Skip to content

Commit eeb5b4a

Browse files
kevin-dankOGAWAHirofumi
authored andcommitted
fat: Fix stat->f_namelen
I found that the length of a file name when created cannot exceed 255 characters, yet, pathconf(), via statfs(), returns the maximum as 260. Signed-off-by: Kevin Dankwardt <k@kcomputing.com> Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
1 parent 8045e29 commit eeb5b4a

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎fs/fat/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
558558
buf->f_bavail = sbi->free_clusters;
559559
buf->f_fsid.val[0] = (u32)id;
560560
buf->f_fsid.val[1] = (u32)(id >> 32);
561-
buf->f_namelen = sbi->options.isvfat ? 260 : 12;
561+
buf->f_namelen = sbi->options.isvfat ? FAT_LFN_LEN : 12;
562562

563563
return 0;
564564
}

‎fs/fat/namei_vfat.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,14 +502,14 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
502502
*outlen = utf8s_to_utf16s(name, len, (wchar_t *)outname);
503503
if (*outlen < 0)
504504
return *outlen;
505-
else if (*outlen > 255)
505+
else if (*outlen > FAT_LFN_LEN)
506506
return -ENAMETOOLONG;
507507

508508
op = &outname[*outlen * sizeof(wchar_t)];
509509
} else {
510510
if (nls) {
511511
for (i = 0, ip = name, op = outname, *outlen = 0;
512-
i < len && *outlen <= 255;
512+
i < len && *outlen <= FAT_LFN_LEN;
513513
*outlen += 1)
514514
{
515515
if (escape && (*ip == ':')) {
@@ -549,7 +549,7 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
549549
return -ENAMETOOLONG;
550550
} else {
551551
for (i = 0, ip = name, op = outname, *outlen = 0;
552-
i < len && *outlen <= 255;
552+
i < len && *outlen <= FAT_LFN_LEN;
553553
i++, *outlen += 1)
554554
{
555555
*op++ = *ip++;

‎include/linux/msdos_fs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */
1616
#define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
1717
#define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
18+
#define MSDOS_LONGNAME 256 /* maximum name length */
1819
#define CF_LE_W(v) le16_to_cpu(v)
1920
#define CF_LE_L(v) le32_to_cpu(v)
2021
#define CT_LE_W(v) cpu_to_le16(v)
@@ -47,8 +48,8 @@
4748
#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
4849
#define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
4950

51+
#define FAT_LFN_LEN 255 /* maximum long name length */
5052
#define MSDOS_NAME 11 /* maximum name length */
51-
#define MSDOS_LONGNAME 256 /* maximum name length */
5253
#define MSDOS_SLOTS 21 /* max # of slots for short and long names */
5354
#define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
5455
#define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */

0 commit comments

Comments
 (0)