skip book previous and next navigation links
go up to top of book: HP OpenVMS System Manager's Manual, Volume 1:... HP OpenVMS System Manager's Manual, Volume 1:...
go to beginning of chapter: Using Files and Directories Using Files and Directories
go to previous page: Creating a CD-ROM Creating a CD-ROM
go to next page: Using BACKUPUsing BACKUP
end of book navigation links

Understanding Hard Links  



A link, or directory entry, is an object in a directory that associates a file name and a version number with a specific file. All links on a volume must represent files on the same volume.

With the introduction of hard link support in OpenVMS Alpha Version 7.3, OpenVMS supports three kinds of links:

Primary links

Aliases

Hard links

OpenVMS Alpha and I64 support files with 0 or more links. The first link to a file is referred to as the "primary link," and is distinguished by having the directory ID and name of the link stored in the file header. Additional links are either aliases or hard links, depending on whether the volume the file resides on has hard links enabled or disabled.

On OpenVMS Alpha and I64 systems, you can enable hard links on particular volumes. On volumes on which hard links are not enabled, non-primary links are aliases. If you choose to enable hard link capability, you cannot create VMS aliases for files on that volume. A volume can support either hard links or aliases, but not both. Use the SET FILE/ENTER command to create either a hard link or an alias for a file.

The essential difference between hard links and aliases is in the effect of a delete operation. What is usually referred to as deleting a file is more precisely deleting a link to that file. When a link to a file is deleted, the associated file might also be deleted. Whether a file is deleted or not depends on whether the volume that the file is on has hard links enabled, and if a hard link to that file has been created.

If you have hard links enabled, a file is actually deleted when no more links to that file exist. If you do not have hard links enabled, and you have not created an alias for a file, essentially only one link to that file exists: the primary link. If you create an alias for that file, and you delete the alias, the file still exists because the primary link to that file has not been deleted. The alias is just another name in a directory for this link. Deleting the primary link deletes the file, leaving the alias entries intact.

Attempting to access a file through an alias link to a deleted file results in a "no such file" error. With a primary link and hard links, many links exist. You actually delete a file when you delete both the primary link and all hard links to that file.

An important related consideration is disk quota. On OpenVMS, the size of each file is charged to the file owner's disk quota. If other users create hard links to a file, they are not charged disk quota. Owners can delete any links to files in directories they can access, but hard links in other users' directories might cause a file to be retained, and the owner will continue to be charged for its quota.

When you enable hard link support on an existing volume, be sure also to execute the ANALYZE/DISK/REPAIR command to ensure the proper operation of hard links.

OpenVMS supports hard links, or aliases, to directories as well as to files. Most UNIX systems limit hard links only to normal files.

Hard Link Examples (INIT and SET VOLUME)  

You can enable hard link support using either the INITIALIZE command or the SET VOLUME command.

To initialize an ODS-5 disk with hard links enabled, issue the following command:

$ INIT/VOLUME_CHARACTERISTICS=HARDLINKS
To enable hard links on a mounted Files-11 volume, issue the following command:
$ SET VOLUME/VOLUME_CHARACTERISTICS=HARDLINKS
If you have a volume that has already been enabled with hard link support and you want to change it, you can disable it using the SET VOLUME command.
$ SET VOLUME SYS$DISK/VOLUME_CHARACTERISTICS=NOHARDLINKS
Issuing this command disables hard link support. However, you should be aware that changing from enabling hard links to disabling hard links may result in some strange file behavior. For example, assume that you have disabled hard link support as shown in the example above, but you would like to create an alias for your file FOO:
$ CREATE FOO.A
$ SET FILE FOO.A/ENTER=FOO.B
You have created an alias for FOO.A called FOO.B. Now you want to delete the original file:
$ DELETE FOO.A;1
FOO.A is deleted. However, if you look for FOO.B on the volume using the directory command,
you receive a "File not found" error, because the primary link to that file no longer exists. For example:
$ DIR FOO.B
To fix this problem, or to check the number of hard links to a file, issue the following command:
$ ANALYZE/DISK/REPAIR
ANALYZE/DISK/REPAIR counts the number of directory entries that references each file, and sets the link count if it is incorrect. Before creating aliases for files on disks that have previously had hard link support enabled, be sure to use the ANALYZE/DISK/REPAIR command to set the link count correctly. If you are unsure as to whether hard links are currently enabled or disabled, issue the SHOW DEVICE/FULL command.

Use DIRECTORY/FULL and DUMP/HEADER to report the link counts. To check the number of links, issue the following command:

$ DIRECTORY/LINK

go to previous page: Creating a CD-ROM Creating a CD-ROM
go to next page: Using BACKUPUsing BACKUP