Whamcloud - gitweb
LU-17000 coverity: llverfs: Add check for -n option
[fs/lustre-release.git] / lustre / doc / llapi_ioctl.3
1 .TH lustreapi 3 "2023 Mar 22" Lustre user application interface library
2 .SH NAME
3 llapi_ioctl \- call ioctl() with possible command remapping
4 .SH SYNOPSIS
5 .nf
6 .B #include <lustre/lustreapi.h>
7 .sp
8 .BI "int llapi_ioctl(int " fd ", unsigned int " cmd ", void *" buf ");"
9 .SH DESCRIPTION
10 .LP
11 .B llapi_ioctl()
12 calls the
13 .BR ioctl (2)
14 system call with the supplied arguments.  However, if the ioctl() returns
15 .B ENOTTY
16 (no such ioctl) then if
17 .I cmd
18 has been remapped from an older ioctl command number the ioctl() call will
19 be retried with the old ioctl command number.
20 .SH RETURN VALUES
21 .LP
22 .B llapi_ioctl()
23 typically returns:
24 .TP
25 0
26 on success in most cases
27 .TP
28 <0
29 a negative value on failure and sets
30 .BR errno .
31 Due to the variety of ioctl commands, it may return different values
32 and errno as appropriate for the
33 .IR fd ,
34 .I cmd
35 number, and argument
36 .I buf
37 passed.
38 .SH "EXAMPLE"
39 .nf
40 #include <lustre/lustreapi.h>
41
42 int main(int argc, char *argv[])
43 {
44         unsigned long group = 1234;
45         int rc, fd;
46
47         fd = open(argv[1], O_RDONLY);
48         if (rc < 0) {
49                 fprintf(stderr, "error opening file '%s': %s\\n",
50                         argv[1], strerror(errno));
51                 return -1;
52         }
53
54         rc = llapi_ioctl(fd, LL_IOC_GROUP_LOCK, &group);
55         if (rc < 0) {
56                 fprintf(stderr, "%s: ioctl error: %s\\n",
57                         argv[1], strerror(errno));
58                 return rc;
59         }
60
61         printf("%s: locked with group %lu\\n", argv[1], group);
62         return 0;
63 }
64 .fi
65 .SH "SEE ALSO"
66 .BR lustre (7),
67 .BR ioctl (2),
68 .BR lustreapi (7)
69