OSDN Git Service

Move to new Fstab class
authorTom Cherry <tomcherry@google.com>
Wed, 30 Jan 2019 01:54:07 +0000 (17:54 -0800)
committerTom Cherry <tomcherry@google.com>
Wed, 30 Jan 2019 01:54:07 +0000 (17:54 -0800)
Test: treehugger
Change-Id: I1873022abde51b71b49e8d89bdaada044530987a

boot_control_copy/bootinfo.cpp

index aa7643a..e4c58b0 100644 (file)
 
 // Open the appropriate fstab file and fallback to /fstab.device if
 // that's what's being used.
-static struct fstab *open_fstab(void)
+static bool open_fstab(Fstab* fstab)
 {
-  struct fstab *fstab = fs_mgr_read_fstab_default();
-  if (fstab != NULL)
-    return fstab;
-
-  fstab = fs_mgr_read_fstab("/fstab.device");
-  return fstab;
+  return ReadDefaultFstab(fstab) || ReadFstabFromFile("/fstab.device", fstab);
 }
 
 int boot_info_open_partition(const char *name, uint64_t *out_size, int flags)
 {
   char *path;
   int fd;
-  struct fstab *fstab;
-  struct fstab_rec *record;
 
   // We can't use fs_mgr to look up |name| because fstab doesn't list
   // every slot partition (it uses the slotselect option to mask the
@@ -70,30 +63,28 @@ int boot_info_open_partition(const char *name, uint64_t *out_size, int flags)
   // by trawling /sys/block looking for the appropriate sibling of
   // misc and then finding an entry in /dev matching the sysfs entry.
 
-  fstab = open_fstab();
-  if (fstab == NULL)
+  Fstab fstab;
+  if (!open_fstab(&fstab)) {
     return -1;
-  record = fs_mgr_get_entry_for_mount_point(fstab, "/misc");
-  if (record == NULL) {
-    fs_mgr_free_fstab(fstab);
+  }
+  auto record = GetEntryForMountPoint(&fstab, "/misc");
+  if (record == nullptr) {
     return -1;
   }
   if (strcmp(name, "misc") == 0) {
-    path = strdup(record->blk_device);
+    path = strdup(record->blk_device.c_str());
   } else {
     size_t trimmed_len, name_len;
-    const char *end_slash = strrchr(record->blk_device, '/');
+    const char *end_slash = strrchr(record->blk_device.c_str(), '/');
     if (end_slash == NULL) {
-      fs_mgr_free_fstab(fstab);
       return -1;
     }
-    trimmed_len = end_slash - record->blk_device + 1;
+    trimmed_len = end_slash - record->blk_device.c_str() + 1;
     name_len = strlen(name);
     path = static_cast<char *>(calloc(trimmed_len + name_len + 1, 1));
-    strncpy(path, record->blk_device, trimmed_len);
+    strncpy(path, record->blk_device.c_str(), trimmed_len);
     strncpy(path + trimmed_len, name, name_len);
   }
-  fs_mgr_free_fstab(fstab);
 
   fd = open(path, flags);
   free(path);