Esempio n. 1
0
/*!
 * \brief
 *
 * Locks the drive and executes operations to be done upon entering MFS call.
 * Cannot be called from an ISR.
 *
 * \param drive_ptr
 * \param mode
 *
 * \return _mfs_error
 */
_mfs_error MFS_lock_and_enter(
    MFS_DRIVE_STRUCT_PTR drive_ptr,
    int mode)
{
    _mfs_error error_code;

    error_code = MFS_lock(drive_ptr);
    if (error_code != MFS_NO_ERROR)
    {
        return error_code;
    }

    error_code = MFS_enter(drive_ptr, mode);
    if (error_code != MFS_NO_ERROR)
    {
        MFS_unlock(drive_ptr);
    }

    return error_code;
}
Esempio n. 2
0
int_32 MFS_Close_Device
    (
    MQX_FILE_PTR             fd_ptr /* [IN] the MFS file handle for the device being closed */
    )
{
    MFS_DRIVE_STRUCT_PTR      drive_ptr;
    FILESYSTEM_INFO_DISK_PTR  fsinfo_ptr;
    int_32                    result = MFS_NO_ERROR;

#if !MFSCFG_READ_ONLY
#if MFSCFG_READ_ONLY_CHECK
    if (MFS_is_read_only (fd_ptr, NULL))
    {
        result = MFS_DISK_IS_WRITE_PROTECTED;
    }
#endif
    if (result != MFS_DISK_IS_WRITE_PROTECTED)
    {
        result = _io_ioctl(fd_ptr, IO_IOCTL_FLUSH_OUTPUT, NULL); 
    }
#endif

    MFS_lock(fd_ptr, &drive_ptr);

#if !MFSCFG_READ_ONLY
    if (result != MFS_DISK_IS_WRITE_PROTECTED)
    {
        MFS_Flush_caches(drive_ptr);
    }
#endif

    if ( _queue_is_empty(&drive_ptr->HANDLE_LIST) )
    {
        if ( drive_ptr->FAT_TYPE == MFS_FAT32 )
        {
#if !MFSCFG_READ_ONLY
            if (result != MFS_DISK_IS_WRITE_PROTECTED)
            {
                fsinfo_ptr = (FILESYSTEM_INFO_DISK_PTR)drive_ptr->DATA_SECTOR_PTR;
                if ( fsinfo_ptr != NULL )
                {
                    htodl(fsinfo_ptr->LEAD_SIG,   FSI_LEADSIG);
                    htodl(fsinfo_ptr->STRUCT_SIG, FSI_STRUCTSIG);
                    htodl(fsinfo_ptr->FREE_COUNT, drive_ptr->FREE_COUNT);
                    htodl(fsinfo_ptr->NEXT_FREE,  drive_ptr->NEXT_FREE_CLUSTER);
                    htodl(fsinfo_ptr->TRAIL_SIG,  FSI_TRAILSIG);

                    MFS_Write_device_sector(drive_ptr, FSINFO_SECTOR, (char_ptr)fsinfo_ptr);
                }
            }
#endif
        }

        MFS_free_drive_data(drive_ptr, TRUE);

        drive_ptr->MFS_FILE_PTR = NULL;
        result = MFS_NO_ERROR;
    }
    else
    {
    	/* liutest add for get unclose handle */
    	MFS_HANDLE_PTR          next_handle;
        next_handle =  (MFS_HANDLE_PTR) _queue_head(&drive_ptr->HANDLE_LIST);
          while ( next_handle )
          {
        	  printf("unclose handle 0x%X\n",(uint_32)next_handle);
               next_handle =  (MFS_HANDLE_PTR) _queue_next(&drive_ptr->HANDLE_LIST, (QUEUE_ELEMENT_STRUCT_PTR) next_handle);
          }  
          
        result = MFS_SHARING_VIOLATION;
        /* MFS_free_drive_data(drive_ptr, TRUE);

         drive_ptr->MFS_FILE_PTR = NULL;
         result = MFS_NO_ERROR;*/
    }  

    MFS_unlock(drive_ptr,FALSE);

    return result;

}