fstyp.c revision 0c79d02b29618f74322989ec8ceafaa5486ac1db
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* libfstyp module for hsfs
*/
#include <unistd.h>
#include <stropts.h>
#include <fcntl.h>
#include <stdio.h>
#include <strings.h>
#include <libnvpair.h>
#include <libfstyp_module.h>
typedef struct fstyp_hsfs {
int fd;
char hs_buf[ISO_SECTOR_SIZE];
int hs_pvd_sec_no;
char iso_buf[ISO_SECTOR_SIZE];
int iso_pvd_sec_no;
char unix_buf[ISO_SECTOR_SIZE];
int unix_pvd_sec_no;
int cdroff;
int cd_type;
} fstyp_hsfs_t;
(nosec)*ISO_SECTOR_SIZE))
#define NELEM(a) sizeof (a) / sizeof (*(a))
static char *get_old_name(char *new);
static int rdev_is_a_cd(int rdevfd);
static void copy_string(char *d, char *s, int maxlen);
static int is_hsfs(fstyp_hsfs_t *h);
static int get_attr(fstyp_hsfs_t *h);
int
{
if (offset != 0) {
return (FSTYP_ERR_OFFSET);
}
return (FSTYP_ERR_NOMEM);
}
*handle = (fstyp_mod_handle_t)h;
return (0);
}
void
{
nvlist_free(h->attr);
}
free(h);
}
int
{
return (is_hsfs(h));
}
int
{
int error;
return (FSTYP_ERR_NOMEM);
}
nvlist_free(h->attr);
return (error);
}
}
return (0);
}
/* ARGSUSED */
int
{
int error;
char *str_value;
char *name;
return (error);
}
/* format is special */
"ISO 9660 with UNIX extension") == 0) {
"CD-ROM is in ISO 9660 format with"
" UNIX extension\n");
} else {
" format\n", str_value);
}
continue;
}
continue;
}
}
}
return (0);
}
static char *
get_old_name(char *new)
{
static char *map[] = {
"system_id", "System id",
"volume_id", "Volume id",
"volume_set_id", "Volume set id",
"publisher_id", "Publisher id",
"data_preparer_id", "Data preparer id",
"application_id", "Application id",
"copyright_file_id", "Copyright File id",
"abstract_file_id", "Abstract File id",
"bibliographic_file_id", "Bibliographic File id",
"volume_set_size", "Volume set size is",
"volume_set_sequence_number", "Volume set sequence number is",
"logical_block_size", "Logical block size is",
"volume_size", "Volume size is"
};
int i;
break;
}
}
return (old);
}
/*
* findhsvol: check if the disk is in high sierra format
* return(1) if found, (0) otherwise
* if found, volp will point to the descriptor
*
*/
static int
{
int secno;
int i;
int err;
return (err);
}
for (i = 0; i < HSV_ID_STRLEN; i++)
goto cantfind;
goto cantfind;
switch (HSV_DESC_TYPE(volp)) {
case VD_SFS:
return (0);
case VD_EOV:
goto cantfind;
}
return (err);
}
}
return (FSTYP_ERR_NO_MATCH);
}
/*
* findisovol: check if the disk is in ISO 9660 format
* return(1) if found, (0) otherwise
* if found, volp will point to the descriptor
*
*/
static int
{
int secno;
int i;
int err;
return (err);
}
for (i = 0; i < ISO_ID_STRLEN; i++)
goto cantfind;
goto cantfind;
switch (ISO_DESC_TYPE(volp)) {
case ISO_VD_PVD:
return (0);
case ISO_VD_EOV:
goto cantfind;
}
return (err);
}
}
return (FSTYP_ERR_NO_MATCH);
}
/*
* findunixvol: check if the disk is in UNIX extension format
* return(1) if found, (0) otherwise
* if found, volp will point to the descriptor
*
*/
static int
{
int secno;
int i;
int err;
return (err);
}
for (i = 0; i < ISO_ID_STRLEN; i++)
goto cantfind;
goto cantfind;
switch (ISO_DESC_TYPE(volp)) {
case ISO_VD_UNIX:
return (0);
case ISO_VD_EOV:
goto cantfind;
}
return (err);
}
}
return (FSTYP_ERR_NO_MATCH);
}
static int
{
int err;
*cd_type = 0;
if (findunixvol(h, h->unix_buf) == 0) {
*cd_type = 2;
} else {
*cd_type = 1;
}
} else {
*cd_type = -1;
}
return (err);
}
static int
is_hsfs(fstyp_hsfs_t *h)
{
#ifdef CDROMREADOFFSET
int err;
if (rdev_is_a_cd(h->fd)) {
if (err == -1)
/*
* This device doesn't support this ioctl.
* That's OK.
*/
h->cdroff = 0;
}
#endif
/* check volume descriptor */
}
return (FSTYP_ERR_NOMEM); \
}
return (FSTYP_ERR_NOMEM); \
}
return (FSTYP_ERR_NOMEM); \
}
static int
get_attr(fstyp_hsfs_t *h)
{
char *sysid;
char *volid;
char *volsetid;
char *pubid;
char *prepid;
char *applid;
char *copyfile;
char *absfile;
char *bibfile;
int volsetsize;
int volsetseq;
int blksize;
int volsize;
char s[256];
switch (h->cd_type) {
case 0:
break;
case 1:
break;
case 2:
break;
default:
return (FSTYP_ERR_NO_MATCH);
}
ADD_STRING(h, "system_id", s);
ADD_STRING(h, "volume_id", s);
ADD_STRING(h, "gen_volume_label", s);
ADD_STRING(h, "volume_set_id", s);
ADD_STRING(h, "publisher_id", s);
ADD_STRING(h, "data_preparer_id", s);
ADD_STRING(h, "application_id", s);
ADD_STRING(h, "copyright_file_id", s);
ADD_STRING(h, "abstract_file_id", s);
ADD_STRING(h, "bibliographic_file_id", s);
return (0);
}
static void
copy_string(char *d, char *s, int maxlen)
{
int i;
/* strip off trailing zeros */
for (i = maxlen-1; i >= 0; i--) {
if (s[i] != ' ') {
break;
}
}
maxlen = i+1;
for (i = 0; i < maxlen; i++) {
*d++ = s[i];
}
*d++ = '\0';
}
/* readdisk - read from cdrom image file */
static int
{
return (FSTYP_ERR_IO);
}
return (FSTYP_ERR_IO);
}
return (0);
}
/*
* rdev_is_a_cd - return TRUE if the raw device identified by
* a file descriptor is a CDROM device.
*
* return FALSE if the device can't be accessed
* or is not a CDROM.
*/
static int
rdev_is_a_cd(int rdevfd)
{
return (0);
return (1);
else
return (0);
}