23 #include <foxxll/config.hpp> 44 TLX_LOG0 <<
"foxxll: Checking " << path <<
" for disk configuration.";
45 std::ifstream in(path.c_str());
50 : is_initialized(false)
55 for (disk_list_type::const_iterator it =
disks_list.begin();
58 if (it->delete_on_exit)
60 TLX_LOG1 <<
"foxxll: Removing disk file: " << it->path;
61 unlink(it->path.c_str());
89 const char* cfg = getenv(
"STXXLCFG");
95 const char* hostname = getenv(
"HOSTNAME");
96 const char* home = getenv(
"HOME");
97 const char* suffix =
"";
100 const char* hostname = getenv(
"COMPUTERNAME");
101 const char* home = getenv(
"APPDATA");
102 const char* suffix =
".txt";
109 if (hostname &&
exist_file(basepath +
"." + hostname + suffix))
122 if (hostname &&
exist_file(basepath +
"." + hostname + suffix))
135 TLX_LOG1 <<
"foxxll: [Warning] no config file found.";
136 TLX_LOG1 <<
"foxxll: Using default disk configuration.";
146 std::vector<disk_config> flash_list;
147 std::ifstream cfg_file(config_path.c_str());
154 while (std::getline(cfg_file, line))
157 if (line.size() == 0 || line[0] ==
'#')
continue;
165 flash_list.push_back(entry);
176 "No disks found in '" << config_path <<
"'." 208 return std::pair<unsigned, unsigned>(0,
first_flash);
214 return std::pair<unsigned, unsigned>(
235 return "/var/tmp/foxxll";
237 char* tmpstr =
new char[255];
238 if (GetTempPathA(255, tmpstr) == 0)
241 result +=
"foxxll.tmp";
279 for (disk_list_type::const_iterator it =
disks_list.begin();
282 total_size += it->size;
293 delete_on_exit(false),
296 queue(
file::DEFAULT_QUEUE),
297 device_id(
file::DEFAULT_DEVICE_ID),
299 unlink_on_open(false),
339 std::vector<std::string> eqfield =
tlx::split(
'=', line, 2, 2);
341 if (eqfield[0] ==
"disk") {
344 else if (eqfield[0] ==
"flash") {
350 "Unknown configuration token " << eqfield[0]
367 std::vector<std::string> cmfield =
tlx::split(
',', eqfield[1], 3, 3);
373 std::string::size_type pos;
374 if ((pos =
path.find(
"$$")) != std::string::npos)
379 DWORD pid = GetCurrentProcessId();
389 "Invalid disk size '" << cmfield[1] <<
"' in disk configuration file." 406 size_t leadspace =
io_impl.find_first_not_of(
' ');
411 size_t spacepos =
io_impl.find(
' ');
412 if (spacepos == std::string::npos)
420 std::vector<std::string> param =
tlx::split(
' ', paramstr);
422 for (std::vector<std::string>::const_iterator p = param.begin();
423 p != param.end(); ++p)
426 std::vector<std::string> eq =
tlx::split(
'=', *p, 2, 2);
432 else if (*p ==
"autogrow" || *p ==
"noautogrow" || eq[0] ==
"autogrow")
436 if (*p ==
"autogrow")
autogrow =
true;
437 else if (*p ==
"noautogrow")
autogrow =
false;
438 else if (eq[1] ==
"off")
autogrow =
false;
439 else if (eq[1] ==
"on")
autogrow =
true;
440 else if (eq[1] ==
"no")
autogrow =
false;
441 else if (eq[1] ==
"yes")
autogrow =
true;
446 "Invalid parameter '" << *p <<
"' in disk configuration file." 450 else if (*p ==
"delete" || *p ==
"delete_on_exit")
454 else if (*p ==
"direct" || *p ==
"nodirect" || eq[0] ==
"direct")
470 "Invalid parameter '" << *p <<
"' in disk configuration file." 474 else if (eq[0] ==
"queue")
477 FOXXLL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
481 queue =
static_cast<int>(strtoul(eq[1].c_str(), &endp, 10));
482 if (endp && *endp != 0) {
485 "Invalid parameter '" << *p <<
"' in disk configuration file." 489 else if (eq[0] ==
"queue_length")
493 std::runtime_error,
"Parameter '" << *p <<
"' " 494 "is only valid for fileio linuxaio " 495 "in disk configuration file." 500 queue_length =
static_cast<int>(strtoul(eq[1].c_str(), &endp, 10));
501 if (endp && *endp != 0) {
504 "Invalid parameter '" << *p <<
"' in disk configuration file." 508 else if (eq[0] ==
"device_id" || eq[0] ==
"devid")
511 device_id =
static_cast<int>(strtoul(eq[1].c_str(), &endp, 10));
512 if (endp && *endp != 0) {
515 "Invalid parameter '" << *p <<
"' in disk configuration file." 519 else if (*p ==
"raw_device")
522 FOXXLL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
527 else if (*p ==
"unlink" || *p ==
"unlink_on_open")
532 FOXXLL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
541 "Invalid optional parameter '" << *p <<
"' in disk configuration file." 549 std::ostringstream oss;
554 oss <<
" autogrow=no";
557 oss <<
" delete_on_exit";
562 oss <<
" direct=off";
571 FOXXLL_THROW(std::runtime_error,
"Invalid setting for 'direct' option.");
578 oss <<
" queue=" <<
queue;
586 oss <<
" raw_device";
590 oss <<
" unlink_on_open";
external_size_type size
file size to initially allocate
void update_max_device_id(unsigned int devid)
Update the automatic physical device id counter.
unsigned int next_device_id()
Returns next automatic physical device id counter.
std::string & expand_environment_variables(std::string *sp)
Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment variables.
std::string path
the file path used by the io implementation
virtual void initialize()
void parse_fileio()
parse the "io_impl" parameter into the optional parameter fields.
static const unsigned int DEFAULT_DEVICE_ID
unsigned int max_device_id()
Returns automatic physical device id counter.
#define FOXXLL_THROW(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message]".
external_size_type disk_size(size_t disk) const
virtual void load_config_file(const std::string &config_path)
Load disk configuration file.
bool unlink_on_open
unlink file immediately after opening (available on most Unix)
virtual std::string default_disk_path()
std::string io_impl
io implementation to access file
disk_config()
default constructor
virtual std::string default_disk_io_impl()
Returns name of the default I/O implementation.
unsigned int max_device_id_
static counter for automatic physical device enumeration
std::string to_str(const Type &t)
Format any ostream-able type into a string.
void parse_line(const std::string &line)
external_size_type total_size() const
Returns the total size over all disks.
std::vector< std::string > split(char sep, const std::string &str, std::string::size_type limit)
Split the given string at each separator character into distinct substrings.
virtual void find_config()
Search several places for a config file.
virtual ~config()
deletes autogrow files
disk_config & disk(size_t disk)
Returns mutable disk_config structure for additional disk parameters.
static bool exist_file(const std::string &path)
disk_list_type disks_list
list of configured disks
bool parse_si_iec_units(const char *str, uint64_t *out_size, char default_unit)
Parse a string like "343KB" or "44 GiB" into the corresponding size in bytes.
const std::string & disk_io_impl(size_t disk) const
bool flash
marks flash drives (configuration entries with flash= instead of disk=)
static const int DEFAULT_QUEUE
std::pair< unsigned, unsigned > regular_disk_range() const
Returns contiguous range of regular disks w/o flash devices in the array of all disks.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
virtual std::string default_config_file_name()
returns the name of the default config file prefix
#define TLX_LOG0
Override default output: never or always output log.
bool is_initialized
Finished initializing config.
std::string fileio_string() const
return formatted fileio name and optional configuration parameters
void print_library_version_mismatch()
Check and print mismatch between header and library versions.
bool raw_device
turned on by syscall fileio when the path points to a raw block device
int queue_length
desired queue length for linuxaio_file and linuxaio_queue
static const int DEFAULT_LINUXAIO_QUEUE
const std::string & disk_path(size_t disk) const
config & add_disk(const disk_config &cfg)
config()
Constructor: this must be inlined to print the header version string.
bool delete_on_exit
delete file on program exit (default for autoconfigurated files)
virtual void load_default_config()
Load default configuration.
bool autogrow
autogrow file if more disk space is needed, automatically set if size == 0.
unsigned first_flash
In disks_list, flash devices come after all regular disks.
uint64_t external_size_type
std::pair< unsigned, unsigned > flash_range() const
enum foxxll::disk_config::direct_type direct
std::string get_version_string_long()
Return longer "X.Y.Z (feature) (version)" version string (of headers)