David Mansfield wrote: > Steve Bergman wrote: >> Andy Green wrote: >>> Adam Gibson wrote: >>> It's possible to use the flag >>> O_DIRECT >> Thanks. :-) ... > I don't think this is necessarily safe to do. O_DIRECT adds additional > requirements to the memory buffer's alignment and file position > alignments. Unless you have audited the 'tar' source code, I think this > is a bad idea. > David The comment by Linus at http://lwn.net/Articles/54041/ and the post at http://www.titov.net/2006/01/02/using-o_largefile-or-o_direct-on-linux/ by someone that mentions something about memory buffer allignment issues when using O_DIRECT does make the patch sound scary. The comment by Linux was from 2003 though so I wonder if the security issues(whatever they are) are still a concern. "Have you ever noticed that O_DIRECT is a piece of crap? The interface is fundamentally flawed, it has nasty security issues, it lacks any kind of sane synchronization, and it exposes stuff that shouldn't be exposed to user space. I hope disk-based databases die off quickly. Yeah, I see where you are working, but where I'm coming from, I see all the _crap_ that Oracle tries to push down to the kernel, and most of the time I go "huh - that's a f**king bad design"." Linus and "And now some words about O_DIRECT. If you plan to use O_DIRECT your buffers should be aligned to pagesize (or sector size, depending on Linux version) and you should read/write in multiples of pagesize. To create buffer aligned at pagesize with size BUFFER_SIZE you can use code like this: pagesize=getpagesize(); realbuff=malloc(BUFFER_SIZE+pagesize); alignedbuff=((((int unsigned)realbuff+pagesize-1)/pagesize)*pagesize); where pagesize is int and realbuff and alignedbuff are pointers. Realbuff is the pointer you should free() when you finished and alignedbuff is the buffer you shoud use with read/write. You should also write only by multiples of pagesize. So if you want to create file that is not multiple of pagesize you should ftruncate the file when you finished writing." Anton Titov