/* * Write (overwrite) the directory entry in slot SLOT of a directory * vnode. */ static int sfs_writedir(struct sfs_vnode *sv, struct sfs_dir *sd, int slot) { struct uio ku; off_t actualpos; int result; /* Compute the actual position in the directory. */ assert(slot>=0); actualpos = slot * sizeof(struct sfs_dir); /* Set up a uio to do the write */ mk_kuio(&ku, sd, sizeof(struct sfs_dir), actualpos, UIO_WRITE); /* do it */ result = sfs_io(sv, &ku); if (result) { return result; } /* Should not end up with a partial entry! */ if (ku.uio_resid > 0) { panic("sfs: writedir: Short write (ino %u)\n", sv->sv_ino); } /* Done */ return 0; }
/* * Read the directory entry out of slot SLOT of a directory vnode. * The "slot" is the index of the directory entry, starting at 0. */ static int sfs_readdir(struct sfs_vnode *sv, struct sfs_dir *sd, int slot) { struct uio ku; off_t actualpos; int result; /* Compute the actual position in the directory to read. */ actualpos = slot * sizeof(struct sfs_dir); /* Set up a uio to do the read */ mk_kuio(&ku, sd, sizeof(struct sfs_dir), actualpos, UIO_READ); /* do it */ result = sfs_io(sv, &ku); if (result) { return result; } /* We should not hit EOF in the middle of a directory entry */ if (ku.uio_resid > 0) { panic("sfs: readdir: Short entry (inode %u)\n", sv->sv_ino); } /* Done */ return 0; }
/* * Called for write(). sfs_io() does the work. */ static int sfs_write(struct vnode *v, struct uio *uio) { struct sfs_vnode *sv = v->vn_data; assert(uio->uio_rw==UIO_WRITE); return sfs_io(sv, uio); }
/* * Called for read(). sfs_io() does the work. */ static int sfs_read(struct vnode *v, struct uio *uio) { struct sfs_vnode *sv = v->vn_data; assert(uio->uio_rw==UIO_READ); return sfs_io(sv, uio); }
/* * Called for write(). sfs_io() does the work. */ static int sfs_write(struct vnode *v, struct uio *uio) { struct sfs_vnode *sv = v->vn_data; int result; KASSERT(uio->uio_rw==UIO_WRITE); vfs_biglock_acquire(); result = sfs_io(sv, uio); vfs_biglock_release(); return result; }
/* * Called for write(). sfs_io() does the work. * * Locking: gets/releases vnode lock. * * Requires up to 3 buffers. */ static int sfs_write(struct vnode *v, struct uio *uio) { struct sfs_vnode *sv = v->vn_data; int result; KASSERT(uio->uio_rw==UIO_WRITE); lock_acquire(sv->sv_lock); reserve_buffers(SFS_BLOCKSIZE); result = sfs_io(sv, uio); unreserve_buffers(SFS_BLOCKSIZE); lock_release(sv->sv_lock); return result; }
// sfs_write - write file static int sfs_write(struct inode *node, struct iobuf *iob) { return sfs_io(node, iob, 1); }
// sfs_read - read file static int sfs_read(struct inode *node, struct iobuf *iob) { return sfs_io(node, iob, 0); }