[PATCH RFC] Support for btime (creation time) for tmpfs/shmem ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am wondering if including support for creation time for tmpfs would
be something sensible ?

The attached patch tentatively adds support for a creation time in
mm/shmem.c, but the patch is probably incomplete or broken, because
while files do appear to behave correctly in tmpfs (birth time is
correctly set, and unmodified when the file is touched), directories
do not appear to bear any metadata (I am missing an obvious other
codepath than shmem_getattr).

Any comment (or rebuttal) welcome.

Note: the birth time can be checked with the now standard statx call:

#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char** argv)
{
    if (argc == 1) {
        fprintf(stderr, "Usage: %s [file...]\n", argv[0]);
    }
    int i;
    for (i = 1; i < argc; i++) {
        struct statx st;
        if (statx(AT_FDCWD, argv[i], 0, STATX_ALL, &st) == 0) {
            fprintf(stderr,
                    "file='%s',\tmtime == %ld,\tbtime == %ld\n",
                    argv[i],
                    (long)st.stx_mtime.tv_sec,
                    (long)st.stx_btime.tv_sec);
        } else {
            perror("statx");
        }
    }

    return EXIT_SUCCESS;
}


-- 
Xavier Roche
From cbcfc268694eaf8493cb7a43c40cb933b4bf1aa2 Mon Sep 17 00:00:00 2001
From: Xavier Roche <xavier.roche@xxxxxxxxxxx>
Date: Thu, 3 Feb 2022 16:04:02 +0100
Subject: [PATCH] mm: support for file creation time

---
 include/linux/shmem_fs.h | 1 +
 mm/shmem.c               | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
index e65b80ed09e7..29787767c3b9 100644
--- a/include/linux/shmem_fs.h
+++ b/include/linux/shmem_fs.h
@@ -25,6 +25,7 @@ struct shmem_inode_info {
 	struct simple_xattrs	xattrs;		/* list of xattrs */
 	atomic_t		stop_eviction;	/* hold when working on inode */
 	struct inode		vfs_inode;
+	struct timespec64	i_crtime;	/* file creation time */
 };
 
 struct shmem_sb_info {
diff --git a/mm/shmem.c b/mm/shmem.c
index a09b29ec2b45..471e8b6e91f1 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1061,6 +1061,12 @@ static int shmem_getattr(struct user_namespace *mnt_userns,
 	if (shmem_is_huge(NULL, inode, 0))
 		stat->blksize = HPAGE_PMD_SIZE;
 
+	if ((request_mask & STATX_BTIME)) {
+		stat->result_mask |= STATX_BTIME;
+		stat->btime.tv_sec = info->i_crtime.tv_sec;
+		stat->btime.tv_nsec = info->i_crtime.tv_nsec;
+	}
+
 	return 0;
 }
 
@@ -2265,6 +2271,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
 		atomic_set(&info->stop_eviction, 0);
 		info->seals = F_SEAL_SEAL;
 		info->flags = flags & VM_NORESERVE;
+		info->i_crtime = inode->i_mtime;
 		INIT_LIST_HEAD(&info->shrinklist);
 		INIT_LIST_HEAD(&info->swaplist);
 		simple_xattrs_init(&info->xattrs);
-- 
2.25.1


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux