bcachefs: implement FS_IOC_GETVERSION to support lsattr
authorHongbo Li <lihongbo22@huawei.com>
Mon, 3 Jun 2024 13:26:18 +0000 (21:26 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 14 Jul 2024 23:00:14 +0000 (19:00 -0400)
In this patch we add the FS_IOC_GETVERSION ioctl for getting
i_generation from inode, after that, users can list file's
generation number by using "lsattr".

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs-ioctl.c

index 79a0c8732bced95d956dc93e719c5ca5ddeb3a2c..add90172b475840faae5333cf554e7c2e9581a46 100644 (file)
@@ -272,6 +272,11 @@ err1:
        return ret;
 }
 
+static int bch2_ioc_getversion(struct bch_inode_info *inode, u32 __user *arg)
+{
+       return put_user(inode->v.i_generation, arg);
+}
+
 static int bch2_ioc_goingdown(struct bch_fs *c, u32 __user *arg)
 {
        u32 flags;
@@ -499,7 +504,7 @@ long bch2_fs_file_ioctl(struct file *file, unsigned cmd, unsigned long arg)
                break;
 
        case FS_IOC_GETVERSION:
-               ret = -ENOTTY;
+               ret = bch2_ioc_getversion(inode, (u32 __user *) arg);
                break;
 
        case FS_IOC_SETVERSION:
@@ -547,6 +552,9 @@ long bch2_compat_fs_ioctl(struct file *file, unsigned cmd, unsigned long arg)
        case FS_IOC32_SETFLAGS:
                cmd = FS_IOC_SETFLAGS;
                break;
+       case FS_IOC32_GETVERSION:
+               cmd = FS_IOC_GETVERSION;
+               break;
        default:
                return -ENOIOCTLCMD;
        }