From f4e427e91a1062ab435e12eb9c770a2466dc27ea Mon Sep 17 00:00:00 2001 From: flatcap Date: Fri, 21 Oct 2005 18:05:13 +0000 Subject: [PATCH] implement logging in libntfs fix whitespace fix build problems tidy source code and more... --- include/ntfs/attrib.h | 8 +- include/ntfs/bitmap.h | 18 +- include/ntfs/debug.h | 25 +- include/ntfs/dir.h | 14 +- include/ntfs/endians.h | 12 +- include/ntfs/index.h | 16 +- include/ntfs/inode.h | 6 +- include/ntfs/layout.h | 168 +-- include/ntfs/logfile.h | 22 +- include/ntfs/logging.h | 91 +- include/ntfs/mft.h | 10 +- include/ntfs/ntfstime.h | 2 + include/ntfs/rich.h | 12 +- include/ntfs/runlist.h | 2 +- include/ntfs/support.h | 2 + include/ntfs/tree.h | 66 +- include/ntfs/types.h | 2 + include/ntfs/version.h | 2 +- include/ntfs/volume.h | 20 +- libntfs/attrib.c | 729 ++++++------- libntfs/attrlist.c | 65 +- libntfs/bitmap.c | 167 ++- libntfs/bootsect.c | 91 +- libntfs/collate.c | 36 +- libntfs/compat.c | 4 +- libntfs/compress.c | 30 +- libntfs/debug.c | 40 +- libntfs/device.c | 46 +- libntfs/dir.c | 423 ++++---- libntfs/index.c | 157 +-- libntfs/inode.c | 199 ++-- libntfs/lcnalloc.c | 386 +++---- libntfs/logfile.c | 112 +- libntfs/logging.c | 258 +++-- libntfs/mft.c | 383 +++---- libntfs/mst.c | 7 +- libntfs/rich.c | 60 +- libntfs/runlist.c | 342 +++--- libntfs/security.c | 16 +- libntfs/tree.c | 894 +++++++-------- libntfs/unistr.c | 20 +- libntfs/unix_io.c | 51 +- libntfs/volume.c | 533 ++++----- ntfsprogs/Makefile.am | 2 +- ntfsprogs/attrdef.c | 4 +- ntfsprogs/mkntfs.c | 1139 ++++++++++---------- ntfsprogs/ntfscat.c | 2 +- ntfsprogs/ntfsclone.c | 19 +- ntfsprogs/ntfscmp.c | 66 +- ntfsprogs/ntfscp.c | 2 +- ntfsprogs/ntfsdump_logfile.c | 3 +- ntfsprogs/ntfsfix.c | 9 +- ntfsprogs/ntfsinfo.c | 18 +- ntfsprogs/ntfslabel.c | 3 +- ntfsprogs/ntfsmount.c | 27 +- ntfsprogs/ntfsmove.h | 2 +- ntfsprogs/ntfsresize.c | 87 +- ntfsprogs/ntfsrm.c | 4 +- ntfsprogs/ntfstruncate.c | 3 +- ntfsprogs/ntfsundelete.c | 252 +++-- ntfsprogs/ntfsundelete.h | 2 +- ntfsprogs/sd.c | 1974 +++++++++++++++++----------------- ntfsprogs/upcase.c | 2 +- ntfsprogs/utils.c | 167 ++- ntfsprogs/utils.h | 8 +- 65 files changed, 4609 insertions(+), 4733 deletions(-) diff --git a/include/ntfs/attrib.h b/include/ntfs/attrib.h index 7d1f9f18..7f9182b8 100644 --- a/include/ntfs/attrib.h +++ b/include/ntfs/attrib.h @@ -33,6 +33,7 @@ typedef struct _ntfs_attr_search_ctx ntfs_attr_search_ctx; #include "runlist.h" #include "volume.h" #include "debug.h" +#include "logging.h" extern ntfschar AT_UNNAMED[]; @@ -135,7 +136,7 @@ static __inline__ int ntfs_attrs_walk(ntfs_attr_search_ctx *ctx) * @allocated_size: copy from the attribute record * @data_size: copy from the attribute record * @initialized_size: copy from the attribute record - * @compressed_size: copy from the attribute record + * @compressed_size: copy from the attribute record * @compression_block_size: size of a compression block (cb) * @compression_block_size_bits: log2 of the size of a cb * @compression_block_clusters: number of clusters per cb @@ -214,9 +215,8 @@ static inline void NAttrSet##flag(ntfs_attr *na) \ if (na->type == AT_DATA && na->name == AT_UNNAMED) \ NInoSet##flag(na->ni); \ else \ - Dprintf("%s(): BUG! Should be called only for " \ - "unnamed data attribute.\n", \ - __FUNCTION__); \ + ntfs_log_trace("BUG! Should be called only for "\ + "unnamed data attribute.\n"); \ } \ static inline void NAttrClear##flag(ntfs_attr *na) \ { \ diff --git a/include/ntfs/bitmap.h b/include/ntfs/bitmap.h index 041153f9..ef8e77ba 100644 --- a/include/ntfs/bitmap.h +++ b/include/ntfs/bitmap.h @@ -150,15 +150,15 @@ struct ntfs_bmp { }; -int ntfs_bmp_rollback (struct ntfs_bmp *bmp); -int ntfs_bmp_commit (struct ntfs_bmp *bmp); -void ntfs_bmp_free (struct ntfs_bmp *bmp); -struct ntfs_bmp * ntfs_bmp_create (ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len); -int ntfs_bmp_add_data (struct ntfs_bmp *bmp, VCN vcn, u8 *data); -u8 * ntfs_bmp_get_data (struct ntfs_bmp *bmp, VCN vcn); -int ntfs_bmp_set_range (struct ntfs_bmp *bmp, VCN vcn, s64 length, int value); -s64 ntfs_bmp_find_last_set (struct ntfs_bmp *bmp); -int ntfs_bmp_find_space (struct ntfs_bmp *bmp, LCN start, long size); +int ntfs_bmp_rollback(struct ntfs_bmp *bmp); +int ntfs_bmp_commit(struct ntfs_bmp *bmp); +void ntfs_bmp_free(struct ntfs_bmp *bmp); +struct ntfs_bmp * ntfs_bmp_create(ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len); +int ntfs_bmp_add_data(struct ntfs_bmp *bmp, VCN vcn, u8 *data); +u8 * ntfs_bmp_get_data(struct ntfs_bmp *bmp, VCN vcn); +int ntfs_bmp_set_range(struct ntfs_bmp *bmp, VCN vcn, s64 length, int value); +s64 ntfs_bmp_find_last_set(struct ntfs_bmp *bmp); +int ntfs_bmp_find_space(struct ntfs_bmp *bmp, LCN start, long size); #endif /* NTFS_RICH */ diff --git a/include/ntfs/debug.h b/include/ntfs/debug.h index b8615571..61ac9df7 100644 --- a/include/ntfs/debug.h +++ b/include/ntfs/debug.h @@ -25,26 +25,31 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + #ifdef HAVE_STDIO_H -# include +#include #endif #ifdef HAVE_STDARG_H -# include +#include #endif +#ifdef HAVE_STRING_H #include +#endif +#ifdef HAVE_ERRNO_H #include +#endif struct _runlist_element; extern void __Sprintf(const int silent, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); + __attribute__((format(printf, 2, 3))); #define Sprintf(silent, f, a...) __Sprintf(silent, f, ##a) #ifdef DEBUG /* Debug output to stderr. To get it run ./configure --enable-debug. */ -extern void __ntfs_debug (const char *file, int line, const char *function, +extern void __ntfs_debug(const char *file, int line, const char *function, const char *format, ...) __attribute__((format(printf, 4, 5))); #define ntfs_debug(f, a...) \ __ntfs_debug(__FILE__, __LINE__, __FUNCTION__, f, ##a) @@ -54,7 +59,7 @@ extern void __ntfs_error(const char *function, #define ntfs_error(sb, f, a...) __ntfs_error(__FUNCTION__, f, ##a) extern void __Dprintf(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); + __attribute__((format(printf, 1, 2))); #define Dprintf(f, a...) __Dprintf(f, ##a) extern void __Dputs(const char *s); @@ -63,8 +68,6 @@ extern void __Dputs(const char *s); extern void __Dperror(const char *s); #define Dperror(s) __Dperror(s) -extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl); - #else /* if !DEBUG */ #define ntfs_debug(f, a...) do {} while (0) @@ -74,10 +77,14 @@ extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl); #define Dputs(s) do {} while (0) #define Dperror(s) do {} while (0) -static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element *rl __attribute__((unused))) {} - #endif /* !DEBUG */ +#ifdef NTFS_DISABLE_DEBUG_LOGGING +static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element *rl __attribute__((unused))) {} +#else +extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl); +#endif + #define NTFS_BUG(msg) \ { \ int ___i; \ diff --git a/include/ntfs/dir.h b/include/ntfs/dir.h index 813f0e9e..fee2dd3c 100644 --- a/include/ntfs/dir.h +++ b/include/ntfs/dir.h @@ -102,13 +102,13 @@ struct ntfs_dir { }; -int ntfs_dir_rollback (struct ntfs_dir *dir); -int ntfs_dir_truncate (ntfs_volume *vol, struct ntfs_dir *dir); -int ntfs_dir_commit (struct ntfs_dir *dir); -void ntfs_dir_free (struct ntfs_dir *dir); -struct ntfs_dir * ntfs_dir_create (ntfs_volume *vol, MFT_REF mft_num); -void ntfs_dir_add (struct ntfs_dir *parent, struct ntfs_dir *child); -struct ntfs_dir * ntfs_dir_find2 (struct ntfs_dir *dir, ntfschar *name, int name_len); +int ntfs_dir_rollback(struct ntfs_dir *dir); +int ntfs_dir_truncate(ntfs_volume *vol, struct ntfs_dir *dir); +int ntfs_dir_commit(struct ntfs_dir *dir); +void ntfs_dir_free(struct ntfs_dir *dir); +struct ntfs_dir * ntfs_dir_create(ntfs_volume *vol, MFT_REF mft_num); +void ntfs_dir_add(struct ntfs_dir *parent, struct ntfs_dir *child); +struct ntfs_dir * ntfs_dir_find2(struct ntfs_dir *dir, ntfschar *name, int name_len); #endif /* NTFS_RICH */ diff --git a/include/ntfs/endians.h b/include/ntfs/endians.h index 27b30064..ec73c442 100644 --- a/include/ntfs/endians.h +++ b/include/ntfs/endians.h @@ -29,7 +29,6 @@ /* * Notes: - * * We define the conversion functions including typecasts since the * defaults don't necessarily perform appropriate typecasts. * Also, using our own functions means that we can change them if it @@ -38,20 +37,21 @@ */ #ifdef HAVE_ENDIAN_H -# include +#include #endif #ifdef HAVE_SYS_ENDIAN_H -# include +#include #endif #ifdef HAVE_MACHINE_ENDIAN_H -# include +#include #endif #ifdef HAVE_SYS_BYTEORDER_H -# include +#include #endif #ifdef HAVE_SYS_PARAM_H -# include +#include #endif + #ifndef __BYTE_ORDER # if defined(_BYTE_ORDER) # define __BYTE_ORDER _BYTE_ORDER diff --git a/include/ntfs/index.h b/include/ntfs/index.h index 20ce386d..756deb98 100644 --- a/include/ntfs/index.h +++ b/include/ntfs/index.h @@ -127,14 +127,14 @@ static inline void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx) #include "layout.h" -void ntfs_ie_free (INDEX_ENTRY *ie); -INDEX_ENTRY * ntfs_ie_create (void); -VCN ntfs_ie_get_vcn (INDEX_ENTRY *ie); -INDEX_ENTRY * ntfs_ie_copy (INDEX_ENTRY *ie); -INDEX_ENTRY * ntfs_ie_set_vcn (INDEX_ENTRY *ie, VCN vcn); -INDEX_ENTRY * ntfs_ie_remove_vcn (INDEX_ENTRY *ie); -INDEX_ENTRY * ntfs_ie_set_name (INDEX_ENTRY *ie, ntfschar *name, int namelen, FILE_NAME_TYPE_FLAGS nametype); -INDEX_ENTRY * ntfs_ie_remove_name (INDEX_ENTRY *ie); +void ntfs_ie_free(INDEX_ENTRY *ie); +INDEX_ENTRY * ntfs_ie_create(void); +VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie); +INDEX_ENTRY * ntfs_ie_copy(INDEX_ENTRY *ie); +INDEX_ENTRY * ntfs_ie_set_vcn(INDEX_ENTRY *ie, VCN vcn); +INDEX_ENTRY * ntfs_ie_remove_vcn(INDEX_ENTRY *ie); +INDEX_ENTRY * ntfs_ie_set_name(INDEX_ENTRY *ie, ntfschar *name, int namelen, FILE_NAME_TYPE_FLAGS nametype); +INDEX_ENTRY * ntfs_ie_remove_name(INDEX_ENTRY *ie); #endif /* NTFS_RICH */ diff --git a/include/ntfs/inode.h b/include/ntfs/inode.h index 41fdf242..4c15a60b 100644 --- a/include/ntfs/inode.h +++ b/include/ntfs/inode.h @@ -187,9 +187,9 @@ extern int ntfs_inode_free_space(ntfs_inode *ni, int size); #ifdef NTFS_RICH -int ntfs_inode_close2 (ntfs_inode *ni); -ntfs_inode * ntfs_inode_open2 (ntfs_volume *vol, const MFT_REF mref); -ntfs_inode * ntfs_inode_open3 (ntfs_volume *vol, const MFT_REF mref); +int ntfs_inode_close2(ntfs_inode *ni); +ntfs_inode * ntfs_inode_open2(ntfs_volume *vol, const MFT_REF mref); +ntfs_inode * ntfs_inode_open3(ntfs_volume *vol, const MFT_REF mref); #endif /* NTFS_RICH */ diff --git a/include/ntfs/layout.h b/include/ntfs/layout.h index 073e1ae7..3a7e1ecc 100644 --- a/include/ntfs/layout.h +++ b/include/ntfs/layout.h @@ -62,7 +62,7 @@ typedef struct { Required to boot Windows. */ /*0x15*/u32 large_sectors; /* zero */ /* sizeof() = 25 (0x19) bytes */ -} __attribute__ ((__packed__)) BIOS_PARAMETER_BLOCK; +} __attribute__((__packed__)) BIOS_PARAMETER_BLOCK; /* * NTFS boot sector structure. @@ -95,7 +95,7 @@ typedef struct { u16 end_of_sector_marker; /* End of bootsector magic. Always is 0xaa55 in little endian. */ /* sizeof() = 512 (0x200) bytes */ -} __attribute__ ((__packed__)) NTFS_BOOT_SECTOR; +} __attribute__((__packed__)) NTFS_BOOT_SECTOR; /* * Magic identifiers present at the beginning of all ntfs record containing @@ -190,7 +190,7 @@ typedef struct { including the Update Sequence Number (usn), thus the number of fixups is the usa_count minus 1. */ -} __attribute__ ((__packed__)) NTFS_RECORD; +} __attribute__((__packed__)) NTFS_RECORD; /* * System files mft record numbers. All these files are always marked as used @@ -241,7 +241,7 @@ typedef enum { /* * These are the so far known MFT_RECORD_* flags (16-bit) which contain * information about the mft record in which they are present. - * _4 and _8 are needed by $Extend sub-files (don't know what to + * _4 and _8 are needed by $Extend sub-files (don't know what to * call them yet...) */ @@ -251,7 +251,7 @@ typedef enum { MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004), MFT_RECORD_IS_8 = const_cpu_to_le16(0x0008), MFT_REC_SPACE_FILLER = 0xffff /* Just to make flags 16-bit. */ -} __attribute__ ((__packed__)) MFT_RECORD_FLAGS; +} __attribute__((__packed__)) MFT_RECORD_FLAGS; /* * mft references (aka file references or file record segment references) are @@ -390,7 +390,7 @@ typedef struct { * by overwriting it since you then can't get it back... * When reading we obviously use the data from the ntfs record header. */ -} __attribute__ ((__packed__)) MFT_RECORD; +} __attribute__((__packed__)) MFT_RECORD; /* This is the version without the NTFS 3.1+ specific fields. */ typedef struct { @@ -457,7 +457,7 @@ typedef struct { * by overwriting it since you then can't get it back... * When reading we obviously use the data from the ntfs record header. */ -} __attribute__ ((__packed__)) MFT_RECORD_OLD; +} __attribute__((__packed__)) MFT_RECORD_OLD; /* * System defined attributes (32-bit). Each attribute type has a corresponding @@ -599,7 +599,7 @@ typedef struct { /* 90*/ s64 min_size; /* Optional minimum attribute size. */ /* 98*/ s64 max_size; /* Maximum size of attribute. */ /* sizeof() = 0xa0 or 160 bytes */ -} __attribute__ ((__packed__)) ATTR_DEF; +} __attribute__((__packed__)) ATTR_DEF; /* * Attribute flags (16-bit). @@ -611,7 +611,7 @@ typedef enum { illegal value. */ ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000), ATTR_IS_SPARSE = const_cpu_to_le16(0x8000), -} __attribute__ ((__packed__)) ATTR_FLAGS; +} __attribute__((__packed__)) ATTR_FLAGS; /* * Attribute compression. @@ -687,7 +687,7 @@ typedef enum { RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index (has implications for deleting and modifying the attribute). */ -} __attribute__ ((__packed__)) RESIDENT_ATTR_FLAGS; +} __attribute__((__packed__)) RESIDENT_ATTR_FLAGS; /* * Attribute record header. Always aligned to 8-byte boundary. @@ -733,7 +733,7 @@ typedef struct { /* 24 */ void *resident_end[0]; /* Use offsetof(ATTR_RECORD, resident_end) to get size of a resident attribute. */ - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); /* Non-resident attributes. */ struct { /* 16*/ VCN lowest_vcn; /* Lowest valid virtual cluster number @@ -790,9 +790,9 @@ typedef struct { /* Use offsetof(ATTR_RECORD, compressed_end) to get size of a compressed attribute. */ /* sizeof(compressed attr) = 72*/ - } __attribute__ ((__packed__)); - } __attribute__ ((__packed__)); -} __attribute__ ((__packed__)) ATTR_RECORD; + } __attribute__((__packed__)); + } __attribute__((__packed__)); +} __attribute__((__packed__)) ATTR_RECORD; typedef ATTR_RECORD ATTR_REC; @@ -848,7 +848,7 @@ typedef enum { us whether this file has a view index present (eg. object id index, quota index, one of the security indexes or the encrypting file system related indexes). */ -} __attribute__ ((__packed__)) FILE_ATTR_FLAGS; +} __attribute__((__packed__)) FILE_ATTR_FLAGS; /* * NOTE on times in NTFS: All times are in MS standard time format, i.e. they @@ -890,7 +890,7 @@ typedef struct { /* 36 */ u8 reserved12[12]; /* Reserved/alignment to 8-byte boundary. */ /* 48 */ void *v1_end[0]; /* Marker for offsetof(). */ - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); /* sizeof() = 48 bytes */ /* NTFS 3.0 */ struct { @@ -944,10 +944,10 @@ typedef struct { journal is a very fast process, so the user won't even notice it. */ /* 72*/ void *v3_end[0]; /* Marker for offsetof(). */ - } __attribute__ ((__packed__)); - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); + } __attribute__((__packed__)); /* sizeof() = 72 bytes (NTFS 3.0) */ -} __attribute__ ((__packed__)) STANDARD_INFORMATION; +} __attribute__((__packed__)) STANDARD_INFORMATION; /* * Attribute: Attribute list (0x20). @@ -1008,7 +1008,7 @@ typedef struct { name_offset to determine the location of the name. */ /* sizeof() = 26 + (attribute_name_length * 2) bytes */ -} __attribute__ ((__packed__)) ATTR_LIST_ENTRY; +} __attribute__((__packed__)) ATTR_LIST_ENTRY; /* * The maximum allowed length for a file name. @@ -1039,7 +1039,7 @@ typedef enum { /* 3 means that both the Win32 and the DOS filenames are identical and hence have been saved in this single filename record. */ -} __attribute__ ((__packed__)) FILE_NAME_TYPE_FLAGS; +} __attribute__((__packed__)) FILE_NAME_TYPE_FLAGS; /* * Attribute: Filename (0x30). @@ -1077,17 +1077,17 @@ typedef struct { pack the extended attributes (EAs), if such are present.*/ /* 3e*/ u16 reserved; /* Reserved for alignment. */ - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); /* 3c*/ u32 reparse_point_tag; /* Type of reparse point, present only in reparse points and only if there are no EAs. */ - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); /* 40*/ u8 file_name_length; /* Length of file name in (Unicode) characters. */ /* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/ /* 42*/ ntfschar file_name[0]; /* File name in Unicode. */ -} __attribute__ ((__packed__)) FILE_NAME_ATTR; +} __attribute__((__packed__)) FILE_NAME_ATTR; /* * GUID structures store globally unique identifiers (GUID). A GUID is a @@ -1105,7 +1105,7 @@ typedef struct { u8 data4[8]; /* The first two bytes are the third group of four hexadecimal digits. The remaining six bytes are the final 12 hexadecimal digits. */ -} __attribute__ ((__packed__)) GUID; +} __attribute__((__packed__)) GUID; /* * FILE_Extend/$ObjId contains an index named $O. This index contains all @@ -1126,10 +1126,10 @@ typedef struct { GUID birth_volume_id; GUID birth_object_id; GUID domain_id; - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); u8 extended_info[48]; - } __attribute__ ((__packed__)); -} __attribute__ ((__packed__)) OBJ_ID_INDEX_DATA; + } __attribute__((__packed__)); +} __attribute__((__packed__)) OBJ_ID_INDEX_DATA; /* * Attribute: Object id (NTFS 3.0+) (0x40). @@ -1153,10 +1153,10 @@ typedef struct { GUID birth_object_id; /* Unique id of file when it was first created. */ GUID domain_id; /* Reserved, zero. */ - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); u8 extended_info[48]; - } __attribute__ ((__packed__)); -} __attribute__ ((__packed__)) OBJECT_ID_ATTR; + } __attribute__((__packed__)); +} __attribute__((__packed__)) OBJECT_ID_ATTR; /* * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in @@ -1297,9 +1297,9 @@ typedef union { struct { u16 high_part; /* High 16-bits. */ u32 low_part; /* Low 32-bits. */ - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); u8 value[6]; /* Value as individual bytes. */ -} __attribute__ ((__packed__)) SID_IDENTIFIER_AUTHORITY; +} __attribute__((__packed__)) SID_IDENTIFIER_AUTHORITY; /* * The SID structure is a variable-length structure used to uniquely identify @@ -1332,7 +1332,7 @@ typedef struct { u8 sub_authority_count; SID_IDENTIFIER_AUTHORITY identifier_authority; u32 sub_authority[1]; /* At least one sub_authority. */ -} __attribute__ ((__packed__)) SID; +} __attribute__((__packed__)) SID; /* * Current constants for SIDs. @@ -1370,7 +1370,7 @@ typedef enum { /* This one is for WinNT&2k. */ ACCESS_MAX_MS_ACE_TYPE = 8, -} __attribute__ ((__packed__)) ACE_TYPES; +} __attribute__((__packed__)) ACE_TYPES; /* * The ACE flags (8-bit) for audit and inheritance (see below). @@ -1394,7 +1394,7 @@ typedef enum { /* The audit flags. */ SUCCESSFUL_ACCESS_ACE_FLAG = 0x40, FAILED_ACCESS_ACE_FLAG = 0x80, -} __attribute__ ((__packed__)) ACE_FLAGS; +} __attribute__((__packed__)) ACE_FLAGS; /* * An ACE is an access-control entry in an access-control list (ACL). @@ -1411,7 +1411,7 @@ typedef struct { ACE_TYPES type; /* Type of the ACE. */ ACE_FLAGS flags; /* Flags describing the ACE. */ u16 size; /* Size in bytes of the ACE. */ -} __attribute__ ((__packed__)) ACE_HEADER; +} __attribute__((__packed__)) ACE_HEADER; /* * The access mask (32-bit). Defines the access rights. @@ -1557,7 +1557,7 @@ typedef struct { ACCESS_MASK generic_write; ACCESS_MASK generic_execute; ACCESS_MASK generic_all; -} __attribute__ ((__packed__)) GENERIC_MAPPING; +} __attribute__((__packed__)) GENERIC_MAPPING; /* * The predefined ACE type structures are as defined below. @@ -1574,7 +1574,7 @@ typedef struct { /* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ /* 8*/ SID sid; /* The SID associated with the ACE. */ -} __attribute__ ((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, +} __attribute__((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE; /* @@ -1596,7 +1596,7 @@ typedef struct { /* 12*/ GUID object_type; /* 28*/ GUID inherited_object_type; /* 44*/ SID sid; /* The SID associated with the ACE. */ -} __attribute__ ((__packed__)) ACCESS_ALLOWED_OBJECT_ACE, +} __attribute__((__packed__)) ACCESS_ALLOWED_OBJECT_ACE, ACCESS_DENIED_OBJECT_ACE, SYSTEM_AUDIT_OBJECT_ACE, SYSTEM_ALARM_OBJECT_ACE; @@ -1616,7 +1616,7 @@ typedef struct { u16 ace_count; /* Number of ACEs in the ACL. */ u16 alignment2; /* sizeof() = 8 bytes */ -} __attribute__ ((__packed__)) ACL; +} __attribute__((__packed__)) ACL; /* * Current constants for ACLs. @@ -1697,7 +1697,7 @@ typedef enum { SE_SACL_PROTECTED = const_cpu_to_le16(0x2000), SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000), SE_SELF_RELATIVE = const_cpu_to_le16(0x8000), -} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_CONTROL; +} __attribute__((__packed__)) SECURITY_DESCRIPTOR_CONTROL; /* * Self-relative security descriptor. Contains the owner and group SIDs as well @@ -1723,7 +1723,7 @@ typedef struct { SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL (unconditionally granting access) is specified. */ /* sizeof() = 0x14 bytes */ -} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_RELATIVE; +} __attribute__((__packed__)) SECURITY_DESCRIPTOR_RELATIVE; /* * Absolute security descriptor. Does not contain the owner and group SIDs, nor @@ -1751,7 +1751,7 @@ typedef struct { 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. */ -} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR; +} __attribute__((__packed__)) SECURITY_DESCRIPTOR; /* * Current constants for security descriptors. @@ -1825,16 +1825,16 @@ typedef struct { 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. */ -} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_HEADER; +} __attribute__((__packed__)) SECURITY_DESCRIPTOR_HEADER; typedef struct { u32 hash; /* Hash of the security descriptor. */ - u32 security_id; /* The security_id assigned to the descriptor. */ + u32 security_id; /* The security_id assigned to the descriptor. */ u64 offset_in_sds; /* Offset of the descriptor in SDS data stream */ u32 size_in_sds; /* Size of the descriptor in SDS data stream */ u64 reserved_II; /* Padding - always unicode "II" */ } __attribute__ ((__packed__)) SDH_INDEX_DATA; - + typedef struct { u32 hash; /* Hash of the security descriptor. */ u32 security_id; /* The security_id assigned to the descriptor. */ @@ -1843,7 +1843,7 @@ typedef struct { } __attribute__ ((__packed__)) SII_INDEX_DATA; typedef struct { - u64 owner_id; + u64 owner_id; } __attribute__ ((__packed__)) QUOTA_O_INDEX_DATA; /* @@ -1866,7 +1866,7 @@ typedef struct { u32 length; /* Size in bytes of this entry in $SDS stream. */ /* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security descriptor. */ -} __attribute__ ((__packed__)) SDS_ENTRY; +} __attribute__((__packed__)) SDS_ENTRY; /* * The index entry key used in the $SII index. The collation type is @@ -1874,7 +1874,7 @@ typedef struct { */ typedef struct { u32 security_id; /* The security_id assigned to the descriptor. */ -} __attribute__ ((__packed__)) SII_INDEX_KEY; +} __attribute__((__packed__)) SII_INDEX_KEY; /* * The index entry key used in the $SDH index. The keys are sorted first by @@ -1884,7 +1884,7 @@ typedef struct { typedef struct { u32 hash; /* Hash of the security descriptor. */ u32 security_id; /* The security_id assigned to the descriptor. */ -} __attribute__ ((__packed__)) SDH_INDEX_KEY; +} __attribute__((__packed__)) SDH_INDEX_KEY; /* * Attribute: Volume name (0x60). @@ -1894,7 +1894,7 @@ typedef struct { */ typedef struct { ntfschar name[0]; /* The name of the volume in Unicode. */ -} __attribute__ ((__packed__)) VOLUME_NAME; +} __attribute__((__packed__)) VOLUME_NAME; /* * Possible flags for the volume (16-bit). @@ -1908,7 +1908,7 @@ typedef enum { VOLUME_REPAIR_OBJECT_ID = const_cpu_to_le16(0x0020), VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000), VOLUME_FLAGS_MASK = const_cpu_to_le16(0x803f), -} __attribute__ ((__packed__)) VOLUME_FLAGS; +} __attribute__((__packed__)) VOLUME_FLAGS; /* * Attribute: Volume information (0x70). @@ -1923,7 +1923,7 @@ typedef struct { 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. */ -} __attribute__ ((__packed__)) VOLUME_INFORMATION; +} __attribute__((__packed__)) VOLUME_INFORMATION; /* * Attribute: Data attribute (0x80). @@ -1934,7 +1934,7 @@ typedef struct { */ typedef struct { u8 data[0]; /* The file's data contents. */ -} __attribute__ ((__packed__)) DATA_ATTR; +} __attribute__((__packed__)) DATA_ATTR; /* * Index header flags (8-bit). @@ -1956,7 +1956,7 @@ typedef enum { INDEX_NODE = 1, /* This node indexes other nodes, i.e. is not a leaf node. */ NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */ -} __attribute__ ((__packed__)) INDEX_HEADER_FLAGS; +} __attribute__((__packed__)) INDEX_HEADER_FLAGS; /* * This is the header for indexes, describing the INDEX_ENTRY records, which @@ -1984,7 +1984,7 @@ typedef struct { belongs to. */ INDEX_HEADER_FLAGS flags; /* Bit field of INDEX_HEADER_FLAGS. */ u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ -} __attribute__ ((__packed__)) INDEX_HEADER; +} __attribute__((__packed__)) INDEX_HEADER; /* * Attribute: Index root (0x90). @@ -2026,7 +2026,7 @@ typedef struct { u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ INDEX_HEADER index; /* Index header describing the following index entries. */ -} __attribute__ ((__packed__)) INDEX_ROOT; +} __attribute__((__packed__)) INDEX_ROOT; /* * Attribute: Index allocation (0xa0). @@ -2057,7 +2057,7 @@ typedef struct { * by overwriting it since you then can't get it back... * When reading use the data from the ntfs record header. */ -} __attribute__ ((__packed__)) INDEX_BLOCK; +} __attribute__((__packed__)) INDEX_BLOCK; typedef INDEX_BLOCK INDEX_ALLOCATION; @@ -2074,7 +2074,7 @@ typedef struct { u32 reparse_tag; /* Reparse point type (inc. flags). */ MFT_REF file_id; /* Mft record of the file containing the reparse point attribute. */ -} __attribute__ ((__packed__)) REPARSE_INDEX_KEY; +} __attribute__((__packed__)) REPARSE_INDEX_KEY; /* * Quota flags (32-bit). @@ -2132,7 +2132,7 @@ typedef struct { SID sid; /* The SID of the user/object associated with this quota entry. Equals zero for the quota defaults entry. */ -} __attribute__ ((__packed__)) QUOTA_CONTROL_ENTRY; +} __attribute__((__packed__)) QUOTA_CONTROL_ENTRY; /* * Predefined owner_id values (32-bit). @@ -2156,7 +2156,7 @@ typedef enum { entry does not represent a file but it can point to a sub-node. */ INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */ -} __attribute__ ((__packed__)) INDEX_ENTRY_FLAGS; +} __attribute__((__packed__)) INDEX_ENTRY_FLAGS; /* * This the index entry header (see below). @@ -2173,8 +2173,8 @@ typedef struct { index key. */ u16 data_length; /* Data length in bytes. */ u32 reservedV; /* Reserved (zero). */ - } __attribute__ ((__packed__)); - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); + } __attribute__((__packed__)); /* 8*/ u16 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 @@ -2183,7 +2183,7 @@ typedef struct { /* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */ /* 14*/ u16 reserved; /* Reserved/align to 8-byte boundary. */ /* sizeof() = 16 bytes */ -} __attribute__ ((__packed__)) INDEX_ENTRY_HEADER; +} __attribute__((__packed__)) INDEX_ENTRY_HEADER; /* * This is an index entry. A sequence of such entries follows each INDEX_HEADER @@ -2205,8 +2205,8 @@ typedef struct { index key. */ u16 data_length; /* Data length in bytes. */ u32 reservedV; /* Reserved (zero). */ - } __attribute__ ((__packed__)); - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); + } __attribute__((__packed__)); u16 length; /* Byte size of this index entry, multiple of 8-bytes. */ u16 key_length; /* Byte size of the key value, which is in the @@ -2234,7 +2234,7 @@ typedef struct { user_id of the owner of the quota control entry in the data part of the index. */ - } __attribute__ ((__packed__)) key; + } __attribute__((__packed__)) key; /* The (optional) index data is inserted here when creating. */ // VCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last @@ -2249,7 +2249,7 @@ typedef struct { // aligned vcn of INDEX_ENTRY{_HEADER} *ie is given by // (char*)ie + le16_to_cpu(ie->length) - sizeof(VCN), // where sizeof(VCN) can be hardcoded as 8 if wanted. */ -} __attribute__ ((__packed__)) INDEX_ENTRY; +} __attribute__((__packed__)) INDEX_ENTRY; /* * Attribute: Bitmap (0xb0). @@ -2263,7 +2263,7 @@ typedef struct { */ typedef struct { u8 bitmap[0]; /* Array of bits. */ -} __attribute__ ((__packed__)) BITMAP_ATTR; +} __attribute__((__packed__)) BITMAP_ATTR; /* * The reparse point tag defines the type of the reparse point. It also @@ -2316,7 +2316,7 @@ typedef struct { u16 reparse_data_length; /* Byte size of reparse data. */ u16 reserved; /* Align to 8-byte boundary. */ u8 reparse_data[0]; /* Meaning depends on reparse_tag. */ -} __attribute__ ((__packed__)) REPARSE_POINT; +} __attribute__((__packed__)) REPARSE_POINT; /* * Attribute: Extended attribute (EA) information (0xd0). @@ -2333,14 +2333,14 @@ typedef struct { ZwQueryEaFile() in Windows NT/2k. I.e. the byte size of the unpacked extended attributes. */ -} __attribute__ ((__packed__)) EA_INFORMATION; +} __attribute__((__packed__)) EA_INFORMATION; /* * Extended attribute flags (8-bit). */ typedef enum { NEED_EA = 0x80, -} __attribute__ ((__packed__)) EA_FLAGS; +} __attribute__((__packed__)) EA_FLAGS; /* * Attribute: Extended attribute (EA) (0xe0). @@ -2360,7 +2360,7 @@ typedef struct { u8 name[0]; /* Name of the EA. */ u8 value[0]; /* The value of the EA. Immediately follows the name. */ -} __attribute__ ((__packed__)) EA_ATTR; +} __attribute__((__packed__)) EA_ATTR; /* * Attribute: Property set (0xf0). @@ -2370,7 +2370,7 @@ typedef struct { */ typedef struct { /* Irrelevant as feature unused. */ -} __attribute__ ((__packed__)) PROPERTY_SET; +} __attribute__((__packed__)) PROPERTY_SET; /* * Attribute: Logged utility stream (0x100). @@ -2385,7 +2385,7 @@ typedef struct { */ typedef struct { /* Can be anything the creator chooses. */ -} __attribute__ ((__packed__)) LOGGED_UTILITY_STREAM; +} __attribute__((__packed__)) LOGGED_UTILITY_STREAM; /* * $EFS Data Structure: @@ -2430,12 +2430,12 @@ typedef struct { recovery fields (DRF), see below. Zero if no DRFs are present. */ u32 reserved; /* Reserved. */ -} __attribute__ ((__packed__)) EFS_ATTR_HEADER; +} __attribute__((__packed__)) EFS_ATTR_HEADER; typedef struct { u32 df_count; /* Number of data decryption/recovery fields in the array. */ -} __attribute__ ((__packed__)) EFS_DF_ARRAY_HEADER; +} __attribute__((__packed__)) EFS_DF_ARRAY_HEADER; typedef struct { /* 0*/ u32 df_length; /* Length of this data decryption/recovery @@ -2446,7 +2446,7 @@ typedef struct { u32 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. */ -} __attribute__ ((__packed__)) EFS_DF_HEADER; +} __attribute__((__packed__)) EFS_DF_HEADER; typedef struct { /* 0*/ u32 cred_length; /* Length of this credential in bytes. */ @@ -2472,7 +2472,7 @@ typedef struct { structure. */ /* 24*/ u32 public_key_blob_size; /* Size in bytes of public key blob. */ - } __attribute__ ((__packed__)); + } __attribute__((__packed__)); /* Certificate thumbprint. */ struct { /* 12*/ u32 cert_thumbprint_header_size; /* Size in @@ -2483,9 +2483,9 @@ typedef struct { thumbprint from start of this structure. */ u32 unknown1; /* Always 0? Might be padding... */ u32 unknown2; /* Always 0? Might be padding... */ - } __attribute__ ((__packed__)); - } __attribute__ ((__packed__)); -} __attribute__ ((__packed__)) EFS_DF_CREDENTIAL_HEADER; + } __attribute__((__packed__)); + } __attribute__((__packed__)); +} __attribute__((__packed__)) EFS_DF_CREDENTIAL_HEADER; typedef EFS_DF_CREDENTIAL_HEADER EFS_DF_CRED_HEADER; @@ -2503,7 +2503,7 @@ typedef struct { from start of this structure or 0 if no user name present. (This is also known as lpDisplayInformation.) */ -} __attribute__ ((__packed__)) EFS_DF_CERTIFICATE_THUMBPRINT_HEADER; +} __attribute__((__packed__)) EFS_DF_CERTIFICATE_THUMBPRINT_HEADER; typedef EFS_DF_CERTIFICATE_THUMBPRINT_HEADER EFS_DF_CERT_THUMBPRINT_HEADER; diff --git a/include/ntfs/logfile.h b/include/ntfs/logfile.h index 4e361e2f..7bfe5d8f 100644 --- a/include/ntfs/logfile.h +++ b/include/ntfs/logfile.h @@ -92,7 +92,7 @@ typedef struct { /* 28*/ sle16 major_ver; /* Log file major version. We only support version 1.1. */ /* sizeof() = 30 (0x1e) bytes */ -} __attribute__ ((__packed__)) RESTART_PAGE_HEADER; +} __attribute__((__packed__)) RESTART_PAGE_HEADER; /* * Constant for the log client indices meaning that there are no client records @@ -109,7 +109,7 @@ typedef struct { enum { RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002), RESTART_SPACE_FILLER = 0xffff, /* gcc: Force enum bit width to 16. */ -} __attribute__ ((__packed__)); +} __attribute__((__packed__)); typedef le16 RESTART_AREA_FLAGS; @@ -250,7 +250,7 @@ typedef struct { system time in NTFS format (see time.h). */ /* 44*/ le32 reserved; /* Reserved/alignment to 8-byte boundary. */ /* sizeof() = 48 (0x30) bytes */ -} __attribute__ ((__packed__)) RESTART_AREA; +} __attribute__((__packed__)) RESTART_AREA; /* * Log client record. The offset of this record is found by adding the offset @@ -289,7 +289,7 @@ typedef struct { always be "NTFS" with the remaining bytes set to 0. */ /* sizeof() = 160 (0xa0) bytes */ -} __attribute__ ((__packed__)) LOG_CLIENT_RECORD; +} __attribute__((__packed__)) LOG_CLIENT_RECORD; /* * Log page record page header. Each log page begins with this header and is @@ -309,7 +309,7 @@ typedef struct { union { LSN last_lsn; s64 file_offset; - } __attribute__ ((__packed__)) copy; + } __attribute__((__packed__)) copy; u32 flags; u16 page_count; u16 page_position; @@ -318,9 +318,9 @@ typedef struct { u16 next_record_offset; u8 reserved[6]; LSN last_end_lsn; - } __attribute__ ((__packed__)) packed; - } __attribute__ ((__packed__)) header; -} __attribute__ ((__packed__)) RECORD_PAGE_HEADER; + } __attribute__((__packed__)) packed; + } __attribute__((__packed__)) header; +} __attribute__((__packed__)) RECORD_PAGE_HEADER; /* * Possible 16-bit flags for log records. (Or is it log record pages?) @@ -330,7 +330,7 @@ typedef enum { LOG_RECORD_SIZE_PLACE_HOLDER = 0xffff, /* This has nothing to do with the log record. It is only so gcc knows to make the flags 16-bit. */ -} __attribute__ ((__packed__)) LOG_RECORD_FLAGS; +} __attribute__((__packed__)) LOG_RECORD_FLAGS; /* * The log client id structure identifying a log client. @@ -338,7 +338,7 @@ typedef enum { typedef struct { u16 seq_number; u16 client_index; -} __attribute__ ((__packed__)) LOG_CLIENT_ID; +} __attribute__((__packed__)) LOG_CLIENT_ID; /* * Log record header. Each log record seems to have a constant size of 0x70 @@ -374,7 +374,7 @@ typedef struct { is not 0. */ LCN lcn; } __attribute__((__packed__)) lcn_list[0]; -} __attribute__ ((__packed__)) LOG_RECORD; +} __attribute__((__packed__)) LOG_RECORD; extern BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp); extern BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp); diff --git a/include/ntfs/logging.h b/include/ntfs/logging.h index d1165ea3..25d23409 100644 --- a/include/ntfs/logging.h +++ b/include/ntfs/logging.h @@ -22,7 +22,9 @@ #ifndef _LOGGING_H_ #define _LOGGING_H_ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDARG_H #include @@ -33,8 +35,8 @@ struct ntfs_logging; /* Function prototype for the logging handlers */ -typedef int (logging_handler) (const char *handler, const char *file, int line, - int level, FILE *stream, const char *format, va_list args); +typedef int (ntfs_logging_handler)(const char *function, const char *file, int line, + u32 level, void *data, const char *format, va_list args); /** * struct ntfs_logging - Control info for the logging system @@ -45,69 +47,72 @@ typedef int (logging_handler) (const char *handler, const char *file, int line, struct ntfs_logging { u32 levels; u32 flags; - logging_handler *handler; + ntfs_logging_handler *handler; }; extern struct ntfs_logging ntfs_log; -void ntfs_logging_set_handler (logging_handler *handler); +void ntfs_logging_set_handler(ntfs_logging_handler *handler); /* Enable/disable certain log levels */ -u32 ntfs_logging_set_levels (u32 levels); -u32 ntfs_logging_clear_levels (u32 levels); -u32 ntfs_logging_get_levels (void); +u32 ntfs_logging_set_levels(u32 levels); +u32 ntfs_logging_clear_levels(u32 levels); +u32 ntfs_logging_get_levels(void); /* Enable/disable certain log flags */ -u32 ntfs_logging_set_flags (u32 flags); -u32 ntfs_logging_clear_flags (u32 flags); -u32 ntfs_logging_get_flags (void); +u32 ntfs_logging_set_flags(u32 flags); +u32 ntfs_logging_clear_flags(u32 flags); +u32 ntfs_logging_get_flags(void); -BOOL ntfs_logging_parse_option (const char *option); +BOOL ntfs_logging_parse_option(const char *option); -int ntfs_logging_redirect (const char *handler, const char *file, int line, - int level, FILE *stream, const char *format, ...) - __attribute__ ((format (printf, 6, 7))); +int ntfs_logging_redirect(const char *function, const char *file, int line, + u32 level, void *data, const char *format, ...) + __attribute__((format(printf, 6, 7))); /* Logging handlers */ -logging_handler ntfs_logging_handler_printf __attribute__ ((format (printf, 6, 0))); -logging_handler ntfs_logging_handler_colour __attribute__ ((format (printf, 6, 0))); +ntfs_logging_handler ntfs_logging_handler_printf __attribute__((format(printf, 6, 0))); +ntfs_logging_handler ntfs_logging_handler_colour __attribute__((format(printf, 6, 0))); /* Logging levels - Determine what gets logged */ -#define LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */ -#define LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */ -#define LOG_LEVEL_QUIET (1 << 2) /* Quietable output */ -#define LOG_LEVEL_INFO (1 << 3) /* Volume needs defragmenting */ -#define LOG_LEVEL_VERBOSE (1 << 4) /* Forced to continue */ -#define LOG_LEVEL_PROGRESS (1 << 5) /* 54% complete */ -#define LOG_LEVEL_WARNING (1 << 6) /* You should backup before starting */ -#define LOG_LEVEL_ERROR (1 << 7) /* Operation failed, no damage done */ -#define LOG_LEVEL_PERROR (1 << 8) /* Message : standard error description */ -#define LOG_LEVEL_CRITICAL (1 << 9) /* Operation failed,damage may have occurred */ +#define NTFS_LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */ +#define NTFS_LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */ +#define NTFS_LOG_LEVEL_QUIET (1 << 2) /* Quietable output */ +#define NTFS_LOG_LEVEL_INFO (1 << 3) /* Volume needs defragmenting */ +#define NTFS_LOG_LEVEL_VERBOSE (1 << 4) /* Forced to continue */ +#define NTFS_LOG_LEVEL_PROGRESS (1 << 5) /* 54% complete */ +#define NTFS_LOG_LEVEL_WARNING (1 << 6) /* You should backup before starting */ +#define NTFS_LOG_LEVEL_ERROR (1 << 7) /* Operation failed, no damage done */ +#define NTFS_LOG_LEVEL_PERROR (1 << 8) /* Message : standard error description */ +#define NTFS_LOG_LEVEL_CRITICAL (1 << 9) /* Operation failed,damage may have occurred */ +#define NTFS_LOG_LEVEL_REASON (1 << 10) /* Human readable reason for failure */ /* Logging style flags - Manage the style of the output */ -#define LOG_FLAG_PREFIX (1 << 0) /* Prefix messages with "ERROR: ", etc */ -#define LOG_FLAG_FILENAME (1 << 1) /* Show the file origin of the message */ -#define LOG_FLAG_LINE (1 << 2) /* Show the line number of the message */ -#define LOG_FLAG_FUNCTION (1 << 3) /* Show the function name containing the message */ +#define NTFS_LOG_FLAG_PREFIX (1 << 0) /* Prefix messages with "ERROR: ", etc */ +#define NTFS_LOG_FLAG_FILENAME (1 << 1) /* Show the file origin of the message */ +#define NTFS_LOG_FLAG_LINE (1 << 2) /* Show the line number of the message */ +#define NTFS_LOG_FLAG_FUNCTION (1 << 3) /* Show the function name containing the message */ +#define NTFS_LOG_FLAG_ONLYNAME (1 << 4) /* Only display the filename, not the pathname */ /* Macros to simplify logging. One for each level defined above. - * Note, if DEBUG isn't defined, then log_debug has no effect. + * Note, if NTFS_DISABLE_DEBUG_LOGGING is defined, then ntfs_log_debug/trace have no effect. */ -#define log_crit(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_CRITICAL,NULL,FORMAT,##ARGS) -#define log_error(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_ERROR,NULL,FORMAT,##ARGS) -#define log_info(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_INFO,NULL,FORMAT,##ARGS) -#define log_perror(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_PERROR,NULL,FORMAT,##ARGS) -#define log_progress(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_PROGRESS,NULL,FORMAT,##ARGS) -#define log_quiet(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_QUIET,NULL,FORMAT,##ARGS) -#define log_verbose(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_VERBOSE,NULL,FORMAT,##ARGS) -#define log_warn(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_WARNING,NULL,FORMAT,##ARGS) +#define ntfs_log_critical(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_CRITICAL,NULL,FORMAT,##ARGS) +#define ntfs_log_error(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_ERROR,NULL,FORMAT,##ARGS) +#define ntfs_log_info(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_INFO,NULL,FORMAT,##ARGS) +#define ntfs_log_perror(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PERROR,NULL,FORMAT,##ARGS) +#define ntfs_log_progress(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PROGRESS,NULL,FORMAT,##ARGS) +#define ntfs_log_quiet(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_QUIET,NULL,FORMAT,##ARGS) +#define ntfs_log_verbose(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_VERBOSE,NULL,FORMAT,##ARGS) +#define ntfs_log_warning(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_WARNING,NULL,FORMAT,##ARGS) +#define ntfs_log_reason(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_REASON,NULL,FORMAT,##ARGS) #ifdef NTFS_DISABLE_DEBUG_LOGGING -#define log_debug(FORMAT, ARGS...)do {} while (0) -#define log_trace(FORMAT, ARGS...)do {} while (0) +#define ntfs_log_debug(FORMAT, ARGS...)do {} while (0) +#define ntfs_log_trace(FORMAT, ARGS...)do {} while (0) #else -#define log_debug(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_DEBUG,NULL,FORMAT,##ARGS) -#define log_trace(FORMAT, ARGS...) ntfs_logging_redirect (__FUNCTION__,__FILE__,__LINE__,LOG_LEVEL_TRACE,NULL,FORMAT,##ARGS) +#define ntfs_log_debug(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_DEBUG,NULL,FORMAT,##ARGS) +#define ntfs_log_trace(FORMAT, ARGS...) ntfs_logging_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_TRACE,NULL,FORMAT,##ARGS) #endif /* NTFS_DISABLE_DEBUG_LOGGING */ #endif /* _LOGGING_H_ */ diff --git a/include/ntfs/mft.h b/include/ntfs/mft.h index 00d2088f..4d811e79 100644 --- a/include/ntfs/mft.h +++ b/include/ntfs/mft.h @@ -116,11 +116,11 @@ extern int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni); #include "bitmap.h" #include "dir.h" -int ntfs_mft_remove_attr (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_TYPES type); -ATTR_RECORD * ntfs_mft_add_attr (ntfs_inode *inode, ATTR_TYPES type, u8 *data, int data_len); -int ntfs_mft_resize_resident (ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len, u8 *data, int data_len); -int ntfs_mft_free_space (struct ntfs_dir *dir); -int ntfs_mft_add_index (struct ntfs_dir *dir); +int ntfs_mft_remove_attr(struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_TYPES type); +ATTR_RECORD * ntfs_mft_add_attr(ntfs_inode *inode, ATTR_TYPES type, u8 *data, int data_len); +int ntfs_mft_resize_resident(ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len, u8 *data, int data_len); +int ntfs_mft_free_space(struct ntfs_dir *dir); +int ntfs_mft_add_index(struct ntfs_dir *dir); #endif /* NTFS_RICH */ diff --git a/include/ntfs/ntfstime.h b/include/ntfs/ntfstime.h index 85d8a53c..e0d1ae20 100644 --- a/include/ntfs/ntfstime.h +++ b/include/ntfs/ntfstime.h @@ -23,7 +23,9 @@ #ifndef _NTFS_NTFSTIME_H #define _NTFS_NTFSTIME_H +#ifdef HAVE_TIME_H #include +#endif #include "types.h" diff --git a/include/ntfs/rich.h b/include/ntfs/rich.h index e07451a7..48400e7e 100644 --- a/include/ntfs/rich.h +++ b/include/ntfs/rich.h @@ -1,4 +1,4 @@ -/** +/* * rich.h - Temporary junk file. Part of the Linux-NTFS project. * * Copyright (c) 2004-2005 Richard Russon @@ -40,11 +40,11 @@ #define ROUND_DOWN(num,bound) ((num) & ~((bound)-1)) #define ATTR_SIZE(s) ROUND_UP(s,8) -ATTR_RECORD * find_attribute (const ATTR_TYPES type, ntfs_attr_search_ctx *ctx); -ATTR_RECORD * find_first_attribute (const ATTR_TYPES type, MFT_RECORD *mft); -int utils_free_non_residents3 (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_RECORD *attr); -int utils_free_non_residents2 (ntfs_inode *inode, struct ntfs_bmp *bmp); -void ntfs_name_print (ntfschar *name, int name_len); +ATTR_RECORD * find_attribute(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx); +ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft); +int utils_free_non_residents3(struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_RECORD *attr); +int utils_free_non_residents2(ntfs_inode *inode, struct ntfs_bmp *bmp); +void ntfs_name_print(ntfschar *name, int name_len); #endif /* _NTFS_RICH_H_ */ diff --git a/include/ntfs/runlist.h b/include/ntfs/runlist.h index 1d48a433..d821f311 100644 --- a/include/ntfs/runlist.h +++ b/include/ntfs/runlist.h @@ -80,7 +80,7 @@ extern int ntfs_rl_sparse(runlist *rl); extern s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl); #ifdef NTFS_TEST -int test_rl_main (int argc, char *argv[]); +int test_rl_main(int argc, char *argv[]); #endif #endif /* defined _NTFS_RUNLIST_H */ diff --git a/include/ntfs/support.h b/include/ntfs/support.h index b02390bf..1c295672 100644 --- a/include/ntfs/support.h +++ b/include/ntfs/support.h @@ -26,7 +26,9 @@ #include "config.h" #endif +#ifdef HAVE_STDDEF_H #include +#endif /* * Generic macro to convert pointers to values for comparison purposes. diff --git a/include/ntfs/tree.h b/include/ntfs/tree.h index 76dda3b0..d7960663 100644 --- a/include/ntfs/tree.h +++ b/include/ntfs/tree.h @@ -1,4 +1,4 @@ -/** +/* * tree.h - Directory tree handling code. Part of the Linux-NTFS project. * * Copyright (c) 2004-2005 Richard Russon @@ -45,38 +45,38 @@ struct ntfs_dt { }; -void ntfs_dt_free (struct ntfs_dt *dt); -int ntfs_dt_rollback (struct ntfs_dt *dt); -int ntfs_dt_commit (struct ntfs_dt *dt); -BOOL ntfs_dt_create_children2 (struct ntfs_dt *dt, int count); -BOOL ntfs_dt_resize_children3 (struct ntfs_dt *dt, int new); -int ntfs_dt_root_count (struct ntfs_dt *dt); -int ntfs_dt_alloc_count (struct ntfs_dt *dt); -int ntfs_dt_initialise2 (ntfs_volume *vol, struct ntfs_dt *dt); -struct ntfs_dt * ntfs_dt_create (struct ntfs_dir *dir, struct ntfs_dt *parent, VCN vcn); -MFT_REF ntfs_dt_find (struct ntfs_dt *dt, ntfschar *name, int name_len); -struct ntfs_dt * ntfs_dt_find2 (struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num); -struct ntfs_dt * ntfs_dt_find3 (struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num); -struct ntfs_dt * ntfs_dt_find4 (struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num); -void ntfs_dt_find_all (struct ntfs_dt *dt); -int ntfs_dt_find_parent (struct ntfs_dt *dt); -BOOL ntfs_dt_isroot (struct ntfs_dt *dt); -int ntfs_dt_root_freespace (struct ntfs_dt *dt); -int ntfs_dt_alloc_freespace (struct ntfs_dt *dt); -int ntfs_dt_transfer (struct ntfs_dt *old, struct ntfs_dt *new, int start, int count); -int ntfs_dt_alloc_insert (struct ntfs_dt *dt, INDEX_ENTRY *first, int count); -INDEX_ENTRY * ntfs_dt_alloc_insert2 (struct ntfs_dt *dt, int before, int count, int bytes); -int ntfs_dt_root_insert (struct ntfs_dt *dt, INDEX_ENTRY *first, int count); -int ntfs_dt_alloc_remove2 (struct ntfs_dt *dt, int start, int count); -int ntfs_dt_root_remove2 (struct ntfs_dt *dt, int start, int count); -int ntfs_dt_transfer2 (struct ntfs_dt *old, struct ntfs_dt *new, int start, int count); -int ntfs_dt_root_replace (struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie); -BOOL ntfs_dt_alloc_replace (struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie); -BOOL ntfs_dt_root_remove (struct ntfs_dt *del, int del_num); -BOOL ntfs_dt_alloc_remove (struct ntfs_dt *del, int del_num); -int ntfs_dt_alloc_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child); -int ntfs_dt_root_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child); -int ntfs_dt_add2 (INDEX_ENTRY *ie, struct ntfs_dt *suc, int suc_num, struct ntfs_dt *ded); +void ntfs_dt_free(struct ntfs_dt *dt); +int ntfs_dt_rollback(struct ntfs_dt *dt); +int ntfs_dt_commit(struct ntfs_dt *dt); +BOOL ntfs_dt_create_children2(struct ntfs_dt *dt, int count); +BOOL ntfs_dt_resize_children3(struct ntfs_dt *dt, int new); +int ntfs_dt_root_count(struct ntfs_dt *dt); +int ntfs_dt_alloc_count(struct ntfs_dt *dt); +int ntfs_dt_initialise2(ntfs_volume *vol, struct ntfs_dt *dt); +struct ntfs_dt * ntfs_dt_create(struct ntfs_dir *dir, struct ntfs_dt *parent, VCN vcn); +MFT_REF ntfs_dt_find(struct ntfs_dt *dt, ntfschar *name, int name_len); +struct ntfs_dt * ntfs_dt_find2(struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num); +struct ntfs_dt * ntfs_dt_find3(struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num); +struct ntfs_dt * ntfs_dt_find4(struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num); +void ntfs_dt_find_all(struct ntfs_dt *dt); +int ntfs_dt_find_parent(struct ntfs_dt *dt); +BOOL ntfs_dt_isroot(struct ntfs_dt *dt); +int ntfs_dt_root_freespace(struct ntfs_dt *dt); +int ntfs_dt_alloc_freespace(struct ntfs_dt *dt); +int ntfs_dt_transfer(struct ntfs_dt *old, struct ntfs_dt *new, int start, int count); +int ntfs_dt_alloc_insert(struct ntfs_dt *dt, INDEX_ENTRY *first, int count); +INDEX_ENTRY * ntfs_dt_alloc_insert2(struct ntfs_dt *dt, int before, int count, int bytes); +int ntfs_dt_root_insert(struct ntfs_dt *dt, INDEX_ENTRY *first, int count); +int ntfs_dt_alloc_remove2(struct ntfs_dt *dt, int start, int count); +int ntfs_dt_root_remove2(struct ntfs_dt *dt, int start, int count); +int ntfs_dt_transfer2(struct ntfs_dt *old, struct ntfs_dt *new, int start, int count); +int ntfs_dt_root_replace(struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie); +BOOL ntfs_dt_alloc_replace(struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie); +BOOL ntfs_dt_root_remove(struct ntfs_dt *del, int del_num); +BOOL ntfs_dt_alloc_remove(struct ntfs_dt *del, int del_num); +int ntfs_dt_alloc_add(struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child); +int ntfs_dt_root_add(struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child); +int ntfs_dt_add2(INDEX_ENTRY *ie, struct ntfs_dt *suc, int suc_num, struct ntfs_dt *ded); #endif /* _NTFS_TREE_H_ */ diff --git a/include/ntfs/types.h b/include/ntfs/types.h index e1ebbae6..fa49fc7a 100644 --- a/include/ntfs/types.h +++ b/include/ntfs/types.h @@ -30,7 +30,9 @@ #if HAVE_STDINT_H || !HAVE_CONFIG_H #include #endif +#ifdef HAVE_SYS_TYPES_H #include +#endif typedef uint8_t u8; /* Unsigned types of an exact size */ typedef uint16_t u16; diff --git a/include/ntfs/version.h b/include/ntfs/version.h index 27e62fdd..ec6dbdca 100644 --- a/include/ntfs/version.h +++ b/include/ntfs/version.h @@ -1,4 +1,4 @@ -/** +/* * version.h - Info about the NTFS library. Part of the Linux-NTFS project. * * Copyright (c) 2005 Anton Altaparmakov diff --git a/include/ntfs/volume.h b/include/ntfs/volume.h index 17d1828c..4c428d29 100644 --- a/include/ntfs/volume.h +++ b/include/ntfs/volume.h @@ -28,15 +28,17 @@ #include "config.h" #endif +#ifdef HAVE_STDIO_H #include +#endif #ifdef HAVE_SYS_PARAM_H -# include +#include #endif #ifdef HAVE_SYS_MOUNT_H -# include +#include #endif #ifdef HAVE_MNTENT_H -# include +#include #endif /* Both under Cygwin and DJGPP we do not have MS_RDONLY, so we define it. */ @@ -206,12 +208,12 @@ extern int ntfs_volume_write_flags(ntfs_volume *v, const u16 flags); #ifdef NTFS_RICH -int ntfs_volume_commit (ntfs_volume *vol); -int ntfs_volume_rollback (ntfs_volume *vol); -int ntfs_volume_umount2 (ntfs_volume *vol, const BOOL force); -ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL force); -int utils_valid_device (const char *name, int force); -ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL force); +int ntfs_volume_commit(ntfs_volume *vol); +int ntfs_volume_rollback(ntfs_volume *vol); +int ntfs_volume_umount2(ntfs_volume *vol, const BOOL force); +ntfs_volume * ntfs_volume_mount2(const char *device, unsigned long flags, BOOL force); +int utils_valid_device(const char *name, int force); +ntfs_volume * utils_mount_volume(const char *device, unsigned long flags, BOOL force); #endif /* NTFS_RICH */ diff --git a/libntfs/attrib.c b/libntfs/attrib.c index 3a8b4d26..a4366143 100644 --- a/libntfs/attrib.c +++ b/libntfs/attrib.c @@ -1,8 +1,8 @@ -/* +/** * attrib.c - Attribute handling code. Part of the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov - * Copyright (c) 2002 Richard Russon + * Copyright (c) 2002-2005 Richard Russon * Copyright (c) 2004-2005 Yura Pakhuchiy * * This program/include file is free software; you can redistribute it and/or @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDIO_H #include @@ -37,7 +39,6 @@ #endif #include "compat.h" - #include "attrib.h" #include "attrlist.h" #include "device.h" @@ -53,6 +54,7 @@ #include "dir.h" #include "compress.h" #include "bitmap.h" +#include "logging.h" ntfschar AT_UNNAMED[] = { const_cpu_to_le16('\0') }; @@ -91,8 +93,8 @@ s64 ntfs_get_attribute_value(const ntfs_volume *vol, } /* Complex attribute? */ if (a->flags) { - Dputs("Encountered non-zero attribute flags. Cannot handle " - "this yet."); + ntfs_log_debug("Encountered non-zero attribute flags. Cannot handle " + "this yet.\n"); errno = EOPNOTSUPP; return 0; } @@ -160,8 +162,8 @@ s64 ntfs_get_attribute_value(const ntfs_volume *vol, intbuf = malloc(rl[i].length << vol->cluster_size_bits); if (!intbuf) { int eo = errno; - perror("Couldn't allocate memory for internal " - "buffer.\n"); + ntfs_log_perror("Couldn't allocate memory for " + "internal buffer."); free(rl); errno = eo; return 0; @@ -184,14 +186,14 @@ s64 ntfs_get_attribute_value(const ntfs_volume *vol, #define ESTR "Error reading attribute value" if (r == -1) { int eo = errno; - perror(ESTR); + ntfs_log_perror(ESTR); errno = eo; } else if (r < rl[i].length << vol->cluster_size_bits) { - Dputs(ESTR ": Ran out of input data."); + ntfs_log_debug(ESTR ": Ran out of input data.\n"); errno = EIO; } else { - Dputs(ESTR ": unknown error"); + ntfs_log_debug(ESTR ": unknown error\n"); errno = EIO; } #undef ESTR @@ -222,13 +224,13 @@ s64 ntfs_get_attribute_value(const ntfs_volume *vol, #define ESTR "Error reading attribute value" if (r == -1) { int eo = errno; - perror(ESTR); + ntfs_log_perror(ESTR); errno = eo; } else if (r < rl[i].length << vol->cluster_size_bits) { - Dputs(ESTR ": Ran out of input data."); + ntfs_log_debug(ESTR ": Ran out of input data.\n"); errno = EIO; } else { - Dputs(ESTR ": unknown error"); + ntfs_log_debug(ESTR ": unknown error\n"); errno = EIO; } #undef ESTR @@ -338,8 +340,8 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, int err; BOOL cs; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", __FUNCTION__, - (unsigned long long)ni->mft_no, type); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (unsigned long long)ni->mft_no, type); if (!ni || !ni->vol || !ni->mrec) { errno = EINVAL; return NULL; @@ -445,9 +447,8 @@ int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn) ntfs_attr_search_ctx *ctx; int err; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x, vcn 0x%llx.\n", - __FUNCTION__, (unsigned long long)na->ni->mft_no, - na->type, (long long)vcn); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, (long long)vcn); lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); if (lcn >= 0 || lcn == LCN_HOLE || lcn == LCN_ENOENT) @@ -498,7 +499,7 @@ int ntfs_attr_map_whole_runlist(ntfs_attr *na) ATTR_RECORD *a; int err; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", __FUNCTION__, + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long long)na->ni->mft_no, na->type); ctx = ntfs_attr_get_search_ctx(na->ni, NULL); @@ -533,10 +534,8 @@ int ntfs_attr_map_whole_runlist(ntfs_attr *na) /* Are we in the first extent? */ if (!next_vcn) { if (a->lowest_vcn) { - Dprintf("%s(): First extent of attribute " - "has non zero lowest_vcn. " - "Inode is corrupt.\n", - __FUNCTION__); + ntfs_log_trace("First extent of attribute has non " + "zero lowest_vcn. Inode is corrupt.\n"); errno = EIO; goto err_out; } @@ -557,8 +556,8 @@ int ntfs_attr_map_whole_runlist(ntfs_attr *na) /* Avoid endless loops due to corruption. */ if (next_vcn < sle64_to_cpu(a->lowest_vcn)) { - Dprintf("%s(): Inode has corrupt attribute list " - "attribute.\n", __FUNCTION__); + ntfs_log_trace("Inode has corrupt attribute list " + "attribute.\n"); errno = EIO; goto err_out; } @@ -566,20 +565,17 @@ int ntfs_attr_map_whole_runlist(ntfs_attr *na) if (!a) { err = errno; if (err == ENOENT) - Dprintf("%s(): Attribute not found. Inode is " - "corrupt.\n", __FUNCTION__); + ntfs_log_trace("Attribute not found. Inode is corrupt.\n"); else - Dprintf("%s(): Inode is corrupt.\n", __FUNCTION__); + ntfs_log_trace("Inode is corrupt.\n"); errno = err; goto err_out; } if (highest_vcn && highest_vcn != last_vcn - 1) { - Dprintf("%s(): Failed to load the complete run list for the " - "attribute. Bug or corrupt inode.\n", - __FUNCTION__); - Dprintf("%s(): highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx\n", - __FUNCTION__, (long long)highest_vcn, - (long long)last_vcn - 1); + ntfs_log_trace("Failed to load the complete run list for the " + "attribute. Bug or corrupt inode.\n"); + ntfs_log_trace("highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx\n", + (long long)highest_vcn, (long long)last_vcn - 1); errno = EIO; goto err_out; } @@ -743,10 +739,9 @@ s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b) ntfs_volume *vol; runlist_element *rl; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, " - "count 0x%llx.\n", __FUNCTION__, - (unsigned long long)na->ni->mft_no, na->type, - (long long)pos, (long long)count); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, count " + "0x%llx.\n", (unsigned long long)na->ni->mft_no, + na->type, (long long)pos, (long long)count); if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { errno = EINVAL; return -1; @@ -861,9 +856,8 @@ res_err_out: to_read = min(count, (rl->length << vol->cluster_size_bits) - ofs); retry: - Dprintf("%s(): Reading 0x%llx bytes from vcn 0x%llx, " - "lcn 0x%llx, ofs 0x%llx.\n", __FUNCTION__, - to_read, rl->vcn, rl->lcn, ofs); + ntfs_log_trace("Reading 0x%llx bytes from vcn 0x%llx, lcn 0x%llx, " + "ofs 0x%llx.\n", to_read, rl->vcn, rl->lcn, ofs); br = ntfs_pread(vol->dev, (rl->lcn << vol->cluster_size_bits) + ofs, to_read, b); /* If everything ok, update progress counters and continue. */ @@ -923,9 +917,9 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) unsigned int update_mapping_pairs : 1; } need_to = { 0, 0, 0 }; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, " - "count 0x%llx.\n", __FUNCTION__, na->ni->mft_no, - na->type, (long long)pos, (long long)count); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, count " + "0x%llx.\n", na->ni->mft_no, na->type, (long long)pos, + (long long)count); if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { errno = EINVAL; return -1; @@ -954,8 +948,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) if (pos + count > na->data_size) { if (ntfs_attr_truncate(na, pos + count)) { eo = errno; - Dprintf("%s(): Attribute extend failed.\n", - __FUNCTION__); + ntfs_log_trace("Attribute extend failed.\n"); errno = eo; return -1; } @@ -1026,8 +1019,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) buf = malloc(NTFS_BUF_SIZE); if (!buf) { err = errno; - Dprintf("%s(): Not enough memory.\n", - __FUNCTION__); + ntfs_log_trace("Not enough memory.\n"); errno = err; goto err_out; } @@ -1039,9 +1031,8 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) to_write, buf); if (written <= 0) { err = errno; - Dprintf("%s(): Failed to zero space " - "between initialized size and " - "@pos.\n", __FUNCTION__); + ntfs_log_trace("Failed to zero space between " + "initialized size and @pos.\n"); free(buf); errno = err; goto err_out; @@ -1147,8 +1138,8 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) /* The buffer is non zero, instantiate the hole. */ cur_vcn = rl->vcn; from_vcn = rl->vcn + (ofs >> vol->cluster_size_bits); - Dprintf("%s(): Instantiate the hole with vcn 0x%llx.\n", - __FUNCTION__, cur_vcn); + ntfs_log_trace("Instantiate the hole with vcn 0x%llx.\n", + cur_vcn); /* * Search backwards to find the best lcn to start * seek from. @@ -1182,8 +1173,8 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) lcn_seek_from, DATA_ZONE); if (!rlc) { eo = errno; - Dprintf("%s(): Failed to allocate clusters for " - "hole instantiating.\n", __FUNCTION__); + ntfs_log_trace("Failed to allocate clusters for hole " + "instantiating.\n"); errno = eo; goto err_out; } @@ -1191,13 +1182,11 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) rl = ntfs_runlists_merge(na->rl, rlc); if (!rl) { eo = errno; - Dprintf("%s(): Failed to merge runlists.\n", - __FUNCTION__); + ntfs_log_trace("Failed to merge runlists.\n"); if (ntfs_cluster_free_from_rl(vol, rlc)) { - Dprintf("%s(): Failed to free just " + ntfs_log_trace("Failed to free just " "allocated clusters. Leaving " - "inconstant metadata. " - "Run chkdsk", __FUNCTION__); + "inconstant metadata. Run chkdsk"); } errno = eo; goto err_out; @@ -1211,10 +1200,9 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) * @cur_vcn, because we missed it during * instantiating of the hole. */ - Dprintf("%s(): BUG! Failed to find run after " - "instantiating. Please report to the " - "linux-ntfs-dev@lists.sf.net.\n", - __FUNCTION__); + ntfs_log_trace("BUG! Failed to find run after " + "instantiating. Please report " + "to the linux-ntfs-dev@lists.sf.net.\n"); errno = EIO; goto err_out; } @@ -1223,10 +1211,9 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) rl++; /* Now LCN shoudn't be less than 0. */ if (rl->lcn < 0) { - Dprintf("%s(): BUG! LCN is lesser than 0. " - "Please report to the " - "linux-ntfs-dev@lists.sf.net." - "\n", __FUNCTION__); + ntfs_log_trace("BUG! LCN is lesser than 0. Please " + "report to the " + "linux-ntfs-dev@lists.sf.net.\n"); errno = EIO; goto err_out; } @@ -1239,9 +1226,8 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) buf = malloc(ofs); if (!buf) { - Dprintf("%s(): Not enough memory to " - "allocate %lld bytes.\n", - __FUNCTION__, ofs); + ntfs_log_trace("Not enough memory to " + "allocate %lld bytes.\n", ofs); errno = ENOMEM; goto err_out; } @@ -1250,8 +1236,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) vol->cluster_size_bits, ofs, buf) < 0) { eo = errno; - Dprintf("%s(): Failed to zero area.\n", - __FUNCTION__); + ntfs_log_trace("Failed to zero area.\n"); free(buf); errno = eo; goto err_out; @@ -1279,9 +1264,8 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) to_write = min(count, (rl->length << vol->cluster_size_bits) - ofs); retry: - Dprintf("%s(): Writing 0x%llx bytes to vcn 0x%llx, lcn 0x%llx, " - "ofs 0x%llx.\n", __FUNCTION__, to_write, - rl->vcn, rl->lcn, ofs); + ntfs_log_trace("Writing 0x%llx bytes to vcn 0x%llx, lcn 0x%llx, ofs " + "0x%llx.\n", to_write, rl->vcn, rl->lcn, ofs); if (!NVolReadOnly(vol)) written = ntfs_pwrite(vol->dev, (rl->lcn << vol->cluster_size_bits) + ofs, @@ -1349,9 +1333,8 @@ err_out: } } if (err) { - Dputs("Eeek! Failed to recover from error. Leaving " - "metadata in inconsistent state! Run " - "chkdsk!"); + ntfs_log_debug("Eeek! Failed to recover from error. Leaving " + "metadata in inconsistent state! Run chkdsk!\n"); // FIXME: At this stage could try to recover by filling // old_initialized_size -> new_initialized_size with // data or at least zeroes. (AIA) @@ -1364,7 +1347,7 @@ err_out: ntfs_attr_update_mapping_pairs(na); /* Restore original data_size if needed. */ if (need_to.undo_data_size && ntfs_attr_truncate(na, old_data_size)) - Dprintf("%s(): Failed to restore data_size.\n", __FUNCTION__); + ntfs_log_trace("Failed to restore data_size.\n"); errno = eo; return -1; } @@ -1404,9 +1387,9 @@ s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt, s64 br; u8 *end; - Dprintf("%s(): Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", - __FUNCTION__, (unsigned long long)na->ni->mft_no, - na->type, (long long)pos); + ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; return -1; @@ -1456,9 +1439,9 @@ s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt, { s64 written, i; - Dprintf("%s(): Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", - __FUNCTION__, (unsigned long long)na->ni->mft_no, - na->type, (long long)pos); + ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; return -1; @@ -1689,7 +1672,7 @@ static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, } } } - Dputs("ntfs_attr_find(): File is corrupt. Run chkdsk."); + ntfs_log_debug("ntfs_attr_find(): File is corrupt. Run chkdsk.\n"); errno = EIO; return -1; } @@ -1782,8 +1765,8 @@ static int ntfs_external_attr_find(ATTR_TYPES type, const ntfschar *name, ni = ctx->ntfs_ino; base_ni = ctx->base_ntfs_ino; - Dprintf("%s(): Entering for inode 0x%llx, attribute type 0x%x.\n", - __FUNCTION__, (unsigned long long)ni->mft_no, type); + ntfs_log_trace("Entering for inode 0x%llx, attribute type 0x%x.\n", + (unsigned long long)ni->mft_no, type); if (!base_ni) { /* First call happens with the base mft record. */ base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino; @@ -1866,9 +1849,8 @@ find_attr_list_attr: return rc; /* Not found?!? Absurd! Must be a bug... )-: */ - Dprintf("%s(): BUG! Attribute list attribute not found " - "but it exists! Returning error " - "(EINVAL).\n", __FUNCTION__); + ntfs_log_trace("BUG! Attribute list attribute not found but " + "it exists! Returning error (EINVAL).\n"); errno = EINVAL; return -1; } @@ -1970,8 +1952,8 @@ is_enumeration: if (MSEQNO_LE(al_entry->mft_reference) != le16_to_cpu( ni->mrec->sequence_number)) { - Dputs("Found stale mft reference in attribute " - "list!"); + ntfs_log_debug("Found stale mft reference in " + "attribute list!\n"); break; } } else { /* Mft references do not match. */ @@ -1985,7 +1967,7 @@ is_enumeration: ni = ntfs_extent_inode_open(base_ni, al_entry->mft_reference); if (!ni) { - Dperror("Failed to map extent inode"); + ntfs_log_perror("Failed to map extent inode"); break; } ctx->ntfs_ino = ni; @@ -2059,7 +2041,7 @@ do_next_attr: ctx->mrec = ctx->base_mrec; ctx->attr = ctx->base_attr; } - Dputs("Inode is corrupt."); + ntfs_log_debug("Inode is corrupt.\n"); errno = EIO; return -1; not_found: @@ -2296,7 +2278,6 @@ ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec) void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx) { free(ctx); - return; } /** @@ -2470,8 +2451,8 @@ int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size) { u32 biu; - Dprintf("%s(): Entering for pos 0x%d, size %u.\n", - __FUNCTION__, (int)(pos - (u8*)m), (unsigned) size); + ntfs_log_trace("Entering for pos 0x%d, size %u.\n", + (int)(pos - (u8*)m), (unsigned) size); /* Make size 8-byte alignment. */ size = (size + 7) & ~7; @@ -2532,9 +2513,8 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, int err, offset; ntfs_inode *base_ni; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n", - __FUNCTION__, (long long) ni->mft_no, (unsigned) type, - (unsigned) flags); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n", + (long long) ni->mft_no, (unsigned) type, (unsigned) flags); if (!ni || (!name && name_len)) { errno = EINVAL; @@ -2544,11 +2524,9 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (ntfs_attr_can_be_resident(ni->vol, type)) { err = errno; if (errno == EPERM) - Dprintf("%s(): Attribute can't be resident.\n", - __FUNCTION__); + ntfs_log_trace("Attribute can't be resident.\n"); else - Dprintf("%s(): ntfs_attr_can_be_resident failed.\n", - __FUNCTION__); + ntfs_log_trace("ntfs_attr_can_be_resident failed.\n"); errno = err; return -1; } @@ -2565,7 +2543,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, val, size, ctx)) { err = EEXIST; - Dprintf("%s(): Attribute already present.\n", __FUNCTION__); + ntfs_log_trace("Attribute already present.\n"); goto put_err_out; } if (errno != ENOENT) { @@ -2581,8 +2559,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ((size + 7) & ~7); if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { err = errno; - Dprintf("%s(): Failed to make room for attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to make room for attribute.\n"); goto put_err_out; } @@ -2618,8 +2595,8 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (ntfs_attrlist_entry_add(ni, a)) { err = errno; ntfs_attr_record_resize(m, a, 0); - Dprintf("%s(): Failed add attribute entry to " - "ATTRIBUTE_LIST.\n", __FUNCTION__); + ntfs_log_trace("Failed add attribute entry to " + "ATTRIBUTE_LIST.\n"); goto put_err_out; } } @@ -2661,10 +2638,10 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ntfs_inode *base_ni; int err, offset; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, " - "dataruns_size %d, flags 0x%x.\n", __FUNCTION__, - (long long) ni->mft_no, (unsigned) type, (long long) lowest_vcn, - dataruns_size, (unsigned) flags); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, " + "dataruns_size %d, flags 0x%x.\n", + (long long) ni->mft_no, (unsigned) type, + (long long) lowest_vcn, dataruns_size, (unsigned) flags); if (!ni || dataruns_size <= 0 || (!name && name_len)) { errno = EINVAL; @@ -2674,11 +2651,9 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (ntfs_attr_can_be_non_resident(ni->vol, type)) { err = errno; if (errno == EPERM) - Dprintf("%s(): Attribute can't be non resident.\n", - __FUNCTION__); + ntfs_log_trace("Attribute can't be non resident.\n"); else - Dprintf("%s(): ntfs_attr_can_be_non_resident failed.\n", - __FUNCTION__); + ntfs_log_trace("ntfs_attr_can_be_non_resident failed.\n"); errno = err; return -1; } @@ -2695,7 +2670,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, NULL, 0, ctx)) { err = EEXIST; - Dprintf("%s(): Attribute already present.\n", __FUNCTION__); + ntfs_log_trace("Attribute already present.\n"); goto put_err_out; } if (errno != ENOENT) { @@ -2713,8 +2688,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, sizeof(a->compressed_size) : 0); if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { err = errno; - Dprintf("%s(): Failed to make room for attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to make room for attribute.\n"); goto put_err_out; } @@ -2753,8 +2727,8 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (ntfs_attrlist_entry_add(ni, a)) { err = errno; ntfs_attr_record_resize(m, a, 0); - Dprintf("%s(): Failed add attribute entry to " - "ATTRIBUTE_LIST.\n", __FUNCTION__); + ntfs_log_trace("Failed add attribute entry to " + "ATTRIBUTE_LIST.\n"); goto put_err_out; } } @@ -2768,8 +2742,8 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, lowest_vcn, NULL, 0, ctx)) { err = errno; - Dprintf("%s(): Attribute lookup failed. Probably leaving " - "inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed. Probably leaving inconstant " + "metadata.\n"); ntfs_attr_put_search_ctx(ctx); errno = err; return -1; @@ -2807,9 +2781,9 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) return -1; } - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", - __FUNCTION__, (long long) ctx->ntfs_ino->mft_no, - (unsigned) le32_to_cpu(ctx->attr->type)); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) ctx->ntfs_ino->mft_no, + (unsigned) le32_to_cpu(ctx->attr->type)); type = ctx->attr->type; ni = ctx->ntfs_ino; if (ctx->base_ntfs_ino) @@ -2819,12 +2793,12 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) /* Remove attribute itself. */ if (ntfs_attr_record_resize(ctx->mrec, ctx->attr, 0)) { - Dprintf("%s(): Couldn't remove attribute record. Bug or " - "damaged MFT record.\n", __FUNCTION__); + ntfs_log_trace("Couldn't remove attribute record. Bug or damaged MFT " + "record.\n"); if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) if (ntfs_attrlist_entry_add(ni, ctx->attr)) - Dprintf("%s(): Rollback failed. Leaving " - "inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Rollback failed. Leaving inconstant " + "metadata.\n"); err = EIO; return -1; } @@ -2837,8 +2811,8 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) { if (ntfs_attrlist_entry_rm(ctx)) { err = errno; - Dprintf("%s(): Couldn't delete record from " - "$ATTRIBUTE_LIST.\n", __FUNCTION__); + ntfs_log_trace("Couldn't delete record from " + "$ATTRIBUTE_LIST.\n"); errno = err; return -1; } @@ -2858,8 +2832,7 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) le16_to_cpu(ctx->mrec->attrs_offset) == 8) { if (ntfs_mft_record_free(ni->vol, ni)) { // FIXME: We need rollback here. - Dprintf("%s(): Couldn't free MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't free MFT record.\n"); errno = EIO; return -1; } @@ -2881,8 +2854,8 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) * goes wrong because NInoAttrList(base_ni) returned * that we have got attribute list. */ - Dprintf("%s(): Couldn't find attribute list. Succeed " - "anyway.\n", __FUNCTION__); + ntfs_log_trace("Couldn't find attribute list. Succeed " + "anyway.\n"); return 0; } /* Deallocate clusters. */ @@ -2892,16 +2865,14 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) al_rl = ntfs_mapping_pairs_decompress(base_ni->vol, ctx->attr, NULL); if (!al_rl) { - Dprintf("%s(): Couldn't decompress attribute " - "list runlist. Succeed anyway.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't decompress attribute list " + "runlist. Succeed anyway.\n"); return 0; } if (ntfs_cluster_free_from_rl(base_ni->vol, al_rl)) { - Dprintf("%s(): Leaking clusters! Run chkdsk. " - "Couldn't free clusters from attribute " - "list runlist.\n", - __FUNCTION__); + ntfs_log_trace("Leaking clusters! Run chkdsk. " + "Couldn't free clusters from " + "attribute list runlist.\n"); } free(al_rl); } @@ -2912,8 +2883,8 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) * complain if it find MFT record with attribute list, * but without extents. */ - Dprintf("%s(): Couldn't remove attribute list. Succeed " - "anyway.\n", __FUNCTION__); + ntfs_log_trace("Couldn't remove attribute list. Succeed " + "anyway.\n"); return 0; } } @@ -2956,13 +2927,13 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, ntfs_attr *na; if (!ni || size < 0 || type == AT_ATTRIBUTE_LIST) { - Dprintf("%s(): Invalid arguments passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for inode 0x%llx, attr %x, size %lld.\n", - __FUNCTION__, (long long) ni->mft_no, type, size); + ntfs_log_trace("Entering for inode 0x%llx, attr %x, size %lld.\n", + (long long) ni->mft_no, type, size); if (ni->nr_extents == -1) ni = ni->base_ni; @@ -2971,11 +2942,9 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, if (ntfs_attr_size_bounds_check(ni->vol, type, size)) { err = errno; if (err == ERANGE) { - Dprintf("%s(): Size bounds check failed. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Size bounds check failed. Aborting...\n"); } else if (err == ENOENT) { - Dprintf("%s(): Invalid attribute type. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Invalid attribute type. Aborting...\n"); err = EIO; } errno = err; @@ -2986,19 +2955,18 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, if (ntfs_attr_can_be_non_resident(ni->vol, type)) { if (errno != EPERM) { err = errno; - Dprintf("%s(): ntfs_attr_can_be_non_resident failed.\n", - __FUNCTION__); + ntfs_log_trace("ntfs_attr_can_be_non_resident failed.\n"); goto err_out; } /* @val is mandatory. */ if (!val) { - Dprintf("%s(): @val is mandatory for always resident " - "atributes.\n", __FUNCTION__); + ntfs_log_trace("val is mandatory for always resident " + "atributes.\n"); errno = EINVAL; return -1; } if (size > ni->vol->mft_record_size) { - Dprintf("%s(): Attribute is too big.\n", __FUNCTION__); + ntfs_log_trace("Attribute is too big.\n"); errno = ERANGE; return -1; } @@ -3020,8 +2988,7 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, } else { if (errno != EPERM) { err = errno; - Dprintf("%s(): ntfs_attr_can_be_resident failed.\n", - __FUNCTION__); + ntfs_log_trace("ntfs_attr_can_be_resident failed.\n"); goto err_out; } /* Attribute can't be resident. */ @@ -3049,8 +3016,7 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, /* Try to add to extent inodes. */ if (ntfs_inode_attach_all_extents(ni)) { err = errno; - Dprintf("%s(): Failed to attach all extents to inode.\n", - __FUNCTION__); + ntfs_log_trace("Failed to attach all extents to inode.\n"); goto err_out; } for (i = 0; i < ni->nr_extents; i++) { @@ -3066,8 +3032,7 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, /* Add attribute list not present, add it and retry. */ if (ntfs_inode_add_attrlist(ni)) { err = errno; - Dprintf("%s(): Failed to add attribute list.\n", - __FUNCTION__); + ntfs_log_trace("Failed to add attribute list.\n"); goto err_out; } return ntfs_attr_add(ni, type, name, name_len, val, size); @@ -3076,8 +3041,7 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, attr_ni = ntfs_mft_record_alloc(ni->vol, ni); if (!attr_ni) { err = errno; - Dprintf("%s(): Failed to allocate extent record.\n", - __FUNCTION__); + ntfs_log_trace("Failed to allocate extent record.\n"); goto err_out; } @@ -3088,8 +3052,7 @@ add_attr_record: name_len, val, size, 0); if (offset < 0) { err = errno; - Dprintf("%s(): Failed to add resident attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to add resident attribute.\n"); goto free_err_out; } return 0; @@ -3100,8 +3063,7 @@ add_attr_record: name_len, 0, 8, 0); if (offset < 0) { err = errno; - Dprintf("%s(): Failed to add non resident attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to add non resident attribute.\n"); goto free_err_out; } @@ -3113,20 +3075,17 @@ add_attr_record: na = ntfs_attr_open(ni, type, name, name_len); if (!na) { err = errno; - Dprintf("%s(): Failed to open just added attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to open just added attribute.\n"); goto rm_attr_err_out; } /* Resize and set attribute value. */ if (ntfs_attr_truncate(na, size) || (val && (ntfs_attr_pwrite(na, 0, size, val) != size))) { err = errno; - Dprintf("%s(): Failed to initialize just added attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to initialize just added attribute.\n"); if (ntfs_attr_rm(na)) { - Dprintf("%s(): Failed to remove just added attribute. " - "Probably leaving inconstant metadata.\n", - __FUNCTION__); + ntfs_log_trace("Failed to remove just added attribute. " + "Probably leaving inconstant metadata.\n"); ntfs_attr_close(na); } goto err_out; @@ -3139,16 +3098,15 @@ rm_attr_err_out: /* Remove just added attribute. */ if (ntfs_attr_record_resize(attr_ni->mrec, (ATTR_RECORD*)((u8*)attr_ni->mrec + offset), 0)) { - Dprintf("%s(): Failed to remove just added attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to remove just added attribute.\n"); } 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) { if (ntfs_mft_record_free(attr_ni->vol, attr_ni)) { - Dprintf("%s(): Failed to free MFT record. Leaving " - "inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Failed to free MFT record. Leaving " + "inconstant metadata.\n"); } } err_out: @@ -3171,21 +3129,21 @@ int ntfs_attr_rm(ntfs_attr *na) int ret = 0; if (!na) { - Dprintf("%s(): Invalid arguments passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", - __FUNCTION__, (long long) na->ni->mft_no, na->type); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) na->ni->mft_no, na->type); /* Free cluster allocation. */ if (NAttrNonResident(na)) { if (ntfs_attr_map_whole_runlist(na)) return -1; if (ntfs_cluster_free(na->ni->vol, na, 0, -1) < 0) { - Dprintf("%s(): Failed to free cluster allocation. " - "Leaving inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Failed to free cluster allocation. Leaving " + "inconstant metadata.\n"); ret = -1; } } @@ -3197,15 +3155,15 @@ int ntfs_attr_rm(ntfs_attr *na) while (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (ntfs_attr_record_rm(ctx)) { - Dprintf("%s(): Failed to remove attribute extent. " - "Leaving inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Failed to remove attribute extent. Leaving " + "inconstant metadata.\n"); ret = -1; } ntfs_attr_reinit_search_ctx(ctx); } if (errno != ENOENT) { - Dprintf("%s(): Attribute lookup failed. Probably leaving " - "inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed. Probably leaving inconstant " + "metadata.\n"); ret = -1; } @@ -3234,8 +3192,7 @@ int ntfs_attr_rm(ntfs_attr *na) */ int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size) { - Dprintf("%s(): Entering for new_size %u.\n", - __FUNCTION__, (unsigned) new_size); + ntfs_log_trace("Entering for new_size %u.\n", (unsigned) new_size); /* Align to 8 bytes, just in case the caller hasn't. */ new_size = (new_size + 7) & ~7; /* If the actual attribute length has changed, move things around. */ @@ -3283,9 +3240,8 @@ int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a, */ if (a->name_length && le16_to_cpu(a->name_offset) >= le16_to_cpu(a->value_offset)) { - Dprintf("%s(): Eeek! Name is placed after the " - "attribute value. Corrupted inode. Run chkdsk. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Name is placed after the attribute value. " + "Corrupted inode. Run chkdsk. Aborting...\n"); errno = EIO; return -1; } @@ -3294,8 +3250,8 @@ int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a, new_size + 7) & ~7) < 0) { if (errno != ENOSPC) { int eo = errno; - Dprintf("%s(): Eeek! Attribute record resize failed. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Attribute record resize failed. " + "Aborting...\n"); errno = eo; } return -1; @@ -3330,22 +3286,23 @@ int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) int err; if (!ctx || !ctx->attr || !ctx->ntfs_ino || !ni) { - Dprintf("%s(): Invalid arguments passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for ctx->attr->type 0x%x, ctx->ntfs_ino->mft_no" - " 0x%llx, ni->mft_no 0x%llx.\n", __FUNCTION__, (unsigned) - le32_to_cpu(ctx->attr->type), (long long) ctx->ntfs_ino->mft_no, - (long long) ni->mft_no); + ntfs_log_trace("Entering for ctx->attr->type 0x%x, ctx->ntfs_ino->mft_no " + "0x%llx, ni->mft_no 0x%llx.\n", + (unsigned) le32_to_cpu(ctx->attr->type), + (long long) ctx->ntfs_ino->mft_no, + (long long) ni->mft_no); if (ctx->ntfs_ino == ni) return 0; if (!ctx->al_entry) { - Dprintf("%s(): Inode should contain attribute list to use " - "this function.\n", __FUNCTION__); + ntfs_log_trace("Inode should contain attribute list to use this " + "function.\n"); errno = EINVAL; return -1; } @@ -3355,8 +3312,7 @@ int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) nctx = ntfs_attr_get_search_ctx(ni, NULL); if (!nctx) { err = errno; - Dprintf("%s(): Couldn't obtain search context.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't obtain search context.\n"); errno = err; return -1; } @@ -3368,14 +3324,14 @@ int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) if (!ntfs_attr_find(a->type, (ntfschar*)((u8*)a + le16_to_cpu( a->name_offset)), a->name_length, CASE_SENSITIVE, NULL, 0, nctx)) { - Dprintf("%s(): Attribute of such type, with same name already " - "present in this MFT record.\n", __FUNCTION__); + ntfs_log_trace("Attribute of such type, with same name already " + "present in this MFT record.\n"); err = EEXIST; goto put_err_out; } if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", __FUNCTION__); + ntfs_log_debug("Attribute lookup failed.\n"); goto put_err_out; } @@ -3383,8 +3339,7 @@ int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) if (ntfs_make_room_for_attr(ni->mrec, (u8*) nctx->attr, le32_to_cpu(a->length))) { err = errno; - Dprintf("%s(): Couldn't make space for attribute.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't make space for attribute.\n"); goto put_err_out; } memcpy(nctx->attr, a, le32_to_cpu(a->length)); @@ -3429,12 +3384,12 @@ int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra) int i, err; if (!ctx || !ctx->attr || !ctx->ntfs_ino || extra < 0) { - Dprintf("%s(): Invalid arguments passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for attr 0x%x, inode 0x%llx.\n", __FUNCTION__, + ntfs_log_trace("Entering for attr 0x%x, inode 0x%llx.\n", (unsigned) le32_to_cpu(ctx->attr->type), (long long) ctx->ntfs_ino->mft_no); @@ -3444,15 +3399,15 @@ int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra) base_ni = ctx->ntfs_ino; if (!NInoAttrList(base_ni)) { - Dprintf("%s(): Inode should contain attribute list to use " - "this function.\n", __FUNCTION__); + ntfs_log_trace("Inode should contain attribute list to use this " + "function.\n"); errno = EINVAL; return -1; } if (ntfs_inode_attach_all_extents(ctx->ntfs_ino)) { err = errno; - Dprintf("%s(): Couldn't attach extent inode.\n", __FUNCTION__); + ntfs_log_trace("Couldn't attach extent inode.\n"); errno = err; return -1; } @@ -3486,15 +3441,13 @@ int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra) ni = ntfs_mft_record_alloc(base_ni->vol, base_ni); if (!ni) { err = errno; - Dprintf("%s(): Couldn't allocate new MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't allocate new MFT record.\n"); errno = err; return -1; } if (ntfs_attr_record_move_to(ctx, ni)) { err = errno; - Dprintf("%s(): Couldn't move attribute to new MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't move attribute to new MFT record.\n"); errno = err; return -1; } @@ -3531,8 +3484,8 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, /* Some preliminary sanity checking. */ if (NAttrNonResident(na)) { - Dprintf("%s(): Eeek! Trying to make non-resident attribute " - "non-resident. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Trying to make non-resident attribute " + "non-resident. Aborting...\n"); errno = EINVAL; return -1; } @@ -3547,9 +3500,8 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, */ if (a->name_length && le16_to_cpu(a->name_offset) >= le16_to_cpu(a->value_offset)) { - Dprintf("%s(): Eeek! Name is placed after the " - "attribute value. Corrupted inode. Run chkdsk. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Name is placed after the attribute value. " + "Corrupted inode. Run chkdsk. Aborting...\n"); errno = EIO; return -1; } @@ -3565,9 +3517,8 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, if (errno != ENOSPC) { int eo = errno; - Dprintf("%s(): Eeek! Failed to allocate " - "cluster(s). Aborting...\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Failed to allocate " + "cluster(s). Aborting...\n"); errno = eo; } return -1; @@ -3596,7 +3547,7 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, (u8*)a + le16_to_cpu(a->value_offset)); if (bw != le32_to_cpu(a->value_length)) { err = errno; - Dprintf("Eeek! Failed to write out attribute value " + ntfs_log_debug("Eeek! Failed to write out attribute value " "(bw = %lli, errno = %i). " "Aborting...\n", (long long)bw, err); if (bw >= 0) @@ -3608,8 +3559,8 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, mp_size = ntfs_get_size_for_mapping_pairs(vol, rl, 0); if (mp_size < 0) { err = errno; - Dputs("Eeek! Failed to get size for mapping pairs array. " - "Aborting..."); + ntfs_log_debug("Eeek! Failed to get size for mapping pairs array. " + "Aborting...\n"); goto cluster_free_err_out; } /* Calculate new offsets for the name and the mapping pairs array. */ @@ -3626,8 +3577,8 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, if (ntfs_attr_record_resize(ctx->mrec, a, arec_size) < 0) { err = errno; if (err != ENOSPC) { - Dprintf("%s(): Eeek! Failed to resize attribute " - "record. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Failed to resize attribute record. " + "Aborting...\n"); } goto cluster_free_err_out; } @@ -3667,11 +3618,10 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, rl, 0, NULL) < 0) { err = errno; // FIXME: Eeek! We need rollback! (AIA) - Dprintf("%s(): Eeek! Failed to build mapping pairs. Leaving " - "corrupt attribute record on disk. " - "In memory runlist is still intact! Error " - "code is %i. FIXME: Need to rollback " - "instead!\n", __FUNCTION__, err); + ntfs_log_trace("Eeek! Failed to build mapping pairs. Leaving " + "corrupt attribute record on disk. In memory " + "runlist is still intact! Error code is %i. " + "FIXME: Need to rollback instead!\n", err); errno = err; return -1; } @@ -3681,14 +3631,12 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na, cluster_free_err_out: if (rl && ntfs_cluster_free(vol, na, 0, -1) < 0) - Dprintf("%s(): Eeek! Failed to release allocated " - "clusters in error code path. Leaving " - "inconsistent metadata...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Failed to release allocated clusters in error " + "code path. Leaving inconsistent metadata...\n"); NAttrClearNonResident(na); na->allocated_size = na->data_size; na->rl = NULL; - if (rl) - free(rl); + free(rl); errno = err; return -1; } @@ -3702,9 +3650,9 @@ cluster_free_err_out: * * On success return 0 and on error return -1 with errno set to the error code. * The following error codes are defined: - * ENOMEM - Not enough memory to complete operation. - * ERANGE - @newsize is not valid for the attribute type of @na. - * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. */ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) { @@ -3713,8 +3661,8 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) ntfs_inode *ni; int err; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", __FUNCTION__, - (unsigned long long)na->ni->mft_no, na->type); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); /* Get the attribute record that needs modification. */ ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) @@ -3732,8 +3680,8 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { err = errno; if (err == ERANGE) { - Dprintf("%s(): Eeek! Size bounds check failed. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Size bounds check failed. " + "Aborting...\n"); } else if (err == ENOENT) err = EIO; goto put_err_out; @@ -3757,8 +3705,8 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) /* Error! If not enough space, just continue. */ if (errno != ENOSPC) { err = errno; - Dprintf("%s(): Eeek! Failed to resize resident part " - "of attribute. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Failed to resize resident part of " + "attribute. Aborting...\n"); goto put_err_out; } } @@ -3772,8 +3720,8 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) return ntfs_attr_truncate(na, newsize); } else if (errno != ENOSPC && errno != EPERM) { err = errno; - Dprintf("%s(): Eeek! Failed to make attribute non-resident. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Failed to make attribute non-resident. " + "Aborting...\n"); goto put_err_out; } @@ -3800,8 +3748,7 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) le16_to_cpu(a->name_offset)), a->name_length); if (!tna) { err = errno; - Dprintf("%s(): Couldn't open attribute.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't open attribute.\n"); goto put_err_out; } if (ntfs_attr_make_non_resident(tna, ctx)) { @@ -3816,7 +3763,7 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) /* Check whether error occurred. */ if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); goto put_err_out; } @@ -3826,9 +3773,8 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) if (ntfs_inode_free_space(na->ni, offsetof(ATTR_RECORD, non_resident_end) + 8)) { err = errno; - Dprintf("%s(): Couldn't free space in the MFT record " - "to make attribute list non resident.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't free space in the MFT record to " + "make attribute list non resident.\n"); errno = err; return -1; } @@ -3844,7 +3790,7 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) ntfs_attr_init_search_ctx(ctx, na->ni, NULL); if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { - Dprintf("%s(): Attribute lookup failed.\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); err = errno; goto put_err_out; } @@ -3875,15 +3821,13 @@ static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) ni = ntfs_mft_record_alloc(vol, ni); if (!ni) { err = errno; - Dprintf("%s(): Couldn't allocate new MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't allocate new MFT record.\n"); goto put_err_out; } /* Move attribute to it. */ if (ntfs_attr_record_move_to(ctx, ni)) { err = errno; - Dprintf("%s(): Couldn't move attribute to new MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't move attribute to new MFT record.\n"); goto put_err_out; } /* Update ntfs attribute. */ @@ -3937,16 +3881,16 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) /* Should be called for the first extent of the attribute. */ if (sle64_to_cpu(a->lowest_vcn)) { - Dprintf("%s(): Eeek! Should be called for the first extent " - "of the attribute. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Should be called for the first extent of the " + "attribute. Aborting...\n"); err = EINVAL; return -1; } /* Some preliminary sanity checking. */ if (!NAttrNonResident(na)) { - Dprintf("%s(): Eeek! Trying to make resident attribute " - "resident. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Trying to make resident attribute resident. " + "Aborting...\n"); errno = EINVAL; return -1; } @@ -3967,17 +3911,15 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) */ if (a->name_length && le16_to_cpu(a->name_offset) >= le16_to_cpu(a->mapping_pairs_offset)) { - Dprintf("%s(): Eeek! Damaged attribute. Name is placed after " - "the mapping pairs array. Run chkdsk. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Damaged attribute. Name is placed after the " + "mapping pairs array. Run chkdsk. Aborting...\n"); errno = EIO; return -1; } if (NAttrCompressed(na) || NAttrEncrypted(na)) { - Dprintf("%s(): Making compressed or encrypted files " - "resident is not implemented yet.\n", - __FUNCTION__); + ntfs_log_trace("Making compressed or encrypted files resident is not " + "implemented yet.\n"); errno = EOPNOTSUPP; return -1; } @@ -4011,9 +3953,9 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) * Bug, because ntfs_attr_record_resize should not fail (we * already checked that attribute fits MFT record). */ - Dprintf("%s(): BUG! Failed to resize attribute record. " - "Please report to the linux-ntfs-dev@lists.sf.net. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("BUG! Failed to resize attribute record. Please " + "report to the linux-ntfs-dev@lists.sf.net. " + "Aborting...\n"); errno = EIO; return -1; } @@ -4044,9 +3986,9 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) if (bytes_read != na->initialized_size) { if (bytes_read < 0) err = errno; - Dprintf("%s(): Eeek! Failed to read attribute data. " - "Leaving inconstant metadata. Run chkdsk. " - "Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Failed to read attribute data. Leaving " + "inconstant metadata. Run chkdsk. " + "Aborting...\n"); errno = err; return -1; } @@ -4065,10 +4007,9 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) */ if (ntfs_cluster_free(vol, na, 0, -1) < 0) { err = errno; - Dprintf("%s(): Eeek! Failed to release allocated " - "clusters (error: %s). Ignoring error and " - "leaving behind wasted clusters.\n", - __FUNCTION__, strerror(err)); + ntfs_log_perror("Eeek! Failed to release allocated clusters"); + ntfs_log_trace("Ignoring error and leaving behind wasted " + "clusters.\n"); } /* Throw away the now unused runlist. */ @@ -4098,8 +4039,8 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) * * On success return 0 and on error return -1 with errno set to the error code. * The following error codes are defined: - * ENOMEM - Not enough memory to complete operation. - * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. + * ENOMEM - Not enough memory to complete operation. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. */ int ntfs_attr_update_mapping_pairs(ntfs_attr *na) { @@ -4113,20 +4054,19 @@ int ntfs_attr_update_mapping_pairs(ntfs_attr *na) retry: if (!na || !na->rl) { - Dprintf("%s(): Invalid parameters passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid parameters passed.\n"); errno = EINVAL; return -1; } if (!NAttrNonResident(na)) { - Dprintf("%s(): Attribute should be non resident.\n", - __FUNCTION__); + ntfs_log_trace("Attribute should be non resident.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", __FUNCTION__, - (unsigned long long)na->ni->mft_no, na->type); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); if (na->ni->nr_extents == -1) base_ni = na->ni->base_ni; @@ -4136,7 +4076,7 @@ retry: ctx = ntfs_attr_get_search_ctx(base_ni, NULL); if (!ctx) { err = errno; - Dprintf("%s(): Couldn't get search context.\n", __FUNCTION__); + ntfs_log_trace("Couldn't get search context.\n"); errno = err; return -1; } @@ -4156,9 +4096,8 @@ retry: * delete extent) and continue search. */ if (finished_build) { - Dprintf("%s(): Mark attr 0x%x for delete in inode " - "0x%llx.\n", __FUNCTION__, - (unsigned)le32_to_cpu(a->type), + ntfs_log_trace("Mark attr 0x%x for delete in inode " + "0x%llx.\n", (unsigned)le32_to_cpu(a->type), ctx->ntfs_ino->mft_no); a->highest_vcn = cpu_to_sle64(NTFS_VCN_DELETE_MARK); ntfs_inode_mark_dirty(ctx->ntfs_ino); @@ -4172,9 +4111,9 @@ retry: if (a->name_length) { if (le16_to_cpu(a->name_offset) >= le16_to_cpu(a->mapping_pairs_offset)) { - Dprintf("%s(): Eeek! Damaged attribute. Name is" - " placed after the mapping pairs array." - " Run chkdsk.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Damaged attribute. Name is " + "placed after the mapping pairs " + "array. Run chkdsk.\n"); err = EIO; goto put_err_out; } @@ -4185,7 +4124,7 @@ retry: sparse = ntfs_rl_sparse(na->rl); if (sparse == -1) { - Dprintf("%s(): Bad runlist.\n", __FUNCTION__); + ntfs_log_trace("Bad runlist.\n"); err = EIO; goto put_err_out; } @@ -4211,10 +4150,9 @@ retry: } if (ntfs_attr_record_move_away(ctx, 8)) { - Dprintf("%s(): Failed to move " + ntfs_log_trace("Failed to move " "attribute to another " - "extent. Aborting...\n", - __FUNCTION__); + "extent. Aborting...\n"); err = errno; goto put_err_out; } @@ -4223,10 +4161,10 @@ retry: } if (!(le32_to_cpu(a->length) - le16_to_cpu( a->mapping_pairs_offset))) { - Dprintf("%s(): Size of the space " - "allocated for mapping pairs " - "should not be 0. " - "Aborting ...\n", __FUNCTION__); + ntfs_log_trace("Size of the space allocated " + "for mapping pairs " + "should not be 0. " + "Aborting ...\n"); err = EIO; goto put_err_out; } @@ -4279,8 +4217,7 @@ retry: stop_vcn); if (mp_size <= 0) { err = errno; - Dprintf("%s(): Eeek! Get size for mapping " - "pairs failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Get size for mapping pairs failed.\n"); goto put_err_out; } /* @@ -4309,11 +4246,12 @@ retry: cur_max_mp_size)) { if (errno != ENOSPC) return -1; - Dprintf("%s(): Attribute list mapping " - "pairs size to big, can't fit " - "them in the base MFT record. " - "Defragment volume and try " - "once again.\n", __FUNCTION__); + ntfs_log_trace("Attribute list mapping pairs " + "size to big, can't fit " + "them in the base MFT " + "record. Defragment " + "volume and try once " + "again.\n"); errno = ENOSPC; return -1; } @@ -4325,9 +4263,8 @@ retry: ntfs_attr_put_search_ctx(ctx); if (ntfs_inode_add_attrlist(base_ni)) { err = errno; - Dprintf("%s(): Eeek! Couldn't add " - "attribute list.\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Couldn't add attribute " + "list.\n"); errno = err; return -1; } @@ -4347,13 +4284,11 @@ retry: if (ntfs_attr_record_resize(m, a, le16_to_cpu(a->mapping_pairs_offset) + mp_size)) { - Dprintf("%s(): BUG! Ran out of space in" - " mft record. Please run chkdsk" - " and if that doesn't find any " - "errors please report you saw " - "this message to " - "linux-ntfs-dev@lists.sf.net." - "\n", __FUNCTION__); + ntfs_log_trace("BUG! Ran out of space in mft record. " + "Please run chkdsk and if that " + "doesn't find any errors please " + "report you saw this message to " + "linux-ntfs-dev@lists.sf.net.\n"); err = EIO; goto put_err_out; } @@ -4379,11 +4314,10 @@ retry: finished_build = TRUE; if (!finished_build && errno != ENOSPC) { err = errno; - Dprintf("%s(): BUG! Mapping pairs build failed. " - "Please run chkdsk and if that doesn't find " - "any errors please report you saw this message" - " to linux-ntfs-dev@lists.sf.net.\n", - __FUNCTION__); + ntfs_log_trace("BUG! Mapping pairs build failed. Please " + "run chkdsk and if that doesn't find " + "any errors please report you saw this " + "message to linux-ntfs-dev@lists.sf.net.\n"); goto put_err_out; } a->highest_vcn = cpu_to_sle64(stop_vcn - 1); @@ -4391,14 +4325,14 @@ retry: /* Check whether error occurred. */ if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); goto put_err_out; } /* Deallocate not used attribute extents and return with success. */ if (finished_build) { ntfs_attr_reinit_search_ctx(ctx); - Dprintf("%s(): Deallocate marked extents.\n", __FUNCTION__); + ntfs_log_trace("Deallocate marked extents.\n"); while (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (sle64_to_cpu(ctx->attr->highest_vcn) != @@ -4407,19 +4341,18 @@ retry: /* Remove unused attribute record. */ if (ntfs_attr_record_rm(ctx)) { err = errno; - Dprintf("%s(): Couldn't remove unused attribute" - " record.\n", __FUNCTION__); + ntfs_log_trace("Couldn't remove unused attribute " + "record.\n"); goto put_err_out; } ntfs_attr_reinit_search_ctx(ctx); } if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", - __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); goto put_err_out; } - Dprintf("%s(): Deallocate done.\n", __FUNCTION__); + ntfs_log_trace("Deallocate done.\n"); ntfs_attr_put_search_ctx(ctx); return 0; } @@ -4433,16 +4366,14 @@ retry: na->rl, stop_vcn); if (mp_size <= 0) { err = errno; - Dprintf("%s(): Eeek! Get size for mapping " - "pairs failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Get size for mapping pairs failed.\n"); goto put_err_out; } /* Allocate new mft record. */ ni = ntfs_mft_record_alloc(na->ni->vol, base_ni); if (!ni) { err = errno; - Dprintf("%s(): Couldn't allocate new MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't allocate new MFT record.\n"); goto put_err_out; } m = ni->mrec; @@ -4463,11 +4394,10 @@ retry: na->name, na->name_len, stop_vcn, mp_size, 0); if (err == -1) { err = errno; - Dprintf("%s(): Couldn't add attribute extent " - "into the MFT record.\n", __FUNCTION__); + ntfs_log_trace("Couldn't add attribute extent into the MFT " + "record.\n"); if (ntfs_mft_record_free(na->ni->vol, ni)) { - Dprintf("%s(): Couldn't free MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't free MFT record.\n"); } goto put_err_out; } @@ -4478,15 +4408,12 @@ retry: stop_vcn, &stop_vcn); if (err < 0 && errno != ENOSPC) { err = errno; - Dprintf("%s(): BUG! Mapping pairs build " - "failed. Please run chkdsk and if " - "that doesn't find any errors please " - "report you saw this message to " - "linux-ntfs-dev@lists.sf.net.\n", - __FUNCTION__); + ntfs_log_trace("BUG! Mapping pairs build failed. Please " + "run chkdsk and if that doesn't find " + "any errors please report you saw this " + "message to linux-ntfs-dev@lists.sf.net.\n"); if (ntfs_mft_record_free(na->ni->vol, ni)) - Dprintf("%s(): Couldn't free MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't free MFT record.\n"); goto put_err_out; } a->highest_vcn = cpu_to_sle64(stop_vcn - 1); @@ -4525,8 +4452,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) s64 nr_freed_clusters; int err; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", __FUNCTION__, - (unsigned long long)na->ni->mft_no, na->type); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); vol = na->ni->vol; @@ -4537,8 +4464,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { err = errno; if (err == ERANGE) { - Dprintf("%s(): Eeek! Size bounds check " - "failed. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Size bounds check failed. " + "Aborting...\n"); } else if (err == ENOENT) err = EIO; errno = err; @@ -4555,8 +4482,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) if ((na->allocated_size >> vol->cluster_size_bits) != first_free_vcn) { if (ntfs_attr_map_whole_runlist(na)) { err = errno; - Dprintf("%s(): Eeek! ntfs_attr_map_whole_runlist " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! ntfs_attr_map_whole_runlist " + "failed.\n"); errno = err; return -1; } @@ -4565,8 +4492,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) -1); if (nr_freed_clusters < 0) { err = errno; - Dprintf("%s(): Eeek! Freeing of clusters " - "failed. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Freeing of clusters failed. " + "Aborting...\n"); errno = err; return -1; } @@ -4580,8 +4507,7 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) */ free(na->rl); na->rl = NULL; - Dprintf("%s(): Eeek! Run list truncation failed.\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Run list truncation failed.\n"); errno = err; return -1; } @@ -4589,9 +4515,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) /* Write mapping pairs for new runlist. */ if (ntfs_attr_update_mapping_pairs(na)) { err = errno; - Dprintf("%s(): Eeek! Mapping pairs update failed. " - "Leaving inconstant metadata. Run chkdsk.\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Mapping pairs update failed. Leaving " + "inconstant metadata. Run chkdsk.\n"); errno = err; return -1; } @@ -4603,11 +4528,10 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) err = errno; if ((na->allocated_size >> vol->cluster_size_bits) != first_free_vcn) - Dprintf("%s(): Couldn't get attribute search context. " - "Leaving inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Couldn't get attribute search context. " + "Leaving inconstant metadata.\n"); else - Dprintf("%s(): Couldn't get attribute search context.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't get attribute search context.\n"); errno = err; return -1; } @@ -4616,8 +4540,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) err = errno; if (err == ENOENT) err = EIO; - Dprintf("%s(): Eeek! Lookup of first attribute extent failed. " - "Leaving inconstant metadata.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Lookup of first attribute extent failed. " + "Leaving inconstant metadata.\n"); goto put_err_out; } a = ctx->attr; @@ -4635,8 +4559,7 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) new_compr_size = ntfs_rl_get_compressed_size(vol, na->rl); if (new_compr_size == -1) { err = errno; - Dprintf("%s(): BUG! Leaving inconstant metadata.\n", - __FUNCTION__); + ntfs_log_trace("BUG! Leaving inconstant metadata.\n"); goto put_err_out; } na->compressed_size = new_compr_size; @@ -4656,9 +4579,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) if (ntfs_attr_make_resident(na, ctx)) { /* If couldn't make resident, just continue. */ if (errno != EPERM) - Dprintf("%s(): Failed to make attribute " - "resident. Leaving as is...\n", - __FUNCTION__); + ntfs_log_trace("Failed to make attribute resident. " + "Leaving as is...\n"); } } @@ -4683,9 +4605,9 @@ put_err_out: * * On success return 0 and on error return -1 with errno set to the error code. * The following error codes are defined: - * ENOMEM - Not enough memory to complete operation. - * ERANGE - @newsize is not valid for the attribute type of @na. - * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. */ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) { @@ -4697,8 +4619,8 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) runlist *rl, *rln; int err; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", __FUNCTION__, - (unsigned long long)na->ni->mft_no, na->type); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); vol = na->ni->vol; @@ -4709,8 +4631,8 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { err = errno; if (err == ERANGE) { - Dprintf("%s(): Eeek! Size bounds check " - "failed. Aborting...\n", __FUNCTION__); + ntfs_log_trace("Eeek! Size bounds check failed. " + "Aborting...\n"); } else if (err == ENOENT) err = EIO; errno = err; @@ -4727,8 +4649,8 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) if ((na->allocated_size >> vol->cluster_size_bits) < first_free_vcn) { if (ntfs_attr_map_whole_runlist(na)) { err = errno; - Dprintf("%s(): Eeek! ntfs_attr_map_whole_runlist " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! ntfs_attr_map_whole_runlist " + "failed.\n"); errno = err; return -1; } @@ -4740,8 +4662,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) if (na->type == AT_DATA && vol->major_ver >= 3) { rl = malloc(0x1000); if (!rl) { - Dprintf("%s(): Not enough memory.\n", - __FUNCTION__); + ntfs_log_trace("Not enough memory.\n"); err = ENOMEM; return -1; } @@ -4786,8 +4707,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) DATA_ZONE); if (!rl) { err = errno; - Dprintf("%s(): Eeek! Cluster allocation " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Cluster allocation failed.\n"); errno = err; return -1; } @@ -4798,8 +4718,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) if (!rln) { /* Failed, free just allocated clusters. */ err = errno; - Dprintf("%s(): Eeek! Run list merge " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Run list merge failed.\n"); ntfs_cluster_free_from_rl(vol, rl); free(rl); errno = err; @@ -4810,8 +4729,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) /* Write mapping pairs for new runlist. */ if (ntfs_attr_update_mapping_pairs(na)) { err = errno; - Dprintf("%s(): Eeek! Mapping pairs update failed.\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Mapping pairs update failed.\n"); goto rollback; } } @@ -4819,7 +4737,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) { err = errno; - Dprintf("%s(): Failed to get search context.\n", __FUNCTION__); + ntfs_log_trace("Failed to get search context.\n"); if ((na->allocated_size >> vol->cluster_size_bits) == first_free_vcn) { errno = err; @@ -4830,8 +4748,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { - Dprintf("%s(): Eeek! Lookup of first attribute extent " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Lookup of first attribute extent failed.\n"); err = errno; if (err == ENOENT) err = EIO; @@ -4857,8 +4774,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) new_compr_size = ntfs_rl_get_compressed_size(vol, na->rl); if (new_compr_size == -1) { err = errno; - Dprintf("%s(): BUG! Leaving inconstant metadata.\n", - __FUNCTION__); + ntfs_log_trace("BUG! Leaving inconstant metadata.\n"); goto put_err_out; } na->compressed_size = new_compr_size; @@ -4877,8 +4793,7 @@ rollback: /* Free allocated clusters. */ if (ntfs_cluster_free(vol, na, na->allocated_size >> vol->cluster_size_bits, -1) < 0) { - Dprintf("%s(): Eeek! Leaking clusters. Run chkdsk!\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Leaking clusters. Run chkdsk!\n"); err = EIO; } /* Now, truncate the runlist itself. */ @@ -4890,13 +4805,13 @@ rollback: */ free(na->rl); na->rl = NULL; - Dprintf("%s(): Eeek! Couldn't truncate runlist. Rollback " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Couldn't truncate runlist. Rollback " + "failed.\n"); } else { /* Restore mapping pairs. */ if (ntfs_attr_update_mapping_pairs(na)) { - Dprintf("%s(): Eeek! Couldn't restore old mapping " - "pairs. Rollback failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Couldn't restore old mapping pairs. " + "Rollback failed.\n"); } } errno = err; @@ -4929,7 +4844,7 @@ int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize) if (!na || newsize < 0 || (na->ni->mft_no == FILE_MFT && na->type == AT_DATA)) { - Dprintf("%s(): Invalid arguments passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments passed.\n"); errno = EINVAL; return -1; } diff --git a/libntfs/attrlist.c b/libntfs/attrlist.c index 530a0a36..b1c7475b 100644 --- a/libntfs/attrlist.c +++ b/libntfs/attrlist.c @@ -1,4 +1,4 @@ -/* +/** * attrlist.c - Attribute list attribute handling code. Part of the Linux-NTFS * project. * @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -36,6 +38,7 @@ #include "attrlist.h" #include "debug.h" #include "unistr.h" +#include "logging.h" /** * ntfs_attrlist_need - check whether inode need attribute list @@ -55,23 +58,21 @@ int ntfs_attrlist_need(ntfs_inode *ni) ATTR_LIST_ENTRY *ale; if (!ni) { - Dprintf("%s(): Invalid arguments.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for inode 0x%llx.\n", - __FUNCTION__, (long long) ni->mft_no); + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); if (!NInoAttrList(ni)) { - Dprintf("%s(): Inode haven't got attribute list.\n", - __FUNCTION__); + ntfs_log_trace("Inode haven't got attribute list.\n"); errno = EINVAL; return -1; } if (!ni->attr_list) { - Dprintf("%s(): Corrupt in-memory struct.\n", __FUNCTION__); + ntfs_log_trace("Corrupt in-memory struct.\n"); errno = EINVAL; return -1; } @@ -107,12 +108,12 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) u8 *new_al; int entry_len, entry_offset, err; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x.\n", - __FUNCTION__, (long long) ni->mft_no, + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) ni->mft_no, (unsigned) le32_to_cpu(attr->type)); if (!ni || !attr) { - Dprintf("%s(): Invalid arguments.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } @@ -123,7 +124,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) ni = ni->base_ni; if (!NInoAttrList(ni)) { - Dprintf("%s(): Attribute list isn't present.\n", __FUNCTION__); + ntfs_log_trace("Attribute list isn't present.\n"); errno = ENOENT; return -1; } @@ -133,7 +134,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) attr->name_length + 7) & ~7; new_al = malloc(ni->attr_list_size + entry_len); if (!new_al) { - Dprintf("%s(): Not enough memory.\n", __FUNCTION__); + ntfs_log_trace("Not enough memory.\n"); err = ENOMEM; return -1; } @@ -142,8 +143,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; - Dprintf("%s(): Failed to obtain attribute search context.\n", - __FUNCTION__); + ntfs_log_trace("Failed to obtain attribute search context.\n"); goto err_out; } if (!ntfs_attr_lookup(attr->type, (attr->name_length) ? (ntfschar*) @@ -156,8 +156,8 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) /* Found some extent, check it to be before new extent. */ if (ctx->al_entry->lowest_vcn == attr->lowest_vcn) { err = EEXIST; - Dprintf("%s(): Such attribute already present in the " - "attribute list.\n", __FUNCTION__); + ntfs_log_trace("Such attribute already present in the " + "attribute list.\n"); ntfs_attr_put_search_ctx(ctx); goto err_out; } @@ -168,8 +168,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) /* Check for real errors. */ if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", - __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); ntfs_attr_put_search_ctx(ctx); goto err_out; } @@ -203,13 +202,12 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); if (!na) { err = errno; - Dprintf("%s(): Failed to open $ATTRIBUTE_LIST attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n"); goto err_out; } if (ntfs_attr_truncate(na, ni->attr_list_size + entry_len)) { err = errno; - Dprintf("%s(): $ATTRIBUTE_LIST resize failed.\n", __FUNCTION__); + ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n"); goto err_out; } @@ -219,8 +217,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) entry_offset, ni->attr_list_size - entry_offset); /* Set new runlist. */ - if (ni->attr_list) - free(ni->attr_list); + free(ni->attr_list); ni->attr_list = new_al; ni->attr_list_size = ni->attr_list_size + entry_len; NInoAttrListSetDirty(ni); @@ -253,7 +250,7 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) int err; if (!ctx || !ctx->ntfs_ino || !ctx->al_entry) { - Dprintf("%s(): Invalid arguments.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } @@ -264,13 +261,13 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) base_ni = ctx->ntfs_ino; ale = ctx->al_entry; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x, lowest_vcn " - "%lld.\n", __FUNCTION__, (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)); + 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)); if (!NInoAttrList(base_ni)) { - Dprintf("%s(): Attribute list isn't present.\n", __FUNCTION__); + ntfs_log_trace("Attribute list isn't present.\n"); errno = ENOENT; return -1; } @@ -279,7 +276,7 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) new_al_len = base_ni->attr_list_size - le16_to_cpu(ale->length); new_al = malloc(new_al_len); if (!new_al) { - Dprintf("%s(): Not enough memory.\n", __FUNCTION__); + ntfs_log_trace("Not enough memory.\n"); errno = ENOMEM; return -1; } @@ -288,13 +285,12 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) na = ntfs_attr_open(base_ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); if (!na) { err = errno; - Dprintf("%s(): Failed to open $ATTRIBUTE_LIST attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n"); goto err_out; } if (ntfs_attr_truncate(na, new_al_len)) { err = errno; - Dprintf("%s(): $ATTRIBUTE_LIST resize failed.\n", __FUNCTION__); + ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n"); goto err_out; } @@ -304,8 +300,7 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) ale->length), new_al_len - ((u8*)ale - base_ni->attr_list)); /* Set new runlist. */ - if (base_ni->attr_list) - free(base_ni->attr_list); + free(base_ni->attr_list); base_ni->attr_list = new_al; base_ni->attr_list_size = new_al_len; NInoAttrListSetDirty(base_ni); diff --git a/libntfs/bitmap.c b/libntfs/bitmap.c index 79ca11c0..e722fe9b 100644 --- a/libntfs/bitmap.c +++ b/libntfs/bitmap.c @@ -1,4 +1,4 @@ -/* +/** * bitmap.c - Bitmap handling code. Part of the Linux-NTFS project. * * Copyright (c) 2002-2004 Anton Altaparmakov @@ -20,7 +20,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -39,6 +41,7 @@ #include "attrib.h" #include "bitmap.h" #include "debug.h" +#include "logging.h" /** * ntfs_bitmap_set_bits_in_run - set a run of bits in a bitmap to a value @@ -112,9 +115,8 @@ static __inline__ int ntfs_bitmap_set_bits_in_run(ntfs_attr *na, s64 start_bit, lastbyte_pos = ((count + 7) >> 3) + firstbyte; if (!lastbyte_pos) { // FIXME: Eeek! BUG! - Dprintf("%s(): Eeek! lastbyte is zero. " - "Leaving inconsistent " - "metadata.\n", __FUNCTION__); + ntfs_log_trace("Eeek! lastbyte is zero. Leaving " + "inconsistent metadata.\n"); err = EIO; goto free_err_out; } @@ -127,11 +129,9 @@ static __inline__ int ntfs_bitmap_set_bits_in_run(ntfs_attr *na, s64 start_bit, 3, 1, lastbyte_buf); if (br != 1) { // FIXME: Eeek! We need rollback! (AIA) - Dprintf("%s(): Eeek! Read of last " - "byte failed. " - "Leaving inconsistent " - "metadata.\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Read of last byte " + "failed. Leaving " + "inconsistent metadata.\n"); err = EIO; goto free_err_out; } @@ -154,9 +154,8 @@ static __inline__ int ntfs_bitmap_set_bits_in_run(ntfs_attr *na, s64 start_bit, br = ntfs_attr_pwrite(na, tmp, bufsize, buf); if (br != bufsize) { // FIXME: Eeek! We need rollback! (AIA) - Dprintf("%s(): Eeek! Failed to write buffer to " - "bitmap. Leaving inconsistent " - "metadata.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Failed to write buffer to bitmap. " + "Leaving inconsistent metadata.\n"); err = EIO; goto free_err_out; } @@ -171,10 +170,9 @@ static __inline__ int ntfs_bitmap_set_bits_in_run(ntfs_attr *na, s64 start_bit, if (lastbyte && count != 0) { // FIXME: Eeek! BUG! - Dprintf("%s(): Eeek! Last buffer but count is not " - "zero (= %lli). Leaving " - "inconsistent metadata.\n", - __FUNCTION__, (long long)count); + ntfs_log_trace("Eeek! Last buffer but count is not zero (= " + "%lli). Leaving inconsistent metadata.\n", + (long long)count); err = EIO; goto free_err_out; } @@ -225,17 +223,14 @@ int ntfs_bitmap_clear_run(ntfs_attr *na, s64 start_bit, s64 count) #ifdef NTFS_RICH -#include - #include "layout.h" #include "volume.h" -#include "bitmap.h" #include "rich.h" /** * ntfs_bmp_rollback */ -int ntfs_bmp_rollback (struct ntfs_bmp *bmp) +int ntfs_bmp_rollback(struct ntfs_bmp *bmp) { int i; @@ -243,10 +238,10 @@ int ntfs_bmp_rollback (struct ntfs_bmp *bmp) return 0; for (i = 0; i < bmp->count; i++) - free (bmp->data[i]); + free(bmp->data[i]); - free (bmp->data); - free (bmp->data_vcn); + free(bmp->data); + free(bmp->data_vcn); bmp->data = NULL; bmp->data_vcn = NULL; bmp->count = 0; @@ -257,7 +252,7 @@ int ntfs_bmp_rollback (struct ntfs_bmp *bmp) /** * ntfs_bmp_commit */ -int ntfs_bmp_commit (struct ntfs_bmp *bmp) +int ntfs_bmp_commit(struct ntfs_bmp *bmp) { int i; u32 cs; @@ -271,16 +266,16 @@ int ntfs_bmp_commit (struct ntfs_bmp *bmp) return 0; #if 0 - printf ("attr = 0x%02X\n", bmp->attr->type); - printf ("resident = %d\n", !NAttrNonResident (bmp->attr)); - printf ("\ta size = %lld\n", bmp->attr->allocated_size); - printf ("\td size = %lld\n", bmp->attr->data_size); - printf ("\ti size = %lld\n", bmp->attr->initialized_size); + ntfs_log_debug("attr = 0x%02X\n", bmp->attr->type); + ntfs_log_debug("resident = %d\n", !NAttrNonResident(bmp->attr)); + ntfs_log_debug("\ta size = %lld\n", bmp->attr->allocated_size); + ntfs_log_debug("\td size = %lld\n", bmp->attr->data_size); + ntfs_log_debug("\ti size = %lld\n", bmp->attr->initialized_size); #endif - printf ("commit bmp inode %lld, 0x%02X (%sresident)\n", bmp->attr->ni->mft_no, bmp->attr->type, NAttrNonResident (bmp->attr) ? "non-" : ""); + ntfs_log_debug("commit bmp inode %lld, 0x%02X (%sresident)\n", bmp->attr->ni->mft_no, bmp->attr->type, NAttrNonResident(bmp->attr) ? "non-" : ""); - if (NAttrNonResident (bmp->attr)) { + if (NAttrNonResident(bmp->attr)) { cs = bmp->vol->cluster_size; // non-resident @@ -290,20 +285,20 @@ int ntfs_bmp_commit (struct ntfs_bmp *bmp) ws = cs; else ws = bmp->attr->data_size & (cs - 1); - //printf ("writing %d bytes\n", ws); - ntfs_attr_pwrite (bmp->attr, bmp->data_vcn[i] * cs, ws, bmp->data[i]); // XXX retval + //ntfs_log_debug("writing %d bytes\n", ws); + ntfs_attr_pwrite(bmp->attr, bmp->data_vcn[i] * cs, ws, bmp->data[i]); // XXX retval #endif - printf (RED "\tntfs_attr_pwrite (vcn %lld)\n" END, bmp->data_vcn[i]); + ntfs_log_debug(RED "\tntfs_attr_pwrite(vcn %lld)\n" END, bmp->data_vcn[i]); } } else { // resident #ifdef RM_WRITE - ntfs_attr_pwrite (bmp->attr, bmp->data_vcn[0], bmp->attr->data_size, bmp->data[0]); // XXX retval + ntfs_attr_pwrite(bmp->attr, bmp->data_vcn[0], bmp->attr->data_size, bmp->data[0]); // XXX retval #endif - printf (RED "\tntfs_attr_pwrite resident (%lld)\n" END, bmp->attr->data_size); + ntfs_log_debug(RED "\tntfs_attr_pwrite resident (%lld)\n" END, bmp->attr->data_size); } - ntfs_bmp_rollback (bmp); + ntfs_bmp_rollback(bmp); return 0; } @@ -311,22 +306,22 @@ int ntfs_bmp_commit (struct ntfs_bmp *bmp) /** * ntfs_bmp_free */ -void ntfs_bmp_free (struct ntfs_bmp *bmp) +void ntfs_bmp_free(struct ntfs_bmp *bmp) { if (!bmp) return; - ntfs_bmp_rollback (bmp); + ntfs_bmp_rollback(bmp); - ntfs_attr_close (bmp->attr); + ntfs_attr_close(bmp->attr); - free (bmp); + free(bmp); } /** * ntfs_bmp_create */ -struct ntfs_bmp * ntfs_bmp_create (ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len) +struct ntfs_bmp * ntfs_bmp_create(ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len) { struct ntfs_bmp *bmp; ntfs_attr *attr; @@ -334,13 +329,13 @@ struct ntfs_bmp * ntfs_bmp_create (ntfs_inode *inode, ATTR_TYPES type, ntfschar if (!inode) return NULL; - attr = ntfs_attr_open (inode, type, name, name_len); + attr = ntfs_attr_open(inode, type, name, name_len); if (!attr) return NULL; - bmp = calloc (1, sizeof (*bmp)); + bmp = calloc(1, sizeof(*bmp)); if (!bmp) { - ntfs_attr_close (attr); + ntfs_attr_close(attr); return NULL; } @@ -356,7 +351,7 @@ struct ntfs_bmp * ntfs_bmp_create (ntfs_inode *inode, ATTR_TYPES type, ntfschar /** * ntfs_bmp_add_data */ -int ntfs_bmp_add_data (struct ntfs_bmp *bmp, VCN vcn, u8 *data) +int ntfs_bmp_add_data(struct ntfs_bmp *bmp, VCN vcn, u8 *data) { int i = 0; int old; @@ -365,13 +360,13 @@ int ntfs_bmp_add_data (struct ntfs_bmp *bmp, VCN vcn, u8 *data) if (!bmp || !data) return -1; - old = ROUND_UP (bmp->count, 16); + old = ROUND_UP(bmp->count, 16); bmp->count++; - new = ROUND_UP (bmp->count, 16); + new = ROUND_UP(bmp->count, 16); if (old != new) { - bmp->data = realloc (bmp->data, new * sizeof (*bmp->data)); - bmp->data_vcn = realloc (bmp->data_vcn , new * sizeof (*bmp->data_vcn)); + bmp->data = realloc(bmp->data, new * sizeof(*bmp->data)); + bmp->data_vcn = realloc(bmp->data_vcn , new * sizeof(*bmp->data_vcn)); } for (i = 0; i < bmp->count-1; i++) @@ -379,8 +374,8 @@ int ntfs_bmp_add_data (struct ntfs_bmp *bmp, VCN vcn, u8 *data) break; if ((bmp->count-i) > 0) { - memmove (&bmp->data[i+1], &bmp->data[i], (bmp->count-i) * sizeof (*bmp->data)); - memmove (&bmp->data_vcn[i+1], &bmp->data_vcn[i], (bmp->count-i) * sizeof (*bmp->data_vcn)); + memmove(&bmp->data[i+1], &bmp->data[i], (bmp->count-i) * sizeof(*bmp->data)); + memmove(&bmp->data_vcn[i+1], &bmp->data_vcn[i], (bmp->count-i) * sizeof(*bmp->data_vcn)); } bmp->data[i] = data; @@ -392,7 +387,7 @@ int ntfs_bmp_add_data (struct ntfs_bmp *bmp, VCN vcn, u8 *data) /** * ntfs_bmp_get_data */ -u8 * ntfs_bmp_get_data (struct ntfs_bmp *bmp, VCN vcn) +u8 * ntfs_bmp_get_data(struct ntfs_bmp *bmp, VCN vcn) { u8 *buffer; int i; @@ -412,30 +407,30 @@ u8 * ntfs_bmp_get_data (struct ntfs_bmp *bmp, VCN vcn) for (i = 0; i < bmp->count; i++) { if (vcn == bmp->data_vcn[i]) { - //printf ("reusing bitmap cluster %lld\n", vcn); + //ntfs_log_debug("reusing bitmap cluster %lld\n", vcn); return bmp->data[i]; } } - buffer = calloc (1, cs); // XXX could be smaller if attr size < cluster size + buffer = calloc(1, cs); // XXX could be smaller if attr size < cluster size if (!buffer) return NULL; - //printf ("loading from bitmap cluster %lld\n", vcn); - //printf ("loading from bitmap byte %lld\n", vcn<attr, vcn<attr, vcn< 1) { - memset (buffer+byte_start+1, value, byte_finish-byte_start-1); + memset(buffer+byte_start+1, value, byte_finish-byte_start-1); } else if (byte_finish == byte_start) { mask_start &= mask_finish; mask_finish = 0x00; @@ -509,13 +504,13 @@ int ntfs_bmp_set_range (struct ntfs_bmp *bmp, VCN vcn, s64 length, int value) } #if 1 - printf (GREEN "Modified: inode %lld, ", bmp->attr->ni->mft_no); + ntfs_log_debug(GREEN "Modified: inode %lld, ", bmp->attr->ni->mft_no); switch (bmp->attr->type) { - case AT_BITMAP: printf ("$BITMAP"); break; - case AT_DATA: printf ("$DATA"); break; - default: break; + case AT_BITMAP: ntfs_log_debug("$BITMAP"); break; + case AT_DATA: ntfs_log_debug("$DATA"); break; + default: break; } - printf (" vcn %lld-%lld\n" END, vcn>>12, (vcn+length-1)>>12); + ntfs_log_debug(" vcn %lld-%lld\n" END, vcn>>12, (vcn+length-1)>>12); #endif return 1; } @@ -523,7 +518,7 @@ int ntfs_bmp_set_range (struct ntfs_bmp *bmp, VCN vcn, s64 length, int value) /** * ntfs_bmp_find_last_set */ -s64 ntfs_bmp_find_last_set (struct ntfs_bmp *bmp) +s64 ntfs_bmp_find_last_set(struct ntfs_bmp *bmp) { s64 clust_count; s64 byte_count; @@ -540,17 +535,17 @@ s64 ntfs_bmp_find_last_set (struct ntfs_bmp *bmp) // find cluster size of bmp byte_count = bmp->attr->data_size; - clust_count = ROUND_UP (byte_count, bmp->vol->cluster_size) >> bmp->vol->cluster_size_bits; + clust_count = ROUND_UP(byte_count, bmp->vol->cluster_size) >> bmp->vol->cluster_size_bits; - //printf ("bitmap = %lld bytes\n", byte_count); - //printf ("bitmap = %lld buffers\n", clust_count); + //ntfs_log_debug("bitmap = %lld bytes\n", byte_count); + //ntfs_log_debug("bitmap = %lld buffers\n", clust_count); // for each cluster backwards for (clust = clust_count-1; clust >= 0; clust--) { - //printf ("cluster %lld\n", clust); - //printf ("get vcn %lld\n", clust << (bmp->vol->cluster_size_bits + 3)); - buffer = ntfs_bmp_get_data (bmp, clust << (bmp->vol->cluster_size_bits + 3)); - //utils_dump_mem (buffer, 0, 8, DM_NO_ASCII); + //ntfs_log_debug("cluster %lld\n", clust); + //ntfs_log_debug("get vcn %lld\n", clust << (bmp->vol->cluster_size_bits + 3)); + buffer = ntfs_bmp_get_data(bmp, clust << (bmp->vol->cluster_size_bits + 3)); + //utils_dump_mem(buffer, 0, 8, DM_NO_ASCII); if (!buffer) return -2; if ((clust == (clust_count-1) && ((byte_count % bmp->vol->cluster_size) != 0))) { @@ -558,14 +553,14 @@ s64 ntfs_bmp_find_last_set (struct ntfs_bmp *bmp) } else { byte = bmp->vol->cluster_size; } - //printf ("start byte = %d\n", byte); + //ntfs_log_debug("start byte = %d\n", byte); // for each byte backward for (byte--; byte >= 0; byte--) { - //printf ("\tbyte %d (%d)\n", byte, buffer[byte]); + //ntfs_log_debug("\tbyte %d (%d)\n", byte, buffer[byte]); // for each bit shift up note = -1; for (bit = 7; bit >= 0; bit--) { - //printf ("\t\tbit %d (%d)\n", (1<= 0) { // if note, return value - //printf ("match %lld (c=%lld,b=%d,n=%d)\n", (((clust << bmp->vol->cluster_size_bits) + byte) << 3) + note, clust, byte, note); + //ntfs_log_debug("match %lld (c=%lld,b=%d,n=%d)\n", (((clust << bmp->vol->cluster_size_bits) + byte) << 3) + note, clust, byte, note); return ((((clust << bmp->vol->cluster_size_bits) + byte) << 3) + note); } } @@ -586,7 +581,7 @@ s64 ntfs_bmp_find_last_set (struct ntfs_bmp *bmp) /** * ntfs_bmp_find_space */ -int ntfs_bmp_find_space (struct ntfs_bmp *bmp, LCN start, long size) +int ntfs_bmp_find_space(struct ntfs_bmp *bmp, LCN start, long size) { if (!bmp) return 0; diff --git a/libntfs/bootsect.c b/libntfs/bootsect.c index e9fb56f9..cf81bb10 100644 --- a/libntfs/bootsect.c +++ b/libntfs/bootsect.c @@ -1,4 +1,4 @@ -/* +/** * bootsect.c - Boot sector handling code. Part of the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov @@ -20,7 +20,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDIO_H #include @@ -36,9 +38,9 @@ #endif #include "compat.h" - #include "bootsect.h" #include "debug.h" +#include "logging.h" /** * ntfs_boot_sector_is_ntfs - check if buffer contains a valid ntfs boot sector @@ -54,11 +56,11 @@ * * Return TRUE if @b contains a valid ntfs boot sector and FALSE if not. */ -BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b, const BOOL silent) +BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b, const BOOL silent __attribute__((unused))) { u32 i; - Sprintf(silent, "\nBeginning bootsector check...\n"); + ntfs_log_debug("\nBeginning bootsector check...\n"); /* Calculate the checksum. Note, this is just a simple addition of all u32 values in the bootsector starting at the beginning and @@ -68,31 +70,31 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b, const BOOL silent) u32 *u = (u32 *)b; u32 *bi = (u32 *)(&b->checksum); - Sprintf(silent, "Calculating bootsector checksum... "); + ntfs_log_debug("Calculating bootsector checksum... "); for (i = 0; u < bi; ++u) i += le32_to_cpup(u); if (le32_to_cpu(b->checksum) && le32_to_cpu(b->checksum) != i) goto not_ntfs; - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); } /* Check OEMidentifier is "NTFS " */ - Sprintf(silent, "Checking OEMid... "); + ntfs_log_debug("Checking OEMid... "); if (b->oem_id != cpu_to_le64(0x202020205346544eULL)) /* "NTFS " */ goto not_ntfs; - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); /* Check bytes per sector value is between 256 and 4096. */ - Sprintf(silent, "Checking bytes per sector... "); + ntfs_log_debug("Checking bytes per sector... "); if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 || le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000) goto not_ntfs; - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); /* Check sectors per cluster value is valid. */ - Sprintf(silent, "Checking sectors per cluster... "); + ntfs_log_debug("Checking sectors per cluster... "); switch (b->bpb.sectors_per_cluster) { case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128: @@ -100,17 +102,17 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b, const BOOL silent) default: goto not_ntfs; } - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); /* Check the cluster size is not above 65536 bytes. */ - Sprintf(silent, "Checking cluster size... "); + ntfs_log_debug("Checking cluster size... "); if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) * b->bpb.sectors_per_cluster > 0x10000) goto not_ntfs; - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); /* Check reserved/unused fields are really zero. */ - Sprintf(silent, "Checking reserved fields are zero... "); + ntfs_log_debug("Checking reserved fields are zero... "); if (le16_to_cpu(b->bpb.reserved_sectors) || le16_to_cpu(b->bpb.root_entries) || le16_to_cpu(b->bpb.sectors) || @@ -118,10 +120,10 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b, const BOOL silent) le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats) goto not_ntfs; - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); /* Check clusters per file mft record value is valid. */ - Sprintf(silent, "Checking clusters per mft record... "); + ntfs_log_debug("Checking clusters per mft record... "); if ((u8)b->clusters_per_mft_record < 0xe1 || (u8)b->clusters_per_mft_record > 0xf7) { switch (b->clusters_per_mft_record) { @@ -131,10 +133,10 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b, const BOOL silent) goto not_ntfs; } } - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); /* Check clusters per index block value is valid. */ - Sprintf(silent, "Checking clusters per index block... "); + ntfs_log_debug("Checking clusters per index block... "); if ((u8)b->clusters_per_index_record < 0xe1 || (u8)b->clusters_per_index_record > 0xf7) { switch (b->clusters_per_index_record) { @@ -144,17 +146,17 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b, const BOOL silent) goto not_ntfs; } } - Sprintf(silent, "OK\n"); + ntfs_log_debug("OK\n"); if (b->end_of_sector_marker != cpu_to_le16(0xaa55)) - Dputs("Warning: Bootsector has invalid end of sector marker."); + ntfs_log_debug("Warning: Bootsector has invalid end of sector marker.\n"); - Sprintf(silent, "Bootsector check completed successfully.\n"); + ntfs_log_debug("Bootsector check completed successfully.\n"); return TRUE; not_ntfs: - Sprintf(silent, "FAILED\n"); - Sprintf(silent, "Bootsector check failed. Aborting...\n"); + ntfs_log_debug("FAILED\n"); + ntfs_log_debug("Bootsector check failed. Aborting...\n"); return FALSE; } @@ -178,18 +180,18 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) vol->sector_size = le16_to_cpu(bs->bpb.bytes_per_sector); vol->sector_size_bits = ffs(vol->sector_size) - 1; - Dprintf("SectorSize = 0x%x\n", vol->sector_size); - Dprintf("SectorSizeBits = %u\n", vol->sector_size_bits); + ntfs_log_debug("SectorSize = 0x%x\n", vol->sector_size); + ntfs_log_debug("SectorSizeBits = %u\n", vol->sector_size_bits); /* * The bounds checks on mft_lcn and mft_mirr_lcn (i.e. them being * below or equal the number_of_clusters) really belong in the * ntfs_boot_sector_is_ntfs but in this way we can just do this once. */ sectors_per_cluster = bs->bpb.sectors_per_cluster; - Dprintf("NumberOfSectors = %lli\n", sle64_to_cpu(bs->number_of_sectors)); - Dprintf("SectorsPerCluster = 0x%x\n", sectors_per_cluster); + ntfs_log_debug("NumberOfSectors = %lli\n", sle64_to_cpu(bs->number_of_sectors)); + ntfs_log_debug("SectorsPerCluster = 0x%x\n", sectors_per_cluster); if (sectors_per_cluster & (sectors_per_cluster - 1)) { - Dprintf("Error: %s is not a valid NTFS partition! " + ntfs_log_debug("Error: %s is not a valid NTFS partition! " "sectors_per_cluster is not a power of 2.\n", vol->dev->d_name); return -1; @@ -199,18 +201,19 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) vol->mft_lcn = sle64_to_cpu(bs->mft_lcn); vol->mftmirr_lcn = sle64_to_cpu(bs->mftmirr_lcn); - Dprintf("MFT LCN = 0x%llx\n", vol->mft_lcn); - Dprintf("MFTMirr LCN = 0x%llx\n", vol->mftmirr_lcn); + ntfs_log_debug("MFT LCN = 0x%llx\n", vol->mft_lcn); + ntfs_log_debug("MFTMirr LCN = 0x%llx\n", vol->mftmirr_lcn); if (vol->mft_lcn > vol->nr_clusters || vol->mftmirr_lcn > vol->nr_clusters) { - Dprintf("Error: %s is not a valid NTFS partition! ($Mft LCN " - "or\n$MftMirr LCN is greater than the number " - "of clusters!\n", vol->dev->d_name); + ntfs_log_debug("Error: %s is not a valid NTFS partition!\n", + vol->dev->d_name); + ntfs_log_debug("($Mft LCN or $MftMirr LCN is greater than the " + "number of clusters!)\n"); return -1; } vol->cluster_size = sectors_per_cluster * vol->sector_size; if (vol->cluster_size & (vol->cluster_size - 1)) { - Dprintf("Error: %s is not a valid NTFS partition! " + ntfs_log_debug("Error: %s is not a valid NTFS partition! " "cluster_size is not a power of 2.\n", vol->dev->d_name); return -1; @@ -222,9 +225,9 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) * illegal, thus signed char is actually ok! */ c = bs->clusters_per_mft_record; - Dprintf("ClusterSize = 0x%x\n", (unsigned)vol->cluster_size); - Dprintf("ClusterSizeBits = %u\n", vol->cluster_size_bits); - Dprintf("ClustersPerMftRecord = 0x%x\n", c); + ntfs_log_debug("ClusterSize = 0x%x\n", (unsigned)vol->cluster_size); + ntfs_log_debug("ClusterSizeBits = %u\n", vol->cluster_size_bits); + ntfs_log_debug("ClustersPerMftRecord = 0x%x\n", c); /* * When clusters_per_mft_record is negative, it means that it is to * be taken to be the negative base 2 logarithm of the mft_record_size @@ -236,24 +239,24 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) else vol->mft_record_size = c << vol->cluster_size_bits; if (vol->mft_record_size & (vol->mft_record_size - 1)) { - Dprintf("Error: %s is not a valid NTFS partition! " + ntfs_log_debug("Error: %s is not a valid NTFS partition! " "mft_record_size is not a power of 2.\n", vol->dev->d_name); return -1; } vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1; - Dprintf("MftRecordSize = 0x%x\n", (unsigned)vol->mft_record_size); - Dprintf("MftRecordSizeBits = %u\n", vol->mft_record_size_bits); + ntfs_log_debug("MftRecordSize = 0x%x\n", (unsigned)vol->mft_record_size); + ntfs_log_debug("MftRecordSizeBits = %u\n", vol->mft_record_size_bits); /* Same as above for INDX record. */ c = bs->clusters_per_index_record; - Dprintf("ClustersPerINDXRecord = 0x%x\n", c); + ntfs_log_debug("ClustersPerINDXRecord = 0x%x\n", c); if (c < 0) vol->indx_record_size = 1 << -c; else vol->indx_record_size = c << vol->cluster_size_bits; vol->indx_record_size_bits = ffs(vol->indx_record_size) - 1; - Dprintf("INDXRecordSize = 0x%x\n", (unsigned)vol->indx_record_size); - Dprintf("INDXRecordSizeBits = %u\n", vol->indx_record_size_bits); + ntfs_log_debug("INDXRecordSize = 0x%x\n", (unsigned)vol->indx_record_size); + ntfs_log_debug("INDXRecordSizeBits = %u\n", vol->indx_record_size_bits); /* * Work out the size of the MFT mirror in number of mft records. If the * cluster size is less than or equal to the size taken by four mft diff --git a/libntfs/collate.c b/libntfs/collate.c index 15251b09..08128ca1 100644 --- a/libntfs/collate.c +++ b/libntfs/collate.c @@ -1,4 +1,4 @@ -/* +/** * collate.c - NTFS collation handling. Part of the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov @@ -20,17 +20,25 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "collate.h" #include "debug.h" #include "unistr.h" +#include "logging.h" +/** + * ntfs_collate_binary + */ static int ntfs_collate_binary(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) { int rc; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); rc = memcmp(data1, data2, min(data1_len, data2_len)); if (!rc && (data1_len != data2_len)) { if (data1_len < data2_len) @@ -38,10 +46,13 @@ static int ntfs_collate_binary(ntfs_volume *vol __attribute__((unused)), else rc = 1; } - ntfs_debug("Done, returning %i.", rc); + ntfs_log_trace("Done, returning %i.", rc); return rc; } +/** + * ntfs_collate_ntofs_ulong + */ static int ntfs_collate_ntofs_ulong(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) @@ -49,9 +60,9 @@ static int ntfs_collate_ntofs_ulong(ntfs_volume *vol __attribute__((unused)), int rc; u32 d1, d2; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (data1_len != data2_len || data1_len != 4) { - ntfs_error(, "data1_len or/and data2_len not equal to 4."); + ntfs_log_error("data1_len or/and data2_len not equal to 4."); return NTFS_COLLATION_ERROR; } d1 = le32_to_cpup(data1); @@ -64,24 +75,27 @@ static int ntfs_collate_ntofs_ulong(ntfs_volume *vol __attribute__((unused)), else rc = 1; } - ntfs_debug("Done, returning %i.", rc); + ntfs_log_trace("Done, returning %i.\n", rc); return rc; } +/** + * ntfs_collate_file_name + */ static int ntfs_collate_file_name(ntfs_volume *vol, const void *data1, const int data1_len __attribute__((unused)), const void *data2, const int data2_len __attribute__((unused))) { int rc; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); rc = ntfs_file_values_compare(data1, data2, NTFS_COLLATION_ERROR, IGNORE_CASE, vol->upcase, vol->upcase_len); if (!rc) rc = ntfs_file_values_compare(data1, data2, NTFS_COLLATION_ERROR, CASE_SENSITIVE, vol->upcase, vol->upcase_len); - ntfs_debug("Done, returning %i.", rc); + ntfs_log_trace("Done, returning %i.\n", rc); return rc; } @@ -125,9 +139,9 @@ int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr, { int i; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (!vol || !data1 || !data2 || data1_len < 0 || data2_len < 0) { - ntfs_error(, "Invalid arguments passed."); + ntfs_log_error("Invalid arguments passed."); return NTFS_COLLATION_ERROR; } /* @@ -151,6 +165,6 @@ int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr, return ntfs_do_collate0x1[i](vol, data1, data1_len, data2, data2_len); err: - ntfs_error(, "Unknown collation rule."); + ntfs_log_debug("Unknown collation rule.\n"); return NTFS_COLLATION_ERROR; } diff --git a/libntfs/compat.c b/libntfs/compat.c index 0ea141dc..636987d5 100644 --- a/libntfs/compat.c +++ b/libntfs/compat.c @@ -1,4 +1,4 @@ -/* +/** * compat.c - Tweaks for Windows compatibility * * Copyright (c) 2002 Richard Russon @@ -22,7 +22,9 @@ #ifdef WINDOWS +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #include "compat.h" diff --git a/libntfs/compress.c b/libntfs/compress.c index 869e8de0..abf44d0d 100644 --- a/libntfs/compress.c +++ b/libntfs/compress.c @@ -1,4 +1,4 @@ -/* +/** * compress.c - Compressed attribute handling code. Part of the Linux-NTFS * project. * @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDIO_H #include @@ -43,6 +45,7 @@ #include "layout.h" #include "runlist.h" #include "compress.h" +#include "logging.h" /** * ntfs_compression_constants - enum of constants used in the compression code @@ -93,9 +96,9 @@ static int ntfs_decompress(u8 *dest, const u32 dest_size, u8 tag; /* Current tag. */ int token; /* Loop counter for the eight tokens in tag. */ - Dprintf("Entering, cb_size = 0x%x.\n", (unsigned)cb_size); + ntfs_log_trace("Entering, cb_size = 0x%x.\n", (unsigned)cb_size); do_next_sb: - Dprintf("Beginning sub-block at offset = 0x%x in the cb.\n", + ntfs_log_debug("Beginning sub-block at offset = 0x%x in the cb.\n", cb - cb_start); /* * Have we reached the end of the compression block or the end of the @@ -104,7 +107,7 @@ do_next_sb: * first two checks do not detect it. */ if (cb == cb_end || !le16_to_cpup((u16*)cb) || dest == dest_end) { - Dprintf("Completed. Returning success (0).\n"); + ntfs_log_debug("Completed. Returning success (0).\n"); return 0; } /* Setup offset for the current sub-block destination. */ @@ -124,7 +127,7 @@ do_next_sb: goto return_overflow; /* Now, we are ready to process the current sub-block (sb). */ if (!(le16_to_cpup((u16*)cb) & NTFS_SB_IS_COMPRESSED)) { - Dprintf("Found uncompressed sub-block.\n"); + ntfs_log_debug("Found uncompressed sub-block.\n"); /* This sb is not compressed, just copy it into destination. */ /* Advance source position to first data byte. */ cb += 2; @@ -138,7 +141,7 @@ do_next_sb: dest += NTFS_SB_SIZE; goto do_next_sb; } - Dprintf("Found compressed sub-block.\n"); + ntfs_log_debug("Found compressed sub-block.\n"); /* This sb is compressed, decompress it into destination. */ /* Forward to the first tag in the sub-block. */ cb += 2; @@ -148,7 +151,7 @@ do_next_tag: if (dest < dest_sb_end) { int nr_bytes = dest_sb_end - dest; - Dprintf("Filling incomplete sub-block with zeroes.\n"); + ntfs_log_debug("Filling incomplete sub-block with zeroes.\n"); /* Zero remainder and update destination position. */ memset(dest, 0, nr_bytes); dest += nr_bytes; @@ -238,7 +241,7 @@ do_next_tag: /* No tokens left in the current tag. Continue with the next tag. */ goto do_next_tag; return_overflow: - Dprintf("Failed. Returning -EOVERFLOW.\n"); + ntfs_log_debug("Failed. Returning -EOVERFLOW.\n"); errno = EOVERFLOW; return -1; } @@ -329,8 +332,7 @@ s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b) int err; unsigned int nr_cbs, cb_clusters; - Dprintf("%s(): Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, " - "count 0x%llx.\n", __FUNCTION__, + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, count 0x%llx.\n", (unsigned long long)na->ni->mft_no, na->type, (long long)pos, (long long)count); if (!na || !NAttrCompressed(na) || !na->ni || !na->ni->vol || !b || @@ -421,7 +423,7 @@ do_next_cb: } if (rl->lcn == LCN_HOLE) { /* Sparse cb, zero out destination range overlapping the cb. */ - Dprintf("Found sparse compression block.\n"); + ntfs_log_debug("Found sparse compression block.\n"); to_read = min(count, cb_size - ofs); memset(b, 0, to_read); ofs = 0; @@ -434,7 +436,7 @@ do_next_cb: * Uncompressed cb, read it straight into the destination range * overlapping the cb. */ - Dprintf("Found uncompressed compression block.\n"); + ntfs_log_debug("Found uncompressed compression block.\n"); /* * Read the uncompressed data into the destination buffer. * NOTE: We cheat a little bit here by marking the attribute as @@ -480,7 +482,7 @@ do_next_cb: * Compressed cb, decompress it into the temporary buffer, then * copy the data to the destination range overlapping the cb. */ - Dprintf("Found compressed compression block.\n"); + ntfs_log_debug("Found compressed compression block.\n"); /* * Read the compressed data into the temporary buffer. * NOTE: We cheat a little bit here by marking the attribute as @@ -520,7 +522,7 @@ do_next_cb: /* Just a precaution. */ if (cb_pos + 2 <= cb_end) *(u16*)cb_pos = 0; - Dprintf("Successfully read the compression block.\n"); + ntfs_log_debug("Successfully read the compression block.\n"); if (ntfs_decompress(dest, cb_size, cb, cb_size) < 0) { err = errno; free(cb); diff --git a/libntfs/debug.c b/libntfs/debug.c index 55008543..c9803ca5 100644 --- a/libntfs/debug.c +++ b/libntfs/debug.c @@ -1,4 +1,4 @@ -/* +/** * debug.c - Debugging output functions. Part of the Linux-NTFS project. * * Copyright (c) 2002-2004 Anton Altaparmakov @@ -19,11 +19,14 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #include "types.h" #include "attrib.h" #include "debug.h" +#include "logging.h" /** * Sprintf - silencable output to stderr @@ -61,6 +64,9 @@ void __Sprintf(const int silent, const char *fmt, ...) /* Debug output to stderr. To get it run ./configure --enable-debug. */ +/** + * __ntfs_error + */ void __ntfs_error(const char *function, const char *fmt, ...) { int eo = errno; @@ -78,7 +84,10 @@ void __ntfs_error(const char *function, const char *fmt, ...) errno = eo; } -void __ntfs_debug (const char *file, int line, const char *function, +/** + * __ntfs_debug + */ +void __ntfs_debug(const char *file, int line, const char *function, const char *fmt, ...) { int eo = errno; @@ -96,6 +105,9 @@ void __ntfs_debug (const char *file, int line, const char *function, errno = eo; } +/** + * __Dprintf + */ void __Dprintf(const char *fmt, ...) { int eo = errno; @@ -107,6 +119,9 @@ void __Dprintf(const char *fmt, ...) errno = eo; } +/** + * __Dputs + */ void __Dputs(const char *s) { int eo = errno; @@ -114,6 +129,9 @@ void __Dputs(const char *s) errno = eo; } +/** + * __Dperror + */ void __Dperror(const char *s) { int eo = errno; @@ -121,6 +139,9 @@ void __Dperror(const char *s) errno = eo; } +#endif + +#ifndef NTFS_DISABLE_DEBUG_LOGGING /** * ntfs_debug_runlist_dump - Dump a runlist. */ @@ -131,12 +152,12 @@ void ntfs_debug_runlist_dump(const runlist_element *rl) "LCN_ENOENT ", "LCN_EINVAL ", "LCN_unknown " }; - Dputs("NTFS-fs DEBUG: Dumping runlist (values in hex):"); + ntfs_log_debug("NTFS-fs DEBUG: Dumping runlist (values in hex):\n"); if (!rl) { - Dputs("Run list not present."); + ntfs_log_debug("Run list not present.\n"); return; } - Dputs("VCN LCN Run length"); + ntfs_log_debug("VCN LCN Run length\n"); do { LCN lcn = (rl + i)->lcn; @@ -145,14 +166,11 @@ void ntfs_debug_runlist_dump(const runlist_element *rl) if (idx > -LCN_EINVAL - 1) idx = 4; - Dprintf("%-16llx %s %-16llx%s\n", rl[i].vcn, - lcn_str[idx], rl[i].length, - rl[i].length ? "" : " (runlist end)"); + ntfs_log_debug("%-16llx %s %-16llx%s\n", rl[i].vcn, lcn_str[idx], rl[i].length, rl[i].length ? "" : " (runlist end)"); } else - Dprintf("%-16llx %-16llx %-16llx%s\n", rl[i].vcn, - rl[i].lcn, rl[i].length, - rl[i].length ? "" : " (runlist end)"); + ntfs_log_debug("%-16llx %-16llx %-16llx%s\n", rl[i].vcn, rl[i].lcn, rl[i].length, rl[i].length ? "" : " (runlist end)"); } while (rl[i++].length); } #endif + diff --git a/libntfs/device.c b/libntfs/device.c index 83da11c3..a78319fe 100644 --- a/libntfs/device.c +++ b/libntfs/device.c @@ -1,4 +1,4 @@ -/* +/** * device.c - Low level device io functions. Part of the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov @@ -19,7 +19,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_UNISTD_H #include @@ -46,19 +48,20 @@ #include #endif #ifdef HAVE_SYS_IOCTL_H -# include +#include #endif #ifdef HAVE_LINUX_FD_H -# include +#include #endif #ifdef HAVE_LINUX_HDREG_H -# include +#include #endif #include "types.h" #include "mst.h" #include "debug.h" #include "device.h" +#include "logging.h" #if defined(linux) && defined(_IO) && !defined(BLKGETSIZE) #define BLKGETSIZE _IO(0x12,96) /* Get device size in 512-byte blocks. */ @@ -132,8 +135,7 @@ int ntfs_device_free(struct ntfs_device *dev) errno = EBUSY; return -1; } - if (dev->d_name) - free(dev->d_name); + free(dev->d_name); free(dev); return 0; } @@ -162,8 +164,7 @@ s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, void *b) s64 br, total; struct ntfs_device_operations *dops; - Dprintf("%s(): Entering for pos 0x%llx, count 0x%llx.\n", __FUNCTION__, - pos, count); + ntfs_log_trace("Entering for pos 0x%llx, count 0x%llx.\n", pos, count); if (!b || count < 0 || pos < 0) { errno = EINVAL; return -1; @@ -173,8 +174,8 @@ s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, void *b) dops = dev->d_ops; /* Locate to position. */ if (dops->seek(dev, pos, SEEK_SET) == (off_t)-1) { - Dprintf("ntfs_pread: device seek to 0x%llx returned error: " - "%s\n", pos, strerror(errno)); + ntfs_log_perror("ntfs_pread: device seek to 0x%llx returned error", + pos); return -1; } /* Read the data. */ @@ -218,8 +219,7 @@ s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, s64 written, total; struct ntfs_device_operations *dops; - Dprintf("%s(): Entering for pos 0x%llx, count 0x%llx.\n", __FUNCTION__, - pos, count); + ntfs_log_trace("Entering for pos 0x%llx, count 0x%llx.\n", pos, count); if (!b || count < 0 || pos < 0) { errno = EINVAL; return -1; @@ -233,8 +233,8 @@ s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, dops = dev->d_ops; /* Locate to position. */ if (dops->seek(dev, pos, SEEK_SET) == (off_t)-1) { - Dprintf("ntfs_pwrite: seek to 0x%llx returned error: %s\n", - pos, strerror(errno)); + ntfs_log_perror("ntfs_pwrite: seek to 0x%llx returned error", + pos); return -1; } NDevSetDirty(dev); @@ -405,7 +405,7 @@ s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn, const s64 count, br = ntfs_pread(vol->dev, lcn << vol->cluster_size_bits, count << vol->cluster_size_bits, b); if (br < 0) { - Dperror("Error reading cluster(s)"); + ntfs_log_perror("Error reading cluster(s)"); return br; } return br >> vol->cluster_size_bits; @@ -441,7 +441,7 @@ s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, else bw = count << vol->cluster_size_bits; if (bw < 0) { - Dperror("Error writing cluster(s)"); + ntfs_log_perror("Error writing cluster(s)"); return bw; } return bw >> vol->cluster_size_bits; @@ -491,7 +491,7 @@ s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size) { u64 size; if (dev->d_ops->ioctl(dev, BLKGETSIZE64, &size) >= 0) { - Dprintf("BLKGETSIZE64 nr bytes = %llu (0x%llx)\n", + ntfs_log_debug("BLKGETSIZE64 nr bytes = %llu (0x%llx)\n", (unsigned long long)size, (unsigned long long)size); return (s64)size / block_size; @@ -502,8 +502,8 @@ s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size) { unsigned long size; if (dev->d_ops->ioctl(dev, BLKGETSIZE, &size) >= 0) { - Dprintf("BLKGETSIZE nr 512 byte blocks = %lu " - "(0x%lx)\n", size, size); + ntfs_log_debug("BLKGETSIZE nr 512 byte blocks = %lu (0x%lx)\n", + size, size); return (s64)size * 512 / block_size; } } @@ -512,7 +512,7 @@ s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size) { struct floppy_struct this_floppy; if (dev->d_ops->ioctl(dev, FDGETPRM, &this_floppy) >= 0) { - Dprintf("FDGETPRM nr 512 byte blocks = %lu (0x%lx)\n", + ntfs_log_debug("FDGETPRM nr 512 byte blocks = %lu (0x%lx)\n", (unsigned long)this_floppy.size, (unsigned long)this_floppy.size); return (s64)this_floppy.size * 512 / block_size; @@ -560,7 +560,7 @@ s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev) { struct hd_geometry geo; if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { - Dprintf("HDIO_GETGEO start_sect = %lu (0x%lx)\n", + ntfs_log_debug("HDIO_GETGEO start_sect = %lu (0x%lx)\n", geo.start, geo.start); return geo.start; } @@ -593,7 +593,7 @@ int ntfs_device_heads_get(struct ntfs_device *dev) { struct hd_geometry geo; if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { - Dprintf("HDIO_GETGEO heads = %u (0x%x)\n", + ntfs_log_debug("HDIO_GETGEO heads = %u (0x%x)\n", (unsigned)geo.heads, (unsigned)geo.heads); return geo.heads; @@ -627,7 +627,7 @@ int ntfs_device_sectors_per_track_get(struct ntfs_device *dev) { struct hd_geometry geo; if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { - Dprintf("HDIO_GETGEO sectors_per_track = %u (0x%x)\n", + ntfs_log_debug("HDIO_GETGEO sectors_per_track = %u (0x%x)\n", (unsigned)geo.sectors, (unsigned)geo.sectors); return geo.sectors; diff --git a/libntfs/dir.c b/libntfs/dir.c index 4866e6d9..fc2756f8 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -1,4 +1,4 @@ -/* +/** * dir.c - Directory handling code. Part of the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov @@ -21,16 +21,18 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H -# include +#include #endif #ifdef HAVE_ERRNO_H -# include +#include #endif #ifdef HAVE_STRING_H -# include +#include #endif #include "types.h" @@ -43,6 +45,7 @@ #include "index.h" #include "ntfstime.h" #include "lcnalloc.h" +#include "logging.h" /* * The little endian Unicode strings "$I30", "$SII", "$SDH", "$O" @@ -116,10 +119,8 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, const ntfschar *uname, /* Find the index root attribute in the mft record. */ if (ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0, ctx)) { - Dprintf("Index root attribute missing in directory inode " - "0x%llx: %s\n", - (unsigned long long)dir_ni->mft_no, - strerror(errno)); + ntfs_log_perror("Index root attribute missing in directory inode " + "0x%llx", (unsigned long long)dir_ni->mft_no); goto put_err_out; } /* Get to the index root value. */ @@ -128,7 +129,7 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, const ntfschar *uname, index_block_size = le32_to_cpu(ir->index_block_size); if (index_block_size < NTFS_BLOCK_SIZE || index_block_size & (index_block_size - 1)) { - Dprintf("Index block size %u is invalid.\n", + ntfs_log_debug("Index block size %u is invalid.\n", (unsigned)index_block_size); goto put_err_out; } @@ -187,12 +188,12 @@ found_it: IGNORE_CASE, vol->upcase, vol->upcase_len)) { /* Only one case insensitive matching name allowed. */ if (mref) { - Dputs("Found already cached mft reference in " - "phase 1. Please run chkdsk " - "and if that doesn't find any " - "errors please report you saw " - "this message to " - "linux-ntfs-dev@lists.sf.net."); + ntfs_log_debug("Found already cached mft reference " + "in phase 1. Please run " + "chkdsk and if that doesn't " + "find any errors please report " + "you saw this message to " + "linux-ntfs-dev@lists.sf.net.\n"); goto put_err_out; } mref = le64_to_cpu(ie->indexed_file); @@ -245,7 +246,7 @@ found_it: ntfs_attr_put_search_ctx(ctx); if (mref) return mref; - Dputs("Entry not found."); + ntfs_log_debug("Entry not found.\n"); errno = ENOENT; return -1; } /* Child node present, descend into it. */ @@ -253,17 +254,16 @@ found_it: /* Open the index allocation attribute. */ ia_na = ntfs_attr_open(dir_ni, AT_INDEX_ALLOCATION, I30, 4); if (!ia_na) { - Dprintf("Failed to open index allocation attribute. Directory " - "inode 0x%llx is corrupt or driver bug: %s\n", - (unsigned long long)dir_ni->mft_no, - strerror(errno)); + ntfs_log_perror("Failed to open index allocation attribute. Directory " + "inode 0x%llx is corrupt or driver bug", + (unsigned long long)dir_ni->mft_no); goto put_err_out; } /* Allocate a buffer for the current index block. */ ia = (INDEX_ALLOCATION*)malloc(index_block_size); if (!ia) { - Dperror("Failed to allocate buffer for index block"); + ntfs_log_perror("Failed to allocate buffer for index block"); ntfs_attr_close(ia_na); goto put_err_out; } @@ -288,33 +288,33 @@ descend_into_child_node: if (br != 1) { if (br != -1) errno = EIO; - Dprintf("Failed to read vcn 0x%llx: %s\n", vcn, strerror(errno)); + ntfs_log_perror("Failed to read vcn 0x%llx", vcn); goto close_err_out; } if (sle64_to_cpu(ia->index_block_vcn) != vcn) { - Dprintf("Actual VCN (0x%llx) of index buffer is different from " - "expected VCN (0x%llx).\n", + ntfs_log_debug("Actual VCN (0x%llx) of index buffer is different " + "from expected VCN (0x%llx).\n", (long long)sle64_to_cpu(ia->index_block_vcn), (long long)vcn); errno = EIO; goto close_err_out; } if (le32_to_cpu(ia->index.allocated_size) + 0x18 != index_block_size) { - Dprintf("Index buffer (VCN 0x%llx) of directory inode 0x%llx " + ntfs_log_debug("Index buffer (VCN 0x%llx) of directory inode 0x%llx " "has a size (%u) differing from the directory " "specified size (%u).\n", (long long)vcn, - (unsigned long long)dir_ni->mft_no, (unsigned) - le32_to_cpu(ia->index.allocated_size) + 0x18, + (unsigned long long)dir_ni->mft_no, + (unsigned) le32_to_cpu(ia->index.allocated_size) + 0x18, (unsigned)index_block_size); errno = EIO; goto close_err_out; } index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); if (index_end > (u8*)ia + index_block_size) { - Dprintf("Size of index buffer (VCN 0x%llx) of directory inode " - "0x%llx exceeds maximum size.\n", (long long)vcn, - (unsigned long long)dir_ni->mft_no); + ntfs_log_debug("Size of index buffer (VCN 0x%llx) of directory inode " + "0x%llx exceeds maximum size.\n", + (long long)vcn, (unsigned long long)dir_ni->mft_no); errno = EIO; goto close_err_out; } @@ -333,8 +333,8 @@ descend_into_child_node: sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->key_length) > index_end) { - Dprintf("Index entry out of bounds in directory inode " - "0x%llx.\n", + ntfs_log_debug("Index entry out of bounds in directory " + "inode 0x%llx.\n", (unsigned long long)dir_ni->mft_no); errno = EIO; goto close_err_out; @@ -381,12 +381,12 @@ found_it2: IGNORE_CASE, vol->upcase, vol->upcase_len)) { /* Only one case insensitive matching name allowed. */ if (mref) { - Dputs("Found already cached mft reference in " - "phase 2. Please run chkdsk " - "and if that doesn't find any " - "errors please report you saw " - "this message to " - "linux-ntfs-dev@lists.sf.net."); + ntfs_log_debug("Found already cached mft reference " + "in phase 2. Please run " + "chkdsk and if that doesn't " + "find any errors please report " + "you saw this message to " + "linux-ntfs-dev@lists.sf.net.\n"); goto close_err_out; } mref = le64_to_cpu(ie->indexed_file); @@ -435,7 +435,7 @@ found_it2: */ if (ie->flags & INDEX_ENTRY_NODE) { if ((ia->index.flags & NODE_MASK) == LEAF_NODE) { - Dprintf("Index entry with child node found in a leaf " + ntfs_log_debug("Index entry with child node found in a leaf " "node in directory inode 0x%llx.\n", (unsigned long long)dir_ni->mft_no); errno = EIO; @@ -445,8 +445,8 @@ found_it2: vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8); if (vcn >= 0) goto descend_into_child_node; - Dprintf("Negative child node vcn in directory inode 0x%llx.\n", - (unsigned long long)dir_ni->mft_no); + ntfs_log_debug("Negative child node vcn in directory inode " + "0x%llx.\n", (unsigned long long)dir_ni->mft_no); errno = EIO; goto close_err_out; } @@ -460,12 +460,12 @@ found_it2: */ if (mref) return mref; - Dputs("Entry not found."); + ntfs_log_debug("Entry not found.\n"); errno = ENOENT; return -1; put_err_out: eo = EIO; - Dputs("Corrupt directory. Aborting lookup."); + ntfs_log_debug("Corrupt directory. Aborting lookup.\n"); eo_put_err_out: ntfs_attr_put_search_ctx(ctx); errno = eo; @@ -511,7 +511,7 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, } else { ni = ntfs_inode_open(vol, FILE_root); if (!ni) { - Dprintf("Couldn't open the inode of the root " + ntfs_log_debug("Couldn't open the inode of the root " "directory.\n"); err = EIO; goto close; @@ -521,7 +521,7 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, unicode = calloc(1, MAX_PATH); ascii = strdup(pathname); if (!unicode || !ascii) { - Dprintf("Out of memory.\n"); + ntfs_log_debug("Out of memory.\n"); err = ENOMEM; goto close; } @@ -540,15 +540,15 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, len = ntfs_mbstoucs(p, &unicode, MAX_PATH); if (len < 0) { - Dprintf("Couldn't convert name to Unicode: %s.\n", p); + ntfs_log_debug("Couldn't convert name to Unicode: %s.\n", p); err = EILSEQ; goto close; } inum = ntfs_inode_lookup_by_name(ni, unicode, len); if (inum == (u64) -1) { - Dprintf("Couldn't find name '%s' in " - "pathname '%s'.\n", p, pathname); + ntfs_log_debug("Couldn't find name '%s' in pathname " + "'%s'.\n", p, pathname); err = ENOENT; goto close; } @@ -559,7 +559,7 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, inum = MREF(inum); ni = ntfs_inode_open(vol, inum); if (!ni) { - Dprintf("Cannot open inode %llu: %s.\n", + ntfs_log_debug("Cannot open inode %llu: %s.\n", (unsigned long long)inum, p); err = EIO; goto close; @@ -595,7 +595,7 @@ static const ntfschar dotdot[3] = { const_cpu_to_le16('.'), typedef union { INDEX_ROOT *ir; INDEX_ALLOCATION *ia; -} index_union __attribute__ ((__transparent_union__)); +} index_union __attribute__((__transparent_union__)); typedef enum { INDEX_TYPE_ROOT, /* index root */ @@ -681,12 +681,12 @@ static MFT_REF ntfs_mft_get_parent_ref(ntfs_inode *ni) if (!ctx) return ERR_MREF(-1); if (ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { - Dprintf("No file name found in inode 0x%llx. Corrupt inode.\n", - (unsigned long long)ni->mft_no); + ntfs_log_debug("No file name found in inode 0x%llx. Corrupt " + "inode.\n", (unsigned long long)ni->mft_no); goto err_out; } if (ctx->attr->non_resident) { - Dprintf("File name attribute must be resident. Corrupt inode " + ntfs_log_debug("File name attribute must be resident. Corrupt inode " "0x%llx.\n", (unsigned long long)ni->mft_no); goto io_err_out; } @@ -694,7 +694,7 @@ static MFT_REF ntfs_mft_get_parent_ref(ntfs_inode *ni) le16_to_cpu(ctx->attr->value_offset)); if ((u8*)fn + le32_to_cpu(ctx->attr->value_length) > (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) { - Dprintf("Corrupt file name attribute in inode 0x%llx.\n", + ntfs_log_debug("Corrupt file name attribute in inode 0x%llx.\n", (unsigned long long)ni->mft_no); goto io_err_out; } @@ -753,18 +753,16 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, vol = dir_ni->vol; - Dprintf("Entering for inode 0x%llx, *pos 0x%llx.\n", + ntfs_log_trace("Entering for inode 0x%llx, *pos 0x%llx.\n", (unsigned long long)dir_ni->mft_no, (long long)*pos); /* Open the index allocation attribute. */ ia_na = ntfs_attr_open(dir_ni, AT_INDEX_ALLOCATION, I30, 4); if (!ia_na) { if (errno != ENOENT) { - Dprintf("Failed to open index allocation attribute. " - "Directory inode 0x%llx is corrupt or " - "bug: %s\n", - (unsigned long long)dir_ni->mft_no, - strerror(errno)); + ntfs_log_perror("Failed to open index allocation attribute. " + "Directory inode 0x%llx is corrupt or bug", + (unsigned long long)dir_ni->mft_no); return -1; } i_size = 0; @@ -792,7 +790,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, parent_mref = ntfs_mft_get_parent_ref(dir_ni); if (parent_mref == ERR_MREF(-1)) { - Dperror("Parent directory not found"); + ntfs_log_perror("Parent directory not found"); goto dir_err_out; } @@ -812,7 +810,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, /* Find the index root attribute in the mft record. */ if (ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0, ctx)) { - Dprintf("Index root attribute missing in directory inode " + ntfs_log_debug("Index root attribute missing in directory inode " "0x%llx.\n", (unsigned long long)dir_ni->mft_no); goto dir_err_out; } @@ -824,7 +822,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, index_block_size = le32_to_cpu(ir->index_block_size); if (index_block_size < NTFS_BLOCK_SIZE || index_block_size & (index_block_size - 1)) { - Dprintf("Index block size %u is invalid.\n", + ntfs_log_debug("Index block size %u is invalid.\n", (unsigned)index_block_size); goto dir_err_out; } @@ -854,7 +852,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, * or signals an error (both covered by the rc test). */ for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { - Dprintf("In index root, offset 0x%x.\n", (u8*)ie - (u8*)ir); + ntfs_log_debug("In index root, offset 0x%x.\n", (u8*)ie - (u8*)ir); /* Bounds checks. */ if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || @@ -897,13 +895,13 @@ skip_index_root: /* Allocate a buffer for the current index block. */ ia = (INDEX_ALLOCATION*)malloc(index_block_size); if (!ia) { - Dperror("Failed to allocate buffer for index block"); + ntfs_log_perror("Failed to allocate buffer for index block"); goto err_out; } bmp_na = ntfs_attr_open(dir_ni, AT_BITMAP, I30, 4); if (!bmp_na) { - Dperror("Failed to open index bitmap attribute"); + ntfs_log_perror("Failed to open index bitmap attribute"); goto dir_err_out; } @@ -912,14 +910,15 @@ skip_index_root: bmp_pos = ia_pos >> index_block_size_bits; if (bmp_pos >> 3 >= bmp_na->data_size) { - Dputs("Current index position exceeds index bitmap size."); + ntfs_log_debug("Current index position exceeds index bitmap " + "size.\n"); goto dir_err_out; } bmp_buf_size = min(bmp_na->data_size - (bmp_pos >> 3), 4096); bmp = (u8*)malloc(bmp_buf_size); if (!bmp) { - Dperror("Failed to allocate bitmap buffer"); + ntfs_log_perror("Failed to allocate bitmap buffer"); goto err_out; } @@ -927,7 +926,7 @@ skip_index_root: if (br != bmp_buf_size) { if (br != -1) errno = EIO; - Dperror("Failed to read from index bitmap attribute"); + ntfs_log_perror("Failed to read from index bitmap attribute"); goto err_out; } @@ -950,12 +949,12 @@ find_next_index_buffer: if (br != bmp_buf_size) { if (br != -1) errno = EIO; - Dperror("Failed to read from index bitmap attribute"); + ntfs_log_perror("Failed to read from index bitmap attribute"); goto err_out; } } - Dprintf("Handling index block 0x%llx.\n", (long long)bmp_pos); + ntfs_log_debug("Handling index block 0x%llx.\n", (long long)bmp_pos); /* Read the index block starting at bmp_pos. */ br = ntfs_attr_mst_pread(ia_na, bmp_pos << index_block_size_bits, 1, @@ -963,33 +962,33 @@ find_next_index_buffer: if (br != 1) { if (br != -1) errno = EIO; - Dperror("Failed to read index block"); + ntfs_log_perror("Failed to read index block"); goto err_out; } ia_start = ia_pos & ~(s64)(index_block_size - 1); if (sle64_to_cpu(ia->index_block_vcn) != ia_start >> index_vcn_size_bits) { - Dprintf("Actual VCN (0x%llx) of index buffer is different from " - "expected VCN (0x%llx) in inode 0x%llx.\n", + ntfs_log_debug("Actual VCN (0x%llx) of index buffer is different " + "from expected VCN (0x%llx) in inode 0x%llx.\n", (long long)sle64_to_cpu(ia->index_block_vcn), (long long)ia_start >> index_vcn_size_bits, (unsigned long long)dir_ni->mft_no); goto dir_err_out; } if (le32_to_cpu(ia->index.allocated_size) + 0x18 != index_block_size) { - Dprintf("Index buffer (VCN 0x%llx) of directory inode 0x%llx " + ntfs_log_debug("Index buffer (VCN 0x%llx) of directory inode 0x%llx " "has a size (%u) differing from the directory " - "specified size (%u).\n", - (long long)ia_start >> index_vcn_size_bits, - (unsigned long long)dir_ni->mft_no, (unsigned) - le32_to_cpu(ia->index.allocated_size) + 0x18, - (unsigned)index_block_size); + "specified size (%u).\n", (long long)ia_start >> + index_vcn_size_bits, + (unsigned long long)dir_ni->mft_no, + (unsigned) le32_to_cpu(ia->index.allocated_size) + + 0x18, (unsigned)index_block_size); goto dir_err_out; } index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); if (index_end > (u8*)ia + index_block_size) { - Dprintf("Size of index buffer (VCN 0x%llx) of directory inode " + ntfs_log_debug("Size of index buffer (VCN 0x%llx) of directory inode " "0x%llx exceeds maximum size.\n", (long long)ia_start >> index_vcn_size_bits, (unsigned long long)dir_ni->mft_no); @@ -1004,16 +1003,15 @@ find_next_index_buffer: * enough or signals an error (both covered by the rc test). */ for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { - Dprintf("In index allocation, offset 0x%llx.\n", + ntfs_log_debug("In index allocation, offset 0x%llx.\n", (long long)ia_start + ((u8*)ie - (u8*)ia)); /* Bounds checks. */ if ((u8*)ie < (u8*)ia || (u8*)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->key_length) > index_end) { - Dprintf("Index entry out of bounds in directory inode " - "0x%llx.\n", - (unsigned long long)dir_ni->mft_no); + ntfs_log_debug("Index entry out of bounds in directory inode " + "0x%llx.\n", (unsigned long long)dir_ni->mft_no); goto dir_err_out; } /* The last entry cannot contain a name. */ @@ -1036,19 +1034,17 @@ EOD: /* We are finished, set *pos to EOD. */ *pos = i_size + vol->mft_record_size; done: - if (ia) - free(ia); - if (bmp) - free(bmp); + free(ia); + free(bmp); if (bmp_na) ntfs_attr_close(bmp_na); if (ia_na) ntfs_attr_close(ia_na); #ifdef DEBUG if (!rc) - Dprintf("EOD, *pos 0x%llx, returning 0.\n", (long long)*pos); + ntfs_log_debug("EOD, *pos 0x%llx, returning 0.\n", (long long)*pos); else - Dprintf("filldir returned %i, *pos 0x%llx, returning 0.\n", + ntfs_log_debug("filldir returned %i, *pos 0x%llx, returning 0.\n", rc, (long long)*pos); #endif return 0; @@ -1056,13 +1052,11 @@ dir_err_out: errno = EIO; err_out: eo = errno; - Dprintf("%s() failed.\n", __FUNCTION__); + ntfs_log_trace("failed.\n"); if (ctx) ntfs_attr_put_search_ctx(ctx); - if (ia) - free(ia); - if (bmp) - free(bmp); + free(ia); + free(bmp); if (bmp_na) ntfs_attr_close(bmp_na); if (ia_na) @@ -1092,17 +1086,17 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, STANDARD_INFORMATION *si = NULL; int err, fn_len, si_len; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); /* Sanity checks. */ if (!dir_ni || !name || !name_len || (type != NTFS_DT_REG && type != NTFS_DT_DIR)) { - ntfs_error(, "Invalid arguments."); + ntfs_log_error("Invalid arguments."); return NULL; } /* Allocate MFT record for new file. */ ni = ntfs_mft_record_alloc(dir_ni->vol, NULL); if (!ni) { - ntfs_error(, "Failed to allocate new MFT record."); + ntfs_log_error("Failed to allocate new MFT record."); return NULL; } /* @@ -1113,7 +1107,7 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, si = calloc(1, si_len); if (!si) { err = errno; - ntfs_error(, "Not enough memory."); + ntfs_log_error("Not enough memory."); goto err_out; } si->creation_time = utc2ntfs(ni->creation_time); @@ -1124,7 +1118,7 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, if (ntfs_attr_add(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0, (u8*)si, si_len)) { err = errno; - ntfs_error(, "Failed to add STANDARD_INFORMATION attribute."); + ntfs_log_error("Failed to add STANDARD_INFORMATION attribute."); goto err_out; } if (type == NTFS_DT_DIR) { @@ -1138,7 +1132,7 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, ir = calloc(1, ir_len); if (!ir) { err = errno; - ntfs_error(, "Not enough memory."); + ntfs_log_error("Not enough memory."); goto err_out; } ir->type = AT_FILE_NAME; @@ -1162,14 +1156,14 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, if (ntfs_attr_add(ni, AT_INDEX_ROOT, I30, 4, (u8*)ir, ir_len)) { err = errno; free(ir); - ntfs_error(, "Failed to add INDEX_ROOT attribute."); + ntfs_log_error("Failed to add INDEX_ROOT attribute."); goto err_out; } } else { /* Add DATA attribute to inode. */ if (ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, NULL, 0)) { err = errno; - ntfs_error(, "Failed to add DATA attribute."); + ntfs_log_error("Failed to add DATA attribute."); goto err_out; } } @@ -1178,7 +1172,7 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, fn = calloc(1, fn_len); if (!fn) { err = errno; - ntfs_error(, "Not enough memory."); + ntfs_log_error("Not enough memory."); goto err_out; } fn->parent_directory = MK_LE_MREF(dir_ni->mft_no, @@ -1195,14 +1189,14 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, /* Add FILE_NAME attribute to inode. */ if (ntfs_attr_add(ni, AT_FILE_NAME, AT_UNNAMED, 0, (u8*)fn, fn_len)) { err = errno; - ntfs_error(, "Failed to add FILE_NAME attribute."); + ntfs_log_error("Failed to add FILE_NAME attribute."); goto err_out; } /* Add FILE_NAME attribute to index. */ if (ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)))) { err = errno; - ntfs_error(, "Failed to add entry to the index."); + ntfs_log_error("Failed to add entry to the index."); goto err_out; } /* Set hard links count and directory flag. */ @@ -1213,17 +1207,15 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, /* Done! */ free(fn); free(si); - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return ni; err_out: - ntfs_debug("Failed."); + ntfs_log_trace("Failed.\n"); if (ntfs_mft_record_free(ni->vol, ni)) - ntfs_error(, "Failed to free MFT record. " + ntfs_log_error("Failed to free MFT record. " "Leaving inconsist metadata. Run chkdsk."); - if (fn) - free(fn); - if (si) - free(si); + free(fn); + free(si); errno = err; return NULL; } @@ -1248,9 +1240,9 @@ int ntfs_delete(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) BOOL looking_for_dos_name = FALSE, looking_for_win32_name = FALSE; int err = 0; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (!ni || !dir_ni || !name || !name_len) { - ntfs_error(, "Invalid arguments."); + ntfs_log_error("Invalid arguments."); errno = EINVAL; goto err_out; } @@ -1264,14 +1256,14 @@ int ntfs_delete(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) na = ntfs_attr_open(ni, AT_INDEX_ROOT, I30, 4); if (!na) { - ntfs_error(, "Corrupt directory or library bug."); + ntfs_log_error("Corrupt directory or library bug."); errno = EIO; goto err_out; } if (na->data_size != sizeof(INDEX_ROOT) + sizeof(INDEX_ENTRY_HEADER)) { ntfs_attr_close(na); - ntfs_error(, "Directory is not empty."); + ntfs_log_error("Directory is not empty."); errno = ENOTEMPTY; goto err_out; } @@ -1376,13 +1368,13 @@ search: NULL); if (!rl) { err = errno; - ntfs_error(, "Failed to decompress runlist. " + ntfs_log_error("Failed to decompress runlist. " "Leaving inconsist metadata."); continue; } if (ntfs_cluster_free_from_rl(ni->vol, rl)) { err = errno; - ntfs_error(, "Failed to free clusters. " + ntfs_log_error("Failed to free clusters. " "Leaving inconsist metadata."); continue; } @@ -1391,19 +1383,19 @@ search: } if (errno != ENOENT) { err = errno; - ntfs_error(, "Atribute enumeration failed. " + ntfs_log_error("Atribute enumeration failed. " "Probably leaving inconsist metadata."); } /* All extents should be attached after attribute walk. */ while (ni->nr_extents) if (ntfs_mft_record_free(ni->vol, *(ni->extent_nis))) { err = errno; - ntfs_error(, "Failed to free extent MFT record. " + ntfs_log_error("Failed to free extent MFT record. " "Leaving inconsist metadata."); } if (ntfs_mft_record_free(ni->vol, ni)) { err = errno; - ntfs_error(, "Failed to free base MFT record. " + ntfs_log_error("Failed to free base MFT record. " "Leaving inconsist metadata."); } ni = NULL; @@ -1415,11 +1407,11 @@ out: if (ni) ntfs_inode_close(ni); if (err) { - ntfs_error(, "Failed."); + ntfs_log_error("Failed.\n"); errno = err; return -1; } - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return 0; err_out: err = errno; @@ -1440,10 +1432,10 @@ int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) FILE_NAME_ATTR *fn = NULL; int fn_len, err; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (!ni || !dir_ni || !name || !name_len) { err = errno; - ntfs_error(, "Invalid arguments."); + ntfs_log_error("Invalid arguments."); goto err_out; } /* Create FILE_NAME attribute. */ @@ -1451,7 +1443,7 @@ int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) fn = calloc(1, fn_len); if (!fn) { err = errno; - ntfs_error(, "Not enough memory."); + ntfs_log_error("Not enough memory."); goto err_out; } fn->parent_directory = MK_LE_MREF(dir_ni->mft_no, @@ -1469,7 +1461,7 @@ int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) if (ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)))) { err = errno; - ntfs_error(, "Failed to add entry to the index."); + ntfs_log_error("Failed to add entry to the index."); goto err_out; } /* Add FILE_NAME attribute to inode. */ @@ -1477,7 +1469,7 @@ int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) ntfs_index_context *ictx; err = errno; - ntfs_error(, "Failed to add FILE_NAME attribute."); + ntfs_log_error("Failed to add FILE_NAME attribute."); /* Try to remove just added attribute from index. */ ictx = ntfs_index_ctx_get(dir_ni, I30, 4); if (!ictx) @@ -1507,14 +1499,13 @@ int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) /* Done! */ ntfs_inode_mark_dirty(ni); free(fn); - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return 0; rollback_failed: - ntfs_error(, "Rollback failed. Leaving inconsist metadata."); + ntfs_log_error("Rollback failed. Leaving inconsist metadata."); err_out: - ntfs_error(, "Failed."); - if (fn) - free(fn); + ntfs_log_error("Failed.\n"); + free(fn); errno = err; return -1; } @@ -1536,21 +1527,21 @@ err_out: /** * ntfs_dir_rollback */ -int ntfs_dir_rollback (struct ntfs_dir *dir) +int ntfs_dir_rollback(struct ntfs_dir *dir) { int i; if (!dir) return -1; - if (ntfs_dt_rollback (dir->index) < 0) + if (ntfs_dt_rollback(dir->index) < 0) return -1; - if (ntfs_bmp_rollback (dir->bitmap) < 0) + if (ntfs_bmp_rollback(dir->bitmap) < 0) return -1; for (i = 0; i < dir->child_count; i++) { - if (ntfs_dir_rollback (dir->children[i]) < 0) + if (ntfs_dir_rollback(dir->children[i]) < 0) return -1; } @@ -1560,7 +1551,7 @@ int ntfs_dir_rollback (struct ntfs_dir *dir) /** * ntfs_dir_truncate */ -int ntfs_dir_truncate (ntfs_volume *vol, struct ntfs_dir *dir) +int ntfs_dir_truncate(ntfs_volume *vol, struct ntfs_dir *dir) { //int i; //u8 *buffer; @@ -1575,80 +1566,80 @@ int ntfs_dir_truncate (ntfs_volume *vol, struct ntfs_dir *dir) return 0; #if 0 - buf_count = ROUND_UP (dir->bitmap->attr->allocated_size, vol->cluster_size) >> vol->cluster_size_bits; - printf ("alloc = %lld bytes\n", dir->ialloc->allocated_size); - printf ("alloc = %lld clusters\n", dir->ialloc->allocated_size >> vol->cluster_size_bits); - printf ("bitmap bytes 0 to %lld\n", ((dir->ialloc->allocated_size >> vol->cluster_size_bits)-1)>>3); - printf ("bitmap = %p\n", dir->bitmap); - printf ("bitmap = %lld bytes\n", dir->bitmap->attr->allocated_size); - printf ("bitmap = %d buffers\n", buf_count); + buf_count = ROUND_UP(dir->bitmap->attr->allocated_size, vol->cluster_size) >> vol->cluster_size_bits; + ntfs_log_debug("alloc = %lld bytes\n", dir->ialloc->allocated_size); + ntfs_log_debug("alloc = %lld clusters\n", dir->ialloc->allocated_size >> vol->cluster_size_bits); + ntfs_log_debug("bitmap bytes 0 to %lld\n", ((dir->ialloc->allocated_size >> vol->cluster_size_bits)-1)>>3); + ntfs_log_debug("bitmap = %p\n", dir->bitmap); + ntfs_log_debug("bitmap = %lld bytes\n", dir->bitmap->attr->allocated_size); + ntfs_log_debug("bitmap = %d buffers\n", buf_count); #endif - last_bit = ntfs_bmp_find_last_set (dir->bitmap); + last_bit = ntfs_bmp_find_last_set(dir->bitmap); if (dir->ialloc->allocated_size == (dir->index_size * (last_bit + 1))) { - //printf ("nothing to do\n"); + //ntfs_log_debug("nothing to do\n"); return 0; } - printf (BOLD YELLOW "Truncation needed\n" END); + ntfs_log_debug(BOLD YELLOW "Truncation needed\n" END); #if 0 - printf ("\tlast bit = %lld\n", last_bit); - printf ("\tactual IALLOC size = %lld\n", dir->ialloc->allocated_size); - printf ("\tshould IALLOC size = %lld\n", dir->index_size * (last_bit + 1)); + ntfs_log_debug("\tlast bit = %lld\n", last_bit); + ntfs_log_debug("\tactual IALLOC size = %lld\n", dir->ialloc->allocated_size); + ntfs_log_debug("\tshould IALLOC size = %lld\n", dir->index_size * (last_bit + 1)); #endif if ((dir->index_size * (last_bit + 1)) == 0) { - printf ("root dt %d, vcn = %lld\n", dir->index->changed, dir->index->vcn); + ntfs_log_debug("root dt %d, vcn = %lld\n", dir->index->changed, dir->index->vcn); //rollback all dts - //ntfs_dt_rollback (dir->index); + //ntfs_dt_rollback(dir->index); //dir->index = NULL; // What about the ROOT dt? - ie = ntfs_ie_copy (dir->index->children[0]); + ie = ntfs_ie_copy(dir->index->children[0]); if (!ie) { - printf (RED "IE copy failed\n" END); + ntfs_log_debug(RED "IE copy failed\n" END); return -1; } - ie = ntfs_ie_remove_vcn (ie); + ie = ntfs_ie_remove_vcn(ie); if (!ie) { - printf (RED "IE remove vcn failed\n" END); + ntfs_log_debug(RED "IE remove vcn failed\n" END); return -1; } - //utils_dump_mem (dir->index->data, 0, dir->index->data_len, DM_DEFAULTS); printf ("\n"); - //utils_dump_mem (ie, 0, ie->length, DM_DEFAULTS); printf ("\n"); - ntfs_dt_root_replace (dir->index, 0, dir->index->children[0], ie); - //utils_dump_mem (dir->index->data, 0, dir->index->data_len, DM_DEFAULTS); printf ("\n"); - //printf ("root dt %d, vcn = %lld\n", dir->index->changed, dir->index->vcn); + //utils_dump_mem(dir->index->data, 0, dir->index->data_len, DM_DEFAULTS); ntfs_log_debug("\n"); + //utils_dump_mem(ie, 0, ie->length, DM_DEFAULTS); ntfs_log_debug("\n"); + ntfs_dt_root_replace(dir->index, 0, dir->index->children[0], ie); + //utils_dump_mem(dir->index->data, 0, dir->index->data_len, DM_DEFAULTS); ntfs_log_debug("\n"); + //ntfs_log_debug("root dt %d, vcn = %lld\n", dir->index->changed, dir->index->vcn); - ntfs_ie_free (ie); + ntfs_ie_free(ie); ie = NULL; //index flags remove LARGE_INDEX dir->index->header->flags = 0; //rollback dir's bmp - ntfs_bmp_free (dir->bitmap); + ntfs_bmp_free(dir->bitmap); dir->bitmap = NULL; /* for (i = 0; i < dir->index->child_count; i++) { - ntfs_dt_rollback (dir->index->sub_nodes[i]); + ntfs_dt_rollback(dir->index->sub_nodes[i]); dir->index->sub_nodes[i] = NULL; } */ - //printf ("dir->index->inodes[0] = %p\n", dir->index->inodes[0]); + //ntfs_log_debug("dir->index->inodes[0] = %p\n", dir->index->inodes[0]); //remove 0xA0 attribute - ntfs_mft_remove_attr (vol->private_bmp2, dir->inode, AT_INDEX_ALLOCATION); + ntfs_mft_remove_attr(vol->private_bmp2, dir->inode, AT_INDEX_ALLOCATION); //remove 0xB0 attribute - ntfs_mft_remove_attr (vol->private_bmp2, dir->inode, AT_BITMAP); + ntfs_mft_remove_attr(vol->private_bmp2, dir->inode, AT_BITMAP); } else { - printf (RED "Cannot shrink directory\n" END); + ntfs_log_debug(RED "Cannot shrink directory\n" END); //ntfs_dir_shrink_alloc //ntfs_dir_shrink_bitmap //make bitmap resident? @@ -1674,14 +1665,14 @@ int ntfs_dir_truncate (ntfs_volume *vol, struct ntfs_dir *dir) */ #if 0 - buffer = ntfs_bmp_get_data (dir->bitmap, 0); + buffer = ntfs_bmp_get_data(dir->bitmap, 0); if (!buffer) return -1; - utils_dump_mem (buffer, 0, 8, DM_NO_ASCII); + utils_dump_mem(buffer, 0, 8, DM_NO_ASCII); for (i = buf_count-1; i >= 0; i--) { if (buffer[i]) { - printf ("alloc in use\n"); + ntfs_log_debug("alloc in use\n"); return 0; } } @@ -1704,29 +1695,29 @@ int ntfs_dir_truncate (ntfs_volume *vol, struct ntfs_dir *dir) /** * ntfs_dir_commit */ -int ntfs_dir_commit (struct ntfs_dir *dir) +int ntfs_dir_commit(struct ntfs_dir *dir) { int i; if (!dir) return 0; - printf ("commit dir inode %llu\n", dir->inode->mft_no); - if (NInoDirty (dir->inode)) { + ntfs_log_debug("commit dir inode %llu\n", dir->inode->mft_no); + if (NInoDirty(dir->inode)) { #ifdef RM_WRITE - ntfs_inode_sync (dir->inode); + ntfs_inode_sync(dir->inode); #endif - printf (RED "\tntfs_inode_sync %llu\n" END, dir->inode->mft_no); + ntfs_log_debug(RED "\tntfs_inode_sync %llu\n" END, dir->inode->mft_no); } - if (ntfs_dt_commit (dir->index) < 0) + if (ntfs_dt_commit(dir->index) < 0) return -1; - if (ntfs_bmp_commit (dir->bitmap) < 0) + if (ntfs_bmp_commit(dir->bitmap) < 0) return -1; for (i = 0; i < dir->child_count; i++) { - if (ntfs_dir_commit (dir->children[i]) < 0) + if (ntfs_dir_commit(dir->children[i]) < 0) return -1; } @@ -1736,7 +1727,7 @@ int ntfs_dir_commit (struct ntfs_dir *dir) /** * ntfs_dir_free */ -void ntfs_dir_free (struct ntfs_dir *dir) +void ntfs_dir_free(struct ntfs_dir *dir) { struct ntfs_dir *parent; int i; @@ -1744,7 +1735,7 @@ void ntfs_dir_free (struct ntfs_dir *dir) if (!dir) return; - ntfs_dir_rollback (dir); + ntfs_dir_rollback(dir); parent = dir->parent; if (parent) { @@ -1755,25 +1746,25 @@ void ntfs_dir_free (struct ntfs_dir *dir) } } - ntfs_attr_close (dir->iroot); - ntfs_attr_close (dir->ialloc); - ntfs_inode_close2 (dir->inode); + ntfs_attr_close(dir->iroot); + ntfs_attr_close(dir->ialloc); + ntfs_inode_close2(dir->inode); ntfs_dt_free (dir->index); - ntfs_bmp_free (dir->bitmap); + ntfs_bmp_free(dir->bitmap); for (i = 0; i < dir->child_count; i++) - ntfs_dir_free (dir->children[i]); + ntfs_dir_free(dir->children[i]); - free (dir->name); - free (dir->children); - free (dir); + free(dir->name); + free(dir->children); + free(dir); } /** * ntfs_dir_create */ -struct ntfs_dir * ntfs_dir_create (ntfs_volume *vol, MFT_REF mft_num) +struct ntfs_dir * ntfs_dir_create(ntfs_volume *vol, MFT_REF mft_num) { struct ntfs_dir *dir = NULL; ntfs_inode *inode = NULL; @@ -1784,23 +1775,23 @@ struct ntfs_dir * ntfs_dir_create (ntfs_volume *vol, MFT_REF mft_num) if (!vol) return NULL; - //printf ("ntfs_dir_create %lld\n", MREF (mft_num)); - inode = ntfs_inode_open2 (vol, mft_num); + //ntfs_log_debug("ntfs_dir_create %lld\n", MREF(mft_num)); + inode = ntfs_inode_open2(vol, mft_num); if (!inode) return NULL; - dir = calloc (1, sizeof (*dir)); + dir = calloc(1, sizeof(*dir)); if (!dir) { - ntfs_inode_close2 (inode); + ntfs_inode_close2(inode); return NULL; } dir->inode = inode; - dir->iroot = ntfs_attr_open (inode, AT_INDEX_ROOT, I30, 4); - dir->ialloc = ntfs_attr_open (inode, AT_INDEX_ALLOCATION, I30, 4); + dir->iroot = ntfs_attr_open(inode, AT_INDEX_ROOT, I30, 4); + dir->ialloc = ntfs_attr_open(inode, AT_INDEX_ALLOCATION, I30, 4); if (!dir->iroot) { - ntfs_dir_free (dir); + ntfs_dir_free(dir); return NULL; } @@ -1814,10 +1805,10 @@ struct ntfs_dir * ntfs_dir_create (ntfs_volume *vol, MFT_REF mft_num) dir->mft_num = mft_num; // This may not exist - dir->bitmap = ntfs_bmp_create (inode, AT_BITMAP, I30, 4); + dir->bitmap = ntfs_bmp_create(inode, AT_BITMAP, I30, 4); if (dir->iroot) { - rec = find_first_attribute (AT_INDEX_ROOT, inode->mrec); + rec = find_first_attribute(AT_INDEX_ROOT, inode->mrec); ir = (INDEX_ROOT*) ((u8*)rec + rec->value_offset); dir->index_size = ir->index_block_size; } else { @@ -1826,12 +1817,12 @@ struct ntfs_dir * ntfs_dir_create (ntfs_volume *vol, MFT_REF mft_num) } // Finally, find the dir's name - rec = find_first_attribute (AT_FILE_NAME, inode->mrec); + rec = find_first_attribute(AT_FILE_NAME, inode->mrec); name = (FILE_NAME_ATTR*) ((u8*)rec + rec->value_offset); dir->name_len = name->file_name_length; - dir->name = malloc (sizeof (ntfschar) * dir->name_len); - memcpy (dir->name, name->file_name, sizeof (ntfschar) * dir->name_len); + dir->name = malloc(sizeof(ntfschar) * dir->name_len); + memcpy(dir->name, name->file_name, sizeof(ntfschar) * dir->name_len); return dir; } @@ -1839,14 +1830,14 @@ struct ntfs_dir * ntfs_dir_create (ntfs_volume *vol, MFT_REF mft_num) /** * ntfs_dir_add */ -void ntfs_dir_add (struct ntfs_dir *parent, struct ntfs_dir *child) +void ntfs_dir_add(struct ntfs_dir *parent, struct ntfs_dir *child) { if (!parent || !child) return; parent->child_count++; - //printf ("child count = %d\n", parent->child_count); - parent->children = realloc (parent->children, parent->child_count * sizeof (struct ntfs_dir*)); + //ntfs_log_debug("child count = %d\n", parent->child_count); + parent->children = realloc(parent->children, parent->child_count * sizeof(struct ntfs_dir*)); child->parent = parent; parent->children[parent->child_count-1] = child; @@ -1855,7 +1846,7 @@ void ntfs_dir_add (struct ntfs_dir *parent, struct ntfs_dir *child) /** * ntfs_dir_find2 */ -struct ntfs_dir * ntfs_dir_find2 (struct ntfs_dir *dir, ntfschar *name, int name_len) +struct ntfs_dir * ntfs_dir_find2(struct ntfs_dir *dir, ntfschar *name, int name_len) { int i; struct ntfs_dir *child = NULL; @@ -1868,12 +1859,12 @@ struct ntfs_dir * ntfs_dir_find2 (struct ntfs_dir *dir, ntfschar *name, int name return NULL; if (!dir->index) { // XXX when will this happen? - printf ("ntfs_dir_find2 - directory has no index\n"); + ntfs_log_debug("ntfs_dir_find2 - directory has no index\n"); return NULL; } for (i = 0; i < dir->child_count; i++) { - if (0 == ntfs_names_collate (name, name_len, + if (0 == ntfs_names_collate(name, name_len, dir->children[i]->name, dir->children[i]->name_len, 2, IGNORE_CASE, @@ -1882,9 +1873,9 @@ struct ntfs_dir * ntfs_dir_find2 (struct ntfs_dir *dir, ntfschar *name, int name return dir->children[i]; } - dt = ntfs_dt_find2 (dir->index, name, name_len, &dt_num); + dt = ntfs_dt_find2(dir->index, name, name_len, &dt_num); if (!dt) { - printf ("can't find name in dir\n"); + ntfs_log_debug("can't find name in dir\n"); return NULL; } @@ -1892,13 +1883,13 @@ struct ntfs_dir * ntfs_dir_find2 (struct ntfs_dir *dir, ntfschar *name, int name mft_num = ie->indexed_file; - child = ntfs_dir_create (dir->vol, mft_num); + child = ntfs_dir_create(dir->vol, mft_num); if (!child) return NULL; - child->index = ntfs_dt_create (child, NULL, -1); + child->index = ntfs_dt_create(child, NULL, -1); - ntfs_dir_add (dir, child); + ntfs_dir_add(dir, child); return child; } diff --git a/libntfs/index.c b/libntfs/index.c index 1824e478..f575039a 100644 --- a/libntfs/index.c +++ b/libntfs/index.c @@ -1,4 +1,4 @@ -/* +/** * index.c - NTFS index handling. Part of the Linux-NTFS project. * * Copyright (c) 2004-2005 Anton Altaparmakov @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -33,6 +35,7 @@ #include "index.h" #include "mst.h" #include "dir.h" +#include "logging.h" /** * ntfs_index_ctx_get - allocate and initialize a new index context @@ -85,7 +88,7 @@ void ntfs_index_ctx_put(ntfs_index_context *ictx) cluster_size_bits, 1, ictx->block_size, ictx->ia) != 1) - ntfs_error(, "Failed to write out " + ntfs_log_error("Failed to write out " "index block."); } /* Free resources. */ @@ -117,7 +120,7 @@ void ntfs_index_ctx_reinit(ntfs_index_context *ictx) cluster_size_bits, 1, ictx->block_size, ictx->ia) != 1) - ntfs_error(, "Failed to write out " + ntfs_log_error("Failed to write out " "index block."); } /* Free resources. */ @@ -179,7 +182,7 @@ int ntfs_index_lookup(const void *key, const int key_len, ntfs_attr *na = NULL; int rc, err = 0; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (!key || key_len <= 0) { errno = EINVAL; return -1; @@ -196,7 +199,7 @@ int ntfs_index_lookup(const void *key, const int key_len, CASE_SENSITIVE, 0, NULL, 0, actx); if (err) { if (errno == ENOENT) { - ntfs_error(sb, "Index root attribute missing in inode " + ntfs_log_error("Index root attribute missing in inode " "0x%llx.", ni->mft_no); err = EIO; } else @@ -212,7 +215,7 @@ int ntfs_index_lookup(const void *key, const int key_len, /* Get collation rule type and validate it. */ cr = ir->collation_rule; if (!ntfs_is_collation_rule_supported(cr)) { - ntfs_error(sb, "Index uses unsupported collation rule 0x%x. " + ntfs_log_error("Index uses unsupported collation rule 0x%x. " "Aborting lookup.", (unsigned)le32_to_cpu(cr)); err = EOPNOTSUPP; goto err_out; @@ -248,7 +251,7 @@ done: ictx->entry = ie; ictx->data = (u8*)ie + offsetof(INDEX_ENTRY, key); ictx->data_len = le16_to_cpu(ie->key_length); - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); if (err) { errno = err; return -1; @@ -262,7 +265,7 @@ done: rc = ntfs_collate(vol, cr, key, key_len, &ie->key, le16_to_cpu(ie->key_length)); if (rc == NTFS_COLLATION_ERROR) { - ntfs_error(, "Collation error. Probably filename " + ntfs_log_error("Collation error. Probably filename " "contain invalid characters."); err = ERANGE; goto err_out; @@ -288,7 +291,7 @@ done: * -1 with errno ENOENT. */ if (!(ie->flags & INDEX_ENTRY_NODE)) { - ntfs_debug("Entry not found."); + ntfs_log_debug("Entry not found.\n"); err = ENOENT; goto ir_done; } /* Child node present, descend into it. */ @@ -301,7 +304,7 @@ done: na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, ictx->name, ictx->name_len); if (!na) { - ntfs_error(sb, "No index allocation attribute but index entry " + ntfs_log_error("No index allocation attribute but index entry " "requires one. Inode 0x%llx is corrupt or " "library bug.", ni->mft_no); goto err_out; @@ -309,28 +312,28 @@ done: /* Allocate memory to store index block. */ ia = malloc(ictx->block_size); if (!ia) { - ntfs_error(, "Not enough memory to allocate buffer for index" + ntfs_log_error("Not enough memory to allocate buffer for index" " allocation."); err = ENOMEM; goto err_out; } descend_into_child_node: - ntfs_debug("Descend into node with VCN %lld.", vcn); + ntfs_log_debug("Descend into node with VCN %lld.\n", vcn); /* Read index allocation block. */ if (ntfs_attr_mst_pread(na, vcn << vol->cluster_size_bits, 1, ictx->block_size, ia) != 1) { - ntfs_error(, "Failed to read index allocation."); + ntfs_log_error("Failed to read index allocation."); goto err_out; } /* Catch multi sector transfer fixup errors. */ if (!ntfs_is_indx_record(ia->magic)) { - ntfs_error(sb, "Index record with vcn 0x%llx is corrupt. " + ntfs_log_error("Index record with vcn 0x%llx is corrupt. " "Corrupt inode 0x%llx. Run chkdsk.", (long long)vcn, ni->mft_no); goto err_out; } if (sle64_to_cpu(ia->index_block_vcn) != vcn) { - ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is " + ntfs_log_error("Actual VCN (0x%llx) of index buffer is " "different from expected VCN (0x%llx). Inode " "0x%llx is corrupt or driver bug.", (unsigned long long) @@ -339,7 +342,7 @@ descend_into_child_node: goto err_out; } if (le32_to_cpu(ia->index.allocated_size) + 0x18 != ictx->block_size) { - ntfs_error(sb, "Index buffer (VCN 0x%llx) of inode 0x%llx has " + ntfs_log_error("Index buffer (VCN 0x%llx) of inode 0x%llx has " "a size (%u) differing from the index " "specified size (%u). Inode is corrupt or " "driver bug.", (unsigned long long)vcn, @@ -350,7 +353,7 @@ descend_into_child_node: } index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); if (index_end > (u8*)ia + ictx->block_size) { - ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of inode " + ntfs_log_error("Size of index buffer (VCN 0x%llx) of inode " "0x%llx exceeds maximum size.", (unsigned long long)vcn, ni->mft_no); goto err_out; @@ -368,7 +371,7 @@ descend_into_child_node: if ((u8*)ie < (u8*)ia || (u8*)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->length) > index_end) { - ntfs_error(sb, "Index entry out of bounds in inode " + ntfs_log_error("Index entry out of bounds in inode " "0x%llx.", ni->mft_no); goto err_out; } @@ -396,7 +399,7 @@ ia_done: rc = ntfs_collate(vol, cr, key, key_len, &ie->key, le16_to_cpu(ie->key_length)); if (rc == NTFS_COLLATION_ERROR) { - ntfs_error(, "Collation error. Probably filename " + ntfs_log_error("Collation error. Probably filename " "contain invalid characters."); err = ERANGE; goto err_out; @@ -421,12 +424,12 @@ ia_done: * the presence of a child node and if not present return ENOENT. */ if (!(ie->flags & INDEX_ENTRY_NODE)) { - ntfs_debug("Entry not found."); + ntfs_log_debug("Entry not found.\n"); err = ENOENT; goto ia_done; } if ((ia->index.flags & NODE_MASK) == LEAF_NODE) { - ntfs_error(sb, "Index entry with child node found in a leaf " + ntfs_log_error("Index entry with child node found in a leaf " "node in inode 0x%llx.", ni->mft_no); goto err_out; } @@ -434,12 +437,11 @@ ia_done: vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8)); if (vcn >= 0) goto descend_into_child_node; - ntfs_error(sb, "Negative child node vcn in inode 0x%llx.", ni->mft_no); + ntfs_log_error("Negative child node vcn in inode 0x%llx.", ni->mft_no); err_out: if (na) ntfs_attr_close(na); - if (ia) - free(ia); + free(ia); if (!err) err = EIO; if (actx) @@ -447,7 +449,7 @@ err_out: errno = err; return -1; idx_err_out: - ntfs_error(sb, "Corrupt index. Aborting lookup."); + ntfs_log_error("Corrupt index. Aborting lookup."); goto err_out; } @@ -469,9 +471,9 @@ int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn, MFT_REF mref) INDEX_HEADER *ih; int err, fn_size, ie_size, allocated_size = 0; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (!ni || !fn) { - ntfs_error(, "Invalid arguments."); + ntfs_log_error("Invalid arguments."); errno = EINVAL; return -1; } @@ -485,12 +487,12 @@ retry: /* Find place where insert new entry. */ if (!ntfs_index_lookup(fn, fn_size, ictx)) { err = EEXIST; - ntfs_error(, "Index already have such entry."); + ntfs_log_error("Index already have such entry."); goto err_out; } if (errno != ENOENT) { err = errno; - ntfs_error(, "Failed to find place where to insert new entry."); + ntfs_log_error("Failed to find place where to insert new entry."); goto err_out; } /* Some setup. */ @@ -512,21 +514,21 @@ retry: ictx->name_len); if (!na) { err = errno; - ntfs_error(, "Failed to open INDEX_ROOT."); + ntfs_log_error("Failed to open INDEX_ROOT."); goto err_out; } if (ntfs_attr_truncate(na, allocated_size + offsetof( INDEX_ROOT, index))) { err = EOPNOTSUPP; ntfs_attr_close(na); - ntfs_error(, "Failed to truncate INDEX_ROOT."); + ntfs_log_error("Failed to truncate INDEX_ROOT."); goto err_out; } ntfs_attr_close(na); ntfs_index_ctx_reinit(ictx); goto retry; } - ntfs_debug("Not implemented case."); + ntfs_log_debug("Not implemented case.\n"); err = EOPNOTSUPP; goto err_out; } @@ -553,10 +555,10 @@ retry: ntfs_index_entry_mark_dirty(ictx); ntfs_index_ctx_put(ictx); free(ie); - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return 0; err_out: - ntfs_debug("Failed."); + ntfs_log_trace("Failed.\n"); ntfs_index_ctx_put(ictx); errno = err; return -1; @@ -579,10 +581,10 @@ int ntfs_index_rm(ntfs_index_context *ictx) u32 new_index_length; int err; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (!ictx || (!ictx->ia && !ictx->ir) || ictx->entry->flags & INDEX_ENTRY_END) { - ntfs_error(, "Invalid arguments."); + ntfs_log_error("Invalid arguments."); err = EINVAL; goto err_out; } @@ -621,25 +623,25 @@ int ntfs_index_rm(ntfs_index_context *ictx) ictx->name_len); if (!na) { err = errno; - ntfs_error(, "Failed to open INDEX_ROOT attribute. " + ntfs_log_error("Failed to open INDEX_ROOT attribute. " "Leaving inconsist metadata."); goto err_out; } if (ntfs_attr_truncate(na, new_index_length + offsetof( INDEX_ROOT, index))) { err = errno; - ntfs_error(, "Failed to truncate INDEX_ROOT attribute. " + ntfs_log_error("Failed to truncate INDEX_ROOT attribute. " " Leaving inconsist metadata."); goto err_out; } ntfs_attr_close(na); } ntfs_index_ctx_reinit(ictx); - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return 0; err_out: ntfs_index_ctx_reinit(ictx); - ntfs_debug("Failed."); + ntfs_log_trace("Failed.\n"); errno = err; return -1; } @@ -647,30 +649,29 @@ err_out: #ifdef NTFS_RICH -#include +#ifdef HAVE_STRING_H #include - -#include "index.h" +#endif #include "rich.h" /** * ntfs_ie_free */ -void ntfs_ie_free (INDEX_ENTRY *ie) +void ntfs_ie_free(INDEX_ENTRY *ie) { - free (ie); + free(ie); } /** * ntfs_ie_create */ -INDEX_ENTRY * ntfs_ie_create (void) +INDEX_ENTRY * ntfs_ie_create(void) { int length; INDEX_ENTRY *ie; length = 16; - ie = calloc (1, length); + ie = calloc(1, length); if (!ie) return NULL; @@ -685,7 +686,7 @@ INDEX_ENTRY * ntfs_ie_create (void) /** * ntfs_ie_get_vcn */ -VCN ntfs_ie_get_vcn (INDEX_ENTRY *ie) +VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie) { if (!ie) return -1; @@ -698,17 +699,17 @@ VCN ntfs_ie_get_vcn (INDEX_ENTRY *ie) /** * ntfs_ie_copy */ -INDEX_ENTRY * ntfs_ie_copy (INDEX_ENTRY *ie) +INDEX_ENTRY * ntfs_ie_copy(INDEX_ENTRY *ie) { INDEX_ENTRY *copy = NULL; if (!ie) return NULL; - copy = malloc (ie->length); + copy = malloc(ie->length); if (!copy) return NULL; - memcpy (copy, ie, ie->length); + memcpy(copy, ie, ie->length); return copy; } @@ -716,14 +717,14 @@ INDEX_ENTRY * ntfs_ie_copy (INDEX_ENTRY *ie) /** * ntfs_ie_set_vcn */ -INDEX_ENTRY * ntfs_ie_set_vcn (INDEX_ENTRY *ie, VCN vcn) +INDEX_ENTRY * ntfs_ie_set_vcn(INDEX_ENTRY *ie, VCN vcn) { if (!ie) return 0; if (!(ie->flags & INDEX_ENTRY_NODE)) { ie->length += 8; - ie = realloc (ie, ie->length); + ie = realloc(ie, ie->length); if (!ie) return NULL; @@ -737,7 +738,7 @@ INDEX_ENTRY * ntfs_ie_set_vcn (INDEX_ENTRY *ie, VCN vcn) /** * ntfs_ie_remove_vcn */ -INDEX_ENTRY * ntfs_ie_remove_vcn (INDEX_ENTRY *ie) +INDEX_ENTRY * ntfs_ie_remove_vcn(INDEX_ENTRY *ie) { if (!ie) return NULL; @@ -746,14 +747,14 @@ INDEX_ENTRY * ntfs_ie_remove_vcn (INDEX_ENTRY *ie) ie->length -= 8; ie->flags &= ~INDEX_ENTRY_NODE; - ie = realloc (ie, ie->length); + ie = realloc(ie, ie->length); return ie; } /** * ntfs_ie_set_name */ -INDEX_ENTRY * ntfs_ie_set_name (INDEX_ENTRY *ie, ntfschar *name, int namelen, FILE_NAME_TYPE_FLAGS nametype) +INDEX_ENTRY * ntfs_ie_set_name(INDEX_ENTRY *ie, ntfschar *name, int namelen, FILE_NAME_TYPE_FLAGS nametype) { FILE_NAME_ATTR *file; int need; @@ -789,50 +790,50 @@ INDEX_ENTRY * ntfs_ie_set_name (INDEX_ENTRY *ie, ntfschar *name, int namelen, FI * VCN vcn; */ - //printf ("key length = 0x%02X\n", ie->key_length); - //printf ("new name length = %d\n", namelen); + //ntfs_log_debug("key length = 0x%02X\n", ie->key_length); + //ntfs_log_debug("new name length = %d\n", namelen); if (ie->key_length > 0) { file = &ie->key.file_name; - //printf ("filename, length %d\n", file->file_name_length); - need = ATTR_SIZE (namelen * sizeof (ntfschar) + 2) - - ATTR_SIZE (file->file_name_length * sizeof (ntfschar) + 2); + //ntfs_log_debug("filename, length %d\n", file->file_name_length); + need = ATTR_SIZE(namelen * sizeof(ntfschar) + 2) - + ATTR_SIZE(file->file_name_length * sizeof(ntfschar) + 2); } else { - //printf ("no filename\n"); - need = ATTR_SIZE (sizeof (FILE_NAME_ATTR) + (namelen * sizeof (ntfschar))); + //ntfs_log_debug("no filename\n"); + need = ATTR_SIZE(sizeof(FILE_NAME_ATTR) + (namelen * sizeof(ntfschar))); wipe = TRUE; } - //printf ("need 0x%02X bytes\n", need); + //ntfs_log_debug("need 0x%02X bytes\n", need); if (need != 0) { if (ie->flags & INDEX_ENTRY_NODE) - vcn = ntfs_ie_get_vcn (ie); + vcn = ntfs_ie_get_vcn(ie); ie->length += need; ie->key_length += need; - //printf ("realloc 0x%02X\n", ie->length); - ie = realloc (ie, ie->length); + //ntfs_log_debug("realloc 0x%02X\n", ie->length); + ie = realloc(ie, ie->length); if (!ie) return NULL; if (ie->flags & INDEX_ENTRY_NODE) - ie = ntfs_ie_set_vcn (ie, vcn); + ie = ntfs_ie_set_vcn(ie, vcn); if (wipe) - memset (&ie->key.file_name, 0, sizeof (FILE_NAME_ATTR)); + memset(&ie->key.file_name, 0, sizeof(FILE_NAME_ATTR)); if (need > 0) - memset ((u8*)ie + ie->length - need, 0, need); + memset((u8*)ie + ie->length - need, 0, need); } - memcpy (ie->key.file_name.file_name, name, namelen * sizeof (ntfschar)); + memcpy(ie->key.file_name.file_name, name, namelen * sizeof(ntfschar)); ie->key.file_name.file_name_length = namelen; ie->key.file_name.file_name_type = nametype; ie->flags &= ~INDEX_ENTRY_END; - //printf ("ie->length = 0x%02X\n", ie->length); - //printf ("ie->key_length = 0x%02X\n", ie->key_length); + //ntfs_log_debug("ie->length = 0x%02X\n", ie->length); + //ntfs_log_debug("ie->key_length = 0x%02X\n", ie->key_length); return ie; } @@ -840,7 +841,7 @@ INDEX_ENTRY * ntfs_ie_set_name (INDEX_ENTRY *ie, ntfschar *name, int namelen, FI /** * ntfs_ie_remove_name */ -INDEX_ENTRY * ntfs_ie_remove_name (INDEX_ENTRY *ie) +INDEX_ENTRY * ntfs_ie_remove_name(INDEX_ENTRY *ie) { VCN vcn = 0; @@ -850,18 +851,18 @@ INDEX_ENTRY * ntfs_ie_remove_name (INDEX_ENTRY *ie) return ie; if (ie->flags & INDEX_ENTRY_NODE) - vcn = ntfs_ie_get_vcn (ie); + vcn = ntfs_ie_get_vcn(ie); - ie->length -= ATTR_SIZE (ie->key_length); + ie->length -= ATTR_SIZE(ie->key_length); ie->key_length = 0; ie->flags |= INDEX_ENTRY_END; - ie = realloc (ie, ie->length); + ie = realloc(ie, ie->length); if (!ie) return NULL; if (ie->flags & INDEX_ENTRY_NODE) - ie = ntfs_ie_set_vcn (ie, vcn); + ie = ntfs_ie_set_vcn(ie, vcn); return ie; } diff --git a/libntfs/inode.c b/libntfs/inode.c index 96a41854..b13b24da 100644 --- a/libntfs/inode.c +++ b/libntfs/inode.c @@ -1,4 +1,4 @@ -/* +/** * inode.c - Inode handling code. Part of the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -34,7 +36,6 @@ #endif #include "compat.h" - #include "types.h" #include "attrib.h" #include "inode.h" @@ -46,6 +47,7 @@ #include "index.h" #include "dir.h" #include "ntfstime.h" +#include "logging.h" /** * Internal: @@ -80,11 +82,10 @@ ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol) static __inline__ int __ntfs_inode_release(ntfs_inode *ni) { if (NInoDirty(ni)) - Dputs("Eeek. Discarding dirty inode!"); + ntfs_log_debug("Eeek. Discarding dirty inode!\n"); if (NInoAttrList(ni) && ni->attr_list) free(ni->attr_list); - if (ni->mrec) - free(ni->mrec); + free(ni->mrec); free(ni); return 0; } @@ -120,7 +121,7 @@ ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref) int err = 0; STANDARD_INFORMATION *std_info; - Dprintf("%s(): Entering for inode 0x%llx.\n", __FUNCTION__, MREF(mref)); + ntfs_log_trace("Entering for inode 0x%llx.\n", MREF(mref)); if (!vol) { errno = EINVAL; return NULL; @@ -144,8 +145,8 @@ ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref) if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { err = errno; - Dprintf("%s(): Failed to receive STANDARD_INFORMATION " - "attribute.\n", __FUNCTION__); + ntfs_log_trace("Failed to receive STANDARD_INFORMATION " + "attribute.\n"); goto put_err_out; } std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + @@ -280,15 +281,15 @@ int ntfs_inode_close(ntfs_inode *ni) /* Ignore errors, they don't really matter. */ if (tmp_nis) base_ni->extent_nis = tmp_nis; - } else if(tmp_nis) + } else if (tmp_nis) free(tmp_nis); /* Allow for error checking. */ i = -1; break; } if (i != -1) - Dputs("Extent inode was not attached to base inode! " - "Weird! Continuing regardless."); + ntfs_log_debug("Extent inode was not attached to base inode! " + "Weird! Continuing regardless.\n"); } return __ntfs_inode_release(ni); } @@ -329,8 +330,8 @@ ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref) errno = EINVAL; return NULL; } - Dprintf("%s(): Opening extent inode 0x%llx (base mft record 0x%llx).\n", - __FUNCTION__, (unsigned long long)mft_no, + ntfs_log_trace("Opening extent inode 0x%llx (base mft record 0x%llx).\n", + (unsigned long long)mft_no, (unsigned long long)base_ni->mft_no); /* Is the extent inode already open and attached to the base inode? */ if (base_ni->nr_extents > 0) { @@ -345,9 +346,8 @@ ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref) seq_no = MSEQNO_LE(mref); if (seq_no && seq_no != le16_to_cpu( ni->mrec->sequence_number)) { - Dputs("Found stale extent mft reference! " - "Corrupt file system. Run " - "chkdsk."); + ntfs_log_debug("Found stale extent mft reference! " + "Corrupt file system. Run chkdsk.\n"); errno = EIO; return NULL; } @@ -385,7 +385,7 @@ err_out: i = errno; __ntfs_inode_release(ni); errno = i; - Dperror("Failed to open extent inode"); + ntfs_log_perror("Failed to open extent inode"); return NULL; } @@ -401,7 +401,7 @@ int ntfs_inode_attach_all_extents(ntfs_inode *ni) u64 prev_attached = 0; if (!ni) { - Dprintf("%s(): Invalid arguments.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } @@ -409,15 +409,14 @@ int ntfs_inode_attach_all_extents(ntfs_inode *ni) if (ni->nr_extents == -1) ni = ni->base_ni; - Dprintf("%s(): Entering for inode 0x%llx.\n", - __FUNCTION__, (long long) ni->mft_no); + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); /* Inode haven't got attribute list, thus nothing to attach. */ if (!NInoAttrList(ni)) return 0; if (!ni->attr_list) { - Dprintf("%s(): Corrupt in-memory struct.\n", __FUNCTION__); + ntfs_log_trace("Corrupt in-memory struct.\n"); errno = EINVAL; return -1; } @@ -430,8 +429,7 @@ int ntfs_inode_attach_all_extents(ntfs_inode *ni) prev_attached != MREF_LE(ale->mft_reference)) { if (!ntfs_extent_inode_open(ni, MREF_LE(ale->mft_reference))) { - Dprintf("%s(): Couldn't attach extent inode.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't attach extent inode.\n"); return -1; } prev_attached = MREF_LE(ale->mft_reference); @@ -459,8 +457,8 @@ static int ntfs_inode_sync_standard_information(ntfs_inode *ni) if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { err = errno; - Dprintf("%s(): Failed to receive STANDARD_INFORMATION " - "attribute.\n", __FUNCTION__); + ntfs_log_trace("Failed to receive STANDARD_INFORMATION " + "attribute.\n"); ntfs_attr_put_search_ctx(ctx); errno = err; return -1; @@ -507,8 +505,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni) ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; - Dprintf("%s(): Failed to get attribute search context.\n", - __FUNCTION__); + ntfs_log_trace("Failed to get attribute search context.\n"); goto err_out; } /* Walk through all FILE_NAME attributes and update them. */ @@ -530,16 +527,14 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni) if (!index_ni) { if (!err) err = errno; - Dprintf("%s(): Failed to open inode with index.\n", - __FUNCTION__); + ntfs_log_trace("Failed to open inode with index.\n"); continue; } ictx = ntfs_index_ctx_get(index_ni, I30, 4); if (!ictx) { if (!err) err = errno; - Dprintf("%s(): Failed to get index context.\n", - __FUNCTION__); + ntfs_log_trace("Failed to get index context.\n"); ntfs_inode_close(index_ni); continue; } @@ -550,7 +545,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni) else err = errno; } - Dprintf("%s(): Index lookup failed.\n", __FUNCTION__); + ntfs_log_trace("Index lookup failed.\n"); ntfs_index_ctx_put(ictx); ntfs_inode_close(index_ni); continue; @@ -584,7 +579,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni) /* Check for real error occurred. */ if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); goto err_out; } ntfs_attr_put_search_ctx(ctx); @@ -628,8 +623,7 @@ int ntfs_inode_sync(ntfs_inode *ni) return -1; } - Dprintf("%s(): Entering for inode 0x%llx.\n", - __FUNCTION__, (long long) ni->mft_no); + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); /* Update STANDARD_INFORMATION. */ if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && @@ -639,8 +633,7 @@ int ntfs_inode_sync(ntfs_inode *ni) if (err != EIO) err = EBUSY; } - Dprintf("%s(): Failed to sync standard information.\n", - __FUNCTION__); + ntfs_log_trace("Failed to sync standard information.\n"); } /* Update FILE_NAME's in the index. */ @@ -652,8 +645,7 @@ int ntfs_inode_sync(ntfs_inode *ni) if (err != EIO) err = EBUSY; } - Dprintf("%s(): Failed to sync FILE_NAME attributes.\n", - __FUNCTION__); + ntfs_log_trace("Failed to sync FILE_NAME attributes.\n"); NInoFileNameSetDirty(ni); } @@ -668,8 +660,8 @@ int ntfs_inode_sync(ntfs_inode *ni) err = errno; if (err != EIO) err = EBUSY; - Dprintf("%s(): Attribute list sync failed " - "(open failed).\n", __FUNCTION__); + ntfs_log_trace("Attribute list sync failed (open " + "failed).\n"); } NInoAttrListSetDirty(ni); } else { @@ -681,16 +673,14 @@ int ntfs_inode_sync(ntfs_inode *ni) err = errno; if (err != EIO) err = EBUSY; - Dprintf("%s(): Attribute list " - "sync failed (write failed).\n", - __FUNCTION__); + ntfs_log_trace("Attribute list sync " + "failed (write failed).\n"); } NInoAttrListSetDirty(ni); } } else { err = EIO; - Dprintf("%s(): Attribute list sync failed " - "(invalid size).\n", __FUNCTION__); + ntfs_log_trace("Attribute list sync failed (invalid size).\n"); NInoAttrListSetDirty(ni); } ntfs_attr_close(na); @@ -706,8 +696,7 @@ int ntfs_inode_sync(ntfs_inode *ni) err = EBUSY; } NInoSetDirty(ni); - Dprintf("%s(): Base MFT record sync failed.\n", - __FUNCTION__); + ntfs_log_trace("Base MFT record sync failed.\n"); } } @@ -728,8 +717,8 @@ int ntfs_inode_sync(ntfs_inode *ni) err = EBUSY; } NInoSetDirty(eni); - Dprintf("%s(): Extent MFT record sync " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Extent MFT record sync " + "failed.\n"); } } } @@ -762,17 +751,15 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) ntfs_attr *na; if (!ni) { - Dprintf("%s(): Invalid arguments.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for inode 0x%llx.\n", - __FUNCTION__, (long long) ni->mft_no); + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); if (NInoAttrList(ni) || ni->nr_extents) { - Dprintf("%s(): Inode already has got attribute list.\n", - __FUNCTION__); + ntfs_log_trace("Inode already has got attribute list.\n"); errno = EEXIST; return -1; } @@ -782,7 +769,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) al = malloc(al_allocated); ale = (ATTR_LIST_ENTRY *) al; if (!al) { - Dprintf("%s(): Not enough memory.\n", __FUNCTION__); + ntfs_log_trace("Not enough memory.\n"); errno = ENOMEM; return -1; } @@ -791,15 +778,14 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; - Dprintf("%s(): Couldn't get search context.\n", __FUNCTION__); + ntfs_log_trace("Couldn't get search context.\n"); goto err_out; } /* Walk through all attributes. */ while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) { if (ctx->attr->type == AT_ATTRIBUTE_LIST) { err = EIO; - Dprintf("%s(): Eeek! Attribute list already present.\n", - __FUNCTION__); + ntfs_log_trace("Eeek! Attribute list already present.\n"); goto put_err_out; } /* Calculate new length of attribute list. */ @@ -810,8 +796,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) al_allocated += 0x40; aln = realloc(al, al_allocated); if (!aln) { - Dprintf("%s(): Not enough memory.\n", - __FUNCTION__); + ntfs_log_trace("Not enough memory.\n"); err = ENOMEM; goto put_err_out; } @@ -839,14 +824,14 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) /* Check for real error occurred. */ if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); goto put_err_out; } /* Deallocate trailing memory. */ aln = realloc(al, al_len); if (!aln) { err = errno; - Dprintf("%s(): realloc() failed.\n", __FUNCTION__); + ntfs_log_trace("realloc() failed.\n"); goto put_err_out; } al = aln; @@ -865,8 +850,8 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) offsetof(ATTR_RECORD, resident_end))) { /* Failed to free space. */ err = errno; - Dprintf("%s(): Failed to free space for " - "$ATTRIBUTE_LIST.\n", __FUNCTION__); + ntfs_log_trace("Failed to free space for " + "$ATTRIBUTE_LIST.\n"); goto rollback; } } @@ -875,8 +860,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) if (ntfs_resident_attr_record_add(ni, AT_ATTRIBUTE_LIST, NULL, 0, NULL, 0, 0) < 0) { err = errno; - Dprintf("%s(): Couldn't add $ATTRIBUTE_LIST to MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Couldn't add $ATTRIBUTE_LIST to MFT record.\n"); goto rollback; } @@ -884,14 +868,12 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); if (!na) { err = errno; - Dprintf("%s(): Failed to open just added $ATTRIBUTE_LIST.\n", - __FUNCTION__); + ntfs_log_trace("Failed to open just added $ATTRIBUTE_LIST.\n"); goto remove_attrlist_record; } if (ntfs_attr_truncate(na, al_len)) { err = errno; - Dprintf("%s(): Failed to resize just added $ATTRIBUTE_LIST.\n", - __FUNCTION__); + ntfs_log_trace("Failed to resize just added $ATTRIBUTE_LIST.\n"); ntfs_attr_close(na); goto remove_attrlist_record;; } @@ -907,11 +889,11 @@ remove_attrlist_record: if (!ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { if (ntfs_attr_record_rm(ctx)) - Dprintf("%s(): Rollback failed. Failed to remove " - "attribute list record.\n", __FUNCTION__); + ntfs_log_trace("Rollback failed. Failed to remove attribute " + "list record.\n"); } else - Dprintf("%s(): Rollback failed. Couldn't find attribute list " - "record.\n", __FUNCTION__); + ntfs_log_trace("Rollback failed. Couldn't find attribute list " + "record.\n"); /* Setup back in-memory runlist. */ ni->attr_list = al; ni->attr_list_size = al_len; @@ -931,14 +913,11 @@ rollback: sle64_to_cpu(ale->lowest_vcn), NULL, 0, ctx)) { if (ntfs_attr_record_move_to(ctx, ni)) - Dprintf("%s(): Rollback failed. " - "Couldn't back attribute to " - "base MFT record.\n", - __FUNCTION__); + ntfs_log_trace("Rollback failed. Couldn't " + "back attribute to base MFT record.\n"); } else - Dprintf("%s(): Rollback failed. " - "ntfs_attr_lookup failed.\n", - __FUNCTION__); + ntfs_log_trace("Rollback failed. ntfs_attr_lookup " + "failed.\n"); ntfs_attr_reinit_search_ctx(ctx); } ale = (ATTR_LIST_ENTRY*)((u8*)ale + le16_to_cpu(ale->length)); @@ -969,13 +948,13 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) int freed, err; if (!ni || size < 0) { - Dprintf("%s(): Invalid arguments.\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments.\n"); errno = EINVAL; return -1; } - Dprintf("%s(): Entering for inode 0x%llx, size %d.\n", - __FUNCTION__, (long long) ni->mft_no, size); + ntfs_log_trace("Entering for inode 0x%llx, size %d.\n", + (long long) ni->mft_no, size); freed = (le32_to_cpu(ni->mrec->bytes_allocated) - le32_to_cpu(ni->mrec->bytes_in_use)); @@ -986,8 +965,7 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; - Dprintf("%s(): Failed to get attribute search context.\n", - __FUNCTION__); + ntfs_log_trace("Failed to get attribute search context.\n"); errno = err; return -1; } @@ -1010,8 +988,7 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) 0, ctx)) { if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", - __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); goto put_err_out; } if (ctx->attr->type == AT_END) { @@ -1032,8 +1009,7 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) 0, NULL, 0, ctx)) { err = errno; if (errno != ENOENT) { - Dprintf("%s(): Attribute lookup failed." - "\n", __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); } else err = ENOSPC; goto put_err_out; @@ -1045,8 +1021,7 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) /* Move away attribute. */ if (ntfs_attr_record_move_away(ctx, 0)) { err = errno; - Dprintf("%s(): Failed to move out attribute.\n", - __FUNCTION__); + ntfs_log_trace("Failed to move out attribute.\n"); break; } freed += record_size; @@ -1066,8 +1041,7 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) NULL, 0, ctx)) { if (errno != ENOENT) { err = errno; - Dprintf("%s(): Attribute lookup failed.\n", - __FUNCTION__); + ntfs_log_trace("Attribute lookup failed.\n"); break; } if (ctx->attr->type == AT_END) { @@ -1079,8 +1053,7 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) put_err_out: ntfs_attr_put_search_ctx(ctx); if (err == ENOSPC) - Dprintf("%s(): No attributes left that can be moved out.\n", - __FUNCTION__); + ntfs_log_trace("No attributes left that can be moved out.\n"); errno = err; return -1; } @@ -1091,12 +1064,12 @@ put_err_out: /** * ntfs_inode_close2 */ -int ntfs_inode_close2 (ntfs_inode *ni) +int ntfs_inode_close2(ntfs_inode *ni) { if (!ni) return 0; - //printf (BOLD YELLOW "inode close %lld (%d)\n" END, ni->mft_no, ni->ref_count); + //ntfs_log_debug(BOLD YELLOW "inode close %lld (%d)\n" END, ni->mft_no, ni->ref_count); ni->ref_count--; if (ni->ref_count > 0) @@ -1108,13 +1081,13 @@ int ntfs_inode_close2 (ntfs_inode *ni) // XXX temporary until we have commit/rollback NInoClearDirty(ni); - return ntfs_inode_close (ni); + return ntfs_inode_close(ni); } /** * ntfs_inode_open2 */ -ntfs_inode * ntfs_inode_open2 (ntfs_volume *vol, const MFT_REF mref) +ntfs_inode * ntfs_inode_open2(ntfs_volume *vol, const MFT_REF mref) { ntfs_inode *ino = NULL; struct ntfs_dir *dir; @@ -1134,12 +1107,12 @@ ntfs_inode * ntfs_inode_open2 (ntfs_volume *vol, const MFT_REF mref) } if (ino) { - //printf (BOLD YELLOW "inode reuse %lld\n" END, mref); + //ntfs_log_debug(BOLD YELLOW "inode reuse %lld\n" END, mref); ino->ref_count++; return ino; } - ino = ntfs_inode_open (vol, mref); + ino = ntfs_inode_open(vol, mref); if (!ino) return NULL; @@ -1154,7 +1127,7 @@ ntfs_inode * ntfs_inode_open2 (ntfs_volume *vol, const MFT_REF mref) ino->private_data = NULL; ino->ref_count = 1; - //printf (BOLD YELLOW "inode open %lld\n" END, mref); + //ntfs_log_debug(BOLD YELLOW "inode open %lld\n" END, mref); return ino; } @@ -1162,20 +1135,20 @@ ntfs_inode * ntfs_inode_open2 (ntfs_volume *vol, const MFT_REF mref) * ntfs_inode_open3 * open a deleted inode */ -ntfs_inode * ntfs_inode_open3 (ntfs_volume *vol, const MFT_REF mref) +ntfs_inode * ntfs_inode_open3(ntfs_volume *vol, const MFT_REF mref) { ntfs_inode *ino = NULL; if (!vol) return NULL; - ino = calloc (1, sizeof (*ino)); + ino = calloc(1, sizeof(*ino)); if (!ino) return NULL; - ino->mrec = malloc (vol->mft_record_size); + ino->mrec = malloc(vol->mft_record_size); if (!ino->mrec) { - free (ino); + free(ino); return NULL; } @@ -1188,14 +1161,14 @@ ntfs_inode * ntfs_inode_open3 (ntfs_volume *vol, const MFT_REF mref) ino->private_data = NULL; ino->ref_count = 1; - if (1 != ntfs_attr_mst_pread (vol->mft_na, MREF(mref) * vol->mft_record_size, 1, vol->mft_record_size, ino->mrec)) { - //ntfs_inode_close2 (ino); ??? - free (ino->mrec); - free (ino); + if (1 != ntfs_attr_mst_pread(vol->mft_na, MREF(mref) * vol->mft_record_size, 1, vol->mft_record_size, ino->mrec)) { + //ntfs_inode_close2(ino); ??? + free(ino->mrec); + free(ino); return NULL; } - NInoSetDirty (ino); + NInoSetDirty(ino); return ino; } diff --git a/libntfs/lcnalloc.c b/libntfs/lcnalloc.c index 807e6537..f40f3604 100644 --- a/libntfs/lcnalloc.c +++ b/libntfs/lcnalloc.c @@ -1,4 +1,4 @@ -/* +/** * lcnalloc.c - Cluster (de)allocation code. Part of the Linux-NTFS project. * * Copyright (c) 2002-2004 Anton Altaparmakov @@ -20,7 +20,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -39,6 +41,7 @@ #include "runlist.h" #include "volume.h" #include "lcnalloc.h" +#include "logging.h" /** * ntfs_cluster_alloc - allocate clusters on an ntfs volume @@ -107,13 +110,12 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, int err = 0, rlpos, rlsize, buf_size; u8 pass, done_zones, search_zone, need_writeback, bit; - Dprintf("%s(): Entering with count = 0x%llx, start_lcn = 0x%llx, " - "zone = %s_ZONE.\n", __FUNCTION__, (long long)count, - (long long)start_lcn, + ntfs_log_trace("Entering with count = 0x%llx, start_lcn = 0x%llx, zone = " + "%s_ZONE.\n", (long long)count, (long long)start_lcn, zone == MFT_ZONE ? "MFT" : "DATA"); if (!vol || count < 0 || start_lcn < -1 || !vol->lcnbmp_na || (s8)zone < FIRST_ZONE || zone > LAST_ZONE) { - Dprintf("%s(): Invalid arguments!\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments!\n"); errno = EINVAL; return NULL; } @@ -207,30 +209,27 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, clusters = count; rlpos = rlsize = 0; while (1) { - Dprintf("%s(): Start of outer while loop: done_zones = 0x%x, " + ntfs_log_trace("Start of outer while loop: done_zones = 0x%x, " "search_zone = %i, pass = %i, zone_start = " "0x%llx, zone_end = 0x%llx, bmp_initial_pos = " "0x%llx, bmp_pos = 0x%llx, rlpos = %i, rlsize = " - "%i.\n", __FUNCTION__, done_zones, search_zone, - pass, (long long)zone_start, - (long long)zone_end, (long long)bmp_initial_pos, - (long long)bmp_pos, rlpos, rlsize); + "%i.\n", done_zones, search_zone, pass, + (long long)zone_start, (long long)zone_end, + (long long)bmp_initial_pos, (long long)bmp_pos, + rlpos, rlsize); /* Loop until we run out of free clusters. */ last_read_pos = bmp_pos >> 3; - Dprintf("%s(): last_read_pos = 0x%llx.\n", __FUNCTION__, - (long long)last_read_pos); + ntfs_log_trace("last_read_pos = 0x%llx.\n", (long long)last_read_pos); br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos, 8192, buf); if (br <= 0) { if (!br) { /* Reached end of attribute. */ - Dprintf("%s(): End of attribute reached. " - "Skipping to zone_pass_done.\n", - __FUNCTION__); + ntfs_log_trace("End of attribute reached. Skipping " + "to zone_pass_done.\n"); goto zone_pass_done; } err = errno; - Dprintf("%s(): ntfs_attr_pread() failed. Aborting.\n", - __FUNCTION__); + ntfs_log_trace("ntfs_attr_pread() failed. Aborting.\n"); goto err_ret; } /* @@ -241,109 +240,90 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, lcn = bmp_pos & 7; bmp_pos &= ~7; need_writeback = 0; - Dprintf("%s(): Before inner while loop: buf_size = %i, " - "lcn = 0x%llx, bmp_pos = 0x%llx, need_writeback " - "= %i.\n", __FUNCTION__, buf_size, - (long long)lcn, (long long)bmp_pos, + ntfs_log_trace("Before inner while loop: buf_size = %i, lcn = " + "0x%llx, bmp_pos = 0x%llx, need_writeback = %i.\n", + buf_size, (long long)lcn, (long long)bmp_pos, need_writeback); while (lcn < buf_size && lcn + bmp_pos < zone_end) { byte = buf + (lcn >> 3); - Dprintf("%s(): In inner while loop: buf_size = %i, " - "lcn = 0x%llx, bmp_pos = 0x%llx, " + ntfs_log_trace("In inner while loop: buf_size = %i, lcn = " + "0x%llx, bmp_pos = 0x%llx, " "need_writeback = %i, byte ofs = 0x%x, " - "*byte = 0x%x.\n", __FUNCTION__, - buf_size, (long long)lcn, - (long long)bmp_pos, need_writeback, - (unsigned int)(lcn >> 3), + "*byte = 0x%x.\n", buf_size, + (long long)lcn, (long long)bmp_pos, + need_writeback, (unsigned int)(lcn >> 3), (unsigned int)*byte); /* Skip full bytes. */ if (*byte == 0xff) { lcn = (lcn + 8) & ~7; - Dprintf("%s(): continuing while loop 1.\n", - __FUNCTION__); + ntfs_log_trace("continuing while loop 1.\n"); continue; } bit = 1 << (lcn & 7); - Dprintf("%s(): bit = %i.\n", __FUNCTION__, bit); + ntfs_log_trace("bit = %i.\n", bit); /* If the bit is already set, go onto the next one. */ if (*byte & bit) { lcn++; - Dprintf("%s(): continuing while loop 2.\n", - __FUNCTION__); + ntfs_log_trace("continuing while loop 2.\n"); continue; } /* Reallocate memory if necessary. */ if ((rlpos + 2) * (int)sizeof(runlist) >= rlsize) { - Dprintf("%s(): Reallocating space.\n", - __FUNCTION__); + ntfs_log_trace("Reallocating space.\n"); if (!rl) - Dprintf("%s(): First free bit is at " - "LCN = 0x%llx.\n", - __FUNCTION__, - (long long)(lcn + - bmp_pos)); + ntfs_log_trace("First free bit is at LCN = " + "0x%llx.\n", (long long)(lcn + bmp_pos)); rlsize += 4096; trl = (runlist*)realloc(rl, rlsize); if (!trl) { err = ENOMEM; - Dprintf("%s(): Failed to allocate " - "memory, going to " - "wb_err_ret.\n", - __FUNCTION__); + ntfs_log_trace("Failed to allocate memory, " + "going to wb_err_ret.\n"); goto wb_err_ret; } rl = trl; - Dprintf("%s(): Reallocated memory, rlsize = " - "0x%x.\n", __FUNCTION__, - rlsize); + ntfs_log_trace("Reallocated memory, rlsize = " + "0x%x.\n", rlsize); } /* Allocate the bitmap bit. */ *byte |= bit; /* We need to write this bitmap buffer back to disk! */ need_writeback = 1; - Dprintf("%s(): *byte = 0x%x, need_writeback is set.\n", - __FUNCTION__, (unsigned int)*byte); + ntfs_log_trace("*byte = 0x%x, need_writeback is set.\n", + (unsigned int)*byte); /* * Coalesce with previous run if adjacent LCNs. * Otherwise, append a new run. */ - Dprintf("%s(): Adding run (lcn 0x%llx, len 0x%llx), " + ntfs_log_trace("Adding run (lcn 0x%llx, len 0x%llx), " "prev_lcn = 0x%llx, lcn = 0x%llx, " "bmp_pos = 0x%llx, prev_run_len = " - "0x%llx, rlpos = %i.\n", __FUNCTION__, + "0x%llx, rlpos = %i.\n", (long long)(lcn + bmp_pos), 1LL, (long long)prev_lcn, (long long)lcn, (long long)bmp_pos, (long long)prev_run_len, rlpos); if (prev_lcn == lcn + bmp_pos - prev_run_len && rlpos) { - Dprintf("%s(): Coalescing to run (lcn 0x%llx, " - "len 0x%llx).\n", __FUNCTION__, + ntfs_log_trace("Coalescing to run (lcn 0x%llx, len " + "0x%llx).\n", (long long)rl[rlpos - 1].lcn, - (long long) - rl[rlpos - 1].length); + (long long) rl[rlpos - 1].length); rl[rlpos - 1].length = ++prev_run_len; - Dprintf("%s(): Run now (lcn 0x%llx, len 0x%llx), " + ntfs_log_trace("Run now (lcn 0x%llx, len 0x%llx), " "prev_run_len = 0x%llx.\n", - __FUNCTION__, (long long)rl[rlpos - 1].lcn, (long long)rl[rlpos - 1].length, (long long)prev_run_len); } else { if (rlpos) { - Dprintf("%s(): Adding new run, " - "(previous run lcn " - "0x%llx, len 0x%llx).\n", - __FUNCTION__, - (long long) - rl[rlpos - 1].lcn, - (long long) - rl[rlpos - 1].length); + ntfs_log_trace("Adding new run, (previous " + "run lcn 0x%llx, len 0x%llx).\n", + (long long) rl[rlpos - 1].lcn, + (long long) rl[rlpos - 1].length); rl[rlpos].vcn = rl[rlpos - 1].vcn + prev_run_len; } else { - Dprintf("%s(): Adding new run, is " - "first run.\n", - __FUNCTION__); + ntfs_log_trace("Adding new run, is first run.\n"); rl[rlpos].vcn = start_vcn; } rl[rlpos].lcn = prev_lcn = lcn + bmp_pos; @@ -359,19 +339,13 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, * during the respective zone switches. */ tc = lcn + bmp_pos + 1; - Dprintf("%s(): Done. Updating current zone " - "position, tc = 0x%llx, " - "search_zone = %i.\n", - __FUNCTION__, (long long)tc, - search_zone); + ntfs_log_trace("Done. Updating current zone " + "position, tc = 0x%llx, search_zone = %i.\n", + (long long)tc, search_zone); switch (search_zone) { case 1: - Dprintf("%s(): Before checks, " - "vol->mft_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->mft_zone_pos); + ntfs_log_trace("Before checks, vol->mft_zone_pos = 0x%llx.\n", + (long long) vol->mft_zone_pos); if (tc >= vol->mft_zone_end) { vol->mft_zone_pos = vol->mft_lcn; @@ -382,20 +356,12 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, tc > vol->mft_zone_pos) && tc >= vol->mft_lcn) vol->mft_zone_pos = tc; - Dprintf("%s(): After checks, " - "vol->mft_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->mft_zone_pos); + ntfs_log_trace("After checks, vol->mft_zone_pos = 0x%llx.\n", + (long long) vol->mft_zone_pos); break; case 2: - Dprintf("%s(): Before checks, " - "vol->data1_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data1_zone_pos); + ntfs_log_trace("Before checks, vol->data1_zone_pos = 0x%llx.\n", + (long long) vol->data1_zone_pos); if (tc >= vol->nr_clusters) vol->data1_zone_pos = vol->mft_zone_end; @@ -404,55 +370,40 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, tc > vol->data1_zone_pos) && tc >= vol->mft_zone_end) vol->data1_zone_pos = tc; - Dprintf("%s(): After checks, " - "vol->data1_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data1_zone_pos); + ntfs_log_trace("After checks, vol->data1_zone_pos = 0x%llx.\n", + (long long) vol->data1_zone_pos); break; case 4: - Dprintf("%s(): Before checks, " - "vol->data2_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data2_zone_pos); + ntfs_log_trace("Before checks, vol->data2_zone_pos = 0x%llx.\n", + (long long) vol->data2_zone_pos); if (tc >= vol->mft_zone_start) vol->data2_zone_pos = 0; else if (bmp_initial_pos >= vol->data2_zone_pos || tc > vol->data2_zone_pos) vol->data2_zone_pos = tc; - Dprintf("%s(): After checks, " - "vol->data2_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data2_zone_pos); + ntfs_log_trace("After checks, vol->data2_zone_pos = 0x%llx.\n", + (long long) vol->data2_zone_pos); break; default: - if (rl) - free(rl); + free(rl); free(buf); - NTFS_BUG("switch(search_zone) 1"); + NTFS_BUG("switch (search_zone) 1"); return NULL; } - Dprintf("%s(): Going to done_ret.\n", - __FUNCTION__); + ntfs_log_trace("Going to done_ret.\n"); goto done_ret; } lcn++; } bmp_pos += buf_size; - Dprintf("%s(): After inner while loop: buf_size = 0x%x, " - "lcn = 0x%llx, bmp_pos = 0x%llx, need_writeback " - "= %i.\n", __FUNCTION__, buf_size, - (long long)lcn, (long long)bmp_pos, - need_writeback); + ntfs_log_trace("After inner while loop: buf_size = 0x%x, lcn = " + "0x%llx, bmp_pos = 0x%llx, need_writeback = %i.\n", + buf_size, (long long)lcn, + (long long)bmp_pos, need_writeback); if (need_writeback) { s64 bw; - Dprintf("%s(): Writing back.\n", __FUNCTION__); + ntfs_log_trace("Writing back.\n"); need_writeback = 0; bw = ntfs_attr_pwrite(vol->lcnbmp_na, last_read_pos, br, buf); @@ -461,23 +412,20 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, err = errno; else err = EIO; - Dprintf("%s(): Bitmap writeback failed in " - "read next buffer code path " - "with error code %i.\n", - __FUNCTION__, err); + ntfs_log_trace("Bitmap writeback failed in read next " + "buffer code path with error code %i.\n", err); goto err_ret; } } if (bmp_pos < zone_end) { - Dprintf("%s(): Continuing outer while loop, bmp_pos = " + ntfs_log_trace("Continuing outer while loop, bmp_pos = " "0x%llx, zone_end = 0x%llx.\n", - __FUNCTION__, (long long)bmp_pos, + (long long)bmp_pos, (long long)zone_end); continue; } zone_pass_done: /* Finished with the current zone pass. */ - Dprintf("%s(): At zone_pass_done, pass = %i.\n", __FUNCTION__, - pass); + ntfs_log_trace("At zone_pass_done, pass = %i.\n", pass); if (pass == 1) { /* * Now do pass 2, scanning the first part of the zone @@ -496,41 +444,36 @@ zone_pass_done: /* Finished with the current zone pass. */ zone_start = 0; break; default: - NTFS_BUG("switch(search_zone) 2"); + NTFS_BUG("switch (search_zone) 2"); } /* Sanity check. */ if (zone_end < zone_start) zone_end = zone_start; bmp_pos = zone_start; - Dprintf("%s(): Continuing outer while loop, pass = 2, " - "zone_start = 0x%llx, zone_end = 0x%llx, " - "bmp_pos = 0x%llx.\n", __FUNCTION__, + ntfs_log_trace("Continuing outer while loop, pass = 2, " + "zone_start = 0x%llx, zone_end = " + "0x%llx, bmp_pos = 0x%llx.\n", zone_start, zone_end, bmp_pos); continue; } /* pass == 2 */ done_zones_check: - Dprintf("%s(): At done_zones_check, search_zone = %i, " - "done_zones before = 0x%x, done_zones after = " - "0x%x.\n", __FUNCTION__, search_zone, - done_zones, done_zones | search_zone); + ntfs_log_trace("At done_zones_check, search_zone = %i, done_zones " + "before = 0x%x, done_zones after = 0x%x.\n", + search_zone, done_zones, done_zones | search_zone); done_zones |= search_zone; if (done_zones < 7) { - Dprintf("%s(): Switching zone.\n", __FUNCTION__); + ntfs_log_trace("Switching zone.\n"); /* Now switch to the next zone we haven't done yet. */ pass = 1; switch (search_zone) { case 1: - Dprintf("%s(): Switching from mft zone to " - "data1 zone.\n", __FUNCTION__); + ntfs_log_trace("Switching from mft zone to data1 " + "zone.\n"); /* Update mft zone position. */ if (rlpos) { LCN tc; - Dprintf("%s(): Before checks, " - "vol->mft_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->mft_zone_pos); + ntfs_log_trace("Before checks, vol->mft_zone_pos = 0x%llx.\n", + (long long) vol->mft_zone_pos); tc = rl[rlpos - 1].lcn + rl[rlpos - 1].length; if (tc >= vol->mft_zone_end) { @@ -543,12 +486,8 @@ done_zones_check: tc > vol->mft_zone_pos) && tc >= vol->mft_lcn) vol->mft_zone_pos = tc; - Dprintf("%s(): After checks, " - "vol->mft_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->mft_zone_pos); + ntfs_log_trace("After checks, vol->mft_zone_pos = 0x%llx.\n", + (long long) vol->mft_zone_pos); } /* Switch from mft zone to data1 zone. */ switch_to_data1_zone: search_zone = 2; @@ -564,17 +503,13 @@ switch_to_data1_zone: search_zone = 2; } break; case 2: - Dprintf("%s(): Switching from data1 zone to " - "data2 zone.\n", __FUNCTION__); + ntfs_log_trace("Switching from data1 zone to data2 " + "zone.\n"); /* Update data1 zone position. */ if (rlpos) { LCN tc; - Dprintf("%s(): Before checks, " - "vol->data1_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data1_zone_pos); + ntfs_log_trace("Before checks, vol->data1_zone_pos = 0x%llx.\n", + (long long) vol->data1_zone_pos); tc = rl[rlpos - 1].lcn + rl[rlpos - 1].length; if (tc >= vol->nr_clusters) @@ -585,12 +520,8 @@ switch_to_data1_zone: search_zone = 2; tc > vol->data1_zone_pos) && tc >= vol->mft_zone_end) vol->data1_zone_pos = tc; - Dprintf("%s(): After checks, " - "vol->data1_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data1_zone_pos); + ntfs_log_trace("After checks, vol->data1_zone_pos = 0x%llx.\n", + (long long) vol->data1_zone_pos); } /* Switch from data1 zone to data2 zone. */ search_zone = 4; @@ -606,17 +537,13 @@ switch_to_data1_zone: search_zone = 2; } break; case 4: - Dputs("Switching from data2 zone to data1 " - "zone."); + ntfs_log_debug("Switching from data2 zone to data1 " + "zone.\n"); /* Update data2 zone position. */ if (rlpos) { LCN tc; - Dprintf("%s(): Before checks, " - "vol->data2_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data2_zone_pos); + ntfs_log_trace("Before checks, vol->data2_zone_pos = 0x%llx.\n", + (long long) vol->data2_zone_pos); tc = rl[rlpos - 1].lcn + rl[rlpos - 1].length; if (tc >= vol->mft_zone_start) @@ -625,56 +552,49 @@ switch_to_data1_zone: search_zone = 2; vol->data2_zone_pos || tc > vol->data2_zone_pos) vol->data2_zone_pos = tc; - Dprintf("%s(): After checks, " - "vol->data2_zone_pos = " - "0x%llx.\n", - __FUNCTION__, - (long long) - vol->data2_zone_pos); + ntfs_log_trace("After checks, vol->data2_zone_pos = 0x%llx.\n", + (long long) vol->data2_zone_pos); } /* Switch from data2 zone to data1 zone. */ goto switch_to_data1_zone; /* See above. */ default: - NTFS_BUG("switch(search_zone) 3"); + NTFS_BUG("switch (search_zone) 3"); } - Dprintf("%s(): After zone switch, search_zone = %i, " - "pass = %i, bmp_initial_pos = 0x%llx, " + ntfs_log_trace("After zone switch, search_zone = %i, pass = " + "%i, bmp_initial_pos = 0x%llx, " "zone_start = 0x%llx, zone_end = " - "0x%llx.\n", __FUNCTION__, search_zone, - pass, (long long)bmp_initial_pos, + "0x%llx.\n", search_zone, pass, + (long long)bmp_initial_pos, (long long)zone_start, (long long)zone_end); bmp_pos = zone_start; if (zone_start == zone_end) { - Dprintf("%s(): Empty zone, going to " - "done_zones_check.\n", - __FUNCTION__); + ntfs_log_trace("Empty zone, going to " + "done_zones_check.\n"); /* Empty zone. Don't bother searching it. */ goto done_zones_check; } - Dprintf("%s(): Continuing outer while loop.\n", - __FUNCTION__); + ntfs_log_trace("Continuing outer while loop.\n"); continue; } /* done_zones == 7 */ - Dprintf("%s(): All zones are finished.\n", __FUNCTION__); + ntfs_log_trace("All zones are finished.\n"); /* * All zones are finished! If DATA_ZONE, shrink mft zone. If * MFT_ZONE, we have really run out of space. */ mft_zone_size = vol->mft_zone_end - vol->mft_zone_start; - Dprintf("%s(): vol->mft_zone_start = 0x%llx, vol->mft_zone_end " - "= 0x%llx, mft_zone_size = 0x%llx.\n", - __FUNCTION__, (long long)vol->mft_zone_start, + ntfs_log_trace("vol->mft_zone_start = 0x%llx, vol->mft_zone_end = " + "0x%llx, mft_zone_size = 0x%llx.\n", + (long long)vol->mft_zone_start, (long long)vol->mft_zone_end, (long long)mft_zone_size); if (zone == MFT_ZONE || mft_zone_size <= 0) { - Dprintf("%s(): No free clusters left, going to " - "err_ret.\n", __FUNCTION__); + ntfs_log_trace("No free clusters left, going to err_ret.\n"); /* Really no more space left on device. */ err = ENOSPC; goto err_ret; } /* zone == DATA_ZONE && mft_zone_size > 0 */ - Dprintf("%s(): Shrinking mft zone.\n", __FUNCTION__); + ntfs_log_trace("Shrinking mft zone.\n"); zone_end = vol->mft_zone_end; mft_zone_size >>= 1; if (mft_zone_size > 0) @@ -692,31 +612,32 @@ switch_to_data1_zone: search_zone = 2; search_zone = 2; pass = 2; done_zones &= ~2; - Dprintf("%s(): After shrinking mft zone, mft_zone_size = " - "0x%llx, vol->mft_zone_start = 0x%llx, " + ntfs_log_trace("After shrinking mft zone, mft_zone_size = 0x%llx, " + "vol->mft_zone_start = 0x%llx, " "vol->mft_zone_end = 0x%llx, vol->mft_zone_pos " "= 0x%llx, search_zone = 2, pass = 2, " "dones_zones = 0x%x, zone_start = 0x%llx, " "zone_end = 0x%llx, vol->data1_zone_pos = " "0x%llx, continuing outer while loop.\n", - __FUNCTION__, (long long)mft_zone_size, + (long long)mft_zone_size, (long long)vol->mft_zone_start, (long long)vol->mft_zone_end, (long long)vol->mft_zone_pos, - done_zones, (long long)zone_start, + done_zones, + (long long)zone_start, (long long)zone_end, (long long)vol->data1_zone_pos); } - Dputs("After outer while loop."); + ntfs_log_debug("After outer while loop.\n"); done_ret: - Dputs("At done_ret."); + ntfs_log_debug("At done_ret.\n"); /* Add runlist terminator element. */ rl[rlpos].vcn = rl[rlpos - 1].vcn + rl[rlpos - 1].length; rl[rlpos].lcn = LCN_RL_NOT_MAPPED; rl[rlpos].length = 0; if (need_writeback) { s64 bw; - Dprintf("%s(): Writing back.\n", __FUNCTION__); + ntfs_log_trace("Writing back.\n"); need_writeback = 0; bw = ntfs_attr_pwrite(vol->lcnbmp_na, last_read_pos, br, buf); if (bw != br) { @@ -724,27 +645,26 @@ done_ret: err = errno; else err = EIO; - Dprintf("%s(): Bitmap writeback failed in done code " - "path with error code %i.\n", - __FUNCTION__, err); + ntfs_log_trace("Bitmap writeback failed in done code path " + "with error code %i.\n", err); goto err_ret; } } done_err_ret: - Dputs("At done_err_ret (follows done_ret)."); + ntfs_log_debug("At done_err_ret (follows done_ret).\n"); free(buf); /* Done! */ if (!err) return rl; - Dprintf("%s(): Failed to allocate clusters. Returning with error code " - "%i.\n", __FUNCTION__, err); + ntfs_log_trace("Failed to allocate clusters. Returning with error code " + "%i.\n", err); errno = err; return NULL; wb_err_ret: - Dprintf("%s(): At wb_err_ret.\n", __FUNCTION__); + ntfs_log_trace("At wb_err_ret.\n"); if (need_writeback) { s64 bw; - Dprintf("%s(): Writing back.\n", __FUNCTION__); + ntfs_log_trace("Writing back.\n"); need_writeback = 0; bw = ntfs_attr_pwrite(vol->lcnbmp_na, last_read_pos, br, buf); if (bw != br) { @@ -752,18 +672,16 @@ wb_err_ret: err = errno; else err = EIO; - Dprintf("%s(): Bitmap writeback failed in error code " - "path with error code %i.\n", - __FUNCTION__, err); + ntfs_log_trace("Bitmap writeback failed in error code path " + "with error code %i.\n", err); } } err_ret: - Dprintf("%s(): At err_ret.\n", __FUNCTION__); + ntfs_log_trace("At err_ret.\n"); if (rl) { if (err == ENOSPC) { - Dprintf("%s(): err = ENOSPC, first free lcn = 0x%llx, " - "could allocate up to = 0x%llx " - "clusters.\n", __FUNCTION__, + ntfs_log_trace("err = ENOSPC, first free lcn = 0x%llx, could " + "allocate up to = 0x%llx clusters.\n", (long long)rl[0].lcn, (long long)count - clusters); } @@ -772,21 +690,19 @@ err_ret: rl[rlpos].lcn = LCN_RL_NOT_MAPPED; rl[rlpos].length = 0; /* Deallocate all allocated clusters. */ - Dprintf("%s(): Deallocating allocated clusters.\n", - __FUNCTION__); - ntfs_cluster_free_from_rl (vol, rl); + ntfs_log_trace("Deallocating allocated clusters.\n"); + ntfs_cluster_free_from_rl(vol, rl); /* Free the runlist. */ free(rl); rl = NULL; } else { if (err == ENOSPC) { - Dprintf("%s(): No space left at all, err = ENOSPC, " - "first free lcn = 0x%llx.\n", - __FUNCTION__, + ntfs_log_trace("No space left at all, err = ENOSPC, first " + "free lcn = 0x%llx.\n", (long long)vol->data1_zone_pos); } } - Dprintf("%s(): rl = NULL, going to done_err_ret.\n", __FUNCTION__); + ntfs_log_trace("rl = NULL, going to done_err_ret.\n"); goto done_err_ret; } @@ -803,8 +719,7 @@ int ntfs_cluster_free_from_rl(ntfs_volume *vol, runlist *rl) if (rl->lcn >= 0 && ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn, rl->length)) { int eo = errno; - Dprintf("%s(): Eeek! Deallocation of clusters " - "failed.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Deallocation of clusters failed.\n"); errno = eo; return -1; } @@ -835,7 +750,7 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) if (!vol || !vol->lcnbmp_na || !na || start_vcn < 0 || (count < 0 && count != -1)) { - Dprintf("%s(): Invalid arguments!\n", __FUNCTION__); + ntfs_log_trace("Invalid arguments!\n"); errno = EINVAL; return -1; } @@ -887,10 +802,9 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) // list support! (AIA) if (rl->lcn < 0 && rl->lcn != LCN_HOLE) { // FIXME: Eeek! We need rollback! (AIA) - Dprintf("%s(): Eeek! invalid lcn (= %lli). Should " - "attempt to map runlist! " - "Leaving inconsistent metadata!\n", - __FUNCTION__, (long long)rl->lcn); + ntfs_log_trace("Eeek! invalid lcn (= %lli). Should attempt " + "to map runlist! Leaving inconsistent " + "metadata!\n", (long long)rl->lcn); errno = EIO; return -1; } @@ -907,9 +821,8 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) int eo = errno; // FIXME: Eeek! We need rollback! (AIA) - Dprintf("%s(): Eeek! bitmap clear run " - "failed. Leaving inconsistent " - "metadata!\n", __FUNCTION__); + ntfs_log_trace("Eeek! bitmap clear run failed. " + "Leaving inconsistent metadata!\n"); errno = eo; return -1; } @@ -923,9 +836,8 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) if (count != -1 && count != 0) { // FIXME: Eeek! BUG() - Dprintf("%s(): Eeek! count still not zero (= %lli). Leaving " - "inconsistent metadata!\n", __FUNCTION__, - (long long)count); + ntfs_log_trace("Eeek! count still not zero (= %lli). Leaving " + "inconsistent metadata!\n", (long long)count); errno = EIO; return -1; } diff --git a/libntfs/logfile.c b/libntfs/logfile.c index c56fb5fa..53f5359c 100644 --- a/libntfs/logfile.c +++ b/libntfs/logfile.c @@ -1,4 +1,4 @@ -/* +/** * logfile.c - NTFS journal handling. Part of the Linux-NTFS project. * * Copyright (c) 2002-2005 Anton Altaparmakov @@ -20,7 +20,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -31,6 +33,7 @@ #include "logfile.h" #include "volume.h" #include "mst.h" +#include "logging.h" /** * ntfs_check_restart_page_header - check the page header for consistency @@ -49,7 +52,7 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) u16 ra_ofs, usa_count, usa_ofs, usa_end = 0; BOOL have_usa = TRUE; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); /* * If the system or log page sizes are smaller than the ntfs block size * or either is not a power of 2 we cannot handle this log file. @@ -61,7 +64,7 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) logfile_system_page_size & (logfile_system_page_size - 1) || logfile_log_page_size & (logfile_log_page_size - 1)) { - ntfs_error(vi->i_sb, "$LogFile uses unsupported page size."); + ntfs_log_error("$LogFile uses unsupported page size."); return FALSE; } /* @@ -69,14 +72,14 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) * size (2nd restart page). */ if (pos && pos != logfile_system_page_size) { - ntfs_error(vi->i_sb, "Found restart area in incorrect " + ntfs_log_error("Found restart area in incorrect " "position in $LogFile."); return FALSE; } /* We only know how to handle version 1.1. */ if (sle16_to_cpu(rp->major_ver) != 1 || sle16_to_cpu(rp->minor_ver) != 1) { - ntfs_error(vi->i_sb, "$LogFile version %i.%i is not " + ntfs_log_error("$LogFile version %i.%i is not " "supported. (This driver supports version " "1.1 only.)", (int)sle16_to_cpu(rp->major_ver), (int)sle16_to_cpu(rp->minor_ver)); @@ -93,7 +96,7 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) /* Verify the size of the update sequence array. */ usa_count = 1 + (logfile_system_page_size >> NTFS_BLOCK_SIZE_BITS); if (usa_count != le16_to_cpu(rp->usa_count)) { - ntfs_error(vi->i_sb, "$LogFile restart page specifies " + ntfs_log_error("$LogFile restart page specifies " "inconsistent update sequence array count."); return FALSE; } @@ -102,7 +105,7 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) usa_end = usa_ofs + usa_count * sizeof(u16); if (usa_ofs < sizeof(RESTART_PAGE_HEADER) || usa_end > NTFS_BLOCK_SIZE - sizeof(u16)) { - ntfs_error(vi->i_sb, "$LogFile restart page specifies " + ntfs_log_error("$LogFile restart page specifies " "inconsistent update sequence array offset."); return FALSE; } @@ -117,7 +120,7 @@ skip_usa_checks: if (ra_ofs & 7 || (have_usa ? ra_ofs < usa_end : ra_ofs < sizeof(RESTART_PAGE_HEADER)) || ra_ofs > logfile_system_page_size) { - ntfs_error(vi->i_sb, "$LogFile restart page specifies " + ntfs_log_error("$LogFile restart page specifies " "inconsistent restart area offset."); return FALSE; } @@ -126,11 +129,11 @@ skip_usa_checks: * set. */ if (!ntfs_is_chkd_record(rp->magic) && sle64_to_cpu(rp->chkdsk_lsn)) { - ntfs_error(vi->i_sb, "$LogFile restart page is not modified " + ntfs_log_error("$LogFile restart page is not modified " "by chkdsk but a chkdsk LSN is specified."); return FALSE; } - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return TRUE; } @@ -154,7 +157,7 @@ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) u16 ra_ofs, ra_len, ca_ofs; u8 fs_bits; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); ra_ofs = le16_to_cpu(rp->restart_area_offset); ra = (RESTART_AREA*)((u8*)rp + ra_ofs); /* @@ -164,7 +167,7 @@ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) */ if (ra_ofs + offsetof(RESTART_AREA, file_size) > NTFS_BLOCK_SIZE - sizeof(u16)) { - ntfs_error(vi->i_sb, "$LogFile restart area specifies " + ntfs_log_error("$LogFile restart area specifies " "inconsistent file offset."); return FALSE; } @@ -179,7 +182,7 @@ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) if (((ca_ofs + 7) & ~7) != ca_ofs || ra_ofs + ca_ofs > (u16)(NTFS_BLOCK_SIZE - sizeof(u16))) { - ntfs_error(vi->i_sb, "$LogFile restart area specifies " + ntfs_log_error("$LogFile restart area specifies " "inconsistent client array offset."); return FALSE; } @@ -194,7 +197,7 @@ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) (u32)(ra_ofs + le16_to_cpu(ra->restart_area_length)) > le32_to_cpu(rp->system_page_size) || ra_len > le16_to_cpu(ra->restart_area_length)) { - ntfs_error(vi->i_sb, "$LogFile restart area is out of bounds " + ntfs_log_error("$LogFile restart area is out of bounds " "of the system page size specified by the " "restart page header and/or the specified " "restart area length is inconsistent."); @@ -211,7 +214,7 @@ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) (ra->client_in_use_list != LOGFILE_NO_CLIENT && le16_to_cpu(ra->client_in_use_list) >= le16_to_cpu(ra->log_clients))) { - ntfs_error(vi->i_sb, "$LogFile restart area specifies " + ntfs_log_error("$LogFile restart area specifies " "overflowing client free and/or in use lists."); return FALSE; } @@ -226,25 +229,25 @@ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) fs_bits++; } if (le32_to_cpu(ra->seq_number_bits) != (u32)(67 - fs_bits)) { - ntfs_error(vi->i_sb, "$LogFile restart area specifies " + ntfs_log_error("$LogFile restart area specifies " "inconsistent sequence number bits."); return FALSE; } /* The log record header length must be a multiple of 8. */ if (((le16_to_cpu(ra->log_record_header_length) + 7) & ~7) != le16_to_cpu(ra->log_record_header_length)) { - ntfs_error(vi->i_sb, "$LogFile restart area specifies " + ntfs_log_error("$LogFile restart area specifies " "inconsistent log record header length."); return FALSE; } /* Ditto for the log page data offset. */ if (((le16_to_cpu(ra->log_page_data_offset) + 7) & ~7) != le16_to_cpu(ra->log_page_data_offset)) { - ntfs_error(vi->i_sb, "$LogFile restart area specifies " + ntfs_log_error("$LogFile restart area specifies " "inconsistent log page data offset."); return FALSE; } - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return TRUE; } @@ -269,7 +272,7 @@ static BOOL ntfs_check_log_client_array(RESTART_PAGE_HEADER *rp) u16 nr_clients, idx; BOOL in_free_list, idx_is_first; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); ca = (LOG_CLIENT_RECORD*)((u8*)ra + le16_to_cpu(ra->client_array_offset)); @@ -304,10 +307,10 @@ check_list: idx = le16_to_cpu(ra->client_in_use_list); goto check_list; } - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return TRUE; err_out: - ntfs_error(vi->i_sb, "$LogFile log client array is corrupt."); + ntfs_log_error("$LogFile log client array is corrupt."); return FALSE; } @@ -346,7 +349,7 @@ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na, RESTART_PAGE_HEADER *trp; int err; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); /* Check the restart page header for consistency. */ if (!ntfs_check_restart_page_header(rp, pos)) { /* Error output already done inside the function. */ @@ -364,7 +367,7 @@ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na, */ trp = malloc(le32_to_cpu(rp->system_page_size)); if (!trp) { - ntfs_error(vi->i_sb, "Failed to allocate memory for $LogFile " + ntfs_log_error("Failed to allocate memory for $LogFile " "restart page buffer."); return ENOMEM; } @@ -379,7 +382,7 @@ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na, le32_to_cpu(rp->system_page_size), trp) != le32_to_cpu(rp->system_page_size)) { err = errno; - ntfs_error(, "Failed to read whole restart page into the " + ntfs_log_error("Failed to read whole restart page into the " "buffer."); if (err != ENOMEM) err = EIO; @@ -400,7 +403,7 @@ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na, if (le16_to_cpu(rp->restart_area_offset) + le16_to_cpu(ra->restart_area_length) > NTFS_BLOCK_SIZE - (int)sizeof(u16)) { - ntfs_error(vi->i_sb, "Multi sector transfer error " + ntfs_log_error("Multi sector transfer error " "detected in $LogFile restart page."); err = EINVAL; goto err_out; @@ -425,7 +428,7 @@ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na, else /* if (ntfs_is_chkd_record(rp->magic)) */ *lsn = sle64_to_cpu(rp->chkdsk_lsn); } - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); if (wrp) *wrp = trp; else { @@ -464,7 +467,7 @@ BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp) BOOL logfile_is_empty = TRUE; u8 log_page_bits; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); /* An empty $LogFile must have been clean before it got emptied. */ if (NVolLogFileEmpty(vol)) goto is_empty; @@ -487,13 +490,13 @@ BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp) */ if (size < log_page_size * 2 || (size - log_page_size * 2) >> log_page_bits < MinLogRecordPages) { - ntfs_error(vol->sb, "$LogFile is too small."); + ntfs_log_error("$LogFile is too small."); return FALSE; } /* Allocate memory for restart page. */ kaddr = malloc(NTFS_BLOCK_SIZE); if (!kaddr) { - ntfs_error(, "Not enough memory."); + ntfs_log_error("Not enough memory."); return FALSE; } /* @@ -510,7 +513,7 @@ BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp) */ if (ntfs_attr_pread(log_na, pos, NTFS_BLOCK_SIZE, kaddr) != NTFS_BLOCK_SIZE) { - ntfs_error(, "Failed to read first NTFS_BLOCK_SIZE " + ntfs_log_error("Failed to read first NTFS_BLOCK_SIZE " "bytes of potential restart page."); goto err_out; } @@ -579,13 +582,13 @@ BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp) if (logfile_is_empty) { NVolSetLogFileEmpty(vol); is_empty: - ntfs_debug("Done. ($LogFile is empty.)"); + ntfs_log_trace("Done. ($LogFile is empty.)\n"); return TRUE; } if (!rstr1_ph) { if (rstr2_ph) - ntfs_error(vol->sb, "BUG: rstr2_ph isn't NULL!"); - ntfs_error(vol->sb, "Did not find any restart pages in " + ntfs_log_error("BUG: rstr2_ph isn't NULL!"); + ntfs_log_error("Did not find any restart pages in " "$LogFile and it was not empty."); return FALSE; } @@ -596,13 +599,13 @@ is_empty: * Otherwise just throw it away. */ if (rstr2_lsn > rstr1_lsn) { - ntfs_debug("Using second restart page as it is more " + ntfs_log_debug("Using second restart page as it is more " "recent."); free(rstr1_ph); rstr1_ph = rstr2_ph; /* rstr1_lsn = rstr2_lsn; */ } else { - ntfs_debug("Using first restart page as it is more " + ntfs_log_debug("Using first restart page as it is more " "recent."); free(rstr2_ph); } @@ -613,15 +616,12 @@ is_empty: *rp = rstr1_ph; else free(rstr1_ph); - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return TRUE; err_out: - if (kaddr) - free(kaddr); - if (rstr1_ph) - free(rstr1_ph); - if (rstr2_ph) - free(rstr2_ph); + free(kaddr); + free(rstr1_ph); + free(rstr2_ph); return FALSE; } @@ -649,19 +649,19 @@ BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp) { RESTART_AREA *ra; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); /* An empty $LogFile must have been clean before it got emptied. */ if (NVolLogFileEmpty(log_na->ni->vol)) { - ntfs_debug("Done. ($LogFile is empty.)"); + ntfs_log_trace("Done. ($LogFile is empty.)\n"); return TRUE; } if (!rp) { - ntfs_error(, "Restart page header is NULL."); + ntfs_log_error("Restart page header is NULL."); return FALSE; } if (!ntfs_is_rstr_record(rp->magic) && !ntfs_is_chkd_record(rp->magic)) { - ntfs_error(vol->sb, "Restart page buffer is invalid. This is " + ntfs_log_error("Restart page buffer is invalid. This is " "probably a bug in that the $LogFile should " "have been consistency checked before calling " "this function."); @@ -676,11 +676,11 @@ BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp) */ if (ra->client_in_use_list != LOGFILE_NO_CLIENT && !(ra->flags & RESTART_VOLUME_IS_CLEAN)) { - ntfs_debug("Done. $LogFile indicates a dirty shutdown."); + ntfs_log_debug("Done. $LogFile indicates a dirty shutdown.\n"); return FALSE; } /* $LogFile indicates a clean shutdown. */ - ntfs_debug("Done. $LogFile indicates a clean shutdown."); + ntfs_log_trace("Done. $LogFile indicates a clean shutdown.\n"); return TRUE; } @@ -701,21 +701,21 @@ int ntfs_empty_logfile(ntfs_attr *na) char buf[NTFS_BUF_SIZE]; int err; - ntfs_debug("Entering."); + ntfs_log_trace("Entering.\n"); if (NVolLogFileEmpty(na->ni->vol)) goto done; /* The $DATA attribute of the $LogFile has to be non-resident. */ if (!NAttrNonResident(na)) { err = EIO; - Dprintf("$LogFile $DATA attribute is resident!?!\n"); + ntfs_log_debug("$LogFile $DATA attribute is resident!?!\n"); goto io_error_exit; } /* Get length of $LogFile contents. */ len = na->data_size; if (!len) { - Dprintf("$LogFile has zero length, no disk write needed.\n"); + ntfs_log_debug("$LogFile has zero length, no disk write needed.\n"); return 0; } @@ -728,8 +728,8 @@ int ntfs_empty_logfile(ntfs_attr *na) if (count == -1 || pos != len) { err = errno; - Dprintf("Amount of $LogFile data read does not " - "correspond to expected length!"); + ntfs_log_debug("Amount of $LogFile data read does not correspond to " + "expected length!"); if (count != -1) err = EIO; goto io_error_exit; @@ -746,7 +746,7 @@ int ntfs_empty_logfile(ntfs_attr *na) if ((count = ntfs_attr_pwrite(na, pos, count, buf)) <= 0) { err = errno; - Dprintf("Failed to set the $LogFile attribute value."); + ntfs_log_debug("Failed to set the $LogFile attribute value.\n"); if (count != -1) err = EIO; goto io_error_exit; @@ -757,7 +757,7 @@ int ntfs_empty_logfile(ntfs_attr *na) /* Set the flag so we do not have to do it again on remount. */ NVolSetLogFileEmpty(na->ni->vol); done: - ntfs_debug("Done."); + ntfs_log_trace("Done.\n"); return 0; io_error_exit: ntfs_attr_close(na); diff --git a/libntfs/logging.c b/libntfs/logging.c index 6aba1027..6ec0ec27 100644 --- a/libntfs/logging.c +++ b/libntfs/logging.c @@ -19,7 +19,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDIO_H #include @@ -33,6 +35,9 @@ #ifdef HAVE_STRING_H #include #endif +#ifdef HAVE_STDLIB_H +#include +#endif #include "logging.h" @@ -47,10 +52,12 @@ struct ntfs_logging ntfs_log = { #ifdef DEBUG - LOG_LEVEL_DEBUG | LOG_LEVEL_TRACE | + NTFS_LOG_LEVEL_DEBUG | NTFS_LOG_LEVEL_TRACE | #endif - LOG_LEVEL_INFO | LOG_LEVEL_WARNING | LOG_LEVEL_ERROR | LOG_LEVEL_PERROR | LOG_LEVEL_CRITICAL, - LOG_FLAG_PREFIX, + NTFS_LOG_LEVEL_INFO | NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_WARNING | + NTFS_LOG_LEVEL_ERROR | NTFS_LOG_LEVEL_PERROR | NTFS_LOG_LEVEL_CRITICAL | + NTFS_LOG_LEVEL_REASON, + NTFS_LOG_FLAG_ONLYNAME, ntfs_logging_handler_printf }; @@ -61,7 +68,7 @@ struct ntfs_logging ntfs_log = * * Returns: Log levels in a 32-bit field */ -u32 ntfs_logging_get_levels (void) +u32 ntfs_logging_get_levels(void) { return ntfs_log.levels; } @@ -71,11 +78,11 @@ u32 ntfs_logging_get_levels (void) * @levels: 32-bit field of log levels to set * * Enable one or more logging levels. - * The logging levels are named: LOG_LEVEL_*. + * The logging levels are named: NTFS_LOG_LEVEL_*. * * Returns: Log levels that were enabled before the call */ -u32 ntfs_logging_set_levels (u32 levels) +u32 ntfs_logging_set_levels(u32 levels) { u32 old; old = ntfs_log.levels; @@ -88,11 +95,11 @@ u32 ntfs_logging_set_levels (u32 levels) * @levels: 32-bit field of log levels to clear * * Disable one or more logging levels. - * The logging levels are named: LOG_LEVEL_*. + * The logging levels are named: NTFS_LOG_LEVEL_*. * * Returns: Log levels that were enabled before the call */ -u32 ntfs_logging_clear_levels (u32 levels) +u32 ntfs_logging_clear_levels(u32 levels) { u32 old; old = ntfs_log.levels; @@ -108,7 +115,7 @@ u32 ntfs_logging_clear_levels (u32 levels) * * Returns: Logging flags in a 32-bit field */ -u32 ntfs_logging_get_flags (void) +u32 ntfs_logging_get_flags(void) { return ntfs_log.flags; } @@ -118,11 +125,11 @@ u32 ntfs_logging_get_flags (void) * @flags: 32-bit field of logging flags to set * * Enable one or more logging flags. - * The log flags are named: LOG_LEVEL_*. + * The log flags are named: NTFS_LOG_LEVEL_*. * * Returns: Logging flags that were enabled before the call */ -u32 ntfs_logging_set_flags (u32 flags) +u32 ntfs_logging_set_flags(u32 flags) { u32 old; old = ntfs_log.flags; @@ -135,11 +142,11 @@ u32 ntfs_logging_set_flags (u32 flags) * @flags: 32-bit field of logging flags to clear * * Disable one or more logging flags. - * The log flags are named: LOG_LEVEL_*. + * The log flags are named: NTFS_LOG_LEVEL_*. * * Returns: Logging flags that were enabled before the call */ -u32 ntfs_logging_clear_flags (u32 flags) +u32 ntfs_logging_clear_flags(u32 flags) { u32 old; old = ntfs_log.flags; @@ -157,23 +164,24 @@ u32 ntfs_logging_clear_flags (u32 flags) * * Returns: "string" Prefix to be used */ -static FILE * ntfs_logging_get_stream (int level) +static FILE * ntfs_logging_get_stream(u32 level) { FILE *stream; switch (level) { - case LOG_LEVEL_INFO: - case LOG_LEVEL_QUIET: - case LOG_LEVEL_PROGRESS: + case NTFS_LOG_LEVEL_INFO: + case NTFS_LOG_LEVEL_QUIET: + case NTFS_LOG_LEVEL_PROGRESS: + case NTFS_LOG_LEVEL_VERBOSE: stream = stdout; break; - case LOG_LEVEL_DEBUG: - case LOG_LEVEL_TRACE: - case LOG_LEVEL_WARNING: - case LOG_LEVEL_ERROR: - case LOG_LEVEL_CRITICAL: - case LOG_LEVEL_PERROR: + case NTFS_LOG_LEVEL_DEBUG: + case NTFS_LOG_LEVEL_TRACE: + case NTFS_LOG_LEVEL_WARNING: + case NTFS_LOG_LEVEL_ERROR: + case NTFS_LOG_LEVEL_CRITICAL: + case NTFS_LOG_LEVEL_PERROR: default: stream = stderr; break; @@ -190,39 +198,39 @@ static FILE * ntfs_logging_get_stream (int level) * * Returns: "string" Prefix to be used */ -static const char * ntfs_logging_get_prefix (int level) +static const char * ntfs_logging_get_prefix(u32 level) { const char *prefix; switch (level) { - case LOG_LEVEL_DEBUG: + case NTFS_LOG_LEVEL_DEBUG: prefix = "DEBUG: "; break; - case LOG_LEVEL_TRACE: + case NTFS_LOG_LEVEL_TRACE: prefix = "TRACE: "; break; - case LOG_LEVEL_QUIET: + case NTFS_LOG_LEVEL_QUIET: prefix = "QUIET: "; break; - case LOG_LEVEL_INFO: + case NTFS_LOG_LEVEL_INFO: prefix = "INFO: "; break; - case LOG_LEVEL_VERBOSE: + case NTFS_LOG_LEVEL_VERBOSE: prefix = "VERBOSE: "; break; - case LOG_LEVEL_PROGRESS: + case NTFS_LOG_LEVEL_PROGRESS: prefix = "PROGRESS: "; break; - case LOG_LEVEL_WARNING: + case NTFS_LOG_LEVEL_WARNING: prefix = "WARNING: "; break; - case LOG_LEVEL_ERROR: + case NTFS_LOG_LEVEL_ERROR: prefix = "ERROR: "; break; - case LOG_LEVEL_PERROR: + case NTFS_LOG_LEVEL_PERROR: prefix = "ERROR: "; break; - case LOG_LEVEL_CRITICAL: + case NTFS_LOG_LEVEL_CRITICAL: prefix = "CRITICAL: "; break; default: @@ -243,7 +251,7 @@ static const char * ntfs_logging_get_prefix (int level) * * Returns: void */ -void ntfs_logging_set_handler (logging_handler *handler) +void ntfs_logging_set_handler(ntfs_logging_handler *handler) { if (handler) ntfs_log.handler = handler; @@ -257,22 +265,19 @@ void ntfs_logging_set_handler (logging_handler *handler) * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged - * @stream: FILE stream to output to (may be NULL) + * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @...: Arguments to be formatted * * This is just a redirector function. The arguments are simply passed to the * main logging handler (as defined in the global logging struct @ntfs_log). * - * Note: If @stream is NULL, the output stream will be determined by the - * function: ntfs_logging_get_stream - * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ -int ntfs_logging_redirect (const char *function, const char *file, - int line, int level, FILE *stream, const char *format, ...) +int ntfs_logging_redirect(const char *function, const char *file, + int line, u32 level, void *data, const char *format, ...) { int olderr = errno; int ret; @@ -281,10 +286,10 @@ int ntfs_logging_redirect (const char *function, const char *file, if (!(ntfs_log.levels & level)) /* Don't log this message */ return 0; - va_start (args, format); + va_start(args, format); errno = olderr; - ret = ntfs_log.handler (function, file, line, level, stream, format, args); - va_end (args); + ret = ntfs_log.handler(function, file, line, level, data, format, args); + va_end(args); errno = olderr; return ret; @@ -296,49 +301,73 @@ int ntfs_logging_redirect (const char *function, const char *file, * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged - * @stream: FILE stream to output to (may be NULL) + * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * * A simple logging handler. This is where the log line is finally displayed. * - * Note: If @stream is NULL, the output stream will be determined by the - * function: ntfs_logging_get_stream + * Note: For this handler, @data is a pointer to a FILE output stream. + * If @data is NULL, the function ntfs_logging_get_stream will be called * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ -int ntfs_logging_handler_printf (const char *function, const char *file, - int line, int level, FILE *stream, const char *format, va_list args) +int ntfs_logging_handler_printf(const char *function, const char *file, + int line, u32 level, void *data, const char *format, va_list args) { + const int reason_size = 128; + static char *reason = NULL; int ret = 0; int olderr = errno; + FILE *stream; - if (!stream) - stream = ntfs_logging_get_stream (level); - - if (strchr (file, PATH_SEP)) /* Abbreviate the filename */ - file = strrchr (file, PATH_SEP) + 1; - - if (ntfs_log.flags & LOG_FLAG_PREFIX) /* Prefix the output */ - ret += fprintf (stream, "%s", ntfs_logging_get_prefix (level)); - - if (ntfs_log.flags & LOG_FLAG_FILENAME) /* Source filename */ - ret += fprintf (stream, "%s ", file); - - if (ntfs_log.flags & LOG_FLAG_LINE) /* Source line number */ - ret += fprintf (stream, "(%d) ", line); - - if (ntfs_log.flags & LOG_FLAG_FUNCTION) /* Source function */ - ret += fprintf (stream, ": %s : ", function); - - if (level & LOG_LEVEL_PERROR) { - errno = olderr; - ret += fprintf (stream, "<%s> : ", strerror (olderr)); + if (level == NTFS_LOG_LEVEL_REASON) { + if (!reason) + reason = malloc (reason_size); + if (reason) { + memset (reason, 0, reason_size); + return vsnprintf (reason, reason_size, format, args); + } else { + /* Rather than call ourselves, just drop through */ + level = NTFS_LOG_LEVEL_PERROR; + format = "Couldn't create reason"; + args = NULL; + olderr = errno; + } } - ret += vfprintf (stream, format, args); + if (data) + stream = (FILE*) data; + else + stream = ntfs_logging_get_stream(level); + + if ((ntfs_log.flags & NTFS_LOG_FLAG_ONLYNAME) && + (strchr(file, PATH_SEP))) /* Abbreviate the filename */ + file = strrchr(file, PATH_SEP) + 1; + + if (ntfs_log.flags & NTFS_LOG_FLAG_PREFIX) /* Prefix the output */ + ret += fprintf(stream, "%s", ntfs_logging_get_prefix(level)); + + if (ntfs_log.flags & NTFS_LOG_FLAG_FILENAME) /* Source filename */ + ret += fprintf(stream, "%s ", file); + + if (ntfs_log.flags & NTFS_LOG_FLAG_LINE) /* Source line number */ + ret += fprintf(stream, "(%d) ", line); + + if ((ntfs_log.flags & NTFS_LOG_FLAG_FUNCTION) && /* Source function */ + (level & NTFS_LOG_LEVEL_TRACE)) + ret += fprintf(stream, "%s(): ", function); + + ret += vfprintf(stream, format, args); + + if (level & NTFS_LOG_LEVEL_PERROR) { + if (reason) + ret += fprintf(stream, " : %s\n", reason); + else + ret += fprintf(stream, " : %s\n", strerror(olderr)); + } errno = olderr; return ret; @@ -350,7 +379,7 @@ int ntfs_logging_handler_printf (const char *function, const char *file, * @file: File in which the log line occurred * @line: Line number on which the log line occurred * @level: Level at which the line is logged - * @stream: FILE stream to output to (may be NULL) + * @data: User specified data, possibly specific to a handler * @format: printf-style formatting string * @args: Arguments to be formatted * @@ -361,49 +390,62 @@ int ntfs_logging_handler_printf (const char *function, const char *file, * * Note: This function calls ntfs_logging_handler_printf to do the main work. * - * Note: If @stream is NULL, the output stream will be determined by the - * function: ntfs_logging_get_stream + * Note: For this handler, @data is a pointer to a FILE output stream. + * If @data is NULL, the function ntfs_logging_get_stream will be called * * Returns: -1 Error occurred * 0 Message wasn't logged * num Number of output characters */ -int ntfs_logging_handler_colour (const char *function, const char *file, - int line, int level, FILE *stream, const char *format, va_list args) +int ntfs_logging_handler_colour(const char *function, const char *file, + int line, u32 level, void *data, const char *format, va_list args) { int ret = 0; int olderr = errno; const char *prefix = NULL; const char *suffix = NULL; const char *end = "\e[0m"; + FILE *stream = NULL; - if (!stream) - stream = ntfs_logging_get_stream (level); + if (level != NTFS_LOG_LEVEL_REASON) { /* Reasons get passed through */ + if (data) + stream = (FILE*) data; + else + stream = ntfs_logging_get_stream(level); - switch (level) { - case LOG_LEVEL_WARNING: - prefix = "\e[01;33m"; /* Yellow */ - suffix = end; - break; - case LOG_LEVEL_ERROR: - case LOG_LEVEL_PERROR: - prefix = "\e[01;31m"; /* Red */ - suffix = end; - break; - case LOG_LEVEL_CRITICAL: - prefix = "\e[01;07;31m"; /* Red, inverse */ - suffix = end; - break; + switch (level) { + case NTFS_LOG_LEVEL_DEBUG: + prefix = "\e[32m"; /* Green */ + suffix = end; + break; + case NTFS_LOG_LEVEL_TRACE: + prefix = "\e[36m"; /* Cyan */ + suffix = end; + break; + case NTFS_LOG_LEVEL_WARNING: + prefix = "\e[01;33m"; /* Yellow */ + suffix = end; + break; + case NTFS_LOG_LEVEL_ERROR: + case NTFS_LOG_LEVEL_PERROR: + prefix = "\e[01;31m"; /* Red */ + suffix = end; + break; + case NTFS_LOG_LEVEL_CRITICAL: + prefix = "\e[01;07;31m"; /* Red, inverse */ + suffix = end; + break; + } } if (prefix) - ret += fprintf (stream, prefix); + ret += fprintf(stream, prefix); errno = olderr; - ret += ntfs_logging_handler_printf (function, file, line, level, stream, format, args); + ret += ntfs_logging_handler_printf(function, file, line, level, stream, format, args); if (suffix) - ret += fprintf (stream, suffix); + ret += fprintf(stream, suffix); errno = olderr; return ret; @@ -423,27 +465,27 @@ int ntfs_logging_handler_colour (const char *function, const char *file, * Returns: TRUE Option understood * FALSE Invalid log option */ -BOOL ntfs_logging_parse_option (const char *option) +BOOL ntfs_logging_parse_option(const char *option) { - if (strcmp (option, "--log-debug") == 0) { - ntfs_logging_set_levels (LOG_LEVEL_DEBUG); + if (strcmp(option, "--log-debug") == 0) { + ntfs_logging_set_levels(NTFS_LOG_LEVEL_DEBUG); return TRUE; - } else if (strcmp (option, "--log-verbose") == 0) { - ntfs_logging_set_levels (LOG_LEVEL_VERBOSE); + } else if (strcmp(option, "--log-verbose") == 0) { + ntfs_logging_set_levels(NTFS_LOG_LEVEL_VERBOSE); return TRUE; - } else if (strcmp (option, "--log-quiet") == 0) { - ntfs_logging_set_levels (LOG_LEVEL_QUIET); + } else if (strcmp(option, "--log-quiet") == 0) { + ntfs_logging_set_levels(NTFS_LOG_LEVEL_QUIET); return TRUE; - } else if (strcmp (option, "--log-trace") == 0) { - ntfs_logging_set_levels (LOG_LEVEL_TRACE); + } else if (strcmp(option, "--log-trace") == 0) { + ntfs_logging_set_levels(NTFS_LOG_LEVEL_TRACE); return TRUE; - } else if ((strcmp (option, "--log-colour") == 0) || - (strcmp (option, "--log-color") == 0)) { - ntfs_logging_set_handler (ntfs_logging_handler_colour); + } else if ((strcmp(option, "--log-colour") == 0) || + (strcmp(option, "--log-color") == 0)) { + ntfs_logging_set_handler(ntfs_logging_handler_colour); return TRUE; } - log_error ("Unknown logging option '%s'\n", option); + ntfs_log_warning("Unknown logging option '%s'\n", option); return FALSE; } diff --git a/libntfs/mft.c b/libntfs/mft.c index beb682fc..d5c10b69 100644 --- a/libntfs/mft.c +++ b/libntfs/mft.c @@ -1,4 +1,4 @@ -/* +/** * mft.c - Mft record handling code. Part of the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -38,7 +40,6 @@ #include #include "compat.h" - #include "types.h" #include "device.h" #include "debug.h" @@ -49,6 +50,7 @@ #include "layout.h" #include "lcnalloc.h" #include "mft.h" +#include "logging.h" /** * ntfs_mft_records_read - read records from the mft from disk @@ -77,7 +79,7 @@ int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref, s64 br; VCN m; - Dprintf("%s(): Entering for inode 0x%llx.\n", __FUNCTION__, MREF(mref)); + ntfs_log_trace("Entering for inode 0x%llx.\n", MREF(mref)); if (!vol || !vol->mft_na || !b || count < 0) { errno = EINVAL; return -1; @@ -95,9 +97,10 @@ int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref, if (br != -1) errno = EIO; if (br >= 0) - Dputs("Error: partition is smaller than it should be!"); + ntfs_log_debug("Error: partition is smaller than it should " + "be!\n"); else - Dperror("Error reading $Mft record(s)"); + ntfs_log_perror("Error reading $Mft record(s)"); return -1; } return 0; @@ -135,7 +138,7 @@ int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, void *bmirr = NULL; int cnt = 0, res = 0; - Dprintf("%s(): Entering for inode 0x%llx.\n", __FUNCTION__, MREF(mref)); + ntfs_log_trace("Entering for inode 0x%llx.\n", MREF(mref)); if (!vol || !vol->mft_na || vol->mftmirr_size <= 0 || !b || count < 0) { errno = EINVAL; return -1; @@ -166,10 +169,10 @@ int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, if (bw != -1) errno = EIO; if (bw >= 0) - Dputs("Error: partial write while writing $Mft " + ntfs_log_debug("Error: partial write while writing $Mft " "record(s)!\n"); else - Dperror("Error writing $Mft record(s)"); + ntfs_log_perror("Error writing $Mft record(s)"); res = errno; } if (bmirr && bw > 0) { @@ -181,12 +184,12 @@ int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, if (bw != cnt) { if (bw != -1) errno = EIO; - Dputs("Error: failed to sync $MFTMirr! Run chkdsk."); + ntfs_log_debug("Error: failed to sync $MFTMirr! Run " + "chkdsk.\n"); res = errno; } } - if (bmirr) - free(bmirr); + free(bmirr); if (!res) return res; errno = res; @@ -257,7 +260,7 @@ int ntfs_file_record_read(const ntfs_volume *vol, const MFT_REF mref, *attr = a; return 0; file_corrupt: - Dputs("ntfs_file_record_read(): file is corrupt."); + ntfs_log_debug("ntfs_file_record_read(): file is corrupt.\n"); err = EIO; read_failed: if (m != *mrec) @@ -294,7 +297,7 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, else { /* Abort if mref is > 32 bits. */ if (MREF(mref) & 0x0000ffff00000000ull) { - Dputs("Mft reference exceeds 32 bits!"); + ntfs_log_debug("Mft reference exceeds 32 bits!\n"); errno = ERANGE; return -1; } @@ -312,12 +315,13 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, NTFS_BLOCK_SIZE + 1); else { m->usa_count = cpu_to_le16(1); - Dprintf("Sector size is bigger than MFT record size. " - "Setting usa_count to 1. If Windows\nchkdsk " - "reports this as corruption, please email " - "linux-ntfs-dev@lists.sf.net\nstating that " - "you saw this message and that the file " - "system created was corrupt.\nThank you.\n"); + ntfs_log_debug("Sector size is bigger than MFT record size. " + "Setting usa_count to 1. If Windows\n"); + ntfs_log_debug("chkdsk reports this as corruption, please email " + "linux-ntfs-dev@lists.sf.net\n"); + ntfs_log_debug("stating that you saw this message and that the " + "file system created was corrupt.\n"); + ntfs_log_debug("Thank you.\n"); } /* Set the update sequence number to 1. */ *(u16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = cpu_to_le16(1); @@ -383,7 +387,7 @@ int ntfs_mft_record_format(const ntfs_volume *vol, const MFT_REF mref) return 0; } -#ifdef DEBUG +#ifndef NTFS_DISABLE_DEBUG_LOGGING static const char *es = " Leaving inconsistent metadata. Run chkdsk."; #endif @@ -451,11 +455,11 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni) buf = (u8*)malloc(PAGE_SIZE); if (!buf) return -1; - ntfs_debug("Starting bitmap search: pass %u, pass_start 0x%llx, " - "pass_end 0x%llx, data_pos 0x%llx.", pass, + ntfs_log_debug("Starting bitmap search: pass %u, pass_start 0x%llx, " + "pass_end 0x%llx, data_pos 0x%llx.\n", pass, (long long)pass_start, (long long)pass_end, (long long)data_pos); -#ifdef DEBUG +#ifndef NTFS_DISABLE_DEBUG_LOGGING byte = NULL; b = 0; #endif @@ -468,20 +472,20 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni) size = ll; ll = ntfs_attr_pread(mftbmp_na, ofs, size, buf); if (ll < 0) { - ntfs_error(vol->sb, "Failed to read mft bitmap " + ntfs_log_error("Failed to read mft bitmap " "attribute, aborting."); free(buf); return -1; } - ntfs_debug("Read 0x%llx bytes.", (long long)ll); + ntfs_log_debug("Read 0x%llx bytes.\n", (long long)ll); /* If we read at least one byte, search @buf for a zero bit. */ if (ll) { size = ll << 3; bit = data_pos & 7; data_pos &= ~7ull; - ntfs_debug("Before inner for loop: size 0x%x, " + ntfs_log_debug("Before inner for loop: size 0x%x, " "data_pos 0x%llx, bit 0x%llx, " - "*byte 0x%hhx, b %u.", size, + "*byte 0x%hhx, b %u.\n", size, (long long)data_pos, (long long)bit, byte ? *byte : -1, b); for (; bit < size && data_pos + bit < pass_end; @@ -496,9 +500,9 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni) return data_pos + (bit & ~7ull) + b; } } - ntfs_debug("After inner for loop: size 0x%x, " + ntfs_log_debug("After inner for loop: size 0x%x, " "data_pos 0x%llx, bit 0x%llx, " - "*byte 0x%hhx, b %u.", size, + "*byte 0x%hhx, b %u.\n", size, (long long)data_pos, (long long)bit, byte ? *byte : -1, b); data_pos += size; @@ -518,8 +522,8 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni) */ pass_end = pass_start; data_pos = pass_start = 24; - ntfs_debug("pass %i, pass_start 0x%llx, pass_end " - "0x%llx.", pass, (long long)pass_start, + ntfs_log_debug("pass %i, pass_start 0x%llx, pass_end " + "0x%llx.\n", pass, (long long)pass_start, (long long)pass_end); if (data_pos >= pass_end) break; @@ -569,7 +573,7 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) rl = ntfs_attr_find_vcn(mftbmp_na, (mftbmp_na->allocated_size - 1) >> vol->cluster_size_bits); if (!rl || !rl->length || rl->lcn < 0) { - ntfs_error(vol->sb, "Failed to determine last allocated " + ntfs_log_error("Failed to determine last allocated " "cluster of mft bitmap attribute."); if (rl) errno = EIO; @@ -583,17 +587,17 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) */ ret = (int)ntfs_attr_pread(lcnbmp_na, lcn >> 3, 1, &b); if (ret < 0) { - ntfs_error(vol->sb, "Failed to read from lcn bitmap."); + ntfs_log_error("Failed to read from lcn bitmap."); return -1; } - ntfs_debug("Read %i byte%s.", ret, ret == 1 ? "" : "s"); + ntfs_log_debug("Read %i byte%s.\n", ret, ret == 1 ? "" : "s"); tb = 1 << (lcn & 7ull); if (ret == 1 && b != 0xff && !(b & tb)) { /* Next cluster is free, allocate it. */ b |= tb; ret = (int)ntfs_attr_pwrite(lcnbmp_na, lcn >> 3, 1, &b); if (ret < 1) { - ntfs_error(vol->sb, "Failed to write to lcn " + ntfs_log_error("Failed to write to lcn " "bitmap."); if (!ret) errno = EIO; @@ -603,22 +607,22 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) rl->length++; rl[1].vcn++; status.added_cluster = 1; - ntfs_debug("Appending one cluster to mft bitmap."); + ntfs_log_debug("Appending one cluster to mft bitmap.\n"); } else { /* Allocate a cluster from the DATA_ZONE. */ rl2 = ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, DATA_ZONE); if (!rl2) { - ntfs_error(vol->sb, "Failed to allocate a cluster for " + ntfs_log_error("Failed to allocate a cluster for " "the mft bitmap."); return -1; } rl = ntfs_runlists_merge(mftbmp_na->rl, rl2); if (!rl) { ret = errno; - ntfs_error(vol->sb, "Failed to merge runlists for mft " + ntfs_log_error("Failed to merge runlists for mft " "bitmap."); if (ntfs_cluster_free_from_rl(vol, rl2)) - ntfs_error(vol->sb, "Failed to deallocate " + ntfs_log_error("Failed to deallocate " "cluster.%s", es); free(rl2); errno = ret; @@ -626,7 +630,7 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) } mftbmp_na->rl = rl; status.added_run = 1; - ntfs_debug("Adding one run to mft bitmap."); + ntfs_log_debug("Adding one run to mft bitmap.\n"); /* Find the last run in the new runlist. */ for (; rl[1].length; rl++) ; @@ -637,12 +641,12 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) */ ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); if (!ctx) { - ntfs_error(vol->sb, "Failed to get search context."); + ntfs_log_error("Failed to get search context."); goto undo_alloc; } if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find last attribute extent of " + ntfs_log_error("Failed to find last attribute extent of " "mft bitmap attribute."); goto undo_alloc; } @@ -651,7 +655,7 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) ll = sle64_to_cpu(a->lowest_vcn); rl2 = ntfs_attr_find_vcn(mftbmp_na, ll); if (!rl2 || !rl2->length) { - ntfs_error(vol->sb, "Failed to determine previous last " + ntfs_log_error("Failed to determine previous last " "allocated cluster of mft bitmap attribute."); if (rl2) errno = EIO; @@ -660,7 +664,7 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) /* Get the size for the new mapping pairs array for this extent. */ mp_size = ntfs_get_size_for_mapping_pairs(vol, rl2, ll); if (mp_size <= 0) { - ntfs_error(vol->sb, "Get size for mapping pairs failed for " + ntfs_log_error("Get size for mapping pairs failed for " "mft bitmap attribute extent."); goto undo_alloc; } @@ -669,13 +673,13 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) if (ntfs_attr_record_resize(m, a, mp_size + le16_to_cpu(a->mapping_pairs_offset))) { if (errno != ENOSPC) { - ntfs_error(vol->sb, "Failed to resize attribute " + ntfs_log_error("Failed to resize attribute " "record for mft bitmap attribute."); goto undo_alloc; } // TODO: Deal with this by moving this extent to a new mft // record or by starting a new extent in a new mft record. - ntfs_error(vol->sb, "Not enough space in this mft record to " + ntfs_log_error("Not enough space in this mft record to " "accommodate extended mft bitmap attribute " "extent. Cannot handle this yet."); errno = EOPNOTSUPP; @@ -686,7 +690,7 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp_size, rl2, ll, NULL)) { - ntfs_error(vol->sb, "Failed to build mapping pairs array for " + ntfs_log_error("Failed to build mapping pairs array for " "mft bitmap attribute."); errno = EIO; goto undo_alloc; @@ -706,7 +710,7 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find first attribute " + ntfs_log_error("Failed to find first attribute " "extent of mft bitmap attribute."); goto restore_undo_alloc; } @@ -723,7 +727,7 @@ restore_undo_alloc: ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find last attribute extent of " + ntfs_log_error("Failed to find last attribute extent of " "mft bitmap attribute.%s", es); ntfs_attr_put_search_ctx(ctx); mftbmp_na->allocated_size += vol->cluster_size; @@ -752,16 +756,16 @@ undo_alloc: } /* Deallocate the cluster. */ if (ntfs_bitmap_clear_bit(lcnbmp_na, lcn)) - ntfs_error(vol->sb, "Failed to free cluster.%s", es); + ntfs_log_error("Failed to free cluster.%s", es); if (status.mp_rebuilt) { if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), old_alen - le16_to_cpu(a->mapping_pairs_offset), rl2, ll, NULL)) - ntfs_error(vol->sb, "Failed to restore mapping " + ntfs_log_error("Failed to restore mapping " "pairs array.%s", es); if (ntfs_attr_record_resize(m, a, old_alen)) - ntfs_error(vol->sb, "Failed to restore attribute " + ntfs_log_error("Failed to restore attribute " "record.%s", es); ntfs_inode_mark_dirty(ctx->ntfs_ino); @@ -795,12 +799,12 @@ static int ntfs_mft_bitmap_extend_initialized(ntfs_volume *vol) mftbmp_na = vol->mftbmp_na; ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); if (!ctx) { - ntfs_error(vol->sb, "Failed to get search context."); + ntfs_log_error("Failed to get search context."); return -1; } if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find first attribute extent of " + ntfs_log_error("Failed to find first attribute extent of " "mft bitmap attribute."); err = errno; goto put_err_out; @@ -821,22 +825,22 @@ static int ntfs_mft_bitmap_extend_initialized(ntfs_volume *vol) ll = 0; ll = ntfs_attr_pwrite(mftbmp_na, old_initialized_size, 8, &ll); if (ll == 8) { - ntfs_debug("Wrote eight initialized bytes to mft bitmap."); + ntfs_log_debug("Wrote eight initialized bytes to mft bitmap.\n"); return 0; } - ntfs_error(vol->sb, "Failed to write to mft bitmap."); + ntfs_log_error("Failed to write to mft bitmap."); err = errno; if (ll >= 0) err = EIO; /* Try to recover from the error. */ ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); if (!ctx) { - ntfs_error(vol->sb, "Failed to get search context.%s", es); + ntfs_log_error("Failed to get search context.%s", es); goto err_out; } if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find first attribute extent of " + ntfs_log_error("Failed to find first attribute extent of " "mft bitmap attribute.%s", es); put_err_out: ntfs_attr_put_search_ctx(ctx); @@ -851,8 +855,8 @@ put_err_out: } ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); - ntfs_debug("Restored status of mftbmp: allocated_size 0x%llx, " - "data_size 0x%llx, initialized_size 0x%llx.", + ntfs_log_debug("Restored status of mftbmp: allocated_size 0x%llx, " + "data_size 0x%llx, initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); @@ -888,7 +892,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) u32 old_alen = 0; /* silence compiler warning */ BOOL mp_rebuilt = FALSE; - ntfs_debug("Extending mft data allocation."); + ntfs_log_debug("Extending mft data allocation.\n"); mft_na = vol->mft_na; /* * Determine the preferred allocation location, i.e. the last lcn of @@ -898,14 +902,14 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) rl = ntfs_attr_find_vcn(mft_na, (mft_na->allocated_size - 1) >> vol->cluster_size_bits); if (!rl || !rl->length || rl->lcn < 0) { - ntfs_error(vol->sb, "Failed to determine last allocated " + ntfs_log_error("Failed to determine last allocated " "cluster of mft data attribute."); if (rl) errno = EIO; return -1; } lcn = rl->lcn + rl->length; - ntfs_debug("Last lcn of mft data attribute is 0x%llx.", (long long)lcn); + ntfs_log_debug("Last lcn of mft data attribute is 0x%llx.\n", (long long)lcn); /* Minimum allocation is one mft record worth of clusters. */ min_nr = vol->mft_record_size >> vol->cluster_size_bits; if (!min_nr) @@ -914,15 +918,15 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) nr = vol->mft_record_size << 4 >> vol->cluster_size_bits; if (!nr) nr = min_nr; - ntfs_debug("Trying mft data allocation with default cluster count " - "%lli.", (long long)nr); + ntfs_log_debug("Trying mft data allocation with default cluster count " + "%lli.\n", (long long)nr); old_last_vcn = rl[1].vcn; do { rl2 = ntfs_cluster_alloc(vol, old_last_vcn, nr, lcn, MFT_ZONE); if (rl2) break; if (errno != ENOSPC || nr == min_nr) { - ntfs_error(vol->sb, "Failed to allocate the minimal " + ntfs_log_error("Failed to allocate the minimal " "number of clusters (%lli) for the " "mft data attribute.", (long long)nr); return -1; @@ -933,35 +937,35 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) * before failing. */ nr = min_nr; - ntfs_debug("Retrying mft data allocation with minimal cluster " - "count %lli.", (long long)nr); + ntfs_log_debug("Retrying mft data allocation with minimal cluster " + "count %lli.\n", (long long)nr); } while (1); rl = ntfs_runlists_merge(mft_na->rl, rl2); if (!rl) { err = errno; - ntfs_error(vol->sb, "Failed to merge runlists for mft data " + ntfs_log_error("Failed to merge runlists for mft data " "attribute."); if (ntfs_cluster_free_from_rl(vol, rl2)) - ntfs_error(vol->sb, "Failed to deallocate clusters " + ntfs_log_error("Failed to deallocate clusters " "from the mft data attribute.%s", es); free(rl2); errno = err; return -1; } mft_na->rl = rl; - ntfs_debug("Allocated %lli clusters.", nr); + ntfs_log_debug("Allocated %lli clusters.\n", nr); /* Find the last run in the new runlist. */ for (; rl[1].length; rl++) ; /* Update the attribute record as well. */ ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); if (!ctx) { - ntfs_error(vol->sb, "Failed to get search context."); + ntfs_log_error("Failed to get search context."); goto undo_alloc; } if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find last attribute extent of " + ntfs_log_error("Failed to find last attribute extent of " "mft data attribute."); goto undo_alloc; } @@ -970,7 +974,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) ll = sle64_to_cpu(a->lowest_vcn); rl2 = ntfs_attr_find_vcn(mft_na, ll); if (!rl2 || !rl2->length) { - ntfs_error(vol->sb, "Failed to determine previous last " + ntfs_log_error("Failed to determine previous last " "allocated cluster of mft data attribute."); if (rl2) errno = EIO; @@ -979,7 +983,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) /* Get the size for the new mapping pairs array for this extent. */ mp_size = ntfs_get_size_for_mapping_pairs(vol, rl2, ll); if (mp_size <= 0) { - ntfs_error(vol->sb, "Get size for mapping pairs failed for " + ntfs_log_error("Get size for mapping pairs failed for " "mft data attribute extent."); goto undo_alloc; } @@ -988,7 +992,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) if (ntfs_attr_record_resize(m, a, mp_size + le16_to_cpu(a->mapping_pairs_offset))) { if (errno != ENOSPC) { - ntfs_error(vol->sb, "Failed to resize attribute " + ntfs_log_error("Failed to resize attribute " "record for mft data attribute."); goto undo_alloc; } @@ -997,7 +1001,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) // Note: Use the special reserved mft records and ensure that // this extent is not required to find the mft record in // question. - ntfs_error(vol->sb, "Not enough space in this mft record to " + ntfs_log_error("Not enough space in this mft record to " "accommodate extended mft data attribute " "extent. Cannot handle this yet."); errno = EOPNOTSUPP; @@ -1010,7 +1014,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp_size, rl2, ll, NULL)) { - ntfs_error(vol->sb, "Failed to build mapping pairs array of " + ntfs_log_error("Failed to build mapping pairs array of " "mft data attribute."); errno = EIO; goto undo_alloc; @@ -1032,7 +1036,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, 0, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find first attribute " + ntfs_log_error("Failed to find first attribute " "extent of mft data attribute."); goto restore_undo_alloc; } @@ -1049,7 +1053,7 @@ restore_undo_alloc: ntfs_attr_reinit_search_ctx(ctx); if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find last attribute extent of " + ntfs_log_error("Failed to find last attribute extent of " "mft data attribute.%s", es); ntfs_attr_put_search_ctx(ctx); mft_na->allocated_size += nr << vol->cluster_size_bits; @@ -1067,20 +1071,20 @@ restore_undo_alloc: undo_alloc: err = errno; if (ntfs_cluster_free(vol, mft_na, old_last_vcn, -1) < 0) - ntfs_error(vol->sb, "Failed to free clusters from mft data " + ntfs_log_error("Failed to free clusters from mft data " "attribute.%s", es); if (ntfs_rl_truncate(&mft_na->rl, old_last_vcn)) - ntfs_error(vol->sb, "Failed to truncate mft data attribute " + ntfs_log_error("Failed to truncate mft data attribute " "runlist.%s", es); if (mp_rebuilt) { if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(a->mapping_pairs_offset), old_alen - le16_to_cpu(a->mapping_pairs_offset), rl2, ll, NULL)) - ntfs_error(vol->sb, "Failed to restore mapping pairs " + ntfs_log_error("Failed to restore mapping pairs " "array.%s", es); if (ntfs_attr_record_resize(m, a, old_alen)) - ntfs_error(vol->sb, "Failed to restore attribute " + ntfs_log_error("Failed to restore attribute " "record.%s", es); ntfs_inode_mark_dirty(ctx->ntfs_ino); } @@ -1185,11 +1189,11 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) u16 seq_no, usn; if (base_ni) - ntfs_debug("Entering (allocating an extent mft record for " + ntfs_log_trace("Entering (allocating an extent mft record for " "base mft record 0x%llx).", (long long)base_ni->mft_no); else - ntfs_debug("Entering (allocating a base mft record)."); + ntfs_log_trace("Entering (allocating a base mft record).\n"); if (!vol || !vol->mft_na || !vol->mftbmp_na) { errno = EINVAL; return NULL; @@ -1198,7 +1202,7 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) mftbmp_na = vol->mftbmp_na; bit = ntfs_mft_bitmap_find_free_rec(vol, base_ni); if (bit >= 0) { - ntfs_debug("Found free record (#1), bit 0x%llx.", + ntfs_log_debug("Found free record (#1), bit 0x%llx.\n", (long long)bit); goto found_free_rec; } @@ -1218,7 +1222,7 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) bit = ll; if (bit < 24) bit = 24; - ntfs_debug("Found free record (#2), bit 0x%llx.", + ntfs_log_debug("Found free record (#2), bit 0x%llx.\n", (long long)bit); goto found_free_rec; } @@ -1227,19 +1231,19 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) * mft record that we can allocate. * Note: The smallest mft record we allocate is mft record 24. */ - ntfs_debug("Status of mftbmp before extension: allocated_size 0x%llx, " - "data_size 0x%llx, initialized_size 0x%llx.", + ntfs_log_debug("Status of mftbmp before extension: allocated_size 0x%llx, " + "data_size 0x%llx, initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); if (mftbmp_na->initialized_size + 8 > mftbmp_na->allocated_size) { /* Need to extend bitmap by one more cluster. */ - ntfs_debug("mftbmp: initialized_size + 8 > allocated_size."); + ntfs_log_debug("mftbmp: initialized_size + 8 > allocated_size.\n"); if (ntfs_mft_bitmap_extend_allocation(vol)) goto err_out; - ntfs_debug("Status of mftbmp after allocation extension: " + ntfs_log_debug("Status of mftbmp after allocation extension: " "allocated_size 0x%llx, data_size 0x%llx, " - "initialized_size 0x%llx.", + "initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); @@ -1252,46 +1256,46 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) bit = mftbmp_na->initialized_size << 3; if (ntfs_mft_bitmap_extend_initialized(vol)) goto err_out; - ntfs_debug("Status of mftbmp after initialized extension: " + ntfs_log_debug("Status of mftbmp after initialized extension: " "allocated_size 0x%llx, data_size 0x%llx, " - "initialized_size 0x%llx.", + "initialized_size 0x%llx.\n", (long long)mftbmp_na->allocated_size, (long long)mftbmp_na->data_size, (long long)mftbmp_na->initialized_size); - ntfs_debug("Found free record (#3), bit 0x%llx.", (long long)bit); + ntfs_log_debug("Found free record (#3), bit 0x%llx.\n", (long long)bit); found_free_rec: /* @bit is the found free mft record, allocate it in the mft bitmap. */ - ntfs_debug("At found_free_rec."); + ntfs_log_debug("At found_free_rec.\n"); if (ntfs_bitmap_set_bit(mftbmp_na, bit)) { - ntfs_error(vol->sb, "Failed to allocate bit in mft bitmap."); + ntfs_log_error("Failed to allocate bit in mft bitmap."); goto err_out; } - ntfs_debug("Set bit 0x%llx in mft bitmap.", (long long)bit); + ntfs_log_debug("Set bit 0x%llx in mft bitmap.\n", (long long)bit); /* The mft bitmap is now uptodate. Deal with mft data attribute now. */ ll = (bit + 1) << vol->mft_record_size_bits; if (ll <= mft_na->initialized_size) { - ntfs_debug("Allocated mft record already initialized."); + ntfs_log_debug("Allocated mft record already initialized.\n"); goto mft_rec_already_initialized; } - ntfs_debug("Initializing allocated mft record."); + ntfs_log_debug("Initializing allocated mft record.\n"); /* * The mft record is outside the initialized data. Extend the mft data * attribute until it covers the allocated record. The loop is only * actually traversed more than once when a freshly formatted volume is * first written to so it optimizes away nicely in the common case. */ - ntfs_debug("Status of mft data before extension: " + ntfs_log_debug("Status of mft data before extension: " "allocated_size 0x%llx, data_size 0x%llx, " - "initialized_size 0x%llx.", + "initialized_size 0x%llx.\n", (long long)mft_na->allocated_size, (long long)mft_na->data_size, (long long)mft_na->initialized_size); while (ll > mft_na->allocated_size) { if (ntfs_mft_data_extend_allocation(vol)) goto undo_mftbmp_alloc; - ntfs_debug("Status of mft data after allocation extension: " + ntfs_log_debug("Status of mft data after allocation extension: " "allocated_size 0x%llx, data_size 0x%llx, " - "initialized_size 0x%llx.", + "initialized_size 0x%llx.\n", (long long)mft_na->allocated_size, (long long)mft_na->data_size, (long long)mft_na->initialized_size); @@ -1310,22 +1314,22 @@ found_free_rec: mft_na->initialized_size += vol->mft_record_size; if (mft_na->initialized_size > mft_na->data_size) mft_na->data_size = mft_na->initialized_size; - ntfs_debug("Initializing mft record 0x%llx.", (long long)ll2); + ntfs_log_debug("Initializing mft record 0x%llx.\n", (long long)ll2); err = ntfs_mft_record_format(vol, ll2); if (err) { - ntfs_error(vol->sb, "Failed to format mft record."); + ntfs_log_error("Failed to format mft record."); goto undo_data_init; } } /* Update the mft data attribute record to reflect the new sizes. */ ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); if (!ctx) { - ntfs_error(vol->sb, "Failed to get search context."); + ntfs_log_error("Failed to get search context."); goto undo_data_init; } if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, 0, NULL, 0, ctx)) { - ntfs_error(vol->sb, "Failed to find first attribute extent of " + ntfs_log_error("Failed to find first attribute extent of " "mft data attribute."); ntfs_attr_put_search_ctx(ctx); goto undo_data_init; @@ -1336,9 +1340,9 @@ found_free_rec: /* Ensure the changes make it to disk. */ ntfs_inode_mark_dirty(ctx->ntfs_ino); ntfs_attr_put_search_ctx(ctx); - ntfs_debug("Status of mft data after mft record initialization: " + ntfs_log_debug("Status of mft data after mft record initialization: " "allocated_size 0x%llx, data_size 0x%llx, " - "initialized_size 0x%llx.", + "initialized_size 0x%llx.\n", (long long)mft_na->allocated_size, (long long)mft_na->data_size, (long long)mft_na->initialized_size); @@ -1357,20 +1361,20 @@ mft_rec_already_initialized: */ m = (MFT_RECORD*)malloc(vol->mft_record_size); if (!m) { - ntfs_error(vol->sb, "Failed to allocate buffer for mft " + ntfs_log_error("Failed to allocate buffer for mft " "record."); goto undo_mftbmp_alloc; } if (ntfs_mft_record_read(vol, bit, m)) { err = errno; - ntfs_error(vol->sb, "Failed to read mft record."); + ntfs_log_error("Failed to read mft record."); free(m); errno = err; goto undo_mftbmp_alloc; } /* Sanity check that the mft record is really not in use. */ if (ntfs_is_file_record(m->magic) && (m->flags & MFT_RECORD_IN_USE)) { - ntfs_error(vol->sb, "Mft record 0x%llx was marked unused in " + ntfs_log_error("Mft record 0x%llx was marked unused in " "mft bitmap but is marked used itself. " "Corrupt filesystem or library bug! " "Run chkdsk immediately!", (long long)bit); @@ -1382,7 +1386,7 @@ mft_rec_already_initialized: usn = *(u16*)((u8*)m + le16_to_cpu(m->usa_ofs)); if (ntfs_mft_record_layout(vol, bit, m)) { err = errno; - ntfs_error(vol->sb, "Failed to re-format mft record."); + ntfs_log_error("Failed to re-format mft record."); free(m); errno = err; goto undo_mftbmp_alloc; @@ -1398,7 +1402,7 @@ mft_rec_already_initialized: ni = ntfs_inode_allocate(vol); if (!ni) { err = errno; - ntfs_error(vol->sb, "Failed to allocate buffer for inode."); + ntfs_log_error("Failed to allocate buffer for inode."); free(m); errno = err; goto undo_mftbmp_alloc; @@ -1427,7 +1431,7 @@ mft_rec_already_initialized: extent_nis = (ntfs_inode**)malloc(i); if (!extent_nis) { err = errno; - ntfs_error(vol->sb, "Failed to allocate " + ntfs_log_error("Failed to allocate " "buffer for extent inodes " "array."); free(m); @@ -1455,7 +1459,7 @@ mft_rec_already_initialized: if (!base_ni) vol->mft_data_pos = bit + 1; /* Return the opened, allocated inode of the allocated mft record. */ - ntfs_debug("Returning opened, allocated %sinode 0x%llx.", + ntfs_log_debug("Returning opened, allocated %sinode 0x%llx.\n", base_ni ? "extent " : "", (long long)bit); return ni; undo_data_init: @@ -1464,7 +1468,7 @@ undo_data_init: undo_mftbmp_alloc: err = errno; if (ntfs_bitmap_clear_bit(mftbmp_na, bit)) - ntfs_error(vol->sb, "Failed to clear bit in mft bitmap.%s", es); + ntfs_log_error("Failed to clear bit in mft bitmap.%s", es); errno = err; err_out: if (!errno) @@ -1489,8 +1493,7 @@ int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni) int err; u16 seq_no, old_seq_no; - Dprintf("%s(): Entering for inode 0x%llx.\n", - __FUNCTION__, (long long) ni->mft_no); + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); if (!vol || !vol->mftbmp_na || !ni) { errno = EINVAL; @@ -1535,8 +1538,8 @@ int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni) /* Rollback what we did... */ bitmap_rollback: if (ntfs_bitmap_set_bit(vol->mftbmp_na, mft_no)) - Dputs("Eeek! Rollback failed in ntfs_mft_record_free(). " - "Leaving inconsistent metadata!"); + ntfs_log_debug("Eeek! Rollback failed in ntfs_mft_record_free(). " + "Leaving inconsistent metadata!\n"); sync_rollback: ni->mrec->flags |= MFT_RECORD_IN_USE; ni->mrec->sequence_number = old_seq_no; @@ -1557,7 +1560,7 @@ sync_rollback: /** * ntfs_mft_remove_attr */ -int ntfs_mft_remove_attr (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_TYPES type) +int ntfs_mft_remove_attr(struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_TYPES type) { ATTR_RECORD *attr20, *attrXX; MFT_RECORD *mft; @@ -1567,28 +1570,28 @@ int ntfs_mft_remove_attr (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_TYPES ty if (!inode) return 1; - attr20 = find_first_attribute (AT_ATTRIBUTE_LIST, inode->mrec); + attr20 = find_first_attribute(AT_ATTRIBUTE_LIST, inode->mrec); if (attr20) return 1; - printf ("remove inode %lld, attr 0x%02X\n", inode->mft_no, type); + ntfs_log_debug("remove inode %lld, attr 0x%02X\n", inode->mft_no, type); - attrXX = find_first_attribute (type, inode->mrec); + attrXX = find_first_attribute(type, inode->mrec); if (!attrXX) return 1; - if (utils_free_non_residents3 (bmp, inode, attrXX)) + if (utils_free_non_residents3(bmp, inode, attrXX)) return 1; // remove entry // inode->mrec mft = inode->mrec; - //utils_dump_mem (mft, 0, mft->bytes_in_use, DM_DEFAULTS); printf ("\n"); + //utils_dump_mem(mft, 0, mft->bytes_in_use, DM_DEFAULTS); ntfs_log_debug("\n"); - //utils_dump_mem (attrXX, 0, attrXX->length, DM_DEFAULTS); printf ("\n"); + //utils_dump_mem(attrXX, 0, attrXX->length, DM_DEFAULTS); ntfs_log_debug("\n"); - //printf ("mrec = %p, attr = %p, diff = %d (0x%02X)\n", mft, attrXX, (u8*)attrXX - (u8*)mft, (u8*)attrXX - (u8*)mft); + //ntfs_log_debug("mrec = %p, attr = %p, diff = %d (0x%02X)\n", mft, attrXX, (u8*)attrXX - (u8*)mft, (u8*)attrXX - (u8*)mft); // memmove dst = (u8*) attrXX; @@ -1599,14 +1602,14 @@ int ntfs_mft_remove_attr (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_TYPES ty mft->bytes_in_use -= attrXX->length; #if 0 - printf ("dst = 0x%02X, src = 0x%02X, len = 0x%02X\n", (dst - (u8*)mft), (src - (u8*)mft), len); - printf ("attr %02X, len = 0x%02X\n", attrXX->type, attrXX->length); - printf ("bytes in use = 0x%02X\n", mft->bytes_in_use); - printf ("\n"); + ntfs_log_debug("dst = 0x%02X, src = 0x%02X, len = 0x%02X\n", (dst - (u8*)mft), (src - (u8*)mft), len); + ntfs_log_debug("attr %02X, len = 0x%02X\n", attrXX->type, attrXX->length); + ntfs_log_debug("bytes in use = 0x%02X\n", mft->bytes_in_use); + ntfs_log_debug("\n"); #endif - memmove (dst, src, len); - //utils_dump_mem (mft, 0, mft->bytes_in_use, DM_DEFAULTS); printf ("\n"); + memmove(dst, src, len); + //utils_dump_mem(mft, 0, mft->bytes_in_use, DM_DEFAULTS); ntfs_log_debug("\n"); NInoSetDirty(inode); return 0; @@ -1615,7 +1618,7 @@ int ntfs_mft_remove_attr (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_TYPES ty /** * ntfs_mft_add_attr */ -ATTR_RECORD * ntfs_mft_add_attr (ntfs_inode *inode, ATTR_TYPES type, u8 *data, int data_len) +ATTR_RECORD * ntfs_mft_add_attr(ntfs_inode *inode, ATTR_TYPES type, u8 *data, int data_len) { MFT_RECORD *mrec; ATTR_RECORD *attr; @@ -1630,14 +1633,14 @@ ATTR_RECORD * ntfs_mft_add_attr (ntfs_inode *inode, ATTR_TYPES type, u8 *data, i if (!data) return NULL; - attr_size = ATTR_SIZE (data_len); + attr_size = ATTR_SIZE(data_len); mrec = inode->mrec; if (!mrec) return NULL; if ((mrec->bytes_in_use + attr_size + 0x18) > mrec->bytes_allocated) { - printf ("attribute is too big to fit in the record\n"); + ntfs_log_debug("attribute is too big to fit in the record\n"); return NULL; } @@ -1651,13 +1654,13 @@ ATTR_RECORD * ntfs_mft_add_attr (ntfs_inode *inode, ATTR_TYPES type, u8 *data, i ptr += attr->length; } - //printf ("insert before attr 0x%02X\n", attr->type); + //ntfs_log_debug("insert before attr 0x%02X\n", attr->type); len = ((u8*) mrec + mrec->bytes_in_use) - ((u8*) attr); src = (u8*) attr; dst = src + attr_size + 0x18; - memmove (dst, src, len); + memmove(dst, src, len); src = data; dst = (u8*) attr + 0x18; @@ -1665,11 +1668,11 @@ ATTR_RECORD * ntfs_mft_add_attr (ntfs_inode *inode, ATTR_TYPES type, u8 *data, i // XXX wipe slack space after attr? - memcpy (dst, src, len); + memcpy(dst, src, len); mrec->bytes_in_use += attr_size + 0x18; - memset (attr, 0, 0x18); + memset(attr, 0, 0x18); *(u32*)((u8*) attr + 0x00) = type; *(u32*)((u8*) attr + 0x04) = attr_size + 0x18; *(u16*)((u8*) attr + 0x0E) = mrec->next_attr_instance; @@ -1684,7 +1687,7 @@ ATTR_RECORD * ntfs_mft_add_attr (ntfs_inode *inode, ATTR_TYPES type, u8 *data, i /** * ntfs_mft_resize_resident */ -int ntfs_mft_resize_resident (ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len, u8 *data, int data_len) +int ntfs_mft_resize_resident(ntfs_inode *inode, ATTR_TYPES type, ntfschar *name, int name_len, u8 *data, int data_len) { int mft_size; int mft_usage; @@ -1713,12 +1716,12 @@ int ntfs_mft_resize_resident (ntfs_inode *inode, ATTR_TYPES type, ntfschar *name mft_usage = mrec->bytes_in_use; mft_free = mft_size - mft_usage; - //printf ("mft_size = %d\n", mft_size); - //printf ("mft_usage = %d\n", mft_usage); - //printf ("mft_free = %d\n", mft_free); - //printf ("\n"); + //ntfs_log_debug("mft_size = %d\n", mft_size); + //ntfs_log_debug("mft_usage = %d\n", mft_usage); + //ntfs_log_debug("mft_free = %d\n", mft_free); + //ntfs_log_debug("\n"); - ctx = ntfs_attr_get_search_ctx (NULL, mrec); + ctx = ntfs_attr_get_search_ctx(NULL, mrec); if (!ctx) goto done; @@ -1728,57 +1731,57 @@ int ntfs_mft_resize_resident (ntfs_inode *inode, ATTR_TYPES type, ntfschar *name arec = ctx->attr; if (arec->non_resident) { - printf ("attribute isn't resident\n"); + ntfs_log_debug("attribute isn't resident\n"); goto done; } attr_orig = arec->value_length; attr_new = data_len; - //printf ("attr orig = %d\n", attr_orig); - //printf ("attr new = %d\n", attr_new); - //printf ("\n"); + //ntfs_log_debug("attr orig = %d\n", attr_orig); + //ntfs_log_debug("attr new = %d\n", attr_new); + //ntfs_log_debug("\n"); if ((attr_new - attr_orig + mft_usage) > mft_size) { - printf ("attribute won't fit into mft record\n"); + ntfs_log_debug("attribute won't fit into mft record\n"); goto done; } - //printf ("new free space = %d\n", mft_size - (attr_new - attr_orig + mft_usage)); + //ntfs_log_debug("new free space = %d\n", mft_size - (attr_new - attr_orig + mft_usage)); src = (u8*)arec + arec->length; dst = src + (attr_new - attr_orig); end = (u8*)mrec + mft_usage; len = end - src; - //printf ("src = %d\n", src - (u8*)mrec); - //printf ("dst = %d\n", dst - (u8*)mrec); - //printf ("end = %d\n", end - (u8*)mrec); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - (u8*)mrec); + //ntfs_log_debug("dst = %d\n", dst - (u8*)mrec); + //ntfs_log_debug("end = %d\n", end - (u8*)mrec); + //ntfs_log_debug("len = %d\n", len); if (src != dst) - memmove (dst, src, len); + memmove(dst, src, len); - memcpy ((u8*)arec + arec->value_offset, data, data_len); + memcpy((u8*)arec + arec->value_offset, data, data_len); mrec->bytes_in_use += (attr_new - attr_orig); arec->length += (attr_new - attr_orig); arec->value_length += (attr_new - attr_orig); - memset ((u8*)mrec + mrec->bytes_in_use, 0, mft_size - mrec->bytes_in_use); + memset((u8*)mrec + mrec->bytes_in_use, 0, mft_size - mrec->bytes_in_use); mft_usage += (attr_new - attr_orig); - //utils_dump_mem (mrec, 0, mft_size, DM_DEFAULTS); + //utils_dump_mem(mrec, 0, mft_size, DM_DEFAULTS); res = 0; done: - ntfs_attr_put_search_ctx (ctx); + ntfs_attr_put_search_ctx(ctx); return res; } /** * ntfs_mft_free_space */ -int ntfs_mft_free_space (struct ntfs_dir *dir) +int ntfs_mft_free_space(struct ntfs_dir *dir) { int res = 0; MFT_RECORD *mft; @@ -1796,7 +1799,7 @@ int ntfs_mft_free_space (struct ntfs_dir *dir) /** * ntfs_mft_add_index */ -int ntfs_mft_add_index (struct ntfs_dir *dir) +int ntfs_mft_add_index(struct ntfs_dir *dir) { ntfs_volume *vol; u8 *buffer = NULL; @@ -1814,31 +1817,31 @@ int ntfs_mft_add_index (struct ntfs_dir *dir) return 1; vol = dir->vol; - printf ("add two attrs to " YELLOW); ntfs_name_print (dir->name, dir->name_len); printf (END "\n"); - printf ("index size = %d\n", dir->index_size); + ntfs_log_debug("add two attrs to " YELLOW); ntfs_name_print(dir->name, dir->name_len); ntfs_log_debug(END "\n"); + ntfs_log_debug("index size = %d\n", dir->index_size); - buffer = malloc (dir->index_size); + buffer = malloc(dir->index_size); if (!buffer) return 1; - dt = ntfs_dt_create (dir, dir->index, -1); + dt = ntfs_dt_create(dir, dir->index, -1); if (!dt) return 1; dt->vcn = 0; // New alloc record - ie = ntfs_ie_copy (dir->index->children[dir->index->child_count-1]); - ie = ntfs_ie_set_vcn (ie, dt->vcn); + ie = ntfs_ie_copy(dir->index->children[dir->index->child_count-1]); + ie = ntfs_ie_set_vcn(ie, dt->vcn); // can't replace ie yet, there may not be room - ntfs_ie_free (ie); + ntfs_ie_free(ie); - ntfs_dt_transfer2 (dir->index, dt, 0, dir->index->child_count - 1); + ntfs_dt_transfer2(dir->index, dt, 0, dir->index->child_count - 1); - printf ("root has %d children\n", dir->index->child_count); - printf ("node has %d children\n", dt->child_count); + ntfs_log_debug("root has %d children\n", dir->index->child_count); + ntfs_log_debug("node has %d children\n", dt->child_count); - ntfs_dt_free (dt); + ntfs_dt_free(dt); // create a new dt // attach dt to dir @@ -1851,14 +1854,14 @@ int ntfs_mft_add_index (struct ntfs_dir *dir) // need disk allocation before here // Index Allocation - memset (buffer, 0, 128); - attr = ntfs_mft_add_attr (dir->inode, AT_INDEX_ALLOCATION, buffer, 0x48); + memset(buffer, 0, 128); + attr = ntfs_mft_add_attr(dir->inode, AT_INDEX_ALLOCATION, buffer, 0x48); // Bitmap - memset (buffer, 0, 8); + memset(buffer, 0, 8); buffer[0] = 0x01; - //printf ("inode = %p\n", dir->inode); - attr = ntfs_mft_add_attr (dir->inode, AT_BITMAP, buffer, 8); + //ntfs_log_debug("inode = %p\n", dir->inode); + attr = ntfs_mft_add_attr(dir->inode, AT_BITMAP, buffer, 8); // attach alloc and bitmap to dir // need to create ntfs_attr's for them @@ -1866,15 +1869,15 @@ int ntfs_mft_add_index (struct ntfs_dir *dir) // one indx record // 8 bits of bitmap - if (0) ntfs_bmp_find_space (NULL, 0, 0); + if (0) ntfs_bmp_find_space(NULL, 0, 0); - //printf ("m1 = %lld\n", vol->mft_zone_start); - //printf ("m2 = %lld\n", vol->mft_zone_end); - //printf ("m3 = %lld\n", vol->mft_zone_pos); - //printf ("z1 = %lld\n", vol->data1_zone_pos); - //printf ("z2 = %lld\n", vol->data2_zone_pos); + //ntfs_log_debug("m1 = %lld\n", vol->mft_zone_start); + //ntfs_log_debug("m2 = %lld\n", vol->mft_zone_end); + //ntfs_log_debug("m3 = %lld\n", vol->mft_zone_pos); + //ntfs_log_debug("z1 = %lld\n", vol->data1_zone_pos); + //ntfs_log_debug("z2 = %lld\n", vol->data2_zone_pos); - free (buffer); + free(buffer); return 0; } diff --git a/libntfs/mst.c b/libntfs/mst.c index 72587d4c..140700ea 100644 --- a/libntfs/mst.c +++ b/libntfs/mst.c @@ -1,4 +1,4 @@ -/* +/** * mst.c - Multi sector fixup handling code. Part of the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov @@ -19,13 +19,16 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif -#include "mst.h" #ifdef HAVE_ERRNO_H #include #endif +#include "mst.h" + /** * ntfs_mst_post_read_fixup - deprotect multi sector transfer protected data * @b: pointer to the data to deprotect diff --git a/libntfs/rich.c b/libntfs/rich.c index aefe4a3e..42cc0022 100644 --- a/libntfs/rich.c +++ b/libntfs/rich.c @@ -21,9 +21,17 @@ #ifdef NTFS_RICH +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H #include +#endif + #include "rich.h" #include "layout.h" +#include "logging.h" /** * find_attribute - Find an attribute of the given type @@ -39,7 +47,7 @@ * Return: Pointer Success, an attribute was found * NULL Error, no matching attributes were found */ -ATTR_RECORD * find_attribute (const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) +ATTR_RECORD * find_attribute(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) { if (!ctx) { errno = EINVAL; @@ -47,11 +55,11 @@ ATTR_RECORD * find_attribute (const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) } if (ntfs_attr_lookup(type, NULL, 0, 0, 0, NULL, 0, ctx) != 0) { - Dprintf ("find_attribute didn't find an attribute of type: 0x%02x.\n", type); + ntfs_log_debug("find_attribute didn't find an attribute of type: 0x%02x.\n", type); return NULL; /* None / no more of that type */ } - Dprintf ("find_attribute found an attribute of type: 0x%02x.\n", type); + ntfs_log_debug("find_attribute found an attribute of type: 0x%02x.\n", type); return ctx->attr; } @@ -69,7 +77,7 @@ ATTR_RECORD * find_attribute (const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) * Return: Pointer Success, an attribute was found * NULL Error, no matching attributes were found */ -ATTR_RECORD * find_first_attribute (const ATTR_TYPES type, MFT_RECORD *mft) +ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft) { ntfs_attr_search_ctx *ctx; ATTR_RECORD *rec; @@ -79,41 +87,41 @@ ATTR_RECORD * find_first_attribute (const ATTR_TYPES type, MFT_RECORD *mft) return NULL; } - ctx = ntfs_attr_get_search_ctx (NULL, mft); + ctx = ntfs_attr_get_search_ctx(NULL, mft); if (!ctx) { - //XXX Eprintf ("Couldn't create a search context.\n"); + //XXX ntfs_log_error("Couldn't create a search context.\n"); return NULL; } - rec = find_attribute (type, ctx); - ntfs_attr_put_search_ctx (ctx); + rec = find_attribute(type, ctx); + ntfs_attr_put_search_ctx(ctx); if (rec) - Dprintf ("find_first_attribute: found attr of type 0x%02x.\n", type); + ntfs_log_debug("find_first_attribute: found attr of type 0x%02x.\n", type); else - Dprintf ("find_first_attribute: didn't find attr of type 0x%02x.\n", type); + ntfs_log_debug("find_first_attribute: didn't find attr of type 0x%02x.\n", type); return rec; } /** * ntfs_name_print */ -void ntfs_name_print (ntfschar *name, int name_len) +void ntfs_name_print(ntfschar *name, int name_len) { char *buffer = NULL; if (name_len) { - ntfs_ucstombs (name, name_len, &buffer, 0); - printf ("%s", buffer); - free (buffer); + ntfs_ucstombs(name, name_len, &buffer, 0); + ntfs_log_info("%s", buffer); + free(buffer); } else { - printf ("!"); + ntfs_log_info("!"); } } /** * utils_free_non_residents3 */ -int utils_free_non_residents3 (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_RECORD *attr) +int utils_free_non_residents3(struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_RECORD *attr) { ntfs_attr *na; runlist_element *rl; @@ -129,19 +137,19 @@ int utils_free_non_residents3 (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_REC if (!attr->non_resident) return 0; - na = ntfs_attr_open (inode, attr->type, NULL, 0); + na = ntfs_attr_open(inode, attr->type, NULL, 0); if (!na) return 1; - ntfs_attr_map_whole_runlist (na); + ntfs_attr_map_whole_runlist(na); rl = na->rl; size = na->allocated_size >> inode->vol->cluster_size_bits; for (count = 0; count < size; count += rl->length, rl++) { - if (ntfs_bmp_set_range (bmp, rl->lcn, rl->length, 0) < 0) { - printf (RED "set range : %lld - %lld FAILED\n" END, rl->lcn, rl->lcn+rl->length-1); + if (ntfs_bmp_set_range(bmp, rl->lcn, rl->length, 0) < 0) { + ntfs_log_info(RED "set range : %lld - %lld FAILED\n" END, rl->lcn, rl->lcn+rl->length-1); } } - ntfs_attr_close (na); + ntfs_attr_close(na); return 0; } @@ -149,7 +157,7 @@ int utils_free_non_residents3 (struct ntfs_bmp *bmp, ntfs_inode *inode, ATTR_REC /** * utils_free_non_residents2 */ -int utils_free_non_residents2 (ntfs_inode *inode, struct ntfs_bmp *bmp) +int utils_free_non_residents2(ntfs_inode *inode, struct ntfs_bmp *bmp) { ntfs_attr_search_ctx *ctx; @@ -158,17 +166,17 @@ int utils_free_non_residents2 (ntfs_inode *inode, struct ntfs_bmp *bmp) if (!bmp) return -1; - ctx = ntfs_attr_get_search_ctx (NULL, inode->mrec); + ctx = ntfs_attr_get_search_ctx(NULL, inode->mrec); if (!ctx) { - printf ("can't create a search context\n"); + ntfs_log_info("can't create a search context\n"); return -1; } while (ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx) == 0) { - utils_free_non_residents3 (bmp, inode, ctx->attr); + utils_free_non_residents3(bmp, inode, ctx->attr); } - ntfs_attr_put_search_ctx (ctx); + ntfs_attr_put_search_ctx(ctx); return 0; } diff --git a/libntfs/runlist.c b/libntfs/runlist.c index 058f2313..f70f3e35 100644 --- a/libntfs/runlist.c +++ b/libntfs/runlist.c @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDIO_H #include @@ -37,13 +39,13 @@ #endif #include "compat.h" - #include "types.h" #include "attrib.h" #include "volume.h" #include "layout.h" #include "debug.h" #include "device.h" +#include "logging.h" /** * Internal: @@ -114,8 +116,8 @@ static __inline__ BOOL ntfs_rl_are_mergeable(runlist_element *dst, runlist_element *src) { if (!dst || !src) { - Dputs("Eeek. ntfs_rl_are_mergeable() invoked with NULL " - "pointer!"); + ntfs_log_debug("Eeek. ntfs_rl_are_mergeable() invoked with NULL " + "pointer!\n"); return FALSE; } @@ -182,7 +184,8 @@ static __inline__ runlist_element *ntfs_rl_append(runlist_element *dst, int marker; /* End of the inserted runs */ if (!dst || !src) { - Dputs("Eeek. ntfs_rl_append() invoked with NULL pointer!"); + ntfs_log_debug("Eeek. ntfs_rl_append() invoked with NULL " + "pointer!\n"); errno = EINVAL; return NULL; } @@ -251,7 +254,8 @@ static __inline__ runlist_element *ntfs_rl_insert(runlist_element *dst, int marker; /* End of the inserted runs */ if (!dst || !src) { - Dputs("Eeek. ntfs_rl_insert() invoked with NULL pointer!"); + ntfs_log_debug("Eeek. ntfs_rl_insert() invoked with NULL " + "pointer!\n"); errno = EINVAL; return NULL; } @@ -349,7 +353,8 @@ static __inline__ runlist_element *ntfs_rl_replace(runlist_element *dst, int marker; /* End of the inserted runs */ if (!dst || !src) { - Dputs("Eeek. ntfs_rl_replace() invoked with NULL pointer!"); + ntfs_log_debug("Eeek. ntfs_rl_replace() invoked with NULL " + "pointer!\n"); errno = EINVAL; return NULL; } @@ -428,7 +433,7 @@ static __inline__ runlist_element *ntfs_rl_split(runlist_element *dst, int dsize, runlist_element *src, int ssize, int loc) { if (!dst || !src) { - Dputs("Eeek. ntfs_rl_split() invoked with NULL pointer!"); + ntfs_log_debug("Eeek. ntfs_rl_split() invoked with NULL pointer!\n"); errno = EINVAL; return NULL; } @@ -499,9 +504,9 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl, int marker = 0; VCN marker_vcn = 0; - Dputs("dst:"); + ntfs_log_debug("dst:\n"); ntfs_debug_runlist_dump(drl); - Dputs("src:"); + ntfs_log_debug("src:\n"); ntfs_debug_runlist_dump(srl); /* Check for silly calling... */ @@ -537,8 +542,8 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl, /* Can't have an entirely unmapped source runlist. */ if (!srl[si].length) { - Dputs("Eeek! ntfs_runlists_merge() received entirely " - "unmapped source runlist."); + ntfs_log_debug("Eeek! ntfs_runlists_merge() received entirely " + "unmapped source runlist.\n"); errno = EINVAL; return NULL; } @@ -560,7 +565,7 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl, /* Sanity check for illegal overlaps. */ if ((drl[di].vcn == srl[si].vcn) && (drl[di].lcn >= 0) && (srl[si].lcn >= 0)) { - Dputs("Run lists overlap. Cannot merge!"); + ntfs_log_debug("Run lists overlap. Cannot merge!\n"); errno = ERANGE; return NULL; } @@ -598,10 +603,10 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl, if (marker && (drl[dins].vcn + drl[dins].length > srl[send - 1].vcn)) finish = FALSE; #ifdef DEBUG - Dprintf("dfinal = %i, dend = %i\n", dfinal, dend); - Dprintf("sstart = %i, sfinal = %i, send = %i\n", sstart, sfinal, send); - Dprintf("start = %i, finish = %i\n", start, finish); - Dprintf("ds = %i, ss = %i, dins = %i\n", ds, ss, dins); + ntfs_log_debug("dfinal = %i, dend = %i\n", dfinal, dend); + ntfs_log_debug("sstart = %i, sfinal = %i, send = %i\n", sstart, sfinal, send); + ntfs_log_debug("start = %i, finish = %i\n", start, finish); + ntfs_log_debug("ds = %i, ss = %i, dins = %i\n", ds, ss, dins); #endif if (start) { if (finish) @@ -615,13 +620,12 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl, drl = ntfs_rl_split(drl, ds, srl + sstart, ss, dins); } if (!drl) { - Dprintf("%s(): Merge failed: %s\n", __FUNCTION__, - strerror(errno)); + ntfs_log_perror("Merge failed"); return drl; } free(srl); if (marker) { - Dputs("Triggering marker code."); + ntfs_log_debug("Triggering marker code.\n"); for (ds = dend; drl[ds].length; ds++) ; /* We only need to care if @srl ended after @drl. */ @@ -629,7 +633,7 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl, int slots = 0; if (drl[ds].vcn == marker_vcn) { - Dprintf("Old marker = %lli, replacing with " + ntfs_log_debug("Old marker = %lli, replacing with " "LCN_ENOENT.\n", (long long)drl[ds].lcn); drl[ds].lcn = (LCN)LCN_ENOENT; @@ -684,14 +688,14 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl, finished: /* The merge was completed successfully. */ - Dputs("Merged runlist:"); + ntfs_log_debug("Merged runlist:\n"); ntfs_debug_runlist_dump(drl); return drl; critical_error: /* Critical error! We cannot afford to fail here. */ - Dperror("libntfs: Critical error"); - Dputs("Forcing segmentation fault!"); + ntfs_log_perror("libntfs: Critical error"); + ntfs_log_debug("Forcing segmentation fault!\n"); marker_vcn = ((runlist*)NULL)->lcn; return drl; } @@ -737,7 +741,7 @@ runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, runlist_elements. */ u8 b; /* Current byte offset in buf. */ - Dprintf("%s(): Entering for attr 0x%x.\n", __FUNCTION__, + ntfs_log_trace("Entering for attr 0x%x.\n", (unsigned)le32_to_cpu(attr->type)); /* Make sure attr exists and is non-resident. */ if (!attr || !attr->non_resident || @@ -752,7 +756,7 @@ runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, buf = (const u8*)attr + le16_to_cpu(attr->mapping_pairs_offset); attr_end = (const u8*)attr + le32_to_cpu(attr->length); if (buf < (const u8*)attr || buf > attr_end) { - Dputs("Corrupt attribute."); + ntfs_log_debug("Corrupt attribute.\n"); errno = EIO; return NULL; } @@ -803,7 +807,8 @@ runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, for (deltaxcn = (s8)buf[b--]; b; b--) deltaxcn = (deltaxcn << 8) + buf[b]; } else { /* The length entry is compulsory. */ - Dputs("Missing length entry in mapping pairs array."); + ntfs_log_debug("Missing length entry in mapping pairs " + "array.\n"); deltaxcn = (s64)-1; } /* @@ -811,7 +816,7 @@ runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, * hence clean-up and return NULL. */ if (deltaxcn < 0) { - Dputs("Invalid length in mapping pairs array."); + ntfs_log_debug("Invalid length in mapping pairs array.\n"); goto err_out; } /* @@ -848,15 +853,15 @@ runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, */ if (vol->major_ver < 3) { if (deltaxcn == (LCN)-1) - Dputs("lcn delta == -1"); + ntfs_log_debug("lcn delta == -1\n"); if (lcn == (LCN)-1) - Dputs("lcn == -1"); + ntfs_log_debug("lcn == -1\n"); } #endif /* Check lcn is not below -1. */ if (lcn < (LCN)-1) { - Dputs("Invalid LCN < -1 in mapping pairs " - "array."); + ntfs_log_debug("Invalid LCN < -1 in mapping pairs " + "array.\n"); goto err_out; } /* Enter the current lcn into the runlist element. */ @@ -876,7 +881,8 @@ runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, deltaxcn = sle64_to_cpu(attr->highest_vcn); if (deltaxcn && vcn - 1 != deltaxcn) { mpa_err: - Dputs("Corrupt mapping pairs array in non-resident attribute."); + ntfs_log_debug("Corrupt mapping pairs array in non-resident " + "attribute.\n"); goto err_out; } /* Setup not mapped runlist element if this is the base extent. */ @@ -898,8 +904,8 @@ mpa_err: * this one. */ if (deltaxcn < max_cluster) { - Dprintf("More extents to follow; deltaxcn = 0x%llx, " - "max_cluster = 0x%llx\n", + ntfs_log_debug("More extents to follow; deltaxcn = " + "0x%llx, max_cluster = 0x%llx\n", (long long)deltaxcn, (long long)max_cluster); rl[rlpos].vcn = vcn; @@ -907,8 +913,8 @@ mpa_err: rl[rlpos].lcn = (LCN)LCN_RL_NOT_MAPPED; rlpos++; } else if (deltaxcn > max_cluster) { - Dprintf("Corrupt attribute. deltaxcn = 0x%llx, " - "max_cluster = 0x%llx", + ntfs_log_debug("Corrupt attribute. deltaxcn = " + "0x%llx, max_cluster = 0x%llx", (long long)deltaxcn, (long long)max_cluster); goto mpa_err; @@ -923,7 +929,7 @@ mpa_err: rl[rlpos].length = (s64)0; /* If no existing runlist was specified, we are done. */ if (!old_rl) { - Dputs("Mapping pairs array successfully decompressed:"); + ntfs_log_debug("Mapping pairs array successfully decompressed:\n"); ntfs_debug_runlist_dump(rl); return rl; } @@ -933,11 +939,11 @@ mpa_err: return old_rl; err = errno; free(rl); - Dputs("Failed to merge runlists."); + ntfs_log_debug("Failed to merge runlists.\n"); errno = err; return NULL; io_error: - Dputs("Corrupt attribute."); + ntfs_log_debug("Corrupt attribute.\n"); err_out: free(rl); errno = EIO; @@ -1256,15 +1262,15 @@ int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol, int rls; if (start_vcn < 0) { - Dprintf("%s(): start_vcn %lld (should be >= 0)", - __FUNCTION__, (long long) start_vcn); + ntfs_log_trace("start_vcn %lld (should be >= 0)\n", + (long long) start_vcn); errno = EINVAL; return -1; } if (!rl) { if (start_vcn) { - Dprintf("%s(): rl NULL, start_vcn %lld (should be > 0)", - __FUNCTION__, (long long) start_vcn); + ntfs_log_trace("rl NULL, start_vcn %lld (should be > 0)\n", + (long long) start_vcn); errno = EINVAL; return -1; } @@ -1581,8 +1587,8 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn) rl = *arl; if (start_vcn < rl->vcn) { // FIXME: Eeek! BUG() - Dprintf("%s(): Eeek! start_vcn lies outside front of " - "runlist! Aborting.\n", __FUNCTION__); + ntfs_log_trace("Eeek! start_vcn lies outside front of runlist! " + "Aborting.\n"); errno = EIO; return -1; } @@ -1594,15 +1600,14 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn) } if (!rl->length) { // FIXME: Weird, probably a BUG()! - Dprintf("%s(): Weird! Asking to truncate already truncated " - "runlist?!? Abort.\n", __FUNCTION__); + ntfs_log_trace("Weird! Asking to truncate already truncated " + "runlist?!? Abort.\n"); errno = EIO; return -1; } if (start_vcn < rl->vcn) { // FIXME: Eeek! BUG() - Dprintf("%s(): Eeek! start_vcn < rl->vcn! Aborting.\n", - __FUNCTION__); + ntfs_log_trace("Eeek! start_vcn < rl->vcn! Aborting.\n"); errno = EIO; return -1; } @@ -1635,9 +1640,8 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn) *arl = NULL; else { // FIXME: Eeek! - Dprintf("%s(): Eeek! Failed to reallocate runlist " - "buffer! Continuing regardless and " - "returning success.\n", __FUNCTION__); + ntfs_log_trace("Eeek! Failed to reallocate runlist buffer! " + "Continuing regardless and returning success.\n"); } } /* Done! */ @@ -1655,7 +1659,7 @@ int ntfs_rl_sparse(runlist *rl) runlist *rlc; if (!rl) { - Dprintf("%s(): Invalid argument passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid argument passed.\n"); errno = EINVAL; return -1; } @@ -1663,8 +1667,7 @@ int ntfs_rl_sparse(runlist *rl) for (rlc = rl; rlc->length; rlc++) if (rlc->lcn < 0) { if (rlc->lcn != LCN_HOLE) { - Dprintf("%s(): Received unmapped runlist.\n", - __FUNCTION__); + ntfs_log_trace("Received unmapped runlist.\n"); errno = EINVAL; return -1; } @@ -1686,7 +1689,7 @@ s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl) s64 ret = 0; if (!rl) { - Dprintf("%s(): Invalid argument passed.\n", __FUNCTION__); + ntfs_log_trace("Invalid argument passed.\n"); errno = EINVAL; return -1; } @@ -1694,8 +1697,7 @@ s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl) for (rlc = rl; rlc->length; rlc++) { if (rlc->lcn < 0) { if (rlc->lcn != LCN_HOLE) { - Dprintf("%s(): Received unmapped runlist.\n", - __FUNCTION__); + ntfs_log_trace("Received unmapped runlist.\n"); errno = EINVAL; return -1; } @@ -1720,7 +1722,7 @@ s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl) /** * test_rl_dump_runlist */ -static void test_rl_dump_runlist (const runlist_element *rl) +static void test_rl_dump_runlist(const runlist_element *rl) { int abbr = 0; /* abbreviate long lists */ int len = 0; @@ -1728,20 +1730,20 @@ static void test_rl_dump_runlist (const runlist_element *rl) const char *lcn_str[5] = { "HOLE", "NOTMAP", "ENOENT", "XXXX" }; if (!rl) { - printf(" Run list not present.\n"); + ntfs_log_debug(" Run list not present.\n"); return; } if (abbr) for (len = 0; rl[len].length; len++) ; - printf(" VCN LCN len\n"); + ntfs_log_debug(" VCN LCN len\n"); for (i = 0; ; i++, rl++) { LCN lcn = rl->lcn; if ((abbr) && (len > 20)) { if (i == 4) - printf (" ...\n"); + ntfs_log_debug(" ...\n"); if ((i > 3) && (i < (len - 3))) continue; } @@ -1751,35 +1753,35 @@ static void test_rl_dump_runlist (const runlist_element *rl) if (ind > -LCN_ENOENT - 1) ind = 3; - printf("%8lld %8s %8lld\n", + ntfs_log_debug("%8lld %8s %8lld\n", rl->vcn, lcn_str[ind], rl->length); } else - printf("%8lld %8lld %8lld\n", + ntfs_log_debug("%8lld %8lld %8lld\n", rl->vcn, rl->lcn, rl->length); if (!rl->length) break; } if ((abbr) && (len > 20)) - printf (" (%d entries)\n", len+1); - printf ("\n"); + ntfs_log_debug(" (%d entries)\n", len+1); + ntfs_log_debug("\n"); } /** * test_rl_runlists_merge */ -static runlist_element * test_rl_runlists_merge (runlist_element *drl, runlist_element *srl) +static runlist_element * test_rl_runlists_merge(runlist_element *drl, runlist_element *srl) { runlist_element *res = NULL; - printf ("dst:\n"); - test_rl_dump_runlist (drl); - printf ("src:\n"); - test_rl_dump_runlist (srl); + ntfs_log_debug("dst:\n"); + test_rl_dump_runlist(drl); + ntfs_log_debug("src:\n"); + test_rl_dump_runlist(srl); - res = ntfs_runlists_merge (drl, srl); + res = ntfs_runlists_merge(drl, srl); - printf ("res:\n"); - test_rl_dump_runlist (res); + ntfs_log_debug("res:\n"); + test_rl_dump_runlist(res); return res; } @@ -1787,29 +1789,29 @@ static runlist_element * test_rl_runlists_merge (runlist_element *drl, runlist_e /** * test_rl_read_buffer */ -static int test_rl_read_buffer (const char *file, u8 *buf, int bufsize) +static int test_rl_read_buffer(const char *file, u8 *buf, int bufsize) { FILE *fptr; - fptr = fopen (file, "r"); + fptr = fopen(file, "r"); if (!fptr) { - printf ("open %s\n", file); + ntfs_log_debug("open %s\n", file); return 0; } - if (fread (buf, bufsize, 1, fptr) == 99) { - printf ("read %s\n", file); + if (fread(buf, bufsize, 1, fptr) == 99) { + ntfs_log_debug("read %s\n", file); return 0; } - fclose (fptr); + fclose(fptr); return 1; } /** * test_rl_pure_src */ -static runlist_element * test_rl_pure_src (BOOL contig, BOOL multi, int vcn, int len) +static runlist_element * test_rl_pure_src(BOOL contig, BOOL multi, int vcn, int len) { runlist_element *result; int fudge; @@ -1819,16 +1821,16 @@ static runlist_element * test_rl_pure_src (BOOL contig, BOOL multi, int vcn, int else fudge = 999; - result = malloc (4096); + result = malloc(4096); if (multi) { - MKRL (result+0, vcn + (0*len/4), fudge + vcn + 1000 + (0*len/4), len / 4) - MKRL (result+1, vcn + (1*len/4), fudge + vcn + 1000 + (1*len/4), len / 4) - MKRL (result+2, vcn + (2*len/4), fudge + vcn + 1000 + (2*len/4), len / 4) - MKRL (result+3, vcn + (3*len/4), fudge + vcn + 1000 + (3*len/4), len / 4) - MKRL (result+4, vcn + (4*len/4), LCN_RL_NOT_MAPPED, 0) + MKRL(result+0, vcn + (0*len/4), fudge + vcn + 1000 + (0*len/4), len / 4) + MKRL(result+1, vcn + (1*len/4), fudge + vcn + 1000 + (1*len/4), len / 4) + MKRL(result+2, vcn + (2*len/4), fudge + vcn + 1000 + (2*len/4), len / 4) + MKRL(result+3, vcn + (3*len/4), fudge + vcn + 1000 + (3*len/4), len / 4) + MKRL(result+4, vcn + (4*len/4), LCN_RL_NOT_MAPPED, 0) } else { - MKRL (result+0, vcn, fudge + vcn + 1000, len) - MKRL (result+1, vcn + len, LCN_RL_NOT_MAPPED, 0) + MKRL(result+0, vcn, fudge + vcn + 1000, len) + MKRL(result+1, vcn + len, LCN_RL_NOT_MAPPED, 0) } return result; } @@ -1836,27 +1838,27 @@ static runlist_element * test_rl_pure_src (BOOL contig, BOOL multi, int vcn, int /** * test_rl_pure_test */ -static void test_rl_pure_test (int test, BOOL contig, BOOL multi, int vcn, int len, runlist_element *file, int size) +static void test_rl_pure_test(int test, BOOL contig, BOOL multi, int vcn, int len, runlist_element *file, int size) { runlist_element *src; runlist_element *dst; runlist_element *res; - src = test_rl_pure_src (contig, multi, vcn, len); - dst = malloc (4096); + src = test_rl_pure_src(contig, multi, vcn, len); + dst = malloc(4096); - memcpy (dst, file, size); + memcpy(dst, file, size); - printf ("Test %2d ----------\n", test); - res = test_rl_runlists_merge (dst, src); + ntfs_log_debug("Test %2d ----------\n", test); + res = test_rl_runlists_merge(dst, src); - free (res); + free(res); } /** * test_rl_pure */ -static void test_rl_pure (char *contig, char *multi) +static void test_rl_pure(char *contig, char *multi) { /* VCN, LCN, len */ static runlist_element file1[] = { @@ -1894,118 +1896,118 @@ static void test_rl_pure (char *contig, char *multi) }; BOOL c, m; - if (strcmp (contig, "contig") == 0) + if (strcmp(contig, "contig") == 0) c = TRUE; - else if (strcmp (contig, "noncontig") == 0) + else if (strcmp(contig, "noncontig") == 0) c = FALSE; else { - printf ("rl pure [contig|noncontig] [single|multi]\n"); + ntfs_log_debug("rl pure [contig|noncontig] [single|multi]\n"); return; } - if (strcmp (multi, "multi") == 0) + if (strcmp(multi, "multi") == 0) m = TRUE; - else if (strcmp (multi, "single") == 0) + else if (strcmp(multi, "single") == 0) m = FALSE; else { - printf ("rl pure [contig|noncontig] [single|multi]\n"); + ntfs_log_debug("rl pure [contig|noncontig] [single|multi]\n"); return; } - test_rl_pure_test (1, c, m, 0, 40, file1, sizeof (file1)); - test_rl_pure_test (2, c, m, 40, 40, file1, sizeof (file1)); - test_rl_pure_test (3, c, m, 60, 40, file1, sizeof (file1)); - test_rl_pure_test (4, c, m, 0, 100, file1, sizeof (file1)); - test_rl_pure_test (5, c, m, 200, 40, file1, sizeof (file1)); - test_rl_pure_test (6, c, m, 240, 40, file1, sizeof (file1)); - test_rl_pure_test (7, c, m, 260, 40, file1, sizeof (file1)); - test_rl_pure_test (8, c, m, 200, 100, file1, sizeof (file1)); - test_rl_pure_test (9, c, m, 400, 40, file1, sizeof (file1)); - test_rl_pure_test (10, c, m, 440, 40, file1, sizeof (file1)); - test_rl_pure_test (11, c, m, 460, 40, file1, sizeof (file1)); - test_rl_pure_test (12, c, m, 400, 100, file1, sizeof (file1)); - test_rl_pure_test (13, c, m, 160, 100, file2, sizeof (file2)); - test_rl_pure_test (14, c, m, 100, 140, file2, sizeof (file2)); - test_rl_pure_test (15, c, m, 200, 40, file2, sizeof (file2)); - test_rl_pure_test (16, c, m, 240, 40, file2, sizeof (file2)); - test_rl_pure_test (17, c, m, 100, 40, file3, sizeof (file3)); - test_rl_pure_test (18, c, m, 140, 40, file3, sizeof (file3)); - test_rl_pure_test (19, c, m, 0, 40, file4, sizeof (file4)); - test_rl_pure_test (20, c, m, 40, 40, file4, sizeof (file4)); - test_rl_pure_test (21, c, m, 0, 40, file5, sizeof (file5)); - test_rl_pure_test (22, c, m, 40, 40, file5, sizeof (file5)); - test_rl_pure_test (23, c, m, 60, 40, file5, sizeof (file5)); - test_rl_pure_test (24, c, m, 0, 100, file5, sizeof (file5)); - test_rl_pure_test (25, c, m, 200, 40, file5, sizeof (file5)); - test_rl_pure_test (26, c, m, 240, 40, file5, sizeof (file5)); - test_rl_pure_test (27, c, m, 260, 40, file5, sizeof (file5)); - test_rl_pure_test (28, c, m, 200, 100, file5, sizeof (file5)); - test_rl_pure_test (29, c, m, 400, 40, file5, sizeof (file5)); - test_rl_pure_test (30, c, m, 440, 40, file5, sizeof (file5)); - test_rl_pure_test (31, c, m, 460, 40, file5, sizeof (file5)); - test_rl_pure_test (32, c, m, 400, 100, file5, sizeof (file5)); - test_rl_pure_test (33, c, m, 160, 100, file6, sizeof (file6)); - test_rl_pure_test (34, c, m, 100, 140, file6, sizeof (file6)); + test_rl_pure_test(1, c, m, 0, 40, file1, sizeof(file1)); + test_rl_pure_test(2, c, m, 40, 40, file1, sizeof(file1)); + test_rl_pure_test(3, c, m, 60, 40, file1, sizeof(file1)); + test_rl_pure_test(4, c, m, 0, 100, file1, sizeof(file1)); + test_rl_pure_test(5, c, m, 200, 40, file1, sizeof(file1)); + test_rl_pure_test(6, c, m, 240, 40, file1, sizeof(file1)); + test_rl_pure_test(7, c, m, 260, 40, file1, sizeof(file1)); + test_rl_pure_test(8, c, m, 200, 100, file1, sizeof(file1)); + test_rl_pure_test(9, c, m, 400, 40, file1, sizeof(file1)); + test_rl_pure_test(10, c, m, 440, 40, file1, sizeof(file1)); + test_rl_pure_test(11, c, m, 460, 40, file1, sizeof(file1)); + test_rl_pure_test(12, c, m, 400, 100, file1, sizeof(file1)); + test_rl_pure_test(13, c, m, 160, 100, file2, sizeof(file2)); + test_rl_pure_test(14, c, m, 100, 140, file2, sizeof(file2)); + test_rl_pure_test(15, c, m, 200, 40, file2, sizeof(file2)); + test_rl_pure_test(16, c, m, 240, 40, file2, sizeof(file2)); + test_rl_pure_test(17, c, m, 100, 40, file3, sizeof(file3)); + test_rl_pure_test(18, c, m, 140, 40, file3, sizeof(file3)); + test_rl_pure_test(19, c, m, 0, 40, file4, sizeof(file4)); + test_rl_pure_test(20, c, m, 40, 40, file4, sizeof(file4)); + test_rl_pure_test(21, c, m, 0, 40, file5, sizeof(file5)); + test_rl_pure_test(22, c, m, 40, 40, file5, sizeof(file5)); + test_rl_pure_test(23, c, m, 60, 40, file5, sizeof(file5)); + test_rl_pure_test(24, c, m, 0, 100, file5, sizeof(file5)); + test_rl_pure_test(25, c, m, 200, 40, file5, sizeof(file5)); + test_rl_pure_test(26, c, m, 240, 40, file5, sizeof(file5)); + test_rl_pure_test(27, c, m, 260, 40, file5, sizeof(file5)); + test_rl_pure_test(28, c, m, 200, 100, file5, sizeof(file5)); + test_rl_pure_test(29, c, m, 400, 40, file5, sizeof(file5)); + test_rl_pure_test(30, c, m, 440, 40, file5, sizeof(file5)); + test_rl_pure_test(31, c, m, 460, 40, file5, sizeof(file5)); + test_rl_pure_test(32, c, m, 400, 100, file5, sizeof(file5)); + test_rl_pure_test(33, c, m, 160, 100, file6, sizeof(file6)); + test_rl_pure_test(34, c, m, 100, 140, file6, sizeof(file6)); } /** * test_rl_zero */ -static void test_rl_zero (void) +static void test_rl_zero(void) { runlist_element *jim = NULL; runlist_element *bob = NULL; - bob = calloc (3, sizeof (runlist_element)); + bob = calloc(3, sizeof(runlist_element)); if (!bob) return; MKRL(bob+0, 10, 99, 5) MKRL(bob+1, 15, LCN_RL_NOT_MAPPED, 0) - jim = test_rl_runlists_merge (jim, bob); + jim = test_rl_runlists_merge(jim, bob); if (!jim) return; - free (jim); + free(jim); } /** * test_rl_frag_combine */ -static void test_rl_frag_combine (ntfs_volume *vol, ATTR_RECORD *attr1, ATTR_RECORD *attr2, ATTR_RECORD *attr3) +static void test_rl_frag_combine(ntfs_volume *vol, ATTR_RECORD *attr1, ATTR_RECORD *attr2, ATTR_RECORD *attr3) { runlist_element *run1; runlist_element *run2; runlist_element *run3; - run1 = ntfs_mapping_pairs_decompress (vol, attr1, NULL); + run1 = ntfs_mapping_pairs_decompress(vol, attr1, NULL); if (!run1) return; - run2 = ntfs_mapping_pairs_decompress (vol, attr2, NULL); + run2 = ntfs_mapping_pairs_decompress(vol, attr2, NULL); if (!run2) return; - run1 = test_rl_runlists_merge (run1, run2); + run1 = test_rl_runlists_merge(run1, run2); - run3 = ntfs_mapping_pairs_decompress (vol, attr3, NULL); + run3 = ntfs_mapping_pairs_decompress(vol, attr3, NULL); if (!run3) return; - run1 = test_rl_runlists_merge (run1, run3); + run1 = test_rl_runlists_merge(run1, run3); - free (run1); + free(run1); } /** * test_rl_frag */ -static void test_rl_frag (char *test) +static void test_rl_frag(char *test) { ntfs_volume vol; - ATTR_RECORD *attr1 = malloc (1024); - ATTR_RECORD *attr2 = malloc (1024); - ATTR_RECORD *attr3 = malloc (1024); + ATTR_RECORD *attr1 = malloc(1024); + ATTR_RECORD *attr2 = malloc(1024); + ATTR_RECORD *attr3 = malloc(1024); if (!attr1 || !attr2 || !attr3) goto out; @@ -2016,36 +2018,36 @@ static void test_rl_frag (char *test) vol.cluster_size_bits = 11; vol.major_ver = 3; - if (!test_rl_read_buffer ("runlist-data/attr1.bin", (u8*) attr1, 1024)) + if (!test_rl_read_buffer("runlist-data/attr1.bin", (u8*) attr1, 1024)) goto out; - if (!test_rl_read_buffer ("runlist-data/attr2.bin", (u8*) attr2, 1024)) + if (!test_rl_read_buffer("runlist-data/attr2.bin", (u8*) attr2, 1024)) goto out; - if (!test_rl_read_buffer ("runlist-data/attr3.bin", (u8*) attr3, 1024)) + if (!test_rl_read_buffer("runlist-data/attr3.bin", (u8*) attr3, 1024)) goto out; - if (strcmp (test, "123") == 0) test_rl_frag_combine (&vol, attr1, attr2, attr3); - else if (strcmp (test, "132") == 0) test_rl_frag_combine (&vol, attr1, attr3, attr2); - else if (strcmp (test, "213") == 0) test_rl_frag_combine (&vol, attr2, attr1, attr3); - else if (strcmp (test, "231") == 0) test_rl_frag_combine (&vol, attr2, attr3, attr1); - else if (strcmp (test, "312") == 0) test_rl_frag_combine (&vol, attr3, attr1, attr2); - else if (strcmp (test, "321") == 0) test_rl_frag_combine (&vol, attr3, attr2, attr1); - else printf ("Frag: No such test '%s'\n", test); + if (strcmp(test, "123") == 0) test_rl_frag_combine(&vol, attr1, attr2, attr3); + else if (strcmp(test, "132") == 0) test_rl_frag_combine(&vol, attr1, attr3, attr2); + else if (strcmp(test, "213") == 0) test_rl_frag_combine(&vol, attr2, attr1, attr3); + else if (strcmp(test, "231") == 0) test_rl_frag_combine(&vol, attr2, attr3, attr1); + else if (strcmp(test, "312") == 0) test_rl_frag_combine(&vol, attr3, attr1, attr2); + else if (strcmp(test, "321") == 0) test_rl_frag_combine(&vol, attr3, attr2, attr1); + else ntfs_log_debug("Frag: No such test '%s'\n", test); out: - free (attr1); - free (attr2); - free (attr3); + free(attr1); + free(attr2); + free(attr3); } /** * test_rl_main */ -int test_rl_main (int argc, char *argv[]) +int test_rl_main(int argc, char *argv[]) { - if ((argc == 2) && (strcmp (argv[1], "zero") == 0)) test_rl_zero(); - else if ((argc == 3) && (strcmp (argv[1], "frag") == 0)) test_rl_frag (argv[2]); - else if ((argc == 4) && (strcmp (argv[1], "pure") == 0)) test_rl_pure (argv[2], argv[3]); - else printf ("rl [zero|frag|pure] {args}\n"); + if ((argc == 2) && (strcmp(argv[1], "zero") == 0)) test_rl_zero(); + else if ((argc == 3) && (strcmp(argv[1], "frag") == 0)) test_rl_frag(argv[2]); + else if ((argc == 4) && (strcmp(argv[1], "pure") == 0)) test_rl_pure(argv[2], argv[3]); + else ntfs_log_debug("rl [zero|frag|pure] {args}\n"); return 0; } diff --git a/libntfs/security.c b/libntfs/security.c index fec170ef..e30e6662 100644 --- a/libntfs/security.c +++ b/libntfs/security.c @@ -1,6 +1,5 @@ -/* - * security.c - Code for handling security/ACLs in NTFS. Part of the - * Linux-NTFS project. +/** + * security.c - Handling security/ACLs in NTFS. Part of the Linux-NTFS project. * * Copyright (c) 2004 Anton Altaparmakov * @@ -20,7 +19,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDIO_H #include @@ -249,12 +250,11 @@ err_out: return NULL; } -/* - * GUID generate_guid(GUID *guid) +/** + * GUID generate_guid(GUID *guid) * generatates a random current guid * perhaps not a very good random number generator though... */ - GUID *generate_guid(GUID *guid) { int i; @@ -262,9 +262,9 @@ GUID *generate_guid(GUID *guid) { for (i = 0; i < 16; i++) { array[i] = (u8)(random() & 0xFF); - if (i == 7) + if (i == 7) array[7] = (array[7] & 0x0F) | 0x40; - if (i == 8) + if (i == 8) array[8] = (array[8] & 0x3F) | 0x80; } memcpy(guid, array, sizeof(guid)); diff --git a/libntfs/tree.c b/libntfs/tree.c index dbbaec36..1256ecae 100644 --- a/libntfs/tree.c +++ b/libntfs/tree.c @@ -21,7 +21,9 @@ #ifdef NTFS_RICH +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -29,17 +31,17 @@ #include "volume.h" #include "dir.h" - #include "tree.h" #include "bitmap.h" #include "index.h" #include "inode.h" +#include "logging.h" #include "rich.h" /** * ntfs_dt_free */ -void ntfs_dt_free (struct ntfs_dt *dt) +void ntfs_dt_free(struct ntfs_dt *dt) { int i; @@ -47,21 +49,21 @@ void ntfs_dt_free (struct ntfs_dt *dt) return; for (i = 0; i < dt->child_count; i++) { - ntfs_dt_free (dt->sub_nodes[i]); - ntfs_inode_close2 (dt->inodes[i]); + ntfs_dt_free(dt->sub_nodes[i]); + ntfs_inode_close2(dt->inodes[i]); } - free (dt->sub_nodes); - free (dt->children); - free (dt->inodes); - free (dt->data); // XXX is this always ours? - free (dt); + free(dt->sub_nodes); + free(dt->children); + free(dt->inodes); + free(dt->data); // XXX is this always ours? + free(dt); } /** * ntfs_dt_rollback */ -int ntfs_dt_rollback (struct ntfs_dt *dt) +int ntfs_dt_rollback(struct ntfs_dt *dt) { int i; @@ -73,16 +75,16 @@ int ntfs_dt_rollback (struct ntfs_dt *dt) if (dt->changed) { // We can't trust anything below us in the tree for (i = 0; i < dt->child_count; i++) { - ntfs_dt_free (dt->sub_nodes[i]); - ntfs_inode_close2 (dt->inodes[i]); + ntfs_dt_free(dt->sub_nodes[i]); + ntfs_inode_close2(dt->inodes[i]); } dt->child_count = 0; - free (dt->data); - free (dt->children); - free (dt->sub_nodes); - free (dt->inodes); + free(dt->data); + free(dt->children); + free(dt->sub_nodes); + free(dt->inodes); dt->data = NULL; dt->children = NULL; @@ -91,8 +93,8 @@ int ntfs_dt_rollback (struct ntfs_dt *dt) } else { // This node is OK, check the su-nodes for (i = 0; i < dt->child_count; i++) { - if (ntfs_dt_rollback (dt->sub_nodes[i])) { - ntfs_inode_close2 (dt->inodes[i]); + if (ntfs_dt_rollback(dt->sub_nodes[i])) { + ntfs_inode_close2(dt->inodes[i]); // Child was changed so unmap it dt->sub_nodes[i] = NULL; dt->inodes[i] = NULL; @@ -106,7 +108,7 @@ int ntfs_dt_rollback (struct ntfs_dt *dt) /** * ntfs_dt_commit */ -int ntfs_dt_commit (struct ntfs_dt *dt) +int ntfs_dt_commit(struct ntfs_dt *dt) { ntfs_volume *vol; ntfs_attr *attr; @@ -125,38 +127,38 @@ int ntfs_dt_commit (struct ntfs_dt *dt) if (dt->changed) { if (dt->parent) { - printf ("commit dt (alloc)\n"); + ntfs_log_debug("commit dt (alloc)\n"); attr = dt->dir->ialloc; size = dt->dir->index_size; - //utils_dump_mem (dt->data, 0, size, DM_DEFAULTS); + //utils_dump_mem(dt->data, 0, size, DM_DEFAULTS); #ifdef RM_WRITE ntfs_attr_mst_pwrite(attr, dt->vcn * vol->cluster_size, 1, size, dt->data); // XXX retval #endif } else { - printf ("commit dt (root)\n"); + ntfs_log_debug("commit dt (root)\n"); attr = dt->dir->iroot; size = dt->data_len; - //utils_dump_mem (dt->data, 0, size, DM_DEFAULTS); + //utils_dump_mem(dt->data, 0, size, DM_DEFAULTS); #ifdef RM_WRITE ntfs_attr_pwrite(attr, 0, size, dt->data); // XXX retval #endif } - printf (RED "\tntfs_attr_pwrite (vcn %lld)\n" END, dt->vcn); + ntfs_log_debug(RED "\tntfs_attr_pwrite(vcn %lld)\n" END, dt->vcn); dt->changed = FALSE; } for (i = 0; i < dt->child_count; i++) { - if ((dt->inodes[i]) && (NInoDirty (dt->inodes[i]))) { - //utils_dump_mem (dt->inodes[i]->mrec, 0, vol->mft_record_size, DM_DEFAULTS); + if ((dt->inodes[i]) && (NInoDirty(dt->inodes[i]))) { + //utils_dump_mem(dt->inodes[i]->mrec, 0, vol->mft_record_size, DM_DEFAULTS); #ifdef RM_WRITE - ntfs_inode_sync (dt->inodes[i]); + ntfs_inode_sync(dt->inodes[i]); #endif - printf (RED "\tntfs_inode_sync %llu\n" END, dt->inodes[i]->mft_no); + ntfs_log_debug(RED "\tntfs_inode_sync %llu\n" END, dt->inodes[i]->mft_no); } - if (ntfs_dt_commit (dt->sub_nodes[i]) < 0) + if (ntfs_dt_commit(dt->sub_nodes[i]) < 0) return -1; } @@ -166,7 +168,7 @@ int ntfs_dt_commit (struct ntfs_dt *dt) /** * ntfs_dt_create_children2 */ -BOOL ntfs_dt_create_children2 (struct ntfs_dt *dt, int count) +BOOL ntfs_dt_create_children2(struct ntfs_dt *dt, int count) { // XXX calculate for 2K and 4K indexes max and min filenames (inc/exc VCN) @@ -176,16 +178,16 @@ BOOL ntfs_dt_create_children2 (struct ntfs_dt *dt, int count) if (old == new) return TRUE; - dt->children = realloc (dt->children, new * sizeof (*dt->children)); - dt->sub_nodes = realloc (dt->sub_nodes, new * sizeof (*dt->sub_nodes)); - dt->inodes = realloc (dt->inodes, new * sizeof (*dt->inodes)); + dt->children = realloc(dt->children, new * sizeof(*dt->children)); + dt->sub_nodes = realloc(dt->sub_nodes, new * sizeof(*dt->sub_nodes)); + dt->inodes = realloc(dt->inodes, new * sizeof(*dt->inodes)); if (!dt->children || !dt->sub_nodes || !dt->inodes) return FALSE; // dt->child_count = -1 ? - memset ((u8*)dt->children + old, 0, (new - old) * sizeof (*dt->children)); - memset ((u8*)dt->sub_nodes + old, 0, (new - old) * sizeof (*dt->sub_nodes)); - memset ((u8*)dt->inodes + old, 0, (new - old) * sizeof (*dt->inodes)); + memset((u8*)dt->children + old, 0, (new - old) * sizeof(*dt->children)); + memset((u8*)dt->sub_nodes + old, 0, (new - old) * sizeof(*dt->sub_nodes)); + memset((u8*)dt->inodes + old, 0, (new - old) * sizeof(*dt->inodes)); return TRUE; } @@ -193,12 +195,12 @@ BOOL ntfs_dt_create_children2 (struct ntfs_dt *dt, int count) /** * ntfs_dt_resize_children3 */ -BOOL ntfs_dt_resize_children3 (struct ntfs_dt *dt, int new) +BOOL ntfs_dt_resize_children3(struct ntfs_dt *dt, int new) { int old; // XXX calculate for 2K and 4K indexes max and min filenames (inc/exc VCN) - // XXX assumption: sizeof (*dt->children) == sizeof (*dt->sub_nodes) == sizeof (*dt->inodes) + // XXX assumption: sizeof(*dt->children) == sizeof(*dt->sub_nodes) == sizeof(*dt->inodes) // XXX put back blocking factor if (!dt) @@ -210,20 +212,20 @@ BOOL ntfs_dt_resize_children3 (struct ntfs_dt *dt, int new) dt->child_count = new; - old *= sizeof (*dt->children); - new *= sizeof (*dt->children); + old *= sizeof(*dt->children); + new *= sizeof(*dt->children); - dt->children = realloc (dt->children, new); - dt->sub_nodes = realloc (dt->sub_nodes, new); - dt->inodes = realloc (dt->inodes, new); + dt->children = realloc(dt->children, new); + dt->sub_nodes = realloc(dt->sub_nodes, new); + dt->inodes = realloc(dt->inodes, new); if (!dt->children || !dt->sub_nodes || !dt->inodes) return FALSE; if (new > old) { - memset ((u8*)dt->children + old, 0, (new - old)); - memset ((u8*)dt->sub_nodes + old, 0, (new - old)); - memset ((u8*)dt->inodes + old, 0, (new - old)); + memset((u8*)dt->children + old, 0, (new - old)); + memset((u8*)dt->sub_nodes + old, 0, (new - old)); + memset((u8*)dt->inodes + old, 0, (new - old)); } return TRUE; @@ -232,7 +234,7 @@ BOOL ntfs_dt_resize_children3 (struct ntfs_dt *dt, int new) /** * ntfs_dt_root_count */ -int ntfs_dt_root_count (struct ntfs_dt *dt) +int ntfs_dt_root_count(struct ntfs_dt *dt) { u8 *buffer = NULL; u8 *ptr = NULL; @@ -264,27 +266,27 @@ int ntfs_dt_root_count (struct ntfs_dt *dt) while (ptr < (buffer + size)) { entry = (INDEX_ENTRY*) ptr; - ntfs_dt_resize_children3 (dt, dt->child_count + 1); // XXX retval + ntfs_dt_resize_children3(dt, dt->child_count + 1); // XXX retval if (entry->flags & INDEX_ENTRY_NODE) { - vcn = ntfs_ie_get_vcn ((INDEX_ENTRY*) ptr); - //printf ("VCN %lld\n", vcn); + vcn = ntfs_ie_get_vcn((INDEX_ENTRY*) ptr); + //ntfs_log_debug("VCN %lld\n", vcn); } if (!(entry->flags & INDEX_ENTRY_END)) { - ntfs_ucstombs (entry->key.file_name.file_name, entry->key.file_name.file_name_length, &name, 0); - //printf ("\tinode %8lld %s\n", MREF (entry->indexed_file), name); - free (name); + ntfs_ucstombs(entry->key.file_name.file_name, entry->key.file_name.file_name_length, &name, 0); + //ntfs_log_debug("\tinode %8lld %s\n", MREF(entry->indexed_file), name); + free(name); name = NULL; } - //printf ("CC[%d] = %p\n", dt->child_count-1, entry); + //ntfs_log_debug("CC[%d] = %p\n", dt->child_count-1, entry); dt->children[dt->child_count-1] = entry; ptr += entry->length; } - //printf ("count = %d\n\n", dt->child_count); + //ntfs_log_debug("count = %d\n\n", dt->child_count); return dt->child_count; } @@ -292,7 +294,7 @@ int ntfs_dt_root_count (struct ntfs_dt *dt) /** * ntfs_dt_alloc_count */ -int ntfs_dt_alloc_count (struct ntfs_dt *dt) +int ntfs_dt_alloc_count(struct ntfs_dt *dt) { u8 *buffer = NULL; u8 *ptr = NULL; @@ -309,24 +311,24 @@ int ntfs_dt_alloc_count (struct ntfs_dt *dt) buffer = dt->data; size = dt->data_len; - //utils_dump_mem (buffer, 0, 128, DM_DEFAULTS); + //utils_dump_mem(buffer, 0, 128, DM_DEFAULTS); block = (INDEX_BLOCK*) buffer; - //printf ("INDX %lld\n", block->index_block_vcn); + //ntfs_log_debug("INDX %lld\n", block->index_block_vcn); ptr = buffer + 0x18 + block->index.entries_offset; - //printf ("block size %d\n", block->index.index_length); + //ntfs_log_debug("block size %d\n", block->index.index_length); dt->child_count = 0; - //printf ("start = 0x%02X, end = 0x%02X\n", 0x18 + block->index.entries_offset, 0x18 + block->index.index_length); + //ntfs_log_debug("start = 0x%02X, end = 0x%02X\n", 0x18 + block->index.entries_offset, 0x18 + block->index.index_length); while (ptr < (buffer + 0x18 + block->index.index_length)) { entry = (INDEX_ENTRY*) ptr; - ntfs_dt_resize_children3 (dt, dt->child_count + 1); // XXX retval + ntfs_dt_resize_children3(dt, dt->child_count + 1); // XXX retval if (entry->flags & INDEX_ENTRY_NODE) { - vcn = ntfs_ie_get_vcn ((INDEX_ENTRY*) ptr); - //printf ("\tVCN %lld\n", vcn); + vcn = ntfs_ie_get_vcn((INDEX_ENTRY*) ptr); + //ntfs_log_debug("\tVCN %lld\n", vcn); } dt->children[dt->child_count-1] = entry; @@ -334,15 +336,15 @@ int ntfs_dt_alloc_count (struct ntfs_dt *dt) if (entry->flags & INDEX_ENTRY_END) { break; } else { - ntfs_ucstombs (entry->key.file_name.file_name, entry->key.file_name.file_name_length, &name, 0); - //printf ("\tinode %8lld %s\n", MREF (entry->indexed_file), name); - free (name); + ntfs_ucstombs(entry->key.file_name.file_name, entry->key.file_name.file_name_length, &name, 0); + //ntfs_log_debug("\tinode %8lld %s\n", MREF(entry->indexed_file), name); + free(name); name = NULL; } ptr += entry->length; } - //printf ("count = %d\n", dt->child_count); + //ntfs_log_debug("count = %d\n", dt->child_count); return dt->child_count; } @@ -350,7 +352,7 @@ int ntfs_dt_alloc_count (struct ntfs_dt *dt) /** * ntfs_dt_initialise2 */ -int ntfs_dt_initialise2 (ntfs_volume *vol, struct ntfs_dt *dt) +int ntfs_dt_initialise2(ntfs_volume *vol, struct ntfs_dt *dt) { INDEX_ALLOCATION *alloc; INDEX_ENTRY *entry; @@ -360,7 +362,7 @@ int ntfs_dt_initialise2 (ntfs_volume *vol, struct ntfs_dt *dt) if (!dt) return 1; - memset (dt->data, 0, dt->data_len); + memset(dt->data, 0, dt->data_len); alloc = (INDEX_ALLOCATION*) dt->data; @@ -382,7 +384,7 @@ int ntfs_dt_initialise2 (ntfs_volume *vol, struct ntfs_dt *dt) entry->key_length = 0; entry->flags = INDEX_ENTRY_END; - ntfs_dt_resize_children3 (dt, 1); // XXX retval + ntfs_dt_resize_children3(dt, 1); // XXX retval dt->children[0] = entry; @@ -392,7 +394,7 @@ int ntfs_dt_initialise2 (ntfs_volume *vol, struct ntfs_dt *dt) /** * ntfs_dt_create */ -struct ntfs_dt * ntfs_dt_create (struct ntfs_dir *dir, struct ntfs_dt *parent, VCN vcn) +struct ntfs_dt * ntfs_dt_create(struct ntfs_dir *dir, struct ntfs_dt *parent, VCN vcn) { struct ntfs_dt *dt = NULL; //int i; @@ -400,7 +402,7 @@ struct ntfs_dt * ntfs_dt_create (struct ntfs_dir *dir, struct ntfs_dt *parent, V if (!dir) return NULL; - dt = calloc (1, sizeof (*dt)); + dt = calloc(1, sizeof(*dt)); if (!dt) return NULL; @@ -414,76 +416,76 @@ struct ntfs_dt * ntfs_dt_create (struct ntfs_dir *dir, struct ntfs_dt *parent, V dt->changed = FALSE; if (parent) { - //printf ("alloc a = %lld\n", dir->ialloc->allocated_size); - //printf ("alloc d = %lld\n", dir->ialloc->data_size); - //printf ("alloc i = %lld\n", dir->ialloc->initialized_size); - //printf ("vcn = %lld\n", vcn); + //ntfs_log_debug("alloc a = %lld\n", dir->ialloc->allocated_size); + //ntfs_log_debug("alloc d = %lld\n", dir->ialloc->data_size); + //ntfs_log_debug("alloc i = %lld\n", dir->ialloc->initialized_size); + //ntfs_log_debug("vcn = %lld\n", vcn); dt->data_len = dt->dir->index_size; - //printf ("parent size = %d\n", dt->data_len); - dt->data = malloc (dt->data_len); + //ntfs_log_debug("parent size = %d\n", dt->data_len); + dt->data = malloc(dt->data_len); if (vcn >= 0) { - //printf ("%lld\n", ntfs_attr_mst_pread (dir->ialloc, vcn*512, 1, dt->data_len, dt->data)); - ntfs_attr_mst_pread (dir->ialloc, vcn*512, 1, dt->data_len, dt->data); + //ntfs_log_debug("%lld\n", ntfs_attr_mst_pread(dir->ialloc, vcn*512, 1, dt->data_len, dt->data)); + ntfs_attr_mst_pread(dir->ialloc, vcn*512, 1, dt->data_len, dt->data); } else { - ntfs_dt_initialise2 (dir->vol, dt); + ntfs_dt_initialise2(dir->vol, dt); } - //utils_dump_mem (dt->data, 0, dt->data_len, DM_DEFAULTS); - //printf ("\n"); + //utils_dump_mem(dt->data, 0, dt->data_len, DM_DEFAULTS); + //ntfs_log_debug("\n"); - ntfs_dt_alloc_count (dt); + ntfs_dt_alloc_count(dt); dt->header = &((INDEX_BLOCK*)dt->data)->index; - //printf ("USA = %d\n", ((INDEX_BLOCK*)dt->data)->usa_count); + //ntfs_log_debug("USA = %d\n", ((INDEX_BLOCK*)dt->data)->usa_count); #if 0 for (i = 0; i < dt->child_count; i++) { INDEX_ENTRY *ie = dt->children[i]; - printf ("%d\n", ((u8*)ie) - dt->data); + ntfs_log_debug("%d\n", ((u8*)ie) - dt->data); if (ie->flags & INDEX_ENTRY_END) - printf ("IE (%d)\n", ie->length); + ntfs_log_debug("IE (%d)\n", ie->length); else - printf ("IE %lld (%d)\n", MREF (ie->key.file_name.parent_directory), ie->length); - utils_dump_mem (ie, 0, ie->length, DM_DEFAULTS); - printf ("\n"); + ntfs_log_debug("IE %lld (%d)\n", MREF(ie->key.file_name.parent_directory), ie->length); + utils_dump_mem(ie, 0, ie->length, DM_DEFAULTS); + ntfs_log_debug("\n"); } #endif } else { - //printf ("root a = %lld\n", dir->iroot->allocated_size); - //printf ("root d = %lld\n", dir->iroot->data_size); - //printf ("root i = %lld\n", dir->iroot->initialized_size); + //ntfs_log_debug("root a = %lld\n", dir->iroot->allocated_size); + //ntfs_log_debug("root d = %lld\n", dir->iroot->data_size); + //ntfs_log_debug("root i = %lld\n", dir->iroot->initialized_size); dt->data_len = dir->iroot->allocated_size; - dt->data = malloc (dt->data_len); - //printf ("%lld\n", ntfs_attr_pread (dir->iroot, 0, dt->data_len, dt->data)); - ntfs_attr_pread (dir->iroot, 0, dt->data_len, dt->data); - //utils_dump_mem (dt->data, 0, dt->data_len, DM_DEFAULTS); - //printf ("\n"); + dt->data = malloc(dt->data_len); + //ntfs_log_debug("%lld\n", ntfs_attr_pread(dir->iroot, 0, dt->data_len, dt->data)); + ntfs_attr_pread(dir->iroot, 0, dt->data_len, dt->data); + //utils_dump_mem(dt->data, 0, dt->data_len, DM_DEFAULTS); + //ntfs_log_debug("\n"); - ntfs_dt_root_count (dt); + ntfs_dt_root_count(dt); dt->header = &((INDEX_ROOT*)dt->data)->index; //dt->data_len = ((INDEX_ROOT*)dt->data)->index_block_size; - //printf ("IBS = %d\n", ((INDEX_ROOT*)dt->data)->index_block_size); + //ntfs_log_debug("IBS = %d\n", ((INDEX_ROOT*)dt->data)->index_block_size); #if 0 for (i = 0; i < dt->child_count; i++) { INDEX_ENTRY *ie = dt->children[i]; - printf ("%d\n", ((u8*)ie) - dt->data); + ntfs_log_debug("%d\n", ((u8*)ie) - dt->data); if (ie->flags & INDEX_ENTRY_END) - printf ("IE (%d)\n", ie->length); + ntfs_log_debug("IE (%d)\n", ie->length); else - printf ("IE %lld (%d)\n", MREF (ie->key.file_name.parent_directory), ie->length); - utils_dump_mem (ie, 0, ie->length, DM_DEFAULTS); - printf ("\n"); + ntfs_log_debug("IE %lld (%d)\n", MREF(ie->key.file_name.parent_directory), ie->length); + utils_dump_mem(ie, 0, ie->length, DM_DEFAULTS); + ntfs_log_debug("\n"); } #endif } - //printf ("index_header (%d,%d)\n", dt->header.index_length, dt->header.allocated_size); + //ntfs_log_debug("index_header (%d,%d)\n", dt->header.index_length, dt->header.allocated_size); return dt; } @@ -493,7 +495,7 @@ struct ntfs_dt * ntfs_dt_create (struct ntfs_dir *dir, struct ntfs_dt *parent, V * find dt by name, return MFT_REF * maps dt's as necessary */ -MFT_REF ntfs_dt_find (struct ntfs_dt *dt, ntfschar *name, int name_len) +MFT_REF ntfs_dt_find(struct ntfs_dt *dt, ntfschar *name, int name_len) { MFT_REF res = -1; INDEX_ENTRY *ie; @@ -516,15 +518,15 @@ MFT_REF ntfs_dt_find (struct ntfs_dt *dt, ntfschar *name, int name_len) * end marker yes map & recurse */ - //printf ("child_count = %d\n", dt->child_count); + //ntfs_log_debug("child_count = %d\n", dt->child_count); for (i = 0; i < dt->child_count; i++) { ie = dt->children[i]; if (ie->flags & INDEX_ENTRY_END) { r = -1; } else { - //printf ("\t"); ntfs_name_print (ie->key.file_name.file_name, ie->key.file_name.file_name_length); printf ("\n"); - r = ntfs_names_collate (name, name_len, + //ntfs_log_debug("\t"); ntfs_name_print(ie->key.file_name.file_name, ie->key.file_name.file_name_length); ntfs_log_debug("\n"); + r = ntfs_names_collate(name, name_len, ie->key.file_name.file_name, ie->key.file_name.file_name_length, 2, IGNORE_CASE, @@ -532,30 +534,30 @@ MFT_REF ntfs_dt_find (struct ntfs_dt *dt, ntfschar *name, int name_len) dt->dir->vol->upcase_len); } - //printf ("%d, %d\n", i, r); + //ntfs_log_debug("%d, %d\n", i, r); if (r == 1) { - //printf ("keep searching\n"); + //ntfs_log_debug("keep searching\n"); continue; } else if (r == 0) { - res = MREF (ie->indexed_file); - //printf ("match %lld\n", res); + res = MREF(ie->indexed_file); + //ntfs_log_debug("match %lld\n", res); } else if (r == -1) { if (ie->flags & INDEX_ENTRY_NODE) { - //printf ("map & recurse\n"); - //printf ("sub %p\n", dt->sub_nodes); + //ntfs_log_debug("map & recurse\n"); + //ntfs_log_debug("sub %p\n", dt->sub_nodes); if (!dt->sub_nodes[i]) { - vcn = ntfs_ie_get_vcn (ie); - //printf ("vcn = %lld\n", vcn); - sub = ntfs_dt_create (dt->dir, dt, vcn); + vcn = ntfs_ie_get_vcn(ie); + //ntfs_log_debug("vcn = %lld\n", vcn); + sub = ntfs_dt_create(dt->dir, dt, vcn); dt->sub_nodes[i] = sub; } - res = ntfs_dt_find (dt->sub_nodes[i], name, name_len); + res = ntfs_dt_find(dt->sub_nodes[i], name, name_len); } else { - //printf ("ENOENT\n"); + //ntfs_log_debug("ENOENT\n"); } } else { - printf ("error collating name\n"); + ntfs_log_debug("error collating name\n"); } break; } @@ -568,7 +570,7 @@ MFT_REF ntfs_dt_find (struct ntfs_dt *dt, ntfschar *name, int name_len) * find dt by name, returns dt and index * maps dt's as necessary */ -struct ntfs_dt * ntfs_dt_find2 (struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num) +struct ntfs_dt * ntfs_dt_find2(struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num) { struct ntfs_dt *res = NULL; INDEX_ENTRY *ie; @@ -592,15 +594,15 @@ struct ntfs_dt * ntfs_dt_find2 (struct ntfs_dt *dt, ntfschar *name, int name_len * end marker yes map & recurse */ - //printf ("child_count = %d\n", dt->child_count); + //ntfs_log_debug("child_count = %d\n", dt->child_count); for (i = 0; i < dt->child_count; i++) { ie = dt->children[i]; if (ie->flags & INDEX_ENTRY_END) { r = -1; } else { - //printf ("\t"); ntfs_name_print (ie->key.file_name.file_name, ie->key.file_name.file_name_length); printf ("\n"); - r = ntfs_names_collate (name, name_len, + //ntfs_log_debug("\t"); ntfs_name_print(ie->key.file_name.file_name, ie->key.file_name.file_name_length); ntfs_log_debug("\n"); + r = ntfs_names_collate(name, name_len, ie->key.file_name.file_name, ie->key.file_name.file_name_length, 2, IGNORE_CASE, @@ -608,26 +610,26 @@ struct ntfs_dt * ntfs_dt_find2 (struct ntfs_dt *dt, ntfschar *name, int name_len dt->dir->vol->upcase_len); } - //printf ("%d, %d\n", i, r); + //ntfs_log_debug("%d, %d\n", i, r); if (r == 1) { - //printf ("keep searching\n"); + //ntfs_log_debug("keep searching\n"); continue; } else if (r == 0) { res = dt; - //printf ("match %p\n", res); + //ntfs_log_debug("match %p\n", res); if (index_num) *index_num = i; } else if ((r == -1) && (ie->flags & INDEX_ENTRY_NODE)) { - //printf ("recurse\n"); + //ntfs_log_debug("recurse\n"); if (!dt->sub_nodes[i]) { - vcn = ntfs_ie_get_vcn (ie); - //printf ("vcn = %lld\n", vcn); - dt->sub_nodes[i] = ntfs_dt_create (dt->dir, dt, vcn); + vcn = ntfs_ie_get_vcn(ie); + //ntfs_log_debug("vcn = %lld\n", vcn); + dt->sub_nodes[i] = ntfs_dt_create(dt->dir, dt, vcn); } - res = ntfs_dt_find2 (dt->sub_nodes[i], name, name_len, index_num); + res = ntfs_dt_find2(dt->sub_nodes[i], name, name_len, index_num); } else { - printf ("error collating name\n"); + ntfs_log_debug("error collating name\n"); } break; } @@ -640,7 +642,7 @@ struct ntfs_dt * ntfs_dt_find2 (struct ntfs_dt *dt, ntfschar *name, int name_len * find dt by name, returns dt and index * does not map new dt's */ -struct ntfs_dt * ntfs_dt_find3 (struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num) +struct ntfs_dt * ntfs_dt_find3(struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num) { struct ntfs_dt *res = NULL; INDEX_ENTRY *ie; @@ -650,15 +652,15 @@ struct ntfs_dt * ntfs_dt_find3 (struct ntfs_dt *dt, ntfschar *name, int name_len if (!dt || !name) return NULL; - //printf ("child_count = %d\n", dt->child_count); + //ntfs_log_debug("child_count = %d\n", dt->child_count); for (i = 0; i < dt->child_count; i++) { ie = dt->children[i]; if (ie->flags & INDEX_ENTRY_END) { r = -1; } else { - //printf ("\t"); ntfs_name_print (ie->key.file_name.file_name, ie->key.file_name.file_name_length); printf ("\n"); - r = ntfs_names_collate (name, name_len, + //ntfs_log_debug("\t"); ntfs_name_print(ie->key.file_name.file_name, ie->key.file_name.file_name_length); ntfs_log_debug("\n"); + r = ntfs_names_collate(name, name_len, ie->key.file_name.file_name, ie->key.file_name.file_name_length, 2, IGNORE_CASE, @@ -666,28 +668,28 @@ struct ntfs_dt * ntfs_dt_find3 (struct ntfs_dt *dt, ntfschar *name, int name_len dt->dir->vol->upcase_len); } - //printf ("%d, %d\n", i, r); + //ntfs_log_debug("%d, %d\n", i, r); if (r == 1) { - //printf ("keep searching\n"); + //ntfs_log_debug("keep searching\n"); continue; } else if (r == 0) { res = dt; - //printf ("match %p\n", res); + //ntfs_log_debug("match %p\n", res); if (index_num) *index_num = i; } else if (r == -1) { if (ie->flags & INDEX_ENTRY_NODE) { - //printf ("recurse\n"); - res = ntfs_dt_find3 (dt->sub_nodes[i], name, name_len, index_num); + //ntfs_log_debug("recurse\n"); + res = ntfs_dt_find3(dt->sub_nodes[i], name, name_len, index_num); } else { - //printf ("no match\n"); + //ntfs_log_debug("no match\n"); res = dt; if (index_num) *index_num = i; } } else { - printf ("error collating name\n"); + ntfs_log_debug("error collating name\n"); } break; } @@ -700,7 +702,7 @@ struct ntfs_dt * ntfs_dt_find3 (struct ntfs_dt *dt, ntfschar *name, int name_len * find successor to specified name, returns dt and index * maps dt's as necessary */ -struct ntfs_dt * ntfs_dt_find4 (struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num) +struct ntfs_dt * ntfs_dt_find4(struct ntfs_dt *dt, ntfschar *name, int name_len, int *index_num) { struct ntfs_dt *res = NULL; struct ntfs_dt *sub = NULL; @@ -712,16 +714,16 @@ struct ntfs_dt * ntfs_dt_find4 (struct ntfs_dt *dt, ntfschar *name, int name_len if (!dt || !name) return NULL; - //printf ("child_count = %d\n", dt->child_count); + //ntfs_log_debug("child_count = %d\n", dt->child_count); for (i = 0; i < dt->child_count; i++) { ie = dt->children[i]; - //printf ("ie->flags = %d\n", ie->flags); + //ntfs_log_debug("ie->flags = %d\n", ie->flags); if (ie->flags & INDEX_ENTRY_END) { r = -1; } else { - //printf ("\t"); ntfs_name_print (ie->key.file_name.file_name, ie->key.file_name.file_name_length); printf ("\n"); - r = ntfs_names_collate (name, name_len, + //ntfs_log_debug("\t"); ntfs_name_print(ie->key.file_name.file_name, ie->key.file_name.file_name_length); ntfs_log_debug("\n"); + r = ntfs_names_collate(name, name_len, ie->key.file_name.file_name, ie->key.file_name.file_name_length, 2, IGNORE_CASE, @@ -729,33 +731,33 @@ struct ntfs_dt * ntfs_dt_find4 (struct ntfs_dt *dt, ntfschar *name, int name_len dt->dir->vol->upcase_len); } - //printf ("%d, %d\n", i, r); + //ntfs_log_debug("%d, %d\n", i, r); if (r == 1) { - //printf ("keep searching\n"); + //ntfs_log_debug("keep searching\n"); } else if (r == 0) { //res = dt; - //printf ("match\n"); + //ntfs_log_debug("match\n"); // ignore } else if (r == -1) { if (ie->flags & INDEX_ENTRY_NODE) { - //printf ("recurse\n"); + //ntfs_log_debug("recurse\n"); if (!dt->sub_nodes[i]) { - vcn = ntfs_ie_get_vcn (ie); - //printf ("vcn = %lld\n", vcn); - sub = ntfs_dt_create (dt->dir, dt, vcn); + vcn = ntfs_ie_get_vcn(ie); + //ntfs_log_debug("vcn = %lld\n", vcn); + sub = ntfs_dt_create(dt->dir, dt, vcn); dt->sub_nodes[i] = sub; } - res = ntfs_dt_find4 (dt->sub_nodes[i], name, name_len, index_num); + res = ntfs_dt_find4(dt->sub_nodes[i], name, name_len, index_num); } else { - //printf ("no match\n"); + //ntfs_log_debug("no match\n"); res = dt; if (index_num) *index_num = i; } break; } else { - printf ("error collating name\n"); + ntfs_log_debug("error collating name\n"); } //break; } @@ -767,7 +769,7 @@ struct ntfs_dt * ntfs_dt_find4 (struct ntfs_dt *dt, ntfschar *name, int name_len * ntfs_dt_find_all * maps all dt's into memory */ -void ntfs_dt_find_all (struct ntfs_dt *dt) +void ntfs_dt_find_all(struct ntfs_dt *dt) { INDEX_ENTRY *ie; VCN vcn; @@ -781,10 +783,10 @@ void ntfs_dt_find_all (struct ntfs_dt *dt) if (ie->flags & INDEX_ENTRY_NODE) { if (!dt->sub_nodes[i]) { - vcn = ntfs_ie_get_vcn (ie); - dt->sub_nodes[i] = ntfs_dt_create (dt->dir, dt, vcn); + vcn = ntfs_ie_get_vcn(ie); + dt->sub_nodes[i] = ntfs_dt_create(dt->dir, dt, vcn); } - ntfs_dt_find_all (dt->sub_nodes[i]); + ntfs_dt_find_all(dt->sub_nodes[i]); } } } @@ -792,7 +794,7 @@ void ntfs_dt_find_all (struct ntfs_dt *dt) /** * ntfs_dt_find_parent */ -int ntfs_dt_find_parent (struct ntfs_dt *dt) +int ntfs_dt_find_parent(struct ntfs_dt *dt) { int i; struct ntfs_dt *parent; @@ -814,7 +816,7 @@ int ntfs_dt_find_parent (struct ntfs_dt *dt) /** * ntfs_dt_isroot */ -BOOL ntfs_dt_isroot (struct ntfs_dt *dt) +BOOL ntfs_dt_isroot(struct ntfs_dt *dt) { if (!dt) return FALSE; @@ -824,7 +826,7 @@ BOOL ntfs_dt_isroot (struct ntfs_dt *dt) /** * ntfs_dt_root_freespace */ -int ntfs_dt_root_freespace (struct ntfs_dt *dt) +int ntfs_dt_root_freespace(struct ntfs_dt *dt) { int recsize; int inuse; @@ -844,7 +846,7 @@ int ntfs_dt_root_freespace (struct ntfs_dt *dt) /** * ntfs_dt_alloc_freespace */ -int ntfs_dt_alloc_freespace (struct ntfs_dt *dt) +int ntfs_dt_alloc_freespace(struct ntfs_dt *dt) { int recsize; int inuse; @@ -864,7 +866,7 @@ int ntfs_dt_alloc_freespace (struct ntfs_dt *dt) /** * ntfs_dt_transfer */ -int ntfs_dt_transfer (struct ntfs_dt *old, struct ntfs_dt *new, int start, int count) +int ntfs_dt_transfer(struct ntfs_dt *old, struct ntfs_dt *new, int start, int count) { int i; int need; @@ -884,26 +886,26 @@ int ntfs_dt_transfer (struct ntfs_dt *old, struct ntfs_dt *new, int start, int c if ((start < 0) || ((start+count) >= old->child_count)) return -1; - printf ("\n"); - printf (BOLD YELLOW "Transferring children\n" END); + ntfs_log_debug("\n"); + ntfs_log_debug(BOLD YELLOW "Transferring children\n" END); need = 0; for (i = start; i < (start+count+1); i++) { mov_ie = old->children[i]; need += mov_ie->length; - //file = &mov_ie->key.file_name; printf ("\ttrn name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n"); + //file = &mov_ie->key.file_name; ntfs_log_debug("\ttrn name: "); ntfs_name_print(file->file_name, file->file_name_length); ntfs_log_debug("\n"); } - if (ntfs_dt_isroot (new)) - space = ntfs_dt_root_freespace (new); + if (ntfs_dt_isroot(new)) + space = ntfs_dt_root_freespace(new); else - space = ntfs_dt_alloc_freespace (new); + space = ntfs_dt_alloc_freespace(new); // XXX if this is an index root, it'll go badly wrong // restrict to allocs only? - printf ("\tneed = %d\n", need); - printf ("\tspace = %d\n", space); + ntfs_log_debug("\tneed = %d\n", need); + ntfs_log_debug("\tspace = %d\n", space); if (space < need) return -1; @@ -920,7 +922,7 @@ int ntfs_dt_transfer (struct ntfs_dt *old, struct ntfs_dt *new, int start, int c n2 = old->children[start]->key.file_name.file_name; l2 = old->children[start]->key.file_name.file_name_length; - i = ntfs_names_collate (n1, l1, n2, l2, + i = ntfs_names_collate(n1, l1, n2, l2, 2, IGNORE_CASE, old->dir->vol->upcase, old->dir->vol->upcase_len); @@ -939,44 +941,44 @@ int ntfs_dt_transfer (struct ntfs_dt *old, struct ntfs_dt *new, int start, int c dst = src + need; len = (u8*) new->children[new->child_count-1] + new->children[new->child_count-1]->length - src; - //printf ("src = %d, dst = %d, len = %d\n", src - new->data, dst - new->data, len); - memmove (dst, src, len); + //ntfs_log_debug("src = %d, dst = %d, len = %d\n", src - new->data, dst - new->data, len); + memmove(dst, src, len); dst = src; src = (u8*) old->children[start]; len = need; - memcpy (dst, src, len); + memcpy(dst, src, len); src = (u8*) old->children[start+count-1]; dst = (u8*) old->children[start]; len = (u8*) old->children[old->child_count-1] + old->children[old->child_count-1]->length - src; - //printf ("src = %d, dst = %d, len = %d\n", src - old->data, dst - old->data, len); - memmove (dst, src, len); + //ntfs_log_debug("src = %d, dst = %d, len = %d\n", src - old->data, dst - old->data, len); + memmove(dst, src, len); dst += len; len = old->data + old->dir->index_size - dst; - //printf ("dst = %d, len = %d\n", dst - old->data, len); - memset (dst, 0, len); + //ntfs_log_debug("dst = %d, len = %d\n", dst - old->data, len); + memset(dst, 0, len); - if (!ntfs_dt_resize_children3 (new, new->child_count + count)) + if (!ntfs_dt_resize_children3(new, new->child_count + count)) return -1; src = (u8*) &old->sub_nodes[start+count-1]; dst = (u8*) &old->sub_nodes[start]; - len = (old->child_count - start - count + 1) * sizeof (struct ntfs_dt*); + len = (old->child_count - start - count + 1) * sizeof(struct ntfs_dt*); - memmove (dst, src, len); + memmove(dst, src, len); src = (u8*) &new->sub_nodes[insert]; dst = (u8*) &new->sub_nodes[insert+count-1]; - len = (new->child_count - insert - count + 1) * sizeof (struct ntfs_dt*); + len = (new->child_count - insert - count + 1) * sizeof(struct ntfs_dt*); - memmove (dst, src, len); + memmove(dst, src, len); - if (!ntfs_dt_resize_children3 (old, old->child_count - count)) + if (!ntfs_dt_resize_children3(old, old->child_count - count)) return -1; src = (u8*) new->children[0]; @@ -1004,8 +1006,8 @@ int ntfs_dt_transfer (struct ntfs_dt *old, struct ntfs_dt *new, int start, int c old->changed = TRUE; new->changed = TRUE; - printf (GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, old->dir->inode->mft_no, old->vcn, old->vcn + (old->dir->index_size>>9) - 1); - printf (GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, new->dir->inode->mft_no, new->vcn, new->vcn + (new->dir->index_size>>9) - 1); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, old->dir->inode->mft_no, old->vcn, old->vcn + (old->dir->index_size>>9) - 1); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, new->dir->inode->mft_no, new->vcn, new->vcn + (new->dir->index_size>>9) - 1); return 0; } @@ -1013,7 +1015,7 @@ int ntfs_dt_transfer (struct ntfs_dt *old, struct ntfs_dt *new, int start, int c /** * ntfs_dt_alloc_insert */ -int ntfs_dt_alloc_insert (struct ntfs_dt *dt, INDEX_ENTRY *first, int count) +int ntfs_dt_alloc_insert(struct ntfs_dt *dt, INDEX_ENTRY *first, int count) { // XXX don't bother measuring, just subtract the children pointers @@ -1037,46 +1039,46 @@ int ntfs_dt_alloc_insert (struct ntfs_dt *dt, INDEX_ENTRY *first, int count) ie = (INDEX_ENTRY*) ((u8*)ie + ie->length); } - printf ("alloc insert %d bytes\n", need); + ntfs_log_debug("alloc insert %d bytes\n", need); alloc = (INDEX_ALLOCATION*) dt->data; - printf ("entries_offset = %d\n", alloc->index.entries_offset); - printf ("index_length = %d\n", alloc->index.index_length); - printf ("allocated_size = %d\n", alloc->index.allocated_size); + ntfs_log_debug("entries_offset = %d\n", alloc->index.entries_offset); + ntfs_log_debug("index_length = %d\n", alloc->index.index_length); + ntfs_log_debug("allocated_size = %d\n", alloc->index.allocated_size); - printf ("insert has %d children\n", dt->child_count); - printf ("children = %p\n", dt->children); - //utils_dump_mem (dt->data, 0, 128, DM_DEFAULTS); + ntfs_log_debug("insert has %d children\n", dt->child_count); + ntfs_log_debug("children = %p\n", dt->children); + //utils_dump_mem(dt->data, 0, 128, DM_DEFAULTS); ie = dt->children[dt->child_count-1]; - printf ("last child = %p (%ld)\n", ie, (long)ie - (long)dt->data); - printf ("size = %d\n", ie->length); + ntfs_log_debug("last child = %p (%ld)\n", ie, (long)ie - (long)dt->data); + ntfs_log_debug("size = %d\n", ie->length); src = (u8*) ie; dst = src + need; len = ie->length; - memmove (dst, src, len); + memmove(dst, src, len); src = (u8*) first; dst = (u8*) ie; len = need; - memcpy (dst, src, len); + memcpy(dst, src, len); // use create children // measure need and update children list // adjust headers - //utils_dump_mem (dt->data, 0, 256, DM_DEFAULTS); + //utils_dump_mem(dt->data, 0, 256, DM_DEFAULTS); return 0; } /** * ntfs_dt_alloc_insert2 */ -INDEX_ENTRY * ntfs_dt_alloc_insert2 (struct ntfs_dt *dt, int before, int count, int bytes) +INDEX_ENTRY * ntfs_dt_alloc_insert2(struct ntfs_dt *dt, int before, int count, int bytes) { int space; u8 *src; @@ -1095,7 +1097,7 @@ INDEX_ENTRY * ntfs_dt_alloc_insert2 (struct ntfs_dt *dt, int before, int count, return NULL; // check alloc has enough space - space = ntfs_dt_alloc_freespace (dt); + space = ntfs_dt_alloc_freespace(dt); if (bytes > space) return NULL; @@ -1104,37 +1106,37 @@ INDEX_ENTRY * ntfs_dt_alloc_insert2 (struct ntfs_dt *dt, int before, int count, dst = src + bytes; len = dt->header->index_length - ((int)dt->children[before] - (int)dt->data) + 24; - //printf ("%d, %d, %d\n", (int)src - (int)dt->data, (int)dst - (int)dt->data, len); + //ntfs_log_debug("%d, %d, %d\n", (int)src - (int)dt->data, (int)dst - (int)dt->data, len); - memmove (dst, src, len); - memset (dst, 0, bytes); + memmove(dst, src, len); + memset(dst, 0, bytes); // resize arrays - ntfs_dt_resize_children3 (dt, dt->child_count + count); + ntfs_dt_resize_children3(dt, dt->child_count + count); // move keys (children) src = (u8*) (dt->children + before); - dst = src + (count * sizeof (u8*)); - len = (dt->child_count - count - before) * sizeof (u8*); + dst = src + (count * sizeof(u8*)); + len = (dt->child_count - count - before) * sizeof(u8*); - memmove (dst, src, len); - memset (src, 0, count * sizeof (u8*)); + memmove(dst, src, len); + memset(src, 0, count * sizeof(u8*)); // move keys (inodes) src = (u8*) (dt->inodes + before); - dst = src + (count * sizeof (u8*)); - len = (dt->child_count - count - before) * sizeof (u8*); + dst = src + (count * sizeof(u8*)); + len = (dt->child_count - count - before) * sizeof(u8*); - memmove (dst, src, len); - memset (src, 0, count * sizeof (u8*)); + memmove(dst, src, len); + memset(src, 0, count * sizeof(u8*)); // move keys (sub_nodes) src = (u8*) (dt->sub_nodes + before); - dst = src + (count * sizeof (u8*)); - len = (dt->child_count - count - before) * sizeof (u8*); + dst = src + (count * sizeof(u8*)); + len = (dt->child_count - count - before) * sizeof(u8*); - memmove (dst, src, len); - memset (src, 0, count * sizeof (u8*)); + memmove(dst, src, len); + memset(src, 0, count * sizeof(u8*)); return NULL; } @@ -1142,7 +1144,7 @@ INDEX_ENTRY * ntfs_dt_alloc_insert2 (struct ntfs_dt *dt, int before, int count, /** * ntfs_dt_root_insert */ -int ntfs_dt_root_insert (struct ntfs_dt *dt, INDEX_ENTRY *first, int count) +int ntfs_dt_root_insert(struct ntfs_dt *dt, INDEX_ENTRY *first, int count) { if (!dt) return 1; @@ -1155,7 +1157,7 @@ int ntfs_dt_root_insert (struct ntfs_dt *dt, INDEX_ENTRY *first, int count) /** * ntfs_dt_alloc_remove2 */ -int ntfs_dt_alloc_remove2 (struct ntfs_dt *dt, int start, int count) +int ntfs_dt_alloc_remove2(struct ntfs_dt *dt, int start, int count) { int i; int size; @@ -1174,7 +1176,7 @@ int ntfs_dt_alloc_remove2 (struct ntfs_dt *dt, int start, int count) /** * ntfs_dt_root_remove2 */ -int ntfs_dt_root_remove2 (struct ntfs_dt *dt, int start, int count) +int ntfs_dt_root_remove2(struct ntfs_dt *dt, int start, int count) { int i; int size; @@ -1186,18 +1188,18 @@ int ntfs_dt_root_remove2 (struct ntfs_dt *dt, int start, int count) if ((count < 1) || ((start + count - 1) >= dt->child_count)) return -1; - printf ("s c/t %d %d/%d\n", start, count, dt->child_count); + ntfs_log_debug("s c/t %d %d/%d\n", start, count, dt->child_count); size = 0; for (i = start; i < (start + count); i++) size += dt->children[i]->length; - printf ("size1 = %d\n", size); + ntfs_log_debug("size1 = %d\n", size); size = (int) dt->children[start+count] - (int) dt->children[start]; - printf ("size2 = %d\n", size); + ntfs_log_debug("size2 = %d\n", size); size = (int) dt->children[start+count-1] - (int) dt->children[start] + dt->children[start+count-1]->length; - printf ("size3 = %d\n", size); + ntfs_log_debug("size3 = %d\n", size); // XXX what shall we do with the inodes? // transfer them to the dir (commit them for now) @@ -1206,16 +1208,16 @@ int ntfs_dt_root_remove2 (struct ntfs_dt *dt, int start, int count) // rearrange arrays // shrink attribute - ntfs_dt_resize_children3 (dt, dt->child_count - count); + ntfs_dt_resize_children3(dt, dt->child_count - count); - printf ("ntfs_dt_root_remove2\n"); + ntfs_log_debug("ntfs_dt_root_remove2\n"); return dt->child_count; } /** * ntfs_dt_transfer2 */ -int ntfs_dt_transfer2 (struct ntfs_dt *old, struct ntfs_dt *new, int start, int count) +int ntfs_dt_transfer2(struct ntfs_dt *old, struct ntfs_dt *new, int start, int count) { int i; int need; @@ -1236,39 +1238,39 @@ int ntfs_dt_transfer2 (struct ntfs_dt *old, struct ntfs_dt *new, int start, int if ((start + count) >= old->child_count) return -1; - printf ("\n"); - printf (BOLD YELLOW "Transferring children\n" END); + ntfs_log_debug("\n"); + ntfs_log_debug(BOLD YELLOW "Transferring children\n" END); need = 0; for (i = start; i < (start+count); i++) { mov_ie = old->children[i]; need += mov_ie->length; - //file = &mov_ie->key.file_name; printf ("\ttrn name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n"); + //file = &mov_ie->key.file_name; ntfs_log_debug("\ttrn name: "); ntfs_name_print(file->file_name, file->file_name_length); ntfs_log_debug("\n"); } - if (ntfs_dt_isroot (new)) - space = ntfs_dt_root_freespace (new); + if (ntfs_dt_isroot(new)) + space = ntfs_dt_root_freespace(new); else - space = ntfs_dt_alloc_freespace (new); + space = ntfs_dt_alloc_freespace(new); - printf ("\tneed = %d\n", need); - printf ("\tspace = %d\n", space); + ntfs_log_debug("\tneed = %d\n", need); + ntfs_log_debug("\tspace = %d\n", space); if (need > space) return -1; - if (ntfs_dt_isroot (new)) - ntfs_dt_root_insert (new, old->children[0], count); + if (ntfs_dt_isroot(new)) + ntfs_dt_root_insert(new, old->children[0], count); else - ntfs_dt_alloc_insert2 (new, 0, count, need); + ntfs_dt_alloc_insert2(new, 0, count, need); - if (ntfs_dt_isroot (old)) - ntfs_dt_root_remove2 (old, 0, count); + if (ntfs_dt_isroot(old)) + ntfs_dt_root_remove2(old, 0, count); else - ntfs_dt_alloc_remove2 (old, 0, count); + ntfs_dt_alloc_remove2(old, 0, count); if (1) return -1; - if (0) ntfs_dt_alloc_insert (NULL, NULL, 0); + if (0) ntfs_dt_alloc_insert(NULL, NULL, 0); if (new->child_count == 1) { i = -1; @@ -1282,7 +1284,7 @@ int ntfs_dt_transfer2 (struct ntfs_dt *old, struct ntfs_dt *new, int start, int n2 = old->children[start]->key.file_name.file_name; l2 = old->children[start]->key.file_name.file_name_length; - i = ntfs_names_collate (n1, l1, n2, l2, + i = ntfs_names_collate(n1, l1, n2, l2, 2, IGNORE_CASE, old->dir->vol->upcase, old->dir->vol->upcase_len); @@ -1301,44 +1303,44 @@ int ntfs_dt_transfer2 (struct ntfs_dt *old, struct ntfs_dt *new, int start, int dst = src + need; len = (u8*) new->children[new->child_count-1] + new->children[new->child_count-1]->length - src; - //printf ("src = %d, dst = %d, len = %d\n", src - new->data, dst - new->data, len); - memmove (dst, src, len); + //ntfs_log_debug("src = %d, dst = %d, len = %d\n", src - new->data, dst - new->data, len); + memmove(dst, src, len); dst = src; src = (u8*) old->children[start]; len = need; - memcpy (dst, src, len); + memcpy(dst, src, len); src = (u8*) old->children[start+count-1]; dst = (u8*) old->children[start]; len = (u8*) old->children[old->child_count-1] + old->children[old->child_count-1]->length - src; - //printf ("src = %d, dst = %d, len = %d\n", src - old->data, dst - old->data, len); - memmove (dst, src, len); + //ntfs_log_debug("src = %d, dst = %d, len = %d\n", src - old->data, dst - old->data, len); + memmove(dst, src, len); dst += len; len = old->data + old->dir->index_size - dst; - //printf ("dst = %d, len = %d\n", dst - old->data, len); - memset (dst, 0, len); + //ntfs_log_debug("dst = %d, len = %d\n", dst - old->data, len); + memset(dst, 0, len); - if (!ntfs_dt_resize_children3 (new, new->child_count + count)) + if (!ntfs_dt_resize_children3(new, new->child_count + count)) return -1; src = (u8*) &old->sub_nodes[start+count-1]; dst = (u8*) &old->sub_nodes[start]; - len = (old->child_count - start - count + 1) * sizeof (struct ntfs_dt*); + len = (old->child_count - start - count + 1) * sizeof(struct ntfs_dt*); - memmove (dst, src, len); + memmove(dst, src, len); src = (u8*) &new->sub_nodes[insert]; dst = (u8*) &new->sub_nodes[insert+count-1]; - len = (new->child_count - insert - count + 1) * sizeof (struct ntfs_dt*); + len = (new->child_count - insert - count + 1) * sizeof(struct ntfs_dt*); - memmove (dst, src, len); + memmove(dst, src, len); - if (!ntfs_dt_resize_children3 (old, old->child_count - count)) + if (!ntfs_dt_resize_children3(old, old->child_count - count)) return -1; src = (u8*) new->children[0]; @@ -1366,8 +1368,8 @@ int ntfs_dt_transfer2 (struct ntfs_dt *old, struct ntfs_dt *new, int start, int old->changed = TRUE; new->changed = TRUE; - printf (GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, old->dir->inode->mft_no, old->vcn, old->vcn + (old->dir->index_size>>9) - 1); - printf (GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, new->dir->inode->mft_no, new->vcn, new->vcn + (new->dir->index_size>>9) - 1); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, old->dir->inode->mft_no, old->vcn, old->vcn + (old->dir->index_size>>9) - 1); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, new->dir->inode->mft_no, new->vcn, new->vcn + (new->dir->index_size>>9) - 1); return 0; } @@ -1375,7 +1377,7 @@ int ntfs_dt_transfer2 (struct ntfs_dt *old, struct ntfs_dt *new, int start, int /** * ntfs_dt_root_replace */ -int ntfs_dt_root_replace (struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie) +int ntfs_dt_root_replace(struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie) { u8 *src; u8 *dst; @@ -1386,51 +1388,51 @@ int ntfs_dt_root_replace (struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, if (!del || !del_ie || !suc_ie) return FALSE; - //utils_dump_mem (del->data, 0, del->data_len, DM_DEFAULTS); - //printf ("\n"); + //utils_dump_mem(del->data, 0, del->data_len, DM_DEFAULTS); + //ntfs_log_debug("\n"); - attr = malloc (del->data_len + suc_ie->length - del_ie->length); + attr = malloc(del->data_len + suc_ie->length - del_ie->length); dst = attr; src = del->data; len = (u8*) del_ie - del->data; - memcpy (dst, src, len); + memcpy(dst, src, len); dst += len; src = (u8*) suc_ie; len = suc_ie->length; - memcpy (dst, src, len); + memcpy(dst, src, len); dst += len; src = (u8*) del_ie + del_ie->length; len = del->data_len + (del->data - (u8*) del_ie) - del_ie->length; - memcpy (dst, src, len); + memcpy(dst, src, len); src = (u8*) del->data; dst = attr; len = suc_ie->length - del_ie->length; - free (del->data); + free(del->data); del->data = attr; del->data_len += len; del->header = (INDEX_HEADER*) (del->data + 0x10); del->header->index_length += len; del->header->allocated_size += len; - ntfs_mft_resize_resident (del->dir->inode, AT_INDEX_ROOT, I30, 4, del->data, del->data_len); + ntfs_mft_resize_resident(del->dir->inode, AT_INDEX_ROOT, I30, 4, del->data, del->data_len); - //utils_dump_mem (attr, 0, del->data_len, DM_DEFAULTS); + //utils_dump_mem(attr, 0, del->data_len, DM_DEFAULTS); - //printf ("\n"); - //printf (BOLD YELLOW "Adjust children\n" END); + //ntfs_log_debug("\n"); + //ntfs_log_debug(BOLD YELLOW "Adjust children\n" END); //for (i = 0; i < del->child_count; i++) - // printf ("\tChild %d %p %d\n", i, del->children[i], del->children[i]->flags); - //printf ("\n"); + // ntfs_log_debug("\tChild %d %p %d\n", i, del->children[i], del->children[i]->flags); + //ntfs_log_debug("\n"); - //printf ("src = %p, dst = %p, len = %d\n", src, dst, len); fflush (stdout); + //ntfs_log_debug("src = %p, dst = %p, len = %d\n", src, dst, len); fflush (stdout); for (i = 0; i < del->child_count; i++) del->children[i] = (INDEX_ENTRY*) (dst + ((u8*) del->children[i] - src)); @@ -1439,22 +1441,22 @@ int ntfs_dt_root_replace (struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, del->children[i] = (INDEX_ENTRY*) ((u8*) del->children[i] + len); //for (i = 0; i < del->child_count; i++) - // printf ("\tChild %d %p %d\n", i, del->children[i], del->children[i]->flags); - //printf ("\n"); + // ntfs_log_debug("\tChild %d %p %d\n", i, del->children[i], del->children[i]->flags); + //ntfs_log_debug("\n"); - //utils_dump_mem (del->data, 0, del->data_len, DM_DEFAULTS); - //printf ("\n"); + //utils_dump_mem(del->data, 0, del->data_len, DM_DEFAULTS); + //ntfs_log_debug("\n"); del->changed = TRUE; - printf (GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, del->dir->inode->mft_no); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, del->dir->inode->mft_no); return TRUE; } /** * ntfs_dt_alloc_replace */ -BOOL ntfs_dt_alloc_replace (struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie) +BOOL ntfs_dt_alloc_replace(struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_ie, INDEX_ENTRY *suc_ie) { u8 *src; u8 *dst; @@ -1464,59 +1466,59 @@ BOOL ntfs_dt_alloc_replace (struct ntfs_dt *del, int del_num, INDEX_ENTRY *del_i if (!del || !del_ie || !suc_ie) return FALSE; - //utils_dump_mem (del->data, 0, del->data_len, DM_DEFAULTS); + //utils_dump_mem(del->data, 0, del->data_len, DM_DEFAULTS); src = (u8*) del_ie + del_ie->length; dst = (u8*) del_ie + suc_ie->length; len = del->header->index_length + 24 + (del->data - src); - //printf ("src = %d\n", src - del->data); - //printf ("dst = %d\n", dst - del->data); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - del->data); + //ntfs_log_debug("dst = %d\n", dst - del->data); + //ntfs_log_debug("len = %d\n", len); if (src != dst) - memmove (dst, src, len); + memmove(dst, src, len); src = (u8*) suc_ie; dst = (u8*) del_ie; len = suc_ie->length; - memcpy (dst, src, len); + memcpy(dst, src, len); - //utils_dump_mem (del->data, 0, del->data_len, DM_DEFAULTS); + //utils_dump_mem(del->data, 0, del->data_len, DM_DEFAULTS); del->header->index_length += suc_ie->length - del_ie->length; dst = del->data + del->header->index_length + 24; len = del->data_len - del->header->index_length - 24; - memset (dst, 0, len); + memset(dst, 0, len); //for (i = 0; i < del->child_count; i++) - // printf ("Child %d %p\n", i, del->children[i]); - //printf ("\n"); + // ntfs_log_debug("Child %d %p\n", i, del->children[i]); + //ntfs_log_debug("\n"); len = suc_ie->length - del_ie->length; - //printf ("len = %d\n", len); + //ntfs_log_debug("len = %d\n", len); for (i = del_num+1; i < del->child_count; i++) del->children[i] = (INDEX_ENTRY*) ((u8*) del->children[i] + len); //for (i = 0; i < del->child_count; i++) - // printf ("Child %d %p\n", i, del->children[i]); - //printf ("\n"); + // ntfs_log_debug("Child %d %p\n", i, del->children[i]); + //ntfs_log_debug("\n"); - //utils_dump_mem (del->data, 0, del->data_len, DM_DEFAULTS); + //utils_dump_mem(del->data, 0, del->data_len, DM_DEFAULTS); del->changed = TRUE; - printf (GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, del->dir->inode->mft_no, del->vcn, del->vcn + (del->dir->index_size>>9) - 1); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, del->dir->inode->mft_no, del->vcn, del->vcn + (del->dir->index_size>>9) - 1); return TRUE; } /** * ntfs_dt_root_remove */ -BOOL ntfs_dt_root_remove (struct ntfs_dt *del, int del_num) +BOOL ntfs_dt_root_remove(struct ntfs_dt *del, int del_num) { INDEX_ENTRY *del_ie = NULL; u8 *src; @@ -1530,26 +1532,26 @@ BOOL ntfs_dt_root_remove (struct ntfs_dt *del, int del_num) if (!del) return FALSE; - //utils_dump_mem (del->data, 0, del->header->index_length+16, DM_RED); - //printf ("\n"); + //utils_dump_mem(del->data, 0, del->header->index_length+16, DM_RED); + //ntfs_log_debug("\n"); #if 0 off = (u8*) del->children[0] - del->data; for (i = 0; i < del->child_count; i++) { del_ie = del->children[i]; - printf ("%2d %4d ", i+1, off); + ntfs_log_debug("%2d %4d ", i+1, off); off += del_ie->length; if (del_ie->flags & INDEX_ENTRY_END) { - printf ("END (%d)\n", del_ie->length); + ntfs_log_debug("END (%d)\n", del_ie->length); break; } - ntfs_name_print (del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); - printf (" (%d)\n", del_ie->length); + ntfs_name_print(del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); + ntfs_log_debug(" (%d)\n", del_ie->length); } - printf ("total = %d\n", off); + ntfs_log_debug("total = %d\n", off); #endif del_ie = del->children[del_num]; @@ -1559,11 +1561,11 @@ BOOL ntfs_dt_root_remove (struct ntfs_dt *del, int del_num) dst = (u8*) del_ie; len = del->header->index_length + 16 - (src - del->data); - //printf ("src = %d\n", src - del->data); - //printf ("dst = %d\n", dst - del->data); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - del->data); + //ntfs_log_debug("dst = %d\n", dst - del->data); + //ntfs_log_debug("len = %d\n", len); - memmove (dst, src, len); + memmove(dst, src, len); del->data_len -= del_len; del->child_count--; @@ -1571,40 +1573,40 @@ BOOL ntfs_dt_root_remove (struct ntfs_dt *del, int del_num) del->header->index_length = del->data_len - 16; del->header->allocated_size = del->data_len - 16; - ntfs_mft_resize_resident (del->dir->inode, AT_INDEX_ROOT, I30, 4, del->data, del->data_len); + ntfs_mft_resize_resident(del->dir->inode, AT_INDEX_ROOT, I30, 4, del->data, del->data_len); old = del->data; - del->data = realloc (del->data, del->data_len); + del->data = realloc(del->data, del->data_len); del->header = (INDEX_HEADER*) (del->data + 0x10); - //utils_dump_mem (del->data, 0, del->data_len, DM_GREEN | DM_RED); + //utils_dump_mem(del->data, 0, del->data_len, DM_GREEN | DM_RED); src = (u8*) (&del->children[del_num+1]); dst = (u8*) (&del->children[del_num]); - len = (del->child_count - del_num) * sizeof (INDEX_ENTRY*); + len = (del->child_count - del_num) * sizeof(INDEX_ENTRY*); - //printf ("src = %d\n", src - (u8*) del->children); - //printf ("dst = %d\n", dst - (u8*) del->children); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - (u8*) del->children); + //ntfs_log_debug("dst = %d\n", dst - (u8*) del->children); + //ntfs_log_debug("len = %d\n", len); - memmove (dst, src, len); + memmove(dst, src, len); src = (u8*) (&del->sub_nodes[del_num+1]); dst = (u8*) (&del->sub_nodes[del_num]); - len = (del->child_count - del_num) * sizeof (struct ntfs_dt*); + len = (del->child_count - del_num) * sizeof(struct ntfs_dt*); - //printf ("src = %d\n", src - (u8*) del->children); - //printf ("dst = %d\n", dst - (u8*) del->children); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - (u8*) del->children); + //ntfs_log_debug("dst = %d\n", dst - (u8*) del->children); + //ntfs_log_debug("len = %d\n", len); - memmove (dst, src, len); + memmove(dst, src, len); - //printf ("del_num = %d\n", del_num); + //ntfs_log_debug("del_num = %d\n", del_num); for (i = 0; i < del->child_count; i++) del->children[i] = (INDEX_ENTRY*) ((u8*) del->children[i] - old + del->data); for (i = del_num; i < del->child_count; i++) del->children[i] = (INDEX_ENTRY*) ((u8*) del->children[i] - del_len); - if (!ntfs_dt_create_children2 (del, del->child_count)) + if (!ntfs_dt_create_children2(del, del->child_count)) return FALSE; #if 0 @@ -1612,32 +1614,32 @@ BOOL ntfs_dt_root_remove (struct ntfs_dt *del, int del_num) for (i = 0; i < del->child_count; i++) { del_ie = del->children[i]; - printf ("%2d %4d ", i+1, off); + ntfs_log_debug("%2d %4d ", i+1, off); off += del_len; if (del_ie->flags & INDEX_ENTRY_END) { - printf ("END (%d)\n", del_len); + ntfs_log_debug("END (%d)\n", del_len); break; } - ntfs_name_print (del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); - printf (" (%d)\n", del_len); + ntfs_name_print(del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); + ntfs_log_debug(" (%d)\n", del_len); } - printf ("total = %d\n", off); + ntfs_log_debug("total = %d\n", off); #endif - //utils_dump_mem (del->data, 0, del->header->index_length+16, DM_DEFAULTS); + //utils_dump_mem(del->data, 0, del->header->index_length+16, DM_DEFAULTS); del->changed = TRUE; - printf (GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, del->dir->inode->mft_no); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, del->dir->inode->mft_no); return TRUE; } /** * ntfs_dt_alloc_remove */ -BOOL ntfs_dt_alloc_remove (struct ntfs_dt *del, int del_num) +BOOL ntfs_dt_alloc_remove(struct ntfs_dt *del, int del_num) { INDEX_ENTRY *del_ie = NULL; u8 *dst; @@ -1654,23 +1656,23 @@ BOOL ntfs_dt_alloc_remove (struct ntfs_dt *del, int del_num) for (i = 0; i < del->child_count; i++) { del_ie = del->children[i]; - printf ("%2d %4d ", i, off); + ntfs_log_debug("%2d %4d ", i, off); off += del_ie->length; if (del_ie->flags & INDEX_ENTRY_END) { - printf ("END (%d)\n", del_ie->length); + ntfs_log_debug("END (%d)\n", del_ie->length); break; } - ntfs_name_print (del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); - printf (" (%d)\n", del_ie->length); + ntfs_name_print(del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); + ntfs_log_debug(" (%d)\n", del_ie->length); } - printf ("total = %d\n", off); - printf ("\n"); + ntfs_log_debug("total = %d\n", off); + ntfs_log_debug("\n"); #endif - //utils_dump_mem (del->data, 0, del->data_len, DM_DEFAULTS); - //printf ("\n"); + //utils_dump_mem(del->data, 0, del->data_len, DM_DEFAULTS); + //ntfs_log_debug("\n"); del_ie = del->children[del_num]; @@ -1678,11 +1680,11 @@ BOOL ntfs_dt_alloc_remove (struct ntfs_dt *del, int del_num) dst = (u8*) del_ie; len = del->header->index_length + 24 - (src - del->data); - //printf ("src = %d\n", src - del->data); - //printf ("dst = %d\n", dst - del->data); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - del->data); + //ntfs_log_debug("dst = %d\n", dst - del->data); + //ntfs_log_debug("len = %d\n", len); - memmove (dst, src, len); + memmove(dst, src, len); del->header->index_length -= src - dst; del->child_count--; @@ -1690,67 +1692,67 @@ BOOL ntfs_dt_alloc_remove (struct ntfs_dt *del, int del_num) dst += len; len = del->data_len - del->header->index_length - 24; - //printf ("dst = %d\n", dst - del->data); - //printf ("len = %d\n", len); + //ntfs_log_debug("dst = %d\n", dst - del->data); + //ntfs_log_debug("len = %d\n", len); - memset (dst, 0, len); + memset(dst, 0, len); src = (u8*) (&del->children[del_num+1]); dst = (u8*) (&del->children[del_num]); - len = (del->child_count - del_num) * sizeof (INDEX_ENTRY*); + len = (del->child_count - del_num) * sizeof(INDEX_ENTRY*); - //printf ("src = %d\n", src - (u8*) del->children); - //printf ("dst = %d\n", dst - (u8*) del->children); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - (u8*) del->children); + //ntfs_log_debug("dst = %d\n", dst - (u8*) del->children); + //ntfs_log_debug("len = %d\n", len); - memmove (dst, src, len); + memmove(dst, src, len); src = (u8*) (&del->sub_nodes[del_num+1]); dst = (u8*) (&del->sub_nodes[del_num]); - len = (del->child_count - del_num) * sizeof (struct ntfs_dt*); + len = (del->child_count - del_num) * sizeof(struct ntfs_dt*); - //printf ("src = %d\n", src - (u8*) del->children); - //printf ("dst = %d\n", dst - (u8*) del->children); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - (u8*) del->children); + //ntfs_log_debug("dst = %d\n", dst - (u8*) del->children); + //ntfs_log_debug("len = %d\n", len); - memmove (dst, src, len); + memmove(dst, src, len); - //printf ("del_num = %d\n", del_num); + //ntfs_log_debug("del_num = %d\n", del_num); for (i = del_num; i < del->child_count; i++) del->children[i] = (INDEX_ENTRY*) ((u8*) del->children[i] - del_ie->length); - if (!ntfs_dt_create_children2 (del, del->child_count)) + if (!ntfs_dt_create_children2(del, del->child_count)) return FALSE; - //utils_dump_mem (del->data, 0, del->data_len, DM_DEFAULTS); + //utils_dump_mem(del->data, 0, del->data_len, DM_DEFAULTS); #if 0 off = (u8*)del->children[0] - del->data; for (i = 0; i < del->child_count; i++) { del_ie = del->children[i]; - printf ("%2d %4d ", i, off); + ntfs_log_debug("%2d %4d ", i, off); off += del_ie->length; if (del_ie->flags & INDEX_ENTRY_END) { - printf ("END (%d)\n", del_ie->length); + ntfs_log_debug("END (%d)\n", del_ie->length); break; } - ntfs_name_print (del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); - printf (" (%d)\n", del_ie->length); + ntfs_name_print(del_ie->key.file_name.file_name, del_ie->key.file_name.file_name_length); + ntfs_log_debug(" (%d)\n", del_ie->length); } - printf ("total = %d\n", off); - printf ("\n"); + ntfs_log_debug("total = %d\n", off); + ntfs_log_debug("\n"); #endif del->changed = TRUE; - printf (GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, del->dir->inode->mft_no, del->vcn, del->vcn + (del->dir->index_size>>9) - 1); + ntfs_log_debug(GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, del->dir->inode->mft_no, del->vcn, del->vcn + (del->dir->index_size>>9) - 1); if (del->child_count < 2) { - printf ("indx is empty\n"); - ntfs_bmp_set_range (del->dir->bitmap, del->vcn, 1, 0); + ntfs_log_debug("indx is empty\n"); + ntfs_bmp_set_range(del->dir->bitmap, del->vcn, 1, 0); } return TRUE; @@ -1759,7 +1761,7 @@ BOOL ntfs_dt_alloc_remove (struct ntfs_dt *del, int del_num) /** * ntfs_dt_alloc_add */ -int ntfs_dt_alloc_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child) +int ntfs_dt_alloc_add(struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child) { INDEX_BLOCK *block; INDEX_ENTRY *entry; @@ -1777,39 +1779,39 @@ int ntfs_dt_alloc_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, s need = ie->length; space = parent->data_len - block->index.index_length - 24; - printf ("need %d, have %d\n", need, space); + ntfs_log_debug("need %d, have %d\n", need, space); if (need > space) { - printf ("no room"); + ntfs_log_debug("no room"); return 0; } - //utils_dump_mem (parent->data, 0, parent->data_len, DM_DEFAULTS); - //printf ("\n"); + //utils_dump_mem(parent->data, 0, parent->data_len, DM_DEFAULTS); + //ntfs_log_debug("\n"); src = (u8*) parent->children[index_num]; dst = src + need; len = parent->data + parent->data_len - src - space; - //printf ("src = %d\n", src - parent->data); - //printf ("dst = %d\n", dst - parent->data); - //printf ("len = %d\n", len); + //ntfs_log_debug("src = %d\n", src - parent->data); + //ntfs_log_debug("dst = %d\n", dst - parent->data); + //ntfs_log_debug("len = %d\n", len); - memmove (dst, src, len); + memmove(dst, src, len); dst = src; src = (u8*) ie; len = need; - memcpy (dst, src, len); + memcpy(dst, src, len); block->index.index_length += len; dst = parent->data + block->index.index_length + 24; len = parent->data_len - block->index.index_length - 24; - memset (dst, 0, len); + memset(dst, 0, len); //realloc children, sub_nodes - ntfs_dt_create_children2 (parent, parent->child_count + 1); + ntfs_dt_create_children2(parent, parent->child_count + 1); // regen children pointers parent->child_count = 0; @@ -1828,26 +1830,26 @@ int ntfs_dt_alloc_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, s src += entry->length; } - printf ("count = %d\n", parent->child_count); + ntfs_log_debug("count = %d\n", parent->child_count); src = (u8*) &parent->sub_nodes[index_num+parent->child_count-1]; dst = (u8*) &parent->sub_nodes[index_num]; - len = (parent->child_count - index_num - 1) * sizeof (struct ntfs_dt*); + len = (parent->child_count - index_num - 1) * sizeof(struct ntfs_dt*); - memmove (dst, src, len); + memmove(dst, src, len); //insert sub_node pointer parent->sub_nodes[index_num] = child; - //utils_dump_mem (parent->data, 0, parent->data_len, DM_DEFAULTS); - //printf ("\n"); + //utils_dump_mem(parent->data, 0, parent->data_len, DM_DEFAULTS); + //ntfs_log_debug("\n"); return 0; } /** * ntfs_dt_root_add */ -int ntfs_dt_root_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child) +int ntfs_dt_root_add(struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, struct ntfs_dt *child) { INDEX_ROOT *root; INDEX_ENTRY *entry; @@ -1863,39 +1865,39 @@ int ntfs_dt_root_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, st root = (INDEX_ROOT*) parent->data; - //utils_dump_mem (parent->data, 0, parent->data_len, DM_DEFAULTS); - printf ("\n"); + //utils_dump_mem(parent->data, 0, parent->data_len, DM_DEFAULTS); + ntfs_log_debug("\n"); need = ie->length; - space = ntfs_mft_free_space (parent->dir); + space = ntfs_mft_free_space(parent->dir); - printf ("need %d, have %d\n", need, space); + ntfs_log_debug("need %d, have %d\n", need, space); if (need > space) { - printf ("no room"); + ntfs_log_debug("no room"); return 0; } - attr = malloc (parent->data_len + need); + attr = malloc(parent->data_len + need); src = parent->data; dst = attr; len = root->index.entries_offset + 16; - memcpy (dst, src, len); + memcpy(dst, src, len); dst += len; src = (u8*) ie; len = ie->length; - memcpy (dst, src, len); + memcpy(dst, src, len); dst += len; src = (u8*) parent->children[index_num]; len = parent->data + parent->data_len - src; - memcpy (dst, src, len); + memcpy(dst, src, len); - free (parent->data); + free(parent->data); parent->data = attr; parent->data_len += need; @@ -1903,13 +1905,13 @@ int ntfs_dt_root_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, st root->index.index_length = parent->data_len - 16; root->index.allocated_size = parent->data_len - 16; - //utils_dump_mem (parent->data, 0, parent->data_len, DM_DEFAULTS); - printf ("\n"); + //utils_dump_mem(parent->data, 0, parent->data_len, DM_DEFAULTS); + ntfs_log_debug("\n"); - ntfs_mft_resize_resident (parent->dir->inode, AT_INDEX_ROOT, I30, 4, parent->data, parent->data_len); + ntfs_mft_resize_resident(parent->dir->inode, AT_INDEX_ROOT, I30, 4, parent->data, parent->data_len); //realloc children, sub_nodes - ntfs_dt_create_children2 (parent, parent->child_count + 1); + ntfs_dt_create_children2(parent, parent->child_count + 1); // regen children pointers parent->child_count = 0; @@ -1929,13 +1931,13 @@ int ntfs_dt_root_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, st src += entry->length; } - printf ("count = %d\n", parent->child_count); + ntfs_log_debug("count = %d\n", parent->child_count); src = (u8*) &parent->sub_nodes[index_num+parent->child_count-1]; dst = (u8*) &parent->sub_nodes[index_num]; - len = (parent->child_count - index_num - 1) * sizeof (struct ntfs_dt*); + len = (parent->child_count - index_num - 1) * sizeof(struct ntfs_dt*); - memmove (dst, src, len); + memmove(dst, src, len); //insert sub_node pointer parent->sub_nodes[index_num] = child; @@ -1946,7 +1948,7 @@ int ntfs_dt_root_add (struct ntfs_dt *parent, int index_num, INDEX_ENTRY *ie, st /** * ntfs_dt_add2 */ -int ntfs_dt_add2 (INDEX_ENTRY *ie, struct ntfs_dt *suc, int suc_num, struct ntfs_dt *ded) +int ntfs_dt_add2(INDEX_ENTRY *ie, struct ntfs_dt *suc, int suc_num, struct ntfs_dt *ded) { int need; int space; @@ -1961,10 +1963,10 @@ int ntfs_dt_add2 (INDEX_ENTRY *ie, struct ntfs_dt *suc, int suc_num, struct ntfs if (!ie || !suc) return -1; - printf ("\n"); - printf (BOLD YELLOW "Add key to leaf\n" END); + ntfs_log_debug("\n"); + ntfs_log_debug(BOLD YELLOW "Add key to leaf\n" END); - //utils_dump_mem (suc->data, 0, suc->data_len, DM_DEFAULTS); + //utils_dump_mem(suc->data, 0, suc->data_len, DM_DEFAULTS); chl = NULL; ascend: @@ -1972,7 +1974,7 @@ ascend: #if 0 for (; ded; ded = ded->sub_nodes[0]) { - printf ("\tded vcn = %lld\n", ded->vcn); + ntfs_log_debug("\tded vcn = %lld\n", ded->vcn); } #endif @@ -1984,19 +1986,19 @@ ascend: */ need = ie->length; - if (ntfs_dt_isroot (suc)) - space = ntfs_dt_root_freespace (suc); + if (ntfs_dt_isroot(suc)) + space = ntfs_dt_root_freespace(suc); else - space = ntfs_dt_alloc_freespace (suc); + space = ntfs_dt_alloc_freespace(suc); - printf ("\tneed %d\n", need); - printf ("\tspace %d\n", space); + ntfs_log_debug("\tneed %d\n", need); + ntfs_log_debug("\tspace %d\n", space); if (space >= need) { - if (ntfs_dt_isroot (suc)) - ntfs_dt_root_add (suc, suc_num, ie, chl); + if (ntfs_dt_isroot(suc)) + ntfs_dt_root_add(suc, suc_num, ie, chl); else - ntfs_dt_alloc_add (suc, suc_num, ie, chl); + ntfs_dt_alloc_add(suc, suc_num, ie, chl); goto done; } @@ -2010,9 +2012,9 @@ ascend: new = ded; vcn = ded->vcn; ded = ded->sub_nodes[0]; - printf ("\treusing vcn %lld\n", new->vcn); + ntfs_log_debug("\treusing vcn %lld\n", new->vcn); } else { - ntfs_mft_add_index (suc->dir); + ntfs_mft_add_index(suc->dir); /* * ALLOC * any unused records? @@ -2038,7 +2040,7 @@ ascend: */ } - //printf ("\tnode has %d children\n", suc->child_count); + //ntfs_log_debug("\tnode has %d children\n", suc->child_count); // initialise new node // XXX ntfs_dt_initialise (new, vcn); @@ -2047,37 +2049,37 @@ ascend: // find median key median = (suc->child_count+1) / 2; - med_ie = ntfs_ie_copy (suc->children[median]); - //file = &med_ie->key.file_name; printf ("\tmed name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n"); + med_ie = ntfs_ie_copy(suc->children[median]); + //file = &med_ie->key.file_name; ntfs_log_debug("\tmed name: "); ntfs_name_print(file->file_name, file->file_name_length); ntfs_log_debug("\n"); - ntfs_ie_free (med_ie); + ntfs_ie_free(med_ie); med_ie = NULL; - //printf ("suc key count = %d\n", suc->child_count); - //printf ("new key count = %d\n", new->child_count); + //ntfs_log_debug("suc key count = %d\n", suc->child_count); + //ntfs_log_debug("new key count = %d\n", new->child_count); - //printf ("median's child = %p\n", suc->sub_nodes[median]); + //ntfs_log_debug("median's child = %p\n", suc->sub_nodes[median]); // need to pass the child when ascending chl = suc->sub_nodes[median]; // transfer keys - if (ntfs_dt_transfer (suc, new, 0, median-1) < 0) + if (ntfs_dt_transfer(suc, new, 0, median-1) < 0) goto done; - //printf ("suc key count = %d\n", suc->child_count); - //printf ("new key count = %d\n", new->child_count); + //ntfs_log_debug("suc key count = %d\n", suc->child_count); + //ntfs_log_debug("new key count = %d\n", new->child_count); - //file = &suc->children[0]->key.file_name; printf ("\tmed name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n"); + //file = &suc->children[0]->key.file_name; ntfs_log_debug("\tmed name: "); ntfs_name_print(file->file_name, file->file_name_length); ntfs_log_debug("\n"); // can this be a root node? - if (ntfs_dt_isroot (suc)) - ntfs_dt_root_remove (suc, 0); + if (ntfs_dt_isroot(suc)) + ntfs_dt_root_remove(suc, 0); else - ntfs_dt_alloc_remove (suc, 0); + ntfs_dt_alloc_remove(suc, 0); - //file = &suc->children[0]->key.file_name; printf ("\tmed name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n"); - //printf ("suc key count = %d\n", suc->child_count); - //printf ("new key count = %d\n", new->child_count); + //file = &suc->children[0]->key.file_name; ntfs_log_debug("\tmed name: "); ntfs_name_print(file->file_name, file->file_name_length); ntfs_log_debug("\n"); + //ntfs_log_debug("suc key count = %d\n", suc->child_count); + //ntfs_log_debug("new key count = %d\n", new->child_count); // remove the median key @@ -2086,12 +2088,12 @@ ascend: // median child is new // ascend - med_ie = ntfs_ie_set_vcn (med_ie, new->vcn); + med_ie = ntfs_ie_set_vcn(med_ie, new->vcn); if (!med_ie) goto done; - //printf ("median child = %lld\n", ntfs_ie_get_vcn (med_ie)); - //printf ("new's vcn = %lld\n", new->vcn); + //ntfs_log_debug("median child = %lld\n", ntfs_ie_get_vcn(med_ie)); + //ntfs_log_debug("new's vcn = %lld\n", new->vcn); // adjust parents // attach new to median @@ -2107,8 +2109,8 @@ ascend: suc = suc->parent; suc_num = 0; - printf ("\n"); - printf (BOLD YELLOW "Ascend\n" END); + ntfs_log_debug("\n"); + ntfs_log_debug(BOLD YELLOW "Ascend\n" END); goto ascend; done: return 0; diff --git a/libntfs/unistr.c b/libntfs/unistr.c index 529a2b9e..a8b91d20 100644 --- a/libntfs/unistr.c +++ b/libntfs/unistr.c @@ -1,4 +1,4 @@ -/* +/** * unistr.c - Unicode string handling. Part of the Linux-NTFS project. * * Copyright (c) 2000-2004 Anton Altaparmakov @@ -19,7 +19,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDIO_H #include @@ -40,6 +42,7 @@ #include "types.h" #include "unistr.h" #include "debug.h" +#include "logging.h" /* * IMPORTANT @@ -129,7 +132,7 @@ int ntfs_names_collate(const ntfschar *name1, const u32 name1_len, #ifdef DEBUG if (!name1 || !name2 || (ic && (!upcase || !upcase_len))) { - Dputs("ntfs_names_collate received NULL pointer!"); + ntfs_log_debug("ntfs_names_collate received NULL pointer!\n"); exit(1); } #endif @@ -187,7 +190,7 @@ int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n) #ifdef DEBUG if (!s1 || !s2) { - Dputs("ntfs_wcsncmp() received NULL pointer!"); + ntfs_log_debug("ntfs_wcsncmp() received NULL pointer!\n"); exit(1); } #endif @@ -230,7 +233,7 @@ int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n, #ifdef DEBUG if (!s1 || !s2 || !upcase) { - Dputs("ntfs_wcsncasecmp() received NULL pointer!"); + ntfs_log_debug("ntfs_wcsncasecmp() received NULL pointer!\n"); exit(1); } #endif @@ -428,7 +431,7 @@ int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs, if (cnt == -1) goto err_out; if (cnt <= 0) { - Dprintf("Eeek. cnt <= 0, cnt = %i\n", cnt); + ntfs_log_debug("Eeek. cnt <= 0, cnt = %i\n", cnt); errno = EINVAL; goto err_out; } @@ -437,7 +440,7 @@ int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs, #ifdef HAVE_MBSINIT /* Make sure we are back in the initial state. */ if (!mbsinit(&mbstate)) { - Dputs("Eeek. mbstate not in initial state!"); + ntfs_log_debug("Eeek. mbstate not in initial state!\n"); errno = EILSEQ; goto err_out; } @@ -572,7 +575,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs, int outs_len) if (cnt == -1) goto err_out; if (cnt < -1) { - Dprintf("%s(): Eeek. cnt = %i\n", __FUNCTION__, cnt); + ntfs_log_trace("Eeek. cnt = %i\n", cnt); errno = EINVAL; goto err_out; } @@ -588,8 +591,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs, int outs_len) #ifdef HAVE_MBSINIT /* Make sure we are back in the initial state. */ if (!mbsinit(&mbstate)) { - Dprintf("%s(): Eeek. mbstate not in initial state!\n", - __FUNCTION__); + ntfs_log_trace("Eeek. mbstate not in initial state!\n"); errno = EILSEQ; goto err_out; } diff --git a/libntfs/unix_io.c b/libntfs/unix_io.c index 196d6160..a91b6431 100644 --- a/libntfs/unix_io.c +++ b/libntfs/unix_io.c @@ -1,4 +1,4 @@ -/* +/** * unix_io.c - Unix style disk io functions. Part of the Linux-NTFS project. * * Copyright (c) 2000-2003 Anton Altaparmakov @@ -19,7 +19,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_UNISTD_H #include @@ -49,13 +51,14 @@ #include #endif #ifdef HAVE_LINUX_FD_H -# include +#include #endif #include "types.h" #include "mst.h" #include "debug.h" #include "device.h" +#include "logging.h" #if defined(linux) && defined(_IO) && !defined(BLKGETSIZE) # define BLKGETSIZE _IO(0x12,96) /* Get device size in 512byte blocks. */ @@ -63,6 +66,9 @@ #define DEV_FD(dev) (*(int *)dev->d_private) +/** + * ntfs_device_unix_io_open + */ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) { struct flock flk; @@ -92,13 +98,11 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) flk.l_start = flk.l_len = 0LL; if (fcntl(DEV_FD(dev), F_SETLK, &flk)) { err = errno; - Dprintf("ntfs_device_unix_io_open: Could not lock %s for %s: " - "%s\n", dev->d_name, NDevReadOnly(dev) ? - "reading" : "writing", strerror(errno)); + ntfs_log_debug("ntfs_device_unix_io_open: Could not lock %s for %s", + dev->d_name, NDevReadOnly(dev) ? "reading" : "writing"); if (close(DEV_FD(dev))) - Dprintf("ntfs_device_unix_io_open: Warning: Could not " - "close %s: %s\n", dev->d_name, - strerror(errno)); + ntfs_log_perror("ntfs_device_unix_io_open: Warning: Could not " + "close %s", dev->d_name); goto err_out; } /* Set our open flag. */ @@ -111,6 +115,9 @@ err_out: return -1; } +/** + * ntfs_device_unix_io_close + */ static int ntfs_device_unix_io_close(struct ntfs_device *dev) { struct flock flk; @@ -127,8 +134,8 @@ static int ntfs_device_unix_io_close(struct ntfs_device *dev) flk.l_whence = SEEK_SET; flk.l_start = flk.l_len = 0LL; if (fcntl(DEV_FD(dev), F_SETLK, &flk)) - Dprintf("ntfs_device_unix_io_close: Warning: Could not unlock " - "%s: %s\n", dev->d_name, strerror(errno)); + ntfs_log_perror("ntfs_device_unix_io_close: Warning: Could not " + "unlock %s", dev->d_name); /* Close the file descriptor and clear our open flag. */ if (close(DEV_FD(dev))) return -1; @@ -138,18 +145,27 @@ static int ntfs_device_unix_io_close(struct ntfs_device *dev) return 0; } +/** + * ntfs_device_unix_io_seek + */ static s64 ntfs_device_unix_io_seek(struct ntfs_device *dev, s64 offset, int whence) { return lseek(DEV_FD(dev), offset, whence); } +/** + * ntfs_device_unix_io_read + */ static s64 ntfs_device_unix_io_read(struct ntfs_device *dev, void *buf, s64 count) { return read(DEV_FD(dev), buf, count); } +/** + * ntfs_device_unix_io_write + */ static s64 ntfs_device_unix_io_write(struct ntfs_device *dev, const void *buf, s64 count) { @@ -161,12 +177,18 @@ static s64 ntfs_device_unix_io_write(struct ntfs_device *dev, const void *buf, return write(DEV_FD(dev), buf, count); } +/** + * ntfs_device_unix_io_pread + */ static s64 ntfs_device_unix_io_pread(struct ntfs_device *dev, void *buf, s64 count, s64 offset) { return ntfs_pread(dev, offset, count, buf); } +/** + * ntfs_device_unix_io_pwrite + */ static s64 ntfs_device_unix_io_pwrite(struct ntfs_device *dev, const void *buf, s64 count, s64 offset) { @@ -178,6 +200,9 @@ static s64 ntfs_device_unix_io_pwrite(struct ntfs_device *dev, const void *buf, return ntfs_pwrite(dev, offset, count, buf); } +/** + * ntfs_device_unix_io_sync + */ static int ntfs_device_unix_io_sync(struct ntfs_device *dev) { if (!NDevReadOnly(dev) && NDevDirty(dev)) { @@ -189,11 +214,17 @@ static int ntfs_device_unix_io_sync(struct ntfs_device *dev) return 0; } +/** + * ntfs_device_unix_io_stat + */ static int ntfs_device_unix_io_stat(struct ntfs_device *dev, struct stat *buf) { return fstat(DEV_FD(dev), buf); } +/** + * ntfs_device_unix_io_ioctl + */ static int ntfs_device_unix_io_ioctl(struct ntfs_device *dev, int request, void *argp) { diff --git a/libntfs/volume.c b/libntfs/volume.c index 00cf6c47..5c5ca3a2 100644 --- a/libntfs/volume.c +++ b/libntfs/volume.c @@ -1,4 +1,4 @@ -/* +/** * volume.c - NTFS volume handling code. Part of the Linux-NTFS project. * * Copyright (c) 2000-2005 Anton Altaparmakov @@ -21,7 +21,9 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_STDLIB_H #include @@ -58,6 +60,7 @@ #include "runlist.h" #include "logfile.h" #include "dir.h" +#include "logging.h" #ifndef PATH_MAX #define PATH_MAX 4096 @@ -65,7 +68,6 @@ /** * ntfs_volume_alloc - - * */ ntfs_volume *ntfs_volume_alloc(void) { @@ -92,7 +94,6 @@ ntfs_volume *ntfs_volume_alloc(void) * Internal: * * __ntfs_volume_release - - * */ static void __ntfs_volume_release(ntfs_volume *v) { @@ -124,16 +125,11 @@ static void __ntfs_volume_release(ntfs_volume *v) if (NDevDirty(dev)) dev->d_ops->sync(dev); if (dev->d_ops->close(dev)) - Dprintf("%s(): Eeek! Failed to close the device. " - "Error: %s\n", __FUNCTION__, - strerror(errno)); + ntfs_log_perror("Eeek! Failed to close the device. Error: "); } - if (v->vol_name) - free(v->vol_name); - if (v->upcase) - free(v->upcase); - if (v->attrdef) - free(v->attrdef); + free(v->vol_name); + free(v->upcase); + free(v->attrdef); free(v); } @@ -162,7 +158,7 @@ static int ntfs_mft_load(ntfs_volume *vol) vol->mft_ni = ntfs_inode_allocate(vol); mb = (MFT_RECORD*)malloc(vol->mft_record_size); if (!vol->mft_ni || !mb) { - Dperror("Error allocating memory for $MFT"); + ntfs_log_perror("Error allocating memory for $MFT"); goto error_exit; } vol->mft_ni->mft_no = 0; @@ -173,33 +169,33 @@ static int ntfs_mft_load(ntfs_volume *vol) if (l != 1) { if (l != -1) errno = EIO; - Dperror("Error reading $MFT"); + ntfs_log_perror("Error reading $MFT"); goto error_exit; } if (ntfs_is_baad_record(mb->magic)) { - Dputs("Error: Incomplete multi sector transfer detected in " - "$MFT."); + ntfs_log_debug("Error: Incomplete multi sector transfer detected in " + "$MFT.\n"); goto io_error_exit; } if (!ntfs_is_mft_record(mb->magic)) { - Dputs("Error: $MFT has invalid magic."); + ntfs_log_debug("Error: $MFT has invalid magic.\n"); goto io_error_exit; } ctx = ntfs_attr_get_search_ctx(vol->mft_ni, NULL); if (!ctx) { - Dperror("Failed to allocate attribute search context"); + ntfs_log_perror("Failed to allocate attribute search context"); goto error_exit; } if (p2n(ctx->attr) < p2n(mb) || (char*)ctx->attr > (char*)mb + vol->mft_record_size) { - Dputs("Error: $MFT is corrupt."); + ntfs_log_debug("Error: $MFT is corrupt.\n"); goto io_error_exit; } /* Find the $ATTRIBUTE_LIST attribute in $MFT if present. */ if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { if (errno != ENOENT) { - Dputs("Error: $MFT has corrupt attribute list."); + ntfs_log_debug("Error: $MFT has corrupt attribute list.\n"); goto io_error_exit; } goto mft_has_no_attr_list; @@ -207,23 +203,25 @@ static int ntfs_mft_load(ntfs_volume *vol) NInoSetAttrList(vol->mft_ni); l = ntfs_get_attribute_value_length(ctx->attr); if (l <= 0 || l > 0x40000) { - Dputs("Error: $MFT/$ATTRIBUTE_LIST has invalid length."); + ntfs_log_debug("Error: $MFT/$ATTRIBUTE_LIST has invalid length.\n"); goto io_error_exit; } vol->mft_ni->attr_list_size = l; vol->mft_ni->attr_list = malloc(l); if (!vol->mft_ni->attr_list) { - Dputs("Error: failed to allocate buffer for attribute list."); + ntfs_log_debug("Error: failed to allocate buffer for attribute " + "list.\n"); goto error_exit; } l = ntfs_get_attribute_value(vol, ctx->attr, vol->mft_ni->attr_list); if (!l) { - Dputs("Error: failed to get value of $MFT/$ATTRIBUTE_LIST."); + ntfs_log_debug("Error: failed to get value of " + "$MFT/$ATTRIBUTE_LIST.\n"); goto io_error_exit; } if (l != vol->mft_ni->attr_list_size) { - Dputs("Error: got unexpected amount of data when reading " - "$MFT/$ATTRIBUTE_LIST."); + ntfs_log_debug("Error: got unexpected amount of data when reading " + "$MFT/$ATTRIBUTE_LIST.\n"); goto io_error_exit; } mft_has_no_attr_list: @@ -232,7 +230,7 @@ mft_has_no_attr_list: /* Get an ntfs attribute for $MFT/$DATA and set it up, too. */ vol->mft_na = ntfs_attr_open(vol->mft_ni, AT_DATA, AT_UNNAMED, 0); if (!vol->mft_na) { - Dperror("Failed to open ntfs attribute"); + ntfs_log_perror("Failed to open ntfs attribute"); goto error_exit; } /* Read all extents from the $DATA attribute in $MFT. */ @@ -247,17 +245,17 @@ mft_has_no_attr_list: a = ctx->attr; /* $MFT must be non-resident. */ if (!a->non_resident) { - Dputs("$MFT must be non-resident but a resident " - "extent was found. $MFT is corrupt. " - "Run chkdsk."); + ntfs_log_debug("$MFT must be non-resident but a resident " + "extent was found. $MFT is corrupt. Run " + "chkdsk.\n"); goto io_error_exit; } /* $MFT must be uncompressed and unencrypted. */ if (a->flags & ATTR_COMPRESSION_MASK || a->flags & ATTR_IS_ENCRYPTED) { - Dputs("$MFT must be uncompressed and unencrypted but " - "a compressed/encrypted extent was " - "found. $MFT is corrupt. Run chkdsk."); + ntfs_log_debug("$MFT must be uncompressed and unencrypted " + "but a compressed/encrypted extent was " + "found. $MFT is corrupt. Run chkdsk.\n"); goto io_error_exit; } /* @@ -268,7 +266,7 @@ mft_has_no_attr_list: */ nrl = ntfs_mapping_pairs_decompress(vol, a, vol->mft_na->rl); if (!nrl) { - Dperror("ntfs_mapping_pairs_decompress() failed"); + ntfs_log_perror("ntfs_mapping_pairs_decompress() failed"); goto error_exit; } vol->mft_na->rl = nrl; @@ -283,22 +281,21 @@ mft_has_no_attr_list: /* Avoid endless loops due to corruption. */ if (next_vcn < sle64_to_cpu(a->lowest_vcn)) { - Dputs("$MFT has corrupt attribute list attribute. " - "Run chkdsk."); + ntfs_log_debug("$MFT has corrupt attribute list attribute. " + "Run chkdsk.\n"); goto io_error_exit; } } if (!a) { - Dputs("$MFT/$DATA attribute not found. $MFT is corrupt. " - "Run chkdsk."); + ntfs_log_debug("$MFT/$DATA attribute not found. $MFT is corrupt. Run " + "chkdsk.\n"); goto io_error_exit; } if (highest_vcn && highest_vcn != last_vcn - 1) { - Dputs("Failed to load the complete runlist for $MFT/$DATA. " - "Bug or corrupt $MFT. Run chkdsk."); - Dprintf("highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx\n", - (long long)highest_vcn, - (long long)last_vcn - 1); + ntfs_log_debug("Failed to load the complete runlist for $MFT/$DATA. " + "Bug or corrupt $MFT. Run chkdsk.\n"); + ntfs_log_debug("highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx\n", + (long long)highest_vcn, (long long)last_vcn - 1); goto io_error_exit; } /* Done with the $Mft mft record. */ @@ -309,7 +306,7 @@ mft_has_no_attr_list: */ vol->mftbmp_na = ntfs_attr_open(vol->mft_ni, AT_BITMAP, AT_UNNAMED, 0); if (!vol->mftbmp_na) { - Dperror("Failed to open $MFT/$BITMAP"); + ntfs_log_perror("Failed to open $MFT/$BITMAP"); goto error_exit; } return 0; @@ -351,17 +348,17 @@ static int ntfs_mftmirr_load(ntfs_volume *vol) vol->mftmirr_ni = ntfs_inode_open(vol, FILE_MFTMirr); if (!vol->mftmirr_ni) { - Dperror("Failed to open inode $MFTMirr"); + ntfs_log_perror("Failed to open inode $MFTMirr"); return -1; } /* Get an ntfs attribute for $MFTMirr/$DATA, too. */ vol->mftmirr_na = ntfs_attr_open(vol->mftmirr_ni, AT_DATA, AT_UNNAMED, 0); if (!vol->mftmirr_na) { - Dperror("Failed to open $MFTMirr/$DATA"); + ntfs_log_perror("Failed to open $MFTMirr/$DATA"); goto error_exit; } if (ntfs_attr_map_runlist(vol->mftmirr_na, 0) < 0) { - Dperror("Failed to map runlist of $MFTMirr/$DATA"); + ntfs_log_perror("Failed to map runlist of $MFTMirr/$DATA"); goto error_exit; } /* Construct the mft mirror runlist. */ @@ -378,7 +375,8 @@ static int ntfs_mftmirr_load(ntfs_volume *vol) if (rl[i].vcn != vol->mftmirr_na->rl[i].vcn || rl[i].lcn != vol->mftmirr_na->rl[i].lcn || rl[i].length != vol->mftmirr_na->rl[i].length) { - Dputs("Error: $MFTMirr location mismatch! Run chkdsk."); + ntfs_log_debug("Error: $MFTMirr location mismatch! Run " + "chkdsk.\n"); errno = EIO; goto error_exit; } @@ -415,9 +413,9 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long rwflag) ntfs_volume *vol; NTFS_BOOT_SECTOR *bs; int eo; -#ifdef DEBUG - const char *OK = "OK"; - const char *FAILED = "FAILED"; +#ifndef NTFS_DISABLE_DEBUG_LOGGING + const char *OK = "OK\n"; + const char *FAILED = "FAILED\n"; BOOL debug = 1; #else BOOL debug = 0; @@ -439,17 +437,17 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long rwflag) vol->upcase_len = 65536; vol->upcase = (ntfschar*)malloc(vol->upcase_len * sizeof(ntfschar)); if (!vol->upcase) { - Dperror("Error allocating memory for upcase table."); + ntfs_log_perror("Error allocating memory for upcase table."); goto error_exit; } ntfs_upcase_table_build(vol->upcase, vol->upcase_len * sizeof(ntfschar)); if ((rwflag & MS_RDONLY) == MS_RDONLY) NVolSetReadOnly(vol); - Dprintf("Reading bootsector... "); + ntfs_log_debug("Reading bootsector... "); if (dev->d_ops->open(dev, NVolReadOnly(vol) ? O_RDONLY: O_RDWR)) { - Dputs(FAILED); - Dperror("Error opening partition device"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Error opening partition device"); goto error_exit; } /* Attach the device to the volume. */ @@ -457,25 +455,25 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long rwflag) /* Now read the bootsector. */ br = ntfs_pread(dev, 0, sizeof(NTFS_BOOT_SECTOR), bs); if (br != sizeof(NTFS_BOOT_SECTOR)) { - Dputs(FAILED); + ntfs_log_debug(FAILED); if (br != -1) errno = EINVAL; if (!br) - Dputs("Error: partition is smaller than bootsector " - "size. Weird!"); + ntfs_log_debug("Error: partition is smaller than bootsector " + "size. Weird!\n"); else - Dperror("Error reading bootsector"); + ntfs_log_perror("Error reading bootsector"); goto error_exit; } - Dputs(OK); + ntfs_log_debug(OK); if (!ntfs_boot_sector_is_ntfs(bs, !debug)) { - Dprintf("Error: %s is not a valid NTFS partition!\n", + ntfs_log_debug("Error: %s is not a valid NTFS partition!\n", dev->d_name); errno = EINVAL; goto error_exit; } if (ntfs_boot_sector_parse(vol, bs) < 0) { - Dperror("Failed to parse ntfs bootsector"); + ntfs_log_perror("Failed to parse ntfs bootsector"); goto error_exit; } free(bs); @@ -510,7 +508,7 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long rwflag) /* Setup the mft zone. */ vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn; - Dprintf("mft_zone_pos = 0x%llx\n", (long long)vol->mft_zone_pos); + ntfs_log_debug("mft_zone_pos = 0x%llx\n", (long long)vol->mft_zone_pos); /* * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs @@ -527,7 +525,7 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long rwflag) vol->cluster_size; if (vol->mft_zone_start <= mft_lcn) vol->mft_zone_start = 0; - Dprintf("mft_zone_start = 0x%llx\n", (long long)vol->mft_zone_start); + ntfs_log_debug("mft_zone_start = 0x%llx\n", (long long)vol->mft_zone_start); /* * Need to cap the mft zone on non-standard volumes so that it does @@ -539,16 +537,16 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long rwflag) mft_zone_size >>= 1; vol->mft_zone_end = vol->mft_lcn + mft_zone_size; } - Dprintf("mft_zone_end = 0x%llx\n", (long long)vol->mft_zone_end); + ntfs_log_debug("mft_zone_end = 0x%llx\n", (long long)vol->mft_zone_end); /* * Set the current position within each data zone to the start of the * respective zone. */ vol->data1_zone_pos = vol->mft_zone_end; - Dprintf("data1_zone_pos = 0x%llx\n", vol->data1_zone_pos); + ntfs_log_debug("data1_zone_pos = 0x%llx\n", vol->data1_zone_pos); vol->data2_zone_pos = 0; - Dprintf("data2_zone_pos = 0x%llx\n", vol->data2_zone_pos); + ntfs_log_debug("data2_zone_pos = 0x%llx\n", vol->data2_zone_pos); /* Set the mft data allocation position to mft record 24. */ vol->mft_data_pos = 24; @@ -558,22 +556,22 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long rwflag) */ /* Need to setup $MFT so we can use the library read functions. */ - Dprintf("Loading $MFT... "); + ntfs_log_debug("Loading $MFT... "); if (ntfs_mft_load(vol) < 0) { - Dputs(FAILED); - Dperror("Failed to load $MFT"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to load $MFT"); goto error_exit; } - Dputs(OK); + ntfs_log_debug(OK); /* Need to setup $MFTMirr so we can use the write functions, too. */ - Dprintf("Loading $MFTMirr... "); + ntfs_log_debug("Loading $MFTMirr... "); if (ntfs_mftmirr_load(vol) < 0) { - Dputs(FAILED); - Dperror("Failed to load $MFTMirr"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to load $MFTMirr"); goto error_exit; } - Dputs(OK); + ntfs_log_debug(OK); return vol; error_exit: eo = errno; @@ -598,19 +596,18 @@ static int ntfs_volume_check_logfile(ntfs_volume *vol) int err = 0; if ((ni = ntfs_inode_open(vol, FILE_LogFile)) == NULL) { - Dprintf("Failed to open inode FILE_LogFile.\n"); + ntfs_log_debug("Failed to open inode FILE_LogFile.\n"); errno = EIO; return -1; } if ((na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0)) == NULL) { - Dprintf("Failed to open $FILE_LogFile/$DATA\n"); + ntfs_log_debug("Failed to open $FILE_LogFile/$DATA\n"); err = EIO; goto exit; } if (!ntfs_check_logfile(na, &rp) || !ntfs_is_logfile_clean(na, rp)) err = EOPNOTSUPP; - if (rp) - free(rp); + free(rp); exit: if (na) ntfs_attr_close(na); @@ -645,32 +642,31 @@ static ntfs_inode *ntfs_hiberfile_open(ntfs_volume *vol) ni_root = ntfs_inode_open(vol, FILE_root); if (!ni_root) { - Dprintf("Couldn't open the root directory.\n"); + ntfs_log_debug("Couldn't open the root directory.\n"); return NULL; } unicode_len = ntfs_mbstoucs(hiberfile, &unicode, 0); if (unicode_len < 0) { - Dperror("Couldn't convert 'hiberfil.sys' to Unicode"); + ntfs_log_perror("Couldn't convert 'hiberfil.sys' to Unicode"); goto out; } inode = ntfs_inode_lookup_by_name(ni_root, unicode, unicode_len); if (inode == (u64)-1) { - Dprintf("Couldn't find file '%s'.\n", hiberfile); + ntfs_log_debug("Couldn't find file '%s'.\n", hiberfile); goto out; } inode = MREF(inode); ni_hibr = ntfs_inode_open(vol, inode); if (!ni_hibr) { - Dprintf("Couldn't open inode %lld.\n", (long long)inode); + ntfs_log_debug("Couldn't open inode %lld.\n", (long long)inode); goto out; } out: ntfs_inode_close(ni_root); - if (unicode) - free(unicode); + free(unicode); return ni_hibr; } @@ -701,34 +697,35 @@ static int ntfs_volume_check_hiberfile(ntfs_volume *vol) buf = malloc(NTFS_HIBERFILE_HEADER_SIZE); if (!buf) { - Dperror("Error allocating memory for hiberfile.sys header"); + ntfs_log_perror("Error allocating memory for hiberfile.sys header"); goto out; } na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { - Dperror("Failed to open hiberfil.sys data attribute"); + ntfs_log_perror("Failed to open hiberfil.sys data attribute"); goto out; } bytes_read = ntfs_attr_pread(na, 0, NTFS_HIBERFILE_HEADER_SIZE, buf); if (bytes_read == -1) { - Dperror("Failed to read hiberfil.sys"); + ntfs_log_perror("Failed to read hiberfil.sys"); goto out; } if (bytes_read < NTFS_HIBERFILE_HEADER_SIZE) { - Dprintf("Hibernated non-system partition, refused to mount!\n"); + ntfs_log_debug("Hibernated non-system partition, refused to " + "mount!\n"); errno = EPERM; goto out; } if (memcmp(buf, "hibr", 4) == 0) { - Dprintf("Windows is hibernated, refused to mount!\n"); + ntfs_log_debug("Windows is hibernated, refused to mount!\n"); errno = EPERM; goto out; } for (i = 0; i < NTFS_HIBERFILE_HEADER_SIZE; i++) { if (buf[i]) { - Dprintf("Windows is hibernated, won't mount!\n"); + ntfs_log_debug("Windows is hibernated, won't mount!\n"); errno = EPERM; goto out; } @@ -738,8 +735,7 @@ static int ntfs_volume_check_hiberfile(ntfs_volume *vol) out: if (na) ntfs_attr_close(na); - if (buf) - free(buf); + free(buf); ntfs_inode_close(ni); return ret; } @@ -769,9 +765,9 @@ out: ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) { s64 l; -#ifdef DEBUG - const char *OK = "OK"; - const char *FAILED = "FAILED"; +#ifndef NTFS_DISABLE_DEBUG_LOGGING + const char *OK = "OK\n"; + const char *FAILED = "FAILED\n"; #endif ntfs_volume *vol; u8 *m = NULL, *m2 = NULL; @@ -786,7 +782,7 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) vol = ntfs_volume_startup(dev, rwflag); if (!vol) { - Dperror("Failed to startup volume"); + ntfs_log_perror("Failed to startup volume"); return NULL; } @@ -794,7 +790,7 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) m = (u8*)malloc(vol->mftmirr_size << vol->mft_record_size_bits); m2 = (u8*)malloc(vol->mftmirr_size << vol->mft_record_size_bits); if (!m || !m2) { - Dperror("Failed to allocate memory"); + ntfs_log_perror("Failed to allocate memory"); goto error_exit; } @@ -802,9 +798,10 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) vol->mft_record_size, m); if (l != vol->mftmirr_size) { if (l == -1) - Dperror("Failed to read $MFT"); + ntfs_log_perror("Failed to read $MFT"); else { - Dputs("Length of data not equal expected length."); + ntfs_log_debug("Length of data not equal expected " + "length.\n"); errno = EIO; } goto error_exit; @@ -813,14 +810,15 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) vol->mft_record_size, m2); if (l != vol->mftmirr_size) { if (l == -1) - Dperror("Failed to read $MFTMirr"); + ntfs_log_perror("Failed to read $MFTMirr"); else { - Dputs("Length of data not equal expected length."); + ntfs_log_debug("Length of data not equal expected " + "length.\n"); errno = EIO; } goto error_exit; } - Dprintf("Comparing $MFTMirr to $MFT... "); + ntfs_log_debug("Comparing $MFTMirr to $MFT... "); for (i = 0; i < vol->mftmirr_size; ++i) { const char *ESTR[12] = { "$MFT", "$MFTMirr", "$LogFile", "$Volume", "$AttrDef", "root directory", "$Bitmap", @@ -835,74 +833,75 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) s = "mft record"; if (ntfs_is_baad_recordp(m + i * vol->mft_record_size)) { - Dputs("FAILED"); - Dprintf("$MFT error: Incomplete multi sector transfer " + 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(m + i * vol->mft_record_size)) { - Dputs("FAILED"); - Dprintf("$MFT error: Invalid mft record for %s.\n", s); + ntfs_log_debug("FAILED\n"); + ntfs_log_debug("$MFT error: Invalid mft record for %s.\n", s); goto io_error_exit; } if (ntfs_is_baad_recordp(m2 + i * vol->mft_record_size)) { - Dputs("FAILED"); - Dprintf("$MFTMirr error: Incomplete multi sector " + 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(m2 + i * vol->mft_record_size)) { - Dputs("FAILED"); - Dprintf("$MFTMirr error: Invalid mft record for %s.\n", - s); + ntfs_log_debug("FAILED\n"); + ntfs_log_debug("$MFTMirr error: Invalid mft record for " + "%s.\n", s); goto io_error_exit; } if (memcmp((u8*)m + i * vol->mft_record_size, (u8*)m2 + i * vol->mft_record_size, ntfs_mft_record_get_data_size((MFT_RECORD*)( (u8*)m + i * vol->mft_record_size)))) { - Dputs(FAILED); - Dputs("$MFTMirr does not match $MFT. Run chkdsk."); + ntfs_log_debug(FAILED); + ntfs_log_debug("$MFTMirr does not match $MFT. Run " + "chkdsk.\n"); goto io_error_exit; } } - Dputs(OK); + ntfs_log_debug(OK); free(m2); free(m); m = m2 = NULL; /* Now load the bitmap from $Bitmap. */ - Dprintf("Loading $Bitmap... "); + ntfs_log_debug("Loading $Bitmap... "); vol->lcnbmp_ni = ntfs_inode_open(vol, FILE_Bitmap); if (!vol->lcnbmp_ni) { - Dputs(FAILED); - Dperror("Failed to open inode"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to open inode"); goto error_exit; } /* Get an ntfs attribute for $Bitmap/$DATA. */ vol->lcnbmp_na = ntfs_attr_open(vol->lcnbmp_ni, AT_DATA, AT_UNNAMED, 0); if (!vol->lcnbmp_na) { - Dputs(FAILED); - Dperror("Failed to open ntfs attribute"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to open ntfs attribute"); goto error_exit; } /* Done with the $Bitmap mft record. */ - Dputs(OK); + ntfs_log_debug(OK); /* Now load the upcase table from $UpCase. */ - Dprintf("Loading $UpCase... "); + ntfs_log_debug("Loading $UpCase... "); ni = ntfs_inode_open(vol, FILE_UpCase); if (!ni) { - Dputs(FAILED); - Dperror("Failed to open inode"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to open inode"); goto error_exit; } /* Get an ntfs attribute for $UpCase/$DATA. */ na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { - Dputs(FAILED); - Dperror("Failed to open ntfs attribute"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to open ntfs attribute"); goto error_exit; } /* @@ -912,8 +911,9 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) * characters. */ if (na->data_size & ~0x1ffffffffULL) { - Dputs(FAILED); - Dputs("Error: Upcase table is too big (max 32-bit allowed)."); + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Upcase table is too big (max 32-bit " + "allowed).\n"); errno = EINVAL; goto error_exit; } @@ -923,58 +923,58 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) free(vol->upcase); vol->upcase = (ntfschar*)malloc(na->data_size); if (!vol->upcase) { - Dputs(FAILED); - Dputs("Not enough memory to load $UpCase."); + ntfs_log_debug(FAILED); + ntfs_log_debug("Not enough memory to load $UpCase.\n"); goto error_exit; } } /* Read in the $DATA attribute value into the buffer. */ l = ntfs_attr_pread(na, 0, na->data_size, vol->upcase); if (l != na->data_size) { - Dputs(FAILED); - Dputs("Amount of data read does not correspond to expected " - "length!"); + ntfs_log_debug(FAILED); + ntfs_log_debug("Amount of data read does not correspond to expected " + "length!\n"); errno = EIO; goto error_exit; } /* Done with the $UpCase mft record. */ - Dputs(OK); + ntfs_log_debug(OK); ntfs_attr_close(na); if (ntfs_inode_close(ni)) - Dperror("Failed to close inode, leaking memory"); + ntfs_log_perror("Failed to close inode, leaking memory"); /* * Now load $Volume and set the version information and flags in the * vol structure accordingly. */ - Dprintf("Loading $Volume... "); + ntfs_log_debug("Loading $Volume... "); vol->vol_ni = ntfs_inode_open(vol, FILE_Volume); if (!vol->vol_ni) { - Dputs(FAILED); - Dperror("Failed to open inode"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to open inode"); goto error_exit; } /* Get a search context for the $Volume/$VOLUME_INFORMATION lookup. */ ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); if (!ctx) { - Dputs(FAILED); - Dperror("Failed to allocate attribute search context"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to allocate attribute search context"); goto error_exit; } /* Find the $VOLUME_INFORMATION attribute. */ if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { - Dputs(FAILED); - Dputs("$VOLUME_INFORMATION attribute not found in " - "$Volume?!?"); + ntfs_log_debug(FAILED); + ntfs_log_debug("$VOLUME_INFORMATION attribute not found in " + "$Volume?!?\n"); goto error_exit; } a = ctx->attr; /* Has to be resident. */ if (a->non_resident) { - Dputs(FAILED); - Dputs("Error: Attribute $VOLUME_INFORMATION must be resident " - "(and it isn't)!"); + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Attribute $VOLUME_INFORMATION must be " + "resident (and it isn't)!\n"); errno = EIO; goto error_exit; } @@ -985,9 +985,9 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) le32_to_cpu(ctx->mrec->bytes_in_use) || le16_to_cpu(a->value_offset) + le32_to_cpu( a->value_length) > le32_to_cpu(a->length)) { - Dputs(FAILED); - Dputs("Error: Attribute $VOLUME_INFORMATION in $Volume is " - "corrupt!"); + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Attribute $VOLUME_INFORMATION in $Volume is " + "corrupt!\n"); errno = EIO; goto error_exit; } @@ -1004,10 +1004,10 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) if (ntfs_attr_lookup(AT_VOLUME_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { if (errno != ENOENT) { - Dputs(FAILED); - Dputs("Error: Lookup of $VOLUME_NAME attribute in " + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Lookup of $VOLUME_NAME attribute in " "$Volume failed. This probably means " - "something is corrupt. Run chkdsk."); + "something is corrupt. Run chkdsk.\n"); goto error_exit; } /* @@ -1017,9 +1017,9 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) */ vol->vol_name = malloc(1); if (!vol->vol_name) { - Dputs(FAILED); - Dputs("Error: Unable to allocate memory for volume " - "name!"); + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Unable to allocate memory for volume " + "name!\n"); goto error_exit; } vol->vol_name[0] = '\0'; @@ -1027,9 +1027,9 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) a = ctx->attr; /* Has to be resident. */ if (a->non_resident) { - Dputs(FAILED); - Dputs("Error: Attribute $VOLUME_NAME must be " - "resident!"); + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Attribute $VOLUME_NAME must be " + "resident!\n"); errno = EIO; goto error_exit; } @@ -1042,15 +1042,15 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) */ vol->vol_name = NULL; if (ntfs_ucstombs(vname, u, &vol->vol_name, 0) == -1) { - Dperror("Error: Volume name could not be converted to " - "current locale"); - Dputs("Forcing name into ASCII by replacing non-ASCII " - "characters with underscores."); + ntfs_log_perror("Error: Volume name could not be converted " + "to current locale"); + ntfs_log_debug("Forcing name into ASCII by replacing " + "non-ASCII characters with underscores.\n"); vol->vol_name = malloc(u + 1); if (!vol->vol_name) { - Dputs(FAILED); - Dputs("Error: Unable to allocate memory for " - "volume name!"); + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Unable to allocate memory for " + "volume name!\n"); goto error_exit; } for (j = 0; j < (s32)u; j++) { @@ -1062,53 +1062,53 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long rwflag) vol->vol_name[u] = '\0'; } } - Dputs(OK); + ntfs_log_debug(OK); ntfs_attr_put_search_ctx(ctx); ctx = NULL; /* Now load the attribute definitions from $AttrDef. */ - Dprintf("Loading $AttrDef... "); + ntfs_log_debug("Loading $AttrDef... "); ni = ntfs_inode_open(vol, FILE_AttrDef); if (!ni) { - Dputs(FAILED); - Dperror("Failed to open inode"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to open inode"); goto error_exit; } /* Get an ntfs attribute for $AttrDef/$DATA. */ na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { - Dputs(FAILED); - Dperror("Failed to open ntfs attribute"); + ntfs_log_debug(FAILED); + ntfs_log_perror("Failed to open ntfs attribute"); goto error_exit; } /* Check we don't overflow 32-bits. */ if (na->data_size > 0xffffffffLL) { - Dputs(FAILED); - Dputs("Error: Attribute definition table is too big " - "(max 32-bit allowed)."); + ntfs_log_debug(FAILED); + ntfs_log_debug("Error: Attribute definition table is too big (max " + "32-bit allowed).\n"); errno = EINVAL; goto error_exit; } vol->attrdef_len = na->data_size; vol->attrdef = (ATTR_DEF*)malloc(na->data_size); if (!vol->attrdef) { - Dputs(FAILED); - Dputs("Not enough memory to load $AttrDef."); + ntfs_log_debug(FAILED); + ntfs_log_debug("Not enough memory to load $AttrDef.\n"); goto error_exit; } /* Read in the $DATA attribute value into the buffer. */ l = ntfs_attr_pread(na, 0, na->data_size, vol->attrdef); if (l != na->data_size) { - Dputs(FAILED); - Dputs("Amount of data read does not correspond to expected " - "length!"); + ntfs_log_debug(FAILED); + ntfs_log_debug("Amount of data read does not correspond to expected " + "length!\n"); errno = EIO; goto error_exit; } /* Done with the $AttrDef mft record. */ - Dputs(OK); + ntfs_log_debug(OK); ntfs_attr_close(na); if (ntfs_inode_close(ni)) - Dperror("Failed to close inode, leaking memory"); + ntfs_log_perror("Failed to close inode, leaking memory"); /* * Check for dirty logfile and hibernated Windows. * We care only about read-write mounts. @@ -1127,10 +1127,8 @@ error_exit: eo = errno; if (ctx) ntfs_attr_put_search_ctx(ctx); - if (m) - free(m); - if (m2) - free(m2); + free(m); + free(m2); __ntfs_volume_release(vol); errno = eo; return NULL; @@ -1267,7 +1265,11 @@ int ntfs_umount(ntfs_volume *vol, #ifdef HAVE_MNTENT_H #ifndef HAVE_REALPATH -/* If there is no realpath() on the system, provide a dummy one. */ +/** + * Internal: + * + * realpath - If there is no realpath on the system + */ static char *realpath(const char *path, char *resolved_path) { strncpy(resolved_path, path, PATH_MAX); @@ -1275,7 +1277,6 @@ static char *realpath(const char *path, char *resolved_path) return resolved_path; } #endif - /** * Internal: * @@ -1327,8 +1328,7 @@ static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags) #endif exit: free(real_file); - if (real_fsname) - free(real_fsname); + free(real_fsname); if (err) { errno = err; return -1; @@ -1441,19 +1441,19 @@ int ntfs_logfile_reset(ntfs_volume *vol) } if ((ni = ntfs_inode_open(vol, FILE_LogFile)) == NULL) { - Dperror("Failed to open inode FILE_LogFile.\n"); + ntfs_log_perror("Failed to open inode FILE_LogFile."); return -1; } if ((na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0)) == NULL) { eo = errno; - Dperror("Failed to open $FILE_LogFile/$DATA\n"); + ntfs_log_perror("Failed to open $FILE_LogFile/$DATA"); goto error_exit; } if (ntfs_empty_logfile(na)) { eo = errno; - Dperror("Failed to empty $FILE_LogFile/$DATA\n"); + ntfs_log_perror("Failed to empty $FILE_LogFile/$DATA"); ntfs_attr_close(na); goto error_exit; } @@ -1490,20 +1490,20 @@ int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags) /* Get a pointer to the volume information attribute. */ ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); if (!ctx) { - Dperror("Failed to allocate attribute search context"); + ntfs_log_perror("Failed to allocate attribute search context"); return -1; } if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { - Dputs("Error: Attribute $VOLUME_INFORMATION was not found in " - "$Volume!"); + ntfs_log_debug("Error: Attribute $VOLUME_INFORMATION was not found " + "in $Volume!\n"); goto err_out; } a = ctx->attr; /* Sanity check. */ if (a->non_resident) { - Dputs("Error: Attribute $VOLUME_INFORMATION must be resident " - "(and it isn't)!"); + ntfs_log_debug("Error: Attribute $VOLUME_INFORMATION must be " + "resident (and it isn't)!\n"); errno = EIO; goto err_out; } @@ -1514,8 +1514,8 @@ int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags) le32_to_cpu(ctx->mrec->bytes_in_use) || le16_to_cpu(a->value_offset) + le32_to_cpu(a->value_length) > le32_to_cpu(a->length)) { - Dputs("Error: Attribute $VOLUME_INFORMATION in $Volume is " - "corrupt!"); + ntfs_log_debug("Error: Attribute $VOLUME_INFORMATION in $Volume is " + "corrupt!\n"); errno = EIO; goto err_out; } @@ -1524,7 +1524,7 @@ int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags) /* Write them to disk. */ ntfs_inode_mark_dirty(vol->vol_ni); if (ntfs_inode_sync(vol->vol_ni)) { - Dperror("Error writing $Volume"); + ntfs_log_perror("Error writing $Volume"); goto err_out; } ret = 0; /* success */ @@ -1538,13 +1538,8 @@ err_out: #include "tree.h" -// XXX temp -#define Eprintf printf -#define Vprintf printf -#define Qprintf printf - /** - * utils_valid_device - Perform some safety checks on the device, before we start + * utils_valid_device - Perform some safety checks on the device before we start * @name: Full pathname of the device/file to work with * @force: Continue regardless of problems * @@ -1554,7 +1549,7 @@ err_out: * Return: 1 Success, we can continue * 0 Error, we cannot use this device */ -int utils_valid_device (const char *name, int force) +int utils_valid_device(const char *name, int force) { unsigned long mnt_flags = 0; struct stat st; @@ -1568,39 +1563,44 @@ int utils_valid_device (const char *name, int force) return 0; } - if (stat (name, &st) == -1) { + if (stat(name, &st) == -1) { if (errno == ENOENT) { - Eprintf ("The device %s doesn't exist\n", name); + ntfs_log_error("The device %s doesn't exist\n", name); } else { - Eprintf ("Error getting information about %s: %s\n", name, strerror (errno)); + ntfs_log_perror("Error getting information about %s", + name); } return 0; } - if (!S_ISBLK (st.st_mode)) { - Vprintf ("%s is not a block device.\n", name); + if (!S_ISBLK(st.st_mode)) { + ntfs_log_verbose("%s is not a block device.\n", name); if (!force) { - Eprintf ("Use the force option to work with files.\n"); + ntfs_log_error("Use the force option to work with " + "files.\n"); return 0; } - Vprintf ("Forced to continue.\n"); + ntfs_log_verbose("Forced to continue.\n"); } /* Make sure the file system is not mounted. */ - if (ntfs_check_if_mounted (name, &mnt_flags)) { - Vprintf ("Failed to determine whether %s is mounted: %s\n", name, strerror (errno)); + if (ntfs_check_if_mounted(name, &mnt_flags)) { + ntfs_log_perror("Failed to determine whether %s is mounted", + name); if (!force) { - Eprintf ("Use the force option to ignore this error.\n"); + ntfs_log_error("Use the force option to ignore this " + "error.\n"); return 0; } - Vprintf ("Forced to continue.\n"); + ntfs_log_verbose("Forced to continue.\n"); } else if (mnt_flags & NTFS_MF_MOUNTED) { - Vprintf ("The device %s, is mounted.\n", name); + ntfs_log_verbose("The device %s, is mounted.\n", name); if (!force) { - Eprintf ("Use the force option to work a mounted filesystem.\n"); + ntfs_log_error("Use the force option to work a mounted " + "filesystem.\n"); return 0; } - Vprintf ("Forced to continue.\n"); + ntfs_log_verbose("Forced to continue.\n"); } return 1; @@ -1609,7 +1609,7 @@ int utils_valid_device (const char *name, int force) /** * utils_mount_volume */ -ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL force) +ntfs_volume * utils_mount_volume(const char *device, unsigned long flags, BOOL force) { ntfs_volume *vol; @@ -1618,18 +1618,17 @@ ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL return NULL; } - if (!utils_valid_device (device, force)) + if (!utils_valid_device(device, force)) return NULL; - vol = ntfs_mount (device, flags); + vol = ntfs_mount(device, flags); if (!vol) { int err; err = errno; - Eprintf("Couldn't mount device '%s': %s\n", device, - strerror(err)); + ntfs_log_perror("Couldn't mount device '%s'", device); if (err == EOPNOTSUPP) - Eprintf("Windows was either hibernated or did not " + ntfs_log_error("Windows was either hibernated or did not " "shut down properly. Try to mount " "volume in windows, shut down and try " "again.\n"); @@ -1637,13 +1636,15 @@ ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL } if (vol->flags & VOLUME_IS_DIRTY) { - Qprintf ("Volume is dirty.\n"); + ntfs_log_quiet("Volume is dirty.\n"); + return NULL; if (!force) { - Eprintf ("Run chkdsk and try again, or use the --force option.\n"); - ntfs_umount (vol, FALSE); + ntfs_log_error("Run chkdsk and try again, or use the " + "--force option.\n"); + ntfs_umount(vol, FALSE); return NULL; } - Qprintf ("Forced to continue.\n"); + ntfs_log_quiet("Forced to continue.\n"); } return vol; @@ -1652,19 +1653,19 @@ ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL /** * ntfs_volume_commit */ -int ntfs_volume_commit (ntfs_volume *vol) +int ntfs_volume_commit(ntfs_volume *vol) { if (!vol) return -1; - printf ("commit volume\n"); - if (ntfs_bmp_commit (vol->private_bmp1) < 0) + ntfs_log_debug("commit volume\n"); + if (ntfs_bmp_commit(vol->private_bmp1) < 0) return -1; - if (ntfs_bmp_commit (vol->private_bmp2) < 0) + if (ntfs_bmp_commit(vol->private_bmp2) < 0) return -1; - if (ntfs_dir_commit (vol->private_data) < 0) + if (ntfs_dir_commit(vol->private_data) < 0) return -1; return 0; @@ -1673,18 +1674,18 @@ int ntfs_volume_commit (ntfs_volume *vol) /** * ntfs_volume_rollback */ -int ntfs_volume_rollback (ntfs_volume *vol) +int ntfs_volume_rollback(ntfs_volume *vol) { if (!vol) return -1; - if (ntfs_bmp_rollback (vol->private_bmp1) < 0) + if (ntfs_bmp_rollback(vol->private_bmp1) < 0) return -1; - if (ntfs_bmp_rollback (vol->private_bmp2) < 0) + if (ntfs_bmp_rollback(vol->private_bmp2) < 0) return -1; - if (ntfs_dir_rollback (vol->private_data) < 0) + if (ntfs_dir_rollback(vol->private_data) < 0) return -1; return 0; @@ -1693,7 +1694,7 @@ int ntfs_volume_rollback (ntfs_volume *vol) /** * ntfs_volume_umount2 */ -int ntfs_volume_umount2 (ntfs_volume *vol, const BOOL force) +int ntfs_volume_umount2(ntfs_volume *vol, const BOOL force) { struct ntfs_dir *dir; struct ntfs_bmp *bmp; @@ -1701,27 +1702,27 @@ int ntfs_volume_umount2 (ntfs_volume *vol, const BOOL force) if (!vol) return 0; - ntfs_volume_rollback (vol); + ntfs_volume_rollback(vol); dir = (struct ntfs_dir *) vol->private_data; vol->private_data = NULL; - ntfs_dir_free (dir); + ntfs_dir_free(dir); bmp = (struct ntfs_bmp *) vol->private_bmp1; vol->private_bmp1 = NULL; - ntfs_bmp_free (bmp); + ntfs_bmp_free(bmp); bmp = (struct ntfs_bmp *) vol->private_bmp2; vol->private_bmp2 = NULL; - ntfs_bmp_free (bmp); + ntfs_bmp_free(bmp); - return ntfs_umount (vol, force); + return ntfs_umount(vol, force); } /** * ntfs_volume_mount2 */ -ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL force) +ntfs_volume * ntfs_volume_mount2(const char *device, unsigned long flags, BOOL force) { // XXX can we replace these and search by mft number? Hmm... NO. // unless I have a recursive search for an MFT number @@ -1767,7 +1768,7 @@ ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL struct ntfs_dt *found; int num; - vol = utils_mount_volume (device, flags, force); + vol = utils_mount_volume(device, flags, force); if (!vol) return NULL; @@ -1779,23 +1780,23 @@ ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL vol->mft_ni ->private_data = NULL; vol->mftmirr_ni->private_data = NULL; - dir = ntfs_dir_create (vol, FILE_root); + dir = ntfs_dir_create(vol, FILE_root); if (!dir) { - ntfs_volume_umount2 (vol, FALSE); + ntfs_volume_umount2(vol, FALSE); vol = NULL; goto done; } - dir->index = ntfs_dt_create (dir, NULL, -1); + dir->index = ntfs_dt_create(dir, NULL, -1); root = dir->index; //$Bitmap num = -1; - found = ntfs_dt_find2 (root, bmp, sizeof (bmp) - 1, &num); + found = ntfs_dt_find2(root, bmp, sizeof(bmp) - 1, &num); if ((!found) || (num < 0)) { - printf ("can't find $Bitmap\n"); - ntfs_volume_umount2 (vol, FALSE); + ntfs_log_debug("can't find $Bitmap\n"); + ntfs_volume_umount2(vol, FALSE); vol = NULL; goto done; } @@ -1805,10 +1806,10 @@ ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL //$MFT num = -1; - found = ntfs_dt_find2 (root, mft, sizeof (mft) - 1, &num); + found = ntfs_dt_find2(root, mft, sizeof(mft) - 1, &num); if ((!found) || (num < 0)) { - printf ("can't find $MFT\n"); - ntfs_volume_umount2 (vol, FALSE); + ntfs_log_debug("can't find $MFT\n"); + ntfs_volume_umount2(vol, FALSE); vol = NULL; goto done; } @@ -1818,10 +1819,10 @@ ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL //$MFTMirr num = -1; - found = ntfs_dt_find2 (root, mftmirr, sizeof (mftmirr) - 1, &num); + found = ntfs_dt_find2(root, mftmirr, sizeof(mftmirr) - 1, &num); if ((!found) || (num < 0)) { - printf ("can't find $MFTMirr\n"); - ntfs_volume_umount2 (vol, FALSE); + ntfs_log_debug("can't find $MFTMirr\n"); + ntfs_volume_umount2(vol, FALSE); vol = NULL; goto done; } @@ -1831,10 +1832,10 @@ ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL // root directory num = -1; - found = ntfs_dt_find2 (root, dot, 1, &num); + found = ntfs_dt_find2(root, dot, 1, &num); if ((!found) || (num < 0)) { - printf ("can't find the root directory\n"); - ntfs_volume_umount2 (vol, FALSE); + ntfs_log_debug("can't find the root directory\n"); + ntfs_volume_umount2(vol, FALSE); vol = NULL; goto done; } @@ -1844,12 +1845,12 @@ ntfs_volume * ntfs_volume_mount2 (const char *device, unsigned long flags, BOOL dir->inode->private_data = found; dir->inode->ref_count = 2; - vol->private_bmp1 = ntfs_bmp_create (vol->mft_ni, AT_BITMAP, NULL, 0); - vol->private_bmp2 = ntfs_bmp_create (vol->lcnbmp_ni, AT_DATA, NULL, 0); + vol->private_bmp1 = ntfs_bmp_create(vol->mft_ni, AT_BITMAP, NULL, 0); + vol->private_bmp2 = ntfs_bmp_create(vol->lcnbmp_ni, AT_DATA, NULL, 0); if (!vol->private_bmp1 || !vol->private_bmp2) { - printf ("can't find the bitmaps\n"); - ntfs_volume_umount2 (vol, FALSE); + ntfs_log_debug("can't find the bitmaps\n"); + ntfs_volume_umount2(vol, FALSE); vol = NULL; goto done; } diff --git a/ntfsprogs/Makefile.am b/ntfsprogs/Makefile.am index 8ce5aad3..aef3c517 100644 --- a/ntfsprogs/Makefile.am +++ b/ntfsprogs/Makefile.am @@ -48,7 +48,7 @@ ntfsfix_SOURCES = ntfsfix.c utils.c utils.h ntfsfix_LDADD = $(AM_LIBS) ntfsfix_LDFLAGS = $(AM_LFLAGS) -mkntfs_SOURCES = attrdef.c upcase.c boot.c sd.c mkntfs.c utils.c utils.h +mkntfs_SOURCES = attrdef.c attrdef.h upcase.c upcase.h boot.c boot.h sd.c sd.h mkntfs.c utils.c utils.h mkntfs_LDADD = $(AM_LIBS) mkntfs_LDFLAGS = $(AM_LFLAGS) diff --git a/ntfsprogs/attrdef.c b/ntfsprogs/attrdef.c index c55a8d5f..3cdaf400 100644 --- a/ntfsprogs/attrdef.c +++ b/ntfsprogs/attrdef.c @@ -203,7 +203,8 @@ const unsigned char attrdef_ntfs3x_array[2560] = { , 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00 +, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF , 0x24, 0x00, 0x49, 0x00, 0x4E, 0x00, 0x44, 0x00, 0x45, 0x00, 0x58, 0x00, 0x5F, 0x00, 0x41, 0x00, 0x4C, 0x00, 0x4C, 0x00, 0x4F, 0x00, 0x43, 0x00, 0x41, 0x00, 0x54, 0x00 , 0x49, 0x00, 0x4F, 0x00, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -245,3 +246,4 @@ const unsigned char attrdef_ntfs3x_array[2560] = { , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 897633ab..290cda0d 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -140,6 +140,10 @@ #include "runlist.h" #include "utils.h" #include "ntfstime.h" +#include "sd.h" +#include "upcase.h" +#include "boot.h" +#include "attrdef.h" #include "version.h" #ifdef NO_NTFS_DEVICE_DEFAULT_IO_OPS @@ -148,15 +152,6 @@ You need to run ./configure without the --disable-default-device-io-ops \ switch if you want to be able to build the NTFS utilities." #endif -extern const unsigned char attrdef_ntfs12_array[2400]; -extern const unsigned char attrdef_ntfs3x_array[2560]; -extern const unsigned char boot_array[3429]; -extern void init_system_file_sd(int sys_file_no, u8 **sd_val, int *sd_val_len); -extern void init_upcase_table(ntfschar *uc, u32 uc_len); -extern void init_secure_30(char *idx_secure); -extern void init_secure_31(char *idx_secure); -extern void init_root_sd_31(u8 **sd_val, int *sd_val_len); - /* Page size on ia32. Can change to 8192 on Alpha. */ #define NTFS_PAGE_SIZE 4096 @@ -344,7 +339,7 @@ static void usage(void) " -v Verbose execution\n" " -vv Very verbose execution\n" " -V Display version \n" - " -w NTFS version " + " -w NTFS version " "information\n" " -l Display licensing " "information\n" @@ -354,7 +349,6 @@ static void usage(void) exit(1); } -#include "version.h" /** * parse_options */ @@ -417,34 +411,34 @@ static void parse_options(int argc, char *argv[]) case 'v': opts.verbose++; break; - case 'w': - if (!strcmp(optarg , "1.2")) { + case 'w': + if (!strcmp(optarg , "1.2")) { vol->major_ver = 1; vol->minor_ver = 2; - opts.attr_defs = + opts.attr_defs = (ATTR_DEF*)&attrdef_ntfs12_array; - opts.attr_defs_len = + opts.attr_defs_len = sizeof(attrdef_ntfs12_array); break; } - if (!strcmp(optarg , "3.0")) { - vol->major_ver = 3; - vol->minor_ver = 0; - opts.attr_defs = - (ATTR_DEF*)&attrdef_ntfs3x_array; - opts.attr_defs_len = - sizeof(attrdef_ntfs3x_array); - break; - } - if (!strcmp(optarg , "3.1")) { - vol->major_ver = 3; - vol->minor_ver = 1; - opts.attr_defs = + if (!strcmp(optarg , "3.0")) { + vol->major_ver = 3; + vol->minor_ver = 0; + opts.attr_defs = (ATTR_DEF*)&attrdef_ntfs3x_array; - opts.attr_defs_len = + opts.attr_defs_len = + sizeof(attrdef_ntfs3x_array); + break; + } + if (!strcmp(optarg , "3.1")) { + vol->major_ver = 3; + vol->minor_ver = 1; + opts.attr_defs = + (ATTR_DEF*)&attrdef_ntfs3x_array; + opts.attr_defs_len = sizeof(attrdef_ntfs3x_array); - break; - } + break; + } err_exit("Ntfs version not supported.\n"); case 'z': l = strtol(optarg, &s, 0); @@ -574,7 +568,7 @@ static __inline__ long long mkntfs_write(struct ntfs_device *dev, */ static s64 ntfs_rlwrite(struct ntfs_device *dev, const runlist *rl, const u8 *val, const s64 val_len, s64 *inited_size) -{ +{ s64 bytes_written, total, length, delta; int retry, i; @@ -1696,8 +1690,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, err_out: if (ctx) ntfs_attr_put_search_ctx(ctx); - if (uname) - free(uname); + free(uname); return err; } @@ -1887,8 +1880,7 @@ err_out: ntfs_attr_put_search_ctx(ctx); if (uname && (uname != AT_UNNAMED)) free(uname); - if (rl) - free(rl); + free(rl); return err; } @@ -2004,7 +1996,7 @@ err_out: * add_attr_std_info * Return 0 on success or -errno on error. */ -static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, +static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, u32 security_id) { STANDARD_INFORMATION si; @@ -2024,7 +2016,7 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, si.version_number = cpu_to_le32(0); si.class_id = cpu_to_le32(0); si.security_id = security_id; - if (si.security_id != 0) + if (si.security_id != 0) sd_size = 72; /* FIXME: $Quota support... */ si.owner_id = cpu_to_le32(0); @@ -2127,23 +2119,23 @@ static int add_attr_file_name(MFT_RECORD *m, const MFT_REF parent_dir, */ static int add_attr_object_id(MFT_RECORD *m, OBJECT_ID_ATTR *objid_attr, - int objid_attr_len) + int objid_attr_len) { - int err; + int err; - /* Does it fit? NO: create non-resident. YES: create resident. */ - if (le32_to_cpu(m->bytes_in_use) + 24 + objid_attr_len > - le32_to_cpu(m->bytes_allocated)) - err = insert_non_resident_attr_in_mft_record(m, - AT_OBJECT_ID, NULL, 0, 0, 0, (u8*)objid_attr, - objid_attr_len); - else - err = insert_resident_attr_in_mft_record(m, - AT_OBJECT_ID, NULL, 0, 0, 0, 0, + /* Does it fit? NO: create non-resident. YES: create resident. */ + if (le32_to_cpu(m->bytes_in_use) + 24 + objid_attr_len > + le32_to_cpu(m->bytes_allocated)) + err = insert_non_resident_attr_in_mft_record(m, + AT_OBJECT_ID, NULL, 0, 0, 0, (u8*)objid_attr, + objid_attr_len); + else + err = insert_resident_attr_in_mft_record(m, + AT_OBJECT_ID, NULL, 0, 0, 0, 0, (u8*)objid_attr, objid_attr_len); - if (err < 0) - Eprintf("add_attr_volume_id failed: %s\n", strerror(-err)); - return err; + if (err < 0) + Eprintf("add_attr_volume_id failed: %s\n", strerror(-err)); + return err; } @@ -2267,8 +2259,7 @@ static int add_attr_vol_name(MFT_RECORD *m, const char *vol_name, } i = insert_resident_attr_in_mft_record(m, AT_VOLUME_NAME, NULL, 0, 0, 0, 0, (u8*)uname, len); - if (uname) - free(uname); + free(uname); if (i < 0) Eprintf("add_attr_vol_name failed: %s\n", strerror(-i)); return i; @@ -2477,21 +2468,18 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, ctx = ntfs_attr_get_search_ctx(NULL, m); if (!ctx) { Eprintf("Failed to allocate attribute search context.\n"); - if (uname) - free(uname); + free(uname); return -ENOMEM; } if (ic == IGNORE_CASE) { Eprintf("FIXME: Hit unimplemented code path #4.\n"); err = -EOPNOTSUPP; - if (uname) - free(uname); + free(uname); goto err_out; } err = mkntfs_attr_lookup(AT_INDEX_ROOT, uname, name_len, ic, 0, NULL, 0, ctx); - if (uname) - free(uname); + free(uname); if (err) { err = -ENOTDIR; goto err_out; @@ -2599,8 +2587,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, err_out: if (ctx) ntfs_attr_put_search_ctx(ctx); - if (ia_val) - free(ia_val); + free(ia_val); return err; } @@ -2657,13 +2644,13 @@ static int make_room_for_index_entry_in_index_block(INDEX_BLOCK *idx, /* * ntfs_index_keys_compare(char *key1, char *key2, - * COLLATION_RULES *collation_rule) + * COLLATION_RULES *collation_rule) * not alle types of COLLATION_RULES supported yet... * added as needed.. (remove this comment when all is added) - */ + */ -static int ntfs_index_keys_compare(char *key1, char *key2, - int key1_length,int key2_length, +static int ntfs_index_keys_compare(char *key1, char *key2, + int key1_length,int key2_length, COLLATION_RULES collation_rule) { int i, j; @@ -2673,73 +2660,73 @@ static int ntfs_index_keys_compare(char *key1, char *key2, if (collation_rule == COLLATION_NTOFS_ULONG) { //i.e. $SII or $QUOTA-$Q while ((j < min(key1_length, key2_length)) && (i == 0)) { - if (*(u32*)(key1 + j) < *(u32*)(key2 + j)) i = -1; - if (*(u32*)(key1 + j) > *(u32*)(key2 + j)) i = +1; - if (*(u32*)(key1 + j) == *(u32*)(key2 + j)) { + if (*(u32*)(key1 + j) < *(u32*)(key2 + j)) i = -1; + if (*(u32*)(key1 + j) > *(u32*)(key2 + j)) i = +1; + if (*(u32*)(key1 + j) == *(u32*)(key2 + j)) { i = 0; j += 4; - } + } } if ((i == 0) && (key1_length > key2_length)) i = -1; if ((i == 0) && (key1_length < key2_length)) i = +1; - return i; + return i; } if (collation_rule == COLLATION_NTOFS_ULONGS) { //i.e $OBJID-$O - while ((j < min(key1_length, key2_length)) && (i == 0)) { - if (bswap_32(*(u32*)(key1 + j)) < + while ((j < min(key1_length, key2_length)) && (i == 0)) { + if (bswap_32(*(u32*)(key1 + j)) < bswap_32(*(u32*)(key1 + j))) i = -1; - if (bswap_32(*(u32*)(key1 + j)) > + if (bswap_32(*(u32*)(key1 + j)) > bswap_32(*(u32*)(key1 + j))) i = +1; - if (bswap_32(*(u32*)(key1 + j)) == + if (bswap_32(*(u32*)(key1 + j)) == bswap_32(*(u32*)(key1 + j))) { - i = 0; - j += 4; - } - } - if ((i == 0) && (key1_length > key2_length)) i = -1; - if ((i == 0) && (key1_length < key2_length)) i = +1; + i = 0; + j += 4; + } + } + if ((i == 0) && (key1_length > key2_length)) i = -1; + if ((i == 0) && (key1_length < key2_length)) i = +1; - return i; + return i; } if (collation_rule == COLLATION_NTOFS_SECURITY_HASH) { //i.e. $SDH if (((SDH_INDEX_KEY*)key1)->hash < ((SDH_INDEX_KEY*)key2)->hash) i = -1; if (((SDH_INDEX_KEY*)key1)->hash > - ((SDH_INDEX_KEY*)key2)->hash) i = +1; - if (((SDH_INDEX_KEY*)key1)->hash == + ((SDH_INDEX_KEY*)key2)->hash) i = +1; + if (((SDH_INDEX_KEY*)key1)->hash == ((SDH_INDEX_KEY*)key2)->hash) { if (((SDH_INDEX_KEY*)key1)->security_id < ((SDH_INDEX_KEY*)key2)->security_id) i = -1; if (((SDH_INDEX_KEY*)key1)->security_id > ((SDH_INDEX_KEY*)key2)->security_id) i = +1; - if (((SDH_INDEX_KEY*)key1)->security_id == + if (((SDH_INDEX_KEY*)key1)->security_id == ((SDH_INDEX_KEY*)key2)->security_id) i = 0; } - return i; + return i; } - if (collation_rule == COLLATION_NTOFS_SID ) { + if (collation_rule == COLLATION_NTOFS_SID ) { //i.e. $QUOTA-O i = memcmp(key1, key2, min(key1_length, key2_length)); - if ((i == 0) && (key1_length > key2_length)) i = -1; - if ((i == 0) && (key1_length < key2_length)) i = +1; + if ((i == 0) && (key1_length > key2_length)) i = -1; + if ((i == 0) && (key1_length < key2_length)) i = +1; return i; } - err_exit("ntfs_index_keys_compare called without supported " + err_exit("ntfs_index_keys_compare called without supported " "collation rule.\n"); } /** - * insert_index_entry_in_res_dir_index + * insert_index_entry_in_res_dir_index * i.e. insert an index_entry in some named index_root - * simplified search method, works for mkntfs + * simplified search method, works for mkntfs */ -static int insert_index_entry_in_res_dir_index(INDEX_ENTRY *idx, +static int insert_index_entry_in_res_dir_index(INDEX_ENTRY *idx, u32 idx_size, MFT_RECORD *m, ntfschar *name, u32 name_size, ATTR_TYPES type) { @@ -2750,90 +2737,90 @@ static int insert_index_entry_in_res_dir_index(INDEX_ENTRY *idx, COLLATION_RULES collation_rule; int err, i; - err = 0; + err = 0; /* does it fit ?*/ if ( vol->mft_record_size > idx_size + m->bytes_allocated ) return -ENOSPC; /* find the INDEX_ROOT attribute:*/ ctx = ntfs_attr_get_search_ctx(NULL, m); - if (!ctx) { - Eprintf("Failed to allocate attribute search context.\n"); - err = -ENOMEM; - goto err_out; - } - if (ntfs_attr_lookup(AT_INDEX_ROOT, name, name_size, 0, 0, + if (!ctx) { + Eprintf("Failed to allocate attribute search context.\n"); + err = -ENOMEM; + goto err_out; + } + if (ntfs_attr_lookup(AT_INDEX_ROOT, name, name_size, 0, 0, NULL, 0, ctx)) { - err = EEXIST; - goto err_out; - } + err = EEXIST; + goto err_out; + } /* found attribute */ a = (ATTR_RECORD*)ctx->attr; - collation_rule = ((INDEX_ROOT*)((char*)a + + collation_rule = ((INDEX_ROOT*)((char*)a + le16_to_cpu(a->value_offset)))->collation_rule; - idx_header = (INDEX_HEADER*)((char*)a + le16_to_cpu(a->value_offset) + idx_header = (INDEX_HEADER*)((char*)a + le16_to_cpu(a->value_offset) + le16_to_cpu(0x10)); - idx_entry = (INDEX_ENTRY*)((char*)idx_header + - le16_to_cpu((idx_header)->entries_offset)); - idx_end = (INDEX_ENTRY*)((char*)idx_entry + + idx_entry = (INDEX_ENTRY*)((char*)idx_header + + le16_to_cpu((idx_header)->entries_offset)); + idx_end = (INDEX_ENTRY*)((char*)idx_entry + le32_to_cpu(idx_header->index_length)); /* - * Loop until we exceed valid memory (corruption case) or until we - * reach the last entry. - */ + * Loop until we exceed valid memory (corruption case) or until we + * reach the last entry. + */ - if (type == AT_FILE_NAME) { - while ((char*)idx_entry < (char*)idx_end && + if (type == AT_FILE_NAME) { + while ((char*)idx_entry < (char*)idx_end && !(idx_entry->flags & INDEX_ENTRY_END)) { - i = ntfs_file_values_compare( + i = ntfs_file_values_compare( (FILE_NAME_ATTR*)&idx->key.file_name, - (FILE_NAME_ATTR*)&idx_entry->key.file_name, 1, - IGNORE_CASE, vol->upcase, vol->upcase_len); - /* - * If @file_name collates before ie->key.file_name, + (FILE_NAME_ATTR*)&idx_entry->key.file_name, 1, + IGNORE_CASE, vol->upcase, vol->upcase_len); + /* + * If @file_name collates before ie->key.file_name, * there is no - * matching index entry. - */ - if (i == -1) - break; - /* If file names are not equal, continue search. */ - if (i) - goto do_next; - if (((FILE_NAME_ATTR*)&idx->key.file_name)->\ + * matching index entry. + */ + if (i == -1) + break; + /* If file names are not equal, continue search. */ + if (i) + goto do_next; + if (((FILE_NAME_ATTR*)&idx->key.file_name)->\ file_name_type != FILE_NAME_POSIX || - idx_entry->key.file_name.file_name_type + idx_entry->key.file_name.file_name_type != FILE_NAME_POSIX) - return -EEXIST; - - i = ntfs_file_values_compare((FILE_NAME_ATTR*)&idx-> + return -EEXIST; + + i = ntfs_file_values_compare((FILE_NAME_ATTR*)&idx-> key.file_name, - (FILE_NAME_ATTR*)&idx_entry->key.file_name, 1, - CASE_SENSITIVE, vol->upcase, vol->upcase_len); - if (i == -1) - break; - /* Complete match. Bugger. Can't insert. */ - /*if (!i) - return -EEXIST; - */ + (FILE_NAME_ATTR*)&idx_entry->key.file_name, 1, + CASE_SENSITIVE, vol->upcase, vol->upcase_len); + if (i == -1) + break; + /* Complete match. Bugger. Can't insert. */ + /*if (!i) + return -EEXIST; + */ do_next: - idx_entry = (INDEX_ENTRY*)((char*)idx_entry + + idx_entry = (INDEX_ENTRY*)((char*)idx_entry + le16_to_cpu(idx_entry->length)); } } else if (type == AT_UNUSED) { // case view while ((char*)idx_entry < (char*)idx_end && !(idx_entry->flags & INDEX_ENTRY_END)) { i = ntfs_index_keys_compare((char*)idx_entry + 0x10, - (char*)idx + 0x10, + (char*)idx + 0x10, idx_entry->key_length, idx->key_length, collation_rule); if (!i) { return -EEXIST; } if (i == 1) break; - idx_entry = (INDEX_ENTRY*)((char*)idx_entry + - le16_to_cpu(idx_entry->length)); - } - } else return EINVAL; + idx_entry = (INDEX_ENTRY*)((char*)idx_entry + + le16_to_cpu(idx_entry->length)); + } + } else return EINVAL; memmove((char*)idx_entry + idx_size, (char*)idx_entry, (char*)m + vol->mft_record_size - @@ -2843,13 +2830,13 @@ do_next: m->bytes_in_use += idx_size; a->length += idx_size; a->value_length += idx_size; - ((INDEX_HEADER*)idx_header)->index_length += idx_size; + ((INDEX_HEADER*)idx_header)->index_length += idx_size; ((INDEX_HEADER*)idx_header)->allocated_size += idx_size; err_out: - if (ctx) - ntfs_attr_put_search_ctx(ctx); - return err; + if (ctx) + ntfs_attr_put_search_ctx(ctx); + return err; } /** @@ -2867,11 +2854,11 @@ static int initialize_secure(char *sds, u32 sds_size, MFT_RECORD *m) { sds_header = (SECURITY_DESCRIPTOR_HEADER*)sds; sdh_size = cpu_to_le32(0x30); - sii_size = cpu_to_le32(0x28); + sii_size = cpu_to_le32(0x28); idx_entry_sdh = (INDEX_ENTRY*)calloc(1, sizeof(INDEX_ENTRY)); idx_entry_sii = (INDEX_ENTRY*)calloc(1, sizeof(INDEX_ENTRY)); err = 0; - + while ( (char*)sds_header < (char*)sds + sds_size) { //SDH index entry idx_entry_sdh->data_offset = cpu_to_le16(0x18); @@ -2879,64 +2866,64 @@ static int initialize_secure(char *sds, u32 sds_size, MFT_RECORD *m) { idx_entry_sdh->reservedV = cpu_to_le32(0x00); idx_entry_sdh->length = cpu_to_le16(0x30); idx_entry_sdh->key_length = cpu_to_le16(0x08); - idx_entry_sdh->flags = cpu_to_le16(0x00); - idx_entry_sdh->reserved = cpu_to_le16(0x00); + idx_entry_sdh->flags = cpu_to_le16(0x00); + idx_entry_sdh->reserved = cpu_to_le16(0x00); idx_entry_sdh->key.sdh.hash = sds_header->hash; idx_entry_sdh->key.sdh.security_id = sds_header->security_id; - sdh_data = (SDH_INDEX_DATA*)((char*)idx_entry_sdh + + sdh_data = (SDH_INDEX_DATA*)((char*)idx_entry_sdh + idx_entry_sdh->data_offset); sdh_data->hash = sds_header->hash; sdh_data->security_id = sds_header->security_id; sdh_data->offset_in_sds = sds_header->offset; - + sdh_data->size_in_sds = sds_header->length; - sdh_data->reserved_II = cpu_to_le64(0x00490049); + sdh_data->reserved_II = cpu_to_le64(0x00490049); //SII index entry idx_entry_sii->data_offset = cpu_to_le16(0x14); - idx_entry_sii->data_length = cpu_to_le16(0x14); - idx_entry_sii->reservedV = cpu_to_le32(0x00); - idx_entry_sii->length = cpu_to_le16(0x28); - idx_entry_sii->key_length = cpu_to_le16(0x04); - idx_entry_sii->flags = cpu_to_le16(0x00); - idx_entry_sii->reserved = cpu_to_le16(0x00); - idx_entry_sii->key.sii.security_id = sds_header->security_id; + idx_entry_sii->data_length = cpu_to_le16(0x14); + idx_entry_sii->reservedV = cpu_to_le32(0x00); + idx_entry_sii->length = cpu_to_le16(0x28); + idx_entry_sii->key_length = cpu_to_le16(0x04); + idx_entry_sii->flags = cpu_to_le16(0x00); + idx_entry_sii->reserved = cpu_to_le16(0x00); + idx_entry_sii->key.sii.security_id = sds_header->security_id; sii_data = (SII_INDEX_DATA*)((char*)idx_entry_sii + idx_entry_sii->data_offset); - sii_data->hash = sds_header->hash; + sii_data->hash = sds_header->hash; sii_data->security_id = sds_header->security_id; sii_data->offset_in_sds = sds_header->offset; sii_data->size_in_sds = sds_header->length; if ((err = insert_index_entry_in_res_dir_index(idx_entry_sdh, sdh_size, m, - SDH, 4, AT_UNUSED))) + SDH, 4, AT_UNUSED))) break; - + if ((err = insert_index_entry_in_res_dir_index(idx_entry_sii, sii_size, m, - SII, 4, AT_UNUSED))) - break; + SII, 4, AT_UNUSED))) + break; sds_header = (SECURITY_DESCRIPTOR_HEADER*)((char*)sds_header + (cpu_to_le32(sds_header->length + 0x0F) & ~cpu_to_le32(0x0F))); - if (!sds_header->length) + if (!sds_header->length) break; } - if(idx_entry_sdh) free(idx_entry_sdh); - if(idx_entry_sii) free(idx_entry_sii); + free(idx_entry_sdh); + free(idx_entry_sii); return err; } /* - * initialize_quota(MFT_RECORD *m) + * initialize_quota(MFT_RECORD *m) * initialize $Quota with the default quota index-entries. */ static int initialize_quota(MFT_RECORD *m) { - + int o_size, q1_size, q2_size, err; INDEX_ENTRY *idx_entry_o, *idx_entry_q1, *idx_entry_q2; QUOTA_O_INDEX_DATA *idx_entry_o_data; @@ -2946,50 +2933,50 @@ static int initialize_quota(MFT_RECORD *m) { q1_size = cpu_to_le32(0x48); q2_size = cpu_to_le32(0x58); - idx_entry_o = (INDEX_ENTRY*)calloc(1, o_size); + idx_entry_o = (INDEX_ENTRY*)calloc(1, o_size); idx_entry_q1 = (INDEX_ENTRY*)calloc(1, q1_size); idx_entry_q2 = (INDEX_ENTRY*)calloc(1, q2_size); - idx_entry_o->data_offset = cpu_to_le16(0x20); - idx_entry_o->data_length = cpu_to_le16(0x04); - idx_entry_o->reservedV = cpu_to_le32(0x00); - idx_entry_o->length = cpu_to_le16(0x28); - idx_entry_o->key_length = cpu_to_le16(0x10); - idx_entry_o->flags = cpu_to_le16(0x00); - idx_entry_o->reserved = cpu_to_le16(0x00); - idx_entry_o->key.sid.revision = 0x01; + idx_entry_o->data_offset = cpu_to_le16(0x20); + idx_entry_o->data_length = cpu_to_le16(0x04); + idx_entry_o->reservedV = cpu_to_le32(0x00); + idx_entry_o->length = cpu_to_le16(0x28); + idx_entry_o->key_length = cpu_to_le16(0x10); + idx_entry_o->flags = cpu_to_le16(0x00); + idx_entry_o->reserved = 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 = + idx_entry_o->key.sid.identifier_authority.high_part = cpu_to_le16(0x0000); - idx_entry_o->key.sid.identifier_authority.low_part = + idx_entry_o->key.sid.identifier_authority.low_part = cpu_to_le32(0x05000000); idx_entry_o->key.sid.sub_authority[0] = cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - idx_entry_o->key.sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - idx_entry_o_data = (QUOTA_O_INDEX_DATA*)((char*)idx_entry_o - + idx_entry_o->data_offset); - idx_entry_o_data->owner_id = QUOTA_FIRST_USER_ID; + idx_entry_o->key.sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + idx_entry_o_data = (QUOTA_O_INDEX_DATA*)((char*)idx_entry_o + + idx_entry_o->data_offset); + idx_entry_o_data->owner_id = QUOTA_FIRST_USER_ID; // 20 00 00 00 padding after here on ntfs 3.1 ?? err = insert_index_entry_in_res_dir_index(idx_entry_o, - o_size, m, - O, 2, AT_UNUSED); - if (idx_entry_o) free(idx_entry_o); - if (err) return err; + o_size, m, + O, 2, AT_UNUSED); + free(idx_entry_o); + if (err) return err; //q index entry nr. 1 - idx_entry_q1->data_offset = cpu_to_le16(0x14); - idx_entry_q1->data_length = cpu_to_le16(0x30); - idx_entry_q1->reservedV = cpu_to_le32(0x00); - idx_entry_q1->length = cpu_to_le16(0x48); - idx_entry_q1->key_length = cpu_to_le16(0x04); - idx_entry_q1->flags = cpu_to_le16(0x00); - idx_entry_q1->reserved = cpu_to_le16(0x00); - idx_entry_q1->key.owner_id = cpu_to_le16(0x01); - idx_entry_q1_data = (QUOTA_CONTROL_ENTRY*)((char*)idx_entry_q1 - + idx_entry_q1->data_offset); - idx_entry_q1_data->version = cpu_to_le32(0x02); + idx_entry_q1->data_offset = cpu_to_le16(0x14); + idx_entry_q1->data_length = cpu_to_le16(0x30); + idx_entry_q1->reservedV = cpu_to_le32(0x00); + idx_entry_q1->length = cpu_to_le16(0x48); + idx_entry_q1->key_length = cpu_to_le16(0x04); + idx_entry_q1->flags = cpu_to_le16(0x00); + idx_entry_q1->reserved = cpu_to_le16(0x00); + idx_entry_q1->key.owner_id = cpu_to_le16(0x01); + idx_entry_q1_data = (QUOTA_CONTROL_ENTRY*)((char*)idx_entry_q1 + + idx_entry_q1->data_offset); + idx_entry_q1_data->version = cpu_to_le32(0x02); idx_entry_q1_data->flags = QUOTA_FLAG_DEFAULT_LIMITS; if (vol->minor_ver == 0) idx_entry_q1_data->flags |= QUOTA_FLAG_OUT_OF_DATE; @@ -2997,54 +2984,54 @@ static int initialize_quota(MFT_RECORD *m) { idx_entry_q1_data->change_time = utc2ntfs(time(NULL)); idx_entry_q1_data->threshold = cpu_to_sle64(-0x01); idx_entry_q1_data->limit = cpu_to_sle64(-0x01); - idx_entry_q1_data->exceeded_time = cpu_to_sle64(0x00); + idx_entry_q1_data->exceeded_time = cpu_to_sle64(0x00); - err = insert_index_entry_in_res_dir_index(idx_entry_q1, - q1_size, m, - Q, 2, AT_UNUSED); - if (idx_entry_q1) free(idx_entry_q1); - if (err) return err; + err = insert_index_entry_in_res_dir_index(idx_entry_q1, + q1_size, m, + Q, 2, AT_UNUSED); + free(idx_entry_q1); + if (err) return err; - //q index entry nr. 2 - idx_entry_q2->data_offset = cpu_to_le16(0x14); - idx_entry_q2->data_length = cpu_to_le16(0x40); - idx_entry_q2->reservedV = cpu_to_le32(0x00); - idx_entry_q2->length = cpu_to_le16(0x58); - idx_entry_q2->key_length = cpu_to_le16(0x04); - idx_entry_q2->flags = cpu_to_le16(0x00); - idx_entry_q2->reserved = cpu_to_le16(0x00); - idx_entry_q2->key.owner_id = QUOTA_FIRST_USER_ID; - idx_entry_q2_data = (QUOTA_CONTROL_ENTRY*)((char*)idx_entry_q2 - + idx_entry_q2->data_offset); - idx_entry_q2_data->version = cpu_to_le32(0x02); - idx_entry_q2_data->flags = QUOTA_FLAG_DEFAULT_LIMITS; - idx_entry_q2_data->bytes_used = cpu_to_le64(0x00); - idx_entry_q2_data->change_time = utc2ntfs(time(NULL));; - idx_entry_q2_data->threshold = cpu_to_sle64(-0x01); - idx_entry_q2_data->limit = cpu_to_sle64(-0x01); - idx_entry_q2_data->exceeded_time = cpu_to_sle64(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 = + //q index entry nr. 2 + idx_entry_q2->data_offset = cpu_to_le16(0x14); + idx_entry_q2->data_length = cpu_to_le16(0x40); + idx_entry_q2->reservedV = cpu_to_le32(0x00); + idx_entry_q2->length = cpu_to_le16(0x58); + idx_entry_q2->key_length = cpu_to_le16(0x04); + idx_entry_q2->flags = cpu_to_le16(0x00); + idx_entry_q2->reserved = cpu_to_le16(0x00); + idx_entry_q2->key.owner_id = QUOTA_FIRST_USER_ID; + idx_entry_q2_data = (QUOTA_CONTROL_ENTRY*)((char*)idx_entry_q2 + + idx_entry_q2->data_offset); + idx_entry_q2_data->version = cpu_to_le32(0x02); + idx_entry_q2_data->flags = QUOTA_FLAG_DEFAULT_LIMITS; + idx_entry_q2_data->bytes_used = cpu_to_le64(0x00); + idx_entry_q2_data->change_time = utc2ntfs(time(NULL));; + idx_entry_q2_data->threshold = cpu_to_sle64(-0x01); + idx_entry_q2_data->limit = cpu_to_sle64(-0x01); + idx_entry_q2_data->exceeded_time = cpu_to_sle64(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 = cpu_to_le16(0x0000); - idx_entry_q2_data->sid.identifier_authority.low_part = + idx_entry_q2_data->sid.identifier_authority.low_part = cpu_to_le32(0x05000000); - idx_entry_q2_data->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - idx_entry_q2_data->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + idx_entry_q2_data->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + idx_entry_q2_data->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + err = insert_index_entry_in_res_dir_index(idx_entry_q2, + q2_size, m, + Q, 2, AT_UNUSED); + free(idx_entry_q2); - err = insert_index_entry_in_res_dir_index(idx_entry_q2, - q2_size, m, - Q, 2, AT_UNUSED); - if (idx_entry_q2) free(idx_entry_q2); - return err; } /* - * initialize_objid(MFT_RECORD *m, GUID guid, const MFT_REF mref) + * initialize_objid(MFT_RECORD *m, GUID guid, const MFT_REF mref) * initialize $ObjId with the default index-entries. * It is one entry which belongs to $Volume. (W2k3) */ @@ -3056,27 +3043,27 @@ static int initialize_objid(MFT_RECORD *m, GUID guid, const MFT_REF mref) { OBJ_ID_INDEX_DATA *idx_entry_o_data; err = 0; - o_size = cpu_to_le32(0x58); - idx_entry_o = (INDEX_ENTRY*)calloc(1, o_size); + o_size = cpu_to_le32(0x58); + idx_entry_o = (INDEX_ENTRY*)calloc(1, o_size); //o index entry idx_entry_o->data_offset = cpu_to_le16(0x20); - idx_entry_o->data_length = cpu_to_le16(0x38); - idx_entry_o->reservedV = cpu_to_le32(0x00); - idx_entry_o->length = cpu_to_le16(0x58); - idx_entry_o->key_length = cpu_to_le16(0x10); - idx_entry_o->flags = cpu_to_le16(0x00); - idx_entry_o->reserved = cpu_to_le16(0x00); + idx_entry_o->data_length = cpu_to_le16(0x38); + idx_entry_o->reservedV = cpu_to_le32(0x00); + idx_entry_o->length = cpu_to_le16(0x58); + idx_entry_o->key_length = cpu_to_le16(0x10); + idx_entry_o->flags = cpu_to_le16(0x00); + idx_entry_o->reserved = cpu_to_le16(0x00); idx_entry_o->key.object_id = guid; idx_entry_o_data = (OBJ_ID_INDEX_DATA*)((char*)idx_entry_o + idx_entry_o->data_offset); idx_entry_o_data->mft_reference = mref; idx_entry_o_data->birth_volume_id = *zero_guid; - idx_entry_o_data->birth_object_id = *zero_guid; - idx_entry_o_data->domain_id = *zero_guid; + idx_entry_o_data->birth_object_id = *zero_guid; + idx_entry_o_data->domain_id = *zero_guid; err = insert_index_entry_in_res_dir_index(idx_entry_o, - o_size, m, - O, 2, AT_UNUSED); + o_size, m, + O, 2, AT_UNUSED); if (idx_entry_o) free (idx_entry_o); return err; @@ -3225,103 +3212,103 @@ do_next: */ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent, - MFT_RECORD *m_file, const MFT_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, - const FILE_NAME_TYPE_FLAGS file_name_type) + MFT_RECORD *m_file, const MFT_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, + const FILE_NAME_TYPE_FLAGS file_name_type) { - FILE_NAME_ATTR *fn; - int i, fn_size, idx_size; + FILE_NAME_ATTR *fn; + int i, fn_size, idx_size; INDEX_ENTRY *idx_entry_new; - /* Create the file_name attribute. */ - i = (strlen(file_name) + 1) * sizeof(ntfschar); - fn_size = sizeof(FILE_NAME_ATTR) + i; - fn = (FILE_NAME_ATTR*)malloc(fn_size); - if (!fn) - return -errno; - fn->parent_directory = ref_parent; - // FIXME: Is this correct? Or do we have to copy the creation_time - // from the std info? - fn->creation_time = utc2ntfs(time(NULL)); - 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->file_attributes = flags; - /* These are in a union so can't have both. */ - if (packed_ea_size && reparse_point_tag) { - free(fn); - return -EINVAL; - } - if (packed_ea_size) { - free(fn); - return -EINVAL; - } - if (packed_ea_size) { - fn->packed_ea_size = cpu_to_le16(packed_ea_size); - fn->reserved = cpu_to_le16(0); - } else - fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); - fn->file_name_type = file_name_type; - i = stoucs(fn->file_name, file_name, i); - if (i < 1) { - free(fn); - return -EINVAL; - } - if (i > 0xff) { - free(fn); - return -ENAMETOOLONG; - } - /* No terminating null in file names. */ - fn->file_name_length = i; - fn_size = sizeof(FILE_NAME_ATTR) + i * sizeof(ntfschar); - /* Increment the link count of @m_file. */ - i = le16_to_cpu(m_file->link_count); - if (i == 0xffff) { - Eprintf("Too many hardlinks present already.\n"); - free(fn); - return -EINVAL; - } - m_file->link_count = cpu_to_le16(i + 1); - /* Add the file_name to @m_file. */ - i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, 0, - 0, RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size); - if (i < 0) { - Eprintf("create_hardlink failed adding file name attribute: " - "%s\n", strerror(-i)); - free(fn); - /* Undo link count increment. */ - m_file->link_count = cpu_to_le16( - le16_to_cpu(m_file->link_count) - 1); - return i; - } - /* Insert the index entry for file_name in @idx. */ + /* Create the file_name attribute. */ + i = (strlen(file_name) + 1) * sizeof(ntfschar); + fn_size = sizeof(FILE_NAME_ATTR) + i; + fn = (FILE_NAME_ATTR*)malloc(fn_size); + if (!fn) + return -errno; + fn->parent_directory = ref_parent; + // FIXME: Is this correct? Or do we have to copy the creation_time + // from the std info? + fn->creation_time = utc2ntfs(time(NULL)); + 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->file_attributes = flags; + /* These are in a union so can't have both. */ + if (packed_ea_size && reparse_point_tag) { + free(fn); + return -EINVAL; + } + if (packed_ea_size) { + free(fn); + return -EINVAL; + } + if (packed_ea_size) { + fn->packed_ea_size = cpu_to_le16(packed_ea_size); + fn->reserved = cpu_to_le16(0); + } else + fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); + fn->file_name_type = file_name_type; + i = stoucs(fn->file_name, file_name, i); + if (i < 1) { + free(fn); + return -EINVAL; + } + if (i > 0xff) { + free(fn); + return -ENAMETOOLONG; + } + /* No terminating null in file names. */ + fn->file_name_length = i; + fn_size = sizeof(FILE_NAME_ATTR) + i * sizeof(ntfschar); + /* Increment the link count of @m_file. */ + i = le16_to_cpu(m_file->link_count); + if (i == 0xffff) { + Eprintf("Too many hardlinks present already.\n"); + free(fn); + return -EINVAL; + } + m_file->link_count = cpu_to_le16(i + 1); + /* Add the file_name to @m_file. */ + i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, 0, + 0, RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size); + if (i < 0) { + Eprintf("create_hardlink failed adding file name attribute: " + "%s\n", strerror(-i)); + free(fn); + /* Undo link count increment. */ + m_file->link_count = cpu_to_le16( + le16_to_cpu(m_file->link_count) - 1); + return i; + } + /* Insert the index entry for file_name in @idx. */ //remmet ut kun for debugging idx_size = (fn_size + 7) & ~7; idx_entry_new = (INDEX_ENTRY*)calloc(1, idx_size + 0x10); idx_entry_new->indexed_file = ref_file; idx_entry_new->length = idx_size + 0x10; - idx_entry_new->key_length = fn_size; + idx_entry_new->key_length = fn_size; memcpy((char*)idx_entry_new+0x10, (char*)fn, fn_size); i = insert_index_entry_in_res_dir_index(idx_entry_new, idx_size + 0x10 , m_parent, I30, 4, AT_FILE_NAME); - if (i < 0) { - Eprintf("create_hardlink failed inserting index entry: %s\n", - strerror(-i)); - /* FIXME: Remove the file name attribute from @m_file. */ - free(fn); - /* Undo link count increment. */ - m_file->link_count = cpu_to_le16( - le16_to_cpu(m_file->link_count) - 1); - return i; - } + if (i < 0) { + Eprintf("create_hardlink failed inserting index entry: %s\n", + strerror(-i)); + /* FIXME: Remove the file name attribute from @m_file. */ + free(fn); + /* Undo link count increment. */ + m_file->link_count = cpu_to_le16( + le16_to_cpu(m_file->link_count) - 1); + return i; + } free(fn); - return 0; + return 0; } - + /** * create_hardlink * Create a file_name_attribute in the mft record @m_file which points to the @@ -3429,8 +3416,8 @@ static void init_options(void) opts.heads = -1; opts.part_start_sect = -1; opts.index_block_size = 4096; - opts.attr_defs = (ATTR_DEF*)&attrdef_ntfs12_array; - opts.attr_defs_len = sizeof(attrdef_ntfs12_array); + opts.attr_defs = (ATTR_DEF*)&attrdef_ntfs12_array; + opts.attr_defs_len = sizeof(attrdef_ntfs12_array); //mkDprintf("Attr_defs table length = %u\n", opts.attr_defs_len); } @@ -3439,43 +3426,27 @@ static void init_options(void) */ static void mkntfs_exit(void) { - if (index_block) - free(index_block); - if (buf_sds_init) - free(buf_sds_init); - if (buf_sds) - free(buf_sds); - if (buf) - free(buf); - if (buf2) - free(buf2); - if (lcn_bitmap) - free(lcn_bitmap); - if (mft_bitmap) - free(mft_bitmap); - if (rl_mft) - free(rl_mft); - if (rl_mft_bmp) - free(rl_mft_bmp); - if (rl_mftmirr) - free(rl_mftmirr); - if (rl_logfile) - free(rl_logfile); - if (rl_boot) - free(rl_boot); - if (rl_bad) - free(rl_bad); - if (rl_index) - free(rl_index); - if (opts.bad_blocks) - free(opts.bad_blocks); + free(index_block); + free(buf_sds_init); + free(buf_sds); + free(buf); + free(buf2); + free(lcn_bitmap); + free(mft_bitmap); + free(rl_mft); + free(rl_mft_bmp); + free(rl_mftmirr); + free(rl_logfile); + free(rl_boot); + free(rl_bad); + free(rl_index); + free(opts.bad_blocks); if ((opts.attr_defs != (const ATTR_DEF*)attrdef_ntfs12_array) && (opts.attr_defs != (const ATTR_DEF*)attrdef_ntfs3x_array)) free(opts.attr_defs); if (!vol) return; - if (vol->upcase) - free(vol->upcase); + free(vol->upcase); if (vol->dev) { if (NDevOpen(vol->dev) && vol->dev->d_ops->close(vol->dev)) Eprintf("Warning: Could not close %s: %s\n", @@ -3819,11 +3790,11 @@ static void mkntfs_initialize_bitmaps(void) for (i = opts.nr_clusters; i < lcn_bitmap_byte_size << 3; i++) ntfs_bit_set(lcn_bitmap, (u64)i, 1); /* - * Determine mft_size: (16 (1.2) or 28 (3.0+) mft records) or + * Determine mft_size: (16 (1.2) or 28 (3.0+) mft records) or * 1 cluster, which ever is bigger, rounded to multiples of cluster * size */ - opts.mft_size = ((16 + 12 * (vol->major_ver >= 3)) * + opts.mft_size = ((16 + 12 * (vol->major_ver >= 3)) * vol->mft_record_size + vol->cluster_size - 1) & ~(vol->cluster_size - 1); mkDprintf("MFT size = %i (0x%x) bytes\n", opts.mft_size, opts.mft_size); @@ -4139,54 +4110,54 @@ static void mkntfs_fill_device_with_zeroes(void) Qprintf(" - Done.\n"); } -/** +/** * mkntfs_sync_index_record - * (ERSO) made a function out of this, but the reason for doing that - * disapeared during coding.... + * (ERSO) made a function out of this, but the reason for doing that + * disapeared during coding.... */ -static void mkntfs_sync_index_record(INDEX_ALLOCATION* idx, MFT_RECORD* m, +static void mkntfs_sync_index_record(INDEX_ALLOCATION* idx, MFT_RECORD* m, ntfschar* name, u32 name_len) { - int i, err; - ntfs_attr_search_ctx *ctx; - ATTR_RECORD *a; - long long lw; - i = 5 * sizeof(ntfschar); - ctx = ntfs_attr_get_search_ctx(NULL, m); + int i, err; + ntfs_attr_search_ctx *ctx; + ATTR_RECORD *a; + long long lw; + i = 5 * sizeof(ntfschar); + ctx = ntfs_attr_get_search_ctx(NULL, m); - if (!ctx) - err_exit("Failed to allocate attribute search context: %s\n", - strerror(errno)); - // FIXME: This should be IGNORE_CASE! - if (mkntfs_attr_lookup(AT_INDEX_ALLOCATION, name, name_len, 0, 0, - NULL, 0, ctx)) { - ntfs_attr_put_search_ctx(ctx); - err_exit("BUG: $INDEX_ALLOCATION attribute not found.\n"); - } - a = ctx->attr; - rl_index = ntfs_mapping_pairs_decompress(vol, a, NULL); - if (!rl_index) { - ntfs_attr_put_search_ctx(ctx); - err_exit("Failed to decompress runlist of $INDEX_ALLOCATION " - "attribute.\n"); - } - if (sle64_to_cpu(a->initialized_size) < i) { - ntfs_attr_put_search_ctx(ctx); - err_exit("BUG: $INDEX_ALLOCATION attribute too short.\n"); - } - ntfs_attr_put_search_ctx(ctx); - i = sizeof(INDEX_BLOCK) - sizeof(INDEX_HEADER) + - le32_to_cpu(idx->index.allocated_size); - err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)idx, i); - if (err) - err_exit("ntfs_mst_pre_write_fixup() failed while " + if (!ctx) + err_exit("Failed to allocate attribute search context: %s\n", + strerror(errno)); + // FIXME: This should be IGNORE_CASE! + if (mkntfs_attr_lookup(AT_INDEX_ALLOCATION, name, name_len, 0, 0, + NULL, 0, ctx)) { + ntfs_attr_put_search_ctx(ctx); + err_exit("BUG: $INDEX_ALLOCATION attribute not found.\n"); + } + a = ctx->attr; + rl_index = ntfs_mapping_pairs_decompress(vol, a, NULL); + if (!rl_index) { + ntfs_attr_put_search_ctx(ctx); + err_exit("Failed to decompress runlist of $INDEX_ALLOCATION " + "attribute.\n"); + } + if (sle64_to_cpu(a->initialized_size) < i) { + ntfs_attr_put_search_ctx(ctx); + err_exit("BUG: $INDEX_ALLOCATION attribute too short.\n"); + } + ntfs_attr_put_search_ctx(ctx); + i = sizeof(INDEX_BLOCK) - sizeof(INDEX_HEADER) + + le32_to_cpu(idx->index.allocated_size); + err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)idx, i); + if (err) + err_exit("ntfs_mst_pre_write_fixup() failed while " "syncing index block.\n"); - lw = ntfs_rlwrite(vol->dev, rl_index, (u8*)idx, i, NULL); - if (lw != i) - err_exit("Error writing $INDEX_ALLOCATION.\n"); - /* No more changes to @idx below here so no need for fixup: */ - // ntfs_mst_post_write_fixup((NTFS_RECORD*)idx); + lw = ntfs_rlwrite(vol->dev, rl_index, (u8*)idx, i, NULL); + if (lw != i) + err_exit("Error writing $INDEX_ALLOCATION.\n"); + /* No more changes to @idx below here so no need for fixup: */ + // ntfs_mst_post_write_fixup((NTFS_RECORD*)idx); } /** @@ -4301,43 +4272,43 @@ static void mkntfs_create_root_structures(void) * of that file (only for $MFT is the sequence number 1 rather than 0). */ for (i = 0; i < 16 + 12 * (vol->major_ver >= 3); i++) { - if (ntfs_mft_record_layout(vol, 0, m = (MFT_RECORD *)(buf + + if (ntfs_mft_record_layout(vol, 0, m = (MFT_RECORD *)(buf + i * vol->mft_record_size))) - err_exit("Error: Failed to layout mft record.\n"); + err_exit("Error: Failed to layout mft record.\n"); #if 0 - if (!opts.quiet && opts.verbose > 1) - dump_mft_record((MFT_RECORD*)buf + + if (!opts.quiet && opts.verbose > 1) + dump_mft_record((MFT_RECORD*)buf + i * vol->mft_record_size); -#endif - +#endif + if ( i > 0 ) m->sequence_number = cpu_to_le16(i); if ( i == 0) m->sequence_number = cpu_to_le16(1); } /* - * If a cluster contains more than the 16 (ntfs 1.2) or + * If a cluster contains more than the 16 (ntfs 1.2) or * 28 (ntfs 3.0+) system files, fill the rest * with empty, formatted records. */ - mft_total_cluster_size = vol->cluster_size * - (((16 + 12 * (vol->major_ver >= 3) -1) + mft_total_cluster_size = vol->cluster_size * + (((16 + 12 * (vol->major_ver >= 3) -1) * vol->mft_record_size) / vol->cluster_size + 1); - if (mft_total_cluster_size > (16 + 12 * (vol->major_ver >= 3))* + if (mft_total_cluster_size > (16 + 12 * (vol->major_ver >= 3))* vol->mft_record_size) { - for (i = 16 + 12 * (vol->major_ver >= 3); + for (i = 16 + 12 * (vol->major_ver >= 3); i * vol->mft_record_size < mft_total_cluster_size; i++) - { - if (ntfs_mft_record_layout(vol, 0, m = + { + if (ntfs_mft_record_layout(vol, 0, m = (MFT_RECORD *)(buf + i * vol->mft_record_size))) - err_exit("Error: Failed to layout mft" + err_exit("Error: Failed to layout mft" " record.\n"); #if 0 - if (!opts.quiet && opts.verbose > 1) - dump_mft_record((MFT_RECORD*)buf + + if (!opts.quiet && opts.verbose > 1) + dump_mft_record((MFT_RECORD*)buf + i * vol->mft_record_size); #endif m->flags = cpu_to_le16(0); - m->sequence_number = cpu_to_le16(i); - } + m->sequence_number = cpu_to_le16(i); + } } /* * Create the 16 system files, adding the system information attribute @@ -4348,7 +4319,7 @@ static void mkntfs_create_root_structures(void) m = (MFT_RECORD*)(buf + i * vol->mft_record_size); if (i < 16 || i > 23) { - if (vol->major_ver >= 3 && vol->minor_ver >= 1) + if (vol->major_ver >= 3 && vol->minor_ver >= 1) m->mft_record_number = cpu_to_le32(i); m->flags |= MFT_RECORD_IN_USE; ntfs_bit_set(mft_bitmap, 0LL + i, 1); @@ -4360,40 +4331,40 @@ static void mkntfs_create_root_structures(void) if (opts.enable_compression) file_attrs |= FILE_ATTR_COMPRESSED; } - - if (vol->major_ver < 3) - add_attr_std_info(m, file_attrs, + + if (vol->major_ver < 3) + add_attr_std_info(m, file_attrs, cpu_to_le32(0)); // dump_mft_record(m); else { - // setting specific security_id flag and - // filepermissions for ntfs 3.x - if (i == 0 || i == 1 || i == 2 || i == 6 || i == 8 || + // setting specific security_id flag and + // filepermissions for ntfs 3.x + if (i == 0 || i == 1 || i == 2 || i == 6 || i == 8 || i == 10 ) - add_attr_std_info(m, file_attrs, + add_attr_std_info(m, file_attrs, cpu_to_le32(0x0100)); else if (i == 9) { file_attrs |= FILE_ATTR_NOT_CONTENT_INDEXED; - add_attr_std_info(m, file_attrs, + add_attr_std_info(m, file_attrs, cpu_to_le32(0x0101)); } else if (i == 11) - add_attr_std_info(m, file_attrs, + add_attr_std_info(m, file_attrs, cpu_to_le32(0x0101)); else if (i ==24 || i == 25 || i == 26) { file_attrs |= FILE_ATTR_DUP_VIEW_INDEX_PRESENT; - add_attr_std_info(m, file_attrs, + add_attr_std_info(m, file_attrs, cpu_to_le32(0x0101)); } - else if (i == 27) - add_attr_std_info(m, file_attrs, + else if (i == 27) + add_attr_std_info(m, file_attrs, cpu_to_le32(0x0102)); - else add_attr_std_info(m, file_attrs, + else add_attr_std_info(m, file_attrs, cpu_to_le32(0x00)); } } /* The root directory mft reference. */ root_ref = MK_LE_MREF(FILE_root, FILE_root); - extend_ref = MK_LE_MREF(11,11); + extend_ref = MK_LE_MREF(11,11); Vprintf("Creating root directory (mft record 5)\n"); m = (MFT_RECORD*)(buf + 5 * vol->mft_record_size); m->flags |= MFT_RECORD_IS_DIRECTORY; @@ -4407,11 +4378,11 @@ static void mkntfs_create_root_structures(void) init_system_file_sd(FILE_root, &sd, &i); err = add_attr_sd(m, sd, i); } else if (vol->major_ver == 3 && vol->minor_ver == 0) { - init_system_file_sd(FILE_root, &sd, &i); - err = add_attr_sd(m, sd, i); + init_system_file_sd(FILE_root, &sd, &i); + err = add_attr_sd(m, sd, i); } else if (vol->major_ver == 3 && vol->minor_ver == 1) { - init_root_sd_31(&sd, &i); - err = add_attr_sd(m, sd, i); + init_root_sd_31(&sd, &i); + err = add_attr_sd(m, sd, i); } else err_exit("BUG: Unsupported NTFS version\n"); } @@ -4541,13 +4512,13 @@ static void mkntfs_create_root_structures(void) //dump_mft_record(m); Vprintf("Creating $Bitmap (mft record 6)\n"); m = (MFT_RECORD*)(buf + 6 * vol->mft_record_size); - // the data attribute of $Bitmap must be non-resident or otherwise + // the data attribute of $Bitmap must be non-resident or otherwise // windows 2003 will regard the volume as corrupt (ERSO) - if(!err) - err = insert_non_resident_attr_in_mft_record(m, - AT_DATA, NULL, 0, - 0, 0, - lcn_bitmap, lcn_bitmap_byte_size); + if (!err) + err = insert_non_resident_attr_in_mft_record(m, + AT_DATA, NULL, 0, + 0, 0, + lcn_bitmap, lcn_bitmap_byte_size); if (!err) @@ -4688,7 +4659,7 @@ static void mkntfs_create_root_structures(void) //dump_mft_record(m); /* create $Quota (1.2) or $Secure (3.0+) */ - + if (vol->major_ver < 3 ) { Vprintf("Creating $Quota (mft record 9)\n"); m = (MFT_RECORD*)(buf + 9 * vol->mft_record_size); @@ -4698,64 +4669,64 @@ static void mkntfs_create_root_structures(void) MK_LE_MREF(9, 9), 0LL, 0LL, FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0 , 0, "$Quota", - FILE_NAME_WIN32_AND_DOS); + FILE_NAME_WIN32_AND_DOS); if (!err) { init_system_file_sd(FILE_Secure, &sd, &i); err = add_attr_sd(m, sd, i); } if (err < 0) - err_exit("Couldn't create $Quota: %s\n", + err_exit("Couldn't create $Quota: %s\n", strerror(-err)); } else { - Vprintf("Creating $Secure (mft record 9)\n"); - m = (MFT_RECORD*)(buf + 9 * vol->mft_record_size); - m->flags |= MFT_RECORD_IS_8; - if (!err) - err = create_hardlink(index_block, root_ref, m, - MK_LE_MREF(9, 9), 0LL, 0LL, + Vprintf("Creating $Secure (mft record 9)\n"); + m = (MFT_RECORD*)(buf + 9 * vol->mft_record_size); + m->flags |= MFT_RECORD_IS_8; + if (!err) + err = create_hardlink(index_block, root_ref, m, + MK_LE_MREF(9, 9), 0LL, 0LL, FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | - FILE_ATTR_DUP_VIEW_INDEX_PRESENT + FILE_ATTR_DUP_VIEW_INDEX_PRESENT , 0, 0, "$Secure", - FILE_NAME_WIN32_AND_DOS); + FILE_NAME_WIN32_AND_DOS); if (!err) { if (vol->minor_ver == 0) { buf_sds_first_size = 0x1E0; buf_sds_size = 0x40000 + buf_sds_first_size; buf_sds_init = (char*)calloc(1, buf_sds_first_size); - init_secure_30(buf_sds_init); + init_secure_30(buf_sds_init); } else { - buf_sds_first_size = 0x240; - buf_sds_size = 0x40000 + buf_sds_first_size; + buf_sds_first_size = 0x240; + buf_sds_size = 0x40000 + buf_sds_first_size; buf_sds_init = (char*)calloc(1, buf_sds_first_size); - init_secure_31(buf_sds_init); + init_secure_31(buf_sds_init); } buf_sds = (char*)calloc(1,buf_sds_size); - if (!buf_sds) - err_exit("Failed to allocate internal buffer:" + if (!buf_sds) + err_exit("Failed to allocate internal buffer:" " %s\n", strerror(errno)); - memcpy((char*)buf_sds, (char*)buf_sds_init, - buf_sds_first_size); - memcpy((char*)buf_sds + 0x40000, (char*)buf_sds_init, + memcpy((char*)buf_sds, (char*)buf_sds_init, buf_sds_first_size); - err = add_attr_data(m, "$SDS", 4, 0, 0, (u8*)buf_sds, + memcpy((char*)buf_sds + 0x40000, (char*)buf_sds_init, + buf_sds_first_size); + err = add_attr_data(m, "$SDS", 4, 0, 0, (u8*)buf_sds, buf_sds_size); } - // FIXME: This should be IGNORE_CASE - if (!err) - err = add_attr_index_root(m, "$SDH", 4, 0, AT_UNUSED, - COLLATION_NTOFS_SECURITY_HASH , + // FIXME: This should be IGNORE_CASE + if (!err) + err = add_attr_index_root(m, "$SDH", 4, 0, AT_UNUSED, + COLLATION_NTOFS_SECURITY_HASH , opts.index_block_size); - // FIXME: This should be IGNORE_CASE - if (!err) - err = add_attr_index_root(m, "$SII", 4, 0, AT_UNUSED, - COLLATION_NTOFS_ULONG, opts.index_block_size); + // FIXME: This should be IGNORE_CASE + if (!err) + err = add_attr_index_root(m, "$SII", 4, 0, AT_UNUSED, + COLLATION_NTOFS_ULONG, opts.index_block_size); if (!err) err =initialize_secure(buf_sds_init, buf_sds_first_size - , m); - if (err < 0) - err_exit("Couldn't create $Secure: %s\n", + , m); + if (err < 0) + err_exit("Couldn't create $Secure: %s\n", strerror(-err)); } //dump_mft_record(m); @@ -4766,7 +4737,7 @@ static void mkntfs_create_root_structures(void) if (!err) err = create_hardlink(index_block, root_ref, m, MK_LE_MREF(FILE_UpCase, FILE_UpCase), - ((vol->upcase_len << 1) + + ((vol->upcase_len << 1) + vol->cluster_size - 1) & ~(vol->cluster_size - 1), vol->upcase_len << 1, FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0, @@ -4778,43 +4749,43 @@ static void mkntfs_create_root_structures(void) if (err < 0) err_exit("Couldn't create $UpCase: %s\n", strerror(-err)); //dump_mft_record(m); - - if (vol->major_ver < 3) { - Vprintf("Creating empty record, marked as in use " + + if (vol->major_ver < 3) { + Vprintf("Creating empty record, marked as in use " "(mft record 11)\n"); - m = (MFT_RECORD*)(buf + 11 * vol->mft_record_size); - err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0); - if (!err) { - init_system_file_sd(11, &sd, &j); - err = add_attr_sd(m, sd, j); - } - if (err < 0) - err_exit("Couldn't create system file 11 (0x0b): %s\n", - strerror(-err)); - //dump_mft_record(m); + m = (MFT_RECORD*)(buf + 11 * vol->mft_record_size); + err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0); + if (!err) { + init_system_file_sd(11, &sd, &j); + err = add_attr_sd(m, sd, j); + } + if (err < 0) + err_exit("Couldn't create system file 11 (0x0b): %s\n", + strerror(-err)); + //dump_mft_record(m); } else { Vprintf("Creating $Extend (mft record 11)\n"); /* * $Extends index must be resident. Otherwise, w2k3 will * regard the volume as corrupt. (ERSO) */ - m = (MFT_RECORD*)(buf + 11 * vol->mft_record_size); + m = (MFT_RECORD*)(buf + 11 * vol->mft_record_size); m->flags |= MFT_RECORD_IS_DIRECTORY; - if (!err) - err = create_hardlink(index_block, root_ref, m, - MK_LE_MREF(11, 11), 0LL, 0LL, + if (!err) + err = create_hardlink(index_block, root_ref, m, + MK_LE_MREF(11, 11), 0LL, 0LL, FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT, - 0, 0, "$Extend", + 0, 0, "$Extend", FILE_NAME_WIN32_AND_DOS); // FIXME: This should be IGNORE_CASE - if (!err) - err = add_attr_index_root(m, "$I30", 4, 0, AT_FILE_NAME, - COLLATION_FILE_NAME, opts.index_block_size); - if (err < 0) - err_exit("Couldn't create $Extend: %s\n", + if (!err) + err = add_attr_index_root(m, "$I30", 4, 0, AT_FILE_NAME, + COLLATION_FILE_NAME, opts.index_block_size); + if (err < 0) + err_exit("Couldn't create $Extend: %s\n", strerror(-err)); - } + } /* NTFS 1.2 reserved system files (mft records 0xc-0xf) */ for (i = 0xc; i < 0x10; i++) { Vprintf("Creating system file (mft record 0x%x)\n", i); @@ -4829,92 +4800,92 @@ static void mkntfs_create_root_structures(void) i, i, strerror(-err)); //dump_mft_record(m); } - // create systemfiles for ntfs volumes (3.1) + // create systemfiles for ntfs volumes (3.1) // starting vith file 24 (ignoring file 16-23) - if (vol->major_ver >= 3) { - extend_flags = FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | + if (vol->major_ver >= 3) { + extend_flags = FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | FILE_ATTR_DUP_VIEW_INDEX_PRESENT; Vprintf("Creating $ObjId (mft record 24)\n"); - m = (MFT_RECORD*)(buf + 24 * vol->mft_record_size); - m->flags |= MFT_RECORD_IS_4; - m->flags |= MFT_RECORD_IS_8; - if (!err) - err = create_hardlink_res((MFT_RECORD*)(buf + + m = (MFT_RECORD*)(buf + 24 * vol->mft_record_size); + m->flags |= MFT_RECORD_IS_4; + m->flags |= MFT_RECORD_IS_8; + if (!err) + err = create_hardlink_res((MFT_RECORD*)(buf + 11 * vol->mft_record_size), extend_ref, m, MK_LE_MREF(24, 24), 0LL, 0LL, - extend_flags, 0, 0, "$ObjId", - FILE_NAME_WIN32_AND_DOS); - - // FIXME: This should be IGNORE_CASE - if (!err) - err = add_attr_index_root(m, "$O", 2, 0, AT_UNUSED, - COLLATION_NTOFS_ULONGS, opts.index_block_size); + extend_flags, 0, 0, "$ObjId", + FILE_NAME_WIN32_AND_DOS); + + // FIXME: This should be IGNORE_CASE + if (!err) + err = add_attr_index_root(m, "$O", 2, 0, AT_UNUSED, + COLLATION_NTOFS_ULONGS, opts.index_block_size); if (!err) err = initialize_objid(m, volume_obj_id->object_id, MK_LE_MREF(FILE_Volume, FILE_Volume)); - if (err < 0) - err_exit("Couldn't create $ObjId: %s\n", strerror(-err)); - Vprintf("Creating $Quota (mft record 25)\n"); - m = (MFT_RECORD*)(buf + 25 * vol->mft_record_size); - m->flags |= MFT_RECORD_IS_4; - m->flags |= MFT_RECORD_IS_8; - if (!err) - err = create_hardlink_res((MFT_RECORD*)(buf + + if (err < 0) + err_exit("Couldn't create $ObjId: %s\n", strerror(-err)); + Vprintf("Creating $Quota (mft record 25)\n"); + m = (MFT_RECORD*)(buf + 25 * vol->mft_record_size); + m->flags |= MFT_RECORD_IS_4; + m->flags |= MFT_RECORD_IS_8; + if (!err) + err = create_hardlink_res((MFT_RECORD*)(buf + 11 * vol->mft_record_size), extend_ref, m, - MK_LE_MREF(25, 25), 0LL, 0LL, extend_flags + MK_LE_MREF(25, 25), 0LL, 0LL, extend_flags , 0, 0, "$Quota", FILE_NAME_WIN32_AND_DOS); - // FIXME: This should be IGNORE_CASE - if (!err) - err = add_attr_index_root(m, "$O", 2, 0, AT_UNUSED, - COLLATION_NTOFS_SID, opts.index_block_size); - // FIXME: This should be IGNORE_CASE - if (!err) - err = add_attr_index_root(m, "$Q", 2, 0, AT_UNUSED, - COLLATION_NTOFS_ULONG, opts.index_block_size); + // FIXME: This should be IGNORE_CASE + if (!err) + err = add_attr_index_root(m, "$O", 2, 0, AT_UNUSED, + COLLATION_NTOFS_SID, opts.index_block_size); + // FIXME: This should be IGNORE_CASE + if (!err) + err = add_attr_index_root(m, "$Q", 2, 0, AT_UNUSED, + COLLATION_NTOFS_ULONG, opts.index_block_size); if (!err) err = initialize_quota(m); - if (err < 0) - err_exit("Couldn't create $Quota: %s\n", strerror(-err)); - Vprintf("Creating $Reparse (mft record 26)\n"); - m = (MFT_RECORD*)(buf + 26 * vol->mft_record_size); - m->flags |= MFT_RECORD_IS_4; - m->flags |= MFT_RECORD_IS_8; - if (!err) - err = create_hardlink_res((MFT_RECORD*)(buf + + if (err < 0) + err_exit("Couldn't create $Quota: %s\n", strerror(-err)); + Vprintf("Creating $Reparse (mft record 26)\n"); + m = (MFT_RECORD*)(buf + 26 * vol->mft_record_size); + m->flags |= MFT_RECORD_IS_4; + m->flags |= MFT_RECORD_IS_8; + if (!err) + err = create_hardlink_res((MFT_RECORD*)(buf + 11 * vol->mft_record_size), extend_ref, m, MK_LE_MREF(26, 26), - 0LL, 0LL, extend_flags, 0, 0, - "$Reparse", FILE_NAME_WIN32_AND_DOS); - // FIXME: This should be IGNORE_CASE - if (!err) - err = add_attr_index_root(m, "$R", 2, 0, AT_UNUSED, - COLLATION_NTOFS_ULONGS, opts.index_block_size); - if (err < 0) - err_exit("Couldn't create $Reparse: %s\n", - strerror(-err)); - Vprintf("Creating System Volume Information (mft record 27)\n"); - m = (MFT_RECORD*)(buf + 27 * vol->mft_record_size); - m->flags |= MFT_RECORD_IS_DIRECTORY; - if (!err) - err = create_hardlink(index_block, root_ref, m, - MK_LE_MREF(27, 27), 0LL, 0LL, - FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | - FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT, 0, 0, - "SYSTEM~1", FILE_NAME_DOS); - + 0LL, 0LL, extend_flags, 0, 0, + "$Reparse", FILE_NAME_WIN32_AND_DOS); + // FIXME: This should be IGNORE_CASE if (!err) - err = create_hardlink(index_block, root_ref, m, - MK_LE_MREF(27, 27), 0LL, 0LL, - FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | - FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT, 0, 0, - "System Volume Information", FILE_NAME_WIN32); - if (!err) - err = add_attr_index_root(m, "$I30", 4, 0, AT_FILE_NAME, - COLLATION_FILE_NAME, opts.index_block_size); + err = add_attr_index_root(m, "$R", 2, 0, AT_UNUSED, + COLLATION_NTOFS_ULONGS, opts.index_block_size); if (err < 0) - err_exit("Couldn't create 'System Volume Information'" + err_exit("Couldn't create $Reparse: %s\n", + strerror(-err)); + Vprintf("Creating System Volume Information (mft record 27)\n"); + m = (MFT_RECORD*)(buf + 27 * vol->mft_record_size); + m->flags |= MFT_RECORD_IS_DIRECTORY; + if (!err) + err = create_hardlink(index_block, root_ref, m, + MK_LE_MREF(27, 27), 0LL, 0LL, + FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | + FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT, 0, 0, + "SYSTEM~1", FILE_NAME_DOS); + + if (!err) + err = create_hardlink(index_block, root_ref, m, + MK_LE_MREF(27, 27), 0LL, 0LL, + FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM | + FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT, 0, 0, + "System Volume Information", FILE_NAME_WIN32); + if (!err) + err = add_attr_index_root(m, "$I30", 4, 0, AT_FILE_NAME, + COLLATION_FILE_NAME, opts.index_block_size); + if (err < 0) + err_exit("Couldn't create 'System Volume Information'" ": %s\n", strerror(-err)); - } + } } /** @@ -4955,7 +4926,7 @@ int main(int argc, char **argv) err_exit("Could not allocate memory for internal buffer.\n"); init_upcase_table(vol->upcase, vol->upcase_len * sizeof(ntfschar)); /* Initialize opts to zero / required values. */ - init_options(); + init_options(); /* Parse command line options. */ parse_options(argc, argv); /* Open the partition. */ diff --git a/ntfsprogs/ntfscat.c b/ntfsprogs/ntfscat.c index ea59d903..1964fa25 100644 --- a/ntfsprogs/ntfscat.c +++ b/ntfsprogs/ntfscat.c @@ -243,7 +243,7 @@ static int parse_options (int argc, char **argv) opts.quiet = 0; } else { if (opts.device == NULL) { - Eprintf ("You must specify a device.\n"); + Eprintf ("You must specify a device.\n"); err++; } else if (opts.file == NULL && opts.inode == -1) { diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index 32734e57..f9e8c1c1 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -162,10 +162,10 @@ struct { #define PERR_PREFIX ERR_PREFIX "(%d): " #define NERR_PREFIX ERR_PREFIX ": " -#define LAST_METADATA_INODE 11 +#define LAST_METADATA_INODE 11 -#define NTFS_MAX_CLUSTER_SIZE 65536 -#define NTFS_SECTOR_SIZE 512 +#define NTFS_MAX_CLUSTER_SIZE 65536 +#define NTFS_SECTOR_SIZE 512 #define rounded_up_division(a, b) (((a) + (b - 1)) / (b)) @@ -383,7 +383,7 @@ static void parse_options(int argc, char **argv) msg_out = stdout; - /* FIXME: this is a workaround for loosing debug info if stdout != stderr + /* FIXME: this is a workaround for losing debug info if stdout != stderr and for the uncontrollable verbose messages in libntfs. Ughhh. */ if (opt.std_out) msg_out = stderr; @@ -699,7 +699,7 @@ static void restore_image(void) #define WIPE_TIMESTAMPS(atype, attr) \ do { \ atype *ats; \ - ats = (atype *)((char*)(attr) + (attr)->value_offset); \ + ats = (atype *)((char*)(attr) + (attr)->value_offset); \ \ ats->creation_time = 0; \ ats->last_data_change_time = 0; \ @@ -708,7 +708,7 @@ do { \ \ wiped_timestamp_data += 32; \ \ -} while(0) +} while (0) static void wipe_timestamps(ntfs_walk_clusters_ctx *image) { @@ -1004,8 +1004,7 @@ static int walk_clusters(ntfs_volume *volume, struct ntfs_walk_cluster *walk) } } - if (ni->mrec) - free(ni->mrec); + free(ni->mrec); free(ni); if (deleted_inode) @@ -1248,9 +1247,9 @@ static void set_filesize(s64 filesize) if (fstatfs(fd_out, &opt.stfs) == -1) Printf("WARNING: Couldn't get filesystem type: " "%s\n", strerror(errno)); - else + else fs_type = opt.stfs.f_type; - + if (fs_type == 0x52654973) Printf("WARNING: You're using ReiserFS, it has very poor " "performance creating\nlarge sparse files. The next " diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 13ab60bb..687e25c3 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -176,7 +176,7 @@ static void parse_options(int argc, char **argv) { "debug", no_argument, NULL, 'd' }, #endif { "help", no_argument, NULL, 'h' }, - { "no-progress-bar", no_argument, NULL, 'P' }, + { "no-progress-bar", no_argument, NULL, 'P' }, { "verbose", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } }; @@ -193,7 +193,7 @@ static void parse_options(int argc, char **argv) opt.vol1 = argv[optind - 1]; } else if (!opt.vol2) { opt.vol2 = argv[optind - 1]; - } else { + } else { err_printf("Too many arguments!\n"); usage(); } @@ -284,7 +284,7 @@ static u64 inumber(ntfs_inode *ni) { if (ni->nr_extents >= 0) return ni->mft_no; - + return ni->base_ni->mft_no; } @@ -312,7 +312,7 @@ static inline s64 get_nr_mft_records(ntfs_volume *vol) #define NTFSCMP_EXTENSION_RECORD 4 #define NTFSCMP_INODE_CLOSE_ERROR 5 -const char *ntfscmp_errs[] = { +const char *ntfscmp_errs[] = { "OK", "INODE_OPEN_ERROR", "INODE_OPEN_IO_ERROR", @@ -325,7 +325,7 @@ const char *ntfscmp_errs[] = { static const char *err2string(int err) { - return ntfscmp_errs[err]; + return ntfscmp_errs[err]; } static const char *pret2str(void *p) @@ -352,7 +352,7 @@ static int inode_open(ntfs_volume *vol, MFT_REF mref, ntfs_inode **ni) if (inode_close(*ni) != 0) return NTFSCMP_INODE_CLOSE_ERROR; - + return NTFSCMP_EXTENSION_RECORD; } @@ -363,7 +363,7 @@ static ntfs_inode *base_inode(ntfs_attr_search_ctx *ctx) { if (ctx->base_ntfs_ino) return ctx->base_ntfs_ino; - + return ctx->ntfs_ino; } @@ -401,7 +401,7 @@ static void free_name(char **name) static char *get_attr_name(u64 mft_no, ATTR_TYPES atype, - const ntfschar *uname, + const ntfschar *uname, const int uname_len) { char *name = NULL; @@ -417,7 +417,7 @@ static char *get_attr_name(u64 mft_no, print_attribute_type(atype); puts(""); exit(1); - + } else if (name_len > 0) return name; @@ -495,9 +495,9 @@ static void cmp_attribute_data(ntfs_attr *na1, ntfs_attr *na2) printf("len = %lld, pos = %lld\n", na1->data_size, pos); exit(1); } - + if (count1 == 0) { - + if (pos + count1 == na1->data_size) return; /* we are ready */ @@ -506,7 +506,7 @@ static void cmp_attribute_data(ntfs_attr *na1, ntfs_attr *na2) printf("%lld != %lld\n", pos + count1, na1->data_size); exit(1); } - + if (memcmp(buf1, buf2, count1)) { print_na(na1); printf("content"); @@ -515,15 +515,15 @@ static void cmp_attribute_data(ntfs_attr *na1, ntfs_attr *na2) return; } } - + err_printf("%s read overrun: ", __FUNCTION__); print_na(na1); - err_printf("(len = %lld, pos = %lld, count = %lld)\n", + err_printf("(len = %lld, pos = %lld, count = %lld)\n", na1->data_size, pos, count1); exit(1); } -static void cmp_attribute(ntfs_attr_search_ctx *ctx1, +static void cmp_attribute(ntfs_attr_search_ctx *ctx1, ntfs_attr_search_ctx *ctx2) { ATTR_RECORD *a1 = ctx1->attr; @@ -532,7 +532,7 @@ static void cmp_attribute(ntfs_attr_search_ctx *ctx1, na1 = ntfs_attr_open(base_inode(ctx1), a1->type, GET_ATTR_NAME(a1)); na2 = ntfs_attr_open(base_inode(ctx2), a2->type, GET_ATTR_NAME(a2)); - + if ((!na1 && na2) || (na1 && !na2)) { print_ctx(ctx1); printf("open: %s != %s\n", pret2str(na1), pret2str(na2)); @@ -579,7 +579,7 @@ static int new_name(ntfs_attr_search_ctx *ctx, char *prev_name) { int ret = 0; char *name = get_attr_name_ctx(ctx); - + if (prev_name && name) { if (strcmp(prev_name, name) != 0) ret = 1; @@ -597,13 +597,13 @@ static int new_attribute(ntfs_attr_search_ctx *ctx, { if (!prev_atype && !prev_name) return 1; - + if (!ctx->attr->non_resident) return 1; if (prev_atype != ctx->attr->type) return 1; - + if (new_name(ctx, prev_name)) return 1; @@ -613,11 +613,11 @@ static int new_attribute(ntfs_attr_search_ctx *ctx, printf("record %llu lowest_vcn %lld: SKIPPED\n", ctx->ntfs_ino->mft_no, ctx->attr->lowest_vcn); } - + return 0; } - -static void set_prev(char **prev_name, ATTR_TYPES *prev_atype, + +static void set_prev(char **prev_name, ATTR_TYPES *prev_atype, char *name, ATTR_TYPES atype) { free_name(prev_name); @@ -632,8 +632,8 @@ static void set_prev(char **prev_name, ATTR_TYPES *prev_atype, static void set_cmp_attr(ntfs_attr_search_ctx *ctx, ATTR_TYPES *atype, char **name) { - *atype = ctx->attr->type; - + *atype = ctx->attr->type; + free_name(name); *name = get_attr_name_ctx(ctx); } @@ -642,15 +642,15 @@ static int next_attr(ntfs_attr_search_ctx *ctx, ATTR_TYPES *atype, char **name, int *err) { int ret; - + ret = ntfs_attrs_walk(ctx); *err = errno; - if (ret) { + if (ret) { *atype = AT_END; free_name(name); } else set_cmp_attr(ctx, atype, name); - + return ret; } @@ -662,12 +662,12 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2) char *prev_name = NULL, *name1 = NULL, *name2 = NULL; ATTR_TYPES old_atype1, prev_atype = 0, atype1, atype2; ntfs_attr_search_ctx *ctx1, *ctx2; - + if (!(ctx1 = attr_get_search_ctx(ni1))) return -1; if (!(ctx2 = attr_get_search_ctx(ni2))) goto out; - + set_cmp_attr(ctx1, &atype1, &name1); set_cmp_attr(ctx2, &atype2, &name2); @@ -681,7 +681,7 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2) ret2 = next_attr(ctx2, &atype2, &name2, &errno2); print_attributes(ni1, atype1, atype2, name1, name2); - + if (ret1 && ret2) { if (errno1 != errno2) { print_inode_ni(ni1); @@ -697,14 +697,14 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2) printf("presence: EXISTS != MISSING\n"); set_prev(&prev_name, &prev_atype, name1, atype1); } - + } else if (ret1 || atype1 > atype2) { if (new_attribute(ctx2, prev_atype, prev_name)) { print_ctx(ctx2); printf("presence: MISSING != EXISTS \n"); set_prev(&prev_name, &prev_atype, name2, atype2); } - + } else /* atype1 == atype2 */ { if (new_attribute(ctx1, prev_atype, prev_name)) { cmp_attribute(ctx1, ctx2); @@ -759,7 +759,7 @@ static int cmp_inodes(ntfs_volume *vol1, ntfs_volume *vol2) if (ret1 != ret2) { print_inode(inode); - printf("open: %s != %s\n", + printf("open: %s != %s\n", err2string(ret1), err2string(ret2)); goto close_inodes; } diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index 0b087fa0..988e2777 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -222,7 +222,7 @@ static int parse_options (int argc, char **argv) opts.quiet = 0; } else { if (!opts.device) { - Eprintf("You must specify a device.\n"); + Eprintf("You must specify a device.\n"); err++; } else if (!opts.src_file) { Eprintf("You must specify a source file.\n"); diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 24e2647c..0ace7ef1 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -153,8 +153,7 @@ static void log_err_exit(u8 *buf, const char *fmt, ...) { va_list ap; - if (buf) - free(buf); + free(buf); fprintf(stderr, "ERROR: "); va_start(ap, fmt); diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index de871a95..e8ace522 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -228,8 +228,7 @@ static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const u16 flags) err_out: ntfs_attr_put_search_ctx(ctx); err_exit: - if (m) - free(m); + free(m); return ret; } @@ -509,10 +508,8 @@ mount_ok: /* Set return code to 0. */ i = 0; final_exit: - if (m) - free(m); - if (m2) - free(m2); + free(m); + free(m2); if (vol && ntfs_umount(vol, 0)) ntfs_umount(vol, 1); return i; diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 3e941f8f..8bc55a16 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -625,7 +625,7 @@ static void ntfs_dump_attr_list(ATTR_RECORD *attr, ntfs_volume *vol) } printf("\tDumping attribute list:"); entry = (ATTR_LIST_ENTRY *) value; - for(;(u8 *)entry < (u8 *) value + l; entry = (ATTR_LIST_ENTRY *) + for (;(u8 *)entry < (u8 *) value + l; entry = (ATTR_LIST_ENTRY *) ((u8 *) entry + le16_to_cpu(entry->length))) { printf("\n"); printf("\t\tAttribute type:\t0x%x\n", @@ -832,8 +832,7 @@ static void ntfs_dump_acl(const char *prefix,ACL *acl) /* get a SID string */ sid = ntfs_sid_to_mbs(&ace->sid, NULL, 0); printf("%s\t\t SID: %s\n",prefix,sid); - if (sid) - free(sid); + free(sid); /* proceed to next ACE */ ace = (ACCESS_ALLOWED_ACE *)(((char *)ace) + le32_to_cpu(ace->size)); @@ -1098,7 +1097,7 @@ static int ntfs_dump_index_entries(INDEX_ENTRY *entry, ATTR_TYPES type) int numb_entries = 1; char *name = NULL; - while(1) { + while (1) { if (!opts.verbose) { if (entry->flags & INDEX_ENTRY_END) break; @@ -1121,7 +1120,7 @@ static int ntfs_dump_index_entries(INDEX_ENTRY *entry, ATTR_TYPES type) if (entry->flags & INDEX_ENTRY_END) break; - switch(type) { + switch (type) { case(AT_FILE_NAME): Vprintf("\t\tFILE record number:\t %llu\n", MREF_LE(entry->indexed_file)); @@ -1351,7 +1350,7 @@ static void ntfs_dump_index_allocation(ATTR_RECORD *attr, ntfs_inode *ni) tmp_alloc = allocation; bit = 0; - while((u8 *)tmp_alloc < (u8 *)allocation + na->data_size) { + while ((u8 *)tmp_alloc < (u8 *)allocation + na->data_size) { if (*byte & (1 << bit)) { if (ntfs_mst_post_read_fixup((NTFS_RECORD *) tmp_alloc, indx_record_size)) { @@ -1493,7 +1492,7 @@ static void ntfs_dump_attr_reparse_point(ATTR_RECORD *attr __attribute__((unused static void ntfs_dump_attr_ea_information(ATTR_RECORD *attr) { EA_INFORMATION *ea_info; - + ea_info = (EA_INFORMATION*)((u8*)attr + le16_to_cpu(attr->value_offset)); printf("Dumping attribute $EA_INFORMATION (0xD0)\n"); @@ -1519,7 +1518,7 @@ static void ntfs_dump_attr_ea(ATTR_RECORD *attr, ntfs_volume *vol) if (attr->non_resident) { runlist *rl; - data_size = sle64_to_cpu(attr->data_size); + data_size = sle64_to_cpu(attr->data_size); printf("\tIs resident? \t\t No\n"); printf("\tData size:\t\t %lld\n", data_size); if (!opts.verbose) @@ -1578,8 +1577,7 @@ static void ntfs_dump_attr_ea(ATTR_RECORD *attr, ntfs_volume *vol) if ((u8*)ea - buf >= data_size) break; } - if (buf) - free(buf); + free(buf); } /** diff --git a/ntfsprogs/ntfslabel.c b/ntfsprogs/ntfslabel.c index 8727ebc5..2de0c033 100644 --- a/ntfsprogs/ntfslabel.c +++ b/ntfsprogs/ntfslabel.c @@ -354,8 +354,7 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label, } result = 0; err_out: - if (new_label) - free(new_label); + free(new_label); return result; } diff --git a/ntfsprogs/ntfsmount.c b/ntfsprogs/ntfsmount.c index ab46d430..097c8144 100644 --- a/ntfsprogs/ntfsmount.c +++ b/ntfsprogs/ntfsmount.c @@ -119,7 +119,7 @@ static long ntfs_fuse_get_nr_free_mft_records(ntfs_volume *vol) u8 *buf; long nr_free = 0; s64 br, total = 0; - + if (!(ctx->state & NF_FreeMFTOutdate)) return ctx->free_mft; buf = malloc(vol->cluster_size); @@ -494,7 +494,7 @@ static int ntfs_fuse_write(const char *org_path, const char *buf, size_t size, total += res; } res = total; -exit: +exit: ctx->state |= (NF_FreeClustersOutdate | NF_FreeMFTOutdate); if (na) ntfs_attr_close(na); @@ -587,8 +587,7 @@ static int ntfs_fuse_create(const char *org_path, const unsigned type) else res = -errno; exit: - if (uname) - free(uname); + free(uname); if (dir_ni) ntfs_inode_close(dir_ni); free(path); @@ -693,8 +692,7 @@ static int ntfs_fuse_link(const char *old_path, const char *new_path) exit: if (ni) ntfs_inode_close(ni); - if (uname) - free(uname); + free(uname); if (dir_ni) ntfs_inode_close(dir_ni); free(path); @@ -742,8 +740,7 @@ static int ntfs_fuse_rm(const char *org_path) exit: if (ni) ntfs_inode_close(ni); - if (uname) - free(uname); + free(uname); if (dir_ni) ntfs_inode_close(dir_ni); free(path); @@ -1015,8 +1012,7 @@ static int ntfs_fuse_getxattr(const char *path, const char *name, exit: if (na) ntfs_attr_close(na); - if (lename) - free(lename); + free(lename); if (ntfs_inode_close(ni)) perror("Failed to close inode"); return res; @@ -1070,8 +1066,7 @@ static int ntfs_fuse_setxattr(const char *path, const char *name, exit: if (na) ntfs_attr_close(na); - if (lename) - free(lename); + free(lename); if (ntfs_inode_close(ni)) perror("Failed to close inode"); return res; @@ -1111,8 +1106,7 @@ static int ntfs_fuse_removexattr(const char *path, const char *name) exit: if (na) ntfs_attr_close(na); - if (lename) - free(lename); + free(lename); if (ntfs_inode_close(ni)) perror("Failed to close inode"); return res; @@ -1140,7 +1134,7 @@ static struct fuse_operations ntfs_fuse_oper = { .utime = ntfs_fuse_utime, #ifdef HAVE_SETXATTR .getxattr = ntfs_fuse_getxattr, -#if 0 +#if 0 .setxattr = ntfs_fuse_setxattr, .removexattr = ntfs_fuse_removexattr, .listxattr = ntfs_fuse_listxattr, @@ -1487,8 +1481,7 @@ int main(int argc, char *argv[]) parsed_options = parse_mount_options((opts.options) ? opts.options : ""); if (!parsed_options) { - if (opts.device) - free(opts.device); + free(opts.device); ntfs_fuse_destroy(); return 3; } diff --git a/ntfsprogs/ntfsmove.h b/ntfsprogs/ntfsmove.h index f13dcdbf..1aeeef2a 100644 --- a/ntfsprogs/ntfsmove.h +++ b/ntfsprogs/ntfsmove.h @@ -39,7 +39,7 @@ struct options { int verbose; /* Extra output */ int noaction; /* Do not write to disk */ int nodirty; /* Do not mark volume dirty */ - u8 padding[4]; /* Unused: alignment to 64 bit. */ + u8 padding[4]; /* Unused: alignment to 64 bit. */ }; #endif /* _NTFSMOVE_H_ */ diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index 67b4c185..3b074fdf 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -204,7 +204,7 @@ s64 max_free_cluster_range = 0; #define DIRTY_INODE (1) #define DIRTY_ATTRIB (2) -#define NTFS_MAX_CLUSTER_SIZE (65536) +#define NTFS_MAX_CLUSTER_SIZE (65536) GEN_PRINTF(Eprintf, stderr, NULL, FALSE) GEN_PRINTF(Vprintf, stdout, &opt.verbose, TRUE) @@ -694,7 +694,7 @@ static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl) exit(1); return; } - + if (inode == FILE_Bitmap) { llcn = &resize->last_lcn; if (atype == AT_DATA && NInoAttrList(resize->ni)) @@ -765,7 +765,7 @@ static void collect_relocation_info(ntfs_resize_t *resize, runlist *rl) if (inode == FILE_Bitmap && resize->ctx->attr->type == AT_DATA) return; - + start = lcn; len = lcn_length; @@ -1636,11 +1636,11 @@ 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) return 1; - + return 0; } @@ -1648,30 +1648,30 @@ static int handle_mftdata(ntfs_resize_t *resize, int do_mftdata) { ATTR_RECORD *attr = resize->ctx->attr; VCN highest_vcn, lowest_vcn; - + if (do_mftdata) { - + if (!is_mftdata(resize)) return 0; - + highest_vcn = sle64_to_cpu(attr->highest_vcn); lowest_vcn = sle64_to_cpu(attr->lowest_vcn); - + if (resize->mft_highest_vcn != highest_vcn) return 0; - + if (lowest_vcn == 0) resize->mft_highest_vcn = lowest_vcn; else resize->mft_highest_vcn = lowest_vcn - 1; } else if (is_mftdata(resize)) { - + highest_vcn = sle64_to_cpu(attr->highest_vcn); - + if (resize->mft_highest_vcn < highest_vcn) resize->mft_highest_vcn = highest_vcn; - + return 0; } @@ -1688,10 +1688,10 @@ static void relocate_attributes(ntfs_resize_t *resize, int do_mftdata) while (!ntfs_attrs_walk(resize->ctx)) { if (resize->ctx->attr->type == AT_END) break; - + if (handle_mftdata(resize, do_mftdata) == 0) continue; - + ret = has_bad_sectors(resize, 0); if (ret == -1) exit(1); @@ -1752,10 +1752,10 @@ static void relocate_inodes(ntfs_resize_t *resize) nr_mft_records = resize->vol->mft_na->initialized_size >> resize->vol->mft_record_size_bits; - for (mref = 0; mref < (MFT_REF)nr_mft_records; mref++) + for (mref = 0; mref < (MFT_REF)nr_mft_records; mref++) relocate_inode(resize, mref, 0); - while(1) { + while (1) { highest_vcn = resize->mft_highest_vcn; mref = nr_mft_records; do { @@ -1769,8 +1769,7 @@ static void relocate_inodes(ntfs_resize_t *resize) "Please report!\n", highest_vcn); } done: - if (resize->mrec) - free(resize->mrec); + free(resize->mrec); } static void print_hint(ntfs_volume *vol, const char *s, struct llcn_t llcn) @@ -1800,12 +1799,12 @@ static void advise_on_resize(ntfs_resize_t *resize) if (opt.verbose) { printf("Estimating smallest shrunken size supported ...\n"); printf("File feature Last used at By inode\n"); - print_hint(vol, "$MFT", resize->last_mft); + print_hint(vol, "$MFT", resize->last_mft); print_hint(vol, "Multi-Record", resize->last_multi_mft); - print_hint(vol, "$MFTMirr", resize->last_mftmir); - print_hint(vol, "Compressed", resize->last_compressed); - print_hint(vol, "Sparse", resize->last_sparse); - print_hint(vol, "Ordinary", resize->last_lcn); + print_hint(vol, "$MFTMirr", resize->last_mftmir); + print_hint(vol, "Compressed", resize->last_compressed); + print_hint(vol, "Sparse", resize->last_sparse); + print_hint(vol, "Ordinary", resize->last_lcn); } print_advise(vol, resize->last_unsupp); @@ -1849,16 +1848,16 @@ static void rl_truncate(runlist **rl, const VCN last_vcn) { int len; VCN vcn; - + len = rl_items(*rl) - 1; if (len <= 0) err_exit("rl_truncate: bad runlist length: %d\n", len); vcn = (*rl)[len].vcn; - + if (vcn < last_vcn) rl_expand(rl, last_vcn); - + else if (vcn > last_vcn) if (ntfs_rl_truncate(rl, last_vcn) == -1) perr_exit("ntfs_rl_truncate"); @@ -1898,7 +1897,7 @@ static void truncate_badclust_bad_attr(ntfs_resize_t *resize) if (!(rl_bad = ntfs_mapping_pairs_decompress(vol, a, NULL))) perr_exit("ntfs_mapping_pairs_decompress"); - + rl_truncate(&rl_bad, nr_clusters); a->highest_vcn = cpu_to_le64(nr_clusters - 1LL); @@ -1945,7 +1944,7 @@ static void realloc_lcn_bitmap(ntfs_resize_t *resize, s64 bm_bsize) if (!(tmp = realloc(resize->lcn_bitmap.bm, bm_bsize))) perr_exit("realloc"); - + resize->lcn_bitmap.bm = tmp; resize->lcn_bitmap.size = bm_bsize; bitmap_file_data_fixup(resize->new_volume_size, &resize->lcn_bitmap); @@ -2037,41 +2036,41 @@ static int check_bad_sectors(ntfs_volume *vol) ntfs_attr_search_ctx *ctx; runlist *rl; s64 i, badclusters = 0; - + Vprintf("Checking for bad sectors ...\n"); lookup_data_attr(vol, FILE_BadClus, "$Bad", &ctx); - + if (NInoAttrList(ctx->ntfs_ino)) err_exit("Hopelessly many bad sectors! Please report to " "linux-ntfs@lists.sf.net\n"); - + if (!ctx->attr->non_resident) err_exit("Resident attribute in $BadClust! Please report to " "linux-ntfs@lists.sf.net\n"); if (!(rl = ntfs_mapping_pairs_decompress(vol, ctx->attr, NULL))) perr_exit("Decompressing $BadClust:$Bad mapping pairs failed"); - + for (i = 0; rl[i].length; i++) { /* CHECKME: LCN_RL_NOT_MAPPED check isn't needed */ if (rl[i].lcn == LCN_HOLE || rl[i].lcn == LCN_RL_NOT_MAPPED) continue; - + badclusters += rl[i].length; - Vprintf("Bad cluster: %8lld - %lld\n", rl[i].lcn, + Vprintf("Bad cluster: %8lld - %lld\n", rl[i].lcn, rl[i].lcn + rl[i].length - 1); } if (badclusters) { printf("%sThis software has detected that the disk has at least" - " %lld bad sector%s.\n", + " %lld bad sector%s.\n", !opt.badsectors ? NERR_PREFIX : "WARNING: ", badclusters, badclusters - 1 ? "s" : ""); if (!opt.badsectors) { printf("%s", bad_sectors_warning_msg); exit(1); - } else + } else printf("WARNING: Bad sectors can cause reliability " "problems and massive data loss!!!\n"); } @@ -2263,7 +2262,7 @@ static ntfs_volume *mount_volume(void) printf("%s", corrupt_volume_msg); else if (err == EPERM) printf("%s", hibernated_volume_msg); - else if (err == EOPNOTSUPP) + else if (err == EOPNOTSUPP) printf("%s", unclean_journal_msg); exit(1); } @@ -2384,7 +2383,7 @@ static void check_cluster_allocation(ntfs_volume *vol, ntfsck_t *fsck) printf("%s", corrupt_volume_msg); exit(1); } - + compare_bitmaps(vol, &fsck->lcn_bitmap); } @@ -2444,7 +2443,7 @@ int main(int argc, char **argv) printf("Nothing to do: NTFS volume size is already OK.\n"); exit(0); } - + memset(&resize, 0, sizeof(resize)); resize.vol = vol; resize.new_volume_size = new_size; @@ -2453,13 +2452,13 @@ int main(int argc, char **argv) resize.shrink = 1; if (opt.show_progress) resize.progress.flags |= NTFS_PROGBAR; - /* + /* * Checking and __reporting__ of bad sectors must be done before cluster * allocation check because chkdsk doesn't fix $Bitmap's w/ bad sectors * thus users would (were) quite confused why chkdsk doesn't work. - */ + */ resize.badclusters = check_bad_sectors(vol); - + check_cluster_allocation(vol, &fsck); print_disk_usage(vol, fsck.inuse); @@ -2472,7 +2471,7 @@ int main(int argc, char **argv) check_resize_constraints(&resize); if (opt.info) { - advise_on_resize(&resize); + advise_on_resize(&resize); exit(0); } diff --git a/ntfsprogs/ntfsrm.c b/ntfsprogs/ntfsrm.c index 1b564a2c..0a4cf481 100644 --- a/ntfsprogs/ntfsrm.c +++ b/ntfsprogs/ntfsrm.c @@ -264,7 +264,7 @@ static int utils_array_insert (void *ptr, int asize, int before, int count) return -1; src = (u8*) ptr + (before * esize); - dst = src + (count * esize); + dst = src + (count * esize); len = (asize - before) * esize; // XXX what about realloc? @@ -291,7 +291,7 @@ static int utils_array_remove (void *ptr, int asize, int first, int count) return -1; dst = (u8*) ptr + (first * esize); - src = dst + (count * esize); + src = dst + (count * esize); len = (asize - first) * esize; memmove (dst, src, len); diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 0b455e07..c82ad43d 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -64,10 +64,9 @@ #include "layout.h" #include "volume.h" #include "utils.h" +#include "attrdef.h" #include "version.h" -extern const unsigned char attrdef_ntfs12_array[2400]; - const char *EXEC_NAME = "ntfstruncate"; /* Need these global so ntfstruncate_exit can access them. */ diff --git a/ntfsprogs/ntfsundelete.c b/ntfsprogs/ntfsundelete.c index d8d009b0..848b9400 100644 --- a/ntfsprogs/ntfsundelete.c +++ b/ntfsprogs/ntfsundelete.c @@ -105,10 +105,6 @@ GEN_PRINTF (Eprintf, stderr, NULL, FALSE) GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE) GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE) -static int undelete_file (ntfs_volume *vol, long long inode); - -#define _(S) gettext(S) - /** * parse_inode_arg - parses the inode expression * @@ -1571,130 +1567,6 @@ static int set_date (const char *pathname, time_t date) return 1; } -/** - * scan_disk - Search an NTFS volume for files that could be undeleted - * @vol: An ntfs volume obtained from ntfs_mount - * - * Read through all the MFT entries looking for deleted files. For each one - * determine how much of the data lies in unused disk space. - * - * The list can be filtered by name, size and date, using command line options. - * - * Return: -1 Error, something went wrong - * n Success, the number of recoverable files - */ -static int scan_disk (ntfs_volume *vol) -{ - s64 nr_mft_records; - const int BUFSIZE = 8192; - char *buffer = NULL; - int results = 0; - ntfs_attr *attr; - long long size; - long long bmpsize; - int i, j, k, b; - int percent; - struct ufile *file; - regex_t re; - - if (!vol) - return -1; - - attr = ntfs_attr_open (vol->mft_ni, AT_BITMAP, AT_UNNAMED, 0); - if (!attr) { - Eprintf ("ERROR: Couldn't open $MFT/$BITMAP: %s\n", strerror (errno)); - return -1; - } - bmpsize = attr->initialized_size; - - buffer = malloc (BUFSIZE); - if (!buffer) { - Eprintf ("ERROR: Couldn't allocate memory in scan_disk()\n"); - results = -1; - goto out; - } - - if (opts.match) { - int flags = REG_NOSUB; - - if (!opts.match_case) - flags |= REG_ICASE; - if (regcomp (&re, opts.match, flags)) { - Eprintf ("ERROR: Couldn't create a regex.\n"); - goto out; - } - } - - nr_mft_records = vol->mft_na->initialized_size >> - vol->mft_record_size_bits; - - Qprintf ("Inode Flags %%age Date Size Filename\n"); - Qprintf ("---------------------------------------------------------------\n"); - for (i = 0; i < bmpsize; i += BUFSIZE) { - long long read_count = min ((bmpsize - i), BUFSIZE); - size = ntfs_attr_pread (attr, i, read_count, buffer); - if (size < 0) - break; - - for (j = 0; j < size; j++) { - b = buffer[j]; - for (k = 0; k < 8; k++, b>>=1) { - if (((i+j)*8+k) >= nr_mft_records) - goto done; - if (b & 1) - continue; - file = read_record (vol, (i+j)*8+k); - if (!file) { - Eprintf ("Couldn't read MFT Record %d.\n", (i+j)*8+k); - continue; - } - - if ((opts.since > 0) && (file->date <= opts.since)) - goto skip; - if (opts.match && !name_match (&re, file)) - goto skip; - if (opts.size_begin && (opts.size_begin > file->max_size)) - goto skip; - if (opts.size_end && (opts.size_end < file->max_size)) - goto skip; - - percent = calc_percentage (file, vol); - if ((opts.percent == -1) || (percent >= opts.percent)) { - if (opts.verbose) - dump_record (file); - else - list_record (file); - - /* Was -u specified with no inode - so undelete file by regex */ - if (opts.mode == MODE_UNDELETE) { - if (!undelete_file (vol, file->inode)) - Vprintf ("ERROR: Failed to undelete " - "inode %lli\n!", - file->inode); - printf ("\n"); - } - } - if (((opts.percent == -1) && (percent > 0)) || - ((opts.percent > 0) && (percent >= opts.percent))) { - results++; - } -skip: - free_file (file); - } - } - } -done: - Qprintf ("\nFiles with potentially recoverable content: %d\n", results); -out: - if (opts.match) - regfree (&re); - free (buffer); - if (attr) - ntfs_attr_close (attr); - return results; -} - /** * undelete_file - Recover a deleted file from an NTFS volume * @vol: An ntfs volume obtained from ntfs_mount @@ -1940,6 +1812,130 @@ free: return result; } +/** + * scan_disk - Search an NTFS volume for files that could be undeleted + * @vol: An ntfs volume obtained from ntfs_mount + * + * Read through all the MFT entries looking for deleted files. For each one + * determine how much of the data lies in unused disk space. + * + * The list can be filtered by name, size and date, using command line options. + * + * Return: -1 Error, something went wrong + * n Success, the number of recoverable files + */ +static int scan_disk (ntfs_volume *vol) +{ + s64 nr_mft_records; + const int BUFSIZE = 8192; + char *buffer = NULL; + int results = 0; + ntfs_attr *attr; + long long size; + long long bmpsize; + int i, j, k, b; + int percent; + struct ufile *file; + regex_t re; + + if (!vol) + return -1; + + attr = ntfs_attr_open (vol->mft_ni, AT_BITMAP, AT_UNNAMED, 0); + if (!attr) { + Eprintf ("ERROR: Couldn't open $MFT/$BITMAP: %s\n", strerror (errno)); + return -1; + } + bmpsize = attr->initialized_size; + + buffer = malloc (BUFSIZE); + if (!buffer) { + Eprintf ("ERROR: Couldn't allocate memory in scan_disk()\n"); + results = -1; + goto out; + } + + if (opts.match) { + int flags = REG_NOSUB; + + if (!opts.match_case) + flags |= REG_ICASE; + if (regcomp (&re, opts.match, flags)) { + Eprintf ("ERROR: Couldn't create a regex.\n"); + goto out; + } + } + + nr_mft_records = vol->mft_na->initialized_size >> + vol->mft_record_size_bits; + + Qprintf ("Inode Flags %%age Date Size Filename\n"); + Qprintf ("---------------------------------------------------------------\n"); + for (i = 0; i < bmpsize; i += BUFSIZE) { + long long read_count = min ((bmpsize - i), BUFSIZE); + size = ntfs_attr_pread (attr, i, read_count, buffer); + if (size < 0) + break; + + for (j = 0; j < size; j++) { + b = buffer[j]; + for (k = 0; k < 8; k++, b>>=1) { + if (((i+j)*8+k) >= nr_mft_records) + goto done; + if (b & 1) + continue; + file = read_record (vol, (i+j)*8+k); + if (!file) { + Eprintf ("Couldn't read MFT Record %d.\n", (i+j)*8+k); + continue; + } + + if ((opts.since > 0) && (file->date <= opts.since)) + goto skip; + if (opts.match && !name_match (&re, file)) + goto skip; + if (opts.size_begin && (opts.size_begin > file->max_size)) + goto skip; + if (opts.size_end && (opts.size_end < file->max_size)) + goto skip; + + percent = calc_percentage (file, vol); + if ((opts.percent == -1) || (percent >= opts.percent)) { + if (opts.verbose) + dump_record (file); + else + list_record (file); + + /* Was -u specified with no inode + so undelete file by regex */ + if (opts.mode == MODE_UNDELETE) { + if (!undelete_file (vol, file->inode)) + Vprintf ("ERROR: Failed to undelete " + "inode %lli\n!", + file->inode); + printf ("\n"); + } + } + if (((opts.percent == -1) && (percent > 0)) || + ((opts.percent > 0) && (percent >= opts.percent))) { + results++; + } +skip: + free_file (file); + } + } + } +done: + Qprintf ("\nFiles with potentially recoverable content: %d\n", results); +out: + if (opts.match) + regfree (&re); + free (buffer); + if (attr) + ntfs_attr_close (attr); + return results; +} + /** * copy_mft - Write a range of MFT Records to a file * @vol: An ntfs volume obtained from ntfs_mount diff --git a/ntfsprogs/ntfsundelete.h b/ntfsprogs/ntfsundelete.h index ace3341b..f4b0271a 100644 --- a/ntfsprogs/ntfsundelete.h +++ b/ntfsprogs/ntfsundelete.h @@ -102,7 +102,7 @@ struct ufile { struct list_head name; /* A list of filenames */ struct list_head data; /* A list of data streams */ char *pref_name; /* Preferred filename */ - char *pref_pname; /* parent filename */ + char *pref_pname; /* parent filename */ long long max_size; /* Largest size we find */ int attr_list; /* MFT record may be one of many */ int directory; /* MFT record represents a directory */ diff --git a/ntfsprogs/sd.c b/ntfsprogs/sd.c index 209281fd..a9c5f82f 100644 --- a/ntfsprogs/sd.c +++ b/ntfsprogs/sd.c @@ -1,5 +1,6 @@ #include "types.h" #include "layout.h" +#include "sd.h" /** * init_system_file_sd @@ -27,7 +28,6 @@ * Do NOT free *@sd_val as it is static memory. This also means that you can * only use *@sd_val until the next call to this function. */ -void init_system_file_sd(int sys_file_no, u8 **sd_val, int *sd_val_len); void init_system_file_sd(int sys_file_no, u8 **sd_val, int *sd_val_len) { static u8 sd_array[0x68]; @@ -200,222 +200,219 @@ void init_system_file_sd(int sys_file_no, u8 **sd_val, int *sd_val_len) sid->sub_authority[1] = cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); } - -/* +/** * init_root_sd_31 (ERSO) * creates the security_descriptor for the root folder on ntfs 3.1. * It is very long ; lot's av ACE's at first, then large pieces of zero's - * the owner user/group is near the end. On a partition created with + * the owner user/group is near the end. On a partition created with * w2k3 the owner user/group at the end is surrounded by 'garbage', which I - * yet do not understand. Here I have replaced the 'garbage' with + * yet do not understand. Here I have replaced the 'garbage' with * zero's, which seems to work. Chkdsk does not add the 'garbage', nor alter * this security descriptor in any way. */ - -void init_root_sd_31(u8 **sd_val, int *sd_val_len); void init_root_sd_31(u8 **sd_val, int *sd_val_len) { - SECURITY_DESCRIPTOR_RELATIVE *sd; - ACL *acl; - ACCESS_ALLOWED_ACE *ace; - SID *sid; + SECURITY_DESCRIPTOR_RELATIVE *sd; + ACL *acl; + ACCESS_ALLOWED_ACE *ace; + SID *sid; static char sd_array[0x1200]; - //char* sd_val = NULL; - *sd_val_len = 0x1200; - *sd_val = (u8*)&sd_array; + //char* sd_val = NULL; + *sd_val_len = 0x1200; + *sd_val = (u8*)&sd_array; - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)&sd_array; - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x1014); - sd->group = cpu_to_le32(0x1024); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)&sd_array; + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x1014); + sd->group = cpu_to_le32(0x1024); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x1000); - acl->ace_count = cpu_to_le16(0x07); - acl->alignment2 = cpu_to_le16(0x00); + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x1000); + acl->ace_count = cpu_to_le16(0x07); + acl->alignment2 = cpu_to_le16(0x00); - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; - ace->size = cpu_to_le16(0x18); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + ace->size = cpu_to_le16(0x18); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | FILE_LIST_DIRECTORY | FILE_WRITE_DATA | FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | FILE_TRAVERSE | FILE_DELETE_CHILD | FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); ace->sid.sub_authority[1] = cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - + //ace2 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; - ace->size = cpu_to_le16(0x14); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + ace->size = cpu_to_le16(0x14); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + ace->sid.sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - //ace3 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | + //ace3 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE; - ace->size = cpu_to_le16(0x14); - ace->mask = cpu_to_le32(0x10000000); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_CREATOR_SID_AUTHORITY (S-1-3) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 3; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_CREATOR_OWNER_RID); + ace->size = cpu_to_le16(0x14); + ace->mask = cpu_to_le32(0x10000000); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_CREATOR_SID_AUTHORITY (S-1-3) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 3; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_CREATOR_OWNER_RID); - //ace4 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; - ace->size = cpu_to_le16(0x18); - ace->mask = cpu_to_le32(0x1200A9); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = + //ace4 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + ace->size = cpu_to_le16(0x18); + ace->mask = cpu_to_le32(0x1200A9); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = cpu_to_le32(DOMAIN_ALIAS_RID_USERS); - //ace5 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = CONTAINER_INHERIT_ACE; - ace->size = cpu_to_le16(0x18); - ace->mask = cpu_to_le32(0x04); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_USERS); + //ace5 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = CONTAINER_INHERIT_ACE; + ace->size = cpu_to_le16(0x18); + ace->mask = cpu_to_le32(0x04); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_USERS); - //ace6 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE; - ace->size = cpu_to_le16(0x18); - ace->mask = cpu_to_le32(0x02); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_USERS); + //ace6 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE; + ace->size = cpu_to_le16(0x18); + ace->mask = cpu_to_le32(0x02); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_USERS); - //ace7 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = cpu_to_le32(0x1200A9); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_WORLD_SID_AUTHORITY (S-1-1) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 1; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_WORLD_RID); + //ace7 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = cpu_to_le32(0x1200A9); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_WORLD_SID_AUTHORITY (S-1-1) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 1; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_WORLD_RID); - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); } @@ -425,420 +422,15 @@ void init_root_sd_31(u8 **sd_val, int *sd_val_len) * NTFS 3.0 - System files security decriptors * =========================================== * Create the security descriptor entries in $SDS data stream like they - * are in a partition, newly formatet with windows 2000 - * + * are in a partition, newly formatted with windows 2000 */ -void init_secure_30(char *sd_val); void init_secure_30(char *sd_val) -{ - SECURITY_DESCRIPTOR_HEADER *sds; - SECURITY_DESCRIPTOR_RELATIVE *sd; - ACL *acl; - ACCESS_ALLOWED_ACE *ace; - SID *sid; - -/* - * security descriptor #1 - */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val); - sds->hash = cpu_to_le32(0xF80312F0); - sds->security_id = cpu_to_le32(0x0100); - sds->offset = cpu_to_le64(0x00); - sds->length = cpu_to_le32(0x7C); - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + - sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x48); - sd->group = cpu_to_le32(0x58); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); - - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x34); - acl->ace_count = cpu_to_le16(0x02); - acl->alignment2 = 0x00; - - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = cpu_to_le32(0x120089); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - //ace2 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x18); - ace->mask = cpu_to_le32(0x120089); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - -/* - * security descriptor #2 - */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80); - sds->hash = cpu_to_le32(0xB32451); - sds->security_id = cpu_to_le32(0x0101); - sds->offset = cpu_to_le64(0x80); - sds->length = cpu_to_le32(0x7C); - - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + - sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x48); - sd->group = cpu_to_le32(0x58); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); - - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x34); - acl->ace_count = cpu_to_le16(0x02); - acl->alignment2 = 0x00; - - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = cpu_to_le32(0x12019F); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - //ace2 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x18); - ace->mask = cpu_to_le32(0x12019F); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - -/* - * security descriptor #3 - */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80); - sds->hash = cpu_to_le32(0x0A9F9562); - sds->security_id = cpu_to_le32(0x0102); - sds->offset = cpu_to_le64(0x0100); - sds->length = cpu_to_le32(0x60); - - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + - sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x30); - sd->group = cpu_to_le32(0x40); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); - - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x1C); - acl->ace_count = cpu_to_le16(0x01); - acl->alignment2 = 0x00; - - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x01; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - -/* - * security descriptor #4 - */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80 + 0x60); - sds->hash = cpu_to_le32(0x453F0A2E); - sds->security_id = cpu_to_le32(0x0103); - sds->offset = cpu_to_le64(0x0160); - sds->length = cpu_to_le32(0x78); - - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + - sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x48); - sd->group = cpu_to_le32(0x58); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); - - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x34); - acl->ace_count = cpu_to_le16(0x02); - acl->alignment2 = 0x00; - - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x18); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - //ace2 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x01; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - return; -} - -/** - * init_secure_31(char **r, int size); - * - * NTFS 3.1 - System files security decriptors - * =========================================== - * Create the security descriptor entries in $SDS data stream like they - * are in a partition, newly formatet with windows 2003 - * - */ -void init_secure_31(char *sd_val); -void init_secure_31(char *sd_val) { SECURITY_DESCRIPTOR_HEADER *sds; - SECURITY_DESCRIPTOR_RELATIVE *sd; - ACL *acl; - ACCESS_ALLOWED_ACE *ace; - SID *sid; + SECURITY_DESCRIPTOR_RELATIVE *sd; + ACL *acl; + ACCESS_ALLOWED_ACE *ace; + SID *sid; /* * security descriptor #1 @@ -850,13 +442,13 @@ void init_secure_31(char *sd_val) sds->offset = cpu_to_le64(0x00); sds->length = cpu_to_le32(0x7C); //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + sizeof(SECURITY_DESCRIPTOR_HEADER)); sd->revision = 0x01; - sd->alignment = 0x00; + sd->alignment = 0x00; sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; sd->owner = cpu_to_le32(0x48); - sd->group = cpu_to_le32(0x58); + sd->group = cpu_to_le32(0x58); sd->sacl = cpu_to_le32(0x00); sd->dacl = cpu_to_le32(0x14); @@ -867,444 +459,838 @@ void init_secure_31(char *sd_val) acl->size = cpu_to_le16(0x34); acl->ace_count = cpu_to_le16(0x02); acl->alignment2 = 0x00; - - + //ace1 ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); ace->type = 0x00; ace->flags = 0x00; ace->size = cpu_to_le16(0x14); ace->mask = cpu_to_le32(0x120089); - ace->sid.revision = 0x01; + ace->sid.revision = 0x01; ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + //ace2 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x18); - ace->mask = cpu_to_le32(0x120089); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x18); + ace->mask = cpu_to_le32(0x120089); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); sid->revision = 0x01; sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + /* * security descriptor #2 */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80); - sds->hash = cpu_to_le32(0xB32451); - sds->security_id = cpu_to_le32(0x0101); - sds->offset = cpu_to_le64(0x80); - sds->length = cpu_to_le32(0x7C); + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80); + sds->hash = cpu_to_le32(0xB32451); + sds->security_id = cpu_to_le32(0x0101); + sds->offset = cpu_to_le64(0x80); + sds->length = cpu_to_le32(0x7C); - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + - sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x48); - sd->group = cpu_to_le32(0x58); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x48); + sd->group = cpu_to_le32(0x58); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x34); - acl->ace_count = cpu_to_le16(0x02); - acl->alignment2 = 0x00; - - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = cpu_to_le32(0x12019F); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - //ace2 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x18); - ace->mask = cpu_to_le32(0x12019F); - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x34); + acl->ace_count = cpu_to_le16(0x02); + acl->alignment2 = 0x00; - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = cpu_to_le32(0x12019F); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //ace2 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x18); + ace->mask = cpu_to_le32(0x12019F); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); /* * security descriptor #3 */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80); - sds->hash = cpu_to_le32(0x0A9F9B62); - sds->security_id = cpu_to_le32(0x0102); - sds->offset = cpu_to_le64(0x0100); - sds->length = cpu_to_le32(0x60); - + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80); + sds->hash = cpu_to_le32(0x0A9F9562); + sds->security_id = cpu_to_le32(0x0102); + sds->offset = cpu_to_le64(0x0100); + sds->length = cpu_to_le32(0x60); - - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x30); - sd->group = cpu_to_le32(0x40); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x30); + sd->group = cpu_to_le32(0x40); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x1C); - acl->ace_count = cpu_to_le16(0x01); - acl->alignment2 = 0x00; + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x1C); + acl->ace_count = cpu_to_le16(0x01); + acl->alignment2 = 0x00; - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; - ace->size = cpu_to_le16(0x14); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x01; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); /* * security descriptor #4 */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80 + 0x60); - sds->hash = cpu_to_le32(0x0A9F9562); - sds->security_id = cpu_to_le32(0x0103); - sds->offset = cpu_to_le64(0x0160); - sds->length = cpu_to_le32(0x60); + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80 + 0x60); + sds->hash = cpu_to_le32(0x453F0A2E); + sds->security_id = cpu_to_le32(0x0103); + sds->offset = cpu_to_le64(0x0160); + sds->length = cpu_to_le32(0x78); - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x30); - sd->group = cpu_to_le32(0x40); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x48); + sd->group = cpu_to_le32(0x58); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x1C); - acl->ace_count = cpu_to_le16(0x01); - acl->alignment2 = 0x00; + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x34); + acl->ace_count = cpu_to_le16(0x02); + acl->alignment2 = 0x00; - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x01; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - - -/* - * security descriptor #5 - */ - //header - sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80 + - 0x60 + 0x60); - sds->hash = cpu_to_le32(0x453F0A2E); - sds->security_id = cpu_to_le32(0x0104); - sds->offset = cpu_to_le64(0x01C0); - sds->length = cpu_to_le32(0x78); - - //security descriptor relative - sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + - sizeof(SECURITY_DESCRIPTOR_HEADER)); - sd->revision = 0x01; - sd->alignment = 0x00; - sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; - sd->owner = cpu_to_le32(0x48); - sd->group = cpu_to_le32(0x58); - sd->sacl = cpu_to_le32(0x00); - sd->dacl = cpu_to_le32(0x14); - - //acl - acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); - acl->revision = 0x02; - acl->alignment1 = 0x00; - acl->size = cpu_to_le16(0x34); - acl->ace_count = cpu_to_le16(0x02); - acl->alignment2 = 0x00; - - //ace1 - ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); - ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x18); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x02; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - ace->sid.sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - //ace2 - ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); ace->type = 0x00; - ace->flags = 0x00; - ace->size = cpu_to_le16(0x14); - ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | - FILE_LIST_DIRECTORY | FILE_WRITE_DATA | - FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | - FILE_TRAVERSE | FILE_DELETE_CHILD | - FILE_READ_ATTRIBUTES; - ace->sid.revision = 0x01; - ace->sid.sub_authority_count = 0x01; - /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ - ace->sid.identifier_authority.value[0] = 0; - ace->sid.identifier_authority.value[1] = 0; - ace->sid.identifier_authority.value[2] = 0; - ace->sid.identifier_authority.value[3] = 0; - ace->sid.identifier_authority.value[4] = 0; - ace->sid.identifier_authority.value[5] = 5; - ace->sid.sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + ace->flags = 0x00; + ace->size = cpu_to_le16(0x18); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //ace2 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); - //owner sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); - sid->revision = 0x01; - sid->sub_authority_count = 0x02; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); - sid->sub_authority[1] = - cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); - //group sid - sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); - sid->revision = 0x01; - sid->sub_authority_count = 0x01; - // SECURITY_NT_SID_AUTHORITY (S-1-5) - sid->identifier_authority.value[0] = 0; - sid->identifier_authority.value[1] = 0; - sid->identifier_authority.value[2] = 0; - sid->identifier_authority.value[3] = 0; - sid->identifier_authority.value[4] = 0; - sid->identifier_authority.value[5] = 5; - sid->sub_authority[0] = - cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x01; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); return; } +/** + * init_secure_31(char **r, int size); + * + * NTFS 3.1 - System files security decriptors + * =========================================== + * Create the security descriptor entries in $SDS data stream like they + * are in a partition, newly formatted with windows 2003 + */ +void init_secure_31(char *sd_val) +{ + SECURITY_DESCRIPTOR_HEADER *sds; + SECURITY_DESCRIPTOR_RELATIVE *sd; + ACL *acl; + ACCESS_ALLOWED_ACE *ace; + SID *sid; + +/* + * security descriptor #1 + */ + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val); + sds->hash = cpu_to_le32(0xF80312F0); + sds->security_id = cpu_to_le32(0x0100); + sds->offset = cpu_to_le64(0x00); + sds->length = cpu_to_le32(0x7C); + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x48); + sd->group = cpu_to_le32(0x58); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); + + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x34); + acl->ace_count = cpu_to_le16(0x02); + acl->alignment2 = 0x00; + + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = cpu_to_le32(0x120089); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + //ace2 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + le32_to_cpu(ace->size)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x18); + ace->mask = cpu_to_le32(0x120089); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); +/* + * security descriptor #2 + */ + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80); + sds->hash = cpu_to_le32(0xB32451); + sds->security_id = cpu_to_le32(0x0101); + sds->offset = cpu_to_le64(0x80); + sds->length = cpu_to_le32(0x7C); + + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x48); + sd->group = cpu_to_le32(0x58); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); + + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x34); + acl->ace_count = cpu_to_le16(0x02); + acl->alignment2 = 0x00; + + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = cpu_to_le32(0x12019F); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + //ace2 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x18); + ace->mask = cpu_to_le32(0x12019F); + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + +/* + * security descriptor #3 + */ + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80); + sds->hash = cpu_to_le32(0x0A9F9B62); + sds->security_id = cpu_to_le32(0x0102); + sds->offset = cpu_to_le64(0x0100); + sds->length = cpu_to_le32(0x60); + + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x30); + sd->group = cpu_to_le32(0x40); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); + + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x1C); + acl->ace_count = cpu_to_le16(0x01); + acl->alignment2 = 0x00; + + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + ace->size = cpu_to_le16(0x14); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + +/* + * security descriptor #4 + */ + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80 + 0x60); + sds->hash = cpu_to_le32(0x0A9F9562); + sds->security_id = cpu_to_le32(0x0103); + sds->offset = cpu_to_le64(0x0160); + sds->length = cpu_to_le32(0x60); + + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x30); + sd->group = cpu_to_le32(0x40); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); + + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x1C); + acl->ace_count = cpu_to_le16(0x01); + acl->alignment2 = 0x00; + + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x01; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + +/* + * security descriptor #5 + */ + //header + sds = (SECURITY_DESCRIPTOR_HEADER*)((char*)sd_val + 0x80 + 0x80 + + 0x60 + 0x60); + sds->hash = cpu_to_le32(0x453F0A2E); + sds->security_id = cpu_to_le32(0x0104); + sds->offset = cpu_to_le64(0x01C0); + sds->length = cpu_to_le32(0x78); + + //security descriptor relative + sd = (SECURITY_DESCRIPTOR_RELATIVE*)((char*)sds + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + sd->revision = 0x01; + sd->alignment = 0x00; + sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; + sd->owner = cpu_to_le32(0x48); + sd->group = cpu_to_le32(0x58); + sd->sacl = cpu_to_le32(0x00); + sd->dacl = cpu_to_le32(0x14); + + //acl + acl = (ACL*)((char*)sd + sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + acl->revision = 0x02; + acl->alignment1 = 0x00; + acl->size = cpu_to_le16(0x34); + acl->ace_count = cpu_to_le16(0x02); + acl->alignment2 = 0x00; + + //ace1 + ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x18); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x02; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + ace->sid.sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + //ace2 + ace = (ACCESS_ALLOWED_ACE*)((char*)ace + ace->size); + ace->type = 0x00; + ace->flags = 0x00; + ace->size = cpu_to_le16(0x14); + ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES | + FILE_LIST_DIRECTORY | FILE_WRITE_DATA | + FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA | + FILE_TRAVERSE | FILE_DELETE_CHILD | + FILE_READ_ATTRIBUTES; + ace->sid.revision = 0x01; + ace->sid.sub_authority_count = 0x01; + /* SECURITY_NT_SID_AUTHORITY (S-1-5) */ + ace->sid.identifier_authority.value[0] = 0; + ace->sid.identifier_authority.value[1] = 0; + ace->sid.identifier_authority.value[2] = 0; + ace->sid.identifier_authority.value[3] = 0; + ace->sid.identifier_authority.value[4] = 0; + ace->sid.identifier_authority.value[5] = 5; + ace->sid.sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + + //owner sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->owner)); + sid->revision = 0x01; + sid->sub_authority_count = 0x02; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = + cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + + //group sid + sid = (SID*)((char*)sd + le32_to_cpu(sd->group)); + sid->revision = 0x01; + sid->sub_authority_count = 0x01; + // SECURITY_NT_SID_AUTHORITY (S-1-5) + sid->identifier_authority.value[0] = 0; + sid->identifier_authority.value[1] = 0; + sid->identifier_authority.value[2] = 0; + sid->identifier_authority.value[3] = 0; + sid->identifier_authority.value[4] = 0; + sid->identifier_authority.value[5] = 5; + sid->sub_authority[0] = + cpu_to_le32(SECURITY_LOCAL_SYSTEM_RID); + + return; +} diff --git a/ntfsprogs/upcase.c b/ntfsprogs/upcase.c index 08cdb0bb..505e7275 100644 --- a/ntfsprogs/upcase.c +++ b/ntfsprogs/upcase.c @@ -29,11 +29,11 @@ #endif #include "types.h" +#include "upcase.h" /** * init_upcase_table */ -void init_upcase_table(ntfschar *uc, u32 uc_len); void init_upcase_table(ntfschar *uc, u32 uc_len) { static int uc_run_table[][3] = { /* Start, End, Add */ diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index fd409371..72e78088 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -50,7 +50,7 @@ #include #endif #ifdef HAVE_LIBINTL_H -# include +#include #endif #ifdef HAVE_STDLIB_H #include @@ -69,6 +69,7 @@ #include "debug.h" #include "dir.h" #include "version.h" +#include "logging.h" const char *ntfs_bugs = "Developers' email address: linux-ntfs-dev@lists.sourceforge.net\n"; const char *ntfs_home = "Linux NTFS homepage: http://linux-ntfs.sourceforge.net\n"; @@ -89,10 +90,10 @@ int utils_set_locale (void) locale = setlocale (LC_ALL, ""); if (!locale) { locale = setlocale (LC_ALL, NULL); - Eprintf ("Failed to set locale, using default '%s'.\n", locale); + ntfs_log_error ("Failed to set locale, using default '%s'.\n", locale); return 1; } else { - Vprintf ("Using locale '%s'.\n", locale); + ntfs_log_verbose ("Using locale '%s'.\n", locale); return 0; } } @@ -125,37 +126,37 @@ int utils_valid_device (const char *name, int force) if (stat (name, &st) == -1) { if (errno == ENOENT) { - Eprintf ("The device %s doesn't exist\n", name); + ntfs_log_error ("The device %s doesn't exist\n", name); } else { - Eprintf ("Error getting information about %s: %s\n", name, strerror (errno)); + ntfs_log_error ("Error getting information about %s: %s\n", name, strerror (errno)); } return 0; } if (!S_ISBLK (st.st_mode)) { - Vprintf ("%s is not a block device.\n", name); + ntfs_log_verbose ("%s is not a block device.\n", name); if (!force) { - Eprintf ("Use the force option to work with files.\n"); + ntfs_log_error ("Use the force option to work with files.\n"); return 0; } - Vprintf ("Forced to continue.\n"); + ntfs_log_verbose ("Forced to continue.\n"); } /* Make sure the file system is not mounted. */ if (ntfs_check_if_mounted (name, &mnt_flags)) { - Vprintf ("Failed to determine whether %s is mounted: %s\n", name, strerror (errno)); + ntfs_log_verbose ("Failed to determine whether %s is mounted: %s\n", name, strerror (errno)); if (!force) { - Eprintf ("Use the force option to ignore this error.\n"); + ntfs_log_error ("Use the force option to ignore this error.\n"); return 0; } - Vprintf ("Forced to continue.\n"); + ntfs_log_verbose ("Forced to continue.\n"); } else if (mnt_flags & NTFS_MF_MOUNTED) { - Vprintf ("The device %s, is mounted.\n", name); + ntfs_log_verbose ("The device %s, is mounted.\n", name); if (!force) { - Eprintf ("Use the force option to work a mounted filesystem.\n"); + ntfs_log_error ("Use the force option to work a mounted filesystem.\n"); return 0; } - Vprintf ("Forced to continue.\n"); + ntfs_log_verbose ("Forced to continue.\n"); } return 1; @@ -181,27 +182,27 @@ ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL int err; err = errno; - Eprintf("Couldn't mount device '%s': %s\n", device, + ntfs_log_error("Couldn't mount device '%s': %s\n", device, strerror(err)); if (err == EPERM) - Eprintf("Windows was hibernated. Try to mount volume " + ntfs_log_error("Windows was hibernated. Try to mount volume " "in windows, shut down and try " "again.\n"); if (err == EOPNOTSUPP) - Eprintf("Windows did not shut down properly. Try to " + ntfs_log_error("Windows did not shut down properly. Try to " "mount volume in windows, shut down " "and try again.\n"); return NULL; } if (vol->flags & VOLUME_IS_DIRTY) { - Qprintf ("Volume is dirty.\n"); + ntfs_log_quiet ("Volume is dirty.\n"); if (!force) { - Eprintf ("Run chkdsk and try again, or use the --force option.\n"); + ntfs_log_error ("Run chkdsk and try again, or use the --force option.\n"); ntfs_umount (vol, FALSE); return NULL; } - Qprintf ("Forced to continue.\n"); + ntfs_log_quiet ("Forced to continue.\n"); } return vol; @@ -241,16 +242,16 @@ int utils_parse_size (const char *value, s64 *size, BOOL scale) return 0; } - Dprintf ("Parsing size '%s'.\n", value); + ntfs_log_debug ("Parsing size '%s'.\n", value); result = strtoll (value, &suffix, 10); if (result < 0 || errno == ERANGE) { - Eprintf ("Invalid size '%s'.\n", value); + ntfs_log_error ("Invalid size '%s'.\n", value); return 0; } if (!suffix) { - Eprintf ("Internal error, strtoll didn't return a suffix.\n"); + ntfs_log_error ("Internal error, strtoll didn't return a suffix.\n"); return 0; } @@ -263,17 +264,17 @@ int utils_parse_size (const char *value, s64 *size, BOOL scale) case '-': case 0: break; default: - Eprintf ("Invalid size suffix '%s'. Use T, G, M, or K.\n", suffix); + ntfs_log_error ("Invalid size suffix '%s'. Use T, G, M, or K.\n", suffix); return 0; } } else { if ((suffix[0] != '-') && (suffix[0] != 0)) { - Eprintf ("Invalid number '%.*s'.\n", (int)(suffix - value + 1), value); + ntfs_log_error ("Invalid number '%.*s'.\n", (int)(suffix - value + 1), value); return 0; } } - Dprintf ("Parsed size = %lld.\n", result); + ntfs_log_debug ("Parsed size = %lld.\n", result); *size = result; return 1; } @@ -303,7 +304,7 @@ int utils_parse_range (const char *string, s64 *start, s64 *finish, BOOL scale) middle = strchr (string, '-'); if (string == middle) { - Dprintf ("Range has no beginning, defaulting to 0.\n"); + ntfs_log_debug ("Range has no beginning, defaulting to 0.\n"); a = 0; } else { if (!utils_parse_size (string, &a, scale)) @@ -313,7 +314,7 @@ int utils_parse_range (const char *string, s64 *start, s64 *finish, BOOL scale) if (middle) { if (middle[1] == 0) { b = LONG_MAX; // XXX ULLONG_MAX - Dprintf ("Range has no end, defaulting to %lld.\n", b); + ntfs_log_debug ("Range has no end, defaulting to %lld.\n", b); } else { if (!utils_parse_size (middle+1, &b, scale)) return 0; @@ -322,7 +323,7 @@ int utils_parse_range (const char *string, s64 *start, s64 *finish, BOOL scale) b = a; } - Dprintf ("Range '%s' = %lld - %lld\n", string, a, b); + ntfs_log_debug ("Range '%s' = %lld - %lld\n", string, a, b); *start = a; *finish = b; @@ -352,11 +353,11 @@ ATTR_RECORD * find_attribute (const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) } if (ntfs_attr_lookup(type, NULL, 0, 0, 0, NULL, 0, ctx) != 0) { - Dprintf ("find_attribute didn't find an attribute of type: 0x%02x.\n", type); + ntfs_log_debug ("find_attribute didn't find an attribute of type: 0x%02x.\n", type); return NULL; /* None / no more of that type */ } - Dprintf ("find_attribute found an attribute of type: 0x%02x.\n", type); + ntfs_log_debug ("find_attribute found an attribute of type: 0x%02x.\n", type); return ctx->attr; } @@ -386,16 +387,16 @@ ATTR_RECORD * find_first_attribute (const ATTR_TYPES type, MFT_RECORD *mft) ctx = ntfs_attr_get_search_ctx (NULL, mft); if (!ctx) { - Eprintf ("Couldn't create a search context.\n"); + ntfs_log_error ("Couldn't create a search context.\n"); return NULL; } rec = find_attribute (type, ctx); ntfs_attr_put_search_ctx (ctx); if (rec) - Dprintf ("find_first_attribute: found attr of type 0x%02x.\n", type); + ntfs_log_debug ("find_first_attribute: found attr of type 0x%02x.\n", type); else - Dprintf ("find_first_attribute: didn't find attr of type 0x%02x.\n", type); + ntfs_log_debug ("find_first_attribute: didn't find attr of type 0x%02x.\n", type); return rec; } @@ -432,18 +433,18 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) vol = inode->vol; - //printf ("sizeof (char*) = %d, sizeof (names) = %d\n", sizeof (char*), sizeof (names)); + //ntfs_log_debug ("sizeof (char*) = %d, sizeof (names) = %d\n", sizeof (char*), sizeof (names)); memset (names, 0, sizeof (names)); for (i = 0; i < max_path; i++) { ctx = ntfs_attr_get_search_ctx (inode, NULL); if (!ctx) { - Eprintf ("Couldn't create a search context.\n"); + ntfs_log_error ("Couldn't create a search context.\n"); return 0; } - //printf ("i = %d, inode = %p (%lld)\n", i, inode, inode->mft_no); + //ntfs_log_debug ("i = %d, inode = %p (%lld)\n", i, inode, inode->mft_no); name_space = 4; while ((rec = find_attribute (AT_FILE_NAME, ctx))) { @@ -465,7 +466,7 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) if (ntfs_ucstombs (attr->file_name, attr->file_name_length, &names[i], 0) < 0) { char *temp; - Eprintf ("Couldn't translate filename to current locale.\n"); + ntfs_log_error ("Couldn't translate filename to current locale.\n"); temp = malloc (30); if (!temp) return 0; @@ -474,8 +475,8 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) names[i] = temp; } - //printf ("names[%d] %s\n", i, names[i]); - //printf ("parent = %lld\n", MREF (parent)); + //ntfs_log_debug ("names[%d] %s\n", i, names[i]); + //ntfs_log_debug ("parent = %lld\n", MREF (parent)); } ntfs_attr_put_search_ctx(ctx); @@ -484,13 +485,13 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) ntfs_inode_close (inode); if (MREF (parent) == FILE_root) { /* The root directory, stop. */ - //printf ("inode 5\n"); + //ntfs_log_debug ("inode 5\n"); break; } inode = ntfs_inode_open (vol, parent); if (!inode) { - Eprintf ("Couldn't open inode %llu.\n", + ntfs_log_error ("Couldn't open inode %llu.\n", (unsigned long long)MREF(parent)); break; } @@ -498,7 +499,7 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) if (i >= max_path) { /* If we get into an infinite loop, we'll end up here. */ - Eprintf ("The directory structure is too deep (over %d) nested directories.\n", max_path); + ntfs_log_error ("The directory structure is too deep (over %d) nested directories.\n", max_path); return 0; } @@ -509,7 +510,7 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) len = snprintf (buffer + offset, bufsize - offset, "%c%s", PATH_SEP, names[i]); if (len >= (bufsize - offset)) { - Eprintf ("Pathname was truncated.\n"); + ntfs_log_error ("Pathname was truncated.\n"); break; } @@ -520,7 +521,7 @@ int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize) for (i = 0; i < max_path; i++) free (names[i]); - Dprintf ("Pathname: %s\n", buffer); + ntfs_log_debug ("Pathname: %s\n", buffer); return 0; } @@ -545,18 +546,18 @@ int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int name = NULL; namelen = ntfs_ucsnlen (attrdef->name, sizeof (attrdef->name)); if (ntfs_ucstombs (attrdef->name, namelen, &name, 0) < 0) { - Eprintf ("Couldn't translate attribute type to current locale.\n"); + ntfs_log_error ("Couldn't translate attribute type to current locale.\n"); // ? return 0; } len = snprintf (buffer, bufsize, "%s", name); } else { - Eprintf ("Unknown attribute type 0x%02x\n", attr->type); + ntfs_log_error ("Unknown attribute type 0x%02x\n", attr->type); len = snprintf (buffer, bufsize, ""); } if (len >= bufsize) { - Eprintf ("Attribute type was truncated.\n"); + ntfs_log_error ("Attribute type was truncated.\n"); return 0; } @@ -571,7 +572,7 @@ int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int namelen = attr->name_length; if (ntfs_ucstombs ((ntfschar *)((char *)attr + attr->name_offset), namelen, &name, 0) < 0) { - Eprintf ("Couldn't translate attribute name to current locale.\n"); + ntfs_log_error ("Couldn't translate attribute name to current locale.\n"); // ? len = snprintf (buffer, bufsize, ""); return 0; @@ -581,7 +582,7 @@ int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int free (name); if (len >= bufsize) { - Eprintf ("Attribute name was truncated.\n"); + ntfs_log_error ("Attribute name was truncated.\n"); return 0; } @@ -620,10 +621,10 @@ int utils_cluster_in_use (ntfs_volume *vol, long long lcn) /* Does lcn lie in the section of $Bitmap we already have cached? */ if ((lcn < bmplcn) || (lcn >= (bmplcn + (sizeof (buffer) << 3)))) { - Dprintf ("Bit lies outside cache.\n"); + ntfs_log_debug ("Bit lies outside cache.\n"); attr = ntfs_attr_open (vol->lcnbmp_ni, AT_DATA, AT_UNNAMED, 0); if (!attr) { - Eprintf ("Couldn't open $Bitmap: %s\n", strerror (errno)); + ntfs_log_error ("Couldn't open $Bitmap: %s\n", strerror (errno)); return -1; } @@ -632,19 +633,18 @@ int utils_cluster_in_use (ntfs_volume *vol, long long lcn) bmplcn = lcn & (~((sizeof (buffer) << 3) - 1)); if (ntfs_attr_pread (attr, (bmplcn>>3), sizeof (buffer), buffer) < 0) { - Eprintf ("Couldn't read $Bitmap: %s\n", strerror (errno)); + ntfs_log_error ("Couldn't read $Bitmap: %s\n", strerror (errno)); ntfs_attr_close (attr); return -1; } - Dprintf ("Reloaded bitmap buffer.\n"); + ntfs_log_debug ("Reloaded bitmap buffer.\n"); ntfs_attr_close (attr); } bit = 1 << (lcn & 7); byte = (lcn >> 3) & (sizeof (buffer) - 1); - Dprintf ("cluster = %lld, bmplcn = %lld, byte = %d, bit = %d, in use %d\n", - lcn, bmplcn, byte, bit, buffer[byte] & bit); + ntfs_log_debug ("cluster = %lld, bmplcn = %lld, byte = %d, bit = %d, in use %d\n", lcn, bmplcn, byte, bit, buffer[byte] & bit); return (buffer[byte] & bit); } @@ -681,24 +681,23 @@ int utils_mftrec_in_use (ntfs_volume *vol, MFT_REF mref) /* Does mref lie in the section of $Bitmap we already have cached? */ if (((s64)MREF(mref) < bmpmref) || ((s64)MREF(mref) >= (bmpmref + (sizeof (buffer) << 3)))) { - Dprintf ("Bit lies outside cache.\n"); + ntfs_log_debug ("Bit lies outside cache.\n"); /* Mark the buffer as not in use, in case the read is shorter. */ memset (buffer, 0, sizeof (buffer)); bmpmref = mref & (~((sizeof (buffer) << 3) - 1)); if (ntfs_attr_pread (vol->mftbmp_na, (bmpmref>>3), sizeof (buffer), buffer) < 0) { - Eprintf ("Couldn't read $MFT/$BITMAP: %s\n", strerror (errno)); + ntfs_log_error ("Couldn't read $MFT/$BITMAP: %s\n", strerror (errno)); return -1; } - Dprintf ("Reloaded bitmap buffer.\n"); + ntfs_log_debug ("Reloaded bitmap buffer.\n"); } bit = 1 << (mref & 7); byte = (mref >> 3) & (sizeof (buffer) - 1); - Dprintf ("cluster = %lld, bmpmref = %lld, byte = %d, bit = %d, in use %d\n", - mref, bmpmref, byte, bit, buffer[byte] & bit); + ntfs_log_debug ("cluster = %lld, bmpmref = %lld, byte = %d, bit = %d, in use %d\n", mref, bmpmref, byte, bit, buffer[byte] & bit); return (buffer[byte] & bit); } @@ -804,38 +803,38 @@ void utils_dump_mem (void *buf, int start, int length, int flags) if (flags & DM_BLUE) col += 4; if (flags & DM_INDENT) - printf ("\t"); + ntfs_log_debug ("\t"); if (flags & DM_BOLD) - printf ("\e[01m"); + ntfs_log_debug ("\e[01m"); if (flags & (DM_RED | DM_BLUE | DM_GREEN | DM_BOLD)) - printf ("\e[%dm", col); + ntfs_log_debug ("\e[%dm", col); if (off == s) - printf("%6.6x ", start); + ntfs_log_debug("%6.6x ", start); else - printf("%6.6x ", off); + ntfs_log_debug("%6.6x ", off); for (i = 0; i < 16; i++) { if ((i == 8) && (!(flags & DM_NO_DIVIDER))) - printf (" -"); + ntfs_log_debug (" -"); if (((off+i) >= start) && ((off+i) < (start+length))) - printf (" %02X", mem[off+i]); + ntfs_log_debug (" %02X", mem[off+i]); else - printf (" "); + ntfs_log_debug (" "); } if (!(flags & DM_NO_ASCII)) { - printf (" "); + ntfs_log_debug (" "); for (i = 0; i < 16; i++) { if (((off+i) < start) || ((off+i) >= (start+length))) - printf (" "); + ntfs_log_debug (" "); else if (isprint (mem[off + i])) - printf ("%c", mem[off + i]); + ntfs_log_debug ("%c", mem[off + i]); else - printf ("."); + ntfs_log_debug ("."); } } if (flags & (DM_RED | DM_BLUE | DM_GREEN | DM_BOLD)) - printf ("\e[0m"); - printf ("\n"); + ntfs_log_debug ("\e[0m"); + ntfs_log_debug ("\n"); } } @@ -902,7 +901,7 @@ int mft_next_record (struct mft_search_ctx *ctx) ctx->flags_match = 0; in_use = utils_mftrec_in_use (ctx->vol, (MFT_REF) ctx->mft_num); if (in_use == -1) { - Eprintf ("Error reading inode %llu. Aborting.\n", + ntfs_log_error ("Error reading inode %llu. Aborting.\n", (unsigned long long)ctx->mft_num); return -1; } @@ -912,7 +911,7 @@ int mft_next_record (struct mft_search_ctx *ctx) ctx->inode = ntfs_inode_open (ctx->vol, (MFT_REF) ctx->mft_num); if (ctx->inode == NULL) { - Eprintf ("Error reading inode %llu.\n", (unsigned + ntfs_log_error ("Error reading inode %llu.\n", (unsigned long long) ctx->mft_num); continue; } @@ -940,7 +939,7 @@ int mft_next_record (struct mft_search_ctx *ctx) ntfs_attr_put_search_ctx (attr_ctx); } else { - Eprintf ("Couldn't create a search context.\n"); + ntfs_log_error ("Couldn't create a search context.\n"); return -1; } } @@ -950,7 +949,7 @@ int mft_next_record (struct mft_search_ctx *ctx) case 0: ctx->flags_match |= FEMR_NOT_METADATA; break; default: ctx->flags_match |= FEMR_NOT_METADATA; break; - //Eprintf ("Error reading inode %lld.\n", ctx->mft_num); + //ntfs_log_error ("Error reading inode %lld.\n", ctx->mft_num); //return -1; } @@ -961,7 +960,7 @@ int mft_next_record (struct mft_search_ctx *ctx) ctx->inode = calloc (1, sizeof (*ctx->inode)); if (!ctx->inode) { - Eprintf ("Out of memory. Aborting.\n"); + ntfs_log_error ("Out of memory. Aborting.\n"); return -1; } @@ -970,20 +969,20 @@ int mft_next_record (struct mft_search_ctx *ctx) ctx->inode->mrec = malloc (ctx->vol->mft_record_size); if (!ctx->inode->mrec) { free (ctx->inode); // == ntfs_inode_close - Eprintf ("Out of memory. Aborting.\n"); + ntfs_log_error ("Out of memory. Aborting.\n"); return -1; } mft = ntfs_attr_open (ctx->vol->mft_ni, AT_DATA, AT_UNNAMED, 0); if (!mft) { - Eprintf ("Couldn't open $MFT/$DATA: %s\n", strerror (errno)); + ntfs_log_error ("Couldn't open $MFT/$DATA: %s\n", strerror (errno)); // free / close return -1; } if (ntfs_attr_pread (mft, ctx->vol->mft_record_size * ctx->mft_num, ctx->vol->mft_record_size, ctx->inode->mrec) < ctx->vol->mft_record_size) { - Eprintf ("Couldn't read MFT Record %llu: %s.\n", + ntfs_log_error ("Couldn't read MFT Record %llu: %s.\n", (unsigned long long) ctx->mft_num, strerror (errno)); // free / close @@ -999,7 +998,7 @@ int mft_next_record (struct mft_search_ctx *ctx) } if (ntfs_inode_close (ctx->inode)) { - Eprintf ("Error closing inode %llu.\n", + ntfs_log_error ("Error closing inode %llu.\n", (unsigned long long)ctx->mft_num); return -errno; } diff --git a/ntfsprogs/utils.h b/ntfsprogs/utils.h index 40b50e6a..f6c09d0e 100644 --- a/ntfsprogs/utils.h +++ b/ntfsprogs/utils.h @@ -31,9 +31,13 @@ #include "layout.h" #include "volume.h" +#ifdef HAVE_ERRNO_H #include +#endif +#ifdef HAVE_STDARG_H #include -#include +#endif +//#include extern const char *ntfs_bugs; extern const char *ntfs_home; @@ -42,7 +46,6 @@ extern const char *ntfs_gpl; #if !defined(REG_NOERROR) || (REG_NOERROR != 0) # define REG_NOERROR 0 #endif - #define DEC_PRINTF(NAME) \ int NAME (const char *format, ...) \ __attribute__ ((format (printf, 1, 2))); @@ -67,6 +70,7 @@ extern const char *ntfs_gpl; return ret; \ } + /* utils.c's utilities require the following functions implemented. * Example of implementation is: * GEN_PRINTF (Eprintf, stderr, NULL, FALSE)