dev->fd = alloc_fd(FTYPE_BLK);
printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd);
files[dev->fd].blk.dev = dev;
- files[dev->fd].blk.offset = 0;
return dev->fd;
}
int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
{
struct blkfront_dev* dev = files[fd].blk.dev;
- off_t offset = files[fd].blk.offset;
+ off_t offset = files[fd].offset;
struct blkfront_aiocb aiocb;
unsigned long long disksize = dev->info.sectors * dev->info.sector_size;
unsigned int blocksize = dev->info.sector_size;
}
free(copybuf);
- files[fd].blk.offset += rc;
+ files[fd].offset += rc;
return rc;
}
struct file {
enum fd_type type;
bool read; /* maybe available for read */
+ off_t offset;
union {
struct {
/* lwIP fd */
struct {
/* FS import fd */
int fd;
- off_t offset;
} file;
struct {
struct evtchn_port_list ports;
} tap;
struct {
struct blkfront_dev *dev;
- off_t offset;
} blk;
struct {
struct kbdfront_dev *dev;
struct {
struct tpmfront_dev *dev;
int respgot;
- off_t offset;
} tpmfront;
#endif
#ifdef CONFIG_TPM_TIS
struct {
struct tpm_chip *dev;
int respgot;
- off_t offset;
} tpm_tis;
#endif
#ifdef CONFIG_XENBUS
for (i=0; i<NOFILE; i++) {
if (files[i].type == FTYPE_NONE) {
files[i].type = type;
+ files[i].offset = 0;
pthread_mutex_unlock(&fd_lock);
return i;
}
off_t lseek(int fd, off_t offset, int whence)
{
- off_t* target = NULL;
switch(files[fd].type) {
#ifdef CONFIG_BLKFRONT
case FTYPE_BLK:
- target = &files[fd].blk.offset;
break;
#endif
#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
case FTYPE_FILE:
- target = &files[fd].file.offset;
break;
default:
/* Not implemented for this filetype */
switch (whence) {
case SEEK_SET:
- *target = offset;
+ files[fd].offset = offset;
break;
case SEEK_CUR:
- *target += offset;
+ files[fd].offset += offset;
break;
case SEEK_END:
{
ret = fstat(fd, &st);
if (ret)
return -1;
- *target = st.st_size + offset;
+ files[fd].offset = st.st_size + offset;
break;
}
default:
errno = EINVAL;
return -1;
}
- return *target;
+ return files[fd].offset;
}
int fsync(int fd) {
if(tpm->fd >= 0) {
files[tpm->fd].read = false;
files[tpm->fd].tpm_tis.respgot = 0;
- files[tpm->fd].tpm_tis.offset = 0;
+ files[tpm->fd].offset = 0;
}
#endif
return len;
tpm->fd = alloc_fd(FTYPE_TPM_TIS);
printk("tpm_tis_open() -> %d\n", tpm->fd);
files[tpm->fd].tpm_tis.dev = tpm;
- files[tpm->fd].tpm_tis.offset = 0;
files[tpm->fd].tpm_tis.respgot = 0;
return tpm->fd;
}
/* Handle EOF case */
- if(files[fd].tpm_tis.offset >= tpm->data_len) {
+ if(files[fd].offset >= tpm->data_len) {
rc = 0;
} else {
- rc = min(tpm->data_len - files[fd].tpm_tis.offset, count);
- memcpy(buf, tpm->data_buffer + files[fd].tpm_tis.offset, rc);
+ rc = min(tpm->data_len - files[fd].offset, count);
+ memcpy(buf, tpm->data_buffer + files[fd].offset, rc);
}
- files[fd].tpm_tis.offset += rc;
+ files[fd].offset += rc;
/* Reset the data pending flag */
return rc;
}
if(dev->fd >= 0) {
files[dev->fd].read = false;
files[dev->fd].tpmfront.respgot = 0;
- files[dev->fd].tpmfront.offset = 0;
+ files[dev->fd].offset = 0;
}
#endif
wmb();
dev->fd = alloc_fd(FTYPE_TPMFRONT);
printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd);
files[dev->fd].tpmfront.dev = dev;
- files[dev->fd].tpmfront.offset = 0;
files[dev->fd].tpmfront.respgot = 0;
return dev->fd;
}
}
/* handle EOF case */
- if(files[dev->fd].tpmfront.offset >= dev->resplen) {
+ if(files[dev->fd].offset >= dev->resplen) {
return 0;
}
/* Compute the number of bytes and do the copy operation */
- if((rc = min(count, dev->resplen - files[dev->fd].tpmfront.offset)) != 0) {
- memcpy(buf, dev->respbuf + files[dev->fd].tpmfront.offset, rc);
- files[dev->fd].tpmfront.offset += rc;
+ if((rc = min(count, dev->resplen - files[dev->fd].offset)) != 0) {
+ memcpy(buf, dev->respbuf + files[dev->fd].offset, rc);
+ files[dev->fd].offset += rc;
}
return rc;