exfat: use fat ioctls definitions from include/uapi/linux/msdos_fs.h

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
This commit is contained in:
Namjae Jeon 2023-10-30 21:08:39 +09:00
parent 8279a1a0bc
commit 950e271397
7 changed files with 41 additions and 44 deletions

8
dir.c
View File

@ -288,7 +288,7 @@ get_new:
mutex_unlock(&EXFAT_SB(sb)->s_lock); mutex_unlock(&EXFAT_SB(sb)->s_lock);
if (!dir_emit(ctx, nb->lfn, strlen(nb->lfn), inum, if (!dir_emit(ctx, nb->lfn, strlen(nb->lfn), inum,
(de.attr & ATTR_SUBDIR) ? DT_DIR : DT_REG)) (de.attr & EXFAT_ATTR_SUBDIR) ? DT_DIR : DT_REG))
goto out; goto out;
ctx->pos = cpos; ctx->pos = cpos;
goto get_new; goto get_new;
@ -366,7 +366,7 @@ unsigned int exfat_get_entry_type(struct exfat_dentry *ep)
if (ep->type == EXFAT_VOLUME) if (ep->type == EXFAT_VOLUME)
return TYPE_VOLUME; return TYPE_VOLUME;
if (ep->type == EXFAT_FILE) { if (ep->type == EXFAT_FILE) {
if (le16_to_cpu(ep->dentry.file.attr) & ATTR_SUBDIR) if (le16_to_cpu(ep->dentry.file.attr) & EXFAT_ATTR_SUBDIR)
return TYPE_DIR; return TYPE_DIR;
return TYPE_FILE; return TYPE_FILE;
} }
@ -417,10 +417,10 @@ static void exfat_set_entry_type(struct exfat_dentry *ep, unsigned int type)
ep->type = EXFAT_VOLUME; ep->type = EXFAT_VOLUME;
} else if (type == TYPE_DIR) { } else if (type == TYPE_DIR) {
ep->type = EXFAT_FILE; ep->type = EXFAT_FILE;
ep->dentry.file.attr = cpu_to_le16(ATTR_SUBDIR); ep->dentry.file.attr = cpu_to_le16(EXFAT_ATTR_SUBDIR);
} else if (type == TYPE_FILE) { } else if (type == TYPE_FILE) {
ep->type = EXFAT_FILE; ep->type = EXFAT_FILE;
ep->dentry.file.attr = cpu_to_le16(ATTR_ARCHIVE); ep->dentry.file.attr = cpu_to_le16(EXFAT_ATTR_ARCHIVE);
} }
} }

View File

@ -162,12 +162,6 @@ enum {
#define DIR_CACHE_SIZE \ #define DIR_CACHE_SIZE \
(DIV_ROUND_UP(EXFAT_DEN_TO_B(ES_MAX_ENTRY_NUM), SECTOR_SIZE) + 1) (DIV_ROUND_UP(EXFAT_DEN_TO_B(ES_MAX_ENTRY_NUM), SECTOR_SIZE) + 1)
/*
* attribute ioctls, same as their FAT equivalents.
*/
#define EXFAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, __u32)
#define EXFAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32)
struct exfat_dentry_namebuf { struct exfat_dentry_namebuf {
char *lfn; char *lfn;
int lfnbuf_len; /* usually MAX_UNINAME_BUF_SIZE */ int lfnbuf_len; /* usually MAX_UNINAME_BUF_SIZE */
@ -390,10 +384,10 @@ static inline int exfat_mode_can_hold_ro(struct inode *inode)
static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi, static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi,
unsigned short attr, mode_t mode) unsigned short attr, mode_t mode)
{ {
if ((attr & ATTR_READONLY) && !(attr & ATTR_SUBDIR)) if ((attr & EXFAT_ATTR_READONLY) && !(attr & EXFAT_ATTR_SUBDIR))
mode &= ~0222; mode &= ~0222;
if (attr & ATTR_SUBDIR) if (attr & EXFAT_ATTR_SUBDIR)
return (mode & ~sbi->options.fs_dmask) | S_IFDIR; return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
return (mode & ~sbi->options.fs_fmask) | S_IFREG; return (mode & ~sbi->options.fs_fmask) | S_IFREG;
@ -405,18 +399,18 @@ static inline unsigned short exfat_make_attr(struct inode *inode)
unsigned short attr = EXFAT_I(inode)->attr; unsigned short attr = EXFAT_I(inode)->attr;
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
attr |= ATTR_SUBDIR; attr |= EXFAT_ATTR_SUBDIR;
if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & 0222)) if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & 0222))
attr |= ATTR_READONLY; attr |= EXFAT_ATTR_READONLY;
return attr; return attr;
} }
static inline void exfat_save_attr(struct inode *inode, unsigned short attr) static inline void exfat_save_attr(struct inode *inode, unsigned short attr)
{ {
if (exfat_mode_can_hold_ro(inode)) if (exfat_mode_can_hold_ro(inode))
EXFAT_I(inode)->attr = attr & (ATTR_RWMASK | ATTR_READONLY); EXFAT_I(inode)->attr = attr & (EXFAT_ATTR_RWMASK | EXFAT_ATTR_READONLY);
else else
EXFAT_I(inode)->attr = attr & ATTR_RWMASK; EXFAT_I(inode)->attr = attr & EXFAT_ATTR_RWMASK;
} }
static inline bool exfat_is_last_sector_in_cluster(struct exfat_sb_info *sbi, static inline bool exfat_is_last_sector_in_cluster(struct exfat_sb_info *sbi,

View File

@ -64,15 +64,16 @@
#define CS_DEFAULT 2 #define CS_DEFAULT 2
/* file attributes */ /* file attributes */
#define ATTR_READONLY 0x0001 #define EXFAT_ATTR_READONLY 0x0001
#define ATTR_HIDDEN 0x0002 #define EXFAT_ATTR_HIDDEN 0x0002
#define ATTR_SYSTEM 0x0004 #define EXFAT_ATTR_SYSTEM 0x0004
#define ATTR_VOLUME 0x0008 #define EXFAT_ATTR_VOLUME 0x0008
#define ATTR_SUBDIR 0x0010 #define EXFAT_ATTR_SUBDIR 0x0010
#define ATTR_ARCHIVE 0x0020 #define EXFAT_ATTR_ARCHIVE 0x0020
#define ATTR_RWMASK (ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME | \ #define EXFAT_ATTR_RWMASK (EXFAT_ATTR_HIDDEN | EXFAT_ATTR_SYSTEM | \
ATTR_SUBDIR | ATTR_ARCHIVE) EXFAT_ATTR_VOLUME | EXFAT_ATTR_SUBDIR | \
EXFAT_ATTR_ARCHIVE)
#define BOOTSEC_JUMP_BOOT_LEN 3 #define BOOTSEC_JUMP_BOOT_LEN 3
#define BOOTSEC_FS_NAME_LEN 8 #define BOOTSEC_FS_NAME_LEN 8

16
file.c
View File

@ -14,6 +14,7 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/fsnotify.h> #include <linux/fsnotify.h>
#include <linux/security.h> #include <linux/security.h>
#include <linux/msdos_fs.h>
#include "exfat_raw.h" #include "exfat_raw.h"
#include "exfat_fs.h" #include "exfat_fs.h"
@ -154,7 +155,7 @@ int __exfat_truncate(struct inode *inode)
} }
if (ei->type == TYPE_FILE) if (ei->type == TYPE_FILE)
ei->attr |= ATTR_ARCHIVE; ei->attr |= EXFAT_ATTR_ARCHIVE;
/* /*
* update the directory entry * update the directory entry
@ -443,8 +444,9 @@ static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
/* /*
* Mask attributes so we don't set reserved fields. * Mask attributes so we don't set reserved fields.
*/ */
attr &= (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_ARCHIVE); attr &= (EXFAT_ATTR_READONLY | EXFAT_ATTR_HIDDEN | EXFAT_ATTR_SYSTEM |
attr |= (is_dir ? ATTR_SUBDIR : 0); EXFAT_ATTR_ARCHIVE);
attr |= (is_dir ? EXFAT_ATTR_SUBDIR : 0);
/* Equivalent to a chmod() */ /* Equivalent to a chmod() */
ia.ia_valid = ATTR_MODE | ATTR_CTIME; ia.ia_valid = ATTR_MODE | ATTR_CTIME;
@ -459,12 +461,12 @@ static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
ia.ia_mode = exfat_make_mode(sbi, attr, 0666 | (inode->i_mode & 0111)); ia.ia_mode = exfat_make_mode(sbi, attr, 0666 | (inode->i_mode & 0111));
/* The root directory has no attributes */ /* The root directory has no attributes */
if (inode->i_ino == EXFAT_ROOT_INO && attr != ATTR_SUBDIR) { if (inode->i_ino == EXFAT_ROOT_INO && attr != EXFAT_ATTR_SUBDIR) {
err = -EINVAL; err = -EINVAL;
goto out_unlock_inode; goto out_unlock_inode;
} }
if (((attr | oldattr) & ATTR_SYSTEM) && if (((attr | oldattr) & EXFAT_ATTR_SYSTEM) &&
!capable(CAP_LINUX_IMMUTABLE)) { !capable(CAP_LINUX_IMMUTABLE)) {
err = -EPERM; err = -EPERM;
goto out_unlock_inode; goto out_unlock_inode;
@ -562,9 +564,9 @@ long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
u32 __user *user_attr = (u32 __user *)arg; u32 __user *user_attr = (u32 __user *)arg;
switch (cmd) { switch (cmd) {
case EXFAT_IOCTL_GET_ATTRIBUTES: case FAT_IOCTL_GET_ATTRIBUTES:
return exfat_ioctl_get_attributes(inode, user_attr); return exfat_ioctl_get_attributes(inode, user_attr);
case EXFAT_IOCTL_SET_ATTRIBUTES: case FAT_IOCTL_SET_ATTRIBUTES:
return exfat_ioctl_set_attributes(filp, user_attr); return exfat_ioctl_set_attributes(filp, user_attr);
case FITRIM: case FITRIM:
return exfat_ioctl_fitrim(inode, arg); return exfat_ioctl_fitrim(inode, arg);

View File

@ -436,13 +436,13 @@ static int exfat_write_end(struct file *file, struct address_space *mapping,
if (err < len) if (err < len)
exfat_write_failed(mapping, pos+len); exfat_write_failed(mapping, pos+len);
if (!(err < 0) && !(ei->attr & ATTR_ARCHIVE)) { if (!(err < 0) && !(ei->attr & EXFAT_ATTR_ARCHIVE)) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
inode->i_mtime = inode->i_ctime = current_time(inode); inode->i_mtime = inode->i_ctime = current_time(inode);
#else #else
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
#endif #endif
ei->attr |= ATTR_ARCHIVE; ei->attr |= EXFAT_ATTR_ARCHIVE;
mark_inode_dirty(inode); mark_inode_dirty(inode);
} }
@ -629,7 +629,7 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
inode->i_generation = prandom_u32(); inode->i_generation = prandom_u32();
#endif #endif
if (info->attr & ATTR_SUBDIR) { /* directory */ if (info->attr & EXFAT_ATTR_SUBDIR) { /* directory */
inode->i_generation &= ~1; inode->i_generation &= ~1;
inode->i_mode = exfat_make_mode(sbi, info->attr, 0777); inode->i_mode = exfat_make_mode(sbi, info->attr, 0777);
inode->i_op = &exfat_dir_inode_operations; inode->i_op = &exfat_dir_inode_operations;

16
namei.c
View File

@ -572,12 +572,12 @@ static int exfat_add_entry(struct inode *inode, const char *path,
info->type = type; info->type = type;
if (type == TYPE_FILE) { if (type == TYPE_FILE) {
info->attr = ATTR_ARCHIVE; info->attr = EXFAT_ATTR_ARCHIVE;
info->start_clu = EXFAT_EOF_CLUSTER; info->start_clu = EXFAT_EOF_CLUSTER;
info->size = 0; info->size = 0;
info->num_subdirs = 0; info->num_subdirs = 0;
} else { } else {
info->attr = ATTR_SUBDIR; info->attr = EXFAT_ATTR_SUBDIR;
if (sbi->options.zero_size_dir) if (sbi->options.zero_size_dir)
info->start_clu = EXFAT_EOF_CLUSTER; info->start_clu = EXFAT_EOF_CLUSTER;
else else
@ -1177,8 +1177,8 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
*epnew = *epold; *epnew = *epold;
if (exfat_get_entry_type(epnew) == TYPE_FILE) { if (exfat_get_entry_type(epnew) == TYPE_FILE) {
epnew->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE); epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE);
ei->attr |= ATTR_ARCHIVE; ei->attr |= EXFAT_ATTR_ARCHIVE;
} }
exfat_update_bh(new_bh, sync); exfat_update_bh(new_bh, sync);
brelse(old_bh); brelse(old_bh);
@ -1209,8 +1209,8 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
ei->entry = newentry; ei->entry = newentry;
} else { } else {
if (exfat_get_entry_type(epold) == TYPE_FILE) { if (exfat_get_entry_type(epold) == TYPE_FILE) {
epold->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE); epold->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE);
ei->attr |= ATTR_ARCHIVE; ei->attr |= EXFAT_ATTR_ARCHIVE;
} }
exfat_update_bh(old_bh, sync); exfat_update_bh(old_bh, sync);
brelse(old_bh); brelse(old_bh);
@ -1258,8 +1258,8 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
*epnew = *epmov; *epnew = *epmov;
if (exfat_get_entry_type(epnew) == TYPE_FILE) { if (exfat_get_entry_type(epnew) == TYPE_FILE) {
epnew->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE); epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE);
ei->attr |= ATTR_ARCHIVE; ei->attr |= EXFAT_ATTR_ARCHIVE;
} }
exfat_update_bh(new_bh, IS_DIRSYNC(inode)); exfat_update_bh(new_bh, IS_DIRSYNC(inode));
brelse(mov_bh); brelse(mov_bh);

View File

@ -640,7 +640,7 @@ static int exfat_read_root(struct inode *inode)
inode->i_version++; inode->i_version++;
#endif #endif
inode->i_generation = 0; inode->i_generation = 0;
inode->i_mode = exfat_make_mode(sbi, ATTR_SUBDIR, 0777); inode->i_mode = exfat_make_mode(sbi, EXFAT_ATTR_SUBDIR, 0777);
inode->i_op = &exfat_dir_inode_operations; inode->i_op = &exfat_dir_inode_operations;
inode->i_fop = &exfat_dir_operations; inode->i_fop = &exfat_dir_operations;
@ -649,7 +649,7 @@ static int exfat_read_root(struct inode *inode)
ei->i_size_aligned = i_size_read(inode); ei->i_size_aligned = i_size_read(inode);
ei->i_size_ondisk = i_size_read(inode); ei->i_size_ondisk = i_size_read(inode);
exfat_save_attr(inode, ATTR_SUBDIR); exfat_save_attr(inode, EXFAT_ATTR_SUBDIR);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime = inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
current_time(inode); current_time(inode);