I am trying to understand the structures associated with a call to the pipe syscall.
int pipe(int pipefd[2]);
From my understanding, there will be a "read" and "write" kernel buffer/structure associated with the read end pipefd[0]
and write end pipefd[1]
of the pipe.
I would really like some pointers (no pun intended) on structures referring to the read/write ends of this pipe, which I believe are just file descriptors. For instance, how does the computer know that there is no more bytes to be transferred "read" during a read operation such as:
char tmpBuff[15];
bytesRead = read(filedes[0], tmpBuff, 15);
What structure is defined that keeps track of the buffer, file position, etc.. associated with the filedes[0]
or filedes[1]
descriptors?
According to the man page for ssize_t read(int fd, void *buf, size_t count);
READ(2) Linux Programmer's Manual
NAME read - read from a file descriptor
SYNOPSIS #include
ssize_t read(int fd, void *buf, size_t count);
RETURN VALUE On success, the number of bytes read is returned (zero indicates end of file), and the file position is advanced by this number.
There must be some kind of structure pointed to be the index referred to by a file descriptor to make up some kind of structure like below.
struct file_info
{
char *start_buf;
char *end_buf;
int fileposition;
};
Lastly, is it possible from userspace to access these values out of curiousity and make a program that would say something like, "about to read from file descriptor foo, there is currently 120 bytes in the buffer and the file position is at 0". Since the buffer isn't accessible at the user level (I think), how could we access this information, only knowing the file descriptor value?