/** * Close the associated file * * @throws LastErrorException when operations fails */ @Override public void close() throws LastErrorException { if (fd != -1) { int copy = fd; fd = -1; libc.close(copy); } }
/** * Perform a Linux style ioctl operation on the associated file. * * @param req ioctl operation to be performed * @param info input as integer * @return Linux style ioctl return * @throws LastErrorException when operations fails */ public int ioctl(int req, int info) throws LastErrorException { return libc.ioctl(fd, req, info); }
/** * Open the specified file/device for native access. * * @param fname the name of the file to open * @param flags Linux style file access flags * @param mode Linux style file access mode * @throws LastErrorException when operations fails */ public void open(@NonNull String fname, int flags, int mode) throws LastErrorException { fd = libc.open(fname, flags, mode); }
/** * Attempt to write the requested number of bytes to the associated file. * * @param buf location to store the read bytes * @param offset the offset within buf to take data from for the write * @param len number of bytes to attempt to read * @return number of bytes read * @throws LastErrorException when operations fails */ public int write(@NonNull byte[] buf, int offset, int len) throws LastErrorException { return libc.write(fd, ByteBuffer.wrap(buf, offset, len), len); }
/** * Attempt to read the requested number of byte from the associated file. * * @param buf location to store the read bytes * @param offset offset with buf to start storing the read bytes * @param len number of bytes to attempt to read * @return number of bytes read * @throws LastErrorException when operations fails */ public int read(@NonNull byte[] buf, int offset, int len) throws LastErrorException { return libc.read(fd, ByteBuffer.wrap(buf, offset, len), len); }
/** * Synchronize mapped memory region. * * @param addr Mapped address. * @param len Region length. * @param flags Synchronization flags * @throws LastErrorException when operations fails */ public void msync(@NonNull Pointer addr, long len, int flags) throws LastErrorException { libc.msync(addr, new NativeLong(len), flags); }
/** * Unmap mapped memory region. * * @param addr Mapped address. * @param len Region length. * @throws LastErrorException when operations fails */ public void munmap(@NonNull Pointer addr, long len) throws LastErrorException { libc.munmap(addr, new NativeLong(len)); }
/** * Map a portion of the associated file into memory and return a pointer * that can be used to access that memory. * * @param len size of the region to map * @param prot protection for the memory region * @param flags Linux mmap flags * @param off offset within the file for the start of the region * @return a pointer that can be used to access the mapped data * @throws LastErrorException when operations fails */ public Pointer mmap(long len, int prot, int flags, long off) throws LastErrorException { Pointer p = libc.mmap(new Pointer(0), new NativeLong(len), prot, flags, fd, new NativeLong(off)); if (p.equals(new Pointer(-1))) { throw new LastErrorException("mmap() failed"); } return p; }
/** * Attempt to write the requested number of bytes to the associated file. * * @param buf location to store the read bytes * @param len number of bytes to attempt to read * @return number of bytes read * @throws LastErrorException when operations fails */ public int write(@NonNull byte[] buf, int len) throws LastErrorException { return libc.write(fd, ByteBuffer.wrap(buf), len); }
/** * Attempt to read the requested number of bytes from the associated file. * * @param buf location to store the read bytes * @param len number of bytes to attempt to read * @return number of bytes read * @throws LastErrorException when operations fails */ public int read(@NonNull byte[] buf, int len) throws LastErrorException { return libc.read(fd, ByteBuffer.wrap(buf), len); }
/** * Perform a Linux style ioctl operation on the associated file. * * @param req ioctl operation to be performed * @param buf pointer to ioctl parameters * @return Linux style ioctl return * @throws LastErrorException when operations fails */ public int ioctl(int req, @NonNull Pointer buf) throws LastErrorException { return libc.ioctl(fd, req, buf); }
/** * Open the specified file/device for native access. * * @param fname the name of the file to open * @param flags Linux style file access flags * @throws LastErrorException when operations fails */ public void open(@NonNull String fname, int flags) throws LastErrorException { fd = libc.open(fname, flags, DEFAULT_PRIVS); }
/** * Perform a Linux style ioctl operation on the associated file. * * @param req ioctl operation to be performed * @param info output as integer * @return Linux style ioctl return * @throws LastErrorException when operations fails */ public int ioctl(int req, @NonNull IntByReference info) throws LastErrorException { return libc.ioctl(fd, req, info.getPointer()); }