summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/syslinux/syslinux/0007-linux-syslinux-implement-ext_construct_sectmap_fs.patch
blob: 391381191758febd8a620a429478768651823919 (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
From a95b831e18dd123f859bc5e6c4cecdcc0184ee37 Mon Sep 17 00:00:00 2001
From: Robert Yang <liezhi.yang@windriver.com>
Date: Fri, 2 Jan 2015 12:18:02 +0800
Subject: [PATCH 7/9] linux/syslinux: implement ext_construct_sectmap_fs()

The ext_construct_sectmap_fs() constucts the sector according to the
bmap.

Upstream-Status: Submitted

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

diff --git a/linux/syslinux.c b/linux/syslinux.c
index f0c97a8..c741750 100755
--- a/linux/syslinux.c
+++ b/linux/syslinux.c
@@ -421,10 +421,60 @@ int install_bootblock(int fd, const char *device)
 {
 }
 
+/* The file's block count */
+int block_count = 0;
+static int get_block_count(ext2_filsys fs EXT2FS_ATTR((unused)),
+			     blk64_t *blocknr EXT2FS_ATTR((unused)),
+			     e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+			     blk64_t ref_block EXT2FS_ATTR((unused)),
+			     int ref_offset EXT2FS_ATTR((unused)),
+			     void *private EXT2FS_ATTR((unused)))
+{
+    block_count++;
+    return 0;
+}
+
 /* Construct the boot file map */
 int ext_construct_sectmap_fs(ext2_filsys fs, ext2_ino_t newino,
                                 sector_t *sectors, int nsect)
 {
+    blk64_t             pblk, blksize, blk = 0;
+    sector_t            sec;
+    unsigned int        i;
+    int                 retval;
+
+    blksize = fs->blocksize;
+    blksize >>= SECTOR_SHIFT;
+
+    /* Get the total blocks no. */
+    retval = ext2fs_block_iterate3(fs, newino, BLOCK_FLAG_READ_ONLY,
+            NULL, get_block_count, NULL);
+    if (retval) {
+        fprintf(stderr, "%s: ERROR: ext2fs_block_iterate3() failed.\n", program);
+        return -1;
+    }
+
+    while (nsect) {
+        if (block_count-- == 0)
+            break;
+
+        /* Get the physical block no. (bmap) */
+        retval = ext2fs_bmap2(fs, newino, 0, 0, 0, blk, 0, &pblk);
+        if (retval) {
+            fprintf(stderr, "%s: ERROR: ext2fs_bmap2() failed.\n", program);
+            return -1;
+        }
+
+        blk++;
+        sec = (sector_t)pblk * blksize;
+        for (i = 0; i < blksize; i++) {
+            *sectors++ = sec++;
+            if (! --nsect)
+                break;
+        }
+    }
+
+    return 0;
 }
 
 static int handle_adv_on_ext(void)
-- 
1.9.1