コード例 #1
0
ファイル: mktest.c プロジェクト: GDXN/snapraid
void generate(int disk, int size)
{
	char path[PATH_MAX];
	char* file;

	snprintf(path, sizeof(path), "bench/disk%d/", disk);
	file = path + strlen(path);

	/* add a directory */
	*file++ = 'a' + rnd(2);
	*file = 0;

	/* create it */
	if (mkdir(path, 0777) != 0) {
		if (errno != EEXIST) {
			/* LCOV_EXCL_START */
			fprintf(stderr, "Error creating directory %s\n", path);
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}
	}

	*file++ = '/';

	while (1) {
		/* add a random file */
		rnd_name(file);

		/* skip some invalid file name, see http://en.wikipedia.org/wiki/Filename */
		if (strcmp(file, ".") == 0
			|| strcmp(file, "..") == 0
			|| strcmp(file, "prn") == 0
			|| strcmp(file, "con") == 0
			|| strcmp(file, "nul") == 0
			|| strcmp(file, "aux") == 0
			|| file[0] == ' '
			|| file[strlen(file)-1] == ' '
			|| file[strlen(file)-1] == '.'
		) {
			continue;
		}

		break;
	}

#ifndef WIN32 /* Windows XP doesn't support symlinks */
	if (rnd(32) == 0) {
		/* symlink */
		char linkto[PATH_MAX];

		rnd_name(linkto);

		create_symlink(path, linkto);
	} else
#endif
	{
		/* file */
		create_file(path, size);
	}
}
コード例 #2
0
ファイル: mktest.c プロジェクト: DarkMatter26/snapraid
/**
 * Change a file. Or deleted/truncated/append/created.
 * - The file must exist.
 */
void cmd_change(const char* path, int size)
{
	struct stat st;

	if (!size)
		return;

	if (lstat(path, &st) != 0) {
		/* LCOV_EXCL_START */
		log_fatal("Error accessing %s\n", path);
		exit(EXIT_FAILURE);
		/* LCOV_EXCL_STOP */
	}

	if (S_ISLNK(st.st_mode)) {
		/* symlink */
		if (rnd(2) == 0) {
			/* delete */
			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				log_fatal("Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}
		} else {
			/* recreate */
			char linkto[PATH_MAX];

			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				log_fatal("Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}

			rnd_name(linkto);

			cmd_generate_symlink(path, linkto);
		}
	} else if (S_ISREG(st.st_mode)) {
		int r;

		r = rnd(4);

		if (r == 0) {
			cmd_write(path, size);
		} else if (r == 1) {
			cmd_append(path, size);
		} else if (r == 2) {
			cmd_truncate(path, size);
		} else {
			cmd_delete(path);
		}
	}
}
コード例 #3
0
ファイル: mktest.c プロジェクト: GDXN/snapraid
void change(const char* path, int size)
{
	struct stat st;

	if (!size)
		return;

	if (lstat(path, &st) != 0) {
		if (errno == ENOENT)
			return; /* it may be already deleted */
		/* LCOV_EXCL_START */
		fprintf(stderr, "Error accessing %s\n", path);
		exit(EXIT_FAILURE);
		/* LCOV_EXCL_STOP */
	}

	if (S_ISLNK(st.st_mode)) {
		/* symlink */
		if (rnd(2) == 0) {
			/* delete */
			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				fprintf(stderr, "Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}
		} else {
			/* recreate */
			char linkto[PATH_MAX];

			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				fprintf(stderr, "Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}

			rnd_name(linkto);

			create_symlink(path, linkto);
		}
	} else if (S_ISREG(st.st_mode)) {
		int r;

		r = rnd(4);

		if (r == 0) {
			/* write */
			writ(path, size, 0);
		} else if (r == 1) {
			/* append */
			append(path, size);
		} else if (r == 2) {
			/* truncate */
			truncat(path, size);
		} else {
			/* delete */
			if (remove(path) != 0) {
				/* LCOV_EXCL_START */
				fprintf(stderr, "Error removing %s\n", path);
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}
		}
	}
}