File e2fsprogs-libvolume_id-support.patch of Package e2fsprogs

diff --git a/misc/Makefile.in b/misc/Makefile.in
index be362e9..80af1b3 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -40,7 +40,7 @@ UUIDD_OBJS=	uuidd.o
 DUMPE2FS_OBJS=	dumpe2fs.o
 BADBLOCKS_OBJS=	badblocks.o
 E2IMAGE_OBJS=	e2image.o
-FSCK_OBJS=	fsck.o base_device.o ismounted.o
+FSCK_OBJS=	fsck.o base_device.o ismounted.o fsck_volume_id.o
 BLKID_OBJS=	blkid.o
 FILEFRAG_OBJS=	filefrag.o
 
@@ -62,6 +62,9 @@ STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR)
 LIBS_BLKID= $(LIBBLKID) $(LIBUUID)
 DEPLIBS_BLKID= $(DEPLIBBLKID) $(DEPLIBUUID)
 
+LIBS_VOLID= -lvolume_id
+DEPLIBS_VOLID=
+
 LIBS_E2P= $(LIBE2P) $(LIBCOM_ERR) 
 DEPLIBS_E2P= $(LIBE2P) $(LIBCOM_ERR) 
 
@@ -117,10 +120,6 @@ base_device: base_device.c
 	@$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(srcdir)/base_device.c \
 		-DDEBUG -o base_device
 
-check:: base_device
-	./base_device < $(srcdir)/base_device.tst > base_device.out
-	cmp $(srcdir)/base_device.tst base_device.out
-
 mklost+found: $(MKLPF_OBJS)
 	@echo "	LD $@"
 	@$(CC) $(ALL_LDFLAGS) -o mklost+found $(MKLPF_OBJS) $(LIBINTL)
@@ -157,9 +156,9 @@ dumpe2fs: $(DUMPE2FS_OBJS) $(DEPLIBS) $(DEPLIBS_E2P) $(DEPLIBUUID)
 	@$(CC) $(ALL_LDFLAGS) -o dumpe2fs $(DUMPE2FS_OBJS) $(LIBS) \
 		$(LIBS_E2P) $(LIBUUID) $(LIBINTL)
 
-fsck: $(FSCK_OBJS) $(DEBLIBS_BLKID)
+fsck: $(FSCK_OBJS) $(DEBLIBS_VOLID)
 	@echo "	LD $@"
-	@$(CC) $(ALL_LDFLAGS) -o fsck $(FSCK_OBJS) $(LIBS_BLKID) $(LIBINTL)
+	@$(CC) $(ALL_LDFLAGS) -o fsck $(FSCK_OBJS) $(LIBS_VOLID) $(LIBINTL)
 
 badblocks: $(BADBLOCKS_OBJS) $(DEPLIBS)
 	@echo "	LD $@"
diff --git a/misc/base_device.c b/misc/base_device.c
index 6237d0e..c3261fc 100644
--- a/misc/base_device.c
+++ b/misc/base_device.c
@@ -27,6 +27,8 @@
 #endif
 #include <ctype.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <errno.h>
 
 #include "fsck.h"
 
diff --git a/misc/fsck.c b/misc/fsck.c
index 5cf1a1c..ad1d7a9 100644
--- a/misc/fsck.c
+++ b/misc/fsck.c
@@ -59,7 +59,6 @@
 #include "../version.h"
 #include "nls-enable.h"
 #include "fsck.h"
-#include "blkid/blkid.h"
 
 #ifndef _PATH_MNTTAB
 #define	_PATH_MNTTAB	"/etc/fstab"
@@ -118,7 +117,6 @@ struct fs_info *filesys_info = NULL, *filesys_last = NULL;
 struct fsck_instance *instance_list;
 const char *fsck_prefix_path = "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
 char *fsck_path = 0;
-blkid_cache cache = NULL;
 
 static char *string_copy(const char *s)
 {
@@ -296,7 +294,7 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
 	parse_escape(freq);
 	parse_escape(passno);
 
-	dev = blkid_get_devname(cache, device, NULL);
+	dev = fsck_get_devname(device);
 	if (dev)
 		device = dev;
 
@@ -321,7 +319,7 @@ static void interpret_type(struct fs_info *fs)
 	
 	if (strcmp(fs->type, "auto") != 0)
 		return;
-	t = blkid_get_tag_value(cache, "TYPE", fs->device);
+	t = fsck_get_fstype(fs->device);
 	if (t) {
 		free(fs->type);
 		fs->type = t;
@@ -1104,7 +1102,7 @@ static void PRS(int argc, char *argv[])
 					progname);
 				exit(EXIT_ERROR);
 			}
-			dev = blkid_get_devname(cache, arg, NULL);
+			dev = fsck_get_devname(arg);
 			if (!dev && strchr(arg, '=')) {
 				/*
 				 * Check to see if we failed because
@@ -1250,7 +1248,7 @@ int main(int argc, char *argv[])
 	bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
 	textdomain(NLS_CAT_NAME);
 #endif
-	blkid_get_cache(&cache, NULL);
+	fsck_get_cache(NULL);
 	PRS(argc, argv);
 
 	if (!notitle)
@@ -1319,6 +1317,6 @@ int main(int argc, char *argv[])
 	}
 	status |= wait_many(FLAG_WAIT_ALL);
 	free(fsck_path);
-	blkid_put_cache(cache);
+	fsck_put_cache();
 	return status;
 }
diff --git a/misc/fsck.h b/misc/fsck.h
index 55cb525..242b21e 100644
--- a/misc/fsck.h
+++ b/misc/fsck.h
@@ -66,5 +66,10 @@ struct fsck_instance {
 	struct fsck_instance *next;
 };
 
+extern int fsck_get_cache(const char *filename);
+extern void fsck_put_cache(void);
+extern char *fsck_get_devname(const char *device);
+extern char *fsck_get_fstype(const char *device);
+
 extern char *base_device(const char *device);
 extern const char *identify_fs(const char *fs_name, const char *fs_types);
diff --git a/misc/fsck_volume_id.c b/misc/fsck_volume_id.c
new file mode 100644
index 0000000..9456394
--- /dev/null
+++ b/misc/fsck_volume_id.c
@@ -0,0 +1,132 @@
+/*
+ * Wrapper for libvolume_id
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/mount.h>
+#include <sys/ioctl.h>
+#include <stddef.h>
+#include <libvolume_id.h>
+
+#include "fsck.h"
+
+int fsck_get_cache(const char *filename)
+{
+	return 0;
+}
+
+void fsck_put_cache(void)
+{
+}
+
+static char *fsck_get_devname_by_uuid(const char *uuid)
+{
+	char *dev = NULL;
+
+	if (!uuid)
+		return NULL;
+
+	dev = malloc(19 + strlen(uuid));
+	if (dev) {
+		strcpy(dev,"/dev/disk/by-uuid/");
+		strcat(dev,uuid);
+	}
+
+	return dev;
+}
+
+static char *fsck_get_devname_by_label(const char *label)
+{
+	char *dev = NULL;
+
+	if (!label)
+		return NULL;
+
+	dev = malloc(20 + strlen(label));
+	if (dev) {
+		strcpy(dev,"/dev/disk/by-label/");
+		strcat(dev,label);
+	}
+
+	return dev;
+}
+
+char *fsck_get_devname(const char *spec)
+{
+	char *token, *cp, *value;
+	char *nspec = NULL;
+
+	if (!spec)
+		return NULL;
+
+	token = strdup(spec);
+	if (!token)
+		return NULL;
+
+	/* We have to return an allocated string */
+	if (!(cp = strchr(token, '=')))
+		return token;
+
+	value = token + (cp - token);
+	*value++ = '\0';
+
+	if (*value == '"' || *value == '\'') {
+		char c = *value++;
+		if (!(cp = strrchr(value, c)))
+			goto errout; /* missing closing quote */
+		*cp = '\0';
+	}
+	
+	if (!strcmp(token,"LABEL")) {
+		nspec = fsck_get_devname_by_label(value);
+	} else if (!strcmp(token,"UUID")) {
+		nspec = fsck_get_devname_by_uuid(value);
+	}
+
+	free(token);
+
+ errout:
+	return nspec;
+}       
+
+char *fsck_get_fstype(const char *device)
+{
+	int fd = -1;
+	struct volume_id *vid = NULL;
+	uint64_t size;
+	const char *s;
+	char *value = NULL;
+
+	if (!device)
+		return NULL;
+
+	fd = open(device, O_RDONLY);
+	if (fd < 0)
+		return NULL;
+
+	vid = volume_id_open_fd(fd);
+	if (!vid)
+		goto out;
+
+	if (ioctl(fd, BLKGETSIZE64, &size) != 0)
+		size = 0;
+
+	if (volume_id_probe_all(vid, 0, size) != 0)
+		goto out;
+
+	if (!volume_id_get_type(vid, &s))
+		goto out;
+
+	value = strdup(s);
+out:
+	if (vid != NULL)
+		volume_id_close(vid);
+	if (fd >= 0)
+		close(fd);
+
+	return value;
+}
openSUSE Build Service is sponsored by