Commit a9721f3152bc2be6702807705902e06abdd6e3bb

Authored by Al Viro
Committed by Linus Torvalds
1 parent e5201c58cd

[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>

Showing 6 changed files with 106 additions and 72 deletions Side-by-side Diff

... ... @@ -94,7 +94,7 @@
94 94  
95 95 void befs_dump_super_block(const struct super_block *sb, befs_super_block *);
96 96 void befs_dump_inode(const struct super_block *sb, befs_inode *);
97   -void befs_dump_index_entry(const struct super_block *sb, befs_btree_super *);
  97 +void befs_dump_index_entry(const struct super_block *sb, befs_disk_btree_super *);
98 98 void befs_dump_index_node(const struct super_block *sb, befs_btree_nodehead *);
99 99 /****************************/
100 100  
... ... @@ -136,7 +136,7 @@
136 136 static inline unsigned int
137 137 befs_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  
142 142 static inline int
fs/befs/befs_fs_types.h
... ... @@ -84,15 +84,22 @@
84 84 typedef u16 __bitwise fs16;
85 85  
86 86 typedef u64 befs_off_t;
87   -typedef u64 befs_time_t;
  87 +typedef fs64 befs_time_t;
88 88  
89 89 /* Block runs */
90 90 typedef struct {
  91 + fs32 allocation_group;
  92 + fs16 start;
  93 + fs16 len;
  94 +} PACKED befs_disk_block_run;
  95 +
  96 +typedef struct {
91 97 u32 allocation_group;
92 98 u16 start;
93 99 u16 len;
94 100 } PACKED befs_block_run;
95 101  
  102 +typedef befs_disk_block_run befs_disk_inode_addr;
96 103 typedef befs_block_run befs_inode_addr;
97 104  
98 105 /*
99 106  
100 107  
101 108  
102 109  
103 110  
104 111  
105 112  
... ... @@ -100,31 +107,31 @@
100 107 */
101 108 typedef struct {
102 109 char name[B_OS_NAME_LENGTH];
103   - u32 magic1;
104   - u32 fs_byte_order;
  110 + fs32 magic1;
  111 + fs32 fs_byte_order;
105 112  
106   - u32 block_size;
107   - u32 block_shift;
  113 + fs32 block_size;
  114 + fs32 block_shift;
108 115  
109   - befs_off_t num_blocks;
110   - befs_off_t used_blocks;
  116 + fs64 num_blocks;
  117 + fs64 used_blocks;
111 118  
112   - u32 inode_size;
  119 + fs32 inode_size;
113 120  
114   - u32 magic2;
115   - u32 blocks_per_ag;
116   - u32 ag_shift;
117   - u32 num_ags;
  121 + fs32 magic2;
  122 + fs32 blocks_per_ag;
  123 + fs32 ag_shift;
  124 + fs32 num_ags;
118 125  
119   - u32 flags;
  126 + fs32 flags;
120 127  
121   - befs_block_run log_blocks;
122   - befs_off_t log_start;
123   - befs_off_t log_end;
  128 + befs_disk_block_run log_blocks;
  129 + fs64 log_start;
  130 + fs64 log_end;
124 131  
125   - u32 magic3;
126   - befs_inode_addr root_dir;
127   - befs_inode_addr indices;
  132 + fs32 magic3;
  133 + befs_disk_inode_addr root_dir;
  134 + befs_disk_inode_addr indices;
128 135  
129 136 } PACKED befs_super_block;
130 137  
... ... @@ -133,6 +140,16 @@
133 140 * be longer than one block!
134 141 */
135 142 typedef 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 +
  152 +typedef struct {
136 153 befs_block_run direct[BEFS_NUM_DIRECT_BLOCKS];
137 154 befs_off_t max_direct_range;
138 155 befs_block_run indirect;
139 156  
140 157  
141 158  
142 159  
143 160  
... ... @@ -144,35 +161,35 @@
144 161  
145 162 /* Attribute */
146 163 typedef struct {
147   - u32 type;
148   - u16 name_size;
149   - u16 data_size;
  164 + fs32 type;
  165 + fs16 name_size;
  166 + fs16 data_size;
150 167 char name[1];
151 168 } PACKED befs_small_data;
152 169  
153 170 /* Inode structure */
154 171 typedef struct {
155   - u32 magic1;
156   - befs_inode_addr inode_num;
157   - u32 uid;
158   - u32 gid;
159   - u32 mode;
160   - u32 flags;
  172 + fs32 magic1;
  173 + befs_disk_inode_addr inode_num;
  174 + fs32 uid;
  175 + fs32 gid;
  176 + fs32 mode;
  177 + fs32 flags;
161 178 befs_time_t create_time;
162 179 befs_time_t last_modified_time;
163   - befs_inode_addr parent;
164   - befs_inode_addr attributes;
165   - u32 type;
  180 + befs_disk_inode_addr parent;
  181 + befs_disk_inode_addr attributes;
  182 + fs32 type;
166 183  
167   - u32 inode_size;
168   - u32 etc; /* not use */
  184 + fs32 inode_size;
  185 + fs32 etc; /* not use */
169 186  
170 187 union {
171   - befs_data_stream datastream;
  188 + befs_disk_data_stream datastream;
172 189 char symlink[BEFS_SYMLINK_LEN];
173 190 } data;
174 191  
175   - u32 pad[4]; /* not use */
  192 + fs32 pad[4]; /* not use */
176 193 befs_small_data small_data[1];
177 194 } PACKED befs_inode;
178 195  
... ... @@ -193,6 +210,16 @@
193 210 };
194 211  
195 212 typedef 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 +
  222 +typedef struct {
196 223 u32 magic;
197 224 u32 node_size;
198 225 u32 max_depth;
199 226  
... ... @@ -206,12 +233,20 @@
206 233 * Header stucture of each btree node
207 234 */
208 235 typedef 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 +
  243 +typedef struct {
209 244 befs_off_t left;
210 245 befs_off_t right;
211 246 befs_off_t overflow;
212 247 u16 all_key_count;
213 248 u16 all_key_length;
214   -} PACKED befs_btree_nodehead;
  249 +} PACKED befs_host_btree_nodehead;
215 250  
216 251 #endif /* _LINUX_BEFS_FS_TYPES */
... ... @@ -79,7 +79,7 @@
79 79 * In memory structure of each btree node
80 80 */
81 81 typedef 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 83 struct buffer_head *bh;
84 84 befs_btree_nodehead *od_node; /* on disk node */
85 85 } befs_btree_node;
86 86  
... ... @@ -101,9 +101,9 @@
101 101  
102 102 static int befs_leafnode(befs_btree_node * node);
103 103  
104   -static u16 *befs_bt_keylen_index(befs_btree_node * node);
  104 +static fs16 *befs_bt_keylen_index(befs_btree_node * node);
