|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2005 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 (struct 059 * permissions, ... (struct sos_fs_node for !! 059 * 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 (ie size, permissions) is located at sector 64589 on 068 * this meta information directly from disk !! 068 * disk. By retrieving this meta information directly from disk, we 069 * struct sos_fs_node, which would (for exa !! 069 * can build the struct sos_fs_node, which would (for example) tell 070 * corresponding file spans (for example) o !! 070 * that the corresponding file spans (for example) over sectors 071 * 4539 and 6575, is 1.7kB long !! 071 * 4345, 5645, 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 164 165 /** 165 /** 166 * The type of filesystem object. 166 * The type of filesystem object. 167 * 167 * 168 * Each struct sos_fs_node has a type. Here ar 168 * Each struct sos_fs_node has a type. Here are the supported types. 169 */ 169 */ 170 typedef enum { 170 typedef enum { 171 SOS_FS_NODE_REGULAR_FILE = 0x42, 171 SOS_FS_NODE_REGULAR_FILE = 0x42, 172 SOS_FS_NODE_DIRECTORY = 0x24, 172 SOS_FS_NODE_DIRECTORY = 0x24, 173 SOS_FS_NODE_SYMLINK = 0x84, 173 SOS_FS_NODE_SYMLINK = 0x84, 174 SOS_FS_NODE_DEVICE_CHAR = 0x48, << 175 } sos_fs_node_type_t; 174 } sos_fs_node_type_t; 176 175 177 176 178 #define SOS_FS_MANAGER_NAME_MAXLEN 32 177 #define SOS_FS_MANAGER_NAME_MAXLEN 32 179 /** 178 /** 180 * Description of a supported Filesystem type. 179 * Description of a supported Filesystem type. 181 * 180 * 182 * These descriptions are listed in an interna 181 * These descriptions are listed in an internal list (see 183 * fs.c:fs_list), and each time we want to mou 182 * fs.c:fs_list), and each time we want to mount a FS, we precise a 184 * name (eg "FAT", "EXT2", ...). The VFS will 183 * name (eg "FAT", "EXT2", ...). The VFS will look for this name into 185 * the list of supported filesystem types, and 184 * the list of supported filesystem types, and, when found, call its 186 * sos_fs_manager_type::mount() method. 185 * sos_fs_manager_type::mount() method. 187 * 186 * 188 * New filesystem types are registered using s 187 * New filesystem types are registered using sos_fs_register_fs_type() 189 */ 188 */ 190 struct sos_fs_manager_type 189 struct sos_fs_manager_type 191 { 190 { 192 char name[SOS_FS_MANAGER_NAME_MAXLEN]; 191 char name[SOS_FS_MANAGER_NAME_MAXLEN]; 193 192 194 /** 193 /** 195 * Responsible for making sure the underlyin 194 * Responsible for making sure the underlying device (if any) really 196 * stores the correct filesystem format, for 195 * stores the correct filesystem format, for creating the hash of fs 197 * nodes and for calling sos_fs_register_fs_ 196 * nodes and for calling sos_fs_register_fs_instance 198 * 197 * 199 * @param device May be NULL 198 * @param device May be NULL 200 * 199 * 201 * @note mandatory, may block 200 * @note mandatory, may block 202 */ 201 */ 203 sos_ret_t (*mount)(struct sos_fs_manager_typ 202 sos_ret_t (*mount)(struct sos_fs_manager_type * this, 204 struct sos_fs_node * devi 203 struct sos_fs_node * device, 205 const char * args, 204 const char * args, 206 struct sos_fs_manager_ins 205 struct sos_fs_manager_instance ** mounted_fs); 207 206 208 /** 207 /** 209 * Responsible for de-allocating the hash of 208 * Responsible for de-allocating the hash of fs nodes and for 210 * calling sos_fs_unregister_fs_instance 209 * calling sos_fs_unregister_fs_instance 211 * 210 * 212 * @note mandatory, may block 211 * @note mandatory, may block 213 */ 212 */ 214 sos_ret_t (*umount)(struct sos_fs_manager_ty 213 sos_ret_t (*umount)(struct sos_fs_manager_type * this, 215 struct sos_fs_manager_in 214 struct sos_fs_manager_instance * mounted_fs); 216 215 217 /** Free of use */ 216 /** Free of use */ 218 void * custom_data; 217 void * custom_data; 219 218 220 /** List of filesystem instances of this typ 219 /** List of filesystem instances of this type currently mounted 221 somewhere in the system */ 220 somewhere in the system */ 222 struct sos_fs_manager_instance * instances; 221 struct sos_fs_manager_instance * instances; 223 222 224 /** Linkage for the list of filesystem types 223 /** Linkage for the list of filesystem types registered in the 225 system */ 224 system */ 226 struct sos_fs_manager_type *prev, *next; 225 struct sos_fs_manager_type *prev, *next; 227 }; 226 }; 228 227 229 228 230 /** 229 /** 231 * Data related to a particular "mounting" of !! 230 * Data related to a particular "mounting" of a file system. A so-called "superblock" under Linux 232 * so-called "superblock" under Linux << 233 * 231 * 234 * This holds the FUNDAMENTAL functions respon 232 * This holds the FUNDAMENTAL functions responsible for loading struct 235 * sos_fs_node from disk, or for allocating th 233 * sos_fs_node from disk, or for allocating thom on disk. It also 236 * holds the hash-table of struct sos_fs_node 234 * holds the hash-table of struct sos_fs_node already loaded into 237 * memory. 235 * memory. 238 */ 236 */ 239 struct sos_fs_manager_instance 237 struct sos_fs_manager_instance 240 { 238 { 241 /** 239 /** 242 * @note Publicly readable. Written only by 240 * @note Publicly readable. Written only by sos_fs_manager_type::mount() 243 */ 241 */ 244 struct sos_fs_manager_type * fs_type; 242 struct sos_fs_manager_type * fs_type; 245 243 246 /** 244 /** 247 * Usually, a filesystem relies on a device 245 * Usually, a filesystem relies on a device (disk, network, ram, 248 * ...) to fetch its data. This is the locat 246 * ...) to fetch its data. This is the location of the device. 249 * 247 * 250 * @note Publicly readable. Written only by 248 * @note Publicly readable. Written only by fs.c 251 */ 249 */ 252 struct sos_fs_node * device; 250 struct sos_fs_node * device; 253 251 254 #define SOS_FS_MOUNT_SYNC (1 << 0) 252 #define SOS_FS_MOUNT_SYNC (1 << 0) 255 #define SOS_FS_MOUNT_READONLY (1 << 1) 253 #define SOS_FS_MOUNT_READONLY (1 << 1) 256 #define SOS_FS_MOUNT_NOEXEC (1 << 2) 254 #define SOS_FS_MOUNT_NOEXEC (1 << 2) 257 /** 255 /** 258 * Is this FS read-only, without EXEC file p 256 * Is this FS read-only, without EXEC file permission, write-through 259 * ? Or-red combination of the SOS_FS_MOUNT_ 257 * ? Or-red combination of the SOS_FS_MOUNT_ flags 260 * 258 * 261 * @note Publicly readable. Written only by 259 * @note Publicly readable. Written only by fs.c 262 */ 260 */ 263 sos_ui32_t flags; 261 sos_ui32_t flags; 264 262 265 /** 263 /** 266 * The namespace node that is the root of TH 264 * The namespace node that is the root of THIS file system mounting 267 * 265 * 268 * @note Publicly readable. Written only by 266 * @note Publicly readable. Written only by fs.c 269 */ 267 */ 270 struct sos_fs_nscache_node * root; 268 struct sos_fs_nscache_node * root; 271 269 272 /** 270 /** 273 * List of dirty nodes. These are the nodes 271 * List of dirty nodes. These are the nodes that need to be written 274 * back to disk. With FS supporting deferred 272 * back to disk. With FS supporting deferred-writes, the 275 * sos_fs_sync() function will use this list 273 * sos_fs_sync() function will use this list to flush the dirty 276 * nodes back to disk. 274 * nodes back to disk. 277 * 275 * 278 * @note Reserved to fs.c 276 * @note Reserved to fs.c 279 */ 277 */ 280 struct sos_fs_node * dirty_nodes; 278 struct sos_fs_node * dirty_nodes; 281 279 282 /** 280 /** 283 * Build a fresh new FS node at the given lo 281 * Build a fresh new FS node at the given location. This implies 284 * the allocation of a new sos_fs_node struc 282 * the allocation of a new sos_fs_node structure in memory 285 * 283 * 286 * @note Mandatory, may block. Appropriate l 284 * @note Mandatory, may block. Appropriate locking MUST be implemented 287 */ 285 */ 288 sos_ret_t (*fetch_node_from_disk)(struct sos 286 sos_ret_t (*fetch_node_from_disk)(struct sos_fs_manager_instance * this, 289 sos_ui64_t 287 sos_ui64_t storage_location, 290 struct sos 288 struct sos_fs_node ** result); 291 289 292 /** 290 /** 293 * Build a fresh new FS node ON THE DISK of 291 * Build a fresh new FS node ON THE DISK of the given type (dir, 294 * plain file, symlink, ...), completely emp 292 * plain file, symlink, ...), completely empty ; return a newly 295 * allocated IN-MEMORY node structure repres 293 * allocated IN-MEMORY node structure representing it 296 * 294 * 297 * @param open_creat_flags is the open_flags 295 * @param open_creat_flags is the open_flags parameter passed to 298 * sos_fs_open() when O_CREAT is set. 0 when 296 * sos_fs_open() when O_CREAT is set. 0 when allocated trough 299 * creat/mkdir/mknod/symlink 297 * creat/mkdir/mknod/symlink 300 * 298 * 301 * @note Mandatory, may block. Appropriate l 299 * @note Mandatory, may block. Appropriate locking MUST be implemented 302 */ 300 */ 303 sos_ret_t (*allocate_new_node)(struct sos_fs 301 sos_ret_t (*allocate_new_node)(struct sos_fs_manager_instance * this, 304 sos_fs_node_t 302 sos_fs_node_type_t type, 305 const struct 303 const struct sos_process * creator, 306 sos_ui32_t ac 304 sos_ui32_t access_rights, 307 sos_ui32_t op 305 sos_ui32_t open_creat_flags, 308 struct sos_fs 306 struct sos_fs_node ** result); 309 307 310 /** 308 /** 311 * Return filesystem status (RTFM df) 309 * Return filesystem status (RTFM df) 312 * 310 * 313 * @note Optional, may block. Appropriate lo 311 * @note Optional, may block. Appropriate locking MUST be implemented 314 */ 312 */ 315 sos_ret_t (*statfs)(struct sos_fs_manager_in 313 sos_ret_t (*statfs)(struct sos_fs_manager_instance * this, 316 struct sos_fs_statfs * r 314 struct sos_fs_statfs * result); 317 315 318 /** 316 /** 319 * Comparison callback called when looking f 317 * Comparison callback called when looking for file/dirs in the 320 * namespace cache. Normally, a usual lexico 318 * namespace cache. Normally, a usual lexicographical comparison is 321 * done (when this function points to NULL). 319 * done (when this function points to NULL). But for some FS, it 322 * might be useful to use another comparison 320 * might be useful to use another comparison function (eg for 323 * case-insensitive FS) 321 * case-insensitive FS) 324 * 322 * 325 * @note Optional (may be NULL), must NOT bl 323 * @note Optional (may be NULL), must NOT block 326 */ 324 */ 327 sos_bool_t (*nsnode_same_name)(const char * 325 sos_bool_t (*nsnode_same_name)(const char * name1, sos_ui16_t namelen1, 328 const char * 326 const char * name2, sos_ui16_t namelen2); 329 327 330 /** 328 /** 331 * Hash table of the struct sos_fs_node of t 329 * Hash table of the struct sos_fs_node of this filesystem instance 332 * loaded in memory: key=storage_location, e 330 * loaded in memory: key=storage_location, element=sos_fs_node 333 */ 331 */ 334 struct sos_hash_table * nodecache; 332 struct sos_hash_table * nodecache; 335 333 336 /** 334 /** 337 * Unique identifier of this FS (used in syn 335 * Unique identifier of this FS (used in sync method, updated by 338 * fs.c). This enables sync_all_fs to be res 336 * fs.c). This enables sync_all_fs to be resilient to mount/umount 339 * and (un)register_fs_type/instance 337 * and (un)register_fs_type/instance 340 */ 338 */ 341 sos_ui64_t uid; 339 sos_ui64_t uid; 342 340 343 void * custom_data; 341 void * custom_data; 344 342 345 /** Linkage for the list of instances for th 343 /** Linkage for the list of instances for the underlying fs type */ 346 struct sos_fs_manager_instance * prev, * nex 344 struct sos_fs_manager_instance * prev, * next; 347 }; 345 }; 348 346 349 347 350 /** 348 /** 351 * The CENTRAL data structure of the whole thi 349 * The CENTRAL data structure of the whole thing. A so-called "inode" 352 * 350 * 353 * This represents the meta-information relate 351 * This represents the meta-information related to a file on disk: its 354 * permission, where its data is located. Actu 352 * permission, where its data is located. Actually, in SOS, these 355 * information are not stored in this structur 353 * information are not stored in this structure. Instead, we define a 356 * series of methods in this structure that MU 354 * series of methods in this structure that MUST be implemented by the 357 * FS and that realize the higher level operat 355 * FS and that realize the higher level operations needed by the 358 * OS. These operations will rely on the meta- 356 * OS. These operations will rely on the meta-information that the FS 359 * code MUST define and manage by itself (henc 357 * code MUST define and manage by itself (hence the 360 * sos_fs_node::custom_data field). 358 * sos_fs_node::custom_data field). 361 */ 359 */ 362 struct sos_fs_node 360 struct sos_fs_node 363 { 361 { 364 /** 362 /** 365 * An struct sos_fs_node always belong to ex 363 * An struct sos_fs_node always belong to exactly ONE file system 366 */ 364 */ 367 struct sos_fs_manager_instance * fs; 365 struct sos_fs_manager_instance * fs; 368 366 369 /** 367 /** 370 * The so-called "inode": location of this n 368 * The so-called "inode": location of this node inside the FS 371 * instance. Updated by struct 369 * instance. Updated by struct 372 * sos_fs_manager_instance::fetch_node_from_ 370 * sos_fs_manager_instance::fetch_node_from_disk() 373 */ 371 */ 374 sos_ui64_t storage_location; 372 sos_ui64_t storage_location; 375 373 376 /** 374 /** 377 * Number of ON-DISK links to this node. 375 * Number of ON-DISK links to this node. 378 * 376 * 379 * - For everything but directories: the num 377 * - For everything but directories: the number of hard links to the file 380 * - For directories: 1 + the number of chil 378 * - For directories: 1 + the number of children nodes 381 * 379 * 382 * @note Publicly readable. Written only by 380 * @note Publicly readable. Written only by 383 * sos_fs_node_ops_dir::link() and sos_fs_no 381 * sos_fs_node_ops_dir::link() and sos_fs_node_ops_dir::unlink() 384 */ 382 */ 385 sos_count_t ondisk_lnk_cnt; 383 sos_count_t ondisk_lnk_cnt; 386 384 387 /** 385 /** 388 * Number of IN-MEMORY nscache_nodes referen 386 * Number of IN-MEMORY nscache_nodes referencing this FS node. 389 * 387 * 390 * Corresponds to the number of struct sos_f 388 * Corresponds to the number of struct sos_fs_nscache_node pointing 391 * to this node. This could be as much as on 389 * to this node. This could be as much as ondisk_lnk_cnt + 1, but is 392 * usually less 390 * usually less 393 * 391 * 394 * @note Reserved to fs.c 392 * @note Reserved to fs.c 395 */ 393 */ 396 sos_count_t inmem_ref_cnt; 394 sos_count_t inmem_ref_cnt; 397 395 398 /** 396 /** 399 * Directory, symlink, ... 397 * Directory, symlink, ... 400 * 398 * 401 * @see sos_fs_node_type_t 399 * @see sos_fs_node_type_t 402 * 400 * 403 * @note Publicly readable. Written only by 401 * @note Publicly readable. Written only by fs.c 404 */ 402 */ 405 sos_fs_node_type_t type; 403 sos_fs_node_type_t type; 406 404 407 #define SOS_FS_READABLE 00400 405 #define SOS_FS_READABLE 00400 408 #define SOS_FS_WRITABLE 00200 406 #define SOS_FS_WRITABLE 00200 409 #define SOS_FS_EXECUTABLE 00100 407 #define SOS_FS_EXECUTABLE 00100 410 /** 408 /** 411 * read/write, ... @see the SOS_FS_*ABLE fla 409 * read/write, ... @see the SOS_FS_*ABLE flags 412 * @note Publicly readable. Written only by 410 * @note Publicly readable. Written only by fs.c 413 */ 411 */ 414 sos_ui32_t access_rights; 412 sos_ui32_t access_rights; 415 413 416 /** 414 /** 417 * @note Reserved to fs.c 415 * @note Reserved to fs.c 418 */ 416 */ 419 sos_bool_t dirty; 417 sos_bool_t dirty; 420 418 421 /** 419 /** 422 * Incremented each time one of the opened f 420 * Incremented each time one of the opened files for this node is 423 * modified 421 * modified 424 * @note Publicly readable. Written only by 422 * @note Publicly readable. Written only by fs.c 425 */ 423 */ 426 sos_lcount_t generation; 424 sos_lcount_t generation; 427 425 428 /** << 429 * @note Available only for device files (ch << 430 * @note Publicly readable. Written only by << 431 * sos_fs_manager_instance::fetch_node_from_ << 432 */ << 433 struct sos_fs_dev_id_t << 434 { << 435 sos_ui32_t device_class; /**< aka "majo << 436 sos_ui32_t device_instance; /**< aka "mino << 437 } dev_id; << 438 << 439 /** Operations common to all node types */ 426 /** Operations common to all node types */ 440 struct sos_fs_node_ops_file *ops_file; 427 struct sos_fs_node_ops_file *ops_file; 441 428 442 /** Operations specific to some node types * 429 /** Operations specific to some node types */ 443 union 430 union 444 { 431 { 445 /** when type == SOS_FS_NODE_DIRECTORY */ 432 /** when type == SOS_FS_NODE_DIRECTORY */ 446 struct sos_fs_node_ops_dir *ops_dir; 433 struct sos_fs_node_ops_dir *ops_dir; 447 434 448 /** when type == SOS_FS_NODE_SYMLINK */ 435 /** when type == SOS_FS_NODE_SYMLINK */ 449 struct sos_fs_node_ops_symlink *ops_symli 436 struct sos_fs_node_ops_symlink *ops_symlink; 450 }; /* Anonymous union (gcc extension) */ 437 }; /* Anonymous union (gcc extension) */ 451 438 452 439 453 /** 440 /** 454 * Flush any change to disk << 455 * << 456 * @note Mandatory, may block. Appropriate l << 457 */ << 458 sos_ret_t (*sync)(struct sos_fs_node *this); << 459 << 460 << 461 /** << 462 * Simply free this FS node from the kernel 441 * Simply free this FS node from the kernel memory: it does NOT 463 * mean that the corresponding on-disk node 442 * mean that the corresponding on-disk node is free ! Actually, the 464 * corresponding ON-DISK node is free iff on 443 * corresponding ON-DISK node is free iff ondisk_lnk_cnt == 0. No 465 * need to sync anything to disk, as the VFS 444 * need to sync anything to disk, as the VFS will sync the node 466 * before calling this method 445 * before calling this method 467 * 446 * 468 * @note Mandatory, may block, no special lo 447 * @note Mandatory, may block, no special locking needed 469 */ 448 */ 470 sos_ret_t (*destructor)(struct sos_fs_node * 449 sos_ret_t (*destructor)(struct sos_fs_node * this); 471 450 472 /** 451 /** 473 * Called when a process opens the node 452 * Called when a process opens the node 474 * 453 * 475 * @note Mandatory, may block. Appropriate l 454 * @note Mandatory, may block. Appropriate locking MUST be implemented 476 * @note FS-specific EXCPET for device speci << 477 * block) because they are handled in an uni << 478 * chardev/blockdev subsystems << 479 * @note As a consequence, FS code can safel << 480 * never a character or block device << 481 */ 455 */ 482 sos_ret_t (*new_opened_file)(struct sos_fs_n 456 sos_ret_t (*new_opened_file)(struct sos_fs_node * this, 483 const struct so 457 const struct sos_process * owner, 484 sos_ui32_t open 458 sos_ui32_t open_flags, 485 struct sos_fs_o 459 struct sos_fs_opened_file ** result_of); 486 460 487 /** 461 /** 488 * Called when a process opens the node 462 * Called when a process opens the node 489 * 463 * 490 * @note Mandatory, may block. Appropriate l 464 * @note Mandatory, may block. Appropriate locking MUST be implemented 491 * @note FS-specific EXCEPT for device speci << 492 * block) because they are handled in an uni << 493 * chardev/blockdev subsystems << 494 * @note As a consequence, FS code can safel << 495 * never a character or block device << 496 */ 465 */ 497 sos_ret_t (*close_opened_file)(struct sos_fs 466 sos_ret_t (*close_opened_file)(struct sos_fs_node * this, 498 struct sos_fs 467 struct sos_fs_opened_file * of); 499 468 500 /** 469 /** 501 * This should hold the meta information for 470 * This should hold the meta information for this node as needed by 502 * the FS instance. 471 * the FS instance. 503 */ 472 */ 504 void * custom_data; 473 void * custom_data; 505 474 506 /** Hash linkage entry for this FS node in t 475 /** Hash linkage entry for this FS node in the nodecache 507 dictionary */ 476 dictionary */ 508 struct sos_hash_linkage hlink_nodecache; 477 struct sos_hash_linkage hlink_nodecache; 509 478 510 /** Linkage to list the dirty nodes of the g 479 /** Linkage to list the dirty nodes of the given FS */ 511 struct sos_fs_node *prev_dirty, *next_dirty; 480 struct sos_fs_node *prev_dirty, *next_dirty; 512 }; 481 }; 513 482 514 483 515 484 516 /** 485 /** 517 * The list of methods implementing the basic 486 * The list of methods implementing the basic VFS operations on the 518 * given struct sos_fs_node 487 * given struct sos_fs_node 519 * 488 * 520 * @see sos_fs_node::ops_file 489 * @see sos_fs_node::ops_file 521 */ 490 */ 522 struct sos_fs_node_ops_file 491 struct sos_fs_node_ops_file 523 { 492 { 524 /** 493 /** 525 * Change size of file 494 * Change size of file 526 * 495 * 527 * @note Optional, may block. Appropriate lo 496 * @note Optional, may block. Appropriate locking MUST be implemented 528 */ 497 */ 529 sos_ret_t (*truncate)(struct sos_fs_node *th 498 sos_ret_t (*truncate)(struct sos_fs_node *this, 530 sos_lsoffset_t length) 499 sos_lsoffset_t length); 531 500 532 /** 501 /** 533 * Retrieve the status (eg size) of the file 502 * Retrieve the status (eg size) of the file 534 * 503 * 535 * @note Mandatory, may block. Appropriate l 504 * @note Mandatory, may block. Appropriate locking MUST be implemented 536 */ 505 */ 537 sos_ret_t (*stat)(struct sos_fs_node * this, 506 sos_ret_t (*stat)(struct sos_fs_node * this, 538 struct sos_fs_stat * resul 507 struct sos_fs_stat * result); 539 508 540 /** 509 /** >> 510 * Flush any change to disk >> 511 * >> 512 * @note Mandatory, may block. Appropriate locking MUST be implemented >> 513 */ >> 514 sos_ret_t (*sync)(struct sos_fs_node *this); >> 515 >> 516 /** 541 * Change the sos_fs_node::access_rights att 517 * Change the sos_fs_node::access_rights attribute 542 * 518 * 543 * @note Mandatory, may block. Appropriate l 519 * @note Mandatory, may block. Appropriate locking MUST be implemented 544 */ 520 */ 545 sos_ret_t (*chmod)(struct sos_fs_node * this 521 sos_ret_t (*chmod)(struct sos_fs_node * this, 546 sos_ui32_t new_access_rig 522 sos_ui32_t new_access_rights); 547 }; 523 }; 548 524 549 525 550 /** 526 /** 551 * The list of methods implementing the basic 527 * The list of methods implementing the basic VFS symlink operations 552 * 528 * 553 * @see sos_fs_node::ops_symlink 529 * @see sos_fs_node::ops_symlink 554 */ 530 */ 555 struct sos_fs_node_ops_symlink 531 struct sos_fs_node_ops_symlink 556 { 532 { 557 /** 533 /** 558 * Used by the _kernel_ to resolve the symli 534 * Used by the _kernel_ to resolve the symlinks. To change/create a 559 * symlink target, it is needed only from us 535 * symlink target, it is needed only from userland: the read/write 560 * methods are made for this 536 * methods are made for this 561 * 537 * 562 * @param target Pointer to the string repre 538 * @param target Pointer to the string representing the target's 563 * path, allocated for the fs_node's lifetim 539 * path, allocated for the fs_node's lifetime ! 564 * 540 * 565 * @note Mandatory, may block. Appropriate l 541 * @note Mandatory, may block. Appropriate locking MUST be implemented 566 */ 542 */ 567 sos_ret_t (*expand)(struct sos_fs_node *this 543 sos_ret_t (*expand)(struct sos_fs_node *this, 568 char const ** target, 544 char const ** target, 569 sos_size_t * target_len) 545 sos_size_t * target_len); 570 }; 546 }; 571 547 572 548 573 /** 549 /** 574 * The list of methods implementing the basic 550 * The list of methods implementing the basic VFS directory operations 575 * 551 * 576 * @see sos_fs_node::ops_dir 552 * @see sos_fs_node::ops_dir 577 */ 553 */ 578 struct sos_fs_node_ops_dir 554 struct sos_fs_node_ops_dir 579 { 555 { 580 /** 556 /** 581 * Look for the on-disk location of the sos_ 557 * Look for the on-disk location of the sos_fs_node having the given 582 * name 558 * name 583 * 559 * 584 * @note Mandatory, may block. Appropriate l 560 * @note Mandatory, may block. Appropriate locking MUST be implemented 585 */ 561 */ 586 sos_ret_t (*lookup)(struct sos_fs_node *this 562 sos_ret_t (*lookup)(struct sos_fs_node *this, 587 const char * name, sos_u 563 const char * name, sos_ui16_t namelen, 588 sos_ui64_t * result_stor 564 sos_ui64_t * result_storage_location); 589 565 590 /** 566 /** 591 * Add a new reference in the current sos_fs 567 * Add a new reference in the current sos_fs_node to the on-disk 592 * location of the given sos_fs_node 568 * location of the given sos_fs_node 593 * 569 * 594 * @note Responsible for updating this->ondi 570 * @note Responsible for updating this->ondisk_lnk_cnt 595 * @note Mandatory for writable directories, 571 * @note Mandatory for writable directories, may block. Appropriate 596 * locking MUST be implemented 572 * locking MUST be implemented 597 */ 573 */ 598 sos_ret_t (*link)(struct sos_fs_node *this, 574 sos_ret_t (*link)(struct sos_fs_node *this, 599 const struct sos_process * 575 const struct sos_process *actor, 600 const char * entry_name, s 576 const char * entry_name, sos_ui16_t entry_namelen, 601 struct sos_fs_node * node) 577 struct sos_fs_node * node); 602 578 603 /** 579 /** 604 * Remove the entry in the current sos_fs_no 580 * Remove the entry in the current sos_fs_node for the on-disk 605 * location with the given name 581 * location with the given name 606 * 582 * 607 * @note Responsible for updating this->ondi 583 * @note Responsible for updating this->ondisk_lnk_cnt 608 * @note Mandatory for writable directories, 584 * @note Mandatory for writable directories, may block. Appropriate 609 * locking MUST be implemented 585 * locking MUST be implemented 610 */ 586 */ 611 sos_ret_t (*unlink)(struct sos_fs_node *this 587 sos_ret_t (*unlink)(struct sos_fs_node *this, 612 const struct sos_process 588 const struct sos_process *actor, 613 const char * entry_name, 589 const char * entry_name, sos_ui16_t entry_namelen); 614 }; 590 }; 615 591 616 592 617 /** 593 /** 618 * The data structure holding information and 594 * The data structure holding information and method related to a 619 * particular usage of a file. A so-called "st 595 * particular usage of a file. A so-called "struct file" 620 * 596 * 621 * This represents the kernel structure behind 597 * This represents the kernel structure behind a "file descriptor" or 622 * behind a chdir/chroot. Among other things, 598 * behind a chdir/chroot. Among other things, it holds the methods 623 * responsible for reading/writing into the fi 599 * responsible for reading/writing into the file, and for moving the 624 * file pointer (see @sos_fs_opened_file::posi 600 * file pointer (see @sos_fs_opened_file::position) inside it. 625 */ 601 */ 626 struct sos_fs_opened_file 602 struct sos_fs_opened_file 627 { 603 { 628 /** The process that opened the file/dir */ 604 /** The process that opened the file/dir */ 629 const struct sos_process * owner; 605 const struct sos_process * owner; 630 606 631 /** 607 /** 632 * The reference to the sos_fs_nscache_node 608 * The reference to the sos_fs_nscache_node and, hence, to the underlying sos_fs_node. 633 * 609 * 634 * Used to cache the in-memory fs nodes 610 * Used to cache the in-memory fs nodes 635 */ 611 */ 636 struct sos_fs_nscache_node * direntry; 612 struct sos_fs_nscache_node * direntry; 637 613 638 /** Use for memory-management */ 614 /** Use for memory-management */ 639 sos_count_t ref_cnt; 615 sos_count_t ref_cnt; 640 616 641 /** 617 /** 642 * Always > 0 (ie max size = 2^63-1 = 9.2 10 618 * Always > 0 (ie max size = 2^63-1 = 9.2 10^18). We make it 643 * "signed" here to limit its range. Because 619 * "signed" here to limit its range. Because we must be able to 644 * seek to the begining of the file with SEE 620 * seek to the begining of the file with SEEK_END and a negative 645 * offset, so the max size of the file must 621 * offset, so the max size of the file must be reachable by a lseek 646 * offset 622 * offset 647 * 623 * 648 * @note reserved to filesystem instance cod 624 * @note reserved to filesystem instance code. Not modified nor used 649 * by fs.c 625 * by fs.c 650 */ 626 */ 651 sos_lsoffset_t position; 627 sos_lsoffset_t position; 652 628 653 /** 629 /** 654 * Incremented each time this opened file is 630 * Incremented each time this opened file is modified 655 * 631 * 656 * Used to implement a readdir method resili 632 * Used to implement a readdir method resilient to 657 * creat/mkdir/rmdir/unlink 633 * creat/mkdir/rmdir/unlink 658 */ 634 */ 659 sos_lcount_t generation; 635 sos_lcount_t generation; 660 636 661 /** 637 /** 662 * @see SOS_FS_OPEN_* flags 638 * @see SOS_FS_OPEN_* flags 663 */ 639 */ 664 sos_ui32_t open_flags; 640 sos_ui32_t open_flags; 665 641 666 /** Operations common to all node types */ 642 /** Operations common to all node types */ 667 struct sos_fs_ops_opened_file * ops_file; 643 struct sos_fs_ops_opened_file * ops_file; 668 644 669 /** Operations specific to some node types * 645 /** Operations specific to some node types */ 670 union 646 union 671 { 647 { 672 /** when direntry->fs_node->type == SOS_FS 648 /** when direntry->fs_node->type == SOS_FS_NODE_DIRECTORY */ 673 struct sos_fs_ops_opened_dir * ops_di 649 struct sos_fs_ops_opened_dir * ops_dir; 674 << 675 /** when direntry->fs_node->type == SOS_FS << 676 struct sos_fs_ops_opened_chardev * ops_ch << 677 }; /* Anonymous union (gcc extension) */ 650 }; /* Anonymous union (gcc extension) */ 678 651 679 /** 652 /** 680 * Called upon fork() to duplicate all the o 653 * Called upon fork() to duplicate all the opened files 681 * << 682 * @note FS-specific EXCEPT for device speci << 683 * block) because they are handled in an uni << 684 * chardev/blockdev subsystems << 685 * @note As a consequence, FS code can safel << 686 * never a character or block device << 687 */ 654 */ 688 sos_ret_t (*duplicate)(struct sos_fs_opened_ 655 sos_ret_t (*duplicate)(struct sos_fs_opened_file *this, 689 const struct sos_proc 656 const struct sos_process * for_owner, 690 struct sos_fs_opened_ 657 struct sos_fs_opened_file **result); 691 658 692 void * custom_data; 659 void * custom_data; 693 }; 660 }; 694 661 695 662 696 /** 663 /** 697 * Reference position for sos_fs_seek 664 * Reference position for sos_fs_seek 698 */ 665 */ 699 typedef enum { SOS_SEEK_SET=42, 666 typedef enum { SOS_SEEK_SET=42, 700 SOS_SEEK_CUR=24, 667 SOS_SEEK_CUR=24, 701 SOS_SEEK_END=84 } sos_seek_when 668 SOS_SEEK_END=84 } sos_seek_whence_t; 702 /** 669 /** 703 * The list of methods implementing the basic 670 * The list of methods implementing the basic VFS opened file 704 * operations 671 * operations 705 * 672 * 706 * See the Unix manual pages, they basically f 673 * See the Unix manual pages, they basically form the interfaces to to 707 * these functions 674 * these functions 708 * 675 * 709 * @see sos_fs_opened_file::ops_file 676 * @see sos_fs_opened_file::ops_file 710 */ 677 */ 711 struct sos_fs_ops_opened_file 678 struct sos_fs_ops_opened_file 712 { 679 { 713 /** 680 /** 714 * @note Mandatory, may block. Appropriate l 681 * @note Mandatory, may block. Appropriate locking MUST be implemented 715 * @note Please call sos_fs_mark_dirty() if 682 * @note Please call sos_fs_mark_dirty() if disk contents is changed 716 */ 683 */ 717 sos_ret_t (*seek)(struct sos_fs_opened_file 684 sos_ret_t (*seek)(struct sos_fs_opened_file *this, 718 sos_lsoffset_t offset, 685 sos_lsoffset_t offset, 719 sos_seek_whence_t whence, 686 sos_seek_whence_t whence, 720 /* out */ sos_lsoffset_t * 687 /* out */ sos_lsoffset_t * result_position); 721 688 722 /** 689 /** 723 * @note Mandatory, may block. Appropriate l 690 * @note Mandatory, may block. Appropriate locking MUST be implemented 724 * @note Please call sos_fs_mark_dirty() if 691 * @note Please call sos_fs_mark_dirty() if disk contents is changed 725 */ 692 */ 726 sos_ret_t (*read)(struct sos_fs_opened_file 693 sos_ret_t (*read)(struct sos_fs_opened_file *this, 727 sos_uaddr_t dest_buf, 694 sos_uaddr_t dest_buf, 728 sos_size_t * /* in/out */l 695 sos_size_t * /* in/out */len); 729 696 730 /** 697 /** 731 * @note Optional (might be NULL), may block 698 * @note Optional (might be NULL), may block. Appropriate locking 732 * MUST be implemented 699 * MUST be implemented 733 * @note Please call sos_fs_mark_dirty() if 700 * @note Please call sos_fs_mark_dirty() if disk contents is changed 734 */ 701 */ 735 sos_ret_t (*write)(struct sos_fs_opened_file 702 sos_ret_t (*write)(struct sos_fs_opened_file *this, 736 sos_uaddr_t src_buf, 703 sos_uaddr_t src_buf, 737 sos_size_t * /* in/out */ 704 sos_size_t * /* in/out */len); 738 705 739 /** 706 /** 740 * @note Optional (might be NULL), may block 707 * @note Optional (might be NULL), may block. Appropriate locking 741 * MUST be implemented 708 * MUST be implemented 742 * @note Please call sos_fs_mark_dirty() if 709 * @note Please call sos_fs_mark_dirty() if disk contents is changed 743 */ 710 */ 744 sos_ret_t (*mmap)(struct sos_fs_opened_file 711 sos_ret_t (*mmap)(struct sos_fs_opened_file *this, 745 sos_uaddr_t *uaddr, sos_si 712 sos_uaddr_t *uaddr, sos_size_t size, 746 sos_ui32_t access_rights, 713 sos_ui32_t access_rights, 747 sos_ui32_t flags, 714 sos_ui32_t flags, 748 sos_luoffset_t offset); 715 sos_luoffset_t offset); 749 716 750 /** 717 /** 751 * @note Optional (might be NULL), may block 718 * @note Optional (might be NULL), may block. Appropriate locking 752 * MUST be implemented 719 * MUST be implemented 753 * @note Please call sos_fs_mark_dirty() if 720 * @note Please call sos_fs_mark_dirty() if disk contents is changed 754 */ 721 */ 755 sos_ret_t (*fcntl)(struct sos_fs_opened_file 722 sos_ret_t (*fcntl)(struct sos_fs_opened_file *this, 756 int req_id, 723 int req_id, 757 sos_ui32_t req_arg /* Usu 724 sos_ui32_t req_arg /* Usually: sos_uaddr_t */); 758 }; 725 }; 759 726 760 727 761 /** << 762 * The list of methods implementing the basic << 763 * operations << 764 * << 765 * @see sos_fs_opened_file::ops_file << 766 */ << 767 struct sos_fs_ops_opened_chardev << 768 { << 769 /** << 770 * @note Optional (might be NULL), may block << 771 * MUST be implemented << 772 * @note Please call sos_fs_mark_dirty() if << 773 */ << 774 sos_ret_t (*ioctl)(struct sos_fs_opened_file << 775 int req_id, << 776 sos_ui32_t req_arg /* Usu << 777 }; << 778 << 779 << 780 /** Data structure that is to be filled by rea 728 /** Data structure that is to be filled by readdir */ 781 struct sos_fs_dirent 729 struct sos_fs_dirent 782 { 730 { 783 sos_ui64_t storage_location; 731 sos_ui64_t storage_location; 784 sos_si64_t offset_in_dirfile; 732 sos_si64_t offset_in_dirfile; 785 sos_ui32_t type; 733 sos_ui32_t type; 786 sos_ui16_t namelen; 734 sos_ui16_t namelen; 787 735 788 #define SOS_FS_DIRENT_NAME_MAXLEN 128 736 #define SOS_FS_DIRENT_NAME_MAXLEN 128 789 char name[SOS_FS_DIRENT_NAME_MAXLEN]; 737 char name[SOS_FS_DIRENT_NAME_MAXLEN]; 790 }; 738 }; 791 739 792 740 793 /** 741 /** 794 * The list of methods implementing the basic 742 * The list of methods implementing the basic VFS opened directory 795 * operations 743 * operations 796 * 744 * 797 * @see sos_fs_opened_file::ops_file 745 * @see sos_fs_opened_file::ops_file 798 */ 746 */ 799 struct sos_fs_ops_opened_dir 747 struct sos_fs_ops_opened_dir 800 { 748 { 801 /** 749 /** 802 * Each time it is called, responsible for f 750 * Each time it is called, responsible for filling the sos_fs_dirent 803 * structure, return -SOS_ENOENT when done. 751 * structure, return -SOS_ENOENT when done. 804 * 752 * 805 * @note Mandatory, may block. Appropriate l 753 * @note Mandatory, may block. Appropriate locking MUST be implemented 806 * @note Please call sos_fs_mark_dirty() if 754 * @note Please call sos_fs_mark_dirty() if disk contents is changed 807 */ 755 */ 808 sos_ret_t (*readdir)(struct sos_fs_opened_fi 756 sos_ret_t (*readdir)(struct sos_fs_opened_file *this, 809 struct sos_fs_dirent * 757 struct sos_fs_dirent * result); 810 }; 758 }; 811 759 812 760 813 761 814 /** 762 /** 815 * Used by the stat calls 763 * Used by the stat calls 816 * 764 * 817 * @see sos_fs_node_ops_file::stat 765 * @see sos_fs_node_ops_file::stat 818 */ 766 */ 819 struct sos_fs_stat 767 struct sos_fs_stat 820 { 768 { 821 struct sos_fs_dev_id_t st_rdev; << 822 sos_fs_node_type_t st_type; 769 sos_fs_node_type_t st_type; 823 sos_ui64_t st_storage_location; 770 sos_ui64_t st_storage_location; 824 sos_ui32_t st_access_rights; 771 sos_ui32_t st_access_rights; 825 sos_count_t st_nlink; 772 sos_count_t st_nlink; 826 sos_si64_t st_size; 773 sos_si64_t st_size; 827 }; 774 }; 828 775 829 776 830 /** 777 /** 831 * Used by the statvfs calls 778 * Used by the statvfs calls 832 * 779 * 833 * @see sos_fs_manager_instance::statfs 780 * @see sos_fs_manager_instance::statfs 834 */ 781 */ 835 struct sos_fs_statfs 782 struct sos_fs_statfs 836 { 783 { 837 struct sos_fs_dev_id_t f_rdev; << 838 sos_size_t f_sz_total; /**< Tot 784 sos_size_t f_sz_total; /**< Total size */ 839 sos_size_t f_sz_free; /**< Siz 785 sos_size_t f_sz_free; /**< Size left on device */ 840 sos_count_t f_node_total;/**< Tot 786 sos_count_t f_node_total;/**< Total allocatable FS nodes */ 841 sos_count_t f_node_avail;/**< Num 787 sos_count_t f_node_avail;/**< Number of available free FS nodes */ 842 sos_ui32_t f_flags; 788 sos_ui32_t f_flags; 843 }; 789 }; 844 790 845 791 846 /** 792 /** 847 * Must be called AFTER the FS manager types n 793 * Must be called AFTER the FS manager types needed to mount the root 848 * filesystem have been registered 794 * filesystem have been registered 849 */ 795 */ 850 sos_ret_t sos_fs_subsystem_setup(const char * 796 sos_ret_t sos_fs_subsystem_setup(const char * root_device, 851 const char * 797 const char * fs_type, 852 const char * 798 const char * mount_args, 853 struct sos_fs 799 struct sos_fs_manager_instance ** result_rootfs); 854 800 855 801 856 /* ****************************************** 802 /* *************************************************************** 857 * The Following functions are relatively stan 803 * The Following functions are relatively standard 858 * 804 * 859 * @see Unix manual pages for details 805 * @see Unix manual pages for details 860 */ 806 */ 861 807 862 808 863 /** 809 /** 864 * mount a file system 810 * mount a file system 865 * 811 * 866 * @param actor process calling mount 812 * @param actor process calling mount 867 * @param _src_path(len) may be NULL (as for v 813 * @param _src_path(len) may be NULL (as for virtfs or /proc) 868 * @fsname the name of the filesystem type to 814 * @fsname the name of the filesystem type to mount 869 * @args any args passed to the sos_fs_manager 815 * @args any args passed to the sos_fs_manager_type::mount method 870 * @result_fs the resulting filesystem instanc 816 * @result_fs the resulting filesystem instance 871 */ 817 */ 872 sos_ret_t sos_fs_mount(struct sos_process * ac 818 sos_ret_t sos_fs_mount(struct sos_process * actor, 873 const char * _src_path, 819 const char * _src_path, 874 sos_size_t _src_pathlen 820 sos_size_t _src_pathlen, 875 const char * _dst_path, 821 const char * _dst_path, 876 sos_size_t _dst_pathlen 822 sos_size_t _dst_pathlen, 877 const char * fsname, 823 const char * fsname, 878 sos_ui32_t mountflags, 824 sos_ui32_t mountflags, 879 const char * args, 825 const char * args, 880 struct sos_fs_manager_i 826 struct sos_fs_manager_instance ** /*out*/result_fs); 881 827 882 /** 828 /** 883 * unmount the filesystem at the given locatio 829 * unmount the filesystem at the given location 884 */ 830 */ 885 sos_ret_t sos_fs_umount(struct sos_process * a 831 sos_ret_t sos_fs_umount(struct sos_process * actor, 886 const char * _mountpoi 832 const char * _mountpoint_path, 887 sos_size_t _mountpoint 833 sos_size_t _mountpoint_pathlen); 888 834 889 /** 835 /** 890 * Flush all the dirty nodes of all the FS to 836 * Flush all the dirty nodes of all the FS to disk 891 */ 837 */ 892 sos_ret_t sos_fs_sync_all_fs(); 838 sos_ret_t sos_fs_sync_all_fs(); 893 839 894 /** 840 /** 895 * Retrieve filesystem status, or return -SOS_ !! 841 * Retrieve filesystem status, or return -SOS_ENOSUP if filesystem 896 * cannot report this 842 * cannot report this 897 */ 843 */ 898 sos_ret_t sos_fs_vfstat(const struct sos_proce 844 sos_ret_t sos_fs_vfstat(const struct sos_process * actor, 899 const char * _path, 845 const char * _path, 900 sos_size_t _pathlen, 846 sos_size_t _pathlen, 901 struct sos_fs_statfs * 847 struct sos_fs_statfs * result); 902 848 903 /** 849 /** 904 * Open flags 850 * Open flags 905 */ 851 */ 906 #define SOS_FS_OPEN_EXCL (1 << 0) 852 #define SOS_FS_OPEN_EXCL (1 << 0) 907 #define SOS_FS_OPEN_CREAT (1 << 1) 853 #define SOS_FS_OPEN_CREAT (1 << 1) 908 #define SOS_FS_OPEN_TRUNC (1 << 2) !! 854 #define SOS_FS_OPEN_NOFOLLOW (1 << 2) 909 #define SOS_FS_OPEN_NOFOLLOW (1 << 3) !! 855 #define SOS_FS_OPEN_DIRECTORY (1 << 3) /* Incompatible with CREAT */ 910 #define SOS_FS_OPEN_DIRECTORY (1 << 4) /* In !! 856 #define SOS_FS_OPEN_SYNC (1 << 4) 911 #define SOS_FS_OPEN_SYNC (1 << 5) !! 857 #define SOS_FS_OPEN_KEEPONEXEC (1 << 5) /* By default, files are closed 912 #define SOS_FS_OPEN_CLOSEONEXEC (1 << 6) /* By !! 858 upon an exec() */ 913 op << 914 859 915 #define SOS_FS_OPEN_READ (1 << 16) 860 #define SOS_FS_OPEN_READ (1 << 16) 916 #define SOS_FS_OPEN_WRITE (1 << 17) 861 #define SOS_FS_OPEN_WRITE (1 << 17) 917 862 918 863 919 /** 864 /** 920 * FS access rights 865 * FS access rights 921 */ 866 */ 922 #define SOS_FS_S_IRUSR 00400 867 #define SOS_FS_S_IRUSR 00400 923 #define SOS_FS_S_IWUSR 00200 868 #define SOS_FS_S_IWUSR 00200 924 #define SOS_FS_S_IXUSR 00100 869 #define SOS_FS_S_IXUSR 00100 925 870 926 #define SOS_FS_S_IRWXALL 07777 /* For symlinks 871 #define SOS_FS_S_IRWXALL 07777 /* For symlinks */ 927 872 928 sos_ret_t sos_fs_open(const struct sos_process 873 sos_ret_t sos_fs_open(const struct sos_process *owner, 929 const char *_path, 874 const char *_path, 930 sos_size_t _pathlen, 875 sos_size_t _pathlen, 931 sos_ui32_t open_flags, 876 sos_ui32_t open_flags, 932 sos_ui32_t creat_access_ 877 sos_ui32_t creat_access_rights, 933 struct sos_fs_opened_fil 878 struct sos_fs_opened_file ** of); 934 879 935 sos_ret_t sos_fs_close(struct sos_fs_opened_fi 880 sos_ret_t sos_fs_close(struct sos_fs_opened_file * of); 936 881 937 sos_ret_t sos_fs_read(struct sos_fs_opened_fil 882 sos_ret_t sos_fs_read(struct sos_fs_opened_file * of, 938 sos_uaddr_t dest_buf, 883 sos_uaddr_t dest_buf, 939 sos_size_t * /* in/ou */ 884 sos_size_t * /* in/ou */len); 940 885 941 sos_ret_t sos_fs_readdir(struct sos_fs_opened_ 886 sos_ret_t sos_fs_readdir(struct sos_fs_opened_file * of, 942 struct sos_fs_dirent 887 struct sos_fs_dirent * result); 943 888 944 sos_ret_t sos_fs_write(struct sos_fs_opened_fi 889 sos_ret_t sos_fs_write(struct sos_fs_opened_file * of, 945 sos_uaddr_t src_buf, 890 sos_uaddr_t src_buf, 946 sos_size_t * /* in/out 891 sos_size_t * /* in/out */len); 947 892 948 sos_ret_t sos_fs_seek(struct sos_fs_opened_fil 893 sos_ret_t sos_fs_seek(struct sos_fs_opened_file *of, 949 sos_lsoffset_t offset, 894 sos_lsoffset_t offset, 950 sos_seek_whence_t whence 895 sos_seek_whence_t whence, 951 sos_lsoffset_t * result_ 896 sos_lsoffset_t * result_position); 952 897 953 sos_ret_t sos_fs_ftruncate(struct sos_fs_opene 898 sos_ret_t sos_fs_ftruncate(struct sos_fs_opened_file *of, 954 sos_lsoffset_t leng 899 sos_lsoffset_t length); 955 900 956 sos_ret_t sos_fs_mmap(struct sos_fs_opened_fil 901 sos_ret_t sos_fs_mmap(struct sos_fs_opened_file *of, 957 sos_uaddr_t *uaddr, sos_ 902 sos_uaddr_t *uaddr, sos_size_t size, 958 sos_ui32_t access_rights 903 sos_ui32_t access_rights, 959 sos_ui32_t flags, 904 sos_ui32_t flags, 960 sos_luoffset_t offset); 905 sos_luoffset_t offset); 961 906 962 sos_ret_t sos_fs_fsync(struct sos_fs_opened_fi 907 sos_ret_t sos_fs_fsync(struct sos_fs_opened_file * of); 963 908 964 sos_ret_t sos_fs_fcntl(struct sos_fs_opened_fi 909 sos_ret_t sos_fs_fcntl(struct sos_fs_opened_file *of, 965 int req_id, 910 int req_id, 966 sos_ui32_t req_arg /* U 911 sos_ui32_t req_arg /* Usually: sos_uaddr_t */); 967 912 968 sos_ret_t sos_fs_ioctl(struct sos_fs_opened_fi << 969 int req_id, << 970 sos_ui32_t req_arg /* U << 971 << 972 sos_ret_t sos_fs_creat(const struct sos_proces 913 sos_ret_t sos_fs_creat(const struct sos_process * creator, 973 const char * _path, 914 const char * _path, 974 sos_size_t _pathlen, 915 sos_size_t _pathlen, 975 sos_ui32_t access_right 916 sos_ui32_t access_rights); 976 917 977 sos_ret_t sos_fs_link(const struct sos_process 918 sos_ret_t sos_fs_link(const struct sos_process * creator, 978 const char * _old_path, 919 const char * _old_path, 979 sos_size_t _old_pathlen, 920 sos_size_t _old_pathlen, 980 const char * _dest_path, 921 const char * _dest_path, 981 sos_size_t _dest_pathlen 922 sos_size_t _dest_pathlen); 982 923 983 sos_ret_t sos_fs_rename(const struct sos_proce 924 sos_ret_t sos_fs_rename(const struct sos_process * creator, 984 const char * _old_path 925 const char * _old_path, 985 sos_size_t _old_pathle 926 sos_size_t _old_pathlen, 986 const char * _dest_pat 927 const char * _dest_path, 987 sos_size_t _dest_pathl 928 sos_size_t _dest_pathlen); 988 929 989 sos_ret_t sos_fs_unlink(const struct sos_proce 930 sos_ret_t sos_fs_unlink(const struct sos_process * actor, 990 const char * _path, 931 const char * _path, 991 sos_size_t _pathlen); 932 sos_size_t _pathlen); 992 933 993 sos_ret_t sos_fs_symlink(const struct sos_proc 934 sos_ret_t sos_fs_symlink(const struct sos_process * creator, 994 const char * _path, 935 const char * _path, 995 sos_size_t _pathlen, 936 sos_size_t _pathlen, 996 sos_uaddr_t symlink_t 937 sos_uaddr_t symlink_target, 997 sos_size_t symlink_ta 938 sos_size_t symlink_target_len); 998 << 999 sos_ret_t sos_fs_mknod(const struct sos_proces << 1000 const char * _path, << 1001 sos_size_t _pathlen, << 1002 sos_fs_node_type_t typ << 1003 sos_ui32_t access_righ << 1004 const struct sos_fs_de << 1005 939 1006 sos_ret_t sos_fs_mkdir(const struct sos_proce 940 sos_ret_t sos_fs_mkdir(const struct sos_process * creator, 1007 const char * _path, 941 const char * _path, 1008 sos_size_t _pathlen, 942 sos_size_t _pathlen, 1009 sos_ui32_t access_righ 943 sos_ui32_t access_rights); 1010 944 1011 sos_ret_t sos_fs_rmdir(const struct sos_proce 945 sos_ret_t sos_fs_rmdir(const struct sos_process * actor, 1012 const char * _path, 946 const char * _path, 1013 sos_size_t _pathlen); 947 sos_size_t _pathlen); 1014 948 1015 sos_ret_t sos_fs_chmod(const struct sos_proce 949 sos_ret_t sos_fs_chmod(const struct sos_process * actor, 1016 const char * _path, 950 const char * _path, 1017 sos_size_t _pathlen, 951 sos_size_t _pathlen, 1018 sos_ui32_t access_righ 952 sos_ui32_t access_rights); 1019 953 1020 sos_ret_t sos_fs_stat(const struct sos_proces 954 sos_ret_t sos_fs_stat(const struct sos_process * actor, 1021 const char * _path, 955 const char * _path, 1022 sos_size_t _pathlen, 956 sos_size_t _pathlen, 1023 int nofollow, 957 int nofollow, 1024 struct sos_fs_stat * re 958 struct sos_fs_stat * result); 1025 959 1026 960 1027 /* ****************************************** 961 /* *************************************************************** 1028 * Restricted functions reserved to FS code a 962 * Restricted functions reserved to FS code and block/char devices 1029 */ 963 */ 1030 964 1031 /** 965 /** 1032 * Function to be called when proposing a new 966 * Function to be called when proposing a new File system type 1033 */ 967 */ 1034 sos_ret_t sos_fs_register_fs_type(struct sos_ 968 sos_ret_t sos_fs_register_fs_type(struct sos_fs_manager_type * fstype); 1035 sos_ret_t sos_fs_unregister_fs_type(struct so 969 sos_ret_t sos_fs_unregister_fs_type(struct sos_fs_manager_type * fstype); 1036 970 1037 /** 971 /** 1038 * Marthe given file as dirty, for FS support 972 * Marthe given file as dirty, for FS supporting deferred write access 1039 * mode 973 * mode 1040 */ 974 */ 1041 sos_ret_t sos_fs_mark_dirty(struct sos_fs_ope 975 sos_ret_t sos_fs_mark_dirty(struct sos_fs_opened_file * of); 1042 976 1043 /** 977 /** 1044 * Helper function to be called from the moun 978 * Helper function to be called from the mount() method of the FS 1045 * instance code. Responsible for creating an 979 * instance code. Responsible for creating and updating the "root" 1046 * field of the FS instance structure and for 980 * field of the FS instance structure and for connecting this FS in 1047 * the nscache 981 * the nscache 1048 * @param root_fsnode The root of the FS bein 982 * @param root_fsnode The root of the FS being mounted 1049 */ 983 */ 1050 sos_ret_t sos_fs_register_fs_instance(struct 984 sos_ret_t sos_fs_register_fs_instance(struct sos_fs_manager_instance * fs, 1051 struct 985 struct sos_fs_node * root_fsnode); 1052 986 1053 /** 987 /** 1054 * Helper function to be called from the umou 988 * Helper function to be called from the umount() method of the FS 1055 * instance code. Responsible for unregisteri 989 * instance code. Responsible for unregistering the instance from the 1056 * FS type's instances list and for disconnec 990 * FS type's instances list and for disconnecting this mountpoint in 1057 * the nscache. 991 * the nscache. 1058 */ 992 */ 1059 sos_ret_t sos_fs_unregister_fs_instance(struc 993 sos_ret_t sos_fs_unregister_fs_instance(struct sos_fs_manager_instance * fs); 1060 994 1061 995 1062 /* ****************************************** 996 /* *************************************************************** 1063 * Restricted functions reserved to syscall.c 997 * Restricted functions reserved to syscall.c 1064 */ 998 */ 1065 sos_ret_t sos_fs_ref_opened_file(struct sos_f 999 sos_ret_t sos_fs_ref_opened_file(struct sos_fs_opened_file * of); 1066 sos_ret_t _sos_fs_unref_opened_file(struct so 1000 sos_ret_t _sos_fs_unref_opened_file(struct sos_fs_opened_file ** of); 1067 #define sos_fs_unref_opened_file(f) _sos_fs_u 1001 #define sos_fs_unref_opened_file(f) _sos_fs_unref_opened_file(&(f)) 1068 1002 1069 1003 1070 /* ****************************************** 1004 /* *************************************************************** 1071 * Restricted functions to be used only by fs 1005 * Restricted functions to be used only by fs_nscache.c 1072 */ 1006 */ 1073 1007 1074 sos_ret_t sos_fs_ref_fsnode(struct sos_fs_nod 1008 sos_ret_t sos_fs_ref_fsnode(struct sos_fs_node * fsnode); 1075 1009 1076 sos_ret_t _sos_fs_unref_fsnode(struct sos_fs_ 1010 sos_ret_t _sos_fs_unref_fsnode(struct sos_fs_node * fsnode); 1077 #define sos_fs_unref_fsnode(n) \ 1011 #define sos_fs_unref_fsnode(n) \ 1078 ({ sos_ret_t __retval = _sos_fs_unref_fsnod 1012 ({ sos_ret_t __retval = _sos_fs_unref_fsnode(n); (n)=NULL; __retval; }) 1079 1013 1080 1014 1081 /* ****************************************** 1015 /* *************************************************************** 1082 * Restricted functions reserved to process.c 1016 * Restricted functions reserved to process.c and main.c:start_init() 1083 */ 1017 */ 1084 sos_ret_t sos_fs_new_opened_file(const struct 1018 sos_ret_t sos_fs_new_opened_file(const struct sos_process * proc, 1085 struct sos_f 1019 struct sos_fs_nscache_node * nsnode, 1086 sos_ui32_t o 1020 sos_ui32_t open_flags, 1087 struct sos_f 1021 struct sos_fs_opened_file ** result_of); 1088 1022 1089 1023 1090 sos_ret_t sos_fs_duplicate_opened_file(struct 1024 sos_ret_t sos_fs_duplicate_opened_file(struct sos_fs_opened_file * src_of, 1091 const 1025 const struct sos_process * dst_proc, 1092 struct 1026 struct sos_fs_opened_file ** result_of); 1093 1027 1094 1028 1095 1029 1096 #endif /* _SOS_FS_H_ */ 1030 #endif /* _SOS_FS_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |