All of lore.kernel.org
 help / color / mirror / Atom feed
From: tridge@samba.org
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: john.lanza@linux.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,
	Dave Kleikamp <shaggy@linux.vnet.ibm.com>,
	Steve French <sfrench@us.ibm.com>, Mingming Cao <cmm@us.ibm.com>,
	Paul McKenney <paulmck@linux.vnet.ibm.com>
Subject: [PATCH] Added CONFIG_VFAT_FS_DUALNAMES option
Date: Sat, 27 Jun 2009 05:19:33 +1000	[thread overview]
Message-ID: <19013.8005.541836.436991@samba.org> (raw)

This is a new patch for VFAT long filename support, replacing the one
that I posted last month. It retains a lot more functionality then the
previous patch.

A FAQ will be posted immediately after this patch to answer the
questions that were raised from the previous discussion.

Cheers, Tridge


------------

When VFAT_FS_DUALNAMES is disabled we avoid the creation of 8.3 short
filenames for files on VFAT filesystems that require a long name. The
patch uses a pattern of 11 bytes in the directory entry which contains
invalid characters such that it cannot be considered to be a valid short
filename.

Signed-off-by: Andrew Tridgell <tridge@samba.org>
Acked-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 fs/fat/Kconfig      |   20 +++++++++++++++++
 fs/fat/dir.c        |   15 ++++++-------
 fs/fat/namei_vfat.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 8 deletions(-)

diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig
index 182f9ff..907a5de 100644
--- a/fs/fat/Kconfig
+++ b/fs/fat/Kconfig
@@ -74,6 +74,26 @@ config VFAT_FS
 	  To compile this as a module, choose M here: the module will be called
 	  vfat.
 
+config VFAT_FS_DUALNAMES
+	bool "VFAT dual names support"
+	depends on VFAT_FS
+	help
+	  This option provides support for dual filenames on VFAT filesystems.
+	  If this option is disabled then file creation will either put
+	  a short (8.3) name or a long name on the file, but never both.
+	  The field where a shortname would normally go is filled with
+	  invalid characters such that it cannot be considered a valid
+	  short filename.
+
+	  That means that long filenames created with this option
+	  disabled will not be accessible at all to operating systems
+	  that do not understand the VFAT extensions.
+
+	  Users considering enabling this option should consider the implications
+	  of any patents that may exist on dual filenames in VFAT.
+
+	  If unsure, say N
+
 config FAT_DEFAULT_CODEPAGE
 	int "Default codepage for FAT"
 	depends on MSDOS_FS || VFAT_FS
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 38ff75a..cd5d3ec 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -420,14 +420,13 @@ parse_record:
 			}
 			i += chl;
 		}
