/* scan file descr cache */
for (tfd = fdcache, i = 0; i < MAXFDCACHE; i++, tfd++) {
if (afid == tfd->fileID && tfd->refCount == 0) { /* don't use open fd */
- lseek(tfd->fd, 0, 0); /* reset ptr just like open would have */
tfd->refCount++;
return tfd->fd;
}
fd = uphys_open(adbase, afile);
if (fd < 0)
return UNOENT;
+ if (lseek(fd, 0, 0) < 0) {
+ uphys_close(fd);
+ return EIO;
+ }
code = read(fd, &thdr, sizeof(thdr));
if (code != sizeof(thdr)) {
uphys_close(fd);
thdr.version.counter = htonl(aversion->counter);
thdr.magic = htonl(UBIK_MAGIC);
thdr.size = htons(HDRSIZE);
+ if (lseek(fd, 0, 0) < 0) {
+ uphys_close(fd);
+ return EIO;
+ }
code = write(fd, &thdr, sizeof(thdr));
fsync(fd); /* preserve over crash */
uphys_close(fd);