Commit 7a9730af authored by Stuart Swales's avatar Stuart Swales Committed by Linus Torvalds

adfs: improve timestamp precision

ADFS (FileCore) storage complies with the RISC OS timestamp specification
(40-bit centiseconds since 01 Jan 1900 00:00:00).  It is desirable that
stored timestamp precision be maintained to facilitate a precise copy of
data and metadata from a hard disc (or image thereof) into a RISC OS
emulator (such as RPCEmu).

This patch implements a full-precision conversion from ADFS to Unix
timestamp as the existing driver, for ease of calculation with old 32-bit
compilers, uses the common trick of shifting the 40-bits representing
centiseconds around into 32-bits representing seconds thereby losing
precision.

Signed-off-by: Stuart Swales<stuart.swales.croftnuisk@gmail.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2f09719a
...@@ -174,50 +174,48 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode) ...@@ -174,50 +174,48 @@ adfs_mode2atts(struct super_block *sb, struct inode *inode)
/* /*
* 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) * referenced to 1 Jan 1900 (til 2248) so we need to discard 2208988800 seconds
* of time to convert from RISC OS epoch to Unix epoch.
*/ */
static void static void
adfs_adfs2unix_time(struct timespec *tv, struct inode *inode) adfs_adfs2unix_time(struct timespec *tv, struct inode *inode)
{ {
unsigned int high, low; unsigned int high, low;
/* 01 Jan 1970 00:00:00 (Unix epoch) as nanoseconds since
* 01 Jan 1900 00:00:00 (RISC OS epoch)
*/
static const s64 nsec_unix_epoch_diff_risc_os_epoch =
2208988800000000000LL;
s64 nsec;
if (ADFS_I(inode)->stamped == 0) if (ADFS_I(inode)->stamped == 0)
goto cur_time; goto cur_time;
high = ADFS_I(inode)->loadaddr << 24; high = ADFS_I(inode)->loadaddr & 0xFF; /* top 8 bits of timestamp */
low = ADFS_I(inode)->execaddr; low = ADFS_I(inode)->execaddr; /* bottom 32 bits of timestamp */
high |= low >> 8; /* convert 40-bit centi-seconds to 32-bit seconds
low &= 255; * going via nanoseconds to retain precision
*/
nsec = (((s64) high << 32) | (s64) low) * 10000000; /* cs to ns */
/* Files dated pre 01 Jan 1970 00:00:00. */ /* Files dated pre 01 Jan 1970 00:00:00. */
if (high < 0x336e996a) if (nsec < nsec_unix_epoch_diff_risc_os_epoch)
goto too_early; goto too_early;
/* Files dated post 18 Jan 2038 03:14:05. */ /* convert from RISC OS to Unix epoch */
if (high >= 0x656e9969) nsec -= nsec_unix_epoch_diff_risc_os_epoch;
goto too_late;
/* discard 2208988800 (0x336e996a00) seconds of time */
high -= 0x336e996a;
/* convert 40-bit centi-seconds to 32-bit seconds */ *tv = ns_to_timespec(nsec);
tv->tv_sec = (((high % 100) << 8) + low) / 100 + (high / 100 << 8);
tv->tv_nsec = 0;
return; return;
cur_time: cur_time:
*tv = CURRENT_TIME_SEC; *tv = CURRENT_TIME;
return; return;
too_early: too_early:
tv->tv_sec = tv->tv_nsec = 0; tv->tv_sec = tv->tv_nsec = 0;
return; return;
too_late:
tv->tv_sec = 0x7ffffffd;
tv->tv_nsec = 0;
return;
} }
/* /*
......
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