Back to home page

LXR

 
 

    


0001 /*
0002  *  linux/fs/ioctl.c
0003  *
0004  *  Copyright (C) 1991, 1992  Linus Torvalds
0005  */
0006 
0007 #include <linux/syscalls.h>
0008 #include <linux/mm.h>
0009 #include <linux/capability.h>
0010 #include <linux/file.h>
0011 #include <linux/fs.h>
0012 #include <linux/security.h>
0013 #include <linux/export.h>
0014 #include <linux/uaccess.h>
0015 #include <linux/writeback.h>
0016 #include <linux/buffer_head.h>
0017 #include <linux/falloc.h>
0018 #include "internal.h"
0019 
0020 #include <asm/ioctls.h>
0021 
0022 /* So that the fiemap access checks can't overflow on 32 bit machines. */
0023 #define FIEMAP_MAX_EXTENTS  (UINT_MAX / sizeof(struct fiemap_extent))
0024 
0025 /**
0026  * vfs_ioctl - call filesystem specific ioctl methods
0027  * @filp:   open file to invoke ioctl method on
0028  * @cmd:    ioctl command to execute
0029  * @arg:    command-specific argument for ioctl
0030  *
0031  * Invokes filesystem specific ->unlocked_ioctl, if one exists; otherwise
0032  * returns -ENOTTY.
0033  *
0034  * Returns 0 on success, -errno on error.
0035  */
0036 long vfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
0037 {
0038     int error = -ENOTTY;
0039 
0040     if (!filp->f_op->unlocked_ioctl)
0041         goto out;
0042 
0043     error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
0044     if (error == -ENOIOCTLCMD)
0045         error = -ENOTTY;
0046  out:
0047     return error;
0048 }
0049 
0050 static int ioctl_fibmap(struct file *filp, int __user *p)
0051 {
0052     struct address_space *mapping = filp->f_mapping;
0053     int res, block;
0054 
0055     /* do we support this mess? */
0056     if (!mapping->a_ops->bmap)
0057         return -EINVAL;
0058     if (!capable(CAP_SYS_RAWIO))
0059         return -EPERM;
0060     res = get_user(block, p);
0061     if (res)
0062         return res;
0063     res = mapping->a_ops->bmap(mapping, block);
0064     return put_user(res, p);
0065 }
0066 
0067 /**
0068  * fiemap_fill_next_extent - Fiemap helper function
0069  * @fieinfo:    Fiemap context passed into ->fiemap
0070  * @logical:    Extent logical start offset, in bytes
0071  * @phys:   Extent physical start offset, in bytes
0072  * @len:    Extent length, in bytes
0073  * @flags:  FIEMAP_EXTENT flags that describe this extent
0074  *
0075  * Called from file system ->fiemap callback. Will populate extent
0076  * info as passed in via arguments and copy to user memory. On
0077  * success, extent count on fieinfo is incremented.
0078  *
0079  * Returns 0 on success, -errno on error, 1 if this was the last
0080  * extent that will fit in user array.
0081  */
0082 #define SET_UNKNOWN_FLAGS   (FIEMAP_EXTENT_DELALLOC)
0083 #define SET_NO_UNMOUNTED_IO_FLAGS   (FIEMAP_EXTENT_DATA_ENCRYPTED)
0084 #define SET_NOT_ALIGNED_FLAGS   (FIEMAP_EXTENT_DATA_TAIL|FIEMAP_EXTENT_DATA_INLINE)
0085 int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
0086                 u64 phys, u64 len, u32 flags)
0087 {
0088     struct fiemap_extent extent;
0089     struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
0090 
0091     /* only count the extents */
0092     if (fieinfo->fi_extents_max == 0) {
0093         fieinfo->fi_extents_mapped++;
0094         return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0;
0095     }
0096 
0097     if (fieinfo->fi_extents_mapped >= fieinfo->fi_extents_max)
0098         return 1;
0099 
0100     if (flags & SET_UNKNOWN_FLAGS)
0101         flags |= FIEMAP_EXTENT_UNKNOWN;
0102     if (flags & SET_NO_UNMOUNTED_IO_FLAGS)
0103         flags |= FIEMAP_EXTENT_ENCODED;
0104     if (flags & SET_NOT_ALIGNED_FLAGS)
0105         flags |= FIEMAP_EXTENT_NOT_ALIGNED;
0106 
0107     memset(&extent, 0, sizeof(extent));
0108     extent.fe_logical = logical;
0109     extent.fe_physical = phys;
0110     extent.fe_length = len;
0111     extent.fe_flags = flags;
0112 
0113     dest += fieinfo->fi_extents_mapped;
0114     if (copy_to_user(dest, &extent, sizeof(extent)))
0115         return -EFAULT;
0116 
0117     fieinfo->fi_extents_mapped++;
0118     if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max)
0119         return 1;
0120     return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0;
0121 }
0122 EXPORT_SYMBOL(fiemap_fill_next_extent);
0123 
0124 /**
0125  * fiemap_check_flags - check validity of requested flags for fiemap
0126  * @fieinfo:    Fiemap context passed into ->fiemap
0127  * @fs_flags:   Set of fiemap flags that the file system understands
0128  *
0129  * Called from file system ->fiemap callback. This will compute the
0130  * intersection of valid fiemap flags and those that the fs supports. That
0131  * value is then compared against the user supplied flags. In case of bad user
0132  * flags, the invalid values will be written into the fieinfo structure, and
0133  * -EBADR is returned, which tells ioctl_fiemap() to return those values to
0134  * userspace. For this reason, a return code of -EBADR should be preserved.
0135  *
0136  * Returns 0 on success, -EBADR on bad flags.
0137  */
0138 int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags)
0139 {
0140     u32 incompat_flags;
0141 
0142     incompat_flags = fieinfo->fi_flags & ~(FIEMAP_FLAGS_COMPAT & fs_flags);
0143     if (incompat_flags) {
0144         fieinfo->fi_flags = incompat_flags;
0145         return -EBADR;
0146     }
0147     return 0;
0148 }
0149 EXPORT_SYMBOL(fiemap_check_flags);
0150 
0151 static int fiemap_check_ranges(struct super_block *sb,
0152                    u64 start, u64 len, u64 *new_len)
0153 {
0154     u64 maxbytes = (u64) sb->s_maxbytes;
0155 
0156     *new_len = len;
0157 
0158     if (len == 0)
0159         return -EINVAL;
0160 
0161     if (start > maxbytes)
0162         return -EFBIG;
0163 
0164     /*
0165      * Shrink request scope to what the fs can actually handle.
0166      */
0167     if (len > maxbytes || (maxbytes - len) < start)
0168         *new_len = maxbytes - start;
0169 
0170     return 0;
0171 }
0172 
0173 static int ioctl_fiemap(struct file *filp, unsigned long arg)
0174 {
0175     struct fiemap fiemap;
0176     struct fiemap __user *ufiemap = (struct fiemap __user *) arg;
0177     struct fiemap_extent_info fieinfo = { 0, };
0178     struct inode *inode = file_inode(filp);
0179     struct super_block *sb = inode->i_sb;
0180     u64 len;
0181     int error;
0182 
0183     if (!inode->i_op->fiemap)
0184         return -EOPNOTSUPP;
0185 
0186     if (copy_from_user(&fiemap, ufiemap, sizeof(fiemap)))
0187         return -EFAULT;
0188 
0189     if (fiemap.fm_extent_count > FIEMAP_MAX_EXTENTS)
0190         return -EINVAL;
0191 
0192     error = fiemap_check_ranges(sb, fiemap.fm_start, fiemap.fm_length,
0193                     &len);
0194     if (error)
0195         return error;
0196 
0197     fieinfo.fi_flags = fiemap.fm_flags;
0198     fieinfo.fi_extents_max = fiemap.fm_extent_count;
0199     fieinfo.fi_extents_start = ufiemap->fm_extents;
0200 
0201     if (fiemap.fm_extent_count != 0 &&
0202         !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
0203                fieinfo.fi_extents_max * sizeof(struct fiemap_extent)))
0204         return -EFAULT;
0205 
0206     if (fieinfo.fi_flags & FIEMAP_FLAG_SYNC)
0207         filemap_write_and_wait(inode->i_mapping);
0208 
0209     error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
0210     fiemap.fm_flags = fieinfo.fi_flags;
0211     fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
0212     if (copy_to_user(ufiemap, &fiemap, sizeof(fiemap)))
0213         error = -EFAULT;
0214 
0215     return error;
0216 }
0217 
0218 static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
0219                  u64 off, u64 olen, u64 destoff)
0220 {
0221     struct fd src_file = fdget(srcfd);
0222     int ret;
0223 
0224     if (!src_file.file)
0225         return -EBADF;
0226     ret = -EXDEV;
0227     if (src_file.file->f_path.mnt != dst_file->f_path.mnt)
0228         goto fdput;
0229     ret = do_clone_file_range(src_file.file, off, dst_file, destoff, olen);
0230 fdput:
0231     fdput(src_file);
0232     return ret;
0233 }
0234 
0235 static long ioctl_file_clone_range(struct file *file, void __user *argp)
0236 {
0237     struct file_clone_range args;
0238 
0239     if (copy_from_user(&args, argp, sizeof(args)))
0240         return -EFAULT;
0241     return ioctl_file_clone(file, args.src_fd, args.src_offset,
0242                 args.src_length, args.dest_offset);
0243 }
0244 
0245 #ifdef CONFIG_BLOCK
0246 
0247 static inline sector_t logical_to_blk(struct inode *inode, loff_t offset)
0248 {
0249     return (offset >> inode->i_blkbits);
0250 }
0251 
0252 static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)
0253 {
0254     return (blk << inode->i_blkbits);
0255 }
0256 
0257 /**
0258  * __generic_block_fiemap - FIEMAP for block based inodes (no locking)
0259  * @inode: the inode to map
0260  * @fieinfo: the fiemap info struct that will be passed back to userspace
0261  * @start: where to start mapping in the inode
0262  * @len: how much space to map
0263  * @get_block: the fs's get_block function
0264  *
0265  * This does FIEMAP for block based inodes.  Basically it will just loop
0266  * through get_block until we hit the number of extents we want to map, or we
0267  * go past the end of the file and hit a hole.
0268  *
0269  * If it is possible to have data blocks beyond a hole past @inode->i_size, then
0270  * please do not use this function, it will stop at the first unmapped block
0271  * beyond i_size.
0272  *
0273  * If you use this function directly, you need to do your own locking. Use
0274  * generic_block_fiemap if you want the locking done for you.
0275  */
0276 
0277 int __generic_block_fiemap(struct inode *inode,
0278                struct fiemap_extent_info *fieinfo, loff_t start,
0279                loff_t len, get_block_t *get_block)
0280 {
0281     struct buffer_head map_bh;
0282     sector_t start_blk, last_blk;
0283     loff_t isize = i_size_read(inode);
0284     u64 logical = 0, phys = 0, size = 0;
0285     u32 flags = FIEMAP_EXTENT_MERGED;
0286     bool past_eof = false, whole_file = false;
0287     int ret = 0;
0288 
0289     ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
0290     if (ret)
0291         return ret;
0292 
0293     /*
0294      * Either the i_mutex or other appropriate locking needs to be held
0295      * since we expect isize to not change at all through the duration of
0296      * this call.
0297      */
0298     if (len >= isize) {
0299         whole_file = true;
0300         len = isize;
0301     }
0302 
0303     /*
0304      * Some filesystems can't deal with being asked to map less than
0305      * blocksize, so make sure our len is at least block length.
0306      */
0307     if (logical_to_blk(inode, len) == 0)
0308         len = blk_to_logical(inode, 1);
0309 
0310     start_blk = logical_to_blk(inode, start);
0311     last_blk = logical_to_blk(inode, start + len - 1);
0312 
0313     do {
0314         /*
0315          * we set b_size to the total size we want so it will map as
0316          * many contiguous blocks as possible at once
0317          */
0318         memset(&map_bh, 0, sizeof(struct buffer_head));
0319         map_bh.b_size = len;
0320 
0321         ret = get_block(inode, start_blk, &map_bh, 0);
0322         if (ret)
0323             break;
0324 
0325         /* HOLE */
0326         if (!buffer_mapped(&map_bh)) {
0327             start_blk++;
0328 
0329             /*
0330              * We want to handle the case where there is an
0331              * allocated block at the front of the file, and then
0332              * nothing but holes up to the end of the file properly,
0333              * to make sure that extent at the front gets properly
0334              * marked with FIEMAP_EXTENT_LAST
0335              */
0336             if (!past_eof &&
0337                 blk_to_logical(inode, start_blk) >= isize)
0338                 past_eof = 1;
0339 
0340             /*
0341              * First hole after going past the EOF, this is our
0342              * last extent
0343              */
0344             if (past_eof && size) {
0345                 flags = FIEMAP_EXTENT_MERGED|FIEMAP_EXTENT_LAST;
0346                 ret = fiemap_fill_next_extent(fieinfo, logical,
0347                                   phys, size,
0348                                   flags);
0349             } else if (size) {
0350                 ret = fiemap_fill_next_extent(fieinfo, logical,
0351                                   phys, size, flags);
0352                 size = 0;
0353             }
0354 
0355             /* if we have holes up to/past EOF then we're done */
0356             if (start_blk > last_blk || past_eof || ret)
0357                 break;
0358         } else {
0359             /*
0360              * We have gone over the length of what we wanted to
0361              * map, and it wasn't the entire file, so add the extent
0362              * we got last time and exit.
0363              *
0364              * This is for the case where say we want to map all the
0365              * way up to the second to the last block in a file, but
0366              * the last block is a hole, making the second to last
0367              * block FIEMAP_EXTENT_LAST.  In this case we want to
0368              * see if there is a hole after the second to last block
0369              * so we can mark it properly.  If we found data after
0370              * we exceeded the length we were requesting, then we
0371              * are good to go, just add the extent to the fieinfo
0372              * and break
0373              */
0374             if (start_blk > last_blk && !whole_file) {
0375                 ret = fiemap_fill_next_extent(fieinfo, logical,
0376                                   phys, size,
0377                                   flags);
0378                 break;
0379             }
0380 
0381             /*
0382              * if size != 0 then we know we already have an extent
0383              * to add, so add it.
0384              */
0385             if (size) {
0386                 ret = fiemap_fill_next_extent(fieinfo, logical,
0387                                   phys, size,
0388                                   flags);
0389                 if (ret)
0390                     break;
0391             }
0392 
0393             logical = blk_to_logical(inode, start_blk);
0394             phys = blk_to_logical(inode, map_bh.b_blocknr);
0395             size = map_bh.b_size;
0396             flags = FIEMAP_EXTENT_MERGED;
0397 
0398             start_blk += logical_to_blk(inode, size);
0399 
0400             /*
0401              * If we are past the EOF, then we need to make sure as
0402              * soon as we find a hole that the last extent we found
0403              * is marked with FIEMAP_EXTENT_LAST
0404              */
0405             if (!past_eof && logical + size >= isize)
0406                 past_eof = true;
0407         }
0408         cond_resched();
0409         if (fatal_signal_pending(current)) {
0410             ret = -EINTR;
0411             break;
0412         }
0413 
0414     } while (1);
0415 
0416     /* If ret is 1 then we just hit the end of the extent array */
0417     if (ret == 1)
0418         ret = 0;
0419 
0420     return ret;
0421 }
0422 EXPORT_SYMBOL(__generic_block_fiemap);
0423 
0424 /**
0425  * generic_block_fiemap - FIEMAP for block based inodes
0426  * @inode: The inode to map
0427  * @fieinfo: The mapping information
0428  * @start: The initial block to map
0429  * @len: The length of the extect to attempt to map
0430  * @get_block: The block mapping function for the fs
0431  *
0432  * Calls __generic_block_fiemap to map the inode, after taking
0433  * the inode's mutex lock.
0434  */
0435 
0436 int generic_block_fiemap(struct inode *inode,
0437              struct fiemap_extent_info *fieinfo, u64 start,
0438              u64 len, get_block_t *get_block)
0439 {
0440     int ret;
0441     inode_lock(inode);
0442     ret = __generic_block_fiemap(inode, fieinfo, start, len, get_block);
0443     inode_unlock(inode);
0444     return ret;
0445 }
0446 EXPORT_SYMBOL(generic_block_fiemap);
0447 
0448 #endif  /*  CONFIG_BLOCK  */
0449 
0450 /*
0451  * This provides compatibility with legacy XFS pre-allocation ioctls
0452  * which predate the fallocate syscall.
0453  *
0454  * Only the l_start, l_len and l_whence fields of the 'struct space_resv'
0455  * are used here, rest are ignored.
0456  */
0457 int ioctl_preallocate(struct file *filp, void __user *argp)
0458 {
0459     struct inode *inode = file_inode(filp);
0460     struct space_resv sr;
0461 
0462     if (copy_from_user(&sr, argp, sizeof(sr)))
0463         return -EFAULT;
0464 
0465     switch (sr.l_whence) {
0466     case SEEK_SET:
0467         break;
0468     case SEEK_CUR:
0469         sr.l_start += filp->f_pos;
0470         break;
0471     case SEEK_END:
0472         sr.l_start += i_size_read(inode);
0473         break;
0474     default:
0475         return -EINVAL;
0476     }
0477 
0478     return vfs_fallocate(filp, FALLOC_FL_KEEP_SIZE, sr.l_start, sr.l_len);
0479 }
0480 
0481 static int file_ioctl(struct file *filp, unsigned int cmd,
0482         unsigned long arg)
0483 {
0484     struct inode *inode = file_inode(filp);
0485     int __user *p = (int __user *)arg;
0486 
0487     switch (cmd) {
0488     case FIBMAP:
0489         return ioctl_fibmap(filp, p);
0490     case FIONREAD:
0491         return put_user(i_size_read(inode) - filp->f_pos, p);
0492     case FS_IOC_RESVSP:
0493     case FS_IOC_RESVSP64:
0494         return ioctl_preallocate(filp, p);
0495     }
0496 
0497     return vfs_ioctl(filp, cmd, arg);
0498 }
0499 
0500 static int ioctl_fionbio(struct file *filp, int __user *argp)
0501 {
0502     unsigned int flag;
0503     int on, error;
0504 
0505     error = get_user(on, argp);
0506     if (error)
0507         return error;
0508     flag = O_NONBLOCK;
0509 #ifdef __sparc__
0510     /* SunOS compatibility item. */
0511     if (O_NONBLOCK != O_NDELAY)
0512         flag |= O_NDELAY;
0513 #endif
0514     spin_lock(&filp->f_lock);
0515     if (on)
0516         filp->f_flags |= flag;
0517     else
0518         filp->f_flags &= ~flag;
0519     spin_unlock(&filp->f_lock);
0520     return error;
0521 }
0522 
0523 static int ioctl_fioasync(unsigned int fd, struct file *filp,
0524               int __user *argp)
0525 {
0526     unsigned int flag;
0527     int on, error;
0528 
0529     error = get_user(on, argp);
0530     if (error)
0531         return error;
0532     flag = on ? FASYNC : 0;
0533 
0534     /* Did FASYNC state change ? */
0535     if ((flag ^ filp->f_flags) & FASYNC) {
0536         if (filp->f_op->fasync)
0537             /* fasync() adjusts filp->f_flags */
0538             error = filp->f_op->fasync(fd, filp, on);
0539         else
0540             error = -ENOTTY;
0541     }
0542     return error < 0 ? error : 0;
0543 }
0544 
0545 static int ioctl_fsfreeze(struct file *filp)
0546 {
0547     struct super_block *sb = file_inode(filp)->i_sb;
0548 
0549     if (!capable(CAP_SYS_ADMIN))
0550         return -EPERM;
0551 
0552     /* If filesystem doesn't support freeze feature, return. */
0553     if (sb->s_op->freeze_fs == NULL && sb->s_op->freeze_super == NULL)
0554         return -EOPNOTSUPP;
0555 
0556     /* Freeze */
0557     if (sb->s_op->freeze_super)
0558         return sb->s_op->freeze_super(sb);
0559     return freeze_super(sb);
0560 }
0561 
0562 static int ioctl_fsthaw(struct file *filp)
0563 {
0564     struct super_block *sb = file_inode(filp)->i_sb;
0565 
0566     if (!capable(CAP_SYS_ADMIN))
0567         return -EPERM;
0568 
0569     /* Thaw */
0570     if (sb->s_op->thaw_super)
0571         return sb->s_op->thaw_super(sb);
0572     return thaw_super(sb);
0573 }
0574 
0575 static int ioctl_file_dedupe_range(struct file *file, void __user *arg)
0576 {
0577     struct file_dedupe_range __user *argp = arg;
0578     struct file_dedupe_range *same = NULL;
0579     int ret;
0580     unsigned long size;
0581     u16 count;
0582 
0583     if (get_user(count, &argp->dest_count)) {
0584         ret = -EFAULT;
0585         goto out;
0586     }
0587 
0588     size = offsetof(struct file_dedupe_range __user, info[count]);
0589     if (size > PAGE_SIZE) {
0590         ret = -ENOMEM;
0591         goto out;
0592     }
0593 
0594     same = memdup_user(argp, size);
0595     if (IS_ERR(same)) {
0596         ret = PTR_ERR(same);
0597         same = NULL;
0598         goto out;
0599     }
0600 
0601     same->dest_count = count;
0602     ret = vfs_dedupe_file_range(file, same);
0603     if (ret)
0604         goto out;
0605 
0606     ret = copy_to_user(argp, same, size);
0607     if (ret)
0608         ret = -EFAULT;
0609 
0610 out:
0611     kfree(same);
0612     return ret;
0613 }
0614 
0615 /*
0616  * When you add any new common ioctls to the switches above and below
0617  * please update compat_sys_ioctl() too.
0618  *
0619  * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
0620  * It's just a simple helper for sys_ioctl and compat_sys_ioctl.
0621  */
0622 int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
0623          unsigned long arg)
0624 {
0625     int error = 0;
0626     int __user *argp = (int __user *)arg;
0627     struct inode *inode = file_inode(filp);
0628 
0629     switch (cmd) {
0630     case FIOCLEX:
0631         set_close_on_exec(fd, 1);
0632         break;
0633 
0634     case FIONCLEX:
0635         set_close_on_exec(fd, 0);
0636         break;
0637 
0638     case FIONBIO:
0639         error = ioctl_fionbio(filp, argp);
0640         break;
0641 
0642     case FIOASYNC:
0643         error = ioctl_fioasync(fd, filp, argp);
0644         break;
0645 
0646     case FIOQSIZE:
0647         if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode) ||
0648             S_ISLNK(inode->i_mode)) {
0649             loff_t res = inode_get_bytes(inode);
0650             error = copy_to_user(argp, &res, sizeof(res)) ?
0651                     -EFAULT : 0;
0652         } else
0653             error = -ENOTTY;
0654         break;
0655 
0656     case FIFREEZE:
0657         error = ioctl_fsfreeze(filp);
0658         break;
0659 
0660     case FITHAW:
0661         error = ioctl_fsthaw(filp);
0662         break;
0663 
0664     case FS_IOC_FIEMAP:
0665         return ioctl_fiemap(filp, arg);
0666 
0667     case FIGETBSZ:
0668         return put_user(inode->i_sb->s_blocksize, argp);
0669 
0670     case FICLONE:
0671         return ioctl_file_clone(filp, arg, 0, 0, 0);
0672 
0673     case FICLONERANGE:
0674         return ioctl_file_clone_range(filp, argp);
0675 
0676     case FIDEDUPERANGE:
0677         return ioctl_file_dedupe_range(filp, argp);
0678 
0679     default:
0680         if (S_ISREG(inode->i_mode))
0681             error = file_ioctl(filp, cmd, arg);
0682         else
0683             error = vfs_ioctl(filp, cmd, arg);
0684         break;
0685     }
0686     return error;
0687 }
0688 
0689 SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
0690 {
0691     int error;
0692     struct fd f = fdget(fd);
0693 
0694     if (!f.file)
0695         return -EBADF;
0696     error = security_file_ioctl(f.file, cmd, arg);
0697     if (!error)
0698         error = do_vfs_ioctl(f.file, fd, cmd, arg);
0699     fdput(f);
0700     return error;
0701 }