dnode.c (1749a10e02a9c6ed1a5c0a2860fb9ed132f2cc42) dnode.c (a19189e5535ed8fd191d8989fc39da1637cfa224)
1/*
2 * linux/fs/hpfs/dnode.c
3 *
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
5 *
6 * handling directory dnode tree - adding, deleteing & searching for dirents
7 */
8

--- 18 unchanged lines hidden (view full) ---

27 int i = 0;
28 loff_t **ppos;
29
30 if (hpfs_inode->i_rddir_off)
31 for (; hpfs_inode->i_rddir_off[i]; i++)
32 if (hpfs_inode->i_rddir_off[i] == pos) return;
33 if (!(i&0x0f)) {
34 if (!(ppos = kmalloc((i+0x11) * sizeof(loff_t*), GFP_NOFS))) {
1/*
2 * linux/fs/hpfs/dnode.c
3 *
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
5 *
6 * handling directory dnode tree - adding, deleteing & searching for dirents
7 */
8

--- 18 unchanged lines hidden (view full) ---

27 int i = 0;
28 loff_t **ppos;
29
30 if (hpfs_inode->i_rddir_off)
31 for (; hpfs_inode->i_rddir_off[i]; i++)
32 if (hpfs_inode->i_rddir_off[i] == pos) return;
33 if (!(i&0x0f)) {
34 if (!(ppos = kmalloc((i+0x11) * sizeof(loff_t*), GFP_NOFS))) {
35 pr_warn("out of memory for position list\n");
35 pr_err("out of memory for position list\n");
36 return;
37 }
38 if (hpfs_inode->i_rddir_off) {
39 memcpy(ppos, hpfs_inode->i_rddir_off, i * sizeof(loff_t));
40 kfree(hpfs_inode->i_rddir_off);
41 }
42 hpfs_inode->i_rddir_off = ppos;
43 }

--- 45 unchanged lines hidden (view full) ---

89 if ((*p & ~0x3f) == (f & ~0x3f)) *p = (t & ~0x3f) | (*p & 0x3f);
90}*/
91
92static void hpfs_pos_ins(loff_t *p, loff_t d, loff_t c)
93{
94 if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
95 int n = (*p & 0x3f) + c;
96 if (n > 0x3f)
36 return;
37 }
38 if (hpfs_inode->i_rddir_off) {
39 memcpy(ppos, hpfs_inode->i_rddir_off, i * sizeof(loff_t));
40 kfree(hpfs_inode->i_rddir_off);
41 }
42 hpfs_inode->i_rddir_off = ppos;
43 }

--- 45 unchanged lines hidden (view full) ---

