Commit graph

26 commits

Author SHA1 Message Date
Xiang Xiao
5ead824fff apps: Fix O_ACCMODE bitmask checks after Linux flag alignment
After aligning NuttX open() flag constants with Linux (O_RDONLY=0,
O_WRONLY=1, O_RDWR=2), code that used '(flags & O_RDONLY)' or
'(flags & O_WRONLY)' as a bitmask check is broken because O_RDONLY
is now 0.  Fix by using '(flags & O_ACCMODE)' comparisons instead.

  - usrsocktest: replace 'flags & O_RDWR' with 'flags & O_ACCMODE'
    in fcntl F_GETFL assertions
  - dd: verify mode used '(oflags & O_RDONLY)' to detect verify;
    replace with '(oflags & O_ACCMODE) == O_RDWR'
  - dpopen: replace '(oflag & O_RDWR) == O_RDWR' with
    '(oflag & O_ACCMODE) == O_RDWR'
  - usbmsc: replace 'flags & O_WRONLY' with
    '(flags & O_ACCMODE) == O_RDONLY'
  - fcntl_test: replace '(flags & O_WRONLY) == 0' with
    '(flags & O_ACCMODE) == O_RDONLY'

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-06-30 12:19:58 -04:00
Xiang Xiao
f9f59bd0f8 !apps: drop redundant casts on tv_sec/tv_nsec and fix printf formats
Now that time_t is unconditionally 64-bit (signed int64_t) and the
struct timespec fields tv_sec / tv_nsec are wide enough on their own,
the explicit (uint64_t)/(int64_t)/(int) casts that used to guard the
multiplications and subtractions in *_us / *_ms / *_ns helpers are no
longer needed.  Drop them to keep the timekeeping math readable.

In the same spirit, this commit also normalises the printf-style format
specifiers and casts used to print tv_sec / tv_nsec / tv_usec values.
The prior code was a mix of "%d"/"%u"/"%ld"/"%lu"/"%lld" with matching
(int)/(unsigned long)/(long long) casts; some formats truncated time_t
on 32-bit hosts, others mismatched signedness or width.  Replace all
such cases with the portable POSIX-recommended forms:

  - tv_sec  (time_t,       signed, impl-defined width) -> %jd  + (intmax_t)
  - tv_nsec (long,         signed)                     -> %ld  (no cast)
  - tv_usec (suseconds_t / long)                       -> %ld  (no cast)

Also drop two stale `(FAR const time_t *)&ts.tv_sec` casts that are
unnecessary now that ts.tv_sec is plain time_t.

Arithmetic-cleanup files (existing scope):

  - benchmarks/cyclictest/cyclictest.c:        timediff_us()
  - benchmarks/sd_bench/sd_bench_main.c:       get_time_delta_us()
  - examples/oneshot/oneshot_main.c:           maxus computation
  - examples/watchdog/watchdog_main.c:         current_time_ms (x2)
  - industry/nxmodbus/nxmb_internal.h:         nxmb_util_clock_ms()
  - netutils/ntpclient/ntpclient.c:            timespec2ntp()
  - netutils/ptpd/ptpd.c:                      ptp_adjtime()
  - system/dd/dd_main.c:                       elapsed accounting
  - testing/drivers/drivertest/drivertest_posix_timer.c:
                                               get_timestamp()
  - testing/drivers/sd_stress/sd_stress_main.c:get_time_delta()
  - testing/sched/getprime/getprime_main.c:    elapsed accounting
  - testing/sched/pthread_mutex_perf/pthread_mutex_perf.c:
                                               timespec_avg()

Printf-format-fix files (new in this revision):

  - examples/adjtime/adjtime_main.c
  - examples/charger/charger_main.c
  - examples/netpkt/netpkt_ethercat.c
  - fsutils/mkfatfs/mkfatfs.c
  - graphics/tiff/tiff_initialize.c
  - netutils/ptpd/ptpd.c
  - nshlib/nsh_timcmds.c
  - system/coredump/coredump.c
  - system/ptpd/ptpd_main.c
  - testing/drivers/drivertest/drivertest_oneshot.c
  - testing/mm/kasantest/kasantest.c
  - testing/ostest/semtimed.c
  - testing/sched/pthread_mutex_perf/pthread_mutex_perf.c
  - testing/sched/timerjitter/timerjitter.c
  - testing/testsuites/kernel/time/cases/clock_test_clock01.c
  - testing/testsuites/kernel/time/cases/clock_test_smoke.c

No behavioural change.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-05-22 13:38:25 +08:00
Piyush Patle
9d849adfab include/debug.h: Use <nuttx/debug.h> in apps
Replace app-side includes of <debug.h> with <nuttx/debug.h> to use the
header from the NuttX tree explicitly after the header move.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-11 10:39:27 -03:00
Bartosz Wawrzynek
f09d0b2e09 apps: Fix minor issues for latest toolchains
- crypto/mbedtls: Add -Wno-cpp flag to suppress warnings
- interpreters/quickjs: Add flags to suppress warnings
- lte/alt1250: Fix spelling issues in comments
- system/dd: Add missing includes for modern compilers
- system/zlib: Add -Wno-cpp flag
- testing/cxx: Include missing algorithm header

Signed-off-by: Bartosz <bartol2205@gmail.com>
2026-01-23 10:00:52 +08:00
Lars Kruse
df711238fe system/dd: implement "--help" parameter
Previously the usage hints were displayed only in case of errors.

Signed-off-by: Lars Kruse <devel@sumpfralle.de>
2025-09-12 09:33:13 +08:00
Lars Kruse
db36c8c617 system/dd: emit status messages to stderr (not stdout)
Previously `dd` clobbered its output by writing status messages (e.g.
transfer statistics) to stdout.

Now all status messages are written to stderr.

Signed-off-by: Lars Kruse <devel@sumpfralle.de>
2025-09-12 09:33:13 +08:00
YAMAMOTO Takashi
71ce94a13e system/dd/dd_main.c: fix a typo in a comment
Found by the CI.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2025-08-26 21:56:12 +08:00
YAMAMOTO Takashi
93ced081dc system/dd/dd_main.c: replace #if defined with #ifdef
Although I personally prefer the former, at least one reviewer
preferred the latter. I coundn't find project-wide preferences.
Anyway, this is not important for me.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2025-08-26 21:56:12 +08:00
YAMAMOTO Takashi
78bae4f14f system/dd: portability to non-nuttx platforms
while this is not a goal for this repository,
it's convenient for me (hopefully for some others too)
to be able to build this for other platforms.

an obvious downside is to have a few more ifdefs.

tested with:
```
/opt/wasi-sdk-25.0/bin/clang -Wall -Oz -s -o dd.wasm dd_main.c
```

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2025-08-26 21:56:12 +08:00
dongjiuzhu1
5585c9d347 nshlib/dd: remove nsh dd cmd
using system/dd to instead nsh dd cmd
remove related to config, file.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-04-20 00:41:18 +08:00
dongjiuzhu1
6db2c14faa system/dd: align nsh dd command
nshlib/dd: Increase the integer width for sector size in dd.

    On some systems, using sector sizes larger than 65536 is needed for
    profiling performance or testing.

    Stuart Ianna <stuart.ianna@motec.com.au>

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-04-20 00:41:18 +08:00
dongjiuzhu1
be6a45cb14 system/dd: check infile/outfile when closing
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-04-20 00:41:18 +08:00
dongjiuzhu1
721d79fb73 system/dd: align nshlib/cmd_dd
cmd_dd:support dd can do verify

    After writing the file, compare the contents of the two files again

    Signed-off-by: anjiahao <anjiahao@xiaomi.com>

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-04-20 00:41:18 +08:00
dongjiuzhu1
b608dd0e3f system/dd: align nshlib/cmd_dd
nshlib/cmd_dd: Retry if read() was interrupted

    Without this patch

      nsh> ls /etc/group | dd | dd
      sh [13:100]
      sh [14:100]
      nsh: dd: read failed: 4
      nsh>

    Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-04-20 00:41:18 +08:00
dongjiuzhu1
2a52c4c7f5 system/dd: support conv=nocreat
align nshlib/nsh_cmddd

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-04-20 00:41:18 +08:00
YAMAMOTO Takashi
61551aa849 system/dd: Implement conv=notrunc
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html
> notrunc
>   Do not truncate the output file. Preserve blocks in the output
>   file not explicitly written by this invocation of the dd utility.

Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2025-04-03 18:45:22 +08:00
Alin Jerpelea
66e8296230 system: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-12-30 18:02:50 +08:00
YAMAMOTO Takashi
6560618600 system/dd: improve EOF handling a bit 2024-11-28 15:20:13 +08:00
YAMAMOTO Takashi
9039b9cb18 system/dd: Fix a printf format 2024-11-28 15:20:13 +08:00
YAMAMOTO Takashi
f6f223e674 system/dd: portability to non-nuttx platforms
eg.
```
/opt/wasi-sdk-24.0/bin/clang -Wall -Oz -s -o dd.wasm dd_main.c
```
2024-11-28 15:20:13 +08:00
YAMAMOTO Takashi
1fed08e870 system/dd: make if= and of= optional 2024-11-28 15:20:13 +08:00
YAMAMOTO Takashi
1caf06bd77 system/dd: print help and abort on unknown options 2024-11-28 15:20:13 +08:00
YAMAMOTO Takashi
9c7a65e1e7 system/dd/dd_main.c: remove unnecessary header include 2024-11-28 15:20:13 +08:00
Denis Ryndine
1852731df8 dd_main.c: Add oseek optional argument.
- If oseek=N passed, will seek N*bs on output file before writing.
2024-07-10 00:16:25 +08:00
xuxin19
2e133feb09 cmake:support system apps CMake build
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-06-30 21:40:25 +08:00
chenxiaoyi
0c6016475b system: dd: add standalone dd command
enabling SYSTEM_DD will disable nsh_dd by selecting NSH_DISABLE_DD

Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2023-08-09 20:59:40 +08:00