Fix inode time stamps. #334
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this was a relatively straightforward fix. I noticed the failed test timestamps were off by multiples of 2^32 seconds, both in the runner and when running local tests, so something wasn't calculating properly.
Casting Values:
It looked like something was off with the way bytes were being converted to ints on lines where we get the seconds like this:
accessTimeSeconds := uint64(binary.LittleEndian.Uint32(b[0x8:0xc])). Here we are casting to a uint64 when the value outlined in the kernel doc is a signed int32. This could cause problems if we encounter a date before the Unix epoch, so it's best to use an int32 like the kernel does for the seconds value.Decoding Timestamps:
Since the decoding tasks were very repetitive, it seemed easier to extract the decoding logic into a function and use the kernel doc provided formula:
We use the 32-bit signed time value plus (2^32 * (extra epoch bits))Encoding Timestamps:
The original code simply does this:
This may be problematic because I don't see where the extra epoch bits are being set. However, we can just extract a function and do the inverse of the decode operation.
Tests:
Updated to include the valid time range provided by the kernel doc.
make lintandmake testboth pass.kernel doc