Fork (file system) explained

In a computer file system, a fork is a set of data associated with a file-system object. File systems without forks only allow a single set of data for the contents, while file systems with forks allow multiple such contents. Every non-empty file must have at least one fork, often of default type, and depending on the file system, a file may have one or more other associated forks, which in turn may contain primary data integral to the file, or just metadata.

Unlike extended attributes, a similar file system feature which is typically of fixed size, forks can be of variable size, possibly even larger than the file's primary data fork. The size of a file is the sum of the sizes of each fork.

Popular file systems that can use forks include Apple's HFS+ and Microsoft's NTFS.

Alternatives

On file systems without forks, one may instead use multiple separate files that are associated with each other, particularly sidecar files for metadata. However, the connection between these files is not automatically preserved by the file system, and must instead be handled by each program that works on files. Another alternative is a container file, which stores additional data within a given file format, or an archive file, which allows storing several files and metadata within a file (within a single fork). This requires that programs process the container file or archive file, rather than the file system handling forks. These alternatives require additional work by programs using the data, but benefit from portability to file systems that do not support forks.

Implementations

Apple

See also: Resource fork. File system forks are associated with Apple's Hierarchical File System (HFS).[1] HFS, and the original Apple Macintosh file system MFS, allowed a file system object to have two kinds of forks: a data fork and a resource fork.

The resource fork was designed to store non-compiled data that would be used by the system's graphical user interface (GUI), such as localizable text strings, a file's icon to be used by the Finder or the menus and dialog boxes associated with an application.[2] However the feature was very flexible, so additional uses were found, such as splitting a word processing document into content and presentation, then storing each part in separate resources. As compiled software code was also stored in a resource, often applications would consist of just a resource fork and no data fork.

One of HFS+'s most obscure features is that a file may have an arbitrary number of custom "named forks" in addition to the traditional data and resource forks. This feature has gone largely unused, as Apple never added support for it under Mac OS 8.1-10.3.9. Beginning with 10.4, a partial implementation was made to support Apple's extended inline attributes.[3]

In Mac OS X until Mac OS X v10.4, users running Unix command line utilities such as tar would risk data loss, as the utilities had not been updated to handle the resource forks of files.[4]

Novell

Starting in 1985, Novell NetWare File System (NWFS), and its successor Novell Storage Services (NSS), were designed from the ground up to use a variety of methods to store a file's metadata. Some metadata resides in Novell Directory Services (NDS), some is stored in the directory structure on the disk, and some is stored in, as Novell terms it, 'multiple data streams' with the file itself. Multiple data streams also allow Macintosh clients to attach to and use NetWare servers.

Microsoft

NTFS, the file system introduced with Windows NT 3.1, supports file system forks known as alternate data streams (ADS).[5] ReFS, a new file system introduced with Windows Server 2012, originally did not support ADS,[6] [7] [8] but in Windows 8.1 64-bit and Server 2012 R2, support for ADS, with lengths of up to 128K, was added to ReFS.[9]

ADS was originally intended to add compatibility with existing operating systems that support forks. A computer program may be directed to open an ADS by specifying the name of ADS after a colon sign (:) after the file path.[10] In spite of the support, most programs, including Windows Explorer and the dir command (before Windows Vista) ignore ADS. Windows Explorer copies ADS and warns when the target file system does not support them, but only calculates the main stream's size and does not list a file or folder's streams. Since Windows Vista, the dir command supports showing ADS.[11] Windows PowerShell v3.0 and later supports manipulating ADS.[12]

Uses

Windows 2000 uses ADS to store thumbnails in image files, and to store summary information (such as title and author) in any file, without changing the main stream.[13] [14] With Windows XP, Microsoft realized that ADS is susceptible to loss when the files containing them are moved off NTFS volumes; thus Windows XP stores them in the main stream whenever the file format supports it. Windows Vista discontinued support for adding summary information altogether, as Microsoft decided that they are too sensitive for ADS to handle.[15] But the use of ADS for other purposes did not stop. Service Pack 2 for Windows XP introduced the Attachment Execution Service that stores details on the origin of downloaded files in an ADS called zone identifier, in an effort to protect users from downloaded files that may present a risk.[16] Internet Explorer and Windows 8 extended this function through SmartScreen.[17] Internet Explorer also uses ADS to store favicons in Internet shortcut files.

Sun

