All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] Return better error codes from vfat_valid_longname()
Date: Tue, 9 Nov 2004 17:49:02 +0100	[thread overview]
Message-ID: <20041109164902.GA14088@neapel230.server4you.de> (raw)
In-Reply-To: <87vfcf3uu0.fsf@devron.myhome.or.jp>

OGAWA Hirofumi wrote:
> lsr@neapel230.server4you.de writes:
> 
> 
>>Currently vfat returns -EINVAL if one tries to create a file or directory
>>with an invalid name. This patch changes vfat_valid_longname() to return
>>a more specific error code.
>>
>>POSIX doesn't define a nice error code for invalid filenames, so I chose
>>EACCES -- unlike EINVAL this is a valid error code of mkdir(2). Hope it
>>sort of fits. (EINVAL did *not* fit; it generally seems to point to
>>problems not with the filename  but with e.g. the flags value of open(2)
>>etc.).
> 
> 
> Yes, the error code for this should be consistent on _system_.
> Until we do it, this change would not be useful.

At least ENAMETOOLONG and ENOENT are properly defined error codes. :)

VFAT returning EACCES when trying to access "forbidden" filenames would
be useful right now because it gives better error messages with current
tools. At least the error msg of touch looks less confusing IMHO
(didn't check much other programs).

And I doubt we'll get an official Linux error code for invalid
filenames soon: according to POSIX there are only two forbidden
characters, '/' and '\0', so anything goes.

Anyway, what do you think about the following patch? I just replaced
EACCES by EINVAL.

Thanks,
René



--- ./fs/vfat/namei.c.orig	2004-11-08 21:33:35.000000000 +0100
+++ ./fs/vfat/namei.c	2004-11-08 21:32:52.000000000 +0100
@@ -184,10 +184,13 @@ static int vfat_valid_longname(const uns
 {
 	const unsigned char *p;
 
-	if (len && name[len-1] == ' ')
-		return 0;
-	if (len >= 256)
-		return 0;
+	if (len == 0)
+		return -ENOENT;
+	if (len > 255)
+		return -ENAMETOOLONG;
+
+	if (name[len-1] == ' ')
+		return -EINVAL;
 
 	/* MS-DOS "device special files" */
 	if (len == 3 || (len > 3 && name[3] == '.')) {	/* basename == 3 */
@@ -195,24 +198,24 @@ static int vfat_valid_longname(const uns
 		    !strnicmp(name, "con", 3) ||
 		    !strnicmp(name, "nul", 3) ||
 		    !strnicmp(name, "prn", 3))
-			return 0;
+			return -EINVAL;
 	}
 	if (len == 4 || (len > 4 && name[4] == '.')) {	/* basename == 4 */
 		/* "com1", "com2", ... */
 		if ('1' <= name[3] && name[3] <= '9') {
 			if (!strnicmp(name, "com", 3) ||
 			    !strnicmp(name, "lpt", 3))
-				return 0;
+				return -EINVAL;
 		}
 	}
 
 	/* check for invalid characters */
 	for (p = name; p < name + len; p++) {
 		if (*p < 0x0020 || strchr("*?<>|\":\\", *p) != NULL)
-			return 0;
+			return -EINVAL;
 	}
 
-	return 1;
+	return 0;
 }
 
 static int vfat_find_form(struct inode *dir, unsigned char *name)
@@ -615,8 +618,9 @@ static int vfat_build_slots(struct inode
 	loff_t offset;
 
 	*slots = 0;
-	if (!vfat_valid_longname(name, len))
-		return -EINVAL;
+	res = vfat_valid_longname(name, len);
+	if (res)
+		return res;
 
 	if(!(page = __get_free_page(GFP_KERNEL)))
 		return -ENOMEM;

  reply	other threads:[~2004-11-09 16:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-09  1:30 [PATCH 0/4] VFAT cleanup Rene Scharfe
2004-11-09  1:35 ` [PATCH 1/4] Move check for invalid chars to vfat_valid_longname() lsr
2004-11-09 15:03   ` OGAWA Hirofumi
2004-11-09 16:22     ` René Scharfe
2004-11-09 17:25       ` OGAWA Hirofumi
2004-11-09 18:22         ` Rene Scharfe
2004-11-09 18:41           ` OGAWA Hirofumi
2004-11-09  1:38 ` [PATCH 2/4] Return better error codes from vfat_valid_longname() lsr
2004-11-09 15:28   ` OGAWA Hirofumi
2004-11-09 16:49     ` Rene Scharfe [this message]
2004-11-09 17:35       ` OGAWA Hirofumi
2004-11-09 18:35         ` Rene Scharfe
2004-11-09 19:08           ` OGAWA Hirofumi
2004-11-09  1:42 ` [PATCH 3/4] Simplify checks for unwanted chars lsr
2004-11-09 15:40   ` OGAWA Hirofumi
2004-11-09  1:43 ` [PATCH 4/4] Manually inline shortname_info_to_lcase() lsr
2004-11-09 15:11   ` OGAWA Hirofumi

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=20041109164902.GA14088@neapel230.server4you.de \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    /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.