X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=fs%2Fvfat%2Fnamei.c;h=a3522727ea5b090ea4ee02d925e7327cde21fe7b;hb=5bf6c6e30d8b71d092e8830208e182d84b907fcd;hp=c28add2fbe95eebce0ec79de64e8389be793ea26;hpb=ef29498655b18d2bfd69048e20835d19333981ab;p=linux-2.6-omap-h63xx.git diff --git a/fs/vfat/namei.c b/fs/vfat/namei.c index c28add2fbe9..a3522727ea5 100644 --- a/fs/vfat/namei.c +++ b/fs/vfat/namei.c @@ -176,15 +176,10 @@ static inline int vfat_is_used_badchars(const wchar_t *s, int len) for (i = 0; i < len; i++) if (vfat_bad_char(s[i])) return -EINVAL; - return 0; -} -static int vfat_valid_longname(const unsigned char *name, unsigned int len) -{ - if (name[len - 1] == ' ') + if (s[i - 1] == ' ') /* last character cannot be space */ return -EINVAL; - if (len >= 256) - return -ENAMETOOLONG; + return 0; } @@ -477,7 +472,7 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname, if (utf8) { int name_len = strlen(name); - *outlen = utf8_mbstowcs((wchar_t *)outname, name, PAGE_SIZE); + *outlen = utf8_mbstowcs((wchar_t *)outname, name, PATH_MAX); /* * We stripped '.'s before and set len appropriately, @@ -485,11 +480,14 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname, */ *outlen -= (name_len - len); + if (*outlen > 255) + return -ENAMETOOLONG; + op = &outname[*outlen * sizeof(wchar_t)]; } else { if (nls) { for (i = 0, ip = name, op = outname, *outlen = 0; - i < len && *outlen <= 260; + i < len && *outlen <= 255; *outlen += 1) { if (escape && (*ip == ':')) { @@ -525,18 +523,20 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname, op += 2; } } + if (i < len) + return -ENAMETOOLONG; } else { for (i = 0, ip = name, op = outname, *outlen = 0; - i < len && *outlen <= 260; + i < len && *outlen <= 255; i++, *outlen += 1) { *op++ = *ip++; *op++ = 0; } + if (i < len) + return -ENAMETOOLONG; } } - if (*outlen > 260) - return -ENAMETOOLONG; *longlen = *outlen; if (*outlen % 13) { @@ -565,7 +565,6 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name, struct fat_mount_options *opts = &sbi->options; struct msdos_dir_slot *ps; struct msdos_dir_entry *de; - unsigned long page; unsigned char cksum, lcase; unsigned char msdos_name[MSDOS_NAME]; wchar_t *uname; @@ -574,15 +573,11 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name, loff_t offset; *nr_slots = 0; - err = vfat_valid_longname(name, len); - if (err) - return err; - page = __get_free_page(GFP_KERNEL); - if (!page) + uname = __getname(); + if (!uname) return -ENOMEM; - uname = (wchar_t *)page; err = xlate_to_uni(name, len, (unsigned char *)uname, &ulen, &usize, opts->unicode_xlate, opts->utf8, sbi->nls_io); if (err) @@ -634,7 +629,7 @@ shortname: de->starthi = cpu_to_le16(cluster >> 16); de->size = 0; out_free: - free_page(page); + __putname(uname); return err; } @@ -705,7 +700,7 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry, brelse(sinfo.bh); if (IS_ERR(inode)) { unlock_kernel(); - return ERR_PTR(PTR_ERR(inode)); + return ERR_CAST(inode); } alias = d_find_alias(inode); if (alias) { @@ -991,7 +986,7 @@ error_inode: if (corrupt < 0) { fat_fs_panic(new_dir->i_sb, "%s: Filesystem corrupted (i_pos %lld)", - __FUNCTION__, sinfo.i_pos); + __func__, sinfo.i_pos); } goto out; } @@ -1003,7 +998,7 @@ static const struct inode_operations vfat_dir_inode_operations = { .mkdir = vfat_mkdir, .rmdir = vfat_rmdir, .rename = vfat_rename, - .setattr = fat_notify_change, + .setattr = fat_setattr, .getattr = fat_getattr, };