105 105  
106   -static befs_off_t *befs_bt_valarray(befs_btree_node * node);
  106 +static fs64 *befs_bt_valarray(befs_btree_node * node);
107 107  
108 108 static char *befs_bt_keydata(befs_btree_node * node);
109 109  
... ... @@ -135,7 +135,7 @@
135 135 befs_btree_super * sup)
136 136 {
137 137 struct buffer_head *bh = NULL;
138   - befs_btree_super *od_sup = NULL;
  138 + befs_disk_btree_super *od_sup = NULL;
139 139  
140 140 befs_debug(sb, "---> befs_btree_read_super()");
141 141  
... ... @@ -145,7 +145,7 @@
145 145 befs_error(sb, "Couldn't read index header.");
146 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 149 befs_dump_index_entry(sb, od_sup);
150 150  
151 151 sup->magic = fs32_to_cpu(sb, od_sup->magic);
... ... @@ -341,7 +341,7 @@
341 341 u16 keylen;
342 342 int findkey_len;
343 343 char *thiskey;
344   - befs_off_t *valarray;
  344 + fs64 *valarray;
345 345  
346 346 befs_debug(sb, "---> befs_find_key() %s", findkey);
347 347  
... ... @@ -421,7 +421,7 @@
421 421 befs_btree_super bt_super;
422 422 befs_off_t node_off = 0;
423 423 int cur_key;
424   - befs_off_t *valarray;
  424 + fs64 *valarray;
425 425 char *keystart;
426 426 u16 keylen;
427 427 int res;
... ... @@ -571,7 +571,7 @@
571 571 this_node->head.overflow);
572 572 *node_off = this_node->head.overflow;
573 573 } else {
574   - befs_off_t *valarray = befs_bt_valarray(this_node);
  574 + fs64 *valarray = befs_bt_valarray(this_node);
575 575 *node_off = fs64_to_cpu(sb, valarray[0]);
576 576 }
577 577 if (befs_bt_read_node(sb, ds, this_node, *node_off) != BEFS_OK) {
... ... @@ -621,7 +621,7 @@
621 621 *
622 622 * Except that rounding up to 8 works, and rounding up to 4 doesn't.
623 623 */
624   -static u16 *
  624 +static fs16 *
625 625 befs_bt_keylen_index(befs_btree_node * node)
626 626 {
627 627 const int keylen_align = 8;
... ... @@ -632,7 +632,7 @@
632 632 if (tmp)
633 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 /**
639 639  
640 640  
... ... @@ -642,13 +642,13 @@
642 642 * Returns a pointer to the start of the value array
643 643 * of the node pointed to by the node header
644 644 */
645   -static befs_off_t *
  645 +static fs64 *
646 646 befs_bt_valarray(befs_btree_node * node)
647 647 {
648 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 @@
680 680 {
681 681 int prev_key_end;
682 682 char *keystart;
683   - u16 *keylen_index;
  683 + fs16 *keylen_index;
684 684  
685 685 if (index < 0 || index > node->head.all_key_count) {
686 686 *keylen = 0;
fs/befs/datastream.c
... ... @@ -311,7 +311,7 @@
311 311 befs_blocknr_t indir_start_blk;
312 312 befs_blocknr_t search_blk;
313 313 struct buffer_head *indirblock;
314   - befs_block_run *array;
  314 + befs_disk_block_run *array;
315 315  
316 316 befs_block_run indirect = data->indirect;
317 317 befs_blocknr_t indirblockno = iaddr2blockno(sb, &indirect);
... ... @@ -333,7 +333,7 @@
333 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 338 for (j = 0; j < arraylen; ++j) {
339 339 int len = fs16_to_cpu(sb, array[j].len);
... ... @@ -426,7 +426,7 @@
426 426 struct buffer_head *dbl_indir_block;
427 427 struct buffer_head *indir_block;
428 428 befs_block_run indir_run;
429   - befs_inode_addr *iaddr_array = NULL;
  429 + befs_disk_inode_addr *iaddr_array = NULL;
430 430 befs_sb_info *befs_sb = BEFS_SB(sb);
431 431  
432 432 befs_blocknr_t indir_start_blk =
... ... @@ -481,7 +481,7 @@
481 481  
482 482 dbl_block_indx =
483 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 485 indir_run = fsrun_to_cpu(sb, iaddr_array[dbl_block_indx]);
486 486 brelse(dbl_indir_block);
487 487 iaddr_array = NULL;
... ... @@ -506,7 +506,7 @@
506 506 }
507 507  
508 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 510 *run = fsrun_to_cpu(sb, iaddr_array[block_indx]);
511 511 brelse(indir_block);
512 512 iaddr_array = NULL;
... ... @@ -230,21 +230,20 @@
230 230  
231 231 /* unused */
232 232 void
233   -befs_dump_run(const struct super_block *sb, befs_block_run run)
  233 +befs_dump_run(const struct super_block *sb, befs_disk_block_run run)
234 234 {
235 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]",
240   - run.allocation_group, run.start, run.len);
  239 + befs_debug(sb, "[%u, %hu, %hu]", n.allocation_group, n.start, n.len);
241 240  
242 241 #endif //CONFIG_BEFS_DEBUG
243 242 }
244 243 #endif /* 0 */
245 244  
246 245 void
247   -befs_dump_index_entry(const struct super_block *sb, befs_btree_super * super)
  246 +befs_dump_index_entry(const struct super_block *sb, befs_disk_btree_super * super)
248 247 {
249 248 #ifdef CONFIG_BEFS_DEBUG
250 249  
... ... @@ -68,26 +68,26 @@
68 68 /* Composite types below here */
69 69  
70 70 static inline befs_block_run
71   -fsrun_to_cpu(const struct super_block *sb, befs_block_run n)
  71 +fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n)
72 72 {
73 73 befs_block_run run;
74 74  
75 75 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
76   - run.allocation_group = le32_to_cpu(n.allocation_group);
77   - run.start = le16_to_cpu(n.start);
78   - run.len = le16_to_cpu(n.len);
  76 + run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group);
  77 + run.start = le16_to_cpu((__force __le16)n.start);
  78 + run.len = le16_to_cpu((__force __le16)n.len);
79 79 } else {
80   - run.allocation_group = be32_to_cpu(n.allocation_group);
81   - run.start = be16_to_cpu(n.start);
82   - run.len = be16_to_cpu(n.len);
  80 + run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group);
  81 + run.start = be16_to_cpu((__force __be16)n.start);
  82 + run.len = be16_to_cpu((__force __be16)n.len);
83 83 }
84 84 return run;
85 85 }
86 86  
87   -static inline befs_block_run
  87 +static inline befs_disk_block_run
88 88 cpu_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 92 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
93 93 run.allocation_group = cpu_to_le32(n.allocation_group);
... ... @@ -102,7 +102,7 @@
102 102 }
103 103  
104 104 static inline befs_data_stream
105   -fsds_to_cpu(const struct super_block *sb, befs_data_stream n)
  105 +fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n)
106 106 {
107 107 befs_data_stream data;
108 108 int i;