From 3d419435be4b7271277b25420a5a9d148526e320 Mon Sep 17 00:00:00 2001 From: Jeremy Katz Date: Wed, 23 Jan 2002 20:00:43 +0000 Subject: merge in the generic parts of the xfs changes from sgi and in the process take care of some of our multifsification --- fsset.py | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 6 deletions(-) (limited to 'fsset.py') diff --git a/fsset.py b/fsset.py index 5e30374eb..ef4a223d2 100644 --- a/fsset.py +++ b/fsset.py @@ -59,6 +59,19 @@ def fileSystemTypeRegister(klass): def fileSystemTypeGetTypes(): return fileSystemTypes.copy() +def getUsableLinuxFs(): + rc = [] + for fsType in fileSystemTypes.keys(): + if fileSystemTypes[fsType].isMountable() and \ + fileSystemTypes[fsType].isLinuxNativeFS(): + rc.append(fsType) + + # make sure the default is first in the list, kind of ugly + default = fileSystemTypeGetDefault() + if default in rc: + rc = [ default ] + rc.remove(default) + return rc + def mountCompare(a, b): one = a.mountpoint two = b.mountpoint @@ -77,7 +90,7 @@ class LabelFactory: def __init__(self): self.labels = None - def createLabel(self, mountpoint): + def createLabel(self, mountpoint, maxLabelChars): if self.labels == None: self.labels = {} @@ -89,16 +102,16 @@ class LabelFactory: del diskset self.reserveLabels(labels) - if len(mountpoint) > 16: - mountpoint = mountpoint[0:16] + if len(mountpoint) > maxLabelChars: + mountpoint = mountpoint[0:maxLabelChars] count = 0 while self.labels.has_key(mountpoint): count = count + 1 s = "%s" % count - if (len(mountpoint) + len(s)) <= 16: + if (len(mountpoint) + len(s)) <= maxLabelChars: mountpoint = mountpoint + s else: - strip = len(mountpoint) + len(s) - 16 + strip = len(mountpoint) + len(s) - maxLabelChars mountpoint = mountpoint[0:len(mountpoint) - strip] + s self.labels[mountpoint] = 1 @@ -127,6 +140,7 @@ class FileSystemType: self.defaultOptions = "defaults" self.migratetofs = None self.extraFormatArgs = [] + self.maxLabelChars = 16 def mount(self, device, mountpoint, readOnly=0): if not self.isMountable(): @@ -244,6 +258,7 @@ class FileSystemType: else: return 0 + class reiserfsFileSystem(FileSystemType): def __init__(self): FileSystemType.__init__(self) @@ -288,6 +303,47 @@ class reiserfsFileSystem(FileSystemType): fileSystemTypeRegister(reiserfsFileSystem()) +class xfsFileSystem(FileSystemType): + def __init__(self): + FileSystemType.__init__(self) + self.partedFileSystemType = parted.file_system_type_get("xfs") + self.formattable = 1 + self.checked = 1 + self.linuxnativefs = 1 + self.name = "xfs" + self.maxSize = 2 * 1024 * 1024 + self.maxLabelChars = 12 + # we don't even have the module, so it won't be mountable... but + # just in case + self.supported = 0 + + def formatDevice(self, entry, progress, chroot='/'): + devicePath = entry.device.setupDevice(chroot) + + rc = iutil.execWithRedirect("/usr/sbin/mkfs.xfs", + ["mkfs.xfs", "-f", "-l", "internal", + devicePath ], + stdout = "/dev/tty5", + stderr = "/dev/tty5") + + if rc: + raise SystemError + + def labelDevice(self, entry, chroot): + devicePath = entry.device.setupDevice(chroot) + label = labelFactory.createLabel(entry.mountpoint, self.maxLabelChars) + db_cmd = "label " + label + rc = iutil.execWithRedirect("/usr/sbin/xfs_db", + ["xfs_db", "-x", "-c", db_cmd, + devicePath], + stdout = "/dev/tty5", + stderr = "/dev/tty5") + if rc: + raise SystemError + entry.setLabel(label) + +fileSystemTypeRegister(xfsFileSystem()) + class extFileSystem(FileSystemType): def __init__(self): FileSystemType.__init__(self) @@ -299,7 +355,7 @@ class extFileSystem(FileSystemType): def labelDevice(self, entry, chroot): devicePath = entry.device.setupDevice(chroot) - label = labelFactory.createLabel(entry.mountpoint) + label = labelFactory.createLabel(entry.mountpoint, self.maxLabelChars) rc = iutil.execWithRedirect("/usr/sbin/e2label", ["e2label", devicePath, label], stdout = "/dev/tty5", @@ -1467,6 +1523,40 @@ def isValidExt2(device): return 0 +def isValidXFS(device): + file = '/tmp/' + device + isys.makeDevInode(device, file) + try: + fd = os.open(file, os.O_RDONLY) + except: + return 0 + + buf = os.read(fd, 4) + os.close(fd) + + if len(buf) != 4: + return 0 + + if buf == "XFSB": + return 1 + + return 0 + +# this will return a list of types of filesystems which device +# looks like it could be to try mounting as +def getFStoTry(device): + rc = [] + + if isValidXFS(device): + rc.append("xfs") + + if isValidExt2(device): + rc.append("ext2") + rc.append("ext3") + + # XXX check for reiserfs signature, jfs signature, and others ? + return rc + def allocateLoopback(file): found = 1 for i in range(8): -- cgit