Exemplo n.º 1
0
/***********SAVE_ORPHANS***************/
void orphan_search(uint8_t *image_buf, struct bpb33* bpb, int * refcount, int FATsz) {
	int count = 0; //count orphans
	int i = 2;
	for(; i < FATsz; i++)
	{
		uint16_t cluster = get_fat_entry(i, image_buf, bpb);
		if(cluster != (FAT12_MASK & CLUST_FREE) && cluster != (FAT12_MASK & CLUST_BAD) && refcount[i] == 0) 
		{
			printf("FOUND AN ORPHAN, CLUSTER # = %d\n", i);
			count++;
			int orphan_size = 1;
			refcount[i] = 1;
			uint16_t orphan_cluster = cluster;
		
			while(is_valid_cluster(orphan_cluster, bpb)) 
			{
				if (refcount[orphan_cluster] == 1)
				{
					set_fat_entry(orphan_cluster, (FAT12_MASK & CLUST_EOFS), image_buf, bpb);
				}
				else if(refcount[orphan_cluster] > 1)
				{
					struct direntry *dirent = (struct direntry*)cluster_to_addr(cluster, image_buf, bpb);
					dirent->deName[0] = SLOT_DELETED;
					refcount[orphan_cluster]--;
					printf("DELETED\n");
				}
				else if(refcount[orphan_cluster] < 1)
				{
					refcount[orphan_cluster]++;
				}
			orphan_cluster = get_fat_entry(orphan_cluster, image_buf, bpb);
			orphan_size++;
			}
			//got to concatanate stuff
			struct direntry *dirent = (struct direntry*)root_dir_addr(image_buf, bpb);
			char name[5];
			sprintf(name, "%d", count);
			char str[1024] = "";
			strcat(str, "located");
			strcat(str, name);
			strcat(str, ".dat\0");
			char * file_name = str;
			create_dirent(dirent, file_name, i, orphan_size * 512, image_buf, bpb);
			printf("added %s to directory \n", str);
			printf("orphan cluster chain size = %d \n", orphan_size);
		}
	}
	printf("orphans saved: %d\n", count);
}
Exemplo n.º 2
0
int main(int argc, char** argv)
{
    uint8_t *image_buf;
    int fd;
    struct bpb33* bpb;
    if (argc != 2)
    {
	usage(argv[0]);
    }

    image_buf = mmap_file(argv[1], &fd);
    bpb = check_bootsector(image_buf);
    printf("Root directory address is: %lu\n", root_dir_addr(image_buf, bpb));
    traverse_root(image_buf, bpb);

    unmmap_file(image_buf, &fd);

    return 0;
}