Re: [RFC] Heads up on sys_fallocate()
From: Eric Sandeen
Date: Thu Mar 01 2007 - 18:30:47 EST
Amit K. Arora wrote:
Might want more error checking in there, something like (rough cut)...
(or is some of this glibc's job?)
+asmlinkage long sys_fallocate(int fd, loff_t offset, loff_t len)
+{
+ struct file *file;
+ struct inode *inode;
+ long ret;
> +
> + ret = -EINVAL;
> + if (len == 0 || offset < 0)
> + goto out;
> + ret = -EBADF;
+ file = fget(fd);
+ if (!file)
+ goto out;
> + if (!(file->f_mode & FMODE_WRITE))
> + goto out_fput;
+ inode = file->f_path.dentry->d_inode;
> + ret = -ESPIPE;
> + if (S_ISFIFO(inode->i_mode))
> + goto out_fput;
> + ret = -ENODEV;
> + if (!S_ISREG(inode->i_mode))
> + goto out_fput;
> + ret = -EFBIG;
> + if (offset + len > inode->i_sb->s_maxbytes)
> + goto out_fput;
+ if (inode->i_op && inode->i_op->fallocate)
+ ret = inode->i_op->fallocate(inode, offset, len);
+ else
+ ret = -ENOTTY;
> +out_fput:
+ fput(file);
+out:
+ return ret;
+}
which would keep things in line with posix_fallocate's specified errors,
too?
-Eric
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/