uint_64 MFS_Get_disk_free_space ( MQX_FILE_PTR mfs_fd_ptr ) { MFS_DRIVE_STRUCT_PTR drive_ptr; uint_32 clusters_free; uint_32 error_code; uint_64 bytes_free; if ( MFS_lock_dos_disk( mfs_fd_ptr, &drive_ptr) != MFS_NO_ERROR ) { return 0; } clusters_free = MFS_Get_disk_free_space_internal(drive_ptr,&error_code); if (error_code == MFS_NO_ERROR) { bytes_free = clusters_free << drive_ptr->CLUSTER_POWER_BYTES; } else { bytes_free = 0; } MFS_unlock(drive_ptr,FALSE); return bytes_free; }
/*! * \brief Get number of free clusters/bytes on the disk. * * \param drive_ptr * \param clusters_free_ptr * \param bytes_free_ptr * * \return _mfs_error */ _mfs_error MFS_Get_disk_free_space( MFS_DRIVE_STRUCT_PTR drive_ptr, uint32_t *clusters_free_ptr, uint64_t *bytes_free_ptr) { uint32_t clusters_free; uint32_t error_code; error_code = MFS_lock_and_enter(drive_ptr, 0); if (error_code != MFS_NO_ERROR) { return error_code; } error_code = MFS_Get_disk_free_space_internal(drive_ptr, &clusters_free); if (clusters_free_ptr) { *clusters_free_ptr = clusters_free; } if (bytes_free_ptr) { *bytes_free_ptr = ((uint64_t)clusters_free) << drive_ptr->CLUSTER_POWER_BYTES; } MFS_leave_and_unlock(drive_ptr, 0); return error_code; }
int_32 MFS_Open_Device ( MQX_FILE_PTR fd_ptr, /* [IN] the MFS file handle for the device being opened */ MFS_DRIVE_STRUCT_PTR drive_ptr ) { MQX_FILE_PTR dev_fd; uint_32 sector_size, k; int_32 error_code; dev_fd = drive_ptr->DEV_FILE_PTR; fd_ptr->DEV_DATA_PTR = NULL; drive_ptr->MFS_FILE_PTR = fd_ptr; /* Select partition, if desired */ if (drive_ptr->DRV_NUM) { error_code = ioctl(dev_fd, IO_IOCTL_SEL_PART, &drive_ptr->DRV_NUM); if (error_code) { return error_code; } } /* ** obtain the buffer for configuration data and for storing general ** sector reads */ error_code = _mfs_validate_device(dev_fd, §or_size, &drive_ptr->BLOCK_MODE); if ( error_code ) { /* Device isn't valid */ drive_ptr->MFS_FILE_PTR = NULL; return error_code; } _lwsem_wait(&drive_ptr->SEM); drive_ptr->BPB.SECTOR_SIZE = (uint_16) sector_size; drive_ptr->DIR_SECTOR_PTR = MFS_mem_alloc_system_zero(sector_size); MFS_Invalidate_directory_sector(drive_ptr); if ( drive_ptr->DIR_SECTOR_PTR == NULL ) { _lwsem_post(&drive_ptr->SEM); drive_ptr->MFS_FILE_PTR = NULL; return MFS_INSUFFICIENT_MEMORY; } _mem_set_type(drive_ptr->DIR_SECTOR_PTR, MEM_TYPE_MFS_DIRECTORY_SECTOR); _queue_init(&drive_ptr->HANDLE_LIST, 0); k = drive_ptr->BPB.SECTOR_SIZE; for ( drive_ptr->SECTOR_POWER = 0; !(k & 1); drive_ptr->SECTOR_POWER++ ) { k>>=1; } /* ** read boot sector and get the BIOS Parameter Block */ error_code = MFS_Read_device_sector(drive_ptr, BOOT_SECTOR, drive_ptr->DIR_SECTOR_PTR); if ( error_code == MFS_NO_ERROR ) { drive_ptr->DIR_SECTOR_NUMBER = BOOT_SECTOR; error_code = MFS_Mount_drive_internal(drive_ptr); } if ( !error_code ) { /* Determine the real sector size */ if ( sector_size != drive_ptr->BPB.SECTOR_SIZE ) { _mem_free(drive_ptr->DIR_SECTOR_PTR); drive_ptr->DIR_SECTOR_PTR = MFS_mem_alloc_system_zero(drive_ptr->BPB.SECTOR_SIZE); MFS_Invalidate_directory_sector(drive_ptr); if ( drive_ptr->DIR_SECTOR_PTR == NULL ) { error_code = MFS_INSUFFICIENT_MEMORY; drive_ptr->MFS_FILE_PTR = NULL; } else { _mem_set_type(drive_ptr->DIR_SECTOR_PTR, MEM_TYPE_MFS_DIRECTORY_SECTOR); } } /* Calculate the free space on disk */ #if MFSCFG_CALCULATE_FREE_SPACE_ON_OPEN if ( !error_code ) { MFS_Get_disk_free_space_internal(drive_ptr,(uint_32_ptr)&error_code); } #endif } else { printf(" open fs read secotor err+\n"); drive_ptr->MFS_FILE_PTR = NULL; if(drive_ptr->DIR_SECTOR_PTR) { _mem_free(drive_ptr->DIR_SECTOR_PTR); drive_ptr->DIR_SECTOR_PTR = NULL; } printf(" open fs read secotor err+\n"); } _lwsem_post(&drive_ptr->SEM); return(error_code); }