Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Asynchronous File I/O on Linux



On May 15, 2010, at 5:56 PM, Mark Woodward wrote:
> 
> OK, so, the methodology is quite similar, fine. Now the question 
> remains, is it possible to quickly "clone" an existing file handle so 
> that it will be a new and distinct file handle with the same permissions 
> and modes with its own distict view of current location, i.e. seek on 
> one does not affect seek on the other?

Part of the difficulty finding an answer is, I think, your incorrect use of "asynchronous I/O".  This isn't it.  What you've described is random access.

A file handle is really a pointer to a structure in the kernel somewhere that contains, among other things, the file read/write pointer.  If you clone the descriptor then you get a pointer to the same structure.  What you want is a completely new file handle for the same file.  That's easy: open().  So you'd do something like:

fh1 = open(filename, O_WRONLY, mode);
fh2 = open(filename, O_WRONLY, mode);
readblock(block,size,offset,fd1);
readblock(block,size,offset,fd2);
close(fd1);
close(fd2);

I think.

--Rich P.








BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org