All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: dhowells@redhat.com, linux-api@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] statx: Ext4: Return enhanced file attributes [ver #3]
Date: Wed, 23 Nov 2016 00:55:59 +0000	[thread overview]
Message-ID: <147986255921.19139.6012507332848890196.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <147986254484.19139.8038609825799670925.stgit@warthog.procyon.org.uk>

Return enhanced file attributes from the Ext4 filesystem.  This includes
the following:

 (1) The inode creation time (i_crtime) as stx_btime, setting STATX_BTIME.

 (2) Certain FS_xxx_FL flags are mapped to stx_attribute flags.

This requires that all ext4 inodes have a getattr call, not just some of
them, so to this end, split the ext4_getattr() function and only call part
of it where appropriate.

Example output:

	[root@andromeda ~]# touch foo
	[root@andromeda ~]# chattr +ai foo
	[root@andromeda ~]# /tmp/test-statx foo
	statx(foo) = 0
	results=fff
	  Size: 0               Blocks: 0          IO Block: 4096    regular file
	Device: 08:12           Inode: 2101950     Links: 1
	Access: (0644/-rw-r--r--)  Uid:     0   Gid:     0
	Access: 2016-02-11 17:08:29.031795451+0000
	Modify: 2016-02-11 17:08:29.031795451+0000
	Change: 2016-02-11 17:11:11.987790114+0000
	 Birth: 2016-02-11 17:08:29.031795451+0000
	Attributes: 0000000000000030 (-------- -------- -------- -------- -------- -------- -------- --ai----)
	IO-blocksize: blksize=4096

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/ext4/ext4.h    |    2 ++
 fs/ext4/file.c    |    2 +-
 fs/ext4/inode.c   |   36 +++++++++++++++++++++++++++++++++---
 fs/ext4/namei.c   |    2 ++
 fs/ext4/symlink.c |    2 ++
 5 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 282a51b07c57..f65e4a560c4c 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2485,6 +2485,8 @@ extern int  ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
 				struct kstat *stat);
 extern void ext4_evict_inode(struct inode *);
 extern void ext4_clear_inode(struct inode *);
