Skip to content
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

psh: implement 'du' command #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

psh: implement 'du' command #213

wants to merge 1 commit into from

Conversation

gerard5
Copy link
Contributor

@gerard5 gerard5 commented Jan 24, 2024

Description

The du command is used to estimate the space used by a directory or a specific file. The command stands for disk usage. When executed, du traverses the specified directories and prints the sizes of the subdirectories and files (if -a switch is used) in bytes by default, unless specified otherwise (using switch -k for kilobytes and -K for Kibibytes).

Usage: du [-acsxkK] [-d depth] [startdir]
-a	print all (directories and files)
-c	calculate grand total
-s	silent mode
-d n	print directories up to 'n' level deep
-k	round up and print sizes as kilobytes
-K	round up and print sizes as kibibytes

Motivation and Context

Need tool to print directory structure and files while developing a file system.

JIRA: RTOS-745

Examples

ia32-generic, estimate size in bytes of /usr/bin and /bin directories

(psh)% du /usr/bin /bin
498212	/usr/bin
3084624	/bin

kB, all directories

(psh)% du -ck /
17	/lost+found
497	/sbin
2	/mnt
2	/local
3085	/bin
2	/etc/rc.conf.d
4	/etc/ssl/certs
5	/etc/ssl
6	/etc/rc.d
29	/etc
2	/data
499	/usr/bin
146	/usr/share/cow/x_rated
3760	/usr/share/cow
3761	/usr/share
4260	/usr
2	/root
2	/var/tmp
3	/var
1	/dev/pts
1	/dev/event
1	/dev/posix
2	/dev
2	/tmp
7896	/
7896	total

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: imxrt1176-nil, ia32-generic

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gerard5 gerard5 self-assigned this Jan 24, 2024
Copy link

github-actions bot commented Jan 24, 2024

Unit Test Results

7 460 tests  +6   6 745 ✅ +7   36m 20s ⏱️ - 2m 0s
  420 suites ±0     715 💤 ±0 
    1 files   ±0       0 ❌  - 1 

Results for commit cac8d8e. ± Comparison against base commit 1c234da.

This pull request removes 1 and adds 7 tests. Note that renamed tests count towards both.
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit.clear.clear
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit.generate.change
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit.generate.unique
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit.generate.version
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit.parse.parse_basic
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit.parse.parse_fail
phoenix-rtos-tests/libuuid/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libuuid/unit.parse.unparse

♻️ This comment has been updated with latest results.

@gerard5 gerard5 force-pushed the gerard5/RTOS-745 branch 2 times, most recently from 5a996a8 to 04c47cb Compare January 24, 2024 09:55
@gerard5 gerard5 marked this pull request as ready for review January 24, 2024 11:15
psh/du/du.c Outdated Show resolved Hide resolved
psh/du/du.c Outdated Show resolved Hide resolved


if ((curLevel >= du_common.levels) || ((maybePrint) && (curLevel >= 0))) {
printf("%zu\t%s\n", roundPrefix(total), d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this can be used:

int psh_prefix(unsigned int base, int x, int y, unsigned int prec, char *buff)

To not reimplement existing functionality

if (!((entry->d_name[0] == '.') && ((entry->d_name[1] == '\0') || ((entry->d_name[1] == '.') && (entry->d_name[2] == '\0'))))) {
const size_t nextPos = makePath(startPos, entry->d_name);
if (nextPos > 0u) {
total += doDirectory(nextPos, curLevel - 1, stbuf.st_dev);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid recursion

@Darchiv Darchiv self-requested a review June 11, 2024 10:57
@gerard5 gerard5 requested review from Darchiv and removed request for Darchiv June 11, 2024 11:01
Implements tool that estimates file space usage

JIRA: RTOS-745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants