home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / fstab.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  20.7 KB  |  708 lines

  1. # this owns partitioning, fstab generation, disk scanning, raid, etc
  2. #
  3. # a fstab is returned as a list of:
  4. #    ( mntpoint, device, fsystem, doFormat, size, (file) )
  5. # tuples, sorted by mntpoint; note that device may be a raid device; the file 
  6. # value is optional, and if it exists it names a file which will be created 
  7. # on the (already existant!) device and loopback mounted
  8. #
  9. # the swap information is stored as ( device, format ) tuples
  10. #
  11. # raid lists are stored as ( mntpoint, raiddevice, fssystem, doFormat,
  12. #                 raidlevel, [ device list ] )
  13. #
  14. # we always store as much of the fstab within the disk druid structure
  15. # as we can -- Don't Duplicate Data.
  16.  
  17. import isys
  18. import iutil
  19. import os
  20. import string
  21. import raid
  22. import struct
  23. from translate import _
  24.  
  25. def isValidExt2(device):
  26.     file = '/tmp/' + device
  27.     isys.makeDevInode(device, file)
  28.     try:
  29.     fd = os.open(file, os.O_RDONLY)
  30.     except:
  31.     return 0
  32.  
  33.     buf = os.read(fd, 2048)
  34.     os.close(fd)
  35.  
  36.     if len(buf) != 2048:
  37.     return 0
  38.  
  39.     if struct.unpack("H", buf[1080:1082]) == (0xef53,):
  40.     return 1
  41.  
  42.     return 0
  43.  
  44. class Fstab:
  45.     def attemptPartitioning(self, partitions, clearParts):
  46.     attempt = []
  47.     swapCount = 0
  48.  
  49.     fstab = []
  50.     for (mntpoint, dev, fstype, reformat, size) in self.extraFilesystems:
  51.             fstab.append ((dev, mntpoint))
  52.  
  53.     ddruid = self.createDruid(fstab = fstab, ignoreBadDrives = 1)
  54.  
  55.     for (mntpoint, size, maxsize, grow, device) in partitions:
  56.         type = 0x83
  57.         if (mntpoint == "swap"):
  58.         mntpoint = "Swap%04d-auto" % swapCount
  59.         swapCount = swapCount + 1
  60.         type = 0x82
  61.         elif (mntpoint[0:5] == "raid."):
  62.         type = 0xfd
  63.  
  64.         attempt.append((mntpoint, size, maxsize, type, grow, -1, device))
  65.  
  66.     try:
  67.         ddruid.attempt (attempt, "Junk Argument", clearParts)
  68.         return ddruid
  69.     except:
  70.         pass
  71.  
  72.     return None
  73.  
  74.     def getMbrDevice(self):
  75.     return self.driveList()[0]
  76.  
  77.     def getBootDevice(self):
  78.     bootDevice = None
  79.     rootDevice = None
  80.     for (mntpoint, partition, fsystem, doFormat, size) in self.mountList():
  81.         if mntpoint == '/':
  82.         rootDevice = partition
  83.         elif mntpoint == '/boot':
  84.         bootDevice = partition
  85.  
  86.     if not bootDevice:
  87.         bootDevice = rootDevice
  88.  
  89.     return bootDevice
  90.  
  91.     def getRootDevice(self):
  92.     for (mntpoint, partition, fsystem, doFormat, size) in self.mountList():
  93.         if mntpoint == '/':
  94.         return (partition, fsystem)
  95.  
  96.     def rootOnLoop(self):
  97.         if not self.setupFilesystems: return 0
  98.     for (mntpoint, partition, fsystem, doFormat, size) in self.mountList():
  99.         if mntpoint == '/':
  100.         if fsystem == "vfat": 
  101.             return 1
  102.         else:
  103.             return 0
  104.  
  105.     raise ValueError, "no root device has been set"
  106.  
  107.     def getLoopbackSize(self):
  108.     return (self.loopbackSize, self.loopbackSwapSize)
  109.  
  110.     def setLoopbackSize(self, size, swapSize):
  111.     self.loopbackSize = size
  112.     self.loopbackSwapSize = swapSize
  113.  
  114.     def setDruid(self, druid, raid):
  115.     self.ddruid = druid
  116.     self.fsCache = {}
  117.     for (mntPoint, raidDev, level, devices) in raid:
  118.         if mntPoint == "swap":
  119.         fsystem = "swap"
  120.         else:
  121.         fsystem = "ext2"
  122.         self.addNewRaidDevice(mntPoint, raidDev, fsystem, level, devices)
  123.         
  124.     def rescanPartitions(self, clearFstabCache = 0):
  125.     if self.ddruid:
  126.         self.closeDrives(clearFstabCache)
  127.  
  128.         fstab = []
  129.     for (mntpoint, dev, fstype, reformat, size) in self.cachedFstab:
  130.             fstab.append ((dev, mntpoint))
  131.  
  132.     self.ddruid = self.fsedit(0, self.driveList(), fstab, self.zeroMbr,
  133.                   self.readOnly)
  134.     del self.cachedFstab
  135.  
  136.     def closeDrives(self, clearFstabCache = 0):
  137.     # we expect a rescanPartitions() after this!!!
  138.         if clearFstabCache:
  139.             self.cachedFstab = []
  140.         else:
  141.         self.cachedFstab = self.mountList(skipExtra = 1)
  142.     self.ddruid = None
  143.  
  144.     def setReadonly(self, readOnly):
  145.     self.readOnly = readOnly
  146.         self.ddruid.setReadOnly(readOnly)
  147.  
  148.     def savePartitions(self):
  149.     self.ddruid.save()
  150.  
  151.     def runDruid(self):
  152.     rc = self.ddruid.edit()
  153.     # yikes! this needs to be smarter
  154.     self.beenSaved = 0
  155.     return rc
  156.  
  157.     def updateFsCache(self):
  158.     realFs = {}
  159.     for (partition, mount, fsystem, size) in self.ddruid.getFstab():
  160.         realFs[(partition, mount)] = 1
  161.     for ((partition, mount)) in self.fsCache.keys():
  162.         if not realFs.has_key((partition, mount)):
  163.         del self.fsCache[(partition, mount)]
  164.  
  165.     def setFormatFilesystem(self, device, format):
  166.     for (mntpoint, partition, fsystem, doFormat, size) in self.mountList():
  167.         if partition == device:
  168.         self.fsCache[(partition, mntpoint)] = (format,)
  169.         return
  170.  
  171.     raise TypeError, "unknown partition to format %s" % (device,)
  172.  
  173.     def formatAllFilesystems(self):
  174.     for (partition, mount, fsystem, size) in self.ddruid.getFstab():
  175.         if mount[0] == '/':
  176.         self.fsCache[(partition, mount)] = (1,)
  177.         (devices, raid) = self.ddruid.partitionList()
  178.     for (mount, partition, fsystem, level, i, j, deviceList) in \
  179.         self.raidList()[1]:
  180.         if mount[0] == '/':
  181.         self.fsCache[(partition, mount)] = (1,)
  182.  
  183.     def partitionList(self):
  184.     return self.ddruid.partitionList()
  185.  
  186.     def driveList(self):
  187.     drives = isys.hardDriveDict().keys()
  188.     drives.sort (isys.compareDrives)
  189.     return drives
  190.  
  191.     def drivesByName(self):
  192.     return isys.hardDriveDict()
  193.  
  194.     def swapList(self):
  195.     fstab = []
  196.     for (partition, mount, fsystem, size) in self.ddruid.getFstab():
  197.         if fsystem != "swap": continue
  198.  
  199.         fstab.append((partition, 1))
  200.  
  201.     # Add raid mounts to mount list
  202.         (devices, raid) = self.raidList()
  203.     for (mntpoint, device, fsType, raidType, start, size, makeup) in raid:
  204.         if fsType != "swap": continue
  205.         fstab.append((device, 1))
  206.  
  207.     for n in self.extraFilesystems:
  208.         (mntpoint, device, fsType, doFormat, size) = n
  209.         if fsType != "swap": continue
  210.         fstab.append((device, 1))
  211.  
  212.     return fstab
  213.  
  214.     def turnOffSwap(self):
  215.     if not self.swapOn: return
  216.     self.swapOn = 0
  217.     for (device, doFormat) in self.swapList():
  218.         file = '/tmp/swap/' + device
  219.         isys.swapoff(file)
  220.  
  221.     def turnOnSwap(self, formatSwap = 1):
  222.     # we could be smarter about this
  223.     if self.swapOn or self.rootOnLoop(): return
  224.     self.swapOn = 1
  225.  
  226.     iutil.mkdirChain('/tmp/swap')
  227.  
  228.     for (device, doFormat) in self.swapList():
  229.         file = '/tmp/swap/' + device
  230.         isys.makeDevInode(device, file)
  231.  
  232.         if formatSwap:
  233.         w = self.waitWindow(_("Formatting"),
  234.                   _("Formatting swap space on /dev/%s...") % 
  235.                     (device,))
  236.  
  237.         rc = iutil.execWithRedirect ("/usr/sbin/mkswap",
  238.                      [ "mkswap", '-v1', file ],
  239.                      stdout = None, stderr = None,
  240.                      searchPath = 1)
  241.         w.pop()
  242.  
  243.         if rc:
  244.             self.messageWindow(_("Error"), _("Error creating swap on device ") + device)
  245.         else:
  246.             isys.swapon (file)
  247.         else:
  248.         try:
  249.             isys.swapon (file)
  250.         except:
  251.             # XXX should we complain?
  252.             pass
  253.  
  254.     def addNewRaidDevice(self, mountPoint, raidDevice, fileSystem, 
  255.               raidLevel, deviceList):
  256.     self.supplementalRaid.append((mountPoint, raidDevice, fileSystem,
  257.                   raidLevel, deviceList))
  258.  
  259.     def clearExistingRaid(self):
  260.     self.existingRaid = []
  261.  
  262.     def addExistingRaidDevice(self, raidDevice, mntPoint, fsystem, deviceList):
  263.         self.existingRaid.append(raidDevice, mntPoint, fsystem, deviceList)
  264.  
  265.     def existingRaidList(self):
  266.     return self.existingRaid
  267.     
  268.     def raidList(self):
  269.         (devices, raid) = self.ddruid.partitionList()
  270.  
  271.     if raid == None:
  272.         raid = []
  273.  
  274.     for (mountPoint, raidDevice, fileSystem, raidLevel, deviceList) in \
  275.         self.supplementalRaid:
  276.         raid.append(mountPoint, raidDevice, fileSystem, raidLevel,
  277.             0, 0, deviceList)
  278.  
  279.     return (devices, raid)
  280.  
  281.     def createRaidTab(self, file, devPrefix, createDevices = 0):
  282.     (devices, raid) = self.raidList()
  283.  
  284.     if not raid: return
  285.  
  286.     deviceDict = {}
  287.     for (device, name, type, start, size) in devices:
  288.         deviceDict[name] = device
  289.  
  290.     rt = open(file, "w")
  291.     for (mntpoint, device, fstype, raidType, start, size, makeup) in raid:
  292.  
  293.         if createDevices:
  294.         isys.makeDevInode(device, devPrefix + '/' + device)
  295.  
  296.         rt.write("raiddev            %s/%s\n" % (devPrefix, device,))
  297.         rt.write("raid-level            %d\n" % (raidType,))
  298.         rt.write("nr-raid-disks            %d\n" % (len(makeup),))
  299.         rt.write("chunk-size            64k\n")
  300.         rt.write("persistent-superblock        1\n");
  301.         rt.write("#nr-spare-disks        0\n")
  302.         i = 0
  303.         for subDevName in makeup:
  304.         isys.makeDevInode(deviceDict[subDevName], '%s/%s' % 
  305.                 (devPrefix, deviceDict[subDevName]))
  306.         rt.write("    device        %s/%s\n" % 
  307.             (devPrefix, deviceDict[subDevName],))
  308.         rt.write("    raid-disk     %d\n" % (i,))
  309.         i = i + 1
  310.  
  311.     rt.write("\n")
  312.     rt.close()
  313.  
  314.     def umountFilesystems(self, instPath, ignoreErrors = 0):
  315.     if (not self.setupFilesystems): return 
  316.  
  317.     isys.umount(instPath + '/proc')
  318.  
  319.     mounts = self.mountList()
  320.     mounts.reverse()
  321.     for (n, device, fsystem, doFormat, size) in mounts:
  322.             if fsystem != "swap":
  323.         try:
  324.             mntPoint = instPath + n
  325.                     isys.umount(mntPoint)
  326.         except SystemError, (errno, msg):
  327.             if not ignoreErrors:
  328.             self.messageWindow(_("Error"), 
  329.                 _("Error unmounting %s: %s") % (device, msg))
  330.  
  331.     if self.rootOnLoop():
  332.         isys.makeDevInode("loop0", '/tmp/' + "loop0")
  333.         isys.unlosetup("/tmp/loop0")
  334.  
  335.     for (raidDevice, mntPoint, fileSystem, deviceList) in self.existingRaid:
  336.         isys.raidstop(raidDevice)
  337.  
  338.     def makeFilesystems(self):
  339.     # let's make the RAID devices first -- the fstab will then proceed
  340.     # naturally
  341.     (devices, raid) = self.raidList()
  342.  
  343.     if self.serial:
  344.         messageFile = "/tmp/mke2fs.log"
  345.     else:
  346.         messageFile = "/dev/tty5"
  347.  
  348.     if raid:
  349.         self.createRaidTab("/tmp/raidtab", "/tmp", createDevices = 1)
  350.  
  351.         w = self.waitWindow(_("Creating"), _("Creating RAID devices..."))
  352.  
  353.         for (mntpoint, device, fsType, raidType, start, size, makeup) in raid:
  354.                 iutil.execWithRedirect ("/usr/sbin/mkraid", 
  355.             [ 'mkraid', '--really-force', '--configfile', 
  356.               '/tmp/raidtab', '/tmp/' + device ],
  357.             stderr = messageFile, stdout = messageFile)
  358.  
  359.         w.pop()
  360.         
  361.         # XXX remove extraneous inodes here
  362. #        print "created raid"
  363.  
  364.         if not self.setupFilesystems: return
  365.  
  366.         arch = iutil.getArch ()
  367.  
  368.         if arch == "alpha":
  369.             bootPart = self.getBootDevice()
  370.  
  371.     for (mntpoint, device, fsystem, doFormat, size) in self.mountList():
  372.         if not doFormat: continue
  373.         isys.makeDevInode(device, '/tmp/' + device)
  374.             if fsystem == "ext2":
  375.                 args = [ "mke2fs", '/tmp/' + device ]
  376.                 # FORCE the partition that MILO has to read
  377.                 # to have 1024 block size.  It's the only
  378.                 # thing that our milo seems to read.
  379.                 if arch == "alpha" and device == bootPart:
  380.                     args = args + ["-b", "1024", '-r', '0', '-O', 'none']
  381.                 # set up raid options for md devices.
  382.                 if device[:2] == 'md':
  383.                     for (rmnt, rdevice, fsType, raidType, start, size, makeup) in raid:
  384.                         if rdevice == device:
  385.                             rtype = raidType
  386.                             rdisks = len (makeup)
  387.                     if rtype == 5:
  388.                         rdisks = rdisks - 1
  389.                         args = args + [ '-R', 'stride=%d' % (rdisks * 16) ]
  390.                     elif rtype == 0:
  391.                         args = args + [ '-R', 'stride=%d' % (rdisks * 16) ]
  392.                         
  393.                 if self.badBlockCheck:
  394.                     args.append ("-c")
  395.  
  396.         w = self.waitWindow(_("Formatting"),
  397.                   _("Formatting %s filesystem...") % (mntpoint,))
  398.  
  399.                 iutil.execWithRedirect ("/usr/sbin/mke2fs",
  400.                                         args, stdout = messageFile, 
  401.                     stderr = messageFile, searchPath = 1)
  402.         w.pop()
  403.             else:
  404.                 pass
  405.  
  406.             os.remove('/tmp/' + device)
  407.  
  408.     def mountFilesystems(self, instPath):
  409.     if (not self.setupFilesystems): return 
  410.  
  411.     for (raidDevice, mntPoint, fileSystem, deviceList) in self.existingRaid:
  412.         isys.raidstart(raidDevice, deviceList[0])
  413.  
  414.     for (mntpoint, device, fsystem, doFormat, size) in self.mountList():
  415.             if fsystem == "swap":
  416.         continue
  417.         elif fsystem == "vfat" and mntpoint == "/":
  418.         # do a magical loopback mount -- whee!
  419.         w = self.waitWindow(_("Loopback"),
  420.                   _("Creating loopback filesystem on device /dev/%s...") % (device,))
  421.  
  422.         iutil.mkdirChain("/mnt/loophost")
  423.         isys.makeDevInode(device, '/tmp/' + device)
  424.         isys.mount('/tmp/' + device, "/mnt/loophost", fstype = "vfat")
  425.         os.remove( '/tmp/' + device);
  426.         
  427.         isys.makeDevInode("loop0", '/tmp/' + "loop0")
  428.         isys.ddfile("/mnt/loophost/redhat.img", self.loopbackSize)
  429.         isys.losetup("/tmp/loop0", "/mnt/loophost/redhat.img")
  430.  
  431.         if self.serial:
  432.             messageFile = "/tmp/mke2fs.log"
  433.         else:
  434.             messageFile = "/dev/tty5"
  435.  
  436.                 iutil.execWithRedirect ("/usr/sbin/mke2fs", 
  437.                     [ "mke2fs", "/tmp/loop0" ],
  438.                                         stdout = messageFile, 
  439.                     stderr = messageFile, searchPath = 1)
  440.  
  441.         isys.mount('/tmp/loop0', instPath)
  442.         os.remove('/tmp/loop0')
  443.  
  444.         if self.loopbackSwapSize:
  445.             isys.ddfile("/mnt/loophost/rh-swap.img", 
  446.                 self.loopbackSwapSize)
  447.             iutil.execWithRedirect ("/usr/sbin/mkswap",
  448.                      [ "mkswap", '-v1', 
  449.                        '/mnt/loophost/rh-swap.img' ],
  450.                      stdout = None, stderr = None)
  451.             isys.swapon("/mnt/loophost/rh-swap.img")
  452.  
  453.         w.pop()
  454.         elif fsystem == "ext2":
  455.         try:
  456.             iutil.mkdirChain(instPath + mntpoint)
  457.             isys.makeDevInode(device, '/tmp/' + device)
  458.             isys.mount('/tmp/' + device, 
  459.                 instPath + mntpoint)
  460.             os.remove( '/tmp/' + device);
  461.         except SystemError, (errno, msg):
  462.             self.messageWindow(_("Error"), 
  463.             _("Error mounting %s: %s") % (device, msg))
  464.             raise SystemError, (errno, msg)
  465.  
  466.         try:
  467.             os.mkdir (instPath + '/proc')
  468.         except:
  469.             pass
  470.             
  471.     isys.mount('/proc', instPath + '/proc', 'proc')
  472.  
  473.     def write(self, prefix, fdDevice = "/dev/fd0"):
  474.     format = "%-23s %-23s %-7s %-15s %d %d\n";
  475.  
  476.     f = open (prefix + "/etc/fstab", "w")
  477.     for (mntpoint, dev, fs, reformat, size) in self.mountList():
  478.         if fs == "vfat" and mntpoint == "/":
  479.         f.write("# LOOP0: /dev/%s %s /redhat.img\n" % (dev, fs))
  480.         dev = "loop0"
  481.         fs = "ext2"
  482.  
  483.         iutil.mkdirChain(prefix + mntpoint)
  484.         if mntpoint == '/':
  485.         f.write (format % ( '/dev/' + dev, mntpoint, fs, 'defaults', 1, 1))
  486.         else:
  487.                 if fs == "ext2":
  488.                     f.write (format % ( '/dev/' + dev, mntpoint, fs, 'defaults', 1, 2))
  489.                 elif fs == "iso9660":
  490.                     f.write (format % ( '/dev/' + dev, mntpoint, fs, 'noauto,owner,ro', 0, 0))
  491.         elif fs == "auto" and (dev == "zip" or dev == "jaz"):
  492.             f.write (format % ( '/dev/' + dev, mntpoint, fs, 'noauto,owner', 0, 0))
  493.                 else:
  494.                     f.write (format % ( '/dev/' + dev, mntpoint, fs, 'defaults', 0, 0))
  495.     f.write (format % (fdDevice, "/mnt/floppy", 'auto', 'noauto,owner', 0, 0))
  496.     f.write (format % ("none", "/proc", 'proc', 'defaults', 0, 0))
  497.     f.write (format % ("none", "/dev/pts", 'devpts', 'gid=5,mode=620', 0, 0))
  498.  
  499.     if self.loopbackSwapSize:
  500.         f.write(format % ("/initrd/loopfs/rh-swap.img", 'swap',
  501.                 'swap', 'defaults', 0, 0))
  502.  
  503.     for (partition, doFormat) in self.swapList():
  504.         f.write (format % ("/dev/" + partition, 'swap', 'swap', 
  505.                    'defaults', 0, 0))
  506.  
  507.     f.close ()
  508.         # touch mtab
  509.         open (prefix + "/etc/mtab", "w+")
  510.         f.close ()
  511.  
  512.     self.createRaidTab(prefix + "/etc/raidtab", "/dev")
  513.  
  514.     def clearMounts(self):
  515.     self.extraFilesystems = []
  516.  
  517.     def addMount(self, partition, mount, fsystem, doFormat = 0, size = 0):
  518.     self.extraFilesystems.append(mount, partition, fsystem, doFormat,
  519.                      size)
  520. # XXX code from sparc merge
  521. #          if fsystem == "swap":
  522. #              ufs = 0
  523. #              try:
  524. #                  isys.makeDevInode(device, '/tmp/' + device)
  525. #              except:
  526. #                  pass
  527. #              try:
  528. #                  ufs = isys.checkUFS ('/tmp/' + device)
  529. #              except:
  530. #                  pass
  531. #              if not ufs:
  532. #                  location = "swap"
  533. #                  reformat = 1
  534. #          self.mounts[location] = (device, fsystem, reformat)
  535.  
  536.  
  537.     def mountList(self, skipExtra = 0):
  538.     def sortMounts(one, two):
  539.         mountOne = one[0]
  540.         mountTwo = two[0]
  541.         if (mountOne < mountTwo):
  542.         return -1
  543.         elif (mountOne == mountTwo):
  544.         return 0
  545.         return 1
  546.  
  547.     fstab = []
  548.     for (partition, mount, fsystem, size) in self.ddruid.getFstab():
  549.         if fsystem == "swap": continue
  550.  
  551.         if not self.fsCache.has_key((partition, mount)):
  552.         if mount == '/home' and isValidExt2(partition):
  553.             self.fsCache[(partition, mount)] = (0, )
  554.         else:
  555.             self.fsCache[(partition, mount)] = (1, )
  556.         (doFormat,) = self.fsCache[(partition, mount)]
  557.         fstab.append((mount, partition, fsystem, doFormat, size ))
  558.  
  559.     for (raidDevice, mntPoint, fsType, deviceList) in self.existingRaid:
  560.         if fsType == "swap": continue
  561.  
  562.         fstab.append((mntPoint, raidDevice, fsType, 0, 0 ))
  563.  
  564.     # Add raid mounts to mount list
  565.         (devices, raid) = self.raidList()
  566.     for (mntpoint, device, fsType, raidType, start, size, makeup) in raid:
  567.         if fsType == "swap": continue
  568.  
  569.         if not self.fsCache.has_key((device, mntpoint)):
  570.         self.fsCache[(device, mntpoint)] = (1, )
  571.         (doFormat,) = self.fsCache[(device, mntpoint)]
  572.         fstab.append((mntpoint, device, fsType, doFormat, size ))
  573.  
  574.     if not skipExtra:
  575.         for n in self.extraFilesystems:
  576.         (mntpoint, sevice, fsType, doFormat, size) = n
  577.         if fsType == "swap": continue
  578.         fstab.append(n)
  579.  
  580.     fstab.sort(sortMounts)
  581.  
  582.     return fstab
  583.  
  584.     def saveDruidPartitions(self):
  585.     if self.beenSaved: return
  586.     self.ddruid.save()
  587.     self.beenSaved = 1
  588.  
  589.     def setBadBlockCheck(self, state):
  590.     self.badBlockCheck = state
  591.  
  592.     def getBadBlockCheck(self):
  593.     return self.badBlockCheck
  594.  
  595.     def createDruid(self, fstab = [], ignoreBadDrives = 0):
  596.     return self.fsedit(0, self.driveList(), fstab, self.zeroMbr, 
  597.                self.readOnly, ignoreBadDrives)
  598.  
  599.     def getRunDruid(self):
  600.     return self.shouldRunDruid
  601.  
  602.     def setRunDruid(self, state):
  603.     self.shouldRunDruid = state
  604.  
  605.     def __init__(self, fsedit, setupFilesystems, serial, zeroMbr, 
  606.          readOnly, waitWindow, messageWindow):
  607.     self.fsedit = fsedit
  608.     self.fsCache = {}
  609.     self.swapOn = 0
  610.     self.supplementalRaid = []
  611.     self.beenSaved = 1
  612.     self.setupFilesystems = setupFilesystems
  613.     self.serial = serial
  614.     self.zeroMbr = zeroMbr
  615.     self.readOnly = readOnly
  616.     self.waitWindow = waitWindow
  617.     self.messageWindow = messageWindow
  618.     self.badBlockCheck = 0
  619.     self.extraFilesystems = []
  620.     self.existingRaid = []
  621.     self.ddruid = self.createDruid()
  622.     self.loopbackSize = 0
  623.     self.loopbackSwapSize = 0
  624.     # I intentionally don't initialize this, as all install paths should
  625.     # initialize this automatically
  626.     #self.shouldRunDruid = 0
  627.  
  628. class GuiFstab(Fstab):
  629.     def accel (self, widget, area):
  630.         self.accelgroup = self.GtkAccelGroup (_obj = widget.get_data ("accelgroup"))
  631.         self.toplevel = widget.get_toplevel()
  632.         self.toplevel.add_accel_group (self.accelgroup)
  633.  
  634.     def runDruid(self, callback):
  635.         self.ddruid.setCallback (callback)
  636.         bin = self.GtkFrame (None, _obj = self.ddruid.getWindow ())
  637.         bin.connect ("draw", self.accel)
  638.         bin.set_shadow_type (self.SHADOW_NONE)
  639.         self.ddruid.edit ()
  640.     return bin
  641.  
  642.     def runDruidFinished(self):
  643.         if self.accelgroup:
  644.             self.toplevel.remove_accel_group (self.accelgroup)        
  645.     self.ddruid.next ()
  646.     self.updateFsCache()
  647.     # yikes! this needs to be smarter
  648.     self.beenSaved = 0
  649.  
  650.     def __init__(self, setupFilesystems, serial, zeroMbr, readOnly, waitWindow,
  651.          messageWindow):
  652.     from gnomepyfsedit import fsedit        
  653.     from gtk import *
  654.  
  655.     Fstab.__init__(self, fsedit, setupFilesystems, serial, zeroMbr, 
  656.                readOnly, waitWindow, messageWindow)
  657.  
  658.     self.GtkFrame = GtkFrame
  659.         self.GtkAccelGroup = GtkAccelGroup
  660.     self.SHADOW_NONE = SHADOW_NONE
  661.         self.accelgroup = None
  662.  
  663. class NewtFstab(Fstab):
  664.  
  665.     def __init__(self, setupFilesystems, serial, zeroMbr, readOnly, waitWindow,
  666.          messageWindow):
  667.     from newtpyfsedit import fsedit        
  668.  
  669.     Fstab.__init__(self, fsedit, setupFilesystems, serial, zeroMbr, 
  670.                readOnly, waitWindow, messageWindow)
  671.  
  672. def readFstab (path, fstab):
  673.     f = open (path, "r")
  674.     lines = f.readlines ()
  675.     f.close
  676.  
  677.     fstab.clearExistingRaid()
  678.     fstab.clearMounts()
  679.  
  680.     drives = fstab.driveList()
  681.     raidList = raid.scanForRaid(drives)
  682.     raidByDev = {}
  683.     for (mdDev, devList) in raidList:
  684.     raidByDev[mdDev] = devList
  685.  
  686.     for line in lines:
  687.     fields = string.split (line)
  688.     # skip comments
  689.     if fields and fields[0][0] == '#':
  690.         continue
  691.     if not fields: continue
  692.     # all valid fstab entries have 6 fields
  693.     if len (fields) < 4 or len (fields) > 6: continue
  694.  
  695.     if fields[2] != "ext2" and fields[2] != "swap": continue
  696.     if string.find(fields[3], "noauto") != -1: continue
  697.     if (fields[0][0:7] != "/dev/hd" and 
  698.         fields[0][0:7] != "/dev/sd" and
  699.         fields[0][0:7] != "/dev/md" and
  700.         fields[0][0:8] != "/dev/rd/" and
  701.         fields[0][0:9] != "/dev/ida/"): continue
  702.  
  703.         if fields[0][0:7] == "/dev/md":
  704.         fstab.addExistingRaidDevice(fields[0][5:], fields[1], 
  705.                     fields[2], raidByDev[int(fields[0][7:])])
  706.     else:
  707.         fstab.addMount(fields[0][5:], fields[1], fields[2])
  708.