Im working on writing a small operating system. I am currently working on implementing dup, dup2, pipe, and close and I need to implement some type of file descriptor table in my PCB.
I was wondering if there is anyone who is familiar with linux/unix implementation of these tables who could explain to me a little about how they are implemented. I know basically how it works, what I am really having a little trouble with now is how file descriptors are mapped to input/output streams. Are their pointers to the pipe / device, or is there some other way its done? Thanks.
Basically a file descriptor table is a kernel mantained array of pointers to kernel objects representing open files of some kind.
Imagine for a moment that these were C++ object...
But as kernels are generally written in C, other mechanisms, (pointers to jump tables etc) are used to provide the polymorphism.
Also reference counting is heavily used, so "close" for instance only really drops a reference count, if it gets to zero then the true close occurs.
What you need to consider in the model is where flags such as whether a file descriptor is blocking or not, and where the file-offset should live. Ask yourself, if I use "dup()" do both file descriptors have the same file offset?
If you do look inside the Linux kernel for instance you will notice that the BSD sockets API is handled quite differently to normal ioctl/read/write.
Im working on writing a small operating system. I am currently working on implementing dup, dup2, pipe, and close and I need to implement some type of file descriptor table in my PCB.
I was wondering if there is anyone who is familiar with linux/unix implementation of these tables who could explain to me a little about how they are implemented. I know basically how it works, what I am really having a little trouble with now is how file descriptors are mapped to input/output streams. Are their pointers to the pipe / device, or is there some other way its done? Thanks.
-shane
Streams must necessarily have a file descriptor as one of their attributes. Streams are a higher level processing construct than the driver level open/close/read/write/ioctl entry points. Generally they at least manage a buffering logic that works "above" what's actually going on in the kernel's queueing mechanisms.
You can email me direct email address removed if you want a more rapid dialogue.
S.
Last edited by vino; 12-03-2007 at 12:14 AM..
Reason: email address removed
Andrew S. Tanenbaum
Operating Systems Design and Implementation
Prentice Hall, 1997
ISBN-10: 0136386776
ISBN-13: 978-0136386773
If you can't find answers to your questions in there you won't probably find any answers at all. In my copy (2 vol german translation, Hanser, 1990) there is the complete and commented source code for Minix included.
Hi,
I am trying to read a file line-by-line in a while loop, and perform some tasks which involves non-interactive SSH to a remote server. The code looks something like this --
#!/usr/bin/ksh
export myFile=/path/to/my/file.load
while read line
do
do something
## Adding the SSH... (2 Replies)
Hello,
How can i use file descriptor in a script to read 2 files at the same time and extract line 200 from file 1 and line 500 from file 2.
Thanks. (6 Replies)
Hello All,
Im opening a file desciptor in perl and sending data using print CMD "$xyz".
is there a limit to the length of the string that I can give to this CMD at a time. (3 Replies)
I am trying to right a function which uses a file descriptor to write to a log file. The problem is that the on the print statement the file descriptor is called bad. Now when I first open the file and print to it in the f_open function by passing the descriptor to f_print_log all works well,... (6 Replies)
I have a requirement to close all the file descriptors from 3 to 1024 for a particular application.
Right now, this is how I do it ..
for ( int i = 3 ; i <= 1024; ++i )
close(i);
The change I am looking at is, I want to do away with the number 1024 and replace it with a constant which... (4 Replies)
Hi,
look at the following code:
The client after estabilishing a connection with the server does the following:
if ((peter = fopen(argv, "r")) == NULL){
printf("errore\n");
exit(0);
}
... (11 Replies)
I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Ok, I'm sure this is a total newbie question, but I think I'm in the right place, no?
I'm trying to call a perl module from a cgi script - Mail::Sendmail - and my web host installed the module in a directory that doesn't seem to be accessible, at least not the way I'm trying. But I thought you... (1 Reply)