Skip to content

Commit a4af51c

Browse files
Kent Overstreetbrauner
authored andcommitted
fs: super_set_uuid()
Some weird old filesytems have UUID-like things that we wish to expose as UUIDs, but are smaller; add a length field so that the new FS_IOC_(GET|SET)UUID ioctls can handle them in generic code. And add a helper super_set_uuid(), for setting nonstandard length uuids. Helper is now required for the new FS_IOC_GETUUID ioctl; if super_set_uuid() hasn't been called, the ioctl won't be supported. Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev> Link: https://lore.kernel.org/r/20240207025624.1019754-2-kent.overstreet@linux.dev Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 6613476 commit a4af51c

File tree

9 files changed

+22
-9
lines changed

9 files changed

+22
-9
lines changed

fs/ext4/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5346,7 +5346,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53465346
sb->s_qcop = &ext4_qctl_operations;
53475347
sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
53485348
#endif
5349-
memcpy(&sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
5349+
super_set_uuid(sb, es->s_uuid, sizeof(es->s_uuid));
53505350

53515351
INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
53525352
mutex_init(&sbi->s_orphan_lock);

fs/f2fs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4496,7 +4496,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
44964496
sb->s_time_gran = 1;
44974497
sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
44984498
(test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
4499-
memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
4499+
super_set_uuid(sb, (void *) raw_super->uuid, sizeof(raw_super->uuid));
45004500
sb->s_iflags |= SB_I_CGROUPWB;
45014501

45024502
/* init f2fs-specific super block info */

fs/gfs2/ops_fstype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void gfs2_sb_in(struct gfs2_sbd *sdp, const void *buf)
214214

215215
memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
216216
memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
217-
memcpy(&s->s_uuid, str->sb_uuid, 16);
217+
super_set_uuid(s, str->sb_uuid, 16);
218218
}
219219

220220
/**

fs/kernfs/mount.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ int kernfs_get_tree(struct fs_context *fc)
358358
}
359359
sb->s_flags |= SB_ACTIVE;
360360

361-
uuid_gen(&sb->s_uuid);
361+
uuid_t uuid;
362+
uuid_gen(&uuid);
363+
super_set_uuid(sb, uuid.b, sizeof(uuid));
362364

363365
down_write(&root->kernfs_supers_rwsem);
364366
list_add(&info->node, &info->root->supers);

fs/ocfs2/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,8 +2027,8 @@ static int ocfs2_initialize_super(struct super_block *sb,
20272027
cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
20282028
bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
20292029
sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
2030-
memcpy(&sb->s_uuid, di->id2.i_super.s_uuid,
2031-
sizeof(di->id2.i_super.s_uuid));
2030+
super_set_uuid(sb, di->id2.i_super.s_uuid,
2031+
sizeof(di->id2.i_super.s_uuid));
20322032

20332033
osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
20342034

fs/ubifs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
22452245
goto out_umount;
22462246
}
22472247

2248-
import_uuid(&sb->s_uuid, c->uuid);
2248+
super_set_uuid(sb, c->uuid, sizeof(c->uuid));
22492249

22502250
mutex_unlock(&c->umount_mutex);
22512251
return 0;

fs/xfs/xfs_mount.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ xfs_uuid_mount(
6262
int hole, i;
6363

6464
/* Publish UUID in struct super_block */
65-
uuid_copy(&mp->m_super->s_uuid, uuid);
65+
super_set_uuid(mp->m_super, uuid->b, sizeof(*uuid));
6666

6767
if (xfs_has_nouuid(mp))
6868
return 0;

include/linux/fs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,7 @@ struct super_block {
12571257

12581258
char s_id[32]; /* Informational name */
12591259
uuid_t s_uuid; /* UUID */
1260+
u8 s_uuid_len; /* Default 16, possibly smaller for weird filesystems */
12601261

12611262
unsigned int s_max_links;
12621263

@@ -2532,6 +2533,14 @@ extern __printf(2, 3)
25322533
int super_setup_bdi_name(struct super_block *sb, char *fmt, ...);
25332534
extern int super_setup_bdi(struct super_block *sb);
25342535

2536+
static inline void super_set_uuid(struct super_block *sb, const u8 *uuid, unsigned len)
2537+
{
2538+
if (WARN_ON(len > sizeof(sb->s_uuid)))
2539+
len = sizeof(sb->s_uuid);
2540+
sb->s_uuid_len = len;
2541+
memcpy(&sb->s_uuid, uuid, len);
2542+
}
2543+
25352544
extern int current_umask(void);
25362545

25372546
extern void ihold(struct inode * inode);

mm/shmem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4355,7 +4355,9 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
43554355
#ifdef CONFIG_TMPFS_POSIX_ACL
43564356
sb->s_flags |= SB_POSIXACL;
43574357
#endif
4358-
uuid_gen(&sb->s_uuid);
4358+
uuid_t uuid;
4359+
uuid_gen(&uuid);
4360+
super_set_uuid(sb, uuid.b, sizeof(uuid));
43594361

43604362
#ifdef CONFIG_TMPFS_QUOTA
43614363
if (ctx->seen & SHMEM_SEEN_QUOTA) {

0 commit comments

Comments
 (0)