16 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
20 printk(
"HPFS: get_pos: not_found\n");
35 printk(
"HPFS: out of memory for position list\n");
54 for (i = hpfs_inode->
i_rddir_off; *i; i++)
if (*i == pos)
goto fnd;
57 for (j = i + 1; *
j; j++) ;
70 static void for_all_poss(
struct inode *
inode,
void (*
f)(loff_t *, loff_t, loff_t),
81 static void hpfs_pos_subst(loff_t *
p, loff_t
f, loff_t
t)
91 static void hpfs_pos_ins(loff_t *p, loff_t d, loff_t
c)
93 if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
94 int n = (*p & 0x3f) + c;
95 if (n > 0x3f)
printk(
"HPFS: hpfs_pos_ins: %08x + %d\n", (
int)*p, (
int)c >> 8);
96 else *p = (*p & ~0x3f) | n;
100 static void hpfs_pos_del(loff_t *p, loff_t d, loff_t c)
102 if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
103 int n = (*p & 0x3f) - c;
104 if (n < 1)
printk(
"HPFS: hpfs_pos_ins: %08x - %d\n", (
int)*p, (
int)c >> 8);
105 else *p = (*p & ~0x3f) | n;
112 de_end = dnode_end_de(d);
113 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
114 deee = dee; dee = de;
122 de_end = dnode_end_de(d);
123 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
132 if (!(de = dnode_last_de(d))) {
136 if (hpfs_sb(s)->sb_chk) {
138 hpfs_error(s,
"set_last_pointer: dnode %08x has already last pointer %08x",
163 const unsigned char *
name,
168 unsigned d_size = de_size(namelen, down_ptr);
169 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
177 memmove((
char *)de + d_size, de, (
char *)de_end - (
char *)de);
209 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de))
226 static int hpfs_add_to_dnode(
struct inode *i,
dnode_secno dno,
235 unsigned char *nname;
238 struct buffer_head *bh;
242 printk(
"HPFS: out of memory, can't add to dnode\n");
246 if (namelen >= 256) {
258 if (hpfs_sb(i->
i_sb)->sb_chk)
269 for_all_poss(i, hpfs_pos_ins, t, 1);
270 for_all_poss(i, hpfs_pos_subst, 4, t);
271 for_all_poss(i, hpfs_pos_subst, 5, t + 1);
284 printk(
"HPFS: out of memory for dnode splitting\n");
290 copy_de(de =
hpfs_add_de(i->
i_sb, nd, name, namelen, down_ptr), new_de);
291 for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1);
292 h = ((
char *)dnode_last_de(nd) - (
char *)nd) / 2 + 10;
294 hpfs_error(i->
i_sb,
"unable to alloc dnode - dnode tree will be corrupted");
303 for (de = dnode_first_de(nd); (
char *)de_next_de(de) - (
char *)nd < h; de = de_next_de(de)) {
305 for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, ((loff_t)adno << 4) | pos);
308 copy_de(new_de = &nde, de);
312 for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, 4);
314 set_last_pointer(i->
i_sb, ad, de->
down ? de_down_pointer(de) : 0);
317 le32_add_cpu(&nd->first_free, -((
char *)de - (
char *)nd - 20));
319 for_all_poss(i, hpfs_pos_del, (loff_t)dno << 4, pos);
320 fix_up_ptrs(i->
i_sb, ad);
331 hpfs_error(i->
i_sb,
"unable to alloc dnode - dnode tree will be corrupted");
354 hpfs_i(i)->i_dno = rdno;
362 set_last_pointer(i->
i_sb, rd, dno);
377 const unsigned char *name,
unsigned namelen,
387 dno = hpfs_inode->
i_dno;
389 if (hpfs_sb(i->
i_sb)->sb_chk)
392 de_end = dnode_end_de(d);
393 for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
400 dno = de_down_pointer(de);
413 c = hpfs_add_to_dnode(i, dno, name, namelen, new_de, 0);
435 if (hpfs_sb(i->
i_sb)->sb_chk)
439 if (hpfs_sb(i->
i_sb)->sb_chk) {
441 hpfs_error(i->
i_sb,
"move_to_top: up pointer from %08x should be %08x, is %08x",
448 if (!(de = dnode_last_de(dnode))) {
449 hpfs_error(i->
i_sb,
"move_to_top: dnode %08x has no last de", dno);
453 if (!de->
down)
break;
454 dno = de_down_pointer(de);
457 while (!(de = dnode_pre_last_de(dnode))) {
463 for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, 5);
464 if (up == to)
return to;
467 hpfs_error(i->
i_sb,
"move_to_top: got to root_dnode while moving from %08x to %08x", from, to);
471 de = dnode_last_de(dnode);
472 if (!de || !de->
down) {
473 hpfs_error(i->
i_sb,
"move_to_top: dnode %08x doesn't point down to %08x", up, dno);
478 le16_add_cpu(&de->
length, -4);
483 t = get_pos(dnode, de);
484 for_all_poss(i, hpfs_pos_subst, t, 4);
485 for_all_poss(i, hpfs_pos_subst, t + 1, 5);
487 hpfs_error(i->
i_sb,
"out of memory for dirent - directory will be corrupted");
492 ddno = de->
down ? de_down_pointer(de) : 0;
493 hpfs_delete_de(i->
i_sb, dnode, de);
494 set_last_pointer(i->
i_sb, dnode, ddno);
497 a = hpfs_add_to_dnode(i, to, nde->
name, nde->
namelen, nde, from);
508 static void delete_empty_dnode(
struct inode *i,
dnode_secno dno)
525 de = dnode_first_de(dnode);
526 down = de->
down ? de_down_pointer(de) : 0;
527 if (hpfs_sb(i->
i_sb)->sb_chk)
if (root && !down) {
528 hpfs_error(i->
i_sb,
"delete_empty_dnode: root dnode %08x is empty", dno);
537 struct buffer_head *bh;
540 if (hpfs_sb(i->
i_sb)->sb_chk)
541 if (up != i->
i_ino) {
543 "bad pointer to fnode, dnode %08x, pointing to %08x, should be %08lx",
544 dno, up, (
unsigned long)i->
i_ino);
559 for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, (loff_t) 12);
564 de_end = dnode_end_de(dnode);
565 for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de), p++)
566 if (de->
down)
if (de_down_pointer(de) == dno)
goto fnd;
567 hpfs_error(i->
i_sb,
"delete_empty_dnode: pointer to dnode %08x not found in dnode %08x", dno, up);
570 for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, ((loff_t)up << 4) | p);
573 le16_add_cpu(&de->
length, -4);
575 memmove(de_next_de(de), (
char *)de_next_de(de) + 4,
597 if (!de_next->
down)
goto endm;
598 ndown = de_down_pointer(de_next);
600 printk(
"HPFS: out of memory for dtree balancing\n");
604 hpfs_delete_de(i->
i_sb, dnode, de);
607 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, 4);
608 for_all_poss(i, hpfs_pos_del, ((loff_t)up << 4) | p, 1);
614 hpfs_add_to_dnode(i, ndown, de_cp->
name, de_cp->
namelen, de_cp, de_cp->
down ? de_down_pointer(de_cp) : 0);
620 struct hpfs_dirent *de_prev = dnode_pre_last_de(dnode);
632 if (!de_prev->
down)
goto endm;
633 ndown = de_down_pointer(de_prev);
636 dlp = del->
down ? de_down_pointer(del) : 0;
639 if (hpfs_sb(i->
i_sb)->sb_chk >= 2) {
640 printk(
"HPFS: warning: unbalanced dnode tree, see hpfs.txt 4 more info\n");
641 printk(
"HPFS: warning: terminating balancing operation\n");
646 if (hpfs_sb(i->
i_sb)->sb_chk >= 2) {
647 printk(
"HPFS: warning: unbalanced dnode tree, see hpfs.txt 4 more info\n");
648 printk(
"HPFS: warning: goin'on\n");
650 le16_add_cpu(&del->
length, 4);
655 le16_add_cpu(&del->
length, -4);
662 printk(
"HPFS: out of memory for dtree balancing\n");
669 hpfs_delete_de(i->
i_sb, dnode, de_prev);
670 if (!de_prev->
down) {
671 le16_add_cpu(&de_prev->
length, 4);
678 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4);
679 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, ((loff_t)up << 4) | (p - 1));
685 hpfs_add_to_dnode(i, ndown, de_cp->
name, de_cp->
namelen, de_cp, dlp);
702 struct dnode *dnode = qbh->
data;
706 hpfs_error(i->
i_sb,
"hpfs_remove_dirent: attempt to delete first or last dirent in dnode %08x", dno);
710 if (de->
down) down = de_down_pointer(de);
711 if (depth && (de->
down || (de == dnode_first_de(dnode) && de_next_de(de)->
last))) {
718 for_all_poss(i, hpfs_pos_del, (t = get_pos(dnode, de)) + 1, 1);
719 hpfs_delete_de(i->
i_sb, dnode, de);
724 for_all_poss(i, hpfs_pos_subst, 5, t);
725 if (a) delete_empty_dnode(i, a);
728 delete_empty_dnode(i, dno);
733 int *n_subdirs,
int *n_items)
742 if (n_dnodes) (*n_dnodes)++;
743 if (hpfs_sb(s)->sb_chk)
748 if (hpfs_sb(s)->sb_chk)
if (odno && odno != -1 &&
le32_to_cpu(dnode->
up) != odno)
749 hpfs_error(s,
"hpfs_count_dnodes: bad up pointer; dnode %08x, down %08x points to %08x", odno, dno,
le32_to_cpu(dnode->
up));
750 de = dnode_first_de(dnode);
752 if (de->
down)
if (de_down_pointer(de) == ptr)
goto process_de;
755 hpfs_error(s,
"hpfs_count_dnodes: pointer to dnode %08x not found in dnode %08x, got here from %08x",
764 dno = de_down_pointer(de);
770 if (!de->
first && !de->
last && n_items) (*n_items)++;
771 if ((de = de_next_de(de)) < dnode_end_de(dnode))
goto next_de;
779 if (hpfs_sb(s)->sb_chk)
792 if (!dnode)
return NULL;
794 de = dnode_first_de(dnode);
795 de_end = dnode_end_de(dnode);
796 for (i = 1; de < de_end; i++, de = de_next_de(de)) {
803 hpfs_error(s,
"map_nth_dirent: n too high; dnode = %08x, requested %08x", dno, n);
816 if (hpfs_sb(s)->sb_chk)
819 if (!(de = map_nth_dirent(s, d, 1, &qbh,
NULL)))
return dno;
820 if (hpfs_sb(s)->sb_chk)
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));
828 d = de_down_pointer(de);
843 struct dnode *up_dnode;
849 if (!(de = map_nth_dirent(inode->
i_sb, dno, pos, qbh, &dnode)))
853 if ((d = de_next_de(de)) < dnode_end_de(dnode)) {
854 if (!(++*posp & 077)) {
856 "map_pos_dirent: pos crossed dnode boundary; pos = %08llx",
857 (
unsigned long long)*posp);
874 end_up_de = dnode_end_de(up_dnode);
876 for (up_de = dnode_first_de(up_dnode); up_de < end_up_de;
877 up_de = de_next_de(up_de)) {
879 "map_pos_dirent: pos crossed dnode boundary; dnode = %08x",
le32_to_cpu(dnode->
up));
880 if (up_de->
down && de_down_pointer(up_de) == dno) {
887 hpfs_error(inode->
i_sb,
"map_pos_dirent: pointer to dnode %08x not found in parent dnode %08x",
899 const unsigned char *name,
unsigned len,
909 if (hpfs_sb(inode->
i_sb)->sb_chk)
913 de_end = dnode_end_de(dnode);
914 for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de)) {
922 dno = de_down_pointer(de);
947 de = dnode_first_de(dnode);
949 if (de->
down) d1 = de_down_pointer(de);
957 d1 = de->
down ? de_down_pointer(de) : 0;
960 d2 = de->
down ? de_down_pointer(de) : 0;
966 de = dnode_first_de(dnode);
968 d1 = de->
down ? de_down_pointer(de) : 0;
979 hpfs_error(s,
"directory %08x is corrupted or not empty", rdno);
990 unsigned char *name1;
991 unsigned char *name2;
992 int name1len, name2len;
996 struct buffer_head *bh;
1003 printk(
"HPFS: out of memory, can't map dirent\n");
1007 memcpy(name2, name1, name1len = name2len = f->
len);
1009 memcpy(name2, name1, 15);
1010 memset(name2 + 15, 0xff, 256 - 15);
1012 name1len = 15; name2len = 256;
1018 if (!fnode_is_dir(upf)) {
1033 de_end = dnode_end_de(d);
1034 de = dnode_first_de(d);
1036 while (de < de_end) {
1037 if (de->
down)
if (de_down_pointer(de) == downd)
goto f;
1038 de = de_next_de(de);
1040 hpfs_error(s,
"pointer to dnode %08x not found in dnode %08x", downd, dno);
1051 if (c < 0 && de->down) {
1052 dno = de_down_pointer(de);
1054 if (hpfs_sb(s)->sb_chk)
1067 if (c < 0 && !de->
last)
goto not_found;
1068 if ((de = de_next_de(de)) < de_end)
goto next_de;
1073 if (hpfs_sb(s)->sb_chk)
1081 hpfs_error(s,
"dirent for fnode %08x not found", fno);