1 #define DEBUG_SUBSYSTEM S_LNET
3 #include <libcfs/libcfs.h>
4 #include <libcfs/kp30.h>
8 int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
10 struct libcfs_ioctl_hdr *hdr;
11 struct libcfs_ioctl_data *data;
15 hdr = (struct libcfs_ioctl_hdr *)buf;
16 data = (struct libcfs_ioctl_data *)buf;
18 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
22 if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) {
23 CERROR("PORTALS: version mismatch kernel vs application\n");
27 if (hdr->ioc_len + buf >= end) {
28 CERROR("PORTALS: user buffer exceeds kernel buffer\n");
33 if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) {
34 CERROR("PORTALS: user buffer too small for ioctl\n");
38 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
42 if (libcfs_ioctl_is_invalid(data)) {
43 CERROR("PORTALS: ioctl not correctly formatted\n");
47 if (data->ioc_inllen1)
48 data->ioc_inlbuf1 = &data->ioc_bulk[0];
50 if (data->ioc_inllen2)
51 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
52 size_round(data->ioc_inllen1);
57 int libcfs_ioctl_popdata(void *arg, void *data, int size)
59 if (copy_to_user((char *)arg, data, size))
64 extern struct cfs_psdev_ops libcfs_psdev_ops;
67 libcfs_psdev_open(struct inode * inode, struct file * file)
69 struct libcfs_device_userstate **pdu = NULL;
74 pdu = (struct libcfs_device_userstate **)&file->private_data;
75 if (libcfs_psdev_ops.p_open != NULL)
76 rc = libcfs_psdev_ops.p_open(0, (void *)pdu);
82 /* called when closing /dev/device */
84 libcfs_psdev_release(struct inode * inode, struct file * file)
86 struct libcfs_device_userstate *pdu;
91 pdu = file->private_data;
92 if (libcfs_psdev_ops.p_close != NULL)
93 rc = libcfs_psdev_ops.p_close(0, (void *)pdu);
100 libcfs_ioctl(struct inode *inode, struct file *file,
101 unsigned int cmd, unsigned long arg)
103 struct cfs_psdev_file pfile;
106 if (current->fsuid != 0)
109 if ( _IOC_TYPE(cmd) != IOC_LIBCFS_TYPE ||
110 _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR ||
111 _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR ) {
112 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
113 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
117 /* Handle platform-dependent IOC requests */
119 case IOC_LIBCFS_PANIC:
120 if (!capable (CAP_SYS_BOOT))
122 panic("debugctl-invoked panic");
124 case IOC_LIBCFS_MEMHOG:
125 if (!capable (CAP_SYS_ADMIN))
131 pfile.private_data = file->private_data;
132 if (libcfs_psdev_ops.p_ioctl != NULL)
133 rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void *)arg);
139 static struct file_operations libcfs_fops = {
141 open: libcfs_psdev_open,
142 release: libcfs_psdev_release
145 cfs_psdev_t libcfs_dev = {