Commit eeeb9dd9 authored by Russell King's avatar Russell King Committed by Al Viro

fs/adfs: inode: update timestamps to centisecond precision

Despite ADFS timestamps having centi-second granularity, and Linux
gaining fine-grained timestamp support in v2.5.48, fs/adfs was never
updated.

Update fs/adfs to centi-second support, and ensure that the inode ctime
always reflects what is written in underlying media.
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent e42617b8
...@@ -158,6 +158,8 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode) ...@@ -158,6 +158,8 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode)
return attr; return attr;
} }
static const s64 nsec_unix_epoch_diff_risc_os_epoch = 2208988800000000000LL;
/* /*
* Convert an ADFS time to Unix time. ADFS has a 40-bit centi-second time * Convert an ADFS time to Unix time. ADFS has a 40-bit centi-second time
* referenced to 1 Jan 1900 (til 2248) so we need to discard 2208988800 seconds * referenced to 1 Jan 1900 (til 2248) so we need to discard 2208988800 seconds
...@@ -170,8 +172,6 @@ adfs_adfs2unix_time(struct timespec64 *tv, struct inode *inode) ...@@ -170,8 +172,6 @@ adfs_adfs2unix_time(struct timespec64 *tv, struct inode *inode)
/* 01 Jan 1970 00:00:00 (Unix epoch) as nanoseconds since /* 01 Jan 1970 00:00:00 (Unix epoch) as nanoseconds since
* 01 Jan 1900 00:00:00 (RISC OS epoch) * 01 Jan 1900 00:00:00 (RISC OS epoch)
*/ */
static const s64 nsec_unix_epoch_diff_risc_os_epoch =
2208988800000000000LL;
s64 nsec; s64 nsec;
if (!adfs_inode_is_stamped(inode)) if (!adfs_inode_is_stamped(inode))
...@@ -204,24 +204,23 @@ adfs_adfs2unix_time(struct timespec64 *tv, struct inode *inode) ...@@ -204,24 +204,23 @@ adfs_adfs2unix_time(struct timespec64 *tv, struct inode *inode)
return; return;
} }
/* /* Convert an Unix time to ADFS time for an entry that is already stamped. */
* Convert an Unix time to ADFS time. We only do this if the entry has a static void adfs_unix2adfs_time(struct inode *inode,
* time/date stamp already. const struct timespec64 *ts)
*/
static void
adfs_unix2adfs_time(struct inode *inode, unsigned int secs)
{ {
unsigned int high, low; s64 cs, nsec = timespec64_to_ns(ts);
if (adfs_inode_is_stamped(inode)) { /* convert from Unix to RISC OS epoch */
/* convert 32-bit seconds to 40-bit centi-seconds */ nsec += nsec_unix_epoch_diff_risc_os_epoch;
low = (secs & 255) * 100;
high = (secs / 256) * 100 + (low >> 8) + 0x336e996a;
ADFS_I(inode)->loadaddr = (high >> 24) | /* convert from nanoseconds to centiseconds */
(ADFS_I(inode)->loadaddr & ~0xff); cs = div_s64(nsec, 10000000);
ADFS_I(inode)->execaddr = (low & 255) | (high << 8);
} cs = clamp_t(s64, cs, 0, 0xffffffffff);
ADFS_I(inode)->loadaddr &= ~0xff;
ADFS_I(inode)->loadaddr |= (cs >> 32) & 0xff;
ADFS_I(inode)->execaddr = cs;
} }
/* /*
...@@ -315,10 +314,11 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr) ...@@ -315,10 +314,11 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr)
if (ia_valid & ATTR_SIZE) if (ia_valid & ATTR_SIZE)
truncate_setsize(inode, attr->ia_size); truncate_setsize(inode, attr->ia_size);
if (ia_valid & ATTR_MTIME) { if (ia_valid & ATTR_MTIME && adfs_inode_is_stamped(inode)) {
inode->i_mtime = attr->ia_mtime; adfs_unix2adfs_time(inode, &attr->ia_mtime);
adfs_unix2adfs_time(inode, attr->ia_mtime.tv_sec); adfs_adfs2unix_time(&inode->i_mtime, inode);
} }
/* /*
* FIXME: should we make these == to i_mtime since we don't * FIXME: should we make these == to i_mtime since we don't
* have the ability to represent them in our filesystem? * have the ability to represent them in our filesystem?
......
...@@ -391,7 +391,9 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -391,7 +391,9 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
asb = kzalloc(sizeof(*asb), GFP_KERNEL); asb = kzalloc(sizeof(*asb), GFP_KERNEL);
if (!asb) if (!asb)
return -ENOMEM; return -ENOMEM;
sb->s_fs_info = asb; sb->s_fs_info = asb;
sb->s_time_gran = 10000000;
/* set default options */ /* set default options */
asb->s_uid = GLOBAL_ROOT_UID; asb->s_uid = GLOBAL_ROOT_UID;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment