Introduce sparse endian annotations. Adopt library (also fix 2 real bugs) and progs (lots of bugs).

edge.strict_endians
Yura Pakhuchiy 2007-06-08 13:47:57 +03:00
parent def36146b7
commit 0d264b7d25
30 changed files with 835 additions and 672 deletions

View File

@ -2,7 +2,7 @@
* attrib.h - Exports for attribute handling. Part of the Linux-NTFS project.
*
* Copyright (c) 2000-2004 Anton Altaparmakov
* Copyright (c) 2004-2005 Yura Pakhuchiy
* Copyright (c) 2004-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -203,25 +203,25 @@ typedef enum {
#define NAttrSetNonResident(na) set_nattr_flag(na, NonResident)
#define NAttrClearNonResident(na) clear_nattr_flag(na, NonResident)
#define GenNAttrIno(func_name,flag) \
static inline int NAttr##func_name(ntfs_attr *na) \
{ \
if (na->type == AT_DATA && na->name == AT_UNNAMED) \
return (na->ni->flags & FILE_ATTR_##flag); \
return 0; \
} \
static inline void NAttrSet##func_name(ntfs_attr *na) \
{ \
if (na->type == AT_DATA && na->name == AT_UNNAMED) \
na->ni->flags |= FILE_ATTR_##flag; \
else \
ntfs_log_trace("BUG! Should be called only for "\
"unnamed data attribute.\n"); \
} \
static inline void NAttrClear##func_name(ntfs_attr *na) \
{ \
if (na->type == AT_DATA && na->name == AT_UNNAMED) \
na->ni->flags &= ~FILE_ATTR_##flag; \
#define GenNAttrIno(func_name,flag) \
static inline int NAttr##func_name(ntfs_attr *na) \
{ \
if (na->type == AT_DATA && na->name == AT_UNNAMED) \
return (na->ni->flags & FILE_ATTR_##flag) ? 1 : 0; \
return 0; \
} \
static inline void NAttrSet##func_name(ntfs_attr *na) \
{ \
if (na->type == AT_DATA && na->name == AT_UNNAMED) \
na->ni->flags |= FILE_ATTR_##flag; \
else \
ntfs_log_trace("BUG! Should be called only for " \
"unnamed data attribute.\n"); \
} \
static inline void NAttrClear##func_name(ntfs_attr *na) \
{ \
if (na->type == AT_DATA && na->name == AT_UNNAMED) \
na->ni->flags &= ~FILE_ATTR_##flag; \
}
GenNAttrIno(Compressed, COMPRESSED)

View File

@ -3,6 +3,7 @@
* Linux-NTFS project.
*
* Copyright (c) 2000-2005 Anton Altaparmakov
* Copyright (c) 2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -110,39 +111,42 @@
#if defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN)
#define __le16_to_cpu(x) (x)
#define __le32_to_cpu(x) (x)
#define __le64_to_cpu(x) (x)
#define __le16_to_cpu(x) ((__force u16)(x))
#define __le32_to_cpu(x) ((__force u32)(x))
#define __le64_to_cpu(x) ((__force u64)(x))
#define __cpu_to_le16(x) (x)
#define __cpu_to_le32(x) (x)
#define __cpu_to_le64(x) (x)
#define __cpu_to_le16(x) ((__force le16)(x))
#define __cpu_to_le32(x) ((__force le32)(x))
#define __cpu_to_le64(x) ((__force le64)(x))
#define __constant_le16_to_cpu(x) (x)
#define __constant_le32_to_cpu(x) (x)
#define __constant_le64_to_cpu(x) (x)
#define __constant_le16_to_cpu(x) ((__force u16)(x))
#define __constant_le32_to_cpu(x) ((__force u32)(x))
#define __constant_le64_to_cpu(x) ((__force u64)(x))
#define __constant_cpu_to_le16(x) (x)
#define __constant_cpu_to_le32(x) (x)
#define __constant_cpu_to_le64(x) (x)
#define __constant_cpu_to_le16(x) ((__force le16)(x))
#define __constant_cpu_to_le32(x) ((__force le32)(x))
#define __constant_cpu_to_le64(x) ((__force le64)(x))
#elif defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN)
#define __le16_to_cpu(x) bswap_16(x)
#define __le32_to_cpu(x) bswap_32(x)
#define __le64_to_cpu(x) bswap_64(x)
#define __le16_to_cpu(x) bswap_16((__force u16)(x))
#define __le32_to_cpu(x) bswap_32((__force u16)(x))
#define __le64_to_cpu(x) bswap_64((__force u16)(x))
#define __cpu_to_le16(x) bswap_16(x)
#define __cpu_to_le32(x) bswap_32(x)
#define __cpu_to_le64(x) bswap_64(x)
#define __cpu_to_le16(x) (__force le16)bswap_16((__force u16)(x))
#define __cpu_to_le32(x) (__force le32)bswap_32((__force u32)(x))
#define __cpu_to_le64(x) (__force le64)bswap_64((__force u64)(x))
#define __constant_le16_to_cpu(x) __ntfs_bswap_constant_16((u16)(x))
#define __constant_le32_to_cpu(x) __ntfs_bswap_constant_32((u32)(x))
#define __constant_le64_to_cpu(x) __ntfs_bswap_constant_64((u64)(x))
#define __constant_le16_to_cpu(x) __ntfs_bswap_constant_16((__force u16)(x))
#define __constant_le32_to_cpu(x) __ntfs_bswap_constant_32((__force u32)(x))
#define __constant_le64_to_cpu(x) __ntfs_bswap_constant_64((__force u64)(x))
#define __constant_cpu_to_le16(x) __ntfs_bswap_constant_16((u16)(x))
#define __constant_cpu_to_le32(x) __ntfs_bswap_constant_32((u32)(x))
#define __constant_cpu_to_le64(x) __ntfs_bswap_constant_64((u64)(x))
#define __constant_cpu_to_le16(x) \
(__force le16)__ntfs_bswap_constant_16((__force u16)(x))
#define __constant_cpu_to_le32(x) \
(__force le32)__ntfs_bswap_constant_32((__force u32)(x))
#define __constant_cpu_to_le64(x) \
(__force le64)__ntfs_bswap_constant_64((__force u64)(x))
#else
@ -152,52 +156,83 @@
/* Unsigned from LE to CPU conversion. */
#define le16_to_cpu(x) (u16)__le16_to_cpu((u16)(x))
#define le32_to_cpu(x) (u32)__le32_to_cpu((u32)(x))
#define le64_to_cpu(x) (u64)__le64_to_cpu((u64)(x))
#define le16_to_cpu(x) (u16)__le16_to_cpu((le16)(x))
#define le32_to_cpu(x) (u32)__le32_to_cpu((le32)(x))
#define le64_to_cpu(x) (u64)__le64_to_cpu((le64)(x))
#define le16_to_cpup(x) (u16)__le16_to_cpu(*(const u16*)(x))
#define le32_to_cpup(x) (u32)__le32_to_cpu(*(const u32*)(x))
#define le64_to_cpup(x) (u64)__le64_to_cpu(*(const u64*)(x))
#define le16_to_cpup(x) (u16)__le16_to_cpu(*(const le16*)(x))
#define le32_to_cpup(x) (u32)__le32_to_cpu(*(const le32*)(x))
#define le64_to_cpup(x) (u64)__le64_to_cpu(*(const le64*)(x))
/* Signed from LE to CPU conversion. */
#define sle16_to_cpu(x) (s16)__le16_to_cpu((s16)(x))
#define sle32_to_cpu(x) (s32)__le32_to_cpu((s32)(x))
#define sle64_to_cpu(x) (s64)__le64_to_cpu((s64)(x))
#define sle16_to_cpu(x) (s16)__le16_to_cpu((sle16)(x))
#define sle32_to_cpu(x) (s32)__le32_to_cpu((sle32)(x))
#define sle64_to_cpu(x) (s64)__le64_to_cpu((sle64)(x))
#define sle16_to_cpup(x) (s16)__le16_to_cpu(*(s16*)(x))
#define sle32_to_cpup(x) (s32)__le32_to_cpu(*(s32*)(x))
#define sle64_to_cpup(x) (s64)__le64_to_cpu(*(s64*)(x))
#define sle16_to_cpup(x) (s16)__le16_to_cpu(*(const sle16*)(x))
#define sle32_to_cpup(x) (s32)__le32_to_cpu(*(const sle32*)(x))
#define sle64_to_cpup(x) (s64)__le64_to_cpu(*(const sle64*)(x))
/* Unsigned from CPU to LE conversion. */
#define cpu_to_le16(x) (u16)__cpu_to_le16((u16)(x))
#define cpu_to_le32(x) (u32)__cpu_to_le32((u32)(x))
#define cpu_to_le64(x) (u64)__cpu_to_le64((u64)(x))
#define cpu_to_le16(x) (le16)__cpu_to_le16((u16)(x))
#define cpu_to_le32(x) (le32)__cpu_to_le32((u32)(x))
#define cpu_to_le64(x) (le64)__cpu_to_le64((u64)(x))
#define cpu_to_le16p(x) (u16)__cpu_to_le16(*(u16*)(x))
#define cpu_to_le32p(x) (u32)__cpu_to_le32(*(u32*)(x))
#define cpu_to_le64p(x) (u64)__cpu_to_le64(*(u64*)(x))
#define cpu_to_le16p(x) (le16)__cpu_to_le16(*(const u16*)(x))
#define cpu_to_le32p(x) (le32)__cpu_to_le32(*(const u32*)(x))
#define cpu_to_le64p(x) (le64)__cpu_to_le64(*(const u64*)(x))
/* Signed from CPU to LE conversion. */
#define cpu_to_sle16(x) (s16)__cpu_to_le16((s16)(x))
#define cpu_to_sle32(x) (s32)__cpu_to_le32((s32)(x))
#define cpu_to_sle64(x) (s64)__cpu_to_le64((s64)(x))
#define cpu_to_sle16(x) (__force sle16)__cpu_to_le16((s16)(x))
#define cpu_to_sle32(x) (__force sle32)__cpu_to_le32((s32)(x))
#define cpu_to_sle64(x) (__force sle64)__cpu_to_le64((s64)(x))
#define cpu_to_sle16p(x) (s16)__cpu_to_le16(*(s16*)(x))
#define cpu_to_sle32p(x) (s32)__cpu_to_le32(*(s32*)(x))
#define cpu_to_sle64p(x) (s64)__cpu_to_le64(*(s64*)(x))
#define cpu_to_sle16p(x) (__force sle16)__cpu_to_le16(*(const s16*)(x))
#define cpu_to_sle32p(x) (__force sle32)__cpu_to_le32(*(const s32*)(x))
#define cpu_to_sle64p(x) (__force sle64)__cpu_to_le64(*(const s64*)(x))
/* Constant endianness conversion defines. */
#define const_le16_to_cpu(x) __constant_le16_to_cpu(x)
#define const_le32_to_cpu(x) __constant_le32_to_cpu(x)
#define const_le64_to_cpu(x) __constant_le64_to_cpu(x)
#define const_le16_to_cpu(x) (u16)__constant_le16_to_cpu((le16)(x))
#define const_le32_to_cpu(x) (u32)__constant_le32_to_cpu((le32)(x))
#define const_le64_to_cpu(x) (u64)__constant_le64_to_cpu((le64)(x))
#define const_cpu_to_le16(x) __constant_cpu_to_le16(x)
#define const_cpu_to_le32(x) __constant_cpu_to_le32(x)
#define const_cpu_to_le64(x) __constant_cpu_to_le64(x)
#define const_cpu_to_le16(x) (le16)__constant_cpu_to_le16((u16)(x))
#define const_cpu_to_le32(x) (le32)__constant_cpu_to_le32((u32)(x))
#define const_cpu_to_le64(x) (le64)__constant_cpu_to_le64((u64)(x))
#ifdef __CHECKER__
static void ntfs_endian_self_test(void)
{
/* Should not generate warnings. */
(le16)cpu_to_le16((u16)0);
(le32)cpu_to_le32((u32)0);
(le64)cpu_to_le64((u64)0);
(sle16)cpu_to_sle16((s16)0);
(sle32)cpu_to_sle32((s32)0);
(sle64)cpu_to_sle64((s64)0);
(u16)le16_to_cpu((__force le16)0);
(u32)le32_to_cpu((__force le32)0);
(u64)le64_to_cpu((__force le64)0);
(s16)sle16_to_cpu((__force sle16)0);
(s32)sle32_to_cpu((__force sle32)0);
(s64)sle64_to_cpu((__force sle64)0);
(le16)const_cpu_to_le16((u16)0);
(le32)const_cpu_to_le32((u32)0);
(le64)const_cpu_to_le64((u64)0);
(u16)const_le16_to_cpu((__force le16)0);
(u32)const_le32_to_cpu((__force le32)0);
(u64)const_le64_to_cpu((__force le64)0);
/*
* TODO: Need some how to test that warnings are actually generated,
* but without flooding output with them and vice-versa print warning
* in case if some one warning is not triggered, but should. Any ideas?
*/
}
#endif
#endif /* defined _NTFS_ENDIANS_H */

View File

@ -2,7 +2,7 @@
* inode.h - Defines for NTFS inode handling. Part of the Linux-NTFS project.
*
* Copyright (c) 2001,2002 Anton Altaparmakov
* Copyright (c) 2004-2005 Yura Pakhuchiy
* Copyright (c) 2004-2007 Yura Pakhuchiy
* Copyright (c) 2004-2005 Richard Russon
*
* This program/include file is free software; you can redistribute it and/or
@ -155,7 +155,7 @@ extern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref);
extern int ntfs_inode_close(ntfs_inode *ni);
extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni,
const MFT_REF mref);
const leMFT_REF mref);
extern int ntfs_inode_attach_all_extents(ntfs_inode *ni);

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
* logfile.h - Exports for $LogFile handling. Part of the Linux-NTFS project.
*
* Copyright (c) 2000-2005 Anton Altaparmakov
* Copyright (c) 2005-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -110,7 +111,8 @@ typedef struct {
*/
enum {
RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
RESTART_SPACE_FILLER = 0xffff, /* gcc: Force enum bit width to 16. */
RESTART_SPACE_FILLER = const_cpu_to_le16(0xffff),
/* gcc: Force enum bit width to 16. */
} __attribute__((__packed__));
typedef le16 RESTART_AREA_FLAGS;

View File

@ -1,8 +1,8 @@
/*
* ntfstime.h - NTFS time related functions. Part of the Linux-NTFS project.
*
* Copyright (c) 2005 Anton Altaparmakov
* Copyright (c) 2005 Yura Pakhuchiy
* Copyright (c) 2005 Anton Altaparmakov
* Copyright (c) 2005-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -40,7 +40,7 @@
*
* Return: n A Unix time (number of seconds since 1970)
*/
static __inline__ time_t ntfs2utc(s64 ntfs_time)
static __inline__ time_t ntfs2utc(sle64 ntfs_time)
{
return (sle64_to_cpu(ntfs_time) - (NTFS_TIME_OFFSET)) / 10000000;
}
@ -60,7 +60,7 @@ static __inline__ time_t ntfs2utc(s64 ntfs_time)
*
* Return: n An NTFS time (100ns units since Jan 1601)
*/
static __inline__ s64 utc2ntfs(time_t utc_time)
static __inline__ sle64 utc2ntfs(time_t utc_time)
{
/* Convert to 100ns intervals and then add the NTFS time offset. */
return cpu_to_sle64((s64)utc_time * 10000000 + NTFS_TIME_OFFSET);

View File

@ -4,6 +4,7 @@
*
* Copyright (c) 2000-2004 Anton Altaparmakov
* Copyright (c) 2006 Szabolcs Szakacsits
* Copyright (c) 2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -47,8 +48,10 @@ typedef int64_t s64;
#ifdef __CHECKER__
#define __bitwise __attribute__((bitwise))
#define __force __attribute__((force))
#else
#define __bitwise
#define __force
#endif
typedef u16 __bitwise le16;
@ -63,7 +66,11 @@ typedef u16 __bitwise sle16;
typedef u32 __bitwise sle32;
typedef u64 __bitwise sle64;
typedef u16 ntfschar; /* 2-byte Unicode character type. */
typedef u16 __bitwise be16;
typedef u32 __bitwise be32;
typedef u64 __bitwise be64;
typedef le16 ntfschar; /* 2-byte Unicode character type. */
#define UCHAR_T_SIZE_BITS 1
/*

View File

@ -2,7 +2,7 @@
* volume.h - Exports for NTFS volume handling. Part of the Linux-NTFS project.
*
* Copyright (c) 2000-2004 Anton Altaparmakov
* Copyright (c) 2005-2006 Yura Pakhuchiy
* Copyright (c) 2005-2007 Yura Pakhuchiy
* Copyright (c) 2004-2005 Richard Russon
*
* This program/include file is free software; you can redistribute it and/or
@ -151,7 +151,7 @@ struct _ntfs_volume {
ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */
u8 major_ver; /* Ntfs major version of volume. */
u8 minor_ver; /* Ntfs minor version of volume. */
u16 flags; /* Bit array of VOLUME_* flags. */
le16 flags; /* Bit array of VOLUME_* flags. */
GUID guid; /* The volume guid if present (otherwise it is
a NULL guid). */
@ -234,6 +234,6 @@ extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
extern int ntfs_version_is_supported(ntfs_volume *vol);
extern int ntfs_logfile_reset(ntfs_volume *vol);
extern int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags);
extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags);
#endif /* defined _NTFS_VOLUME_H */

View File

@ -4,7 +4,7 @@
* Copyright (c) 2000-2006 Anton Altaparmakov
* Copyright (c) 2002-2005 Richard Russon
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2004-2006 Yura Pakhuchiy
* Copyright (c) 2004-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -393,7 +393,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type,
*/
if (type == AT_ATTRIBUTE_LIST)
a->flags = 0;
cs = a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE);
cs = (a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? 1 : 0;
if (!name) {
if (a->name_length) {
name = ntfs_ucsndup((ntfschar*)((u8*)a + le16_to_cpu(
@ -410,9 +410,9 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type,
}
__ntfs_attr_init(na, ni, type, name, name_len);
if (a->non_resident) {
ntfs_attr_init(na, TRUE, a->flags & ATTR_IS_COMPRESSED,
a->flags & ATTR_IS_ENCRYPTED,
a->flags & ATTR_IS_SPARSE,
ntfs_attr_init(na, TRUE, (a->flags & ATTR_IS_COMPRESSED)? 1 : 0,
(a->flags & ATTR_IS_ENCRYPTED) ? 1 : 0,
(a->flags & ATTR_IS_SPARSE) ? 1 : 0,
sle64_to_cpu(a->allocated_size),
sle64_to_cpu(a->data_size),
sle64_to_cpu(a->initialized_size),
@ -420,10 +420,10 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type,
cs ? a->compression_unit : 0);
} else {
s64 l = le32_to_cpu(a->value_length);
ntfs_attr_init(na, FALSE, a->flags & ATTR_IS_COMPRESSED,
a->flags & ATTR_IS_ENCRYPTED,
a->flags & ATTR_IS_SPARSE, (l + 7) & ~7, l, l,
cs ? (l + 7) & ~7 : 0, 0);
ntfs_attr_init(na, FALSE, (a->flags & ATTR_IS_COMPRESSED) ? 1:0,
(a->flags & ATTR_IS_ENCRYPTED) ? 1 : 0,
(a->flags & ATTR_IS_SPARSE) ? 1 : 0,
(l + 7) & ~7, l, l, cs ? (l + 7) & ~7 : 0, 0);
}
ntfs_attr_put_search_ctx(ctx);
return na;
@ -2622,7 +2622,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
ntfs_inode *base_ni;
ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n",
(long long) ni->mft_no, (unsigned) type, (unsigned) flags);
(long long) ni->mft_no, le32_to_cpu(type), le16_to_cpu(flags));
if (!ni || (!name && name_len)) {
errno = EINVAL;
@ -2746,9 +2746,9 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, "
"dataruns_size %d, flags 0x%x.\n",
(long long) ni->mft_no, (unsigned) type,
(long long) ni->mft_no, le32_to_cpu(type),
(long long) lowest_vcn, dataruns_size,
(unsigned) flags);
le16_to_cpu(flags));
if (!ni || dataruns_size <= 0 || (!name && name_len)) {
errno = EINVAL;
@ -3226,7 +3226,7 @@ rm_attr_err_out:
free_err_out:
/* Free MFT record, if it isn't contain attributes. */
if (le32_to_cpu(attr_ni->mrec->bytes_in_use) -
le32_to_cpu(attr_ni->mrec->attrs_offset) == 8) {
le16_to_cpu(attr_ni->mrec->attrs_offset) == 8) {
if (ntfs_mft_record_free(attr_ni->vol, attr_ni)) {
ntfs_log_trace("Failed to free MFT record. Leaving "
"inconsistent metadata.\n");

View File

@ -3,7 +3,7 @@
* project.
*
* Copyright (c) 2004-2005 Anton Altaparmakov
* Copyright (c) 2004-2005 Yura Pakhuchiy
* Copyright (c) 2004-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -105,7 +105,7 @@ int ntfs_attrlist_need(ntfs_inode *ni)
int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr)
{
ATTR_LIST_ENTRY *ale;
MFT_REF mref;
leMFT_REF mref;
ntfs_attr *na = NULL;
ntfs_attr_search_ctx *ctx;
u8 *new_al;
@ -152,7 +152,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr)
if (!ntfs_attr_lookup(attr->type, (attr->name_length) ? (ntfschar*)
((u8*)attr + le16_to_cpu(attr->name_offset)) :
AT_UNNAMED, attr->name_length, CASE_SENSITIVE,
(attr->non_resident) ? le64_to_cpu(attr->lowest_vcn) :
(attr->non_resident) ? sle64_to_cpu(attr->lowest_vcn) :
0, (attr->non_resident) ? NULL : ((u8*)attr +
le16_to_cpu(attr->value_offset)), (attr->non_resident) ?
0 : le32_to_cpu(attr->value_length), ctx)) {
@ -264,10 +264,10 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx)
base_ni = ctx->ntfs_ino;
ale = ctx->al_entry;
ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld.\n",
(long long) ctx->ntfs_ino->mft_no,
ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld."
"\n", (long long) ctx->ntfs_ino->mft_no,
(unsigned) le32_to_cpu(ctx->al_entry->type),
(long long) le64_to_cpu(ctx->al_entry->lowest_vcn));
(long long) sle64_to_cpu(ctx->al_entry->lowest_vcn));
if (!NInoAttrList(base_ni)) {
ntfs_log_trace("Attribute list isn't present.\n");

View File

@ -2,7 +2,7 @@
* dir.c - Directory handling code. Part of the Linux-NTFS project.
*
* Copyright (c) 2002-2005 Anton Altaparmakov
* Copyright (c) 2005-2006 Yura Pakhuchiy
* Copyright (c) 2005-2007 Yura Pakhuchiy
* Copyright (c) 2004-2005 Richard Russon
*
* This program/include file is free software; you can redistribute it and/or

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2004-2005 Anton Altaparmakov
* Copyright (c) 2004-2005 Richard Russon
* Copyright (c) 2005-2006 Yura Pakhuchiy
* Copyright (c) 2005-2007 Yura Pakhuchiy
* Copyright (c) 2005-2006 Szabolcs Szakacsits
*
* This program/include file is free software; you can redistribute it and/or
@ -193,9 +193,9 @@ void ntfs_index_ctx_reinit(ntfs_index_context *icx)
};
}
static VCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie)
static leVCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie)
{
return (VCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(VCN));
return (leVCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(VCN));
}
/**
@ -224,7 +224,7 @@ static u8 *ntfs_ie_get_end(INDEX_HEADER *ih)
static int ntfs_ie_end(INDEX_ENTRY *ie)
{
return ie->flags & INDEX_ENTRY_END;
return (ie->flags & INDEX_ENTRY_END) ? 1 : 0;
}
/**
@ -344,7 +344,7 @@ static void ntfs_ie_delete(INDEX_HEADER *ih, INDEX_ENTRY *ie)
static void ntfs_ie_set_vcn(INDEX_ENTRY *ie, VCN vcn)
{
*ntfs_ie_get_vcn_addr(ie) = cpu_to_le64(vcn);
*ntfs_ie_get_vcn_addr(ie) = cpu_to_sle64(vcn);
}
/**
@ -811,8 +811,8 @@ static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size,
ib->usa_ofs = cpu_to_le16(sizeof(INDEX_BLOCK));
ib->usa_count = cpu_to_le16(ib_size / NTFS_BLOCK_SIZE + 1);
/* Set USN to 1 */
*(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = cpu_to_le16(1);
ib->lsn = cpu_to_le64(0);
*(le16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = cpu_to_le16(1);
ib->lsn = 0;
ib->index_block_vcn = cpu_to_sle64(ib_vcn);

View File

@ -2,7 +2,7 @@
* inode.c - Inode handling code. Part of the Linux-NTFS project.
*
* Copyright (c) 2002-2005 Anton Altaparmakov
* Copyright (c) 2004-2005 Yura Pakhuchiy
* Copyright (c) 2004-2007 Yura Pakhuchiy
* Copyright (c) 2004-2005 Richard Russon
*
* This program/include file is free software; you can redistribute it and/or
@ -343,7 +343,7 @@ int ntfs_inode_close(ntfs_inode *ni)
* Note, extent inodes are never closed directly. They are automatically
* disposed off by the closing of the base inode.
*/
ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref)
ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const leMFT_REF mref)
{
u64 mft_no = MREF_LE(mref);
ntfs_inode *ni;
@ -453,8 +453,7 @@ int ntfs_inode_attach_all_extents(ntfs_inode *ni)
while ((u8*)ale < ni->attr_list + ni->attr_list_size) {
if (ni->mft_no != MREF_LE(ale->mft_reference) &&
prev_attached != MREF_LE(ale->mft_reference)) {
if (!ntfs_extent_inode_open(ni,
MREF_LE(ale->mft_reference))) {
if (!ntfs_extent_inode_open(ni, ale->mft_reference)) {
ntfs_log_trace("Couldn't attach extent "
"inode (attr type 0x%x "
"references to it).\n",
@ -1143,8 +1142,8 @@ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr)
}
if (ustr && ntfs_names_are_equal(ustr, len,
(ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)),
attr->name_length, 0, NULL, 0))
(ntfschar *)((u8 *)attr + le16_to_cpu(
attr->name_offset)), attr->name_length, 0, NULL, 0))
ret = 1;
ntfs_ucsfree(ustr);

View File

@ -2,7 +2,7 @@
* mft.c - Mft record handling code. Part of the Linux-NTFS project.
*
* Copyright (c) 2000-2004 Anton Altaparmakov
* Copyright (c) 2005 Yura Pakhuchiy
* Copyright (c) 2005-2007 Yura Pakhuchiy
* Copyright (c) 2004-2005 Richard Russon
*
* This program/include file is free software; you can redistribute it and/or
@ -323,7 +323,7 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref,
"Thank you.\n", NTFS_DEV_LIST);
}
/* Set the update sequence number to 1. */
*(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = cpu_to_le16(1);
*(le16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = cpu_to_le16(1);
mrec->lsn = cpu_to_le64(0ull);
mrec->sequence_number = cpu_to_le16(1);
mrec->link_count = cpu_to_le16(0);
@ -1191,7 +1191,7 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni)
ATTR_RECORD *a;
ntfs_inode *ni;
int err;
u16 seq_no, usn;
le16 seq_no, usn;
if (base_ni)
ntfs_log_trace("Entering (allocating an extent mft record for "
@ -1389,7 +1389,7 @@ mft_rec_already_initialized:
goto undo_mftbmp_alloc;
}
seq_no = m->sequence_number;
usn = *(u16*)((u8*)m + le16_to_cpu(m->usa_ofs));
usn = *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs));
if (ntfs_mft_record_layout(vol, bit, m)) {
err = errno;
ntfs_log_error("Failed to re-format mft record.\n");
@ -1397,11 +1397,10 @@ mft_rec_already_initialized:
errno = err;
goto undo_mftbmp_alloc;
}
if (le16_to_cpu(seq_no))
if (seq_no)
m->sequence_number = seq_no;
seq_no = le16_to_cpu(usn);
if (seq_no && seq_no != 0xffff)
*(u16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn;
if (usn && le16_to_cpu(usn) != 0xffff)
*(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn;
/* Set the mft record itself in use. */
m->flags |= MFT_RECORD_IN_USE;
/* Now need to open an ntfs inode for the mft record. */
@ -1495,7 +1494,8 @@ int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni)
{
u64 mft_no;
int err;
u16 seq_no, old_seq_no;
u16 seq_no;
le16 old_seq_no;
ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no);
@ -1560,13 +1560,14 @@ sync_rollback:
*/
int ntfs_mft_usn_dec(MFT_RECORD *mrec)
{
u16 usn, *usnp;
u16 usn;
le16 *usnp;
if (!mrec) {
errno = EINVAL;
return -1;
}
usnp = (u16 *)((char *)mrec + le16_to_cpu(mrec->usa_ofs));
usnp = (le16 *)((char *)mrec + le16_to_cpu(mrec->usa_ofs));
usn = le16_to_cpup(usnp);
if (usn-- <= 1)
usn = 0xfffe;

View File

@ -2,6 +2,7 @@
* mst.c - Multi sector fixup handling code. Part of the Linux-NTFS project.
*
* Copyright (c) 2000-2004 Anton Altaparmakov
* Copyright (c) 2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -130,7 +131,7 @@ int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size)
int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size)
{
u16 usa_ofs, usa_count, usn;
u16 *usa_pos, *data_pos;
le16 *usa_pos, *data_pos, usnle;
/* Sanity check + only fixup if it makes sense. */
if (!b || ntfs_is_baad_record(b->magic) ||
@ -150,7 +151,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size)
return -1;
}
/* Position of usn in update sequence array. */
usa_pos = (u16*)((u8*)b + usa_ofs);
usa_pos = (le16*)((u8*)b + usa_ofs);
/*
* Cyclically increment the update sequence number
* (skipping 0 and -1, i.e. 0xffff).
@ -158,10 +159,10 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size)
usn = le16_to_cpup(usa_pos) + 1;
if (usn == 0xffff || !usn)
usn = 1;
usn = cpu_to_le16(usn);
*usa_pos = usn;
usnle = cpu_to_le16(usn);
*usa_pos = usnle;
/* Position in data of first u16 that needs fixing up. */
data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1;
data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1;
/* Fixup all sectors. */
while (usa_count--) {
/*
@ -170,7 +171,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size)
*/
*(++usa_pos) = *data_pos;
/* Apply fixup to data. */
*data_pos = usn;
*data_pos = usnle;
/* Increment position in data as well. */
data_pos += NTFS_BLOCK_SIZE/sizeof(u16);
}