Solaris version 9 and later allows files to have forks. Forks are called extended attributes in Solaris, although they are not within the usual meaning of "extended attribute". The maximum size of a Solaris-type extended attribute is the same as the maximum size of a file, and they are read and written in the same fashion as files. Internally, they are actually stored and accessed like normal files, so their ownership and permissions can differ from those of the parent file. Sub-directories are administratively disabled, so their names cannot contain "/" characters.

Extended attributes in Network File System Version 4 are similar to Solaris-style extended attributes.

Possible security and data loss risks

When a file system supports different forks, the applications should be aware of them, or security risks can arise. Allowing legacy software to access data without appropriate shims in place is the primary culprit for such problems.

If the different system utilities (disk explorer, antivirus software, archivers, and so on), are not aware of the different forks, the following problems can arise:

External links

Notes and References

  1. Web site: File Forks . Apple . 1996-07-02 . Apple . 2006-11-18 . https://web.archive.org/web/20080724120835/https://developer.apple.com/documentation/mac/Files/Files-14.html . 2008-07-24 . dead .
  2. Web site: The Grand Unified Model (1) - Resources . Bruce Horn . Folklore.org . 2017-10-03.
  3. Web site: Mac OS X 10.4 Tiger . John . Siracusa . . 28 April 2005.
  4. Web site: Command-line Backup Solutions on Mac OS X . 2005-10-29 . Apple . 2006-11-18 . dead . https://web.archive.org/web/20080225103633/http://developer.apple.com/macosx/backuponmacosx.html . February 25, 2008 .
  5. Web site: Files and Clusters . 7 January 2021 . Microsoft . 2023-08-15.
  6. Web site: Building the next generation file system for Windows: ReFS . Building Windows 8 . . Microsoft . Verma . Surendra . Steven . Sinofsky . Steven Sinofsky . 16 January 2012 . 20 January 2013 . https://web.archive.org/web/20130216075338/http://blogs.msdn.com/b/b8/archive/2012/01/16/building-the-next-generation-file-system-for-windows-refs.aspx . 16 February 2013 . dead.
  7. Web site: Microsoft goes public with plans for its new Windows 8 file system . . . 16 January 2012 . 31 July 2024 . Mary Jo . Foley.
  8. Web site: Windows Server 2012: Does ReFS replace NTFS? When should I use it? . Martin Lucas . . https://web.archive.org/web/20130123074743/http://blogs.technet.com/b/askpfeplat/archive/2013/01/02/windows-server-2012-does-refs-replace-ntfs-when-should-i-use-it.aspx . 23 January 2013 . dead.
  9. Web site: Resilient File System Overview. 13 January 2017. Microsoft Docs. Microsoft. 15 August 2023.
  10. Web site: Fun with Favicons . 7 September 2013 . 15 August 2023 . . . Law . Eric.
  11. Web site: Use Vista's DIR command to display alternate data streams . Bart De Smet . 2006-07-13 . B# .NET Blog . 2007-07-07 . https://web.archive.org/web/20070927194949/http://bartdesmet.net/blogs/bart/archive/2006/07/13/4129.aspx . 2007-09-27 . dead.
  12. Web site: FileSystem Provider (Windows PowerShell 3.0) . . . 9 August 2012 . dead . https://web.archive.org/web/20150123140513/https://technet.microsoft.com/en-us/library/hh847764%28v%3Dwps.620%29.aspx . 23 January 2015.
  13. Web site: Why are custom properties created on Windows 2000 lost when I view the file from newer versions of Windows?. 27 May 2011. 10 June 2020. The Old New Thing. Microsoft. Chen. Raymond.
  14. Web site: Indexing service adds data streams to image files . Microsoft . 2006-10-27 . Microsoft . 2006-11-18.
  15. Web site: What happened to the Summary information created on Windows 2000 and Windows XP?. 1 May 2012. 10 June 2020. The Old New Thing. Microsoft. Chen. Raymond.
  16. Web site: Demo of "Attachment Execution Service internals" in Windows XP SP2 and Windows Server 2003 SP1 . Bart De Smet . 2005-08-19 . B# .NET Blog . 2006-11-18 . https://web.archive.org/web/20070223140832/http://community.bartdesmet.net/blogs/bart/archive/2005/08/19/3485.aspx . 2007-02-23 . dead.
  17. Web site: Manipulating the zone identifier to specify where a file was download from. 4 November 2013. The Old New Thing. Microsoft. Chen. Raymond.