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)
63 is_initialized =
true;
66 void config::find_config()
71 const char* stxxlcfg = getenv(
"STXXLCFG");
73 return load_config_file(stxxlcfg);
77 const char* hostname = getenv(
"HOSTNAME");
78 const char* home = getenv(
"HOME");
79 const char* suffix =
"";
82 const char* hostname = getenv(
"COMPUTERNAME");
83 const char* home = getenv(
"APPDATA");
84 const char* suffix =
".txt";
89 std::string basepath =
"./.stxxl";
91 if (hostname &&
exist_file(basepath +
"." + hostname + suffix))
92 return load_config_file(basepath +
"." + hostname + suffix);
95 return load_config_file(basepath + suffix);
101 std::string basepath = std::string(home) +
"/.stxxl";
103 if (hostname &&
exist_file(basepath +
"." + hostname + suffix))
104 return load_config_file(basepath +
"." + hostname + suffix);
107 return load_config_file(basepath + suffix);
111 load_default_config();
114 void config::load_default_config()
119 disk_config entry1(
"/var/tmp/stxxl", 1000 * 1024 * 1024,
"syscall");
123 disk_config entry1(
"", 1000 * 1024 * 1024,
"wincall");
127 char* tmpstr =
new char[255];
128 if (GetTempPath(255, tmpstr) == 0)
130 entry1.
path = tmpstr;
131 entry1.
path +=
"stxxl.tmp";
134 disks_list.push_back(entry1);
137 first_flash = (
unsigned int)disks_list.size();
140 void config::load_config_file(
const std::string& config_path)
142 std::vector<disk_config> flash_list;
143 std::ifstream cfg_file(config_path.c_str());
146 return load_default_config();
150 while (std::getline(cfg_file, line))
153 if (line.size() == 0 || line[0] ==
'#')
continue;
159 disks_list.push_back(entry);
161 flash_list.push_back(entry);
166 first_flash = (
unsigned int)disks_list.size();
167 disks_list.insert(disks_list.end(), flash_list.begin(), flash_list.end());
169 if (disks_list.empty()) {
171 "No disks found in '" << config_path <<
"'.");
177 assert(is_initialized);
181 for (disk_list_type::const_iterator it = disks_list.begin();
182 it != disks_list.end(); it++)
184 total_size += it->size;
190 disk_config::disk_config()
193 delete_on_exit(false),
198 unlink_on_open(false)
202 const std::string& _io_impl)
207 delete_on_exit(false),
212 unlink_on_open(false)
220 delete_on_exit(false),
225 unlink_on_open(false)
233 std::vector<std::string> eqfield =
split(line,
"=", 2, 2);
235 if (eqfield[0] ==
"disk") {
238 else if (eqfield[0] ==
"flash") {
243 "Unknown configuration token " << eqfield[0]);
258 std::vector<std::string> cmfield =
split(eqfield[1],
",", 3, 3);
264 std::string::size_type pos;
265 if ((pos =
path.find(
"###")) != std::string::npos)
270 DWORD pid = GetCurrentProcessId();
279 "Invalid disk size '" << cmfield[1] <<
"' in disk configuration file.");
295 size_t leadspace =
io_impl.find_first_not_of(
' ');
300 size_t spacepos =
io_impl.find(
' ');
301 if (spacepos == std::string::npos)
306 std::string paramstr =
io_impl.substr(spacepos + 1);
309 std::vector<std::string> param =
split(paramstr,
" ");
311 for (std::vector<std::string>::const_iterator p = param.begin();
312 p != param.end(); ++p)
315 std::vector<std::string> eq =
split(*p,
"=", 2, 2);
321 else if (*p ==
"autogrow")
326 else if (*p ==
"delete" || *p ==
"delete_on_exit")
330 else if (*p ==
"direct" || *p ==
"nodirect" || eq[0] ==
"direct")
345 "Invalid parameter '" << *p <<
"' in disk configuration file.");
348 else if (eq[0] ==
"queue")
351 queue = strtoul(eq[1].c_str(), &endp, 10);
352 if (endp && *endp != 0) {
354 "Invalid parameter '" << *p <<
"' in disk configuration file.");
357 else if (*p ==
"raw_device")
360 STXXL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
365 else if (*p ==
"unlink" || *p ==
"unlink_on_open")
368 STXXL_THROW(std::runtime_error,
"Parameter '" << *p <<
"' invalid for fileio '" <<
io_impl <<
"' in disk configuration file.");
376 "Invalid optional parameter '" << *p <<
"' in disk configuration file.");
383 std::ostringstream oss;
391 oss <<
" delete_on_exit";
395 oss <<
" direct=off";
401 assert(!
"Invalid setting for 'direct' option.");
407 oss <<
" queue=" <<
queue;
410 oss <<
" raw_device";
413 oss <<
" unlink_on_open";
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
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.
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