/* Generic write interface */ int afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr, afs_int32 asize) { size_t resid; afs_int32 code; AFS_STATCNT(osi_Write); if (!afile) osi_Panic("afs_osi_Write called with null afile"); if (offset != -1) afile->offset = offset; AFS_GUNLOCK(); code = vn_rdwr(UIO_WRITE, afile->vnode, aptr, asize, afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, osi_curproc()); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; if (afile->offset > afile->size) afile->size = afile->offset; } else { if (code > 0) { code = -code; } } if (afile->proc) (*afile->proc) (afile, code); return code; }
/* Generic write interface */ int afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr, afs_int32 asize) { unsigned int resid; afs_int32 code; AFS_STATCNT(osi_Write); if (!afile) osi_Panic("afs_osi_Write called with null afile"); if (offset != -1) afile->offset = offset; AFS_GUNLOCK(); VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY); code = vn_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, osi_curproc()); VOP_UNLOCK(afile->vnode, 0); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; if (afile->offset > afile->size) afile->size = afile->offset; } else code = -1; if (afile->proc) (*afile->proc) (afile, code); return code; }
int afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg, int followlink, struct vnode **compvpp) { struct nameidata nd; int niflag; int error; /* * Lookup pathname "fnamep", returning leaf in *compvpp. segflg says * whether the pathname is user or system space. */ /* XXX LOCKLEAF ? */ niflag = followlink ? FOLLOW : NOFOLLOW; NDINIT(&nd, LOOKUP, niflag, segflg, fnamep, osi_curproc()); if ((error = namei(&nd))) return error; *compvpp = nd.ni_vp; return error; }
int osi_UFSTruncate(struct osi_file *afile, afs_int32 asize) { struct vattr tvattr; afs_int32 code; struct osi_stat tstat; AFS_STATCNT(osi_Truncate); /* * This routine only shrinks files, and most systems * have very slow truncates, even when the file is already * small enough. Check now and save some time. */ code = afs_osi_Stat(afile, &tstat); if (code || tstat.size <= asize) return code; ObtainWriteLock(&afs_xosi, 321); VATTR_NULL(&tvattr); tvattr.va_size = asize; AFS_GUNLOCK(); VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY); #ifdef AFS_NBSD50_ENV code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp); #else code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, osi_curproc()); #endif #ifdef AFS_NBSD60_ENV VOP_UNLOCK(afile->vnode); #else VOP_UNLOCK(afile->vnode, 0); #endif AFS_GLOCK(); if (code == 0) afile->size = asize; ReleaseWriteLock(&afs_xosi); return code; }
/* Generic read interface */ int afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize) { size_t resid; afs_int32 code; AFS_STATCNT(osi_Read); /* * If the osi_file passed in is NULL, panic only if AFS is not shutting * down. No point in crashing when we are already shutting down */ if (!afile) { if (afs_shuttingdown == AFS_RUNNING) osi_Panic("osi_Read called with null param"); else return -EIO; } if (offset != -1) afile->offset = offset; AFS_GUNLOCK(); code = vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, osi_curproc()); AFS_GLOCK(); if (code == 0) { code = asize - resid; afile->offset += code; osi_DisableAtimes(afile->vnode); } else { afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code); if (code > 0) { code = -code; } } return code; }
int afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat) { afs_int32 code; struct vattr tvattr; AFS_STATCNT(osi_Stat); ObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); #ifdef AFS_NBSD50_ENV code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp); #else code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, osi_curproc()); #endif AFS_GLOCK(); if (code == 0) { astat->size = afile->size = tvattr.va_size; astat->mtime = tvattr.va_mtime.tv_sec; astat->atime = tvattr.va_atime.tv_sec; } ReleaseWriteLock(&afs_xosi); return code; }