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