Lines Matching +full:de +full:- +full:be
1 // SPDX-License-Identifier: GPL-2.0
5 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
7 * handling directory dnode tree - adding, deleteing & searching for dirents
14 struct hpfs_dirent *de; in get_pos() local
17 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) { in get_pos()
18 if (de == fde) return ((loff_t) le32_to_cpu(d->self) << 4) | (loff_t)i; in get_pos()
22 return ((loff_t)le32_to_cpu(d->self) << 4) | (loff_t)1; in get_pos()
31 if (hpfs_inode->i_rddir_off) in hpfs_add_pos()
32 for (; hpfs_inode->i_rddir_off[i]; i++) in hpfs_add_pos()
33 if (hpfs_inode->i_rddir_off[i] == pos) in hpfs_add_pos()
39 return -ENOMEM; in hpfs_add_pos()
41 if (hpfs_inode->i_rddir_off) { in hpfs_add_pos()
42 memcpy(ppos, hpfs_inode->i_rddir_off, i * sizeof(loff_t)); in hpfs_add_pos()
43 kfree(hpfs_inode->i_rddir_off); in hpfs_add_pos()
45 hpfs_inode->i_rddir_off = ppos; in hpfs_add_pos()
47 hpfs_inode->i_rddir_off[i] = pos; in hpfs_add_pos()
48 hpfs_inode->i_rddir_off[i + 1] = NULL; in hpfs_add_pos()
57 if (!hpfs_inode->i_rddir_off) goto not_f; in hpfs_del_pos()
58 for (i = hpfs_inode->i_rddir_off; *i; i++) if (*i == pos) goto fnd; in hpfs_del_pos()
62 *i = *(j - 1); in hpfs_del_pos()
63 *(j - 1) = NULL; in hpfs_del_pos()
64 if (j - 1 == hpfs_inode->i_rddir_off) { in hpfs_del_pos()
65 kfree(hpfs_inode->i_rddir_off); in hpfs_del_pos()
66 hpfs_inode->i_rddir_off = NULL; in hpfs_del_pos()
70 /*pr_warn("position pointer %p->%08x not found\n", in hpfs_del_pos()
81 if (!hpfs_inode->i_rddir_off) return; in for_all_poss()
82 for (i = hpfs_inode->i_rddir_off; *i; i++) (*f)(*i, p1, p2); in for_all_poss()
111 int n = (*p & 0x3f) - c; in hpfs_pos_del()
113 pr_err("%s(): %08x - %d\n", in hpfs_pos_del()
122 struct hpfs_dirent *de, *de_end, *dee = NULL, *deee = NULL; in dnode_pre_last_de() local
124 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) { in dnode_pre_last_de()
125 deee = dee; dee = de; in dnode_pre_last_de()
132 struct hpfs_dirent *de, *de_end, *dee = NULL; in dnode_last_de() local
134 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) { in dnode_last_de()
135 dee = de; in dnode_last_de()
142 struct hpfs_dirent *de; in set_last_pointer() local
143 if (!(de = dnode_last_de(d))) { in set_last_pointer()
144 hpfs_error(s, "set_last_pointer: empty dnode %08x", le32_to_cpu(d->self)); in set_last_pointer()
147 if (hpfs_sb(s)->sb_chk) { in set_last_pointer()
148 if (de->down) { in set_last_pointer()
150 le32_to_cpu(d->self), de_down_pointer(de)); in set_last_pointer()
153 if (le16_to_cpu(de->length) != 32) { in set_last_pointer()
154 hpfs_error(s, "set_last_pointer: bad last dirent in dnode %08x", le32_to_cpu(d->self)); in set_last_pointer()
159 le32_add_cpu(&d->first_free, 4); in set_last_pointer()
160 if (le32_to_cpu(d->first_free) > 2048) { in set_last_pointer()
161 hpfs_error(s, "set_last_pointer: too long dnode %08x", le32_to_cpu(d->self)); in set_last_pointer()
162 le32_add_cpu(&d->first_free, -4); in set_last_pointer()
165 de->length = cpu_to_le16(36); in set_last_pointer()
166 de->down = 1; in set_last_pointer()
167 *(__le32 *)((char *)de + 32) = cpu_to_le32(ptr); in set_last_pointer()
177 struct hpfs_dirent *de; in hpfs_add_de() local
180 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) { in hpfs_add_de()
181 int c = hpfs_compare_names(s, name, namelen, de->name, de->namelen, de->last); in hpfs_add_de()
183 hpfs_error(s, "name (%c,%d) already exists in dnode %08x", *name, namelen, le32_to_cpu(d->self)); in hpfs_add_de()
188 memmove((char *)de + d_size, de, (char *)de_end - (char *)de); in hpfs_add_de()
189 memset(de, 0, d_size); in hpfs_add_de()
191 *(__le32 *)((char *)de + d_size - 4) = cpu_to_le32(down_ptr); in hpfs_add_de()
192 de->down = 1; in hpfs_add_de()
194 de->length = cpu_to_le16(d_size); in hpfs_add_de()
195 de->not_8x3 = hpfs_is_name_long(name, namelen); in hpfs_add_de()
196 de->namelen = namelen; in hpfs_add_de()
197 memcpy(de->name, name, namelen); in hpfs_add_de()
198 le32_add_cpu(&d->first_free, d_size); in hpfs_add_de()
199 return de; in hpfs_add_de()
205 struct hpfs_dirent *de) in hpfs_delete_de() argument
207 if (de->last) { in hpfs_delete_de()
208 hpfs_error(s, "attempt to delete last dirent in dnode %08x", le32_to_cpu(d->self)); in hpfs_delete_de()
211 d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) - le16_to_cpu(de->length)); in hpfs_delete_de()
212 memmove(de, de_next_de(de), le32_to_cpu(d->first_free) + (char *)d - (char *)de); in hpfs_delete_de()
217 struct hpfs_dirent *de; in fix_up_ptrs() local
219 dnode_secno dno = le32_to_cpu(d->self); in fix_up_ptrs()
220 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) in fix_up_ptrs()
221 if (de->down) { in fix_up_ptrs()
224 if ((dd = hpfs_map_dnode(s, de_down_pointer(de), &qbh))) { in fix_up_ptrs()
225 if (le32_to_cpu(dd->up) != dno || dd->root_dnode) { in fix_up_ptrs()
226 dd->up = cpu_to_le32(dno); in fix_up_ptrs()
227 dd->root_dnode = 0; in fix_up_ptrs()
244 struct hpfs_dirent *de; in hpfs_add_to_dnode() local
258 hpfs_error(i->i_sb, "%s(): namelen == %d", __func__, namelen); in hpfs_add_to_dnode()
263 if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) { in hpfs_add_to_dnode()
269 if (hpfs_sb(i->i_sb)->sb_chk) in hpfs_add_to_dnode()
270 if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_to_dnode")) { in hpfs_add_to_dnode()
276 if (le32_to_cpu(d->first_free) + de_size(namelen, down_ptr) <= 2048) { in hpfs_add_to_dnode()
278 copy_de(de=hpfs_add_de(i->i_sb, d, name, namelen, down_ptr), new_de); in hpfs_add_to_dnode()
279 t = get_pos(d, de); in hpfs_add_to_dnode()
292 not be any error while splitting dnodes, otherwise the in hpfs_add_to_dnode()
294 be lost. */ in hpfs_add_to_dnode()
300 memcpy(nd, d, le32_to_cpu(d->first_free)); in hpfs_add_to_dnode()
301 copy_de(de = hpfs_add_de(i->i_sb, nd, name, namelen, down_ptr), new_de); in hpfs_add_to_dnode()
302 for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1); in hpfs_add_to_dnode()
303 h = ((char *)dnode_last_de(nd) - (char *)nd) / 2 + 10; in hpfs_add_to_dnode()
304 if (!(ad = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &adno, &qbh1))) { in hpfs_add_to_dnode()
305 hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted"); in hpfs_add_to_dnode()
311 i->i_size += 2048; in hpfs_add_to_dnode()
312 i->i_blocks += 4; in hpfs_add_to_dnode()
314 for (de = dnode_first_de(nd); (char *)de_next_de(de) - (char *)nd < h; de = de_next_de(de)) { in hpfs_add_to_dnode()
315 copy_de(hpfs_add_de(i->i_sb, ad, de->name, de->namelen, de->down ? de_down_pointer(de) : 0), de); in hpfs_add_to_dnode()
319 copy_de(new_de = &nde, de); in hpfs_add_to_dnode()
320 memcpy(nname, de->name, de->namelen); in hpfs_add_to_dnode()
322 namelen = de->namelen; in hpfs_add_to_dnode()
325 set_last_pointer(i->i_sb, ad, de->down ? de_down_pointer(de) : 0); in hpfs_add_to_dnode()
326 de = de_next_de(de); in hpfs_add_to_dnode()
327 memmove((char *)nd + 20, de, le32_to_cpu(nd->first_free) + (char *)nd - (char *)de); in hpfs_add_to_dnode()
328 le32_add_cpu(&nd->first_free, -((char *)de - (char *)nd - 20)); in hpfs_add_to_dnode()
329 memcpy(d, nd, le32_to_cpu(nd->first_free)); in hpfs_add_to_dnode()
331 fix_up_ptrs(i->i_sb, ad); in hpfs_add_to_dnode()
332 if (!d->root_dnode) { in hpfs_add_to_dnode()
333 ad->up = d->up; in hpfs_add_to_dnode()
334 dno = le32_to_cpu(ad->up); in hpfs_add_to_dnode()
341 if (!(rd = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &rdno, &qbh2))) { in hpfs_add_to_dnode()
342 hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted"); in hpfs_add_to_dnode()
349 i->i_size += 2048; in hpfs_add_to_dnode()
350 i->i_blocks += 4; in hpfs_add_to_dnode()
351 rd->root_dnode = 1; in hpfs_add_to_dnode()
352 rd->up = d->up; in hpfs_add_to_dnode()
353 if (!(fnode = hpfs_map_fnode(i->i_sb, le32_to_cpu(d->up), &bh))) { in hpfs_add_to_dnode()
354 hpfs_free_dnode(i->i_sb, rdno); in hpfs_add_to_dnode()
362 fnode->u.external[0].disk_secno = cpu_to_le32(rdno); in hpfs_add_to_dnode()
365 hpfs_i(i)->i_dno = rdno; in hpfs_add_to_dnode()
366 d->up = ad->up = cpu_to_le32(rdno); in hpfs_add_to_dnode()
367 d->root_dnode = ad->root_dnode = 0; in hpfs_add_to_dnode()
373 set_last_pointer(i->i_sb, rd, dno); in hpfs_add_to_dnode()
384 * I hope, now it's finally bug-free.
393 struct hpfs_dirent *de, *de_end; in hpfs_add_dirent() local
398 dno = hpfs_inode->i_dno; in hpfs_add_dirent()
400 if (hpfs_sb(i->i_sb)->sb_chk) in hpfs_add_dirent()
401 if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_dirent")) return 1; in hpfs_add_dirent()
402 if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 1; in hpfs_add_dirent()
404 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) { in hpfs_add_dirent()
405 if (!(c = hpfs_compare_names(i->i_sb, name, namelen, de->name, de->namelen, de->last))) { in hpfs_add_dirent()
407 return -1; in hpfs_add_dirent()
410 if (de->down) { in hpfs_add_dirent()
411 dno = de_down_pointer(de); in hpfs_add_dirent()
419 if (hpfs_check_free_dnodes(i->i_sb, FREE_DNODES_ADD)) { in hpfs_add_dirent()
430 * Return the dnode we moved from (to be checked later if it's empty)
439 struct hpfs_dirent *de, *nde; in move_to_top() local
445 if (hpfs_sb(i->i_sb)->sb_chk) in move_to_top()
446 if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "move_to_top")) in move_to_top()
448 if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 0; in move_to_top()
449 if (hpfs_sb(i->i_sb)->sb_chk) { in move_to_top()
450 if (le32_to_cpu(dnode->up) != chk_up) { in move_to_top()
451 hpfs_error(i->i_sb, "move_to_top: up pointer from %08x should be %08x, is %08x", in move_to_top()
452 dno, chk_up, le32_to_cpu(dnode->up)); in move_to_top()
458 if (!(de = dnode_last_de(dnode))) { in move_to_top()
459 hpfs_error(i->i_sb, "move_to_top: dnode %08x has no last de", dno); in move_to_top()
463 if (!de->down) break; in move_to_top()
464 dno = de_down_pointer(de); in move_to_top()
467 while (!(de = dnode_pre_last_de(dnode))) { in move_to_top()
468 dnode_secno up = le32_to_cpu(dnode->up); in move_to_top()
470 hpfs_free_dnode(i->i_sb, dno); in move_to_top()
471 i->i_size -= 2048; in move_to_top()
472 i->i_blocks -= 4; in move_to_top()
475 if (!(dnode = hpfs_map_dnode(i->i_sb, up, &qbh))) return 0; in move_to_top()
476 if (dnode->root_dnode) { in move_to_top()
477 hpfs_error(i->i_sb, "move_to_top: got to root_dnode while moving from %08x to %08x", from, to); in move_to_top()
481 de = dnode_last_de(dnode); in move_to_top()
482 if (!de || !de->down) { in move_to_top()
483 hpfs_error(i->i_sb, "move_to_top: dnode %08x doesn't point down to %08x", up, dno); in move_to_top()
487 le32_add_cpu(&dnode->first_free, -4); in move_to_top()
488 le16_add_cpu(&de->length, -4); in move_to_top()
489 de->down = 0; in move_to_top()
493 t = get_pos(dnode, de); in move_to_top()
496 if (!(nde = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) { in move_to_top()
497 hpfs_error(i->i_sb, "out of memory for dirent - directory will be corrupted"); in move_to_top()
501 memcpy(nde, de, le16_to_cpu(de->length)); in move_to_top()
502 ddno = de->down ? de_down_pointer(de) : 0; in move_to_top()
503 hpfs_delete_de(i->i_sb, dnode, de); in move_to_top()
504 set_last_pointer(i->i_sb, dnode, ddno); in move_to_top()
507 a = hpfs_add_to_dnode(i, to, nde->name, nde->namelen, nde, from); in move_to_top()
525 struct hpfs_dirent *de; in delete_empty_dnode() local
528 if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "delete_empty_dnode")) return; in delete_empty_dnode()
529 if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return; in delete_empty_dnode()
530 if (le32_to_cpu(dnode->first_free) > 56) goto end; in delete_empty_dnode()
531 if (le32_to_cpu(dnode->first_free) == 52 || le32_to_cpu(dnode->first_free) == 56) { in delete_empty_dnode()
533 int root = dnode->root_dnode; in delete_empty_dnode()
534 up = le32_to_cpu(dnode->up); in delete_empty_dnode()
535 de = dnode_first_de(dnode); in delete_empty_dnode()
536 down = de->down ? de_down_pointer(de) : 0; in delete_empty_dnode()
537 if (hpfs_sb(i->i_sb)->sb_chk) if (root && !down) { in delete_empty_dnode()
538 hpfs_error(i->i_sb, "delete_empty_dnode: root dnode %08x is empty", dno); in delete_empty_dnode()
542 hpfs_free_dnode(i->i_sb, dno); in delete_empty_dnode()
543 i->i_size -= 2048; in delete_empty_dnode()
544 i->i_blocks -= 4; in delete_empty_dnode()
550 if (hpfs_sb(i->i_sb)->sb_chk) in delete_empty_dnode()
551 if (up != i->i_ino) { in delete_empty_dnode()
552 hpfs_error(i->i_sb, in delete_empty_dnode()
553 "bad pointer to fnode, dnode %08x, pointing to %08x, should be %08lx", in delete_empty_dnode()
555 (unsigned long)i->i_ino); in delete_empty_dnode()
558 if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) { in delete_empty_dnode()
559 d1->up = cpu_to_le32(up); in delete_empty_dnode()
560 d1->root_dnode = 1; in delete_empty_dnode()
564 if ((fnode = hpfs_map_fnode(i->i_sb, up, &bh))) { in delete_empty_dnode()
565 fnode->u.external[0].disk_secno = cpu_to_le32(down); in delete_empty_dnode()
569 hpfs_inode->i_dno = down; in delete_empty_dnode()
573 if (!(dnode = hpfs_map_dnode(i->i_sb, up, &qbh))) return; in delete_empty_dnode()
576 for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de), p++) in delete_empty_dnode()
577 if (de->down) if (de_down_pointer(de) == dno) goto fnd; in delete_empty_dnode()
578 hpfs_error(i->i_sb, "delete_empty_dnode: pointer to dnode %08x not found in dnode %08x", dno, up); in delete_empty_dnode()
583 de->down = 0; in delete_empty_dnode()
584 le16_add_cpu(&de->length, -4); in delete_empty_dnode()
585 le32_add_cpu(&dnode->first_free, -4); in delete_empty_dnode()
586 memmove(de_next_de(de), (char *)de_next_de(de) + 4, in delete_empty_dnode()
587 (char *)dnode + le32_to_cpu(dnode->first_free) - (char *)de_next_de(de)); in delete_empty_dnode()
591 *(dnode_secno *) ((void *) de + le16_to_cpu(de->length) - 4) = down; in delete_empty_dnode()
592 if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) { in delete_empty_dnode()
593 d1->up = cpu_to_le32(up); in delete_empty_dnode()
599 …hpfs_error(i->i_sb, "delete_empty_dnode: dnode %08x, first_free == %03x", dno, le32_to_cpu(dnode->… in delete_empty_dnode()
603 if (!de->last) { in delete_empty_dnode()
604 struct hpfs_dirent *de_next = de_next_de(de); in delete_empty_dnode()
608 if (!de_next->down) goto endm; in delete_empty_dnode()
610 if (!(de_cp = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) { in delete_empty_dnode()
614 memcpy(de_cp, de, le16_to_cpu(de->length)); in delete_empty_dnode()
615 hpfs_delete_de(i->i_sb, dnode, de); in delete_empty_dnode()
620 if (de_cp->down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de_cp), &qbh1))) { in delete_empty_dnode()
621 d1->up = cpu_to_le32(ndown); in delete_empty_dnode()
625 …hpfs_add_to_dnode(i, ndown, de_cp->name, de_cp->namelen, de_cp, de_cp->down ? de_down_pointer(de_c… in delete_empty_dnode()
626 /*pr_info("UP-TO-DNODE: %08x (ndown = %08x, down = %08x, dno = %08x)\n", in delete_empty_dnode()
638 hpfs_error(i->i_sb, "delete_empty_dnode: empty dnode %08x", up); in delete_empty_dnode()
644 if (!de_prev->down) goto endm; in delete_empty_dnode()
646 if ((d1 = hpfs_map_dnode(i->i_sb, ndown, &qbh1))) { in delete_empty_dnode()
648 dlp = del->down ? de_down_pointer(del) : 0; in delete_empty_dnode()
650 if (le32_to_cpu(d1->first_free) > 2044) { in delete_empty_dnode()
651 if (hpfs_sb(i->i_sb)->sb_chk >= 2) { in delete_empty_dnode()
658 if (hpfs_sb(i->i_sb)->sb_chk >= 2) { in delete_empty_dnode()
662 le16_add_cpu(&del->length, 4); in delete_empty_dnode()
663 del->down = 1; in delete_empty_dnode()
664 le32_add_cpu(&d1->first_free, 4); in delete_empty_dnode()
667 le16_add_cpu(&del->length, -4); in delete_empty_dnode()
668 del->down = 0; in delete_empty_dnode()
669 le32_add_cpu(&d1->first_free, -4); in delete_empty_dnode()
671 *(__le32 *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down); in delete_empty_dnode()
673 if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) { in delete_empty_dnode()
680 memcpy(de_cp, de_prev, le16_to_cpu(de_prev->length)); in delete_empty_dnode()
681 hpfs_delete_de(i->i_sb, dnode, de_prev); in delete_empty_dnode()
682 if (!de_prev->down) { in delete_empty_dnode()
683 le16_add_cpu(&de_prev->length, 4); in delete_empty_dnode()
684 de_prev->down = 1; in delete_empty_dnode()
685 le32_add_cpu(&dnode->first_free, 4); in delete_empty_dnode()
687 *(__le32 *) ((void *) de_prev + le16_to_cpu(de_prev->length) - 4) = cpu_to_le32(ndown); in delete_empty_dnode()
690 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4); in delete_empty_dnode()
691 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, ((loff_t)up << 4) | (p - 1)); in delete_empty_dnode()
692 if (down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de), &qbh1))) { in delete_empty_dnode()
693 d1->up = cpu_to_le32(ndown); in delete_empty_dnode()
697 hpfs_add_to_dnode(i, ndown, de_cp->name, de_cp->namelen, de_cp, dlp); in delete_empty_dnode()
711 int hpfs_remove_dirent(struct inode *i, dnode_secno dno, struct hpfs_dirent *de, in hpfs_remove_dirent() argument
714 struct dnode *dnode = qbh->data; in hpfs_remove_dirent()
717 if (de->first || de->last) { in hpfs_remove_dirent()
718 …hpfs_error(i->i_sb, "hpfs_remove_dirent: attempt to delete first or last dirent in dnode %08x", dn… in hpfs_remove_dirent()
722 if (de->down) down = de_down_pointer(de); in hpfs_remove_dirent()
723 if (depth && (de->down || (de == dnode_first_de(dnode) && de_next_de(de)->last))) { in hpfs_remove_dirent()
724 if (hpfs_check_free_dnodes(i->i_sb, FREE_DNODES_DEL)) { in hpfs_remove_dirent()
729 for_all_poss(i, hpfs_pos_del, (t = get_pos(dnode, de)) + 1, 1); in hpfs_remove_dirent()
730 hpfs_delete_de(i->i_sb, dnode, de); in hpfs_remove_dirent()
748 struct hpfs_dirent *de; in hpfs_count_dnodes() local
754 if (hpfs_sb(s)->sb_chk) in hpfs_count_dnodes()
759 if (hpfs_sb(s)->sb_chk) if (odno && odno != -1 && le32_to_cpu(dnode->up) != odno) in hpfs_count_dnodes()
760 …_dnodes: bad up pointer; dnode %08x, down %08x points to %08x", odno, dno, le32_to_cpu(dnode->up)); in hpfs_count_dnodes()
761 de = dnode_first_de(dnode); in hpfs_count_dnodes()
763 if (de->down) if (de_down_pointer(de) == ptr) goto process_de; in hpfs_count_dnodes()
764 if (de->last) { in hpfs_count_dnodes()
770 de = de_next_de(de); in hpfs_count_dnodes()
773 if (de->down) { in hpfs_count_dnodes()
775 dno = de_down_pointer(de); in hpfs_count_dnodes()
780 if (!de->first && !de->last && de->directory && n_subdirs) (*n_subdirs)++; in hpfs_count_dnodes()
781 if (!de->first && !de->last && n_items) (*n_items)++; in hpfs_count_dnodes()
782 if ((de = de_next_de(de)) < dnode_end_de(dnode)) goto next_de; in hpfs_count_dnodes()
784 dno = le32_to_cpu(dnode->up); in hpfs_count_dnodes()
785 if (dnode->root_dnode) { in hpfs_count_dnodes()
790 if (hpfs_sb(s)->sb_chk) in hpfs_count_dnodes()
792 odno = -1; in hpfs_count_dnodes()
800 struct hpfs_dirent *de, *de_end; in map_nth_dirent() local
805 de = dnode_first_de(dnode); in map_nth_dirent()
807 for (i = 1; de < de_end; i++, de = de_next_de(de)) { in map_nth_dirent()
809 return de; in map_nth_dirent()
811 if (de->last) break; in map_nth_dirent()
823 struct hpfs_dirent *de; in hpfs_de_as_down_as_possible() local
827 if (hpfs_sb(s)->sb_chk) in hpfs_de_as_down_as_possible()
830 if (!(de = map_nth_dirent(s, d, 1, &qbh, NULL))) return dno; in hpfs_de_as_down_as_possible()
831 if (hpfs_sb(s)->sb_chk) in hpfs_de_as_down_as_possible()
832 if (up && le32_to_cpu(((struct dnode *)qbh.data)->up) != up) in hpfs_de_as_down_as_possible()
833 …ointer; dnode %08x, down %08x points to %08x", up, d, le32_to_cpu(((struct dnode *)qbh.data)->up)); in hpfs_de_as_down_as_possible()
834 if (!de->down) { in hpfs_de_as_down_as_possible()
839 d = de_down_pointer(de); in hpfs_de_as_down_as_possible()
850 struct hpfs_dirent *de, *d; in map_pos_dirent() local
860 if (!(de = map_nth_dirent(inode->i_sb, dno, pos, qbh, &dnode))) in map_pos_dirent()
864 if ((d = de_next_de(de)) < dnode_end_de(dnode)) { in map_pos_dirent()
866 hpfs_error(inode->i_sb, in map_pos_dirent()
872 if (d->down) { in map_pos_dirent()
873 *posp = ((loff_t) hpfs_de_as_down_as_possible(inode->i_sb, de_down_pointer(d)) << 4) + 1; in map_pos_dirent()
876 return de; in map_pos_dirent()
880 if (dnode->root_dnode) goto bail; in map_pos_dirent()
882 if (!(up_dnode = hpfs_map_dnode(inode->i_sb, le32_to_cpu(dnode->up), &qbh0))) in map_pos_dirent()
889 if (!(++c & 077)) hpfs_error(inode->i_sb, in map_pos_dirent()
890 "map_pos_dirent: pos crossed dnode boundary; dnode = %08x", le32_to_cpu(dnode->up)); in map_pos_dirent()
891 if (up_de->down && de_down_pointer(up_de) == dno) { in map_pos_dirent()
892 *posp = ((loff_t) le32_to_cpu(dnode->up) << 4) + c; in map_pos_dirent()
894 return de; in map_pos_dirent()
898 hpfs_error(inode->i_sb, "map_pos_dirent: pointer to dnode %08x not found in parent dnode %08x", in map_pos_dirent()
899 dno, le32_to_cpu(dnode->up)); in map_pos_dirent()
904 return de; in map_pos_dirent()
914 struct hpfs_dirent *de; in map_dirent() local
918 if (!S_ISDIR(inode->i_mode)) hpfs_error(inode->i_sb, "map_dirent: not a directory\n"); in map_dirent()
920 if (hpfs_sb(inode->i_sb)->sb_chk) in map_dirent()
921 if (hpfs_stop_cycles(inode->i_sb, dno, &c1, &c2, "map_dirent")) return NULL; in map_dirent()
922 if (!(dnode = hpfs_map_dnode(inode->i_sb, dno, qbh))) return NULL; in map_dirent()
925 for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de)) { in map_dirent()
926 int t = hpfs_compare_names(inode->i_sb, name, len, de->name, de->namelen, de->last); in map_dirent()
929 return de; in map_dirent()
932 if (de->down) { in map_dirent()
933 dno = de_down_pointer(de); in map_dirent()
954 struct hpfs_dirent *de; in hpfs_remove_dtree() local
958 de = dnode_first_de(dnode); in hpfs_remove_dtree()
959 if (de->last) { in hpfs_remove_dtree()
960 if (de->down) d1 = de_down_pointer(de); in hpfs_remove_dtree()
967 if (!de->first) goto error; in hpfs_remove_dtree()
968 d1 = de->down ? de_down_pointer(de) : 0; in hpfs_remove_dtree()
969 de = de_next_de(de); in hpfs_remove_dtree()
970 if (!de->last) goto error; in hpfs_remove_dtree()
971 d2 = de->down ? de_down_pointer(de) : 0; in hpfs_remove_dtree()
977 de = dnode_first_de(dnode); in hpfs_remove_dtree()
978 if (!de->last) goto error; in hpfs_remove_dtree()
979 d1 = de->down ? de_down_pointer(de) : 0; in hpfs_remove_dtree()
994 * Find dirent for specified fnode. Use truncated 15-char name in fnode as
1008 struct hpfs_dirent *de, *de_end; in map_fnode_dirent() local
1012 name1 = f->name; in map_fnode_dirent()
1017 if (f->len <= 15) in map_fnode_dirent()
1018 memcpy(name2, name1, name1len = name2len = f->len); in map_fnode_dirent()
1021 memset(name2 + 15, 0xff, 256 - 15); in map_fnode_dirent()
1025 if (!(upf = hpfs_map_fnode(s, le32_to_cpu(f->up), &bh))) { in map_fnode_dirent()
1031 hpfs_error(s, "fnode %08x has non-directory parent %08x", fno, le32_to_cpu(f->up)); in map_fnode_dirent()
1035 dno = le32_to_cpu(upf->u.external[0].disk_secno); in map_fnode_dirent()
1045 de = dnode_first_de(d); in map_fnode_dirent()
1047 while (de < de_end) { in map_fnode_dirent()
1048 if (de->down) if (de_down_pointer(de) == downd) goto f; in map_fnode_dirent()
1049 de = de_next_de(de); in map_fnode_dirent()
1057 if (le32_to_cpu(de->fnode) == fno) { in map_fnode_dirent()
1059 return de; in map_fnode_dirent()
1061 c = hpfs_compare_names(s, name1, name1len, de->name, de->namelen, de->last); in map_fnode_dirent()
1062 if (c < 0 && de->down) { in map_fnode_dirent()
1063 dno = de_down_pointer(de); in map_fnode_dirent()
1065 if (hpfs_sb(s)->sb_chk) in map_fnode_dirent()
1073 if (le32_to_cpu(de->fnode) == fno) { in map_fnode_dirent()
1075 return de; in map_fnode_dirent()
1077 c = hpfs_compare_names(s, name2, name2len, de->name, de->namelen, de->last); in map_fnode_dirent()
1078 if (c < 0 && !de->last) goto not_found; in map_fnode_dirent()
1079 if ((de = de_next_de(de)) < de_end) goto next_de; in map_fnode_dirent()
1080 if (d->root_dnode) goto not_found; in map_fnode_dirent()
1082 dno = le32_to_cpu(d->up); in map_fnode_dirent()
1084 if (hpfs_sb(s)->sb_chk) in map_fnode_dirent()