1 From b44b8600d4096de8203c1fb0702bbc95ee51017f Mon Sep 17 00:00:00 2001
2 From: Jiro SEKIBA <jir@unicus.jp>
3 Date: Tue, 13 Jul 2010 09:12:56 +0200
4 Subject: [PATCH] libblkid: add nilfs2 filesystem superblock probe
6 This patch implements nilfs2_idinfo to proble nilfs2 partition.
7 The patch probes uuid, label, version and verify crc check sum of
10 Signed-off-by: Jiro SEKIBA <jir@unicus.jp>
11 Signed-off-by: Karel Zak <kzak@redhat.com>
13 shlibs/blkid/src/superblocks/Makefile.am | 1 +
14 shlibs/blkid/src/superblocks/nilfs.c | 120 ++++++++++++++++++++++++++++
15 shlibs/blkid/src/superblocks/superblocks.c | 1 +
16 shlibs/blkid/src/superblocks/superblocks.h | 1 +
17 4 files changed, 123 insertions(+), 0 deletions(-)
18 create mode 100644 shlibs/blkid/src/superblocks/nilfs.c
20 diff --git a/shlibs/blkid/src/superblocks/Makefile.am b/shlibs/blkid/src/superblocks/Makefile.am
21 index 39b074b..1501fab 100644
22 --- a/shlibs/blkid/src/superblocks/Makefile.am
23 +++ b/shlibs/blkid/src/superblocks/Makefile.am
24 @@ -47,4 +47,5 @@ libblkid_superblocks_la_SOURCES = \
30 diff --git a/shlibs/blkid/src/superblocks/nilfs.c b/shlibs/blkid/src/superblocks/nilfs.c
32 index 0000000..c7aba35
34 +++ b/shlibs/blkid/src/superblocks/nilfs.c
37 + * Copyright (C) 2010 by Jiro SEKIBA <jir@unicus.jp>
39 + * This file may be redistributed under the terms of the
40 + * GNU Lesser General Public License
45 +#include "superblocks.h"
48 +struct nilfs_super_block {
49 + uint32_t s_rev_level;
50 + uint16_t s_minor_rev_level;
56 + uint32_t s_crc_seed;
59 + uint32_t s_log_block_size;
61 + uint64_t s_nsegments;
62 + uint64_t s_dev_size;
63 + uint64_t s_first_data_block;
64 + uint32_t s_blocks_per_segment;
65 + uint32_t s_r_segments_percentage;
67 + uint64_t s_last_cno;
68 + uint64_t s_last_pseg;
69 + uint64_t s_last_seq;
70 + uint64_t s_free_blocks_count;
76 + uint16_t s_mnt_count;
77 + uint16_t s_max_mnt_count;
80 + uint64_t s_lastcheck;
82 + uint32_t s_checkinterval;
83 + uint32_t s_creator_os;
84 + uint16_t s_def_resuid;
85 + uint16_t s_def_resgid;
86 + uint32_t s_first_ino;
88 + uint16_t s_inode_size;
89 + uint16_t s_dat_entry_size;
90 + uint16_t s_checkpoint_size;
91 + uint16_t s_segment_usage_size;
94 + char s_volume_name[80];
96 + uint32_t s_c_interval;
97 + uint32_t s_c_block_max;
98 + uint32_t s_reserved[192];
101 +/* nilfs2 magic string */
102 +#define NILFS_SB_MAGIC "\x34\x34"
103 +/* nilfs2 super block offset */
104 +#define NILFS_SB_OFF 0x400
105 +/* nilfs2 super block offset in kB */
106 +#define NILFS_SB_KBOFF (NILFS_SB_OFF >> 10)
107 +/* nilfs2 magic string offset within super block */
108 +#define NILFS_MAG_OFF 6
110 +static int probe_nilfs2(blkid_probe pr, const struct blkid_idmag *mag)
112 + struct nilfs_super_block *sb;
113 + static unsigned char sum[4];
114 + const int sumoff = offsetof(struct nilfs_super_block, s_sum);
118 + sb = blkid_probe_get_sb(pr, mag, struct nilfs_super_block);
122 + bytes = le32_to_cpu(sb->s_bytes);
123 + crc = crc32(le32_to_cpu(sb->s_crc_seed), (unsigned char *)sb, sumoff);
124 + crc = crc32(crc, sum, 4);
125 + crc = crc32(crc, (unsigned char *)sb + sumoff + 4, bytes - sumoff - 4);
127 + if (crc != le32_to_cpu(sb->s_sum))
130 + if (strlen(sb->s_volume_name))
131 + blkid_probe_set_label(pr, (unsigned char *) sb->s_volume_name,
132 + sizeof(sb->s_volume_name));
134 + blkid_probe_set_uuid(pr, sb->s_uuid);
135 + blkid_probe_sprintf_version(pr, "%u", le32_to_cpu(sb->s_rev_level));
140 +const struct blkid_idinfo nilfs2_idinfo =
143 + .usage = BLKID_USAGE_FILESYSTEM,
144 + .probefunc = probe_nilfs2,
148 + .magic = NILFS_SB_MAGIC,
150 + .kboff = NILFS_SB_KBOFF,
151 + .sboff = NILFS_MAG_OFF
156 diff --git a/shlibs/blkid/src/superblocks/superblocks.c b/shlibs/blkid/src/superblocks/superblocks.c
157 index b80c10b..3d66d98 100644
158 --- a/shlibs/blkid/src/superblocks/superblocks.c
159 +++ b/shlibs/blkid/src/superblocks/superblocks.c
160 @@ -140,6 +140,7 @@ static const struct blkid_idinfo *idinfos[] =
168 diff --git a/shlibs/blkid/src/superblocks/superblocks.h b/shlibs/blkid/src/superblocks/superblocks.h
169 index 74cb974..a79d7cb 100644
170 --- a/shlibs/blkid/src/superblocks/superblocks.h
171 +++ b/shlibs/blkid/src/superblocks/superblocks.h
172 @@ -65,6 +65,7 @@ extern const struct blkid_idinfo vmfs_volume_idinfo;
173 extern const struct blkid_idinfo vmfs_fs_idinfo;
174 extern const struct blkid_idinfo drbd_idinfo;
175 extern const struct blkid_idinfo befs_idinfo;
176 +extern const struct blkid_idinfo nilfs2_idinfo;
177 extern const struct blkid_idinfo exfat_idinfo;
182 From 67bb0074eec2b154d15bd3dd77b482c3d6125761 Mon Sep 17 00:00:00 2001
183 From: Jiro SEKIBA <jir@unicus.jp>
184 Date: Tue, 13 Jul 2010 09:14:08 +0200
185 Subject: [PATCH] tests: add nilfs2 test for libblkid
187 Signed-off-by: Jiro SEKIBA <jir@unicus.jp>
188 Signed-off-by: Karel Zak <kzak@redhat.com>
190 tests/expected/blkid/low-probe-nilfs2 | 7 +++++++
191 tests/ts/blkid/images-fs/nilfs2.img.bz2 | Bin 0 -> 795 bytes
192 2 files changed, 7 insertions(+), 0 deletions(-)
193 create mode 100644 tests/expected/blkid/low-probe-nilfs2
194 create mode 100644 tests/ts/blkid/images-fs/nilfs2.img.bz2
196 diff --git a/tests/expected/blkid/low-probe-nilfs2 b/tests/expected/blkid/low-probe-nilfs2
198 index 0000000..bfd8fcd
200 +++ b/tests/expected/blkid/low-probe-nilfs2
202 +ID_FS_LABEL=test-nilfs2
203 +ID_FS_LABEL_ENC=test-nilfs2
205 +ID_FS_USAGE=filesystem
206 +ID_FS_UUID=524025fb-6d31-40e6-baad-1db36cfdf806
207 +ID_FS_UUID_ENC=524025fb-6d31-40e6-baad-1db36cfdf806
209 diff --git a/tests/ts/blkid/images-fs/nilfs2.img.bz2 b/tests/ts/blkid/images-fs/nilfs2.img.bz2
211 index 0000000000000000000000000000000000000000..a9762eb1ace9f1999aaad3c40f1d836668d856ac
214 zcmZ>Y%CIzaj8qGbG`Ml9n}H$iKM?$BcJi+ANKl`nz?|O0@_@lbK*y;^z=e@R;iM8v
215 z^#R6D2YV7HdVE!LUvc5DPv^n~3?@drY>Er`xpEzs%?rp}D3rOt`HEDABm)D32?GP;
216 z0!EREipv^IOn^)V240{j^Q<Hzqs++;Mp8zSMhpyWZZoCW1WqjeK1)#Iz#6seeHv~(
217 zmxJ_T@69=2^IA3QjKnD|>vorkjN+>MH*4-%s37X<)*F#v)Rf{P;KEe-N=h(9AxK5r
218 zNaB>=<>ixS2R?swwRU~FskVY@0E2@ILyiK&T}MB??Mn}*D~htZ3cdTZRH0!*OIOhp
219 zuF1Yi0SZB_TmsB4k61&aUN!_Ugm_J068*5`gF*w#0teARmnpo_kuT2~GOf!|DtB62
220 z!)T++5$eFKB*GXf;<I9F!NQM?v;8`}*7b6px{&k4S4E)bP}5GYFDbo;*GrVLFkN9@
221 z@@Z9sSb~JGco?eycMA(Q^Ph&Ju|ft>1p%^G=UuLqkPtM9ycck)X|u7g*QFMo>QK!;
222 zURQKH*iWxuZsIwzh@rOT!@1{s7L*D22$pQI7i2k@S1M-~SA2Zm@7XFsJ@fXR;7eg<
223 zQ4&<W_Vc7f@7p(fvkiM$nYo*^O$-78_-wK~RVMkbV1D8JQ`OC<q49;V$o`^l=O3L4
224 zcH6Z3#E!YsGG`s)RMF~EOO1d3>aY{zarw_8qLWfhCp?&^`$6=_69yh&WHm7`bFf@V
225 z(PE04u!6IgDET?h6*ny4n=k(V{?{W7DhkUTSQr9X7>p_oxG=CVFtI2!vN$jZD6(v3
226 z;O=l+m1w{)gHeLB;X+0N+bk2QBw&h}z@#bCHj{nH7h4xLj+2u!PE3DPVsFhCSH8Sp
227 zT}DV?fa{Ns2bOWHVhs!t%xc}wps|W$-`>x&rn$fKjBA>})U}{HMs?HV9M&t-a)KVS
228 zYg}FWIQh_-FYD!hutchUy`86XxmogM<nBjObNPCsG{5_M%3n}$Xkh3NkUdt<dS{}a
236 From 1326e1dfa5c1d06ff7521b8c8162452799164239 Mon Sep 17 00:00:00 2001
237 From: Jiro SEKIBA <jir@unicus.jp>
238 Date: Thu, 15 Jul 2010 13:40:27 +0900
239 Subject: [PATCH] libblkid: fix typo filesystem name nilfs to nilfs2
241 The correct filesystem name is nilfs2, not nilfs.
243 Signed-off-by: Jiro SEKIBA <jir@unicus.jp>
245 shlibs/blkid/src/superblocks/nilfs.c | 2 +-
246 tests/expected/blkid/low-probe-nilfs2 | 2 +-
247 2 files changed, 2 insertions(+), 2 deletions(-)
249 diff --git a/shlibs/blkid/src/superblocks/nilfs.c b/shlibs/blkid/src/superblocks/nilfs.c
250 index c7aba35..bf16918 100644
251 --- a/shlibs/blkid/src/superblocks/nilfs.c
252 +++ b/shlibs/blkid/src/superblocks/nilfs.c
253 @@ -104,7 +104,7 @@ static int probe_nilfs2(blkid_probe pr, const struct blkid_idmag *mag)
255 const struct blkid_idinfo nilfs2_idinfo =
259 .usage = BLKID_USAGE_FILESYSTEM,
260 .probefunc = probe_nilfs2,
262 diff --git a/tests/expected/blkid/low-probe-nilfs2 b/tests/expected/blkid/low-probe-nilfs2
263 index bfd8fcd..c6c9cab 100644
264 --- a/tests/expected/blkid/low-probe-nilfs2
265 +++ b/tests/expected/blkid/low-probe-nilfs2
267 ID_FS_LABEL=test-nilfs2
268 ID_FS_LABEL_ENC=test-nilfs2
271 ID_FS_USAGE=filesystem
272 ID_FS_UUID=524025fb-6d31-40e6-baad-1db36cfdf806
273 ID_FS_UUID_ENC=524025fb-6d31-40e6-baad-1db36cfdf806