From 4a55531d087badb904a3d8acb8c650386d41c853 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 16 Jul 2009 12:47:15 +1000 Subject: [PATCH] FAT: Added FAT_NO_83NAME This patch adds a new flag field 'FAT_NO_83NAME' for FAT files. When this flag is set on an 8.3 FAT entry, both the MSDOS and VFAT filesystems will skip the entry. For MSDOS this makes the file inaccessible. For VFAT it makes the file only accessible by the long filename. Signed-off-by: Andrew Tridgell --- fs/fat/dir.c | 17 ++++++++++++++++- include/uapi/linux/msdos_fs.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 9d01db37183f..f997d538e84b 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -368,7 +368,8 @@ static int fat_parse_short(struct super_block *sb, dotoffset = 1; } - memcpy(work, de->name, sizeof(work)); + memcpy(work, de->name, sizeof(de->name)); + /* For an explanation of the special treatment of 0x05 in * filenames, see msdos_format_name in namei_msdos.c */ @@ -500,6 +501,13 @@ int fat_search_long(struct inode *inode, const unsigned char *name, goto end_of_dir; } + /* + * The FAT_NO_83NAME flag is used to mark files + * created with no 8.3 short name + */ + if (de->lcase & FAT_NO_83NAME) + goto compare_longname; + /* Never prepend '.' to hidden files here. * That is done only for msdos mounts (and only when * 'dotsOK=yes'); if we are executing here, it is in the @@ -513,6 +521,7 @@ int fat_search_long(struct inode *inode, const unsigned char *name, if (fat_name_match(sbi, name, name_len, bufname, len)) goto found; +compare_longname: if (nr_slots) { void *longname = unicode + FAT_MAX_UNI_CHARS; int size = PATH_MAX - FAT_MAX_UNI_SIZE; @@ -604,6 +613,8 @@ static int __fat_readdir(struct inode *inode, struct file *file, if (de->attr != ATTR_EXT && IS_FREE(de->name)) goto record_end; } else { + if (de->lcase & FAT_NO_83NAME) + goto record_end; if ((de->attr & ATTR_VOLUME) || IS_FREE(de->name)) goto record_end; } @@ -962,6 +973,10 @@ int fat_scan(struct inode *dir, const unsigned char *name, sinfo->bh = NULL; while (fat_get_short_entry(dir, &sinfo->slot_off, &sinfo->bh, &sinfo->de) >= 0) { + /* skip files marked as having no 8.3 short name */ + if (sinfo->de->lcase & FAT_NO_83NAME) + continue; + if (!strncmp(sinfo->de->name, name, MSDOS_NAME)) { sinfo->slot_off -= sizeof(*sinfo->de); sinfo->nr_slots = 1; diff --git a/include/uapi/linux/msdos_fs.h b/include/uapi/linux/msdos_fs.h index a5773899f4d9..22794eb8d1a3 100644 --- a/include/uapi/linux/msdos_fs.h +++ b/include/uapi/linux/msdos_fs.h @@ -48,6 +48,7 @@ #define CASE_LOWER_BASE 8 /* base is lower case */ #define CASE_LOWER_EXT 16 /* extension is lower case */ +#define FAT_NO_83NAME 32 /* no 8.3 short filename for this file */ #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */ #define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG) -- 2.5.0