示例#1
0
/*
 * NAME:	do_format()
 * DESCRIPTION:	call hfs_format() with necessary privileges
 */
static
hfsvol *do_format(const char *path, int partno, const char *vname)
{
    hfsvol *vol = 0;

    suid_enable();

    if (hfs_format(path, partno, vname, 0, 0) != -1)
        vol = hfs_mount(path, partno, HFS_MODE_ANY);

    suid_disable();

    return vol;
}
示例#2
0
/*
**	make_mac_volume: "create" an HFS volume using the ISO data
**
**	The HFS volume structures are set up (but no data is written yet).
**
**	ISO volumes have a allocation size of 2048 bytes - regardless
**	of the size of the volume. HFS allocation size is depends on volume
**	size, so we may have to update the ISO structures to add in any
**	padding.
*/
int FDECL2(make_mac_volume, struct directory *, dpnt, int, start_extent)
{
	char vol_name[HFS_MAX_VLEN+1];	/* Mac volume name */
	hfsvol *vol;			/* Mac volume */
	int vlen, vblen;		/* vol length (bytes, blocks) */
	int Csize, lastCsize;		/* allocation sizes */
	int ret = 0;			/* return value */
	int loop = 1;

	/* umount volume if we have had a previous attempt */
	if (vol_save)
	    if (hfs_umount(vol_save, 0) < 0)
		return (-1);

	/* set the default clump size to the ISO block size */
	lastCsize = SECTOR_SIZE;

	if (verbose > 1)
	    fprintf(stderr, "Creating HFS Volume info\n");

	/* name or copy ISO volume name to Mac Volume name */
	strncpy(vol_name, hfs_volume_id ? hfs_volume_id : volume_id, HFS_MAX_VLEN);
	vol_name[HFS_MAX_VLEN] = '\0';

	/* get initial size of HFS volume (size of ISO volume) */
	vblen = last_extent * BLK_CONV;

	/* add on size of extents/catalog file, but this may mean
	   the allocation size will change, so loop round until the allocation
	   size doesn't change */
	while (loop) {
	    hce->XTCsize = XClpSiz(vblen);
	    vblen = get_vol_size(vblen);
	    Csize = AlcSiz(vblen);

	    if (Csize == lastCsize) {
		/* allocation size hasn't changed, so carry on */
		loop = 0;
	    }
	    else {
		/* allocation size has changed, so update ISO volume size */
		if ((vlen = get_adj_size(Csize)) < 0) {
		    snprintf(hce->error, ERROR_SIZE, 
		    	"too many files for HFS volume");
		    return (-1);
		}
		vlen += V_ROUND_UP(start_extent * SECTOR_SIZE, Csize);
		vblen = vlen /  HFS_BLOCKSZ;
		lastCsize = Csize;
	    }
	}

	/* set vlen to size in bytes */
/*	vlen = hce->hfs_vol_size = vblen * HFS_BLOCKSZ; */
	/* take off the label/map size */
	vblen -= hce->hfs_map_size;
	vlen = hce->hfs_vol_size = vblen * HFS_BLOCKSZ;

	/* set the default allocation size for libhfs */
	hce->Csize = Csize;

	/* format and mount the "volume" */
	if (hfs_format(hce, 0, vol_name) < 0)
	{
	    snprintf(hce->error, ERROR_SIZE, "can't HFS format %s",vol_name);
	    return(-1);
	}

	/* update the ISO structures with new start extents and any padding
	   required */
	if (Csize != SECTOR_SIZE) {
	    last_extent = adj_size(Csize, start_extent, hce->hfs_hdr_size + hce->hfs_map_size);
	    adj_size_other(dpnt);
	}

	if ((vol = hfs_mount(hce, 0, 0)) == 0)
	{
	    snprintf(hce->error, ERROR_SIZE, "can't HFS mount %s",vol_name);
	    return(-1);
	}

	/* save the volume for possible later use */
	vol_save = vol;

	/* Recursively "copy" the files to the volume - we need to
	   know the first allocation block in the volume as starting blocks
	   of files are relative to this.
	*/
	ret = copy_to_mac_vol(vol, dpnt);
	if (ret < 0)
	    return(ret);

	/* make the Desktop files - I *think* this stops the Mac
	   rebuilding the desktop when the CD is mounted on a Mac
	   These will be ignored if they already exist */
	if (create_dt)
	    ret = make_desktop(vol, last_extent*BLK_CONV);
	if (ret < 0)
	    return(ret);

	/* close the volume */
	if (hfs_flush(vol) < 0)
	    return(-1);

	/* unmount and set the start blocks for the catalog/extents files */
	if (hfs_umount(vol, last_extent*BLK_CONV) < 0)
	    return(-1);

	return(Csize);
}