blob: 46dc41463f130d7deafe892dab657f53b74c3391 [file] [log] [blame]
wdenk4d01d9e2004-03-25 14:59:05 +00001/*
2 * (C) Copyright 2003 - 2004
3 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20
21#include <common.h>
Jon Loeliger80eb47c2007-07-09 17:56:50 -050022#if defined(CONFIG_CMD_REISER)
wdenk4d01d9e2004-03-25 14:59:05 +000023
24#include <config.h>
25#include <reiserfs.h>
26
27#include "reiserfs_private.h"
28
29static block_dev_desc_t *reiserfs_block_dev_desc;
30static disk_partition_t part_info;
31
32
33int reiserfs_set_blk_dev(block_dev_desc_t *rbdd, int part)
34{
35 reiserfs_block_dev_desc = rbdd;
36
37 if (part == 0) {
Wolfgang Denka1be4762008-05-20 16:00:29 +020038 /* disk doesn't use partition table */
wdenk4d01d9e2004-03-25 14:59:05 +000039 part_info.start = 0;
40 part_info.size = rbdd->lba;
41 part_info.blksz = rbdd->blksz;
42 } else {
43 if (get_partition_info (reiserfs_block_dev_desc, part, &part_info)) {
44 return 0;
45 }
46 }
47 return (part_info.size);
48}
49
50
51int reiserfs_devread (int sector, int byte_offset, int byte_len, char *buf)
52{
53 char sec_buf[SECTOR_SIZE];
54 unsigned block_len;
55/*
56 unsigned len = byte_len;
57 u8 *start = buf;
58*/
59 /*
60 * Check partition boundaries
61 */
62 if (sector < 0
63 || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS))
64 >= part_info.size)) {
wdenkd3602132004-03-25 15:14:43 +000065/* errnum = ERR_OUTSIDE_PART; */
wdenk4d01d9e2004-03-25 14:59:05 +000066 printf (" ** reiserfs_devread() read outside partition\n");
67 return 0;
68 }
69
70 /*
71 * Get the read to the beginning of a partition.
72 */
73 sector += byte_offset >> SECTOR_BITS;
74 byte_offset &= SECTOR_SIZE - 1;
75
76#if defined(DEBUG)
77 printf (" <%d, %d, %d> ", sector, byte_offset, byte_len);
78#endif
79
80
81 if (reiserfs_block_dev_desc == NULL)
82 return 0;
83
84
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");
90 return 0;
91 }
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);
95 sector++;
96 }
97
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");
104 return 0;
105 }
106 buf+=block_len;
107 byte_len-=block_len;
108 sector+= block_len/SECTOR_SIZE;
109
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");
115 return 0;
116 }
117 memcpy(buf, sec_buf, byte_len);
118 }
119
120 return 1;
121}
122
Jon Loeliger8bdca102007-07-10 11:07:56 -0500123#endif