blob: cb9fd59a688c23c7ba1c31fee5a7b3a3c36fd862 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Pioctl operations for Coda.
John Kacur1977bb22010-05-05 15:15:35 +02004 * Original version: (C) 1996 Peter Braam
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Rewritten for Linux 2.1: (C) 1997 Carnegie Mellon University
6 *
7 * Carnegie Mellon encourages users of this code to contribute improvements
8 * to the Coda project. Contact Peter Braam <coda@cs.cmu.edu>.
9 */
10
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/time.h>
14#include <linux/fs.h>
15#include <linux/stat.h>
16#include <linux/errno.h>
17#include <linux/string.h>
18#include <linux/namei.h>
19#include <linux/module.h>
Fabian Frederick834b46c2014-08-08 14:20:33 -070020#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <linux/coda.h>
David Howells8fc8b9d2019-07-16 16:28:47 -070023#include "coda_psdev.h"
Al Viro31a203d2011-01-12 16:36:09 -050024#include "coda_linux.h"
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/* pioctl ops */
Christian Brauner549c7292021-01-21 14:19:43 +010027static int coda_ioctl_permission(struct user_namespace *mnt_userns,
28 struct inode *inode, int mask);
John Kacur2ff82f82010-05-05 15:15:34 +020029static long coda_pioctl(struct file *filp, unsigned int cmd,
30 unsigned long user_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/* exported from this file */
John Kacur1977bb22010-05-05 15:15:35 +020033const struct inode_operations coda_ioctl_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 .permission = coda_ioctl_permission,
35 .setattr = coda_setattr,
36};
37
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080038const struct file_operations coda_ioctl_operations = {
John Kacur2ff82f82010-05-05 15:15:34 +020039 .unlocked_ioctl = coda_pioctl,
Arnd Bergmann6038f372010-08-15 18:52:59 +020040 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041};
42
43/* the coda pioctl inode ops */
Christian Brauner549c7292021-01-21 14:19:43 +010044static int coda_ioctl_permission(struct user_namespace *mnt_userns,
45 struct inode *inode, int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Miklos Szeredif696a362008-07-31 13:41:58 +020047 return (mask & MAY_EXEC) ? -EACCES : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
John Kacur2ff82f82010-05-05 15:15:34 +020050static long coda_pioctl(struct file *filp, unsigned int cmd,
51 unsigned long user_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Al Viro2d8f3032008-07-22 09:59:21 -040053 struct path path;
John Kacur1977bb22010-05-05 15:15:35 +020054 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 struct PioctlData data;
Al Viro496ad9a2013-01-23 17:07:38 -050056 struct inode *inode = file_inode(filp);
John Kacur1977bb22010-05-05 15:15:35 +020057 struct inode *target_inode = NULL;
58 struct coda_inode_info *cnp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
John Kacur1977bb22010-05-05 15:15:35 +020060 /* get the Pioctl data arguments from user space */
Yoshihisa Abef7cc02b82010-10-25 02:03:45 -040061 if (copy_from_user(&data, (void __user *)user_data, sizeof(data)))
62 return -EINVAL;
John Kacur1977bb22010-05-05 15:15:35 +020063
64 /*
65 * Look up the pathname. Note that the pathname is in
66 * user memory, and namei takes care of this
67 */
Al Viroce6595a2019-07-14 16:42:44 -040068 error = user_path_at(AT_FDCWD, data.path,
69 data.follow ? LOOKUP_FOLLOW : 0, &path);
John Kacur2ff82f82010-05-05 15:15:34 +020070 if (error)
Yoshihisa Abef7cc02b82010-10-25 02:03:45 -040071 return error;
72
David Howells2b0143b2015-03-17 22:25:59 +000073 target_inode = d_inode(path.dentry);
John Kacur2ff82f82010-05-05 15:15:34 +020074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 /* return if it is not a Coda inode */
John Kacur1977bb22010-05-05 15:15:35 +020076 if (target_inode->i_sb != inode->i_sb) {
John Kacur2ff82f82010-05-05 15:15:34 +020077 error = -EINVAL;
78 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
80
81 /* now proceed to make the upcall */
John Kacur1977bb22010-05-05 15:15:35 +020082 cnp = ITOC(target_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
John Kacur2ff82f82010-05-05 15:15:34 +020085out:
Yoshihisa Abef7cc02b82010-10-25 02:03:45 -040086 path_put(&path);
John Kacur1977bb22010-05-05 15:15:35 +020087 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}