Skip to content

Commit 41bcbe5

Browse files
Kent Overstreetbrauner
authored andcommitted
fs: FS_IOC_GETUUID
Add a new generic ioctls for querying the filesystem UUID. These are lifted versions of the ext4 ioctls, with one change: we're not using a flexible array member, because UUIDs will never be more than 16 bytes. This patch adds a generic implementation of FS_IOC_GETFSUUID, which reads from super_block->s_uuid. We're not lifting SETFSUUID from ext4 - that can be done on offline filesystems by the people who need it, trying to do it online is just asking for too much trouble. Cc: Christian Brauner <brauner@kernel.org> Cc: Jan Kara <jack@suse.cz> Cc: Dave Chinner <dchinner@redhat.com> Cc: Darrick J. Wong <djwong@kernel.org> Cc: Theodore Ts'o <tytso@mit.edu> Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev> Link: https://lore.kernel.org/r/20240207025624.1019754-4-kent.overstreet@linux.dev Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent dd90196 commit 41bcbe5

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Documentation/userspace-api/ioctl/ioctl-number.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ Code Seq# Include File Comments
8282
0x10 00-0F drivers/char/s390/vmcp.h
8383
0x10 10-1F arch/s390/include/uapi/sclp_ctl.h
8484
0x10 20-2F arch/s390/include/uapi/asm/hypfs.h
85-
0x12 all linux/fs.h
85+
0x12 all linux/fs.h BLK* ioctls
8686
linux/blkpg.h
87+
0x15 all linux/fs.h FS_IOC_* ioctls
8788
0x1b all InfiniBand Subsystem
8889
<http://infiniband.sourceforge.net/>
8990
0x20 all drivers/cdrom/cm206.h

fs/ioctl.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,19 @@ static int ioctl_fssetxattr(struct file *file, void __user *argp)
763763
return err;
764764
}
765765

766+
static int ioctl_getfsuuid(struct file *file, void __user *argp)
767+
{
768+
struct super_block *sb = file_inode(file)->i_sb;
769+
struct fsuuid2 u = { .len = sb->s_uuid_len, };
770+
771+
if (!sb->s_uuid_len)
772+
return -ENOIOCTLCMD;
773+
774+
memcpy(&u.uuid[0], &sb->s_uuid, sb->s_uuid_len);
775+
776+
return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
777+
}
778+
766779
/*
767780
* do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
768781
* It's just a simple helper for sys_ioctl and compat_sys_ioctl.
@@ -845,6 +858,9 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
845858
case FS_IOC_FSSETXATTR:
846859
return ioctl_fssetxattr(filp, argp);
847860

861+
case FS_IOC_GETFSUUID:
862+
return ioctl_getfsuuid(filp, argp);
863+
848864
default:
849865
if (S_ISREG(inode->i_mode))
850866
return file_ioctl(filp, cmd, argp);

include/uapi/linux/fs.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ struct fstrim_range {
6464
__u64 minlen;
6565
};
6666

67+
/*
68+
* We include a length field because some filesystems (vfat) have an identifier
69+
* that we do want to expose as a UUID, but doesn't have the standard length.
70+
*
71+
* We use a fixed size buffer beacuse this interface will, by fiat, never
72+
* support "UUIDs" longer than 16 bytes; we don't want to force all downstream
73+
* users to have to deal with that.
74+
*/
75+
struct fsuuid2 {
76+
__u8 len;
77+
__u8 uuid[16];
78+
};
79+
6780
/* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
6881
#define FILE_DEDUPE_RANGE_SAME 0
6982
#define FILE_DEDUPE_RANGE_DIFFERS 1
@@ -215,6 +228,8 @@ struct fsxattr {
215228
#define FS_IOC_FSSETXATTR _IOW('X', 32, struct fsxattr)
216229
#define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX])
217230
#define FS_IOC_SETFSLABEL _IOW(0x94, 50, char[FSLABEL_MAX])
231+
/* Returns the external filesystem UUID, the same one blkid returns */
232+
#define FS_IOC_GETFSUUID _IOR(0x15, 0, struct fsuuid2)
218233

219234
/*
220235
* Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)

0 commit comments

Comments
 (0)