forked from efidroid/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfstab.py
111 lines (90 loc) · 3.36 KB
/
fstab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#
# Copyright (C) 2016 The EFIDroid Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class FSTabEntry:
blk_device = None
mount_point = None
fs_type = None
flags = []
fs_options = []
def __init__(self, blk_device, mount_point, fs_type, flags, fs_options):
self.blk_device = blk_device
self.mount_point = mount_point
self.fs_type = fs_type
self.flags = flags
self.fs_options = fs_options
class FSTab:
entries = []
def __init__(self, filename):
with open(filename) as f:
for line in f:
line = line.strip() # strip whitespace
line = line.split('#', 1)[0] # remove comments
if not line:
continue
# get device
tmp = line.split(' ', 1)
blk_device = tmp[0]
# get mountpoint
tmp = tmp[1].strip().split(' ', 1)
mount_point = tmp[0]
# get fs_type
tmp = tmp[1].strip().split(' ', 1)
fs_type = tmp[0]
# get mount flags
tmp = tmp[1].strip().split(' ', 1)
flags = tmp[0].split(',')
if len(tmp)>1:
# get fs_options
tmp = tmp[1].strip().split(' ', 1)
fs_options = tmp[0].split(',')
self.entries.append(FSTabEntry(blk_device, mount_point, fs_type, flags, fs_options))
def getOptionValue(self, entry, name):
for fs_option in entry.fs_options:
optname = fs_option
optval = None
fs_option_kv = fs_option.split('=')
if len(fs_option_kv)>1:
optname = fs_option_kv[0]
optval = fs_option_kv[1]
if name in optname:
return optval
def hasOption(self, entry, name):
for fs_option in entry.fs_options:
optname = fs_option
optval = None
fs_option_kv = fs_option.split('=')
if len(fs_option_kv)>1:
optname = fs_option_kv[0]
optval = fs_option_kv[1]
if name in optname:
return True
return False
def getNVVarsPartition(self):
for entry in self.entries:
if 'nvvars' in entry.fs_options:
return entry.blk_device
return None
def getESPPartition(self):
for entry in self.entries:
if self.hasOption(entry, 'esp'):
path = self.getOptionValue(entry, 'esp')
if 'datamedia' in path:
path = 'media'
elif path[0] == '/':
pass
else:
raise Exception('Invalid ESP value in fstab: %s' % (path))
return [entry.blk_device, path]
return None