mirror of
https://github.com/AltraMayor/f3.git
synced 2025-09-16 18:46:44 -04:00
Remove arbitrary limit on filenames
The filenames were from 0001.fff to 9999.fff. This limit hasn't been a problem, but Anselm Distelrath reported on February 8th, 2013 that isn't enough to test his system: a RAID 6 with 18 hard drives of 3TB each. Now filenames are from 1.fff to <INT_MAX>.fff.
This commit is contained in:
parent
a642c2f3c8
commit
90b0bfbfcd
2
f3read.c
2
f3read.c
@ -158,7 +158,7 @@ static void iterate_files(const char *path, const int *files, int progress)
|
||||
int number = 0;
|
||||
|
||||
tot_ok = tot_corrupted = tot_changed = tot_overwritten = tot_size = 0;
|
||||
printf(" SECTORS "
|
||||
printf(" SECTORS "
|
||||
" ok/corrupted/changed/overwritten\n");
|
||||
|
||||
while (*files >= 0) {
|
||||
|
41
utils.c
41
utils.c
@ -21,26 +21,45 @@ const char *adjust_unit(double *ptr_bytes)
|
||||
return units[i];
|
||||
}
|
||||
|
||||
int is_my_file(const char *filename)
|
||||
{
|
||||
const char *p = filename;
|
||||
|
||||
if (!p || !isdigit(*p))
|
||||
return 0;
|
||||
|
||||
/* Skip digits. */
|
||||
do {
|
||||
p++;
|
||||
} while (isdigit(*p));
|
||||
|
||||
return (p[0] == '.') && (p[1] == 'f') && (p[2] == 'f') &&
|
||||
(p[3] == 'f') && (p[4] == '\0');
|
||||
}
|
||||
|
||||
void full_fn_from_number(char *full_fn, const char **filename,
|
||||
const char *path, int num)
|
||||
{
|
||||
static char format[32] = "";
|
||||
if (!format[0]) {
|
||||
assert(FILENAME_NUM_DIGITS > 0);
|
||||
assert(FILENAME_NUM_DIGITS < 10);
|
||||
sprintf(format, "%%s/%%%02ii.fff", FILENAME_NUM_DIGITS);
|
||||
}
|
||||
assert(snprintf(full_fn, PATH_MAX, format, path, num + 1) < PATH_MAX);
|
||||
assert(snprintf(full_fn, PATH_MAX, "%s/%i.fff", path, num + 1) <
|
||||
PATH_MAX);
|
||||
*filename = full_fn + strlen(path) + 1;
|
||||
}
|
||||
|
||||
static int number_from_filename(const char *filename)
|
||||
{
|
||||
char str[FILENAME_NUM_DIGITS + 1];
|
||||
const char *p;
|
||||
int num;
|
||||
|
||||
assert(is_my_file(filename));
|
||||
strncpy(str, filename, FILENAME_NUM_DIGITS);
|
||||
str[FILENAME_NUM_DIGITS] = '\0';
|
||||
return strtol(str, NULL, 10) - 1;
|
||||
|
||||
p = filename;
|
||||
num = 0;
|
||||
do {
|
||||
num = num * 10 + (*p - '0');
|
||||
p++;
|
||||
} while (isdigit(*p));
|
||||
|
||||
return num - 1;
|
||||
}
|
||||
|
||||
/* Don't call this function directly, use ls_my_files() instead. */
|
||||
|
12
utils.h
12
utils.h
@ -7,21 +7,13 @@
|
||||
#include <sys/time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define FILENAME_NUM_DIGITS 4
|
||||
|
||||
#define SECTOR_SIZE (512)
|
||||
#define GIGABYTES (1024 * 1024 * 1024)
|
||||
|
||||
const char *adjust_unit(double *ptr_bytes);
|
||||
|
||||
static inline int is_my_file(const char *filename)
|
||||
{
|
||||
return isdigit(filename[0]) && isdigit(filename[1]) &&
|
||||
isdigit(filename[2]) && isdigit(filename[3]) &&
|
||||
(filename[4] == '.') && (filename[5] == 'f') &&
|
||||
(filename[6] == 'f') && (filename[7] == 'f') &&
|
||||
(filename[8] == '\0');
|
||||
}
|
||||
/* Return true if @filename matches the regex /^[0-9]+\.fff$/ */
|
||||
int is_my_file(const char *filename);
|
||||
|
||||
/* @filename should be PATH_MAX long. */
|
||||
void full_fn_from_number(char *full_fn, const char **filename,
|
||||
|
Loading…
x
Reference in New Issue
Block a user