Commit 306a3b89 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] hfsplus endianness annotations

Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent df5acb11
......@@ -85,7 +85,8 @@ int hfs_brec_find(struct hfs_find_data *fd)
{
struct hfs_btree *tree;
struct hfs_bnode *bnode;
u32 data, nidx, parent;
u32 nidx, parent;
__be32 data;
int height, res;
tree = fd->tree;
......
......@@ -19,8 +19,9 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
{
struct page *page;
struct address_space *mapping;
u32 *pptr, *curr, *end;
u32 val, mask, start, len;
__be32 *pptr, *curr, *end;
u32 mask, start, len, n;
__be32 val;
int i;
len = *max;
......@@ -44,10 +45,10 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
/* scan the first partial u32 for zero bits */
val = *curr;
if (~val) {
val = be32_to_cpu(val);
n = be32_to_cpu(val);
mask = (1U << 31) >> i;
for (; i < 32; mask >>= 1, i++) {
if (!(val & mask))
if (!(n & mask))
goto found;
}
}
......@@ -58,10 +59,10 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
while (curr < end) {
val = *curr;
if (~val) {
val = be32_to_cpu(val);
n = be32_to_cpu(val);
mask = 1 << 31;
for (i = 0; i < 32; mask >>= 1, i++) {
if (!(val & mask))
if (!(n & mask))
goto found;
}
}
......@@ -92,27 +93,27 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
/* do any partial u32 at the start */
len = min(size - start, len);
while (1) {
val |= mask;
n |= mask;
if (++i >= 32)
break;
mask >>= 1;
if (!--len || val & mask)
if (!--len || n & mask)
goto done;
}
if (!--len)
goto done;
*curr++ = cpu_to_be32(val);
*curr++ = cpu_to_be32(n);
/* do full u32s */
while (1) {
while (curr < end) {
val = be32_to_cpu(*curr);
n = be32_to_cpu(*curr);
if (len < 32)
goto last;
if (val) {
if (n) {
len = 32;
goto last;
}
*curr++ = 0xffffffffU;
*curr++ = cpu_to_be32(0xffffffff);
len -= 32;
}
set_page_dirty(page);
......@@ -128,13 +129,13 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
/* do any partial u32 at end */
mask = 1U << 31;
for (i = 0; i < len; i++) {
if (val & mask)
if (n & mask)
break;
val |= mask;
n |= mask;
mask >>= 1;
}
done:
*curr = cpu_to_be32(val);
*curr = cpu_to_be32(n);
set_page_dirty(page);
kunmap(page);
*max = offset + (curr - pptr) * 32 + i - start;
......@@ -150,7 +151,7 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
{
struct page *page;
struct address_space *mapping;
u32 *pptr, *curr, *end;
__be32 *pptr, *curr, *end;
u32 mask, len, pnr;
int i;
......
......@@ -44,7 +44,7 @@ void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len)
u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off)
{
u16 data;
__be16 data;
// optimize later...
hfs_bnode_read(node, &data, off, 2);
return be16_to_cpu(data);
......@@ -98,9 +98,9 @@ void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len)
void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data)
{
data = cpu_to_be16(data);
__be16 v = cpu_to_be16(data);
// optimize later...
hfs_bnode_write(node, &data, off, 2);
hfs_bnode_write(node, &v, off, 2);
}
void hfs_bnode_clear(struct hfs_bnode *node, int off, int len)
......@@ -297,7 +297,7 @@ void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len)
void hfs_bnode_dump(struct hfs_bnode *node)
{
struct hfs_bnode_desc desc;
u32 cnid;
__be32 cnid;
int i, off, key_off;
dprint(DBG_BNODE_MOD, "bnode: %d\n", node->this);
......@@ -334,7 +334,7 @@ void hfs_bnode_unlink(struct hfs_bnode *node)
{
struct hfs_btree *tree;
struct hfs_bnode *tmp;
u32 cnid;
__be32 cnid;
tree = node->tree;
if (node->prev) {
......
......@@ -14,7 +14,7 @@
/* Get the length and offset of the given record in the given node */
u16 hfs_brec_lenoff(struct hfs_bnode *node, u16 rec, u16 *off)
{
u16 retval[2];
__be16 retval[2];
u16 dataoff;
dataoff = node->tree->node_size - (rec + 2) * 2;
......@@ -53,7 +53,7 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len)
int size, key_len, rec;
int data_off, end_off;
int idx_rec_off, data_rec_off, end_rec_off;
u32 cnid;
__be32 cnid;
tree = fd->tree;
if (!fd->bnode) {
......@@ -387,7 +387,7 @@ int hfs_brec_update_parent(struct hfs_find_data *fd)
node = parent;
if (new_node) {
u32 cnid;
__be32 cnid;
fd->bnode = hfs_bnode_find(tree, new_node->parent);
/* create index key and entry */
......@@ -419,7 +419,7 @@ int hfs_btree_inc_height(struct hfs_btree *tree)
struct hfs_bnode *node, *new_node;
struct hfs_bnode_desc node_desc;
int key_size, rec;
u32 cnid;
__be32 cnid;
node = NULL;
if (tree->root) {
......
......@@ -142,7 +142,7 @@ static struct hfs_bnode *hfs_bmap_new_bmap(struct hfs_bnode *prev, u32 idx)
struct hfs_btree *tree = prev->tree;
struct hfs_bnode *node;
struct hfs_bnode_desc desc;
u32 cnid;
__be32 cnid;
node = hfs_bnode_create(tree, idx);
if (IS_ERR(node))
......
......@@ -15,7 +15,7 @@
int hfsplus_cat_cmp_key(hfsplus_btree_key *k1, hfsplus_btree_key *k2)
{
u32 k1p, k2p;
__be32 k1p, k2p;
k1p = k1->cat.parent;
k2p = k2->cat.parent;
......@@ -34,8 +34,10 @@ void hfsplus_cat_build_key(hfsplus_btree_key *key, u32 parent,
if (str) {
hfsplus_asc2uni(&key->cat.name, str->name, str->len);
len = be16_to_cpu(key->cat.name.length);
} else
len = key->cat.name.length = 0;
} else {
key->cat.name.length = 0;
len = 0;
}
key->key_len = cpu_to_be16(6 + 2 * len);
}
......
......@@ -19,8 +19,8 @@
/* Compare two extents keys, returns 0 on same, pos/neg for difference */
int hfsplus_ext_cmp_key(hfsplus_btree_key *k1, hfsplus_btree_key *k2)
{
u32 k1id, k2id;
u32 k1s, k2s;
__be32 k1id, k2id;
__be32 k1s, k2s;
k1id = k1->ext.cnid;
k2id = k2->ext.cnid;
......
......@@ -45,12 +45,12 @@
/* Structures used on disk */
typedef u32 hfsplus_cnid;
typedef u16 hfsplus_unichr;
typedef __be32 hfsplus_cnid;
typedef __be16 hfsplus_unichr;
/* A "string" as used in filenames, etc. */
struct hfsplus_unistr {
u16 length;
__be16 length;
hfsplus_unichr unicode[255];
} __packed;
......@@ -58,12 +58,12 @@ struct hfsplus_unistr {
/* POSIX permissions */
struct hfsplus_perm {
u32 owner;
u32 group;
__be32 owner;
__be32 group;
u8 rootflags;
u8 userflags;
u16 mode;
u32 dev;
__be16 mode;
__be32 dev;
} __packed;
#define HFSPLUS_FLG_NODUMP 0x01
......@@ -72,46 +72,46 @@ struct hfsplus_perm {
/* A single contiguous area of a file */
struct hfsplus_extent {
u32 start_block;
u32 block_count;
__be32 start_block;
__be32 block_count;
} __packed;
typedef struct hfsplus_extent hfsplus_extent_rec[8];
/* Information for a "Fork" in a file */
struct hfsplus_fork_raw {
u64 total_size;
u32 clump_size;
u32 total_blocks;
__be64 total_size;
__be32 clump_size;
__be32 total_blocks;
hfsplus_extent_rec extents;
} __packed;
/* HFS+ Volume Header */
struct hfsplus_vh {
u16 signature;
u16 version;
u32 attributes;
u32 last_mount_vers;
__be16 signature;
__be16 version;
__be32 attributes;
__be32 last_mount_vers;
u32 reserved;
u32 create_date;
u32 modify_date;
u32 backup_date;
u32 checked_date;
__be32 create_date;
__be32 modify_date;
__be32 backup_date;
__be32 checked_date;
u32 file_count;
u32 folder_count;
__be32 file_count;
__be32 folder_count;
u32 blocksize;
u32 total_blocks;
u32 free_blocks;
__be32 blocksize;
__be32 total_blocks;
__be32 free_blocks;
u32 next_alloc;
u32 rsrc_clump_sz;
u32 data_clump_sz;
__be32 next_alloc;
__be32 rsrc_clump_sz;
__be32 data_clump_sz;
hfsplus_cnid next_cnid;
u32 write_count;
u64 encodings_bmp;
__be32 write_count;
__be64 encodings_bmp;
u8 finder_info[32];
......@@ -131,11 +131,11 @@ struct hfsplus_vh {
/* HFS+ BTree node descriptor */
struct hfs_bnode_desc {
u32 next;
u32 prev;
__be32 next;
__be32 prev;
s8 type;
u8 height;
u16 num_recs;
__be16 num_recs;
u16 reserved;
} __packed;
......@@ -147,20 +147,20 @@ struct hfs_bnode_desc {
/* HFS+ BTree header */
struct hfs_btree_header_rec {
u16 depth;
u32 root;
u32 leaf_count;
u32 leaf_head;
u32 leaf_tail;
u16 node_size;
u16 max_key_len;
u32 node_count;
u32 free_nodes;
__be16 depth;
__be32 root;
__be32 leaf_count;
__be32 leaf_head;
__be32 leaf_tail;
__be16 node_size;
__be16 max_key_len;
__be32 node_count;
__be32 free_nodes;
u16 reserved1;
u32 clump_size;
__be32 clump_size;
u8 btree_type;
u8 reserved2;
u32 attributes;
__be32 attributes;
u32 reserved3[16];
} __packed;
......@@ -186,7 +186,7 @@ struct hfs_btree_header_rec {
/* HFS+ catalog entry key */
struct hfsplus_cat_key {
u16 key_len;
__be16 key_len;
hfsplus_cnid parent;
struct hfsplus_unistr name;
} __packed;
......@@ -194,83 +194,83 @@ struct hfsplus_cat_key {
/* Structs from hfs.h */
struct hfsp_point {
u16 v;
u16 h;
__be16 v;
__be16 h;
} __packed;
struct hfsp_rect {
u16 top;
u16 left;
u16 bottom;
u16 right;
__be16 top;
__be16 left;
__be16 bottom;
__be16 right;
} __packed;
/* HFS directory info (stolen from hfs.h */
struct DInfo {
struct hfsp_rect frRect;
u16 frFlags;
__be16 frFlags;
struct hfsp_point frLocation;
u16 frView;
__be16 frView;
} __packed;
struct DXInfo {
struct hfsp_point frScroll;
u32 frOpenChain;
u16 frUnused;
u16 frComment;
u32 frPutAway;
__be32 frOpenChain;
__be16 frUnused;
__be16 frComment;
__be32 frPutAway;
} __packed;
/* HFS+ folder data (part of an hfsplus_cat_entry) */
struct hfsplus_cat_folder {
s16 type;
u16 flags;
u32 valence;
__be16 type;
__be16 flags;
__be32 valence;
hfsplus_cnid id;
u32 create_date;
u32 content_mod_date;
u32 attribute_mod_date;
u32 access_date;
u32 backup_date;
__be32 create_date;
__be32 content_mod_date;
__be32 attribute_mod_date;
__be32 access_date;
__be32 backup_date;
struct hfsplus_perm permissions;
struct DInfo user_info;
struct DXInfo finder_info;
u32 text_encoding;
__be32 text_encoding;
u32 reserved;
} __packed;
/* HFS file info (stolen from hfs.h) */
struct FInfo {
u32 fdType;
u32 fdCreator;
u16 fdFlags;
__be32 fdType;
__be32 fdCreator;
__be16 fdFlags;
struct hfsp_point fdLocation;
u16 fdFldr;
__be16 fdFldr;
} __packed;
struct FXInfo {
u16 fdIconID;
__be16 fdIconID;
u8 fdUnused[8];
u16 fdComment;
u32 fdPutAway;
__be16 fdComment;
__be32 fdPutAway;
} __packed;
/* HFS+ file data (part of a cat_entry) */
struct hfsplus_cat_file {
s16 type;
u16 flags;
__be16 type;
__be16 flags;
u32 reserved1;
hfsplus_cnid id;
u32 create_date;
u32 content_mod_date;
u32 attribute_mod_date;
u32 access_date;
u32 backup_date;
__be32 create_date;
__be32 content_mod_date;
__be32 attribute_mod_date;
__be32 access_date;
__be32 backup_date;
struct hfsplus_perm permissions;
struct FInfo user_info;
struct FXInfo finder_info;
u32 text_encoding;
__be32 text_encoding;
u32 reserved2;
struct hfsplus_fork_raw data_fork;
......@@ -283,7 +283,7 @@ struct hfsplus_cat_file {
/* HFS+ catalog thread (part of a cat_entry) */
struct hfsplus_cat_thread {
s16 type;
__be16 type;
s16 reserved;
hfsplus_cnid parentID;
struct hfsplus_unistr nodeName;
......@@ -293,7 +293,7 @@ struct hfsplus_cat_thread {
/* A data record in the catalog tree */
typedef union {
s16 type;
__be16 type;
struct hfsplus_cat_folder folder;
struct hfsplus_cat_file file;
struct hfsplus_cat_thread thread;
......@@ -307,18 +307,18 @@ typedef union {
/* HFS+ extents tree key */
struct hfsplus_ext_key {
u16 key_len;
__be16 key_len;
u8 fork_type;
u8 pad;
hfsplus_cnid cnid;
u32 start_block;
__be32 start_block;
} __packed;
#define HFSPLUS_EXT_KEYLEN 12
/* HFS+ generic BTree key */
typedef union {
u16 key_len;
__be16 key_len;
struct hfsplus_cat_key cat;
struct hfsplus_ext_key ext;
} __packed hfsplus_btree_key;
......
......@@ -35,11 +35,11 @@
* contiguous starting at block 1.
*/
struct new_pmap {
u16 pmSig; /* signature */
u16 reSigPad; /* padding */
u32 pmMapBlkCnt; /* partition blocks count */
u32 pmPyPartStart; /* physical block start of partition */
u32 pmPartBlkCnt; /* physical block count of partition */
__be16 pmSig; /* signature */
__be16 reSigPad; /* padding */
__be32 pmMapBlkCnt; /* partition blocks count */
__be32 pmPyPartStart; /* physical block start of partition */
__be32 pmPartBlkCnt; /* physical block count of partition */
u8 pmPartName[32]; /* (null terminated?) string
giving the name of this
partition */
......@@ -57,11 +57,11 @@ struct new_pmap {
* one of these.
*/
struct old_pmap {
u16 pdSig; /* Signature bytes */
__be16 pdSig; /* Signature bytes */
struct old_pmap_entry {
u32 pdStart;
u32 pdSize;
u32 pdFSID;
__be32 pdStart;
__be32 pdSize;
__be32 pdFSID;
} pdEntry[42];
} __packed;
......@@ -75,7 +75,7 @@ int hfs_part_find(struct super_block *sb,
sector_t *part_start, sector_t *part_size)
{
struct buffer_head *bh;
u16 *data;
__be16 *data;
int i, size, res;
res = -ENOENT;
......
......@@ -30,22 +30,22 @@ static int hfsplus_read_mdb(void *bufptr, struct hfsplus_wd *wd)
u32 extent;
u16 attrib;
if (be16_to_cpu(*(u16 *)(bufptr + HFSP_WRAPOFF_EMBEDSIG)) != HFSPLUS_VOLHEAD_SIG)
if (be16_to_cpu(*(__be16 *)(bufptr + HFSP_WRAPOFF_EMBEDSIG)) != HFSPLUS_VOLHEAD_SIG)
return 0;
attrib = be16_to_cpu(*(u16 *)(bufptr + HFSP_WRAPOFF_ATTRIB));
attrib = be16_to_cpu(*(__be16 *)(bufptr + HFSP_WRAPOFF_ATTRIB));
if (!(attrib & HFSP_WRAP_ATTRIB_SLOCK) ||
!(attrib & HFSP_WRAP_ATTRIB_SPARED))
return 0;
wd->ablk_size = be32_to_cpu(*(u32 *)(bufptr + HFSP_WRAPOFF_ABLKSIZE));
wd->ablk_size = be32_to_cpu(*(__be32 *)(bufptr + HFSP_WRAPOFF_ABLKSIZE));
if (wd->ablk_size < HFSPLUS_SECTOR_SIZE)
return 0;
if (wd->ablk_size % HFSPLUS_SECTOR_SIZE)
return 0;
wd->ablk_start = be16_to_cpu(*(u16 *)(bufptr + HFSP_WRAPOFF_ABLKSTART));
wd->ablk_start = be16_to_cpu(*(__be16 *)(bufptr + HFSP_WRAPOFF_ABLKSTART));
extent = be32_to_cpu(get_unaligned((u32 *)(bufptr + HFSP_WRAPOFF_EMBEDEXT)));
extent = be32_to_cpu(get_unaligned((__be32 *)(bufptr + HFSP_WRAPOFF_EMBEDEXT)));
wd->embed_start = (extent >> 16) & 0xFFFF;
wd->embed_count = extent & 0xFFFF;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment