grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/7] android_bootimg: Implement dir


From: Shea Levy
Subject: [PATCH 2/7] android_bootimg: Implement dir
Date: Tue, 26 Jan 2016 13:51:17 -0500

---
 grub-core/fs/android_bootimg.c | 43 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/grub-core/fs/android_bootimg.c b/grub-core/fs/android_bootimg.c
index f6b2283..de49303 100644
--- a/grub-core/fs/android_bootimg.c
+++ b/grub-core/fs/android_bootimg.c
@@ -60,7 +60,48 @@ static grub_err_t
 grub_android_bootimg_dir (grub_device_t device, const char *path_in,
                grub_fs_dir_hook_t hook, void *hook_data)
 {
-  return GRUB_ERR_NOT_IMPLEMENTED_YET;
+  struct boot_img_hdr hd;
+  if (grub_disk_read (device->disk, 0, 0, sizeof hd, &hd))
+    goto fail;
+
+  if (grub_memcmp (hd.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE))
+    goto fail;
+
+  if (hd.unused[0] || hd.unused[1])
+    goto fail;
+
+  const struct grub_dirhook_info info = {
+    .dir = 0,
+    .mtimeset = 0,
+    .case_insensitive = 0,
+    .inodeset = 0,
+    .mtime = 0,
+    .inode = 0
+  };
+
+  if (!grub_strcmp(path_in, "/")) {
+    return GRUB_ERR_FILE_NOT_FOUND;
+  }
+
+  if (hook ("kernel", &info, hook_data)) {
+    return grub_errno;
+  }
+
+  if (hook ("info", &info, hook_data)) {
+    return grub_errno;
+  }
+
+  if (hd.ramdisk_size != 0) {
+    if (hook ("ramdisk", &info, hook_data)) {
+      return grub_errno;
+    }
+  }
+
+  return GRUB_ERR_NONE;
+
+fail:
+  return grub_error (GRUB_ERR_BAD_FS, "%s is not an android bootimg",
+                     device->disk->name);
 }
 
 static grub_err_t
-- 
2.7.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]