4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_CLASS
39 #include <mach/mach_types.h>
43 #include <miscfs/devfs/devfs.h>
45 #include <libcfs/libcfs.h>
46 #include <obd_support.h>
47 #include <obd_class.h>
48 #include <lprocfs_status.h>
50 #ifndef OBD_MAX_IOCTL_BUFFER
51 #define OBD_MAX_IOCTL_BUFFER 8192
54 /* buffer MUST be at least the size of obd_ioctl_hdr */
55 int obd_ioctl_getdata(char **buf, int *len, void *arg)
57 struct obd_ioctl_hdr *hdr;
58 struct obd_ioctl_data *data;
63 hdr = (struct obd_ioctl_hdr *)arg;
64 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
65 CERROR("Version mismatch kernel vs application\n");
69 if (hdr->ioc_len > OBD_MAX_IOCTL_BUFFER) {
70 CERROR("User buffer len %d exceeds %d max buffer\n",
71 hdr->ioc_len, OBD_MAX_IOCTL_BUFFER);
75 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
76 CERROR("OBD: user buffer too small for ioctl (%d)\n", hdr->ioc_len);
80 OBD_ALLOC_LARGE(*buf, hdr->ioc_len);
82 CERROR("Cannot allocate control buffer of len %d\n",
87 data = (struct obd_ioctl_data *)*buf;
89 bzero(data, hdr->ioc_len);
90 memcpy(data, (void *)arg, sizeof(struct obd_ioctl_data));
91 if (data->ioc_inlbuf1)
92 err = copy_from_user(&data->ioc_bulk[0], (void *)data->ioc_inlbuf1,
93 hdr->ioc_len - ((void *)&data->ioc_bulk[0] - (void *)data));
95 if (obd_ioctl_is_invalid(data)) {
96 CERROR("ioctl not correctly formatted\n");
97 OBD_FREE_LARGE(*buf, hdr->ioc_len);
101 if (data->ioc_inllen1) {
102 data->ioc_inlbuf1 = &data->ioc_bulk[0];
103 offset += size_round(data->ioc_inllen1);
106 if (data->ioc_inllen2) {
107 data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
108 offset += size_round(data->ioc_inllen2);
111 if (data->ioc_inllen3) {
112 data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
113 offset += size_round(data->ioc_inllen3);
116 if (data->ioc_inllen4) {
117 data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
124 int obd_ioctl_popdata(void *arg, void *data, int len)
127 * Xnu ioctl copyout(uaddr, arg, sizeof(struct obd_ioctl_data)),
128 * we have to copyout data exceed sizeof(struct obd_ioctl_data)
131 if (len <= sizeof(struct obd_ioctl_data)) {
132 memcpy(arg, data, len);
136 struct obd_ioctl_data *u = (struct obd_ioctl_data *)arg;
137 struct obd_ioctl_data *k = (struct obd_ioctl_data *)data;
138 err = copy_to_user((void *)u->ioc_inlbuf1, &k->ioc_bulk[0],
139 len -((void *)&k->ioc_bulk[0] -(void *)k));
140 memcpy(arg, data, sizeof(struct obd_ioctl_data));
146 obd_class_open(dev_t dev, int flags, int devtype, struct proc *p)
153 /* closing /dev/obd */
155 obd_class_release(dev_t dev, int flags, int mode, struct proc *p)
163 obd_class_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
171 err = class_handle_ioctl(cmd, (unsigned long)arg);
176 static struct cdevsw obd_psdevsw = {
192 cfs_psdev_t obd_psdev = {
199 int class_procfs_init(void)
204 int class_procfs_clean(void)