1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
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 # define EXPORT_SYMTAB
42 #include <mach/mach_types.h>
46 #include <miscfs/devfs/devfs.h>
48 #include <libcfs/libcfs.h>
49 #include <obd_support.h>
50 #include <obd_class.h>
51 #include <lprocfs_status.h>
53 #ifndef OBD_MAX_IOCTL_BUFFER
54 #define OBD_MAX_IOCTL_BUFFER 8192
57 /* buffer MUST be at least the size of obd_ioctl_hdr */
58 int obd_ioctl_getdata(char **buf, int *len, void *arg)
60 struct obd_ioctl_hdr *hdr;
61 struct obd_ioctl_data *data;
66 hdr = (struct obd_ioctl_hdr *)arg;
67 if (hdr->ioc_version != OBD_IOCTL_VERSION) {
68 CERROR("Version mismatch kernel vs application\n");
72 if (hdr->ioc_len > OBD_MAX_IOCTL_BUFFER) {
73 CERROR("User buffer len %d exceeds %d max buffer\n",
74 hdr->ioc_len, OBD_MAX_IOCTL_BUFFER);
78 if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
79 CERROR("OBD: user buffer too small for ioctl (%d)\n", hdr->ioc_len);
83 OBD_ALLOC_LARGE(*buf, hdr->ioc_len);
85 CERROR("Cannot allocate control buffer of len %d\n",
90 data = (struct obd_ioctl_data *)*buf;
92 bzero(data, hdr->ioc_len);
93 memcpy(data, (void *)arg, sizeof(struct obd_ioctl_data));
94 if (data->ioc_inlbuf1)
95 err = copy_from_user(&data->ioc_bulk[0], (void *)data->ioc_inlbuf1,
96 hdr->ioc_len - ((void *)&data->ioc_bulk[0] - (void *)data));
98 if (obd_ioctl_is_invalid(data)) {
99 CERROR("ioctl not correctly formatted\n");
100 OBD_FREE_LARGE(*buf, hdr->ioc_len);
104 if (data->ioc_inllen1) {
105 data->ioc_inlbuf1 = &data->ioc_bulk[0];
106 offset += size_round(data->ioc_inllen1);
109 if (data->ioc_inllen2) {
110 data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
111 offset += size_round(data->ioc_inllen2);
114 if (data->ioc_inllen3) {
115 data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
116 offset += size_round(data->ioc_inllen3);
119 if (data->ioc_inllen4) {
120 data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
127 int obd_ioctl_popdata(void *arg, void *data, int len)
130 * Xnu ioctl copyout(uaddr, arg, sizeof(struct obd_ioctl_data)),
131 * we have to copyout data exceed sizeof(struct obd_ioctl_data)
134 if (len <= sizeof(struct obd_ioctl_data)) {
135 memcpy(arg, data, len);
139 struct obd_ioctl_data *u = (struct obd_ioctl_data *)arg;
140 struct obd_ioctl_data *k = (struct obd_ioctl_data *)data;
141 err = copy_to_user((void *)u->ioc_inlbuf1, &k->ioc_bulk[0],
142 len -((void *)&k->ioc_bulk[0] -(void *)k));
143 memcpy(arg, data, sizeof(struct obd_ioctl_data));
149 obd_class_open(dev_t dev, int flags, int devtype, struct proc *p)
156 /* closing /dev/obd */
158 obd_class_release(dev_t dev, int flags, int mode, struct proc *p)
166 obd_class_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
174 err = class_handle_ioctl(cmd, (unsigned long)arg);
179 static struct cdevsw obd_psdevsw = {
195 cfs_psdev_t obd_psdev = {
202 int class_procfs_init(void)
207 int class_procfs_clean(void)