From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Frank Sorenson <sorenson@redhat.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [RFC PATCH] fat: truncate timestamps returned from fat_getattr
Date: Sun, 01 Apr 2018 15:02:23 +0900 [thread overview]
Message-ID: <87sh8fsbv4.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <866cd645-3e99-c7a5-56d6-9134a03c556d@redhat.com> (Frank Sorenson's message of "Mon, 26 Mar 2018 16:23:56 -0500")
Frank Sorenson <sorenson@redhat.com> writes:
Hi,
> Author: Frank Sorenson <sorenson@redhat.com>
> Date: 2018-03-23 23:28:32 -0500
>
> fat: add function to truncate timestamps returned from fat_getattr
>
> vfat/msdos timestamps are stored on-disk with several different
> granularities, some of them lower resolution than timespec_trunc()
> can provide. However, they are only truncated as they are written
> to disk, so the timestamps in-memory for new or modified
> files/directories may be different from the same timestamps after
> a remount, as the now-truncated times are re-read from the on-disk
> format.
>
> This patch adds a function to adjust the timestamps returned from
> fat_getattr() so that userspace sees consistent times across a
> remount. The existing functions are used to convert the timespec
> to the on-disk representation, then back to timespec again.
>
> Signed-off-by: Frank Sorenson <sorenson@redhat.com>
Already tried to use ->update_time() callback? With quick look though,
it seems to be possible to control timestamp granularity with
->update_time(), and add fat_current_time() or such to get proper
timestamp for FAT.
I think we should give consistent in-core inode timestamp too. For
example, overlayfs may be copy timestamps from in-core inode, etc., then
this stat workaround will not work.
Thanks.
> diff --git a/fs/fat/fat.h b/fs/fat/fat.h
> index 8fc1093da47d..0367be021b23 100644
> --- a/fs/fat/fat.h
> +++ b/fs/fat/fat.h
> @@ -410,6 +410,7 @@ extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
> __le16 __time, __le16 __date, u8 time_cs);
> extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts,
> __le16 *time, __le16 *date, u8 *time_cs);
> +extern void fat_trunc_kstat_times(struct msdos_sb_info *sbi, struct kstat *stat);
> extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs);
>
> int fat_cache_init(void);
> diff --git a/fs/fat/file.c b/fs/fat/file.c
> index 4724cc9ad650..11639e393ef7 100644
> --- a/fs/fat/file.c
> +++ b/fs/fat/file.c
> @@ -370,6 +370,7 @@ int fat_getattr(const struct path *path, struct kstat *stat,
> {
> struct inode *inode = d_inode(path->dentry);
> generic_fillattr(inode, stat);
> + fat_trunc_kstat_times(MSDOS_SB(inode->i_sb), stat);
> stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size;
>
> if (MSDOS_SB(inode->i_sb)->options.nfs == FAT_NFS_NOSTALE_RO) {
> diff --git a/fs/fat/misc.c b/fs/fat/misc.c
> index f9bdc1e01c98..52f40edefd12 100644
> --- a/fs/fat/misc.c
> +++ b/fs/fat/misc.c
> @@ -262,6 +262,29 @@ void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec *ts,
> }
> EXPORT_SYMBOL_GPL(fat_time_unix2fat);
>
> +void fat_trunc_kstat_times(struct msdos_sb_info *sbi, struct kstat *stat)
> +{
> + if (stat->ino == MSDOS_ROOT_INO)
> + stat->mtime = stat->ctime = stat->atime =
> + (struct timespec){0, 0};
> + else {
> + __le16 time;
> + __le16 date;
> + u8 ctime_cs;
> +
> + fat_time_unix2fat(sbi, &stat->mtime, &time, &date, NULL);
> + fat_time_fat2unix(sbi, &stat->mtime, time, date, 0);
> +
> + fat_time_unix2fat(sbi, &stat->ctime, &time, &date,
> + sbi->options.isvfat ? &ctime_cs : NULL);
> + fat_time_fat2unix(sbi, &stat->ctime, time, date,
> + sbi->options.isvfat ? ctime_cs : 0);
> +
> + fat_time_unix2fat(sbi, &stat->atime, &time, &date, NULL);
> + fat_time_fat2unix(sbi, &stat->atime, 0, date, 0);
> + }
> +}
> +
> int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs)
> {
> int i, err = 0;
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
next prev parent reply other threads:[~2018-04-01 6:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-26 21:23 [RFC PATCH] fat: truncate timestamps returned from fat_getattr Frank Sorenson
2018-04-01 6:02 ` OGAWA Hirofumi [this message]
2018-04-02 1:26 ` Frank Sorenson
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=87sh8fsbv4.fsf@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sorenson@redhat.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.