Skip to content

Commit

Permalink
tests second fs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Oct 21, 2024
1 parent 2e05c39 commit 499ece5
Show file tree
Hide file tree
Showing 25 changed files with 485 additions and 226 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ jobs:
source: '.'
extensions: 'h,cpp,c'
clangFormatVersion: 14
# inplace: True
# - name: Commit changes
# uses: EndBug/add-and-commit@v9
# with:
# message: clang-format fixes
# committer_name: GitHub Actions
# committer_email: [email protected]
inplace: True
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
message: clang-format fixes
committer_name: GitHub Actions
committer_email: [email protected]
1 change: 1 addition & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:
path: |
${{github.workspace}}/build/wr-bin
${{github.workspace}}/build/wr-tests
${{github.workspace}}/build/fs2.bin
test-on-macos-13-and-14:
# The run on MacOS 14 is the amd64 on arm64 test
Expand Down
51 changes: 32 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,10 @@ add_library(dwarfs-wr STATIC
"src/tebako-io-helpers.cpp"
"src/tebako-io-root.cpp"
"src/tebako-kfd.cpp"
"src/tebako-mnt.cpp"
"src/tebako-mount-table.cpp"
"src/tebako-mfs.cpp"
"src/tebako-dfs.cpp"
"src/tebako-dft.cpp"
"src/tebako-memfs-table.cpp"
"src/tebako-fd.cpp"
"src/tebako-dirent.cpp"
"include/tebako-cmdline-helpers.h"
Expand All @@ -829,9 +829,9 @@ add_library(dwarfs-wr STATIC
"include/tebako-io-inner.h"
"include/tebako-io-root.h"
"include/tebako-kfd.h"
"include/tebako-dfs.h"
"include/tebako-dft.h"
"include/tebako-mnt.h"
"include/tebako-memfs.h"
"include/tebako-memfs-table.h"
"include/tebako-mount-table.h"
"include/tebako-mfs.h"
"include/tebako-pch.h"
"include/tebako-pch-pp.h"
Expand Down Expand Up @@ -938,11 +938,21 @@ if(WITH_TESTS)
BYPRODUCTS ${DATA_BIN_FILE_2}
)

add_dependencies(PACKAGED_FILESYSTEM_STEP_1 empty)
add_dependencies(PACKAGED_FILESYSTEM_STEP_1 empty ${DWARFS_PRJ})
add_dependencies(dwarfs-wr PACKAGED_FILESYSTEM_STEP_1)

set(TESTS_OUTSIDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_files")

set(TESTS_THE_OTHER_MEMFS_IMAGE "${CMAKE_CURRENT_BINARY_DIR}/fs2.bin")

# feat: exectable application stub
# add_executable(wr-mount "tests/tebako-fs2.cpp")
# if(WIN32)
# set(TESTS_THE_OTHER_MEMFS_IMAGE "${CMAKE_CURRENT_BINARY_DIR}/wr-mount.exe")
# else()
# set(TESTS_THE_OTHER_MEMFS_IMAGE "${CMAKE_CURRENT_BINARY_DIR}/wr-mount")
# endif()

if (WITH_LINK_TESTS)
add_custom_target(PACKAGED_FILESYSTEM_STEP_2 ALL
COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} rm -rf h-link-to-file-2 s-link-to-file-1 s-link-to-dir-1 s-link-outside-of-memfs s-dir-outside-of-memfs
Expand Down Expand Up @@ -1001,23 +1011,25 @@ if(WITH_TESTS)
@ONLY
)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/tebako-fs2.cpp.in
${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp
@ONLY
)
# feat: exectable application stub
# configure_file(
# ${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/tebako-fs2.cpp.in
# ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp
# @ONLY
# )

if(IS_WINDOWS)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs0.c
COMMAND ${DEPS}/bin/incbin.exe ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs.cpp -o ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs0.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs.cpp ${DATA_BIN_FILE} ${INCBIN_PRJ}
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
COMMAND ${DEPS}/bin/incbin.exe ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp -o ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp ${DATA_BIN_FILE_2} ${INCBIN_PRJ}
)
# feat: exectable application stub
# add_custom_command(
# OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
# COMMAND ${DEPS}/bin/incbin.exe ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp -o ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp ${DATA_BIN_FILE_2} ${INCBIN_PRJ}
# )
endif(IS_WINDOWS)

