[1] | 1 | /* |
---|
| 2 | * vfs.c - Virtual File System implementation. |
---|
| 3 | * |
---|
| 4 | * Author Mohamed Lamine Karaoui (2015) |
---|
[437] | 5 | * Alain Greiner (2016,2017,2018) |
---|
[1] | 6 | * |
---|
| 7 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 8 | * |
---|
| 9 | * This file is part of ALMOS-MKH. |
---|
| 10 | * |
---|
| 11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 12 | * under the terms of the GNU General Public License as published by |
---|
| 13 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 14 | * |
---|
| 15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | |
---|
[14] | 26 | #include <kernel_config.h> |
---|
[457] | 27 | #include <hal_kernel_types.h> |
---|
[1] | 28 | #include <hal_atomic.h> |
---|
| 29 | #include <hal_special.h> |
---|
| 30 | #include <printk.h> |
---|
| 31 | #include <list.h> |
---|
| 32 | #include <xlist.h> |
---|
| 33 | #include <slist.h> |
---|
| 34 | #include <xhtab.h> |
---|
[430] | 35 | #include <string.h> |
---|
[23] | 36 | #include <rpc.h> |
---|
[1] | 37 | #include <errno.h> |
---|
| 38 | #include <kmem.h> |
---|
| 39 | #include <mapper.h> |
---|
| 40 | #include <thread.h> |
---|
[337] | 41 | #include <chdev.h> |
---|
[1] | 42 | #include <process.h> |
---|
[568] | 43 | #include <cluster.h> |
---|
[23] | 44 | #include <vfs.h> |
---|
[1] | 45 | #include <fatfs.h> |
---|
| 46 | #include <ramfs.h> |
---|
[23] | 47 | #include <devfs.h> |
---|
| 48 | #include <syscalls.h> |
---|
[1] | 49 | |
---|
| 50 | |
---|
| 51 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[50] | 52 | // Extern variables |
---|
[1] | 53 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 54 | |
---|
[337] | 55 | extern vfs_ctx_t fs_context[FS_TYPES_NR]; // allocated in kernel_init.c |
---|
| 56 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
[568] | 57 | extern char * lock_type_str[]; // allocated in kernel_init.c |
---|
[50] | 58 | |
---|
[602] | 59 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 60 | // VFS Context related functions |
---|
[1] | 61 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 62 | |
---|
[188] | 63 | //////////////////////////////////////// |
---|
| 64 | void vfs_ctx_init( vfs_fs_type_t type, |
---|
| 65 | uint32_t attr, |
---|
| 66 | uint32_t total_clusters, |
---|
| 67 | uint32_t cluster_size, |
---|
| 68 | xptr_t vfs_root_xp, |
---|
| 69 | void * extend ) |
---|
| 70 | { |
---|
| 71 | vfs_ctx_t * vfs_ctx = &fs_context[type]; |
---|
| 72 | |
---|
| 73 | vfs_ctx->type = type; |
---|
| 74 | vfs_ctx->attr = attr; |
---|
| 75 | vfs_ctx->total_clusters = total_clusters; |
---|
| 76 | vfs_ctx->cluster_size = cluster_size; |
---|
| 77 | vfs_ctx->vfs_root_xp = vfs_root_xp; |
---|
| 78 | vfs_ctx->extend = extend; |
---|
| 79 | |
---|
[568] | 80 | busylock_init( &vfs_ctx->lock , LOCK_VFS_CTX ); |
---|
[188] | 81 | |
---|
| 82 | bitmap_init( vfs_ctx->bitmap , BITMAP_SIZE(CONFIG_VFS_MAX_INODES) ); |
---|
| 83 | } |
---|
| 84 | |
---|
[23] | 85 | //////////////////////////////////////////// |
---|
[1] | 86 | error_t vfs_ctx_inum_alloc( vfs_ctx_t * ctx, |
---|
| 87 | uint32_t * inum ) |
---|
| 88 | { |
---|
| 89 | // get lock on inum allocator |
---|
[568] | 90 | busylock_acquire( &ctx->lock ); |
---|
[1] | 91 | |
---|
| 92 | // get lid from local inum allocator |
---|
[23] | 93 | uint32_t lid = bitmap_ffc( ctx->bitmap , CONFIG_VFS_MAX_INODES ); |
---|
[1] | 94 | |
---|
[473] | 95 | if( lid == 0xFFFFFFFF ) // no more free slot => error |
---|
[1] | 96 | { |
---|
| 97 | // release lock |
---|
[568] | 98 | busylock_release( &ctx->lock ); |
---|
[1] | 99 | |
---|
| 100 | // return error |
---|
| 101 | return 1; |
---|
| 102 | } |
---|
| 103 | else // found => return inum |
---|
| 104 | { |
---|
| 105 | // set slot allocated |
---|
[23] | 106 | bitmap_set( ctx->bitmap , lid ); |
---|
[1] | 107 | |
---|
| 108 | // release lock |
---|
[568] | 109 | busylock_release( &ctx->lock ); |
---|
[1] | 110 | |
---|
| 111 | // return inum |
---|
| 112 | *inum = (((uint32_t)local_cxy) << 16) | (lid & 0xFFFF); |
---|
| 113 | return 0; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | //////////////////////////////////////////// |
---|
| 118 | void vfs_ctx_inum_release( vfs_ctx_t * ctx, |
---|
| 119 | uint32_t inum ) |
---|
| 120 | { |
---|
[23] | 121 | bitmap_clear( ctx->bitmap , inum & 0xFFFF ); |
---|
[1] | 122 | } |
---|
| 123 | |
---|
| 124 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 125 | // VFS inode descriptor related functions |
---|
[1] | 126 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 127 | |
---|
[598] | 128 | const char * vfs_inode_type_str( vfs_inode_type_t type ) |
---|
[188] | 129 | { |
---|
[598] | 130 | switch ( type ) |
---|
| 131 | { |
---|
| 132 | case INODE_TYPE_FILE: return "FILE"; |
---|
| 133 | case INODE_TYPE_DIR: return "DIR "; |
---|
| 134 | case INODE_TYPE_FIFO: return "FIFO"; |
---|
| 135 | case INODE_TYPE_PIPE: return "PIPE"; |
---|
| 136 | case INODE_TYPE_SOCK: return "SOCK"; |
---|
| 137 | case INODE_TYPE_DEV: return "DEV "; |
---|
| 138 | case INODE_TYPE_SYML: return "SYML"; |
---|
| 139 | default: return "undefined"; |
---|
[527] | 140 | } |
---|
[188] | 141 | } |
---|
| 142 | |
---|
[610] | 143 | //////////////////////////////////////////////////// |
---|
| 144 | error_t vfs_inode_create( vfs_fs_type_t fs_type, |
---|
[23] | 145 | vfs_inode_type_t inode_type, |
---|
| 146 | uint32_t attr, |
---|
| 147 | uint32_t rights, |
---|
| 148 | uid_t uid, |
---|
| 149 | gid_t gid, |
---|
| 150 | xptr_t * inode_xp ) |
---|
[1] | 151 | { |
---|
| 152 | mapper_t * mapper; // associated mapper( to be allocated) |
---|
| 153 | vfs_inode_t * inode; // inode descriptor (to be allocated) |
---|
| 154 | uint32_t inum; // inode identifier (to be allocated) |
---|
| 155 | vfs_ctx_t * ctx; // file system context |
---|
| 156 | kmem_req_t req; // request to kernel memory allocator |
---|
| 157 | error_t error; |
---|
| 158 | |
---|
[438] | 159 | #if DEBUG_VFS_INODE_CREATE |
---|
[568] | 160 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 161 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 162 | cxy_t dentry_cxy = GET_CXY( dentry_xp ); |
---|
| 163 | vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp ); |
---|
| 164 | thread_t * this = CURRENT_THREAD; |
---|
| 165 | if( dentry_xp != XPTR_NULL ) hal_remote_strcpy( XPTR( local_cxy , name ), |
---|
| 166 | XPTR( dentry_cxy , dentry_ptr->name ) ); |
---|
| 167 | else strcpy( name , "/" ); |
---|
[438] | 168 | if( DEBUG_VFS_INODE_CREATE < cycle ) |
---|
[598] | 169 | printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", |
---|
| 170 | __FUNCTION__, this->process->pid, this->trdid, name, cycle ); |
---|
[433] | 171 | #endif |
---|
[279] | 172 | |
---|
[23] | 173 | // check fs type and get pointer on context |
---|
| 174 | if ( fs_type == FS_TYPE_FATFS ) ctx = &fs_context[FS_TYPE_FATFS]; |
---|
| 175 | else if( fs_type == FS_TYPE_RAMFS ) ctx = &fs_context[FS_TYPE_RAMFS]; |
---|
| 176 | else if( fs_type == FS_TYPE_DEVFS ) ctx = &fs_context[FS_TYPE_DEVFS]; |
---|
[1] | 177 | else |
---|
| 178 | { |
---|
| 179 | ctx = NULL; |
---|
[492] | 180 | assert( false , "illegal file system type = %d\n" , fs_type ); |
---|
[1] | 181 | } |
---|
| 182 | |
---|
| 183 | // allocate inum |
---|
| 184 | error = vfs_ctx_inum_alloc( ctx , &inum ); |
---|
| 185 | |
---|
| 186 | if( error ) |
---|
| 187 | { |
---|
| 188 | printk("\n[ERROR] in %s : cannot allocate inum\n", __FUNCTION__ ); |
---|
| 189 | return ENOMEM; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | // allocate memory for mapper |
---|
[246] | 193 | mapper = mapper_create( fs_type ); |
---|
[1] | 194 | |
---|
| 195 | if( mapper == NULL ) |
---|
| 196 | { |
---|
| 197 | printk("\n[ERROR] in %s : cannot allocate mapper\n", __FUNCTION__ ); |
---|
| 198 | vfs_ctx_inum_release( ctx , inum ); |
---|
| 199 | return ENOMEM; |
---|
| 200 | } |
---|
| 201 | |
---|
[23] | 202 | // allocate memory for VFS inode descriptor |
---|
[1] | 203 | req.type = KMEM_VFS_INODE; |
---|
| 204 | req.size = sizeof(vfs_inode_t); |
---|
| 205 | req.flags = AF_KERNEL | AF_ZERO; |
---|
| 206 | inode = (vfs_inode_t *)kmem_alloc( &req ); |
---|
| 207 | |
---|
| 208 | if( inode == NULL ) |
---|
| 209 | { |
---|
| 210 | printk("\n[ERROR] in %s : cannot allocate inode descriptor\n", __FUNCTION__ ); |
---|
| 211 | vfs_ctx_inum_release( ctx , inum ); |
---|
| 212 | mapper_destroy( mapper ); |
---|
[610] | 213 | return -1; |
---|
[1] | 214 | } |
---|
| 215 | |
---|
| 216 | // initialize inode descriptor |
---|
[23] | 217 | inode->type = inode_type; |
---|
[1] | 218 | inode->inum = inum; |
---|
| 219 | inode->attr = attr; |
---|
[23] | 220 | inode->rights = rights; |
---|
[1] | 221 | inode->uid = uid; |
---|
| 222 | inode->gid = gid; |
---|
| 223 | inode->ctx = ctx; |
---|
[246] | 224 | inode->mapper = mapper; |
---|
[602] | 225 | inode->extend = NULL; |
---|
[610] | 226 | inode->links = 0; |
---|
[1] | 227 | |
---|
[246] | 228 | // initialise inode field in mapper |
---|
| 229 | mapper->inode = inode; |
---|
| 230 | |
---|
[1] | 231 | // initialise threads waiting queue |
---|
[610] | 232 | // xlist_root_init( XPTR( local_cxy , &inode->wait_root ) ); |
---|
[1] | 233 | |
---|
[610] | 234 | // initialize chidren dentries xhtab |
---|
[204] | 235 | xhtab_init( &inode->children , XHTAB_DENTRY_TYPE ); |
---|
[1] | 236 | |
---|
[610] | 237 | // initialize parents dentries xlist |
---|
| 238 | xlist_root_init( XPTR( local_cxy , &inode->parents ) ); |
---|
| 239 | |
---|
| 240 | // initialize lock protecting size |
---|
| 241 | remote_rwlock_init( XPTR( local_cxy , &inode->size_lock ), LOCK_VFS_SIZE ); |
---|
[1] | 242 | |
---|
[610] | 243 | // initialise lock protecting inode tree traversal |
---|
| 244 | remote_rwlock_init( XPTR( local_cxy , &inode->main_lock ), LOCK_VFS_MAIN ); |
---|
[568] | 245 | |
---|
[610] | 246 | // return extended pointer on inode |
---|
| 247 | *inode_xp = XPTR( local_cxy , inode ); |
---|
| 248 | |
---|
[438] | 249 | #if DEBUG_VFS_INODE_CREATE |
---|
[568] | 250 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 251 | if( DEBUG_VFS_INODE_CREATE < cycle ) |
---|
[598] | 252 | printk("\n[%s] thread[%x,%x] exit for <%s> / inode [%x,%x] / cycle %d\n", |
---|
| 253 | __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, inode, cycle ); |
---|
[433] | 254 | #endif |
---|
[401] | 255 | |
---|
[1] | 256 | return 0; |
---|
| 257 | |
---|
| 258 | } // end vfs_inode_create() |
---|
| 259 | |
---|
[602] | 260 | ///////////////////////////////////////////// |
---|
| 261 | void vfs_inode_destroy( vfs_inode_t * inode ) |
---|
[1] | 262 | { |
---|
| 263 | // release memory allocated for mapper |
---|
| 264 | mapper_destroy( inode->mapper ); |
---|
| 265 | |
---|
| 266 | // release memory allocate for inode descriptor |
---|
| 267 | kmem_req_t req; |
---|
| 268 | req.ptr = inode; |
---|
| 269 | req.type = KMEM_VFS_INODE; |
---|
| 270 | kmem_free( &req ); |
---|
| 271 | |
---|
| 272 | } // end vfs_inode_destroy() |
---|
| 273 | |
---|
| 274 | ////////////////////////////////////////////// |
---|
| 275 | uint32_t vfs_inode_get_size( xptr_t inode_xp ) |
---|
| 276 | { |
---|
| 277 | // get inode cluster and local pointer |
---|
| 278 | cxy_t cxy = GET_CXY( inode_xp ); |
---|
[473] | 279 | vfs_inode_t * ptr = GET_PTR( inode_xp ); |
---|
[1] | 280 | |
---|
| 281 | // get size |
---|
[610] | 282 | remote_rwlock_rd_acquire( XPTR( cxy , &ptr->size_lock ) ); |
---|
[568] | 283 | uint32_t size = hal_remote_l32( XPTR( cxy , &ptr->size ) ); |
---|
[610] | 284 | remote_rwlock_rd_release( XPTR( cxy , &ptr->size_lock ) ); |
---|
[1] | 285 | return size; |
---|
| 286 | } |
---|
| 287 | |
---|
[101] | 288 | //////////////////////////////////////////// |
---|
| 289 | void vfs_inode_set_size( xptr_t inode_xp, |
---|
[409] | 290 | uint32_t size ) |
---|
[1] | 291 | { |
---|
| 292 | // get inode cluster and local pointer |
---|
| 293 | cxy_t cxy = GET_CXY( inode_xp ); |
---|
[473] | 294 | vfs_inode_t * ptr = GET_PTR( inode_xp ); |
---|
[1] | 295 | |
---|
| 296 | // set size |
---|
[610] | 297 | remote_rwlock_wr_release( XPTR( cxy , &ptr->size_lock ) ); |
---|
[568] | 298 | hal_remote_s32( XPTR( cxy , &ptr->size ) , size ); |
---|
[610] | 299 | remote_rwlock_wr_release( XPTR( cxy , &ptr->size_lock ) ); |
---|
[1] | 300 | } |
---|
| 301 | |
---|
[101] | 302 | //////////////////////////////////////// |
---|
| 303 | void vfs_inode_unlock( xptr_t inode_xp ) |
---|
[1] | 304 | { |
---|
| 305 | // get inode cluster and local pointer |
---|
| 306 | cxy_t cxy = GET_CXY( inode_xp ); |
---|
[473] | 307 | vfs_inode_t * ptr = GET_PTR( inode_xp ); |
---|
[1] | 308 | |
---|
| 309 | // release the main lock |
---|
[568] | 310 | remote_busylock_release( XPTR( cxy , &ptr->main_lock ) ); |
---|
[1] | 311 | } |
---|
| 312 | |
---|
[101] | 313 | ////////////////////////////////////// |
---|
| 314 | void vfs_inode_lock( xptr_t inode_xp ) |
---|
[1] | 315 | { |
---|
| 316 | // get inode cluster and local pointer |
---|
| 317 | cxy_t cxy = GET_CXY( inode_xp ); |
---|
[473] | 318 | vfs_inode_t * ptr = GET_PTR( inode_xp ); |
---|
[1] | 319 | |
---|
| 320 | // get the main lock |
---|
[568] | 321 | remote_busylock_acquire( XPTR( cxy , &ptr->main_lock ) ); |
---|
[1] | 322 | } |
---|
| 323 | |
---|
[610] | 324 | /////////////////////////////////////////// |
---|
| 325 | void vfs_inode_get_name( xptr_t inode_xp, |
---|
| 326 | char * name ) |
---|
[101] | 327 | { |
---|
[610] | 328 | cxy_t inode_cxy; // inode cluster identifier |
---|
| 329 | vfs_inode_t * inode_ptr; // local pointer on inode |
---|
| 330 | xptr_t parents_root_xp; // extended pointer on inode parents root |
---|
[204] | 331 | |
---|
| 332 | // get inode cluster and local pointer |
---|
| 333 | inode_cxy = GET_CXY( inode_xp ); |
---|
[473] | 334 | inode_ptr = GET_PTR( inode_xp ); |
---|
[204] | 335 | |
---|
[610] | 336 | // build extended pointer on parents dentries root |
---|
| 337 | parents_root_xp = XPTR( inode_cxy , &inode_ptr->parents ); |
---|
[204] | 338 | |
---|
[610] | 339 | // check VFS root |
---|
| 340 | if( xlist_is_empty( parents_root_xp ) ) // inode is the VFS root |
---|
[204] | 341 | { |
---|
| 342 | strcpy( name , "/" ); |
---|
| 343 | } |
---|
[610] | 344 | else // not the VFS root |
---|
[204] | 345 | { |
---|
[610] | 346 | xptr_t dentry_xp; |
---|
| 347 | cxy_t dentry_cxy; |
---|
| 348 | vfs_dentry_t * dentry_ptr; |
---|
| 349 | |
---|
| 350 | // get first name in list of parents |
---|
| 351 | dentry_xp = XLIST_FIRST( parents_root_xp , vfs_dentry_t , parents ); |
---|
[204] | 352 | dentry_cxy = GET_CXY( dentry_xp ); |
---|
[473] | 353 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
[204] | 354 | |
---|
| 355 | hal_remote_strcpy( XPTR( local_cxy , name ) , |
---|
[610] | 356 | XPTR( dentry_cxy , dentry_ptr->name ) ); |
---|
[204] | 357 | } |
---|
[610] | 358 | |
---|
[409] | 359 | } // end vfs_inode_get_name() |
---|
[204] | 360 | |
---|
[602] | 361 | /////////////////////////////////////////////////////// |
---|
| 362 | error_t vfs_inode_load_all_pages( vfs_inode_t * inode ) |
---|
| 363 | { |
---|
| 364 | |
---|
| 365 | assert( (inode != NULL) , "inode pointer is NULL\n" ); |
---|
| 366 | |
---|
| 367 | uint32_t page_id; |
---|
| 368 | xptr_t page_xp; |
---|
| 369 | |
---|
| 370 | mapper_t * mapper = inode->mapper; |
---|
| 371 | uint32_t size = inode->size; |
---|
| 372 | |
---|
| 373 | assert( (mapper != NULL) , "mapper pointer is NULL\n" ); |
---|
| 374 | |
---|
| 375 | #if DEBUG_VFS_INODE_LOAD_ALL |
---|
| 376 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 377 | thread_t * this = CURRENT_THREAD; |
---|
| 378 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 379 | vfs_inode_get_name( XPTR( local_cxy , inode ) , name ); |
---|
| 380 | if( DEBUG_VFS_INODE_LOAD_ALL < cycle ) |
---|
| 381 | printk("\n[%s] thread[%x,%x] enter for <%s> in cluster %x / cycle %d\n", |
---|
| 382 | __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, cycle ); |
---|
| 383 | #endif |
---|
| 384 | |
---|
| 385 | // compute number of pages |
---|
| 386 | uint32_t npages = size >> CONFIG_PPM_PAGE_SHIFT; |
---|
| 387 | if( (size & CONFIG_PPM_PAGE_MASK) || (size == 0) ) npages++; |
---|
| 388 | |
---|
| 389 | // loop on pages |
---|
| 390 | for( page_id = 0 ; page_id < npages ; page_id ++ ) |
---|
| 391 | { |
---|
| 392 | // If the mage is missing, this function allocates the missing page, |
---|
| 393 | // and load the page from IOC device into mapper |
---|
| 394 | page_xp = mapper_remote_get_page( XPTR( local_cxy , mapper ), page_id ); |
---|
| 395 | |
---|
| 396 | if( page_xp == XPTR_NULL ) return -1; |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | #if DEBUG_VFS_INODE_LOAD_ALL |
---|
| 400 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 401 | if( DEBUG_VFS_INODE_LOAD_ALL < cycle ) |
---|
| 402 | printk("\n[%s] thread[%x,%x] exit for <%x> in cluster %x / cycle %d\n", |
---|
| 403 | __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, cycle ); |
---|
| 404 | #endif |
---|
| 405 | |
---|
| 406 | return 0; |
---|
| 407 | |
---|
| 408 | } // end vfs_inode_load_all_pages() |
---|
| 409 | |
---|
[204] | 410 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 411 | // VFS dentry descriptor related functions |
---|
[1] | 412 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 413 | |
---|
[23] | 414 | /////////////////////////////////////////////////// |
---|
| 415 | error_t vfs_dentry_create( vfs_fs_type_t fs_type, |
---|
| 416 | char * name, |
---|
| 417 | xptr_t * dentry_xp ) |
---|
[1] | 418 | { |
---|
| 419 | vfs_ctx_t * ctx; // context descriptor |
---|
| 420 | vfs_dentry_t * dentry; // dentry descriptor (to be allocated) |
---|
| 421 | kmem_req_t req; // request to kernel memory allocator |
---|
| 422 | |
---|
[438] | 423 | #if DEBUG_VFS_DENTRY_CREATE |
---|
[598] | 424 | thread_t * this = CURRENT_THREAD; |
---|
[433] | 425 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 426 | if( DEBUG_VFS_DENTRY_CREATE < cycle ) |
---|
[598] | 427 | printk("\n[%s] thread[%x,%x] enter for <%s> / parent_inode %x / cycle %d\n", |
---|
| 428 | __FUNCTION__, this->process->pid, this->trdid, name, parent, cycle ); |
---|
[433] | 429 | #endif |
---|
[296] | 430 | |
---|
[188] | 431 | // get pointer on context |
---|
[23] | 432 | if ( fs_type == FS_TYPE_FATFS ) ctx = &fs_context[FS_TYPE_FATFS]; |
---|
| 433 | else if( fs_type == FS_TYPE_RAMFS ) ctx = &fs_context[FS_TYPE_RAMFS]; |
---|
| 434 | else if( fs_type == FS_TYPE_DEVFS ) ctx = &fs_context[FS_TYPE_DEVFS]; |
---|
[459] | 435 | else |
---|
[1] | 436 | { |
---|
| 437 | ctx = NULL; |
---|
[610] | 438 | return -1; |
---|
[1] | 439 | } |
---|
| 440 | |
---|
| 441 | // get name length |
---|
| 442 | uint32_t length = strlen( name ); |
---|
| 443 | |
---|
[459] | 444 | if( length >= CONFIG_VFS_MAX_NAME_LENGTH ) return EINVAL; |
---|
[437] | 445 | |
---|
[1] | 446 | // allocate memory for dentry descriptor |
---|
| 447 | req.type = KMEM_VFS_DENTRY; |
---|
| 448 | req.size = sizeof(vfs_dentry_t); |
---|
| 449 | req.flags = AF_KERNEL | AF_ZERO; |
---|
| 450 | dentry = (vfs_dentry_t *)kmem_alloc( &req ); |
---|
| 451 | |
---|
[610] | 452 | if( dentry == NULL ) |
---|
| 453 | { |
---|
| 454 | printk("\n[ERROR] in %s : cannot allocate dentry descriptor\n", |
---|
| 455 | __FUNCTION__ ); |
---|
| 456 | return -1; |
---|
| 457 | } |
---|
[437] | 458 | |
---|
[1] | 459 | // initialize dentry descriptor |
---|
| 460 | dentry->ctx = ctx; |
---|
| 461 | dentry->length = length; |
---|
[602] | 462 | dentry->extend = NULL; |
---|
[1] | 463 | strcpy( dentry->name , name ); |
---|
| 464 | |
---|
[23] | 465 | // return extended pointer on dentry |
---|
[1] | 466 | *dentry_xp = XPTR( local_cxy , dentry ); |
---|
| 467 | |
---|
[438] | 468 | #if DEBUG_VFS_DENTRY_CREATE |
---|
[433] | 469 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 470 | if( DEBUG_VFS_DENTRY_CREATE < cycle ) |
---|
[602] | 471 | printk("\n[%s] thread[%x,%x] exit for <%s> / dentry [%x,%x] / cycle %d\n", |
---|
| 472 | __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, dentry, cycle ); |
---|
[433] | 473 | #endif |
---|
[296] | 474 | |
---|
[1] | 475 | return 0; |
---|
| 476 | |
---|
| 477 | } // end vfs_dentry_create() |
---|
| 478 | |
---|
[602] | 479 | //////////////////////////////////////////////// |
---|
| 480 | void vfs_dentry_destroy( vfs_dentry_t * dentry ) |
---|
[1] | 481 | { |
---|
[459] | 482 | // release memory allocated to dentry |
---|
[1] | 483 | kmem_req_t req; |
---|
| 484 | req.ptr = dentry; |
---|
| 485 | req.type = KMEM_VFS_DENTRY; |
---|
| 486 | kmem_free( &req ); |
---|
[459] | 487 | |
---|
[602] | 488 | } // end vfs_dentry_destroy() |
---|
| 489 | |
---|
| 490 | |
---|
[1] | 491 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 492 | // VFS file descriptor related functions |
---|
[1] | 493 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 494 | |
---|
[23] | 495 | ///////////////////////////////////////////// |
---|
| 496 | error_t vfs_file_create( vfs_inode_t * inode, |
---|
| 497 | uint32_t attr, |
---|
| 498 | xptr_t * file_xp ) |
---|
| 499 | { |
---|
| 500 | vfs_file_t * file; |
---|
| 501 | kmem_req_t req; |
---|
| 502 | |
---|
[568] | 503 | #if DEBUG_VFS_FILE_CREATE |
---|
[598] | 504 | thread_t * this = CURRENT_THREAD; |
---|
[568] | 505 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 506 | if( DEBUG_VFS_OPEN < cycle ) |
---|
[598] | 507 | printk("\n[%s] thread[%x,%x] enter for inode %x in cluster %x / cycle %d\n", |
---|
| 508 | __FUNCTION__, this->process->pid, this->trdid, inode, local_cxy, cycle ); |
---|
[568] | 509 | #endif |
---|
| 510 | |
---|
[23] | 511 | // allocate memory for new file descriptor |
---|
| 512 | req.type = KMEM_VFS_FILE; |
---|
| 513 | req.size = sizeof(vfs_file_t); |
---|
| 514 | req.flags = AF_KERNEL | AF_ZERO; |
---|
| 515 | file = (vfs_file_t *)kmem_alloc( &req ); |
---|
| 516 | |
---|
| 517 | if( file == NULL ) return ENOMEM; |
---|
| 518 | |
---|
| 519 | // initializes new file descriptor |
---|
| 520 | file->gc = 0; |
---|
| 521 | file->type = inode->type; |
---|
| 522 | file->attr = attr; |
---|
| 523 | file->offset = 0; |
---|
[337] | 524 | file->refcount = 1; |
---|
[23] | 525 | file->inode = inode; |
---|
| 526 | file->ctx = inode->ctx; |
---|
| 527 | file->mapper = inode->mapper; |
---|
| 528 | |
---|
[568] | 529 | remote_rwlock_init( XPTR( local_cxy , &file->lock ), LOCK_VFS_FILE ); |
---|
[23] | 530 | |
---|
| 531 | *file_xp = XPTR( local_cxy , file ); |
---|
[459] | 532 | |
---|
[568] | 533 | #if DEBUG_VFS_FILE_CREATE |
---|
| 534 | cycle = (uint32_t)hal_get_cycles(); |
---|
[459] | 535 | if( DEBUG_VFS_OPEN < cycle ) |
---|
[598] | 536 | printk("\n[%s] thread[%x,%x] created file %x in cluster %x / cycle %d\n", |
---|
| 537 | __FUNCTION__, this->process->pid, this->trdid, file, local_cxy, cycle ); |
---|
[459] | 538 | #endif |
---|
| 539 | |
---|
[23] | 540 | return 0; |
---|
| 541 | |
---|
| 542 | } // end vfs_file_create() |
---|
| 543 | |
---|
| 544 | /////////////////////////////////////////// |
---|
| 545 | void vfs_file_destroy( vfs_file_t * file ) |
---|
| 546 | { |
---|
| 547 | |
---|
[610] | 548 | // check refcount |
---|
| 549 | assert( (file->refcount == 0) , "refcount non zero\n" ); |
---|
| 550 | |
---|
[23] | 551 | kmem_req_t req; |
---|
| 552 | req.ptr = file; |
---|
| 553 | req.type = KMEM_VFS_FILE; |
---|
| 554 | kmem_free( &req ); |
---|
| 555 | |
---|
[459] | 556 | #if DEBUG_VFS_CLOSE |
---|
[598] | 557 | thread_t * this = CURRENT_THREAD; |
---|
[459] | 558 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 559 | if( DEBUG_VFS_CLOSE < cycle ) |
---|
[598] | 560 | printk("\n[%s] thread[%x,%x] deleted file %x in cluster %x / cycle %d\n", |
---|
| 561 | __FUNCTION__, this->process->pid, this->trdid, file, local_cxy, cycle ); |
---|
[459] | 562 | #endif |
---|
| 563 | |
---|
[23] | 564 | } // end vfs_file_destroy() |
---|
| 565 | |
---|
| 566 | |
---|
[1] | 567 | //////////////////////////////////////// |
---|
| 568 | void vfs_file_count_up( xptr_t file_xp ) |
---|
| 569 | { |
---|
| 570 | // get file cluster and local pointer |
---|
| 571 | cxy_t file_cxy = GET_CXY( file_xp ); |
---|
[459] | 572 | vfs_file_t * file_ptr = GET_PTR( file_xp ); |
---|
[1] | 573 | |
---|
| 574 | // atomically increment count |
---|
| 575 | hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->refcount ) , 1 ); |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | ////////////////////////////////////////// |
---|
| 579 | void vfs_file_count_down( xptr_t file_xp ) |
---|
| 580 | { |
---|
| 581 | // get file cluster and local pointer |
---|
| 582 | cxy_t file_cxy = GET_CXY( file_xp ); |
---|
[459] | 583 | vfs_file_t * file_ptr = GET_PTR( file_xp ); |
---|
[1] | 584 | |
---|
| 585 | // atomically decrement count |
---|
| 586 | hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->refcount ) , -1 ); |
---|
| 587 | } |
---|
| 588 | |
---|
[23] | 589 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 590 | // "syscalls" API related functions |
---|
[23] | 591 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 592 | |
---|
[407] | 593 | ////////////////////////////////////// |
---|
[610] | 594 | error_t vfs_open( xptr_t root_xp, |
---|
[407] | 595 | char * path, |
---|
[610] | 596 | xptr_t process_xp, |
---|
[407] | 597 | uint32_t flags, |
---|
| 598 | uint32_t mode, |
---|
| 599 | xptr_t * new_file_xp, |
---|
| 600 | uint32_t * new_file_id ) |
---|
[1] | 601 | { |
---|
[610] | 602 | error_t error; |
---|
| 603 | xptr_t inode_xp; // extended pointer on target inode |
---|
| 604 | cxy_t inode_cxy; // inode cluster identifier |
---|
| 605 | vfs_inode_t * inode_ptr; // inode local pointer |
---|
| 606 | uint32_t file_attr; // file descriptor attributes |
---|
| 607 | uint32_t lookup_mode; // lookup working mode |
---|
| 608 | xptr_t file_xp; // extended pointer on created file descriptor |
---|
| 609 | uint32_t file_id; // created file descriptor index in reference fd_array |
---|
| 610 | xptr_t vfs_root_xp; // extended pointer on VFS root inode |
---|
| 611 | vfs_inode_t * vfs_root_ptr; // local pointer on VFS root inode |
---|
| 612 | cxy_t vfs_root_cxy; // VFS root inode cluster identifier |
---|
| 613 | xptr_t lock_xp; // extended pointer on Inode Tree lock |
---|
[1] | 614 | |
---|
[602] | 615 | if( mode != 0 ) |
---|
| 616 | { |
---|
| 617 | printk("\n[ERROR] in %s : the mode parameter is not supported yet\n" ); |
---|
| 618 | return -1; |
---|
| 619 | } |
---|
| 620 | |
---|
[610] | 621 | thread_t * this = CURRENT_THREAD; |
---|
| 622 | process_t * process = this->process; |
---|
| 623 | |
---|
[438] | 624 | #if DEBUG_VFS_OPEN |
---|
[433] | 625 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 626 | if( DEBUG_VFS_OPEN < cycle ) |
---|
[610] | 627 | printk("\n[%s] thread[%x,%x] enter for <%s> / root_inode (%x,%x) / cycle %d\n", |
---|
| 628 | __FUNCTION__, process->pid, this->trdid, path, GET_CXY(root_xp), GET_PTR(root_xp), cycle ); |
---|
[433] | 629 | #endif |
---|
[101] | 630 | |
---|
[23] | 631 | // compute lookup working mode |
---|
| 632 | lookup_mode = VFS_LOOKUP_OPEN; |
---|
| 633 | if( (flags & O_DIR ) ) lookup_mode |= VFS_LOOKUP_DIR; |
---|
| 634 | if( (flags & O_CREAT ) ) lookup_mode |= VFS_LOOKUP_CREATE; |
---|
| 635 | if( (flags & O_EXCL ) ) lookup_mode |= VFS_LOOKUP_EXCL; |
---|
| 636 | |
---|
| 637 | // compute attributes for the created file |
---|
| 638 | file_attr = 0; |
---|
[407] | 639 | if( (flags & O_RDONLY ) == 0 ) file_attr |= FD_ATTR_WRITE_ENABLE; |
---|
| 640 | if( (flags & O_WRONLY ) == 0 ) file_attr |= FD_ATTR_READ_ENABLE; |
---|
[23] | 641 | if( (flags & O_SYNC ) ) file_attr |= FD_ATTR_SYNC; |
---|
| 642 | if( (flags & O_APPEND ) ) file_attr |= FD_ATTR_APPEND; |
---|
| 643 | if( (flags & O_CLOEXEC) ) file_attr |= FD_ATTR_CLOSE_EXEC; |
---|
[1] | 644 | |
---|
[610] | 645 | // build extended pointer on lock protecting Inode Tree |
---|
| 646 | vfs_root_xp = process->vfs_root_xp; |
---|
| 647 | vfs_root_ptr = GET_PTR( vfs_root_xp ); |
---|
| 648 | vfs_root_cxy = GET_CXY( vfs_root_xp ); |
---|
| 649 | lock_xp = XPTR( vfs_root_cxy , &vfs_root_ptr->main_lock ); |
---|
| 650 | |
---|
| 651 | // take lock protecting Inode Tree in read mode |
---|
| 652 | remote_rwlock_rd_acquire( lock_xp ); |
---|
| 653 | |
---|
[23] | 654 | // get extended pointer on target inode |
---|
[610] | 655 | error = vfs_lookup( root_xp, |
---|
| 656 | path, |
---|
| 657 | lookup_mode, |
---|
| 658 | &inode_xp, |
---|
| 659 | NULL ); |
---|
[23] | 660 | |
---|
[610] | 661 | // release lock protecting Inode Tree |
---|
| 662 | remote_rwlock_rd_release( lock_xp ); |
---|
[23] | 663 | |
---|
[610] | 664 | if( error ) |
---|
| 665 | { |
---|
| 666 | printk("\n[ERROR] in %s : cannot get inode <%s>\n", |
---|
| 667 | __FUNCTION__ , path ); |
---|
| 668 | return -1; |
---|
| 669 | } |
---|
| 670 | |
---|
[23] | 671 | // get target inode cluster and local pointer |
---|
| 672 | inode_cxy = GET_CXY( inode_xp ); |
---|
[473] | 673 | inode_ptr = GET_PTR( inode_xp ); |
---|
[23] | 674 | |
---|
[610] | 675 | #if (DEBUG_VFS_OPEN & 1) |
---|
| 676 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 677 | if( DEBUG_VFS_OPEN < cycle ) |
---|
| 678 | printk("\n[%s] thread[%x,%x] found inode(%x,%x) for <%s>\n", |
---|
| 679 | __FUNCTION__, process->pid, this->trdid, inode_cxy, inode_ptr, path ); |
---|
| 680 | #endif |
---|
| 681 | |
---|
[23] | 682 | // create a new file descriptor in cluster containing inode |
---|
| 683 | if( inode_cxy == local_cxy ) // target cluster is local |
---|
[1] | 684 | { |
---|
[23] | 685 | error = vfs_file_create( inode_ptr , file_attr , &file_xp ); |
---|
[1] | 686 | } |
---|
[23] | 687 | else // target cluster is remote |
---|
| 688 | { |
---|
| 689 | rpc_vfs_file_create_client( inode_cxy , inode_ptr , file_attr , &file_xp , &error ); |
---|
| 690 | } |
---|
[1] | 691 | |
---|
[23] | 692 | if( error ) return error; |
---|
[1] | 693 | |
---|
[610] | 694 | #if (DEBUG_VFS_OPEN & 1) |
---|
| 695 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 696 | if( DEBUG_VFS_OPEN < cycle ) |
---|
| 697 | printk("\n[%s] thread[%x,%x] created file descriptor (%x,%x) for <%s>\n", |
---|
| 698 | __FUNCTION__, process->pid, this->trdid, GET_CXY(file_xp), GET_PTR(file_xp), path ); |
---|
| 699 | #endif |
---|
| 700 | |
---|
[407] | 701 | // allocate and register a new file descriptor index in reference process |
---|
[610] | 702 | error = process_fd_register( process_xp , file_xp , &file_id ); |
---|
[1] | 703 | |
---|
[23] | 704 | if( error ) return error; |
---|
[1] | 705 | |
---|
[438] | 706 | #if DEBUG_VFS_OPEN |
---|
[433] | 707 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 708 | if( DEBUG_VFS_OPEN < cycle ) |
---|
[610] | 709 | printk("\n[%s] thread[%x,%x] exit for <%s> / fdid %d / cluster %x / cycle %d\n", |
---|
| 710 | __FUNCTION__, process->pid, this->trdid, path, file_id, GET_CXY( file_xp ), cycle ); |
---|
[433] | 711 | #endif |
---|
[238] | 712 | |
---|
[23] | 713 | // success |
---|
| 714 | *new_file_xp = file_xp; |
---|
| 715 | *new_file_id = file_id; |
---|
| 716 | return 0; |
---|
[1] | 717 | |
---|
[23] | 718 | } // end vfs_open() |
---|
| 719 | |
---|
[407] | 720 | ////////////////////////////////////// |
---|
| 721 | int vfs_user_move( bool_t to_buffer, |
---|
| 722 | xptr_t file_xp, |
---|
| 723 | void * buffer, |
---|
| 724 | uint32_t size ) |
---|
[23] | 725 | { |
---|
| 726 | cxy_t file_cxy; // remote file descriptor cluster |
---|
| 727 | vfs_file_t * file_ptr; // remote file descriptor local pointer |
---|
| 728 | vfs_inode_type_t inode_type; |
---|
| 729 | uint32_t file_offset; // current offset in file |
---|
| 730 | mapper_t * mapper; |
---|
| 731 | error_t error; |
---|
| 732 | |
---|
[602] | 733 | // check argument |
---|
| 734 | assert( (file_xp != XPTR_NULL), "file_xp == XPTR_NULL\n" ); |
---|
| 735 | |
---|
[23] | 736 | // get cluster and local pointer on remote file descriptor |
---|
| 737 | file_cxy = GET_CXY( file_xp ); |
---|
[473] | 738 | file_ptr = GET_PTR( file_xp ); |
---|
[23] | 739 | |
---|
| 740 | // get inode type from remote file descriptor |
---|
[568] | 741 | inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); |
---|
[23] | 742 | |
---|
[602] | 743 | // check inode type |
---|
| 744 | assert( (inode_type == INODE_TYPE_FILE), "inode type is not INODE_TYPE_FILE" ); |
---|
[23] | 745 | |
---|
[407] | 746 | // get mapper pointer and file offset from file descriptor |
---|
[568] | 747 | file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); |
---|
[407] | 748 | mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); |
---|
[23] | 749 | |
---|
[407] | 750 | // move data between mapper and buffer |
---|
[610] | 751 | error = mapper_move_user( XPTR( file_cxy , mapper ), |
---|
| 752 | to_buffer, |
---|
| 753 | file_offset, |
---|
| 754 | buffer, |
---|
| 755 | size ); |
---|
[407] | 756 | |
---|
[602] | 757 | // update file offset in file descriptor |
---|
| 758 | hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->offset ) , size ); |
---|
[407] | 759 | |
---|
[602] | 760 | if( error ) |
---|
| 761 | { |
---|
| 762 | return -1; |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | return size; |
---|
| 766 | |
---|
[313] | 767 | } // end vfs_user_move() |
---|
[23] | 768 | |
---|
[317] | 769 | //////////////////////////////////////////// |
---|
| 770 | error_t vfs_kernel_move( bool_t to_buffer, |
---|
| 771 | xptr_t file_xp, |
---|
| 772 | xptr_t buffer_xp, |
---|
| 773 | uint32_t size ) |
---|
| 774 | { |
---|
| 775 | cxy_t file_cxy; // remote file descriptor cluster |
---|
| 776 | vfs_file_t * file_ptr; // remote file descriptor local pointer |
---|
[602] | 777 | vfs_inode_type_t inode_type; // remote file type |
---|
[317] | 778 | uint32_t file_offset; // current offset in file |
---|
[602] | 779 | mapper_t * mapper_ptr; // remote mapper local pointer |
---|
| 780 | xptr_t mapper_xp; // remote mapper extended pointer |
---|
[317] | 781 | error_t error; |
---|
| 782 | |
---|
[602] | 783 | // check argument |
---|
| 784 | assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL\n" ); |
---|
| 785 | |
---|
[317] | 786 | // get cluster and local pointer on remote file descriptor |
---|
| 787 | file_cxy = GET_CXY( file_xp ); |
---|
[473] | 788 | file_ptr = GET_PTR( file_xp ); |
---|
[317] | 789 | |
---|
| 790 | // get inode type from remote file descriptor |
---|
[568] | 791 | inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); |
---|
[610] | 792 | |
---|
[317] | 793 | // action depends on inode type |
---|
| 794 | if( inode_type == INODE_TYPE_FILE ) |
---|
| 795 | { |
---|
[602] | 796 | // get mapper pointers and file offset from file descriptor |
---|
[568] | 797 | file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); |
---|
[602] | 798 | mapper_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); |
---|
| 799 | mapper_xp = XPTR( file_cxy , mapper_ptr ); |
---|
[317] | 800 | |
---|
| 801 | // move data between mapper and buffer |
---|
[602] | 802 | error = mapper_move_kernel( mapper_xp, |
---|
| 803 | to_buffer, |
---|
| 804 | file_offset, |
---|
| 805 | buffer_xp, |
---|
| 806 | size ); |
---|
[317] | 807 | if( error ) return -1; |
---|
| 808 | } |
---|
| 809 | else |
---|
| 810 | { |
---|
| 811 | printk("\n[ERROR] in %s : inode is not a file", __FUNCTION__ ); |
---|
| 812 | return -1; |
---|
| 813 | } |
---|
[602] | 814 | |
---|
| 815 | return 0; |
---|
| 816 | |
---|
[317] | 817 | } // end vfs_kernel_move() |
---|
| 818 | |
---|
[23] | 819 | ////////////////////////////////////// |
---|
| 820 | error_t vfs_lseek( xptr_t file_xp, |
---|
| 821 | uint32_t offset, |
---|
| 822 | uint32_t whence, |
---|
| 823 | uint32_t * new_offset ) |
---|
| 824 | { |
---|
[266] | 825 | xptr_t offset_xp; |
---|
| 826 | xptr_t lock_xp; |
---|
[602] | 827 | xptr_t size_xp; |
---|
[266] | 828 | cxy_t file_cxy; |
---|
| 829 | vfs_file_t * file_ptr; |
---|
| 830 | vfs_inode_t * inode_ptr; |
---|
| 831 | uint32_t new; |
---|
| 832 | |
---|
[602] | 833 | // check argument |
---|
| 834 | assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL\n" ); |
---|
[266] | 835 | |
---|
| 836 | // get cluster and local pointer on remote file descriptor |
---|
| 837 | file_cxy = GET_CXY( file_xp ); |
---|
[473] | 838 | file_ptr = GET_PTR( file_xp ); |
---|
[266] | 839 | |
---|
[602] | 840 | // get local pointer on remote inode |
---|
| 841 | inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); |
---|
| 842 | |
---|
| 843 | // build extended pointers on lock, offset and size |
---|
[266] | 844 | offset_xp = XPTR( file_cxy , &file_ptr->offset ); |
---|
| 845 | lock_xp = XPTR( file_cxy , &file_ptr->lock ); |
---|
[602] | 846 | size_xp = XPTR( file_cxy , &inode_ptr->size ); |
---|
[266] | 847 | |
---|
| 848 | // take file descriptor lock |
---|
[568] | 849 | remote_rwlock_wr_acquire( lock_xp ); |
---|
[266] | 850 | |
---|
| 851 | if ( whence == SEEK_CUR ) // new = current + offset |
---|
| 852 | { |
---|
[568] | 853 | new = hal_remote_l32( offset_xp ) + offset; |
---|
[266] | 854 | } |
---|
| 855 | else if ( whence == SEEK_SET ) // new = offset |
---|
| 856 | { |
---|
| 857 | new = offset; |
---|
| 858 | } |
---|
| 859 | else if ( whence == SEEK_END ) // new = size + offset |
---|
| 860 | { |
---|
[602] | 861 | new = hal_remote_l32( size_xp ) + offset; |
---|
[266] | 862 | } |
---|
| 863 | else |
---|
| 864 | { |
---|
| 865 | printk("\n[ERROR] in %s : illegal whence value\n", __FUNCTION__ ); |
---|
[568] | 866 | remote_rwlock_wr_release( lock_xp ); |
---|
[266] | 867 | return -1; |
---|
| 868 | } |
---|
| 869 | |
---|
[602] | 870 | #if DEBUG_VFS_LSEEK |
---|
| 871 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 872 | thread_t * this = CURRENT_THREAD; |
---|
| 873 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 874 | vfs_inode_get_name( XPTR( file_cxy , inode_ptr ) , name ); |
---|
| 875 | if( cycle > DEBUG_VFS_LSEEK ) |
---|
| 876 | printk("\n[%s] thread[%x,%x] for <%s> / new offset %d / cycle %d\n", |
---|
| 877 | __FUNCTION__ , this->process->pid, this->trdid, name, new, cycle ); |
---|
| 878 | #endif |
---|
| 879 | |
---|
[266] | 880 | // set new offset |
---|
[568] | 881 | hal_remote_s32( offset_xp , new ); |
---|
[266] | 882 | |
---|
| 883 | // release file descriptor lock |
---|
[568] | 884 | remote_rwlock_wr_release( lock_xp ); |
---|
[266] | 885 | |
---|
| 886 | // success |
---|
[602] | 887 | if ( new_offset != NULL ) *new_offset = new; |
---|
[1] | 888 | return 0; |
---|
| 889 | |
---|
[23] | 890 | } // vfs_lseek() |
---|
| 891 | |
---|
| 892 | /////////////////////////////////// |
---|
| 893 | error_t vfs_close( xptr_t file_xp, |
---|
| 894 | uint32_t file_id ) |
---|
[1] | 895 | { |
---|
[459] | 896 | cluster_t * cluster; // local pointer on local cluster |
---|
| 897 | cxy_t file_cxy; // cluster containing the file descriptor. |
---|
| 898 | vfs_file_t * file_ptr; // local ponter on file descriptor |
---|
| 899 | cxy_t owner_cxy; // process owner cluster |
---|
| 900 | lpid_t lpid; // process local index |
---|
| 901 | xptr_t root_xp; // root of list of process copies |
---|
| 902 | xptr_t lock_xp; // lock protecting the list of copies |
---|
| 903 | xptr_t iter_xp; // iterator on list of process copies |
---|
| 904 | xptr_t process_xp; // extended pointer on one process copy |
---|
| 905 | cxy_t process_cxy; // process copy cluster |
---|
| 906 | process_t * process_ptr; // process copy local pointer |
---|
| 907 | |
---|
[602] | 908 | // check arguments |
---|
| 909 | assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL\n" ); |
---|
| 910 | assert( (file_id < CONFIG_PROCESS_FILE_MAX_NR) , "illegal file_id\n" ); |
---|
[23] | 911 | |
---|
| 912 | thread_t * this = CURRENT_THREAD; |
---|
| 913 | process_t * process = this->process; |
---|
| 914 | |
---|
[459] | 915 | #if DEBUG_VFS_CLOSE |
---|
| 916 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 917 | if( DEBUG_VFS_CLOSE < cycle ) |
---|
[598] | 918 | printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n", |
---|
| 919 | __FUNCTION__, process->pid, this->trdid, file_id, cycle ); |
---|
[459] | 920 | #endif |
---|
[1] | 921 | |
---|
[23] | 922 | // get local pointer on local cluster manager |
---|
[459] | 923 | cluster = LOCAL_CLUSTER; |
---|
[23] | 924 | |
---|
| 925 | // get owner process cluster and lpid |
---|
[459] | 926 | owner_cxy = CXY_FROM_PID( process->pid ); |
---|
| 927 | lpid = LPID_FROM_PID( process->pid ); |
---|
[23] | 928 | |
---|
| 929 | // get extended pointers on copies root and lock |
---|
[459] | 930 | root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] ); |
---|
| 931 | lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] ); |
---|
[23] | 932 | |
---|
[459] | 933 | // 1) loop on the process descriptor copies to reset all fd_array[file_id] entries |
---|
| 934 | |
---|
| 935 | // take the lock protecting the list of copies |
---|
[568] | 936 | remote_queuelock_acquire( lock_xp ); |
---|
[23] | 937 | |
---|
| 938 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
[1] | 939 | { |
---|
[459] | 940 | process_xp = XLIST_ELEMENT( iter_xp , process_t , copies_list ); |
---|
| 941 | process_cxy = GET_CXY( process_xp ); |
---|
| 942 | process_ptr = GET_PTR( process_xp ); |
---|
[1] | 943 | |
---|
[459] | 944 | #if (DEBUG_VFS_CLOSE & 1 ) |
---|
| 945 | if( DEBUG_VFS_CLOSE < cycle ) |
---|
[598] | 946 | printk("\n[%s] reset fd_array[%d] for process %x in cluster %x\n", |
---|
[459] | 947 | __FUNCTION__, file_id, process_ptr, process_cxy ); |
---|
| 948 | #endif |
---|
[23] | 949 | |
---|
[459] | 950 | // fd_array lock is required for atomic write of a 64 bits word |
---|
| 951 | // xptr_t fd_array_lock_xp = XPTR( process_cxy , &process_ptr->fd_array.lock ); |
---|
| 952 | |
---|
| 953 | xptr_t entry_xp = XPTR( process_cxy , &process_ptr->fd_array.array[file_id] ); |
---|
| 954 | |
---|
[568] | 955 | // remote_rwlock_wr_acquire( fd_array_lock_xp ); |
---|
[459] | 956 | |
---|
[568] | 957 | hal_remote_s64( entry_xp , XPTR_NULL ); |
---|
[459] | 958 | |
---|
[568] | 959 | // remote_rwlock_wr_release( fd_array_lock_xp ); |
---|
[23] | 960 | |
---|
[459] | 961 | vfs_file_count_down( file_xp ); |
---|
| 962 | |
---|
[124] | 963 | hal_fence(); |
---|
[23] | 964 | } |
---|
| 965 | |
---|
[459] | 966 | // release the lock protecting the list of copies |
---|
[568] | 967 | remote_queuelock_release( lock_xp ); |
---|
[459] | 968 | |
---|
| 969 | #if (DEBUG_VFS_CLOSE & 1) |
---|
| 970 | if( DEBUG_VFS_CLOSE < cycle ) |
---|
[598] | 971 | printk("\n[%s] thread[%x,%x] reset all fd-array copies\n", |
---|
| 972 | __FUNCTION__, process->pid, this->trdid ); |
---|
[459] | 973 | #endif |
---|
| 974 | |
---|
[23] | 975 | // 2) release memory allocated to file descriptor in remote cluster |
---|
[459] | 976 | |
---|
| 977 | // get cluster and local pointer on remote file descriptor |
---|
| 978 | file_cxy = GET_CXY( file_xp ); |
---|
| 979 | file_ptr = GET_PTR( file_xp ); |
---|
| 980 | |
---|
[23] | 981 | if( file_cxy == local_cxy ) // file cluster is local |
---|
[1] | 982 | { |
---|
[23] | 983 | vfs_file_destroy( file_ptr ); |
---|
| 984 | } |
---|
| 985 | else // file cluster is local |
---|
| 986 | { |
---|
| 987 | rpc_vfs_file_destroy_client( file_cxy , file_ptr ); |
---|
| 988 | } |
---|
[1] | 989 | |
---|
[459] | 990 | #if DEBUG_VFS_CLOSE |
---|
| 991 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 992 | if( DEBUG_VFS_CLOSE < cycle ) |
---|
[598] | 993 | printk("\n[%s] thread[%x,%x] exit / fdid %d closed / cycle %d\n", |
---|
| 994 | __FUNCTION__, process->pid, this->trdid, file_id, cycle ); |
---|
[459] | 995 | #endif |
---|
| 996 | |
---|
[23] | 997 | return 0; |
---|
[1] | 998 | |
---|
[23] | 999 | } // end vfs_close() |
---|
[1] | 1000 | |
---|
| 1001 | //////////////////////////////////// |
---|
[610] | 1002 | error_t vfs_mkdir( xptr_t root_xp, |
---|
| 1003 | char * path, |
---|
| 1004 | uint32_t rights ) |
---|
| 1005 | { |
---|
| 1006 | error_t error; |
---|
| 1007 | xptr_t vfs_root_xp; // extended pointer on VFS root inode |
---|
| 1008 | vfs_inode_t * vfs_root_ptr; // local pointer on VFS root inode |
---|
| 1009 | cxy_t vfs_root_cxy; // VFS root inode cluster identifier |
---|
| 1010 | xptr_t lock_xp; // extended pointer on lock protecting Inode Tree |
---|
| 1011 | xptr_t inode_xp; // extended pointer on target inode |
---|
| 1012 | vfs_inode_t * inode_ptr; // local pointer on target inode |
---|
| 1013 | cxy_t inode_cxy; // target inode cluster identifier |
---|
| 1014 | xptr_t dentry_xp; // extended pointer on new dentry |
---|
| 1015 | vfs_dentry_t * dentry_ptr; // target dentry local pointer |
---|
| 1016 | xptr_t parent_xp; // extended pointer on new parent inode |
---|
| 1017 | vfs_inode_t * parent_ptr; // local pointer on new parent inode |
---|
| 1018 | cxy_t parent_cxy; // new parent inode cluster identifier |
---|
| 1019 | vfs_ctx_t * parent_ctx_ptr; // local pointer on target inode context |
---|
| 1020 | uint32_t parent_fs_type; // target inode file system type |
---|
| 1021 | |
---|
| 1022 | xptr_t parents_root_xp; // extended pointer on parents field in inode (root) |
---|
| 1023 | xptr_t parents_entry_xp; // extended pointer on parents field in dentry |
---|
| 1024 | xptr_t children_xhtab_xp; // extended pointer on children field in inode (root) |
---|
| 1025 | xptr_t children_entry_xp; // extended pointer on children field in dentry |
---|
| 1026 | |
---|
| 1027 | char last_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1028 | |
---|
| 1029 | thread_t * this = CURRENT_THREAD; |
---|
| 1030 | process_t * process = this->process; |
---|
| 1031 | |
---|
| 1032 | #if DEBUG_VFS_MKDIR |
---|
| 1033 | char root_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1034 | vfs_inode_get_name( root_xp , root_name ); |
---|
| 1035 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 1036 | if( DEBUG_VFS_MKDIR < cycle ) |
---|
| 1037 | printk("\n[%s] thread[%x,%x] enter / root <%s> / path <%s> / cycle %d\n", |
---|
| 1038 | __FUNCTION__, process->pid, this->trdid, root_name, path, cycle ); |
---|
| 1039 | #endif |
---|
| 1040 | |
---|
| 1041 | // build extended pointer on lock protecting Inode Tree (in VFS root inode) |
---|
| 1042 | vfs_root_xp = process->vfs_root_xp; |
---|
| 1043 | vfs_root_ptr = GET_PTR( vfs_root_xp ); |
---|
| 1044 | vfs_root_cxy = GET_CXY( vfs_root_xp ); |
---|
| 1045 | lock_xp = XPTR( vfs_root_cxy , &vfs_root_ptr->main_lock ); |
---|
| 1046 | |
---|
| 1047 | // take the lock protecting Inode Tree in write mode |
---|
| 1048 | remote_rwlock_wr_acquire( lock_xp ); |
---|
| 1049 | |
---|
| 1050 | // 1. get pointers on parent inode |
---|
| 1051 | error = vfs_lookup( root_xp, |
---|
| 1052 | path, |
---|
| 1053 | VFS_LOOKUP_DIR | VFS_LOOKUP_PARENT, |
---|
| 1054 | &parent_xp, |
---|
| 1055 | last_name ); |
---|
| 1056 | if( error ) |
---|
| 1057 | { |
---|
| 1058 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1059 | printk("\n[ERROR] in %s : cannot get parent inode for <%s>\n", |
---|
| 1060 | __FUNCTION__, path ); |
---|
| 1061 | return -1; |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | // get parent inode cluster and local pointer |
---|
| 1065 | parent_cxy = GET_CXY( parent_xp ); |
---|
| 1066 | parent_ptr = GET_PTR( parent_xp ); |
---|
| 1067 | |
---|
| 1068 | #if( DEBUG_VFS_MKDIR & 1 ) |
---|
| 1069 | if( DEBUG_VFS_MKDIR < cycle ) |
---|
| 1070 | printk("\n[%s] thread[%x,%x] get parent inode (%x,%x) for <%s>\n", |
---|
| 1071 | __FUNCTION__, process->pid, this->trdid, parent_cxy, parent_ptr, path ); |
---|
| 1072 | #endif |
---|
| 1073 | |
---|
| 1074 | // get parent inode context, and FS type |
---|
| 1075 | parent_ctx_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) ); |
---|
| 1076 | parent_fs_type = hal_remote_l32( XPTR( parent_cxy , &parent_ctx_ptr->type ) ); |
---|
| 1077 | |
---|
| 1078 | // 2. create one new dentry in parent cluster |
---|
| 1079 | if( parent_cxy == local_cxy ) |
---|
| 1080 | { |
---|
| 1081 | error = vfs_dentry_create( parent_fs_type, |
---|
| 1082 | last_name, |
---|
| 1083 | &dentry_xp ); |
---|
| 1084 | } |
---|
| 1085 | else |
---|
| 1086 | { |
---|
| 1087 | rpc_vfs_dentry_create_client( parent_cxy, |
---|
| 1088 | parent_fs_type, |
---|
| 1089 | last_name, |
---|
| 1090 | &dentry_xp, |
---|
| 1091 | &error ); |
---|
| 1092 | } |
---|
| 1093 | |
---|
| 1094 | if( error ) |
---|
| 1095 | { |
---|
| 1096 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1097 | printk("\n[ERROR] in %s : cannot create new dentry in cluster %x for <%s>\n", |
---|
| 1098 | __FUNCTION__, parent_cxy, path ); |
---|
| 1099 | return -1; |
---|
| 1100 | } |
---|
| 1101 | |
---|
| 1102 | // get local pointer on dentry |
---|
| 1103 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
| 1104 | |
---|
| 1105 | #if( DEBUG_VFS_MKDIR & 1 ) |
---|
| 1106 | if( DEBUG_VFS_MKDIR < cycle ) |
---|
| 1107 | printk("\n[%s] thread[%x,%x] created new dentry (%x,%x) for <%s>\n", |
---|
| 1108 | __FUNCTION__, process->pid, this->trdid, parent_cxy, dentry_ptr, path ); |
---|
| 1109 | #endif |
---|
| 1110 | |
---|
| 1111 | // 3. create new directory inode in child cluster |
---|
| 1112 | // TODO : define attr / uid / gid |
---|
| 1113 | uint32_t attr = 0; |
---|
| 1114 | uint32_t uid = 0; |
---|
| 1115 | uint32_t gid = 0; |
---|
| 1116 | |
---|
| 1117 | // select a target cluster for new inode |
---|
| 1118 | inode_cxy = cluster_random_select(); |
---|
| 1119 | |
---|
| 1120 | if( inode_cxy == local_cxy ) // child cluster is local |
---|
| 1121 | { |
---|
| 1122 | error = vfs_inode_create( parent_fs_type, |
---|
| 1123 | INODE_TYPE_DIR, |
---|
| 1124 | attr, |
---|
| 1125 | rights, |
---|
| 1126 | uid, |
---|
| 1127 | gid, |
---|
| 1128 | &inode_xp ); |
---|
| 1129 | } |
---|
| 1130 | else // child cluster is remote |
---|
| 1131 | { |
---|
| 1132 | rpc_vfs_inode_create_client( inode_cxy, |
---|
| 1133 | parent_fs_type, |
---|
| 1134 | INODE_TYPE_DIR, |
---|
| 1135 | attr, |
---|
| 1136 | rights, |
---|
| 1137 | uid, |
---|
| 1138 | gid, |
---|
| 1139 | &inode_xp, |
---|
| 1140 | &error ); |
---|
| 1141 | } |
---|
| 1142 | |
---|
| 1143 | if( error ) |
---|
| 1144 | { |
---|
| 1145 | printk("\n[ERROR] in %s : cannot create new inode in cluster %x for <%s>\n", |
---|
| 1146 | __FUNCTION__ , inode_cxy , path ); |
---|
| 1147 | |
---|
| 1148 | if( parent_cxy == local_cxy ) vfs_dentry_destroy( dentry_ptr ); |
---|
| 1149 | else rpc_vfs_dentry_destroy_client( parent_cxy , dentry_ptr ); |
---|
| 1150 | return -1; |
---|
| 1151 | } |
---|
| 1152 | |
---|
| 1153 | // get new inode local pointer |
---|
| 1154 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 1155 | |
---|
| 1156 | #if(DEBUG_VFS_MKDIR & 1) |
---|
| 1157 | if( DEBUG_VFS_MKDIR < cycle ) |
---|
| 1158 | printk("\n[%s] thread[%x,%x] created new inode (%x,%x) for <%s>\n", |
---|
| 1159 | __FUNCTION__ , process->pid, this->trdid, inode_cxy, inode_ptr, path ); |
---|
| 1160 | #endif |
---|
| 1161 | |
---|
| 1162 | // 4. register dentry in new inode list of parents |
---|
| 1163 | parents_root_xp = XPTR( inode_cxy , &inode_ptr->parents ); |
---|
| 1164 | parents_entry_xp = XPTR( parent_cxy , &dentry_ptr->parents ); |
---|
| 1165 | xlist_add_first( parents_root_xp , parents_entry_xp ); |
---|
| 1166 | hal_remote_atomic_add( XPTR( inode_cxy , &inode_ptr->links ) , 1 ); |
---|
| 1167 | |
---|
| 1168 | // 5. register dentry in parent inode |
---|
| 1169 | children_xhtab_xp = XPTR( parent_cxy , &parent_ptr->children ); |
---|
| 1170 | children_entry_xp = XPTR( parent_cxy , &dentry_ptr->children ); |
---|
| 1171 | xhtab_insert( children_xhtab_xp , last_name , children_entry_xp ); |
---|
| 1172 | |
---|
| 1173 | // 6. update "parent" and "child_xp" fields in dentry |
---|
| 1174 | hal_remote_s64( XPTR( parent_cxy , &dentry_ptr->child_xp ) , inode_xp ); |
---|
| 1175 | hal_remote_spt( XPTR( parent_cxy , &dentry_ptr->parent ) , parent_ptr ); |
---|
| 1176 | |
---|
| 1177 | #if(DEBUG_VFS_MKDIR & 1) |
---|
| 1178 | if( DEBUG_VFS_MKDIR < cycle ) |
---|
| 1179 | printk("\n[%s] thread[%x,%x] updated Inode Tree for <%s>\n", |
---|
| 1180 | __FUNCTION__, process->pid, this->trdid, path ); |
---|
| 1181 | #endif |
---|
| 1182 | |
---|
| 1183 | // release the lock protecting Inode Tree |
---|
| 1184 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1185 | |
---|
| 1186 | // 5. update parent directory mapper |
---|
| 1187 | // and synchronize the parent directory on IOC device |
---|
| 1188 | if (parent_cxy == local_cxy) |
---|
| 1189 | { |
---|
| 1190 | error = vfs_fs_add_dentry( parent_ptr, |
---|
| 1191 | dentry_ptr ); |
---|
| 1192 | } |
---|
| 1193 | else |
---|
| 1194 | { |
---|
| 1195 | rpc_vfs_fs_add_dentry_client( parent_cxy, |
---|
| 1196 | parent_ptr, |
---|
| 1197 | dentry_ptr, |
---|
| 1198 | &error ); |
---|
| 1199 | } |
---|
| 1200 | |
---|
| 1201 | if( error ) |
---|
| 1202 | { |
---|
| 1203 | printk("\n[ERROR] in %s : cannot update parent directory for <%s>\n", |
---|
| 1204 | __FUNCTION__, path ); |
---|
| 1205 | return -1; |
---|
| 1206 | } |
---|
| 1207 | |
---|
| 1208 | #if(DEBUG_VFS_MKDIR & 1) |
---|
| 1209 | if( DEBUG_VFS_MKDIR < cycle ) |
---|
| 1210 | printk("\n[%s] thread[%x,%x] updated parent dir (mapper and IOC) for <%s>\n", |
---|
| 1211 | __FUNCTION__, process->pid, this->trdid, path ); |
---|
| 1212 | #endif |
---|
| 1213 | |
---|
| 1214 | return 0; |
---|
| 1215 | |
---|
| 1216 | } // end vfs_mkdir() |
---|
| 1217 | |
---|
| 1218 | /////////////////////////////////////// |
---|
| 1219 | error_t vfs_link( xptr_t old_root_xp, |
---|
| 1220 | char * old_path, |
---|
| 1221 | xptr_t new_root_xp, |
---|
| 1222 | char * new_path ) |
---|
| 1223 | { |
---|
| 1224 | error_t error; |
---|
| 1225 | xptr_t vfs_root_xp; // extended pointer on VFS root inode |
---|
| 1226 | vfs_inode_t * vfs_root_ptr; // local pointer on VFS root inode |
---|
| 1227 | cxy_t vfs_root_cxy; // VFS root inode cluster identifier |
---|
| 1228 | xptr_t lock_xp; // extended pointer on lock protecting Inode Tree |
---|
| 1229 | xptr_t inode_xp; // extended pointer on target inode |
---|
| 1230 | vfs_inode_t * inode_ptr; // local pointer on target inode |
---|
| 1231 | cxy_t inode_cxy; // target inode cluster identifier |
---|
| 1232 | uint32_t inode_type; // target inode type |
---|
| 1233 | vfs_ctx_t * inode_ctx_ptr; // local pointer on target inode context |
---|
| 1234 | uint32_t inode_fs_type; // target inode file system type |
---|
| 1235 | xptr_t dentry_xp; // extended pointer on new dentry |
---|
| 1236 | vfs_dentry_t * dentry_ptr; // target dentry local pointer |
---|
| 1237 | xptr_t new_parent_xp; // extended pointer on new parent inode |
---|
| 1238 | vfs_inode_t * new_parent_ptr; // local pointer on new parent inode |
---|
| 1239 | cxy_t new_parent_cxy; // new parent inode cluster identifier |
---|
| 1240 | |
---|
| 1241 | xptr_t parents_root_xp; // extended pointer on parents field in inode (root) |
---|
| 1242 | xptr_t parents_entry_xp; // extended pointer on parents field in dentry |
---|
| 1243 | xptr_t children_xhtab_xp; // extended pointer on children field in inode (root) |
---|
| 1244 | xptr_t children_entry_xp; // extended pointer on children field in dentry |
---|
| 1245 | |
---|
| 1246 | char new_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1247 | |
---|
| 1248 | thread_t * this = CURRENT_THREAD; |
---|
| 1249 | process_t * process = this->process; |
---|
| 1250 | |
---|
| 1251 | #if DEBUG_VFS_LINK |
---|
| 1252 | char old_root_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1253 | char new_root_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1254 | vfs_inode_get_name( old_root_xp , old_root_name ); |
---|
| 1255 | vfs_inode_get_name( new_root_xp , new_root_name ); |
---|
| 1256 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 1257 | if( DEBUG_VFS_LINK < cycle ) |
---|
| 1258 | printk("\n[%s] thread[%x,%x] enter / old_root <%s> / old_path <%s> / " |
---|
| 1259 | "new_root <%s> / new_path <%s> / cycle %d\n", |
---|
| 1260 | __FUNCTION__, process->pid, this->trdid, |
---|
| 1261 | old_root_name, old_path, new_root_name, new_path, cycle ); |
---|
| 1262 | #endif |
---|
| 1263 | |
---|
| 1264 | // build extended pointer on lock protecting Inode Tree (in VFS root inode) |
---|
| 1265 | vfs_root_xp = process->vfs_root_xp; |
---|
| 1266 | vfs_root_ptr = GET_PTR( vfs_root_xp ); |
---|
| 1267 | vfs_root_cxy = GET_CXY( vfs_root_xp ); |
---|
| 1268 | lock_xp = XPTR( vfs_root_cxy , &vfs_root_ptr->main_lock ); |
---|
| 1269 | |
---|
| 1270 | // take the lock protecting Inode Tree in write mode |
---|
| 1271 | remote_rwlock_wr_acquire( lock_xp ); |
---|
| 1272 | |
---|
| 1273 | // get extended pointer on target inode |
---|
| 1274 | error = vfs_lookup( old_root_xp, |
---|
| 1275 | old_path, |
---|
| 1276 | 0, |
---|
| 1277 | &inode_xp, |
---|
| 1278 | NULL ); |
---|
| 1279 | if( error ) |
---|
| 1280 | { |
---|
| 1281 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1282 | printk("\n[ERROR] in %s : cannot get target inode for <%s>\n", |
---|
| 1283 | __FUNCTION__, old_path ); |
---|
| 1284 | return -1; |
---|
| 1285 | } |
---|
| 1286 | |
---|
| 1287 | #if( DEBUG_VFS_LINK & 1 ) |
---|
| 1288 | if( DEBUG_VFS_LINK < cycle ) |
---|
| 1289 | printk("\n[%s] thread[%x,%x] get child inode (%x,%x) for <%s>\n", |
---|
| 1290 | __FUNCTION__, process->pid, this->trdid, |
---|
| 1291 | GET_CXY(inode_xp), GET_PTR(inode_xp), old_path, cycle ); |
---|
| 1292 | #endif |
---|
| 1293 | |
---|
| 1294 | // get extended pointer on parent inode in new path |
---|
| 1295 | error = vfs_lookup( new_root_xp, |
---|
| 1296 | new_path, |
---|
| 1297 | VFS_LOOKUP_PARENT, |
---|
| 1298 | &new_parent_xp, |
---|
| 1299 | new_name ); |
---|
| 1300 | if( error ) |
---|
| 1301 | { |
---|
| 1302 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1303 | printk("\n[ERROR] in %s : cannot get parent inode for <%s>\n", |
---|
| 1304 | __FUNCTION__, new_path ); |
---|
| 1305 | return -1; |
---|
| 1306 | } |
---|
| 1307 | |
---|
| 1308 | #if( DEBUG_VFS_LINK & 1 ) |
---|
| 1309 | if( DEBUG_VFS_LINK < cycle ) |
---|
| 1310 | printk("\n[%s] thread[%x,%x] get parent inode (%x,%x) for <%s>\n", |
---|
| 1311 | __FUNCTION__, process->pid, this->trdid, |
---|
| 1312 | GET_CXY(new_parent_xp), GET_PTR(new_parent_xp), new_path ); |
---|
| 1313 | #endif |
---|
| 1314 | |
---|
| 1315 | // get target inode cluster and local pointer |
---|
| 1316 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 1317 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 1318 | |
---|
| 1319 | // get target inode type, context, and FS type |
---|
| 1320 | inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); |
---|
| 1321 | inode_ctx_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->ctx ) ); |
---|
| 1322 | inode_fs_type = hal_remote_l32( XPTR( inode_cxy , &inode_ctx_ptr->type ) ); |
---|
| 1323 | |
---|
| 1324 | // get new parent inode cluster an local pointer |
---|
| 1325 | new_parent_ptr = GET_PTR( new_parent_xp ); |
---|
| 1326 | new_parent_cxy = GET_CXY( new_parent_xp ); |
---|
| 1327 | |
---|
| 1328 | /////////////////////////////////////////////////////////////////////// |
---|
| 1329 | if( (inode_type == INODE_TYPE_FILE) || (inode_type == INODE_TYPE_DIR) ) |
---|
| 1330 | { |
---|
| 1331 | // 1. create one new dentry |
---|
| 1332 | if( new_parent_cxy == local_cxy ) |
---|
| 1333 | { |
---|
| 1334 | error = vfs_dentry_create( inode_fs_type, |
---|
| 1335 | new_name, |
---|
| 1336 | &dentry_xp ); |
---|
| 1337 | } |
---|
| 1338 | else |
---|
| 1339 | { |
---|
| 1340 | rpc_vfs_dentry_create_client( new_parent_cxy, |
---|
| 1341 | inode_fs_type, |
---|
| 1342 | new_name, |
---|
| 1343 | &dentry_xp, |
---|
| 1344 | &error ); |
---|
| 1345 | } |
---|
| 1346 | |
---|
| 1347 | if( error ) |
---|
| 1348 | { |
---|
| 1349 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1350 | printk("\n[ERROR] in %s : cannot create new dentry for <%s>\n", |
---|
| 1351 | __FUNCTION__, new_path ); |
---|
| 1352 | return -1; |
---|
| 1353 | } |
---|
| 1354 | |
---|
| 1355 | // get local pointer on dentry |
---|
| 1356 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
| 1357 | |
---|
| 1358 | // 2. register dentry in target inode |
---|
| 1359 | parents_root_xp = XPTR( inode_cxy , &inode_ptr->parents ); |
---|
| 1360 | parents_entry_xp = XPTR( new_parent_cxy , &dentry_ptr->parents ); |
---|
| 1361 | xlist_add_first( parents_root_xp , parents_entry_xp ); |
---|
| 1362 | hal_remote_atomic_add( XPTR( inode_cxy , &inode_ptr->links ) , 1 ); |
---|
| 1363 | |
---|
| 1364 | // 3. register dentry in parent inode |
---|
| 1365 | children_xhtab_xp = XPTR( new_parent_cxy , &new_parent_ptr->children ); |
---|
| 1366 | children_entry_xp = XPTR( new_parent_cxy , &dentry_ptr->children ); |
---|
| 1367 | xhtab_insert( children_xhtab_xp , new_name , children_entry_xp ); |
---|
| 1368 | |
---|
| 1369 | // 4. update "parent" and "child_xp" fields in dentry |
---|
| 1370 | hal_remote_s64( XPTR( new_parent_cxy , &dentry_ptr->child_xp ) , inode_xp ); |
---|
| 1371 | hal_remote_spt( XPTR( new_parent_cxy , &dentry_ptr->parent ) , new_parent_ptr ); |
---|
| 1372 | |
---|
| 1373 | #if(DEBUG_VFS_LINK & 1) |
---|
| 1374 | if( DEBUG_VFS_LINK < cycle ) |
---|
| 1375 | printk("\n[%s] thread[%x,%x] updated Inode Tree / old <%s> / new <%s>\n", |
---|
| 1376 | __FUNCTION__, process->pid, this->trdid, old_path, new_path ); |
---|
| 1377 | vfs_display( new_parent_xp ); |
---|
| 1378 | #endif |
---|
| 1379 | |
---|
| 1380 | // release the lock protecting Inode Tree |
---|
| 1381 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1382 | |
---|
| 1383 | // 5. update new parent directory mapper in Inode Tree |
---|
| 1384 | // and synchronize the parent directory on IOC device |
---|
| 1385 | if (new_parent_cxy == local_cxy) |
---|
| 1386 | { |
---|
| 1387 | error = vfs_fs_add_dentry( new_parent_ptr, |
---|
| 1388 | dentry_ptr ); |
---|
| 1389 | } |
---|
| 1390 | else |
---|
| 1391 | { |
---|
| 1392 | rpc_vfs_fs_add_dentry_client( new_parent_cxy, |
---|
| 1393 | new_parent_ptr, |
---|
| 1394 | dentry_ptr, |
---|
| 1395 | &error ); |
---|
| 1396 | } |
---|
| 1397 | if( error ) |
---|
| 1398 | { |
---|
| 1399 | printk("\n[ERROR] in %s : cannot update new parent directory for <%s>\n", |
---|
| 1400 | __FUNCTION__, new_path ); |
---|
| 1401 | return -1; |
---|
| 1402 | } |
---|
| 1403 | |
---|
| 1404 | #if(DEBUG_VFS_LINK & 1) |
---|
| 1405 | if( DEBUG_VFS_LINK < cycle ) |
---|
| 1406 | printk("\n[%s] thread[%x,%x] updated new parent dir (mapper and IOC) / old <%s> / new <%s>\n", |
---|
| 1407 | __FUNCTION__, process->pid, this->trdid, old_path, new_path ); |
---|
| 1408 | #endif |
---|
| 1409 | return 0; |
---|
| 1410 | } |
---|
| 1411 | else |
---|
| 1412 | { |
---|
| 1413 | // release the lock protecting Inode Tree |
---|
| 1414 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1415 | |
---|
| 1416 | printk("\n[ERROR] in %s : unsupported inode type %s\n", |
---|
| 1417 | __FUNCTION__ , vfs_inode_type_str( inode_type ) ); |
---|
| 1418 | return -1; |
---|
| 1419 | } |
---|
| 1420 | |
---|
| 1421 | } // end vfs_link() |
---|
| 1422 | |
---|
| 1423 | ///////////////////////////////////// |
---|
| 1424 | error_t vfs_unlink( xptr_t root_xp, |
---|
[23] | 1425 | char * path ) |
---|
[1] | 1426 | { |
---|
[602] | 1427 | error_t error; |
---|
[610] | 1428 | xptr_t vfs_root_xp; // extended pointer on VFS root inode |
---|
| 1429 | vfs_inode_t * vfs_root_ptr; // local_pointer on VFS root inode |
---|
| 1430 | cxy_t vfs_root_cxy; // VFS root inode cluster identifier |
---|
| 1431 | xptr_t lock_xp; // extended pointer on lock protecting Inode Tree |
---|
| 1432 | xptr_t parent_xp; // extended pointer on target inode |
---|
| 1433 | cxy_t parent_cxy; // target inode cluster identifier |
---|
| 1434 | vfs_inode_t * parent_ptr; // target inode local pointer |
---|
[602] | 1435 | xptr_t inode_xp; // extended pointer on target inode |
---|
| 1436 | cxy_t inode_cxy; // target inode cluster identifier |
---|
| 1437 | vfs_inode_t * inode_ptr; // target inode local pointer |
---|
[610] | 1438 | uint32_t inode_links; // target inode links count |
---|
| 1439 | vfs_inode_type_t inode_type; // target inode type |
---|
| 1440 | uint32_t inode_children; // target inode number of children |
---|
| 1441 | xptr_t dentry_xp; // extended pointer on dentry to unlink |
---|
| 1442 | vfs_dentry_t * dentry_ptr; // local pointer on dentry to unlink |
---|
[1] | 1443 | |
---|
[610] | 1444 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; // name of link to remove |
---|
| 1445 | |
---|
| 1446 | thread_t * this = CURRENT_THREAD; |
---|
| 1447 | process_t * process = this->process; |
---|
| 1448 | |
---|
[602] | 1449 | #if DEBUG_VFS_UNLINK |
---|
| 1450 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[610] | 1451 | char root_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1452 | vfs_inode_get_name( root_xp , root_name ); |
---|
[602] | 1453 | if( DEBUG_VFS_UNLINK < cycle ) |
---|
[610] | 1454 | printk("\n[%s] thread[%x,%x] enter / root <%s> / path <%s> / cycle %d\n", |
---|
| 1455 | __FUNCTION__, process->pid, this->trdid, root_name, path, cycle ); |
---|
[602] | 1456 | #endif |
---|
| 1457 | |
---|
[610] | 1458 | // build extended pointer on lock protecting Inode Tree (in VFS root inode) |
---|
| 1459 | vfs_root_xp = process->vfs_root_xp; |
---|
| 1460 | vfs_root_ptr = GET_PTR( root_xp ); |
---|
| 1461 | vfs_root_cxy = GET_CXY( root_xp ); |
---|
| 1462 | lock_xp = XPTR( vfs_root_cxy , &vfs_root_ptr->main_lock ); |
---|
[602] | 1463 | |
---|
[610] | 1464 | // take the lock protecting Inode Tree |
---|
| 1465 | remote_rwlock_wr_acquire( lock_xp ); |
---|
[602] | 1466 | |
---|
[610] | 1467 | // get extended pointer on parent inode |
---|
| 1468 | error = vfs_lookup( root_xp, |
---|
| 1469 | path, |
---|
| 1470 | VFS_LOOKUP_PARENT, |
---|
| 1471 | &parent_xp, |
---|
| 1472 | name ); |
---|
| 1473 | if( error ) |
---|
| 1474 | { |
---|
| 1475 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1476 | printk("\n[ERROR] in %s : cannot get parent inode for <%s> in <%s>\n", |
---|
| 1477 | __FUNCTION__, name, path ); |
---|
| 1478 | return -1; |
---|
| 1479 | } |
---|
| 1480 | |
---|
| 1481 | // get parent inode cluster and local pointer |
---|
| 1482 | parent_cxy = GET_CXY( parent_xp ); |
---|
| 1483 | parent_ptr = GET_PTR( parent_xp ); |
---|
| 1484 | |
---|
| 1485 | #if( DEBUG_VFS_UNLINK & 1 ) |
---|
| 1486 | char parent_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1487 | vfs_inode_get_name( parent_xp , parent_name ); |
---|
| 1488 | if( DEBUG_VFS_UNLINK < cycle ) |
---|
| 1489 | printk("\n[%s] thread[%x,%x] parent inode <%s> is (%x,%x)\n", |
---|
| 1490 | __FUNCTION__, process->pid, this->trdid, parent_name, parent_cxy, parent_ptr ); |
---|
| 1491 | #endif |
---|
| 1492 | |
---|
| 1493 | // build extended pointer on parent inode "children" xhtab |
---|
| 1494 | xptr_t children_xp = XPTR( parent_cxy , &parent_ptr->children ); |
---|
| 1495 | |
---|
| 1496 | // get extended pointer on dentry to unlink |
---|
| 1497 | dentry_xp = xhtab_lookup( children_xp , name ); |
---|
| 1498 | |
---|
| 1499 | if( dentry_xp == XPTR_NULL ) |
---|
| 1500 | { |
---|
| 1501 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1502 | printk("\n[ERROR] in %s : cannot get target dentry <%s> in <%s>\n", |
---|
| 1503 | __FUNCTION__, name, path ); |
---|
| 1504 | return -1; |
---|
| 1505 | } |
---|
| 1506 | |
---|
| 1507 | // get local pointer on dentry to unlink |
---|
| 1508 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
| 1509 | |
---|
| 1510 | #if( DEBUG_VFS_UNLINK & 1 ) |
---|
| 1511 | if( DEBUG_VFS_UNLINK < cycle ) |
---|
| 1512 | printk("\n[%s] thread[%x,%x] dentry <%s> to unlink is (%x,%x)\n", |
---|
| 1513 | __FUNCTION__, process->pid, this->trdid, name, parent_cxy, dentry_ptr ); |
---|
| 1514 | #endif |
---|
| 1515 | |
---|
| 1516 | // get pointer on target inode |
---|
| 1517 | inode_xp = hal_remote_l64( XPTR( parent_cxy , &dentry_ptr->child_xp ) ); |
---|
[602] | 1518 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 1519 | inode_ptr = GET_PTR( inode_xp ); |
---|
[610] | 1520 | |
---|
| 1521 | #if( DEBUG_VFS_UNLINK & 1 ) |
---|
| 1522 | char inode_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1523 | vfs_inode_get_name( inode_xp , inode_name ); |
---|
| 1524 | if( DEBUG_VFS_UNLINK < cycle ) |
---|
| 1525 | printk("\n[%s] thread[%x,%x] target inode <%s> is (%x,%x) / cycle %d\n", |
---|
| 1526 | __FUNCTION__, process->pid, this->trdid, inode_name, inode_cxy, inode_ptr, cycle ); |
---|
| 1527 | #endif |
---|
[602] | 1528 | |
---|
[610] | 1529 | // get target inode "type" and "links" |
---|
| 1530 | inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); |
---|
| 1531 | inode_links = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->links ) ); |
---|
[602] | 1532 | |
---|
[610] | 1533 | // check target inode links counter |
---|
| 1534 | assert( (inode_links >= 1), "illegal inode links count %d for <%s>\n", inode_links, path ); |
---|
[602] | 1535 | |
---|
[610] | 1536 | /////////////////////////////////////////////////////////////////////// |
---|
| 1537 | if( (inode_type == INODE_TYPE_FILE) || (inode_type == INODE_TYPE_DIR) ) |
---|
[602] | 1538 | { |
---|
[610] | 1539 | // 1. Release clusters allocated to target inode |
---|
| 1540 | // and synchronize the FAT on IOC device if last link. |
---|
| 1541 | if( inode_links == 1 ) |
---|
[602] | 1542 | { |
---|
[610] | 1543 | // build extended pointer on target inode "children" number |
---|
| 1544 | xptr_t inode_children_xp = XPTR( inode_cxy , &inode_ptr->children.items ); |
---|
[602] | 1545 | |
---|
[610] | 1546 | // get target inode number of children |
---|
| 1547 | inode_children = hal_remote_l32( inode_children_xp ); |
---|
| 1548 | |
---|
| 1549 | // check no children |
---|
| 1550 | if( inode_children != 0 ) |
---|
| 1551 | { |
---|
| 1552 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1553 | printk("\n[ERROR] in %s : cannot remove <%s> inode that has children\n", |
---|
| 1554 | __FUNCTION__, path ); |
---|
| 1555 | return -1; |
---|
| 1556 | } |
---|
| 1557 | |
---|
| 1558 | // release clusters on IOC device |
---|
| 1559 | error = vfs_fs_release_inode( inode_xp ); |
---|
| 1560 | |
---|
| 1561 | if( error ) |
---|
| 1562 | { |
---|
| 1563 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1564 | printk("\n[ERROR] in %s : cannot update FAT mapper to remove <%s> inode\n", |
---|
| 1565 | __FUNCTION__ , path ); |
---|
| 1566 | return -1; |
---|
| 1567 | } |
---|
| 1568 | |
---|
[602] | 1569 | #if(DEBUG_VFS_UNLINK & 1) |
---|
| 1570 | if( DEBUG_VFS_UNLINK < cycle ) |
---|
| 1571 | printk("\n[%s] thread[%x,%x] removed <%s> inode from FAT (mapper and IOC device)\n", |
---|
[610] | 1572 | __FUNCTION__, process->pid, this->trdid, path ); |
---|
[602] | 1573 | #endif |
---|
[610] | 1574 | } |
---|
[602] | 1575 | |
---|
[610] | 1576 | // 2. update parent directory mapper |
---|
| 1577 | // and synchronize the parent directory on IOC device |
---|
| 1578 | if (parent_cxy == local_cxy) |
---|
[602] | 1579 | { |
---|
[610] | 1580 | error = vfs_fs_remove_dentry( parent_ptr, |
---|
[602] | 1581 | dentry_ptr ); |
---|
| 1582 | } |
---|
[610] | 1583 | else |
---|
[602] | 1584 | { |
---|
[610] | 1585 | rpc_vfs_fs_remove_dentry_client( parent_cxy, |
---|
| 1586 | parent_ptr, |
---|
[602] | 1587 | dentry_ptr, |
---|
| 1588 | &error ); |
---|
| 1589 | } |
---|
[610] | 1590 | |
---|
[602] | 1591 | if( error ) |
---|
| 1592 | { |
---|
[610] | 1593 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1594 | printk("\n[ERROR] in %s : cannot update dentry on device for <%s>\n", |
---|
| 1595 | __FUNCTION__ , path ); |
---|
[602] | 1596 | return -1; |
---|
| 1597 | } |
---|
| 1598 | |
---|
| 1599 | #if(DEBUG_VFS_UNLINK & 1) |
---|
| 1600 | if( DEBUG_VFS_UNLINK < cycle ) |
---|
| 1601 | printk("\n[%s] thread[%x,%x] removed <%s> inode from parent dir (mapper and IOC device)\n", |
---|
[610] | 1602 | __FUNCTION__, process->pid, this->trdid, path ); |
---|
[602] | 1603 | #endif |
---|
[610] | 1604 | // 3. remove dentry from Inode Tree (and associated chils inode when last link) |
---|
| 1605 | vfs_remove_child_from_parent( dentry_xp ); |
---|
[602] | 1606 | |
---|
[610] | 1607 | // release the lock protecting Inode Tree |
---|
| 1608 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1609 | |
---|
[602] | 1610 | #if DEBUG_VFS_UNLINK |
---|
| 1611 | if( DEBUG_VFS_UNLINK < cycle ) |
---|
| 1612 | printk("\n[%s] thread[%x,%x] exit / removed <%s> inode from Inode Tree / cycle %d\n", |
---|
[610] | 1613 | __FUNCTION__, process->pid, this->trdid, path, cycle ); |
---|
[602] | 1614 | #endif |
---|
| 1615 | return 0; |
---|
| 1616 | } |
---|
| 1617 | else |
---|
| 1618 | { |
---|
[610] | 1619 | remote_rwlock_wr_release( lock_xp ); |
---|
| 1620 | printk("\n[ERROR] in %s : unsupported inode type %s\n", |
---|
| 1621 | __FUNCTION__ , vfs_inode_type_str( inode_type ) ); |
---|
[602] | 1622 | return -1; |
---|
| 1623 | } |
---|
| 1624 | |
---|
| 1625 | } // end vfs_unlink() |
---|
| 1626 | |
---|
[610] | 1627 | /////////////////////////////////////////// |
---|
| 1628 | error_t vfs_stat( xptr_t root_inode_xp, |
---|
| 1629 | char * path, |
---|
[598] | 1630 | stat_t * st ) |
---|
[1] | 1631 | { |
---|
[610] | 1632 | error_t error; |
---|
| 1633 | xptr_t inode_xp; // extended pointer on target inode |
---|
| 1634 | vfs_inode_t * inode_ptr; // local pointer on target inode |
---|
| 1635 | cxy_t inode_cxy; // target inode cluster identifier |
---|
| 1636 | xptr_t vfs_root_xp; // extended pointer on VFS root inode |
---|
| 1637 | vfs_inode_t * vfs_root_ptr; // local_pointer on VFS root inode |
---|
| 1638 | cxy_t vfs_root_cxy; // VFS root inode cluster identifier |
---|
| 1639 | xptr_t lock_xp; // extended pointer on lock protecting Inode Tree |
---|
| 1640 | |
---|
| 1641 | thread_t * this = CURRENT_THREAD; |
---|
| 1642 | process_t * process = this->process; |
---|
| 1643 | |
---|
| 1644 | // build extended pointer on lock protecting Inode Tree (in VFS root inode) |
---|
| 1645 | vfs_root_xp = process->vfs_root_xp; |
---|
| 1646 | vfs_root_ptr = GET_PTR( vfs_root_xp ); |
---|
| 1647 | vfs_root_cxy = GET_CXY( vfs_root_xp ); |
---|
| 1648 | lock_xp = XPTR( vfs_root_cxy , &vfs_root_ptr->main_lock ); |
---|
| 1649 | |
---|
| 1650 | // get the lock protecting Inode Tree in read mode |
---|
| 1651 | remote_rwlock_rd_acquire( lock_xp ); |
---|
| 1652 | |
---|
| 1653 | // get extended pointer on target inode |
---|
| 1654 | error = vfs_lookup( root_inode_xp, |
---|
| 1655 | path, |
---|
| 1656 | 0, |
---|
| 1657 | &inode_xp, |
---|
| 1658 | NULL ); |
---|
| 1659 | |
---|
| 1660 | // release the lock protecting Inode Tree |
---|
| 1661 | remote_rwlock_rd_release( lock_xp ); |
---|
| 1662 | |
---|
| 1663 | if( error ) |
---|
| 1664 | { |
---|
| 1665 | printk("\n[ERROR] in %s : cannot found inode <%s>\n", |
---|
| 1666 | __FUNCTION__ , path ); |
---|
| 1667 | return -1; |
---|
| 1668 | } |
---|
| 1669 | |
---|
[598] | 1670 | // get cluster and local pointer on inode descriptor |
---|
[610] | 1671 | inode_ptr = GET_PTR( inode_xp ); |
---|
| 1672 | inode_cxy = GET_CXY( inode_xp ); |
---|
[598] | 1673 | |
---|
| 1674 | // get relevant infos from inode descriptor |
---|
| 1675 | uint32_t inum = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->inum ) ); |
---|
| 1676 | uint32_t size = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->size ) ); |
---|
| 1677 | uint32_t uid = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->uid ) ); |
---|
| 1678 | uint32_t gid = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->gid ) ); |
---|
| 1679 | uint32_t type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); |
---|
| 1680 | uint32_t rights = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->rights ) ); |
---|
| 1681 | |
---|
| 1682 | // set stat structure fields |
---|
| 1683 | st->st_ino = inum; |
---|
| 1684 | st->st_gid = gid; |
---|
| 1685 | st->st_uid = uid; |
---|
| 1686 | st->st_size = size; |
---|
| 1687 | st->st_mode = (type << 16) | rights; |
---|
| 1688 | |
---|
| 1689 | #if DEBUG_VFS_STAT |
---|
| 1690 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 1691 | if( DEBUG_VFS_STAT < cycle ) |
---|
| 1692 | printk("\n[%s] thread[%x,%x] set stat %x for inode %x in cluster %x / cycle %d\n" |
---|
| 1693 | " %s / inum %d / size %d\n", |
---|
[610] | 1694 | __FUNCTION__, process->pid, this->trdid, st, inode_ptr, inode_cxy, cycle, |
---|
[598] | 1695 | vfs_inode_type_str( type ), inum, size ); |
---|
| 1696 | #endif |
---|
| 1697 | |
---|
[1] | 1698 | return 0; |
---|
| 1699 | |
---|
[602] | 1700 | } // end vfs_stat() |
---|
| 1701 | |
---|
[407] | 1702 | ///////////////////////////////////////////// |
---|
| 1703 | error_t vfs_readdir( xptr_t file_xp, |
---|
| 1704 | struct dirent * k_dirent ) |
---|
[1] | 1705 | { |
---|
[492] | 1706 | assert( false , "not implemented file_xp: %x, k_dirent ptr %x\n", |
---|
| 1707 | file_xp, k_dirent ); |
---|
[1] | 1708 | return 0; |
---|
| 1709 | } |
---|
| 1710 | |
---|
[23] | 1711 | //////////////////////////////////// |
---|
| 1712 | error_t vfs_rmdir( xptr_t file_xp, |
---|
| 1713 | char * path ) |
---|
[1] | 1714 | { |
---|
[492] | 1715 | assert( false , "not implemented file_xp: %x, path <%s>\n", |
---|
| 1716 | file_xp, path ); |
---|
[1] | 1717 | return 0; |
---|
| 1718 | } |
---|
| 1719 | |
---|
[610] | 1720 | //////////////////////////////////// |
---|
| 1721 | error_t vfs_chdir( xptr_t root_xp, |
---|
[23] | 1722 | char * path ) |
---|
[1] | 1723 | { |
---|
[23] | 1724 | error_t error; |
---|
[610] | 1725 | xptr_t inode_xp; // extended pointer on target inode |
---|
| 1726 | cxy_t inode_cxy; // target inode cluster identifier |
---|
| 1727 | vfs_inode_t * inode_ptr; // target inode local pointer |
---|
| 1728 | vfs_inode_type_t inode_type; // target inode type |
---|
| 1729 | xptr_t vfs_root_xp; // extended pointer on VFS root inode |
---|
| 1730 | vfs_inode_t * vfs_root_ptr; // local_pointer on VFS root inode |
---|
| 1731 | cxy_t vfs_root_cxy; // VFS root inode cluster identifier |
---|
| 1732 | xptr_t main_lock_xp; // extended pointer on lock protecting Inode Tree |
---|
| 1733 | xptr_t ref_xp; // extended pointer on reference process |
---|
| 1734 | process_t * ref_ptr; // local pointer on reference process |
---|
| 1735 | cxy_t ref_cxy; // reference process cluster |
---|
| 1736 | xptr_t cwd_lock_xp; // extended pointer on lock protecting CWD change |
---|
| 1737 | xptr_t cwd_xp_xp; // extended pointer on cwd_xp in reference process |
---|
[23] | 1738 | |
---|
[610] | 1739 | thread_t * this = CURRENT_THREAD; |
---|
| 1740 | process_t * process = this->process; |
---|
[23] | 1741 | |
---|
[610] | 1742 | #if DEBUG_VFS_CHDIR |
---|
| 1743 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 1744 | if( DEBUG_VFS_CHDIR < cycle ) |
---|
| 1745 | printk("\n[%s] thread[%x,%x] enter for path <%s> / cycle %d\n", |
---|
| 1746 | __FUNCTION__, process->pid, this->trdid, path, cycle ); |
---|
| 1747 | #endif |
---|
| 1748 | |
---|
| 1749 | // build extended pointer on lock protecting Inode Tree (in VFS root inode) |
---|
| 1750 | vfs_root_xp = process->vfs_root_xp; |
---|
| 1751 | vfs_root_ptr = GET_PTR( vfs_root_xp ); |
---|
| 1752 | vfs_root_cxy = GET_CXY( vfs_root_xp ); |
---|
| 1753 | main_lock_xp = XPTR( vfs_root_cxy , &vfs_root_ptr->main_lock ); |
---|
| 1754 | |
---|
| 1755 | // take lock protecting Inode Tree in read mode |
---|
| 1756 | remote_rwlock_rd_acquire( main_lock_xp ); |
---|
| 1757 | |
---|
[23] | 1758 | // get extended pointer on target inode |
---|
[610] | 1759 | error = vfs_lookup( root_xp, |
---|
| 1760 | path, |
---|
| 1761 | VFS_LOOKUP_DIR, |
---|
| 1762 | &inode_xp, |
---|
| 1763 | NULL ); |
---|
[23] | 1764 | |
---|
[610] | 1765 | // release lock protecting Inode Tree in read mode |
---|
| 1766 | remote_rwlock_rd_release( main_lock_xp ); |
---|
[23] | 1767 | |
---|
[610] | 1768 | if( error ) |
---|
| 1769 | { |
---|
| 1770 | printk("\n[ERROR] in %s : <%s> not found\n", |
---|
| 1771 | __FUNCTION__, path ); |
---|
| 1772 | return -1; |
---|
| 1773 | } |
---|
| 1774 | |
---|
| 1775 | // get inode type from remote file |
---|
[23] | 1776 | inode_cxy = GET_CXY( inode_xp ); |
---|
[473] | 1777 | inode_ptr = GET_PTR( inode_xp ); |
---|
[568] | 1778 | inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); |
---|
[23] | 1779 | |
---|
| 1780 | if( inode_type != INODE_TYPE_DIR ) |
---|
| 1781 | { |
---|
[610] | 1782 | printk("\n[ERROR] in %s : <%s> is not a directory\n", |
---|
| 1783 | __FUNCTION__, path ); |
---|
[23] | 1784 | return -1; |
---|
| 1785 | } |
---|
| 1786 | |
---|
[610] | 1787 | // build extended pointer on cwd_lock and cwd_xp |
---|
| 1788 | ref_xp = process->ref_xp; |
---|
| 1789 | ref_ptr = GET_PTR( ref_xp ); |
---|
| 1790 | ref_cxy = GET_CXY( ref_xp ); |
---|
| 1791 | cwd_lock_xp = XPTR( ref_cxy , &ref_ptr->cwd_lock ); |
---|
| 1792 | cwd_xp_xp = XPTR( ref_cxy , &ref_ptr->cwd_xp ); |
---|
[568] | 1793 | |
---|
[610] | 1794 | // take lock protecting CWD changes |
---|
| 1795 | remote_busylock_acquire( cwd_lock_xp ); |
---|
[568] | 1796 | |
---|
[610] | 1797 | // update cwd_xp field in reference process descriptor |
---|
| 1798 | hal_remote_s64( cwd_xp_xp , inode_xp ); |
---|
| 1799 | |
---|
| 1800 | // release lock protecting CWD changes |
---|
| 1801 | remote_busylock_release( cwd_lock_xp ); |
---|
| 1802 | |
---|
| 1803 | #if DEBUG_VFS_CHDIR |
---|
| 1804 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 1805 | if( DEBUG_VFS_CHDIR < cycle ) |
---|
| 1806 | printk("\n[%s] thread[%x,%x] exit : inode (%x,%x) / &cwd_xp (%x,%x) / cycle %d\n", |
---|
| 1807 | __FUNCTION__, process->pid, this->trdid, inode_cxy, inode_ptr, |
---|
| 1808 | GET_CXY(cwd_xp_xp), GET_PTR(cwd_xp_xp), cycle ); |
---|
| 1809 | #endif |
---|
| 1810 | |
---|
[1] | 1811 | return 0; |
---|
| 1812 | |
---|
[610] | 1813 | } // end vfs_chdir() |
---|
| 1814 | |
---|
[23] | 1815 | /////////////////////////////////// |
---|
| 1816 | error_t vfs_chmod( xptr_t cwd_xp, |
---|
| 1817 | char * path, |
---|
| 1818 | uint32_t rights ) |
---|
[1] | 1819 | { |
---|
[23] | 1820 | error_t error; |
---|
| 1821 | xptr_t inode_xp; // extended pointer on target inode |
---|
| 1822 | cxy_t inode_cxy; // inode cluster identifier |
---|
| 1823 | vfs_inode_t * inode_ptr; // inode local pointer |
---|
| 1824 | vfs_inode_type_t inode_type; // target inode type |
---|
| 1825 | |
---|
| 1826 | // set lookup working mode |
---|
[473] | 1827 | assert( (rights == 0), __FUNCTION__, |
---|
| 1828 | "access rights non implemented yet\n" ); |
---|
[23] | 1829 | |
---|
| 1830 | // get extended pointer on target inode |
---|
[610] | 1831 | error = vfs_lookup( cwd_xp, |
---|
| 1832 | path, |
---|
| 1833 | 0, |
---|
| 1834 | &inode_xp, |
---|
| 1835 | NULL ); |
---|
[23] | 1836 | |
---|
| 1837 | if( error ) return error; |
---|
| 1838 | |
---|
| 1839 | // get inode cluster and local pointer |
---|
| 1840 | inode_cxy = GET_CXY( inode_xp ); |
---|
[473] | 1841 | inode_ptr = GET_PTR( inode_xp ); |
---|
[23] | 1842 | |
---|
| 1843 | // get inode type from remote inode |
---|
[568] | 1844 | inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); |
---|
[23] | 1845 | |
---|
[610] | 1846 | // TODO implement this function |
---|
| 1847 | |
---|
| 1848 | assert( false , "not implemented\n" ); |
---|
| 1849 | |
---|
[1] | 1850 | return 0; |
---|
| 1851 | } |
---|
| 1852 | |
---|
[23] | 1853 | /////////////////////////////////// |
---|
| 1854 | error_t vfs_mkfifo( xptr_t cwd_xp, |
---|
| 1855 | char * path, |
---|
| 1856 | uint32_t rights ) |
---|
| 1857 | { |
---|
[492] | 1858 | assert( false , "not implemented cwd_xp: %x, path <%s>, rights %x\n", |
---|
| 1859 | cwd_xp, path, rights ); |
---|
[23] | 1860 | return 0; |
---|
| 1861 | } |
---|
[1] | 1862 | |
---|
| 1863 | |
---|
| 1864 | |
---|
[188] | 1865 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 1866 | // Distributed Inode Tree access related functions |
---|
[1] | 1867 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1868 | |
---|
[188] | 1869 | ////////////////////////////////////////////////////////////////////////// |
---|
| 1870 | // This static function is called by the vfs_display() function. |
---|
[337] | 1871 | // that is supposed to take the TXT0 lock. |
---|
[188] | 1872 | ////////////////////////////////////////////////////////////////////////// |
---|
| 1873 | static void vfs_recursive_display( xptr_t inode_xp, |
---|
| 1874 | xptr_t name_xp, |
---|
| 1875 | uint32_t indent ) |
---|
| 1876 | { |
---|
| 1877 | cxy_t inode_cxy; |
---|
| 1878 | vfs_inode_t * inode_ptr; |
---|
| 1879 | vfs_inode_type_t inode_type; |
---|
[598] | 1880 | uint32_t inode_size; |
---|
| 1881 | uint32_t inode_inum; |
---|
| 1882 | uint32_t inode_attr; |
---|
| 1883 | uint32_t inode_dirty; |
---|
[204] | 1884 | xptr_t children_xp; // extended pointer on children xhtab |
---|
[188] | 1885 | |
---|
[204] | 1886 | xptr_t child_dentry_xp; |
---|
| 1887 | cxy_t child_dentry_cxy; |
---|
| 1888 | vfs_dentry_t * child_dentry_ptr; |
---|
| 1889 | xptr_t child_inode_xp; |
---|
| 1890 | xptr_t child_dentry_name_xp; |
---|
[598] | 1891 | mapper_t * mapper_ptr; |
---|
[188] | 1892 | |
---|
| 1893 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1894 | |
---|
| 1895 | char * indent_str[] = { "", // level 0 |
---|
| 1896 | " ", // level 1 |
---|
| 1897 | " ", // level 2 |
---|
| 1898 | " ", // level 3 |
---|
| 1899 | " ", // level 4 |
---|
| 1900 | " ", // level 5 |
---|
| 1901 | " ", // level 6 |
---|
| 1902 | " ", // level 7 |
---|
| 1903 | " ", // level 8 |
---|
| 1904 | " ", // level 9 |
---|
| 1905 | " ", // level 10 |
---|
| 1906 | " ", // level 11 |
---|
| 1907 | " ", // level 12 |
---|
| 1908 | " ", // level 13 |
---|
| 1909 | " ", // level 14 |
---|
| 1910 | " " }; // level 15 |
---|
| 1911 | |
---|
[598] | 1912 | assert( (inode_xp != XPTR_NULL) , "inode_xp cannot be NULL\n" ); |
---|
| 1913 | assert( (name_xp != XPTR_NULL) , "name_xp cannot be NULL\n" ); |
---|
| 1914 | assert( (indent < 16) , "depth cannot be larger than 15\n" ); |
---|
[188] | 1915 | |
---|
[610] | 1916 | // get current inode cluster and local pointer |
---|
[188] | 1917 | inode_cxy = GET_CXY( inode_xp ); |
---|
[473] | 1918 | inode_ptr = GET_PTR( inode_xp ); |
---|
[188] | 1919 | |
---|
[598] | 1920 | // get inode type, size, attr, mapper, and inum |
---|
| 1921 | inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); |
---|
| 1922 | inode_size = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->size ) ); |
---|
| 1923 | inode_inum = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->inum ) ); |
---|
| 1924 | inode_attr = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->attr ) ); |
---|
| 1925 | mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); |
---|
[188] | 1926 | |
---|
| 1927 | // make a local copy of node name |
---|
| 1928 | hal_remote_strcpy( XPTR( local_cxy , name ) , name_xp ); |
---|
| 1929 | |
---|
[598] | 1930 | // compute dirty |
---|
| 1931 | inode_dirty = ((inode_attr & INODE_ATTR_DIRTY) != 0); |
---|
| 1932 | |
---|
[188] | 1933 | // display inode |
---|
[598] | 1934 | nolock_printk("%s%s <%s> : inum %d / %d bytes / dirty %d / cxy %x (inode %x / mapper %x)\n", |
---|
[367] | 1935 | indent_str[indent], vfs_inode_type_str( inode_type ), name, |
---|
[598] | 1936 | inode_inum, inode_size, inode_dirty, inode_cxy, inode_ptr, mapper_ptr ); |
---|
[188] | 1937 | |
---|
| 1938 | // scan directory entries |
---|
| 1939 | if( inode_type == INODE_TYPE_DIR ) |
---|
| 1940 | { |
---|
| 1941 | // get extended pointer on directory entries xhtab |
---|
[204] | 1942 | children_xp = XPTR( inode_cxy , &inode_ptr->children ); |
---|
[188] | 1943 | |
---|
| 1944 | // get xhtab lock |
---|
[568] | 1945 | xhtab_lock( children_xp ); |
---|
[188] | 1946 | |
---|
| 1947 | // get first dentry from xhtab |
---|
[204] | 1948 | child_dentry_xp = xhtab_get_first( children_xp ); |
---|
[188] | 1949 | |
---|
[204] | 1950 | while( child_dentry_xp != XPTR_NULL ) |
---|
[188] | 1951 | { |
---|
| 1952 | // get dentry cluster and local pointer |
---|
[204] | 1953 | child_dentry_cxy = GET_CXY( child_dentry_xp ); |
---|
[473] | 1954 | child_dentry_ptr = GET_PTR( child_dentry_xp ); |
---|
[188] | 1955 | |
---|
| 1956 | // get extended pointer on child inode |
---|
[568] | 1957 | child_inode_xp = hal_remote_l64( XPTR( child_dentry_cxy, |
---|
[204] | 1958 | &child_dentry_ptr->child_xp ) ); |
---|
[188] | 1959 | |
---|
| 1960 | // get extended pointer on dentry name |
---|
[204] | 1961 | child_dentry_name_xp = XPTR( child_dentry_cxy , &child_dentry_ptr->name ); |
---|
[188] | 1962 | |
---|
[568] | 1963 | // recursive call on inode display |
---|
[204] | 1964 | vfs_recursive_display( child_inode_xp, |
---|
| 1965 | child_dentry_name_xp, |
---|
| 1966 | indent+1 ); |
---|
[188] | 1967 | |
---|
| 1968 | // get next dentry |
---|
[204] | 1969 | child_dentry_xp = xhtab_get_next( children_xp ); |
---|
[188] | 1970 | } |
---|
| 1971 | |
---|
| 1972 | // release xhtab lock |
---|
[568] | 1973 | xhtab_unlock( children_xp ); |
---|
[188] | 1974 | } |
---|
| 1975 | } // end vfs_recursive_display() |
---|
| 1976 | |
---|
| 1977 | /////////////////////////////////// |
---|
| 1978 | void vfs_display( xptr_t inode_xp ) |
---|
| 1979 | { |
---|
[204] | 1980 | xptr_t name_xp; |
---|
[188] | 1981 | xptr_t dentry_xp; |
---|
| 1982 | cxy_t dentry_cxy; |
---|
| 1983 | vfs_dentry_t * dentry_ptr; |
---|
[610] | 1984 | xptr_t parents_root_xp; // root of parent dentries xlist |
---|
[188] | 1985 | |
---|
| 1986 | // get target inode cluster and local pointer |
---|
| 1987 | cxy_t inode_cxy = GET_CXY( inode_xp ); |
---|
[473] | 1988 | vfs_inode_t * inode_ptr = GET_PTR( inode_xp ); |
---|
[188] | 1989 | |
---|
[610] | 1990 | // build extended pointer on parents dentries root |
---|
| 1991 | parents_root_xp = XPTR( inode_cxy , &inode_ptr->parents ); |
---|
[188] | 1992 | |
---|
[610] | 1993 | // check VFS root |
---|
| 1994 | if( xlist_is_empty( parents_root_xp ) ) // inode is the VFS root |
---|
[188] | 1995 | { |
---|
| 1996 | // build extended pointer on root name |
---|
| 1997 | name_xp = XPTR( local_cxy , "/" ); |
---|
| 1998 | } |
---|
| 1999 | else |
---|
| 2000 | { |
---|
[610] | 2001 | // get first parent dentry cluster and pointers |
---|
| 2002 | dentry_xp = XLIST_FIRST( parents_root_xp , vfs_dentry_t , parents ); |
---|
[188] | 2003 | dentry_cxy = GET_CXY( dentry_xp ); |
---|
[473] | 2004 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
[188] | 2005 | |
---|
| 2006 | // get extended pointer on dentry name |
---|
| 2007 | name_xp = XPTR( dentry_cxy , &dentry_ptr->name ); |
---|
| 2008 | } |
---|
| 2009 | |
---|
[337] | 2010 | // get pointers on TXT0 chdev |
---|
[407] | 2011 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
---|
[337] | 2012 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
---|
| 2013 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
---|
| 2014 | |
---|
| 2015 | // get extended pointer on remote TXT0 chdev lock |
---|
| 2016 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
| 2017 | |
---|
| 2018 | // get TXT0 lock in busy waiting mode |
---|
[568] | 2019 | remote_busylock_acquire( lock_xp ); |
---|
[337] | 2020 | |
---|
[188] | 2021 | // print header |
---|
[401] | 2022 | nolock_printk("\n***** file system state\n\n"); |
---|
[188] | 2023 | |
---|
| 2024 | // call recursive function |
---|
[473] | 2025 | vfs_recursive_display( inode_xp , name_xp , 0 ); |
---|
[188] | 2026 | |
---|
[337] | 2027 | // release lock |
---|
[568] | 2028 | remote_busylock_release( lock_xp ); |
---|
[337] | 2029 | |
---|
[204] | 2030 | } // end vfs_display() |
---|
[188] | 2031 | |
---|
[602] | 2032 | /* |
---|
[1] | 2033 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 2034 | // This static function is used by the vfs_lookup() function. |
---|
[1] | 2035 | // It takes an extended pointer on a remote inode (parent directory inode), |
---|
| 2036 | // and check access_rights violation for the calling thread. |
---|
| 2037 | // It can be used by any thread running in any cluster. |
---|
| 2038 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2039 | // @ inode_xp : extended pointer on inode. |
---|
| 2040 | // @ client_uid : client thread user ID |
---|
| 2041 | // @ client_gid : client thread group ID |
---|
| 2042 | // @ return true if access rights are violated. |
---|
| 2043 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 2044 | static bool_t vfs_access_denied( xptr_t inode_xp, |
---|
[1] | 2045 | uint32_t client_uid, |
---|
| 2046 | uint32_t client_gid ) |
---|
| 2047 | { |
---|
| 2048 | // get found inode cluster and local pointer |
---|
| 2049 | cxy_t inode_cxy = GET_CXY( inode_xp ); |
---|
[473] | 2050 | vfs_inode_t * inode_ptr = GET_PTR( inode_xp ); |
---|
[1] | 2051 | |
---|
| 2052 | // get inode access mode, UID, and GID |
---|
[568] | 2053 | // TODO uint32_t mode = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->mode ) ); |
---|
| 2054 | uid_t uid = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->uid ) ); |
---|
| 2055 | gid_t gid = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->gid ) ); |
---|
[1] | 2056 | |
---|
| 2057 | // FIXME : me must use mode |
---|
| 2058 | if( (uid == client_uid) || (gid == client_gid) ) return false; |
---|
| 2059 | else return true; |
---|
| 2060 | } |
---|
[602] | 2061 | */ |
---|
[1] | 2062 | |
---|
| 2063 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2064 | // This static function is used by the vfs_lookup() function. |
---|
[204] | 2065 | // It takes an extended pointer on a remote parent directory inode, a directory |
---|
[1] | 2066 | // entry name, and returns an extended pointer on the child inode. |
---|
| 2067 | // It can be used by any thread running in any cluster. |
---|
| 2068 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2069 | // @ parent_xp : extended pointer on parent inode in remote cluster. |
---|
| 2070 | // @ name : dentry name |
---|
| 2071 | // @ child_xp : [out] buffer for extended pointer on child inode. |
---|
| 2072 | // @ return true if success / return false if not found. |
---|
| 2073 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2074 | static bool_t vfs_get_child( xptr_t parent_xp, |
---|
| 2075 | char * name, |
---|
| 2076 | xptr_t * child_xp ) |
---|
| 2077 | { |
---|
[610] | 2078 | xptr_t xhtab_xp; // extended pointer on hash table for children dentries |
---|
| 2079 | xptr_t dentry_xp; // extended pointer on children dentry |
---|
| 2080 | cxy_t dentry_cxy; |
---|
| 2081 | vfs_dentry_t * dentry_ptr; |
---|
[1] | 2082 | |
---|
| 2083 | // get parent inode cluster and local pointer |
---|
| 2084 | cxy_t parent_cxy = GET_CXY( parent_xp ); |
---|
[473] | 2085 | vfs_inode_t * parent_ptr = GET_PTR( parent_xp ); |
---|
[1] | 2086 | |
---|
| 2087 | // get extended pointer on hash table of children directory entries |
---|
| 2088 | xhtab_xp = XPTR( parent_cxy , &parent_ptr->children ); |
---|
| 2089 | |
---|
[610] | 2090 | // get pointers on matching dentry |
---|
| 2091 | dentry_xp = xhtab_lookup( xhtab_xp , name ); |
---|
| 2092 | dentry_cxy = GET_CXY( dentry_xp ); |
---|
| 2093 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
[1] | 2094 | |
---|
[610] | 2095 | if( dentry_xp == XPTR_NULL ) |
---|
| 2096 | { |
---|
| 2097 | return false; |
---|
| 2098 | } |
---|
| 2099 | else |
---|
| 2100 | { |
---|
| 2101 | *child_xp = (xptr_t)hal_remote_l64( XPTR( dentry_cxy , &dentry_ptr->child_xp ) ); |
---|
| 2102 | return true; |
---|
| 2103 | } |
---|
[1] | 2104 | |
---|
[204] | 2105 | } // end vfs_get_child() |
---|
| 2106 | |
---|
[1] | 2107 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2108 | // This static function is used by the vfs_lookup() function. |
---|
| 2109 | // It takes the <current> pointer on a buffer containing a complete pathname, and return |
---|
| 2110 | // in the <name> buffer, allocated by the caller, a single name in the path. |
---|
| 2111 | // It return also in the <next> pointer the next character to analyse in the path. |
---|
| 2112 | // Finally it returns a <last> boolean, that is true when the returned <name> is the |
---|
| 2113 | // last name in the path. The names are supposed to be separated by one or several '/' |
---|
| 2114 | // characters, that are not written in the <name> buffer. |
---|
[610] | 2115 | // |
---|
| 2116 | // WARNING: the leading characters '/' in the path are skiped before analysis. |
---|
| 2117 | // The path "/" identifies the VFS root, and is therefore anaysed as an empty |
---|
| 2118 | // string. This empty string is dignaled by the (-1) return value. |
---|
[1] | 2119 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2120 | // @ current : pointer on first character to analyse in buffer containing the path. |
---|
| 2121 | // @ name : [out] pointer on buffer allocated by the caller for the returned name. |
---|
| 2122 | // @ next : [out] pointer on next character to analyse in buffer containing the path. |
---|
| 2123 | // @ last : [out] true if the returned name is the last (NUL character found). |
---|
[610] | 2124 | // @ return 0 if success / return -1 if string empty (first chracter is NUL). |
---|
[1] | 2125 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2126 | static error_t vfs_get_name_from_path( char * current, |
---|
| 2127 | char * name, |
---|
| 2128 | char ** next, |
---|
| 2129 | bool_t * last ) |
---|
| 2130 | { |
---|
| 2131 | char * ptr = current; |
---|
| 2132 | |
---|
| 2133 | // skip leading '/' characters |
---|
| 2134 | while( *ptr == '/' ) ptr++; |
---|
| 2135 | |
---|
[610] | 2136 | // signal empty string |
---|
| 2137 | if( *ptr == 0 ) |
---|
| 2138 | { |
---|
| 2139 | *last = true; |
---|
| 2140 | return -1; |
---|
| 2141 | } |
---|
[1] | 2142 | |
---|
| 2143 | // copy all characters in name until NUL or '/' |
---|
| 2144 | while( (*ptr != 0) && (*ptr !='/') ) *(name++) = *(ptr++); |
---|
| 2145 | |
---|
[204] | 2146 | // set NUL terminating character in name buffer |
---|
| 2147 | *(name++) = 0; |
---|
| 2148 | |
---|
[1] | 2149 | // return last an next |
---|
| 2150 | if( *ptr == 0 ) // last found character is NUL => last name in path |
---|
| 2151 | { |
---|
| 2152 | *last = true; |
---|
| 2153 | } |
---|
| 2154 | else // last found character is '/' => skip it |
---|
| 2155 | { |
---|
| 2156 | *last = false; |
---|
| 2157 | *next = ptr + 1; |
---|
| 2158 | } |
---|
| 2159 | |
---|
| 2160 | return 0; |
---|
[204] | 2161 | |
---|
| 2162 | } // end vfs_get name_from_path() |
---|
[188] | 2163 | |
---|
[610] | 2164 | /////////////////////////////////////////////// |
---|
| 2165 | error_t vfs_lookup( xptr_t root_xp, |
---|
[23] | 2166 | char * pathname, |
---|
[610] | 2167 | uint32_t lookup_mode, |
---|
| 2168 | xptr_t * inode_xp, |
---|
| 2169 | char * last_name ) |
---|
[1] | 2170 | { |
---|
[101] | 2171 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; // one name in path |
---|
[1] | 2172 | |
---|
[23] | 2173 | xptr_t parent_xp; // extended pointer on parent inode |
---|
| 2174 | cxy_t parent_cxy; // cluster for parent inode |
---|
| 2175 | vfs_inode_t * parent_ptr; // local pointer on parent inode |
---|
[602] | 2176 | xptr_t dentry_xp; // extended pointer on dentry |
---|
[23] | 2177 | xptr_t child_xp; // extended pointer on child inode |
---|
| 2178 | cxy_t child_cxy; // cluster for child inode |
---|
[602] | 2179 | vfs_inode_t * child_ptr; // local pointer on child inode |
---|
| 2180 | vfs_inode_type_t child_type; // child inode type |
---|
[23] | 2181 | vfs_fs_type_t fs_type; // File system type |
---|
| 2182 | vfs_ctx_t * ctx_ptr; // local pointer on FS context |
---|
| 2183 | char * current; // current pointer on path |
---|
| 2184 | char * next; // next value for current pointer |
---|
| 2185 | bool_t last; // true when the name is the last in path |
---|
| 2186 | bool_t found; // true when a child has been found |
---|
[459] | 2187 | bool_t dir; // searched inode is a directory |
---|
| 2188 | bool_t create; // searched inode must be created if not found |
---|
| 2189 | bool_t excl; // searched inode must not exist |
---|
[610] | 2190 | bool_t par; // searched inode is the parent |
---|
[23] | 2191 | thread_t * this; // pointer on calling thread descriptor |
---|
| 2192 | process_t * process; // pointer on calling process descriptor |
---|
| 2193 | error_t error; |
---|
[1] | 2194 | |
---|
| 2195 | this = CURRENT_THREAD; |
---|
| 2196 | process = this->process; |
---|
| 2197 | |
---|
[610] | 2198 | // check pathname / root_xp consistency |
---|
| 2199 | assert( ((pathname[0] != '/') || (root_xp == process->vfs_root_xp)), |
---|
| 2200 | "root inode must be VFS root for path <%s>\n", pathname ); |
---|
| 2201 | |
---|
[438] | 2202 | #if DEBUG_VFS_LOOKUP |
---|
[433] | 2203 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[610] | 2204 | char root_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 2205 | vfs_inode_get_name( root_xp , root_name ); |
---|
[438] | 2206 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[610] | 2207 | printk("\n[%s] thread[%x,%x] enter / root <%s> / path <%s> / mode %x / cycle %d\n", |
---|
| 2208 | __FUNCTION__, process->pid, this->trdid, root_name, pathname, lookup_mode, cycle ); |
---|
[433] | 2209 | #endif |
---|
[380] | 2210 | |
---|
[459] | 2211 | // compute lookup flags |
---|
[610] | 2212 | dir = (lookup_mode & VFS_LOOKUP_DIR) == VFS_LOOKUP_DIR; |
---|
| 2213 | create = (lookup_mode & VFS_LOOKUP_CREATE) == VFS_LOOKUP_CREATE; |
---|
| 2214 | excl = (lookup_mode & VFS_LOOKUP_EXCL) == VFS_LOOKUP_EXCL; |
---|
| 2215 | par = (lookup_mode & VFS_LOOKUP_PARENT) == VFS_LOOKUP_PARENT; |
---|
[1] | 2216 | |
---|
[610] | 2217 | // initialise loop variables |
---|
| 2218 | parent_xp = root_xp; |
---|
| 2219 | current = pathname; |
---|
| 2220 | next = NULL; |
---|
| 2221 | last = false; |
---|
| 2222 | child_xp = XPTR_NULL; |
---|
[1] | 2223 | |
---|
[610] | 2224 | // loop on nodes in pathname |
---|
| 2225 | // load from device if one node in path not found in Inode Tree |
---|
[401] | 2226 | // exit loop when last name found (i.e. last == true) |
---|
[610] | 2227 | while( 1 ) |
---|
[1] | 2228 | { |
---|
[610] | 2229 | // get parent inode cluster and local pointer |
---|
| 2230 | parent_cxy = GET_CXY( parent_xp ); |
---|
| 2231 | parent_ptr = GET_PTR( parent_xp ); |
---|
[1] | 2232 | |
---|
[610] | 2233 | // get one "name" from path, and "last" flag |
---|
| 2234 | error = vfs_get_name_from_path( current , name , &next , &last ); |
---|
| 2235 | |
---|
| 2236 | // VFS root case |
---|
| 2237 | if ( error ) |
---|
| 2238 | { |
---|
| 2239 | |
---|
| 2240 | #if DEBUG_VFS_LOOKUP |
---|
| 2241 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 2242 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
| 2243 | printk("\n[%s] thread[%x,%x] exit / parent inode(%x,%x) / <%s> / cycle %d\n", |
---|
| 2244 | __FUNCTION__ , process->pid, this->trdid, parent_cxy, parent_ptr, pathname, cycle ); |
---|
| 2245 | #endif |
---|
| 2246 | *inode_xp = process->vfs_root_xp; |
---|
| 2247 | break; |
---|
| 2248 | } |
---|
| 2249 | |
---|
[438] | 2250 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2251 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[602] | 2252 | printk("\n[%s] thread[%x,%x] look for <%s> in <%s> / last = %d\n", |
---|
| 2253 | __FUNCTION__, process->pid, this->trdid, name, pathname, last ); |
---|
[433] | 2254 | #endif |
---|
[101] | 2255 | |
---|
[610] | 2256 | // search the child dentry matching name in parent inode |
---|
[1] | 2257 | found = vfs_get_child( parent_xp, |
---|
| 2258 | name, |
---|
| 2259 | &child_xp ); |
---|
| 2260 | |
---|
[610] | 2261 | // analyse found & last, depending on lookup_mode |
---|
| 2262 | if( found == false ) // not found in Inode Tree |
---|
[1] | 2263 | { |
---|
[610] | 2264 | // when a inode is not found in the Inode Tree: |
---|
| 2265 | // - if (last and par) the Inode Tree is not modified |
---|
| 2266 | // - else we speculatively introduce a new (dentry/inode) in inode tree, |
---|
| 2267 | // and scan the parent directory mapper to initialise it. |
---|
| 2268 | // . if it is not found in the parent mapper: |
---|
| 2269 | // - if(last and create), a brand new file or directory is created |
---|
| 2270 | // - else, an error is reported |
---|
| 2271 | // . if it is found in parent mapper: |
---|
| 2272 | // - if( last and excl ), an error is reported |
---|
| 2273 | // - else the new child (inode & dentry) is initialised in Inode Tree |
---|
| 2274 | // - if the child is a directory, the child mapper is loaded from device |
---|
[101] | 2275 | |
---|
[610] | 2276 | if( last && par ) // does nothing |
---|
| 2277 | { |
---|
| 2278 | |
---|
[438] | 2279 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2280 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[610] | 2281 | printk("\n[%s] thread[%x,%x] child not found but only parent requested in <%s>\n", |
---|
| 2282 | __FUNCTION__, process->pid, this->trdid, pathname ); |
---|
| 2283 | #endif |
---|
| 2284 | } |
---|
| 2285 | else // try to get it from parent mapper |
---|
| 2286 | { |
---|
| 2287 | |
---|
| 2288 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2289 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
| 2290 | printk("\n[%s] thread[%x,%x] miss <%s> inode in Inode Tree => build from parent mapper\n", |
---|
[602] | 2291 | __FUNCTION__, process->pid, this->trdid, name ); |
---|
[433] | 2292 | #endif |
---|
[610] | 2293 | // get parent inode FS type |
---|
| 2294 | ctx_ptr = hal_remote_lpt( XPTR( parent_cxy,&parent_ptr->ctx ) ); |
---|
| 2295 | fs_type = hal_remote_l32( XPTR( parent_cxy , &ctx_ptr->type ) ); |
---|
[407] | 2296 | |
---|
[610] | 2297 | // select a cluster for new inode |
---|
| 2298 | child_cxy = cluster_random_select(); |
---|
[602] | 2299 | |
---|
[610] | 2300 | // define child inode type |
---|
| 2301 | if( dir ) child_type = INODE_TYPE_DIR; |
---|
| 2302 | else child_type = INODE_TYPE_FILE; |
---|
[401] | 2303 | |
---|
[610] | 2304 | // insert (speculatively) a new child dentry/inode in inode tree |
---|
| 2305 | error = vfs_add_child_in_parent( child_cxy, |
---|
| 2306 | child_type, |
---|
| 2307 | fs_type, |
---|
| 2308 | parent_xp, |
---|
| 2309 | name, |
---|
| 2310 | &dentry_xp, |
---|
| 2311 | &child_xp ); |
---|
| 2312 | if( error ) |
---|
| 2313 | { |
---|
| 2314 | printk("\n[ERROR] in %s : cannot create inode <%s> in path <%s>\n", |
---|
| 2315 | __FUNCTION__ , name, pathname ); |
---|
| 2316 | return -1; |
---|
| 2317 | } |
---|
[238] | 2318 | |
---|
[610] | 2319 | // get child inode local pointer |
---|
| 2320 | child_ptr = GET_PTR( child_xp ); |
---|
[459] | 2321 | |
---|
| 2322 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2323 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[602] | 2324 | printk("\n[%s] thread[%x,%x] created missing inode <%s> in cluster %x\n", |
---|
| 2325 | __FUNCTION__, process->pid, this->trdid, name, child_cxy ); |
---|
[459] | 2326 | #endif |
---|
[610] | 2327 | // scan parent mapper to find the missing dentry, and complete |
---|
| 2328 | // the initialisation of dentry and child inode desciptors |
---|
| 2329 | if( parent_cxy == local_cxy ) |
---|
[602] | 2330 | |
---|
[610] | 2331 | { |
---|
| 2332 | error = vfs_fs_child_init( parent_ptr, |
---|
| 2333 | name, |
---|
| 2334 | child_xp ); |
---|
| 2335 | } |
---|
| 2336 | else |
---|
| 2337 | { |
---|
| 2338 | rpc_vfs_fs_child_init_client( parent_cxy, |
---|
| 2339 | parent_ptr, |
---|
| 2340 | name, |
---|
| 2341 | child_xp, |
---|
| 2342 | &error ); |
---|
| 2343 | } |
---|
[238] | 2344 | |
---|
[610] | 2345 | if ( error ) // child not found in parent mapper |
---|
[459] | 2346 | { |
---|
[610] | 2347 | if ( last && create ) // add a brand new dentry in parent |
---|
[602] | 2348 | { |
---|
[610] | 2349 | error = vfs_new_child_init( parent_xp, |
---|
| 2350 | dentry_xp, |
---|
| 2351 | child_xp ); |
---|
| 2352 | if ( error ) |
---|
| 2353 | { |
---|
| 2354 | printk("\n[ERROR] in %s : cannot init inode <%s> in path <%s>\n", |
---|
| 2355 | __FUNCTION__, name, pathname ); |
---|
| 2356 | vfs_remove_child_from_parent( dentry_xp ); |
---|
| 2357 | return -1; |
---|
| 2358 | } |
---|
[1] | 2359 | |
---|
[459] | 2360 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2361 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[610] | 2362 | printk("\n[%s] thread[%x,%x] child <%s> not found in parent mapper => create it\n", |
---|
[602] | 2363 | __FUNCTION__, process->pid, this->trdid, name ); |
---|
[459] | 2364 | #endif |
---|
[610] | 2365 | } |
---|
| 2366 | else // not last or not create => error |
---|
| 2367 | { |
---|
| 2368 | printk("\n[ERROR] in %s : <%s> node not found in parent for <%s>\n", |
---|
| 2369 | __FUNCTION__ , name , pathname ); |
---|
| 2370 | vfs_remove_child_from_parent( dentry_xp ); |
---|
| 2371 | return -1; |
---|
| 2372 | } |
---|
[238] | 2373 | } |
---|
[610] | 2374 | else // child has been found in parent mapper |
---|
[459] | 2375 | { |
---|
[610] | 2376 | // check the excl |
---|
| 2377 | if( last && create && excl ) |
---|
[459] | 2378 | { |
---|
[610] | 2379 | printk("\n[ERROR] in %s : node already exist <%s>\n", |
---|
| 2380 | __FUNCTION__, name ); |
---|
| 2381 | return -1; |
---|
[459] | 2382 | } |
---|
[610] | 2383 | |
---|
| 2384 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2385 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
| 2386 | printk("\n[%s] thread[%x,%x] initialised inode <%s> from parent mapper\n", |
---|
| 2387 | __FUNCTION__, process->pid, this->trdid, name ); |
---|
| 2388 | #endif |
---|
| 2389 | // load child mapper from device if child is a directory (prefetch) |
---|
| 2390 | uint32_t type = hal_remote_l32( XPTR( child_cxy , &child_ptr->type ) ); |
---|
| 2391 | if( type == INODE_TYPE_DIR ) |
---|
[459] | 2392 | { |
---|
[610] | 2393 | if( child_cxy == local_cxy ) |
---|
| 2394 | { |
---|
| 2395 | error = vfs_inode_load_all_pages( child_ptr ); |
---|
| 2396 | } |
---|
| 2397 | else |
---|
| 2398 | { |
---|
| 2399 | rpc_vfs_inode_load_all_pages_client( child_cxy, |
---|
| 2400 | child_ptr, |
---|
| 2401 | &error ); |
---|
| 2402 | } |
---|
| 2403 | if ( error ) |
---|
| 2404 | { |
---|
| 2405 | printk("\n[ERROR] in %s : cannot load <%s> from device\n", |
---|
| 2406 | __FUNCTION__ , name ); |
---|
| 2407 | vfs_remove_child_from_parent( dentry_xp ); |
---|
| 2408 | return -1; |
---|
| 2409 | } |
---|
[238] | 2410 | |
---|
[438] | 2411 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2412 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[610] | 2413 | printk("\n[%s] thread[%x,%x] loaded directory mapper for <%s> from IOC\n", |
---|
| 2414 | __FUNCTION__ , process->pid, this->trdid, name ); |
---|
[433] | 2415 | #endif |
---|
[610] | 2416 | } |
---|
[459] | 2417 | } |
---|
| 2418 | } |
---|
[1] | 2419 | } |
---|
[610] | 2420 | else // child directly found in inode tree |
---|
[459] | 2421 | { |
---|
| 2422 | |
---|
[438] | 2423 | #if (DEBUG_VFS_LOOKUP & 1) |
---|
| 2424 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[610] | 2425 | printk("\n[%s] thread[%x,%x] found <%s> in Inode Tree / inode (%x,%x)\n", |
---|
| 2426 | __FUNCTION__, process->pid, this->trdid, name, GET_CXY(child_xp), GET_PTR(child_xp) ); |
---|
[433] | 2427 | #endif |
---|
[610] | 2428 | // get child inode local pointer and cluster |
---|
[459] | 2429 | child_ptr = GET_PTR( child_xp ); |
---|
| 2430 | child_cxy = GET_CXY( child_xp ); |
---|
[101] | 2431 | |
---|
[610] | 2432 | // check the excl flag |
---|
| 2433 | if( last && create && excl ) |
---|
[459] | 2434 | { |
---|
[610] | 2435 | printk("\n[ERROR] in %s : node <%s> already exist\n", |
---|
| 2436 | __FUNCTION__, name ); |
---|
| 2437 | return -1; |
---|
[459] | 2438 | } |
---|
| 2439 | } |
---|
| 2440 | |
---|
[380] | 2441 | // TODO check access rights here [AG] |
---|
[23] | 2442 | // error = vfs_access_denied( child_xp, |
---|
| 2443 | // client_uid, |
---|
| 2444 | // client_gid ); |
---|
| 2445 | // if( error ) |
---|
| 2446 | // { |
---|
[441] | 2447 | // printk("\n[ERROR] in %s : thread %x / permission denied for %s\n", |
---|
| 2448 | // __FUNCTION__ , this , name ); |
---|
[23] | 2449 | // return EACCES; |
---|
| 2450 | // } |
---|
[1] | 2451 | |
---|
[238] | 2452 | // take lock on child inode and release lock on parent |
---|
[610] | 2453 | // vfs_inode_lock( child_xp ); |
---|
| 2454 | // vfs_inode_unlock( parent_xp ); |
---|
[1] | 2455 | |
---|
[610] | 2456 | // exit when last |
---|
| 2457 | if ( last ) // last inode in path => return relevant info |
---|
| 2458 | { |
---|
| 2459 | if ( par ) // return parent inode and child name |
---|
| 2460 | { |
---|
[1] | 2461 | |
---|
[610] | 2462 | #if DEBUG_VFS_LOOKUP |
---|
| 2463 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 2464 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
| 2465 | printk("\n[%s] thread[%x,%x] exit / parent inode(%x,%x) / <%s> / cycle %d\n", |
---|
| 2466 | __FUNCTION__ , process->pid, this->trdid, parent_cxy, parent_ptr, pathname, cycle ); |
---|
| 2467 | #endif |
---|
| 2468 | *inode_xp = parent_xp; |
---|
| 2469 | strcpy( last_name , name ); |
---|
| 2470 | break; |
---|
| 2471 | } |
---|
| 2472 | else // return child inode name |
---|
| 2473 | { |
---|
[1] | 2474 | |
---|
[438] | 2475 | #if DEBUG_VFS_LOOKUP |
---|
[433] | 2476 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 2477 | if( DEBUG_VFS_LOOKUP < cycle ) |
---|
[610] | 2478 | printk("\n[%s] thread[%x,%x] exit / child inode (%x,%x) / <%s> / cycle %d\n", |
---|
| 2479 | __FUNCTION__ , process->pid, this->trdid, child_cxy, child_ptr, pathname, cycle ); |
---|
[433] | 2480 | #endif |
---|
[610] | 2481 | *inode_xp = child_xp; |
---|
| 2482 | break; |
---|
| 2483 | } |
---|
| 2484 | } |
---|
| 2485 | else // not the last inode in path => update loop variables |
---|
| 2486 | { |
---|
| 2487 | parent_xp = child_xp; |
---|
| 2488 | current = next; |
---|
| 2489 | } |
---|
| 2490 | } |
---|
[1] | 2491 | |
---|
| 2492 | return 0; |
---|
| 2493 | |
---|
| 2494 | } // end vfs_lookup() |
---|
| 2495 | |
---|
[602] | 2496 | /////////////////////////////////////////////// |
---|
| 2497 | error_t vfs_new_child_init( xptr_t parent_xp, |
---|
| 2498 | xptr_t dentry_xp, |
---|
| 2499 | xptr_t child_xp ) |
---|
| 2500 | { |
---|
| 2501 | error_t error; |
---|
| 2502 | uint32_t cluster; |
---|
| 2503 | uint32_t child_type; |
---|
| 2504 | uint32_t child_size; |
---|
| 2505 | |
---|
| 2506 | #if DEBUG_VFS_NEW_CHILD_INIT |
---|
| 2507 | char parent_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 2508 | char child_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 2509 | vfs_inode_get_name( parent_xp , parent_name ); |
---|
| 2510 | vfs_inode_get_name( child_xp , child_name ); |
---|
| 2511 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 2512 | thread_t * this = CURRENT_THREAD; |
---|
| 2513 | if( DEBUG_VFS_NEW_CHILD_INIT < cycle ) |
---|
| 2514 | printk("\n[%s] thread[%x,%x] enter / parent <%s> / child <%s> / cycle %d\n", |
---|
| 2515 | __FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle ); |
---|
| 2516 | #endif |
---|
| 2517 | |
---|
| 2518 | // get parent inode cluster and local pointer |
---|
| 2519 | cxy_t parent_cxy = GET_CXY( parent_xp ); |
---|
| 2520 | vfs_inode_t * parent_ptr = GET_PTR( parent_xp ); |
---|
| 2521 | |
---|
| 2522 | // get dentry local pointer |
---|
| 2523 | vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp ); |
---|
| 2524 | |
---|
| 2525 | // get child inode cluster and local pointer |
---|
| 2526 | cxy_t child_cxy = GET_CXY( child_xp ); |
---|
| 2527 | vfs_inode_t * child_ptr = GET_PTR( child_xp ); |
---|
| 2528 | |
---|
| 2529 | // 1. allocate one free cluster to child inode |
---|
| 2530 | // depending on the child inode FS type |
---|
| 2531 | vfs_ctx_t * ctx = hal_remote_lpt( XPTR( child_cxy , &child_ptr->ctx ) ); |
---|
| 2532 | |
---|
| 2533 | error = vfs_fs_cluster_alloc( ctx->type, |
---|
| 2534 | &cluster ); |
---|
| 2535 | if ( error ) |
---|
| 2536 | { |
---|
| 2537 | printk("\n[ERROR] in %s : cannot find a free VFS cluster\n", |
---|
| 2538 | __FUNCTION__ ); |
---|
| 2539 | return -1; |
---|
| 2540 | } |
---|
| 2541 | |
---|
| 2542 | #if( DEBUG_VFS_NEW_CHILD_INIT & 1) |
---|
| 2543 | if( DEBUG_VFS_NEW_CHILD_INIT < cycle ) |
---|
| 2544 | printk("\n[%s] thread[%x,%x] allocated one FAT cluster to <%s>\n", |
---|
| 2545 | __FUNCTION__ , this->process->pid, this->trdid, child_name ); |
---|
| 2546 | #endif |
---|
| 2547 | |
---|
| 2548 | // 2. update the child inode descriptor |
---|
| 2549 | child_type = hal_remote_l32( XPTR( child_cxy , &child_ptr->type ) ); |
---|
| 2550 | child_size = (child_type == INODE_TYPE_DIR) ? 4096 : 0; |
---|
| 2551 | |
---|
| 2552 | hal_remote_s32( XPTR( child_cxy , &child_ptr->size ) , child_size ); |
---|
| 2553 | hal_remote_spt( XPTR( child_cxy , &child_ptr->extend ) , (void*)(intptr_t)cluster ); |
---|
| 2554 | |
---|
| 2555 | // 3. update the parent inode mapper, and |
---|
| 2556 | // update the dentry extension if required |
---|
| 2557 | if( local_cxy == parent_cxy ) |
---|
| 2558 | { |
---|
| 2559 | error = vfs_fs_add_dentry( parent_ptr, |
---|
| 2560 | dentry_ptr ); |
---|
| 2561 | } |
---|
| 2562 | else |
---|
| 2563 | { |
---|
| 2564 | rpc_vfs_fs_add_dentry_client( parent_cxy, |
---|
| 2565 | parent_ptr, |
---|
| 2566 | dentry_ptr, |
---|
| 2567 | &error ); |
---|
| 2568 | } |
---|
| 2569 | if ( error ) |
---|
| 2570 | { |
---|
| 2571 | printk("\n[ERROR] in %s : cannot register child in parent directory\n", |
---|
| 2572 | __FUNCTION__ ); |
---|
| 2573 | return -1; |
---|
| 2574 | } |
---|
| 2575 | |
---|
| 2576 | #if DEBUG_VFS_NEW_CHILD_INIT |
---|
| 2577 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 2578 | if( DEBUG_VFS_NEW_CHILD_INIT < cycle ) |
---|
[610] | 2579 | printk("\n[%s] thread[%x,%x] exit / parent <%s> / child <%s> / cycle %d\n", |
---|
[602] | 2580 | __FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle ); |
---|
| 2581 | #endif |
---|
| 2582 | |
---|
| 2583 | return 0; |
---|
| 2584 | |
---|
| 2585 | } // end vfs_new_child_init() |
---|
| 2586 | |
---|
[610] | 2587 | ////////////////////////////////////////// |
---|
| 2588 | error_t vfs_get_path( xptr_t inode_xp, |
---|
| 2589 | char * buffer, |
---|
| 2590 | char ** first, |
---|
| 2591 | uint32_t max_size ) |
---|
[1] | 2592 | { |
---|
[610] | 2593 | xptr_t dentry_xp; // extended pointer on current dentry |
---|
| 2594 | vfs_dentry_t * dentry_ptr; // local pointer on current dentry |
---|
| 2595 | cxy_t dentry_cxy; // current dentry cluster identifier |
---|
| 2596 | xptr_t name_xp; // extended pointer on current dentry name |
---|
| 2597 | uint32_t length; // length of current dentry name |
---|
| 2598 | int32_t index; // slot index in buffer |
---|
| 2599 | xptr_t current_xp; // extended pointer on current inode |
---|
| 2600 | vfs_inode_t * current_ptr; // local pointer on current inode |
---|
| 2601 | cxy_t current_cxy; // current inode cluster identifier |
---|
| 2602 | xptr_t vfs_root_xp; // extended pointer on VFS root inode |
---|
| 2603 | vfs_inode_t * vfs_root_ptr; // local pointer on VFS root inode |
---|
| 2604 | cxy_t vfs_root_cxy; // VFS root inode cluster identifier |
---|
| 2605 | xptr_t lock_xp; // extended pointer on Inode Tree lock |
---|
| 2606 | xptr_t parents_root_xp; // extended pointer on current inode parents root |
---|
| 2607 | bool_t found; // condition to exit the while loop |
---|
[1] | 2608 | |
---|
[610] | 2609 | thread_t * this = CURRENT_THREAD; |
---|
| 2610 | process_t * process = this->process; |
---|
[1] | 2611 | |
---|
[610] | 2612 | #if DEBUG_VFS_GET_PATH |
---|
| 2613 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 2614 | if( DEBUG_VFS_GET_PATH < cycle ) |
---|
| 2615 | printk("\n[%s] thread[%x,%x] enter : inode (%x,%x) / cycle %d\n", |
---|
| 2616 | __FUNCTION__ , process->pid, this->trdid, |
---|
| 2617 | GET_CXY( inode_xp ), GET_PTR( inode_xp ), cycle ); |
---|
| 2618 | #endif |
---|
| 2619 | |
---|
| 2620 | // set the NUL character in buffer / initialise buffer index |
---|
[1] | 2621 | buffer[max_size - 1] = 0; |
---|
[610] | 2622 | index = (int32_t)(max_size - 1); |
---|
[1] | 2623 | |
---|
| 2624 | // initialize current inode |
---|
[610] | 2625 | current_xp = inode_xp; |
---|
[1] | 2626 | |
---|
[610] | 2627 | // build extended pointer on lock protecting Inode Tree |
---|
| 2628 | vfs_root_xp = process->vfs_root_xp; |
---|
| 2629 | vfs_root_ptr = GET_PTR( vfs_root_xp ); |
---|
| 2630 | vfs_root_cxy = GET_CXY( vfs_root_xp ); |
---|
| 2631 | lock_xp = XPTR( vfs_root_cxy , &vfs_root_ptr->main_lock ); |
---|
| 2632 | |
---|
| 2633 | // take lock protecting Inode Tree in read mode |
---|
| 2634 | remote_rwlock_rd_acquire( lock_xp ); |
---|
| 2635 | |
---|
| 2636 | // traverse Inode Tree from target inode to VFS root |
---|
| 2637 | // selecting always the first parent dentry |
---|
| 2638 | // the buffer is written in "reverse order" (from target inode to root) |
---|
| 2639 | // exit the while loop when the VFS root has been found |
---|
[1] | 2640 | do |
---|
| 2641 | { |
---|
[610] | 2642 | // get current inode cluster and local pointer |
---|
| 2643 | current_cxy = GET_CXY( current_xp ); |
---|
| 2644 | current_ptr = GET_PTR( current_xp ); |
---|
[1] | 2645 | |
---|
[610] | 2646 | // build extended pointer on parents dentries root |
---|
| 2647 | parents_root_xp = XPTR( current_cxy , ¤t_ptr->parents ); |
---|
[1] | 2648 | |
---|
[610] | 2649 | // compute exit condition <=> current inode is VFS root |
---|
| 2650 | found = xlist_is_empty( parents_root_xp ); |
---|
[1] | 2651 | |
---|
[610] | 2652 | if( found ) // parent is the VFS root |
---|
| 2653 | { |
---|
| 2654 | if( index == (int32_t)(max_size - 1) ) |
---|
| 2655 | { |
---|
| 2656 | // update index |
---|
| 2657 | index--; |
---|
| 2658 | |
---|
| 2659 | // set separator |
---|
| 2660 | buffer[index] = '/'; |
---|
[1] | 2661 | |
---|
[610] | 2662 | // check buffer overflow |
---|
| 2663 | assert( (index >= 0) , "kernel buffer too small\n" ); |
---|
[1] | 2664 | |
---|
[610] | 2665 | } |
---|
| 2666 | } |
---|
| 2667 | else // not the VFS root |
---|
[1] | 2668 | { |
---|
[610] | 2669 | // get first parent dentry cluster and pointers |
---|
| 2670 | dentry_xp = XLIST_FIRST( parents_root_xp , vfs_dentry_t , parents ); |
---|
| 2671 | dentry_cxy = GET_CXY( dentry_xp ); |
---|
| 2672 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
[1] | 2673 | |
---|
[610] | 2674 | // get extended pointer on dentry name and name length |
---|
| 2675 | name_xp = XPTR( dentry_cxy , dentry_ptr->name ); |
---|
| 2676 | length = hal_remote_l32( XPTR( dentry_cxy , &dentry_ptr->length ) ); |
---|
[1] | 2677 | |
---|
[610] | 2678 | #if (DEBUG_VFS_GET_PATH & 1) |
---|
| 2679 | char debug_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 2680 | hal_remote_strcpy( XPTR( local_cxy , debug_name ) , name_xp ); |
---|
| 2681 | if( DEBUG_VFS_GET_PATH < cycle ) |
---|
| 2682 | printk("\n[%s] thread(%x,%s) get current dentry <%s> in cluster %x\n", |
---|
| 2683 | __FUNCTION__ , process->pid, this->trdid, debug_name, current_cxy ); |
---|
| 2684 | #endif |
---|
| 2685 | // update index |
---|
| 2686 | index -= (length + 1); |
---|
| 2687 | |
---|
| 2688 | // check buffer overflow |
---|
| 2689 | assert( (index >= 0) , "kernel buffer too small\n" ); |
---|
| 2690 | |
---|
| 2691 | // update pathname |
---|
| 2692 | hal_remote_memcpy( XPTR( local_cxy , &buffer[index + 1] ) , |
---|
| 2693 | name_xp , length ); |
---|
| 2694 | |
---|
| 2695 | // set separator |
---|
| 2696 | buffer[index] = '/'; |
---|
| 2697 | |
---|
| 2698 | // get extended pointer on parent inode |
---|
| 2699 | current_xp = XPTR( dentry_cxy , |
---|
| 2700 | hal_remote_lpt( XPTR( dentry_cxy , &dentry_ptr->parent ) ) ); |
---|
| 2701 | } |
---|
[1] | 2702 | } |
---|
[610] | 2703 | while( found == false ); |
---|
[1] | 2704 | |
---|
[610] | 2705 | // release lock protecting Inode Tree in read mode |
---|
| 2706 | remote_rwlock_rd_release( lock_xp ); |
---|
| 2707 | |
---|
| 2708 | #if DEBUG_VFS_GET_PATH |
---|
| 2709 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 2710 | if( DEBUG_VFS_GET_PATH < cycle ) |
---|
| 2711 | printk("\n[%s] thread[%x,%x] exit : path <%s> / cycle %d\n", |
---|
| 2712 | __FUNCTION__ , process->pid, this->trdid, &buffer[index], cycle ); |
---|
| 2713 | #endif |
---|
| 2714 | |
---|
| 2715 | // return pointer on first character in buffer |
---|
| 2716 | *first = &buffer[index]; |
---|
[1] | 2717 | return 0; |
---|
| 2718 | |
---|
| 2719 | } // end vfs_get_path() |
---|
| 2720 | |
---|
[188] | 2721 | |
---|
[602] | 2722 | //////////////////////////////////////////////////////////////////// |
---|
[610] | 2723 | error_t vfs_add_child_in_parent( cxy_t child_cxy, |
---|
| 2724 | vfs_inode_type_t child_type, |
---|
[23] | 2725 | vfs_fs_type_t fs_type, |
---|
[602] | 2726 | xptr_t parent_inode_xp, |
---|
[23] | 2727 | char * name, |
---|
[610] | 2728 | xptr_t * child_dentry_xp, |
---|
[602] | 2729 | xptr_t * child_inode_xp ) |
---|
[1] | 2730 | { |
---|
[610] | 2731 | error_t error; |
---|
| 2732 | cxy_t parent_cxy; // parent inode cluster identifier |
---|
| 2733 | vfs_inode_t * parent_inode_ptr; // parent inode local pointer |
---|
| 2734 | xptr_t new_dentry_xp; // extended pointer on created dentry |
---|
| 2735 | vfs_dentry_t * new_dentry_ptr; // created dentry local pointer |
---|
| 2736 | xptr_t new_inode_xp; // extended pointer on created child inode |
---|
| 2737 | vfs_inode_t * new_inode_ptr; // local pointer on created child inode |
---|
[1] | 2738 | |
---|
[610] | 2739 | xptr_t parents_root_xp; // extended pointer on child inode "parents" field |
---|
| 2740 | xptr_t parents_entry_xp; // extended pointer on child dentry "parents" field |
---|
| 2741 | xptr_t children_xhtab_xp; // extended pointer on parent inode "children" field |
---|
| 2742 | xptr_t children_entry_xp; // extended pointer on child dentry "children" field |
---|
| 2743 | |
---|
| 2744 | // get parent inode cluster and pointer |
---|
| 2745 | parent_cxy = GET_CXY( parent_inode_xp ); |
---|
[602] | 2746 | parent_inode_ptr = GET_PTR( parent_inode_xp ); |
---|
[1] | 2747 | |
---|
[438] | 2748 | #if DEBUG_VFS_ADD_CHILD |
---|
[602] | 2749 | char parent_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 2750 | vfs_inode_get_name( parent_inode_xp , parent_name ); |
---|
[433] | 2751 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
[568] | 2752 | thread_t * this = CURRENT_THREAD; |
---|
[438] | 2753 | if( DEBUG_VFS_ADD_CHILD < cycle ) |
---|
[610] | 2754 | printk("\n[%s] thread[%x,%x] enter / child <%s> / parent <%s> / cycle %d\n", |
---|
| 2755 | __FUNCTION__, this->process->pid, this->trdid, name, |
---|
| 2756 | parent_name, (uint32_t)hal_get_cycles() ); |
---|
[433] | 2757 | #endif |
---|
[279] | 2758 | |
---|
[610] | 2759 | // 1. create dentry in parent cluster |
---|
| 2760 | if( parent_cxy == local_cxy ) // parent cluster is local |
---|
[1] | 2761 | { |
---|
[23] | 2762 | error = vfs_dentry_create( fs_type, |
---|
[1] | 2763 | name, |
---|
[602] | 2764 | &new_dentry_xp ); |
---|
[1] | 2765 | } |
---|
[610] | 2766 | else // parent cluster is remote |
---|
[1] | 2767 | { |
---|
[610] | 2768 | rpc_vfs_dentry_create_client( parent_cxy, |
---|
[23] | 2769 | fs_type, |
---|
[1] | 2770 | name, |
---|
[602] | 2771 | &new_dentry_xp, |
---|
[1] | 2772 | &error ); |
---|
| 2773 | } |
---|
| 2774 | |
---|
| 2775 | if( error ) |
---|
| 2776 | { |
---|
[437] | 2777 | printk("\n[ERROR] in %s : cannot create dentry <%s> in cluster %x\n", |
---|
[610] | 2778 | __FUNCTION__ , name , parent_cxy ); |
---|
[602] | 2779 | return -1; |
---|
[1] | 2780 | } |
---|
| 2781 | |
---|
[602] | 2782 | // get dentry local pointer |
---|
| 2783 | new_dentry_ptr = GET_PTR( new_dentry_xp ); |
---|
| 2784 | |
---|
[568] | 2785 | #if(DEBUG_VFS_ADD_CHILD & 1) |
---|
| 2786 | if( DEBUG_VFS_ADD_CHILD < cycle ) |
---|
[610] | 2787 | printk("\n[%s] thread[%x,%x] / dentry <%s> created (%x,%x)\n", |
---|
| 2788 | __FUNCTION__, this->process->pid, this->trdid, name, parent_cxy, new_dentry_ptr ); |
---|
[568] | 2789 | #endif |
---|
| 2790 | |
---|
[610] | 2791 | // 2. create child inode in child cluster |
---|
| 2792 | // TODO : define attr / mode / uid / gid |
---|
[1] | 2793 | uint32_t attr = 0; |
---|
| 2794 | uint32_t mode = 0; |
---|
| 2795 | uint32_t uid = 0; |
---|
| 2796 | uint32_t gid = 0; |
---|
| 2797 | |
---|
[610] | 2798 | if( child_cxy == local_cxy ) // child cluster is local |
---|
[1] | 2799 | { |
---|
[610] | 2800 | error = vfs_inode_create( fs_type, |
---|
| 2801 | child_type, |
---|
[1] | 2802 | attr, |
---|
| 2803 | mode, |
---|
| 2804 | uid, |
---|
| 2805 | gid, |
---|
[602] | 2806 | &new_inode_xp ); |
---|
[1] | 2807 | } |
---|
| 2808 | else // child cluster is remote |
---|
| 2809 | { |
---|
[610] | 2810 | rpc_vfs_inode_create_client( child_cxy, |
---|
[23] | 2811 | fs_type, |
---|
[610] | 2812 | child_type, |
---|
[1] | 2813 | attr, |
---|
| 2814 | mode, |
---|
| 2815 | uid, |
---|
| 2816 | gid, |
---|
[602] | 2817 | &new_inode_xp, |
---|
[1] | 2818 | &error ); |
---|
| 2819 | } |
---|
| 2820 | |
---|
| 2821 | if( error ) |
---|
| 2822 | { |
---|
| 2823 | printk("\n[ERROR] in %s : cannot create inode in cluster %x\n", |
---|
[610] | 2824 | __FUNCTION__ , child_cxy ); |
---|
[1] | 2825 | |
---|
[610] | 2826 | if( parent_cxy == local_cxy ) vfs_dentry_destroy( new_dentry_ptr ); |
---|
| 2827 | else rpc_vfs_dentry_destroy_client( parent_cxy , new_dentry_ptr ); |
---|
[602] | 2828 | return -1; |
---|
[1] | 2829 | } |
---|
| 2830 | |
---|
[610] | 2831 | // get new inode local pointer |
---|
| 2832 | new_inode_ptr = GET_PTR( new_inode_xp ); |
---|
| 2833 | |
---|
[568] | 2834 | #if(DEBUG_VFS_ADD_CHILD & 1) |
---|
| 2835 | if( DEBUG_VFS_ADD_CHILD < cycle ) |
---|
[610] | 2836 | printk("\n[%s] thread[%x,%x] / inode <%s> created (%x,%x)\n", |
---|
| 2837 | __FUNCTION__ , this->process->pid, this->trdid, name , child_cxy, new_inode_ptr ); |
---|
[568] | 2838 | #endif |
---|
| 2839 | |
---|
[610] | 2840 | // 3. register new_dentry in new_inode xlist of parents |
---|
| 2841 | parents_root_xp = XPTR( child_cxy , &new_inode_ptr->parents ); |
---|
| 2842 | parents_entry_xp = XPTR( parent_cxy, &new_dentry_ptr->parents ); |
---|
| 2843 | xlist_add_first( parents_root_xp , parents_entry_xp ); |
---|
| 2844 | hal_remote_atomic_add( XPTR( child_cxy , &new_inode_ptr->links ) , 1 ); |
---|
[204] | 2845 | |
---|
[610] | 2846 | #if(DEBUG_VFS_ADD_CHILD & 1) |
---|
| 2847 | if( local_cxy == 1 ) |
---|
| 2848 | // if( DEBUG_VFS_ADD_CHILD < cycle ) |
---|
| 2849 | printk("\n[%s] thread[%x,%x] / dentry (%x,%x) registered in child inode (%x,%x)\n", |
---|
| 2850 | __FUNCTION__, this->process->pid, this->trdid, |
---|
| 2851 | parent_cxy, new_dentry_ptr, child_cxy, new_inode_ptr ); |
---|
| 2852 | #endif |
---|
| 2853 | |
---|
| 2854 | // 4. register new_dentry in parent_inode xhtab of children |
---|
| 2855 | children_xhtab_xp = XPTR( parent_cxy , &parent_inode_ptr->children ); |
---|
| 2856 | children_entry_xp = XPTR( parent_cxy , &new_dentry_ptr->children ); |
---|
| 2857 | xhtab_insert( children_xhtab_xp , name , children_entry_xp ); |
---|
| 2858 | |
---|
| 2859 | #if(DEBUG_VFS_ADD_CHILD & 1) |
---|
| 2860 | if( DEBUG_VFS_ADD_CHILD < cycle ) |
---|
| 2861 | printk("\n[%s] thread[%x,%x] / dentry (%x,%x) registered in parent inode (%x,%x)\n", |
---|
| 2862 | __FUNCTION__, this->process->pid, this->trdid, |
---|
| 2863 | parent_cxy, new_dentry_ptr, parent_cxy, parent_inode_ptr ); |
---|
| 2864 | #endif |
---|
| 2865 | |
---|
| 2866 | // 5. update "parent" and "child_xp" fields in new_dentry |
---|
| 2867 | hal_remote_s64( XPTR( parent_cxy , &new_dentry_ptr->child_xp ) , new_inode_xp ); |
---|
| 2868 | hal_remote_spt( XPTR( parent_cxy , &new_dentry_ptr->parent ) , parent_inode_ptr ); |
---|
| 2869 | |
---|
[438] | 2870 | #if DEBUG_VFS_ADD_CHILD |
---|
[433] | 2871 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 2872 | if( DEBUG_VFS_ADD_CHILD < cycle ) |
---|
[598] | 2873 | printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n", |
---|
| 2874 | __FUNCTION__, this->process->pid, this->trdid, name, (uint32_t)hal_get_cycles() ); |
---|
[433] | 2875 | #endif |
---|
[296] | 2876 | |
---|
[602] | 2877 | // return extended pointer on dentry & child inode |
---|
[610] | 2878 | *child_dentry_xp = new_dentry_xp; |
---|
| 2879 | *child_inode_xp = new_inode_xp; |
---|
[1] | 2880 | return 0; |
---|
| 2881 | |
---|
| 2882 | } // end vfs_add_child_in_parent() |
---|
| 2883 | |
---|
[610] | 2884 | ///////////////////////////////////////////////////// |
---|
| 2885 | void vfs_remove_child_from_parent( xptr_t dentry_xp ) |
---|
[459] | 2886 | { |
---|
[610] | 2887 | cxy_t parent_cxy; // parent inode cluster identifier |
---|
| 2888 | cxy_t child_cxy; // child inode cluster identifier |
---|
| 2889 | vfs_dentry_t * dentry_ptr; // local pointer on dentry |
---|
| 2890 | xptr_t child_inode_xp; // extended pointer on child inode |
---|
| 2891 | vfs_inode_t * child_inode_ptr; // local pointer on child inode |
---|
| 2892 | vfs_inode_t * parent_inode_ptr; // local pointer on parent inode |
---|
| 2893 | uint32_t links; // number of child inode parents |
---|
| 2894 | |
---|
| 2895 | char dentry_name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
[459] | 2896 | |
---|
[610] | 2897 | // get parent cluster and dentry local pointer |
---|
| 2898 | parent_cxy = GET_CXY( dentry_xp ); |
---|
[459] | 2899 | dentry_ptr = GET_PTR( dentry_xp ); |
---|
| 2900 | |
---|
[610] | 2901 | // get a local copy of dentry name |
---|
| 2902 | hal_remote_strcpy( XPTR( local_cxy , dentry_name ), |
---|
| 2903 | XPTR( parent_cxy , &dentry_ptr->name ) ); |
---|
[459] | 2904 | |
---|
[610] | 2905 | // get parent_inode local pointer |
---|
| 2906 | parent_inode_ptr = hal_remote_lpt( XPTR( parent_cxy , &dentry_ptr->parent ) ); |
---|
| 2907 | |
---|
| 2908 | // get child cluster and child_inode pointers |
---|
| 2909 | child_inode_xp = hal_remote_l64( XPTR( parent_cxy , &dentry_ptr->child_xp ) ); |
---|
| 2910 | child_cxy = GET_CXY( child_inode_xp ); |
---|
| 2911 | child_inode_ptr = GET_PTR( child_inode_xp ); |
---|
[602] | 2912 | |
---|
[610] | 2913 | // remove dentry from parent_inode |
---|
| 2914 | xhtab_remove( XPTR( parent_cxy , &parent_inode_ptr->children ), |
---|
| 2915 | dentry_name, |
---|
| 2916 | XPTR( parent_cxy , &dentry_ptr->children ) ); |
---|
[602] | 2917 | |
---|
[610] | 2918 | // remove dentry from child_inode |
---|
| 2919 | xlist_unlink( XPTR( parent_cxy , &dentry_ptr->parents ) ); |
---|
| 2920 | links = hal_remote_atomic_add( XPTR( child_cxy , &child_inode_ptr->links ) , -1 ); |
---|
| 2921 | |
---|
| 2922 | // delete dentry descriptor |
---|
| 2923 | if( parent_cxy == local_cxy ) |
---|
[459] | 2924 | { |
---|
[602] | 2925 | vfs_dentry_destroy( dentry_ptr ); |
---|
[459] | 2926 | } |
---|
| 2927 | else |
---|
| 2928 | { |
---|
[610] | 2929 | rpc_vfs_dentry_destroy_client( parent_cxy, |
---|
[602] | 2930 | dentry_ptr ); |
---|
[459] | 2931 | } |
---|
| 2932 | |
---|
[610] | 2933 | // delete child_inode descriptor if last link |
---|
| 2934 | if( links == 1 ) |
---|
[459] | 2935 | { |
---|
[610] | 2936 | if( child_cxy == local_cxy ) |
---|
| 2937 | { |
---|
| 2938 | vfs_inode_destroy( child_inode_ptr ); |
---|
| 2939 | } |
---|
| 2940 | else |
---|
| 2941 | { |
---|
| 2942 | rpc_vfs_inode_destroy_client( child_cxy , child_inode_ptr ); |
---|
| 2943 | } |
---|
[459] | 2944 | } |
---|
| 2945 | |
---|
| 2946 | } // end vfs_remove_child_from_parent() |
---|
| 2947 | |
---|
[23] | 2948 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[602] | 2949 | // API used by VFS to access a specific FS |
---|
[23] | 2950 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2951 | |
---|
[602] | 2952 | /////////////////////////////////////////// |
---|
| 2953 | error_t vfs_fs_move_page( xptr_t page_xp, |
---|
| 2954 | bool_t to_mapper ) |
---|
[23] | 2955 | { |
---|
[204] | 2956 | error_t error = 0; |
---|
[23] | 2957 | |
---|
[602] | 2958 | assert( (page_xp != XPTR_NULL) , "page pointer is NULL\n" ); |
---|
[23] | 2959 | |
---|
[602] | 2960 | page_t * page_ptr = GET_PTR( page_xp ); |
---|
| 2961 | cxy_t page_cxy = GET_CXY( page_xp ); |
---|
[23] | 2962 | |
---|
[602] | 2963 | // get local pointer on page mapper |
---|
| 2964 | mapper_t * mapper = hal_remote_lpt( XPTR( page_cxy , &page_ptr->mapper ) ); |
---|
[23] | 2965 | |
---|
[602] | 2966 | assert( (mapper != NULL) , "no mapper for page\n" ); |
---|
[246] | 2967 | |
---|
[23] | 2968 | // get FS type |
---|
[602] | 2969 | vfs_fs_type_t fs_type = hal_remote_l32( XPTR( page_cxy , &mapper->type ) ); |
---|
[23] | 2970 | |
---|
[238] | 2971 | // call relevant FS function |
---|
[23] | 2972 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 2973 | { |
---|
[602] | 2974 | error = fatfs_move_page( page_xp , to_mapper ); |
---|
| 2975 | } |
---|
| 2976 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 2977 | { |
---|
| 2978 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 2979 | } |
---|
| 2980 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 2981 | { |
---|
| 2982 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 2983 | } |
---|
| 2984 | else |
---|
| 2985 | { |
---|
| 2986 | assert( false , "undefined file system type\n" ); |
---|
| 2987 | } |
---|
[568] | 2988 | |
---|
[602] | 2989 | return error; |
---|
[568] | 2990 | |
---|
[602] | 2991 | } // end vfs_fs_move_page() |
---|
| 2992 | |
---|
| 2993 | //////////////////////////////////////////////// |
---|
| 2994 | error_t vfs_fs_add_dentry( vfs_inode_t * inode, |
---|
| 2995 | vfs_dentry_t * dentry ) |
---|
| 2996 | { |
---|
| 2997 | error_t error = 0; |
---|
| 2998 | |
---|
| 2999 | assert( (inode != NULL) , "inode pointer is NULL\n" ); |
---|
| 3000 | assert( (dentry != NULL) , "dentry pointer is NULL\n" ); |
---|
| 3001 | |
---|
| 3002 | mapper_t * mapper = inode->mapper; |
---|
| 3003 | |
---|
| 3004 | assert( (mapper != NULL) , "mapper pointer is NULL\n" ); |
---|
| 3005 | |
---|
| 3006 | // get FS type |
---|
| 3007 | vfs_fs_type_t fs_type = mapper->type; |
---|
| 3008 | |
---|
| 3009 | // call relevant FS function |
---|
| 3010 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 3011 | { |
---|
| 3012 | error = fatfs_add_dentry( inode , dentry ); |
---|
[23] | 3013 | } |
---|
| 3014 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3015 | { |
---|
[492] | 3016 | assert( false , "should not be called for RAMFS\n" ); |
---|
[23] | 3017 | } |
---|
| 3018 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3019 | { |
---|
[492] | 3020 | assert( false , "should not be called for DEVFS\n" ); |
---|
[23] | 3021 | } |
---|
| 3022 | else |
---|
| 3023 | { |
---|
[492] | 3024 | assert( false , "undefined file system type\n" ); |
---|
[23] | 3025 | } |
---|
| 3026 | |
---|
| 3027 | return error; |
---|
| 3028 | |
---|
[602] | 3029 | } // end vfs_fs_add_dentry() |
---|
[23] | 3030 | |
---|
[602] | 3031 | /////////////////////////////////////////////////// |
---|
| 3032 | error_t vfs_fs_remove_dentry( vfs_inode_t * inode, |
---|
| 3033 | vfs_dentry_t * dentry ) |
---|
[23] | 3034 | { |
---|
[602] | 3035 | error_t error = 0; |
---|
[23] | 3036 | |
---|
[602] | 3037 | assert( (inode != NULL) , "inode pointer is NULL\n" ); |
---|
| 3038 | assert( (dentry != NULL) , "dentry pointer is NULL\n" ); |
---|
[23] | 3039 | |
---|
[238] | 3040 | mapper_t * mapper = inode->mapper; |
---|
[23] | 3041 | |
---|
[598] | 3042 | assert( (mapper != NULL) , "mapper pointer is NULL\n" ); |
---|
[23] | 3043 | |
---|
[602] | 3044 | // get FS type |
---|
| 3045 | vfs_fs_type_t fs_type = mapper->type; |
---|
[401] | 3046 | |
---|
[602] | 3047 | // call relevant FS function |
---|
| 3048 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 3049 | { |
---|
| 3050 | error = fatfs_remove_dentry( inode , dentry ); |
---|
| 3051 | } |
---|
| 3052 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3053 | { |
---|
| 3054 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 3055 | } |
---|
| 3056 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3057 | { |
---|
| 3058 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 3059 | } |
---|
| 3060 | else |
---|
| 3061 | { |
---|
| 3062 | assert( false , "undefined file system type\n" ); |
---|
| 3063 | } |
---|
[238] | 3064 | |
---|
[602] | 3065 | return error; |
---|
| 3066 | |
---|
| 3067 | } // end vfs_fs_remove_dentry() |
---|
| 3068 | |
---|
| 3069 | //////////////////////////////////////////////// |
---|
| 3070 | error_t vfs_fs_child_init( vfs_inode_t * parent, |
---|
| 3071 | char * name, |
---|
| 3072 | xptr_t child_xp ) |
---|
| 3073 | { |
---|
| 3074 | error_t error = 0; |
---|
| 3075 | |
---|
| 3076 | // check arguments |
---|
| 3077 | assert( (parent != NULL) , "parent pointer is NULL\n"); |
---|
| 3078 | assert( (child_xp != XPTR_NULL) , "child pointer is NULL\n"); |
---|
| 3079 | |
---|
| 3080 | // get parent inode FS type |
---|
| 3081 | vfs_fs_type_t fs_type = parent->ctx->type; |
---|
| 3082 | |
---|
| 3083 | // call relevant FS function |
---|
| 3084 | if( fs_type == FS_TYPE_FATFS ) |
---|
[23] | 3085 | { |
---|
[602] | 3086 | error = fatfs_child_init( parent , name , child_xp ); |
---|
| 3087 | } |
---|
| 3088 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3089 | { |
---|
| 3090 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 3091 | } |
---|
| 3092 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3093 | { |
---|
| 3094 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 3095 | } |
---|
| 3096 | else |
---|
| 3097 | { |
---|
| 3098 | assert( false , "undefined file system type\n" ); |
---|
| 3099 | } |
---|
[23] | 3100 | |
---|
[602] | 3101 | return error; |
---|
| 3102 | |
---|
| 3103 | } // end vfs_fs_child_init() |
---|
| 3104 | |
---|
[610] | 3105 | //////////////////////////////////////////////// |
---|
| 3106 | error_t vfs_fs_sync_inode( vfs_inode_t * inode ) |
---|
| 3107 | { |
---|
| 3108 | error_t error = 0; |
---|
| 3109 | |
---|
| 3110 | // check arguments |
---|
| 3111 | assert( (inode != NULL) , "inode pointer is NULL\n"); |
---|
| 3112 | |
---|
| 3113 | // get inode FS type |
---|
| 3114 | vfs_fs_type_t fs_type = inode->ctx->type; |
---|
| 3115 | |
---|
| 3116 | // call relevant FS function |
---|
| 3117 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 3118 | { |
---|
| 3119 | error = fatfs_sync_inode( inode ); |
---|
| 3120 | } |
---|
| 3121 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3122 | { |
---|
| 3123 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 3124 | } |
---|
| 3125 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3126 | { |
---|
| 3127 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 3128 | } |
---|
| 3129 | else |
---|
| 3130 | { |
---|
| 3131 | assert( false , "undefined file system type\n" ); |
---|
| 3132 | } |
---|
| 3133 | |
---|
| 3134 | return error; |
---|
| 3135 | |
---|
| 3136 | } // end vfs_fs_sync_inode() |
---|
| 3137 | |
---|
| 3138 | //////////////////////////////////////////////// |
---|
| 3139 | error_t vfs_fs_sync_fat( vfs_fs_type_t fs_type ) |
---|
| 3140 | { |
---|
| 3141 | error_t error = 0; |
---|
| 3142 | |
---|
| 3143 | // call relevant FS function |
---|
| 3144 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 3145 | { |
---|
| 3146 | error = fatfs_sync_fat(); |
---|
| 3147 | } |
---|
| 3148 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3149 | { |
---|
| 3150 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 3151 | } |
---|
| 3152 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3153 | { |
---|
| 3154 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 3155 | } |
---|
| 3156 | else |
---|
| 3157 | { |
---|
| 3158 | assert( false , "undefined file system type\n" ); |
---|
| 3159 | } |
---|
| 3160 | |
---|
| 3161 | return error; |
---|
| 3162 | |
---|
| 3163 | } // end vfs_fs_sync_fat() |
---|
| 3164 | |
---|
| 3165 | ////////////////////////////////////////////////////// |
---|
| 3166 | error_t vfs_fs_sync_free_info( vfs_fs_type_t fs_type ) |
---|
| 3167 | { |
---|
| 3168 | error_t error = 0; |
---|
| 3169 | |
---|
| 3170 | // call relevant FS function |
---|
| 3171 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 3172 | { |
---|
| 3173 | error = fatfs_sync_free_info(); |
---|
| 3174 | } |
---|
| 3175 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3176 | { |
---|
| 3177 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 3178 | } |
---|
| 3179 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3180 | { |
---|
| 3181 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 3182 | } |
---|
| 3183 | else |
---|
| 3184 | { |
---|
| 3185 | assert( false , "undefined file system type\n" ); |
---|
| 3186 | } |
---|
| 3187 | |
---|
| 3188 | return error; |
---|
| 3189 | |
---|
| 3190 | } // end vfs_fs_sync_fat() |
---|
| 3191 | |
---|
[602] | 3192 | ///////////////////////////////////////////////// |
---|
| 3193 | error_t vfs_fs_cluster_alloc( uint32_t fs_type, |
---|
| 3194 | uint32_t * cluster ) |
---|
| 3195 | { |
---|
| 3196 | error_t error = 0; |
---|
| 3197 | |
---|
| 3198 | // call relevant FS function |
---|
| 3199 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 3200 | { |
---|
| 3201 | error = fatfs_cluster_alloc( cluster ); |
---|
[23] | 3202 | } |
---|
[602] | 3203 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3204 | { |
---|
| 3205 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 3206 | } |
---|
| 3207 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3208 | { |
---|
| 3209 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 3210 | } |
---|
| 3211 | else |
---|
| 3212 | { |
---|
| 3213 | assert( false , "undefined file system type\n" ); |
---|
| 3214 | } |
---|
[23] | 3215 | |
---|
[602] | 3216 | return error; |
---|
[401] | 3217 | |
---|
[602] | 3218 | } // end vfs_fs_alloc_cluster() |
---|
[23] | 3219 | |
---|
[602] | 3220 | //////////////////////////////////////////////// |
---|
| 3221 | error_t vfs_fs_release_inode( xptr_t inode_xp ) |
---|
| 3222 | { |
---|
| 3223 | error_t error = 0; |
---|
[23] | 3224 | |
---|
[602] | 3225 | assert( (inode_xp != XPTR_NULL) , "inode pointer is NULL\n") |
---|
| 3226 | |
---|
| 3227 | vfs_inode_t * inode_ptr = GET_PTR( inode_xp ); |
---|
| 3228 | cxy_t inode_cxy = GET_CXY( inode_xp ); |
---|
| 3229 | |
---|
| 3230 | // get local pointer on page mapper |
---|
| 3231 | mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); |
---|
| 3232 | |
---|
| 3233 | assert( (mapper != NULL) , "mapper pointer is NULL\n") |
---|
| 3234 | |
---|
| 3235 | // get FS type from mapper |
---|
| 3236 | vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->type ) ); |
---|
| 3237 | |
---|
| 3238 | // call relevant FS function |
---|
| 3239 | if( fs_type == FS_TYPE_FATFS ) |
---|
| 3240 | { |
---|
| 3241 | error = fatfs_release_inode( inode_xp ); |
---|
| 3242 | } |
---|
| 3243 | else if( fs_type == FS_TYPE_RAMFS ) |
---|
| 3244 | { |
---|
| 3245 | assert( false , "should not be called for RAMFS\n" ); |
---|
| 3246 | } |
---|
| 3247 | else if( fs_type == FS_TYPE_DEVFS ) |
---|
| 3248 | { |
---|
| 3249 | assert( false , "should not be called for DEVFS\n" ); |
---|
| 3250 | } |
---|
| 3251 | else |
---|
| 3252 | { |
---|
| 3253 | assert( false , "undefined file system type\n" ); |
---|
| 3254 | } |
---|
| 3255 | |
---|
| 3256 | return error; |
---|
| 3257 | |
---|
| 3258 | } // end vfs_fs_release_inode() |
---|
| 3259 | |
---|
| 3260 | |
---|