2 * (C) Copyright 2003 - 2004
3 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #if defined(CONFIG_CMD_REISER)
27 #include "reiserfs_private.h"
29 static block_dev_desc_t *reiserfs_block_dev_desc;
30 static disk_partition_t part_info;
33 int reiserfs_set_blk_dev(block_dev_desc_t *rbdd, int part)
35 reiserfs_block_dev_desc = rbdd;
38 /* disk doesn't use partition table */
40 part_info.size = rbdd->lba;
41 part_info.blksz = rbdd->blksz;
43 if (get_partition_info (reiserfs_block_dev_desc, part, &part_info)) {
47 return (part_info.size);
51 int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
53 char sec_buf[SECTOR_SIZE];
56 unsigned len = byte_len;
60 * Check partition boundaries
63 || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS))
65 /* errnum = ERR_OUTSIDE_PART; */
66 printf (" ** reiserfs_devread() read outside partition\n");
71 * Get the read to the beginning of a partition.
73 sector += byte_offset >> SECTOR_BITS;
74 byte_offset &= SECTOR_SIZE - 1;
77 printf (" <%d, %d, %d> ", sector, byte_offset, byte_len);
81 if (reiserfs_block_dev_desc == NULL)
85 if (byte_offset != 0) {
86 /* read first part which isn't aligned with start of sector */
87 if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
88 part_info.start+sector, 1, (unsigned long *)sec_buf) != 1) {
89 printf (" ** reiserfs_devread() read error\n");
92 memcpy(buf, sec_buf+byte_offset, min(SECTOR_SIZE-byte_offset, byte_len));
93 buf+=min(SECTOR_SIZE-byte_offset, byte_len);
94 byte_len-=min(SECTOR_SIZE-byte_offset, byte_len);
98 /* read sector aligned part */
99 block_len = byte_len & ~(SECTOR_SIZE-1);
100 if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
101 part_info.start+sector, block_len/SECTOR_SIZE, (unsigned long *)buf) !=
102 block_len/SECTOR_SIZE) {
103 printf (" ** reiserfs_devread() read error - block\n");
108 sector+= block_len/SECTOR_SIZE;
110 if ( byte_len != 0 ) {
111 /* read rest of data which are not in whole sector */
112 if (reiserfs_block_dev_desc->block_read(reiserfs_block_dev_desc->dev,
113 part_info.start+sector, 1, (unsigned long *)sec_buf) != 1) {
114 printf (" ** reiserfs_devread() read error - last part\n");
117 memcpy(buf, sec_buf, byte_len);