Hi Linus, please do a
bk pull bk://linux-ntfs.bkbits.net/ntfs-2.6
This includes the (off-list) discussed NTFS sparse annotations, some other
cleanups and a fix for a bug found by the bitwise sparse annotations. (-:
Please apply. Thanks!
For the benefit of non-BK users and to make code review easier, I am
sending each ChangeSet in a separate email as a diff -u style patch.
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
This will update the following files:
Documentation/filesystems/ntfs.txt | 5
fs/ntfs/ChangeLog | 36 +
fs/ntfs/Makefile | 4
fs/ntfs/attrib.c | 9
fs/ntfs/attrib.h | 4
fs/ntfs/collate.c | 20
fs/ntfs/collate.h | 12
fs/ntfs/compress.c | 8
fs/ntfs/dir.c | 62 -
fs/ntfs/endian.h | 78 +-
fs/ntfs/index.c | 4
fs/ntfs/inode.c | 148 +++-
fs/ntfs/inode.h | 8
fs/ntfs/layout.h | 1216 ++++++++++++++++++-------------------
fs/ntfs/logfile.c | 8
fs/ntfs/logfile.h | 68 +-
fs/ntfs/mft.c | 12
fs/ntfs/mst.c | 23
fs/ntfs/ntfs.h | 2
fs/ntfs/quota.c | 2
fs/ntfs/super.c | 21
fs/ntfs/time.h | 6
fs/ntfs/types.h | 14
fs/ntfs/unistr.c | 12
fs/ntfs/upcase.c | 3
25 files changed, 961 insertions(+), 824 deletions(-)
through these ChangeSets:
<[email protected]> (04/09/22 1.1947)
NTFS: - Remove BKL use from ntfs_setattr() syncing up with the rest of the
kernel.
- Update ->setattr (fs/ntfs/inode.c::ntfs_setattr()) to refuse to
change the uid, gid, and mode of an inode as we do not support NTFS
ACLs yet.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/22 1.1948)
NTFS: Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
and ntfs_filldir() as per suggestion from Al Viro.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/22 1.1949)
NTFS: Improve the previous transparent union removal.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/23 1.1951)
NTFS: Change '\0' and L'\0' to simply 0 as per advice from Linus Torvalds.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/23 1.1952)
NTFS: - Update ->truncate (fs/ntfs/inode.c::ntfs_truncate()) to check if the
inode size has changed and to only output an error if so.
- Rename fs/ntfs/attrib.h::attribute_value_length() to ntfs_attr_size().
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/24 1.1952.1.1)
NTFS: Begin of sparse annotations: new data types and endianness conversion.
- Add le{16,32,64} as well as sle{16,32,64} data types to fs/ntfs/types.h.
- Change ntfschar to be le16 instead of u16 in fs/ntfs/types.h.
- Add le versions of VCN, LCN, and LSN called leVCN, leLCN, and leLSN,
respectively, to fs/ntfs/types.h.
- Update endianness conversion macros in fs/ntfs/endian.h to use the
new types as appropriate.
- Do proper type casting when using sle64_to_cpup() in fs/ntfs/dir.c
and index.c.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/24 1.1952.1.2)
NTFS: Continuing sparse annotations: finish data types and header files.
- Add leMFT_REF data type to fs/ntfs/layout.h.
- Update all NTFS header files with the new little endian data types.
Affected files are fs/ntfs/layout.h, logfile.h, and time.h.
- Do proper type casting when using ntfs_is_*_recordp() in
fs/ntfs/logfile.c, mft.c, and super.c.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/24 1.1952.1.3)
NTFS: Finish off sparse annotation.
- Fix all the sparse bitwise warnings. Had to change all the enums
storing little endian values to #defines because we cannot set enums
to be little endian so we had lots of bitwise warnings from sparse.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/24 1.1952.1.4)
NTFS: 2.1.19 - Many cleanups, improvements, and a minor bug fix.
- Fix bug found by the new sparse bitwise warnings where the default
upcase table was defined as a pointer to wchar_t rather than ntfschar
in fs/ntfs/ntfs.h and super.c.
Signed-off-by: Anton Altaparmakov <[email protected]>
<[email protected]> (04/09/24 1.1956)
NTFS: Fix a stupid bug where I forgot to actually do the attribute lookup
and then went and used the looked up attribute... Ooops.
Signed-off-by: Anton Altaparmakov <[email protected]>
This is patch 2/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/22 1.1948)
NTFS: Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
and ntfs_filldir() as per suggestion from Al Viro.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:05 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:05 +01:00
@@ -28,6 +28,8 @@
ACLs yet.
- Remove BKL use from ntfs_setattr() syncing up with the rest of the
kernel.
+ - Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
+ and ntfs_filldir() as per suggestion from Al Viro.
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
diff -Nru a/fs/ntfs/dir.c b/fs/ntfs/dir.c
--- a/fs/ntfs/dir.c 2004-09-24 17:06:05 +01:00
+++ b/fs/ntfs/dir.c 2004-09-24 17:06:05 +01:00
@@ -999,23 +999,11 @@
#endif
-typedef union {
- INDEX_ROOT *ir;
- INDEX_ALLOCATION *ia;
-} index_union __attribute__ ((__transparent_union__));
-
-typedef enum {
- INDEX_TYPE_ROOT, /* index root */
- INDEX_TYPE_ALLOCATION, /* index allocation */
-} INDEX_TYPE;
-
/**
* ntfs_filldir - ntfs specific filldir method
* @vol: current ntfs volume
* @fpos: position in the directory
* @ndir: ntfs inode of current directory
- * @index_type: specifies whether @iu is an index root or an index allocation
- * @iu: index root or index allocation attribute to which @ie belongs
* @ia_page: page in which the index allocation buffer @ie is in resides
* @ie: current index entry
* @name: buffer to use for the converted name
@@ -1036,8 +1024,7 @@
* would need to drop the lock immediately anyway.
*/
static inline int ntfs_filldir(ntfs_volume *vol, loff_t *fpos,
- ntfs_inode *ndir, const INDEX_TYPE index_type,
- index_union iu, struct page *ia_page, INDEX_ENTRY *ie,
+ ntfs_inode *ndir, struct page *ia_page, INDEX_ENTRY *ie,
u8 *name, void *dirent, filldir_t filldir)
{
unsigned long mref;
@@ -1045,14 +1032,6 @@
unsigned dt_type;
FILE_NAME_TYPE_FLAGS name_type;
- /* Advance the position even if going to skip the entry. */
- if (index_type == INDEX_TYPE_ALLOCATION)
- *fpos = (u8*)ie - (u8*)iu.ia +
- (sle64_to_cpu(iu.ia->index_block_vcn) <<
- ndir->itype.index.vcn_size_bits) +
- vol->mft_record_size;
- else /* if (index_type == INDEX_TYPE_ROOT) */
- *fpos = (u8*)ie - (u8*)iu.ir;
name_type = ie->key.file_name.file_name_type;
if (name_type == FILE_NAME_DOS) {
ntfs_debug("Skipping DOS name space entry.");
@@ -1084,14 +1063,14 @@
* Drop the page lock otherwise we deadlock with NFS when it calls
* ->lookup since ntfs_lookup() will lock the same page.
*/
- if (index_type == INDEX_TYPE_ALLOCATION)
+ if (ia_page)
unlock_page(ia_page);
ntfs_debug("Calling filldir for %s with len %i, fpos 0x%llx, inode "
"0x%lx, DT_%s.", name, name_len, *fpos, mref,
dt_type == DT_DIR ? "DIR" : "REG");
rc = filldir(dirent, name, name_len, *fpos, mref, dt_type);
/* Relock the page but not if we are aborting ->readdir. */
- if (!rc && index_type == INDEX_TYPE_ALLOCATION)
+ if (!rc && ia_page)
lock_page(ia_page);
return rc;
}
@@ -1244,9 +1223,11 @@
/* Skip index root entry if continuing previous readdir. */
if (ir_pos > (u8*)ie - (u8*)ir)
continue;
+ /* Advance the position even if going to skip the entry. */
+ fpos = (u8*)ie - (u8*)ir;
/* Submit the name to the filldir callback. */
- rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ROOT, ir, NULL,
- ie, name, dirent, filldir);
+ rc = ntfs_filldir(vol, &fpos, ndir, NULL, ie, name, dirent,
+ filldir);
if (rc) {
kfree(ir);
goto abort;
@@ -1420,14 +1401,19 @@
/* Skip index block entry if continuing previous readdir. */
if (ia_pos - ia_start > (u8*)ie - (u8*)ia)
continue;
+ /* Advance the position even if going to skip the entry. */
+ fpos = (u8*)ie - (u8*)ia +
+ (sle64_to_cpu(ia->index_block_vcn) <<
+ ndir->itype.index.vcn_size_bits) +
+ vol->mft_record_size;
/*
* Submit the name to the @filldir callback. Note,
* ntfs_filldir() drops the lock on @ia_page but it retakes it
* before returning, unless a non-zero value is returned in
* which case the page is left unlocked.
*/
- rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ALLOCATION, ia,
- ia_page, ie, name, dirent, filldir);
+ rc = ntfs_filldir(vol, &fpos, ndir, ia_page, ie, name, dirent,
+ filldir);
if (rc) {
/* @ia_page is already unlocked in this case. */
ntfs_unmap_page(ia_page);
This is patch 1/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/22 1.1947)
NTFS: - Remove BKL use from ntfs_setattr() syncing up with the rest of the
kernel.
- Update ->setattr (fs/ntfs/inode.c::ntfs_setattr()) to refuse to
change the uid, gid, and mode of an inode as we do not support NTFS
ACLs yet.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:01 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:01 +01:00
@@ -21,6 +21,14 @@
- Enable the code for setting the NT4 compatibility flag when we start
making NTFS 1.2 specific modifications.
+2.1.19-WIP
+
+ - Update ->setattr (fs/ntfs/inode.c::ntfs_setattr()) to refuse to
+ change the uid, gid, and mode of an inode as we do not support NTFS
+ ACLs yet.
+ - Remove BKL use from ntfs_setattr() syncing up with the rest of the
+ kernel.
+
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
- Remove vol->nr_mft_records as it was pretty meaningless and optimize
diff -Nru a/fs/ntfs/Makefile b/fs/ntfs/Makefile
--- a/fs/ntfs/Makefile 2004-09-24 17:06:01 +01:00
+++ b/fs/ntfs/Makefile 2004-09-24 17:06:01 +01:00
@@ -6,7 +6,7 @@
index.o inode.o mft.o mst.o namei.o super.o sysctl.o unistr.o \
upcase.o
-EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.18\"
+EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.19-WIP\"
ifeq ($(CONFIG_NTFS_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
diff -Nru a/fs/ntfs/inode.c b/fs/ntfs/inode.c
--- a/fs/ntfs/inode.c 2004-09-24 17:06:01 +01:00
+++ b/fs/ntfs/inode.c 2004-09-24 17:06:01 +01:00
@@ -2270,7 +2270,11 @@
*
* We don't support i_size changes yet.
*
- * Called with ->i_sem held.
+ * Called with ->i_sem held. In all but one case ->i_alloc_sem is held for
+ * writing. The only case where ->i_alloc_sem is not held is
+ * mm/filemap.c::generic_file_buffered_write() where vmtruncate() is called
+ * with the current i_size as the offset which means that it is a noop as far
+ * as ntfs_truncate() is concerned.
*/
void ntfs_truncate(struct inode *vi)
{
@@ -2289,67 +2293,62 @@
* @attr: structure describing the attributes and the changes
*
* We have to trap VFS attempts to truncate the file described by @dentry as
- * soon as possible, because we do not implement changes in i_size yet. So we
+ * soon as possible, because we do not implement changes in i_size yet. So we
* abort all i_size changes here.
*
- * Called with ->i_sem held.
+ * We also abort all changes of user, group, and mode as we do not implement
+ * the NTFS ACLs yet.
+ *
+ * Called with ->i_sem held. For the ATTR_SIZE (i.e. ->truncate) case, also
+ * called with ->i_alloc_sem held for writing.
*
* Basically this is a copy of generic notify_change() and inode_setattr()
* functionality, except we intercept and abort changes in i_size.
*/
int ntfs_setattr(struct dentry *dentry, struct iattr *attr)
{
- struct inode *vi;
+ struct inode *vi = dentry->d_inode;
int err;
unsigned int ia_valid = attr->ia_valid;
- vi = dentry->d_inode;
-
err = inode_change_ok(vi, attr);
if (err)
return err;
- if ((ia_valid & ATTR_UID && attr->ia_uid != vi->i_uid) ||
- (ia_valid & ATTR_GID && attr->ia_gid != vi->i_gid)) {
- err = DQUOT_TRANSFER(vi, attr) ? -EDQUOT : 0;
- if (err)
- return err;
+ /* We do not support NTFS ACLs yet. */
+ if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE)) {
+ ntfs_warning(vi->i_sb, "Changes in user/group/mode are not "
+ "supported yet, ignoring.");
+ err = -EOPNOTSUPP;
+ goto out;
}
- lock_kernel();
-
if (ia_valid & ATTR_SIZE) {
- ntfs_error(vi->i_sb, "Changes in i_size are not supported "
- "yet. Sorry.");
- // TODO: Implement...
- // err = vmtruncate(vi, attr->ia_size);
- err = -EOPNOTSUPP;
- if (err)
- goto trunc_err;
+ if (attr->ia_size != i_size_read(vi)) {
+ ntfs_warning(vi->i_sb, "Changes in inode size are not "
+ "supported yet, ignoring.");
+ err = -EOPNOTSUPP;
+ // TODO: Implement...
+ // err = vmtruncate(vi, attr->ia_size);
+ if (err || ia_valid == ATTR_SIZE)
+ goto out;
+ } else {
+ /*
+ * We skipped the truncate but must still update
+ * timestamps.
+ */
+ ia_valid |= ATTR_MTIME|ATTR_CTIME;
+ }
}
- if (ia_valid & ATTR_UID)
- vi->i_uid = attr->ia_uid;
- if (ia_valid & ATTR_GID)
- vi->i_gid = attr->ia_gid;
if (ia_valid & ATTR_ATIME)
vi->i_atime = attr->ia_atime;
if (ia_valid & ATTR_MTIME)
vi->i_mtime = attr->ia_mtime;
if (ia_valid & ATTR_CTIME)
vi->i_ctime = attr->ia_ctime;
- if (ia_valid & ATTR_MODE) {
- vi->i_mode = attr->ia_mode;
- if (!in_group_p(vi->i_gid) &&
- !capable(CAP_FSETID))
- vi->i_mode &= ~S_ISGID;
- }
mark_inode_dirty(vi);
-
-trunc_err:
-
- unlock_kernel();
-
+out:
return err;
}
This is patch 6/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/24 1.1952.1.1)
NTFS: Begin of sparse annotations: new data types and endianness conversion.
- Add le{16,32,64} as well as sle{16,32,64} data types to fs/ntfs/types.h.
- Change ntfschar to be le16 instead of u16 in fs/ntfs/types.h.
- Add le versions of VCN, LCN, and LSN called leVCN, leLCN, and leLSN,
respectively, to fs/ntfs/types.h.
- Update endianness conversion macros in fs/ntfs/endian.h to use the
new types as appropriate.
- Do proper type casting when using sle64_to_cpup() in fs/ntfs/dir.c
and index.c.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:20 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:20 +01:00
@@ -34,6 +34,15 @@
- Update ->truncate (fs/ntfs/inode.c::ntfs_truncate()) to check if the
inode size has changed and to only output an error if so.
- Rename fs/ntfs/attrib.h::attribute_value_length() to ntfs_attr_size().
+ - Add le{16,32,64} as well as sle{16,32,64} data types to
+ fs/ntfs/types.h.
+ - Change ntfschar to be le16 instead of u16 in fs/ntfs/types.h.
+ - Add le versions of VCN, LCN, and LSN called leVCN, leLCN, and leLSN,
+ respectively, to fs/ntfs/types.h.
+ - Update endianness conversion macros in fs/ntfs/endian.h to use the
+ new types as appropriate.
+ - Do proper type casting when using sle64_to_cpup() in fs/ntfs/dir.c
+ and index.c.
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
diff -Nru a/fs/ntfs/dir.c b/fs/ntfs/dir.c
--- a/fs/ntfs/dir.c 2004-09-24 17:06:20 +01:00
+++ b/fs/ntfs/dir.c 2004-09-24 17:06:20 +01:00
@@ -299,7 +299,7 @@
goto err_out;
}
/* Get the starting vcn of the index_block holding the child node. */
- vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
+ vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
ia_mapping = VFS_I(dir_ni)->i_mapping;
/*
* We are done with the index root and the mft record. Release them,
@@ -551,7 +551,8 @@
}
/* Child node present, descend into it. */
old_vcn = vcn;
- vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
+ vcn = sle64_to_cpup((sle64*)((u8*)ie +
+ le16_to_cpu(ie->length) - 8));
if (vcn >= 0) {
/* If vcn is in the same page cache page as old_vcn we
* recycle the mapped page. */
diff -Nru a/fs/ntfs/endian.h b/fs/ntfs/endian.h
--- a/fs/ntfs/endian.h 2004-09-24 17:06:20 +01:00
+++ b/fs/ntfs/endian.h 2004-09-24 17:06:20 +01:00
@@ -24,24 +24,70 @@
#define _LINUX_NTFS_ENDIAN_H
#include <asm/byteorder.h>
+#include "types.h"
/*
- * Signed endianness conversion defines.
+ * Signed endianness conversion functions.
*/
-#define sle16_to_cpu(x) ((s16)__le16_to_cpu((s16)(x)))
-#define sle32_to_cpu(x) ((s32)__le32_to_cpu((s32)(x)))
-#define sle64_to_cpu(x) ((s64)__le64_to_cpu((s64)(x)))
-
-#define sle16_to_cpup(x) ((s16)__le16_to_cpu(*(s16*)(x)))
-#define sle32_to_cpup(x) ((s32)__le32_to_cpu(*(s32*)(x)))
-#define sle64_to_cpup(x) ((s64)__le64_to_cpu(*(s64*)(x)))
-
-#define cpu_to_sle16(x) ((s16)__cpu_to_le16((s16)(x)))
-#define cpu_to_sle32(x) ((s32)__cpu_to_le32((s32)(x)))
-#define cpu_to_sle64(x) ((s64)__cpu_to_le64((s64)(x)))
-
-#define cpu_to_sle16p(x) ((s16)__cpu_to_le16(*(s16*)(x)))
-#define cpu_to_sle32p(x) ((s32)__cpu_to_le32(*(s32*)(x)))
-#define cpu_to_sle64p(x) ((s64)__cpu_to_le64(*(s64*)(x)))
+
+static inline s16 sle16_to_cpu(sle16 x)
+{
+ return le16_to_cpu((__force le16)x);
+}
+
+static inline s32 sle32_to_cpu(sle32 x)
+{
+ return le32_to_cpu((__force le32)x);
+}
+
+static inline s64 sle64_to_cpu(sle64 x)
+{
+ return le64_to_cpu((__force le64)x);
+}
+
+static inline s16 sle16_to_cpup(sle16 *x)
+{
+ return le16_to_cpu(*(__force le16*)x);
+}
+
+static inline s32 sle32_to_cpup(sle32 *x)
+{
+ return le32_to_cpu(*(__force le32*)x);
+}
+
+static inline s64 sle64_to_cpup(sle64 *x)
+{
+ return le64_to_cpu(*(__force le64*)x);
+}
+
+static inline sle16 cpu_to_sle16(s16 x)
+{
+ return (__force sle16)cpu_to_le16(x);
+}
+
+static inline sle32 cpu_to_sle32(s32 x)
+{
+ return (__force sle32)cpu_to_le32(x);
+}
+
+static inline sle64 cpu_to_sle64(s64 x)
+{
+ return (__force sle64)cpu_to_le64(x);
+}
+
+static inline sle16 cpu_to_sle16p(s16 *x)
+{
+ return (__force sle16)cpu_to_le16(*x);
+}
+
+static inline sle32 cpu_to_sle32p(s32 *x)
+{
+ return (__force sle32)cpu_to_le32(*x);
+}
+
+static inline sle64 cpu_to_sle64p(s64 *x)
+{
+ return (__force sle64)cpu_to_le64(*x);
+}
#endif /* _LINUX_NTFS_ENDIAN_H */
diff -Nru a/fs/ntfs/index.c b/fs/ntfs/index.c
--- a/fs/ntfs/index.c 2004-09-24 17:06:20 +01:00
+++ b/fs/ntfs/index.c 2004-09-24 17:06:20 +01:00
@@ -265,7 +265,7 @@
goto err_out;
}
/* Get the starting vcn of the index_block holding the child node. */
- vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
+ vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
ia_mapping = VFS_I(idx_ni)->i_mapping;
/*
* We are done with the index root and the mft record. Release them,
@@ -427,7 +427,7 @@
}
/* Child node present, descend into it. */
old_vcn = vcn;
- vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
+ vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
if (vcn >= 0) {
/*
* If vcn is in the same page cache page as old_vcn we recycle
diff -Nru a/fs/ntfs/types.h b/fs/ntfs/types.h
--- a/fs/ntfs/types.h 2004-09-24 17:06:20 +01:00
+++ b/fs/ntfs/types.h 2004-09-24 17:06:20 +01:00
@@ -23,8 +23,17 @@
#ifndef _LINUX_NTFS_TYPES_H
#define _LINUX_NTFS_TYPES_H
+#include <linux/types.h>
+
+typedef __le16 le16;
+typedef __le32 le32;
+typedef __le64 le64;
+typedef __u16 __bitwise sle16;
+typedef __u32 __bitwise sle32;
+typedef __u64 __bitwise sle64;
+
/* 2-byte Unicode character type. */
-typedef u16 ntfschar;
+typedef le16 ntfschar;
#define UCHAR_T_SIZE_BITS 1
/*
@@ -32,7 +41,9 @@
* and VCN, to allow for type checking and better code readability.
*/
typedef s64 VCN;
+typedef sle64 leVCN;
typedef s64 LCN;
+typedef sle64 leLCN;
/*
* The NTFS journal $LogFile uses log sequence numbers which are signed 64-bit
@@ -40,6 +51,7 @@
* code readability.
*/
typedef s64 LSN;
+typedef sle64 leLSN;
/**
* runlist_element - in memory vcn to lcn mapping array element
This is patch 4/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/23 1.1951)
NTFS: Change '\0' and L'\0' to simply 0 as per advice from Linus Torvalds.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:12 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:12 +01:00
@@ -30,6 +30,7 @@
kernel.
- Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
and ntfs_filldir() as per suggestion from Al Viro.
+ - Change '\0' and L'\0' to simply 0 as per advice from Linus Torvalds.
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
diff -Nru a/fs/ntfs/inode.c b/fs/ntfs/inode.c
--- a/fs/ntfs/inode.c 2004-09-24 17:06:12 +01:00
+++ b/fs/ntfs/inode.c 2004-09-24 17:06:12 +01:00
@@ -130,7 +130,7 @@
if (!ni->name)
return -ENOMEM;
memcpy(ni->name, na->name, i);
- ni->name[i] = cpu_to_le16(L'\0');
+ ni->name[i] = cpu_to_le16(0);
}
return 0;
}
@@ -2270,6 +2270,12 @@
*
* We don't support i_size changes yet.
*
+ * The kernel guarantees that @vi is a regular file (S_ISREG() is true) and
+ * that the change is allowed.
+ *
+ * This implies for us that @vi is a file inode rather than a directory, index,
+ * or attribute inode as well as that @vi is a base inode.
+ *
* Called with ->i_sem held. In all but one case ->i_alloc_sem is held for
* writing. The only case where ->i_alloc_sem is not held is
* mm/filemap.c::generic_file_buffered_write() where vmtruncate() is called
@@ -2279,10 +2285,10 @@
void ntfs_truncate(struct inode *vi)
{
// TODO: Implement...
- ntfs_warning(vi->i_sb, "Eeek: i_size may have changed! If you see "
+ ntfs_warning(vi->i_sb, "Eeek: i_size may have changed! If you see "
"this right after a message from "
- "ntfs_{prepare,commit}_{,nonresident_}write() then "
- "just ignore it. Otherwise it is bad news.");
+ "ntfs_prepare_{,nonresident_}write() then just ignore "
+ "it. Otherwise it is bad news.");
// TODO: reset i_size now!
return;
}
diff -Nru a/fs/ntfs/super.c b/fs/ntfs/super.c
--- a/fs/ntfs/super.c 2004-09-24 17:06:12 +01:00
+++ b/fs/ntfs/super.c 2004-09-24 17:06:12 +01:00
@@ -145,7 +145,7 @@
ntfs_debug("Entering with mount options string: %s", opt);
while ((p = strsep(&opt, ","))) {
if ((v = strchr(p, '=')))
- *v++ = '\0';
+ *v++ = 0;
NTFS_GETOPT("uid", uid)
else NTFS_GETOPT("gid", gid)
else NTFS_GETOPT("umask", fmask = dmask)
diff -Nru a/fs/ntfs/unistr.c b/fs/ntfs/unistr.c
--- a/fs/ntfs/unistr.c 2004-09-24 17:06:12 +01:00
+++ b/fs/ntfs/unistr.c 2004-09-24 17:06:12 +01:00
@@ -276,7 +276,7 @@
} /* else (wc_len < 0) */
goto conversion_err;
}
- ucs[o] = cpu_to_le16('\0');
+ ucs[o] = cpu_to_le16(0);
*outs = ucs;
return o;
} /* else (!ucs) */
@@ -362,7 +362,7 @@
} /* wc < 0, real error. */
goto conversion_err;
}
- ns[o] = '\0';
+ ns[o] = 0;
*outs = ns;
return o;
} /* else (!ins) */
This is patch 5/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/23 1.1952)
NTFS: - Update ->truncate (fs/ntfs/inode.c::ntfs_truncate()) to check if the
inode size has changed and to only output an error if so.
- Rename fs/ntfs/attrib.h::attribute_value_length() to ntfs_attr_size().
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:16 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:16 +01:00
@@ -31,6 +31,9 @@
- Get rid of the ugly transparent union in fs/ntfs/dir.c::ntfs_readdir()
and ntfs_filldir() as per suggestion from Al Viro.
- Change '\0' and L'\0' to simply 0 as per advice from Linus Torvalds.
+ - Update ->truncate (fs/ntfs/inode.c::ntfs_truncate()) to check if the
+ inode size has changed and to only output an error if so.
+ - Rename fs/ntfs/attrib.h::attribute_value_length() to ntfs_attr_size().
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
diff -Nru a/fs/ntfs/attrib.h b/fs/ntfs/attrib.h
--- a/fs/ntfs/attrib.h 2004-09-24 17:06:16 +01:00
+++ b/fs/ntfs/attrib.h 2004-09-24 17:06:16 +01:00
@@ -89,7 +89,7 @@
extern int load_attribute_list(ntfs_volume *vol, runlist *rl, u8 *al_start,
const s64 size, const s64 initialized_size);
-static inline s64 attribute_value_length(const ATTR_RECORD *a)
+static inline s64 ntfs_attr_size(const ATTR_RECORD *a)
{
if (!a->non_resident)
return (s64)le32_to_cpu(a->data.resident.value_length);
diff -Nru a/fs/ntfs/inode.c b/fs/ntfs/inode.c
--- a/fs/ntfs/inode.c 2004-09-24 17:06:16 +01:00
+++ b/fs/ntfs/inode.c 2004-09-24 17:06:16 +01:00
@@ -680,7 +680,7 @@
goto unm_err_out;
}
/* Now allocate memory for the attribute list. */
- ni->attr_list_size = (u32)attribute_value_length(ctx->attr);
+ ni->attr_list_size = (u32)ntfs_attr_size(ctx->attr);
ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size);
if (!ni->attr_list) {
ntfs_error(vi->i_sb, "Not enough memory to allocate "
@@ -1794,7 +1794,7 @@
goto put_err_out;
}
/* Now allocate memory for the attribute list. */
- ni->attr_list_size = (u32)attribute_value_length(ctx->attr);
+ ni->attr_list_size = (u32)ntfs_attr_size(ctx->attr);
ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size);
if (!ni->attr_list) {
ntfs_error(sb, "Not enough memory to allocate buffer "
@@ -2284,12 +2284,38 @@
*/
void ntfs_truncate(struct inode *vi)
{
- // TODO: Implement...
- ntfs_warning(vi->i_sb, "Eeek: i_size may have changed! If you see "
- "this right after a message from "
- "ntfs_prepare_{,nonresident_}write() then just ignore "
- "it. Otherwise it is bad news.");
- // TODO: reset i_size now!
+ ntfs_inode *ni = NTFS_I(vi);
+ ntfs_attr_search_ctx *ctx;
+ MFT_RECORD *m;
+
+ m = map_mft_record(ni);
+ if (IS_ERR(m)) {
+ ntfs_error(vi->i_sb, "Failed to map mft record for inode 0x%lx "
+ "(error code %ld).", vi->i_ino, PTR_ERR(m));
+ if (PTR_ERR(m) != ENOMEM)
+ make_bad_inode(vi);
+ return;
+ }
+ ctx = ntfs_attr_get_search_ctx(ni, m);
+ if (unlikely(!ctx)) {
+ ntfs_error(vi->i_sb, "Failed to allocate a search context: "
+ "Not enough memory");
+ // FIXME: We can't report an error code upstream. So what do
+ // we do?!? make_bad_inode() seems a bit harsh...
+ unmap_mft_record(ni);
+ goto out;
+ }
+ /* If the size has not changed there is nothing to do. */
+ if (ntfs_attr_size(ctx->attr) == i_size_read(vi))
+ goto out;
+ // TODO: Implement the truncate...
+ ntfs_error(vi->i_sb, "Inode size has changed but this is not "
+ "implemented yet. Resetting inode size to old value. "
+ " This is most likely a bug in the ntfs driver!");
+ i_size_write(vi, ntfs_attr_size(ctx->attr));
+out:
+ ntfs_attr_put_search_ctx(ctx);
+ unmap_mft_record(ni);
return;
}
This is patch 7/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/24 1.1952.1.2)
NTFS: Continuing sparse annotations: finish data types and header files.
- Add leMFT_REF data type to fs/ntfs/layout.h.
- Update all NTFS header files with the new little endian data types.
Affected files are fs/ntfs/layout.h, logfile.h, and time.h.
- Do proper type casting when using ntfs_is_*_recordp() in
fs/ntfs/logfile.c, mft.c, and super.c.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:23 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:23 +01:00
@@ -43,6 +43,11 @@
new types as appropriate.
- Do proper type casting when using sle64_to_cpup() in fs/ntfs/dir.c
and index.c.
+ - Add leMFT_REF data type to fs/ntfs/layout.h.
+ - Update all NTFS header files with the new little endian data types.
+ Affected files are fs/ntfs/layout.h, logfile.h, and time.h.
+ - Do proper type casting when using ntfs_is_*_recordp() in
+ fs/ntfs/logfile.c, mft.c, and super.c.
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
diff -Nru a/fs/ntfs/layout.h b/fs/ntfs/layout.h
--- a/fs/ntfs/layout.h 2004-09-24 17:06:23 +01:00
+++ b/fs/ntfs/layout.h 2004-09-24 17:06:23 +01:00
@@ -60,18 +60,18 @@
* BIOS parameter block (bpb) structure.
*/
typedef struct {
- u16 bytes_per_sector; /* Size of a sector in bytes. */
+ le16 bytes_per_sector; /* Size of a sector in bytes. */
u8 sectors_per_cluster; /* Size of a cluster in sectors. */
- u16 reserved_sectors; /* zero */
+ le16 reserved_sectors; /* zero */
u8 fats; /* zero */
- u16 root_entries; /* zero */
- u16 sectors; /* zero */
+ le16 root_entries; /* zero */
+ le16 sectors; /* zero */
u8 media_type; /* 0xf8 = hard disk */
- u16 sectors_per_fat; /* zero */
- u16 sectors_per_track; /* irrelevant */
- u16 heads; /* irrelevant */
- u32 hidden_sectors; /* zero */
- u32 large_sectors; /* zero */
+ le16 sectors_per_fat; /* zero */
+ le16 sectors_per_track; /* irrelevant */
+ le16 heads; /* irrelevant */
+ le32 hidden_sectors; /* zero */
+ le32 large_sectors; /* zero */
} __attribute__ ((__packed__)) BIOS_PARAMETER_BLOCK;
/*
@@ -79,7 +79,7 @@
*/
typedef struct {
u8 jump[3]; /* Irrelevant (jump to boot up code).*/
- u64 oem_id; /* Magic "NTFS ". */
+ le64 oem_id; /* Magic "NTFS ". */
BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */
u8 unused[4]; /* zero, NTFS diskedit.exe states that
this is actually:
@@ -89,21 +89,21 @@
// 0x80
__u8 unused; // zero
*/
-/*0x28*/s64 number_of_sectors; /* Number of sectors in volume. Gives
+/*0x28*/sle64 number_of_sectors; /* Number of sectors in volume. Gives
maximum volume size of 2^63 sectors.
Assuming standard sector size of 512
bytes, the maximum byte size is
approx. 4.7x10^21 bytes. (-; */
- s64 mft_lcn; /* Cluster location of mft data. */
- s64 mftmirr_lcn; /* Cluster location of copy of mft. */
+ sle64 mft_lcn; /* Cluster location of mft data. */
+ sle64 mftmirr_lcn; /* Cluster location of copy of mft. */
s8 clusters_per_mft_record; /* Mft record size in clusters. */
u8 reserved0[3]; /* zero */
s8 clusters_per_index_record; /* Index block size in clusters. */
u8 reserved1[3]; /* zero */
- u64 volume_serial_number; /* Irrelevant (serial number). */
- u32 checksum; /* Boot sector checksum. */
+ le64 volume_serial_number; /* Irrelevant (serial number). */
+ le32 checksum; /* Boot sector checksum. */
/*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */
- u16 end_of_sector_marker; /* End of bootsector magic. Always is
+ le16 end_of_sector_marker; /* End of bootsector magic. Always is
0xaa55 in little endian. */
/* sizeof() = 512 (0x200) bytes */
} __attribute__ ((__packed__)) NTFS_BOOT_SECTOR;
@@ -143,57 +143,67 @@
* Generic magic comparison macros. Finally found a use for the ## preprocessor
* operator! (-8
*/
-#define ntfs_is_magic(x, m) ( (u32)(x) == magic_##m )
-#define ntfs_is_magicp(p, m) ( *(u32*)(p) == magic_##m )
+
+static inline BOOL __ntfs_is_magic(le32 x, NTFS_RECORD_TYPES r)
+{
+ return (x == (__force le32)r);
+}
+#define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m)
+
+static inline BOOL __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPES r)
+{
+ return (*p == (__force le32)r);
+}
+#define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m)
/*
* Specialised magic comparison macros for the NTFS_RECORD_TYPES defined above.
*/
-#define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) )
-#define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) )
-#define ntfs_is_mft_record(x) ( ntfs_is_file_record(x) )
-#define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) )
-#define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) )
-#define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) )
-#define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) )
-#define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) )
-
-#define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) )
-#define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) )
-#define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) )
-#define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) )
+#define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) )
+#define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) )
+#define ntfs_is_mft_record(x) ( ntfs_is_file_record (x) )
+#define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) )
+#define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) )
+#define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) )
+#define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) )
+#define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) )
+
+#define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) )
+#define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) )
+#define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) )
+#define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) )
-#define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) )
-#define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) )
+#define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) )
+#define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) )
-#define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) )
-#define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) )
+#define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) )
+#define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) )
#define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) )
#define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) )
/*
- * The Update Sequence Array (usa) is an array of the u16 values which belong
+ * The Update Sequence Array (usa) is an array of the le16 values which belong
* to the end of each sector protected by the update sequence record in which
* this array is contained. Note that the first entry is the Update Sequence
* Number (usn), a cyclic counter of how many times the protected record has
* been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All
- * last u16's of each sector have to be equal to the usn (during reading) or
+ * last le16's of each sector have to be equal to the usn (during reading) or
* are set to it (during writing). If they are not, an incomplete multi sector
* transfer has occurred when the data was written.
* The maximum size for the update sequence array is fixed to:
* maximum size = usa_ofs + (usa_count * 2) = 510 bytes
- * The 510 bytes comes from the fact that the last u16 in the array has to
- * (obviously) finish before the last u16 of the first 512-byte sector.
+ * The 510 bytes comes from the fact that the last le16 in the array has to
+ * (obviously) finish before the last le16 of the first 512-byte sector.
* This formula can be used as a consistency check in that usa_ofs +
* (usa_count * 2) has to be less than or equal to 510.
*/
typedef struct {
NTFS_RECORD_TYPES magic; /* A four-byte magic identifying the
record type and/or status. */
- u16 usa_ofs; /* Offset to the Update Sequence Array (usa)
+ le16 usa_ofs; /* Offset to the Update Sequence Array (usa)
from the start of the ntfs record. */
- u16 usa_count; /* Number of u16 sized entries in the usa
+ le16 usa_count; /* Number of le16 sized entries in the usa
including the Update Sequence Number (usn),
thus the number of fixups is the usa_count
minus 1. */
@@ -305,6 +315,7 @@
} MFT_REF_CONSTS;
typedef u64 MFT_REF;
+typedef le64 leMFT_REF;
#define MREF(x) ((unsigned long)((x) & MFT_REF_MASK_CPU))
#define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff))
@@ -326,17 +337,17 @@
/*Ofs*/
/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */
- u16 usa_ofs; /* See NTFS_RECORD definition above. */
- u16 usa_count; /* See NTFS_RECORD definition above. */
+ le16 usa_ofs; /* See NTFS_RECORD definition above. */
+ le16 usa_count; /* See NTFS_RECORD definition above. */
-/* 8*/ u64 lsn; /* $LogFile sequence number for this record.
+/* 8*/ le64 lsn; /* $LogFile sequence number for this record.
Changed every time the record is modified. */
-/* 16*/ u16 sequence_number; /* Number of times this mft record has been
+/* 16*/ le16 sequence_number; /* Number of times this mft record has been
reused. (See description for MFT_REF
above.) NOTE: The increment (skipping zero)
is done when the file is deleted. NOTE: If
this is zero it is left zero. */
-/* 18*/ u16 link_count; /* Number of hard links, i.e. the number of
+/* 18*/ le16 link_count; /* Number of hard links, i.e. the number of
directory entries referencing this record.
NOTE: Only used in mft base records.
NOTE: When deleting a directory entry we
@@ -346,18 +357,18 @@
directory entry from the mft record and
decrement the link_count.
FIXME: Careful with Win32 + DOS names! */
-/* 20*/ u16 attrs_offset; /* Byte offset to the first attribute in this
+/* 20*/ le16 attrs_offset; /* Byte offset to the first attribute in this
mft record from the start of the mft record.
NOTE: Must be aligned to 8-byte boundary. */
/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file
is deleted, the MFT_RECORD_IN_USE flag is
set to zero. */
-/* 24*/ u32 bytes_in_use; /* Number of bytes used in this mft record.
+/* 24*/ le32 bytes_in_use; /* Number of bytes used in this mft record.
NOTE: Must be aligned to 8-byte boundary. */
-/* 28*/ u32 bytes_allocated; /* Number of bytes allocated for this mft
+/* 28*/ le32 bytes_allocated; /* Number of bytes allocated for this mft
record. This should be equal to the mft
record size. */
-/* 32*/ MFT_REF base_mft_record; /* This is zero for base mft records.
+/* 32*/ leMFT_REF base_mft_record;/* This is zero for base mft records.
When it is not zero it is a mft reference
pointing to the base mft record to which
this record belongs (this is then used to
@@ -369,17 +380,16 @@
attribute list also means finding the other
potential extents, belonging to the non-base
mft record). */
-/* 40*/ u16 next_attr_instance; /* The instance number that will be
- assigned to the next attribute added to this
- mft record. NOTE: Incremented each time
- after it is used. NOTE: Every time the mft
- record is reused this number is set to zero.
- NOTE: The first instance number is always 0.
- */
+/* 40*/ le16 next_attr_instance;/* The instance number that will be assigned to
+ the next attribute added to this mft record.
+ NOTE: Incremented each time after it is used.
+ NOTE: Every time the mft record is reused
+ this number is set to zero. NOTE: The first
+ instance number is always 0. */
/* sizeof() = 42 bytes */
/* NTFS 3.1+ (Windows XP and above) introduce the following additions. */
-/* 42*/ //u16 reserved; /* Reserved/alignment. */
-/* 44*/ //u32 mft_record_number;/* Number of this mft record. */
+/* 42*/ //le16 reserved; /* Reserved/alignment. */
+/* 44*/ //le32 mft_record_number;/* Number of this mft record. */
/* sizeof() = 48 bytes */
/*
* When (re)using the mft record, we place the update sequence array at this
@@ -435,28 +445,28 @@
* unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[]
* for what I mean but COLLATION_UNICODE_STRING would not give any special
* treatment to any characters at all, but this is speculation.
- * COLLATION_NTOFS_ULONG - Sorting is done according to ascending u32 key
+ * COLLATION_NTOFS_ULONG - Sorting is done according to ascending le32 key
* values. E.g. used for $SII index in FILE_Secure, which sorts by
- * security_id (u32).
+ * security_id (le32).
* COLLATION_NTOFS_SID - Sorting is done according to ascending SID values.
* E.g. used for $O index in FILE_Extend/$Quota.
* COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash
* values and second by ascending security_id values. E.g. used for $SDH
* index in FILE_Secure.
* COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending
- * u32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which
+ * le32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which
* sorts by object_id (16-byte), by splitting up the object_id in four
- * u32 values and using them as individual keys. E.g. take the following
+ * le32 values and using them as individual keys. E.g. take the following
* two security_ids, stored as follows on disk:
* 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59
* 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45
- * To compare them, they are split into four u32 values each, like so:
+ * To compare them, they are split into four le32 values each, like so:
* 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081
* 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179
* Now, it is apparent why the 2nd object_id collates after the 1st: the
- * first u32 value of the 1st object_id is less than the first u32 of
- * the 2nd object_id. If the first u32 values of both object_ids were
- * equal then the second u32 values would be compared, etc.
+ * first le32 value of the 1st object_id is less than the first le32 of
+ * the 2nd object_id. If the first le32 values of both object_ids were
+ * equal then the second le32 values would be compared, etc.
*/
typedef enum {
COLLATION_BINARY = const_cpu_to_le32(0x00), /* Collate by
@@ -507,12 +517,12 @@
/* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero
terminated. */
/* 80*/ ATTR_TYPES type; /* Type of the attribute. */
-/* 84*/ u32 display_rule; /* Default display rule.
+/* 84*/ le32 display_rule; /* Default display rule.
FIXME: What does it mean? (AIA) */
/* 88*/ COLLATION_RULES collation_rule; /* Default collation rule. */
/* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */
-/* 90*/ u64 min_size; /* Optional minimum attribute size. */
-/* 98*/ u64 max_size; /* Maximum size of attribute. */
+/* 90*/ le64 min_size; /* Optional minimum attribute size. */
+/* 98*/ le64 max_size; /* Maximum size of attribute. */
/* sizeof() = 0xa0 or 160 bytes */
} __attribute__ ((__packed__)) ATTR_DEF;
@@ -610,14 +620,14 @@
typedef struct {
/*Ofs*/
/* 0*/ ATTR_TYPES type; /* The (32-bit) type of the attribute. */
-/* 4*/ u32 length; /* Byte size of the resident part of the
+/* 4*/ le32 length; /* Byte size of the resident part of the
attribute (aligned to 8-byte boundary).
Used to get to the next attribute. */
/* 8*/ u8 non_resident; /* If 0, attribute is resident.
If 1, attribute is non-resident. */
/* 9*/ u8 name_length; /* Unicode character size of name of attribute.
0 if unnamed. */
-/* 10*/ u16 name_offset; /* If name_length != 0, the byte offset to the
+/* 10*/ le16 name_offset; /* If name_length != 0, the byte offset to the
beginning of the name from the attribute
record. Note that the name is stored as a
Unicode string. When creating, place offset
@@ -627,15 +637,15 @@
respectively, aligning to an 8-byte
boundary. */
/* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */
-/* 14*/ u16 instance; /* The instance of this attribute record. This
+/* 14*/ le16 instance; /* The instance of this attribute record. This
number is unique within this mft record (see
MFT_RECORD/next_attribute_instance notes in
in mft.h for more details). */
/* 16*/ union {
/* Resident attributes. */
struct {
-/* 16 */ u32 value_length; /* Byte size of attribute value. */
-/* 20 */ u16 value_offset; /* Byte offset of the attribute
+/* 16 */ le32 value_length;/* Byte size of attribute value. */
+/* 20 */ le16 value_offset;/* Byte offset of the attribute
value from the start of the
attribute record. When creating,
align to 8-byte boundary if we
@@ -648,18 +658,18 @@
} __attribute__ ((__packed__)) resident;
/* Non-resident attributes. */
struct {
-/* 16*/ VCN lowest_vcn; /* Lowest valid virtual cluster number
+/* 16*/ leVCN lowest_vcn;/* Lowest valid virtual cluster number
for this portion of the attribute value or
0 if this is the only extent (usually the
case). - Only when an attribute list is used
does lowest_vcn != 0 ever occur. */
-/* 24*/ VCN highest_vcn; /* Highest valid vcn of this extent of
+/* 24*/ leVCN highest_vcn;/* Highest valid vcn of this extent of
the attribute value. - Usually there is only one
portion, so this usually equals the attribute
value size in clusters minus 1. Can be -1 for
zero length files. Can be 0 for "single extent"
attributes. */
-/* 32*/ u16 mapping_pairs_offset; /* Byte offset from the
+/* 32*/ le16 mapping_pairs_offset; /* Byte offset from the
beginning of the structure to the mapping pairs
array which contains the mappings between the
vcns and the logical cluster numbers (lcns).
@@ -674,7 +684,7 @@
/* 35*/ u8 reserved[5]; /* Align to 8-byte boundary. */
/* The sizes below are only used when lowest_vcn is zero, as otherwise it would
be difficult to keep them up-to-date.*/
-/* 40*/ s64 allocated_size; /* Byte size of disk space
+/* 40*/ sle64 allocated_size; /* Byte size of disk space
allocated to hold the attribute value. Always
is a multiple of the cluster size. When a file
is compressed, this field is a multiple of the
@@ -682,14 +692,14 @@
it represents the logically allocated space
rather than the actual on disk usage. For this
use the compressed_size (see below). */
-/* 48*/ s64 data_size; /* Byte size of the attribute
+/* 48*/ sle64 data_size; /* Byte size of the attribute
value. Can be larger than allocated_size if
attribute value is compressed or sparse. */
-/* 56*/ s64 initialized_size; /* Byte size of initialized
+/* 56*/ sle64 initialized_size; /* Byte size of initialized
portion of the attribute value. Usually equals
data_size. */
/* sizeof(uncompressed attr) = 64*/
-/* 64*/ s64 compressed_size; /* Byte size of the attribute
+/* 64*/ sle64 compressed_size; /* Byte size of the attribute
value after compression. Only present when
compressed. Always is a multiple of the
cluster size. Represents the actual amount of
@@ -774,13 +784,13 @@
*/
typedef struct {
/*Ofs*/
-/* 0*/ s64 creation_time; /* Time file was created. Updated when
+/* 0*/ sle64 creation_time; /* Time file was created. Updated when
a filename is changed(?). */
-/* 8*/ s64 last_data_change_time; /* Time the data attribute was last
+/* 8*/ sle64 last_data_change_time; /* Time the data attribute was last
modified. */
-/* 16*/ s64 last_mft_change_time; /* Time this mft record was last
+/* 16*/ sle64 last_mft_change_time; /* Time this mft record was last
modified. */
-/* 24*/ s64 last_access_time; /* Approximate time when the file was
+/* 24*/ sle64 last_access_time; /* Approximate time when the file was
last accessed (obviously this is not
updated on read-only volumes). In
Windows this is only updated when
@@ -817,23 +827,23 @@
* views that as a corruption, assuming that it behaves like this for all
* attributes.
*/
- /* 36*/ u32 maximum_versions; /* Maximum allowed versions for
+ /* 36*/ le32 maximum_versions; /* Maximum allowed versions for
file. Zero if version numbering is disabled. */
- /* 40*/ u32 version_number; /* This file's version (if any).
+ /* 40*/ le32 version_number; /* This file's version (if any).
Set to zero if maximum_versions is zero. */
- /* 44*/ u32 class_id; /* Class id from bidirectional
+ /* 44*/ le32 class_id; /* Class id from bidirectional
class id index (?). */
- /* 48*/ u32 owner_id; /* Owner_id of the user owning
+ /* 48*/ le32 owner_id; /* Owner_id of the user owning
the file. Translate via $Q index in FILE_Extend
/$Quota to the quota control entry for the user
owning the file. Zero if quotas are disabled. */
- /* 52*/ u32 security_id; /* Security_id for the file.
+ /* 52*/ le32 security_id; /* Security_id for the file.
Translate via $SII index and $SDS data stream
in FILE_Secure to the security descriptor. */
- /* 56*/ u64 quota_charged; /* Byte size of the charge to
+ /* 56*/ le64 quota_charged; /* Byte size of the charge to
the quota for all streams of the file. Note: Is
zero if quotas are disabled. */
- /* 64*/ u64 usn; /* Last update sequence number
+ /* 64*/ le64 usn; /* Last update sequence number
of the file. This is a direct index into the
change (aka usn) journal file. It is zero if
the usn journal is disabled.
@@ -887,13 +897,13 @@
typedef struct {
/*Ofs*/
/* 0*/ ATTR_TYPES type; /* Type of referenced attribute. */
-/* 4*/ u16 length; /* Byte size of this entry (8-byte aligned). */
+/* 4*/ le16 length; /* Byte size of this entry (8-byte aligned). */
/* 6*/ u8 name_length; /* Size in Unicode chars of the name of the
attribute or 0 if unnamed. */
/* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name
(always set this to where the name would
start even if unnamed). */
-/* 8*/ VCN lowest_vcn; /* Lowest virtual cluster number of this portion
+/* 8*/ leVCN lowest_vcn; /* Lowest virtual cluster number of this portion
of the attribute value. This is usually 0. It
is non-zero for the case where one attribute
does not fit into one mft record and thus
@@ -905,10 +915,10 @@
value! The windows driver uses cmp, followed
by jg when comparing this, thus it treats it
as signed. */
-/* 16*/ MFT_REF mft_reference; /* The reference of the mft record holding
+/* 16*/ leMFT_REF mft_reference;/* The reference of the mft record holding
the ATTR_RECORD for this portion of the
attribute value. */
-/* 24*/ u16 instance; /* If lowest_vcn = 0, the instance of the
+/* 24*/ le16 instance; /* If lowest_vcn = 0, the instance of the
attribute being referenced; otherwise 0. */
/* 26*/ ntfschar name[0]; /* Use when creating only. When reading use
name_offset to determine the location of the
@@ -962,30 +972,30 @@
*/
typedef struct {
/*hex ofs*/
-/* 0*/ MFT_REF parent_directory; /* Directory this filename is
+/* 0*/ leMFT_REF parent_directory; /* Directory this filename is
referenced from. */
-/* 8*/ s64 creation_time; /* Time file was created. */
-/* 10*/ s64 last_data_change_time; /* Time the data attribute was last
+/* 8*/ sle64 creation_time; /* Time file was created. */
+/* 10*/ sle64 last_data_change_time; /* Time the data attribute was last
modified. */
-/* 18*/ s64 last_mft_change_time; /* Time this mft record was last
+/* 18*/ sle64 last_mft_change_time; /* Time this mft record was last
modified. */
-/* 20*/ s64 last_access_time; /* Time this mft record was last
+/* 20*/ sle64 last_access_time; /* Time this mft record was last
accessed. */
-/* 28*/ s64 allocated_size; /* Byte size of allocated space for the
+/* 28*/ sle64 allocated_size; /* Byte size of allocated space for the
data attribute. NOTE: Is a multiple
of the cluster size. */
-/* 30*/ s64 data_size; /* Byte size of actual data in data
+/* 30*/ sle64 data_size; /* Byte size of actual data in data
attribute. */
/* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */
/* 3c*/ union {
/* 3c*/ struct {
- /* 3c*/ u16 packed_ea_size; /* Size of the buffer needed to
+ /* 3c*/ le16 packed_ea_size; /* Size of the buffer needed to
pack the extended attributes
(EAs), if such are present.*/
- /* 3e*/ u16 reserved; /* Reserved for alignment. */
+ /* 3e*/ le16 reserved; /* Reserved for alignment. */
} __attribute__ ((__packed__)) ea;
/* 3c*/ struct {
- /* 3c*/ u32 reparse_point_tag; /* Type of reparse point,
+ /* 3c*/ le32 reparse_point_tag; /* Type of reparse point,
present only in reparse
points and only if there are
no EAs. */
@@ -1007,9 +1017,9 @@
* 1F010768-5A73-BC91-0010A52216A7
*/
typedef struct {
- u32 data1; /* The first eight hexadecimal digits of the GUID. */
- u16 data2; /* The first group of four hexadecimal digits. */
- u16 data3; /* The second group of four hexadecimal digits. */
+ le32 data1; /* The first eight hexadecimal digits of the GUID. */
+ le16 data2; /* The first group of four hexadecimal digits. */
+ le16 data3; /* The second group of four hexadecimal digits. */
u8 data4[8]; /* The first two bytes are the third group of four
hexadecimal digits. The remaining six bytes are the
final 12 hexadecimal digits. */
@@ -1027,7 +1037,7 @@
* domain_id - Reserved (always zero).
*/
typedef struct {
- MFT_REF mft_reference; /* Mft record containing the object_id in
+ leMFT_REF mft_reference;/* Mft record containing the object_id in
the index entry key. */
union {
struct {
@@ -1195,13 +1205,16 @@
/*
* The SID_IDENTIFIER_AUTHORITY is a 48-bit value used in the SID structure.
+ *
+ * NOTE: This is stored as a big endian number, hence the high_part comes
+ * before the low_part.
*/
typedef union {
struct {
- u32 low; /* Low 32-bits. */
- u16 high; /* High 16-bits. */
+ u16 high_part; /* High 16-bits. */
+ u32 low_part; /* Low 32-bits. */
} __attribute__ ((__packed__)) parts;
- u8 value[6]; /* Value as individual bytes. */
+ u8 value[6]; /* Value as individual bytes. */
} __attribute__ ((__packed__)) SID_IDENTIFIER_AUTHORITY;
/*
@@ -1232,7 +1245,7 @@
u8 revision;
u8 sub_authority_count;
SID_IDENTIFIER_AUTHORITY identifier_authority;
- u32 sub_authority[1]; /* At least one sub_authority. */
+ le32 sub_authority[1]; /* At least one sub_authority. */
} __attribute__ ((__packed__)) SID;
/*
@@ -1312,7 +1325,7 @@
/*Ofs*/
/* 0*/ ACE_TYPES type; /* Type of the ACE. */
/* 1*/ ACE_FLAGS flags; /* Flags describing the ACE. */
-/* 2*/ u16 size; /* Size in bytes of the ACE. */
+/* 2*/ le16 size; /* Size in bytes of the ACE. */
} __attribute__ ((__packed__)) ACE_HEADER;
/*
@@ -1472,7 +1485,7 @@
/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */
ACE_TYPES type; /* Type of the ACE. */
ACE_FLAGS flags; /* Flags describing the ACE. */
- u16 size; /* Size in bytes of the ACE. */
+ le16 size; /* Size in bytes of the ACE. */
/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */
/* 8*/ SID sid; /* The SID associated with the ACE. */
@@ -1491,7 +1504,7 @@
/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */
ACE_TYPES type; /* Type of the ACE. */
ACE_FLAGS flags; /* Flags describing the ACE. */
- u16 size; /* Size in bytes of the ACE. */
+ le16 size; /* Size in bytes of the ACE. */
/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */
/* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */
@@ -1514,10 +1527,10 @@
typedef struct {
u8 revision; /* Revision of this ACL. */
u8 alignment1;
- u16 size; /* Allocated space in bytes for ACL. Includes this
+ le16 size; /* Allocated space in bytes for ACL. Includes this
header, the ACEs and the remaining free space. */
- u16 ace_count; /* Number of ACEs in the ACL. */
- u16 alignment2;
+ le16 ace_count; /* Number of ACEs in the ACL. */
+ le16 alignment2;
/* sizeof() = 8 bytes */
} __attribute__ ((__packed__)) ACL;
@@ -1608,17 +1621,17 @@
u8 alignment;
SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of
the descriptor as well as the following fields. */
- u32 owner; /* Byte offset to a SID representing an object's
+ le32 owner; /* Byte offset to a SID representing an object's
owner. If this is NULL, no owner SID is present in
the descriptor. */
- u32 group; /* Byte offset to a SID representing an object's
+ le32 group; /* Byte offset to a SID representing an object's
primary group. If this is NULL, no primary group
SID is present in the descriptor. */
- u32 sacl; /* Byte offset to a system ACL. Only valid, if
+ le32 sacl; /* Byte offset to a system ACL. Only valid, if
SE_SACL_PRESENT is set in the control field. If
SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL
is specified. */
- u32 dacl; /* Byte offset to a discretionary ACL. Only valid, if
+ le32 dacl; /* Byte offset to a discretionary ACL. Only valid, if
SE_DACL_PRESENT is set in the control field. If
SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL
(unconditionally granting access) is specified. */
@@ -1721,10 +1734,10 @@
* This is also the index entry data part of both the $SII and $SDH indexes.
*/
typedef struct {
- u32 hash; /* Hash of the security descriptor. */
- u32 security_id; /* The security_id assigned to the descriptor. */
- u64 offset; /* Byte offset of this entry in the $SDS stream. */
- u32 length; /* Size in bytes of this entry in $SDS stream. */
+ le32 hash; /* Hash of the security descriptor. */
+ le32 security_id; /* The security_id assigned to the descriptor. */
+ le64 offset; /* Byte offset of this entry in the $SDS stream. */
+ le32 length; /* Size in bytes of this entry in $SDS stream. */
} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_HEADER;
/*
@@ -1742,10 +1755,10 @@
/*Ofs*/
/* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like
unnamed structs. */
- u32 hash; /* Hash of the security descriptor. */
- u32 security_id; /* The security_id assigned to the descriptor. */
- u64 offset; /* Byte offset of this entry in the $SDS stream. */
- u32 length; /* Size in bytes of this entry in $SDS stream. */
+ le32 hash; /* Hash of the security descriptor. */
+ le32 security_id; /* The security_id assigned to the descriptor. */
+ le64 offset; /* Byte offset of this entry in the $SDS stream. */
+ le32 length; /* Size in bytes of this entry in $SDS stream. */
/* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security
descriptor. */
} __attribute__ ((__packed__)) SDS_ENTRY;
@@ -1755,7 +1768,7 @@
* COLLATION_NTOFS_ULONG.
*/
typedef struct {
- u32 security_id; /* The security_id assigned to the descriptor. */
+ le32 security_id; /* The security_id assigned to the descriptor. */
} __attribute__ ((__packed__)) SII_INDEX_KEY;
/*
@@ -1764,8 +1777,8 @@
* COLLATION_NTOFS_SECURITY_HASH.
*/
typedef struct {
- u32 hash; /* Hash of the security descriptor. */
- u32 security_id; /* The security_id assigned to the descriptor. */
+ le32 hash; /* Hash of the security descriptor. */
+ le32 security_id; /* The security_id assigned to the descriptor. */
} __attribute__ ((__packed__)) SDH_INDEX_KEY;
/*
@@ -1804,7 +1817,7 @@
* NTFS 1.2. I haven't personally seen other values yet.
*/
typedef struct {
- u64 reserved; /* Not used (yet?). */
+ le64 reserved; /* Not used (yet?). */
u8 major_ver; /* Major version of the ntfs format. */
u8 minor_ver; /* Minor version of the ntfs format. */
VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */
@@ -1853,12 +1866,12 @@
* start of the index root or index allocation structures themselves.
*/
typedef struct {
- u32 entries_offset; /* Byte offset to first INDEX_ENTRY
+ le32 entries_offset; /* Byte offset to first INDEX_ENTRY
aligned to 8-byte boundary. */
- u32 index_length; /* Data size of the index in bytes,
+ le32 index_length; /* Data size of the index in bytes,
i.e. bytes used from allocated
size, aligned to 8-byte boundary. */
- u32 allocated_size; /* Byte size of this index (block),
+ le32 allocated_size; /* Byte size of this index (block),
multiple of 8 bytes. */
/* NOTE: For the index root attribute, the above two numbers are always
equal, as the attribute is resident and it is resized as needed. In
@@ -1898,7 +1911,7 @@
COLLATION_RULES collation_rule; /* Collation rule used to sort the
index entries. If type is $FILE_NAME,
this must be COLLATION_FILE_NAME. */
- u32 index_block_size; /* Size of each index block in bytes (in
+ le32 index_block_size; /* Size of each index block in bytes (in
the index allocation attribute). */
u8 clusters_per_index_block; /* Cluster size of each index block (in
the index allocation attribute), when
@@ -1925,12 +1938,12 @@
typedef struct {
/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
NTFS_RECORD_TYPES magic;/* Magic is "INDX". */
- u16 usa_ofs; /* See NTFS_RECORD definition. */
- u16 usa_count; /* See NTFS_RECORD definition. */
+ le16 usa_ofs; /* See NTFS_RECORD definition. */
+ le16 usa_count; /* See NTFS_RECORD definition. */
-/* 8*/ s64 lsn; /* $LogFile sequence number of the last
+/* 8*/ sle64 lsn; /* $LogFile sequence number of the last
modification of this index block. */
-/* 16*/ VCN index_block_vcn; /* Virtual cluster number of the index block.
+/* 16*/ leVCN index_block_vcn; /* Virtual cluster number of the index block.
If the cluster_size on the volume is <= the
index_block_size of the directory,
index_block_vcn counts in units of clusters,
@@ -1960,8 +1973,8 @@
* primary key / is not a key at all. (AIA)
*/
typedef struct {
- u32 reparse_tag; /* Reparse point type (inc. flags). */
- MFT_REF file_id; /* Mft record of the file containing the
+ le32 reparse_tag; /* Reparse point type (inc. flags). */
+ leMFT_REF file_id; /* Mft record of the file containing the
reparse point attribute. */
} __attribute__ ((__packed__)) REPARSE_INDEX_KEY;
@@ -2011,13 +2024,13 @@
* The $Q index entry data is the quota control entry and is defined below.
*/
typedef struct {
- u32 version; /* Currently equals 2. */
+ le32 version; /* Currently equals 2. */
QUOTA_FLAGS flags; /* Flags describing this quota entry. */
- u64 bytes_used; /* How many bytes of the quota are in use. */
- s64 change_time; /* Last time this quota entry was changed. */
- s64 threshold; /* Soft quota (-1 if not limited). */
- s64 limit; /* Hard quota (-1 if not limited). */
- s64 exceeded_time; /* How long the soft quota has been exceeded. */
+ le64 bytes_used; /* How many bytes of the quota are in use. */
+ sle64 change_time; /* Last time this quota entry was changed. */
+ sle64 threshold; /* Soft quota (-1 if not limited). */
+ sle64 limit; /* Hard quota (-1 if not limited). */
+ sle64 exceeded_time; /* How long the soft quota has been exceeded. */
SID sid; /* The SID of the user/object associated with
this quota entry. Equals zero for the quota
defaults entry (and in fact on a WinXP
@@ -2063,26 +2076,26 @@
typedef struct {
/* 0*/ union {
struct { /* Only valid when INDEX_ENTRY_END is not set. */
- MFT_REF indexed_file; /* The mft reference of the file
+ leMFT_REF indexed_file; /* The mft reference of the file
described by this index
entry. Used for directory
indexes. */
} __attribute__ ((__packed__)) dir;
struct { /* Used for views/indexes to find the entry's data. */
- u16 data_offset; /* Data byte offset from this
+ le16 data_offset; /* Data byte offset from this
INDEX_ENTRY. Follows the
index key. */
- u16 data_length; /* Data length in bytes. */
- u32 reservedV; /* Reserved (zero). */
+ le16 data_length; /* Data length in bytes. */
+ le32 reservedV; /* Reserved (zero). */
} __attribute__ ((__packed__)) vi;
} __attribute__ ((__packed__)) data;
-/* 8*/ u16 length; /* Byte size of this index entry, multiple of
+/* 8*/ le16 length; /* Byte size of this index entry, multiple of
8-bytes. */
-/* 10*/ u16 key_length; /* Byte size of the key value, which is in the
+/* 10*/ le16 key_length; /* Byte size of the key value, which is in the
index entry. It follows field reserved. Not
multiple of 8-bytes. */
/* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */
-/* 14*/ u16 reserved; /* Reserved/align to 8-byte boundary. */
+/* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */
/* sizeof() = 16 bytes */
} __attribute__ ((__packed__)) INDEX_ENTRY_HEADER;
@@ -2098,26 +2111,26 @@
/* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */
union {
struct { /* Only valid when INDEX_ENTRY_END is not set. */
- MFT_REF indexed_file; /* The mft reference of the file
+ leMFT_REF indexed_file; /* The mft reference of the file
described by this index
entry. Used for directory
indexes. */
} __attribute__ ((__packed__)) dir;
struct { /* Used for views/indexes to find the entry's data. */
- u16 data_offset; /* Data byte offset from this
+ le16 data_offset; /* Data byte offset from this
INDEX_ENTRY. Follows the
index key. */
- u16 data_length; /* Data length in bytes. */
- u32 reservedV; /* Reserved (zero). */
+ le16 data_length; /* Data length in bytes. */
+ le32 reservedV; /* Reserved (zero). */
} __attribute__ ((__packed__)) vi;
} __attribute__ ((__packed__)) data;
- u16 length; /* Byte size of this index entry, multiple of
+ le16 length; /* Byte size of this index entry, multiple of
8-bytes. */
- u16 key_length; /* Byte size of the key value, which is in the
+ le16 key_length; /* Byte size of the key value, which is in the
index entry. It follows field reserved. Not
multiple of 8-bytes. */
INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */
- u16 reserved; /* Reserved/align to 8-byte boundary. */
+ le16 reserved; /* Reserved/align to 8-byte boundary. */
/* 16*/ union { /* The key of the indexed attribute. NOTE: Only present
if INDEX_ENTRY_END bit in flags is not set. NOTE: On
@@ -2134,13 +2147,13 @@
FILE_Extend/$Reparse. */
SID sid; /* $O index in FILE_Extend/$Quota:
SID of the owner of the user_id. */
- u32 owner_id; /* $Q index in FILE_Extend/$Quota:
+ le32 owner_id; /* $Q index in FILE_Extend/$Quota:
user_id of the owner of the quota
control entry in the data part of
the index. */
} __attribute__ ((__packed__)) key;
/* The (optional) index data is inserted here when creating. */
- // VCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last
+ // leVCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last
// eight bytes of this index entry contain the virtual
// cluster number of the index block that holds the
// entries immediately preceding the current entry (the
@@ -2215,9 +2228,9 @@
* NOTE: Can be resident or non-resident.
*/
typedef struct {
- u32 reparse_tag; /* Reparse point type (inc. flags). */
- u16 reparse_data_length; /* Byte size of reparse data. */
- u16 reserved; /* Align to 8-byte boundary. */
+ le32 reparse_tag; /* Reparse point type (inc. flags). */
+ le16 reparse_data_length; /* Byte size of reparse data. */
+ le16 reserved; /* Align to 8-byte boundary. */
u8 reparse_data[0]; /* Meaning depends on reparse_tag. */
} __attribute__ ((__packed__)) REPARSE_POINT;
@@ -2227,11 +2240,11 @@
* NOTE: Always resident. (Is this true???)
*/
typedef struct {
- u16 ea_length; /* Byte size of the packed extended
+ le16 ea_length; /* Byte size of the packed extended
attributes. */
- u16 need_ea_count; /* The number of extended attributes which have
+ le16 need_ea_count; /* The number of extended attributes which have
the NEED_EA bit set. */
- u32 ea_query_length; /* Byte size of the buffer required to query
+ le32 ea_query_length; /* Byte size of the buffer required to query
the extended attributes when calling
ZwQueryEaFile() in Windows NT/2k. I.e. the
byte size of the unpacked extended
@@ -2256,10 +2269,10 @@
* FIXME: It appears weird that the EA name is not unicode. Is it true?
*/
typedef struct {
- u32 next_entry_offset; /* Offset to the next EA_ATTR. */
+ le32 next_entry_offset; /* Offset to the next EA_ATTR. */
EA_FLAGS flags; /* Flags describing the EA. */
u8 ea_name_length; /* Length of the name of the EA in bytes. */
- u16 ea_value_length; /* Byte size of the EA's value. */
+ le16 ea_value_length; /* Byte size of the EA's value. */
u8 ea_name[0]; /* Name of the EA. */
u8 ea_value[0]; /* The value of the EA. Immediately follows
the name. */
diff -Nru a/fs/ntfs/logfile.c b/fs/ntfs/logfile.c
--- a/fs/ntfs/logfile.c 2004-09-24 17:06:23 +01:00
+++ b/fs/ntfs/logfile.c 2004-09-24 17:06:23 +01:00
@@ -497,7 +497,7 @@
* empty block after a non-empty block has been encountered
* means we are done.
*/
- if (!ntfs_is_empty_recordp(kaddr))
+ if (!ntfs_is_empty_recordp((le32*)kaddr))
logfile_is_empty = FALSE;
else if (!logfile_is_empty)
break;
@@ -505,20 +505,20 @@
* A log record page means there cannot be a restart page after
* this so no need to continue searching.
*/
- if (ntfs_is_rcrd_recordp(kaddr))
+ if (ntfs_is_rcrd_recordp((le32*)kaddr))
break;
/*
* A modified by chkdsk restart page means we cannot handle
* this log file.
*/
- if (ntfs_is_chkd_recordp(kaddr)) {
+ if (ntfs_is_chkd_recordp((le32*)kaddr)) {
ntfs_error(vol->sb, "$LogFile has been modified by "
"chkdsk. Mount this volume in "
"Windows.");
goto err_out;
}
/* If not a restart page, continue. */
- if (!ntfs_is_rstr_recordp(kaddr)) {
+ if (!ntfs_is_rstr_recordp((le32*)kaddr)) {
/* Skip to the minimum page size for the next one. */
if (!pos)
pos = NTFS_BLOCK_SIZE >> 1;
diff -Nru a/fs/ntfs/logfile.h b/fs/ntfs/logfile.h
--- a/fs/ntfs/logfile.h 2004-09-24 17:06:23 +01:00
+++ b/fs/ntfs/logfile.h 2004-09-24 17:06:23 +01:00
@@ -68,33 +68,33 @@
/*Ofs*/
/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
/* 0*/ NTFS_RECORD_TYPES magic;/* The magic is "RSTR". */
-/* 4*/ u16 usa_ofs; /* See NTFS_RECORD definition in layout.h.
+/* 4*/ le16 usa_ofs; /* See NTFS_RECORD definition in layout.h.
When creating, set this to be immediately
after this header structure (without any
alignment). */
-/* 6*/ u16 usa_count; /* See NTFS_RECORD definition in layout.h. */
+/* 6*/ le16 usa_count; /* See NTFS_RECORD definition in layout.h. */
-/* 8*/ LSN chkdsk_lsn; /* The last log file sequence number found by
+/* 8*/ leLSN chkdsk_lsn; /* The last log file sequence number found by
chkdsk. Only used when the magic is changed
to "CHKD". Otherwise this is zero. */
-/* 16*/ u32 system_page_size; /* Byte size of system pages when the log file
+/* 16*/ le32 system_page_size; /* Byte size of system pages when the log file
was created, has to be >= 512 and a power of
2. Use this to calculate the required size
of the usa (usa_count) and add it to usa_ofs.
Then verify that the result is less than the
value of the restart_area_offset. */
-/* 20*/ u32 log_page_size; /* Byte size of log file pages, has to be >=
+/* 20*/ le32 log_page_size; /* Byte size of log file pages, has to be >=
512 and a power of 2. The default is 4096
and is used when the system page size is
between 4096 and 8192. Otherwise this is
set to the system page size instead. */
-/* 24*/ u16 restart_area_offset;/* Byte offset from the start of this header to
+/* 24*/ le16 restart_area_offset;/* Byte offset from the start of this header to
the RESTART_AREA. Value has to be aligned
to 8-byte boundary. When creating, set this
to be after the usa. */
-/* 26*/ s16 minor_ver; /* Log file minor version. Only check if major
+/* 26*/ sle16 minor_ver; /* Log file minor version. Only check if major
version is 1. */
-/* 28*/ s16 major_ver; /* Log file major version. We only support
+/* 28*/ sle16 major_ver; /* Log file major version. We only support
version 1.1. */
/* sizeof() = 30 (0x1e) bytes */
} __attribute__ ((__packed__)) RESTART_PAGE_HEADER;
@@ -123,16 +123,16 @@
*/
typedef struct {
/*Ofs*/
-/* 0*/ LSN current_lsn; /* The current, i.e. last LSN inside the log
+/* 0*/ leLSN current_lsn; /* The current, i.e. last LSN inside the log
when the restart area was last written.
This happens often but what is the interval?
Is it just fixed time or is it every time a
check point is written or somethine else?
On create set to 0. */
-/* 8*/ u16 log_clients; /* Number of log client records in the array of
+/* 8*/ le16 log_clients; /* Number of log client records in the array of
log client records which follows this
restart area. Must be 1. */
-/* 10*/ u16 client_free_list; /* The index of the first free log client record
+/* 10*/ le16 client_free_list; /* The index of the first free log client record
in the array of log client records.
LOGFILE_NO_CLIENT means that there are no
free log client records in the array.
@@ -148,7 +148,7 @@
and presumably later, the logfile is always
open, even on clean shutdown so this should
always be LOGFILE_NO_CLIENT. */
-/* 12*/ u16 client_in_use_list; /* The index of the first in-use log client
+/* 12*/ le16 client_in_use_list;/* The index of the first in-use log client
record in the array of log client records.
LOGFILE_NO_CLIENT means that there are no
in-use log client records in the array. If
@@ -181,13 +181,13 @@
clean. If on the other hand the logfile is
open and this bit is clear, we can be almost
certain that the logfile is dirty. */
-/* 16*/ u32 seq_number_bits; /* How many bits to use for the sequence
+/* 16*/ le32 seq_number_bits; /* How many bits to use for the sequence
number. This is calculated as 67 - the
number of bits required to store the logfile
size in bytes and this can be used in with
the specified file_size as a consistency
check. */
-/* 20*/ u16 restart_area_length;/* Length of the restart area including the
+/* 20*/ le16 restart_area_length;/* Length of the restart area including the
client array. Following checks required if
version matches. Otherwise, skip them.
restart_area_offset + restart_area_length
@@ -195,7 +195,7 @@
restart_area_length has to be >=
client_array_offset + (log_clients *
sizeof(log client record)). */
-/* 22*/ u16 client_array_offset;/* Offset from the start of this record to
+/* 22*/ le16 client_array_offset;/* Offset from the start of this record to
the first log client record if versions are
matched. When creating, set this to be
after this restart area structure, aligned
@@ -217,7 +217,7 @@
the client array. This probably means that
the RESTART_AREA record is actually bigger
in WinXP and later. */
-/* 24*/ s64 file_size; /* Usable byte size of the log file. If the
+/* 24*/ sle64 file_size; /* Usable byte size of the log file. If the
restart_area_offset + the offset of the
file_size are > 510 then corruption has
occured. This is the very first check when
@@ -230,28 +230,28 @@
then it has to be at least big enough to
store the two restart pages and 48 (0x30)
log record pages. */
-/* 32*/ u32 last_lsn_data_length;/* Length of data of last LSN, not including
+/* 32*/ le32 last_lsn_data_length;/* Length of data of last LSN, not including
the log record header. On create set to
0. */
-/* 36*/ u16 log_record_header_length;/* Byte size of the log record header. If
- the version matches then check that the
+/* 36*/ le16 log_record_header_length;/* Byte size of the log record header.
+ If the version matches then check that the
value of log_record_header_length is a
multiple of 8, i.e.
(log_record_header_length + 7) & ~7 ==
log_record_header_length. When creating set
it to sizeof(LOG_RECORD_HEADER), aligned to
8 bytes. */
-/* 38*/ u16 log_page_data_offset;/* Offset to the start of data in a log record
+/* 38*/ le16 log_page_data_offset;/* Offset to the start of data in a log record
page. Must be a multiple of 8. On create
set it to immediately after the update
sequence array of the log record page. */
-/* 40*/ u32 restart_log_open_count;/* A counter that gets incremented every time
- the logfile is restarted which happens at
- mount time when the logfile is opened. When
- creating set to a random value. Win2k sets
- it to the low 32 bits of the current system
- time in NTFS format (see time.h). */
-/* 44*/ u32 reserved; /* Reserved/alignment to 8-byte boundary. */
+/* 40*/ le32 restart_log_open_count;/* A counter that gets incremented every
+ time the logfile is restarted which happens
+ at mount time when the logfile is opened.
+ When creating set to a random value. Win2k
+ sets it to the low 32 bits of the current
+ system time in NTFS format (see time.h). */
+/* 44*/ le32 reserved; /* Reserved/alignment to 8-byte boundary. */
/* sizeof() = 48 (0x30) bytes */
} __attribute__ ((__packed__)) RESTART_AREA;
@@ -261,32 +261,32 @@
*/
typedef struct {
/*Ofs*/
-/* 0*/ LSN oldest_lsn; /* Oldest LSN needed by this client. On create
+/* 0*/ leLSN oldest_lsn; /* Oldest LSN needed by this client. On create
set to 0. */
-/* 8*/ LSN client_restart_lsn; /* LSN at which this client needs to restart
+/* 8*/ leLSN client_restart_lsn;/* LSN at which this client needs to restart
the volume, i.e. the current position within
the log file. At present, if clean this
should = current_lsn in restart area but it
probably also = current_lsn when dirty most
of the time. At create set to 0. */
-/* 16*/ u16 prev_client; /* The offset to the previous log client record
+/* 16*/ le16 prev_client; /* The offset to the previous log client record
in the array of log client records.
LOGFILE_NO_CLIENT means there is no previous
client record, i.e. this is the first one.
This is always LOGFILE_NO_CLIENT. */
-/* 18*/ u16 next_client; /* The offset to the next log client record in
+/* 18*/ le16 next_client; /* The offset to the next log client record in
the array of log client records.
LOGFILE_NO_CLIENT means there are no next
client records, i.e. this is the last one.
This is always LOGFILE_NO_CLIENT. */
-/* 20*/ u16 seq_number; /* On Win2k and presumably earlier, this is set
+/* 20*/ le16 seq_number; /* On Win2k and presumably earlier, this is set
to zero every time the logfile is restarted
and it is incremented when the logfile is
closed at dismount time. Thus it is 0 when
dirty and 1 when clean. On WinXP and
presumably later, this is always 0. */
/* 22*/ u8 reserved[6]; /* Reserved/alignment. */
-/* 28*/ u32 client_name_length; /* Length of client name in bytes. Should
+/* 28*/ le32 client_name_length;/* Length of client name in bytes. Should
always be 8. */
/* 32*/ ntfschar client_name[64];/* Name of the client in Unicode. Should
always be "NTFS" with the remaining bytes
diff -Nru a/fs/ntfs/mft.c b/fs/ntfs/mft.c
--- a/fs/ntfs/mft.c 2004-09-24 17:06:23 +01:00
+++ b/fs/ntfs/mft.c 2004-09-24 17:06:23 +01:00
@@ -980,7 +980,7 @@
ntfs_debug("Inode 0x%lx is not in icache.", mft_no);
/* The inode is not in icache. */
/* Skip the record if it is not a mft record (type "FILE"). */
- if (!ntfs_is_mft_recordp(maddr)) {
+ if (!ntfs_is_mft_recordp((le32*)maddr)) {
ntfs_debug("Mft record 0x%lx is not a FILE record, "
"continuing search.", mft_no);
continue;
diff -Nru a/fs/ntfs/super.c b/fs/ntfs/super.c
--- a/fs/ntfs/super.c 2004-09-24 17:06:23 +01:00
+++ b/fs/ntfs/super.c 2004-09-24 17:06:23 +01:00
@@ -511,8 +511,10 @@
* field. If checksum is zero, no checking is done.
*/
if ((void*)b < (void*)&b->checksum && b->checksum) {
- u32 i, *u;
- for (i = 0, u = (u32*)b; u < (u32*)(&b->checksum); ++u)
+ le32 *u;
+ u32 i;
+
+ for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u)
i += le32_to_cpup(u);
if (le32_to_cpu(b->checksum) != i)
goto not_ntfs;
@@ -521,7 +523,7 @@
if (b->oem_id != magicNTFS)
goto not_ntfs;
/* Check bytes per sector value is between 256 and 4096. */
- if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 ||
+ if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 ||
le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000)
goto not_ntfs;
/* Check sectors per cluster value is valid. */
@@ -1003,7 +1005,7 @@
++index;
}
/* Make sure the record is ok. */
- if (ntfs_is_baad_recordp(kmft)) {
+ if (ntfs_is_baad_recordp((le32*)kmft)) {
ntfs_error(sb, "Incomplete multi sector transfer "
"detected in mft record %i.", i);
mm_unmap_out:
@@ -1012,7 +1014,7 @@
ntfs_unmap_page(mft_page);
return FALSE;
}
- if (ntfs_is_baad_recordp(kmirr)) {
+ if (ntfs_is_baad_recordp((le32*)kmirr)) {
ntfs_error(sb, "Incomplete multi sector transfer "
"detected in mft mirror record %i.", i);
goto mm_unmap_out;
diff -Nru a/fs/ntfs/time.h b/fs/ntfs/time.h
--- a/fs/ntfs/time.h 2004-09-24 17:06:23 +01:00
+++ b/fs/ntfs/time.h 2004-09-24 17:06:23 +01:00
@@ -45,7 +45,7 @@
* measured as the number of 100-nano-second intervals since 1st January 1601,
* 00:00:00 UTC.
*/
-static inline s64 utc2ntfs(const struct timespec ts)
+static inline sle64 utc2ntfs(const struct timespec ts)
{
/*
* Convert the seconds to 100ns intervals, add the nano-seconds
@@ -61,7 +61,7 @@
* Get the current time from the Linux kernel, convert it to its corresponding
* NTFS time and return that in little endian format.
*/
-static inline s64 get_current_ntfs_time(void)
+static inline sle64 get_current_ntfs_time(void)
{
return utc2ntfs(current_kernel_time());
}
@@ -82,7 +82,7 @@
* measured as the number of 100 nano-second intervals since 1st January 1601,
* 00:00:00 UTC.
*/
-static inline struct timespec ntfs2utc(const s64 time)
+static inline struct timespec ntfs2utc(const sle64 time)
{
struct timespec ts;
This is patch 3/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/22 1.1949)
NTFS: Improve the previous transparent union removal.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/dir.c b/fs/ntfs/dir.c
--- a/fs/ntfs/dir.c 2004-09-24 17:06:09 +01:00
+++ b/fs/ntfs/dir.c 2004-09-24 17:06:09 +01:00
@@ -1013,9 +1013,8 @@
* Convert the Unicode @name to the loaded NLS and pass it to the @filldir
* callback.
*
- * If @index_type is INDEX_TYPE_ALLOCATION, @ia_page is the locked page
- * containing the index allocation block containing the index entry @ie.
- * Otherwise, @ia_page is NULL.
+ * If @ia_page is not NULL it is the locked page containing the index
+ * allocation block containing the index entry @ie.
*
* Note, we drop (and then reacquire) the page lock on @ia_page across the
* @filldir() call otherwise we would deadlock with NFSd when it calls ->lookup
@@ -1023,7 +1022,7 @@
* retake the lock if we are returning a non-zero value as ntfs_readdir()
* would need to drop the lock immediately anyway.
*/
-static inline int ntfs_filldir(ntfs_volume *vol, loff_t *fpos,
+static inline int ntfs_filldir(ntfs_volume *vol, loff_t fpos,
ntfs_inode *ndir, struct page *ia_page, INDEX_ENTRY *ie,
u8 *name, void *dirent, filldir_t filldir)
{
@@ -1066,9 +1065,9 @@
if (ia_page)
unlock_page(ia_page);
ntfs_debug("Calling filldir for %s with len %i, fpos 0x%llx, inode "
- "0x%lx, DT_%s.", name, name_len, *fpos, mref,
+ "0x%lx, DT_%s.", name, name_len, fpos, mref,
dt_type == DT_DIR ? "DIR" : "REG");
- rc = filldir(dirent, name, name_len, *fpos, mref, dt_type);
+ rc = filldir(dirent, name, name_len, fpos, mref, dt_type);
/* Relock the page but not if we are aborting ->readdir. */
if (!rc && ia_page)
lock_page(ia_page);
@@ -1226,7 +1225,7 @@
/* Advance the position even if going to skip the entry. */
fpos = (u8*)ie - (u8*)ir;
/* Submit the name to the filldir callback. */
- rc = ntfs_filldir(vol, &fpos, ndir, NULL, ie, name, dirent,
+ rc = ntfs_filldir(vol, fpos, ndir, NULL, ie, name, dirent,
filldir);
if (rc) {
kfree(ir);
@@ -1412,7 +1411,7 @@
* before returning, unless a non-zero value is returned in
* which case the page is left unlocked.
*/
- rc = ntfs_filldir(vol, &fpos, ndir, ia_page, ie, name, dirent,
+ rc = ntfs_filldir(vol, fpos, ndir, ia_page, ie, name, dirent,
filldir);
if (rc) {
/* @ia_page is already unlocked in this case. */
This is patch 8/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/24 1.1952.1.3)
NTFS: Finish off sparse annotation.
- Fix all the sparse bitwise warnings. Had to change all the enums
storing little endian values to #defines because we cannot set enums
to be little endian so we had lots of bitwise warnings from sparse.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:27 +01:00
@@ -48,6 +48,9 @@
Affected files are fs/ntfs/layout.h, logfile.h, and time.h.
- Do proper type casting when using ntfs_is_*_recordp() in
fs/ntfs/logfile.c, mft.c, and super.c.
+ - Fix all the sparse bitwise warnings. Had to change all the enums
+ storing little endian values to #defines because we cannot set enums
+ to be little endian so we had lots of bitwise warnings from sparse.
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
diff -Nru a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
--- a/fs/ntfs/attrib.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/attrib.c 2004-09-24 17:06:27 +01:00
@@ -1203,7 +1203,7 @@
* Warning: Never use @val when looking for attribute types which can be
* non-resident as this most likely will result in a crash!
*/
-static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name,
+static int ntfs_attr_find(const ATTR_TYPE type, const ntfschar *name,
const u32 name_len, const IGNORE_CASE_BOOL ic,
const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx)
{
@@ -1475,7 +1475,7 @@
* On actual error, ntfs_external_attr_find() returns -EIO. In this case
* @ctx->attr is undefined and in particular do not rely on it not changing.
*/
-static int ntfs_external_attr_find(const ATTR_TYPES type,
+static int ntfs_external_attr_find(const ATTR_TYPE type,
const ntfschar *name, const u32 name_len,
const IGNORE_CASE_BOOL ic, const VCN lowest_vcn,
const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx)
@@ -1620,7 +1620,8 @@
} else {
/* We want an extent record. */
ctx->mrec = map_extent_mft_record(base_ni,
- al_entry->mft_reference, &ni);
+ le64_to_cpu(
+ al_entry->mft_reference), &ni);
ctx->ntfs_ino = ni;
if (IS_ERR(ctx->mrec)) {
ntfs_error(vol->sb, "Failed to map "
@@ -1799,7 +1800,7 @@
* When -errno != -ENOENT, an error occured during the lookup. @ctx->attr is
* then undefined and in particular you should not rely on it not changing.
*/
-int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
+int ntfs_attr_lookup(const ATTR_TYPE type, const ntfschar *name,
const u32 name_len, const IGNORE_CASE_BOOL ic,
const VCN lowest_vcn, const u8 *val, const u32 val_len,
ntfs_attr_search_ctx *ctx)
diff -Nru a/fs/ntfs/attrib.h b/fs/ntfs/attrib.h
--- a/fs/ntfs/attrib.h 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/attrib.h 2004-09-24 17:06:27 +01:00
@@ -81,7 +81,7 @@
extern runlist_element *ntfs_find_vcn(ntfs_inode *ni, const VCN vcn,
const BOOL need_write);
-int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
+int ntfs_attr_lookup(const ATTR_TYPE type, const ntfschar *name,
const u32 name_len, const IGNORE_CASE_BOOL ic,
const VCN lowest_vcn, const u8 *val, const u32 val_len,
ntfs_attr_search_ctx *ctx);
diff -Nru a/fs/ntfs/collate.c b/fs/ntfs/collate.c
--- a/fs/ntfs/collate.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/collate.c 2004-09-24 17:06:27 +01:00
@@ -97,24 +97,26 @@
* For speed we use the collation rule @cr as an index into two tables of
* function pointers to call the appropriate collation function.
*/
-int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr,
+int ntfs_collate(ntfs_volume *vol, COLLATION_RULE cr,
const void *data1, const int data1_len,
const void *data2, const int data2_len) {
+ int i;
+
ntfs_debug("Entering.");
/*
* FIXME: At the moment we only support COLLATION_BINARY and
* COLLATION_NTOFS_ULONG, so we BUG() for everything else for now.
*/
BUG_ON(cr != COLLATION_BINARY && cr != COLLATION_NTOFS_ULONG);
- cr = le32_to_cpu(cr);
- BUG_ON(cr < 0);
- if (cr <= 0x02)
- return ntfs_do_collate0x0[cr](vol, data1, data1_len,
+ i = le32_to_cpu(cr);
+ BUG_ON(i < 0);
+ if (i <= 0x02)
+ return ntfs_do_collate0x0[i](vol, data1, data1_len,
data2, data2_len);
- BUG_ON(cr < 0x10);
- cr -= 0x10;
- if (likely(cr <= 3))
- return ntfs_do_collate0x1[cr](vol, data1, data1_len,
+ BUG_ON(i < 0x10);
+ i -= 0x10;
+ if (likely(i <= 3))
+ return ntfs_do_collate0x1[i](vol, data1, data1_len,
data2, data2_len);
BUG();
return 0;
diff -Nru a/fs/ntfs/collate.h b/fs/ntfs/collate.h
--- a/fs/ntfs/collate.h 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/collate.h 2004-09-24 17:06:27 +01:00
@@ -26,7 +26,9 @@
#include "types.h"
#include "volume.h"
-static inline BOOL ntfs_is_collation_rule_supported(COLLATION_RULES cr) {
+static inline BOOL ntfs_is_collation_rule_supported(COLLATION_RULE cr) {
+ int i;
+
/*
* FIXME: At the moment we only support COLLATION_BINARY and
* COLLATION_NTOFS_ULONG, so we return false for everything else for
@@ -34,14 +36,14 @@
*/
if (unlikely(cr != COLLATION_BINARY && cr != COLLATION_NTOFS_ULONG))
return FALSE;
- cr = le32_to_cpu(cr);
- if (likely(((cr >= 0) && (cr <= 0x02)) ||
- ((cr >= 0x10) && (cr <= 0x13))))
+ i = le32_to_cpu(cr);
+ if (likely(((i >= 0) && (i <= 0x02)) ||
+ ((i >= 0x10) && (i <= 0x13))))
return TRUE;
return FALSE;
}
-extern int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr,
+extern int ntfs_collate(ntfs_volume *vol, COLLATION_RULE cr,
const void *data1, const int data1_len,
const void *data2, const int data2_len);
diff -Nru a/fs/ntfs/compress.c b/fs/ntfs/compress.c
--- a/fs/ntfs/compress.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/compress.c 2004-09-24 17:06:27 +01:00
@@ -203,7 +203,7 @@
* position in the compression block is one byte before its end so the
* first two checks do not detect it.
*/
- if (cb == cb_end || !le16_to_cpup((u16*)cb) ||
+ if (cb == cb_end || !le16_to_cpup((le16*)cb) ||
(*dest_index == dest_max_index &&
*dest_ofs == dest_max_ofs)) {
int i;
@@ -255,7 +255,7 @@
/* Setup the current sub-block source pointers and validate range. */
cb_sb_start = cb;
- cb_sb_end = cb_sb_start + (le16_to_cpup((u16*)cb) & NTFS_SB_SIZE_MASK)
+ cb_sb_end = cb_sb_start + (le16_to_cpup((le16*)cb) & NTFS_SB_SIZE_MASK)
+ 3;
if (cb_sb_end > cb_end)
goto return_overflow;
@@ -277,7 +277,7 @@
dp_addr = (u8*)page_address(dp) + do_sb_start;
/* Now, we are ready to process the current sub-block (sb). */
- if (!(le16_to_cpup((u16*)cb) & NTFS_SB_IS_COMPRESSED)) {
+ if (!(le16_to_cpup((le16*)cb) & NTFS_SB_IS_COMPRESSED)) {
ntfs_debug("Found uncompressed sub-block.");
/* This sb is not compressed, just copy it into destination. */
@@ -382,7 +382,7 @@
lg++;
/* Get the phrase token into i. */
- pt = le16_to_cpup((u16*)cb);
+ pt = le16_to_cpup((le16*)cb);
/*
* Calculate starting position of the byte sequence in
diff -Nru a/fs/ntfs/inode.c b/fs/ntfs/inode.c
--- a/fs/ntfs/inode.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/inode.c 2004-09-24 17:06:27 +01:00
@@ -214,7 +214,7 @@
* value with IS_ERR() and if true, the function failed and the error code is
* obtained from PTR_ERR().
*/
-struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPES type,
+struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPE type,
ntfschar *name, u32 name_len)
{
struct inode *vi;
@@ -2404,7 +2404,7 @@
*/
int ntfs_write_inode(struct inode *vi, int sync)
{
- s64 nt;
+ sle64 nt;
ntfs_inode *ni = NTFS_I(vi);
ntfs_attr_search_ctx *ctx;
MFT_RECORD *m;
diff -Nru a/fs/ntfs/inode.h b/fs/ntfs/inode.h
--- a/fs/ntfs/inode.h 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/inode.h 2004-09-24 17:06:27 +01:00
@@ -53,7 +53,7 @@
* name_len = 0 for files and name = I30 (global constant) and
* name_len = 4 for directories.
*/
- ATTR_TYPES type; /* Attribute type of this fake inode. */
+ ATTR_TYPE type; /* Attribute type of this fake inode. */
ntfschar *name; /* Attribute name of this fake inode. */
u32 name_len; /* Attribute name length of this fake inode. */
runlist runlist; /* If state has the NI_NonResident bit set,
@@ -96,7 +96,7 @@
u32 block_size; /* Size of an index block. */
u32 vcn_size; /* Size of a vcn in this
index. */
- COLLATION_RULES collation_rule; /* The collation rule
+ COLLATION_RULE collation_rule; /* The collation rule
for the index. */
u8 block_size_bits; /* Log2 of the above. */
u8 vcn_size_bits; /* Log2 of the above. */
@@ -252,7 +252,7 @@
unsigned long mft_no;
ntfschar *name;
u32 name_len;
- ATTR_TYPES type;
+ ATTR_TYPE type;
} ntfs_attr;
typedef int (*test_t)(struct inode *, void *);
@@ -260,7 +260,7 @@
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_attr_iget(struct inode *base_vi, ATTR_TYPES type,
+extern struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPE type,
ntfschar *name, u32 name_len);
extern struct inode *ntfs_index_iget(struct inode *base_vi, ntfschar *name,
u32 name_len);
diff -Nru a/fs/ntfs/layout.h b/fs/ntfs/layout.h
--- a/fs/ntfs/layout.h 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/layout.h 2004-09-24 17:06:27 +01:00
@@ -112,52 +112,49 @@
* Magic identifiers present at the beginning of all ntfs record containing
* records (like mft records for example).
*/
-typedef enum {
- /* Found in $MFT/$DATA. */
- magic_FILE = const_cpu_to_le32(0x454c4946), /* Mft entry. */
- magic_INDX = const_cpu_to_le32(0x58444e49), /* Index buffer. */
- magic_HOLE = const_cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */
-
- /* Found in $LogFile/$DATA. */
- magic_RSTR = const_cpu_to_le32(0x52545352), /* Restart page. */
- magic_RCRD = const_cpu_to_le32(0x44524352), /* Log record page. */
-
- /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */
- magic_CHKD = const_cpu_to_le32(0x424b4843), /* Modified by chkdsk. */
-
- /* Found in all ntfs record containing records. */
- magic_BAAD = const_cpu_to_le32(0x44414142), /* Failed multi sector
- transfer was detected. */
-
- /*
- * Found in $LogFile/$DATA when a page is full or 0xff bytes and is
- * thus not initialized. User has to initialize the page before using
- * it.
- */
- magic_empty = const_cpu_to_le32(0xffffffff),/* Record is empty and has
- to be initialized before
- it can be used. */
-} NTFS_RECORD_TYPES;
+/* Found in $MFT/$DATA. */
+#define magic_FILE const_cpu_to_le32(0x454c4946) /* Mft entry. */
+#define magic_INDX const_cpu_to_le32(0x58444e49) /* Index buffer. */
+#define magic_HOLE const_cpu_to_le32(0x454c4f48) /* ? (NTFS 3.0+?) */
+
+/* Found in $LogFile/$DATA. */
+#define magic_RSTR const_cpu_to_le32(0x52545352) /* Restart page. */
+#define magic_RCRD const_cpu_to_le32(0x44524352) /* Log record page. */
+
+/* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */
+#define magic_CHKD const_cpu_to_le32(0x424b4843) /* Modified by chkdsk. */
+
+/* Found in all ntfs record containing records. */
+#define magic_BAAD const_cpu_to_le32(0x44414142) /* Failed multi sector
+ transfer was detected. */
+/*
+ * Found in $LogFile/$DATA when a page is full or 0xff bytes and is thus not
+ * initialized. User has to initialize the page before using it.
+ */
+#define magic_empty const_cpu_to_le32(0xffffffff)/* Record is empty and has to
+ be initialized before it
+ can be used. */
+typedef le32 NTFS_RECORD_TYPE;
/*
* Generic magic comparison macros. Finally found a use for the ## preprocessor
* operator! (-8
*/
-static inline BOOL __ntfs_is_magic(le32 x, NTFS_RECORD_TYPES r)
+static inline BOOL __ntfs_is_magic(le32 x, NTFS_RECORD_TYPE r)
{
return (x == (__force le32)r);
}
#define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m)
-static inline BOOL __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPES r)
+static inline BOOL __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPE r)
{
return (*p == (__force le32)r);
}
#define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m)
/*
- * Specialised magic comparison macros for the NTFS_RECORD_TYPES defined above.
+ * Specialised magic comparison macros for the NTFS_RECORD_TYPEs defined above.
*/
#define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) )
#define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) )
@@ -199,8 +196,8 @@
* (usa_count * 2) has to be less than or equal to 510.
*/
typedef struct {
- NTFS_RECORD_TYPES magic; /* A four-byte magic identifying the
- record type and/or status. */
+ NTFS_RECORD_TYPE magic; /* A four-byte magic identifying the record
+ type and/or status. */
le16 usa_ofs; /* Offset to the Update Sequence Array (usa)
from the start of the ntfs record. */
le16 usa_count; /* Number of le16 sized entries in the usa
@@ -259,11 +256,10 @@
* These are the so far known MFT_RECORD_* flags (16-bit) which contain
* information about the mft record in which they are present.
*/
-typedef enum {
- MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001),
- MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002),
- MFT_REC_SPACE_FILLER = 0xffff /* Just to make flags 16-bit. */
-} __attribute__ ((__packed__)) MFT_RECORD_FLAGS;
+#define MFT_RECORD_IN_USE const_cpu_to_le16(0x0001)
+#define MFT_RECORD_IS_DIRECTORY const_cpu_to_le16(0x0002)
+
+typedef le16 MFT_RECORD_FLAGS;
/*
* mft references (aka file references or file record segment references) are
@@ -336,7 +332,7 @@
typedef struct {
/*Ofs*/
/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
- NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */
+ NTFS_RECORD_TYPE magic; /* Usually the magic is "FILE". */
le16 usa_ofs; /* See NTFS_RECORD definition above. */
le16 usa_count; /* See NTFS_RECORD definition above. */
@@ -403,38 +399,40 @@
} __attribute__ ((__packed__)) MFT_RECORD;
/*
- * System defined attributes (32-bit). Each attribute type has a corresponding
+ * System defined attributes (32-bit). Each attribute type has a corresponding
* attribute name (Unicode string of maximum 64 character length) as described
* by the attribute definitions present in the data attribute of the $AttrDef
- * system file. On NTFS 3.0 volumes the names are just as the types are named
- * in the below enum exchanging AT_ for the dollar sign ($). If that isn't a
- * revealing choice of symbol... (-;
- */
-typedef enum {
- AT_UNUSED = const_cpu_to_le32( 0),
- AT_STANDARD_INFORMATION = const_cpu_to_le32( 0x10),
- AT_ATTRIBUTE_LIST = const_cpu_to_le32( 0x20),
- AT_FILE_NAME = const_cpu_to_le32( 0x30),
- AT_OBJECT_ID = const_cpu_to_le32( 0x40),
- AT_SECURITY_DESCRIPTOR = const_cpu_to_le32( 0x50),
- AT_VOLUME_NAME = const_cpu_to_le32( 0x60),
- AT_VOLUME_INFORMATION = const_cpu_to_le32( 0x70),
- AT_DATA = const_cpu_to_le32( 0x80),
- AT_INDEX_ROOT = const_cpu_to_le32( 0x90),
- AT_INDEX_ALLOCATION = const_cpu_to_le32( 0xa0),
- AT_BITMAP = const_cpu_to_le32( 0xb0),
- AT_REPARSE_POINT = const_cpu_to_le32( 0xc0),
- AT_EA_INFORMATION = const_cpu_to_le32( 0xd0),
- AT_EA = const_cpu_to_le32( 0xe0),
- AT_PROPERTY_SET = const_cpu_to_le32( 0xf0),
- AT_LOGGED_UTILITY_STREAM = const_cpu_to_le32( 0x100),
- AT_FIRST_USER_DEFINED_ATTRIBUTE = const_cpu_to_le32( 0x1000),
- AT_END = const_cpu_to_le32(0xffffffff),
-} ATTR_TYPES;
+ * system file. On NTFS 3.0 volumes the names are just as the types are named
+ * in the below defines exchanging AT_ for the dollar sign ($). If that is not
+ * a revealing choice of symbol I do not know what is... (-;
+ */
+#define AT_UNUSED const_cpu_to_le32( 0)
+#define AT_STANDARD_INFORMATION const_cpu_to_le32( 0x10)
+#define AT_ATTRIBUTE_LIST const_cpu_to_le32( 0x20)
+#define AT_FILE_NAME const_cpu_to_le32( 0x30)
+#define AT_OBJECT_ID const_cpu_to_le32( 0x40)
+#define AT_SECURITY_DESCRIPTOR const_cpu_to_le32( 0x50)
+#define AT_VOLUME_NAME const_cpu_to_le32( 0x60)
+#define AT_VOLUME_INFORMATION const_cpu_to_le32( 0x70)
+#define AT_DATA const_cpu_to_le32( 0x80)
+#define AT_INDEX_ROOT const_cpu_to_le32( 0x90)
+#define AT_INDEX_ALLOCATION const_cpu_to_le32( 0xa0)
+#define AT_BITMAP const_cpu_to_le32( 0xb0)
+#define AT_REPARSE_POINT const_cpu_to_le32( 0xc0)
+#define AT_EA_INFORMATION const_cpu_to_le32( 0xd0)
+#define AT_EA const_cpu_to_le32( 0xe0)
+#define AT_PROPERTY_SET const_cpu_to_le32( 0xf0)
+#define AT_LOGGED_UTILITY_STREAM const_cpu_to_le32( 0x100)
+#define AT_FIRST_USER_DEFINED_ATTRIBUTE const_cpu_to_le32( 0x1000)
+#define AT_END const_cpu_to_le32(0xffffffff)
+
+typedef le32 ATTR_TYPE;
/*
* The collation rules for sorting views/indexes/etc (32-bit).
*
+ * COLLATION_BINARY - Collate by binary compare where the first byte is most
+ * significant.
* COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary
* Unicode values, except that when a character can be uppercased, the
* upper case value collates before the lower case one.
@@ -468,40 +466,32 @@
* the 2nd object_id. If the first le32 values of both object_ids were
* equal then the second le32 values would be compared, etc.
*/
-typedef enum {
- COLLATION_BINARY = const_cpu_to_le32(0x00), /* Collate by
- binary compare where the first byte is
- most significant. */
- COLLATION_FILE_NAME = const_cpu_to_le32(0x01), /* Collate file
- names as Unicode strings. */
- COLLATION_UNICODE_STRING = const_cpu_to_le32(0x02), /* Collate Unicode
- strings by comparing their binary
- Unicode values, except that when a
- character can be uppercased, the upper
- case value collates before the lower
- case one. */
- COLLATION_NTOFS_ULONG = const_cpu_to_le32(0x10),
- COLLATION_NTOFS_SID = const_cpu_to_le32(0x11),
- COLLATION_NTOFS_SECURITY_HASH = const_cpu_to_le32(0x12),
- COLLATION_NTOFS_ULONGS = const_cpu_to_le32(0x13),
-} COLLATION_RULES;
+#define COLLATION_BINARY const_cpu_to_le32(0x00)
+#define COLLATION_FILE_NAME const_cpu_to_le32(0x01)
+#define COLLATION_UNICODE_STRING const_cpu_to_le32(0x02)
+#define COLLATION_NTOFS_ULONG const_cpu_to_le32(0x10)
+#define COLLATION_NTOFS_SID const_cpu_to_le32(0x11)
+#define COLLATION_NTOFS_SECURITY_HASH const_cpu_to_le32(0x12)
+#define COLLATION_NTOFS_ULONGS const_cpu_to_le32(0x13)
+
+typedef le32 COLLATION_RULE;
/*
* The flags (32-bit) describing attribute properties in the attribute
- * definition structure. FIXME: This information is from Regis's information
+ * definition structure. FIXME: This information is from Regis's information
* and, according to him, it is not certain and probably incomplete.
* The INDEXABLE flag is fairly certainly correct as only the file name
* attribute has this flag set and this is the only attribute indexed in NT4.
*/
-typedef enum {
- INDEXABLE = const_cpu_to_le32(0x02), /* Attribute can be
- indexed. */
- NEED_TO_REGENERATE = const_cpu_to_le32(0x40), /* Need to regenerate
- during regeneration
- phase. */
- CAN_BE_NON_RESIDENT = const_cpu_to_le32(0x80), /* Attribute can be
- non-resident. */
-} ATTR_DEF_FLAGS;
+#define INDEXABLE const_cpu_to_le32(0x02) /* Attribute can be
+ indexed. */
+#define NEED_TO_REGENERATE const_cpu_to_le32(0x40) /* Need to regenerate
+ during regeneration
+ phase. */
+#define CAN_BE_NON_RESIDENT const_cpu_to_le32(0x80) /* Attribute can be
+ non-resident. */
+
+typedef le32 ATTR_DEF_FLAGS;
/*
* The data attribute of FILE_AttrDef contains a sequence of attribute
@@ -516,10 +506,10 @@
/*hex ofs*/
/* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero
terminated. */
-/* 80*/ ATTR_TYPES type; /* Type of the attribute. */
+/* 80*/ ATTR_TYPE type; /* Type of the attribute. */
/* 84*/ le32 display_rule; /* Default display rule.
FIXME: What does it mean? (AIA) */
-/* 88*/ COLLATION_RULES collation_rule; /* Default collation rule. */
+/* 88*/ COLLATION_RULE collation_rule; /* Default collation rule. */
/* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */
/* 90*/ le64 min_size; /* Optional minimum attribute size. */
/* 98*/ le64 max_size; /* Maximum size of attribute. */
@@ -529,14 +519,14 @@
/*
* Attribute flags (16-bit).
*/
-typedef enum {
- ATTR_IS_COMPRESSED = const_cpu_to_le16(0x0001),
- ATTR_COMPRESSION_MASK = const_cpu_to_le16(0x00ff), /* Compression
- method mask. Also, first
- illegal value. */
- ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000),
- ATTR_IS_SPARSE = const_cpu_to_le16(0x8000),
-} __attribute__ ((__packed__)) ATTR_FLAGS;
+#define ATTR_IS_COMPRESSED const_cpu_to_le16(0x0001)
+#define ATTR_COMPRESSION_MASK const_cpu_to_le16(0x00ff) /* Compression method
+ mask. Also, first
+ illegal value. */
+#define ATTR_IS_ENCRYPTED const_cpu_to_le16(0x4000)
+#define ATTR_IS_SPARSE const_cpu_to_le16(0x8000)
+
+typedef le16 ATTR_FLAGS;
/*
* Attribute compression.
@@ -608,18 +598,18 @@
/*
* Flags of resident attributes (8-bit).
*/
-typedef enum {
- RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index
- (has implications for deleting and
- modifying the attribute). */
-} __attribute__ ((__packed__)) RESIDENT_ATTR_FLAGS;
+#define RESIDENT_ATTR_IS_INDEXED 0x01 /* Attribute is referenced in an index
+ (has implications for deleting and
+ modifying the attribute). */
+
+typedef u8 RESIDENT_ATTR_FLAGS;
/*
* Attribute record header. Always aligned to 8-byte boundary.
*/
typedef struct {
/*Ofs*/
-/* 0*/ ATTR_TYPES type; /* The (32-bit) type of the attribute. */
+/* 0*/ ATTR_TYPE type; /* The (32-bit) type of the attribute. */
/* 4*/ le32 length; /* Byte size of the resident part of the
attribute (aligned to 8-byte boundary).
Used to get to the next attribute. */
@@ -713,57 +703,56 @@
/*
* File attribute flags (32-bit).
+ *
+ * The following flags are only present in the STANDARD_INFORMATION attribute
+ * (in the field file_attributes).
*/
-typedef enum {
- /*
- * These flags are only present in the STANDARD_INFORMATION attribute
- * (in the field file_attributes).
- */
- FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001),
- FILE_ATTR_HIDDEN = const_cpu_to_le32(0x00000002),
- FILE_ATTR_SYSTEM = const_cpu_to_le32(0x00000004),
- /* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */
-
- FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010),
- /* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved
- for the DOS SUBDIRECTORY flag. */
- FILE_ATTR_ARCHIVE = const_cpu_to_le32(0x00000020),
- FILE_ATTR_DEVICE = const_cpu_to_le32(0x00000040),
- FILE_ATTR_NORMAL = const_cpu_to_le32(0x00000080),
-
- FILE_ATTR_TEMPORARY = const_cpu_to_le32(0x00000100),
- FILE_ATTR_SPARSE_FILE = const_cpu_to_le32(0x00000200),
- FILE_ATTR_REPARSE_POINT = const_cpu_to_le32(0x00000400),
- FILE_ATTR_COMPRESSED = const_cpu_to_le32(0x00000800),
-
- FILE_ATTR_OFFLINE = const_cpu_to_le32(0x00001000),
- FILE_ATTR_NOT_CONTENT_INDEXED = const_cpu_to_le32(0x00002000),
- FILE_ATTR_ENCRYPTED = const_cpu_to_le32(0x00004000),
-
- FILE_ATTR_VALID_FLAGS = const_cpu_to_le32(0x00007fb7),
- /* FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the
- FILE_ATTR_DEVICE and preserves everything else. This mask
- is used to obtain all flags that are valid for reading. */
- FILE_ATTR_VALID_SET_FLAGS = const_cpu_to_le32(0x000031a7),
- /* FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the
- F_A_DEVICE, F_A_DIRECTORY, F_A_SPARSE_FILE, F_A_REPARSE_POINT,
- F_A_COMPRESSED and F_A_ENCRYPTED and preserves the rest. This mask
- is used to to obtain all flags that are valid for setting. */
+#define FILE_ATTR_READONLY const_cpu_to_le32(0x00000001)
+#define FILE_ATTR_HIDDEN const_cpu_to_le32(0x00000002)
+#define FILE_ATTR_SYSTEM const_cpu_to_le32(0x00000004)
+/* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */
+
+#define FILE_ATTR_DIRECTORY const_cpu_to_le32(0x00000010)
+/* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved for the
+ DOS SUBDIRECTORY flag. */
+#define FILE_ATTR_ARCHIVE const_cpu_to_le32(0x00000020)
+#define FILE_ATTR_DEVICE const_cpu_to_le32(0x00000040)
+#define FILE_ATTR_NORMAL const_cpu_to_le32(0x00000080)
+
+#define FILE_ATTR_TEMPORARY const_cpu_to_le32(0x00000100)
+#define FILE_ATTR_SPARSE_FILE const_cpu_to_le32(0x00000200)
+#define FILE_ATTR_REPARSE_POINT const_cpu_to_le32(0x00000400)
+#define FILE_ATTR_COMPRESSED const_cpu_to_le32(0x00000800)
+
+#define FILE_ATTR_OFFLINE const_cpu_to_le32(0x00001000)
+#define FILE_ATTR_NOT_CONTENT_INDEXED const_cpu_to_le32(0x00002000)
+#define FILE_ATTR_ENCRYPTED const_cpu_to_le32(0x00004000)
+
+#define FILE_ATTR_VALID_FLAGS const_cpu_to_le32(0x00007fb7)
+/* FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the FILE_ATTR_DEVICE
+ and preserves everything else. This mask is used to obtain all flags that
+ are valid for reading. */
+#define FILE_ATTR_VALID_SET_FLAGS const_cpu_to_le32(0x000031a7)
+/* FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the F_A_DEVICE,
+ F_A_DIRECTORY, F_A_SPARSE_FILE, F_A_REPARSE_POINT, F_A_COMPRESSED, and
+ F_A_ENCRYPTED and preserves the rest. This mask is used to to obtain all
+ flags that are valid for setting. */
+
+/*
+ * The following flags are only present in the FILE_NAME attribute (in the
+ * field file_attributes).
+ */
+#define FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT const_cpu_to_le32(0x10000000)
+/* This is a copy of the corresponding bit from the mft record, telling us
+ whether this is a directory or not, i.e. whether it has an index root
+ attribute or not. */
+#define FILE_ATTR_DUP_VIEW_INDEX_PRESENT const_cpu_to_le32(0x20000000)
+/* This is a copy of the corresponding bit from the mft record, telling us
+ whether this file has a view index present (eg. object id index, quota
+ index, one of the security indexes or the encrypting file system related
+ indexes). */
- /*
- * These flags are only present in the FILE_NAME attribute (in the
- * field file_attributes).
- */
- FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT = const_cpu_to_le32(0x10000000),
- /* This is a copy of the corresponding bit from the mft record, telling
- us whether this is a directory or not, i.e. whether it has an
- index root attribute or not. */
- FILE_ATTR_DUP_VIEW_INDEX_PRESENT = const_cpu_to_le32(0x20000000),
- /* This is a copy of the corresponding bit from the mft record, telling
- us whether this file has a view index present (eg. object id index,
- quota index, one of the security indexes or the encrypting file
- system related indexes). */
-} FILE_ATTR_FLAGS;
+typedef le32 FILE_ATTR_FLAGS;
/*
* NOTE on times in NTFS: All times are in MS standard time format, i.e. they
@@ -896,7 +885,7 @@
*/
typedef struct {
/*Ofs*/
-/* 0*/ ATTR_TYPES type; /* Type of referenced attribute. */
+/* 0*/ ATTR_TYPE type; /* Type of referenced attribute. */
/* 4*/ le16 length; /* Byte size of this entry (8-byte aligned). */
/* 6*/ u8 name_length; /* Size in Unicode chars of the name of the
attribute or 0 if unnamed. */
@@ -934,28 +923,26 @@
/*
* Possible namespaces for filenames in ntfs (8-bit).
*/
-typedef enum {
- FILE_NAME_POSIX = 0x00,
- /* This is the largest namespace. It is case sensitive and
- allows all Unicode characters except for: '\0' and '/'.
- Beware that in WinNT/2k files which eg have the same name
- except for their case will not be distinguished by the
- standard utilities and thus a "del filename" will delete
- both "filename" and "fileName" without warning. */
- FILE_NAME_WIN32 = 0x01,
- /* The standard WinNT/2k NTFS long filenames. Case insensitive.
- All Unicode chars except: '\0', '"', '*', '/', ':', '<',
- '>', '?', '\' and '|'. Further, names cannot end with a '.'
- or a space. */
- FILE_NAME_DOS = 0x02,
- /* The standard DOS filenames (8.3 format). Uppercase only.
- All 8-bit characters greater space, except: '"', '*', '+',
- ',', '/', ':', ';', '<', '=', '>', '?' and '\'. */
- FILE_NAME_WIN32_AND_DOS = 0x03,
- /* 3 means that both the Win32 and the DOS filenames are
- identical and hence have been saved in this single filename
- record. */
-} __attribute__ ((__packed__)) FILE_NAME_TYPE_FLAGS;
+#define FILE_NAME_POSIX 0x00
+ /* This is the largest namespace. It is case sensitive and allows all
+ Unicode characters except for: '\0' and '/'. Beware that in
+ WinNT/2k files which eg have the same name except for their case
+ will not be distinguished by the standard utilities and thus a "del
+ filename" will delete both "filename" and "fileName" without
+ warning. */
+#define FILE_NAME_WIN32 0x01
+ /* The standard WinNT/2k NTFS long filenames. Case insensitive. All
+ Unicode chars except: '\0', '"', '*', '/', ':', '<', '>', '?', '\',
+ and '|'. Further, names cannot end with a '.' or a space. */
+#define FILE_NAME_DOS 0x02
+ /* The standard DOS filenames (8.3 format). Uppercase only. All 8-bit
+ characters greater space, except: '"', '*', '+', ',', '/', ':', ';',
+ '<', '=', '>', '?', and '\'. */
+#define FILE_NAME_WIN32_AND_DOS 0x03
+ /* 3 means that both the Win32 and the DOS filenames are identical and
+ hence have been saved in this single filename record. */
+
+typedef u8 FILE_NAME_TYPE_FLAGS;
/*
* Attribute: Filename (0x30).
@@ -1261,30 +1248,31 @@
/*
* The predefined ACE types (8-bit, see below).
*/
-typedef enum {
- ACCESS_MIN_MS_ACE_TYPE = 0,
- ACCESS_ALLOWED_ACE_TYPE = 0,
- ACCESS_DENIED_ACE_TYPE = 1,
- SYSTEM_AUDIT_ACE_TYPE = 2,
- SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */
- ACCESS_MAX_MS_V2_ACE_TYPE = 3,
-
- ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4,
- ACCESS_MAX_MS_V3_ACE_TYPE = 4,
-
- /* The following are Win2k only. */
- ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5,
- ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5,
- ACCESS_DENIED_OBJECT_ACE_TYPE = 6,
- SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7,
- SYSTEM_ALARM_OBJECT_ACE_TYPE = 8,
- ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8,
-
- ACCESS_MAX_MS_V4_ACE_TYPE = 8,
-
- /* This one is for WinNT&2k. */
- ACCESS_MAX_MS_ACE_TYPE = 8,
-} __attribute__ ((__packed__)) ACE_TYPES;
+#define ACCESS_MIN_MS_ACE_TYPE 0
+#define ACCESS_ALLOWED_ACE_TYPE 0
+#define ACCESS_DENIED_ACE_TYPE 1
+#define SYSTEM_AUDIT_ACE_TYPE 2
+#define SYSTEM_ALARM_ACE_TYPE 3 /* Not implemented as of
+ Win2k. */
+#define ACCESS_MAX_MS_V2_ACE_TYPE 3
+
+#define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 4
+#define ACCESS_MAX_MS_V3_ACE_TYPE 4
+
+/* The following are Win2k only. */
+#define ACCESS_MIN_MS_OBJECT_ACE_TYPE 5
+#define ACCESS_ALLOWED_OBJECT_ACE_TYPE 5
+#define ACCESS_DENIED_OBJECT_ACE_TYPE 6
+#define SYSTEM_AUDIT_OBJECT_ACE_TYPE 7
+#define SYSTEM_ALARM_OBJECT_ACE_TYPE 8
+#define ACCESS_MAX_MS_OBJECT_ACE_TYPE 8
+
+#define ACCESS_MAX_MS_V4_ACE_TYPE 8
+
+/* This one is for WinNT/2k. */
+#define ACCESS_MAX_MS_ACE_TYPE 8
+
+typedef u8 ACE_TYPES;
/*
* The ACE flags (8-bit) for audit and inheritance (see below).
@@ -1296,19 +1284,19 @@
* FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types
* to indicate that a message is generated (in Windows!) for failed accesses.
*/
-typedef enum {
- /* The inheritance flags. */
- OBJECT_INHERIT_ACE = 0x01,
- CONTAINER_INHERIT_ACE = 0x02,
- NO_PROPAGATE_INHERIT_ACE = 0x04,
- INHERIT_ONLY_ACE = 0x08,
- INHERITED_ACE = 0x10, /* Win2k only. */
- VALID_INHERIT_FLAGS = 0x1f,
-
- /* The audit flags. */
- SUCCESSFUL_ACCESS_ACE_FLAG = 0x40,
- FAILED_ACCESS_ACE_FLAG = 0x80,
-} __attribute__ ((__packed__)) ACE_FLAGS;
+/* The inheritance flags. */
+#define OBJECT_INHERIT_ACE 0x01
+#define CONTAINER_INHERIT_ACE 0x02
+#define NO_PROPAGATE_INHERIT_ACE 0x04
+#define INHERIT_ONLY_ACE 0x08
+#define INHERITED_ACE 0x10 /* Win2k only. */
+#define VALID_INHERIT_FLAGS 0x1f
+
+/* The audit flags. */
+#define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
+#define FAILED_ACCESS_ACE_FLAG 0x80
+
+typedef u8 ACE_FLAGS;
/*
* An ACE is an access-control entry in an access-control list (ACL).
@@ -1330,136 +1318,135 @@
/*
* The access mask (32-bit). Defines the access rights.
+ *
+ * The specific rights (bits 0 to 15). These depend on the type of the object
+ * being secured by the ACE.
*/
-typedef enum {
- /*
- * The specific rights (bits 0 to 15). Depend on the type of the
- * object being secured by the ACE.
- */
- /* Specific rights for files and directories are as follows: */
+/* Specific rights for files and directories are as follows: */
- /* Right to read data from the file. (FILE) */
- FILE_READ_DATA = const_cpu_to_le32(0x00000001),
- /* Right to list contents of a directory. (DIRECTORY) */
- FILE_LIST_DIRECTORY = const_cpu_to_le32(0x00000001),
-
- /* Right to write data to the file. (FILE) */
- FILE_WRITE_DATA = const_cpu_to_le32(0x00000002),
- /* Right to create a file in the directory. (DIRECTORY) */
- FILE_ADD_FILE = const_cpu_to_le32(0x00000002),
-
- /* Right to append data to the file. (FILE) */
- FILE_APPEND_DATA = const_cpu_to_le32(0x00000004),
- /* Right to create a subdirectory. (DIRECTORY) */
- FILE_ADD_SUBDIRECTORY = const_cpu_to_le32(0x00000004),
-
- /* Right to read extended attributes. (FILE/DIRECTORY) */
- FILE_READ_EA = const_cpu_to_le32(0x00000008),
-
- /* Right to write extended attributes. (FILE/DIRECTORY) */
- FILE_WRITE_EA = const_cpu_to_le32(0x00000010),
-
- /* Right to execute a file. (FILE) */
- FILE_EXECUTE = const_cpu_to_le32(0x00000020),
- /* Right to traverse the directory. (DIRECTORY) */
- FILE_TRAVERSE = const_cpu_to_le32(0x00000020),
+/* Right to read data from the file. (FILE) */
+#define FILE_READ_DATA const_cpu_to_le32(0x00000001)
+/* Right to list contents of a directory. (DIRECTORY) */
+#define FILE_LIST_DIRECTORY const_cpu_to_le32(0x00000001)
- /*
- * Right to delete a directory and all the files it contains (its
- * children), even if the files are read-only. (DIRECTORY)
- */
- FILE_DELETE_CHILD = const_cpu_to_le32(0x00000040),
+/* Right to write data to the file. (FILE) */
+#define FILE_WRITE_DATA const_cpu_to_le32(0x00000002)
+/* Right to create a file in the directory. (DIRECTORY) */
+#define FILE_ADD_FILE const_cpu_to_le32(0x00000002)
- /* Right to read file attributes. (FILE/DIRECTORY) */
- FILE_READ_ATTRIBUTES = const_cpu_to_le32(0x00000080),
+/* Right to append data to the file. (FILE) */
+#define FILE_APPEND_DATA const_cpu_to_le32(0x00000004)
+/* Right to create a subdirectory. (DIRECTORY) */
+#define FILE_ADD_SUBDIRECTORY const_cpu_to_le32(0x00000004)
- /* Right to change file attributes. (FILE/DIRECTORY) */
- FILE_WRITE_ATTRIBUTES = const_cpu_to_le32(0x00000100),
+/* Right to read extended attributes. (FILE/DIRECTORY) */
+#define FILE_READ_EA const_cpu_to_le32(0x00000008)
- /*
- * The standard rights (bits 16 to 23). Are independent of the type of
- * object being secured.
- */
+/* Right to write extended attributes. (FILE/DIRECTORY) */
+#define FILE_WRITE_EA const_cpu_to_le32(0x00000010)
- /* Right to delete the object. */
- DELETE = const_cpu_to_le32(0x00010000),
+/* Right to execute a file. (FILE) */
+#define FILE_EXECUTE const_cpu_to_le32(0x00000020)
+/* Right to traverse the directory. (DIRECTORY) */
+#define FILE_TRAVERSE const_cpu_to_le32(0x00000020)
- /*
- * Right to read the information in the object's security descriptor,
- * not including the information in the SACL. I.e. right to read the
- * security descriptor and owner.
- */
- READ_CONTROL = const_cpu_to_le32(0x00020000),
+/*
+ * Right to delete a directory and all the files it contains (its children),
+ * even if the files are read-only. (DIRECTORY)
+ */
+#define FILE_DELETE_CHILD const_cpu_to_le32(0x00000040)
- /* Right to modify the DACL in the object's security descriptor. */
- WRITE_DAC = const_cpu_to_le32(0x00040000),
+/* Right to read file attributes. (FILE/DIRECTORY) */
+#define FILE_READ_ATTRIBUTES const_cpu_to_le32(0x00000080)
- /* Right to change the owner in the object's security descriptor. */
- WRITE_OWNER = const_cpu_to_le32(0x00080000),
+/* Right to change file attributes. (FILE/DIRECTORY) */
+#define FILE_WRITE_ATTRIBUTES const_cpu_to_le32(0x00000100)
- /*
- * Right to use the object for synchronization. Enables a process to
- * wait until the object is in the signalled state. Some object types
- * do not support this access right.
- */
- SYNCHRONIZE = const_cpu_to_le32(0x00100000),
+/*
+ * The standard rights (bits 16 to 23). These are independent of the type of
+ * object being secured.
+ */
- /*
- * The following STANDARD_RIGHTS_* are combinations of the above for
- * convenience and are defined by the Win32 API.
- */
+/* Right to delete the object. */
+#define DELETE const_cpu_to_le32(0x00010000)
- /* These are currently defined to READ_CONTROL. */
- STANDARD_RIGHTS_READ = const_cpu_to_le32(0x00020000),
- STANDARD_RIGHTS_WRITE = const_cpu_to_le32(0x00020000),
- STANDARD_RIGHTS_EXECUTE = const_cpu_to_le32(0x00020000),
+/*
+ * Right to read the information in the object's security descriptor, not
+ * including the information in the SACL. I.e. right to read the security
+ * descriptor and owner.
+ */
+#define READ_CONTROL const_cpu_to_le32(0x00020000)
- /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */
- STANDARD_RIGHTS_REQUIRED = const_cpu_to_le32(0x000f0000),
+/* Right to modify the DACL in the object's security descriptor. */
+#define WRITE_DAC const_cpu_to_le32(0x00040000)
- /*
- * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and
- * SYNCHRONIZE access.
- */
- STANDARD_RIGHTS_ALL = const_cpu_to_le32(0x001f0000),
+/* Right to change the owner in the object's security descriptor. */
+#define WRITE_OWNER const_cpu_to_le32(0x00080000)
- /*
- * The access system ACL and maximum allowed access types (bits 24 to
- * 25, bits 26 to 27 are reserved).
- */
- ACCESS_SYSTEM_SECURITY = const_cpu_to_le32(0x01000000),
- MAXIMUM_ALLOWED = const_cpu_to_le32(0x02000000),
+/*
+ * Right to use the object for synchronization. Enables a process to wait until
+ * the object is in the signalled state. Some object types do not support this
+ * access right.
+ */
+#define SYNCHRONIZE const_cpu_to_le32(0x00100000)
- /*
- * The generic rights (bits 28 to 31). These map onto the standard and
- * specific rights.
- */
+/*
+ * The following STANDARD_RIGHTS_* are combinations of the above for
+ * convenience and are defined by the Win32 API.
+ */
- /* Read, write, and execute access. */
- GENERIC_ALL = const_cpu_to_le32(0x10000000),
+/* These are currently defined to READ_CONTROL. */
+#define STANDARD_RIGHTS_READ const_cpu_to_le32(0x00020000)
+#define STANDARD_RIGHTS_WRITE const_cpu_to_le32(0x00020000)
+#define STANDARD_RIGHTS_EXECUTE const_cpu_to_le32(0x00020000)
- /* Execute access. */
- GENERIC_EXECUTE = const_cpu_to_le32(0x20000000),
+/* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */
+#define STANDARD_RIGHTS_REQUIRED const_cpu_to_le32(0x000f0000)
- /*
- * Write access. For files, this maps onto:
- * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA |
- * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE
- * For directories, the mapping has the same numberical value. See
- * above for the descriptions of the rights granted.
- */
- GENERIC_WRITE = const_cpu_to_le32(0x40000000),
+/*
+ * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and
+ * SYNCHRONIZE access.
+ */
+#define STANDARD_RIGHTS_ALL const_cpu_to_le32(0x001f0000)
- /*
- * Read access. For files, this maps onto:
- * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA |
- * STANDARD_RIGHTS_READ | SYNCHRONIZE
- * For directories, the mapping has the same numberical value. See
- * above for the descriptions of the rights granted.
- */
- GENERIC_READ = const_cpu_to_le32(0x80000000),
-} ACCESS_MASK;
+/*
+ * The access system ACL and maximum allowed access types (bits 24 to
+ * 25, bits 26 to 27 are reserved).
+ */
+#define ACCESS_SYSTEM_SECURITY const_cpu_to_le32(0x01000000)
+#define MAXIMUM_ALLOWED const_cpu_to_le32(0x02000000)
+
+/*
+ * The generic rights (bits 28 to 31). These map onto the standard and specific
+ * rights.
+ */
+
+/* Read, write, and execute access. */
+#define GENERIC_ALL const_cpu_to_le32(0x10000000)
+
+/* Execute access. */
+#define GENERIC_EXECUTE const_cpu_to_le32(0x20000000)
+
+/*
+ * Write access. For files, this maps onto:
+ * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA |
+ * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE
+ * For directories, the mapping has the same numberical value. See above for
+ * the descriptions of the rights granted.
+ */
+#define GENERIC_WRITE const_cpu_to_le32(0x40000000)
+
+/*
+ * Read access. For files, this maps onto:
+ * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA |
+ * STANDARD_RIGHTS_READ | SYNCHRONIZE
+ * For directories, the mapping has the same numberical value. See above for
+ * the descriptions of the rights granted.
+ */
+#define GENERIC_READ const_cpu_to_le32(0x80000000)
+
+typedef le32 ACCESS_MASK;
/*
* The generic mapping array. Used to denote the mapping of each generic
@@ -1495,10 +1482,10 @@
/*
* The object ACE flags (32-bit).
*/
-typedef enum {
- ACE_OBJECT_TYPE_PRESENT = const_cpu_to_le32(1),
- ACE_INHERITED_OBJECT_TYPE_PRESENT = const_cpu_to_le32(2),
-} OBJECT_ACE_FLAGS;
+#define ACE_OBJECT_TYPE_PRESENT const_cpu_to_le32(1)
+#define ACE_INHERITED_OBJECT_TYPE_PRESENT const_cpu_to_le32(2)
+
+typedef le32 OBJECT_ACE_FLAGS;
typedef struct {
/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */
@@ -1595,22 +1582,22 @@
* security descriptor are contiguous in memory and all pointer fields are
* expressed as offsets from the beginning of the security descriptor.
*/
-typedef enum {
- SE_OWNER_DEFAULTED = const_cpu_to_le16(0x0001),
- SE_GROUP_DEFAULTED = const_cpu_to_le16(0x0002),
- SE_DACL_PRESENT = const_cpu_to_le16(0x0004),
- SE_DACL_DEFAULTED = const_cpu_to_le16(0x0008),
- SE_SACL_PRESENT = const_cpu_to_le16(0x0010),
- SE_SACL_DEFAULTED = const_cpu_to_le16(0x0020),
- SE_DACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0100),
- SE_SACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0200),
- SE_DACL_AUTO_INHERITED = const_cpu_to_le16(0x0400),
- SE_SACL_AUTO_INHERITED = const_cpu_to_le16(0x0800),
- SE_DACL_PROTECTED = const_cpu_to_le16(0x1000),
- SE_SACL_PROTECTED = const_cpu_to_le16(0x2000),
- SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000),
- SE_SELF_RELATIVE = const_cpu_to_le16(0x8000),
-} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_CONTROL;
+#define SE_OWNER_DEFAULTED const_cpu_to_le16(0x0001)
+#define SE_GROUP_DEFAULTED const_cpu_to_le16(0x0002)
+#define SE_DACL_PRESENT const_cpu_to_le16(0x0004)
+#define SE_DACL_DEFAULTED const_cpu_to_le16(0x0008)
+#define SE_SACL_PRESENT const_cpu_to_le16(0x0010)
+#define SE_SACL_DEFAULTED const_cpu_to_le16(0x0020)
+#define SE_DACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x0100)
+#define SE_SACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x0200)
+#define SE_DACL_AUTO_INHERITED const_cpu_to_le16(0x0400)
+#define SE_SACL_AUTO_INHERITED const_cpu_to_le16(0x0800)
+#define SE_DACL_PROTECTED const_cpu_to_le16(0x1000)
+#define SE_SACL_PROTECTED const_cpu_to_le16(0x2000)
+#define SE_RM_CONTROL_VALID const_cpu_to_le16(0x4000)
+#define SE_SELF_RELATIVE const_cpu_to_le16(0x8000)
+
+typedef le16 SECURITY_DESCRIPTOR_CONTROL;
/*
* Self-relative security descriptor. Contains the owner and group SIDs as well
@@ -1794,19 +1781,19 @@
/*
* Possible flags for the volume (16-bit).
*/
-typedef enum {
- VOLUME_IS_DIRTY = const_cpu_to_le16(0x0001),
- VOLUME_RESIZE_LOG_FILE = const_cpu_to_le16(0x0002),
- VOLUME_UPGRADE_ON_MOUNT = const_cpu_to_le16(0x0004),
- VOLUME_MOUNTED_ON_NT4 = const_cpu_to_le16(0x0008),
- VOLUME_DELETE_USN_UNDERWAY = const_cpu_to_le16(0x0010),
- VOLUME_REPAIR_OBJECT_ID = const_cpu_to_le16(0x0020),
- VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000),
- VOLUME_FLAGS_MASK = const_cpu_to_le16(0x803f),
-
- /* To make our life easier when checking if we must mount read-only. */
- VOLUME_MUST_MOUNT_RO_MASK = const_cpu_to_le16(0x8037),
-} __attribute__ ((__packed__)) VOLUME_FLAGS;
+#define VOLUME_IS_DIRTY const_cpu_to_le16(0x0001)
+#define VOLUME_RESIZE_LOG_FILE const_cpu_to_le16(0x0002)
+#define VOLUME_UPGRADE_ON_MOUNT const_cpu_to_le16(0x0004)
+#define VOLUME_MOUNTED_ON_NT4 const_cpu_to_le16(0x0008)
+#define VOLUME_DELETE_USN_UNDERWAY const_cpu_to_le16(0x0010)
+#define VOLUME_REPAIR_OBJECT_ID const_cpu_to_le16(0x0020)
+#define VOLUME_MODIFIED_BY_CHKDSK const_cpu_to_le16(0x8000)
+#define VOLUME_FLAGS_MASK const_cpu_to_le16(0x803f)
+
+/* To make our life easier when checking if we must mount read-only. */
+#define VOLUME_MUST_MOUNT_RO_MASK const_cpu_to_le16(0x8037)
+
+typedef le16 VOLUME_FLAGS;
/*
* Attribute: Volume information (0x70).
@@ -1836,25 +1823,26 @@
/*
* Index header flags (8-bit).
+ *
+ * When index header is in an index root attribute:
*/
-typedef enum {
- /* When index header is in an index root attribute: */
- SMALL_INDEX = 0, /* The index is small enough to fit inside the
- index root attribute and there is no index
- allocation attribute present. */
- LARGE_INDEX = 1, /* The index is too large to fit in the index
- root attribute and/or an index allocation
- attribute is present. */
- /*
- * When index header is in an index block, i.e. is part of index
- * allocation attribute:
- */
- LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more
- nodes branching off it. */
- INDEX_NODE = 1, /* This node indexes other nodes, i.e. is not a
- leaf node. */
- NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */
-} __attribute__ ((__packed__)) INDEX_HEADER_FLAGS;
+#define SMALL_INDEX 0 /* The index is small enough to fit inside the index root
+ attribute and there is no index allocation attribute
+ present. */
+#define LARGE_INDEX 1 /* The index is too large to fit in the index root
+ attribute and/or an index allocation attribute is
+ present. */
+/*
+ * When index header is in an index block, i.e. is part of index allocation
+ * attribute:
+ */
+#define LEAF_NODE 0 /* This is a leaf node, i.e. there are no more nodes
+ branching off it. */
+#define INDEX_NODE 1 /* This node indexes other nodes, i.e. it is not a leaf
+ node. */
+#define NODE_MASK 1 /* Mask for accessing the *_NODE bits. */
+
+typedef u8 INDEX_HEADER_FLAGS;
/*
* This is the header for indexes, describing the INDEX_ENTRY records, which
@@ -1904,11 +1892,11 @@
* dircetories do not contain entries for themselves, though.
*/
typedef struct {
- ATTR_TYPES type; /* Type of the indexed attribute. Is
+ ATTR_TYPE type; /* Type of the indexed attribute. Is
$FILE_NAME for directories, zero
for view indexes. No other values
allowed. */
- COLLATION_RULES collation_rule; /* Collation rule used to sort the
+ COLLATION_RULE collation_rule; /* Collation rule used to sort the
index entries. If type is $FILE_NAME,
this must be COLLATION_FILE_NAME. */
le32 index_block_size; /* Size of each index block in bytes (in
@@ -1937,7 +1925,7 @@
*/
typedef struct {
/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
- NTFS_RECORD_TYPES magic;/* Magic is "INDX". */
+ NTFS_RECORD_TYPE magic; /* Magic is "INDX". */
le16 usa_ofs; /* See NTFS_RECORD definition. */
le16 usa_count; /* See NTFS_RECORD definition. */
@@ -1980,27 +1968,28 @@
/*
* Quota flags (32-bit).
+ *
+ * The user quota flags. Names explain meaning.
*/
-typedef enum {
- /* The user quota flags. Names explain meaning. */
- QUOTA_FLAG_DEFAULT_LIMITS = const_cpu_to_le32(0x00000001),
- QUOTA_FLAG_LIMIT_REACHED = const_cpu_to_le32(0x00000002),
- QUOTA_FLAG_ID_DELETED = const_cpu_to_le32(0x00000004),
-
- QUOTA_FLAG_USER_MASK = const_cpu_to_le32(0x00000007),
- /* Bit mask for user quota flags. */
-
- /* These flags are only present in the quota defaults index entry,
- i.e. in the entry where owner_id = QUOTA_DEFAULTS_ID. */
- QUOTA_FLAG_TRACKING_ENABLED = const_cpu_to_le32(0x00000010),
- QUOTA_FLAG_ENFORCEMENT_ENABLED = const_cpu_to_le32(0x00000020),
- QUOTA_FLAG_TRACKING_REQUESTED = const_cpu_to_le32(0x00000040),
- QUOTA_FLAG_LOG_THRESHOLD = const_cpu_to_le32(0x00000080),
- QUOTA_FLAG_LOG_LIMIT = const_cpu_to_le32(0x00000100),
- QUOTA_FLAG_OUT_OF_DATE = const_cpu_to_le32(0x00000200),
- QUOTA_FLAG_CORRUPT = const_cpu_to_le32(0x00000400),
- QUOTA_FLAG_PENDING_DELETES = const_cpu_to_le32(0x00000800),
-} QUOTA_FLAGS;
+#define QUOTA_FLAG_DEFAULT_LIMITS const_cpu_to_le32(0x00000001)
+#define QUOTA_FLAG_LIMIT_REACHED const_cpu_to_le32(0x00000002)
+#define QUOTA_FLAG_ID_DELETED const_cpu_to_le32(0x00000004)
+
+#define QUOTA_FLAG_USER_MASK const_cpu_to_le32(0x00000007)
+ /* Bit mask for user quota flags. */
+
+/* These flags are only present in the quota defaults index entry, i.e. in the
+ entry where owner_id = QUOTA_DEFAULTS_ID. */
+#define QUOTA_FLAG_TRACKING_ENABLED const_cpu_to_le32(0x00000010)
+#define QUOTA_FLAG_ENFORCEMENT_ENABLED const_cpu_to_le32(0x00000020)
+#define QUOTA_FLAG_TRACKING_REQUESTED const_cpu_to_le32(0x00000040)
+#define QUOTA_FLAG_LOG_THRESHOLD const_cpu_to_le32(0x00000080)
+#define QUOTA_FLAG_LOG_LIMIT const_cpu_to_le32(0x00000100)
+#define QUOTA_FLAG_OUT_OF_DATE const_cpu_to_le32(0x00000200)
+#define QUOTA_FLAG_CORRUPT const_cpu_to_le32(0x00000400)
+#define QUOTA_FLAG_PENDING_DELETES const_cpu_to_le32(0x00000800)
+
+typedef le32 QUOTA_FLAGS;
/*
* The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas
@@ -2040,11 +2029,9 @@
/*
* Predefined owner_id values (32-bit).
*/
-typedef enum {
- QUOTA_INVALID_ID = const_cpu_to_le32(0x00000000),
- QUOTA_DEFAULTS_ID = const_cpu_to_le32(0x00000001),
- QUOTA_FIRST_USER_ID = const_cpu_to_le32(0x00000100),
-} PREDEFINED_OWNER_IDS;
+#define QUOTA_INVALID_ID const_cpu_to_le32(0x00000000)
+#define QUOTA_DEFAULTS_ID const_cpu_to_le32(0x00000001)
+#define QUOTA_FIRST_USER_ID const_cpu_to_le32(0x00000100)
/*
* Current constants for quota control entries.
@@ -2057,18 +2044,14 @@
/*
* Index entry flags (16-bit).
*/
-typedef enum {
- INDEX_ENTRY_NODE = const_cpu_to_le16(1), /* This entry contains a
- sub-node, i.e. a reference to an
- index block in form of a virtual
- cluster number (see below). */
- INDEX_ENTRY_END = const_cpu_to_le16(2), /* This signifies the last
- entry in an index block. The
- index entry does not represent a
- file but it can point to a
- sub-node. */
- INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */
-} __attribute__ ((__packed__)) INDEX_ENTRY_FLAGS;
+#define INDEX_ENTRY_NODE const_cpu_to_le16(1) /* This entry contains a
+ sub-node, i.e. a reference to an index block in form of
+ a virtual cluster number (see below). */
+#define INDEX_ENTRY_END const_cpu_to_le16(2) /* This signifies the last entry
+ in an index block. The index entry does not represent
+ a file but it can point to a sub-node. */
+
+typedef le16 INDEX_ENTRY_FLAGS;
/*
* This the index entry header (see below).
@@ -2198,29 +2181,29 @@
* be slow. (E.g. the data is stored on a tape drive.)
* bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User
* defined tags have to use zero here.
+ *
+ * These are the predefined reparse point tags:
*/
-typedef enum {
- IO_REPARSE_TAG_IS_ALIAS = const_cpu_to_le32(0x20000000),
- IO_REPARSE_TAG_IS_HIGH_LATENCY = const_cpu_to_le32(0x40000000),
- IO_REPARSE_TAG_IS_MICROSOFT = const_cpu_to_le32(0x80000000),
+#define IO_REPARSE_TAG_IS_ALIAS const_cpu_to_le32(0x20000000)
+#define IO_REPARSE_TAG_IS_HIGH_LATENCY const_cpu_to_le32(0x40000000)
+#define IO_REPARSE_TAG_IS_MICROSOFT const_cpu_to_le32(0x80000000)
- IO_REPARSE_TAG_RESERVED_ZERO = const_cpu_to_le32(0x00000000),
- IO_REPARSE_TAG_RESERVED_ONE = const_cpu_to_le32(0x00000001),
- IO_REPARSE_TAG_RESERVED_RANGE = const_cpu_to_le32(0x00000001),
+#define IO_REPARSE_TAG_RESERVED_ZERO const_cpu_to_le32(0x00000000)
+#define IO_REPARSE_TAG_RESERVED_ONE const_cpu_to_le32(0x00000001)
+#define IO_REPARSE_TAG_RESERVED_RANGE const_cpu_to_le32(0x00000001)
- IO_REPARSE_TAG_NSS = const_cpu_to_le32(0x68000005),
- IO_REPARSE_TAG_NSS_RECOVER = const_cpu_to_le32(0x68000006),
- IO_REPARSE_TAG_SIS = const_cpu_to_le32(0x68000007),
- IO_REPARSE_TAG_DFS = const_cpu_to_le32(0x68000008),
+#define IO_REPARSE_TAG_NSS const_cpu_to_le32(0x68000005)
+#define IO_REPARSE_TAG_NSS_RECOVER const_cpu_to_le32(0x68000006)
+#define IO_REPARSE_TAG_SIS const_cpu_to_le32(0x68000007)
+#define IO_REPARSE_TAG_DFS const_cpu_to_le32(0x68000008)
- IO_REPARSE_TAG_MOUNT_POINT = const_cpu_to_le32(0x88000003),
+#define IO_REPARSE_TAG_MOUNT_POINT const_cpu_to_le32(0x88000003)
- IO_REPARSE_TAG_HSM = const_cpu_to_le32(0xa8000004),
+#define IO_REPARSE_TAG_HSM const_cpu_to_le32(0xa8000004)
- IO_REPARSE_TAG_SYMBOLIC_LINK = const_cpu_to_le32(0xe8000000),
+#define IO_REPARSE_TAG_SYMBOLIC_LINK const_cpu_to_le32(0xe8000000)
- IO_REPARSE_TAG_VALID_VALUES = const_cpu_to_le32(0xe000ffff),
-} PREDEFINED_REPARSE_TAGS;
+#define IO_REPARSE_TAG_VALID_VALUES const_cpu_to_le32(0xe000ffff)
/*
* Attribute: Reparse point (0xc0).
@@ -2254,9 +2237,9 @@
/*
* Extended attribute flags (8-bit).
*/
-typedef enum {
- NEED_EA = 0x80,
-} __attribute__ ((__packed__)) EA_FLAGS;
+#define NEED_EA 0x80
+
+typedef u8 EA_FLAGS;
/*
* Attribute: Extended attribute (EA) (0xe0).
diff -Nru a/fs/ntfs/logfile.h b/fs/ntfs/logfile.h
--- a/fs/ntfs/logfile.h 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/logfile.h 2004-09-24 17:06:27 +01:00
@@ -67,7 +67,7 @@
typedef struct {
/*Ofs*/
/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */
-/* 0*/ NTFS_RECORD_TYPES magic;/* The magic is "RSTR". */
+/* 0*/ NTFS_RECORD_TYPE magic; /* The magic is "RSTR". */
/* 4*/ le16 usa_ofs; /* See NTFS_RECORD definition in layout.h.
When creating, set this to be immediately
after this header structure (without any
diff -Nru a/fs/ntfs/mft.c b/fs/ntfs/mft.c
--- a/fs/ntfs/mft.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/mft.c 2004-09-24 17:06:27 +01:00
@@ -44,7 +44,7 @@
m->usa_ofs = cpu_to_le16((sizeof(MFT_RECORD) + 1) & ~1);
m->usa_count = cpu_to_le16(size / NTFS_BLOCK_SIZE + 1);
/* Set the update sequence number to 1. */
- *(u16*)((char*)m + ((sizeof(MFT_RECORD) + 1) & ~1)) = cpu_to_le16(1);
+ *(le16*)((char*)m + ((sizeof(MFT_RECORD) + 1) & ~1)) = cpu_to_le16(1);
m->lsn = cpu_to_le64(0LL);
m->sequence_number = cpu_to_le16(1);
m->link_count = cpu_to_le16(0);
@@ -311,11 +311,11 @@
/**
* map_extent_mft_record - load an extent inode and attach it to its base
* @base_ni: base ntfs inode
- * @mref: mft reference of the extent inode to load (in little endian)
+ * @mref: mft reference of the extent inode to load
* @ntfs_ino: on successful return, pointer to the ntfs_inode structure
*
* Load the extent mft record @mref and attach it to its base inode @base_ni.
- * Return the mapped extent mft record if IS_ERR(result) is false. Otherwise
+ * Return the mapped extent mft record if IS_ERR(result) is false. Otherwise
* PTR_ERR(result) gives the negative error code.
*
* On successful return, @ntfs_ino contains a pointer to the ntfs_inode
@@ -328,8 +328,8 @@
ntfs_inode *ni = NULL;
ntfs_inode **extent_nis = NULL;
int i;
- unsigned long mft_no = MREF_LE(mref);
- u16 seq_no = MSEQNO_LE(mref);
+ unsigned long mft_no = MREF(mref);
+ u16 seq_no = MSEQNO(mref);
BOOL destroy_ni = FALSE;
ntfs_debug("Mapping extent mft record 0x%lx (base mft record 0x%lx).",
diff -Nru a/fs/ntfs/mst.c b/fs/ntfs/mst.c
--- a/fs/ntfs/mst.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/mst.c 2004-09-24 17:06:27 +01:00
@@ -122,8 +122,9 @@
*/
int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size)
{
+ le16 *usa_pos, *data_pos;
u16 usa_ofs, usa_count, usn;
- u16 *usa_pos, *data_pos;
+ le16 le_usn;
/* Sanity check + only fixup if it makes sense. */
if (!b || ntfs_is_baad_record(b->magic) ||
@@ -140,7 +141,7 @@
(size >> NTFS_BLOCK_SIZE_BITS) != usa_count)
return -EINVAL;
/* Position of usn in update sequence array. */
- usa_pos = (u16*)((u8*)b + usa_ofs);
+ usa_pos = (le16*)((u8*)b + usa_ofs);
/*
* Cyclically increment the update sequence number
* (skipping 0 and -1, i.e. 0xffff).
@@ -148,10 +149,10 @@
usn = le16_to_cpup(usa_pos) + 1;
if (usn == 0xffff || !usn)
usn = 1;
- usn = cpu_to_le16(usn);
- *usa_pos = usn;
+ le_usn = cpu_to_le16(usn);
+ *usa_pos = le_usn;
/* Position in data of first u16 that needs fixing up. */
- data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1;
+ data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1;
/* Fixup all sectors. */
while (usa_count--) {
/*
@@ -160,9 +161,9 @@
*/
*(++usa_pos) = *data_pos;
/* Apply fixup to data. */
- *data_pos = usn;
+ *data_pos = le_usn;
/* Increment position in data as well. */
- data_pos += NTFS_BLOCK_SIZE/sizeof(u16);
+ data_pos += NTFS_BLOCK_SIZE/sizeof(le16);
}
return 0;
}
@@ -177,16 +178,16 @@
*/
void post_write_mst_fixup(NTFS_RECORD *b)
{
- u16 *usa_pos, *data_pos;
+ le16 *usa_pos, *data_pos;
u16 usa_ofs = le16_to_cpu(b->usa_ofs);
u16 usa_count = le16_to_cpu(b->usa_count) - 1;
/* Position of usn in update sequence array. */
- usa_pos = (u16*)b + usa_ofs/sizeof(u16);
+ usa_pos = (le16*)b + usa_ofs/sizeof(le16);
/* Position in protected data of first u16 that needs fixing up. */
- data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1;
+ data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1;
/* Fixup all sectors. */
while (usa_count--) {
@@ -197,6 +198,6 @@
*data_pos = *(++usa_pos);
/* Increment position in data as well. */
- data_pos += NTFS_BLOCK_SIZE/sizeof(u16);
+ data_pos += NTFS_BLOCK_SIZE/sizeof(le16);
}
}
diff -Nru a/fs/ntfs/quota.c b/fs/ntfs/quota.c
--- a/fs/ntfs/quota.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/quota.c 2004-09-24 17:06:27 +01:00
@@ -37,7 +37,7 @@
{
ntfs_index_context *ictx;
QUOTA_CONTROL_ENTRY *qce;
- const u32 qid = QUOTA_DEFAULTS_ID;
+ const le32 qid = QUOTA_DEFAULTS_ID;
int err;
ntfs_debug("Entering.");
diff -Nru a/fs/ntfs/super.c b/fs/ntfs/super.c
--- a/fs/ntfs/super.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/super.c 2004-09-24 17:06:27 +01:00
@@ -322,7 +322,7 @@
int err;
ntfs_debug("Entering, old flags = 0x%x, new flags = 0x%x.",
- vol->vol_flags, flags);
+ le16_to_cpu(vol->vol_flags), le16_to_cpu(flags));
if (vol->vol_flags == flags)
goto done;
BUG_ON(!ni);
@@ -386,7 +386,8 @@
static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags)
{
flags &= VOLUME_FLAGS_MASK;
- return ntfs_write_volume_flags(vol, vol->vol_flags & ~flags);
+ flags = vol->vol_flags & cpu_to_le16(~le16_to_cpu(flags));
+ return ntfs_write_volume_flags(vol, flags);
}
#endif /* NTFS_RW */
diff -Nru a/fs/ntfs/unistr.c b/fs/ntfs/unistr.c
--- a/fs/ntfs/unistr.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/unistr.c 2004-09-24 17:06:27 +01:00
@@ -96,7 +96,7 @@
const ntfschar *upcase, const u32 upcase_len)
{
u32 cnt, min_len;
- ntfschar c1, c2;
+ u16 c1, c2;
min_len = name1_len;
if (name1_len > name2_len)
@@ -144,7 +144,7 @@
*/
int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n)
{
- ntfschar c1, c2;
+ u16 c1, c2;
size_t i;
for (i = 0; i < n; ++i) {
@@ -181,8 +181,8 @@
int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
const ntfschar *upcase, const u32 upcase_size)
{
- ntfschar c1, c2;
size_t i;
+ u16 c1, c2;
for (i = 0; i < n; ++i) {
if ((c1 = le16_to_cpu(s1[i])) < upcase_size)
@@ -203,7 +203,7 @@
const u32 upcase_len)
{
u32 i;
- ntfschar u;
+ u16 u;
for (i = 0; i < name_len; i++)
if ((u = le16_to_cpu(name[i])) < upcase_len)
diff -Nru a/fs/ntfs/upcase.c b/fs/ntfs/upcase.c
--- a/fs/ntfs/upcase.c 2004-09-24 17:06:27 +01:00
+++ b/fs/ntfs/upcase.c 2004-09-24 17:06:27 +01:00
@@ -3,7 +3,7 @@
* Part of the Linux-NTFS project.
*
* Copyright (c) 2001 Richard Russon <[email protected]>
- * Copyright (c) 2001-2003 Anton Altaparmakov
+ * Copyright (c) 2001-2004 Anton Altaparmakov
*
* Modified for mkntfs inclusion 9 June 2001 by Anton Altaparmakov.
* Modified for kernel inclusion 10 September 2001 by Anton Altparmakov.
@@ -87,4 +87,3 @@
uc[uc_word_table[r][0]] = cpu_to_le16(uc_word_table[r][1]);
return uc;
}
-
On Fri, 24 Sep 2004, Anton Altaparmakov wrote:
>
> - Fix all the sparse bitwise warnings. Had to change all the enums
> storing little endian values to #defines because we cannot set enums
> to be little endian so we had lots of bitwise warnings from sparse.
Btw, Al is fixing this. We'll make enum's properly typed, rather than just
plain integers. It's not traditional C behaviour, but it gives you better
type safety, and Al points out that other C compilers (the Plan 9 one, to
be specific) have done the same thing for similar reasons.
So we'll eventually be able to use enum's instead of #defines without
losing any sparse information.
Of course, the only case where it matters is exactly cases like this,
where the difference between using an enum and a #define is basically a
matter of taste. But since I agree that enum's can look a lot nicer, it's
good to know that it's being worked on.
Linus
This is patch 9/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/24 1.1952.1.4)
NTFS: 2.1.19 - Many cleanups, improvements, and a minor bug fix.
- Fix bug found by the new sparse bitwise warnings where the default
upcase table was defined as a pointer to wchar_t rather than ntfschar
in fs/ntfs/ntfs.h and super.c.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/Documentation/filesystems/ntfs.txt b/Documentation/filesystems/ntfs.txt
--- a/Documentation/filesystems/ntfs.txt 2004-09-24 17:06:31 +01:00
+++ b/Documentation/filesystems/ntfs.txt 2004-09-24 17:06:31 +01:00
@@ -277,6 +277,11 @@
Note, a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog.
+2.1.19:
+ - Minor bugfix in handling of the default upcase table.
+ - Many internal cleanups and improvements. Many thanks to Linus
+ Torvalds and Al Viro for the help and advice with the sparse
+ annotations and cleanups.
2.1.18:
- Fix scheduling latencies at mount time. (Ingo Molnar)
- Fix endianness bug in a little traversed portion of the attribute
diff -Nru a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
--- a/fs/ntfs/ChangeLog 2004-09-24 17:06:31 +01:00
+++ b/fs/ntfs/ChangeLog 2004-09-24 17:06:31 +01:00
@@ -21,7 +21,7 @@
- Enable the code for setting the NT4 compatibility flag when we start
making NTFS 1.2 specific modifications.
-2.1.19-WIP
+2.1.19 - Many cleanups, improvements, and a minor bug fix.
- Update ->setattr (fs/ntfs/inode.c::ntfs_setattr()) to refuse to
change the uid, gid, and mode of an inode as we do not support NTFS
@@ -51,6 +51,9 @@
- Fix all the sparse bitwise warnings. Had to change all the enums
storing little endian values to #defines because we cannot set enums
to be little endian so we had lots of bitwise warnings from sparse.
+ - Fix a bug found by the new sparse bitwise warnings where the default
+ upcase table was defined as a pointer to wchar_t rather than ntfschar
+ in fs/ntfs/ntfs.h and super.c.
2.1.18 - Fix scheduling latencies at mount time as well as an endianness bug.
diff -Nru a/fs/ntfs/Makefile b/fs/ntfs/Makefile
--- a/fs/ntfs/Makefile 2004-09-24 17:06:31 +01:00
+++ b/fs/ntfs/Makefile 2004-09-24 17:06:31 +01:00
@@ -6,7 +6,7 @@
index.o inode.o mft.o mst.o namei.o super.o sysctl.o unistr.o \
upcase.o
-EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.19-WIP\"
+EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.19\"
ifeq ($(CONFIG_NTFS_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
diff -Nru a/fs/ntfs/ntfs.h b/fs/ntfs/ntfs.h
--- a/fs/ntfs/ntfs.h 2004-09-24 17:06:31 +01:00
+++ b/fs/ntfs/ntfs.h 2004-09-24 17:06:31 +01:00
@@ -156,7 +156,7 @@
/* From fs/ntfs/super.c */
#define default_upcase_len 0x10000
-extern wchar_t *default_upcase;
+extern ntfschar *default_upcase;
extern unsigned long ntfs_nr_upcase_users;
extern struct semaphore ntfs_lock;
diff -Nru a/fs/ntfs/super.c b/fs/ntfs/super.c
--- a/fs/ntfs/super.c 2004-09-24 17:06:31 +01:00
+++ b/fs/ntfs/super.c 2004-09-24 17:06:31 +01:00
@@ -2574,7 +2574,7 @@
kmem_cache_t *ntfs_index_ctx_cache;
/* A global default upcase table and a corresponding reference count. */
-wchar_t *default_upcase = NULL;
+ntfschar *default_upcase = NULL;
unsigned long ntfs_nr_upcase_users = 0;
/* Driver wide semaphore. */
This is patch 10/10 in the series. It contains the following ChangeSet:
<[email protected]> (04/09/24 1.1956)
NTFS: Fix a stupid bug where I forgot to actually do the attribute lookup
and then went and used the looked up attribute... Ooops.
Signed-off-by: Anton Altaparmakov <[email protected]>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/, http://www-stu.christs.cam.ac.uk/~aia21/
===================================================================
diff -Nru a/fs/ntfs/inode.c b/fs/ntfs/inode.c
--- a/fs/ntfs/inode.c 2004-09-24 17:06:34 +01:00
+++ b/fs/ntfs/inode.c 2004-09-24 17:06:34 +01:00
@@ -2287,6 +2287,7 @@
ntfs_inode *ni = NTFS_I(vi);
ntfs_attr_search_ctx *ctx;
MFT_RECORD *m;
+ int err;
m = map_mft_record(ni);
if (IS_ERR(m)) {
@@ -2303,6 +2304,24 @@
// FIXME: We can't report an error code upstream. So what do
// we do?!? make_bad_inode() seems a bit harsh...
unmap_mft_record(ni);
+ return;
+ }
+ err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
+ CASE_SENSITIVE, 0, NULL, 0, ctx);
+ if (unlikely(err)) {
+ if (err == -ENOENT) {
+ ntfs_error(vi->i_sb, "Open attribute is missing from "
+ "mft record. Inode 0x%lx is corrupt. "
+ "Run chkdsk.", vi->i_ino);
+ make_bad_inode(vi);
+ } else {
+ ntfs_error(vi->i_sb, "Failed to lookup attribute in "
+ "inode 0x%lx (error code %d).",
+ vi->i_ino, err);
+ // FIXME: We can't report an error code upstream. So
+ // what do we do?!? make_bad_inode() seems a bit
+ // harsh...
+ }
goto out;
}
/* If the size has not changed there is nothing to do. */
On Fri, 24 Sep 2004, Linus Torvalds wrote:
> On Fri, 24 Sep 2004, Anton Altaparmakov wrote:
> > - Fix all the sparse bitwise warnings. Had to change all the enums
> > storing little endian values to #defines because we cannot set enums
> > to be little endian so we had lots of bitwise warnings from sparse.
>
> Btw, Al is fixing this. We'll make enum's properly typed, rather than just
> plain integers. It's not traditional C behaviour, but it gives you better
> type safety, and Al points out that other C compilers (the Plan 9 one, to
> be specific) have done the same thing for similar reasons.
>
> So we'll eventually be able to use enum's instead of #defines without
> losing any sparse information.
>
> Of course, the only case where it matters is exactly cases like this,
> where the difference between using an enum and a #define is basically a
> matter of taste. But since I agree that enum's can look a lot nicer, it's
> good to know that it's being worked on.
This is good news. Once that is done I will be very happy to go back to
using enums as I also agree that they can and in this case do look a
lot nicer...
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Fri, 24 Sep 2004, Anton Altaparmakov wrote:
> On Fri, 24 Sep 2004, Linus Torvalds wrote:
> >
> > Btw, Al is fixing this. We'll make enum's properly typed, rather than just
> > plain integers. It's not traditional C behaviour, but it gives you better
> > type safety, and Al points out that other C compilers (the Plan 9 one, to
> > be specific) have done the same thing for similar reasons.
Well, when I said "Al is fixing this", I lied.
I just fixed it myself.
> This is good news. Once that is done I will be very happy to go back to
> using enums as I also agree that they can and in this case do look a
> lot nicer...
Try the current sparse, I think it should work for you.
So if you make an enum where the initializer expression is a little-endian
expression, the type of that (single) enumerator will be little-endian.
HOWEVER, the type of an enum _variable_ will still be just "int". So
enum myenum {
one = 1ULL,
two = 2,
};
has the strange behaviour that if you use "one" in an expression, it will
have the type "unsigned long long", but if you use a "enum myenum" entry
(even if it has the value "1"), it will be an "int":
sizeof(one) == 8
sizeof(enum myenum) == 4
So I would stronly suggest (and I may make sparse warn) against using
non-integertyped enum values with any enum that actually has any backing
store (ie if you ever use a variable of type "enum myenum", that would
result in a warning - you can really just use the values "one" and "two"
directly).
Note that gcc has some similarly strange behaviour wrt enum types that
depends on the _values_ of the enum entries themselves, and that can
result in serious problems if you declare the enum in a different place
from where you defined the values. Again, those problems only happen for
enums that actually get used with backing store (as opposed to just
readable compile-time constants).
Linus
On Fri, Sep 24, 2004 at 05:13:20PM +0100, Anton Altaparmakov wrote:
> This is patch 4/10 in the series. It contains the following ChangeSet:
>
> <[email protected]> (04/09/23 1.1951)
> NTFS: Change '\0' and L'\0' to simply 0 as per advice from Linus Torvalds.
Take one more step and replace cpu_to_le16(0) with 0...
On Fri, Sep 24, 2004 at 05:13:53PM +0100, Anton Altaparmakov wrote:
> /* Get the starting vcn of the index_block holding the child node. */
> - vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
> + vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
I don't like the look of that. Are there any alignment warranties for that
pointer? The same goes for other users of that function...
On Fri, Sep 24, 2004 at 05:14:12PM +0100, Anton Altaparmakov wrote:
> * Generic magic comparison macros. Finally found a use for the ## preprocessor
> * operator! (-8
> */
> -#define ntfs_is_magic(x, m) ( (u32)(x) == magic_##m )
> -#define ntfs_is_magicp(p, m) ( *(u32*)(p) == magic_##m )
> +
> +static inline BOOL __ntfs_is_magic(le32 x, NTFS_RECORD_TYPES r)
> +{
> + return (x == (__force le32)r);
> +}
> +#define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m)
> +
> +static inline BOOL __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPES r)
> +{
> + return (*p == (__force le32)r);
> +}
> +#define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m)
*eeeeeek*
It looks badly wrong. Why do you need these casts?
On Fri, Sep 24, 2004 at 07:46:20PM -0700, Linus Torvalds wrote:
> So I would stronly suggest (and I may make sparse warn) against using
> non-integertyped enum values with any enum that actually has any backing
> store (ie if you ever use a variable of type "enum myenum", that would
> result in a warning - you can really just use the values "one" and "two"
> directly).
Linus, backing store is irrelevant here (and BTW, variables are no better
or worse than arguments / structure fields / return values / argument of
sizeof / etc.)
a) integer type equivalent to particular enum is up to compiler; anything
that depends on it is at the very least non-portable.
b) __bitwise doesn't break anything; __le32 enum members are just as OK as
int ones.
c) its enum members where we are not doing what gcc does; enum itself is
trivial to deal with. So that's where the warnings should be.
Anyway, I'll send you sparse patches tomorrow when I rediff that stuff to
your current tree...
On Sat, 25 Sep 2004 [email protected] wrote:
>
> Linus, backing store is irrelevant here (and BTW, variables are no better
> or worse than arguments / structure fields / return values / argument of
> sizeof / etc.)
I agree that in the case of NTFS it is irrelevant. I was talking more in
general: if you use enums with "types", you really should only use them as
compile-time constants. Which is, obviously, one very common usage of
enums, but is not the only one.
I personally believe that people use enum's largely in two (independent)
ways:
- a convenient compile-time constant:
enum {
DevEnableMask = 1UL << 0,
DevIRQMask = 1UL << 5,
DevError = 1UL << 31
};
where you never actually _save_ an enum anywhere. In this case, the
typing is very convenient indeed.
- a "type enumerator":
enum token_type {
TOKEN_IDENT = 1,
TOKEN_NUMBER,
TOKEN_MACRO,
...
where the enum actually is used as a variable to distinguish different
cases. In this case, the per-enum typing ends up being possibly even
confusing, since using a constant will have a potentially _different_
type than loading that constant from a variable.
The second case is why I think it's a sane thing to warn if anybody ever
creates a variable (or structure/union member) with an enum that used the
typing features. Not because we can't make the enum fit all the values,
but because the types simply WILL NOT MATCH. They fundamentally cannot,
since we took the approach of having per-entry types.
And for sparse, since the type is _the_ most important part of anything,
we should warn when the types won't match.
Linus
On Sat, 25 Sep 2004 [email protected] wrote:
> On Fri, Sep 24, 2004 at 05:13:53PM +0100, Anton Altaparmakov wrote:
> > /* Get the starting vcn of the index_block holding the child node. */
> > - vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
> > + vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
>
> I don't like the look of that. Are there any alignment warranties for that
> pointer? The same goes for other users of that function...
The above pointer is always aligned to 8-byte boundary as goes for all
users of sle64_to_cpup().
If that matters, everything using _to_cpup() in ntfs is aligned
sufficiently expect for perhaps the two uses of le32_to_cpu() in
fs/ntfs/collate.c and the four uses of le16_to_cpu() in
fs/ntfs/compress.c where I would not be so sure and in fact the compress.c
ones I am pretty sure that there is no alignement guarantee for anything
at all.
Simillar, some of the othe *le*_to_cpu() conversion in NTFS are not
aligned (especially most of the boot sector ones).
I decided to not use the get_unaligned macros despite of this after a
discussion on LKML (perhaps fs-devel or perhaps only #kernel several years
ago, can't remember) where it was discussed that all architectures can do
the appropriate fixups on unaligned accesses if they need them and that
get_unaligned makes code very slow so it is better to just do the accesses
and have high speed on architectures which don't care and to have fixups
on other architectures than it is to use get_unaligned everywhere.
Is there anything wrong with that? Remember that NTFS in real life is
almost entirely restricted to x86 which AFAIK doesn't care about
alignement. I guess Windows now also exists (as beta) for ia64 and x86_64
but I don't know if these architectures require alignment or not...
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Sat, 25 Sep 2004 [email protected] wrote:
> On Fri, Sep 24, 2004 at 05:14:12PM +0100, Anton Altaparmakov wrote:
> > * Generic magic comparison macros. Finally found a use for the ## preprocessor
> > * operator! (-8
> > */
> > -#define ntfs_is_magic(x, m) ( (u32)(x) == magic_##m )
> > -#define ntfs_is_magicp(p, m) ( *(u32*)(p) == magic_##m )
> > +
> > +static inline BOOL __ntfs_is_magic(le32 x, NTFS_RECORD_TYPES r)
> > +{
> > + return (x == (__force le32)r);
> > +}
> > +#define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m)
> > +
> > +static inline BOOL __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPES r)
> > +{
> > + return (*p == (__force le32)r);
> > +}
> > +#define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m)
>
> *eeeeeek*
>
> It looks badly wrong. Why do you need these casts?
*eeeeeek*
It is badly wrong. Removed. Thanks!
IIRC I had put them in to silence some sparse warnings I was getting until
I solved the underlying problems and then completely forgot about them and
so they didn't get removed again afterwards. Sorry. Just me being
stupid. )-:
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Sat, 25 Sep 2004 [email protected] wrote:
> On Fri, Sep 24, 2004 at 05:13:20PM +0100, Anton Altaparmakov wrote:
> > This is patch 4/10 in the series. It contains the following ChangeSet:
> >
> > <[email protected]> (04/09/23 1.1951)
> > NTFS: Change '\0' and L'\0' to simply 0 as per advice from Linus Torvalds.
>
> Take one more step and replace cpu_to_le16(0) with 0...
Done.
Thanks,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Sun, 26 Sep 2004, Anton Altaparmakov wrote:
> On Sat, 25 Sep 2004 [email protected] wrote:
> > On Fri, Sep 24, 2004 at 05:13:53PM +0100, Anton Altaparmakov wrote:
> > > /* Get the starting vcn of the index_block holding the child node. */
> > > - vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
> > > + vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
> >
> > I don't like the look of that. Are there any alignment warranties for that
> > pointer? The same goes for other users of that function...
>
> The above pointer is always aligned to 8-byte boundary as goes for all
> users of sle64_to_cpup().
>
> If that matters, everything using _to_cpup() in ntfs is aligned
> sufficiently expect for perhaps the two uses of le32_to_cpu() in
s/expect/except/
s/le32_to_cpu/le32_to_cpup/
> fs/ntfs/collate.c and the four uses of le16_to_cpu() in
s/le16_to_cpu/le16_to_cpup/
> fs/ntfs/compress.c where I would not be so sure and in fact the compress.c
> ones I am pretty sure that there is no alignement guarantee for anything
> at all.
>
> Simillar, some of the othe *le*_to_cpu() conversion in NTFS are not
> aligned (especially most of the boot sector ones).
>
> I decided to not use the get_unaligned macros despite of this after a
> discussion on LKML (perhaps fs-devel or perhaps only #kernel several years
> ago, can't remember) where it was discussed that all architectures can do
> the appropriate fixups on unaligned accesses if they need them and that
> get_unaligned makes code very slow so it is better to just do the accesses
> and have high speed on architectures which don't care and to have fixups
> on other architectures than it is to use get_unaligned everywhere.
>
> Is there anything wrong with that? Remember that NTFS in real life is
> almost entirely restricted to x86 which AFAIK doesn't care about
> alignement. I guess Windows now also exists (as beta) for ia64 and x86_64
> but I don't know if these architectures require alignment or not...
>
> Best regards,
>
> Anton
>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Fri, 24 Sep 2004, Linus Torvalds wrote:
> On Fri, 24 Sep 2004, Anton Altaparmakov wrote:
> > On Fri, 24 Sep 2004, Linus Torvalds wrote:
> > >
> > > Btw, Al is fixing this. We'll make enum's properly typed, rather than just
> > > plain integers. It's not traditional C behaviour, but it gives you better
> > > type safety, and Al points out that other C compilers (the Plan 9 one, to
> > > be specific) have done the same thing for similar reasons.
>
> Well, when I said "Al is fixing this", I lied.
>
> I just fixed it myself.
Great. (-:
> > This is good news. Once that is done I will be very happy to go back to
> > using enums as I also agree that they can and in this case do look a
> > lot nicer...
>
> Try the current sparse, I think it should work for you.
>
> So if you make an enum where the initializer expression is a little-endian
> expression, the type of that (single) enumerator will be little-endian.
>
> HOWEVER, the type of an enum _variable_ will still be just "int". So
>
> enum myenum {
> one = 1ULL,
> two = 2,
> };
>
> has the strange behaviour that if you use "one" in an expression, it will
> have the type "unsigned long long", but if you use a "enum myenum" entry
> (even if it has the value "1"), it will be an "int":
>
> sizeof(one) == 8
> sizeof(enum myenum) == 4
>
> So I would stronly suggest (and I may make sparse warn) against using
> non-integertyped enum values with any enum that actually has any backing
> store (ie if you ever use a variable of type "enum myenum", that would
> result in a warning - you can really just use the values "one" and "two"
> directly).
Ah, I was using them for backing store as well and I was using the
__attribute__((packed)) gcc extension to make them the bit-width I wanted
in combination with a "filler element" at the end of the enum.
So for example to get a 16-bit enum type I was using:
typedef enum {
RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
REST_AREA_SPACE_FILLER = 0xffff /* Just to make flags
16-bit. */
} __attribute__ ((__packed__)) RESTART_AREA_FLAGS;
And then when defining the structure containing these flags I would just
do:
typedef struct {
...
RESTART_AREA_FLAGS flags;
...
} __attribute__ ((__packed__)) RESTART_AREA;
Also I use the enum type as parameters to functions, for example in the
above case I might have:
int blah(RESTART_AREA_FLAGS flags);
So this use doesn't work with the sparse update either. At the moment I
have changed everything to just a bunch of #defines followed by a:
typedef le16 RESTART_AREA_FLAGS;
So I guess with your sparse update I can now go to a point in between the
old one and the new one:
enum {
RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
} __attribute__ ((__packed__)) RESTART_AREA_FLAGS;
typedef le16 RESTART_AREA_FLAGS;
So I get the enum rather than bunch of defines and I get my proper types
as well.
That only looses the ability for the compiler to warn if people use the
wrong constant when trying to set such a variable or pass a wrong constant
into a function but that is not nearly as useful a warning as the wrong
endianness bitwise warnings we have now gained so I am not going to worry
about losing it.
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Sat, 25 Sep 2004, Linus Torvalds wrote:
> I personally believe that people use enum's largely in two (independent)
> ways:
>
> - a convenient compile-time constant:
>
> enum {
> DevEnableMask = 1UL << 0,
> DevIRQMask = 1UL << 5,
> DevError = 1UL << 31
> };
>
> where you never actually _save_ an enum anywhere. In this case, the
> typing is very convenient indeed.
>
> - a "type enumerator":
>
> enum token_type {
> TOKEN_IDENT = 1,
> TOKEN_NUMBER,
> TOKEN_MACRO,
> ...
>
> where the enum actually is used as a variable to distinguish different
> cases. In this case, the per-enum typing ends up being possibly even
> confusing, since using a constant will have a potentially _different_
> type than loading that constant from a variable.
>
> The second case is why I think it's a sane thing to warn if anybody ever
> creates a variable (or structure/union member) with an enum that used the
> typing features. Not because we can't make the enum fit all the values,
> but because the types simply WILL NOT MATCH. They fundamentally cannot,
> since we took the approach of having per-entry types.
>
> And for sparse, since the type is _the_ most important part of anything,
> we should warn when the types won't match.
What does sparse do at the moment when the enum size has been changed
away from sizeof(int) using __attribute__ ((__packed__))?
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Sun, 26 Sep 2004, Anton Altaparmakov wrote:
> On Fri, 24 Sep 2004, Linus Torvalds wrote:
> > On Fri, 24 Sep 2004, Anton Altaparmakov wrote:
> > > On Fri, 24 Sep 2004, Linus Torvalds wrote:
> > > >
> > > > Btw, Al is fixing this. We'll make enum's properly typed, rather than just
> > > > plain integers. It's not traditional C behaviour, but it gives you better
> > > > type safety, and Al points out that other C compilers (the Plan 9 one, to
> > > > be specific) have done the same thing for similar reasons.
> >
> > Well, when I said "Al is fixing this", I lied.
> >
> > I just fixed it myself.
>
> Great. (-:
>
> > > This is good news. Once that is done I will be very happy to go back to
> > > using enums as I also agree that they can and in this case do look a
> > > lot nicer...
> >
> > Try the current sparse, I think it should work for you.
> >
> > So if you make an enum where the initializer expression is a little-endian
> > expression, the type of that (single) enumerator will be little-endian.
> >
> > HOWEVER, the type of an enum _variable_ will still be just "int". So
> >
> > enum myenum {
> > one = 1ULL,
> > two = 2,
> > };
> >
> > has the strange behaviour that if you use "one" in an expression, it will
> > have the type "unsigned long long", but if you use a "enum myenum" entry
> > (even if it has the value "1"), it will be an "int":
> >
> > sizeof(one) == 8
> > sizeof(enum myenum) == 4
> >
> > So I would stronly suggest (and I may make sparse warn) against using
> > non-integertyped enum values with any enum that actually has any backing
> > store (ie if you ever use a variable of type "enum myenum", that would
> > result in a warning - you can really just use the values "one" and "two"
> > directly).
>
> Ah, I was using them for backing store as well and I was using the
> __attribute__((packed)) gcc extension to make them the bit-width I wanted
> in combination with a "filler element" at the end of the enum.
>
> So for example to get a 16-bit enum type I was using:
>
> typedef enum {
> RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
> REST_AREA_SPACE_FILLER = 0xffff /* Just to make flags
> 16-bit. */
> } __attribute__ ((__packed__)) RESTART_AREA_FLAGS;
>
> And then when defining the structure containing these flags I would just
> do:
>
> typedef struct {
> ...
> RESTART_AREA_FLAGS flags;
> ...
> } __attribute__ ((__packed__)) RESTART_AREA;
>
> Also I use the enum type as parameters to functions, for example in the
> above case I might have:
> int blah(RESTART_AREA_FLAGS flags);
>
> So this use doesn't work with the sparse update either. At the moment I
> have changed everything to just a bunch of #defines followed by a:
>
> typedef le16 RESTART_AREA_FLAGS;
>
> So I guess with your sparse update I can now go to a point in between the
> old one and the new one:
>
> enum {
> RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
> } __attribute__ ((__packed__)) RESTART_AREA_FLAGS;
Silly cut'n'paste error. I meant:
> } __attribute__ ((__packed__));
>
> typedef le16 RESTART_AREA_FLAGS;
>
> So I get the enum rather than bunch of defines and I get my proper types
> as well.
>
> That only looses the ability for the compiler to warn if people use the
> wrong constant when trying to set such a variable or pass a wrong constant
> into a function but that is not nearly as useful a warning as the wrong
> endianness bitwise warnings we have now gained so I am not going to worry
> about losing it.
>
> Best regards,
>
> Anton
>
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
On Sun, 26 Sep 2004, Anton Altaparmakov wrote:
>
> What does sparse do at the moment when the enum size has been changed
> away from sizeof(int) using __attribute__ ((__packed__))?
Spatse doesn't support that at all, and will just ignore it.
Of course, since sparse doesn't actually generate any code, there's no
real impact from that. In theory, you might get sparse to complain if you
do something like "__attribute__((align(sizeof(xx)))" where the size is
now wrong and not a power-of-two, but..
Linus