PatchworkOS
Loading...
Searching...
No Matches

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

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.
 
typedef ctl_t ctl_array_t[]
 Type definition for an array of ctl commands.
 

Functions

uint64_t ctl_dispatch (ctl_array_t ctls, file_t *file, const void *buffer, uint64_t count)
 Dispatch a ctl command.
 

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.

Macro Definition Documentation

◆ 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:25
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:57
uint64_t(* write)(file_t *file, const void *buffer, uint64_t count, uint64_t *offset)
Definition file.h:62

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 41 of file ctl.h.

◆ 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_array_t ctls, file_t *file, const void *buffer, uint64_t count)
Dispatch a ctl command.
Definition ctl.c:9
static dentry_t * file
Definition log_file.c:17
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static atomic_long count
Definition main.c:9
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Structure defining a ctl command.
Definition ctl.h:62
File structure.
Definition file.h:37

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 25 of file ctl.h.

Typedef Documentation

◆ ctl_array_t

typedef ctl_t ctl_array_t[]

Type definition for an array of ctl commands.

Definition at line 72 of file ctl.h.

◆ ctl_func_t

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

Type definition for a ctl function.

Parameters
fileThe file the ctl command was sent to.
argcThe number of arguments.
argvThe arguments.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 55 of file ctl.h.

Function Documentation

◆ ctl_dispatch()

uint64_t ctl_dispatch ( ctl_array_t  ctls,
file_t file,
const void *  buffer,
uint64_t  count 
)

Dispatch a ctl command.

Parameters
ctlsThe array of ctl commands to dispatch to.
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.

Definition at line 9 of file ctl.c.

References ctl_t::argcMax, argsplit_buf(), buffer, count, E2BIG, EINVAL, ENOENT, ERR, errno, EUNKNOWNCTL, file, ctl_t::func, MAX_PATH, ctl_t::name, NULL, and strcmp().