iPXE
pxe_file.c File Reference

PXE FILE API. More...

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/posix_io.h>
#include <ipxe/features.h>
#include <pxe.h>
#include <realmode.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FEATURE (FEATURE_MISC, "PXEXT", DHCP_EB_FEATURE_PXE_EXT, 2)
static PXENV_EXIT_t pxenv_file_open (struct s_PXENV_FILE_OPEN *file_open)
 FILE OPEN.
static PXENV_EXIT_t pxenv_file_close (struct s_PXENV_FILE_CLOSE *file_close)
 FILE CLOSE.
static PXENV_EXIT_t pxenv_file_select (struct s_PXENV_FILE_SELECT *file_select)
 FILE SELECT.
static PXENV_EXIT_t pxenv_file_read (struct s_PXENV_FILE_READ *file_read)
 FILE READ.
static PXENV_EXIT_t pxenv_get_file_size (struct s_PXENV_GET_FILE_SIZE *get_file_size)
 GET FILE SIZE.
static PXENV_EXIT_t pxenv_file_exec (struct s_PXENV_FILE_EXEC *file_exec)
 FILE EXEC.
static PXENV_EXIT_t pxenv_file_cmdline (struct s_PXENV_FILE_CMDLINE *file_cmdline)
 FILE CMDLINE.
static PXENV_EXIT_t pxenv_file_api_check (struct s_PXENV_FILE_API_CHECK *file_api_check)
 FILE API CHECK.

Variables

struct pxe_api_call pxe_file_api[] __pxe_api_call
 PXE file API.

Detailed Description

PXE FILE API.

Definition in file pxe_file.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FEATURE()

FEATURE ( FEATURE_MISC ,
"PXEXT" ,
DHCP_EB_FEATURE_PXE_EXT ,
2  )

◆ pxenv_file_open()

PXENV_EXIT_t pxenv_file_open ( struct s_PXENV_FILE_OPEN * file_open)
static

FILE OPEN.

Parameters
file_openPointer to a struct s_PXENV_FILE_OPEN
s_PXENV_FILE_OPEN::FileNameURL of file to open
Return values
PXENV_EXIT_SUCCESSFile was opened
PXENV_EXIT_FAILUREFile was not opened
s_PXENV_FILE_OPEN::StatusPXE status code
s_PXENV_FILE_OPEN::FileHandleHandle of opened file

Definition at line 54 of file pxe_file.c.

54 {
55 const char *filename;
56 int fd;
57
58 DBG ( "PXENV_FILE_OPEN" );
59
60 /* Open specified filename */
61 filename = real_to_virt ( file_open->FileName.segment,
62 file_open->FileName.offset );
63 DBG ( " %s", filename );
64 fd = open ( filename );
65 if ( fd < 0 ) {
66 file_open->Status = PXENV_STATUS ( fd );
67 return PXENV_EXIT_FAILURE;
68 }
69 DBG ( " as file %d", fd );
70
71 file_open->FileHandle = fd;
72 file_open->Status = PXENV_STATUS_SUCCESS;
73 return PXENV_EXIT_SUCCESS;
74}
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define PXENV_EXIT_FAILURE
An error occurred.
Definition pxe_types.h:46
#define PXENV_EXIT_SUCCESS
No error occurred.
Definition pxe_types.h:45
#define PXENV_STATUS_SUCCESS
Definition pxe_error.h:19
int open(const char *uri_string)
Open file.
Definition posix_io.c:176
#define PXENV_STATUS(rc)
Derive PXENV_STATUS code from iPXE error number.
Definition pxe_error.h:121
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition realmode.h:77
SEGOFF16_t FileName
File URL.
Definition pxe_api.h:1539
UINT16_t FileHandle
File handle.
Definition pxe_api.h:1538
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1537

