static void read_verify(const struct test_case_t *test) { if (test->fd == &fd4 && *test->fd == -1) { tst_resm(TCONF, "O_DIRECT not supported on %s filesystem", tst_fs_type_name(fs_type)); return; } TEST(read(*test->fd, *test->buf, test->count)); if (*test->fd == fd4 && TEST_RETURN >= 0) { tst_resm(TPASS, "O_DIRECT unaligned reads fallbacks to buffered I/O"); return; } if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); return; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == test->exp_error) { tst_resm(TPASS | TTERRNO, "expected failure"); } else { tst_resm(TFAIL | TTERRNO, "unexpected error expected %d", test->exp_error); } }
static void renameat2_verify(const struct test_case *test) { TEST(renameat2(*(test->olddirfd), test->oldpath, *(test->newdirfd), test->newpath, test->flags)); if ((test->flags & RENAME_EXCHANGE) && EINVAL == TEST_ERRNO && fs_type == TST_BTRFS_MAGIC) { tst_resm(TCONF, "RENAME_EXCHANGE flag is not implemeted on %s", tst_fs_type_name(fs_type)); return; } if (test->exp_errno && TEST_RETURN != -1) { tst_resm(TFAIL, "renameat2() succeeded unexpectedly"); return; } if (test->exp_errno == 0 && TEST_RETURN != 0) { tst_resm(TFAIL | TTERRNO, "renameat2() failed unexpectedly"); return; } if (test->exp_errno == TEST_ERRNO) { tst_resm(TPASS | TTERRNO, "renameat2() returned the expected value"); return; } tst_resm(TFAIL | TTERRNO, "renameat2() got unexpected return value: expected: %d - %s", test->exp_errno, tst_strerrno(test->exp_errno)); }
static void verify_read(unsigned int n) { struct tcase *tc = &tcases[n]; if (tc->fd == &fd4 && *tc->fd == -1) { tst_res(TCONF, "O_DIRECT not supported on %s filesystem", tst_fs_type_name(fs_type)); return; } TEST(read(*tc->fd, *tc->buf, tc->count)); if (*tc->fd == fd4 && TEST_RETURN >= 0) { tst_res(TPASS, "O_DIRECT unaligned reads fallbacks to buffered I/O"); return; } if (TEST_RETURN != -1) { tst_res(TFAIL, "read() succeeded unexpectedly"); return; } if (TEST_ERRNO == tc->exp_error) { tst_res(TPASS | TTERRNO, "read() failed as expected"); } else { tst_res(TFAIL | TTERRNO, "read() failed unexpectedly, " "expected %s", tst_strerrno(tc->exp_error)); } }
static void setup(void) { long type; struct passwd *nobody; tst_sig(FORK, DEF_HANDLER, cleanup); TEST_EXP_ENOS(exp_enos); tst_require_root(NULL); nobody = SAFE_GETPWNAM(NULL, "nobody"); nobody_uid = nobody->pw_uid; TEST_PAUSE; tst_tmpdir(); switch ((type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: case TST_TMPFS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do swapoff on a file on %s filesystem", tst_fs_type_name(type)); break; } if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) { tst_brkm(TBROK, cleanup, "Insufficient disk space to create swap file"); } if (tst_fill_file("./swapfile01", 0x00, 1024, 1)) tst_brkm(TBROK, cleanup, "Failed to create swapfile"); }
static void setup(void) { tst_sig(FORK, DEF_HANDLER, cleanup); tst_require_root(NULL); tst_tmpdir(); switch ((fs_type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: case TST_TMPFS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do swapon on a file on %s filesystem", tst_fs_type_name(fs_type)); break; } TEST_PAUSE; }
static void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; tst_tmpdir(); switch ((type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: case TST_RAMFS_MAGIC: case TST_TMPFS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do fcntl(F_SETLEASE, F_WRLCK) " "on %s filesystem", tst_fs_type_name(type)); default: break; } SAFE_TOUCH(cleanup, "file", FILE_MODE, NULL); }
static void setup(void) { tst_sig(FORK, DEF_HANDLER, cleanup); tst_require_root(); if (access("/proc/swaps", F_OK)) tst_brkm(TCONF, NULL, "swap not supported by kernel"); tst_tmpdir(); switch ((fs_type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: case TST_TMPFS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do swapon on a file on %s filesystem", tst_fs_type_name(fs_type)); break; } TEST_PAUSE; }
static void setup(void) { tst_sig(FORK, DEF_HANDLER, cleanup); tst_require_root(); tst_timer_check(CLOCK_MONOTONIC); /* Backup and set the lease-break-time. */ SAFE_FILE_SCANF(NULL, PATH_LS_BRK_T, "%d", &ls_brk_t); SAFE_FILE_PRINTF(NULL, PATH_LS_BRK_T, "%d", 45); tst_tmpdir(); switch ((type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: case TST_RAMFS_MAGIC: case TST_TMPFS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do fcntl(F_SETLEASE, F_WRLCK) " "on %s filesystem", tst_fs_type_name(type)); default: break; } SAFE_TOUCH(cleanup, "file", FILE_MODE, NULL); sigemptyset(&newset); sigaddset(&newset, SIGIO); if (sigprocmask(SIG_SETMASK, &newset, &oldset) < 0) tst_brkm(TBROK | TERRNO, cleanup, "sigprocmask() failed"); TEST_PAUSE; }
int main(int ac, char **av) { int lc; long type; /*************************************************************** * parse standard options ***************************************************************/ tst_parse_opts(ac, av, NULL, NULL); /*************************************************************** * perform global setup for test ***************************************************************/ setup(); switch ((type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: case TST_RAMFS_MAGIC: case TST_TMPFS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do fcntl on a file on %s filesystem", tst_fs_type_name(type)); break; } /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; #ifdef F_SETLEASE /* * Call fcntl(2) with F_SETLEASE & F_WRLCK argument on fname */ TEST(fcntl(fd, F_SETLEASE, F_WRLCK)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_WRLCK) Failed, errno=%d : %s", fname, TEST_ERRNO, strerror(TEST_ERRNO)); } else { TEST(fcntl(fd, F_GETLEASE)); if (TEST_RETURN != F_WRLCK) tst_resm(TFAIL, "fcntl(%s, F_GETLEASE) did not return F_WRLCK, returned %ld", fname, TEST_RETURN); else { TEST(fcntl(fd, F_SETLEASE, F_UNLCK)); if (TEST_RETURN != 0) tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_UNLCK) did not return 0, returned %ld", fname, TEST_RETURN); else tst_resm(TPASS, "fcntl(%s, F_SETLEASE, F_WRLCK)", fname); } } #else tst_resm(TINFO, "F_SETLEASE not defined, skipping test"); #endif } cleanup(); tst_exit(); }
int main(int ac, char **av) { struct stat stat_buf; /* struct buffer to hold file info. */ int lc; long type; time_t modf_time, access_time; time_t pres_time; /* file modification/access/present time */ tst_parse_opts(ac, av, NULL, NULL); setup(); switch ((type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: if (tst_kvercmp(2, 6, 18) < 0) tst_brkm(TCONF, cleanup, "Cannot do utime on a file" " on %s filesystem before 2.6.18", tst_fs_type_name(type)); break; case TST_V9FS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do utime on a file on %s filesystem", tst_fs_type_name(type)); break; } for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Invoke utime(2) to set TEMP_FILE access and * modification times to the current time. */ TEST(utime(TEMP_FILE, NULL)); if (TEST_RETURN == -1) { tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE); } else { /* * Sleep for a second so that mod time and * access times will be different from the * current time */ sleep(2); /* * Get the current time now, after calling * utime(2) */ pres_time = time(NULL); /* * Get the modification and access times of * temporary file using stat(2). */ SAFE_STAT(cleanup, TEMP_FILE, &stat_buf); modf_time = stat_buf.st_mtime; access_time = stat_buf.st_atime; /* Now do the actual verification */ if (modf_time <= curr_time || modf_time >= pres_time || access_time <= curr_time || access_time >= pres_time) { tst_resm(TFAIL, "%s access and " "modification times not set", TEMP_FILE); } else { tst_resm(TPASS, "Functionality of " "utime(%s, NULL) successful", TEMP_FILE); } } tst_count++; } cleanup(); tst_exit(); }
int main(int ac, char **av) { struct stat stat_buf; /* struct buffer to hold file info. */ int lc; long type; const char *msg; time_t modf_time, access_time; time_t pres_time; /* file modification/access/present time */ msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); switch ((type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: if (tst_kvercmp(2, 6, 18) < 0) tst_brkm(TCONF, cleanup, "Cannot do utime on a file" " on %s filesystem before 2.6.18", tst_fs_type_name(type)); break; case TST_V9FS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do utime on a file on %s filesystem", tst_fs_type_name(type)); break; } /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Invoke utime(2) to set TEMP_FILE access and * modification times to the current time. */ TEST(utime(TEMP_FILE, NULL)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s", TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Sleep for a second so that mod time and * access times will be different from the * current time */ sleep(2); /* * Get the current time now, after calling * utime(2) */ if ((pres_time = time(&tloc)) < 0) { tst_brkm(TFAIL, cleanup, "time() " "failed to get present time " "after utime, error=%d", errno); } /* * Get the modification and access times of * temporary file using stat(2). */ if (stat(TEMP_FILE, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "stat(2) of " "%s failed, error:%d", TEMP_FILE, TEST_ERRNO); } modf_time = stat_buf.st_mtime; access_time = stat_buf.st_atime; /* Now do the actual verification */ if (modf_time <= curr_time || modf_time >= pres_time || access_time <= curr_time || access_time >= pres_time) { tst_resm(TFAIL, "%s access and " "modification times not set", TEMP_FILE); } else { tst_resm(TPASS, "Functionality of " "utime(%s, NULL) successful", TEMP_FILE); } } tst_count++; } cleanup(); tst_exit(); }
static void setup(void) { char filename[PATH_MAX]; int n, j, fd, directflag = 1; long type; if (align_str) { align = atoi(align_str); if (align < 0 || align > PAGE_SIZE) tst_brkm(TCONF, NULL, "Bad alignment %d.", align); } tst_resm(TINFO, "using alignment %d", align); if (workers_str) { workers = atoi(workers_str); if (workers < MIN_WORKERS || workers > MAX_WORKERS) { tst_brkm(TCONF, NULL, "Worker count %d not between " "%d and %d, inclusive", workers, MIN_WORKERS, MAX_WORKERS); } } tst_resm(TINFO, "using %d workers.", workers); tst_sig(FORK, DEF_HANDLER, NULL); tst_require_root(NULL); TEST_PAUSE; tst_tmpdir(); /* * Some file systems may not implement the O_DIRECT flag and open() will * fail with EINVAL if it is used. So add this check for current * filesystem current directory is in, if not supported, we choose to * have this test in LTP_BIG_DEV and mkfs it as ext3. */ fd = open("testfile", O_CREAT | O_DIRECT, 0644); if (fd < 0 && errno == EINVAL) { type = tst_fs_type(NULL, "."); tst_resm(TINFO, "O_DIRECT flag is not supported on %s " "filesystem", tst_fs_type_name(type)); directflag = 0; } else if (fd > 0) { SAFE_CLOSE(NULL, fd); } SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE); /* * verify whether the current directory has enough free space, * if it is not satisfied, we will use the LTP_BIG_DEV, which * will be exported by runltp with "-z" option. */ if (!directflag || !tst_fs_has_free(NULL, ".", 1300, TST_MB)) { device = getenv("LTP_BIG_DEV"); if (device == NULL) { tst_brkm(TCONF, NULL, "you must specify a big blockdevice(>1.3G)"); } else { tst_mkfs(NULL, device, "ext3", NULL); } if (mount(device, MNT_POINT, "ext3", 0, NULL) < 0) { tst_brkm(TBROK | TERRNO, NULL, "mount device:%s failed", device); } mount_flag = 1; } worker = SAFE_MALLOC(cleanup, workers * sizeof(worker_t)); for (j = 0; j < workers; j++) worker[j].worker_number = j; for (n = 1; n <= FILECOUNT; n++) { snprintf(filename, sizeof(filename), FILE_BASEPATH, n); if (tst_fill_file(filename, n, FILESIZE, 1)) { tst_brkm(TBROK, cleanup, "failed to create file: %s", filename); } } if (posix_memalign((void **)&buffer, PAGE_SIZE, READSIZE + align) != 0) tst_brkm(TBROK, cleanup, "call posix_memalign failed"); }
int main(int ac, char **av) { struct stat stat_buf; /* struct buffer to hold file info. */ int lc; long type; const char *msg; time_t modf_time, access_time; time_t pres_time; /* file modification/access/present time */ pid_t pid; msg = parse_opts(ac, av, NULL, NULL); if (msg != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); switch ((type = tst_fs_type(cleanup, "."))) { case TST_NFS_MAGIC: case TST_V9FS_MAGIC: tst_brkm(TCONF, cleanup, "Cannot do utime on a file on %s filesystem", tst_fs_type_name(type)); break; } /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); pid = FORK_OR_VFORK(); if (pid == -1) { tst_brkm(TBROK, cleanup, "fork() failed"); } else if (pid == 0) { if ((ltpuser = getpwnam(LTPUSER1)) == NULL) { tst_brkm(TBROK, cleanup, "%s not found in /etc/passwd", LTPUSER1); } /* get uid/gid of user accordingly */ user_uid = ltpuser->pw_uid; seteuid(user_uid); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Invoke utime(2) to set TEMP_FILE access and * modification times to the current time. */ TEST(utime(TEMP_FILE, NULL)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s", TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO)); } else { /* * Sleep for a second so that mod time * and access times will be different * from the current time. */ sleep(2); /* * Get the current time now, after * calling utime(2) */ if ((pres_time = time(&tloc)) < 0) { tst_brkm(TFAIL, cleanup, "time() failed to get " "present time after " "utime, error=%d", errno); } /* * Get the modification and access * times of temporary file using * stat(2). */ if (stat(TEMP_FILE, &stat_buf) < 0) { tst_brkm(TFAIL, cleanup, "stat(2) of %s failed, " "error:%d", TEMP_FILE, TEST_ERRNO); } modf_time = stat_buf.st_mtime; access_time = stat_buf.st_atime; /* Now do the actual verification */ if (modf_time <= curr_time || modf_time >= pres_time || access_time <= curr_time || access_time >= pres_time) { tst_resm(TFAIL, "%s access and " "modification times " "not set", TEMP_FILE); } else { tst_resm(TPASS, "Functionality " "of utime(%s, NULL) " "successful", TEMP_FILE); } } tst_count++; /* incr. TEST_LOOP counter */ } } else { waitpid(pid, &status, 0); _exit(0); /* * Exit here and let the child clean up. * This allows the errno information set * by the TEST_ERROR_LOG macro and the * PASS/FAIL status to be preserved for * use during cleanup. */ } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int fblocks = 1; /* Iterations. Default 1 */ int bufsize = BUFSIZE; int count, ret; int offset; int fd, newfd; int i, l_fail = 0, fail_count = 0, total = 0; int failed = 0; int shmsz = MMAP_GRANULARITY; int pagemask = ~(sysconf(_SC_PAGE_SIZE) - 1); char *buf0, *buf1, *buf2; caddr_t shm_base; /* Options */ while ((i = getopt(argc, argv, "b:")) != -1) { switch (i) { case 'b': if ((fblocks = atoi(optarg)) <= 0) { fprintf(stderr, "fblocks must be > 0\n"); prg_usage(); } break; default: prg_usage(); } } setup(); /* Open file and fill, allocate for buffer */ if ((fd = open(filename, O_DIRECT | O_RDWR | O_CREAT, 0666)) < 0) { tst_brkm(TBROK, cleanup, "open failed for %s: %s", filename, strerror(errno)); } if ((buf0 = valloc(bufsize)) == NULL) { tst_brkm(TBROK, cleanup, "valloc() buf0 failed: %s", strerror(errno)); } for (i = 1; i < fblocks; i++) { fillbuf(buf0, bufsize, (char)i); if (write(fd, buf0, bufsize) < 0) { tst_brkm(TBROK, cleanup, "write failed for %s: %s", filename, strerror(errno)); } } close(fd); if ((buf2 = valloc(bufsize)) == NULL) { tst_brkm(TBROK, cleanup, "valloc() buf2 failed: %s", strerror(errno)); } if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "open failed for %s: %s", filename, strerror(errno)); } /* Test-1: Negative Offset */ offset = -1; count = bufsize; errno = 0; ret = lseek(fd, offset, SEEK_SET); if ((ret >= 0) || (errno != EINVAL)) { tst_resm(TFAIL, "lseek allows negative offset. returns %d:%s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "Negative Offset"); total++; /* Test-2: Removed */ tst_resm(TPASS, "removed"); /* Test-3: Odd count of read and write */ offset = 0; count = 1; lseek(fd, 0, SEEK_SET); if (write(fd, buf2, 4096) == -1) { tst_resm(TFAIL, "can't write to file %d", ret); } switch (fs_type) { case TST_NFS_MAGIC: case TST_BTRFS_MAGIC: tst_resm(TCONF, "%s supports odd count IO", tst_fs_type_name(fs_type)); break; default: ret = runtest_f(fd, buf2, offset, count, EINVAL, 3, "odd count"); testcheck_end(ret, &failed, &fail_count, "Odd count of read and write"); } total++; /* Test-4: Read beyond the file size */ offset = bufsize * (fblocks + 10); count = bufsize; if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek failed: %s", strerror(errno)); failed = TRUE; fail_count++; tst_resm(TFAIL, "Read beyond the file size"); } else { errno = 0; ret = read(fd, buf2, count); if (ret > 0 || (ret < 0 && errno != EINVAL)) { tst_resm(TFAIL, "allows read beyond file size. returns %d: %s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "Read beyond the file size"); } total++; /* Test-5: Invalid file descriptor */ offset = 4096; count = bufsize; newfd = -1; ret = runtest_f(newfd, buf2, offset, count, EBADF, 5, "negative fd"); testcheck_end(ret, &failed, &fail_count, "Invalid file descriptor"); total++; /* Test-6: Out of range file descriptor */ count = bufsize; offset = 4096; if ((newfd = getdtablesize()) < 0) { tst_resm(TFAIL, "getdtablesize() failed: %s", strerror(errno)); failed = TRUE; tst_resm(TFAIL, "Out of range file descriptor"); } else { ret = runtest_f(newfd, buf2, offset, count, EBADF, 6, "out of range fd"); testcheck_end(ret, &failed, &fail_count, "Out of range file descriptor"); } close(newfd); total++; /* Test-7: Closed file descriptor */ offset = 4096; count = bufsize; SAFE_CLOSE(cleanup, fd); ret = runtest_f(fd, buf2, offset, count, EBADF, 7, "closed fd"); testcheck_end(ret, &failed, &fail_count, "Closed file descriptor"); total++; /* Test-9: removed */ tst_resm(TPASS, "removed"); /* Test-9: Character device (/dev/null) read, write */ offset = 0; count = bufsize; if ((newfd = open("/dev/null", O_DIRECT | O_RDWR)) < 0) { tst_resm(TCONF, "Direct I/O on /dev/null is not supported"); } else { ret = runtest_s(newfd, buf2, offset, count, 9, "/dev/null"); testcheck_end(ret, &failed, &fail_count, "character device read, write"); } close(newfd); total++; /* Test-10: read, write to a mmaped file */ shm_base = (char *)(((long)sbrk(0) + (shmsz - 1)) & ~(shmsz - 1)); if (shm_base == NULL) { tst_brkm(TBROK, cleanup, "sbrk failed: %s", strerror(errno)); } offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } shm_base = mmap(shm_base, 0x100000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); if (shm_base == (caddr_t) - 1) { tst_brkm(TBROK, cleanup, "can't mmap file: %s", strerror(errno)); } ret = runtest_s(fd, buf2, offset, count, 10, "mmapped file"); testcheck_end(ret, &failed, &fail_count, "read, write to a mmaped file"); total++; /* Test-11: read, write to an unmaped file with munmap */ if ((ret = munmap(shm_base, 0x100000)) < 0) { tst_brkm(TBROK, cleanup, "can't unmap file: %s", strerror(errno)); } ret = runtest_s(fd, buf2, offset, count, 11, "unmapped file"); testcheck_end(ret, &failed, &fail_count, "read, write to an unmapped file"); close(fd); total++; /* Test-12: read from file not open for reading */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_WRONLY)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek failed: %s", strerror(errno)); failed = TRUE; fail_count++; } else { errno = 0; ret = read(fd, buf2, count); if (ret >= 0 || errno != EBADF) { tst_resm(TFAIL, "allows read on file not open for reading. returns %d: %s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "read from file not open for reading"); } close(fd); total++; /* Test-13: write to file not open for writing */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDONLY)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek failed: %s", strerror(errno)); failed = TRUE; fail_count++; } else { errno = 0; ret = write(fd, buf2, count); if (ret >= 0 || errno != EBADF) { tst_resm(TFAIL, "allows write on file not open for writing. returns %d: %s", ret, strerror(errno)); failed = TRUE; fail_count++; } else tst_resm(TPASS, "write to file not open for writing"); } close(fd); total++; /* Test-14: read, write with non-aligned buffer */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } switch (fs_type) { case TST_NFS_MAGIC: case TST_BTRFS_MAGIC: tst_resm(TCONF, "%s supports non-aligned buffer", tst_fs_type_name(fs_type)); break; default: ret = runtest_f(fd, buf2 + 1, offset, count, EINVAL, 14, " nonaligned buf"); testcheck_end(ret, &failed, &fail_count, "read, write with non-aligned buffer"); } close(fd); total++; /* Test-15: read, write buffer in read-only space */ offset = 4096; count = bufsize; l_fail = 0; if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK, cleanup, "can't open %s: %s", filename, strerror(errno)); } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek before read failed: %s", strerror(errno)); l_fail = TRUE; } else { errno = 0; ret = read(fd, (char *)((ulong) ADDRESS_OF_MAIN & pagemask), count); if (ret >= 0 || errno != EFAULT) { tst_resm(TFAIL, "read to read-only space. returns %d: %s", ret, strerror(errno)); l_fail = TRUE; } } if (lseek(fd, offset, SEEK_SET) < 0) { tst_resm(TFAIL, "lseek before write failed: %s", strerror(errno)); l_fail = TRUE; } else { ret = write(fd, (char *)((ulong) ADDRESS_OF_MAIN & pagemask), count); if (ret < 0) { tst_resm(TFAIL, "write to read-only space. returns %d: %s", ret, strerror(errno)); l_fail = TRUE; } } testcheck_end(l_fail, &failed, &fail_count, "read, write buffer in read-only space"); close(fd); total++; /* Test-16: read, write in non-existant space */ offset = 4096; count = bufsize; if ((buf1 = (char *)(((long)sbrk(0) + (shmsz - 1)) & ~(shmsz - 1))) == NULL) { tst_brkm(TBROK | TERRNO, cleanup, "sbrk failed"); } if ((fd = open(filename, O_DIRECT | O_RDWR)) < 0) { tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_DIRECT|O_RDWR) failed", filename); } ret = runtest_f(fd, buf1, offset, count, EFAULT, 16, " nonexistant space"); testcheck_end(ret, &failed, &fail_count, "read, write in non-existant space"); total++; close(fd); /* Test-17: read, write for file with O_SYNC */ offset = 4096; count = bufsize; if ((fd = open(filename, O_DIRECT | O_RDWR | O_SYNC)) < 0) { tst_brkm(TBROK, cleanup, "open(%s, O_DIRECT|O_RDWR|O_SYNC failed)", filename); } ret = runtest_s(fd, buf2, offset, count, 17, "opened with O_SYNC"); testcheck_end(ret, &failed, &fail_count, "read, write for file with O_SYNC"); total++; close(fd); unlink(filename); if (failed) tst_resm(TINFO, "%d/%d test blocks failed", fail_count, total); else tst_resm(TINFO, "%d testblocks completed", total); cleanup(); tst_exit(); }