Commit c9dba577 authored by Anton Altaparmakov's avatar Anton Altaparmakov

Merge cantab.net:/home/src/bklinux-2.6

into cantab.net:/home/src/ntfs-2.6
parents 09b9f933 0de89e24
...@@ -19,6 +19,25 @@ ToDo: ...@@ -19,6 +19,25 @@ ToDo:
sufficient for synchronisation here. We then just need to make sure sufficient for synchronisation here. We then just need to make sure
ntfs_readpage/writepage/truncate interoperate properly with us. ntfs_readpage/writepage/truncate interoperate properly with us.
2.1.8-WIP
- Use get_bh() instead of manual atomic_inc() in fs/ntfs/compress.c.
- Modify fs/ntfs/time.c::ntfs2utc(), get_current_ntfs_time(), and
utc2ntfs() to work with struct timespec instead of time_t on the
Linux UTC time side thus preserving the full precision of the NTFS
time and only loosing up to 99 nano-seconds in the Linux UTC time.
- Move fs/ntfs/time.c to fs/ntfs/time.h and make the time functions
static inline.
- Remove unused ntfs_dirty_inode().
- Cleanup super operations declaration in fs/ntfs/super.c.
- Wrap flush_dcache_mft_record_page() in #ifdef NTFS_RW.
- Add NInoTestSetFoo() and NInoTestClearFoo() macro magic to
fs/ntfs/inode.h and use it to declare NInoTest{Set,Clear}Dirty.
- Move typedefs for ntfs_attr and test_t from fs/ntfs/inode.c to
fs/ntfs/inode.h so they can be used elsewhere.
- Determine the mft mirror size as the number of mirrored mft records
and store it in ntfs_volume->mftmirr_size (fs/ntfs/super.c).
2.1.7 - Enable NFS exporting of mounted NTFS volumes. 2.1.7 - Enable NFS exporting of mounted NTFS volumes.
- Set i_generation in the VFS inode from the seq_no of the NTFS inode. - Set i_generation in the VFS inode from the seq_no of the NTFS inode.
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
obj-$(CONFIG_NTFS_FS) += ntfs.o obj-$(CONFIG_NTFS_FS) += ntfs.o
ntfs-objs := aops.o attrib.o compress.o debug.o dir.o file.o inode.o mft.o \ ntfs-objs := aops.o attrib.o compress.o debug.o dir.o file.o inode.o mft.o \
mst.o namei.o super.o sysctl.o time.o unistr.o upcase.o mst.o namei.o super.o sysctl.o unistr.o upcase.o
EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.7\" EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.8-WIP\"
ifeq ($(CONFIG_NTFS_DEBUG),y) ifeq ($(CONFIG_NTFS_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG EXTRA_CFLAGS += -DDEBUG
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* compress.c - NTFS kernel compressed attributes handling. * compress.c - NTFS kernel compressed attributes handling.
* Part of the Linux-NTFS project. * Part of the Linux-NTFS project.
* *
* Copyright (c) 2001-2003 Anton Altaparmakov * Copyright (c) 2001-2004 Anton Altaparmakov
* Copyright (c) 2002 Richard Russon * Copyright (c) 2002 Richard Russon
* *
* This program/include file is free software; you can redistribute it and/or * This program/include file is free software; you can redistribute it and/or
...@@ -643,7 +643,7 @@ int ntfs_read_compressed_block(struct page *page) ...@@ -643,7 +643,7 @@ int ntfs_read_compressed_block(struct page *page)
unlock_buffer(tbh); unlock_buffer(tbh);
continue; continue;
} }
atomic_inc(&tbh->b_count); get_bh(tbh);
tbh->b_end_io = end_buffer_read_sync; tbh->b_end_io = end_buffer_read_sync;
submit_bh(READ, tbh); submit_bh(READ, tbh);
} }
...@@ -943,4 +943,3 @@ int ntfs_read_compressed_block(struct page *page) ...@@ -943,4 +943,3 @@ int ntfs_read_compressed_block(struct page *page)
kfree(pages); kfree(pages);
return -EIO; return -EIO;
} }
...@@ -29,26 +29,7 @@ ...@@ -29,26 +29,7 @@
#include "dir.h" #include "dir.h"
#include "inode.h" #include "inode.h"
#include "attrib.h" #include "attrib.h"
#include "time.h"
/**
* ntfs_attr - ntfs in memory attribute structure
* @mft_no: mft record number of the base mft record of this attribute
* @name: Unicode name of the attribute (NULL if unnamed)
* @name_len: length of @name in Unicode characters (0 if unnamed)
* @type: attribute type (see layout.h)
*
* This structure exists only to provide a small structure for the
* ntfs_{attr_}iget()/ntfs_test_inode()/ntfs_init_locked_inode() mechanism.
*
* NOTE: Elements are ordered by size to make the structure as compact as
* possible on all architectures.
*/
typedef struct {
unsigned long mft_no;
uchar_t *name;
u32 name_len;
ATTR_TYPES type;
} ntfs_attr;
/** /**
* ntfs_test_inode - compare two (possibly fake) inodes for equality * ntfs_test_inode - compare two (possibly fake) inodes for equality
...@@ -66,7 +47,7 @@ typedef struct { ...@@ -66,7 +47,7 @@ typedef struct {
* NOTE: This function runs with the inode_lock spin lock held so it is not * NOTE: This function runs with the inode_lock spin lock held so it is not
* allowed to sleep. * allowed to sleep.
*/ */
static int ntfs_test_inode(struct inode *vi, ntfs_attr *na) int ntfs_test_inode(struct inode *vi, ntfs_attr *na)
{ {
ntfs_inode *ni; ntfs_inode *ni;
...@@ -150,7 +131,6 @@ static int ntfs_init_locked_inode(struct inode *vi, ntfs_attr *na) ...@@ -150,7 +131,6 @@ static int ntfs_init_locked_inode(struct inode *vi, ntfs_attr *na)
return 0; return 0;
} }
typedef int (*test_t)(struct inode *, void *);
typedef int (*set_t)(struct inode *, void *); typedef int (*set_t)(struct inode *, void *);
static int ntfs_read_locked_inode(struct inode *vi); static int ntfs_read_locked_inode(struct inode *vi);
static int ntfs_read_locked_attr_inode(struct inode *base_vi, struct inode *vi); static int ntfs_read_locked_attr_inode(struct inode *base_vi, struct inode *vi);
...@@ -590,21 +570,18 @@ static int ntfs_read_locked_inode(struct inode *vi) ...@@ -590,21 +570,18 @@ static int ntfs_read_locked_inode(struct inode *vi)
* mtime is the last change of the data within the file. Not changed * mtime is the last change of the data within the file. Not changed
* when only metadata is changed, e.g. a rename doesn't affect mtime. * when only metadata is changed, e.g. a rename doesn't affect mtime.
*/ */
vi->i_mtime.tv_sec = ntfs2utc(si->last_data_change_time); vi->i_mtime = ntfs2utc(si->last_data_change_time);
vi->i_mtime.tv_nsec = 0;
/* /*
* ctime is the last change of the metadata of the file. This obviously * ctime is the last change of the metadata of the file. This obviously
* always changes, when mtime is changed. ctime can be changed on its * always changes, when mtime is changed. ctime can be changed on its
* own, mtime is then not changed, e.g. when a file is renamed. * own, mtime is then not changed, e.g. when a file is renamed.
*/ */
vi->i_ctime.tv_sec = ntfs2utc(si->last_mft_change_time); vi->i_ctime = ntfs2utc(si->last_mft_change_time);
vi->i_ctime.tv_nsec = 0;
/* /*
* Last access to the data within the file. Not changed during a rename * Last access to the data within the file. Not changed during a rename
* for example but changed whenever the file is written to. * for example but changed whenever the file is written to.
*/ */
vi->i_atime.tv_sec = ntfs2utc(si->last_access_time); vi->i_atime = ntfs2utc(si->last_access_time);
vi->i_atime.tv_nsec = 0;
/* Find the attribute list attribute if present. */ /* Find the attribute list attribute if present. */
reinit_attr_search_ctx(ctx); reinit_attr_search_ctx(ctx);
...@@ -1738,39 +1715,6 @@ void ntfs_read_inode_mount(struct inode *vi) ...@@ -1738,39 +1715,6 @@ void ntfs_read_inode_mount(struct inode *vi)
goto out_now; goto out_now;
} }
/**
* ntfs_dirty_inode - mark the inode's metadata dirty
* @vi: inode to mark dirty
*
* This is called from fs/inode.c::__mark_inode_dirty(), when the inode itself
* is being marked dirty. An example is when update_atime() is invoked.
*
* We mark the inode dirty by setting both the page in which the mft record
* resides and the buffer heads in that page which correspond to the mft record
* dirty. This ensures that the changes will eventually be propagated to disk
* when the inode is set dirty.
*
* FIXME: Can we do that with the buffer heads? I am not too sure. Because if we
* do that we need to make sure that the kernel will not write out those buffer
* heads or we are screwed as it will write corrupt data to disk. The only way
* a mft record can be written correctly is by mst protecting it, writting it
* synchronously and fast mst deprotecting it. During this period, obviously,
* the mft record must be marked as not uptodate, be locked for writing or
* whatever, so that nobody attempts anything stupid.
*
* FIXME: Do we need to check that the fs is not mounted read only? And what
* about the inode? Anything else?
*
* FIXME: As we are only a read only driver it is safe to just return here for
* the moment.
*/
void ntfs_dirty_inode(struct inode *vi)
{
ntfs_debug("Entering for inode 0x%lx.", vi->i_ino);
NInoSetDirty(NTFS_I(vi));
return;
}
/** /**
* ntfs_commit_inode - write out a dirty inode * ntfs_commit_inode - write out a dirty inode
* @ni: inode to write out * @ni: inode to write out
...@@ -2029,4 +1973,3 @@ int ntfs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -2029,4 +1973,3 @@ int ntfs_setattr(struct dentry *dentry, struct iattr *attr)
} }
#endif #endif
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* inode.h - Defines for inode structures NTFS Linux kernel driver. Part of * inode.h - Defines for inode structures NTFS Linux kernel driver. Part of
* the Linux-NTFS project. * the Linux-NTFS project.
* *
* Copyright (c) 2001-2003 Anton Altaparmakov * Copyright (c) 2001-2004 Anton Altaparmakov
* Copyright (c) 2002 Richard Russon * Copyright (c) 2002 Richard Russon
* *
* This program/include file is free software; you can redistribute it and/or * This program/include file is free software; you can redistribute it and/or
...@@ -181,8 +181,22 @@ static inline void NInoClear##flag(ntfs_inode *ni) \ ...@@ -181,8 +181,22 @@ static inline void NInoClear##flag(ntfs_inode *ni) \
clear_bit(NI_##flag, &(ni)->state); \ clear_bit(NI_##flag, &(ni)->state); \
} }
/*
* As above for NInoTestSetFoo() and NInoTestClearFoo().
*/
#define TAS_NINO_FNS(flag) \
static inline int NInoTestSet##flag(ntfs_inode *ni) \
{ \
return test_and_set_bit(NI_##flag, &(ni)->state); \
} \
static inline int NInoTestClear##flag(ntfs_inode *ni) \
{ \
return test_and_clear_bit(NI_##flag, &(ni)->state); \
}
/* Emit the ntfs inode bitops functions. */ /* Emit the ntfs inode bitops functions. */
NINO_FNS(Dirty) NINO_FNS(Dirty)
TAS_NINO_FNS(Dirty)
NINO_FNS(AttrList) NINO_FNS(AttrList)
NINO_FNS(AttrListNonResident) NINO_FNS(AttrListNonResident)
NINO_FNS(Attr) NINO_FNS(Attr)
...@@ -219,6 +233,30 @@ static inline struct inode *VFS_I(ntfs_inode *ni) ...@@ -219,6 +233,30 @@ static inline struct inode *VFS_I(ntfs_inode *ni)
return &((big_ntfs_inode *)ni)->vfs_inode; return &((big_ntfs_inode *)ni)->vfs_inode;
} }
/**
* ntfs_attr - ntfs in memory attribute structure
* @mft_no: mft record number of the base mft record of this attribute
* @name: Unicode name of the attribute (NULL if unnamed)
* @name_len: length of @name in Unicode characters (0 if unnamed)
* @type: attribute type (see layout.h)
*
* This structure exists only to provide a small structure for the
* ntfs_{attr_}iget()/ntfs_test_inode()/ntfs_init_locked_inode() mechanism.
*
* NOTE: Elements are ordered by size to make the structure as compact as
* possible on all architectures.
*/
typedef struct {
unsigned long mft_no;
uchar_t *name;
u32 name_len;
ATTR_TYPES type;
} ntfs_attr;
typedef int (*test_t)(struct inode *, void *);
extern int ntfs_test_inode(struct inode *vi, ntfs_attr *na);
extern struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no); extern struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no);
extern struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPES type, extern struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPES type,
uchar_t *name, u32 name_len); uchar_t *name, u32 name_len);
...@@ -233,8 +271,6 @@ extern void ntfs_clear_extent_inode(ntfs_inode *ni); ...@@ -233,8 +271,6 @@ extern void ntfs_clear_extent_inode(ntfs_inode *ni);
extern void ntfs_read_inode_mount(struct inode *vi); extern void ntfs_read_inode_mount(struct inode *vi);
extern void ntfs_dirty_inode(struct inode *vi);
extern void ntfs_put_inode(struct inode *vi); extern void ntfs_put_inode(struct inode *vi);
extern int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt); extern int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt);
...@@ -245,7 +281,6 @@ extern void ntfs_truncate(struct inode *vi); ...@@ -245,7 +281,6 @@ extern void ntfs_truncate(struct inode *vi);
extern int ntfs_setattr(struct dentry *dentry, struct iattr *attr); extern int ntfs_setattr(struct dentry *dentry, struct iattr *attr);
#endif #endif /* NTFS_RW */
#endif /* _LINUX_NTFS_FS_INODE_H */
#endif /* _LINUX_NTFS_INODE_H */
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mft.h - Defines for mft record handling in NTFS Linux kernel driver. * mft.h - Defines for mft record handling in NTFS Linux kernel driver.
* Part of the Linux-NTFS project. * Part of the Linux-NTFS project.
* *
* Copyright (c) 2001,2002 Anton Altaparmakov. * Copyright (c) 2001-2004 Anton Altaparmakov.
* *
* This program/include file is free software; you can redistribute it and/or * This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published * modify it under the terms of the GNU General Public License as published
...@@ -43,7 +43,9 @@ static inline void unmap_extent_mft_record(ntfs_inode *ni) ...@@ -43,7 +43,9 @@ static inline void unmap_extent_mft_record(ntfs_inode *ni)
return; return;
} }
/* #ifdef NTFS_RW
/**
* flush_dcache_mft_record_page - flush_dcache_page() for mft records * flush_dcache_mft_record_page - flush_dcache_page() for mft records
* @ni: ntfs inode structure of mft record * @ni: ntfs inode structure of mft record
* *
...@@ -57,5 +59,6 @@ static inline void flush_dcache_mft_record_page(ntfs_inode *ni) ...@@ -57,5 +59,6 @@ static inline void flush_dcache_mft_record_page(ntfs_inode *ni)
flush_dcache_page(ni->page); flush_dcache_page(ni->page);
} }
#endif /* _LINUX_NTFS_MFT_H */ #endif /* NTFS_RW */
#endif /* _LINUX_NTFS_MFT_H */
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ntfs.h - Defines for NTFS Linux kernel driver. Part of the Linux-NTFS * ntfs.h - Defines for NTFS Linux kernel driver. Part of the Linux-NTFS
* project. * project.
* *
* Copyright (c) 2001,2002 Anton Altaparmakov. * Copyright (c) 2001-2004 Anton Altaparmakov.
* Copyright (C) 2002 Richard Russon. * Copyright (C) 2002 Richard Russon.
* *
* This program/include file is free software; you can redistribute it and/or * This program/include file is free software; you can redistribute it and/or
...@@ -180,11 +180,6 @@ extern int post_read_mst_fixup(NTFS_RECORD *b, const u32 size); ...@@ -180,11 +180,6 @@ extern int post_read_mst_fixup(NTFS_RECORD *b, const u32 size);
extern int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size); extern int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size);
extern void post_write_mst_fixup(NTFS_RECORD *b); extern void post_write_mst_fixup(NTFS_RECORD *b);
/* From fs/ntfs/time.c */
extern inline s64 utc2ntfs(const time_t time);
extern inline s64 get_current_ntfs_time(void);
extern time_t ntfs2utc(const s64 time);
/* From fs/ntfs/unistr.c */ /* From fs/ntfs/unistr.c */
extern BOOL ntfs_are_names_equal(const uchar_t *s1, size_t s1_len, extern BOOL ntfs_are_names_equal(const uchar_t *s1, size_t s1_len,
const uchar_t *s2, size_t s2_len, const uchar_t *s2, size_t s2_len,
......
...@@ -657,6 +657,20 @@ static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b) ...@@ -657,6 +657,20 @@ static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
} }
vol->mftmirr_lcn = ll; vol->mftmirr_lcn = ll;
ntfs_debug("vol->mftmirr_lcn = 0x%Lx", (long long)vol->mftmirr_lcn); ntfs_debug("vol->mftmirr_lcn = 0x%Lx", (long long)vol->mftmirr_lcn);
/*
* Work out the size of the mft mirror in number of mft records. If the
* cluster size is less than or equal to the size taken by four mft
* records, the mft mirror stores the first four mft records. If the
* cluster size is bigger than the size taken by four mft records, the
* mft mirror contains as many mft records as will fit into one
* cluster.
*/
if (vol->cluster_size <= (4 << vol->mft_record_size_bits))
vol->mftmirr_size = 4;
else
vol->mftmirr_size = vol->cluster_size >>
vol->mft_record_size_bits;
ntfs_debug("vol->mftmirr_size = %i", vol->mftmirr_size);
vol->serial_no = le64_to_cpu(b->volume_serial_number); vol->serial_no = le64_to_cpu(b->volume_serial_number);
ntfs_debug("vol->serial_no = 0x%Lx", ntfs_debug("vol->serial_no = 0x%Lx",
(unsigned long long)vol->serial_no); (unsigned long long)vol->serial_no);
...@@ -1321,24 +1335,36 @@ struct super_operations ntfs_mount_sops = { ...@@ -1321,24 +1335,36 @@ struct super_operations ntfs_mount_sops = {
struct super_operations ntfs_sops = { struct super_operations ntfs_sops = {
.alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */ .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */
.destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */ .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */
//.dirty_inode = ntfs_dirty_inode, /* VFS: Called from .put_inode = ntfs_put_inode, /* VFS: Called just before
the inode reference count
is decreased. */
#ifdef NTFS_RW
//.dirty_inode = NULL, /* VFS: Called from
// __mark_inode_dirty(). */ // __mark_inode_dirty(). */
//.write_inode = NULL, /* VFS: Write dirty inode to disk. */ //.write_inode = NULL, /* VFS: Write dirty inode to
.put_inode = ntfs_put_inode, /* VFS: Called just before the inode // disk. */
reference count is decreased. */ //.drop_inode = NULL, /* VFS: Called just after the
//.delete_inode = NULL, /* VFS: Delete inode from disk. Called // inode reference count has
// when i_count becomes 0 and i_nlink // been decreased to zero.
// is also 0. */ // NOTE: The inode lock is
// held. See fs/inode.c::
// generic_drop_inode(). */
//.delete_inode = NULL, /* VFS: Delete inode from disk.
// Called when i_count becomes
// 0 and i_nlink is also 0. */
//.write_super = NULL, /* Flush dirty super block to
// disk. */
//.write_super_lockfs = NULL, /* ? */
//.unlockfs = NULL, /* ? */
#endif
.put_super = ntfs_put_super, /* Syscall: umount. */ .put_super = ntfs_put_super, /* Syscall: umount. */
//write_super = NULL, /* Flush dirty super block to disk. */
//write_super_lockfs = NULL, /* ? */
//unlockfs = NULL, /* ? */
.statfs = ntfs_statfs, /* Syscall: statfs */ .statfs = ntfs_statfs, /* Syscall: statfs */
.remount_fs = ntfs_remount, /* Syscall: mount -o remount. */ .remount_fs = ntfs_remount, /* Syscall: mount -o remount. */
.clear_inode = ntfs_clear_big_inode, /* VFS: Called when an inode is .clear_inode = ntfs_clear_big_inode, /* VFS: Called when an inode is
removed from memory. */ removed from memory. */
//.umount_begin = NULL, /* Forced umount. */ //.umount_begin = NULL, /* Forced umount. */
.show_options = ntfs_show_options, /* Show mount options in proc. */ .show_options = ntfs_show_options, /* Show mount options in
proc. */
}; };
......
/* /*
* time.c - NTFS time conversion functions. Part of the Linux-NTFS project. * time.h - NTFS time conversion functions. Part of the Linux-NTFS project.
* *
* Copyright (c) 2001 Anton Altaparmakov. * Copyright (c) 2001-2004 Anton Altaparmakov.
* *
* This program/include file is free software; you can redistribute it and/or * This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published * modify it under the terms of the GNU General Public License as published
...@@ -19,31 +19,40 @@ ...@@ -19,31 +19,40 @@
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <linux/sched.h> /* For CURRENT_TIME. */ #ifndef _LINUX_NTFS_TIME_H
#define _LINUX_NTFS_TIME_H
#include <linux/time.h> /* For current_kernel_time(). */
#include <asm/div64.h> /* For do_div(). */ #include <asm/div64.h> /* For do_div(). */
#include "ntfs.h" #include "endian.h"
#define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000) #define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000)
/** /**
* utc2ntfs - convert Linux time to NTFS time * utc2ntfs - convert Linux UTC time to NTFS time
* @time: Linux time to convert to NTFS * @ts: Linux UTC time to convert to NTFS time
* *
* Convert the Linux time @time to its corresponding NTFS time and return that * Convert the Linux UTC time @ts to its corresponding NTFS time and return
* in little endian format. * that in little endian format.
* *
* Linux stores time in a long at present and measures it as the number of * Linux stores time in a struct timespec consisting of a time_t (long at
* 1-second intervals since 1st January 1970, 00:00:00 UTC. * present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second
* intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of
* 1-nano-second intervals since the value of tv_sec.
* *
* NTFS uses Microsoft's standard time format which is stored in a s64 and is * NTFS uses Microsoft's standard time format which is stored in a s64 and is
* measured as the number of 100 nano-second intervals since 1st January 1601, * measured as the number of 100-nano-second intervals since 1st January 1601,
* 00:00:00 UTC. * 00:00:00 UTC.
*/ */
inline s64 utc2ntfs(const time_t time) static inline s64 utc2ntfs(const struct timespec ts)
{ {
/* Convert to 100ns intervals and then add the NTFS time offset. */ /*
return cpu_to_sle64((s64)time * 10000000 + NTFS_TIME_OFFSET); * Convert the seconds to 100ns intervals, add the nano-seconds
* converted to 100ns intervals, and then add the NTFS time offset.
*/
return cpu_to_sle64((s64)ts.tv_sec * 10000000 + ts.tv_nsec / 100 +
NTFS_TIME_OFFSET);
} }
/** /**
...@@ -52,31 +61,40 @@ inline s64 utc2ntfs(const time_t time) ...@@ -52,31 +61,40 @@ inline s64 utc2ntfs(const time_t time)
* Get the current time from the Linux kernel, convert it to its corresponding * Get the current time from the Linux kernel, convert it to its corresponding
* NTFS time and return that in little endian format. * NTFS time and return that in little endian format.
*/ */
inline s64 get_current_ntfs_time(void) static inline s64 get_current_ntfs_time(void)
{ {
/* ignores leap second */ return utc2ntfs(current_kernel_time());
return utc2ntfs(get_seconds()) + xtime.tv_nsec/1000;
} }
/** /**
* ntfs2utc - convert NTFS time to Linux time * ntfs2utc - convert NTFS time to Linux time
* @time: NTFS time (little endian) to convert to Linux * @time: NTFS time (little endian) to convert to Linux UTC
* *
* Convert the little endian NTFS time @time to its corresponding Linux time * Convert the little endian NTFS time @time to its corresponding Linux UTC
* and return that in cpu format. * time and return that in cpu format.
* *
* Linux stores time in a long at present and measures it as the number of * Linux stores time in a struct timespec consisting of a time_t (long at
* 1-second intervals since 1st January 1970, 00:00:00 UTC. * present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second
* intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of
* 1-nano-second intervals since the value of tv_sec.
* *
* NTFS uses Microsoft's standard time format which is stored in a s64 and is * NTFS uses Microsoft's standard time format which is stored in a s64 and is
* measured as the number of 100 nano-second intervals since 1st January 1601, * measured as the number of 100 nano-second intervals since 1st January 1601,
* 00:00:00 UTC. * 00:00:00 UTC.
*/ */
inline time_t ntfs2utc(const s64 time) static inline struct timespec ntfs2utc(const s64 time)
{ {
/* Subtract the NTFS time offset, then convert to 1s intervals. */ struct timespec ts;
/* Subtract the NTFS time offset. */
s64 t = sle64_to_cpu(time) - NTFS_TIME_OFFSET; s64 t = sle64_to_cpu(time) - NTFS_TIME_OFFSET;
do_div(t, 10000000); /*
return (time_t)t; * Convert the time to 1-second intervals and the remainder to
* 1-nano-second intervals.
*/
ts.tv_nsec = do_div(t, 10000000) * 100;
ts.tv_sec = t;
return ts;
} }
#endif /* _LINUX_NTFS_TIME_H */
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* volume.h - Defines for volume structures in NTFS Linux kernel driver. Part * volume.h - Defines for volume structures in NTFS Linux kernel driver. Part
* of the Linux-NTFS project. * of the Linux-NTFS project.
* *
* Copyright (c) 2001,2002 Anton Altaparmakov. * Copyright (c) 2001-2004 Anton Altaparmakov.
* Copyright (c) 2002 Richard Russon. * Copyright (c) 2002 Richard Russon.
* *
* This program/include file is free software; you can redistribute it and/or * This program/include file is free software; you can redistribute it and/or
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define _LINUX_NTFS_VOLUME_H #define _LINUX_NTFS_VOLUME_H
#include "types.h" #include "types.h"
#include "layout.h"
/* /*
* The NTFS in memory super block structure. * The NTFS in memory super block structure.
...@@ -83,13 +84,17 @@ typedef struct { ...@@ -83,13 +84,17 @@ typedef struct {
bits in mft bitmap. */ bits in mft bitmap. */
struct inode *mftmirr_ino; /* The VFS inode of $MFTMirr. */ struct inode *mftmirr_ino; /* The VFS inode of $MFTMirr. */
int mftmirr_size; /* Size of mft mirror in mft records. */
struct inode *lcnbmp_ino; /* The VFS inode of $Bitmap. */ struct inode *lcnbmp_ino; /* The VFS inode of $Bitmap. */
struct rw_semaphore lcnbmp_lock; /* Lock for serializing accesses to the struct rw_semaphore lcnbmp_lock; /* Lock for serializing accesses to the
cluster bitmap ($Bitmap/$DATA). */ cluster bitmap ($Bitmap/$DATA). */
struct inode *vol_ino; /* The VFS inode of $Volume. */ struct inode *vol_ino; /* The VFS inode of $Volume. */
unsigned long vol_flags; /* Volume flags (VOLUME_*). */ VOLUME_FLAGS vol_flags; /* Volume flags (VOLUME_*). */
u8 major_ver; /* Ntfs major version of volume. */ u8 major_ver; /* Ntfs major version of volume. */
u8 minor_ver; /* Ntfs minor version of volume. */ u8 minor_ver; /* Ntfs minor version of volume. */
struct inode *root_ino; /* The VFS inode of the root struct inode *root_ino; /* The VFS inode of the root
directory. */ directory. */
struct inode *secure_ino; /* The VFS inode of $Secure (NTFS3.0+ struct inode *secure_ino; /* The VFS inode of $Secure (NTFS3.0+
...@@ -133,4 +138,3 @@ NVOL_FNS(ShowSystemFiles) ...@@ -133,4 +138,3 @@ NVOL_FNS(ShowSystemFiles)
NVOL_FNS(CaseSensitive) NVOL_FNS(CaseSensitive)
#endif /* _LINUX_NTFS_VOLUME_H */ #endif /* _LINUX_NTFS_VOLUME_H */
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