2
* Copyright (C) 2010 by Jiro SEKIBA <jir@unicus.jp>
4
* This file may be redistributed under the terms of the
5
* GNU Lesser General Public License
10
#include "superblocks.h"
13
struct nilfs_super_block {
15
uint16_t s_minor_rev_level;
24
uint32_t s_log_block_size;
28
uint64_t s_first_data_block;
29
uint32_t s_blocks_per_segment;
30
uint32_t s_r_segments_percentage;
35
uint64_t s_free_blocks_count;
42
uint16_t s_max_mnt_count;
47
uint32_t s_checkinterval;
48
uint32_t s_creator_os;
49
uint16_t s_def_resuid;
50
uint16_t s_def_resgid;
53
uint16_t s_inode_size;
54
uint16_t s_dat_entry_size;
55
uint16_t s_checkpoint_size;
56
uint16_t s_segment_usage_size;
59
char s_volume_name[80];
61
uint32_t s_c_interval;
62
uint32_t s_c_block_max;
63
uint32_t s_reserved[192];
66
/* nilfs2 magic string */
67
#define NILFS_SB_MAGIC "\x34\x34"
68
/* nilfs2 super block offset */
69
#define NILFS_SB_OFF 0x400
70
/* nilfs2 super block offset in kB */
71
#define NILFS_SB_KBOFF (NILFS_SB_OFF >> 10)
72
/* nilfs2 magic string offset within super block */
73
#define NILFS_MAG_OFF 6
75
static int probe_nilfs2(blkid_probe pr, const struct blkid_idmag *mag)
77
struct nilfs_super_block *sb;
78
static unsigned char sum[4];
79
const int sumoff = offsetof(struct nilfs_super_block, s_sum);
83
sb = blkid_probe_get_sb(pr, mag, struct nilfs_super_block);
87
bytes = le16_to_cpu(sb->s_bytes);
88
crc = crc32(le32_to_cpu(sb->s_crc_seed), (unsigned char *)sb, sumoff);
89
crc = crc32(crc, sum, 4);
90
crc = crc32(crc, (unsigned char *)sb + sumoff + 4, bytes - sumoff - 4);
92
if (crc != le32_to_cpu(sb->s_sum))
95
if (strlen(sb->s_volume_name))
96
blkid_probe_set_label(pr, (unsigned char *) sb->s_volume_name,
97
sizeof(sb->s_volume_name));
99
blkid_probe_set_uuid(pr, sb->s_uuid);
100
blkid_probe_sprintf_version(pr, "%u", le32_to_cpu(sb->s_rev_level));
105
const struct blkid_idinfo nilfs2_idinfo =
108
.usage = BLKID_USAGE_FILESYSTEM,
109
.probefunc = probe_nilfs2,
113
.magic = NILFS_SB_MAGIC,
115
.kboff = NILFS_SB_KBOFF,
116
.sboff = NILFS_MAG_OFF