Use fstab to get /data device path
This commit is contained in:
@@ -16,7 +16,8 @@ LOCAL_SRC_FILES:= \
|
||||
button.c \
|
||||
pong.c \
|
||||
progressdots.c \
|
||||
multirom_ui_themes.c
|
||||
multirom_ui_themes.c \
|
||||
fstab.c
|
||||
|
||||
ifeq ($(ARCH_ARM_HAVE_NEON),true)
|
||||
LOCAL_SRC_FILES += col32cb16blend_neon.S
|
||||
|
||||
57
fstab.c
57
fstab.c
@@ -20,6 +20,8 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "fstab.h"
|
||||
#include "util.h"
|
||||
@@ -96,7 +98,7 @@ struct fstab *fstab_load(const char *path)
|
||||
}
|
||||
|
||||
if(t->version == 2)
|
||||
part->device = strdup(p);
|
||||
part->device = readlink_recursive(p);
|
||||
else
|
||||
part->path = strdup (p);
|
||||
|
||||
@@ -120,7 +122,7 @@ struct fstab *fstab_load(const char *path)
|
||||
if(t->version == 2)
|
||||
part->type = strdup(p);
|
||||
else
|
||||
part->device = strdup(p);
|
||||
part->device = readlink_recursive(p);
|
||||
|
||||
if((p = strtok_r(NULL, delim, &saveptr)))
|
||||
fstab_parse_options(p, part);
|
||||
@@ -128,6 +130,15 @@ struct fstab *fstab_load(const char *path)
|
||||
if((p = strtok_r(NULL, delim, &saveptr)))
|
||||
part->options2 = strdup(p);
|
||||
|
||||
// Check device
|
||||
if(!part->device)
|
||||
{
|
||||
ERROR("fstab: device for part %s does not exist!\n", part->path);
|
||||
fstab_destroy_part(part);
|
||||
part = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
list_add(part, &t->parts);
|
||||
++t->count;
|
||||
part = NULL;
|
||||
@@ -229,3 +240,45 @@ void fstab_parse_options(char *opt, struct fstab_part *part)
|
||||
part->options = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
struct fstab *fstab_auto_load(void)
|
||||
{
|
||||
char path[64];
|
||||
path[0] = 0;
|
||||
|
||||
if(access("/mrom.fstab", F_OK) >= 0)
|
||||
strcpy(path, "/mrom.fstab");
|
||||
else
|
||||
{
|
||||
DIR *d = opendir("/");
|
||||
if(!d)
|
||||
{
|
||||
ERROR("Failed to open /\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dirent *dt;
|
||||
while((dt = readdir(d)))
|
||||
{
|
||||
if(dt->d_type != DT_REG)
|
||||
continue;
|
||||
|
||||
if(strncmp(dt->d_name, "fstab.", sizeof("fstab.")-1) == 0)
|
||||
{
|
||||
strcpy(path, "/");
|
||||
strcat(path, dt->d_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
if(path[0] == 0)
|
||||
{
|
||||
ERROR("Failed to find fstab!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ERROR("Loading fstab \"%s\"...\n", path);
|
||||
return fstab_load(path);
|
||||
}
|
||||
|
||||
2
fstab.h
2
fstab.h
@@ -36,10 +36,12 @@ struct fstab
|
||||
};
|
||||
|
||||
struct fstab *fstab_load(const char *path);
|
||||
struct fstab *fstab_auto_load(void);
|
||||
void fstab_destroy(struct fstab *f);
|
||||
void fstab_destroy_part(struct fstab_part *p);
|
||||
void fstab_dump(struct fstab *f);
|
||||
struct fstab_part *fstab_find_by_path(struct fstab *f, const char *path);
|
||||
void fstab_parse_options(char *opt, struct fstab_part *p);
|
||||
void fstab_get_part_dev(struct fstab_part *part, char *out);
|
||||
|
||||
#endif
|
||||
|
||||
68
multirom.c
68
multirom.c
@@ -290,6 +290,10 @@ int multirom_default_status(struct multirom_status *s)
|
||||
s->enable_adb = 0;
|
||||
s->rotation = MULTIROM_DEFAULT_ROTATION;
|
||||
|
||||
s->fstab = fstab_auto_load();
|
||||
if(!s->fstab)
|
||||
return -1;
|
||||
|
||||
char roms_path[256];
|
||||
sprintf(roms_path, "%s/roms/"INTERNAL_ROM_NAME, multirom_dir);
|
||||
DIR *d = opendir(roms_path);
|
||||
@@ -553,12 +557,11 @@ int multirom_scan_partition_for_roms(struct multirom_status *s, struct usb_parti
|
||||
{
|
||||
char path[256];
|
||||
int i;
|
||||
struct stat info;
|
||||
struct dirent *dr;
|
||||
struct multirom_rom **add_roms = NULL;
|
||||
|
||||
sprintf(path, "%s/multirom", p->mount_path);
|
||||
if(stat(path, &info) < 0)
|
||||
if(access(path, F_OK) < 0)
|
||||
return -1;
|
||||
|
||||
DIR *d = opendir(path);
|
||||
@@ -594,9 +597,7 @@ int multirom_scan_partition_for_roms(struct multirom_status *s, struct usb_parti
|
||||
// sort roms
|
||||
qsort(add_roms, list_item_count(add_roms), sizeof(struct multirom_rom*), compare_rom_names);
|
||||
|
||||
//add them to main list
|
||||
for(i = 0; add_roms[i]; ++i)
|
||||
list_add(add_roms[i], &s->roms);
|
||||
list_add_from_list(add_roms, &s->roms);
|
||||
list_clear(&add_roms, NULL);
|
||||
}
|
||||
return 0;
|
||||
@@ -817,6 +818,7 @@ void multirom_free_status(struct multirom_status *s)
|
||||
list_clear(&s->roms, &multirom_free_rom);
|
||||
free(s->curr_rom_part);
|
||||
free(s->int_display_name);
|
||||
fstab_destroy(s->fstab);
|
||||
}
|
||||
|
||||
void multirom_free_rom(void *rom)
|
||||
@@ -1644,12 +1646,9 @@ int multirom_replace_aliases_cmdline(char **s, struct rom_info *i, struct multir
|
||||
if(strlen(*s) == c)
|
||||
return 0;
|
||||
|
||||
struct usb_partition *p = rom->partition;
|
||||
if(!p && (p = multirom_get_data_partition(status)) == NULL)
|
||||
{
|
||||
ERROR("Failed to find ROM's root partition!\n");
|
||||
return 0;
|
||||
}
|
||||
struct fstab_part *data_part = NULL;
|
||||
if(!rom->partition)
|
||||
data_part = fstab_find_by_path(status->fstab, "/data");
|
||||
|
||||
char *buff = malloc(4096);
|
||||
memset(buff, 0, 4096);
|
||||
@@ -1683,25 +1682,39 @@ int multirom_replace_aliases_cmdline(char **s, struct rom_info *i, struct multir
|
||||
// root device. is either "UUID=..." (USB drive) or "/dev/mmcblk0p9" or "/dev/mmcblk0p10"
|
||||
case 'd':
|
||||
{
|
||||
if(!rom->partition)
|
||||
if(data_part)
|
||||
{
|
||||
struct stat info;
|
||||
if(stat("/dev/block/mmcblk0p10", &info) < 0)
|
||||
strcpy(itr_o, "/dev/mmcblk0p9");
|
||||
char *blk = strstr(data_part->device, "/dev/block/");
|
||||
if(blk)
|
||||
{
|
||||
strcpy(itr_o, "/dev/");
|
||||
strcat(itr_o, blk+sizeof("/dev/block/")-1);
|
||||
}
|
||||
else
|
||||
strcpy(itr_o, "/dev/mmcblk0p10");
|
||||
strcpy(itr_o, data_part->device);
|
||||
}
|
||||
else
|
||||
else if(rom->partition)
|
||||
sprintf(itr_o, "UUID=%s", rom->partition->uuid);
|
||||
else
|
||||
ERROR("Failed to set root device\n");
|
||||
break;
|
||||
}
|
||||
// root fs type
|
||||
case 'r':
|
||||
if(!strcmp(p->fs, "ntfs"))
|
||||
strcpy(itr_o, "ntfs-3g");
|
||||
{
|
||||
if(data_part)
|
||||
strcpy(itr_o, data_part->type);
|
||||
else if(rom->partition)
|
||||
{
|
||||
if(!strcmp(rom->partition->fs, "ntfs"))
|
||||
strcpy(itr_o, "ntfs-3g");
|
||||
else
|
||||
strcpy(itr_o, rom->partition->fs);
|
||||
}
|
||||
else
|
||||
strcpy(itr_o, p->fs);
|
||||
ERROR("Failed to set root fs type\n");
|
||||
break;
|
||||
}
|
||||
// root directory, from root of the root device
|
||||
case 's':
|
||||
{
|
||||
@@ -1850,7 +1863,7 @@ int multirom_update_partitions(struct multirom_status *s)
|
||||
part->fs = strndup(t, strchr(t, '"') - t);
|
||||
}
|
||||
|
||||
if(part->fs && (strstr(part->name, "mmcblk") || multirom_mount_usb(part) == 0))
|
||||
if(part->fs && !strstr(part->name, "mmcblk") && multirom_mount_usb(part) == 0)
|
||||
{
|
||||
list_add(part, &s->partitions);
|
||||
ERROR("Found part %s: %s, %s\n", part->name, part->uuid, part->fs);
|
||||
@@ -2061,19 +2074,6 @@ struct usb_partition *multirom_get_partition(struct multirom_status *s, char *uu
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct usb_partition *multirom_get_data_partition(struct multirom_status *s)
|
||||
{
|
||||
int i;
|
||||
struct usb_partition *p;
|
||||
for(i = 0; s->partitions && s->partitions[i]; ++i)
|
||||
{
|
||||
p = s->partitions[i];
|
||||
if(strstr(p->name, "mmcblk") == p->name && strstr(p->fs, "ext") == p->fs)
|
||||
return p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int multirom_search_last_kmsg(const char *expr)
|
||||
{
|
||||
FILE *f = fopen("/proc/last_kmsg", "r");
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "boot_img_hdr.h"
|
||||
#include "util.h"
|
||||
#include "fstab.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -99,6 +100,7 @@ struct multirom_status
|
||||
struct multirom_rom **roms;
|
||||
struct usb_partition **partitions;
|
||||
char *curr_rom_part;
|
||||
struct fstab *fstab;
|
||||
};
|
||||
|
||||
int multirom(void);
|
||||
@@ -141,7 +143,6 @@ int multirom_mount_loop(const char *src, const char *dst, const char *fs, int fl
|
||||
int multirom_copy_log(char *klog);
|
||||
int multirom_scan_partition_for_roms(struct multirom_status *s, struct usb_partition *p);
|
||||
struct usb_partition *multirom_get_partition(struct multirom_status *s, char *uuid);
|
||||
struct usb_partition *multirom_get_data_partition(struct multirom_status *s);
|
||||
int multirom_path_exists(char *base, char *filename);
|
||||
int multirom_search_last_kmsg(const char *expr);
|
||||
struct rom_info *multirom_parse_rom_info(struct multirom_status *s, struct multirom_rom *rom);
|
||||
|
||||
@@ -120,48 +120,6 @@ static void run_multirom(void)
|
||||
} while(restart);
|
||||
}
|
||||
|
||||
static struct fstab *find_load_fstab(void)
|
||||
{
|
||||
char path[64];
|
||||
path[0] = 0;
|
||||
|
||||
if(access("/mrom.fstab", F_OK) >= 0)
|
||||
strcpy(path, "/mrom.fstab");
|
||||
else
|
||||
{
|
||||
DIR *d = opendir("/");
|
||||
if(!d)
|
||||
{
|
||||
ERROR("Failed to open /\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dirent *dt;
|
||||
while((dt = readdir(d)))
|
||||
{
|
||||
if(dt->d_type != DT_REG)
|
||||
continue;
|
||||
|
||||
if(strncmp(dt->d_name, "fstab.", sizeof("fstab.")-1) == 0)
|
||||
{
|
||||
strcpy(path, "/");
|
||||
strcat(path, dt->d_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
if(path[0] == 0)
|
||||
{
|
||||
ERROR("Failed to find fstab!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ERROR("Loading fstab \"%s\"...\n", path);
|
||||
return fstab_load(path);
|
||||
}
|
||||
|
||||
static void mount_and_run(struct fstab *fstab)
|
||||
{
|
||||
struct fstab_part *p = fstab_find_by_path(fstab, "/data");
|
||||
@@ -238,7 +196,7 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fstab = find_load_fstab();
|
||||
fstab = fstab_auto_load();
|
||||
if(!fstab)
|
||||
goto exit;
|
||||
|
||||
|
||||
49
util.c
49
util.c
@@ -404,6 +404,44 @@ uint32_t timespec_diff(struct timespec *f, struct timespec *s)
|
||||
return res;
|
||||
}
|
||||
|
||||
char *readlink_recursive(const char *link)
|
||||
{
|
||||
struct stat info;
|
||||
if(lstat(link, &info) < 0)
|
||||
return NULL;
|
||||
|
||||
char path[256];
|
||||
char buff[256];
|
||||
char *p = (char*)link;
|
||||
|
||||
while(S_ISLNK(info.st_mode))
|
||||
{
|
||||
if(info.st_size >= sizeof(path)-1)
|
||||
{
|
||||
ERROR("readlink_recursive(): Couldn't resolve, too long path.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(readlink(p, buff, info.st_size) != info.st_size)
|
||||
{
|
||||
ERROR("readlink_recursive: readlink() failed on %s!\n", p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buff[info.st_size] = 0;
|
||||
strcpy(path, buff);
|
||||
p = path;
|
||||
|
||||
if(lstat(buff, &info) < 0)
|
||||
{
|
||||
ERROR("readlink_recursive: couldn't do lstat on %s!\n", buff);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return strdup(buff);
|
||||
}
|
||||
|
||||
int list_item_count(listItself list)
|
||||
{
|
||||
void **l = (void**)list;
|
||||
@@ -439,22 +477,21 @@ int list_add_from_list(listItself src_p, ptrToList list_p)
|
||||
void ***list = (void***)list_p;
|
||||
int i, len_src = 0, len_list = 0;
|
||||
|
||||
while(src && src[i])
|
||||
while(src && src[len_src])
|
||||
++len_src;
|
||||
|
||||
if(len_src == 0)
|
||||
return 0;
|
||||
|
||||
while(*list && (*list)[i])
|
||||
while(*list && (*list)[len_list])
|
||||
++len_list;
|
||||
|
||||
*list = realloc(*list, (len_list+len_src+1)*sizeof(void*));
|
||||
++len_src; // for NULL
|
||||
*list = realloc(*list, (len_list+len_src)*sizeof(void*));
|
||||
|
||||
for(i = 0; i < len_src; ++i)
|
||||
(*list)[i+len_list] = src[i];
|
||||
|
||||
(*list)[i] = NULL;
|
||||
return len_src;
|
||||
return len_src-1;
|
||||
}
|
||||
|
||||
int list_rm_opt(int reorder, void *item, ptrToList list_p, callback destroy_callback_p)
|
||||
|
||||
3
util.h
3
util.h
@@ -39,6 +39,7 @@ int write_file(const char *path, const char *value);
|
||||
int remove_dir(const char *dir);
|
||||
int run_cmd(char **cmd);
|
||||
char *run_get_stdout(char **cmd);
|
||||
char *readlink_recursive(const char *link);
|
||||
|
||||
char *parse_string(char *src);
|
||||
uint32_t timespec_diff(struct timespec *f, struct timespec *s);
|
||||
@@ -51,7 +52,7 @@ typedef void* callback;
|
||||
typedef void(*callbackPtr)(void*);
|
||||
|
||||
void list_add(void *item, ptrToList list_p);
|
||||
void list_add_from_list(listItself src_p, ptrToList list_p);
|
||||
int list_add_from_list(listItself src_p, ptrToList list_p);
|
||||
int list_rm(void *item, ptrToList list_p, callback destroy_callback_p);
|
||||
int list_rm_noreorder(void *item, ptrToList list_p, callback destroy_callback_p);
|
||||
int list_rm_opt(int reorder, void *item, ptrToList list_p, callback destroy_callback_p);
|
||||
|
||||
Reference in New Issue
Block a user