SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /sos/fs.h (Article 9.5) and /sos/fs.h (Article 9)


001 /* Copyright (C) 2005,2006 David Decotigny     !! 001 /* Copyright (C) 2005      David Decotigny
002    Copyright (C) 2000-2005 The KOS Team (Thoma    002    Copyright (C) 2000-2005 The KOS Team (Thomas Petazzoni, David
003                            Decotigny, Julien M    003                            Decotigny, Julien Munier)
004                                                   004 
005    This program is free software; you can redi    005    This program is free software; you can redistribute it and/or
006    modify it under the terms of the GNU Genera    006    modify it under the terms of the GNU General Public License
007    as published by the Free Software Foundatio    007    as published by the Free Software Foundation; either version 2
008    of the License, or (at your option) any lat    008    of the License, or (at your option) any later version.
009                                                   009    
010    This program is distributed in the hope tha    010    This program is distributed in the hope that it will be useful,
011    but WITHOUT ANY WARRANTY; without even the     011    but WITHOUT ANY WARRANTY; without even the implied warranty of
012    MERCHANTABILITY or FITNESS FOR A PARTICULAR    012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013    GNU General Public License for more details    013    GNU General Public License for more details.
014                                                   014    
015    You should have received a copy of the GNU     015    You should have received a copy of the GNU General Public License
016    along with this program; if not, write to t    016    along with this program; if not, write to the Free Software
017    Foundation, Inc., 59 Temple Place - Suite 3    017    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
018    USA.                                           018    USA. 
019 */                                                019 */
020 #ifndef _SOS_FS_H_                                020 #ifndef _SOS_FS_H_
021 #define _SOS_FS_H_                                021 #define _SOS_FS_H_
022                                                   022 
023                                                   023 
024 /**                                               024 /**
025  * @file fs.h                                     025  * @file fs.h
026  *                                                026  *
027  * (Virtual) Filesystem management.               027  * (Virtual) Filesystem management.
028  *                                                028  *
029  * SOS provides a complete Unix-like file syst    029  * SOS provides a complete Unix-like file system service. Supported
030  * features of this service are:                  030  * features of this service are:
031  *   - mountpoints                                031  *   - mountpoints
032  *   - generic file system support (FS) throug    032  *   - generic file system support (FS) through object-oriented
033  *     specialization (so-called VFS)             033  *     specialization (so-called VFS)
034  *   - hard & symbolic links                      034  *   - hard & symbolic links
035  *   - regular files and directories              035  *   - regular files and directories
036  *   - block and character device special file    036  *   - block and character device special files (from article 9 onward)
037  *   - file mapping                               037  *   - file mapping
038  *   - basic permission management ("rwx" only    038  *   - basic permission management ("rwx" only, no notion of owner)
039  *   - chroot                                     039  *   - chroot
040  *   - separation of disk node and namespace n    040  *   - separation of disk node and namespace notions allowing hard links
041  *     and to move/rename/remove files or dire    041  *     and to move/rename/remove files or directories that are in use
042  *   - basic FS interface (open/read/seek/crea    042  *   - basic FS interface (open/read/seek/creat/mkdir/rename/link
043  *     / symlink/chmod/mount/fcntl/ioctl...)      043  *     / symlink/chmod/mount/fcntl/ioctl...)
044  *   - deferred writes (ie file caching). @see    044  *   - deferred writes (ie file caching). @see sync(3)
045  *                                                045  *
046  * Among the unsupported features:                046  * Among the unsupported features:
047  *   - no user-based permission (uid/gid, ACLS    047  *   - no user-based permission (uid/gid, ACLS)
048  *   - no modification / access time accountin    048  *   - no modification / access time accounting
049  *   - no Fifo/socket special files (yet)         049  *   - no Fifo/socket special files (yet)
050  *   - no generic support library for common f    050  *   - no generic support library for common fcntl commands
051  *     (F_SETOWN/GETLEASE/NOTIFY, etc.)           051  *     (F_SETOWN/GETLEASE/NOTIFY, etc.)
052  *   - no flock-style functions                   052  *   - no flock-style functions
053  *                                                053  *
054  * Rationale                                      054  * Rationale
055  * =========                                      055  * =========
056  * The VFS layer is based on 3 central concept    056  * The VFS layer is based on 3 central concepts:
057  *                                                057  *
058  *  - The meta-information for each file store    058  *  - The meta-information for each file stored on disk: size,
059  *    permissions, ... (struct sos_fs_node for    059  *    permissions, ... (struct sos_fs_node for SOS, inode for Unix)
060  *                                                060  *
061  *    It is sufficient to know where this meta    061  *    It is sufficient to know where this meta-information is located
062  *    on disk (a simple sector number most of     062  *    on disk (a simple sector number most of the time) to build the
063  *    corresponding struct sos_fs_node into me    063  *    corresponding struct sos_fs_node into memory and to retrieve the
064  *    data of the file from the disk              064  *    data of the file from the disk
065  *                                                065  *
066  *    For example, consider that we know a sec    066  *    For example, consider that we know a sector that holds the meta
067  *    information is located at sector 64589 o    067  *    information is located at sector 64589 on disk. By retrieving
068  *    this meta information directly from disk    068  *    this meta information directly from disk, we can build the
069  *    struct sos_fs_node, which would (for exa    069  *    struct sos_fs_node, which would (for example) tell that the
070  *    corresponding file spans (for example) o    070  *    corresponding file spans (for example) over sectors 4345, 5645,
071  *    4539 and 6575, is 1.7kB long                071  *    4539 and 6575, is 1.7kB long
072  *                                                072  *
073  *    Everything is stored this way on the dis    073  *    Everything is stored this way on the disk, even the
074  *    directories. From the disk contents' poi    074  *    directories. From the disk contents' point of view, a directory
075  *    is simply a file whose contents represen    075  *    is simply a file whose contents represent a list of mappings
076  *    "name" -> meta-information location         076  *    "name" -> meta-information location
077  *                                                077  *
078  *  - One or many nodes in the file hierarchy     078  *  - One or many nodes in the file hierarchy pointing to this data
079  *    (struct sos_fs_nscache_node for SOS, str    079  *    (struct sos_fs_nscache_node for SOS, struct dentry for Linux). This
080  *    tells that the entry "toto" in directory    080  *    tells that the entry "toto" in directory "/home/zorglub"
081  *    corresponds to the given struct sos_fs_n    081  *    corresponds to the given struct sos_fs_node
082  *                                                082  *
083  *    Actually, with the struct sos_fs_node ab    083  *    Actually, with the struct sos_fs_node above, we can reach any
084  *    file in the system. However, dealing wit    084  *    file in the system. However, dealing with mountpoints requires
085  *    an intermediary data structure because a    085  *    an intermediary data structure because a directory on a disk
086  *    cannot make reference to children struct    086  *    cannot make reference to children struct sos_fs_node on other
087  *    disk. This is one of the reasons why the    087  *    disk. This is one of the reasons why there is this struct
088  *    sos_fs_nscache_node. Another reason is t    088  *    sos_fs_nscache_node. Another reason is that we kind-of "cache" the
089  *    most used struct sos_fs_node: those that    089  *    most used struct sos_fs_node: those that lead from the global
090  *    root ("/") to the files and directories     090  *    root ("/") to the files and directories currently being used
091  *    (hence the name "nscache" for "namespace    091  *    (hence the name "nscache" for "namespace cache"). This speeds-up
092  *    the path-resolving process (aka "lookup"    092  *    the path-resolving process (aka "lookup"), as the most-used path
093  *    are already in-memory and the struct sos    093  *    are already in-memory and the struct sos_fs_node are already
094  *    in-memory too.                              094  *    in-memory too.
095  *                                                095  *
096  *    A struct sos_fs_nscache_node can have at    096  *    A struct sos_fs_nscache_node can have at most 1 parent (the ".."
097  *    entry). It can also have 0 parent in cas    097  *    entry). It can also have 0 parent in case the node is being used
098  *    by a process (file is opened or mapped),    098  *    by a process (file is opened or mapped), but the file is
099  *    actually "removed", ie un-reachable from    099  *    actually "removed", ie un-reachable from any directory.
100  *                                                100  *
101  *    Many such structures can reference the s    101  *    Many such structures can reference the same underlying struct
102  *    sos_fs_node, which enables the support o    102  *    sos_fs_node, which enables the support of "hard links".
103  *                                                103  *
104  *  - The "opened file" strucures. They store     104  *  - The "opened file" strucures. They store the information
105  *    pertaining to a particular usage of a fi    105  *    pertaining to a particular usage of a file. The most important
106  *    thing they store is the "file pointer",     106  *    thing they store is the "file pointer", which holds the
107  *    location in the file where the next read    107  *    location in the file where the next read/write operation should
108  *    start                                       108  *    start
109  *                                                109  *
110  *    Each process has at least 2 such opened     110  *    Each process has at least 2 such opened files: its "current
111  *    working directory" (RTFM chdir) and its     111  *    working directory" (RTFM chdir) and its "process root" (RTFM
112  *    chroot). Those are heritated across fork    112  *    chroot). Those are heritated across fork() and can be changed by
113  *    appropriate syscalls (resp. chdir/chroot    113  *    appropriate syscalls (resp. chdir/chroot). The main "root" of
114  *    the system is the process root of the "i    114  *    the system is the process root of the "init" process. The usual
115  *    opened files (think of open() and opendi    115  *    opened files (think of open() and opendir()) are stored in the
116  *    file descriptor array (fds[]). This is t    116  *    file descriptor array (fds[]). This is the index in this array
117  *    that is commonly called a "file descript    117  *    that is commonly called a "file descriptor".
118  *                                                118  *
119  *                                                119  *
120  * The whole VFS layer comprises a series of o    120  * The whole VFS layer comprises a series of objects that can be
121  * specialized to implement different FS suppo    121  * specialized to implement different FS support (fat, ext2, ffs, ...):
122  *                                                122  *
123  *  - The notion of "file system manager", whi    123  *  - The notion of "file system manager", which basically is a
124  *    container to a FS name (eg "FAT", "EXT2"    124  *    container to a FS name (eg "FAT", "EXT2", etc...) and a series of
125  *    functions responsible for initializing a    125  *    functions responsible for initializing a particular "mounting" of
126  *    a FS (the "mount" method). This is SOS's    126  *    a FS (the "mount" method). This is SOS's struct sos_fs_manager_type
127  *                                                127  *
128  *  - The notion of "file system instance" whi    128  *  - The notion of "file system instance" which contains the data
129  *    proper to a particular mounting of an FS    129  *    proper to a particular mounting of an FS. Its most important job
130  *    is to allocate new struct sos_fs_node on    130  *    is to allocate new struct sos_fs_node on disk, or to retrieve the
131  *    meta-information (ie struct sos_fs_node)    131  *    meta-information (ie struct sos_fs_node) located at the given
132  *    location on disk. This is roughly THE pr    132  *    location on disk. This is roughly THE primary physical interface
133  *    between the VFS and the disks. This is S    133  *    between the VFS and the disks. This is SOS's struct
134  *    sos_fs_manager_instance, aka the Linux's    134  *    sos_fs_manager_instance, aka the Linux's superblock
135  *                                                135  *
136  *    For each struct sos_fs_node that it allo    136  *    For each struct sos_fs_node that it allocates, or that is loads
137  *    from disk into memory, this "instance ma    137  *    from disk into memory, this "instance manager" is responsible
138  *    for inidicating the functions that imple    138  *    for inidicating the functions that implement the FS-dedicated
139  *    routine such as read/write/mmap/ioctl/..    139  *    routine such as read/write/mmap/ioctl/... for this precise node.
140  *                                                140  *
141  *    The nodes (struct sos_fs_node) of a stru    141  *    The nodes (struct sos_fs_node) of a struct
142  *    sos_fs_manager_instance that are current    142  *    sos_fs_manager_instance that are currently loaded in memory are
143  *    stored in a hash-table. The key of this     143  *    stored in a hash-table. The key of this map is the location of the
144  *    meta-information on disk. That way, it i    144  *    meta-information on disk. That way, it is very fast to look for
145  *    the given meta-information whose locatio    145  *    the given meta-information whose location on disk is knows: if
146  *    it has already been loaded into memory,     146  *    it has already been loaded into memory, its memory address is
147  *    quickly resolved thanks to this hash tab    147  *    quickly resolved thanks to this hash table.
148  */                                               148  */
149                                                   149 
150 #include <sos/types.h>                            150 #include <sos/types.h>
151 #include <sos/errno.h>                            151 #include <sos/errno.h>
152 #include <sos/hash.h>                             152 #include <sos/hash.h>
153 #include <sos/umem_vmm.h>                         153 #include <sos/umem_vmm.h>
154                                                   154 
155 /* Forward declarations (structures defined in    155 /* Forward declarations (structures defined in this file) */
156 struct sos_fs_manager_type;                       156 struct sos_fs_manager_type;
157 struct sos_fs_manager_instance;                   157 struct sos_fs_manager_instance;
158 struct sos_fs_statfs;                             158 struct sos_fs_statfs;
159 struct sos_fs_node;                               159 struct sos_fs_node;
160 struct sos_fs_opened_file;                        160 struct sos_fs_opened_file;
161 struct sos_fs_stat;                               161 struct sos_fs_stat;
162                                                   162 
163 #include "fs_nscache.h"                           163 #include "fs_nscache.h"
164 #include <sos/blkdev.h>                        << 
165                                                   164 
166 /**                                               165 /**
167  * The type of filesystem object.                 166  * The type of filesystem object.
168  *                                                167  *
169  * Each struct sos_fs_node has a type. Here ar    168  * Each struct sos_fs_node has a type. Here are the supported types.
170  */                                               169  */
171 typedef enum {                                    170 typedef enum {
172   SOS_FS_NODE_REGULAR_FILE = 0x42,                171   SOS_FS_NODE_REGULAR_FILE = 0x42,
173   SOS_FS_NODE_DIRECTORY    = 0x24,                172   SOS_FS_NODE_DIRECTORY    = 0x24,
174   SOS_FS_NODE_SYMLINK      = 0x84,                173   SOS_FS_NODE_SYMLINK      = 0x84,
175   SOS_FS_NODE_DEVICE_CHAR  = 0x48,                174   SOS_FS_NODE_DEVICE_CHAR  = 0x48,
176   SOS_FS_NODE_DEVICE_BLOCK = 0x12              << 
177 } sos_fs_node_type_t;                             175 } sos_fs_node_type_t;
178                                                   176 
179                                                   177 
180 #define SOS_FS_MANAGER_NAME_MAXLEN 32             178 #define SOS_FS_MANAGER_NAME_MAXLEN 32
181 /**                                               179 /**
182  * Description of a supported Filesystem type.    180  * Description of a supported Filesystem type.
183  *                                                181  *
184  * These descriptions are listed in an interna    182  * These descriptions are listed in an internal list (see
185  * fs.c:fs_list), and each time we want to mou    183  * fs.c:fs_list), and each time we want to mount a FS, we precise a
186  * name (eg "FAT", "EXT2", ...). The VFS will     184  * name (eg "FAT", "EXT2", ...). The VFS will look for this name into
187  * the list of supported filesystem types, and    185  * the list of supported filesystem types, and, when found, call its
188  * sos_fs_manager_type::mount() method.           186  * sos_fs_manager_type::mount() method.
189  *                                                187  *
190  * New filesystem types are registered using s    188  * New filesystem types are registered using sos_fs_register_fs_type()
191  */                                               189  */
192 struct sos_fs_manager_type                        190 struct sos_fs_manager_type
193 {                                                 191 {
194   char name[SOS_FS_MANAGER_NAME_MAXLEN];          192   char name[SOS_FS_MANAGER_NAME_MAXLEN];
195                                                   193 
196   /**                                             194   /**
197    * Responsible for making sure the underlyin    195    * Responsible for making sure the underlying device (if any) really
198    * stores the correct filesystem format, for    196    * stores the correct filesystem format, for creating the hash of fs
199    * nodes and for calling sos_fs_register_fs_    197    * nodes and for calling sos_fs_register_fs_instance
200    *                                              198    *
201    * @param device May be NULL                    199    * @param device May be NULL
202    *                                              200    *
203    * @note mandatory, may block                   201    * @note mandatory, may block
204    */                                             202    */
205   sos_ret_t (*mount)(struct sos_fs_manager_typ    203   sos_ret_t (*mount)(struct sos_fs_manager_type * this,
206                      struct sos_fs_node * devi    204                      struct sos_fs_node * device,
207                      const char * args,           205                      const char * args,
208                      struct sos_fs_manager_ins    206                      struct sos_fs_manager_instance ** mounted_fs);
209                                                   207   
210   /**                                             208   /**
211    * Responsible for de-allocating the hash of    209    * Responsible for de-allocating the hash of fs nodes and for
212    * calling sos_fs_unregister_fs_instance        210    * calling sos_fs_unregister_fs_instance
213    *                                              211    *
214    * @note mandatory, may block                   212    * @note mandatory, may block
215    */                                             213    */
216   sos_ret_t (*umount)(struct sos_fs_manager_ty    214   sos_ret_t (*umount)(struct sos_fs_manager_type * this,
217                       struct sos_fs_manager_in    215                       struct sos_fs_manager_instance * mounted_fs);
218                                                   216 
219   /** Free of use */                              217   /** Free of use */
220   void * custom_data;                             218   void * custom_data;
221                                                   219 
222   /** List of filesystem instances of this typ    220   /** List of filesystem instances of this type currently mounted
223       somewhere in the system */                  221       somewhere in the system */
224   struct sos_fs_manager_instance * instances;     222   struct sos_fs_manager_instance * instances;
225                                                   223 
226   /** Linkage for the list of filesystem types    224   /** Linkage for the list of filesystem types registered in the
227       system */                                   225       system */
228   struct sos_fs_manager_type *prev, *next;        226   struct sos_fs_manager_type *prev, *next;
229 };                                                227 };
230                                                   228 
231                                                   229 
232 /**                                               230 /**
233  * Data related to a particular "mounting" of     231  * Data related to a particular "mounting" of a file system. A
234  * so-called "superblock" under Linux             232  * so-called "superblock" under Linux
235  *                                                233  *
236  * This holds the FUNDAMENTAL functions respon    234  * This holds the FUNDAMENTAL functions responsible for loading struct
237  * sos_fs_node from disk, or for allocating th    235  * sos_fs_node from disk, or for allocating thom on disk. It also
238  * holds the hash-table of struct sos_fs_node     236  * holds the hash-table of struct sos_fs_node already loaded into
239  * memory.                                        237  * memory.
240  */                                               238  */
241 struct sos_fs_manager_instance                    239 struct sos_fs_manager_instance
242 {                                                 240 {
243   /**                                             241   /**
244    * @note Publicly readable. Written only by     242    * @note Publicly readable. Written only by sos_fs_manager_type::mount()
245    */                                             243    */
246   struct sos_fs_manager_type * fs_type;           244   struct sos_fs_manager_type * fs_type;
247                                                   245 
248   /**                                             246   /**
249    * Usually, a filesystem relies on a device     247    * Usually, a filesystem relies on a device (disk, network, ram,
250    * ...) to fetch its data. This is the locat    248    * ...) to fetch its data. This is the location of the device.
251    *                                              249    *
252    * @note Publicly readable. Written only by     250    * @note Publicly readable. Written only by fs.c
253    */                                             251    */
254   struct sos_fs_node * device;                    252   struct sos_fs_node * device;
255                                                   253 
256 #define SOS_FS_MOUNT_SYNC     (1 << 0)            254 #define SOS_FS_MOUNT_SYNC     (1 << 0)
257 #define SOS_FS_MOUNT_READONLY (1 << 1)            255 #define SOS_FS_MOUNT_READONLY (1 << 1)
258 #define SOS_FS_MOUNT_NOEXEC   (1 << 2)            256 #define SOS_FS_MOUNT_NOEXEC   (1 << 2)
259   /**                                             257   /**
260    * Is this FS read-only, without EXEC file p    258    * Is this FS read-only, without EXEC file permission, write-through
261    * ? Or-red combination of the SOS_FS_MOUNT_    259    * ? Or-red combination of the SOS_FS_MOUNT_ flags
262    *                                              260    *
263    * @note Publicly readable. Written only by     261    * @note Publicly readable. Written only by fs.c
264    */                                             262    */
265   sos_ui32_t flags;                               263   sos_ui32_t flags;
266                                                   264 
267   /**                                             265   /**
268    * The namespace node that is the root of TH    266    * The namespace node that is the root of THIS file system mounting
269    *                                              267    *
270    * @note Publicly readable. Written only by     268    * @note Publicly readable. Written only by fs.c
271    */                                             269    */
272   struct sos_fs_nscache_node * root;              270   struct sos_fs_nscache_node * root;
273                                                   271 
274   /**                                             272   /**
275    * List of dirty nodes. These are the nodes     273    * List of dirty nodes. These are the nodes that need to be written
276    * back to disk. With FS supporting deferred    274    * back to disk. With FS supporting deferred-writes, the
277    * sos_fs_sync() function will use this list    275    * sos_fs_sync() function will use this list to flush the dirty
278    * nodes back to disk.                          276    * nodes back to disk.
279    *                                              277    *
280    * @note Reserved to fs.c                       278    * @note Reserved to fs.c
281    */                                             279    */
282   struct sos_fs_node * dirty_nodes;               280   struct sos_fs_node * dirty_nodes;
283                                                   281 
284   /**                                             282   /**
285    * Build a fresh new FS node at the given lo    283    * Build a fresh new FS node at the given location. This implies
286    * the allocation of a new sos_fs_node struc    284    * the allocation of a new sos_fs_node structure in memory
287    *                                              285    *
288    * @note Mandatory, may block. Appropriate l    286    * @note Mandatory, may block. Appropriate locking MUST be implemented
289    */                                             287    */
290   sos_ret_t (*fetch_node_from_disk)(struct sos    288   sos_ret_t (*fetch_node_from_disk)(struct sos_fs_manager_instance * this,
291                                     sos_ui64_t    289                                     sos_ui64_t storage_location,
292                                     struct sos    290                                     struct sos_fs_node ** result);
293                                                   291 
294   /**                                             292   /**
295    * Build a fresh new FS node ON THE DISK of     293    * Build a fresh new FS node ON THE DISK of the given type (dir,
296    * plain file, symlink, ...), completely emp    294    * plain file, symlink, ...), completely empty ; return a newly
297    * allocated IN-MEMORY node structure repres    295    * allocated IN-MEMORY node structure representing it
298    *                                              296    *
299    * @param open_creat_flags is the open_flags    297    * @param open_creat_flags is the open_flags parameter passed to
300    * sos_fs_open() when O_CREAT is set. 0 when    298    * sos_fs_open() when O_CREAT is set. 0 when allocated trough
301    * creat/mkdir/mknod/symlink                    299    * creat/mkdir/mknod/symlink
302    *                                              300    *
303    * @note Mandatory, may block. Appropriate l    301    * @note Mandatory, may block. Appropriate locking MUST be implemented
304    */                                             302    */
305   sos_ret_t (*allocate_new_node)(struct sos_fs    303   sos_ret_t (*allocate_new_node)(struct sos_fs_manager_instance * this,
306                                  sos_fs_node_t    304                                  sos_fs_node_type_t type,
307                                  const struct     305                                  const struct sos_process * creator,
308                                  sos_ui32_t ac    306                                  sos_ui32_t access_rights,
309                                  sos_ui32_t op    307                                  sos_ui32_t open_creat_flags,
310                                  struct sos_fs    308                                  struct sos_fs_node ** result);
311                                                   309 
312   /**                                             310   /**
313    * Return filesystem status (RTFM df)           311    * Return filesystem status (RTFM df)
314    *                                              312    *
315    * @note Optional, may block. Appropriate lo    313    * @note Optional, may block. Appropriate locking MUST be implemented
316    */                                             314    */
317   sos_ret_t (*statfs)(struct sos_fs_manager_in    315   sos_ret_t (*statfs)(struct sos_fs_manager_instance * this,
318                       struct sos_fs_statfs * r    316                       struct sos_fs_statfs * result);
319                                                   317 
320   /**                                             318   /**
321    * Comparison callback called when looking f    319    * Comparison callback called when looking for file/dirs in the
322    * namespace cache. Normally, a usual lexico    320    * namespace cache. Normally, a usual lexicographical comparison is
323    * done (when this function points to NULL).    321    * done (when this function points to NULL). But for some FS, it
324    * might be useful to use another comparison    322    * might be useful to use another comparison function (eg for
325    * case-insensitive FS)                         323    * case-insensitive FS)
326    *                                              324    *
327    * @note Optional (may be NULL), must NOT bl    325    * @note Optional (may be NULL), must NOT block
328    */                                             326    */
329   sos_bool_t (*nsnode_same_name)(const char *     327   sos_bool_t (*nsnode_same_name)(const char * name1, sos_ui16_t namelen1,
330                                  const char *     328                                  const char * name2, sos_ui16_t namelen2);
331                                                   329 
332   /**                                             330   /**
333    * Hash table of the struct sos_fs_node of t    331    * Hash table of the struct sos_fs_node of this filesystem instance
334    * loaded in memory: key=storage_location, e    332    * loaded in memory: key=storage_location, element=sos_fs_node
335    */                                             333    */
336   struct sos_hash_table * nodecache;              334   struct sos_hash_table * nodecache;
337                                                   335 
338   /**                                             336   /**
339    * Unique identifier of this FS (used in syn    337    * Unique identifier of this FS (used in sync method, updated by
340    * fs.c). This enables sync_all_fs to be res    338    * fs.c). This enables sync_all_fs to be resilient to mount/umount
341    * and (un)register_fs_type/instance            339    * and (un)register_fs_type/instance
342    */                                             340    */
343   sos_ui64_t uid;                                 341   sos_ui64_t uid;
344                                                   342 
345   void * custom_data;                             343   void * custom_data;
346                                                   344 
347   /** Linkage for the list of instances for th    345   /** Linkage for the list of instances for the underlying fs type */
348   struct sos_fs_manager_instance * prev, * nex    346   struct sos_fs_manager_instance * prev, * next;
349 };                                                347 };
350                                                   348 
351                                                   349 
352 /**                                               350 /**
353  * The CENTRAL data structure of the whole thi    351  * The CENTRAL data structure of the whole thing. A so-called "inode"
354  *                                                352  *
355  * This represents the meta-information relate    353  * This represents the meta-information related to a file on disk: its
356  * permission, where its data is located. Actu    354  * permission, where its data is located. Actually, in SOS, these
357  * information are not stored in this structur    355  * information are not stored in this structure. Instead, we define a
358  * series of methods in this structure that MU    356  * series of methods in this structure that MUST be implemented by the
359  * FS and that realize the higher level operat    357  * FS and that realize the higher level operations needed by the
360  * OS. These operations will rely on the meta-    358  * OS. These operations will rely on the meta-information that the FS
361  * code MUST define and manage by itself (henc    359  * code MUST define and manage by itself (hence the
362  * sos_fs_node::custom_data field).               360  * sos_fs_node::custom_data field).
363  */                                               361  */
364 struct sos_fs_node                                362 struct sos_fs_node
365 {                                                 363 {
366   /**                                             364   /**
367    * An struct sos_fs_node always belong to ex    365    * An struct sos_fs_node always belong to exactly ONE file system
368    */                                             366    */
369   struct sos_fs_manager_instance * fs;            367   struct sos_fs_manager_instance * fs;
370                                                   368 
371   /**                                             369   /**
372    * The so-called "inode": location of this n    370    * The so-called "inode": location of this node inside the FS
373    * instance. Updated by struct                  371    * instance. Updated by struct
374    * sos_fs_manager_instance::fetch_node_from_    372    * sos_fs_manager_instance::fetch_node_from_disk()
375    */                                             373    */
376   sos_ui64_t storage_location;                    374   sos_ui64_t storage_location;
377                                                   375 
378   /**                                             376   /**
379    * Number of ON-DISK links to this node.        377    * Number of ON-DISK links to this node.
380    *                                              378    *
381    * - For everything but directories: the num    379    * - For everything but directories: the number of hard links to the file
382    * - For directories: 1 + the number of chil    380    * - For directories: 1 + the number of children nodes
383    *                                              381    *
384    * @note Publicly readable. Written only by     382    * @note Publicly readable. Written only by
385    * sos_fs_node_ops_dir::link() and sos_fs_no    383    * sos_fs_node_ops_dir::link() and sos_fs_node_ops_dir::unlink()
386    */                                             384    */
387   sos_count_t ondisk_lnk_cnt;                     385   sos_count_t ondisk_lnk_cnt;
388                                                   386 
389   /**                                             387   /**
390    * Number of IN-MEMORY nscache_nodes referen    388    * Number of IN-MEMORY nscache_nodes referencing this FS node.
391    *                                              389    *
392    * Corresponds to the number of struct sos_f    390    * Corresponds to the number of struct sos_fs_nscache_node pointing
393    * to this node. This could be as much as on    391    * to this node. This could be as much as ondisk_lnk_cnt + 1, but is
394    * usually less                                 392    * usually less
395    *                                              393    *
396    * @note Reserved to fs.c                       394    * @note Reserved to fs.c
397    */                                             395    */
398   sos_count_t inmem_ref_cnt;                      396   sos_count_t inmem_ref_cnt;
399                                                   397 
400   /**                                             398   /**
401    * Directory, symlink, ...                      399    * Directory, symlink, ...
402    *                                              400    *
403    * @see sos_fs_node_type_t                      401    * @see sos_fs_node_type_t
404    *                                              402    *
405    * @note Publicly readable. Written only by     403    * @note Publicly readable. Written only by fs.c
406    */                                             404    */
407   sos_fs_node_type_t type;                        405   sos_fs_node_type_t type;
408                                                   406 
409 #define SOS_FS_READABLE          00400            407 #define SOS_FS_READABLE          00400
410 #define SOS_FS_WRITABLE          00200            408 #define SOS_FS_WRITABLE          00200
411 #define SOS_FS_EXECUTABLE        00100            409 #define SOS_FS_EXECUTABLE        00100
412   /**                                             410   /**
413    * read/write, ... @see the SOS_FS_*ABLE fla    411    * read/write, ... @see the SOS_FS_*ABLE flags
414    * @note Publicly readable. Written only by     412    * @note Publicly readable. Written only by fs.c
415    */                                             413    */
416   sos_ui32_t access_rights;                       414   sos_ui32_t access_rights;
417                                                   415 
418   /**                                             416   /**
419    * @note Reserved to fs.c                       417    * @note Reserved to fs.c
420    */                                             418    */
421   sos_bool_t dirty;                               419   sos_bool_t dirty;
422                                                   420 
423   /**                                             421   /**
424    * Incremented each time one of the opened f    422    * Incremented each time one of the opened files for this node is
425    * modified                                     423    * modified
426    * @note Publicly readable. Written only by     424    * @note Publicly readable. Written only by fs.c
427    */                                             425    */
428   sos_lcount_t generation;                        426   sos_lcount_t generation;
429                                                   427 
430   /**                                             428   /**
431    * @note Available only for device files (ch    429    * @note Available only for device files (char/block)
432    * @note Publicly readable. Written only by     430    * @note Publicly readable. Written only by
433    * sos_fs_manager_instance::fetch_node_from_    431    * sos_fs_manager_instance::fetch_node_from_disk() and mknod()
434    */                                             432    */
435   struct sos_fs_dev_id_t                          433   struct sos_fs_dev_id_t
436   {                                               434   {
437     sos_ui32_t device_class;    /**< aka "majo    435     sos_ui32_t device_class;    /**< aka "major" */
438     sos_ui32_t device_instance; /**< aka "mino    436     sos_ui32_t device_instance; /**< aka "minor" */
439   } dev_id;                                       437   } dev_id;
440                                                   438 
441   /** Operations common to all node types */      439   /** Operations common to all node types */
442   struct sos_fs_node_ops_file  *ops_file;         440   struct sos_fs_node_ops_file  *ops_file;
443                                                   441 
444   /** Operations specific to some node types *    442   /** Operations specific to some node types */
445   union                                           443   union
446   {                                               444   {
447     /** when type == SOS_FS_NODE_DIRECTORY */     445     /** when type == SOS_FS_NODE_DIRECTORY */
448     struct sos_fs_node_ops_dir      *ops_dir;     446     struct sos_fs_node_ops_dir      *ops_dir;
449                                                   447 
450     /**                                        << 
451      * when type == SOS_FS_NODE_DEVICE_BLOCK   << 
452      * The FS node has a link to some data per << 
453      * not to any special operations           << 
454      * @see blkdev.c for a definition of this  << 
455      */                                        << 
456     struct sos_blockdev_instance *block_device << 
457                                                << 
458     /** when type == SOS_FS_NODE_SYMLINK */       448     /** when type == SOS_FS_NODE_SYMLINK */
459     struct sos_fs_node_ops_symlink  *ops_symli    449     struct sos_fs_node_ops_symlink  *ops_symlink;
460   }; /* Anonymous union (gcc extension) */        450   }; /* Anonymous union (gcc extension) */
461                                                   451 
462                                                   452 
463   /**                                             453   /**
                                                   >> 454    * Flush any change to disk
                                                   >> 455    *
                                                   >> 456    * @note Mandatory, may block. Appropriate locking MUST be implemented
                                                   >> 457    */
                                                   >> 458   sos_ret_t (*sync)(struct sos_fs_node *this);
                                                   >> 459 
                                                   >> 460 
                                                   >> 461   /**
464    * Simply free this FS node from the kernel     462    * Simply free this FS node from the kernel memory: it does NOT
465    * mean that the corresponding on-disk node     463    * mean that the corresponding on-disk node is free ! Actually, the
466    * corresponding ON-DISK node is free iff on    464    * corresponding ON-DISK node is free iff ondisk_lnk_cnt == 0. No
467    * need to sync anything to disk, as the VFS    465    * need to sync anything to disk, as the VFS will sync the node
468    * before calling this method                   466    * before calling this method
469    *                                              467    *
470    * @note Mandatory, may block, no special lo    468    * @note Mandatory, may block, no special locking needed
471    */                                             469    */
472   sos_ret_t (*destructor)(struct sos_fs_node *    470   sos_ret_t (*destructor)(struct sos_fs_node * this);
473                                                   471 
474   /**                                             472   /**
475    * Called when a process opens the node         473    * Called when a process opens the node
476    *                                              474    *
477    * @note Mandatory, may block. Appropriate l    475    * @note Mandatory, may block. Appropriate locking MUST be implemented
478    * @note FS-specific EXCPET for device speci    476    * @note FS-specific EXCPET for device special files (char &
479    * block) because they are handled in an uni    477    * block) because they are handled in an uniform way by the
480    * chardev/blockdev subsystems                  478    * chardev/blockdev subsystems
481    * @note As a consequence, FS code can safel    479    * @note As a consequence, FS code can safely assume that "this" is
482    * never a character or block device            480    * never a character or block device
483    */                                             481    */
484   sos_ret_t (*new_opened_file)(struct sos_fs_n    482   sos_ret_t (*new_opened_file)(struct sos_fs_node * this,
485                                const struct so    483                                const struct sos_process * owner,
486                                sos_ui32_t open    484                                sos_ui32_t open_flags,
487                                struct sos_fs_o    485                                struct sos_fs_opened_file ** result_of);
488                                                   486 
489   /**                                             487   /**
490    * Called when a process opens the node         488    * Called when a process opens the node
491    *                                              489    *
492    * @note Mandatory, may block. Appropriate l    490    * @note Mandatory, may block. Appropriate locking MUST be implemented
493    * @note FS-specific EXCEPT for device speci    491    * @note FS-specific EXCEPT for device special files (char &
494    * block) because they are handled in an uni    492    * block) because they are handled in an uniform way by the
495    * chardev/blockdev subsystems                  493    * chardev/blockdev subsystems
496    * @note As a consequence, FS code can safel    494    * @note As a consequence, FS code can safely assume that "this" is
497    * never a character or block device            495    * never a character or block device
498    */                                             496    */
499   sos_ret_t (*close_opened_file)(struct sos_fs    497   sos_ret_t (*close_opened_file)(struct sos_fs_node * this,
500                                  struct sos_fs    498                                  struct sos_fs_opened_file * of);
501                                                   499 
502   /**                                             500   /**
503    * This should hold the meta information for    501    * This should hold the meta information for this node as needed by
504    * the FS instance.                             502    * the FS instance.
505    */                                             503    */
506   void * custom_data;                             504   void * custom_data;
507                                                   505 
508   /** Hash linkage entry for this FS node in t    506   /** Hash linkage entry for this FS node in the nodecache
509      dictionary */                                507      dictionary */
510   struct sos_hash_linkage hlink_nodecache;        508   struct sos_hash_linkage hlink_nodecache;
511                                                   509 
512   /** Linkage to list the dirty nodes of the g    510   /** Linkage to list the dirty nodes of the given FS */
513   struct sos_fs_node *prev_dirty, *next_dirty;    511   struct sos_fs_node *prev_dirty, *next_dirty;
514 };                                                512 };
515                                                   513 
516                                                   514 
517                                                   515 
518 /**                                               516 /**
519  * The list of methods implementing the basic     517  * The list of methods implementing the basic VFS operations on the
520  * given struct sos_fs_node                       518  * given struct sos_fs_node
521  *                                                519  *
522  * @see sos_fs_node::ops_file                     520  * @see sos_fs_node::ops_file
523  */                                               521  */
524 struct sos_fs_node_ops_file                       522 struct sos_fs_node_ops_file
525 {                                                 523 {
526   /**                                             524   /**
527    * Change size of file                          525    * Change size of file
528    *                                              526    *
529    * @note Optional, may block. Appropriate lo    527    * @note Optional, may block. Appropriate locking MUST be implemented
530    */                                             528    */
531   sos_ret_t (*truncate)(struct sos_fs_node *th    529   sos_ret_t (*truncate)(struct sos_fs_node *this,
532                         sos_lsoffset_t length)    530                         sos_lsoffset_t length);
533                                                   531 
534   /**                                             532   /**
535    * Retrieve the status (eg size) of the file    533    * Retrieve the status (eg size) of the file
536    *                                              534    *
537    * @note Mandatory, may block. Appropriate l    535    * @note Mandatory, may block. Appropriate locking MUST be implemented
538    */                                             536    */
539   sos_ret_t (*stat)(struct sos_fs_node * this,    537   sos_ret_t (*stat)(struct sos_fs_node * this,
540                     struct sos_fs_stat * resul    538                     struct sos_fs_stat * result);
541                                                   539 
542   /**                                             540   /**
543    * Change the sos_fs_node::access_rights att    541    * Change the sos_fs_node::access_rights attribute
544    *                                              542    *
545    * @note Mandatory, may block. Appropriate l    543    * @note Mandatory, may block. Appropriate locking MUST be implemented
546    */                                             544    */
547   sos_ret_t (*chmod)(struct sos_fs_node * this    545   sos_ret_t (*chmod)(struct sos_fs_node * this,
548                      sos_ui32_t new_access_rig    546                      sos_ui32_t new_access_rights);
549                                                << 
550                                                << 
551   /**                                          << 
552    * Flush any change to the node back to the  << 
553    *                                           << 
554    * @note Mandatory, may block. Appropriate l << 
555    */                                          << 
556   sos_ret_t (*sync)(struct sos_fs_node *this); << 
557 };                                                547 };
558                                                   548 
559                                                   549 
560 /**                                               550 /**
561  * The list of methods implementing the basic     551  * The list of methods implementing the basic VFS symlink operations
562  *                                                552  *
563  * @see sos_fs_node::ops_symlink                  553  * @see sos_fs_node::ops_symlink
564  */                                               554  */
565 struct sos_fs_node_ops_symlink                    555 struct sos_fs_node_ops_symlink
566 {                                                 556 {
567   /**                                             557   /**
568    * Used by the _kernel_ to resolve the symli    558    * Used by the _kernel_ to resolve the symlinks. To change/create a
569    * symlink target, it is needed only from us    559    * symlink target, it is needed only from userland: the read/write
570    * methods are made for this                    560    * methods are made for this
571    *                                              561    *
572    * @param target Pointer to the string repre    562    * @param target Pointer to the string representing the target's
573    * path, allocated for the fs_node's lifetim    563    * path, allocated for the fs_node's lifetime !
574    *                                              564    *
575    * @note Mandatory, may block. Appropriate l    565    * @note Mandatory, may block. Appropriate locking MUST be implemented
576    */                                             566    */
577   sos_ret_t (*expand)(struct sos_fs_node *this    567   sos_ret_t (*expand)(struct sos_fs_node *this,
578                       char const  ** target,      568                       char const  ** target,
579                       sos_size_t * target_len)    569                       sos_size_t * target_len);
580 };                                                570 };
581                                                   571 
582                                                   572 
583 /**                                               573 /**
584  * The list of methods implementing the basic     574  * The list of methods implementing the basic VFS directory operations
585  *                                                575  *
586  * @see sos_fs_node::ops_dir                      576  * @see sos_fs_node::ops_dir
587  */                                               577  */
588 struct sos_fs_node_ops_dir                        578 struct sos_fs_node_ops_dir
589 {                                                 579 {
590   /**                                             580   /**
591    * Look for the on-disk location of the sos_    581    * Look for the on-disk location of the sos_fs_node having the given
592    * name                                         582    * name
593    *                                              583    *
594    * @note Mandatory, may block. Appropriate l    584    * @note Mandatory, may block. Appropriate locking MUST be implemented
595    */                                             585    */
596   sos_ret_t (*lookup)(struct sos_fs_node *this    586   sos_ret_t (*lookup)(struct sos_fs_node *this,
597                       const char * name, sos_u    587                       const char * name, sos_ui16_t namelen,
598                       sos_ui64_t * result_stor    588                       sos_ui64_t * result_storage_location);
599                                                   589 
600   /**                                             590   /**
601    * Add a new reference in the current sos_fs    591    * Add a new reference in the current sos_fs_node to the on-disk
602    * location of the given sos_fs_node            592    * location of the given sos_fs_node
603    *                                              593    *
604    * @note Responsible for updating this->ondi    594    * @note Responsible for updating this->ondisk_lnk_cnt
605    * @note Mandatory for writable directories,    595    * @note Mandatory for writable directories, may block. Appropriate
606    * locking MUST be implemented                  596    * locking MUST be implemented
607    */                                             597    */
608   sos_ret_t (*link)(struct sos_fs_node *this,     598   sos_ret_t (*link)(struct sos_fs_node *this,
609                     const struct sos_process *    599                     const struct sos_process *actor,
610                     const char * entry_name, s    600                     const char * entry_name, sos_ui16_t entry_namelen,
611                     struct sos_fs_node * node)    601                     struct sos_fs_node * node);
612                                                   602 
613   /**                                             603   /**
614    * Remove the entry in the current sos_fs_no    604    * Remove the entry in the current sos_fs_node for the on-disk
615    * location with the given name                 605    * location with the given name
616    *                                              606    *
617    * @note Responsible for updating this->ondi    607    * @note Responsible for updating this->ondisk_lnk_cnt
618    * @note Mandatory for writable directories,    608    * @note Mandatory for writable directories, may block. Appropriate
619    * locking MUST be implemented                  609    * locking MUST be implemented
620    */                                             610    */
621   sos_ret_t (*unlink)(struct sos_fs_node *this    611   sos_ret_t (*unlink)(struct sos_fs_node *this,
622                       const struct sos_process    612                       const struct sos_process *actor,
623                       const char * entry_name,    613                       const char * entry_name, sos_ui16_t entry_namelen);
624 };                                                614 };
625                                                   615 
626                                                   616 
627 /**                                               617 /**
628  * The data structure holding information and     618  * The data structure holding information and method related to a
629  * particular usage of a file. A so-called "st    619  * particular usage of a file. A so-called "struct file"
630  *                                                620  *
631  * This represents the kernel structure behind    621  * This represents the kernel structure behind a "file descriptor" or
632  * behind a chdir/chroot. Among other things,     622  * behind a chdir/chroot. Among other things, it holds the methods
633  * responsible for reading/writing into the fi    623  * responsible for reading/writing into the file, and for moving the
634  * file pointer (see @sos_fs_opened_file::posi    624  * file pointer (see @sos_fs_opened_file::position) inside it.
635  */                                               625  */
636 struct sos_fs_opened_file                         626 struct sos_fs_opened_file
637 {                                                 627 {
638   /** The process that opened the file/dir */     628   /** The process that opened the file/dir */
639   const struct sos_process * owner;               629   const struct sos_process * owner;
640                                                   630 
641   /**                                             631   /**
642    * The reference to the sos_fs_nscache_node     632    * The reference to the sos_fs_nscache_node and, hence, to the underlying sos_fs_node.
643    *                                              633    *
644    * Used to cache the in-memory fs nodes         634    * Used to cache the in-memory fs nodes
645    */                                             635    */
646   struct sos_fs_nscache_node * direntry;          636   struct sos_fs_nscache_node * direntry;
647                                                   637 
648   /** Use for memory-management */                638   /** Use for memory-management */
649   sos_count_t ref_cnt;                            639   sos_count_t ref_cnt;
650                                                   640 
651   /**                                             641   /**
652    * Always > 0 (ie max size = 2^63-1 = 9.2 10    642    * Always > 0 (ie max size = 2^63-1 = 9.2 10^18). We make it
653    * "signed" here to limit its range. Because    643    * "signed" here to limit its range. Because we must be able to
654    * seek to the begining of the file with SEE    644    * seek to the begining of the file with SEEK_END and a negative
655    * offset, so the max size of the file must     645    * offset, so the max size of the file must be reachable by a lseek
656    * offset                                       646    * offset
657    *                                              647    *
658    * @note reserved to filesystem instance cod    648    * @note reserved to filesystem instance code. Not modified nor used
659    * by fs.c                                      649    * by fs.c
660    */                                             650    */
661   sos_lsoffset_t     position;                    651   sos_lsoffset_t     position;
662                                                   652 
663   /**                                             653   /**
664    * Incremented each time this opened file is    654    * Incremented each time this opened file is modified
665    *                                              655    *
666    * Used to implement a readdir method resili    656    * Used to implement a readdir method resilient to
667    * creat/mkdir/rmdir/unlink                     657    * creat/mkdir/rmdir/unlink
668    */                                             658    */
669   sos_lcount_t generation;                        659   sos_lcount_t generation;
670                                                   660 
671   /**                                             661   /**
672    * @see SOS_FS_OPEN_* flags                     662    * @see SOS_FS_OPEN_* flags
673    */                                             663    */
674   sos_ui32_t open_flags;                          664   sos_ui32_t open_flags;
675                                                   665 
676   /** Operations common to all node types */      666   /** Operations common to all node types */
677   struct sos_fs_ops_opened_file * ops_file;       667   struct sos_fs_ops_opened_file * ops_file;
678                                                   668 
679   /** Operations specific to some node types *    669   /** Operations specific to some node types */
680   union                                           670   union
681   {                                               671   {
682     /** when direntry->fs_node->type == SOS_FS    672     /** when direntry->fs_node->type == SOS_FS_NODE_DIRECTORY */
683     struct sos_fs_ops_opened_dir      * ops_di    673     struct sos_fs_ops_opened_dir      * ops_dir;
684                                                   674 
685     /** when direntry->fs_node->type == SOS_FS    675     /** when direntry->fs_node->type == SOS_FS_NODE_DEVICE_CHAR */
686     struct sos_fs_ops_opened_chardev  * ops_ch    676     struct sos_fs_ops_opened_chardev  * ops_chardev;
687                                                << 
688     /** when direntry->fs_node->type == SOS_FS << 
689     struct sos_fs_ops_opened_blockdev * ops_bl << 
690   }; /* Anonymous union (gcc extension) */        677   }; /* Anonymous union (gcc extension) */
691                                                   678 
692   /**                                             679   /**
693    * Called upon fork() to duplicate all the o    680    * Called upon fork() to duplicate all the opened files
694    *                                              681    *
695    * @note FS-specific EXCEPT for device speci    682    * @note FS-specific EXCEPT for device special files (char &
696    * block) because they are handled in an uni    683    * block) because they are handled in an uniform way by the
697    * chardev/blockdev subsystems                  684    * chardev/blockdev subsystems
698    * @note As a consequence, FS code can safel    685    * @note As a consequence, FS code can safely assume that "this" is
699    * never a character or block device            686    * never a character or block device
700    */                                             687    */
701   sos_ret_t (*duplicate)(struct sos_fs_opened_    688   sos_ret_t (*duplicate)(struct sos_fs_opened_file *this,
702                          const struct sos_proc    689                          const struct sos_process  * for_owner,
703                          struct sos_fs_opened_    690                          struct sos_fs_opened_file **result);
704                                                   691 
705   void * custom_data;                             692   void * custom_data;
706 };                                                693 };
707                                                   694 
708                                                   695 
709 /**                                               696 /**
710  * Reference position for sos_fs_seek             697  * Reference position for sos_fs_seek
711  */                                               698  */
712 typedef enum { SOS_SEEK_SET=42,                   699 typedef enum { SOS_SEEK_SET=42,
713                SOS_SEEK_CUR=24,                   700                SOS_SEEK_CUR=24,
714                SOS_SEEK_END=84 } sos_seek_when    701                SOS_SEEK_END=84 } sos_seek_whence_t;
715 /**                                               702 /**
716  * The list of methods implementing the basic     703  * The list of methods implementing the basic VFS opened file
717  * operations                                     704  * operations
718  *                                                705  *
719  * See the Unix manual pages, they basically f    706  * See the Unix manual pages, they basically form the interfaces to to
720  * these functions                                707  * these functions
721  *                                                708  *
722  * @see sos_fs_opened_file::ops_file              709  * @see sos_fs_opened_file::ops_file
723  */                                               710  */
724 struct sos_fs_ops_opened_file                     711 struct sos_fs_ops_opened_file
725 {                                                 712 {
726   /**                                             713   /**
727    * @note Mandatory, may block. Appropriate l    714    * @note Mandatory, may block. Appropriate locking MUST be implemented
728    * @note Please call sos_fs_mark_dirty() if     715    * @note Please call sos_fs_mark_dirty() if disk contents is changed
729    */                                             716    */
730   sos_ret_t (*seek)(struct sos_fs_opened_file     717   sos_ret_t (*seek)(struct sos_fs_opened_file *this,
731                     sos_lsoffset_t offset,        718                     sos_lsoffset_t offset,
732                     sos_seek_whence_t whence,     719                     sos_seek_whence_t whence,
733                     /* out */ sos_lsoffset_t *    720                     /* out */ sos_lsoffset_t * result_position);
734                                                   721 
735   /**                                             722   /**
736    * @note Mandatory, may block. Appropriate l    723    * @note Mandatory, may block. Appropriate locking MUST be implemented
737    * @note Please call sos_fs_mark_dirty() if     724    * @note Please call sos_fs_mark_dirty() if disk contents is changed
738    */                                             725    */
739   sos_ret_t (*read)(struct sos_fs_opened_file     726   sos_ret_t (*read)(struct sos_fs_opened_file *this,
740                     sos_uaddr_t dest_buf,         727                     sos_uaddr_t dest_buf,
741                     sos_size_t * /* in/out */l    728                     sos_size_t * /* in/out */len);
742                                                   729 
743   /**                                             730   /**
744    * @note Optional (might be NULL), may block    731    * @note Optional (might be NULL), may block. Appropriate locking
745    * MUST be implemented                          732    * MUST be implemented
746    * @note Please call sos_fs_mark_dirty() if     733    * @note Please call sos_fs_mark_dirty() if disk contents is changed
747    */                                             734    */
748   sos_ret_t (*write)(struct sos_fs_opened_file    735   sos_ret_t (*write)(struct sos_fs_opened_file *this,
749                      sos_uaddr_t src_buf,         736                      sos_uaddr_t src_buf,
750                      sos_size_t * /* in/out */    737                      sos_size_t * /* in/out */len);
751                                                   738 
752   /**                                             739   /**
753    * @note Optional (might be NULL), may block    740    * @note Optional (might be NULL), may block. Appropriate locking
754    * MUST be implemented                          741    * MUST be implemented
755    * @note Please call sos_fs_mark_dirty() if     742    * @note Please call sos_fs_mark_dirty() if disk contents is changed
756    */                                             743    */
757   sos_ret_t (*mmap)(struct sos_fs_opened_file     744   sos_ret_t (*mmap)(struct sos_fs_opened_file *this,
758                     sos_uaddr_t *uaddr, sos_si    745                     sos_uaddr_t *uaddr, sos_size_t size,
759                     sos_ui32_t access_rights,     746                     sos_ui32_t access_rights,
760                     sos_ui32_t flags,             747                     sos_ui32_t flags,
761                     sos_luoffset_t offset);       748                     sos_luoffset_t offset);
762                                                   749 
763   /**                                             750   /**
764    * @note Optional (might be NULL), may block    751    * @note Optional (might be NULL), may block. Appropriate locking
765    * MUST be implemented                          752    * MUST be implemented
766    * @note Please call sos_fs_mark_dirty() if     753    * @note Please call sos_fs_mark_dirty() if disk contents is changed
767    */                                             754    */
768   sos_ret_t (*fcntl)(struct sos_fs_opened_file    755   sos_ret_t (*fcntl)(struct sos_fs_opened_file *this,
769                      int req_id,                  756                      int req_id,
770                      sos_ui32_t req_arg /* Usu    757                      sos_ui32_t req_arg /* Usually: sos_uaddr_t */);
771 };                                                758 };
772                                                   759 
773                                                   760 
774 /**                                               761 /**
775  * The list of methods implementing the basic     762  * The list of methods implementing the basic VFS opened character device
776  * operations                                     763  * operations
777  *                                                764  *
778  * @see sos_fs_opened_file::ops_file              765  * @see sos_fs_opened_file::ops_file
779  */                                               766  */
780 struct sos_fs_ops_opened_chardev                  767 struct sos_fs_ops_opened_chardev
781 {                                                 768 {
782   /**                                             769   /**
783    * @note Optional (might be NULL), may block    770    * @note Optional (might be NULL), may block. Appropriate locking
784    * MUST be implemented                          771    * MUST be implemented
785    * @note Please call sos_fs_mark_dirty() if     772    * @note Please call sos_fs_mark_dirty() if disk contents is changed
786    */                                             773    */
787   sos_ret_t (*ioctl)(struct sos_fs_opened_file    774   sos_ret_t (*ioctl)(struct sos_fs_opened_file *this,
788                      int req_id,                  775                      int req_id,
789                      sos_ui32_t req_arg /* Usu    776                      sos_ui32_t req_arg /* Usually: sos_uaddr_t */);
790 };                                                777 };
791                                                   778 
792                                                   779 
793 /**                                            << 
794  * The list of methods implementing the basic  << 
795  * operations                                  << 
796  *                                             << 
797  * @see sos_fs_opened_file::ops_file           << 
798  */                                            << 
799 struct sos_fs_ops_opened_blockdev              << 
800 {                                              << 
801   /**                                          << 
802    * @note Optional (might be NULL), may block << 
803    * MUST be implemented                       << 
804    * @note Please call sos_fs_mark_dirty() if  << 
805    */                                          << 
806   sos_ret_t (*ioctl)(struct sos_fs_opened_file << 
807                      int req_id,               << 
808                      sos_ui32_t req_arg /* Usu << 
809 };                                             << 
810                                                << 
811                                                << 
812 /** Data structure that is to be filled by rea    780 /** Data structure that is to be filled by readdir */
813 struct sos_fs_dirent                              781 struct sos_fs_dirent
814 {                                                 782 {
815   sos_ui64_t storage_location;                    783   sos_ui64_t storage_location;
816   sos_si64_t offset_in_dirfile;                   784   sos_si64_t offset_in_dirfile;
817   sos_ui32_t type;                                785   sos_ui32_t type;
818   sos_ui16_t namelen;                             786   sos_ui16_t namelen;
819                                                   787 
820 #define SOS_FS_DIRENT_NAME_MAXLEN 128             788 #define SOS_FS_DIRENT_NAME_MAXLEN 128
821   char       name[SOS_FS_DIRENT_NAME_MAXLEN];     789   char       name[SOS_FS_DIRENT_NAME_MAXLEN];
822 };                                                790 };
823                                                   791 
824                                                   792 
825 /**                                               793 /**
826  * The list of methods implementing the basic     794  * The list of methods implementing the basic VFS opened directory
827  * operations                                     795  * operations
828  *                                                796  *
829  * @see sos_fs_opened_file::ops_file              797  * @see sos_fs_opened_file::ops_file
830  */                                               798  */
831 struct sos_fs_ops_opened_dir                      799 struct sos_fs_ops_opened_dir
832 {                                                 800 {
833   /**                                             801   /**
834    * Each time it is called, responsible for f    802    * Each time it is called, responsible for filling the sos_fs_dirent
835    * structure, return -SOS_ENOENT when done.     803    * structure, return -SOS_ENOENT when done.
836    *                                              804    *
837    * @note Mandatory, may block. Appropriate l    805    * @note Mandatory, may block. Appropriate locking MUST be implemented
838    * @note Please call sos_fs_mark_dirty() if     806    * @note Please call sos_fs_mark_dirty() if disk contents is changed
839    */                                             807    */
840   sos_ret_t (*readdir)(struct sos_fs_opened_fi    808   sos_ret_t (*readdir)(struct sos_fs_opened_file *this,
841                        struct sos_fs_dirent *     809                        struct sos_fs_dirent * result);
842 };                                                810 };
843                                                   811 
844                                                   812 
845                                                   813 
846 /**                                               814 /**
847  * Used by the stat calls                         815  * Used by the stat calls
848  *                                                816  *
849  * @see sos_fs_node_ops_file::stat                817  * @see sos_fs_node_ops_file::stat
850  */                                               818  */
851 struct sos_fs_stat                                819 struct sos_fs_stat
852 {                                                 820 {
853   struct sos_fs_dev_id_t st_rdev;                 821   struct sos_fs_dev_id_t st_rdev;
854   sos_fs_node_type_t     st_type;                 822   sos_fs_node_type_t     st_type;
855   sos_ui64_t             st_storage_location;     823   sos_ui64_t             st_storage_location;
856   sos_ui32_t             st_access_rights;        824   sos_ui32_t             st_access_rights;
857   sos_count_t            st_nlink;                825   sos_count_t            st_nlink;
858   sos_si64_t             st_size;                 826   sos_si64_t             st_size;
859 };                                                827 };
860                                                   828 
861                                                   829 
862 /**                                               830 /**
863  * Used by the statvfs calls                      831  * Used by the statvfs calls
864  *                                                832  *
865  * @see sos_fs_manager_instance::statfs           833  * @see sos_fs_manager_instance::statfs
866  */                                               834  */
867 struct sos_fs_statfs                              835 struct sos_fs_statfs
868 {                                                 836 {
869   struct sos_fs_dev_id_t f_rdev;                  837   struct sos_fs_dev_id_t f_rdev;
870   sos_size_t             f_sz_total;  /**< Tot    838   sos_size_t             f_sz_total;  /**< Total size */
871   sos_size_t             f_sz_free;   /**< Siz    839   sos_size_t             f_sz_free;   /**< Size left on device */
872   sos_count_t            f_node_total;/**< Tot    840   sos_count_t            f_node_total;/**< Total allocatable FS nodes */
873   sos_count_t            f_node_avail;/**< Num    841   sos_count_t            f_node_avail;/**< Number of available free FS nodes */
874   sos_ui32_t             f_flags;                 842   sos_ui32_t             f_flags;
875 };                                                843 };
876                                                   844 
877                                                   845 
878 /**                                               846 /**
879  * Must be called AFTER the FS manager types n    847  * Must be called AFTER the FS manager types needed to mount the root
880  * filesystem have been registered                848  * filesystem have been registered
881  */                                               849  */
882 sos_ret_t sos_fs_subsystem_setup(const char *     850 sos_ret_t sos_fs_subsystem_setup(const char * root_device,
883                                  const char *     851                                  const char * fs_type,
884                                  const char *     852                                  const char * mount_args,
885                                  struct sos_fs    853                                  struct sos_fs_manager_instance ** result_rootfs);
886                                                   854 
887                                                   855 
888 /*  ******************************************    856 /*  ***************************************************************
889  * The Following functions are relatively stan    857  * The Following functions are relatively standard
890  *                                                858  *
891  * @see Unix manual pages for details             859  * @see Unix manual pages for details
892  */                                               860  */
893                                                   861 
894                                                   862 
895 /**                                               863 /**
896  * mount a file system                            864  * mount a file system
897  *                                                865  *
898  * @param actor process calling mount             866  * @param actor process calling mount
899  * @param _src_path(len) may be NULL (as for v    867  * @param _src_path(len) may be NULL (as for virtfs or /proc)
900  * @fsname the name of the filesystem type to     868  * @fsname the name of the filesystem type to mount
901  * @args any args passed to the sos_fs_manager    869  * @args any args passed to the sos_fs_manager_type::mount method
902  * @result_fs the resulting filesystem instanc    870  * @result_fs the resulting filesystem instance
903  */                                               871  */
904 sos_ret_t sos_fs_mount(struct sos_process * ac    872 sos_ret_t sos_fs_mount(struct sos_process * actor,
905                        const char * _src_path,    873                        const char * _src_path,
906                        sos_size_t _src_pathlen    874                        sos_size_t _src_pathlen,
907                        const char * _dst_path,    875                        const char * _dst_path,
908                        sos_size_t _dst_pathlen    876                        sos_size_t _dst_pathlen,
909                        const char * fsname,       877                        const char * fsname,
910                        sos_ui32_t mountflags,     878                        sos_ui32_t mountflags,
911                        const char * args,         879                        const char * args,
912                        struct sos_fs_manager_i    880                        struct sos_fs_manager_instance ** /*out*/result_fs);
913                                                   881 
914 /**                                               882 /**
915  * unmount the filesystem at the given locatio    883  * unmount the filesystem at the given location
916  */                                               884  */
917 sos_ret_t sos_fs_umount(struct sos_process * a    885 sos_ret_t sos_fs_umount(struct sos_process * actor,
918                         const char * _mountpoi    886                         const char * _mountpoint_path,
919                         sos_size_t _mountpoint    887                         sos_size_t _mountpoint_pathlen);
920                                                   888 
921 /**                                               889 /**
922  * Flush all the dirty nodes of all the FS to     890  * Flush all the dirty nodes of all the FS to disk
923  */                                               891  */
924 sos_ret_t sos_fs_sync_all_fs(void);            !! 892 sos_ret_t sos_fs_sync_all_fs();
925                                                   893 
926 /**                                               894 /**
927  * Retrieve filesystem status, or return -SOS_    895  * Retrieve filesystem status, or return -SOS_ENOSYS if filesystem
928  * cannot report this                             896  * cannot report this
929  */                                               897  */
930 sos_ret_t sos_fs_vfstat(const struct sos_proce    898 sos_ret_t sos_fs_vfstat(const struct sos_process * actor,
931                         const char * _path,       899                         const char * _path,
932                         sos_size_t _pathlen,      900                         sos_size_t _pathlen,
933                         struct sos_fs_statfs *    901                         struct sos_fs_statfs * result);
934                                                   902 
935 /**                                               903 /**
936  * Open flags                                     904  * Open flags
937  */                                               905  */
938 #define SOS_FS_OPEN_EXCL        (1 << 0)          906 #define SOS_FS_OPEN_EXCL        (1 << 0)
939 #define SOS_FS_OPEN_CREAT       (1 << 1)          907 #define SOS_FS_OPEN_CREAT       (1 << 1)
940 #define SOS_FS_OPEN_TRUNC       (1 << 2)          908 #define SOS_FS_OPEN_TRUNC       (1 << 2)
941 #define SOS_FS_OPEN_NOFOLLOW    (1 << 3)          909 #define SOS_FS_OPEN_NOFOLLOW    (1 << 3)
942 #define SOS_FS_OPEN_DIRECTORY   (1 << 4) /* In    910 #define SOS_FS_OPEN_DIRECTORY   (1 << 4) /* Incompatible with CREAT/TRUNC */
943 #define SOS_FS_OPEN_SYNC        (1 << 5)          911 #define SOS_FS_OPEN_SYNC        (1 << 5)
944 #define SOS_FS_OPEN_CLOSEONEXEC (1 << 6) /* By    912 #define SOS_FS_OPEN_CLOSEONEXEC (1 << 6) /* By default, files are kept
945                                             op    913                                             open upon an exec() */
946                                                   914 
947 #define SOS_FS_OPEN_READ        (1 << 16)         915 #define SOS_FS_OPEN_READ        (1 << 16)
948 #define SOS_FS_OPEN_WRITE       (1 << 17)         916 #define SOS_FS_OPEN_WRITE       (1 << 17)
949                                                   917 
950                                                   918 
951 /**                                               919 /**
952  * FS access rights                               920  * FS access rights
953  */                                               921  */
954 #define SOS_FS_S_IRUSR   00400                    922 #define SOS_FS_S_IRUSR   00400
955 #define SOS_FS_S_IWUSR   00200                    923 #define SOS_FS_S_IWUSR   00200
956 #define SOS_FS_S_IXUSR   00100                    924 #define SOS_FS_S_IXUSR   00100
957                                                   925 
958 #define SOS_FS_S_IRWXALL 07777 /* For symlinks    926 #define SOS_FS_S_IRWXALL 07777 /* For symlinks */
959                                                   927 
960 sos_ret_t sos_fs_open(const struct sos_process    928 sos_ret_t sos_fs_open(const struct sos_process *owner,
961                       const char *_path,          929                       const char *_path,
962                       sos_size_t _pathlen,        930                       sos_size_t _pathlen,
963                       sos_ui32_t open_flags,      931                       sos_ui32_t open_flags,
964                       sos_ui32_t creat_access_    932                       sos_ui32_t creat_access_rights,
965                       struct sos_fs_opened_fil    933                       struct sos_fs_opened_file ** of);
966                                                   934 
967 sos_ret_t sos_fs_close(struct sos_fs_opened_fi    935 sos_ret_t sos_fs_close(struct sos_fs_opened_file * of);
968                                                   936 
969 sos_ret_t sos_fs_read(struct sos_fs_opened_fil    937 sos_ret_t sos_fs_read(struct sos_fs_opened_file * of,
970                       sos_uaddr_t dest_buf,       938                       sos_uaddr_t dest_buf,
971                       sos_size_t * /* in/ou */    939                       sos_size_t * /* in/ou */len);
972                                                   940 
973 sos_ret_t sos_fs_readdir(struct sos_fs_opened_    941 sos_ret_t sos_fs_readdir(struct sos_fs_opened_file * of,
974                          struct sos_fs_dirent     942                          struct sos_fs_dirent * result);
975                                                   943 
976 sos_ret_t sos_fs_write(struct sos_fs_opened_fi    944 sos_ret_t sos_fs_write(struct sos_fs_opened_file * of,
977                        sos_uaddr_t src_buf,       945                        sos_uaddr_t src_buf,
978                        sos_size_t * /* in/out     946                        sos_size_t * /* in/out */len);
979                                                   947 
980 sos_ret_t sos_fs_seek(struct sos_fs_opened_fil    948 sos_ret_t sos_fs_seek(struct sos_fs_opened_file *of,
981                       sos_lsoffset_t offset,      949                       sos_lsoffset_t offset,
982                       sos_seek_whence_t whence    950                       sos_seek_whence_t whence,
983                       sos_lsoffset_t * result_    951                       sos_lsoffset_t * result_position);
984                                                   952 
985 sos_ret_t sos_fs_ftruncate(struct sos_fs_opene    953 sos_ret_t sos_fs_ftruncate(struct sos_fs_opened_file *of,
986                            sos_lsoffset_t leng    954                            sos_lsoffset_t length);
987                                                   955 
988 sos_ret_t sos_fs_mmap(struct sos_fs_opened_fil    956 sos_ret_t sos_fs_mmap(struct sos_fs_opened_file *of,
989                       sos_uaddr_t *uaddr, sos_    957                       sos_uaddr_t *uaddr, sos_size_t size,
990                       sos_ui32_t access_rights    958                       sos_ui32_t access_rights,
991                       sos_ui32_t flags,           959                       sos_ui32_t flags,
992                       sos_luoffset_t offset);     960                       sos_luoffset_t offset);
993                                                   961 
994 sos_ret_t sos_fs_fsync(struct sos_fs_opened_fi    962 sos_ret_t sos_fs_fsync(struct sos_fs_opened_file * of);
995                                                   963 
996 sos_ret_t sos_fs_fcntl(struct sos_fs_opened_fi    964 sos_ret_t sos_fs_fcntl(struct sos_fs_opened_file *of,
997                        int req_id,                965                        int req_id,
998                        sos_ui32_t req_arg /* U    966                        sos_ui32_t req_arg /* Usually: sos_uaddr_t */);
999                                                   967 
1000 sos_ret_t sos_fs_ioctl(struct sos_fs_opened_f    968 sos_ret_t sos_fs_ioctl(struct sos_fs_opened_file *of,
1001                        int req_id,               969                        int req_id,
1002                        sos_ui32_t req_arg /*     970                        sos_ui32_t req_arg /* Usually: sos_uaddr_t */);
1003                                                  971 
1004 sos_ret_t sos_fs_creat(const struct sos_proce    972 sos_ret_t sos_fs_creat(const struct sos_process * creator,
1005                        const char * _path,       973                        const char * _path,
1006                        sos_size_t _pathlen,      974                        sos_size_t _pathlen,
1007                        sos_ui32_t access_righ    975                        sos_ui32_t access_rights);
1008                                                  976 
1009 sos_ret_t sos_fs_link(const struct sos_proces    977 sos_ret_t sos_fs_link(const struct sos_process * creator,
1010                       const char * _old_path,    978                       const char * _old_path,
1011                       sos_size_t _old_pathlen    979                       sos_size_t _old_pathlen,
1012                       const char * _dest_path    980                       const char * _dest_path,
1013                       sos_size_t _dest_pathle    981                       sos_size_t _dest_pathlen);
1014                                                  982 
1015 sos_ret_t sos_fs_rename(const struct sos_proc    983 sos_ret_t sos_fs_rename(const struct sos_process * creator,
1016                         const char * _old_pat    984                         const char * _old_path,
1017                         sos_size_t _old_pathl    985                         sos_size_t _old_pathlen,
1018                         const char * _dest_pa    986                         const char * _dest_path,
1019                         sos_size_t _dest_path    987                         sos_size_t _dest_pathlen);
1020                                                  988 
1021 sos_ret_t sos_fs_unlink(const struct sos_proc    989 sos_ret_t sos_fs_unlink(const struct sos_process * actor,
1022                         const char * _path,      990                         const char * _path,
1023                         sos_size_t _pathlen);    991                         sos_size_t _pathlen);
1024                                                  992 
1025 sos_ret_t sos_fs_symlink(const struct sos_pro    993 sos_ret_t sos_fs_symlink(const struct sos_process * creator,
1026                          const char * _path,     994                          const char * _path,
1027                          sos_size_t _pathlen,    995                          sos_size_t _pathlen,
1028                          sos_uaddr_t symlink_    996                          sos_uaddr_t symlink_target,
1029                          sos_size_t symlink_t    997                          sos_size_t symlink_target_len);
1030                                                  998 
1031 sos_ret_t sos_fs_mknod(const struct sos_proce    999 sos_ret_t sos_fs_mknod(const struct sos_process * creator,
1032                        const char * _path,       1000                        const char * _path,
1033                        sos_size_t _pathlen,      1001                        sos_size_t _pathlen,
1034                        sos_fs_node_type_t typ    1002                        sos_fs_node_type_t type /* only block/char allowed */,
1035                        sos_ui32_t access_righ    1003                        sos_ui32_t access_rights,
1036                        const struct sos_fs_de    1004                        const struct sos_fs_dev_id_t * devid);
1037                                                  1005 
1038 sos_ret_t sos_fs_mkdir(const struct sos_proce    1006 sos_ret_t sos_fs_mkdir(const struct sos_process * creator,
1039                        const char * _path,       1007                        const char * _path,
1040                        sos_size_t _pathlen,      1008                        sos_size_t _pathlen,
1041                        sos_ui32_t access_righ    1009                        sos_ui32_t access_rights);
1042                                                  1010 
1043 sos_ret_t sos_fs_rmdir(const struct sos_proce    1011 sos_ret_t sos_fs_rmdir(const struct sos_process * actor,
1044                        const char * _path,       1012                        const char * _path,
1045                        sos_size_t _pathlen);     1013                        sos_size_t _pathlen);
1046                                                  1014 
1047 sos_ret_t sos_fs_chmod(const struct sos_proce    1015 sos_ret_t sos_fs_chmod(const struct sos_process * actor,
1048                        const char * _path,       1016                        const char * _path,
1049                        sos_size_t _pathlen,      1017                        sos_size_t _pathlen,
1050                        sos_ui32_t access_righ    1018                        sos_ui32_t access_rights);
1051                                                  1019 
1052 sos_ret_t sos_fs_stat(const struct sos_proces    1020 sos_ret_t sos_fs_stat(const struct sos_process * actor,
1053                       const char * _path,        1021                       const char * _path,
1054                       sos_size_t _pathlen,       1022                       sos_size_t _pathlen,
1055                       int nofollow,              1023                       int nofollow,
1056                       struct sos_fs_stat * re    1024                       struct sos_fs_stat * result);
1057                                                  1025 
1058                                                  1026 
1059 /* ******************************************    1027 /* ***************************************************************
1060  * Restricted functions reserved to FS code a    1028  * Restricted functions reserved to FS code and block/char devices
1061  */                                              1029  */
1062                                                  1030 
1063 /**                                              1031 /**
1064  * Function to be called when proposing a new    1032  * Function to be called when proposing a new File system type
1065  */                                              1033  */
1066 sos_ret_t sos_fs_register_fs_type(struct sos_    1034 sos_ret_t sos_fs_register_fs_type(struct sos_fs_manager_type * fstype);
1067 sos_ret_t sos_fs_unregister_fs_type(struct so    1035 sos_ret_t sos_fs_unregister_fs_type(struct sos_fs_manager_type * fstype);
1068                                                  1036 
1069 /**                                              1037 /**
1070  * Marthe given file as dirty, for FS support    1038  * Marthe given file as dirty, for FS supporting deferred write access
1071  * mode                                          1039  * mode
1072  */                                              1040  */
1073 sos_ret_t sos_fs_mark_dirty(struct sos_fs_ope    1041 sos_ret_t sos_fs_mark_dirty(struct sos_fs_opened_file * of);
1074                                                  1042 
1075 /**                                              1043 /**
1076  * Helper function to be called from the moun    1044  * Helper function to be called from the mount() method of the FS
1077  * instance code. Responsible for creating an    1045  * instance code. Responsible for creating and updating the "root"
1078  * field of the FS instance structure and for    1046  * field of the FS instance structure and for connecting this FS in
1079  * the nscache                                   1047  * the nscache
1080  * @param root_fsnode The root of the FS bein    1048  * @param root_fsnode The root of the FS being mounted
1081  */                                              1049  */
1082 sos_ret_t sos_fs_register_fs_instance(struct     1050 sos_ret_t sos_fs_register_fs_instance(struct sos_fs_manager_instance * fs,
1083                                       struct     1051                                       struct sos_fs_node * root_fsnode);
1084                                                  1052 
1085 /**                                              1053 /**
1086  * Helper function to be called from the umou    1054  * Helper function to be called from the umount() method of the FS
1087  * instance code. Responsible for unregisteri    1055  * instance code. Responsible for unregistering the instance from the
1088  * FS type's instances list and for disconnec    1056  * FS type's instances list and for disconnecting this mountpoint in
1089  * the nscache.                                  1057  * the nscache.
1090  */                                              1058  */
1091 sos_ret_t sos_fs_unregister_fs_instance(struc    1059 sos_ret_t sos_fs_unregister_fs_instance(struct sos_fs_manager_instance * fs);
1092                                                  1060 
1093                                                  1061 
1094 /* ******************************************    1062 /* ***************************************************************
1095  * Restricted functions reserved to syscall.c    1063  * Restricted functions reserved to syscall.c
1096  */                                              1064  */
1097 sos_ret_t sos_fs_ref_opened_file(struct sos_f    1065 sos_ret_t sos_fs_ref_opened_file(struct sos_fs_opened_file * of);
1098 sos_ret_t _sos_fs_unref_opened_file(struct so    1066 sos_ret_t _sos_fs_unref_opened_file(struct sos_fs_opened_file ** of);
1099 #define sos_fs_unref_opened_file(f) _sos_fs_u    1067 #define sos_fs_unref_opened_file(f) _sos_fs_unref_opened_file(&(f))
1100                                                  1068 
1101                                                  1069 
1102 /* ******************************************    1070 /* ***************************************************************
1103  * Restricted functions to be used only by fs    1071  * Restricted functions to be used only by fs_nscache.c
1104  */                                              1072  */
1105                                                  1073 
1106 sos_ret_t sos_fs_ref_fsnode(struct sos_fs_nod    1074 sos_ret_t sos_fs_ref_fsnode(struct sos_fs_node * fsnode);
1107                                                  1075 
1108 sos_ret_t _sos_fs_unref_fsnode(struct sos_fs_    1076 sos_ret_t _sos_fs_unref_fsnode(struct sos_fs_node * fsnode);
1109 #define sos_fs_unref_fsnode(n) \                 1077 #define sos_fs_unref_fsnode(n) \
1110   ({ sos_ret_t __retval = _sos_fs_unref_fsnod    1078   ({ sos_ret_t __retval = _sos_fs_unref_fsnode(n); (n)=NULL; __retval; })
1111                                                  1079 
1112                                                  1080 
1113 /* ******************************************    1081 /* ***************************************************************
1114  * Restricted functions reserved to process.c    1082  * Restricted functions reserved to process.c and main.c:start_init()
1115  */                                              1083  */
1116 sos_ret_t sos_fs_new_opened_file(const struct    1084 sos_ret_t sos_fs_new_opened_file(const struct sos_process * proc,
1117                                  struct sos_f    1085                                  struct sos_fs_nscache_node * nsnode,
1118                                  sos_ui32_t o    1086                                  sos_ui32_t open_flags,
1119                                  struct sos_f    1087                                  struct sos_fs_opened_file ** result_of);
1120                                                  1088 
1121                                                  1089 
1122 sos_ret_t sos_fs_duplicate_opened_file(struct    1090 sos_ret_t sos_fs_duplicate_opened_file(struct sos_fs_opened_file * src_of,
1123                                        const     1091                                        const struct sos_process * dst_proc,
1124                                        struct    1092                                        struct sos_fs_opened_file ** result_of);
1125                                                  1093 
1126                                                  1094 
1127                                                  1095 
1128 #endif /* _SOS_FS_H_ */                          1096 #endif /* _SOS_FS_H_ */
                                                      

source navigation ] diff markup ] identifier search ] general search ]