Ejemplo n.º 1
0
int			s_receive_file(char **path, int socket)
{
	int				ret;
	char			buff[1024];
	int				size;

	ft_bzero(buff, 1023);
	if ((ret = recv(socket, buff, 1023, 0)) == 0)
		return (0);
	if (!(ft_strcmp(buff, "file") == 0))
		return (0);
	ft_bzero(buff, 1023);
	send(socket, "", 1, 0);
	if ((ret = recv(socket, buff, 1023, 0)) == 0)
		return (0);
	if ((size = ft_atoi(buff)) == 0)
	{
		send(socket, "", 1, 0);
		ft_putendl("SUCCESS");
		return (s_create_file(path[1]));
	}
	else if (size == -1)
		return (report(2, socket));
	send(socket, "", 1, 0);
	return (fill_file(buff, path, size, socket));
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: wtaysom/tau
int rwp (int argc, char *argv[])
{
	u64	key;
	char	*file;
	int	rc;
FN;
	if (argc == 1) {
		file = "testfile";
	} else {
		file = argv[1];
	}
	rc = Creat(file);
	if (rc) {
		printf("Creat of %s failed %d\n", file, rc);
		return rc;
	}
	rc = Open(file, &key);
	if (rc) {
		printf("Open of %s failed %d\n", file, rc);
		return rc;
	}
	fill_file(key, 1000);
	Seek(key, 0);
	check_file(key, 1000);
	rc = Close(key);
	if (rc) {
		printf("Close of %llx failed %d\n", key, rc);
		return rc;
	}
	return 0;
}
Ejemplo n.º 3
0
/* Create a file of size file_size */
static uint64_t create_file(const char *file_name, uint64_t file_size)
{
	int fd;
	int flags;
	mode_t mode;
	uint64_t actual_size; /* Less than size if the file system is full */

	flags = O_CREAT | O_TRUNC | O_WRONLY;
	mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
	before();
	fd = open(file_name, flags, mode);
	if (fd == -1 && errno == ENOSPC) {
		errno = 0;
		after("open");
		fprintf(stderr,"\nrndrm99: open failed with ENOSPC\n");fflush(stderr);
		display_stats();
		return 0; /* File system full */
	}
	CHECK(fd != -1);
	after("open");
	actual_size = fill_file(fd, file_size);
	before();
	CHECK(close(fd) != -1);
	after("close");
	if (file_size != 0 && actual_size == 0) {
		printf("\nrndrm99: unlinking zero size file\n");fflush(stdout);
		before();
		CHECK(unlink(file_name) != -1);
		after("unlink (create_file)");
	}
	return actual_size;
}
Ejemplo n.º 4
0
/* test swap in */
void test_swap_in(void)
{
	vm_map_t map;
	const w_size_t num_pages = 10;
	const w_size_t num_frames = 4;
	char tmp;
	w_size_t i;
	w_size_t offset;
	w_boolean_t match_found = FALSE;

	vmsim_init();
	w_set_exception_handler(vmsim_test_segv_handler);
	vm_alloc(num_pages, num_frames, &map);

	/* fault all pages */
	for (i = 0; i < num_pages; i++) {
		offset = get_random_byte_mapping_position(1);
		*((char *) map.start + i * p_sz + offset) = MAGIC;
	}

	dlog(LOG_INFO, "all pages faulted\n");

	/* fill swap with other data */
	fill_file(map.swap_handle, num_pages * p_sz, ~MAGIC);

	/*
	 * at most num_frame pages will be backed by RAM;
	 * at least the (num_frame + 1)-th page is in swap;
	 * it will be swapped in
	 */
	for (i = 0; i < num_frames + 1; i++) {
		offset = get_random_byte_mapping_position(1);
		*((char *) map.start + i * p_sz + offset) = MAGIC;
	}

	/* some pages will be swapped in */
	for (i = 0; i < num_pages; i++) {
		offset = get_random_byte_mapping_position(1);
		tmp = *((char *) map.start + i * p_sz + offset);
		dlog(LOG_DEBUG, "tmp = %02x, not-magic = %02x\n", tmp, ~MAGIC);
		if (tmp == ~MAGIC)
			match_found = TRUE;
	}

	dlog(LOG_DEBUG, "match found: %d\n", match_found);

	vm_free(map.start);
	vmsim_cleanup();

	basic_test(match_found == TRUE);
}
Ejemplo n.º 5
0
void llp_nodes_finalize() {
	/* Writing file. */
	fill_file(llp_get_recent_nodes_file());
	
	/* Freeing memory allocated to hosts cache. */
	free(nodes.cache_list);
	
	/* Freeing mutexes. */
	pthread_mutex_destroy(&nodes_mutex);
	
	liblog_debug(LAYER_LINK, "mutex destroyed.");
	
	liblog_debug(LAYER_LINK, "nodes module finalized.");
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
	int fd, index;

	if (argc < 2)
		return usage(argv[0]);

	index = parse_options(argc, argv);
	if (index == -1 || index + 1 > argc)
		return usage(argv[0]);

	fd = open(argv[index], O_WRONLY | O_CREAT | O_TRUNC, 0644);
	if (fd < 0)
		return error("open output file");

	return fill_file(fd);
}
Ejemplo n.º 7
0
/* check that initial read-only page is swapped out */
void test_initial_readonly_page_is_swapped_out(void)
{
	vm_map_t map;
	const w_size_t num_pages = 10;
	const w_size_t num_frames = 4;
	char tmp;
	w_size_t i;
	w_size_t offset;
	w_boolean_t match_found = FALSE;

	vmsim_init();
	w_set_exception_handler(vmsim_test_segv_handler);
	vm_alloc(num_pages, num_frames, &map);

	/* zero swap for further checking */
	fill_file(map.swap_handle, num_pages * p_sz, ~MAGIC);

	/*
	 * at most num_frame pages will be backed by RAM
	 * the (num_frame + 1)-th access will result in a swap out
	 */
	for (i = 0; i < num_frames + 1; i++) {
		offset = get_random_byte_mapping_position(1);
		tmp = *((char *) map.start + i * p_sz + offset);
		/* sync ram file to ensure proper swap out */
		w_sync_mapping(map.start, num_pages);
	}

	/* go through swap to look for swapped pages */
	for (i = 0; i < num_pages; i++) {
		tmp = read_byte_from_file(map.swap_handle, i * p_sz + offset);
		dlog(LOG_DEBUG, "tmp = %02x\n", tmp);
		if (tmp != ~MAGIC) {
			dlog(LOG_DEBUG, "match found, frame index:"
				"%u, offset: %u\n", i, offset);
			match_found = TRUE;
		}
	}

	dlog(LOG_DEBUG, "match found: %d\n", match_found);

	vm_free(map.start);
	vmsim_cleanup();

	basic_test(match_found == TRUE);
}
Ejemplo n.º 8
0
/* test whether clean pages are swapped out (it shouldn't happen) */
void test_clean_page_is_not_swapped_out(void)
{
	vm_map_t map;
	char tmp, value1, value2;
	const w_size_t offset1 = 10;
	const w_size_t offset2 = 20;

	vmsim_init();
	w_set_exception_handler(vmsim_test_segv_handler);
	vm_alloc(2, 1, &map);

	/* fault first page (write) */
	*((char *) map.start + 0 * p_sz + offset1) = MAGIC;
	w_sync_mapping(map.start, 2);

	/* fault second page (write) -- first page goes to swap */
	*((char *) map.start + 1 * p_sz + offset2) = MAGIC;
	w_sync_mapping(map.start, 2);

	/* fault first page (read-only) -- second page goes to swap */
	tmp = *((char *) map.start + 0 * p_sz + offset1);
	w_sync_mapping(map.start, 2);

	fill_file(map.swap_handle, 2 * p_sz, ~MAGIC);

	/* fault second page (read-only) -- first page should not go to swap */
	tmp = *((char *) map.start + 1 * p_sz + offset2);
	w_sync_mapping(map.start, 2);

	/* fault first page (read-only) -- second page should not go to swap */
	tmp = *((char *) map.start + 0 * p_sz + offset1);
	w_sync_mapping(map.start, 2);

	w_set_file_pointer(map.swap_handle, 0 * p_sz + offset1);
	w_read_file(map.swap_handle, &value1, 1);
	w_set_file_pointer(map.swap_handle, 1 * p_sz + offset2);
	w_read_file(map.swap_handle, &value2, 1);

	dlog(LOG_LEVEL, "value1 = %02x, value2 = %02x\n", value1, value2);

	vm_free(map.start);
	vmsim_cleanup();

	basic_test(value1 == ~MAGIC && value2 == ~MAGIC);
}
Ejemplo n.º 9
0
static void chew_some_file(int num)
{
	char filename[10];
	int fd, rv;

	buf = mmap(NULL, FILE_SIZE, PROT_READ | PROT_WRITE,
			MAP_PRIVATE | MAP_ANON, 0, 0);
	rv = MMAP_FAILED;
	if (buf == MAP_FAILED)
		goto out_exit;

	sprintf(filename, "chew%d", num);
	fd = open(filename, O_CREAT | O_EXCL | O_RDWR, 0666);
	rv = OPEN_FAILED;
	if (fd == -1)
		goto out_unmap;

	while (!stop) {
		prepare_buf();
		switch (fill_file(fd)) {
		case -1:
			rv = WRITE_FAILED;
			goto out_exit;
		case -2:
			rv = SEEK_FAILED;
			goto out_exit;
		}
		if (fsync(fd) == -1) {
			rv = FSYNC_FAILED;
			goto out_exit;
		}
		if (fsync(fd) == -1) {
			rv = FSYNC_FAILED;
			goto out_exit;
		}
		switch (check_file(fd)) {
		case -1:
			rv = READ_FAILED;
			goto out_exit;
		case -2:
			rv = SEEK_FAILED;
			goto out_exit;
		case 1:
			rv = FILE_CORRUPTED;
			int fd1;
			char str[32];
			// create standard file
			sprintf(str, "standard_%s", filename);
			fd1 = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0666);
			if (write(fd1, buf, FILE_SIZE) != FILE_SIZE)
				err("can't write %s: %m\n", str);
			close(fd1);
			goto out_exit;
		}
	}
	rv = SUCCESS;
	close(fd);
	unlink(filename);
out_unmap:
	munmap(buf, FILE_SIZE);
out_exit:
	exit(rv);
}
Ejemplo n.º 10
0
Archivo: uread.c Proyecto: taysom/tau
int main (int argc, char *argv[])
{
	u8		*buf;
	int		fd;
	ssize_t		haveRead;
	size_t		toRead;
	unsigned	i;
	unsigned	bufsize;
	unsigned	n;
	u64		size;
	u64		rest;
	u64		l;

	drop_caches();
	Option.file_size = 0;
	Option.iterations = 1;
	Option.loops = 1;
	punyopt(argc, argv, myopt, "b:");
	n = Option.iterations;
	bufsize = 1 << Bufsize_log2;
	buf = emalloc(bufsize);
	size = Option.file_size;
	if (!size) {
		size = memtotal() / FRACTION_OF_MEMORY;
	}
	if (Hog_memory) {
		hog_leave_memory(size / FRACTION_OF_FILE_SIZE);
	}
	fd = open(Option.file, O_RDWR | O_CREAT | O_TRUNC, 0666);
	fill_file(fd, size);
	for (l = 0; l < Option.loops; l++) {
		startTimer();
		for (i = 0; i < n; ++i) {
			for (rest = size; rest; rest -= haveRead) {
				if (rest > bufsize) {
					toRead = bufsize;
				} else {
					toRead = rest;
				}
				haveRead = read(fd, buf, toRead);
				if (haveRead != toRead) {
					if (haveRead == -1) {
						perror("read");
						exit(1);
					}
					fprintf(stderr,
						"toRead=%llu != haveRead=%lld\n",
						(u64)toRead, (s64)haveRead);
					exit(1);
				}
			}
			lseek(fd, 0, 0);
		}
		stopTimer();
		printf("size=%lld n=%d ", size, n);
		prTimer();

		printf("\t%6.4g MiB/s\n",
			(double)(n * size) / get_avg() / MEBI);
	}
	close(fd);
	unlink(Option.file);
	return 0;
}