fs/ntfs3: Add windows_names mount option
Subsystems (3)
v2 cover fs/ntfs3: Add windows_names mount option
Changes v1->v2:
- Add documentation for windows_names mount option.
When enabled, the windows_names mount option prevents the creation of files or directories with names not allowed by Windows. Use the same option name as NTFS-3G for compatibility.
Daniel Pinto (2):
fs/ntfs3: add windows_names mount option
fs/ntfs3: document windows_names mount option
Documentation/filesystems/ntfs3.rst | 8 +++ fs/ntfs3/frecord.c | 7 +- fs/ntfs3/fsntfs.c | 104 ++++++++++++++++++++++++++++ fs/ntfs3/inode.c | 7 ++ fs/ntfs3/ntfs_fs.h | 2 + fs/ntfs3/super.c | 7 ++ 6 files changed, 134 insertions(+), 1 deletion(-)
PATCH v2 1/2 fs/ntfs3: add windows_names mount option
When enabled, the windows_names mount option prevents the creation of files or directories with names not allowed by Windows. Use the same option name as NTFS-3G for compatibility.
--- fs/ntfs3/frecord.c | 7 ++- fs/ntfs3/fsntfs.c | 104 +++++++++++++++++++++++++++++++++++++++++++++ fs/ntfs3/inode.c | 7 +++ fs/ntfs3/ntfs_fs.h | 2 + fs/ntfs3/super.c | 7 +++ 5 files changed, 126 insertions(+), 1 deletion(-)
fs/ntfs3/frecord.c +6 -1
@@ -3011,6 +3011,7 @@ int ni_add_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni, struct NTFS_DE *de) {int err; +struct ntfs_sb_info *sbi = ni->mi.sbi;struct ATTRIB *attr;struct ATTR_LIST_ENTRY *le;struct mft_inode *mi;
@@ -3018,6 +3019,10 @@ int ni_add_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,struct ATTR_FILE_NAME *de_name = (struct ATTR_FILE_NAME *)(de +1 );u16 de_key_size =le16_to_cpu (de->key_size); +if (sbi->options->windows_names && + !valid_windows_name (sbi, (struct le_str *)&de_name->name_len)) +return -EINVAL ; +mi_get_ref (&ni->mi, &de->ref);mi_get_ref (&dir_ni->mi, &de_name->home);
@@ -3036,7 +3041,7 @@ int ni_add_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,memcpy (Add2Ptr (attr,SIZEOF_RESIDENT ), de_name, de_key_size);/* Insert new name into directory. */ - err =indx_insert_entry (&dir_ni->dir, dir_ni, de, ni->mi.sbi,NULL ,0 ); + err =indx_insert_entry (&dir_ni->dir, dir_ni, de, sbi,NULL ,0 );if (err)ni_remove_attr_le (ni, attr, mi, le);
fs/ntfs3/fsntfs.c +104 -0
113 lines not on this page · raw message
fs/ntfs3/inode.c +7 -0
@@ -1361,6 +1361,13 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,mi_get_ref (&ni->mi, &new_de->ref); fname = (struct ATTR_FILE_NAME *)(new_de +1 ); + +if (sbi->options->windows_names && + !valid_windows_name (sbi, (struct le_str *)&fname->name_len)) { + err = -EINVAL ; + goto out4; + } +mi_get_ref (&dir_ni->mi, &fname->home); fname->dup.cr_time = fname->dup.m_time = fname->dup.c_time = fname->dup.a_time = std5->cr_time;
fs/ntfs3/ntfs_fs.h +2 -0
@@ -98,6 +98,7 @@ struct ntfs_mount_options { unsigned showmeta : 1; /* Show meta files. */ unsigned nohidden : 1; /* Do not show hidden files. */ unsigned hide_dot_files : 1; /* Set hidden flag on dot files. */ + unsigned windows_names : 1; /* Disallow names forbidden by Windows. */ unsigned force : 1; /* RW mount dirty volume. */ unsigned noacsrules : 1; /* Exclude acs rules. */ unsigned prealloc : 1; /* Preallocate space when file is growing. */
@@ -645,6 +646,7 @@ int ntfs_remove_reparse(struct ntfs_sb_info *sbi, __le32 rtag, const struct MFT_REF *ref);void mark_as_free_ex (struct ntfs_sb_info *sbi,CLST lcn,CLST len,bool trim);int run_deallocate (struct ntfs_sb_info *sbi,struct runs_tree *run,bool trim); +bool valid_windows_name (struct ntfs_sb_info *sbi,const struct le_str *name);/* Globals from index.c */ int indx_used_bit (struct ntfs_index *indx,struct ntfs_inode *ni,size_t *bit);
fs/ntfs3/super.c +7 -0
@@ -248,6 +248,7 @@ enum Opt { Opt_sparse, Opt_nohidden, Opt_hide_dot_files, + Opt_windows_names, Opt_showmeta, Opt_acl, Opt_iocharset,
@@ -269,6 +270,7 @@ static const struct fs_parameter_spec ntfs_fs_parameters[] = {fsparam_flag_no ("sparse" , Opt_sparse),fsparam_flag_no ("hidden" , Opt_nohidden),fsparam_flag_no ("hidedotfiles" , Opt_hide_dot_files), +fsparam_flag_no ("windows_names" , Opt_windows_names),fsparam_flag_no ("acl" , Opt_acl),fsparam_flag_no ("showmeta" , Opt_showmeta), fsparam_flag_no("prealloc", Opt_prealloc),
@@ -361,6 +363,9 @@ static int ntfs_fs_parse_param(struct fs_context *fc,case Opt_hide_dot_files: opts->hide_dot_files = result.negated ?1 :0 ;break ; +case Opt_windows_names: + opts->windows_names = result.negated ?0 :1 ; +break ;case Opt_acl:if (!result.negated) #ifdef CONFIG_NTFS3_FS_POSIX_ACL
@@ -561,6 +566,8 @@ static int ntfs_show_options(struct seq_file *m, struct dentry *root)seq_puts (m,",showmeta" );if (opts->nohidden)seq_puts (m,",nohidden" ); +if (opts->windows_names) +seq_puts (m,",windows_names" );if (opts->force)seq_puts (m,",force" );if (opts->noacsrules)
PATCH v2 2/2 fs/ntfs3: document windows_names mount option
In reply to Daniel PintoAdd documentation for windows_names mount option.
--- Documentation/filesystems/ntfs3.rst | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/filesystems/ntfs3.rst +8 -0
@@ -75,6 +75,14 @@ this table marked with no it means default is without **no**. - Files with the Windows-specific SYSTEM (FILE_ATTRIBUTE_SYSTEM) attribute will be marked as system immutable files. + * - windows_names + - Prevents the creation of files and directories with a name not allowed + by Windows, either because it contains some not allowed character (which + are the characters " * / : < > ? \\ | and those whose code is less than + 0x20), because the name (with or without extension) is a reserved file + name (CON, AUX, NUL, PRN, LPT1-9, COM1-9) or because the last character + is a space or a dot. Existing such files can still be read and renamed. + * - discard - Enable support of the TRIM command for improved performance on delete operations, which is recommended for use with the solid-state drives
Konstantin Komarov
maintainerQuoted 11 lines · Daniel Pinto
Changes
v1->v2:
- Add documentation forwindows_namesmount option.When enabled, the
windows_namesmount option prevents the creation of files or directories with names not allowed by Windows. Use the same option name as NTFS-3G for compatibility.Daniel Pinto (2):
fs/ntfs3: addwindows_namesmount option
fs/ntfs3: documentwindows_namesmount option
Quoted 7 lines
Documentation/filesystems/ntfs3.rst | 8 +++ fs/ntfs3/frecord.c | 7 +- fs/ntfs3/fsntfs.c | 104 ++++++++++++++++++++++++++++ fs/ntfs3/inode.c | 7 ++ fs/ntfs3/ntfs_fs.h | 2 + fs/ntfs3/super.c | 7 ++ 6 files changed, 134 insertions(+), 1 deletion(-)
Thanks for patches, applied!