Skip to content

Commit 7c5efd0

Browse files
pkunH. Peter Anvin
authored andcommitted
FSUUID for ext2 filesystem
The ext2 filesystem supports volume UUID now. The FSUUID variable can be set to kernel command line. Patch is based on FSUUID for FAT patch. Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent 386b59e commit 7c5efd0

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

core/fs/ext2/ext2.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ static int ext2_fs_init(struct fs_info *fs)
312312
sbi->s_first_data_block = sb.s_first_data_block;
313313
sbi->s_inode_size = sb.s_inode_size;
314314

315+
/* Volume UUID */
316+
memcpy(sbi->s_uuid, sb.s_uuid, sizeof(sbi->s_uuid));
317+
315318
/* Initialize the cache, and force block zero to all zero */
316319
cache_init(fs->fs_dev, fs->block_shift);
317320
cs = _get_cache_block(fs->fs_dev, 0);
@@ -321,6 +324,41 @@ static int ext2_fs_init(struct fs_info *fs)
321324
return fs->block_shift;
322325
}
323326

327+
#define EXT2_UUID_LEN (4 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + 4 + 4 + 1)
328+
static char *ext2_fs_uuid(struct fs_info *fs)
329+
{
330+
char *uuid = NULL;
331+
332+
uuid = malloc(EXT2_UUID_LEN);
333+
if (!uuid)
334+
return NULL;
335+
336+
if (snprintf(uuid, EXT2_UUID_LEN,
337+
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
338+
EXT2_SB(fs)->s_uuid[0],
339+
EXT2_SB(fs)->s_uuid[1],
340+
EXT2_SB(fs)->s_uuid[2],
341+
EXT2_SB(fs)->s_uuid[3],
342+
EXT2_SB(fs)->s_uuid[4],
343+
EXT2_SB(fs)->s_uuid[5],
344+
EXT2_SB(fs)->s_uuid[6],
345+
EXT2_SB(fs)->s_uuid[7],
346+
EXT2_SB(fs)->s_uuid[8],
347+
EXT2_SB(fs)->s_uuid[9],
348+
EXT2_SB(fs)->s_uuid[10],
349+
EXT2_SB(fs)->s_uuid[11],
350+
EXT2_SB(fs)->s_uuid[12],
351+
EXT2_SB(fs)->s_uuid[13],
352+
EXT2_SB(fs)->s_uuid[14],
353+
EXT2_SB(fs)->s_uuid[15]
354+
) < 0) {
355+
free(uuid);
356+
return NULL;
357+
}
358+
359+
return uuid;
360+
}
361+
324362
const struct fs_ops ext2_fs_ops = {
325363
.fs_name = "ext2",
326364
.fs_flags = FS_THISIND | FS_USEMEM,
@@ -336,5 +374,5 @@ const struct fs_ops ext2_fs_ops = {
336374
.readlink = ext2_readlink,
337375
.readdir = ext2_readdir,
338376
.next_extent = ext2_next_extent,
339-
.fs_uuid = NULL,
377+
.fs_uuid = ext2_fs_uuid,
340378
};

core/fs/ext2/ext2_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ struct ext2_sb_info {
277277
uint32_t s_groups_count; /* Number of groups in the fs */
278278
uint32_t s_first_data_block; /* First Data Block */
279279
int s_inode_size;
280+
uint8_t s_uuid[16]; /* 128-bit uuid for volume */
280281
};
281282

282283
static inline struct ext2_sb_info *EXT2_SB(struct fs_info *fs)

0 commit comments

Comments
 (0)