summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/syslinux/syslinux/0003-linux-syslinux-implement-install_to_ext2.patch
blob: 8d2fef2d49800f639c334722516ebe71403e5fed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
From 9110cf47d04ca1958d14228908a5c57a23769e7d Mon Sep 17 00:00:00 2001
From: Robert Yang <liezhi.yang@windriver.com>
Date: Wed, 31 Dec 2014 16:17:42 +0800
Subject: [PATCH] linux/syslinux: implement install_to_ext2()

* The handle_adv_on_ext() checks whether we only need update adv.
* The write_to_ext() installs files (ldlinux.sys or ldlinux.c32) to the
  device.
* The install_bootblock() installs the boot block.

Upstream-Status: Submitted

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Tested-by: Du Dolpher <dolpher.du@intel.com>
---
 linux/syslinux.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/linux/syslinux.c b/linux/syslinux.c
index f3727ea..fc5edb1 100755
--- a/linux/syslinux.c
+++ b/linux/syslinux.c
@@ -347,11 +347,90 @@ static int open_ext2_fs(const char *device, const char *subdir)
 fail:
     (void) ext2fs_close(e2fs);
     return -1;
+
+}
+
+/*
+ * Install the boot block on the specified device.
+ * Must be run AFTER file installed.
+ */
+int install_bootblock(int fd, const char *device)
+{
+}
+
+static int handle_adv_on_ext(void)
+{
+}
+
+/* Write files, adv, boot sector */
+static int write_to_ext(const char *filename, const char *str, int length,
+                        int i_flags, int dev_fd, const char *subdir)
+{
 }
 
 /* The install func for ext2, ext3 and ext4 */
 static int install_to_ext2(const char *device, int dev_fd, const char *subdir)
 {
+    int         retval;
+    ext2_ino_t  oldino;
+
+    const char *file = "ldlinux.sys";
+    const char *oldfile = "extlinux.sys";
+    const char *c32file = "ldlinux.c32";
+
+    /* Handle the adv */
+    if (handle_adv_on_ext() < 0) {
+        fprintf(stderr, "%s: error while handling ADV on %s\n",
+                program, device);
+        retval = 1;
+        goto fail;
+    }
+
+    /* Return if only need update the adv */
+    if (opt.update_only == -1) {
+        return ext2fs_close(e2fs);
+    }
+
+    /* Write ldlinux.sys, adv, boot sector */
+    retval = write_to_ext(file, (const char _force *)boot_image,
+                boot_image_len, EXT2_IMMUTABLE_FL, dev_fd, subdir);
+    if (retval) {
+        fprintf(stderr, "%s: ERROR: while writing: %s.\n",
+                program, file);
+        goto fail;
+    }
+
+    /* Write ldlinux.c32 */
+    retval = write_to_ext(c32file,
+                (const char _force *)syslinux_ldlinuxc32,
+                syslinux_ldlinuxc32_len, 0, dev_fd, subdir);
+    if (retval) {
+        fprintf(stderr, "%s: ERROR: while writing: %s.\n",
+                program, c32file);
+        goto fail;
+    }
+
+    /* Look if we have the extlinux.sys and remove it*/
+    retval = ext2fs_namei(e2fs, root, cwd, oldfile, &oldino);
+    if (retval == 0) {
+        retval = ext2fs_unlink(e2fs, cwd, oldfile, oldino, 0);
+        if (retval) {
+            fprintf(stderr, "%s: ERROR: failed to unlink: %s\n",
+                program, oldfile);
+            goto fail;
+        }
+    } else {
+        retval = 0;
+    }
+
+    sync();
+    retval = install_bootblock(dev_fd, device);
+    close(dev_fd);
+    sync();
+
+fail:
+    (void) ext2fs_close(e2fs);
+    return retval;
 }
 
 int main(int argc, char *argv[])