* - Ported to dump/restore
*/
+#include <config.h>
#include <stdio.h>
#include <sys/param.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
-#include <linux/ext2_fs.h>
-#include <ext2fs/ext2fs.h>
+#include <malloc.h>
#include "bylabel.h"
#define PROC_PARTITIONS "/proc/partitions"
#define DEVLABELDIR "/dev"
+#define EXT2_SUPER_OFFSET 1024
+#define EXT2_SUPER_SIZE sizeof(struct ext2_super_block)
+#define EXT2_SUPER_MAGIC 0xEF53
+
+struct ext2_super_block {
+ unsigned char s_dummy1[56];
+ unsigned char s_magic[2];
+ unsigned char s_dummy2[46];
+ unsigned char s_uuid[16];
+ unsigned char s_volume_name[16];
+};
+#define ext2magic(s) ((unsigned int) s.s_magic[0] + (((unsigned int) s.s_magic[1]) << 8))
+
void msg __P((const char *fmt, ...));
static struct uuidCache_s {
if (fd < 0)
return 1;
- if (lseek(fd, 1024, SEEK_SET) != 1024
- || read(fd, (char *) &e2sb, sizeof(e2sb)) != sizeof(e2sb)
- || (e2sb.s_magic != EXT2_SUPER_MAGIC)) {
+ if (lseek(fd, EXT2_SUPER_OFFSET, SEEK_SET) != EXT2_SUPER_OFFSET ||
+ read(fd, (char *) &e2sb, EXT2_SUPER_SIZE) != EXT2_SUPER_SIZE ||
+ ext2magic(e2sb) != EXT2_SUPER_MAGIC) {
close(fd);
return 1;
}
struct uuidCache_s *last;
if (!uuidCache) {
- last = uuidCache = malloc(sizeof(*uuidCache));
+ last = uuidCache = (struct uuidCache_s *)malloc(sizeof(*uuidCache));
} else {
for (last = uuidCache; last->next; last = last->next) ;
- last->next = malloc(sizeof(*uuidCache));
+ last->next = (struct uuidCache_s *)malloc(sizeof(*uuidCache));
last = last->next;
}
last->next = NULL;
return rc;
}
+
+const char *
+get_device_label(const char * spec) {
+ struct uuidCache_s *uc;
+
+ uuidcache_init();
+ uc = uuidCache;
+
+ while(uc) {
+ if (!strcmp(spec, uc->device))
+ return uc->label[0] == '\0' ? NULL : strdup(uc->label);
+ uc = uc->next;
+ }
+ return NULL;
+}