function(ADD_DWARFS_LIBRARY NAME PRJ APP_NM)
Expand Down Expand Up @@ -1150,13 +1162,14 @@ else(IS_WINDOWS)
)
add_dependencies(wr-tests PACKAGED_FILESYSTEM_STEP_3)

add_executable(wr-mount "tests/tebako-fs2.cpp")
add_dependencies(wr-mount PACKAGED_FILESYSTEM_STEP_1)
# feat: exectable application stub
# add_dependencies(wr-mount PACKAGED_FILESYSTEM_STEP_1)

if(IS_WINDOWS)
target_sources(wr-bin PUBLIC "tests/tebako-fs0.c" )
target_sources(wr-tests PUBLIC "tests/tebako-fs0.c")
target_sources(wr-mount PUBLIC "tests/tebako-fs02.c")
# feat: exectable application stub
# target_sources(wr-mount PUBLIC "tests/tebako-fs02.c")
endif(IS_WINDOWS)

if(RB_W32)
Expand Down
5 changes: 5 additions & 0 deletions include/tebako-io-root.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ int mount_root_memfs(const void* data,
const char* decompress_ratio,
const char* image_offset);

int mount_memfs(const void* data,
const unsigned int size,
const char* image_offset,
const char* path);

void unmount_root_memfs(void);

int dwarfs_access(const std::string&, int amode, uid_t uid, gid_t gid, std::string& lnk) noexcept;
Expand Down
5 changes: 5 additions & 0 deletions include/tebako-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ int mount_root_memfs(const void* data,
const char* decompress_ratio,
const char* image_offset);

int mount_memfs(const void* data,
const unsigned int size,
const char* image_offset,
const char* path);

void unmount_root_memfs(void);

