Exemple #1
0
/*
 * volume-add <device> <filesystem>
 */
void
hammer_cmd_volume_add(char **av, int ac)
{
	struct hammer_ioc_volume ioc;
	struct volume_info *vol;
	int fd;
	const char *device, *filesystem;

	if (ac != 2) {
		fprintf(stderr, "hammer volume-add <device> <filesystem>\n");
		exit(1);
	}

	device = av[0];
	filesystem = av[1];

        fd = open(filesystem, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "hammer volume-add: unable to access %s: %s\n",
			filesystem, strerror(errno));
		exit(1);
	}

	/*
	 * Initialize and check the device
	 */
	vol = init_volume(device, O_RDONLY, -1);
	assert(vol->vol_no == -1);
	if (strcmp(vol->type, "DEVICE")) {
		fprintf(stderr, "Not a block device: %s\n", device);
		exit(1);
	}
	close(vol->fd);

	/*
	 * volume-add ioctl
	 */
	bzero(&ioc, sizeof(ioc));
	strncpy(ioc.device_name, device, MAXPATHLEN);
	ioc.vol_size = vol->size;
	ioc.boot_area_size = init_boot_area_size(0, ioc.vol_size);
	ioc.memory_log_size = init_memory_log_size(0, ioc.vol_size);

	if (ioctl(fd, HAMMERIOC_ADD_VOLUME, &ioc) < 0) {
		fprintf(stderr, "hammer volume-add ioctl: %s\n",
			strerror(errno));
		exit(1);
	}

	close(fd);
	hammer_cmd_volume_list(av + 1, ac - 1);
}
Exemple #2
0
int main(int argc, char **argv) {
	int result, nr_of_plugins, x;
	t_tissue_stack *t;
	char serv_command[20], load_command[150];

	prctl(PR_SET_NAME, "TS_CORE");

	// initialisation of some variable
	t = malloc(sizeof(*t));
	init_prog(t);
	srand((unsigned) time(NULL));
	// intitialisation the volume
	if (argc > 2) {
		if (argv[2] != NULL && strcmp(argv[2], "--prompt") != 0) {
			t->volume_first = malloc(sizeof(*t->volume_first));
			if ((result = init_volume(t->memory_mappings, t->volume_first,
					argv[2])) != 0)
				return (result);
		} else if (argv[3] != NULL && strcmp(argv[3], "--prompt") != 0) {
			t->volume_first = malloc(sizeof(*t->volume_first));
			if ((result = init_volume(t->memory_mappings, t->volume_first,
					argv[3])) != 0)
				return (result);
		}
	} else
		t->volume_first = NULL;

	// lunch thread_pool
	t->tp = malloc(sizeof(*t->tp));
	thread_pool_init(t->tp, 16);

	nr_of_plugins = sizeof(PLUGINS) / sizeof(PLUGINS[0]);
	for (x = 0; x < nr_of_plugins; x++) {
		sprintf(load_command, "load %s %s/%s", PLUGINS[x][0], PLUGINS_PATH,
				PLUGINS[x][1]);
		plugin_load_from_string(load_command, t);
		DEBUG("Loading: %s\n", load_command);
	}

	sprintf(serv_command, "start serv %s", argv[1]);

	// start plugins
	(t->plug_actions)(t, serv_command, NULL);
	(t->plug_actions)(t, "start comm", NULL);

	task_clean_up(t);
	task_lunch(t);

	signal_manager(t);

	if ((argv[2] != NULL && strcmp(argv[2], "--prompt") == 0)
			|| (argv[3] != NULL && strcmp(argv[3], "--prompt") == 0))
		prompt_start(t);
	else {
		INFO("TissueStackImageServer Running!");
		pthread_mutex_lock(&t->main_mutex);
		pthread_cond_wait(&t->main_cond, &t->main_mutex);
		pthread_mutex_unlock(&t->main_mutex);
	}

	// free all the stuff mallocked
	INFO("Shutting down TissueStackImageServer!");

	t->tp->loop = 0;

	thread_pool_destroy(t->tp);
	free_core_struct(t);

	return (0);
}
Exemple #3
0
int main(int argc, char** argv) {
	/* Variable declaration */
	unsigned char* buffer;
	int free_size = 0, count = 0, i, j;

	/* Variable initialization */
	srand(time(NULL));
	buffer = (unsigned char*) malloc(HDA_SECTORSIZE * sizeof(unsigned char));

	/* Check the usage of the main program */
	cmdname = argv[0];
	processtype = argv[1];
	if (argc == 1) {
		usage();
		return EXIT_FAILURE;
	}

	/* Only disk creation */
	if(strcmp(processtype, "mkhd") == 0) {

		/* Delete the old disks */
		remove("vdiskA.bin");
		remove("vdiskB.bin");

		/* New disk initialization */
		init_master();

		printf("The disks have been successfully created.\n");
		return EXIT_SUCCESS;
	}

	/* Disk initialization */
	init_master();
	/* Load master boot record and partition information */
	load_mbr();
	init_volume();

	/* Get the status of the disk (free space) */
	if (strcmp(processtype, "status") == 0) {
		if (!load_super(CURRENT_VOL)) {
			fprintf(stderr, "No file system on the chosen partition\n");
			return EXIT_FAILURE;
		}
		printf("Space status of the volume : %s \n", current_super.super_name);
		free_size = mbr.mbr_vol[CURRENT_VOL].vol_n_sector - 1;
		double percent = (current_super.super_nb_free / (double) free_size)
				* 100;
		printf("Free space : %f %\n", percent);
		printf("Free blocs : %d\n", current_super.super_nb_free);
		return EXIT_SUCCESS;
	}

	/* Fill the partition */
	if (strcmp(processtype, "debug_fill") == 0) {
		printf("Filling the current partition\n");
		if (!load_super(CURRENT_VOL)) {
			fprintf(stderr, "No file system on the chosen partition\n");
			return EXIT_FAILURE;
		}
		int b;
		do {
			b = new_bloc();
			if(b != BLOC_NULL) {
				count++;
				printf(".");
				fflush(stdout);
			}
		} while (b != 0);
		printf("\n");
		printf("Number of allocated blocs : %d\n", count);
		return EXIT_SUCCESS;
	}

	/* Random free of the partition */
	if (strcmp(processtype, "debug_free") == 0) {
		unsigned size = mbr.mbr_vol[CURRENT_VOL].vol_n_sector - 1;
		unsigned begin = mbr.mbr_vol[CURRENT_VOL].vol_first_sector;
		int it = begin + size;
		int n;
		count = 0;

		if (!load_super(CURRENT_VOL)) {
			fprintf(stderr, "No file system on the chosen partition\n");
			return EXIT_FAILURE;
		}

		/* Check if the partition is empty */
		if(current_super.super_nb_free == size) {
			fprintf(stderr, "No bloc to free, the current partition is empty.\n");
			return EXIT_FAILURE;
		}

		/* Random free of the partition blocs */
		for (n = begin; n < it / 10; n++) {
			int random = rand() % it;
			if(random == 0) continue;

			free_bloc(random);
			printf("%d\n", random);

			count++;
		}
		printf("Number of desallocated blocs : %d\n", count);

		return EXIT_SUCCESS;
	}

	/* Make a new filesystem */
	if (strcmp(processtype, "mknfs") == 0) {
		init_super(CURRENT_VOL);
		printf("A new file system has been successfully installed on the current partition N°%d.\n", CURRENT_VOL);
		return EXIT_SUCCESS;
	}


	/* Process to format the entire disk	 */
	if (strcmp(processtype, "frmt") == 0) {
		for (i = 0; i < HDA_MAXCYLINDER; i++) {
			for (j = 0; j < HDA_MAXSECTOR; j++) {
				format_sector(i, j, HDA_SECTORSIZE, 0);
			}
		}
		printf("The entire disk has been successfully formated.\n");
		return EXIT_SUCCESS;
	}

	/* Process to dump the content of the first sector */
	if (strcmp(processtype, "dmps") == 0) {
		read_sector_n(0, 0, HDA_SECTORSIZE, buffer);
		dump(buffer, HDA_SECTORSIZE, 0, 1);
		return EXIT_SUCCESS;
	}

	/* Process type unknown */
	usage();

	return EXIT_FAILURE;

}