Repository navigation
df: implement it - #241
Open
metif12 wants to merge 2 commits into
Open
df: implement it#241metif12 wants to merge 2 commits into
metif12 wants to merge 2 commits into
Conversation
Reports per-volume capacity, used and available space, with -a -B -h -H -i -k -l -m -g -P -T -t -x --total and file operands. The presentation layer lives in common/df so the column layout is unit-testable; src/df is a thin main. Windows enumerates fixed drives through GetLogicalDrives/GetDiskFreeSpaceExA, Unix reads /proc/mounts and statvfs. Column widths, the -H suffix table (-si keeps a lowercase k but M, G, T for the rest) and the total row's '-' placeholders were measured against GNU 9.4. -i is refused on Windows because no API there exposes inode counts. Two reference quirks are deliberately not copied: uutils 0.0.17 reports Available as 0 and Use% as 100% on Windows, and this port reports the real numbers instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
dffor the disk-space listing: per-volume capacity, used and available space, a percentage, the file-system type and the mount point.The presentation layer lives in
common/dfandsrc/dfis an eleven-linemain, becausev test <dir>only compiles_test.vfiles, so a test insrc/dfcannot see code defined insrc/df. Moving the logic into a module made the column layout assertable directly instead of only through the built binary.Backends:
GetLogicalDrives,GetDiskFreeSpaceExAandGetVolumeInformationA. Device name is the drive letter, since that is the name a Windows user has for the volume./proc/mountsplusos.disk_usage(statvfs), including the kernel's octal-escape decoding for device and mount-point names.Options:
-a -B -h -H -i -k -l -m -g -P -T -t -x --total, file operands. Clustered short options (-hT),-B512and comma-separated--type=a,bare parsed here rather than bycommon.flag_parser, which does not expand clusters.Measured against GNU 9.4 before writing the code:
Size/Used5,Use%4. The last column is not padded, so there are no trailing spaces.--sikeeps a lowercasekbut usesM,G,Tfor the rest;-husesK.132kversus128Kis what distinguishes them.--totalrow prints-for both type and mount point, and the percentage is rounded to nearest, not truncated.Not implemented, and refused rather than silently wrong:
-ion Windows. No API there exposes inode counts, so it printsdf: doesn't support -i optionand exits 1, which is what uutils does too. It works on Unix.--block-sizeaccepts plain decimal only.1K,1MandKBparse as nothing and produce a diagnostic instead of a wrong number.--output=FIELD_LISTis not implemented.Two reference behaviours are deliberately not copied. uutils 0.0.17 on Windows reports
Availableas0andUse%as100%for every volume, anddf C:resolves to the wrong one. Those are defects in the reference, so this port reports the real numbers and the tests do not diff against the rig for those cases; the column layout is pinned against GNU instead, following the same approachunexpandtakes.18 test functions, all green.
v fmt -lis clean for everything this changes; it reportssrc/tr/tr.v, which comes from upstream #239 untouched here.