From 9191d85e28d4991e7c4294f37a3cdb3542f716a0 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Sat, 3 Oct 2015 12:58:08 +0200 Subject: [PATCH 01/20] Use appropriate little-endian/big-endian types in struct definitions. On-disk struct definitions used native types (u16/u32/u64/s16/s32/s64), which doesn't say anything about the intended interpretation of the data. The intention of having little-endian-specific types and big-endian-specific types must have been to clarify interpretation of data and intentions in the code. Therefore it seems reasonable to use these types in struct definitions to clarify what data represention is used to encode field data. Because some struct members in layout.h are big-endian, this change also means moving the duplicated definitions for big-endian byteswapping macros and big-endian types found in acls.h and security.h to the appropriate locations in endians.h and types.h respectively in order to make them available for the struct definitions in layout.h. --- include/ntfs-3g/acls.h | 14 +- include/ntfs-3g/endians.h | 80 ++++++++ include/ntfs-3g/layout.h | 402 +++++++++++++++++++------------------ include/ntfs-3g/logfile.h | 64 +++--- include/ntfs-3g/security.h | 13 +- include/ntfs-3g/types.h | 14 +- 6 files changed, 328 insertions(+), 259 deletions(-) diff --git a/include/ntfs-3g/acls.h b/include/ntfs-3g/acls.h index 38d2cd64..a91eda7c 100644 --- a/include/ntfs-3g/acls.h +++ b/include/ntfs-3g/acls.h @@ -24,6 +24,8 @@ #ifndef ACLS_H #define ACLS_H +#include "endians.h" + /* * JPA configuration modes for security.c / acls.c * should be moved to some config file @@ -35,18 +37,6 @@ #define CACHE_PERMISSIONS_BITS 6 /* log2 of unitary allocation of permissions */ #define CACHE_PERMISSIONS_SIZE 262144 /* max cacheable permissions */ -/* - * JPA The following must be in some library... - * but did not found out where - */ - -#define endian_rev16(x) (((x >> 8) & 255) | ((x & 255) << 8)) -#define endian_rev32(x) (((x >> 24) & 255) | ((x >> 8) & 0xff00) \ - | ((x & 0xff00) << 8) | ((x & 255) << 24)) - -#define cpu_to_be16(x) endian_rev16(cpu_to_le16(x)) -#define cpu_to_be32(x) endian_rev32(cpu_to_le32(x)) - /* * Macro definitions needed to share code with secaudit */ diff --git a/include/ntfs-3g/endians.h b/include/ntfs-3g/endians.h index 397f1c20..0604867b 100644 --- a/include/ntfs-3g/endians.h +++ b/include/ntfs-3g/endians.h @@ -126,6 +126,22 @@ #define __constant_cpu_to_le32(x) (x) #define __constant_cpu_to_le64(x) (x) +#define __be16_to_cpu(x) bswap_16(x) +#define __be32_to_cpu(x) bswap_32(x) +#define __be64_to_cpu(x) bswap_64(x) + +#define __cpu_to_be16(x) bswap_16(x) +#define __cpu_to_be32(x) bswap_32(x) +#define __cpu_to_be64(x) bswap_64(x) + +#define __constant_be16_to_cpu(x) __ntfs_bswap_constant_16((u16)(x)) +#define __constant_be32_to_cpu(x) __ntfs_bswap_constant_32((u32)(x)) +#define __constant_be64_to_cpu(x) __ntfs_bswap_constant_64((u64)(x)) + +#define __constant_cpu_to_be16(x) __ntfs_bswap_constant_16((u16)(x)) +#define __constant_cpu_to_be32(x) __ntfs_bswap_constant_32((u32)(x)) +#define __constant_cpu_to_be64(x) __ntfs_bswap_constant_64((u64)(x)) + #elif defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) #define __le16_to_cpu(x) bswap_16(x) @@ -144,6 +160,22 @@ #define __constant_cpu_to_le32(x) __ntfs_bswap_constant_32((u32)(x)) #define __constant_cpu_to_le64(x) __ntfs_bswap_constant_64((u64)(x)) +#define __be16_to_cpu(x) (x) +#define __be32_to_cpu(x) (x) +#define __be64_to_cpu(x) (x) + +#define __cpu_to_be16(x) (x) +#define __cpu_to_be32(x) (x) +#define __cpu_to_be64(x) (x) + +#define __constant_be16_to_cpu(x) (x) +#define __constant_be32_to_cpu(x) (x) +#define __constant_be64_to_cpu(x) (x) + +#define __constant_cpu_to_be16(x) (x) +#define __constant_cpu_to_be32(x) (x) +#define __constant_cpu_to_be64(x) (x) + #else #error "You must define __BYTE_ORDER to be __LITTLE_ENDIAN or __BIG_ENDIAN." @@ -190,6 +222,46 @@ #define cpu_to_sle32p(x) (s32)__cpu_to_le32(*(s32*)(x)) #define cpu_to_sle64p(x) (s64)__cpu_to_le64(*(s64*)(x)) +/* Unsigned from BE to CPU conversion. */ + +#define be16_to_cpu(x) (u16)__be16_to_cpu((u16)(x)) +#define be32_to_cpu(x) (u32)__be32_to_cpu((u32)(x)) +#define be64_to_cpu(x) (u64)__be64_to_cpu((u64)(x)) + +#define be16_to_cpup(x) (u16)__be16_to_cpu(*(const u16*)(x)) +#define be32_to_cpup(x) (u32)__be32_to_cpu(*(const u32*)(x)) +#define be64_to_cpup(x) (u64)__be64_to_cpu(*(const u64*)(x)) + +/* Signed from BE to CPU conversion. */ + +#define sbe16_to_cpu(x) (s16)__be16_to_cpu((s16)(x)) +#define sbe32_to_cpu(x) (s32)__be32_to_cpu((s32)(x)) +#define sbe64_to_cpu(x) (s64)__be64_to_cpu((s64)(x)) + +#define sbe16_to_cpup(x) (s16)__be16_to_cpu(*(s16*)(x)) +#define sbe32_to_cpup(x) (s32)__be32_to_cpu(*(s32*)(x)) +#define sbe64_to_cpup(x) (s64)__be64_to_cpu(*(s64*)(x)) + +/* Unsigned from CPU to BE conversion. */ + +#define cpu_to_be16(x) (u16)__cpu_to_be16((u16)(x)) +#define cpu_to_be32(x) (u32)__cpu_to_be32((u32)(x)) +#define cpu_to_be64(x) (u64)__cpu_to_be64((u64)(x)) + +#define cpu_to_be16p(x) (u16)__cpu_to_be16(*(u16*)(x)) +#define cpu_to_be32p(x) (u32)__cpu_to_be32(*(u32*)(x)) +#define cpu_to_be64p(x) (u64)__cpu_to_be64(*(u64*)(x)) + +/* Signed from CPU to BE conversion. */ + +#define cpu_to_sbe16(x) (s16)__cpu_to_be16((s16)(x)) +#define cpu_to_sbe32(x) (s32)__cpu_to_be32((s32)(x)) +#define cpu_to_sbe64(x) (s64)__cpu_to_be64((s64)(x)) + +#define cpu_to_sbe16p(x) (s16)__cpu_to_be16(*(s16*)(x)) +#define cpu_to_sbe32p(x) (s32)__cpu_to_be32(*(s32*)(x)) +#define cpu_to_sbe64p(x) (s64)__cpu_to_be64(*(s64*)(x)) + /* Constant endianness conversion defines. */ #define const_le16_to_cpu(x) __constant_le16_to_cpu(x) @@ -200,4 +272,12 @@ #define const_cpu_to_le32(x) __constant_cpu_to_le32(x) #define const_cpu_to_le64(x) __constant_cpu_to_le64(x) +#define const_be16_to_cpu(x) __constant_be16_to_cpu(x) +#define const_be32_to_cpu(x) __constant_be32_to_cpu(x) +#define const_be64_to_cpu(x) __constant_be64_to_cpu(x) + +#define const_cpu_to_be16(x) __constant_cpu_to_be16(x) +#define const_cpu_to_be32(x) __constant_cpu_to_be32(x) +#define const_cpu_to_be64(x) __constant_cpu_to_be64(x) + #endif /* defined _NTFS_ENDIANS_H */ diff --git a/include/ntfs-3g/layout.h b/include/ntfs-3g/layout.h index 5b5fff6e..9bee6e75 100644 --- a/include/ntfs-3g/layout.h +++ b/include/ntfs-3g/layout.h @@ -47,20 +47,20 @@ * struct BIOS_PARAMETER_BLOCK - 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 */ -/*0x0d*/u16 sectors_per_track; /* Required to boot Windows. */ -/*0x0f*/u16 heads; /* Required to boot Windows. */ -/*0x11*/u32 hidden_sectors; /* Offset to the start of the partition + le16 sectors_per_fat; /* zero */ +/*0x0d*/le16 sectors_per_track; /* Required to boot Windows. */ +/*0x0f*/le16 heads; /* Required to boot Windows. */ +/*0x11*/le32 hidden_sectors; /* Offset to the start of the partition relative to the disk in sectors. Required to boot Windows. */ -/*0x15*/u32 large_sectors; /* zero */ +/*0x15*/le32 large_sectors; /* zero */ /* sizeof() = 25 (0x19) bytes */ } __attribute__((__packed__)) BIOS_PARAMETER_BLOCK; @@ -69,27 +69,27 @@ typedef struct { */ typedef struct { u8 jump[3]; /* Irrelevant (jump to boot up code).*/ - u64 oem_id; /* Magic "NTFS ". */ + le64 oem_id; /* Magic "NTFS ". */ /*0x0b*/BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */ u8 physical_drive; /* 0x00 floppy, 0x80 hard disk */ u8 current_head; /* zero */ u8 extended_boot_signature; /* 0x80 */ u8 reserved2; /* 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; @@ -167,27 +167,27 @@ typedef enum { /** * struct NTFS_RECORD - * - * 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. */ @@ -340,17 +340,17 @@ typedef struct { /*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*/ LSN lsn; /* $LogFile sequence number for this record. +/* 8*/ leLSN 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 @@ -360,18 +360,19 @@ typedef struct { 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 @@ -383,7 +384,7 @@ typedef struct { 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 +/* 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 @@ -391,8 +392,8 @@ typedef struct { NOTE: The first instance number is always 0. */ /* The below fields are specific to NTFS 3.1+ (Windows XP and above): */ -/* 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 @@ -414,17 +415,17 @@ typedef struct { /*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*/ LSN lsn; /* $LogFile sequence number for this record. +/* 8*/ leLSN 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 @@ -434,18 +435,19 @@ typedef struct { 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 @@ -457,7 +459,7 @@ typedef struct { 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 +/* 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 @@ -523,28 +525,28 @@ typedef enum { * 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(0), /* Collate by binary @@ -617,12 +619,12 @@ typedef struct { /* 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*/ s64 min_size; /* Optional minimum attribute size. */ -/* 98*/ s64 max_size; /* Maximum size of attribute. */ +/* 90*/ sle64 min_size; /* Optional minimum attribute size. */ +/* 98*/ sle64 max_size; /* Maximum size of attribute. */ /* sizeof() = 0xa0 or 160 bytes */ } __attribute__((__packed__)) ATTR_DEF; @@ -722,14 +724,14 @@ typedef enum { 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 @@ -739,15 +741,15 @@ typedef struct { 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 above 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 @@ -763,18 +765,18 @@ typedef struct { } __attribute__((__packed__)); /* 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). @@ -789,7 +791,7 @@ typedef struct { /* 35*/ u8 reserved1[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 @@ -797,10 +799,10 @@ typedef struct { 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. */ /* 64 */ void *non_resident_end[0]; /* Use offsetof(ATTR_RECORD, @@ -808,7 +810,7 @@ typedef struct { size of a non resident attribute. */ /* 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 @@ -908,13 +910,13 @@ typedef enum { */ 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 @@ -952,23 +954,23 @@ typedef struct { * 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. @@ -1020,13 +1022,13 @@ typedef struct { typedef struct { /*Ofs*/ /* 0*/ ATTR_TYPES type; /* Type of referenced attribute. */ -/* 4*/ u16 length; /* Byte size of this entry. */ +/* 4*/ le16 length; /* Byte size of this entry. */ /* 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 @@ -1038,10 +1040,10 @@ typedef struct { 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 @@ -1096,16 +1098,16 @@ typedef enum { */ 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; /* Last time this mft record was +/* 20*/ sle64 last_access_time; /* Last time this mft record was accessed. */ -/* 28*/ s64 allocated_size; /* Byte size of on-disk allocated space +/* 28*/ sle64 allocated_size; /* Byte size of on-disk allocated space for the data attribute. So for normal $DATA, this is the allocated_size from the unnamed @@ -1114,17 +1116,17 @@ typedef struct { compressed_size from the unnamed $DATA attribute. NOTE: This 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__)); - /* 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. */ @@ -1148,9 +1150,9 @@ typedef struct { * 1F010768-5A73-BC91-0010-A52216A7227B */ 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. */ @@ -1170,8 +1172,8 @@ typedef struct { * domain_id - Reserved (always zero). */ typedef struct { - MFT_REF mft_reference; /* Mft record containing the object_id in - the index entry key. */ + leMFT_REF mft_reference; /* Mft record containing the object_id + in the index entry key. */ union { struct { GUID birth_volume_id; @@ -1352,8 +1354,8 @@ typedef enum { /* Identifier authority. */ */ typedef union { struct { - u16 high_part; /* High 16-bits. */ - u32 low_part; /* Low 32-bits. */ + be16 high_part; /* High 16-bits. */ + be32 low_part; /* Low 32-bits. */ } __attribute__((__packed__)); u8 value[6]; /* Value as individual bytes. */ } __attribute__((__packed__)) SID_IDENTIFIER_AUTHORITY; @@ -1390,7 +1392,7 @@ typedef struct { 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; /** @@ -1471,7 +1473,7 @@ typedef enum { typedef struct { 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. */ } __attribute__((__packed__)) ACE_HEADER; /** @@ -1637,7 +1639,7 @@ typedef struct { /* 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. */ @@ -1659,7 +1661,7 @@ typedef struct { /* 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. */ @@ -1682,10 +1684,10 @@ typedef struct { 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; @@ -1783,17 +1785,17 @@ typedef struct { 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. */ @@ -1904,21 +1906,21 @@ typedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR; * 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; /** * struct SDH_INDEX_DATA - */ 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. */ - u32 reserved_II; /* Padding - always unicode "II" or zero. This field + 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. */ + le32 reserved_II; /* Padding - always unicode "II" or zero. This field isn't counted in INDEX_ENTRY's data_length. */ } __attribute__((__packed__)) SDH_INDEX_DATA; @@ -1943,10 +1945,10 @@ typedef SECURITY_DESCRIPTOR_HEADER SII_INDEX_DATA; typedef struct { /* 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; @@ -1957,7 +1959,7 @@ typedef struct { * The collation type is 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; /** @@ -1967,8 +1969,8 @@ typedef struct { * The collation rule is 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; /** @@ -2005,7 +2007,7 @@ typedef enum { * 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. */ @@ -2056,11 +2058,11 @@ typedef enum { * start of the index root or index allocation structures themselves. */ typedef struct { -/* 0*/ u32 entries_offset; /* Byte offset from the INDEX_HEADER to first +/* 0*/ le32 entries_offset; /* Byte offset from the INDEX_HEADER to first INDEX_ENTRY, aligned to 8-byte boundary. */ -/* 4*/ u32 index_length; /* Data size in byte of the INDEX_ENTRY's, +/* 4*/ le32 index_length; /* Data size in byte of the INDEX_ENTRY's, including the INDEX_HEADER, aligned to 8. */ -/* 8*/ u32 allocated_size; /* Allocated byte size of this index (block), +/* 8*/ le32 allocated_size; /* Allocated byte size of this index (block), multiple of 8 bytes. See more below. */ /* For the index root attribute, the above two numbers are always @@ -2103,7 +2105,7 @@ typedef struct { /* 4*/ COLLATION_RULES collation_rule; /* Collation rule used to sort the index entries. If type is $FILE_NAME, this must be COLLATION_FILE_NAME. */ -/* 8*/ u32 index_block_size; /* Size of index block in bytes (in +/* 8*/ le32 index_block_size; /* Size of index block in bytes (in the index allocation attribute). */ /* 12*/ s8 clusters_per_index_block; /* Size of index block in clusters (in the index allocation attribute), when @@ -2127,12 +2129,12 @@ typedef struct { 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*/ LSN lsn; /* $LogFile sequence number of the last +/* 8*/ leLSN 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. */ /* 24*/ INDEX_HEADER index; /* Describes the following index entries. */ /* sizeof()= 40 (0x28) bytes */ /* @@ -2160,8 +2162,8 @@ typedef INDEX_BLOCK INDEX_ALLOCATION; * 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; @@ -2213,13 +2215,13 @@ typedef enum { * 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. */ /* The below field is NOT present for the quota defaults entry. */ SID sid; /* The SID of the user/object associated with this quota entry. If this field is missing @@ -2235,8 +2237,8 @@ typedef struct { * struct QUOTA_O_INDEX_DATA - */ typedef struct { - u32 owner_id; - u32 unknown; /* Always 32. Seems to be padding and it's not + le32 owner_id; + le32 unknown; /* Always 32. Seems to be padding and it's not counted in the INDEX_ENTRY's data_length. This field shouldn't be really here. */ } __attribute__((__packed__)) QUOTA_O_INDEX_DATA; @@ -2274,17 +2276,17 @@ typedef enum { */ typedef struct { /* 0*/ union { - MFT_REF indexed_file; + leMFT_REF indexed_file; struct { - u16 data_offset; - u16 data_length; - u32 reservedV; + le16 data_offset; + le16 data_length; + le32 reservedV; } __attribute__((__packed__)); } __attribute__((__packed__)); -/* 8*/ u16 length; -/* 10*/ u16 key_length; +/* 8*/ le16 length; +/* 10*/ le16 key_length; /* 12*/ INDEX_ENTRY_FLAGS flags; -/* 14*/ u16 reserved; +/* 14*/ le16 reserved; /* sizeof() = 16 bytes */ } __attribute__((__packed__)) INDEX_ENTRY_HEADER; @@ -2300,26 +2302,26 @@ typedef struct { typedef struct { /* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */ union { /* 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. */ 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__)); } __attribute__((__packed__)); -/* 8*/ u16 length; /* Byte size of this index entry, multiple of +/* 8*/ le16 length; /* Byte size of this index entry, multiple of 8-bytes. Size includes INDEX_ENTRY_HEADER and the optional subnode VCN. See below. */ -/* 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 ie_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. */ /* End of INDEX_ENTRY_HEADER */ /* 16*/ union { /* The key of the indexed attribute. NOTE: Only present if INDEX_ENTRY_END bit in flags is not set. NOTE: On @@ -2336,13 +2338,13 @@ typedef struct { 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 ie_flags is set, the last + leVCN vcn; If INDEX_ENTRY_NODE bit in ie_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. @@ -2419,9 +2421,9 @@ typedef enum { * 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; @@ -2431,11 +2433,11 @@ typedef struct { * NOTE: Always resident. */ 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 @@ -2462,11 +2464,11 @@ typedef enum { * FIXME: It seems that name is always uppercased. 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 name_length; /* Length of the name of the extended attribute in bytes. */ - u16 value_length; /* Byte size of the EA's value. */ + le16 value_length; /* Byte size of the EA's value. */ u8 name[0]; /* Name of the EA. */ u8 value[0]; /* The value of the EA. Immediately follows the name. */ @@ -2530,10 +2532,10 @@ typedef struct { * The header of the Logged utility stream (0x100) attribute named "$EFS". */ typedef struct { -/* 0*/ u32 length; /* Length of EFS attribute in bytes. */ - u32 state; /* Always 0? */ - u32 version; /* Efs version. Always 2? */ - u32 crypto_api_version; /* Always 0? */ +/* 0*/ le32 length; /* Length of EFS attribute in bytes. */ + le32 state; /* Always 0? */ + le32 version; /* Efs version. Always 2? */ + le32 crypto_api_version; /* Always 0? */ /* 16*/ u8 unknown4[16]; /* MD5 hash of decrypted FEK? This field is created with a call to UuidCreate() so is unlikely to be an MD5 hash and is more @@ -2541,20 +2543,20 @@ typedef struct { or something like that. */ /* 32*/ u8 unknown5[16]; /* MD5 hash of DDFs? */ /* 48*/ u8 unknown6[16]; /* MD5 hash of DRFs? */ -/* 64*/ u32 offset_to_ddf_array;/* Offset in bytes to the array of data +/* 64*/ le32 offset_to_ddf_array;/* Offset in bytes to the array of data decryption fields (DDF), see below. Zero if no DDFs are present. */ - u32 offset_to_drf_array;/* Offset in bytes to the array of data + le32 offset_to_drf_array;/* Offset in bytes to the array of data recovery fields (DRF), see below. Zero if no DRFs are present. */ - u32 reserved; /* Reserved. */ + le32 reserved; /* Reserved. */ } __attribute__((__packed__)) EFS_ATTR_HEADER; /** * struct EFS_DF_ARRAY_HEADER - */ typedef struct { - u32 df_count; /* Number of data decryption/recovery fields in + le32 df_count; /* Number of data decryption/recovery fields in the array. */ } __attribute__((__packed__)) EFS_DF_ARRAY_HEADER; @@ -2562,25 +2564,25 @@ typedef struct { * struct EFS_DF_HEADER - */ typedef struct { -/* 0*/ u32 df_length; /* Length of this data decryption/recovery +/* 0*/ le32 df_length; /* Length of this data decryption/recovery field in bytes. */ - u32 cred_header_offset; /* Offset in bytes to the credential header. */ - u32 fek_size; /* Size in bytes of the encrypted file + le32 cred_header_offset; /* Offset in bytes to the credential header. */ + le32 fek_size; /* Size in bytes of the encrypted file encryption key (FEK). */ - u32 fek_offset; /* Offset in bytes to the FEK from the start of + le32 fek_offset; /* Offset in bytes to the FEK from the start of the data decryption/recovery field. */ -/* 16*/ u32 unknown1; /* always 0? Might be just padding. */ +/* 16*/ le32 unknown1; /* always 0? Might be just padding. */ } __attribute__((__packed__)) EFS_DF_HEADER; /** * struct EFS_DF_CREDENTIAL_HEADER - */ typedef struct { -/* 0*/ u32 cred_length; /* Length of this credential in bytes. */ - u32 sid_offset; /* Offset in bytes to the user's sid from start +/* 0*/ le32 cred_length; /* Length of this credential in bytes. */ + le32 sid_offset; /* Offset in bytes to the user's sid from start of this structure. Zero if no sid is present. */ -/* 8*/ u32 type; /* Type of this credential: +/* 8*/ le32 type; /* Type of this credential: 1 = CryptoAPI container. 2 = Unexpected type. 3 = Certificate thumbprint. @@ -2588,28 +2590,28 @@ typedef struct { union { /* CryptoAPI container. */ struct { -/* 12*/ u32 container_name_offset; /* Offset in bytes to +/* 12*/ le32 container_name_offset; /* Offset in bytes to the name of the container from start of this structure (may not be zero). */ -/* 16*/ u32 provider_name_offset; /* Offset in bytes to +/* 16*/ le32 provider_name_offset; /* Offset in bytes to the name of the provider from start of this structure (may not be zero). */ - u32 public_key_blob_offset; /* Offset in bytes to + le32 public_key_blob_offset; /* Offset in bytes to the public key blob from start of this structure. */ -/* 24*/ u32 public_key_blob_size; /* Size in bytes of +/* 24*/ le32 public_key_blob_size; /* Size in bytes of public key blob. */ } __attribute__((__packed__)); /* Certificate thumbprint. */ struct { -/* 12*/ u32 cert_thumbprint_header_size; /* Size in +/* 12*/ le32 cert_thumbprint_header_size; /* Size in bytes of the header of the certificate thumbprint. */ -/* 16*/ u32 cert_thumbprint_header_offset; /* Offset in +/* 16*/ le32 cert_thumbprint_header_offset; /* Offset in bytes to the header of the certificate thumbprint from start of this structure. */ - u32 unknown1; /* Always 0? Might be padding... */ - u32 unknown2; /* Always 0? Might be padding... */ + le32 unknown1; /* Always 0? Might be padding... */ + le32 unknown2; /* Always 0? Might be padding... */ } __attribute__((__packed__)); } __attribute__((__packed__)); } __attribute__((__packed__)) EFS_DF_CREDENTIAL_HEADER; @@ -2620,16 +2622,16 @@ typedef EFS_DF_CREDENTIAL_HEADER EFS_DF_CRED_HEADER; * struct EFS_DF_CERTIFICATE_THUMBPRINT_HEADER - */ typedef struct { -/* 0*/ u32 thumbprint_offset; /* Offset in bytes to the thumbprint. */ - u32 thumbprint_size; /* Size of thumbprint in bytes. */ -/* 8*/ u32 container_name_offset; /* Offset in bytes to the name of the +/* 0*/ le32 thumbprint_offset; /* Offset in bytes to the thumbprint. */ + le32 thumbprint_size; /* Size of thumbprint in bytes. */ +/* 8*/ le32 container_name_offset; /* Offset in bytes to the name of the container from start of this structure or 0 if no name present. */ - u32 provider_name_offset; /* Offset in bytes to the name of the + le32 provider_name_offset; /* Offset in bytes to the name of the cryptographic provider from start of this structure or 0 if no name present. */ -/* 16*/ u32 user_name_offset; /* Offset in bytes to the user name +/* 16*/ le32 user_name_offset; /* Offset in bytes to the user name from start of this structure or 0 if no user name present. (This is also known as lpDisplayInformation.) */ @@ -2651,8 +2653,8 @@ typedef struct { union { /* For character and block devices. */ struct { - u64 major; /* Major device number. */ - u64 minor; /* Minor device number. */ + le64 major; /* Major device number. */ + le64 minor; /* Minor device number. */ void *device_end[0]; /* Marker for offsetof(). */ } __attribute__((__packed__)); /* For symbolic links. */ diff --git a/include/ntfs-3g/logfile.h b/include/ntfs-3g/logfile.h index 798d562d..6b2305b7 100644 --- a/include/ntfs-3g/logfile.h +++ b/include/ntfs-3g/logfile.h @@ -308,24 +308,24 @@ typedef struct { typedef struct { /* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ NTFS_RECORD_TYPES magic;/* Usually the magic is "RCRD". */ - u16 usa_ofs; /* See NTFS_RECORD definition in layout.h. + le16 usa_ofs; /* See NTFS_RECORD definition in layout.h. When creating, set this to be immediately after this header structure (without any alignment). */ - u16 usa_count; /* See NTFS_RECORD definition in layout.h. */ + le16 usa_count; /* See NTFS_RECORD definition in layout.h. */ union { - LSN last_lsn; - s64 file_offset; + leLSN last_lsn; + sle64 file_offset; } __attribute__((__packed__)) copy; - u32 flags; - u16 page_count; - u16 page_position; + le32 flags; + le16 page_count; + le16 page_position; union { struct { - u16 next_record_offset; + le16 next_record_offset; u8 reserved[6]; - LSN last_end_lsn; + leLSN last_end_lsn; } __attribute__((__packed__)) packed; } __attribute__((__packed__)) header; } __attribute__((__packed__)) RECORD_PAGE_HEADER; @@ -346,8 +346,8 @@ typedef enum { * struct LOG_CLIENT_ID - The log client id structure identifying a log client. */ typedef struct { - u16 seq_number; - u16 client_index; + le16 seq_number; + le16 client_index; } __attribute__((__packed__)) LOG_CLIENT_ID; /** @@ -356,34 +356,34 @@ typedef struct { * Each log record seems to have a constant size of 0x70 bytes. */ typedef struct { - LSN this_lsn; - LSN client_previous_lsn; - LSN client_undo_next_lsn; - u32 client_data_length; + leLSN this_lsn; + leLSN client_previous_lsn; + leLSN client_undo_next_lsn; + le32 client_data_length; LOG_CLIENT_ID client_id; - u32 record_type; - u32 transaction_id; - u16 flags; - u16 reserved_or_alignment[3]; + le32 record_type; + le32 transaction_id; + le16 flags; + le16 reserved_or_alignment[3]; /* Now are at ofs 0x30 into struct. */ - u16 redo_operation; - u16 undo_operation; - u16 redo_offset; - u16 redo_length; - u16 undo_offset; - u16 undo_length; - u16 target_attribute; - u16 lcns_to_follow; /* Number of lcn_list entries + le16 redo_operation; + le16 undo_operation; + le16 redo_offset; + le16 redo_length; + le16 undo_offset; + le16 undo_length; + le16 target_attribute; + le16 lcns_to_follow; /* Number of lcn_list entries following this entry. */ /* Now at ofs 0x40. */ - u16 record_offset; - u16 attribute_offset; - u32 alignment_or_reserved; - VCN target_vcn; + le16 record_offset; + le16 attribute_offset; + le32 alignment_or_reserved; + leVCN target_vcn; /* Now at ofs 0x50. */ struct { /* Only present if lcns_to_follow is not 0. */ - LCN lcn; + leLCN lcn; } __attribute__((__packed__)) lcn_list[0]; } __attribute__((__packed__)) LOG_RECORD; diff --git a/include/ntfs-3g/security.h b/include/ntfs-3g/security.h index 8875c9c1..10de638c 100644 --- a/include/ntfs-3g/security.h +++ b/include/ntfs-3g/security.h @@ -29,23 +29,12 @@ #include "layout.h" #include "inode.h" #include "dir.h" +#include "endians.h" #ifndef POSIXACLS #define POSIXACLS 0 #endif -typedef u16 be16; -typedef u32 be32; - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define const_cpu_to_be16(x) ((((x) & 255L) << 8) + (((x) >> 8) & 255L)) -#define const_cpu_to_be32(x) ((((x) & 255L) << 24) + (((x) & 0xff00L) << 8) \ - + (((x) >> 8) & 0xff00L) + (((x) >> 24) & 255L)) -#else -#define const_cpu_to_be16(x) (x) -#define const_cpu_to_be32(x) (x) -#endif - /* * item in the mapping list */ diff --git a/include/ntfs-3g/types.h b/include/ntfs-3g/types.h index a64f12fa..43d91b20 100644 --- a/include/ntfs-3g/types.h +++ b/include/ntfs-3g/types.h @@ -48,15 +48,23 @@ typedef u16 le16; typedef u32 le32; typedef u64 le64; +typedef u16 be16; +typedef u32 be32; +typedef u64 be64; + /* - * Declare sle{16,32,64} to be unsigned because we do not want sign extension - * on BE architectures. + * Declare s{l,b}e{16,32,64} to be unsigned because we do not want sign + * extension on BE architectures. */ typedef u16 sle16; typedef u32 sle32; typedef u64 sle64; -typedef u16 ntfschar; /* 2-byte Unicode character type. */ +typedef u16 sbe16; +typedef u32 sbe32; +typedef u64 sbe64; + +typedef le16 ntfschar; /* 2-byte Unicode character type. */ #define UCHAR_T_SIZE_BITS 1 /* From 58bb59487c53ce3c86e23b85b7096259fe756ee3 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 21 Dec 2015 23:05:36 +0100 Subject: [PATCH 02/20] endians.h: Add const endian conversion macros for s{l,b}e{16,32,64}. --- include/ntfs-3g/endians.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/ntfs-3g/endians.h b/include/ntfs-3g/endians.h index 0604867b..f7eb6c4f 100644 --- a/include/ntfs-3g/endians.h +++ b/include/ntfs-3g/endians.h @@ -272,6 +272,14 @@ #define const_cpu_to_le32(x) __constant_cpu_to_le32(x) #define const_cpu_to_le64(x) __constant_cpu_to_le64(x) +#define const_sle16_to_cpu(x) __constant_le16_to_cpu((le16) x) +#define const_sle32_to_cpu(x) __constant_le32_to_cpu((le32) x) +#define const_sle64_to_cpu(x) __constant_le64_to_cpu((le64) x) + +#define const_cpu_to_sle16(x) __constant_cpu_to_le16((u16) x) +#define const_cpu_to_sle32(x) __constant_cpu_to_le32((u32) x) +#define const_cpu_to_sle64(x) __constant_cpu_to_le64((u64) x) + #define const_be16_to_cpu(x) __constant_be16_to_cpu(x) #define const_be32_to_cpu(x) __constant_be32_to_cpu(x) #define const_be64_to_cpu(x) __constant_be64_to_cpu(x) @@ -280,4 +288,12 @@ #define const_cpu_to_be32(x) __constant_cpu_to_be32(x) #define const_cpu_to_be64(x) __constant_cpu_to_be64(x) +#define const_sbe16_to_cpu(x) __constant_be16_to_cpu((be16) x) +#define const_sbe32_to_cpu(x) __constant_be32_to_cpu((be32) x) +#define const_sbe64_to_cpu(x) __constant_be64_to_cpu((be64) x) + +#define const_cpu_to_sbe16(x) __constant_cpu_to_be16((u16) x) +#define const_cpu_to_sbe32(x) __constant_cpu_to_be32((u32) x) +#define const_cpu_to_sbe64(x) __constant_cpu_to_be64((u64) x) + #endif /* defined _NTFS_ENDIANS_H */ From dfa4a6647fa5ac094bb1edfe23019750b0ea403c Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 21 Dec 2015 23:21:00 +0100 Subject: [PATCH 03/20] Fix code to use const_cpu_to_X/const_X_to_cpu macros for constants. This enables the compiler to optimize this code in cases where compiler support for endianness swapping is not present. --- include/ntfs-3g/layout.h | 2 +- libntfs-3g/acls.c | 2 +- libntfs-3g/attrib.c | 6 ++-- libntfs-3g/bootsect.c | 4 +-- libntfs-3g/dir.c | 8 ++--- libntfs-3g/index.c | 8 ++--- libntfs-3g/inode.c | 2 +- libntfs-3g/mft.c | 20 +++++------ libntfs-3g/unistr.c | 4 +-- ntfsprogs/mkntfs.c | 75 +++++++++++++++++++------------------- ntfsprogs/ntfscat.c | 6 ++-- ntfsprogs/ntfswipe.c | 22 ++++++------ src/secaudit.c | 78 ++++++++++++++++++++++------------------ src/secaudit.h | 60 +++++++++++++++---------------- 14 files changed, 154 insertions(+), 143 deletions(-) diff --git a/include/ntfs-3g/layout.h b/include/ntfs-3g/layout.h index 9bee6e75..a7766aca 100644 --- a/include/ntfs-3g/layout.h +++ b/include/ntfs-3g/layout.h @@ -836,7 +836,7 @@ typedef enum { 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), */ + /* Old DOS volid. Unused in NT. = const_cpu_to_le32(0x00000008), */ FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010), /* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved diff --git a/libntfs-3g/acls.c b/libntfs-3g/acls.c index 51a7e7f5..858cd818 100644 --- a/libntfs-3g/acls.c +++ b/libntfs-3g/acls.c @@ -790,7 +790,7 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, | FILE_READ | FILE_WRITE | FILE_EXEC - | cpu_to_le32(0x40); + | const_cpu_to_le32(0x40); } /* reencode GENERIC_READ (+ EXECUTE) */ if (pnewace->mask & GENERIC_READ) { diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 77b1f03a..1b6619ae 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3828,7 +3828,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, a->non_resident = 0; a->name_length = name_len; a->name_offset = (name_len - ? cpu_to_le16(offsetof(ATTR_RECORD, resident_end)) + ? const_cpu_to_le16(offsetof(ATTR_RECORD, resident_end)) : const_cpu_to_le16(0)); a->flags = data_flags; a->instance = m->next_attr_instance; @@ -3974,7 +3974,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ? STANDARD_COMPRESSION_UNIT : 0; /* If @lowest_vcn == 0, than setup empty attribute. */ if (!lowest_vcn) { - a->highest_vcn = cpu_to_sle64(-1); + a->highest_vcn = const_cpu_to_sle64(-1); a->allocated_size = 0; a->data_size = 0; a->initialized_size = 0; @@ -4874,7 +4874,7 @@ int ntfs_attr_make_non_resident(ntfs_attr *na, a->name_offset = cpu_to_le16(name_ofs); /* Setup the fields specific to non-resident attributes. */ - a->lowest_vcn = cpu_to_sle64(0); + a->lowest_vcn = const_cpu_to_sle64(0); a->highest_vcn = cpu_to_sle64((new_allocated_size - 1) >> vol->cluster_size_bits); diff --git a/libntfs-3g/bootsect.c b/libntfs-3g/bootsect.c index 92c8505d..e185fe3f 100644 --- a/libntfs-3g/bootsect.c +++ b/libntfs-3g/bootsect.c @@ -65,7 +65,7 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b) ntfs_log_debug("Beginning bootsector check.\n"); ntfs_log_debug("Checking OEMid, NTFS signature.\n"); - if (b->oem_id != cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */ + if (b->oem_id != const_cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */ ntfs_log_error("NTFS signature is missing.\n"); goto not_ntfs; } @@ -140,7 +140,7 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b) } } - if (b->end_of_sector_marker != cpu_to_le16(0xaa55)) + if (b->end_of_sector_marker != const_cpu_to_le16(0xaa55)) ntfs_log_debug("Warning: Bootsector has invalid end of sector " "marker.\n"); diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 8633c7d9..a3500aab 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -1599,11 +1599,11 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, ir->clusters_per_index_block = ni->vol->indx_record_size >> NTFS_BLOCK_SIZE_BITS; - ir->index.entries_offset = cpu_to_le32(sizeof(INDEX_HEADER)); + ir->index.entries_offset = const_cpu_to_le32(sizeof(INDEX_HEADER)); ir->index.index_length = cpu_to_le32(index_len); ir->index.allocated_size = cpu_to_le32(index_len); ie = (INDEX_ENTRY*)((u8*)ir + sizeof(INDEX_ROOT)); - ie->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); + ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); ie->key_length = 0; ie->ie_flags = INDEX_ENTRY_END; /* Add INDEX_ROOT attribute to inode. */ @@ -1711,7 +1711,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, goto err_out; } /* Set hard links count and directory flag. */ - ni->mrec->link_count = cpu_to_le16(1); + ni->mrec->link_count = const_cpu_to_le16(1); if (S_ISDIR(type)) ni->mrec->flags |= MFT_RECORD_IS_DIRECTORY; ntfs_inode_mark_dirty(ni); @@ -1970,7 +1970,7 @@ search: * (Windows also does so), however delete the name if it were * in an extent, to avoid leaving an attribute list. */ - if ((ni->mrec->link_count == cpu_to_le16(1)) && !actx->base_ntfs_ino) { + if ((ni->mrec->link_count == const_cpu_to_le16(1)) && !actx->base_ntfs_ino) { /* make sure to not loop to another search */ looking_for_dos_name = FALSE; } else { diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index d498dde4..0b6538e3 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -811,11 +811,11 @@ static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size, return NULL; ib->magic = magic_INDX; - ib->usa_ofs = cpu_to_le16(sizeof(INDEX_BLOCK)); + ib->usa_ofs = const_cpu_to_le16(sizeof(INDEX_BLOCK)); ib->usa_count = cpu_to_le16(ib_size / NTFS_BLOCK_SIZE + 1); /* Set USN to 1 */ - *(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = cpu_to_le16(1); - ib->lsn = cpu_to_le64(0); + *(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = const_cpu_to_le16(1); + ib->lsn = const_cpu_to_le64(0); ib->index_block_vcn = cpu_to_sle64(ib_vcn); @@ -1160,7 +1160,7 @@ retry : ie = ntfs_ie_get_first(&ir->index); ie->ie_flags |= INDEX_ENTRY_NODE; - ie->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN)); + ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN)); ir->index.ih_flags = LARGE_INDEX; ir->index.index_length = cpu_to_le32(le32_to_cpu(ir->index.entries_offset) diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index a4a01348..c4da274c 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -806,7 +806,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) goto err_out; } /* Collect the reparse tag, if any */ - reparse_tag = cpu_to_le32(0); + reparse_tag = const_cpu_to_le32(0); if (ni->flags & FILE_ATTR_REPARSE_POINT) { if (!ntfs_attr_lookup(AT_REPARSE_POINT, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index ac4c610b..761c2b9d 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -355,7 +355,7 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, * Set the NTFS 3.1+ specific fields while we know that the * volume version is 3.1+. */ - mrec->reserved = cpu_to_le16(0); + mrec->reserved = const_cpu_to_le16(0); mrec->mft_record_number = cpu_to_le32(MREF(mref)); } mrec->magic = magic_FILE; @@ -363,7 +363,7 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, mrec->usa_count = cpu_to_le16(vol->mft_record_size / NTFS_BLOCK_SIZE + 1); else { - mrec->usa_count = cpu_to_le16(1); + mrec->usa_count = const_cpu_to_le16(1); ntfs_log_error("Sector size is bigger than MFT record size. " "Setting usa_count to 1. If Windows chkdsk " "reports this as corruption, please email %s " @@ -372,14 +372,14 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, "Thank you.\n", NTFS_DEV_LIST); } /* Set the update sequence number to 1. */ - *(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = cpu_to_le16(1); - mrec->lsn = cpu_to_le64(0ull); - mrec->sequence_number = cpu_to_le16(1); - mrec->link_count = cpu_to_le16(0); + *(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = const_cpu_to_le16(1); + mrec->lsn = const_cpu_to_le64(0ull); + mrec->sequence_number = const_cpu_to_le16(1); + mrec->link_count = const_cpu_to_le16(0); /* Aligned to 8-byte boundary. */ mrec->attrs_offset = cpu_to_le16((le16_to_cpu(mrec->usa_ofs) + (le16_to_cpu(mrec->usa_count) << 1) + 7) & ~7); - mrec->flags = cpu_to_le16(0); + mrec->flags = const_cpu_to_le16(0); /* * Using attrs_offset plus eight bytes (for the termination attribute), * aligned to 8-byte boundary. @@ -387,11 +387,11 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, mrec->bytes_in_use = cpu_to_le32((le16_to_cpu(mrec->attrs_offset) + 8 + 7) & ~7); mrec->bytes_allocated = cpu_to_le32(vol->mft_record_size); - mrec->base_mft_record = cpu_to_le64((MFT_REF)0); - mrec->next_attr_instance = cpu_to_le16(0); + mrec->base_mft_record = const_cpu_to_le64((MFT_REF)0); + mrec->next_attr_instance = const_cpu_to_le16(0); a = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset)); a->type = AT_END; - a->length = cpu_to_le32(0); + a->length = const_cpu_to_le32(0); /* Finally, clear the unused part of the mft record. */ memset((u8*)a + 8, 0, vol->mft_record_size - ((u8*)a + 8 - (u8*)mrec)); return 0; diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c index e12d21e7..bfcfc672 100644 --- a/libntfs-3g/unistr.c +++ b/libntfs-3g/unistr.c @@ -360,7 +360,7 @@ ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen) dst = ntfs_malloc((len + 1) * sizeof(ntfschar)); if (dst) { memcpy(dst, s, len * sizeof(ntfschar)); - dst[len] = cpu_to_le16(L'\0'); + dst[len] = const_cpu_to_le16(L'\0'); } return dst; } @@ -1050,7 +1050,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs) } #endif /* Now write the NULL character. */ - ucs[o] = cpu_to_le16(L'\0'); + ucs[o] = const_cpu_to_le16(L'\0'); *outs = ucs; return o; err_out: diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index a7b1fd23..7d942a27 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -1552,7 +1552,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_le64(0); a->highest_vcn = cpu_to_sle64(highest_vcn - 1LL); a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7)); memset(a->reserved1, 0, sizeof(a->reserved1)); @@ -1571,7 +1571,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->compression_unit = 4; inited_size = val_len; /* FIXME: Set the compressed size. */ - a->compressed_size = cpu_to_le64(0); + a->compressed_size = const_cpu_to_le64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -1745,7 +1745,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_le64(0); for (i = 0; rl[i].length; i++) ; a->highest_vcn = cpu_to_sle64(rl[i].vcn - 1); @@ -1767,7 +1767,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, } a->compression_unit = 4; /* FIXME: Set the compressed size. */ - a->compressed_size = cpu_to_le64(0); + a->compressed_size = const_cpu_to_le64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -1926,17 +1926,17 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, si.last_mft_change_time = si.creation_time; si.last_access_time = si.creation_time; si.file_attributes = flags; /* already LE */ - si.maximum_versions = cpu_to_le32(0); - si.version_number = cpu_to_le32(0); - si.class_id = cpu_to_le32(0); + si.maximum_versions = const_cpu_to_le32(0); + si.version_number = const_cpu_to_le32(0); + si.class_id = const_cpu_to_le32(0); si.security_id = security_id; if (si.security_id != const_cpu_to_le32(0)) sd_size = 72; /* FIXME: $Quota support... */ - si.owner_id = cpu_to_le32(0); - si.quota_charged = cpu_to_le64(0ULL); + si.owner_id = const_cpu_to_le32(0); + si.quota_charged = const_cpu_to_le64(0ULL); /* FIXME: $UsnJrnl support... Not needed on fresh w2k3-volume */ - si.usn = cpu_to_le64(0ULL); + si.usn = const_cpu_to_le64(0ULL); /* NTFS 1.2: size of si = 48, NTFS 3.[01]: size of si = 72 */ err = insert_resident_attr_in_mft_record(m, AT_STANDARD_INFORMATION, NULL, 0, CASE_SENSITIVE, const_cpu_to_le16(0), @@ -2055,7 +2055,7 @@ static int add_attr_file_name(MFT_RECORD *m, const leMFT_REF parent_dir, } if (packed_ea_size) { fn->packed_ea_size = cpu_to_le16(packed_ea_size); - fn->reserved = cpu_to_le16(0); + fn->reserved = const_cpu_to_le16(0); } else { fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); } @@ -2481,12 +2481,12 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Setup header. */ ia_val->magic = magic_INDX; - ia_val->usa_ofs = cpu_to_le16(sizeof(INDEX_ALLOCATION)); + ia_val->usa_ofs = const_cpu_to_le16(sizeof(INDEX_ALLOCATION)); if (index_block_size >= NTFS_BLOCK_SIZE) { ia_val->usa_count = cpu_to_le16(index_block_size / NTFS_BLOCK_SIZE + 1); } else { - ia_val->usa_count = cpu_to_le16(1); + ia_val->usa_count = const_cpu_to_le16(1); ntfs_log_error("Sector size is bigger than index block size. " "Setting usa_count to 1. If Windows chkdsk " "reports this as corruption, please email %s " @@ -2496,9 +2496,9 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Set USN to 1. */ *(le16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) = - cpu_to_le16(1); - ia_val->lsn = cpu_to_le64(0); - ia_val->index_block_vcn = cpu_to_le64(0); + const_cpu_to_le16(1); + ia_val->lsn = const_cpu_to_le64(0); + ia_val->index_block_vcn = const_cpu_to_le64(0); ia_val->index.ih_flags = LEAF_NODE; /* Align to 8-byte boundary. */ ia_val->index.entries_offset = cpu_to_le32((sizeof(INDEX_HEADER) + @@ -2541,7 +2541,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Set VCN pointer to 0LL. */ *(leVCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) = - cpu_to_le64(0); + const_cpu_to_le64(0); err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size); if (err) { err = -errno; @@ -2930,8 +2930,8 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q1_data->flags = QUOTA_FLAG_DEFAULT_LIMITS; idx_entry_q1_data->bytes_used = const_cpu_to_le64(0x00); idx_entry_q1_data->change_time = mkntfs_time(); - idx_entry_q1_data->threshold = cpu_to_sle64(-1); - idx_entry_q1_data->limit = cpu_to_sle64(-1); + idx_entry_q1_data->threshold = const_cpu_to_sle64(-1); + idx_entry_q1_data->limit = const_cpu_to_sle64(-1); idx_entry_q1_data->exceeded_time = const_cpu_to_le64(0); err = insert_index_entry_in_res_dir_index(idx_entry_q1, q1_size, m, NTFS_INDEX_Q, 2, AT_UNUSED); @@ -2957,8 +2957,8 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q2_data->flags = QUOTA_FLAG_DEFAULT_LIMITS; idx_entry_q2_data->bytes_used = const_cpu_to_le64(0x00); idx_entry_q2_data->change_time = mkntfs_time(); - idx_entry_q2_data->threshold = cpu_to_sle64(-1); - idx_entry_q2_data->limit = cpu_to_sle64(-1); + idx_entry_q2_data->threshold = const_cpu_to_sle64(-1); + idx_entry_q2_data->limit = const_cpu_to_sle64(-1); idx_entry_q2_data->exceeded_time = const_cpu_to_le64(0); idx_entry_q2_data->sid.revision = 1; idx_entry_q2_data->sid.sub_authority_count = 2; @@ -3133,8 +3133,8 @@ do_next: ie->indexed_file = file_ref; ie->length = cpu_to_le16(i); ie->key_length = cpu_to_le16(file_name_size); - ie->ie_flags = cpu_to_le16(0); - ie->reserved = cpu_to_le16(0); + ie->ie_flags = const_cpu_to_le16(0); + ie->reserved = const_cpu_to_le16(0); memcpy((char*)&ie->key.file_name, (char*)file_name, file_name_size); return 0; } @@ -3189,7 +3189,7 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const leMFT_REF ref_parent, } if (packed_ea_size) { fn->packed_ea_size = cpu_to_le16(packed_ea_size); - fn->reserved = cpu_to_le16(0); + fn->reserved = const_cpu_to_le16(0); } else { fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); } @@ -3304,7 +3304,7 @@ static int create_hardlink(INDEX_BLOCK *idx, const leMFT_REF ref_parent, } if (packed_ea_size) { fn->packed_ea_size = cpu_to_le16(packed_ea_size); - fn->reserved = cpu_to_le16(0); + fn->reserved = const_cpu_to_le16(0); } else { fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); } @@ -3332,7 +3332,7 @@ static int create_hardlink(INDEX_BLOCK *idx, const leMFT_REF ref_parent, m_file->link_count = cpu_to_le16(i + 1); /* Add the file_name to @m_file. */ i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, - CASE_SENSITIVE, cpu_to_le16(0), + CASE_SENSITIVE, const_cpu_to_le16(0), RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size); if (i < 0) { ntfs_log_error("create_hardlink failed adding file name attribute: " @@ -3388,9 +3388,10 @@ static int index_obj_id_insert(MFT_RECORD *m, const GUID *guid, if (!idx_entry_new) return -errno; idx_entry_new->data_offset = cpu_to_le16(data_ofs); - idx_entry_new->data_length = cpu_to_le16(sizeof(OBJ_ID_INDEX_DATA)); + idx_entry_new->data_length = + const_cpu_to_le16(sizeof(OBJ_ID_INDEX_DATA)); idx_entry_new->length = cpu_to_le16(idx_size); - idx_entry_new->key_length = cpu_to_le16(sizeof(GUID)); + idx_entry_new->key_length = const_cpu_to_le16(sizeof(GUID)); idx_entry_new->key.object_id = *guid; oi = (OBJ_ID_INDEX_DATA*)((u8*)idx_entry_new + data_ofs); oi->mft_reference = ref; @@ -4406,7 +4407,7 @@ static BOOL mkntfs_create_root_structures(void) return FALSE; } if (i == 0 || i > 23) - m->sequence_number = cpu_to_le16(1); + m->sequence_number = const_cpu_to_le16(1); else m->sequence_number = cpu_to_le16(i); } @@ -4423,7 +4424,7 @@ static BOOL mkntfs_create_root_structures(void) "\n"); return FALSE; } - m->flags = cpu_to_le16(0); + m->flags = const_cpu_to_le16(0); m->sequence_number = cpu_to_le16(i); } } @@ -4453,22 +4454,22 @@ static BOOL mkntfs_create_root_structures(void) if (i == 0 || i == 1 || i == 2 || i == 6 || i == 8 || i == 10) { add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0100)); + const_cpu_to_le32(0x0100)); } else if (i == 9) { file_attrs |= FILE_ATTR_VIEW_INDEX_PRESENT; add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0101)); + const_cpu_to_le32(0x0101)); } else if (i == 11) { add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0101)); + const_cpu_to_le32(0x0101)); } else if (i == 24 || i == 25 || i == 26) { file_attrs |= FILE_ATTR_ARCHIVE; file_attrs |= FILE_ATTR_VIEW_INDEX_PRESENT; add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0101)); + const_cpu_to_le32(0x0101)); } else { add_attr_std_info(m, file_attrs, - cpu_to_le32(0x00)); + const_cpu_to_le32(0x00)); } } /* The root directory mft reference. */ @@ -4693,7 +4694,7 @@ static BOOL mkntfs_create_root_structures(void) * Leave zero for now as NT4 leaves it zero, too. If want it later, see * ../libntfs/bootsect.c for how to calculate it. */ - bs->checksum = cpu_to_le32(0); + bs->checksum = const_cpu_to_le32(0); /* Make sure the bootsector is ok. */ if (!ntfs_boot_sector_is_ntfs(bs)) { free(bs); @@ -4997,7 +4998,7 @@ static int mkntfs_redirect(struct mkntfs_options *opts2) g_vol->upcase_len * sizeof(ntfschar)); /* keep the version fields as zero */ memset(g_upcaseinfo, 0, sizeof(struct UPCASEINFO)); - g_upcaseinfo->len = cpu_to_le32(sizeof(struct UPCASEINFO)); + g_upcaseinfo->len = const_cpu_to_le32(sizeof(struct UPCASEINFO)); g_upcaseinfo->crc = cpu_to_le64(upcase_crc); g_vol->attrdef = ntfs_malloc(sizeof(attrdef_ntfs3x_array)); if (!g_vol->attrdef) { diff --git a/ntfsprogs/ntfscat.c b/ntfsprogs/ntfscat.c index 2ae1f9cd..e3a58284 100644 --- a/ntfsprogs/ntfscat.c +++ b/ntfsprogs/ntfscat.c @@ -183,7 +183,7 @@ static int parse_options(int argc, char **argv) opterr = 0; /* We'll handle the errors, thank you. */ opts.inode = -1; - opts.attr = cpu_to_le32(-1); + opts.attr = const_cpu_to_le32(-1); opts.attr_name = NULL; opts.attr_name_len = 0; @@ -201,7 +201,7 @@ static int parse_options(int argc, char **argv) } break; case 'a': - if (opts.attr != cpu_to_le32(-1)) { + if (opts.attr != const_cpu_to_le32(-1)) { ntfs_log_error("You must specify exactly one " "attribute.\n"); } else if (parse_attribute(optarg, &attr) > 0) { @@ -432,7 +432,7 @@ int main(int argc, char *argv[]) } attr = AT_DATA; - if (opts.attr != cpu_to_le32(-1)) + if (opts.attr != const_cpu_to_le32(-1)) attr = opts.attr; result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len); diff --git a/ntfsprogs/ntfswipe.c b/ntfsprogs/ntfswipe.c index 658aaac0..55803057 100644 --- a/ntfsprogs/ntfswipe.c +++ b/ntfsprogs/ntfswipe.c @@ -1011,14 +1011,14 @@ static s64 wipe_mft(ntfs_volume *vol, int byte, enum action act) rec->magic = magic_FILE; rec->usa_ofs = cpu_to_le16(usa_offset); rec->usa_count = cpu_to_le16((u16) usa_size); - rec->sequence_number = cpu_to_le16(0x0001); + rec->sequence_number = const_cpu_to_le16(0x0001); rec->attrs_offset = cpu_to_le16(attrs_offset); rec->bytes_in_use = cpu_to_le32(bytes_in_use); rec->bytes_allocated = cpu_to_le32(vol->mft_record_size); - rec->next_attr_instance = cpu_to_le16(0x0001); + rec->next_attr_instance = const_cpu_to_le16(0x0001); // End marker. - *((le32*) (((u8*) rec) + attrs_offset)) = cpu_to_le32(0xFFFFFFFF); + *((le32*) (((u8*) rec) + attrs_offset)) = const_cpu_to_le32(0xFFFFFFFF); } result = ntfs_attr_mst_pwrite(vol->mft_na, vol->mft_record_size * i, @@ -1795,7 +1795,7 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->value_length = cpu_to_le32(0); + ctx->attr->value_length = const_cpu_to_le32(0); if (!opts.noaction) { if (ntfs_mft_records_write(nv, MK_MREF(record, 0), 1LL, ctx->mrec) != 0) { @@ -1863,7 +1863,7 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->value_length = cpu_to_le32(0); + ctx->attr->value_length = const_cpu_to_le32(0); if ( !opts.noaction ) { if (ntfs_mft_records_write(nv, MK_MREF(record, 0), @@ -1953,12 +1953,12 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->lowest_vcn = cpu_to_le64(0); - ctx->attr->highest_vcn = cpu_to_le64(0); - ctx->attr->allocated_size = cpu_to_le64(0); - ctx->attr->data_size = cpu_to_le64(0); - ctx->attr->initialized_size = cpu_to_le64(0); - ctx->attr->compressed_size = cpu_to_le64(0); + ctx->attr->lowest_vcn = const_cpu_to_le64(0); + ctx->attr->highest_vcn = const_cpu_to_le64(0); + ctx->attr->allocated_size = const_cpu_to_le64(0); + ctx->attr->data_size = const_cpu_to_le64(0); + ctx->attr->initialized_size = const_cpu_to_le64(0); + ctx->attr->compressed_size = const_cpu_to_le64(0); if (!opts.noaction) { if (ntfs_mft_records_write(nv, MK_MREF (record, 0), diff --git a/src/secaudit.c b/src/secaudit.c index 8ffb2a91..25516264 100644 --- a/src/secaudit.c +++ b/src/secaudit.c @@ -3072,15 +3072,17 @@ void tryposix(struct POSIX_SECURITY *pxdesc) { le32 owner_sid[] = /* S-1-5-21-3141592653-589793238-462843383-1016 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(1016) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(1016) } ; le32 group_sid[] = /* S-1-5-21-3141592653-589793238-462843383-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(513) } ; char *attr; @@ -3228,9 +3230,9 @@ static char *build_dummy_descr(BOOL isdir __attribute__((unused)), pacl = (ACL*)&attr[pos]; pacl->revision = ACL_REVISION; pacl->alignment1 = 0; - pacl->size = cpu_to_le16(0); /* fixed later */ + pacl->size = const_cpu_to_le16(0); /* fixed later */ pacl->ace_count = cpu_to_le16(cnt); - pacl->alignment2 = cpu_to_le16(0); + pacl->alignment2 = const_cpu_to_le16(0); /* enter the ACEs */ @@ -3257,8 +3259,8 @@ static char *build_dummy_descr(BOOL isdir __attribute__((unused)), /* append usid and gsid if defined */ /* positions of ACL, USID and GSID into header */ - pnhead->owner = cpu_to_le32(0); - pnhead->group = cpu_to_le32(0); + pnhead->owner = const_cpu_to_le32(0); + pnhead->group = const_cpu_to_le32(0); if (usid) { memcpy(&attr[pos], usid, usidsz); pnhead->owner = cpu_to_le32(pos); @@ -3268,13 +3270,14 @@ static char *build_dummy_descr(BOOL isdir __attribute__((unused)), pnhead->group = cpu_to_le32(pos + usidsz); } /* positions of DACL and SACL into header */ - pnhead->sacl = cpu_to_le32(0); + pnhead->sacl = const_cpu_to_le32(0); if (cnt) { pacl->size = cpu_to_le16(aclsz); pnhead->dacl = - cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + const_cpu_to_le32(sizeof( + SECURITY_DESCRIPTOR_RELATIVE)); } else - pnhead->dacl = cpu_to_le32(0); + pnhead->dacl = const_cpu_to_le32(0); if (!ntfs_valid_descr(attr,pos+usidsz+gsidsz)) { printf("** Bad sample descriptor\n"); free(attr); @@ -3309,33 +3312,38 @@ void check_samples() #endif le32 owner1[] = /* S-1-5-21-1833069642-4243175381-1340018762-1003 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(1833069642), cpu_to_le32(4243175381), - cpu_to_le32(1340018762), cpu_to_le32(1003) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(1833069642), + const_cpu_to_le32(4243175381), const_cpu_to_le32(1340018762), + const_cpu_to_le32(1003) } ; le32 group1[] = /* S-1-5-21-1833069642-4243175381-1340018762-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(1833069642), cpu_to_le32(4243175381), - cpu_to_le32(1340018762), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(1833069642), + const_cpu_to_le32(4243175381), const_cpu_to_le32(1340018762), + const_cpu_to_le32(513) } ; le32 group2[] = /* S-1-5-21-1607551490-981732888-1819828000-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(1607551490), cpu_to_le32(981732888), - cpu_to_le32(1819828000), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(1607551490), + const_cpu_to_le32(981732888), const_cpu_to_le32(1819828000), + const_cpu_to_le32(513) } ; le32 owner3[] = /* S-1-5-21-3141592653-589793238-462843383-1016 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(1016) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(1016) } ; le32 group3[] = /* S-1-5-21-3141592653-589793238-462843383-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(513) } ; #if POSIXACLS @@ -4169,15 +4177,17 @@ void selftests(void) { le32 owner_sid[] = /* S-1-5-21-3141592653-589793238-462843383-1016 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(1016) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(1016) } ; le32 group_sid[] = /* S-1-5-21-3141592653-589793238-462843383-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(513) } ; #if POSIXACLS #ifdef STSC diff --git a/src/secaudit.h b/src/secaudit.h index a8ad163f..9edaf02b 100644 --- a/src/secaudit.h +++ b/src/secaudit.h @@ -216,8 +216,8 @@ typedef DWORD *LPDWORD; #define SE_SACL_PROTECTED const_cpu_to_le16(0x2000) #define SE_DACL_AUTO_INHERITED const_cpu_to_le16(0x400) #define SE_SACL_AUTO_INHERITED const_cpu_to_le16(0x800) -#define SE_DACL_AUTO_INHERIT_REQ cpu_to_le16(0x100) -#define SE_SACL_AUTO_INHERIT_REQ cpu_to_le16(0x200) +#define SE_DACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x100) +#define SE_SACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x200) typedef le16 ntfschar; @@ -326,10 +326,10 @@ typedef enum { OWNER_SECURITY_INFORMATION = 1, // The owner identifier of the object is being referenced. } SECURITY_INFORMATION; -#define STANDARD_RIGHTS_READ cpu_to_le32(0x20000) -#define STANDARD_RIGHTS_WRITE cpu_to_le32(0x20000) -#define STANDARD_RIGHTS_EXECUTE cpu_to_le32(0x20000) -#define STANDARD_RIGHTS_REQUIRED cpu_to_le32(0xf0000) +#define STANDARD_RIGHTS_READ const_cpu_to_le32(0x20000) +#define STANDARD_RIGHTS_WRITE const_cpu_to_le32(0x20000) +#define STANDARD_RIGHTS_EXECUTE const_cpu_to_le32(0x20000) +#define STANDARD_RIGHTS_REQUIRED const_cpu_to_le32(0xf0000) #endif @@ -452,39 +452,39 @@ enum { #ifndef WIN32 -#define DELETE cpu_to_le32(0x00010000L) -#define READ_CONTROL cpu_to_le32(0x00020000L) -#define WRITE_DAC cpu_to_le32(0x00040000L) -#define WRITE_OWNER cpu_to_le32(0x00080000L) -#define SYNCHRONIZE cpu_to_le32(0x00100000L) +#define DELETE const_cpu_to_le32(0x00010000L) +#define READ_CONTROL const_cpu_to_le32(0x00020000L) +#define WRITE_DAC const_cpu_to_le32(0x00040000L) +#define WRITE_OWNER const_cpu_to_le32(0x00080000L) +#define SYNCHRONIZE const_cpu_to_le32(0x00100000L) -#define FILE_READ_DATA cpu_to_le32( 0x0001 ) // file & pipe -#define FILE_LIST_DIRECTORY cpu_to_le32( 0x0001 ) // directory +#define FILE_READ_DATA const_cpu_to_le32(0x0001) // file & pipe +#define FILE_LIST_DIRECTORY const_cpu_to_le32(0x0001) // directory -#define FILE_WRITE_DATA cpu_to_le32( 0x0002 ) // file & pipe -#define FILE_ADD_FILE cpu_to_le32( 0x0002 ) // directory +#define FILE_WRITE_DATA const_cpu_to_le32(0x0002) // file & pipe +#define FILE_ADD_FILE const_cpu_to_le32(0x0002) // directory -#define FILE_APPEND_DATA cpu_to_le32( 0x0004 ) // file -#define FILE_ADD_SUBDIRECTORY cpu_to_le32( 0x0004 ) // directory -#define FILE_CREATE_PIPE_INSTANCE cpu_to_le32( 0x0004 ) // named pipe +#define FILE_APPEND_DATA const_cpu_to_le32(0x0004) // file +#define FILE_ADD_SUBDIRECTORY const_cpu_to_le32(0x0004) // directory +#define FILE_CREATE_PIPE_INSTANCE const_cpu_to_le32(0x0004) // named pipe -#define FILE_READ_EA cpu_to_le32( 0x0008 ) // file & directory +#define FILE_READ_EA const_cpu_to_le32(0x0008) // file & directory -#define FILE_WRITE_EA cpu_to_le32( 0x0010 ) // file & directory +#define FILE_WRITE_EA const_cpu_to_le32(0x0010) // file & directory -#define FILE_EXECUTE cpu_to_le32( 0x0020 ) // file -#define FILE_TRAVERSE cpu_to_le32( 0x0020 ) // directory +#define FILE_EXECUTE const_cpu_to_le32(0x0020) // file +#define FILE_TRAVERSE const_cpu_to_le32(0x0020) // directory -#define FILE_DELETE_CHILD cpu_to_le32( 0x0040 ) // directory +#define FILE_DELETE_CHILD const_cpu_to_le32(0x0040) // directory -#define FILE_READ_ATTRIBUTES cpu_to_le32( 0x0080 ) // all +#define FILE_READ_ATTRIBUTES const_cpu_to_le32(0x0080) // all -#define FILE_WRITE_ATTRIBUTES cpu_to_le32( 0x0100 ) // all +#define FILE_WRITE_ATTRIBUTES const_cpu_to_le32(0x0100) // all #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \ - cpu_to_le32(0x1FF)) + const_cpu_to_le32(0x1FF)) #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\ FILE_READ_DATA |\ @@ -506,10 +506,10 @@ enum { FILE_EXECUTE |\ SYNCHRONIZE) -#define GENERIC_READ cpu_to_le32(0x80000000L) -#define GENERIC_WRITE cpu_to_le32(0x40000000L) -#define GENERIC_EXECUTE cpu_to_le32(0x20000000L) -#define GENERIC_ALL cpu_to_le32(0x10000000L) +#define GENERIC_READ const_cpu_to_le32(0x80000000L) +#define GENERIC_WRITE const_cpu_to_le32(0x40000000L) +#define GENERIC_EXECUTE const_cpu_to_le32(0x20000000L) +#define GENERIC_ALL const_cpu_to_le32(0x10000000L) #define OBJECT_INHERIT_ACE (0x1) From f076fae75a242606ae0cbfdceb2280c06c2f1a0f Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 21 Dec 2015 23:31:09 +0100 Subject: [PATCH 04/20] Fix endianness issues in log and terminal output. This commit addresses issues where little-endian variables are emitted raw to a log or output stream which is to be interpreted by the user. Outputting data in non-native endianness can cause confusion for anybody attempting to debug issues with a file system. --- libntfs-3g/attrib.c | 70 ++++++++++++++++++------------------ libntfs-3g/compress.c | 2 +- libntfs-3g/lcnalloc.c | 2 +- libntfs-3g/mst.c | 2 +- ntfsprogs/ntfsck.c | 2 +- ntfsprogs/ntfscmp.c | 4 +-- ntfsprogs/ntfsdump_logfile.c | 2 +- ntfsprogs/ntfsinfo.c | 4 +-- ntfsprogs/ntfsmove.c | 2 +- ntfsprogs/ntfstruncate.c | 4 +-- ntfsprogs/utils.c | 10 +++--- 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 1b6619ae..63212062 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -96,7 +96,7 @@ static void NAttrSetFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) na->ni->flags |= flag; else ntfs_log_trace("Denied setting flag %d for not unnamed data " - "attribute\n", flag); + "attribute\n", le32_to_cpu(flag)); } static void NAttrClearFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) @@ -405,7 +405,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, le16 cs; ntfs_log_enter("Entering for inode %lld, attr 0x%x.\n", - (unsigned long long)ni->mft_no, type); + (unsigned long long)ni->mft_no, le32_to_cpu(type)); if (!ni || !ni->vol || !ni->mrec) { errno = EINVAL; @@ -484,7 +484,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, errno = EIO; ntfs_log_perror("Inode %lld has corrupt attribute flags " "(0x%x <> 0x%x)",(unsigned long long)ni->mft_no, - a->flags, na->ni->flags); + le16_to_cpu(a->flags), le32_to_cpu(na->ni->flags)); goto put_err_out; } @@ -494,7 +494,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, errno = EIO; ntfs_log_perror("Compressed inode %lld attr 0x%x has " "no compression unit", - (unsigned long long)ni->mft_no, type); + (unsigned long long)ni->mft_no, le32_to_cpu(type)); goto put_err_out; } ntfs_attr_init(na, TRUE, a->flags, @@ -561,7 +561,7 @@ int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn) ntfs_attr_search_ctx *ctx; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, (long long)vcn); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)vcn); lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); if (lcn >= 0 || lcn == LCN_HOLE || lcn == LCN_ENOENT) @@ -704,7 +704,7 @@ int ntfs_attr_map_whole_runlist(ntfs_attr *na) int not_mapped; ntfs_log_enter("Entering for inode %llu, attr 0x%x.\n", - (unsigned long long)na->ni->mft_no, na->type); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); /* avoid multiple full runlist mappings */ if (NAttrFullyMapped(na)) { @@ -831,7 +831,7 @@ LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn) return (LCN)LCN_EINVAL; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long - long)na->ni->mft_no, na->type); + long)na->ni->mft_no, le32_to_cpu(na->type)); retry: /* Convert vcn to lcn. If that fails map the runlist and retry once. */ lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); @@ -883,7 +883,7 @@ runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn) } ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn %llx\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)vcn); retry: rl = na->rl; @@ -1176,7 +1176,7 @@ s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b) ntfs_log_enter("Entering for inode %lld attr 0x%x pos %lld count " "%lld\n", (unsigned long long)na->ni->mft_no, - na->type, (long long)pos, (long long)count); + le32_to_cpu(na->type), (long long)pos, (long long)count); ret = ntfs_attr_pread_i(na, pos, count, b); @@ -1800,7 +1800,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) BOOL compressed; ntfs_log_enter("Entering for inode %lld, attr 0x%x, pos 0x%llx, count " - "0x%llx.\n", (long long)na->ni->mft_no, na->type, + "0x%llx.\n", (long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos, (long long)count); if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { @@ -2349,7 +2349,7 @@ int ntfs_attr_pclose(ntfs_attr *na) BOOL compressed; ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x.\n", - na->ni->mft_no, na->type); + na->ni->mft_no, le32_to_cpu(na->type)); if (!na || !na->ni || !na->ni->vol) { errno = EINVAL; @@ -2568,7 +2568,7 @@ s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt, BOOL warn; ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; @@ -2624,7 +2624,7 @@ s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt, s64 written, i; ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; @@ -2742,7 +2742,7 @@ static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, ntfschar *upcase; u32 upcase_len; - ntfs_log_trace("attribute type 0x%x.\n", type); + ntfs_log_trace("attribute type 0x%x.\n", le32_to_cpu(type)); if (ctx->ntfs_ino) { vol = ctx->ntfs_ino->vol; @@ -2967,7 +2967,7 @@ static int ntfs_external_attr_find(ATTR_TYPES type, const ntfschar *name, ni = ctx->ntfs_ino; base_ni = ctx->base_ntfs_ino; ntfs_log_trace("Entering for inode %lld, attribute type 0x%x.\n", - (unsigned long long)ni->mft_no, type); + (unsigned long long)ni->mft_no, le32_to_cpu(type)); if (!base_ni) { /* First call happens with the base mft record. */ base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino; @@ -3350,7 +3350,7 @@ int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, ntfs_inode *base_ni; int ret = -1; - ntfs_log_enter("Entering for attribute type 0x%x\n", type); + ntfs_log_enter("Entering for attribute type 0x%x\n", le32_to_cpu(type)); if (!ctx || !ctx->mrec || !ctx->attr || (name && name != AT_UNNAMED && (!ctx->ntfs_ino || !(vol = ctx->ntfs_ino->vol) || @@ -3518,7 +3518,7 @@ ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, if (!vol || !vol->attrdef || !type) { errno = EINVAL; - ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + ntfs_log_perror("%s: type=%d", __FUNCTION__, le32_to_cpu(type)); return NULL; } for (ad = vol->attrdef; (u8*)ad - (u8*)vol->attrdef < @@ -3533,7 +3533,7 @@ ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, break; } errno = ENOENT; - ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + ntfs_log_perror("%s: type=%d", __FUNCTION__, le32_to_cpu(type)); return NULL; } @@ -3594,7 +3594,7 @@ int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type, ((max_size > 0) && (size > max_size))) { errno = ERANGE; ntfs_log_perror("Attr type %d size check failed (min,size,max=" - "%lld,%lld,%lld)", type, (long long)min_size, + "%lld,%lld,%lld)", le32_to_cpu(type), (long long)min_size, (long long)size, (long long)max_size); return -1; } @@ -3774,7 +3774,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ntfs_inode *base_ni; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n", - (long long) ni->mft_no, (unsigned) type, (unsigned) data_flags); + (long long) ni->mft_no, (unsigned) le32_to_cpu(type), (unsigned) le16_to_cpu(data_flags)); if (!ni || (!name && name_len)) { errno = EINVAL; @@ -3907,8 +3907,8 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, " "dataruns_size %d, flags 0x%x.\n", - (long long) ni->mft_no, (unsigned) type, - (long long) lowest_vcn, dataruns_size, (unsigned) flags); + (long long) ni->mft_no, (unsigned) le32_to_cpu(type), + (long long) lowest_vcn, dataruns_size, (unsigned) le16_to_cpu(flags)); if (!ni || dataruns_size <= 0 || (!name && name_len)) { errno = EINVAL; @@ -3935,7 +3935,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, NULL, 0, ctx)) { err = EEXIST; - ntfs_log_perror("Attribute 0x%x already present", type); + ntfs_log_perror("Attribute 0x%x already present", le32_to_cpu(type)); goto put_err_out; } if (errno != ENOENT) { @@ -4196,7 +4196,7 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, } ntfs_log_trace("Entering for inode %lld, attr %x, size %lld.\n", - (long long)ni->mft_no, type, (long long)size); + (long long)ni->mft_no, le32_to_cpu(type), (long long)size); if (ni->nr_extents == -1) ni = ni->base_ni; @@ -4418,7 +4418,7 @@ int ntfs_attr_rm(ntfs_attr *na) } ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", - (long long) na->ni->mft_no, na->type); + (long long) na->ni->mft_no, le32_to_cpu(na->type)); /* Free cluster allocation. */ if (NAttrNonResident(na)) { @@ -4766,7 +4766,7 @@ int ntfs_attr_make_non_resident(ntfs_attr *na, int mp_size, mp_ofs, name_ofs, arec_size, err; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long - long)na->ni->mft_no, na->type); + long)na->ni->mft_no, le32_to_cpu(na->type)); /* Some preliminary sanity checking. */ if (NAttrNonResident(na)) { @@ -4960,7 +4960,7 @@ static int ntfs_resident_attr_resize_i(ntfs_attr *na, const s64 newsize, int err, ret = STATUS_ERROR; ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); /* Get the attribute record that needs modification. */ @@ -5263,7 +5263,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) s64 arec_size, bytes_read; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long - long)na->ni->mft_no, na->type); + long)na->ni->mft_no, le32_to_cpu(na->type)); /* Should be called for the first extent of the attribute. */ if (sle64_to_cpu(a->lowest_vcn)) { @@ -5425,7 +5425,7 @@ static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, int sparse, ret = 0; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x\n", - (unsigned long long)na->ni->mft_no, na->type); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); if (a->lowest_vcn) goto out; @@ -5568,7 +5568,7 @@ retry: } ntfs_log_trace("Entering for inode %llu, attr 0x%x\n", - (unsigned long long)na->ni->mft_no, na->type); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); if (!NAttrNonResident(na)) { errno = EINVAL; @@ -5997,7 +5997,7 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) int err; ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", (unsigned long long) - na->ni->mft_no, na->type, (long long)newsize); + na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); vol = na->ni->vol; @@ -6155,7 +6155,7 @@ static int ntfs_non_resident_attr_expand_i(ntfs_attr *na, const s64 newsize, int err; ntfs_log_trace("Inode %lld, attr 0x%x, new size %lld old size %lld\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize, (long long)na->data_size); vol = na->ni->vol; @@ -6426,7 +6426,7 @@ static int ntfs_attr_truncate_i(ntfs_attr *na, const s64 newsize, } ntfs_log_enter("Entering for inode %lld, attr 0x%x, size %lld\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); if (na->data_size == newsize) { @@ -6811,7 +6811,7 @@ int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, /* do not log removal of non-existent stream */ if (type != AT_DATA) { ntfs_log_perror("Failed to open attribute 0x%02x of inode " - "0x%llx", type, (unsigned long long)ni->mft_no); + "0x%llx", le32_to_cpu(type), (unsigned long long)ni->mft_no); } return -1; } @@ -6819,7 +6819,7 @@ int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, ret = ntfs_attr_rm(na); if (ret) ntfs_log_perror("Failed to remove attribute 0x%02x of inode " - "0x%llx", type, (unsigned long long)ni->mft_no); + "0x%llx", le32_to_cpu(type), (unsigned long long)ni->mft_no); ntfs_attr_close(na); return ret; diff --git a/libntfs-3g/compress.c b/libntfs-3g/compress.c index f1070aa2..45cd9346 100644 --- a/libntfs-3g/compress.c +++ b/libntfs-3g/compress.c @@ -719,7 +719,7 @@ s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b) unsigned int nr_cbs, cb_clusters; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, count 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos, (long long)count); data_flags = na->data_flags; compression = na->ni->flags & FILE_ATTR_COMPRESSED; diff --git a/libntfs-3g/lcnalloc.c b/libntfs-3g/lcnalloc.c index e84d2431..486e3510 100644 --- a/libntfs-3g/lcnalloc.c +++ b/libntfs-3g/lcnalloc.c @@ -676,7 +676,7 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x, count 0x%llx, " "vcn 0x%llx.\n", (unsigned long long)na->ni->mft_no, - na->type, (long long)count, (long long)start_vcn); + le32_to_cpu(na->type), (long long)count, (long long)start_vcn); rl = ntfs_attr_find_vcn(na, start_vcn); if (!rl) { diff --git a/libntfs-3g/mst.c b/libntfs-3g/mst.c index b7937b7a..88d5e7e6 100644 --- a/libntfs-3g/mst.c +++ b/libntfs-3g/mst.c @@ -101,7 +101,7 @@ int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size, errno = EIO; ntfs_log_perror("Incomplete multi-sector transfer: " "magic: 0x%08x size: %d usa_ofs: %d usa_count:" - " %d data: %d usn: %d", *(le32 *)b, size, + " %d data: %d usn: %d", le32_to_cpu(*(le32 *)b), size, usa_ofs, usa_count, *data_pos, usn); b->magic = magic_BAAD; return -1; diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index 27816019..ead2e9c8 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -610,7 +610,7 @@ static BOOL check_file_record(u8 *buffer, u16 buflen) // We should know all the flags. if (mft_rec->flags>0xf) { check_failed("Unknown MFT record flags (0x%x).\n", - (unsigned int)mft_rec->flags); + (unsigned int)le16_to_cpu(mft_rec->flags)); } // todo: flag in_use must be on. diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 469d1d9a..97aa17dd 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -394,7 +394,7 @@ static void print_inode_ni(ntfs_inode *ni) static void print_attribute_type(ATTR_TYPES atype) { - printf("attribute 0x%x", atype); + printf("attribute 0x%x", le32_to_cpu(atype)); } static void print_attribute_name(char *name) @@ -781,7 +781,7 @@ static int new_attribute(ntfs_attr_search_ctx *ctx, print_attribute_ctx(ctx); printf("record %llu lowest_vcn %lld: SKIPPED\n", (unsigned long long)ctx->ntfs_ino->mft_no, - (long long)ctx->attr->lowest_vcn); + (long long)sle64_to_cpu(ctx->attr->lowest_vcn)); } return 0; diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 279ebac2..b5b73f40 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -557,7 +557,7 @@ static void dump_log_record(LOG_RECORD *lr) (unsigned int)le32_to_cpu(lr->record_type)); ntfs_log_info("transaction_id = 0x%x\n", (unsigned int)le32_to_cpu(lr->transaction_id)); - ntfs_log_info("flags = 0x%x:", lr->flags); + ntfs_log_info("flags = 0x%x:", le16_to_cpu(lr->flags)); if (!lr->flags) ntfs_log_info(" NONE\n"); else { diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 817eadc4..54f28bb8 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -420,7 +420,7 @@ static void ntfs_dump_volume(ntfs_volume *vol) printf("\tDevice state: %lu\n", vol->dev->d_state); printf("\tVolume Name: %s\n", vol->vol_name); printf("\tVolume State: %lu\n", vol->state); - printf("\tVolume Flags: 0x%04x", (int)vol->flags); + printf("\tVolume Flags: 0x%04x", (int)le16_to_cpu(vol->flags)); if (vol->flags & VOLUME_IS_DIRTY) printf(" DIRTY"); if (vol->flags & VOLUME_MODIFIED_BY_CHKDSK) @@ -1695,7 +1695,7 @@ static INDEX_ATTR_TYPE get_index_attr_type(ntfs_inode *ni, ATTR_RECORD *attr, else /* weird, this should be illegal */ ntfs_log_error("Unknown index attribute type: 0x%0X\n", - index_root->type); + le32_to_cpu(index_root->type)); return INDEX_ATTR_UNKNOWN; } diff --git a/ntfsprogs/ntfsmove.c b/ntfsprogs/ntfsmove.c index 571808fd..0e11d48a 100644 --- a/ntfsprogs/ntfsmove.c +++ b/ntfsprogs/ntfsmove.c @@ -830,7 +830,7 @@ static s64 move_file(ntfs_volume *vol, ntfs_inode *ino, u64 loc, int flags) while ((rec = find_attribute(AT_UNUSED, ctx))) { utils_attr_get_name(vol, rec, buffer, MAX_PATH); - ntfs_log_info("\tAttribute 0x%02x %s is ", rec->type, buffer); + ntfs_log_info("\tAttribute 0x%02x %s is ", le32_to_cpu(rec->type), buffer); if (rec->non_resident) { ntfs_log_info("non-resident. Moving it.\n"); diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index f561690f..886a8c37 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -358,7 +358,7 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len) VOL_INF(val)->minor_ver); i = VOL_INF(val)->flags; #undef VOL_INF - printf("Volume flags = 0x%x: ", i); + printf("Volume flags = 0x%x: ", le16_to_cpu(i)); if (!i) { printf("NONE\n"); return; @@ -776,7 +776,7 @@ int main(int argc, char **argv) err = ntfs_attr_truncate(na, new_len); if (err) err_exit("Failed to truncate attribute 0x%x: %s\n", - (unsigned int)attr_type, strerror(errno)); + (unsigned int)le32_to_cpu(attr_type), strerror(errno)); if (!opts.quiet && opts.verbose > 1) { ntfs_log_verbose("Dumping mft record after calling " diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index 7ac31163..636ccd9a 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -458,11 +458,11 @@ ATTR_RECORD * find_attribute(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) } if (ntfs_attr_lookup(type, NULL, 0, 0, 0, NULL, 0, ctx) != 0) { - ntfs_log_debug("find_attribute didn't find an attribute of type: 0x%02x.\n", type); + ntfs_log_debug("find_attribute didn't find an attribute of type: 0x%02x.\n", le32_to_cpu(type)); return NULL; /* None / no more of that type */ } - ntfs_log_debug("find_attribute found an attribute of type: 0x%02x.\n", type); + ntfs_log_debug("find_attribute found an attribute of type: 0x%02x.\n", le32_to_cpu(type)); return ctx->attr; } @@ -499,9 +499,9 @@ ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft) rec = find_attribute(type, ctx); ntfs_attr_put_search_ctx(ctx); if (rec) - ntfs_log_debug("find_first_attribute: found attr of type 0x%02x.\n", type); + ntfs_log_debug("find_first_attribute: found attr of type 0x%02x.\n", le32_to_cpu(type)); else - ntfs_log_debug("find_first_attribute: didn't find attr of type 0x%02x.\n", type); + ntfs_log_debug("find_first_attribute: didn't find attr of type 0x%02x.\n", le32_to_cpu(type)); return rec; } @@ -659,7 +659,7 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b } len = snprintf(buffer, bufsize, "%s", name); } else { - ntfs_log_error("Unknown attribute type 0x%02x\n", attr->type); + ntfs_log_error("Unknown attribute type 0x%02x\n", le32_to_cpu(attr->type)); len = snprintf(buffer, bufsize, ""); } From 9cf04fd2cd1905692d0842106d3c707495aafa61 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 21 Dec 2015 23:55:31 +0100 Subject: [PATCH 05/20] Fix incorrect usage of native/little-endian types, signed types, etc. This is harmless with regard to code generation but if we turn on strict type checking these type mismatches will result in errors. --- include/ntfs-3g/inode.h | 2 +- include/ntfs-3g/ntfstime.h | 2 +- libntfs-3g/attrib.c | 18 +++++++++--------- libntfs-3g/attrlist.c | 8 ++++---- libntfs-3g/dir.c | 12 ++++++------ libntfs-3g/efs.c | 4 ++-- libntfs-3g/index.c | 14 +++++++------- libntfs-3g/inode.c | 28 ++++++++++++++-------------- libntfs-3g/logfile.c | 8 ++++---- libntfs-3g/mft.c | 8 ++++---- libntfs-3g/mst.c | 10 +++++----- libntfs-3g/unistr.c | 2 +- ntfsprogs/mkntfs.c | 20 ++++++++++---------- ntfsprogs/ntfsck.c | 4 ++-- ntfsprogs/ntfsclone.c | 22 +++++++++++----------- ntfsprogs/ntfscmp.c | 2 +- ntfsprogs/ntfscp.c | 10 +++++----- ntfsprogs/ntfsdecrypt.c | 2 +- ntfsprogs/ntfsdump_logfile.c | 10 +++++----- ntfsprogs/ntfsfallocate.c | 8 ++++---- ntfsprogs/ntfsfix.c | 24 ++++++++++++------------ ntfsprogs/ntfslabel.c | 4 ++-- ntfsprogs/ntfsmftalloc.c | 2 +- ntfsprogs/ntfsresize.c | 34 +++++++++++++++++----------------- ntfsprogs/ntfstruncate.c | 2 +- ntfsprogs/ntfswipe.c | 12 ++++++------ ntfsprogs/sd.c | 8 ++++---- src/lowntfs-3g.c | 12 ++++++------ src/ntfs-3g.c | 14 +++++++------- 29 files changed, 153 insertions(+), 153 deletions(-) diff --git a/include/ntfs-3g/inode.h b/include/ntfs-3g/inode.h index 5a6f7da6..8d58d245 100644 --- a/include/ntfs-3g/inode.h +++ b/include/ntfs-3g/inode.h @@ -197,7 +197,7 @@ extern int ntfs_inode_nidata_hash(const struct CACHED_GENERIC *item); extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, - const MFT_REF mref); + const leMFT_REF mref); extern int ntfs_inode_attach_all_extents(ntfs_inode *ni); diff --git a/include/ntfs-3g/ntfstime.h b/include/ntfs-3g/ntfstime.h index 236c0fb4..f3a89dd8 100644 --- a/include/ntfs-3g/ntfstime.h +++ b/include/ntfs-3g/ntfstime.h @@ -102,7 +102,7 @@ static __inline__ ntfs_time timespec2ntfs(struct timespec spec) units = (s64)spec.tv_sec * 10000000 + NTFS_TIME_OFFSET + spec.tv_nsec/100; - return (cpu_to_le64(units)); + return (cpu_to_sle64(units)); } /* diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 63212062..82e50210 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -452,7 +452,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, * does not detect or fix them so we need to cope with it, too. */ if (type == AT_ATTRIBUTE_LIST) - a->flags = 0; + a->flags = const_cpu_to_le16(0); if ((type == AT_DATA) && (a->non_resident ? !a->initialized_size : !a->value_length)) { @@ -643,7 +643,7 @@ static int ntfs_attr_map_partial_runlist(ntfs_attr *na, VCN vcn) rl = na->rl; if (rl) { na->rl = rl; - highest_vcn = le64_to_cpu(a->highest_vcn); + highest_vcn = sle64_to_cpu(a->highest_vcn); if (highest_vcn < needed) { /* corruption detection on unchanged runlists */ if (newrunlist @@ -1040,7 +1040,7 @@ res_err_out: count--; total2++; } else { - *(u16*)((u8*)b+count-2) = cpu_to_le16(efs_padding_length); + *(le16*)((u8*)b+count-2) = cpu_to_le16(efs_padding_length); count -= 2; total2 +=2; } @@ -3975,9 +3975,9 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, /* If @lowest_vcn == 0, than setup empty attribute. */ if (!lowest_vcn) { a->highest_vcn = const_cpu_to_sle64(-1); - a->allocated_size = 0; - a->data_size = 0; - a->initialized_size = 0; + a->allocated_size = const_cpu_to_sle64(0); + a->data_size = const_cpu_to_sle64(0); + a->initialized_size = const_cpu_to_sle64(0); /* Set empty mapping pairs. */ *((u8*)a + le16_to_cpu(a->mapping_pairs_offset)) = 0; } @@ -4891,7 +4891,7 @@ int ntfs_attr_make_non_resident(ntfs_attr *na, if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { /* support only ATTR_IS_COMPRESSED compression mode */ a->compression_unit = STANDARD_COMPRESSION_UNIT; - a->compressed_size = const_cpu_to_le64(0); + a->compressed_size = const_cpu_to_sle64(0); } else { a->compression_unit = 0; a->flags &= ~ATTR_COMPRESSION_MASK; @@ -5337,7 +5337,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) /* Convert the attribute record to describe a resident attribute. */ a->non_resident = 0; - a->flags = 0; + a->flags = const_cpu_to_le16(0); a->value_length = cpu_to_le32(na->data_size); a->value_offset = cpu_to_le16(val_ofs); /* @@ -6762,7 +6762,7 @@ int ntfs_attr_shrink_size(ntfs_inode *ni, ntfschar *stream_name, if (a->non_resident && (sle64_to_cpu(a->initialized_size) > offset)) { - a->initialized_size = cpu_to_le64(offset); + a->initialized_size = cpu_to_sle64(offset); a->data_size = a->initialized_size; } res = 0; diff --git a/libntfs-3g/attrlist.c b/libntfs-3g/attrlist.c index 9c62f316..29d40859 100644 --- a/libntfs-3g/attrlist.c +++ b/libntfs-3g/attrlist.c @@ -107,7 +107,7 @@ int ntfs_attrlist_need(ntfs_inode *ni) int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) { ATTR_LIST_ENTRY *ale; - MFT_REF mref; + leMFT_REF mref; ntfs_attr *na = NULL; ntfs_attr_search_ctx *ctx; u8 *new_al; @@ -150,7 +150,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) if (!ntfs_attr_lookup(attr->type, (attr->name_length) ? (ntfschar*) ((u8*)attr + le16_to_cpu(attr->name_offset)) : AT_UNNAMED, attr->name_length, CASE_SENSITIVE, - (attr->non_resident) ? le64_to_cpu(attr->lowest_vcn) : + (attr->non_resident) ? sle64_to_cpu(attr->lowest_vcn) : 0, (attr->non_resident) ? NULL : ((u8*)attr + le16_to_cpu(attr->value_offset)), (attr->non_resident) ? 0 : le32_to_cpu(attr->value_length), ctx)) { @@ -193,7 +193,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) if (attr->non_resident) ale->lowest_vcn = attr->lowest_vcn; else - ale->lowest_vcn = 0; + ale->lowest_vcn = const_cpu_to_sle64(0); ale->mft_reference = mref; ale->instance = attr->instance; memcpy(ale->name, (u8 *)attr + le16_to_cpu(attr->name_offset), @@ -265,7 +265,7 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld.\n", (long long) ctx->ntfs_ino->mft_no, (unsigned) le32_to_cpu(ctx->al_entry->type), - (long long) le64_to_cpu(ctx->al_entry->lowest_vcn)); + (long long) sle64_to_cpu(ctx->al_entry->lowest_vcn)); if (!NInoAttrList(base_ni)) { ntfs_log_trace("Attribute list isn't present.\n"); diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index a3500aab..9041eec2 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -384,7 +384,7 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, } /* 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)); descend_into_child_node: @@ -496,7 +496,7 @@ descend_into_child_node: goto close_err_out; } /* Child node present, descend into it. */ - 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) goto descend_into_child_node; ntfs_log_error("Negative child node vcn in directory inode " @@ -1531,7 +1531,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, si->last_access_time = ni->last_access_time; if (securid) { set_nino_flag(ni, v3_Extensions); - ni->owner_id = si->owner_id = 0; + ni->owner_id = si->owner_id = const_cpu_to_le32(0); ni->security_id = si->security_id = securid; ni->quota_charged = si->quota_charged = const_cpu_to_le64(0); ni->usn = si->usn = const_cpu_to_le64(0); @@ -1604,7 +1604,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, ir->index.allocated_size = cpu_to_le32(index_len); ie = (INDEX_ENTRY*)((u8*)ir + sizeof(INDEX_ROOT)); ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); - ie->key_length = 0; + ie->key_length = const_cpu_to_le16(0); ie->ie_flags = INDEX_ENTRY_END; /* Add INDEX_ROOT attribute to inode. */ if (ntfs_attr_add(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4, @@ -1691,7 +1691,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, fn->last_mft_change_time = ni->last_mft_change_time; fn->last_access_time = ni->last_access_time; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) - fn->data_size = fn->allocated_size = const_cpu_to_le64(0); + fn->data_size = fn->allocated_size = const_cpu_to_sle64(0); else { fn->data_size = cpu_to_sle64(ni->data_size); fn->allocated_size = cpu_to_sle64(ni->allocated_size); @@ -2186,7 +2186,7 @@ static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, fn->file_attributes = ni->flags; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { fn->file_attributes |= FILE_ATTR_I30_INDEX_PRESENT; - fn->data_size = fn->allocated_size = const_cpu_to_le64(0); + fn->data_size = fn->allocated_size = const_cpu_to_sle64(0); } else { fn->allocated_size = cpu_to_sle64(ni->allocated_size); fn->data_size = cpu_to_sle64(ni->data_size); diff --git a/libntfs-3g/efs.c b/libntfs-3g/efs.c index 7957005b..14a2cb51 100644 --- a/libntfs-3g/efs.c +++ b/libntfs-3g/efs.c @@ -420,8 +420,8 @@ int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na) NInoSetDirty(ni); NInoFileNameSetDirty(ni); - ctx->attr->data_size = cpu_to_le64(newsize); - if (le64_to_cpu(ctx->attr->initialized_size) > newsize) + ctx->attr->data_size = cpu_to_sle64(newsize); + if (sle64_to_cpu(ctx->attr->initialized_size) > newsize) ctx->attr->initialized_size = ctx->attr->data_size; ctx->attr->flags |= ATTR_IS_ENCRYPTED; if (close_ctx) diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index 0b6538e3..0ca91de0 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -191,9 +191,9 @@ void ntfs_index_ctx_reinit(ntfs_index_context *icx) }; } -static VCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie) +static leVCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie) { - return (VCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(VCN)); + return (leVCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(leVCN)); } /** @@ -338,7 +338,7 @@ static void ntfs_ie_delete(INDEX_HEADER *ih, INDEX_ENTRY *ie) static void ntfs_ie_set_vcn(INDEX_ENTRY *ie, VCN vcn) { - *ntfs_ie_get_vcn_addr(ie) = cpu_to_le64(vcn); + *ntfs_ie_get_vcn_addr(ie) = cpu_to_sle64(vcn); } /** @@ -814,14 +814,14 @@ static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size, ib->usa_ofs = const_cpu_to_le16(sizeof(INDEX_BLOCK)); ib->usa_count = cpu_to_le16(ib_size / NTFS_BLOCK_SIZE + 1); /* Set USN to 1 */ - *(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = const_cpu_to_le16(1); - ib->lsn = const_cpu_to_le64(0); + *(le16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = const_cpu_to_le16(1); + ib->lsn = const_cpu_to_sle64(0); ib->index_block_vcn = cpu_to_sle64(ib_vcn); ib->index.entries_offset = cpu_to_le32((ih_size + le16_to_cpu(ib->usa_count) * 2 + 7) & ~7); - ib->index.index_length = 0; + ib->index.index_length = const_cpu_to_le32(0); ib->index.allocated_size = cpu_to_le32(ib_size - (sizeof(INDEX_BLOCK) - ih_size)); ib->index.ih_flags = node_type; @@ -2042,7 +2042,7 @@ static INDEX_ENTRY *ntfs_index_walk_up(INDEX_ENTRY *ie, INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, ntfs_index_context *ictx) { INDEX_ENTRY *next; - int flags; + le16 flags; /* * lookup() may have returned an invalid node diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index c4da274c..a43714cc 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -570,7 +570,7 @@ int ntfs_inode_close(ntfs_inode *ni) * Note, extent inodes are never closed directly. They are automatically * disposed off by the closing of the base inode. */ -ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref) +ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const leMFT_REF mref) { u64 mft_no = MREF_LE(mref); VCN extent_vcn; @@ -874,7 +874,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) (ni->flags & FILE_ATTR_VALID_FLAGS); if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) fnx->data_size = fnx->allocated_size - = const_cpu_to_le64(0); + = const_cpu_to_sle64(0); else { fnx->allocated_size = cpu_to_sle64(ni->allocated_size); fnx->data_size = cpu_to_sle64(ni->data_size); @@ -1168,7 +1168,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) if (ctx->attr->non_resident) ale->lowest_vcn = ctx->attr->lowest_vcn; else - ale->lowest_vcn = 0; + ale->lowest_vcn = const_cpu_to_sle64(0); ale->mft_reference = MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); ale->instance = ctx->attr->instance; @@ -1206,7 +1206,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) /* Add $ATTRIBUTE_LIST to mft record. */ if (ntfs_resident_attr_record_add(ni, - AT_ATTRIBUTE_LIST, NULL, 0, NULL, 0, 0) < 0) { + AT_ATTRIBUTE_LIST, NULL, 0, NULL, 0, const_cpu_to_le16(0)) < 0) { err = errno; ntfs_log_perror("Couldn't add $ATTRIBUTE_LIST to MFT"); goto rollback; @@ -1477,18 +1477,18 @@ int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size) le16_to_cpu(ctx->attr->value_offset)); if (value && (size >= 8)) { times = (u64*)value; - times[0] = le64_to_cpu(std_info->creation_time); + times[0] = sle64_to_cpu(std_info->creation_time); ret = 8; if (size >= 16) { - times[1] = le64_to_cpu(std_info->last_data_change_time); + times[1] = sle64_to_cpu(std_info->last_data_change_time); ret = 16; } if (size >= 24) { - times[2] = le64_to_cpu(std_info->last_access_time); + times[2] = sle64_to_cpu(std_info->last_access_time); ret = 24; } if (size >= 32) { - times[3] = le64_to_cpu(std_info->last_mft_change_time); + times[3] = sle64_to_cpu(std_info->last_mft_change_time); ret = 32; } } else @@ -1551,16 +1551,16 @@ int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, * return sub-second times in getattr() */ set_nino_flag(ni, TimesSet); - std_info->creation_time = cpu_to_le64(times[0]); + std_info->creation_time = cpu_to_sle64(times[0]); ni->creation_time = std_info->creation_time; if (size >= 16) { - std_info->last_data_change_time = cpu_to_le64(times[1]); + std_info->last_data_change_time = cpu_to_sle64(times[1]); ni->last_data_change_time = std_info->last_data_change_time; } if (size >= 24) { - std_info->last_access_time = cpu_to_le64(times[2]); + std_info->last_access_time = cpu_to_sle64(times[2]); ni->last_access_time = std_info->last_access_time; } @@ -1578,13 +1578,13 @@ int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, fn = (FILE_NAME_ATTR*)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); fn->creation_time - = cpu_to_le64(times[0]); + = cpu_to_sle64(times[0]); if (size >= 16) fn->last_data_change_time - = cpu_to_le64(times[1]); + = cpu_to_sle64(times[1]); if (size >= 24) fn->last_access_time - = cpu_to_le64(times[2]); + = cpu_to_sle64(times[2]); fn->last_mft_change_time = now; cnt++; } diff --git a/libntfs-3g/logfile.c b/libntfs-3g/logfile.c index 336bdd28..dfe5b7d4 100644 --- a/libntfs-3g/logfile.c +++ b/libntfs-3g/logfile.c @@ -90,10 +90,10 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) * Windows 8, and we will refuse to mount. * Nevertheless, do all the relevant checks before rejecting. */ - if (((rp->major_ver != const_cpu_to_le16(1)) - || (rp->minor_ver != const_cpu_to_le16(1))) - && ((rp->major_ver != const_cpu_to_le16(2)) - || (rp->minor_ver != const_cpu_to_le16(0)))) { + if (((rp->major_ver != const_cpu_to_sle16(1)) + || (rp->minor_ver != const_cpu_to_sle16(1))) + && ((rp->major_ver != const_cpu_to_sle16(2)) + || (rp->minor_ver != const_cpu_to_sle16(0)))) { ntfs_log_error("$LogFile version %i.%i is not " "supported.\n (This driver supports version " "1.1 and 2.0 only.)\n", diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index 761c2b9d..a88391fb 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -372,8 +372,8 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, "Thank you.\n", NTFS_DEV_LIST); } /* Set the update sequence number to 1. */ - *(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = const_cpu_to_le16(1); - mrec->lsn = const_cpu_to_le64(0ull); + *(le16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = const_cpu_to_le16(1); + mrec->lsn = const_cpu_to_sle64(0ll); mrec->sequence_number = const_cpu_to_le16(1); mrec->link_count = const_cpu_to_le16(0); /* Aligned to 8-byte boundary. */ @@ -1510,7 +1510,7 @@ found_free_rec: ntfs_inode_mark_dirty(ni); /* Initialize time, allocated and data size in ntfs_inode struct. */ ni->data_size = ni->allocated_size = 0; - ni->flags = 0; + ni->flags = const_cpu_to_le32(0); ni->creation_time = ni->last_data_change_time = ni->last_mft_change_time = ni->last_access_time = ntfs_current_time(); @@ -1814,7 +1814,7 @@ found_free_rec: ntfs_inode_mark_dirty(ni); /* Initialize time, allocated and data size in ntfs_inode struct. */ ni->data_size = ni->allocated_size = 0; - ni->flags = 0; + ni->flags = const_cpu_to_le32(0); ni->creation_time = ni->last_data_change_time = ni->last_mft_change_time = ni->last_access_time = ntfs_current_time(); diff --git a/libntfs-3g/mst.c b/libntfs-3g/mst.c index 88d5e7e6..9a164390 100644 --- a/libntfs-3g/mst.c +++ b/libntfs-3g/mst.c @@ -157,7 +157,7 @@ int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size) int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) { u16 usa_ofs, usa_count, usn; - u16 *usa_pos, *data_pos; + le16 *usa_pos, *data_pos; ntfs_log_trace("Entering\n"); @@ -181,7 +181,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) return -1; } /* 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). @@ -191,8 +191,8 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) usn = 1; usn = cpu_to_le16(usn); *usa_pos = usn; - /* Position in data of first u16 that needs fixing up. */ - data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; + /* Position in data of first le16 that needs fixing up. */ + data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1; /* Fixup all sectors. */ while (usa_count--) { /* @@ -203,7 +203,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) /* Apply fixup to data. */ *data_pos = usn; /* Increment position in data as well. */ - data_pos += NTFS_BLOCK_SIZE/sizeof(u16); + data_pos += NTFS_BLOCK_SIZE/sizeof(le16); } return 0; } diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c index bfcfc672..a56c0b8c 100644 --- a/libntfs-3g/unistr.c +++ b/libntfs-3g/unistr.c @@ -244,7 +244,7 @@ int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len, */ int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n) { - ntfschar c1, c2; + u16 c1, c2; size_t i; #ifdef DEBUG diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 7d942a27..8fec2dfd 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -1552,7 +1552,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = const_cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_sle64(0); a->highest_vcn = cpu_to_sle64(highest_vcn - 1LL); a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7)); memset(a->reserved1, 0, sizeof(a->reserved1)); @@ -1571,7 +1571,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->compression_unit = 4; inited_size = val_len; /* FIXME: Set the compressed size. */ - a->compressed_size = const_cpu_to_le64(0); + a->compressed_size = const_cpu_to_sle64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -1745,7 +1745,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = const_cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_sle64(0); for (i = 0; rl[i].length; i++) ; a->highest_vcn = cpu_to_sle64(rl[i].vcn - 1); @@ -1767,7 +1767,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, } a->compression_unit = 4; /* FIXME: Set the compressed size. */ - a->compressed_size = const_cpu_to_le64(0); + a->compressed_size = const_cpu_to_sle64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -2497,8 +2497,8 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, /* Set USN to 1. */ *(le16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) = const_cpu_to_le16(1); - ia_val->lsn = const_cpu_to_le64(0); - ia_val->index_block_vcn = const_cpu_to_le64(0); + ia_val->lsn = const_cpu_to_sle64(0); + ia_val->index_block_vcn = const_cpu_to_sle64(0); ia_val->index.ih_flags = LEAF_NODE; /* Align to 8-byte boundary. */ ia_val->index.entries_offset = cpu_to_le32((sizeof(INDEX_HEADER) + @@ -2541,7 +2541,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Set VCN pointer to 0LL. */ *(leVCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) = - const_cpu_to_le64(0); + const_cpu_to_sle64(0); err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size); if (err) { err = -errno; @@ -2932,7 +2932,7 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q1_data->change_time = mkntfs_time(); idx_entry_q1_data->threshold = const_cpu_to_sle64(-1); idx_entry_q1_data->limit = const_cpu_to_sle64(-1); - idx_entry_q1_data->exceeded_time = const_cpu_to_le64(0); + idx_entry_q1_data->exceeded_time = const_cpu_to_sle64(0); err = insert_index_entry_in_res_dir_index(idx_entry_q1, q1_size, m, NTFS_INDEX_Q, 2, AT_UNUSED); free(idx_entry_q1); @@ -2959,7 +2959,7 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q2_data->change_time = mkntfs_time(); idx_entry_q2_data->threshold = const_cpu_to_sle64(-1); idx_entry_q2_data->limit = const_cpu_to_sle64(-1); - idx_entry_q2_data->exceeded_time = const_cpu_to_le64(0); + idx_entry_q2_data->exceeded_time = const_cpu_to_sle64(0); idx_entry_q2_data->sid.revision = 1; idx_entry_q2_data->sid.sub_authority_count = 2; for (i = 0; i < 5; i++) @@ -4965,7 +4965,7 @@ static int mkntfs_redirect(struct mkntfs_options *opts2) goto done; } /* Initialize the random number generator with the current time. */ - srandom(le64_to_cpu(mkntfs_time())/10000000); + srandom(sle64_to_cpu(mkntfs_time())/10000000); /* Allocate and initialize ntfs_volume structure g_vol. */ g_vol = ntfs_volume_alloc(); if (!g_vol) { diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index ead2e9c8..fee0dc3a 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -247,7 +247,7 @@ static BOOL verify_boot_sector(struct ntfs_device *dev, ntfs_volume *rawvol) * * Assumes dev is open. */ -static runlist *load_runlist(ntfs_volume *rawvol, s64 offset_to_file_record, u32 attr_type, u32 size_of_file_record) +static runlist *load_runlist(ntfs_volume *rawvol, s64 offset_to_file_record, ATTR_TYPES attr_type, u32 size_of_file_record) { u8 *buf; u16 attrs_offset; @@ -789,7 +789,7 @@ static void check_volume(ntfs_volume *vol) static int reset_dirty(ntfs_volume *vol) { - u16 flags; + le16 flags; if (!(vol->flags | VOLUME_IS_DIRTY)) return 0; diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index 1504c252..2ed9b8e4 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -898,7 +898,7 @@ static void gap_to_cluster(s64 gap) static void image_skip_clusters(s64 count) { if (opt.save_image && count > 0) { - s64 count_buf; + sle64 count_buf; char buff[1 + sizeof(count)]; buff[0] = CMD_GAP; @@ -1012,7 +1012,7 @@ static void restore_image(void) progress_init(&progress, p_counter, opt.std_out ? sle64_to_cpu(image_hdr.nr_clusters) + 1 : - sle64_to_cpu(image_hdr.inuse) + 1, + le64_to_cpu(image_hdr.inuse) + 1, 100); if (opt.new_serial) @@ -1032,7 +1032,7 @@ static void restore_image(void) if (cmd == CMD_GAP) { if (!image_is_host_endian) { - le64 lecount; + sle64 lecount; /* little endian image, on any computer */ if (read_all(&fd_in, &lecount, @@ -1083,7 +1083,7 @@ static void restore_image(void) static void wipe_index_entry_timestams(INDEX_ENTRY *e) { static const struct timespec zero_time = { .tv_sec = 0, .tv_nsec = 0 }; - le64 timestamp = timespec2ntfs(zero_time); + sle64 timestamp = timespec2ntfs(zero_time); /* FIXME: can fall into infinite loop if corrupted */ while (!(e->ie_flags & INDEX_ENTRY_END)) { @@ -1193,7 +1193,7 @@ out_indexr: free(indexr); } -static void wipe_index_root_timestamps(ATTR_RECORD *attr, le64 timestamp) +static void wipe_index_root_timestamps(ATTR_RECORD *attr, sle64 timestamp) { INDEX_ENTRY *entry; INDEX_ROOT *iroot; @@ -1256,7 +1256,7 @@ static void wipe_timestamps(ntfs_walk_clusters_ctx *image) { static const struct timespec zero_time = { .tv_sec = 0, .tv_nsec = 0 }; ATTR_RECORD *a = image->ctx->attr; - le64 timestamp = timespec2ntfs(zero_time); + sle64 timestamp = timespec2ntfs(zero_time); if (a->type == AT_FILE_NAME) WIPE_TIMESTAMPS(FILE_NAME_ATTR, a, timestamp); @@ -2097,10 +2097,10 @@ static void print_image_info(void) sle64_to_cpu(image_hdr.nr_clusters) * le32_to_cpu(image_hdr.cluster_size)); Printf("Image device size : %lld bytes\n", - (long long)sle64_to_cpu(image_hdr.device_size)); + (long long)le64_to_cpu(image_hdr.device_size)); print_disk_usage(" ", le32_to_cpu(image_hdr.cluster_size), sle64_to_cpu(image_hdr.nr_clusters), - sle64_to_cpu(image_hdr.inuse)); + le64_to_cpu(image_hdr.inuse)); Printf("Offset to image data : %u (0x%x) bytes\n", (unsigned)le32_to_cpu(image_hdr.offset_to_image_data), (unsigned)le32_to_cpu(image_hdr.offset_to_image_data)); @@ -2402,7 +2402,7 @@ static s64 open_image(void) free(dummy_buf); } } - return sle64_to_cpu(image_hdr.device_size); + return le64_to_cpu(image_hdr.device_size); } static s64 open_volume(void) @@ -2432,9 +2432,9 @@ static void initialise_image_hdr(s64 device_size, s64 inuse) image_hdr.major_ver = NTFSCLONE_IMG_VER_MAJOR; image_hdr.minor_ver = NTFSCLONE_IMG_VER_MINOR; image_hdr.cluster_size = cpu_to_le32(vol->cluster_size); - image_hdr.device_size = cpu_to_sle64(device_size); + image_hdr.device_size = cpu_to_le64(device_size); image_hdr.nr_clusters = cpu_to_sle64(vol->nr_clusters); - image_hdr.inuse = cpu_to_sle64(inuse); + image_hdr.inuse = cpu_to_le64(inuse); image_hdr.offset_to_image_data = cpu_to_le32((sizeof(image_hdr) + IMAGE_HDR_ALIGN - 1) & -IMAGE_HDR_ALIGN); } diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 97aa17dd..3ac73365 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -830,7 +830,7 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2) int old_ret1, ret1 = 0, ret2 = 0; int errno1 = 0, errno2 = 0; char *prev_name = NULL, *name1 = NULL, *name2 = NULL; - ATTR_TYPES old_atype1, prev_atype = 0, atype1, atype2; + ATTR_TYPES old_atype1, prev_atype = const_cpu_to_le32(0), atype1, atype2; ntfs_attr_search_ctx *ctx1, *ctx2; if (!(ctx1 = attr_get_search_ctx(ni1))) diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index 87a7da30..feee4061 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -609,11 +609,11 @@ static int set_sizes(struct ALLOC_CONTEXT *alctx, ntfs_attr_search_ctx *ctx) /* Feed the sizes into the attribute */ attr = ctx->attr; attr->non_resident = 1; - attr->data_size = cpu_to_le64(na->data_size); - attr->initialized_size = cpu_to_le64(na->initialized_size); - attr->allocated_size = cpu_to_le64(na->allocated_size); + attr->data_size = cpu_to_sle64(na->data_size); + attr->initialized_size = cpu_to_sle64(na->initialized_size); + attr->allocated_size = cpu_to_sle64(na->allocated_size); if (na->data_flags & ATTR_IS_SPARSE) - attr->compressed_size = cpu_to_le64(na->compressed_size); + attr->compressed_size = cpu_to_sle64(na->compressed_size); /* Copy the unnamed data attribute sizes to inode */ if ((opts.attribute == AT_DATA) && !na->name_len) { ni = na->ni; @@ -806,7 +806,7 @@ static ntfs_inode *ntfs_new_file(ntfs_inode *dir_ni, filename); return NULL; } - ni = ntfs_create(dir_ni, 0, ufilename, ufilename_len, S_IFREG); + ni = ntfs_create(dir_ni, const_cpu_to_le32(0), ufilename, ufilename_len, S_IFREG); free(ufilename); return ni; } diff --git a/ntfsprogs/ntfsdecrypt.c b/ntfsprogs/ntfsdecrypt.c index ab58cbd9..cbde912a 100644 --- a/ntfsprogs/ntfsdecrypt.c +++ b/ntfsprogs/ntfsdecrypt.c @@ -1049,7 +1049,7 @@ static ntfs_fek *ntfs_fek_import_from_raw(u8 *fek_buf, unsigned fek_size) gcry_error_t err; ntfs_desx_ctx *ctx; - key_size = le32_to_cpup(fek_buf); + key_size = le32_to_cpup((le32*) fek_buf); ntfs_log_debug("key_size 0x%x\n", key_size); if (key_size + 16 > fek_size) { ntfs_log_debug("Invalid FEK. It was probably decrypted with " diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index b5b73f40..7fe22b3d 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -542,11 +542,11 @@ static void dump_log_record(LOG_RECORD *lr) { unsigned int i; ntfs_log_info("this lsn = 0x%llx\n", - (unsigned long long)le64_to_cpu(lr->this_lsn)); + (unsigned long long)sle64_to_cpu(lr->this_lsn)); ntfs_log_info("client previous lsn = 0x%llx\n", (unsigned long long) - le64_to_cpu(lr->client_previous_lsn)); + sle64_to_cpu(lr->client_previous_lsn)); ntfs_log_info("client undo next lsn = 0x%llx\n", (unsigned long long) - le64_to_cpu(lr->client_undo_next_lsn)); + sle64_to_cpu(lr->client_undo_next_lsn)); ntfs_log_info("client data length = 0x%x\n", (unsigned int)le32_to_cpu(lr->client_data_length)); ntfs_log_info("client_id.seq_number = 0x%x\n", @@ -628,14 +628,14 @@ rcrd_pass_loc: "CHKD"); // TODO: I am here... (AIA) ntfs_log_info("copy.last_lsn/file_offset = 0x%llx\n", (unsigned long long) - le64_to_cpu(rcrd->copy.last_lsn)); + sle64_to_cpu(rcrd->copy.last_lsn)); ntfs_log_info("flags = 0x%x\n", (unsigned int)le32_to_cpu(rcrd->flags)); ntfs_log_info("page count = %i\n", le16_to_cpu(rcrd->page_count)); ntfs_log_info("page position = %i\n", le16_to_cpu(rcrd->page_position)); ntfs_log_info("header.next_record_offset = 0x%llx\n", (unsigned long long) le64_to_cpu(rcrd->header.packed.next_record_offset)); ntfs_log_info("header.last_end_lsn = 0x%llx\n", (unsigned long long) - le64_to_cpu(rcrd->header.packed.last_end_lsn)); + sle64_to_cpu(rcrd->header.packed.last_end_lsn)); /* * Where does the 0x40 come from? Is it just usa_offset + * usa_client * 2 + 7 & ~7 or is it derived from somewhere? diff --git a/ntfsprogs/ntfsfallocate.c b/ntfsprogs/ntfsfallocate.c index 1b243ae6..83c68234 100644 --- a/ntfsprogs/ntfsfallocate.c +++ b/ntfsprogs/ntfsfallocate.c @@ -704,14 +704,14 @@ static int ntfs_full_allocation(ntfs_attr *na, ntfs_attr_search_ctx *ctx, } else { /* Feed the sizes into the attribute */ attr = ctx->attr; - attr->data_size = cpu_to_le64(na->data_size); + attr->data_size = cpu_to_sle64(na->data_size); attr->initialized_size - = cpu_to_le64(na->initialized_size); + = cpu_to_sle64(na->initialized_size); attr->allocated_size - = cpu_to_le64(na->allocated_size); + = cpu_to_sle64(na->allocated_size); if (na->data_flags & ATTR_IS_SPARSE) attr->compressed_size - = cpu_to_le64(na->compressed_size); + = cpu_to_sle64(na->compressed_size); /* Copy the unnamed data attribute sizes to inode */ if ((attr_type == AT_DATA) && !attr_name_len) { ni = na->ni; diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index 59b8a98f..568fd9ae 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -781,7 +781,7 @@ static BOOL short_mft_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) a = find_unnamed_attr(mft0,AT_DATA); if (a && a->non_resident - && (((le64_to_cpu(a->highest_vcn) + 1) + && (((sle64_to_cpu(a->highest_vcn) + 1) << vol->cluster_size_bits) == (SELFLOC_LIMIT*vol->mft_record_size))) { rl = ntfs_mapping_pairs_decompress(vol, a, NULL); @@ -841,13 +841,13 @@ static BOOL attrlist_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) rl = ntfs_mapping_pairs_decompress(vol, a, NULL); if (rl && (rl->lcn >= 0) - && (le64_to_cpu(a->data_size) < vol->cluster_size) + && (sle64_to_cpu(a->data_size) < vol->cluster_size) && (ntfs_pread(vol->dev, rl->lcn << vol->cluster_size_bits, vol->cluster_size, attrlist) == vol->cluster_size)) { selfloc->attrlist_lcn = rl->lcn; al = attrlist; - length = le64_to_cpu(a->data_size); + length = sle64_to_cpu(a->data_size); } } else { al = (ATTR_LIST_ENTRY*) @@ -858,7 +858,7 @@ static BOOL attrlist_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) /* search for a data attribute defining entry 16 */ vcn = (SELFLOC_LIMIT*vol->mft_record_size) >> vol->cluster_size_bits; - levcn = cpu_to_le64(vcn); + levcn = cpu_to_sle64(vcn); while ((length > 0) && al->length && ((al->type != AT_DATA) @@ -921,7 +921,7 @@ static BOOL self_mapped_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) a = find_unnamed_attr(mft1,AT_DATA); if (a && (mft1->flags & MFT_RECORD_IN_USE) - && ((VCN)le64_to_cpu(a->lowest_vcn) == lowest_vcn) + && ((VCN)sle64_to_cpu(a->lowest_vcn) == lowest_vcn) && (le64_to_cpu(mft1->base_mft_record) == selfloc->mft_ref0) && ((u16)MSEQNO(selfloc->mft_ref1) @@ -1020,9 +1020,9 @@ static int fix_selfloc_conditions(struct MFT_SELF_LOCATED *selfloc) mft1->sequence_number = const_cpu_to_le16(SELFLOC_LIMIT - 1); a = find_unnamed_attr(mft1,AT_DATA); if (a) { - a->allocated_size = const_cpu_to_le64(0); - a->data_size = const_cpu_to_le64(0); - a->initialized_size = const_cpu_to_le64(0); + a->allocated_size = const_cpu_to_sle64(0); + a->data_size = const_cpu_to_sle64(0); + a->initialized_size = const_cpu_to_sle64(0); } else res = -1; /* bug : it has been found earlier */ @@ -1189,8 +1189,8 @@ static int try_fix_boot(ntfs_volume *vol, char *full_bs, ntfs_log_perror("Error reading alternate bootsector"); } else { bs = (NTFS_BOOT_SECTOR*)full_bs; - got_sectors = le64_to_cpu(bs->number_of_sectors); - bs->number_of_sectors = cpu_to_le64(fix_sectors); + got_sectors = sle64_to_cpu(bs->number_of_sectors); + bs->number_of_sectors = cpu_to_sle64(fix_sectors); /* alignment problem on Sparc, even doing memcpy() */ sector_size_le = cpu_to_le16(sector_size); if (!memcmp(§or_size_le, &bs->bpb.bytes_per_sector,2) @@ -1325,7 +1325,7 @@ static int check_alternate_boot(ntfs_volume *vol) br = ntfs_pread(vol->dev, 0, vol->sector_size, full_bs); if (br == vol->sector_size) { bs = (NTFS_BOOT_SECTOR*)full_bs; - got_sectors = le64_to_cpu(bs->number_of_sectors); + got_sectors = sle64_to_cpu(bs->number_of_sectors); actual_sectors = ntfs_device_size_get(vol->dev, vol->sector_size); if (actual_sectors > got_sectors) { @@ -1453,7 +1453,7 @@ static int fix_startup(struct ntfs_device *dev, unsigned long flags) if (!ntfs_boot_sector_is_ntfs(bs) /* get the bootsector data, only fails when inconsistent */ || (ntfs_boot_sector_parse(vol, bs) < 0)) { - shown_sectors = le64_to_cpu(bs->number_of_sectors); + shown_sectors = sle64_to_cpu(bs->number_of_sectors); /* boot sector is wrong, try the alternate boot sector */ if (try_alternate_boot(vol, full_bs, sector_size, shown_sectors)) { diff --git a/ntfsprogs/ntfslabel.c b/ntfsprogs/ntfslabel.c index c0494ab5..77a34f08 100644 --- a/ntfsprogs/ntfslabel.c +++ b/ntfsprogs/ntfslabel.c @@ -299,7 +299,7 @@ static int set_new_serial(ntfs_volume *vol) serial_number = cpu_to_le64(sn); } if (!change_serial(vol, 0, serial_number, bs, oldbs)) { - number_of_sectors = le64_to_cpu(bs->number_of_sectors); + number_of_sectors = sle64_to_cpu(bs->number_of_sectors); if (!change_serial(vol, number_of_sectors, serial_number, bs, oldbs)) { ntfs_log_info("New serial number : %016llx\n", @@ -389,7 +389,7 @@ static int change_label(ntfs_volume *vol, char *label) (unsigned)(label_len - (0x100 / sizeof(ntfschar)))); label_len = 0x100 / sizeof(ntfschar); - label[label_len] = const_cpu_to_le16(0); + label[label_len] = 0; } if(!opts.noaction) diff --git a/ntfsprogs/ntfsmftalloc.c b/ntfsprogs/ntfsmftalloc.c index 246ab54a..96f7f79d 100644 --- a/ntfsprogs/ntfsmftalloc.c +++ b/ntfsprogs/ntfsmftalloc.c @@ -229,7 +229,7 @@ static void dump_mft_record(MFT_RECORD *m) ntfs_log_info("Update sequence array offset = %u (0x%x)\n", u, u); ntfs_log_info("Update sequence array size = %u\n", le16_to_cpu(m->usa_count)); ntfs_log_info("$LogFile sequence number (lsn) = %llu\n", - (unsigned long long)le64_to_cpu(m->lsn)); + (unsigned long long)sle64_to_cpu(m->lsn)); ntfs_log_info("Sequence number = %u\n", le16_to_cpu(m->sequence_number)); ntfs_log_info("Reference (hard link) count = %u\n", le16_to_cpu(m->link_count)); diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index ce3b9f54..1c1bff5f 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -1412,7 +1412,7 @@ static void replace_later(ntfs_resize_t *resize, runlist *rl, runlist *head_rl) delayed->type = a->type; delayed->attr_name = attr_name; delayed->name_len = name_len; - delayed->lowest_vcn = le64_to_cpu(a->lowest_vcn); + delayed->lowest_vcn = sle64_to_cpu(a->lowest_vcn); delayed->rl = rl; delayed->head_rl = head_rl; delayed->next = resize->delayed_runlists; @@ -2058,7 +2058,7 @@ static void relocate_inodes(ntfs_resize_t *resize) s64 nr_mft_records; MFT_REF mref; VCN highest_vcn; - u64 length; + s64 length; printf("Relocating needed data ...\n"); @@ -2103,11 +2103,11 @@ static void relocate_inodes(ntfs_resize_t *resize) while (!ntfs_attrs_walk(resize->ctx) && (resize->ctx->attr->type != AT_DATA)) { } if (resize->ctx->attr->type == AT_DATA) { - le64 high_le; + sle64 high_le; high_le = resize->ctx->attr->highest_vcn; - if (le64_to_cpu(high_le) < length) - length = le64_to_cpu(high_le) + 1; + if (sle64_to_cpu(high_le) < length) + length = sle64_to_cpu(high_le) + 1; } else { err_exit("Could not find the DATA of MFT\n"); } @@ -3064,7 +3064,7 @@ static s64 get_data_size(expand_t *expand, s64 inum) /* get the size of unnamed $DATA */ a = get_unnamed_attr(expand, AT_DATA, inum); if (a && a->non_resident) - size = le64_to_cpu(a->allocated_size); + size = sle64_to_cpu(a->allocated_size); if (!size) { err_printf("Bad record %lld, could not get its size\n", (long long)inum); @@ -3092,7 +3092,7 @@ static u8 *get_mft_bitmap(expand_t *expand) /* get the runlist of unnamed bitmap */ a = get_unnamed_attr(expand, AT_BITMAP, FILE_MFT); ok = TRUE; - bitmap_size = le64_to_cpu(a->allocated_size); + bitmap_size = sle64_to_cpu(a->allocated_size); if (a && a->non_resident && ((bitmap_size << (vol->mft_record_size_bits + 3)) @@ -3615,10 +3615,10 @@ static int copy_boot(expand_t *expand) if (buf) { /* set the new volume parameters in the bootsector */ bs = (NTFS_BOOT_SECTOR*)expand->bootsector; - bs->number_of_sectors = cpu_to_le64(expand->new_sectors); - bs->mft_lcn = cpu_to_le64(expand->mft_lcn); + bs->number_of_sectors = cpu_to_sle64(expand->new_sectors); + bs->mft_lcn = cpu_to_sle64(expand->mft_lcn); mftmirr_lcn = vol->mftmirr_lcn + expand->cluster_increment; - bs->mftmirr_lcn = cpu_to_le64(mftmirr_lcn); + bs->mftmirr_lcn = cpu_to_sle64(mftmirr_lcn); /* the hidden sectors are needed to boot into windows */ memcpy(&hidden_sectors_le,&bs->bpb.hidden_sectors,4); /* alignment messed up on the Sparc */ @@ -3984,11 +3984,11 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum) rl[1].length = 0; if (set_bitmap(expand,rl)) res = -1; - a->data_size = cpu_to_le64(data_size); + a->data_size = cpu_to_sle64(data_size); a->initialized_size = a->data_size; a->allocated_size - = cpu_to_le64(allocated_size); - a->highest_vcn = cpu_to_le64(lth - 1); + = cpu_to_sle64(allocated_size); + a->highest_vcn = cpu_to_sle64(lth - 1); } /* expand the named data for $BadClus */ if ((a->type == AT_DATA) @@ -4004,11 +4004,11 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum) prl[1].vcn = lth; } else prl->vcn = lth; - a->data_size = cpu_to_le64(data_size); + a->data_size = cpu_to_sle64(data_size); /* do not change the initialized size */ a->allocated_size - = cpu_to_le64(allocated_size); - a->highest_vcn = cpu_to_le64(lth - 1); + = cpu_to_sle64(allocated_size); + a->highest_vcn = cpu_to_sle64(lth - 1); } if (!res && update_runlist(expand,inum,a,rl)) res = -1; @@ -4212,7 +4212,7 @@ static ntfs_volume *get_volume_data(expand_t *expand, struct ntfs_device *dev, && ntfs_boot_sector_is_ntfs(bs) && !ntfs_boot_sector_parse(vol, bs)) { expand->original_sectors - = le64_to_cpu(bs->number_of_sectors); + = sle64_to_cpu(bs->number_of_sectors); expand->mrec = (MFT_RECORD*) ntfs_malloc(vol->mft_record_size); if (expand->mrec diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 886a8c37..90b88998 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -638,7 +638,7 @@ static void dump_mft_record(MFT_RECORD *m) printf("Update sequence array offset = %u (0x%x)\n", u, u); printf("Update sequence array size = %u\n", le16_to_cpu(m->usa_count)); printf("$LogFile sequence number (lsn) = %llu\n", - (unsigned long long)le64_to_cpu(m->lsn)); + (unsigned long long)sle64_to_cpu(m->lsn)); printf("Sequence number = %u\n", le16_to_cpu(m->sequence_number)); printf("Reference (hard link) count = %u\n", le16_to_cpu(m->link_count)); diff --git a/ntfsprogs/ntfswipe.c b/ntfsprogs/ntfswipe.c index 55803057..ad794172 100644 --- a/ntfsprogs/ntfswipe.c +++ b/ntfsprogs/ntfswipe.c @@ -1953,12 +1953,12 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->lowest_vcn = const_cpu_to_le64(0); - ctx->attr->highest_vcn = const_cpu_to_le64(0); - ctx->attr->allocated_size = const_cpu_to_le64(0); - ctx->attr->data_size = const_cpu_to_le64(0); - ctx->attr->initialized_size = const_cpu_to_le64(0); - ctx->attr->compressed_size = const_cpu_to_le64(0); + ctx->attr->lowest_vcn = const_cpu_to_sle64(0); + ctx->attr->highest_vcn = const_cpu_to_sle64(0); + ctx->attr->allocated_size = const_cpu_to_sle64(0); + ctx->attr->data_size = const_cpu_to_sle64(0); + ctx->attr->initialized_size = const_cpu_to_sle64(0); + ctx->attr->compressed_size = const_cpu_to_sle64(0); if (!opts.noaction) { if (ntfs_mft_records_write(nv, MK_MREF (record, 0), diff --git a/ntfsprogs/sd.c b/ntfsprogs/sd.c index 4e3af978..a60a8288 100644 --- a/ntfsprogs/sd.c +++ b/ntfsprogs/sd.c @@ -187,7 +187,7 @@ void init_root_sd(u8 **sd_val, int *sd_val_len) sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; sd->owner = const_cpu_to_le32(0x1014); sd->group = const_cpu_to_le32(0x1020); - sd->sacl = 0; + sd->sacl = const_cpu_to_le32(0); sd->dacl = const_cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); //acl @@ -196,7 +196,7 @@ void init_root_sd(u8 **sd_val, int *sd_val_len) acl->alignment1 = 0; acl->size = const_cpu_to_le16(0x1000); acl->ace_count = const_cpu_to_le16(0x08); - acl->alignment2 = 0; + acl->alignment2 = const_cpu_to_le16(0); //ace1 ace = (ACCESS_ALLOWED_ACE*)((u8*)acl + sizeof(ACL)); @@ -436,7 +436,7 @@ void init_secure_sds(char *sd_val) acl->alignment1 = 0x00; acl->size = const_cpu_to_le16(0x34); acl->ace_count = const_cpu_to_le16(0x02); - acl->alignment2 = 0x00; + acl->alignment2 = const_cpu_to_le16(0x00); //ace1 ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); @@ -532,7 +532,7 @@ void init_secure_sds(char *sd_val) acl->alignment1 = 0x00; acl->size = const_cpu_to_le16(0x34); acl->ace_count = const_cpu_to_le16(0x02); - acl->alignment2 = 0x00; + acl->alignment2 = const_cpu_to_le16(0x00); //ace1 ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 3ff8b9de..8ce3d9f6 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -270,10 +270,10 @@ static void ntfs_fuse_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) if (ctx->atime == ATIME_DISABLED) mask &= ~NTFS_UPDATE_ATIME; else if (ctx->atime == ATIME_RELATIVE && mask == NTFS_UPDATE_ATIME && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_data_change_time)) && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_mft_change_time))) + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_data_change_time)) && + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_mft_change_time))) return; ntfs_inode_update_times(ni, mask); } @@ -1416,8 +1416,8 @@ static void ntfs_fuse_write(fuse_req_t req, fuse_ino_t ino, const char *buf, res = total; if ((res > 0) && (!ctx->dmtime - || (le64_to_cpu(ntfs_current_time()) - - le64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) + || (sle64_to_cpu(ntfs_current_time()) + - sle64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) ntfs_fuse_update_times(na->ni, NTFS_UPDATE_MCTIME); exit: if (na) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index de0f920e..dc2d4454 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -232,10 +232,10 @@ static void ntfs_fuse_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) if (ctx->atime == ATIME_DISABLED) mask &= ~NTFS_UPDATE_ATIME; else if (ctx->atime == ATIME_RELATIVE && mask == NTFS_UPDATE_ATIME && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_data_change_time)) && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_mft_change_time))) + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_data_change_time)) && + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_mft_change_time))) return; ntfs_inode_update_times(ni, mask); } @@ -1339,8 +1339,8 @@ static int ntfs_fuse_write(const char *org_path, const char *buf, size_t size, res = total; if ((res > 0) && (!ctx->dmtime - || (le64_to_cpu(ntfs_current_time()) - - le64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) + || (sle64_to_cpu(ntfs_current_time()) + - sle64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) ntfs_fuse_update_times(na->ni, NTFS_UPDATE_MCTIME); exit: if (na) @@ -1709,7 +1709,7 @@ static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev, * have to build a security attribute later. */ if (!ctx->security.mapping[MAPUSERS]) - securid = 0; + securid = const_cpu_to_le32(0); else if (ctx->inherit) securid = ntfs_inherited_id(&security, From 75da0ce302f2b40f52cd178c54f699522f1d6f4e Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 4 Jan 2016 10:08:15 +0100 Subject: [PATCH 06/20] Fix inverted usage of endian conversion macros. This is mostly a semantic issue since the end result would be the same. --- ntfsprogs/mkntfs.c | 2 +- ntfsprogs/ntfstruncate.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 8fec2dfd..affbb919 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -2540,7 +2540,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, goto err_out; } /* Set VCN pointer to 0LL. */ - *(leVCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) = + *(leVCN*)((char*)re + le16_to_cpu(re->length) - sizeof(VCN)) = const_cpu_to_sle64(0); err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size); if (err) { diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 90b88998..9cd44c76 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -563,12 +563,12 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("Length of resident part = %u (0x%x)\n", u, u); printf("Attribute is %sresident\n", a->non_resident ? "non-" : ""); printf("Name length = %u unicode characters\n", a->name_length); - printf("Name offset = %u (0x%x)\n", cpu_to_le16(a->name_offset), - cpu_to_le16(a->name_offset)); + printf("Name offset = %u (0x%x)\n", le16_to_cpu(a->name_offset), + le16_to_cpu(a->name_offset)); u = a->flags; if (a->name_length) { if (ucstos(s, (ntfschar*)((char*)a + - cpu_to_le16(a->name_offset)), + le16_to_cpu(a->name_offset)), min((int)sizeof(s), a->name_length + 1)) == -1) { ntfs_log_error("Could not convert Unicode string to single " From 84f042e73962e5e0a7162051d5f1814e41ef396e Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 4 Jan 2016 10:19:05 +0100 Subject: [PATCH 07/20] reparse.c: Fix big-endian bug when converting file name to lowercase. When looking up the lowercase equivalent of a Unicode character in ntfs_fix_file_name, no byte swapping was performed on the ntfschar used as index into the 'locase' array. This would lead to very strange results on big-endian systems. --- libntfs-3g/reparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libntfs-3g/reparse.c b/libntfs-3g/reparse.c index 7b96902c..ee14efbe 100644 --- a/libntfs-3g/reparse.c +++ b/libntfs-3g/reparse.c @@ -195,7 +195,7 @@ static u64 ntfs_fix_file_name(ntfs_inode *dir_ni, ntfschar *uname, uname[i] = found->file_name[i]; } else { for (i=0; ifile_name_length; i++) - uname[i] = vol->locase[found->file_name[i]]; + uname[i] = vol->locase[le16_to_cpu(found->file_name[i])]; } } } From 8aa2769d702374cd582685cb25a6b703f07865e1 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 25 Jan 2016 11:30:13 +0100 Subject: [PATCH 08/20] mst.c: Fix mixed native/little-endian usage of variable 'usn'. --- libntfs-3g/mst.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libntfs-3g/mst.c b/libntfs-3g/mst.c index 9a164390..9dff7738 100644 --- a/libntfs-3g/mst.c +++ b/libntfs-3g/mst.c @@ -157,6 +157,7 @@ int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size) int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) { u16 usa_ofs, usa_count, usn; + le16 le_usn; le16 *usa_pos, *data_pos; ntfs_log_trace("Entering\n"); @@ -189,8 +190,8 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) 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 le16 that needs fixing up. */ data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1; /* Fixup all sectors. */ @@ -201,7 +202,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) */ *(++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(le16); } From 701cd61cca83d504ad5cf14d908e49b32aad18be Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 25 Jan 2016 11:31:12 +0100 Subject: [PATCH 09/20] volume.c: Fix passing bad pointer type to ntfs_is_[baad|mft]_recordp. --- libntfs-3g/volume.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index edd76979..dc9aa9ab 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -963,13 +963,13 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags) mrec = (MFT_RECORD*)(m + i * vol->mft_record_size); if (mrec->flags & MFT_RECORD_IN_USE) { - if (ntfs_is_baad_recordp(mrec)) { + if (ntfs_is_baad_recordp(&mrec->magic)) { ntfs_log_error("$MFT error: Incomplete multi " "sector transfer detected in " "'%s'.\n", s); goto io_error_exit; } - if (!ntfs_is_mft_recordp(mrec)) { + if (!ntfs_is_mft_recordp(&mrec->magic)) { ntfs_log_error("$MFT error: Invalid mft " "record for '%s'.\n", s); goto io_error_exit; @@ -977,13 +977,13 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags) } mrec2 = (MFT_RECORD*)(m2 + i * vol->mft_record_size); if (mrec2->flags & MFT_RECORD_IN_USE) { - if (ntfs_is_baad_recordp(mrec2)) { + if (ntfs_is_baad_recordp(&mrec2->magic)) { ntfs_log_error("$MFTMirr error: Incomplete " "multi sector transfer " "detected in '%s'.\n", s); goto io_error_exit; } - if (!ntfs_is_mft_recordp(mrec2)) { + if (!ntfs_is_mft_recordp(&mrec2->magic)) { ntfs_log_error("$MFTMirr error: Invalid mft " "record for '%s'.\n", s); goto io_error_exit; From 02ce4947dfdb5aa9ed936f8187faa47f506d4d20 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 07:55:45 +0100 Subject: [PATCH 10/20] ntfs-3g.c: Fix raw usage of inode time fields without byteswapping. --- src/ntfs-3g.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index dc2d4454..1e56de72 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -568,7 +568,7 @@ static int ntfs_macfuse_getxtimes(const char *org_path, } /* We have no backup timestamp in NTFS. */ - crtime->tv_sec = ni->creation_time; + crtime->tv_sec = sle64_to_cpu(ni->creation_time); exit: if (ntfs_inode_close(ni)) set_fuse_error(&res); @@ -590,7 +590,7 @@ int ntfs_macfuse_setcrtime(const char *path, const struct timespec *tv) return -errno; if (tv) { - ni->creation_time = tv->tv_sec; + ni->creation_time = cpu_to_sle64(tv->tv_sec); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } @@ -632,7 +632,7 @@ int ntfs_macfuse_setchgtime(const char *path, const struct timespec *tv) return -errno; if (tv) { - ni->last_mft_change_time = tv->tv_sec; + ni->last_mft_change_time = cpu_to_sle64(tv->tv_sec); ntfs_fuse_update_times(ni, 0); } From efa876d31becaf8fb55c314a36ecc2618896bb6f Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:03:36 +0100 Subject: [PATCH 11/20] ntfstruncate.c: Fix mixed endianness usage of variable 'u'. In 'dump_attr_record' the variable 'u' was first used to store a CPU-endian 32-bit value, and then to store a 16-bit little-endian value. This is bad practice and results in a hard error when strict endian type checking is used. Fixed by storing the 16-bit little-endian flags value in a new variable 'flags'. --- ntfsprogs/ntfstruncate.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 9cd44c76..bfd19e0d 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -531,6 +531,7 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) unsigned int u; char s[0x200]; int i; + ATTR_FLAGS flags; printf("-- Beginning dump of attribute record at offset 0x%x. --\n", (unsigned)((u8*)a - (u8*)m)); @@ -565,7 +566,7 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("Name length = %u unicode characters\n", a->name_length); printf("Name offset = %u (0x%x)\n", le16_to_cpu(a->name_offset), le16_to_cpu(a->name_offset)); - u = a->flags; + flags = a->flags; if (a->name_length) { if (ucstos(s, (ntfschar*)((char*)a + le16_to_cpu(a->name_offset)), @@ -579,17 +580,17 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) } printf("Name = %s\n", s); } - printf("Attribute flags = 0x%x: ", le16_to_cpu(u)); - if (!u) + printf("Attribute flags = 0x%x: ", le16_to_cpu(flags)); + if (!flags) printf("NONE"); else { int first = TRUE; - if (u & ATTR_COMPRESSION_MASK) { - if (u & ATTR_IS_COMPRESSED) { + if (flags & ATTR_COMPRESSION_MASK) { + if (flags & ATTR_IS_COMPRESSED) { printf("ATTR_IS_COMPRESSED"); first = FALSE; } - if ((u & ATTR_COMPRESSION_MASK) & ~ATTR_IS_COMPRESSED) { + if ((flags & ATTR_COMPRESSION_MASK) & ~ATTR_IS_COMPRESSED) { if (!first) printf(" | "); else @@ -597,14 +598,14 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("ATTR_UNKNOWN_COMPRESSION"); } } - if (u & ATTR_IS_ENCRYPTED) { + if (flags & ATTR_IS_ENCRYPTED) { if (!first) printf(" | "); else first = FALSE; printf("ATTR_IS_ENCRYPTED"); } - if (u & ATTR_IS_SPARSE) { + if (flags & ATTR_IS_SPARSE) { if (!first) printf(" | "); else From 1b67b943df224cd340248476476e6f7dc55dd501 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:18:51 +0100 Subject: [PATCH 12/20] ntfstruncate.c: Fix conflicting endianness for variable 'attr_type'. If the attribute type is specified by the user, 'attr_type' was assigned a CPU-endian value, however if the attribute type was not specified it would be assigned the attribute type AT_DATA, which is a little-endian value. The rest of the code seems to assume that 'attr_type' is CPU-endian, so this is clearly a bug. Resolved by fixing the endianness of the variable at little-endian, converting the input value to little-endian when specified. --- ntfsprogs/ntfstruncate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index bfd19e0d..f64bdbee 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -75,7 +75,7 @@ BOOL success = FALSE; char *dev_name; s64 inode; -u32 attr_type; +ATTR_TYPES attr_type; ntfschar *attr_name = NULL; u32 attr_name_len; s64 new_len; @@ -236,7 +236,7 @@ static void parse_options(int argc, char *argv[]) if (*s2 || !ul || (ul >= ULONG_MAX && errno == ERANGE)) err_exit("Invalid attribute type %s: %s\n", s, strerror(errno)); - attr_type = ul; + attr_type = cpu_to_le32(ul); /* Get the attribute name, if specified. */ s = argv[optind++]; @@ -258,7 +258,7 @@ static void parse_options(int argc, char *argv[]) attr_name_len = 0; } } - ntfs_log_verbose("attribute type = 0x%x\n", (unsigned int)attr_type); + ntfs_log_verbose("attribute type = 0x%x\n", (unsigned int)le32_to_cpu(attr_type)); if (attr_name == AT_UNNAMED) ntfs_log_verbose("attribute name = \"\" (UNNAMED)\n"); else @@ -666,7 +666,7 @@ static void dump_mft_record(MFT_RECORD *m) a = (ATTR_RECORD*)((char*)m + le16_to_cpu(m->attrs_offset)); printf("-- Beginning dump of attributes within mft record. --\n"); while ((char*)a < (char*)m + le32_to_cpu(m->bytes_in_use)) { - if (a->type == cpu_to_le32(attr_type)) + if (a->type == attr_type) dump_attr_record(m, a); if (a->type == AT_END) break; @@ -765,7 +765,7 @@ int main(int argc, char **argv) na = ntfs_attr_open(ni, attr_type, attr_name, attr_name_len); if (!na) err_exit("Failed to open attribute 0x%x: %s\n", - (unsigned int)attr_type, strerror(errno)); + (unsigned int)le32_to_cpu(attr_type), strerror(errno)); if (!opts.quiet && opts.verbose > 1) { ntfs_log_verbose("Dumping mft record before calling " From 7e9003b1470d67c7fe2e5765bd6c50325dc62a41 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:19:44 +0100 Subject: [PATCH 13/20] ntfstruncate.c: Fix incorrect type for CPU-endian value in 'ucstos'. --- ntfsprogs/ntfstruncate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index f64bdbee..990c3aa1 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -286,7 +286,7 @@ static void parse_options(int argc, char *argv[]) */ static int ucstos(char *dest, const ntfschar *src, int maxlen) { - ntfschar u; + u16 u; int i; /* Need one byte for null terminator. */ From ef09702b0c4a171dc2cf1a21b88ff56d7abb2488 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:28:38 +0100 Subject: [PATCH 14/20] ntfstruncate.c: Fix mixed endianness usage of variable 'i'. In 'dump_resident_attr_val', 'i' was sometimes used as a native-endian 'int'-precision string length value and sometimes used as a little- endian 16-bit flags value. This type of mixed usage is bad practice and results in a hard error when strict endianness checking is used. Fixed by introducing new variable 'flags' to hold the little-endian 16- bit flags value. --- ntfsprogs/ntfstruncate.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 990c3aa1..e9970558 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -314,6 +314,7 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len) const char *todo = "This is still work in progress."; char *buf; int i, j; + VOLUME_FLAGS flags; u32 u; switch (type) { @@ -356,54 +357,54 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len) #define VOL_INF(x) ((VOLUME_INFORMATION *)(x)) printf("NTFS version %i.%i\n", VOL_INF(val)->major_ver, VOL_INF(val)->minor_ver); - i = VOL_INF(val)->flags; + flags = VOL_INF(val)->flags; #undef VOL_INF - printf("Volume flags = 0x%x: ", le16_to_cpu(i)); - if (!i) { + printf("Volume flags = 0x%x: ", le16_to_cpu(flags)); + if (!flags) { printf("NONE\n"); return; } j = 0; - if (i & VOLUME_MODIFIED_BY_CHKDSK) { + if (flags & VOLUME_MODIFIED_BY_CHKDSK) { j = 1; printf("VOLUME_MODIFIED_BY_CHKDSK"); } - if (i & VOLUME_REPAIR_OBJECT_ID) { + if (flags & VOLUME_REPAIR_OBJECT_ID) { if (j) printf(" | "); else j = 0; printf("VOLUME_REPAIR_OBJECT_ID"); } - if (i & VOLUME_DELETE_USN_UNDERWAY) { + if (flags & VOLUME_DELETE_USN_UNDERWAY) { if (j) printf(" | "); else j = 0; printf("VOLUME_DELETE_USN_UNDERWAY"); } - if (i & VOLUME_MOUNTED_ON_NT4) { + if (flags & VOLUME_MOUNTED_ON_NT4) { if (j) printf(" | "); else j = 0; printf("VOLUME_MOUNTED_ON_NT4"); } - if (i & VOLUME_UPGRADE_ON_MOUNT) { + if (flags & VOLUME_UPGRADE_ON_MOUNT) { if (j) printf(" | "); else j = 0; printf("VOLUME_UPGRADE_ON_MOUNT"); } - if (i & VOLUME_RESIZE_LOG_FILE) { + if (flags & VOLUME_RESIZE_LOG_FILE) { if (j) printf(" | "); else j = 0; printf("VOLUME_RESIZE_LOG_FILE"); } - if (i & VOLUME_IS_DIRTY) { + if (flags & VOLUME_IS_DIRTY) { if (j) printf(" | "); else From ec18534f318bf3f9f22d8cd3670cf1d3e612873d Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:21:05 +0100 Subject: [PATCH 15/20] ntfsck.c: Fix comparison between little-endian and native-endian data. This comparison would yield the wrong result on big-endian systems. --- ntfsprogs/ntfsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index fee0dc3a..c1087c7c 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -608,7 +608,7 @@ static BOOL check_file_record(u8 *buffer, u16 buflen) // We should know all the flags. - if (mft_rec->flags>0xf) { + if (le16_to_cpu(mft_rec->flags) > 0xf) { check_failed("Unknown MFT record flags (0x%x).\n", (unsigned int)le16_to_cpu(mft_rec->flags)); } From 55dafda73224cdf13fcee617e31e882e1c4827df Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:23:13 +0100 Subject: [PATCH 16/20] ntfsck.c: Fix comparing le32 values as u32. This is harmless except when we do strict endianness checking, in which case this results in a compile error. Fixed by converting values to CPU endianness before comparing them. --- ntfsprogs/ntfsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index c1087c7c..d49f3f96 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -584,7 +584,7 @@ static BOOL check_file_record(u8 *buffer, u16 buflen) ATTR_REC *attr_rec; // check record magic - assert_u32_equal(mft_rec->magic, magic_FILE, "FILE record magic"); + assert_u32_equal(le32_to_cpu(mft_rec->magic), le32_to_cpu(magic_FILE), "FILE record magic"); // todo: records 16-23 must be filled in order. // todo: what to do with magic_BAAD? From 0741f54b2ebab594dc58db6ca2bfb3c8f549e785 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:24:52 +0100 Subject: [PATCH 17/20] ntfsdump_logfile.c: Fix incorrectly parenthesized expression. On big-endian systems the result of the '!=' operation would be endian-swapped rather than the first argument (which must have been the intended action). --- ntfsprogs/ntfsdump_logfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 7fe22b3d..0d49aace 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -306,8 +306,8 @@ static void restart_header_sanity(RESTART_PAGE_HEADER *rstr, u8 *buf) "size. Cannot handle this yet.\n"); } /* Abort if the version number is not 1.1. */ - if (sle16_to_cpu(rstr->major_ver != 1) || - sle16_to_cpu(rstr->minor_ver != 1)) + if (sle16_to_cpu(rstr->major_ver) != 1 || + sle16_to_cpu(rstr->minor_ver) != 1) log_err_exit(buf, "Unknown $LogFile version %i.%i. Only know " "how to handle version 1.1.\n", sle16_to_cpu(rstr->major_ver), From 8daa92717e72a96ffc18e9cc228cadc24a5dd81b Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:26:51 +0100 Subject: [PATCH 18/20] ntfsdump_logfile.c: Fix use of wrong byteswapping macro for le16 field. --- ntfsprogs/ntfsdump_logfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 0d49aace..f300a5fc 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -633,7 +633,7 @@ rcrd_pass_loc: ntfs_log_info("page count = %i\n", le16_to_cpu(rcrd->page_count)); ntfs_log_info("page position = %i\n", le16_to_cpu(rcrd->page_position)); ntfs_log_info("header.next_record_offset = 0x%llx\n", (unsigned long long) - le64_to_cpu(rcrd->header.packed.next_record_offset)); + le16_to_cpu(rcrd->header.packed.next_record_offset)); ntfs_log_info("header.last_end_lsn = 0x%llx\n", (unsigned long long) sle64_to_cpu(rcrd->header.packed.last_end_lsn)); /* @@ -648,7 +648,7 @@ rcrd_pass_loc: client++; lr = (LOG_RECORD*)((u8*)lr + 0x70); } while (((u8*)lr + 0x70 <= (u8*)rcrd + - le64_to_cpu(rcrd->header.packed.next_record_offset))); + le16_to_cpu(rcrd->header.packed.next_record_offset))); pass++; goto rcrd_pass_loc; From 8aca3d4800488fd35d0204f394bab64c88f1abdd Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:28:55 +0100 Subject: [PATCH 19/20] ntfsmove.c: Fix multiple cases of raw usage of little-endian fields. There were multiple cases of little-endian fields being used as CPU-endian without byte swapping. This would result in incorrect behaviour on big-endian systems. --- ntfsprogs/ntfsmove.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ntfsprogs/ntfsmove.c b/ntfsprogs/ntfsmove.c index 0e11d48a..123041dd 100644 --- a/ntfsprogs/ntfsmove.c +++ b/ntfsprogs/ntfsmove.c @@ -319,10 +319,10 @@ static int resize_nonres_attr(MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size) int old_size; u8 *ptr; - old_size = a->length; - file_size = m->bytes_in_use; + old_size = le32_to_cpu(a->length); + file_size = le32_to_cpu(m->bytes_in_use); this_attr = p2n(a)-p2n(m); - next_attr = this_attr + a->length; + next_attr = this_attr + le32_to_cpu(a->length); tail_size = file_size - next_attr; ptr = (u8*) m; @@ -337,8 +337,8 @@ static int resize_nonres_attr(MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size) memmove(ptr + this_attr + new_size, ptr + next_attr, tail_size); - a->length = new_size; - m->bytes_in_use += new_size - old_size; + a->length = cpu_to_le32(new_size); + m->bytes_in_use = cpu_to_le32(le32_to_cpu(m->bytes_in_use) + (new_size - old_size)); return 0; } @@ -355,7 +355,7 @@ static int calc_attr_length(ATTR_RECORD *rec, int runlength) if (!rec->non_resident) return -1; - size = rec->mapping_pairs_offset + runlength + 7; + size = le16_to_cpu(rec->mapping_pairs_offset) + runlength + 7; size &= 0xFFF8; return size; } @@ -492,7 +492,7 @@ static int dont_move(ntfs_inode *ino) return 1; } - name = (FILE_NAME_ATTR*) ((u8*)rec + rec->value_offset); + name = (FILE_NAME_ATTR*) ((u8*)rec + le16_to_cpu(rec->value_offset)); if (ntfs_names_are_equal(ntldr, 5, name->file_name, name->file_name_length, IGNORE_CASE, ino->vol->upcase, ino->vol->upcase_len)) { ntfs_log_error("ntldr\n"); @@ -727,10 +727,10 @@ static s64 move_datarun(ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec, } // wipe orig runs - memset(((u8*)rec) +rec->mapping_pairs_offset, 0, need_to - rec->mapping_pairs_offset); + memset(((u8*)rec) + le16_to_cpu(rec->mapping_pairs_offset), 0, need_to - le16_to_cpu(rec->mapping_pairs_offset)); // update data runs - ntfs_mapping_pairs_build(vol, ((u8*)rec) + rec->mapping_pairs_offset, + ntfs_mapping_pairs_build(vol, ((u8*)rec) + le16_to_cpu(rec->mapping_pairs_offset), need_to, from, 0, NULL); // commit From e37258bf01737a6bb3c9872e380e0e0cd2aa68d0 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Thu, 28 Jan 2016 09:11:55 +0100 Subject: [PATCH 20/20] ntfscmp.c: Fix missing byteswap of little-endian attribute type value. --- ntfsprogs/ntfscmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 3ac73365..555e4017 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -722,7 +722,7 @@ static void vprint_attribute(ATTR_TYPES atype, char *name) if (!opt.verbose) return; - printf("0x%x", atype); + printf("0x%x", le32_to_cpu(atype)); if (name) printf(":%s", name); printf(" ");