blkid: optional support for TYPE="fstype"
Adapted from patch created by T4ndeta <t4ndeta@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
		@@ -51,7 +51,7 @@ int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
		volume_id_set_label_string(id, cs->name, 16);
 | 
			
		||||
 | 
			
		||||
//		volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//		id->type = "cramfs";
 | 
			
		||||
		IF_FEATURE_BLKID_TYPE(id->type = "cramfs";)
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -65,10 +65,12 @@ int FAST_FUNC volume_id_probe_ext(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
	volume_id_set_uuid(id, es->uuid, UUID_DCE);
 | 
			
		||||
	dbg("ext: label '%s' uuid '%s'", id->label, id->uuid);
 | 
			
		||||
 | 
			
		||||
//	if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)
 | 
			
		||||
//		id->type = "ext3";
 | 
			
		||||
//	else
 | 
			
		||||
//		id->type = "ext2";
 | 
			
		||||
#if ENABLE_FEATURE_BLKID_TYPE
 | 
			
		||||
	if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)
 | 
			
		||||
		id->type = "ext3";
 | 
			
		||||
	else
 | 
			
		||||
		id->type = "ext2";
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -332,7 +332,7 @@ int FAST_FUNC volume_id_probe_vfat(struct volume_id *id /*,uint64_t fat_partitio
 | 
			
		||||
 | 
			
		||||
 ret:
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "vfat";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "vfat";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,14 +19,22 @@ static struct uuidCache_s {
 | 
			
		||||
	char *device;
 | 
			
		||||
	char *label;
 | 
			
		||||
	char *uc_uuid; /* prefix makes it easier to grep for */
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(const char *type;)
 | 
			
		||||
} *uuidCache;
 | 
			
		||||
 | 
			
		||||
#if !ENABLE_FEATURE_BLKID_TYPE
 | 
			
		||||
#define get_label_uuid(fd, label, uuid, type) \
 | 
			
		||||
	get_label_uuid(fd, label, uuid)
 | 
			
		||||
#define uuidcache_addentry(device, label, uuid, type) \
 | 
			
		||||
	uuidcache_addentry(device, label, uuid)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* Returns !0 on error.
 | 
			
		||||
 * Otherwise, returns malloc'ed strings for label and uuid
 | 
			
		||||
 * (and they can't be NULL, although they can be "").
 | 
			
		||||
 * NB: closes fd. */
 | 
			
		||||
static int
 | 
			
		||||
get_label_uuid(int fd, char **label, char **uuid)
 | 
			
		||||
get_label_uuid(int fd, char **label, char **uuid, const char **type)
 | 
			
		||||
{
 | 
			
		||||
	int rv = 1;
 | 
			
		||||
	uint64_t size;
 | 
			
		||||
@@ -44,7 +52,12 @@ get_label_uuid(int fd, char **label, char **uuid)
 | 
			
		||||
	if (vid->label[0] != '\0' || vid->uuid[0] != '\0') {
 | 
			
		||||
		*label = xstrndup(vid->label, sizeof(vid->label));
 | 
			
		||||
		*uuid  = xstrndup(vid->uuid, sizeof(vid->uuid));
 | 
			
		||||
#if ENABLE_FEATURE_BLKID_TYPE
 | 
			
		||||
		*type = vid->type;
 | 
			
		||||
		dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type);
 | 
			
		||||
#else
 | 
			
		||||
		dbg("found label '%s', uuid '%s'", *label, *uuid);
 | 
			
		||||
#endif
 | 
			
		||||
		rv = 0;
 | 
			
		||||
	}
 | 
			
		||||
 ret:
 | 
			
		||||
@@ -54,7 +67,7 @@ get_label_uuid(int fd, char **label, char **uuid)
 | 
			
		||||
 | 
			
		||||
/* NB: we take ownership of (malloc'ed) label and uuid */
 | 
			
		||||
static void
 | 
			
		||||
uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid)
 | 
			
		||||
uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type)
 | 
			
		||||
{
 | 
			
		||||
	struct uuidCache_s *last;
 | 
			
		||||
 | 
			
		||||
@@ -72,6 +85,7 @@ uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uu
 | 
			
		||||
	last->device = device;
 | 
			
		||||
	last->label = label;
 | 
			
		||||
	last->uc_uuid = uuid;
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(last->type = type;)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* If get_label_uuid() on device_name returns success,
 | 
			
		||||
@@ -83,10 +97,6 @@ uuidcache_check_device(const char *device,
 | 
			
		||||
		void *userData UNUSED_PARAM,
 | 
			
		||||
		int depth UNUSED_PARAM)
 | 
			
		||||
{
 | 
			
		||||
	char *uuid = uuid; /* for compiler */
 | 
			
		||||
	char *label = label;
 | 
			
		||||
	int fd;
 | 
			
		||||
 | 
			
		||||
	/* note: this check rejects links to devices, among other nodes */
 | 
			
		||||
	if (!S_ISBLK(statbuf->st_mode))
 | 
			
		||||
		return TRUE;
 | 
			
		||||
@@ -99,21 +109,15 @@ uuidcache_check_device(const char *device,
 | 
			
		||||
	if (major(statbuf->st_rdev) == 2)
 | 
			
		||||
		return TRUE;
 | 
			
		||||
 | 
			
		||||
	fd = open(device, O_RDONLY);
 | 
			
		||||
	if (fd < 0)
 | 
			
		||||
		return TRUE;
 | 
			
		||||
	add_to_uuid_cache(device);
 | 
			
		||||
 | 
			
		||||
	/* get_label_uuid() closes fd in all cases (success & failure) */
 | 
			
		||||
	if (get_label_uuid(fd, &label, &uuid) == 0) {
 | 
			
		||||
		/* uuidcache_addentry() takes ownership of all three params */
 | 
			
		||||
		uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid);
 | 
			
		||||
	}
 | 
			
		||||
	return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
uuidcache_init(void)
 | 
			
		||||
{
 | 
			
		||||
	dbg("DBG: uuidCache=%x, uuidCache");
 | 
			
		||||
	if (uuidCache)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
@@ -223,11 +227,38 @@ void display_uuid_cache(void)
 | 
			
		||||
			printf(" LABEL=\"%s\"", u->label);
 | 
			
		||||
		if (u->uc_uuid[0])
 | 
			
		||||
			printf(" UUID=\"%s\"", u->uc_uuid);
 | 
			
		||||
#if ENABLE_FEATURE_BLKID_TYPE
 | 
			
		||||
	if (u->type)
 | 
			
		||||
		printf(" TYPE=\"%s\"", u->type);
 | 
			
		||||
#endif
 | 
			
		||||
		bb_putchar('\n');
 | 
			
		||||
		u = u->next;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int add_to_uuid_cache(const char *device)
 | 
			
		||||
{
 | 
			
		||||
	char *uuid = uuid; /* for compiler */
 | 
			
		||||
	char *label = label;
 | 
			
		||||
#if ENABLE_FEATURE_BLKID_TYPE
 | 
			
		||||
	const char *type = type;
 | 
			
		||||
#endif
 | 
			
		||||
	int fd;
 | 
			
		||||
 | 
			
		||||
	fd = open(device, O_RDONLY);
 | 
			
		||||
	if (fd < 0)
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	/* get_label_uuid() closes fd in all cases (success & failure) */
 | 
			
		||||
	if (get_label_uuid(fd, &label, &uuid, &type) == 0) {
 | 
			
		||||
		/* uuidcache_addentry() takes ownership of all four params */
 | 
			
		||||
		uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid, type);
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Used by mount and findfs */
 | 
			
		||||
 | 
			
		||||
char *get_devname_from_label(const char *spec)
 | 
			
		||||
 
 | 
			
		||||
@@ -195,7 +195,7 @@ int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/
 | 
			
		||||
 | 
			
		||||
	volume_id_set_uuid(id, hfs->finder_info.id, UUID_HFS);
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "hfs";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "hfs";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -114,7 +114,7 @@ int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
 | 
			
		||||
 found:
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "iso9660";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "iso9660";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,7 @@ int FAST_FUNC volume_id_probe_jfs(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
	volume_id_set_uuid(id, js->uuid, UUID_DCE);
 | 
			
		||||
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "jfs";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "jfs";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -75,7 +75,7 @@ int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/,
 | 
			
		||||
 | 
			
		||||
	dbg("found raid signature");
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_RAID);
 | 
			
		||||
//	id->type = "linux_raid_member";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "linux_raid_member";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,7 @@ int FAST_FUNC volume_id_probe_linux_swap(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
 | 
			
		||||
found:
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_OTHER);
 | 
			
		||||
//	id->type = "swap";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "swap";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -94,7 +94,7 @@ int FAST_FUNC volume_id_probe_luks(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_CRYPTO);
 | 
			
		||||
	volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING);
 | 
			
		||||
//	id->type = "crypto_LUKS";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "crypto_LUKS";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -188,7 +188,7 @@ int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
 | 
			
		||||
 found:
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "ntfs";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "ntfs";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -101,6 +101,6 @@ int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
	volume_id_set_label_string(id, os->s_label, OCFS2_MAX_VOL_LABEL_LEN < VOLUME_ID_LABEL_SIZE ?
 | 
			
		||||
					OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE);
 | 
			
		||||
	volume_id_set_uuid(id, os->s_uuid, UUID_DCE);
 | 
			
		||||
//	id->type = "ocfs2";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "ocfs2";)
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -107,7 +107,7 @@ int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
 | 
			
		||||
 found:
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "reiserfs";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,7 @@ int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
//		volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//		id->type = "romfs";
 | 
			
		||||
		IF_FEATURE_BLKID_TYPE(id->type = "romfs";)
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -99,7 +99,7 @@ int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
		if (vs->s_magic == cpu_to_le32(SYSV_MAGIC) || vs->s_magic == cpu_to_be32(SYSV_MAGIC)) {
 | 
			
		||||
//			volume_id_set_label_raw(id, vs->s_fname, 6);
 | 
			
		||||
			volume_id_set_label_string(id, vs->s_fname, 6);
 | 
			
		||||
//			id->type = "sysv";
 | 
			
		||||
			IF_FEATURE_BLKID_TYPE(id->type = "sysv");
 | 
			
		||||
			goto found;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -112,7 +112,7 @@ int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
		if (xs->s_magic == cpu_to_le32(XENIX_MAGIC) || xs->s_magic == cpu_to_be32(XENIX_MAGIC)) {
 | 
			
		||||
//			volume_id_set_label_raw(id, xs->s_fname, 6);
 | 
			
		||||
			volume_id_set_label_string(id, xs->s_fname, 6);
 | 
			
		||||
//			id->type = "xenix";
 | 
			
		||||
			IF_FEATURE_BLKID_TYPE(id->type = "xenix";)
 | 
			
		||||
			goto found;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -167,7 +167,6 @@ anchor:
 | 
			
		||||
 | 
			
		||||
 found:
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "udf";
 | 
			
		||||
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "udf";)
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -80,7 +80,9 @@ struct volume_id {
 | 
			
		||||
//	char		type_version[VOLUME_ID_FORMAT_SIZE];
 | 
			
		||||
//	smallint	usage_id;
 | 
			
		||||
//	const char	*usage;
 | 
			
		||||
//	const char	*type;
 | 
			
		||||
#if ENABLE_FEATURE_BLKID_TYPE
 | 
			
		||||
	const char	*type;
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct volume_id* FAST_FUNC volume_id_open_node(int fd);
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,7 @@ int FAST_FUNC volume_id_probe_xfs(struct volume_id *id /*,uint64_t off*/)
 | 
			
		||||
	volume_id_set_uuid(id, xs->uuid, UUID_DCE);
 | 
			
		||||
 | 
			
		||||
//	volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
 | 
			
		||||
//	id->type = "xfs";
 | 
			
		||||
	IF_FEATURE_BLKID_TYPE(id->type = "xfs";)
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user