File: ioctl_client.c

package info (click to toggle)
fuse3 3.17.2-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 37,592 kB
  • sloc: ansic: 22,937; perl: 6,044; cpp: 3,853; python: 1,128; sh: 408; javascript: 313; makefile: 59
file content (76 lines) | stat: -rw-r--r-- 1,348 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
  FUSE fioclient: FUSE ioctl example client
  Copyright (C) 2008       SUSE Linux Products GmbH
  Copyright (C) 2008       Tejun Heo <teheo@suse.de>

  This program tests the ioctl.c example file systsem.

  This program can be distributed under the terms of the GNU GPLv2.
  See the file COPYING.
*/

/** @file
 *
 * This program tests the ioctl.c example file systsem.
 *
 * Compile with:
 *
 *     gcc -Wall ioctl_client.c -o ioctl_client
 *
 * ## Source code ##
 * \include ioctl_client.c
 */

#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include "ioctl.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;
	int ret = 0;

	if (argc < 2) {
		fprintf(stderr, "%s", usage);
		return 1;
	}

	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");
			ret = 1;
			goto out;
		}
		printf("%zu\n", size);
	} else {
		size = strtoul(argv[2], NULL, 0);
		if (ioctl(fd, FIOC_SET_SIZE, &size)) {
			perror("ioctl");
			ret = 1;
			goto out;
		}
	}
out:
	close(fd);
	return ret;
}