aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hpfs/dnode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/hpfs/dnode.c')
-rw-r--r--fs/hpfs/dnode.c127
1 files changed, 64 insertions, 63 deletions
diff --git a/fs/hpfs/dnode.c b/fs/hpfs/dnode.c
index 07711c392f8b..1e0e2ac30fd3 100644
--- a/fs/hpfs/dnode.c
+++ b/fs/hpfs/dnode.c
@@ -14,11 +14,11 @@ static loff_t get_pos(struct dnode *d, struct hpfs_dirent *fde)
14 struct hpfs_dirent *de_end = dnode_end_de(d); 14 struct hpfs_dirent *de_end = dnode_end_de(d);
15 int i = 1; 15 int i = 1;
16 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) { 16 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
17 if (de == fde) return ((loff_t) d->self << 4) | (loff_t)i; 17 if (de == fde) return ((loff_t) le32_to_cpu(d->self) << 4) | (loff_t)i;
18 i++; 18 i++;
19 } 19 }
20 printk("HPFS: get_pos: not_found\n"); 20 printk("HPFS: get_pos: not_found\n");
21 return ((loff_t)d->self << 4) | (loff_t)1; 21 return ((loff_t)le32_to_cpu(d->self) << 4) | (loff_t)1;
22} 22}
23 23
24void hpfs_add_pos(struct inode *inode, loff_t *pos) 24void hpfs_add_pos(struct inode *inode, loff_t *pos)
@@ -130,30 +130,30 @@ static void set_last_pointer(struct super_block *s, struct dnode *d, dnode_secno
130{ 130{
131 struct hpfs_dirent *de; 131 struct hpfs_dirent *de;
132 if (!(de = dnode_last_de(d))) { 132 if (!(de = dnode_last_de(d))) {
133 hpfs_error(s, "set_last_pointer: empty dnode %08x", d->self); 133 hpfs_error(s, "set_last_pointer: empty dnode %08x", le32_to_cpu(d->self));
134 return; 134 return;
135 } 135 }
136 if (hpfs_sb(s)->sb_chk) { 136 if (hpfs_sb(s)->sb_chk) {
137 if (de->down) { 137 if (de->down) {
138 hpfs_error(s, "set_last_pointer: dnode %08x has already last pointer %08x", 138 hpfs_error(s, "set_last_pointer: dnode %08x has already last pointer %08x",
139 d->self, de_down_pointer(de)); 139 le32_to_cpu(d->self), de_down_pointer(de));
140 return; 140 return;
141 } 141 }
142 if (de->length != 32) { 142 if (le16_to_cpu(de->length) != 32) {
143 hpfs_error(s, "set_last_pointer: bad last dirent in dnode %08x", d->self); 143 hpfs_error(s, "set_last_pointer: bad last dirent in dnode %08x", le32_to_cpu(d->self));
144 return; 144 return;
145 } 145 }
146 } 146 }
147 if (ptr) { 147 if (ptr) {
148 d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) + 4); 148 d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) + 4);
149 if (le32_to_cpu(d->first_free) > 2048) { 149 if (le32_to_cpu(d->first_free) > 2048) {
150 hpfs_error(s, "set_last_pointer: too long dnode %08x", d->self); 150 hpfs_error(s, "set_last_pointer: too long dnode %08x", le32_to_cpu(d->self));
151 d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) - 4); 151 d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) - 4);
152 return; 152 return;
153 } 153 }
154 de->length = 36; 154 de->length = cpu_to_le16(36);
155 de->down = 1; 155 de->down = 1;
156 *(dnode_secno *)((char *)de + 32) = ptr; 156 *(dnode_secno *)((char *)de + 32) = cpu_to_le32(ptr);
157 } 157 }
158} 158}
159 159
@@ -169,7 +169,7 @@ struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d,
169 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) { 169 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
170 int c = hpfs_compare_names(s, name, namelen, de->name, de->namelen, de->last); 170 int c = hpfs_compare_names(s, name, namelen, de->name, de->namelen, de->last);
171 if (!c) { 171 if (!c) {
172 hpfs_error(s, "name (%c,%d) already exists in dnode %08x", *name, namelen, d->self); 172 hpfs_error(s, "name (%c,%d) already exists in dnode %08x", *name, namelen, le32_to_cpu(d->self));
173 return NULL; 173 return NULL;
174 } 174 }
175 if (c < 0) break; 175 if (c < 0) break;
@@ -177,11 +177,10 @@ struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d,
177 memmove((char *)de + d_size, de, (char *)de_end - (char *)de); 177 memmove((char *)de + d_size, de, (char *)de_end - (char *)de);
178 memset(de, 0, d_size); 178 memset(de, 0, d_size);
179 if (down_ptr) { 179 if (down_ptr) {
180 *(int *)((char *)de + d_size - 4) = down_ptr; 180 *(dnode_secno *)((char *)de + d_size - 4) = cpu_to_le32(down_ptr);
181 de->down = 1; 181 de->down = 1;
182 } 182 }
183 de->length = d_size; 183 de->length = cpu_to_le16(d_size);
184 if (down_ptr) de->down = 1;
185 de->not_8x3 = hpfs_is_name_long(name, namelen); 184 de->not_8x3 = hpfs_is_name_long(name, namelen);
186 de->namelen = namelen; 185 de->namelen = namelen;
187 memcpy(de->name, name, namelen); 186 memcpy(de->name, name, namelen);
@@ -195,10 +194,10 @@ static void hpfs_delete_de(struct super_block *s, struct dnode *d,
195 struct hpfs_dirent *de) 194 struct hpfs_dirent *de)
196{ 195{
197 if (de->last) { 196 if (de->last) {
198 hpfs_error(s, "attempt to delete last dirent in dnode %08x", d->self); 197 hpfs_error(s, "attempt to delete last dirent in dnode %08x", le32_to_cpu(d->self));
199 return; 198 return;
200 } 199 }
201 d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) - de->length); 200 d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) - le16_to_cpu(de->length));
202 memmove(de, de_next_de(de), le32_to_cpu(d->first_free) + (char *)d - (char *)de); 201 memmove(de, de_next_de(de), le32_to_cpu(d->first_free) + (char *)d - (char *)de);
203} 202}
204 203
@@ -206,14 +205,14 @@ static void fix_up_ptrs(struct super_block *s, struct dnode *d)
206{ 205{
207 struct hpfs_dirent *de; 206 struct hpfs_dirent *de;
208 struct hpfs_dirent *de_end = dnode_end_de(d); 207 struct hpfs_dirent *de_end = dnode_end_de(d);
209 dnode_secno dno = d->self; 208 dnode_secno dno = le32_to_cpu(d->self);
210 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) 209 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de))
211 if (de->down) { 210 if (de->down) {
212 struct quad_buffer_head qbh; 211 struct quad_buffer_head qbh;
213 struct dnode *dd; 212 struct dnode *dd;
214 if ((dd = hpfs_map_dnode(s, de_down_pointer(de), &qbh))) { 213 if ((dd = hpfs_map_dnode(s, de_down_pointer(de), &qbh))) {
215 if (dd->up != dno || dd->root_dnode) { 214 if (le32_to_cpu(dd->up) != dno || dd->root_dnode) {
216 dd->up = dno; 215 dd->up = cpu_to_le32(dno);
217 dd->root_dnode = 0; 216 dd->root_dnode = 0;
218 hpfs_mark_4buffers_dirty(&qbh); 217 hpfs_mark_4buffers_dirty(&qbh);
219 } 218 }
@@ -291,7 +290,7 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
291 copy_de(de = hpfs_add_de(i->i_sb, nd, name, namelen, down_ptr), new_de); 290 copy_de(de = hpfs_add_de(i->i_sb, nd, name, namelen, down_ptr), new_de);
292 for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1); 291 for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1);
293 h = ((char *)dnode_last_de(nd) - (char *)nd) / 2 + 10; 292 h = ((char *)dnode_last_de(nd) - (char *)nd) / 2 + 10;
294 if (!(ad = hpfs_alloc_dnode(i->i_sb, d->up, &adno, &qbh1))) { 293 if (!(ad = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &adno, &qbh1))) {
295 hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted"); 294 hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted");
296 hpfs_brelse4(&qbh); 295 hpfs_brelse4(&qbh);
297 kfree(nd); 296 kfree(nd);
@@ -315,19 +314,20 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
315 set_last_pointer(i->i_sb, ad, de->down ? de_down_pointer(de) : 0); 314 set_last_pointer(i->i_sb, ad, de->down ? de_down_pointer(de) : 0);
316 de = de_next_de(de); 315 de = de_next_de(de);
317 memmove((char *)nd + 20, de, le32_to_cpu(nd->first_free) + (char *)nd - (char *)de); 316 memmove((char *)nd + 20, de, le32_to_cpu(nd->first_free) + (char *)nd - (char *)de);
318 nd->first_free = cpu_to_le32(le32_to_cpu(nd->first_free) - (char *)de - (char *)nd - 20); 317 nd->first_free = cpu_to_le32(le32_to_cpu(nd->first_free) - ((char *)de - (char *)nd - 20));
319 memcpy(d, nd, le32_to_cpu(nd->first_free)); 318 memcpy(d, nd, le32_to_cpu(nd->first_free));
320 for_all_poss(i, hpfs_pos_del, (loff_t)dno << 4, pos); 319 for_all_poss(i, hpfs_pos_del, (loff_t)dno << 4, pos);
321 fix_up_ptrs(i->i_sb, ad); 320 fix_up_ptrs(i->i_sb, ad);
322 if (!d->root_dnode) { 321 if (!d->root_dnode) {
323 dno = ad->up = d->up; 322 ad->up = d->up;
323 dno = le32_to_cpu(ad->up);
324 hpfs_mark_4buffers_dirty(&qbh); 324 hpfs_mark_4buffers_dirty(&qbh);
325 hpfs_brelse4(&qbh); 325 hpfs_brelse4(&qbh);
326 hpfs_mark_4buffers_dirty(&qbh1); 326 hpfs_mark_4buffers_dirty(&qbh1);
327 hpfs_brelse4(&qbh1); 327 hpfs_brelse4(&qbh1);
328 goto go_up; 328 goto go_up;
329 } 329 }
330 if (!(rd = hpfs_alloc_dnode(i->i_sb, d->up, &rdno, &qbh2))) { 330 if (!(rd = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &rdno, &qbh2))) {
331 hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted"); 331 hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted");
332 hpfs_brelse4(&qbh); 332 hpfs_brelse4(&qbh);
333 hpfs_brelse4(&qbh1); 333 hpfs_brelse4(&qbh1);
@@ -339,7 +339,7 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
339 i->i_blocks += 4; 339 i->i_blocks += 4;
340 rd->root_dnode = 1; 340 rd->root_dnode = 1;
341 rd->up = d->up; 341 rd->up = d->up;
342 if (!(fnode = hpfs_map_fnode(i->i_sb, d->up, &bh))) { 342 if (!(fnode = hpfs_map_fnode(i->i_sb, le32_to_cpu(d->up), &bh))) {
343 hpfs_free_dnode(i->i_sb, rdno); 343 hpfs_free_dnode(i->i_sb, rdno);
344 hpfs_brelse4(&qbh); 344 hpfs_brelse4(&qbh);
345 hpfs_brelse4(&qbh1); 345 hpfs_brelse4(&qbh1);
@@ -348,10 +348,11 @@ static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
348 kfree(nname); 348 kfree(nname);
349 return 1; 349 return 1;
350 } 350 }
351 fnode->u.external[0].disk_secno = rdno; 351 fnode->u.external[0].disk_secno = cpu_to_le32(rdno);
352 mark_buffer_dirty(bh); 352 mark_buffer_dirty(bh);
353 brelse(bh); 353 brelse(bh);
354 d->up = ad->up = hpfs_i(i)->i_dno = rdno; 354 hpfs_i(i)->i_dno = rdno;
355 d->up = ad->up = cpu_to_le32(rdno);
355 d->root_dnode = ad->root_dnode = 0; 356 d->root_dnode = ad->root_dnode = 0;
356 hpfs_mark_4buffers_dirty(&qbh); 357 hpfs_mark_4buffers_dirty(&qbh);
357 hpfs_brelse4(&qbh); 358 hpfs_brelse4(&qbh);
@@ -436,9 +437,9 @@ static secno move_to_top(struct inode *i, dnode_secno from, dnode_secno to)
436 return 0; 437 return 0;
437 if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 0; 438 if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 0;
438 if (hpfs_sb(i->i_sb)->sb_chk) { 439 if (hpfs_sb(i->i_sb)->sb_chk) {
439 if (dnode->up != chk_up) { 440 if (le32_to_cpu(dnode->up) != chk_up) {
440 hpfs_error(i->i_sb, "move_to_top: up pointer from %08x should be %08x, is %08x", 441 hpfs_error(i->i_sb, "move_to_top: up pointer from %08x should be %08x, is %08x",
441 dno, chk_up, dnode->up); 442 dno, chk_up, le32_to_cpu(dnode->up));
442 hpfs_brelse4(&qbh); 443 hpfs_brelse4(&qbh);
443 return 0; 444 return 0;
444 } 445 }
@@ -454,7 +455,7 @@ static secno move_to_top(struct inode *i, dnode_secno from, dnode_secno to)
454 hpfs_brelse4(&qbh); 455 hpfs_brelse4(&qbh);
455 } 456 }
456 while (!(de = dnode_pre_last_de(dnode))) { 457 while (!(de = dnode_pre_last_de(dnode))) {
457 dnode_secno up = dnode->up; 458 dnode_secno up = le32_to_cpu(dnode->up);
458 hpfs_brelse4(&qbh); 459 hpfs_brelse4(&qbh);
459 hpfs_free_dnode(i->i_sb, dno); 460 hpfs_free_dnode(i->i_sb, dno);
460 i->i_size -= 2048; 461 i->i_size -= 2048;
@@ -474,7 +475,7 @@ static secno move_to_top(struct inode *i, dnode_secno from, dnode_secno to)
474 return 0; 475 return 0;
475 } 476 }
476 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) - 4); 477 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) - 4);
477 de->length -= 4; 478 de->length = cpu_to_le16(le16_to_cpu(de->length) - 4);
478 de->down = 0; 479 de->down = 0;
479 hpfs_mark_4buffers_dirty(&qbh); 480 hpfs_mark_4buffers_dirty(&qbh);
480 dno = up; 481 dno = up;
@@ -482,12 +483,12 @@ static secno move_to_top(struct inode *i, dnode_secno from, dnode_secno to)
482 t = get_pos(dnode, de); 483 t = get_pos(dnode, de);
483 for_all_poss(i, hpfs_pos_subst, t, 4); 484 for_all_poss(i, hpfs_pos_subst, t, 4);
484 for_all_poss(i, hpfs_pos_subst, t + 1, 5); 485 for_all_poss(i, hpfs_pos_subst, t + 1, 5);
485 if (!(nde = kmalloc(de->length, GFP_NOFS))) { 486 if (!(nde = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
486 hpfs_error(i->i_sb, "out of memory for dirent - directory will be corrupted"); 487 hpfs_error(i->i_sb, "out of memory for dirent - directory will be corrupted");
487 hpfs_brelse4(&qbh); 488 hpfs_brelse4(&qbh);
488 return 0; 489 return 0;
489 } 490 }
490 memcpy(nde, de, de->length); 491 memcpy(nde, de, le16_to_cpu(de->length));
491 ddno = de->down ? de_down_pointer(de) : 0; 492 ddno = de->down ? de_down_pointer(de) : 0;
492 hpfs_delete_de(i->i_sb, dnode, de); 493 hpfs_delete_de(i->i_sb, dnode, de);
493 set_last_pointer(i->i_sb, dnode, ddno); 494 set_last_pointer(i->i_sb, dnode, ddno);
@@ -520,7 +521,7 @@ static void delete_empty_dnode(struct inode *i, dnode_secno dno)
520 if (le32_to_cpu(dnode->first_free) == 52 || le32_to_cpu(dnode->first_free) == 56) { 521 if (le32_to_cpu(dnode->first_free) == 52 || le32_to_cpu(dnode->first_free) == 56) {
521 struct hpfs_dirent *de_end; 522 struct hpfs_dirent *de_end;
522 int root = dnode->root_dnode; 523 int root = dnode->root_dnode;
523 up = dnode->up; 524 up = le32_to_cpu(dnode->up);
524 de = dnode_first_de(dnode); 525 de = dnode_first_de(dnode);
525 down = de->down ? de_down_pointer(de) : 0; 526 down = de->down ? de_down_pointer(de) : 0;
526 if (hpfs_sb(i->i_sb)->sb_chk) if (root && !down) { 527 if (hpfs_sb(i->i_sb)->sb_chk) if (root && !down) {
@@ -544,13 +545,13 @@ static void delete_empty_dnode(struct inode *i, dnode_secno dno)
544 return; 545 return;
545 } 546 }
546 if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) { 547 if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) {
547 d1->up = up; 548 d1->up = cpu_to_le32(up);
548 d1->root_dnode = 1; 549 d1->root_dnode = 1;
549 hpfs_mark_4buffers_dirty(&qbh1); 550 hpfs_mark_4buffers_dirty(&qbh1);
550 hpfs_brelse4(&qbh1); 551 hpfs_brelse4(&qbh1);
551 } 552 }
552 if ((fnode = hpfs_map_fnode(i->i_sb, up, &bh))) { 553 if ((fnode = hpfs_map_fnode(i->i_sb, up, &bh))) {
553 fnode->u.external[0].disk_secno = down; 554 fnode->u.external[0].disk_secno = cpu_to_le32(down);
554 mark_buffer_dirty(bh); 555 mark_buffer_dirty(bh);
555 brelse(bh); 556 brelse(bh);
556 } 557 }
@@ -569,16 +570,16 @@ static void delete_empty_dnode(struct inode *i, dnode_secno dno)
569 for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, ((loff_t)up << 4) | p); 570 for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, ((loff_t)up << 4) | p);
570 if (!down) { 571 if (!down) {
571 de->down = 0; 572 de->down = 0;
572 de->length -= 4; 573 de->length = cpu_to_le16(le16_to_cpu(de->length) - 4);
573 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) - 4); 574 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) - 4);
574 memmove(de_next_de(de), (char *)de_next_de(de) + 4, 575 memmove(de_next_de(de), (char *)de_next_de(de) + 4,
575 (char *)dnode + le32_to_cpu(dnode->first_free) - (char *)de_next_de(de)); 576 (char *)dnode + le32_to_cpu(dnode->first_free) - (char *)de_next_de(de));
576 } else { 577 } else {
577 struct dnode *d1; 578 struct dnode *d1;
578 struct quad_buffer_head qbh1; 579 struct quad_buffer_head qbh1;
579 *(dnode_secno *) ((void *) de + de->length - 4) = down; 580 *(dnode_secno *) ((void *) de + le16_to_cpu(de->length) - 4) = down;
580 if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) { 581 if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) {
581 d1->up = up; 582 d1->up = cpu_to_le32(up);
582 hpfs_mark_4buffers_dirty(&qbh1); 583 hpfs_mark_4buffers_dirty(&qbh1);
583 hpfs_brelse4(&qbh1); 584 hpfs_brelse4(&qbh1);
584 } 585 }
@@ -595,18 +596,18 @@ static void delete_empty_dnode(struct inode *i, dnode_secno dno)
595 struct quad_buffer_head qbh1; 596 struct quad_buffer_head qbh1;
596 if (!de_next->down) goto endm; 597 if (!de_next->down) goto endm;
597 ndown = de_down_pointer(de_next); 598 ndown = de_down_pointer(de_next);
598 if (!(de_cp = kmalloc(de->length, GFP_NOFS))) { 599 if (!(de_cp = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
599 printk("HPFS: out of memory for dtree balancing\n"); 600 printk("HPFS: out of memory for dtree balancing\n");
600 goto endm; 601 goto endm;
601 } 602 }
602 memcpy(de_cp, de, de->length); 603 memcpy(de_cp, de, le16_to_cpu(de->length));
603 hpfs_delete_de(i->i_sb, dnode, de); 604 hpfs_delete_de(i->i_sb, dnode, de);
604 hpfs_mark_4buffers_dirty(&qbh); 605 hpfs_mark_4buffers_dirty(&qbh);
605 hpfs_brelse4(&qbh); 606 hpfs_brelse4(&qbh);
606 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, 4); 607 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, 4);
607 for_all_poss(i, hpfs_pos_del, ((loff_t)up << 4) | p, 1); 608 for_all_poss(i, hpfs_pos_del, ((loff_t)up << 4) | p, 1);
608 if (de_cp->down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de_cp), &qbh1))) { 609 if (de_cp->down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de_cp), &qbh1))) {
609 d1->up = ndown; 610 d1->up = cpu_to_le32(ndown);
610 hpfs_mark_4buffers_dirty(&qbh1); 611 hpfs_mark_4buffers_dirty(&qbh1);
611 hpfs_brelse4(&qbh1); 612 hpfs_brelse4(&qbh1);
612 } 613 }
@@ -646,38 +647,38 @@ static void delete_empty_dnode(struct inode *i, dnode_secno dno)
646 printk("HPFS: warning: unbalanced dnode tree, see hpfs.txt 4 more info\n"); 647 printk("HPFS: warning: unbalanced dnode tree, see hpfs.txt 4 more info\n");
647 printk("HPFS: warning: goin'on\n"); 648 printk("HPFS: warning: goin'on\n");
648 } 649 }
649 del->length += 4; 650 del->length = cpu_to_le16(le16_to_cpu(del->length) + 4);
650 del->down = 1; 651 del->down = 1;
651 d1->first_free = cpu_to_le32(le32_to_cpu(d1->first_free) + 4); 652 d1->first_free = cpu_to_le32(le32_to_cpu(d1->first_free) + 4);
652 } 653 }
653 if (dlp && !down) { 654 if (dlp && !down) {
654 del->length -= 4; 655 del->length = cpu_to_le16(le16_to_cpu(del->length) - 4);
655 del->down = 0; 656 del->down = 0;
656 d1->first_free = cpu_to_le32(le32_to_cpu(d1->first_free) - 4); 657 d1->first_free = cpu_to_le32(le32_to_cpu(d1->first_free) - 4);
657 } else if (down) 658 } else if (down)
658 *(dnode_secno *) ((void *) del + del->length - 4) = down; 659 *(dnode_secno *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down);
659 } else goto endm; 660 } else goto endm;
660 if (!(de_cp = kmalloc(de_prev->length, GFP_NOFS))) { 661 if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) {
661 printk("HPFS: out of memory for dtree balancing\n"); 662 printk("HPFS: out of memory for dtree balancing\n");
662 hpfs_brelse4(&qbh1); 663 hpfs_brelse4(&qbh1);
663 goto endm; 664 goto endm;
664 } 665 }
665 hpfs_mark_4buffers_dirty(&qbh1); 666 hpfs_mark_4buffers_dirty(&qbh1);
666 hpfs_brelse4(&qbh1); 667 hpfs_brelse4(&qbh1);
667 memcpy(de_cp, de_prev, de_prev->length); 668 memcpy(de_cp, de_prev, le16_to_cpu(de_prev->length));
668 hpfs_delete_de(i->i_sb, dnode, de_prev); 669 hpfs_delete_de(i->i_sb, dnode, de_prev);
669 if (!de_prev->down) { 670 if (!de_prev->down) {
670 de_prev->length += 4; 671 de_prev->length = cpu_to_le16(le16_to_cpu(de_prev->length) + 4);
671 de_prev->down = 1; 672 de_prev->down = 1;
672 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) + 4); 673 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) + 4);
673 } 674 }
674 *(dnode_secno *) ((void *) de_prev + de_prev->length - 4) = ndown; 675 *(dnode_secno *) ((void *) de_prev + le16_to_cpu(de_prev->length) - 4) = cpu_to_le32(ndown);
675 hpfs_mark_4buffers_dirty(&qbh); 676 hpfs_mark_4buffers_dirty(&qbh);
676 hpfs_brelse4(&qbh); 677 hpfs_brelse4(&qbh);
677 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4); 678 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4);
678 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, ((loff_t)up << 4) | (p - 1)); 679 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, ((loff_t)up << 4) | (p - 1));
679 if (down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de), &qbh1))) { 680 if (down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de), &qbh1))) {
680 d1->up = ndown; 681 d1->up = cpu_to_le32(ndown);
681 hpfs_mark_4buffers_dirty(&qbh1); 682 hpfs_mark_4buffers_dirty(&qbh1);
682 hpfs_brelse4(&qbh1); 683 hpfs_brelse4(&qbh1);
683 } 684 }
@@ -744,8 +745,8 @@ void hpfs_count_dnodes(struct super_block *s, dnode_secno dno, int *n_dnodes,
744 ptr = 0; 745 ptr = 0;
745 go_up: 746 go_up:
746 if (!(dnode = hpfs_map_dnode(s, dno, &qbh))) return; 747 if (!(dnode = hpfs_map_dnode(s, dno, &qbh))) return;
747 if (hpfs_sb(s)->sb_chk) if (odno && odno != -1 && dnode->up != odno) 748 if (hpfs_sb(s)->sb_chk) if (odno && odno != -1 && le32_to_cpu(dnode->up) != odno)
748 hpfs_error(s, "hpfs_count_dnodes: bad up pointer; dnode %08x, down %08x points to %08x", odno, dno, dnode->up); 749 hpfs_error(s, "hpfs_count_dnodes: bad up pointer; dnode %08x, down %08x points to %08x", odno, dno, le32_to_cpu(dnode->up));
749 de = dnode_first_de(dnode); 750 de = dnode_first_de(dnode);
750 if (ptr) while(1) { 751 if (ptr) while(1) {
751 if (de->down) if (de_down_pointer(de) == ptr) goto process_de; 752 if (de->down) if (de_down_pointer(de) == ptr) goto process_de;
@@ -769,7 +770,7 @@ void hpfs_count_dnodes(struct super_block *s, dnode_secno dno, int *n_dnodes,
769 if (!de->first && !de->last && n_items) (*n_items)++; 770 if (!de->first && !de->last && n_items) (*n_items)++;
770 if ((de = de_next_de(de)) < dnode_end_de(dnode)) goto next_de; 771 if ((de = de_next_de(de)) < dnode_end_de(dnode)) goto next_de;
771 ptr = dno; 772 ptr = dno;
772 dno = dnode->up; 773 dno = le32_to_cpu(dnode->up);
773 if (dnode->root_dnode) { 774 if (dnode->root_dnode) {
774 hpfs_brelse4(&qbh); 775 hpfs_brelse4(&qbh);
775 return; 776 return;
@@ -817,8 +818,8 @@ dnode_secno hpfs_de_as_down_as_possible(struct super_block *s, dnode_secno dno)
817 return d; 818 return d;
818 if (!(de = map_nth_dirent(s, d, 1, &qbh, NULL))) return dno; 819 if (!(de = map_nth_dirent(s, d, 1, &qbh, NULL))) return dno;
819 if (hpfs_sb(s)->sb_chk) 820 if (hpfs_sb(s)->sb_chk)
820 if (up && ((struct dnode *)qbh.data)->up != up) 821 if (up && le32_to_cpu(((struct dnode *)qbh.data)->up) != up)
821 hpfs_error(s, "hpfs_de_as_down_as_possible: bad up pointer; dnode %08x, down %08x points to %08x", up, d, ((struct dnode *)qbh.data)->up); 822 hpfs_error(s, "hpfs_de_as_down_as_possible: bad up pointer; dnode %08x, down %08x points to %08x", up, d, le32_to_cpu(((struct dnode *)qbh.data)->up));
822 if (!de->down) { 823 if (!de->down) {
823 hpfs_brelse4(&qbh); 824 hpfs_brelse4(&qbh);
824 return d; 825 return d;
@@ -867,7 +868,7 @@ struct hpfs_dirent *map_pos_dirent(struct inode *inode, loff_t *posp,
867 /* Going up */ 868 /* Going up */
868 if (dnode->root_dnode) goto bail; 869 if (dnode->root_dnode) goto bail;
869 870
870 if (!(up_dnode = hpfs_map_dnode(inode->i_sb, dnode->up, &qbh0))) 871 if (!(up_dnode = hpfs_map_dnode(inode->i_sb, le32_to_cpu(dnode->up), &qbh0)))
871 goto bail; 872 goto bail;
872 873
873 end_up_de = dnode_end_de(up_dnode); 874 end_up_de = dnode_end_de(up_dnode);
@@ -875,16 +876,16 @@ struct hpfs_dirent *map_pos_dirent(struct inode *inode, loff_t *posp,
875 for (up_de = dnode_first_de(up_dnode); up_de < end_up_de; 876 for (up_de = dnode_first_de(up_dnode); up_de < end_up_de;
876 up_de = de_next_de(up_de)) { 877 up_de = de_next_de(up_de)) {
877 if (!(++c & 077)) hpfs_error(inode->i_sb, 878 if (!(++c & 077)) hpfs_error(inode->i_sb,
878 "map_pos_dirent: pos crossed dnode boundary; dnode = %08x", dnode->up); 879 "map_pos_dirent: pos crossed dnode boundary; dnode = %08x", le32_to_cpu(dnode->up));
879 if (up_de->down && de_down_pointer(up_de) == dno) { 880 if (up_de->down && de_down_pointer(up_de) == dno) {
880 *posp = ((loff_t) dnode->up << 4) + c; 881 *posp = ((loff_t) le32_to_cpu(dnode->up) << 4) + c;
881 hpfs_brelse4(&qbh0); 882 hpfs_brelse4(&qbh0);
882 return de; 883 return de;
883 } 884 }
884 } 885 }
885 886
886 hpfs_error(inode->i_sb, "map_pos_dirent: pointer to dnode %08x not found in parent dnode %08x", 887 hpfs_error(inode->i_sb, "map_pos_dirent: pointer to dnode %08x not found in parent dnode %08x",
887 dno, dnode->up); 888 dno, le32_to_cpu(dnode->up));
888 hpfs_brelse4(&qbh0); 889 hpfs_brelse4(&qbh0);
889 890
890 bail: 891 bail:
@@ -1010,17 +1011,17 @@ struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
1010 /*name2[15] = 0xff;*/ 1011 /*name2[15] = 0xff;*/
1011 name1len = 15; name2len = 256; 1012 name1len = 15; name2len = 256;
1012 } 1013 }
1013 if (!(upf = hpfs_map_fnode(s, f->up, &bh))) { 1014 if (!(upf = hpfs_map_fnode(s, le32_to_cpu(f->up), &bh))) {
1014 kfree(name2); 1015 kfree(name2);
1015 return NULL; 1016 return NULL;
1016 } 1017 }
1017 if (!upf->dirflag) { 1018 if (!upf->dirflag) {
1018 brelse(bh); 1019 brelse(bh);
1019 hpfs_error(s, "fnode %08x has non-directory parent %08x", fno, f->up); 1020 hpfs_error(s, "fnode %08x has non-directory parent %08x", fno, le32_to_cpu(f->up));
1020 kfree(name2); 1021 kfree(name2);
1021 return NULL; 1022 return NULL;
1022 } 1023 }
1023 dno = upf->u.external[0].disk_secno; 1024 dno = le32_to_cpu(upf->u.external[0].disk_secno);
1024 brelse(bh); 1025 brelse(bh);
1025 go_down: 1026 go_down:
1026 downd = 0; 1027 downd = 0;
@@ -1042,7 +1043,7 @@ struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
1042 return NULL; 1043 return NULL;
1043 } 1044 }
1044 next_de: 1045 next_de:
1045 if (de->fnode == fno) { 1046 if (le32_to_cpu(de->fnode) == fno) {
1046 kfree(name2); 1047 kfree(name2);
1047 return de; 1048 return de;
1048 } 1049 }
@@ -1058,7 +1059,7 @@ struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
1058 goto go_down; 1059 goto go_down;
1059 } 1060 }
1060 f: 1061 f:
1061 if (de->fnode == fno) { 1062 if (le32_to_cpu(de->fnode) == fno) {
1062 kfree(name2); 1063 kfree(name2);
1063 return de; 1064 return de;
1064 } 1065 }
@@ -1067,7 +1068,7 @@ struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
1067 if ((de = de_next_de(de)) < de_end) goto next_de; 1068 if ((de = de_next_de(de)) < de_end) goto next_de;
1068 if (d->root_dnode) goto not_found; 1069 if (d->root_dnode) goto not_found;
1069 downd = dno; 1070 downd = dno;
1070 dno = d->up; 1071 dno = le32_to_cpu(d->up);
1071 hpfs_brelse4(qbh); 1072 hpfs_brelse4(qbh);
1072 if (hpfs_sb(s)->sb_chk) 1073 if (hpfs_sb(s)->sb_chk)
1073 if (hpfs_stop_cycles(s, downd, &d1, &d2, "map_fnode_dirent #2")) { 1074 if (hpfs_stop_cycles(s, downd, &d1, &d2, "map_fnode_dirent #2")) {