Esempio n. 1
0
/* 
 * given a directory entry the function counts the number of
 * clusters referred to by the entry.
 */
int count_clusters(struct direntry *dirent, 
                   uint8_t *image_buf, struct bpb33 *bpb) {
    uint16_t cluster = getushort(dirent->deStartCluster);
    uint16_t cluster_size = bpb->bpbBytesPerSec * bpb->bpbSecPerClust;
    int num_bytes = 0; uint16_t prev_cluster = cluster;
    append_clusters(cluster);
    if (is_end_of_file(cluster)) num_bytes = 512;
    while (!is_end_of_file(cluster) && cluster < usable_clusters) {   
        if (cluster == bad_cluster) {
            printf("Bad cluster: cluster number %d \n\n", cluster);
            set_fat_entry(prev_cluster, eof_cluster, image_buf, bpb);
            break;
        }
        if (cluster == free_cluster) {
            set_fat_entry(prev_cluster, eof_cluster, image_buf, bpb);
            break;   
        }
        num_bytes += cluster_size;
        prev_cluster = cluster;
        cluster = get_fat_entry(cluster, image_buf, bpb);
        if (prev_cluster == cluster) {
            printf("Self referential cluster. \n\n");
            set_fat_entry(prev_cluster, eof_cluster, image_buf, bpb);
            break;   
        }
        append_clusters(cluster);
    }

    return num_bytes;
}
Esempio n. 2
0
/*
 * repair an inconsistent file
 */
void repair(struct direntry *dirent, uint8_t *image_buf, struct bpb33 *bpb, int actual_size) {
    
    uint16_t cluster = getushort(dirent->deStartCluster);
    uint16_t cluster_size = bpb->bpbBytesPerSec * bpb->bpbSecPerClust;
    uint16_t prev_cluster = cluster;

    uint16_t num_bytes = 0;
    
    // accumulate all the related clusters in the FAT
    while (num_bytes < actual_size) {
        num_bytes += cluster_size;
        prev_cluster = cluster;
        cluster = get_fat_entry(cluster, image_buf, bpb);
    }
    
    if (num_bytes != 0) {
        set_fat_entry(prev_cluster, eof_cluster, image_buf, bpb);
    }
    
    // update all other clusters attached and mark them as free
    while (!is_end_of_file(cluster)) {
        uint16_t old_cluster = cluster;
        cluster = get_fat_entry(cluster, image_buf, bpb);
        set_fat_entry(old_cluster, free_cluster, image_buf, bpb);
    }
}
Esempio n. 3
0
uint32_t get_file_length(uint16_t cluster, uint8_t *image_buf, struct bpb33* bpb)
{
    uint32_t length = 1;

    cluster = get_fat_entry(cluster, image_buf, bpb);
    while (!is_end_of_file(cluster)) {
        cluster = get_fat_entry(cluster, image_buf, bpb);
        length++;
    }

    return length;
}
Esempio n. 4
0
/*
 * calculate the size of a cluster chain
 */
uint32_t size_of_cluster(uint16_t cluster, uint8_t *image_buf, 
                         struct bpb33 *bpb) {
    uint16_t cluster_size = bpb->bpbBytesPerSec * bpb->bpbSecPerClust;
    uint32_t num_bytes = 0;
    append_clusters(cluster);
    while (!is_end_of_file(cluster)) {   
        if (cluster == bad_cluster) {
            printf("Bad cluster: cluster number %d \n\n", cluster);
        }
        num_bytes += cluster_size;
        cluster = get_fat_entry(cluster, image_buf, bpb);
        append_clusters(cluster);
    }
    return num_bytes;
}
Esempio n. 5
0
void free_clusters(uint16_t cluster_begin, uint16_t cluster_end, uint8_t *image_buf, struct bpb33* bpb) {
    uint16_t current_cluster = cluster_begin;

    while(1) {
        uint16_t next_cluster = get_fat_entry(current_cluster, image_buf, bpb);

        set_fat_entry(current_cluster, FAT12_MASK&CLUST_FREE, image_buf, bpb);

        if (current_cluster == cluster_end || is_end_of_file(next_cluster)) {
            break;
        }

        current_cluster = next_cluster;
    }

    set_fat_entry(cluster_begin, FAT12_MASK&CLUST_EOFS, image_buf, bpb);
}
Esempio n. 6
0
    bool FrameStreamReader::read()
    {
        bool isSuccessful = true;

        if (m_isEndOfFile)
        {
            m_inputStream->seek_to_first_frame();

            isSuccessful = m_inputStream->read_frame_description(m_frameDescription);
            if (isSuccessful)
            {
                m_pulser.set_period(1 / m_frameDescription->framePeriod);
            }

            m_isEndOfFile = false;
        }

        m_pulser.stop();

        if (!m_pulser.is_pulse())
        {
            return !isSuccessful;
        }

        isSuccessful = m_inputStream->read_frame(m_frame);

        if (!is_end_of_file())
        {
            isSuccessful = m_inputStream->read_frame_description(m_frameDescription);

            if (isSuccessful)
            {
                m_pulser.set_period(1 / m_frameDescription->framePeriod);
            }
        }

        m_pulser.start();

        return isSuccessful;
    }
