@Override protected void fallocateFD(int fd, long offset, long len) throws LastErrorException { int errno = posix_fallocate64(fd, offset, len); if (errno != 0) { throw new LastErrorException(errno); } } }
@Override protected void fallocateFD(int fd, long offset, long len) throws LastErrorException { int errno = posix_fallocate64(fd, offset, len); if (errno != 0) { throw new LastErrorException(errno); } } }
/** * Read bytes from the framebuffer [INVALID OPERATION]. * * @param fd Not used. * @param buffer Not used. * @param count Not used. * @return Nothing. * @throws LastErrorException EIO always. */ @Override public int read(int fd, Buffer buffer, int count) throws LastErrorException { throw new LastErrorException(NativeConstants.EIO); }
/** * Invoke i/o control action with integer argument [UNUSED OPERATION]. * * @param fd Not used. * @param cmd Not used. * @param arg Not used. * @return Nothing. * @throws LastErrorException EINVAL always. */ @Override public int ioctl(int fd, int cmd, int arg) throws LastErrorException { throw new LastErrorException(NativeConstants.EINVAL); }
/** * Write bytes to the framebuffer [INVALID OPERATION]. * * @param fd Not used. * @param buffer Not used. * @param count Not used. * @return Nothing. * @throws LastErrorException EIO always. */ @Override public int write(int fd, Buffer buffer, int count) throws LastErrorException { throw new LastErrorException(NativeConstants.EIO); }
/** * Get path for selected file descriptor. * * @param fd Queried file descriptor. * @return Path from where this file descriptor was opened. * @throws LastErrorException EBADF when the file descriptor was not found. */ private String path(int fd) { return Optional .ofNullable(opened.get(fd)) .orElseThrow(() -> new LastErrorException(NativeConstants.EBADF)); }
/** * Get path for selected memory-mapped pointer. * * @param mem Queried pointer. * @return Path from where this pointer was mapped. * @throws LastErrorException EINVAL when the pointer was not found. */ private String path(@NonNull Pointer mem) { return Optional .ofNullable(mmaps.get(mem)) .orElseThrow(() -> new LastErrorException(NativeConstants.EINVAL)); }
/** * Get backend implementation for the following file. * * @param path Queried file path. * @return Implementation of the file. * @throws LastErrorException ENOENT when the file isn't known. */ private IFile impl(@NonNull String path) { return Optional .ofNullable(mapping.get(path)) .orElseThrow(() -> new LastErrorException(NativeConstants.ENOENT)); }
/** * Process variable info set request. * * @param info Structure from the application. * @throws LastErrorException EINVAL if the configured parameters do not meet the initial ones. */ private void takeVarInfo(fb_var_screeninfo info) throws LastErrorException { if (!info.dataEquals(varinfo)) { throw new LastErrorException(NativeConstants.EINVAL); } }
/** * Uses the {@link Kernel32#GetEnvironmentStrings()} to retrieve and * parse the current process environment * @return The current process environment as a {@link Map}. * @throws LastErrorException if failed to get or free the environment * data block * @see #getEnvironmentVariables(Pointer, long) */ public static Map<String,String> getEnvironmentVariables() { Pointer lpszEnvironmentBlock=Kernel32.INSTANCE.GetEnvironmentStrings(); if (lpszEnvironmentBlock == null) { throw new LastErrorException(Kernel32.INSTANCE.GetLastError()); } try { return getEnvironmentVariables(lpszEnvironmentBlock, 0L); } finally { if (!Kernel32.INSTANCE.FreeEnvironmentStrings(lpszEnvironmentBlock)) { throw new LastErrorException(Kernel32.INSTANCE.GetLastError()); } } }
/** * Format a message from an HRESULT. * @param code * HRESULT * @return * Formatted message. */ public static String formatMessageFromHR(HRESULT code) { PointerByReference buffer = new PointerByReference(); if (0 == Kernel32.INSTANCE.FormatMessage( WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER | WinBase.FORMAT_MESSAGE_FROM_SYSTEM | WinBase.FORMAT_MESSAGE_IGNORE_INSERTS, null, code.intValue(), 0, // TODO: MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) buffer, 0, null)) { throw new LastErrorException(Kernel32.INSTANCE.GetLastError()); } String s = buffer.getValue().getString(0, ! Boolean.getBoolean("w32.ascii")); Kernel32.INSTANCE.LocalFree(buffer.getValue()); return s.trim(); }
/** * Format a message from the value obtained from * {@link Kernel32#GetLastError()} or {@link Native#getLastError()}. * * @param code The error code * @return Formatted message. */ public static String formatMessage(int code) { PointerByReference buffer = new PointerByReference(); int nLen = Kernel32.INSTANCE.FormatMessage( WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER | WinBase.FORMAT_MESSAGE_FROM_SYSTEM | WinBase.FORMAT_MESSAGE_IGNORE_INSERTS, null, code, 0, // TODO: // MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT) buffer, 0, null); if (nLen == 0) { throw new LastErrorException(Native.getLastError()); } Pointer ptr = buffer.getValue(); try { String s = ptr.getWideString(0); return s.trim(); } finally { freeLocalMemory(ptr); } }
/** * 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; }
map = new fb_con2fbmap(arg); if (!con2fb.containsKey(map.console)) { throw new LastErrorException(NativeConstants.EINVAL); break; default: throw new LastErrorException(NativeConstants.EINVAL);