Skip to content

Commit 4cf5e53

Browse files
committed
begun unmount option
1 parent 2c8bc2a commit 4cf5e53

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

examples/mount.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
import getopt
3232

3333
hidden = False
34+
unmount = False
3435

3536
args = getopt.getopt(sys.argv[1:], "h")
3637

3738
# parse cmdline options
3839
for k in args[0]:
3940
if k[0]=='-h':
4041
hidden = True
42+
# if k[0]=='-u':
43+
# unmount = True
4144

4245
if len(args[1]) != 2:
4346
print "Usage: python mount.py [-h] volumepath dmname"
@@ -53,6 +56,11 @@
5356
PASSWORD = getpass.getpass("Enter password: ")
5457
DMNAME = args[1][1]
5558

59+
#if unmount:
60+
#todo
61+
# remove loopback
62+
# os.system("losetup -d `sudo losetup -a | grep '%s' | cut -d ':' -f 1`" % (FILENAME))
63+
5664
#initialise pytruecrypt
5765
tc = PyTruecrypt(FILENAME)
5866

@@ -63,17 +71,20 @@
6371

6472
#if root - mount it
6573
if os.getuid() == 0:
66-
#find a free loopback device
67-
child = Popen("losetup -f", shell=True, stdout=PIPE)
68-
output, errors = child.communicate();
69-
freeLoopback = output.strip()
70-
71-
#setup loopback
72-
os.system("losetup %s %s" % (freeLoopback, FILENAME))
74+
devName = FILENAME
75+
76+
# if not block device - use loopback
77+
if not stat.S_ISBLK(os.stat(devName).st_mode):
78+
#find a free loopback device
79+
child = Popen("losetup -f", shell=True, stdout=PIPE)
80+
output, errors = child.communicate();
81+
devName = output.strip()
82+
83+
#setup loopback
84+
os.system("losetup %s %s" % (devName, FILENAME))
7385

7486
#setup linux device mapper so can mount volume
75-
dmtable = tc.getDeviceMapperTable(freeLoopback)
76-
87+
dmtable = tc.getDeviceMapperTable(devName)
7788

7889
#create dm target /dev/mapper/tcrypt
7990
# print "Device mapper table"

util.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# Truecrypt parsing library for Python by Gareth Owen
2+
# https://github.com/drgowen/pytruecrypt/
3+
# See LICENCE for licence details
4+
5+
# PyTruecrypt is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
10+
# PyTruecrypt is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
15+
# You should have received a copy of the GNU General Public License
16+
# along with PyTruecrypt. If not, see <http://www.gnu.org/licenses/>.
17+
18+
119
# hexdump print function
220
def hexdump(src, length=16):
321
FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)])

0 commit comments

Comments
 (0)