diff options
author | Bowgo Tsai <bowgotsai@google.com> | 2019-01-07 15:30:27 +0800 |
---|---|---|
committer | Bowgo Tsai <bowgotsai@google.com> | 2019-01-08 17:56:56 +0800 |
commit | fa416f9bec39a2ef25d5b83070e7ca0e450a2549 (patch) | |
tree | 53768a5d39496daa56518e6711e42229240d52e8 /fs_mgr/fs_mgr_fstab.cpp | |
parent | 2fc9f626073a4977969de6b33605d01f082091d4 (diff) | |
download | system_core-fa416f9bec39a2ef25d5b83070e7ca0e450a2549.tar.gz system_core-fa416f9bec39a2ef25d5b83070e7ca0e450a2549.tar.bz2 system_core-fa416f9bec39a2ef25d5b83070e7ca0e450a2549.zip |
Support host build for libdm and libfstab
The host builds for both libs are needed for libfs_avb host unit test.
Also replaces strlcat()/strlcpy() with snprintf() because the former
doesn't have a glibc version. Or switch char* to std::string*.
Bug: 112103720
Bug: 117960205
Test: m libdm ARCH=x86_64
Test: m libfstab ARCH=x86_64
Test: atest libdm_test
Test: atest fs_mgr_unit_test
Test: boot a device
Change-Id: Id9b92b5286b8ed9ab0d80f18ab5802dcfeb83dfa
Diffstat (limited to 'fs_mgr/fs_mgr_fstab.cpp')
-rw-r--r-- | fs_mgr/fs_mgr_fstab.cpp | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index e0891eb67..53b47be6d 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -209,17 +209,12 @@ static bool read_dt_file(const std::string& file_name, std::string* dt_value) } static uint64_t parse_flags(char* flags, struct flag_list* fl, struct fs_mgr_flag_values* flag_vals, - char* fs_options, int fs_options_len) { + std::string* fs_options) { uint64_t f = 0; int i; char *p; char *savep; - /* initialize fs_options to the null string */ - if (fs_options && (fs_options_len > 0)) { - fs_options[0] = '\0'; - } - p = strtok_r(flags, ",", &savep); while (p) { /* Look for the flag "p" in the flag list "fl" @@ -356,26 +351,20 @@ static uint64_t parse_flags(char* flags, struct flag_list* fl, struct fs_mgr_fla if (!fl[i].name) { if (fs_options) { - /* It's not a known flag, so it must be a filesystem specific - * option. Add it to fs_options if it was passed in. - */ - strlcat(fs_options, p, fs_options_len); - strlcat(fs_options, ",", fs_options_len); + // It's not a known flag, so it must be a filesystem specific + // option. Add it to fs_options if it was passed in. + if (!fs_options->empty()) { + fs_options->append(","); // appends a comma if not the first + } + fs_options->append(p); } else { - /* fs_options was not passed in, so if the flag is unknown - * it's an error. - */ + // fs_options was not passed in, so if the flag is unknown it's an error. LERROR << "Warning: unknown flag " << p; } } p = strtok_r(NULL, ",", &savep); } - if (fs_options && fs_options[0]) { - /* remove the last trailing comma from the list of options */ - fs_options[strlen(fs_options) - 1] = '\0'; - } - return f; } @@ -513,8 +502,6 @@ static bool fs_mgr_read_fstab_file(FILE* fstab_file, bool proc_mounts, Fstab* fs char *save_ptr, *p; Fstab fstab; struct fs_mgr_flag_values flag_vals; -#define FS_OPTIONS_LEN 1024 - char tmp_fs_options[FS_OPTIONS_LEN]; while ((len = getline(&line, &alloc_len, fstab_file)) != -1) { /* if the last character is a newline, shorten the string by 1 byte */ @@ -555,13 +542,7 @@ static bool fs_mgr_read_fstab_file(FILE* fstab_file, bool proc_mounts, Fstab* fs LERROR << "Error parsing mount_flags"; goto err; } - tmp_fs_options[0] = '\0'; - entry.flags = parse_flags(p, mount_flags, NULL, tmp_fs_options, FS_OPTIONS_LEN); - - /* fs_options are optional */ - if (tmp_fs_options[0]) { - entry.fs_options = tmp_fs_options; - } + entry.flags = parse_flags(p, mount_flags, nullptr, &entry.fs_options); // For /proc/mounts, ignore everything after mnt_freq and mnt_passno if (proc_mounts) { @@ -570,7 +551,7 @@ static bool fs_mgr_read_fstab_file(FILE* fstab_file, bool proc_mounts, Fstab* fs LERROR << "Error parsing fs_mgr_options"; goto err; } - entry.fs_mgr_flags.val = parse_flags(p, fs_mgr_flags, &flag_vals, NULL, 0); + entry.fs_mgr_flags.val = parse_flags(p, fs_mgr_flags, &flag_vals, nullptr); entry.key_loc = std::move(flag_vals.key_loc); entry.key_dir = std::move(flag_vals.key_dir); |