You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

posix_io.h 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef _GPXE_POSIX_IO_H
  2. #define _GPXE_POSIX_IO_H
  3. /** @file
  4. *
  5. * POSIX-like I/O
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/uaccess.h>
  10. /** Minimum file descriptor that will ever be allocated */
  11. #define POSIX_FD_MIN ( 1 )
  12. /** Maximum file descriptor that will ever be allocated */
  13. #define POSIX_FD_MAX ( 31 )
  14. /** File descriptor set as used for select() */
  15. typedef uint32_t fd_set;
  16. extern int open ( const char *uri_string );
  17. extern ssize_t read_user ( int fd, userptr_t buffer,
  18. off_t offset, size_t len );
  19. extern int select ( fd_set *readfds, int wait );
  20. extern ssize_t fsize ( int fd );
  21. extern int close ( int fd );
  22. /**
  23. * Zero a file descriptor set
  24. *
  25. * @v set File descriptor set
  26. */
  27. static inline __attribute__ (( always_inline )) void
  28. FD_ZERO ( fd_set *set ) {
  29. *set = 0;
  30. }
  31. /**
  32. * Set a bit within a file descriptor set
  33. *
  34. * @v fd File descriptor
  35. * @v set File descriptor set
  36. */
  37. static inline __attribute__ (( always_inline )) void
  38. FD_SET ( int fd, fd_set *set ) {
  39. *set |= ( 1 << fd );
  40. }
  41. /**
  42. * Clear a bit within a file descriptor set
  43. *
  44. * @v fd File descriptor
  45. * @v set File descriptor set
  46. */
  47. static inline __attribute__ (( always_inline )) void
  48. FD_CLR ( int fd, fd_set *set ) {
  49. *set &= ~( 1 << fd );
  50. }
  51. /**
  52. * Test a bit within a file descriptor set
  53. *
  54. * @v fd File descriptor
  55. * @v set File descriptor set
  56. * @ret is_set Corresponding bit is set
  57. */
  58. static inline __attribute__ (( always_inline )) int
  59. FD_ISSET ( int fd, fd_set *set ) {
  60. return ( *set & ( 1 << fd ) );
  61. }
  62. /**
  63. * Read data from file
  64. *
  65. * @v fd File descriptor
  66. * @v buf Data buffer
  67. * @v len Maximum length to read
  68. * @ret len Actual length read, or negative error number
  69. */
  70. static inline ssize_t read ( int fd, void *buf, size_t len ) {
  71. return read_user ( fd, virt_to_user ( buf ), 0, len );
  72. }
  73. #endif /* _GPXE_POSIX_IO_H */