-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add birthtime, blocksize and blks to stat output for NTFS #848
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #848 +/- ##
==========================================
+ Coverage 76.48% 76.50% +0.02%
==========================================
Files 314 314
Lines 26933 26945 +12
==========================================
+ Hits 20600 20615 +15
+ Misses 6333 6330 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
So what do we want to use, the windows style or unix style? Cause I'd prefer them to be consistent across dissect. Regardless what the python docs say. As we change it anyways |
The entire filesystem layer is designed to be consistent with Python since the beginning of Dissect. |
In that case, have we changed that for any other filesystem then? Where the Cause in this current case it seems to only hold for ntfs doesn't it? |
https://github.com/python/cpython/blob/3.12/Modules/posixmodule.c#L2142-L2145 The only thing missing currently is setting Btrfs and other filesystems don't have this, as they actually properly expose all 4 timestamps. |
st_birthtime gets set here right?: https://github.com/python/cpython/blob/aee219f4558dda619bd86e4b0e028ce47a5e4b77/Python/fileutils.c#L1122 where ctime gets changed afterwards at the posixmodule sets it to the value in st_birthtime, which is only used for backwards compatibility. So sure, I'll set the ctime to birthtime for now. And make a note about it for backwards compatibility |
d5a6364
to
8fd94c0
Compare
In our code. |
which I've done? |
Yes, it seems to be correct now. Both The change for |
8fd94c0
to
88d9121
Compare
Ack on the timestamps. Is @Poeloe still on for a code-review? |
dissect/target/filesystems/btrfs.py
Outdated
|
||
st_info.st_blocks = 0 | ||
if not self.is_dir(): | ||
st_info.st_blocks = math.ceil(st_info.st_blksize / 512) * math.ceil(st_info.st_size / st_info.st_blksize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this double ceiling is correct, it could lead to a really inflated number of blocks, e.g.:
st_size: 256
st_blksize: 128
->
math.ceil(128/512) * math.ceil(256/128) = math.ceil(1/4) * math.ceil(2) = 1 * 2 = 2
Inflates the apparent size by a factor of 4
st_size: 1024
st_blksize: 768
->
math.ceil(768/512) * math.ceil(1024/768) = math.ceil(3/2) * math.ceil(4/3) = 2 * 2 = 4
Inflates the apparent size by a factor of 2
If I read and interpret the various sources of what st_blocks
should be it seems to me it represents the size on disk in blocks (which are 512 bytes in our implementation).
The POSIX/opengroup for example says: "Number of blocks allocated for this object."
The on disk is important in the sense that if files that are e.g. sparse their size on disk is smaller than their actual size, the same holds for example for files that are compressed on the filesystem layer.
So I think we can just do a math.ceil(st_info.st_size / 512)
here. It also means that for symbolic links st_blocks
should be 0, unless the symbolic link data is not (only) contained in the inode structure.
st_block uses the realsize if defined, oterwise it uses the size the real size on disk is only defined if the file is not a resident file. st_birthtime and st_birthtime_ns now use the creation_time from a MFT Record Other timestamps where incorrectly used, and have been changed: st_mtime: changed from using last_change_time to last_modification_time
5baac61
to
fe92d40
Compare
st_block uses the realsize if defined, oterwise it uses the size
the real size on disk is only defined if the file is not a resident file.
st_birthtime and st_birthtime_ns now use the creation_time from a MFT Record
Other timestamps where incorrectly used, and have been changed:
st_mtime: changed from using last_change_time to last_modification_time