Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining file permissions



The original writer also mentioned that the question related to cross-platform code. I've seen a number of cases in Windows where opening a file read/write generated a success-code result, but the file was actually opened read-only. There are definitely cases (particularly in cross-platform code and in some network environments) where the "try it and see" approach doesn't work.

Cheers,

Rick Aurbach


On Nov 10, 2005, at 3:06 AM, email@hidden wrote:

From: Alexey Proskuryakov <email@hidden>

Date: November 10, 2005 2:43:35 AM CST

To: John Stiles <email@hidden>, Mark Wagner <email@hidden>

Cc: Chris Page <email@hidden>, Carbon Development <email@hidden>

Subject: Re: Determining file permissions



On 10.11.2005 01:53, "John Stiles" <email@hidden> wrote:


The easiest way to learn whether a file can be written to is to open the file

with write permission and then immediately close it. If you were able to open

it, it's writable. This is safe to do and doesn't take a long time.


  According to <http://developer.apple.com/technotes/fl/fl_37.html>, opening

files on read-only volumes with fsRdWrPerm of fsWrPerm should succeed,

falling back to read/deny-write or similar. Ancient documentation, but still

true for some file systems (AFP, but not SMB, rdar://3755430).


-------------------------------------------------

An open with write permission request (fsCurPerm, fsWrPerm, fsRdWrPerm, or

fsRdWrShPerm) does not fail on a locked volume and the write bit in

ioFCBFlags returned by PBGetFCBInfo will be set indicating that data can be

written to the file. As noted in Inside Macintosh: Files on page 2-8, you

won't discover this until you receive an error (either vLckdErr or wPrErr)

on the first call that attempts to write to the file or change the file's

logical or physical end-of-file. You can preflight for this condition by

calling PBHGetVInfo and checking the hardware and software locked bits in

ioVAtrb.

-------------------------------------------------

<...>

-------------------------------------------------

fsRdWrPerm is also retried as read-only, to simulate the case where a file

is being opened from a locked disk. Elsewhere, it's pointed out that

fsRdWrPerm is granted even if the volume is locked, and that an error won't

be returned until a PBWrite (or PBSetEOF or PBAllocate) call is made. The

same is now true for a read-only folder on an AppleShare volume.

-------------------------------------------------


- WBR, Alexey Proskuryakov


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.