Esempio n. 1
0
/*
 * Main.
 */
int
main(int argc, char **argv)
{
	uint32_t size, blocksize;
	char *volname, *s;

#ifdef HOST
	hostcompat_init(argc, argv);
#endif

	if (argc!=3) {
		errx(1, "Usage: mksfs device/diskfile volume-name");
	}

	check();

	volname = argv[2];

	/* Remove one trailing colon from volname, if present */
	s = strchr(volname, ':');
	if (s != NULL) {
		if (strlen(s)!=1) {
			errx(1, "Illegal volume name %s", volname);
		}
		*s = 0;
	}

	/* Don't allow slashes */
	s = strchr(volname, '/');
	if (s != NULL) {
		errx(1, "Illegal volume name %s", volname);
	}

	opendisk(argv[1]);
	blocksize = diskblocksize();

	if (blocksize!=SFS_BLOCKSIZE) {
		errx(1, "Device has wrong blocksize %u (should be %u)\n",
		     blocksize, SFS_BLOCKSIZE);
	}
	size = diskblocks();

	/* Write out the on-disk structures */
	initfreemap(size);
	writesuper(volname, size);
	writefreemap(size);
	writerootdir();

	closedisk();

	return 0;
}
Esempio n. 2
0
int
main(int argc, char **argv)
{
#ifdef HOST
	hostcompat_init(argc, argv);
#endif

	if (argc!=2) {
		errx(EXIT_USAGE, "Usage: sfsck device/diskfile");
	}

	assert(sizeof(struct sfs_super)==SFS_BLOCKSIZE);
	assert(sizeof(struct sfs_inode)==SFS_BLOCKSIZE);
	assert(SFS_BLOCKSIZE % sizeof(struct sfs_dir) == 0);

	opendisk(argv[1]);

	check_sb();
	check_root_dir();
	check_bitmap();
	adjust_filelinks();

	closedisk();

	warnx("%lu blocks used (of %lu); %lu directories; %lu files",
	      count_blocks, (unsigned long) nblocks, count_dirs, count_files);

	switch (badness) {
	    case EXIT_USAGE:
	    case EXIT_FATAL:
	    default:
		/* not supposed to happen here */
		assert(0);
		break;
	    case EXIT_UNRECOV:
		warnx("WARNING - unrecoverable errors. Maybe try again?");
		break;
	    case EXIT_RECOV:
		warnx("Caution - filesystem modified. Run again for luck.");
		break;
	    case EXIT_CLEAN:
		break;
	}

	return badness;
}