ext.c revision 2603474ff9be2418900581da1af5cccc9f13cae1
/*
* volume_id - reads filesystem label and uuid
*
* Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
* Copyright (C) 2008 Theodore Ts'o <tytso@mit.edu>
*
* The probe logic is based on libblkid from e2fsutils.
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "libvolume_id.h"
#include "libvolume_id-private.h"
#include "util.h"
struct ext2_super_block {
} PACKED;
#define EXT_SUPER_MAGIC 0xEF53
#define EXT2_FLAGS_TEST_FILESYS 0x0004
#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
#define EXT_SUPERBLOCK_OFFSET 0x400
#define EXT3_MIN_BLOCK_SIZE 0x400
#define EXT3_MAX_BLOCK_SIZE 0x1000
{
struct ext2_super_block *es;
return -1;
return -1;
dbg("invalid ext blocksize\n");
return -1;
}
/* external journal device is jbd */
if ((feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) != 0) {
goto found;
}
/* has journal */
if ((feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0) {
/* "use on development code" is ext4dev */
if ((flags & EXT2_FLAGS_TEST_FILESYS) != 0) {
goto found;
}
/* incompatible ext3 features is ext4 */
if ((feature_ro_compat & EXT3_FEATURE_RO_COMPAT_UNSUPPORTED) != 0 ||
(feature_incompat & EXT3_FEATURE_INCOMPAT_UNSUPPORTED) != 0) {
goto found;
}
goto found;
} else {
/* no incompatible ext2 feature is ext2 */
if ((feature_ro_compat & EXT2_FEATURE_RO_COMPAT_UNSUPPORTED) == 0 &&
(feature_incompat & EXT2_FEATURE_INCOMPAT_UNSUPPORTED) == 0) {
goto found;
}
}
return -1;
return 0;
}