|Home » Learning Curve
Hard Link FAQ
For the cerebrally challenged or for those of you who just want to get up to speed. You thought flaky paint for $150 was the living end? You thought the all-new Apple toasters were too hot too handle? You discovered you're allergic to computer mayonnaise? You thought that Tom Ferris' fuzzballs were embarrassing? Guess what, loser: you still don't have a file system.
Q. What is a hard link?
A. Nothing special. It's just another name to the same physical file.
Q. The same physical item? The same physical file or directory?
A. No. Not on POSIX. POSIX does not allow hard links to directories.
Q. Why not?
A. Good question! Next question!
Q. Are hard links the same as symbolic links?
A. Of course not. They wouldn't have two names, would they?
Q. Are hard links and symbolic links interchangeable?
Q. Why would I want to use a hard link?
A. Because it's there. Because you can. You think of why, Einstein.
Q. Give me some examples?
A. OK, but they'll cost. I'll give you these examples if you give me your bib.
Q. OK. It's a deal.
A. Gimme the bib now.
Q. OK. Here.
A. OK. First example: collaborative work.
Q. How so?
A. You and your colleagues all edit the same file. From different paths.
Q. Something like SubEthaEdit?
A. Yeah. Except not in real time.
Q. And other uses?
A. Tonnes. Millions. Look in your BSD subsystem. Most binaries are hard links.
Q. Why are those binaries hard links?
A. Because when running they go by the name to figure out what to do.
Q. An example?
A. Sure. All the 'zip' programs. They're all the same file.
Q. All the same file?
A. Yup. For both compressing and decompressing.
Q. OK. One final example and the bib is yours.
A. The bib is already mine, sucker.
Q. OK. Sure. But one final example - please?
A. Your shells.
Q. My shells?
A. Yes, your shells. Look them up. You might have four or more.
Q. Four or more?
A. Yes. sh, csh, ksh, tcsh, bash, and so forth.
Q. OK, I got those. So what?
A. Check the linkage. They're not all unique files.
A. Yeah, 'whoa'. If you touch any of them, you're fucked.
Q. I'm fucked?
A. You're fucked. Just as if his Steveness was in the room.
Q. How am I fucked?
A. Because if you touch them you can't modify them.
Q. But I don't want to modify them!
A. But you might have to - or want to. You might get a new copy.
Q. So I just overwrite it, right?
A. Wrong. If you overwrite it, you break the hard link.
Q. I do what?
A. You break the hard link. To the other names.
Q. I do?
A. Yes you do.
Q. Why? I thought hard links were collaborative!
A. They are - on Unix.
Q. But isn't OS X Unix?
A. It would seem not, or what do you say?
Q. I'm a bit confused.
A. Here. Wipe yourself with the bib.
Q. So what do I do?
A. Nothing. Literally 'nothing'.
Q. As in what?
A. As in you can't update any of your files.
Q. Would I ever want to?
A. Sure. Suppose you get an update for a shell or a zipper.
Q. I can't just copy it in?
A. No. If you do, you break the links.
Q. Can't I just restore the links?
A. Only if you know what those links were.
Q. So I can make a list of the links first then?
A. With some tools you could do that. The ACP Xscan might help.
Q. So then it's no issue, is it?
A. Au contraire. You have to manually find all the links first.
Q. But you just said I could. With this 'X-scam'.
A. No. I said it would help. Hard links can be anywhere on your disk.
A. Yeah, 'whoa'.
Q. OK. Now I got a big question.
A. Your time's run out, boob.
A. OK. Shit. You're starting to piss me off, loser.
Q. You just don't appreciate a good user interface!
A. Yeah right.
Q. I bet you don't even read Ars Technica! Or Daring Fireball!
A. Good guess, loser. Did they ever mention hard links?
Q. Not that I can remember.
A. Care to hazard a guess why?
Q. I don't know.
A. That's your homework. Now your final question?
Q. OK. It's this: why doesn't OS X have a POSIX file system?
A. OK. This is your answer: look in the mirror.
(Two days later they meet again.)
Q. Hey! I just want to thank you.
A. For what?
Q. For giving me all that information.
A. Oh that? Hehe! It was all lies. Hehe.
Q. All lies?
A. Yup. All lies.
Q. How so?
A. For example, you can so too overwrite a hard linked file.
Q. You said I couldn't! Where's my bib?
A. You can't - not from an OS X application.
Q. Wait! You can or you can't? Which is it?
A. You can't from an OS X application; you can from the command line.
Q. Huh? Now I'm confused all over again!
A. Join the club, loser.
Q. Do you know why things are like this?
A. Of course. That's what they pay me the Swiss francs for, isn't it?
Q. So why are things like this?
A. Look in your root directory for something called '.vol'.
Q. Yeah. I see it. What is it?
A. Look inside.
Q. Hey! It has '..' but it doesn't have '.'!
A. Nope. It's not a Unix directory.
Q. Not a Unix directory??!??
A. Nope. Anything else in there?
Q. Yeah. A number.
A. Is it a file or a directory?
Q. It appears to be a directory.
A. So drill down into it. What's inside?
Q. Nothing! What's it do?
A. OK. Try this: try copying an ordinary file into there.
Q. It won't work!
A. What's the mode and ownership on .vol?
Q. It's root:wheel and 0444.
A. OK. Drop to a command line and try to change the mode to 777.
Q. It won't work!
A. Did you use 'sudo'?
Q. Yes! Of course!
A. What did you get back?
Q. 'chmod: .vol: Operation not supported'.
A. Puzzled good now, aren't you!
Q. Don't laugh at me!
A. Sorry. You're so easy.
Q. So what's going on in there? And what's that number?
A. What's going on is that directory isn't a Unix directory.
Q. If it isn't a Unix directory - what is it?
A. Ask the geniuses in Cupertino. They're the ones made this mess.
Q. And the number?
A. Here's a clue: check its inode.
Q. They're the same!
Q. So what does that mean?
A. It means 'more Steve Jobs smoke and mirrors'.
Q. So what does this have to do with anything?
A. That directory is used by beige box programs.
A. I guess you heard that beige box programs can't access file paths?
Q. Yeah, I heard that.
A. Then the peanut oil the doctor poured in your ears did good.
Q. How do they access file paths?
A. With CNIDs.
A. Yeah. CNIDs. They're numbers. Don't worry about it.
Q. But I am worried about it!
A. Good. Remember when we talked about hard links?
Q. Of course! That was only a couple of days ago.
A. Just checking. Remember any file can have any number of paths?
A. Apple's file system HFS can't handle that.
Q. It can't?
Q. Why not?
A. Because it assumes there is only one path for each CNID.
Q. OK. I think I got that.
A. OK. Now here's the punch line.
Q. OK. I'm ready.
A. Are you sure? Remember you can overwrite hard links from the command line?
Q. Yes. And I'm ready. I'm definitely ready. Tell me.
A. OK. You can't do it from OS X apps because Apple are still running the toolbox.
A. You've heard of the toolbox?
Q. Yeah. It's called Carbon today?
A. Yes. It's there so all the legacy beige box apps can run on OS X too.
Q. But why would anybody want to run that shit on OS X?
A. Good question. But they can run. Because of that number in there.
Q. How does that work?
A. Easy. The toolbox/Carbon goes in there and asks for a file by CNID.
Q. Yeah. Then what?
A. The driver in there converts the CNID to a Unix path.
Q. But if that file had a hard link, which path would OS X choose?
A. You do know you're not as dumb as you look?
Q. Thanks. By the way, I can't see a driver in there.
A. Appearances can deceive.
Q. So what you're saying is that OS X can't give me my link because of HFS.
A. That's right. If it's not unique, OS X throws a hissy fit. No can overwrite.
Q. But I thought this was NeXTSTEP or Openstep on top?
A. Yeah. That's what a lot of people thought.
Q. Yeah! What happened?
A. Remember what I told you do to a couple of days ago?
Q. Yeah. 'Look in the mirror', you said.
A. Well do it again.
Copyright © Beige Box Blues Productions. All rights reserved. UNIX is a trademark of Bell Laboratories. That at least in Cupertino is almost worthless today.