Alias (Mac OS)
This article needs additional citations for verification. (May 2010) |
This article includes a list of general references, but it lacks sufficient corresponding inline citations. (April 2009) |
Type code | alis |
---|---|
Uniform Type Identifier (UTI) | com.apple.alias-file |
Magic number | 'book\0\0\0\0mark\0\0\0\0' |
Developed by | Apple, Inc. |
Type of format | shortcut |
In
It is similar to the
Function
An alias acts as a stand-in for any object in the file system, such as a
Preventing alias failure
An alias is a dynamic reference to an object. The original may be moved to another place within the same filesystem, without breaking the link. The operating system stores several pieces of information about the original in the resource fork of the alias file. Examples of the information used to locate the original are:
- path
- file ID (inode number)
- directory ID (inode number)
- name
- file size
Since any of these properties can change without the computer's knowledge, as a result of user activity, various search algorithms are used to find the most plausible target. This fault-tolerance sets the alias apart from similar functions in some other operating systems, such as the
The question can arise of how an alias should work if a file is moved, and then a file is created with the same name as the original moved file, since the alias can be used to locate both the original name and the new location of the original file. With symbolic links the reference is unambiguous (soft links refer to the new file, hard links to the original). Before Mac OS X 10.2, however, such an ambiguous alias would consistently find the original moved file, rather than the recreated file. In Mac OS X 10.2 and later releases, the new file is found, matching the behaviour of symbolic links [1]. macOS applications can programmatically use the old behavior if required.
Aliases are similar in operation to shadows in the graphical Workplace Shell of the OS/2 operating system.
Distinguishing marks
In System 7 through Mac OS 9, aliases distinguished themselves visually to the user by the fact that their file names were in italics. To accommodate languages that don't have italics (such as Japanese), in Mac OS 8.5 another distinguishing mark was added, badging with an "alias arrow"—a black arrow with a small white border—similar to that used for shortcuts in Microsoft Windows.
In macOS, the filenames of aliases are not italicized, but the arrow badge remains.
File structure
The alias files in macOS start by the magic number 62 6F 6F 6B 00 00 00 00 6D 61 72 6B 00 00 00 00
which is in ASCII book␀␀␀␀mark␀␀␀␀
(␀ representing the Null character).
Following the magic number, it has been reported that an alias has a set of records inside it, each record is 150 bytes long and consists of the fields shown below (all integers are big endian).[2] However, alias files are far larger than this would explain, and include other information at least including icons.[3][4]
- 4 bytes user type name/app creator code = long ASCII text string (none = 0)
- 2 bytes record size = short unsigned total length
- 2 bytes record version = short integer version (current version = 2)
- 2 bytes alias kind = short integer value (file = 0; directory = 1)
- 1 byte volume name string length = byte unsigned length
- 27 bytes volume name string (if volume name string < 27 chars then pad with zeros)
- 4 bytes volume created mac date = long unsigned value in seconds since beginning 1904 to 2040
- 2 bytes volume signature = short unsigned HFS value
- 2 bytes volume type = short integer mac os value (types are Fixed HD = 0; Network Disk = 1; 400kB FD = 2;800kB FD = 3; 1.4MB FD = 4; Other Ejectable Media = 5 )
- 4 bytes parent directory id = long unsigned HFS value
- 1 bytes file name string length = byte unsigned length
- 63 bytes file name string (if file name string < 63 chars then pad with zeros)
- 4 bytes file number = long unsigned HFS value
- 4 bytes file created mac date = long unsigned value in seconds since beginning 1904 to 2040
- 4 bytes file type name = long ASCII text string
- 4 bytes file creator name = long ASCII text string
- 2 bytes nlvl From (directories from alias thru to root) = short integer range
- 2 bytes nlvl To (directories from root thru to source) = short integer range (if alias on different volume then set above to -1)
- 4 bytes volume attributes = long hex flags
- 2 bytes volume file system id = short integer HFS value
- 10 bytes reserved = 80-bit value set to zero
- 4+ bytes optional extra data strings = short integer type + short unsigned string length (types are Extended Info End = -1; Directory Name = 0; Directory IDs = 1; Absolute Path = 2; AppleShare Zone Name = 3; AppleShare Server Name = 4; AppleShare User Name = 5; Driver Name = 6; Revised AppleShare info = 9; AppleRemoteAccess dialup info = 10)
- string data = hex dump
- odd lengths have a 1 byte odd string length pad = byte value set to zero
Alias record structure outside of size length
The following is for use with the Apple's Alias Resource Manager.
- 4 bytes resource type name = long ASCII text string
- 2 bytes resource ID = short integer value
- 2 bytes resource end pad = short value set to zero
Java code to flag an alias file
// This function checks whether a file matches the alias magic number.
public static boolean checkForMacAliasFile(File inputFile) throws FileNotFoundException, IOException {
// Only files can be aliases.
// Do not test directories; they will be false.
if (inputFile.isFile()) {
byte[] bookmark = new byte[] {
0x62, 0x6F, 0x6F, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x6D, 0x61, 0x72, 0x6B, 0x00, 0x00, 0x00, 0x00
};
long length = inputFile.length();
if (length > 16) {
byte[] result = new byte[16];
FileInputStream fis = new FileInputStream(inputFile);
fis.read(result);
fis.close();
return Arrays.equals(result, bookmark);
}
}
return false;
}
There is a github repo with working C++ code here.
Managing aliases
User interface
In System 7, the only way to create an alias was to select the original and choose "Make Alias" from the "File" menu. An alias, with the same name and " alias" appended would then be created in the same folder. In later versions, it became possible to create aliases by
Mac OS 8.5 added a feature for re-connecting aliases that had been broken for one reason or another (when the simple search algorithms failed to find a reliable replacement). This was done by selecting a new target through the standard Open File dialog.
In Mac OS 8.5 options were added for command-option dragging an object in the Finder to create an alias at that location. This is where the alias cursor was added to the system. The cursor mirrors the appearance of the "create shortcut" cursor on Windows systems.
Programming API
The Alias Manager API is part of Carbon that allows developers to create aliases and access the aliased file.[5]
Mac OS X 10.6 introduced the Bookmarks API to Cocoa as a set of methods on NSURL
and functions for CFURL
.[6][7] In Mac OS X 10.7.3, the API was enhanced for the App Sandbox with security-scoped bookmarks, which add security permissions to aliases on a per-application or per-document basis.[8]
In Mac OS X 10.8 the Alias Manager API was officially deprecated in favor of the Bookmarks API.[5]
Relation to BSD symbolic and hard links
There is currently no pre-installed command to resolve an alias to the path of the file or directory it refers to. However, a freely available C program makes use of the Mac
References
- ^ "Chapter 4 - Alias Manager / About the Alias Manager - Search Strategies". Inside Macintosh: Files. Archived from the original on October 7, 2008.
- ^ "Some information about MacOS aliases collected from the web". Archived from the original on 2010-01-20.
- ^ "Why are Finder alias files so huge lately?". Apple Support Communities. Archived from the original on 2021-05-07.
- ^ "Further details, including changes with various Mac OS versions". Archived from the original on 2013-04-30. Retrieved 2018-10-11.
- ^ a b "Alias Manager". Apple Developer Documentation. Archived from the original on 2020-08-11.
- ^ "NSURL and CFURL Release Notes". Mac OS X Reference Library. 2008-06-05. Archived from the original on 2018-10-26.
- ^ "File System Programming Guide". Mac OS X Developer Library. 2011-06-06. Archived from the original on 2011-10-06.
- ^ "App Sandbox in Depth". Mac OS X Developer Library. 2016-09-13. Archived from the original on 2012-07-11.
- ^ Davis, Thos. "getTrueName.c". Mac OS X Hints. IDG. Archived from the original on 2014-11-13. Retrieved 24 October 2016.
External links
- System 7 aliases — Article about System 7 aliases, from 1992