Example #1
0
/* 
 * follow dir recursively scans through the file hierarchy
 * we check for consistency for every directory entry
 * taken from dos with some modifications.
 */
void follow_dir(uint16_t cluster, int indent,
               uint8_t *image_buf, struct bpb33* bpb) {   
    while (is_valid_cluster(cluster, bpb)) {   
        append_clusters(cluster);
        struct direntry *dirent = (struct direntry*)
                               cluster_to_addr(cluster, image_buf, bpb);
                               
        int numDirEntries = (bpb->bpbBytesPerSec * bpb->bpbSecPerClust) 
                            / sizeof(struct direntry);
                            
        char buffer[MAXFILENAME];
        int i = 0;
        for ( ; i < numDirEntries; i++) {
            append_clusters(cluster);
            uint16_t followclust = get_dirent(dirent, buffer);
   
            chkerr(dirent, buffer, image_buf, bpb);
            if (followclust) {
                follow_dir(followclust, indent+1, image_buf, bpb);
            }
            dirent++;
        }
        cluster = get_fat_entry(cluster, image_buf, bpb);
    }
}
Example #2
0
/* 
 * traverse root - taken from dos files. modified collectively
 * recursively follows directories from the root checking each file
 * for consistency as it goes
 */
void traverse_root(uint8_t *image_buf, struct bpb33* bpb) {

    uint16_t cluster = 0;
    struct direntry* dirent = (struct direntry*) 
                              cluster_to_addr(cluster, image_buf, bpb);

    char buffer [MAXFILENAME]; //buffer for storing file names

    int i;
    for (i = 0; i < bpb->bpbRootDirEnts; i++) {
        uint16_t followclust = get_dirent(dirent, buffer);
        // deal with normal files
        if (dirent->deAttributes == ATTR_NORMAL) { 
            chkerr(dirent, buffer, image_buf, bpb);
        }

        append_clusters(followclust); // append file cluster

        if (is_valid_cluster(followclust, bpb)) {
            append_clusters(followclust);
            follow_dir(followclust, 1, image_buf, bpb);
        }

        dirent++;
    }
}
Example #3
0
void checkandfix(uint8_t *image_buf, struct bpb33* bpb, int *refcount)
{
	uint16_t cluster = 0;
	struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);
	int i = 0;
    for ( ; i < bpb->bpbRootDirEnts; i++)
    {
		//to print directory use print_dirent (change to get_dirent when done)
        uint16_t followclust = print_dirent(dirent, 0, image_buf, bpb, refcount);
	
		//char buffer[MAXFILENAME]; 
        //uint16_t followclust = get_dirent(dirent, buffer);
        if (is_valid_cluster(followclust, bpb))
		{
			refcount[followclust]++; //updating refcount for index of current cluster
			printf("refcount is: %d, followclust is: %d\n\n",  refcount[followclust], followclust);
        	follow_dir(followclust, 1, image_buf, bpb, refcount);
        }
		


		//this is where the magic happens...or in print_dirent? I'd rather do 
		// it here
		
		

        dirent++;
    }

}
Example #4
0
/************FOLLOW_DIR***************/
void follow_dir(uint16_t cluster, int indent, uint8_t *image_buf, struct bpb33* bpb, int* refcount)
{
    while (is_valid_cluster(cluster, bpb))
    {
        struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);

        int numDirEntries = (bpb->bpbBytesPerSec * bpb->bpbSecPerClust) / sizeof(struct direntry); //can't we just use int numDirEntries = bpb->RootDirEnts??
        int i = 0;
	
	for ( ; i < numDirEntries; i++)
	{
           // char buffer[MAXFILENAME]; 
           // uint16_t followclust = get_dirent(dirent, buffer);
			uint16_t followclust = print_dirent(dirent, indent, image_buf, bpb, refcount);		//changed to print as follow_dir is called	
			
            if (followclust)
			{
				refcount[followclust]++;
                follow_dir(followclust, indent+1, image_buf, bpb, refcount);
			}
            dirent++;
	}

	cluster = get_fat_entry(cluster, image_buf, bpb);
    }
}
Example #5
0
void follow_dir(char* filename, uint16_t cluster, int indent,
		uint8_t *image_buf, struct bpb33* bpb)
{
    while (is_valid_cluster(cluster, bpb))
    {
        struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);

        int numDirEntries = (bpb->bpbBytesPerSec * bpb->bpbSecPerClust) / sizeof(struct direntry);
     
	for ( int i=0; i < numDirEntries; i++)
	{
            
   		uint16_t followclust = print_dirent(filename, dirent, indent);
		int count = -1;
		if (followclust!= 0) {
			count=compare(filename, followclust,dirent,image_buf,bpb);
			}
		else {
			
			}		
		//printf("count: %i\n", count);
            if (followclust !=0)
                follow_dir(filename, followclust, indent+1, image_buf, bpb);
            dirent++;
	}

	cluster = get_fat_entry(cluster, image_buf, bpb);
    }
}
Example #6
0
void traverse_root(uint8_t *image_buf, struct bpb33* bpb)
{
    uint16_t cluster = 0;

    struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);
    printf("The address of the first dirent is: %lu\n", dirent);
    int i = 0;
    for ( ; i < bpb->bpbRootDirEnts; i++)
    {
        uint16_t followclust = print_dirent(dirent, 0);
        if (is_valid_cluster(followclust, bpb))
            follow_dir(followclust, 1, image_buf, bpb);

        dirent++;
    }
}
Example #7
0
void traverse_root(uint8_t *image_buf, struct bpb33* bpb)
{
    uint16_t cluster = 0;

    struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);

    int i = 0;
    for ( ; i < bpb->bpbRootDirEnts; i++)
    {
        uint16_t followclust = print_dirent(dirent, 0);
        if (is_valid_cluster(followclust, bpb)){
            //dirent->deReferenceCount=1;
            follow_dir(followclust, 1, image_buf, bpb);
            }

        dirent++;
    }
    //printf("ReferenceCount= %d\n", dirent->deReferenceCount);
}
Example #8
0
void follow_dir(uint16_t cluster, int indent,
		uint8_t *image_buf, struct bpb33* bpb)
{
    while (is_valid_cluster(cluster, bpb))
    {
        struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);

        int numDirEntries = (bpb->bpbBytesPerSec * bpb->bpbSecPerClust) / sizeof(struct direntry);
        int i = 0;
	for ( ; i < numDirEntries; i++)
	{
            
            uint16_t followclust = print_dirent(dirent, indent);
            if (followclust)
                follow_dir(followclust, indent+1, image_buf, bpb);
            dirent++;
	}

	cluster = get_fat_entry(cluster, image_buf, bpb);
    }
}
Example #9
0
void traverse_root(char * filename, uint8_t *image_buf, struct bpb33* bpb)
{
	
    uint16_t cluster = 0;

    struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);

    int i = 0;
    for ( ; i < bpb->bpbRootDirEnts; i++)
    {
        uint16_t followclust = print_dirent(filename,dirent, 0);
        if (is_valid_cluster(followclust, bpb)) {
            follow_dir(filename, followclust, 1, image_buf, bpb);
		printf("Cluster is valid\n");
		}
        dirent++;
    }
printf("finished going through stuff\n");
	//
	find_orphans(image_buf, bpb);
			
			
		
}