aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ext4_fs.h
diff options
context:
space:
mode:
authorKalpak Shah <kalpak@clusterfs.com>2007-07-18 09:15:20 -0400
committerTheodore Ts'o <tytso@mit.edu>2007-07-18 09:15:20 -0400
commitef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80 (patch)
treeee34a5821332cf70b89827eb872f08bc0dd43f89 /include/linux/ext4_fs.h
parent0f49d5d019afa4e94253bfc92f0daca3badb990b (diff)
ext4: Add nanosecond timestamps
This patch adds nanosecond timestamps for ext4. This involves adding *time_extra fields to the ext4_inode to extend the timestamps to 64-bits. Creation time is also added by this patch. These extended fields will fit into an inode if the filesystem was formatted with large inodes (-I 256 or larger) and there are currently no EAs consuming all of the available space. For new inodes we always reserve enough space for the kernel's known extended fields, but for inodes created with an old kernel this might not have been the case. So this patch also adds the EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE feature flag(ro-compat so that older kernels can't create inodes with a smaller extra_isize). which indicates if the fields fitting inside s_min_extra_isize are available or not. If the expansion of inodes if unsuccessful then this feature will be disabled. This feature is only enabled if requested by the sysadmin. None of the extended inode fields is critical for correct filesystem operation. Signed-off-by: Andreas Dilger <adilger@clusterfs.com> Signed-off-by: Kalpak Shah <kalpak@clusterfs.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com> Signed-off-by: Mingming Cao <cmm@us.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'include/linux/ext4_fs.h')
-rw-r--r--include/linux/ext4_fs.h86
1 files changed, 85 insertions, 1 deletions
diff --git a/include/linux/ext4_fs.h b/include/linux/ext4_fs.h
index 45ec7258b2b1..df5e38faa15f 100644
--- a/include/linux/ext4_fs.h
+++ b/include/linux/ext4_fs.h
@@ -288,7 +288,7 @@ struct ext4_inode {
288 __le16 i_uid; /* Low 16 bits of Owner Uid */ 288 __le16 i_uid; /* Low 16 bits of Owner Uid */
289 __le32 i_size; /* Size in bytes */ 289 __le32 i_size; /* Size in bytes */
290 __le32 i_atime; /* Access time */ 290 __le32 i_atime; /* Access time */
291 __le32 i_ctime; /* Creation time */ 291 __le32 i_ctime; /* Inode Change time */
292 __le32 i_mtime; /* Modification time */ 292 __le32 i_mtime; /* Modification time */
293 __le32 i_dtime; /* Deletion Time */ 293 __le32 i_dtime; /* Deletion Time */
294 __le16 i_gid; /* Low 16 bits of Group Id */ 294 __le16 i_gid; /* Low 16 bits of Group Id */
@@ -337,10 +337,85 @@ struct ext4_inode {
337 } osd2; /* OS dependent 2 */ 337 } osd2; /* OS dependent 2 */
338 __le16 i_extra_isize; 338 __le16 i_extra_isize;
339 __le16 i_pad1; 339 __le16 i_pad1;
340 __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
341 __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
342 __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
343 __le32 i_crtime; /* File Creation time */
344 __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
340}; 345};
341 346
342#define i_size_high i_dir_acl 347#define i_size_high i_dir_acl
343 348
349#define EXT4_EPOCH_BITS 2
350#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
351#define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS)
352
353/*
354 * Extended fields will fit into an inode if the filesystem was formatted
355 * with large inodes (-I 256 or larger) and there are not currently any EAs
356 * consuming all of the available space. For new inodes we always reserve
357 * enough space for the kernel's known extended fields, but for inodes
358 * created with an old kernel this might not have been the case. None of
359 * the extended inode fields is critical for correct filesystem operation.
360 * This macro checks if a certain field fits in the inode. Note that
361 * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize
362 */
363#define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \
364 ((offsetof(typeof(*ext4_inode), field) + \
365 sizeof((ext4_inode)->field)) \
366 <= (EXT4_GOOD_OLD_INODE_SIZE + \
367 (einode)->i_extra_isize)) \
368
369static inline __le32 ext4_encode_extra_time(struct timespec *time)
370{
371 return cpu_to_le32((sizeof(time->tv_sec) > 4 ?
372 time->tv_sec >> 32 : 0) |
373 ((time->tv_nsec << 2) & EXT4_NSEC_MASK));
374}
375
376static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
377{
378 if (sizeof(time->tv_sec) > 4)
379 time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK)
380 << 32;
381 time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> 2;
382}
383
384#define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \
385do { \
386 (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
387 if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
388 (raw_inode)->xtime ## _extra = \
389 ext4_encode_extra_time(&(inode)->xtime); \
390} while (0)
391
392#define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \
393do { \
394 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
395 (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \
396 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
397 (raw_inode)->xtime ## _extra = \
398 ext4_encode_extra_time(&(einode)->xtime); \
399} while (0)
400
401#define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \
402do { \
403 (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \
404 if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
405 ext4_decode_extra_time(&(inode)->xtime, \
406 raw_inode->xtime ## _extra); \
407} while (0)
408
409#define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \
410do { \
411 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
412 (einode)->xtime.tv_sec = \
413 (signed)le32_to_cpu((raw_inode)->xtime); \
414 if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
415 ext4_decode_extra_time(&(einode)->xtime, \
416 raw_inode->xtime ## _extra); \
417} while (0)
418
344#if defined(__KERNEL__) || defined(__linux__) 419#if defined(__KERNEL__) || defined(__linux__)
345#define i_reserved1 osd1.linux1.l_i_reserved1 420#define i_reserved1 osd1.linux1.l_i_reserved1
346#define i_frag osd2.linux2.l_i_frag 421#define i_frag osd2.linux2.l_i_frag
@@ -539,6 +614,13 @@ static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
539 return container_of(inode, struct ext4_inode_info, vfs_inode); 614 return container_of(inode, struct ext4_inode_info, vfs_inode);
540} 615}
541 616
617static inline struct timespec ext4_current_time(struct inode *inode)
618{
619 return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
620 current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
621}
622
623
542static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) 624static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
543{ 625{
544 return ino == EXT4_ROOT_INO || 626 return ino == EXT4_ROOT_INO ||
@@ -609,6 +691,7 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
609#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 691#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
610#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 692#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
611#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 693#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
694#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
612 695
613#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001 696#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
614#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002 697#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
@@ -626,6 +709,7 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
626 EXT4_FEATURE_INCOMPAT_64BIT) 709 EXT4_FEATURE_INCOMPAT_64BIT)
627#define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 710#define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
628 EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \ 711 EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
712 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
629 EXT4_FEATURE_RO_COMPAT_BTREE_DIR) 713 EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
630 714
631/* 715/*