aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hpfs/alloc.c
diff options
context:
space:
mode:
authorMikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>2011-05-08 14:44:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-09 12:04:24 -0400
commit0b69760be6968c528869d4aec95ecf64dbf3e8bd (patch)
treeebc1f353c7df72bfe28b9da64af810c20ca8cdd4 /fs/hpfs/alloc.c
parentbc8728ee56bca62df269b2dd159bc60838ac8e80 (diff)
HPFS: Fix endianity. Make hpfs work on big-endian machines
Fix endianity. Make hpfs work on big-endian machines. Signed-off-by: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/hpfs/alloc.c')
-rw-r--r--fs/hpfs/alloc.c68
1 files changed, 32 insertions, 36 deletions
diff --git a/fs/hpfs/alloc.c b/fs/hpfs/alloc.c
index 995472de92a..7a5eb2c718c 100644
--- a/fs/hpfs/alloc.c
+++ b/fs/hpfs/alloc.c
@@ -16,9 +16,9 @@
16static int chk_if_allocated(struct super_block *s, secno sec, char *msg) 16static int chk_if_allocated(struct super_block *s, secno sec, char *msg)
17{ 17{
18 struct quad_buffer_head qbh; 18 struct quad_buffer_head qbh;
19 unsigned *bmp; 19 u32 *bmp;
20 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "chk"))) goto fail; 20 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "chk"))) goto fail;
21 if ((bmp[(sec & 0x3fff) >> 5] >> (sec & 0x1f)) & 1) { 21 if ((cpu_to_le32(bmp[(sec & 0x3fff) >> 5]) >> (sec & 0x1f)) & 1) {
22 hpfs_error(s, "sector '%s' - %08x not allocated in bitmap", msg, sec); 22 hpfs_error(s, "sector '%s' - %08x not allocated in bitmap", msg, sec);
23 goto fail1; 23 goto fail1;
24 } 24 }
@@ -26,7 +26,7 @@ static int chk_if_allocated(struct super_block *s, secno sec, char *msg)
26 if (sec >= hpfs_sb(s)->sb_dirband_start && sec < hpfs_sb(s)->sb_dirband_start + hpfs_sb(s)->sb_dirband_size) { 26 if (sec >= hpfs_sb(s)->sb_dirband_start && sec < hpfs_sb(s)->sb_dirband_start + hpfs_sb(s)->sb_dirband_size) {
27 unsigned ssec = (sec - hpfs_sb(s)->sb_dirband_start) / 4; 27 unsigned ssec = (sec - hpfs_sb(s)->sb_dirband_start) / 4;
28 if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) goto fail; 28 if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) goto fail;
29 if ((bmp[ssec >> 5] >> (ssec & 0x1f)) & 1) { 29 if ((le32_to_cpu(bmp[ssec >> 5]) >> (ssec & 0x1f)) & 1) {
30 hpfs_error(s, "sector '%s' - %08x not allocated in directory bitmap", msg, sec); 30 hpfs_error(s, "sector '%s' - %08x not allocated in directory bitmap", msg, sec);
31 goto fail1; 31 goto fail1;
32 } 32 }
@@ -82,10 +82,6 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne
82 ret = bs + nr; 82 ret = bs + nr;
83 goto rt; 83 goto rt;
84 } 84 }
85 /*if (!tstbits(bmp, nr + n, n + forward)) {
86 ret = bs + nr + n;
87 goto rt;
88 }*/
89 q = nr + n; b = 0; 85 q = nr + n; b = 0;
90 while ((a = tstbits(bmp, q, n + forward)) != 0) { 86 while ((a = tstbits(bmp, q, n + forward)) != 0) {
91 q += a; 87 q += a;
@@ -102,14 +98,14 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne
102 goto rt; 98 goto rt;
103 } 99 }
104 nr >>= 5; 100 nr >>= 5;
105 /*for (i = nr + 1; i != nr; i++, i &= 0x1ff) {*/ 101 /*for (i = nr + 1; i != nr; i++, i &= 0x1ff) */
106 i = nr; 102 i = nr;
107 do { 103 do {
108 if (!bmp[i]) goto cont; 104 if (!le32_to_cpu(bmp[i])) goto cont;
109 if (n + forward >= 0x3f && bmp[i] != -1) goto cont; 105 if (n + forward >= 0x3f && le32_to_cpu(bmp[i]) != 0xffffffff) goto cont;
110 q = i<<5; 106 q = i<<5;
111 if (i > 0) { 107 if (i > 0) {
112 unsigned k = bmp[i-1]; 108 unsigned k = le32_to_cpu(bmp[i-1]);
113 while (k & 0x80000000) { 109 while (k & 0x80000000) {
114 q--; k <<= 1; 110 q--; k <<= 1;
115 } 111 }
@@ -129,12 +125,12 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne
129 } while (i != nr); 125 } while (i != nr);
130 rt: 126 rt:
131 if (ret) { 127 if (ret) {
132 if (hpfs_sb(s)->sb_chk && ((ret >> 14) != (bs >> 14) || (bmp[(ret & 0x3fff) >> 5] | ~(((1 << n) - 1) << (ret & 0x1f))) != 0xffffffff)) { 128 if (hpfs_sb(s)->sb_chk && ((ret >> 14) != (bs >> 14) || (le32_to_cpu(bmp[(ret & 0x3fff) >> 5]) | ~(((1 << n) - 1) << (ret & 0x1f))) != 0xffffffff)) {
133 hpfs_error(s, "Allocation doesn't work! Wanted %d, allocated at %08x", n, ret); 129 hpfs_error(s, "Allocation doesn't work! Wanted %d, allocated at %08x", n, ret);
134 ret = 0; 130 ret = 0;
135 goto b; 131 goto b;
136 } 132 }
137 bmp[(ret & 0x3fff) >> 5] &= ~(((1 << n) - 1) << (ret & 0x1f)); 133 bmp[(ret & 0x3fff) >> 5] &= cpu_to_le32(~(((1 << n) - 1) << (ret & 0x1f)));
138 hpfs_mark_4buffers_dirty(&qbh); 134 hpfs_mark_4buffers_dirty(&qbh);
139 } 135 }
140 b: 136 b:
@@ -240,10 +236,10 @@ static secno alloc_in_dirband(struct super_block *s, secno near)
240int hpfs_alloc_if_possible(struct super_block *s, secno sec) 236int hpfs_alloc_if_possible(struct super_block *s, secno sec)
241{ 237{
242 struct quad_buffer_head qbh; 238 struct quad_buffer_head qbh;
243 unsigned *bmp; 239 u32 *bmp;
244 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "aip"))) goto end; 240 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "aip"))) goto end;
245 if (bmp[(sec & 0x3fff) >> 5] & (1 << (sec & 0x1f))) { 241 if (le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) & (1 << (sec & 0x1f))) {
246 bmp[(sec & 0x3fff) >> 5] &= ~(1 << (sec & 0x1f)); 242 bmp[(sec & 0x3fff) >> 5] &= cpu_to_le32(~(1 << (sec & 0x1f)));
247 hpfs_mark_4buffers_dirty(&qbh); 243 hpfs_mark_4buffers_dirty(&qbh);
248 hpfs_brelse4(&qbh); 244 hpfs_brelse4(&qbh);
249 return 1; 245 return 1;
@@ -258,7 +254,7 @@ int hpfs_alloc_if_possible(struct super_block *s, secno sec)
258void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n) 254void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n)
259{ 255{
260 struct quad_buffer_head qbh; 256 struct quad_buffer_head qbh;
261 unsigned *bmp; 257 u32 *bmp;
262 struct hpfs_sb_info *sbi = hpfs_sb(s); 258 struct hpfs_sb_info *sbi = hpfs_sb(s);
263 /*printk("2 - ");*/ 259 /*printk("2 - ");*/
264 if (!n) return; 260 if (!n) return;
@@ -273,12 +269,12 @@ void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n)
273 return; 269 return;
274 } 270 }
275 new_tst: 271 new_tst:
276 if ((bmp[(sec & 0x3fff) >> 5] >> (sec & 0x1f) & 1)) { 272 if ((le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) >> (sec & 0x1f) & 1)) {
277 hpfs_error(s, "sector %08x not allocated", sec); 273 hpfs_error(s, "sector %08x not allocated", sec);
278 hpfs_brelse4(&qbh); 274 hpfs_brelse4(&qbh);
279 return; 275 return;
280 } 276 }
281 bmp[(sec & 0x3fff) >> 5] |= 1 << (sec & 0x1f); 277 bmp[(sec & 0x3fff) >> 5] |= cpu_to_le32(1 << (sec & 0x1f));
282 if (!--n) { 278 if (!--n) {
283 hpfs_mark_4buffers_dirty(&qbh); 279 hpfs_mark_4buffers_dirty(&qbh);
284 hpfs_brelse4(&qbh); 280 hpfs_brelse4(&qbh);
@@ -303,13 +299,13 @@ int hpfs_check_free_dnodes(struct super_block *s, int n)
303 int n_bmps = (hpfs_sb(s)->sb_fs_size + 0x4000 - 1) >> 14; 299 int n_bmps = (hpfs_sb(s)->sb_fs_size + 0x4000 - 1) >> 14;
304 int b = hpfs_sb(s)->sb_c_bitmap & 0x0fffffff; 300 int b = hpfs_sb(s)->sb_c_bitmap & 0x0fffffff;
305 int i, j; 301 int i, j;
306 unsigned *bmp; 302 u32 *bmp;
307 struct quad_buffer_head qbh; 303 struct quad_buffer_head qbh;
308 if ((bmp = hpfs_map_dnode_bitmap(s, &qbh))) { 304 if ((bmp = hpfs_map_dnode_bitmap(s, &qbh))) {
309 for (j = 0; j < 512; j++) { 305 for (j = 0; j < 512; j++) {
310 unsigned k; 306 unsigned k;
311 if (!bmp[j]) continue; 307 if (!le32_to_cpu(bmp[j])) continue;
312 for (k = bmp[j]; k; k >>= 1) if (k & 1) if (!--n) { 308 for (k = le32_to_cpu(bmp[j]); k; k >>= 1) if (k & 1) if (!--n) {
313 hpfs_brelse4(&qbh); 309 hpfs_brelse4(&qbh);
314 return 0; 310 return 0;
315 } 311 }
@@ -328,10 +324,10 @@ int hpfs_check_free_dnodes(struct super_block *s, int n)
328 chk_bmp: 324 chk_bmp:
329 if (bmp) { 325 if (bmp) {
330 for (j = 0; j < 512; j++) { 326 for (j = 0; j < 512; j++) {
331 unsigned k; 327 u32 k;
332 if (!bmp[j]) continue; 328 if (!le32_to_cpu(bmp[j])) continue;
333 for (k = 0xf; k; k <<= 4) 329 for (k = 0xf; k; k <<= 4)
334 if ((bmp[j] & k) == k) { 330 if ((le32_to_cpu(bmp[j]) & k) == k) {
335 if (!--n) { 331 if (!--n) {
336 hpfs_brelse4(&qbh); 332 hpfs_brelse4(&qbh);
337 return 0; 333 return 0;
@@ -355,12 +351,12 @@ void hpfs_free_dnode(struct super_block *s, dnode_secno dno)
355 hpfs_free_sectors(s, dno, 4); 351 hpfs_free_sectors(s, dno, 4);
356 } else { 352 } else {
357 struct quad_buffer_head qbh; 353 struct quad_buffer_head qbh;
358 unsigned *bmp; 354 u32 *bmp;
359 unsigned ssec = (dno - hpfs_sb(s)->sb_dirband_start) / 4; 355 unsigned ssec = (dno - hpfs_sb(s)->sb_dirband_start) / 4;
360 if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) { 356 if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) {
361 return; 357 return;
362 } 358 }
363 bmp[ssec >> 5] |= 1 << (ssec & 0x1f); 359 bmp[ssec >> 5] |= cpu_to_le32(1 << (ssec & 0x1f));
364 hpfs_mark_4buffers_dirty(&qbh); 360 hpfs_mark_4buffers_dirty(&qbh);
365 hpfs_brelse4(&qbh); 361 hpfs_brelse4(&qbh);
366 } 362 }
@@ -382,13 +378,13 @@ struct dnode *hpfs_alloc_dnode(struct super_block *s, secno near,
382 return NULL; 378 return NULL;
383 } 379 }
384 memset(d, 0, 2048); 380 memset(d, 0, 2048);
385 d->magic = DNODE_MAGIC; 381 d->magic = cpu_to_le32(DNODE_MAGIC);
386 d->first_free = 52; 382 d->first_free = cpu_to_le32(52);
387 d->dirent[0] = 32; 383 d->dirent[0] = 32;
388 d->dirent[2] = 8; 384 d->dirent[2] = 8;
389 d->dirent[30] = 1; 385 d->dirent[30] = 1;
390 d->dirent[31] = 255; 386 d->dirent[31] = 255;
391 d->self = *dno; 387 d->self = cpu_to_le32(*dno);
392 return d; 388 return d;
393} 389}
394 390
@@ -402,10 +398,10 @@ struct fnode *hpfs_alloc_fnode(struct super_block *s, secno near, fnode_secno *f
402 return NULL; 398 return NULL;
403 } 399 }
404 memset(f, 0, 512); 400 memset(f, 0, 512);
405 f->magic = FNODE_MAGIC; 401 f->magic = cpu_to_le32(FNODE_MAGIC);
406 f->ea_offs = 0xc4; 402 f->ea_offs = cpu_to_le16(0xc4);
407 f->btree.n_free_nodes = 8; 403 f->btree.n_free_nodes = 8;
408 f->btree.first_free = 8; 404 f->btree.first_free = cpu_to_le16(8);
409 return f; 405 return f;
410} 406}
411 407
@@ -419,10 +415,10 @@ struct anode *hpfs_alloc_anode(struct super_block *s, secno near, anode_secno *a
419 return NULL; 415 return NULL;
420 } 416 }
421 memset(a, 0, 512); 417 memset(a, 0, 512);
422 a->magic = ANODE_MAGIC; 418 a->magic = cpu_to_le32(ANODE_MAGIC);
423 a->self = *ano; 419 a->self = cpu_to_le32(*ano);
424 a->btree.n_free_nodes = 40; 420 a->btree.n_free_nodes = 40;
425 a->btree.n_used_nodes = 0; 421 a->btree.n_used_nodes = 0;
426 a->btree.first_free = 8; 422 a->btree.first_free = cpu_to_le16(8);
427 return a; 423 return a;
428} 424}