diff --git a/include/ntfs/attrib.h b/include/ntfs/attrib.h index 5cbf8a0c..99665f31 100644 --- a/include/ntfs/attrib.h +++ b/include/ntfs/attrib.h @@ -2,7 +2,7 @@ * attrib.h - Exports for attribute handling. Part of the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov - * Copyright (c) 2004-2005 Yura Pakhuchiy + * Copyright (c) 2004-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -203,25 +203,25 @@ typedef enum { #define NAttrSetNonResident(na) set_nattr_flag(na, NonResident) #define NAttrClearNonResident(na) clear_nattr_flag(na, NonResident) -#define GenNAttrIno(func_name,flag) \ -static inline int NAttr##func_name(ntfs_attr *na) \ -{ \ - if (na->type == AT_DATA && na->name == AT_UNNAMED) \ - return (na->ni->flags & FILE_ATTR_##flag); \ - return 0; \ -} \ -static inline void NAttrSet##func_name(ntfs_attr *na) \ -{ \ - if (na->type == AT_DATA && na->name == AT_UNNAMED) \ - na->ni->flags |= FILE_ATTR_##flag; \ - else \ - ntfs_log_trace("BUG! Should be called only for "\ - "unnamed data attribute.\n"); \ -} \ -static inline void NAttrClear##func_name(ntfs_attr *na) \ -{ \ - if (na->type == AT_DATA && na->name == AT_UNNAMED) \ - na->ni->flags &= ~FILE_ATTR_##flag; \ +#define GenNAttrIno(func_name,flag) \ +static inline int NAttr##func_name(ntfs_attr *na) \ +{ \ + if (na->type == AT_DATA && na->name == AT_UNNAMED) \ + return (na->ni->flags & FILE_ATTR_##flag) ? 1 : 0; \ + return 0; \ +} \ +static inline void NAttrSet##func_name(ntfs_attr *na) \ +{ \ + if (na->type == AT_DATA && na->name == AT_UNNAMED) \ + na->ni->flags |= FILE_ATTR_##flag; \ + else \ + ntfs_log_trace("BUG! Should be called only for " \ + "unnamed data attribute.\n"); \ +} \ +static inline void NAttrClear##func_name(ntfs_attr *na) \ +{ \ + if (na->type == AT_DATA && na->name == AT_UNNAMED) \ + na->ni->flags &= ~FILE_ATTR_##flag; \ } GenNAttrIno(Compressed, COMPRESSED) diff --git a/include/ntfs/endians.h b/include/ntfs/endians.h index ec73c442..0b3dd762 100644 --- a/include/ntfs/endians.h +++ b/include/ntfs/endians.h @@ -3,6 +3,7 @@ * Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov + * Copyright (c) 2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -110,39 +111,42 @@ #if defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) -#define __le16_to_cpu(x) (x) -#define __le32_to_cpu(x) (x) -#define __le64_to_cpu(x) (x) +#define __le16_to_cpu(x) ((__force u16)(x)) +#define __le32_to_cpu(x) ((__force u32)(x)) +#define __le64_to_cpu(x) ((__force u64)(x)) -#define __cpu_to_le16(x) (x) -#define __cpu_to_le32(x) (x) -#define __cpu_to_le64(x) (x) +#define __cpu_to_le16(x) ((__force le16)(x)) +#define __cpu_to_le32(x) ((__force le32)(x)) +#define __cpu_to_le64(x) ((__force le64)(x)) -#define __constant_le16_to_cpu(x) (x) -#define __constant_le32_to_cpu(x) (x) -#define __constant_le64_to_cpu(x) (x) +#define __constant_le16_to_cpu(x) ((__force u16)(x)) +#define __constant_le32_to_cpu(x) ((__force u32)(x)) +#define __constant_le64_to_cpu(x) ((__force u64)(x)) -#define __constant_cpu_to_le16(x) (x) -#define __constant_cpu_to_le32(x) (x) -#define __constant_cpu_to_le64(x) (x) +#define __constant_cpu_to_le16(x) ((__force le16)(x)) +#define __constant_cpu_to_le32(x) ((__force le32)(x)) +#define __constant_cpu_to_le64(x) ((__force le64)(x)) #elif defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) -#define __le16_to_cpu(x) bswap_16(x) -#define __le32_to_cpu(x) bswap_32(x) -#define __le64_to_cpu(x) bswap_64(x) +#define __le16_to_cpu(x) bswap_16((__force u16)(x)) +#define __le32_to_cpu(x) bswap_32((__force u16)(x)) +#define __le64_to_cpu(x) bswap_64((__force u16)(x)) -#define __cpu_to_le16(x) bswap_16(x) -#define __cpu_to_le32(x) bswap_32(x) -#define __cpu_to_le64(x) bswap_64(x) +#define __cpu_to_le16(x) (__force le16)bswap_16((__force u16)(x)) +#define __cpu_to_le32(x) (__force le32)bswap_32((__force u32)(x)) +#define __cpu_to_le64(x) (__force le64)bswap_64((__force u64)(x)) -#define __constant_le16_to_cpu(x) __ntfs_bswap_constant_16((u16)(x)) -#define __constant_le32_to_cpu(x) __ntfs_bswap_constant_32((u32)(x)) -#define __constant_le64_to_cpu(x) __ntfs_bswap_constant_64((u64)(x)) +#define __constant_le16_to_cpu(x) __ntfs_bswap_constant_16((__force u16)(x)) +#define __constant_le32_to_cpu(x) __ntfs_bswap_constant_32((__force u32)(x)) +#define __constant_le64_to_cpu(x) __ntfs_bswap_constant_64((__force u64)(x)) -#define __constant_cpu_to_le16(x) __ntfs_bswap_constant_16((u16)(x)) -#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 __constant_cpu_to_le16(x) \ + (__force le16)__ntfs_bswap_constant_16((__force u16)(x)) +#define __constant_cpu_to_le32(x) \ + (__force le32)__ntfs_bswap_constant_32((__force u32)(x)) +#define __constant_cpu_to_le64(x) \ + (__force le64)__ntfs_bswap_constant_64((__force u64)(x)) #else @@ -152,52 +156,83 @@ /* Unsigned from LE to CPU conversion. */ -#define le16_to_cpu(x) (u16)__le16_to_cpu((u16)(x)) -#define le32_to_cpu(x) (u32)__le32_to_cpu((u32)(x)) -#define le64_to_cpu(x) (u64)__le64_to_cpu((u64)(x)) +#define le16_to_cpu(x) (u16)__le16_to_cpu((le16)(x)) +#define le32_to_cpu(x) (u32)__le32_to_cpu((le32)(x)) +#define le64_to_cpu(x) (u64)__le64_to_cpu((le64)(x)) -#define le16_to_cpup(x) (u16)__le16_to_cpu(*(const u16*)(x)) -#define le32_to_cpup(x) (u32)__le32_to_cpu(*(const u32*)(x)) -#define le64_to_cpup(x) (u64)__le64_to_cpu(*(const u64*)(x)) +#define le16_to_cpup(x) (u16)__le16_to_cpu(*(const le16*)(x)) +#define le32_to_cpup(x) (u32)__le32_to_cpu(*(const le32*)(x)) +#define le64_to_cpup(x) (u64)__le64_to_cpu(*(const le64*)(x)) /* Signed from LE to CPU conversion. */ -#define sle16_to_cpu(x) (s16)__le16_to_cpu((s16)(x)) -#define sle32_to_cpu(x) (s32)__le32_to_cpu((s32)(x)) -#define sle64_to_cpu(x) (s64)__le64_to_cpu((s64)(x)) +#define sle16_to_cpu(x) (s16)__le16_to_cpu((sle16)(x)) +#define sle32_to_cpu(x) (s32)__le32_to_cpu((sle32)(x)) +#define sle64_to_cpu(x) (s64)__le64_to_cpu((sle64)(x)) -#define sle16_to_cpup(x) (s16)__le16_to_cpu(*(s16*)(x)) -#define sle32_to_cpup(x) (s32)__le32_to_cpu(*(s32*)(x)) -#define sle64_to_cpup(x) (s64)__le64_to_cpu(*(s64*)(x)) +#define sle16_to_cpup(x) (s16)__le16_to_cpu(*(const sle16*)(x)) +#define sle32_to_cpup(x) (s32)__le32_to_cpu(*(const sle32*)(x)) +#define sle64_to_cpup(x) (s64)__le64_to_cpu(*(const sle64*)(x)) /* Unsigned from CPU to LE conversion. */ -#define cpu_to_le16(x) (u16)__cpu_to_le16((u16)(x)) -#define cpu_to_le32(x) (u32)__cpu_to_le32((u32)(x)) -#define cpu_to_le64(x) (u64)__cpu_to_le64((u64)(x)) +#define cpu_to_le16(x) (le16)__cpu_to_le16((u16)(x)) +#define cpu_to_le32(x) (le32)__cpu_to_le32((u32)(x)) +#define cpu_to_le64(x) (le64)__cpu_to_le64((u64)(x)) -#define cpu_to_le16p(x) (u16)__cpu_to_le16(*(u16*)(x)) -#define cpu_to_le32p(x) (u32)__cpu_to_le32(*(u32*)(x)) -#define cpu_to_le64p(x) (u64)__cpu_to_le64(*(u64*)(x)) +#define cpu_to_le16p(x) (le16)__cpu_to_le16(*(const u16*)(x)) +#define cpu_to_le32p(x) (le32)__cpu_to_le32(*(const u32*)(x)) +#define cpu_to_le64p(x) (le64)__cpu_to_le64(*(const u64*)(x)) /* Signed from CPU to LE conversion. */ -#define cpu_to_sle16(x) (s16)__cpu_to_le16((s16)(x)) -#define cpu_to_sle32(x) (s32)__cpu_to_le32((s32)(x)) -#define cpu_to_sle64(x) (s64)__cpu_to_le64((s64)(x)) +#define cpu_to_sle16(x) (__force sle16)__cpu_to_le16((s16)(x)) +#define cpu_to_sle32(x) (__force sle32)__cpu_to_le32((s32)(x)) +#define cpu_to_sle64(x) (__force sle64)__cpu_to_le64((s64)(x)) -#define cpu_to_sle16p(x) (s16)__cpu_to_le16(*(s16*)(x)) -#define cpu_to_sle32p(x) (s32)__cpu_to_le32(*(s32*)(x)) -#define cpu_to_sle64p(x) (s64)__cpu_to_le64(*(s64*)(x)) +#define cpu_to_sle16p(x) (__force sle16)__cpu_to_le16(*(const s16*)(x)) +#define cpu_to_sle32p(x) (__force sle32)__cpu_to_le32(*(const s32*)(x)) +#define cpu_to_sle64p(x) (__force sle64)__cpu_to_le64(*(const s64*)(x)) /* Constant endianness conversion defines. */ -#define const_le16_to_cpu(x) __constant_le16_to_cpu(x) -#define const_le32_to_cpu(x) __constant_le32_to_cpu(x) -#define const_le64_to_cpu(x) __constant_le64_to_cpu(x) +#define const_le16_to_cpu(x) (u16)__constant_le16_to_cpu((le16)(x)) +#define const_le32_to_cpu(x) (u32)__constant_le32_to_cpu((le32)(x)) +#define const_le64_to_cpu(x) (u64)__constant_le64_to_cpu((le64)(x)) -#define const_cpu_to_le16(x) __constant_cpu_to_le16(x) -#define const_cpu_to_le32(x) __constant_cpu_to_le32(x) -#define const_cpu_to_le64(x) __constant_cpu_to_le64(x) +#define const_cpu_to_le16(x) (le16)__constant_cpu_to_le16((u16)(x)) +#define const_cpu_to_le32(x) (le32)__constant_cpu_to_le32((u32)(x)) +#define const_cpu_to_le64(x) (le64)__constant_cpu_to_le64((u64)(x)) + +#ifdef __CHECKER__ +static void ntfs_endian_self_test(void) +{ + /* Should not generate warnings. */ + (le16)cpu_to_le16((u16)0); + (le32)cpu_to_le32((u32)0); + (le64)cpu_to_le64((u64)0); + (sle16)cpu_to_sle16((s16)0); + (sle32)cpu_to_sle32((s32)0); + (sle64)cpu_to_sle64((s64)0); + (u16)le16_to_cpu((__force le16)0); + (u32)le32_to_cpu((__force le32)0); + (u64)le64_to_cpu((__force le64)0); + (s16)sle16_to_cpu((__force sle16)0); + (s32)sle32_to_cpu((__force sle32)0); + (s64)sle64_to_cpu((__force sle64)0); + (le16)const_cpu_to_le16((u16)0); + (le32)const_cpu_to_le32((u32)0); + (le64)const_cpu_to_le64((u64)0); + (u16)const_le16_to_cpu((__force le16)0); + (u32)const_le32_to_cpu((__force le32)0); + (u64)const_le64_to_cpu((__force le64)0); + + /* + * TODO: Need some how to test that warnings are actually generated, + * but without flooding output with them and vice-versa print warning + * in case if some one warning is not triggered, but should. Any ideas? + */ +} +#endif #endif /* defined _NTFS_ENDIANS_H */ diff --git a/include/ntfs/inode.h b/include/ntfs/inode.h index a7b431e3..1da51a0d 100644 --- a/include/ntfs/inode.h +++ b/include/ntfs/inode.h @@ -2,7 +2,7 @@ * inode.h - Defines for NTFS inode handling. Part of the Linux-NTFS project. * * Copyright (c) 2001,2002 Anton Altaparmakov - * Copyright (c) 2004-2005 Yura Pakhuchiy + * Copyright (c) 2004-2007 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * * This program/include file is free software; you can redistribute it and/or @@ -155,7 +155,7 @@ extern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref); extern int ntfs_inode_close(ntfs_inode *ni); 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/layout.h b/include/ntfs/layout.h index 85cf8461..eb1c43ec 100644 --- a/include/ntfs/layout.h +++ b/include/ntfs/layout.h @@ -2,7 +2,7 @@ * layout.h - Ntfs on-disk layout structures. Part of the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov - * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2005-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -31,34 +31,34 @@ #define NTFS_SB_MAGIC const_cpu_to_le64(0x202020205346544eULL) /* - * Location of bootsector on partition: + * Location of boot sector on partition: * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition. * On NT4 and above there is one backup copy of the boot sector to * be found on the last sector of the partition (not normally accessible - * from within Windows as the bootsector contained number of sectors + * from within Windows as the boot sector contained number of sectors * value is one less than the actual value!). * On versions of NT 3.51 and earlier, the backup copy was located at * number of sectors/2 (integer divide), i.e. in the middle of the volume. */ /** - * struct BIOS_PARAMETER_BLOCK - BIOS parameter block (bpb) structure. + * 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; @@ -67,27 +67,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 boot sector magic. Always is 0xaa55 in little endian. */ /* sizeof() = 512 (0x200) bytes */ } __attribute__((__packed__)) NTFS_BOOT_SECTOR; @@ -129,8 +129,18 @@ typedef enum { * Generic magic comparison macros. Finally found a use for the ## preprocessor * operator! (-8 */ -#define ntfs_is_magic(x, m) ( (u32)(x) == (u32)magic_##m ) -#define ntfs_is_magicp(p, m) ( *(u32*)(p) == (u32)magic_##m ) + +static inline BOOL __ntfs_is_magic(le32 x, NTFS_RECORD_TYPES r) +{ + return (x == (__force le32)r); +} +#define ntfs_is_magic(x, m) __ntfs_is_magic(x, magic_##m) + +static inline BOOL __ntfs_is_magicp(le32 *p, NTFS_RECORD_TYPES r) +{ + return (*p == (__force le32)r); +} +#define ntfs_is_magicp(p, m) __ntfs_is_magicp(p, magic_##m) /* * Specialised magic comparison macros for the NTFS_RECORD_TYPES defined above. @@ -165,28 +175,28 @@ 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 + * 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 - including the Update Sequence Number (usn), + le16 usa_count; /* Number of u16 sized entries in the USA + including the Update Sequence Number (USN), thus the number of fixups is the usa_count minus 1. */ } __attribute__((__packed__)) NTFS_RECORD; @@ -215,7 +225,7 @@ typedef enum { FILE_AttrDef = 4, /* Array of attribute definitions in data attribute. */ FILE_root = 5, /* Root directory. */ - FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in + FILE_Bitmap = 6, /* Allocation bitmap of all clusters (LCNs) in data attribute. */ FILE_Boot = 7, /* Boot sector (always at cluster 0) in data attribute. */ @@ -229,7 +239,7 @@ typedef enum { characters in data attribute. */ FILE_Extend = 11, /* Directory containing other system files (eg. $ObjId, $Quota, $Reparse and $UsnJrnl). This - is new to NTFS3.0. */ + is new to NTFS 3.0. */ FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */ FILE_reserved13 = 13, FILE_reserved14 = 14, @@ -257,8 +267,8 @@ typedef enum { MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002), MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004), MFT_RECORD_IS_VIEW_INDEX = const_cpu_to_le16(0x0008), - MFT_REC_SPACE_FILLER = 0xffff, /* Just to make flags - 16-bit. */ + MFT_REC_SPACE_FILLER = const_cpu_to_le16(0xffff), + /* Just to make flags 16-bit. */ } __attribute__((__packed__)) MFT_RECORD_FLAGS; /* @@ -309,6 +319,7 @@ typedef enum { #define MFT_REF_MASK_LE const_cpu_to_le64(MFT_REF_MASK_CPU) typedef u64 MFT_REF; +typedef le64 leMFT_REF; #define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \ ((MFT_REF)(m) & MFT_REF_MASK_CPU))) @@ -337,17 +348,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 @@ -357,18 +368,18 @@ 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 @@ -380,7 +391,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 @@ -388,8 +399,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 @@ -411,17 +422,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 @@ -431,15 +442,15 @@ 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. @@ -454,7 +465,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 @@ -520,28 +531,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 @@ -614,12 +625,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; @@ -719,14 +730,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 @@ -736,15 +747,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 @@ -760,21 +771,21 @@ 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). + VCNs and the logical cluster numbers (LCNs). When creating, place this at the end of this record header aligned to 8-byte boundary. */ /* 34*/ u8 compression_unit; /* The compression unit expressed @@ -786,7 +797,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 @@ -794,10 +805,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, @@ -805,7 +816,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 @@ -831,7 +842,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 valid. Unused in NT. = cpu_to_le32(0x00000008), */ FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010), /* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved @@ -905,13 +916,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 @@ -949,29 +960,29 @@ 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. + change (aka USN) journal file. It is zero if + the USN journal is disabled. NOTE: To disable the journal need to delete the journal file itself and to then walk the - whole mft and set all Usn entries in all mft + whole mft and set all USN entries in all mft records to zero! (This can take a while!) The journal is FILE_Extend/$UsnJrnl. Win2k will recreate the journal and initiate @@ -1017,13 +1028,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 @@ -1035,10 +1046,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 @@ -1093,16 +1104,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 @@ -1111,17 +1122,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,11 +1159,11 @@ typedef struct { */ typedef union { struct { - u32 data1; /* The first eight hexadecimal digits of the + le32 data1; /* The first eight hexadecimal digits of the GUID. */ - u16 data2; /* The first group of four hexadecimal + le16 data2; /* The first group of four hexadecimal digits. */ - u16 data3; /* The second group of four hexadecimal + 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 @@ -1175,7 +1186,7 @@ typedef union { * domain_id - Reserved (always zero). */ typedef struct { - MFT_REF mft_reference; /* Mft record containing the object_id in + leMFT_REF mft_reference;/* Mft record containing the object_id in the index entry key. */ union { struct { @@ -1331,7 +1342,7 @@ typedef enum { /* Identifier authority. */ * NT_AUTHORITY_SID S-1-5 * DIALUP_SID S-1-5-1 * - * NETWORD_SID S-1-5-2 + * NETWORK_SID S-1-5-2 * BATCH_SID S-1-5-3 * INTERACTIVE_SID S-1-5-4 * SERVICE_SID S-1-5-6 @@ -1357,8 +1368,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; @@ -1395,7 +1406,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; /** @@ -1476,7 +1487,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; /** @@ -1642,7 +1653,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. */ @@ -1664,7 +1675,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. */ @@ -1687,10 +1698,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; @@ -1788,17 +1799,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. */ @@ -1909,21 +1920,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; @@ -1948,10 +1959,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; @@ -1962,7 +1973,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; /** @@ -1972,8 +1983,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; /** @@ -2013,7 +2024,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. */ @@ -2064,12 +2075,12 @@ typedef enum { * start of the index root or index allocation structures themselves. */ typedef struct { - u32 entries_offset; /* Byte offset to first INDEX_ENTRY + le32 entries_offset; /* Byte offset to first INDEX_ENTRY aligned to 8-byte boundary. */ - u32 index_length; /* Data size of the index in bytes, + le32 index_length; /* Data size of the index in bytes, i.e. bytes used from allocated size, aligned to 8-byte boundary. */ - u32 allocated_size; /* Byte size of this index (block), + le32 allocated_size; /* Byte size of this index (block), multiple of 8 bytes. */ /* NOTE: For the index root attribute, the above two numbers are always equal, as the attribute is resident and it is resized as needed. In @@ -2095,7 +2106,7 @@ typedef struct { * large to fit in the index root, on the other hand, two additional attributes * are present: an index allocation attribute, containing sub-nodes of the B+ * directory tree (see below), and a bitmap attribute, describing which virtual - * cluster numbers (vcns) in the index allocation attribute are in use by an + * cluster numbers (VCNs) in the index allocation attribute are in use by an * index block. * * NOTE: The root directory (FILE_root) contains an entry for itself. Other @@ -2109,7 +2120,7 @@ typedef struct { COLLATION_RULES collation_rule; /* Collation rule used to sort the index entries. If type is $FILE_NAME, this must be COLLATION_FILE_NAME. */ - u32 index_block_size; /* Size of each index block in bytes (in + le32 index_block_size; /* Size of each index block in bytes (in the index allocation attribute). */ u8 clusters_per_index_block; /* Cluster size of each index block (in the index allocation attribute), when @@ -2132,12 +2143,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 */ /* @@ -2165,8 +2176,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; @@ -2218,19 +2229,19 @@ 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 then the INDEX_ENTRY is padded with zeros to multiply of 8 which are not counted in - the data_length field. If the sid is present + the data_length field. If the SID is present then this structure is padded with zeros to multiply of 8 and the padding is counted in the INDEX_ENTRY's data_length. */ @@ -2240,8 +2251,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; @@ -2267,7 +2278,8 @@ typedef enum { entry in an index block. The index entry does not represent a file but it can point to a sub-node. */ - INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */ + INDEX_ENTRY_SPACE_FILLER = const_cpu_to_le16(0xffff), + /* Just to force 16-bit width. */ } __attribute__((__packed__)) INDEX_ENTRY_FLAGS; /** @@ -2275,25 +2287,25 @@ typedef enum { */ typedef struct { /* 0*/ 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. */ -/* 10*/ u16 key_length; /* Byte size of the key value, which is in the +/* 10*/ le16 key_length; /* Byte size of the key value, which is in the index entry. It follows field reserved. Not multiple of 8-bytes. */ /* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ -/* 14*/ u16 reserved; /* Reserved/align to 8-byte boundary. */ +/* 14*/ le16 reserved; /* Reserved/align to 8-byte boundary. */ /* sizeof() = 16 bytes */ } __attribute__((__packed__)) INDEX_ENTRY_HEADER; @@ -2309,25 +2321,25 @@ 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__)); - u16 length; /* Byte size of this index entry, multiple of + le16 length; /* Byte size of this index entry, multiple of 8-bytes. */ - u16 key_length; /* Byte size of the key value, which is in the + le16 key_length; /* Byte size of the key value, which is in the index entry. It follows field reserved. Not multiple of 8-bytes. */ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ - u16 reserved; /* Reserved/align to 8-byte boundary. */ + le16 reserved; /* Reserved/align to 8-byte boundary. */ /* 16*/ union { /* The key of the indexed attribute. NOTE: Only present if INDEX_ENTRY_END bit in flags is not set. NOTE: On @@ -2344,7 +2356,7 @@ 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. */ @@ -2427,9 +2439,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; @@ -2439,11 +2451,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 @@ -2470,11 +2482,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. */ @@ -2538,10 +2550,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 @@ -2549,20 +2561,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; @@ -2570,25 +2582,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. @@ -2596,28 +2608,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; @@ -2628,16 +2640,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.) */ @@ -2659,8 +2671,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/logfile.h b/include/ntfs/logfile.h index 8aadc8c1..b35b5ecf 100644 --- a/include/ntfs/logfile.h +++ b/include/ntfs/logfile.h @@ -2,6 +2,7 @@ * logfile.h - Exports for $LogFile handling. Part of the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov + * Copyright (c) 2005-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -110,7 +111,8 @@ typedef struct { */ enum { RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002), - RESTART_SPACE_FILLER = 0xffff, /* gcc: Force enum bit width to 16. */ + RESTART_SPACE_FILLER = const_cpu_to_le16(0xffff), + /* gcc: Force enum bit width to 16. */ } __attribute__((__packed__)); typedef le16 RESTART_AREA_FLAGS; diff --git a/include/ntfs/ntfstime.h b/include/ntfs/ntfstime.h index e0d1ae20..2fb85a54 100644 --- a/include/ntfs/ntfstime.h +++ b/include/ntfs/ntfstime.h @@ -1,8 +1,8 @@ /* * ntfstime.h - NTFS time related functions. Part of the Linux-NTFS project. * - * Copyright (c) 2005 Anton Altaparmakov - * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2005 Anton Altaparmakov + * Copyright (c) 2005-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -40,7 +40,7 @@ * * Return: n A Unix time (number of seconds since 1970) */ -static __inline__ time_t ntfs2utc(s64 ntfs_time) +static __inline__ time_t ntfs2utc(sle64 ntfs_time) { return (sle64_to_cpu(ntfs_time) - (NTFS_TIME_OFFSET)) / 10000000; } @@ -60,7 +60,7 @@ static __inline__ time_t ntfs2utc(s64 ntfs_time) * * Return: n An NTFS time (100ns units since Jan 1601) */ -static __inline__ s64 utc2ntfs(time_t utc_time) +static __inline__ sle64 utc2ntfs(time_t utc_time) { /* Convert to 100ns intervals and then add the NTFS time offset. */ return cpu_to_sle64((s64)utc_time * 10000000 + NTFS_TIME_OFFSET); diff --git a/include/ntfs/types.h b/include/ntfs/types.h index ea156b27..bb0e654b 100644 --- a/include/ntfs/types.h +++ b/include/ntfs/types.h @@ -4,6 +4,7 @@ * * Copyright (c) 2000-2004 Anton Altaparmakov * Copyright (c) 2006 Szabolcs Szakacsits + * Copyright (c) 2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -47,8 +48,10 @@ typedef int64_t s64; #ifdef __CHECKER__ #define __bitwise __attribute__((bitwise)) +#define __force __attribute__((force)) #else #define __bitwise +#define __force #endif typedef u16 __bitwise le16; @@ -63,7 +66,11 @@ typedef u16 __bitwise sle16; typedef u32 __bitwise sle32; typedef u64 __bitwise sle64; -typedef u16 ntfschar; /* 2-byte Unicode character type. */ +typedef u16 __bitwise be16; +typedef u32 __bitwise be32; +typedef u64 __bitwise be64; + +typedef le16 ntfschar; /* 2-byte Unicode character type. */ #define UCHAR_T_SIZE_BITS 1 /* diff --git a/include/ntfs/volume.h b/include/ntfs/volume.h index 61915d07..e5f97c93 100644 --- a/include/ntfs/volume.h +++ b/include/ntfs/volume.h @@ -2,7 +2,7 @@ * volume.h - Exports for NTFS volume handling. Part of the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov - * Copyright (c) 2005-2006 Yura Pakhuchiy + * Copyright (c) 2005-2007 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * * This program/include file is free software; you can redistribute it and/or @@ -151,7 +151,7 @@ struct _ntfs_volume { ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */ u8 major_ver; /* Ntfs major version of volume. */ u8 minor_ver; /* Ntfs minor version of volume. */ - u16 flags; /* Bit array of VOLUME_* flags. */ + le16 flags; /* Bit array of VOLUME_* flags. */ GUID guid; /* The volume guid if present (otherwise it is a NULL guid). */ @@ -234,6 +234,6 @@ extern int ntfs_umount(ntfs_volume *vol, const BOOL force); extern int ntfs_version_is_supported(ntfs_volume *vol); extern int ntfs_logfile_reset(ntfs_volume *vol); -extern int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags); +extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags); #endif /* defined _NTFS_VOLUME_H */ diff --git a/libntfs/attrib.c b/libntfs/attrib.c index 41e40b8c..9e91b3e4 100644 --- a/libntfs/attrib.c +++ b/libntfs/attrib.c @@ -4,7 +4,7 @@ * Copyright (c) 2000-2006 Anton Altaparmakov * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2002-2006 Szabolcs Szakacsits - * Copyright (c) 2004-2006 Yura Pakhuchiy + * Copyright (c) 2004-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -393,7 +393,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, */ if (type == AT_ATTRIBUTE_LIST) a->flags = 0; - cs = a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE); + cs = (a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? 1 : 0; if (!name) { if (a->name_length) { name = ntfs_ucsndup((ntfschar*)((u8*)a + le16_to_cpu( @@ -410,9 +410,9 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, } __ntfs_attr_init(na, ni, type, name, name_len); if (a->non_resident) { - ntfs_attr_init(na, TRUE, a->flags & ATTR_IS_COMPRESSED, - a->flags & ATTR_IS_ENCRYPTED, - a->flags & ATTR_IS_SPARSE, + ntfs_attr_init(na, TRUE, (a->flags & ATTR_IS_COMPRESSED)? 1 : 0, + (a->flags & ATTR_IS_ENCRYPTED) ? 1 : 0, + (a->flags & ATTR_IS_SPARSE) ? 1 : 0, sle64_to_cpu(a->allocated_size), sle64_to_cpu(a->data_size), sle64_to_cpu(a->initialized_size), @@ -420,10 +420,10 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, cs ? a->compression_unit : 0); } else { s64 l = le32_to_cpu(a->value_length); - ntfs_attr_init(na, FALSE, a->flags & ATTR_IS_COMPRESSED, - a->flags & ATTR_IS_ENCRYPTED, - a->flags & ATTR_IS_SPARSE, (l + 7) & ~7, l, l, - cs ? (l + 7) & ~7 : 0, 0); + ntfs_attr_init(na, FALSE, (a->flags & ATTR_IS_COMPRESSED) ? 1:0, + (a->flags & ATTR_IS_ENCRYPTED) ? 1 : 0, + (a->flags & ATTR_IS_SPARSE) ? 1 : 0, + (l + 7) & ~7, l, l, cs ? (l + 7) & ~7 : 0, 0); } ntfs_attr_put_search_ctx(ctx); return na; @@ -2622,7 +2622,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) flags); + (long long) ni->mft_no, le32_to_cpu(type), le16_to_cpu(flags)); if (!ni || (!name && name_len)) { errno = EINVAL; @@ -2746,9 +2746,9 @@ 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) ni->mft_no, le32_to_cpu(type), (long long) lowest_vcn, dataruns_size, - (unsigned) flags); + le16_to_cpu(flags)); if (!ni || dataruns_size <= 0 || (!name && name_len)) { errno = EINVAL; @@ -3226,7 +3226,7 @@ rm_attr_err_out: free_err_out: /* Free MFT record, if it isn't contain attributes. */ if (le32_to_cpu(attr_ni->mrec->bytes_in_use) - - le32_to_cpu(attr_ni->mrec->attrs_offset) == 8) { + le16_to_cpu(attr_ni->mrec->attrs_offset) == 8) { if (ntfs_mft_record_free(attr_ni->vol, attr_ni)) { ntfs_log_trace("Failed to free MFT record. Leaving " "inconsistent metadata.\n"); diff --git a/libntfs/attrlist.c b/libntfs/attrlist.c index f09d4b42..ce171bf9 100644 --- a/libntfs/attrlist.c +++ b/libntfs/attrlist.c @@ -3,7 +3,7 @@ * project. * * Copyright (c) 2004-2005 Anton Altaparmakov - * Copyright (c) 2004-2005 Yura Pakhuchiy + * Copyright (c) 2004-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -105,7 +105,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; @@ -152,7 +152,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)) { @@ -264,10 +264,10 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) base_ni = ctx->ntfs_ino; ale = ctx->al_entry; - ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld.\n", - (long long) ctx->ntfs_ino->mft_no, + 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/dir.c b/libntfs/dir.c index a08fa48f..33684181 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -2,7 +2,7 @@ * dir.c - Directory handling code. Part of the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov - * Copyright (c) 2005-2006 Yura Pakhuchiy + * Copyright (c) 2005-2007 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * * This program/include file is free software; you can redistribute it and/or diff --git a/libntfs/index.c b/libntfs/index.c index 472254db..4d1300c4 100644 --- a/libntfs/index.c +++ b/libntfs/index.c @@ -3,7 +3,7 @@ * * Copyright (c) 2004-2005 Anton Altaparmakov * Copyright (c) 2004-2005 Richard Russon - * Copyright (c) 2005-2006 Yura Pakhuchiy + * Copyright (c) 2005-2007 Yura Pakhuchiy * Copyright (c) 2005-2006 Szabolcs Szakacsits * * This program/include file is free software; you can redistribute it and/or @@ -193,9 +193,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(VCN)); } /** @@ -224,7 +224,7 @@ static u8 *ntfs_ie_get_end(INDEX_HEADER *ih) static int ntfs_ie_end(INDEX_ENTRY *ie) { - return ie->flags & INDEX_ENTRY_END; + return (ie->flags & INDEX_ENTRY_END) ? 1 : 0; } /** @@ -344,7 +344,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); } /** @@ -811,8 +811,8 @@ static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size, ib->usa_ofs = 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); + *(le16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = cpu_to_le16(1); + ib->lsn = 0; ib->index_block_vcn = cpu_to_sle64(ib_vcn); diff --git a/libntfs/inode.c b/libntfs/inode.c index a82ebdc0..20518ece 100644 --- a/libntfs/inode.c +++ b/libntfs/inode.c @@ -2,7 +2,7 @@ * inode.c - Inode handling code. Part of the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov - * Copyright (c) 2004-2005 Yura Pakhuchiy + * Copyright (c) 2004-2007 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * * This program/include file is free software; you can redistribute it and/or @@ -343,7 +343,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); ntfs_inode *ni; @@ -453,8 +453,7 @@ int ntfs_inode_attach_all_extents(ntfs_inode *ni) while ((u8*)ale < ni->attr_list + ni->attr_list_size) { if (ni->mft_no != MREF_LE(ale->mft_reference) && prev_attached != MREF_LE(ale->mft_reference)) { - if (!ntfs_extent_inode_open(ni, - MREF_LE(ale->mft_reference))) { + if (!ntfs_extent_inode_open(ni, ale->mft_reference)) { ntfs_log_trace("Couldn't attach extent " "inode (attr type 0x%x " "references to it).\n", @@ -1143,8 +1142,8 @@ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr) } if (ustr && ntfs_names_are_equal(ustr, len, - (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)), - attr->name_length, 0, NULL, 0)) + (ntfschar *)((u8 *)attr + le16_to_cpu( + attr->name_offset)), attr->name_length, 0, NULL, 0)) ret = 1; ntfs_ucsfree(ustr); diff --git a/libntfs/mft.c b/libntfs/mft.c index 6ba963a6..caf491fb 100644 --- a/libntfs/mft.c +++ b/libntfs/mft.c @@ -2,7 +2,7 @@ * mft.c - Mft record handling code. Part of the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov - * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2005-2007 Yura Pakhuchiy * Copyright (c) 2004-2005 Richard Russon * * This program/include file is free software; you can redistribute it and/or @@ -323,7 +323,7 @@ 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); + *(le16*)((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); @@ -1191,7 +1191,7 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) ATTR_RECORD *a; ntfs_inode *ni; int err; - u16 seq_no, usn; + le16 seq_no, usn; if (base_ni) ntfs_log_trace("Entering (allocating an extent mft record for " @@ -1389,7 +1389,7 @@ mft_rec_already_initialized: goto undo_mftbmp_alloc; } seq_no = m->sequence_number; - usn = *(u16*)((u8*)m + le16_to_cpu(m->usa_ofs)); + usn = *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)); if (ntfs_mft_record_layout(vol, bit, m)) { err = errno; ntfs_log_error("Failed to re-format mft record.\n"); @@ -1397,11 +1397,10 @@ mft_rec_already_initialized: errno = err; goto undo_mftbmp_alloc; } - if (le16_to_cpu(seq_no)) + if (seq_no) m->sequence_number = seq_no; - seq_no = le16_to_cpu(usn); - if (seq_no && seq_no != 0xffff) - *(u16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn; + if (usn && le16_to_cpu(usn) != 0xffff) + *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn; /* Set the mft record itself in use. */ m->flags |= MFT_RECORD_IN_USE; /* Now need to open an ntfs inode for the mft record. */ @@ -1495,7 +1494,8 @@ int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni) { u64 mft_no; int err; - u16 seq_no, old_seq_no; + u16 seq_no; + le16 old_seq_no; ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); @@ -1560,13 +1560,14 @@ sync_rollback: */ int ntfs_mft_usn_dec(MFT_RECORD *mrec) { - u16 usn, *usnp; + u16 usn; + le16 *usnp; if (!mrec) { errno = EINVAL; return -1; } - usnp = (u16 *)((char *)mrec + le16_to_cpu(mrec->usa_ofs)); + usnp = (le16 *)((char *)mrec + le16_to_cpu(mrec->usa_ofs)); usn = le16_to_cpup(usnp); if (usn-- <= 1) usn = 0xfffe; diff --git a/libntfs/mst.c b/libntfs/mst.c index 140700ea..e9ca83b9 100644 --- a/libntfs/mst.c +++ b/libntfs/mst.c @@ -2,6 +2,7 @@ * mst.c - Multi sector fixup handling code. Part of the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov + * Copyright (c) 2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -130,7 +131,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, usnle; /* Sanity check + only fixup if it makes sense. */ if (!b || ntfs_is_baad_record(b->magic) || @@ -150,7 +151,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). @@ -158,10 +159,10 @@ 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; + usnle = cpu_to_le16(usn); + *usa_pos = usnle; /* Position in data of first u16 that needs fixing up. */ - data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; + data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; /* Fixup all sectors. */ while (usa_count--) { /* @@ -170,7 +171,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 = usnle; /* Increment position in data as well. */ data_pos += NTFS_BLOCK_SIZE/sizeof(u16); } diff --git a/libntfs/runlist.c b/libntfs/runlist.c index b729804c..e0170b6b 100644 --- a/libntfs/runlist.c +++ b/libntfs/runlist.c @@ -4,7 +4,7 @@ * Copyright (c) 2002-2005 Anton Altaparmakov * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2002-2006 Szabolcs Szakacsits - * Copyright (c) 2004 Yura Pakhuchiy + * Copyright (c) 2004-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published diff --git a/libntfs/unistr.c b/libntfs/unistr.c index 53de09e8..bbeb6ccf 100644 --- a/libntfs/unistr.c +++ b/libntfs/unistr.c @@ -2,6 +2,7 @@ * unistr.c - Unicode string handling. Part of the Linux-NTFS project. * * Copyright (c) 2000-2006 Anton Altaparmakov + * Copyright (c) 2005-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -130,7 +131,7 @@ int ntfs_names_collate(const ntfschar *name1, const u32 name1_len, const u32 upcase_len) { u32 cnt; - ntfschar c1, c2; + u16 c1, c2; #ifdef DEBUG if (!name1 || !name2 || (ic && (!upcase || !upcase_len))) { @@ -187,7 +188,7 @@ int ntfs_names_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 @@ -230,7 +231,7 @@ int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n) int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n, const ntfschar *upcase, const u32 upcase_size) { - ntfschar c1, c2; + u16 c1, c2; size_t i; #ifdef DEBUG @@ -323,7 +324,7 @@ void ntfs_name_upcase(ntfschar *name, u32 name_len, const ntfschar *upcase, const u32 upcase_len) { u32 i; - ntfschar u; + u16 u; for (i = 0; i < name_len; i++) if ((u = le16_to_cpu(name[i])) < upcase_len) diff --git a/libntfs/volume.c b/libntfs/volume.c index bc658b40..225e2ee4 100644 --- a/libntfs/volume.c +++ b/libntfs/volume.c @@ -4,7 +4,7 @@ * Copyright (c) 2000-2006 Anton Altaparmakov * Copyright (c) 2002-2006 Szabolcs Szakacsits * Copyright (c) 2004-2005 Richard Russon - * Copyright (c) 2005-2006 Yura Pakhuchiy + * Copyright (c) 2005-2007 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -849,14 +849,14 @@ 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_record(mrec->magic)) { ntfs_log_debug("FAILED\n"); ntfs_log_debug("$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_record(mrec->magic)) { ntfs_log_debug("FAILED\n"); ntfs_log_debug("$MFT error: Invalid mft " "record for %s.\n", s); @@ -865,14 +865,14 @@ 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_record(mrec2->magic)) { ntfs_log_debug("FAILED\n"); ntfs_log_debug("$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_record(mrec2->magic)) { ntfs_log_debug("FAILED\n"); ntfs_log_debug("$MFTMirr error: Invalid mft " "record for %s.\n", s); @@ -1076,12 +1076,12 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags) goto error_exit; } for (j = 0; j < (s32)u; j++) { - ntfschar uc = le16_to_cpu(vname[j]); + u16 uc = le16_to_cpu(vname[j]); if (uc > 0xff) - uc = (ntfschar)'_'; + uc = (u16)'_'; vol->vol_name[j] = (char)uc; } - vol->vol_name[u] = '\0'; + vol->vol_name[u] = 0; } } ntfs_log_debug(OK); @@ -1506,7 +1506,7 @@ error_exit: * * Return 0 if successful and -1 if not with errno set to the error code. */ -int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags) +int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags) { ATTR_RECORD *a; VOLUME_INFORMATION *c; diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index b6c4fe47..3ba6d439 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -5,6 +5,7 @@ * Copyright (c) 2001-2005 Richard Russon * Copyright (c) 2002-2006 Szabolcs Szakacsits * Copyright (c) 2005 Erik Sornes + * Copyright (c) 2007 Yura Pakhuchiy * * This utility will create an NTFS 1.2 or 3.1 volume on a user * specified (block) device. @@ -209,35 +210,35 @@ static void mkntfs_license(void) static void mkntfs_usage(void) { ntfs_log_info("\nUsage: %s [options] device [number-of-sectors]\n" - "\n" - "Basic options:\n" - " -f, --fast Perform a quick format\n" - " -Q, --quick Perform a quick format\n" - " -L, --label STRING Set the volume label\n" - " -C, --enable-compression Enable compression on the volume\n" - " -I, --no-indexing Disable indexing on the volume\n" - " -n, --no-action Do not write to disk\n" - "\n" - "Advanced options:\n" - " -c, --cluster-size BYTES Specify the cluster size for the volume\n" - " -s, --sector-size BYTES Specify the sector size for the device\n" - " -p, --partition-start SECTOR Specify the partition start sector\n" - " -H, --heads NUM Specify the number of heads\n" - " -S, --sectors-per-track NUM Specify the number of sectors per track\n" - " -z, --mft-zone-multiplier NUM Set the MFT zone multiplier\n" - " -T, --zero-time Fake the time to be 00:00 UTC, Jan 1, 1970\n" - " -F, --force Force execution despite errors\n" - "\n" - "Output options:\n" - " -q, --quiet Quiet execution\n" - " -v, --verbose Verbose execution\n" - " --debug Very verbose execution\n" - "\n" - "Help options:\n" - " -V, --version Display version\n" - " -l, --license Display licensing information\n" - " -h, --help Display this help\n" - "\n", basename(EXEC_NAME)); +"\n" +"Basic options:\n" +" -f, --fast Perform a quick format\n" +" -Q, --quick Perform a quick format\n" +" -L, --label STRING Set the volume label\n" +" -C, --enable-compression Enable compression on the volume\n" +" -I, --no-indexing Disable indexing on the volume\n" +" -n, --no-action Do not write to disk\n" +"\n" +"Advanced options:\n" +" -c, --cluster-size BYTES Specify the cluster size for the volume\n" +" -s, --sector-size BYTES Specify the sector size for the device\n" +" -p, --partition-start SECTOR Specify the partition start sector\n" +" -H, --heads NUM Specify the number of heads\n" +" -S, --sectors-per-track NUM Specify the number of sectors per track\n" +" -z, --mft-zone-multiplier NUM Set the MFT zone multiplier\n" +" -T, --zero-time Fake the time to be 00:00 UTC, Jan 1, 1970\n" +" -F, --force Force execution despite errors\n" +"\n" +"Output options:\n" +" -q, --quiet Quiet execution\n" +" -v, --verbose Verbose execution\n" +" --debug Very verbose execution\n" +"\n" +"Help options:\n" +" -V, --version Display version\n" +" -l, --license Display licensing information\n" +" -h, --help Display this help\n" +"\n", basename(EXEC_NAME)); ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home); } @@ -246,12 +247,15 @@ static void mkntfs_usage(void) */ static void mkntfs_version(void) { - ntfs_log_info("\n%s v%s (libntfs %s)\n\n", EXEC_NAME, VERSION, ntfs_libntfs_version()); - ntfs_log_info("Create an NTFS volume on a user specified (block) device.\n\n"); + ntfs_log_info("\n%s v%s (libntfs %s)\n\n", EXEC_NAME, VERSION, + ntfs_libntfs_version()); + ntfs_log_info("Create an NTFS volume on a user specified (block) " + "device.\n\n"); ntfs_log_info("Copyright (c) 2000-2007 Anton Altaparmakov\n"); ntfs_log_info("Copyright (c) 2001-2005 Richard Russon\n"); ntfs_log_info("Copyright (c) 2002-2006 Szabolcs Szakacsits\n"); ntfs_log_info("Copyright (c) 2005 Erik Sornes\n"); + ntfs_log_info("Copyright (c) 2007 Yura Pakhuchiy\n"); ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); } @@ -285,7 +289,8 @@ static BOOL mkntfs_parse_long(const char *string, const char *name, long *num) /** * mkntfs_parse_llong */ -static BOOL mkntfs_parse_llong(const char *string, const char *name, long long *num) +static BOOL mkntfs_parse_llong(const char *string, const char *name, + long long *num) { char *end = NULL; long long tmp; @@ -300,7 +305,8 @@ static BOOL mkntfs_parse_llong(const char *string, const char *name, long long * tmp = strtoll(string, &end, 0); if (end && *end) { - ntfs_log_error("Cannot understand the %s '%s'.\n", name, string); + ntfs_log_error("Cannot understand the %s '%s'.\n", name, + string); return FALSE; } else { *num = tmp; @@ -364,7 +370,8 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options * int ver = 0; if (!argv || !opts2) { - ntfs_log_error("Internal error: invalid parameters to mkntfs_options.\n"); + ntfs_log_error("Internal error: invalid parameters to " + "mkntfs_options.\n"); return FALSE; } @@ -374,15 +381,18 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options * switch (c) { case 1: /* A device, or a number of sectors */ if (!opts2->dev_name) - opts2->dev_name = argv[optind-1]; - else if (!mkntfs_parse_llong(optarg, "number of sectors", &opts2->num_sectors)) + opts2->dev_name = argv[optind - 1]; + else if (!mkntfs_parse_llong(optarg, + "number of sectors", + &opts2->num_sectors)) err++; break; case 'C': opts2->enable_compression = TRUE; break; case 'c': - if (!mkntfs_parse_long(optarg, "cluster size", &opts2->cluster_size)) + if (!mkntfs_parse_long(optarg, "cluster size", + &opts2->cluster_size)) err++; break; case 'F': @@ -406,7 +416,8 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options * if (!opts2->label) { opts2->label = argv[optind-1]; } else { - ntfs_log_error("You may only specify the label once.\n"); + ntfs_log_error("You may only specify the label " + "once.\n"); err++; } break; @@ -417,34 +428,45 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options * opts2->no_action = TRUE; break; case 'p': - if (!mkntfs_parse_llong(optarg, "partition start", &opts2->part_start_sect)) + if (!mkntfs_parse_llong(optarg, "partition start", + &opts2->part_start_sect)) err++; break; case 'q': - ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_VERBOSE | NTFS_LOG_LEVEL_PROGRESS); + ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET | + NTFS_LOG_LEVEL_VERBOSE | + NTFS_LOG_LEVEL_PROGRESS); break; case 's': - if (!mkntfs_parse_long(optarg, "sector size", &opts2->sector_size)) + if (!mkntfs_parse_long(optarg, "sector size", + &opts2->sector_size)) err++; break; case 'S': - if (!mkntfs_parse_long(optarg, "sectors per track", &opts2->sectors_per_track)) + if (!mkntfs_parse_long(optarg, "sectors per track", + &opts2->sectors_per_track)) err++; break; case 'T': opts2->use_epoch_time = TRUE; break; case 'v': - ntfs_log_set_levels(NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_VERBOSE | NTFS_LOG_LEVEL_PROGRESS); + ntfs_log_set_levels(NTFS_LOG_LEVEL_QUIET | + NTFS_LOG_LEVEL_VERBOSE | + NTFS_LOG_LEVEL_PROGRESS); break; case 'V': ver++; /* display version info */ break; case 'Z': /* debug - turn on everything */ - ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG | NTFS_LOG_LEVEL_TRACE | NTFS_LOG_LEVEL_VERBOSE | NTFS_LOG_LEVEL_QUIET); + ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG | + NTFS_LOG_LEVEL_TRACE | + NTFS_LOG_LEVEL_VERBOSE | + NTFS_LOG_LEVEL_QUIET); break; case 'z': - if (!mkntfs_parse_long(optarg, "mft zone multiplier", &opts2->mft_zone_multiplier)) + if (!mkntfs_parse_long(optarg, "mft zone multiplier", + &opts2->mft_zone_multiplier)) err++; break; default: @@ -455,9 +477,11 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options * (optopt == 's') || (optopt == 'S') || (optopt == 'N') || (optopt == 'z')) && (!optarg)) { - ntfs_log_error("Option '%s' requires an argument.\n", argv[optind-1]); + ntfs_log_error("Option '%s' requires an " + "argument.\n", argv[optind-1]); } else if (optopt != '?') { - ntfs_log_error("Unknown option '%s'.\n", argv[optind-1]); + ntfs_log_error("Unknown option '%s'.\n", + argv[optind - 1]); } err++; break; @@ -1137,8 +1161,8 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, err = -EOPNOTSUPP; goto err_out; } - if (flags & (ATTR_IS_ENCRYPTED || ATTR_IS_SPARSE)) { - ntfs_log_error("Encrypted/sparse attributes not supported yet.\n"); + if (flags & (ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) { + ntfs_log_error("Encrypted/sparse attributes not supported.\n"); err = -EOPNOTSUPP; goto err_out; } @@ -1213,18 +1237,18 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); a->lowest_vcn = cpu_to_le64(0); - a->highest_vcn = cpu_to_le64(highest_vcn - 1LL); + 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)); /* FIXME: Allocated size depends on compression. */ - a->allocated_size = cpu_to_le64(highest_vcn * g_vol->cluster_size); - a->data_size = cpu_to_le64(val_len); + a->allocated_size = cpu_to_sle64(highest_vcn * g_vol->cluster_size); + a->data_size = cpu_to_sle64(val_len); if (name_len) memcpy((char*)a + hdr_size, uname, name_len << 1); if (flags & ATTR_COMPRESSION_MASK) { if (flags & ATTR_COMPRESSION_MASK & ~ATTR_IS_COMPRESSED) { - ntfs_log_error("Unknown compression format. Reverting to " - "standard compression.\n"); + ntfs_log_error("Unknown compression format. Reverting " + "to standard compression.\n"); a->flags &= ~ATTR_COMPRESSION_MASK; a->flags |= ATTR_IS_COMPRESSED; } @@ -1239,21 +1263,22 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->compression_unit = 0; bw = ntfs_rlwrite(g_vol->dev, rl, val, val_len, &inited_size); if (bw != val_len) { - ntfs_log_error("Error writing non-resident attribute value.\n"); + ntfs_log_error("Error writing non-resident attribute " + "value.\n"); return -errno; } err = ntfs_mapping_pairs_build(g_vol, (u8*)a + hdr_size + ((name_len + 7) & ~7), mpa_size, rl, 0, NULL); } - a->initialized_size = cpu_to_le64(inited_size); + a->initialized_size = cpu_to_sle64(inited_size); if (err < 0 || bw != val_len) { /* FIXME: Handle error. */ /* deallocate clusters */ /* remove attribute */ if (err >= 0) err = -EIO; - ntfs_log_error("insert_positioned_attr_in_mft_record failed with " - "error %i.\n", err < 0 ? err : (int)bw); + ntfs_log_error("insert_positioned_attr_in_mft_record failed " + "with error %i.\n", err < 0 ? err : (int)bw); } err_out: if (ctx) @@ -1319,8 +1344,8 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, err = -EOPNOTSUPP; goto err_out; } - if (flags & (ATTR_IS_ENCRYPTED || ATTR_IS_SPARSE)) { - ntfs_log_error("Encrypted/sparse attributes not supported yet.\n"); + if (flags & (ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) { + ntfs_log_error("Encrypted/sparse attributes not supported.\n"); err = -EOPNOTSUPP; goto err_out; } @@ -1399,14 +1424,14 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, a->lowest_vcn = cpu_to_le64(0); for (i = 0; rl[i].length; i++) ; - a->highest_vcn = cpu_to_le64(rl[i].vcn - 1); + a->highest_vcn = cpu_to_sle64(rl[i].vcn - 1); a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7)); memset(a->reserved1, 0, sizeof(a->reserved1)); /* FIXME: Allocated size depends on compression. */ - a->allocated_size = cpu_to_le64((val_len + (g_vol->cluster_size - 1)) & + a->allocated_size = cpu_to_sle64((val_len + (g_vol->cluster_size - 1)) & ~(g_vol->cluster_size - 1)); - a->data_size = cpu_to_le64(val_len); - a->initialized_size = cpu_to_le64(val_len); + a->data_size = cpu_to_sle64(val_len); + a->initialized_size = cpu_to_sle64(val_len); if (name_len) memcpy((char*)a + hdr_size, uname, name_len << 1); if (flags & ATTR_COMPRESSION_MASK) { @@ -1563,7 +1588,7 @@ err_out: * Return 0 on success or -errno on error. */ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, - u32 security_id) + le32 security_id) { STANDARD_INFORMATION si; int err, sd_size; @@ -1599,7 +1624,7 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, * * Return 0 on success or -errno on error. */ -static int add_attr_file_name(MFT_RECORD *m, const MFT_REF parent_dir, +static int add_attr_file_name(MFT_RECORD *m, const leMFT_REF parent_dir, const s64 allocated_size, const s64 data_size, const FILE_ATTR_FLAGS flags, const u16 packed_ea_size, const u32 reparse_point_tag, const char *file_name, @@ -1614,14 +1639,14 @@ static int add_attr_file_name(MFT_RECORD *m, const MFT_REF parent_dir, /* Check if the attribute is already there. */ ctx = ntfs_attr_get_search_ctx(NULL, m); if (!ctx) { - ntfs_log_error("Failed to allocate attribute search context.\n"); + ntfs_log_error("Failed to get attribute search context.\n"); return -ENOMEM; } - if (mkntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, - ctx)) { + if (mkntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, 0, 0, + NULL, 0, ctx)) { int eo = errno; - ntfs_log_error("BUG: Standard information attribute not present in " - "file record\n"); + ntfs_log_error("BUG: Standard information attribute not " + "present in file record.\n"); ntfs_attr_put_search_ctx(ctx); return -eo; } @@ -1642,8 +1667,8 @@ static int add_attr_file_name(MFT_RECORD *m, const MFT_REF parent_dir, fn->last_access_time = si->last_access_time; ntfs_attr_put_search_ctx(ctx); - fn->allocated_size = cpu_to_le64(allocated_size); - fn->data_size = cpu_to_le64(data_size); + fn->allocated_size = cpu_to_sle64(allocated_size); + fn->data_size = cpu_to_sle64(data_size); fn->file_attributes = flags; /* These are in a union so can't have both. */ if (packed_ea_size && reparse_point_tag) { @@ -1896,8 +1921,8 @@ static int add_attr_index_root(MFT_RECORD *m, const char *name, return -EINVAL; } if (index_block_size < (u32)opts.sector_size) { - ntfs_log_error("add_attr_index_root: index block size is " - "smaller than the sector size.\n"); + ntfs_log_error("add_attr_index_root: index block size " + "is smaller than the sector size.\n"); free(r); return -EINVAL; } @@ -2084,7 +2109,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, "Thank you.", NTFS_DEV_LIST); } /* Set USN to 1. */ - *(u16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) = + *(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); @@ -2129,8 +2154,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, goto err_out; } /* Set VCN pointer to 0LL. */ - *(VCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) = - cpu_to_le64(0); + *(leVCN*)((char*)re + le16_to_cpu(re->length) - sizeof(VCN)) = 0; err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size); if (err) { err = -errno; @@ -2482,7 +2506,7 @@ static int initialize_secure(char *sds, u32 sds_size, MFT_RECORD *m) */ static int initialize_quota(MFT_RECORD *m) { - int o_size, q1_size, q2_size, err; + int o_size, q1_size, q2_size, err, i; INDEX_ENTRY *idx_entry_o, *idx_entry_q1, *idx_entry_q2; QUOTA_O_INDEX_DATA *idx_entry_o_data; QUOTA_CONTROL_ENTRY *idx_entry_q1_data, *idx_entry_q2_data; @@ -2507,8 +2531,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 = utc2ntfs(mkntfs_time()); - idx_entry_q1_data->threshold = const_cpu_to_le64((s64)-1); - idx_entry_q1_data->limit = const_cpu_to_le64((s64)-1); + idx_entry_q1_data->threshold = cpu_to_sle64(-1); + idx_entry_q1_data->limit = cpu_to_sle64(-1); idx_entry_q1_data->exceeded_time = const_cpu_to_le64(0x00); err = insert_index_entry_in_res_dir_index(idx_entry_q1, q1_size, m, NTFS_INDEX_Q, 2, AT_UNUSED); @@ -2534,15 +2558,14 @@ 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 = utc2ntfs(mkntfs_time());; - idx_entry_q2_data->threshold = const_cpu_to_le64((s64)-1); - idx_entry_q2_data->limit = const_cpu_to_le64((s64)-1); + idx_entry_q2_data->threshold = cpu_to_sle64(-1); + idx_entry_q2_data->limit = cpu_to_sle64(-1); idx_entry_q2_data->exceeded_time = const_cpu_to_le64(0x00); idx_entry_q2_data->sid.revision = 1; idx_entry_q2_data->sid.sub_authority_count = 2; - idx_entry_q2_data->sid.identifier_authority.high_part = - const_cpu_to_le16(0x0000); - idx_entry_q2_data->sid.identifier_authority.low_part = - const_cpu_to_le32(0x05000000); + for (i = 0; i < 5; i++) + idx_entry_q2_data->sid.identifier_authority.value[i] = 0; + idx_entry_q2_data->sid.identifier_authority.value[5] = 0x05; idx_entry_q2_data->sid.sub_authority[0] = const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); idx_entry_q2_data->sid.sub_authority[1] = @@ -2565,10 +2588,9 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_o->reserved = const_cpu_to_le16(0x00); idx_entry_o->key.sid.revision = 0x01; idx_entry_o->key.sid.sub_authority_count = 0x02; - idx_entry_o->key.sid.identifier_authority.high_part = - const_cpu_to_le16(0x0000); - idx_entry_o->key.sid.identifier_authority.low_part = - const_cpu_to_le32(0x05000000); + for (i = 0; i < 5; i++) + idx_entry_o->key.sid.identifier_authority.value[i] = 0; + idx_entry_o->key.sid.identifier_authority.value[5] = 0x05; idx_entry_o->key.sid.sub_authority[0] = const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); idx_entry_o->key.sid.sub_authority[1] = @@ -2594,7 +2616,7 @@ static int initialize_quota(MFT_RECORD *m) * * Return 0 on success or -errno on error. */ -static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref, +static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, leMFT_REF file_ref, FILE_NAME_ATTR *file_name, u32 file_name_size) { int err, i; @@ -2627,7 +2649,8 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref, if (i < 0) ntfs_log_debug("Name contains non-displayable " "Unicode characters.\n"); - ntfs_log_debug("file_name_attr1->file_name = %s\n", __buf); + ntfs_log_debug("file_name_attr1->file_name = %s\n", + __buf); free(__buf); } ntfs_log_debug("file_name_attr2->file_name_length = %i\n", @@ -2635,11 +2658,13 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref, if (ie->key.file_name.file_name_length) { char *__buf = NULL; i = ntfs_ucstombs(ie->key.file_name.file_name, - ie->key.file_name.file_name_length + 1, &__buf, 0); + ie->key.file_name.file_name_length + 1, &__buf, + 0); if (i < 0) ntfs_log_debug("Name contains non-displayable " "Unicode characters.\n"); - ntfs_log_debug("file_name_attr2->file_name = %s\n", __buf); + ntfs_log_debug("file_name_attr2->file_name = %s\n", + __buf); free(__buf); } #endif @@ -2670,7 +2695,8 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref, return -EEXIST; i = ntfs_file_values_compare(file_name, (FILE_NAME_ATTR*)&ie->key.file_name, 1, - CASE_SENSITIVE, g_vol->upcase, g_vol->upcase_len); + CASE_SENSITIVE, g_vol->upcase, + g_vol->upcase_len); if (i == -1) break; /* Complete match. Bugger. Can't insert. */ @@ -2680,7 +2706,8 @@ do_next: #ifdef DEBUG /* Next entry. */ if (!ie->length) { - ntfs_log_debug("BUG: ie->length is zero, breaking out of loop.\n"); + ntfs_log_debug("BUG: ie->length is zero, breaking out " + "of loop.\n"); break; } #endif @@ -2689,8 +2716,8 @@ do_next: i = (sizeof(INDEX_ENTRY_HEADER) + file_name_size + 7) & ~7; err = make_room_for_index_entry_in_index_block(idx, ie, i); if (err) { - ntfs_log_error("make_room_for_index_entry_in_index_block failed: " - "%s\n", strerror(-err)); + ntfs_log_error("make_room_for_index_entry_in_index_block " + "failed: %s\n", strerror(-err)); return err; } /* Create entry in place and copy file name attribute value. */ @@ -2716,8 +2743,8 @@ do_next: * * Return 0 on success or -errno on error. */ -static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent, - MFT_RECORD *m_file, const MFT_REF ref_file, +static int create_hardlink_res(MFT_RECORD *m_parent, const leMFT_REF ref_parent, + MFT_RECORD *m_file, const leMFT_REF ref_file, const s64 allocated_size, const s64 data_size, const FILE_ATTR_FLAGS flags, const u16 packed_ea_size, const u32 reparse_point_tag, const char *file_name, @@ -2740,8 +2767,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent, fn->last_data_change_time = fn->creation_time; fn->last_mft_change_time = fn->creation_time; fn->last_access_time = fn->creation_time; - fn->allocated_size = cpu_to_le64(allocated_size); - fn->data_size = cpu_to_le64(data_size); + fn->allocated_size = cpu_to_sle64(allocated_size); + fn->data_size = cpu_to_sle64(data_size); fn->file_attributes = flags; /* These are in a union so can't have both. */ if (packed_ea_size && reparse_point_tag) { @@ -2784,8 +2811,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent, i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, 0, 0, RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size); if (i < 0) { - ntfs_log_error("create_hardlink failed adding file name attribute: " - "%s\n", strerror(-i)); + ntfs_log_error("create_hardlink failed adding file name " + "attribute: %s\n", strerror(-i)); free(fn); /* Undo link count increment. */ m_file->link_count = cpu_to_le16( @@ -2804,8 +2831,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent, i = insert_index_entry_in_res_dir_index(idx_entry_new, idx_size + 0x10, m_parent, NTFS_INDEX_I30, 4, AT_FILE_NAME); if (i < 0) { - ntfs_log_error("create_hardlink failed inserting index entry: %s\n", - strerror(-i)); + ntfs_log_error("create_hardlink failed inserting index entry: " + "%s\n", strerror(-i)); /* FIXME: Remove the file name attribute from @m_file. */ free(idx_entry_new); free(fn); @@ -2832,8 +2859,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent, * * Return 0 on success or -errno on error. */ -static int create_hardlink(INDEX_BLOCK *idx, const MFT_REF ref_parent, - MFT_RECORD *m_file, const MFT_REF ref_file, +static int create_hardlink(INDEX_BLOCK *idx, const leMFT_REF ref_parent, + MFT_RECORD *m_file, const leMFT_REF ref_file, const s64 allocated_size, const s64 data_size, const FILE_ATTR_FLAGS flags, const u16 packed_ea_size, const u32 reparse_point_tag, const char *file_name, @@ -2856,8 +2883,8 @@ static int create_hardlink(INDEX_BLOCK *idx, const MFT_REF ref_parent, fn->last_data_change_time = fn->creation_time; fn->last_mft_change_time = fn->creation_time; fn->last_access_time = fn->creation_time; - fn->allocated_size = cpu_to_le64(allocated_size); - fn->data_size = cpu_to_le64(data_size); + fn->allocated_size = cpu_to_sle64(allocated_size); + fn->data_size = cpu_to_sle64(data_size); fn->file_attributes = flags; /* These are in a union so can't have both. */ if (packed_ea_size && reparse_point_tag) { @@ -2932,7 +2959,7 @@ static int create_hardlink(INDEX_BLOCK *idx, const MFT_REF ref_parent, * Return 0 on success or -errno on error. */ static int index_obj_id_insert(MFT_RECORD *m, const GUID *guid, - const MFT_REF ref) + const leMFT_REF ref) { INDEX_ENTRY *idx_entry_new; int data_ofs, idx_size, err; @@ -3840,7 +3867,7 @@ static BOOL mkntfs_sync_index_record(INDEX_ALLOCATION* idx, MFT_RECORD* m, /** * create_file_volume - */ -static BOOL create_file_volume(MFT_RECORD *m, MFT_REF root_ref, +static BOOL create_file_volume(MFT_RECORD *m, leMFT_REF root_ref, VOLUME_FLAGS fl, const GUID *volume_guid #ifndef ENABLE_UUID __attribute__((unused)) @@ -3943,8 +3970,8 @@ static BOOL mkntfs_create_root_structures(void) { NTFS_BOOT_SECTOR *bs; MFT_RECORD *m; - MFT_REF root_ref; - MFT_REF extend_ref; + leMFT_REF root_ref; + leMFT_REF extend_ref; int i; int j; int err; @@ -3970,7 +3997,8 @@ static BOOL mkntfs_create_root_structures(void) for (i = 0; i < nr_sysfiles; i++) { if (ntfs_mft_record_layout(g_vol, 0, m = (MFT_RECORD *)(g_buf + i * g_vol->mft_record_size))) { - ntfs_log_error("Failed to layout system mft records.\n"); + ntfs_log_error("Failed to layout system mft records." + "\n"); return FALSE; } if (i == 0 || i > 23) @@ -3987,7 +4015,8 @@ static BOOL mkntfs_create_root_structures(void) i * (s32)g_vol->mft_record_size < g_mft_size; i++) { m = (MFT_RECORD *)(g_buf + i * g_vol->mft_record_size); if (ntfs_mft_record_layout(g_vol, 0, m)) { - ntfs_log_error("Failed to layout mft record.\n"); + ntfs_log_error("Failed to layout mft record." + "\n"); return FALSE; } m->flags = cpu_to_le16(0); @@ -3999,7 +4028,7 @@ static BOOL mkntfs_create_root_structures(void) * to each as well as marking them in use in the mft bitmap. */ for (i = 0; i < nr_sysfiles; i++) { - u32 file_attrs; + le32 file_attrs; m = (MFT_RECORD*)(g_buf + i * g_vol->mft_record_size); if (i < 16 || i > 23) { @@ -4065,14 +4094,16 @@ static BOOL mkntfs_create_root_structures(void) ATTR_RECORD *a; ctx = ntfs_attr_get_search_ctx(NULL, m); if (!ctx) { - ntfs_log_perror("Failed to allocate attribute search context"); + ntfs_log_perror("Failed to allocate attribute search " + "context"); return FALSE; } /* There is exactly one file name so this is ok. */ - if (mkntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, - ctx)) { + if (mkntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL, + 0, ctx)) { ntfs_attr_put_search_ctx(ctx); - ntfs_log_error("BUG: $FILE_NAME attribute not found.\n"); + ntfs_log_error("BUG: $FILE_NAME attribute not found." + "\n"); return FALSE; } a = ctx->attr; @@ -4118,7 +4149,8 @@ static BOOL mkntfs_create_root_structures(void) FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0, "$MFTMirr", FILE_NAME_WIN32_AND_DOS); if (err < 0) { - ntfs_log_error("Couldn't create $MFTMirr: %s\n", strerror(-err)); + ntfs_log_error("Couldn't create $MFTMirr: %s\n", + strerror(-err)); return FALSE; } ntfs_log_verbose("Creating $LogFile (mft record 2)\n"); @@ -4138,12 +4170,14 @@ static BOOL mkntfs_create_root_structures(void) FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0, "$LogFile", FILE_NAME_WIN32_AND_DOS); if (err < 0) { - ntfs_log_error("Couldn't create $LogFile: %s\n", strerror(-err)); + ntfs_log_error("Couldn't create $LogFile: %s\n", + strerror(-err)); return FALSE; } ntfs_log_verbose("Creating $AttrDef (mft record 4)\n"); m = (MFT_RECORD*)(g_buf + 4 * g_vol->mft_record_size); - err = add_attr_data(m, NULL, 0, 0, 0, (u8*)g_vol->attrdef, g_vol->attrdef_len); + err = add_attr_data(m, NULL, 0, 0, 0, (u8*)g_vol->attrdef, + g_vol->attrdef_len); if (!err) err = create_hardlink(g_index_block, root_ref, m, MK_LE_MREF(FILE_AttrDef, FILE_AttrDef), @@ -4156,7 +4190,8 @@ static BOOL mkntfs_create_root_structures(void) err = add_attr_sd(m, sd, i); } if (err < 0) { - ntfs_log_error("Couldn't create $AttrDef: %s\n", strerror(-err)); + ntfs_log_error("Couldn't create $AttrDef: %s\n", + strerror(-err)); return FALSE; } ntfs_log_verbose("Creating $Bitmap (mft record 6)\n"); @@ -4172,8 +4207,9 @@ static BOOL mkntfs_create_root_structures(void) if (!err) err = create_hardlink(g_index_block, root_ref, m, MK_LE_MREF(FILE_Bitmap, FILE_Bitmap), - (g_lcn_bitmap_byte_size + g_vol->cluster_size - 1) & - ~(g_vol->cluster_size - 1), g_lcn_bitmap_byte_size, + (g_lcn_bitmap_byte_size + g_vol->cluster_size - + 1) & ~(g_vol->cluster_size - 1), + g_lcn_bitmap_byte_size, FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0, "$Bitmap", FILE_NAME_WIN32_AND_DOS); if (err < 0) { @@ -4196,8 +4232,8 @@ static BOOL mkntfs_create_root_structures(void) opts.sector_size); bs->bpb.media_type = 0xf8; /* hard disk */ bs->bpb.sectors_per_track = cpu_to_le16(opts.sectors_per_track); - ntfs_log_debug("sectors per track = %ld (0x%lx)\n", opts.sectors_per_track, - opts.sectors_per_track); + ntfs_log_debug("sectors per track = %ld (0x%lx)\n", + opts.sectors_per_track, opts.sectors_per_track); bs->bpb.heads = cpu_to_le16(opts.heads); ntfs_log_debug("heads = %ld (0x%lx)\n", opts.heads, opts.heads); bs->bpb.hidden_sectors = cpu_to_le32(opts.part_start_sect); @@ -4212,12 +4248,13 @@ static BOOL mkntfs_create_root_structures(void) bs->clusters_per_mft_record = g_vol->mft_record_size / g_vol->cluster_size; } else { - bs->clusters_per_mft_record = -(ffs(g_vol->mft_record_size) - 1); + bs->clusters_per_mft_record = -(ffs(g_vol->mft_record_size) - + 1); if ((u32)(1 << -bs->clusters_per_mft_record) != g_vol->mft_record_size) { free(bs); - ntfs_log_error("BUG: calculated clusters_per_mft_record " - "is wrong (= 0x%x)\n", + ntfs_log_error("BUG: calculated clusters_per_mft_record" + " is wrong (= 0x%x)\n", bs->clusters_per_mft_record); return FALSE; } @@ -4230,10 +4267,12 @@ static BOOL mkntfs_create_root_structures(void) g_vol->cluster_size; } else { bs->clusters_per_index_record = -g_vol->indx_record_size_bits; - if ((1 << -bs->clusters_per_index_record) != (s32)g_vol->indx_record_size) { + if ((1 << -bs->clusters_per_index_record) != + (s32)g_vol->indx_record_size) { free(bs); - ntfs_log_error("BUG: calculated clusters_per_index_record " - "is wrong (= 0x%x)\n", + ntfs_log_error("BUG: calculated " + "clusters_per_index_record is wrong " + "(= 0x%x)\n", bs->clusters_per_index_record); return FALSE; } @@ -4242,8 +4281,8 @@ static BOOL mkntfs_create_root_structures(void) bs->clusters_per_index_record, bs->clusters_per_index_record); /* Generate a 64-bit random number for the serial number. */ - bs->volume_serial_number = cpu_to_sle64(((s64)random() << 32) | - ((s64)random() & 0xffffffff)); + bs->volume_serial_number = cpu_to_le64(((u64)random() << 32) | + ((u64)random() & 0xffffffff)); /* * Leave zero for now as NT4 leaves it zero, too. If want it later, see * ../libntfs/bootsect.c for how to calculate it. @@ -4255,7 +4294,8 @@ static BOOL mkntfs_create_root_structures(void) ntfs_log_error("FATAL: Generated boot sector is invalid!\n"); return FALSE; } - err = add_attr_data_positioned(m, NULL, 0, 0, 0, g_rl_boot, (u8*)bs, 8192); + err = add_attr_data_positioned(m, NULL, 0, 0, 0, g_rl_boot, (u8*)bs, + 8192); if (!err) err = create_hardlink(g_index_block, root_ref, m, MK_LE_MREF(FILE_Boot, FILE_Boot), @@ -4311,7 +4351,8 @@ static BOOL mkntfs_create_root_structures(void) 0, 0, "$BadClus", FILE_NAME_WIN32_AND_DOS); } if (err < 0) { - ntfs_log_error("Couldn't create $BadClus: %s\n", strerror(-err)); + ntfs_log_error("Couldn't create $BadClus: %s\n", + strerror(-err)); return FALSE; } /* create $Secure (NTFS 3.0+) */ @@ -4365,7 +4406,8 @@ static BOOL mkntfs_create_root_structures(void) MK_LE_MREF(FILE_UpCase, FILE_UpCase), ((g_vol->upcase_len << 1) + g_vol->cluster_size - 1) & - ~(g_vol->cluster_size - 1), g_vol->upcase_len << 1, + ~(g_vol->cluster_size - 1), + g_vol->upcase_len << 1, FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0, "$UpCase", FILE_NAME_WIN32_AND_DOS); if (err < 0) { @@ -4404,8 +4446,8 @@ static BOOL mkntfs_create_root_structures(void) err = add_attr_sd(m, sd, j); } if (err < 0) { - ntfs_log_error("Couldn't create system file %i (0x%x): %s\n", - i, i, strerror(-err)); + ntfs_log_error("Couldn't create system file %i (0x%x): " + "%s\n", i, i, strerror(-err)); return FALSE; } } diff --git a/ntfsprogs/ntfscat.c b/ntfsprogs/ntfscat.c index 57d2af69..88a12fe8 100644 --- a/ntfsprogs/ntfscat.c +++ b/ntfsprogs/ntfscat.c @@ -4,6 +4,7 @@ * Copyright (c) 2003-2005 Richard Russon * Copyright (c) 2003-2005 Anton Altaparmakov * Copyright (c) 2003-2005 Szabolcs Szakacsits + * Copyright (c) 2007 Yura Pakhuchiy * * This utility will concatenate files and print on the standard output. * @@ -59,12 +60,13 @@ static struct options opts; */ static void version(void) { - ntfs_log_info("\n%s v%s (libntfs %s) - Concatenate files and print on the " - "standard output.\n\n", EXEC_NAME, VERSION, + ntfs_log_info("\n%s v%s (libntfs %s) - Concatenate files and print " + "on the standard output.\n\n", EXEC_NAME, VERSION, ntfs_libntfs_version()); ntfs_log_info("Copyright (c) 2003-2005 Richard Russon\n"); ntfs_log_info("Copyright (c) 2003-2005 Anton Altaparmakov\n"); ntfs_log_info("Copyright (c) 2003-2005 Szabolcs Szakacsits\n"); + ntfs_log_info("Copyright (c) 2007 Yura Pakhuchiy\n"); ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); } @@ -131,15 +133,15 @@ static int parse_attribute(const char *value, ATTR_TYPES *attr) for (i = 0; attr_name[i]; i++) { if ((strcmp(value, attr_name[i]) == 0) || - (strcmp(value, attr_name[i]+1) == 0)) { - *attr = (ATTR_TYPES) ((i+1)*16); + (strcmp(value, attr_name[i] + 1) == 0)) { + *attr = (ATTR_TYPES)cpu_to_le32((i + 1) * 16); return 1; } } num = strtol(value, NULL, 0); if ((num > 0) && (num < 257)) { - *attr = (ATTR_TYPES) num; + *attr = (ATTR_TYPES)cpu_to_le32(num); return 1; } @@ -181,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 = -1; + opts.attr = cpu_to_le32(-1); opts.attr_name = NULL; opts.attr_name_len = 0; @@ -189,17 +191,19 @@ static int parse_options(int argc, char **argv) switch (c) { case 1: /* A non-option argument */ if (!opts.device) { - opts.device = argv[optind-1]; + opts.device = argv[optind - 1]; } else if (!opts.file) { - opts.file = argv[optind-1]; + opts.file = argv[optind - 1]; } else { - ntfs_log_error("You must specify exactly one file.\n"); + ntfs_log_error("You must specify exactly one " + "file.\n"); err++; } break; case 'a': - if (opts.attr != (ATTR_TYPES)-1) { - ntfs_log_error("You must specify exactly one attribute.\n"); + if (opts.attr != cpu_to_le32(-1)) { + ntfs_log_error("You must specify exactly one " + "attribute.\n"); } else if (parse_attribute(optarg, &attr) > 0) { opts.attr = attr; break; @@ -234,7 +238,8 @@ static int parse_options(int argc, char **argv) opts.attr_name_len = ntfs_mbstoucs(optarg, &opts.attr_name, 0); if (opts.attr_name_len < 0) { - ntfs_log_perror("Invalid attribute name '%s'", optarg); + ntfs_log_perror("Invalid attribute name '%s'", + optarg); usage(); } @@ -317,8 +322,7 @@ static int index_get_size(ntfs_inode *inode) return 0; // not a directory iroot = (INDEX_ROOT*)((u8*)attr90 + le16_to_cpu(attr90->value_offset)); - - return iroot->index_block_size; + return le32_to_cpu(iroot->index_block_size); } /** @@ -340,7 +344,8 @@ static int cat(ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type, attr = ntfs_attr_open(inode, type, name, namelen); if (!attr) { - ntfs_log_error("Cannot find attribute type 0x%lx.\n", (long) type); + ntfs_log_error("Cannot find attribute type 0x%x.\n", + le32_to_cpu(type)); free(buffer); return 1; } @@ -422,7 +427,7 @@ int main(int argc, char *argv[]) } attr = AT_DATA; - if (opts.attr != (ATTR_TYPES)-1) + if (opts.attr != cpu_to_le32(-1)) attr = opts.attr; result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len); diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index dac19f30..8bb94ab0 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -3,6 +3,7 @@ * * Copyright (c) 2003-2006 Szabolcs Szakacsits * Copyright (c) 2004-2006 Anton Altaparmakov + * Copyright (c) 2007 Yura Pakhuchiy * Special image format support copyright (c) 2004 Per Olofsson * * Clone NTFS data and/or metadata to a sparse file, image, device or stdout. @@ -153,8 +154,6 @@ static unsigned int wiped_unused_mft = 0; static unsigned int wiped_resident_data = 0; static unsigned int wiped_timestamp_data = 0; -static BOOL image_is_host_endian = FALSE; - #define IMAGE_MAGIC "\0ntfsclone-image" #define IMAGE_MAGIC_SIZE 16 @@ -180,11 +179,11 @@ static struct { char magic[IMAGE_MAGIC_SIZE]; u8 major_ver; u8 minor_ver; - u32 cluster_size; - s64 device_size; - s64 nr_clusters; - s64 inuse; - u32 offset_to_image_data; /* From start of image_hdr. */ + le32 cluster_size; + sle64 device_size; + sle64 nr_clusters; + sle64 inuse; + le32 offset_to_image_data; /* From start of image_hdr. */ } __attribute__((__packed__)) image_hdr; #define NTFSCLONE_IMG_HEADER_SIZE_OLD \ @@ -612,7 +611,7 @@ static void lseek_to_cluster(s64 lcn) static void image_skip_clusters(s64 count) { if (opt.save_image && count > 0) { - typeof(count) count_buf; + sle64 count_buf; char buff[1 + sizeof(count)]; buff[0] = 0; @@ -661,8 +660,8 @@ static void clone_ntfs(u64 nr_clusters) progress_init(&progress, p_counter, nr_clusters, 100); if (opt.save_image) { - if (write_all(&fd_out, &image_hdr, - image_hdr.offset_to_image_data) == -1) + if (write_all(&fd_out, &image_hdr, le32_to_cpu( + image_hdr.offset_to_image_data)) == -1) perr_exit("write_all"); } @@ -704,6 +703,7 @@ static void write_empty_clusters(s32 csize, s64 count, static void restore_image(void) { + sle64 countle; s64 pos = 0, count; s32 csize = le32_to_cpu(image_hdr.cluster_size); char cmd; @@ -722,10 +722,9 @@ static void restore_image(void) perr_exit("read_all"); if (cmd == 0) { - if (read_all(&fd_in, &count, sizeof(count)) == -1) + if (read_all(&fd_in, &countle, sizeof(countle)) == -1) perr_exit("read_all"); - if (!image_is_host_endian) - count = sle64_to_cpu(count); + count = sle64_to_cpu(countle); if (opt.std_out) write_empty_clusters(csize, count, &progress, &p_counter); @@ -746,7 +745,7 @@ static void restore_image(void) static void wipe_index_entry_timestams(INDEX_ENTRY *e) { - s64 timestamp = utc2ntfs(0); + sle64 timestamp = utc2ntfs(0); /* FIXME: can fall into infinite loop if corrupted */ while (!(e->flags & INDEX_ENTRY_END)) { @@ -855,7 +854,7 @@ out_indexr: free(indexr); } -static void wipe_index_root_timestamps(ATTR_RECORD *attr, s64 timestamp) +static void wipe_index_root_timestamps(ATTR_RECORD *attr, sle64 timestamp) { INDEX_ENTRY *entry; INDEX_ROOT *iroot; @@ -917,7 +916,7 @@ do { \ static void wipe_timestamps(ntfs_walk_clusters_ctx *image) { ATTR_RECORD *a = image->ctx->attr; - s64 timestamp = utc2ntfs(0); + sle64 timestamp = utc2ntfs(0); if (a->type == AT_FILE_NAME) WIPE_TIMESTAMPS(FILE_NAME_ATTR, a, timestamp); @@ -1552,9 +1551,8 @@ static s64 open_image(void) #endif image_hdr.offset_to_image_data = const_cpu_to_le32((sizeof(image_hdr) + 7) & ~7); - image_is_host_endian = TRUE; } else { - typeof(image_hdr.offset_to_image_data) offset_to_image_data; + le32 offset_to_image_data; int delta; if (image_hdr.major_ver > NTFSCLONE_IMG_VER_MAJOR) @@ -1567,16 +1565,16 @@ static s64 open_image(void) if (read_all(&fd_in, &offset_to_image_data, sizeof(offset_to_image_data)) == -1) perr_exit("read_all"); - image_hdr.offset_to_image_data = - le32_to_cpu(offset_to_image_data); + image_hdr.offset_to_image_data = offset_to_image_data; /* * Read any fields from the header that we have not read yet so * that the input stream is positioned correctly. This means * we can support future minor versions that just extend the * header in a backwards compatible way. */ - delta = offset_to_image_data - (NTFSCLONE_IMG_HEADER_SIZE_OLD + - sizeof(image_hdr.offset_to_image_data)); + delta = le32_to_cpu(offset_to_image_data) - + (NTFSCLONE_IMG_HEADER_SIZE_OLD + + sizeof(image_hdr.offset_to_image_data)); if (delta > 0) { char *dummy_buf; diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 414b64b7..f53c33fc 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -1,10 +1,26 @@ /** - * ntfscmp - compare two NTFS volumes. + * ntfscmp - Part of the Linux-NTFS project. * * Copyright (c) 2005-2006 Szabolcs Szakacsits - * Copyright (c) 2005 Anton Altaparmakov + * Copyright (c) 2005 Anton Altaparmakov + * Copyright (c) 2007 Yura Pakhuchiy * - * This utility is part of the Linux-NTFS project. + * This utility compare two NTFS volumes. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the Linux-NTFS + * distribution in the file COPYING); if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" @@ -386,7 +402,8 @@ static void print_attribute_name(char *name) } #define GET_ATTR_NAME(a) \ - ((ntfschar *)(((u8 *)(a)) + ((a)->name_offset))), ((a)->name_length) + ((ntfschar *)(((u8 *)(a)) + le16_to_cpu((a)->name_offset))), \ + ((a)->name_length) static void free_name(char **name) { @@ -537,15 +554,15 @@ static void cmp_index_allocation(ntfs_attr *na1, ntfs_attr *na2) if (cmp_buffer((u8 *)cia1.ia, (u8 *)cia2.ia, 0x18, na1)) goto out; - ib_size = cia1.ia->index.allocated_size + 0x18; + ib_size = le32_to_cpu(cia1.ia->index.allocated_size) + 0x18; bit = 0; while ((u8 *)cia1.tmp_ia < (u8 *)cia1.ia + na1->data_size) { if (*cia1.byte & (1 << bit)) { - ret1 = ntfs_mst_post_read_fixup((NTFS_RECORD *)cia1.tmp_ia, - ib_size); - ret2 = ntfs_mst_post_read_fixup((NTFS_RECORD *)cia2.tmp_ia, - ib_size); + ret1 = ntfs_mst_post_read_fixup((NTFS_RECORD *) + cia1.tmp_ia, ib_size); + ret2 = ntfs_mst_post_read_fixup((NTFS_RECORD *) + cia2.tmp_ia, ib_size); if (ret1 != ret2) { print_differ(na1); goto out; @@ -555,8 +572,9 @@ static void cmp_index_allocation(ntfs_attr *na1, ntfs_attr *na2) continue; if (cmp_buffer(((u8 *)cia1.tmp_ia) + 0x18, - ((u8 *)cia2.tmp_ia) + 0x18, - cia1.ia->index.index_length, na1)) + ((u8 *)cia2.tmp_ia) + 0x18, + le32_to_cpu(cia1.ia-> + index.index_length), na1)) goto out; } @@ -638,7 +656,7 @@ static int cmp_attribute_header(ATTR_RECORD *a1, ATTR_RECORD *a2) /* * FIXME: includes paddings which are not handled by ntfsinfo! */ - header_size = a1->length; + header_size = le32_to_cpu(a1->length); } return memcmp(a1, a2, header_size); @@ -818,9 +836,11 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2) old_atype1 = atype1; old_ret1 = ret1; - if (!ret1 && (atype1 <= atype2 || ret2)) + if (!ret1 && (le32_to_cpu(atype1) <= le32_to_cpu(atype2) || + ret2)) ret1 = next_attr(ctx1, &atype1, &name1, &errno1); - if (!ret2 && (old_atype1 >= atype2 || old_ret1)) + if (!ret2 && (le32_to_cpu(old_atype1) >= le32_to_cpu(atype2) || + old_ret1)) ret2 = next_attr(ctx2, &atype2, &name2, &errno2); print_attributes(ni1, atype1, atype2, name1, name2); @@ -834,14 +854,15 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2) break; } - if (ret2 || atype1 < atype2) { + if (ret2 || le32_to_cpu(atype1) < le32_to_cpu(atype2)) { if (new_attribute(ctx1, prev_atype, prev_name)) { print_ctx(ctx1); printf("presence: EXISTS != MISSING\n"); - set_prev(&prev_name, &prev_atype, name1, atype1); + set_prev(&prev_name, &prev_atype, name1, + atype1); } - } else if (ret1 || atype1 > atype2) { + } else if (ret1 || le32_to_cpu(atype1) > le32_to_cpu(atype2)) { if (new_attribute(ctx2, prev_atype, prev_name)) { print_ctx(ctx2); printf("presence: MISSING != EXISTS \n"); diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index 72af5a96..b2425174 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -182,7 +182,7 @@ static int parse_options(int argc, char **argv) ntfs_log_error("Couldn't parse attribute.\n"); err++; } else - opts.attribute = (ATTR_TYPES)attr; + opts.attribute = (ATTR_TYPES)cpu_to_le32(attr); break; case 'i': opts.inode++; diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index 66e1becf..738b13d9 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -1,8 +1,9 @@ /** * ntfsfix - Part of the Linux-NTFS project. * - * Copyright (c) 2000-2006 Anton Altaparmakov. - * Copyright (c) 2002-2006 Szabolcs Szakacsits. + * Copyright (c) 2000-2006 Anton Altaparmakov + * Copyright (c) 2002-2006 Szabolcs Szakacsits + * Copyright (c) 2007 Yura Pakhuchiy * * This utility fixes some common NTFS problems, resets the NTFS journal file * and schedules an NTFS consistency check for the first boot into Windows. @@ -116,8 +117,9 @@ static void version(void) { ntfs_log_info("%s v%s\n\n" "Attempt to fix an NTFS partition.\n\n" - "Copyright (c) 2000-2006 Anton Altaparmakov.\n" - "Copyright (c) 2002-2006 Szabolcs Szakacsits.\n\n", + "Copyright (c) 2000-2006 Anton Altaparmakov\n" + "Copyright (c) 2002-2006 Szabolcs Szakacsits\n" + "Copyright (c) 2007 Yura Pakhuchiy\n\n", EXEC_NAME, VERSION); ntfs_log_info("%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home); exit(1); @@ -168,7 +170,7 @@ static void parse_options(int argc, char **argv) /** * OLD_ntfs_volume_set_flags */ -static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const u16 flags) +static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const le16 flags) { MFT_RECORD *m = NULL; ATTR_RECORD *a; @@ -225,7 +227,7 @@ static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const u16 flags) goto err_out; } /* Set the volume flags. */ - vol->flags = c->flags = cpu_to_le16(flags); + vol->flags = c->flags = flags; if (ntfs_mft_record_write(vol, FILE_Volume, m)) { ntfs_log_perror("Error writing $Volume"); goto err_out; @@ -243,7 +245,7 @@ err_exit: */ static int set_dirty_flag(ntfs_volume *vol) { - u16 flags; + le16 flags; if (NVolWasDirty(vol)) return 0; @@ -362,7 +364,7 @@ static int fix_mftmirr(ntfs_volume *vol) use_mirr = FALSE; 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_record(mrec->magic)) { ntfs_log_info(FAILED); ntfs_log_error("$MFT error: Incomplete multi " "sector transfer detected in " @@ -370,7 +372,7 @@ static int fix_mftmirr(ntfs_volume *vol) ")-:\n", s); goto error_exit; } - if (!ntfs_is_mft_recordp(mrec)) { + if (!ntfs_is_mft_record(mrec->magic)) { ntfs_log_info(FAILED); ntfs_log_error("$MFT error: Invalid mft " "record for %s.\nCannot " @@ -380,14 +382,14 @@ static int fix_mftmirr(ntfs_volume *vol) } 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_record(mrec2->magic)) { ntfs_log_info(FAILED); ntfs_log_error("$MFTMirr error: Incomplete " "multi sector transfer " "detected in %s.\n", s); goto error_exit; } - if (!ntfs_is_mft_recordp(mrec2)) { + if (!ntfs_is_mft_record(mrec2->magic)) { ntfs_log_info(FAILED); ntfs_log_error("$MFTMirr error: Invalid mft " "record for %s.\n", s); @@ -395,7 +397,7 @@ static int fix_mftmirr(ntfs_volume *vol) } /* $MFT is corrupt but $MFTMirr is ok, use $MFTMirr. */ if (!(mrec->flags & MFT_RECORD_IN_USE) && - !ntfs_is_mft_recordp(mrec)) + !ntfs_is_mft_record(mrec->magic)) use_mirr = TRUE; } if (memcmp(mrec, mrec2, ntfs_mft_record_get_data_size(mrec))) { diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 127c8f5a..f723e52d 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -6,7 +6,7 @@ * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2003-2006 Szabolcs Szakacsits * Copyright (c) 2004-2005 Yuval Fledel - * Copyright (c) 2004-2006 Yura Pakhuchiy + * Copyright (c) 2004-2007 Yura Pakhuchiy * Copyright (c) 2005 Cristian Klein * * This utility will dump a file's attributes. @@ -113,7 +113,7 @@ static void version(void) printf(" 2003-2006 Szabolcs Szakacsits\n"); printf(" 2003 Leonard NorrgÄrd\n"); printf(" 2004-2005 Yuval Fledel\n"); - printf(" 2004-2006 Yura Pakhuchiy\n"); + printf(" 2004-2007 Yura Pakhuchiy\n"); printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); } @@ -333,7 +333,7 @@ static int parse_options(int argc, char *argv[]) * sle64_to_cpu(standard_attr->creation_time)); * printf("\tFile Creation Time:\t %s", time_str); */ -static char *ntfsinfo_time_to_str(const s64 sle_ntfs_clock) +static char *ntfsinfo_time_to_str(const sle64 sle_ntfs_clock) { time_t unix_clock = ntfs2utc(sle_ntfs_clock); return ctime(&unix_clock); @@ -448,7 +448,7 @@ static void ntfs_dump_volume(ntfs_volume *vol) * @type: dump flags for this attribute type * @flags: flags for dumping */ -static void ntfs_dump_flags(const char *indent, ATTR_TYPES type, u32 flags) +static void ntfs_dump_flags(const char *indent, ATTR_TYPES type, le32 flags) { printf("%sFile attributes:\t", indent); if (flags & FILE_ATTR_READONLY) { @@ -1030,7 +1030,7 @@ static void ntfs_dump_attr_volume_name(ATTR_RECORD *attr) { ntfschar *ucs_vol_name = NULL; - if (attr->value_length>0) { + if (le32_to_cpu(attr->value_length) > 0) { char *mbs_vol_name = NULL; int mbs_vol_name_size; /* calculate volume name position */ @@ -1038,20 +1038,18 @@ static void ntfs_dump_attr_volume_name(ATTR_RECORD *attr) le16_to_cpu(attr->value_offset)); /* convert the name to current locale multibyte sequence */ mbs_vol_name_size = ntfs_ucstombs(ucs_vol_name, - le32_to_cpu(attr->value_length)/sizeof(ntfschar), - &mbs_vol_name,0); + le32_to_cpu(attr->value_length) / + sizeof(ntfschar), &mbs_vol_name, 0); if (mbs_vol_name_size>0) { /* output the converted name. */ - printf("\tVolume Name:\t\t '%s'\n",mbs_vol_name); + printf("\tVolume Name:\t\t '%s'\n", mbs_vol_name); free(mbs_vol_name); - } else { - /* an error occurred, errno holds the reason - notify the user */ - ntfs_log_perror("ntfsinfo error: could not parse volume name"); - } - } else { + } else + ntfs_log_perror("ntfsinfo error: could not parse " + "volume name"); + } else printf("\tVolume Name:\t\t unnamed\n"); - } } /** @@ -1089,12 +1087,12 @@ static void ntfs_dump_attr_volume_information(ATTR_RECORD *attr) if (vol_information->flags & VOLUME_FLAGS_MASK) { printf("(0x%04x)\n", (unsigned)le16_to_cpu(vol_information->flags)); - } else { + } else printf("none set (0x0000)\n"); - } - if (vol_information->flags & (0xFFFF - VOLUME_FLAGS_MASK)) + if (vol_information->flags & (~VOLUME_FLAGS_MASK)) printf("\t\t\t\t Unknown Flags: 0x%04x\n", - vol_information->flags & (0xFFFF - VOLUME_FLAGS_MASK)); + le16_to_cpu(vol_information->flags & + (~VOLUME_FLAGS_MASK))); } static ntfschar NTFS_DATA_SDS[5] = { const_cpu_to_le16('$'), @@ -1168,7 +1166,7 @@ static void ntfs_dump_sds(ATTR_RECORD *attr, ntfs_inode *ni) free(sds); } -static const char *get_attribute_type_name(u32 type) +static const char *get_attribute_type_name(le32 type) { switch (type) { case AT_UNUSED: return "$UNUSED"; @@ -1367,7 +1365,7 @@ static void ntfs_dump_index_key(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type) break; default: ntfs_log_verbose("\t\tIndex attr type is UNKNOWN: \t 0x%08x\n", - (unsigned)le32_to_cpu(type)); + (unsigned)type); break; } } @@ -1383,7 +1381,8 @@ static void ntfs_dump_index_data(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type) { INDEX_ENTRY_DATA *data; - data = (INDEX_ENTRY_DATA *)((u8 *)entry + entry->data_offset); + data = (INDEX_ENTRY_DATA *)((u8 *)entry + + le16_to_cpu(entry->data_offset)); switch (type) { case INDEX_ATTR_SECURE_SII: @@ -1469,20 +1468,20 @@ static void ntfs_dump_index_data(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type) data->quota_q.change_time)); ntfs_log_verbose("\t\tThreshold:\t\t %lld (0x%llx)\n", (unsigned long long) - le64_to_cpu(data->quota_q.threshold), + sle64_to_cpu(data->quota_q.threshold), (unsigned long long) - le64_to_cpu(data->quota_q.threshold)); + sle64_to_cpu(data->quota_q.threshold)); ntfs_log_verbose("\t\tLimit:\t\t\t %lld (0x%llx)\n", (unsigned long long) - le64_to_cpu(data->quota_q.limit), + sle64_to_cpu(data->quota_q.limit), (unsigned long long) - le64_to_cpu(data->quota_q.limit)); + sle64_to_cpu(data->quota_q.limit)); ntfs_log_verbose("\t\tExceeded time:\t\t %lld (0x%llx)\n", (unsigned long long) - le64_to_cpu(data->quota_q.exceeded_time), + sle64_to_cpu(data->quota_q.exceeded_time), (unsigned long long) - le64_to_cpu(data->quota_q.exceeded_time)); - if (entry->data_length > 48) { + sle64_to_cpu(data->quota_q.exceeded_time)); + if (le16_to_cpu(entry->data_length) > 48) { char *sid; sid = ntfs_sid_to_mbs(&data->quota_q.sid, NULL, 0); ntfs_log_verbose("\t\tOwner SID:\t\t %s\n", sid); @@ -1491,7 +1490,7 @@ static void ntfs_dump_index_data(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type) break; default: ntfs_log_verbose("\t\tIndex attr type is UNKNOWN: \t 0x%08x\n", - (unsigned)le32_to_cpu(type)); + (unsigned)type); break; } } @@ -2013,8 +2012,8 @@ static void ntfs_dump_attr_unknown(ATTR_RECORD *attr) /* hex dump */ printf("\tDumping some of the attribute data:\n"); ntfs_hex_dump((u8*)attr + le16_to_cpu(attr->value_offset), - (le16_to_cpu(attr->value_length)>128)? - 128 : le16_to_cpu(attr->value_length)); + (le32_to_cpu(attr->value_length) > 128) ? + 128 : le32_to_cpu(attr->value_length)); } } @@ -2024,7 +2023,7 @@ static void ntfs_dump_attr_unknown(ATTR_RECORD *attr) static void ntfs_dump_inode_general_info(ntfs_inode *inode) { MFT_RECORD *mrec = inode->mrec; - u16 inode_flags = mrec->flags; + le16 inode_flags = mrec->flags; printf("Dumping Inode %llu (0x%llx)\n", (long long)inode->mft_no, @@ -2061,7 +2060,8 @@ static void ntfs_dump_inode_general_info(ntfs_inode *inode) inode_flags &= ~MFT_RECORD_IS_VIEW_INDEX; } if (inode_flags) - printf("UNKNOWN: 0x%04x", (unsigned)inode_flags); + printf("UNKNOWN: 0x%04x", (unsigned)le16_to_cpu( + inode_flags)); } else { printf("none"); } diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index b4797282..a6fc9926 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2006 Szabolcs Szakacsits * Copyright (c) 2002-2005 Anton Altaparmakov * Copyright (c) 2002-2003 Richard Russon + * Copyright (c) 2007 Yura Pakhuchiy * * This utility will resize an NTFS volume without data loss. * @@ -367,6 +368,7 @@ static void version(void) printf("Copyright (c) 2002-2006 Szabolcs Szakacsits\n"); printf("Copyright (c) 2002-2005 Anton Altaparmakov\n"); printf("Copyright (c) 2002-2003 Richard Russon\n"); + printf("Copyright (c) 2007 Yura Pakhuchiy\n"); printf("\n%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home); } @@ -1169,7 +1171,7 @@ static void replace_attribute_runlist(ntfs_volume *vol, ntfs_log_verbose("Bytes in use : %u\n", (unsigned int) le32_to_cpu(ctx->mrec->bytes_in_use)); - next_attr = (char *)a + le16_to_cpu(a->length); + next_attr = (char *)a + le32_to_cpu(a->length); l = mp_size - l; ntfs_log_verbose("Bytes in use new : %u\n", l + (unsigned int) @@ -1196,7 +1198,7 @@ static void replace_attribute_runlist(ntfs_volume *vol, memmove(next_attr + l, next_attr, remains_size); ctx->mrec->bytes_in_use = cpu_to_le32(l + le32_to_cpu(ctx->mrec->bytes_in_use)); - a->length += l; + a->length = cpu_to_le32(le32_to_cpu(a->length) + l); } mp = ntfs_calloc(mp_size); @@ -1609,8 +1611,8 @@ static int is_mftdata(ntfs_resize_t *resize) if (resize->mref == 0) return 1; - if ( MREF(resize->mrec->base_mft_record) == 0 && - MSEQNO(resize->mrec->base_mft_record) != 0) + if (MREF_LE(resize->mrec->base_mft_record) == 0 && + MSEQNO_LE(resize->mrec->base_mft_record) != 0) return 1; return 0; @@ -1872,9 +1874,9 @@ static void truncate_badclust_bad_attr(ntfs_resize_t *resize) rl_truncate(&rl_bad, nr_clusters); - a->highest_vcn = cpu_to_le64(nr_clusters - 1LL); - a->allocated_size = cpu_to_le64(nr_clusters * vol->cluster_size); - a->data_size = cpu_to_le64(nr_clusters * vol->cluster_size); + a->highest_vcn = cpu_to_sle64(nr_clusters - 1LL); + a->allocated_size = cpu_to_sle64(nr_clusters * vol->cluster_size); + a->data_size = cpu_to_sle64(nr_clusters * vol->cluster_size); replace_attribute_runlist(vol, resize->ctx, rl_bad); @@ -1949,10 +1951,10 @@ static void truncate_bitmap_data_attr(ntfs_resize_t *resize) realloc_bitmap_data_attr(resize, &rl, nr_bm_clusters); } - a->highest_vcn = cpu_to_le64(nr_bm_clusters - 1LL); - a->allocated_size = cpu_to_le64(nr_bm_clusters * vol->cluster_size); - a->data_size = cpu_to_le64(bm_bsize); - a->initialized_size = cpu_to_le64(bm_bsize); + a->highest_vcn = cpu_to_sle64(nr_bm_clusters - 1LL); + a->allocated_size = cpu_to_sle64(nr_bm_clusters * vol->cluster_size); + a->data_size = cpu_to_sle64(bm_bsize); + a->initialized_size = cpu_to_sle64(bm_bsize); replace_attribute_runlist(vol, resize->ctx, rl); @@ -2151,7 +2153,7 @@ static void update_bootsector(ntfs_resize_t *r) r->progress.flags |= NTFS_PROGBAR_SUPPRESS; copy_clusters(r, r->mftmir_rl.lcn, r->mftmir_old, r->mftmir_rl.length); - bs.mftmirr_lcn = cpu_to_le64(r->mftmir_rl.lcn); + bs.mftmirr_lcn = cpu_to_sle64(r->mftmir_rl.lcn); r->progress.flags &= ~NTFS_PROGBAR_SUPPRESS; } diff --git a/ntfsprogs/ntfsundelete.c b/ntfsprogs/ntfsundelete.c index 4718a96a..0dac320c 100644 --- a/ntfsprogs/ntfsundelete.c +++ b/ntfsprogs/ntfsundelete.c @@ -3,7 +3,8 @@ * * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2004-2005 Holger Ohmacht - * Copyright (c) 2005 Anton Altaparmakov + * Copyright (c) 2005 Anton Altaparmakov + * Copyright (c) 2007 Yura Pakhuchiy * * This utility will recover deleted files from an NTFS volume. * @@ -221,11 +222,13 @@ static int parse_inode_arg(void) */ static void version(void) { - ntfs_log_info("\n%s v%s (libntfs %s) - Recover deleted files from an NTFS " - "Volume.\n\n", EXEC_NAME, VERSION, + ntfs_log_info("\n%s v%s (libntfs %s) - Recover deleted files from an " + "NTFS Volume.\n\n", EXEC_NAME, VERSION, ntfs_libntfs_version()); ntfs_log_info("Copyright (c) 2002-2005 Richard Russon\n" - "Copyright (c) 2004-2005 Holger Ohmacht\n"); + "Copyright (c) 2004-2005 Holger Ohmacht\n" + "Copyright (c) 2005 Anton Altaparmakov\n" + "Copyright (c) 2007 Yura Pakhuchiy\n"); ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); } @@ -834,7 +837,8 @@ static void get_parent_name(struct filename* name, ntfs_volume* vol) rec = calloc(1, vol->mft_record_size); if (!rec) { - ntfs_log_error("ERROR: Couldn't allocate memory in get_parent_name()\n"); + ntfs_log_error("ERROR: Couldn't allocate memory in " + "get_parent_name()\n"); return; } @@ -842,10 +846,12 @@ static void get_parent_name(struct filename* name, ntfs_volume* vol) if (!mft_data) { ntfs_log_perror("ERROR: Couldn't open $MFT/$DATA"); } else { - inode_num = MREF(name->parent_mref); + inode_num = MREF_LE(name->parent_mref); - if (ntfs_attr_pread(mft_data, vol->mft_record_size * inode_num, vol->mft_record_size, rec) < 1) { - ntfs_log_error("ERROR: Couldn't read MFT Record %lld.\n", inode_num); + if (ntfs_attr_pread(mft_data, vol->mft_record_size * inode_num, + vol->mft_record_size, rec) < 1) { + ntfs_log_error("ERROR: Couldn't read MFT Record %lld" + ".\n", inode_num); } else if ((filename_attr = verify_parent(name, rec))) { if (ntfs_ucstombs(filename_attr->file_name, filename_attr->file_name_length, @@ -906,11 +912,13 @@ static int get_filenames(struct ufile *file, ntfs_volume* vol) while ((rec = find_attribute(AT_FILE_NAME, ctx))) { /* We know this will always be resident. */ - attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu(rec->value_offset)); + attr = (FILE_NAME_ATTR *)((char *)rec + + le16_to_cpu(rec->value_offset)); name = calloc(1, sizeof(*name)); if (!name) { - ntfs_log_error("ERROR: Couldn't allocate memory in get_filenames().\n"); + ntfs_log_error("ERROR: Couldn't allocate memory in " + "get_filenames().\n"); count = -1; break; } @@ -990,28 +998,32 @@ static int get_data(struct ufile *file, ntfs_volume *vol) while ((rec = find_attribute(AT_DATA, ctx))) { data = calloc(1, sizeof(*data)); if (!data) { - ntfs_log_error("ERROR: Couldn't allocate memory in get_data().\n"); + ntfs_log_error("ERROR: Couldn't allocate memory in " + "get_data().\n"); count = -1; break; } data->resident = !rec->non_resident; - data->compressed = rec->flags & ATTR_IS_COMPRESSED; - data->encrypted = rec->flags & ATTR_IS_ENCRYPTED; + data->compressed = (rec->flags & ATTR_IS_COMPRESSED) ? 1 : 0; + data->encrypted = (rec->flags & ATTR_IS_ENCRYPTED) ? 1 : 0; if (rec->name_length) { - data->uname = (ntfschar *) ((char *) rec + le16_to_cpu(rec->name_offset)); + data->uname = (ntfschar *)((char *)rec + + le16_to_cpu(rec->name_offset)); data->uname_len = rec->name_length; - if (ntfs_ucstombs(data->uname, data->uname_len, &data->name, - 0) < 0) { - ntfs_log_error("ERROR: Cannot translate name into current locale.\n"); + if (ntfs_ucstombs(data->uname, data->uname_len, + &data->name, 0) < 0) { + ntfs_log_error("ERROR: Cannot translate name " + "into current locale.\n"); } } if (data->resident) { - data->size_data = le32_to_cpu(rec->value_length); - data->data = ((char*) (rec)) + le16_to_cpu(rec->value_offset); + data->size_data = le32_to_cpu(rec->value_length); + data->data = (char*)rec + + le16_to_cpu(rec->value_offset); } else { data->size_alloc = sle64_to_cpu(rec->allocated_size); data->size_data = sle64_to_cpu(rec->data_size); @@ -1169,17 +1181,20 @@ static int calc_percentage(struct ufile *file, ntfs_volume *vol) clusters_free = 0; if (data->encrypted) { - ntfs_log_verbose("File is encrypted, recovery is impossible.\n"); + ntfs_log_verbose("File is encrypted, recovery is " + "impossible.\n"); continue; } if (data->compressed) { - ntfs_log_verbose("File is compressed, recovery not yet implemented.\n"); + ntfs_log_verbose("File is compressed, recovery not yet " + "implemented.\n"); continue; } if (data->resident) { - ntfs_log_verbose("File is resident, therefore recoverable.\n"); + ntfs_log_verbose("File is resident, therefore " + "recoverable.\n"); percent = 100; data->percent = 100; continue; @@ -1187,16 +1202,18 @@ static int calc_percentage(struct ufile *file, ntfs_volume *vol) rl = data->runlist; if (!rl) { - ntfs_log_verbose("File has no runlist, hence no data.\n"); + ntfs_log_verbose("File has no runlist, hence no data." + "\n"); continue; } if (rl[0].length <= 0) { - ntfs_log_verbose("File has an empty runlist, hence no data.\n"); + ntfs_log_verbose("File has an empty runlist, hence no " + "data.\n"); continue; } - if (rl[0].lcn == LCN_RL_NOT_MAPPED) { /* extended mft record */ + if (rl[0].lcn == LCN_RL_NOT_MAPPED) { /* extended mft record */ ntfs_log_verbose("Missing segment at beginning, %lld " "clusters\n", (long long)rl[0].length); clusters_inuse += rl[0].length; @@ -1288,12 +1305,18 @@ static void dump_record(struct ufile *file) ntfs_log_quiet("Filename: (%d) %s\n", f->name_space, f->name); ntfs_log_quiet("File Flags: "); - if (f->flags & FILE_ATTR_SYSTEM) ntfs_log_quiet("System "); - if (f->flags & FILE_ATTR_DIRECTORY) ntfs_log_quiet("Directory "); - if (f->flags & FILE_ATTR_SPARSE_FILE) ntfs_log_quiet("Sparse "); - if (f->flags & FILE_ATTR_REPARSE_POINT) ntfs_log_quiet("Reparse "); - if (f->flags & FILE_ATTR_COMPRESSED) ntfs_log_quiet("Compressed "); - if (f->flags & FILE_ATTR_ENCRYPTED) ntfs_log_quiet("Encrypted "); + if (f->flags & FILE_ATTR_SYSTEM) + ntfs_log_quiet("System "); + if (f->flags & FILE_ATTR_DIRECTORY) + ntfs_log_quiet("Directory "); + if (f->flags & FILE_ATTR_SPARSE_FILE) + ntfs_log_quiet("Sparse "); + if (f->flags & FILE_ATTR_REPARSE_POINT) + ntfs_log_quiet("Reparse "); + if (f->flags & FILE_ATTR_COMPRESSED) + ntfs_log_quiet("Compressed "); + if (f->flags & FILE_ATTR_ENCRYPTED) + ntfs_log_quiet("Encrypted "); if (!(f->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_DIRECTORY | FILE_ATTR_SPARSE_FILE | FILE_ATTR_REPARSE_POINT | FILE_ATTR_COMPRESSED | FILE_ATTR_ENCRYPTED))) { @@ -1310,13 +1333,17 @@ static void dump_record(struct ufile *file) ntfs_log_quiet("Size alloc: %lld\n", f->size_alloc); ntfs_log_quiet("Size data: %lld\n", f->size_data); - strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_c)); + strftime(buffer, sizeof(buffer), "%F %R", + localtime(&f->date_c)); ntfs_log_quiet("Date C: %s\n", buffer); - strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_a)); + strftime(buffer, sizeof(buffer), "%F %R", + localtime(&f->date_a)); ntfs_log_quiet("Date A: %s\n", buffer); - strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_m)); + strftime(buffer, sizeof(buffer), "%F %R", + localtime(&f->date_m)); ntfs_log_quiet("Date M: %s\n", buffer); - strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_r)); + strftime(buffer, sizeof(buffer), "%F %R", + localtime(&f->date_r)); ntfs_log_quiet("Date R: %s\n", buffer); } @@ -1349,7 +1376,8 @@ static void dump_record(struct ufile *file) } } - ntfs_log_quiet("Amount potentially recoverable %d%%\n", d->percent); + ntfs_log_quiet("Amount potentially recoverable %d%%\n", + d->percent); } ntfs_log_quiet("________________________________________\n\n"); @@ -1402,10 +1430,14 @@ static void list_record(struct ufile *file) struct data *d = list_entry(item, struct data, list); if (!d->name) { - if (d->resident) flagr = 'R'; - else flagr = 'N'; - if (d->compressed) flagc = 'C'; /* These two are mutually exclusive */ - if (d->encrypted) flagc = 'E'; + if (d->resident) + flagr = 'R'; + else + flagr = 'N'; + if (d->compressed) + flagc = 'C'; + if (d->encrypted) + flagc = 'E'; percent = max(percent, d->percent); } diff --git a/ntfsprogs/ntfsundelete.h b/ntfsprogs/ntfsundelete.h index 177f5eec..529587b7 100644 --- a/ntfsprogs/ntfsundelete.h +++ b/ntfsprogs/ntfsundelete.h @@ -2,6 +2,7 @@ * ntfsundelete - Part of the Linux-NTFS project. * * Copyright (c) 2002 Richard Russon + * Copyright (c) 2007 Yura Pakhuchiy * * This utility will recover deleted files from an NTFS volume. * @@ -72,7 +73,7 @@ struct filename { time_t date_r; /* read */ char *name; /* Filename in current locale */ FILE_NAME_TYPE_FLAGS name_space; - long long parent_mref; + leMFT_REF parent_mref; char *parent_name; }; diff --git a/ntfsprogs/sd.c b/ntfsprogs/sd.c index 06d35fe8..bfc7341d 100644 --- a/ntfsprogs/sd.c +++ b/ntfsprogs/sd.c @@ -324,7 +324,6 @@ void init_root_sd(u8 **sd_val, int *sd_val_len) ace->type = ACCESS_ALLOWED_ACE_TYPE; ace->flags = 0; ace->size = const_cpu_to_le16(0x18); - ace->mask = 9; ace->mask = SYNCHRONIZE | READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_TRAVERSE | FILE_READ_EA | FILE_LIST_DIRECTORY; ace->sid.revision = SID_REVISION; diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index ed8ceaf8..9d8beb9e 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -4,6 +4,7 @@ * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2003-2006 Anton Altaparmakov * Copyright (c) 2003 Lode Leroy + * Copyright (c) 2005-2007 Yura Pakhuchiy * * A set of shared functions for ntfs utilities * @@ -578,7 +579,8 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b name = NULL; namelen = ntfs_ucsnlen(attrdef->name, sizeof(attrdef->name)); if (ntfs_ucstombs(attrdef->name, namelen, &name, 0) < 0) { - ntfs_log_error("Couldn't translate attribute type to current locale.\n"); + ntfs_log_error("Couldn't translate attribute type to " + "current locale.\n"); // ? return 0; } @@ -602,9 +604,10 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b name = NULL; namelen = attr->name_length; - if (ntfs_ucstombs((ntfschar *)((char *)attr + attr->name_offset), - namelen, &name, 0) < 0) { - ntfs_log_error("Couldn't translate attribute name to current locale.\n"); + if (ntfs_ucstombs((ntfschar *)((char *)attr + le16_to_cpu( + attr->name_offset)), namelen, &name, 0) < 0) { + ntfs_log_error("Couldn't translate attribute name to current " + "locale.\n"); // ? len = snprintf(buffer, bufsize, ""); return 0; @@ -785,7 +788,7 @@ int utils_is_metadata(ntfs_inode *inode) file = inode->mrec; if (file && (file->base_mft_record != 0)) { - num = MREF(file->base_mft_record); + num = MREF_LE(file->base_mft_record); if (__metadata(vol, num) == 1) return 1; } @@ -796,9 +799,9 @@ int utils_is_metadata(ntfs_inode *inode) return -1; /* We know this will always be resident. */ - attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu(rec->value_offset)); + attr = (FILE_NAME_ATTR *)((char *)rec + le16_to_cpu(rec->value_offset)); - num = MREF(attr->parent_directory); + num = MREF_LE(attr->parent_directory); if ((num != FILE_root) && (__metadata(vol, num) == 1)) return 1;