]>
git.ipfire.org Git - people/ms/u-boot.git/blob - fs/zfs/dev.c
3 * based on code of fs/reiserfs/dev.c by
5 * (C) Copyright 2003 - 2004
6 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <zfs_common.h>
16 static block_dev_desc_t
*zfs_block_dev_desc
;
17 static disk_partition_t
*part_info
;
19 void zfs_set_blk_dev(block_dev_desc_t
*rbdd
, disk_partition_t
*info
)
21 zfs_block_dev_desc
= rbdd
;
26 int zfs_devread(int sector
, int byte_offset
, int byte_len
, char *buf
)
28 short sec_buffer
[SECTOR_SIZE
/sizeof(short)];
29 char *sec_buf
= (char *)sec_buffer
;
33 * Check partition boundaries
36 ((sector
+ ((byte_offset
+ byte_len
- 1) >> SECTOR_BITS
)) >=
38 /* errnum = ERR_OUTSIDE_PART; */
39 printf(" ** zfs_devread() read outside partition sector %d\n", sector
);
44 * Get the read to the beginning of a partition.
46 sector
+= byte_offset
>> SECTOR_BITS
;
47 byte_offset
&= SECTOR_SIZE
- 1;
49 debug(" <%d, %d, %d>\n", sector
, byte_offset
, byte_len
);
51 if (zfs_block_dev_desc
== NULL
) {
52 printf("** Invalid Block Device Descriptor (NULL)\n");
56 if (byte_offset
!= 0) {
57 /* read first part which isn't aligned with start of sector */
58 if (zfs_block_dev_desc
->block_read(zfs_block_dev_desc
->dev
,
59 part_info
->start
+ sector
, 1,
60 (unsigned long *)sec_buf
) != 1) {
61 printf(" ** zfs_devread() read error **\n");
64 memcpy(buf
, sec_buf
+ byte_offset
,
65 min(SECTOR_SIZE
- byte_offset
, byte_len
));
66 buf
+= min(SECTOR_SIZE
- byte_offset
, byte_len
);
67 byte_len
-= min(SECTOR_SIZE
- byte_offset
, byte_len
);
74 /* read sector aligned part */
75 block_len
= byte_len
& ~(SECTOR_SIZE
- 1);
80 block_len
= SECTOR_SIZE
;
81 zfs_block_dev_desc
->block_read(zfs_block_dev_desc
->dev
,
82 part_info
->start
+ sector
,
83 1, (unsigned long *)p
);
84 memcpy(buf
, p
, byte_len
);
88 if (zfs_block_dev_desc
->block_read(zfs_block_dev_desc
->dev
,
89 part_info
->start
+ sector
, block_len
/ SECTOR_SIZE
,
90 (unsigned long *) buf
) != block_len
/ SECTOR_SIZE
) {
91 printf(" ** zfs_devread() read error - block\n");
95 block_len
= byte_len
& ~(SECTOR_SIZE
- 1);
97 byte_len
-= block_len
;
98 sector
+= block_len
/ SECTOR_SIZE
;
101 /* read rest of data which are not in whole sector */
102 if (zfs_block_dev_desc
->
103 block_read(zfs_block_dev_desc
->dev
,
104 part_info
->start
+ sector
, 1,
105 (unsigned long *) sec_buf
) != 1) {
106 printf(" ** zfs_devread() read error - last part\n");
109 memcpy(buf
, sec_buf
, byte_len
);