aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>2014-05-06 16:57:26 +0900
committerDaniel Phillips <daniel@tux3.org>2014-05-06 16:57:26 +0900
commit5ba195b3e5122a4f8885dd502895208209d8d165 (patch)
tree933c8ed2b22c4a3ea169f32fe7796185eab52ac6
parent4bb790e7a72885e91e47a6981d1ae8a2c6062b4c (diff)
downloadlinux-tux3-5ba195b3e5122a4f8885dd502895208209d8d165.tar.gz
tux3: Introduce nanosecond timestamp format
This format is not fixed version though, was easier to implement compared with fixed 32.32. FIXME: timestamp can has many unused bits, and it bloats inode size. So, we may introduce new format again to reduce size. Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
-rw-r--r--fs/tux3/iattr.c42
-rw-r--r--fs/tux3/tux3.h3
2 files changed, 10 insertions, 35 deletions
diff --git a/fs/tux3/iattr.c b/fs/tux3/iattr.c
index 9627179bfded06..1ececcef987389 100644
--- a/fs/tux3/iattr.c
+++ b/fs/tux3/iattr.c
@@ -33,44 +33,18 @@ unsigned atsize[MAX_ATTRS] = {
};
/*
- * Tux3 times are 32.32 fixed point while time attributes are stored in 32.16
- * format, trading away some precision to compress time fields by two bytes
- * each. It is not clear whether the saved space is worth the lower precision.
- *
- * On-disk format is changed to use 32.32.
+ * Tux3 times are nanosecond from base FS time (for now, same with unix epoch).
+ * It is not clear whether the saved space is worth the lower precision.
*/
-#define TIME_ATTR_SHIFT 0
-#define SEC_BITS 32
-#define NSEC_BITS (64 - SEC_BITS)
-#define NSEC_MASK ((1ULL << NSEC_BITS) - 1)
-#define NSEC 1000000000LL
-
-static inline long fixed_to_sec(s64 val)
-{
- return val >> NSEC_BITS;
-}
-
-static inline long fixed_to_nsec(s64 val)
-{
- const s64 roundup = 1LL << (NSEC_BITS - 1);
- return ((val & NSEC_MASK) * NSEC + roundup) >> NSEC_BITS;
-}
static inline struct timespec spectime(const s64 time)
{
- struct timespec ts = {
- .tv_sec = fixed_to_sec(time),
- .tv_nsec = fixed_to_nsec(time),
- };
- return ts;
+ return ns_to_timespec(time);
}
static inline s64 tuxtime(const struct timespec ts)
{
- const s64 mult = (1ULL << 63) / NSEC;
- const s64 roundup = 3LL << ((32 - 1) - 2);
- return ((s64)ts.tv_sec << NSEC_BITS) +
- (((s64)ts.tv_nsec * mult + roundup) >> (SEC_BITS - 1));
+ return timespec_to_ns(&ts);
}
static unsigned encode_asize(unsigned bits)
@@ -171,7 +145,7 @@ static void *encode_attrs(struct btree *btree, void *data, void *attrs,
attrs = encode32(attrs, idata->i_gid);
break;
case CTIME_SIZE_ATTR:
- attrs = encode64(attrs, tuxtime(idata->i_ctime) >> TIME_ATTR_SHIFT);
+ attrs = encode64(attrs, tuxtime(idata->i_ctime));
attrs = encode64(attrs, idata->i_size);
break;
case DATA_BTREE_ATTR:
@@ -181,7 +155,7 @@ static void *encode_attrs(struct btree *btree, void *data, void *attrs,
attrs = encode32(attrs, idata->i_nlink);
break;
case MTIME_ATTR:
- attrs = encode64(attrs, tuxtime(idata->i_mtime) >> TIME_ATTR_SHIFT);
+ attrs = encode64(attrs, tuxtime(idata->i_mtime));
break;
}
}
@@ -230,7 +204,7 @@ static void *decode_attrs(struct inode *inode, void *attrs, unsigned size)
break;
case CTIME_SIZE_ATTR:
attrs = decode64(attrs, &v64);
- inode->i_ctime = spectime(v64 << TIME_ATTR_SHIFT);
+ inode->i_ctime = spectime(v64);
attrs = decode64(attrs, &v64);
inode->i_size = v64;
break;
@@ -247,7 +221,7 @@ static void *decode_attrs(struct inode *inode, void *attrs, unsigned size)
}
case MTIME_ATTR:
attrs = decode64(attrs, &v64);
- inode->i_mtime = spectime(v64 << TIME_ATTR_SHIFT);
+ inode->i_mtime = spectime(v64);
break;
case XATTR_ATTR:
attrs = decode_xattr(inode, attrs);
diff --git a/fs/tux3/tux3.h b/fs/tux3/tux3.h
index 1dbe203b55eff3..4b3c4fb980c62d 100644
--- a/fs/tux3/tux3.h
+++ b/fs/tux3/tux3.h
@@ -98,8 +98,9 @@ static inline void *decode48(void *at, u64 *val)
* 2012-07-02: Use timestamp 32.32 fixed point. Increase log_balloc size.
* 2012-12-20: Add ->usedinodes
* 2014-03-27: Change internal inum numbers. Change btree->root.depth.
+ * 2014-05-06: Change timestamp format to nanosecond.
*/
-#define TUX3_MAGIC { 't', 'u', 'x', '3', 0x20, 0x14, 0x03, 0x27 }
+#define TUX3_MAGIC { 't', 'u', 'x', '3', 0x20, 0x14, 0x05, 0x06 }
#define TUX3_MAGIC_STR \
((typeof(((struct disksuper *)0)->magic))TUX3_MAGIC)