1 #include <mach/mach_types.h>
5 #include <miscfs/devfs/devfs.h>
7 #define DEBUG_SUBSYSTEM S_PORTALS
8 #include <libcfs/libcfs.h>
9 #include <libcfs/kp30.h>
11 int portal_ioctl_getdata(char *buf, char *end, void *arg)
13 struct portal_ioctl_hdr *hdr;
14 struct portal_ioctl_data *data;
18 hdr = (struct portal_ioctl_hdr *)buf;
19 data = (struct portal_ioctl_data *)buf;
20 /* portals_ioctl_data has been copied in by ioctl of osx */
21 memcpy(buf, arg, sizeof(struct portal_ioctl_data));
23 if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
24 CERROR("PORTALS: version mismatch kernel vs application\n");
28 if (hdr->ioc_len + buf >= end) {
29 CERROR("PORTALS: user buffer exceeds kernel buffer\n");
33 if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
34 CERROR("PORTALS: user buffer too small for ioctl\n");
37 buf += size_round(sizeof(*data));
39 if (data->ioc_inllen1) {
40 err = copy_from_user(buf, data->ioc_inlbuf1, size_round(data->ioc_inllen1));
43 data->ioc_inlbuf1 = buf;
44 buf += size_round(data->ioc_inllen1);
47 if (data->ioc_inllen2) {
48 copy_from_user(buf, data->ioc_inlbuf2, size_round(data->ioc_inllen2));
51 data->ioc_inlbuf2 = buf;
57 extern struct cfs_psdev_ops libcfs_psdev_ops;
58 struct portals_device_userstate *mdev_state[16];
61 libcfs_psdev_open(dev_t dev, int flags, int devtype, struct proc *p)
63 struct portals_device_userstate *mstat = NULL;
68 if (devid > 16) return (-ENXIO);
70 if (libcfs_psdev_ops.p_open != NULL)
71 rc = libcfs_psdev_ops.p_open(0, &mstat);
76 mdev_state[devid] = mstat;
81 libcfs_psdev_close(dev_t dev, int flags, int mode, struct proc *p)
87 if (devid > 16) return (-ENXIO);
89 if (libcfs_psdev_ops.p_close != NULL)
90 rc = libcfs_psdev_ops.p_close(0, mdev_state[devid]);
95 mdev_state[devid] = NULL;
100 libcfs_ioctl (dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
103 struct cfs_psdev_file pfile;
107 if (devid > 16) return (-ENXIO);
109 if (suser(p->p_ucred, &p->p_acflag))
113 pfile.private_data = mdev_state[devid];
115 if (libcfs_psdev_ops.p_ioctl != NULL)
116 rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void *)arg);
122 static struct cdevsw libcfs_devsw =
124 libcfs_psdev_open, /* open */
125 libcfs_psdev_close, /* close */
128 libcfs_ioctl, /* ioctl */
140 cfs_psdev_t libcfs_dev = {
149 kportal_daemonize (char *str)
151 printf("Daemonize request: %s.\n", str);
156 kportal_blockallsigs(void)