1 #define DEBUG_SUBSYSTEM S_LNET
3 #include <libcfs/libcfs.h>
7 int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
9 struct libcfs_ioctl_hdr *hdr;
10 struct libcfs_ioctl_data *data;
14 hdr = (struct libcfs_ioctl_hdr *)buf;
15 data = (struct libcfs_ioctl_data *)buf;
17 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
21 if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) {
22 CERROR("PORTALS: version mismatch kernel vs application\n");
26 if (hdr->ioc_len + buf >= end) {
27 CERROR("PORTALS: user buffer exceeds kernel buffer\n");
32 if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) {
33 CERROR("PORTALS: user buffer too small for ioctl\n");
37 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
41 if (libcfs_ioctl_is_invalid(data)) {
42 CERROR("PORTALS: ioctl not correctly formatted\n");
46 if (data->ioc_inllen1)
47 data->ioc_inlbuf1 = &data->ioc_bulk[0];
49 if (data->ioc_inllen2)
50 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
51 size_round(data->ioc_inllen1);
56 int libcfs_ioctl_popdata(void *arg, void *data, int size)
58 if (copy_to_user((char *)arg, data, size))
63 extern struct cfs_psdev_ops libcfs_psdev_ops;
66 libcfs_psdev_open(struct inode * inode, struct file * file)
68 struct libcfs_device_userstate **pdu = NULL;
73 pdu = (struct libcfs_device_userstate **)&file->private_data;
74 if (libcfs_psdev_ops.p_open != NULL)
75 rc = libcfs_psdev_ops.p_open(0, (void *)pdu);
81 /* called when closing /dev/device */
83 libcfs_psdev_release(struct inode * inode, struct file * file)
85 struct libcfs_device_userstate *pdu;
90 pdu = file->private_data;
91 if (libcfs_psdev_ops.p_close != NULL)
92 rc = libcfs_psdev_ops.p_close(0, (void *)pdu);
99 libcfs_ioctl(struct inode *inode, struct file *file,
100 unsigned int cmd, unsigned long arg)
102 struct cfs_psdev_file pfile;
105 if (current->fsuid != 0)
108 if ( _IOC_TYPE(cmd) != IOC_LIBCFS_TYPE ||
109 _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR ||
110 _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR ) {
111 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
112 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
116 /* Handle platform-dependent IOC requests */
118 case IOC_LIBCFS_PANIC:
119 if (!capable (CAP_SYS_BOOT))
121 panic("debugctl-invoked panic");
123 case IOC_LIBCFS_MEMHOG:
124 if (!capable (CAP_SYS_ADMIN))
130 pfile.private_data = file->private_data;
131 if (libcfs_psdev_ops.p_ioctl != NULL)
132 rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void *)arg);
138 static struct file_operations libcfs_fops = {
140 open: libcfs_psdev_open,
141 release: libcfs_psdev_release
144 cfs_psdev_t libcfs_dev = {