hsfs_susp_subr.c revision cf83459a3a773fbf09bbf2d90428884d292a6584
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * System Use Sharing protocol subroutines for High Sierra filesystem
2N/A *
2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <sys/types.h>
2N/A#include <sys/t_lock.h>
2N/A#include <sys/param.h>
2N/A#include <sys/systm.h>
2N/A#include <sys/sysmacros.h>
2N/A#include <sys/kmem.h>
2N/A#include <sys/signal.h>
2N/A#include <sys/user.h>
2N/A#include <sys/proc.h>
2N/A#include <sys/disp.h>
2N/A#include <sys/buf.h>
2N/A#include <sys/pathname.h>
2N/A#include <sys/vfs.h>
2N/A#include <sys/vnode.h>
2N/A#include <sys/file.h>
2N/A#include <sys/uio.h>
2N/A#include <sys/conf.h>
2N/A
2N/A#include <vm/page.h>
2N/A
2N/A#include <sys/fs/hsfs_spec.h>
2N/A#include <sys/fs/hsfs_isospec.h>
2N/A#include <sys/fs/hsfs_node.h>
2N/A#include <sys/fs/hsfs_impl.h>
2N/A#include <sys/fs/hsfs_susp.h>
2N/A#include <sys/fs/hsfs_rrip.h>
2N/A
2N/A#include <sys/statvfs.h>
2N/A#include <sys/mount.h>
2N/A#include <sys/swap.h>
2N/A#include <sys/errno.h>
2N/A#include <sys/debug.h>
2N/A#include "fs/fs_subr.h"
2N/A#include <sys/cmn_err.h>
2N/A
2N/A/* static declarations */
2N/Astatic void free_cont_area(uchar_t *);
2N/Astatic int get_cont_area(struct hsfs *, uchar_t **, cont_info_t *);
2N/Astatic int parse_signatures(sig_args_t *, uint_t, uchar_t *, int);
2N/A
2N/A/*
2N/A * parse_sua()
2N/A *
2N/A * This is the main SUSP routine, that gets all the SUA areas and
2N/A * continuations. It calls parse_signatures() to actually interpret
2N/A * the signature fields.
2N/A *
2N/A * XXX - need to implement signature searching to speed things up and
2N/A * which is needed for the api, which isn't done yet.
2N/A */
2N/Aint
2N/Aparse_sua(
2N/A uchar_t *name_p, /* location to copy name */
2N/A int *name_len_p, /* location to put name len */
2N/A int *name_change_p, /* flags to signal name chg */
2N/A uchar_t *dirp, /* pointer to ISO dir entry */
2N/A struct hs_direntry *hdp, /* loc to store dir info */
2N/A struct hsfs *fsp, /* filesystem pointer */
2N/A uchar_t *search_sig, /* signature to search for */
2N/A int search_num) /* n^th sig to search for */
2N/A{
2N/A uchar_t *SUA_p = IDE_sys_use_area(dirp);
2N/A int SUA_len = IDE_SUA_LEN(dirp);
2N/A uchar_t *tmp_SUA_p = (SUA_p + fsp->hsfs_sua_off);
2N/A int tmp_SUA_len = (SUA_len - fsp->hsfs_sua_off);
2N/A short ret_val = -1;
2N/A uchar_t *cont_p = (uchar_t *)NULL;
2N/A sig_args_t sig_args;
2N/A cont_info_t cont_info;
2N/A
2N/A /*
2N/A * If there is no SUA, just return, no error
2N/A */
2N/A
2N/A if (SUA_len == 0)
2N/A return (0);
2N/A
2N/A /*
2N/A * Make sure that the continuation lenth is zero, as that is
2N/A * the way to tell if we must grab another continuation area.
2N/A */
2N/A bzero((char *)&cont_info, sizeof (cont_info));
2N/A
2N/A sig_args.dirp = dirp;
2N/A sig_args.name_p = name_p;
2N/A sig_args.name_len_p = name_len_p;
2N/A sig_args.SUF_ptr = tmp_SUA_p;
2N/A sig_args.hdp = hdp;
2N/A sig_args.fsp = fsp;
2N/A sig_args.cont_info_p = &cont_info;
2N/A sig_args.flags = 0;
2N/A sig_args.name_flags = 0;
2N/A
2N/A /*
2N/A * Get ready to put in a new name. If no "NM" is found, then
2N/A * hs_namecopy will come to the rescue. Make sure you don't
2N/A * have NULL names, also.
2N/A */
2N/A if (name_p)
2N/A *(name_p) = '\0';
2N/A if (name_len_p)
2N/A *(name_len_p) = 0;
2N/A
2N/A while (ret_val == -1) {
2N/A switch (parse_signatures(&sig_args, tmp_SUA_len, search_sig,
2N/A search_num)) {
2N/A case END_OF_SUA :
2N/A if (cont_info.cont_len) {
2N/A
2N/A if (get_cont_area(fsp, &cont_p, &cont_info)) {
2N/A ret_val = 1;
2N/A goto clean_up;
2N/A }
2N/A
2N/A sig_args.SUF_ptr = cont_p +
2N/A cont_info.cont_offset;
2N/A
2N/A tmp_SUA_len = cont_info.cont_len;
2N/A cont_info.cont_len = 0;
2N/A
2N/A continue;
2N/A }
2N/A sig_args.flags = 0; /* reset */
2N/A ret_val = 0; /* keep going */
2N/A break;
2N/A case SUA_NULL_POINTER:
2N/A ret_val = SUA_NULL_POINTER;
2N/A goto clean_up;
2N/A case SUA_ENOMEM:
2N/A ret_val = SUA_ENOMEM;
2N/A goto clean_up;
2N/A case SUA_EINVAL:
2N/A ret_val = SUA_EINVAL;
2N/A goto clean_up;
2N/A case RELOC_DIR:
2N/A ret_val = RELOC_DIR;
2N/A goto clean_up;
2N/A }
2N/A }
2N/A
2N/A if (ret_val != 0)
2N/A goto clean_up;
2N/A
2N/A if (IS_NAME_BIT_SET(sig_args.name_flags, RRIP_NAME_CHANGE))
2N/A SET_NAME_BIT(*(name_change_p), RRIP_NAME_CHANGE);
2N/A
2N/Aclean_up:
2N/A free_cont_area(cont_p);
2N/A return (ret_val);
2N/A
2N/A}
2N/A
2N/A/*
2N/A * parse_signatures()
2N/A *
2N/A * Find the correct handling function for the signature string that is
2N/A * passed to this function.
2N/A *
2N/A * signature searching:
2N/A *
2N/A * The two arguments of search_sig and search_num are for finding the
2N/A * search_num^th occurance of the signature search_sig. This will come
2N/A * in handy with searching for the "NM" field and is part of the api
2N/A * for rrip (which really can be used for any extension).
2N/A */
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Aparse_signatures(
2N/A sig_args_t *sig_args_p,
2N/A uint_t SUA_len,
2N/A uchar_t *search_sig, /* possible signature to search for */
2N/A int search_num) /* n^th occurance of search_sig to */
2N/A /* search for */
2N/A{
2N/A uchar_t *sig_string = sig_args_p->SUF_ptr;
2N/A extension_name_t *extnp;
2N/A ext_signature_t *ext_sigp;
2N/A int impl_bit_num = 0;
2N/A uint_t SUA_rem = SUA_len; /* SUA length */
2N/A /* remaining to be parsed */
2N/A
2N/A /* This should never happen ... just so we don't panic, literally */
2N/A if (sig_string == (uchar_t *)NULL)
2N/A return (SUA_NULL_POINTER);
2N/A
2N/A /*
2N/A * Until the end of SUA, search for the signatures
2N/A * (check for end of SUA (2 consecutive NULL bytes)) or the
2N/A * remaining length of the SUA is <= 3. The minimum signature
2N/A * field is 4.
2N/A */
2N/A
2N/A while ((SUA_rem >= SUF_MIN_LEN) && (*sig_string != '\0') &&
2N/A (*(sig_string + 1) != '\0')) {
2N/A
2N/A /*
2N/A * Find appropriate extension and signature table
2N/A */
2N/A for (extnp = extension_name_table, impl_bit_num = 0;
2N/A extnp->extension_name != (char *)NULL;
2N/A extnp++, impl_bit_num++) {
2N/A
2N/A /*
2N/A * look at an extension only if it is implemented
2N/A * on the CD-ROM
2N/A */
2N/A if (!IS_IMPL_BIT_SET(sig_args_p->fsp, impl_bit_num))
2N/A continue;
2N/A
2N/A /*
2N/A * Find the appropriate signature
2N/A */
2N/A for (ext_sigp = extnp->signature_table;
2N/A ext_sigp->ext_signature != (char *)NULL;
2N/A ext_sigp++) {
2N/A
2N/A if (strncmp((char *)sig_string,
2N/A ext_sigp->ext_signature,
2N/A SUF_SIG_LEN) == 0) {
2N/A
2N/A SUA_rem -= SUF_LEN(sig_string);
2N/A
2N/A /*
2N/A * The SUA_len parameter specifies the
2N/A * length of the SUA that the kernel
2N/A * expects. There is also a length
2N/A * encoded in the SUA data. If they
2N/A * do not agree, bail out.
2N/A */
2N/A if (SUA_len < SUF_LEN(sig_string)) {
2N/A cmn_err(CE_NOTE,
2N/A "parse_signatures: SUA length too big: "
2N/A "expected=%d, found=%d",
2N/A SUA_len,
2N/A SUF_LEN(sig_string));
2N/A return (SUA_EINVAL);
}
sig_args_p->SUF_ptr = sig_string;
sig_string =
(ext_sigp->sig_handler)(sig_args_p);
switch (sig_args_p->flags) {
case END_OF_SUA :
return (END_OF_SUA);
case SUA_ENOMEM :
return (SUA_ENOMEM);
case SUA_EINVAL :
return (SUA_EINVAL);
case RELOC_DIR :
return (RELOC_DIR);
default :
#if NAME_SEARCH
case NAME_CONTINUE :
/* nothing for now */
case NAME_CHANGE :
/* nothing for now */
#endif
break;
}
/* reset to be zero */
sig_args_p->flags = 0;
goto next_signature;
}
/* off to the next signature .... */
} /* for ext_sigp */
} /* for extnp (extension parsing) */
/*
* Opps, did not find this signature. We must
* advance on the the next signature in the SUA
* and pray to persumedly omniscient, omnipresent,
* almighty transcendental being(s) that the next
* record is in the susp format, or we get hosed.
*/
if (SUA_rem < SUF_MIN_LEN)
return (END_OF_SUA);
SUA_rem -= SUF_LEN(sig_string);
sig_string += SUF_LEN(sig_string);
next_signature:
/*
* Failsafe
*/
if (SUA_rem < SUF_MIN_LEN || SUF_LEN(sig_string) <= 0) {
return (END_OF_SUA);
}
} /* while */
return (END_OF_SUA);
}
/*
* hs_fill_root_dirent()
*
*
* This function reads the root directory extent to get to the SUA of
* the "." entry of the root directory. It the checks to see if the
* susp is implemented.
*/
void
hs_check_root_dirent(struct vnode *vp, struct hs_direntry *hdp)
{
struct buf *secbp;
uchar_t *root_ptr;
uchar_t *secp;
uint_t secno;
offset_t secoff;
sig_args_t sig_args;
struct hsfs *fsp;
int error;
if (vp->v_type != VDIR) {
cmn_err(CE_NOTE,
"hs_check_root_dirent: vp (0x%p) not a directory",
(void *)vp);
return;
}
bzero((caddr_t)&sig_args, sizeof (sig_args));
fsp = VFS_TO_HSFS(vp->v_vfsp);
secno = LBN_TO_SEC(hdp->ext_lbn+hdp->xar_len, vp->v_vfsp);
secoff = LBN_TO_BYTE(hdp->ext_lbn+hdp->xar_len, vp->v_vfsp) &
MAXHSOFFSET;
secbp = bread(fsp->hsfs_devvp->v_rdev, secno * 4, HS_SECTOR_SIZE);
error = geterror(secbp);
if (error != 0) {
cmn_err(CE_NOTE,
"hs_check_root_dirent: bread: error=(%d)", error);
goto end;
}
secp = (uchar_t *)secbp->b_un.b_addr;
root_ptr = &secp[secoff];
/* quick check */
if (hdp->ext_lbn != HDE_EXT_LBN(root_ptr)) {
cmn_err(CE_NOTE, "hs_check_root_dirent: dirent not match\n");
/* keep on going */
}
/*
* Here, we know that the "." entry is the first in the sector
* just read (ISO 9660). Let's now check for the sharing
* protocol and set call the susp sig_handler() if we should.
* Then we run through the hs_parsedir() function to catch all
* the other possibilities of SUSP fields and continuations.
*
* If there is not SUA area, just return, and assume ISO.
*/
if (IDE_SUA_LEN(root_ptr) == 0)
goto end;
if (strncmp(SUSP_SP, (char *)IDE_sys_use_area(root_ptr),
SUF_SIG_LEN) == 0) {
/*
* We have a match of the sharing signature, so let's
* call the sig_handler to do what is necessary. We can
* ignore the return value, as implemented bits are set.
*/
sig_args.SUF_ptr = IDE_sys_use_area(root_ptr);
sig_args.fsp = fsp;
if ((susp_sp->sig_handler)(&sig_args) == (uchar_t *)NULL) {
goto end;
}
} else
goto end;
(void) hs_parsedir(fsp, root_ptr, hdp, (char *)NULL, (int *)NULL);
/*
* If we did not get at least 1 extension, let's assume ISO and
* NULL out the implementation bits.
*/
if (fsp->hsfs_ext_impl <= 1L)
fsp->hsfs_ext_impl = 0L;
end:
brelse(secbp);
}
/*
* get_cont_area()
*
* This function allocates a memory block, if necessary, and reads the
* continuation area into the allocated space.
*
* Return value : 0 if the read and allocation went OK.
* 1 if there was an error.
*/
static int
get_cont_area(struct hsfs *fsp, uchar_t **buf_pp, cont_info_t *cont_info_p)
{
struct buf *secbp;
int error;
uint_t secno;
/*
* Guard against invalid continuation area records.
* Both cont_offset and cont_len must be no longer than
* HS_SECTOR_SIZE. If they are, return an error.
*/
if (cont_info_p->cont_offset > HS_SECTOR_SIZE ||
cont_info_p->cont_len > HS_SECTOR_SIZE) {
cmn_err(CE_NOTE, "get_cont_area: invalid offset/length");
return (1);
}
if (*buf_pp == (uchar_t *)NULL)
*buf_pp = kmem_alloc((size_t)HS_SECTOR_SIZE, KM_SLEEP);
secno = (uint_t)LBN_TO_SEC(cont_info_p->cont_lbn, fsp->hsfs_vfs);
secbp = bread(fsp->hsfs_devvp->v_rdev, secno * 4, HS_SECTOR_SIZE);
error = geterror(secbp);
if (error != 0) {
cmn_err(CE_NOTE, "get_cont_area: bread: error=(%d)", error);
brelse(secbp);
return (1);
}
/*
* This continuation area does not extend into the next sector
* so just copy the data to the buffer.
*/
if ((cont_info_p->cont_offset + cont_info_p->cont_len) <=
HS_SECTOR_SIZE) {
bcopy(secbp->b_un.b_addr, (char *)*buf_pp, HS_SECTOR_SIZE);
}
/*
* This continuation area extends into the next sector so we
* need to do some dancing:
*
* - zero the return buffer so nothing random is returned
* - copy the partial data to the *beginning* of the return buffer
* - release the first sector's buffer
* - read the next sector
* - copy the remainder of the data to the return buffer
*/
else {
uint_t partial_size;
bzero((char *)*buf_pp, HS_SECTOR_SIZE);
partial_size = HS_SECTOR_SIZE - cont_info_p->cont_offset;
bcopy(&secbp->b_un.b_addr[cont_info_p->cont_offset],
(char *)*buf_pp, partial_size);
cont_info_p->cont_offset = 0;
brelse(secbp);
secbp = bread(fsp->hsfs_devvp->v_rdev, (secno + 1) * 4,
HS_SECTOR_SIZE);
error = geterror(secbp);
if (error != 0) {
cmn_err(CE_NOTE, "get_cont_area: bread(2): error=(%d)",
error);
brelse(secbp);
return (1);
}
bcopy(secbp->b_un.b_addr, (char *)&(*buf_pp)[partial_size],
cont_info_p->cont_len - partial_size);
}
brelse(secbp);
return (0);
}
/*
* free_cont_area
*
* simple function to just free up memory, if it exists
*
*/
static void
free_cont_area(uchar_t *cont_p)
{
if (cont_p)
(void) kmem_free((caddr_t)cont_p, (size_t)HS_SECTOR_SIZE);
cont_p = (uchar_t *)NULL;
}