Changeset 458


Ignore:
Timestamp:
Dec 5, 2014, 3:48:29 PM (10 years ago)
Author:
alain
Message:

Introducing the new spin-lock (with waiting queue).

Location:
soft/giet_vm/giet_fat32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_fat32/fat32.c

    r443 r458  
    2323#include <giet_config.h>
    2424#include <fat32.h>
    25 #include <tty_driver.h>
     25#include <tty0.h>
    2626#include <ioc_driver.h>
    2727#include <utils.h>
     
    725725    if ( _get_next_cluster( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER)
    726726    {
    727         _puts("\n[FAT ERROR] in _fat_allocate() : first free_cluster not free\n");
     727        _puts("\n[FAT ERROR] in _fat_allocate() : first free cluster not free\n");
    728728        return -1;
    729729    }
     
    755755_putx( last_cluster_file );
    756756_puts(" / free cluster = ");
    757 _putx( free-cluster );
     757_putx( free_cluster );
    758758_puts(" / clusters required = ");
    759 _putx( cluster_to allocate );
     759_putx( cluster_to_allocate );
    760760_puts("\n");
    761761#endif
     
    853853_puts(",");
    854854_putd( p );
    855 _puts("] enters for ")
     855_puts("] enters for ");
    856856_puts( file_name );
    857857_puts(" / is_sfn = ");
     
    10181018_puts(" / cluster = ");
    10191019_putx( searched_cluster );
    1020 _puts("\n")
     1020_puts("\n");
    10211021#endif
    10221022
     
    10441044
    10451045//////////////////////////////////////////////////////////////////////////
    1046 // This function initializes the FAT structure, including the
    1047 // files descriptors array, from informations found in the boot record.
     1046// This function initializes the FAT structure, including the open
     1047// files descriptors array and the lock protecting the FAT,
     1048// from informations found in the boot record.
     1049// This should be done only once.
    10481050//////////////////////////////////////////////////////////////////////////
    10491051// Return 0 if success, Return -1 if failure
     
    10651067_puts(",");
    10661068_putd( p );
    1067 _puts("] enters");
    1068 if ( mode == IOC_BOOT_MODE   ) _puts(" / IOC_BOOT_MODE\n");
    1069 if ( mode == IOC_KERNEL_MODE ) _puts(" / IOC_KERNEL_MODE\n");
    1070 if ( mode == IOC_USER_MODE   ) _puts(" / IOC_USER_MODE\n");
    1071 #endif
    1072    
     1069_puts("] enters _fat_init()");
     1070if ( mode == IOC_BOOT_MODE   ) _puts(" in BOOT_MODE\n");
     1071if ( mode == IOC_KERNEL_MODE ) _puts(" in KERNEL_MODE\n");
     1072if ( mode == IOC_USER_MODE   ) _puts(" in USER_MODE\n");
     1073#endif
     1074
     1075    // FAT initialisation should be done only once
     1076    if ( fat.initialised == FAT_INITIALISED )
     1077    {
     1078        _puts("\n[FAT WARNING] Strange initialisation  of a FAT already initialised...\n");
     1079        return 0;
     1080    }
     1081
    10731082    // load Boot Record (VBR) into fat cache
    10741083    if ( _ioc_read( 0,                   // channel
     
    11181127    fat.fat_lba             = _read_entry( BPB_RSVDSECCNT, fat.fat_cache, 1 );
    11191128    fat.data_lba            = fat.fat_lba + fat.fat_sectors;
    1120     fat.fat_lock.value      = 0;
    11211129    fat.initialised         = FAT_INITIALISED;
     1130
     1131    // initalise the lock protecting the FAT
     1132    _lock_init( &fat.fat_lock );
    11221133
    11231134    // initialise file descriptor array
     
    11481159#if GIET_DEBUG_FAT
    11491160_fat_print();
    1150 _puts("\n[FAT DEBUG] _fat_init() : P[");
     1161_puts("\n[FAT DEBUG] P[");
    11511162_putd( x );
    11521163_puts(",");
     
    11541165_puts(",");
    11551166_putd( p );
    1156 _puts("] exit\n");
     1167_puts("] exit _fat_init()\n");
    11571168#endif
    11581169
     
    11771188///////////////////////////////////////////////////////////////////////////////
    11781189// This function checks that the kernel FAT structure has been initialised.
    1179 // It makes the FAT initialisation if it is the first open request.
    1180 // This function searches a file identified by the "pathname" argument.
     1190// It searches a file identified by the "pathname" argument.
    11811191// It starts from root (cluster 2) to scan successively each subdirectory.
    11821192// When the file is not found, but the path is found, and "creat" is set,
     
    12061216unsigned int p       = procid & ((1<<P_WIDTH)-1);
    12071217
     1218_puts("\n[FAT DEBUG] P[");
     1219_putd( x );
     1220_puts(",");
     1221_putd( y );
     1222_puts(",");
     1223_putd( p );
     1224_puts("] enters _fat_open() for path ");
     1225_puts( pathname );
     1226_puts("\n");
     1227#endif
     1228
     1229    // checking creat argument
     1230    if ( creat )
     1231    {
     1232        _puts("[FAT ERROR] in _fat_open() : create not supported yet\n");
     1233        return -1;
     1234    }
     1235
     1236    // checking FAT initialised
     1237    if( fat.initialised != FAT_INITIALISED )
     1238    {
     1239        _puts("[FAT ERROR] in _fat_open() : FAT not initialised\n");
     1240        return -1;
     1241    }
     1242    // takes the FAT lock for exclusive access
     1243    _lock_acquire( &fat.fat_lock );
     1244
     1245#if GIET_DEBUG_FAT
    12081246_puts("\n[FAT DEBUG] _fat_open() : P[");
    12091247_putd( x );
     
    12121250_puts(",");
    12131251_putd( p );
    1214 _puts("] enters for path ");
    1215 _puts( pathname );
    1216 _puts("\n");
    1217 #endif
    1218 
    1219     // checking arguments
    1220     if ( creat )
    1221     {
    1222         _puts("[FAT ERROR] in _fat_open() : create not supported yet\n");
    1223         return -1;
    1224     }
    1225 
    1226     // takes the FAT lock for exclusive access
    1227     _get_lock( &fat.fat_lock );
    1228 
    1229 #if GIET_DEBUG_FAT
    1230 _puts("\n[FAT DEBUG] _fat_open() : P[");
    1231 _putd( x );
    1232 _puts(",");
    1233 _putd( y );
    1234 _puts(",");
    1235 _putd( p );
    12361252_puts("] takes the FAT lock\n");
    12371253#endif
    1238 
    1239     // FAT initialisation if required
    1240     if( fat.initialised != FAT_INITIALISED )
    1241     {
    1242         if ( _fat_init( mode ) )
    1243         {
    1244             _puts("[FAT ERROR] in _fat_open() : Cannot initialize FAT descriptor\n");
    1245             _release_lock( &fat.fat_lock );
    1246             return -1;
    1247         }
    1248     }
    12491254 
    12501255    // Scan the directories, starting from the root directory (cluster 2)
     
    12911296            _puts( name );
    12921297            _puts("\n");
    1293             _release_lock( &fat.fat_lock );
     1298            _lock_release( &fat.fat_lock );
    12941299            return -1;
    12951300        }
     
    13461351
    13471352            // release FAT lock
    1348             _release_lock( &fat.fat_lock );
     1353            _lock_release( &fat.fat_lock );
    13491354
    13501355            return fd_id;
     
    13551360            _puts( pathname );
    13561361            _puts(" : fd array full\n");
    1357             _release_lock( &fat.fat_lock );
     1362            _lock_release( &fat.fat_lock );
    13581363            return -1;
    13591364        }
     
    13641369        _puts( pathname );
    13651370        _puts(" : bad cluster\n");
    1366         _release_lock( &fat.fat_lock );
     1371        _lock_release( &fat.fat_lock );
    13671372        return -1;
    13681373    }
  • soft/giet_vm/giet_fat32/fat32.h

    r354 r458  
    1010
    1111#include "giet_config.h"
    12 #include "utils.h"
     12#include "locks.h"
    1313
    1414/*************** Partition Boot Sector Format ******************************************/
     
    138138{
    139139    char            fat_cache[512];          // FAT cache: 1 sector = 128 cluster indexes
    140     giet_lock_t     fat_lock;                // lock protecting exclusive access
     140    spin_lock_t     fat_lock;                // lock protecting exclusive access
    141141    file_desc_t     fd[GIET_OPEN_FILES_MAX]; // file descriptors array
    142142    unsigned int    initialised;             // contains 0xBABEF00D when FAT initialised
Note: See TracChangeset for help on using the changeset viewer.