Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

posix_io.h 1.8KB

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