2 * linux/fs/vfat/namei.c
4 * Written 1992,1993 by Werner Almesberger
6 * Windows95/Windows NT compatible extended MSDOS filesystem
7 * by Gordon Chaffee Copyright (C) 1995. Send bug reports for the
8 * VFAT filesystem to <chaffee@cs.berkeley.edu>. Specify
9 * what file operation caused you trouble and if you can duplicate
10 * the problem, send a script that demonstrates it.
12 * Short name translation 1999, 2001 by Wolfram Pienkoss <wp@bszh.de>
14 * Support Multibyte character and cleanup by
15 * OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
18 #include <linux/module.h>
20 #include <linux/jiffies.h>
21 #include <linux/msdos_fs.h>
22 #include <linux/ctype.h>
23 #include <linux/slab.h>
24 #include <linux/smp_lock.h>
25 #include <linux/buffer_head.h>
26 #include <linux/namei.h>
28 static int vfat_hashi(struct dentry *parent, struct qstr *qstr);
29 static int vfat_hash(struct dentry *parent, struct qstr *qstr);
30 static int vfat_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b);
31 static int vfat_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b);
32 static int vfat_revalidate(struct dentry *dentry, struct nameidata *nd);
34 static struct dentry_operations vfat_dentry_ops[4] = {
37 .d_compare = vfat_cmpi,
40 .d_revalidate = vfat_revalidate,
42 .d_compare = vfat_cmpi,
46 .d_compare = vfat_cmp,
49 .d_revalidate = vfat_revalidate,
51 .d_compare = vfat_cmp,
55 static int vfat_revalidate(struct dentry *dentry, struct nameidata *nd)
59 if (!dentry->d_inode &&
60 nd && !(nd->flags & LOOKUP_CONTINUE) && (nd->flags & LOOKUP_CREATE))
62 * negative dentry is dropped, in order to make sure
63 * to use the name which a user desires if this is
68 spin_lock(&dentry->d_lock);
69 if (dentry->d_time != dentry->d_parent->d_inode->i_version)
71 spin_unlock(&dentry->d_lock);
76 static inline unsigned char
77 vfat_tolower(struct nls_table *t, unsigned char c)
79 unsigned char nc = t->charset2lower[c];
84 static inline unsigned char
85 vfat_toupper(struct nls_table *t, unsigned char c)
87 unsigned char nc = t->charset2upper[c];
93 vfat_strnicmp(struct nls_table *t, const unsigned char *s1,
94 const unsigned char *s2, int len)
97 if (vfat_tolower(t, *s1++) != vfat_tolower(t, *s2++))
103 /* returns the length of a struct qstr, ignoring trailing dots */
104 static unsigned int vfat_striptail_len(struct qstr *qstr)
106 unsigned int len = qstr->len;
108 while (len && qstr->name[len-1] == '.')
115 * Compute the hash for the vfat name corresponding to the dentry.
116 * Note: if the name is invalid, we leave the hash code unchanged so
117 * that the existing dentry can be used. The vfat fs routines will
118 * return ENOENT or EINVAL as appropriate.
120 static int vfat_hash(struct dentry *dentry, struct qstr *qstr)
122 qstr->hash = full_name_hash(qstr->name, vfat_striptail_len(qstr));
128 * Compute the hash for the vfat name corresponding to the dentry.
129 * Note: if the name is invalid, we leave the hash code unchanged so
130 * that the existing dentry can be used. The vfat fs routines will
131 * return ENOENT or EINVAL as appropriate.
133 static int vfat_hashi(struct dentry *dentry, struct qstr *qstr)
135 struct nls_table *t = MSDOS_SB(dentry->d_inode->i_sb)->nls_io;
136 const unsigned char *name;
141 len = vfat_striptail_len(qstr);
143 hash = init_name_hash();
145 hash = partial_name_hash(vfat_tolower(t, *name++), hash);
146 qstr->hash = end_name_hash(hash);
152 * Case insensitive compare of two vfat names.
154 static int vfat_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b)
156 struct nls_table *t = MSDOS_SB(dentry->d_inode->i_sb)->nls_io;
157 unsigned int alen, blen;
159 /* A filename cannot end in '.' or we treat it like it has none */
160 alen = vfat_striptail_len(a);
161 blen = vfat_striptail_len(b);
163 if (vfat_strnicmp(t, a->name, b->name, alen) == 0)
170 * Case sensitive compare of two vfat names.
172 static int vfat_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b)
174 unsigned int alen, blen;
176 /* A filename cannot end in '.' or we treat it like it has none */
177 alen = vfat_striptail_len(a);
178 blen = vfat_striptail_len(b);
180 if (strncmp(a->name, b->name, alen) == 0)
186 /* Characters that are undesirable in an MS-DOS file name */
188 static wchar_t bad_chars[] = {
189 /* `*' `?' `<' `>' `|' `"' `:' `/' */
190 0x002A, 0x003F, 0x003C, 0x003E, 0x007C, 0x0022, 0x003A, 0x002F,
194 #define IS_BADCHAR(uni) (vfat_unistrchr(bad_chars, (uni)) != NULL)
196 static wchar_t replace_chars[] = {
197 /* `[' `]' `;' `,' `+' `=' */
198 0x005B, 0x005D, 0x003B, 0x002C, 0x002B, 0x003D, 0,
200 #define IS_REPLACECHAR(uni) (vfat_unistrchr(replace_chars, (uni)) != NULL)
202 static wchar_t skip_chars[] = {
206 #define IS_SKIPCHAR(uni) \
207 ((wchar_t)(uni) == skip_chars[0] || (wchar_t)(uni) == skip_chars[1])
209 static inline wchar_t *vfat_unistrchr(const wchar_t *s, const wchar_t c)
214 return (wchar_t *) s;
217 static inline int vfat_is_used_badchars(const wchar_t *s, int len)
221 for (i = 0; i < len; i++)
222 if (s[i] < 0x0020 || IS_BADCHAR(s[i]))
227 static int vfat_valid_longname(const unsigned char *name, unsigned int len)
229 if (len && name[len-1] == ' ')
234 /* MS-DOS "device special files" */
235 if (len == 3 || (len > 3 && name[3] == '.')) { /* basename == 3 */
236 if (!strnicmp(name, "aux", 3) ||
237 !strnicmp(name, "con", 3) ||
238 !strnicmp(name, "nul", 3) ||
239 !strnicmp(name, "prn", 3))
242 if (len == 4 || (len > 4 && name[4] == '.')) { /* basename == 4 */
243 /* "com1", "com2", ... */
244 if ('1' <= name[3] && name[3] <= '9') {
245 if (!strnicmp(name, "com", 3) ||
246 !strnicmp(name, "lpt", 3))
254 static int vfat_find_form(struct inode *dir, unsigned char *name)
256 struct msdos_dir_entry *de;
257 struct buffer_head *bh = NULL;
261 res = fat_scan(dir, name, &bh, &de, &i_pos);
269 * 1) Valid characters for the 8.3 format alias are any combination of
270 * letters, uppercase alphabets, digits, any of the
271 * following special characters:
272 * $ % ' ` - @ { } ~ ! # ( ) & _ ^
273 * In this case Longfilename is not stored in disk.
276 * File name and extension name is contain uppercase/lowercase
277 * only. And it is expressed by CASE_LOWER_BASE and CASE_LOWER_EXT.
279 * 2) File name is 8.3 format, but it contain the uppercase and
280 * lowercase char, muliti bytes char, etc. In this case numtail is not
281 * added, but Longfilename is stored.
283 * 3) When the one except for the above, or the following special
284 * character are contained:
286 * numtail is added, and Longfilename must be stored in disk .
288 struct shortname_info {
289 unsigned char lower:1,
293 #define INIT_SHORTNAME_INFO(x) do { \
299 static inline unsigned char
300 shortname_info_to_lcase(struct shortname_info *base,
301 struct shortname_info *ext)
303 unsigned char lcase = 0;
305 if (base->valid && ext->valid) {
306 if (!base->upper && base->lower && (ext->lower || ext->upper))
307 lcase |= CASE_LOWER_BASE;
308 if (!ext->upper && ext->lower && (base->lower || base->upper))
309 lcase |= CASE_LOWER_EXT;
315 static inline int to_shortname_char(struct nls_table *nls,
316 unsigned char *buf, int buf_size, wchar_t *src,
317 struct shortname_info *info)
321 if (IS_SKIPCHAR(*src)) {
325 if (IS_REPLACECHAR(*src)) {
331 len = nls->uni2char(*src, buf, buf_size);
336 } else if (len == 1) {
337 unsigned char prev = buf[0];
339 if (buf[0] >= 0x7F) {
344 buf[0] = vfat_toupper(nls, buf[0]);
345 if (isalpha(buf[0])) {
360 * Given a valid longname, create a unique shortname. Make sure the
361 * shortname does not exist
362 * Returns negative number on error, 0 for a normal
363 * return, and 1 for valid shortname
365 static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
366 wchar_t *uname, int ulen,
367 unsigned char *name_res, unsigned char *lcase)
369 wchar_t *ip, *ext_start, *end, *name_start;
370 unsigned char base[9], ext[4], buf[8], *p;
371 unsigned char charbuf[NLS_MAX_CHARSET_SIZE];
373 int sz = 0, extlen, baselen, i, numtail_baselen, numtail2_baselen;
375 struct shortname_info base_info, ext_info;
376 unsigned short opt_shortname = MSDOS_SB(dir->i_sb)->options.shortname;
379 INIT_SHORTNAME_INFO(&base_info);
380 INIT_SHORTNAME_INFO(&ext_info);
382 /* Now, we need to create a shortname from the long name */
383 ext_start = end = &uname[ulen];
384 while (--ext_start >= uname) {
385 if (*ext_start == 0x002E) { /* is `.' */
386 if (ext_start == end - 1) {
394 if (ext_start == uname - 1) {
397 } else if (ext_start) {
399 * Names which start with a dot could be just
400 * an extension eg. "...test". In this case Win95
401 * uses the extension as the name and sets no extension.
403 name_start = &uname[0];
404 while (name_start < ext_start) {
405 if (!IS_SKIPCHAR(*name_start))
409 if (name_start != ext_start) {
410 sz = ext_start - uname;
419 numtail2_baselen = 2;
420 for (baselen = i = 0, p = base, ip = uname; i < sz; i++, ip++) {
421 chl = to_shortname_char(nls, charbuf, sizeof(charbuf),
426 if (baselen < 2 && (baselen + chl) > 2)
427 numtail2_baselen = baselen;
428 if (baselen < 6 && (baselen + chl) > 6)
429 numtail_baselen = baselen;
430 for (chi = 0; chi < chl; chi++){
437 if ((chi < chl - 1) || (ip + 1) - uname < sz)
448 for (p = ext, ip = ext_start; extlen < 3 && ip < end; ip++) {
449 chl = to_shortname_char(nls, charbuf, sizeof(charbuf),
454 if ((extlen + chl) > 3) {
458 for (chi = 0; chi < chl; chi++) {
470 base[baselen] = '\0';
472 /* Yes, it can happen. ".\xe5" would do it. */
473 if (base[0] == DELETED_FLAG)
476 /* OK, at this point we know that base is not longer than 8 symbols,
477 * ext is not longer than 3, base is nonempty, both don't contain
478 * any bad symbols (lowercase transformed to uppercase).
481 memset(name_res, ' ', MSDOS_NAME);
482 memcpy(name_res, base, baselen);
483 memcpy(name_res + 8, ext, extlen);
485 if (is_shortname && base_info.valid && ext_info.valid) {
486 if (vfat_find_form(dir, name_res) == 0)
489 if (opt_shortname & VFAT_SFN_CREATE_WIN95) {
490 return (base_info.upper && ext_info.upper);
491 } else if (opt_shortname & VFAT_SFN_CREATE_WINNT) {
492 if ((base_info.upper || base_info.lower)
493 && (ext_info.upper || ext_info.lower)) {
494 *lcase = shortname_info_to_lcase(&base_info,
504 if (MSDOS_SB(dir->i_sb)->options.numtail == 0)
505 if (vfat_find_form(dir, name_res) < 0)
509 * Try to find a unique extension. This used to
510 * iterate through all possibilities sequentially,
511 * but that gave extremely bad performance. Windows
512 * only tries a few cases before using random
513 * values for part of the base.
517 baselen = numtail_baselen;
520 name_res[baselen] = '~';
521 for (i = 1; i < 10; i++) {
522 name_res[baselen+1] = i + '0';
523 if (vfat_find_form(dir, name_res) < 0)
527 i = jiffies & 0xffff;
528 sz = (jiffies >> 16) & 0x7;
530 baselen = numtail2_baselen;
533 name_res[baselen+4] = '~';
534 name_res[baselen+5] = '1' + sz;
536 sprintf(buf, "%04X", i);
537 memcpy(&name_res[baselen], buf, 4);
538 if (vfat_find_form(dir, name_res) < 0)
545 /* Translate a string, including coded sequences into Unicode */
547 xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
548 int *longlen, int *outlen, int escape, int utf8,
549 struct nls_table *nls)
551 const unsigned char *ip;
559 int name_len = strlen(name);
561 *outlen = utf8_mbstowcs((wchar_t *)outname, name, PAGE_SIZE);
564 * We stripped '.'s before and set len appropriately,
565 * but utf8_mbstowcs doesn't care about len
567 *outlen -= (name_len-len);
569 op = &outname[*outlen * sizeof(wchar_t)];
572 for (i = 0, ip = name, op = outname, *outlen = 0;
573 i < len && *outlen <= 260; *outlen += 1)
575 if (escape && (*ip == ':')) {
579 for (k = 1; k < 5; k++) {
582 if (nc >= '0' && nc <= '9') {
586 if (nc >= 'a' && nc <= 'f') {
587 ec |= nc - ('a' - 10);
590 if (nc >= 'A' && nc <= 'F') {
591 ec |= nc - ('A' - 10);
601 if ((charlen = nls->char2uni(ip, len-i, (wchar_t *)op)) < 0)
609 for (i = 0, ip = name, op = outname, *outlen = 0;
610 i < len && *outlen <= 260; i++, *outlen += 1)
618 return -ENAMETOOLONG;
626 fill = 13 - (*outlen % 13);
627 for (i = 0; i < fill; i++) {
638 static int vfat_build_slots(struct inode *dir, const unsigned char *name,
639 int len, struct msdos_dir_slot *ds,
640 int *slots, int is_dir)
642 struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
643 struct fat_mount_options *opts = &sbi->options;
644 struct msdos_dir_slot *ps;
645 struct msdos_dir_entry *de;
647 unsigned char cksum, lcase;
648 unsigned char msdos_name[MSDOS_NAME];
650 int res, slot, ulen, usize, i;
654 if (!vfat_valid_longname(name, len))
657 if(!(page = __get_free_page(GFP_KERNEL)))
660 uname = (wchar_t *)page;
661 res = xlate_to_uni(name, len, (unsigned char *)uname, &ulen, &usize,
662 opts->unicode_xlate, opts->utf8, sbi->nls_io);
666 res = vfat_is_used_badchars(uname, ulen);
670 res = vfat_create_shortname(dir, sbi->nls_disk, uname, ulen,
675 de = (struct msdos_dir_entry *)ds;
680 /* build the entry of long file name */
682 for (cksum = i = 0; i < 11; i++) {
683 cksum = (((cksum&1)<<7)|((cksum&0xfe)>>1)) + msdos_name[i];
686 for (ps = ds, slot = *slots; slot > 0; slot--, ps++) {
690 ps->alias_checksum = cksum;
692 offset = (slot - 1) * 13;
693 fatwchar_to16(ps->name0_4, uname + offset, 5);
694 fatwchar_to16(ps->name5_10, uname + offset + 5, 6);
695 fatwchar_to16(ps->name11_12, uname + offset + 11, 2);
698 de = (struct msdos_dir_entry *) ps;
701 /* build the entry of 8.3 alias name */
703 memcpy(de->name, msdos_name, MSDOS_NAME);
704 de->attr = is_dir ? ATTR_DIR : ATTR_ARCH;
706 de->adate = de->cdate = de->date = 0;
707 de->ctime_ms = de->ctime = de->time = 0;
717 static int vfat_add_entry(struct inode *dir,struct qstr* qname,
718 int is_dir, struct vfat_slot_info *sinfo_out,
719 struct buffer_head **bh, struct msdos_dir_entry **de)
721 struct msdos_dir_slot *dir_slots;
723 int res, slots, slot;
725 struct msdos_dir_entry *dummy_de;
726 struct buffer_head *dummy_bh;
729 len = vfat_striptail_len(qname);
734 kmalloc(sizeof(struct msdos_dir_slot) * MSDOS_SLOTS, GFP_KERNEL);
735 if (dir_slots == NULL)
738 res = vfat_build_slots(dir, qname->name, len,
739 dir_slots, &slots, is_dir);
743 /* build the empty directory entry of number of slots */
744 offset = fat_add_entries(dir, slots, &dummy_bh, &dummy_de, &dummy_i_pos);
751 /* Now create the new entry */
753 for (slot = 0; slot < slots; slot++) {
754 if (fat_get_entry(dir, &offset, bh, de, &sinfo_out->i_pos) < 0) {
758 memcpy(*de, dir_slots + slot, sizeof(struct msdos_dir_slot));
759 mark_buffer_dirty(*bh);
763 /* update timestamp */
764 dir->i_ctime = dir->i_mtime = dir->i_atime = CURRENT_TIME;
765 mark_inode_dirty(dir);
767 fat_date_unix2dos(dir->i_mtime.tv_sec, &(*de)->time, &(*de)->date);
768 (*de)->ctime = (*de)->time;
769 (*de)->adate = (*de)->cdate = (*de)->date;
771 mark_buffer_dirty(*bh);
773 /* slots can't be less than 1 */
774 sinfo_out->long_slots = slots - 1;
775 sinfo_out->longname_offset =
776 offset - sizeof(struct msdos_dir_slot) * slots;
783 static int vfat_find(struct inode *dir,struct qstr* qname,
784 struct vfat_slot_info *sinfo, struct buffer_head **last_bh,
785 struct msdos_dir_entry **last_de)
787 struct super_block *sb = dir->i_sb;
792 len = vfat_striptail_len(qname);
796 res = fat_search_long(dir, qname->name, len,
797 (MSDOS_SB(sb)->options.name_check != 's'),
798 &offset, &sinfo->longname_offset);
800 sinfo->long_slots = res-1;
801 if (fat_get_entry(dir,&offset,last_bh,last_de,&sinfo->i_pos)>=0)
805 return res ? res : -ENOENT;
808 struct dentry *vfat_lookup(struct inode *dir,struct dentry *dentry, struct nameidata *nd)
811 struct vfat_slot_info sinfo;
813 struct dentry *alias;
814 struct buffer_head *bh = NULL;
815 struct msdos_dir_entry *de;
819 table = (MSDOS_SB(dir->i_sb)->options.name_check == 's') ? 2 : 0;
820 dentry->d_op = &vfat_dentry_ops[table];
823 res = vfat_find(dir,&dentry->d_name,&sinfo,&bh,&de);
828 inode = fat_build_inode(dir->i_sb, de, sinfo.i_pos, &res);
834 alias = d_find_alias(inode);
836 if (d_invalidate(alias)==0)
847 dentry->d_op = &vfat_dentry_ops[table];
848 dentry->d_time = dentry->d_parent->d_inode->i_version;
849 dentry = d_splice_alias(inode, dentry);
851 dentry->d_op = &vfat_dentry_ops[table];
852 dentry->d_time = dentry->d_parent->d_inode->i_version;
857 int vfat_create(struct inode *dir,struct dentry* dentry,int mode,
858 struct nameidata *nd)
860 struct super_block *sb = dir->i_sb;
861 struct inode *inode = NULL;
862 struct buffer_head *bh = NULL;
863 struct msdos_dir_entry *de;
864 struct vfat_slot_info sinfo;
868 res = vfat_add_entry(dir, &dentry->d_name, 0, &sinfo, &bh, &de);
873 inode = fat_build_inode(sb, de, sinfo.i_pos, &res);
879 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
880 mark_inode_dirty(inode);
883 dentry->d_time = dentry->d_parent->d_inode->i_version;
884 d_instantiate(dentry,inode);
889 static void vfat_remove_entry(struct inode *dir,struct vfat_slot_info *sinfo,
890 struct buffer_head *bh, struct msdos_dir_entry *de)
892 loff_t offset, i_pos;
895 /* remove the shortname */
896 dir->i_mtime = dir->i_atime = CURRENT_TIME;
898 mark_inode_dirty(dir);
899 de->name[0] = DELETED_FLAG;
900 mark_buffer_dirty(bh);
901 /* remove the longname */
902 offset = sinfo->longname_offset; de = NULL;
903 for (i = sinfo->long_slots; i > 0; --i) {
904 if (fat_get_entry(dir, &offset, &bh, &de, &i_pos) < 0)
906 de->name[0] = DELETED_FLAG;
907 de->attr = ATTR_NONE;
908 mark_buffer_dirty(bh);
913 int vfat_rmdir(struct inode *dir,struct dentry* dentry)
916 struct vfat_slot_info sinfo;
917 struct buffer_head *bh = NULL;
918 struct msdos_dir_entry *de;
921 res = fat_dir_empty(dentry->d_inode);
927 res = vfat_find(dir,&dentry->d_name,&sinfo, &bh, &de);
932 dentry->d_inode->i_nlink = 0;
933 dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME;
934 fat_detach(dentry->d_inode);
935 mark_inode_dirty(dentry->d_inode);
937 vfat_remove_entry(dir,&sinfo,bh,de);
943 int vfat_unlink(struct inode *dir, struct dentry* dentry)
946 struct vfat_slot_info sinfo;
947 struct buffer_head *bh = NULL;
948 struct msdos_dir_entry *de;
951 res = vfat_find(dir,&dentry->d_name,&sinfo,&bh,&de);
956 dentry->d_inode->i_nlink = 0;
957 dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME;
958 fat_detach(dentry->d_inode);
959 mark_inode_dirty(dentry->d_inode);
961 vfat_remove_entry(dir,&sinfo,bh,de);
968 int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode)
970 struct super_block *sb = dir->i_sb;
971 struct inode *inode = NULL;
972 struct vfat_slot_info sinfo;
973 struct buffer_head *bh = NULL;
974 struct msdos_dir_entry *de;
978 res = vfat_add_entry(dir, &dentry->d_name, 1, &sinfo, &bh, &de);
983 inode = fat_build_inode(sb, de, sinfo.i_pos, &res);
986 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
987 mark_inode_dirty(inode);
991 inode->i_nlink = 2; /* no need to mark them dirty */
992 res = fat_new_dir(inode, dir, 1);
995 dentry->d_time = dentry->d_parent->d_inode->i_version;
996 d_instantiate(dentry,inode);
1004 inode->i_mtime = inode->i_atime = CURRENT_TIME;
1006 mark_inode_dirty(inode);
1008 vfat_remove_entry(dir,&sinfo,bh,de);
1015 int vfat_rename(struct inode *old_dir,struct dentry *old_dentry,
1016 struct inode *new_dir,struct dentry *new_dentry)
1018 struct buffer_head *old_bh,*new_bh,*dotdot_bh;
1019 struct msdos_dir_entry *old_de,*new_de,*dotdot_de;
1020 loff_t dotdot_i_pos;
1021 struct inode *old_inode, *new_inode;
1023 struct vfat_slot_info old_sinfo,sinfo;
1025 old_bh = new_bh = dotdot_bh = NULL;
1026 old_inode = old_dentry->d_inode;
1027 new_inode = new_dentry->d_inode;
1029 res = vfat_find(old_dir,&old_dentry->d_name,&old_sinfo,&old_bh,&old_de);
1033 is_dir = S_ISDIR(old_inode->i_mode);
1036 if (fat_scan(old_inode, MSDOS_DOTDOT, &dotdot_bh,
1037 &dotdot_de, &dotdot_i_pos) < 0) {
1043 if (new_dentry->d_inode) {
1044 res = vfat_find(new_dir,&new_dentry->d_name,&sinfo,&new_bh,
1046 if (res < 0 || MSDOS_I(new_inode)->i_pos != sinfo.i_pos) {
1047 /* WTF??? Cry and fail. */
1048 printk(KERN_WARNING "vfat_rename: fs corrupted\n");
1053 res = fat_dir_empty(new_inode);
1057 fat_detach(new_inode);
1059 res = vfat_add_entry(new_dir,&new_dentry->d_name,is_dir,&sinfo,
1061 if (res < 0) goto rename_done;
1064 new_dir->i_version++;
1066 /* releases old_bh */
1067 vfat_remove_entry(old_dir,&old_sinfo,old_bh,old_de);
1069 fat_detach(old_inode);
1070 fat_attach(old_inode, sinfo.i_pos);
1071 mark_inode_dirty(old_inode);
1073 old_dir->i_version++;
1074 old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
1075 mark_inode_dirty(old_dir);
1077 new_inode->i_nlink--;
1078 new_inode->i_ctime=CURRENT_TIME;
1082 int start = MSDOS_I(new_dir)->i_logstart;
1083 dotdot_de->start = CT_LE_W(start);
1084 dotdot_de->starthi = CT_LE_W(start>>16);
1085 mark_buffer_dirty(dotdot_bh);
1088 new_inode->i_nlink--;
1091 mark_inode_dirty(new_dir);
1105 /* Public inode operations for the VFAT fs */
1106 struct inode_operations vfat_dir_inode_operations = {
1107 .create = vfat_create,
1108 .lookup = vfat_lookup,
1109 .unlink = vfat_unlink,
1110 .mkdir = vfat_mkdir,
1111 .rmdir = vfat_rmdir,
1112 .rename = vfat_rename,
1113 .setattr = fat_notify_change,
1116 int vfat_fill_super(struct super_block *sb, void *data, int silent)
1120 res = fat_fill_super(sb, data, silent, &vfat_dir_inode_operations, 1);
1124 if (MSDOS_SB(sb)->options.name_check != 's')
1125 sb->s_root->d_op = &vfat_dentry_ops[0];
1127 sb->s_root->d_op = &vfat_dentry_ops[2];