1 ext4: add a new ioctl EXT4_IOC_GETSTATE
3 The new ioctl EXT4_IOC_GETSTATE returns some of the dynamic state of
4 an ext4 inode for debugging purposes.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 fs/ext4/ext4.h | 11 +++++++++++
9 fs/ext4/ioctl.c | 17 +++++++++++++++++
10 2 files changed, 28 insertions(+)
12 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
13 index b22f24f1d365..ee296797bcd2 100644
16 @@ -651,6 +651,7 @@ enum {
17 #define EXT4_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
18 /* ioctl codes 19--39 are reserved for fscrypt */
19 #define EXT4_IOC_CLEAR_ES_CACHE _IO('f', 40)
20 +#define EXT4_IOC_GETSTATE _IOW('f', 41, __u32)
22 #define EXT4_IOC_FSGETXATTR FS_IOC_FSGETXATTR
23 #define EXT4_IOC_FSSETXATTR FS_IOC_FSSETXATTR
24 @@ -664,6 +665,16 @@ enum {
25 #define EXT4_GOING_FLAGS_LOGFLUSH 0x1 /* flush log but not data */
26 #define EXT4_GOING_FLAGS_NOLOGFLUSH 0x2 /* don't flush log nor data */
29 + * Flags returned by EXT4_IOC_GETSTATE
31 + * We only expose to userspace a subset of the state flags in
34 +#define EXT4_STATE_FLAG_EXT_PRECACHED 0x00000001
35 +#define EXT4_STATE_FLAG_NEW 0x00000002
36 +#define EXT4_STATE_FLAG_NEWENTRY 0x00000004
37 +#define EXT4_STATE_FLAG_DA_ALLOC_CLOSE 0x00000008
39 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
41 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
42 index 15b1047878ab..ffb7bde4900d 100644
45 @@ -1123,6 +1123,22 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
49 + case EXT4_IOC_GETSTATE:
53 + if (ext4_test_inode_state(inode, EXT4_STATE_EXT_PRECACHED))
54 + state |= EXT4_STATE_FLAG_EXT_PRECACHED;
55 + if (ext4_test_inode_state(inode, EXT4_STATE_NEW))
56 + state |= EXT4_STATE_FLAG_NEW;
57 + if (ext4_test_inode_state(inode, EXT4_STATE_NEWENTRY))
58 + state |= EXT4_STATE_FLAG_NEWENTRY;
59 + if (ext4_test_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE))
60 + state |= EXT4_STATE_FLAG_DA_ALLOC_CLOSE;
62 + return put_user(state, (__u32 __user *) arg);
65 case EXT4_IOC_FSGETXATTR:
68 @@ -1242,6 +1258,7 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
69 case EXT4_IOC_SHUTDOWN:
71 case EXT4_IOC_CLEAR_ES_CACHE:
72 + case EXT4_IOC_GETSTATE: