2 * (C) Copyright 2003 - 2004
3 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
5 * SPDX-License-Identifier: GPL-2.0+
13 #include "reiserfs_private.h"
15 static block_dev_desc_t *reiserfs_block_dev_desc;
16 static disk_partition_t *part_info;
19 void reiserfs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
21 reiserfs_block_dev_desc = rbdd;
26 int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
28 char sec_buf[SECTOR_SIZE];
31 unsigned len = byte_len;
35 * Check partition boundaries
38 || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS))
39 >= part_info->size)) {
40 /* errnum = ERR_OUTSIDE_PART; */
41 printf (" ** reiserfs_devread() read outside partition\n");
46 * Get the read to the beginning of a partition.
48 sector += byte_offset >> SECTOR_BITS;
49 byte_offset &= SECTOR_SIZE - 1;
52 printf (" <%d, %d, %d> ", sector, byte_offset, byte_len);
56 if (reiserfs_block_dev_desc == NULL)
60 if (byte_offset != 0) {
61 /* read first part which isn't aligned with start of sector */
62 if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
63 part_info->start + sector, 1,
64 (unsigned long *)sec_buf) != 1) {
65 printf (" ** reiserfs_devread() read error\n");
68 memcpy(buf, sec_buf+byte_offset, min(SECTOR_SIZE-byte_offset, byte_len));
69 buf+=min(SECTOR_SIZE-byte_offset, byte_len);
70 byte_len-=min(SECTOR_SIZE-byte_offset, byte_len);
74 /* read sector aligned part */
75 block_len = byte_len & ~(SECTOR_SIZE-1);
76 if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
77 part_info->start + sector, block_len/SECTOR_SIZE,
78 (unsigned long *)buf) != block_len/SECTOR_SIZE) {
79 printf (" ** reiserfs_devread() read error - block\n");
84 sector+= block_len/SECTOR_SIZE;
86 if ( byte_len != 0 ) {
87 /* read rest of data which are not in whole sector */
88 if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
89 part_info->start + sector, 1,
90 (unsigned long *)sec_buf) != 1) {
91 printf (" ** reiserfs_devread() read error - last part\n");
94 memcpy(buf, sec_buf, byte_len);