7500c33daae832f8df47e318385fc52feede2828
[vuplus_dvbapp] / lib / python / Components / Harddisk.py
1 from os import system, listdir, statvfs, popen, makedirs, stat, major, minor, path, access
2 #       ikseong
3 from Tools.Directories import SCOPE_HDD, resolveFilename, fileExists
4
5 from Tools.CList import CList
6 from SystemInfo import SystemInfo
7 import time
8 from Components.Console import Console
9
10 def MajorMinor(path):
11         rdev = stat(path).st_rdev
12         return (major(rdev),minor(rdev))
13
14 def readFile(filename):
15         file = open(filename)
16         data = file.read().strip()
17         file.close()
18         return data
19
20 DEVTYPE_UDEV = 0
21 DEVTYPE_DEVFS = 1
22
23 class Harddisk:
24         def __init__(self, device):
25                 self.device = device
26
27                 if access("/dev/.udev", 0):
28                         self.type = DEVTYPE_UDEV
29                 elif access("/dev/.devfsd", 0):
30                         self.type = DEVTYPE_DEVFS
31                 else:
32                         print "Unable to determine structure of /dev"
33
34                 self.max_idle_time = 0
35                 self.idle_running = False
36                 self.timer = None
37
38                 self.dev_path = ''
39                 self.disk_path = ''
40                 self.phys_path = path.realpath(self.sysfsPath('device'))
41
42                 if self.type == DEVTYPE_UDEV:
43                         self.dev_path = '/dev/' + self.device
44                         self.disk_path = self.dev_path
45
46                 elif self.type == DEVTYPE_DEVFS:
47                         tmp = readFile(self.sysfsPath('dev')).split(':')
48                         s_major = int(tmp[0])
49                         s_minor = int(tmp[1])
50                         for disc in listdir("/dev/discs"):
51                                 dev_path = path.realpath('/dev/discs/' + disc)
52                                 disk_path = dev_path + '/disc'
53                                 try:
54                                         rdev = stat(disk_path).st_rdev
55                                 except OSError:
56                                         continue
57                                 if s_major == major(rdev) and s_minor == minor(rdev):
58                                         self.dev_path = dev_path
59                                         self.disk_path = disk_path
60                                         break
61
62                 print "new Harddisk", self.device, '->', self.dev_path, '->', self.disk_path
63                 self.startIdle()
64
65         def __lt__(self, ob):
66                 return self.device < ob.device
67
68         def partitionPath(self, n):
69                 if self.type == DEVTYPE_UDEV:
70                         return self.dev_path + n
71                 elif self.type == DEVTYPE_DEVFS:
72                         return self.dev_path + '/part' + n
73
74         def sysfsPath(self, filename):
75                 return path.realpath('/sys/block/' + self.device + '/' + filename)
76
77         def stop(self):
78                 if self.timer:
79                         self.timer.stop()
80                         self.timer.callback.remove(self.runIdle)
81
82         def bus(self):
83                 # CF (7025 specific)
84                 if self.type == DEVTYPE_UDEV:
85                         ide_cf = False  # FIXME
86                 elif self.type == DEVTYPE_DEVFS:
87                         ide_cf = self.device[:2] == "hd" and "host0" not in self.dev_path
88
89                 internal = "pci" in self.phys_path
90
91                 if ide_cf:
92                         ret = "External (CF)"
93                 elif internal:
94                         ret = "Internal"
95                 else:
96                         ret = "External"
97                 return ret
98
99         def diskSize(self):
100                 #       ikseong
101                 try:
102                         line = readFile(self.sysfsPath('size'))
103                 except:
104                         harddiskmanager.removeHotplugPartition(self.device)
105                         print "error remove",self.device
106                         return -1
107                 try:
108                         cap = int(line)
109                 except:
110                         return 0;
111                 return cap / 1000 * 512 / 1000
112
113         def capacity(self):
114                 cap = self.diskSize()
115                 if cap == 0:
116                         return ""
117                 return "%d.%03d GB" % (cap/1000, cap%1000)
118
119         def model(self):
120                 #       ikseong
121                 try:
122                         if self.device[:2] == "hd":
123                                 return readFile('/proc/ide/' + self.device + '/model')
124                         elif self.device[:2] == "sd":
125                                 vendor = readFile(self.sysfsPath('device/vendor'))
126                                 model = readFile(self.sysfsPath('device/model'))
127                                 return vendor + '(' + model + ')'
128                         else:
129                                 assert False, "no hdX or sdX"
130                 except:
131                         harddiskmanager.removeHotplugPartition(self.device)
132                         print "error remove",self.device
133                         return -1
134
135         def free(self):
136                 try:
137                         mounts = open("/proc/mounts")
138                 except IOError:
139                         return -1
140
141                 lines = mounts.readlines()
142                 mounts.close()
143
144                 for line in lines:
145                         parts = line.strip().split(" ")
146                         real_path = path.realpath(parts[0])
147                         if not real_path[-1].isdigit():
148                                 continue
149                         try:
150                                 if MajorMinor(real_path) == MajorMinor(self.partitionPath(real_path[-1])):
151                                         stat = statvfs(parts[1])
152                                         return stat.f_bfree/1000 * stat.f_bsize/1000
153                         except OSError:
154                                 pass
155                 return -1
156
157         def numPartitions(self):
158                 numPart = -1
159                 if self.type == DEVTYPE_UDEV:
160                         try:
161                                 devdir = listdir('/dev')
162                         except OSError:
163                                 return -1
164                         for filename in devdir:
165                                 if filename.startswith(self.device):
166                                         numPart += 1
167
168                 elif self.type == DEVTYPE_DEVFS:
169                         try:
170                                 idedir = listdir(self.dev_path)
171                         except OSError:
172                                 return -1
173                         for filename in idedir:
174                                 if filename.startswith("disc"):
175                                         numPart += 1
176                                 if filename.startswith("part"):
177                                         numPart += 1
178                 return numPart
179
180         def unmount(self):
181                 try:
182                         mounts = open("/proc/mounts")
183                 except IOError:
184                         return -1
185
186                 lines = mounts.readlines()
187                 mounts.close()
188
189                 cmd = "umount"
190
191                 for line in lines:                                                                          
192                         parts = line.strip().split(" ")                                                     
193                         real_path = path.realpath(parts[0])                                                 
194                         if not real_path[-1].isdigit():                                                     
195                                 continue                                                                    
196                         try:                                                                                
197                                 if MajorMinor(real_path) == MajorMinor(self.partitionPath(real_path[-1])):
198                                         cmd = ' ' . join([cmd, parts[1]])
199                                         break
200                         except OSError:
201                                 pass
202
203                 res = system(cmd)
204                 return (res >> 8)
205
206         def checkPartionPath(self, path):
207                 import time, os
208                 for i in range(1,10):
209                         if os.path.exists(path):
210                                 return True
211                         time.sleep(1)
212                 return False
213
214         def createPartition(self):
215                 def CheckPartedVer():
216                         cmd = 'parted --version'
217                         lines = popen(cmd).readlines()
218                         for l in lines:
219                                 if l.find("parted (GNU parted)") != -1:
220                                         ver = l.split()[3].strip()
221                                         break
222                         try:
223                                 ver = float(ver)
224                         except:
225                                 print "[CheckPartedVer] check parted version Failed!"
226                                 return 0
227                         return ver
228
229                 disk_size = self.diskSize()
230
231                 if disk_size > 2.2 * 1000 * 1000: # if 2.2 TB
232                         setAlign = ""
233                         partedVer = CheckPartedVer()
234                         if partedVer >= 2.1: # align option is supported in version 2.1 or later
235                                 setAlign = "--align optimal"
236                         cmd = 'parted %s %s --script mklabel gpt mkpart disk ext2 0%% 100%%' % ( setAlign, self.disk_path )
237
238                 else:
239                         cmd = 'printf "8,\n;0,0\n;0,0\n;0,0\ny\n" | sfdisk -f -uS ' + self.disk_path
240
241                 res = system(cmd)
242                 if not self.checkPartionPath(self.partitionPath("1")):
243                         print "no exist : ", self.partitionPath("1")
244                         return 1
245                 return (res >> 8)
246
247         def mkfs(self):
248                 cmd = "mkfs.ext3 "
249                 if self.diskSize() > 4 * 1024:
250                         cmd += "-T largefile "
251                 cmd += "-m0 -O dir_index " + self.partitionPath("1")
252                 res = system(cmd)
253                 return (res >> 8)
254
255         def mount(self):
256                 try:
257                         fstab = open("/etc/fstab")
258                 except IOError:
259                         return -1
260
261                 lines = fstab.readlines()
262                 fstab.close()
263
264                 res = -1
265                 for line in lines:
266                         parts = line.strip().split(" ")
267                         real_path = path.realpath(parts[0])                                                 
268                         if not real_path[-1].isdigit():                                                     
269                                 continue                                                                    
270                         try:                                                                                
271                                 if MajorMinor(real_path) == MajorMinor(self.partitionPath(real_path[-1])):
272                                         cmd = "mount -t ext3 " + parts[0]
273                                         res = system(cmd)
274                                         break
275                         except OSError:
276                                 pass
277
278                 return (res >> 8)
279
280         def createMovieFolder(self):
281 #       ikseong
282                 try:
283                         if not fileExists("/hdd", 0):
284                                 print "not found /hdd"
285                                 system("ln -s /media/hdd /hdd")
286 #                               
287                         makedirs(resolveFilename(SCOPE_HDD))
288                 except OSError:
289                         return -1
290                 return 0
291
292         def fsck(self):
293                 # We autocorrect any failures
294                 # TODO: we could check if the fs is actually ext3
295                 cmd = "fsck.ext3 -f -p " + self.partitionPath("1")
296                 res = system(cmd)
297                 return (res >> 8)
298
299         def killPartition(self, n):
300                 part = self.partitionPath(n)
301
302                 if access(part, 0):
303                         cmd = 'dd bs=512 count=3 if=/dev/zero of=' + part
304                         res = system(cmd)
305                 else:
306                         res = 0
307
308                 return (res >> 8)
309
310         errorList = [ _("Everything is fine"), _("Creating partition failed"), _("Mkfs failed"), _("Mount failed"), _("Create movie folder failed"), _("Fsck failed"), _("Please Reboot"), _("Filesystem contains uncorrectable errors"), _("Unmount failed")]
311
312         def initialize(self):
313                 self.unmount()
314
315                 # Udev tries to mount the partition immediately if there is an
316                 # old filesystem on it when fdisk reloads the partition table.
317                 # To prevent that, we overwrite the first 3 sectors of the
318                 # partition, if the partition existed before. That's enough for
319                 # ext3 at least.
320                 self.killPartition("1")
321
322                 if self.createPartition() != 0:
323                         return -1
324
325                 if self.mkfs() != 0:
326                         return -2
327
328                 if self.mount() != 0:
329                         return -3
330
331                 if self.createMovieFolder() != 0:
332                         return -4
333
334                 return 0
335
336         def check(self):
337                 self.unmount()
338
339                 res = self.fsck()
340                 if res & 2 == 2:
341                         return -6
342
343                 if res & 4 == 4:
344                         return -7
345
346                 if res != 0 and res != 1:
347                         # A sum containing 1 will also include a failure
348                         return -5
349
350                 if self.mount() != 0:
351                         return -3
352
353                 return 0
354
355         def getDeviceDir(self):
356                 return self.dev_path
357
358         def getDeviceName(self):
359                 return self.disk_path
360
361         # the HDD idle poll daemon.
362         # as some harddrives have a buggy standby timer, we are doing this by hand here.
363         # first, we disable the hardware timer. then, we check every now and then if
364         # any access has been made to the disc. If there has been no access over a specifed time,
365         # we set the hdd into standby.
366         def readStats(self):
367                 try:
368                         l = open("/sys/block/%s/stat" % self.device).read()
369                 except IOError:
370                         return -1,-1
371                 (nr_read, _, _, _, nr_write) = l.split()[:5]
372                 return int(nr_read), int(nr_write)
373
374         def startIdle(self):
375                 self.last_access = time.time()
376                 self.last_stat = 0
377                 self.is_sleeping = False
378                 from enigma import eTimer
379
380                 # disable HDD standby timer
381                 Console().ePopen(("hdparm", "hdparm", "-S0", self.disk_path))
382                 self.timer = eTimer()
383                 self.timer.callback.append(self.runIdle)
384                 self.idle_running = True
385                 self.setIdleTime(self.max_idle_time) # kick the idle polling loop
386
387         def runIdle(self):
388                 if not self.max_idle_time:
389                         return
390                 t = time.time()
391
392                 idle_time = t - self.last_access
393
394                 stats = self.readStats()
395                 #       ikseong
396                 if stats == -1:
397                         self.setIdleTime(0)
398                         return
399                 print "nr_read", stats[0], "nr_write", stats[1]
400                 l = sum(stats)
401                 print "sum", l, "prev_sum", self.last_stat
402
403                 if l != self.last_stat and l >= 0: # access
404                         print "hdd was accessed since previous check!"
405                         self.last_stat = l
406                         self.last_access = t
407                         idle_time = 0
408                         self.is_sleeping = False
409                 else:
410                         print "hdd IDLE!"
411
412                 print "[IDLE]", idle_time, self.max_idle_time, self.is_sleeping
413                 if idle_time >= self.max_idle_time and not self.is_sleeping:
414                         self.setSleep()
415                         self.is_sleeping = True
416
417         def setSleep(self):
418                 Console().ePopen(("hdparm", "hdparm", "-y", self.disk_path))
419
420         def setIdleTime(self, idle):
421                 self.max_idle_time = idle
422                 if self.idle_running:
423                         if not idle:
424                                 self.timer.stop()
425                         else:
426                                 self.timer.start(idle * 100, False)  # poll 10 times per period.
427
428         def isSleeping(self):
429                 return self.is_sleeping
430
431 class Partition:
432         def __init__(self, mountpoint, device = None, description = "", force_mounted = False):
433                 self.mountpoint = mountpoint
434                 self.description = description
435                 self.force_mounted = force_mounted
436                 self.is_hotplug = force_mounted # so far; this might change.
437                 self.device = device
438
439         def stat(self):
440                 return statvfs(self.mountpoint)
441
442         def free(self):
443                 try:
444                         s = self.stat()
445                         return s.f_bavail * s.f_bsize
446                 except OSError:
447                         return None
448
449         def total(self):
450                 try:
451                         s = self.stat()
452                         return s.f_blocks * s.f_bsize
453                 except OSError:
454                         return None
455
456         def mounted(self):
457                 # THANK YOU PYTHON FOR STRIPPING AWAY f_fsid.
458                 # TODO: can os.path.ismount be used?
459                 if self.force_mounted:
460                         return True
461
462                 try:
463                         mounts = open("/proc/mounts")
464                 except IOError:
465                         return False
466
467                 lines = mounts.readlines()
468                 mounts.close()
469
470                 for line in lines:
471                         if line.split(' ')[1] == self.mountpoint:
472                                 return True
473                 return False
474
475 DEVICEDB_SR = \
476         {"dm8000":
477                 {
478                         "/devices/pci0000:01/0000:01:00.0/host0/target0:0:0/0:0:0:0": _("DVD Drive"),
479                         "/devices/pci0000:01/0000:01:00.0/host1/target1:0:0/1:0:0:0": _("DVD Drive"),
480                         "/devices/platform/brcm-ehci-1.1/usb2/2-1/2-1:1.0/host3/target3:0:0/3:0:0:0": _("DVD Drive"),
481                 },
482         "dm800":
483         {
484         },
485         "dm7025":
486         {
487         }
488         }
489
490 DEVICEDB = \
491         {"dm8000":
492                 {
493                         "/devices/platform/brcm-ehci.0/usb1/1-1/1-1.1/1-1.1:1.0": _("Front USB Slot"),
494                         "/devices/platform/brcm-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0": _("Back, upper USB Slot"),
495                         "/devices/platform/brcm-ehci.0/usb1/1-1/1-1.3/1-1.3:1.0": _("Back, lower USB Slot"),
496                         "/devices/platform/brcm-ehci.0/usb1/1-1/1-1.1/1-1.1:1.0": _("Front USB Slot"),
497                         "/devices/platform/brcm-ehci-1.1/usb2/2-1/2-1:1.0/": _("Internal USB Slot"),
498                         "/devices/platform/brcm-ohci-1.1/usb4/4-1/4-1:1.0/": _("Internal USB Slot"),
499                 },
500         "dm800":
501         {
502                 "/devices/platform/brcm-ehci.0/usb1/1-2/1-2:1.0": "Upper USB Slot",
503                 "/devices/platform/brcm-ehci.0/usb1/1-1/1-1:1.0": "Lower USB Slot",
504         },
505         "dm7025":
506         {
507                 "/devices/pci0000:00/0000:00:14.1/ide1/1.0": "CF Card Slot", #hdc
508                 "/devices/pci0000:00/0000:00:14.1/ide0/0.0": "Internal Harddisk"
509         }
510         }
511
512 class HarddiskManager:
513         def __init__(self):
514                 self.hdd = [ ]
515                 self.cd = ""
516                 self.partitions = [ ]
517                 self.devices_scanned_on_init = [ ]
518
519                 self.on_partition_list_change = CList()
520
521                 self.enumerateBlockDevices()
522
523                 # currently, this is just an enumeration of what's possible,
524                 # this probably has to be changed to support automount stuff.
525                 # still, if stuff is mounted into the correct mountpoints by
526                 # external tools, everything is fine (until somebody inserts
527                 # a second usb stick.)
528                 p = [
529                                         ("/media/hdd", _("Harddisk")),
530                                         ("/media/card", _("Card")),
531                                         ("/media/cf", _("Compact Flash")),
532                                         ("/media/mmc1", _("MMC Card")),
533                                         ("/media/net", _("Network Mount")),
534                                         ("/media/ram", _("Ram Disk")),
535                                         ("/media/usb", _("USB Stick")),
536                                         ("/", _("Internal Flash"))
537                                 ]
538
539                 self.partitions.extend([ Partition(mountpoint = x[0], description = x[1]) for x in p ])
540
541         def getBlockDevInfo(self, blockdev):
542                 devpath = "/sys/block/" + blockdev
543                 error = False
544                 removable = False
545                 blacklisted = False
546                 is_cdrom = False
547                 partitions = []
548                 try:
549                         removable = bool(int(readFile(devpath + "/removable")))
550                         dev = int(readFile(devpath + "/dev").split(':')[0])
551                         if dev in (7, 31): # loop, mtdblock
552                                 blacklisted = True
553                         if blockdev[0:2] == 'sr':
554                                 is_cdrom = True
555                         if blockdev[0:2] == 'hd':
556                                 try:
557                                         media = readFile("/proc/ide/%s/media" % blockdev)
558                                         if "cdrom" in media:
559                                                 is_cdrom = True
560                                 except IOError:
561                                         error = True
562                         # check for partitions
563                         if not is_cdrom:
564                                 for partition in listdir(devpath):
565                                         if partition[0:len(blockdev)] != blockdev:
566                                                 continue
567                                         partitions.append(partition)
568                         else:
569                                 self.cd = blockdev
570                 except IOError:
571                         error = True
572                 # check for medium
573                 medium_found = True
574                 try:
575                         open("/dev/" + blockdev).close()
576                 except IOError, err:
577                         if err.errno == 159: # no medium present
578                                 medium_found = False
579
580                 return error, blacklisted, removable, is_cdrom, partitions, medium_found
581
582         def enumerateBlockDevices(self):
583                 print "enumerating block devices..."
584                 for blockdev in listdir("/sys/block"):
585                         error, blacklisted, removable, is_cdrom, partitions, medium_found = self.addHotplugPartition(blockdev)
586                         if not error and not blacklisted:
587                                 if medium_found:
588                                         for part in partitions:
589                                                 self.addHotplugPartition(part)
590                                 self.devices_scanned_on_init.append((blockdev, removable, is_cdrom, medium_found))
591
592         def getAutofsMountpoint(self, device):
593                 return "/autofs/%s/" % (device)
594
595
596         def is_hard_mounted(self, device):
597                 mounts = file('/proc/mounts').read().split('\n')
598                 for x in mounts:
599                         if x.find('/autofs') == -1 and x.find(device) != -1:
600                                 return True
601                 return False
602
603         def addHotplugPartition(self, device, physdev = None):
604                 if not physdev:
605                         dev, part = self.splitDeviceName(device)
606                         try:
607                                 physdev = path.realpath('/sys/block/' + dev + '/device')[4:]
608                         except OSError:
609                                 physdev = dev
610                                 print "couldn't determine blockdev physdev for device", device
611
612                 error, blacklisted, removable, is_cdrom, partitions, medium_found = self.getBlockDevInfo(device)
613                 print "found block device '%s':" % device,
614
615                 if blacklisted:
616                         print "blacklisted"
617                 else:
618                         if error:
619                                 print "error querying properties"
620                         elif not medium_found:
621                                 print "no medium"
622                         else:
623                                 print "ok, removable=%s, cdrom=%s, partitions=%s" % (removable, is_cdrom, partitions)
624
625                         l = len(device)
626                         if l:
627                                 # see if this is a harddrive
628                                 if not device[l-1].isdigit() and not removable and not is_cdrom:
629                                         self.hdd.append(Harddisk(device))
630                                         self.hdd.sort()
631                                         SystemInfo["Harddisk"] = len(self.hdd) > 0
632
633                                 if (not removable or medium_found) and not self.is_hard_mounted(device):
634                                         # device is the device name, without /dev
635                                         # physdev is the physical device path, which we (might) use to determine the userfriendly name
636                                         description = self.getUserfriendlyDeviceName(device, physdev)
637                                         p = Partition(mountpoint = self.getAutofsMountpoint(device), description = description, force_mounted = True, device = device)
638                                         self.partitions.append(p)
639                                         self.on_partition_list_change("add", p)
640
641                 return error, blacklisted, removable, is_cdrom, partitions, medium_found
642
643         def removeHotplugPartition(self, device):
644                 mountpoint = self.getAutofsMountpoint(device)
645                 for x in self.partitions[:]:
646                         if x.mountpoint == mountpoint:
647                                 self.partitions.remove(x)
648                                 self.on_partition_list_change("remove", x)
649                 l = len(device)
650                 if l and not device[l-1].isdigit():
651                         for hdd in self.hdd:
652                                 if hdd.device == device:
653                                         hdd.stop()
654                                         self.hdd.remove(hdd)
655                                         break
656                         SystemInfo["Harddisk"] = len(self.hdd) > 0
657
658         def HDDCount(self):
659                 return len(self.hdd)
660
661         def HDDList(self):
662                 list = [ ]
663                 for hd in self.hdd:
664                         #       ikseong
665                         if hd.model() == -1:
666                                 continue
667                         hdd = hd.model() + " - " + hd.bus()
668                         cap = hd.capacity()
669                         if cap != "":
670                                 hdd += " (" + cap + ")"
671                         list.append((hdd, hd))
672                 return list
673
674         def getCD(self):
675                 return self.cd
676
677         def getMountedPartitions(self, onlyhotplug = False):
678                 parts = [x for x in self.partitions if (x.is_hotplug or not onlyhotplug) and x.mounted()]
679                 devs = set([x.device for x in parts])
680                 for devname in devs.copy():
681                         if not devname:
682                                 continue
683                         dev, part = self.splitDeviceName(devname)
684                         if part and dev in devs: # if this is a partition and we still have the wholedisk, remove wholedisk
685                                 devs.remove(dev)
686
687                 # return all devices which are not removed due to being a wholedisk when a partition exists
688                 return [x for x in parts if not x.device or x.device in devs]
689
690         def splitDeviceName(self, devname):
691                 # this works for: sdaX, hdaX, sr0 (which is in fact dev="sr0", part=""). It doesn't work for other names like mtdblock3, but they are blacklisted anyway.
692                 dev = devname[:3]
693                 part = devname[3:]
694                 for p in part:
695                         if not p.isdigit():
696                                 return devname, 0
697                 return dev, part and int(part) or 0
698
699         def getUserfriendlyDeviceName(self, dev, phys):
700                 dev, part = self.splitDeviceName(dev)
701                 description = "External Storage %s" % dev
702                 have_model_descr = False
703                 try:
704                         description = readFile("/sys" + phys + "/model")
705                         have_model_descr = True
706                 except IOError, s:
707                         print "couldn't read model: ", s
708                 from Tools.HardwareInfo import HardwareInfo
709                 if dev.find('sr') == 0 and dev[2].isdigit():
710                         devicedb = DEVICEDB_SR
711                 else:
712                         devicedb = DEVICEDB
713                 for physdevprefix, pdescription in devicedb.get(HardwareInfo().device_name,{}).items():
714                         if phys.startswith(physdevprefix):
715                                 if have_model_descr:
716                                         description = pdescription + ' - ' + description
717                                 else:
718                                         description = pdescription
719                 # not wholedisk and not partition 1
720                 if part and part != 1:
721                         description += " (Partition %d)" % part
722                 return description
723
724         def addMountedPartition(self, device, desc):
725                 already_mounted = False
726                 for x in self.partitions[:]:
727                         if x.mountpoint == device:
728                                 already_mounted = True
729                 if not already_mounted:
730                         self.partitions.append(Partition(mountpoint = device, description = desc))
731
732         def removeMountedPartition(self, mountpoint):
733                 for x in self.partitions[:]:
734                         if x.mountpoint == mountpoint:
735                                 self.partitions.remove(x)
736                                 self.on_partition_list_change("remove", x)
737
738 harddiskmanager = HarddiskManager()