Changeset 3b77417 in rtems


Ignore:
Timestamp:
Dec 13, 2017, 3:15:25 PM (22 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
0940648f
Parents:
b17bcb3
git-author:
Sebastian Huber <sebastian.huber@…> (12/13/17 15:15:25)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/02/18 14:01:22)
Message:

dosfs: Use self-contained recursive mutex

Update #2843.

Location:
cpukit
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/confdefs.h

    rb17bcb3 r3b77417  
    418418    defined(CONFIGURE_FILESYSTEM_DOSFS)
    419419  #include <rtems/dosfs.h>
    420   #if !defined(CONFIGURE_MAXIMUM_DOSFS_MOUNTS)
    421     #define CONFIGURE_MAXIMUM_DOSFS_MOUNTS 1
    422   #endif
    423420  #define CONFIGURE_FILESYSTEM_ENTRY_DOSFS \
    424421    { RTEMS_FILESYSTEM_TYPE_DOSFS, rtems_dosfs_initialize }
    425   #define _CONFIGURE_SEMAPHORES_FOR_DOSFS CONFIGURE_MAXIMUM_DOSFS_MOUNTS
    426 #else
    427   #define _CONFIGURE_SEMAPHORES_FOR_DOSFS 0
    428422#endif
    429423
     
    461455    (_CONFIGURE_SEMAPHORES_FOR_FIFOS + \
    462456     _CONFIGURE_SEMAPHORES_FOR_NFS + \
    463      _CONFIGURE_SEMAPHORES_FOR_DOSFS + \
    464457     _CONFIGURE_SEMAPHORES_FOR_RFS)
    465458
  • cpukit/libfs/src/dosfs/msdos.h

    rb17bcb3 r3b77417  
    2525#include <rtems/libio_.h>
    2626#include <rtems/dosfs.h>
     27#include <rtems/thread.h>
    2728
    2829#include "fat.h"
     
    6364                                                            * type
    6465                                                            */
    65     rtems_id                          vol_sema;           /*
    66                                                            * semaphore
    67                                                            * associated with
    68                                                            * the volume
    69                                                            */
     66    rtems_recursive_mutex vol_mutex;
    7067    uint8_t                          *cl_buf;              /*
    7168                                                            * just placeholder
     
    7673} msdos_fs_info_t;
    7774
     75RTEMS_INLINE_ROUTINE void msdos_fs_lock(msdos_fs_info_t *fs_info)
     76{
     77    rtems_recursive_mutex_lock(&fs_info->vol_mutex);
     78}
     79
     80RTEMS_INLINE_ROUTINE void msdos_fs_unlock(msdos_fs_info_t *fs_info)
     81{
     82    rtems_recursive_mutex_unlock(&fs_info->vol_mutex);
     83}
     84
    7885/* a set of routines that handle the nodes which are directories */
    7986extern const rtems_filesystem_file_handlers_r  msdos_dir_handlers;
     
    8188/* a set of routines that handle the nodes which are files */
    8289extern const rtems_filesystem_file_handlers_r  msdos_file_handlers;
    83 
    84 /* Volume semaphore timeout value. This value can be changed to a number
    85  * of ticks to help debugging or if you need such a  */
    86 #define MSDOS_VOLUME_SEMAPHORE_TIMEOUT    RTEMS_NO_TIMEOUT
    8790
    8891/*
  • cpukit/libfs/src/dosfs/msdos_dir.c

    rb17bcb3 r3b77417  
    6666    int                rc = RC_OK;
    6767    int                eno = 0;
    68     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    6968    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    7069    rtems_dosfs_convert_control *converter = fs_info->converter;
     
    8887    bool               is_first_entry;
    8988
    90     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    91                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    92     if (sc != RTEMS_SUCCESSFUL)
    93         rtems_set_errno_and_return_minus_one(EIO);
     89    msdos_fs_lock(fs_info);
    9490
    9591    /*
     
    124120        if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
    125121        {
    126             rtems_semaphore_release(fs_info->vol_sema);
     122            msdos_fs_unlock(fs_info);
    127123            rtems_set_errno_and_return_minus_one(EIO);
    128124        }
     
    138134                MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY)
    139135            {
    140                 rtems_semaphore_release(fs_info->vol_sema);
     136                msdos_fs_unlock(fs_info);
    141137                return cmpltd;
    142138            }
     
    253249                if (rc != RC_OK)
    254250                {
    255                     rtems_semaphore_release(fs_info->vol_sema);
     251                    msdos_fs_unlock(fs_info);
    256252                    return rc;
    257253                }
     
    263259                if (rc != RC_OK)
    264260                {
    265                     rtems_semaphore_release(fs_info->vol_sema);
     261                    msdos_fs_unlock(fs_info);
    266262                    return rc;
    267263                }
     
    337333                    if (rc != RC_OK)
    338334                    {
    339                         rtems_semaphore_release(fs_info->vol_sema);
     335                        msdos_fs_unlock(fs_info);
    340336                        return rc;
    341337                    }
     
    349345    }
    350346
    351     rtems_semaphore_release(fs_info->vol_sema);
     347    msdos_fs_unlock(fs_info);
    352348    return cmpltd;
    353349}
     
    383379)
    384380{
    385     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    386381    msdos_fs_info_t   *fs_info = loc->mt_entry->fs_info;
    387382    fat_file_fd_t     *fat_fd = loc->node_access;
    388383
    389     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    390                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    391     if (sc != RTEMS_SUCCESSFUL)
    392         rtems_set_errno_and_return_minus_one(EIO);
     384    msdos_fs_lock(fs_info);
    393385
    394386    buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
     
    403395    buf->st_mtime = fat_fd->mtime;
    404396
    405     rtems_semaphore_release(fs_info->vol_sema);
     397    msdos_fs_unlock(fs_info);
    406398    return RC_OK;
    407399}
  • cpukit/libfs/src/dosfs/msdos_file.c

    rb17bcb3 r3b77417  
    4848{
    4949    ssize_t            ret = 0;
    50     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    51     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    52     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    53 
    54     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    55                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    56     if (sc != RTEMS_SUCCESSFUL)
    57         rtems_set_errno_and_return_minus_one(EIO);
     50    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
     51    fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
     52
     53    msdos_fs_lock(fs_info);
    5854
    5955    ret = fat_file_read(&fs_info->fat, fat_fd, iop->offset, count,
     
    6258        iop->offset += ret;
    6359
    64     rtems_semaphore_release(fs_info->vol_sema);
     60    msdos_fs_unlock(fs_info);
    6561    return ret;
    6662}
     
    8379{
    8480    ssize_t            ret = 0;
    85     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    86     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    87     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    88 
    89     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    90                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    91     if (sc != RTEMS_SUCCESSFUL)
    92         rtems_set_errno_and_return_minus_one(EIO);
     81    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
     82    fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
     83
     84    msdos_fs_lock(fs_info);
    9385
    9486    if (rtems_libio_iop_is_append(iop))
     
    9991    if (ret < 0)
    10092    {
    101         rtems_semaphore_release(fs_info->vol_sema);
     93        msdos_fs_unlock(fs_info);
    10294        return -1;
    10395    }
     
    114106        fat_file_set_ctime_mtime(fat_fd, time(NULL));
    115107
    116     rtems_semaphore_release(fs_info->vol_sema);
     108    msdos_fs_unlock(fs_info);
    117109    return ret;
    118110}
     
    133125)
    134126{
    135     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    136127    msdos_fs_info_t   *fs_info = loc->mt_entry->fs_info;
    137128    fat_file_fd_t     *fat_fd = loc->node_access;
    138129    uint32_t           cl_mask = fs_info->fat.vol.bpc - 1;
    139130
    140     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    141                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    142     if (sc != RTEMS_SUCCESSFUL)
    143         rtems_set_errno_and_return_minus_one(EIO);
     131    msdos_fs_lock(fs_info);
    144132
    145133    buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
     
    155143    buf->st_mtime = fat_fd->mtime;
    156144
    157     rtems_semaphore_release(fs_info->vol_sema);
     145    msdos_fs_unlock(fs_info);
    158146    return RC_OK;
    159147}
     
    173161{
    174162    int                rc = RC_OK;
    175     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    176163    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    177164    fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    178165    uint32_t old_length;
    179166
    180     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    181                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    182     if (sc != RTEMS_SUCCESSFUL)
    183         rtems_set_errno_and_return_minus_one(EIO);
     167    msdos_fs_lock(fs_info);
    184168
    185169    old_length = fat_fd->fat_file_size;
     
    207191    }
    208192
    209     rtems_semaphore_release(fs_info->vol_sema);
     193    msdos_fs_unlock(fs_info);
    210194
    211195    return rc;
     
    226210{
    227211    int                rc = RC_OK;
    228     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    229     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    230     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    231 
    232     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    233                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    234     if (sc != RTEMS_SUCCESSFUL)
    235         rtems_set_errno_and_return_minus_one(EIO);
     212    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
     213    fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
     214
     215    msdos_fs_lock(fs_info);
    236216
    237217    rc = fat_file_update(&fs_info->fat, fat_fd);
    238218    if (rc != RC_OK)
    239219    {
    240         rtems_semaphore_release(fs_info->vol_sema);
     220        msdos_fs_unlock(fs_info);
    241221        return rc;
    242222    }
     
    244224    rc = fat_sync(&fs_info->fat);
    245225
    246     rtems_semaphore_release(fs_info->vol_sema);
    247     if ( rc != 0 )
    248       rtems_set_errno_and_return_minus_one(EIO);
     226    msdos_fs_unlock(fs_info);
    249227
    250228    return RC_OK;
  • cpukit/libfs/src/dosfs/msdos_fsunmount.c

    rb17bcb3 r3b77417  
    5555    fat_shutdown_drive(&fs_info->fat);
    5656
    57     rtems_semaphore_delete(fs_info->vol_sema);
     57    rtems_recursive_mutex_destroy(&fs_info->vol_mutex);
    5858    (*converter->handler->destroy)( converter );
    5959    free(fs_info->cl_buf);
  • cpukit/libfs/src/dosfs/msdos_init.c

    rb17bcb3 r3b77417  
    7676void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry)
    7777{
    78   msdos_fs_info_t *fs_info = mt_entry->fs_info;
    79   rtems_status_code sc = rtems_semaphore_obtain(
    80     fs_info->vol_sema,
    81     RTEMS_WAIT,
    82     RTEMS_NO_TIMEOUT
    83   );
    84   if (sc != RTEMS_SUCCESSFUL) {
    85     rtems_fatal_error_occurred(0xdeadbeef);
    86   }
     78  msdos_fs_lock(mt_entry->fs_info);
    8779}
    8880
    8981void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry)
    9082{
    91   msdos_fs_info_t *fs_info = mt_entry->fs_info;
    92   rtems_status_code sc = rtems_semaphore_release(fs_info->vol_sema);
    93   if (sc != RTEMS_SUCCESSFUL) {
    94     rtems_fatal_error_occurred(0xdeadbeef);
    95   }
     83  msdos_fs_unlock(mt_entry->fs_info);
    9684}
    9785
  • cpukit/libfs/src/dosfs/msdos_initsupp.c

    rb17bcb3 r3b77417  
    5858{
    5959    int                rc = RC_OK;
    60     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    6160    msdos_fs_info_t   *fs_info = NULL;
    6261    fat_file_fd_t     *fat_fd = NULL;
     
    134133    }
    135134
    136     sc = rtems_semaphore_create(3,
    137                                 1,
    138                                 RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
    139                                 RTEMS_INHERIT_PRIORITY,
    140                                 0,
    141                                 &fs_info->vol_sema);
    142     if (sc != RTEMS_SUCCESSFUL)
    143     {
    144         fat_file_close(&fs_info->fat, fat_fd);
    145         fat_shutdown_drive(&fs_info->fat);
    146         free(fs_info->cl_buf);
    147         free(fs_info);
    148         rtems_set_errno_and_return_minus_one( EIO );
    149     }
     135    rtems_recursive_mutex_init(&fs_info->vol_mutex,
     136                               RTEMS_FILESYSTEM_TYPE_DOSFS);
    150137
    151138    temp_mt_entry->mt_fs_root->location.node_access = fat_fd;
  • cpukit/libfs/src/dosfs/msdos_misc.c

    rb17bcb3 r3b77417  
    20732073{
    20742074    int                rc = RC_OK;
    2075     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    20762075    msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    20772076
    2078     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    2079                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    2080     if (sc != RTEMS_SUCCESSFUL)
    2081         rtems_set_errno_and_return_minus_one(EIO);
     2077    msdos_fs_lock(fs_info);
    20822078
    20832079    rc = fat_sync(&fs_info->fat);
    20842080
    2085     rtems_semaphore_release(fs_info->vol_sema);
     2081    msdos_fs_unlock(fs_info);
    20862082    return rc;
    20872083}
  • cpukit/libfs/src/dosfs/msdos_statvfs.c

    rb17bcb3 r3b77417  
    2525  msdos_fs_info_t *fs_info = root_loc->mt_entry->fs_info;
    2626  fat_vol_t *vol = &fs_info->fat.vol;
    27   rtems_status_code sc = RTEMS_SUCCESSFUL;
    2827
    29   sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    30                               MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    31   if (sc != RTEMS_SUCCESSFUL)
    32       rtems_set_errno_and_return_minus_one(EIO);
     28  msdos_fs_lock(fs_info);
    3329
    3430  sb->f_bsize = FAT_SECTOR512_SIZE;
     
    5551      if (rc != RC_OK)
    5652      {
    57         rtems_semaphore_release(fs_info->vol_sema);
     53        msdos_fs_unlock(fs_info);
    5854        return rc;
    5955      }
     
    7268  }
    7369
    74   rtems_semaphore_release(fs_info->vol_sema);
     70  msdos_fs_unlock(fs_info);
    7571  return RC_OK;
    7672}
Note: See TracChangeset for help on using the changeset viewer.