storage: Allow specifying the storage directory

Enable the specification of storage paths other than /boot, using
a new -o command line argument. Getoptify the command line arguments
for better processing.
This commit is contained in:
Evan Green 2018-12-07 16:03:43 -08:00 committed by Bjorn Andersson
parent 08d20f1646
commit cfb76ff6ee
3 changed files with 38 additions and 11 deletions

23
rmtfs.c
View File

@ -448,15 +448,32 @@ static int run_rmtfs(void)
int main(int argc, char **argv)
{
int ret;
int option;
const char *storage_root = NULL;
if (argc == 2 && strcmp(argv[1], "-v") == 0)
dbgprintf_enabled = true;
while ((option = getopt(argc, argv, "o:v")) != -1) {
switch (option) {
/* -o sets the directory where EFS images are stored. */
case 'o':
storage_root = optarg;
break;
/* -v is for verbose */
case 'v':
dbgprintf_enabled = 1;
break;
case '?':
fprintf(stderr, "Unknown option: -%c\n", option);
return 1;
}
}
rmem = rmtfs_mem_open();
if (!rmem)
return 1;
ret = storage_open();
ret = storage_open(storage_root);
if (ret) {
fprintf(stderr, "failed to initialize storage system\n");
goto close_rmtfs_mem;

View File

@ -23,7 +23,7 @@ void rmtfs_mem_free(struct rmtfs_mem *rmem);
ssize_t rmtfs_mem_read(struct rmtfs_mem *rmem, unsigned long phys_address, void *buf, ssize_t len);
ssize_t rmtfs_mem_write(struct rmtfs_mem *rmem, unsigned long phys_address, const void *buf, ssize_t len);
int storage_open(void);
int storage_open(const char *storage_root);
int storage_get(unsigned node, const char *path);
int storage_put(unsigned node, int caller_id);
int storage_get_handle(unsigned node, int caller_id);

View File

@ -22,20 +22,25 @@ struct caller {
const struct partition *partition;
};
static const char *storage_dir = "/boot";
static const struct partition partition_table[] = {
{ "/boot/modem_fs1", "/boot/modem_fs1" },
{ "/boot/modem_fs2", "/boot/modem_fs2" },
{ "/boot/modem_fsc", "/boot/modem_fsc" },
{ "/boot/modem_fsg", "/boot/modem_fsg" },
{ "/boot/modem_fs1", "modem_fs1" },
{ "/boot/modem_fs2", "modem_fs2" },
{ "/boot/modem_fsc", "modem_fsc" },
{ "/boot/modem_fsg", "modem_fsg" },
{}
};
static struct caller caller_handles[MAX_CALLERS];
int storage_open(void)
int storage_open(const char *storage_root)
{
int i;
if (storage_root)
storage_dir = storage_root;
for (i = 0; i < MAX_CALLERS; i++) {
caller_handles[i].id = i;
caller_handles[i].fd = -1;
@ -46,8 +51,10 @@ int storage_open(void)
int storage_get(unsigned node, const char *path)
{
char *fspath;
const struct partition *part;
struct caller *caller = NULL;
size_t pathlen;
int saved_errno;
int fd;
int i;
@ -80,11 +87,14 @@ found:
return -EBUSY;
}
fd = open(part->actual, O_RDWR);
pathlen = strlen(storage_dir) + strlen(part->actual) + 2;
fspath = alloca(pathlen);
snprintf(fspath, pathlen, "%s/%s", storage_dir, part->actual);
fd = open(fspath, O_RDWR);
if (fd < 0) {
saved_errno = errno;
fprintf(stderr, "[storage] failed to open '%s' (requested '%s'): %s\n",
part->actual, part->path, strerror(saved_errno));
fspath, part->path, strerror(saved_errno));
return -saved_errno;
}