1
#ifndef _IPXE_POSIX_IO_H
2
#define _IPXE_POSIX_IO_H
10
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13
#include <ipxe/uaccess.h>
15
/** Minimum file descriptor that will ever be allocated */
16
#define POSIX_FD_MIN ( 1 )
18
/** Maximum file descriptor that will ever be allocated */
19
#define POSIX_FD_MAX ( 31 )
21
/** File descriptor set as used for select() */
22
typedef uint32_t fd_set;
24
extern int open ( const char *uri_string );
25
extern ssize_t read_user ( int fd, userptr_t buffer,
26
off_t offset, size_t len );
27
extern int select ( fd_set *readfds, int wait );
28
extern ssize_t fsize ( int fd );
29
extern int close ( int fd );
32
* Zero a file descriptor set
34
* @v set File descriptor set
36
static inline __attribute__ (( always_inline )) void
37
FD_ZERO ( fd_set *set ) {
42
* Set a bit within a file descriptor set
44
* @v fd File descriptor
45
* @v set File descriptor set
47
static inline __attribute__ (( always_inline )) void
48
FD_SET ( int fd, fd_set *set ) {
53
* Clear a bit within a file descriptor set
55
* @v fd File descriptor
56
* @v set File descriptor set
58
static inline __attribute__ (( always_inline )) void
59
FD_CLR ( int fd, fd_set *set ) {
64
* Test a bit within a file descriptor set
66
* @v fd File descriptor
67
* @v set File descriptor set
68
* @ret is_set Corresponding bit is set
70
static inline __attribute__ (( always_inline )) int
71
FD_ISSET ( int fd, fd_set *set ) {
72
return ( *set & ( 1 << fd ) );
78
* @v fd File descriptor
80
* @v len Maximum length to read
81
* @ret len Actual length read, or negative error number
83
static inline ssize_t read ( int fd, void *buf, size_t len ) {
84
return read_user ( fd, virt_to_user ( buf ), 0, len );
87
#endif /* _IPXE_POSIX_IO_H */