"Fossies" - the Fresh Open Source Software Archive

Member "fuse-3.10.4/doc/html/fuse-3_810_83_2example_2ioctl__client_8c_source.html" (9 Jun 2021, 10973 Bytes) of package /linux/misc/fuse-3.10.4.tar.xz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the project site itself.

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 }