mirror of
https://github.com/nitanmarcel/isodrive.git
synced 2026-03-13 04:17:24 +00:00
isodrive: fix usb gadget
- correctly get gadget - fix writing to sysfs - allow umounting iso
This commit is contained in:
@@ -6,12 +6,14 @@
|
|||||||
#include "configfsisomanager.h"
|
#include "configfsisomanager.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
char *get_gadget_root()
|
char *get_gadget_root()
|
||||||
{
|
{
|
||||||
char *configFsRoot = fs_mount_point("configfs");
|
char *configFsRoot = fs_mount_point("configfs");
|
||||||
char *usbGadgetRoot = strjin(configFsRoot, "/usb_gadget/");
|
char *usbGadgetRoot = strjin(configFsRoot, "/usb_gadget/");
|
||||||
char *gadgetRoot = nullptr;
|
char *gadgetRoot = nullptr;
|
||||||
|
char *udc = nullptr;
|
||||||
|
|
||||||
struct dirent *entry = nullptr;
|
struct dirent *entry = nullptr;
|
||||||
DIR *dp = nullptr;
|
DIR *dp = nullptr;
|
||||||
@@ -22,7 +24,9 @@ char *get_gadget_root()
|
|||||||
if (entry->d_name[0] != '.')
|
if (entry->d_name[0] != '.')
|
||||||
{
|
{
|
||||||
gadgetRoot = strjin(usbGadgetRoot, entry->d_name);
|
gadgetRoot = strjin(usbGadgetRoot, entry->d_name);
|
||||||
break;
|
udc = strjin(gadgetRoot, "/UDC");
|
||||||
|
if (strcmp(udc, getprop("sys.usb.controller")) == 1)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gadgetRoot;
|
return gadgetRoot;
|
||||||
@@ -65,6 +69,7 @@ void mount_iso(char *iso_path)
|
|||||||
char *lunRo = strjin(lunRoot, "/ro");
|
char *lunRo = strjin(lunRoot, "/ro");
|
||||||
|
|
||||||
reset_udc();
|
reset_udc();
|
||||||
|
|
||||||
if (!isdir(massStorageRoot))
|
if (!isdir(massStorageRoot))
|
||||||
{
|
{
|
||||||
mkdir(massStorageRoot, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
mkdir(massStorageRoot, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
char *fs_mount_point(char *filesystem_type);
|
char *fs_mount_point(char *filesystem_type);
|
||||||
char *strjin(char *w1, char *w2);
|
char *strjin(char *w1, char *w2);
|
||||||
bool isdir(char *path);
|
bool isdir(char *path);
|
||||||
|
char *sysfs_read(char *path);
|
||||||
void sysfs_write(char *path, char *content);
|
void sysfs_write(char *path, char *content);
|
||||||
char *getprop(char *key);
|
char *getprop(char *key);
|
||||||
void trim(char *s);
|
void trim(char *s);
|
||||||
|
|||||||
+1
-7
@@ -12,13 +12,7 @@ int main(int argc, char* argv[]){
|
|||||||
}
|
}
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
std::cerr << "Not enough args" << std::endl;
|
iso_target = "";
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (iso_target[0] != '/')
|
|
||||||
{
|
|
||||||
std::cerr << "Iso path is not absolute" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
mount_iso(iso_target);
|
mount_iso(iso_target);
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-9
@@ -9,7 +9,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
// https://stackoverflow.com/a/123724
|
// https://stackoverflow.com/a/123724
|
||||||
void trim(char *s)
|
void trim(char *s)
|
||||||
@@ -58,15 +58,18 @@ bool isdir(char *path)
|
|||||||
void sysfs_write(char *path, char *content)
|
void sysfs_write(char *path, char *content)
|
||||||
{
|
{
|
||||||
std::cout << "Write: " << content << " -> " << path << std::endl;
|
std::cout << "Write: " << content << " -> " << path << std::endl;
|
||||||
std::ofstream sysfsFile;
|
std::ofstream sysfsFile(path);
|
||||||
sysfsFile.open(path);
|
sysfsFile << content << std::endl;
|
||||||
if (!sysfsFile.is_open()) {
|
|
||||||
perror("Failed to open sysfs path");
|
|
||||||
}
|
|
||||||
sysfsFile << content;
|
|
||||||
perror("Status");
|
|
||||||
sysfsFile.close();
|
sysfsFile.close();
|
||||||
std::cout << std::endl;
|
}
|
||||||
|
|
||||||
|
char *sysfs_read(char *path)
|
||||||
|
{
|
||||||
|
char *value = nullptr;
|
||||||
|
std::ifstream sysfsFile(path);
|
||||||
|
sysfsFile >> path;
|
||||||
|
sysfsFile.close();
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user