![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| File descriptor constant | vino | High Level Programming | 4 | 05-18-2005 01:18 AM |
| Problems with file descriptor | teo | High Level Programming | 11 | 05-09-2005 11:47 AM |
| File Descriptor Help | rahulrathod | UNIX for Dummies Questions & Answers | 3 | 10-14-2004 05:08 AM |
| file activity (open/closed) file descriptor info using KORN shell scripting | Gary Dunn | UNIX for Dummies Questions & Answers | 3 | 06-07-2004 01:54 PM |
| bad file descriptor? | ftb | UNIX for Dummies Questions & Answers | 1 | 02-20-2002 07:19 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 09:56 PM.. |
|
||||
|
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-03-2007 at 12:14 AM.. Reason: email address removed |
|
||||
|
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 |
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|