Exemplo 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;
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
#ifdef HOST
	hostcompat_init(argc, argv);
#endif

	(void)argc;
	(void)argv;

	char line[MAX_LINE_LENGTH];
	int result;
	pid_t child_pid;
	int status;
	char *tokens[MAX_ARGS+1];

	while (1) {

		printf("os161-sh$ ");
		result = get_line(line);
		if (strcmp(line, "exit") == 0) break;
		if (strlen(line) == 0) continue;

		tokens[0] = (char *)line;
		int count = 0;
		char *ptr;
		for (ptr = line; *ptr != (char)NULL; ptr++) {
			if (*ptr == ' ') {
				*ptr = (char)NULL;
				tokens[++count] = ptr + 1;
			}
		}
		tokens[count+1] = NULL;

		child_pid = fork();
		if (child_pid == 0) {
			execv(line, tokens);
			printf("%s: execv failed\n", tokens[0]);
			exit(1);
		} else {
			waitpid(child_pid, &status, 0);
		}

	}

	exit(0);
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
int
main(int argc, char *argv[])
{
	int fd;
	char readbuf[1];
	int j = 0;
	char *fname;

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

	/* set default */
	fname = default_filename;

        if (argc == 2) {
	  /* override default from command line */
	  fname = argv[1];
	}
	else if (argc != 1) {
	  errx(1, "Usage: hash [filename]");
	}
	
	fd = open(fname, O_RDONLY, 0664);
	
	if (fd<0) { 
		err(1, "%s", fname);
	}
	for (;;) {
		if (read(fd, readbuf, 1) <= 0) break;

		j = ((j*8) + (int) readbuf[0]) % HASHP;
	}

	close(fd);
	

	return 0;
}
/* 
 * main
 * if there are no arguments, run interactively, otherwise, run a program
 * from within the shell, but immediately exit.
 */
int
main(int argc, char *argv[])
{
#ifdef HOST
	hostcompat_init(argc, argv);
#endif
	check_timing();

	/*
	 * Allow argc to be 0 in case we're running on a broken kernel,
	 * or one that doesn't set argv when starting the first shell.
	 */
	if (argc == 0 || argc == 1) {
		interactive();
	}
	else if (argc == 3 && !strcmp(argv[1], "-c")) {
		return docommand(argv[2]);
	}
	else {
		errx(1, "Usage: sh [-c command]");
	}
	return 0;
}