9 #include <linux/capability.h>
13 #include <linux/export.h>
17 #include <linux/falloc.h>
19 #include <asm/ioctls.h>
22 #define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent))
35 static long vfs_ioctl(
struct file *filp,
unsigned int cmd,
40 if (!filp->
f_op || !filp->
f_op->unlocked_ioctl)
43 error = filp->
f_op->unlocked_ioctl(filp, cmd, arg);
50 static int ioctl_fibmap(
struct file *filp,
int __user *
p)
56 if (!mapping->
a_ops->bmap)
63 res = mapping->
a_ops->bmap(mapping, block);
82 #define SET_UNKNOWN_FLAGS (FIEMAP_EXTENT_DELALLOC)
83 #define SET_NO_UNMOUNTED_IO_FLAGS (FIEMAP_EXTENT_DATA_ENCRYPTED)
84 #define SET_NOT_ALIGNED_FLAGS (FIEMAP_EXTENT_DATA_TAIL|FIEMAP_EXTENT_DATA_INLINE)
107 memset(&extent, 0,
sizeof(extent));
143 if (incompat_flags) {
161 if (start > maxbytes)
167 if (len > maxbytes || (maxbytes - len) <
start)
168 *new_len = maxbytes - start;
173 static int ioctl_fiemap(
struct file *filp,
unsigned long arg)
183 if (!inode->
i_op->fiemap)
220 static inline sector_t logical_to_blk(
struct inode *inode, loff_t
offset)
225 static inline loff_t blk_to_logical(
struct inode *inode,
sector_t blk)
254 struct buffer_head map_bh;
256 loff_t isize = i_size_read(inode);
259 bool past_eof =
false, whole_file =
false;
280 if (logical_to_blk(inode, len) == 0)
281 len = blk_to_logical(inode, 1);
283 start_blk = logical_to_blk(inode, start);
284 last_blk = logical_to_blk(inode, start + len - 1);
291 memset(&map_bh, 0,
sizeof(
struct buffer_head));
294 ret = get_block(inode, start_blk, &map_bh, 0);
299 if (!buffer_mapped(&map_bh)) {
310 blk_to_logical(inode, start_blk) >= isize)
317 if (past_eof &&
size) {
329 if (start_blk > last_blk || past_eof || ret)
347 if (start_blk > last_blk && !whole_file) {
366 logical = blk_to_logical(inode, start_blk);
367 phys = blk_to_logical(inode, map_bh.b_blocknr);
368 size = map_bh.b_size;
371 start_blk += logical_to_blk(inode,
size);
378 if (!past_eof && logical +
size >= isize)
427 struct inode *inode = filp->
f_path.dentry->d_inode;
440 sr.
l_start += i_size_read(inode);
449 static int file_ioctl(
struct file *filp,
unsigned int cmd,
452 struct inode *inode = filp->
f_path.dentry->d_inode;
457 return ioctl_fibmap(filp, p);
465 return vfs_ioctl(filp, cmd, arg);
468 static int ioctl_fionbio(
struct file *filp,
int __user *
argp)
487 spin_unlock(&filp->
f_lock);
491 static int ioctl_fioasync(
unsigned int fd,
struct file *filp,
504 if (filp->
f_op && filp->
f_op->fasync)
506 error = filp->
f_op->fasync(fd, filp, on);
510 return error < 0 ? error : 0;
513 static int ioctl_fsfreeze(
struct file *filp)
528 static int ioctl_fsthaw(
struct file *filp)
551 struct inode *inode = filp->
f_path.dentry->d_inode;
563 error = ioctl_fionbio(filp, argp);
567 error = ioctl_fioasync(fd, filp, argp);
581 error = ioctl_fsfreeze(filp);
585 error = ioctl_fsthaw(filp);
589 return ioctl_fiemap(filp, arg);
596 error = file_ioctl(filp, cmd, arg);
598 error = vfs_ioctl(filp, cmd, arg);
607 struct fd f = fdget(fd);