Allow setting file birth time with utimensat()
Subsystems (7)
cover Allow setting file birth time with utimensat()
From: Omar Sandoval <[email protected]>
Hi,
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support to utimensat() with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.
Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]
I've also included a man page patch, xfs_io support, and an xfstest.
Thoughts on the implementation or the interface?
Thanks!
1: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setattrlist.2.html
2: https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfiletime
Omar Sandoval (6):
fs: add btime to struct iattr
fs: add AT_UTIME_BTIME for utimensat()
Btrfs: add support for setting btime
ext4: add support for setting btime
f2fs: add support for setting btime
xfs: add support for setting btime
fs/attr.c | 6 +++ fs/btrfs/inode.c | 2 + fs/btrfs/super.c | 4 +- fs/ext4/inode.c | 15 +++++- fs/ext4/super.c | 2 +- fs/f2fs/file.c | 19 ++++++-- fs/f2fs/super.c | 2 +- fs/utimes.c | 86 +++++++++++++++++++++------------- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/libxfs/xfs_log_format.h | 2 +- fs/xfs/xfs_iops.c | 11 ++++- fs/xfs/xfs_super.c | 2 +- include/linux/fs.h | 4 ++ include/uapi/linux/fcntl.h | 2 + 14 files changed, 111 insertions(+), 48 deletions(-)
Signature · 1 line
2.20.1
RFC PATCH 1/6 fs: add btime to struct iattr
From: Omar Sandoval <[email protected]>
Add btime as an attribute that can be updated through notify_change() if the filesystem supports it, which is indicated by FS_HAS_BTIME in file_system_type->fs_flags.
--- fs/attr.c | 6 ++++++ include/linux/fs.h | 4 ++++ 2 files changed, 10 insertions(+)
fs/attr.c +6 -0
@@ -233,6 +233,10 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **deWARN_ON_ONCE (!inode_is_locked (inode)); +if ((ia_valid &ATTR_BTIME ) && + !(inode->i_sb->s_type->fs_flags &FS_HAS_BTIME )) +return -EOPNOTSUPP ; +if (ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID |ATTR_TIMES_SET )) {if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;
@@ -267,6 +271,8 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de attr->ia_atime = now;if (!(ia_valid &ATTR_MTIME_SET )) attr->ia_mtime = now; +if (!(ia_valid &ATTR_BTIME_SET )) + attr->ia_btime = now;if (ia_valid &ATTR_KILL_PRIV ) { error =security_inode_need_killpriv (dentry);if (error <0 )
include/linux/fs.h +4 -0
@@ -191,6 +191,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,#define ATTR_OPEN (1 << 15)/* Truncating from open(O_TRUNC) */ #define ATTR_TIMES_SET (1 << 16)#define ATTR_TOUCH (1 << 17) +#define ATTR_BTIME (1 << 18) +#define ATTR_BTIME_SET (1 << 19)/* * Whiteout is represented by a char device. The following constants define the
@@ -217,6 +219,7 @@ struct iattr {struct timespec64 ia_atime;struct timespec64 ia_mtime;struct timespec64 ia_ctime; +struct timespec64 ia_btime;/* * Not an attribute, but an auxiliary info for filesystems wanting to
@@ -2172,6 +2175,7 @@ struct file_system_type {#define FS_BINARY_MOUNTDATA 2#define FS_HAS_SUBTYPE 4#define FS_USERNS_MOUNT 8/* Can be mounted by userns root */ +#define FS_HAS_BTIME 16/* Supports getting/setting btime. */ #define FS_RENAME_DOES_D_MOVE 32768/* FS will handle d_move() during rename() internally. */ struct dentry *(*mount) (struct file_system_type *,int ,const char *,void *);
Signature · 1 line
2.20.1
RFC PATCH 2/6 fs: add AT_UTIME_BTIME for utimensat()
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
Now that we have a btime iattr, use it to allow updating btime from utimensat(). We do so by adding a new AT_UTIME_BTIME flag. Iff this flag is given, the btime is set to times[2] (unless times is NULL, in which case the current time is used).
--- fs/utimes.c | 86 +++++++++++++++++++++++--------------- include/uapi/linux/fcntl.h | 2 + 2 files changed, 55 insertions(+), 33 deletions(-)
fs/utimes.c +53 -33
@@ -16,7 +16,20 @@ static bool nsec_valid(long nsec)return nsec >=0 && nsec <=999999999 ; } -static int utimes_common (const struct path *path,struct timespec64 *times) +static void init_time_attr (struct iattr *newattrs,struct timespec64 *time_attr, +struct timespec64 time,unsigned int attr, +unsigned int attr_set) +{ +if (time.tv_nsec ==UTIME_OMIT ) { + newattrs->ia_valid &= ~attr; + }else { + *time_attr = time; + newattrs->ia_valid |= attr_set; + } +} + +static int utimes_common (const struct path *path,struct timespec64 *times, +bool btime) {int error;struct iattr newattrs;
@@ -28,25 +41,21 @@ static int utimes_common(const struct path *path, struct timespec64 *times) goto out;if (times && times[0 ].tv_nsec ==UTIME_NOW && - times[1 ].tv_nsec ==UTIME_NOW ) + times[1 ].tv_nsec ==UTIME_NOW && + (!btime || times[2 ].tv_nsec ==UTIME_NOW )) times =NULL ; newattrs.ia_valid =ATTR_CTIME |ATTR_MTIME |ATTR_ATIME ; +if (btime) + newattrs.ia_valid |=ATTR_BTIME ;if (times) { -if (times[0 ].tv_nsec ==UTIME_OMIT ) - newattrs.ia_valid &= ~ATTR_ATIME ; -else if (times[0 ].tv_nsec !=UTIME_NOW ) { - newattrs.ia_atime.tv_sec = times[0 ].tv_sec; - newattrs.ia_atime.tv_nsec = times[0 ].tv_nsec; - newattrs.ia_valid |=ATTR_ATIME_SET ; - } - -if (times[1 ].tv_nsec ==UTIME_OMIT ) - newattrs.ia_valid &= ~ATTR_MTIME ; -else if (times[1 ].tv_nsec !=UTIME_NOW ) { - newattrs.ia_mtime.tv_sec = times[1 ].tv_sec; - newattrs.ia_mtime.tv_nsec = times[1 ].tv_nsec; - newattrs.ia_valid |=ATTR_MTIME_SET ; +init_time_attr (&newattrs, &newattrs.ia_atime, times[0 ], +ATTR_ATIME ,ATTR_ATIME_SET ); +init_time_attr (&newattrs, &newattrs.ia_mtime, times[1 ], +ATTR_MTIME ,ATTR_MTIME_SET ); +if (btime) { +init_time_attr (&newattrs, &newattrs.ia_btime, times[2 ], +ATTR_BTIME ,ATTR_BTIME_SET ); }/* * Tell setattr_prepare(), that this is an explicit time
@@ -90,14 +99,16 @@ static int utimes_common(const struct path *path, struct timespec64 *times)long do_utimes (int dfd,const char __user *filename,struct timespec64 *times,int flags) { +bool btime = flags &AT_UTIME_BTIME ;int error = -EINVAL ;if (times && (!nsec_valid (times[0 ].tv_nsec) || - !nsec_valid (times[1 ].tv_nsec))) { + !nsec_valid (times[1 ].tv_nsec) || + (btime && !nsec_valid (times[2 ].tv_nsec)))) { goto out; } -if (flags & ~AT_SYMLINK_NOFOLLOW ) +if (flags & ~(AT_SYMLINK_NOFOLLOW |AT_UTIME_BTIME )) goto out;if (filename ==NULL && dfd !=AT_FDCWD ) {
@@ -111,7 +122,7 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times,if (!f.file) goto out; - error =utimes_common (&f.file->f_path, times); + error =utimes_common (&f.file->f_path, times, btime);fdput (f); }else {struct path path;
@@ -124,7 +135,7 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times,if (error) goto out; - error =utimes_common (&path, times); + error =utimes_common (&path, times, btime);path_put (&path);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ;
@@ -139,16 +150,20 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename, struct __kernel_timespec __user *, utimes, int, flags) { -struct timespec64 tstimes[2 ]; +struct timespec64 tstimes[3 ];if (utimes) { -if ((get_timespec64 (&tstimes[0 ], &utimes[0 ]) || -get_timespec64 (&tstimes[1 ], &utimes[1 ]))) -return -EFAULT ; - +int i, n = (flags &AT_UTIME_BTIME ) ?3 :2 ; +bool all_omit = true; + +for (i =0 ; i < n; i++) { +if (get_timespec64 (&tstimes[i], &utimes[i])) +return -EFAULT ; +if (tstimes[i].tv_nsec !=UTIME_OMIT ) + all_omit = false; + }/* Nothing to do, we must not even check the path. */ -if (tstimes[0 ].tv_nsec ==UTIME_OMIT && - tstimes[1 ].tv_nsec ==UTIME_OMIT ) +if (all_omit)return 0 ; }
@@ -242,14 +257,19 @@ COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct old_timespec32 __user *, t, int, flags) { -struct timespec64 tv[2 ]; +struct timespec64 tv[3 ];if (t) { -if (get_old_timespec32 (&tv[0 ], &t[0 ]) || -get_old_timespec32 (&tv[1 ], &t[1 ])) -return -EFAULT ; - -if (tv[0 ].tv_nsec ==UTIME_OMIT && tv[1 ].tv_nsec ==UTIME_OMIT ) +int i, n = (flags &AT_UTIME_BTIME ) ?3 :2 ; +bool all_omit = true; + +for (i =0 ; i < n; i++) { +if (get_old_timespec32 (&tv[i], &t[i])) +return -EFAULT ; +if (tv[i].tv_nsec !=UTIME_OMIT ) + all_omit = false; + } +if (all_omit)return 0 ; }return do_utimes (dfd, filename, t ? tv :NULL , flags);
include/uapi/linux/fcntl.h +2 -0
@@ -90,5 +90,7 @@#define AT_STATX_FORCE_SYNC 0x2000/* - Force the attributes to be sync'd with the server */ #define AT_STATX_DONT_SYNC 0x4000/* - Don't sync attributes with the server */ +#define AT_UTIME_BTIME 0x8000/* Also update file creation time */ +#endif /* _UAPI_LINUX_FCNTL_H */
Signature · 1 line
2.20.1
RFC PATCH 3/6 Btrfs: add support for setting btime
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
The Btrfs inode format has always included btime (under the name otime), so setting it is trivial.
--- fs/btrfs/inode.c | 2 ++ fs/btrfs/super.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +2 -0
@@ -5153,6 +5153,8 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)if (attr->ia_valid) {setattr_copy (inode, attr); +if (attr->ia_valid &ATTR_BTIME ) +BTRFS_I (inode)->i_otime = attr->ia_btime;inode_inc_iversion (inode); err =btrfs_dirty_inode (inode);
fs/btrfs/super.c +2 -2
@@ -2140,7 +2140,7 @@ static struct file_system_type btrfs_fs_type = { .name = "btrfs", .mount = btrfs_mount, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_HAS_BTIME, };static struct file_system_type btrfs_root_fs_type = {
@@ -2148,7 +2148,7 @@ static struct file_system_type btrfs_root_fs_type = { .name = "btrfs", .mount = btrfs_mount_root, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_HAS_BTIME, };MODULE_ALIAS_FS ("btrfs" );
Signature · 1 line
2.20.1
RFC PATCH 4/6 ext4: add support for setting btime
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
The ext4 inode format includes btime (under the name crtime) if the inode is large enough (256 bytes).
--- fs/ext4/inode.c | 15 +++++++++++++-- fs/ext4/super.c | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-)
fs/ext4/inode.c +13 -2
@@ -5489,6 +5489,13 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode) } } +static bool ext4_inode_has_crtime (struct inode *inode) +{ +struct ext4_inode *raw_inode; + +return EXT4_FITS_IN_INODE (raw_inode,EXT4_I (inode), i_crtime); +} +/* * ext4_setattr() *
@@ -5520,6 +5527,9 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)int orphan =0 ;const unsigned int ia_valid = attr->ia_valid; +if ((ia_valid &ATTR_BTIME ) && !ext4_inode_has_crtime (inode)) +return -EOPNOTSUPP ; +if (unlikely (ext4_forced_shutdown (EXT4_SB (inode->i_sb))))return -EIO ;
@@ -5671,6 +5681,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)if (!error) {setattr_copy (inode, attr); +if (ia_valid &ATTR_BTIME ) +EXT4_I (inode)->i_crtime = attr->ia_btime;mark_inode_dirty (inode); }
@@ -5695,11 +5707,10 @@ int ext4_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int query_flags) { struct inode *inode = d_inode(path->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)) { +if (ext4_inode_has_crtime (inode)) { stat->result_mask |=STATX_BTIME ; stat->btime.tv_sec = ei->i_crtime.tv_sec; stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
fs/ext4/super.c +1 -1
@@ -5976,7 +5976,7 @@ static struct file_system_type ext4_fs_type = { .name = "ext4", .mount = ext4_mount, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_HAS_BTIME, };MODULE_ALIAS_FS ("ext4" );
Signature · 1 line
2.20.1
RFC PATCH 5/6 f2fs: add support for setting btime
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
The f2fs inode format includes btime (under the name crtime) if the feature was enabled at mkfs time.
--- fs/f2fs/file.c | 19 +++++++++++++++---- fs/f2fs/super.c | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/file.c +15 -4
@@ -690,17 +690,23 @@ int f2fs_truncate(struct inode *inode)return 0 ; } +static bool f2fs_inode_has_crtime (struct inode *inode) +{ +struct f2fs_inode *ri; + +return (f2fs_has_extra_attr (inode) && +f2fs_sb_has_inode_crtime (F2FS_I_SB (inode)) && +F2FS_FITS_IN_INODE (ri,F2FS_I (inode)->i_extra_isize, i_crtime)); +} +int f2fs_getattr (const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);struct f2fs_inode_info *fi =F2FS_I (inode); -struct f2fs_inode *ri;unsigned int flags; -if (f2fs_has_extra_attr (inode) && -f2fs_sb_has_inode_crtime (F2FS_I_SB (inode)) && -F2FS_FITS_IN_INODE (ri, fi->i_extra_isize, i_crtime)) { +if (f2fs_inode_has_crtime (inode)) { stat->result_mask |=STATX_BTIME ; stat->btime.tv_sec = fi->i_crtime.tv_sec; stat->btime.tv_nsec = fi->i_crtime.tv_nsec;
@@ -770,6 +776,9 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)int err;bool size_changed = false; +if ((attr->ia_valid &ATTR_BTIME ) && !f2fs_inode_has_crtime (inode)) +return -EOPNOTSUPP ; +if (unlikely (f2fs_cp_error (F2FS_I_SB (inode))))return -EIO ;
@@ -848,6 +857,8 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) }__setattr_copy (inode, attr); +if (attr->ia_valid &ATTR_BTIME ) +F2FS_I (inode)->i_crtime = attr->ia_btime;if (attr->ia_valid &ATTR_MODE ) { err =posix_acl_chmod (inode,f2fs_get_inode_mode (inode));
fs/f2fs/super.c +1 -1
@@ -3485,7 +3485,7 @@ static struct file_system_type f2fs_fs_type = { .name = "f2fs", .mount = f2fs_mount, .kill_sb = kill_f2fs_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_HAS_BTIME, };MODULE_ALIAS_FS ("f2fs" );
Signature · 1 line
2.20.1
RFC PATCH 6/6 xfs: add support for setting btime
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
The XFS inode format includes btime (under the name crtime) in inode version 3. Also update the comments in libxfs to reflect that di_crtime can now change.
--- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/libxfs/xfs_log_format.h | 2 +- fs/xfs/xfs_iops.c | 11 +++++++++-- fs/xfs/xfs_super.c | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_format.h +1 -1
@@ -884,9 +884,9 @@ typedef struct xfs_dinode {__be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ __u8 di_pad2[12 ];/* more padding for future expansion */ +xfs_timestamp_t di_crtime;/* time created */ /* fields only written to during inode creation */ -xfs_timestamp_t di_crtime;/* time created */ __be64 di_ino;/* inode number */ uuid_t di_uuid;/* UUID of the filesystem */
fs/xfs/libxfs/xfs_log_format.h +1 -1
@@ -415,9 +415,9 @@ struct xfs_log_dinode {uint64_t di_flags2;/* more random flags */ uint32_t di_cowextsize;/* basic cow extent size for file */ uint8_t di_pad2[12 ];/* more padding for future expansion */ +xfs_ictimestamp_t di_crtime;/* time created */ /* fields only written to during inode creation */ -xfs_ictimestamp_t di_crtime;/* time created */ xfs_ino_t di_ino;/* inode number */ uuid_t di_uuid;/* UUID of the filesystem */
fs/xfs/xfs_iops.c +9 -2
@@ -582,6 +582,10 @@ xfs_setattr_time( inode->i_ctime = iattr->ia_ctime;if (iattr->ia_valid &ATTR_MTIME ) inode->i_mtime = iattr->ia_mtime; +if (iattr->ia_valid &ATTR_BTIME ) { + ip->i_d.di_crtime.t_sec = iattr->ia_btime.tv_sec; + ip->i_d.di_crtime.t_nsec = iattr->ia_btime.tv_nsec; + } } static int
@@ -1025,11 +1029,14 @@ xfs_vn_setattr(struct dentry *dentry, struct iattr *iattr) { + struct inode *inode = d_inode(dentry); +struct xfs_inode *ip =XFS_I (inode);int error; +if ((iattr->ia_valid &ATTR_BTIME ) && ip->i_d.di_version !=3 ) +return -EOPNOTSUPP ; +if (iattr->ia_valid &ATTR_SIZE ) { -struct inode *inode =d_inode (dentry); -struct xfs_inode *ip =XFS_I (inode);uint iolock;xfs_ilock (ip,XFS_MMAPLOCK_EXCL );
fs/xfs/xfs_super.c +1 -1
@@ -1860,7 +1860,7 @@ static struct file_system_type xfs_fs_type = { .name = "xfs", .mount = xfs_fs_mount, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_HAS_BTIME, };MODULE_ALIAS_FS ("xfs" );
Signature · 1 line
2.20.1
PATCH 1/1 generic: add a test for AT_UTIME_BTIME
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
Test that on filesystems supporting btime, the timestamp is updated as expected.
--- common/rc | 14 ++++++++++ tests/generic/526 | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/526.out | 14 ++++++++++ tests/generic/group | 1 + 4 files changed, 93 insertions(+) create mode 100755 tests/generic/526 create mode 100644 tests/generic/526.out
common/rc +14 -0
@@ -3843,6 +3843,20 @@ _require_btime() rm -f $TEST_DIR/test_creation_time } +_require_utime_btime() +{ + _require_btime + _require_xfs_io_command utimes + testio=`$XFS_IO_PROG -f -c "utimes 0 0 0 0 0 0" "$TEST_DIR/$$.xfs_io" 2>&1` + echo $testio | grep -q "expected 4 arguments" && \ + _notrun "xfs_io utimes btime support is missing" + echo $testio | grep -q "Operation not supported" && \ + _notrun "updating inode creation time not supported by this filesystem" + echo $testio | grep -q "Invalid" && \ + _notrun "updating inode creation time not supported by this kernel" + rm -f $testfile > /dev/null 2>&1 +} + _require_scratch_btime() { _require_scratch
tests/generic/526 new file +64 -0
64 lines not on this page · raw message
tests/generic/526.out new file +14 -0
@@ -0,0 +1,14 @@ +QA output created by 526 +Set btime +stat.btime.tv_sec = 683153828 +stat.btime.tv_nsec = 0 +Set atime and mtime +stat.btime.tv_sec = 683153828 +stat.btime.tv_nsec = 0 +Omit btime +stat.btime.tv_sec = 683153828 +stat.btime.tv_nsec = 0 +Cycle mount +stat.btime.tv_sec = 683153828 +stat.btime.tv_nsec = 0 +Set btime to now
tests/generic/group +1 -0
@@ -528,3 +528,4 @@ 523 auto quick attr 524 auto quick 525 auto quick rw +526 auto quick
Signature · 1 line
2.20.1
PATCH 1/1 utimensat2: document AT_UTIME_BTIME
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
--- man2/utimensat.2 | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
man2/utimensat.2 +37 -1
@@ -211,7 +211,7 @@ is ignored. .PP The .I flags -field is a bit mask that may be 0, or include the following constant, +field is a bit mask that may be 0, or include the following constants, defined in .IR <fcntl.h> : .TP
@@ -220,6 +220,36 @@ If .I pathname specifies a symbolic link, then update the timestamps of the link, rather than the file to which it refers. +.TP +.B AT_UTIME_BTIME +Also update the file's "creation time" (\fIbtime\fP). If +.I times +is not NULL, then its length must be at least 3, and +.IR times [2] +specifies the new creation time. The +.I tv_nsec +field may be +.BR UTIME_NOW +or +.BR UTIME_OMIT ; +this has the same meaning as for the first two timestamps. +If +.I times +is NULL, then the creation time is set to the current time. +.IP +Not all filesystems store the file creation time; if a filesystem does not, an +error is returned. At least the following filesystems store the creation time: +.RS +.IP * 3 +Btrfs +.IP * +ext4, if the filesystem was created with an inode size of at least 256 +.IP * +F2FS, if the filesystem was created with the inode_crtime feature +.IP * +XFS, if the filesystem was created with the v5 format (i.e., with CRCs enabled) +.HP +Support for this flag was added in Linux 5.2. .SH RETURN VALUE On success, .BR utimensat ()
@@ -359,6 +389,12 @@ or, one of the prefix components of .I pathname is not a directory. .TP +.B EOPNOTSUPP +.I flags +contains +.BR AT_UTIME_BTIME +but the filesystem does not store the file creation time. +.TP .B EPERM The caller attempted to change one or both timestamps to a value other than the current time,
Signature · 1 line
2.20.1
PATCH 1/1 xfs_io: add AT_UTIME_BTIME support
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
In order to test updating btime, make the utimes command optionally take the btime timestamp.
--- io/utimes.c | 41 +++++++++++++++++++++++++++++++---------- man/man8/xfs_io.8 | 5 +++-- 2 files changed, 34 insertions(+), 12 deletions(-)
io/utimes.c +31 -10
@@ -4,11 +4,18 @@* All Rights Reserved. */ +#include <fcntl.h> +#include <sys/syscall.h> +#include "command.h" #include "input.h" #include "init.h" #include "io.h" +#ifndef AT_UTIME_BTIME +#define AT_UTIME_BTIME 0x8000 +#endif +static cmdinfo_t utimes_cmd; static void
@@ -16,9 +23,10 @@ utimes_help(void) {printf (_ ("\n" -" Update file atime and mtime of the current file with nansecond precision.\n" +" Update file atime, mtime, and optionally btime of the current file with\n" +" nansecond precision.\n" "\n" -" Usage: utimes atime_sec atime_nsec mtime_sec mtime_nsec.\n" +" Usage: utimes atime_sec atime_nsec mtime_sec mtime_nsec [btime_sec btime_nsec]\n" " *_sec: Seconds elapsed since 1970-01-01 00:00:00 UTC.\n" " *_nsec: Nanoseconds since the corresponding *_sec.\n" "\n" ));
@@ -29,9 +37,13 @@ utimes_f(int argc, char **argv) { - struct timespec t[2]; + struct timespec t[3]; +int flags =0 ;int result; +if (argc ==6 ) +return command_usage (&utimes_cmd); +/* Get the timestamps */ result =timespec_from_string (argv[1 ], argv[2 ], &t[0 ]);if (result) {
@@ -43,13 +55,22 @@ utimes_f(fprintf (stderr,"Bad value for mtime\n" );return 0 ; } - -/* Call futimens to update time. */ -if (futimens (file->fd, t)) { -perror ("futimens" ); -return 0 ; +if (argc ==7 ) { + result =timespec_from_string (argv[5 ], argv[6 ], &t[2 ]); +if (result) { +fprintf (stderr,"Bad value for btime\n" ); +return 0 ; + } + flags |=AT_UTIME_BTIME ; } +/* +* Use syscall() because the glibc wrapper for utimensat() disallows a +* NULL pathname. +*/ +if (syscall (SYS_utimensat, file->fd,NULL , t, flags)) +perror ("utimensat" ); +return 0 ; }
@@ -59,9 +80,9 @@ utimes_init(void) utimes_cmd.name ="utimes" ; utimes_cmd.cfunc = utimes_f; utimes_cmd.argmin =4 ; - utimes_cmd.argmax =4 ; + utimes_cmd.argmax =6 ; utimes_cmd.flags =CMD_NOMAP_OK |CMD_FOREIGN_OK ; - utimes_cmd.args =_ ("atime_sec atime_nsec mtime_sec mtime_nsec" ); + utimes_cmd.args =_ ("atime_sec atime_nsec mtime_sec mtime_nsec [btime_sec btime_nsec]" ); utimes_cmd.oneline =_ ("Update file times of the current file" ); utimes_cmd.help = utimes_help;
man/man8/xfs_io.8 +3 -2
@@ -827,8 +827,9 @@ verbose output will be printed. .RE .PD .TP -.BI utimes " atime_sec atime_nsec mtime_sec mtime_nsec" -The utimes command changes the atime and mtime of the current file. +.BI utimes " atime_sec atime_nsec mtime_sec mtime_nsec [btime_sec btime_nsec]" +The utimes command changes the atime, mtime, and optionally btime of the +current file. sec uses UNIX timestamp notation and is the seconds elapsed since 1970-01-01 00:00:00 UTC. nsec is the nanoseconds since the sec. This value needs to be in
Signature · 1 line
2.20.1
Quoted 11 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Hi,
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.
Quoted 5 lines
Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]
So you're adding an interface that allows users to change the create time of files without needing any privileges?
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into. Just because it's exposed to userspace via statx(), it doesn't mean that it is information that users should be allowed to change. i.e. allowing users to be able to change the create time on files makes it completely useless for the purpose it was added to XFS for...
And allowing root to change the create time doesn't really help, because once you've broken into a system, this makes it really easy to cover tracks (e.g. we can't find files that were created and unlinked during the break in window anymore) and lay false trails....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 12 lines · Dave Chinner
Quoted 11 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Hi,
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.
Quoted 8 lines
Quoted 5 lines
Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]So you're adding an interface that allows users to change the create time of files without needing any privileges?
I think it'd be reasonable to make this a privileged operation. I didn't for this initial submission for a couple of reasons:
1. The precedent on Mac OS and Windows is that this isn't a privileged operation.
2. I knew there would be different opinions on this either way I went.
Quoted 11 lines
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into. Just because it's exposed to userspace via
statx(), it doesn't mean that it is information that users should be allowed to change. i.e. allowing users to be able to change the create time on files makes it completely useless for the purpose it was added to XFS for...And allowing root to change the create time doesn't really help, because once you've broken into a system, this makes it really easy to cover tracks
If the threat model is that the attacker has root, then they can overwrite the timestamp on disk anyways, no?
Quoted 3 lines
(e.g. we can't find files that were created and unlinked during the break in window anymore) and lay false trails....
Fair point, although there's still ctime during the break-in window, which I assume you'd be looking for anyways since files modified during the break-in window are also of interest.
I see a few options, none of which are particularly nice:
1. Filesystems like XFS could choose not to support setting btime even if they support reading it.
2. XFS could add a second, writeable btime which is used for statx/utimes when available (it would fit in di_pad2...).
3. We could add a btime_writable sysctl/mount option/mkfs option.
Thanks!
Quoted 19 lines · Omar Sandoval
Quoted 18 lines · Dave Chinner
Quoted 16 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Hi,
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]
Quoted 8 lines
Quoted 2 lines
So you're adding an interface that allows users to change the create time of files without needing any privileges?
I think it'd be reasonable to make this a privileged operation. I didn't for this initial submission for a couple of reasons:
1. The precedent on Mac OS and Windows is that this isn't a privileged operation.
Don't really care about them. Interop file servers that support these operations on other OSs will need to be storing this info in xattrs because they have to work on filesystems that don't support btime.
Quoted 1 line
2. I knew there would be different opinions on this either way I went.
Yup.
Quoted 8 lines
Quoted 8 lines
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into. Just because it's exposed to userspace via
statx(), it doesn't mean that it is information that users should be allowed to change. i.e. allowing users to be able to change the create time on files makes it completely useless for the purpose it was added to XFS for...
Quoted 6 lines
Quoted 3 lines
And allowing root to change the create time doesn't really help, because once you've broken into a system, this makes it really easy to cover tracks
If the threat model is that the attacker has root, then they can overwrite the timestamp on disk anyways, no?
Modifying the block devicee under an active filesystem is fraught with danger, and there's no guarantee it will work if the metadata being modified is still active in memory. Corrupting the filesystem is a sure way to get noticed....
Quoted 5 lines
Quoted 3 lines
(e.g. we can't find files that were created and unlinked during the break in window anymore) and lay false trails....
Fair point, although there's still ctime during the break-in window,
Unless you're smart enough to know how to trigger S_NOCMTIME or FMODE_NOCMTIME....
Quoted 2 lines
which I assume you'd be looking for anyways since files modified during the break-in window are also of interest.
... and then that also can't be guaranteed. :/
Quoted 7 lines
I see a few options, none of which are particularly nice:
1. Filesystems like XFS could choose not to support setting btime even if they support reading it.
2. XFS could add a second, writeable btime which is used for statx/utimes when available (it would fit indi_pad2...).
3. We could add abtime_writablesysctl/mount option/mkfs option.
4. create time remains a read-only field, and btrfs grows its own special interface to twiddle it in btrfs-recv if it really is necessary.
I'm still not convinced that even backup/restore should be doing this, because there's so much other metadata that is unique even on restored files that it doesn't really make any sense to me to lie about it being created in the past....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Hi,
Quoted 9 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.
Quoted 3 lines
Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
Can you give an example of such usefulness? What's the thing you run into that you can't do without having this?
You guys are having a technical discussion about 'implementation or the interface' in this thread, while I'm wondering what I'm missing as btrfs send/receive user by not having this. I never needed it in my use cases.
There's two levels of use case hidden in the above line. So, I don't mean why btrfs send/receive is useful (it is, for quick efficient replication of changes) but, what's an important usecase for btime on top of that?
Quoted 36 lines
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]
I've also included a man page patch,
xfs_iosupport, and an xfstest.Thoughts on the implementation or the interface?
Thanks!
1: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setattrlist.2.html
2: https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfiletimeOmar Sandoval (6):
fs: add btime to struct iattr
fs: addAT_UTIME_BTIMEforutimensat()
Btrfs: add support for setting btime
ext4: add support for setting btime
f2fs: add support for setting btime
xfs: add support for setting btimefs/attr.c | 6 +++ fs/btrfs/inode.c | 2 + fs/btrfs/super.c | 4 +- fs/ext4/inode.c | 15 +++++- fs/ext4/super.c | 2 +- fs/f2fs/file.c | 19 ++++++-- fs/f2fs/super.c | 2 +- fs/utimes.c | 86 +++++++++++++++++++++------------- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/libxfs/xfs_log_format.h | 2 +- fs/xfs/xfs_iops.c | 11 ++++- fs/xfs/xfs_super.c | 2 +- include/linux/fs.h | 4 ++ include/uapi/linux/fcntl.h | 2 + 14 files changed, 111 insertions(+), 48 deletions(-)
Signature · 1 line
Hans van Kranenburg
Quoted 12 lines · Hans van Kranenburg
Hi,
Quoted 9 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.
Quoted 6 lines
Quoted 3 lines
Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
Can you give an example of such usefulness? What's the thing you run into that you can't do without having this?
That boils down to what's useful about having the file creation time, and it's really just another tidbit of information which you may or may not care about. Maybe you have a document that you've been editing for awhile, and you want to know when you started working on it. Or, you want to know when a user created some directory that they keep adding files to.
If the file creation time is useful to you, then you likely want it preserved if you have to restore from backups. If I had to restore from backups yesterday and I'm trying to figure out when I started that document, I don't care that I restored that file yesterday, I want the real creation date.
If you've never wondered when a file was created, then I'm sure you won't care whether btrfs send/receive preserves it :)
Quoted 79 lines · Dave Chinner
Quoted 19 lines · Omar Sandoval
Quoted 18 lines · Dave Chinner
Quoted 16 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Hi,
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]Quoted 8 lines
Quoted 2 lines
So you're adding an interface that allows users to change the create time of files without needing any privileges?
I think it'd be reasonable to make this a privileged operation. I didn't for this initial submission for a couple of reasons:
1. The precedent on Mac OS and Windows is that this isn't a privileged operation.
Don't really care about them. Interop file servers that support these operations on other OSs will need to be storing this info in xattrs because they have to work on filesystems that don't support btime.
Quoted 1 line
2. I knew there would be different opinions on this either way I went.
Yup.
Quoted 8 lines
Quoted 8 lines
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into. Just because it's exposed to userspace via
statx(), it doesn't mean that it is information that users should be allowed to change. i.e. allowing users to be able to change the create time on files makes it completely useless for the purpose it was added to XFS for...Quoted 6 lines
Quoted 3 lines
And allowing root to change the create time doesn't really help, because once you've broken into a system, this makes it really easy to cover tracks
If the threat model is that the attacker has root, then they can overwrite the timestamp on disk anyways, no?
Modifying the block devicee under an active filesystem is fraught with danger, and there's no guarantee it will work if the metadata being modified is still active in memory. Corrupting the filesystem is a sure way to get noticed....
Quoted 5 lines
Quoted 3 lines
(e.g. we can't find files that were created and unlinked during the break in window anymore) and lay false trails....
Fair point, although there's still ctime during the break-in window,
Unless you're smart enough to know how to trigger
S_NOCMTIMEorFMODE_NOCMTIME....Quoted 2 lines
which I assume you'd be looking for anyways since files modified during the break-in window are also of interest.
... and then that also can't be guaranteed. :/
Quoted 7 lines
I see a few options, none of which are particularly nice:
1. Filesystems like XFS could choose not to support setting btime even if they support reading it.
2. XFS could add a second, writeable btime which is used for statx/utimes when available (it would fit indi_pad2...).
3. We could add abtime_writablesysctl/mount option/mkfs option.
Quoted 3 lines
4. create time remains a read-only field, and btrfs grows its own special interface to twiddle it in btrfs-recv if it really is necessary.
I'm curious to hear what the ext4/f2fs/CIFS developers think. If no one else wants btime to be mutable, then I might as well make it Btrfs-specific. That is, assuming we reach consensus on the Btrfs side that btrfs receive should set btime.
Quoted 4 lines
I'm still not convinced that even backup/restore should be doing this, because there's so much other metadata that is unique even on restored files that it doesn't really make any sense to me to lie about it being created in the past....
I suppose it depends on how you interpret btime: if it's strictly filesystem metadata, then it makes sense that it should be immutable; if it's metadata for the user's own purposes, then we should allow setting it.
Quoted 3 lines · Omar Sandoval
Quoted 2 lines · Dave Chinner
Quoted 1 line · Omar Sandoval
On Fri, Feb 15, 2019 at 09:06:26AM +1100, Dave Chinner wrote:
...
Quoted 24 lines
Quoted 24 lines
Quoted 8 lines
Quoted 8 lines
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into. Just because it's exposed to userspace via
statx(), it doesn't mean that it is information that users should be allowed to change. i.e. allowing users to be able to change the create time on files makes it completely useless for the purpose it was added to XFS for...Quoted 6 lines
Quoted 3 lines
And allowing root to change the create time doesn't really help, because once you've broken into a system, this makes it really easy to cover tracks
If the threat model is that the attacker has root, then they can overwrite the timestamp on disk anyways, no?
Modifying the block devicee under an active filesystem is fraught with danger, and there's no guarantee it will work if the metadata being modified is still active in memory. Corrupting the filesystem is a sure way to get noticed....
Quoted 4 lines
Quoted 3 lines
(e.g. we can't find files that were created and unlinked during the break in window anymore) and lay false trails....
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Fair point, although there's still ctime during the break-in window,
Unless you're smart enough to know how to trigger
S_NOCMTIMEorFMODE_NOCMTIME....Quoted 2 lines
which I assume you'd be looking for anyways since files modified during the break-in window are also of interest.
I'm not sure I follow the forensics use-case for immutable btime. I'd expect dm-verity or selinux/apparmor audits to do a better job for those worried about this kind of attack.
Quoted 10 lines
Quoted 10 lines
... and then that also can't be guaranteed. :/
Quoted 7 lines
I see a few options, none of which are particularly nice:
1. Filesystems like XFS could choose not to support setting btime even if they support reading it.
2. XFS could add a second, writeable btime which is used for statx/utimes when available (it would fit indi_pad2...).
3. We could add abtime_writablesysctl/mount option/mkfs option.
Quoted 8 lines
Quoted 3 lines
4. create time remains a read-only field, and btrfs grows its own special interface to twiddle it in btrfs-recv if it really is necessary.
I'm curious to hear what the ext4/f2fs/CIFS developers think. If no one else wants btime to be mutable, then I might as well make it Btrfs-specific. That is, assuming we reach consensus on the Btrfs side that btrfs receive should set btime.
Samba currently uses a user.DOSATTRIB xattr for tracking creation time. IMO a mutable btime accessible via statx would be useful for cross-protocol interoperability.
Cheers, David
Quoted 27 lines · Omar Sandoval
Quoted 12 lines · Hans van Kranenburg
Hi,
Quoted 9 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.Quoted 6 lines
Quoted 3 lines
Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
Can you give an example of such usefulness? What's the thing you run into that you can't do without having this?
That boils down to what's useful about having the file creation time, and it's really just another tidbit of information which you may or may not care about. Maybe you have a document that you've been editing for awhile, and you want to know when you started working on it. Or, you want to know when a user created some directory that they keep adding files to.
Quoted 8 lines
If the file creation time is useful to you, then you likely want it preserved if you have to restore from backups. If I had to restore from backups yesterday and I'm trying to figure out when I started that document, I don't care that I restored that file yesterday, I want the real creation date.
If you've never wondered when a file was created, then I'm sure you won't care whether btrfs send/receive preserves it :)
Thanks for the elaborate answer. I was just curious if this was to make send "more feature complete" or if there was something else special to it, and it seems to be the first one. ;]
And for myself, I mostly treat btrfs send/receive like a improved replacement for rsync and usually don't care that much about btime indeed.
Thanks,
Signature · 1 line
Hans van Kranenburg
Quoted 25 lines · Omar Sandoval
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Omar Sandoval
I see a few options, none of which are particularly nice:
1. Filesystems like XFS could choose not to support setting btime even if they support reading it.
2. XFS could add a second, writeable btime which is used for statx/utimes when available (it would fit indi_pad2...).
3. We could add abtime_writablesysctl/mount option/mkfs option.Quoted 3 lines
4. create time remains a read-only field, and btrfs grows its own special interface to twiddle it in btrfs-recv if it really is necessary.
I'm curious to hear what the ext4/f2fs/CIFS developers think. If no one else wants btime to be mutable, then I might as well make it Btrfs-specific. That is, assuming we reach consensus on the Btrfs side that btrfs receive should set btime.
Quoted 4 lines
I'm still not convinced that even backup/restore should be doing this, because there's so much other metadata that is unique even on restored files that it doesn't really make any sense to me to lie about it being created in the past....
Quoted 4 lines
I suppose it depends on how you interpret btime: if it's strictly filesystem metadata, then it makes sense that it should be immutable; if it's metadata for the user's own purposes, then we should allow setting it.
My personal preference is that crtime/btime be read-only information that tells when the file itself was created in this filesystem, not some added metadata that is managed by userspace. There have been many times when I've needed to know when a file was _actually_ created in the filesystem, not what mtime/ctime report.
While it may be a bit of a stretch to call this "forensic evidence", making it hard to change from except via total root compromise by a skilled hacker is very useful.
If this were to go in (which I'm not in favour of), then there would need to be a CONFIG and/or runtime knob to turn it off (or better to only turn it on), similar to how FIPS and other security options can only go in one direction.
Cheers, Andreas
Quoted 12 lines · Dave Chinner
Quoted 11 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Hi,
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.
Quoted 2 lines
Quoted 2 lines
Updating btime is useful for at least a couple of use cases:
[1]
Quoted 7 lines
Quoted 3 lines
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]So you're adding an interface that allows users to change the create time of files without needing any privileges?
[2]
Quoted 8 lines
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into. Just because it's exposed to userspace via
statx(), it doesn't mean that it is information that users should be allowed to change. i.e. allowing users to be able to change the create time on files makes it completely useless for the purpose it was added to XFS for...
<snap>
I think the difference in opinion here is that there are two totally different BTIme out in the world. For two somewhat opposite motivations and it seems they both try to be crammed into the same on disk space.
One - Author creation time
This is a Windows originated creature and later MAC (and all vendors who make a living by serving cifs (hint see my email address))
This is a tag carried globally on the globe denoting the time of the original creator of the file. copy, download, backup-restore and so on preserve it from the very first original creation.
This creature is a user oriented information. That needs to be carefully orchestrated by all parties
Two - Local creation time
This is an immutable local FS information that helps in debugging and FS-checking / recovery of data. It is an information that kind of denotes the order of creation of files on a local FS.
So it looks like both sides are correct trying to preserve their own guy?
XFS invented [2] I'd let it be. If you need [1] on XFS better push for a well defined standardized xattr and be in peace.
BTRFS should decide which one of [2] or [1] it has space for in the inode and commit to it. Documenting well what it is.
That said putting my Netapp hat. I would love to see an easy API for Author-creation-time BTime type of value. That is accessed uniformly by user-mode and/or Network file servers (NFS/CIFS). And would love to see a generic implementation of that interface that puts it into a standardized xattr if the FS in question does not have a native support for it [1].
So I love these patches. And would want to see this through. But let us understand each other?
Thanks
Boaz
Quoted 8 lines · Boaz Harrosh
Quoted 6 lines · Dave Chinner
So you're adding an interface that allows users to change the create time of files without needing any privileges?
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into.
Quoted 8 lines
I think the difference in opinion here is that there are two totally different BTIme out in the world. For two somewhat opposite motivations and it seems they both try to be crammed into the same on disk space.
One - Author creation time
Two - Local creation timeSo it looks like both sides are correct trying to preserve their own guy?
I'd say that [2] is too easily gameable to be worth the effort. You can just change it on the disk. That right now it'd take some skill to find the right place to edit doesn't matter -- a tool to update the btime against your wishes would need to be written just once. Unlike btrfs, XFS doesn't even have a chain of checksums all the way to the root.
On the other hand, [1] has a lot of uses. It can also be preserved in backups and version control (svnt and git-restore-mtime could be easily extended).
I'd thus go with [2] -- any uses for [1] are better delegated to filesystem specific tools.
Meow!
Signature · 4 lines
⢀⣴⠾⠻⢶⣦⠀ ⣾⠁⢠⠒⠀⣿⡁ ⢿⡄⠘⠷⠚⠋⠀ Have you accepted Khorne as your lord and saviour? ⠈⠳⣄⠀⠀⠀⠀
Quoted 25 lines · Adam Borowski
Quoted 8 lines · Boaz Harrosh
Quoted 6 lines · Dave Chinner
So you're adding an interface that allows users to change the create time of files without needing any privileges?
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into.
Quoted 8 lines
I think the difference in opinion here is that there are two totally different BTIme out in the world. For two somewhat opposite motivations and it seems they both try to be crammed into the same on disk space.
One - Author creation time
Two - Local creation timeSo it looks like both sides are correct trying to preserve their own guy?
I'd say that [2] is too easily gameable to be worth the effort. You can just change it on the disk. That right now it'd take some skill to find the right place to edit doesn't matter -- a tool to update the btime against your wishes would need to be written just once. Unlike btrfs, XFS doesn't even have a chain of checksums all the way to the root.
Quoted 7 lines
On the other hand, [1] has a lot of uses. It can also be preserved in backups and version control (svnt and git-restore-mtime could be easily extended).
I'd thus go with [2] -- any uses for [1] are better delegated to filesystem specific tools.
I started out in the Windows world, and I found it quite handy to right-click a file and see when it was created. When I started using Linux, I saw things like this:
Access: 2019-02-16 22:19:32.024284060 -0800
Modify: 2016-02-02 19:26:47.901766778 -0800
Change: 2016-02-02 19:26:47.907766649 -0800
and my mind boggled a bit. Modify makes sense. Change? What's that?
Why do I care?
Adding "birth" makes sense, and I think that filesystem-agnostic backup tools *should* be able to write it.
So I'm highly in favor of this patch. If XFS wants to disallow writing the birth time, fine, but I think that behavior should be overridable.
Quoted 1 line · Andreas Dilger
While it may be a bit of a stretch to call this "forensic evidence", making
We do forensic analysis of corrupt filesystems looking for evidence of what went wrong, not just looking for evidence of what happened on systems that have been broken into.
Quoted 2 lines
it hard to change from except via total root compromise by a skilled hacker is very useful.
*nod*.
Quoted 3 lines
If this were to go in (which I'm not in favour of), then there would need to be a CONFIG and/or runtime knob to turn it off (or better to only turn it on), similar to how FIPS and other security options can only go in one direction.
The problem here is that "inode birth time" is being conflated with "user document creation time". These two things are very different.
i.e. One is filesystem internal information and is not related to when the original copy of the data in the file was created, the other is user specified metadata that is related to the file data contents and needs to travel with the data, not the filesystem.
IMO, trying to make one on-disk field hold two different types of information defeats one or the other purpose, and nobody knows which one the field stores for any given file.
I'd suggest that "authored date" should be a generic system xattr so most filesystems support it, not just those that have a birth time field on disk. Sure, modify it through utimesat() and expose it through statx() (as authored time, not birth time), but store it a system xattr rather than an internal filesystem metadata field that requires was never intended to be user modifiable.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 3 lines · Andy Lutomirski
So I'm highly in favor of this patch. If XFS wants to disallow writing the birth time, fine, but I think that behavior should be overridable.
Please, no. We need to have consistent behaviour between at least Linux local filesystems. Not "Chris thinks this is a good idea, while Dave and Ted think its a bad idea, so btrfs supports it and XFS and ext4 disallow it".
Quoted 9 lines · Matthew Wilcox
Quoted 3 lines · Andy Lutomirski
So I'm highly in favor of this patch. If XFS wants to disallow writing the birth time, fine, but I think that behavior should be overridable.
Please, no. We need to have consistent behaviour between at least Linux local filesystems. Not "Chris thinks this is a good idea, while Dave and Ted think its a bad idea, so btrfs supports it and XFS and ext4 disallow it".
And, quite frankly, this is the entire reason xattrs exist. i.e. so that generic file attributes can be stored persitently without each individual having to support them in their on-disk format.
I wish people would stop trying to implement stuff like this in filesystem code and instead added it to the VFS and stored it in VFS defined system xattrs so that it is common across all filesystems. It also means that backup applications can preserve them during file copies without really even being aware of their meaning, simply by copying all the xattrs on the file...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 43 lines · Boaz Harrosh
Quoted 12 lines · Dave Chinner
Quoted 11 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Hi,
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime with
utimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.Quoted 2 lines
Quoted 2 lines
Updating btime is useful for at least a couple of use cases:
[1]
Quoted 7 lines
Quoted 3 lines
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]So you're adding an interface that allows users to change the create time of files without needing any privileges?
[2]
Quoted 8 lines
Inode create time is forensic metadata in XFS - information we use for sequence of event and inode lifetime analysis during examination of broken filesystem images and systems that have been broken into. Just because it's exposed to userspace via
statx(), it doesn't mean that it is information that users should be allowed to change. i.e. allowing users to be able to change the create time on files makes it completely useless for the purpose it was added to XFS for...<snap>
I think the difference in opinion here is that there are two totally different BTIme out in the world. For two somewhat opposite motivations and it seems they both try to be crammed into the same on disk space.
One - Author creation time
This is a Windows originated creature and later MAC (and all vendors who make a living by serving cifs (hint see my email address))
Quoted 5 lines
This is a tag carried globally on the globe denoting the time of the original creator of the file. copy, download, backup-restore and so on preserve it from the very first original creation.
This creature is a user oriented information. That needs to be carefully orchestrated by all parties.
One of the issues with user-supplied "creation time" is that it is vague. If Vim (or many other programs) is writing out an existing file, it will actually create a new file and rename it over the old file, so even though the newly-written file is "created" at write time, the content is older. Unless the creation time is actually stored internal to the file itself, rather than as filesystem metadata, it is unlikely to be kept across filesystems, between systems, etc.
Conversely, there is already such metadata in existing file formats, e.g. .jpg (Exif.Image.DateTime), .png (tEXt Creation Time), .docx (Date Completed), etc. that sticks with the file regardless of the underlying storage medium.
Cheers, Andreas
Quoted 8 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Since statx was added in 4.11, userspace has had an interface for reading btime (file creation time), but no way to set it. This RFC patch series adds support for changing btime withutimensat(). Patch 1 adds the VFS infrastructure, patch 2 adds the support toutimensat()with a new flag, and the rest of the patches add filesystem support; I excluded CIFS for now because I don't have a CIFS setup to test it on.
Quoted 5 lines
Updating btime is useful for at least a couple of use cases:
- Backup/restore programs (my motivation for this feature is btrfs send)
- File servers which interoperate with operating systems that allow updating file creation time, including Mac OS [1] and Windows [2]
I don't have anything new to add to what has been said in the thread. The creation time is property of the filesystem and if user wants to track additional metadata, then as external attributes.
Quoted 28 lines · Dave Chinner
Quoted 1 line · Andreas Dilger
While it may be a bit of a stretch to call this "forensic evidence", making
We do forensic analysis of corrupt filesystems looking for evidence of what went wrong, not just looking for evidence of what happened on systems that have been broken into.
Quoted 2 lines
it hard to change from except via total root compromise by a skilled hacker is very useful.
*nod*.
Quoted 3 lines
If this were to go in (which I'm not in favour of), then there would need to be a CONFIG and/or runtime knob to turn it off (or better to only turn it on), similar to how FIPS and other security options can only go in one direction.
The problem here is that "inode birth time" is being conflated with "user document creation time". These two things are very different.
i.e. One is filesystem internal information and is not related to when the original copy of the data in the file was created, the other is user specified metadata that is related to the file data contents and needs to travel with the data, not the filesystem.
IMO, trying to make one on-disk field hold two different types of information defeats one or the other purpose, and nobody knows which one the field stores for any given file.
Quoted 6 lines
I'd suggest that "authored date" should be a generic system xattr so most filesystems support it, not just those that have a birth time field on disk. Sure, modify it through
utimesat()and expose it throughstatx()(as authored time, not birth time), but store it a system xattr rather than an internal filesystem metadata field that requires was never intended to be user modifiable.
It seems that this is the general consensus, so I'll look into implementing this functionality as an xattr.
Quoted 40 lines · Omar Sandoval
Quoted 29 lines · Dave Chinner
Quoted 1 line · Andreas Dilger
While it may be a bit of a stretch to call this "forensic evidence",
We do forensic analysis of corrupt filesystems looking for evidence of what went wrong, not just looking for evidence of what happened on systems that have been broken into.
Quoted 2 lines
making it hard to change from except via total root compromise by a skilled hacker is very useful.
*nod*.
Quoted 4 lines
If this were to go in (which I'm not in favour of), then there would need to be a CONFIG and/or runtime knob to turn it off (or better to only turn it on), similar to how FIPS and other security options can only go in one direction.
The problem here is that "inode birth time" is being conflated with "user document creation time". These two things are very different.
i.e. One is filesystem internal information and is not related to when the original copy of the data in the file was created, the other is user specified metadata that is related to the file data contents and needs to travel with the data, not the filesystem.
IMO, trying to make one on-disk field hold two different types of information defeats one or the other purpose, and nobody knows which one the field stores for any given file.
Quoted 6 lines
I'd suggest that "authored date" should be a generic system xattr so most filesystems support it, not just those that have a birth time field on disk. Sure, modify it through
utimesat()and expose it throughstatx()(as authored time, not birth time), but store it a system xattr rather than an internal filesystem metadata field that requires was never intended to be user modifiable.
Quoted 2 lines
It seems that this is the general consensus, so I'll look into implementing this functionality as an xattr.
I would recommend to look at how Samba is storing these attributes today, and do the same thing, maybe add support into GNU coreutils to handle this transparently.
Cheers, Andreas