2022-12-03 04:20:27 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-12-03 04:20:27 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 akuker
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "test/linux_os_stubs.h"
|
|
|
|
#include "test/test_shared.h"
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <map>
|
2023-10-15 06:38:15 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2022-12-03 04:20:27 +00:00
|
|
|
#include <string>
|
2023-10-15 06:38:15 +00:00
|
|
|
#ifdef __linux__
|
2022-12-03 04:20:27 +00:00
|
|
|
#include <sys/epoll.h>
|
2023-10-15 06:38:15 +00:00
|
|
|
#endif
|
2022-12-03 04:20:27 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace filesystem;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
#ifdef __USE_LARGEFILE64
|
|
|
|
FILE *__wrap_fopen64(const char *__restrict __filename, const char *__restrict __modes)
|
|
|
|
#else
|
|
|
|
FILE *__wrap_fopen(const char *__restrict __filename, const char *__restrict __modes)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
path new_filename;
|
2022-12-09 15:50:45 +00:00
|
|
|
auto in_filename = path(__filename);
|
2022-12-03 04:20:27 +00:00
|
|
|
bool create_directory = false;
|
|
|
|
|
|
|
|
// If we're trying to open up the device tree soc ranges,
|
|
|
|
// re-direct it to a temporary local file.
|
2022-12-09 15:50:45 +00:00
|
|
|
if ((string(__filename) == "/proc/device-tree/soc/ranges") ||
|
|
|
|
(string(__filename).find(".properties") != string::npos)) {
|
2022-12-03 04:20:27 +00:00
|
|
|
create_directory = true;
|
|
|
|
new_filename = test_data_temp_path;
|
2022-12-09 15:50:45 +00:00
|
|
|
if (!in_filename.has_parent_path()) {
|
|
|
|
new_filename += "/";
|
|
|
|
}
|
|
|
|
new_filename += in_filename;
|
2022-12-03 04:20:27 +00:00
|
|
|
} else {
|
2022-12-09 15:50:45 +00:00
|
|
|
new_filename = in_filename;
|
2022-12-03 04:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (create_directory) {
|
|
|
|
create_directories(new_filename.parent_path());
|
|
|
|
}
|
|
|
|
#ifdef __USE_LARGEFILE64
|
|
|
|
return __real_fopen64(new_filename.c_str(), __modes);
|
|
|
|
#else
|
|
|
|
return __real_fopen(new_filename.c_str(), __modes);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
} // end extern "C"
|