fix sparse errors. and first steps towards endianness checking

edge.strict_endians
yura 2006-12-12 15:02:25 +00:00
parent a38ead2f20
commit 7b60afcc2f
5 changed files with 31 additions and 45 deletions

View File

@ -45,17 +45,23 @@ typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef u16 le16;
typedef u32 le32;
typedef u64 le64;
#ifdef __CHECKER__
#define __bitwise __attribute__((bitwise))
#else
#define __bitwise
#endif
typedef u16 __bitwise le16;
typedef u32 __bitwise le32;
typedef u64 __bitwise le64;
/*
* Declare sle{16,32,64} to be unsigned because we do not want sign extension
* on BE architectures.
*/
typedef u16 sle16;
typedef u32 sle32;
typedef u64 sle64;
typedef u16 __bitwise sle16;
typedef u32 __bitwise sle32;
typedef u64 __bitwise sle64;
typedef u16 ntfschar; /* 2-byte Unicode character type. */
#define UCHAR_T_SIZE_BITS 1

View File

@ -594,29 +594,10 @@ static const ntfschar dotdot[3] = { const_cpu_to_le16('.'),
const_cpu_to_le16('.'),
const_cpu_to_le16('\0') };
/*
* union index_union - Helper for ntfs_readdir().
*/
typedef union {
INDEX_ROOT *ir;
INDEX_ALLOCATION *ia;
} index_union __attribute__((__transparent_union__));
/**
* enum INDEX_TYPE - Helper for ntfs_readdir().
*/
typedef enum {
INDEX_TYPE_ROOT, /* index root */
INDEX_TYPE_ALLOCATION, /* index allocation */
} INDEX_TYPE;
/**
* ntfs_filldir - ntfs specific filldir method
* @dir_ni: ntfs inode of current directory
* @pos: current position in directory
* @ivcn_bits: log(2) of index vcn size
* @index_type: specifies whether @iu is an index root or an index allocation
* @iu: index root or index block to which @ie belongs
* @ie: current index entry
* @dirent: context for filldir callback supplied by the caller
* @filldir: filldir callback supplied by the caller
@ -624,8 +605,7 @@ typedef enum {
* Pass information specifying the current directory entry @ie to the @filldir
* callback.
*/
static int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits,
const INDEX_TYPE index_type, index_union iu, INDEX_ENTRY *ie,
static int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, INDEX_ENTRY *ie,
void *dirent, ntfs_filldir_t filldir)
{
FILE_NAME_ATTR *fn = &ie->key.file_name;
@ -633,13 +613,6 @@ static int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits,
ntfs_log_trace("Entering.\n");
/* Advance the position even if going to skip the entry. */
if (index_type == INDEX_TYPE_ALLOCATION)
*pos = (u8*)ie - (u8*)iu.ia + (sle64_to_cpu(
iu.ia->index_block_vcn) << ivcn_bits) +
dir_ni->vol->mft_record_size;
else /* if (index_type == INDEX_TYPE_ROOT) */
*pos = (u8*)ie - (u8*)iu.ir;
/* Skip root directory self reference entry. */
if (MREF_LE(ie->indexed_file) == FILE_root)
return 0;
@ -770,9 +743,10 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
ia_na = ntfs_attr_open(dir_ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4);
if (!ia_na) {
if (errno != ENOENT) {
ntfs_log_perror("Failed to open index allocation attribute. "
"Directory inode 0x%llx is corrupt or bug",
(unsigned long long)dir_ni->mft_no);
ntfs_log_perror("Failed to open index allocation "
"attribute. Directory inode 0x%llx is "
"corrupt or bug", (unsigned long long)
dir_ni->mft_no);
return -1;
}
i_size = 0;
@ -877,12 +851,13 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
/* Skip index root entry if continuing previous readdir. */
if (ir_pos > (u8*)ie - (u8*)ir)
continue;
/* Advance the position even if going to skip the entry. */
*pos = (u8*)ie - (u8*)ir;
/*
* Submit the directory entry to ntfs_filldir(), which will
* invoke the filldir() callback as appropriate.
*/
rc = ntfs_filldir(dir_ni, pos, index_vcn_size_bits,
INDEX_TYPE_ROOT, ir, ie, dirent, filldir);
rc = ntfs_filldir(dir_ni, pos, ie, dirent, filldir);
if (rc) {
ntfs_attr_put_search_ctx(ctx);
ctx = NULL;
@ -1035,12 +1010,15 @@ find_next_index_buffer:
/* Skip index entry if continuing previous readdir. */
if (ia_pos - ia_start > (u8*)ie - (u8*)ia)
continue;
/* Advance the position even if going to skip the entry. */
*pos = (u8*)ie - (u8*)ia + (sle64_to_cpu(
ia->index_block_vcn) << index_vcn_size_bits) +
dir_ni->vol->mft_record_size;
/*
* Submit the directory entry to ntfs_filldir(), which will
* invoke the filldir() callback as appropriate.
*/
rc = ntfs_filldir(dir_ni, pos, index_vcn_size_bits,
INDEX_TYPE_ALLOCATION, ia, ie, dirent, filldir);
rc = ntfs_filldir(dir_ni, pos, ie, dirent, filldir);
if (rc)
goto done;
}

View File

@ -302,7 +302,7 @@ ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen)
dst = ntfs_malloc((len + 1) * sizeof(ntfschar));
if (dst) {
memcpy(dst, s, len * sizeof(ntfschar));
dst[len] = cpu_to_le16(L'\0');
dst[len] = 0;
}
return dst;
}
@ -623,7 +623,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs, int outs_len)
}
#endif
/* Now write the NULL character. */
ucs[o] = cpu_to_le16(L'\0');
ucs[o] = 0;
if (*outs != ucs)
*outs = ucs;
return o;

View File

@ -326,7 +326,7 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label,
"allowed. Truncating excess characters.\n",
(unsigned)(0x100 / sizeof(ntfschar)));
label_len = 0x100;
new_label[label_len / sizeof(ntfschar)] = cpu_to_le16(L'\0');
new_label[label_len / sizeof(ntfschar)] = 0;
}
if (a) {
if (resize_resident_attribute_value(ctx->mrec, a, label_len)) {

View File

@ -441,11 +441,12 @@ ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft)
* if parent is 5 (/) stop
* get inode of parent
*/
#define max_path 20
int utils_inode_get_name(ntfs_inode *inode, char *buffer, int bufsize)
{
// XXX option: names = posix/win32 or dos
// flags: path, filename, or both
const int max_path = 20;
ntfs_volume *vol;
ntfs_attr_search_ctx *ctx;
@ -555,6 +556,7 @@ int utils_inode_get_name(ntfs_inode *inode, char *buffer, int bufsize)
return 1;
}
#undef max_path
/**
* utils_attr_get_name