linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES option
@ 2009-05-01 17:41 Dave Kleikamp
  2009-05-01 17:47 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 89+ messages in thread
From: Dave Kleikamp @ 2009-05-01 17:41 UTC (permalink / raw)
  To: Ogawa Hirofumi
  Cc: Andrew Tridgell, Steve French, Mingming Cao, Paul McKenney, LKML,
	linux-fsdevel

From: Andrew Tridgell <tridge@samba.org>
Subject: [PATCH] Add CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES option

When this option is enabled the VFAT filesystem will refuse to create
new files with long names. Accessing existing files with long names
will continue to work.

File names to be created must conform to the 8.3 format.  Mixed case is
not allowed in either the prefix or the suffix.

Signed-off-by: Andrew Tridgell <tridge@samba.org>
Signed-off-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Acked-by: Steve French <sfrench@us.ibm.com>
Cc: Ogawa Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mingming Cao <cmm@us.ibm.com>
---
 fs/fat/Kconfig      |   18 ++++++++++++++++++
 fs/fat/namei_vfat.c |   26 +++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig
index 182f9ff..1439681 100644
--- a/fs/fat/Kconfig
+++ b/fs/fat/Kconfig
@@ -98,3 +98,21 @@ config FAT_DEFAULT_IOCHARSET
 
 	  Enable any character sets you need in File Systems/Native Language
 	  Support.
+
+config VFAT_NO_CREATE_WITH_LONGNAMES
+	bool "Disable creating files with long names"
+	depends on VFAT_FS
+	default n
+	help
+	  Set this to disable support for creating files or directories with
+	  names longer than 8.3 (the original DOS maximum file name length)
+	  e.g. naming a file FILE1234.TXT would be allowed but creating or
+	  renaming a file to FILE12345.TXT or FILE1234.TEXT would not
+	  be permitted.
+
+	  Case on files is only preserved if all of the prefix is the same
+	  case and all of the extension is the same case. So the names
+	  "FILE.txt", "file.TXT" would be case preserved, but if you create a
+	  file called "File.TxT" then it will be stored on disk as "FILE.TXT".
+
+	  Reading files with long file names is still permitted.
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index a0e00e3..cf0400e 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -316,6 +316,7 @@ static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
 	int sz = 0, extlen, baselen, i, numtail_baselen, numtail2_baselen;
 	int is_shortname;
 	struct shortname_info base_info, ext_info;
+	unsigned shortname_flags = opts->shortname;
 
 	is_shortname = 1;
 	INIT_SHORTNAME_INFO(&base_info);
@@ -424,13 +425,20 @@ static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
 	memcpy(name_res, base, baselen);
 	memcpy(name_res + 8, ext, extlen);
 	*lcase = 0;
+
+#ifdef CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES
+	if (is_shortname == 0)
+		return -ENAMETOOLONG;
+	shortname_flags = VFAT_SFN_CREATE_WINNT;
+#endif
+
 	if (is_shortname && base_info.valid && ext_info.valid) {
 		if (vfat_find_form(dir, name_res) == 0)
 			return -EEXIST;
 
-		if (opts->shortname & VFAT_SFN_CREATE_WIN95) {
+		if (shortname_flags & VFAT_SFN_CREATE_WIN95) {
 			return (base_info.upper && ext_info.upper);
-		} else if (opts->shortname & VFAT_SFN_CREATE_WINNT) {
+		} else if (shortname_flags & VFAT_SFN_CREATE_WINNT) {
 			if ((base_info.upper || base_info.lower) &&
 			    (ext_info.upper || ext_info.lower)) {
 				if (!base_info.upper && base_info.lower)
@@ -593,15 +601,19 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name,
 {
 	struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
 	struct fat_mount_options *opts = &sbi->options;
-	struct msdos_dir_slot *ps;
 	struct msdos_dir_entry *de;
-	unsigned char cksum, lcase;
+	unsigned char lcase;
 	unsigned char msdos_name[MSDOS_NAME];
 	wchar_t *uname;
 	__le16 time, date;
 	u8 time_cs;
-	int err, ulen, usize, i;
+	int err, ulen, usize;
+#ifndef CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES
+	unsigned char cksum;
+	int i;
 	loff_t offset;
+	struct msdos_dir_slot *ps;
+#endif
 
 	*nr_slots = 0;
 
@@ -628,6 +640,9 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name,
 		goto shortname;
 	}
 
+#ifdef CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES
+	de = (struct msdos_dir_entry *)slots;
+#else
 	/* build the entry of long file name */
 	cksum = fat_checksum(msdos_name);
 
@@ -645,6 +660,7 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name,
 	}
 	slots[0].id |= 0x40;
 	de = (struct msdos_dir_entry *)ps;
+#endif
 
 shortname:
 	/* build the entry of 8.3 alias name */

-- 
David Kleikamp
IBM Linux Technology Center


^ permalink raw reply related	[flat|nested] 89+ messages in thread
* Re: [PATCH] Add CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES option
@ 2009-05-01 20:18 Steve French
  2009-05-01 21:01 ` Christoph Hellwig
  0 siblings, 1 reply; 89+ messages in thread
From: Steve French @ 2009-05-01 20:18 UTC (permalink / raw)
  To: Dave Kleikamp, Christoph Hellwig
  Cc: Ogawa Hirofumi, linux-fsdevel, Michael Tokarev, Paul McKenney,
	Andrew Tridgell, LKML

Dave Kleikamp <shaggy@linux.vnet.ibm.com> wrote on 05/01/2009 02:09:33 PM:
> On Fri, 2009-05-01 at 22:19 +0400, Michael Tokarev wrote:
> > Dave Kleikamp wrote:
> > > On Fri, 2009-05-01 at 13:47 -0400, Christoph Hellwig wrote:
> > >> On Fri, May 01, 2009 at 12:41:29PM -0500, Dave Kleikamp wrote:
> > >>> From: Andrew Tridgell <tridge@samba.org>
> > >>> Subject: [PATCH] Add CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES option
> > >>>
> > >>> When this option is enabled the VFAT filesystem will refuse to create
> > >>> new files with long names. Accessing existing files with long names
> > >>> will continue to work.
> > >>>
> > >>> File names to be created must conform to the 8.3 format.  Mixed case is
> > >>> not allowed in either the prefix or the suffix.
> > >> This doesn't make any sense as a compile time option. Might make sense
> > >> as a mount option, but I'd like to hear a rationale for it first.
> > >
> > > Some linux-based devices would be happy not to contain code to create
> > > the long name at all.
> >
> > Well, is that a rationale per se?  Which devices they are and why?
>
> Could be anything.  cameras, phones, etc.  Anything that might be
> mountable by a host computer in order to share files, or to write to a
> device that can be shared by other computers or devices.
>
> > But besides, why `msdos' filesystem is not sufficient?
> > It contains no code to create long file names and no code to
> > read such names either.
>
> An example, an mp3 player wants to read files with long mixed-case
> names, which can be manipulated on a host computer.  But it may not need
> to create files that don't fit the 8.3 syntax.
>
> Of course, msdos might be a good option for other devices.

msdos file system does not support other features that vfat does
(there are probably more than maximum volume and file size).
For those manufacturers who who would like to disable
creation of long file names, but allow reading long file names,
and handle FAT32 on disk format and maximum sizes, it seems
reasonable to give them a simple configure option for it.  It is
harder, and less effective, to make the corresponding change
to modify the mount helper and kernel code to add
a new mount option, because it can be bypassed trivially
at the command line (ie having to "force" mount to pass a "nolongfilename"
mount option, would be harder than a simple kernel configure option)

-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 89+ messages in thread

end of thread, other threads:[~2009-06-04 21:33 UTC | newest]

Thread overview: 89+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-01 17:41 [PATCH] Add CONFIG_VFAT_NO_CREATE_WITH_LONGNAMES option Dave Kleikamp
2009-05-01 17:47 ` Christoph Hellwig
2009-05-01 18:12   ` Dave Kleikamp
2009-05-01 18:19     ` Michael Tokarev
2009-05-01 19:09       ` Dave Kleikamp
2009-05-01 18:30     ` Christoph Hellwig
2009-05-02 10:09 ` OGAWA Hirofumi
2009-05-02 10:14   ` OGAWA Hirofumi
2009-05-02 10:26     ` OGAWA Hirofumi
2009-05-02 10:41       ` tridge
2009-05-02 11:03         ` OGAWA Hirofumi
2009-05-02 11:13           ` tridge
2009-05-02 11:29             ` OGAWA Hirofumi
2009-05-02 11:41               ` tridge
2009-05-02 11:59                 ` OGAWA Hirofumi
2009-05-02 12:15                   ` tridge
2009-05-02 12:48                     ` OGAWA Hirofumi
2009-05-02 13:06                       ` tridge
2009-05-02 14:01                         ` OGAWA Hirofumi
2009-05-27 12:05                   ` vimal singh
2009-05-27 23:57                     ` tridge
2009-06-04 10:26                       ` vimal singh
2009-06-04 21:33                         ` tridge
2009-05-02 10:20   ` tridge
2009-05-02 10:32     ` OGAWA Hirofumi
2009-05-03 21:56 ` Pavel Machek
  -- strict thread matches above, loose matches on Subject: below --
2009-05-01 20:18 Steve French
2009-05-01 21:01 ` Christoph Hellwig
2009-05-02  1:37   ` Paul E. McKenney
2009-05-02  1:59     ` Matthew Wilcox
2009-05-02  3:02       ` Steve French
2009-05-02  4:51       ` Paul E. McKenney
2009-05-02  9:15       ` tridge
2009-05-02  9:22         ` Christoph Hellwig
2009-05-02  9:30           ` tridge
2009-05-02 12:44             ` Christoph Hellwig
2009-05-03 21:57             ` Pavel Machek
2009-05-03 22:25               ` tridge
2009-05-03 22:56                 ` Al Viro
2009-05-03 23:15                   ` tridge
2009-05-04  5:42                     ` Eric W. Biederman
2009-05-04  6:34                       ` Paul E. McKenney
2009-05-04  6:49                         ` Eric W. Biederman
2009-05-04 12:41                           ` Paul E. McKenney
2009-05-04 12:44                             ` Matthew Wilcox
2009-05-04 13:06                               ` Paul E. McKenney
2009-05-04 13:21                                 ` Matthew Wilcox
2009-05-04 14:39                                   ` Paul E. McKenney
2009-05-04 15:08                                     ` Matthew Wilcox
2009-05-04 15:36                                       ` Dave Kleikamp
2009-05-04 15:59                                         ` Eric W. Biederman
2009-05-04 16:07                                           ` Dave Kleikamp
2009-05-04 16:30                                             ` Eric W. Biederman
2009-05-04 16:42                                               ` Paul E. McKenney
2009-05-04 17:18                                                 ` Eric W. Biederman
2009-05-04 17:49                                                   ` Paul E. McKenney
2009-05-04 17:54                                                     ` Matthew Wilcox
2009-05-04 18:14                                                       ` Paul E. McKenney
2009-05-04 18:17                                                 ` Al Viro
2009-05-04 20:18                                                   ` Paul E. McKenney
2009-05-04 17:06                                               ` Olivier Galibert
2009-05-04 17:27                                                 ` Christoph Hellwig
2009-05-04 20:53                                                   ` Chris Friesen
2009-05-04 23:03                                                     ` Theodore Tso
2009-05-05 11:09                                                       ` David Newall
2009-05-05 20:56                                                         ` Valdis.Kletnieks
2009-05-05 21:04                                                           ` Christoph Hellwig
2009-05-05 22:29                                                             ` Steve French
2009-05-04 16:11                                           ` Paul E. McKenney
2009-05-04 15:38                                       ` Paul E. McKenney
2009-05-04 15:55                                         ` Matthew Wilcox
2009-05-04 16:10                                           ` Paul E. McKenney
2009-05-04 16:22                                             ` Matthew Wilcox
2009-05-04 22:12                                               ` Greg KH
2009-05-05  2:01                                                 ` Matthew Wilcox
2009-05-05  2:11                                                   ` Paul E. McKenney
2009-05-05  2:18                                                     ` Matthew Wilcox
2009-05-05  3:34                                                       ` Paul E. McKenney
2009-05-05  8:05                                                         ` Valdis.Kletnieks
2009-05-05 15:35                                                           ` Paul E. McKenney
2009-05-05 21:00                                                             ` Valdis.Kletnieks
2009-05-05 21:56                                                               ` Paul E. McKenney
2009-05-05  3:08                                                     ` Valdis.Kletnieks
2009-05-04 15:55                                         ` Christoph Hellwig
2009-05-04 16:11                                           ` Paul E. McKenney
2009-05-04 15:40                 ` Valdis.Kletnieks
2009-05-02  6:33     ` Christoph Hellwig
2009-05-02  2:12   ` Theodore Tso
2009-05-02  6:38     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).