bcachefs: Report inode counts via statfs
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 3 Nov 2020 00:49:23 +0000 (19:49 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:46 +0000 (17:08 -0400)
Took awhile to figure out exactly what statfs wanted...

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c

index 2ed80ef41d1a0b9d19f39a17dbd57150200434dd..917a08ddc14884c97aa027a0cbde177cc0730f4f 100644 (file)
@@ -1261,6 +1261,11 @@ static int bch2_statfs(struct dentry *dentry, struct kstatfs *buf)
        struct bch_fs *c = sb->s_fs_info;
        struct bch_fs_usage_short usage = bch2_fs_usage_read_short(c);
        unsigned shift = sb->s_blocksize_bits - 9;
+       /*
+        * this assumes inodes take up 64 bytes, which is a decent average
+        * number:
+        */
+       u64 avail_inodes = ((usage.capacity - usage.used) << 3);
        u64 fsid;
 
        buf->f_type     = BCACHEFS_STATFS_MAGIC;
@@ -1268,8 +1273,9 @@ static int bch2_statfs(struct dentry *dentry, struct kstatfs *buf)
        buf->f_blocks   = usage.capacity >> shift;
        buf->f_bfree    = (usage.capacity - usage.used) >> shift;
        buf->f_bavail   = buf->f_bfree;
-       buf->f_files    = 0;
-       buf->f_ffree    = 0;
+
+       buf->f_files    = usage.nr_inodes + avail_inodes;
+       buf->f_ffree    = avail_inodes;
 
        fsid = le64_to_cpup((void *) c->sb.user_uuid.b) ^
               le64_to_cpup((void *) c->sb.user_uuid.b + sizeof(u64));