agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
vfs_fd.h File Reference
#include <zrtos/bitfield.h>
#include <zrtos/vfs_file.h>
Include dependency graph for vfs_fd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _zrtos_vfs_fd_t
 
struct  _zrtos_vfs_fd_set_t
 

Macros

#define ZRTOS_VFS_FD_SET__EACH_BEGIN(thiz, fd_)
 
#define ZRTOS_VFS_FD_SET__EACH_END   }
 

Typedefs

typedef struct _zrtos_vfs_fd_t zrtos_vfs_fd_t
 
typedef struct _zrtos_vfs_fd_set_t zrtos_vfs_fd_set_t
 

Functions

void zrtos_vfs_fd_set__clear (zrtos_vfs_fd_set_t *thiz, zrtos_vfs_fd_t fd)
 
bool zrtos_vfs_fd_set__is_set (zrtos_vfs_fd_set_t *thiz, zrtos_vfs_fd_t fd)
 
void zrtos_vfs_fd_set__set (zrtos_vfs_fd_set_t *thiz, zrtos_vfs_fd_t fd)
 
void zrtos_vfs_fd_set__zero (zrtos_vfs_fd_set_t *thiz)
 
void zrtos_vfs_fd_set__copy (zrtos_vfs_fd_set_t *thiz, zrtos_vfs_fd_set_t *src)
 
bool zrtos_vfs_fd_set__init (zrtos_vfs_fd_set_t *thiz)
 
zrtos_error_t zrtos_vfs_fd__open (char *path, zrtos_vfs_fd_t *thiz, void *file_ctx)
 
zrtos_error_t zrtos_vfs_fd__close (zrtos_vfs_fd_t thiz)
 
zrtos_error_t zrtos_vfs_fd__read (zrtos_vfs_fd_t thiz, char *path, void *buffer, size_t len, size_t offset, size_t *outlen)
 
zrtos_error_t zrtos_vfs_fd__spi_transfer (zrtos_vfs_fd_t fd, size_t len,...)
 
bool zrtos_vfs_fd__is_sync_again_error (zrtos_error_t ret)
 
zrtos_error_t zrtos_vfs_fd__read_sync (zrtos_vfs_fd_t thiz, char *path, void *buffer, size_t len, size_t offset)
 
zrtos_error_t zrtos_vfs_fd__write (zrtos_vfs_fd_t thiz, char *path, void *buffer, size_t len, size_t offset, size_t *outlen)
 
zrtos_error_t zrtos_vfs_fd__write_sync (zrtos_vfs_fd_t thiz, char *path, void *buffer, size_t len, size_t offset)
 
zrtos_error_t zrtos_vfs_fd__ioctl (zrtos_vfs_fd_t thiz, char *path, int request,...)
 
zrtos_error_t zrtos_vfs_fd__can_read (zrtos_vfs_fd_t thiz)
 
zrtos_error_t zrtos_vfs_fd__can_write (zrtos_vfs_fd_t thiz)
 
size_t zrtos_vfs_fd__select (zrtos_vfs_fd_set_t *readfds, zrtos_vfs_fd_set_t *writefds)
 

Macro Definition Documentation

◆ ZRTOS_VFS_FD_SET__EACH_BEGIN

#define ZRTOS_VFS_FD_SET__EACH_BEGIN (   thiz,
  fd_ 
)
Value:
(thiz)->fds_bits\
,pos\
){\
zrtos_vfs_fd_t fd_ = {.fd = pos};
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
#define ZRTOS_BITFIELD__NFDBITS
Definition: bitfield.h:26
#define ZRTOS_BITFIELD__EACH(thiz, len, pos)
Definition: bitfield.h:114

Definition at line 341 of file vfs_fd.h.

◆ ZRTOS_VFS_FD_SET__EACH_END

#define ZRTOS_VFS_FD_SET__EACH_END   }

Definition at line 349 of file vfs_fd.h.

Typedef Documentation

◆ zrtos_vfs_fd_set_t

◆ zrtos_vfs_fd_t

Function Documentation

◆ zrtos_vfs_fd__can_read()

zrtos_error_t zrtos_vfs_fd__can_read ( zrtos_vfs_fd_t  thiz)

Definition at line 278 of file vfs_fd.h.

280  {
282  ZRTOS_TYPES__TYPEOF(thiz.fd) fd = thiz.fd;
283 
287  );
288  }
289 
290  return ret;
291 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
zrtos_error_t zrtos_vfs_file__can_read(zrtos_vfs_file_t *file)
Definition: vfs_file.h:126
size_t fd
Definition: vfs_fd.h:18
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
Invalid argument.
Definition: error.h:46
zrtos_error_t
Definition: error.h:20
#define ZRTOS_TYPES__TYPEOF(a)
Definition: types.h:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__can_write()

