iPXE
|
POSIX-like I/O. More...
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/list.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/process.h>
#include <ipxe/posix_io.h>
Go to the source code of this file.
Data Structures | |
struct | posix_file |
An open file. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static | LIST_HEAD (posix_files) |
List of open files. More... | |
static void | posix_file_free (struct refcnt *refcnt) |
Free open file. More... | |
static void | posix_file_finished (struct posix_file *file, int rc) |
Terminate file data transfer. More... | |
static int | posix_file_xfer_deliver (struct posix_file *file, struct io_buffer *iobuf, struct xfer_metadata *meta) |
Handle deliver_iob() event. More... | |
static struct posix_file * | posix_fd_to_file (int fd) |
Identify file by file descriptor. More... | |
static int | posix_find_free_fd (void) |
Find an available file descriptor. More... | |
int | open (const char *uri_string) |
Open file. More... | |
int | select (fd_set *readfds, int wait) |
Check file descriptors for readiness. More... | |
ssize_t | read_user (int fd, userptr_t buffer, off_t offset, size_t max_len) |
Read data from file. More... | |
ssize_t | fsize (int fd) |
Determine file size. More... | |
int | close (int fd) |
Close file. More... | |
Variables | |
static struct interface_operation | posix_file_xfer_operations [] |
POSIX file data transfer interface operations. More... | |
static struct interface_descriptor | posix_file_xfer_desc |
POSIX file data transfer interface descriptor. More... | |
POSIX-like I/O.
These functions provide traditional blocking I/O semantics. They are designed to be used by the PXE TFTP API. Because they block, they may not be used by most other portions of the iPXE codebase.
Definition in file posix_io.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
List of open files.
|
static |
Free open file.
refcnt | Reference counter |
Definition at line 76 of file posix_io.c.
References container_of, posix_file::data, free, free_iob(), io_buffer::list, list_del, list_for_each_entry_safe, and tmp.
Referenced by open().
|
static |
Terminate file data transfer.
file | POSIX file |
rc | Reason for termination |
Definition at line 95 of file posix_io.c.
References intf_shutdown(), posix_file::rc, rc, and posix_file::xfer.
|
static |
Handle deliver_iob() event.
file | POSIX file |
iobuf | I/O buffer |
meta | Data transfer metadata |
rc | Return status code |
Definition at line 108 of file posix_io.c.
References posix_file::data, posix_file::filesize, free_iob(), iob_len(), io_buffer::list, list_add_tail, meta(), posix_file::pos, and XFER_FL_ABS_OFFSET.
|
static |
Identify file by file descriptor.
fd | File descriptor |
file | Corresponding file, or NULL |
Definition at line 144 of file posix_io.c.
References posix_file::fd, posix_file::list, list_for_each_entry, and NULL.
Referenced by close(), fsize(), posix_find_free_fd(), read_user(), and select().
|
static |
Find an available file descriptor.
fd | File descriptor, or negative error number |
Definition at line 159 of file posix_io.c.
References DBG, ENFILE, posix_file::fd, POSIX_FD_MAX, POSIX_FD_MIN, and posix_fd_to_file().
Referenced by open().
int open | ( | const char * | uri_string | ) |
Open file.
uri_string | URI string |
fd | File descriptor, or negative error number |
Definition at line 176 of file posix_io.c.
References posix_file::data, DBG, EINPROGRESS, ENOMEM, posix_file::fd, INIT_LIST_HEAD, intf_init(), posix_file::list, list_add, list_empty, posix_file_finished(), posix_file_free(), posix_file_xfer_desc, posix_find_free_fd(), posix_file::rc, rc, ref_init, ref_put, posix_file::refcnt, step(), posix_file::xfer, xfer_open_uri_string(), and zalloc().
Referenced by int22(), peerdist_discovery_reply_values(), pxenv_file_open(), vmbus_open(), and xve_update_state().
int select | ( | fd_set * | readfds, |
int | wait | ||
) |
Check file descriptors for readiness.
readfds | File descriptors to check |
wait | Wait until data is ready |
nready | Number of ready file descriptors |
Definition at line 229 of file posix_io.c.
References posix_file::data, EBADF, EINPROGRESS, posix_file::fd, list_empty, POSIX_FD_MAX, POSIX_FD_MIN, posix_fd_to_file(), posix_file::rc, and step().
Referenced by int22(), pxenv_file_select(), and show_menu().
Read data from file.
buffer | Data buffer |
offset | Starting offset within data buffer |
len | Maximum length to read |
len | Actual length read, or negative error number |
This call is non-blocking; if no data is available to read then -EWOULDBLOCK will be returned.
Definition at line 265 of file posix_io.c.
References assert(), buffer, copy_to_user(), io_buffer::data, posix_file::data, EBADF, EINPROGRESS, EWOULDBLOCK, free_iob(), iob_len(), iob_pull, len, io_buffer::list, list_del, list_empty, list_for_each_entry, offset, posix_file::pos, posix_fd_to_file(), posix_file::rc, and step().
Referenced by int22(), pxenv_file_read(), and read().
ssize_t fsize | ( | int | fd | ) |
Determine file size.
fd | File descriptor |
size | File size, or negative error number |
Definition at line 311 of file posix_io.c.
References EBADF, posix_file::fd, posix_file::filesize, and posix_fd_to_file().
Referenced by int22(), and pxenv_get_file_size().
int close | ( | int | fd | ) |
Close file.
fd | File descriptor |
rc | Return status code |
Definition at line 328 of file posix_io.c.
References EBADF, posix_file::fd, posix_file::list, list_del, posix_fd_to_file(), posix_file_finished(), ref_put, and posix_file::refcnt.
|
static |
POSIX file data transfer interface operations.
Definition at line 129 of file posix_io.c.
|
static |
POSIX file data transfer interface descriptor.
Definition at line 135 of file posix_io.c.
Referenced by open().