38 std::ifstream in(path.c_str());
44 for (disk_list_type::const_iterator it = disks_list.begin();
45 it != disks_list.end(); it++)
47 if (it->delete_on_exit)
50 unlink(it->path.c_str());
55 void config::initialize()
58 if (disks_list.size() == 0)
65 is_initialized =
true;
68 void config::find_config()
73 const char* stxxlcfg = getenv(
"STXXLCFG");
75 return load_config_file(stxxlcfg);
79 const char* hostname = getenv(
"HOSTNAME");
80 const char* home = getenv(
"HOME");
81 const char* suffix =
"";
84 const char* hostname = getenv(
"COMPUTERNAME");
85 const char* home = getenv(
"APPDATA");
86 const char* suffix =
".txt";
91 std::string basepath =
"./.stxxl";
93 if (hostname &&
exist_file(basepath +
"." + hostname + suffix))
94 return load_config_file(basepath +
"." + hostname + suffix);
97 return load_config_file(basepath + suffix);
103 std::string basepath = std::string(home) +
"/.stxxl";
105 if (hostname &&
exist_file(basepath +
"." + hostname + suffix))
106 return load_config_file(basepath +
"." + hostname + suffix);
109 return load_config_file(basepath + suffix);
113 load_default_config();
116 void config::load_default_config()
121 disk_config entry1(
"/var/tmp/stxxl", 1000 * 1024 * 1024,
"syscall");
125 disk_config entry1(
"", 1000 * 1024 * 1024,
"wincall");
129 char* tmpstr =
new char[255];
130 if (GetTempPathA(255, tmpstr) == 0)
132 entry1.
path = tmpstr;
133 entry1.
path +=
"stxxl.tmp";
136 disks_list.push_back(entry1);
139 first_flash = (
unsigned int)disks_list.size();
142 void config::load_config_file(
const std::string& config_path)
144 std::vector<disk_config> flash_list;
145 std::ifstream cfg_file(config_path.c_str());
148 return load_default_config();
152 while (std::getline(cfg_file, line))
155 if (line.size() == 0 || line[0] ==
'#')
continue;
161 disks_list.push_back(entry);
163 flash_list.push_back(entry);
168 first_flash = (
unsigned int)disks_list.size();
169 disks_list.insert(disks_list.end(), flash_list.begin(), flash_list.end());
171 if (disks_list.empty()) {
173 "No disks found in '" << config_path <<
"'.");
178 unsigned int config::get_max_device_id()
180 return m_max_device_id;
184 unsigned int config::get_next_device_id()
186 return m_max_device_id++;
190 void config::update_max_device_id(
unsigned int devid)
192 if (m_max_device_id < devid + 1)
193 m_max_device_id = devid + 1;
198 assert(is_initialized);
202 for (disk_list_type::const_iterator it = disks_list.begin();
203 it != disks_list.end(); it++)
205 total_size += it->size;
213 disk_config::disk_config()
216 delete_on_exit(false),
220 device_id(
file::DEFAULT_DEVICE_ID),
222 unlink_on_open(false),
227 const std::string& _io_impl)
232 delete_on_exit(false),
236 device_id(
file::DEFAULT_DEVICE_ID),
238 unlink_on_open(false),
247 delete_on_exit(false),
251 device_id(
file::DEFAULT_DEVICE_ID),
253 unlink_on_open(false),
262 std::vector<std::string> eqfield =
split(line,
"=", 2, 2);
264 if (eqfield[0] ==
"disk") {
267 else if (eqfield[0] ==
"flash") {
272 "Unknown configuration token " << eqfield[0]);
288 std::vector<std::string> cmfield =
split(eqfield[1],
",", 3, 3);
294 std::string::size_type pos;
295 if ((pos =
path.find(
"###")) != std::string::npos)
300 DWORD pid = GetCurrentProcessId();
309 "Invalid disk size '" << cmfield[1] <<
"' in disk configuration file.");
325 size_t leadspace =
io_impl.find_first_not_of(
' ');
330 size_t spacepos =
io_impl.find(
' ');
331 if (spacepos == std::string::npos)
336 std::string paramstr =
io_impl.substr(spacepos + 1);
339 std::vector<std::string> param =
split(paramstr,
" ");
341 for (std::vector<std::string>::const_iterator p = param.begin();
342 p != param.end(); ++p)
345 std::vector<std::string> eq =
split(*p,
"=", 2, 2);
351 else if (*p ==
"autogrow" || *p ==
"noautogrow" || eq[0] ==
"autogrow")
355 if (*p ==
"autogrow")
autogrow =
true;
356 else if (*p ==
"noautogrow")
autogrow =
false;
357 else if (eq[1] ==
"off")
autogrow =
false;
358 else if (eq[1] ==
"on")
autogrow =
true;
359 else if (eq[1] ==
"no")
autogrow =
false;
360 else if (eq[1] ==
"yes")
autogrow =
true;
364 "Invalid parameter '" << *p <<
"' in disk configuration file.");
367 else if (*p ==
"delete" || *p ==
"delete_on_exit")
371 else if (*p ==
"direct" || *p ==
"nodirect" || eq[0] ==
"direct")
386 "Invalid parameter '" << *p <<
"' in disk configuration file.");
389 else if (eq[0] ==
"queue")
392 STXXL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
396 queue = (int)strtoul(eq[1].c_str(), &endp, 10);
397 if (endp && *endp != 0) {
399 "Invalid parameter '" << *p <<
"' in disk configuration file.");
402 else if (eq[0] ==
"queue_length")
405 STXXL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' "
406 "is only valid for fileio linuxaio "
407 "in disk configuration file.");
412 if (endp && *endp != 0) {
414 "Invalid parameter '" << *p <<
"' in disk configuration file.");
417 else if (eq[0] ==
"device_id" || eq[0] ==
"devid")
420 device_id = (int)strtoul(eq[1].c_str(), &endp, 10);
421 if (endp && *endp != 0) {
423 "Invalid parameter '" << *p <<
"' in disk configuration file.");
426 else if (*p ==
"raw_device")
429 STXXL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
434 else if (*p ==
"unlink" || *p ==
"unlink_on_open")
439 STXXL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
447 "Invalid optional parameter '" << *p <<
"' in disk configuration file.");
454 std::ostringstream oss;
459 oss <<
" autogrow=no";
462 oss <<
" delete_on_exit";
466 oss <<
" direct=off";
472 STXXL_THROW(std::runtime_error,
"Invalid setting for 'direct' option.");
478 oss <<
" queue=" <<
queue;
484 oss <<
" raw_device";
487 oss <<
" unlink_on_open";
static const unsigned int DEFAULT_DEVICE_ID
int queue
select request queue for disk. Use different queues for files on different disks. queue=-1 -> default...
unsigned long long int uint64
External FIFO queue container. Introduction to queue container: see STXXL Queue tutorial Design a...
bool unlink_on_open
unlink file immediately after opening (available on most Unix)
#define STXXL_THROW(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message]".
static bool exist_file(const std::string &path)
#define STXXL_THROW_WIN_LASTERROR(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message] : [formatted GetLastError()]".
bool delete_on_exit
delete file on program exit (default for autoconfigurated files)
Defines interface of file.
std::string path
the file path used by the io implementation
Encapsulate the configuration of one "disk". The disk is actually a file I/O object which block_manag...
static std::vector< std::string > split(const std::string &str, const std::string &sep, unsigned int min_fields=0, unsigned int limit_fields=std::numeric_limits< unsigned int >::max())
Split a string by given separator string. Returns a vector of strings with at least min_fields and at...
bool autogrow
autogrow file if more disk space is needed, automatically set if size == 0.
std::string to_str(const Type &t)
Format any ostream-able type into a string.
#define STXXL_BEGIN_NAMESPACE
std::string fileio_string() const
return formatted fileio name and optional configuration parameters
void parse_line(const std::string &line)
parse a disk=<path>,<size>,<fileio> options line into disk_config, throws std::runtime_error on parse...
bool parse_SI_IEC_size(const std::string &str, uint64 &size, char def_unit=0)
Parse a string like "343KB" or "44 GiB" into the corresponding size in bytes. Returns the number of b...
disk_config()
default constructor
unsigned int device_id
the selected physical device id (e.g. for calculating prefetching sequences). If -1 then the device i...
int queue_length
desired queue length for linuxaio_file and linuxaio_queue
static const int DEFAULT_QUEUE
bool raw_device
turned on by syscall fileio when the path points to a raw block device
void parse_fileio()
parse the "io_impl" parameter into the optional parameter fields.
static const int DEFAULT_LINUXAIO_QUEUE
bool flash
marks flash drives (configuration entries with flash= instead of disk=)
enum stxxl::disk_config::direct_type direct
std::string io_impl
io implementation to access file
uint64 size
file size to initially allocate
#define STXXL_END_NAMESPACE