diff options
author | Matthew Fioravante <matthew.fioravante@jhuapl.edu> | 2012-11-19 12:59:47 +0000 |
---|---|---|
committer | Matthew Fioravante <matthew.fioravante@jhuapl.edu> | 2012-11-19 12:59:47 +0000 |
commit | 7967bbb45e08d7d3bd4c5ef8e3df6e428a5918fd (patch) | |
tree | 5dd78b1c1928998dab63797633b74711bc38cb8f /extras | |
parent | 2ac19a6b381c9a9cd57afc107af95761bbddb5e0 (diff) | |
download | xen-7967bbb45e08d7d3bd4c5ef8e3df6e428a5918fd.tar.gz xen-7967bbb45e08d7d3bd4c5ef8e3df6e428a5918fd.tar.bz2 xen-7967bbb45e08d7d3bd4c5ef8e3df6e428a5918fd.zip |
minios: fix bug in lseek for mini-os
lseek always used files[fd].file.offset. It should
use the offset of whatever union member is actually
being used.
Signed-off-by: Matthew Fioravante <matthew.fioravante@jhuapl.edu>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'extras')
-rw-r--r-- | extras/mini-os/lib/sys.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/extras/mini-os/lib/sys.c b/extras/mini-os/lib/sys.c index d212969b52..3cc334000c 100644 --- a/extras/mini-os/lib/sys.c +++ b/extras/mini-os/lib/sys.c @@ -360,45 +360,54 @@ int write(int fd, const void *buf, size_t nbytes) off_t lseek(int fd, off_t offset, int whence) { + off_t* target = NULL; switch(files[fd].type) { -#if defined(CONFIG_BLKFRONT) || defined(CONFIG_TPMFRONT) || defined(CONFIG_TPM_TIS) #ifdef CONFIG_BLKFRONT case FTYPE_BLK: + target = &files[fd].blk.offset; + break; #endif -#ifdef CONFIG_TPMFRNT +#ifdef CONFIG_TPMFRONT case FTYPE_TPMFRONT: + target = &files[fd].tpmfront.offset; + break; #endif #ifdef CONFIG_TPM_TIS case FTYPE_TPM_TIS: + target = &files[fd].tpm_tis.offset; + break; #endif - switch (whence) { - case SEEK_SET: - files[fd].file.offset = offset; - break; - case SEEK_CUR: - files[fd].file.offset += offset; - break; - case SEEK_END: - { - struct stat st; - int ret; - ret = fstat(fd, &st); - if (ret) - return -1; - files[fd].file.offset = st.st_size + offset; - break; - } - default: - errno = EINVAL; - return -1; - } - return files[fd].file.offset; - break; -#endif - default: /* Not implemented on this FTYPE */ - errno = ESPIPE; - return (off_t) -1; + case FTYPE_FILE: + target = &files[fd].file.offset; + break; + default: + /* Not implemented for this filetype */ + errno = ESPIPE; + return (off_t) -1; + } + + switch (whence) { + case SEEK_SET: + *target = offset; + break; + case SEEK_CUR: + *target += offset; + break; + case SEEK_END: + { + struct stat st; + int ret; + ret = fstat(fd, &st); + if (ret) + return -1; + *target = st.st_size + offset; + break; + } + default: + errno = EINVAL; + return -1; } + return *target; } int fsync(int fd) { |