zrtos_error_t zrtos_vfs_fd__can_write ( zrtos_vfs_fd_t  thiz)

Definition at line 293 of file vfs_fd.h.

295  {
297  ZRTOS_TYPES__TYPEOF(thiz.fd) fd = thiz.fd;
298 
302  );
303  }
304 
305  return ret;
306 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
size_t fd
Definition: vfs_fd.h:18
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
Invalid argument.
Definition: error.h:46
zrtos_error_t zrtos_vfs_file__can_write(zrtos_vfs_file_t *file)
Definition: vfs_file.h:136
zrtos_error_t
Definition: error.h:20
#define ZRTOS_TYPES__TYPEOF(a)
Definition: types.h:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__close()

zrtos_error_t zrtos_vfs_fd__close ( zrtos_vfs_fd_t  thiz)

Definition at line 77 of file vfs_fd.h.

77  {
79  ZRTOS_TYPES__TYPEOF(thiz.fd) fd = thiz.fd;
80 
83  }
84 
85  return ret;
86 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
size_t fd
Definition: vfs_fd.h:18
zrtos_error_t zrtos_vfs_file__close(zrtos_vfs_file_t *file)
Definition: vfs_file.h:71
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
Invalid argument.
Definition: error.h:46
zrtos_error_t
Definition: error.h:20
#define ZRTOS_TYPES__TYPEOF(a)
Definition: types.h:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__ioctl()

zrtos_error_t zrtos_vfs_fd__ioctl ( zrtos_vfs_fd_t  thiz,
char *  path,
int  request,
  ... 
)

Definition at line 254 of file vfs_fd.h.

259  {
261  ZRTOS_TYPES__TYPEOF(thiz.fd) fd = thiz.fd;
262  va_list args;
263 
264  va_start(args,request);
268  ,path
269  ,request
270  ,args
271  );
272  }
273  va_end(args);
274 
275  return ret;
276 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
zrtos_error_t zrtos_vfs_file__ioctl_va(zrtos_vfs_file_t *file, char *path, int request, va_list args)
Definition: vfs_file.h:146
size_t fd
Definition: vfs_fd.h:18
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
Invalid argument.
Definition: error.h:46
zrtos_error_t
Definition: error.h:20
#define ZRTOS_TYPES__TYPEOF(a)
Definition: types.h:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__is_sync_again_error()

bool zrtos_vfs_fd__is_sync_again_error ( zrtos_error_t  ret)

Definition at line 163 of file vfs_fd.h.

163  {
164  return ret == ZRTOS_ERROR__AGAIN
165  || ret == ZRTOS_ERROR__WOULDBLOCK
166  ;
167 }
Try again.
Definition: error.h:35
Operation would block.
Definition: error.h:65
Here is the caller graph for this function:

◆ zrtos_vfs_fd__open()

zrtos_error_t zrtos_vfs_fd__open ( char *  path,
zrtos_vfs_fd_t thiz,
void *  file_ctx 
)

Definition at line 70 of file vfs_fd.h.

70  {
71  zrtos_vfs_file_t *file;
72  zrtos_error_t ret = zrtos_vfs_file__open(path,&file,file_ctx);
73  thiz->fd = file - (&zrtos_vfs_file__index[0]);
74  return ret;
75 }
zrtos_error_t zrtos_vfs_file__open(char *path, zrtos_vfs_file_t **file, void *file_ctx)
Definition: vfs_file.h:30
size_t fd
Definition: vfs_fd.h:18
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__read()

zrtos_error_t zrtos_vfs_fd__read ( zrtos_vfs_fd_t  thiz,
char *  path,
void *  buffer,
size_t  len,
size_t  offset,
size_t outlen 
)

Definition at line 88 of file vfs_fd.h.

95  {
97  ZRTOS_TYPES__TYPEOF(thiz.fd) fd = thiz.fd;
98 
100  ret = zrtos_vfs_file__read(
102  ,path
103  ,buffer
104  ,len
105  ,offset
106  ,outlen
107  );
108  }
109 
110  return ret;
111 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
zrtos_error_t zrtos_vfs_file__read(zrtos_vfs_file_t *file, char *path, void *buffer, size_t len, size_t offset, size_t *ret)
Definition: vfs_file.h:86
size_t fd
Definition: vfs_fd.h:18
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
Invalid argument.
Definition: error.h:46
zrtos_error_t
Definition: error.h:20
#define ZRTOS_TYPES__TYPEOF(a)
Definition: types.h:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__read_sync()

zrtos_error_t zrtos_vfs_fd__read_sync ( zrtos_vfs_fd_t  thiz,
char *  path,
void *  buffer,
size_t  len,
size_t  offset 
)

Definition at line 169 of file vfs_fd.h.

175  {
177  size_t outlen;
178  uint8_t *data = ZRTOS_CAST(uint8_t*,buffer);
179 
180  while(len && zrtos_vfs_fd__is_sync_again_error(ret)){
181  ret = zrtos_vfs_fd__read(
182  thiz
183  ,path
184  ,data
185  ,len
186  ,offset
187  ,&outlen
188  );
189  if(zrtos_error__is_success(ret)){
190  len -= outlen;
191  offset += outlen;
192  data += outlen;
193  }
194  }
195 
196  return ret;
197 }
#define ZRTOS_CAST(type, value)
Definition: cast.h:18
Try again.
Definition: error.h:35
zrtos_error_t zrtos_vfs_fd__read(zrtos_vfs_fd_t thiz, char *path, void *buffer, size_t len, size_t offset, size_t *outlen)
Definition: vfs_fd.h:88
bool zrtos_vfs_fd__is_sync_again_error(zrtos_error_t ret)
Definition: vfs_fd.h:163
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
static uint8_t
Definition: mcp2515.h:159
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:

◆ zrtos_vfs_fd__select()

size_t zrtos_vfs_fd__select ( zrtos_vfs_fd_set_t readfds,
zrtos_vfs_fd_set_t writefds 
)

Definition at line 308 of file vfs_fd.h.

311  {
312  size_t ret = 0;
314  zrtos_bitfield_t *bitfield = readfds->fds_bits;
315  size_t l = 1;
316 
317  while(l--){
319  bitfield
321  ,pos
322  ){
323  zrtos_vfs_fd_t fd = {.fd = pos};
324  if(ZRTOS_ERROR__AGAIN == callback(fd)){
326  bitfield
327  ,fd.fd
328  ,false
329  );
330  }else{
331  ret++;
332  }
333  }
334  callback = zrtos_vfs_fd__can_write;
335  bitfield = writefds->fds_bits;
336  }
337 
338  return ret;
339 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
Try again.
Definition: error.h:35
#define ZRTOS_BITFIELD__NFDBITS
Definition: bitfield.h:26
#define ZRTOS_BITFIELD__EACH(thiz, len, pos)
Definition: bitfield.h:114
size_t fd
Definition: vfs_fd.h:18
zrtos_error_t zrtos_vfs_fd__can_write(zrtos_vfs_fd_t thiz)
Definition: vfs_fd.h:293
zrtos_error_t zrtos_vfs_fd__can_read(zrtos_vfs_fd_t thiz)
Definition: vfs_fd.h:278
void zrtos_bitfield__set(zrtos_bitfield_t *thiz, size_t pos, bool val)
Definition: bitfield.h:31
#define ZRTOS_TYPES__TYPEOF(a)
Definition: types.h:146
zrtos_bitfield_t fds_bits[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX/ZRTOS_BITFIELD__NFDBITS]
Definition: vfs_fd.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__spi_transfer()

zrtos_error_t zrtos_vfs_fd__spi_transfer ( zrtos_vfs_fd_t  fd,
size_t  len,
  ... 
)

Definition at line 113 of file vfs_fd.h.

117  {
118  size_t l = 0;
119  uint8_t ll;
121  zrtos_va_t args1;
122  zrtos_va_t args2;
123  size_t outlen;
124 
125  zrtos_va__start(len,args1);
126  zrtos_va__copy(args2,args1);
127 
128  while(len--){
129  zrtos_va__arg_ptr(args2,void*);
130  l += zrtos_va__arg(args2,size_t);
131  }
132 
133  ll = l;
134 
135  ret = zrtos_vfs_fd__read(
136  fd
137  ,(char*)""
138  ,&ll
139  ,1
140  ,0
141  ,&outlen
142  );
143 
144  while(zrtos_error__is_success(ret) && len--){
145  void *buffer = zrtos_va__arg_ptr(args,void*);
146  size_t length = zrtos_va__arg(args,size_t);
147  ret = zrtos_vfs_fd__read(
148  fd
149  ,(char*)""
150  ,buffer
151  ,length
152  ,0
153  ,&outlen
154  );
155  }
156 
157  zrtos_va__end(args1);
158  zrtos_va__end(args2);
159 
160  return ret;
161 }
zrtos_error_t zrtos_vfs_fd__read(zrtos_vfs_fd_t thiz, char *path, void *buffer, size_t len, size_t offset, size_t *outlen)
Definition: vfs_fd.h:88
#define zrtos_va_t
Definition: va.h:19
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
Successful program execution status.
Definition: error.h:22
#define zrtos_va__arg_ptr(ap, type)
Definition: va.h:26
#define zrtos_va__start
Definition: va.h:20
static uint8_t
Definition: mcp2515.h:159
zrtos_error_t
Definition: error.h:20
#define zrtos_va__copy
Definition: va.h:29
#define zrtos_va__end
Definition: va.h:28
#define zrtos_va__arg(ap, type)
Definition: va.h:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__write()

zrtos_error_t zrtos_vfs_fd__write ( zrtos_vfs_fd_t  thiz,
char *  path,
void *  buffer,
size_t  len,
size_t  offset,
size_t outlen 
)

Definition at line 199 of file vfs_fd.h.

206  {
208  ZRTOS_TYPES__TYPEOF(thiz.fd) fd = thiz.fd;
209 
211  ret = zrtos_vfs_file__write(
213  ,path
214  ,buffer
215  ,len
216  ,offset
217  ,outlen
218  );
219  }
220 
221  return ret;
222 }
zrtos_error_t zrtos_vfs_file__write(zrtos_vfs_file_t *file, char *path, void *buffer, size_t len, size_t offset, size_t *ret)
Definition: vfs_file.h:106
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
size_t fd
Definition: vfs_fd.h:18
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
Invalid argument.
Definition: error.h:46
zrtos_error_t
Definition: error.h:20
#define ZRTOS_TYPES__TYPEOF(a)
Definition: types.h:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd__write_sync()

zrtos_error_t zrtos_vfs_fd__write_sync ( zrtos_vfs_fd_t  thiz,
char *  path,
void *  buffer,
size_t  len,
size_t  offset 
)

Definition at line 224 of file vfs_fd.h.

230  {
232  size_t outlen;
233  uint8_t *data = ZRTOS_CAST(uint8_t*,buffer);
234 
235  while(len && zrtos_vfs_fd__is_sync_again_error(ret)){
236  ret = zrtos_vfs_fd__write(
237  thiz
238  ,path
239  ,data
240  ,len
241  ,offset
242  ,&outlen
243  );
244  if(zrtos_error__is_success(ret)){
245  len -= outlen;
246  offset += outlen;
247  data += outlen;
248  }
249  }
250 
251  return ret;
252 }
#define ZRTOS_CAST(type, value)
Definition: cast.h:18
zrtos_error_t zrtos_vfs_fd__write(zrtos_vfs_fd_t thiz, char *path, void *buffer, size_t len, size_t offset, size_t *outlen)
Definition: vfs_fd.h:199
Try again.
Definition: error.h:35
bool zrtos_vfs_fd__is_sync_again_error(zrtos_error_t ret)
Definition: vfs_fd.h:163
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
static uint8_t
Definition: mcp2515.h:159
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:

◆ zrtos_vfs_fd_set__clear()

void zrtos_vfs_fd_set__clear ( zrtos_vfs_fd_set_t thiz,
zrtos_vfs_fd_t  fd 
)

Definition at line 27 of file vfs_fd.h.

27  {
29  thiz->fds_bits
30  ,fd.fd
31  ,false
32  );
33 }
size_t fd
Definition: vfs_fd.h:18
void zrtos_bitfield__set(zrtos_bitfield_t *thiz, size_t pos, bool val)
Definition: bitfield.h:31
zrtos_bitfield_t fds_bits[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX/ZRTOS_BITFIELD__NFDBITS]
Definition: vfs_fd.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd_set__copy()

void zrtos_vfs_fd_set__copy ( zrtos_vfs_fd_set_t thiz,
zrtos_vfs_fd_set_t src 
)

Definition at line 57 of file vfs_fd.h.

57  {
59  thiz->fds_bits
60  ,src->fds_bits
62  );
63 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
#define ZRTOS_BITFIELD__NFDBITS
Definition: bitfield.h:26
void zrtos_bitfield__copy(zrtos_bitfield_t *thiz, zrtos_bitfield_t *src, size_t len)
Definition: bitfield.h:63
zrtos_bitfield_t fds_bits[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX/ZRTOS_BITFIELD__NFDBITS]
Definition: vfs_fd.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd_set__init()

bool zrtos_vfs_fd_set__init ( zrtos_vfs_fd_set_t thiz)

Definition at line 65 of file vfs_fd.h.

65  {
67  return true;
68 }
void zrtos_vfs_fd_set__zero(zrtos_vfs_fd_set_t *thiz)
Definition: vfs_fd.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd_set__is_set()

bool zrtos_vfs_fd_set__is_set ( zrtos_vfs_fd_set_t thiz,
zrtos_vfs_fd_t  fd 
)

Definition at line 35 of file vfs_fd.h.

35  {
36  return zrtos_bitfield__get(
37  thiz->fds_bits
38  ,fd.fd
39  );
40 }
bool zrtos_bitfield__get(zrtos_bitfield_t *thiz, size_t pos)
Definition: bitfield.h:49
size_t fd
Definition: vfs_fd.h:18
zrtos_bitfield_t fds_bits[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX/ZRTOS_BITFIELD__NFDBITS]
Definition: vfs_fd.h:24
Here is the call graph for this function:

◆ zrtos_vfs_fd_set__set()

void zrtos_vfs_fd_set__set ( zrtos_vfs_fd_set_t thiz,
zrtos_vfs_fd_t  fd 
)

Definition at line 42 of file vfs_fd.h.

42  {
44  thiz->fds_bits
45  ,fd.fd
46  ,true
47  );
48 }
size_t fd
Definition: vfs_fd.h:18
void zrtos_bitfield__set(zrtos_bitfield_t *thiz, size_t pos, bool val)
Definition: bitfield.h:31
zrtos_bitfield_t fds_bits[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX/ZRTOS_BITFIELD__NFDBITS]
Definition: vfs_fd.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_vfs_fd_set__zero()

void zrtos_vfs_fd_set__zero ( zrtos_vfs_fd_set_t thiz)

Definition at line 50 of file vfs_fd.h.

50  {
52  thiz->fds_bits
54  );
55 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
#define ZRTOS_BITFIELD__NFDBITS
Definition: bitfield.h:26
void zrtos_bitfield__zero(zrtos_bitfield_t *thiz, size_t len)
Definition: bitfield.h:59
zrtos_bitfield_t fds_bits[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX/ZRTOS_BITFIELD__NFDBITS]
Definition: vfs_fd.h:24
Here is the call graph for this function:
Here is the caller graph for this function: