summaryrefslogtreecommitdiffstats
path: root/isys
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2007-12-03 12:59:39 -0500
committerJeremy Katz <katzj@redhat.com>2007-12-03 15:47:51 -0500
commitd6b03ab77abcf68c9dbb9f0c674c7dbf3548b786 (patch)
treef8d4b6f19989bc235780789eba6c3368e828a1c4 /isys
parentacd7e206ae041101203d1bb0011a37f735bdbf04 (diff)
downloadanaconda-d6b03ab77abcf68c9dbb9f0c674c7dbf3548b786.tar.gz
anaconda-d6b03ab77abcf68c9dbb9f0c674c7dbf3548b786.tar.xz
anaconda-d6b03ab77abcf68c9dbb9f0c674c7dbf3548b786.zip
Use libblkid instead of custom filesystem probing
This patch gets rid of all of our custom filesystem type and label probing and switches it all over to using a simple binding to libblkid instead.
Diffstat (limited to 'isys')
-rw-r--r--isys/Makefile2
-rw-r--r--isys/isys.c32
-rw-r--r--isys/isys.py169
3 files changed, 38 insertions, 165 deletions
diff --git a/isys/Makefile b/isys/Makefile
index 7b38cefc6..1ab65da2c 100644
--- a/isys/Makefile
+++ b/isys/Makefile
@@ -8,7 +8,7 @@ OBJECTS = nfsmount.o nfsmount_clnt.o nfsmount_xdr.o imount.o \
ethtool.o wireless.o eddsupport.o nl.o str.o auditd.o
SOBJECTS = $(patsubst %.o,%.lo,$(OBJECTS))
SOURCES = $(patsubst %.o,%.c,$(OBJECTS)) isys.c
-LOADLIBES = -lresolv -lpci -lpopt -lext2fs -lz -lkudzu -lpci -ldevmapper
+LOADLIBES = -lresolv -lpci -lpopt -lext2fs -lz -lkudzu -lpci -ldevmapper -lblkid
LOADLIBES += $(SELINUXLIBES)
ifeq ($(USESELINUX),1)
LOADLIBES += -laudit
diff --git a/isys/isys.c b/isys/isys.c
index dd2266973..eed25e5a1 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -49,6 +49,8 @@
#include <libdhcp/ip_addr.h>
#include <libdhcp/pump.h>
+#include <blkid/blkid.h>
+
#include "nl.h"
#include "imount.h"
#include "isys.h"
@@ -115,6 +117,7 @@ static PyObject * doGetBiosDisk(PyObject * s, PyObject * args);
static PyObject * doSegvHandler(PyObject *s, PyObject *args);
static PyObject * doAuditDaemon(PyObject *s);
static PyObject * doPrefixToNetmask(PyObject *s, PyObject *args);
+static PyObject * doGetBlkidData(PyObject * s, PyObject * args);
static PyMethodDef isysModuleMethods[] = {
{ "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL },
@@ -167,6 +170,7 @@ static PyMethodDef isysModuleMethods[] = {
{ "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL },
{ "auditdaemon", (PyCFunction) doAuditDaemon, METH_NOARGS, NULL },
{ "prefix2netmask", (PyCFunction) doPrefixToNetmask, METH_VARARGS, NULL },
+ { "getblkid", (PyCFunction) doGetBlkidData, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
} ;
@@ -1195,4 +1199,32 @@ static PyObject * doAuditDaemon(PyObject *s) {
return Py_None;
}
+static PyObject * doGetBlkidData(PyObject * s, PyObject * args) {
+ char * dev, * key;
+ blkid_cache cache;
+ blkid_dev bdev = NULL;
+ blkid_tag_iterate titer;
+ const char * type, * data;
+
+ if (!PyArg_ParseTuple(args, "ss", &dev, &key)) return NULL;
+
+ blkid_get_cache(&cache, NULL);
+
+ bdev = blkid_get_dev(cache, dev, BLKID_DEV_NORMAL);
+ if (bdev == NULL)
+ goto out;
+ titer = blkid_tag_iterate_begin(bdev);
+ while (blkid_tag_next(titer, &type, &data) >= 0) {
+ if (!strcmp(type, key)) {
+ blkid_tag_iterate_end(titer);
+ return Py_BuildValue("s", data);
+ }
+ }
+ blkid_tag_iterate_end(titer);
+
+ out:
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
/* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/isys.py b/isys/isys.py
index eb0b4cbd3..691c1d579 100644
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -769,176 +769,17 @@ def dhcpNetDevice(device):
return _isys.dhcpnetdevice(devname, v4, v4method, v6, v6method, klass)
-def _readXFSLabel_int(device):
- try:
- fd = os.open(device, os.O_RDONLY)
- except:
- return None
-
- try:
- buf = os.read(fd, 128)
- os.close(fd)
- except OSError, e:
- log.debug("error reading xfs label on %s: %s" %(device, e))
- try:
- os.close(fd)
- except:
- pass
- return None
-
- xfslabel = None
- if len(buf) == 128 and buf[0:4] == "XFSB":
- xfslabel = string.rstrip(buf[108:120],"\0x00")
-
- return xfslabel
-
-def readXFSLabel(device, makeDevNode = 1):
- if makeDevNode:
- makeDevInode(device, "/tmp/disk")
- label = _readXFSLabel_int("/tmp/disk")
- os.unlink("/tmp/disk")
- else:
- label = _readXFSLabel_int(device)
- return label
-
-def _readJFSLabel_int(device):
- jfslabel = None
- try:
- fd = os.open(device, os.O_RDONLY)
- except:
- return jfslabel
-
- try:
- os.lseek(fd, 32768, 0)
- buf = os.read(fd, 180)
- os.close(fd)
- except OSError, e:
- log.debug("error reading jfs label on %s: %s" %(device, e))
- try:
- os.close(fd)
- except:
- pass
- return jfslabel
-
- if (len(buf) == 180 and buf[0:4] == "JFS1"):
- jfslabel = string.rstrip(buf[152:168],"\0x00")
-
- return jfslabel
-
-def readJFSLabel(device, makeDevNode = 1):
- if makeDevNode:
- makeDevInode(device, "/tmp/disk")
- label = _readJFSLabel_int("/tmp/disk")
- os.unlink("/tmp/disk")
- else:
- label = _readJFSLabel_int(device)
- return label
-
-def _readSwapLabel_int(device):
- label = None
- try:
- fd = os.open(device, os.O_RDONLY)
- except:
- return label
-
- pagesize = resource.getpagesize()
- try:
- buf = os.read(fd, pagesize)
- os.close(fd)
- except OSError, e:
- log.debug("error reading swap label on %s: %s" %(device, e))
- try:
- os.close(fd)
- except:
- pass
- return label
-
- if ((len(buf) == pagesize) and (buf[pagesize - 10:] == "SWAPSPACE2")):
- label = string.rstrip(buf[1052:1068], "\0x00")
- return label
-
-def readSwapLabel(device, makeDevNode = 1):
+def readFSLabel(device, makeDevNode = 1):
if makeDevNode:
makeDevInode(device, "/tmp/disk")
- label = _readSwapLabel_int("/tmp/disk")
- os.unlink("/tmp/disk")
- else:
- label = _readSwapLabel_int(device)
- return label
-
-def readExt2Label(device, makeDevNode = 1):
+ device = "/tmp/disk"
+ label = _isys.getblkid(device, "LABEL")
if makeDevNode:
- makeDevInode(device, "/tmp/disk")
- label = _isys.e2fslabel("/tmp/disk");
os.unlink("/tmp/disk")
- else:
- label = _isys.e2fslabel(device)
return label
-def _readReiserFSLabel_int(device):
- label = None
-
- try:
- fd = os.open(device, os.O_RDONLY)
- except OSError, e:
- log.debug("error opening device %s: %s" % (device, e))
- return label
-
- # valid block sizes in reiserfs are 512 - 8192, powers of 2
- # we put 4096 first, since it's the default
- # reiserfs superblock occupies either the 2nd or 16th block
- for blksize in (4096, 512, 1024, 2048, 8192):
- for start in (blksize, (blksize*16)):
- try:
- os.lseek(fd, start, 0)
- # read 120 bytes to get s_magic and s_label
- buf = os.read(fd, 120)
-
- # see if this block is the superblock
- # this reads reiserfs_super_block_v1.s_magic as defined
- # in include/reiserfs_fs.h in the reiserfsprogs source
- m = string.rstrip(buf[52:61], "\0x00")
- if m == "ReIsErFs" or m == "ReIsEr2Fs" or m == "ReIsEr3Fs":
- # this reads reiserfs_super_block.s_label as
- # defined in include/reiserfs_fs.h
- label = string.rstrip(buf[100:116], "\0x00")
- os.close(fd)
- return label
- except OSError, e:
- # [Error 22] probably means we're trying to read an
- # extended partition.
- log.debug("error reading reiserfs label on %s: %s" %(device, e))
-
- try:
- os.close(fd)
- except:
- pass
-
- return label
-
- os.close(fd)
- return label
-
-def readReiserFSLabel(device, makeDevNode = 1):
- if makeDevNode:
- makeDevInode(device, "/tmp/disk")
- label = _readReiserFSLabel_int("/tmp/disk")
- os.unlink("/tmp/disk")
- else:
- label = _readReiserFSLabel_int(device)
- return label
-
-def readFSLabel(device, makeDevNode = 1):
- label = readExt2Label(device, makeDevNode)
- if label is None:
- label = readSwapLabel(device, makeDevNode)
- if label is None:
- label = readXFSLabel(device, makeDevNode)
- if label is None:
- label = readJFSLabel(device, makeDevNode)
- if label is None:
- label = readReiserFSLabel(device, makeDevNode)
- return label
+def readFSType(device):
+ return _isys.getblkid(device, "TYPE")
def ext2Clobber(device, makeDevNode = 1):
_isys.e2fsclobber(device)