#include <sys/param.h>
#include <sys/systm.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/namei.h>
#include <sys/resourcevar.h>
#include <sys/kernel.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/kauth.h>
#include <sys/conf.h>
#include <miscfs/specfs/specdev.h>
#include <miscfs/fifofs/fifo.h>
#include <sys/malloc.h>
#include <sys/dir.h>
#include <sys/attr.h>
#include <vfs/vfs_support.h>
#include <vm/vm_kern.h>
#include <sys/ubc.h>
#include <sys/lock.h>
#include <sys/ubc_internal.h>
#include <sys/uio_internal.h>
#include <architecture/byte_order.h>
#include <vm/vm_map.h>
#include <vm/vm_kern.h>
#include <isofs/cd9660/iso.h>
#include <isofs/cd9660/cd9660_node.h>
#include <isofs/cd9660/iso_rrip.h>
int
cd9660_open(__unused struct vnop_open_args *ap)
{
return (0);
}
int
cd9660_close(__unused struct vnop_close_args *ap)
{
return (0);
}
int
cd9660_getattr(struct vnop_getattr_args *ap)
{
struct vnode *vp = ap->a_vp;
register struct vnode_attr *vap = ap->a_vap;
register struct iso_node *ip = VTOI(vp);
VATTR_RETURN(vap, va_fsid, ip->i_dev);
VATTR_RETURN(vap, va_fileid, ip->i_number);
VATTR_RETURN(vap, va_mode, ip->inode.iso_mode);
VATTR_RETURN(vap, va_nlink, ip->inode.iso_links);
VATTR_RETURN(vap, va_uid, ip->inode.iso_uid);
VATTR_RETURN(vap, va_gid, ip->inode.iso_gid);
VATTR_RETURN(vap, va_access_time, ip->inode.iso_atime);
VATTR_RETURN(vap, va_modify_time, ip->inode.iso_mtime);
VATTR_RETURN(vap, va_change_time, ip->inode.iso_ctime);
VATTR_RETURN(vap, va_rdev, ip->inode.iso_rdev);
VATTR_RETURN(vap, va_data_size, (off_t)ip->i_size);
if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
struct vnop_readlink_args rdlnk;
uio_t auio;
char uio_buf[ UIO_SIZEOF(1) ];
char *cp;
MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
auio = uio_createwithbuffer(1, 0, UIO_SYSSPACE, UIO_READ,
&uio_buf[0], sizeof(uio_buf));
uio_addiov(auio, CAST_USER_ADDR_T(cp), MAXPATHLEN);
rdlnk.a_uio = auio;
rdlnk.a_vp = ap->a_vp;
rdlnk.a_context = ap->a_context;
if (cd9660_readlink(&rdlnk) == 0)
VATTR_RETURN(vap, va_data_size, MAXPATHLEN - uio_resid(auio));
FREE(cp, M_TEMP);
}
VATTR_RETURN(vap, va_flags, 0);
VATTR_RETURN(vap, va_gen, 1);
VATTR_RETURN(vap, va_iosize, ip->i_mnt->logical_block_size);
VATTR_RETURN(vap, va_total_size, ip->i_size + ip->i_rsrcsize);
return (0);
}
int
cd9660_read(struct vnop_read_args *ap)
{
struct vnode *vp = ap->a_vp;
register struct uio *uio = ap->a_uio;
register struct iso_node *ip = VTOI(vp);
register struct iso_mnt *imp;
struct buf *bp;
daddr_t lbn;
daddr64_t rablock;
off_t diff;
int rasize, error = 0;
int32_t size, n, on;
if (uio_resid(uio) == 0)
return (0);
if (uio->uio_offset < 0)
return (EINVAL);
imp = ip->i_mnt;
if (UBCINFOEXISTS(vp)) {
if ((ip->i_flag & ISO_ASSOCIATED) && (uio->uio_offset < ADH_SIZE)) {
apple_double_header_t header;
int bytes;
if (uio->uio_offset < sizeof(apple_double_header_t)) {
header.magic = APPLEDOUBLE_MAGIC;
header.version = APPLEDOUBLE_VERSION;
header.count = 2;
header.entries[0].entryID = APPLEDOUBLE_FINDERINFO;
header.entries[0].offset = offsetof(apple_double_header_t, finfo);
header.entries[0].length = 32;
header.entries[1].entryID = APPLEDOUBLE_RESFORK;
header.entries[1].offset = ADH_SIZE;
header.entries[1].length = ip->i_size - ADH_SIZE;
header.finfo.fdType = ip->i_FileType;
header.finfo.fdCreator = ip->i_Creator;
header.finfo.fdFlags = ip->i_FinderFlags;
header.finfo.fdLocation.v = -1;
header.finfo.fdLocation.h = -1;
header.finfo.fdReserved = 0;
bytes = min(uio_resid(uio), sizeof(apple_double_header_t) - uio->uio_offset);
error = uiomove(((char *) &header) + uio->uio_offset, bytes, uio);
if (error)
return error;
}
if (uio_resid(uio) && uio->uio_offset < ADH_SIZE) {
caddr_t buffer;
if (kmem_alloc(kernel_map, (vm_offset_t *)&buffer, ADH_SIZE)) {
return (ENOMEM);
}
bytes = min(uio_resid(uio), ADH_SIZE - uio->uio_offset);
error = uiomove(((char *) buffer) + uio->uio_offset, bytes, uio);
kmem_free(kernel_map, (vm_offset_t)buffer, ADH_SIZE);
if (error)
return error;
}
}
if (uio_resid(uio) > 0)
error = cluster_read(vp, uio, (off_t)ip->i_size, 0);
} else {
do {
lbn = lblkno(imp, uio->uio_offset);
on = blkoff(imp, uio->uio_offset);
n = min((u_int)(imp->logical_block_size - on),
uio_resid(uio));
diff = (off_t)ip->i_size - uio->uio_offset;
if (diff <= 0)
return (0);
if (diff < n)
n = diff;
size = blksize(imp, ip, lbn);
rablock = (daddr64_t)lbn + 1;
if (ip->i_lastr + 1 == lbn &&
lblktosize(imp, rablock) < ip->i_size) {
rasize = blksize(imp, ip, (daddr_t)rablock);
error = (int)buf_breadn(vp, (daddr64_t)((unsigned)lbn), size, &rablock,
&rasize, 1, NOCRED, &bp);
} else
error = (int)buf_bread(vp, (daddr64_t)((unsigned)lbn), size, NOCRED, &bp);
ip->i_lastr = lbn;
n = min(n, size - buf_resid(bp));
if (error) {
buf_brelse(bp);
return (error);
}
error = uiomove((caddr_t)(buf_dataptr(bp) + on), (int)n, uio);
if (n + on == imp->logical_block_size ||
uio->uio_offset == (off_t)ip->i_size)
buf_markaged(bp);
buf_brelse(bp);
} while (error == 0 && uio_resid(uio) > 0 && n != 0);
}
return (error);
}
int
cd9660_ioctl(__unused struct vnop_ioctl_args *ap)
{
return (ENOTTY);
}
int
cd9660_select(__unused struct vnop_select_args *ap)
{
return (1);
}
int
cd9660_mmap(__unused struct vnop_mmap_args *ap)
{
return (EINVAL);
}
struct isoreaddir {
struct dirent saveent;
struct dirent current;
off_t saveoff;
off_t curroff;
struct uio *uio;
off_t uio_off;
int eofflag;
};
static int
iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off)
{
int error;
dp->d_name[dp->d_namlen] = 0;
dp->d_reclen = DIRSIZ(dp);
if (uio_resid(idp->uio) < dp->d_reclen) {
idp->eofflag = 0;
return (-1);
}
#if 0
if (idp->cookies) {
if (*idp->ncookies <= 0) {
idp->eofflag = 0;
return (-1);
}
**idp->cookies++ = off;
--*idp->ncookies;
}
#endif
if ( (error = uiomove( (caddr_t)dp, dp->d_reclen, idp->uio )) )
return (error);
idp->uio_off = off;
return (0);
}
static int
iso_shipdir(struct isoreaddir *idp)
{
struct dirent *dp;
int cl, sl;
int error;
char *cname, *sname;
cl = idp->current.d_namlen;
cname = idp->current.d_name;
dp = &idp->saveent;
sname = dp->d_name;
sl = dp->d_namlen;
if (sl > 0) {
if (sl != cl
|| bcmp(sname,cname,sl)) {
if (idp->saveent.d_namlen) {
if ( (error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) )
return (error);
idp->saveent.d_namlen = 0;
}
}
}
idp->current.d_reclen = DIRSIZ(&idp->current);
idp->saveoff = idp->curroff;
bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
return (0);
}
int
cd9660_readdir(struct vnop_readdir_args *ap)
{
register struct uio *uio = ap->a_uio;
off_t startingOffset = uio->uio_offset;
size_t lost = 0;
struct isoreaddir *idp;
struct vnode *vdp = ap->a_vp;
struct iso_node *dp;
struct iso_mnt *imp;
struct buf *bp = NULL;
struct iso_directory_record *ep;
int entryoffsetinblock;
doff_t endsearch;
uint32_t bmask;
int error = 0;
int reclen;
u_short namelen;
if (ap->a_flags & (VNODE_READDIR_EXTENDED | VNODE_READDIR_REQSEEKOFF))
return (EINVAL);
dp = VTOI(vdp);
imp = dp->i_mnt;
bmask = imp->im_sector_size - 1;
MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
idp->saveent.d_namlen = 0;
idp->saveent.d_type = idp->current.d_type = DT_UNKNOWN;
idp->uio = uio;
idp->eofflag = 1;
idp->curroff = uio->uio_offset;
if ((entryoffsetinblock = idp->curroff & bmask) &&
(error = cd9660_blkatoff(vdp, SECTOFF(imp, idp->curroff), NULL, &bp))) {
FREE(idp, M_TEMP);
return (error);
}
endsearch = dp->i_size;
while (idp->curroff < endsearch) {
if ((idp->curroff & bmask) == 0) {
if (bp != NULL)
buf_brelse(bp);
if ((error = cd9660_blkatoff(vdp, SECTOFF(imp, idp->curroff), NULL, &bp)))
break;
entryoffsetinblock = 0;
}
ep = (struct iso_directory_record *)
(buf_dataptr(bp) + entryoffsetinblock);
reclen = isonum_711(ep->length);
if (reclen == 0) {
idp->curroff =
(idp->curroff & ~bmask) + imp->im_sector_size;
continue;
}
if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
error = EINVAL;
break;
}
if (entryoffsetinblock + reclen > imp->im_sector_size) {
error = EINVAL;
break;
}
idp->current.d_namlen = isonum_711(ep->name_len);
if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
error = EINVAL;
break;
}
if ((uio->uio_offset == 0) && (isonum_733(ep->size) > endsearch)) {
dp->i_size = endsearch = isonum_733(ep->size);
}
if ( isonum_711(ep->flags) & directoryBit )
idp->current.d_fileno = isodirino(ep, imp);
else {
idp->current.d_fileno = ((daddr_t)buf_blkno(bp) << imp->im_bshift) +
entryoffsetinblock;
}
idp->curroff += reclen;
switch (imp->iso_ftype) {
case ISO_FTYPE_RRIP:
cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
&idp->current.d_fileno,imp);
idp->current.d_namlen = (u_char)namelen;
if (idp->current.d_namlen)
error = iso_uiodir(idp,&idp->current,idp->curroff);
break;
case ISO_FTYPE_JOLIET:
ucsfntrans((u_int16_t *)ep->name, idp->current.d_namlen,
idp->current.d_name, &namelen,
isonum_711(ep->flags) & directoryBit,
isonum_711(ep->flags) & associatedBit);
idp->current.d_namlen = (u_char)namelen;
if (idp->current.d_namlen)
error = iso_uiodir(idp,&idp->current,idp->curroff);
break;
default:
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, &namelen,
imp->iso_ftype == ISO_FTYPE_9660,
isonum_711(ep->flags) & associatedBit);
idp->current.d_namlen = (u_char)namelen;
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 0
if (!error && ap->a_ncookies) {
struct dirent *dirp, *dpstart;
off_t bufferOffset;
u_long *cookies;
int ncookies;
if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg) || uio->uio_iovcnt != 1)
panic("ufs_readdir: lost in space");
dpstart = (struct dirent *)
CAST_DOWN(caddr_t, (uio_iov_base(uio) - (uio->uio_offset - startingOffset)));
for (dirp = dpstart, bufferOffset = startingOffset, ncookies = 0;
bufferOffset < uio->uio_offset; ) {
if (dirp->d_reclen == 0)
break;
bufferOffset += dirp->d_reclen;
ncookies++;
dirp = (struct dirent *)((caddr_t)dirp + dirp->d_reclen);
}
lost += uio->uio_offset - bufferOffset;
uio->uio_offset = bufferOffset;
MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP, M_WAITOK);
*ap->a_ncookies = ncookies;
*ap->a_cookies = cookies;
for (bufferOffset = startingOffset, dirp = dpstart; bufferOffset < uio->uio_offset; ) {
*(cookies++) = bufferOffset;
bufferOffset += dirp->d_reclen;
dirp = (struct dirent *)((caddr_t)dirp + dirp->d_reclen);
}
}
#endif
if (error < 0)
error = 0;
if (bp)
buf_brelse (bp);
uio->uio_offset = idp->uio_off;
*ap->a_eofflag = idp->eofflag;
FREE(idp, M_TEMP);
return (error);
}
typedef struct iso_directory_record ISODIR;
typedef struct iso_node ISONODE;
typedef struct iso_mnt ISOMNT;
int
cd9660_readlink(struct vnop_readlink_args *ap)
{
ISONODE *ip;
ISODIR *dirp;
ISOMNT *imp;
struct buf *bp;
struct uio *uio;
u_short symlen;
int error;
char *symname;
ip = VTOI(ap->a_vp);
imp = ip->i_mnt;
uio = ap->a_uio;
if (imp->iso_ftype != ISO_FTYPE_RRIP)
return (EINVAL);
error = (int)buf_bread(imp->im_devvp,
(daddr64_t)((unsigned)(ip->i_number >> imp->im_bshift)),
imp->logical_block_size, NOCRED, &bp);
if (error) {
buf_brelse(bp);
return (EINVAL);
}
dirp = (ISODIR *)(buf_dataptr(bp) + (ip->i_number & imp->im_bmask));
if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
> imp->logical_block_size) {
buf_brelse(bp);
return (EINVAL);
}
if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg))
MALLOC_ZONE(symname, char *, MAXPATHLEN, M_NAMEI, M_WAITOK);
else
symname = CAST_DOWN(caddr_t, uio_iov_base(uio));
if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg))
FREE_ZONE(symname, MAXPATHLEN, M_NAMEI);
buf_brelse(bp);
return (EINVAL);
}
buf_brelse(bp);
if (UIO_SEG_IS_USER_SPACE(uio->uio_segflg)) {
error = uiomove(symname, symlen, uio);
FREE_ZONE(symname, MAXPATHLEN, M_NAMEI);
return (error);
}
#if LP64KERN
uio_setresid(uio, (uio_resid(uio) - symlen));
uio_iov_len_add(uio, -((int64_t)symlen));
#else
uio_setresid(uio, (uio_resid(uio) - symlen));
uio_iov_len_add(uio, -((int)symlen));
#endif
uio_iov_base_add(uio, symlen);
return (0);
}
int
cd9660_strategy(struct vnop_strategy_args *ap)
{
buf_t bp = ap->a_bp;
vnode_t vp = buf_vnode(bp);
struct iso_node *ip = VTOI(vp);
return (buf_strategy(ip->i_devvp, ap));
}
int
cd9660_pathconf(struct vnop_pathconf_args *ap)
{
switch (ap->a_name) {
case _PC_LINK_MAX:
*ap->a_retval = 1;
return (0);
case _PC_NAME_MAX:
switch (VTOI(ap->a_vp)->i_mnt->iso_ftype) {
case ISO_FTYPE_RRIP:
*ap->a_retval = ISO_RRIP_NAMEMAX;
break;
case ISO_FTYPE_JOLIET:
*ap->a_retval = ISO_JOLIET_NAMEMAX;
break;
default:
*ap->a_retval = ISO_NAMEMAX;
}
return (0);
case _PC_PATH_MAX:
*ap->a_retval = PATH_MAX;
return (0);
case _PC_PIPE_BUF:
*ap->a_retval = PIPE_BUF;
return (0);
case _PC_CHOWN_RESTRICTED:
*ap->a_retval = 1;
return (0);
case _PC_NO_TRUNC:
*ap->a_retval = 1;
return (0);
default:
return (EINVAL);
}
}
int
cd9660_enotsupp(void)
{
return (ENOTSUP);
}
int
cd9660_pagein(struct vnop_pagein_args *ap)
{
struct vnode *vp = ap->a_vp;
upl_t pl = ap->a_pl;
size_t size = ap->a_size;
off_t f_offset = ap->a_f_offset;
vm_offset_t pl_offset = ap->a_pl_offset;
int flags = ap->a_flags;
register struct iso_node *ip = VTOI(vp);
int error = 0;
if ((ip->i_flag & ISO_ASSOCIATED) && (f_offset == 0) && (size == ADH_SIZE)) {
apple_double_header_t header;
kern_return_t kret;
vm_offset_t ioaddr;
kret = ubc_upl_map(pl, &ioaddr);
if (kret != KERN_SUCCESS)
panic("cd9660_xa_pagein: ubc_upl_map error = %d", kret);
ioaddr += pl_offset;
bzero((caddr_t)ioaddr, ADH_SIZE);
header.magic = APPLEDOUBLE_MAGIC;
header.version = APPLEDOUBLE_VERSION;
header.count = 2;
header.entries[0].entryID = APPLEDOUBLE_FINDERINFO;
header.entries[0].offset = offsetof(apple_double_header_t, finfo);
header.entries[0].length = 32;
header.entries[1].entryID = APPLEDOUBLE_RESFORK;
header.entries[1].offset = ADH_SIZE;
header.entries[1].length = ip->i_size - ADH_SIZE;
header.finfo.fdType = ip->i_FileType;
header.finfo.fdCreator = ip->i_Creator;
header.finfo.fdFlags = ip->i_FinderFlags;
header.finfo.fdLocation.v = -1;
header.finfo.fdLocation.h = -1;
header.finfo.fdReserved = 0;
bcopy((caddr_t)&header, (caddr_t)ioaddr, sizeof(apple_double_header_t));
kret = ubc_upl_unmap(pl);
if (kret != KERN_SUCCESS)
panic("cd9660_xa_pagein: ubc_upl_unmap error = %d", kret);
if ((flags & UPL_NOCOMMIT) == 0) {
ubc_upl_commit_range(pl, pl_offset, size, UPL_COMMIT_FREE_ON_EMPTY);
}
} else {
if (UBCINVALID(vp))
panic("cd9660_pagein: Not a VREG");
UBCINFOCHECK("cd9660_pagein", vp);
error = cluster_pagein(vp, pl, pl_offset, f_offset, size,
(off_t)ip->i_size, flags);
}
return (error);
}
int
cd9660_remove(__unused struct vnop_remove_args *ap)
{
return (EROFS);
}
int
cd9660_rmdir(struct vnop_rmdir_args *ap)
{
(void) nop_rmdir(ap);
return (EROFS);
}
int
cd9660_getattrlist(struct vnop_getattrlist_args *ap)
{
struct attrlist *alist = ap->a_alist;
int fixedblocksize;
int attrblocksize;
int attrbufsize;
void *attrbufptr;
void *attrptr;
void *varptr;
int error = 0;
if ((alist->bitmapcount != ATTR_BIT_MAP_COUNT) ||
((alist->commonattr & ~ATTR_CMN_VALIDMASK) != 0) ||
((alist->volattr & ~ATTR_VOL_VALIDMASK) != 0) ||
((alist->dirattr & ~ATTR_DIR_VALIDMASK) != 0) ||
((alist->fileattr & ~ATTR_FILE_VALIDMASK) != 0) ||
((alist->forkattr & ~ATTR_FORK_VALIDMASK) != 0)) {
return EINVAL;
};
if ((alist->volattr != 0) &&
(((alist->volattr & ATTR_VOL_INFO) == 0) ||
(alist->dirattr != 0) ||
(alist->fileattr != 0) ||
(alist->forkattr != 0) )) {
return EINVAL;
};
if (alist->volattr & ATTR_VOL_MOUNTPOINT) return EINVAL;
if (alist->commonattr & (ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST)) return EINVAL;
if (alist->fileattr &
(ATTR_FILE_FILETYPE |
ATTR_FILE_FORKCOUNT |
ATTR_FILE_FORKLIST |
ATTR_FILE_DATAEXTENTS |
ATTR_FILE_RSRCEXTENTS)) {
return EINVAL;
};
fixedblocksize = attrcalcsize(alist);
attrblocksize = fixedblocksize + (sizeof(uint32_t));
if (alist->commonattr & ATTR_CMN_NAME) attrblocksize += NAME_MAX;
if (alist->commonattr & ATTR_CMN_NAMEDATTRLIST) attrblocksize += 0;
if (alist->volattr & ATTR_VOL_MOUNTPOINT) attrblocksize += PATH_MAX;
if (alist->volattr & ATTR_VOL_NAME) attrblocksize += NAME_MAX;
if (alist->fileattr & ATTR_FILE_FORKLIST) attrblocksize += 0;
attrbufsize = MIN(uio_resid(ap->a_uio), attrblocksize);
MALLOC(attrbufptr, void *, attrblocksize, M_TEMP, M_WAITOK);
attrptr = attrbufptr;
*((uint32_t *)attrptr) = 0;
++((uint32_t *)attrptr);
varptr = ((char *)attrptr) + fixedblocksize;
packattrblk(alist, ap->a_vp, &attrptr, &varptr);
*((uint32_t *)attrbufptr) = ((char*)varptr - (char*)attrbufptr);
attrbufsize = MIN(attrbufsize, (char*)varptr - (char*)attrbufptr);
error = uiomove((caddr_t)attrbufptr, attrbufsize, ap->a_uio);
FREE(attrbufptr, M_TEMP);
return error;
}
__private_extern__ void
cd9660_xa_init(struct iso_node *ip, struct iso_directory_record *isodir)
{
uint32_t sectors;
struct riff_header *header;
u_char name_len;
char *cdxa;
MALLOC(header, struct riff_header *, sizeof(struct riff_header), M_TEMP, M_WAITOK);
sectors = ip->i_size / 2048;
strncpy(header->riff, "RIFF", 4);
header->fileSize = NXSwapHostLongToLittle(sectors * CDXA_SECTOR_SIZE + sizeof(struct riff_header) - 8);
strncpy(header->cdxa, "CDXA", 4);
strncpy(header->fmt, "fmt ", 4);
header->fmtSize = NXSwapHostLongToLittle(16);
strncpy(header->data, "data", 4);
header->dataSize = NXSwapHostLongToLittle(sectors * CDXA_SECTOR_SIZE);
name_len = isonum_711(isodir->name_len);
cdxa = &isodir->name[name_len];
if ((name_len & 0x01) == 0)
++cdxa;
bcopy(cdxa, header->fmtData, 14);
header->fmtData[14] = 0;
header->fmtData[15] = 0;
ip->i_devvp = ip->i_mnt->phys_devvp;
ip->i_size = sectors * CDXA_SECTOR_SIZE + sizeof(struct riff_header);
ip->i_riff = header;
}
static int
cd9660_xa_read_common(
struct vnode *vp,
off_t offset,
size_t amount,
caddr_t buffer,
struct uio *uio)
{
struct iso_node *ip = VTOI(vp);
struct buf *bp;
off_t diff;
daddr_t block;
off_t sect_off;
u_int count;
int error=0;
if (offset < sizeof(struct riff_header)) {
char *p;
p = ((char *) ip->i_riff) + offset;
count = min(amount, sizeof(struct riff_header) - offset);
if (buffer) {
bcopy(p, buffer, count);
buffer += count;
} else {
error = uiomove(p, count, uio);
}
amount -= count;
offset += count;
}
if (error)
return error;
while (error == 0 && amount > 0) {
diff = ip->i_size - offset;
if (diff <= 0)
return 0;
block = ip->iso_start + (offset - sizeof(struct riff_header))/CDXA_SECTOR_SIZE;
error = (int)buf_bread(ip->i_devvp, (daddr64_t)((unsigned)block), CDXA_SECTOR_SIZE, NOCRED, &bp);
if (error) {
buf_brelse(bp);
return error;
}
if (buf_resid(bp)) {
printf("isofs: cd9660_xa_read_common: buf_bread didn't read full sector\n");
return EIO;
}
sect_off = (offset - sizeof(struct riff_header)) % CDXA_SECTOR_SIZE;
count = min(CDXA_SECTOR_SIZE-sect_off, amount);
if (diff < count)
count = diff;
if (buffer) {
bcopy(CAST_DOWN(caddr_t, (buf_dataptr(bp)+sect_off)), buffer, count);
buffer += count;
} else {
error = uiomove(CAST_DOWN(caddr_t, (buf_dataptr(bp)+sect_off)), count, uio);
}
amount -= count;
offset += count;
if (sect_off+count == CDXA_SECTOR_SIZE || offset == (off_t)ip->i_size)
buf_markaged(bp);
buf_brelse(bp);
}
return error;
}
int
cd9660_xa_read(struct vnop_read_args *ap)
{
struct vnode *vp = ap->a_vp;
register struct uio *uio = ap->a_uio;
register struct iso_node *ip = VTOI(vp);
off_t offset = uio->uio_offset;
size_t size = uio_resid(uio);
if (offset < 0)
return EINVAL;
if (size == 0)
return 0;
if (offset >= ip->i_size)
return 0;
if (offset + size > ip->i_size)
size = ip->i_size - offset;
return cd9660_xa_read_common(vp, offset, size, NULL, uio);
}
static int
cd9660_xa_pagein(struct vnop_pagein_args *ap)
{
struct vnode *vp = ap->a_vp;
upl_t pl = ap->a_pl;
size_t size= ap->a_size;
off_t f_offset = ap->a_f_offset;
vm_offset_t pl_offset = ap->a_pl_offset;
int flags = ap->a_flags;
register struct iso_node *ip = VTOI(vp);
int error;
kern_return_t kret;
vm_offset_t ioaddr;
if (UBCINVALID(vp))
panic("cd9660_xa_pagein: Not a VREG");
UBCINFOCHECK("cd9660_xa_pagein", vp);
if (size <= 0)
panic("cd9660_xa_pagein: size = %d", size);
kret = ubc_upl_map(pl, &ioaddr);
if (kret != KERN_SUCCESS)
panic("cd9660_xa_pagein: ubc_upl_map error = %d", kret);
ioaddr += pl_offset;
if (f_offset + size > ip->i_size)
size = ip->i_size - f_offset;
error = cd9660_xa_read_common(vp, f_offset, size, (caddr_t)ioaddr, NULL);
if (ap->a_size > size)
bzero((caddr_t)ioaddr+size, ap->a_size-size);
kret = ubc_upl_unmap(pl);
if (kret != KERN_SUCCESS)
panic("cd9660_xa_pagein: ubc_upl_unmap error = %d", kret);
if ((flags & UPL_NOCOMMIT) == 0)
{
if (error)
ubc_upl_abort_range(pl, pl_offset, ap->a_size, UPL_ABORT_FREE_ON_EMPTY);
else
ubc_upl_commit_range(pl, pl_offset, ap->a_size, UPL_COMMIT_FREE_ON_EMPTY);
}
return error;
}
#define cd9660_create \
((int (*)(struct vnop_create_args *))err_create)
#define cd9660_mknod ((int (*)(struct vnop_mknod_args *))err_mknod)
#define cd9660_write ((int (*)(struct vnop_write_args *))cd9660_enotsupp)
#define cd9660_fsync ((int (*)(struct vnop_fsync_args *))nullop)
#define cd9660_rename \
((int (*)(struct vnop_rename_args *))err_rename)
#define cd9660_copyfile \
((int (*)(struct vnop_copyfile_args *))err_copyfile)
#define cd9660_link ((int (*)(struct vnop_link_args *))err_link)
#define cd9660_mkdir ((int (*)(struct vnop_mkdir_args *))err_mkdir)
#define cd9660_symlink \
((int (*)(struct vnop_symlink_args *))err_symlink)
#define cd9660_advlock \
((int (*)(struct vnop_advlock_args *))cd9660_enotsupp)
#define cd9660_bwrite \
((int (*)(struct vnop_bwrite_args *))cd9660_enotsupp)
#define cd9660_pageout \
((int (*)(struct vnop_pageout_args *))cd9660_enotsupp)
int cd9660_blktooff(struct vnop_blktooff_args *ap);
int cd9660_offtoblk(struct vnop_offtoblk_args *ap);
int cd9660_blockmap(struct vnop_blockmap_args *ap);
#define VOPFUNC int (*)(void *)
int (**cd9660_vnodeop_p)(void *);
struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
{ &vnop_default_desc, (VOPFUNC)vn_default_error },
{ &vnop_lookup_desc, (VOPFUNC)cd9660_lookup },
{ &vnop_create_desc, (VOPFUNC)cd9660_create },
{ &vnop_mknod_desc, (VOPFUNC)cd9660_mknod },
{ &vnop_open_desc, (VOPFUNC)cd9660_open },
{ &vnop_close_desc, (VOPFUNC)cd9660_close },
{ &vnop_getattr_desc, (VOPFUNC)cd9660_getattr },
{ &vnop_read_desc, (VOPFUNC)cd9660_read },
{ &vnop_write_desc, (VOPFUNC)cd9660_write },
{ &vnop_ioctl_desc, (VOPFUNC)cd9660_ioctl },
{ &vnop_select_desc, (VOPFUNC)cd9660_select },
{ &vnop_mmap_desc, (VOPFUNC)cd9660_mmap },
{ &vnop_fsync_desc, (VOPFUNC)cd9660_fsync },
{ &vnop_remove_desc, (VOPFUNC)cd9660_remove },
{ &vnop_link_desc, (VOPFUNC)cd9660_link },
{ &vnop_rename_desc, (VOPFUNC)cd9660_rename },
{ &vnop_copyfile_desc, (VOPFUNC)cd9660_copyfile },
{ &vnop_mkdir_desc, (VOPFUNC)cd9660_mkdir },
{ &vnop_rmdir_desc, (VOPFUNC)cd9660_rmdir },
{ &vnop_symlink_desc, (VOPFUNC)cd9660_symlink },
{ &vnop_readdir_desc, (VOPFUNC)cd9660_readdir },
{ &vnop_readlink_desc, (VOPFUNC)cd9660_readlink },
{ &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },
{ &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim },
{ &vnop_strategy_desc, (VOPFUNC)cd9660_strategy },
{ &vnop_pathconf_desc, (VOPFUNC)cd9660_pathconf },
{ &vnop_advlock_desc, (VOPFUNC)cd9660_advlock },
{ &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
{ &vnop_pagein_desc, (VOPFUNC)cd9660_pagein },
{ &vnop_pageout_desc, (VOPFUNC)cd9660_pageout },
{ &vnop_getattrlist_desc, (VOPFUNC)cd9660_getattrlist },
{ &vnop_blktooff_desc, (VOPFUNC)cd9660_blktooff },
{ &vnop_offtoblk_desc, (VOPFUNC)cd9660_offtoblk },
{ &vnop_blockmap_desc, (VOPFUNC)cd9660_blockmap },
{ (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
};
struct vnodeopv_desc cd9660_vnodeop_opv_desc =
{ &cd9660_vnodeop_p, cd9660_vnodeop_entries };
int (**cd9660_cdxaop_p)(void *);
struct vnodeopv_entry_desc cd9660_cdxaop_entries[] = {
{ &vnop_default_desc, (VOPFUNC)vn_default_error },
{ &vnop_lookup_desc, (VOPFUNC)cd9660_lookup },
{ &vnop_create_desc, (VOPFUNC)cd9660_create },
{ &vnop_mknod_desc, (VOPFUNC)cd9660_mknod },
{ &vnop_open_desc, (VOPFUNC)cd9660_open },
{ &vnop_close_desc, (VOPFUNC)cd9660_close },
{ &vnop_getattr_desc, (VOPFUNC)cd9660_getattr },
{ &vnop_read_desc, (VOPFUNC)cd9660_xa_read },
{ &vnop_write_desc, (VOPFUNC)cd9660_write },
{ &vnop_ioctl_desc, (VOPFUNC)cd9660_ioctl },
{ &vnop_select_desc, (VOPFUNC)cd9660_select },
{ &vnop_mmap_desc, (VOPFUNC)cd9660_mmap },
{ &vnop_fsync_desc, (VOPFUNC)cd9660_fsync },
{ &vnop_remove_desc, (VOPFUNC)cd9660_remove },
{ &vnop_link_desc, (VOPFUNC)cd9660_link },
{ &vnop_rename_desc, (VOPFUNC)cd9660_rename },
{ &vnop_copyfile_desc, (VOPFUNC)cd9660_copyfile },
{ &vnop_mkdir_desc, (VOPFUNC)cd9660_mkdir },
{ &vnop_rmdir_desc, (VOPFUNC)cd9660_rmdir },
{ &vnop_symlink_desc, (VOPFUNC)cd9660_symlink },
{ &vnop_readdir_desc, (VOPFUNC)cd9660_readdir },
{ &vnop_readlink_desc, (VOPFUNC)cd9660_readlink },
{ &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },
{ &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim },
{ &vnop_strategy_desc, (VOPFUNC)cd9660_strategy },
{ &vnop_pathconf_desc, (VOPFUNC)cd9660_pathconf },
{ &vnop_advlock_desc, (VOPFUNC)cd9660_advlock },
{ &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
{ &vnop_pagein_desc, (VOPFUNC)cd9660_xa_pagein },
{ &vnop_pageout_desc, (VOPFUNC)cd9660_pageout },
{ &vnop_getattrlist_desc, (VOPFUNC)cd9660_getattrlist },
{ (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
};
struct vnodeopv_desc cd9660_cdxaop_opv_desc =
{ &cd9660_cdxaop_p, cd9660_cdxaop_entries };
int (**cd9660_specop_p)(void *);
struct vnodeopv_entry_desc cd9660_specop_entries[] = {
{ &vnop_default_desc, (VOPFUNC)vn_default_error },
{ &vnop_lookup_desc, (VOPFUNC)spec_lookup },
{ &vnop_create_desc, (VOPFUNC)spec_create },
{ &vnop_mknod_desc, (VOPFUNC)spec_mknod },
{ &vnop_open_desc, (VOPFUNC)spec_open },
{ &vnop_close_desc, (VOPFUNC)spec_close },
{ &vnop_getattr_desc, (VOPFUNC)cd9660_getattr },
{ &vnop_read_desc, (VOPFUNC)spec_read },
{ &vnop_write_desc, (VOPFUNC)spec_write },
{ &vnop_ioctl_desc, (VOPFUNC)spec_ioctl },
{ &vnop_select_desc, (VOPFUNC)spec_select },
{ &vnop_mmap_desc, (VOPFUNC)spec_mmap },
{ &vnop_fsync_desc, (VOPFUNC)spec_fsync },
{ &vnop_remove_desc, (VOPFUNC)spec_remove },
{ &vnop_link_desc, (VOPFUNC)spec_link },
{ &vnop_rename_desc, (VOPFUNC)spec_rename },
{ &vnop_mkdir_desc, (VOPFUNC)spec_mkdir },
{ &vnop_rmdir_desc, (VOPFUNC)spec_rmdir },
{ &vnop_symlink_desc, (VOPFUNC)spec_symlink },
{ &vnop_readdir_desc, (VOPFUNC)spec_readdir },
{ &vnop_readlink_desc, (VOPFUNC)spec_readlink },
{ &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },
{ &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim },
{ &vnop_strategy_desc, (VOPFUNC)spec_strategy },
{ &vnop_pathconf_desc, (VOPFUNC)spec_pathconf },
{ &vnop_advlock_desc, (VOPFUNC)spec_advlock },
{ &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
{ &vnop_devblocksize_desc, (VOPFUNC)spec_devblocksize },
{ &vnop_pagein_desc, (VOPFUNC)cd9660_pagein },
{ &vnop_pageout_desc, (VOPFUNC)cd9660_pageout },
{ &vnop_blktooff_desc, (VOPFUNC)cd9660_blktooff },
{ &vnop_offtoblk_desc, (VOPFUNC)cd9660_offtoblk },
{ &vnop_blockmap_desc, (VOPFUNC)cd9660_blockmap },
{ (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
};
struct vnodeopv_desc cd9660_specop_opv_desc =
{ &cd9660_specop_p, cd9660_specop_entries };
#if FIFO
int (**cd9660_fifoop_p)(void *);
struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
{ &vnop_default_desc, (VOPFUNC)vn_default_error },
{ &vnop_lookup_desc, (VOPFUNC)fifo_lookup },
{ &vnop_create_desc, (VOPFUNC)fifo_create },
{ &vnop_mknod_desc, (VOPFUNC)fifo_mknod },
{ &vnop_open_desc, (VOPFUNC)fifo_open },
{ &vnop_close_desc, (VOPFUNC)fifo_close },
{ &vnop_getattr_desc, (VOPFUNC)cd9660_getattr },
{ &vnop_read_desc, (VOPFUNC)fifo_read },
{ &vnop_write_desc, (VOPFUNC)fifo_write },
{ &vnop_ioctl_desc, (VOPFUNC)fifo_ioctl },
{ &vnop_select_desc, (VOPFUNC)fifo_select },
{ &vnop_mmap_desc, (VOPFUNC)fifo_mmap },
{ &vnop_fsync_desc, (VOPFUNC)fifo_fsync },
{ &vnop_remove_desc, (VOPFUNC)fifo_remove },
{ &vnop_link_desc, (VOPFUNC)fifo_link } ,
{ &vnop_rename_desc, (VOPFUNC)fifo_rename },
{ &vnop_mkdir_desc, (VOPFUNC)fifo_mkdir },
{ &vnop_rmdir_desc, (VOPFUNC)fifo_rmdir },
{ &vnop_symlink_desc, (VOPFUNC)fifo_symlink },
{ &vnop_readdir_desc, (VOPFUNC)fifo_readdir },
{ &vnop_readlink_desc, (VOPFUNC)fifo_readlink },
{ &vnop_inactive_desc, (VOPFUNC)cd9660_inactive },
{ &vnop_reclaim_desc, (VOPFUNC)cd9660_reclaim },
{ &vnop_strategy_desc, (VOPFUNC)fifo_strategy },
{ &vnop_pathconf_desc, (VOPFUNC)fifo_pathconf },
{ &vnop_advlock_desc, (VOPFUNC)fifo_advlock },
{ &vnop_bwrite_desc, (VOPFUNC)vn_bwrite },
{ &vnop_pagein_desc, (VOPFUNC)cd9660_pagein },
{ &vnop_pageout_desc, (VOPFUNC)cd9660_pageout },
{ &vnop_blktooff_desc, (VOPFUNC)cd9660_blktooff },
{ &vnop_offtoblk_desc, (VOPFUNC)cd9660_offtoblk },
{ (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
};
struct vnodeopv_desc cd9660_fifoop_opv_desc =
{ &cd9660_fifoop_p, cd9660_fifoop_entries };
#endif