-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce time stamp precision, take two #21
Comments
Hi, thanks for the summary. I agree that this is an unsolved problem. Here are my comments:
I think FAT does not matter as it does not support extended attributes. We can go for 100ns (NTFS).
OK
I think 100ns is precise enough for everything. No need for extra options.
"corrupt" is ok with 100ns. I don't see this happening by accident. |
Thank you for the feedback @rfjakob
You are totally right, we can ignore FAT! However, SMB does matter: it is a very common file sharing protocol, and does support extended attributes. The output I originally posted showed only 1 second because
It is not always rounding down to closets even integer. Sometimes it rounds down to the closest odd one. Here
Oh darn... In this last one, the time difference is even greater than 2 seconds! Let me do some extra testing and report back here. |
Thanks again for your feedback @rfjakob, it pushed me to get hard data and realize that we may actually need to ignore time differences of up to 3 seconds, maybe even more. I ran 1000 tests, calculating some aggregates using:
The results were (about 1 hour ago):
Running the same again now, I get quite different results:
The min is now barely below 2 seconds, and the max dangerously close to 3. I wonder it it would ever go above 3... The time of the day may matter. I'll put this script in a cron job, run it throughout the day and see what that gives us. I'll report back here when done. |
The data did not make sense, so I looked closer I found the reason: the With the fixed script, I get much more sensible data. With 1000 runs:
We get this, which is quite conclusive:
Updating the suggestion accordingly: Suggested implementationI suggest:
*1: SMB, a commonly used file sharing protocol that supports extended attributes, has a 1 second precision What do you think @rfjakob ? |
Hmm, I don't know what's going on on /Volumes/Organizer, but on my Synology SMB mount, there's more that 1 second resolution:
|
OK, so it is not just SMB... It could be a limitation of the MacOS SMB client, or differences on the SMB server (my NAS is a QNAP). I'll do some more experimenting and will report back here. |
Here are my findings:
Here is the demonstration. Note: all the 1) The MacOS SMB client can write timestamps with 100ns resolution:
=> The file was written with a 100ns timestamp resolution 2) But it will read them back with 1s resolution:To show this, I used
=> The fractional part was lost, which shows that So anyway, to support SMB on MacOS, we would need to ignore time differences of 1 second or less. What do you think? |
Does it always round down to the next second? If it does, we can do
|
PS: The difference to just checking if the mtimes are less than 100ns (or 1s) apart is that we only consider something equal when it has zeros in the end, which is very unlikely to occour by chance. |
Ah, I see your point. It sounds like a good idea! One potential problem is: I am still not sure where the rounding happens exactly. I just found that it is not as simple as "writes with 100ns but reads with 1s". The rounding may happen in multiple places too. In this example, two "writes" (one for create, and one for update) happen with different resolutions! I just touch the same file twice, the first time to create it, the second time to update its timestamps:
Anyway, to answer your question, it does seem to be always rounding down. Even
|
Oh, this keeps getting weirder: it is NOT as simple as "creates with 100ns, updates with 1s" either:
One potential explanation, simple (so, Occam's razor, more likely to be correct) and that is consistent with all previously seen behaviors:
So the explanation for all this may simply be: the macOS SMB client handles timestamps (read or write) with a 1s resolution, loosing the fractional seconds (hence rounding down). |
I think I should add
|
I second (support) the proposed solution to this problem. I'm on the same boat as yemartin. My files are on SMB network, and accessed via MacOS SMB client. I'm facing the same issue that the cshatag timestamps calculated on drives mounted on SMB network have lower resolution than timestamp calculated on local drive (even if both drives are the same format). I'm only seeing differences that 1s or less, though. However, this time difference makes it impossible to detect if data is corrupt when I copy files from a local drive to an SMB mounted drive. I would like to be able use cshatag to check file integrity contents on network drives. |
SMB only supports 100ns, so we may have missed corruption in the following case: 1) Files are stored on ext4, cshatag runs and tags all files 2) Files are moved to SMB 3) Some file content gets corrupted during the move 4) cshatag considers these as "outdated" instead of "corrupt" 100ns should be good enough for everything, and avoids this problem. #21
I went for the simpler route in the end. Resolution is now 1s on MacOS and 100ns on Linux. Please test if that works as intended! |
This is a follow-up to #12 that was closed with the introduction of
<timechange>
. But unfortunately,<timechange>
does not solve the original problem:cshatag
still cannot detect bit corruption that happens during move or copy operations between two filesystems with different timestamp precisions.With the same example as in #12, with one added command to simulate corruption during transfer, and with:
/tmp
on my root filesystem (APFS)/Volumes/Organizer
from my NAS, mounted through SMB (SMB_3.1.1)Current behavior
Expected behavior
<timechange>
was a nice introduction for when the data has not changed. But when the data did change, we still need to ignore small time differences below a certain threshold, to differentiate between a legitimate<outdated>
, and a<corrupt>
file.Suggested implementation
As per the discussion in #12, I suggest:
*1: FAT has a 2 seconds precision on last modified time
*2: With this new behavior as default, users may get a harmless false positive, but the file content is still good. If the behavior is opt-in, users would get false negatives, meaning corruption would go undetected.
Note: to get the false positive, the user would need to make a legitimate edit within 2 seconds of running
cshatag
against a given file, quite unlikely. And it if does happen, the file content is good anyway, so no harm done.New status or not?
To keep things simple, I suggest we just do, when data has changed:
if time_delta <= threshold
: corruptelse
(i.e.time_delta > threshold
): outdatedbut we can also consider introducing a new status, something like:
if time_delta == 0
: corruptelse if time_delta <= threshold
: suspiciouselse
(i.e.time_delta > threshold
): outdatedWhat do you think?
The text was updated successfully, but these errors were encountered: