958b25be50
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly. - Clean up MFS by removing old, dead code (backwards compatibility is broken by the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all functions have proper banners and prototypes. - VFS should always provide a (syntactically) valid path to the FS; no need for the FS to do sanity checks when leaving/entering mount points. - Fix several bugs in MFS: - Several path lookup bugs in MFS. - A link can be too big for the path buffer. - A mountpoint can become inaccessible when the creation of a new inode fails, because the inode already exists and is a mountpoint. - Introduce support for supplemental groups. - Add test 46 to test supplemental group functionality (and removed obsolete suppl. tests from test 2). - Clean up VFS (not everything is done yet). - ISOFS now opens device read-only. This makes the -r flag in the mount command unnecessary (but will still report to be mounted read-write). - Introduce PipeFS. PipeFS is a new FS that handles all anonymous and named pipes. However, named pipes still reside on the (M)FS, as they are part of the file system on disk. To make this work VFS now has a concept of 'mapped' inodes, which causes read, write, truncate and stat requests to be redirected to the mapped FS, and all other requests to the original FS.
148 lines
4.2 KiB
C
148 lines
4.2 KiB
C
/* t40b.c
|
|
*
|
|
* Test regular files
|
|
*
|
|
* Select works on regular files, (pseudo) terminal devices, streams-based
|
|
* files, FIFOs, pipes, and sockets. This test verifies selecting for regular
|
|
* file descriptors. "File descriptors associated with regular files shall
|
|
* always select true for ready to read, ready to write, and error conditions"
|
|
* - Open Group. Although we set a timeout, the select should return
|
|
* immediately.
|
|
*
|
|
* This test is part of a bigger select test. It expects as argument which sub-
|
|
* test it is.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <sys/select.h>
|
|
#include <errno.h>
|
|
#include <time.h>
|
|
|
|
#define FILE1 "/tmp/selecttest01-1"
|
|
#define FILES 2
|
|
#define TIME 3
|
|
|
|
#define MAX_ERROR 10
|
|
|
|
int errct = 0, subtest = -1;
|
|
char errorbuf[1000];
|
|
|
|
void e(int n, char *s) {
|
|
printf("Subtest %d, error %d, %s\n", subtest, n, s);
|
|
|
|
if (errct++ > MAX_ERROR) {
|
|
printf("Too many errors; test aborted\n");
|
|
exit(errct);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
int fd1, fd2, retval;
|
|
fd_set fds_read, fds_write, fds_error;
|
|
struct timeval tv;
|
|
time_t start, end;
|
|
|
|
/* Get subtest number */
|
|
if(argc != 2) {
|
|
printf("Usage: %s subtest_no\n", argv[0]);
|
|
exit(-1);
|
|
} else if(sscanf(argv[1], "%d", &subtest) != 1) {
|
|
printf("Usage: %s subtest_no\n", argv[0]);
|
|
exit(-1);
|
|
}
|
|
|
|
/* Set timeout */
|
|
tv.tv_sec = TIME;
|
|
tv.tv_usec = 0;
|
|
|
|
/* Open a file for writing */
|
|
if((fd1 = open(FILE1, O_WRONLY|O_CREAT, 0644)) == -1) {
|
|
snprintf(errorbuf, sizeof(errorbuf), "failed to open file %s for writing",
|
|
FILE1);
|
|
e(1, errorbuf);
|
|
perror(NULL);
|
|
exit(1);
|
|
}
|
|
|
|
/* Open the same file for reading */
|
|
if((fd2 = open(FILE1, O_RDONLY)) == -1) {
|
|
snprintf(errorbuf, sizeof(errorbuf), "failed to open file %s for reading",
|
|
FILE1);
|
|
e(2, errorbuf);
|
|
perror(NULL);
|
|
exit(1);
|
|
}
|
|
|
|
/* Clear file descriptor bit masks */
|
|
FD_ZERO(&fds_read); FD_ZERO(&fds_write); FD_ZERO(&fds_error);
|
|
|
|
/* Fill bit mask */
|
|
FD_SET(fd1, &fds_write);
|
|
FD_SET(fd2, &fds_read);
|
|
FD_SET(fd1, &fds_error);
|
|
FD_SET(fd2, &fds_error);
|
|
|
|
/* Do the select and time how long it takes */
|
|
start = time(NULL);
|
|
retval = select(fd2+1, &fds_read, &fds_write, &fds_error, &tv);
|
|
end = time(NULL);
|
|
|
|
/* Correct amount of ready file descriptors? 1 read + 1 write + 2 errors */
|
|
if(retval != 4) {
|
|
e(3, "four fds should be set");
|
|
}
|
|
|
|
/* Test resulting bit masks */
|
|
if(!FD_ISSET(fd1, &fds_write)) e(4, "write should be set");
|
|
if(!FD_ISSET(fd2, &fds_read)) e(5, "read should be set");
|
|
if(!FD_ISSET(fd1, &fds_error)) e(6, "error should be set");
|
|
if(!FD_ISSET(fd2, &fds_error)) e(7, "error should be set");
|
|
|
|
/* Was it instantaneous? */
|
|
if(end-start != TIME - TIME) {
|
|
snprintf(errorbuf,sizeof(errorbuf),"time spent blocking is not %d, but %ld",
|
|
TIME - TIME, (long int) (end-start));
|
|
e(8, errorbuf);
|
|
}
|
|
|
|
/* Wait for read to become ready on O_WRONLY. This should fail immediately. */
|
|
FD_ZERO(&fds_read); FD_ZERO(&fds_write); FD_ZERO(&fds_error);
|
|
FD_SET(fd1, &fds_read);
|
|
FD_SET(fd1, &fds_error);
|
|
FD_SET(fd2, &fds_error);
|
|
tv.tv_sec = TIME;
|
|
tv.tv_usec = 0;
|
|
retval = select(fd2+1, &fds_read, NULL, &fds_error, &tv);
|
|
|
|
/* Correct amount of ready file descriptors? 1 read + 2 error */
|
|
if(retval != 3) e(9, "incorrect amount of ready file descriptors");
|
|
if(!FD_ISSET(fd1, &fds_read)) e(10, "read should be set");
|
|
if(!FD_ISSET(fd1, &fds_error)) e(11, "error should be set");
|
|
if(!FD_ISSET(fd2, &fds_error)) e(12, "error should be set");
|
|
|
|
/* Try again as above, bit this time with O_RDONLY in the write set */
|
|
FD_ZERO(&fds_error);
|
|
FD_SET(fd2, &fds_write);
|
|
FD_SET(fd1, &fds_error);
|
|
FD_SET(fd2, &fds_error);
|
|
tv.tv_sec = TIME;
|
|
tv.tv_usec = 0;
|
|
retval = select(fd2+1, NULL, &fds_write, &fds_error, &tv);
|
|
|
|
/* Correct amount of ready file descriptors? 1 write + 2 errors */
|
|
if(retval != 3) e(13, "incorrect amount of ready file descriptors");
|
|
if(!FD_ISSET(fd2, &fds_write)) e(14, "write should be set");
|
|
if(!FD_ISSET(fd1, &fds_error)) e(15, "error should be set");
|
|
if(!FD_ISSET(fd2, &fds_error)) e(16, "error should be set");
|
|
|
|
close(fd1);
|
|
close(fd2);
|
|
unlink(FILE1);
|
|
|
|
exit(errct);
|
|
}
|