libfuse
ioctl_client.c
Go to the documentation of this file.
1 /*
2  FUSE fioclient: FUSE ioctl example client
3  Copyright (C) 2008 SUSE Linux Products GmbH
4  Copyright (C) 2008 Tejun Heo <teheo@suse.de>
5 
6  This program tests the ioctl.c example file systsem.
7 
8  This program can be distributed under the terms of the GNU GPL.
9  See the file COPYING.
10 */
11 
24 #include <sys/types.h>
25 #include <fcntl.h>
26 #include <sys/stat.h>
27 #include <sys/ioctl.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <ctype.h>
31 #include <errno.h>
32 #include "ioctl.h"
33 
34 const char *usage =
35 "Usage: fioclient FIOC_FILE [size]\n"
36 "\n"
37 "Get size if <size> is omitted, set size otherwise\n"
38 "\n";
39 
40 int main(int argc, char **argv)
41 {
42  size_t size;
43  int fd;
44 
45  if (argc < 2) {
46  fprintf(stderr, "%s", usage);
47  return 1;
48  }
49 
50  fd = open(argv[1], O_RDWR);
51  if (fd < 0) {
52  perror("open");
53  return 1;
54  }
55 
56  if (argc == 2) {
57  if (ioctl(fd, FIOC_GET_SIZE, &size)) {
58  perror("ioctl");
59  return 1;
60  }
61  printf("%zu\n", size);
62  } else {
63  size = strtoul(argv[2], NULL, 0);
64  if (ioctl(fd, FIOC_SET_SIZE, &size)) {
65  perror("ioctl");
66  return 1;
67  }
68  }
69  return 0;
70 }