Skip to content

Commit 8cd0673

Browse files
committed
layer: add hardlink handling information
Fixes: #306 Signed-off-by: Vincent Batts <[email protected]>
1 parent eebd585 commit 8cd0673

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

layer.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,46 @@ Where supported, MUST include file attributes for Additions and Modifications in
4444
* Group Name (`gname`) *secondary to `gid`*
4545
* Mode (`mode`)
4646
* Extended Attributes (`xattrs`)
47-
* Symlink reference (`linkname`)
47+
* Symlink reference (`linkname` + symbolic link type)
48+
* [Hardlink](#hardlinks) reference (`linkname`)
4849

4950
[Sparse files](https://en.wikipedia.org/wiki/Sparse_file) SHOULD NOT be used because they lack consistent support across tar implementations.
5051

52+
#### Hardlinks
53+
54+
Hardlinks are a [POSIX concept](http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html) for having one or more directory entries for the same file on the same device.
55+
Not all filesystems support hardlinks (e.g. [FAT](https://en.wikipedia.org/wiki/File_Allocation_Table)).
56+
57+
Hardlinks are possible with all [file types](#file-types) except `directories`.
58+
Non-directory files are considered "hardlinked" when their link count is greater than 1.
59+
Hardlinked files are on a same device (i.e. comparing Major:Minor pair) and have the same inode.
60+
The corresponding files that share the link with the > 1 linkcount may be outside the directory that the changeset is being produced from, in which case the `linkname` is not recorded in the changeset.
61+
62+
Hardlinks are stored in a tar archive with type of a `1` char, per the [GNU Basic Tar Format][gnu-tar-standard] and [libarchive tar(5)][libarchive-tar].
63+
64+
While approaches to deriving new or changed hardlinks may vary, a possible approach is:
65+
66+
```
67+
SET LinkMap to map[< Major:Minor String >]map[< inode integer >]< path string >
68+
SET LinkNames to map[< src path string >]< dest path string >
69+
FOR each path in root path
70+
IF path type is directory
71+
CONTINUE
72+
ENDIF
73+
SET filestat to stat(path)
74+
IF filestat num of links == 1
75+
CONTINUE
76+
ENDIF
77+
IF LinkMap[filestat device][filestat inode] is not empty
78+
SET LinkNames[path] to LinkMap[filestat device][filestat inode]
79+
ELSE
80+
SET LinkMap[filestat device][filestat inode] to path
81+
ENDIF
82+
END FOR
83+
```
84+
85+
With this approach, the link map and links names of a directory could be compared against that of another directory to derive additions and changes to hardlinks.
86+
5187
## Creating
5288

5389
### Initial Root Filesystem
@@ -279,4 +315,6 @@ Layers that have these restrictions SHOULD be tagged with an alternative mediaty
279315
[Descriptors](descriptor.md) referencing these layers MAY include `urls` for downloading these layers.
280316
It is implementation-defined whether or not implementations upload layers tagged with this media type.
281317

318+
[libarchive-tar]: https://github.com/libarchive/libarchive/wiki/ManPageTar5#POSIX_ustar_Archives
319+
[gnu-tar-standard]: http://www.gnu.org/software/tar/manual/html_node/Standard.html
282320
[tar-archive]: https://en.wikipedia.org/wiki/Tar_(computing)

0 commit comments

Comments
 (0)