char* tebako_getcwd(char* buf, size_t size);
Expand Down
7 changes: 4 additions & 3 deletions include/tebako-dft.h → include/tebako-memfs-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace tebako {

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

class sync_tebako_memfs_table {
private:
Expand All @@ -43,8 +43,9 @@ class sync_tebako_memfs_table {
bool check(uint32_t index);
void clear(void);
void erase(uint32_t index);
memfs* get(uint32_t index);
bool insert(uint32_t index, memfs* fs);
std::shared_ptr<memfs> get(uint32_t index);
bool insert(uint32_t index, std::shared_ptr<memfs> fs);
uint32_t insert_auto(std::shared_ptr<memfs> fs);
};


Expand Down
6 changes: 4 additions & 2 deletions include/tebako-dfs.h → include/tebako-memfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class memfs {
private:
const void* data;
const unsigned int size;
uint32_t dwarfs_root;
uint32_t dwarfs_root_inode;

dwarfs::filesystem_options fsopts;
dwarfs::filesystem_v2 fs;
Expand All @@ -79,6 +79,8 @@ class memfs {

int load(const char* image_offset = "auto");
void set_image_offset_str(const char* image_offset = "auto");
uint32_t get_root_inode(void) { return dwarfs_root_inode; }
void set_root_inode(uint32_t df_root_inode) { dwarfs_root_inode = df_root_inode; }

int access(const std::string& path, int amode, uid_t uid, gid_t gid, std::string& lnk) noexcept;
int inode_access(uint32_t inode, int amode, uid_t uid, gid_t gid) noexcept;
Expand All @@ -105,7 +107,7 @@ class memfs {
}
int relative_stat(const std::string& path, struct stat* st, std::string& lnk, bool follow) noexcept
{
return find_inode_abs(dwarfs_root, path, follow, lnk, st);
return find_inode_abs(dwarfs_root_inode, path, follow, lnk, st);
}

#if defined(TEBAKO_HAS_LSTAT) || defined(RB_W32) || defined(_WIN32)
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions include/tebako-pch-pp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <cstdlib>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion src/tebako-cmdline-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <tebako-common.h>
#include <tebako-io-inner.h>
#include <tebako-io-root.h>
#include <tebako-mnt.h>
#include <tebako-mount-table.h>

#include <tebako-cmdline-helpers.h>

Expand Down
31 changes: 23 additions & 8 deletions src/tebako-dfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
#include <tebako-pch-pp.h>
#include <tebako-common.h>
#include <tebako-dirent.h>
#include <tebako-dfs.h>
#include <tebako-memfs.h>
#include <tebako-io.h>
#include <tebako-io-inner.h>
#include <tebako-mfs.h>
#include <tebako-mnt.h>
#include <tebako-memfs-table.h>
#include <tebako-mount-table.h>

using namespace dwarfs;

Expand Down Expand Up @@ -66,7 +67,7 @@ memfs_options& memfs::options()
return opts;
}

memfs::memfs(const void* dt, const unsigned int sz, uint32_t df_root): data{dt}, size{sz}, dwarfs_root(df_root)
memfs::memfs(const void* dt, const unsigned int sz, uint32_t df_root_inode): data{dt}, size{sz}, dwarfs_root_inode(df_root_inode)
{
fsopts << options();
}
Expand All @@ -77,21 +78,21 @@ int memfs::load(const char* image_offset)

try {
set_image_offset_str(image_offset);
fs = filesystem_v2(logger(), std::make_shared<tebako::mfs>(data, size), fsopts, dwarfs_root, nullptr);
fs = filesystem_v2(logger(), std::make_shared<tebako::mfs>(data, size), fsopts, dwarfs_root_inode, nullptr);
LOG_TIMED_INFO << "Filesystem initialized";
}

catch (stdfs::filesystem_error const& e) {
LOG_ERROR << "Filesystem error: " << e.what();
return 1;
return -1;
}
catch (std::exception const& e) {
LOG_ERROR << "Error: " << e.what();
return 1;
return -1;
}
catch (...) {
LOG_ERROR << "Unexpected error";
return 1;
return -1;
}

return 0;
Expand Down Expand Up @@ -195,6 +196,20 @@ int memfs::find_inode(uint32_t start_from,
continue;
}
}
else if (std::holds_alternative<uint32_t>(*mount_point)) {
uint32_t index = std::get<uint32_t>(*mount_point);
LOG_DEBUG << __func__ << " [ mount point --> memfs:\"" << index << "\" ]";
auto next_memfs = tebako::sync_tebako_memfs_table::get_tebako_memfs_table().get(index);
if (next_memfs != nullptr) {
auto next_inode = next_memfs->get_root_inode();
ret = next_memfs->find_inode(next_inode, (++p_iterator)->string(), follow_last, lnk, st);
}
else {
LOG_DEBUG << __func__ << " [ Memfs not mounted ]";
TEBAKO_SET_LAST_ERROR(ENOENT);
ret = DWARFS_IO_ERROR;
}
}
else {
LOG_DEBUG << __func__ << " [ Invalid mount point type ]";
TEBAKO_SET_LAST_ERROR(ENOENT);
Expand Down Expand Up @@ -336,7 +351,7 @@ int memfs::find_inode_root(const std::string& path, bool follow, std::string& ln
auto adjusted_path = path.substr(path[TEBAKO_MOUNT_POINT_LENGTH] == '\0' ? TEBAKO_MOUNT_POINT_LENGTH
: TEBAKO_MOUNT_POINT_LENGTH + 1);

ret = find_inode_abs(dwarfs_root, adjusted_path, follow, lnk, st);
ret = find_inode_abs(dwarfs_root_inode, adjusted_path, follow, lnk, st);
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tebako-dirent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <tebako-io-root.h>
#include <tebako-fd.h>
#include <tebako-dirent.h>
#include <tebako-dfs.h>
#include <tebako-memfs.h>

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion src/tebako-fd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <tebako-io-inner.h>
#include <tebako-io-root.h>
#include <tebako-fd.h>
#include <tebako-dfs.h>
#include <tebako-memfs.h>

using namespace std;

Expand Down
Loading

0 comments on commit 499ece5

Please sign in to comment.