View File

@ -4,7 +4,7 @@
* Copyright (c) 2002-2005 Anton Altaparmakov
* Copyright (c) 2002-2005 Richard Russon
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2004 Yura Pakhuchiy
* Copyright (c) 2004-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published

View File

@ -2,6 +2,7 @@
* unistr.c - Unicode string handling. Part of the Linux-NTFS project.
*
* Copyright (c) 2000-2006 Anton Altaparmakov
* Copyright (c) 2005-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -130,7 +131,7 @@ int ntfs_names_collate(const ntfschar *name1, const u32 name1_len,
const u32 upcase_len)
{
u32 cnt;
ntfschar c1, c2;
u16 c1, c2;
#ifdef DEBUG
if (!name1 || !name2 || (ic && (!upcase || !upcase_len))) {
@ -187,7 +188,7 @@ int ntfs_names_collate(const ntfschar *name1, const u32 name1_len,
*/
int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n)
{
ntfschar c1, c2;
u16 c1, c2;
size_t i;
#ifdef DEBUG
@ -230,7 +231,7 @@ int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n)
int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
const ntfschar *upcase, const u32 upcase_size)
{
ntfschar c1, c2;
u16 c1, c2;
size_t i;
#ifdef DEBUG
@ -323,7 +324,7 @@ void ntfs_name_upcase(ntfschar *name, u32 name_len, const ntfschar *upcase,
const u32 upcase_len)
{
u32 i;
ntfschar u;
u16 u;
for (i = 0; i < name_len; i++)
if ((u = le16_to_cpu(name[i])) < upcase_len)

View File

@ -4,7 +4,7 @@
* Copyright (c) 2000-2006 Anton Altaparmakov
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2004-2005 Richard Russon
* Copyright (c) 2005-2006 Yura Pakhuchiy
* Copyright (c) 2005-2007 Yura Pakhuchiy
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
@ -849,14 +849,14 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags)
mrec = (MFT_RECORD*)(m + i * vol->mft_record_size);
if (mrec->flags & MFT_RECORD_IN_USE) {
if (ntfs_is_baad_recordp(mrec)) {
if (ntfs_is_baad_record(mrec->magic)) {
ntfs_log_debug("FAILED\n");
ntfs_log_debug("$MFT error: Incomplete multi "
"sector transfer detected in "
"%s.\n", s);
goto io_error_exit;
}
if (!ntfs_is_mft_recordp(mrec)) {
if (!ntfs_is_mft_record(mrec->magic)) {
ntfs_log_debug("FAILED\n");
ntfs_log_debug("$MFT error: Invalid mft "
"record for %s.\n", s);
@ -865,14 +865,14 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags)
}
mrec2 = (MFT_RECORD*)(m2 + i * vol->mft_record_size);
if (mrec2->flags & MFT_RECORD_IN_USE) {
if (ntfs_is_baad_recordp(mrec2)) {
if (ntfs_is_baad_record(mrec2->magic)) {
ntfs_log_debug("FAILED\n");
ntfs_log_debug("$MFTMirr error: Incomplete "
"multi sector transfer "
"detected in %s.\n", s);
goto io_error_exit;
}
if (!ntfs_is_mft_recordp(mrec2)) {
if (!ntfs_is_mft_record(mrec2->magic)) {
ntfs_log_debug("FAILED\n");
ntfs_log_debug("$MFTMirr error: Invalid mft "
"record for %s.\n", s);
@ -1076,12 +1076,12 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags)
goto error_exit;
}
for (j = 0; j < (s32)u; j++) {
ntfschar uc = le16_to_cpu(vname[j]);
u16 uc = le16_to_cpu(vname[j]);
if (uc > 0xff)
uc = (ntfschar)'_';
uc = (u16)'_';
vol->vol_name[j] = (char)uc;
}
vol->vol_name[u] = '\0';
vol->vol_name[u] = 0;
}
}
ntfs_log_debug(OK);
@ -1506,7 +1506,7 @@ error_exit:
*
* Return 0 if successful and -1 if not with errno set to the error code.
*/
int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags)
int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags)
{
ATTR_RECORD *a;
VOLUME_INFORMATION *c;

View File

@ -5,6 +5,7 @@
* Copyright (c) 2001-2005 Richard Russon
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2005 Erik Sornes
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility will create an NTFS 1.2 or 3.1 volume on a user
* specified (block) device.
@ -209,35 +210,35 @@ static void mkntfs_license(void)
static void mkntfs_usage(void)
{
ntfs_log_info("\nUsage: %s [options] device [number-of-sectors]\n"
"\n"
"Basic options:\n"
" -f, --fast Perform a quick format\n"
" -Q, --quick Perform a quick format\n"
" -L, --label STRING Set the volume label\n"
" -C, --enable-compression Enable compression on the volume\n"
" -I, --no-indexing Disable indexing on the volume\n"
" -n, --no-action Do not write to disk\n"
"\n"
"Advanced options:\n"
" -c, --cluster-size BYTES Specify the cluster size for the volume\n"
" -s, --sector-size BYTES Specify the sector size for the device\n"
" -p, --partition-start SECTOR Specify the partition start sector\n"
" -H, --heads NUM Specify the number of heads\n"
" -S, --sectors-per-track NUM Specify the number of sectors per track\n"
" -z, --mft-zone-multiplier NUM Set the MFT zone multiplier\n"
" -T, --zero-time Fake the time to be 00:00 UTC, Jan 1, 1970\n"
" -F, --force Force execution despite errors\n"
"\n"
"Output options:\n"
" -q, --quiet Quiet execution\n"
" -v, --verbose Verbose execution\n"
" --debug Very verbose execution\n"
"\n"
"Help options:\n"
" -V, --version Display version\n"
" -l, --license Display licensing information\n"
" -h, --help Display this help\n"
"\n", basename(EXEC_NAME));
"\n"
"Basic options:\n"
" -f, --fast Perform a quick format\n"
" -Q, --quick Perform a quick format\n"
" -L, --label STRING Set the volume label\n"
" -C, --enable-compression Enable compression on the volume\n"
" -I, --no-indexing Disable indexing on the volume\n"
" -n, --no-action Do not write to disk\n"
"\n"
"Advanced options:\n"
" -c, --cluster-size BYTES Specify the cluster size for the volume\n"
" -s, --sector-size BYTES Specify the sector size for the device\n"
" -p, --partition-start SECTOR Specify the partition start sector\n"
" -H, --heads NUM Specify the number of heads\n"
" -S, --sectors-per-track NUM Specify the number of sectors per track\n"
" -z, --mft-zone-multiplier NUM Set the MFT zone multiplier\n"
" -T, --zero-time Fake the time to be 00:00 UTC, Jan 1, 1970\n"
" -F, --force Force execution despite errors\n"
"\n"
"Output options:\n"
" -q, --quiet Quiet execution\n"
" -v, --verbose Verbose execution\n"
" --debug Very verbose execution\n"
"\n"
"Help options:\n"
" -V, --version Display version\n"
" -l, --license Display licensing information\n"
" -h, --help Display this help\n"
"\n", basename(EXEC_NAME));
ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home);
}
@ -246,12 +247,15 @@ static void mkntfs_usage(void)
*/
static void mkntfs_version(void)
{
ntfs_log_info("\n%s v%s (libntfs %s)\n\n", EXEC_NAME, VERSION, ntfs_libntfs_version());
ntfs_log_info("Create an NTFS volume on a user specified (block) device.\n\n");
ntfs_log_info("\n%s v%s (libntfs %s)\n\n", EXEC_NAME, VERSION,
ntfs_libntfs_version());
ntfs_log_info("Create an NTFS volume on a user specified (block) "
"device.\n\n");
ntfs_log_info("Copyright (c) 2000-2007 Anton Altaparmakov\n");
ntfs_log_info("Copyright (c) 2001-2005 Richard Russon\n");
ntfs_log_info("Copyright (c) 2002-2006 Szabolcs Szakacsits\n");
ntfs_log_info("Copyright (c) 2005 Erik Sornes\n");
ntfs_log_info("Copyright (c) 2007 Yura Pakhuchiy\n");
ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -285,7 +289,8 @@ static BOOL mkntfs_parse_long(const char *string, const char *name, long *num)
/**
* mkntfs_parse_llong
*/
static BOOL mkntfs_parse_llong(const char *string, const char *name, long long *num)
static BOOL mkntfs_parse_llong(const char *string, const char *name,
long long *num)
{
char *end = NULL;
long long tmp;
@ -300,7 +305,8 @@ static BOOL mkntfs_parse_llong(const char *string, const char *name, long long *
tmp = strtoll(string, &end, 0);
if (end && *end) {
ntfs_log_error("Cannot understand the %s '%s'.\n", name, string);
ntfs_log_error("Cannot understand the %s '%s'.\n", name,
string);
return FALSE;
} else {
*num = tmp;
@ -364,7 +370,8 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
int ver = 0;
if (!argv || !opts2) {
ntfs_log_error("Internal error: invalid parameters to mkntfs_options.\n");
ntfs_log_error("Internal error: invalid parameters to "
"mkntfs_options.\n");
return FALSE;
}
@ -374,15 +381,18 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
switch (c) {
case 1: /* A device, or a number of sectors */
if (!opts2->dev_name)
opts2->dev_name = argv[optind-1];
else if (!mkntfs_parse_llong(optarg, "number of sectors", &opts2->num_sectors))
opts2->dev_name = argv[optind - 1];
else if (!mkntfs_parse_llong(optarg,
"number of sectors",
&opts2->num_sectors))
err++;
break;
case 'C':
opts2->enable_compression = TRUE;
break;
case 'c':
if (!mkntfs_parse_long(optarg, "cluster size", &opts2->cluster_size))
if (!mkntfs_parse_long(optarg, "cluster size",
&opts2->cluster_size))
err++;
break;
case 'F':
@ -406,7 +416,8 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
if (!opts2->label) {
opts2->label = argv[optind-1];
} else {
ntfs_log_error("You may only specify the label once.\n");
ntfs_log_error("You may only specify the label "
"once.\n");
err++;
}
break;
@ -417,34 +428,45 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
opts2->no_action = TRUE;
break;
case 'p':
if (!mkntfs_parse_llong(optarg, "partition start", &opts2->part_start_sect))
if (!mkntfs_parse_llong(optarg, "partition start",
&opts2->part_start_sect))
err++;
break;
case 'q':
ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_VERBOSE | NTFS_LOG_LEVEL_PROGRESS);
ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET |
NTFS_LOG_LEVEL_VERBOSE |
NTFS_LOG_LEVEL_PROGRESS);
break;
case 's':
if (!mkntfs_parse_long(optarg, "sector size", &opts2->sector_size))
if (!mkntfs_parse_long(optarg, "sector size",
&opts2->sector_size))
err++;
break;
case 'S':
if (!mkntfs_parse_long(optarg, "sectors per track", &opts2->sectors_per_track))
if (!mkntfs_parse_long(optarg, "sectors per track",
&opts2->sectors_per_track))
err++;
break;
case 'T':
opts2->use_epoch_time = TRUE;
break;
case 'v':
ntfs_log_set_levels(NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_VERBOSE | NTFS_LOG_LEVEL_PROGRESS);
ntfs_log_set_levels(NTFS_LOG_LEVEL_QUIET |
NTFS_LOG_LEVEL_VERBOSE |
NTFS_LOG_LEVEL_PROGRESS);
break;
case 'V':
ver++; /* display version info */
break;
case 'Z': /* debug - turn on everything */
ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG | NTFS_LOG_LEVEL_TRACE | NTFS_LOG_LEVEL_VERBOSE | NTFS_LOG_LEVEL_QUIET);
ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG |
NTFS_LOG_LEVEL_TRACE |
NTFS_LOG_LEVEL_VERBOSE |
NTFS_LOG_LEVEL_QUIET);
break;
case 'z':
if (!mkntfs_parse_long(optarg, "mft zone multiplier", &opts2->mft_zone_multiplier))
if (!mkntfs_parse_long(optarg, "mft zone multiplier",
&opts2->mft_zone_multiplier))
err++;
break;
default:
@ -455,9 +477,11 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
(optopt == 's') || (optopt == 'S') ||
(optopt == 'N') || (optopt == 'z')) &&
(!optarg)) {
ntfs_log_error("Option '%s' requires an argument.\n", argv[optind-1]);
ntfs_log_error("Option '%s' requires an "
"argument.\n", argv[optind-1]);
} else if (optopt != '?') {
ntfs_log_error("Unknown option '%s'.\n", argv[optind-1]);
ntfs_log_error("Unknown option '%s'.\n",
argv[optind - 1]);
}
err++;
break;
@ -1137,8 +1161,8 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m,
err = -EOPNOTSUPP;
goto err_out;
}
if (flags & (ATTR_IS_ENCRYPTED || ATTR_IS_SPARSE)) {
ntfs_log_error("Encrypted/sparse attributes not supported yet.\n");
if (flags & (ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) {
ntfs_log_error("Encrypted/sparse attributes not supported.\n");
err = -EOPNOTSUPP;
goto err_out;
}
@ -1213,18 +1237,18 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m,
m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance)
+ 1) & 0xffff);
a->lowest_vcn = cpu_to_le64(0);
a->highest_vcn = cpu_to_le64(highest_vcn - 1LL);
a->highest_vcn = cpu_to_sle64(highest_vcn - 1LL);
a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7));
memset(a->reserved1, 0, sizeof(a->reserved1));
/* FIXME: Allocated size depends on compression. */
a->allocated_size = cpu_to_le64(highest_vcn * g_vol->cluster_size);
a->data_size = cpu_to_le64(val_len);
a->allocated_size = cpu_to_sle64(highest_vcn * g_vol->cluster_size);
a->data_size = cpu_to_sle64(val_len);
if (name_len)
memcpy((char*)a + hdr_size, uname, name_len << 1);
if (flags & ATTR_COMPRESSION_MASK) {
if (flags & ATTR_COMPRESSION_MASK & ~ATTR_IS_COMPRESSED) {
ntfs_log_error("Unknown compression format. Reverting to "
"standard compression.\n");
ntfs_log_error("Unknown compression format. Reverting "
"to standard compression.\n");
a->flags &= ~ATTR_COMPRESSION_MASK;
a->flags |= ATTR_IS_COMPRESSED;
}
@ -1239,21 +1263,22 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m,
a->compression_unit = 0;
bw = ntfs_rlwrite(g_vol->dev, rl, val, val_len, &inited_size);
if (bw != val_len) {
ntfs_log_error("Error writing non-resident attribute value.\n");
ntfs_log_error("Error writing non-resident attribute "
"value.\n");
return -errno;
}
err = ntfs_mapping_pairs_build(g_vol, (u8*)a + hdr_size +
((name_len + 7) & ~7), mpa_size, rl, 0, NULL);
}
a->initialized_size = cpu_to_le64(inited_size);
a->initialized_size = cpu_to_sle64(inited_size);
if (err < 0 || bw != val_len) {
/* FIXME: Handle error. */
/* deallocate clusters */
/* remove attribute */
if (err >= 0)
err = -EIO;
ntfs_log_error("insert_positioned_attr_in_mft_record failed with "
"error %i.\n", err < 0 ? err : (int)bw);
ntfs_log_error("insert_positioned_attr_in_mft_record failed "
"with error %i.\n", err < 0 ? err : (int)bw);
}
err_out:
if (ctx)
@ -1319,8 +1344,8 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m,
err = -EOPNOTSUPP;
goto err_out;
}
if (flags & (ATTR_IS_ENCRYPTED || ATTR_IS_SPARSE)) {
ntfs_log_error("Encrypted/sparse attributes not supported yet.\n");
if (flags & (ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) {
ntfs_log_error("Encrypted/sparse attributes not supported.\n");
err = -EOPNOTSUPP;
goto err_out;
}
@ -1399,14 +1424,14 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m,
a->lowest_vcn = cpu_to_le64(0);
for (i = 0; rl[i].length; i++)
;
a->highest_vcn = cpu_to_le64(rl[i].vcn - 1);
a->highest_vcn = cpu_to_sle64(rl[i].vcn - 1);
a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7));
memset(a->reserved1, 0, sizeof(a->reserved1));
/* FIXME: Allocated size depends on compression. */
a->allocated_size = cpu_to_le64((val_len + (g_vol->cluster_size - 1)) &
a->allocated_size = cpu_to_sle64((val_len + (g_vol->cluster_size - 1)) &
~(g_vol->cluster_size - 1));
a->data_size = cpu_to_le64(val_len);
a->initialized_size = cpu_to_le64(val_len);
a->data_size = cpu_to_sle64(val_len);
a->initialized_size = cpu_to_sle64(val_len);
if (name_len)
memcpy((char*)a + hdr_size, uname, name_len << 1);
if (flags & ATTR_COMPRESSION_MASK) {
@ -1563,7 +1588,7 @@ err_out:
* Return 0 on success or -errno on error.
*/
static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags,
u32 security_id)
le32 security_id)
{
STANDARD_INFORMATION si;
int err, sd_size;
@ -1599,7 +1624,7 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags,
*
* Return 0 on success or -errno on error.
*/
static int add_attr_file_name(MFT_RECORD *m, const MFT_REF parent_dir,
static int add_attr_file_name(MFT_RECORD *m, const leMFT_REF parent_dir,
const s64 allocated_size, const s64 data_size,
const FILE_ATTR_FLAGS flags, const u16 packed_ea_size,
const u32 reparse_point_tag, const char *file_name,
@ -1614,14 +1639,14 @@ static int add_attr_file_name(MFT_RECORD *m, const MFT_REF parent_dir,
/* Check if the attribute is already there. */
ctx = ntfs_attr_get_search_ctx(NULL, m);
if (!ctx) {
ntfs_log_error("Failed to allocate attribute search context.\n");
ntfs_log_error("Failed to get attribute search context.\n");
return -ENOMEM;
}
if (mkntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0,
ctx)) {
if (mkntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, 0, 0,
NULL, 0, ctx)) {
int eo = errno;
ntfs_log_error("BUG: Standard information attribute not present in "
"file record\n");
ntfs_log_error("BUG: Standard information attribute not "
"present in file record.\n");
ntfs_attr_put_search_ctx(ctx);
return -eo;
}
@ -1642,8 +1667,8 @@ static int add_attr_file_name(MFT_RECORD *m, const MFT_REF parent_dir,
fn->last_access_time = si->last_access_time;
ntfs_attr_put_search_ctx(ctx);
fn->allocated_size = cpu_to_le64(allocated_size);
fn->data_size = cpu_to_le64(data_size);
fn->allocated_size = cpu_to_sle64(allocated_size);
fn->data_size = cpu_to_sle64(data_size);
fn->file_attributes = flags;
/* These are in a union so can't have both. */
if (packed_ea_size && reparse_point_tag) {
@ -1896,8 +1921,8 @@ static int add_attr_index_root(MFT_RECORD *m, const char *name,
return -EINVAL;
}
if (index_block_size < (u32)opts.sector_size) {
ntfs_log_error("add_attr_index_root: index block size is "
"smaller than the sector size.\n");
ntfs_log_error("add_attr_index_root: index block size "
"is smaller than the sector size.\n");
free(r);
return -EINVAL;
}
@ -2084,7 +2109,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name,
"Thank you.", NTFS_DEV_LIST);
}
/* Set USN to 1. */
*(u16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) =
*(le16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) =
cpu_to_le16(1);
ia_val->lsn = cpu_to_le64(0);
ia_val->index_block_vcn = cpu_to_le64(0);
@ -2129,8 +2154,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name,
goto err_out;
}
/* Set VCN pointer to 0LL. */
*(VCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) =
cpu_to_le64(0);
*(leVCN*)((char*)re + le16_to_cpu(re->length) - sizeof(VCN)) = 0;
err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size);
if (err) {
err = -errno;
@ -2482,7 +2506,7 @@ static int initialize_secure(char *sds, u32 sds_size, MFT_RECORD *m)
*/
static int initialize_quota(MFT_RECORD *m)
{
int o_size, q1_size, q2_size, err;
int o_size, q1_size, q2_size, err, i;
INDEX_ENTRY *idx_entry_o, *idx_entry_q1, *idx_entry_q2;
QUOTA_O_INDEX_DATA *idx_entry_o_data;
QUOTA_CONTROL_ENTRY *idx_entry_q1_data, *idx_entry_q2_data;
@ -2507,8 +2531,8 @@ static int initialize_quota(MFT_RECORD *m)
idx_entry_q1_data->flags = QUOTA_FLAG_DEFAULT_LIMITS;
idx_entry_q1_data->bytes_used = const_cpu_to_le64(0x00);
idx_entry_q1_data->change_time = utc2ntfs(mkntfs_time());
idx_entry_q1_data->threshold = const_cpu_to_le64((s64)-1);
idx_entry_q1_data->limit = const_cpu_to_le64((s64)-1);
idx_entry_q1_data->threshold = cpu_to_sle64(-1);
idx_entry_q1_data->limit = cpu_to_sle64(-1);
idx_entry_q1_data->exceeded_time = const_cpu_to_le64(0x00);
err = insert_index_entry_in_res_dir_index(idx_entry_q1, q1_size, m,
NTFS_INDEX_Q, 2, AT_UNUSED);
@ -2534,15 +2558,14 @@ static int initialize_quota(MFT_RECORD *m)
idx_entry_q2_data->flags = QUOTA_FLAG_DEFAULT_LIMITS;
idx_entry_q2_data->bytes_used = const_cpu_to_le64(0x00);
idx_entry_q2_data->change_time = utc2ntfs(mkntfs_time());;
idx_entry_q2_data->threshold = const_cpu_to_le64((s64)-1);
idx_entry_q2_data->limit = const_cpu_to_le64((s64)-1);
idx_entry_q2_data->threshold = cpu_to_sle64(-1);
idx_entry_q2_data->limit = cpu_to_sle64(-1);
idx_entry_q2_data->exceeded_time = const_cpu_to_le64(0x00);
idx_entry_q2_data->sid.revision = 1;
idx_entry_q2_data->sid.sub_authority_count = 2;
idx_entry_q2_data->sid.identifier_authority.high_part =
const_cpu_to_le16(0x0000);
idx_entry_q2_data->sid.identifier_authority.low_part =
const_cpu_to_le32(0x05000000);
for (i = 0; i < 5; i++)
idx_entry_q2_data->sid.identifier_authority.value[i] = 0;
idx_entry_q2_data->sid.identifier_authority.value[5] = 0x05;
idx_entry_q2_data->sid.sub_authority[0] =
const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID);
idx_entry_q2_data->sid.sub_authority[1] =
@ -2565,10 +2588,9 @@ static int initialize_quota(MFT_RECORD *m)
idx_entry_o->reserved = const_cpu_to_le16(0x00);
idx_entry_o->key.sid.revision = 0x01;
idx_entry_o->key.sid.sub_authority_count = 0x02;
idx_entry_o->key.sid.identifier_authority.high_part =
const_cpu_to_le16(0x0000);
idx_entry_o->key.sid.identifier_authority.low_part =
const_cpu_to_le32(0x05000000);
for (i = 0; i < 5; i++)
idx_entry_o->key.sid.identifier_authority.value[i] = 0;
idx_entry_o->key.sid.identifier_authority.value[5] = 0x05;
idx_entry_o->key.sid.sub_authority[0] =
const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID);
idx_entry_o->key.sid.sub_authority[1] =
@ -2594,7 +2616,7 @@ static int initialize_quota(MFT_RECORD *m)
*
* Return 0 on success or -errno on error.
*/
static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref,
static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, leMFT_REF file_ref,
FILE_NAME_ATTR *file_name, u32 file_name_size)
{
int err, i;
@ -2627,7 +2649,8 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref,
if (i < 0)
ntfs_log_debug("Name contains non-displayable "
"Unicode characters.\n");
ntfs_log_debug("file_name_attr1->file_name = %s\n", __buf);
ntfs_log_debug("file_name_attr1->file_name = %s\n",
__buf);
free(__buf);
}
ntfs_log_debug("file_name_attr2->file_name_length = %i\n",
@ -2635,11 +2658,13 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref,
if (ie->key.file_name.file_name_length) {
char *__buf = NULL;
i = ntfs_ucstombs(ie->key.file_name.file_name,
ie->key.file_name.file_name_length + 1, &__buf, 0);
ie->key.file_name.file_name_length + 1, &__buf,
0);
if (i < 0)
ntfs_log_debug("Name contains non-displayable "
"Unicode characters.\n");
ntfs_log_debug("file_name_attr2->file_name = %s\n", __buf);
ntfs_log_debug("file_name_attr2->file_name = %s\n",
__buf);
free(__buf);
}
#endif
@ -2670,7 +2695,8 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, MFT_REF file_ref,
return -EEXIST;
i = ntfs_file_values_compare(file_name,
(FILE_NAME_ATTR*)&ie->key.file_name, 1,
CASE_SENSITIVE, g_vol->upcase, g_vol->upcase_len);
CASE_SENSITIVE, g_vol->upcase,
g_vol->upcase_len);
if (i == -1)
break;
/* Complete match. Bugger. Can't insert. */
@ -2680,7 +2706,8 @@ do_next:
#ifdef DEBUG
/* Next entry. */
if (!ie->length) {
ntfs_log_debug("BUG: ie->length is zero, breaking out of loop.\n");
ntfs_log_debug("BUG: ie->length is zero, breaking out "
"of loop.\n");
break;
}
#endif
@ -2689,8 +2716,8 @@ do_next:
i = (sizeof(INDEX_ENTRY_HEADER) + file_name_size + 7) & ~7;
err = make_room_for_index_entry_in_index_block(idx, ie, i);
if (err) {
ntfs_log_error("make_room_for_index_entry_in_index_block failed: "
"%s\n", strerror(-err));
ntfs_log_error("make_room_for_index_entry_in_index_block "
"failed: %s\n", strerror(-err));
return err;
}
/* Create entry in place and copy file name attribute value. */
@ -2716,8 +2743,8 @@ do_next:
*
* Return 0 on success or -errno on error.
*/
static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent,
MFT_RECORD *m_file, const MFT_REF ref_file,
static int create_hardlink_res(MFT_RECORD *m_parent, const leMFT_REF ref_parent,
MFT_RECORD *m_file, const leMFT_REF ref_file,
const s64 allocated_size, const s64 data_size,
const FILE_ATTR_FLAGS flags, const u16 packed_ea_size,
const u32 reparse_point_tag, const char *file_name,
@ -2740,8 +2767,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent,
fn->last_data_change_time = fn->creation_time;
fn->last_mft_change_time = fn->creation_time;
fn->last_access_time = fn->creation_time;
fn->allocated_size = cpu_to_le64(allocated_size);
fn->data_size = cpu_to_le64(data_size);
fn->allocated_size = cpu_to_sle64(allocated_size);
fn->data_size = cpu_to_sle64(data_size);
fn->file_attributes = flags;
/* These are in a union so can't have both. */
if (packed_ea_size && reparse_point_tag) {
@ -2784,8 +2811,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent,
i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, 0,
0, RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size);
if (i < 0) {
ntfs_log_error("create_hardlink failed adding file name attribute: "
"%s\n", strerror(-i));
ntfs_log_error("create_hardlink failed adding file name "
"attribute: %s\n", strerror(-i));
free(fn);
/* Undo link count increment. */
m_file->link_count = cpu_to_le16(
@ -2804,8 +2831,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent,
i = insert_index_entry_in_res_dir_index(idx_entry_new, idx_size + 0x10,
m_parent, NTFS_INDEX_I30, 4, AT_FILE_NAME);
if (i < 0) {
ntfs_log_error("create_hardlink failed inserting index entry: %s\n",
strerror(-i));
ntfs_log_error("create_hardlink failed inserting index entry: "
"%s\n", strerror(-i));
/* FIXME: Remove the file name attribute from @m_file. */
free(idx_entry_new);
free(fn);
@ -2832,8 +2859,8 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const MFT_REF ref_parent,
*
* Return 0 on success or -errno on error.
*/
static int create_hardlink(INDEX_BLOCK *idx, const MFT_REF ref_parent,
MFT_RECORD *m_file, const MFT_REF ref_file,
static int create_hardlink(INDEX_BLOCK *idx, const leMFT_REF ref_parent,
MFT_RECORD *m_file, const leMFT_REF ref_file,
const s64 allocated_size, const s64 data_size,
const FILE_ATTR_FLAGS flags, const u16 packed_ea_size,
const u32 reparse_point_tag, const char *file_name,
@ -2856,8 +2883,8 @@ static int create_hardlink(INDEX_BLOCK *idx, const MFT_REF ref_parent,
fn->last_data_change_time = fn->creation_time;
fn->last_mft_change_time = fn->creation_time;
fn->last_access_time = fn->creation_time;
fn->allocated_size = cpu_to_le64(allocated_size);
fn->data_size = cpu_to_le64(data_size);
fn->allocated_size = cpu_to_sle64(allocated_size);
fn->data_size = cpu_to_sle64(data_size);
fn->file_attributes = flags;
/* These are in a union so can't have both. */
if (packed_ea_size && reparse_point_tag) {
@ -2932,7 +2959,7 @@ static int create_hardlink(INDEX_BLOCK *idx, const MFT_REF ref_parent,
* Return 0 on success or -errno on error.
*/
static int index_obj_id_insert(MFT_RECORD *m, const GUID *guid,
const MFT_REF ref)
const leMFT_REF ref)
{
INDEX_ENTRY *idx_entry_new;
int data_ofs, idx_size, err;
@ -3840,7 +3867,7 @@ static BOOL mkntfs_sync_index_record(INDEX_ALLOCATION* idx, MFT_RECORD* m,
/**
* create_file_volume -
*/
static BOOL create_file_volume(MFT_RECORD *m, MFT_REF root_ref,
static BOOL create_file_volume(MFT_RECORD *m, leMFT_REF root_ref,
VOLUME_FLAGS fl, const GUID *volume_guid
#ifndef ENABLE_UUID
__attribute__((unused))
@ -3943,8 +3970,8 @@ static BOOL mkntfs_create_root_structures(void)
{
NTFS_BOOT_SECTOR *bs;
MFT_RECORD *m;
MFT_REF root_ref;
MFT_REF extend_ref;
leMFT_REF root_ref;
leMFT_REF extend_ref;
int i;
int j;
int err;
@ -3970,7 +3997,8 @@ static BOOL mkntfs_create_root_structures(void)
for (i = 0; i < nr_sysfiles; i++) {
if (ntfs_mft_record_layout(g_vol, 0, m = (MFT_RECORD *)(g_buf +
i * g_vol->mft_record_size))) {
ntfs_log_error("Failed to layout system mft records.\n");
ntfs_log_error("Failed to layout system mft records."
"\n");
return FALSE;
}
if (i == 0 || i > 23)
@ -3987,7 +4015,8 @@ static BOOL mkntfs_create_root_structures(void)
i * (s32)g_vol->mft_record_size < g_mft_size; i++) {
m = (MFT_RECORD *)(g_buf + i * g_vol->mft_record_size);
if (ntfs_mft_record_layout(g_vol, 0, m)) {
ntfs_log_error("Failed to layout mft record.\n");
ntfs_log_error("Failed to layout mft record."
"\n");
return FALSE;
}
m->flags = cpu_to_le16(0);
@ -3999,7 +4028,7 @@ static BOOL mkntfs_create_root_structures(void)
* to each as well as marking them in use in the mft bitmap.
*/
for (i = 0; i < nr_sysfiles; i++) {
u32 file_attrs;
le32 file_attrs;
m = (MFT_RECORD*)(g_buf + i * g_vol->mft_record_size);
if (i < 16 || i > 23) {
@ -4065,14 +4094,16 @@ static BOOL mkntfs_create_root_structures(void)
ATTR_RECORD *a;
ctx = ntfs_attr_get_search_ctx(NULL, m);
if (!ctx) {
ntfs_log_perror("Failed to allocate attribute search context");
ntfs_log_perror("Failed to allocate attribute search "
"context");
return FALSE;
}
/* There is exactly one file name so this is ok. */
if (mkntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0,
ctx)) {
if (mkntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL,
0, ctx)) {
ntfs_attr_put_search_ctx(ctx);
ntfs_log_error("BUG: $FILE_NAME attribute not found.\n");
ntfs_log_error("BUG: $FILE_NAME attribute not found."
"\n");
return FALSE;
}
a = ctx->attr;
@ -4118,7 +4149,8 @@ static BOOL mkntfs_create_root_structures(void)
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$MFTMirr", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
ntfs_log_error("Couldn't create $MFTMirr: %s\n", strerror(-err));
ntfs_log_error("Couldn't create $MFTMirr: %s\n",
strerror(-err));
return FALSE;
}
ntfs_log_verbose("Creating $LogFile (mft record 2)\n");
@ -4138,12 +4170,14 @@ static BOOL mkntfs_create_root_structures(void)
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$LogFile", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
ntfs_log_error("Couldn't create $LogFile: %s\n", strerror(-err));
ntfs_log_error("Couldn't create $LogFile: %s\n",
strerror(-err));
return FALSE;
}
ntfs_log_verbose("Creating $AttrDef (mft record 4)\n");
m = (MFT_RECORD*)(g_buf + 4 * g_vol->mft_record_size);
err = add_attr_data(m, NULL, 0, 0, 0, (u8*)g_vol->attrdef, g_vol->attrdef_len);
err = add_attr_data(m, NULL, 0, 0, 0, (u8*)g_vol->attrdef,
g_vol->attrdef_len);
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_AttrDef, FILE_AttrDef),
@ -4156,7 +4190,8 @@ static BOOL mkntfs_create_root_structures(void)
err = add_attr_sd(m, sd, i);
}
if (err < 0) {
ntfs_log_error("Couldn't create $AttrDef: %s\n", strerror(-err));
ntfs_log_error("Couldn't create $AttrDef: %s\n",
strerror(-err));
return FALSE;
}
ntfs_log_verbose("Creating $Bitmap (mft record 6)\n");
@ -4172,8 +4207,9 @@ static BOOL mkntfs_create_root_structures(void)
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_Bitmap, FILE_Bitmap),
(g_lcn_bitmap_byte_size + g_vol->cluster_size - 1) &
~(g_vol->cluster_size - 1), g_lcn_bitmap_byte_size,
(g_lcn_bitmap_byte_size + g_vol->cluster_size -
1) & ~(g_vol->cluster_size - 1),
g_lcn_bitmap_byte_size,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$Bitmap", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
@ -4196,8 +4232,8 @@ static BOOL mkntfs_create_root_structures(void)
opts.sector_size);
bs->bpb.media_type = 0xf8; /* hard disk */
bs->bpb.sectors_per_track = cpu_to_le16(opts.sectors_per_track);
ntfs_log_debug("sectors per track = %ld (0x%lx)\n", opts.sectors_per_track,
opts.sectors_per_track);
ntfs_log_debug("sectors per track = %ld (0x%lx)\n",
opts.sectors_per_track, opts.sectors_per_track);
bs->bpb.heads = cpu_to_le16(opts.heads);
ntfs_log_debug("heads = %ld (0x%lx)\n", opts.heads, opts.heads);
bs->bpb.hidden_sectors = cpu_to_le32(opts.part_start_sect);
@ -4212,12 +4248,13 @@ static BOOL mkntfs_create_root_structures(void)
bs->clusters_per_mft_record = g_vol->mft_record_size /
g_vol->cluster_size;
} else {
bs->clusters_per_mft_record = -(ffs(g_vol->mft_record_size) - 1);
bs->clusters_per_mft_record = -(ffs(g_vol->mft_record_size) -
1);
if ((u32)(1 << -bs->clusters_per_mft_record) !=
g_vol->mft_record_size) {
free(bs);
ntfs_log_error("BUG: calculated clusters_per_mft_record "
"is wrong (= 0x%x)\n",
ntfs_log_error("BUG: calculated clusters_per_mft_record"
" is wrong (= 0x%x)\n",
bs->clusters_per_mft_record);
return FALSE;
}
@ -4230,10 +4267,12 @@ static BOOL mkntfs_create_root_structures(void)
g_vol->cluster_size;
} else {
bs->clusters_per_index_record = -g_vol->indx_record_size_bits;
if ((1 << -bs->clusters_per_index_record) != (s32)g_vol->indx_record_size) {
if ((1 << -bs->clusters_per_index_record) !=
(s32)g_vol->indx_record_size) {
free(bs);
ntfs_log_error("BUG: calculated clusters_per_index_record "
"is wrong (= 0x%x)\n",
ntfs_log_error("BUG: calculated "
"clusters_per_index_record is wrong "
"(= 0x%x)\n",
bs->clusters_per_index_record);
return FALSE;
}
@ -4242,8 +4281,8 @@ static BOOL mkntfs_create_root_structures(void)
bs->clusters_per_index_record,
bs->clusters_per_index_record);
/* Generate a 64-bit random number for the serial number. */
bs->volume_serial_number = cpu_to_sle64(((s64)random() << 32) |
((s64)random() & 0xffffffff));
bs->volume_serial_number = cpu_to_le64(((u64)random() << 32) |
((u64)random() & 0xffffffff));
/*
* Leave zero for now as NT4 leaves it zero, too. If want it later, see
* ../libntfs/bootsect.c for how to calculate it.
@ -4255,7 +4294,8 @@ static BOOL mkntfs_create_root_structures(void)
ntfs_log_error("FATAL: Generated boot sector is invalid!\n");
return FALSE;
}
err = add_attr_data_positioned(m, NULL, 0, 0, 0, g_rl_boot, (u8*)bs, 8192);
err = add_attr_data_positioned(m, NULL, 0, 0, 0, g_rl_boot, (u8*)bs,
8192);
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_Boot, FILE_Boot),
@ -4311,7 +4351,8 @@ static BOOL mkntfs_create_root_structures(void)
0, 0, "$BadClus", FILE_NAME_WIN32_AND_DOS);
}
if (err < 0) {
ntfs_log_error("Couldn't create $BadClus: %s\n", strerror(-err));
ntfs_log_error("Couldn't create $BadClus: %s\n",
strerror(-err));
return FALSE;
}
/* create $Secure (NTFS 3.0+) */
@ -4365,7 +4406,8 @@ static BOOL mkntfs_create_root_structures(void)
MK_LE_MREF(FILE_UpCase, FILE_UpCase),
((g_vol->upcase_len << 1) +
g_vol->cluster_size - 1) &
~(g_vol->cluster_size - 1), g_vol->upcase_len << 1,
~(g_vol->cluster_size - 1),
g_vol->upcase_len << 1,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
"$UpCase", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
@ -4404,8 +4446,8 @@ static BOOL mkntfs_create_root_structures(void)
err = add_attr_sd(m, sd, j);
}
if (err < 0) {
ntfs_log_error("Couldn't create system file %i (0x%x): %s\n",
i, i, strerror(-err));
ntfs_log_error("Couldn't create system file %i (0x%x): "
"%s\n", i, i, strerror(-err));
return FALSE;
}
}

View File

@ -4,6 +4,7 @@
* Copyright (c) 2003-2005 Richard Russon
* Copyright (c) 2003-2005 Anton Altaparmakov
* Copyright (c) 2003-2005 Szabolcs Szakacsits
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility will concatenate files and print on the standard output.
*
@ -59,12 +60,13 @@ static struct options opts;
*/
static void version(void)
{
ntfs_log_info("\n%s v%s (libntfs %s) - Concatenate files and print on the "
"standard output.\n\n", EXEC_NAME, VERSION,
ntfs_log_info("\n%s v%s (libntfs %s) - Concatenate files and print "
"on the standard output.\n\n", EXEC_NAME, VERSION,
ntfs_libntfs_version());
ntfs_log_info("Copyright (c) 2003-2005 Richard Russon\n");
ntfs_log_info("Copyright (c) 2003-2005 Anton Altaparmakov\n");
ntfs_log_info("Copyright (c) 2003-2005 Szabolcs Szakacsits\n");
ntfs_log_info("Copyright (c) 2007 Yura Pakhuchiy\n");
ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -131,15 +133,15 @@ static int parse_attribute(const char *value, ATTR_TYPES *attr)
for (i = 0; attr_name[i]; i++) {
if ((strcmp(value, attr_name[i]) == 0) ||
(strcmp(value, attr_name[i]+1) == 0)) {
*attr = (ATTR_TYPES) ((i+1)*16);
(strcmp(value, attr_name[i] + 1) == 0)) {
*attr = (ATTR_TYPES)cpu_to_le32((i + 1) * 16);
return 1;
}
}
num = strtol(value, NULL, 0);
if ((num > 0) && (num < 257)) {
*attr = (ATTR_TYPES) num;
*attr = (ATTR_TYPES)cpu_to_le32(num);
return 1;
}
@ -181,7 +183,7 @@ static int parse_options(int argc, char **argv)
opterr = 0; /* We'll handle the errors, thank you. */
opts.inode = -1;
opts.attr = -1;
opts.attr = cpu_to_le32(-1);
opts.attr_name = NULL;
opts.attr_name_len = 0;
@ -189,17 +191,19 @@ static int parse_options(int argc, char **argv)
switch (c) {
case 1: /* A non-option argument */
if (!opts.device) {
opts.device = argv[optind-1];
opts.device = argv[optind - 1];
} else if (!opts.file) {
opts.file = argv[optind-1];
opts.file = argv[optind - 1];
} else {
ntfs_log_error("You must specify exactly one file.\n");
ntfs_log_error("You must specify exactly one "
"file.\n");
err++;
}
break;
case 'a':
if (opts.attr != (ATTR_TYPES)-1) {
ntfs_log_error("You must specify exactly one attribute.\n");
if (opts.attr != cpu_to_le32(-1)) {
ntfs_log_error("You must specify exactly one "
"attribute.\n");
} else if (parse_attribute(optarg, &attr) > 0) {
opts.attr = attr;
break;
@ -234,7 +238,8 @@ static int parse_options(int argc, char **argv)
opts.attr_name_len = ntfs_mbstoucs(optarg,
&opts.attr_name, 0);
if (opts.attr_name_len < 0) {
ntfs_log_perror("Invalid attribute name '%s'", optarg);
ntfs_log_perror("Invalid attribute name '%s'",
optarg);
usage();
}
@ -317,8 +322,7 @@ static int index_get_size(ntfs_inode *inode)
return 0; // not a directory
iroot = (INDEX_ROOT*)((u8*)attr90 + le16_to_cpu(attr90->value_offset));
return iroot->index_block_size;
return le32_to_cpu(iroot->index_block_size);
}
/**
@ -340,7 +344,8 @@ static int cat(ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
attr = ntfs_attr_open(inode, type, name, namelen);
if (!attr) {
ntfs_log_error("Cannot find attribute type 0x%lx.\n", (long) type);
ntfs_log_error("Cannot find attribute type 0x%x.\n",
le32_to_cpu(type));
free(buffer);
return 1;
}
@ -422,7 +427,7 @@ int main(int argc, char *argv[])
}
attr = AT_DATA;
if (opts.attr != (ATTR_TYPES)-1)
if (opts.attr != cpu_to_le32(-1))
attr = opts.attr;
result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len);

View File

@ -3,6 +3,7 @@
*
* Copyright (c) 2003-2006 Szabolcs Szakacsits
* Copyright (c) 2004-2006 Anton Altaparmakov
* Copyright (c) 2007 Yura Pakhuchiy
* Special image format support copyright (c) 2004 Per Olofsson
*
* Clone NTFS data and/or metadata to a sparse file, image, device or stdout.
@ -153,8 +154,6 @@ static unsigned int wiped_unused_mft = 0;
static unsigned int wiped_resident_data = 0;
static unsigned int wiped_timestamp_data = 0;
static BOOL image_is_host_endian = FALSE;
#define IMAGE_MAGIC "\0ntfsclone-image"
#define IMAGE_MAGIC_SIZE 16
@ -180,11 +179,11 @@ static struct {
char magic[IMAGE_MAGIC_SIZE];
u8 major_ver;
u8 minor_ver;
u32 cluster_size;
s64 device_size;
s64 nr_clusters;
s64 inuse;
u32 offset_to_image_data; /* From start of image_hdr. */
le32 cluster_size;
sle64 device_size;
sle64 nr_clusters;
sle64 inuse;
le32 offset_to_image_data; /* From start of image_hdr. */
} __attribute__((__packed__)) image_hdr;
#define NTFSCLONE_IMG_HEADER_SIZE_OLD \
@ -612,7 +611,7 @@ static void lseek_to_cluster(s64 lcn)
static void image_skip_clusters(s64 count)
{
if (opt.save_image && count > 0) {
typeof(count) count_buf;
sle64 count_buf;
char buff[1 + sizeof(count)];
buff[0] = 0;
@ -661,8 +660,8 @@ static void clone_ntfs(u64 nr_clusters)
progress_init(&progress, p_counter, nr_clusters, 100);
if (opt.save_image) {
if (write_all(&fd_out, &image_hdr,
image_hdr.offset_to_image_data) == -1)
if (write_all(&fd_out, &image_hdr, le32_to_cpu(
image_hdr.offset_to_image_data)) == -1)
perr_exit("write_all");
}
@ -704,6 +703,7 @@ static void write_empty_clusters(s32 csize, s64 count,
static void restore_image(void)
{
sle64 countle;
s64 pos = 0, count;
s32 csize = le32_to_cpu(image_hdr.cluster_size);
char cmd;
@ -722,10 +722,9 @@ static void restore_image(void)
perr_exit("read_all");
if (cmd == 0) {
if (read_all(&fd_in, &count, sizeof(count)) == -1)
if (read_all(&fd_in, &countle, sizeof(countle)) == -1)
perr_exit("read_all");
if (!image_is_host_endian)
count = sle64_to_cpu(count);
count = sle64_to_cpu(countle);
if (opt.std_out)
write_empty_clusters(csize, count,
&progress, &p_counter);
@ -746,7 +745,7 @@ static void restore_image(void)
static void wipe_index_entry_timestams(INDEX_ENTRY *e)
{
s64 timestamp = utc2ntfs(0);
sle64 timestamp = utc2ntfs(0);
/* FIXME: can fall into infinite loop if corrupted */
while (!(e->flags & INDEX_ENTRY_END)) {
@ -855,7 +854,7 @@ out_indexr:
free(indexr);
}
static void wipe_index_root_timestamps(ATTR_RECORD *attr, s64 timestamp)
static void wipe_index_root_timestamps(ATTR_RECORD *attr, sle64 timestamp)
{
INDEX_ENTRY *entry;
INDEX_ROOT *iroot;
@ -917,7 +916,7 @@ do { \
static void wipe_timestamps(ntfs_walk_clusters_ctx *image)
{
ATTR_RECORD *a = image->ctx->attr;
s64 timestamp = utc2ntfs(0);
sle64 timestamp = utc2ntfs(0);
if (a->type == AT_FILE_NAME)
WIPE_TIMESTAMPS(FILE_NAME_ATTR, a, timestamp);
@ -1552,9 +1551,8 @@ static s64 open_image(void)
#endif
image_hdr.offset_to_image_data =
const_cpu_to_le32((sizeof(image_hdr) + 7) & ~7);
image_is_host_endian = TRUE;
} else {
typeof(image_hdr.offset_to_image_data) offset_to_image_data;
le32 offset_to_image_data;
int delta;
if (image_hdr.major_ver > NTFSCLONE_IMG_VER_MAJOR)
@ -1567,16 +1565,16 @@ static s64 open_image(void)
if (read_all(&fd_in, &offset_to_image_data,
sizeof(offset_to_image_data)) == -1)
perr_exit("read_all");
image_hdr.offset_to_image_data =
le32_to_cpu(offset_to_image_data);
image_hdr.offset_to_image_data = offset_to_image_data;
/*
* Read any fields from the header that we have not read yet so
* that the input stream is positioned correctly. This means
* we can support future minor versions that just extend the
* header in a backwards compatible way.
*/
delta = offset_to_image_data - (NTFSCLONE_IMG_HEADER_SIZE_OLD +
sizeof(image_hdr.offset_to_image_data));
delta = le32_to_cpu(offset_to_image_data) -
(NTFSCLONE_IMG_HEADER_SIZE_OLD +
sizeof(image_hdr.offset_to_image_data));
if (delta > 0) {
char *dummy_buf;

View File

@ -1,10 +1,26 @@
/**
* ntfscmp - compare two NTFS volumes.
* ntfscmp - Part of the Linux-NTFS project.
*
* Copyright (c) 2005-2006 Szabolcs Szakacsits
* Copyright (c) 2005 Anton Altaparmakov
* Copyright (c) 2005 Anton Altaparmakov
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility is part of the Linux-NTFS project.
* This utility compare two NTFS volumes.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
@ -386,7 +402,8 @@ static void print_attribute_name(char *name)
}
#define GET_ATTR_NAME(a) \
((ntfschar *)(((u8 *)(a)) + ((a)->name_offset))), ((a)->name_length)
((ntfschar *)(((u8 *)(a)) + le16_to_cpu((a)->name_offset))), \
((a)->name_length)
static void free_name(char **name)
{
@ -537,15 +554,15 @@ static void cmp_index_allocation(ntfs_attr *na1, ntfs_attr *na2)
if (cmp_buffer((u8 *)cia1.ia, (u8 *)cia2.ia, 0x18, na1))
goto out;
ib_size = cia1.ia->index.allocated_size + 0x18;
ib_size = le32_to_cpu(cia1.ia->index.allocated_size) + 0x18;
bit = 0;
while ((u8 *)cia1.tmp_ia < (u8 *)cia1.ia + na1->data_size) {
if (*cia1.byte & (1 << bit)) {
ret1 = ntfs_mst_post_read_fixup((NTFS_RECORD *)cia1.tmp_ia,
ib_size);
ret2 = ntfs_mst_post_read_fixup((NTFS_RECORD *)cia2.tmp_ia,
ib_size);
ret1 = ntfs_mst_post_read_fixup((NTFS_RECORD *)
cia1.tmp_ia, ib_size);
ret2 = ntfs_mst_post_read_fixup((NTFS_RECORD *)
cia2.tmp_ia, ib_size);
if (ret1 != ret2) {
print_differ(na1);
goto out;
@ -555,8 +572,9 @@ static void cmp_index_allocation(ntfs_attr *na1, ntfs_attr *na2)
continue;
if (cmp_buffer(((u8 *)cia1.tmp_ia) + 0x18,
((u8 *)cia2.tmp_ia) + 0x18,
cia1.ia->index.index_length, na1))
((u8 *)cia2.tmp_ia) + 0x18,
le32_to_cpu(cia1.ia->
index.index_length), na1))
goto out;
}
@ -638,7 +656,7 @@ static int cmp_attribute_header(ATTR_RECORD *a1, ATTR_RECORD *a2)
/*
* FIXME: includes paddings which are not handled by ntfsinfo!
*/
header_size = a1->length;
header_size = le32_to_cpu(a1->length);
}
return memcmp(a1, a2, header_size);
@ -818,9 +836,11 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2)
old_atype1 = atype1;
old_ret1 = ret1;
if (!ret1 && (atype1 <= atype2 || ret2))
if (!ret1 && (le32_to_cpu(atype1) <= le32_to_cpu(atype2) ||
ret2))
ret1 = next_attr(ctx1, &atype1, &name1, &errno1);
if (!ret2 && (old_atype1 >= atype2 || old_ret1))
if (!ret2 && (le32_to_cpu(old_atype1) >= le32_to_cpu(atype2) ||
old_ret1))
ret2 = next_attr(ctx2, &atype2, &name2, &errno2);
print_attributes(ni1, atype1, atype2, name1, name2);
@ -834,14 +854,15 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2)
break;
}
if (ret2 || atype1 < atype2) {
if (ret2 || le32_to_cpu(atype1) < le32_to_cpu(atype2)) {
if (new_attribute(ctx1, prev_atype, prev_name)) {
print_ctx(ctx1);
printf("presence: EXISTS != MISSING\n");
set_prev(&prev_name, &prev_atype, name1, atype1);
set_prev(&prev_name, &prev_atype, name1,
atype1);
}
} else if (ret1 || atype1 > atype2) {
} else if (ret1 || le32_to_cpu(atype1) > le32_to_cpu(atype2)) {
if (new_attribute(ctx2, prev_atype, prev_name)) {
print_ctx(ctx2);
printf("presence: MISSING != EXISTS \n");

View File

@ -182,7 +182,7 @@ static int parse_options(int argc, char **argv)
ntfs_log_error("Couldn't parse attribute.\n");
err++;
} else
opts.attribute = (ATTR_TYPES)attr;
opts.attribute = (ATTR_TYPES)cpu_to_le32(attr);
break;
case 'i':
opts.inode++;

View File

@ -1,8 +1,9 @@
/**
* ntfsfix - Part of the Linux-NTFS project.
*
* Copyright (c) 2000-2006 Anton Altaparmakov.
* Copyright (c) 2002-2006 Szabolcs Szakacsits.
* Copyright (c) 2000-2006 Anton Altaparmakov
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility fixes some common NTFS problems, resets the NTFS journal file
* and schedules an NTFS consistency check for the first boot into Windows.
@ -116,8 +117,9 @@ static void version(void)
{
ntfs_log_info("%s v%s\n\n"
"Attempt to fix an NTFS partition.\n\n"
"Copyright (c) 2000-2006 Anton Altaparmakov.\n"
"Copyright (c) 2002-2006 Szabolcs Szakacsits.\n\n",
"Copyright (c) 2000-2006 Anton Altaparmakov\n"
"Copyright (c) 2002-2006 Szabolcs Szakacsits\n"
"Copyright (c) 2007 Yura Pakhuchiy\n\n",
EXEC_NAME, VERSION);
ntfs_log_info("%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
exit(1);
@ -168,7 +170,7 @@ static void parse_options(int argc, char **argv)
/**
* OLD_ntfs_volume_set_flags
*/
static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const u16 flags)
static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const le16 flags)
{
MFT_RECORD *m = NULL;
ATTR_RECORD *a;
@ -225,7 +227,7 @@ static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const u16 flags)
goto err_out;
}
/* Set the volume flags. */
vol->flags = c->flags = cpu_to_le16(flags);
vol->flags = c->flags = flags;
if (ntfs_mft_record_write(vol, FILE_Volume, m)) {
ntfs_log_perror("Error writing $Volume");
goto err_out;
@ -243,7 +245,7 @@ err_exit:
*/
static int set_dirty_flag(ntfs_volume *vol)
{
u16 flags;
le16 flags;
if (NVolWasDirty(vol))
return 0;
@ -362,7 +364,7 @@ static int fix_mftmirr(ntfs_volume *vol)
use_mirr = FALSE;
mrec = (MFT_RECORD*)(m + i * vol->mft_record_size);
if (mrec->flags & MFT_RECORD_IN_USE) {
if (ntfs_is_baad_recordp(mrec)) {
if (ntfs_is_baad_record(mrec->magic)) {
ntfs_log_info(FAILED);
ntfs_log_error("$MFT error: Incomplete multi "
"sector transfer detected in "
@ -370,7 +372,7 @@ static int fix_mftmirr(ntfs_volume *vol)
")-:\n", s);
goto error_exit;
}
if (!ntfs_is_mft_recordp(mrec)) {
if (!ntfs_is_mft_record(mrec->magic)) {
ntfs_log_info(FAILED);
ntfs_log_error("$MFT error: Invalid mft "
"record for %s.\nCannot "
@ -380,14 +382,14 @@ static int fix_mftmirr(ntfs_volume *vol)
}
mrec2 = (MFT_RECORD*)(m2 + i * vol->mft_record_size);
if (mrec2->flags & MFT_RECORD_IN_USE) {
if (ntfs_is_baad_recordp(mrec2)) {
if (ntfs_is_baad_record(mrec2->magic)) {
ntfs_log_info(FAILED);
ntfs_log_error("$MFTMirr error: Incomplete "
"multi sector transfer "
"detected in %s.\n", s);
goto error_exit;
}
if (!ntfs_is_mft_recordp(mrec2)) {
if (!ntfs_is_mft_record(mrec2->magic)) {
ntfs_log_info(FAILED);
ntfs_log_error("$MFTMirr error: Invalid mft "
"record for %s.\n", s);
@ -395,7 +397,7 @@ static int fix_mftmirr(ntfs_volume *vol)
}
/* $MFT is corrupt but $MFTMirr is ok, use $MFTMirr. */
if (!(mrec->flags & MFT_RECORD_IN_USE) &&
!ntfs_is_mft_recordp(mrec))
!ntfs_is_mft_record(mrec->magic))
use_mirr = TRUE;
}
if (memcmp(mrec, mrec2, ntfs_mft_record_get_data_size(mrec))) {

View File

@ -6,7 +6,7 @@
* Copyright (c) 2002-2005 Richard Russon
* Copyright (c) 2003-2006 Szabolcs Szakacsits
* Copyright (c) 2004-2005 Yuval Fledel
* Copyright (c) 2004-2006 Yura Pakhuchiy
* Copyright (c) 2004-2007 Yura Pakhuchiy
* Copyright (c) 2005 Cristian Klein
*
* This utility will dump a file's attributes.
@ -113,7 +113,7 @@ static void version(void)
printf(" 2003-2006 Szabolcs Szakacsits\n");
printf(" 2003 Leonard Norrgård\n");
printf(" 2004-2005 Yuval Fledel\n");
printf(" 2004-2006 Yura Pakhuchiy\n");
printf(" 2004-2007 Yura Pakhuchiy\n");
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -333,7 +333,7 @@ static int parse_options(int argc, char *argv[])
* sle64_to_cpu(standard_attr->creation_time));
* printf("\tFile Creation Time:\t %s", time_str);
*/
static char *ntfsinfo_time_to_str(const s64 sle_ntfs_clock)
static char *ntfsinfo_time_to_str(const sle64 sle_ntfs_clock)
{
time_t unix_clock = ntfs2utc(sle_ntfs_clock);
return ctime(&unix_clock);
@ -448,7 +448,7 @@ static void ntfs_dump_volume(ntfs_volume *vol)
* @type: dump flags for this attribute type
* @flags: flags for dumping
*/
static void ntfs_dump_flags(const char *indent, ATTR_TYPES type, u32 flags)
static void ntfs_dump_flags(const char *indent, ATTR_TYPES type, le32 flags)
{
printf("%sFile attributes:\t", indent);
if (flags & FILE_ATTR_READONLY) {
@ -1030,7 +1030,7 @@ static void ntfs_dump_attr_volume_name(ATTR_RECORD *attr)
{
ntfschar *ucs_vol_name = NULL;
if (attr->value_length>0) {
if (le32_to_cpu(attr->value_length) > 0) {
char *mbs_vol_name = NULL;
int mbs_vol_name_size;
/* calculate volume name position */
@ -1038,20 +1038,18 @@ static void ntfs_dump_attr_volume_name(ATTR_RECORD *attr)
le16_to_cpu(attr->value_offset));
/* convert the name to current locale multibyte sequence */
mbs_vol_name_size = ntfs_ucstombs(ucs_vol_name,
le32_to_cpu(attr->value_length)/sizeof(ntfschar),
&mbs_vol_name,0);
le32_to_cpu(attr->value_length) /
sizeof(ntfschar), &mbs_vol_name, 0);
if (mbs_vol_name_size>0) {
/* output the converted name. */
printf("\tVolume Name:\t\t '%s'\n",mbs_vol_name);
printf("\tVolume Name:\t\t '%s'\n", mbs_vol_name);
free(mbs_vol_name);
} else {
/* an error occurred, errno holds the reason - notify the user */
ntfs_log_perror("ntfsinfo error: could not parse volume name");
}
} else {
} else
ntfs_log_perror("ntfsinfo error: could not parse "
"volume name");
} else
printf("\tVolume Name:\t\t unnamed\n");
}
}
/**
@ -1089,12 +1087,12 @@ static void ntfs_dump_attr_volume_information(ATTR_RECORD *attr)
if (vol_information->flags & VOLUME_FLAGS_MASK) {
printf("(0x%04x)\n",
(unsigned)le16_to_cpu(vol_information->flags));
} else {
} else
printf("none set (0x0000)\n");
}
if (vol_information->flags & (0xFFFF - VOLUME_FLAGS_MASK))
if (vol_information->flags & (~VOLUME_FLAGS_MASK))
printf("\t\t\t\t Unknown Flags: 0x%04x\n",
vol_information->flags & (0xFFFF - VOLUME_FLAGS_MASK));
le16_to_cpu(vol_information->flags &
(~VOLUME_FLAGS_MASK)));
}
static ntfschar NTFS_DATA_SDS[5] = { const_cpu_to_le16('$'),
@ -1168,7 +1166,7 @@ static void ntfs_dump_sds(ATTR_RECORD *attr, ntfs_inode *ni)
free(sds);
}
static const char *get_attribute_type_name(u32 type)
static const char *get_attribute_type_name(le32 type)
{
switch (type) {
case AT_UNUSED: return "$UNUSED";
@ -1367,7 +1365,7 @@ static void ntfs_dump_index_key(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type)
break;
default:
ntfs_log_verbose("\t\tIndex attr type is UNKNOWN: \t 0x%08x\n",
(unsigned)le32_to_cpu(type));
(unsigned)type);
break;
}
}
@ -1383,7 +1381,8 @@ static void ntfs_dump_index_data(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type)
{
INDEX_ENTRY_DATA *data;
data = (INDEX_ENTRY_DATA *)((u8 *)entry + entry->data_offset);
data = (INDEX_ENTRY_DATA *)((u8 *)entry +
le16_to_cpu(entry->data_offset));
switch (type) {
case INDEX_ATTR_SECURE_SII:
@ -1469,20 +1468,20 @@ static void ntfs_dump_index_data(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type)
data->quota_q.change_time));
ntfs_log_verbose("\t\tThreshold:\t\t %lld (0x%llx)\n",
(unsigned long long)
le64_to_cpu(data->quota_q.threshold),
sle64_to_cpu(data->quota_q.threshold),
(unsigned long long)
le64_to_cpu(data->quota_q.threshold));
sle64_to_cpu(data->quota_q.threshold));
ntfs_log_verbose("\t\tLimit:\t\t\t %lld (0x%llx)\n",
(unsigned long long)
le64_to_cpu(data->quota_q.limit),
sle64_to_cpu(data->quota_q.limit),
(unsigned long long)
le64_to_cpu(data->quota_q.limit));
sle64_to_cpu(data->quota_q.limit));
ntfs_log_verbose("\t\tExceeded time:\t\t %lld (0x%llx)\n",
(unsigned long long)
le64_to_cpu(data->quota_q.exceeded_time),
sle64_to_cpu(data->quota_q.exceeded_time),
(unsigned long long)
le64_to_cpu(data->quota_q.exceeded_time));
if (entry->data_length > 48) {
sle64_to_cpu(data->quota_q.exceeded_time));
if (le16_to_cpu(entry->data_length) > 48) {
char *sid;
sid = ntfs_sid_to_mbs(&data->quota_q.sid, NULL, 0);
ntfs_log_verbose("\t\tOwner SID:\t\t %s\n", sid);
@ -1491,7 +1490,7 @@ static void ntfs_dump_index_data(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type)
break;
default:
ntfs_log_verbose("\t\tIndex attr type is UNKNOWN: \t 0x%08x\n",
(unsigned)le32_to_cpu(type));
(unsigned)type);
break;
}
}
@ -2013,8 +2012,8 @@ static void ntfs_dump_attr_unknown(ATTR_RECORD *attr)
/* hex dump */
printf("\tDumping some of the attribute data:\n");
ntfs_hex_dump((u8*)attr + le16_to_cpu(attr->value_offset),
(le16_to_cpu(attr->value_length)>128)?
128 : le16_to_cpu(attr->value_length));
(le32_to_cpu(attr->value_length) > 128) ?
128 : le32_to_cpu(attr->value_length));
}
}
@ -2024,7 +2023,7 @@ static void ntfs_dump_attr_unknown(ATTR_RECORD *attr)
static void ntfs_dump_inode_general_info(ntfs_inode *inode)
{
MFT_RECORD *mrec = inode->mrec;
u16 inode_flags = mrec->flags;
le16 inode_flags = mrec->flags;
printf("Dumping Inode %llu (0x%llx)\n",
(long long)inode->mft_no,
@ -2061,7 +2060,8 @@ static void ntfs_dump_inode_general_info(ntfs_inode *inode)
inode_flags &= ~MFT_RECORD_IS_VIEW_INDEX;
}
if (inode_flags)
printf("UNKNOWN: 0x%04x", (unsigned)inode_flags);
printf("UNKNOWN: 0x%04x", (unsigned)le16_to_cpu(
inode_flags));
} else {
printf("none");
}

View File

@ -4,6 +4,7 @@
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2002-2005 Anton Altaparmakov
* Copyright (c) 2002-2003 Richard Russon
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility will resize an NTFS volume without data loss.
*
@ -367,6 +368,7 @@ static void version(void)
printf("Copyright (c) 2002-2006 Szabolcs Szakacsits\n");
printf("Copyright (c) 2002-2005 Anton Altaparmakov\n");
printf("Copyright (c) 2002-2003 Richard Russon\n");
printf("Copyright (c) 2007 Yura Pakhuchiy\n");
printf("\n%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -1169,7 +1171,7 @@ static void replace_attribute_runlist(ntfs_volume *vol,
ntfs_log_verbose("Bytes in use : %u\n", (unsigned int)
le32_to_cpu(ctx->mrec->bytes_in_use));
next_attr = (char *)a + le16_to_cpu(a->length);
next_attr = (char *)a + le32_to_cpu(a->length);
l = mp_size - l;
ntfs_log_verbose("Bytes in use new : %u\n", l + (unsigned int)
@ -1196,7 +1198,7 @@ static void replace_attribute_runlist(ntfs_volume *vol,
memmove(next_attr + l, next_attr, remains_size);
ctx->mrec->bytes_in_use = cpu_to_le32(l +
le32_to_cpu(ctx->mrec->bytes_in_use));
a->length += l;
a->length = cpu_to_le32(le32_to_cpu(a->length) + l);
}
mp = ntfs_calloc(mp_size);
@ -1609,8 +1611,8 @@ static int is_mftdata(ntfs_resize_t *resize)
if (resize->mref == 0)
return 1;
if ( MREF(resize->mrec->base_mft_record) == 0 &&
MSEQNO(resize->mrec->base_mft_record) != 0)
if (MREF_LE(resize->mrec->base_mft_record) == 0 &&
MSEQNO_LE(resize->mrec->base_mft_record) != 0)
return 1;
return 0;
@ -1872,9 +1874,9 @@ static void truncate_badclust_bad_attr(ntfs_resize_t *resize)
rl_truncate(&rl_bad, nr_clusters);
a->highest_vcn = cpu_to_le64(nr_clusters - 1LL);
a->allocated_size = cpu_to_le64(nr_clusters * vol->cluster_size);
a->data_size = cpu_to_le64(nr_clusters * vol->cluster_size);
a->highest_vcn = cpu_to_sle64(nr_clusters - 1LL);
a->allocated_size = cpu_to_sle64(nr_clusters * vol->cluster_size);
a->data_size = cpu_to_sle64(nr_clusters * vol->cluster_size);
replace_attribute_runlist(vol, resize->ctx, rl_bad);
@ -1949,10 +1951,10 @@ static void truncate_bitmap_data_attr(ntfs_resize_t *resize)
realloc_bitmap_data_attr(resize, &rl, nr_bm_clusters);
}
a->highest_vcn = cpu_to_le64(nr_bm_clusters - 1LL);
a->allocated_size = cpu_to_le64(nr_bm_clusters * vol->cluster_size);
a->data_size = cpu_to_le64(bm_bsize);
a->initialized_size = cpu_to_le64(bm_bsize);
a->highest_vcn = cpu_to_sle64(nr_bm_clusters - 1LL);
a->allocated_size = cpu_to_sle64(nr_bm_clusters * vol->cluster_size);
a->data_size = cpu_to_sle64(bm_bsize);
a->initialized_size = cpu_to_sle64(bm_bsize);
replace_attribute_runlist(vol, resize->ctx, rl);
@ -2151,7 +2153,7 @@ static void update_bootsector(ntfs_resize_t *r)
r->progress.flags |= NTFS_PROGBAR_SUPPRESS;
copy_clusters(r, r->mftmir_rl.lcn, r->mftmir_old,
r->mftmir_rl.length);
bs.mftmirr_lcn = cpu_to_le64(r->mftmir_rl.lcn);
bs.mftmirr_lcn = cpu_to_sle64(r->mftmir_rl.lcn);
r->progress.flags &= ~NTFS_PROGBAR_SUPPRESS;
}

View File

@ -3,7 +3,8 @@
*
* Copyright (c) 2002-2005 Richard Russon
* Copyright (c) 2004-2005 Holger Ohmacht
* Copyright (c) 2005 Anton Altaparmakov
* Copyright (c) 2005 Anton Altaparmakov
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility will recover deleted files from an NTFS volume.
*
@ -221,11 +222,13 @@ static int parse_inode_arg(void)
*/
static void version(void)
{
ntfs_log_info("\n%s v%s (libntfs %s) - Recover deleted files from an NTFS "
"Volume.\n\n", EXEC_NAME, VERSION,
ntfs_log_info("\n%s v%s (libntfs %s) - Recover deleted files from an "
"NTFS Volume.\n\n", EXEC_NAME, VERSION,
ntfs_libntfs_version());
ntfs_log_info("Copyright (c) 2002-2005 Richard Russon\n"
"Copyright (c) 2004-2005 Holger Ohmacht\n");
"Copyright (c) 2004-2005 Holger Ohmacht\n"
"Copyright (c) 2005 Anton Altaparmakov\n"
"Copyright (c) 2007 Yura Pakhuchiy\n");
ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -834,7 +837,8 @@ static void get_parent_name(struct filename* name, ntfs_volume* vol)
rec = calloc(1, vol->mft_record_size);
if (!rec) {
ntfs_log_error("ERROR: Couldn't allocate memory in get_parent_name()\n");
ntfs_log_error("ERROR: Couldn't allocate memory in "
"get_parent_name()\n");
return;
}
@ -842,10 +846,12 @@ static void get_parent_name(struct filename* name, ntfs_volume* vol)
if (!mft_data) {
ntfs_log_perror("ERROR: Couldn't open $MFT/$DATA");
} else {
inode_num = MREF(name->parent_mref);
inode_num = MREF_LE(name->parent_mref);
if (ntfs_attr_pread(mft_data, vol->mft_record_size * inode_num, vol->mft_record_size, rec) < 1) {
ntfs_log_error("ERROR: Couldn't read MFT Record %lld.\n", inode_num);
if (ntfs_attr_pread(mft_data, vol->mft_record_size * inode_num,
vol->mft_record_size, rec) < 1) {
ntfs_log_error("ERROR: Couldn't read MFT Record %lld"
".\n", inode_num);
} else if ((filename_attr = verify_parent(name, rec))) {
if (ntfs_ucstombs(filename_attr->file_name,
filename_attr->file_name_length,
@ -906,11 +912,13 @@ static int get_filenames(struct ufile *file, ntfs_volume* vol)
while ((rec = find_attribute(AT_FILE_NAME, ctx))) {
/* We know this will always be resident. */
attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu(rec->value_offset));
attr = (FILE_NAME_ATTR *)((char *)rec +
le16_to_cpu(rec->value_offset));
name = calloc(1, sizeof(*name));
if (!name) {
ntfs_log_error("ERROR: Couldn't allocate memory in get_filenames().\n");
ntfs_log_error("ERROR: Couldn't allocate memory in "
"get_filenames().\n");
count = -1;
break;
}
@ -990,28 +998,32 @@ static int get_data(struct ufile *file, ntfs_volume *vol)
while ((rec = find_attribute(AT_DATA, ctx))) {
data = calloc(1, sizeof(*data));
if (!data) {
ntfs_log_error("ERROR: Couldn't allocate memory in get_data().\n");
ntfs_log_error("ERROR: Couldn't allocate memory in "
"get_data().\n");
count = -1;
break;
}
data->resident = !rec->non_resident;
data->compressed = rec->flags & ATTR_IS_COMPRESSED;
data->encrypted = rec->flags & ATTR_IS_ENCRYPTED;
data->compressed = (rec->flags & ATTR_IS_COMPRESSED) ? 1 : 0;
data->encrypted = (rec->flags & ATTR_IS_ENCRYPTED) ? 1 : 0;
if (rec->name_length) {
data->uname = (ntfschar *) ((char *) rec + le16_to_cpu(rec->name_offset));
data->uname = (ntfschar *)((char *)rec +
le16_to_cpu(rec->name_offset));
data->uname_len = rec->name_length;
if (ntfs_ucstombs(data->uname, data->uname_len, &data->name,
0) < 0) {
ntfs_log_error("ERROR: Cannot translate name into current locale.\n");
if (ntfs_ucstombs(data->uname, data->uname_len,
&data->name, 0) < 0) {
ntfs_log_error("ERROR: Cannot translate name "
"into current locale.\n");
}
}
if (data->resident) {
data->size_data = le32_to_cpu(rec->value_length);
data->data = ((char*) (rec)) + le16_to_cpu(rec->value_offset);
data->size_data = le32_to_cpu(rec->value_length);
data->data = (char*)rec +
le16_to_cpu(rec->value_offset);
} else {
data->size_alloc = sle64_to_cpu(rec->allocated_size);
data->size_data = sle64_to_cpu(rec->data_size);
@ -1169,17 +1181,20 @@ static int calc_percentage(struct ufile *file, ntfs_volume *vol)
clusters_free = 0;
if (data->encrypted) {
ntfs_log_verbose("File is encrypted, recovery is impossible.\n");
ntfs_log_verbose("File is encrypted, recovery is "
"impossible.\n");
continue;
}
if (data->compressed) {
ntfs_log_verbose("File is compressed, recovery not yet implemented.\n");
ntfs_log_verbose("File is compressed, recovery not yet "
"implemented.\n");
continue;
}
if (data->resident) {
ntfs_log_verbose("File is resident, therefore recoverable.\n");
ntfs_log_verbose("File is resident, therefore "
"recoverable.\n");
percent = 100;
data->percent = 100;
continue;
@ -1187,16 +1202,18 @@ static int calc_percentage(struct ufile *file, ntfs_volume *vol)
rl = data->runlist;
if (!rl) {
ntfs_log_verbose("File has no runlist, hence no data.\n");
ntfs_log_verbose("File has no runlist, hence no data."
"\n");
continue;
}
if (rl[0].length <= 0) {
ntfs_log_verbose("File has an empty runlist, hence no data.\n");
ntfs_log_verbose("File has an empty runlist, hence no "
"data.\n");
continue;
}
if (rl[0].lcn == LCN_RL_NOT_MAPPED) { /* extended mft record */
if (rl[0].lcn == LCN_RL_NOT_MAPPED) { /* extended mft record */
ntfs_log_verbose("Missing segment at beginning, %lld "
"clusters\n", (long long)rl[0].length);
clusters_inuse += rl[0].length;
@ -1288,12 +1305,18 @@ static void dump_record(struct ufile *file)
ntfs_log_quiet("Filename: (%d) %s\n", f->name_space, f->name);
ntfs_log_quiet("File Flags: ");
if (f->flags & FILE_ATTR_SYSTEM) ntfs_log_quiet("System ");
if (f->flags & FILE_ATTR_DIRECTORY) ntfs_log_quiet("Directory ");
if (f->flags & FILE_ATTR_SPARSE_FILE) ntfs_log_quiet("Sparse ");
if (f->flags & FILE_ATTR_REPARSE_POINT) ntfs_log_quiet("Reparse ");
if (f->flags & FILE_ATTR_COMPRESSED) ntfs_log_quiet("Compressed ");
if (f->flags & FILE_ATTR_ENCRYPTED) ntfs_log_quiet("Encrypted ");
if (f->flags & FILE_ATTR_SYSTEM)
ntfs_log_quiet("System ");
if (f->flags & FILE_ATTR_DIRECTORY)
ntfs_log_quiet("Directory ");
if (f->flags & FILE_ATTR_SPARSE_FILE)
ntfs_log_quiet("Sparse ");
if (f->flags & FILE_ATTR_REPARSE_POINT)
ntfs_log_quiet("Reparse ");
if (f->flags & FILE_ATTR_COMPRESSED)
ntfs_log_quiet("Compressed ");
if (f->flags & FILE_ATTR_ENCRYPTED)
ntfs_log_quiet("Encrypted ");
if (!(f->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_DIRECTORY |
FILE_ATTR_SPARSE_FILE | FILE_ATTR_REPARSE_POINT |
FILE_ATTR_COMPRESSED | FILE_ATTR_ENCRYPTED))) {
@ -1310,13 +1333,17 @@ static void dump_record(struct ufile *file)
ntfs_log_quiet("Size alloc: %lld\n", f->size_alloc);
ntfs_log_quiet("Size data: %lld\n", f->size_data);
strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_c));
strftime(buffer, sizeof(buffer), "%F %R",
localtime(&f->date_c));
ntfs_log_quiet("Date C: %s\n", buffer);
strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_a));
strftime(buffer, sizeof(buffer), "%F %R",
localtime(&f->date_a));
ntfs_log_quiet("Date A: %s\n", buffer);
strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_m));
strftime(buffer, sizeof(buffer), "%F %R",
localtime(&f->date_m));
ntfs_log_quiet("Date M: %s\n", buffer);
strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_r));
strftime(buffer, sizeof(buffer), "%F %R",
localtime(&f->date_r));
ntfs_log_quiet("Date R: %s\n", buffer);
}
@ -1349,7 +1376,8 @@ static void dump_record(struct ufile *file)
}
}
ntfs_log_quiet("Amount potentially recoverable %d%%\n", d->percent);
ntfs_log_quiet("Amount potentially recoverable %d%%\n",
d->percent);
}
ntfs_log_quiet("________________________________________\n\n");
@ -1402,10 +1430,14 @@ static void list_record(struct ufile *file)
struct data *d = list_entry(item, struct data, list);
if (!d->name) {
if (d->resident) flagr = 'R';
else flagr = 'N';
if (d->compressed) flagc = 'C'; /* These two are mutually exclusive */
if (d->encrypted) flagc = 'E';
if (d->resident)
flagr = 'R';
else
flagr = 'N';
if (d->compressed)
flagc = 'C';
if (d->encrypted)
flagc = 'E';
percent = max(percent, d->percent);
}

View File

@ -2,6 +2,7 @@
* ntfsundelete - Part of the Linux-NTFS project.
*
* Copyright (c) 2002 Richard Russon
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility will recover deleted files from an NTFS volume.
*
@ -72,7 +73,7 @@ struct filename {
time_t date_r; /* read */
char *name; /* Filename in current locale */
FILE_NAME_TYPE_FLAGS name_space;
long long parent_mref;
leMFT_REF parent_mref;
char *parent_name;
};

View File

@ -324,7 +324,6 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
ace->type = ACCESS_ALLOWED_ACE_TYPE;
ace->flags = 0;
ace->size = const_cpu_to_le16(0x18);
ace->mask = 9;
ace->mask = SYNCHRONIZE | READ_CONTROL | FILE_READ_ATTRIBUTES |
FILE_TRAVERSE | FILE_READ_EA | FILE_LIST_DIRECTORY;
ace->sid.revision = SID_REVISION;

View File

@ -4,6 +4,7 @@
* Copyright (c) 2002-2005 Richard Russon
* Copyright (c) 2003-2006 Anton Altaparmakov
* Copyright (c) 2003 Lode Leroy
* Copyright (c) 2005-2007 Yura Pakhuchiy
*
* A set of shared functions for ntfs utilities
*
@ -578,7 +579,8 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b
name = NULL;
namelen = ntfs_ucsnlen(attrdef->name, sizeof(attrdef->name));
if (ntfs_ucstombs(attrdef->name, namelen, &name, 0) < 0) {
ntfs_log_error("Couldn't translate attribute type to current locale.\n");
ntfs_log_error("Couldn't translate attribute type to "
"current locale.\n");
// <UNKNOWN>?
return 0;
}
@ -602,9 +604,10 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b
name = NULL;
namelen = attr->name_length;
if (ntfs_ucstombs((ntfschar *)((char *)attr + attr->name_offset),
namelen, &name, 0) < 0) {
ntfs_log_error("Couldn't translate attribute name to current locale.\n");
if (ntfs_ucstombs((ntfschar *)((char *)attr + le16_to_cpu(
attr->name_offset)), namelen, &name, 0) < 0) {
ntfs_log_error("Couldn't translate attribute name to current "
"locale.\n");
// <UNKNOWN>?
len = snprintf(buffer, bufsize, "<UNKNOWN>");
return 0;
@ -785,7 +788,7 @@ int utils_is_metadata(ntfs_inode *inode)
file = inode->mrec;
if (file && (file->base_mft_record != 0)) {
num = MREF(file->base_mft_record);
num = MREF_LE(file->base_mft_record);
if (__metadata(vol, num) == 1)
return 1;
}
@ -796,9 +799,9 @@ int utils_is_metadata(ntfs_inode *inode)
return -1;
/* We know this will always be resident. */
attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu(rec->value_offset));
attr = (FILE_NAME_ATTR *)((char *)rec + le16_to_cpu(rec->value_offset));
num = MREF(attr->parent_directory);
num = MREF_LE(attr->parent_directory);
if ((num != FILE_root) && (__metadata(vol, num) == 1))
return 1;