2003-01-24 00:45:16 +03:00
|
|
|
/*
|
|
|
|
* probe.c - identify a block device by its contents, and return a dev
|
|
|
|
* struct with the details
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 by Andries Brouwer
|
2003-02-13 07:51:21 +03:00
|
|
|
* Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
|
2003-01-24 00:45:16 +03:00
|
|
|
* Copyright (C) 2001 by Andreas Dilger
|
2005-09-11 05:51:20 +04:00
|
|
|
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
|
2003-01-24 00:45:16 +03:00
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the
|
|
|
|
* GNU Lesser General Public License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2008-02-27 10:06:08 +03:00
|
|
|
#include <ctype.h>
|
2003-01-24 00:45:16 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MKDEV_H
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#endif
|
2008-02-09 00:04:12 +03:00
|
|
|
#include <sys/utsname.h>
|
2003-01-24 00:45:16 +03:00
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
2003-01-26 09:54:39 +03:00
|
|
|
#include "blkidP.h"
|
2003-01-24 00:45:16 +03:00
|
|
|
#include "uuid/uuid.h"
|
|
|
|
#include "probe.h"
|
|
|
|
|
2005-09-10 23:46:57 +04:00
|
|
|
static int figure_label_len(const unsigned char *label, int len)
|
|
|
|
{
|
|
|
|
const unsigned char *end = label + len - 1;
|
|
|
|
|
|
|
|
while ((*end == ' ' || *end == 0) && end >= label)
|
|
|
|
--end;
|
|
|
|
if (end >= label) {
|
|
|
|
label = label;
|
|
|
|
return end - label + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static unsigned char *get_buffer(struct blkid_probe *pr,
|
2007-06-19 11:29:47 +04:00
|
|
|
blkid_loff_t off, size_t len)
|
2005-09-11 05:07:23 +04:00
|
|
|
{
|
|
|
|
ssize_t ret_read;
|
|
|
|
unsigned char *newbuf;
|
|
|
|
|
|
|
|
if (off + len <= SB_BUFFER_SIZE) {
|
|
|
|
if (!pr->sbbuf) {
|
|
|
|
pr->sbbuf = malloc(SB_BUFFER_SIZE);
|
|
|
|
if (!pr->sbbuf)
|
|
|
|
return NULL;
|
|
|
|
if (lseek(pr->fd, 0, SEEK_SET) < 0)
|
|
|
|
return NULL;
|
|
|
|
ret_read = read(pr->fd, pr->sbbuf, SB_BUFFER_SIZE);
|
|
|
|
if (ret_read < 0)
|
|
|
|
ret_read = 0;
|
|
|
|
pr->sb_valid = ret_read;
|
|
|
|
}
|
|
|
|
if (off+len > pr->sb_valid)
|
|
|
|
return NULL;
|
|
|
|
return pr->sbbuf + off;
|
|
|
|
} else {
|
|
|
|
if (len > pr->buf_max) {
|
|
|
|
newbuf = realloc(pr->buf, len);
|
|
|
|
if (newbuf == NULL)
|
|
|
|
return NULL;
|
|
|
|
pr->buf = newbuf;
|
|
|
|
pr->buf_max = len;
|
|
|
|
}
|
2007-06-19 11:29:47 +04:00
|
|
|
if (blkid_llseek(pr->fd, off, SEEK_SET) < 0)
|
2005-09-11 05:07:23 +04:00
|
|
|
return NULL;
|
|
|
|
ret_read = read(pr->fd, pr->buf, len);
|
|
|
|
if (ret_read != (ssize_t) len)
|
|
|
|
return NULL;
|
|
|
|
return pr->buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
/*
|
2003-02-13 07:51:21 +03:00
|
|
|
* This is a special case code to check for an MDRAID device. We do
|
|
|
|
* this special since it requires checking for a superblock at the end
|
|
|
|
* of the device.
|
2003-01-24 00:45:16 +03:00
|
|
|
*/
|
2003-02-13 07:51:21 +03:00
|
|
|
static int check_mdraid(int fd, unsigned char *ret_uuid)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
2003-02-13 07:51:21 +03:00
|
|
|
struct mdp_superblock_s *md;
|
|
|
|
blkid_loff_t offset;
|
|
|
|
char buf[4096];
|
|
|
|
|
|
|
|
if (fd < 0)
|
2003-01-24 00:45:16 +03:00
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
offset = (blkid_get_dev_size(fd) & ~((blkid_loff_t)65535)) - 65536;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
if (blkid_llseek(fd, offset, 0) < 0 ||
|
2003-02-13 07:51:21 +03:00
|
|
|
read(fd, buf, 4096) != 4096)
|
2003-01-24 00:45:16 +03:00
|
|
|
return -BLKID_ERR_IO;
|
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
/* Check for magic number */
|
2007-04-10 19:59:46 +04:00
|
|
|
if (memcmp("\251+N\374", buf, 4) && memcmp("\374N+\251", buf, 4))
|
2003-01-24 00:45:16 +03:00
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (!ret_uuid)
|
|
|
|
return 0;
|
|
|
|
*ret_uuid = 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
/* The MD UUID is not contiguous in the superblock, make it so */
|
|
|
|
md = (struct mdp_superblock_s *)buf;
|
|
|
|
if (md->set_uuid0 || md->set_uuid1 || md->set_uuid2 || md->set_uuid3) {
|
|
|
|
memcpy(ret_uuid, &md->set_uuid0, 4);
|
2007-04-10 20:00:38 +04:00
|
|
|
memcpy(ret_uuid + 4, &md->set_uuid1, 12);
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
2003-02-13 07:51:21 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2007-08-04 02:56:01 +04:00
|
|
|
static void set_uuid(blkid_dev dev, uuid_t uuid, const char *tag)
|
2003-02-13 07:51:21 +03:00
|
|
|
{
|
|
|
|
char str[37];
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (!uuid_is_null(uuid)) {
|
|
|
|
uuid_unparse(uuid, str);
|
2006-03-11 02:11:35 +03:00
|
|
|
blkid_set_tag(dev, tag ? tag : "UUID", str, sizeof(str));
|
2003-02-13 07:51:21 +03:00
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
static void get_ext2_info(blkid_dev dev, struct blkid_magic *id,
|
|
|
|
unsigned char *buf)
|
2005-01-06 01:45:32 +03:00
|
|
|
{
|
|
|
|
struct ext2_super_block *es = (struct ext2_super_block *) buf;
|
|
|
|
const char *label = 0;
|
|
|
|
|
|
|
|
DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
|
|
|
|
blkid_le32(es->s_feature_compat),
|
|
|
|
blkid_le32(es->s_feature_incompat),
|
|
|
|
blkid_le32(es->s_feature_ro_compat)));
|
|
|
|
|
2005-01-11 07:58:11 +03:00
|
|
|
if (strlen(es->s_volume_name))
|
2005-01-06 01:45:32 +03:00
|
|
|
label = es->s_volume_name;
|
2005-01-11 07:58:11 +03:00
|
|
|
blkid_set_tag(dev, "LABEL", label, sizeof(es->s_volume_name));
|
2005-01-06 01:45:32 +03:00
|
|
|
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(dev, es->s_uuid, 0);
|
2008-01-27 06:25:50 +03:00
|
|
|
|
|
|
|
if ((es->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
|
|
|
|
!uuid_is_null(es->s_journal_uuid))
|
|
|
|
set_uuid(dev, es->s_journal_uuid, "EXT_JOURNAL");
|
|
|
|
|
|
|
|
if (strcmp(id->bim_type, "ext2") &&
|
|
|
|
((blkid_le32(es->s_feature_incompat) &
|
|
|
|
EXT2_FEATURE_INCOMPAT_UNSUPPORTED) == 0))
|
|
|
|
blkid_set_tag(dev, "SEC_TYPE", "ext2", sizeof("ext2"));
|
2005-01-06 01:45:32 +03:00
|
|
|
}
|
|
|
|
|
2008-02-09 00:04:12 +03:00
|
|
|
/*
|
|
|
|
* Check to see if a filesystem is in /proc/filesystems.
|
|
|
|
* Returns 1 if found, 0 if not
|
|
|
|
*/
|
2008-02-27 10:06:08 +03:00
|
|
|
static int fs_proc_check(const char *fs_name)
|
2008-02-09 00:04:12 +03:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[80], *cp, *t;
|
|
|
|
|
|
|
|
f = fopen("/proc/filesystems", "r");
|
|
|
|
if (!f)
|
|
|
|
return (0);
|
|
|
|
while (!feof(f)) {
|
|
|
|
if (!fgets(buf, sizeof(buf), f))
|
|
|
|
break;
|
|
|
|
cp = buf;
|
|
|
|
if (!isspace(*cp)) {
|
|
|
|
while (*cp && !isspace(*cp))
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
while (*cp && isspace(*cp))
|
|
|
|
cp++;
|
|
|
|
if ((t = strchr(cp, '\n')) != NULL)
|
|
|
|
*t = 0;
|
|
|
|
if ((t = strchr(cp, '\t')) != NULL)
|
|
|
|
*t = 0;
|
|
|
|
if ((t = strchr(cp, ' ')) != NULL)
|
|
|
|
*t = 0;
|
|
|
|
if (!strcmp(fs_name, cp)) {
|
|
|
|
fclose(f);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if a filesystem is available as a module
|
|
|
|
* Returns 1 if found, 0 if not
|
|
|
|
*/
|
2008-02-27 10:06:08 +03:00
|
|
|
static int check_for_modules(const char *fs_name)
|
2008-02-09 00:04:12 +03:00
|
|
|
{
|
|
|
|
struct utsname uts;
|
|
|
|
FILE *f;
|
|
|
|
char buf[1024], *cp, *t;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (uname(&uts))
|
|
|
|
return (0);
|
|
|
|
snprintf(buf, sizeof(buf), "/lib/modules/%s/modules.dep", uts.release);
|
|
|
|
|
|
|
|
f = fopen(buf, "r");
|
|
|
|
if (!f)
|
|
|
|
return (0);
|
|
|
|
while (!feof(f)) {
|
|
|
|
if (!fgets(buf, sizeof(buf), f))
|
|
|
|
break;
|
|
|
|
if ((cp = strchr(buf, ':')) != NULL)
|
|
|
|
*cp = 0;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
if ((cp = strrchr(buf, '/')) != NULL)
|
|
|
|
cp++;
|
|
|
|
i = strlen(cp);
|
|
|
|
if (i > 3) {
|
|
|
|
t = cp + i - 3;
|
|
|
|
if (!strcmp(t, ".ko"))
|
|
|
|
*t = 0;
|
|
|
|
}
|
|
|
|
if (!strcmp(cp, fs_name))
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-02-27 10:06:08 +03:00
|
|
|
static int system_supports_ext4(void)
|
2008-02-09 00:04:12 +03:00
|
|
|
{
|
|
|
|
static time_t last_check = 0;
|
|
|
|
static int ret = -1;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
if (ret != -1 || (last_check - now) < 5)
|
|
|
|
return ret;
|
|
|
|
last_check = now;
|
|
|
|
ret = (fs_proc_check("ext4") || check_for_modules("ext4"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-02-27 10:06:08 +03:00
|
|
|
static int system_supports_ext4dev(void)
|
2008-02-09 00:04:12 +03:00
|
|
|
{
|
|
|
|
static time_t last_check = 0;
|
|
|
|
static int ret = -1;
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
if (ret != -1 || (last_check - now) < 5)
|
|
|
|
return ret;
|
|
|
|
last_check = now;
|
|
|
|
ret = (fs_proc_check("ext4dev") || check_for_modules("ext4dev"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
static int probe_ext4dev(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id,
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct ext2_super_block *es;
|
|
|
|
es = (struct ext2_super_block *)buf;
|
|
|
|
|
|
|
|
/* Distinguish from jbd */
|
|
|
|
if (blkid_le32(es->s_feature_incompat) &
|
|
|
|
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
|
|
|
/* ext4dev requires a journal */
|
|
|
|
if (!(blkid_le32(es->s_feature_compat) &
|
|
|
|
EXT3_FEATURE_COMPAT_HAS_JOURNAL))
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2008-02-09 00:04:12 +03:00
|
|
|
/*
|
|
|
|
* If the filesystem is marked as OK for use by in-development
|
|
|
|
* filesystem code, but ext4dev is not supported, and ext4 is,
|
|
|
|
* then don't call ourselves ext4dev, since we should be
|
|
|
|
* detected as ext4 in that case.
|
|
|
|
*
|
|
|
|
* If the filesystem is marked as in use by production
|
|
|
|
* filesystem, then it can only be used by ext4 and NOT by
|
|
|
|
* ext4dev, so always disclaim we are ext4dev in that case.
|
|
|
|
*/
|
|
|
|
if (blkid_le32(es->s_flags) & EXT2_FLAGS_TEST_FILESYS) {
|
|
|
|
if (!system_supports_ext4dev() && system_supports_ext4())
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
} else
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
get_ext2_info(probe->dev, id, buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int probe_ext4(struct blkid_probe *probe, struct blkid_magic *id,
|
2005-05-07 22:38:10 +04:00
|
|
|
unsigned char *buf)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
|
|
|
struct ext2_super_block *es;
|
|
|
|
es = (struct ext2_super_block *)buf;
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
/* Distinguish from jbd */
|
2005-01-06 01:45:32 +03:00
|
|
|
if (blkid_le32(es->s_feature_incompat) &
|
|
|
|
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
|
2003-01-24 00:45:16 +03:00
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
/* ext4 requires journal */
|
2005-01-06 01:45:32 +03:00
|
|
|
if (!(blkid_le32(es->s_feature_compat) &
|
|
|
|
EXT3_FEATURE_COMPAT_HAS_JOURNAL))
|
|
|
|
return -BLKID_ERR_PARAM;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
/* Ext4 has at least one feature which ext3 doesn't understand */
|
|
|
|
if (!(blkid_le32(es->s_feature_ro_compat) &
|
|
|
|
EXT3_FEATURE_RO_COMPAT_UNSUPPORTED) &&
|
|
|
|
!(blkid_le32(es->s_feature_incompat) &
|
|
|
|
EXT3_FEATURE_INCOMPAT_UNSUPPORTED))
|
|
|
|
return -BLKID_ERR_PARAM;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2008-02-09 00:04:12 +03:00
|
|
|
/*
|
|
|
|
* If the filesystem is a OK for use by in-development
|
|
|
|
* filesystem code, and ext4dev is supported or ext4 is not
|
|
|
|
* supported, then don't call ourselves ext4, so we can redo
|
|
|
|
* the detection and mark the filesystem as ext4dev.
|
|
|
|
*
|
|
|
|
* If the filesystem is marked as in use by production
|
|
|
|
* filesystem, then it can only be used by ext4 and NOT by
|
|
|
|
* ext4dev.
|
|
|
|
*/
|
|
|
|
if (blkid_le32(es->s_flags) & EXT2_FLAGS_TEST_FILESYS) {
|
|
|
|
if (system_supports_ext4dev() || !system_supports_ext4())
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
}
|
2008-01-27 06:25:50 +03:00
|
|
|
get_ext2_info(probe->dev, id, buf);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-11 02:11:35 +03:00
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
static int probe_ext3(struct blkid_probe *probe, struct blkid_magic *id,
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct ext2_super_block *es;
|
|
|
|
es = (struct ext2_super_block *)buf;
|
2005-01-06 01:45:32 +03:00
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
/* Distinguish from ext4dev */
|
|
|
|
if (blkid_le32(es->s_flags) & EXT2_FLAGS_TEST_FILESYS)
|
|
|
|
return -BLKID_ERR_PARAM;
|
2006-03-11 02:11:35 +03:00
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
/* ext3 requires journal */
|
|
|
|
if (!(blkid_le32(es->s_feature_compat) &
|
|
|
|
EXT3_FEATURE_COMPAT_HAS_JOURNAL))
|
|
|
|
return -BLKID_ERR_PARAM;
|
2005-01-06 01:45:32 +03:00
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
/* Any features which ext3 doesn't understand */
|
|
|
|
if ((blkid_le32(es->s_feature_ro_compat) &
|
|
|
|
EXT3_FEATURE_RO_COMPAT_UNSUPPORTED) ||
|
|
|
|
(blkid_le32(es->s_feature_incompat) &
|
|
|
|
EXT3_FEATURE_INCOMPAT_UNSUPPORTED))
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
|
|
|
get_ext2_info(probe->dev, id, buf);
|
2005-01-06 01:45:32 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
static int probe_ext2(struct blkid_probe *probe, struct blkid_magic *id,
|
2005-05-07 22:38:10 +04:00
|
|
|
unsigned char *buf)
|
2005-01-06 01:45:32 +03:00
|
|
|
{
|
|
|
|
struct ext2_super_block *es;
|
|
|
|
|
|
|
|
es = (struct ext2_super_block *)buf;
|
|
|
|
|
2005-09-06 14:26:45 +04:00
|
|
|
/* Distinguish between ext3 and ext2 */
|
|
|
|
if ((blkid_le32(es->s_feature_compat) &
|
|
|
|
EXT3_FEATURE_COMPAT_HAS_JOURNAL))
|
|
|
|
return -BLKID_ERR_PARAM;
|
2005-01-06 01:45:32 +03:00
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
/* Any features which ext2 doesn't understand */
|
|
|
|
if ((blkid_le32(es->s_feature_ro_compat) &
|
|
|
|
EXT2_FEATURE_RO_COMPAT_UNSUPPORTED) ||
|
|
|
|
(blkid_le32(es->s_feature_incompat) &
|
|
|
|
EXT2_FEATURE_INCOMPAT_UNSUPPORTED))
|
|
|
|
return -BLKID_ERR_PARAM;
|
2003-02-23 01:15:20 +03:00
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
get_ext2_info(probe->dev, id, buf);
|
2003-01-24 00:45:16 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
static int probe_jbd(struct blkid_probe *probe, struct blkid_magic *id,
|
2003-12-07 09:28:50 +03:00
|
|
|
unsigned char *buf)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
2003-02-13 07:51:21 +03:00
|
|
|
struct ext2_super_block *es = (struct ext2_super_block *) buf;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-01-27 09:09:24 +03:00
|
|
|
if (!(blkid_le32(es->s_feature_incompat) &
|
2003-02-13 07:51:21 +03:00
|
|
|
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV))
|
2003-01-24 00:45:16 +03:00
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2008-01-27 06:25:50 +03:00
|
|
|
get_ext2_info(probe->dev, id, buf);
|
2005-01-06 01:45:32 +03:00
|
|
|
|
|
|
|
return 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
2005-09-11 05:51:20 +04:00
|
|
|
#define FAT_ATTR_VOLUME_ID 0x08
|
|
|
|
#define FAT_ATTR_DIR 0x10
|
|
|
|
#define FAT_ATTR_LONG_NAME 0x0f
|
|
|
|
#define FAT_ATTR_MASK 0x3f
|
|
|
|
#define FAT_ENTRY_FREE 0xe5
|
|
|
|
|
2007-08-04 02:56:01 +04:00
|
|
|
static const char *no_name = "NO NAME ";
|
2005-09-11 05:51:20 +04:00
|
|
|
|
|
|
|
static unsigned char *search_fat_label(struct vfat_dir_entry *dir, int count)
|
|
|
|
{
|
2006-05-30 03:48:51 +04:00
|
|
|
int i;
|
2005-09-11 05:51:20 +04:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (dir[i].name[0] == 0x00)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((dir[i].name[0] == FAT_ENTRY_FREE) ||
|
|
|
|
(dir[i].cluster_high != 0 || dir[i].cluster_low != 0) ||
|
|
|
|
((dir[i].attr & FAT_ATTR_MASK) == FAT_ATTR_LONG_NAME))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((dir[i].attr & (FAT_ATTR_VOLUME_ID | FAT_ATTR_DIR)) ==
|
|
|
|
FAT_ATTR_VOLUME_ID) {
|
|
|
|
return dir[i].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FAT label extraction from the root directory taken from Kay
|
|
|
|
* Sievers's volume_id library */
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_fat(struct blkid_probe *probe,
|
2003-12-07 09:28:50 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
2005-09-07 20:14:53 +04:00
|
|
|
struct vfat_super_block *vs = (struct vfat_super_block *) buf;
|
|
|
|
struct msdos_super_block *ms = (struct msdos_super_block *) buf;
|
2005-09-11 05:51:20 +04:00
|
|
|
struct vfat_dir_entry *dir;
|
2003-01-24 00:45:16 +03:00
|
|
|
char serno[10];
|
2006-05-30 17:47:12 +04:00
|
|
|
const unsigned char *label = 0, *vol_label = 0, *tmp;
|
2005-09-07 20:14:53 +04:00
|
|
|
unsigned char *vol_serno;
|
2005-09-11 05:51:20 +04:00
|
|
|
int label_len = 0, maxloop = 100;
|
|
|
|
__u16 sector_size, dir_entries, reserved;
|
|
|
|
__u32 sect_count, fat_size, dir_size, cluster_count, fat_length;
|
|
|
|
__u32 buf_size, start_data_sect, next, root_start, root_dir_entries;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-09-07 20:14:53 +04:00
|
|
|
/* sector size check */
|
2006-05-30 18:29:49 +04:00
|
|
|
tmp = (unsigned char *)&ms->ms_sector_size;
|
|
|
|
sector_size = tmp[0] + (tmp[1] << 8);
|
2005-09-07 20:14:53 +04:00
|
|
|
if (sector_size != 0x200 && sector_size != 0x400 &&
|
|
|
|
sector_size != 0x800 && sector_size != 0x1000)
|
|
|
|
return 1;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2006-05-30 18:29:49 +04:00
|
|
|
tmp = (unsigned char *)&ms->ms_dir_entries;
|
|
|
|
dir_entries = tmp[0] + (tmp[1] << 8);
|
2005-09-07 20:14:53 +04:00
|
|
|
reserved = blkid_le16(ms->ms_reserved);
|
2006-05-30 18:29:49 +04:00
|
|
|
tmp = (unsigned char *)&ms->ms_sectors;
|
|
|
|
sect_count = tmp[0] + (tmp[1] << 8);
|
2005-09-07 20:14:53 +04:00
|
|
|
if (sect_count == 0)
|
|
|
|
sect_count = blkid_le32(ms->ms_total_sect);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-09-07 20:14:53 +04:00
|
|
|
fat_length = blkid_le16(ms->ms_fat_length);
|
|
|
|
if (fat_length == 0)
|
|
|
|
fat_length = blkid_le32(vs->vs_fat32_length);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-09-07 20:14:53 +04:00
|
|
|
fat_size = fat_length * ms->ms_fats;
|
|
|
|
dir_size = ((dir_entries * sizeof(struct vfat_dir_entry)) +
|
|
|
|
(sector_size-1)) / sector_size;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-09-07 20:14:53 +04:00
|
|
|
cluster_count = sect_count - (reserved + fat_size + dir_size);
|
2007-12-16 06:21:31 +03:00
|
|
|
if (ms->ms_cluster_size == 0)
|
|
|
|
return 1;
|
2005-09-07 20:14:53 +04:00
|
|
|
cluster_count /= ms->ms_cluster_size;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-09-07 20:14:53 +04:00
|
|
|
if (cluster_count > FAT32_MAX)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (ms->ms_fat_length) {
|
2005-09-11 05:51:20 +04:00
|
|
|
/* the label may be an attribute in the root directory */
|
|
|
|
root_start = (reserved + fat_size) * sector_size;
|
|
|
|
root_dir_entries = vs->vs_dir_entries[0] +
|
|
|
|
(vs->vs_dir_entries[1] << 8);
|
|
|
|
|
|
|
|
buf_size = root_dir_entries * sizeof(struct vfat_dir_entry);
|
|
|
|
dir = (struct vfat_dir_entry *) get_buffer(probe, root_start,
|
|
|
|
buf_size);
|
|
|
|
if (dir)
|
|
|
|
vol_label = search_fat_label(dir, root_dir_entries);
|
|
|
|
|
|
|
|
if (!vol_label || !memcmp(vol_label, no_name, 11))
|
|
|
|
vol_label = ms->ms_label;
|
2005-09-07 20:14:53 +04:00
|
|
|
vol_serno = ms->ms_serno;
|
|
|
|
|
2005-09-11 05:51:20 +04:00
|
|
|
blkid_set_tag(probe->dev, "SEC_TYPE", "msdos",
|
|
|
|
sizeof("msdos"));
|
2005-09-07 20:14:53 +04:00
|
|
|
} else {
|
2005-09-11 05:51:20 +04:00
|
|
|
/* Search the FAT32 root dir for the label attribute */
|
|
|
|
buf_size = vs->vs_cluster_size * sector_size;
|
|
|
|
start_data_sect = reserved + fat_size;
|
|
|
|
|
|
|
|
next = blkid_le32(vs->vs_root_cluster);
|
|
|
|
while (next && --maxloop) {
|
|
|
|
__u32 next_sect_off;
|
|
|
|
__u64 next_off, fat_entry_off;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
next_sect_off = (next - 2) * vs->vs_cluster_size;
|
|
|
|
next_off = (start_data_sect + next_sect_off) *
|
|
|
|
sector_size;
|
|
|
|
|
|
|
|
dir = (struct vfat_dir_entry *)
|
|
|
|
get_buffer(probe, next_off, buf_size);
|
|
|
|
if (dir == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
count = buf_size / sizeof(struct vfat_dir_entry);
|
|
|
|
|
|
|
|
vol_label = search_fat_label(dir, count);
|
|
|
|
if (vol_label)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* get FAT entry */
|
|
|
|
fat_entry_off = (reserved * sector_size) +
|
|
|
|
(next * sizeof(__u32));
|
|
|
|
buf = get_buffer(probe, fat_entry_off, buf_size);
|
|
|
|
if (buf == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* set next cluster */
|
|
|
|
next = blkid_le32(*((__u32 *) buf) & 0x0fffffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vol_label || !memcmp(vol_label, no_name, 11))
|
|
|
|
vol_label = vs->vs_label;
|
2005-09-07 20:14:53 +04:00
|
|
|
vol_serno = vs->vs_serno;
|
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-09-11 05:51:20 +04:00
|
|
|
if (vol_label && memcmp(vol_label, no_name, 11)) {
|
2006-09-18 05:23:46 +04:00
|
|
|
if ((label_len = figure_label_len(vol_label, 11)))
|
|
|
|
label = vol_label;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We can't just print them as %04X, because they are unaligned */
|
2005-09-07 20:14:53 +04:00
|
|
|
sprintf(serno, "%02X%02X-%02X%02X", vol_serno[3], vol_serno[2],
|
|
|
|
vol_serno[1], vol_serno[0]);
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", (const char *) label, label_len);
|
|
|
|
blkid_set_tag(probe->dev, "UUID", serno, sizeof(serno)-1);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-06 16:13:35 +04:00
|
|
|
/*
|
|
|
|
* The FAT filesystem could be without a magic string in superblock
|
|
|
|
* (e.g. old floppies). This heuristic for FAT detection is inspired
|
|
|
|
* by http://vrfy.org/projects/volume_id/ and Linux kernel.
|
|
|
|
* [7-Jul-2005, Karel Zak <kzak@redhat.com>]
|
|
|
|
*/
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_fat_nomagic(struct blkid_probe *probe,
|
2005-09-07 20:14:53 +04:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2005-09-06 16:13:35 +04:00
|
|
|
{
|
|
|
|
struct vfat_super_block *vs;
|
|
|
|
|
|
|
|
vs = (struct vfat_super_block *)buf;
|
|
|
|
|
|
|
|
/* heads check */
|
|
|
|
if (vs->vs_heads == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* cluster size check*/
|
|
|
|
if (vs->vs_cluster_size == 0 ||
|
|
|
|
(vs->vs_cluster_size & (vs->vs_cluster_size-1)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* media check */
|
|
|
|
if (vs->vs_media < 0xf8 && vs->vs_media != 0xf0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* fat counts(Linux kernel expects at least 1 FAT table) */
|
|
|
|
if (!vs->vs_fats)
|
|
|
|
return 1;
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
return probe_fat(probe, id, buf);
|
2005-09-06 16:13:35 +04:00
|
|
|
}
|
|
|
|
|
2007-06-19 11:29:47 +04:00
|
|
|
static int probe_ntfs(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct ntfs_super_block *ns;
|
|
|
|
struct master_file_table_record *mft;
|
|
|
|
struct file_attribute *attr;
|
|
|
|
char uuid_str[17], label_str[129], *cp;
|
|
|
|
int bytes_per_sector, sectors_per_cluster;
|
|
|
|
int mft_record_size, attr_off, attr_len;
|
|
|
|
unsigned int i, attr_type, val_len;
|
|
|
|
int val_off;
|
|
|
|
__u64 nr_clusters;
|
|
|
|
blkid_loff_t off;
|
|
|
|
unsigned char *buf_mft, *val;
|
|
|
|
|
|
|
|
ns = (struct ntfs_super_block *) buf;
|
|
|
|
|
|
|
|
bytes_per_sector = ns->bios_parameter_block[0] +
|
|
|
|
(ns->bios_parameter_block[1] << 8);
|
|
|
|
sectors_per_cluster = ns->bios_parameter_block[2];
|
|
|
|
|
2007-06-25 01:17:24 +04:00
|
|
|
if ((bytes_per_sector < 512) || (sectors_per_cluster == 0))
|
|
|
|
return 1;
|
|
|
|
|
2007-06-19 11:29:47 +04:00
|
|
|
if (ns->cluster_per_mft_record < 0)
|
2007-06-25 01:17:24 +04:00
|
|
|
mft_record_size = 1 << (0-ns->cluster_per_mft_record);
|
2007-06-19 11:29:47 +04:00
|
|
|
else
|
|
|
|
mft_record_size = ns->cluster_per_mft_record *
|
|
|
|
sectors_per_cluster * bytes_per_sector;
|
|
|
|
nr_clusters = blkid_le64(ns->number_of_sectors) / sectors_per_cluster;
|
|
|
|
|
|
|
|
if ((blkid_le64(ns->mft_cluster_location) > nr_clusters) ||
|
|
|
|
(blkid_le64(ns->mft_mirror_cluster_location) > nr_clusters))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
off = blkid_le64(ns->mft_mirror_cluster_location) *
|
|
|
|
bytes_per_sector * sectors_per_cluster;
|
|
|
|
|
|
|
|
buf_mft = get_buffer(probe, off, mft_record_size);
|
|
|
|
if (!buf_mft)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (memcmp(buf_mft, "FILE", 4))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
off = blkid_le64(ns->mft_cluster_location) * bytes_per_sector *
|
|
|
|
sectors_per_cluster;
|
|
|
|
|
|
|
|
buf_mft = get_buffer(probe, off, mft_record_size);
|
|
|
|
if (!buf_mft)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (memcmp(buf_mft, "FILE", 4))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
off += MFT_RECORD_VOLUME * mft_record_size;
|
|
|
|
|
|
|
|
buf_mft = get_buffer(probe, off, mft_record_size);
|
|
|
|
if (!buf_mft)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (memcmp(buf_mft, "FILE", 4))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
mft = (struct master_file_table_record *) buf_mft;
|
|
|
|
|
|
|
|
attr_off = blkid_le16(mft->attrs_offset);
|
|
|
|
label_str[0] = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
attr = (struct file_attribute *) (buf_mft + attr_off);
|
|
|
|
attr_len = blkid_le16(attr->len);
|
|
|
|
attr_type = blkid_le32(attr->type);
|
|
|
|
val_off = blkid_le16(attr->value_offset);
|
|
|
|
val_len = blkid_le32(attr->value_len);
|
|
|
|
|
|
|
|
attr_off += attr_len;
|
|
|
|
|
|
|
|
if ((attr_off > mft_record_size) ||
|
|
|
|
(attr_len == 0))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (attr_type == MFT_RECORD_ATTR_END)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (attr_type == MFT_RECORD_ATTR_VOLUME_NAME) {
|
|
|
|
if (val_len > sizeof(label_str))
|
|
|
|
val_len = sizeof(label_str)-1;
|
|
|
|
|
|
|
|
for (i=0, cp=label_str; i < val_len; i+=2,cp++) {
|
|
|
|
val = ((__u8 *) attr) + val_off + i;
|
|
|
|
*cp = val[0];
|
|
|
|
if (val[1])
|
|
|
|
*cp = '?';
|
|
|
|
}
|
|
|
|
*cp = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-11 13:41:15 +03:00
|
|
|
sprintf(uuid_str, "%016llX", blkid_le64(ns->volume_serial));
|
2007-06-19 11:29:47 +04:00
|
|
|
blkid_set_tag(probe->dev, "UUID", uuid_str, 0);
|
|
|
|
if (label_str[0])
|
|
|
|
blkid_set_tag(probe->dev, "LABEL", label_str, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_xfs(struct blkid_probe *probe,
|
2003-12-07 09:28:50 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
|
|
|
struct xfs_super_block *xs;
|
2003-07-20 19:22:34 +04:00
|
|
|
const char *label = 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
xs = (struct xfs_super_block *)buf;
|
|
|
|
|
|
|
|
if (strlen(xs->xs_fname))
|
2003-07-20 19:22:34 +04:00
|
|
|
label = xs->xs_fname;
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", label, sizeof(xs->xs_fname));
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(probe->dev, xs->xs_uuid, 0);
|
2003-01-24 00:45:16 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_reiserfs(struct blkid_probe *probe,
|
2003-02-23 01:15:20 +03:00
|
|
|
struct blkid_magic *id, unsigned char *buf)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
2003-02-13 07:51:21 +03:00
|
|
|
struct reiserfs_super_block *rs = (struct reiserfs_super_block *) buf;
|
2003-01-24 00:45:16 +03:00
|
|
|
unsigned int blocksize;
|
2003-07-20 19:22:34 +04:00
|
|
|
const char *label = 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-01-27 09:09:24 +03:00
|
|
|
blocksize = blkid_le16(rs->rs_blocksize);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2008-01-27 08:14:01 +03:00
|
|
|
/* The blocksize must be at least 1k */
|
|
|
|
if ((blocksize >> 10) == 0)
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
/* If the superblock is inside the journal, we have the wrong one */
|
2003-02-13 07:51:21 +03:00
|
|
|
if (id->bim_kboff/(blocksize>>10) > blkid_le32(rs->rs_journal_block))
|
2003-01-24 00:45:16 +03:00
|
|
|
return -BLKID_ERR_BIG;
|
|
|
|
|
|
|
|
/* LABEL/UUID are only valid for later versions of Reiserfs v3.6. */
|
2005-09-11 05:07:23 +04:00
|
|
|
if (id->bim_magic[6] == '2' || id->bim_magic[6] == '3') {
|
2003-07-20 19:22:34 +04:00
|
|
|
if (strlen(rs->rs_label))
|
|
|
|
label = rs->rs_label;
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(probe->dev, rs->rs_uuid, 0);
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", label, sizeof(rs->rs_label));
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_reiserfs4(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2005-09-10 19:48:38 +04:00
|
|
|
{
|
|
|
|
struct reiser4_super_block *rs4 = (struct reiser4_super_block *) buf;
|
2005-09-11 05:07:23 +04:00
|
|
|
const unsigned char *label = 0;
|
2005-09-10 19:48:38 +04:00
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
if (strlen((char *) rs4->rs4_label))
|
2005-09-10 19:48:38 +04:00
|
|
|
label = rs4->rs4_label;
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(probe->dev, rs4->rs4_uuid, 0);
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", (const char *) label,
|
|
|
|
sizeof(rs4->rs4_label));
|
2005-09-10 19:48:38 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_jfs(struct blkid_probe *probe,
|
2003-12-07 09:28:50 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2003-04-03 09:04:28 +04:00
|
|
|
{
|
|
|
|
struct jfs_super_block *js;
|
2003-07-20 19:22:34 +04:00
|
|
|
const char *label = 0;
|
2003-04-03 09:04:28 +04:00
|
|
|
|
|
|
|
js = (struct jfs_super_block *)buf;
|
|
|
|
|
2003-07-06 08:36:48 +04:00
|
|
|
if (strlen((char *) js->js_label))
|
2003-07-20 19:22:34 +04:00
|
|
|
label = (char *) js->js_label;
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", label, sizeof(js->js_label));
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(probe->dev, js->js_uuid, 0);
|
2003-04-03 09:04:28 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-21 21:43:33 +04:00
|
|
|
static int probe_luks(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
2007-08-04 02:56:01 +04:00
|
|
|
char uuid[40];
|
|
|
|
|
2007-06-21 21:43:33 +04:00
|
|
|
/* 168 is the offset to the 40 character uuid:
|
|
|
|
* http://luks.endorphin.org/LUKS-on-disk-format.pdf */
|
2007-08-04 02:56:01 +04:00
|
|
|
strncpy(uuid, (char *) buf+168, 40);
|
2007-06-21 21:43:33 +04:00
|
|
|
blkid_set_tag(probe->dev, "UUID", uuid, sizeof(uuid));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_romfs(struct blkid_probe *probe,
|
2003-12-07 09:28:50 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2003-04-03 09:04:28 +04:00
|
|
|
{
|
|
|
|
struct romfs_super_block *ros;
|
2003-07-20 19:22:34 +04:00
|
|
|
const char *label = 0;
|
2003-04-03 09:04:28 +04:00
|
|
|
|
|
|
|
ros = (struct romfs_super_block *)buf;
|
|
|
|
|
2003-07-20 19:22:34 +04:00
|
|
|
if (strlen((char *) ros->ros_volume))
|
|
|
|
label = (char *) ros->ros_volume;
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", label, 0);
|
2005-01-11 07:58:11 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_cramfs(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2005-05-06 02:06:04 +04:00
|
|
|
{
|
|
|
|
struct cramfs_super_block *csb;
|
|
|
|
const char *label = 0;
|
|
|
|
|
|
|
|
csb = (struct cramfs_super_block *)buf;
|
|
|
|
|
|
|
|
if (strlen((char *) csb->name))
|
|
|
|
label = (char *) csb->name;
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", label, 0);
|
2005-05-06 02:06:04 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_swap0(struct blkid_probe *probe,
|
2005-01-11 07:58:11 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf __BLKID_ATTR((unused)))
|
|
|
|
{
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "UUID", 0, 0);
|
|
|
|
blkid_set_tag(probe->dev, "LABEL", 0, 0);
|
2005-01-11 07:58:11 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_swap1(struct blkid_probe *probe,
|
2008-04-18 19:28:44 +04:00
|
|
|
struct blkid_magic *id,
|
2005-01-11 07:58:11 +03:00
|
|
|
unsigned char *buf __BLKID_ATTR((unused)))
|
|
|
|
{
|
|
|
|
struct swap_id_block *sws;
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
probe_swap0(probe, id, buf);
|
2005-01-11 07:58:11 +03:00
|
|
|
/*
|
|
|
|
* Version 1 swap headers are always located at offset of 1024
|
|
|
|
* bytes, although the swap signature itself is located at the
|
|
|
|
* end of the page (which may vary depending on hardware
|
|
|
|
* pagesize).
|
|
|
|
*/
|
2005-09-11 05:07:23 +04:00
|
|
|
sws = (struct swap_id_block *) get_buffer(probe, 1024, 1024);
|
|
|
|
if (!sws)
|
2005-01-11 07:58:11 +03:00
|
|
|
return 1;
|
|
|
|
|
2008-04-18 19:28:44 +04:00
|
|
|
/* check for wrong version or zeroed pagecount, for sanity */
|
|
|
|
if (!memcmp(id->bim_magic, "SWAPSPACE2", id->bim_len) &&
|
2008-05-12 22:26:51 +04:00
|
|
|
(sws->sws_version != 1 || sws->sws_lastpage == 0))
|
2008-04-18 19:28:44 +04:00
|
|
|
return 1;
|
|
|
|
|
2005-01-11 07:58:11 +03:00
|
|
|
/* arbitrary sanity check.. is there any garbage down there? */
|
|
|
|
if (sws->sws_pad[32] == 0 && sws->sws_pad[33] == 0) {
|
|
|
|
if (sws->sws_volume[0])
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", sws->sws_volume,
|
2005-01-11 07:58:11 +03:00
|
|
|
sizeof(sws->sws_volume));
|
|
|
|
if (sws->sws_uuid[0])
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(probe->dev, sws->sws_uuid, 0);
|
2005-01-11 07:58:11 +03:00
|
|
|
}
|
2003-04-03 09:04:28 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_iso9660(struct blkid_probe *probe,
|
2005-09-10 23:46:57 +04:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct iso_volume_descriptor *iso;
|
|
|
|
const unsigned char *label;
|
|
|
|
|
|
|
|
iso = (struct iso_volume_descriptor *) buf;
|
|
|
|
label = iso->volume_id;
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", (const char *) label,
|
|
|
|
figure_label_len(label, 32));
|
2005-09-10 23:46:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-07 09:28:50 +03:00
|
|
|
static const char
|
2003-07-22 09:06:36 +04:00
|
|
|
*udf_magic[] = { "BEA01", "BOOT2", "CD001", "CDW02", "NSR02",
|
|
|
|
"NSR03", "TEA01", 0 };
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_udf(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
2003-12-07 09:28:50 +03:00
|
|
|
unsigned char *buf __BLKID_ATTR((unused)))
|
2003-07-22 09:06:36 +04:00
|
|
|
{
|
|
|
|
int j, bs;
|
2005-09-11 05:07:23 +04:00
|
|
|
struct iso_volume_descriptor *isosb;
|
2003-12-07 09:28:50 +03:00
|
|
|
const char ** m;
|
2003-07-22 09:06:36 +04:00
|
|
|
|
|
|
|
/* determine the block size by scanning in 2K increments
|
|
|
|
(block sizes larger than 2K will be null padded) */
|
|
|
|
for (bs = 1; bs < 16; bs++) {
|
2005-09-11 05:07:23 +04:00
|
|
|
isosb = (struct iso_volume_descriptor *)
|
|
|
|
get_buffer(probe, bs*2048+32768, sizeof(isosb));
|
|
|
|
if (!isosb)
|
2003-07-22 09:06:36 +04:00
|
|
|
return 1;
|
2005-09-11 05:07:23 +04:00
|
|
|
if (isosb->vd_id[0])
|
2003-07-22 09:06:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scan up to another 64 blocks looking for additional VSD's */
|
|
|
|
for (j = 1; j < 64; j++) {
|
|
|
|
if (j > 1) {
|
2005-09-11 05:07:23 +04:00
|
|
|
isosb = (struct iso_volume_descriptor *)
|
|
|
|
get_buffer(probe, j*bs*2048+32768,
|
|
|
|
sizeof(isosb));
|
|
|
|
if (!isosb)
|
2003-07-22 09:06:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* If we find NSR0x then call it udf:
|
|
|
|
NSR01 for UDF 1.00
|
|
|
|
NSR02 for UDF 1.50
|
|
|
|
NSR03 for UDF 2.00 */
|
2006-05-15 01:29:00 +04:00
|
|
|
if (!memcmp(isosb->vd_id, "NSR0", 4))
|
2008-02-10 07:12:56 +03:00
|
|
|
return probe_iso9660(probe, id, buf);
|
2003-07-22 09:06:36 +04:00
|
|
|
for (m = udf_magic; *m; m++)
|
2006-05-15 01:29:00 +04:00
|
|
|
if (!memcmp(*m, isosb->vd_id, 5))
|
2003-07-22 09:06:36 +04:00
|
|
|
break;
|
|
|
|
if (*m == 0)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_ocfs(struct blkid_probe *probe,
|
2004-03-05 03:59:58 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct ocfs_volume_header ovh;
|
|
|
|
struct ocfs_volume_label ovl;
|
2004-12-01 03:05:38 +03:00
|
|
|
__u32 major;
|
2004-03-05 03:59:58 +03:00
|
|
|
|
|
|
|
memcpy(&ovh, buf, sizeof(ovh));
|
|
|
|
memcpy(&ovl, buf+512, sizeof(ovl));
|
|
|
|
|
|
|
|
major = ocfsmajor(ovh);
|
|
|
|
if (major == 1)
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev,"SEC_TYPE","ocfs1",sizeof("ocfs1"));
|
2004-03-05 03:59:58 +03:00
|
|
|
else if (major >= 9)
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev,"SEC_TYPE","ntocfs",sizeof("ntocfs"));
|
2004-03-05 03:59:58 +03:00
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", ovl.label, ocfslabellen(ovl));
|
|
|
|
blkid_set_tag(probe->dev, "MOUNT", ovh.mount, ocfsmountlen(ovh));
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(probe->dev, ovl.vol_id, 0);
|
2004-03-05 03:59:58 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_ocfs2(struct blkid_probe *probe,
|
2005-01-22 01:57:56 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
2004-09-18 05:37:49 +04:00
|
|
|
{
|
|
|
|
struct ocfs2_super_block *osb;
|
|
|
|
|
|
|
|
osb = (struct ocfs2_super_block *)buf;
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", osb->s_label, sizeof(osb->s_label));
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(probe->dev, osb->s_uuid, 0);
|
2004-09-18 05:37:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
static int probe_oracleasm(struct blkid_probe *probe,
|
2005-01-22 01:57:56 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct oracle_asm_disk_label *dl;
|
|
|
|
|
|
|
|
dl = (struct oracle_asm_disk_label *)buf;
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
blkid_set_tag(probe->dev, "LABEL", dl->dl_id, sizeof(dl->dl_id));
|
2005-01-22 01:57:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-18 05:10:58 +04:00
|
|
|
static int probe_gfs(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct gfs2_sb *sbd;
|
|
|
|
const char *label = 0;
|
|
|
|
|
|
|
|
sbd = (struct gfs2_sb *)buf;
|
|
|
|
|
|
|
|
if (blkid_be32(sbd->sb_fs_format) == GFS_FORMAT_FS &&
|
|
|
|
blkid_be32(sbd->sb_multihost_format) == GFS_FORMAT_MULTI)
|
|
|
|
{
|
|
|
|
blkid_set_tag(probe->dev, "UUID", 0, 0);
|
|
|
|
|
|
|
|
if (strlen(sbd->sb_locktable))
|
|
|
|
label = sbd->sb_locktable;
|
|
|
|
blkid_set_tag(probe->dev, "LABEL", label, sizeof(sbd->sb_locktable));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int probe_gfs2(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct gfs2_sb *sbd;
|
|
|
|
const char *label = 0;
|
|
|
|
|
|
|
|
sbd = (struct gfs2_sb *)buf;
|
|
|
|
|
|
|
|
if (blkid_be32(sbd->sb_fs_format) == GFS2_FORMAT_FS &&
|
|
|
|
blkid_be32(sbd->sb_multihost_format) == GFS2_FORMAT_MULTI)
|
|
|
|
{
|
|
|
|
blkid_set_tag(probe->dev, "UUID", 0, 0);
|
|
|
|
|
|
|
|
if (strlen(sbd->sb_locktable))
|
|
|
|
label = sbd->sb_locktable;
|
|
|
|
blkid_set_tag(probe->dev, "LABEL", label, sizeof(sbd->sb_locktable));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-02-27 10:06:08 +03:00
|
|
|
static int probe_hfsplus(struct blkid_probe *probe __BLKID_ATTR((unused)),
|
2008-01-27 08:21:07 +03:00
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
struct hfs_mdb *sbd = (struct hfs_mdb *)buf;
|
|
|
|
|
|
|
|
/* Check for a HFS+ volume embedded in a HFS volume */
|
|
|
|
if (memcmp(sbd->embed_sig, "H+", 2) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-31 02:25:03 +03:00
|
|
|
#define LVM2_LABEL_SIZE 512
|
2008-03-09 04:01:05 +03:00
|
|
|
static unsigned int lvm2_calc_crc(const void *buf, unsigned int size)
|
2008-01-31 02:25:03 +03:00
|
|
|
{
|
2008-03-09 04:01:05 +03:00
|
|
|
static const unsigned int crctab[] = {
|
2008-01-31 02:25:03 +03:00
|
|
|
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
|
|
|
|
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
|
|
|
|
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
|
|
|
|
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
|
|
|
|
};
|
2008-03-09 04:01:05 +03:00
|
|
|
unsigned int i, crc = 0xf597a6cf;
|
2008-01-31 02:25:03 +03:00
|
|
|
const __u8 *data = (const __u8 *) buf;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
crc ^= *data++;
|
|
|
|
crc = (crc >> 4) ^ crctab[crc & 0xf];
|
|
|
|
crc = (crc >> 4) ^ crctab[crc & 0xf];
|
|
|
|
}
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int probe_lvm2(struct blkid_probe *probe,
|
|
|
|
struct blkid_magic *id __BLKID_ATTR((unused)),
|
|
|
|
unsigned char *buf)
|
|
|
|
{
|
|
|
|
int sector = (id->bim_kboff) << 1;;
|
|
|
|
struct lvm2_pv_label_header *label;
|
|
|
|
label = (struct lvm2_pv_label_header *)buf;
|
|
|
|
char *p, *q, uuid[40];
|
|
|
|
unsigned int i, b;
|
|
|
|
|
|
|
|
/* buf is at 0k or 1k offset; find label inside */
|
|
|
|
if (memcmp(buf, "LABELONE", 8) == 0) {
|
|
|
|
label = (struct lvm2_pv_label_header *)buf;
|
|
|
|
} else if (memcmp(buf + 512, "LABELONE", 8) == 0) {
|
|
|
|
label = (struct lvm2_pv_label_header *)(buf + 512);
|
|
|
|
sector++;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-02-27 10:06:08 +03:00
|
|
|
if (blkid_le64(label->sector_xl) != (unsigned) sector) {
|
2008-01-31 02:25:03 +03:00
|
|
|
DBG(DEBUG_PROBE,
|
2008-02-27 10:06:08 +03:00
|
|
|
printf("LVM2: label for sector %llu found at sector %d\n",
|
2008-01-31 02:25:03 +03:00
|
|
|
blkid_le64(label->sector_xl), sector));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lvm2_calc_crc(&label->offset_xl, LVM2_LABEL_SIZE -
|
2008-02-27 10:06:08 +03:00
|
|
|
((char *)&label->offset_xl - (char *)label)) !=
|
2008-01-31 02:25:03 +03:00
|
|
|
blkid_le32(label->crc_xl)) {
|
|
|
|
DBG(DEBUG_PROBE,
|
|
|
|
printf("LVM2: label checksum incorrect at sector %d\n",
|
|
|
|
sector));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-02-27 10:06:08 +03:00
|
|
|
for (i=0, b=1, p=uuid, q= (char *) label->pv_uuid; i <= 32;
|
|
|
|
i++, b <<= 1) {
|
2008-01-31 02:25:03 +03:00
|
|
|
if (b & 0x4444440)
|
|
|
|
*p++ = '-';
|
|
|
|
*p++ = *q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
blkid_set_tag(probe->dev, "UUID", uuid, LVM2_ID_LEN+6);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
/*
|
|
|
|
* BLKID_BLK_OFFS is at least as large as the highest bim_kboff defined
|
2003-02-13 07:51:21 +03:00
|
|
|
* in the type_array table below + bim_kbalign.
|
|
|
|
*
|
|
|
|
* When probing for a lot of magics, we handle everything in 1kB buffers so
|
|
|
|
* that we don't have to worry about reading each combination of block sizes.
|
2003-01-24 00:45:16 +03:00
|
|
|
*/
|
2003-02-13 07:51:21 +03:00
|
|
|
#define BLKID_BLK_OFFS 64 /* currently reiserfs */
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Various filesystem magics that we can check for. Note that kboff and
|
|
|
|
* sboff are in kilobytes and bytes respectively. All magics are in
|
|
|
|
* byte strings so we don't worry about endian issues.
|
|
|
|
*/
|
2003-02-13 07:51:21 +03:00
|
|
|
static struct blkid_magic type_array[] = {
|
|
|
|
/* type kboff sboff len magic probe */
|
2005-01-22 01:57:56 +03:00
|
|
|
{ "oracleasm", 0, 32, 8, "ORCLDISK", probe_oracleasm },
|
2007-06-19 11:29:47 +04:00
|
|
|
{ "ntfs", 0, 3, 8, "NTFS ", probe_ntfs },
|
2003-02-13 07:51:21 +03:00
|
|
|
{ "jbd", 1, 0x38, 2, "\123\357", probe_jbd },
|
2008-01-27 06:25:50 +03:00
|
|
|
{ "ext4dev", 1, 0x38, 2, "\123\357", probe_ext4dev },
|
|
|
|
{ "ext4", 1, 0x38, 2, "\123\357", probe_ext4 },
|
2005-01-06 01:45:32 +03:00
|
|
|
{ "ext3", 1, 0x38, 2, "\123\357", probe_ext3 },
|
2003-02-13 07:51:21 +03:00
|
|
|
{ "ext2", 1, 0x38, 2, "\123\357", probe_ext2 },
|
|
|
|
{ "reiserfs", 8, 0x34, 8, "ReIsErFs", probe_reiserfs },
|
|
|
|
{ "reiserfs", 64, 0x34, 9, "ReIsEr2Fs", probe_reiserfs },
|
|
|
|
{ "reiserfs", 64, 0x34, 9, "ReIsEr3Fs", probe_reiserfs },
|
|
|
|
{ "reiserfs", 64, 0x34, 8, "ReIsErFs", probe_reiserfs },
|
|
|
|
{ "reiserfs", 8, 20, 8, "ReIsErFs", probe_reiserfs },
|
2005-09-10 19:48:38 +04:00
|
|
|
{ "reiser4", 64, 0, 7, "ReIsEr4", probe_reiserfs4 },
|
2006-09-18 05:10:58 +04:00
|
|
|
{ "gfs2", 64, 0, 4, "\x01\x16\x19\x70", probe_gfs2 },
|
|
|
|
{ "gfs", 64, 0, 4, "\x01\x16\x19\x70", probe_gfs },
|
2005-09-07 20:14:53 +04:00
|
|
|
{ "vfat", 0, 0x52, 5, "MSWIN", probe_fat },
|
|
|
|
{ "vfat", 0, 0x52, 8, "FAT32 ", probe_fat },
|
|
|
|
{ "vfat", 0, 0x36, 5, "MSDOS", probe_fat },
|
|
|
|
{ "vfat", 0, 0x36, 8, "FAT16 ", probe_fat },
|
|
|
|
{ "vfat", 0, 0x36, 8, "FAT12 ", probe_fat },
|
2007-09-23 17:50:11 +04:00
|
|
|
{ "vfat", 0, 0, 1, "\353", probe_fat_nomagic },
|
2005-09-07 20:14:53 +04:00
|
|
|
{ "vfat", 0, 0, 1, "\351", probe_fat_nomagic },
|
2007-09-23 17:50:11 +04:00
|
|
|
{ "vfat", 0, 0x1fe, 2, "\125\252", probe_fat_nomagic },
|
2003-02-13 07:51:21 +03:00
|
|
|
{ "minix", 1, 0x10, 2, "\177\023", 0 },
|
|
|
|
{ "minix", 1, 0x10, 2, "\217\023", 0 },
|
|
|
|
{ "minix", 1, 0x10, 2, "\150\044", 0 },
|
|
|
|
{ "minix", 1, 0x10, 2, "\170\044", 0 },
|
|
|
|
{ "vxfs", 1, 0, 4, "\365\374\001\245", 0 },
|
|
|
|
{ "xfs", 0, 0, 4, "XFSB", probe_xfs },
|
2003-04-03 09:04:28 +04:00
|
|
|
{ "romfs", 0, 0, 8, "-rom1fs-", probe_romfs },
|
2003-02-13 07:51:21 +03:00
|
|
|
{ "bfs", 0, 0, 4, "\316\372\173\033", 0 },
|
2005-05-06 02:06:04 +04:00
|
|
|
{ "cramfs", 0, 0, 4, "E=\315\050", probe_cramfs },
|
2003-02-13 07:51:21 +03:00
|
|
|
{ "qnx4", 0, 4, 6, "QNX4FS", 0 },
|
2003-07-22 09:06:36 +04:00
|
|
|
{ "udf", 32, 1, 5, "BEA01", probe_udf },
|
|
|
|
{ "udf", 32, 1, 5, "BOOT2", probe_udf },
|
|
|
|
{ "udf", 32, 1, 5, "CD001", probe_udf },
|
|
|
|
{ "udf", 32, 1, 5, "CDW02", probe_udf },
|
|
|
|
{ "udf", 32, 1, 5, "NSR02", probe_udf },
|
|
|
|
{ "udf", 32, 1, 5, "NSR03", probe_udf },
|
|
|
|
{ "udf", 32, 1, 5, "TEA01", probe_udf },
|
2005-09-10 23:46:57 +04:00
|
|
|
{ "iso9660", 32, 1, 5, "CD001", probe_iso9660 },
|
|
|
|
{ "iso9660", 32, 9, 5, "CDROM", probe_iso9660 },
|
2003-04-03 09:04:28 +04:00
|
|
|
{ "jfs", 32, 0, 4, "JFS1", probe_jfs },
|
2008-01-27 08:21:07 +03:00
|
|
|
{ "hfsplus", 1, 0, 2, "BD", probe_hfsplus },
|
|
|
|
{ "hfsplus", 1, 0, 2, "H+", 0 },
|
2003-02-13 07:51:21 +03:00
|
|
|
{ "hfs", 1, 0, 2, "BD", 0 },
|
|
|
|
{ "ufs", 8, 0x55c, 4, "T\031\001\000", 0 },
|
|
|
|
{ "hpfs", 8, 0, 4, "I\350\225\371", 0 },
|
|
|
|
{ "sysv", 0, 0x3f8, 4, "\020~\030\375", 0 },
|
2005-01-11 07:58:11 +03:00
|
|
|
{ "swap", 0, 0xff6, 10, "SWAP-SPACE", probe_swap0 },
|
|
|
|
{ "swap", 0, 0xff6, 10, "SWAPSPACE2", probe_swap1 },
|
2005-09-06 14:42:49 +04:00
|
|
|
{ "swsuspend", 0, 0xff6, 9, "S1SUSPEND", probe_swap1 },
|
|
|
|
{ "swsuspend", 0, 0xff6, 9, "S2SUSPEND", probe_swap1 },
|
2005-01-11 07:58:11 +03:00
|
|
|
{ "swap", 0, 0x1ff6, 10, "SWAP-SPACE", probe_swap0 },
|
|
|
|
{ "swap", 0, 0x1ff6, 10, "SWAPSPACE2", probe_swap1 },
|
2005-09-06 14:42:49 +04:00
|
|
|
{ "swsuspend", 0, 0x1ff6, 9, "S1SUSPEND", probe_swap1 },
|
|
|
|
{ "swsuspend", 0, 0x1ff6, 9, "S2SUSPEND", probe_swap1 },
|
2005-01-11 07:58:11 +03:00
|
|
|
{ "swap", 0, 0x3ff6, 10, "SWAP-SPACE", probe_swap0 },
|
|
|
|
{ "swap", 0, 0x3ff6, 10, "SWAPSPACE2", probe_swap1 },
|
2005-09-06 14:42:49 +04:00
|
|
|
{ "swsuspend", 0, 0x3ff6, 9, "S1SUSPEND", probe_swap1 },
|
|
|
|
{ "swsuspend", 0, 0x3ff6, 9, "S2SUSPEND", probe_swap1 },
|
2005-01-11 07:58:11 +03:00
|
|
|
{ "swap", 0, 0x7ff6, 10, "SWAP-SPACE", probe_swap0 },
|
|
|
|
{ "swap", 0, 0x7ff6, 10, "SWAPSPACE2", probe_swap1 },
|
2005-09-06 14:42:49 +04:00
|
|
|
{ "swsuspend", 0, 0x7ff6, 9, "S1SUSPEND", probe_swap1 },
|
|
|
|
{ "swsuspend", 0, 0x7ff6, 9, "S2SUSPEND", probe_swap1 },
|
2005-01-11 07:58:11 +03:00
|
|
|
{ "swap", 0, 0xfff6, 10, "SWAP-SPACE", probe_swap0 },
|
|
|
|
{ "swap", 0, 0xfff6, 10, "SWAPSPACE2", probe_swap1 },
|
2005-09-06 14:42:49 +04:00
|
|
|
{ "swsuspend", 0, 0xfff6, 9, "S1SUSPEND", probe_swap1 },
|
|
|
|
{ "swsuspend", 0, 0xfff6, 9, "S2SUSPEND", probe_swap1 },
|
2005-01-22 01:57:56 +03:00
|
|
|
{ "ocfs", 0, 8, 9, "OracleCFS", probe_ocfs },
|
|
|
|
{ "ocfs2", 1, 0, 6, "OCFSV2", probe_ocfs2 },
|
|
|
|
{ "ocfs2", 2, 0, 6, "OCFSV2", probe_ocfs2 },
|
|
|
|
{ "ocfs2", 4, 0, 6, "OCFSV2", probe_ocfs2 },
|
|
|
|
{ "ocfs2", 8, 0, 6, "OCFSV2", probe_ocfs2 },
|
2007-06-21 21:43:33 +04:00
|
|
|
{ "crypt_LUKS", 0, 0, 6, "LUKS\xba\xbe", probe_luks },
|
2007-10-15 21:48:44 +04:00
|
|
|
{ "squashfs", 0, 0, 4, "sqsh", 0 },
|
2007-09-25 21:02:50 +04:00
|
|
|
{ "squashfs", 0, 0, 4, "hsqs", 0 },
|
2008-01-31 02:25:03 +03:00
|
|
|
{ "lvm2pv", 0, 0x218, 8, "LVM2 001", probe_lvm2 },
|
|
|
|
{ "lvm2pv", 0, 0x018, 8, "LVM2 001", probe_lvm2 },
|
|
|
|
{ "lvm2pv", 1, 0x018, 8, "LVM2 001", probe_lvm2 },
|
|
|
|
{ "lvm2pv", 1, 0x218, 8, "LVM2 001", probe_lvm2 },
|
2003-02-13 07:51:21 +03:00
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
2003-01-24 00:45:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that the data in dev is consistent with what is on the actual
|
|
|
|
* block device (using the devname field only). Normally this will be
|
|
|
|
* called when finding items in the cache, but for long running processes
|
|
|
|
* is also desirable to revalidate an item before use.
|
|
|
|
*
|
|
|
|
* If we are unable to revalidate the data, we return the old data and
|
|
|
|
* do not set the BLKID_BID_FL_VERIFIED flag on it.
|
|
|
|
*/
|
2005-01-28 03:51:47 +03:00
|
|
|
blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
|
|
|
struct blkid_magic *id;
|
2005-09-11 05:07:23 +04:00
|
|
|
struct blkid_probe probe;
|
2006-03-11 02:11:35 +03:00
|
|
|
blkid_tag_iterate iter;
|
2005-09-11 05:07:23 +04:00
|
|
|
unsigned char *buf;
|
2006-03-11 02:11:35 +03:00
|
|
|
const char *type, *value;
|
2003-02-13 07:51:21 +03:00
|
|
|
struct stat st;
|
2004-04-20 05:42:18 +04:00
|
|
|
time_t diff, now;
|
2005-09-11 05:07:23 +04:00
|
|
|
int idx;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
2004-04-20 05:42:18 +04:00
|
|
|
now = time(0);
|
|
|
|
diff = now - dev->bid_time;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2006-03-13 07:25:15 +03:00
|
|
|
if ((now > dev->bid_time) && (diff > 0) &&
|
|
|
|
((diff < BLKID_PROBE_MIN) ||
|
|
|
|
(dev->bid_flags & BLKID_BID_FL_VERIFIED &&
|
|
|
|
diff < BLKID_PROBE_INTERVAL)))
|
2003-01-24 00:45:16 +03:00
|
|
|
return dev;
|
|
|
|
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_PROBE,
|
2006-05-30 03:48:51 +04:00
|
|
|
printf("need to revalidate %s (time since last check %llu)\n",
|
|
|
|
dev->bid_name, (unsigned long long)diff));
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
if (((probe.fd = open(dev->bid_name, O_RDONLY)) < 0) ||
|
|
|
|
(fstat(probe.fd, &st) < 0)) {
|
2006-03-25 09:42:02 +03:00
|
|
|
if (probe.fd >= 0) close(probe.fd);
|
2008-04-22 03:22:49 +04:00
|
|
|
if ((errno != EPERM) && (errno != EACCES) &&
|
|
|
|
(errno != ENOENT)) {
|
|
|
|
DBG(DEBUG_PROBE,
|
|
|
|
printf("blkid_verify: error %s (%d) while "
|
|
|
|
"opening %s\n", strerror(errno), errno,
|
|
|
|
dev->bid_name));
|
2003-01-24 00:45:16 +03:00
|
|
|
blkid_free_dev(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* We don't have read permission, just return cache data. */
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_PROBE,
|
|
|
|
printf("returning unverified data for %s\n",
|
|
|
|
dev->bid_name));
|
2003-01-24 00:45:16 +03:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
probe.cache = cache;
|
|
|
|
probe.dev = dev;
|
|
|
|
probe.sbbuf = 0;
|
|
|
|
probe.buf = 0;
|
|
|
|
probe.buf_max = 0;
|
2003-02-13 07:51:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the type array. If we already know the type,
|
|
|
|
* then try that first. If it doesn't work, then blow away
|
|
|
|
* the type information, and try again.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
try_again:
|
|
|
|
type = 0;
|
|
|
|
if (!dev->bid_type || !strcmp(dev->bid_type, "mdraid")) {
|
|
|
|
uuid_t uuid;
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
if (check_mdraid(probe.fd, uuid) == 0) {
|
2006-03-11 02:11:35 +03:00
|
|
|
set_uuid(dev, uuid, 0);
|
2003-02-13 07:51:21 +03:00
|
|
|
type = "mdraid";
|
|
|
|
goto found_type;
|
|
|
|
}
|
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
for (id = type_array; id->bim_type; id++) {
|
2003-02-13 07:51:21 +03:00
|
|
|
if (dev->bid_type &&
|
|
|
|
strcmp(id->bim_type, dev->bid_type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
idx = id->bim_kboff + (id->bim_sboff >> 10);
|
2005-09-11 05:07:23 +04:00
|
|
|
buf = get_buffer(&probe, idx << 10, 1024);
|
|
|
|
if (!buf)
|
2003-02-13 07:51:21 +03:00
|
|
|
continue;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (memcmp(id->bim_magic, buf + (id->bim_sboff&0x3ff),
|
|
|
|
id->bim_len))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((id->bim_probe == NULL) ||
|
2005-09-11 05:07:23 +04:00
|
|
|
(id->bim_probe(&probe, id, buf) == 0)) {
|
2003-02-13 07:51:21 +03:00
|
|
|
type = id->bim_type;
|
|
|
|
goto found_type;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (!id->bim_type && dev->bid_type) {
|
|
|
|
/*
|
2006-03-11 02:11:35 +03:00
|
|
|
* Zap the device filesystem information and try again
|
2003-02-13 07:51:21 +03:00
|
|
|
*/
|
2007-07-09 04:17:31 +04:00
|
|
|
DBG(DEBUG_PROBE,
|
|
|
|
printf("previous fs type %s not valid, "
|
|
|
|
"trying full probe\n", dev->bid_type));
|
2006-03-11 02:11:35 +03:00
|
|
|
iter = blkid_tag_iterate_begin(dev);
|
|
|
|
while (blkid_tag_next(iter, &type, &value) == 0)
|
|
|
|
blkid_set_tag(dev, type, 0, 0);
|
|
|
|
blkid_tag_iterate_end(iter);
|
2003-02-13 07:51:21 +03:00
|
|
|
goto try_again;
|
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (!dev->bid_type) {
|
2003-01-24 00:45:16 +03:00
|
|
|
blkid_free_dev(dev);
|
2007-03-07 03:56:18 +03:00
|
|
|
dev = 0;
|
|
|
|
goto found_type;
|
2003-02-13 07:51:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
found_type:
|
|
|
|
if (dev && type) {
|
|
|
|
dev->bid_devno = st.st_rdev;
|
|
|
|
dev->bid_time = time(0);
|
|
|
|
dev->bid_flags |= BLKID_BID_FL_VERIFIED;
|
2003-02-14 09:31:45 +03:00
|
|
|
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
|
2003-02-13 07:51:21 +03:00
|
|
|
|
2003-02-23 01:15:20 +03:00
|
|
|
blkid_set_tag(dev, "TYPE", type, 0);
|
2003-02-13 07:51:21 +03:00
|
|
|
|
2005-05-07 22:38:10 +04:00
|
|
|
DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n",
|
2006-05-30 03:48:51 +04:00
|
|
|
dev->bid_name, (long long)st.st_rdev, type));
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
2005-09-11 05:07:23 +04:00
|
|
|
if (probe.sbbuf)
|
|
|
|
free(probe.sbbuf);
|
|
|
|
if (probe.buf)
|
|
|
|
free(probe.buf);
|
2007-03-07 03:56:18 +03:00
|
|
|
if (probe.fd >= 0)
|
|
|
|
close(probe.fd);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2003-07-22 03:42:19 +04:00
|
|
|
int blkid_known_fstype(const char *fstype)
|
|
|
|
{
|
|
|
|
struct blkid_magic *id;
|
|
|
|
|
|
|
|
for (id = type_array; id->bim_type; id++) {
|
|
|
|
if (strcmp(fstype, id->bim_type) == 0)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
#ifdef TEST_PROGRAM
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_dev dev;
|
2003-02-13 07:51:21 +03:00
|
|
|
blkid_cache cache;
|
2003-02-23 01:15:20 +03:00
|
|
|
int ret;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Usage: %s device\n"
|
|
|
|
"Probe a single device to determine type\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-02-23 01:15:20 +03:00
|
|
|
if ((ret = blkid_get_cache(&cache, "/dev/null")) != 0) {
|
|
|
|
fprintf(stderr, "%s: error creating cache (%d)\n",
|
|
|
|
argv[0], ret);
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-02-16 08:47:07 +03:00
|
|
|
dev = blkid_get_dev(cache, argv[1], BLKID_DEV_NORMAL);
|
2003-02-13 07:51:21 +03:00
|
|
|
if (!dev) {
|
2003-01-24 00:45:16 +03:00
|
|
|
printf("%s: %s has an unsupported type\n", argv[0], argv[1]);
|
2003-02-13 07:51:21 +03:00
|
|
|
return (1);
|
|
|
|
}
|
2005-09-10 23:55:14 +04:00
|
|
|
printf("TYPE='%s'\n", dev->bid_type ? dev->bid_type : "(null)");
|
2003-02-13 07:51:21 +03:00
|
|
|
if (dev->bid_label)
|
2005-09-10 23:55:14 +04:00
|
|
|
printf("LABEL='%s'\n", dev->bid_label);
|
2003-02-13 07:51:21 +03:00
|
|
|
if (dev->bid_uuid)
|
2005-09-10 23:55:14 +04:00
|
|
|
printf("UUID='%s'\n", dev->bid_uuid);
|
2003-02-13 07:51:21 +03:00
|
|
|
|
|
|
|
blkid_free_dev(dev);
|
2003-01-24 00:45:16 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|