Beispiel #1
0
main()
{
 read_boot(2);
 fat=(char *)malloc(s0->secperfat*512);
 absread(2,s0->secperfat,1,fat);
 mark_16b(10373,0xfff7,fat);
 abswrite(2,s0->secperfat,1,fat);
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    DOS_FS fs;
    rw = 0;

    char *device = NULL;
    char *label = NULL;

    check_atari();

    if (argc < 2 || argc > 3)
        usage(1);

    if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
        usage(0);
    else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
        printf( "dosfslabel " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
        exit(0);
    }

    device = argv[1];
    if (argc == 3) {
        label = argv[2];
        if (strlen(label) > 11) {
            fprintf(stderr,
                    "dosfslabel: labels can be no longer than 11 characters\n");
            exit(1);
        }
        rw = 1;
    }

    fs_open(device, rw);
    read_boot(&fs);
    if (!rw) {
        fprintf(stdout, "%s\n", fs.label);
        exit(0);
    }

    write_label(&fs, label);
    fs_close(rw);
    return 0;
}
Beispiel #3
0
NTSTATUS
WINAPI
VfatChkdsk(IN PUNICODE_STRING DriveRoot,
           IN BOOLEAN FixErrors,
           IN BOOLEAN Verbose,
           IN BOOLEAN CheckOnlyIfDirty,
           IN BOOLEAN ScanDrive,
           IN PFMIFSCALLBACK Callback)
{
#if 0
    BOOLEAN verify;
    BOOLEAN salvage_files;
#endif
    //ULONG free_clusters;
    //DOS_FS fs;

    /* Store callback pointer */
    ChkdskCallback = Callback;
    FsCheckMemQueue = NULL;

    /* Set parameters */
    FsCheckFlags = 0;
    if (Verbose)
        FsCheckFlags |= FSCHECK_VERBOSE;

    FsCheckTotalFiles = 0;

#if 0
    verify = TRUE;
    salvage_files = TRUE;

    /* Open filesystem */
    fs_open(DriveRoot,FixErrors);

    if (CheckOnlyIfDirty && !fs_isdirty())
    {
        /* No need to check FS */
        return fs_close(FALSE);
    }

    read_boot(&fs);
    if (verify)
        VfatPrint("Starting check/repair pass.\n");

    while (read_fat(&fs), scan_root(&fs))
        qfree(&FsCheckMemQueue);

    if (ScanDrive)
        fix_bad(&fs);

    if (salvage_files)
        reclaim_file(&fs);
    else
        reclaim_free(&fs);

    free_clusters = update_free(&fs);
    file_unused();
    qfree(&FsCheckMemQueue);
    if (verify)
    {
        VfatPrint("Starting verification pass.\n");
        read_fat(&fs);
        scan_root(&fs);
        reclaim_free(&fs);
        qfree(&FsCheckMemQueue);
    }

    if (fs_changed())
    {
        if (FixErrors)
        {
            if (FsCheckFlags & FSCHECK_INTERACTIVE)
                FixErrors = get_key("yn","Perform changes ? (y/n)") == 'y';
            else
                VfatPrint("Performing changes.\n");
        }
        else
        {
            VfatPrint("Leaving file system unchanged.\n");
        }
    }

    VfatPrint("%wZ: %u files, %lu/%lu clusters\n", DriveRoot,
        FsCheckTotalFiles, fs.clusters - free_clusters, fs.clusters );

    if (FixErrors)
    {
        /* Dismount the volume */
        fs_dismount();

        /* Unlock the volume */
        fs_lock(FALSE);
    }

    /* Close the volume */
    return fs_close(FixErrors) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
#else
    return STATUS_SUCCESS;
#endif
}
Beispiel #4
0
int main(int argc, char **argv)
{
    DOS_FS fs;
    int salvage_files, verify, c;
    uint32_t free_clusters = 0;

    memset(&fs, 0, sizeof(fs));
    salvage_files = verify = 0;
    rw = interactive = 1;
    check_atari();

    while ((c = getopt(argc, argv, "Aac:d:bflnprtu:vVwy")) != -1)
	switch (c) {
	case 'A':		/* toggle Atari format */
	    atari_format = !atari_format;
	    break;
	case 'a':
	case 'p':
	case 'y':
	    rw = 1;
	    interactive = 0;
	    salvage_files = 1;
	    break;
	case 'b':
	    rw = 0;
	    interactive = 0;
	    boot_only = 1;
	    break;
	case 'c':
	    set_dos_codepage(atoi(optarg));
	    break;
	case 'd':
	    file_add(optarg, fdt_drop);
	    break;
	case 'f':
	    salvage_files = 1;
	    break;
	case 'l':
	    list = 1;
	    break;
	case 'n':
	    rw = 0;
	    interactive = 0;
	    break;
	case 'r':
	    rw = 1;
	    interactive = 1;
	    break;
	case 't':
	    test = 1;
	    break;
	case 'u':
	    file_add(optarg, fdt_undelete);
	    break;
	case 'v':
	    verbose = 1;
	    break;
	case 'V':
	    verify = 1;
	    break;
	case 'w':
	    write_immed = 1;
	    break;
	default:
	    usage(argv[0]);
	}
    set_dos_codepage(-1);	/* set default codepage if none was given in command line */
    if ((test || write_immed) && !rw) {
	fprintf(stderr, "-t and -w can not be used in read only mode\n");
	exit(2);
    }
    if (optind != argc - 1)
	usage(argv[0]);

    printf("fsck.fat " VERSION " (" VERSION_DATE ")\n");
    fs_open(argv[optind], rw);

    read_boot(&fs);
    if (boot_only)
	goto exit;

    if (verify)
	printf("Starting check/repair pass.\n");
    while (read_fat(&fs), scan_root(&fs))
	qfree(&mem_queue);
    if (test)
	fix_bad(&fs);
    if (salvage_files)
	reclaim_file(&fs);
    else
	reclaim_free(&fs);
    free_clusters = update_free(&fs);
    file_unused();
    qfree(&mem_queue);
    if (verify) {
	n_files = 0;
	printf("Starting verification pass.\n");
	read_fat(&fs);
	scan_root(&fs);
	reclaim_free(&fs);
	qfree(&mem_queue);
    }

exit:
    if (fs_changed()) {
	if (rw) {
	    if (interactive)
		rw = get_key("yn", "Perform changes ? (y/n)") == 'y';
	    else
		printf("Performing changes.\n");
	} else
	    printf("Leaving filesystem unchanged.\n");
    }

    if (!boot_only)
	printf("%s: %u files, %lu/%lu clusters\n", argv[optind],
	       n_files, (unsigned long)fs.clusters - free_clusters, (unsigned long)fs.clusters);

    return fs_close(rw) ? 1 : 0;
}
Beispiel #5
0
int main(int argc,char **argv)
{
    DOS_FS fs;
    int rw,salvage_files,verify,c;
	unsigned n_files_check=0, n_files_verify=0;
    unsigned long free_clusters;

    rw = salvage_files = verify = 0;
    interactive = 1;
    check_atari();

    while ((c = getopt(argc,argv,"Aad:flnprtu:vVwy")) != EOF)
	switch (c) {
	    case 'A': /* toggle Atari format */
	  	atari_format = !atari_format;
		break;
	    case 'a':
	    case 'p':
	    case 'y':
		rw = 1;
		interactive = 0;
		salvage_files = 1;
		break;
	    case 'd':
		file_add(optarg,fdt_drop);
		break;
	    case 'f':
		salvage_files = 1;
		break;
	    case 'l':
		list = 1;
		break;
	    case 'n':
		rw = 0;
		interactive = 0;
		break;
	    case 'r':
		rw = 1;
		interactive = 1;
		break;
	    case 't':
		test = 1;
		break;
	    case 'u':
		file_add(optarg,fdt_undelete);
		break;
	    case 'v':
		verbose = 1;
		printf("dosfsck " VERSION " (" VERSION_DATE ")\n");
		break;
	    case 'V':
		verify = 1;
		break;
	    case 'w':
		write_immed = 1;
		break;
	    default:
		usage(argv[0]);
	}
    if ((test || write_immed) && !rw) {
	fprintf(stderr,"-t and -w require -a or -r\n");
	exit(2);
    }
    if (optind != argc-1) usage(argv[0]);

    printf( "dosfsck " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
    fs_open(argv[optind],rw);
    read_boot(&fs);
    if (verify) printf("Starting check/repair pass.\n");
    while (read_fat(&fs), scan_root(&fs)) qfree(&mem_queue);
    if (test) fix_bad(&fs);
    if (salvage_files) reclaim_file(&fs);
    else reclaim_free(&fs);
    free_clusters = update_free(&fs);
    file_unused();
    qfree(&mem_queue);
	n_files_check = n_files;
    if (verify) {
		n_files = 0;
		printf("Starting verification pass.\n");
		read_fat(&fs);
		scan_root(&fs);
		reclaim_free(&fs);
		qfree(&mem_queue);
		n_files_verify = n_files;
    }

    if (fs_changed()) {
	if (rw) {
	    if (interactive)
		rw = get_key("yn","Perform changes ? (y/n)") == 'y';
	    else printf("Performing changes.\n");
	}
	else
	    printf("Leaving file system unchanged.\n");
    }

    printf( "%s: %u files, %lu/%lu clusters\n", argv[optind],
	    n_files, fs.clusters - free_clusters, fs.clusters );

    return fs_close(rw) ? 1 : 0;
}
Beispiel #6
0
/*
 * Boot manager installation/configuration utility.
 */
int
main(int argc, char *argv[])
{
	char	*endptr;
	const	char *iplpath = "/boot/boot0", *menupath = "/boot/boot0.5";
	char	*iplbakpath = NULL, *menubakpath = NULL;
	char	*disk;
	int	B_flag = 0;
	int	c;
	int	fd1;
	int	n;
	int	secsize = 512;
	int	v_flag = 0, version;

	while ((c = getopt(argc, argv, "BF:f:i:m:s:v:")) != -1) {
		switch (c) {
		case 'B':
			B_flag = 1;
			break;
		case 'F':
			menubakpath = optarg;
			break;
		case 'f':
			iplbakpath = optarg;
			break;
		case 'i':
			iplpath = optarg;
			break;
		case 'm':
			menupath = optarg;
			break;
		case 's':
			secsize = strtol(optarg, &endptr, 0);
			if (errno || *optarg == '\0' || *endptr)
				errx(1, "%s: Bad argument to -s option",
				    optarg);
			switch (secsize) {
			case 256:
			case 512:
			case 1024:
			case 2048:
				break;
			default:
				errx(1, "%s: unsupported sector size", optarg);
				break;
			}
			break;
		case 'v':
			v_flag = 1;
			version = strtol(optarg, &endptr, 0);
			if (errno || *optarg == '\0' || *endptr ||
			    version < 0 || version > 255)
				errx(1, "%s: Bad argument to -v option",
				    optarg);
			break;
		default:
			usage();
			/* NOTREACHED */
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc != 1)
		usage();
	disk = mkrdev(*argv);

	read_boot(disk, boot0buf);

	if (iplbakpath != NULL) {
		fd1 = open(iplbakpath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
		if (fd1 < 0)
			err(1, "%s", iplbakpath);
		n = write(fd1, boot0buf, IPLSIZE);
		if (n == -1)
			err(1, "%s", iplbakpath);
		if (n != IPLSIZE)
			errx(1, "%s: short write", iplbakpath);
		close(fd1);
	}

	if (menubakpath != NULL) {
		fd1 = open(menubakpath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
		if (fd1 < 0)
			err(1, "%s", menubakpath);
		n = write(fd1, boot0buf + BOOTMENUOFF, BOOTMENUSIZE);
		if (n == -1)
			err(1, "%s", menubakpath);
		if (n != BOOTMENUSIZE)
			errx(1, "%s: short write", menubakpath);
		close(fd1);
	}

	if (B_flag) {
		/* Read IPL (boot0). */
		fd1 = open(iplpath, O_RDONLY);
		if (fd1 < 0)
			err(1, "%s", disk);
		n = read(fd1, ipl, IPLSIZE);
		if (n < 0)
			err(1, "%s", iplpath);
		if (n != IPLSIZE)
			errx(1, "%s: invalid file", iplpath);
		close(fd1);

		/* Read HDD boot menu (boot0.5). */
		fd1 = open(menupath, O_RDONLY);
		if (fd1 < 0)
			err(1, "%s", disk);
		n = read(fd1, menu, BOOTMENUSIZE);
		if (n < 0)
			err(1, "%s", menupath);
		if (n != BOOTMENUSIZE)
			errx(1, "%s: invalid file", menupath);
		close(fd1);

		memcpy(boot0buf, ipl, IPLSIZE);
		memcpy(boot0buf + BOOTMENUOFF, menu, BOOTMENUSIZE);
	}

	/* Set version number field. */
	if (v_flag)
		*(boot0buf + secsize - 4) = (u_char)version;

	if (B_flag || v_flag)
		write_boot(disk, boot0buf);

	return 0;
}
Beispiel #7
0
static int
biosboot(gpt_t gpt, daddr_t start, uint64_t size, u_int entry, uint8_t *label,
    const char *bootpath)
{
	map_t mbrmap, m;
	struct mbr *mbr, *bootcode;
	unsigned int i;
	struct gpt_ent *ent;
	uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1];

	/*
	 * Parse and validate partition maps
	 */
	if (gpt_hdr(gpt) == NULL)
		return -1;

	mbrmap = map_find(gpt, MAP_TYPE_PMBR);
	if (mbrmap == NULL || mbrmap->map_start != 0) {
		gpt_warnx(gpt, "No valid Protective MBR found");
		return -1;
	}

	mbr = mbrmap->map_data;

	/*
	 * Update the boot code
	 */
	if ((bootcode = read_boot(gpt, bootpath)) == NULL) {
		gpt_warnx(gpt, "Error reading bootcode");
		return -1;
	}
	(void)memcpy(&mbr->mbr_code, &bootcode->mbr_code,
		sizeof(mbr->mbr_code));
	free(bootcode);

	/*
	 * Walk through the GPT and see where we can boot from
	 */
	for (m = map_first(gpt); m != NULL; m = m->map_next) {
		if (m->map_type != MAP_TYPE_GPT_PART || m->map_index < 1)
			continue;

		ent = m->map_data;

		/* first, prefer user selection */
		if (entry > 0 && m->map_index == entry)
			break;

		if (label != NULL) {
			utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf));
			if (strcmp((char *)label, (char *)utfbuf) == 0)
				break;
		}

		/* next, partition as could be specified by wedge */
		if (entry < 1 && label == NULL && size > 0 &&
		    m->map_start == start && m->map_size == (off_t)size)
			break;
	}

	if (m == NULL) {
		gpt_warnx(gpt, "No bootable partition");
		return -1;
	}

	i = m->map_index - 1;


	if (set_bootable(gpt, gpt->gpt, gpt->tbl, i) == -1)
		return -1;

	if (set_bootable(gpt, gpt->tpg, gpt->lbt, i) == -1)
		return -1;

	if (gpt_write(gpt, mbrmap) == -1) {
		gpt_warnx(gpt, "Cannot update Protective MBR");
		return -1;
	}

	gpt_msg(gpt, "Partition %d marked as bootable", i + 1);
	return 0;
}