References DBG, s_PXENV_FILE_OPEN::FileHandle, s_PXENV_FILE_OPEN::FileName, open(), PXENV_EXIT_FAILURE, PXENV_EXIT_SUCCESS, PXENV_STATUS, PXENV_STATUS_SUCCESS, real_to_virt(), and s_PXENV_FILE_OPEN::Status.

◆ pxenv_file_close()

PXENV_EXIT_t pxenv_file_close ( struct s_PXENV_FILE_CLOSE * file_close)
static

FILE CLOSE.

Parameters
file_closePointer to a struct s_PXENV_FILE_CLOSE
s_PXENV_FILE_CLOSE::FileHandleFile handle
Return values
PXENV_EXIT_SUCCESSFile was closed
PXENV_EXIT_FAILUREFile was not closed
s_PXENV_FILE_CLOSE::StatusPXE status code

Definition at line 86 of file pxe_file.c.

86 {
87
88 DBG ( "PXENV_FILE_CLOSE %d", file_close->FileHandle );
89
90 close ( file_close->FileHandle );
91 file_close->Status = PXENV_STATUS_SUCCESS;
92 return PXENV_EXIT_SUCCESS;
93}
UINT16_t FileHandle
File handle.
Definition pxe_api.h:1560
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1559
static struct evtchn_close * close
Definition xenevent.h:24

References close, DBG, s_PXENV_FILE_CLOSE::FileHandle, PXENV_EXIT_SUCCESS, PXENV_STATUS_SUCCESS, and s_PXENV_FILE_CLOSE::Status.

◆ pxenv_file_select()

PXENV_EXIT_t pxenv_file_select ( struct s_PXENV_FILE_SELECT * file_select)
static

FILE SELECT.

Parameters
file_selectPointer to a struct s_PXENV_FILE_SELECT
s_PXENV_FILE_SELECT::FileHandleFile handle
Return values
PXENV_EXIT_SUCCESSFile has been checked for readiness
PXENV_EXIT_FAILUREFile has not been checked for readiness
s_PXENV_FILE_SELECT::StatusPXE status code
s_PXENV_FILE_SELECT::ReadyIndication of readiness

Definition at line 107 of file pxe_file.c.

107 {
108 fd_set fdset;
109 int ready;
110
111 DBG ( "PXENV_FILE_SELECT %d", file_select->FileHandle );
112
113 FD_ZERO ( &fdset );
114 FD_SET ( file_select->FileHandle, &fdset );
115 if ( ( ready = select ( &fdset, 0 ) ) < 0 ) {
116 file_select->Status = PXENV_STATUS ( ready );
117 return PXENV_EXIT_FAILURE;
118 }
119
120 file_select->Ready = ( ready ? RDY_READ : 0 );
121 file_select->Status = PXENV_STATUS_SUCCESS;
122 return PXENV_EXIT_SUCCESS;
123}
#define RDY_READ
File is ready for reading.
Definition pxe_api.h:1578
int select(fd_set *readfds, int wait)
Check file descriptors for readiness.
Definition posix_io.c:229
uint32_t fd_set
File descriptor set as used for select()
Definition posix_io.h:21
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1582
UINT16_t Ready
Indication of readiness.
Definition pxe_api.h:1584
UINT16_t FileHandle
File handle.
Definition pxe_api.h:1583

References DBG, s_PXENV_FILE_SELECT::FileHandle, PXENV_EXIT_FAILURE, PXENV_EXIT_SUCCESS, PXENV_STATUS, PXENV_STATUS_SUCCESS, RDY_READ, s_PXENV_FILE_SELECT::Ready, select(), and s_PXENV_FILE_SELECT::Status.

◆ pxenv_file_read()

PXENV_EXIT_t pxenv_file_read ( struct s_PXENV_FILE_READ * file_read)
static

FILE READ.

