10 namespace SWC {
namespace FS {
14 if(*(--s.cend()) !=
'/')
21 #if !defined (FS_BROKER_APP)
43 "Unknown FileSystem name=%s", fs_name.c_str());
68 : async_exists(has_all), async_remove(has_all), async_length(has_all),
69 async_mkdirs(has_all), async_readdir(has_all), async_rmdir(has_all),
70 async_rename(has_all), async_write(has_all), async_readall(has_all),
71 async_combi_pread(has_all), async_create(has_all), async_open(has_all),
72 async_read(has_all), async_pread(has_all), async_append(has_all),
73 async_seek(has_all), async_flush(has_all), async_sync(has_all),
74 async_close(has_all) {
77 #define ADD_OPTION(_N) \
78 ImplOptions& ImplOptions::add_##_N() noexcept { _N = 1; return *this; }\
79 bool ImplOptions::has_##_N() const noexcept { return _N; }
103 : impl_options(impl_opts),
104 path_root(config->path_root.empty()
108 settings(config->settings),
109 cfg_fds_max(config->cfg_fds_max), m_run(true),
110 statistics(config->stats_enabled) {
113 FileSystem::~FileSystem() noexcept { }
115 void FileSystem::stop() {
117 if(statistics.fds_count.load())
119 to_string().c_str(), statistics.fds_count.load());
122 Type FileSystem::get_type() const noexcept {
126 Type FileSystem::get_type_underlying() const noexcept {
132 "(type=UNKNOWN path_root=%s path_data=%s)",
138 void FileSystem::get_abspath(
const std::string& name, std::string& abspath,
143 (name.empty() ? -1 : name.length()) +
146 abspath.append(path_root);
148 abspath.append(path_data.substr(0, path_data.length() - 1));
150 abspath.append(path_data);
151 abspath.append(name);
155 void FileSystem::fd_open_incr() noexcept {
156 statistics.fds_count.fetch_add(1);
159 void FileSystem::fd_open_decr() noexcept {
160 statistics.fds_count.fetch_sub(1);
163 bool FileSystem::need_fds() const noexcept {
164 return statistics.fds_count >= size_t(cfg_fds_max->get());
167 size_t FileSystem::fds_open() const noexcept {
168 return statistics.fds_count.load();
177 const std::string& name) {
179 bool state =
exists(err, name);
184 const std::string& name) {
191 const std::string& name) {
193 size_t len =
length(err, name);
198 const std::string& name) {
205 const std::string& name) {
209 cb(err, std::move(listing));
213 const std::string& name) {
220 const std::string&
from,
const std::string& to) {
228 auto tracker = statistics.tracker(Statistics::WRITE_SYNC);
231 create(err, smartfd, replication);
232 if(!err && !smartfd->valid()) {
235 if(!err && buffer.
size) {
238 for(
int errtmp; smartfd->valid(); ) {
243 length(err, smartfd->filepath()) != buffer.
size && !err) {
253 write(err, smartfd, replication, buffer);
254 cb(err, std::move(buffer));
257 void FileSystem::default_read(
int& err,
const std::string& name,
259 auto tracker = statistics.tracker(Statistics::READ_ALL_SYNC);
278 if(!err && !smartfd->valid()) {
283 if(
read(err, smartfd, buffer, len) != len) {
288 for(
int errtmp; smartfd->valid(); ) {
297 const std::string& name) {
300 read(err, name, &dst);
301 cb(err, std::move(dst));
305 uint64_t offset, uint32_t amount,
307 auto tracker = statistics.tracker(Statistics::COMBI_PREAD_SYNC);
311 if(!err && !smartfd->valid()) {
316 if(
pread(err, smartfd, offset, buffer, amount) != amount) {
321 for(
int errtmp; smartfd->valid(); ) {
330 uint64_t offset, uint32_t amount) {
334 cb(err, std::move(dst));
338 uint8_t replication) {
340 create(err, smartfd, replication);
354 return read(err, smartfd, dst->
base, amount);
361 read(err, smartfd, &dst, amount);
362 cb(err, std::move(dst));
370 return pread(err, smartfd, offset, dst->
base, amount);
374 uint64_t offset,
size_t amount) {
377 pread(err, smartfd, offset, &dst, amount);
378 cb(err, std::move(dst));
391 seek(err, smartfd, offset);