]>
git.ipfire.org Git - people/ms/u-boot.git/blob - fs/reiserfs/dev.c
cb288d60f567a51246ac1346138324edbdcfbb15
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.
25 #include "reiserfs_private.h"
27 static block_dev_desc_t
*reiserfs_block_dev_desc
;
28 static disk_partition_t
*part_info
;
31 void reiserfs_set_blk_dev(block_dev_desc_t
*rbdd
, disk_partition_t
*info
)
33 reiserfs_block_dev_desc
= rbdd
;
38 int reiserfs_devread (int sector
, int byte_offset
, int byte_len
, char *buf
)
40 char sec_buf
[SECTOR_SIZE
];
43 unsigned len = byte_len;
47 * Check partition boundaries
50 || ((sector
+ ((byte_offset
+ byte_len
- 1) >> SECTOR_BITS
))
51 >= part_info
->size
)) {
52 /* errnum = ERR_OUTSIDE_PART; */
53 printf (" ** reiserfs_devread() read outside partition\n");
58 * Get the read to the beginning of a partition.
60 sector
+= byte_offset
>> SECTOR_BITS
;
61 byte_offset
&= SECTOR_SIZE
- 1;
64 printf (" <%d, %d, %d> ", sector
, byte_offset
, byte_len
);
68 if (reiserfs_block_dev_desc
== NULL
)
72 if (byte_offset
!= 0) {
73 /* read first part which isn't aligned with start of sector */
74 if (reiserfs_block_dev_desc
->block_read(reiserfs_block_dev_desc
->dev
,
75 part_info
->start
+ sector
, 1,
76 (unsigned long *)sec_buf
) != 1) {
77 printf (" ** reiserfs_devread() read error\n");
80 memcpy(buf
, sec_buf
+byte_offset
, min(SECTOR_SIZE
-byte_offset
, byte_len
));
81 buf
+=min(SECTOR_SIZE
-byte_offset
, byte_len
);
82 byte_len
-=min(SECTOR_SIZE
-byte_offset
, byte_len
);
86 /* read sector aligned part */
87 block_len
= byte_len
& ~(SECTOR_SIZE
-1);
88 if (reiserfs_block_dev_desc
->block_read(reiserfs_block_dev_desc
->dev
,
89 part_info
->start
+ sector
, block_len
/SECTOR_SIZE
,
90 (unsigned long *)buf
) != block_len
/SECTOR_SIZE
) {
91 printf (" ** reiserfs_devread() read error - block\n");
96 sector
+= block_len
/SECTOR_SIZE
;
98 if ( byte_len
!= 0 ) {
99 /* read rest of data which are not in whole sector */
100 if (reiserfs_block_dev_desc
->block_read(reiserfs_block_dev_desc
->dev
,
101 part_info
->start
+ sector
, 1,
102 (unsigned long *)sec_buf
) != 1) {
103 printf (" ** reiserfs_devread() read error - last part\n");
106 memcpy(buf
, sec_buf
, byte_len
);