Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  linux/fs/hpfs/dnode.c
0004  *
0005  *  Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
0006  *
0007  *  handling directory dnode tree - adding, deleteing & searching for dirents
0008  */
0009 
0010 #include "hpfs_fn.h"
0011 
0012 static loff_t get_pos(struct dnode *d, struct hpfs_dirent *fde)
0013 {
0014     struct hpfs_dirent *de;
0015     struct hpfs_dirent *de_end = dnode_end_de(d);
0016     int i = 1;
0017     for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
0018         if (de == fde) return ((loff_t) le32_to_cpu(d->self) << 4) | (loff_t)i;
0019         i++;
0020     }
0021     pr_info("%s(): not_found\n", __func__);
0022     return ((loff_t)le32_to_cpu(d->self) << 4) | (loff_t)1;
0023 }
0024 
0025 int hpfs_add_pos(struct inode *inode, loff_t *pos)
0026 {
0027     struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
0028     int i = 0;
0029     loff_t **ppos;
0030 
0031     if (hpfs_inode->i_rddir_off)
0032         for (; hpfs_inode->i_rddir_off[i]; i++)
0033             if (hpfs_inode->i_rddir_off[i] == pos)
0034                 return 0;
0035     if (!(i&0x0f)) {
0036         ppos = kmalloc_array(i + 0x11, sizeof(loff_t *), GFP_NOFS);
0037         if (!ppos) {
0038             pr_err("out of memory for position list\n");
0039             return -ENOMEM;
0040         }
0041         if (hpfs_inode->i_rddir_off) {
0042             memcpy(ppos, hpfs_inode->i_rddir_off, i * sizeof(loff_t));
0043             kfree(hpfs_inode->i_rddir_off);
0044         }
0045         hpfs_inode->i_rddir_off = ppos;
0046     }
0047     hpfs_inode->i_rddir_off[i] = pos;
0048     hpfs_inode->i_rddir_off[i + 1] = NULL;
0049     return 0;
0050 }
0051 
0052 void hpfs_del_pos(struct inode *inode, loff_t *pos)
0053 {
0054     struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
0055     loff_t **i, **j;
0056 
0057     if (!hpfs_inode->i_rddir_off) goto not_f;
0058     for (i = hpfs_inode->i_rddir_off; *i; i++) if (*i == pos) goto fnd;
0059     goto not_f;
0060     fnd:
0061     for (j = i + 1; *j; j++) ;
0062     *i = *(j - 1);
0063     *(j - 1) = NULL;
0064     if (j - 1 == hpfs_inode->i_rddir_off) {
0065         kfree(hpfs_inode->i_rddir_off);
0066         hpfs_inode->i_rddir_off = NULL;
0067     }
0068     return;
0069     not_f:
0070     /*pr_warn("position pointer %p->%08x not found\n",
0071           pos, (int)*pos);*/
0072     return;
0073 }
0074 
0075 static void for_all_poss(struct inode *inode, void (*f)(loff_t *, loff_t, loff_t),
0076              loff_t p1, loff_t p2)
0077 {
0078     struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
0079     loff_t **i;
0080 
0081     if (!hpfs_inode->i_rddir_off) return;
0082     for (i = hpfs_inode->i_rddir_off; *i; i++) (*f)(*i, p1, p2);
0083     return;
0084 }
0085 
0086 static void hpfs_pos_subst(loff_t *p, loff_t f, loff_t t)
0087 {
0088     if (*p == f) *p = t;
0089 }
0090 
0091 /*void hpfs_hpfs_pos_substd(loff_t *p, loff_t f, loff_t t)
0092 {
0093     if ((*p & ~0x3f) == (f & ~0x3f)) *p = (t & ~0x3f) | (*p & 0x3f);
0094 }*/
0095 
0096 static void hpfs_pos_ins(loff_t *p, loff_t d, loff_t c)
0097 {
0098     if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
0099         int n = (*p & 0x3f) + c;
0100         if (n > 0x3f)
0101             pr_err("%s(): %08x + %d\n",
0102                 __func__, (int)*p, (int)c >> 8);
0103         else
0104             *p = (*p & ~0x3f) | n;
0105     }
0106 }
0107 
0108 static void hpfs_pos_del(loff_t *p, loff_t d, loff_t c)
0109 {
0110     if ((*p & ~0x3f) == (d & ~0x3f) && (*p & 0x3f) >= (d & 0x3f)) {
0111         int n = (*p & 0x3f) - c;
0112         if (n < 1)
0113             pr_err("%s(): %08x - %d\n",
0114                 __func__, (int)*p, (int)c >> 8);
0115         else
0116             *p = (*p & ~0x3f) | n;
0117     }
0118 }
0119 
0120 static struct hpfs_dirent *dnode_pre_last_de(struct dnode *d)
0121 {
0122     struct hpfs_dirent *de, *de_end, *dee = NULL, *deee = NULL;
0123     de_end = dnode_end_de(d);
0124     for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
0125         deee = dee; dee = de;
0126     }   
0127     return deee;
0128 }
0129 
0130 static struct hpfs_dirent *dnode_last_de(struct dnode *d)
0131 {
0132     struct hpfs_dirent *de, *de_end, *dee = NULL;
0133     de_end = dnode_end_de(d);
0134     for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
0135         dee = de;
0136     }   
0137     return dee;
0138 }
0139 
0140 static void set_last_pointer(struct super_block *s, struct dnode *d, dnode_secno ptr)
0141 {
0142     struct hpfs_dirent *de;
0143     if (!(de = dnode_last_de(d))) {
0144         hpfs_error(s, "set_last_pointer: empty dnode %08x", le32_to_cpu(d->self));
0145         return;
0146     }
0147     if (hpfs_sb(s)->sb_chk) {
0148         if (de->down) {
0149             hpfs_error(s, "set_last_pointer: dnode %08x has already last pointer %08x",
0150                 le32_to_cpu(d->self), de_down_pointer(de));
0151             return;
0152         }
0153         if (le16_to_cpu(de->length) != 32) {
0154             hpfs_error(s, "set_last_pointer: bad last dirent in dnode %08x", le32_to_cpu(d->self));
0155             return;
0156         }
0157     }
0158     if (ptr) {
0159         le32_add_cpu(&d->first_free, 4);
0160         if (le32_to_cpu(d->first_free) > 2048) {
0161             hpfs_error(s, "set_last_pointer: too long dnode %08x", le32_to_cpu(d->self));
0162             le32_add_cpu(&d->first_free, -4);
0163             return;
0164         }
0165         de->length = cpu_to_le16(36);
0166         de->down = 1;
0167         *(__le32 *)((char *)de + 32) = cpu_to_le32(ptr);
0168     }
0169 }
0170 
0171 /* Add an entry to dnode and don't care if it grows over 2048 bytes */
0172 
0173 struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d,
0174                 const unsigned char *name,
0175                 unsigned namelen, secno down_ptr)
0176 {
0177     struct hpfs_dirent *de;
0178     struct hpfs_dirent *de_end = dnode_end_de(d);
0179     unsigned d_size = de_size(namelen, down_ptr);
0180     for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
0181         int c = hpfs_compare_names(s, name, namelen, de->name, de->namelen, de->last);
0182         if (!c) {
0183             hpfs_error(s, "name (%c,%d) already exists in dnode %08x", *name, namelen, le32_to_cpu(d->self));
0184             return NULL;
0185         }
0186         if (c < 0) break;
0187     }
0188     memmove((char *)de + d_size, de, (char *)de_end - (char *)de);
0189     memset(de, 0, d_size);
0190     if (down_ptr) {
0191         *(__le32 *)((char *)de + d_size - 4) = cpu_to_le32(down_ptr);
0192         de->down = 1;
0193     }
0194     de->length = cpu_to_le16(d_size);
0195     de->not_8x3 = hpfs_is_name_long(name, namelen);
0196     de->namelen = namelen;
0197     memcpy(de->name, name, namelen);
0198     le32_add_cpu(&d->first_free, d_size);
0199     return de;
0200 }
0201 
0202 /* Delete dirent and don't care about its subtree */
0203 
0204 static void hpfs_delete_de(struct super_block *s, struct dnode *d,
0205                struct hpfs_dirent *de)
0206 {
0207     if (de->last) {
0208         hpfs_error(s, "attempt to delete last dirent in dnode %08x", le32_to_cpu(d->self));
0209         return;
0210     }
0211     d->first_free = cpu_to_le32(le32_to_cpu(d->first_free) - le16_to_cpu(de->length));
0212     memmove(de, de_next_de(de), le32_to_cpu(d->first_free) + (char *)d - (char *)de);
0213 }
0214 
0215 static void fix_up_ptrs(struct super_block *s, struct dnode *d)
0216 {
0217     struct hpfs_dirent *de;
0218     struct hpfs_dirent *de_end = dnode_end_de(d);
0219     dnode_secno dno = le32_to_cpu(d->self);
0220     for (de = dnode_first_de(d); de < de_end; de = de_next_de(de))
0221         if (de->down) {
0222             struct quad_buffer_head qbh;
0223             struct dnode *dd;
0224             if ((dd = hpfs_map_dnode(s, de_down_pointer(de), &qbh))) {
0225                 if (le32_to_cpu(dd->up) != dno || dd->root_dnode) {
0226                     dd->up = cpu_to_le32(dno);
0227                     dd->root_dnode = 0;
0228                     hpfs_mark_4buffers_dirty(&qbh);
0229                 }
0230                 hpfs_brelse4(&qbh);
0231             }
0232         }
0233 }
0234 
0235 /* Add an entry to dnode and do dnode splitting if required */
0236 
0237 static int hpfs_add_to_dnode(struct inode *i, dnode_secno dno,
0238                  const unsigned char *name, unsigned namelen,
0239                  struct hpfs_dirent *new_de, dnode_secno down_ptr)
0240 {
0241     struct quad_buffer_head qbh, qbh1, qbh2;
0242     struct dnode *d, *ad, *rd, *nd = NULL;
0243     dnode_secno adno, rdno;
0244     struct hpfs_dirent *de;
0245     struct hpfs_dirent nde;
0246     unsigned char *nname;
0247     int h;
0248     int pos;
0249     struct buffer_head *bh;
0250     struct fnode *fnode;
0251     int c1, c2 = 0;
0252     if (!(nname = kmalloc(256, GFP_NOFS))) {
0253         pr_err("out of memory, can't add to dnode\n");
0254         return 1;
0255     }
0256     go_up:
0257     if (namelen >= 256) {
0258         hpfs_error(i->i_sb, "%s(): namelen == %d", __func__, namelen);
0259         kfree(nd);
0260         kfree(nname);
0261         return 1;
0262     }
0263     if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) {
0264         kfree(nd);
0265         kfree(nname);
0266         return 1;
0267     }
0268     go_up_a:
0269     if (hpfs_sb(i->i_sb)->sb_chk)
0270         if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_to_dnode")) {
0271             hpfs_brelse4(&qbh);
0272             kfree(nd);
0273             kfree(nname);
0274             return 1;
0275         }
0276     if (le32_to_cpu(d->first_free) + de_size(namelen, down_ptr) <= 2048) {
0277         loff_t t;
0278         copy_de(de=hpfs_add_de(i->i_sb, d, name, namelen, down_ptr), new_de);
0279         t = get_pos(d, de);
0280         for_all_poss(i, hpfs_pos_ins, t, 1);
0281         for_all_poss(i, hpfs_pos_subst, 4, t);
0282         for_all_poss(i, hpfs_pos_subst, 5, t + 1);
0283         hpfs_mark_4buffers_dirty(&qbh);
0284         hpfs_brelse4(&qbh);
0285         kfree(nd);
0286         kfree(nname);
0287         return 0;
0288     }
0289     if (!nd) if (!(nd = kmalloc(0x924, GFP_NOFS))) {
0290         /* 0x924 is a max size of dnode after adding a dirent with
0291            max name length. We alloc this only once. There must
0292            not be any error while splitting dnodes, otherwise the
0293            whole directory, not only file we're adding, would
0294            be lost. */
0295         pr_err("out of memory for dnode splitting\n");
0296         hpfs_brelse4(&qbh);
0297         kfree(nname);
0298         return 1;
0299     }   
0300     memcpy(nd, d, le32_to_cpu(d->first_free));
0301     copy_de(de = hpfs_add_de(i->i_sb, nd, name, namelen, down_ptr), new_de);
0302     for_all_poss(i, hpfs_pos_ins, get_pos(nd, de), 1);
0303     h = ((char *)dnode_last_de(nd) - (char *)nd) / 2 + 10;
0304     if (!(ad = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &adno, &qbh1))) {
0305         hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted");
0306         hpfs_brelse4(&qbh);
0307         kfree(nd);
0308         kfree(nname);
0309         return 1;
0310     }
0311     i->i_size += 2048;
0312     i->i_blocks += 4;
0313     pos = 1;
0314     for (de = dnode_first_de(nd); (char *)de_next_de(de) - (char *)nd < h; de = de_next_de(de)) {
0315         copy_de(hpfs_add_de(i->i_sb, ad, de->name, de->namelen, de->down ? de_down_pointer(de) : 0), de);
0316         for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, ((loff_t)adno << 4) | pos);
0317         pos++;
0318     }
0319     copy_de(new_de = &nde, de);
0320     memcpy(nname, de->name, de->namelen);
0321     name = nname;
0322     namelen = de->namelen;
0323     for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | pos, 4);
0324     down_ptr = adno;
0325     set_last_pointer(i->i_sb, ad, de->down ? de_down_pointer(de) : 0);
0326     de = de_next_de(de);
0327     memmove((char *)nd + 20, de, le32_to_cpu(nd->first_free) + (char *)nd - (char *)de);
0328     le32_add_cpu(&nd->first_free, -((char *)de - (char *)nd - 20));
0329     memcpy(d, nd, le32_to_cpu(nd->first_free));
0330     for_all_poss(i, hpfs_pos_del, (loff_t)dno << 4, pos);
0331     fix_up_ptrs(i->i_sb, ad);
0332     if (!d->root_dnode) {
0333         ad->up = d->up;
0334         dno = le32_to_cpu(ad->up);
0335         hpfs_mark_4buffers_dirty(&qbh);
0336         hpfs_brelse4(&qbh);
0337         hpfs_mark_4buffers_dirty(&qbh1);
0338         hpfs_brelse4(&qbh1);
0339         goto go_up;
0340     }
0341     if (!(rd = hpfs_alloc_dnode(i->i_sb, le32_to_cpu(d->up), &rdno, &qbh2))) {
0342         hpfs_error(i->i_sb, "unable to alloc dnode - dnode tree will be corrupted");
0343         hpfs_brelse4(&qbh);
0344         hpfs_brelse4(&qbh1);
0345         kfree(nd);
0346         kfree(nname);
0347         return 1;
0348     }
0349     i->i_size += 2048;
0350     i->i_blocks += 4;
0351     rd->root_dnode = 1;
0352     rd->up = d->up;
0353     if (!(fnode = hpfs_map_fnode(i->i_sb, le32_to_cpu(d->up), &bh))) {
0354         hpfs_free_dnode(i->i_sb, rdno);
0355         hpfs_brelse4(&qbh);
0356         hpfs_brelse4(&qbh1);
0357         hpfs_brelse4(&qbh2);
0358         kfree(nd);
0359         kfree(nname);
0360         return 1;
0361     }
0362     fnode->u.external[0].disk_secno = cpu_to_le32(rdno);
0363     mark_buffer_dirty(bh);
0364     brelse(bh);
0365     hpfs_i(i)->i_dno = rdno;
0366     d->up = ad->up = cpu_to_le32(rdno);
0367     d->root_dnode = ad->root_dnode = 0;
0368     hpfs_mark_4buffers_dirty(&qbh);
0369     hpfs_brelse4(&qbh);
0370     hpfs_mark_4buffers_dirty(&qbh1);
0371     hpfs_brelse4(&qbh1);
0372     qbh = qbh2;
0373     set_last_pointer(i->i_sb, rd, dno);
0374     dno = rdno;
0375     d = rd;
0376     goto go_up_a;
0377 }
0378 
0379 /*
0380  * Add an entry to directory btree.
0381  * I hate such crazy directory structure.
0382  * It's easy to read but terrible to write.
0383  * I wrote this directory code 4 times.
0384  * I hope, now it's finally bug-free.
0385  */
0386 
0387 int hpfs_add_dirent(struct inode *i,
0388             const unsigned char *name, unsigned namelen,
0389             struct hpfs_dirent *new_de)
0390 {
0391     struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
0392     struct dnode *d;
0393     struct hpfs_dirent *de, *de_end;
0394     struct quad_buffer_head qbh;
0395     dnode_secno dno;
0396     int c;
0397     int c1, c2 = 0;
0398     dno = hpfs_inode->i_dno;
0399     down:
0400     if (hpfs_sb(i->i_sb)->sb_chk)
0401         if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "hpfs_add_dirent")) return 1;
0402     if (!(d = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 1;
0403     de_end = dnode_end_de(d);
0404     for (de = dnode_first_de(d); de < de_end; de = de_next_de(de)) {
0405         if (!(c = hpfs_compare_names(i->i_sb, name, namelen, de->name, de->namelen, de->last))) {
0406             hpfs_brelse4(&qbh);
0407             return -1;
0408         }   
0409         if (c < 0) {
0410             if (de->down) {
0411                 dno = de_down_pointer(de);
0412                 hpfs_brelse4(&qbh);
0413                 goto down;
0414             }
0415             break;
0416         }
0417     }
0418     hpfs_brelse4(&qbh);
0419     if (hpfs_check_free_dnodes(i->i_sb, FREE_DNODES_ADD)) {
0420         c = 1;
0421         goto ret;
0422     }   
0423     c = hpfs_add_to_dnode(i, dno, name, namelen, new_de, 0);
0424     ret:
0425     return c;
0426 }
0427 
0428 /* 
0429  * Find dirent with higher name in 'from' subtree and move it to 'to' dnode.
0430  * Return the dnode we moved from (to be checked later if it's empty)
0431  */
0432 
0433 static secno move_to_top(struct inode *i, dnode_secno from, dnode_secno to)
0434 {
0435     dnode_secno dno, ddno;
0436     dnode_secno chk_up = to;
0437     struct dnode *dnode;
0438     struct quad_buffer_head qbh;
0439     struct hpfs_dirent *de, *nde;
0440     int a;
0441     loff_t t;
0442     int c1, c2 = 0;
0443     dno = from;
0444     while (1) {
0445         if (hpfs_sb(i->i_sb)->sb_chk)
0446             if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "move_to_top"))
0447                 return 0;
0448         if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return 0;
0449         if (hpfs_sb(i->i_sb)->sb_chk) {
0450             if (le32_to_cpu(dnode->up) != chk_up) {
0451                 hpfs_error(i->i_sb, "move_to_top: up pointer from %08x should be %08x, is %08x",
0452                     dno, chk_up, le32_to_cpu(dnode->up));
0453                 hpfs_brelse4(&qbh);
0454                 return 0;
0455             }
0456             chk_up = dno;
0457         }
0458         if (!(de = dnode_last_de(dnode))) {
0459             hpfs_error(i->i_sb, "move_to_top: dnode %08x has no last de", dno);
0460             hpfs_brelse4(&qbh);
0461             return 0;
0462         }
0463         if (!de->down) break;
0464         dno = de_down_pointer(de);
0465         hpfs_brelse4(&qbh);
0466     }
0467     while (!(de = dnode_pre_last_de(dnode))) {
0468         dnode_secno up = le32_to_cpu(dnode->up);
0469         hpfs_brelse4(&qbh);
0470         hpfs_free_dnode(i->i_sb, dno);
0471         i->i_size -= 2048;
0472         i->i_blocks -= 4;
0473         for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, 5);
0474         if (up == to) return to;
0475         if (!(dnode = hpfs_map_dnode(i->i_sb, up, &qbh))) return 0;
0476         if (dnode->root_dnode) {
0477             hpfs_error(i->i_sb, "move_to_top: got to root_dnode while moving from %08x to %08x", from, to);
0478             hpfs_brelse4(&qbh);
0479             return 0;
0480         }
0481         de = dnode_last_de(dnode);
0482         if (!de || !de->down) {
0483             hpfs_error(i->i_sb, "move_to_top: dnode %08x doesn't point down to %08x", up, dno);
0484             hpfs_brelse4(&qbh);
0485             return 0;
0486         }
0487         le32_add_cpu(&dnode->first_free, -4);
0488         le16_add_cpu(&de->length, -4);
0489         de->down = 0;
0490         hpfs_mark_4buffers_dirty(&qbh);
0491         dno = up;
0492     }
0493     t = get_pos(dnode, de);
0494     for_all_poss(i, hpfs_pos_subst, t, 4);
0495     for_all_poss(i, hpfs_pos_subst, t + 1, 5);
0496     if (!(nde = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
0497         hpfs_error(i->i_sb, "out of memory for dirent - directory will be corrupted");
0498         hpfs_brelse4(&qbh);
0499         return 0;
0500     }
0501     memcpy(nde, de, le16_to_cpu(de->length));
0502     ddno = de->down ? de_down_pointer(de) : 0;
0503     hpfs_delete_de(i->i_sb, dnode, de);
0504     set_last_pointer(i->i_sb, dnode, ddno);
0505     hpfs_mark_4buffers_dirty(&qbh);
0506     hpfs_brelse4(&qbh);
0507     a = hpfs_add_to_dnode(i, to, nde->name, nde->namelen, nde, from);
0508     kfree(nde);
0509     if (a) return 0;
0510     return dno;
0511 }
0512 
0513 /* 
0514  * Check if a dnode is empty and delete it from the tree
0515  * (chkdsk doesn't like empty dnodes)
0516  */
0517 
0518 static void delete_empty_dnode(struct inode *i, dnode_secno dno)
0519 {
0520     struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
0521     struct quad_buffer_head qbh;
0522     struct dnode *dnode;
0523     dnode_secno down, up, ndown;
0524     int p;
0525     struct hpfs_dirent *de;
0526     int c1, c2 = 0;
0527     try_it_again:
0528     if (hpfs_stop_cycles(i->i_sb, dno, &c1, &c2, "delete_empty_dnode")) return;
0529     if (!(dnode = hpfs_map_dnode(i->i_sb, dno, &qbh))) return;
0530     if (le32_to_cpu(dnode->first_free) > 56) goto end;
0531     if (le32_to_cpu(dnode->first_free) == 52 || le32_to_cpu(dnode->first_free) == 56) {
0532         struct hpfs_dirent *de_end;
0533         int root = dnode->root_dnode;
0534         up = le32_to_cpu(dnode->up);
0535         de = dnode_first_de(dnode);
0536         down = de->down ? de_down_pointer(de) : 0;
0537         if (hpfs_sb(i->i_sb)->sb_chk) if (root && !down) {
0538             hpfs_error(i->i_sb, "delete_empty_dnode: root dnode %08x is empty", dno);
0539             goto end;
0540         }
0541         hpfs_brelse4(&qbh);
0542         hpfs_free_dnode(i->i_sb, dno);
0543         i->i_size -= 2048;
0544         i->i_blocks -= 4;
0545         if (root) {
0546             struct fnode *fnode;
0547             struct buffer_head *bh;
0548             struct dnode *d1;
0549             struct quad_buffer_head qbh1;
0550             if (hpfs_sb(i->i_sb)->sb_chk)
0551                 if (up != i->i_ino) {
0552                     hpfs_error(i->i_sb,
0553                            "bad pointer to fnode, dnode %08x, pointing to %08x, should be %08lx",
0554                            dno, up,
0555                            (unsigned long)i->i_ino);
0556                     return;
0557                 }
0558             if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) {
0559                 d1->up = cpu_to_le32(up);
0560                 d1->root_dnode = 1;
0561                 hpfs_mark_4buffers_dirty(&qbh1);
0562                 hpfs_brelse4(&qbh1);
0563             }
0564             if ((fnode = hpfs_map_fnode(i->i_sb, up, &bh))) {
0565                 fnode->u.external[0].disk_secno = cpu_to_le32(down);
0566                 mark_buffer_dirty(bh);
0567                 brelse(bh);
0568             }
0569             hpfs_inode->i_dno = down;
0570             for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, (loff_t) 12);
0571             return;
0572         }
0573         if (!(dnode = hpfs_map_dnode(i->i_sb, up, &qbh))) return;
0574         p = 1;
0575         de_end = dnode_end_de(dnode);
0576         for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de), p++)
0577             if (de->down) if (de_down_pointer(de) == dno) goto fnd;
0578         hpfs_error(i->i_sb, "delete_empty_dnode: pointer to dnode %08x not found in dnode %08x", dno, up);
0579         goto end;
0580         fnd:
0581         for_all_poss(i, hpfs_pos_subst, ((loff_t)dno << 4) | 1, ((loff_t)up << 4) | p);
0582         if (!down) {
0583             de->down = 0;
0584             le16_add_cpu(&de->length, -4);
0585             le32_add_cpu(&dnode->first_free, -4);
0586             memmove(de_next_de(de), (char *)de_next_de(de) + 4,
0587                 (char *)dnode + le32_to_cpu(dnode->first_free) - (char *)de_next_de(de));
0588         } else {
0589             struct dnode *d1;
0590             struct quad_buffer_head qbh1;
0591             *(dnode_secno *) ((void *) de + le16_to_cpu(de->length) - 4) = down;
0592             if ((d1 = hpfs_map_dnode(i->i_sb, down, &qbh1))) {
0593                 d1->up = cpu_to_le32(up);
0594                 hpfs_mark_4buffers_dirty(&qbh1);
0595                 hpfs_brelse4(&qbh1);
0596             }
0597         }
0598     } else {
0599         hpfs_error(i->i_sb, "delete_empty_dnode: dnode %08x, first_free == %03x", dno, le32_to_cpu(dnode->first_free));
0600         goto end;
0601     }
0602 
0603     if (!de->last) {
0604         struct hpfs_dirent *de_next = de_next_de(de);
0605         struct hpfs_dirent *de_cp;
0606         struct dnode *d1;
0607         struct quad_buffer_head qbh1;
0608         if (!de_next->down) goto endm;
0609         ndown = de_down_pointer(de_next);
0610         if (!(de_cp = kmalloc(le16_to_cpu(de->length), GFP_NOFS))) {
0611             pr_err("out of memory for dtree balancing\n");
0612             goto endm;
0613         }
0614         memcpy(de_cp, de, le16_to_cpu(de->length));
0615         hpfs_delete_de(i->i_sb, dnode, de);
0616         hpfs_mark_4buffers_dirty(&qbh);
0617         hpfs_brelse4(&qbh);
0618         for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, 4);
0619         for_all_poss(i, hpfs_pos_del, ((loff_t)up << 4) | p, 1);
0620         if (de_cp->down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de_cp), &qbh1))) {
0621             d1->up = cpu_to_le32(ndown);
0622             hpfs_mark_4buffers_dirty(&qbh1);
0623             hpfs_brelse4(&qbh1);
0624         }
0625         hpfs_add_to_dnode(i, ndown, de_cp->name, de_cp->namelen, de_cp, de_cp->down ? de_down_pointer(de_cp) : 0);
0626         /*pr_info("UP-TO-DNODE: %08x (ndown = %08x, down = %08x, dno = %08x)\n",
0627           up, ndown, down, dno);*/
0628         dno = up;
0629         kfree(de_cp);
0630         goto try_it_again;
0631     } else {
0632         struct hpfs_dirent *de_prev = dnode_pre_last_de(dnode);
0633         struct hpfs_dirent *de_cp;
0634         struct dnode *d1;
0635         struct quad_buffer_head qbh1;
0636         dnode_secno dlp;
0637         if (!de_prev) {
0638             hpfs_error(i->i_sb, "delete_empty_dnode: empty dnode %08x", up);
0639             hpfs_mark_4buffers_dirty(&qbh);
0640             hpfs_brelse4(&qbh);
0641             dno = up;
0642             goto try_it_again;
0643         }
0644         if (!de_prev->down) goto endm;
0645         ndown = de_down_pointer(de_prev);
0646         if ((d1 = hpfs_map_dnode(i->i_sb, ndown, &qbh1))) {
0647             struct hpfs_dirent *del = dnode_last_de(d1);
0648             dlp = del->down ? de_down_pointer(del) : 0;
0649             if (!dlp && down) {
0650                 if (le32_to_cpu(d1->first_free) > 2044) {
0651                     if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
0652                         pr_err("unbalanced dnode tree, see hpfs.txt 4 more info\n");
0653                         pr_err("terminating balancing operation\n");
0654                     }
0655                     hpfs_brelse4(&qbh1);
0656                     goto endm;
0657                 }
0658                 if (hpfs_sb(i->i_sb)->sb_chk >= 2) {
0659                     pr_err("unbalanced dnode tree, see hpfs.txt 4 more info\n");
0660                     pr_err("goin'on\n");
0661                 }
0662                 le16_add_cpu(&del->length, 4);
0663                 del->down = 1;
0664                 le32_add_cpu(&d1->first_free, 4);
0665             }
0666             if (dlp && !down) {
0667                 le16_add_cpu(&del->length, -4);
0668                 del->down = 0;
0669                 le32_add_cpu(&d1->first_free, -4);
0670             } else if (down)
0671                 *(__le32 *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down);
0672         } else goto endm;
0673         if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) {
0674             pr_err("out of memory for dtree balancing\n");
0675             hpfs_brelse4(&qbh1);
0676             goto endm;
0677         }
0678         hpfs_mark_4buffers_dirty(&qbh1);
0679         hpfs_brelse4(&qbh1);
0680         memcpy(de_cp, de_prev, le16_to_cpu(de_prev->length));
0681         hpfs_delete_de(i->i_sb, dnode, de_prev);
0682         if (!de_prev->down) {
0683             le16_add_cpu(&de_prev->length, 4);
0684             de_prev->down = 1;
0685             le32_add_cpu(&dnode->first_free, 4);
0686         }
0687         *(__le32 *) ((void *) de_prev + le16_to_cpu(de_prev->length) - 4) = cpu_to_le32(ndown);
0688         hpfs_mark_4buffers_dirty(&qbh);
0689         hpfs_brelse4(&qbh);
0690         for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4);
0691         for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | p, ((loff_t)up << 4) | (p - 1));
0692         if (down) if ((d1 = hpfs_map_dnode(i->i_sb, de_down_pointer(de), &qbh1))) {
0693             d1->up = cpu_to_le32(ndown);
0694             hpfs_mark_4buffers_dirty(&qbh1);
0695             hpfs_brelse4(&qbh1);
0696         }
0697         hpfs_add_to_dnode(i, ndown, de_cp->name, de_cp->namelen, de_cp, dlp);
0698         dno = up;
0699         kfree(de_cp);
0700         goto try_it_again;
0701     }
0702     endm:
0703     hpfs_mark_4buffers_dirty(&qbh);
0704     end:
0705     hpfs_brelse4(&qbh);
0706 }
0707 
0708 
0709 /* Delete dirent from directory */
0710 
0711 int hpfs_remove_dirent(struct inode *i, dnode_secno dno, struct hpfs_dirent *de,
0712                struct quad_buffer_head *qbh, int depth)
0713 {
0714     struct dnode *dnode = qbh->data;
0715     dnode_secno down = 0;
0716     loff_t t;
0717     if (de->first || de->last) {
0718         hpfs_error(i->i_sb, "hpfs_remove_dirent: attempt to delete first or last dirent in dnode %08x", dno);
0719         hpfs_brelse4(qbh);
0720         return 1;
0721     }
0722     if (de->down) down = de_down_pointer(de);
0723     if (depth && (de->down || (de == dnode_first_de(dnode) && de_next_de(de)->last))) {
0724         if (hpfs_check_free_dnodes(i->i_sb, FREE_DNODES_DEL)) {
0725             hpfs_brelse4(qbh);
0726             return 2;
0727         }
0728     }
0729     for_all_poss(i, hpfs_pos_del, (t = get_pos(dnode, de)) + 1, 1);
0730     hpfs_delete_de(i->i_sb, dnode, de);
0731     hpfs_mark_4buffers_dirty(qbh);
0732     hpfs_brelse4(qbh);
0733     if (down) {
0734         dnode_secno a = move_to_top(i, down, dno);
0735         for_all_poss(i, hpfs_pos_subst, 5, t);
0736         if (a) delete_empty_dnode(i, a);
0737         return !a;
0738     }
0739     delete_empty_dnode(i, dno);
0740     return 0;
0741 }
0742 
0743 void hpfs_count_dnodes(struct super_block *s, dnode_secno dno, int *n_dnodes,
0744                int *n_subdirs, int *n_items)
0745 {
0746     struct dnode *dnode;
0747     struct quad_buffer_head qbh;
0748     struct hpfs_dirent *de;
0749     dnode_secno ptr, odno = 0;
0750     int c1, c2 = 0;
0751     int d1, d2 = 0;
0752     go_down:
0753     if (n_dnodes) (*n_dnodes)++;
0754     if (hpfs_sb(s)->sb_chk)
0755         if (hpfs_stop_cycles(s, dno, &c1, &c2, "hpfs_count_dnodes #1")) return;
0756     ptr = 0;
0757     go_up:
0758     if (!(dnode = hpfs_map_dnode(s, dno, &qbh))) return;
0759     if (hpfs_sb(s)->sb_chk) if (odno && odno != -1 && le32_to_cpu(dnode->up) != odno)
0760         hpfs_error(s, "hpfs_count_dnodes: bad up pointer; dnode %08x, down %08x points to %08x", odno, dno, le32_to_cpu(dnode->up));
0761     de = dnode_first_de(dnode);
0762     if (ptr) while(1) {
0763         if (de->down) if (de_down_pointer(de) == ptr) goto process_de;
0764         if (de->last) {
0765             hpfs_brelse4(&qbh);
0766             hpfs_error(s, "hpfs_count_dnodes: pointer to dnode %08x not found in dnode %08x, got here from %08x",
0767                 ptr, dno, odno);
0768             return;
0769         }
0770         de = de_next_de(de);
0771     }
0772     next_de:
0773     if (de->down) {
0774         odno = dno;
0775         dno = de_down_pointer(de);
0776         hpfs_brelse4(&qbh);
0777         goto go_down;
0778     }
0779     process_de:
0780     if (!de->first && !de->last && de->directory && n_subdirs) (*n_subdirs)++;
0781     if (!de->first && !de->last && n_items) (*n_items)++;
0782     if ((de = de_next_de(de)) < dnode_end_de(dnode)) goto next_de;
0783     ptr = dno;
0784     dno = le32_to_cpu(dnode->up);
0785     if (dnode->root_dnode) {
0786         hpfs_brelse4(&qbh);
0787         return;
0788     }
0789     hpfs_brelse4(&qbh);
0790     if (hpfs_sb(s)->sb_chk)
0791         if (hpfs_stop_cycles(s, ptr, &d1, &d2, "hpfs_count_dnodes #2")) return;
0792     odno = -1;
0793     goto go_up;
0794 }
0795 
0796 static struct hpfs_dirent *map_nth_dirent(struct super_block *s, dnode_secno dno, int n,
0797                       struct quad_buffer_head *qbh, struct dnode **dn)
0798 {
0799     int i;
0800     struct hpfs_dirent *de, *de_end;
0801     struct dnode *dnode;
0802     dnode = hpfs_map_dnode(s, dno, qbh);
0803     if (!dnode) return NULL;
0804     if (dn) *dn=dnode;
0805     de = dnode_first_de(dnode);
0806     de_end = dnode_end_de(dnode);
0807     for (i = 1; de < de_end; i++, de = de_next_de(de)) {
0808         if (i == n) {
0809             return de;
0810         }   
0811         if (de->last) break;
0812     }
0813     hpfs_brelse4(qbh);
0814     hpfs_error(s, "map_nth_dirent: n too high; dnode = %08x, requested %08x", dno, n);
0815     return NULL;
0816 }
0817 
0818 dnode_secno hpfs_de_as_down_as_possible(struct super_block *s, dnode_secno dno)
0819 {
0820     struct quad_buffer_head qbh;
0821     dnode_secno d = dno;
0822     dnode_secno up = 0;
0823     struct hpfs_dirent *de;
0824     int c1, c2 = 0;
0825 
0826     again:
0827     if (hpfs_sb(s)->sb_chk)
0828         if (hpfs_stop_cycles(s, d, &c1, &c2, "hpfs_de_as_down_as_possible"))
0829             return d;
0830     if (!(de = map_nth_dirent(s, d, 1, &qbh, NULL))) return dno;
0831     if (hpfs_sb(s)->sb_chk)
0832         if (up && le32_to_cpu(((struct dnode *)qbh.data)->up) != up)
0833             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));
0834     if (!de->down) {
0835         hpfs_brelse4(&qbh);
0836         return d;
0837     }
0838     up = d;
0839     d = de_down_pointer(de);
0840     hpfs_brelse4(&qbh);
0841     goto again;
0842 }
0843 
0844 struct hpfs_dirent *map_pos_dirent(struct inode *inode, loff_t *posp,
0845                    struct quad_buffer_head *qbh)
0846 {
0847     loff_t pos;
0848     unsigned c;
0849     dnode_secno dno;
0850     struct hpfs_dirent *de, *d;
0851     struct hpfs_dirent *up_de;
0852     struct hpfs_dirent *end_up_de;
0853     struct dnode *dnode;
0854     struct dnode *up_dnode;
0855     struct quad_buffer_head qbh0;
0856 
0857     pos = *posp;
0858     dno = pos >> 6 << 2;
0859     pos &= 077;
0860     if (!(de = map_nth_dirent(inode->i_sb, dno, pos, qbh, &dnode)))
0861         goto bail;
0862 
0863     /* Going to the next dirent */
0864     if ((d = de_next_de(de)) < dnode_end_de(dnode)) {
0865         if (!(++*posp & 077)) {
0866             hpfs_error(inode->i_sb,
0867                 "map_pos_dirent: pos crossed dnode boundary; pos = %08llx",
0868                 (unsigned long long)*posp);
0869             goto bail;
0870         }
0871         /* We're going down the tree */
0872         if (d->down) {
0873             *posp = ((loff_t) hpfs_de_as_down_as_possible(inode->i_sb, de_down_pointer(d)) << 4) + 1;
0874         }
0875     
0876         return de;
0877     }
0878 
0879     /* Going up */
0880     if (dnode->root_dnode) goto bail;
0881 
0882     if (!(up_dnode = hpfs_map_dnode(inode->i_sb, le32_to_cpu(dnode->up), &qbh0)))
0883         goto bail;
0884 
0885     end_up_de = dnode_end_de(up_dnode);
0886     c = 0;
0887     for (up_de = dnode_first_de(up_dnode); up_de < end_up_de;
0888          up_de = de_next_de(up_de)) {
0889         if (!(++c & 077)) hpfs_error(inode->i_sb,
0890             "map_pos_dirent: pos crossed dnode boundary; dnode = %08x", le32_to_cpu(dnode->up));
0891         if (up_de->down && de_down_pointer(up_de) == dno) {
0892             *posp = ((loff_t) le32_to_cpu(dnode->up) << 4) + c;
0893             hpfs_brelse4(&qbh0);
0894             return de;
0895         }
0896     }
0897     
0898     hpfs_error(inode->i_sb, "map_pos_dirent: pointer to dnode %08x not found in parent dnode %08x",
0899         dno, le32_to_cpu(dnode->up));
0900     hpfs_brelse4(&qbh0);
0901     
0902     bail:
0903     *posp = 12;
0904     return de;
0905 }
0906 
0907 /* Find a dirent in tree */
0908 
0909 struct hpfs_dirent *map_dirent(struct inode *inode, dnode_secno dno,
0910                    const unsigned char *name, unsigned len,
0911                    dnode_secno *dd, struct quad_buffer_head *qbh)
0912 {
0913     struct dnode *dnode;
0914     struct hpfs_dirent *de;
0915     struct hpfs_dirent *de_end;
0916     int c1, c2 = 0;
0917 
0918     if (!S_ISDIR(inode->i_mode)) hpfs_error(inode->i_sb, "map_dirent: not a directory\n");
0919     again:
0920     if (hpfs_sb(inode->i_sb)->sb_chk)
0921         if (hpfs_stop_cycles(inode->i_sb, dno, &c1, &c2, "map_dirent")) return NULL;
0922     if (!(dnode = hpfs_map_dnode(inode->i_sb, dno, qbh))) return NULL;
0923     
0924     de_end = dnode_end_de(dnode);
0925     for (de = dnode_first_de(dnode); de < de_end; de = de_next_de(de)) {
0926         int t = hpfs_compare_names(inode->i_sb, name, len, de->name, de->namelen, de->last);
0927         if (!t) {
0928             if (dd) *dd = dno;
0929             return de;
0930         }
0931         if (t < 0) {
0932             if (de->down) {
0933                 dno = de_down_pointer(de);
0934                 hpfs_brelse4(qbh);
0935                 goto again;
0936             }
0937         break;
0938         }
0939     }
0940     hpfs_brelse4(qbh);
0941     return NULL;
0942 }
0943 
0944 /*
0945  * Remove empty directory. In normal cases it is only one dnode with two
0946  * entries, but we must handle also such obscure cases when it's a tree
0947  * of empty dnodes.
0948  */
0949 
0950 void hpfs_remove_dtree(struct super_block *s, dnode_secno dno)
0951 {
0952     struct quad_buffer_head qbh;
0953     struct dnode *dnode;
0954     struct hpfs_dirent *de;
0955     dnode_secno d1, d2, rdno = dno;
0956     while (1) {
0957         if (!(dnode = hpfs_map_dnode(s, dno, &qbh))) return;
0958         de = dnode_first_de(dnode);
0959         if (de->last) {
0960             if (de->down) d1 = de_down_pointer(de);
0961             else goto error;
0962             hpfs_brelse4(&qbh);
0963             hpfs_free_dnode(s, dno);
0964             dno = d1;
0965         } else break;
0966     }
0967     if (!de->first) goto error;
0968     d1 = de->down ? de_down_pointer(de) : 0;
0969     de = de_next_de(de);
0970     if (!de->last) goto error;
0971     d2 = de->down ? de_down_pointer(de) : 0;
0972     hpfs_brelse4(&qbh);
0973     hpfs_free_dnode(s, dno);
0974     do {
0975         while (d1) {
0976             if (!(dnode = hpfs_map_dnode(s, dno = d1, &qbh))) return;
0977             de = dnode_first_de(dnode);
0978             if (!de->last) goto error;
0979             d1 = de->down ? de_down_pointer(de) : 0;
0980             hpfs_brelse4(&qbh);
0981             hpfs_free_dnode(s, dno);
0982         }
0983         d1 = d2;
0984         d2 = 0;
0985     } while (d1);
0986     return;
0987     error:
0988     hpfs_brelse4(&qbh);
0989     hpfs_free_dnode(s, dno);
0990     hpfs_error(s, "directory %08x is corrupted or not empty", rdno);
0991 }
0992 
0993 /* 
0994  * Find dirent for specified fnode. Use truncated 15-char name in fnode as
0995  * a help for searching.
0996  */
0997 
0998 struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
0999                      struct fnode *f, struct quad_buffer_head *qbh)
1000 {
1001     unsigned char *name1;
1002     unsigned char *name2;
1003     int name1len, name2len;
1004     struct dnode *d;
1005     dnode_secno dno, downd;
1006     struct fnode *upf;
1007     struct buffer_head *bh;
1008     struct hpfs_dirent *de, *de_end;
1009     int c;
1010     int c1, c2 = 0;
1011     int d1, d2 = 0;
1012     name1 = f->name;
1013     if (!(name2 = kmalloc(256, GFP_NOFS))) {
1014         pr_err("out of memory, can't map dirent\n");
1015         return NULL;
1016     }
1017     if (f->len <= 15)
1018         memcpy(name2, name1, name1len = name2len = f->len);
1019     else {
1020         memcpy(name2, name1, 15);
1021         memset(name2 + 15, 0xff, 256 - 15);
1022         /*name2[15] = 0xff;*/
1023         name1len = 15; name2len = 256;
1024     }
1025     if (!(upf = hpfs_map_fnode(s, le32_to_cpu(f->up), &bh))) {
1026         kfree(name2);
1027         return NULL;
1028     }   
1029     if (!fnode_is_dir(upf)) {
1030         brelse(bh);
1031         hpfs_error(s, "fnode %08x has non-directory parent %08x", fno, le32_to_cpu(f->up));
1032         kfree(name2);
1033         return NULL;
1034     }
1035     dno = le32_to_cpu(upf->u.external[0].disk_secno);
1036     brelse(bh);
1037     go_down:
1038     downd = 0;
1039     go_up:
1040     if (!(d = hpfs_map_dnode(s, dno, qbh))) {
1041         kfree(name2);
1042         return NULL;
1043     }
1044     de_end = dnode_end_de(d);
1045     de = dnode_first_de(d);
1046     if (downd) {
1047         while (de < de_end) {
1048             if (de->down) if (de_down_pointer(de) == downd) goto f;
1049             de = de_next_de(de);
1050         }
1051         hpfs_error(s, "pointer to dnode %08x not found in dnode %08x", downd, dno);
1052         hpfs_brelse4(qbh);
1053         kfree(name2);
1054         return NULL;
1055     }
1056     next_de:
1057     if (le32_to_cpu(de->fnode) == fno) {
1058         kfree(name2);
1059         return de;
1060     }
1061     c = hpfs_compare_names(s, name1, name1len, de->name, de->namelen, de->last);
1062     if (c < 0 && de->down) {
1063         dno = de_down_pointer(de);
1064         hpfs_brelse4(qbh);
1065         if (hpfs_sb(s)->sb_chk)
1066             if (hpfs_stop_cycles(s, dno, &c1, &c2, "map_fnode_dirent #1")) {
1067                 kfree(name2);
1068                 return NULL;
1069         }
1070         goto go_down;
1071     }
1072     f:
1073     if (le32_to_cpu(de->fnode) == fno) {
1074         kfree(name2);
1075         return de;
1076     }
1077     c = hpfs_compare_names(s, name2, name2len, de->name, de->namelen, de->last);
1078     if (c < 0 && !de->last) goto not_found;
1079     if ((de = de_next_de(de)) < de_end) goto next_de;
1080     if (d->root_dnode) goto not_found;
1081     downd = dno;
1082     dno = le32_to_cpu(d->up);
1083     hpfs_brelse4(qbh);
1084     if (hpfs_sb(s)->sb_chk)
1085         if (hpfs_stop_cycles(s, downd, &d1, &d2, "map_fnode_dirent #2")) {
1086             kfree(name2);
1087             return NULL;
1088         }
1089     goto go_up;
1090     not_found:
1091     hpfs_brelse4(qbh);
1092     hpfs_error(s, "dirent for fnode %08x not found", fno);
1093     kfree(name2);
1094     return NULL;
1095 }