PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches

Helpers to implement ctl (control) file operations. More...

Collaboration diagram for Ctl:

Detailed Description

Helpers to implement ctl (control) file operations.

A ctl 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_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, uint64_t count)
 Dispatch a ctl command.
 

Macro Definition Documentation

◆ CTL_STANDARD_WRITE_DEFINE

#define CTL_STANDARD_WRITE_DEFINE (   name,
  ... 
)
Value:
static ctl_t name##ctls[] = __VA_ARGS__; \
static uint64_t name(file_t* file, const void* buffer, uint64_t count, uint64_t* offset) \
{ \
(void)offset; \
return ctl_dispatch(name##ctls, file, buffer, count); \
}
uint64_t ctl_dispatch(ctl_t ctls[], file_t *file, const void *buffer, uint64_t count)
Dispatch a ctl command.
static dentry_t * file
Definition log_file.c:22
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static atomic_long count
Definition main.c:10
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Structure defining a ctl command.
Definition ctl.h:65
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 33 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:33
uint64_t write(fd_t fd, const void *buffer, uint64_t count)
System call for writing to files.
Definition write.c:9
File operations structure.
Definition file.h:54
uint64_t(* write)(file_t *file, const void *buffer, uint64_t count, uint64_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 49 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 58 of file ctl.h.

Function Documentation

◆ ctl_dispatch()

uint64_t ctl_dispatch ( ctl_t  ctls[],
file_t file,
const void *  buffer,
uint64_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.