blob: 57cdaf437bb600ac3c0fa0152d1fb1c1541d94e6 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001From 906205015601d5d1190e7326f51ea4316a74a479 Mon Sep 17 00:00:00 2001
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002From: Robert Yang <liezhi.yang@windriver.com>
3Date: Fri, 2 Jan 2015 12:18:02 +0800
Patrick Williams92b42cb2022-09-03 06:53:57 -05004Subject: [PATCH] linux/syslinux: implement ext_construct_sectmap_fs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
6The ext_construct_sectmap_fs() constucts the sector according to the
7bmap.
8
9Upstream-Status: Submitted
10
11Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
12Tested-by: Du Dolpher <dolpher.du@intel.com>
13---
Patrick Williams92b42cb2022-09-03 06:53:57 -050014 linux/syslinux.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015 1 file changed, 50 insertions(+)
16
17diff --git a/linux/syslinux.c b/linux/syslinux.c
Patrick Williams92b42cb2022-09-03 06:53:57 -050018index 7a20fe6..4e43921 100755
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019--- a/linux/syslinux.c
20+++ b/linux/syslinux.c
Patrick Williams92b42cb2022-09-03 06:53:57 -050021@@ -422,10 +422,60 @@ int install_bootblock(int fd, const char *device)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022 {
23 }
24
25+/* The file's block count */
26+int block_count = 0;
27+static int get_block_count(ext2_filsys fs EXT2FS_ATTR((unused)),
28+ blk64_t *blocknr EXT2FS_ATTR((unused)),
29+ e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
30+ blk64_t ref_block EXT2FS_ATTR((unused)),
31+ int ref_offset EXT2FS_ATTR((unused)),
32+ void *private EXT2FS_ATTR((unused)))
33+{
34+ block_count++;
35+ return 0;
36+}
37+
38 /* Construct the boot file map */
39 int ext_construct_sectmap_fs(ext2_filsys fs, ext2_ino_t newino,
40 sector_t *sectors, int nsect)
41 {
42+ blk64_t pblk, blksize, blk = 0;
43+ sector_t sec;
44+ unsigned int i;
45+ int retval;
46+
47+ blksize = fs->blocksize;
48+ blksize >>= SECTOR_SHIFT;
49+
50+ /* Get the total blocks no. */
51+ retval = ext2fs_block_iterate3(fs, newino, BLOCK_FLAG_READ_ONLY,
52+ NULL, get_block_count, NULL);
53+ if (retval) {
54+ fprintf(stderr, "%s: ERROR: ext2fs_block_iterate3() failed.\n", program);
55+ return -1;
56+ }
57+
58+ while (nsect) {
59+ if (block_count-- == 0)
60+ break;
61+
62+ /* Get the physical block no. (bmap) */
63+ retval = ext2fs_bmap2(fs, newino, 0, 0, 0, blk, 0, &pblk);
64+ if (retval) {
65+ fprintf(stderr, "%s: ERROR: ext2fs_bmap2() failed.\n", program);
66+ return -1;
67+ }
68+
69+ blk++;
70+ sec = (sector_t)pblk * blksize;
71+ for (i = 0; i < blksize; i++) {
72+ *sectors++ = sec++;
73+ if (! --nsect)
74+ break;
75+ }
76+ }
77+
78+ return 0;
79 }
80
81 static int handle_adv_on_ext(void)