796 Commits

Author SHA1 Message Date
Ryusuke Konishi
d0fa404821 libnilfsgc: use 'size_t' for total reclaimable blocks calculation
In nilfs_xreclaim_segment(), the local variable 'reclaimable_blocks'
holds the sum of reclaimable blocks across multiple segments.  Using a
32-bit type for this variable imposes a local limit on the total count,
which is theoretically inappropriate even though handling requests
exceeding the 32-bit limit is practically rare.

Change the variable type to 'size_t' to avoid enforcing such a local
restriction and to use a type that is more natural for the
architecture.  Also, rename the variable to 'total_reclaimable_blocks'
to clarify that it represents a total count across segments.

Note that checks for overflow, especially on 32-bit architectures,
should be handled separately.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-24 12:59:59 +09:00
Ryusuke Konishi
a2f9c92586 sbin/cleanerd: use bool type for boolean flags
Switch to using the 'bool' type from <stdbool.h> for boolean flags in
struct nilfs_cleanerd and struct nilfs_cldconfig.  Currently, these
are defined as 'int', which is ambiguous regarding their possible values.

Convert these members to 'bool' bitfields to explicitly indicate they
hold truth values.  Update all assignments and constants to use 'true'
and 'false' instead of '1' and '0'.  Also, update configure.ac to
check for the existence of stdbool.h.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-24 12:59:59 +09:00
Ryusuke Konishi
00adeaa0e9 build: avoid overwriting binaries on merged-/usr
Recent distributions, such as Fedora Rawhide, have fully merged /sbin
and /usr/sbin into /usr/bin.  In this configuration, /usr/sbin is a
symbolic link to bin.

In this environment, if nilfs-utils is configured to install binaries
into /usr/bin, the current logic to create compatibility symlinks in
/usr/sbin causes a critical issue: it overwrites the actual installed
binaries with symbolic links to themselves (e.g., /usr/sbin/nilfs-clean
points to ../bin/nilfs-clean, which are the same file).

Fix this by detecting if /usr/sbin and /usr/bin identify the same
directory.  If they are the same, disable the creation of compatibility
symlinks to avoid this overwrite.

Also, update the README file to clarify that compatibility symbolic
links are created only if /usr/sbin is distinct from /usr/bin.