-		if (!last_u)
-			continue;
-
-		/* Compare shortname */
-		bufuname[last_u] = 0x0000;
-		len = fat_uni_to_x8(sbi, bufuname, bufname, sizeof(bufname));
-		if (fat_name_match(sbi, name, name_len, bufname, len))
-			goto found;
+		if (last_u) {
+			/* Compare shortname */
+			bufuname[last_u] = 0x0000;
+			len = fat_uni_to_x8(sbi, bufuname, bufname, sizeof(bufname));
+			if (fat_name_match(sbi, name, name_len, bufname, len))
+				goto found;
+		}
 
 		if (nr_slots) {
 			void *longname = unicode + FAT_MAX_UNI_CHARS;
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index 73471b7..894f44d 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -22,6 +22,7 @@
 #include <linux/smp_lock.h>
 #include <linux/buffer_head.h>
 #include <linux/namei.h>
+#include <linux/random.h>
 #include "fat.h"
 
 /*
@@ -586,6 +587,59 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
 	return 0;
 }
 
+#ifndef CONFIG_VFAT_FS_DUALNAMES
+/*
+ * build a 11 byte 8.3 buffer which is not a short filename. We want 11
+ * bytes which:
+ *    - will be seen as a constant string to all APIs on Linux and Windows
+ *    - cannot be matched with wildcard patterns
+ *    - cannot be used to access the file
+ *    - has a low probability of collision within a directory
+ *    - has an invalid 3 byte extension
+ *    - contains at least one non-space and non-nul byte
+ */
+static void vfat_build_dummy_83_buffer(struct inode *dir, char *msdos_name)
+{
+	u32 rand_num = random32() & 0x3FFFFFFF;
+	int i;
+
+	/* a value of zero would leave us with only nul and spaces,
+	 * which would not work with older linux systems
+	 */
+	if (rand_num == 0)
+		rand_num = 1;
+
+	/* we start with a space followed by nul as spaces at the
+	 * start of an entry are trimmed in FAT, which means that
+	 * starting the 11 bytes with 0x20 0x00 gives us a value which
+	 * cannot be used to access the file. It also means that the
+	 * value as seen from all Windows and Linux APIs is a constant
+	 */
+	msdos_name[0]  = ' ';
+	msdos_name[1]  = 0;
+
+	/* we use / and 2 nul bytes for the extension. These are
+	 * invalid in FAT and mean that utilities that show the
+	 * directory show no extension, but still work via the long
+	 * name for old Linux kernels
+	 */
+	msdos_name[8]  = '/';
+	msdos_name[9]  = 0;
+	msdos_name[10] = 0;
+
+	/*
+	 * fill the remaining 6 bytes with random invalid values
+	 * This gives us a low collision rate, which means a low
+	 * chance of problems with chkdsk.exe and WindowsXP
+	 */
+	for (i = 2; i < 8; i++) {
+		msdos_name[i] = rand_num & 0x1F;
+		rand_num >>= 5;
+	}
+}
+#endif
+
+
 static int vfat_build_slots(struct inode *dir, const unsigned char *name,
 			    int len, int is_dir, int cluster,
 			    struct timespec *ts,
@@ -628,6 +682,11 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name,
 		goto shortname;
 	}
 
+#ifndef CONFIG_VFAT_FS_DUALNAMES
+	vfat_build_dummy_83_buffer(dir, msdos_name);
+	lcase = 0;
+#endif
+
 	/* build the entry of long file name */
 	cksum = fat_checksum(msdos_name);
 
-- 
1.6.0.4


             reply	other threads:[~2009-06-26 19:20 UTC|newest]

Thread overview: 212+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-26 19:19 tridge [this message]
2009-06-26 21:40 ` [PATCH] Added CONFIG_VFAT_FS_DUALNAMES option H. Peter Anvin
2009-06-26 22:21   ` tridge
2009-06-27  1:48     ` OGAWA Hirofumi
2009-06-27 17:26       ` Jan Engelhardt
2009-06-27  1:56 ` OGAWA Hirofumi
2009-06-27 17:21 ` Jan Engelhardt
2009-06-28  2:59   ` tridge
2009-06-28 21:57     ` Jamie Lokier
2009-06-28 22:02       ` Jan Engelhardt
2009-06-28 22:05         ` Jamie Lokier
2009-06-29  1:23       ` tridge
2009-06-28  1:54 ` Eric W. Biederman
2009-06-28  2:19   ` tridge
2009-06-28  4:10     ` Eric W. Biederman
2009-06-28  5:38       ` tridge
2009-06-28  6:25         ` OGAWA Hirofumi
2009-06-28 19:51           ` Eric W. Biederman
2009-06-28 20:13             ` James Bottomley
2009-06-28 20:45               ` Eric W. Biederman
2009-06-28 21:45                 ` James Bottomley
2009-06-28 21:28             ` tridge
2009-06-29  1:30           ` tridge
2009-06-29 22:18             ` Greg KH
2009-06-29 22:42               ` tridge
2009-06-29 22:52                 ` Greg KH
2009-06-29 23:36                 ` OGAWA Hirofumi
2009-06-29 23:51                   ` tridge
2009-06-30  0:55                     ` OGAWA Hirofumi
2009-06-30  6:31 ` Pavel Machek
2009-07-01 10:09   ` Alan Cox
2009-07-01 11:11     ` tridge
2009-07-01 11:34       ` Alan Cox
2009-07-01 10:49   ` Rusty Russell
2009-07-01 11:25     ` Alan Cox
2009-07-01 14:05       ` Theodore Tso
2009-07-01 14:17         ` Alan Cox
2009-07-02  1:42           ` tridge
2009-07-02 10:33             ` Alan Cox
2009-07-02 12:43               ` tridge
2009-07-02 21:49           ` Pavel Machek
2009-07-06 19:57           ` Jamie Lokier
2009-07-01 16:18         ` Stefan Richter
2009-07-01 16:18           ` Stefan Richter
2009-07-02 23:17         ` CONFIG_VFAT_FS_DUALNAMES regression Jan Engelhardt
2009-07-02 23:17           ` Jan Engelhardt
2009-07-02 23:37           ` tridge
2009-07-03  0:11             ` Jan Engelhardt
2009-07-03  0:11               ` Jan Engelhardt
2009-07-03  0:25               ` tridge
2009-07-03  1:10                 ` Jan Engelhardt
2009-07-03  1:10                   ` Jan Engelhardt
2009-07-03  1:26                   ` tridge
2009-07-03  1:58                     ` Jan Engelhardt
2009-07-11  0:14                       ` Jamie Lokier
2009-07-02 23:46           ` CONFIG_VFAT_FS_DUALNAMES regressions Jan Engelhardt
2009-07-02 23:46             ` Jan Engelhardt
2009-07-03  0:14             ` tridge
2009-07-03  0:58               ` OGAWA Hirofumi
2009-07-03  1:11                 ` tridge
2009-07-03  1:50                   ` Jan Engelhardt
2009-07-03  1:50                     ` Jan Engelhardt
2009-07-03  1:59                     ` tridge
2009-07-03  2:09                       ` Jan Engelhardt
2009-07-03  2:09                         ` Jan Engelhardt
2009-07-03  3:25                         ` tridge
2009-07-03  6:46                           ` OGAWA Hirofumi
2009-07-03  9:40                           ` Jan Engelhardt
2009-07-03  9:40                             ` Jan Engelhardt
2009-07-03 12:24                             ` tridge
2009-07-04  3:09                               ` OGAWA Hirofumi
2009-07-06 11:40                               ` Jan Engelhardt
2009-07-06 13:05                                 ` tridge
2009-07-06 16:17                                   ` David Newall
2009-07-06 16:17                                     ` David Newall
2009-07-06 19:33                                     ` Jamie Lokier
2009-07-06 18:55                                   ` Jan Engelhardt
2009-07-06 20:26                                     ` tridge
2009-07-06 20:42                                       ` Jan Engelhardt
2009-07-06 20:42                                         ` Jan Engelhardt
2009-07-08  7:31                                         ` tridge
2009-07-06 20:36                                     ` Jan Engelhardt
2009-07-06 20:58                                       ` Jamie Lokier
2009-07-06 21:08                                         ` Jan Engelhardt
2009-07-06 22:24                                           ` Jamie Lokier
2009-07-07  9:36                                             ` Jan Engelhardt
2009-07-07  0:21                                       ` tridge
2009-07-07 21:56                                         ` Martin Steigerwald
2009-07-07 22:09                                           ` Martin Steigerwald
2009-07-08  3:12                                           ` tridge
2009-07-08 10:04                                             ` Alan Cox
2009-07-08 10:48                                               ` tridge
2009-07-08 12:02                                                 ` Alan Cox
2009-07-08 13:02                                                   ` tridge
2009-07-08 13:25                                                     ` Alan Cox
2009-07-09  1:20                                                       ` tridge
2009-07-09  9:42                                                         ` Alan Cox
2009-07-09 13:59                                                           ` James Bottomley
2009-07-09 14:10                                                             ` Alan Cox
2009-07-09 15:25                                                               ` Theodore Tso
2009-07-09 17:15                                                                 ` Christoph Hellwig
2009-07-09 20:57                                                                   ` David Newall
2009-07-09 22:23                                                                     ` Martin Steigerwald
2009-07-10  1:45                                                                       ` David Newall
2009-07-10 18:49                                                                         ` Martin Steigerwald
2009-07-10 19:31                                                                           ` Jonathan Corbet
2009-07-10 20:40                                                                             ` Bartlomiej Zolnierkiewicz
2009-07-12 11:21                                                                               ` Jörn Engel
2009-07-12 11:21                                                                                 ` Jörn Engel
2009-07-12 11:27                                                                                 ` Jan Engelhardt
2009-07-12 11:27                                                                                   ` Jan Engelhardt
2009-07-13 22:20                                                                                   ` Jamie Lokier
2009-07-13 22:20                                                                                     ` Jamie Lokier
2009-07-13 22:32                                                                                     ` Jan Engelhardt
2009-07-10 21:14                                                                             ` Alan Cox
2009-07-12  8:52                                                                           ` David Newall
2009-07-10  0:09                                                                 ` Alan Cox
2009-07-08 12:23                                                 ` Jan Engelhardt
2009-07-08 15:27                                               ` James Bottomley
2009-07-08 15:37                                                 ` Alan Cox
2009-07-08 16:06                                                   ` James Bottomley
2009-07-08 16:18                                                     ` Alan Cox
2009-07-09  4:25                                                       ` tridge
2009-07-09  5:27                                                         ` OGAWA Hirofumi
2009-07-09  7:21                                                           ` Pavel Machek
2009-07-09  7:34                                                             ` David Newall
2009-07-09  9:51                                                         ` Alan Cox
2009-07-09  4:53                                                       ` OGAWA Hirofumi
2009-07-09  9:53                                                         ` Alan Cox
2009-07-12 19:39                                                         ` OGAWA Hirofumi
2009-07-21  3:37                                                           ` tridge
2009-07-21  9:16                                                             ` Boaz Harrosh
2009-07-21 10:31                                                               ` Pavel Machek
2009-07-21 13:24                                                                 ` tridge
2009-07-21 15:08                                                                   ` John Lanza
2009-07-21 15:08                                                                     ` John Lanza
2009-07-21 19:36                                                                     ` John Lanza
2009-07-21 19:36                                                                       ` John Lanza
2009-07-21 21:37                                                                   ` Pavel Machek
2009-07-21 22:38                                                                     ` tridge
2009-07-21 10:44                                                               ` Jan Engelhardt
2009-07-21 13:04                                                               ` tridge
2009-07-21 15:06                                                                 ` John Lanza
2009-07-21 19:38                                                                   ` John Lanza
2009-07-21 19:38                                                                     ` John Lanza
2009-07-21 10:31                                                             ` Pavel Machek
2009-07-21 13:19                                                               ` tridge
2009-08-08 12:19                                                                 ` Pavel Machek
2009-07-08 11:39                                             ` Martin Steigerwald
2009-07-08 13:53                                               ` Jamie Lokier
2009-07-08 17:12                                                 ` Jeremy Allison
2009-07-09  3:23                                               ` tridge
2009-07-09 13:34                                                 ` Martin Steigerwald
2009-07-09  4:13                                               ` tridge
2009-07-09 19:47                                                 ` Martin Steigerwald
2009-07-10  7:36                                                 ` Pavel Machek
2009-07-10 21:12                                                   ` Jamie Lokier
2009-07-10 21:28                                                 ` Jamie Lokier
2009-07-11  2:03                                                   ` Jamie Lokier
2009-07-07 19:51                                   ` Pavel Machek
2009-07-08  7:42                                     ` tridge
2009-07-08 10:27                                       ` Jan Engelhardt
2009-07-09  2:23                                         ` tridge
2009-07-09  8:24                                           ` Jan Engelhardt
2009-07-10  7:35                                       ` Pavel Machek
2009-07-06 20:04                               ` Jamie Lokier
2009-07-08  7:30                                 ` tridge
2009-07-10 21:44                                   ` Jamie Lokier
2009-07-02  0:34       ` [PATCH] Added CONFIG_VFAT_FS_DUALNAMES option Rusty Russell
2009-07-02 21:46     ` Pavel Machek
2009-07-02 22:06       ` tridge
2009-07-02 22:33         ` Pavel Machek
2009-07-02 22:41           ` tridge
2009-07-02 22:44             ` Pavel Machek
2009-07-02 23:59               ` tridge
2009-07-08  9:21                 ` Pavel Machek
2009-07-08 14:25                   ` Paul E. McKenney
2009-07-08 21:42                     ` tridge
2009-07-08 22:14                       ` Paul E. McKenney
2009-07-08 23:59                         ` Paul E. McKenney
2009-07-08 16:46                   ` H. Peter Anvin
2009-07-03  0:03               ` Rusty Russell
2009-07-02 23:55       ` Rusty Russell
2009-07-01 10:50   ` tridge
2009-07-01 11:31     ` Alan Cox
2009-07-01 13:16       ` tridge
2009-07-01 13:38         ` Alan Cox
2009-07-01 14:02           ` tridge
2009-07-01 14:41             ` Alan Cox
2009-07-02  4:04               ` tridge
2009-07-02 10:32                 ` Alan Cox
2009-07-02 12:38                   ` tridge
2009-07-02 16:56                     ` Alan Cox
2009-07-03  2:50                       ` OGAWA Hirofumi
2009-07-02 14:56                   ` James Bottomley
2009-07-02 15:27                     ` Theodore Tso
2009-07-02 18:12                     ` Alan Cox
2009-07-02 21:25                       ` James Bottomley
2009-07-01 11:48     ` Boaz Harrosh
2009-07-01 12:28       ` tridge
2009-07-01 15:44       ` James Bottomley
2009-07-02 22:03         ` Pavel Machek
2009-07-06 20:41         ` Jamie Lokier
2009-07-07 10:02           ` Boaz Harrosh
2009-07-07 11:25             ` Jamie Lokier
2009-07-07 11:48               ` Boaz Harrosh
2009-07-07 11:50                 ` tridge
2009-07-02 22:00     ` Pavel Machek
2009-07-02 22:23       ` tridge
2009-07-02 22:41         ` Pavel Machek
     [not found] <4bbed3f70907082014t643209eaw5fc7cd7297f7af78@mail.gmail.com>
2009-07-09 13:16 ` John Lanza
2009-07-09 13:16   ` John Lanza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19013.8005.541836.436991@samba.org \
    --to=tridge@samba.org \
    --cc=cmm@us.ibm.com \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=john.lanza@linux.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=sfrench@us.ibm.com \
    --cc=shaggy@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.