X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fpython%2FComponents%2FHarddisk.py;h=7f837565b82cbaee4176bf73b5c533397587f374;hp=2efdb68f6a1c759180870b460783e2edde5e35e9;hb=0a62b65175152c42976d4cb04fb7026d9f910915;hpb=35cc93a57db072be9ca6cf8737bbb120ab215059 diff --git a/lib/python/Components/Harddisk.py b/lib/python/Components/Harddisk.py old mode 100755 new mode 100644 index 2efdb68..7f83756 --- a/lib/python/Components/Harddisk.py +++ b/lib/python/Components/Harddisk.py @@ -5,6 +5,10 @@ from SystemInfo import SystemInfo import time from Components.Console import Console +def MajorMinor(path): + rdev = stat(path).st_rdev + return (major(rdev),minor(rdev)) + def readFile(filename): file = open(filename) data = file.read().strip() @@ -125,13 +129,15 @@ class Harddisk: for line in lines: parts = line.strip().split(" ") - if path.realpath(parts[0]).startswith(self.dev_path): - try: + real_path = path.realpath(parts[0]) + if not real_path[-1].isdigit(): + continue + try: + if MajorMinor(real_path) == MajorMinor(self.partitionPath(real_path[-1])): stat = statvfs(parts[1]) - except OSError: - continue - return stat.f_bfree/1000 * stat.f_bsize/1000 - + return stat.f_bfree/1000 * stat.f_bsize/1000 + except OSError: + pass return -1 def numPartitions(self): @@ -166,23 +172,30 @@ class Harddisk: lines = mounts.readlines() mounts.close() - cmd = "/bin/umount" + cmd = "umount" - for line in lines: - parts = line.strip().split(" ") - if path.realpath(parts[0]).startswith(self.dev_path): - cmd = ' ' . join([cmd, parts[1]]) + for line in lines: + parts = line.strip().split(" ") + real_path = path.realpath(parts[0]) + if not real_path[-1].isdigit(): + continue + try: + if MajorMinor(real_path) == MajorMinor(self.partitionPath(real_path[-1])): + cmd = ' ' . join([cmd, parts[1]]) + break + except OSError: + pass res = system(cmd) return (res >> 8) def createPartition(self): - cmd = 'printf "0,\n;\n;\n;\ny\n" | /sbin/sfdisk -f ' + self.disk_path + cmd = 'printf "0,\n;\n;\n;\ny\n" | sfdisk -f ' + self.disk_path res = system(cmd) return (res >> 8) def mkfs(self): - cmd = "/sbin/mkfs.ext3 " + cmd = "mkfs.ext3 " if self.diskSize() > 4 * 1024: cmd += "-T largefile " cmd += "-m0 -O dir_index " + self.partitionPath("1") @@ -201,10 +214,16 @@ class Harddisk: res = -1 for line in lines: parts = line.strip().split(" ") - if path.realpath(parts[0]) == self.partitionPath("1"): - cmd = "/bin/mount -t ext3 " + parts[0] - res = system(cmd) - break + real_path = path.realpath(parts[0]) + if not real_path[-1].isdigit(): + continue + try: + if MajorMinor(real_path) == MajorMinor(self.partitionPath(real_path[-1])): + cmd = "mount -t ext3 " + parts[0] + res = system(cmd) + break + except OSError: + pass return (res >> 8) @@ -218,7 +237,7 @@ class Harddisk: def fsck(self): # We autocorrect any failures # TODO: we could check if the fs is actually ext3 - cmd = "/sbin/fsck.ext3 -f -p " + self.partitionPath("1") + cmd = "fsck.ext3 -f -p " + self.partitionPath("1") res = system(cmd) return (res >> 8) @@ -226,7 +245,7 @@ class Harddisk: part = self.partitionPath(n) if access(part, 0): - cmd = '/bin/dd bs=512 count=3 if=/dev/zero of=' + part + cmd = 'dd bs=512 count=3 if=/dev/zero of=' + part res = system(cmd) else: res = 0 @@ -290,7 +309,10 @@ class Harddisk: # any access has been made to the disc. If there has been no access over a specifed time, # we set the hdd into standby. def readStats(self): - l = readFile("/sys/block/%s/stat" % self.device) + try: + l = open("/sys/block/%s/stat" % self.device).read() + except IOError: + return -1,-1 (nr_read, _, _, _, nr_write) = l.split()[:5] return int(nr_read), int(nr_write) @@ -319,7 +341,7 @@ class Harddisk: l = sum(stats) print "sum", l, "prev_sum", self.last_stat - if l != self.last_stat: # access + if l != self.last_stat and l >= 0: # access print "hdd was accessed since previous check!" self.last_stat = l self.last_access = t