Skip to content

Commit f30839b

Browse files
committed
docs: adds spec sections for mode and mtime metadata
I didn't include the pros and cons of the other options because I don't think they should be included in the spec. That is, if I'm implementing this, I read the spec to understand what I should implement and how it should behave, I don't want to read a bunch of exposition on how we got to where we are. The decision log is important though, should it go in `ipfs/notes`? Or maybe we could have accompanying `*-notes.md` files? Follows on from/supersedes #223
1 parent a663e93 commit f30839b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

UNIXFS.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ message Data {
4646
4747
optional uint64 hashType = 5;
4848
optional uint64 fanout = 6;
49+
50+
optional uint32 mode = 7;
51+
optional int64 mtime = 8;
4952
}
5053
5154
message Metadata {
@@ -59,6 +62,32 @@ For files that are comprised of more than a single block, the 'Type' field will
5962

6063
This data is serialized and placed inside the 'Data' field of the outer merkledag protobuf, which also contains the actual links to the child nodes of this object.
6164

65+
For files comprised of a single block, the 'Type' field will be set to 'File', 'filesize' will be set to the total number of bytes in the file and the file data will be stored in the 'Data' field.
66+
67+
The serialized size of a UnixFS node must not exceed 256KiB in order to work will with the [Bitswap] protocol.
68+
69+
## Metadata
70+
71+
UnixFS currently supports three optional metadata fields:
72+
73+
* `mode` -- The `mode` is for persisting the [file permissions in numeric notation](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) \[[spec](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html)\]. If unspecified this defaults to `0755` for directories/HAMT shards and `0644` for all other types where applicable.
74+
* `mtime` -- The modification time in seconds since the epoch. This defaults to the unix epoch if unspecified.
75+
* `MimeType` -- The mime type of the file. This field is deprecated, as is the `Metadata` message and neither will be present in `UnixFSv2` because mime types are not typically properties of a file system.
76+
77+
### Inheritance
78+
79+
When traversing down through a UnixFSv1.5 directory, child entries without metadata fields will inherit those of their direct ascendants.
80+
81+
### Deduplication and inlining
82+
83+
Where the file data is small it would normally be stored in the `Data` field of the UnixFS `File` node.
84+
85+
To aid in deduplication of data even for small files, file data can be stored in a separate node linked to from the `File` node in order for the data to have a constant [CID] regardless of the metadata associated with it.
86+
87+
As a further optimization, if the `File` node's serialized size is small, it may be inlined into it's v1 [CID] by using the [`identity`](https://github.com/multiformats/multicodec/blob/master/table.csv) [multihash].
88+
89+
Such [CID]s must consist of 23 bytes or fewer in order for them to fit inside the 63 character limit for a DNS label when encoded in base32 (see [RFC1035 Section 2.3.1](https://tools.ietf.org/html/rfc1035#section-2.3.1)).
90+
6291
## Importing
6392

6493
Importing a file into unixfs is split up into two parts. The first is chunking, the second is layout.
@@ -86,3 +115,7 @@ If there is only a single chunk, no intermediate unixfs file nodes are created,
86115
## Exporting
87116

88117
To read the file data out of the unixfs graph, perform an in order traversal, emitting the data contained in each of the leaves.
118+
119+
[multihash]: https://tools.ietf.org/html/draft-multiformats-multihash-00
120+
[CID]: https://docs.ipfs.io/guides/concepts/cid/
121+
[Bitswap]: https://github.com/ipfs/specs/blob/master/BITSWAP.md

0 commit comments

Comments
 (0)