Parameters
file_readPointer to a struct s_PXENV_FILE_READ
s_PXENV_FILE_READ::FileHandleFile handle
s_PXENV_FILE_READ::BufferSizeSize of data buffer
s_PXENV_FILE_READ::BufferData buffer
Return values
PXENV_EXIT_SUCCESSData has been read from file
PXENV_EXIT_FAILUREData has not been read from file
s_PXENV_FILE_READ::StatusPXE status code
s_PXENV_FILE_READ::ReadyIndication of readiness
s_PXENV_FILE_READ::BufferSizeLength of data read

Definition at line 139 of file pxe_file.c.

139 {
140 void *buffer;
141 ssize_t len;
142
143 DBG ( "PXENV_FILE_READ %d to %04x:%04x+%04x", file_read->FileHandle,
144 file_read->Buffer.segment, file_read->Buffer.offset,
145 file_read->BufferSize );
146
147 buffer = real_to_virt ( file_read->Buffer.segment,
148 file_read->Buffer.offset );
149 if ( ( len = read ( file_read->FileHandle, buffer,
150 file_read->BufferSize ) ) < 0 ) {
151 file_read->Status = PXENV_STATUS ( len );
152 return PXENV_EXIT_FAILURE;
153 }
154
155 DBG ( " read %04zx", ( ( size_t ) len ) );
156
157 file_read->BufferSize = len;
158 file_read->Status = PXENV_STATUS_SUCCESS;
159 return PXENV_EXIT_SUCCESS;
160}
signed long ssize_t
Definition stdint.h:7
ring len
Length.
Definition dwmac.h:226
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
struct option_descriptor read[1]
Definition nvo_cmd.c:116
UINT16_t BufferSize
Data buffer size.
Definition pxe_api.h:1605
SEGOFF16_t Buffer
Data buffer.
Definition pxe_api.h:1606
UINT16_t FileHandle
File handle.
Definition pxe_api.h:1604
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1603

References s_PXENV_FILE_READ::Buffer, buffer, s_PXENV_FILE_READ::BufferSize, DBG, s_PXENV_FILE_READ::FileHandle, len, PXENV_EXIT_FAILURE, PXENV_EXIT_SUCCESS, PXENV_STATUS, PXENV_STATUS_SUCCESS, read, real_to_virt(), and s_PXENV_FILE_READ::Status.

◆ pxenv_get_file_size()

PXENV_EXIT_t pxenv_get_file_size ( struct s_PXENV_GET_FILE_SIZE * get_file_size)
static

GET FILE SIZE.

Parameters
get_file_sizePointer to a struct s_PXENV_GET_FILE_SIZE
s_PXENV_GET_FILE_SIZE::FileHandleFile handle
Return values
PXENV_EXIT_SUCCESSFile size has been determined
PXENV_EXIT_FAILUREFile size has not been determined
s_PXENV_GET_FILE_SIZE::StatusPXE status code
s_PXENV_GET_FILE_SIZE::FileSizeSize of file

Definition at line 173 of file pxe_file.c.

173 {
174 ssize_t filesize;
175
176 DBG ( "PXENV_GET_FILE_SIZE %d", get_file_size->FileHandle );
177
178 filesize = fsize ( get_file_size->FileHandle );
179 if ( filesize < 0 ) {
180 get_file_size->Status = PXENV_STATUS ( filesize );
181 return PXENV_EXIT_FAILURE;
182 }
183
184 DBG ( " is %zd", ( ( size_t ) filesize ) );
185
186 get_file_size->FileSize = filesize;
187 get_file_size->Status = PXENV_STATUS_SUCCESS;
188 return PXENV_EXIT_SUCCESS;
189}
ssize_t fsize(int fd)
Determine file size.
Definition posix_io.c:310
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1625
UINT16_t FileHandle
File handle.
Definition pxe_api.h:1626
UINT32_t FileSize
File size.
Definition pxe_api.h:1627

References DBG, s_PXENV_GET_FILE_SIZE::FileHandle, s_PXENV_GET_FILE_SIZE::FileSize, fsize(), PXENV_EXIT_FAILURE, PXENV_EXIT_SUCCESS, PXENV_STATUS, PXENV_STATUS_SUCCESS, and s_PXENV_GET_FILE_SIZE::Status.

