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

📄 joliet.c

📁 一款功能很强的光盘镜象制作工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* @(#)joliet.c	1.34 02/11/22 joerg */#ifndef lintstatic	char sccsid[] =	"@(#)joliet.c	1.34 02/11/22 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,2001 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 <mconfig.h>#include "mkisofs.h"#include "gbk2uni.h"#include <timedefs.h>#include <utypes.h>#include <intcvt.h>#include <unls.h>	/* For UNICODE translation */#include <schily.h>static Uint	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			*/};	#ifdef	UDF       void	convert_to_unicode	__PR((unsigned char *buffer,		int size, char *source, struct nls_table *inls, int flag));       int	joliet_strlen		__PR((const char *string, int flag));#elsestatic void	convert_to_unicode	__PR((unsigned char *buffer,		int size, char *source, struct nls_table *inls, int flag));static int	joliet_strlen		__PR((const char *string, int flag));#endifstatic 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));/* *	conv_charset: convert to/from charsets via Unicode. * *	Any unknown character is set to '_' * */#ifdef	PROTOTYPESunsigned char conv_charset(unsigned char c,	struct nls_table *inls,	struct nls_table *onls)#elseunsigned char conv_charset(c, inls, onls)	unsigned char c;	struct nls_table *inls;	struct nls_table *onls;#endif{	unsigned char uh,		      ul,		      uc,		      *up;	/* if we have a null mapping, just return the input character */	if (inls == onls)		return c;	/* get high and low UNICODE bytes */	uh = inls->charset2uni[c].uni2;	ul = inls->charset2uni[c].uni1;	/* get the backconverted page from the output charset */	up = onls->page_uni2charset[uh];	/* if the page exists, get the backconverted character */	if (up == NULL)		uc = '\0';	else		uc = up[ul];	/* return the backconverted, if it's not NULL */	return (uc ? uc : '_');}/* * Function:		convert_to_unicode * * Purpose:		Perform a unicode conversion on a text string *			using the supplied input character set. * * Notes: */#ifdef	UDFvoid#elsestatic void#endifconvert_to_unicode(buffer, size, source, inls, flag)	int             flag;	unsigned char	*buffer;	int		size;	char		*source;	struct nls_table *inls;{	unsigned char	*tmpbuf;	int		i;	int		j;	int             p;	u_int16_t       code, 	                unicode;	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 = (Uchar *) e_malloc(size);		memcpy(tmpbuf, buffer, size);	} else {		tmpbuf = (Uchar *) 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 = inls->charset2uni[uc].uni2;	/* convert forward:							   hibyte...	     */			ul = inls->charset2uni[uc].uni1;	/* ...lobyte	     */			up = inls->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] = inls->charset2uni[uc].uni2;	/* final UNICODE							   conversion */		buffer[i + 1] = inls->charset2uni[uc].uni1;		/**===================================**//* big5 to unicode patch, flag=gbk4win *//* use flag param to call external int *//**===================================**/ if  (flag >= 1) { 	 if  ( tmpbuf[j] >= 0x81 ) { /* **** 00 A4 00 A4 00 A4 00 E5 **** */ /* ****          中          文 **** */ /* ***j=A4 A4 A4 E5 --> code=0xa4a4 ->find unicode **** */  /* ****  E 2D 65 87 <--- result **** */  code = tmpbuf[j];  code = code << 8;  code += tmpbuf[j+1];    unicode = gbk2uni[(((code&0xFF00)>>8)-0x81)*192 + ((code&0x00FF)-0x40)];    if (unicode) {    buffer[i] = unicode >> 8;    buffer[i+1] = unicode ;    j++;     }   }}	}	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. */#ifdef	UDFint#elsestatic int#endifjoliet_strlen(string, flag)	int             flag;	const char	*string;{	int		rtn;        unsigned char   *tmpbuf;
        int             i;
        int             j;

        int             p;
        u_int16_t       code,                         unicode;
        int             tmpsize ;		rtn = strlen(string) << 1;/**===================================**//* big5 to unicode patch, flag=gbk4win *//* use flag param to call external int *//**===================================**/  tmpsize = rtn;  if (flag >= 1) {      tmpbuf = (u_char *)string;
  j=0;
  for(i=0; i < tmpsize ; i += 2, j++)
    {
/******/ /* big5 to unicode patch*/

 if( tmpbuf[j] >= 0x81 ){

 /* **** 00 A4 00 A4 00 A4 00 E5 **** */
 /* ****          中          文 **** */
 /* **** j=A4 A4 A4 E5 -->       **** */ /*   code=0xa4a4 ->find unicode **** */ 
 /* **** 4E 2D 65 87 <--- result **** */

  code = tmpbuf[j];
  code = code << 8;
  code += tmpbuf[j+1];
    unicode = gbk2uni[(((code&0xFF00)>>8)-0x81)*192 + ((code&0x00FF)-0x40)];
    if(unicode) {
       j++;
       tmpsize -= 2;
      }
    }  }}  rtn = tmpsize; 	/*	 * 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 > 2*jlen) {		rtn = 2*jlen;	}	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((Uchar *) jvol_desc->system_id,			sizeof(jvol_desc->system_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->volume_id,			sizeof(jvol_desc->volume_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->volume_set_id,			sizeof(jvol_desc->volume_set_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->publisher_id,			sizeof(jvol_desc->publisher_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->preparer_id,			sizeof(jvol_desc->preparer_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->application_id,			sizeof(jvol_desc->application_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->copyright_file_id,			sizeof(jvol_desc->copyright_file_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->abstract_file_id,			sizeof(jvol_desc->abstract_file_id), NULL, in_nls, gbk4win_filenames);	convert_to_unicode((Uchar *) jvol_desc->bibliographic_file_id,			sizeof(jvol_desc->bibliographic_file_id), NULL, in_nls, gbk4win_filenames);}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;

⌨️ 快捷键说明

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