]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - fs/fs_internal.c
1 // SPDX-License-Identifier: GPL-2.0
3 * 2017 by Marek Behun <marek.behun@nic.cz>
5 * Derived from code in ext4/dev.c, which was based on reiserfs/dev.c
15 int fs_devread(struct blk_desc
*blk
, struct disk_partition
*partition
,
16 lbaint_t sector
, int byte_offset
, int byte_len
, char *buf
)
20 ALLOC_CACHE_ALIGN_BUFFER(char, sec_buf
, (blk
? blk
->blksz
: 0));
22 printf("** Invalid Block Device Descriptor (NULL)\n");
25 log2blksz
= blk
->log2blksz
;
27 /* Check partition boundaries */
28 if ((sector
+ ((byte_offset
+ byte_len
- 1) >> log2blksz
))
30 printf("%s read outside partition " LBAFU
"\n", __func__
,
35 /* Get the read to the beginning of a partition */
36 sector
+= byte_offset
>> log2blksz
;
37 byte_offset
&= blk
->blksz
- 1;
39 debug(" <" LBAFU
", %d, %d>\n", sector
, byte_offset
, byte_len
);
41 if (byte_offset
!= 0) {
43 /* read first part which isn't aligned with start of sector */
44 if (blk_dread(blk
, partition
->start
+ sector
, 1,
45 (void *)sec_buf
) != 1) {
46 printf(" ** %s read error **\n", __func__
);
49 readlen
= min((int)blk
->blksz
- byte_offset
,
51 memcpy(buf
, sec_buf
+ byte_offset
, readlen
);
60 /* read sector aligned part */
61 block_len
= byte_len
& ~(blk
->blksz
- 1);
64 ALLOC_CACHE_ALIGN_BUFFER(u8
, p
, blk
->blksz
);
66 block_len
= blk
->blksz
;
67 blk_dread(blk
, partition
->start
+ sector
, 1,
69 memcpy(buf
, p
, byte_len
);
73 if (blk_dread(blk
, partition
->start
+ sector
,
74 block_len
>> log2blksz
, (void *)buf
) !=
75 block_len
>> log2blksz
) {
76 printf(" ** %s read error - block\n", __func__
);
79 block_len
= byte_len
& ~(blk
->blksz
- 1);
81 byte_len
-= block_len
;
82 sector
+= block_len
/ blk
->blksz
;
85 /* read rest of data which are not in whole sector */
86 if (blk_dread(blk
, partition
->start
+ sector
, 1,
87 (void *)sec_buf
) != 1) {
88 printf("* %s read error - last part\n", __func__
);
91 memcpy(buf
, sec_buf
, byte_len
);