[lkml]   [2001]   [Jan]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subjecttruncate() error values (was Re: Floppy disk strange behavior)

On Wed, 10 Jan 2001 wrote:

> >> dd: advancing past 1 blocks in output file `/dev/fd0': Permission denied
> > dd bug. It tries to ftruncate() the output file and gets all upset when
> > kernel refuses to truncate a block device (surprise, surprise).
> Yes. But EPERM means that something is wrong with privileges.
EACCES, actually.
> One would expect EINVAL or so when something is wrong with the
> way the routine was called.

Oh, agreed. Patch I've sent to Linus and posted on l-k more than a month ago:

diff -urN rc12-pre5/fs/open.c rc12-pre5-truncate/fs/open.c
--- rc12-pre5/fs/open.c Wed Nov 29 21:37:31 2000
+++ rc12-pre5-truncate/fs/open.c Tue Dec 5 14:53:59 2000
@@ -102,7 +102,12 @@
goto out;
inode = nd.dentry->d_inode;

- error = -EACCES;
+ /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
+ error = -EISDIR;
+ if (S_ISDIR(inode->i_mode))
+ goto dput_and_out;
+ error = -EINVAL;
if (!S_ISREG(inode->i_mode))
goto dput_and_out;

@@ -163,7 +168,7 @@
goto out;
dentry = file->f_dentry;
inode = dentry->d_inode;
- error = -EACCES;
+ error = -EINVAL;
if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE))
goto out_putf;
error = -EPERM;
That's test12-pre5. And yes, the case of files opened with O_RDONLY should
be -EINVAL according to
* our own manpages
* *BSD behaviour
* Solaris behaviour
* manpages of all Unices I've seen.
-EACCES is wrong here. More logical, but...

Linus, I realize that we have a moratorium on patches. It's certainly not
a critical one, but it probably ought to be applied at some point. Could
you tell what time would be OK for resubmitting it? All it changes is
* error returned for truncate() on directories (EACCES -> EISDIR)
* error returned for truncate() on other non-file (EACCES -> EINVAL)
* error returned for ftruncate() on O_RDONLY fds (EACCES -> EINVAL)
* error returned for ftruncate() on non-files (EACCES -> EINVAL)
In all cases new error values are what we are required to do by POSIX, SuS,
our own manpages, manpages of other Unices and actual behaviour of other

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:28    [W:0.447 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog