One of the problems computers have is identifying data. Given a random chunk of bytes in a disk file, how can anyone (you or the computer) know what their purpose is? Is it a program? A configuration file or other data for some other program? How can you tell?
Sometimes the answer was simply "you can't". The earliest systems didn't do much in this area. The only real attempt was to use file name extensions: a DOS ".com" file is nothing more than the actual machine code that will execute on the CPU - and I mean absolutely nothing more - it IS the code. Therefore, any random block of data, if saved with a ".com" extension, could be loaded and executed (not likely to have good results, of course).
But even poor old DOS had .exe files, which are a bit more complicated. The extension is part of what tells DOS that you have a .exe file, but the file also has a specific structure; you can't just take any bunch of junk, rename it as "junk.exe" and convince DOS it ought to try running it. Specifically, .exe files use a "magic number" : hex 4d5a in the first two bytes.
Mac OS X of course has a much more sophisticated way to do this kind of thing, but you do have a file /usr/share/file/magic and "man magic" will tell you all about it.
But neither magic numbers nor extensions really provide a satisfactory answer to the problem. Enter UTI's.
UTI's (stored in metadata, of course) identify data. It's not just files, by the way; streaming data, cut-and-paste data, a disk volume - if it exists, it can have a UTI type. Obviously this is much more powerful than identifying things by extensions or by magic numbers. For one thing, UTI's can be related to other UTI's: if a .html file's UTI is a subset of the text UTI, then any text app can handle it. Extensions aren't needed, and data files are easily asociated with applications.
When I first read about this, my immediate reaction was to think "Mime?". Mime types aren't the answer, at least in Apple's opinion. Mime starts off in the right direction, but only has a two level hierarchy and requires approval by the IANA for extensions other than "x-". The UTI that Apple proposes a more extensible format where it has provided top-level identifiers such as public.text, public.plain-text, etc. If you want to define a type yourself, you don't need Apple: "com.yourdomain.yourtype" is how you do it. In your app's Info.plist, you declare that and say what UTI's it inherits from. See http://developer.apple.com/documentation/Carbon/Conceptual/understanding_utis/ for more details and http://arstechnica.com/reviews/os/macosx-10.4.ars/11 also has a nice overview of all this.
More Articles by Tony Lawrence - Find me on Google+
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar