1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Copyright (c) 2004 Cluster File Systems, Inc.
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or modify it under
10 * the terms of version 2 of the GNU General Public License as published by
11 * the Free Software Foundation. Lustre is distributed in the hope that it
12 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. You should have received a
15 * copy of the GNU General Public License along with Lustre; if not, write
16 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 #define DEBUG_SUBSYSTEM S_LIBCFS
23 #include <libcfs/libcfs.h>
25 #define LIBCFS_MINOR 240
27 int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
29 struct libcfs_ioctl_hdr *hdr;
30 struct libcfs_ioctl_data *data;
34 hdr = (struct libcfs_ioctl_hdr *)buf;
35 data = (struct libcfs_ioctl_data *)buf;
37 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
41 if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) {
42 CERROR(("LIBCFS: version mismatch kernel vs application\n"));
46 if (hdr->ioc_len + buf >= end) {
47 CERROR(("LIBCFS: user buffer exceeds kernel buffer\n"));
51 if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) {
52 CERROR(("LIBCFS: user buffer too small for ioctl\n"));
56 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
60 if (libcfs_ioctl_is_invalid(data)) {
61 CERROR(("LIBCFS: ioctl not correctly formatted\n"));
65 if (data->ioc_inllen1)
66 data->ioc_inlbuf1 = &data->ioc_bulk[0];
68 if (data->ioc_inllen2)
69 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
70 size_round(data->ioc_inllen1);
75 extern struct cfs_psdev_ops libcfs_psdev_ops;
78 libcfs_psdev_open(cfs_file_t * file)
80 struct libcfs_device_userstate **pdu = NULL;
83 pdu = (struct libcfs_device_userstate **)&file->private_data;
84 if (libcfs_psdev_ops.p_open != NULL)
85 rc = libcfs_psdev_ops.p_open(0, (void *)pdu);
91 /* called when closing /dev/device */
93 libcfs_psdev_release(cfs_file_t * file)
95 struct libcfss_device_userstate *pdu;
98 pdu = file->private_data;
99 if (libcfs_psdev_ops.p_close != NULL)
100 rc = libcfs_psdev_ops.p_close(0, (void *)pdu);
107 libcfs_ioctl(cfs_file_t * file, unsigned int cmd, ulong_ptr arg)
109 struct cfs_psdev_file pfile;
112 if ( _IOC_TYPE(cmd) != IOC_LIBCFS_TYPE ||
113 _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR ||
114 _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR ) {
115 CDEBUG(D_IOCTL, ("invalid ioctl ( type %d, nr %d, size %d )\n",
116 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd)));
120 /* Handle platform-dependent IOC requests */
122 case IOC_LIBCFS_PANIC:
123 if (!capable (CAP_SYS_BOOT))
125 CERROR(("debugctl-invoked panic"));
126 KeBugCheckEx('LUFS', (ULONG_PTR)libcfs_ioctl, (ULONG_PTR)NULL, (ULONG_PTR)NULL, (ULONG_PTR)NULL);
129 case IOC_LIBCFS_MEMHOG:
131 if (!capable (CAP_SYS_ADMIN))
137 pfile.private_data = file->private_data;
138 if (libcfs_psdev_ops.p_ioctl != NULL)
139 rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void *)arg);
145 static struct file_operations libcfs_fops = {
149 /* ioctl: */ libcfs_ioctl,
150 /* open: */ libcfs_psdev_open,
151 /* release:*/ libcfs_psdev_release
154 cfs_psdev_t libcfs_dev = {