mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-25 18:40:19 -04:00
Normalize comment style
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
This commit is contained in:
parent
8fe9331f42
commit
a39fb132f8
29 changed files with 186 additions and 190 deletions
|
|
@ -105,7 +105,7 @@ SnapRAID is designed to recover from an interruption, including `SIGKILL`, at an
|
|||
- **Format**: Enforce via `uncrustify -c uncrustify.cfg --no-backup *.c *.h` (or `uncrustify -c linux.cfg --no-backup *.c *.h` for `raid/` directory and subdirectories)
|
||||
- **Naming**: Snake_case for functions, UPPER_CASE for macros/constants
|
||||
- **Indentation**: Tabs for indentation, no alignment (existing codebase style)
|
||||
- **Comments**: C-style `/** */` for multiline comments; C `/* first letter lowercase */` for single-line inline notes
|
||||
- **Comments**: Use `/** ... */` for multiline top comments preceding declarations and `/* ... */` for multiline comments within code. Use `/* first letter lowercase */` for single-line inline notes.
|
||||
- **Critical Comments**: Always add a comment at non-obvious critical points, especially around data-integrity invariants, crash recovery, fallback behavior, concurrency, and fatal versus best-effort error handling. Explain why the logic is required, not merely what the code does.
|
||||
- **Headers**: All `.h` files have include guards (`#ifndef __NAME_H`)
|
||||
- **Preferences**: Use 0 instead of NULL and '\0'
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ int fsinfo(const char* path, int* has_persistent_inode, int* has_syncronized_har
|
|||
#define SNAPSHOT_SCAN "scan"
|
||||
#define SNAPSHOT_RETIRING_SUFFIX ".retiring"
|
||||
|
||||
/*
|
||||
/**
|
||||
* Snapshots context
|
||||
*/
|
||||
struct fssnapshot_struct {
|
||||
|
|
@ -213,7 +213,7 @@ int fssnapshot_replace(struct fssnapshot_struct* fss, const char* old_name, cons
|
|||
*/
|
||||
int fssnapshot_path(const struct fssnapshot_struct* fss, const char* name, char* path, size_t path_size);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Log file.
|
||||
*
|
||||
* This stream if fully buffered.
|
||||
|
|
@ -257,7 +257,7 @@ extern int exit_degraded;
|
|||
*/
|
||||
#define SMART_FLAGS 256
|
||||
|
||||
/*
|
||||
/**
|
||||
* Counts command, transport, or controller-level errors reported by the device.
|
||||
* These reflect failed I/O operations not directly caused by media defects
|
||||
* (for example interface, firmware, or power-related errors).
|
||||
|
|
@ -266,7 +266,7 @@ extern int exit_degraded;
|
|||
*/
|
||||
#define SMART_ERROR_PROTOCOL 257
|
||||
|
||||
/*
|
||||
/**
|
||||
* Counts media-level errors where data could not be reliably read or written.
|
||||
* These indicate actual storage surface or flash failures and may imply data loss.
|
||||
* This counter is cumulative and never resets to zero, even if the underlying
|
||||
|
|
@ -387,7 +387,7 @@ struct devinfo_struct {
|
|||
char name[PATH_MAX]; /**< Name of the disk combined with the split index if any */
|
||||
char mount[PATH_MAX]; /**< Mount point or other contained directory. */
|
||||
char smartctl[SMARTCTL_MAX]; /**< Custom option for smartctl. Empty means auto. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /* Info options for smartctl. Empty means -a. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /**< Info options for smartctl. Empty means -a. */
|
||||
struct smartignore_struct smartignore[SMART_IGNORE_MAX]; /**< Attributes to ignore */
|
||||
char file[PATH_MAX]; /**< File device. */
|
||||
#ifdef _WIN32
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "raid/raid.h"
|
||||
#include "raid/combo.h"
|
||||
|
||||
/*
|
||||
/**
|
||||
* SnapRAID check/fix model
|
||||
*
|
||||
* Check verifies the data described by the content file against the files
|
||||
|
|
@ -841,11 +841,9 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns
|
|||
* distinction disappears.
|
||||
*/
|
||||
|
||||
/************************************************************************/
|
||||
/* First strategy: parity represents CURRENT data. */
|
||||
/************************************************************************/
|
||||
|
||||
/*
|
||||
* First strategy: parity represents CURRENT data.
|
||||
*
|
||||
* Under the CURRENT hypothesis:
|
||||
*
|
||||
* BLK hash CURRENT, parity normally synchronized
|
||||
|
|
@ -1129,11 +1127,9 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns
|
|||
else
|
||||
log_tag("recover_sync:%" PRIu64 ":%u: Failed with %d attempts\n", pos, n, ret);
|
||||
|
||||
/************************************************************************/
|
||||
/* Second strategy: parity still represents OLD data. */
|
||||
/************************************************************************/
|
||||
|
||||
/*
|
||||
* Second strategy: parity still represents OLD data.
|
||||
*
|
||||
* The CURRENT attempt failed, so retry under the opposite history
|
||||
* hypothesis: physical parity still represents the state before the
|
||||
* interrupted sync.
|
||||
|
|
@ -1964,7 +1960,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
|
|||
*/
|
||||
valid_parity = 1;
|
||||
|
||||
/* If the parity is used by at least one file */
|
||||
/* if the parity is used by at least one file */
|
||||
used_parity = 0;
|
||||
|
||||
/* keep track of the number of failed blocks */
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ void device_name_set(devinfo_t* dev, const char* name, int index)
|
|||
*/
|
||||
#define SMART_MEASURES 256
|
||||
|
||||
/*
|
||||
/**
|
||||
* Divider for SMART attribute 5
|
||||
*/
|
||||
static unsigned SMART_5_STEP = 1;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Failure rate for 30 days, for a disk
|
||||
* with SMART attribute 5 at a given value.
|
||||
*/
|
||||
|
|
@ -107,12 +107,12 @@ static double SMART_5_R[SMART_MEASURES] = {
|
|||
0.4249,
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Divider for SMART attribute 187
|
||||
*/
|
||||
static unsigned SMART_187_STEP = 1;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Failure rate for 30 days, for a disk
|
||||
* with SMART attribute 187 at a given value.
|
||||
*/
|
||||
|
|
@ -171,12 +171,12 @@ static double SMART_187_R[SMART_MEASURES] = {
|
|||
3.4520,
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Divider for SMART attribute 188
|
||||
*/
|
||||
static unsigned SMART_188_STEP = 1;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Failure rate for 30 days, for a disk
|
||||
* with SMART attribute 188 at a given value.
|
||||
*/
|
||||
|
|
@ -235,12 +235,12 @@ static double SMART_188_R[SMART_MEASURES] = {
|
|||
1.3731,
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Divider for SMART attribute 197
|
||||
*/
|
||||
static unsigned SMART_197_STEP = 1;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Failure rate for 30 days, for a disk
|
||||
* with SMART attribute 197 at a given value.
|
||||
*/
|
||||
|
|
@ -299,12 +299,12 @@ static double SMART_197_R[SMART_MEASURES] = {
|
|||
4.1131,
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Divider for SMART attribute 198
|
||||
*/
|
||||
static unsigned SMART_198_STEP = 1;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Failure rate for 30 days, for a disk
|
||||
* with SMART attribute 198 at a given value.
|
||||
*/
|
||||
|
|
@ -423,7 +423,7 @@ static double smart_afr(devinfo_t* devinfo)
|
|||
}
|
||||
|
||||
if (
|
||||
/**
|
||||
/*
|
||||
* Don't check Command_Timeout (188) for Seagate disks.
|
||||
*
|
||||
* It's reported by users that for Archive SMR (Shingled Magnetic Recording)
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ static int filter_element(tommy_list* filterlist, struct snapraid_filter** reaso
|
|||
{
|
||||
tommy_node* i;
|
||||
|
||||
/**
|
||||
/*
|
||||
* The rule is that the latest filter defines the behaviour of paths
|
||||
* that doesn't match any filter.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
/****************************************************************************/
|
||||
/* snapraid */
|
||||
|
||||
/*
|
||||
/**
|
||||
* Maximum number of block positions in a data/parity disk span.
|
||||
*
|
||||
* With the default 256 KiB block size, this limits the maximum supported
|
||||
|
|
@ -415,7 +415,7 @@ struct snapraid_extra {
|
|||
char name[PATH_MAX]; /**< Name of the disk. */
|
||||
char dir[PATH_MAX]; /**< Mount point of the disk. It always terminates with /. */
|
||||
char smartctl[SMARTCTL_MAX]; /**< Custom option for smartctl. Empty means auto. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /* Info options for smartctl. Empty means -a. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /**< Info options for smartctl. Empty means -a. */
|
||||
struct smartignore_struct smartignore[SMART_IGNORE_MAX]; /**< Smart attributes to ignore for this device. */
|
||||
char uuid[UUID_MAX]; /**< UUID of the disk. They are probed during the config reading. */
|
||||
char fstype[FSINFO_MAX]; /**< Filesystem type */
|
||||
|
|
@ -454,7 +454,7 @@ struct snapraid_disk {
|
|||
struct fssnapshot_struct fss;
|
||||
|
||||
char smartctl[SMARTCTL_MAX]; /**< Custom option for smartctl. Empty means auto. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /* Info options for smartctl. Empty means -a. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /**< Info options for smartctl. Empty means -a. */
|
||||
struct smartignore_struct smartignore[SMART_IGNORE_MAX]; /**< Smart attributes to ignore for this device. */
|
||||
char uuid[UUID_MAX]; /**< UUID of the disk. They are probed during the config reading. */
|
||||
char fstype[FSINFO_MAX]; /**< Filesystem type */
|
||||
|
|
@ -597,7 +597,7 @@ struct snapraid_parity {
|
|||
struct snapraid_split split_map[SPLIT_MAX]; /**< Parity splits. */
|
||||
unsigned split_mac; /**< Number of parity splits. */
|
||||
char smartctl[SMARTCTL_MAX]; /**< Custom option for smartctl. Empty means auto. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /* Info options for smartctl. Empty means -a. */
|
||||
char smartctl_info[SMARTCTL_MAX]; /**< Info options for smartctl. Empty means -a. */
|
||||
struct smartignore_struct smartignore[SMART_IGNORE_MAX]; /**< Smart attributes to ignore for this device. */
|
||||
block_off_t total_blocks; /**< Number of total blocks. */
|
||||
block_off_t free_blocks; /**< Number of free blocks at the last sync. */
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ static int needs_quote(const WCHAR* arg)
|
|||
cmd[pos++] = (c); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
/**
|
||||
* Append one argument using the Microsoft C runtime command-line
|
||||
* quoting rules. Use this when building a normal CreateProcessW()
|
||||
* command line that the target process will parse back into argv[].
|
||||
|
|
@ -146,10 +146,10 @@ static char* argutf8(const WCHAR* arg)
|
|||
return utf8_arg;
|
||||
}
|
||||
|
||||
/* Global variable to store child process handle */
|
||||
/* global variable to store child process handle */
|
||||
static void* volatile child_process = NULL;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Safe atomic access helpers for child_process.
|
||||
*
|
||||
* The console_handler runs concurrently on an OS-managed thread created by
|
||||
|
|
@ -169,7 +169,7 @@ static void child_process_write(HANDLE handle)
|
|||
InterlockedExchangePointer(&child_process, handle);
|
||||
}
|
||||
|
||||
/* Console control handler - forwards Ctrl+C, Ctrl+Break to child */
|
||||
/* console control handler - forwards Ctrl+C, Ctrl+Break to child */
|
||||
static BOOL WINAPI console_handler(DWORD ctrl_type)
|
||||
{
|
||||
/* if no child, default behavior */
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "os/portable.h"
|
||||
|
||||
#ifdef __MINGW32__ /* Only for MingW */
|
||||
#ifdef __MINGW32__ /* only for MingW */
|
||||
|
||||
#include "support.h"
|
||||
#include "raid/cpu.h"
|
||||
|
|
@ -82,7 +82,7 @@ int fsinfo(const char* path, int* has_persistent_inode, int* has_syncronized_har
|
|||
if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||
char* slash = strrchr(dir, '/');
|
||||
|
||||
/**
|
||||
/*
|
||||
* Cut the file name, but leave the last slash.
|
||||
*
|
||||
* This is done because a MSDN comment about using of UNC paths.
|
||||
|
|
@ -135,7 +135,7 @@ int fsinfo(const char* path, int* has_persistent_inode, int* has_syncronized_har
|
|||
if (has_persistent_inode) {
|
||||
*has_persistent_inode = 0;
|
||||
|
||||
/**
|
||||
/*
|
||||
* Reuse stored file IDs across scans only for filesystems known to
|
||||
* provide stable and unique IDs. An unknown or unavailable filesystem
|
||||
* must be treated as volatile: a false negative only loses inode-based
|
||||
|
|
@ -250,7 +250,7 @@ static int base64_encode(const unsigned char* in, size_t in_len, char* out, size
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* PowerShell helper
|
||||
*
|
||||
* Runs a PowerShell one-liner via os_spawn() and captures the first line
|
||||
|
|
@ -2411,7 +2411,7 @@ void machineinfo(struct machineinfo_struct* info)
|
|||
info->memory_page_size = si.dwPageSize;
|
||||
info->cpu_cores_logical = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||
|
||||
/* Query processor topology and cache hierarchy via GetLogicalProcessorInformationEx */
|
||||
/* query processor topology and cache hierarchy via GetLogicalProcessorInformationEx */
|
||||
DWORD len = 0;
|
||||
GetLogicalProcessorInformationEx(RelationAll, 0, &len);
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER && len > 0) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
// MurmurHash3 was written by Austin Appleby, and is placed in the public
|
||||
// domain. The author hereby disclaims copyright to this source code.
|
||||
|
||||
/* Finalization mix - force all bits of a hash block to avalanche */
|
||||
/* finalization mix - force all bits of a hash block to avalanche */
|
||||
static inline uint32_t fmix32(uint32_t h)
|
||||
{
|
||||
h ^= h >> 16;
|
||||
|
|
@ -25,7 +25,7 @@ static inline uint32_t fmix32(uint32_t h)
|
|||
return h;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Non-static variables are intentionally used instead of static const
|
||||
* because keeping these constants in CPU registers yields measurably
|
||||
* higher throughput than using 32-bit immediate constants in imul.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
* of this license, visit: https://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
/*
|
||||
/**
|
||||
* Analysis of the BFast variant and blinding multiplication
|
||||
*
|
||||
* Many fast non-cryptographic hashes (wyhash, rapidhash) use "folding
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* If the parity size is not yet set, set it now.
|
||||
* This happens when adding a new parity level or split that has
|
||||
* no persisted size yet.
|
||||
|
|
@ -884,7 +884,7 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* If the parity size is not yet set, set it now.
|
||||
* This happens when adding a new parity level or split that has
|
||||
* no persisted size yet.
|
||||
|
|
|
|||
|
|
@ -1153,7 +1153,7 @@ static void scan_file_discover(struct snapraid_scan* scan, const char* sub, stru
|
|||
|
||||
disc = discovery_alloc(sub, st);
|
||||
|
||||
/* Hardlink collision detection */
|
||||
/* hardlink collision detection */
|
||||
if (disc->inode != INODE_INVALID) {
|
||||
struct snapraid_discovery* rep = tommy_hashdyn_search(&scan->file_discovery_inodeset, discovery_inode_compare_to_arg, &disc->inode, file_inode_hash(disc->inode));
|
||||
if (!rep) {
|
||||
|
|
@ -1161,7 +1161,7 @@ static void scan_file_discover(struct snapraid_scan* scan, const char* sub, stru
|
|||
disc->flag |= DISCOVERY_IS_CANONICAL;
|
||||
tommy_hashdyn_insert(&scan->file_discovery_inodeset, &disc->nodeset, disc, file_inode_hash(disc->inode));
|
||||
} else {
|
||||
/* Inode collision detected! */
|
||||
/* inode collision detected! */
|
||||
#if HAVE_LSTAT_SYNC
|
||||
if (disk->has_volatile_hardlinks && !(rep->flag & DISCOVERY_IS_SCAN_SYNCED)) {
|
||||
char path_next[PATH_MAX];
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include "io.h"
|
||||
#include "raid/raid.h"
|
||||
|
||||
/*
|
||||
/**
|
||||
* SnapRAID scrub model
|
||||
*
|
||||
* Scrub periodically verifies data and parity without modifying either of
|
||||
|
|
|
|||
|
|
@ -1979,13 +1979,13 @@ static void test_smart_ignore(void)
|
|||
memset(&state, 0, sizeof(state));
|
||||
memset(&devinfo, 0, sizeof(devinfo));
|
||||
|
||||
/* Initialize devinfo attributes with mock data */
|
||||
/* initialize devinfo attributes with mock data */
|
||||
for (i = 0; i < SMART_COUNT; ++i) {
|
||||
devinfo.smart[i].raw = 100;
|
||||
devinfo.smart[i].norm = 100;
|
||||
snprintf(devinfo.smart[i].name, sizeof(devinfo.smart[i].name), "Attr_%d", i);
|
||||
}
|
||||
/* Special name for test */
|
||||
/* special name for test */
|
||||
pathcpy(devinfo.smart[5].name, sizeof(devinfo.smart[5].name), "Reallocated_Sector_Ct");
|
||||
pathcpy(devinfo.smart[197].name, sizeof(devinfo.smart[197].name), "Current_Pending_Sector");
|
||||
|
||||
|
|
@ -2007,7 +2007,7 @@ static void test_smart_ignore(void)
|
|||
|
||||
state_smart_ignore(&state, &devinfo);
|
||||
|
||||
/* Check that ignored attributes are set to SMART_UNASSIGNED */
|
||||
/* check that ignored attributes are set to SMART_UNASSIGNED */
|
||||
if (devinfo.smart[5].raw != SMART_UNASSIGNED || devinfo.smart[5].norm != SMART_UNASSIGNED) {
|
||||
log_fatal(EINTERNAL, "test_smart_ignore: numerical global ignore failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
@ -2025,7 +2025,7 @@ static void test_smart_ignore(void)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Check that non-ignored attributes are still present */
|
||||
/* check that non-ignored attributes are still present */
|
||||
if (devinfo.smart[6].raw != 100) {
|
||||
log_fatal(EINTERNAL, "test_smart_ignore: unmodified attribute was cleared\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
@ -2345,7 +2345,7 @@ static void test_unsynced_sweep(void)
|
|||
block_state_set(file_block(file4, 2), BLOCK_STATE_CHG);
|
||||
fs_allocate(disk1, 30, file4, 0, 4);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Positions 30..33 are all unsynced: REP, REP, CHG, REBUILD respectively.
|
||||
* At 32 and 33 the invalid block changes disks at the same event boundary;
|
||||
* count each position once using the refreshed flags from both disks.
|
||||
|
|
|
|||
|
|
@ -311,152 +311,152 @@ static struct option long_options[] = {
|
|||
{ "gui-threshold-removes", 1, 0, OPT_GUI_THRESHOLD_REMOVES }, /* undocumented GUI, abort sync if too many removed files */
|
||||
{ "gui-threshold-updates", 1, 0, OPT_GUI_THRESHOLD_UPDATES }, /* undocumented GUI, abort sync if too many updated files */
|
||||
|
||||
/* The following are test specific options, DO NOT USE! */
|
||||
/* the following are test specific options, DO NOT USE! */
|
||||
|
||||
/* After syncing, do not write the new content file */
|
||||
/* after syncing, do not write the new content file */
|
||||
{ "test-kill-after-sync", 0, 0, OPT_TEST_KILL_AFTER_SYNC },
|
||||
|
||||
/* Do not execute syncing after resizing parity files, before the normal post-resize content write */
|
||||
/* do not execute syncing after resizing parity files, before the normal post-resize content write */
|
||||
{ "test-kill-after-resize", 0, 0, OPT_TEST_KILL_AFTER_RESIZE },
|
||||
|
||||
/* Do not execute syncing after writing the new initial content file */
|
||||
/* do not execute syncing after writing the new initial content file */
|
||||
{ "test-kill-before-sync", 0, 0, OPT_TEST_KILL_BEFORE_SYNC },
|
||||
|
||||
/* Exit with failure if after check/fix there ARE NOT unrecoverable errors. */
|
||||
/* exit with failure if after check/fix there ARE NOT unrecoverable errors. */
|
||||
{ "test-expect-unrecoverable", 0, 0, OPT_TEST_EXPECT_UNRECOVERABLE },
|
||||
|
||||
/* Exit with failure if after check/fix there ARE NOT recoverable errors. */
|
||||
/* exit with failure if after check/fix there ARE NOT recoverable errors. */
|
||||
{ "test-expect-recoverable", 0, 0, OPT_TEST_EXPECT_RECOVERABLE },
|
||||
|
||||
/* Skip the initial self test */
|
||||
/* skip the initial self test */
|
||||
{ "test-skip-self", 0, 0, OPT_TEST_SKIP_SELF },
|
||||
|
||||
/* Skip the initial sign check when reading the content file */
|
||||
/* skip the initial sign check when reading the content file */
|
||||
{ "test-skip-sign", 0, 0, OPT_TEST_SKIP_SIGN },
|
||||
|
||||
/* Skip the fallocate() when growing the parity files */
|
||||
/* skip the fallocate() when growing the parity files */
|
||||
{ "test-skip-fallocate", 0, 0, OPT_TEST_SKIP_FALLOCATE },
|
||||
|
||||
/* Skip the device check */
|
||||
/* skip the device check */
|
||||
{ "test-skip-device", 0, 0, OPT_TEST_SKIP_DEVICE },
|
||||
|
||||
/* Force Murmur3 hash */
|
||||
/* force Murmur3 hash */
|
||||
{ "test-force-murmur3", 0, 0, OPT_TEST_FORCE_MURMUR3 },
|
||||
|
||||
/* Force Spooky2 hash */
|
||||
/* force Spooky2 hash */
|
||||
{ "test-force-spooky2", 0, 0, OPT_TEST_FORCE_SPOOKY2 },
|
||||
|
||||
/* Skip the use of lock file */
|
||||
/* skip the use of lock file */
|
||||
{ "test-skip-lock", 0, 0, OPT_TEST_SKIP_LOCK },
|
||||
|
||||
/* Force a sort order for files */
|
||||
/* force a sort order for files */
|
||||
{ "test-force-order-inode", 0, 0, OPT_TEST_FORCE_ORDER_INODE },
|
||||
{ "test-force-order-alpha", 0, 0, OPT_TEST_FORCE_ORDER_ALPHA },
|
||||
{ "test-force-order-dir", 0, 0, OPT_TEST_FORCE_ORDER_DIR },
|
||||
|
||||
/* Force scrub of the specified number of blocks */
|
||||
/* force scrub of the specified number of blocks */
|
||||
{ "test-force-scrub-at", 1, 0, OPT_TEST_FORCE_SCRUB_AT },
|
||||
|
||||
/* Force scrub of all the even blocks. This is really for testing, don't try it */
|
||||
/* force scrub of all the even blocks. This is really for testing, don't try it */
|
||||
{ "test-force-scrub-even", 0, 0, OPT_TEST_FORCE_SCRUB_EVEN },
|
||||
|
||||
/* Force write of the content file even if no modification is done */
|
||||
/* force write of the content file even if no modification is done */
|
||||
{ "test-force-content-write", 0, 0, OPT_TEST_FORCE_CONTENT_WRITE },
|
||||
|
||||
/* Relax the checks done at the content file */
|
||||
/* relax the checks done at the content file */
|
||||
{ "test-skip-content-check", 0, 0, OPT_TEST_SKIP_CONTENT_CHECK },
|
||||
|
||||
/* Skip the parity access */
|
||||
/* skip the parity access */
|
||||
{ "test-skip-parity-access", 0, 0, OPT_TEST_SKIP_PARITY_ACCESS },
|
||||
|
||||
/* Exit generic failure */
|
||||
/* exit generic failure */
|
||||
{ "test-expect-failure", 0, 0, OPT_TEST_EXPECT_FAILURE },
|
||||
|
||||
/* Exit generic need sync */
|
||||
/* exit generic need sync */
|
||||
{ "test-expect-need-sync", 0, 0, OPT_TEST_EXPECT_NEED_SYNC },
|
||||
|
||||
#if HAVE_CHECKER
|
||||
/* Run some command after loading the state and before the command */
|
||||
/* run some command after loading the state and before the command */
|
||||
{ "test-run", 1, 0, OPT_TEST_RUN },
|
||||
#endif
|
||||
|
||||
/* Use the FindFirst/Next approach in Windows to list files */
|
||||
/* use the FindFirst/Next approach in Windows to list files */
|
||||
{ "test-force-scan-winfind", 0, 0, OPT_TEST_FORCE_SCAN_WINFIND },
|
||||
|
||||
/* Alternative import working by data */
|
||||
/* alternative import working by data */
|
||||
{ "test-import-content", 1, 0, OPT_TEST_IMPORT_CONTENT },
|
||||
|
||||
/* Force immediate progress state update */
|
||||
/* force immediate progress state update */
|
||||
{ "test-force-progress", 0, 0, OPT_TEST_FORCE_PROGRESS },
|
||||
|
||||
/* Skip the disk access */
|
||||
/* skip the disk access */
|
||||
{ "test-skip-disk-access", 0, 0, OPT_TEST_SKIP_DISK_ACCESS },
|
||||
|
||||
/* Force autosave at the specified block */
|
||||
/* force autosave at the specified block */
|
||||
{ "test-force-autosave-at", 1, 0, OPT_TEST_FORCE_AUTOSAVE_AT },
|
||||
|
||||
/* Fake device data */
|
||||
/* fake device data */
|
||||
{ "test-fake-device", 0, 0, OPT_TEST_FAKE_DEVICE },
|
||||
|
||||
/* Fake UUID */
|
||||
/* fake UUID */
|
||||
{ "test-fake-uuid", 0, 0, OPT_TEST_FAKE_UUID },
|
||||
|
||||
/* Match first UUID */
|
||||
/* match first UUID */
|
||||
{ "test-match-first-uuid", 0, 0, OPT_TEST_MATCH_FIRST_UUID },
|
||||
|
||||
/* Force parity update even if all the data hash is already matching */
|
||||
/* force parity update even if all the data hash is already matching */
|
||||
{ "test-force-parity-update", 0, 0, OPT_TEST_FORCE_PARITY_UPDATE },
|
||||
|
||||
/* Number of IO buffers */
|
||||
/* number of IO buffers */
|
||||
{ "test-io-cache", 1, 0, OPT_TEST_IO_CACHE },
|
||||
|
||||
/* Print IO stats */
|
||||
/* print IO stats */
|
||||
{ "test-io-stats", 0, 0, OPT_TEST_IO_STATS }, /* now replaced by -A, --stats */
|
||||
|
||||
/* Signal condition variable outside the mutex */
|
||||
/* signal condition variable outside the mutex */
|
||||
{ "test-cond-signal-outside", 0, 0, OPT_TEST_COND_SIGNAL_OUTSIDE },
|
||||
|
||||
/* Set the io advise to none */
|
||||
/* set the io advise to none */
|
||||
{ "test-io-advise-none", 0, 0, OPT_TEST_IO_ADVISE_NONE },
|
||||
|
||||
/* Set the io advise to sequential */
|
||||
/* set the io advise to sequential */
|
||||
{ "test-io-advise-sequential", 0, 0, OPT_TEST_IO_ADVISE_SEQUENTIAL },
|
||||
|
||||
/* Set the io advise to flush */
|
||||
/* set the io advise to flush */
|
||||
{ "test-io-advise-flush", 0, 0, OPT_TEST_IO_ADVISE_FLUSH },
|
||||
|
||||
/* Set the io advise to flush window */
|
||||
/* set the io advise to flush window */
|
||||
{ "test-io-advise-flush-window", 0, 0, OPT_TEST_IO_ADVISE_FLUSH_WINDOW },
|
||||
|
||||
/* Set the io advise to discard */
|
||||
/* set the io advise to discard */
|
||||
{ "test-io-advise-discard", 0, 0, OPT_TEST_IO_ADVISE_DISCARD },
|
||||
|
||||
/* Set the io advise to discard window */
|
||||
/* set the io advise to discard window */
|
||||
{ "test-io-advise-discard-window", 0, 0, OPT_TEST_IO_ADVISE_DISCARD_WINDOW },
|
||||
|
||||
/* Set the io advise to direct */
|
||||
/* set the io advise to direct */
|
||||
{ "test-io-advise-direct", 0, 0, OPT_TEST_IO_ADVISE_DIRECT },
|
||||
|
||||
/* Set an artificial parity limit */
|
||||
/* set an artificial parity limit */
|
||||
{ "test-parity-limit", 1, 0, OPT_TEST_PARITY_LIMIT },
|
||||
|
||||
/* Skip content write */
|
||||
/* skip content write */
|
||||
{ "test-skip-content-write", 0, 0, OPT_TEST_SKIP_CONTENT_WRITE },
|
||||
|
||||
/* Skip space holder file in parity disks */
|
||||
/* skip space holder file in parity disks */
|
||||
{ "test-skip-space-holder", 0, 0, OPT_TEST_SKIP_SPACE_HOLDER },
|
||||
|
||||
/* Set the output format */
|
||||
/* set the output format */
|
||||
{ "test-fmt", 1, 0, OPT_TEST_FORMAT },
|
||||
|
||||
/* Skip thread in disk scan */
|
||||
/* skip thread in disk scan */
|
||||
{ "test-skip-multi-scan", 0, 0, OPT_TEST_SKIP_MULTI_SCAN },
|
||||
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
/**
|
||||
* Free letters: gIjJkKMnPQruxXz
|
||||
*
|
||||
* The 's' letter is used in main.c
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#define HAVE_MT_VERIFY 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
/**
|
||||
* Start content-file writeback in bounded windows to avoid dirty-page
|
||||
* throttling; the subsequent fsync() remains responsible for durability.
|
||||
*
|
||||
|
|
@ -4397,7 +4397,7 @@ static void* state_write_thread(void* arg)
|
|||
if (v_state != block_state_get(block))
|
||||
break;
|
||||
|
||||
/* Resolve the mapping only when crossing an extent boundary. */
|
||||
/* resolve the mapping only when crossing an extent boundary. */
|
||||
if (end == extent_end) {
|
||||
block_off_t next_count;
|
||||
block_off_t next_pos = fs_file2par_get_run(disk, file, end, &next_count);
|
||||
|
|
@ -5702,7 +5702,7 @@ static void state_rename_content(struct snapraid_state* state)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Check if a modification time nanosecond value can be represented in the
|
||||
* content format.
|
||||
*
|
||||
|
|
@ -5714,7 +5714,7 @@ static int state_write_mtime_nsec_valid(int mtime_nsec)
|
|||
return mtime_nsec == STAT_NSEC_INVALID || (mtime_nsec >= 0 && mtime_nsec < 1000000000);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Validate invariants required by the persistent content format.
|
||||
*
|
||||
* state_write() must never serialize a state that state_read() would reject.
|
||||
|
|
@ -5807,7 +5807,7 @@ static void state_write_check(struct snapraid_state* state)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Emit structured mapping tags for data disks and parity splits after
|
||||
* content files have been durably published.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ struct snapraid_state {
|
|||
tommy_list bucketlist; /**< Sorted list of info bucket. Derived from infoarr, but updated only state_read()/state_write() */
|
||||
block_off_t bucketcount; /**< Sum of all the counts of the list */
|
||||
|
||||
/* Thermal */
|
||||
/* thermal */
|
||||
tommy_list thermallist; /**< List of all thermal state */
|
||||
int thermal_stop_gathering; /**< If thermal data gathering is stopped */
|
||||
int thermal_system_temperature; /**< System temperature. 0 if not available */
|
||||
|
|
|
|||
|
|
@ -493,7 +493,7 @@ static inline int is_wild_escape(char c)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Match with the previous pattern character provided in prev.
|
||||
*
|
||||
* An initial '**' needs to know if it was preceded by '/' to distinguish
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ char* strtrim(char* s);
|
|||
*/
|
||||
char* strlwr(char* s);
|
||||
|
||||
/*
|
||||
/**
|
||||
* Find the first occurrence of 'needle' in 'haystack' only if it
|
||||
* appears as a separate word (space, number or string boundaries).
|
||||
*
|
||||
|
|
@ -127,7 +127,7 @@ unsigned long long strtonll(const char* nptr, char** endptr, int base);
|
|||
/****************************************************************************/
|
||||
/* match */
|
||||
|
||||
/*
|
||||
/**
|
||||
* Wild match function.
|
||||
*
|
||||
* If match_sub is !=0, it matches sub directory. Specifically it matches if the
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ unsigned char random_u8(void)
|
|||
return random_u64() & 0xFF;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* SplitMix64
|
||||
*
|
||||
* - Zero-safe: Any 64-bit seed is valid (even 0).
|
||||
|
|
@ -293,7 +293,7 @@ unsigned log_hardware_errors(void)
|
|||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Note that in the following functions we always flush both
|
||||
* stdout and stderr, because we want to ensure that they mixes
|
||||
* well when redirected to files
|
||||
|
|
@ -395,7 +395,7 @@ void vlog_fatal(int err, const char* format, va_list ap, const char* post)
|
|||
log_failed = 1;
|
||||
}
|
||||
|
||||
/* A failed tagged write must retain stderr as the only usable fatal diagnostic. */
|
||||
/* a failed tagged write must retain stderr as the only usable fatal diagnostic. */
|
||||
if (!stdlog || log_failed || msg_fatal_stderr) {
|
||||
va_list ap_copy2;
|
||||
va_copy(ap_copy2, ap);
|
||||
|
|
@ -1108,7 +1108,7 @@ void pathimport(char* dst, size_t size, const char* src)
|
|||
pathcpy(dst, size, src);
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Convert the Windows dir separator '\' to C '/' */
|
||||
/* convert the Windows dir separator '\' to C '/' */
|
||||
while (*dst) {
|
||||
if (*dst == '\\')
|
||||
*dst = '/';
|
||||
|
|
@ -1122,7 +1122,7 @@ void pathexport(char* dst, size_t size, const char* src)
|
|||
pathcpy(dst, size, src);
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Convert C '/' to Windows dir separator '\' */
|
||||
/* convert C '/' to Windows dir separator '\' */
|
||||
while (*dst) {
|
||||
if (*dst == '/')
|
||||
*dst = '\\';
|
||||
|
|
@ -1928,7 +1928,7 @@ int is_sep(char c)
|
|||
|| c == (char)0xa0; /* french */
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* snumber()
|
||||
*
|
||||
* Matches a literal prefix (the second argument), then parses the following
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include "io.h"
|
||||
#include "raid/raid.h"
|
||||
|
||||
/*
|
||||
/**
|
||||
* SnapRAID sync model
|
||||
*
|
||||
* Sync brings the stored parity and content metadata in line with the data
|
||||
|
|
@ -1921,7 +1921,7 @@ bail_abort:
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Make a forced full parity rebuild persistent.
|
||||
*
|
||||
* REBUILD means that the current data and hash are known, but physical parity
|
||||
|
|
@ -1959,7 +1959,7 @@ static void state_sync_mark_rebuild(struct snapraid_state* state)
|
|||
state->need_write = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Initialize persistent parity split sizes resolved while opening parity.
|
||||
*
|
||||
* parity_create() resolves PARITY_SIZE_INVALID in the parity handles using
|
||||
|
|
@ -2208,7 +2208,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t
|
|||
/* after resizing parity files, refresh again the free info */
|
||||
state_refresh(state);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Save the new state before the sync but after the hashing phase
|
||||
*
|
||||
* This allows to recover after an aborted sync, and at the same time
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ void thermal_free(void* void_thermal)
|
|||
free(thermal);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Fit exponential heating model to data using least squares
|
||||
*/
|
||||
struct snapraid_thermal_params fit_thermal_model(const struct snapraid_thermal_point* points, int n_points, double t_ambient)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "os/portable.h"
|
||||
|
||||
#ifndef __MINGW32__ /* Only for Unix */
|
||||
#ifndef __MINGW32__ /* only for Unix */
|
||||
|
||||
#include "app.h"
|
||||
#include "support.h"
|
||||
|
|
@ -64,7 +64,7 @@ static inline unsigned statfs_type(const struct statfs* sfs)
|
|||
#if HAVE_LINUX_DEVICE
|
||||
static const char* const bcachefs_paths[] = {
|
||||
#ifdef BCACHEFS_PATH
|
||||
/* Path configured at build time (e.g. on NixOS). */
|
||||
/* path configured at build time (e.g. on NixOS). */
|
||||
BCACHEFS_PATH,
|
||||
#else
|
||||
"/usr/sbin/bcachefs",
|
||||
|
|
@ -96,7 +96,7 @@ static const char* find_bcachefs(void)
|
|||
#if HAVE_LINUX_DEVICE
|
||||
static const char* const zfs_paths[] = {
|
||||
#ifdef ZFS_PATH
|
||||
/* Path configured at build time (e.g. on NixOS). */
|
||||
/* path configured at build time (e.g. on NixOS). */
|
||||
ZFS_PATH,
|
||||
#else
|
||||
"/usr/sbin/zfs",
|
||||
|
|
@ -125,7 +125,7 @@ static const char* find_zfs(void)
|
|||
|
||||
static const char* const zpool_paths[] = {
|
||||
#ifdef ZPOOL_PATH
|
||||
/* Path configured at build time (e.g. on NixOS). */
|
||||
/* path configured at build time (e.g. on NixOS). */
|
||||
ZPOOL_PATH,
|
||||
#else
|
||||
"/usr/sbin/zpool",
|
||||
|
|
@ -157,7 +157,7 @@ static const char* find_zpool(void)
|
|||
|
||||
static const char* smartctl_paths[] = {
|
||||
#ifdef SMARTCTL_PATH
|
||||
/* Path configured at build time (e.g. on NixOS). */
|
||||
/* path configured at build time (e.g. on NixOS). */
|
||||
SMARTCTL_PATH,
|
||||
#else
|
||||
/* Linux & BSD */
|
||||
|
|
@ -228,7 +228,7 @@ static ssize_t sysread(const char* path, char* buf, size_t buf_size)
|
|||
#endif
|
||||
|
||||
#if HAVE_LINUX_DEVICE
|
||||
/*
|
||||
/**
|
||||
* sysattr_vpd_pg80 — parse raw binary VPD page 0x80 (Unit Serial Number)
|
||||
* from a sysfs vpd_pg80 file.
|
||||
*/
|
||||
|
|
@ -291,7 +291,7 @@ static int sysattr_vpd_pg80(const char* path, char* dst, size_t dst_size)
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
/**
|
||||
* sysread_vpd_pg83 — parse raw binary VPD page 0x83 (Device Identification)
|
||||
* from a sysfs vpd_pg83 file and extract the first NAA (Network Address
|
||||
* Authority) designator for the Logical Unit (ASSOCIATION == 0x00).
|
||||
|
|
@ -418,7 +418,7 @@ static int sysattr_vpd_pg83(const char* path, char* dst, size_t dst_size)
|
|||
|
||||
switch (naa) {
|
||||
case 0x1 : /* IEEE Extended */
|
||||
case 0x2 : /* Locally Assigned */
|
||||
case 0x2 : /* locally assigned */
|
||||
case 0x3 : /* IEEE Registered */
|
||||
case 0x5 : /* IEEE Registered */
|
||||
expected = 8;
|
||||
|
|
@ -503,7 +503,7 @@ static long long syslong(const char* path)
|
|||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Parse Linux cpulist format (e.g. "0-3,5,8-11") into an array of CPU IDs.
|
||||
*
|
||||
* Returns the total number of CPUs in the list. Stores up to max_cpus entries.
|
||||
|
|
@ -553,7 +553,7 @@ static unsigned parse_cpulist(const char* str, unsigned* cpus, unsigned max_cpus
|
|||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Read online CPU IDs from /sys/devices/system/cpu/online.
|
||||
*
|
||||
* Falls back to consecutive 0..N-1 IDs if sysfs is unavailable.
|
||||
|
|
@ -584,7 +584,7 @@ static unsigned read_online_cpus(unsigned* cpus, unsigned max_cpus)
|
|||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Returns 1 if the specified cpu is the lowest-numbered logical CPU in its
|
||||
* physical core's SMT sibling set.
|
||||
*/
|
||||
|
|
@ -2737,7 +2737,7 @@ static int fssnapshot_stat_fs(const struct fssnapshot_struct* fss, const char* n
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
/**
|
||||
* Native ZFS snapshots use a SnapRAID-specific prefix to avoid
|
||||
* deleting or renaming unrelated user snapshots with generic
|
||||
* names such as @scan, @pending, or @stable.
|
||||
|
|
@ -2772,7 +2772,7 @@ static int fssnapshot_stat_zfs(const struct fssnapshot_struct* fss, const char*
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* When verifying if a ZFS snapshot has been successfully deleted, a direct
|
||||
* path lookup (stat, access, open) is unreliable. A directory listing
|
||||
* (readdir) of the .zfs/snapshot directory must be used instead.
|
||||
|
|
@ -4530,7 +4530,7 @@ int devmap(void)
|
|||
|
||||
#if HAVE_LINUX_DEVICE
|
||||
|
||||
/* List of possible ambient temperature labels */
|
||||
/* list of possible ambient temperature labels */
|
||||
const char* AMBIENT_LABEL[] = {
|
||||
"systin",
|
||||
"auxtin",
|
||||
|
|
@ -4976,7 +4976,7 @@ void machineinfo(struct machineinfo_struct* info)
|
|||
}
|
||||
}
|
||||
|
||||
/* Fallback if sysfs cpufreq is unavailable (e.g. Cloud VM) */
|
||||
/* fallback if sysfs cpufreq is unavailable (e.g. Cloud VM) */
|
||||
if (info->cpu_clock[0] == 0) {
|
||||
#ifdef CONFIG_X86
|
||||
raid_cpuid(0, 0, reg);
|
||||
|
|
|
|||
|
|
@ -433,7 +433,7 @@ static void crc32c_skip_init(uint32_t table[8][16], size_t size)
|
|||
unsigned i;
|
||||
unsigned j;
|
||||
|
||||
/* Collapse each fixed-size shift into eight nibble table lookups. */
|
||||
/* collapse each fixed-size shift into eight nibble table lookups. */
|
||||
for (i = 0; i < 8; ++i) {
|
||||
for (j = 0; j < 16; ++j)
|
||||
table[i][j] = crc32c_shift((uint32_t)j << (4 * i), size);
|
||||
|
|
@ -514,7 +514,7 @@ void crc32c_init(void)
|
|||
/****************************************************************************/
|
||||
/* byte operations */
|
||||
|
||||
/*
|
||||
/**
|
||||
* Rotate left.
|
||||
* In x86/x64/ARM they are optimized with a single assembler instruction.
|
||||
*/
|
||||
|
|
@ -528,7 +528,7 @@ static inline uint64_t util_rotl64(uint64_t x, unsigned r)
|
|||
return (x << (r & 63)) | (x >> ((-r) & 63));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Rotate right.
|
||||
* In x86/x64/ARM they are optimized with a single assembler instruction.
|
||||
*/
|
||||
|
|
@ -610,7 +610,7 @@ static inline void util_write64(void* ptr, uint64_t v)
|
|||
memcpy(ptr, &v, sizeof(v));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 64*64 -> 128bit multiply function.
|
||||
*
|
||||
* @param A Address of 64-bit number.
|
||||
|
|
@ -622,7 +622,7 @@ static inline void util_write64(void* ptr, uint64_t v)
|
|||
* Overwrites B contents with C's high 64 bits.
|
||||
*/
|
||||
#if defined(__x86_64__) || defined(_M_X64)
|
||||
/*
|
||||
/**
|
||||
* This is intentionally placed before the __SIZEOF_INT128__ implementation.
|
||||
*
|
||||
* This implementation happens to generate more efficient code.
|
||||
|
|
@ -653,7 +653,7 @@ static inline void util_mum(uint64_t* A, uint64_t* B)
|
|||
*B = (uint64_t)(product >> 64);
|
||||
}
|
||||
#elif defined(__aarch64__) || defined(_M_ARM64)
|
||||
/*
|
||||
/**
|
||||
* This is intentionally placed after the __SIZEOF_INT128__ implementation.
|
||||
*
|
||||
* Although the code looks correct, there is a report of this
|
||||
|
|
|
|||
50
os/mingw.c
50
os/mingw.c
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "os/portable.h"
|
||||
|
||||
#ifdef __MINGW32__ /* Only for MingW */
|
||||
#ifdef __MINGW32__ /* only for MingW */
|
||||
|
||||
#include "os.h"
|
||||
|
||||
|
|
@ -14,9 +14,9 @@
|
|||
/****************************************************************************/
|
||||
/* global */
|
||||
|
||||
/* Add missing Windows declaration */
|
||||
/* add missing Windows declaration */
|
||||
|
||||
/* For SetThreadExecutionState */
|
||||
/* for SetThreadExecutionState */
|
||||
#ifndef WIN32_ES_SYSTEM_REQUIRED
|
||||
#define WIN32_ES_SYSTEM_REQUIRED 0x00000001L
|
||||
#endif
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
#define WIN32_ES_CONTINUOUS 0x80000000L
|
||||
#endif
|
||||
|
||||
/* For SetSearchPathMode */
|
||||
/* for SetSearchPathMode */
|
||||
#ifndef BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE
|
||||
#define BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE 0x00000001
|
||||
#endif
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
#define BASE_SEARCH_PATH_PERMANENT 0x00008000
|
||||
#endif
|
||||
|
||||
/* File Index */
|
||||
/* file Index */
|
||||
#undef FILE_INVALID_FILE_ID
|
||||
#define FILE_INVALID_FILE_ID ((ULONGLONG)-1LL)
|
||||
#undef FILE_UNSUPPORTED_FILE_ID
|
||||
|
|
@ -571,17 +571,17 @@ static BOOL GetReparseTagInfoByHandle(HANDLE hFile, FILE_ATTRIBUTE_TAG_INFO* lpF
|
|||
*/
|
||||
static void windows_attr2stat(DWORD FileAttributes, DWORD ReparseTag, struct windows_stat* st)
|
||||
{
|
||||
/* Convert special attributes */
|
||||
/* convert special attributes */
|
||||
if ((FileAttributes & FILE_ATTRIBUTE_DEVICE) != 0) {
|
||||
st->st_mode = S_IFBLK;
|
||||
st->st_desc = "device";
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_OFFLINE) != 0) { /* Offline */
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_OFFLINE) != 0) { /* offline */
|
||||
st->st_mode = S_IFCHR;
|
||||
st->st_desc = "offline";
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0) { /* Temporary */
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0) { /* temporary */
|
||||
st->st_mode = S_IFCHR;
|
||||
st->st_desc = "temporary";
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { /* Reparse point */
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { /* reparse point */
|
||||
switch (ReparseTag) {
|
||||
/* if we don't have the ReparseTag information */
|
||||
case 0 :
|
||||
|
|
@ -622,7 +622,7 @@ static void windows_attr2stat(DWORD FileAttributes, DWORD ReparseTag, struct win
|
|||
st->st_desc = "reparse-point";
|
||||
break;
|
||||
}
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_SYSTEM) != 0) { /* System */
|
||||
} else if ((FileAttributes & FILE_ATTRIBUTE_SYSTEM) != 0) { /* system */
|
||||
if ((FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
||||
st->st_mode = S_IFCHR;
|
||||
st->st_desc = "system-directory";
|
||||
|
|
@ -696,7 +696,7 @@ static int windows_info2stat(const BY_HANDLE_FILE_INFORMATION* info, const FILE_
|
|||
/* GetFileInformationByHandle() ensures to return synced information */
|
||||
st->st_sync = 1;
|
||||
|
||||
/**
|
||||
/*
|
||||
* In ReFS the IDs are 128 bit, and the 64 bit interface may fail.
|
||||
*
|
||||
* From Microsoft "Application Compatibility with ReFS"
|
||||
|
|
@ -799,13 +799,13 @@ static void windows_finddata2stat(const WIN32_FIND_DATAW* info, struct windows_s
|
|||
|
||||
windows_time2stat(mtime, st);
|
||||
|
||||
/* No inode information available */
|
||||
/* no inode information available */
|
||||
st->st_ino = INODE_INVALID;
|
||||
|
||||
/* No link information available */
|
||||
/* no link information available */
|
||||
st->st_nlink = 0;
|
||||
|
||||
/* No device information available */
|
||||
/* no device information available */
|
||||
st->st_dev = 0;
|
||||
|
||||
/* directory listing doesn't ensure to return synced information */
|
||||
|
|
@ -2079,7 +2079,7 @@ int windows_symlink_directory(const char* existing, const char* file)
|
|||
return windows_symlink_flags(existing, file, SYMBOLIC_LINK_FLAG_DIRECTORY);
|
||||
}
|
||||
|
||||
/* Adds missing definitions in MingW winnt.h */
|
||||
/* adds missing definitions in MingW winnt.h */
|
||||
#ifndef FSCTL_GET_REPARSE_POINT
|
||||
#define FSCTL_GET_REPARSE_POINT 0x000900a8
|
||||
#endif
|
||||
|
|
@ -2258,7 +2258,7 @@ ssize_t windows_read(int fd, void* buffer, size_t size)
|
|||
if (!ReadFile(h, buffer, size, &count, 0)) {
|
||||
DWORD error = GetLastError();
|
||||
|
||||
/* A closed Windows pipe has the same read semantics as a POSIX pipe at EOF. */
|
||||
/* a closed Windows pipe has the same read semantics as a POSIX pipe at EOF. */
|
||||
if (error == ERROR_BROKEN_PIPE)
|
||||
return 0;
|
||||
|
||||
|
|
@ -2982,7 +2982,7 @@ static int fixcat(WCHAR* cmd, int size, int pos, const WCHAR* arg)
|
|||
return pos;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Append one argument using the Microsoft C runtime command-line
|
||||
* quoting rules. Use this when building a normal CreateProcessW()
|
||||
* command line that the target process will parse back into argv[].
|
||||
|
|
@ -3043,7 +3043,7 @@ static int argcat(WCHAR* cmd, int size, int pos, const WCHAR* arg)
|
|||
return pos;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Append one argument for a batch script invoked through cmd.exe /c.
|
||||
* Unlike argcat(), this must preserve the argument boundary while
|
||||
* preventing cmd.exe command metacharacters from changing the command
|
||||
|
|
@ -3369,10 +3369,10 @@ pid_t os_spawn(char** argv, int* stdout_read_int, int* stderr_read_int, const ch
|
|||
if (!ret)
|
||||
create_error = GetLastError();
|
||||
} else {
|
||||
/* Drop to restricted service account */
|
||||
/* drop to restricted service account */
|
||||
HANDLE h_token = NULL;
|
||||
|
||||
/* Validate that the requested user is actually a supported Service Account before attempting logon */
|
||||
/* validate that the requested user is actually a supported Service Account before attempting logon */
|
||||
if (_stricmp(run_as_user, "LocalService") != 0 && _stricmp(run_as_user, "NetworkService") != 0) {
|
||||
os_syslog(OS_LVL_INFO, "only supported users are LocalService and NetworkService");
|
||||
pid_unpublish(pid_slot, 0);
|
||||
|
|
@ -3407,7 +3407,7 @@ pid_t os_spawn(char** argv, int* stdout_read_int, int* stderr_read_int, const ch
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Create an environment block to ensure PATH is loaded */
|
||||
/* create an environment block to ensure PATH is loaded */
|
||||
LPVOID env = NULL;
|
||||
if (!CreateEnvironmentBlock(&env, h_token, FALSE)) {
|
||||
windows_errno(GetLastError());
|
||||
|
|
@ -4385,7 +4385,7 @@ OS_FILE* os_popen(const char** argv)
|
|||
fail_child:
|
||||
saved_errno = errno;
|
||||
close(stdout_fd);
|
||||
/* Terminate and reap the child immediately so no process or handle is leaked on stream creation failure. */
|
||||
/* terminate and reap the child immediately so no process or handle is leaked on stream creation failure. */
|
||||
pid_kill(pid);
|
||||
status = 0;
|
||||
os_wait(pid, &status, 0);
|
||||
|
|
@ -4409,15 +4409,15 @@ int os_pclose(OS_FILE* stream)
|
|||
int close_ret;
|
||||
pid_t wait_ret;
|
||||
|
||||
/* Keep the owned resources locally so the OS_FILE container can be released immediately. */
|
||||
/* keep the owned resources locally so the OS_FILE container can be released immediately. */
|
||||
free(stream);
|
||||
|
||||
/* Closing the stream also closes the CRT descriptor and the underlying stdout pipe handle. */
|
||||
/* closing the stream also closes the CRT descriptor and the underlying stdout pipe handle. */
|
||||
close_ret = fclose(fp);
|
||||
if (close_ret != 0)
|
||||
saved_errno = errno;
|
||||
|
||||
/* Always reap the child even if closing the stream failed. */
|
||||
/* always reap the child even if closing the stream failed. */
|
||||
wait_ret = os_wait(pid, &status, 0);
|
||||
if (wait_ret < 0 && saved_errno == 0)
|
||||
saved_errno = errno;
|
||||
|
|
|
|||
12
os/mingw.h
12
os/mingw.h
|
|
@ -4,7 +4,7 @@
|
|||
#ifndef __PORTABLE_MINGW_H
|
||||
#define __PORTABLE_MINGW_H
|
||||
|
||||
#ifdef __MINGW32__ /* Only for MingW */
|
||||
#ifdef __MINGW32__ /* only for MingW */
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ wchar_t* u8tou16_mayfail(wchar_t* conv_buf, size_t number_of_wchar, const char*
|
|||
#undef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
|
||||
/* Remap functions and types */
|
||||
/* remap functions and types */
|
||||
#undef fopen
|
||||
#define fopen windows_fopen
|
||||
#define FOPEN_TEXT "t"
|
||||
|
|
@ -167,11 +167,11 @@ wchar_t* u8tou16_mayfail(wchar_t* conv_buf, size_t number_of_wchar, const char*
|
|||
#undef sleep
|
||||
#define sleep windows_sleep
|
||||
/* 4==DIR, 5,6,7=free, 8==REG */
|
||||
#define S_IFLNK 0x5000 /* Symbolic link to file */
|
||||
#define S_IFLNK 0x5000 /* symbolic link to file */
|
||||
#define S_ISLNK(m) (((m) & _S_IFMT) == S_IFLNK)
|
||||
#define S_IFLNKDIR 0x6000 /* Symbolic link to directory */
|
||||
#define S_IFLNKDIR 0x6000 /* symbolic link to directory */
|
||||
#define S_ISLNKDIR(m) (((m) & _S_IFMT) == S_IFLNKDIR)
|
||||
#define S_IFJUN 0x7000 /* Junction */
|
||||
#define S_IFJUN 0x7000 /* junction */
|
||||
#define S_ISJUN(m) (((m) & _S_IFMT) == S_IFJUN)
|
||||
#undef readlink
|
||||
#define readlink windows_readlink
|
||||
|
|
@ -210,7 +210,7 @@ wchar_t* u8tou16_mayfail(wchar_t* conv_buf, size_t number_of_wchar, const char*
|
|||
*/
|
||||
#define STAT_NSEC_INVALID -1
|
||||
|
||||
/* We have nano second support */
|
||||
/* we have nano second support */
|
||||
#define STAT_NSEC(st) ((int)(st)->st_mtimensec)
|
||||
|
||||
static inline int WEXITSTATUS(DWORD status)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
#define __PORTABLE_H
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h" /* Use " to include first in the same directory of this file */
|
||||
#include "config.h" /* use " to include first in the same directory of this file */
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
/* Config */
|
||||
/* config */
|
||||
|
||||
#ifdef __MINGW32__
|
||||
/**
|
||||
|
|
@ -163,7 +163,7 @@
|
|||
* Includes some standard headers.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* On many systems (e.g., Darwin), `stdio.h' is a prerequisite. */
|
||||
#include <stdlib.h> /* on many systems (e.g., Darwin), `stdio.h' is a prerequisite. */
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
|
@ -299,7 +299,7 @@
|
|||
#include <linux/close_range.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
/**
|
||||
* Flags for open()
|
||||
*/
|
||||
#ifndef O_PATH
|
||||
|
|
|
|||
24
os/unix.c
24
os/unix.c
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "os/portable.h"
|
||||
|
||||
#ifndef __MINGW32__ /* Only for Unix */
|
||||
#ifndef __MINGW32__ /* only for Unix */
|
||||
|
||||
#include "os.h"
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ int filephy(const char* path, uint64_t size, uint64_t* physical)
|
|||
/****************************************************************************/
|
||||
/* exec */
|
||||
|
||||
/*
|
||||
/**
|
||||
* Scrubbed environment
|
||||
* Only provide the bare essentials.
|
||||
*/
|
||||
|
|
@ -369,7 +369,7 @@ static char* const envp_scrubbed[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Enforce a strict 128-byte shebang limit to match the actual Linux kernel behavior
|
||||
* and prevent security risks from truncation.
|
||||
*
|
||||
|
|
@ -560,7 +560,7 @@ static int verify_shebang_interpreter(int fd, const char* script_path)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Securely verify and open an executable file.
|
||||
*
|
||||
* Performs a series of security checks on the file at @exec_path before
|
||||
|
|
@ -940,7 +940,7 @@ static int pid_kill(pid_t pid)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Send SIGKILL signal to the negative PID to target the entire Process Group */
|
||||
/* send SIGKILL signal to the negative PID to target the entire Process Group */
|
||||
int ret = kill(-pid, SIGKILL);
|
||||
|
||||
/*
|
||||
|
|
@ -1219,7 +1219,7 @@ int os_script(char** argv, char** envp, const char* run_as_user, uint64_t timeou
|
|||
os_user_drop_privileges(&user);
|
||||
|
||||
#if defined(__linux__) && defined(PR_SET_PDEATHSIG)
|
||||
/* Send SIGKILL to child if parent daemon dies unexpectedly */
|
||||
/* send SIGKILL to child if parent daemon dies unexpectedly */
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
/* exit if parent died before prctl to avoid becoming orphaned */
|
||||
if (getppid() != ppid) {
|
||||
|
|
@ -1432,13 +1432,13 @@ int os_command(const char* command, const char* run_as_user, const char* stdin_t
|
|||
setpgid(0, 0);
|
||||
|
||||
if (pipe_fds[1] != -1)
|
||||
close(pipe_fds[1]); /* Close unused write end */
|
||||
close(pipe_fds[1]); /* close unused write end */
|
||||
|
||||
/* drop privileges first (if configured) */
|
||||
os_user_drop_privileges(&user);
|
||||
|
||||
#if defined(__linux__) && defined(PR_SET_PDEATHSIG)
|
||||
/* Send SIGKILL to child if parent daemon dies unexpectedly */
|
||||
/* send SIGKILL to child if parent daemon dies unexpectedly */
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
/* exit if parent died before prctl to avoid becoming orphaned */
|
||||
if (getppid() != ppid) {
|
||||
|
|
@ -1461,7 +1461,7 @@ int os_command(const char* command, const char* run_as_user, const char* stdin_t
|
|||
_exit(126);
|
||||
}
|
||||
|
||||
/* Redirect STDOUT and STDERR to /dev/null */
|
||||
/* redirect STDOUT and STDERR to /dev/null */
|
||||
if (dup2(null_fd, STDOUT_FILENO) == -1
|
||||
|| dup2(null_fd, STDERR_FILENO) == -1)
|
||||
_exit(126);
|
||||
|
|
@ -1657,7 +1657,7 @@ pid_t os_spawn(char** argv, int* stdout_read_fd, int* stderr_read_fd, const char
|
|||
os_user_drop_privileges(&user);
|
||||
|
||||
#if defined(__linux__) && defined(PR_SET_PDEATHSIG)
|
||||
/* Send SIGKILL to child if parent daemon dies unexpectedly */
|
||||
/* send SIGKILL to child if parent daemon dies unexpectedly */
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
/* exit if parent died before prctl to avoid becoming orphaned */
|
||||
if (getppid() != ppid) {
|
||||
|
|
@ -2164,7 +2164,7 @@ void os_privileges_release(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Drop UID last. */
|
||||
/* drop UID last. */
|
||||
if (uid_dropped) {
|
||||
if (syscall(SYS_setresuid, (uid_t)-1, (uid_t)unpriv_uid, (uid_t)-1) != 0) {
|
||||
if (errno == EPERM) {
|
||||
|
|
@ -2198,7 +2198,7 @@ void os_privileges_release(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Drop UID last. */
|
||||
/* drop UID last. */
|
||||
if (uid_dropped) {
|
||||
if (seteuid(unpriv_uid) != 0) {
|
||||
if (errno == EPERM) {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ static inline int close_range_impl(unsigned int first, unsigned int last, unsign
|
|||
*/
|
||||
#define STAT_NSEC_INVALID -1
|
||||
|
||||
/* Check if we have nanoseconds support */
|
||||
/* check if we have nanoseconds support */
|
||||
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
|
||||
#define STAT_NSEC(st) ((int)(st)->st_mtim.tv_nsec) /* Linux */
|
||||
#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue