Lines Matching refs:vn

66  * from: Utah Hdr: vn.c 1.13 94/04/02
68 * from: @(#)vn.c 8.6 (Berkeley) 4/1/94
69 * $FreeBSD: src/sys/dev/vn/vn.c,v 1.105.2.4 2001/11/18 07:11:00 dillon Exp $
173 u_int64_t sc_size; /* size of vn, sc_secsize scale */
196 #define IFOPT(vn,opt) if (((vn)->sc_options|vn_options) & (opt))
197 #define TESTOPT(vn,opt) (((vn)->sc_options|vn_options) & (opt))
200 static void vnclear (struct vn_softc *vn, vfs_context_t ctx);
206 vniocattach_file(struct vn_softc *vn,
212 vniocattach_shadow(struct vn_softc * vn,
233 struct vn_softc *vn;
240 vn = vn_table + unit;
241 if ((flags & FWRITE) && (vn->sc_flags & VNF_READONLY))
289 vnread_shadow(struct vn_softc * vn, struct uio *uio, int ioflag,
292 u_int32_t blocksize = vn->sc_secsize;
312 if (shadow_map_read(vn->sc_shadow_map,
316 vp = vn->sc_shadow_vp;
319 vp = vn->sc_vp;
338 printf("vn device: vnread_shadow zero length read\n");
350 vncopy_block_to_shadow(struct vn_softc * vn, vfs_context_t ctx,
356 tmpbuf = _MALLOC(vn->sc_secsize, M_TEMP, M_WAITOK);
361 error = file_io(vn->sc_vp, ctx, UIO_READ,
362 tmpbuf, (off_t)file_block * vn->sc_secsize,
363 vn->sc_secsize, NULL);
368 error = file_io(vn->sc_shadow_vp, ctx, UIO_WRITE,
369 tmpbuf, (off_t)shadow_block * vn->sc_secsize,
370 vn->sc_secsize, NULL);
382 vnwrite_shadow(struct vn_softc * vn, struct uio *uio, int ioflag,
385 u_int32_t blocksize = vn->sc_secsize;
408 && !shadow_map_is_written(vn->sc_shadow_map,
414 && !shadow_map_is_written(vn->sc_shadow_map,
421 if (shadow_map_write(vn->sc_shadow_map,
429 size = (off_t)shadow_map_shadow_size(vn->sc_shadow_map)
430 * vn->sc_secsize;
431 vnode_setsize(vn->sc_shadow_vp, size, IO_SYNC, ctx);
449 error = vncopy_block_to_shadow(vn, ctx, s, d);
461 error = vncopy_block_to_shadow(vn, ctx,
472 error = VNOP_WRITE(vn->sc_shadow_vp, uio, ioflag, ctx);
479 printf("vn device: vnwrite_shadow zero length write\n");
499 struct vn_softc * vn;
508 vn = vn_table + unit;
509 if ((vn->sc_flags & VNF_INITED) == 0) {
515 context.vc_ucred = vn->sc_cred;
517 error = vnode_getwithvid(vn->sc_vp, vn->sc_vid);
521 vnclear(vn, &context);
532 if (offset >= (off_t)vn->sc_fsize) {
533 if (offset > (off_t)vn->sc_fsize) {
541 if ((offset + resid) > (off_t)vn->sc_fsize) {
542 resid = vn->sc_fsize - offset;
546 if (vn->sc_shadow_vp != NULL) {
547 error = vnode_getwithvid(vn->sc_shadow_vp,
548 vn->sc_shadow_vid);
552 vnode_put(vn->sc_vp);
553 vnclear(vn, &context);
556 error = vnread_shadow(vn, uio, ioflag, &context);
557 vnode_put(vn->sc_shadow_vp);
559 error = VNOP_READ(vn->sc_vp, uio, ioflag, &context);
561 vnode_put(vn->sc_vp);
576 struct vn_softc * vn;
585 vn = vn_table + unit;
586 if ((vn->sc_flags & VNF_INITED) == 0) {
590 if (vn->sc_flags & VNF_READONLY) {
596 context.vc_ucred = vn->sc_cred;
598 error = vnode_getwithvid(vn->sc_vp, vn->sc_vid);
602 vnclear(vn, &context);
612 if (offset >= (off_t)vn->sc_fsize) {
613 if (offset > (off_t)vn->sc_fsize) {
621 if ((offset + resid) > (off_t)vn->sc_fsize) {
622 resid = (off_t)vn->sc_fsize - offset;
626 if (vn->sc_shadow_vp != NULL) {
627 error = vnode_getwithvid(vn->sc_shadow_vp,
628 vn->sc_shadow_vid);
632 vnode_put(vn->sc_vp);
633 vnclear(vn, &context);
636 error = vnwrite_shadow(vn, uio, ioflag, &context);
637 vnode_put(vn->sc_shadow_vp);
639 error = VNOP_WRITE(vn->sc_vp, uio, ioflag, &context);
641 vnode_put(vn->sc_vp);
648 shadow_read(struct vn_softc * vn, struct buf * bp, char * base,
651 u_int32_t blocksize = vn->sc_secsize;
666 read_shadow = shadow_map_read(vn->sc_shadow_map,
670 vp = vn->sc_shadow_vp;
673 vp = vn->sc_vp;
684 printf("vn device: shadow_read zero length read\n");
696 shadow_write(struct vn_softc * vn, struct buf * bp, char * base,
699 u_int32_t blocksize = vn->sc_secsize;
713 shadow_grew = shadow_map_write(vn->sc_shadow_map,
720 size = (off_t)shadow_map_shadow_size(vn->sc_shadow_map)
722 vnode_setsize(vn->sc_shadow_vp, size, IO_SYNC, ctx);
725 error = file_io(vn->sc_shadow_vp, ctx, UIO_WRITE,
735 printf("vn device: shadow_write zero length write\n");
747 vn_readwrite_io(struct vn_softc * vn, struct buf * bp, vfs_context_t ctx)
754 panic("vn device: buf_map failed");
757 if (vn->sc_shadow_vp == NULL) {
760 error = file_io(vn->sc_vp, ctx,
763 (off_t)buf_blkno(bp) * vn->sc_secsize,
769 error = shadow_read(vn, bp, iov_base, ctx);
771 error = shadow_write(vn, bp, iov_base, ctx);
781 struct vn_softc *vn;
791 vn = vn_table + vnunit(buf_device(bp));
792 if ((vn->sc_flags & VNF_INITED) == 0) {
798 context.vc_ucred = vn->sc_cred;
806 if (buf_count(bp) % vn->sc_secsize != 0) {
810 sz = howmany(buf_count(bp), vn->sc_secsize);
816 if (blk_num >= 0 && (u_int64_t)blk_num >= vn->sc_size) {
817 if (blk_num > 0 && (u_int64_t)blk_num > vn->sc_size) {
825 if ((blk_num + sz) > 0 && ((u_int64_t)(blk_num + sz)) > vn->sc_size) {
826 buf_setcount(bp, (vn->sc_size - blk_num) * vn->sc_secsize);
829 vp = vn->sc_vp;
835 error = vnode_getwithvid(vp, vn->sc_vid);
839 vnclear(vn, &context);
842 shadow_vp = vn->sc_shadow_vp;
845 vn->sc_shadow_vid);
849 vnode_put(vn->sc_vp);
850 vnclear(vn, &context);
855 error = vn_readwrite_io(vn, bp, &context);
876 struct vn_softc *vn;
893 vn = vn_table + unit;
900 context.vc_ucred = vn->sc_cred;
923 if ((vn->sc_flags & VNF_INITED) == 0) {
932 if (vn->sc_vp != NULL)
933 vfs_ioattr(vnode_mount(vn->sc_vp), &ioattr);
942 *o = ioattr.io_maxreadcnt / vn->sc_secsize;
945 *o = ioattr.io_maxwritecnt / vn->sc_secsize;
966 *f = vn->sc_secsize;
978 if (vn->sc_shadow_vp != NULL) {
979 if (*f == (unsigned)vn->sc_secsize) {
986 vn->sc_secsize = *f;
988 vn->sc_size = vn->sc_fsize / vn->sc_secsize;
994 *f = vn->sc_size;
997 *o = vn->sc_size;
1006 if (vn->sc_shadow_vp != NULL) {
1010 if (vn->sc_vp == NULL) {
1024 error = vniocattach_shadow(vn, viop, dev, 0, p);
1039 if (vn->sc_flags & VNF_INITED) {
1052 error = vniocattach_file(vn, viop, dev, 0, p);
1077 vnclear(vn, &context);
1091 vn->sc_options |= *f;
1092 *f = vn->sc_options;
1096 vn->sc_options &= ~(*f);
1097 *f = vn->sc_options;
1129 vniocattach_file(struct vn_softc *vn,
1192 vn->sc_secsize = DEV_BSIZE;
1193 vn->sc_fsize = file_size;
1194 vn->sc_size = file_size / vn->sc_secsize;
1195 vn->sc_vp = nd.ni_vp;
1196 vn->sc_vid = vnode_vid(nd.ni_vp);
1197 vn->sc_open_flags = flags;
1198 vn->sc_cred = cred;
1200 vn->sc_cdev = devfs_make_node(cdev, DEVFS_CHAR,
1204 vn->sc_flags |= VNF_INITED;
1206 vn->sc_flags |= VNF_READONLY;
1213 vniocattach_shadow(struct vn_softc *vn, struct vn_ioctl_64 *vniop,
1243 map = shadow_map_create(vn->sc_fsize, file_size,
1244 0, vn->sc_secsize);
1248 vn->sc_shadow_vp = NULL;
1251 vn->sc_shadow_vp = nd.ni_vp;
1252 vn->sc_shadow_vid = vnode_vid(nd.ni_vp);
1253 vn->sc_shadow_vp->v_flag |= VNOCACHE_DATA;
1254 vn->sc_shadow_map = map;
1255 vn->sc_flags &= ~VNF_READONLY; /* we're now read/write */
1266 struct vn_softc * vn;
1272 vn = vn_table + ROOT_IMAGE_UNIT;
1275 snprintf(devname, 16, "vn%d", ROOT_IMAGE_UNIT);
1276 error = vniocattach_file(vn, &vnio, *dev_p, 1, current_proc());
1305 vnclear(struct vn_softc *vn, vfs_context_t ctx)
1307 if (vn->sc_vp != NULL) {
1309 (void)vn_close(vn->sc_vp, vn->sc_open_flags, ctx);
1310 vn->sc_vp = NULL;
1312 if (vn->sc_shadow_vp != NULL) {
1314 (void)vn_close(vn->sc_shadow_vp, FREAD | FWRITE, ctx);
1315 vn->sc_shadow_vp = NULL;
1317 if (vn->sc_shadow_map != NULL) {
1318 shadow_map_free(vn->sc_shadow_map);
1319 vn->sc_shadow_map = NULL;
1321 vn->sc_flags &= ~(VNF_INITED | VNF_READONLY);
1322 if (vn->sc_cred) {
1323 kauth_cred_unref(&vn->sc_cred);
1325 vn->sc_size = 0;
1326 vn->sc_fsize = 0;
1327 if (vn->sc_cdev) {
1328 devfs_remove(vn->sc_cdev);
1329 vn->sc_cdev = NULL;
1337 struct vn_softc *vn;
1347 vn = vn_table + unit;
1348 if ((vn->sc_flags & VNF_INITED) == 0)
1351 secsize = vn->sc_secsize;
1392 0600, "vn%d",