1 From 35d3842cc4b930c5102eed2921e0189b7f4fd069 Mon Sep 17 00:00:00 2001
2 From: Robert Yang <liezhi.yang@windriver.com>
3 Date: Wed, 31 Dec 2014 16:43:37 +0800
4 Subject: [PATCH 4/9] linux/syslinux: add ext_file_read() and ext_file_write()
6 Will use them to read and write on the extX device.
8 Upstream-Status: Submitted
10 Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
11 Tested-by: Du Dolpher <dolpher.du@intel.com>
13 linux/syslinux.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14 1 file changed, 62 insertions(+)
16 diff --git a/linux/syslinux.c b/linux/syslinux.c
17 index 45f080d..247c86a 100755
18 --- a/linux/syslinux.c
19 +++ b/linux/syslinux.c
20 @@ -349,6 +349,68 @@ fail:
24 +/* Read from an ext2_file */
25 +static int ext_file_read(ext2_file_t e2_file, void *buf, size_t count,
26 + off_t offset, const char *msg)
29 + char *ptr = (char *) buf;
30 + unsigned int got = 0;
33 + /* Always lseek since e2_file is uncontrolled by this func */
34 + if (ext2fs_file_lseek(e2_file, offset, EXT2_SEEK_SET, NULL)) {
35 + fprintf(stderr, "%s: ext2fs_file_lseek() failed.\n",
41 + retval = ext2fs_file_read(e2_file, ptr, count, &got);
43 + fprintf(stderr, "%s: error while reading %s\n",
50 + if (got == 0 || count == 0)
57 +/* Write to an ext2_file */
58 +static int ext_file_write(ext2_file_t e2_file, const void *buf, size_t count,
61 + const char *ptr = (const char *) buf;
62 + unsigned int written = 0;
65 + /* Always lseek since e2_file is uncontrolled by this func */
66 + if (ext2fs_file_lseek(e2_file, offset, EXT2_SEEK_SET, NULL)) {
67 + fprintf(stderr, "%s: ext2fs_file_lseek() failed.\n",
73 + if (ext2fs_file_write(e2_file, ptr, count, &written)) {
74 + fprintf(stderr, "%s: failed to write syslinux adv.\n",
87 * Install the boot block on the specified device.
88 * Must be run AFTER file installed.