⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joliet.c

📁 创建一个符合iso-9660标准的iso文件系统
💻 C
📖 第 1 页 / 共 3 页
字号:
/* @(#)joliet.c	1.24 00/05/07 joerg */#ifndef lintstatic	char sccsid[] =	"@(#)joliet.c	1.24 00/05/07 joerg";#endif/* * File joliet.c - handle Win95/WinNT long file/unicode extensions for iso9660.   Copyright 1997 Eric Youngdale.   APPLE_HYB James Pearson j.pearson@ge.ucl.ac.uk 22/2/2000   Copyright (c) 1999,2000 J. Schilling   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2, or (at your option)   any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  *//* * Joliet extensions for ISO9660.  These are spottily documented by * Microsoft.  In their infinite stupidity, they completely ignored * the possibility of using an SUSP record with the long filename * in it, and instead wrote out a duplicate directory tree with the * long filenames in it. * * I am not sure why they did this.  One reason is that they get the path * tables with the long filenames in them. * * There are two basic principles to Joliet, and the non-Unicode variant * known as Romeo.  Long filenames seem to be the main one, and the second * is that the character set and a few other things is substantially relaxed. * * The SVD is identical to the PVD, except: * *	Id is 2, not 1 (indicates SVD). *	escape_sequences contains UCS-2 indicator (levels 1, 2 or 3). *	The root directory record points to a different extent (with different *		size). *	There are different path tables for the two sets of directory trees. * * The Unicode level is coded in the SVD as follows: * *	Standard	Level	ASCII escape code *	UCS-2		Level-1	%/@ *	UCS-2		Level-2	%/C *	UCS-2		Level-3	%/E * * The following fields are recorded in Unicode: *	system_id *	volume_id *	volume_set_id *	publisher_id *	preparer_id *	application_id *	copyright_file_id *	abstract_file_id *	bibliographic_file_id * * Unicode strings are always encoded in big-endian format. * * In a directory record, everything is the same as with iso9660, except * that the name is recorded in unicode.  The name length is specified in * total bytes, not in number of unicode characters. * * The character set used for the names is different with UCS - the * restrictions are that the following are not allowed: * *	Characters (00)(00) through (00)(1f) (control chars) *	(00)(2a) '*' *	(00)(2f) '/' *	(00)(3a) ':' *	(00)(3b) ';' *	(00)(3f) '?' *	(00)(5c) '\' */#include "config.h"#include "mkisofs.h"#include "iso9660.h"#include <stdxlib.h>#include <time.h>#include <unls.h>	/* For UNICODE translation */#ifdef	USE_LIBSCHILY#include <standard.h>#include <schily.h>#endif#include <utypes.h>#include <intcvt.h>static int      jpath_table_index;static struct directory **jpathlist;static int      next_jpath_index = 1;static int      sort_goof;static	char	ucs_codes[] = {		'\0',		/* UCS-level 0 is illegal	*/		'@',		/* UCS-level 1			*/		'C',		/* UCS-level 2			*/		'E',		/* UCS-level 3			*/};	static void	convert_to_unicode	__PR((unsigned char *buffer,						int size, char *source));static int	joliet_strlen		__PR((const char *string));static void	get_joliet_vol_desc	__PR((struct iso_primary_descriptor *jvol_desc));static void	assign_joliet_directory_addresses __PR((struct directory *node));static void	build_jpathlist		__PR((struct directory *node));static int	joliet_compare_paths	__PR((void const *r, void const *l));static int	generate_joliet_path_tables __PR((void));static void	generate_one_joliet_directory __PR((struct directory *dpnt,						FILE *outfile));static int	joliet_sort_n_finish	__PR((struct directory *this_dir));static int	joliet_compare_dirs	__PR((const void *rr, const void *ll));static int	joliet_sort_directory	__PR((struct directory_entry **sort_dir));	int	joliet_sort_tree	__PR((struct directory *node));static void	generate_joliet_directories __PR((struct directory *node,						FILE *outfile));static int	jpathtab_write		__PR((FILE *outfile));static int	jdirtree_size		__PR((int starting_extent));static int	jroot_gen		__PR((void));static int	jdirtree_write		__PR((FILE *outfile));static int	jvd_write		__PR((FILE *outfile));static int	jpathtab_size		__PR((int starting_extent));extern struct nls_table *nls;	/* Current UNICODE conversion table *//* * Function:		convert_to_unicode * * Purpose:		Perform a 1/2 assed unicode conversion on a text *			string. * * Notes: */static voidconvert_to_unicode(buffer, size, source)	unsigned char	*buffer;	int		size;	char		*source;{	unsigned char	*tmpbuf;	int		i;	int		j;	unsigned char	uh,			ul,			uc,			*up;	/*	 * If we get a NULL pointer for the source, it means we have an	 * inplace copy, and we need to make a temporary working copy first.	 */	if (source == NULL) {		tmpbuf = (u_char *) e_malloc(size);		memcpy(tmpbuf, buffer, size);	} else {		tmpbuf = (u_char *) source;	}	/*	 * Now start copying characters.  If the size was specified to be 0,	 * then assume the input was 0 terminated.	 */	j = 0;	for (i = 0; (i + 1) < size; i += 2, j++) {	/* Size may be odd!!!*/		/*		 * JS integrated from: Achim_Kaiser@t-online.de		 * SGE modified according to Linux kernel source		 * Let all valid unicode characters pass		 * through (according to charset). Others are set to '_' .		 */		uc = tmpbuf[j];			/* temporary copy */		if (uc != '\0') {		/* must be converted */			uh = nls->charset2uni[uc].uni2;	/* convert forward:							   hibyte...	     */			ul = nls->charset2uni[uc].uni1;	/* ...lobyte	     */			up = nls->page_uni2charset[uh];	/* convert backward:							   page...	     */			if (up == NULL)				uc = '\0';	/* ...wrong unicode page     */			else				uc = up[ul];	/* backconverted character   */			if (uc != tmpbuf[j])				uc = '\0';	/* should be identical */			if (uc <= 0x1f || uc == 0x7f)				uc = '\0';	/* control char */			switch (uc) {		/* test special characters */			case '*':			case '/':			case ':':			case ';':			case '?':			case '\\':			case '\0':		/* illegal char mark */				/*				 * Even Joliet has some standards as to what is				 * allowed in a pathname. Pretty tame in				 * comparison to what DOS restricts you to.				 */				uc = '_';			}		}		buffer[i] = nls->charset2uni[uc].uni2;	/* final UNICODE							   conversion */		buffer[i + 1] = nls->charset2uni[uc].uni1;	}	if (size & 1) {	/* beautification */		buffer[size - 1] = 0;	}	if (source == NULL) {		free(tmpbuf);	}}/* * Function:	joliet_strlen * * Purpose:	Return length in bytes of string after conversion to unicode. * * Notes:	This is provided mainly as a convenience so that when more * 		intelligent Unicode conversion for either Multibyte or 8-bit *		codes is available that we can easily adapt. */static intjoliet_strlen(string)	const char	*string;{	int		rtn;	rtn = strlen(string) << 1;	/*	 * We do clamp the maximum length of a Joliet string to be the	 * maximum path size.  This helps to ensure that we don't completely	 * bolix things up with very long paths.    The Joliet specs say that	 * the maximum length is 128 bytes, or 64 unicode characters.	 */	if (rtn > 0x80) {		rtn = 0x80;	}	return rtn;}/* * Function:		get_joliet_vol_desc * * Purpose:		generate a Joliet compatible volume desc. * * Notes:		Assume that we have the non-joliet vol desc *			already present in the buffer.  Just modifiy the *			appropriate fields. */static voidget_joliet_vol_desc(jvol_desc)	struct iso_primary_descriptor	*jvol_desc;{	jvol_desc->type[0] = ISO_VD_SUPPLEMENTARY;	/*	 * For now, always do Unicode level 3.	 * I don't really know what 1 and 2 are - perhaps a more limited	 * Unicode set.	 * FIXME(eric) - how does Romeo fit in here?	 */	sprintf(jvol_desc->escape_sequences, "%%/%c", ucs_codes[ucs_level]);	/* Until we have Unicode path tables, leave these unset. */	set_733((char *) jvol_desc->path_table_size, jpath_table_size);	set_731(jvol_desc->type_l_path_table, jpath_table[0]);	set_731(jvol_desc->opt_type_l_path_table, jpath_table[1]);	set_732(jvol_desc->type_m_path_table, jpath_table[2]);	set_732(jvol_desc->opt_type_m_path_table, jpath_table[3]);	/* Set this one up. */	memcpy(jvol_desc->root_directory_record, &jroot_record,		offsetof(struct iso_directory_record, name[0]) + 1);	/*	 * Finally, we have a bunch of strings to convert to Unicode.	 * FIXME(eric) - I don't know how to do this in general,	 * so we will just be really lazy and do a char -> short conversion.	 *  We probably will want to filter any characters >= 0x80.	 */	convert_to_unicode((u_char *) jvol_desc->system_id,			sizeof(jvol_desc->system_id), NULL);	convert_to_unicode((u_char *) jvol_desc->volume_id,			sizeof(jvol_desc->volume_id), NULL);	convert_to_unicode((u_char *) jvol_desc->volume_set_id,			sizeof(jvol_desc->volume_set_id), NULL);	convert_to_unicode((u_char *) jvol_desc->publisher_id,			sizeof(jvol_desc->publisher_id), NULL);	convert_to_unicode((u_char *) jvol_desc->preparer_id,			sizeof(jvol_desc->preparer_id), NULL);	convert_to_unicode((u_char *) jvol_desc->application_id,			sizeof(jvol_desc->application_id), NULL);	convert_to_unicode((u_char *) jvol_desc->copyright_file_id,			sizeof(jvol_desc->copyright_file_id), NULL);	convert_to_unicode((u_char *) jvol_desc->abstract_file_id,			sizeof(jvol_desc->abstract_file_id), NULL);	convert_to_unicode((u_char *) jvol_desc->bibliographic_file_id,			sizeof(jvol_desc->bibliographic_file_id), NULL);}static voidassign_joliet_directory_addresses(node)	struct directory	*node;{	int		dir_size;	struct directory *dpnt;	dpnt = node;	while (dpnt) {		if ((dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) == 0) {			/*			 * If we already have an extent for this			 * (i.e. it came from a multisession disc), then			 * don't reassign a new extent.			 */			dpnt->jpath_index = next_jpath_index++;			if (dpnt->jextent == 0) {				dpnt->jextent = last_extent;				dir_size = (dpnt->jsize + (SECTOR_SIZE - 1)) >> 11;				last_extent += dir_size;			}		}		/* skip if hidden - but not for the rr_moved dir */		if (dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir)) {			assign_joliet_directory_addresses(dpnt->subdir);		}		dpnt = dpnt->next;	}}static voidbuild_jpathlist(node)	struct directory	*node;{	struct directory	*dpnt;	dpnt = node;	while (dpnt) {		if ((dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) == 0) {			jpathlist[dpnt->jpath_index] = dpnt;		}		if (dpnt->subdir)			build_jpathlist(dpnt->subdir);		dpnt = dpnt->next;	}}/* build_jpathlist(... */static intjoliet_compare_paths(r, l)	void const	*r;	void const	*l;{	struct directory const *ll = *(struct directory * const *) l;	struct directory const *rr = *(struct directory * const *) r;	int		rparent,			lparent;	char		*rpnt,			*lpnt;	unsigned char	rtmp[2],			ltmp[2];	/* make sure root directory is first */	if (rr == root)		return -1;	if (ll == root)		return 1;	rparent = rr->parent->jpath_index;	lparent = ll->parent->jpath_index;	if (rr->parent == reloc_dir) {		rparent = rr->self->parent_rec->filedir->jpath_index;	}	if (ll->parent == reloc_dir) {		lparent = ll->self->parent_rec->filedir->jpath_index;	}	if (rparent < lparent) {		return -1;	}	if (rparent > lparent) {		return 1;	}#ifdef APPLE_HYB	/*	 * we may be using the HFS name - characters >128 *may* get translated	 * to incorrect Unicode charcters (as far as MacOS is concerned)	 * - but we won't worry about that case at the moment	 */	if (USE_MAC_NAME(rr->self))		rpnt = rr->self->hfs_ent->name;	else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -