diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2008-12-05 10:55:36 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2008-12-05 10:55:36 +0000 |
commit | ecfa5263ab5b19a58d53a7116fb079f3b956b918 (patch) | |
tree | a9f9dd2ec17e9185e4d515328b78e3b5e84938f2 /example/fioclient.c | |
parent | cafdcb253e4c7ad6238198982425c004b487d2e6 (diff) | |
download | libfuse-ecfa5263ab5b19a58d53a7116fb079f3b956b918.tar.gz |
* Implement ioctl support. On high level interface only
"restricted" ioctls are supported (which are defined with the
_IO(), _IOR(), _IOW() or _IOWR() macros). Unrestricted ioctls
will only be allwed to CUSE (Character Device in Userspace)
servers. Patch by Tejun Heo
Diffstat (limited to 'example/fioclient.c')
-rw-r--r-- | example/fioclient.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/example/fioclient.c b/example/fioclient.c new file mode 100644 index 0000000..3ab63b2 --- /dev/null +++ b/example/fioclient.c @@ -0,0 +1,66 @@ +/* + FUSE fioclient: FUSE ioctl example client + Copyright (C) 2008 SUSE Linux Products GmbH + Copyright (C) 2008 Tejun Heo <teheo@suse.de> + + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. + + gcc -Wall fioclient.c -o fioclient +*/ + +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <errno.h> +#include "fioc.h" + +const char *usage = +"Usage: fioclient FIOC_FILE [SIZE]\n" +"\n" +" get size if SIZE is omitted, set size otherwise\n" +"\n"; + +int main(int argc, char **argv) +{ + size_t size; + int fd; + + if (argc < 2) { + goto usage; + } + + fd = open(argv[1], O_RDWR); + if (fd < 0) { + perror("open"); + return 1; + } + + if (argc == 2) { + if (ioctl(fd, FIOC_GET_SIZE, &size)) { + perror("ioctl"); + return 1; + } + printf("%zu\n", size); + } else { + char *endp; + + size = strtoul(argv[2], &endp, 0); + if (endp == argv[2] || *endp != '\0') + goto usage; + + if (ioctl(fd, FIOC_SET_SIZE, &size)) { + perror("ioctl"); + return 1; + } + } + return 0; + +usage: + fprintf(stderr, usage); + return 1; +} |