aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@ftp.linux.org.uk>2005-12-24 14:28:55 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-10 19:15:33 -0400
commita9721f3152bc2be6702807705902e06abdd6e3bb (patch)
tree4f01e2f3426697787330371ab822e7e60bc2238e
parente5201c58cd81066ecd0210bcc6c02e71200040a3 (diff)
[PATCH] befs: endianness annotations
split the data structures that exist in host- and disk-endian variants, annotate the fields of disk-endian ones, propagate changes. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--fs/befs/befs.h4
-rw-r--r--fs/befs/befs_fs_types.h107
-rw-r--r--fs/befs/btree.c28
-rw-r--r--fs/befs/datastream.c10
-rw-r--r--fs/befs/debug.c9
-rw-r--r--fs/befs/endian.h20
6 files changed, 106 insertions, 72 deletions
diff --git a/fs/befs/befs.h b/fs/befs/befs.h
index c400bb6a6b71..d9a40abda6b7 100644
--- a/fs/befs/befs.h
+++ b/fs/befs/befs.h
@@ -94,7 +94,7 @@ void befs_debug(const struct super_block *sb, const char *fmt, ...);
94 94
95void befs_dump_super_block(const struct super_block *sb, befs_super_block *); 95void befs_dump_super_block(const struct super_block *sb, befs_super_block *);
96void befs_dump_inode(const struct super_block *sb, befs_inode *); 96void befs_dump_inode(const struct super_block *sb, befs_inode *);
97void befs_dump_index_entry(const struct super_block *sb, befs_btree_super *); 97void befs_dump_index_entry(const struct super_block *sb, befs_disk_btree_super *);
98void befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead *); 98void befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead *);
99/****************************/ 99/****************************/
100 100
@@ -136,7 +136,7 @@ blockno2iaddr(struct super_block *sb, befs_blocknr_t blockno)
136static inline unsigned int 136static inline unsigned int
137befs_iaddrs_per_block(struct super_block *sb) 137befs_iaddrs_per_block(struct super_block *sb)
138{ 138{
139 return BEFS_SB(sb)->block_size / sizeof (befs_inode_addr); 139 return BEFS_SB(sb)->block_size / sizeof (befs_disk_inode_addr);
140} 140}
141 141
142static inline int 142static inline int
diff --git a/fs/befs/befs_fs_types.h b/fs/befs/befs_fs_types.h
index 128066b1c4b0..e2595c2c403a 100644
--- a/fs/befs/befs_fs_types.h
+++ b/fs/befs/befs_fs_types.h
@@ -84,15 +84,22 @@ typedef u32 __bitwise fs32;
84typedef u16 __bitwise fs16; 84typedef u16 __bitwise fs16;
85 85
86typedef u64 befs_off_t; 86typedef u64 befs_off_t;
87typedef u64 befs_time_t; 87typedef fs64 befs_time_t;
88 88
89/* Block runs */ 89/* Block runs */
90typedef struct { 90typedef struct {
91 fs32 allocation_group;
92 fs16 start;
93 fs16 len;
94} PACKED befs_disk_block_run;
95
96typedef struct {
91 u32 allocation_group; 97 u32 allocation_group;
92 u16 start; 98 u16 start;
93 u16 len; 99 u16 len;
94} PACKED befs_block_run; 100} PACKED befs_block_run;
95 101
102typedef befs_disk_block_run befs_disk_inode_addr;
96typedef befs_block_run befs_inode_addr; 103typedef befs_block_run befs_inode_addr;
97 104
98/* 105/*
@@ -100,31 +107,31 @@ typedef befs_block_run befs_inode_addr;
100 */ 107 */
101typedef struct { 108typedef struct {
102 char name[B_OS_NAME_LENGTH]; 109 char name[B_OS_NAME_LENGTH];
103 u32 magic1; 110 fs32 magic1;
104 u32 fs_byte_order; 111 fs32 fs_byte_order;
105 112
106 u32 block_size; 113 fs32 block_size;
107 u32 block_shift; 114 fs32 block_shift;
108 115
109 befs_off_t num_blocks; 116 fs64 num_blocks;
110 befs_off_t used_blocks; 117 fs64 used_blocks;
111 118
112 u32 inode_size; 119 fs32 inode_size;
113 120
114 u32 magic2; 121 fs32 magic2;
115 u32 blocks_per_ag; 122 fs32 blocks_per_ag;
116 u32 ag_shift; 123 fs32 ag_shift;
117 u32 num_ags; 124 fs32 num_ags;
118 125
119 u32 flags; 126 fs32 flags;
120 127
121 befs_block_run log_blocks; 128 befs_disk_block_run log_blocks;
122 befs_off_t log_start; 129 fs64 log_start;
123 befs_off_t log_end; 130 fs64 log_end;
124 131
125 u32 magic3; 132 fs32 magic3;
126 befs_inode_addr root_dir; 133 befs_disk_inode_addr root_dir;
127 befs_inode_addr indices; 134 befs_disk_inode_addr indices;
128 135
129} PACKED befs_super_block; 136} PACKED befs_super_block;
130 137
@@ -133,6 +140,16 @@ typedef struct {
133 * be longer than one block! 140 * be longer than one block!
134 */ 141 */
135typedef struct { 142typedef struct {
143 befs_disk_block_run direct[BEFS_NUM_DIRECT_BLOCKS];
144 fs64 max_direct_range;
145 befs_disk_block_run indirect;
146 fs64 max_indirect_range;
147 befs_disk_block_run double_indirect;
148 fs64 max_double_indirect_range;
149 fs64 size;
150} PACKED befs_disk_data_stream;
151
152typedef struct {
136 befs_block_run direct[BEFS_NUM_DIRECT_BLOCKS]; 153 befs_block_run direct[BEFS_NUM_DIRECT_BLOCKS];
137 befs_off_t max_direct_range; 154 befs_off_t max_direct_range;
138 befs_block_run indirect; 155 befs_block_run indirect;
@@ -144,35 +161,35 @@ typedef struct {
144 161
145/* Attribute */ 162/* Attribute */
146typedef struct { 163typedef struct {
147 u32 type; 164 fs32 type;
148 u16 name_size; 165 fs16 name_size;
149 u16 data_size; 166 fs16 data_size;
150 char name[1]; 167 char name[1];
151} PACKED befs_small_data; 168} PACKED befs_small_data;
152 169
153/* Inode structure */ 170/* Inode structure */
154typedef struct { 171typedef struct {
155 u32 magic1; 172 fs32 magic1;
156 befs_inode_addr inode_num; 173 befs_disk_inode_addr inode_num;
157 u32 uid; 174 fs32 uid;
158 u32 gid; 175 fs32 gid;
159 u32 mode; 176 fs32 mode;
160 u32 flags; 177 fs32 flags;
161 befs_time_t create_time; 178 befs_time_t create_time;
162 befs_time_t last_modified_time; 179 befs_time_t last_modified_time;
163 befs_inode_addr parent; 180 befs_disk_inode_addr parent;
164 befs_inode_addr attributes; 181 befs_disk_inode_addr attributes;
165 u32 type; 182 fs32 type;
166 183
167 u32 inode_size; 184 fs32 inode_size;
168 u32 etc; /* not use */ 185 fs32 etc; /* not use */
169 186
170 union { 187 union {
171 befs_data_stream datastream; 188 befs_disk_data_stream datastream;
172 char symlink[BEFS_SYMLINK_LEN]; 189 char symlink[BEFS_SYMLINK_LEN];
173 } data; 190 } data;
174 191
175 u32 pad[4]; /* not use */ 192 fs32 pad[4]; /* not use */
176 befs_small_data small_data[1]; 193 befs_small_data small_data[1];
177} PACKED befs_inode; 194} PACKED befs_inode;
178 195
@@ -193,6 +210,16 @@ enum btree_types {
193}; 210};
194 211
195typedef struct { 212typedef struct {
213 fs32 magic;
214 fs32 node_size;
215 fs32 max_depth;
216 fs32 data_type;
217 fs64 root_node_ptr;
218 fs64 free_node_ptr;
219 fs64 max_size;
220} PACKED befs_disk_btree_super;
221
222typedef struct {
196 u32 magic; 223 u32 magic;
197 u32 node_size; 224 u32 node_size;
198 u32 max_depth; 225 u32 max_depth;
@@ -206,11 +233,19 @@ typedef struct {
206 * Header stucture of each btree node 233 * Header stucture of each btree node
207 */ 234 */
208typedef struct { 235typedef struct {
236 fs64 left;
237 fs64 right;
238 fs64 overflow;
239 fs16 all_key_count;
240 fs16 all_key_length;
241} PACKED befs_btree_nodehead;
242
243typedef struct {
209 befs_off_t left; 244 befs_off_t left;
210 befs_off_t right; 245 befs_off_t right;
211 befs_off_t overflow; 246 befs_off_t overflow;
212 u16 all_key_count; 247 u16 all_key_count;
213 u16 all_key_length; 248 u16 all_key_length;
214} PACKED befs_btree_nodehead; 249} PACKED befs_host_btree_nodehead;
215 250
216#endif /* _LINUX_BEFS_FS_TYPES */ 251#endif /* _LINUX_BEFS_FS_TYPES */
diff --git a/fs/befs/btree.c b/fs/befs/btree.c
index 12e0fd60033e..81b042ee24e6 100644
--- a/fs/befs/btree.c
+++ b/fs/befs/btree.c
@@ -79,7 +79,7 @@
79 * In memory structure of each btree node 79 * In memory structure of each btree node
80 */ 80 */
81typedef struct { 81typedef struct {
82 befs_btree_nodehead head; /* head of node converted to cpu byteorder */ 82 befs_host_btree_nodehead head; /* head of node converted to cpu byteorder */
83 struct buffer_head *bh; 83 struct buffer_head *bh;
84 befs_btree_nodehead *od_node; /* on disk node */ 84 befs_btree_nodehead *od_node; /* on disk node */
85} befs_btree_node; 85} befs_btree_node;
@@ -101,9 +101,9 @@ static int befs_bt_read_node(struct super_block *sb, befs_data_stream * ds,
101 101
102static int befs_leafnode(befs_btree_node * node); 102static int befs_leafnode(befs_btree_node * node);
103 103
104static u16 *befs_bt_keylen_index(befs_btree_node * node); 104static fs16 *befs_bt_keylen_index(befs_btree_node * node);
105 105
106static befs_off_t *befs_bt_valarray(befs_btree_node * node); 106static fs64 *befs_bt_valarray(befs_btree_node * node);
107 107
108static char *befs_bt_keydata(befs_btree_node * node); 108static char *befs_bt_keydata(befs_btree_node * node);
109 109
@@ -135,7 +135,7 @@ befs_bt_read_super(struct super_block *sb, befs_data_stream * ds,
135 befs_btree_super * sup) 135 befs_btree_super * sup)
136{ 136{
137 struct buffer_head *bh = NULL; 137 struct buffer_head *bh = NULL;
138 befs_btree_super *od_sup = NULL; 138 befs_disk_btree_super *od_sup = NULL;
139 139
140 befs_debug(sb, "---> befs_btree_read_super()"); 140 befs_debug(sb, "---> befs_btree_read_super()");
141 141
@@ -145,7 +145,7 @@ befs_bt_read_super(struct super_block *sb, befs_data_stream * ds,
145 befs_error(sb, "Couldn't read index header."); 145 befs_error(sb, "Couldn't read index header.");
146 goto error; 146 goto error;
147 } 147 }
148 od_sup = (befs_btree_super *) bh->b_data; 148 od_sup = (befs_disk_btree_super *) bh->b_data;
149 befs_dump_index_entry(sb, od_sup); 149 befs_dump_index_entry(sb, od_sup);
150 150
151 sup->magic = fs32_to_cpu(sb, od_sup->magic); 151 sup->magic = fs32_to_cpu(sb, od_sup->magic);
@@ -341,7 +341,7 @@ befs_find_key(struct super_block *sb, befs_btree_node * node,
341 u16 keylen; 341 u16 keylen;
342 int findkey_len; 342 int findkey_len;
343 char *thiskey; 343 char *thiskey;
344 befs_off_t *valarray; 344 fs64 *valarray;
345 345
346 befs_debug(sb, "---> befs_find_key() %s", findkey); 346 befs_debug(sb, "---> befs_find_key() %s", findkey);
347 347
@@ -421,7 +421,7 @@ befs_btree_read(struct super_block *sb, befs_data_stream * ds,
421 befs_btree_super bt_super; 421 befs_btree_super bt_super;
422 befs_off_t node_off = 0; 422 befs_off_t node_off = 0;
423 int cur_key; 423 int cur_key;
424 befs_off_t *valarray; 424 fs64 *valarray;
425 char *keystart; 425 char *keystart;
426 u16 keylen; 426 u16 keylen;
427 int res; 427 int res;
@@ -571,7 +571,7 @@ befs_btree_seekleaf(struct super_block *sb, befs_data_stream * ds,
571 this_node->head.overflow); 571 this_node->head.overflow);
572 *node_off = this_node->head.overflow; 572 *node_off = this_node->head.overflow;
573 } else { 573 } else {
574 befs_off_t *valarray = befs_bt_valarray(this_node); 574 fs64 *valarray = befs_bt_valarray(this_node);
575 *node_off = fs64_to_cpu(sb, valarray[0]); 575 *node_off = fs64_to_cpu(sb, valarray[0]);
576 } 576 }
577 if (befs_bt_read_node(sb, ds, this_node, *node_off) != BEFS_OK) { 577 if (befs_bt_read_node(sb, ds, this_node, *node_off) != BEFS_OK) {
@@ -621,7 +621,7 @@ befs_leafnode(befs_btree_node * node)
621 * 621 *
622 * Except that rounding up to 8 works, and rounding up to 4 doesn't. 622 * Except that rounding up to 8 works, and rounding up to 4 doesn't.
623 */ 623 */
624static u16 * 624static fs16 *
625befs_bt_keylen_index(befs_btree_node * node) 625befs_bt_keylen_index(befs_btree_node * node)
626{ 626{
627 const int keylen_align = 8; 627 const int keylen_align = 8;
@@ -632,7 +632,7 @@ befs_bt_keylen_index(befs_btree_node * node)
632 if (tmp) 632 if (tmp)
633 off += keylen_align - tmp; 633 off += keylen_align - tmp;
634 634
635 return (u16 *) ((void *) node->od_node + off); 635 return (fs16 *) ((void *) node->od_node + off);
636} 636}
637 637
638/** 638/**
@@ -642,13 +642,13 @@ befs_bt_keylen_index(befs_btree_node * node)
642 * Returns a pointer to the start of the value array 642 * Returns a pointer to the start of the value array
643 * of the node pointed to by the node header 643 * of the node pointed to by the node header
644 */ 644 */
645static befs_off_t * 645static fs64 *
646befs_bt_valarray(befs_btree_node * node) 646befs_bt_valarray(befs_btree_node * node)
647{ 647{
648 void *keylen_index_start = (void *) befs_bt_keylen_index(node); 648 void *keylen_index_start = (void *) befs_bt_keylen_index(node);
649 size_t keylen_index_size = node->head.all_key_count * sizeof (u16); 649 size_t keylen_index_size = node->head.all_key_count * sizeof (fs16);
650 650
651 return (befs_off_t *) (keylen_index_start + keylen_index_size); 651 return (fs64 *) (keylen_index_start + keylen_index_size);
652} 652}
653 653
654/** 654/**
@@ -680,7 +680,7 @@ befs_bt_get_key(struct super_block *sb, befs_btree_node * node,
680{ 680{
681 int prev_key_end; 681 int prev_key_end;
682 char *keystart; 682 char *keystart;
683 u16 *keylen_index; 683 fs16 *keylen_index;
684 684
685 if (index < 0 || index > node->head.all_key_count) { 685 if (index < 0 || index > node->head.all_key_count) {
686 *keylen = 0; 686 *keylen = 0;
diff --git a/fs/befs/datastream.c b/fs/befs/datastream.c
index 67335e2853f6..aacb4da6298a 100644
--- a/fs/befs/datastream.c
+++ b/fs/befs/datastream.c
@@ -311,7 +311,7 @@ befs_find_brun_indirect(struct super_block *sb,
311 befs_blocknr_t indir_start_blk; 311 befs_blocknr_t indir_start_blk;
312 befs_blocknr_t search_blk; 312 befs_blocknr_t search_blk;
313 struct buffer_head *indirblock; 313 struct buffer_head *indirblock;
314 befs_block_run *array; 314 befs_disk_block_run *array;
315 315
316 befs_block_run indirect = data->indirect; 316 befs_block_run indirect = data->indirect;
317 befs_blocknr_t indirblockno = iaddr2blockno(sb, &indirect); 317 befs_blocknr_t indirblockno = iaddr2blockno(sb, &indirect);
@@ -333,7 +333,7 @@ befs_find_brun_indirect(struct super_block *sb,
333 return BEFS_ERR; 333 return BEFS_ERR;
334 } 334 }
335 335
336 array = (befs_block_run *) indirblock->b_data; 336 array = (befs_disk_block_run *) indirblock->b_data;
337 337
338 for (j = 0; j < arraylen; ++j) { 338 for (j = 0; j < arraylen; ++j) {
339 int len = fs16_to_cpu(sb, array[j].len); 339 int len = fs16_to_cpu(sb, array[j].len);
@@ -426,7 +426,7 @@ befs_find_brun_dblindirect(struct super_block *sb,
426 struct buffer_head *dbl_indir_block; 426 struct buffer_head *dbl_indir_block;
427 struct buffer_head *indir_block; 427 struct buffer_head *indir_block;
428 befs_block_run indir_run; 428 befs_block_run indir_run;
429 befs_inode_addr *iaddr_array = NULL; 429 befs_disk_inode_addr *iaddr_array = NULL;
430 befs_sb_info *befs_sb = BEFS_SB(sb); 430 befs_sb_info *befs_sb = BEFS_SB(sb);
431 431
432 befs_blocknr_t indir_start_blk = 432 befs_blocknr_t indir_start_blk =
@@ -481,7 +481,7 @@ befs_find_brun_dblindirect(struct super_block *sb,
481 481
482 dbl_block_indx = 482 dbl_block_indx =
483 dblindir_indx - (dbl_which_block * befs_iaddrs_per_block(sb)); 483 dblindir_indx - (dbl_which_block * befs_iaddrs_per_block(sb));
484 iaddr_array = (befs_inode_addr *) dbl_indir_block->b_data; 484 iaddr_array = (befs_disk_inode_addr *) dbl_indir_block->b_data;
485 indir_run = fsrun_to_cpu(sb, iaddr_array[dbl_block_indx]); 485 indir_run = fsrun_to_cpu(sb, iaddr_array[dbl_block_indx]);
486 brelse(dbl_indir_block); 486 brelse(dbl_indir_block);
487 iaddr_array = NULL; 487 iaddr_array = NULL;
@@ -506,7 +506,7 @@ befs_find_brun_dblindirect(struct super_block *sb,
506 } 506 }
507 507
508 block_indx = indir_indx - (which_block * befs_iaddrs_per_block(sb)); 508 block_indx = indir_indx - (which_block * befs_iaddrs_per_block(sb));
509 iaddr_array = (befs_inode_addr *) indir_block->b_data; 509 iaddr_array = (befs_disk_inode_addr *) indir_block->b_data;
510 *run = fsrun_to_cpu(sb, iaddr_array[block_indx]); 510 *run = fsrun_to_cpu(sb, iaddr_array[block_indx]);
511 brelse(indir_block); 511 brelse(indir_block);
512 iaddr_array = NULL; 512 iaddr_array = NULL;
diff --git a/fs/befs/debug.c b/fs/befs/debug.c
index bb68370f6494..e831a8f30849 100644
--- a/fs/befs/debug.c
+++ b/fs/befs/debug.c
@@ -230,21 +230,20 @@ befs_dump_small_data(const struct super_block *sb, befs_small_data * sd)
230 230
231/* unused */ 231/* unused */
232void 232void
233befs_dump_run(const struct super_block *sb, befs_block_run run) 233befs_dump_run(const struct super_block *sb, befs_disk_block_run run)
234{ 234{
235#ifdef CONFIG_BEFS_DEBUG 235#ifdef CONFIG_BEFS_DEBUG
236 236
237 run = fsrun_to_cpu(sb, run); 237 befs_block_run n = fsrun_to_cpu(sb, run);
238 238
239 befs_debug(sb, "[%u, %hu, %hu]", 239 befs_debug(sb, "[%u, %hu, %hu]", n.allocation_group, n.start, n.len);
240 run.allocation_group, run.start, run.len);
241 240
242#endif //CONFIG_BEFS_DEBUG 241#endif //CONFIG_BEFS_DEBUG
243} 242}
244#endif /* 0 */ 243#endif /* 0 */
245 244
246void 245void
247befs_dump_index_entry(const struct super_block *sb, befs_btree_super * super) 246befs_dump_index_entry(const struct super_block *sb, befs_disk_btree_super * super)
248{ 247{
249#ifdef CONFIG_BEFS_DEBUG 248#ifdef CONFIG_BEFS_DEBUG
250 249
diff --git a/fs/befs/endian.h b/fs/befs/endian.h
index 979c543e6c58..e254a20869f4 100644
--- a/fs/befs/endian.h
+++ b/fs/befs/endian.h
@@ -68,26 +68,26 @@ cpu_to_fs16(const struct super_block *sb, u16 n)
68/* Composite types below here */ 68/* Composite types below here */
69 69
70static inline befs_block_run 70static inline befs_block_run
71fsrun_to_cpu(const struct super_block *sb, befs_block_run n) 71fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n)
72{ 72{
73 befs_block_run run; 73 befs_block_run run;
74 74
75 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) { 75 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
76 run.allocation_group = le32_to_cpu(n.allocation_group); 76 run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group);
77 run.start = le16_to_cpu(n.start); 77 run.start = le16_to_cpu((__force __le16)n.start);
78 run.len = le16_to_cpu(n.len); 78 run.len = le16_to_cpu((__force __le16)n.len);
79 } else { 79 } else {
80 run.allocation_group = be32_to_cpu(n.allocation_group); 80 run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group);
81 run.start = be16_to_cpu(n.start); 81 run.start = be16_to_cpu((__force __be16)n.start);
82 run.len = be16_to_cpu(n.len); 82 run.len = be16_to_cpu((__force __be16)n.len);
83 } 83 }
84 return run; 84 return run;
85} 85}
86 86
87static inline befs_block_run 87static inline befs_disk_block_run
88cpu_to_fsrun(const struct super_block *sb, befs_block_run n) 88cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
89{ 89{
90 befs_block_run run; 90 befs_disk_block_run run;
91 91
92 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) { 92 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
93 run.allocation_group = cpu_to_le32(n.allocation_group); 93 run.allocation_group = cpu_to_le32(n.allocation_group);
@@ -102,7 +102,7 @@ cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
102} 102}
103 103
104static inline befs_data_stream 104static inline befs_data_stream
105fsds_to_cpu(const struct super_block *sb, befs_data_stream n) 105fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n)
106{ 106{
107 befs_data_stream data; 107 befs_data_stream data;
108 int i; 108 int i;