-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* Copyright (C) 2001, 2002 Cluster File Systems, Inc.
*
* This file is part of Portals, http://www.sf.net/projects/lustre/
#define __USE_FILE_OFFSET64
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <unistd.h>
-
-
#include <libcfs/libcfsutil.h>
-
-#include <lnet/api-support.h>
#include <lnet/lnetctl.h>
-#include <libcfs/portals_utils.h>
-
static ioc_handler_t do_ioctl; /* forward ref */
static ioc_handler_t *current_ioc_handler = &do_ioctl;
}
if (ioc_dev_list[dev_id].dev_fd < 0) {
- int fd = open(dev_name, O_RDWR);
-
- /* Make the /dev/ node if we need to */
- if (fd < 0 && errno == ENOENT) {
- if (mknod(dev_name,
- S_IFCHR|S_IWUSR|S_IRUSR,
- MKDEV(ioc_dev_list[dev_id].dev_major,
- ioc_dev_list[dev_id].dev_minor)) == 0)
- fd = open(dev_name, O_RDWR);
+ int fd = open(dev_name, O_RDWR);
+
+ /* Make the /dev/ node if we need to */
+ if (fd < 0 && errno == ENOENT) {
+ if (mknod(dev_name, S_IFCHR|S_IWUSR|S_IRUSR,
+ MKDEV(ioc_dev_list[dev_id].dev_major,
+ ioc_dev_list[dev_id].dev_minor)) == 0)
+ fd = open(dev_name, O_RDWR);
else
fprintf(stderr, "mknod %s failed: %s\n",
dev_name, strerror(errno));
if (fd < 0)
return fd;
- rc = ioctl(fd, opc, buf);
- return rc;
-
+ rc = ioctl(fd, opc, buf);
+
+ return rc;
}
static FILE *
void
unregister_ioc_dev(int dev_id)
{
+ if (dev_id < 0 ||
+ dev_id >= sizeof(ioc_dev_list) / sizeof(ioc_dev_list[0]))
+ return;
- if (dev_id < 0 ||
- dev_id >= sizeof(ioc_dev_list) / sizeof(ioc_dev_list[0]))
- return;
- if (ioc_dev_list[dev_id].dev_name != NULL &&
- ioc_dev_list[dev_id].dev_fd >= 0)
- close(ioc_dev_list[dev_id].dev_fd);
+ if (ioc_dev_list[dev_id].dev_name != NULL &&
+ ioc_dev_list[dev_id].dev_fd >= 0)
+ close(ioc_dev_list[dev_id].dev_fd);
- ioc_dev_list[dev_id].dev_name = NULL;
- ioc_dev_list[dev_id].dev_fd = -1;
+ ioc_dev_list[dev_id].dev_name = NULL;
+ ioc_dev_list[dev_id].dev_fd = -1;
}
/* If this file is set, then all ioctl buffers will be
parse_dump(char * dump_file, ioc_handler_t ioc_func)
{
int line =0;
- struct stat st;
char *start, *buf, *end;
-#ifndef __CYGWIN__
+ struct stat st;
int fd;
-#else
- HANDLE fd, hmap;
- DWORD size;
-#endif
-
-#ifndef __CYGWIN__
- fd = syscall(SYS_open, dump_file, O_RDONLY);
+
+ fd = open(dump_file, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "couldn't open %s: %s\n", dump_file,
strerror(errno));
fprintf(stderr, "can't create file mapping\n");
exit(1);
}
-#else
- fd = CreateFile(dump_file, GENERIC_READ, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- size = GetFileSize(fd, NULL);
- if (size < 1) {
- fprintf(stderr, "KML is empty\n");
- exit(1);
- }
-
- hmap = CreateFileMapping(fd, NULL, PAGE_READONLY, 0,0, NULL);
- start = buf = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0);
- end = buf + size;
- CloseHandle(fd);
- if (start == NULL) {
- fprintf(stderr, "can't create file mapping\n");
- exit(1);
- }
-#endif /* __CYGWIN__ */
while (buf < end) {
struct dump_hdr *dump_hdr = (struct dump_hdr *) buf;
buf += data->ioc_len + sizeof(*dump_hdr);
}
-#ifndef __CYGWIN__
- munmap(start, end - start);
-#else
- UnmapViewOfFile(start);
- CloseHandle(hmap);
-#endif
+ munmap(start, end - start);
- return 0;
+ return 0;
}
int
int libcfs_ioctl_pack(struct libcfs_ioctl_data *data, char **pbuf,
int max)
{
- char *ptr;
- struct libcfs_ioctl_data *overlay;
- data->ioc_len = libcfs_ioctl_packlen(data);
- data->ioc_version = LIBCFS_IOCTL_VERSION;
-
- if (*pbuf && libcfs_ioctl_packlen(data) > max)
- return 1;
- if (*pbuf == NULL) {
- *pbuf = malloc(data->ioc_len);
- }
- if (!*pbuf)
- return 1;
- overlay = (struct libcfs_ioctl_data *)*pbuf;
- memcpy(*pbuf, data, sizeof(*data));
-
- ptr = overlay->ioc_bulk;
- if (data->ioc_inlbuf1)
- LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
- if (data->ioc_inlbuf2)
- LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
- if (libcfs_ioctl_is_invalid(overlay))
- return 1;
-
- return 0;
+ char *ptr;
+ struct libcfs_ioctl_data *overlay;
+ data->ioc_hdr.ioc_len = libcfs_ioctl_packlen(data);
+ data->ioc_hdr.ioc_version = LIBCFS_IOCTL_VERSION;
+
+ if (*pbuf != NULL && libcfs_ioctl_packlen(data) > max)
+ return 1;
+ if (*pbuf == NULL)
+ *pbuf = malloc(data->ioc_hdr.ioc_len);
+ if (*pbuf == NULL)
+ return 1;
+ overlay = (struct libcfs_ioctl_data *)*pbuf;
+ memcpy(*pbuf, data, sizeof(*data));
+
+ ptr = overlay->ioc_bulk;
+ if (data->ioc_inlbuf1 != NULL)
+ LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
+ if (data->ioc_inlbuf2 != NULL)
+ LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
+ if (libcfs_ioctl_is_invalid(overlay))
+ return 1;
+
+ return 0;
}
+void
+libcfs_ioctl_unpack(struct libcfs_ioctl_data *data, char *pbuf)
+{
+ struct libcfs_ioctl_data *overlay = (struct libcfs_ioctl_data *)pbuf;
+ char *ptr;
+
+ /* Preserve the caller's buffer pointers */
+ overlay->ioc_inlbuf1 = data->ioc_inlbuf1;
+ overlay->ioc_inlbuf2 = data->ioc_inlbuf2;
+
+ memcpy(data, pbuf, sizeof(*data));
+ ptr = &overlay->ioc_bulk[0];
+
+ if (data->ioc_inlbuf1 != NULL)
+ LOGU(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
+ if (data->ioc_inlbuf2 != NULL)
+ LOGU(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
+}