UBUNTU: Ubuntu-2.6.38-12.51
[linux-flexiantxendom0-natty.git] / fs / readdir.c
index 93a7559..356f715 100644 (file)
@@ -4,6 +4,7 @@
  *  Copyright (C) 1995  Linus Torvalds
  */
 
+#include <linux/stddef.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/time.h>
@@ -54,7 +55,6 @@ EXPORT_SYMBOL(vfs_readdir);
  * anyway. Thus the special "fillonedir()" function for that
  * case (the low-level handlers don't need to care about this).
  */
-#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
 
 #ifdef __ARCH_WANT_OLD_READDIR
 
@@ -102,7 +102,8 @@ efault:
        return -EFAULT;
 }
 
-asmlinkage long old_readdir(unsigned int fd, struct old_linux_dirent __user * dirent, unsigned int count)
+SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
+               struct old_linux_dirent __user *, dirent, unsigned int, count)
 {
        int error;
        struct file * file;
@@ -117,7 +118,7 @@ asmlinkage long old_readdir(unsigned int fd, struct old_linux_dirent __user * di
        buf.dirent = dirent;
 
        error = vfs_readdir(file, fillonedir, &buf);
-       if (error >= 0)
+       if (buf.result)
                error = buf.result;
 
        fput(file);
@@ -151,7 +152,8 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
        struct linux_dirent __user * dirent;
        struct getdents_callback * buf = (struct getdents_callback *) __buf;
        unsigned long d_ino;
-       int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 2, sizeof(long));
+       int reclen = ALIGN(offsetof(struct linux_dirent, d_name) + namlen + 2,
+               sizeof(long));
 
        buf->error = -EINVAL;   /* only used if we fail.. */
        if (reclen > buf->count)
@@ -187,7 +189,8 @@ efault:
        return -EFAULT;
 }
 
-asmlinkage long sys_getdents(unsigned int fd, struct linux_dirent __user * dirent, unsigned int count)
+SYSCALL_DEFINE3(getdents, unsigned int, fd,
+               struct linux_dirent __user *, dirent, unsigned int, count)
 {
        struct file * file;
        struct linux_dirent __user * lastdirent;
@@ -209,9 +212,8 @@ asmlinkage long sys_getdents(unsigned int fd, struct linux_dirent __user * diren
        buf.error = 0;
 
        error = vfs_readdir(file, filldir, &buf);
-       if (error < 0)
-               goto out_putf;
-       error = buf.error;
+       if (error >= 0)
+               error = buf.error;
        lastdirent = buf.previous;
        if (lastdirent) {
                if (put_user(file->f_pos, &lastdirent->d_off))
@@ -219,8 +221,6 @@ asmlinkage long sys_getdents(unsigned int fd, struct linux_dirent __user * diren
                else
                        error = count - buf.count;
        }
-
-out_putf:
        fput(file);
 out:
        return error;
@@ -238,7 +238,8 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
 {
        struct linux_dirent64 __user *dirent;
        struct getdents_callback64 * buf = (struct getdents_callback64 *) __buf;
-       int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 1, sizeof(u64));
+       int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1,
+               sizeof(u64));
 
        buf->error = -EINVAL;   /* only used if we fail.. */
        if (reclen > buf->count)
@@ -271,7 +272,8 @@ efault:
        return -EFAULT;
 }
 
-asmlinkage long sys_getdents64(unsigned int fd, struct linux_dirent64 __user * dirent, unsigned int count)
+SYSCALL_DEFINE3(getdents64, unsigned int, fd,
+               struct linux_dirent64 __user *, dirent, unsigned int, count)
 {
        struct file * file;
        struct linux_dirent64 __user * lastdirent;
@@ -293,19 +295,16 @@ asmlinkage long sys_getdents64(unsigned int fd, struct linux_dirent64 __user * d
        buf.error = 0;
 
        error = vfs_readdir(file, filldir64, &buf);
-       if (error < 0)
-               goto out_putf;
-       error = buf.error;
+       if (error >= 0)
+               error = buf.error;
        lastdirent = buf.previous;
        if (lastdirent) {
                typeof(lastdirent->d_off) d_off = file->f_pos;
-               error = -EFAULT;
                if (__put_user(d_off, &lastdirent->d_off))
-                       goto out_putf;
-               error = count - buf.count;
+                       error = -EFAULT;
+               else
+                       error = count - buf.count;
        }
-
-out_putf:
        fput(file);
 out:
        return error;