Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer > Re: Get login n...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 32 of 49 Topic 942 of 1040
Post > Topic >>

Re: Get login name and/or path to home directory of current user?

by Michael Ash <mike@[EMAIL PROTECTED] > Jun 1, 2007 at 04:54 PM

In comp.sys.mac.programmer.misc glenn andreas <gandreas@[EMAIL PROTECTED]
> wrote:
> In article <1360pjueho17k0d@[EMAIL PROTECTED]
>,
> SM Ryan <wyrmwif@[EMAIL PROTECTED]
> wrote:
> 
>> Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
>> # (Call me a throwback, or whatever, but I *HATE* the hassle of trying
to 
>> # deal with CFString stuff - particularly since I have almost zero 
>> # expectation that this code will ever want to run on a machine that 
>> # speaks anything other than plain old ASCII English)
>> 
>> If it's any comfort, the kernel only sees a byte string with a zero
>> byte terminator and '/' as a directory separator.
> 
> That's not strictly true.  Take a look at vfs_lookup.c:
> 
>
<http://www.opensource.apple.com/darwinsource/10.4.9.ppc/xnu-792.17.14/bs
> d/vfs/vfs_lookup.c>
> 
> It does all sorts of things, such as handling ".." (and other odd 
> treatment for specially placed '.'), as well as letting the specific 
> file system determine what in a path name is part of a component.  For a

> mac file system, this includes case insensitivity, which means that the 
> file system need to understand how the file name is encoded (in order to

> compare characters) - and this would be UTF8.

It goes well beyond that, actually.

In UTF-8 there are certain cl***** of characters which have multiple 
equivalent representations. These are precomposed characters, which tend 
to be letters with accent marks, which can also be formed by using two 
separate characters with the plain letter as the first one and a combining

accent mark as the second one. The Mac OS X kernel treats all such 
equivalent sequences as being truly equivalent, so that using a decomposed

path will reach a file that was saved with a precomposed name, and vice 
versa. This requires a fairly deep understanding of Unicode in the kernel 
and, indeed, this is complex enough that there were still some bugs in 
this handling up through, I believe, 10.2.

It should also be noted that case insensitivity is also ridiculously hard 
to do. For example, it's possible for the uppercase->lowercase 
transformation to produce more characters than you started with. The 
German uppercase letter that looks like a "beta" turns into "ss" when 
lowercased, and there may be other examples as well.

The kernel definitely doesn't look at your path as a bag of bytes. It is 
fully Unicode aware, and your app should be too.

I also want to note that it is most definitely not a case where paths are 
the OS's native language and FSRefs are some alternate interface 
implemented in libraries. FSRefs actually enjoy sup****t deep in the 
kernel; look up volfs if you want details. In many cases, accessing a 
filesystem object through FSRefs will be significantly faster, because the

kernel is able to go straight from an FSRef to a file's directory entry 
without passing through any of the parent directories first. 
(Incidentally, some consider this to be a security hole, because the 
kernel will let you access a file you have appropriate permissions for in 
this way even if its only link on disk is in a directory which you do not 
have permissions to access.) Whereas if you use a path to access the file 
then the kernel has to break it into pieces, run all these fun Unicode 
transformations on it, then do a relatively expensive directory lookup for

every single path component.

The main downside to FSRefs is that the majority of OS X APIs do not 
accept them, and transforming them back into a path kills all of that 
speed advantage and then some.

It would be great if there were some API that would give you the short 
volfs path for an FSRef if it were available, but alas, there isn't one.

-- 
Michael Ash
Rogue Amoeba Software
?
 




 49 Posts in Topic:
Get login name and/or path to home directory of current user?
Don Bruder <dakidd@[EM  2007-05-29 23:56:30 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-05-30 07:33:28 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-30 12:39:12 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 08:26:55 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 07:15:29 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 12:47:58 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 10:18:03 
Re: Get login name and/or path to home directory of current user
glenn andreas <gandrea  2007-06-01 11:00:38 
Re: Get login name and/or path to home directory of current user
russotto@[EMAIL PROTECTED  2007-06-03 20:38:20 
Re: Get login name and/or path to home directory of current user
glenn andreas <gandrea  2007-06-04 08:53:09 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:43:50 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 20:47:41 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-06-01 19:05:34 
Re: Get login name and/or path to home directory of current user
Sean McBride <cwatson@  2007-06-02 13:26:49 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-04 14:08:38 
Re: Get login name and/or path to home directory of current user
Bo Lindbergh <blgl@[EM  2007-05-30 11:27:08 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-30 12:41:44 
Re: Get login name and/or path to home directory of current user
David Phillip Oster <o  2007-05-31 02:51:48 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-30 20:59:08 
Re: Get login name and/or path to home directory of current user
Jens Ayton <IWISNEXPQQ  2007-05-31 21:29:13 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-05-31 23:03:31 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 07:20:53 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 12:48:00 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 10:28:13 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:43:51 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 20:34:55 
Re: Get login name and/or path to home directory of current user
Don Bruder <dakidd@[EM  2007-06-01 06:07:37 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-01 10:46:07 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-01 10:19:22 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:33:34 
Re: Get login name and/or path to home directory of current user
glenn andreas <gandrea  2007-06-01 16:14:02 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-01 16:54:16 
Re: Get login name and/or path to home directory of current user
Bo Lindbergh <blgl@[EM  2007-06-02 13:14:06 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-02 07:10:43 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:33:46 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 18:33:59 
Re: Get login name and/or path to home directory of current user
russotto@[EMAIL PROTECTED  2007-06-03 20:35:12 
Re: Get login name and/or path to home directory of current user
Gabriele Greco <gabrie  2007-06-11 15:59:22 
Re: Get login name and/or path to home directory of current user
Ben Artin <macdev@[EMA  2007-06-11 08:13:57 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-11 23:02:08 
Re: Get login name and/or path to home directory of current user
Steven Fisher <steve@[  2007-06-12 00:42:44 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-11 20:53:38 
Re: Get login name and/or path to home directory of current user
Ben Artin <macdev@[EMA  2007-06-11 17:58:24 
Re: Get login name and/or path to home directory of current user
Gregory Weston <uce@[E  2007-06-11 17:47:12 
Re: Get login name and/or path to home directory of current user
Michael Ash <mike@[EMA  2007-06-11 19:36:11 
Re: Get login name and/or path to home directory of current user
Steven Fisher <steve@[  2007-06-12 00:41:25 
Re: Get login name and/or path to home directory of current user
SM Ryan <wyrmwif@[EMAI  2007-06-01 07:52:08 
Re: Get login name and/or path to home directory of current user
Sherm Pendley <spamtra  2007-06-01 02:26:44 
Re: Get login name and/or path to home directory of current user
Clark Cox <clarkcox3@[  2007-05-31 16:24:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 1:14:32 CST 2008.