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 can be distributed under the terms of the GNU GPLv2.
7 See the file GPL2.txt.
8*/
9
22#include <sys/types.h>
23#include <fcntl.h>
24#include <sys/stat.h>
25#include <sys/ioctl.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <ctype.h>
29#include <errno.h>
30#include <unistd.h>
31#include "ioctl.h"
32
33const char *usage =
34"Usage: fioclient FIOC_FILE [size]\n"
35"\n"
36"Get size if <size> is omitted, set size otherwise\n"
37"\n";
38
39int main(int argc, char **argv)
40{
41 size_t size;
42 int fd;
43 int ret = 0;
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 ret = 1;
60 goto out;
61 }
62 printf("%zu\n", size);
63 } else {
64 size = strtoul(argv[2], NULL, 0);
65 if (ioctl(fd, FIOC_SET_SIZE, &size)) {
66 perror("ioctl");
67 ret = 1;
68 goto out;
69 }
70 }
71out:
72 close(fd);
73 return ret;
74}