struct dcache *tdc;
struct osi_file *tfile;
afs_size_t offset, len;
+ int code = 0;
tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0);
if (!tdc) {
avc->f.m.Length = len;
ObtainWriteLock(&tdc->lock, 720);
+ tfile = afs_CFileOpen(&tdc->f.inode);
+ if (!tfile) {
+ code = EIO;
+ goto done;
+ }
afs_AdjustSize(tdc, len);
tdc->validPos = len;
- tfile = afs_CFileOpen(&tdc->f.inode);
- osi_Assert(tfile);
afs_CFileWrite(tfile, 0, aname, len);
afs_CFileClose(tfile);
+ done:
ReleaseWriteLock(&tdc->lock);
- return 0;
+ return code;
}
/* don't set CDirty in here because RPC is called synchronously */
/* The directory blob is empty, apparently. This is not a valid dir
* blob, so throw an error. */
code = EIO;
+ goto error;
} else if (page * AFS_BUFFER_PAGESIZE >= adc->f.chunkBytes) {
code = ENOENT; /* past the end */
+ goto error;
}
- if (code) {
- tb->fid = NULLIDX;
- afs_reset_inode(&tb->inode);
- tb->lockers--;
- ReleaseWriteLock(&tb->lock);
- return code;
- }
+
tfile = afs_CFileOpen(&adc->f.inode);
- osi_Assert(tfile);
+ if (!tfile) {
+ code = EIO;
+ goto error;
+ }
code =
afs_CFileRead(tfile, tb->page * AFS_BUFFER_PAGESIZE, tb->data,
AFS_BUFFER_PAGESIZE);
afs_CFileClose(tfile);
if (code < AFS_BUFFER_PAGESIZE) {
- tb->fid = NULLIDX;
- afs_reset_inode(&tb->inode);
- tb->lockers--;
- ReleaseWriteLock(&tb->lock);
- return EIO;
+ code = EIO;
+ goto error;
}
/* Note that findslot sets the page field in the buffer equal to
* what it is searching for. */
entry->buffer = tb;
entry->data = tb->data;
return 0;
+
+ error:
+ tb->fid = NULLIDX;
+ afs_reset_inode(&tb->inode);
+ tb->lockers--;
+ ReleaseWriteLock(&tb->lock);
+ return code;
}
static void
if (lp->dirty) {
/* see DFlush for rationale for not getting and locking the dcache */
tfile = afs_CFileOpen(&lp->inode);
- osi_Assert(tfile);
+ if (!tfile)
+ return NULL; /* Callers will flag as EIO */
+
afs_CFileWrite(tfile, lp->page * AFS_BUFFER_PAGESIZE, lp->data,
AFS_BUFFER_PAGESIZE);
lp->dirty = 0;
{
int i, code, ret_code = 0, written, trans_size;
struct dcache *new_dc = NULL;
- struct osi_file *tfile_src, *tfile_dst;
+ struct osi_file *tfile_src = NULL, *tfile_dst = NULL;
struct VenusFid shadow_fid;
- char *data;
+ char *data = NULL;
/* Is this a dir? */
if (vType(avc) != VDIR)
/* Open the files. */
tfile_src = afs_CFileOpen(&adc->f.inode);
+ if (!tfile_src) {
+ ret_code = EIO;
+ goto done;
+ }
+
tfile_dst = afs_CFileOpen(&new_dc->f.inode);
- osi_Assert(tfile_src);
- osi_Assert(tfile_dst);
+ if (!tfile_dst) {
+ ret_code = EIO;
+ goto done;
+ }
/* And now copy dir dcache data into this dcache,
* 4k at a time.
written+=trans_size;
}
- afs_CFileClose(tfile_dst);
- afs_CFileClose(tfile_src);
+ done:
+ if (tfile_dst)
+ afs_CFileClose(tfile_dst);
+ if (tfile_src)
+ afs_CFileClose(tfile_src);
- afs_osi_Free(data, 4096);
+ if (data)
+ afs_osi_Free(data, 4096);
ReleaseWriteLock(&new_dc->lock);
afs_PutDCache(new_dc);
avc->f.shadow.unique = shadow_fid.Fid.Unique;
}
-done:
return ret_code;
}
}
ObtainReadLock(&tdc->lock);
tfile = afs_CFileOpen(&tdc->f.inode);
- osi_Assert(tfile);
+ if (!tfile) {
+ ReleaseReadLock(&tdc->lock);
+ afs_PutDCache(tdc);
+ code = EIO;
+ goto end;
+ }
code = afs_CFileRead(tfile, 0, ttargetName, tlen);
ttargetName[tlen-1] = '\0';
afs_CFileClose(tfile);
size = tdc->f.chunkBytes;
tfile = afs_CFileOpen(&tdc->f.inode);
- osi_Assert(tfile);
+ if (!tfile) {
+ return EIO;
+ }
while ( size > 0 ) {
code = (*ops->prepare)(rock, size, &tlen);
if (code)
return code;
tfile = afs_CFileOpen(&volumeInode);
- osi_Assert(tfile);
+ if (!tfile) {
+ return EIO;
+ }
afs_CFileTruncate(tfile, 0);
afs_CFileClose(tfile);
return 0;
toAdd = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset;
}
tfile = afs_CFileOpen(&tdc->f.inode);
- osi_Assert(tfile);
+ if (!tfile) {
+ ReleaseWriteLock(&tdc->lock);
+ afs_PutDCache(tdc);
+ code = EIO;
+ break;
+ }
while(tdc->validPos < avc->f.m.Length + toAdd) {
afs_size_t towrite;