hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Anyone have a copy of POSIX?
Reply

Hosting Security and Technology Configuring and optimizing web hosting servers and operating systems, developing administration scripts, building servers, protecting against hackers, and general security (SSL certificates, etc.)
Forum Jump

Anyone have a copy of POSIX?

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-11-2002, 01:42 AM
cperciva cperciva is offline
Retired Moderator
 
Join Date: Jan 2001
Posts: 2,603

Anyone have a copy of POSIX?


Does anyone know offhand if POSIX requires read/write coherence? ie, if one process write(2)s to a region of a file, and another process read(2)s from the same region, is the read guaranteed to get either the original version or the new version (but not some combination of the two)?

It would be an odd system where this wasn't the case, but I'd like to make sure.

__________________
Dr. Colin Percival, FreeBSD Security Officer
Online backups for the truly paranoid: http://www.tarsnap.com/

Reply With Quote


Sponsored Links
  #2  
Old 02-11-2002, 09:34 AM
alchiba alchiba is offline
Web Hosting Master
 
Join Date: Aug 2000
Posts: 1,167
I assume you mean a simultaneous read/write. . .

It's a bit early in the morning for me, but my understanding is that the POSIX specification does not call for preventing "dirty" reads and writes and does not enforce cooperation among processes that simultaneously access a file. You have to explicitly lock the file. Without locks, a process reading from a file that is being written to would retrieve the orginal version.

Reply With Quote
  #3  
Old 02-11-2002, 09:43 AM
cperciva cperciva is offline
Retired Moderator
 
Join Date: Jan 2001
Posts: 2,603
I don't mind if I get the old version when I read from the file. What I'm looking for is a guarantee that I won't get a combination of both... ie if the disk sector size is 512 bytes, and I'm writing/reading a 1024 byte record, is it possible for me to read the first half of the new record and the second half of the old record through some unfortunate timing?

__________________
Dr. Colin Percival, FreeBSD Security Officer
Online backups for the truly paranoid: http://www.tarsnap.com/

Reply With Quote
Sponsored Links
  #4  
Old 02-11-2002, 10:34 AM
priyadi priyadi is offline
Registered User
 
Join Date: Apr 2001
Location: Depok, Indonesia
Posts: 986
I believe it is not possible, but I'm not sure either. It is even possible that POSIX doesn't address this issue. For safety I suggest you lock the portion of file you are trying to read/write using fcntl.

Reply With Quote
  #5  
Old 02-11-2002, 10:47 AM
alchiba alchiba is offline
Web Hosting Master
 
Join Date: Aug 2000
Posts: 1,167
Quote:
Originally posted by cperciva
What I'm looking for is a guarantee that I won't get a combination of both... ie if the disk sector size is 512 bytes, and I'm writing/reading a 1024 byte record, is it possible for me to read the first half of the new record and the second half of the old record through some unfortunate timing?
Write buffers aren't flushed (i.e., file written and pointers updated) until the file is closed. So, I believe you'd safely get the complete original version even in the midst of a write. This would be especially true with higher-level functions such as fread() and fwrite().

The way to guarantee your read result is to stat the file and wait for it to go quiet, make an exclusive lock on it and then execute the read.


Last edited by alchiba; 02-11-2002 at 11:00 AM.
Reply With Quote
  #6  
Old 02-12-2002, 07:08 AM
priyadi priyadi is offline
Registered User
 
Join Date: Apr 2001
Location: Depok, Indonesia
Posts: 986
Quote:
Originally posted by alchiba


Write buffers aren't flushed (i.e., file written and pointers updated) until the file is closed.
I believe fsync() and fdatasync() can be used to flush unwritten buffers prior to closing the fd.

Reply With Quote
  #7  
Old 02-12-2002, 11:48 AM
ScottD ScottD is offline
Web Hosting Master
 
Join Date: Dec 2001
Location: Detroit, MI
Posts: 1,067
This is a very difficult question to answer. I would suggest going to www.xopen.org and trying various searches. Personally, I could not find a good keyword combination that came up with results related to the question.

It seems to me that the POSIX specification really has no place in placing guarantees on data integrity. This should be left to the file system implementors. In many cases a file can be relocated and the already executing read statement will be reading from a now invalid portion of the disk while a call to tell() may describe the length of the file as being longer than it really is. I think locking the file is the only safe way to go, especially for portability issues and certainty that your application will work across different file systems / platforms.

Scott, confused as usual.

__________________
<!-- boo! -->

Reply With Quote
  #8  
Old 02-12-2002, 11:50 AM
cperciva cperciva is offline
Retired Moderator
 
Join Date: Jan 2001
Posts: 2,603
File locking would be good. Anyone know of a good *portable* method for file locking?

Unfortunately it seems that locking was left off the requirements sheet.

__________________
Dr. Colin Percival, FreeBSD Security Officer
Online backups for the truly paranoid: http://www.tarsnap.com/

Reply With Quote
  #9  
Old 02-12-2002, 11:53 AM
ScottD ScottD is offline
Web Hosting Master
 
Join Date: Dec 2001
Location: Detroit, MI
Posts: 1,067
By portable, do you mean cross platform (ie Unix/Windows) or just your typical Unix base?

When in doubt I almost always use semop() to do all of my locking. Generally wrapping the IPC stuff in C++ classes and going from there makes for nice semi-automatic synchronization schemes. If you are dealing with pthreads and a single application then a simple mutex should do the trick.

Scott

__________________
<!-- boo! -->

Reply With Quote
  #10  
Old 02-12-2002, 12:01 PM
cperciva cperciva is offline
Retired Moderator
 
Join Date: Jan 2001
Posts: 2,603
For "portable", read "portable to any POSIX-compliant system with an ANSI C compiler, including Windows, BSD, Linux, Solaris, Irix, and VMS".

And I want safeness across multiple processes, not just within a single process.

__________________
Dr. Colin Percival, FreeBSD Security Officer
Online backups for the truly paranoid: http://www.tarsnap.com/

Reply With Quote
  #11  
Old 02-12-2002, 12:26 PM
ScottD ScottD is offline
Web Hosting Master
 
Join Date: Dec 2001
Location: Detroit, MI
Posts: 1,067
As someone else has mentioned, using fcntl() is probably your best bet. Research F_SETLK, F_GETLK, and F_SETLKW specifically. This appears to be available in FreeBSD and Linux, but I don't see any mention for Visual C++, though possibly with Cygnus. No access to VMS so I can't see for sure.

I don't think there is a standard mechanism available that will work across all platforms so you are likely stuck rolling your own. Then again, I could just be missing it...

Good luck.

__________________
<!-- boo! -->

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Zetta Launches Appliance-Free Hybrid Smart Cloud Backup Solution Web Hosting News 2012-10-23 16:29:27
US Officials Seize 70 Domains Citing Counterfeiting, Fake SSL Certificates Web Hosting News 2012-07-13 10:45:43
Website usability – 10 tips for getting it right Blog 2012-04-27 14:11:03
Apple Confirms Discontinuation of iWeb, MobileMe Hosting in 2012 Web Hosting News 2011-06-24 20:15:37
Q&A: Go Daddy general counsel Christine Jones on Domain Transfer Lawsuit Web Hosting News 2011-06-09 20:50:09


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?