summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/syslinux/syslinux/0004-linux-syslinux-add-ext_file_read-and-ext_file_write.patch
blob: 0a3296915444826e2836d63d54146c07390b3eca (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
From 1957fc6c069493c6789557936adb675f5e7e51ba Mon Sep 17 00:00:00 2001
From: Robert Yang <liezhi.yang@windriver.com>
Date: Wed, 31 Dec 2014 16:43:37 +0800
Subject: [PATCH] linux/syslinux: add ext_file_read() and ext_file_write()

Will use them to read and write on the extX device.

Upstream-Status: Submitted

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

diff --git a/linux/syslinux.c b/linux/syslinux.c
index fc5edb1..c7c1994 100755
--- a/linux/syslinux.c
+++ b/linux/syslinux.c
@@ -350,6 +350,68 @@ fail:
 
 }
 
+/* Read from an ext2_file */
+static int ext_file_read(ext2_file_t e2_file, void *buf, size_t count,
+                        off_t offset, const char *msg)
+{
+    int                 retval;
+    char                *ptr = (char *) buf;
+    unsigned int        got = 0;
+    size_t              done = 0;
+
+    /* Always lseek since e2_file is uncontrolled by this func */
+    if (ext2fs_file_lseek(e2_file, offset, EXT2_SEEK_SET, NULL)) {
+        fprintf(stderr, "%s: ext2fs_file_lseek() failed.\n",
+            program);
+        return -1;
+    }
+
+    while (1) {
+        retval = ext2fs_file_read(e2_file, ptr, count, &got);
+        if (retval) {
+            fprintf(stderr, "%s: error while reading %s\n",
+                    program, msg);
+            return -1;
+        }
+        count -= got;
+        ptr += got;
+        done += got;
+        if (got == 0 || count == 0)
+            break;
+    }
+
+    return done;
+}
+
+/* Write to an ext2_file */
+static int ext_file_write(ext2_file_t e2_file, const void *buf, size_t count,
+                        off_t offset)
+{
+    const char          *ptr = (const char *) buf;
+    unsigned int        written = 0;
+    size_t              done = 0;
+
+    /* Always lseek since e2_file is uncontrolled by this func */
+    if (ext2fs_file_lseek(e2_file, offset, EXT2_SEEK_SET, NULL)) {
+            fprintf(stderr, "%s: ext2fs_file_lseek() failed.\n",
+                program);
+            return -1;
+    }
+
+    while (count > 0) {
+        if (ext2fs_file_write(e2_file, ptr, count, &written)) {
+            fprintf(stderr, "%s: failed to write syslinux adv.\n",
+                    program);
+            return -1;
+        }
+        count -= written;
+        ptr += written;
+        done += written;
+    }
+
+    return done;
+}
+
 /*
  * Install the boot block on the specified device.
  * Must be run AFTER file installed.