◆ pxenv_file_exec()

PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC * file_exec)
static

FILE EXEC.

Parameters
file_execPointer to a struct s_PXENV_FILE_EXEC
s_PXENV_FILE_EXEC::CommandCommand to execute
Return values
PXENV_EXIT_SUCCESSCommand was executed successfully
PXENV_EXIT_FAILURECommand was not executed successfully
s_PXENV_FILE_EXEC::StatusPXE status code

Definition at line 201 of file pxe_file.c.

201 {
202 const char *command;
203 int rc;
204
205 DBG ( "PXENV_FILE_EXEC" );
206
207 /* Execute specified command */
208 command = real_to_virt ( file_exec->Command.segment,
209 file_exec->Command.offset );
210 DBG ( " %s", command );
211 if ( ( rc = system ( command ) ) != 0 ) {
212 file_exec->Status = PXENV_STATUS ( rc );
213 return PXENV_EXIT_FAILURE;
214 }
215
216 file_exec->Status = PXENV_STATUS_SUCCESS;
217 return PXENV_EXIT_SUCCESS;
218}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
uint8_t system[ETH_ALEN]
System identifier.
Definition eth_slow.h:13
A command-line command.
Definition command.h:10
SEGOFF16_t Command
Command to execute.
Definition pxe_api.h:1647
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1646

References s_PXENV_FILE_EXEC::Command, DBG, PXENV_EXIT_FAILURE, PXENV_EXIT_SUCCESS, PXENV_STATUS, PXENV_STATUS_SUCCESS, rc, real_to_virt(), s_PXENV_FILE_EXEC::Status, and system.

◆ pxenv_file_cmdline()

PXENV_EXIT_t pxenv_file_cmdline ( struct s_PXENV_FILE_CMDLINE * file_cmdline)
static

FILE CMDLINE.

Parameters
file_cmdlinePointer to a struct s_PXENV_FILE_CMDLINE
s_PXENV_FILE_CMDLINE::BufferBuffer to contain command line
s_PXENV_FILE_CMDLINE::BufferSizeSize of buffer
Return values
PXENV_EXIT_SUCCESSCommand was executed successfully
PXENV_EXIT_FAILURECommand was not executed successfully
s_PXENV_FILE_EXEC::StatusPXE status code
s_PXENV_FILE_EXEC::BufferSizeLength of command line (including NUL)

Definition at line 233 of file pxe_file.c.

233 {
234 char *buffer;
235 size_t len;
236
237 DBG ( "PXENV_FILE_CMDLINE to %04x:%04x+%04x \"%s\"\n",
238 file_cmdline->Buffer.segment, file_cmdline->Buffer.offset,
239 file_cmdline->BufferSize, pxe_cmdline );
240
241 buffer = real_to_virt ( file_cmdline->Buffer.segment,
242 file_cmdline->Buffer.offset );
243 len = file_cmdline->BufferSize;
244 if ( pxe_cmdline ) {
245 len = snprintf ( buffer, len, "%s", pxe_cmdline );
246 file_cmdline->BufferSize = ( len + 1 /* NUL */ );
247 } else {
248 file_cmdline->BufferSize = 0;
249 }
250
251 file_cmdline->Status = PXENV_STATUS_SUCCESS;
252 return PXENV_EXIT_SUCCESS;
253}
const char * pxe_cmdline
PXE command line.
Definition pxe_image.c:48
SEGOFF16_t Buffer
Data buffer.
Definition pxe_api.h:1712
UINT16_t BufferSize
Data buffer size.
Definition pxe_api.h:1711
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1710
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References s_PXENV_FILE_CMDLINE::Buffer, buffer, s_PXENV_FILE_CMDLINE::BufferSize, DBG, len, pxe_cmdline, PXENV_EXIT_SUCCESS, PXENV_STATUS_SUCCESS, real_to_virt(), snprintf(), and s_PXENV_FILE_CMDLINE::Status.

◆ pxenv_file_api_check()

PXENV_EXIT_t pxenv_file_api_check ( struct s_PXENV_FILE_API_CHECK * file_api_check)
static

FILE API CHECK.

Parameters
file_execPointer to a struct s_PXENV_FILE_API_CHECK
s_PXENV_FILE_API_CHECK::MagicInbound magic number (0x91d447b2)
Return values
PXENV_EXIT_SUCCESSCommand was executed successfully
PXENV_EXIT_FAILURECommand was not executed successfully
s_PXENV_FILE_API_CHECK::StatusPXE status code
s_PXENV_FILE_API_CHECK::MagicOutbound magic number (0xe9c17b20)
s_PXENV_FILE_API_CHECK::Provider"iPXE" (0x45585067)
s_PXENV_FILE_API_CHECK::APIMaskAPI function bitmask
s_PXENV_FILE_API_CHECK::FlagsReserved

Definition at line 270 of file pxe_file.c.

270 {
271 struct pxe_api_call *call;
272 unsigned int mask = 0;
273 unsigned int offset;
274
275 DBG ( "PXENV_FILE_API_CHECK" );
276
277 /* Check for magic value */
278 if ( file_api_check->Magic != 0x91d447b2 ) {
279 file_api_check->Status = PXENV_STATUS_BAD_FUNC;
280 return PXENV_EXIT_FAILURE;
281 }
282
283 /* Check for required parameter size */
284 if ( file_api_check->Size < sizeof ( *file_api_check ) ) {
285 file_api_check->Status = PXENV_STATUS_OUT_OF_RESOURCES;
286 return PXENV_EXIT_FAILURE;
287 }
288
289 /* Determine supported calls */
291 offset = ( call->opcode - PXENV_FILE_MIN );
292 if ( offset <= ( PXENV_FILE_MAX - PXENV_FILE_MIN ) )
293 mask |= ( 1 << offset );
294 }
295
296 /* Fill in parameters */
297 file_api_check->Size = sizeof ( *file_api_check );
298 file_api_check->Magic = 0xe9c17b20;
299 file_api_check->Provider = 0x45585067; /* "iPXE" */
300 file_api_check->APIMask = mask;
301 file_api_check->Flags = 0; /* None defined */
302
303 file_api_check->Status = PXENV_STATUS_SUCCESS;
304 return PXENV_EXIT_SUCCESS;
305}
uint16_t offset
Offset to command line.
Definition bzimage.h:3
#define PXENV_FILE_MIN
Minimum possible opcode used within PXE FILE API.
Definition pxe_api.h:1520
#define PXENV_FILE_MAX
Minimum possible opcode used within PXE FILE API.
Definition pxe_api.h:1523
#define PXENV_STATUS_BAD_FUNC
Definition pxe_error.h:21
#define PXENV_STATUS_OUT_OF_RESOURCES
Definition pxe_error.h:25
#define PXE_API_CALLS
PXE API call table.
Definition pxe.h:93
A PXE API call.
Definition pxe.h:81
uint16_t opcode
Opcode.
Definition pxe.h:89
UINT32_t Magic
Magic number.
Definition pxe_api.h:1668
PXENV_STATUS_t Status
PXE status code.
Definition pxe_api.h:1666
UINT16_t Size
Size of structure.
Definition pxe_api.h:1667
UINT32_t APIMask
Supported API functions.
Definition pxe_api.h:1670
UINT32_t Flags
Reserved for the future.
Definition pxe_api.h:1671
UINT32_t Provider
Implementation identifier.
Definition pxe_api.h:1669
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References s_PXENV_FILE_API_CHECK::APIMask, DBG, s_PXENV_FILE_API_CHECK::Flags, for_each_table_entry, s_PXENV_FILE_API_CHECK::Magic, offset, pxe_api_call::opcode, s_PXENV_FILE_API_CHECK::Provider, PXE_API_CALLS, PXENV_EXIT_FAILURE, PXENV_EXIT_SUCCESS, PXENV_FILE_MAX, PXENV_FILE_MIN, PXENV_STATUS_BAD_FUNC, PXENV_STATUS_OUT_OF_RESOURCES, PXENV_STATUS_SUCCESS, s_PXENV_FILE_API_CHECK::Size, and s_PXENV_FILE_API_CHECK::Status.

Variable Documentation

◆ __pxe_api_call

struct pxe_api_call pxe_file_api [] __pxe_api_call
Initial value:
= {
}
#define PXENV_FILE_API_CHECK
PXE API function code for pxenv_file_api_check()
Definition pxe_api.h:1662
#define PXENV_FILE_CLOSE
PXE API function code for pxenv_file_close()
Definition pxe_api.h:1555
#define PXENV_FILE_CMDLINE
PXE API function code for pxenv_file_cmdline()
Definition pxe_api.h:1706
#define PXENV_FILE_EXEC
PXE API function code for pxenv_file_exec()
Definition pxe_api.h:1642
#define PXENV_FILE_OPEN
PXE API function code for pxenv_file_open()
Definition pxe_api.h:1533
#define PXENV_FILE_READ
PXE API function code for pxenv_file_read()
Definition pxe_api.h:1599
#define PXENV_FILE_SELECT
PXE API function code for pxenv_file_select()
Definition pxe_api.h:1575
#define PXENV_GET_FILE_SIZE
PXE API function code for pxenv_get_file_size()
Definition pxe_api.h:1621
#define PXE_API_CALL(_opcode, _entry, _params_type)
Define a PXE API call.
Definition pxe.h:106
static PXENV_EXIT_t pxenv_file_open(struct s_PXENV_FILE_OPEN *file_open)
FILE OPEN.
Definition pxe_file.c:54
static PXENV_EXIT_t pxenv_get_file_size(struct s_PXENV_GET_FILE_SIZE *get_file_size)
GET FILE SIZE.
Definition pxe_file.c:173
static PXENV_EXIT_t pxenv_file_select(struct s_PXENV_FILE_SELECT *file_select)
FILE SELECT.
Definition pxe_file.c:107
static PXENV_EXIT_t pxenv_file_read(struct s_PXENV_FILE_READ *file_read)
FILE READ.
Definition pxe_file.c:139
static PXENV_EXIT_t pxenv_file_cmdline(struct s_PXENV_FILE_CMDLINE *file_cmdline)
FILE CMDLINE.
Definition pxe_file.c:233
static PXENV_EXIT_t pxenv_file_api_check(struct s_PXENV_FILE_API_CHECK *file_api_check)
FILE API CHECK.
Definition pxe_file.c:270
static PXENV_EXIT_t pxenv_file_close(struct s_PXENV_FILE_CLOSE *file_close)
FILE CLOSE.
Definition pxe_file.c:86
static PXENV_EXIT_t pxenv_file_exec(struct s_PXENV_FILE_EXEC *file_exec)
FILE EXEC.
Definition pxe_file.c:201
Parameter block for pxenv_file_api_check()
Definition pxe_api.h:1665
Parameter block for pxenv_file_close()
Definition pxe_api.h:1558
Parameter block for pxenv_file_cmdline()
Definition pxe_api.h:1709
Parameter block for pxenv_file_exec()
Definition pxe_api.h:1645
Parameter block for pxenv_file_open()
Definition pxe_api.h:1536
Parameter block for pxenv_file_read()
Definition pxe_api.h:1602
Parameter block for pxenv_file_select()
Definition pxe_api.h:1581
Parameter block for pxenv_get_file_size()
Definition pxe_api.h:1624

PXE file API.

Definition at line 308 of file pxe_file.c.