예제 #1
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);

    
	//uint16_t cluster = 0;

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

	int	FATsz = bpb->bpbSectors;
	int *refcount = (int *)malloc(sizeof(int)*FATsz);
	memset((int*)refcount, 0, FATsz * sizeof(int));  //creates array of all 0s of FAT size
	
	/*int i = 0;
    for ( ; i < bpb->bpbRootDirEnts; i++)
    { 
        uint16_t followclust = print_dirent(dirent,0, image_buf, bpb, refcount );
        if (is_valid_cluster(followclust, bpb))

            follow_dir(followclust, 1, image_buf, bpb, refcount);

        dirent++;
    }*/



	//where we run dope functions
	printf("\n");
	checkandfix(image_buf, bpb, refcount);
	orphan_search(image_buf, bpb, refcount, FATsz);

	free(refcount);
	






    unmmap_file(image_buf, &fd);
    return 0;
}
예제 #2
0
파일: scandisk.c 프로젝트: mchav/ScanDisk
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);
    traverse_root(image_buf, bpb);
    foster_orphans(image_buf, bpb);

    free_clusters();
    free(bpb);
    unmmap_file(image_buf, &fd);
    return 0;
}
예제 #3
0
int main(int argc, char** argv)
{
    uint8_t *image_buf;
    int fd;
    struct bpb33* bpb;
    if (argc != 2)
    {
	usage(argv[0]);
    }
    char filename[128];
    image_buf = mmap_file(argv[1], &fd);
    bpb = check_bootsector(image_buf);
    traverse_root(filename, image_buf, bpb);

    unmmap_file(image_buf, &fd);

    return 0;
}
예제 #4
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;
}
예제 #5
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);

    // your code should start here...






    unmmap_file(image_buf, &fd);
    return 0;
}
예제 #6
0
int main(int argc, char** argv)
{
    uint8_t *image_buf;
    int fd;
    struct bpb33* bpb;
    if (argc != 2) {
        usage();
    }

    image_buf = mmap_file(argv[1], &fd);
    bpb = check_bootsector(image_buf);

    int total_clusters = bpb->bpbSectors / bpb->bpbSecPerClust;
    int clust_size = bpb->bpbSecPerClust * bpb->bpbBytesPerSec;
    int used_clusters[total_clusters];
    check_lost_files(used_clusters, 0, image_buf, bpb);

    int i;
    int shownPrefix = 0;
    for (i = 2; i < total_clusters; i++) {
        if (used_clusters[i] == 0 && get_fat_entry(i, image_buf, bpb) != CLUST_FREE) {
            if (!shownPrefix) {
                printf("Unreferenced:");
                shownPrefix = 1;
            }
            printf(" %i", i);
        }

        if (i == total_clusters - 1 && shownPrefix) {
            printf("\n");
        }
    }

    int foundCount = 1;
    shownPrefix = 0;
    for (i = 2; i < total_clusters; i++) {
        if (used_clusters[i] == 0 && get_fat_entry(i, image_buf, bpb) != CLUST_FREE) {
            if (!shownPrefix) {
                printf("Lost File: ");
            }

            uint16_t size = get_file_length(i, image_buf, bpb);
            printf("%i %i\n", i, size);

            struct direntry *dirent = (struct direntry*) cluster_to_addr(0, image_buf, bpb);
            uint32_t size_bytes = size * clust_size;

            const char base[] = "found";
            const char extension[] = ".dat";
            char filename [13];
            sprintf(filename, "%s%i%s", base, foundCount++, extension);

            create_dirent(dirent, filename, i, size_bytes, image_buf, bpb);

            check_lost_files(used_clusters, 0, image_buf, bpb);
        }

        if (i == total_clusters - 1 && shownPrefix) {
            printf("\n");
        }
    }

    check_file_length(0, image_buf, bpb);

    close(fd);
    exit(0);
}