Fixes: 160ab60d4959 ("build: support UsrMerge and Bin-Sbin merge with automatic detection")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-24 08:18:09 +09:00
Ryusuke Konishi
cd6a4ab74c Fix regression causing nilfs-clean failure without device argument
Commit ae0fc7c09b90 ("nilfs-clean: allow specifying filesystem node
instead of device") introduced a regression where running nilfs-clean
without a device argument (e.g., 'nilfs-clean -l') fails with an
"Error: Bad address" message.

This issue occurs because nilfs_cleaner_open() unconditionally calls
nilfs_lookup_device() with the 'device' argument, which is NULL when
no device is specified.  This results in an invalid pointer access
within the lookup function.

Fix this by checking if the 'device' argument is valid before attempting
to resolve the backing device.

Fixes: ae0fc7c09b90 ("nilfs-clean: allow specifying filesystem node instead of device")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-24 00:32:19 +09:00
Ryusuke Konishi
3b56b36203 sbin/cldconfig: fix and improve kernel-doc for nilfs_cldconfig_read()
Fix the kernel-doc comment for nilfs_cldconfig_read() to match the
kernel-doc style and complete the missing descriptions.

This eliminates the following warning and improves code documentation:

 Warning: sbin/cldconfig.c:778 function parameter 'path' not described
  in 'nilfs_cldconfig_read'

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-23 11:44:46 +09:00
Ryusuke Konishi
1b067e62e4 sbin/cleanerd: move macro definitions to head of file
Move the definitions of NILFS_CLEANERD_NSUINFO and NILFS_CLEANERD_NULLTIME
from the middle of the file to the header section.

This resolves the following kernel-doc warning:

 Warning: sbin/cleanerd.c:638 expecting prototype for nilfs_cleanerd_select_segments(). Prototype was for NILFS_CLEANERD_NSUINFO() instead

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-23 11:33:09 +09:00
Ryusuke Konishi
95a15dcb0e sbin/cleanerd: fix and improve kernel-doc for config functions
Fix the kernel-doc comments for nilfs_cleanerd_config() and
nilfs_cleanerd_reconfig() to match the kernel-doc style and complete
the missing descriptions.

This eliminates the following warnings and improves code documentation:

  Warning: sbin/cleanerd.c:284 function parameter 'conffile' not described
   in 'nilfs_cleanerd_config'
  Warning: sbin/cleanerd.c:322 function parameter 'conffile' not described
   in 'nilfs_cleanerd_reconfig'

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-23 11:14:56 +09:00
Ryusuke Konishi
c14126d252 sbin/cleanerd: fix missing kernel-doc description for 'shutdown' member
Add the missing description for the '@shutdown' member in the kernel-doc
comment of struct nilfs_cleanerd.

This fixes the following warning:
  Warning: sbin/cleanerd.c:180 struct member 'shutdown' not described in
   'nilfs_cleanerd'

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-23 10:04:09 +09:00
Ryusuke Konishi
0d90288b6f sbin/cleanerd: fix and improve kernel-doc for nilfs_cleanerd_create()
Fix the kernel-doc comment for nilfs_cleanerd_create() to match the
kernel-doc style and complete the missing descriptions.

This eliminates the following warning and improves code documentation:
  Warning: sbin/cleanerd.c:430 function parameter 'dir' not described in
    'nilfs_cleanerd_create'

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-23 09:56:25 +09:00
Ryusuke Konishi
8129b6efd3 libnilfsfeature: fix kernel-doc comment for nilfs_edit_feature()
The kernel-doc comment for nilfs_edit_feature() incorrectly referred to
nilfs_string2feature() and described a simple conversion, likely due to
a copy-paste error.  This causes a warning in scripts/kernel-doc.

Fix the function name and update the short description to accurately
reflect that the function updates feature flags based on the input string.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-22 09:13:39 +09:00
Ryusuke Konishi
151af4c6a1 libnilfsgc: fix kernel-doc comment marker in gc.c
The kernel-doc comment for nilfs_vdesc_is_live() incorrectly started
with "/*" instead of "/**".

Fix the comment marker so it is correctly recognized as kernel-doc.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-22 09:01:41 +09:00
Ryusuke Konishi
91e91b0917 libsegment: add kernel-doc comments to segment.c
Add kernel-doc style comments to the functions in lib/segment.c.

This file provides iterators for parsing NILFS2 segment summaries
(partial segments, file information, and block information), but it
lacked proper documentation.  Add descriptions to facilitate
maintenance.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-22 08:50:15 +09:00
Ryusuke Konishi
dd2d0df4f4 man: update version and date for release 2.3
Update the version number to 2.3 and the date to Jan 2026 in the manual
pages for mkfs.nilfs2, mount.nilfs2, nilfs, nilfs_cleanerd,
nilfs_cleanerd.conf, nilfs-resize, nilfs-tune, and umount.nilfs2.

This synchronizes the version information across all manual pages in
preparation for the upcoming release.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 20:53:35 +09:00
Ryusuke Konishi
d7886f6583 man: update manual pages for device/node argument support
Update the synopsis and description sections of the manual pages for
chcp, dumpseg, lscp, lssu, mkcp, nilfs-clean, and rmcp.

This reflects the recent changes allowing these tools to accept a
filesystem node (file or directory) argument in place of a block device,
automatically resolving the backing device via the library.

Also update the version date and number to "Jan 2026" and "2.3"
respectively.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 20:53:35 +09:00
Ryusuke Konishi
ae0fc7c09b nilfs-clean: allow specifying filesystem node instead of device
Update nilfs-clean to accept a regular file or directory path on the
target filesystem in addition to a block device node.

This change is implemented within the private library libcleaner.
The functions nilfs_cleaner_launch() and nilfs_cleaner_open() in
lib/cleaner_ctl.c are modified to automatically resolve the backing
block device using the internal helper nilfs_lookup_device() if a
filesystem node is passed.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 20:53:35 +09:00
Ryusuke Konishi
ea6b9b84fd bin: allow specifying filesystem node instead of device
Update chcp, dumpseg, lscp, lssu, mkcp, and rmcp to use the new
NILFS_OPEN_SRCHDEV open flag.

This enables these tools to accept a regular file or directory path on
the target filesystem in addition to a block device node.  When a
filesystem node is specified, the library automatically resolves the
underlying block device.

The usage messages for these commands are updated to reflect that a
"node" can be specified.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 20:53:35 +09:00
Ryusuke Konishi
fec73a61ce libnilfs: allow opening nilfs by resolving backing device
Introduce a new open flag NILFS_OPEN_SRCHDEV.

If this flag is set and the 'dev' argument is a file or directory on a
NILFS filesystem, nilfs_open() automatically locates the backing block
device.

The logic calls the internal helper function nilfs_lookup_device() to
retrieve the device ID from the given path and resolve the canonical
device path (e.g. "/dev/sda1") via sysfs.

To support this, the source file "lookup_device.c" is added to the build
list in lib/Makefile.am.

This feature eliminates the need for users or tools to explicitly specify
the block device path when operating on a mounted NILFS filesystem.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 20:53:35 +09:00
Ryusuke Konishi
fb146a5345 lib: add helper files to resolve device name from sysfs
Add a new helper function, nilfs_lookup_device(), to resolve the kernel
device name (e.g. "sda1") associated with a filesystem node (file or
directory).

This function internally uses a static helper,
nilfs_get_devname_by_devid(), which reads the symlink at
/sys/dev/block/<major>:<minor> to identify the canonical device name
from a device ID.

These helpers are separated into a standalone module to allow sharing
the logic between the nilfs library and other utilities (e.g.
nilfs-clean) without exposing internal symbols in the public API.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 20:53:35 +09:00
Ryusuke Konishi
27bfa50c44 chcp: fix inverted logic in argument parsing
Since commit 7aae659498b8 ("chcp: fix segfault"), the logic to
distinguish between the optional device argument and the checkpoint
number list has been inverted.

The code intended to check if the current argument is *not* a valid
checkpoint number (indicating it is a device string).  However, due to
a logic error in that commit, if the argument is not a number (e.g.
"/dev/sda1"), it sets the device to NULL (implying no device argument).
Conversely, if it is a number, it incorrectly consumes it as a device
name.

This causes chcp to fail with "invalid checkpoint number" when a device
is explicitly specified, because the parser fails to advance past the
device string, subsequently attempting to parse the device name as a
checkpoint number in the main loop.

Fix this regression by correcting the if-else branch assignments.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Fixes: 7aae659498b8 ("chcp: fix segfault")
2026-01-21 15:22:59 +09:00
Ryusuke Konishi
0738712818 man: update examples in nilfs.8
Update the usage examples in the nilfs(8) manual page to reflect current
behavior.

The previous examples were outdated, showing timestamps from 2014 and
mount command output that differs from modern kernel behavior
(specifically regarding the "gcpid" and "relatime" mount options).

This change aligns the examples with the "What is NILFS?" section of the
official website.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 14:05:36 +09:00
Ryusuke Konishi
e1b7417293 man: fix typos, grammatical errors and style
Fix the following typos, grammatical errors, and stylistic issues in
manual pages:

- mount.nilfs2.8, umount.nilfs2.8, nilfs.8, nilfs-clean.8,
  nilfs_cleanerd.8: Correct usage of "shutdown" (noun) vs "shut down"
  (verb).
- nilfs-clean.8: Fix past participle "overrode" to "overwritten".
- nilfs-resize.8: Fix subject-verb agreement ("Resizing ... is").
- nilfs-tune.8: Add missing "if" and "by".
- nilfs_cleanerd.conf.5: Fix "is support" to "is supported".
- nilfs.8: Fix grammar ("with keeping" -> "while keeping", add missing
  "the").

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-21 14:05:36 +09:00
Ryusuke Konishi
6a823f9b40 treewide: output help message to stdout
Currently, most NILFS2 utilities print the usage message to stderr,
even when the user explicitly requests help using the -h or --help
options.

Update the utilities to print the usage message to stdout and exit
with status 0 when help is requested.  For invalid options or missing
arguments, continue to print the usage message to stderr and exit with
status 1.

This aligns the behavior with standard command-line conventions.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-20 17:54:15 +09:00
Ryusuke Konishi
8914cafdcd nilfs-tune: exit with status 1 if device is not specified
Currently, nilfs-tune exits with success (0) even if no device
argument is provided.

Fix this to return failure (1) when mandatory arguments are missing,
aligning the behavior with standard command-line conventions.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-20 17:41:17 +09:00
Ryusuke Konishi
490bff630d mkfs.nilfs2: remove stray debug print
Remove a debug printf() call that prints optind and argc when no
device argument is specified.

This is a leftover from development and pollutes the output when the
usage message is displayed due to missing arguments.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-20 16:33:26 +09:00
Ryusuke Konishi
6ff320f456 treewide: use getprogname()
Replace manual parsing of 'argv[0]' and global/local 'progname'
variables with the newly introduced getprogname() macro.

This simplifies main functions across utilities and ensures consistent
program name retrieval.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-20 00:24:11 +09:00
Ryusuke Konishi
67c58a898d build: add portable getprogname() support
Add a compatibility layer for getprogname() to allow utilities to
retrieve the short program name uniformly, removing the need for
manual argv[0] parsing.

The logic prioritizes the GNU extension variable
'program_invocation_short_name', falling back to getprogname.

If neither is available, the build fails with an #error.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-19 23:04:37 +09:00
Ryusuke Konishi
a421d4f6e7 nilfs-clean: switch to err.h functions
Replace the custom myprintf() function and ad-hoc exit logic with
standard <err.h> functions (warn, warnx, err, errx).

This modernizes the error handling, simplifies the code, and ensures
consistent output formatting.  The error messages now automatically
include the program name prefix, aligning with standard utility
conventions.

In addition, switch the version output from stderr to stdout to comply
with GNU coding standards.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-19 19:48:38 +09:00
Ryusuke Konishi
ac44e1f963 libparser: reject negative values in nilfs_parse_protection_period()
strtoull() converts negative strings to large unsigned integers, causing
inputs like "-1" to result in confusing "value too large" errors (ERANGE).

Fix this by explicitly checking for a minus sign and setting errno to
EINVAL, ensuring negative inputs are treated as invalid format errors.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-19 19:48:32 +09:00
Ryusuke Konishi
783fe0a7ea {mount,umount}.nilfs2: use vwarnx() in logging callbacks
Simplify the logging callback functions nilfs_mount_logger() and
nilfs_umount_logger() by using vwarnx().

This replaces the manual fprintf() sequence with the standard <err.h>
function, ensuring consistent message formatting (including the program
name prefix) across the utilities.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-19 15:57:24 +09:00
Ryusuke Konishi
1a54af4e7d {mount,umount}.nilfs2: decouple libmount-based helpers from sundries
Replace the legacy error() and die() functions derived from 'sundries.c'
with the standard <err.h> functions warnx() and errx() in the
libmount-based mount and umount helpers.

This change removes the dependency on 'sundries.h' and 'xmalloc.h',
completing the decoupling from the legacy implementation. Consequently,
'mount_quiet' and explicit program name handling in error messages are
removed, as err.h functions handle the program name automatically.

Accordingly, update 'Makefile.am' to exclude 'sundries.c' and
'xmalloc.c' from the common source list, moving them to legacy sources.

In addition, explicitly include <limits.h> in 'mount_attrs.c' and
'mount_libmount.c' to define ULONG_MAX, which was previously indirectly
included via 'sundries.h'.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-19 14:59:51 +09:00
Ryusuke Konishi
e371c65c5d mount: replace EX_* macros with MNT_EX_*
Replace the EX_* exit code macros with their MNT_EX_* equivalents in
mount_libmount.c and umount_libmount.c.

This aligns the code with libmount conventions and serves as a
preparatory step to remove the dependency on sundries.h.

A new header libmount_compat.h is added as a transitional measure to
define these macros, because they are missing in libmount.h on some
older distributions.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-19 13:32:44 +09:00
Ryusuke Konishi
0ad2cc77af {mount,umount}.nilfs2: remove unnecessary inclusion of sundries.h
The header file "mount.nilfs2.h" includes "sundries.h", but it only
defines a few constants and does not require any symbols from
"sundries.h".

This dependency is unnecessary and hinders the separation of the new
libmount-based implementation from the legacy support code in
"sundries.c".

Removing this include is safe because all source files that rely on
"sundries.h", including both the legacy programs and the libmount-based
helpers, already include it directly.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-17 14:01:49 +09:00
Ryusuke Konishi
d540681af2 umount.nilfs2: fix broken empty string check
The check for empty arguments 'if (!*argv)' was incorrect as it
checked for a NULL pointer, which never occurs within the argument
loop.  Consequently, passing an empty string "" resulted in a
confusing error message "umount.nilfs2: : not found" generated by
complain() function, instead of the intended error message.

Fix this by correctly checking for the null terminator '\0'.

In addition, replace the fatal die() call with error() (an internal
function derived from sundries.c) and a 'continue' statement.  This
ensures that an empty argument counts as a failure but allows the
command to proceed with unmounting other valid targets, consistent
with the tool's multiple-target behavior.

Refactor the loop structure to support this logic.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-17 00:18:27 +09:00
Ryusuke Konishi
170a000903 umount.nilfs2: fix exit code accumulation and reorganize status codes
Currently, umount.nilfs2 aggregates exit codes using addition.  If
multiple targets fail, the exit code EX_FAIL accumulates, resulting in
unintended values (e.g., 64 for two failures, which creates ambiguity
with EX_SOMEOK).

Fix this by refactoring the logic to use flags for tracking success
and failure states.  This eliminates the theoretical possibility of
integer overflow potentially flagged by static analysis tools, and
reorganizes the status codes to clearly distinguish between total
failure (EX_FAIL) and partial success (EX_SOMEOK).

Accordingly, stop forcing the return value to EX_FAIL in
nilfs_umount_one() to delegate the exit code decision to the main
function.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-16 22:33:12 +09:00
Ryusuke Konishi
7f0b7cbd02 umount.nilfs2: fix assertion failure when unmounting multiple targets
When running umount.nilfs2 with multiple mount points (e.g., "umount
dir1 dir2"), the command crashes with a libmount assertion failure:

  mnt_context_do_umount: Assertion `cxt->syscall_status == 1' failed.

This happens because the libmount context 'cxt' is reused in the loop
without resetting its internal status.  mnt_context_do_umount()
expects a clean status (syscall_status == 1) for each call.

Fix this by calling mnt_context_reset_status() before processing each
target in the loop.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-14 03:31:20 +09:00
Ryusuke Konishi
d189cfcf5c mount.nilfs2: fix ignored error on remount target mismatch
In nilfs_prepare_mount(), when a rw->rw remount is attempted on a
different mount point, an error message is printed, but the function
fails to abort the process.

This occurs because the return variable 'res' remains 0 (success) when
jumping to the failure label.

While a regular mount would eventually fail in the system call, a fake
mount (-f) skips the system call and would incorrectly succeed with exit
code 0 despite the error.

Fix this by setting 'res' to -EINVAL.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-14 03:31:20 +09:00
Ryusuke Konishi
53a23b7069 mount.nilfs2: fix broken overlapping rw-mount protection
The check for overlapping rw-mounts in nilfs_prepare_mount() detects
the condition and prints an error message, but fails to stop the mount
process.

This occurs because the return variable 'res' remains 0 (success) when
jumping to the failure label.

Consequently, the mount succeeds illegally, leading to a state where
umount fails with -EBUSY (due to unhandled garbage collector shutdown),
forcing manual process termination.

Fix this by setting 'res' to -EBUSY.  While any negative value would
abort the mount, -EBUSY is chosen to accurately reflect the cause and
align with libmount's error reporting granularity.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-14 03:31:20 +09:00
Ryusuke Konishi
d0e8cc2caf mount.nilfs2: check return value of mnt_fs_set_root()
In nilfs_mnt_context_complete_root(), the return value of
mnt_fs_set_root() is ignored.

Since mnt_fs_set_root() involves memory allocation, it can fail and
return a negative error code (e.g., -ENOMEM).

Fix this by checking the return value and reporting an error if it fails.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-14 03:31:20 +09:00
Ryusuke Konishi
eba2555a37 {mount,umount}.nilfs2: check return values of mnt_context_set_*()
The calls to mnt_context_set_source(), mnt_context_set_target(), and
mnt_context_set_fstype() in the main routines ignore the return
values.

Although -EINVAL is not expected here since the context is verified to
be valid, these functions can still return -ENOMEM upon memory
allocation failure.

Fix this by checking the return values and exiting with an error if
they fail.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-14 03:31:14 +09:00
Ryusuke Konishi
e2ffb4f0db mount.nilfs2: fix error return in nilfs_mount_attrs_parse() and its caller
In nilfs_prepare_mount(), the return value of nilfs_mount_attrs_parse()
is checked but not stored in 'res'.  When it fails, error() prints
strerror(-res) using a stale value (= 0), resulting in an incorrect
message like "Success".

Additionally, nilfs_mount_attrs_parse() returns -1 for memory
allocation failures or invalid options.  When negated and passed to
strerror(), this translates to "Operation not permitted" (EPERM),
which is confusing.

Fix this by returning specific error codes (-ENOMEM, -EINVAL) in
nilfs_mount_attrs_parse() and properly assigning the return value in
nilfs_prepare_mount().

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-13 17:23:38 +09:00
Ryusuke Konishi
adf84611ed mount.nilfs2: fix error code handling in nilfs_do_mount_one()
nilfs_do_mount_one() relies on the global variable 'errno' when
mnt_context_do_mount() fails.

However, mnt_context_do_mount() returns a positive errno for syscall
errors and a negative error code for library errors.  In the latter
case, 'errno' is not guaranteed to be set correctly, potentially
leading to incorrect error messages.

Fix this by using the return value of mnt_context_do_mount() instead
of 'errno'.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-13 17:17:31 +09:00
Ryusuke Konishi
7fd3a405ae umount.nilfs2: fix incorrect error code handling in libmount-based umount
nilfs_umount_one() passes the return value 'res' directly to complain().
However, mnt_context_do_umount() returns positive errno for syscall
errors and negative codes for library errors.

Since complain() expects a positive errno, passing a negative 'res' leads
to incorrect error messages or switch case mismatches.

Fix this by converting 'res' to its absolute value before passing it to
complain().

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-13 17:17:29 +09:00
Ryusuke Konishi
d619b89d52 nilfs-resize: unify device size type to uint64_t
In the nilfs-resize command, "uint64_t" and "unsigned long long" are
mixed in the type definition of variables that handle the byte size of
the device, so unify them to "uint64_t".

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 22:48:05 +09:00
Ryusuke Konishi
5c20d4b068 Use format specifier PRIu32, PRIu64, and dedicated definition PRIcno
Use PRIu32, PRIu64, and PRIcno, which corresponds to the defined type
nilfs_cno_t, for format strings in printf(), etc, and remove type cast
for corresponding arguments if possible.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 22:48:05 +09:00
Ryusuke Konishi
e95dfbdbd1 nilfs.h: add format string definitions of nilfs_cno_t type
Add {PRI,SCN}cno macros to give format strings for nilfs_cno_t type
variables.  Also include "inttypes.h" header file instead of
"stdint.h" to make format strings available.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 22:48:05 +09:00
Ryusuke Konishi
b156e93bb5 {mount,umount}.nilfs2: move global variable declarations to mount_opts.h
The global variables 'verbose', 'mount_quiet', 'readonly', 'readwrite',
and 'progname' are defined in mount.nilfs2.c (and umount.nilfs2.c) but
are accessed by mount_opts.c via ad-hoc extern declarations.

This structure causes Sparse to warn that the symbols in the defining
files should be static because they lack visible declarations in any
header file.

Move the extern declarations into the shared header "mount_opts.h" and
remove the local declarations from mount_opts.c.  Since the variables
are defined unconditionally in the main programs, the header
declarations are also made unconditional to ensure consistency.

This resolves the following Sparse warnings:

mount.nilfs2.c:96:5: warning: symbol 'verbose' was not declared. Should
 it be static?
mount.nilfs2.c:98:5: warning: symbol 'readonly' was not declared. Should
 it be static?
mount.nilfs2.c:99:5: warning: symbol 'readwrite' was not declared. Should
 it be static?
mount.nilfs2.c:106:6: warning: symbol 'progname' was not declared. Should
 it be static?
umount.nilfs2.c:98:5: warning: symbol 'verbose' was not declared. Should
 it be static?
umount.nilfs2.c💯5: warning: symbol 'readonly' was not declared. Should
 it be static?
umount.nilfs2.c:101:5: warning: symbol 'readwrite' was not declared. Should
 it be static?
umount.nilfs2.c:105:6: warning: symbol 'progname' was not declared. Should
 it be static?

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 13:50:11 +09:00
Ryusuke Konishi
4e2011b0a4 {mount,umount}.nilfs2: make fstype and options variables static
The 'fstype' and 'options' variables in mount.nilfs2.c and
umount.nilfs2.c are defined globally but are not declared in any
header and are not used outside their respective compilation units.

Mark them as static to limit their scope to the file level.

This resolves the following Sparse warnings:

mount.nilfs2.c:105:12: warning: symbol 'fstype' was not declared. Should
 it be static?
mount.nilfs2.c:123:22: warning: symbol 'options' was not declared. Should
 it be static?
umount.nilfs2.c:104:12: warning: symbol 'fstype' was not declared. Should
 it be static?
umount.nilfs2.c:122:23: warning: symbol 'options' was not declared. Should
 it be static?

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 13:50:11 +09:00
Ryusuke Konishi
cad3e0c938 {mount,umount}.nilfs2: make option format strings static
In the legacy mount/umount implementations (mount.nilfs2.c and
umount.nilfs2.c), the format string constants for garbage collector
options are defined globally but are not declared in any header and
are only used locally.

Mark them as static to limit their scope to the compilation unit.

This resolves the following Sparse warnings:

mount.nilfs2.c:108:12: warning: symbol 'gcpid_opt_fmt' was not declared.
 Should it be static?
mount.nilfs2.c:111:12: warning: symbol 'pp_opt_fmt' was not declared.
 Should it be static?
mount.nilfs2.c:114:12: warning: symbol 'nogc_opt_fmt' was not declared.
 Should it be static?
umount.nilfs2.c:107:12: warning: symbol 'gcpid_opt_fmt' was not declared.
 Should it be static?
umount.nilfs2.c:110:12: warning: symbol 'pp_opt_fmt' was not declared.
 Should it be static?

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 13:50:11 +09:00
Ryusuke Konishi
e26738984f {mount,umount}.nilfs2: make mounttable and fstab static
The variables 'mounttable' and 'fstab' in fstab.c are defined with
global scope but are not declared in any header file and are only
accessed within the local compilation unit.

Mark them as static to restrict their scope to the file level.

This resolves the following Sparse warnings:

fstab.c:110:18: warning: symbol 'mounttable' was not declared. Should it
 be static?
fstab.c:110:30: warning: symbol 'fstab' was not declared. Should it be
 static?

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 13:50:11 +09:00
Ryusuke Konishi
3d0577e9ba umount.nilfs2: initialize loopdev variable with NULL instead of 0
Replace the default value (undiscovered) of the loopdev variable used
in loop device discovery in the legacy umount program's umount_one()
function with the pointer type NULL instead of 0.

This resolves the following warning reported by Sparse:

umount.nilfs2.c:435:19: warning: Using plain integer as NULL pointer

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
2026-01-11 13:50:11 +09:00