mirror of
https://github.com/nitanmarcel/isodrive.git
synced 2026-03-13 04:17:24 +00:00
isodrive: uncrustify code to google cpp writing style
This commit is contained in:
@@ -22,13 +22,16 @@ char *get_gadget_root()
|
||||
|
||||
struct dirent *entry = nullptr;
|
||||
DIR *dp = nullptr;
|
||||
|
||||
dp = opendir(usbGadgetRoot);
|
||||
|
||||
if (dp != nullptr)
|
||||
while ((entry = readdir(dp)))
|
||||
{
|
||||
if (entry->d_name[0] != '.')
|
||||
{
|
||||
char *gadget = strjin(usbGadgetRoot, entry->d_name);
|
||||
|
||||
if (sysfs_read(strjin(gadget, (char *)"/UDC")) != nullptr)
|
||||
{
|
||||
gadgetRoot = gadget;
|
||||
@@ -42,6 +45,7 @@ char *get_gadget_root()
|
||||
char* get_config_root()
|
||||
{
|
||||
char *gadgetRoot = get_gadget_root();
|
||||
|
||||
if (gadgetRoot == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
@@ -51,7 +55,9 @@ char *get_config_root()
|
||||
|
||||
struct dirent *entry = nullptr;
|
||||
DIR *dp = nullptr;
|
||||
|
||||
dp = opendir(usbConfigRoot);
|
||||
|
||||
if (dp != nullptr)
|
||||
while ((entry = readdir(dp)))
|
||||
{
|
||||
@@ -67,6 +73,7 @@ char *get_config_root()
|
||||
void mount_iso(char *iso_path, char *cdrom, char *ro)
|
||||
{
|
||||
char *gadgetRoot = get_gadget_root();
|
||||
|
||||
if (gadgetRoot == nullptr)
|
||||
{
|
||||
printf("No active gadget found\n");
|
||||
@@ -90,6 +97,7 @@ void mount_iso(char *iso_path, char *cdrom, char *ro)
|
||||
{
|
||||
mkdir(massStorageRoot, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
}
|
||||
|
||||
if (!isdir(strjin(configRoot, (char *)"/mass_storage.0")))
|
||||
{
|
||||
symlink(massStorageRoot, strjin(configRoot, (char *)"/mass_storage.0"));
|
||||
@@ -104,16 +112,19 @@ void mount_iso(char *iso_path, char *cdrom, char *ro)
|
||||
void set_udc(char *udc, char *gadget)
|
||||
{
|
||||
char *udcFile = strjin(gadget, (char *)"/UDC");
|
||||
|
||||
sysfs_write(udcFile, udc);
|
||||
}
|
||||
|
||||
char* get_udc()
|
||||
{
|
||||
char *gadget_root = get_gadget_root();
|
||||
|
||||
if (gadget_root == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
char *udcFile = strjin(gadget_root, (char *)"/UDC");
|
||||
|
||||
return sysfs_read(udcFile);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,12 @@ bool supported();
|
||||
char* get_gadget_root();
|
||||
char* get_config_root();
|
||||
|
||||
void mount_iso(char *iso_path, char *cdrom, char *ro);
|
||||
void set_udc(char *udc, char *gadget);
|
||||
void mount_iso(char *iso_path,
|
||||
char *cdrom,
|
||||
char *ro);
|
||||
void umount_iso();
|
||||
void set_udc(char *udc,
|
||||
char *gadget);
|
||||
char* get_udc();
|
||||
|
||||
#endif
|
||||
#endif // ifndef CONFIGFSISOMANAGER_H
|
||||
|
||||
+5
-4
@@ -2,10 +2,11 @@
|
||||
#define UTIL_H
|
||||
|
||||
char* fs_mount_point(char *filesystem_type);
|
||||
char *strjin(char *w1, char *w2);
|
||||
char* strjin(char *w1,
|
||||
char *w2);
|
||||
bool isdir(char *path);
|
||||
char* sysfs_read(char *path);
|
||||
void sysfs_write(char *path, char *content);
|
||||
|
||||
#endif
|
||||
void sysfs_write(char *path,
|
||||
char *content);
|
||||
|
||||
#endif // ifndef UTIL_H
|
||||
|
||||
+6
-2
@@ -3,10 +3,12 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *iso_target = argv[1];
|
||||
char *cdrom = (char *)"0";
|
||||
char *ro = (char *)"1";
|
||||
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (strcmp(argv[i], "-rw") == 0)
|
||||
@@ -28,7 +30,8 @@ int main(int argc, char* argv[]){
|
||||
printf("Usage:\n");
|
||||
printf("cdrom [FILE]... [OPTION]...\n");
|
||||
printf("Mounts the given FILE as a bootable device using configfs.\n");
|
||||
printf("Run without any arguments to unmount any mounted files and display this help message.\n\n");
|
||||
printf(
|
||||
"Run without any arguments to unmount any mounted files and display this help message.\n\n");
|
||||
|
||||
printf("Optional arguments:\n");
|
||||
printf("-rw\t Mounts the file in read write mode.\n");
|
||||
@@ -45,6 +48,7 @@ int main(int argc, char* argv[]){
|
||||
printf("Device does not support configfs usb gadget\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (getuid() != 0)
|
||||
{
|
||||
printf("Permission denied\n");
|
||||
|
||||
+11
-3
@@ -11,13 +11,16 @@
|
||||
#include <cstdio>
|
||||
#include <dirent.h>
|
||||
|
||||
char *fs_mount_point(char *filesystem_type) {
|
||||
char* fs_mount_point(char *filesystem_type)
|
||||
{
|
||||
struct mntent *ent;
|
||||
FILE *mounts;
|
||||
char *mount_point = nullptr;
|
||||
|
||||
mounts = setmntent("/proc/mounts", "r");
|
||||
while (nullptr != (ent = getmntent(mounts))) {
|
||||
|
||||
while (nullptr != (ent = getmntent(mounts)))
|
||||
{
|
||||
if (strcmp(ent->mnt_fsname, filesystem_type) == 0)
|
||||
{
|
||||
mount_point = ent->mnt_dir;
|
||||
@@ -30,6 +33,7 @@ char *fs_mount_point(char *filesystem_type) {
|
||||
{
|
||||
const char *alt_usb_gadget = "/config/usb_gadget";
|
||||
DIR *dir = opendir(alt_usb_gadget);
|
||||
|
||||
if (dir)
|
||||
{
|
||||
mount_point = (char *)"/config";
|
||||
@@ -41,6 +45,7 @@ char *fs_mount_point(char *filesystem_type) {
|
||||
char* strjin(char *w1, char *w2)
|
||||
{
|
||||
char *s = new char[strlen(w1) + strlen(w2) + 1];
|
||||
|
||||
strcpy(s, w1);
|
||||
strcat(s, w2);
|
||||
return s;
|
||||
@@ -49,6 +54,7 @@ char *strjin(char *w1, char *w2)
|
||||
bool isdir(char *path)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat(path, &sb) == 0)
|
||||
return true;
|
||||
else
|
||||
@@ -67,18 +73,20 @@ char *sysfs_read(char *path)
|
||||
{
|
||||
std::string value;
|
||||
std::ifstream sysfsFile(path);
|
||||
|
||||
if (!sysfsFile.is_open())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
sysfsFile >> value;
|
||||
sysfsFile.close();
|
||||
|
||||
if (value.empty())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
char *result = new char[value.length() + 1];
|
||||
|
||||
strcpy(result, value.c_str());
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user