blob: 1a4a4e37556bb0dd90d109eb43306941aa67c0bc [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001From a469ce05055c44fdca1ca094ff3a735cc059480d Mon Sep 17 00:00:00 2001
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002From: Robert Yang <liezhi.yang@windriver.com>
3Date: Wed, 31 Dec 2014 16:01:55 +0800
Patrick Williams92b42cb2022-09-03 06:53:57 -05004Subject: [PATCH] linux/syslinux: support ext2/3/4 device
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
6* Support ext2/3/4 deivce.
7* The open_ext2_fs() checks whether it is an ext2/3/4 device,
8 do the ext2/3/4 installation (install_to_ext2()) if yes, otherwise go
9 on to the fat/ntfs.
10* The ext2/3/4 support doesn't require root privileges since it doesn't need
11 mount (but write permission is required).
12
Andrew Geissler6ce62a22020-11-30 19:58:47 -060013Upstream-Status: Submitted [https://www.syslinux.org/archives/2015-January/023039.html]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
15Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
16Tested-by: Du Dolpher <dolpher.du@intel.com>
17---
18 linux/syslinux.c | 36 ++++++++++++++++++++++++++++++++++++
19 1 file changed, 36 insertions(+)
20
21diff --git a/linux/syslinux.c b/linux/syslinux.c
Patrick Williams92b42cb2022-09-03 06:53:57 -050022index 46d5624..1cc276b 100755
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023--- a/linux/syslinux.c
24+++ b/linux/syslinux.c
Patrick Williams92b42cb2022-09-03 06:53:57 -050025@@ -257,6 +257,23 @@ int do_open_file(char *name)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026 return fd;
27 }
28
29+/*
30+ * Check whether the device contains an ext2, ext3 or ext4 fs and open it if
31+ * true.
32+ * return value:
33+ * 0: Everything is OK
34+ * 1: Not an ext2, ext3 or ext4
35+ * -1: unexpected error
36+ */
37+static int open_ext2_fs(const char *device, const char *subdir)
38+{
39+}
40+
41+/* The install func for ext2, ext3 and ext4 */
42+static int install_to_ext2(const char *device, int dev_fd, const char *subdir)
43+{
44+}
45+
46 int main(int argc, char *argv[])
47 {
48 static unsigned char sectbuf[SECTOR_SIZE];
Patrick Williams92b42cb2022-09-03 06:53:57 -050049@@ -314,6 +331,24 @@ int main(int argc, char *argv[])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050 die("can't combine an offset with a block device");
51 }
52
53+ /*
54+ * Check if it is an ext2, ext3 or ext4
55+ */
56+ rv = open_ext2_fs(opt.device, subdir);
57+ if (rv == 0) {
58+ if (install_to_ext2(opt.device, dev_fd, subdir)) {
59+ fprintf(stderr, "%s: installation failed\n", opt.device);
60+ exit(1);
61+ }
62+ return 0;
63+ /* Unexpected errors */
64+ } else if (rv == -1) {
65+ exit(1);
66+ }
67+
68+ /* Reset rv */
69+ rv = 0;
70+
71 xpread(dev_fd, sectbuf, SECTOR_SIZE, opt.offset);
72 fsync(dev_fd);
73
Patrick Williams92b42cb2022-09-03 06:53:57 -050074@@ -323,6 +358,7 @@ int main(int argc, char *argv[])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 */
76 if ((errmsg = syslinux_check_bootsect(sectbuf, &fs_type))) {
77 fprintf(stderr, "%s: %s\n", opt.device, errmsg);
78+ fprintf(stderr, "%s: supported fs: fat/ntfs/ext2/ex3/ext4\n", program);
79 exit(1);
80 }
81