1From c28aae8bd381f77e66e6bac79761df7a484b054c Mon Sep 17 00:00:00 2001
2From: Robert Yang <liezhi.yang@windriver.com>
3Date: Fri, 2 Jan 2015 12:28:35 +0800
4Subject: [PATCH] linux/syslinux: implement install_bootblock()
5
6Refer to the install_bootblock() in extlinux/main.c to make
7linux/syslinux.c's install_bootblock() which only supports ext2/3/4.
8
9Upstream-Status: Submitted
10
11Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
12Tested-by: Du Dolpher <dolpher.du@intel.com>
13---
14 linux/syslinux.c | 20 ++++++++++++++++++++
15 1 file changed, 20 insertions(+)
16
17diff --git a/linux/syslinux.c b/linux/syslinux.c
18index 4e43921..93ed880 100755
19--- a/linux/syslinux.c
20+++ b/linux/syslinux.c
21@@ -420,6 +420,26 @@ static int ext_file_write(ext2_file_t e2_file, const void *buf, size_t count,
22  */
23 int install_bootblock(int fd, const char *device)
24 {
25+    struct ext2_super_block sb;
26+
27+    if (xpread(fd, &sb, sizeof sb, EXT2_SUPER_OFFSET + opt.offset) != sizeof sb) {
28+        perror("reading superblock");
29+        return 1;
30+    }
31+
32+    if (sb.s_magic != EXT2_SUPER_MAGIC) {
33+        fprintf(stderr,
34+                "no ext2/3/4 superblock found on %s\n", device);
35+        return 1;
36+    }
37+
38+    if (xpwrite(fd, syslinux_bootsect, syslinux_bootsect_len, 0)
39+        != (signed)syslinux_bootsect_len) {
40+        perror("writing bootblock");
41+        return 1;
42+    }
43+
44+    return 0;
45 }
46
47 /* The file's block count */
48