Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.4.13 /fs/open.c

Filename:/fs/open.c
Lines Added:27
Lines Deleted:10
Also changed in: (Previous) 2.4.13-pre6  2.4.13-pre5  2.4.13-pre4  2.4.13-pre3  2.4.13-pre2  2.4.12-ac6 
(Following) 2.4.13-ac1  2.4.13-ac2  2.4.13-ac3  2.4.13-ac4  2.4.13-ac5  2.4.13-ac6 

Location
[  2.4.13
  [  fs
     o  open.c

Patch

diff -u --recursive --new-file v2.4.12/linux/fs/open.c linux/fs/open.c
--- v2.4.12/linux/fs/open.c   Tue Oct  9 17:06:53 2001
+++ linux/fs/open.c   Fri Oct 12 13:48:42 2001
@@ -104,7 +104,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;
 
@@ -146,10 +151,11 @@
 
 asmlinkage long sys_truncate(const char * path, unsigned long length)
 {
-   return do_sys_truncate(path, length);
+   /* on 32-bit boxen it will cut the range 2^31--2^32-1 off */
+   return do_sys_truncate(path, (long)length);
 }
 
-static inline long do_sys_ftruncate(unsigned int fd, loff_t length)
+static inline long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
 {
    struct inode * inode;
    struct dentry *dentry;
@@ -163,13 +169,24 @@
    file = fget(fd);
    if (!file)
       goto out;
+
+   /* explicitly opened as large or we are on 64-bit box */
+   if (file->f_flags & O_LARGEFILE)
+      small = 0;
+
    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 = -EINVAL;
+   /* Cannot ftruncate over 2^31 bytes without large file support */
+   if (small && length > MAX_NON_LFS)
+      goto out_putf;
+
    error = -EPERM;
-   if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
+   if (IS_APPEND(inode))
       goto out_putf;
 
    error = locks_verify_truncate(inode, file, length);
@@ -183,7 +200,7 @@
 
 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length)
 {
-   return do_sys_ftruncate(fd, length);
+   return do_sys_ftruncate(fd, length, 1);
 }
 
 /* LFS versions of truncate are only needed on 32 bit machines */
@@ -195,7 +212,7 @@
 
 asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length)
 {
-   return do_sys_ftruncate(fd, length);
+   return do_sys_ftruncate(fd, length, 0);
 }
 #endif
 
@@ -507,7 +524,7 @@
 
    error = -ENOENT;
    if (!(inode = dentry->d_inode)) {
-      printk("chown_common: NULL inode\n");
+      printk(KERN_ERR "chown_common: NULL inode\n");
       goto out;
    }
    error = -EROFS;
@@ -744,7 +761,7 @@
 #if 1
    /* Sanity check */
    if (files->fd[fd] != NULL) {
-      printk("get_unused_fd: slot %d not NULL!\n", fd);
+      printk(KERN_WARNING "get_unused_fd: slot %d not NULL!\n", fd);
       files->fd[fd] = NULL;
    }
 #endif
@@ -807,7 +824,7 @@
    int retval;
 
    if (!file_count(filp)) {
-      printk("VFS: Close: file count is 0\n");
+      printk(KERN_ERR "VFS: Close: file count is 0\n");
       return 0;
    }
    retval = 0;


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.