agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
vfs_file.h File Reference
#include <zrtos/error.h>
#include <zrtos/bitfield.h>
#include <zrtos/vfs_dentry.h>
Include dependency graph for vfs_file.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_file_t
 

Macros

#define ZRTOS_VFS_FILE__EACH_BEGIN(fd, file)
 
#define ZRTOS_VFS_FILE__EACH_END
 

Typedefs

typedef struct _zrtos_vfs_file_t zrtos_vfs_file_t
 

Functions

zrtos_error_t zrtos_vfs_file__open (char *path, zrtos_vfs_file_t **file, void *file_ctx)
 
size_t zrtos_vfs_file__get_dentry_count (zrtos_vfs_file_t *file)
 
zrtos_error_t zrtos_vfs_file__close (zrtos_vfs_file_t *file)
 
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)
 
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)
 
zrtos_error_t zrtos_vfs_file__can_read (zrtos_vfs_file_t *file)
 
zrtos_error_t zrtos_vfs_file__can_write (zrtos_vfs_file_t *file)
 
zrtos_error_t zrtos_vfs_file__ioctl_va (zrtos_vfs_file_t *file, char *path, int request, va_list args)
 
zrtos_error_t zrtos_vfs_file__ioctl (zrtos_vfs_file_t *file, char *path, int request,...)
 
void zrtos_vfs_file__set_inode_data (zrtos_vfs_file_t *thiz, void *ctx)
 
void * zrtos_vfs_file__get_inode_data (zrtos_vfs_file_t *thiz)
 
void zrtos_vfs_file__set_data (zrtos_vfs_file_t *thiz, void *ctx)
 
void * zrtos_vfs_file__get_data (zrtos_vfs_file_t *thiz)
 
void zrtos_vfs_file__set_offset (zrtos_vfs_file_t *thiz, zrtos_vfs_offset_t offset)
 
zrtos_vfs_offset_t zrtos_vfs_file__get_offset (zrtos_vfs_file_t *thiz)
 

Variables

zrtos_vfs_file_t zrtos_vfs_file__index [ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
 

Macro Definition Documentation

◆ ZRTOS_VFS_FILE__EACH_BEGIN

#define ZRTOS_VFS_FILE__EACH_BEGIN (   fd,
  file 
)
Value:
for(size_t fd = 0;fd < ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX;fd++){\
zrtos_vfs_file_t *file = &zrtos_vfs_file__index[fd];\
if(0 != file->dentry){
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28

Definition at line 211 of file vfs_file.h.

◆ ZRTOS_VFS_FILE__EACH_END

#define ZRTOS_VFS_FILE__EACH_END
Value:
}\
}

Definition at line 216 of file vfs_file.h.

Typedef Documentation

◆ zrtos_vfs_file_t

Function Documentation

◆ zrtos_vfs_file__can_read()

zrtos_error_t zrtos_vfs_file__can_read ( zrtos_vfs_file_t file)

Definition at line 126 of file vfs_file.h.

128  {
129  return file->dentry ? ZRTOS_VFS_PLUGIN__INVOKE(
130  file->dentry->inode.plugin
132  ,file
133  ) : ZRTOS_ERROR__BADF;
134 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
zrtos_vfs_plugin_t * plugin
Definition: vfs_inode.h:18
Bad file number.
Definition: error.h:33
#define ZRTOS_VFS_PLUGIN_OPERATION__CAN_READ
Definition: vfs_plugin.h:81
Here is the caller graph for this function:

◆ zrtos_vfs_file__can_write()

zrtos_error_t zrtos_vfs_file__can_write ( zrtos_vfs_file_t file)

Definition at line 136 of file vfs_file.h.

138  {
139  return file->dentry ? ZRTOS_VFS_PLUGIN__INVOKE(
140  file->dentry->inode.plugin
142  ,file
143  ) : ZRTOS_ERROR__BADF;
144 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
zrtos_vfs_plugin_t * plugin
Definition: vfs_inode.h:18
#define ZRTOS_VFS_PLUGIN_OPERATION__CAN_WRITE
Definition: vfs_plugin.h:82
Bad file number.
Definition: error.h:33
Here is the caller graph for this function:

◆ zrtos_vfs_file__close()

zrtos_error_t zrtos_vfs_file__close ( zrtos_vfs_file_t file)

Definition at line 71 of file vfs_file.h.

71  {
72  zrtos_error_t ret;
73 
74  file->dentry->count--;
76  file->dentry->inode.plugin
78  ,file
79  );
80  file->dentry = 0;
81  file->offset = 0;
82 
83  return ret;
84 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
zrtos_vfs_offset_t offset
Definition: vfs_file.h:20
zrtos_vfs_plugin_t * plugin
Definition: vfs_inode.h:18
#define ZRTOS_VFS_PLUGIN_OPERATION__CLOSE
Definition: vfs_plugin.h:76
zrtos_error_t
Definition: error.h:20
Here is the caller graph for this function:

◆ zrtos_vfs_file__get_data()

void* zrtos_vfs_file__get_data ( zrtos_vfs_file_t thiz)

Definition at line 199 of file vfs_file.h.

199  {
200  return thiz->ctx;
201 }
Here is the caller graph for this function:

◆ zrtos_vfs_file__get_dentry_count()

size_t zrtos_vfs_file__get_dentry_count ( zrtos_vfs_file_t file)

Definition at line 67 of file vfs_file.h.

67  {
68  return file->dentry->count;
69 }
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
Here is the caller graph for this function:

◆ zrtos_vfs_file__get_inode_data()

void* zrtos_vfs_file__get_inode_data ( zrtos_vfs_file_t thiz)

Definition at line 191 of file vfs_file.h.

191  {
192  return thiz->dentry->inode.ctx;
193 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
Here is the caller graph for this function:

◆ zrtos_vfs_file__get_offset()

zrtos_vfs_offset_t zrtos_vfs_file__get_offset ( zrtos_vfs_file_t thiz)

Definition at line 207 of file vfs_file.h.

207  {
208  return thiz->offset;
209 }
zrtos_vfs_offset_t offset
Definition: vfs_file.h:20
Here is the caller graph for this function:

◆ zrtos_vfs_file__ioctl()

zrtos_error_t zrtos_vfs_file__ioctl ( zrtos_vfs_file_t file,
char *  path,
int  request,
  ... 
)

Definition at line 166 of file vfs_file.h.

171  {
172  zrtos_error_t ret;
173  va_list args;
174 
175  va_start(args,request);
177  file
178  ,path
179  ,request
180  ,args
181  );
182  va_end(args);
183 
184  return ret;
185 }
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
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:

◆ zrtos_vfs_file__ioctl_va()

zrtos_error_t zrtos_vfs_file__ioctl_va ( zrtos_vfs_file_t file,
char *  path,
int  request,
va_list  args 
)

Definition at line 146 of file vfs_file.h.

151  {
152  zrtos_error_t ret;
153 
154  ret = file->dentry ? ZRTOS_VFS_PLUGIN__INVOKE(
155  file->dentry->inode.plugin
157  ,file
158  ,path
159  ,request
160  ,args
161  ) : ZRTOS_ERROR__BADF;
162 
163  return ret;
164 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
#define ZRTOS_VFS_PLUGIN_OPERATION__IOCTL
Definition: vfs_plugin.h:84
zrtos_vfs_plugin_t * plugin
Definition: vfs_inode.h:18
Bad file number.
Definition: error.h:33
zrtos_error_t
Definition: error.h:20
Here is the caller graph for this function:

◆ zrtos_vfs_file__open()

zrtos_error_t zrtos_vfs_file__open ( char *  path,
zrtos_vfs_file_t **  file,
void *  file_ctx 
)

Definition at line 30 of file vfs_file.h.

30  {
31  zrtos_error_t ret;
33  0
34  ,path
35  );
36  if(dentry){
37  for(size_t fd=0;fd<ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX;fd++){
38  if(0 == zrtos_vfs_file__index[fd].dentry){
39  zrtos_vfs_file_t *tmp = *file = &zrtos_vfs_file__index[fd];
40 
41  dentry->count++;
42  tmp->dentry = dentry;
43  tmp->ctx = file_ctx;
44 
45  zrtos_vfs_plugin_t *plugin = dentry->inode.plugin;
47  plugin
49  ,tmp
50  );
51  if(!zrtos_error__is_success(ret)){
52  dentry->count--;
53  tmp->dentry = 0;
54  }
55  goto L_OUT;
56  }
57  }
58  ret = ZRTOS_ERROR__MFILE;
59  }else{
60  ret = ZRTOS_ERROR__NOENT;
61  }
62 
63 L_OUT:
64  return ret;
65 }
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
No such file or directory.
Definition: error.h:26
#define ZRTOS_VFS_PLUGIN_OPERATION__OPEN
Definition: vfs_plugin.h:75
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
Too many open files.
Definition: error.h:48
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
zrtos_vfs_file_t zrtos_vfs_file__index[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_file.h:28
zrtos_vfs_dentry_t * zrtos_vfs_dentry__lookup(zrtos_vfs_dentry_t *thiz, char *path)
Definition: vfs_dentry.h:126
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_file__read()

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 at line 86 of file vfs_file.h.

93  {
94  return file->dentry ? ZRTOS_VFS_PLUGIN__INVOKE(
95  file->dentry->inode.plugin
97  ,file
98  ,path
99  ,buffer
100  ,len
101  ,offset
102  ,ret
103  ) : ZRTOS_ERROR__BADF;
104 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
#define ZRTOS_VFS_PLUGIN_OPERATION__READ
Definition: vfs_plugin.h:79
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
zrtos_vfs_plugin_t * plugin
Definition: vfs_inode.h:18
Bad file number.
Definition: error.h:33
Here is the caller graph for this function:

◆ zrtos_vfs_file__set_data()

void zrtos_vfs_file__set_data ( zrtos_vfs_file_t thiz,
void *  ctx 
)

Definition at line 195 of file vfs_file.h.

195  {
196  thiz->ctx = ctx;
197 }

◆ zrtos_vfs_file__set_inode_data()

void zrtos_vfs_file__set_inode_data ( zrtos_vfs_file_t thiz,
void *  ctx 
)

Definition at line 187 of file vfs_file.h.

187  {
188  thiz->dentry->inode.ctx = ctx;
189 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19

◆ zrtos_vfs_file__set_offset()

void zrtos_vfs_file__set_offset ( zrtos_vfs_file_t thiz,
zrtos_vfs_offset_t  offset 
)

Definition at line 203 of file vfs_file.h.

203  {
204  thiz->offset = offset;
205 }
zrtos_vfs_offset_t offset
Definition: vfs_file.h:20
Here is the caller graph for this function:

◆ zrtos_vfs_file__write()

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 at line 106 of file vfs_file.h.

113  {
114  return file->dentry ? ZRTOS_VFS_PLUGIN__INVOKE(
115  file->dentry->inode.plugin
117  ,file
118  ,path
119  ,buffer
120  ,len
121  ,offset
122  ,ret
123  ) : ZRTOS_ERROR__BADF;
124 }
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
#define ZRTOS_VFS_PLUGIN_OPERATION__WRITE
Definition: vfs_plugin.h:80
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
zrtos_vfs_dentry_t * dentry
Definition: vfs_file.h:19
zrtos_vfs_plugin_t * plugin
Definition: vfs_inode.h:18
Bad file number.
Definition: error.h:33
Here is the caller graph for this function:

Variable Documentation

◆ zrtos_vfs_file__index

Definition at line 28 of file vfs_file.h.