erofs: Add support for FS_IOC_GETFSLABEL
PATCH v4 1/1 erofs: Add support for FS_IOC_GETFSLABEL
From: Bo Liu (OpenAnolis) <[email protected]>
Add support for reading to the erofs volume label from the FS_IOC_GETFSLABEL ioctls.
---
v1: https://lore.kernel.org/linux-erofs/[email protected]/
v2: https://lore.kernel.org/linux-erofs/[email protected]/
v3: https://lore.kernel.org/linux-erofs/[email protected]/
change since v3:
- move functions into inode.
- remove useless comment.
fs/erofs/data.c | 4 ++++ fs/erofs/dir.c | 4 ++++ fs/erofs/inode.c | 40 ++++++++++++++++++++++++++++++++++++---- fs/erofs/internal.h | 6 ++++++ fs/erofs/super.c | 8 ++++++++ 5 files changed, 58 insertions(+), 4 deletions(-)
fs/erofs/data.c +4 -0
@@ -475,6 +475,10 @@ static loff_t erofs_file_llseek(struct file *file, loff_t offset, int whence)const struct file_operations erofs_file_fops = { .llseek = erofs_file_llseek, .read_iter = erofs_file_read_iter, + .unlocked_ioctl = erofs_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = erofs_compat_ioctl, +#endif .mmap_prepare = erofs_file_mmap_prepare, .get_unmapped_area = thp_get_unmapped_area, .splice_read = filemap_splice_read,
fs/erofs/dir.c +4 -0
@@ -123,4 +123,8 @@ const struct file_operations erofs_dir_fops = { .llseek = generic_file_llseek, .read = generic_read_dir, .iterate_shared = erofs_readdir, + .unlocked_ioctl = erofs_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = erofs_compat_ioctl, +#endif };
fs/erofs/inode.c +36 -4
@@ -213,10 +213,7 @@ static int erofs_fill_inode(struct inode *inode)switch (inode->i_mode &S_IFMT ) {case S_IFREG : inode->i_op = &erofs_generic_iops; -if (erofs_inode_is_data_compressed (vi->datalayout)) - inode->i_fop = &generic_ro_fops; -else - inode->i_fop = &erofs_file_fops; + inode->i_fop = &erofs_file_fops;break ;case S_IFDIR : inode->i_op = &erofs_dir_iops;
@@ -341,6 +338,41 @@ int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,return 0 ; } +static int erofs_ioctl_get_volume_label (struct inode *inode,void __user *arg) +{ +struct erofs_sb_info *sbi =EROFS_I_SB (inode); +int ret; + +if (!sbi->volume_name) + ret =clear_user (arg,1 ); +else + ret =copy_to_user (arg, sbi->volume_name, +strlen (sbi->volume_name)); + +return ret ? -EFAULT :0 ; +} + +long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct inode *inode =file_inode (filp); +void __user *argp = (void __user *)arg; + +switch (cmd) { +case FS_IOC_GETFSLABEL : +return erofs_ioctl_get_volume_label (inode, argp); +default : +return -ENOTTY ; + } +} + +#ifdef CONFIG_COMPAT +long erofs_compat_ioctl (struct file *filp,unsigned int cmd, +unsigned long arg) +{ +return erofs_ioctl (filp, cmd, (unsigned long )compat_ptr (arg)); +} +#endif +const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, .listxattr = erofs_listxattr,
fs/erofs/internal.h +6 -0
@@ -166,6 +166,8 @@ struct erofs_sb_info {struct erofs_domain *domain;char *fsid;char *domain_id; + +char *volume_name; };#define EROFS_SB (sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
@@ -535,6 +537,10 @@ static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) {static inline void erofs_fscache_submit_bio (struct bio *bio) {}#endif +long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg); +long erofs_compat_ioctl (struct file *filp,unsigned int cmd, +unsigned long arg); +#define EFSCORRUPTED EUCLEAN/* Filesystem is corrupted */ #endif /* __EROFS_INTERNAL_H */
fs/erofs/super.c +8 -0
@@ -343,6 +343,13 @@ static int erofs_read_superblock(struct super_block *sb) sbi->fixed_nsec =le32_to_cpu (dsb->fixed_nsec);super_set_uuid (sb, (void *)dsb->uuid,sizeof (dsb->uuid)); +if (dsb->volume_name[0 ]) { + sbi->volume_name =kstrndup (dsb->volume_name, +sizeof (dsb->volume_name),GFP_KERNEL ); +if (!sbi->volume_name) +return -ENOMEM ; + } +/* parse on-disk compression configurations */ ret =z_erofs_parse_cfgs (sb, dsb);if (ret <0 )
@@ -822,6 +829,7 @@ static void erofs_sb_free(struct erofs_sb_info *sbi)kfree (sbi->domain_id);if (sbi->dif0.file)fput (sbi->dif0.file); +kfree (sbi->volume_name);kfree (sbi); }
Signature · 1 line
2.31.1
Quoted 6 lines · Bo Liu
From: Bo Liu (OpenAnolis) <[email protected]>
Add support for reading to the erofs volume label from the
FS_IOC_GETFSLABELioctls.Signed-off-by Bo Liu (OpenAnolis) <[email protected]>
Thanks,
Gao Xiang
Chao Yu
maintainerQuoted 123 lines · Bo Liu
From: Bo Liu (OpenAnolis) <[email protected]>
Add support for reading to the erofs volume label from the
FS_IOC_GETFSLABELioctls.Signed-off-by Bo Liu (OpenAnolis) <[email protected]>---
v1: https://lore.kernel.org/linux-erofs/[email protected]/
v2: https://lore.kernel.org/linux-erofs/[email protected]/
v3: https://lore.kernel.org/linux-erofs/[email protected]/change since v3:
- move functions into inode.
- remove useless comment.fs/erofs/data.c | 4 ++++ fs/erofs/dir.c | 4 ++++ fs/erofs/inode.c | 40 ++++++++++++++++++++++++++++++++++++---- fs/erofs/internal.h | 6 ++++++ fs/erofs/super.c | 8 ++++++++ 5 files changed, 58 insertions(+), 4 deletions(-)fs/erofs/data.c +4
-0@@ -475,6 +475,10 @@ static loff_t erofs_file_llseek(struct file *file, loff_t offset, int whence)const struct file_operations erofs_file_fops = { .llseek = erofs_file_llseek, .read_iter = erofs_file_read_iter, + .unlocked_ioctl = erofs_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = erofs_compat_ioctl, +#endif .mmap_prepare = erofs_file_mmap_prepare, .get_unmapped_area = thp_get_unmapped_area, .splice_read = filemap_splice_read,fs/erofs/dir.c +4
-0@@ -123,4 +123,8 @@ const struct file_operations erofs_dir_fops = { .llseek = generic_file_llseek, .read = generic_read_dir, .iterate_shared = erofs_readdir, + .unlocked_ioctl = erofs_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = erofs_compat_ioctl, +#endif };fs/erofs/inode.c +36
-4@@ -213,10 +213,7 @@ static int erofs_fill_inode(struct inode *inode)switch (inode->i_mode &S_IFMT ) {case S_IFREG : inode->i_op = &erofs_generic_iops; -if (erofs_inode_is_data_compressed (vi->datalayout)) - inode->i_fop = &generic_ro_fops; -else - inode->i_fop = &erofs_file_fops; + inode->i_fop = &erofs_file_fops;break ;case S_IFDIR : inode->i_op = &erofs_dir_iops;@@ -341,6 +338,41 @@ int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,return 0 ; } +static int erofs_ioctl_get_volume_label (struct inode *inode,void __user *arg) +{ +struct erofs_sb_info *sbi =EROFS_I_SB (inode); +int ret; + +if (!sbi->volume_name) + ret =clear_user (arg,1 ); +else + ret =copy_to_user (arg, sbi->volume_name, +strlen (sbi->volume_name)); + +return ret ? -EFAULT :0 ; +} + +long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct inode *inode =file_inode (filp); +void __user *argp = (void __user *)arg; + +switch (cmd) { +case FS_IOC_GETFSLABEL : +return erofs_ioctl_get_volume_label (inode, argp); +default : +return -ENOTTY ; + } +} + +#ifdef CONFIG_COMPAT +long erofs_compat_ioctl (struct file *filp,unsigned int cmd, +unsigned long arg) +{ +return erofs_ioctl (filp, cmd, (unsigned long )compat_ptr (arg)); +} +#endif +const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, .listxattr = erofs_listxattr,fs/erofs/internal.h +2
-0@@ -166,6 +166,8 @@ struct erofs_sb_info {struct erofs_domain *domain;char *fsid;char *domain_id; + +char *volume_name; };#define EROFS_SB (sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
fs/erofs/internal.h static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) { · line 540
Quoted 4 lines
fs/erofs/internal.h +1
-0@@ -535,6 +537,10 @@ static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) {static inline void erofs_fscache_submit_bio (struct bio *bio) {}#endif +long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);
#ifdef CONFIG_COMPAT
fs/erofs/internal.h static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) { · line 542
Quoted 2 lines
fs/erofs/internal.h +2
-0+long erofs_compat_ioctl (struct file *filp,unsigned int cmd, +unsigned long arg);
#endif
Thanks,
Quoted 30 lines
fs/erofs/internal.h +1
-0+#define EFSCORRUPTED EUCLEAN/* Filesystem is corrupted */ #endif /* __EROFS_INTERNAL_H */ fs/erofs/super.c +8
-0@@ -343,6 +343,13 @@ static int erofs_read_superblock(struct super_block *sb) sbi->fixed_nsec =le32_to_cpu (dsb->fixed_nsec);super_set_uuid (sb, (void *)dsb->uuid,sizeof (dsb->uuid)); +if (dsb->volume_name[0 ]) { + sbi->volume_name =kstrndup (dsb->volume_name, +sizeof (dsb->volume_name),GFP_KERNEL ); +if (!sbi->volume_name) +return -ENOMEM ; + } +/* parse on-disk compression configurations */ ret =z_erofs_parse_cfgs (sb, dsb);if (ret <0 )@@ -822,6 +829,7 @@ static void erofs_sb_free(struct erofs_sb_info *sbi)kfree (sbi->domain_id);if (sbi->dif0.file)fput (sbi->dif0.file); +kfree (sbi->volume_name);kfree (sbi); }
Hi Chao,
Quoted 8 lines · Chao Yu
Quoted 7 lines · Bo Liu
From: Bo Liu (OpenAnolis) <[email protected]>
Add support for reading to the erofs volume label from the
FS_IOC_GETFSLABELioctls.Signed-off-by Bo Liu (OpenAnolis) <[email protected]>---
...
Quoted 7 lines
Quoted 2 lines
+long
erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);#ifdef
CONFIG_COMPATfs/erofs/internal.h static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) { · line 542
Quoted 2 lines
fs/erofs/internal.h +2
-0+long erofs_compat_ioctl (struct file *filp,unsigned int cmd, +unsigned long arg);
Since it's a function declaration, when CONFIG_COMPAT is not defined, there is no user to use erofs_compat_ioctl(), so I think it is fine to just leave the declaration here?
Thanks,
Gao Xiang
Quoted 7 lines
#endif
Thanks,
Quoted 1 line
+
Chao Yu
maintainerQuoted 16 lines · Gao Xiang
Hi Chao,
Quoted 8 lines · Chao Yu
Quoted 7 lines · Bo Liu
From: Bo Liu (OpenAnolis) <[email protected]>
Add support for reading to the erofs volume label from the
FS_IOC_GETFSLABELioctls.Signed-off-by Bo Liu (OpenAnolis) <[email protected]>---
...
Quoted 2 lines
Quoted 1 line
+long
erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
Quoted 8 lines
Quoted 4 lines
#ifdef
CONFIG_COMPATQuoted 2 lines
+long
erofs_compat_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg);Since it's a function declaration, when
CONFIG_COMPATis not defined, there is no user to useerofs_compat_ioctl(), so I think it is fine to just leave the declaration here?
Xiang,
Sure, it won't affect compile and link, we can leave it as it is since it's trivial.
Thanks,
Quoted 13 lines
Thanks,
Gao XiangQuoted 7 lines
#endif
Thanks,
Quoted 1 line
+
Quoted 22 lines · Chao Yu
Quoted 21 lines · Gao Xiang
Hi Chao,
Quoted 8 lines · Chao Yu
Quoted 7 lines · Bo Liu
From: Bo Liu (OpenAnolis) <[email protected]>
Add support for reading to the erofs volume label from the
FS_IOC_GETFSLABELioctls.Signed-off-by Bo Liu (OpenAnolis) <[email protected]>---
...
Quoted 6 lines
Quoted 1 line
+long
erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);#ifdef
CONFIG_COMPATQuoted 2 lines
+long
erofs_compat_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg);
Quoted 7 lines
Quoted 3 lines
Since it's a function declaration, when
CONFIG_COMPATis not defined, there is no user to useerofs_compat_ioctl(), so I think it is fine to just leave the declaration here?Xiang,
Sure, it won't affect compile and link, we can leave it as it is since it's trivial.
Yeah, my preference is to avoid unnecessary #ifdef if possible, anyway (since unused function declarations won't affect anything..)
Thanks,
Gao Xiang
Quoted 16 lines
Thanks,
Quoted 13 lines
Thanks,
Gao XiangQuoted 7 lines
#endif
Thanks,
Quoted 1 line
+
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Bo,
kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR on xiang-erofs/dev xiang-erofs/fixes linus/master v6.17-rc7 next-20250922] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bo-Liu/erofs-Add-support-for-FS_IOC_GETFSLABEL/20250922-173127 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test patch link: https://lore.kernel.org/r/20250922092937.2055-1-liubo03%40inspur.com patch subject: [PATCH v4] erofs: Add support for FS_IOC_GETFSLABEL config: sparc64-randconfig-001-20250923 (https://download.01.org/0day-ci/archive/20250923/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project cafc064fc7a96b3979a023ddae1da2b499d6c954) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250923/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> fs/erofs/inode.c:372:47: error: call to undeclared function 'compat_ptr'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
372 | return erofs_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
| ^1 error generated.
vim +/compat_ptr +372 fs/erofs/inode.c
367
368 #ifdef CONFIG_COMPAT
369 long erofs_compat_ioctl(struct file *filp, unsigned int cmd,
370 unsigned long arg)
371 {
> 372 return erofs_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
373 }
374 #endif
375
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki