PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
Control Files

Helpers to implement control file operations. More...

Collaboration diagram for Control Files:

Detailed Description

Helpers to implement control file operations.

A control file is a special file that takes in commands as text input and performs actions based on those commands.

Command Format

Commands should be formatted as follows:

command1 arg1 arg2 arg3 ... && command2 arg1 arg2 ... && ...

Data Structures

struct  ctl_t
 Structure defining a ctl command. More...
 

Macros

#define CTL_MAX_BUFFER   0x1000
 Maximum size of the buffer used for argument parsing.
 
#define CTL_STANDARD_WRITE_DEFINE(name, ...)
 Helper macro to define a standard ctl write function.
 
#define CTL_STANDARD_OPS_DEFINE(name, ...)
 Helper macro to define a standard ctl file operations structure.
 

Typedefs

typedef uint64_t(* ctl_func_t) (file_t *file, uint64_t, const char **)
 Type definition for a ctl function.
 

Functions

uint64_t ctl_dispatch (ctl_t ctls[], file_t *file, const void *buffer, size_t count)
 Dispatch a ctl command.
 

Macro Definition Documentation

◆ CTL_MAX_BUFFER

#define CTL_MAX_BUFFER   0x1000

Maximum size of the buffer used for argument parsing.

Definition at line 28 of file ctl.h.

◆ CTL_STANDARD_WRITE_DEFINE

#define CTL_STANDARD_WRITE_DEFINE (   name,
  ... 
)
Value:
static ctl_t name##ctls[] = __VA_ARGS__; \
static size_t name(file_t* file, const void* buffer, size_t count, size_t* offset) \
{ \
UNUSED(offset); \
return ctl_dispatch(name##ctls, file, buffer, count); \
}
EFI_PHYSICAL_ADDRESS buffer
Definition main.c:237
uint64_t ctl_dispatch(ctl_t ctls[], file_t *file, const void *buffer, size_t count)
Dispatch a ctl command.
static uint64_t offset
Definition screen.c:19
static atomic_long count
Definition main.c:11
Structure defining a ctl command.
Definition ctl.h:70
File structure.
Definition file.h:39

Helper macro to define a standard ctl write function.

This macro defines a write function that dispatches commands to a given array of ctl_t structures.

Parameters
nameThe name of the ctl write function.
...The ctl array to dispatch commands to.

Definition at line 38 of file ctl.h.

◆ CTL_STANDARD_OPS_DEFINE

#define CTL_STANDARD_OPS_DEFINE (   name,
  ... 
)
Value:
CTL_STANDARD_WRITE_DEFINE(name##write, __VA_ARGS__) \
static file_ops_t name = (file_ops_t){ \
.write = name##write, \
};
#define CTL_STANDARD_WRITE_DEFINE(name,...)
Helper macro to define a standard ctl write function.
Definition ctl.h:38
size_t write(fd_t fd, const void *buffer, size_t count)
System call for writing to files.
Definition write.c:8
File operations structure.
Definition file.h:54
size_t(* write)(file_t *file, const void *buffer, size_t count, size_t *offset)
Definition file.h:59

Helper macro to define a standard ctl file operations structure.

This macro defines a file operations structure with all standard ctl operations implemented.

Parameters
nameThe name of the ctl file operations structure.
...The ctl array to dispatch commands to.

Definition at line 54 of file ctl.h.

Typedef Documentation

◆ ctl_func_t

typedef uint64_t(* ctl_func_t) (file_t *file, uint64_t, const char **)

Type definition for a ctl function.

Definition at line 63 of file ctl.h.

Function Documentation

◆ ctl_dispatch()

uint64_t ctl_dispatch ( ctl_t  ctls[],
file_t file,
const void *  buffer,
size_t  count 
)

Dispatch a ctl command.

Parameters
ctlsThe array of ctl commands to dispatch to, terminated by an entry with a NULL name.
fileThe file the ctl command was sent to.
bufferThe buffer containing the command and its arguments.
countThe number of bytes in the buffer.
Returns
On success, the number of bytes processed (count). On failure, ERR and errno is set.