]> git.ipfire.org Git - people/ms/u-boot.git/blob - fs/reiserfs/dev.c
USB: This patch fix readl in ohci swap reg access.
[people/ms/u-boot.git] / fs / reiserfs / dev.c
1 /*
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>
22 #if (CONFIG_COMMANDS & CFG_CMD_REISER)
23
24 #include <config.h>
25 #include <reiserfs.h>
26
27 #include "reiserfs_private.h"
28
29 static block_dev_desc_t *reiserfs_block_dev_desc;
30 static disk_partition_t part_info;
31
32
33 int reiserfs_set_blk_dev(block_dev_desc_t *rbdd, int part)
34 {
35 reiserfs_block_dev_desc = rbdd;
36
37 if (part == 0) {
38 /* disk doesn't use partition table */
39 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
51 int 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)) {
65 /* errnum = ERR_OUTSIDE_PART; */
66 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
123 #endif /* CFG_CMD_REISERFS */