[LTP] open: remove O_DIRECTORY case (move to fstat test)
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Thu Jun 4 17:09:29 CEST 2026
Hi Jinseok,
On Thu, 04 Jun 2026, Jinseok Kim wrote:
> open: remove O_DIRECTORY case (move to fstat test)
--- [PATCH 2/2] ---
> +/*\
> + * Verify that :manpage:`fstat(2)` correctly identifies various
> + * file types.
> + */
> + .needs_root = 1,
Ground Rule 4 requires that the reason for needing root is documented in
the test's doc comment. The test calls SAFE_MKNOD() to create block and
character device nodes, which requires CAP_MKNOD. Please add a note in
the /*\ ... */ block, e.g.:
"Requires root to create block and character device nodes with mknod(2)."
> + int flags = O_RDONLY | O_NONBLOCK;
> +
> + if (tc->exp_type == S_IFDIR)
> + flags |= O_DIRECTORY;
> +
> + int fd = SAFE_OPEN(tc->path, flags);
For the block device case (BLK_DEV, makedev(7, 3) = loop3) this will
attempt to open the underlying block device via its driver. If the loop
module is not loaded -- which can happen in containers or minimal
environments -- SAFE_OPEN aborts with TBROK rather than skipping cleanly.
The test only needs the fd to call fstat(), not to perform I/O. Using
O_PATH avoids instantiating the driver entirely and is more appropriate
for a test focused on fstat() metadata. With O_PATH the branching on
S_IFDIR also becomes unnecessary since directories can be opened without
O_DIRECTORY through an O_PATH descriptor:
int fd = SAFE_OPEN(tc->path, O_PATH | O_NOFOLLOW);
O_PATH + fstat() has been supported since Linux 3.6.
Verdict: Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
More information about the ltp
mailing list