|
1 | 1 | packageev3dev.utils.io; |
2 | 2 |
|
3 | 3 | importcom.sun.jna.LastErrorException; |
| 4 | +importcom.sun.jna.Native; |
4 | 5 | importcom.sun.jna.NativeLong; |
5 | 6 | importcom.sun.jna.Pointer; |
6 | 7 |
|
|
9 | 10 | /** |
10 | 11 | * POSIX Standard C Library wrapper interface |
11 | 12 | * |
| 13 | + * For detailed reference, please see the |
| 14 | + * <a href="https://man7.org/linux/man-pages/dir_section_2.html">Linux syscall manual pages</a> |
12 | 15 | * @author Jakub Vaněk |
13 | 16 | * @since 2.4.7 |
14 | 17 | */ |
15 | 18 | publicinterfaceILibc { |
16 | 19 | // file descriptor operations |
| 20 | + |
| 21 | +/** |
| 22 | + * Manipulate file descriptor |
| 23 | + * @param fd File descriptor to operate upon. |
| 24 | + * @param cmd Command code, see manpages for details. |
| 25 | + * @param arg Command argument, command-speciic. See manpages for details. |
| 26 | + * @return Depends on the command. On failure, -1 is returned. |
| 27 | + * @see <a href="https://man7.org/linux/man-pages/man2/fcntl.2.html">man 2 fcntl</a> |
| 28 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 29 | + */ |
17 | 30 | intfcntl(intfd,intcmd,intarg)throwsLastErrorException; |
18 | 31 |
|
19 | 32 | // ioctls |
| 33 | + |
| 34 | +/** |
| 35 | + * Invoke an I/O control request |
| 36 | + * @param fd Opened file descriptor to act upon. |
| 37 | + * @param cmd IO command code; this is device-specific (see manpages and/or kernel sources for details). |
| 38 | + * @param arg IOCTL integer argument, this is device-specific (see manpages and/or kernel sources for details). |
| 39 | + * @return -1 on failure, 0 otherwise (usually). |
| 40 | + * @see <a href="https://man7.org/linux/man-pages/man2/ioctl.2.html">man 2 ioctl</a> |
| 41 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 42 | + */ |
20 | 43 | intioctl(intfd,intcmd,intarg)throwsLastErrorException; |
21 | 44 |
|
| 45 | +/** |
| 46 | + * Invoke an I/O control request |
| 47 | + * @param fd Opened file descriptor to act upon. |
| 48 | + * @param cmd IO command code; this is device-specific (see manpages and/or kernel sources for details). |
| 49 | + * @param arg IOCTL integer argument, this is device-specific (see manpages and/or kernel sources for details). |
| 50 | + * @return -1 on failure, 0 otherwise (usually). |
| 51 | + * @see <a href="https://man7.org/linux/man-pages/man2/ioctl.2.html">man 2 ioctl</a> |
| 52 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 53 | + */ |
22 | 54 | intioctl(intfd,intcmd,Pointerarg)throwsLastErrorException; |
23 | 55 |
|
24 | 56 | // open/close |
25 | 57 |
|
| 58 | +/** |
| 59 | + * Try to open (or create) a file from the specified path. |
| 60 | + * @param path Path to try to open. |
| 61 | + * @param flags Open mode; typically O_RDONLY/O_WRONLY/O_RDWR combined with other modifiers (see POSIX). |
| 62 | + * @param mode Permissions to be set on the file if it is going to be created (O_CREAT). |
| 63 | + * @return File descriptor or -1 if the file cannot be opened. |
| 64 | + * @see <a href="https://man7.org/linux/man-pages/man2/open.2.html">man 2 open</a> |
| 65 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 66 | + */ |
26 | 67 | intopen(Stringpath,intflags,intmode)throwsLastErrorException; |
27 | 68 |
|
| 69 | +/** |
| 70 | + * Close the specified file descriptor. |
| 71 | + * @param fd File descriptor to close. |
| 72 | + * @return -1 on failure, 0 otherwise. |
| 73 | + * @see <a href="https://man7.org/linux/man-pages/man2/close.2.html">man 2 close</a> |
| 74 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 75 | + */ |
28 | 76 | intclose(intfd)throwsLastErrorException; |
29 | 77 |
|
30 | 78 | // read/write |
| 79 | + |
| 80 | +/** |
| 81 | + * Request a write to the current position in the file referred by a file descriptor. |
| 82 | + * @param fd File descriptor of the file to write. |
| 83 | + * @param buffer Buffer with bytes to write. |
| 84 | + * @param count Size of the buffer. |
| 85 | + * @return Number of bytes written or -1 if an error occurred. |
| 86 | + * @see <a href="https://man7.org/linux/man-pages/man2/write.2.html">man 2 write</a> |
| 87 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 88 | + */ |
31 | 89 | intwrite(intfd,Bufferbuffer,intcount)throwsLastErrorException; |
32 | 90 |
|
| 91 | +/** |
| 92 | + * Request a read from the current position in the file referred by a file descriptor. |
| 93 | + * @param fd File descriptor of the file to read. |
| 94 | + * @param buffer Buffer where to put the data. |
| 95 | + * @param count Size of the buffer. |
| 96 | + * @return Number of bytes read or -1 if an error occurred. |
| 97 | + * @see <a href="https://man7.org/linux/man-pages/man2/read.2.html">man 2 read</a> |
| 98 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 99 | + */ |
33 | 100 | intread(intfd,Bufferbuffer,intcount)throwsLastErrorException; |
34 | 101 |
|
35 | 102 | // read/write with offset |
| 103 | + |
| 104 | +/** |
| 105 | + * Request a read from the specified absolute position in the file referred by a file descriptor. |
| 106 | + * @param fd File descriptor of the file to read. |
| 107 | + * @param buffer Buffer where to put the data. |
| 108 | + * @param count Size of the buffer. |
| 109 | + * @param offset File offset where the data should be read from. |
| 110 | + * @return Number of bytes read or -1 if an error occurred. |
| 111 | + * @see <a href="https://man7.org/linux/man-pages/man2/pread.2.html">man 2 pread</a> |
| 112 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 113 | + */ |
36 | 114 | intpread(intfd,Bufferbuffer,intcount,intoffset)throwsLastErrorException; |
37 | 115 |
|
| 116 | +/** |
| 117 | + * Request a write to the specified absolute position in the file referred by a file descriptor. |
| 118 | + * @param fd File descriptor of the file to write. |
| 119 | + * @param buffer Buffer with bytes to write. |
| 120 | + * @param count Size of the buffer. |
| 121 | + * @param offset File offset where the data should be written to. |
| 122 | + * @return Number of bytes written or -1 if an error occurred. |
| 123 | + * @see <a href="https://man7.org/linux/man-pages/man2/pwrite.2.html">man 2 pwrite</a> |
| 124 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 125 | + */ |
38 | 126 | intpwrite(intfd,Bufferbuffer,intcount,intoffset)throwsLastErrorException; |
39 | 127 |
|
40 | 128 | // map/unmap |
| 129 | + |
| 130 | +/** |
| 131 | + * Map a file to memory. |
| 132 | + * @param addr Address hint from the userspace where to put the mapping in memory. Pass NULL to ignore the hint. |
| 133 | + * @param len Length of the memory to map. |
| 134 | + * @param prot Memory protection flags (PROT_READ/PROT_WRITE/PROT_EXEC). See manpages for details. |
| 135 | + * @param flags Memory mapping flags (MAP_SHARED/MAP_FILE/...). See manpages for deatils. |
| 136 | + * @param fd Opened file descriptor of the file that needs to be mapped to memory. |
| 137 | + * @param off Offset in the file from which to start the mapping. |
| 138 | + * @return On success, address of the mapped memory. On failure, -1 (MAP_FAILED) is returned. |
| 139 | + * @see <a href="https://man7.org/linux/man-pages/man2/mmap.2.html">man 2 mmap</a> |
| 140 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 141 | + */ |
41 | 142 | Pointermmap(Pointeraddr,NativeLonglen,intprot,intflags,intfd,NativeLongoff)throwsLastErrorException; |
42 | 143 |
|
| 144 | +/** |
| 145 | + * Unmap a file from memory. |
| 146 | + * @param addr Address where the file was mapped. |
| 147 | + * @param len Length of the mapped area. |
| 148 | + * @return -1 on failure, 0 otherwise. |
| 149 | + * @see <a href="https://man7.org/linux/man-pages/man2/munmap.2.html">man 2 munmap</a> |
| 150 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 151 | + */ |
43 | 152 | intmunmap(Pointeraddr,NativeLonglen)throwsLastErrorException; |
44 | 153 |
|
| 154 | +/** |
| 155 | + * Synchronize memory-mapped data with file contents. |
| 156 | + * @param addr Address where the file was mapped. |
| 157 | + * @param len Length of the mapped area. |
| 158 | + * @param flags Synchronization type (MS_SYNC/MS_ASYNC/MS_INVALIDATE). See manpages for details. |
| 159 | + * @return -1 on failure, 0 otherwise. |
| 160 | + * @see <a href="https://man7.org/linux/man-pages/man2/msync.2.html">man 2 msync</a> |
| 161 | + * @throws LastErrorException If errno is set during the operation. Use {@link Native#getLastError()} to query the error code. |
| 162 | + */ |
45 | 163 | intmsync(Pointeraddr,NativeLonglen,intflags)throwsLastErrorException; |
46 | 164 | } |