[LibOS] Replace hardcoded paths with manifest-supplied parameters

This commit is contained in:
Dmitrii Kuvaiskii
2019-12-19 15:10:24 -08:00
parent 103995e945
commit b9b1d4bb82
3 changed files with 29 additions and 21 deletions
+7 -5
View File
@@ -134,11 +134,13 @@ size_t shim_do_write (int fd, const void * buf, size_t count)
int shim_do_open (const char * file, int flags, mode_t mode)
{
if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) {
char hardlink[128] = {'\0'};
strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15);
file = hardlink;
debug("[FPGA DEMO] opening hardlink file: %s\n", file);
//char hardlink[128] = {'\0'};
//strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
char devicepath[CONFIG_MAX] = {'\0'};
get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath));
memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15);
file = devicepath;
debug("[FPGA DEMO] opening devicepath file: %s\n", file);
}
if (!file || test_user_string(file))
+21 -15
View File
@@ -33,11 +33,13 @@
int shim_do_stat (const char * file, struct stat * stat)
{
if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) {
char hardlink[128] = {'\0'};
strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15);
file = hardlink;
debug("[FPGA DEMO] stating hardlink file: %s\n", file);
//char hardlink[128] = {'\0'};
//strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
char devicepath[CONFIG_MAX] = {'\0'};
get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath));
memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15);
file = devicepath;
debug("[FPGA DEMO] stating devicepath file: %s\n", file);
}
if (!file || test_user_string(file))
@@ -69,11 +71,13 @@ out:
int shim_do_lstat (const char * file, struct stat * stat)
{
if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) {
char hardlink[128] = {'\0'};
strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15);
file = hardlink;
debug("[FPGA DEMO] stating hardlink file: %s\n", file);
//char hardlink[128] = {'\0'};
//strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
char devicepath[CONFIG_MAX] = {'\0'};
get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath));
memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15);
file = devicepath;
debug("[FPGA DEMO] stating devicepath file: %s\n", file);
}
if (!file || test_user_string(file))
@@ -135,11 +139,13 @@ int shim_do_readlink (const char * file, char * buf, size_t bufsize)
return -EINVAL;
if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) {
char hardlink[128] = {'\0'};
strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15);
memcpy(buf, hardlink, strlen(hardlink));
return strlen(hardlink);
//char hardlink[128] = {'\0'};
//strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink));
char devicepath[CONFIG_MAX] = {'\0'};
get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath));
memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15);
memcpy(buf, devicepath, strlen(devicepath));
return strlen(devicepath);
}
int ret;