Esempio n. 7
0
//==========================================================| MAIN
int main( int argc, char *argv[] ) {
	DEBUG_LEVEL = 0;

	logger log = { debug_function };
	log.debug( INFO(1), "SHELL START" );
	
	int status;
	char* new_line;
	line* parsed_line;
	
    shell_init();
    while( ! is_end_of_file() ) {
        print_prompt();
        new_line = get_line();
        if( !new_line ) continue;
        parsed_line = parseline( new_line );
        execute_line( parsed_line );   
    }
    
    log.debug( INFO(1), "SHELL STOP" );
    exit( EXIT_SUCCESS );
}
Esempio n. 8
0
void mark_file_clusters_used(int usedClusters[], uint16_t cluster, uint32_t bytes_remaining, uint8_t *image_buf, struct bpb33* bpb)
{
    usedClusters[cluster] = 1;

    int clust_size = bpb->bpbSecPerClust * bpb->bpbBytesPerSec;
    int total_clusters = bpb->bpbSectors / bpb->bpbSecPerClust;

    if (cluster == 0) {
        fprintf(stderr, "Bad file termination\n");
        return;
    } else if (cluster > total_clusters) {
        abort(); /* this shouldn't be able to happen */
    }

    uint16_t next_cluster = get_fat_entry(cluster, image_buf, bpb);

    if (is_end_of_file(next_cluster)) {
        return;
    } else {
        mark_file_clusters_used(usedClusters, get_fat_entry(cluster, image_buf, bpb), bytes_remaining - clust_size, image_buf, bpb);
    }
}
Esempio n. 9
0
int compare(char *filename, uint16_t followclust, struct direntry *dirent, uint8_t *image_buf, struct bpb33* bpb){
	//will loop through fat until eof marking the good/bad/free clusters and freeing them
	uint32_t realsize = getulong(dirent->deFileSize);
	uint32_t clustersize = bpb->bpbSecPerClust*bpb->bpbBytesPerSec;
	int expected_num_clust = (realsize+511)/clustersize;  // finds num clusters according to the meta data
	
	//find actual num clusters in fat
	uint16_t fatent = get_fat_entry(followclust, image_buf, bpb);
	uint16_t prev_fatent = fatent;
	int count = 1;
	
	while(!is_end_of_file(fatent)) {  //loops through checking if eof
		uint16_t temp =get_fat_entry(fatent, image_buf, bpb);
		if (fatent == (FAT12_MASK & CLUST_BAD)){ //if the fatent is bad it will mark it in the array
			printf("Bad cluster");
			desperation[followclust+count]=-1;
			printf("File is inconsistant: name is: %s\n",filename);
			}
		
		

		if(count>=expected_num_clust)	//if we have more clusters than expected
			{	
			
			if (count==expected_num_clust) {  //will only happen once
				printf("count is greater\n");
				//will set the previous entry to be eof and fee the current cluster
				//will also set desperation =2 at the eof and 3 at the free cluster
				// this is becasue we want a record in desperation of free normal or not looked at clusters
				set_fat_entry(prev_fatent,FAT12_MASK&CLUST_EOFS, image_buf, bpb);
				desperation[followclust+count-1]=2;
				set_fat_entry(fatent, FAT12_MASK&CLUST_FREE, image_buf, bpb);
				desperation[followclust+count]=3;
				printf("file is inconsistant!!! name is: %s\n",filename);
			
				}
		
			else {
				// if we are over the size just free current cluster
				set_fat_entry(fatent, FAT12_MASK&CLUST_FREE, image_buf, bpb);
			
				}
			//when count is over expected we will put 3 in every cluster over size eof
			desperation[followclust+count]=3;
			fatent=temp;
			count++;
			}
		
		else {

			//if we are still running through the clusters then if we find a free set it as 3 or if it is just normal then set it as 1
			if (fatent == (FAT12_MASK&CLUST_FREE)) {
				printf("FREE CLUSTER BEFORE EOF WEEWOOWEEWOO");
				desperation[followclust+count]=3;
				
				}
			else {
				desperation[followclust+count]=1;
				}
			prev_fatent=fatent;
			fatent=get_fat_entry(fatent,image_buf, bpb);
			count++;
			}
			
		
		}
	desperation[followclust+count]=2;//set this block as an eof in desperation
	if (expected_num_clust>count){
		//if at the end cluster is greater than expected change the size in the meta data to be what the fat size is
		uint32_t clustersize = bpb->bpbSecPerClust*bpb->bpbBytesPerSec;
		putulong(dirent->deFileSize, (count*clustersize));
		printf("File is inconsistant!!! name is: %s \n", filename);
	}
	//loop through the current files clusters on desperation and until you hit the eof
	int i= followclust;
	int countgucci=0;
	while (desperation[i]!=2)
		{
		if (desperation[i]==1) {
			countgucci++;
			}
		}
	//put the newsize into the metadata
	putulong(dirent->deFileSize, (countgucci*clustersize));
	return count;
}