storage: Support operating on raw partitions

Most devices has partitions named modemst1, modemst2, fsg and fsc
backing the rmtfs. Add a new argument '-P' to get the storage
implementation to use these partitions directly instead of files.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson 2019-07-17 12:21:05 -07:00
parent c35633ab23
commit 42edb9c07a
3 changed files with 31 additions and 10 deletions

10
rmtfs.c
View File

@ -449,18 +449,24 @@ static int run_rmtfs(void)
int main(int argc, char **argv)
{
bool use_partitions = false;
bool read_only = false;
int ret;
int option;
const char *storage_root = NULL;
while ((option = getopt(argc, argv, "o:rv")) != -1) {
while ((option = getopt(argc, argv, "o:Prv")) != -1) {
switch (option) {
/* -o sets the directory where EFS images are stored. */
case 'o':
storage_root = optarg;
break;
/* -P to find and use raw EFS partitions */
case 'P':
use_partitions = true;
break;
/* -r to avoid writing to storage */
case 'r':
read_only = true;
@ -481,7 +487,7 @@ int main(int argc, char **argv)
if (!rmem)
return 1;
ret = storage_init(storage_root, read_only);
ret = storage_init(storage_root, read_only, use_partitions);
if (ret) {
fprintf(stderr, "failed to initialize storage system\n");
goto close_rmtfs_mem;

View File

@ -25,7 +25,7 @@ ssize_t rmtfs_mem_write(struct rmtfs_mem *rmem, unsigned long phys_address, cons
struct rmtfd;
int storage_init(const char *storage_root, bool read_only);
int storage_init(const char *storage_root, bool read_only, bool use_partitions);
struct rmtfd *storage_open(unsigned node, const char *path);
struct rmtfd *storage_get(unsigned node, int caller_id);
void storage_close(struct rmtfd *rmtfd);

View File

@ -11,11 +11,14 @@
#define MAX_CALLERS 10
#define STORAGE_MAX_SIZE (16 * 1024 * 1024)
#define BY_PARTLABEL_PATH "/dev/disk/by-partlabel"
#define MIN(x, y) ((x) < (y) ? (x) : (y))
struct partition {
const char *path;
const char *actual;
const char *partlabel;
};
struct rmtfd {
@ -31,12 +34,13 @@ struct rmtfd {
static const char *storage_dir = "/boot";
static int storage_read_only;
static int storage_use_partitions;
static const struct partition partition_table[] = {
{ "/boot/modem_fs1", "modem_fs1" },
{ "/boot/modem_fs2", "modem_fs2" },
{ "/boot/modem_fsc", "modem_fsc" },
{ "/boot/modem_fsg", "modem_fsg" },
{ "/boot/modem_fs1", "modem_fs1", "modemst1" },
{ "/boot/modem_fs2", "modem_fs2", "modemst2" },
{ "/boot/modem_fsc", "modem_fsc", "fsc" },
{ "/boot/modem_fsg", "modem_fsg", "fsg" },
{}
};
@ -44,13 +48,18 @@ static struct rmtfd rmtfds[MAX_CALLERS];
static int storage_populate_shadow_buf(struct rmtfd *rmtfd, const char *file);
int storage_init(const char *storage_root, bool read_only)
int storage_init(const char *storage_root, bool read_only, bool use_partitions)
{
int i;
if (storage_root)
storage_dir = storage_root;
if (use_partitions) {
storage_dir = BY_PARTLABEL_PATH;
storage_use_partitions = true;
}
storage_read_only = read_only;
for (i = 0; i < MAX_CALLERS; i++) {
@ -66,6 +75,7 @@ struct rmtfd *storage_open(unsigned node, const char *path)
char *fspath;
const struct partition *part;
struct rmtfd *rmtfd = NULL;
const char *file;
size_t pathlen;
int saved_errno;
int ret;
@ -100,9 +110,14 @@ found:
return NULL;
}
pathlen = strlen(storage_dir) + strlen(part->actual) + 2;
if (storage_use_partitions)
file = part->partlabel;
else
file = part->actual;
pathlen = strlen(storage_dir) + strlen(file) + 2;
fspath = alloca(pathlen);
snprintf(fspath, pathlen, "%s/%s", storage_dir, part->actual);
snprintf(fspath, pathlen, "%s/%s", storage_dir, file);
if (!storage_read_only) {
fd = open(fspath, O_RDWR);
if (fd < 0) {