agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
vfs_dentry.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 ykat UG (haftungsbeschraenkt) - All Rights Reserved
3  *
4  * Permission for non-commercial use is hereby granted,
5  * free of charge, without warranty of any kind.
6  */
7 #ifndef ZRTOS_VFS_DENTRY_H
8 #define ZRTOS_VFS_DENTRY_H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 
14 #include <zrtos/str.h>
15 #include <zrtos/types.h>
16 #include <zrtos/clist.h>
17 #include <zrtos/vfs_inode.h>
18 
20 
21 typedef struct _zrtos_vfs_dentry_t{
23  char *name;
26  size_t count;
28 
30 
32  zrtos_vfs_dentry_t *thiz
33  ,char *name
35 ){
37  thiz->name = name;
38  thiz->parent = parent;
40  &thiz->inode
41  ,ZRTOS_VFS_PLUGIN(null)
42  ,0
43  );
44  thiz->count = 0;
45 
46  zrtos_clist__push(&zrtos_vfs_dentry__index,&thiz->node);
47 
48  return true;
49 }
50 
52  //return ZRTOS_VFS_PLUGIN_TYPE__FILESYSTEM == node->inode.plugin->type;
53  return false;
54 }
55 /*
56 zrtos_vfs_dentry_t *zrtos_vfs_dentry__get_first_node(){
57  zrtos_clist_node_t *node = zrtos_clist__get_first_node(&zrtos_vfs_dentry__index);
58  return zrtos_types__get_container_of_ex(node,zrtos_vfs_dentry_t,node);
59 }
60 
61 zrtos_vfs_dentry_t *zrtos_vfs_dentry__get_next_node(zrtos_vfs_dentry_t *thiz){
62  zrtos_clist_node_t *node = zrtos_clist_node__get_next_node(&thiz->node);
63  return zrtos_types__get_container_of(node,zrtos_vfs_dentry_t,node);
64 }
65 */
68  bool (*callback)(zrtos_vfs_dentry_t *node,void *arg);
69  void *callback_arg;
70  bool (*filter)(zrtos_vfs_dentry_t *node,void *arg);
71  void *filter_arg;
73 
75  bool ret = true;
77  node
79  ,node
80  );
83  ,arg
84  );
85  if(args->parent == dentry->parent
86  && args->filter(dentry,args->filter_arg)){
87  ret = args->callback(dentry,args->callback_arg);
88  }
89  return ret;
90 }
91 
93  zrtos_vfs_dentry_t *thiz
94  ,bool (*callback)(zrtos_vfs_dentry_t *node,void *arg)
95  ,void *callback_arg
96  ,bool (*filter)(zrtos_vfs_dentry_t *node,void *arg)
97  ,void *filter_arg
98 ){
100  .parent = thiz
101  ,.callback = callback
102  ,.callback_arg = callback_arg
103  ,.filter = filter
104  ,.filter_arg = filter_arg
105  };
107  &zrtos_vfs_dentry__index
109  ,&args
110  );
111 }
112 
114  zrtos_vfs_dentry_t *thiz
115  ,void *arg
116 ){
117  return 0 == zrtos_str__cmp(thiz->name,(char*)arg);
118 }
119 
121  zrtos_vfs_dentry_t **args = (zrtos_vfs_dentry_t **)arg;
122  *args = node;
123  return false;
124 }
125 
127  zrtos_vfs_dentry_t *thiz
128  ,char *path
129 ){
130  char *token;
131  zrtos_vfs_dentry_t *ret = 0;
132 
133  while((token = zrtos_str__tok_r(path,"/", &path))){
135  thiz
137  ,&thiz
139  ,token
140  );
141  if(thiz){
142  ret = thiz;
143  }else{
145  ret = 0;
146  }
147  break;
148  }
149  }
150 
151  return ret;
152 }
153 
155  zrtos_vfs_dentry_t *thiz
156  ,zrtos_vfs_plugin_t *plugin
157  ,void *inode_ctx
158 ){
160  if(0 == thiz->count){
162  &thiz->inode
163  ,plugin
164  ,inode_ctx
165  );
167  plugin
169  ,thiz
170  );
171  }
172  return ret;
173 }
174 
176  zrtos_vfs_dentry_t *thiz
177 ){
179  if(0 == thiz->count){
181  thiz->inode.plugin
183  ,thiz
184  );
185  if(zrtos_error__is_success(ret)){
187  }
188  }
189  return ret;
190 }
191 
193  thiz->inode.ctx = ctx;
194 }
195 
197  return thiz->inode.ctx;
198 }
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 #endif
#define ZRTOS_CAST(type, value)
Definition: cast.h:18
zrtos_clist_node_t node
Definition: vfs_dentry.h:22
zrtos_vfs_inode_t inode
Definition: vfs_dentry.h:25
bool(* filter)(zrtos_vfs_dentry_t *node, void *arg)
Definition: vfs_dentry.h:70
void zrtos_vfs_dentry__each_child(zrtos_vfs_dentry_t *thiz, bool(*callback)(zrtos_vfs_dentry_t *node, void *arg), void *callback_arg, bool(*filter)(zrtos_vfs_dentry_t *node, void *arg), void *filter_arg)
Definition: vfs_dentry.h:92
#define ZRTOS_VFS_PLUGIN__INVOKE(thiz, operation,...)
Definition: vfs_plugin.h:139
#define ZRTOS_VFS_PLUGIN(name)
Definition: vfs_plugin.h:136
void zrtos_vfs_inode__deinit(zrtos_vfs_inode_t *thiz)
Definition: vfs_inode.h:32
static bool zrtos_vfs_dentry__lookup_callback_cb(zrtos_vfs_dentry_t *node, void *arg)
Definition: vfs_dentry.h:120
bool zrtos_vfs_dentry__each_child_filter_name_cb(zrtos_vfs_dentry_t *thiz, void *arg)
Definition: vfs_dentry.h:113
zrtos_clist_t zrtos_vfs_dentry__index
Definition: vfs_dentry.h:29
zrtos_error_t zrtos_vfs_dentry__mount(zrtos_vfs_dentry_t *thiz, zrtos_vfs_plugin_t *plugin, void *inode_ctx)
Definition: vfs_dentry.h:154
void zrtos_vfs_dentry__set_inode_data(zrtos_vfs_dentry_t *thiz, void *ctx)
Definition: vfs_dentry.h:192
bool(* callback)(zrtos_vfs_dentry_t *node, void *arg)
Definition: vfs_dentry.h:68
zrtos_vfs_plugin_t * plugin
Definition: vfs_inode.h:18
zrtos_error_t zrtos_vfs_dentry__umount(zrtos_vfs_dentry_t *thiz)
Definition: vfs_dentry.h:175
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
#define ZRTOS_VFS_PLUGIN_OPERATION__MOUNT
Definition: vfs_plugin.h:77
bool zrtos_vfs_dentry__init(zrtos_vfs_dentry_t *thiz, char *name, struct _zrtos_vfs_dentry_t *parent)
Definition: vfs_dentry.h:31
int zrtos_str__cmp(char *a, char *b)
Definition: str.h:33
void * zrtos_vfs_dentry__get_inode_data(zrtos_vfs_dentry_t *thiz)
Definition: vfs_dentry.h:196
#define zrtos_types__get_container_of_ex(ptr, type, member)
Definition: types.h:75
char * zrtos_str__tok_r(char *s, const char *delim, char **save_ptr)
Definition: str.h:254
zrtos_vfs_dentry_t * zrtos_vfs_dentry__lookup(zrtos_vfs_dentry_t *thiz, char *path)
Definition: vfs_dentry.h:126
Device or resource busy.
Definition: error.h:40
struct _zrtos_vfs_dentry_t * parent
Definition: vfs_dentry.h:24
bool zrtos_clist__push(zrtos_clist_t *thiz, zrtos_clist_node_t *node)
Definition: clist.h:85
bool zrtos_clist_node__init(zrtos_clist_node_t *thiz)
Definition: clist.h:33
static bool zrtos_vfs_dentry__each_child_cb(zrtos_clist_node_t *node, void *arg)
Definition: vfs_dentry.h:74
bool zrtos_vfs_inode__init(zrtos_vfs_inode_t *thiz, zrtos_vfs_plugin_t *plugin, void *ctx)
Definition: vfs_inode.h:22
struct _zrtos_vfs_dentry__each_child_cb_inode_t zrtos_vfs_dentry__each_child_cb_inode_t
zrtos_error_t
Definition: error.h:20
bool zrtos_vfs_dentry__is_filesystem(zrtos_vfs_dentry_t *node)
Definition: vfs_dentry.h:51
void zrtos_clist__each(zrtos_clist_t *thiz, bool(*callback)(zrtos_clist_node_t *node, void *arg), void *arg)
Definition: clist.h:143
struct _zrtos_vfs_dentry_t zrtos_vfs_dentry_t
#define ZRTOS_VFS_PLUGIN_OPERATION__UMOUNT
Definition: vfs_plugin.h:78