Oops when bad ef_type or uid is written to disk

This commit is contained in:
Markus Armbruster 2008-02-25 21:05:48 +01:00
parent 5490782db3
commit 99594c1898

View file

@ -342,13 +342,28 @@ fillcache(struct empfile *ep, int start)
static int static int
do_write(struct empfile *ep, void *buf, int id, int count) do_write(struct empfile *ep, void *buf, int id, int count)
{ {
int n, ret; int i, n, ret;
char *p; char *p;
struct emptypedstr *elt;
if (CANT_HAPPEN(ep->fd < 0 || (ep->flags & EFF_PRIVATE) if (CANT_HAPPEN(ep->fd < 0 || (ep->flags & EFF_PRIVATE)
|| id < 0 || count < 0)) || id < 0 || count < 0))
return -1; return -1;
if (ep->flags & EFF_TYPED) {
for (i = 0; i < count; i++) {
/*
* TODO Oopses here could be due to bad data corruption.
* Fail instead of attempting to recover?
*/
elt = (struct emptypedstr *)((char *)buf + i * ep->size);
if (CANT_HAPPEN(elt->ef_type != ep->uid))
elt->ef_type = ep->uid;
if (CANT_HAPPEN(elt->uid != id + i))
elt->uid = id + i;
}
}
if (lseek(ep->fd, id * ep->size, SEEK_SET) == (off_t)-1) { if (lseek(ep->fd, id * ep->size, SEEK_SET) == (off_t)-1) {
logerror("Error seeking %s (%s)", ep->file, strerror(errno)); logerror("Error seeking %s (%s)", ep->file, strerror(errno));
return -1; return -1;