Project

General

Profile

Bug #17563 » createtest.c

Simple posix testcase - Jeff Layton, 11/01/2016 01:08 PM

 
#define _GNU_SOURCE 1
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#define BUFSZ (16 * 1024)
#define NUMFILES (256)

int
main(void) {
char pathname[PATH_MAX];
char buf[BUFSZ];
int i, ret, fd;

memset(buf, 0x7c, BUFSZ);

for (i = 0; i < NUMFILES; ++i) {
sprintf(pathname, "/mnt/cephfs/testfile%x", i);
printf("%s\n", pathname);
printf("<<< open\n");
fd = open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (fd < 0) {
fprintf(stderr, "open: %d\n", errno);
return fd;
}
printf(">>> open\n");

printf("<<< write\n");
ret = write(fd, buf, BUFSZ);
if (ret < 0) {
fprintf(stderr, "write: %d\n", errno);
return ret;
}
printf(">>> write\n");

printf("<<< fsync\n");
ret = fsync(fd);
if (ret < 0) {
fprintf(stderr, "fsync: %d\n", errno);
return ret;
}
printf(">>> fsync\n");

printf("<<< close\n");
ret = close(fd);
if (ret < 0) {
fprintf(stderr, "close: %d\n", errno);
return ret;
}
printf(">>> close\n");
}
return 0;
}
(2-2/2)