Changeset 23 for trunk/kernel/vfs


Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (7 years ago)
Author:
alain
Message:

Introduce syscalls.

Location:
trunk/kernel/vfs
Files:
2 added
2 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/kernel/vfs/fatfs.c

    r15 r23  
    22 * fatfs.c - FATFS file system API implementation.
    33 *
    4  * Author    Mohamed Lamine Karaoui (2015)
    5  *           Alain Greiner (2016)
     4 * Author    Mohamed Lamine Karaoui (2014,2015)
     5 *           Alain Greiner (2016,2017)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    3232#include <rpc.h>
    3333#include <mapper.h>
     34#include <cluster.h>
    3435#include <dev_ioc.h>
    3536#include <fatfs.h>
    3637
    37 
    3838//////////////////////////////////////////////////////////////////////////////////////////
     39//          Extern  variables         
     40//////////////////////////////////////////////////////////////////////////////////////////
     41
     42extern vfs_ctx_t        fs_context[FS_TYPES_NR];   // allocated in vfs.c file
     43
     44extern remote_barrier_t global_barrier;            // allocated dans kernel_init.c
     45 
    3946//////////////////////////////////////////////////////////////////////////////////////////
    4047// FATFS specific functions : these functions cannot be called by the VFS
    4148//////////////////////////////////////////////////////////////////////////////////////////
    42 //////////////////////////////////////////////////////////////////////////////////////////
    4349
    4450//////////////////////////////////////////////////////////
     
    4652                                        uint32_t      cluster )
    4753{
    48     return (ctx->cluster_begin_lba + ((cluster - 2) * ctx->sectors_per_cluster));
     54    return (ctx->cluster_begin_lba + ((cluster - 2) << 3));
    4955}
    5056
     
    95101
    96102}  // end fatfs_get_cluster()
     103
     104///////////////////////////////////////////////////////////////////////////////////////
     105// This static function return an integer record value (one, two, or four bytes)
     106// from a memory buffer, taking into account endianness.
     107///////////////////////////////////////////////////////////////////////////////////////
     108// @ offset        : first byte of record in buffer.
     109// @ size          : record length in bytes (1/2/4).
     110// @ buffer        : pointer on buffer base.
     111// @ little endian : the most significant byte has the highest address when true.
     112// @ return the integer value in a 32 bits word.
     113///////////////////////////////////////////////////////////////////////////////////////
     114static uint32_t get_record_from_buffer( uint32_t    offset,
     115                                        uint32_t    size,
     116                                        uint8_t   * buffer,
     117                                        uint32_t    little_endian )
     118{
     119    uint32_t n;
     120    uint32_t res  = 0;
     121
     122    if ( little_endian)
     123    {
     124        for( n = size ; n > 0 ; n-- ) res = (res<<8) | buffer[offset+n-1];
     125    }
     126    else
     127    {
     128        for( n = 0 ; n < size ; n++ ) res = (res<<8) | buffer[offset+n];
     129    }
     130    return res;
     131
     132}  // end get_record_from_buffer()
     133
    97134
    98135
     
    162199
    163200///////////////////////////////////////////////////////////////////////////////////////
     201//          The following functions are called by the VFS.
    164202///////////////////////////////////////////////////////////////////////////////////////
    165 // Generic API : the following functions are called by the VFS,
    166 //               and must be defined by all isupported file systems.
    167 ///////////////////////////////////////////////////////////////////////////////////////
    168 ///////////////////////////////////////////////////////////////////////////////////////
    169 
    170 ////////////////////////////////////////////////////////////
    171 error_t fatfs_inode_create( struct vfs_inode_s * vfs_inode )
    172 {
    173     printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ );
    174     hal_core_sleep();
    175 
     203
     204
     205///////////////////
     206xptr_t fatfs_init()
     207{
     208    kmem_req_t    req;
     209    fatfs_ctx_t * fatfs_ctx;       // local pointer on FATFS context
     210    vfs_ctx_t   * vfs_ctx;         // local pointer on VFS context
     211    xptr_t        root_inode_xp;   // extended pointer on root inode
     212    error_t       error;
     213
     214    // get local pointer on VFS context for FATFS
     215    vfs_ctx = &fs_context[FS_TYPE_FATFS];
     216
     217    // get number of kernel instances and extended pointer on global barrier
     218    cluster_t * cluster     = LOCAL_CLUSTER;
     219    uint32_t    nb_clusters = cluster->x_size * cluster->y_size;
     220    xptr_t      barrier_xp  = XPTR( cluster->io_cxy , &global_barrier );
     221
     222    ///// step 1 : all clusters allocate memory for FATFS context
     223
     224    // allocate memory for FATFS context extension
     225        req.type    = KMEM_FATFS_CTX;
     226        req.size    = sizeof(fatfs_ctx_t);
     227    req.flags   = AF_KERNEL | AF_ZERO;
     228        fatfs_ctx   = (fatfs_ctx_t *)kmem_alloc( &req );
     229
     230    if( fatfs_ctx == NULL )
     231    {
     232        printk("\n[PANIC] in %s : no memory for FATFS context\n", __FUNCTION__ );
     233        hal_core_sleep();
     234    }
     235   
     236    ///// step 2 : only cluster_0 access device and creates root inode
     237
     238    if( local_cxy == 0 )
     239    {
     240        // create VFS root inode
     241        error = vfs_inode_create( XPTR_NULL,        // no parent dentry
     242                                  FS_TYPE_FATFS,
     243                                  INODE_TYPE_DIR,
     244                                  0,                // attr
     245                                  0,                // rights
     246                                  0,                // uid
     247                                  0,                // gid
     248                                  &root_inode_xp );
     249
     250        assert( (error == 0 ) , __FUNCTION__ , "cannot create VFS root inode" );
     251
     252        // initialize VFS context / access device to initialize FATFS context
     253        error = fatfs_ctx_init( vfs_ctx,
     254                                fatfs_ctx,
     255                                root_inode_xp );
     256
     257        // create FATFS root inode
     258        error = fatfs_inode_create( GET_PTR( root_inode_xp ) ,
     259                                    fatfs_ctx->root_dir_cluster );
     260
     261        if( error )
     262        {
     263            printk("\n[PANIC] in %s : cannot create FATFS root inode\n", __FUNCTION__ );
     264            hal_core_sleep();
     265        }
     266
     267    }
     268
     269    //////////////// synchronize all clusters
     270    remote_barrier( barrier_xp , nb_clusters );
     271
     272    ///// step 3 : all others clusters initialize both context and extension
     273
     274    if( local_cxy != 0 )
     275    {
     276        // copy VFS context from remote cluster_0 to local cluster
     277        hal_remote_memcpy( XPTR( local_cxy , vfs_ctx ),
     278                           XPTR( 0 , vfs_ctx ),
     279                           sizeof(vfs_ctx_t) );
     280
     281        // copy FATFS context from remote cluster_0 to local cluster
     282        hal_remote_memcpy( XPTR( local_cxy , fatfs_ctx ),
     283                           XPTR( 0 , vfs_ctx->extend ) ,
     284                           sizeof(fatfs_ctx_t) );
     285
     286        // update extend field in local copy of VFS context
     287        vfs_ctx->extend = fatfs_ctx;
     288    }
     289
     290    return root_inode_xp;
     291
     292}  // end fatfs_init()
     293
     294//////////////////////////////////////////////
     295error_t fatfs_ctx_init( vfs_ctx_t   * vfs_ctx,
     296                        fatfs_ctx_t * fatfs_ctx,
     297                        xptr_t        root_inode_xp )
     298{
     299    error_t  error;
     300    uint8_t  buffer[512];    // buffer for boot record
     301
     302    // make a synchronous access to IOC device to read the boot record from device
     303    error = dev_ioc_sync_read( buffer , 0 , 1 );
     304    assert( (error == 0) , __FUNCTION__ , "cannot access FAT boot record" );
     305
     306    // check sector size from boot record
     307    uint32_t sector_size = get_record_from_buffer( BPB_BYTSPERSEC , buffer , 1 );
     308    assert( (sector_size == 512) , __FUNCTION__ , "sector size must be 512 bytes" );
     309
     310    // check cluster size from boot record
     311    uint32_t nb_sectors = get_record_from_buffer( BPB_SECPERCLUS , buffer , 1 );
     312    assert( (nb_sectors == 8) , __FUNCTION__ , "cluster size must be 8 sectors" );
     313
     314    // check number of FAT copies from boot record
     315    uint32_t nb_fats = get_record_from_buffer( BPB_NUMFATS , buffer , 1 );
     316    assert( (nb_fats == 1) , __FUNCTION__ , "number of FAT copies must be 1" );
     317
     318    // get & check number of sectors in FAT from boot record
     319    uint32_t fat_sectors = get_record_from_buffer( BPB_FAT32_FATSZ32 , buffer , 1 );
     320    assert( ((fat_sectors & 0xF) == 0) , __FUNCTION__ , "FAT not multiple of 16 sectors");
     321
     322    // get and check root cluster from boot record
     323    uint32_t root_cluster = get_record_from_buffer( BPB_FAT32_ROOTCLUS , buffer , 1 );
     324    assert( (root_cluster == 2) , __FUNCTION__ , "Root cluster index must be  2");
     325
     326    // get FAT lba from boot record
     327    uint32_t fat_lba = get_record_from_buffer( BPB_RSVDSECCNT , buffer , 1 );
     328   
     329    // allocate a mapper for the FAT itself
     330    mapper_t * fat_mapper = mapper_create();
     331    assert( (fat_mapper != NULL) , __FUNCTION__ , "no memory for FAT mapper" );
     332
     333    // initialize the FATFS context
     334    fatfs_ctx->fat_begin_lba         = fat_lba;
     335    fatfs_ctx->fat_sectors_count     = fat_sectors;
     336    fatfs_ctx->bytes_per_sector      = sector_size;
     337    fatfs_ctx->bytes_per_cluster     = sector_size * nb_sectors;
     338    fatfs_ctx->cluster_begin_lba     = fat_lba + fat_sectors;
     339    fatfs_ctx->root_dir_cluster      = 2;
     340    fatfs_ctx->last_allocated_sector = 0;    // TODO ???
     341    fatfs_ctx->last_allocated_index  = 0;    // TODO ???
     342    fatfs_ctx->fat_mapper_xp         = XPTR( local_cxy , fat_mapper );
     343
     344    // initialize the VFS context
     345    vfs_ctx->type    = FS_TYPE_FATFS;
     346    vfs_ctx->attr    = 0;                    // not READ_ONLY / not SYNC
     347    vfs_ctx->count   = fat_sectors << 10;    // total number of sectors in data region
     348    vfs_ctx->blksize = 512;                  // number of bytes per sector
     349    vfs_ctx->root_xp = root_inode_xp;
     350    vfs_ctx->extend  = fatfs_ctx;
     351
     352    spinlock_init( &vfs_ctx->lock );
     353
     354    bitmap_init( vfs_ctx->bitmap , CONFIG_VFS_MAX_INODES );
     355
     356    return 0;
     357
     358}  // end fatfs_ctx_init()
     359 
     360
     361
     362////////////////////////////////////////////////////
     363void fatfs_ctx_destroy( struct vfs_ctx_s * vfs_ctx )
     364{
     365    kmem_req_t    req;
     366    fatfs_ctx_t * fatfs_ctx;
     367
     368    // get pointer on FATFS context extension
     369    fatfs_ctx = (fatfs_ctx_t *)vfs_ctx->extend;
     370
     371    req.type = KMEM_FATFS_INODE;
     372    req.ptr  = fatfs_ctx;
     373    kmem_free( &req );
     374}
     375
     376
     377////////////////////////////////////////////////////
     378error_t fatfs_inode_create( vfs_inode_t * vfs_inode,
     379                            uint32_t      first_cluster )
     380{
    176381    kmem_req_t      req;
    177382    fatfs_inode_t * fatfs_inode;
    178383
    179     // allocate memory for fatfs inode
     384    // allocate memory for FATFS inode extension
    180385        req.type    = KMEM_FATFS_INODE;
    181386        req.size    = sizeof(fatfs_inode_t);
     
    185390    if( fatfs_inode == NULL ) return ENOMEM;
    186391
    187     // initialise ramfs_inode
    188     fatfs_inode->first_cluster = 0;   // TODO ???
    189     fatfs_inode->ctx           = (fatfs_ctx_t *)vfs_inode->ctx->extend;
     392    // link FATFS inode to VFS inode
     393    vfs_inode->extend = fatfs_inode;
     394
     395    // initialise FATFS inode
     396    fatfs_inode->first_cluster = first_cluster;
    190397 
    191     // link fatfs_inode to vfs_inode
    192     vfs_inode->extend = fatfs_inode;
    193 
    194398    return 0;
    195 
    196 }
    197 
    198 //////////////////////////////////////////////////////
    199 void fatfs_inode_destroy( struct vfs_inode_s * inode )
    200 {
    201     printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ );
    202     hal_core_sleep();
    203 }
    204 
    205 //////////////////////////////////////////////////
    206 error_t fatfs_ctx_create( struct vfs_ctx_s * ctx )
    207 {
    208     printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ );
    209     hal_core_sleep();
    210 
    211     return 0;
    212 }
    213 
    214 ////////////////////////////////////////////////
    215 void fatfs_ctx_destroy( struct vfs_ctx_s * ctx )
    216 {
    217     printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ );
    218     hal_core_sleep();
    219 }
     399}
     400
     401///////////////////////////////////////////////////
     402void fatfs_inode_destroy( vfs_inode_t * vfs_inode )
     403{
     404    kmem_req_t      req;
     405    fatfs_inode_t * fatfs_inode;
     406
     407    // get pointer on FATFS inode
     408    fatfs_inode = (fatfs_inode_t *)vfs_inode->extend;
     409
     410    req.type = KMEM_FATFS_INODE;
     411    req.ptr  = fatfs_inode;
     412    kmem_free( &req );
     413
     414        vfs_inode->extend = NULL;
     415}
     416
    220417
    221418////////////////////////////////////////////////
     
    223420                                  bool_t   is_read )
    224421{
    225     // get source buffer base address
    226     char * buffer = (char *)ppm_page2base( page );
     422    // get memory buffer base address
     423    uint8_t * buffer = (uint8_t *)ppm_page2base( page );
    227424 
    228425    // get pointer on source mapper and page index from page descriptor
    229     mapper_t * src_mapper  = page->mapper;
     426    mapper_t * mapper      = page->mapper;
    230427    uint32_t   page_index  = page->index;
    231428
    232     if( src_mapper == NULL)
    233     {
    234         printk("\n[PANIC] in %s : no mapper for this page\n", __FUNCTION__ );
    235         hal_core_sleep();
    236     }
    237 
    238429    // get VFS inode pointer from mapper
    239     vfs_inode_t * vfs_inode = src_mapper->inode;
     430    vfs_inode_t * vfs_inode = mapper->inode;
    240431
    241432    // get FATFS inode pointer for VFS inode
     
    246437
    247438    // get FATFS context pointer from FATFS inode
    248     fatfs_ctx_t * fatfs_ctx = fatfs_inode->ctx;
     439    fatfs_ctx_t * fatfs_ctx = (fatfs_ctx_t *)vfs_inode->ctx->extend;
    249440
    250441    // get number of sectors
  • trunk/kernel/vfs/fatfs.h

    r15 r23  
    22 * fatfs.h - FATFS file system API definition.
    33 *
    4  * Author    Mohamed Lamine Karaoui (2015)
    5  *           Alain Greiner (2016)
     4 * Author    Mohamed Lamine Karaoui (2014,2015)
     5 *           Alain Greiner (2016,2017)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    2828#include <hal_types.h>
    2929#include <rwlock.h>
     30#include <vfs.h>
     31
     32
     33///////////////////////////////////////////////////////////////////////////////////////////
     34// The FATFS File System implements a FAT32 read/write file system.
     35///////////////////////////////////////////////////////////////////////////////////////////
     36
     37/*************** Partition Boot Sector Format **********************************/
     38//                                     offset |  length
     39#define BS_JMPBOOT                          0 ,  3
     40#define BS_OEMNAME                          3 ,  8
     41#define BPB_BYTSPERSEC                     11 ,  2
     42#define BPB_SECPERCLUS                     13 ,  1
     43#define BPB_RSVDSECCNT                     14 ,  2
     44#define BPB_NUMFATS                        16 ,  1
     45#define BPB_ROOTENTCNT                     17 ,  2
     46#define BPB_TOTSEC16                       19 ,  2
     47#define BPB_MEDIA                          21 ,  1
     48#define BPB_FATSZ16                        22 ,  2
     49#define BPB_SECPERTRK                      24 ,  2
     50#define BPB_NUMHEADS                       26 ,  2
     51#define BPB_HIDDSEC                        28 ,  4
     52#define BPB_TOTSEC32                       32 ,  4
     53#define BPB_PARTITION_TABLE               446 , 64
     54
     55// FAT 32
     56#define BPB_FAT32_FATSZ32                  36 ,  4
     57#define BPB_FAT32_EXTFLAGS                 40 ,  2
     58#define BPB_FAT32_FSVER                    42 ,  2
     59#define BPB_FAT32_ROOTCLUS                 44 ,  4
     60#define BPB_FAT32_FSINFO                   48 ,  2
     61#define BPB_FAT32_BKBOOTSEC                50 ,  2
     62#define BS_FAT32_DRVNUM                    64 ,  1
     63#define BS_FAT32_BOOTSIG                   66 ,  1
     64#define BS_FAT32_VOLID                     67 ,  4
     65#define BS_FAT32_VOLLAB                    71 , 11
     66#define BS_FAT32_FILSYSTYPE                82 ,  8
     67
     68// Partitions
     69#define FIRST_PARTITION_ACTIVE            446 ,  8
     70#define FIRST_PARTITION_BEGIN_LBA         454 ,  4
     71#define FIRST_PARTITION_SIZE              458 ,  4
     72#define SECOND_PARTITION_ACTIVE           462 ,  8
     73#define SECOND_PARTITION_BEGIN_LBA        470 ,  4
     74#define SECOND_PARTITION_SIZE             474 ,  4
     75#define THIRD_PARTITION_ACTIVE            478 ,  8
     76#define THIRD_PARTITION_BEGIN_LBA         486 ,  4
     77#define THIRD_PARTITION_SIZE              490 ,  4
     78#define FOURTH_PARTITION_ACTIVE           494 ,  8
     79#define FOURTH_PARTITION_BEGIN_LBA        502 ,  4
     80#define FOURTH_PARTITION_SIZE             506 ,  4   
     81/*******************************************************************************/
     82
     83#define MBR_SIGNATURE_POSITION            510 , 2
     84#define MBR_SIGNATURE_VALUE               0xAA55 
     85
     86/************** FAT_FS_INFO SECTOR  ********************************************/
     87#define FS_SIGNATURE_VALUE_1              0x52526141
     88#define FS_SIGNATURE_VALUE_2              0x72724161
     89#define FS_SIGNATURE_VALUE_3              0x000055AA 
     90#define FS_SIGNATURE_POSITION_1           0   , 4 
     91#define FS_SIGNATURE_POSITION_2           484 , 4
     92#define FS_SIGNATURE_POSITION_3           508 , 4 
     93#define FS_FREE_CLUSTERS                  488 , 4
     94#define FS_FREE_CLUSTER_HINT              492 , 4
     95/*******************************************************************************/
     96
     97#define DIR_ENTRY_SIZE          32
     98                   
     99#define NAME_MAX_SIZE           31
     100
     101/******* Directory Entry Structure (32 bytes) **********************************/
     102//                            offset | length
     103#define DIR_NAME                   0 , 11   // dir_entry name
     104#define DIR_ATTR                  11 ,  1   // attributes
     105#define DIR_NTRES                 12 ,  1   // reserved for the OS       
     106#define DIR_CRT_TIMES_TENTH       13 ,  1
     107#define DIR_FST_CLUS_HI           20 ,  2   // cluster index 16 MSB bits
     108#define DIR_WRT_TIME              22 ,  2   // time of last write
     109#define DIR_WRT_DATE              24 ,  2   // date of last write
     110#define DIR_FST_CLUS_LO           26 ,  2   // cluster index 16 LSB bit
     111#define DIR_FILE_SIZE             28 ,  4   // dir_entry size (up to 4 Gbytes)
     112/*******************************************************************************/
     113
     114/******* LFN Directory Entry Structure  (32 bytes) *****************************/
     115//                            offset | length
     116#define LDIR_ORD                   0 ,  1   // Sequence number (from 0x01 to 0x0f)   
     117#define LDIR_NAME_1                1 , 10   // name broken into 3 parts
     118#define LDIR_ATTR                 11 ,  1   // attributes (must be 0x0F)
     119#define LDIR_TYPE                 12 ,  1   // directory type (must be 0x00)
     120#define LDIR_CHKSUM               13 ,  1   // checksum of name in short dir 
     121#define LDIR_NAME_2               14 , 12
     122#define LDIR_RSVD                 26 ,  2   // artifact of previous fat (must be 0)
     123#define LDIR_NAME_3               28 ,  4   
     124/*******************************************************************************/
     125
     126/***********************  DIR_ATTR values  (attributes) ************************/
     127#define ATTR_READ_ONLY            0x01
     128#define ATTR_HIDDEN               0x02
     129#define ATTR_SYSTEM               0x04
     130#define ATTR_VOLUME_ID            0x08
     131#define ATTR_DIRECTORY            0x10
     132#define ATTR_ARCHIVE              0x20
     133#define ATTR_LONG_NAME_MASK       0x0f      // READ_ONLY|HIDDEN|SYSTEM|VOLUME_ID
     134/*******************************************************************************/
     135
     136/********************* DIR_ORD special values **********************************/
     137#define FREE_ENTRY                0xE5     // this entry is free in the directory
     138#define NO_MORE_ENTRY             0x00     // no more entry in the directory
     139/*******************************************************************************/
     140
     141/******************** CLuster Index Special Values *****************************/
     142#define FREE_CLUSTER              0x00000000
     143#define RESERVED_CLUSTER          0x00000001
     144#define BAD_CLUSTER               0x0FFFFFF7
     145#define END_OF_CHAIN_CLUSTER_MIN  0x0ffffff8
     146#define END_OF_CHAIN_CLUSTER_MAX  0x0fffffff
     147/*******************************************************************************/
    30148
    31149/****  Forward declarations  ****/
    32150
    33151struct mapper_s;
    34 struct device_s;
     152struct page_s;
     153struct vfs_ctx_s;
    35154struct vfs_inode_s;
    36 struct vfs_ctx_s;
    37 struct page_s;
    38 
    39 /*****************************************************************************************
    40  * This structure defines a FATFS specific context extension.
     155
     156/*****************************************************************************************
     157 * This structure defines a FATFS specific context (extension to VFS context).
    41158 ****************************************************************************************/
    42159
    43160typedef struct fatfs_ctx_s
    44161{
    45     rwlock_t          lock;                  /*! TODO protect what ???                  */
    46     uint32_t          fat_begin_lba;         /*! first lba of FAT region                */
     162    uint32_t          fat_begin_lba;         /*! lba of FAT region                      */
    47163    uint32_t          fat_sectors_count;     /*! number of sectors in FAT region        */
    48164    uint32_t          bytes_per_sector;      /*!                                        */
    49165    uint32_t          bytes_per_cluster;     /*!                                        */
    50     uint32_t          cluster_begin_lba;     /*! first lba of data region on device     */
    51     uint32_t          sectors_per_cluster;   /*!                                        */
    52     uint32_t          rootdir_first_cluster; /*                                         */
    53     uint32_t          last_allocated_sector; /*!                                        */
    54     uint32_t          last_allocated_index;  /*! TODO last allocated cluster ???        */
    55     xptr_t            fat_mapper_xp;         /*! FAT mapper (in IO cluster)             */ 
     166    uint32_t          cluster_begin_lba;     /*! lba of data region                     */
     167    uint32_t          sectors_per_cluster;   /*! cluster index for root directory       */
     168    uint32_t          root_dir_cluster;      /*!                                        */
     169    uint32_t          last_allocated_sector; /*! TODO ???                               */
     170    uint32_t          last_allocated_index;  /*! TODO ???                               */
     171    xptr_t            fat_mapper_xp;         /*! FAT mapper (in IO cluster)             */
    56172}
    57173fatfs_ctx_t;
    58174
    59175/*****************************************************************************************
    60  * This structure defines the FAT specific inode extension (versus the VFS inode).
     176 * This structure defines the FATFS specific inode (extension to VFS inode).
    61177 ****************************************************************************************/
    62178
    63179typedef struct fatfs_inode_s
    64180{
    65     struct fatfs_ctx_s * ctx;                /*! local pointer on the FATFS context     */
    66         uint32_t             first_cluster;      /*! first cluster for this file/dir        */
     181        uint32_t          first_cluster;         /*! first cluster for this file/dir        */
    67182}
    68183fatfs_inode_t;
     
    70185
    71186
     187
     188//////////////////////////////////////////////////////////////////////////////////////////
     189// These functions are specific to the FATFS, and cannot be called by the VFS.
     190//////////////////////////////////////////////////////////////////////////////////////////
     191
    72192/*****************************************************************************************
    73193 * This function returns the LBA of the first sector of a FAT cluster.
     
    76196 * @ ctx          :     pointer on FATFS context.
    77197 * @ cluster  : cluster index in FATFS.
    78  * # return the lba value.
     198 * @ return the lba value.
    79199 ****************************************************************************************/
    80200inline uint32_t fatfs_lba_from_cluster( fatfs_ctx_t * ctx,
     
    105225                           uint32_t        * cluster );
    106226
     227
     228
     229
     230//////////////////////////////////////////////////////////////////////////////////////////
     231// These functions are called by the VFS, and must be implemented by all File Systems.
     232//////////////////////////////////////////////////////////////////////////////////////////
     233
     234/******************************************************************************************
     235 * This function initializes the FATFS file system as the root FS.
     236 * It is executed cooperatively during kernel init by all CP0s in all clusters.
     237 * The initilisation is made in three phases, separated by synchronisation barrier:     
     238 * - phase 1 : all CP0s in all clusters allocate memory for the local copy of
     239 *   the FATFS context.
     240 * - phase 2 : cluster_0 only creates the root inode descriptor, access the external
     241 *   device to get information stored on the boot record, and initialises both
     242 *   the VFS context, and the FATFS context.
     243 * - phase 3 : all other clusters initialize their local VFS context and FATFS context
     244 *   from values contained in cluster_0, using hal_remote_memcpy().
     245 ******************************************************************************************
     246 * @ return an extended pointer on the created root inode / return XPTR_NULL if failure.
     247 *****************************************************************************************/
     248xptr_t fatfs_init();
     249
     250/******************************************************************************************
     251 * This function mount the FATFS on the root FS.
     252 * TODO not implemented [AG]
     253 ******************************************************************************************
     254 * @ parent_inode_xp : extended pointer on the parent inode.
     255 *****************************************************************************************/
     256error_t fatfs_mount( xptr_t parent_inode_xp );
     257
     258
     259/*****************************************************************************************
     260 * This function  initializes both the VFS context and the FATFS context.
     261 * Both the VFS context and the FATFS context must have been previously allocated.
     262 * It access the device to read the boot record, and is supposed to be called only
     263 * in cluster_0 (in other clusters these contexts are replicated from values
     264 * contained in cluster_0).
     265 *****************************************************************************************
     266 * @ vfs_ctx        : local pointer on VFS context for FATFS.
     267 * @ fatfs_ctx      : local pointer on specific FATFS context.
     268 * @ root_inode_xp  : extended pointer on VFS root inode.
     269 ****************************************************************************************/
     270error_t fatfs_ctx_init( struct vfs_ctx_s   * vfs_ctx,
     271                        struct fatfs_ctx_s * fatfs_ctx,
     272                        xptr_t               root_inode_xp );
     273
     274/*****************************************************************************************
     275 * This function releases memory dynamically allocated for the FATFS context extension.
     276 *****************************************************************************************
     277 * @ vfs_ctx   : local pointer on VFS context.
     278 ****************************************************************************************/
     279void fatfs_ctx_destroy( struct vfs_ctx_s * vfs_ctx );
     280
     281
     282
    107283/*****************************************************************************************
    108284 * This function allocates memory for a FATFS inode, initializes it,
    109285 * and link it to the VFS inode.
    110286 *****************************************************************************************
     287 * @ inode         : local pointer on the VFS inode.
     288 * @ first_cluster : first cluster index in the FAT32.
     289 * @ return 0 if success / return ENOMEM if error.
     290 ****************************************************************************************/
     291error_t fatfs_inode_create( struct vfs_inode_s * inode,
     292                            uint32_t             first_cluster);
     293
     294/*****************************************************************************************
     295 * This function releases memory allocated for a FATFS inode.
     296 *****************************************************************************************
    111297 * @ inode   : local pointer on vfs_inode.
    112  * @ return 0 if success / return ENOMEM if error.
    113  ****************************************************************************************/
    114 error_t fatfs_inode_create( struct vfs_inode_s * inode );
    115 
    116 /*****************************************************************************************
    117  * This function releases memory allocated for a FATFS inode.
    118  *****************************************************************************************
    119  * @ inode   : local pointer on vfs_inode.
    120298 ****************************************************************************************/
    121299void fatfs_inode_destroy( struct vfs_inode_s * inode );
    122300
    123 /*****************************************************************************************
    124  * This function allocates memory for a FATFS context, initialises it,
    125  * and link it to the local VFS context.
    126  *****************************************************************************************
    127  * @ inode   : local pointer on VFS context.
    128  * @ return 0 if success / return ENOMEM if error.
    129  ****************************************************************************************/
    130 error_t fatfs_ctx_create( struct vfs_ctx_s * ctx );
    131 
    132 /*****************************************************************************************
    133  * This function releases memory allocated for a FATFS context.
    134  *****************************************************************************************
    135  * @ ctx   : local pointer on VFS context.
    136  ****************************************************************************************/
    137 void fatfs_ctx_destroy( struct vfs_ctx_s * ctx );
    138 
    139 /*****************************************************************************************
    140  * This function moves a page from the mapper to the FATFS file system.
     301
     302
     303/*****************************************************************************************
     304 * This function moves a page from the mapper to the FATFS file system on device.
    141305 * It must be called by a thread running in cluster containing the mapper.
    142  * The pointer on the mapper and the page index in file are supposed to be registered
     306 * The pointer on the mapper and the page index in file are registered
    143307 * in the page descriptor.
    144308 *****************************************************************************************
     
    151315 * This function moves a page from the FATFS file system on device to the mapper.
    152316 * It must be called by a thread running in cluster containing the mapper.
    153  * The pointer on the mapper and the page index in file are supposed to be registered
     317 * The pointer on the mapper and the page index in file are registered
    154318 * in the page descriptor.
    155319 *****************************************************************************************
     
    160324
    161325
     326
     327
    162328#endif  /* _FATFS_H_ */
  • trunk/kernel/vfs/ramfs.c

    r15 r23  
    22 * ramfs.c  RAMFS file system API implementation.
    33 *
    4  * Authors   Mohamed Lamine Karaoui (2015)
    5  *           Alain Greiner (2016)
     4 * Authors   Mohamed Lamine Karaoui (2014,2015)
     5 *           Alain Greiner (2016,2017)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    3232
    3333
    34 ///////////////////////////////////////////////////////////////////////////////////////
    35 // RAMFS specific functions : these static functions cannot be called by the VFS
    36 ///////////////////////////////////////////////////////////////////////////////////////
    3734
    3835
    3936
    4037///////////////////////////////////////////////////////////////////////////////////////
    41 // Generic API : the following functions are called by the VFS,
    42 //               and must be defined by all supported file systems.
     38//             The following functions are called by the VFS.
    4339///////////////////////////////////////////////////////////////////////////////////////
    4440
    45 ////////////////////////////////////////////////////////////
    46 error_t ramfs_inode_create( struct vfs_inode_s * vfs_inode )
     41//////////////////////////////////////////////
     42error_t ramfs_mount( xptr_t   parent_inode_xp,
     43                     char   * ramfs_root_name )
    4744{
    48     printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ );
    49     hal_core_sleep();
     45    xptr_t        root_inode_xp;   // unused                     
     46 
     47    // create VFS dentry and VFS inode for RAMFS root directory
     48    return  vfs_add_child_in_parent( INODE_TYPE_DIR,
     49                                     FS_TYPE_RAMFS,
     50                                     parent_inode_xp,
     51                                     ramfs_root_name,
     52                                     &root_inode_xp );
     53}
    5054
    51     kmem_req_t      req;
    52     ramfs_inode_t * ramfs_inode;
    5355
    54     // allocate memory for ramfs inode
    55         req.type    = KMEM_RAMFS_INODE;
    56         req.size    = sizeof(ramfs_inode_t);
    57     req.flags   = AF_KERNEL | AF_ZERO;
    58         ramfs_inode = (ramfs_inode_t *)kmem_alloc( &req );
     56////////////////////////////////////////////
     57error_t ramfs_ctx_init( vfs_ctx_t * vfs_ctx,
     58                        xptr_t      root_inode_xp )
    5959
    60     if( ramfs_inode == NULL ) return ENOMEM;
     60{
     61    vfs_ctx->type    = FS_TYPE_RAMFS;
     62    vfs_ctx->attr    = 0;                // not READ_ONLY / not SYNC
     63    vfs_ctx->count   = 0;                // unused for RAMFS
     64    vfs_ctx->blksize = 512;              // unused for RAMFS
     65    vfs_ctx->root_xp = root_inode_xp;
     66    vfs_ctx->extend  = NULL;             // unused for DEVFS
    6167
    62     // initialise ramfs_inode TODO
     68    spinlock_init( &vfs_ctx->lock );
    6369
    64     // link vfs_inode to ramfs_inode
    65     vfs_inode->extend = ramfs_inode;
     70    bitmap_init( vfs_ctx->bitmap , CONFIG_VFS_MAX_INODES );
    6671
    6772    return 0;
    6873}
    6974
    70 //////////////////////////////////////////////////////
    71 void ramfs_inode_destroy( struct vfs_inode_s * inode )
    72 {
    73     assert( false , __FUNCTION__ , "not fully implemented yet" );
    74 }
    75 
    76 /////////////////////////////////////////////////
    77 error_t ramfs_write_page( struct page_s  * page )
    78 {
    79     printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ );
    80     hal_core_sleep();
    81 
    82     return 0;
    83 }
    84 
    85 ////////////////////////////////////////////////
    86 error_t ramfs_read_page( struct page_s  * page )
    87 {
    88     printk("\n[PANIC] %s not fully implemented yet\n", __FUNCTION__ );
    89     hal_core_sleep();
    90 
    91     return 0;
    92 }
    93    
  • trunk/kernel/vfs/ramfs.h

    r15 r23  
    22 * ramfs.h  RAMFS file system API definition.
    33 *
    4  * Authors   Mohamed Lamine Karaoui (2015)
    5  *           Alain Greiner (2016)
     4 * Authors   Mohamed Lamine Karaoui (2014,2015)
     5 *           Alain Greiner (2016,2017)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    2626#define _RAMFS_H_
    2727
     28///////////////////////////////////////////////////////////////////////////////////////////
     29// The RAMFS File System Rdoes not uses any external device to store data.
     30// It stores the dynamically created files and directories in the VFS mappers.
     31// The ramfs_read_page() and ramfs_write_page() functions should never be used.
     32// The RAMFS cannot be used as the root FS.
     33// There is no RAMFS context extension, and no RAMFS inode extension.
     34///////////////////////////////////////////////////////////////////////////////////////////
     35
     36
    2837/****  Forward declarations  ****/
    2938
    30 struct vfs_inode_s;
    31 struct page_s;
     39
     40//////////////////////////////////////////////////////////////////////////////////////////
     41// These functions are called by the VFS, and must be implemented by all FS.
     42//////////////////////////////////////////////////////////////////////////////////////////
     43
     44/******************************************************************************************
     45 * This function does not exist, as the RAMFS cannot be the root FS.
     46 *****************************************************************************************/
     47xptr_t ramfs_init();
     48
     49/******************************************************************************************
     50 * This function mount a RAMFS on a given inode of the root FS.
     51 * It actually creates a new VFS dentry in the cluster containing the parent inode,
     52 * and create a new VFS inode in another cluster.
     53 ******************************************************************************************
     54 * @ parent_inode_xp : extended pointer on the parent inode.
     55 * @ ramfs_root_name : RAMFS root directory name.
     56 *****************************************************************************************/
     57error_t ramfs_mount( xptr_t   parent_inode_xp,
     58                     char   * ramfs_root_name );
    3259
    3360/*****************************************************************************************
    34  * This structure defines a RAMFS specific context extension.
     61 * This function initializes all fields of the VFS context.
     62 * No extra memory is allocated for a RAMFS context.
    3563 ****************************************************************************************/
    36 
    37 typedef struct ramfs_ctx_s
    38 {
    39     intptr_t          base;                                                                 
    40     rwlock_t          size;
    41 }
    42 ramfs_ctx_t;
     64error_t ramfs_ctx_init( struct vfs_ctx_s * vfs_ctx,
     65                        xptr_t             root_inode_xp );
    4366
    4467/*****************************************************************************************
    45  * This structure defines the RAMFS inode specific extension (versus the VFS inode).
     68 * This function does not exist for a RAMFS context, as there is no RAMFS context.
    4669 ****************************************************************************************/
    47 
    48 typedef struct ramfs_inode_s
    49 {
    50     struct vfs_inode_s * vfs_inode;   /*! local pointer on VFS inode                    */
    51 }
    52 ramfs_inode_t;
    53 
    54 
    55 
     70error_t ramfs_ctx_destroy();
    5671
    5772/*****************************************************************************************
    58  * This function allocates memory for a RAMFS inode, and link it to the VFS inode.
    59  *****************************************************************************************
    60  * @ inode   : local pointer on vfs_inode.
    61  * @ return 0 if success / return ENOMEM if error.
     73 * This function does not exist, as the RAMFS does not use a RAMFS inode extension.
    6274 ****************************************************************************************/
    6375error_t ramfs_inode_create( struct vfs_inode_s * inode );
    6476
    6577/*****************************************************************************************
    66  * This function releases memory allocated for a RAMFS inode.
    67  *****************************************************************************************
    68  * @ inode   : local pointer on vfs_inode.
     78 * This function does not exist, as the RAMFS does not use a RAMFS inode extension.
    6979 ****************************************************************************************/
    7080void ramfs_inode_destroy( struct vfs_inode_s * inode );
    7181
    7282/*****************************************************************************************
    73  * This function moves a page from the mapper to the RAMFS file system.
    74  * It must be called by a thread running in cluster containing the mapper.
    75  * The pointer on the mapper and the page index in file are supposed to be registered
    76  * in the page descriptor.
    77 ******************************************************************************************
    78  * @ page    : local pointer on source page descriptor.
    79  * @ return 0 if success / return EIO if error.
     83 * This function does nothing for the RAMFS File System.
    8084 ****************************************************************************************/
    81 error_t ramfs_write_page( struct page_s  * page );
     85error_t ramfs_write_page( struct page_s * page );
    8286
    8387/*****************************************************************************************
    84  * This function moves a page from the RAMFS file system to the mapper.
    85  * It must be called by a thread running in cluster containing the mapper.
    86  * The pointer on the mapper and the page index in file are supposed to be registered
    87  * in the page descriptor.
    88  *****************************************************************************************
    89  * @ page    : local pointer on destination page descriptor.
    90  * @ return 0 if success / return EIO if error.
     88 * This function does not exist for the RAMFS File System.
    9189 ****************************************************************************************/
    92 error_t ramfs_read_page( struct page_s  * page );
     90error_t ramfs_read_page( struct page_s * page );
    9391
    9492
    95    
    9693#endif  /* _RAMFS_H_ */
  • trunk/kernel/vfs/vfs.c

    r14 r23  
    3535#include <slist.h>
    3636#include <xhtab.h>
     37#include <rpc.h>
    3738#include <errno.h>
    3839#include <kmem.h>
     
    4041#include <thread.h>
    4142#include <process.h>
     43#include <vfs.h>
    4244#include <fatfs.h>
    4345#include <ramfs.h>
    44 #include <vfs.h>
     46#include <devfs.h>
     47#include <syscalls.h>
    4548
    4649
     
    4952//////////////////////////////////////////////////////////////////////////////////////////
    5053
    51 // array of supported FS contexts (indexed by the FS type)
     54// array of supported FS contexts
    5255vfs_ctx_t   fs_context[FS_TYPES_NR];
    5356
     
    5659//////////////////////////////////////////////////////////////////////////////////////////
    5760
    58 /////////////////////////////////////////////////
     61////////////////////////////////////////////
    5962error_t vfs_ctx_inum_alloc( vfs_ctx_t * ctx,
    6063                            uint32_t  * inum )
     
    6467
    6568    // get lid from local inum allocator
    66     uint32_t lid = bitmap_ffc( ctx->inum , CONFIG_VFS_MAX_INODES );
     69    uint32_t lid = bitmap_ffc( ctx->bitmap , CONFIG_VFS_MAX_INODES );
    6770
    6871    if( lid == -1 )   // no more free slot => error
     
    7780    {
    7881        // set slot allocated
    79         bitmap_set( ctx->inum , lid );
     82        bitmap_set( ctx->bitmap , lid );
    8083
    8184        // release lock
     
    9295                           uint32_t    inum )
    9396{
    94     bitmap_clear( ctx->inum , inum & 0xFFFF );
     97    bitmap_clear( ctx->bitmap , inum & 0xFFFF );
    9598}
    9699
     
    99102//////////////////////////////////////////////////////////////////////////////////////////
    100103
    101 ////////////////////////////////////////////////
    102 error_t vfs_inode_create( xptr_t      dentry_xp,
    103                           uint32_t    type,
    104                           uint32_t    attr,
    105                           uint32_t    mode,
    106                           uid_t       uid,
    107                           gid_t       gid,
    108                           xptr_t    * inode_xp )
     104//////////////////////////////////////////////////////
     105
     106error_t vfs_inode_create( xptr_t            dentry_xp,
     107                          vfs_fs_type_t     fs_type,
     108                          vfs_inode_type_t  inode_type,
     109                          uint32_t          attr,
     110                          uint32_t          rights,
     111                          uid_t             uid,
     112                          gid_t             gid,
     113                          xptr_t          * inode_xp )
    109114{
    110115    mapper_t         * mapper;     // associated mapper( to be allocated)
     
    115120    error_t            error;
    116121
    117     // check type and get pointer on context
    118     if     ( type == FS_TYPE_FATFS ) ctx = &fs_context[FS_TYPE_FATFS];
    119     else if( type == FS_TYPE_RAMFS ) ctx = &fs_context[FS_TYPE_RAMFS];
     122    // check fs type and get pointer on context
     123    if     ( fs_type == FS_TYPE_FATFS ) ctx = &fs_context[FS_TYPE_FATFS];
     124    else if( fs_type == FS_TYPE_RAMFS ) ctx = &fs_context[FS_TYPE_RAMFS];
     125    else if( fs_type == FS_TYPE_DEVFS ) ctx = &fs_context[FS_TYPE_DEVFS];
    120126    else
    121127    {
     
    144150    }
    145151
    146     // allocate memory for inode descriptor
     152    // allocate memory for VFS inode descriptor
    147153        req.type  = KMEM_VFS_INODE;
    148154        req.size  = sizeof(vfs_inode_t);
     
    160166    // initialize inode descriptor
    161167    inode->gc         = 0;
     168    inode->type       = inode_type;
    162169    inode->inum       = inum;
    163170    inode->attr       = attr;
    164     inode->mode       = mode;
     171    inode->rights     = rights;
    165172    inode->uid        = uid;
    166173    inode->gid        = gid;
     
    174181
    175182    // initialize dentries hash table, if new inode is a directory
    176     if( attr & INODE_ATTR_DIR ) xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );
     183    if( inode_type == INODE_TYPE_DIR ) xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );
    177184
    178185    // initialize inode locks
    179186    remote_rwlock_init( XPTR( local_cxy , &inode->data_lock ) );
    180187    remote_spinlock_init( XPTR( local_cxy , &inode->main_lock ) );
    181 
    182     // create FS specific inode
    183     if     ( ctx->type == FS_TYPE_FATFS )  fatfs_inode_create( inode );
    184     else if( ctx->type == FS_TYPE_RAMFS )  ramfs_inode_create( inode );
    185188
    186189    // return extended pointer on inode
     
    284287//////////////////////////////////////////////////////////////////////////////////////////
    285288
    286 //////////////////////////////////////////////
    287 error_t vfs_dentry_create( uint32_t      type,
    288                            char        * name,
    289                            vfs_inode_t * parent,
    290                            xptr_t      * dentry_xp )
     289///////////////////////////////////////////////////
     290error_t vfs_dentry_create( vfs_fs_type_t   fs_type,
     291                           char          * name,
     292                           vfs_inode_t   * parent,
     293                           xptr_t        * dentry_xp )
    291294{
    292295    vfs_ctx_t      * ctx;        // context descriptor
    293296    vfs_dentry_t   * dentry;     // dentry descriptor (to be allocated)
    294297        kmem_req_t       req;        // request to kernel memory allocator
    295     xptr_t           xhtab_xp;   // extended pointer on xhtab_t embedded in inode
    296     xptr_t           xlist_xp;   // extended pointer on xlist_entry_t in dentry
     298
     299printk("\n            @@@ dentry_create : 0 / name = %s\n", name );
    297300
    298301    // check type and get pointer on context
    299     if     ( type == FS_TYPE_FATFS ) ctx = &fs_context[FS_TYPE_FATFS];
    300     else if( type == FS_TYPE_RAMFS ) ctx = &fs_context[FS_TYPE_RAMFS];
     302    if     ( fs_type == FS_TYPE_FATFS ) ctx = &fs_context[FS_TYPE_FATFS];
     303    else if( fs_type == FS_TYPE_RAMFS ) ctx = &fs_context[FS_TYPE_RAMFS];
     304    else if( fs_type == FS_TYPE_DEVFS ) ctx = &fs_context[FS_TYPE_DEVFS];
    301305    else
    302306    {
     
    309313    uint32_t length = strlen( name );
    310314
    311     if( length > (CONFIG_VFS_MAX_NAME_LENGTH - 1) )
     315    if( length >= CONFIG_VFS_MAX_NAME_LENGTH )
    312316    {
    313317        printk("\n[ERROR] in %s : name too long\n", __FUNCTION__ );
    314318        return EINVAL;
    315319    }
     320
     321printk("\n            @@@ dentry_create : 1 / name = %s\n", name );
    316322
    317323    // allocate memory for dentry descriptor
     
    328334
    329335    // initialize dentry descriptor
     336
    330337    dentry->ctx     = ctx;
    331338    dentry->length  = length;
     
    333340    strcpy( dentry->name , name );
    334341
    335     // return extended pointer on dentry to caller
     342printk("\n            @@@ dentry_create : 2 / name = %s\n", name );
     343
     344    // register dentry in hash table rooted in parent inode
     345    xhtab_insert( XPTR( local_cxy , &parent->children ),
     346                  name,
     347                  XPTR( local_cxy , &dentry->xlist ) );
     348
     349printk("\n            @@@ dentry_create : 3 / name = %s\n", name );
     350
     351    // return extended pointer on dentry
    336352    *dentry_xp = XPTR( local_cxy , dentry );
    337353
    338     // register dentry in hash table rooted in parent inode
    339     xhtab_xp    = XPTR( local_cxy , &parent->children );
    340     xlist_xp    = XPTR( local_cxy , &dentry->xlist );
    341     xhtab_register( xhtab_xp  , name , xlist_xp );
    342    
    343354    return 0;
    344355
     
    365376//////////////////////////////////////////////////////////////////////////////////////////
    366377
    367 ////////////////////////////////////////
    368 void vfs_file_count_up( xptr_t file_xp )
    369 {
    370     // get file cluster and local pointer
    371     cxy_t        file_cxy = GET_CXY( file_xp );
    372     vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
    373 
    374     // atomically increment count
    375     hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->refcount ) , 1 );
    376 }
    377 
    378 //////////////////////////////////////////
    379 void vfs_file_count_down( xptr_t file_xp )
    380 {
    381     // get file cluster and local pointer
    382     cxy_t        file_cxy = GET_CXY( file_xp );
    383     vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
    384 
    385     // atomically decrement count
    386     hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->refcount ) , -1 );
    387 }
    388 
    389 ////////////////////////////////////////////////
    390 error_t vfs_file_create( xptr_t        inode_xp,
    391                          uint32_t      type,
     378/////////////////////////////////////////////
     379error_t vfs_file_create( vfs_inode_t * inode,
    392380                         uint32_t      attr,
    393                          xptr_t      * file_xp ) 
    394 {
    395     vfs_file_t  * file_ptr;
     381                         xptr_t      * file_xp )
     382{
     383    vfs_file_t  * file;
    396384        kmem_req_t    req;
    397 
    398     // get inode cluster and local pointer
    399     cxy_t         inode_cxy = GET_CXY( inode_xp );
    400     vfs_inode_t * inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp );
    401 
    402     // check cluster identifier
    403     if( inode_cxy != local_cxy )
    404     {
    405         printk("\n[PANIC] in %s : local cluster is not the inode owner\n", __FUNCTION__ );
    406         hal_core_sleep();
    407     }
    408385
    409386    // allocate memory for new file descriptor
     
    411388        req.size  = sizeof(vfs_file_t);
    412389    req.flags = AF_KERNEL | AF_ZERO;
    413         file_ptr  = (vfs_file_t *)kmem_alloc( &req );
    414 
    415     if( file_ptr == NULL ) return ENOMEM;
    416 
    417     // get inode local pointer
     390        file      = (vfs_file_t *)kmem_alloc( &req );
     391
     392    if( file == NULL ) return ENOMEM;
     393
    418394    // initializes new file descriptor
    419     file_ptr->gc       = 0;
    420     file_ptr->type     = type;
    421     file_ptr->attr     = attr;
    422     file_ptr->offset   = 0;
    423     file_ptr->refcount = 0;
    424     file_ptr->inode    = inode_ptr;
    425     file_ptr->ctx      = inode_ptr->ctx;
    426     file_ptr->mapper   = inode_ptr->mapper;
    427 
    428     remote_rwlock_init( XPTR( local_cxy , &file_ptr->lock ) );
    429 
    430     *file_xp = XPTR( local_cxy , file_ptr );
    431     return 0;
    432 }
    433 
    434 ////////////////////////////////////////
    435 void vfs_file_destroy( xptr_t  file_xp )
    436 {
    437     // get file cluster and local pointer
    438     cxy_t        file_cxy = GET_CXY( file_xp );
    439     vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
    440 
    441     if( file_cxy != local_cxy )
    442     {
    443         printk("\n[PANIC] in %s : file descriptor not in local cluster\n", __FUNCTION__ );
    444         hal_core_sleep();
    445     }
    446 
    447     if( file_ptr->refcount )
     395    file->gc       = 0;
     396    file->type     = inode->type;
     397    file->attr     = attr;
     398    file->offset   = 0;
     399    file->refcount = 0;
     400    file->inode    = inode;
     401    file->ctx      = inode->ctx;
     402    file->mapper   = inode->mapper;
     403
     404    remote_rwlock_init( XPTR( local_cxy , &file->lock ) );
     405
     406    *file_xp = XPTR( local_cxy , file );
     407    return 0;
     408
     409}  // end vfs_file_create()
     410
     411///////////////////////////////////////////
     412void vfs_file_destroy( vfs_file_t *  file )
     413{
     414    if( file->refcount )
    448415    {
    449416        printk("\n[PANIC] in %s : file refcount non zero\n", __FUNCTION__ );
     
    452419
    453420        kmem_req_t req;
    454         req.ptr   = file_ptr;
     421        req.ptr   = file;
    455422        req.type  = KMEM_VFS_FILE;
    456423        kmem_free( &req );
    457 }
    458 
    459 //////////////////////////////////////////////////////////////////////////////////////////
    460 //           File related functions
     424
     425}  // end vfs_file_destroy()
     426
     427
     428////////////////////////////////////////
     429void vfs_file_count_up( xptr_t file_xp )
     430{
     431    // get file cluster and local pointer
     432    cxy_t        file_cxy = GET_CXY( file_xp );
     433    vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
     434
     435    // atomically increment count
     436    hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->refcount ) , 1 );
     437}
     438
     439//////////////////////////////////////////
     440void vfs_file_count_down( xptr_t file_xp )
     441{
     442    // get file cluster and local pointer
     443    cxy_t        file_cxy = GET_CXY( file_xp );
     444    vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
     445
     446    // atomically decrement count
     447    hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->refcount ) , -1 );
     448}
     449
     450//////////////////////////////////////////////////////////////////////////////////////////
     451//           File access related functions
    461452//////////////////////////////////////////////////////////////////////////////////////////
    462453
     
    465456                          char     * path,
    466457                          uint32_t   flags,
    467                           xptr_t   * file_xp )
    468 {
    469     return 0;
    470 }
    471 
    472 ///////////////////////////////////
    473 uint32_t vfs_read( xptr_t   file_xp,
    474                    void   * buffer,
    475                    uint32_t size )
    476 {
    477     return 0;
    478 }
    479 
    480 ////////////////////////////////////
    481 uint32_t vfs_write( xptr_t   file_xp,
    482                     void   * buffer,
    483                     uint32_t size )
    484 {
    485     return 0;
    486 }
     458                  uint32_t   mode,
     459                          xptr_t   * new_file_xp,
     460                  uint32_t * new_file_id )
     461{
     462    error_t       error;
     463    xptr_t        inode_xp;     // extended pointer on target inode
     464    cxy_t         inode_cxy;    // inode cluster identifier       
     465    vfs_inode_t * inode_ptr;    // inode local pointer
     466    uint32_t      file_attr;    // file descriptor attributes
     467    uint32_t      lookup_mode;  // lookup working mode       
     468    xptr_t        file_xp;      // extended pointer on created file descriptor
     469    uint32_t      file_id;      // created file descriptor index in reference fd_array
     470
     471    // compute lookup working mode
     472    lookup_mode = VFS_LOOKUP_OPEN;
     473    if( (flags & O_DIR    )      )  lookup_mode |= VFS_LOOKUP_DIR;
     474    if( (flags & O_CREAT  )      )  lookup_mode |= VFS_LOOKUP_CREATE;
     475    if( (flags & O_EXCL   )      )  lookup_mode |= VFS_LOOKUP_EXCL;
     476 
     477    // compute attributes for the created file
     478    file_attr = 0;
     479    if( (flags & O_RDONLY ) == 0 )  file_attr |= FD_ATTR_READ_ENABLE;
     480    if( (flags & O_WRONLY ) == 0 )  file_attr |= FD_ATTR_WRITE_ENABLE;
     481    if( (flags & O_SYNC   )      )  file_attr |= FD_ATTR_SYNC;
     482    if( (flags & O_APPEND )      )  file_attr |= FD_ATTR_APPEND;
     483    if( (flags & O_CLOEXEC)      )  file_attr |= FD_ATTR_CLOSE_EXEC;
     484
     485    // get extended pointer on target inode
     486    error = vfs_lookup( cwd_xp , path , lookup_mode , &inode_xp );
     487
     488    if( error ) return error;
     489
     490    // get target inode cluster and local pointer
     491    inode_cxy = GET_CXY( inode_xp );
     492    inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp );
     493   
     494    // create a new file descriptor in cluster containing inode
     495    if( inode_cxy == local_cxy )      // target cluster is local
     496    {
     497        error = vfs_file_create( inode_ptr , file_attr , &file_xp );
     498    }
     499    else                              // target cluster is remote
     500    {
     501        rpc_vfs_file_create_client( inode_cxy , inode_ptr , file_attr , &file_xp , &error );
     502    }
     503
     504    if( error )  return error;
     505
     506    // allocate and register a new file descriptor index in reference cluster fd_array
     507    error = process_fd_register( file_xp , &file_id );
     508
     509    if( error ) return error;
     510
     511    // success
     512    *new_file_xp = file_xp;
     513    *new_file_id = file_id;
     514    return 0;
     515
     516}  // end vfs_open()
     517
     518/////////////////////////////////////
     519error_t vfs_move( bool_t   to_buffer,
     520                  xptr_t   file_xp,
     521                  void   * buffer,
     522                  uint32_t size )
     523{
     524    assert( ( file_xp != XPTR_NULL ) , __FUNCTION__ , "file_xp == XPTR_NULL" );
     525
     526    cxy_t              file_cxy;     // remote file descriptor cluster
     527    vfs_file_t       * file_ptr;     // remote file descriptor local pointer
     528    vfs_inode_type_t   inode_type;
     529    uint32_t           file_offset;  // current offset in file
     530    mapper_t         * mapper;
     531    error_t            error;
     532
     533    // get cluster and local pointer on remote file descriptor
     534    file_cxy  = GET_CXY( file_xp );
     535    file_ptr  = (vfs_file_t *)GET_PTR( file_xp );
     536
     537    // get inode type from remote file descriptor
     538    inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type   ) );
     539   
     540    // action depends on inode type
     541    if( inode_type == INODE_TYPE_FILE )
     542    {
     543        // get mapper pointer and file offset from file descriptor
     544        file_offset = hal_remote_lw( XPTR( file_cxy , &file_ptr->offset ) );
     545        mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
     546
     547        // move data between mapper and buffer
     548        if( file_cxy == local_cxy )
     549        {
     550            error = mapper_move( mapper,
     551                                 to_buffer,
     552                                 file_offset,
     553                                 buffer,
     554                                 size );
     555        }
     556        else
     557        {
     558            rpc_mapper_move_client( file_cxy,
     559                                    mapper,
     560                                    to_buffer,
     561                                    file_offset,
     562                                    buffer,
     563                                    size,
     564                                    &error );
     565        }
     566
     567        return error;
     568    }
     569    else if (inode_type == INODE_TYPE_DIR )
     570    {
     571        printk("\n[ERROR] in %s : inode is a directory", __FUNCTION__ );
     572        return EINVAL;
     573    }
     574    else if (inode_type == INODE_TYPE_DEV )
     575    {
     576        // TODO
     577        return 0;
     578    }
     579    else
     580    {
     581        printk("\n[PANIC] in %s : illegal inode type\n", __FUNCTION__ );
     582        hal_core_sleep();
     583        return -1;
     584    }
     585}  // end vfs_access()
    487586
    488587//////////////////////////////////////
     
    492591                   uint32_t * new_offset )
    493592{
    494     return 0;
    495 }
    496 
    497 //////////////////////////////////////
    498 error_t vfs_close( xptr_t     file_xp,
    499                    uint32_t * refcount )
    500 {
    501     return 0;
    502 }
     593    printk("\n[PANIC] %s non implemented\n", __FUNCTION__ );
     594    hal_core_sleep();
     595    return 0;
     596
     597    assert( ( file_xp != XPTR_NULL ) , __FUNCTION__ , "file_xp == XPTR_NULL" );
     598
     599}  // vfs_lseek()
     600
     601///////////////////////////////////
     602error_t vfs_close( xptr_t   file_xp,
     603                   uint32_t file_id )
     604{
     605    assert( (file_xp != XPTR_NULL) , __FUNCTION__ , "file_xp == XPTR_NULL" );
     606
     607    assert( (file_id < CONFIG_PROCESS_FILE_MAX_NR) , __FUNCTION__ , "illegal file_id" );
     608
     609    thread_t  * this    = CURRENT_THREAD;
     610    process_t * process = this->process;
     611
     612    // get cluster and local pointer on remote file descriptor
     613    cxy_t        file_cxy = GET_CXY( file_xp );
     614    vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
     615
     616    // get local pointer on local cluster manager
     617    cluster_t * cluster = LOCAL_CLUSTER;
     618
     619    // get owner process cluster and lpid
     620    cxy_t   owner_cxy  = CXY_FROM_PID( process->pid );
     621    lpid_t  lpid       = LPID_FROM_PID( process->pid );
     622
     623    // get extended pointers on copies root and lock
     624    xptr_t root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] );
     625    xptr_t lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
     626
     627    // take the lock protecting the copies
     628    remote_spinlock_lock( lock_xp );
     629
     630    // 1) loop on the process descriptor copies to cancel all fd_array[file_id] entries
     631    xptr_t  iter_xp;
     632    XLIST_FOREACH( root_xp , iter_xp )
     633    {
     634        xptr_t      process_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
     635        cxy_t       process_cxy = GET_CXY( process_xp );
     636        process_t * process_ptr = (process_t *)GET_PTR( process_xp );
     637
     638        xptr_t lock_xp  = XPTR( process_cxy , &process_ptr->fd_array.lock );
     639        xptr_t entry_xp = XPTR( process_cxy , &process_ptr->fd_array.array[file_id] );
     640
     641        // lock is required for atomic write of a 64 bits word
     642        remote_rwlock_wr_lock( lock_xp );
     643        hal_remote_swd( entry_xp , XPTR_NULL );
     644        remote_rwlock_wr_unlock( lock_xp );
     645
     646        hal_wbflush();
     647    }   
     648
     649    // 2) release memory allocated to file descriptor in remote cluster
     650    if( file_cxy == local_cxy )             // file cluster is local
     651    {
     652        vfs_file_destroy( file_ptr );
     653    }
     654    else                                    // file cluster is local
     655    {
     656        rpc_vfs_file_destroy_client( file_cxy , file_ptr );
     657    }
     658
     659    return 0;
     660
     661}  // end vfs_close()
    503662
    504663////////////////////////////////////
     
    506665                    char   * path )
    507666{
     667    printk("\n[PANIC] %s non implemented\n", __FUNCTION__ );
     668    hal_core_sleep();
     669    return 0;
     670}  // vfs_unlink()
     671
     672///////////////////////////////////////
     673error_t vfs_stat( xptr_t       file_xp,
     674                  vfs_stat_t * k_stat )
     675{
     676    printk("\n[PANIC] %s non implemented\n", __FUNCTION__ );
     677    hal_core_sleep();
     678    return 0;
     679}
     680
     681////////////////////////////////////////////
     682error_t vfs_readdir( xptr_t         file_xp,
     683                     vfs_dirent_t * k_dirent )
     684{
     685    printk("\n[PANIC] %s non implemented\n", __FUNCTION__ );
     686    hal_core_sleep();
    508687    return 0;
    509688}
    510689
    511690//////////////////////////////////////
    512 error_t vfs_stat( xptr_t       file_xp,
    513                   vfs_stat_t * stat )
    514 {
    515     return 0;
    516 }
    517 
    518 //////////////////////////////////////////////////////////////////////////////////////////
    519 //           Directory related functions
    520 //////////////////////////////////////////////////////////////////////////////////////////
    521 
    522 
    523 
    524 
    525 
    526 //////////////////////////////////////////////////////////////////////////////////////////
     691error_t vfs_mkdir( xptr_t     file_xp,
     692                   char     * path,
     693                   uint32_t   mode )
     694{
     695    printk("\n[PANIC] %s non implemented\n", __FUNCTION__ );
     696    hal_core_sleep();
     697    return 0;
     698}
     699
     700////////////////////////////////////
     701error_t vfs_rmdir( xptr_t   file_xp,
     702                   char   * path )
     703{
     704    printk("\n[PANIC] %s non implemented\n", __FUNCTION__ );
     705    hal_core_sleep();
     706    return 0;
     707}
     708
     709///////////////////////////////////
     710error_t vfs_chdir( xptr_t   cwd_xp,
     711                   char   * path )
     712{
     713    error_t           error;
     714    xptr_t            inode_xp;     // extended pointer on target inode
     715    cxy_t             inode_cxy;    // target inode cluster identifier       
     716    vfs_inode_t     * inode_ptr;    // target inode local pointer
     717    uint32_t          mode;         // lookup working mode       
     718    vfs_inode_type_t  inode_type;   // target inode type
     719
     720    // set lookup working mode
     721    mode = 0;
     722
     723    // get extended pointer on target inode
     724    error = vfs_lookup( cwd_xp , path , mode , &inode_xp );
     725
     726    if( error ) return error;
     727
     728    // get inode cluster and local pointer
     729    inode_cxy = GET_CXY( inode_xp );
     730    inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp );
     731
     732    // get inode type from remote file
     733    inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
     734
     735    if( inode_type != INODE_TYPE_DIR )
     736    {
     737        CURRENT_THREAD->errno = ENOTDIR;
     738        return -1;
     739    }
     740
     741    printk("\n[PANIC] %s non fully implemented\n", __FUNCTION__ );
     742    hal_core_sleep();
     743    return 0;
     744}
     745
     746///////////////////////////////////
     747error_t vfs_chmod( xptr_t   cwd_xp,
     748                   char   * path,
     749                   uint32_t rights )
     750{
     751    error_t           error;
     752    xptr_t            inode_xp;     // extended pointer on target inode
     753    cxy_t             inode_cxy;    // inode cluster identifier       
     754    vfs_inode_t     * inode_ptr;    // inode local pointer
     755    uint32_t          mode;         // lookup working mode
     756    vfs_inode_type_t  inode_type;   // target inode type
     757
     758    // set lookup working mode
     759    mode = 0;
     760 
     761    // get extended pointer on target inode
     762    error = vfs_lookup( cwd_xp , path , mode , &inode_xp );
     763
     764    if( error ) return error;
     765
     766    // get inode cluster and local pointer
     767    inode_cxy = GET_CXY( inode_xp );
     768    inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp );
     769   
     770    // get inode type from remote inode
     771    inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
     772
     773   
     774    printk("\n[PANIC] %s non fully implemented\n", __FUNCTION__ );
     775    hal_core_sleep();
     776    return 0;
     777}
     778
     779///////////////////////////////////
     780error_t vfs_mkfifo( xptr_t   cwd_xp,
     781                    char   * path,
     782                    uint32_t rights )
     783{
     784    printk("\n[PANIC] in %s : not implemented yet\n", __FUNCTION__ );
     785    hal_core_sleep();
     786    return 0;
     787}
     788
     789
     790
     791/////////////////////////////////////////////////////////////////////////////////////////r
    527792//            Inode Tree functions
    528793//////////////////////////////////////////////////////////////////////////////////////////
    529794
    530795//////////////////////////////////////////////////////////////////////////////////////////
    531 // This static function is used by the vfs_lookup() function.
     796// This function is used by the vfs_lookup() function.
    532797// It takes an extended pointer on a remote inode (parent directory inode),
    533798// and check access_rights violation for the calling thread.
     
    641906}
    642907
    643 ////////////////////////////////////////
    644 error_t vfs_lookup( xptr_t       cwd_xp,
    645                     char       * pathname,
    646                     uint32_t     client_uid,
    647                     uint32_t     client_gid,
    648                                         xptr_t     * inode_xp,
    649                     xptr_t     * ctx_xp )
     908//////////////////////////////////////////////
     909error_t vfs_lookup( xptr_t             cwd_xp,
     910                    char             * pathname,
     911                    uint32_t           mode,
     912                                        xptr_t           * inode_xp )
    650913{
    651914    char          name[CONFIG_VFS_MAX_NAME_LENGTH];   // one name in path
    652915
    653     xptr_t        parent_xp;    // extended pointer on parent inode
    654     cxy_t         parent_cxy;   // cluster for parentc inode
    655     vfs_inode_t * parent_ptr;   // local pointer on parent inode 
    656     xptr_t        child_xp;     // extended pointer on child inode
    657     cxy_t         child_cxy;    // cluster for child inode
    658     vfs_inode_t * child_ptr;    // local pointer on child inode 
    659     char        * current;      // current pointer on path
    660     char        * next;         // next value for current pointer   
    661     bool_t        last;         // true when the name is the last in path
    662     bool_t        found;        // true when a child has been found
    663     thread_t    * this;         // pointer on calling thread descriptor
    664     process_t   * process;      // pointer on calling process descriptor
    665     vfs_ctx_t   * ctx;          // parent inode context
    666     uint32_t      type;         // file system type of parent inode
    667     error_t       error;
     916    xptr_t             parent_xp;    // extended pointer on parent inode
     917    cxy_t              parent_cxy;   // cluster for parent inode
     918    vfs_inode_t      * parent_ptr;   // local pointer on parent inode 
     919    xptr_t             child_xp;     // extended pointer on child inode
     920    cxy_t              child_cxy;    // cluster for child inode
     921    vfs_inode_t      * child_ptr;    // local pointer on child inode 
     922    vfs_inode_type_t   inode_type;   // child inode type
     923    vfs_fs_type_t      fs_type;      // File system type
     924    vfs_ctx_t        * ctx_ptr;      // local pointer on FS context
     925    char             * current;      // current pointer on path
     926    char             * next;         // next value for current pointer   
     927    bool_t             last;         // true when the name is the last in path
     928    bool_t             found;        // true when a child has been found
     929    thread_t         * this;         // pointer on calling thread descriptor
     930    process_t        * process;      // pointer on calling process descriptor
     931    error_t            error;
    668932
    669933    this    = CURRENT_THREAD;
     
    687951    do
    688952    {
    689         // get cluster and local pointer for parent inode
    690         parent_cxy = GET_CXY( parent_xp );
    691         parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp );
    692        
    693         // get parent inode FS type
    694         ctx = (vfs_ctx_t *)(intptr_t)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) );
    695         type = ctx->type;
    696 
    697         // get one name from path
     953        // get one name from path and the last flag
    698954        vfs_get_name_from_path( current , name , &next , &last );
    699955
     
    708964            vfs_inode_remote_unlock( parent_xp );
    709965
    710             // insert a new dentry/inode in parent inode
    711             error = vfs_add_child_in_parent( type , parent_xp , name , &child_xp );
     966            // get cluster and local pointer on parent inode
     967            parent_cxy = GET_CXY( parent_xp );
     968            parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp );
     969
     970            // get parent inode FS type
     971            ctx_ptr = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) );
     972            fs_type = ctx_ptr->type;
     973
     974            // get child inode type
     975            if( (last == false) || (mode & VFS_LOOKUP_DIR) ) inode_type = INODE_TYPE_DIR;
     976            else                                             inode_type = INODE_TYPE_FILE;
     977
     978            // insert a child dentry/inode in parent inode
     979            error = vfs_add_child_in_parent( inode_type,
     980                                             fs_type,
     981                                             parent_xp,
     982                                             name,
     983                                             &child_xp );
    712984
    713985            if( error )
     
    723995
    724996        // check access rights
    725         error = vfs_access_denied( child_xp,
    726                                    client_uid,
    727                                    client_gid );
    728         if( error )
    729         {
    730             printk("\n[ERROR] in %s : permission denied for %s\n", __FUNCTION__ , name );
    731             return EACCES;
    732         }
     997        // error = vfs_access_denied( child_xp,
     998        //                            client_uid,
     999        //                            client_gid );
     1000        // if( error )
     1001        // {
     1002        //     printk("\n[ERROR] in %s : permission denied for %s\n", __FUNCTION__ , name );
     1003        //     return EACCES;
     1004        // }
    7331005
    7341006        // take lock on child inode if not last
     
    7531025    // return searched pointers
    7541026    *inode_xp = child_xp;
    755     *ctx_xp   = (xptr_t)hal_remote_lwd( XPTR( child_cxy , &child_ptr->ctx ) );
    7561027
    7571028    return 0;
     
    7701041        uint32_t     count;       // number of characters written in buffer
    7711042        uint32_t     index;       // slot index in buffer
    772     xptr_t       inode_xp;  // extended pointer on   
     1043    xptr_t       inode_xp;    // extended pointer on   
    7731044
    7741045    // implementation note:
     
    8291100}  // end vfs_get_path()
    8301101
    831 ///////////////////////////////////////////////
    832 error_t vfs_add_child_in_parent( uint32_t type,
    833                                  xptr_t   parent_xp,
    834                                  char   * name,   
    835                                  xptr_t * child_xp )
    836 {
    837     xptr_t     dentry_xp;  // extended pointer on created dentry
    838     xptr_t     inode_xp;   // extended pointer on created inode
    839     error_t    error;
     1102///////////////////////////////////////////////////////////////
     1103error_t vfs_add_child_in_parent( vfs_inode_type_t   inode_type,
     1104                                 vfs_fs_type_t      fs_type,
     1105                                 xptr_t             parent_xp,
     1106                                 char             * name,
     1107                                 xptr_t           * child_xp )
     1108{
     1109    error_t         error;
     1110    xptr_t          dentry_xp;   // extended pointer on created dentry
     1111    xptr_t          inode_xp;    // extended pointer on created inode
     1112    cxy_t           parent_cxy;  // parent inode cluster identifier
     1113    vfs_inode_t   * parent_ptr;  // parent inode local pointer
     1114    vfs_ctx_t     * parent_ctx;  // parent inode context local pointer
    8401115
    8411116    // get parent inode cluster and local pointer
    842     cxy_t         parent_cxy = GET_CXY( parent_xp );
    843     vfs_inode_t * parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp );
     1117    parent_cxy = GET_CXY( parent_xp );
     1118    parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp );
     1119
     1120    // get parent inode context local pointer
     1121    parent_ctx = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) );
    8441122
    8451123    // create dentry
    8461124    if( parent_cxy == local_cxy )      // parent cluster is the local cluster
    8471125    {
    848         error = vfs_dentry_create( type,
     1126        error = vfs_dentry_create( fs_type,
    8491127                                   name,
    8501128                                   parent_ptr,
     
    8541132    {
    8551133        rpc_vfs_dentry_create_client( parent_cxy,
    856                                       type,
     1134                                      fs_type,
    8571135                                      name,
    8581136                                      parent_ptr,
     
    8871165    {
    8881166        error = vfs_inode_create( dentry_xp,
    889                                   type,
     1167                                  fs_type,
     1168                                  inode_type,
    8901169                                  attr,
    8911170                                  mode,
     
    8981177        rpc_vfs_inode_create_client( child_cxy,
    8991178                                     dentry_xp,
    900                                      type,
     1179                                     fs_type,
     1180                                     inode_type,
    9011181                                     attr,
    9021182                                     mode,
     
    9251205
    9261206
     1207
     1208
     1209//////////////////////////////////////////////////////////////////////////////////////////
     1210//            Mapper related functions
     1211//////////////////////////////////////////////////////////////////////////////////////////
     1212
     1213////////////////////////////////////////////////
     1214error_t vfs_move_page_to_mapper( page_t * page )
     1215{
     1216    error_t         error = 0;
     1217
     1218    assert( (page != NULL) , __FUNCTION__ , "page pointer is NULL\n" );
     1219
     1220    mapper_t * mapper = page->mapper;
     1221
     1222    assert( (mapper != NULL) , __FUNCTION__ , "no mapper for page\n" );
     1223
     1224    // get FS type
     1225    vfs_fs_type_t fs_type = mapper->inode->ctx->type;
     1226
     1227    // update mapper if permitted by file system type
     1228    if( fs_type == FS_TYPE_FATFS )
     1229    {
     1230        // get mapper lock in WRITE_MODE
     1231        rwlock_wr_lock( &mapper->lock );
     1232
     1233        error = fatfs_read_page( page );
     1234
     1235        // release mapper lock
     1236        rwlock_wr_unlock( &mapper->lock );
     1237    }
     1238    else if( fs_type == FS_TYPE_RAMFS )
     1239    {
     1240        assert( false , __FUNCTION__ , "should not be called for RAMFS\n" );
     1241    }
     1242    else if( fs_type == FS_TYPE_DEVFS )
     1243    {
     1244        assert( false , __FUNCTION__ , "should not be called for DEVFS\n" );
     1245    }
     1246    else
     1247    {
     1248        assert( false , __FUNCTION__ , "undefined file system type\n" );
     1249    }
     1250
     1251    return error;
     1252
     1253}  // end vfs_move_page_to_mapper()
     1254
     1255//////////////////////////////////////////////////
     1256error_t vfs_move_page_from_mapper( page_t * page )
     1257{
     1258    error_t         error = 0;
     1259
     1260    assert( (page != NULL) , __FUNCTION__ , "page pointer is NULL\n" );
     1261
     1262    mapper_t * mapper = page->mapper;
     1263
     1264    assert( (mapper != NULL) , __FUNCTION__ , "no mapper for page\n" );
     1265
     1266    // get FS type
     1267    vfs_fs_type_t  fs_type = mapper->inode->ctx->type;
     1268
     1269    // update file system if permitted by file system type
     1270    if( fs_type == FS_TYPE_FATFS )
     1271    {
     1272            if( page_is_flag( page , PG_DIRTY ) )
     1273            {
     1274            // get mapper lock in READ_MODE
     1275            rwlock_rd_lock( &mapper->lock );
     1276
     1277            error = fatfs_write_page( page );
     1278
     1279            // release mapper lock from READ_MODE
     1280            rwlock_rd_unlock( &mapper->lock );
     1281
     1282            // clear dirty bit if success
     1283                    if( error == 0 ) page_undo_dirty( page );
     1284         }
     1285    }
     1286    else if( fs_type == FS_TYPE_RAMFS )
     1287    {
     1288        assert( false , __FUNCTION__ , "should not be called for RAMFS\n" );
     1289    }
     1290    else if( fs_type == FS_TYPE_DEVFS )
     1291    {
     1292        assert( false , __FUNCTION__ , "should not be called for DEVFS\n" );
     1293    }
     1294    else
     1295    {
     1296        assert( false , __FUNCTION__ , "undefined file system type\n" );
     1297    }
     1298       
     1299    return error;
     1300
     1301}  // end vfs_move_page_from_mapper()
     1302
     1303
  • trunk/kernel/vfs/vfs.h

    r14 r23  
    22 * vfs.h - Virtual File System definition.
    33 *
    4  * Author  Mohamed Lamine Karaoui (2015)
    5  *         Alain Greiner (2016)
     4 * Author  Mohamed Lamine Karaoui (2014,2015)
     5 *         Alain Greiner (2016,2017)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    4242#include <fatfs.h>
    4343#include <ramfs.h>
     44#include <devfs.h>
    4445
    4546/****  Forward declarations  ***/
     
    6364struct device_s;
    6465struct vseg_s;
    65 
    66 /*********************************************************************************************
    67  * This defines the various Flags arguments for an open() or opendir() system call.
    68  ********************************************************************************************/
    69 
    70 #define VFS_O_APPEND         0x00080000
    71 #define VFS_O_RDONLY         0x00100000
    72 #define VFS_O_WRONLY         0x00200000
    73 #define VFS_O_RDWR           0x00300000
    74 #define VFS_O_CREATE         0x00400000
    75 #define VFS_O_EXCL           0x00800000
    76 #define VFS_O_TRUNC          0x01000000
    77 #define VFS_O_SYNC               0x08000000
    78 
    79 /*********************************************************************************************
    80  * This defines the various types of command for an lseek() system call.
    81  ********************************************************************************************/
    82 
    83 #define VFS_SEEK_SET         0
    84 #define VFS_SEEK_CUR         1
    85 #define VFS_SEEK_END         2
    86 
    87 /*********************************************************************************************
    88  * TODO : the following flags were defined in the vfs-params.h file...
    89  *        ... and must be documented. [AG]
    90  ********************************************************************************************/
    91 
    92 
    93 //////////////////////////////////////
    94 ///    keep these flags compact    ///
    95 //////////////////////////////////////
    96 #define VFS_REGFILE          0x0000000
    97 #define VFS_DIR              0x0000001
    98 #define VFS_FIFO             0x0000002
    99 #define VFS_DEV_CHR          0x0000004
    100 #define VFS_DEV_BLK          0x0000008
    101 #define VFS_DEV              0x000000C
    102 #define VFS_SOCK             0x0000010
    103 #define VFS_SYMLNK           0x0000020
    104 //////////////////////////////////////
    105 
    106 #define VFS_RD_ONLY          0x0000040
    107 #define VFS_SYS              0x0000080
    108 #define VFS_ARCHIVE          0x0000100
    109 #define VFS_PIPE             0x0000200
    110 
    111 #define VFS_IFMT             0x0170000
    112 #define VFS_IFSOCK           0x0140000
    113 #define VFS_IFLNK            0x0120000
    114 #define VFS_IFREG            0x0100000
    115 #define VFS_IFBLK            0x0060000
    116 #define VFS_IFDIR            0x0040000
    117 #define VFS_IFCHR            0x0020000
    118 #define VFS_IFIFO            0x0010000
    119 
    120 #define VFS_ISUID            0x0004000
    121 #define VFS_ISGID            0x0002000
    122 #define VFS_ISVTX            0x0001000
     66struct page_s;
     67
     68
     69/******************************************************************************************
     70 * These flags are used to define the working mode of the vfs_lookup() function. 
     71 *****************************************************************************************/
     72
     73#define VFS_LOOKUP_DIR      0x01     /* the searched inode is a directory                */
     74#define VFS_LOOKUP_OPEN         0x02     /* the search is for an open/opendir                */
     75#define VFS_LOOKUP_PARENT       0x04     /* return the parent inode (not the inode itself)   */
     76#define VFS_LOOKUP_CREATE   0x10     /* file must be created if missing                  */
     77#define VFS_LOOKUP_EXCL     0x20     /* file cannot previously exist                     */   
     78
     79/******************************************************************************************
     80 * This define the masks for the POSIX access rights to inodes
     81 *****************************************************************************************/
     82
     83#define VFS_ISUID                0x0004000
     84#define VFS_ISGID                0x0002000
     85#define VFS_ISVTX                0x0001000
    12386
    12487#define VFS_IRWXU            0x0000700
     
    12689#define VFS_IWUSR            0x0000200
    12790#define VFS_IXUSR            0x0000100
     91
    12892#define VFS_IRWXG            0x0000070
    12993#define VFS_IRGRP            0x0000040
    13094#define VFS_IWGRP            0x0000020
    13195#define VFS_IXGRP            0x0000010
     96
    13297#define VFS_IRWXO            0x0000007
    13398#define VFS_IROTH            0x0000004
     
    139104#define VFS_IEXEC            VFS_IXUSR
    140105
    141 #define VFS_SET(state,flag)    (state) |= (flag)
    142 #define VFS_IS(state,flag)     (state) & (flag)
    143 #define VFS_CLEAR(state,flag)  (state) &= ~(flag)
    144 
    145 
    146 /* Lookup flags */
    147 #define VFS_LOOKUP_FILE         0x1
    148 #define VFS_LOOKUP_LAST         0x2
    149 #define VFS_LOOKUP_OPEN         0x4
    150 #define VFS_LOOKUP_RESTART      0x8
    151 #define VFS_LOOKUP_RETRY        0x10
    152 #define VFS_LOOKUP_PARENT       0x20
    153 #define VFS_LOOKUP_HELD         0x40
    154 
    155 /* Context flags*/
    156 #define VFS_FS_LOCAL            0x1
    157 #define VFS_FS_USE_MAPPER       0x2
    158 
    159 
    160 
     106
     107/******************************************************************************************
     108 * This structure defines informations common to all inodes and dentries
     109 * of a given file system. As it is declared a global variable in the kdata segment,
     110 * it is replicated in all clusters and handled as private by each OS intance.
     111 *****************************************************************************************/
     112
     113typedef enum
     114{
     115        FS_TYPE_DEVFS = 0,
     116        FS_TYPE_FATFS = 1,
     117        FS_TYPE_RAMFS = 2,
     118 
     119        FS_TYPES_NR   = 3,
     120}
     121vfs_fs_type_t;
     122
     123typedef enum
     124{
     125    CTX_ATTR_READ_ONLY    = 0x01,            /*! write access prohibited                 */
     126    CTX_ATTR_SYNC         = 0x10,            /*! synchronise FS on each write            */
     127}
     128vfs_ctx_attr_t;
     129
     130typedef struct vfs_ctx_s
     131{
     132        vfs_fs_type_t  type;                     /*! File System type                        */
     133        uint32_t           attr;                     /*! global attributes for all files in FS   */
     134        uint32_t       count;                    /*! total number of clusters on device      */
     135        uint32_t       blksize;                  /*! device cluster size (bytes)             */
     136        xptr_t         root_xp;                  /*! extended pointer on root inode          */
     137    spinlock_t     lock;                     /*! lock protecting inum allocator          */
     138    uint32_t       bitmap[BITMAP_SIZE(CONFIG_VFS_MAX_INODES)];  /* inum allocator        */
     139    void         * extend;                   /*! FS specific context extension           */
     140}
     141vfs_ctx_t;
    161142
    162143/******************************************************************************************
     
    166147 * The <parent> inode is unique for a directory (not hard links for directories).
    167148 * For a file, the parent field points to the first dentry who created this inode.
    168  * Syncronisation:
     149 * Syncrhonisation:
    169150 * - the main_lock (spinlock) is used during the inode tree traversal or for inode
    170151 *   modification (add/remove children).
     
    172153 *   in the mapper.
    173154 * - the mapper lock (rwlock) is only used during the radix tree traversal to return
    174  *   to return the relevant page for red/write.
    175  *****************************************************************************************/
     155 *   the relevant page for read/write.
     156 *****************************************************************************************/
     157
     158/* this enum define the VFS inode types values */
    176159
    177160typedef enum   
    178161{
    179     INODE_TYPE_NORMAL,                 /*! file or directory                            */
    180     INODE_TYPE_PIPE,                   /*! POSIX pipe                                   */
    181     INODE_TYPE_SOCKET,                 /*! POSIX socket                                 */
    182     INODE_TYPE_DEV,                    /*! peripheral channel                           */
     162    INODE_TYPE_FILE    =     0x001,      /*! file                                        */
     163    INODE_TYPE_DIR     =     0x002,      /*! directory                                   */
     164    INODE_TYPE_FIFO    =     0x004,      /*! POSIX named pipe                            */
     165    INODE_TYPE_PIPE    =     0x008,      /*! POSIX anonymous pipe                        */
     166    INODE_TYPE_SOCKET  =     0x010,      /*! POSIX socket                                */
     167    INODE_TYPE_DEV     =     0x020,      /*! character peripheral channel                */
     168    INODE_TYPE_SYML    =     0x080,      /*! symbolic link                               */
    183169}
    184170vfs_inode_type_t;
    185171
     172/* this enum define the VFS inode attributes values */
     173
    186174typedef enum
    187175{
    188     INODE_ATTR_DIRTY  = 0x01,
    189     INODE_ATTR_DIR    = 0x02,
    190     INODE_ATTR_INLOAD = 0x04,
    191     INODE_ATTR_NEW    = 0x08,
     176    INODE_ATTR_DIRTY   =     0x01,       /* modified versus the value on device          */
     177    INODE_ATTR_INLOAD  =     0x04,       /* loading from device in progress              */
     178    INODE_ATTR_NEW     =     0x08,       /* not saved on device yet                      */
    192179}
    193180vfs_inode_attr_t;
     
    195182typedef struct vfs_inode_s
    196183{
    197         struct vfs_ctx_s      * ctx;         /*! Rlocal pointer on FS context                */
     184        struct vfs_ctx_s      * ctx;         /*! local pointer on FS context                 */
    198185    uint32_t                gc;          /*! generation counter                          */
    199186        uint32_t                inum;        /*! inode identifier (unique in file system)    */
    200187        uint32_t                attr;        /*! inode attributes (see above)                */
    201         uint32_t                type;        /*! inode type (see above)                      */
     188        vfs_inode_type_t        type;        /*! inode type (see above)                      */
    202189        uint32_t                size;        /*! number of bytes                             */
    203190        uint32_t                links;       /*! number of alias dentry                      */
    204191        uid_t                   uid;         /*! user owner identifier                       */
    205192        gid_t                   gid;         /*! group owner identifier                      */
    206     uint32_t                mode;        /*! access mode                                 */
     193    uint32_t                rights;      /*! access rights                               */
    207194        uint32_t                    refcount;    /*! reference counter (all pointers)            */
    208195        xptr_t                  parent_xp;   /*! extended pointer on parent dentry           */
    209         xhtab_t                 children;    /*! embedded htab of dir entries (for dir type) */
     196        xhtab_t                 children;    /*! embedded xhtab of vfs_dentry_t              */
    210197        remote_rwlock_t         data_lock;   /*! protect read/write to data and to size      */
    211198        remote_spinlock_t       main_lock;   /*! protect inode tree traversal and modifs     */
    212         xlist_entry_t           xlist;       /*! member of set of inodes in same cluster     */
     199        list_entry_t            list;        /*! member of set of inodes in same cluster     */
    213200        xlist_entry_t           wait_root;   /*! root of threads waiting on this inode       */
    214201        struct vfs_inode_op_s * op;          /*! TODO ???                                    */
     
    240227
    241228/******************************************************************************************
    242  * This structure describes an open file/directory for a given process.
     229 * This file structure describes an open file/directory for a given process.
    243230 * It is not replicated, and is dynamically allocated in the cluster that contains
    244231 * the inode, when a thread makes an open() or opendir() system call.
    245  *****************************************************************************************/
    246 
     232 * It cannot exist a file structure without an inode structure.
     233 * Aa the fd_array (containing extended pointers on the open file descriptors)
     234 * is replicated in all process descriptors, we need a references counter.
     235 *****************************************************************************************/
    247236
    248237typedef enum
    249238{
    250     FD_ATTR_READ_ENABLE  = 0x01,       /*! read access possible                         */
    251     FD_ATTR_WRITE_ENABLE = 0x02,       /*! write access possible                        */
    252     FD_ATTR_APPEND       = 0x04,       /*! append on each write                         */
    253     FD_ATTR_CLOSE_EXEC   = 0x08,       /*! close file on exec                           */
    254     FD_ATTR_SYNC         = 0x10,       /*! synchronise FS on each write                 */
    255     FD_ATTR_IS_DIR       = 0x20,       /*! this is a directory                          */
    256 }
    257 vfs_fd_attr_t;
     239    FD_ATTR_READ_ENABLE    = 0x01,     /*! read access possible                         */
     240    FD_ATTR_WRITE_ENABLE   = 0x02,     /*! write access possible                        */
     241    FD_ATTR_APPEND         = 0x04,     /*! append on each write                         */
     242    FD_ATTR_CLOSE_EXEC     = 0x08,     /*! close file on exec                           */
     243    FD_ATTR_SYNC           = 0x10,     /*! synchronise FS on each write                 */
     244    FD_ATTR_IS_DIR         = 0x20,     /*! this is a directory                          */
     245}
     246vfs_file_attr_t;
    258247
    259248typedef struct vfs_file_s
    260249{
     250        struct vfs_ctx_s      * ctx;        /*! local pointer on FS context.                 */
    261251        uint32_t                gc;         /*! generation counter                           */
    262         uint32_t                type;       /*! see above                                    */
    263         uint32_t                attr;       /*! see above                                    */
     252        vfs_file_attr_t         attr;       /*! file attributes bit vector (see above)       */
     253        vfs_inode_type_t        type;       /*! same type as inode                           */
    264254        uint32_t                offset;     /*! seek position in file                        */
    265         uint32_t                refcount;   /*! all pointers on this file                    */
    266         remote_rwlock_t       lock;       /*! protect offset modifications                 */
     255        uint32_t                refcount;   /*! all pointers on this file descriptor         */
     256        remote_rwlock_t         lock;       /*! protect offset modifications                 */
    267257        struct mapper_s       * mapper;     /*! associated file cache                        */
    268258        struct vfs_inode_s    * inode;      /*! local pointer on associated inode            */
    269         struct vfs_ctx_s      * ctx;        /*! file system features                         */
    270         struct vfs_file_op_s  * op;         /*! local set of function pointers               */
     259        void                  * extend;     /*! FS specific extension                        */
    271260}
    272261vfs_file_t;
    273262
    274263/******************************************************************************************
    275  * This structure defines informations common to all inodes and dentries
    276  * of a given file system. As it is declared a global variable in the kdata segment,
    277  * it is replicated in all clusters and handled as private by each OS intance.
    278  *****************************************************************************************/
    279 
    280 typedef enum
    281 {
    282         FS_TYPE_SYSFS = 0,
    283         FS_TYPE_DEVFS = 1,
    284         FS_TYPE_FATFS = 2,
    285         FS_TYPE_RAMFS = 3,
    286  
    287         FS_TYPES_NR   = 4,
    288 }
    289 vfs_types_t;
    290 
    291 typedef enum
    292 {
    293     CTX_ATTR_READ_ONLY    = 0x01,       /*! read access possible                         */
    294     CTX_ATTR_SYNC         = 0x10,       /*! synchronise FS on each write                 */
    295 }
    296 vfs_ctx_attr_t;
    297 
    298 typedef struct vfs_ctx_s
    299 {
    300         uint32_t                      type;          /*! File System type                        */
    301         uint32_t                      attr;          /*! global attributes for all files in FS   */
    302         uint32_t                  count;         /*! number of clusters                      */
    303         uint32_t                  blksize;       /*! cluster size                            */
    304     xptr_t                    ioc_xp;        /*! extended pointer on IOC device          */
    305         xptr_t                    root_xp;       /*! extended pointer on root inode          */
    306 
    307     spinlock_t                lock;          /*! lock protecting inum allocator          */
    308         BITMAP( inum , CONFIG_VFS_MAX_INODES );  /*! inum allocator                          */
    309 
    310     void                    * extend;        /*! FS specific context extension           */
    311 }
    312 vfs_ctx_t;
    313 
    314 /******************************************************************************************
    315  * This structure define the informations associated to a given file descriptor,
    316  * that are returned by the vfs_stat() function.
     264 * This structure define the informations associated to a file descriptor,
     265 * returned to user space by the stat() system call.
    317266 *****************************************************************************************/
    318267
     
    335284vfs_stat_t;
    336285
    337 
    338 
    339 
    340 
    341 
    342 /******************************************************************************************
    343  * This structure defines the set of operations that can be done on a VFS context.
    344  * TODO A quoi cela sert-il ? [AG]
    345  *****************************************************************************************/
    346 
    347 typedef error_t (vfs_create_context_t)  ( vfs_ctx_t * context );
    348 typedef error_t (vfs_destroy_context_t) ( vfs_ctx_t * context );
    349 typedef error_t (vfs_read_root_t)       ( vfs_ctx_t * context , vfs_inode_t * root );
    350 typedef error_t (vfs_reply_root_t)      ( vfs_ctx_t * context , vfs_inode_t * root );
    351 typedef error_t (vfs_write_root_t)      ( vfs_ctx_t * context , vfs_inode_t * root );
    352 
    353 struct vfs_ctx_op_s
    354 {
    355         vfs_create_context_t  * create;      /*! allocate memory and initialize a context   */
    356         vfs_destroy_context_t * destroy;     /*! release memory allocated to a context      */
    357         vfs_read_root_t       * read_root;   /*! TODO                                       */
    358         vfs_reply_root_t      * repli_root;  /*! TODO                                       */
    359         vfs_write_root_t      * write_root;  /*! TODO                                       */
    360 }
    361 vfs_ctx_op_t;
    362 
    363 /******************************************************************************************
    364  * This structure defines the set of operations that can be done on a VFS inode.
    365  * TODO A quoi cela sert-il ? [AG]
    366  *****************************************************************************************/
    367 
    368 typedef error_t (vfs_init_inode_t)    ( vfs_inode_t * inode );
    369 typedef error_t (vfs_create_inode_t)  ( vfs_inode_t * parent , vfs_dentry_t  * dentry );
    370 typedef error_t (vfs_lookup_inode_t)  ( vfs_inode_t * parent , vfs_dentry_t  * dentry );
    371 typedef error_t (vfs_write_inode_t)   ( vfs_inode_t * inode );
    372 typedef error_t (vfs_release_inode_t) ( vfs_inode_t * inode );
    373 typedef error_t (vfs_unlink_inode_t)  ( vfs_inode_t * parent , vfs_dentry_t  * dentry , uint32_t flags );
    374 typedef error_t (vfs_stat_inode_t)    ( vfs_inode_t * inode );
    375 typedef error_t (vfs_trunc_inode_t)   ( vfs_inode_t * inode );
    376 typedef error_t (vfs_delete_inode_t)  ( vfs_inode_t * inode );
    377 
    378 typedef struct vfs_inode_op_s
    379 {
    380         vfs_init_inode_t    * init;     /*! initialise inode from scratch                    */
    381         vfs_create_inode_t  * create;   /*! allocate memory for one inode                    */
    382         vfs_lookup_inode_t  * lookup;   /*! get one directory entry by name                  */
    383         vfs_write_inode_t   * write;    /*! update the device from the inode                 */
    384         vfs_release_inode_t * release;  /*! reset one inode and release associated objects   */
    385         vfs_unlink_inode_t  * unlink;   /*! unlink a directory entry from parent inode       */
    386         vfs_delete_inode_t  * delete;   /*! release memory allocated to inode when count = 0 */
    387         vfs_stat_inode_t    * stat;     /*! TODO                                             */
    388         vfs_trunc_inode_t   * trunc;    /*! change the size of a file                        */
    389 }
    390 vfs_inode_op_t;
    391 
    392 /******************************************************************************************
    393  * This structure defines the set of operations that can be done on a VFS dentry.
    394  * TODO A quoi cela sert-il ? [AG]
    395  *****************************************************************************************/
    396 
    397 typedef error_t (vfs_compare_dentry_t) ( char * first , char * second );
    398 
    399 typedef struct vfs_dentry_op_s
    400 {
    401         vfs_compare_dentry_t * compare;
    402 }
    403 vfs_dentry_op_t;
    404 
    405 /******************************************************************************************
    406  * This structure defines the set of operations that can be done on a VFS file. 
    407  * TODO A quoi cela sert-il ? [AG]
    408  *****************************************************************************************/
    409 
    410 typedef error_t (vfs_open_file_t)    ( vfs_file_t * file , void * priv );
    411 typedef error_t (vfs_read_file_t)    ( vfs_file_t * file , char * buffer );
    412 typedef error_t (vfs_write_file_t)   ( vfs_file_t * file , char * buffer );
    413 typedef error_t (vfs_lseek_file_t)   ( vfs_file_t * file );
    414 typedef error_t (vfs_close_file_t)   ( vfs_file_t * file );
    415 typedef error_t (vfs_release_file_t) ( vfs_file_t * file );
    416 typedef error_t (vfs_read_dir_t)     ( vfs_file_t * file );
    417 typedef error_t (vfs_mmap_file_t)    ( vfs_file_t * file , struct vseg_s * vseg );
    418 typedef error_t (vfs_munmap_file_t)  ( vfs_file_t * file , struct vseg_s * vseg );
    419 
    420 typedef struct vfs_file_op_s
    421 {
    422         vfs_open_file_t    * open;
    423         vfs_read_file_t    * read;
    424         vfs_write_file_t   * write;
    425         vfs_lseek_file_t   * lseek;
    426         vfs_read_dir_t     * readdir;
    427         vfs_close_file_t   * close;
    428         vfs_release_file_t * release;
    429         vfs_mmap_file_t    * mmap;
    430         vfs_munmap_file_t  * munmap;
    431 }
    432 vfs_file_op_t;
    433 
    434 
    435 
     286/*********************************************************************************************
     287 * This structure defines the information associated to a directory entry,
     288 * returned to user space by the readdir() system call.
     289 ********************************************************************************************/
     290
     291typedef struct vfs_dirent_s
     292{
     293    uint32_t    inum;                               /*! inode identifier                    */
     294    uint32_t    type;                               /*! inode type                          */
     295    char        name[CONFIG_VFS_MAX_NAME_LENGTH];   /*! dentry name                         */
     296}
     297vfs_dirent_t;
    436298
    437299
     
    441303/*****************************************************************************************/
    442304
    443 /******************************************************************************************
    444  * This function initializes the Virtual File System.     
    445  *****************************************************************************************/
    446 void vfs_init();
    447 
    448 /******************************************************************************************
    449  * This function mount a given file system type for a given process.     
     305
     306/******************************************************************************************
     307 * This function mount a given file system type for a given process TODO.     
    450308 *****************************************************************************************/
    451309error_t vfs_mount_fs_root( struct device_s  * device,
     
    482340
    483341
    484 /*****************************************************************************************/
    485 /************************ File Descriptor related functions ******************************/
     342
     343/*****************************************************************************************/
     344/********************* Inode related functions *******************************************/
     345/*****************************************************************************************/
     346
     347/******************************************************************************************
     348 * This function allocates memory from local cluster for an inode descriptor and the
     349 * associated mapper. It initialise these descriptors from arguments values.
     350 * The parent dentry must have been previously created.
     351 * If the client thread is not running in the cluster containing this inode,
     352 * it must use the rpc_vfs_inode_create_client() function.
     353 ******************************************************************************************
     354 * @ dentry_xp  : extended pointer on associated dentry (in parent inode cluster).
     355 * @ fs_type    : file system type.
     356 * @ inode_type : inode type.
     357 * @ attr       : inode attributes.
     358 * @ rights     : inode access rights.
     359 * @ uid        : user owner ID.
     360 * @ gid        : group owner ID.
     361 * @ inode_xp   : [out] buffer for extended pointer on created inode.
     362 * # return 0 if success / return ENOMEM or EINVAL if error.
     363 *****************************************************************************************/
     364error_t vfs_inode_create( xptr_t            dentry_xp,
     365                          vfs_fs_type_t     fs_type,
     366                          vfs_inode_type_t  inode_type,
     367                          uint32_t          attr,
     368                          uint32_t          rights,
     369                          uid_t             uid,
     370                          gid_t             gid,
     371                          xptr_t          * inode_xp );
     372
     373/******************************************************************************************
     374 * This function releases memory allocated to an inode descriptor.
     375 * It must be executed by a thread running in the cluster containing the inode,
     376 * and the inode refcount must be zero.
     377 * If the client thread is not running in the owner cluster, it must use the
     378 * rpc_vfs_inode_destroy_client() function.
     379 ******************************************************************************************
     380 * @ inode  : local pointer on inode descriptor.
     381 *****************************************************************************************/
     382void vfs_inode_destroy( vfs_inode_t *  inode ); 
     383
     384/******************************************************************************************
     385 * This function atomically increment/decrement the inode refcount.
     386 * It can be called by any thread running in any cluster.
     387 *****************************************************************************************/
     388void vfs_inode_remote_up( xptr_t  inode_xp );
     389void vfs_inode_remote_down( xptr_t  inode_xp );
     390
     391/******************************************************************************************
     392 * This function returns the <size> of a file/dir from a remote inode,
     393 * taking the remote_rwlock protecting <size> in READ_MODE.
     394 *****************************************************************************************
     395 * @ inode_xp  : extended pointer on the remote inode.
     396 * @ return the current size.
     397 *****************************************************************************************/
     398uint32_t vfs_inode_get_size( xptr_t inode_xp );
     399
     400/******************************************************************************************
     401 * This function set the <size> of a file/dir to a remote inode,
     402 * taking the remote_rwlock protecting <size> in WRITE_MODE.
     403 *****************************************************************************************
     404 * @ inode_xp  : extended pointer on the remote inode.
     405 * @ size      : value to be written.
     406 *****************************************************************************************/
     407void vfs_inode_set_size( xptr_t   inode_xp,
     408                         uint32_t size );
     409
     410/******************************************************************************************
     411 * This function takes the main lock of a remote inode.
     412 * This lock protect all inode fiels, including the children dentries.
     413 *****************************************************************************************
     414 * @ inode_xp  : extended pointer on the remote inode.
     415 *****************************************************************************************/
     416void vfs_inode_remote_lock( xptr_t inode_xp );
     417
     418/******************************************************************************************
     419 * This function releases the main lock of a remote inode.
     420 * This lock protect all inode fiels, including the children dentries.
     421 *****************************************************************************************
     422 * @ inode_xp  : extended pointer on the remote inode.
     423 *****************************************************************************************/
     424void vfs_inode_remote_unlock( xptr_t inode_xp );
     425
     426
     427
     428
     429/******************************************************************************************
     430 * This function TODO                                                         
     431 *****************************************************************************************/
     432error_t vfs_inode_hold( vfs_inode_t * inode,
     433                        uint32_t      gc );
     434
     435/******************************************************************************************
     436 * This function TODO                                                         
     437 *****************************************************************************************/
     438error_t vfs_inode_trunc( vfs_inode_t * inode );
     439
     440/******************************************************************************************
     441 * This function TODO                                                         
     442 *****************************************************************************************/
     443error_t vfs_inode_link( vfs_inode_t * inode,
     444                        uint32_t      igc );
     445
     446/******************************************************************************************
     447 * This function TODO                                                         
     448 *****************************************************************************************/
     449error_t vfs_inode_unlink( vfs_inode_t * inode );
     450
     451/******************************************************************************************
     452 * This function TODO                                                         
     453 *****************************************************************************************/
     454error_t vfs_inode_stat( vfs_inode_t * inode,
     455                        uint32_t      inum );
     456
     457/******************************************************************************************
     458 * This function TODO                                                         
     459 *****************************************************************************************/
     460error_t vfs_icache_del( vfs_inode_t * inode );
     461
     462
     463/******************************************************************************************
     464 * This function TODO  Pourquoi 2 arguments ?
     465 *****************************************************************************************/
     466error_t vfs_stat_inode( vfs_inode_t * inode,
     467                        uint32_t      inum );
     468
     469
     470/*****************************************************************************************/
     471/***************** Dentry related functions **********************************************/
     472/*****************************************************************************************/
     473
     474/******************************************************************************************
     475 * This function allocates memory from local cluster for a dentry descriptor,
     476 * initialises it from  arguments values, and returns the extended pointer on dentry.
     477 * The inode field is not initialized, because the inode does not exist yet.
     478 * If the client thread is not running in the target cluster for this inode,
     479 * it must use the rpc_dentry_create_client() function.
     480 ******************************************************************************************
     481 * @ fs_type    : file system type.
     482 * @ name       : directory entry file/dir name.
     483 * @ parent     : local pointer on parent inode.
     484 * @ dentry_xp  : [out] buffer for extended pointer on created dentry.
     485 * @ return 0 if success / return ENOMEM or EINVAL if error.
     486 *****************************************************************************************/
     487error_t vfs_dentry_create( vfs_fs_type_t   fs_type,
     488                           char          * name,
     489                           vfs_inode_t   * parent,
     490                           xptr_t        * dentry_xp );
     491 
     492/******************************************************************************************
     493 * This function releases memory allocated to a dentry descriptor.
     494 * It must be executed by a thread running in the cluster containing the dentry,
     495 * and the dentry refcount must be zero.
     496 * If the client thread is not running in the owner cluster, it must use the
     497 * rpc_dentry_destroy_client() function.
     498 ******************************************************************************************
     499 * @ dentry  : local pointer on dentry descriptor.
     500 *****************************************************************************************/
     501void vfs_dentry_destroy( vfs_dentry_t *  dentry ); 
     502
     503/******************************************************************************************
     504 * These functions atomically increment/decrement the dentry refcount.
     505 * It can be called by any thread running in any cluster.
     506 *****************************************************************************************/
     507void vfs_dentry_remote_up( xptr_t dentry_xp );
     508void vfs_dentry_remote_down( xptr_t dentry_xp );
     509
     510
     511/*****************************************************************************************/
     512/************************ File descriptor related functions ******************************/
    486513/*****************************************************************************************/
    487514
    488515/******************************************************************************************
    489516 * This function allocates memory and initializes a new local file descriptor.
    490  * It must be executed in the owner cluster containing the inode.
     517 * It must be executed in the cluster containing the inode.
    491518 * If the client thread is not running in the owner cluster, it must use the
    492519 * rpc_vfs_file_create_client() function.
    493520 ******************************************************************************************
    494  * @ inode_xp : extended pointer on associated inode.
    495  * @ type     : file descriptor type.
     521 * @ inode    : local pointer on associated inode.
    496522 * @ attr     : file descriptor attributes.
    497523 * @ file_xp  : [out] buffer for extended pointer on created file descriptor.
    498524 * @ return 0 if success / return ENOMEM if error.
    499525 *****************************************************************************************/
    500 error_t vfs_file_create( xptr_t     inode_xp,
    501                          uint32_t   type,
    502                          uint32_t   attr,
    503                          xptr_t   * file_xp ); 
     526error_t vfs_file_create( vfs_inode_t * inode,
     527                         uint32_t      attr,
     528                         xptr_t      * file_xp ); 
    504529
    505530/******************************************************************************************
     
    510535 * rpc_vfs_file_destroy_client() function.
    511536 ******************************************************************************************
    512  * @ file_xp  : extended pointer on file descriptor.
    513  *****************************************************************************************/
    514 void vfs_file_destroy( xptr_t  file_xp ); 
    515 
     537 * @ file  : local pointer on file descriptor.
     538 *****************************************************************************************/
     539void vfs_file_destroy( vfs_file_t *  file ); 
    516540
    517541/******************************************************************************************
     
    525549
    526550/*****************************************************************************************/
    527 /********************* Inode related functions *******************************************/
    528 /*****************************************************************************************/
    529 
    530 /******************************************************************************************
    531  * This function allocates memory from local cluster for an inode descriptor and the
    532  * associated mapper. It initialise these descriptors from arguments values.
    533  * The parent dentry must have been previously created.
    534  * If the client thread is not running in the cluster containing this inode,
    535  * it must use the rpc_vfs_inode_create_client() function.
    536  ******************************************************************************************
    537  * @ dentry_xp  : extended pointer on associated dentry (in parent inode cluster).
    538  * @ type       : file system type.
    539  * @ attr       : inode attributes.
    540  * @ mode       : inode access mode.
    541  * @ uid        : user owner ID.
    542  * @ gid        : group owner ID.
    543  * @ inode_xp   : [out] buffer for extended pointer on created inode.
    544  * # return 0 if success / return ENOMEM or EINVAL if error.
    545  *****************************************************************************************/
    546 error_t vfs_inode_create( xptr_t      dentry_xp,
    547                           uint32_t    type,
    548                           uint32_t    attr,
    549                           uint32_t    mode,
    550                           uid_t       uid,
    551                           gid_t       gid,
    552                           xptr_t    * inode_xp );
    553 
    554 /******************************************************************************************
    555  * This function releases memory allocated to an inode descriptor.
    556  * It must be executed by a thread running in the cluster containing the inode,
    557  * and the inode refcount must be zero.
    558  * If the client thread is not running in the owner cluster, it must use the
    559  * rpc_vfs_inode_destroy_client() function.
    560  ******************************************************************************************
    561  * @ inode  : local pointer on inode descriptor.
    562  *****************************************************************************************/
    563 void vfs_inode_destroy( vfs_inode_t *  inode ); 
    564 
    565 /******************************************************************************************
    566  * This function atomically increment the inode refcount.
    567  * It can be called by any thread running in any cluster.
    568  *****************************************************************************************/
    569 void vfs_inode_remote_up( xptr_t  inode_xp );
    570 
    571 /******************************************************************************************
    572  * This function atomically decrement the inode refcount.
    573  * It can be called by any thread running in any cluster.
    574  *****************************************************************************************/
    575 void vfs_inode_remote_down( xptr_t  inode_xp );
    576 
    577 /******************************************************************************************
    578  * This function returns the <size> of a file/dir from a remote inode,
    579  * taking the remote_rwlock protecting <size> in READ_MODE.
    580  *****************************************************************************************
    581  * @ inode_xp  : extended pointer on the remote inode.
    582  * @ return the current size.
    583  *****************************************************************************************/
    584 uint32_t vfs_inode_get_size( xptr_t inode_xp );
    585 
    586 /******************************************************************************************
    587  * This function set the <size> of a file/dir to a remote inode,
    588  * taking the remote_rwlock protecting <size> in WRITE_MODE.
    589  *****************************************************************************************
    590  * @ inode_xp  : extended pointer on the remote inode.
    591  * @ size      : value to be written.
    592  *****************************************************************************************/
    593 void vfs_inode_set_size( xptr_t   inode_xp,
    594                          uint32_t size );
    595 
    596 /******************************************************************************************
    597  * This function takes the main lock of a remote inode.
    598  * This lock protect all inode fiels, including the children dentries.
    599  *****************************************************************************************
    600  * @ inode_xp  : extended pointer on the remote inode.
    601  *****************************************************************************************/
    602 void vfs_inode_remote_lock( xptr_t inode_xp );
    603 
    604 /******************************************************************************************
    605  * This function releases the main lock of a remote inode.
    606  * This lock protect all inode fiels, including the children dentries.
    607  *****************************************************************************************
    608  * @ inode_xp  : extended pointer on the remote inode.
    609  *****************************************************************************************/
    610 void vfs_inode_remote_unlock( xptr_t inode_xp );
    611 
    612 
    613 
    614 
    615 /******************************************************************************************
    616  * This function TODO                                                         
    617  *****************************************************************************************/
    618 error_t vfs_inode_hold( vfs_inode_t * inode,
    619                         uint32_t      gc );
    620 
    621 /******************************************************************************************
    622  * This function TODO                                                         
    623  *****************************************************************************************/
    624 error_t vfs_inode_trunc( vfs_inode_t * inode );
    625 
    626 /******************************************************************************************
    627  * This function TODO                                                         
    628  *****************************************************************************************/
    629 error_t vfs_inode_link( vfs_inode_t * inode,
    630                         uint32_t      igc );
    631 
    632 /******************************************************************************************
    633  * This function TODO                                                         
    634  *****************************************************************************************/
    635 error_t vfs_inode_unlink( vfs_inode_t * inode );
    636 
    637 /******************************************************************************************
    638  * This function TODO                                                         
    639  *****************************************************************************************/
    640 error_t vfs_inode_stat( vfs_inode_t * inode,
    641                         uint32_t      inum );
    642 
    643 /******************************************************************************************
    644  * This function TODO                                                         
    645  *****************************************************************************************/
    646 error_t vfs_icache_del( vfs_inode_t * inode );
    647 
    648 
    649 /******************************************************************************************
    650  * This function TODO  Pourquoi 2 arguments ?
    651  *****************************************************************************************/
    652 error_t vfs_stat_inode( vfs_inode_t * inode,
    653                         uint32_t      inum );
    654 
    655 
    656 /*****************************************************************************************/
    657 /***************** Dentry related functions **********************************************/
    658 /*****************************************************************************************/
    659 
    660 /******************************************************************************************
    661  * This function allocates memory from local cluster for a dentry descriptor,
    662  * initialises it from  arguments values, and returns the extended pointer on dentry.
    663  * The inode field is not initialized, because the inode does not exist yet.
    664  * If the client thread is not running in the target cluster for this inode,
    665  * it must use the rpc_dentry_create_client() function.
    666  ******************************************************************************************
    667  * @ type       : file system type.
    668  * @ name       : directory entry file/dir name.
    669  * @ parent     : local pointer on parent inode.
    670  * @ dentry_xp  : [out] buffer for extended pointer on created inode.
    671  * @ return 0 if success / return ENOMEM or EINVAL if error.
    672  *****************************************************************************************/
    673 error_t vfs_dentry_create( uint32_t      type,
    674                            char        * name,
    675                            vfs_inode_t * parent,
    676                            xptr_t      * dentry_xp );
    677  
    678 /******************************************************************************************
    679  * This function releases memory allocated to a dentry descriptor.
    680  * It must be executed by a thread running in the cluster containing the dentry,
    681  * and the dentry refcount must be zero.
    682  * If the client thread is not running in the owner cluster, it must use the
    683  * rpc_dentry_destroy_client() function.
    684  ******************************************************************************************
    685  * @ dentry  : local pointer on dentry descriptor.
    686  *****************************************************************************************/
    687 void vfs_dentry_destroy( vfs_dentry_t *  dentry ); 
    688 
    689 /******************************************************************************************
    690  * This function atomically increment the dentry refcount.                               
    691  * It can be called by any thread running in any cluster.
    692  *****************************************************************************************/
    693 void vfs_dentry_remote_up( xptr_t dentry_xp );
    694 
    695 /******************************************************************************************
    696  * This function atomically decrement the dentry refcount.                               
    697  * It can be called by any thread running in any cluster.
    698  *****************************************************************************************/
    699 void vfs_dentry_remote_down( xptr_t dentry_xp );
    700 
    701 
    702 /*****************************************************************************************/
    703 /*                 Inode-Tree related functions                                          */
     551/******************* Inode-Tree related functions ****************************************/
    704552/*****************************************************************************************/
    705553
     
    721569/******************************************************************************************
    722570 * This function takes a pathname (absolute or relative to cwd) and returns an extended
    723  * pointer on the associated inode, and an extended pointer on the inode context.
    724  * If a given name in the path is not found in the inode tree, it try to load the missing
    725  * dentry/inode couple, from informations found in the parent directory.
    726  * If this directory entry does not exist on device, it returns an error.
    727  ******************************************************************************************
    728  * @ cwd_xp     : extended pointer on current directory (for relative path).
    729  * @ pathname   : path in kernel space (can be relative or absolute).
    730  * @ client_uid : client thread user ID (for checking).
    731  * @ client_gid : client thread group ID (for checking).
    732  * @ inode_xp   : [out] buffer for extended pointer on inode.
    733  * @ ctx_xp     : [out] buffer for extended pointer on inode context.
    734  * @ return 0 if success / ENOENT if inode not found / EACCES if permissopn denied
    735  *****************************************************************************************/
    736 error_t vfs_lookup( xptr_t       cwd_xp,
    737                     char       * pathname,
    738                     uint32_t     client_uid,
    739                     uint32_t     client_gid,
    740                                         xptr_t     * inode_xp,
    741                     xptr_t     * ctx_xp );
     571 * pointer on the associated inode.
     572 * - If a given name in the path is not found in the inode tree, it try to load the missing
     573 *   dentry/inode couple, from informations found in the parent directory.
     574 * - If this directory entry does not exist on device, it returns an error.
     575 * - If the the file identified by the pathname does not exist on device but the
     576 *   flag CREATE is set, the inode is created.
     577 * - If the the file identified by the pathname exist on device but both flags EXCL
     578 *   and CREATE are set, an error is returned.
     579 ******************************************************************************************
     580 * @ cwd_xp      : extended pointer on current directory (for relative path).
     581 * @ pathname    : path in kernel space (can be relative or absolute).
     582 * @ lookup_mode : flags defining the working mode (defined above in this file).
     583 * @ inode_xp    : [out] buffer for extended pointer on inode.
     584 * @ return 0 if success / ENOENT if inode not found , EACCES if permissopn denied,
     585 *                        EAGAIN if a new complete lookup must be made
     586 *****************************************************************************************/
     587error_t vfs_lookup( xptr_t             cwd_xp,
     588                    char             * pathname,
     589                    uint32_t           lookup_mode,
     590                                        xptr_t           * inode_xp );
    742591
    743592/******************************************************************************************
     
    747596 * - The dentry is created in the cluster containing the existing <parent_xp> inode.
    748597 * - the child inode and its associated mapper are created in a randomly selected cluster.
    749  * - The dentry name is defined by the <name> argument.
    750  ******************************************************************************************
    751  * @ type       : new inode type
     598 * - The new dentry name is defined by the <name> argument.
     599 * - The new inode and the parent inode can have different FS types.
     600 ******************************************************************************************
     601 * @ inode_type : new inode type
     602 * @ fs_type    : new inode FS type.
    752603 * @ parent_xp  : extended pointer on parent inode.
    753604 * @ name       : new directory entry name.
     
    755606 * @ return 0 if success / ENOENT if entry not found in parent directory
    756607 *****************************************************************************************/
    757 error_t vfs_add_child_in_parent( uint32_t type,
    758                                  xptr_t   parent_xp,
    759                                  char   * name,   
    760                                  xptr_t * child_xp );
    761 
    762 /******************************************************************************************
    763  * TODO
     608error_t vfs_add_child_in_parent( vfs_inode_type_t   inode_type,
     609                                 vfs_fs_type_t      fs_type,
     610                                 xptr_t             parent_xp,
     611                                 char             * name,   
     612                                 xptr_t           * child_xp );
     613
     614/******************************************************************************************
     615 * This function removes a couple dentry/inode from the Inode-Tree, and remove it from
     616 * the external device.
     617 * TODO                   
    764618 ******************************************************************************************
    765619 * @ child_xp   : extended pointer on removed inode.
     
    767621error_t vfs_remove_child_from_parent( xptr_t child_xp );
    768622
    769 /*****************************************************************************************/
    770 /************************ File related functions *****************************************/
     623
     624
     625
     626
     627
     628/*****************************************************************************************/
     629/****************** File access API ******************************************************/
    771630/*****************************************************************************************/
    772631
    773632/******************************************************************************************
    774633 * This function allocates a vfs_file_t structure in the cluster containing the inode
    775  * associated to the requested file, initializes it, and returns an extended pointer
    776  * on this remote open file descriptor.
     634 * associated to the file identified by <cwd_xp> & <path>.
     635 * It initializes it, register it in the reference process fd_array, and returns both
     636 * the extended pointer on the remote file descriptor, and the index in the fd_array.
    777637 * The pathname can be relative to current directory or absolute.
    778  * If the inode does not exist in the inode cache, it try to find file on the mounted
     638 * If the inode does not exist in the inode cache, it try to find the file on the mounted
    779639 * device, and creates an inode on a pseudo randomly selected cluster if found.
    780640 * It the requested file does not exist on device, it creates a new inode if the
    781641 * O_CREAT flag is set and return an error otherwise.
    782642 ******************************************************************************************
    783  * @ cwd_xp    : extended pointer on current directory file descriptor (for relative path).
    784  * @ path      : file pathname (absolute or relative to current directory).
    785  * @ flags     : O_RDONLY, O_WRONLY, O_CREATE etc...
    786  * @ file_xp   : [out] buffer for extended pointer on created remote file descriptor.
     643 * @ cwd_xp      : extended pointer on current working directory file descriptor.
     644 * @ path        : file pathname (absolute or relative to current directory).
     645 * @ flags       : defined above
     646 * @ mode        : access rights (as defined by chmod)
     647 * @ file_xp     : [out] buffer for extended pointer on created remote file descriptor.
     648 * @ file_id     : [out] buffer for created file descriptor index in reference fd_array.
    787649 * @ return 0 if success / return non-zero if error.
    788650 *****************************************************************************************/
     
    790652                          char     * path,
    791653                          uint32_t   flags,
    792                           xptr_t   * file_xp );
    793 
    794 /******************************************************************************************
    795  * This function moves <size> bytes from the file identified by the open file descriptor
    796  * <file_xp> to the local kernel <buffer> , taken into account the offset in <file_xp>.
    797  ******************************************************************************************
    798  * @ file_xp   : extended pointer on the remote open file descriptor.
    799  * @ buffer    : local pointer on destination kernel buffer.
     654                  uint32_t   mode,
     655                          xptr_t   * file_xp,
     656                          uint32_t * file_id );
     657
     658/******************************************************************************************
     659 * This function moves <size> bytes between the file identified by the open file descriptor
     660 * <file_xp> and a local kernel <buffer> , taken into account the offset in <file_xp>.
     661 * The transfer direction is defined by the <to_buffer> argument.
     662 ******************************************************************************************
     663 * @ to_buffer : mapper -> buffer if true / buffer->mapper if false.
     664 * @ file_xp   : extended pointer on the remote file descriptor.
     665 * @ buffer    : local pointer on local kernel buffer.
    800666 * @ size      : requested number of bytes from offset.
    801  * @ returns number of bytes actually transfered / 0 if EOF / -1 if error.
    802  *****************************************************************************************/
    803 uint32_t vfs_read( xptr_t   file_xp,
    804                    void   * buffer,
    805                    uint32_t size );
    806 
    807 /******************************************************************************************
    808  * This function moves <size> bytes from the local kernel <buffer> to the open file
    809  * descriptor <file_xp>, taken into account the offset defined in <file_xp>.
    810  ******************************************************************************************
    811  * @ file_xp   : extended pointer on the remote open file descriptor.
    812  * @ buffer    : local pointer on source kernel buffer.
    813  * @ size      : requested number of bytes to be written from offset.
    814667 * @ returns number of bytes actually transfered / -1 if error.
    815668 *****************************************************************************************/
    816 uint32_t vfs_write( xptr_t   file_xp,
    817                     void   * buffer,
    818                     uint32_t size );
     669error_t vfs_move( bool_t   to_buffer,
     670                  xptr_t   file_xp,
     671                  void   * buffer,
     672                  uint32_t size );
    819673
    820674/******************************************************************************************
     
    837691
    838692/******************************************************************************************
    839  * This function close an open file descriptor.                             
     693 * This function close an open file descriptor:
     694 * 1) All entries in fd_array copies are directly cancelled by the calling thread,
     695 *    using remote accesses.
     696 * 2) The memory allocated to file descriptor in cluster containing the inode is released.
     697 *    It requires a RPC if cluster containing the file descriptor is remote.
    840698 ******************************************************************************************
    841699 * @ file_xp     : extended pointer on the file descriptor.
    842  * @ refcount    : number of references after close.
    843  * @ return 0 if success / return -1 if error
    844  *****************************************************************************************/
    845 error_t vfs_close( xptr_t     file_xp,
    846                    uint32_t * refcount );
    847 
    848 /******************************************************************************************
    849  * This function remove from the file system a directory entry identified by its pathname.
    850  * The pathname can be relative to current directory or absolute.
    851  ******************************************************************************************
    852  * @ cwd_xp   : extended pointer on the current directory file descriptor.
     700 * @ file_id     : file descriptor index in fd_array.
     701 * @ returns 0 if success / -1 if error.
     702 *****************************************************************************************/
     703error_t vfs_close( xptr_t    file_xp,
     704                   uint32_t  file_id );
     705
     706/******************************************************************************************
     707 * This function remove from the file system a directory entry identified by the
     708 * <cwd_xp> & <path> arguments.
     709 ******************************************************************************************
     710 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
    853711 * @ path     : pathname (absolute or relative to current directory).
     712 * @ returns 0 if success / -1 if error.
    854713 *****************************************************************************************/
    855714error_t vfs_unlink( xptr_t   cwd_xp,
     
    857716
    858717/******************************************************************************************
    859  * This function returns in the <ustat> structure various informations on the file TODO
     718 * This function returns, in the structure pointed by the <k_stat> kernel pointer,
     719 * various informations on the file descriptor identified by the <file_xp> argument.
     720 * TODO not implemented yet...
     721 ******************************************************************************************
     722 * @ file_xp    : extended pointer on the file descriptor of the searched directory .
     723 * @ k_dirent   : local pointer on the dirent_t structure in kernel space.
     724 * @ returns 0 if success / -1 if error.
    860725 *****************************************************************************************/
    861726error_t vfs_stat( xptr_t       file_xp,
    862                   vfs_stat_t * ustat );
    863 
    864 
    865 
    866 
    867 /*****************************************************************************************/
    868 /************************ Directory related functions ************************************/
    869 /*****************************************************************************************/
    870 
    871 /******************************************************************************************
    872  * This function TODO                                                         
    873  *****************************************************************************************/
    874 error_t vfs_opendir( xptr_t      cwd_xp,
    875                      char      * path,
    876                      uint32_t    flags,
    877                      xptr_t      file_xp );
    878 
    879 /******************************************************************************************
    880  * This function TODO                                                         
    881  *    fat32_readdir need cleaning
    882  *****************************************************************************************/
    883 error_t vfs_readdir( xptr_t            file_xp,
    884                      char            * path );
    885 
    886 /******************************************************************************************
    887  * This function TODO                                                         
    888  *****************************************************************************************/
    889 error_t vfs_mkdir( xptr_t            file_xp,
    890                    char            * path,
    891                    uint32_t          mode );
    892 
    893 /******************************************************************************************
    894  * This function remove a directory from the file system.
    895  *****************************************************************************************/
    896 error_t vfs_rmdir( xptr_t            file_xp,
    897                    char            * path );
    898 
    899 /******************************************************************************************
    900  * This function TODO                                                         
    901  *****************************************************************************************/
    902 error_t vfs_chdir( char            * pathname,
    903                    xptr_t            cwd_xp );
    904 
    905 /******************************************************************************************
    906  * This function TODO                                                         
    907  *****************************************************************************************/
    908 error_t vfs_chmod( char            * pathname,
    909                    vfs_file_t      * cwd,
    910                    uint32_t          mode );
    911 
    912 /******************************************************************************************
    913  * This function TODO                                                         
    914  *****************************************************************************************/
    915 error_t vfs_closedir( xptr_t       file_xp,
    916                       uint32_t   * refcount );
    917 
    918 
    919 
    920 
    921 /*****************************************************************************************/
    922 /*******************  Pipe related functions *********************************************/
    923 /*****************************************************************************************/
    924 
    925 /******************************************************************************************
    926  * This function TODO ???                                                         
    927  *****************************************************************************************/
    928 error_t vfs_pipe( xptr_t pipefd[2] );
    929 
    930 /******************************************************************************************
    931  * This function TODO                                                         
    932  *****************************************************************************************/
    933 error_t vfs_mkfifo( xptr_t            cwd_xp,
    934                     char            * path,
    935                     uint32_t          mode );
    936 
    937 
    938 
     727                  vfs_stat_t * k_stat );
     728
     729/******************************************************************************************
     730 * This function returns, in the structure pointed by the <k_dirent> kernel pointer,
     731 * various infos on the directory entry currently pointed by the <file_xp> file descriptor.
     732 * TODO not implemented yet...
     733 ******************************************************************************************
     734 * @ file_xp    : extended pointer on the file descriptor of the searched directory .
     735 * @ k_dirent   : local pointer on the dirent_t structure in kernel space.
     736 * @ returns 0 if success / -1 if error.
     737 *****************************************************************************************/
     738error_t vfs_readdir( xptr_t         file_xp,
     739                     vfs_dirent_t * k_dirent );
     740
     741/******************************************************************************************
     742 * This function  creates a new inode and associated dentry  for the directory defined
     743 * by the <cwd_xp> & <path> arguments.
     744 * TODO not implemented yet...
     745 ******************************************************************************************
     746 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
     747 * @ path     : pathname (absolute or relative to current directory).                     
     748 * @ mode     : access rights (as defined by chmod)
     749 * @ returns 0 if success / -1 if error.
     750 *****************************************************************************************/
     751error_t vfs_mkdir( xptr_t     cwd_xp,
     752                   char     * path,
     753                   uint32_t   mode );
     754
     755/******************************************************************************************
     756 * This function remove a directory identified by the <cwd_xp / path> arguments
     757 * from the file system.
     758 * TODO not implemented yet...
     759 ******************************************************************************************
     760 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
     761 * @ path     : pathname (absolute or relative to current directory).                     
     762 * @ returns 0 if success / -1 if error.
     763 *****************************************************************************************/
     764error_t vfs_rmdir( xptr_t   cwd_xp,
     765                   char   * path );
     766
     767/******************************************************************************************
     768 * This function makes the directory identified by <cwd_xp / path> arguments to become
     769 * the working directory for the calling process.
     770 ******************************************************************************************
     771 * @ cwd_xp      : extended pointer on current directory file descriptor (relative path).
     772 * @ path        : file pathname (absolute or relative to current directory).
     773 * return 0 if success / -1 if error.
     774 *****************************************************************************************/
     775error_t vfs_chdir( xptr_t   cwd_xp,
     776                   char   * path );
     777
     778/******************************************************************************************
     779 * This function change the access rigths for the file identified by the <cwd_xp / path>
     780 * arguments. The new access rights are defined by the <mode> argument value.
     781 ******************************************************************************************
     782 * @ cwd_xp      : extended pointer on current directory file descriptor (relative path).
     783 * @ path        : file pathname (absolute or relative to current directory).
     784 * @ mode        : access rights new value.
     785 * return 0 if success / -1 if error.
     786 *****************************************************************************************/
     787error_t vfs_chmod( xptr_t        cwd_xp,
     788                   char        * path,
     789                   uint32_t      mode );
     790
     791/******************************************************************************************
     792 * This function creates a named FIFO file.
     793 * TODO not implemented yet                                                         
     794 ******************************************************************************************
     795 * @ path        : FIFO pathname (absolute or relative to current directory).
     796 * @ cwd_xp      : extended pointer on the current working directory file descriptor.
     797 * @ mode        : access rights new value.
     798 *****************************************************************************************/
     799error_t vfs_mkfifo( xptr_t       cwd_xp,
     800                    char       * path,
     801                    uint32_t     mode );
     802
     803
     804/*****************************************************************************************/
     805/****************** Mapper access API ****************************************************/
     806/*****************************************************************************************/
     807
     808/******************************************************************************************
     809 * This function makes an I/O operation to move one page from VFS to a given mapper,
     810 * in case of MISS on the mapper cache.
     811 * Depending on the file system type, it calls the proper, FS specific function.
     812 * It must be executed by a thread running in the cluster containing the mapper.
     813 * The mapper pointer is obtained from the page descriptor.
     814 * It takes the mapper lock before launching the IO operation.
     815 ******************************************************************************************
     816 * @ page   : local pointer on the page descriptor.
     817 * @ returns 0 if success / return EINVAL if it cannot access the external device.
     818 *****************************************************************************************/
     819error_t vfs_move_page_to_mapper( struct page_s * page );
     820
     821/******************************************************************************************
     822 * This function makes an I/0 operation to move one page from a given mapper to VFS,
     823 * when a dirty page in the mapper cache must be updated in the File System.
     824 * Depending on the file system type, it calls the proper, FS specific function.
     825 * It must be executed by a thread running in the cluster containing the mapper.
     826 * The mapper pointer is obtained from the page descriptor.
     827 * It takes the mapper lock before launching the IO operation.
     828 * It does nothing if the page is not dirty. If the page is dirty, it clear the page
     829 * dirty bit, and remove the page from the PPM dirty list.
     830 ******************************************************************************************
     831 * @ page   : local pointer on the page descriptor.
     832 * @ returns 0 if success / return EINVAL if it cannot access the external device.
     833 *****************************************************************************************/
     834error_t vfs_move_page_from_mapper( struct page_s * page );       
     835
     836
     837
     838
     839
     840
     841///////////////////////////////////////////////////////////////////////////////////////////
     842// These typedef define the FS specific operations that must be implemented by any
     843// specific file system to be supported by the ALMOS_MKH VFS.
     844// These typedef are not actually used, and are only defined for documentation
     845///////////////////////////////////////////////////////////////////////////////////////////
     846
     847typedef error_t (fs_init_t)          ( xptr_t vfs_root_xp );
     848
     849typedef error_t (fs_inode_extend_t)  ( struct vfs_inode_s * inode,
     850                                       void               * extend );
     851 
     852typedef void    (fs_inode_release_t) ( struct vfs_inode_s * inode );
     853
     854typedef error_t (fs_write_page_t)    ( struct page_s * page );
     855
     856typedef error_t (fs_read_page_t)     ( struct page_s * page );
     857
     858
     859
     860
     861
     862
     863
     864
     865/* deprecated [AG]
     866
     867typedef error_t (lookup_inode_t)  ( vfs_inode_t  * parent ,
     868                                    vfs_dentry_t * dentry );
     869
     870typedef error_t (write_inode_t)   ( vfs_inode_t  * inode );
     871
     872typedef error_t (release_inode_t) ( vfs_inode_t  * inode );
     873
     874typedef error_t (unlink_inode_t)  ( vfs_inode_t  * parent,
     875                                    vfs_dentry_t * dentry,
     876                                    uint32_t       flags );
     877
     878typedef error_t (stat_inode_t)    ( vfs_inode_t  * inode );
     879
     880typedef error_t (trunc_inode_t)   ( vfs_inode_t  * inode );
     881
     882typedef error_t (delete_inode_t)  ( vfs_inode_t  * inode );
     883
     884typedef struct vfs_inode_op_s
     885{
     886        init_inode_t    * init;   
     887        create_inode_t  * create; 
     888        lookup_inode_t  * lookup; 
     889        write_inode_t   * write;
     890        release_inode_t * release;
     891        unlink_inode_t  * unlink;
     892        delete_inode_t  * delete;
     893        stat_inode_t    * stat;
     894        trunc_inode_t   * trunc;    // change the size of a file
     895}
     896vfs_inode_op_t;
     897
     898 ******************************************************************************************
     899 * These typedef define the set of FS specific operations on a VFS DENTRY descriptor.
     900 * They must be implemented by any specific file system to be supported by ALMOS_MKH.
     901 * This code is not actually used, and is only defined for documentation
     902 ******************************************************************************************
     903
     904
     905typedef error_t (vfs_compare_dentry_t) ( char * first , char * second );
     906
     907typedef struct vfs_dentry_op_s
     908{
     909        vfs_compare_dentry_t * compare;
     910}
     911vfs_dentry_op_t;
     912
     913
     914 ******************************************************************************************
     915 * These typedef define the set of FS specific operations on FILE descriptors
     916 * They must be implemented by any specific file system to be supported by ALMOS_MKH.
     917 * This code is not actually used, and is only defined for documentation
     918 ******************************************************************************************
     919
     920
     921typedef error_t (open_file_t   ) ( vfs_file_t * file,
     922                                   void       * extend );
     923
     924typedef error_t (read_file_t   ) ( vfs_file_t * file,
     925                                   char       * buffer,
     926                                   uint32_t     count );
     927
     928typedef error_t (write_file_t  ) ( vfs_file_t * file,
     929                                   char       * buffer,
     930                                   uint32_t     count );
     931
     932typedef error_t (lseek_file_t  ) ( vfs_file_t * file );
     933
     934typedef error_t (close_file_t  ) ( vfs_file_t * file );
     935
     936typedef error_t (release_file_t) ( vfs_file_t * file );
     937
     938typedef error_t (read_dir_t    ) ( vfs_file_t * file );
     939
     940typedef error_t (mmap_file_t   ) ( vfs_file_t    * file ,
     941                                   struct vseg_s * vseg );
     942
     943typedef error_t (munmap_file_t ) ( vfs_file_t    * file,
     944                                   struct vseg_s * vseg );
     945
     946typedef struct vfs_file_op_s
     947{
     948        open_file_t    * open;
     949        read_file_t    * read;
     950        write_file_t   * write;
     951        lseek_file_t   * lseek;
     952        read_dir_t     * readdir;
     953        close_file_t   * close;
     954        release_file_t * release;
     955        mmap_file_t    * mmap;
     956        munmap_file_t  * munmap;
     957}
     958vfs_file_op_t;
     959
     960*/
    939961
    940962#endif  /* _VFS_H_ */
Note: See TracChangeset for help on using the changeset viewer.