コード例 #1
0
ファイル: test_dentry.c プロジェクト: yunccll/fat
static void test_root_entries_print()
{
    FAT_PRINT("Root Entries info :\n");
	int ret = 0;
    const char * file_name = "a.img.flp";

    //1. alloc mem
	size_t re_size = 224 * 32;
	uchar * pre = (uchar *) malloc(sizeof(uchar) * re_size);
	assert(pre);

    //2. read dev with root directory sectors 
    DECLARE_DEVICE_R(fdev, file_name);
    ret = fat_dev_read(&fdev, 19*512, (uchar*)pre, re_size);
	assert(ret == re_size);
    fat_dev_destroy(&fdev);

    //3. print the entries
	fat_root_entries_print(pre, re_size);

    const char * fn = "A.TXT";
    FAT_DEBUG("find the file name is [%s]\n", fn);
    fat_dentry_t  * ptr =fat_find_entry_in_sector(pre, re_size, fn);
    if(NULL != ptr){
        FAT_DEBUG("find the dentry with file_name 0x%X\n", ptr);
    }
    else{
        FAT_DEBUG("can not find the dentry with file_name [%s]\nn",fn);
    }

    //4. free the mem 
	free(pre); pre = NULL;
    FAT_PRINT("Finished......\n\n");
}
コード例 #2
0
ファイル: fat.c プロジェクト: utnode/fat
int fat_stat_fat_info(uchar *buf, size_t size)
{
    assert(buf && size % 3 == 0);

	int bad_cluster_cnt = 0;
	int zero_cluster_cnt = 0;
	int used_cluster_cnt = 0;
	int val = 0;
	size_t i;
	for(i = 0; i < size%3*2; ++i)
	{	
		val = offset_to_cluster_val(buf, clusno_to_offset(i));
		if(val == NOT_USED_CLUSTER)
			++zero_cluster_cnt;
		else if(val >= BAD_CLUSTER_NO_START && val <= BAD_CLUSTER_NO_END)
			++ bad_cluster_cnt;	
		else
			++ used_cluster_cnt;
	}
	FAT_DEBUG("zero cluster : %d\n", zero_cluster_cnt);
	FAT_DEBUG("bad cluster 	: %d\n", zero_cluster_cnt);
	FAT_DEBUG("used cluster : %d\n", zero_cluster_cnt);
    return 0 ;
}
コード例 #3
0
bool Fat_FileRead(FAT_FILE_HANDLE hFileHandle, void *pBuffer, const int nBufferSize){
    FAT_FILE_INFO *f = (FAT_FILE_INFO *)hFileHandle;
    VOLUME_INFO *pVol;
    alt_u32 Pos, PhysicalSecter, NextCluster, Cluster;
    alt_u32 BytesPerCluster, nReadCount=0, nClusterSeq;
    int s;
    bool bSuccess= TRUE;
    
    if (!f || !f->Fat)
        return FALSE;
    pVol = (VOLUME_INFO *)f->Fat;        
    
    if (!f->IsOpened){
        FAT_DEBUG(("[FAT] Fat_FileRead, file not opened\r\n"));
        return bSuccess;
    }        
        
    BytesPerCluster = pVol->nBytesPerCluster; //gVolumeInfo.BPB_BytsPerSec * gVolumeInfo.BPB_SecPerCluster;  
    Pos = f->SeekPos;
    if (BytesPerCluster == 32768){
        nClusterSeq = Pos >> 15;
        Pos -= (f->ClusterSeq << 15);
    }else if (BytesPerCluster == 16384){