The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-02-2007
Ashaman0 Ashaman0 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 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
  #2 (permalink)  
Old 12-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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;
}
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.

Last edited by porter; 12-02-2007 at 09:56 PM..
  #3 (permalink)  
Old 12-02-2007
fsahog fsahog is offline
Registered User
  
 

Join Date: Apr 2006
Location: Northern Virginia
Posts: 23
Not sure we're answering your question..

Quote:
Originally Posted by Ashaman0 View Post
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
  #4 (permalink)  
Old 12-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by fsahog View Post
Streams must necessarily have a file descriptor as one of their attributes.
Depends if you are referering to Sys V STREAMS or stdio Streams....
  #5 (permalink)  
Old 12-03-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by fsahog View Post
You can email me direct email address removed if you want a more rapid dialogue.
Please read the rules. No email replies are encouraged.
  #6 (permalink)  
Old 12-03-2007
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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 (permalink)  
Old 12-03-2007
fsahog fsahog is offline
Registered User
  
 

Join Date: Apr 2006
Location: Northern Virginia
Posts: 23
Follow up

Agreed to Porter, and apologies to the moderator on the email thing.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0