📄 cd9660_vnops.c
字号:
} /* * Get pointer to next entry. */ ep = (struct iso_directory_record *) (bp->b_un.b_addr + entryoffsetinblock); reclen = isonum_711 (ep->length); if (reclen == 0) { /* skip to next block, if any */ idp->curroff = roundup (idp->curroff, imp->logical_block_size); continue; } if (reclen < ISO_DIRECTORY_RECORD_SIZE) { error = EINVAL; /* illegal entry, stop */ break; } if (entryoffsetinblock + reclen > imp->logical_block_size) { error = EINVAL; /* illegal directory, so stop looking */ break; } idp->current.d_namlen = isonum_711 (ep->name_len); if (isonum_711(ep->flags)&2) isodirino(&idp->current.d_fileno,ep,imp); else idp->current.d_fileno = dbtob(bp->b_blkno) + idp->curroff; if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { error = EINVAL; /* illegal entry, stop */ break; } idp->curroff += reclen; /* * */ switch (imp->iso_ftype) { case ISO_FTYPE_RRIP: cd9660_rrip_getname(ep,idp->current.d_name, (u_short *)&idp->current.d_namlen, &idp->current.d_fileno,imp); if (idp->current.d_namlen) error = iso_uiodir(idp,&idp->current,idp->curroff); break; default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */ strcpy(idp->current.d_name,".."); switch (ep->name[0]) { case 0: idp->current.d_namlen = 1; error = iso_uiodir(idp,&idp->current,idp->curroff); break; case 1: idp->current.d_namlen = 2; error = iso_uiodir(idp,&idp->current,idp->curroff); break; default: isofntrans(ep->name,idp->current.d_namlen, idp->current.d_name, &elen, imp->iso_ftype == ISO_FTYPE_9660, isonum_711(ep->flags)&4); idp->current.d_namlen = (u_char)elen; if (imp->iso_ftype == ISO_FTYPE_DEFAULT) error = iso_shipdir(idp); else error = iso_uiodir(idp,&idp->current,idp->curroff); break; } } if (error) break; entryoffsetinblock += reclen; } if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { idp->current.d_namlen = 0; error = iso_shipdir(idp); } if (error < 0) error = 0; if (bp) brelse (bp); uio->uio_offset = idp->uio_off;#if 0 *eofflagp = idp->eof;#endif FREE(idp,M_TEMP); return (error);}/* * Return target name of a symbolic link * Shouldn't we get the parent vnode and read the data from there? * This could eventually result in deadlocks in cd9660_lookup. * But otherwise the block read here is in the block buffer two times. */typedef struct iso_directory_record ISODIR;typedef struct iso_node ISONODE;typedef struct iso_mnt ISOMNT;intcd9660_readlink(ap) struct vop_readlink_args /* { struct vnode *a_vp; struct uio *a_uio; struct ucred *a_cred; } */ *ap;{ ISONODE *ip; ISODIR *dirp; ISOMNT *imp; struct buf *bp; u_short symlen; int error; char *symname; ino_t ino; ip = VTOI(ap->a_vp); imp = ip->i_mnt; if (imp->iso_ftype != ISO_FTYPE_RRIP) return EINVAL; /* * Get parents directory record block that this inode included. */ error = bread(imp->im_devvp, (daddr_t)(ip->i_number / DEV_BSIZE), imp->logical_block_size, NOCRED, &bp); if (error) { brelse(bp); return EINVAL; } /* * Setup the directory pointer for this inode */ dirp = (ISODIR *)(bp->b_un.b_addr + (ip->i_number & imp->im_bmask));#ifdef DEBUG printf("lbn=%d,off=%d,bsize=%d,DEV_BSIZE=%d, dirp= %08x, b_addr=%08x, offset=%08x(%08x)\n", (daddr_t)(ip->i_number >> imp->im_bshift), ip->i_number & imp->im_bmask, imp->logical_block_size, DEV_BSIZE, dirp, bp->b_un.b_addr, ip->i_number, ip->i_number & imp->im_bmask );#endif /* * Just make sure, we have a right one.... * 1: Check not cross boundary on block */ if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length) > imp->logical_block_size) { brelse(bp); return EINVAL; } /* * Now get a buffer * Abuse a namei buffer for now. */ MALLOC(symname,char *,MAXPATHLEN,M_NAMEI,M_WAITOK); /* * Ok, we just gathering a symbolic name in SL record. */ if (cd9660_rrip_getsymname(dirp,symname,&symlen,imp) == 0) { FREE(symname,M_NAMEI); brelse(bp); return EINVAL; } /* * Don't forget before you leave from home ;-) */ brelse(bp); /* * return with the symbolic name to caller's. */ error = uiomove(symname,symlen,ap->a_uio); FREE(symname,M_NAMEI); return error;}/* * Ufs abort op, called after namei() when a CREATE/DELETE isn't actually * done. If a buffer has been saved in anticipation of a CREATE, delete it. */intcd9660_abortop(ap) struct vop_abortop_args /* { struct vnode *a_dvp; struct componentname *a_cnp; } */ *ap;{ if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF) FREE(ap->a_cnp->cn_pnbuf, M_NAMEI); return 0;}/* * Lock an inode. */intcd9660_lock(ap) struct vop_lock_args /* { struct vnode *a_vp; } */ *ap;{ register struct iso_node *ip = VTOI(ap->a_vp); ISO_ILOCK(ip); return 0;}/* * Unlock an inode. */intcd9660_unlock(ap) struct vop_unlock_args /* { struct vnode *a_vp; } */ *ap;{ register struct iso_node *ip = VTOI(ap->a_vp); if (!(ip->i_flag & ILOCKED)) panic("cd9660_unlock NOT LOCKED"); ISO_IUNLOCK(ip); return 0;}/* * Check for a locked inode. */intcd9660_islocked(ap) struct vop_islocked_args /* { struct vnode *a_vp; } */ *ap;{ if (VTOI(ap->a_vp)->i_flag & ILOCKED) return 1; return 0;}/* * Calculate the logical to physical mapping if not done already, * then call the device strategy routine. */intcd9660_strategy(ap) struct vop_strategy_args /* { struct buf *a_bp; } */ *ap;{ register struct buf *bp = ap->a_bp; register struct vnode *vp = bp->b_vp; register struct iso_node *ip; int error; ip = VTOI(vp); if (vp->v_type == VBLK || vp->v_type == VCHR) panic("cd9660_strategy: spec"); if (bp->b_blkno == bp->b_lblkno) { if (error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL)) { bp->b_error = error; bp->b_flags |= B_ERROR; biodone(bp); return (error); } if ((long)bp->b_blkno == -1) clrbuf(bp); } if ((long)bp->b_blkno == -1) { biodone(bp); return (0); } vp = ip->i_devvp; bp->b_dev = vp->v_rdev; VOCALL (vp->v_op, VOFFSET(vop_strategy), ap); return (0);}/* * Print out the contents of an inode. */intcd9660_print(ap) struct vop_print_args /* { struct vnode *a_vp; } */ *ap;{ printf("tag VT_ISOFS, isofs vnode\n"); return 0;}/* * Unsupported operation */intcd9660_enotsupp(){ return (EOPNOTSUPP);}/* * Global vfs data structures for isofs */#define cd9660_create \ ((int (*) __P((struct vop_create_args *)))cd9660_enotsupp)#define cd9660_mknod ((int (*) __P((struct vop_mknod_args *)))cd9660_enotsupp)#define cd9660_setattr \ ((int (*) __P((struct vop_setattr_args *)))cd9660_enotsupp)#define cd9660_write ((int (*) __P((struct vop_write_args *)))cd9660_enotsupp)#define cd9660_fsync ((int (*) __P((struct vop_fsync_args *)))nullop)#define cd9660_remove \ ((int (*) __P((struct vop_remove_args *)))cd9660_enotsupp)#define cd9660_link ((int (*) __P((struct vop_link_args *)))cd9660_enotsupp)#define cd9660_rename \ ((int (*) __P((struct vop_rename_args *)))cd9660_enotsupp)#define cd9660_mkdir ((int (*) __P((struct vop_mkdir_args *)))cd9660_enotsupp)#define cd9660_rmdir ((int (*) __P((struct vop_rmdir_args *)))cd9660_enotsupp)#define cd9660_symlink \ ((int (*) __P((struct vop_symlink_args *)))cd9660_enotsupp)#define cd9660_pathconf \ ((int (*) __P((struct vop_pathconf_args *)))cd9660_enotsupp)#define cd9660_advlock \ ((int (*) __P((struct vop_advlock_args *)))cd9660_enotsupp)#define cd9660_blkatoff \ ((int (*) __P((struct vop_blkatoff_args *)))cd9660_enotsupp)#define cd9660_valloc ((int(*) __P(( \ struct vnode *pvp, \ int mode, \ struct ucred *cred, \ struct vnode **vpp))) cd9660_enotsupp)#define cd9660_vfree ((int (*) __P((struct vop_vfree_args *)))cd9660_enotsupp)#define cd9660_truncate \ ((int (*) __P((struct vop_truncate_args *)))cd9660_enotsupp)#define cd9660_update \ ((int (*) __P((struct vop_update_args *)))cd9660_enotsupp)#define cd9660_bwrite \ ((int (*) __P((struct vop_bwrite_args *)))cd9660_enotsupp)/* * Global vfs data structures for nfs */int (**cd9660_vnodeop_p)();struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = { { &vop_default_desc, vn_default_error }, { &vop_lookup_desc, cd9660_lookup }, /* lookup */ { &vop_create_desc, cd9660_create }, /* create */ { &vop_mknod_desc, cd9660_mknod }, /* mknod */ { &vop_open_desc, cd9660_open }, /* open */ { &vop_close_desc, cd9660_close }, /* close */ { &vop_access_desc, cd9660_access }, /* access */ { &vop_getattr_desc, cd9660_getattr }, /* getattr */ { &vop_setattr_desc, cd9660_setattr }, /* setattr */ { &vop_read_desc, cd9660_read }, /* read */ { &vop_write_desc, cd9660_write }, /* write */ { &vop_ioctl_desc, cd9660_ioctl }, /* ioctl */ { &vop_select_desc, cd9660_select }, /* select */ { &vop_mmap_desc, cd9660_mmap }, /* mmap */ { &vop_fsync_desc, cd9660_fsync }, /* fsync */ { &vop_seek_desc, cd9660_seek }, /* seek */ { &vop_remove_desc, cd9660_remove }, /* remove */ { &vop_link_desc, cd9660_link }, /* link */ { &vop_rename_desc, cd9660_rename }, /* rename */ { &vop_mkdir_desc, cd9660_mkdir }, /* mkdir */ { &vop_rmdir_desc, cd9660_rmdir }, /* rmdir */ { &vop_symlink_desc, cd9660_symlink }, /* symlink */ { &vop_readdir_desc, cd9660_readdir }, /* readdir */ { &vop_readlink_desc, cd9660_readlink },/* readlink */ { &vop_abortop_desc, cd9660_abortop }, /* abortop */ { &vop_inactive_desc, cd9660_inactive },/* inactive */ { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ { &vop_lock_desc, cd9660_lock }, /* lock */ { &vop_unlock_desc, cd9660_unlock }, /* unlock */ { &vop_bmap_desc, cd9660_bmap }, /* bmap */ { &vop_strategy_desc, cd9660_strategy },/* strategy */ { &vop_print_desc, cd9660_print }, /* print */ { &vop_islocked_desc, cd9660_islocked },/* islocked */ { &vop_pathconf_desc, cd9660_pathconf },/* pathconf */ { &vop_advlock_desc, cd9660_advlock }, /* advlock */ { &vop_blkatoff_desc, cd9660_blkatoff },/* blkatoff */ { &vop_valloc_desc, cd9660_valloc }, /* valloc */ { &vop_vfree_desc, cd9660_vfree }, /* vfree */ { &vop_truncate_desc, cd9660_truncate },/* truncate */ { &vop_update_desc, cd9660_update }, /* update */ { &vop_bwrite_desc, vn_bwrite }, { (struct vnodeop_desc*)NULL, (int(*)())NULL }};struct vnodeopv_desc cd9660_vnodeop_opv_desc = { &cd9660_vnodeop_p, cd9660_vnodeop_entries };/* * Special device vnode ops */int (**cd9660_specop_p)();struct vnodeopv_entry_desc cd9660_specop_entries[] = { { &vop_default_desc, vn_default_error }, { &vop_lookup_desc, spec_lookup }, /* lookup */ { &vop_create_desc, cd9660_create }, /* create */ { &vop_mknod_desc, cd9660_mknod }, /* mknod */ { &vop_open_desc, spec_open }, /* open */ { &vop_close_desc, spec_close }, /* close */ { &vop_access_desc, cd9660_access }, /* access */ { &vop_getattr_desc, cd9660_getattr }, /* getattr */ { &vop_setattr_desc, cd9660_setattr }, /* setattr */ { &vop_read_desc, spec_read }, /* read */ { &vop_write_desc, spec_write }, /* write */ { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ { &vop_select_desc, spec_select }, /* select */ { &vop_mmap_desc, spec_mmap }, /* mmap */ { &vop_fsync_desc, spec_fsync }, /* fsync */ { &vop_seek_desc, spec_seek }, /* seek */ { &vop_remove_desc, cd9660_remove }, /* remove */ { &vop_link_desc, cd9660_link }, /* link */ { &vop_rename_desc, cd9660_rename }, /* rename */ { &vop_mkdir_desc, cd9660_mkdir }, /* mkdir */ { &vop_rmdir_desc, cd9660_rmdir }, /* rmdir */ { &vop_symlink_desc, cd9660_symlink }, /* symlink */ { &vop_readdir_desc, spec_readdir }, /* readdir */ { &vop_readlink_desc, spec_readlink }, /* readlink */ { &vop_abortop_desc, spec_abortop }, /* abortop */ { &vop_inactive_desc, cd9660_inactive },/* inactive */ { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ { &vop_lock_desc, cd9660_lock }, /* lock */ { &vop_unlock_desc, cd9660_unlock }, /* unlock */ { &vop_bmap_desc, spec_bmap }, /* bmap */ /* XXX strategy: panics, should be notsupp instead? */ { &vop_strategy_desc, cd9660_strategy },/* strategy */ { &vop_print_desc, cd9660_print }, /* print */ { &vop_islocked_desc, cd9660_islocked },/* islocked */ { &vop_pathconf_desc, spec_pathconf }, /* pathconf */ { &vop_advlock_desc, spec_advlock }, /* advlock */ { &vop_blkatoff_desc, spec_blkatoff }, /* blkatoff */ { &vop_valloc_desc, spec_valloc }, /* valloc */ { &vop_vfree_desc, spec_vfree }, /* vfree */ { &vop_truncate_desc, spec_truncate }, /* truncate */ { &vop_update_desc, cd9660_update }, /* update */ { &vop_bwrite_desc, vn_bwrite }, { (struct vnodeop_desc*)NULL, (int(*)())NULL }};struct vnodeopv_desc cd9660_specop_opv_desc = { &cd9660_specop_p, cd9660_specop_entries };#ifdef FIFOint (**cd9660_fifoop_p)();struct vnodeopv_entry_desc cd9660_fifoop_entries[] = { { &vop_default_desc, vn_default_error }, { &vop_lookup_desc, fifo_lookup }, /* lookup */ { &vop_create_desc, cd9660_create }, /* create */ { &vop_mknod_desc, cd9660_mknod }, /* mknod */ { &vop_open_desc, fifo_open }, /* open */ { &vop_close_desc, fifo_close }, /* close */ { &vop_access_desc, cd9660_access }, /* access */ { &vop_getattr_desc, cd9660_getattr }, /* getattr */ { &vop_setattr_desc, cd9660_setattr }, /* setattr */ { &vop_read_desc, fifo_read }, /* read */ { &vop_write_desc, fifo_write }, /* write */ { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */ { &vop_select_desc, fifo_select }, /* select */ { &vop_mmap_desc, fifo_mmap }, /* mmap */ { &vop_fsync_desc, fifo_fsync }, /* fsync */ { &vop_seek_desc, fifo_seek }, /* seek */ { &vop_remove_desc, cd9660_remove }, /* remove */ { &vop_link_desc, cd9660_link }, /* link */ { &vop_rename_desc, cd9660_rename }, /* rename */ { &vop_mkdir_desc, cd9660_mkdir }, /* mkdir */ { &vop_rmdir_desc, cd9660_rmdir }, /* rmdir */ { &vop_symlink_desc, cd9660_symlink }, /* symlink */ { &vop_readdir_desc, fifo_readdir }, /* readdir */ { &vop_readlink_desc, fifo_readlink }, /* readlink */ { &vop_abortop_desc, fifo_abortop }, /* abortop */ { &vop_inactive_desc, cd9660_inactive },/* inactive */ { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ { &vop_lock_desc, cd9660_lock }, /* lock */ { &vop_unlock_desc, cd9660_unlock }, /* unlock */ { &vop_bmap_desc, fifo_bmap }, /* bmap */ { &vop_strategy_desc, fifo_badop }, /* strategy */ { &vop_print_desc, cd9660_print }, /* print */ { &vop_islocked_desc, cd9660_islocked },/* islocked */ { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */ { &vop_advlock_desc, fifo_advlock }, /* advlock */ { &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */ { &vop_valloc_desc, fifo_valloc }, /* valloc */ { &vop_vfree_desc, fifo_vfree }, /* vfree */ { &vop_truncate_desc, fifo_truncate }, /* truncate */ { &vop_update_desc, cd9660_update }, /* update */ { &vop_bwrite_desc, vn_bwrite }, { (struct vnodeop_desc*)NULL, (int(*)())NULL }};struct vnodeopv_desc cd9660_fifoop_opv_desc = { &cd9660_fifoop_p, cd9660_fifoop_entries };#endif /* FIFO */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -