2006-02-22 20:14:58 +00:00
|
|
|
/*
|
|
|
|
* linux/fs/jfs/ioctl.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Herbert Poetzl
|
|
|
|
* adapted from Remy Card's ext2/ioctl.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/capability.h>
|
2008-02-15 22:37:46 +00:00
|
|
|
#include <linux/mount.h>
|
2006-02-22 20:14:58 +00:00
|
|
|
#include <linux/time.h>
|
2006-10-18 17:55:46 +00:00
|
|
|
#include <linux/sched.h>
|
2012-09-17 16:58:19 +00:00
|
|
|
#include <linux/blkdev.h>
|
2006-02-22 20:14:58 +00:00
|
|
|
#include <asm/current.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2006-02-22 20:14:58 +00:00
|
|
|
|
2012-09-17 16:58:19 +00:00
|
|
|
#include "jfs_filsys.h"
|
|
|
|
#include "jfs_debug.h"
|
2006-02-22 20:14:58 +00:00
|
|
|
#include "jfs_incore.h"
|
|
|
|
#include "jfs_dinode.h"
|
|
|
|
#include "jfs_inode.h"
|
2012-09-17 16:58:19 +00:00
|
|
|
#include "jfs_dmap.h"
|
|
|
|
#include "jfs_discard.h"
|
2006-02-22 20:14:58 +00:00
|
|
|
|
|
|
|
static struct {
|
|
|
|
long jfs_flag;
|
|
|
|
long ext2_flag;
|
|
|
|
} jfs_map[] = {
|
2006-08-29 18:06:16 +00:00
|
|
|
{JFS_NOATIME_FL, FS_NOATIME_FL},
|
|
|
|
{JFS_DIRSYNC_FL, FS_DIRSYNC_FL},
|
|
|
|
{JFS_SYNC_FL, FS_SYNC_FL},
|
|
|
|
{JFS_SECRM_FL, FS_SECRM_FL},
|
|
|
|
{JFS_UNRM_FL, FS_UNRM_FL},
|
|
|
|
{JFS_APPEND_FL, FS_APPEND_FL},
|
|
|
|
{JFS_IMMUTABLE_FL, FS_IMMUTABLE_FL},
|
2006-02-22 20:14:58 +00:00
|
|
|
{0, 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
static long jfs_map_ext2(unsigned long flags, int from)
|
|
|
|
{
|
|
|
|
int index=0;
|
|
|
|
long mapped=0;
|
|
|
|
|
|
|
|
while (jfs_map[index].jfs_flag) {
|
|
|
|
if (from) {
|
|
|
|
if (jfs_map[index].ext2_flag & flags)
|
|
|
|
mapped |= jfs_map[index].jfs_flag;
|
|
|
|
} else {
|
|
|
|
if (jfs_map[index].jfs_flag & flags)
|
|
|
|
mapped |= jfs_map[index].ext2_flag;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
return mapped;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-27 22:58:51 +00:00
|
|
|
long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
2006-02-22 20:14:58 +00:00
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *inode = file_inode(filp);
|
2006-02-22 20:14:58 +00:00
|
|
|
struct jfs_inode_info *jfs_inode = JFS_IP(inode);
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case JFS_IOC_GETFLAGS:
|
2007-04-25 14:36:20 +00:00
|
|
|
jfs_get_inode_flags(jfs_inode);
|
2006-02-22 20:14:58 +00:00
|
|
|
flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
|
|
|
|
flags = jfs_map_ext2(flags, 0);
|
|
|
|
return put_user(flags, (int __user *) arg);
|
|
|
|
case JFS_IOC_SETFLAGS: {
|
|
|
|
unsigned int oldflags;
|
2008-02-15 22:37:46 +00:00
|
|
|
int err;
|
2006-02-22 20:14:58 +00:00
|
|
|
|
2011-11-23 16:57:51 +00:00
|
|
|
err = mnt_want_write_file(filp);
|
2008-02-15 22:37:46 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2006-02-22 20:14:58 +00:00
|
|
|
|
2011-03-23 23:43:26 +00:00
|
|
|
if (!inode_owner_or_capable(inode)) {
|
2008-02-15 22:37:46 +00:00
|
|
|
err = -EACCES;
|
|
|
|
goto setflags_out;
|
|
|
|
}
|
|
|
|
if (get_user(flags, (int __user *) arg)) {
|
|
|
|
err = -EFAULT;
|
|
|
|
goto setflags_out;
|
|
|
|
}
|
2006-02-22 20:14:58 +00:00
|
|
|
|
|
|
|
flags = jfs_map_ext2(flags, 1);
|
|
|
|
if (!S_ISDIR(inode->i_mode))
|
|
|
|
flags &= ~JFS_DIRSYNC_FL;
|
|
|
|
|
2007-11-15 00:58:56 +00:00
|
|
|
/* Is it quota file? Do not allow user to mess with it */
|
2008-02-15 22:37:46 +00:00
|
|
|
if (IS_NOQUOTA(inode)) {
|
|
|
|
err = -EPERM;
|
|
|
|
goto setflags_out;
|
|
|
|
}
|
2008-01-27 22:58:51 +00:00
|
|
|
|
|
|
|
/* Lock against other parallel changes of flags */
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_lock(inode);
|
2008-01-27 22:58:51 +00:00
|
|
|
|
2007-04-25 14:36:20 +00:00
|
|
|
jfs_get_inode_flags(jfs_inode);
|
2006-02-22 20:14:58 +00:00
|
|
|
oldflags = jfs_inode->mode2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The IMMUTABLE and APPEND_ONLY flags can only be changed by
|
|
|
|
* the relevant capability.
|
|
|
|
*/
|
|
|
|
if ((oldflags & JFS_IMMUTABLE_FL) ||
|
|
|
|
((flags ^ oldflags) &
|
|
|
|
(JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
|
2008-01-27 22:58:51 +00:00
|
|
|
if (!capable(CAP_LINUX_IMMUTABLE)) {
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2008-02-15 22:37:46 +00:00
|
|
|
err = -EPERM;
|
|
|
|
goto setflags_out;
|
2008-01-27 22:58:51 +00:00
|
|
|
}
|
2006-02-22 20:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flags = flags & JFS_FL_USER_MODIFIABLE;
|
|
|
|
flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
|
|
|
|
jfs_inode->mode2 = flags;
|
|
|
|
|
|
|
|
jfs_set_inode_flags(inode);
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2016-11-11 18:00:53 +00:00
|
|
|
inode->i_ctime = current_time(inode);
|
2006-02-22 20:14:58 +00:00
|
|
|
mark_inode_dirty(inode);
|
2008-02-15 22:37:46 +00:00
|
|
|
setflags_out:
|
2011-12-09 13:06:57 +00:00
|
|
|
mnt_drop_write_file(filp);
|
2008-02-15 22:37:46 +00:00
|
|
|
return err;
|
2006-02-22 20:14:58 +00:00
|
|
|
}
|
2012-09-17 16:58:19 +00:00
|
|
|
|
|
|
|
case FITRIM:
|
|
|
|
{
|
|
|
|
struct super_block *sb = inode->i_sb;
|
|
|
|
struct request_queue *q = bdev_get_queue(sb->s_bdev);
|
|
|
|
struct fstrim_range range;
|
|
|
|
s64 ret = 0;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
if (!blk_queue_discard(q)) {
|
|
|
|
jfs_warn("FITRIM not supported on device");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_from_user(&range, (struct fstrim_range __user *)arg,
|
|
|
|
sizeof(range)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
range.minlen = max_t(unsigned int, range.minlen,
|
|
|
|
q->limits.discard_granularity);
|
|
|
|
|
|
|
|
ret = jfs_ioc_trim(inode, &range);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (copy_to_user((struct fstrim_range __user *)arg, &range,
|
|
|
|
sizeof(range)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-22 20:14:58 +00:00
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 23:02:02 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
long jfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
/* While these ioctl numbers defined with 'long' and have different
|
|
|
|
* numbers than the 64bit ABI,
|
|
|
|
* the actual implementation only deals with ints and is compatible.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case JFS_IOC_GETFLAGS32:
|
|
|
|
cmd = JFS_IOC_GETFLAGS;
|
|
|
|
break;
|
|
|
|
case JFS_IOC_SETFLAGS32:
|
|
|
|
cmd = JFS_IOC_SETFLAGS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return jfs_ioctl(filp, cmd, arg);
|
|
|
|
}
|
|
|
|
#endif
|