Strengthened variable types

edge.strict_endians
Jean-Pierre André 2010-12-21 15:51:07 +01:00
parent 1ca4a556b2
commit 8f4aa0883b
5 changed files with 144 additions and 108 deletions

View File

@ -1240,7 +1240,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m,
a->instance = m->next_attr_instance;
m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance)
+ 1) & 0xffff);
a->lowest_vcn = 0;
a->lowest_vcn = cpu_to_le64(0);
a->highest_vcn = cpu_to_sle64(highest_vcn - 1LL);
a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7));
memset(a->reserved1, 0, sizeof(a->reserved1));
@ -1259,7 +1259,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m,
a->compression_unit = 4;
inited_size = val_len;
/* FIXME: Set the compressed size. */
a->compressed_size = 0;
a->compressed_size = cpu_to_le64(0);
/* FIXME: Write out the compressed data. */
/* FIXME: err = build_mapping_pairs_compressed(); */
err = -EOPNOTSUPP;
@ -1425,7 +1425,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m,
a->instance = m->next_attr_instance;
m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance)
+ 1) & 0xffff);
a->lowest_vcn = 0;
a->lowest_vcn = cpu_to_le64(0);
for (i = 0; rl[i].length; i++)
;
a->highest_vcn = cpu_to_sle64(rl[i].vcn - 1);
@ -1447,7 +1447,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m,
}
a->compression_unit = 4;
/* FIXME: Set the compressed size. */
a->compressed_size = 0;
a->compressed_size = cpu_to_le64(0);
/* FIXME: Write out the compressed data. */
/* FIXME: err = build_mapping_pairs_compressed(); */
err = -EOPNOTSUPP;
@ -1609,7 +1609,7 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags,
si.version_number = cpu_to_le32(0);
si.class_id = cpu_to_le32(0);
si.security_id = security_id;
if (si.security_id != 0)
if (si.security_id != const_cpu_to_le32(0))
sd_size = 72;
/* FIXME: $Quota support... */
si.owner_id = cpu_to_le32(0);
@ -1618,7 +1618,8 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags,
si.usn = cpu_to_le64(0ULL);
/* NTFS 1.2: size of si = 48, NTFS 3.[01]: size of si = 72 */
err = insert_resident_attr_in_mft_record(m, AT_STANDARD_INFORMATION,
NULL, 0, 0, 0, 0, (u8*)&si, sd_size);
NULL, 0, CASE_SENSITIVE, const_cpu_to_le16(0),
0, (u8*)&si, sd_size);
if (err < 0)
ntfs_log_perror("add_attr_std_info failed");
return err;
@ -1647,8 +1648,8 @@ static int add_attr_file_name(MFT_RECORD *m, const leMFT_REF parent_dir,
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,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
int eo = errno;
ntfs_log_error("BUG: Standard information attribute not "
"present in file record.\n");
@ -1700,8 +1701,9 @@ static int add_attr_file_name(MFT_RECORD *m, const leMFT_REF parent_dir,
/* No terminating null in file names. */
fn->file_name_length = i;
fn_size = sizeof(FILE_NAME_ATTR) + i * sizeof(ntfschar);
i = insert_resident_attr_in_mft_record(m, AT_FILE_NAME, NULL, 0, 0,
0, RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size);
i = insert_resident_attr_in_mft_record(m, AT_FILE_NAME, NULL, 0,
CASE_SENSITIVE, const_cpu_to_le16(0),
RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size);
free(fn);
if (i < 0)
ntfs_log_error("add_attr_file_name failed: %s\n", strerror(-i));
@ -1728,7 +1730,8 @@ static int add_attr_object_id(MFT_RECORD *m, const GUID *object_id)
.object_id = *object_id,
};
err = insert_resident_attr_in_mft_record(m, AT_OBJECT_ID, NULL,
0, 0, 0, 0, (u8*)&oi, sizeof(oi.object_id));
0, CASE_SENSITIVE, const_cpu_to_le16(0),
0, (u8*)&oi, sizeof(oi.object_id));
if (err < 0)
ntfs_log_error("add_attr_vol_info failed: %s\n", strerror(-err));
return err;
@ -1752,11 +1755,13 @@ static int add_attr_sd(MFT_RECORD *m, const u8 *sd, const s64 sd_len)
if (le32_to_cpu(m->bytes_in_use) + 24 + sd_len >
le32_to_cpu(m->bytes_allocated))
err = insert_non_resident_attr_in_mft_record(m,
AT_SECURITY_DESCRIPTOR, NULL, 0, 0, 0, sd,
AT_SECURITY_DESCRIPTOR, NULL, 0,
CASE_SENSITIVE, const_cpu_to_le16(0), sd,
sd_len);
else
err = insert_resident_attr_in_mft_record(m,
AT_SECURITY_DESCRIPTOR, NULL, 0, 0, 0, 0, sd,
AT_SECURITY_DESCRIPTOR, NULL, 0,
CASE_SENSITIVE, const_cpu_to_le16(0), 0, sd,
sd_len);
if (err < 0)
ntfs_log_error("add_attr_sd failed: %s\n", strerror(-err));
@ -1850,8 +1855,9 @@ static int add_attr_vol_name(MFT_RECORD *m, const char *vol_name,
return -ENAMETOOLONG;
}
}
i = insert_resident_attr_in_mft_record(m, AT_VOLUME_NAME, NULL, 0, 0,
0, 0, (u8*)uname, uname_len*sizeof(ntfschar));
i = insert_resident_attr_in_mft_record(m, AT_VOLUME_NAME, NULL, 0,
CASE_SENSITIVE, const_cpu_to_le16(0),
0, (u8*)uname, uname_len*sizeof(ntfschar));
free(uname);
if (i < 0)
ntfs_log_error("add_attr_vol_name failed: %s\n", strerror(-i));
@ -1874,7 +1880,8 @@ static int add_attr_vol_info(MFT_RECORD *m, const VOLUME_FLAGS flags,
vi.minor_ver = minor_ver;
vi.flags = flags & VOLUME_FLAGS_MASK;
err = insert_resident_attr_in_mft_record(m, AT_VOLUME_INFORMATION, NULL,
0, 0, 0, 0, (u8*)&vi, sizeof(vi));
0, CASE_SENSITIVE, const_cpu_to_le16(0),
0, (u8*)&vi, sizeof(vi));
if (err < 0)
ntfs_log_error("add_attr_vol_info failed: %s\n", strerror(-err));
return err;
@ -1899,7 +1906,8 @@ static int add_attr_index_root(MFT_RECORD *m, const char *name,
r = ntfs_malloc(val_len);
if (!r)
return -errno;
r->type = (indexed_attr_type == AT_FILE_NAME) ? AT_FILE_NAME : 0;
r->type = (indexed_attr_type == AT_FILE_NAME)
? AT_FILE_NAME : const_cpu_to_le32(0);
if (indexed_attr_type == AT_FILE_NAME &&
collation_rule != COLLATION_FILE_NAME) {
free(r);
@ -1954,7 +1962,8 @@ static int add_attr_index_root(MFT_RECORD *m, const char *name,
e->flags = INDEX_ENTRY_END;
e->reserved = const_cpu_to_le16(0);
err = insert_resident_attr_in_mft_record(m, AT_INDEX_ROOT, name,
name_len, ic, 0, 0, (u8*)r, val_len);
name_len, ic, const_cpu_to_le16(0), 0,
(u8*)r, val_len);
free(r);
if (err < 0)
ntfs_log_error("add_attr_index_root failed: %s\n", strerror(-err));
@ -1973,8 +1982,8 @@ static int add_attr_index_alloc(MFT_RECORD *m, const char *name,
int err;
err = insert_non_resident_attr_in_mft_record(m, AT_INDEX_ALLOCATION,
name, name_len, ic, 0, index_alloc_val,
index_alloc_val_len);
name, name_len, ic, const_cpu_to_le16(0),
index_alloc_val, index_alloc_val_len);
if (err < 0)
ntfs_log_error("add_attr_index_alloc failed: %s\n", strerror(-err));
return err;
@ -1995,10 +2004,12 @@ static int add_attr_bitmap(MFT_RECORD *m, const char *name, const u32 name_len,
if (le32_to_cpu(m->bytes_in_use) + 24 + bitmap_len >
le32_to_cpu(m->bytes_allocated))
err = insert_non_resident_attr_in_mft_record(m, AT_BITMAP, name,
name_len, ic, 0, bitmap, bitmap_len);
name_len, ic, const_cpu_to_le16(0), bitmap,
bitmap_len);
else
err = insert_resident_attr_in_mft_record(m, AT_BITMAP, name,
name_len, ic, 0, 0, bitmap, bitmap_len);
name_len, ic, const_cpu_to_le16(0), 0,
bitmap, bitmap_len);
if (err < 0)
ntfs_log_error("add_attr_bitmap failed: %s\n", strerror(-err));
@ -2021,7 +2032,7 @@ static int add_attr_bitmap_positioned(MFT_RECORD *m, const char *name,
int err;
err = insert_positioned_attr_in_mft_record(m, AT_BITMAP, name, name_len,
ic, 0, rl, bitmap, bitmap_len);
ic, const_cpu_to_le16(0), rl, bitmap, bitmap_len);
if (err < 0)
ntfs_log_error("add_attr_bitmap_positioned failed: %s\n",
strerror(-err));
@ -2116,8 +2127,8 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name,
/* Set USN to 1. */
*(le16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) =
cpu_to_le16(1);
ia_val->lsn = 0;
ia_val->index_block_vcn = 0;
ia_val->lsn = cpu_to_le64(0);
ia_val->index_block_vcn = cpu_to_le64(0);
ia_val->index.ih_flags = LEAF_NODE;
/* Align to 8-byte boundary. */
ia_val->index.entries_offset = cpu_to_le32((sizeof(INDEX_HEADER) +
@ -2159,7 +2170,8 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name,
goto err_out;
}
/* Set VCN pointer to 0LL. */
*(leVCN*)((char*)re + le16_to_cpu(re->length) - sizeof(VCN)) = 0;
*(leVCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) =
cpu_to_le64(0);
err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size);
if (err) {
err = -errno;
@ -2250,8 +2262,8 @@ static int ntfs_index_keys_compare(u8 *key1, u8 *key2, int key1_length,
if (collation_rule == COLLATION_NTOFS_ULONG) {
/* i.e. $SII or $QUOTA-$Q */
u1 = le32_to_cpup(key1);
u2 = le32_to_cpup(key2);
u1 = le32_to_cpup((const le32*)key1);
u2 = le32_to_cpup((const le32*)key2);
if (u1 < u2)
return -1;
if (u1 > u2)
@ -2263,8 +2275,8 @@ static int ntfs_index_keys_compare(u8 *key1, u8 *key2, int key1_length,
/* i.e $OBJID-$O */
i = 0;
while (i < min(key1_length, key2_length)) {
u1 = le32_to_cpup(key1 + i);
u2 = le32_to_cpup(key2 + i);
u1 = le32_to_cpup((const le32*)(key1 + i));
u2 = le32_to_cpup((const le32*)(key2 + i));
if (u1 < u2)
return -1;
if (u1 > u2)
@ -2339,8 +2351,8 @@ static int insert_index_entry_in_res_dir_index(INDEX_ENTRY *idx, u32 idx_size,
err = -ENOMEM;
goto err_out;
}
if (mkntfs_attr_lookup(AT_INDEX_ROOT, name, name_size, 0, 0, NULL, 0,
ctx)) {
if (mkntfs_attr_lookup(AT_INDEX_ROOT, name, name_size,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
err = -EEXIST;
goto err_out;
}
@ -2550,7 +2562,7 @@ static int initialize_quota(MFT_RECORD *m)
idx_entry_q1_data->change_time = timespec2ntfs(mkntfs_time());
idx_entry_q1_data->threshold = cpu_to_sle64(-1);
idx_entry_q1_data->limit = cpu_to_sle64(-1);
idx_entry_q1_data->exceeded_time = 0;
idx_entry_q1_data->exceeded_time = const_cpu_to_le64(0);
err = insert_index_entry_in_res_dir_index(idx_entry_q1, q1_size, m,
NTFS_INDEX_Q, 2, AT_UNUSED);
free(idx_entry_q1);
@ -2577,7 +2589,7 @@ static int initialize_quota(MFT_RECORD *m)
idx_entry_q2_data->change_time = timespec2ntfs(mkntfs_time());;
idx_entry_q2_data->threshold = cpu_to_sle64(-1);
idx_entry_q2_data->limit = cpu_to_sle64(-1);
idx_entry_q2_data->exceeded_time = 0;
idx_entry_q2_data->exceeded_time = const_cpu_to_le64(0);
idx_entry_q2_data->sid.revision = 1;
idx_entry_q2_data->sid.sub_authority_count = 2;
for (i = 0; i < 5; i++)
@ -2835,8 +2847,9 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const leMFT_REF ref_parent,
}
m_file->link_count = cpu_to_le16(i + 1);
/* Add the file_name to @m_file. */
i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, 0,
0, RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size);
i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0,
CASE_SENSITIVE, const_cpu_to_le16(0),
RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size);
if (i < 0) {
ntfs_log_error("create_hardlink failed adding file name "
"attribute: %s\n", strerror(-i));
@ -2947,8 +2960,9 @@ static int create_hardlink(INDEX_BLOCK *idx, const leMFT_REF ref_parent,
}
m_file->link_count = cpu_to_le16(i + 1);
/* Add the file_name to @m_file. */
i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, 0,
0, RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size);
i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0,
CASE_SENSITIVE, cpu_to_le16(0),
RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size);
if (i < 0) {
ntfs_log_error("create_hardlink failed adding file name attribute: "
"%s\n", strerror(-i));
@ -3851,8 +3865,8 @@ static BOOL mkntfs_sync_index_record(INDEX_ALLOCATION* idx, MFT_RECORD* m,
return FALSE;
}
/* FIXME: This should be IGNORE_CASE! */
if (mkntfs_attr_lookup(AT_INDEX_ALLOCATION, name, name_len, 0, 0,
NULL, 0, ctx)) {
if (mkntfs_attr_lookup(AT_INDEX_ALLOCATION, name, name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
ntfs_attr_put_search_ctx(ctx);
ntfs_log_error("BUG: $INDEX_ALLOCATION attribute not found.\n");
return FALSE;
@ -3916,7 +3930,8 @@ static BOOL create_file_volume(MFT_RECORD *m, leMFT_REF root_ref,
err = add_attr_sd(m, sd, i);
}
if (!err)
err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0);
err = add_attr_data(m, NULL, 0, CASE_SENSITIVE,
const_cpu_to_le16(0), NULL, 0);
if (!err)
err = add_attr_vol_name(m, g_vol->vol_name, g_vol->vol_name ?
strlen(g_vol->vol_name) : 0);
@ -4005,7 +4020,7 @@ static BOOL mkntfs_create_root_structures(void)
int err;
u8 *sd;
FILE_ATTR_FLAGS extend_flags;
VOLUME_FLAGS volume_flags = 0;
VOLUME_FLAGS volume_flags = const_cpu_to_le16(0);
int nr_sysfiles;
u8 *buf_log = NULL;
int buf_sds_first_size;
@ -4113,11 +4128,13 @@ static BOOL mkntfs_create_root_structures(void)
}
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$I30", 4, 0, AT_FILE_NAME,
COLLATION_FILE_NAME, g_vol->indx_record_size);
err = add_attr_index_root(m, "$I30", 4, CASE_SENSITIVE,
AT_FILE_NAME, COLLATION_FILE_NAME,
g_vol->indx_record_size);
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = upgrade_to_large_index(m, "$I30", 4, 0, &g_index_block);
err = upgrade_to_large_index(m, "$I30", 4, CASE_SENSITIVE,
&g_index_block);
if (!err) {
ntfs_attr_search_ctx *ctx;
ATTR_RECORD *a;
@ -4128,8 +4145,8 @@ static BOOL mkntfs_create_root_structures(void)
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,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
ntfs_attr_put_search_ctx(ctx);
ntfs_log_error("BUG: $FILE_NAME attribute not found."
"\n");
@ -4150,8 +4167,8 @@ static BOOL mkntfs_create_root_structures(void)
/* Add all other attributes, on a per-file basis for clarity. */
ntfs_log_verbose("Creating $MFT (mft record 0)\n");
m = (MFT_RECORD*)g_buf;
err = add_attr_data_positioned(m, NULL, 0, 0, 0, g_rl_mft, g_buf,
g_mft_size);
err = add_attr_data_positioned(m, NULL, 0, CASE_SENSITIVE,
const_cpu_to_le16(0), g_rl_mft, g_buf, g_mft_size);
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_MFT, 1), g_mft_size,
@ -4160,7 +4177,8 @@ static BOOL mkntfs_create_root_structures(void)
FILE_NAME_WIN32_AND_DOS);
/* mft_bitmap is not modified in mkntfs; no need to sync it later. */
if (!err)
err = add_attr_bitmap_positioned(m, NULL, 0, 0, g_rl_mft_bmp,
err = add_attr_bitmap_positioned(m, NULL, 0, CASE_SENSITIVE,
g_rl_mft_bmp,
g_mft_bitmap, g_mft_bitmap_byte_size);
if (err < 0) {
ntfs_log_error("Couldn't create $MFT: %s\n", strerror(-err));
@ -4168,7 +4186,8 @@ static BOOL mkntfs_create_root_structures(void)
}
ntfs_log_verbose("Creating $MFTMirr (mft record 1)\n");
m = (MFT_RECORD*)(g_buf + 1 * g_vol->mft_record_size);
err = add_attr_data_positioned(m, NULL, 0, 0, 0, g_rl_mftmirr, g_buf,
err = add_attr_data_positioned(m, NULL, 0, CASE_SENSITIVE,
const_cpu_to_le16(0), g_rl_mftmirr, g_buf,
g_rl_mftmirr[0].length * g_vol->cluster_size);
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
@ -4188,7 +4207,8 @@ static BOOL mkntfs_create_root_structures(void)
if (!buf_log)
return FALSE;
memset(buf_log, -1, g_logfile_size);
err = add_attr_data_positioned(m, NULL, 0, 0, 0, g_rl_logfile, buf_log,
err = add_attr_data_positioned(m, NULL, 0, CASE_SENSITIVE,
const_cpu_to_le16(0), g_rl_logfile, buf_log,
g_logfile_size);
free(buf_log);
buf_log = NULL;
@ -4205,8 +4225,8 @@ static BOOL mkntfs_create_root_structures(void)
}
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, CASE_SENSITIVE, const_cpu_to_le16(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),
@ -4229,8 +4249,9 @@ static BOOL mkntfs_create_root_structures(void)
/* windows 2003 will regard the volume as corrupt (ERSO) */
if (!err)
err = insert_non_resident_attr_in_mft_record(m,
AT_DATA, NULL, 0, 0, 0,
g_lcn_bitmap, g_lcn_bitmap_byte_size);
AT_DATA, NULL, 0, CASE_SENSITIVE,
const_cpu_to_le16(0), (const u8*)NULL,
g_lcn_bitmap_byte_size);
if (!err)
@ -4323,8 +4344,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, CASE_SENSITIVE,
const_cpu_to_le16(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),
@ -4368,10 +4389,12 @@ static BOOL mkntfs_create_root_structures(void)
m = (MFT_RECORD*)(g_buf + 8 * g_vol->mft_record_size);
/* FIXME: This should be IGNORE_CASE */
/* Create a sparse named stream of size equal to the volume size. */
err = add_attr_data_positioned(m, "$Bad", 4, 0, 0, g_rl_bad, NULL,
err = add_attr_data_positioned(m, "$Bad", 4, CASE_SENSITIVE,
const_cpu_to_le16(0), g_rl_bad, NULL,
g_vol->nr_clusters * g_vol->cluster_size);
if (!err) {
err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0);
err = add_attr_data(m, NULL, 0, CASE_SENSITIVE,
const_cpu_to_le16(0), NULL, 0);
}
if (!err) {
err = create_hardlink(g_index_block, root_ref, m,
@ -4406,18 +4429,20 @@ static BOOL mkntfs_create_root_structures(void)
return FALSE;
init_secure_sds(buf_sds);
memcpy(buf_sds + 0x40000, buf_sds, buf_sds_first_size);
err = add_attr_data(m, "$SDS", 4, 0, 0, (u8*)buf_sds,
err = add_attr_data(m, "$SDS", 4, CASE_SENSITIVE,
const_cpu_to_le16(0), (u8*)buf_sds,
buf_sds_size);
}
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$SDH", 4, 0, AT_UNUSED,
COLLATION_NTOFS_SECURITY_HASH,
err = add_attr_index_root(m, "$SDH", 4, CASE_SENSITIVE,
AT_UNUSED, COLLATION_NTOFS_SECURITY_HASH,
g_vol->indx_record_size);
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$SII", 4, 0, AT_UNUSED,
COLLATION_NTOFS_ULONG, g_vol->indx_record_size);
err = add_attr_index_root(m, "$SII", 4, CASE_SENSITIVE,
AT_UNUSED, COLLATION_NTOFS_ULONG,
g_vol->indx_record_size);
if (!err)
err = initialize_secure(buf_sds, buf_sds_first_size, m);
free(buf_sds);
@ -4428,8 +4453,8 @@ static BOOL mkntfs_create_root_structures(void)
}
ntfs_log_verbose("Creating $UpCase (mft record 0xa)\n");
m = (MFT_RECORD*)(g_buf + 0xa * g_vol->mft_record_size);
err = add_attr_data(m, NULL, 0, 0, 0, (u8*)g_vol->upcase,
g_vol->upcase_len << 1);
err = add_attr_data(m, NULL, 0, CASE_SENSITIVE, const_cpu_to_le16(0),
(u8*)g_vol->upcase, g_vol->upcase_len << 1);
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_UpCase, FILE_UpCase),
@ -4458,8 +4483,9 @@ static BOOL mkntfs_create_root_structures(void)
"$Extend", FILE_NAME_WIN32_AND_DOS);
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$I30", 4, 0, AT_FILE_NAME,
COLLATION_FILE_NAME, g_vol->indx_record_size);
err = add_attr_index_root(m, "$I30", 4, CASE_SENSITIVE,
AT_FILE_NAME, COLLATION_FILE_NAME,
g_vol->indx_record_size);
if (err < 0) {
ntfs_log_error("Couldn't create $Extend: %s\n",
strerror(-err));
@ -4469,7 +4495,8 @@ static BOOL mkntfs_create_root_structures(void)
for (i = 0xc; i < 0x10; i++) {
ntfs_log_verbose("Creating system file (mft record 0x%x)\n", i);
m = (MFT_RECORD*)(g_buf + i * g_vol->mft_record_size);
err = add_attr_data(m, NULL, 0, 0, 0, NULL, 0);
err = add_attr_data(m, NULL, 0, CASE_SENSITIVE,
const_cpu_to_le16(0), NULL, 0);
if (!err) {
init_system_file_sd(i, &sd, &j);
err = add_attr_sd(m, sd, j);
@ -4495,11 +4522,11 @@ static BOOL mkntfs_create_root_structures(void)
0, 0, "$Quota", FILE_NAME_WIN32_AND_DOS);
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$Q", 2, 0, AT_UNUSED,
err = add_attr_index_root(m, "$Q", 2, CASE_SENSITIVE, AT_UNUSED,
COLLATION_NTOFS_ULONG, g_vol->indx_record_size);
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$O", 2, 0, AT_UNUSED,
err = add_attr_index_root(m, "$O", 2, CASE_SENSITIVE, AT_UNUSED,
COLLATION_NTOFS_SID, g_vol->indx_record_size);
if (!err)
err = initialize_quota(m);
@ -4520,7 +4547,7 @@ static BOOL mkntfs_create_root_structures(void)
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$O", 2, 0, AT_UNUSED,
err = add_attr_index_root(m, "$O", 2, CASE_SENSITIVE, AT_UNUSED,
COLLATION_NTOFS_ULONGS,
g_vol->indx_record_size);
#ifdef ENABLE_UUID
@ -4545,7 +4572,7 @@ static BOOL mkntfs_create_root_structures(void)
"$Reparse", FILE_NAME_WIN32_AND_DOS);
/* FIXME: This should be IGNORE_CASE */
if (!err)
err = add_attr_index_root(m, "$R", 2, 0, AT_UNUSED,
err = add_attr_index_root(m, "$R", 2, CASE_SENSITIVE, AT_UNUSED,
COLLATION_NTOFS_ULONGS, g_vol->indx_record_size);
if (err < 0) {
ntfs_log_error("Couldn't create $Reparse: %s\n",
@ -4670,7 +4697,8 @@ static int mkntfs_redirect(struct mkntfs_options *opts2)
goto done;
}
if (mkntfs_attr_lookup(AT_DATA, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) {
if (mkntfs_attr_lookup(AT_DATA, AT_UNNAMED, 0, CASE_SENSITIVE,
0, NULL, 0, ctx)) {
ntfs_log_error("BUG: $DATA attribute not found.\n");
goto done;
}

View File

@ -187,11 +187,12 @@ 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. */
/* the following is aligned dangerously (too late...) */
le32 cluster_size;
le64 device_size;
sle64 nr_clusters;
le64 inuse;
le32 offset_to_image_data; /* From start of image_hdr. */
} __attribute__((__packed__)) image_hdr;
#define NTFSCLONE_IMG_HEADER_SIZE_OLD \
@ -252,7 +253,7 @@ static void err_printf(const char *fmt, ...)
__attribute__((noreturn))
__attribute__((format(printf, 1, 2)))
static int err_exit(const char *fmt, ...)
static void err_exit(const char *fmt, ...)
{
va_list ap;
@ -266,7 +267,7 @@ static int err_exit(const char *fmt, ...)
__attribute__((noreturn))
__attribute__((format(printf, 1, 2)))
static int perr_exit(const char *fmt, ...)
static void perr_exit(const char *fmt, ...)
{
va_list ap;
int eo = errno;
@ -629,7 +630,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;
s64 count_buf;
char buff[1 + sizeof(count)];
buff[0] = 0;
@ -764,7 +765,7 @@ static void restore_image(void)
static void wipe_index_entry_timestams(INDEX_ENTRY *e)
{
static const struct timespec zero_time = { .tv_sec = 0, .tv_nsec = 0 };
s64 timestamp = timespec2ntfs(zero_time);
le64 timestamp = timespec2ntfs(zero_time);
/* FIXME: can fall into infinite loop if corrupted */
while (!(e->ie_flags & INDEX_ENTRY_END)) {
@ -804,7 +805,8 @@ static void wipe_index_allocation_timestamps(ntfs_inode *ni, ATTR_RECORD *attr)
name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset));
name_len = attr->name_length;
byte = bitmap = ntfs_attr_readall(ni, AT_BITMAP, name, name_len, NULL);
byte = bitmap = ntfs_attr_readall(ni, AT_BITMAP, name, name_len,
NULL);
if (!byte) {
perr_printf("Failed to read $BITMAP attribute");
goto out_indexr;
@ -873,7 +875,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, le64 timestamp)
{
INDEX_ENTRY *entry;
INDEX_ROOT *iroot;
@ -897,7 +899,7 @@ static void wipe_index_root_timestamps(ATTR_RECORD *attr, s64 timestamp)
sizeof(NTFS_INDEX_Q) / 2 - 1,
(ntfschar *)((char *)attr +
le16_to_cpu(attr->name_offset)),
attr->name_length, 0, NULL, 0)) {
attr->name_length, CASE_SENSITIVE, NULL, 0)) {
QUOTA_CONTROL_ENTRY *quota_q;
@ -936,7 +938,7 @@ static void wipe_timestamps(ntfs_walk_clusters_ctx *image)
{
static const struct timespec zero_time = { .tv_sec = 0, .tv_nsec = 0 };
ATTR_RECORD *a = image->ctx->attr;
s64 timestamp = timespec2ntfs(zero_time);
le64 timestamp = timespec2ntfs(zero_time);
if (a->type == AT_FILE_NAME)
WIPE_TIMESTAMPS(FILE_NAME_ATTR, a, timestamp);
@ -1577,7 +1579,8 @@ static s64 open_image(void)
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;
/* safe image : little endian data */
le32 offset_to_image_data;
int delta;
if (image_hdr.major_ver > NTFSCLONE_IMG_VER_MAJOR)
@ -1590,15 +1593,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);
/* do not translate little endian 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 +
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;
@ -1690,7 +1694,8 @@ static ntfs_attr_search_ctx *lookup_data_attr(ntfs_inode *ni, const char *aname)
goto error_out;
}
if (ntfs_attr_lookup(AT_DATA, ustr, len, 0, 0, NULL, 0, ctx)) {
if (ntfs_attr_lookup(AT_DATA, ustr, len, CASE_SENSITIVE,
0, NULL, 0, ctx)) {
perr_printf("ntfs_attr_lookup");
goto error_out;
}

View File

@ -1123,7 +1123,7 @@ static void ntfs_dump_sds(ATTR_RECORD *attr, ntfs_inode *ni)
name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset));
if (!ntfs_names_are_equal(NTFS_DATA_SDS, sizeof(NTFS_DATA_SDS) / 2 - 1,
name, name_len, 0, NULL, 0))
name, name_len, CASE_SENSITIVE, NULL, 0))
return;
sd = sds = ntfs_attr_readall(ni, AT_DATA, name, name_len, &data_size);
@ -1589,7 +1589,7 @@ static int ntfs_dump_index_entries(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type)
#define COMPARE_INDEX_NAMES(attr, name) \
ntfs_names_are_equal((name), sizeof(name) / 2 - 1, \
(ntfschar*)((char*)(attr) + le16_to_cpu((attr)->name_offset)), \
(attr)->name_length, 0, NULL, 0)
(attr)->name_length, CASE_SENSITIVE, NULL, 0)
static INDEX_ATTR_TYPE get_index_attr_type(ntfs_inode *ni, ATTR_RECORD *attr,
INDEX_ROOT *index_root)
@ -1722,10 +1722,10 @@ static void ntfs_dump_usa_lsn(const char *indent, MFT_RECORD *mrec)
(unsigned)le16_to_cpu(mrec->usa_count),
(unsigned)le16_to_cpu(mrec->usa_count));
printf("%sUpd. Seq. Number:\t %u (0x%x)\n", indent,
(unsigned)le16_to_cpup((u16 *)((u8 *)mrec +
le16_to_cpu(mrec->usa_ofs))),
(unsigned)le16_to_cpup((u16 *)((u8 *)mrec +
le16_to_cpu(mrec->usa_ofs))));
(unsigned)le16_to_cpup((le16*)((u8*)mrec +
le16_to_cpu(mrec->usa_ofs))),
(unsigned)le16_to_cpup((le16*)((u8*)mrec +
le16_to_cpu(mrec->usa_ofs))));
printf("%sLogFile Seq. Number:\t 0x%llx\n", indent,
(unsigned long long)sle64_to_cpu(mrec->lsn));
}
@ -2134,7 +2134,8 @@ static void ntfs_dump_file_attributes(ntfs_inode *inode)
/* then start enumerating attributes
see ntfs_attr_lookup documentation for detailed explanation */
ctx = ntfs_attr_get_search_ctx(inode, NULL);
while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) {
while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, CASE_SENSITIVE,
0, NULL, 0, ctx)) {
if (ctx->attr->type == AT_END || ctx->attr->type == AT_UNUSED) {
printf("Weird: %s attribute type was found, please "
"report this.\n",

View File

@ -2010,7 +2010,8 @@ static void lookup_data_attr(ntfs_volume *vol,
exit(1);
}
if (ntfs_attr_lookup(AT_DATA, ustr, len, 0, 0, NULL, 0, *ctx))
if (ntfs_attr_lookup(AT_DATA, ustr, len, CASE_SENSITIVE,
0, NULL, 0, *ctx))
perr_exit("ntfs_lookup_attr");
ntfs_ucsfree(ustr);

View File

@ -628,8 +628,8 @@ 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 + le16_to_cpu(
attr->name_offset)), namelen, &name, 0) < 0) {
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");
// <UNKNOWN>?
@ -681,7 +681,8 @@ int utils_cluster_in_use(ntfs_volume *vol, long long lcn)
}
/* Does lcn lie in the section of $Bitmap we already have cached? */
if ((lcn < bmplcn) || (lcn >= (bmplcn + (sizeof(buffer) << 3)))) {
if ((lcn < bmplcn)
|| (lcn >= (long long)(bmplcn + (sizeof(buffer) << 3)))) {
ntfs_log_debug("Bit lies outside cache.\n");
attr = ntfs_attr_open(vol->lcnbmp_ni, AT_DATA, AT_UNNAMED, 0);
if (!attr) {
@ -744,8 +745,8 @@ int utils_mftrec_in_use(ntfs_volume *vol, MFT_REF mref)
}
/* Does mref lie in the section of $Bitmap we already have cached? */
if (((s64)MREF(mref) < bmpmref) || ((s64)MREF(mref) >= (bmpmref +
(sizeof(buffer) << 3)))) {
if (((s64)MREF(mref) < bmpmref)
|| ((s64)MREF(mref) >= (s64)(bmpmref + (sizeof(buffer) << 3)))) {
ntfs_log_debug("Bit lies outside cache.\n");
/* Mark the buffer as not in use, in case the read is shorter. */
@ -916,7 +917,7 @@ struct mft_search_ctx * mft_get_search_ctx(ntfs_volume *vol)
return NULL;
}
ctx = calloc(1, sizeof *ctx);
ctx = (struct mft_search_ctx*)calloc(1, sizeof *ctx);
ctx->mft_num = -1;
ctx->vol = vol;
@ -1023,7 +1024,7 @@ int mft_next_record(struct mft_search_ctx *ctx)
ctx->flags_match |= FEMR_NOT_IN_USE;
ctx->inode = calloc(1, sizeof(*ctx->inode));
ctx->inode = (ntfs_inode*)calloc(1, sizeof(*ctx->inode));
if (!ctx->inode) {
ntfs_log_error("Out of memory. Aborting.\n");
return -1;