![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| File descriptor constant | vino | High Level Programming | 4 | 05-17-2005 10:18 PM |
| Problems with file descriptor | teo | High Level Programming | 11 | 05-09-2005 08:47 AM |
| File Descriptor Help | rahulrathod | UNIX for Dummies Questions & Answers | 3 | 10-14-2004 02:08 AM |
| file activity (open/closed) file descriptor info using KORN shell scripting | Gary Dunn | UNIX for Dummies Questions & Answers | 3 | 06-07-2004 10:54 AM |
| bad file descriptor? | ftb | UNIX for Dummies Questions & Answers | 1 | 02-20-2002 04:19 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
File Descriptor Table
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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... Code:
int read(int fd,char *buf,size_t len)
{
return fds[fd]->read(buf,len);
}
int write(int fd,char *buf,size_t len)
{
return fds[fd]->write(buf,len);
}
int close(int fd,char *buf,size_t len)
{
fds[fd]->close();
fds[fd]=NULL;
}
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. Last edited by porter; 12-02-2007 at 06:56 PM. |
|
#3
|
|||
|
|||
|
Not sure we're answering your question..
Quote:
You can email me direct email address removed if you want a more rapid dialogue. S. Last edited by vino; 12-02-2007 at 09:14 PM. Reason: email address removed |
|
#4
|
|||
|
|||
|
Depends if you are referering to Sys V STREAMS or stdio Streams....
|
|
#5
|
||||
|
||||
|
Please read the rules. No email replies are encouraged.
|
|
#6
|
|||
|
|||
|
Perhaps this is THE BOOK for you:
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. bakunin |
|
#7
|
|||
|
|||
|
Follow up
Agreed to Porter, and apologies to the moderator on the email thing.
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|