ia64/xen-unstable

changeset 17032:a1b83b3b0449

ioemu: cope with partial reads/writes when using the read()/write()
syscall interfaces.
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Feb 11 14:47:06 2008 +0000 (2008-02-11)
parents 209512f6d89c
children 7e189fc27f4f
files tools/ioemu/block-raw.c
line diff
     1.1 --- a/tools/ioemu/block-raw.c	Mon Feb 11 14:45:29 2008 +0000
     1.2 +++ b/tools/ioemu/block-raw.c	Mon Feb 11 14:47:06 2008 +0000
     1.3 @@ -169,10 +169,16 @@ static int raw_pread(BlockDriverState *b
     1.4      }
     1.5      s->lseek_err_cnt=0;
     1.6  
     1.7 -    ret = read(s->fd, buf, count);
     1.8 -    if (ret == count) 
     1.9 -        goto label__raw_read__success;
    1.10 +    uint64_t done;
    1.11 +    for (done = 0; done < count; done += ret) {
    1.12 +	ret = read(s->fd, buf + done, count - done);
    1.13 +	if (ret == -1) 
    1.14 +	    goto label__raw_read__error;
    1.15 +    }
    1.16 +    ret = count;
    1.17 +    goto label__raw_read__success;
    1.18      
    1.19 +label__raw_read__error:
    1.20      DEBUG_BLOCK_PRINT("raw_read(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] read failed %d : %d = %s\n", 
    1.21          s->fd, 
    1.22          bs->filename, 
    1.23 @@ -234,9 +240,16 @@ static int raw_pwrite(BlockDriverState *
    1.24      }
    1.25      s->lseek_err_cnt = 0;
    1.26  
    1.27 -    ret = write(s->fd, buf, count);
    1.28 -    if (ret == count) 
    1.29 -        goto label__raw_write__success;
    1.30 +    uint64_t done;
    1.31 +    for (done = 0; done < count; done += ret) {
    1.32 +	ret = write(s->fd, buf + done, count - done);
    1.33 +	if (ret == -1) 
    1.34 +	    goto label__raw_write__error;
    1.35 +    }
    1.36 +    ret = count;
    1.37 +    goto label__raw_write__success;
    1.38 +
    1.39 +label__raw_write__error:
    1.40      
    1.41      DEBUG_BLOCK_PRINT("raw_write(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] write failed %d : %d = %s\n", 
    1.42          s->fd,