+extern int  ext4_file_getattr(struct vfsmount *mnt, struct dentry *dentry,
+			      struct kstat *stat);
 extern int  ext4_sync_inode(handle_t *, struct inode *);
 extern void ext4_dirty_inode(struct inode *, int);
 extern int ext4_change_inode_journal_flag(struct inode *, int);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 2a822d30e73f..20bab4b0d6fc 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -705,7 +705,7 @@ const struct file_operations ext4_file_operations = {
 
 const struct inode_operations ext4_file_inode_operations = {
 	.setattr	= ext4_setattr,
-	.getattr	= ext4_getattr,
+	.getattr	= ext4_file_getattr,
 	.listxattr	= ext4_listxattr,
 	.get_acl	= ext4_get_acl,
 	.set_acl	= ext4_set_acl,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9c064727ed62..fd7d5f918cc3 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5229,11 +5229,41 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
 		 struct kstat *stat)
 {
-	struct inode *inode;
-	unsigned long long delalloc_blocks;
+	struct inode *inode = d_inode(dentry);
+	struct ext4_inode *raw_inode;
+	struct ext4_inode_info *ei = EXT4_I(inode);
+	unsigned int flags;
+
+	if (EXT4_FITS_IN_INODE(raw_inode, ei, i_crtime)) {
+		stat->result_mask |= STATX_BTIME;
+		stat->btime.tv_sec = ei->i_crtime.tv_sec;
+		stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
+	}
+
+	ext4_get_inode_flags(ei);
+	flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
+	if (flags & EXT4_APPEND_FL)
+		stat->attributes |= STATX_ATTR_APPEND;
+	if (flags & EXT4_COMPR_FL)
+		stat->attributes |= STATX_ATTR_COMPRESSED;
+	if (flags & EXT4_ENCRYPT_FL)
+		stat->attributes |= STATX_ATTR_ENCRYPTED;
+	if (flags & EXT4_IMMUTABLE_FL)
+		stat->attributes |= STATX_ATTR_IMMUTABLE;
+	if (flags & EXT4_NODUMP_FL)
+		stat->attributes |= STATX_ATTR_NODUMP;
 
-	inode = d_inode(dentry);
 	generic_fillattr(inode, stat);
+	return 0;
+}
+
+int ext4_file_getattr(struct vfsmount *mnt, struct dentry *dentry,
+		      struct kstat *stat)
+{
+	struct inode *inode = dentry->d_inode;
+	u64 delalloc_blocks;
+
+	ext4_getattr(mnt, dentry, stat);
 
 	/*
 	 * If there is inline data in the inode, the inode will normally not
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 104f8bfba718..e115281fb8c5 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3882,6 +3882,7 @@ const struct inode_operations ext4_dir_inode_operations = {
 	.tmpfile	= ext4_tmpfile,
 	.rename		= ext4_rename2,
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.listxattr	= ext4_listxattr,
 	.get_acl	= ext4_get_acl,
 	.set_acl	= ext4_set_acl,
@@ -3890,6 +3891,7 @@ const struct inode_operations ext4_dir_inode_operations = {
 
 const struct inode_operations ext4_special_inode_operations = {
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.listxattr	= ext4_listxattr,
 	.get_acl	= ext4_get_acl,
 	.set_acl	= ext4_set_acl,
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index 557b3b0d668c..209b833633e2 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -93,6 +93,7 @@ const struct inode_operations ext4_symlink_inode_operations = {
 	.readlink	= generic_readlink,
 	.get_link	= page_get_link,
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.listxattr	= ext4_listxattr,
 };
 
@@ -100,5 +101,6 @@ const struct inode_operations ext4_fast_symlink_inode_operations = {
 	.readlink	= generic_readlink,
 	.get_link	= simple_get_link,
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.listxattr	= ext4_listxattr,
 };

  parent reply	other threads:[~2016-11-23  0:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-23  0:55 [RFC][PATCH 0/4] Enhanced file stat system call " David Howells
2016-11-23  0:55 ` [PATCH 1/4] statx: Add a system call to make enhanced file info available " David Howells
2016-11-23  8:37   ` Michael Kerrisk (man-pages)
2016-11-23 22:42     ` Andreas Dilger
     [not found]     ` <768343b5-e9b4-a86c-53de-2929bc290342-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-11-23 22:42       ` Andreas Dilger
2016-11-23 22:57       ` Andreas Dilger
2016-11-24  8:13         ` Michael Kerrisk (man-pages)
     [not found]         ` <19284F6D-73B9-4A1A-8227-2B2B87F29FE9-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org>
2016-11-24  8:13           ` Michael Kerrisk (man-pages)
2016-11-23 22:57     ` Andreas Dilger
     [not found]   ` <147986255194.19139.9583434946564699577.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2016-11-24  2:08     ` Andreas Dilger
2016-11-24  2:08   ` Andreas Dilger
2016-11-24  7:27   ` David Howells
     [not found]   ` <D1A5E76A-5739-42FE-A451-B49CD1699DB0-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org>
2016-11-24  7:27     ` David Howells
2016-12-04  4:00   ` Al Viro
2016-12-04  4:38   ` Al Viro
2016-12-04 16:05     ` Al Viro
2016-12-04 17:33     ` Al Viro
     [not found]     ` <20161204043803.GA1022-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2016-12-04 17:33       ` Al Viro
2016-12-05 14:49         ` Miklos Szeredi
     [not found]         ` <20161204173317.GH1555-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2016-12-05 14:49           ` Miklos Szeredi
     [not found]     ` <20161204160504.GG1555-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2016-12-05 15:37       ` David Howells
2016-12-05 15:37     ` David Howells
2016-11-23  0:55 ` David Howells [this message]
     [not found]   ` <147986255921.19139.6012507332848890196.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2016-11-23 17:59     ` [PATCH 2/4] statx: Ext4: Return enhanced file attributes " Andreas Dilger
2016-11-23 17:59   ` Andreas Dilger
2016-11-23  0:56 ` [PATCH 3/4] statx: NFS: " David Howells
2016-11-23  0:56 ` [PATCH 4/4] statx: AFS: " David Howells
     [not found] ` <147986254484.19139.8038609825799670925.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2016-11-23  0:56   ` David Howells
2016-11-24  2:06     ` Andreas Dilger
     [not found]     ` <147986257312.19139.10417237189956494459.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2016-11-24  2:06       ` Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=147986255921.19139.6012507332848890196.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 2/4] statx: Ext4: Return enhanced file attributes [ver #3]' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.