1 |
/* Store I/O |
/* Store I/O |
2 |
|
|
3 |
Copyright (C) 1995,96,97,98,99,2001,02 Free Software Foundation, Inc. |
Copyright (C) 1995-1999,2001,2002,2003 Free Software Foundation, Inc. |
4 |
Written by Miles Bader <miles@gnu.org> |
Written by Miles Bader <miles@gnu.org> |
5 |
This file is part of the GNU Hurd. |
This file is part of the GNU Hurd. |
6 |
|
|
89 |
return 1; |
return 1; |
90 |
} |
} |
91 |
|
|
|
#include <assert.h> |
|
|
|
|
92 |
/* Write LEN bytes from BUF to STORE at ADDR. Returns the amount written |
/* Write LEN bytes from BUF to STORE at ADDR. Returns the amount written |
93 |
in AMOUNT. ADDR is in BLOCKS (as defined by STORE->block_size). */ |
in AMOUNT. ADDR is in BLOCKS (as defined by STORE->block_size). */ |
94 |
error_t |
error_t |
108 |
if ((addr << block_shift) + len > store->size) |
if ((addr << block_shift) + len > store->size) |
109 |
return EIO; |
return EIO; |
110 |
|
|
111 |
if (store->block_size != 0) |
if (store->block_size != 0 && (len & (store->block_size - 1)) != 0) |
112 |
assert ((len & (store->block_size - 1)) == 0); |
return EINVAL; |
113 |
|
|
114 |
addr = store_find_first_run (store, addr, &run, &runs_end, &base, &index); |
addr = store_find_first_run (store, addr, &run, &runs_end, &base, &index); |
115 |
if (addr < 0) |
if (addr < 0) |
188 |
if ((addr << block_shift) + amount > store->size) |
if ((addr << block_shift) + amount > store->size) |
189 |
amount = store->size - (addr << block_shift); |
amount = store->size - (addr << block_shift); |
190 |
|
|
191 |
if (store->block_size != 0) |
if (store->block_size != 0 && (amount & (store->block_size - 1)) != 0) |
192 |
assert ((amount & (store->block_size - 1)) == 0); |
return EINVAL; |
193 |
|
|
194 |
if ((amount >> block_shift) <= run->length - addr) |
if ((amount >> block_shift) <= run->length - addr) |
195 |
/* The first run has it all... */ |
/* The first run has it all... */ |