From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH 7/9] include: Document safe file operations
Date: Thu, 10 Sep 2026 10:33:47 +0200 [thread overview]
Message-ID: <20260910-fix_documentation-v1-7-44313069bbe8@suse.com> (raw)
In-Reply-To: <20260910-fix_documentation-v1-0-44313069bbe8@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Add kernel-doc comments for safe file scanning, formatted writing,
file copying, touching, and overlayfs mounting in
include/tst_safe_file_ops.h.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_safe_file_ops.h | 63 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/include/tst_safe_file_ops.h b/include/tst_safe_file_ops.h
index 73ebd2ab8..31d11b3d8 100644
--- a/include/tst_safe_file_ops.h
+++ b/include/tst_safe_file_ops.h
@@ -10,6 +10,17 @@
#define FILE_SCANF(path, fmt, ...) \
file_scanf(__FILE__, __LINE__, (path), (fmt), ## __VA_ARGS__)
+/**
+ * SAFE_FILE_SCANF() - Reads formatted data from a file.
+ *
+ * @path: Path to the file to read.
+ * @fmt: scanf format string.
+ * @...: Pointers to variables to store parsed values into.
+ *
+ * Scans formatted data from path. If opening the file fails or the number of
+ * conversions does not match the format string, exits with
+ * :c:enum:`TBROK <tst_res_flags>`.
+ */
#define SAFE_FILE_SCANF(path, fmt, ...) \
safe_file_scanf(__FILE__, __LINE__, NULL, \
(path), (fmt), ## __VA_ARGS__)
@@ -39,6 +50,17 @@ void safe_file_read_str(const char *file, const int lineno,
file_lines_scanf(__FILE__, __LINE__, NULL, 0,\
(path), (fmt), ## __VA_ARGS__)
+/**
+ * SAFE_FILE_LINES_SCANF() - Searches lines of a file for formatted data.
+ *
+ * @path: Path to the file to read.
+ * @fmt: scanf format string to match against each line.
+ * @...: Pointers to variables to store parsed values into.
+ *
+ * Reads lines from path one by one until a line matches all format
+ * conversions in fmt. If the file cannot be opened or no line matches,
+ * exits with :c:enum:`TBROK <tst_res_flags>`.
+ */
#define SAFE_FILE_LINES_SCANF(path, fmt, ...) \
file_lines_scanf(__FILE__, __LINE__, NULL, 1,\
(path), (fmt), ## __VA_ARGS__)
@@ -61,18 +83,52 @@ void safe_file_read_str(const char *file, const int lineno,
file_printf(__FILE__, __LINE__, \
(path), (fmt), ## __VA_ARGS__)
+/**
+ * SAFE_FILE_PRINTF() - Writes formatted data to a file.
+ *
+ * @path: Path to the file to write.
+ * @fmt: printf format string.
+ * @...: Arguments for the format string.
+ *
+ * Writes formatted output to path. Exits with :c:enum:`TBROK <tst_res_flags>`
+ * if the file cannot be opened or written.
+ */
#define SAFE_FILE_PRINTF(path, fmt, ...) \
safe_file_printf(__FILE__, __LINE__, NULL, \
(path), (fmt), ## __VA_ARGS__)
+#define SAFE_FILE_VPRINTF(path, fmt, va) \
+ safe_file_vprintf(__FILE__, __LINE__, NULL, \
+ (path), (fmt), (va))
+
/* Same as SAFE_FILE_PRINTF() but returns quietly if the path doesn't exist */
#define SAFE_TRY_FILE_PRINTF(path, fmt, ...) \
safe_try_file_printf(__FILE__, __LINE__, NULL, \
(path), (fmt), ## __VA_ARGS__)
+/**
+ * SAFE_CP() - Copies a file from source to destination.
+ *
+ * @src: Source file path.
+ * @dst: Destination file path.
+ *
+ * Copies the file from src to dst. Exits with :c:enum:`TBROK <tst_res_flags>`
+ * on failure.
+ */
#define SAFE_CP(src, dst) \
safe_cp(__FILE__, __LINE__, NULL, (src), (dst))
+/**
+ * SAFE_TOUCH() - Creates or updates timestamp on a file.
+ *
+ * @pathname: Path to the file.
+ * @mode: File permissions mode (0 to use default 0666 & ~umask).
+ * @times: Array of two struct timespec for atime and mtime (NULL for current time).
+ *
+ * Creates the file if it does not exist with the specified mode, or updates
+ * its access and modification times. Exits with :c:enum:`TBROK <tst_res_flags>`
+ * on failure.
+ */
#define SAFE_TOUCH(pathname, mode, times) \
safe_touch(__FILE__, __LINE__, NULL, \
(pathname), (mode), (times))
@@ -83,6 +139,13 @@ void safe_file_read_str(const char *file, const int lineno,
void tst_create_overlay_dirs(void);
int tst_mount_overlay(const char *file, const int lineno, int strict);
+/**
+ * SAFE_MOUNT_OVERLAY() - Mounts overlayfs at OVL_MNT mount point.
+ *
+ * Creates lower, upper, work, and mnt directories, then mounts overlayfs
+ * at OVL_MNT. Exits with :c:enum:`TCONF <tst_res_flags>` if overlayfs is not
+ * supported by kernel, or :c:enum:`TBROK <tst_res_flags>` on mount failure.
+ */
#define SAFE_MOUNT_OVERLAY() \
((void) tst_mount_overlay(__FILE__, __LINE__, 1))
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-10 8:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 8:33 [LTP] [PATCH 0/9] doc: Improve and fix documentation and API comments Andrea Cervesato
2026-09-10 8:33 ` [LTP] [PATCH 1/9] doc: Fix examples and generated links Andrea Cervesato
2026-09-10 10:47 ` [LTP] " linuxtestproject.agent
2026-09-10 19:07 ` [LTP] [PATCH 1/9] " Petr Vorel
2026-09-10 8:33 ` [LTP] [PATCH 2/9] doc: Correct guide and API descriptions Andrea Cervesato
2026-09-10 19:32 ` Petr Vorel
2026-09-10 8:33 ` [LTP] [PATCH 3/9] doc: Clarify API coverage and navigation Andrea Cervesato
2026-09-10 19:52 ` Petr Vorel
2026-09-11 6:57 ` Andrea Cervesato via ltp
2026-09-10 8:33 ` [LTP] [PATCH 4/9] include: Document assertion API macros Andrea Cervesato
2026-09-10 8:33 ` [LTP] [PATCH 5/9] include: Document filesystem test utilities Andrea Cervesato
2026-09-10 8:33 ` [LTP] [PATCH 6/9] include: Document memory " Andrea Cervesato
2026-09-10 8:33 ` Andrea Cervesato [this message]
2026-09-10 8:33 ` [LTP] [PATCH 8/9] doc: Document CPU and common test helpers Andrea Cervesato
2026-09-10 8:33 ` [LTP] [PATCH 9/9] include: Fix API comment spelling and style Andrea Cervesato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260910-fix_documentation-v1-7-44313069bbe8@suse.com \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.