89 if ((*p & ~0x3f) == (f & ~0x3f)) *p = (t & ~0x3f) | (*p & 0x3f);
90}*/
91
92static void hpfs_pos_ins(loff_t *p, loff_t d, loff_t c)
93{
94 if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
95 int n = (*p & 0x3f) + c;
96 if (n > 0x3f)
97 pr_warn("%s(): %08x + %d\n",
97 pr_err("%s(): %08x + %d\n",
98 __func__, (int)*p, (int)c >> 8);
99 else
100 *p = (*p & ~0x3f) | n;
101 }
102}
103
104static void hpfs_pos_del(loff_t *p, loff_t d, loff_t c)
105{
106 if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
107 int n = (*p & 0x3f) - c;
108 if (n < 1)
98 __func__, (int)*p, (int)c >> 8);
99 else
100 *p = (*p & ~0x3f) | n;
101 }
102}
103
104static void hpfs_pos_del(loff_t *p, loff_t d, loff_t c)
105{
106 if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
107 int n = (*p & 0x3f) - c;
108 if (n < 1)
109 pr_warn("%s(): %08x - %d\n",
109 pr_err("%s(): %08x - %d\n",
110 __func__, (int)*p, (int)c >> 8);
111 else
112 *p = (*p & ~0x3f) | n;
113 }
114}
115
116static struct hpfs_dirent *dnode_pre_last_de(struct dnode *d)
117{

--- 123 unchanged lines hidden (view full) ---

241 struct hpfs_dirent nde;
242 unsigned char *nname;
243 int h;
244 int pos;
245 struct buffer_head *bh;
246 struct fnode *fnode;
247 int c1, c2 = 0;
248 if (!(nname = kmalloc(256, GFP_NOFS))) {
110 __func__, (int)*p, (int)c >> 8);
111 else
112 *p = (*p & ~0x3f) | n;
113 }
114}
115
116static struct hpfs_dirent *dnode_pre_last_de(struct dnode *d)
117{

--- 123 unchanged lines hidden (view full) ---

241 struct hpfs_dirent nde;
242 unsigned char *nname;
243 int h;
244 int pos;
245 struct buffer_head *bh;
246 struct fnode *fnode;
247 int c1, c2 = 0;
248 if (!(nname = kmalloc(256, GFP_NOFS))) {
249 pr_warn("out of memory, can't add to dnode\n");
249 pr_err("out of memory, can't add to dnode\n");
250 return 1;
251 }
252 go_up:
253 if (namelen >= 256) {
254 hpfs_error(i->i_sb, "%s(): namelen == %d", __func__, namelen);
255 kfree(nd);
256 kfree(nname);
257 return 1;

--- 25 unchanged lines hidden (view full) ---

283 return 0;
284 }
285 if (!nd) if (!(nd = kmalloc(0x924, GFP_NOFS))) {
286 /* 0x924 is a max size of dnode after adding a dirent with
287 max name length. We alloc this only once. There must
288 not be any error while splitting dnodes, otherwise the
289 whole directory, not only file we're adding, would
290 be lost. */
250 return 1;
251 }
252 go_up:
253 if (namelen >= 256) {
254 hpfs_error(i->i_sb, "%s(): namelen == %d", __func__, namelen);
255 kfree(nd);
256 kfree(nname);
257 return 1;

--- 25 unchanged lines hidden (view full) ---

283 return 0;
284 }
285 if (!nd) if (!(nd = kmalloc(0x924, GFP_NOFS))) {
286 /* 0x924 is a max size of dnode after adding a dirent with
287 max name length. We alloc this only once. There must
288 not be any error while splitting dnodes, otherwise the
289 whole directory, not only file we're adding, would
290 be lost. */
291 pr_warn("out of memory for dnode splitting\n");
291 pr_err("out of memory for dnode splitting\n");
292 hpfs_brelse4(&qbh);
293 kfree(nname);
294 return 1;
295 }
296 memcpy(nd, d, le32_to_cpu(d->first_free));
297 copy_de(de = hpfs_add_de(i->i_sb, nd, name, namelen, down_ptr), new_de);
298 for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1);
299 h = ((char *)dnode_last_de(nd) - (char *)nd) / 2 + 10;

--- 299 unchanged lines hidden (view full) ---

599 if (!de->last) {
600 struct hpfs_dirent *de_next = de_next_de(de);
601 struct hpfs_dirent *de_cp;
602 struct dnode *d1;
603 struct quad_buffer_head qbh1;
604 if (!de_next->down) goto endm;
605 ndown = de_down_pointer(de_next);
606 if (!(de_cp = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
292 hpfs_brelse4(&qbh);
293 kfree(nname);
294 return 1;
295 }
296 memcpy(nd, d, le32_to_cpu(d->first_free));
297 copy_de(de = hpfs_add_de(i->i_sb, nd, name, namelen, down_ptr), new_de);
298 for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1);
299 h = ((char *)dnode_last_de(nd) - (char *)nd) / 2 + 10;

--- 299 unchanged lines hidden (view full) ---

599 if (!de->last) {
600 struct hpfs_dirent *de_next = de_next_de(de);
601 struct hpfs_dirent *de_cp;
602 struct dnode *d1;
603 struct quad_buffer_head qbh1;
604 if (!de_next->down) goto endm;
605 ndown = de_down_pointer(de_next);
606 if (!(de_cp = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
607 pr_warn("out of memory for dtree balancing\n");
607 pr_err("out of memory for dtree balancing\n");
608 goto endm;
609 }
610 memcpy(de_cp, de, le16_to_cpu(de->length));
611 hpfs_delete_de(i->i_sb, dnode, de);
612 hpfs_mark_4buffers_dirty(&qbh);
613 hpfs_brelse4(&qbh);
614 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, 4);
615 for_all_poss(i, hpfs_pos_del, ((loff_t)up << 4) | p, 1);

--- 24 unchanged lines hidden (view full) ---

640 if (!de_prev->down) goto endm;
641 ndown = de_down_pointer(de_prev);
642 if ((d1 = hpfs_map_dnode(i->i_sb, ndown, &qbh1))) {
643 struct hpfs_dirent *del = dnode_last_de(d1);
644 dlp = del->down ? de_down_pointer(del) : 0;
645 if (!dlp && down) {
646 if (le32_to_cpu(d1->first_free) > 2044) {
647 if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
608 goto endm;
609 }
610 memcpy(de_cp, de, le16_to_cpu(de->length));
611 hpfs_delete_de(i->i_sb, dnode, de);
612 hpfs_mark_4buffers_dirty(&qbh);
613 hpfs_brelse4(&qbh);
614 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, 4);
615 for_all_poss(i, hpfs_pos_del, ((loff_t)up << 4) | p, 1);

--- 24 unchanged lines hidden (view full) ---

640 if (!de_prev->down) goto endm;
641 ndown = de_down_pointer(de_prev);
642 if ((d1 = hpfs_map_dnode(i->i_sb, ndown, &qbh1))) {
643 struct hpfs_dirent *del = dnode_last_de(d1);
644 dlp = del->down ? de_down_pointer(del) : 0;
645 if (!dlp && down) {
646 if (le32_to_cpu(d1->first_free) > 2044) {
647 if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
648 pr_warn("unbalanced dnode tree, see hpfs.txt 4 more info\n");
649 pr_warn("terminating balancing operation\n");
648 pr_err("unbalanced dnode tree, see hpfs.txt 4 more info\n");
649 pr_err("terminating balancing operation\n");
650 }
651 hpfs_brelse4(&qbh1);
652 goto endm;
653 }
654 if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
650 }
651 hpfs_brelse4(&qbh1);
652 goto endm;
653 }
654 if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
655 pr_warn("unbalanced dnode tree, see hpfs.txt 4 more info\n");
656 pr_warn("goin'on\n");
655 pr_err("unbalanced dnode tree, see hpfs.txt 4 more info\n");
656 pr_err("goin'on\n");
657 }
658 le16_add_cpu(&del->length, 4);
659 del->down = 1;
660 le32_add_cpu(&d1->first_free, 4);
661 }
662 if (dlp && !down) {
663 le16_add_cpu(&del->length, -4);
664 del->down = 0;
665 le32_add_cpu(&d1->first_free, -4);
666 } else if (down)
667 *(__le32 *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down);
668 } else goto endm;
669 if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) {
657 }
658 le16_add_cpu(&del->length, 4);
659 del->down = 1;
660 le32_add_cpu(&d1->first_free, 4);
661 }
662 if (dlp && !down) {
663 le16_add_cpu(&del->length, -4);
664 del->down = 0;
665 le32_add_cpu(&d1->first_free, -4);
666 } else if (down)
667 *(__le32 *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down);
668 } else goto endm;
669 if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) {
670 pr_warn("out of memory for dtree balancing\n");
670 pr_err("out of memory for dtree balancing\n");
671 hpfs_brelse4(&qbh1);
672 goto endm;
673 }
674 hpfs_mark_4buffers_dirty(&qbh1);
675 hpfs_brelse4(&qbh1);
676 memcpy(de_cp, de_prev, le16_to_cpu(de_prev->length));
677 hpfs_delete_de(i->i_sb, dnode, de_prev);
678 if (!de_prev->down) {

--- 324 unchanged lines hidden (view full) ---

1003 struct fnode *upf;
1004 struct buffer_head *bh;
1005 struct hpfs_dirent *de, *de_end;
1006 int c;
1007 int c1, c2 = 0;
1008 int d1, d2 = 0;
1009 name1 = f->name;
1010 if (!(name2 = kmalloc(256, GFP_NOFS))) {
671 hpfs_brelse4(&qbh1);
672 goto endm;
673 }
674 hpfs_mark_4buffers_dirty(&qbh1);
675 hpfs_brelse4(&qbh1);
676 memcpy(de_cp, de_prev, le16_to_cpu(de_prev->length));
677 hpfs_delete_de(i->i_sb, dnode, de_prev);
678 if (!de_prev->down) {

--- 324 unchanged lines hidden (view full) ---

1003 struct fnode *upf;
1004 struct buffer_head *bh;
1005 struct hpfs_dirent *de, *de_end;
1006 int c;
1007 int c1, c2 = 0;
1008 int d1, d2 = 0;
1009 name1 = f->name;
1010 if (!(name2 = kmalloc(256, GFP_NOFS))) {
1011 pr_warn("out of memory, can't map dirent\n");
1011 pr_err("out of memory, can't map dirent\n");
1012 return NULL;
1013 }
1014 if (f->len <= 15)
1015 memcpy(name2, name1, name1len = name2len = f->len);
1016 else {
1017 memcpy(name2, name1, 15);
1018 memset(name2 + 15, 0xff, 256 - 15);
1019 /*name2[15] = 0xff;*/

--- 73 unchanged lines hidden ---
1012 return NULL;
1013 }
1014 if (f->len <= 15)
1015 memcpy(name2, name1, name1len = name2len = f->len);
1016 else {
1017 memcpy(name2, name1, 15);
1018 memset(name2 + 15, 0xff, 256 - 15);
1019 /*name2[15] = 0xff;*/

--- 73 unchanged lines hidden ---