Skip to content

Commit

Permalink
feat: mount multiply chained dwarfs filesystems, Windows implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Oct 24, 2024
1 parent 53321be commit af21940
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
17 changes: 16 additions & 1 deletion include/tebako-memfs-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@

namespace tebako {

#ifndef _INO_T_DEFINED
typedef ino_t _ino_t;
#define _INO_T_DEFINED
#endif

typedef std::map<uint32_t, std::shared_ptr<memfs>> tebako_memfs_table;

class sync_tebako_memfs_table {
Expand All @@ -40,6 +45,16 @@ class sync_tebako_memfs_table {
public:
static sync_tebako_memfs_table& get_tebako_memfs_table(void);

static constexpr int inoBits = std::min(sizeof(_ino_t), sizeof(uint32_t)) * 8;
static int getFsIndex(_ino_t ino) { return (ino >> (inoBits - 3)) & 0x7; }

static _ino_t getFsIno(_ino_t ino) { return ino & ((static_cast<_ino_t>(1) << (inoBits - 3)) - 1); }

static _ino_t fsInoFromFsAndIno(int index, _ino_t ino)
{
return (static_cast<_ino_t>(index) << (inoBits - 3)) | getFsIno(ino);
}

bool check(uint32_t index);
void clear(void);
void erase(uint32_t index);
Expand Down Expand Up @@ -73,7 +88,7 @@ template <typename Functor, class... Args>
int inode_memfs_call(Functor&& fn, uint32_t inode, Args&&... args)
{
int ret = DWARFS_IO_ERROR;
uint32_t fs_index = (inode >> 29) & 0x7; // Higher three bits is memfs index
uint32_t fs_index = sync_tebako_memfs_table::getFsIndex(inode);

auto fs = sync_tebako_memfs_table::get_tebako_memfs_table().get(fs_index);
if (fs == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/tebako-memfs-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ uint32_t sync_tebako_memfs_table::insert_auto(std::shared_ptr<memfs> fs)
if (index > 7) { // Only three bits to store memfs index
return 0;
}
fs->set_root_inode(index << 29);
fs->set_root_inode(sync_tebako_memfs_table::fsInoFromFsAndIno(index, 0));
p_memfs_table->emplace(index, fs);
return index;
}
Expand Down
31 changes: 31 additions & 0 deletions tests/tests-memfs-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@
struct tebako_dirent;

#include <tebako-io-inner.h>

#ifdef _WIN32
#undef lseek
#undef close
#undef read
#undef pread

#undef chdir
#undef mkdir
#undef rmdir
#undef unlink
#undef access
#undef fstat
#undef stat
#undef lstat
#undef getcwd
#undef opendir
#undef readdir
#undef telldir
#undef seekdir
#undef rewinddir
#undef closedir
#endif

#include <tebako-memfs.h>
#include <tebako-memfs-table.h>

Expand Down Expand Up @@ -124,4 +148,11 @@ TEST_F(MemfsTableTests, test_concurrent_access)
EXPECT_TRUE(memfs_table.check(2));
}

TEST_F(MemfsTableTests, fs_ino_and_index)
{
_ino_t t = sync_tebako_memfs_table::fsInoFromFsAndIno(0x1, 0x234);
EXPECT_EQ(sync_tebako_memfs_table::getFsIndex(t), 0x1);
EXPECT_EQ(sync_tebako_memfs_table::getFsIno(t), 0x234);
}

} // namespace tebako
24 changes: 24 additions & 0 deletions tests/tests-mount-dwarfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@
*/

#include "tests.h"

#ifdef _WIN32
#undef lseek
#undef close
#undef read
#undef pread

#undef chdir
#undef mkdir
#undef rmdir
#undef unlink
#undef access
#undef fstat
#undef stat
#undef lstat
#undef getcwd
#undef opendir
#undef readdir
#undef telldir
#undef seekdir
#undef rewinddir
#undef closedir
#endif

#include <tebako-mount-table.h>

namespace tebako {
Expand Down

0 comments on commit af21940

Please sign in to comment.