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 GPLv2.
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 <unistd.h>
33 #include "ioctl.h"
34 
35 const char *usage =
36 "Usage: fioclient FIOC_FILE [size]\n"
37 "\n"
38 "Get size if <size> is omitted, set size otherwise\n"
39 "\n";
40 
41 int main(int argc, char **argv)
42 {
43  size_t size;
44  int fd;
45  int ret = 0;
46 
47  if (argc < 2) {
48  fprintf(stderr, "%s", usage);
49  return 1;
50  }
51 
52  fd = open(argv[1], O_RDWR);
53  if (fd < 0) {
54  perror("open");
55  return 1;
56  }
57 
58  if (argc == 2) {
59  if (ioctl(fd, FIOC_GET_SIZE, &size)) {
60  perror("ioctl");
61  ret = 1;
62  goto out;
63  }
64  printf("%zu\n", size);
65  } else {
66  size = strtoul(argv[2], NULL, 0);
67  if (ioctl(fd, FIOC_SET_SIZE, &size)) {
68  perror("ioctl");
69  ret = 1;
70  goto out;
71  }
72  }
73 out:
74  close(fd);
75  return ret;
76 }