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>
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>
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>
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>
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>
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>
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>
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>
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")
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Remove the unused code block guarded by #if 0.
This block contains legacy definitions (referencing "util-linux") that
appear to be remnants from the original code import and are not used.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
To clarify the correspondence with the header file "check_mount.h",
which corresponds to the main function check_mount(), rename the
implementation file "ismounted.c" to "check_mount.c".
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The function 'check_mount' is shared among several utilities but lacks a
proper header declaration, relying instead on ad-hoc 'extern' declarations
in each source file. This triggers a Sparse warning suggesting the symbol
should be static.
Introduce a new header file "check_mount.h" to centralize the prototype
declaration. Include this header in the defining file and all users,
removing the redundant manual declarations.
This resolves the following Sparse warning:
ismounted.c:119:5: warning: symbol 'check_mount' was not declared. Should
it be static?
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The functions 'ext2fs_set_bit', 'ext2fs_clear_bit', and 'ext2fs_test_bit'
are defined in bitops.c but were previously declared locally in mkfs.h.
This prevented bitops.c from seeing its own prototypes, triggering
Sparse warnings about undeclared symbols.
Extract these declarations into a new header file "bitops.h" and include
it in both bitops.c and mkfs.h. This ensures that the definitions match
the declarations and resolves the scope issues.
This resolves the following Sparse warnings:
bitops.c:19:5: warning: symbol 'ext2fs_set_bit' was not declared. Should
it be static?
bitops.c:31:5: warning: symbol 'ext2fs_clear_bit' was not declared. Should
it be static?
bitops.c:43:5: warning: symbol 'ext2fs_test_bit' was not declared. Should
it be static?
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The one-bit bitfields in 'struct nilfs_cnormap' are currently defined
as 'int'. On two's complement systems, a one-bit signed integer can
only represent 0 and -1, which is not suitable for boolean flags
intended to hold 0 or 1.
Change them to 'unsigned int' to ensure they can represent 0 and 1
correctly.
While at it, clean up the comments for these members to improve
readability.
This resolves the following Sparse errors reported:
cnormap.c:64:35: error: dubious one-bit signed bitfield
cnormap.c:69:42: error: dubious one-bit signed bitfield
cnormap.c:70:43: error: dubious one-bit signed bitfield
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The global variable 'progname' in mkfs.c is not declared in any header
file and is not referenced outside the compilation unit.
Mark it as static to limit its scope to the file level, and fix the
following Sparse warning:
mkfs.c:90:6: warning: symbol 'progname' was not declared. Should it be
static?
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The global variable 'progname' in mount_libmount.c and umount_libmount.c
triggers Sparse warnings because it is not declared in any header file.
However, exporting such a generic name in a shared header is undesirable
due to potential namespace pollution.
To resolve this, make 'progname' static in the definition files to limit
its scope.
In mount_attrs.c, which previously required access to 'progname' for
error reporting, replace the custom error() function with the standard
warnx() function. This eliminates the need to reference the external
'progname' variable, allowing the extern declaration to be removed.
This resolves the following Sparse warnings:
mount_libmount.c:96:6: warning: symbol 'progname' was not declared. Should
it be static?
umount_libmount.c:88:6: warning: symbol 'progname' was not declared. Should
it be static?
Note:
Strictly speaking, replacing error() with warnx() removes the dependency
on the 'mount_quiet' global variable used for output suppression.
However, in the current libmount-based implementation, 'mount_quiet' is
never set and defaults to 0, rendering the legacy suppression logic
inactive. Therefore, this change does not alter the actual behavior.
Proper verbosity control using the libmount context is left as a future
improvement.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
The 'fstype' variables in mount_libmount.c and umount_libmount.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_libmount.c:95:12: warning: symbol 'fstype' was not declared. Should
it be static?
umount_libmount.c:87:12: warning: symbol 'fstype' was not declared. Should
it be static?
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Replace the comparison of the 'optarg' pointer against the plain
integer 0 with NULL to adhere to standard pointer usage.
This resolves the following warning reported by Sparse:
nilfs-clean.c:530:39: warning: Using plain integer as NULL pointer
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Fix the following Sparse warning reported in nilfs_get_segment():
nilfs.c:1032:29: warning: Using plain integer as NULL pointer
The first argument of mmap() expects a pointer, so use NULL instead of
the plain integer 0.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>