hfsplus: implement attributes file's header node initialization code
Subsystems (2)
Vyacheslav Dubeyko
maintainerPATCH 2/3 hfsplus: implement attributes file's header node initialization code
From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH 2/3] hfsplus: implement attributes file's header node initialization code
This patch implements functionality of AttributesFile's header node initialization.
--- fs/hfsplus/hfsplus_raw.h | 3 +++ fs/hfsplus/xattr.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
fs/hfsplus/hfsplus_raw.h +3 -0
@@ -187,6 +187,9 @@ struct hfs_btree_header_rec {/* HFS+ BTree misc info */ #define HFSPLUS_TREE_HEAD 0#define HFSPLUS_NODE_MXSZ 32768 +#define HFSPLUS_ATTR_TREE_NODE_SIZE 8192 +#define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3 +#define HFSPLUS_BTREE_HDR_USER_BYTES 128/* Some special File ID numbers (stolen from hfs.h) */ #define HFSPLUS_POR_CNID 1/* Parent Of the Root */
fs/hfsplus/xattr.c +63 -0
69 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Quoted 25 lines · On Fri, 20 Sep 2013 14:04:09 +0400 Vyacheslav Dubeyko <[email protected]> wrote:
From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH 2/3] hfsplus: implement attributes file's header node initialization codeThis patch implements functionality of AttributesFile's header node initialization.
...
fs/hfsplus/hfsplus_raw.h +3
-0@@ -187,6 +187,9 @@ struct hfs_btree_header_rec {/* HFS+ BTree misc info */ #define HFSPLUS_TREE_HEAD 0#define HFSPLUS_NODE_MXSZ 32768 +#define HFSPLUS_ATTR_TREE_NODE_SIZE 8192 +#define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3 +#define HFSPLUS_BTREE_HDR_USER_BYTES 128/* Some special File ID numbers (stolen from hfs.h) */ #define HFSPLUS_POR_CNID 1/* Parent Of the Root */ fs/hfsplus/xattr.c +0
-0
fs/hfsplus/xattr.c static int can_set_xattr(struct inode *inode, const char *name, · line 131
Quoted 5 lines
fs/hfsplus/xattr.c +2
-0@@ -127,6 +127,69 @@ static int can_set_xattr(struct inode *inode, const char *name,return 0 ; } +#define SETOFFSET (buf, ndsiz, offset, rec) \ + (*(u16 *)((u8 *)(buf) + (ndsiz) + (-2 * (rec))) = (cpu_to_be16(offset)))
This is pretty ghastly. Can you take a look at reimplementing it in a C function? Add any necessary comments to explain what's happening and I expect you will find that it produces a much nicer result.
I'd also suggest taking a look at the type of buf' and bmp'. They're never really *used* as char*'s, so why not make them u8* or even void* and avoid some typecasting?
Quoted 14 lines
fs/hfsplus/xattr.c +11
-0+static void hfsplus_init_header_node (struct inode *attr_file, +u32 clump_size, +char *buf,size_t node_size) +{ +struct hfs_bnode_desc *desc; +struct hfs_btree_header_rec *head; +u16 offset; +u32 hdr_node_map_rec_bits; +char *bmp; +u32 temp; +
Al Viro
maintainerQuoted 6 lines · Andrew Morton
fs/hfsplus/xattr.c static int can_set_xattr(struct inode *inode, const char *name, · line 131
Quoted 2 lines
fs/hfsplus/xattr.c +2
-0+#define SETOFFSET (buf, ndsiz, offset, rec) \ + (*(u16 *)((u8 *)(buf) + (ndsiz) + (-2 * (rec))) = (cpu_to_be16(offset)))This is pretty ghastly. Can you take a look at reimplementing it in a C function? Add any necessary comments to explain what's happening and I expect you will find that it produces a much nicer result.
Take a look at the callers - buf and ndsiz remain unchanged, rec runs from 1 to 4. IOW, what should be done is
/* last 8 bytes contain offsets */ __be16 *offsets = (__be16 *)(buf + node_size); ... offset = sizeof(struct hfs_bnode_desc); *--offsets = cpu_to_be16(offset); ... offset += sizeof(struct hfs_btree_header_rec); *--offsets = cpu_to_be16(offset); offset += HFSPLUS_BTREE_HDR_USER_BYTES; *--offsets = cpu_to_be16(offset); ... offset += hdr_node_map_rec_bits / 8; *--offsets = cpu_to_be16(offset);
and to hell with that macro.
Speaking of another thing in the patch, there's that useful function called "memset"...