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