Beautify code with uncrustify

This commit is contained in:
Andrea Mazzoleni 2025-10-26 18:06:08 +01:00
parent 04711f7483
commit 21acc31bf1
15 changed files with 79 additions and 67 deletions

View file

@ -44,3 +44,4 @@ void bw_limit(struct snapraid_bw* bw, uint64_t bytes)
usleep(eta * 1000);
}
}

View file

@ -43,3 +43,4 @@ void bw_init(struct snapraid_bw* bw, uint64_t limit);
void bw_limit(struct snapraid_bw* bw, uint64_t bytes);
#endif

View file

@ -2114,3 +2114,4 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
return -1;
return 0;
}

View file

@ -771,7 +771,7 @@ static void state_probe(struct snapraid_state* state, tommy_list* low)
{
tommy_node* i;
size_t device_pad;
(void)state;
/* compute lengths for padding */
@ -803,7 +803,7 @@ static void state_probe(struct snapraid_state* state, tommy_list* low)
switch (devinfo->power) {
case POWER_STANDBY : printf("StandBy"); break;
case POWER_ACTIVE : printf(" Active"); break;
default: printf("Unknown"); break;
default : printf("Unknown"); break;
}
printf(" ");
@ -991,7 +991,7 @@ void state_device(struct snapraid_state* state, int operation, tommy_list* filte
if (operation == DEVICE_SMART)
state_smart(state, state->level + tommy_list_count(&state->disklist), &low);
if (operation == DEVICE_PROBE)
state_probe(state, &low);
}

View file

@ -32,7 +32,7 @@ static int needs_quote(const WCHAR* arg)
return 1;
++arg;
}
return 0;
}
@ -80,7 +80,7 @@ static int argcat(WCHAR* cmd, int size, int pos, const WCHAR* arg)
charcat(*arg);
++arg;
}
}
}
/* ending quote */
charcat(L'"');
@ -112,38 +112,38 @@ static char* argutf8(const WCHAR* arg)
static HANDLE child_process = NULL;
/* Console control handler - forwards Ctrl+C, Ctrl+Break to child */
static BOOL WINAPI console_handler(DWORD ctrl_type)
static BOOL WINAPI console_handler(DWORD ctrl_type)
{
/* if no child, default behavior */
if (child_process == NULL)
if (child_process == NULL)
return FALSE;
switch (ctrl_type) {
case CTRL_C_EVENT :
case CTRL_BREAK_EVENT :
/*
* Return TRUE to prevent parent termination. The child process
* will receive these events automatically because it's attached
* to the same console, so we don't need to forward them.
/*
* Return TRUE to prevent parent termination. The child process
* will receive these events automatically because it's attached
* to the same console, so we don't need to forward them.
*/
return TRUE; /* signal handled, don't terminate parent */
case CTRL_CLOSE_EVENT :
case CTRL_LOGOFF_EVENT :
case CTRL_SHUTDOWN_EVENT :
/*
/*
* Return TRUE to prevent our termination while child handles shutdown.
* The child receives these events automatically (same console).
* Note: Windows will forcibly kill us after a timeout regardless
* of returning TRUE: ~5 seconds for CLOSE_EVENT and LOGOFF_EVENT,
* ~5-20 seconds for SHUTDOWN_EVENT (configurable in registry).
* ~5-20 seconds for SHUTDOWN_EVENT (configurable in registry).
*/
return TRUE; /* signal handled, but Windows will kill us after timeout */
default:
default :
return FALSE;
}
}
int main(int argc, char* argv[])
int main(int argc, char* argv[])
{
int wide_argc;
WCHAR** wide_argv;
@ -156,7 +156,7 @@ int main(int argc, char* argv[])
int pos;
int mode;
int ret;
(void)argc;
(void)argv;
@ -272,7 +272,7 @@ int main(int argc, char* argv[])
}
}
for(i = 0;i < utf8_argc; ++i)
for (i = 0; i < utf8_argc; ++i)
free(utf8_argv[i]);
free(utf8_argv);
@ -282,7 +282,7 @@ int main(int argc, char* argv[])
char full_argv0[PATH_MAX];
const char* get_argv0(const char* argv0)
const char* get_argv0(const char* argv0)
{
ssize_t len = readlink("/proc/self/exe", full_argv0, sizeof(full_argv0) - 1);
if (len != -1) {
@ -302,14 +302,14 @@ const char* get_argv0(const char* argv0)
static volatile pid_t child_pid = 0;
/* signal handler that forwards signals to child */
static void forward_signal(int sig)
static void forward_signal(int sig)
{
if (child_pid > 0) {
kill(child_pid, sig);
}
}
int main(int argc, char* argv[])
int main(int argc, char* argv[])
{
int mode;
int i, j;
@ -318,7 +318,7 @@ int main(int argc, char* argv[])
mode = MODE_DEFAULT;
j = 1;
for (i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--spin-down-on-error") == 0 ) {
if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--spin-down-on-error") == 0) {
mode = MODE_SPINDOWN;
} else {
argv[j] = argv[i];
@ -425,3 +425,4 @@ int main(int argc, char* argv[])
return ret;
}
#endif

View file

@ -206,7 +206,7 @@ void os_abort(void)
#ifdef __GNUC__
printf(", gcc " __VERSION__);
#endif
printf(", %d-bit", (int)sizeof(void *) * 8);
printf(", %d-bit", (int)sizeof(void*) * 8);
printf(", PATH_MAX=%d", PATH_MAX);
printf("\n");
@ -1047,18 +1047,18 @@ int windows_fsync(int fd)
return 0;
}
static int windows_vsync(const wchar_t* volume)
static int windows_vsync(const wchar_t* volume)
{
HANDLE h;
DWORD bytes;
/* open the volume (volumeName already in \\?\Volume{GUID} format) */
h = CreateFileW(volume, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE) {
windows_errno(GetLastError());
return -1;
}
/*
* "The FlushFileBuffers API can be used to flush all the outstanding data
* and metadata on a single file or a whole volume. However, frequent use
@ -1128,12 +1128,12 @@ static int windows_vsync(const wchar_t* volume)
windows_errno(error);
return -1;
}
if (!CloseHandle(h)) {
windows_errno(GetLastError());
return -1;
}
return 0;
}
@ -1144,13 +1144,13 @@ static int windows_async(void)
DWORD error = 0;
DWORD count = 0;
DWORD success = 0;
h = FindFirstVolumeW(volume, sizeof(volume) / sizeof(wchar_t));
if (h == INVALID_HANDLE_VALUE) {
windows_errno(GetLastError());
return -1;
}
do {
/* remove trailing backslash */
size_t len = wcslen(volume);
@ -1192,7 +1192,7 @@ static int windows_async(void)
int windows_sync(void)
{
if (windows_async() != 0)
if (windows_async() != 0)
return -1;
return 0;
@ -1361,7 +1361,7 @@ int windows_open(const char* file, int flags, ...)
case O_RDWR :
access = GENERIC_READ | GENERIC_WRITE;
break;
default:
default :
errno = EINVAL;
return -1;
}
@ -1385,7 +1385,7 @@ int windows_open(const char* file, int flags, ...)
case O_TRUNC :
create = TRUNCATE_EXISTING;
break;
default:
default :
errno = EINVAL;
return -1;
}
@ -3070,7 +3070,7 @@ int windows_cond_wait(windows_cond_t* cond, windows_mutex_t* mutex)
}
struct windows_key_context {
void (* func)(void *);
void (*func)(void*);
DWORD key;
tommy_node node;
};
@ -3078,7 +3078,7 @@ struct windows_key_context {
/* list of all keys with destructor */
static tommy_list windows_key_list = { 0 };
int windows_key_create(windows_key_t* key, void(* destructor)(void*))
int windows_key_create(windows_key_t* key, void (*destructor)(void*))
{
struct windows_key_context* context;
@ -3140,7 +3140,7 @@ int windows_setspecific(windows_key_t key, void* value)
struct windows_thread_context {
HANDLE h;
unsigned id;
void* (* func)(void *);
void* (*func)(void*);
void* arg;
void* ret;
};
@ -3168,7 +3168,7 @@ static unsigned __stdcall windows_thread_func(void* arg)
return 0;
}
int windows_create(thread_id_t* thread, void* attr, void* (* func)(void *), void* arg)
int windows_create(thread_id_t* thread, void* attr, void* (*func)(void*), void* arg)
{
struct windows_thread_context* context;

View file

@ -410,11 +410,11 @@ int windows_cond_destroy(windows_cond_t* cond);
int windows_cond_signal(windows_cond_t* cond);
int windows_cond_broadcast(windows_cond_t* cond);
int windows_cond_wait(windows_cond_t* cond, windows_mutex_t* mutex);
int windows_key_create(windows_key_t* key, void(* destructor)(void*));
int windows_key_create(windows_key_t* key, void (*destructor)(void*));
int windows_key_delete(windows_key_t key);
void* windows_getspecific(windows_key_t key);
int windows_setspecific(windows_key_t key, void* value);
int windows_create(thread_id_t* thread, void* attr, void* (* func)(void *), void *arg);
int windows_create(thread_id_t* thread, void* attr, void* (*func)(void*), void *arg);
int windows_join(thread_id_t thread, void** retval);
#endif

View file

@ -489,7 +489,7 @@ struct option long_options[] = {
/*
* Free letters: gIjJkKMnPQrtuxXWz
*
*
* The 's' letter is used in main.c
*/
#define OPTIONS "c:f:d:mebp:o:S:B:L:i:l:AZEUDNFRahTC:vqHVGw:"
@ -1270,7 +1270,7 @@ int snapraid_main(int argc, char* argv[])
case OPERATION_DRY :
break;
#endif
default:
default :
/* we allow direct IO only on some commands */
if (opt.file_mode == ADVISE_DIRECT)
opt.file_mode = ADVISE_SEQUENTIAL;
@ -1576,3 +1576,4 @@ int snapraid_main(int argc, char* argv[])
return EXIT_SUCCESS;
}

View file

@ -1100,7 +1100,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co
if (strcmp(buffer, "*") == 0) {
smart = state->smartignore;
} else if (lev_config_scan(buffer, &level, 0) == 0) { /* search for parity */
} else if (lev_config_scan(buffer, &level, 0) == 0) { /* search for parity */
smart = state->parity[level].smartignore;
} else {
struct snapraid_disk* disk;
@ -4469,9 +4469,9 @@ static struct snapraid_thermal* state_thermal_find(struct snapraid_state* state,
struct snapraid_thermal* thermal = i->data;
if (strcmp(thermal->name, name) == 0) {
if (found == 0
// if multiple matches, return the one with highest temperature
/* if multiple matches, return the one with highest temperature */
|| found->latest_temperature < thermal->latest_temperature
// or, if the temperature is equal, the one with the higher r_squared
/* or, if the temperature is equal, the one with the higher r_squared */
|| (found->latest_temperature == thermal->latest_temperature && found->params.r_squared < thermal->params.r_squared)
) {
found = thermal;
@ -4578,7 +4578,7 @@ static void state_progress_graph(struct snapraid_state* state, struct snapraid_i
for (i = state->disklist; i != 0; i = i->next) {
struct snapraid_disk* disk = i->data;
v = disk->progress_tick[current] - ref(disk->progress_tick, oldest);
printr(disk->name, pad);
@ -5096,6 +5096,7 @@ int state_flush(struct snapraid_state* state, struct snapraid_io* io, struct sna
/* LCOV_EXCL_STOP */
}
}
return 0;
}

View file

@ -310,7 +310,7 @@ void msg_progress(const char* format, ...)
vmsg(stdout, format, ap);
va_end(ap);
fflush(stdout);
fflush(stdout);
}
unlock_msg();
@ -476,7 +476,7 @@ const char* esc_tag(const char* str, char* buffer)
ESCAPE(':', '\\', 'd');
ESCAPE('\\', '\\', '\\');
default:
default :
if (p == end)
goto bail;
*p++ = c;
@ -608,14 +608,14 @@ const char* esc_shell_multi(const char** str_map, unsigned str_max, char* buffer
case '*' : /* wildcard */
case '(' : /* shell */
case ')' : /* shell */
case '\\': /* quote */
case '\\' : /* quote */
case '|' : /* pipe */
case '[' : /* wildcard */
case ']' : /* wildcard */
case '{' : /* code */
case '}' : /* code */
case ';' : /* separator */
case '\'': /* quote */
case '\'' : /* quote */
case '"' : /* quote */
case '<' : /* redirect */
case '>' : /* redirect */
@ -729,7 +729,7 @@ void strlwr(char* s)
}
#endif
char* worddigitstr(const char* haystack, const char* needle)
char* worddigitstr(const char* haystack, const char* needle)
{
size_t len = strlen(needle);
const char* s;
@ -1840,7 +1840,7 @@ void thread_cond_broadcast_and_unlock(thread_cond_t* cond, thread_mutex_t* mutex
}
}
void thread_create(thread_id_t* thread, void* (* func)(void *), void *arg)
void thread_create(thread_id_t* thread, void* (*func)(void*), void *arg)
{
if (pthread_create(thread, 0, func, arg) != 0) {
/* LCOV_EXCL_START */
@ -1869,3 +1869,4 @@ void thread_yield(void)
#endif
}
#endif

View file

@ -212,7 +212,7 @@ void printp(double v, size_t pad);
/****************************************************************************/
/* string */
#define ESC_MAX (PATH_MAX*2 + 1)
#define ESC_MAX (PATH_MAX * 2 + 1)
/**
* Escape a string for the log.
@ -251,7 +251,7 @@ char* strpolish(char* s);
unsigned strsplit(char** split_map, unsigned split_max, char* line, const char* delimiters);
/**
* Trim spaces from the start and the end
* Trim spaces from the start and the end
*/
void strtrim(char* s);
@ -263,9 +263,9 @@ void strlwr(char* s);
#endif
/*
* Find the first occurrence of 'needle' in 'haystack' only if it
* Find the first occurrence of 'needle' in 'haystack' only if it
* appears as a separate word (space, number or string boundaries).
*
*
* Returns a pointer to the beginning of the match, or NULL if not found.
*/
char* worddigitstr(const char* haystack, const char* needle);

View file

@ -40,8 +40,10 @@ void thermal_free(struct snapraid_thermal* 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)
/*
* 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)
{
struct snapraid_thermal_params model;
double t_steady_try;
@ -75,7 +77,7 @@ struct snapraid_thermal_params fit_thermal_model(const struct snapraid_thermal_p
double diff = points[i].temperature - t_predicted;
error += diff * diff;
}
if (error < best_error) {
best_error = error;
best_k = k_try;
@ -104,10 +106,10 @@ struct snapraid_thermal_params fit_thermal_model(const struct snapraid_thermal_p
double t = points[i].time;
double t_predicted = model.t_steady - (model.t_steady - points[0].temperature) * exp(-model.k_heat * t);
double residual = points[i].temperature - t_predicted;
sum_squared_residuals += residual * residual;
sum_total += (points[i].temperature - mean_temp) * (points[i].temperature - mean_temp);
double abs_error = fabs(residual);
if (abs_error > model.max_error) {
model.max_error = abs_error;
@ -242,7 +244,7 @@ void state_thermal(struct snapraid_state* state, time_t now)
}
found->latest_temperature = temperature;
if (highest_temperature < temperature)
highest_temperature = temperature;
@ -302,7 +304,7 @@ int state_thermal_alarm(struct snapraid_state* state)
void state_thermal_cooldown(struct snapraid_state* state)
{
int sleep_time = state->thermal_cooldown_time;
if (sleep_time == 0)
sleep_time = 5 * 60; /* default sleep time */
if (sleep_time < 5 * 60)
@ -369,6 +371,7 @@ int state_thermal_begin(struct snapraid_state* state, time_t now)
return 0;
/* LCOV_EXCL_STOP */
}
return 1;
}

View file

@ -73,3 +73,4 @@ struct snapraid_thermal* thermal_alloc(uint64_t dev, const char* name);
void thermal_free(struct snapraid_thermal* thermal);
#endif

View file

@ -70,7 +70,7 @@ const char* stat_desc(struct stat* st)
/**
* Read a file from sys
*
*
* Return -1 on error, otherwise the data read
*/
#if HAVE_LINUX_DEVICE
@ -1815,14 +1815,14 @@ int ambient_temperature(void)
DIR* hwmon_dir;
struct dirent* hwmon_entry;
if (strncmp(entry->d_name, "hwmon", 5) != 0)
if (strncmp(entry->d_name, "hwmon", 5) != 0)
continue;
pathprint(path, sizeof(path), "/sys/class/hwmon/%s", entry->d_name);
/* iterate through temp*_input files */
hwmon_dir = opendir(path);
if (!hwmon_dir)
if (!hwmon_dir)
continue;
while ((hwmon_entry = readdir(hwmon_dir)) != NULL) {
@ -1852,7 +1852,7 @@ int ambient_temperature(void)
continue;
temp = strtol(value, &e, 10) / 1000;
if (*e != 0 && !isspace(*e))
if (*e != 0 && !isspace(*e))
continue;
/* cut the file name at "_input" */

View file

@ -258,3 +258,4 @@ unsigned muldiv(uint64_t v, uint64_t mul, uint64_t div);
unsigned muldiv_upper(uint64_t v, uint64_t mul, uint64_t div);
#endif