Skip to content

Commit f993894

Browse files
committed
Add timespec structured mtime metadata
1 parent 0c055cb commit f993894

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

UNIXFS.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,25 @@ message Data {
6161
optional uint64 hashType = 5;
6262
optional uint64 fanout = 6;
6363
optional uint32 mode = 7;
64-
optional int64 mtime = 8;
64+
optional TimSpec mtime = 8;
6565
}
6666
6767
message Metadata {
6868
optional string MimeType = 1;
6969
}
70+
71+
message TimeSpec {
72+
// Use of int64 is deliberate - negative epoch is super unlikely
73+
// Using sint64 would introduce zig-zag encoding ( harder to eyeball )
74+
// The varint representing the time of writing this is 5 bytes long
75+
// It will remain so until October 26, 3058 ( 34,359,738,367 )
76+
required int64 EpochSeconds = 1;
77+
78+
// fixed32 ( always 4 bytes, no varint ), as nanosecs are often > 2^28
79+
// https://developers.google.com/protocol-buffers/docs/proto#scalar
80+
// NOTE: on the wire this value will be *little* endian
81+
optional fixed32 EpochNanoseconds = 2;
82+
}
7083
```
7184

7285
This `Data` object is used for all non-leaf nodes in Unixfs.
@@ -90,7 +103,9 @@ UnixFS currently supports two optional metadata fields:
90103
- The remaining 20 bits are reserved for future use, and are subject to change. Spec implementations **MUST** handle bits they do not expect as follows:
91104
- For future-proofing the (de)serialization layer must preserve the entire uint32 value during clone/copy operations, modifying only bit values that have a well defined meaning: `clonedValue = ( modifiedBits & 07777 ) | ( originalValue & 0xFFFFF000 )`
92105
- Implementations of this spec must proactively mask off bits without a defined meaning in the implemented version of the spec: `interpretedValue = originalValue & 07777`
93-
* `mtime` -- The modification time in seconds since the epoch. This defaults to the unix epoch if unspecified
106+
* `mtime` -- A two-element structure ( `EpochSeconds`, `EpochNanoseconds` ) representing the modification time in seconds relative to the unix epoch `1970-01-01T00:00:00Z`. In contexts where an mtime is mandatory ( e.g. FUSE interfaces ) implementations must treat an unspecified mtime as `0`.
107+
- `EpochSeconds` represents the amount of seconds after **or before** the epoch. Implementations must be able to gracefully handle negative mtime, even if such a value is not applicable within their domain ( e.g. a POSIX filesystem )
108+
- `EpochNanoseconds` represents the fractional part of the mtime as the amount of nanoseconds. The valid range for this value is the integer range `[1, 999999999]`. If a fractional part outside of this range is encountered, implementations should consider the entire metadata block invalid and abort processing it. Note that **a fractional value of `0` is NOT valid** - omit the nanosecond value altogether to represent whole seconds.
94109

95110
### Deduplication and inlining
96111

0 commit comments

Comments
 (0)