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

📄 isoinfo.c

📁 创建一个符合iso-9660标准的iso文件系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/* @(#)isoinfo.c	1.17 00/05/07 joerg */#ifndef lintstatic	char sccsid[] =	"@(#)isoinfo.c	1.17 00/05/07 joerg";#endif/* * File isodump.c - dump iso9660 directory information. *   Written by Eric Youngdale (1993).   Copyright 1993 Yggdrasil Computing, Incorporated   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.  *//* * Simple program to dump contents of iso9660 image in more usable format. * * Usage: * To list contents of image (with or without RR): *	isoinfo -l [-R] -i imagefile * To extract file from image: *	isoinfo -i imagefile -x xtractfile > outfile * To generate a "find" like list of files: *	isoinfo -f -i imagefile */#include "../config.h"#include <stdxlib.h>#include <unixstd.h>#include <strdefs.h>#include <stdio.h>#include <standard.h>#include <signal.h>#include <sys/stat.h>#include <statdefs.h>#include <schily.h>#include "../iso9660.h"#ifdef __SVR4#include <stdlib.h>#elseextern int optind;extern char *optarg;/* extern int getopt (int __argc, char **__argv, char *__optstring); */#endif#ifndef S_ISLNK#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)#endif#ifndef S_ISSOCK# ifdef S_IFSOCK#   define S_ISSOCK(m)	(((m) & S_IFMT) == S_IFSOCK)# else#   define S_ISSOCK(m)	(0)# endif#endifFILE * infile;int use_rock = 0;int use_joliet = 0;int do_listing = 0;int do_find = 0;int do_pathtab = 0;int do_pvd = 0;char * xtract = 0;int ucs_level = 0;struct stat fstat_buf;char name_buf[256];char xname[256];unsigned char date_buf[9];unsigned int sector_offset = 0;unsigned char buffer[2048];#define PAGE sizeof(buffer)#define ISODCL(from, to) (to - from + 1)int	isonum_721	__PR((char * p));int	isonum_723	__PR((char * p));int	isonum_731	__PR((char * p));int	isonum_733	__PR((unsigned char * p));void	printchars	__PR((char *s, int n));void	dump_pathtab	__PR((int block, int size));int	parse_rr	__PR((unsigned char * pnt, int len, int cont_flag));void	dump_rr		__PR((struct iso_directory_record * idr));void	dump_stat	__PR((int extent));void	extract_file	__PR((struct iso_directory_record * idr));void	parse_dir	__PR((char * rootname, int extent, int len));void	usage		__PR((int excode));int	main		__PR((int argc, char *argv[]));intisonum_721 (p)	char	*p;{	return ((p[0] & 0xff)		| ((p[1] & 0xff) << 8));}intisonum_723 (p)	char * p;{#if 0	if (p[0] != p[3] || p[1] != p[2]) {#ifdef	USE_LIBSCHILY		comerrno(EX_BAD, "invalid format 7.2.3 number\n");#else		fprintf (stderr, "invalid format 7.2.3 number\n");		exit (1);#endif	}#endif	return (isonum_721 (p));}intisonum_731 (p)	char	*p;{	return ((p[0] & 0xff)		| ((p[1] & 0xff) << 8)		| ((p[2] & 0xff) << 16)		| ((p[3] & 0xff) << 24));}intisonum_733 (p)	unsigned char	*p;{	return (isonum_731 ((char *)p));}voidprintchars(s, n)	char	*s;	int	n;{	int	i;	char	*p;	for (;n > 0 && *s; n--) {		if (*s == ' ') {			p = s;			i = n;			while (--i >= 0 && *p++ == ' ')				;			if (i <= 0)				break;		}		putchar(*s++);	}}voiddump_pathtab(block, size)	int	block;	int	size;{    char * buf;    int    offset;    int    idx;    int    extent;    int    pindex;    int    j;    int    len;    char   namebuf[255];    printf("Path table starts at block %d, size %d\n", block, size);        buf = (char *) malloc(size);        lseek(fileno(infile), (block - sector_offset) << 11, 0);    read(fileno(infile), buf, size);        offset = 0;    idx = 1;    while(offset < size)    {	len    = buf[offset];	extent = isonum_731(buf + offset + 2);	pindex  = isonum_721(buf + offset + 6);	switch( ucs_level )	{	case 3:	case 2:	case 1:	    for(j=0; j < len; j++)	    {		namebuf[j] = buf[offset + 8 + j*2+1];	    }	    printf("%4d: %4d %x %.*s\n", idx, pindex, extent, len, namebuf);	    break;	case 0:	    printf("%4d: %4d %x %.*s\n", idx, pindex, extent, len, buf + offset + 8);	}	idx++;	offset += 8 + len;	if( offset & 1) offset++;    }    free(buf);}int parse_rr(pnt, len, cont_flag)	unsigned char	*pnt;	int		len;	int		cont_flag;{	int slen;	int ncount;	int extent;	int cont_extent, cont_offset, cont_size;	int flag1, flag2;	unsigned char *pnts;	char symlinkname[1024];	int goof;	symlinkname[0] = 0;	cont_extent = cont_offset = cont_size = 0;	ncount = 0;	flag1 = flag2 = 0;	while(len >= 4){		if(pnt[3] != 1 && pnt[3] != 2) {		  printf("**BAD RRVERSION (%d)\n", pnt[3]);		  return 0;	/* JS ??? Is this right ??? */		};		ncount++;		if(pnt[0] == 'R' && pnt[1] == 'R') flag1 = pnt[4] & 0xff;		if(strncmp((char *)pnt, "PX", 2) == 0) flag2 |= 1;	/* POSIX attributes */		if(strncmp((char *)pnt, "PN", 2) == 0) flag2 |= 2;	/* POSIX devive number */		if(strncmp((char *)pnt, "SL", 2) == 0) flag2 |= 4;	/* Symlink */		if(strncmp((char *)pnt, "NM", 2) == 0) flag2 |= 8;	/* Alternate Name */		if(strncmp((char *)pnt, "CL", 2) == 0) flag2 |= 16;	/* Child link */		if(strncmp((char *)pnt, "PL", 2) == 0) flag2 |= 32;	/* Parent link */		if(strncmp((char *)pnt, "RE", 2) == 0) flag2 |= 64;	/* Relocated Direcotry */		if(strncmp((char *)pnt, "TF", 2) == 0) flag2 |= 128;	/* Time stamp */		if(strncmp((char *)pnt, "PX", 2) == 0) {		/* POSIX attributes */			fstat_buf.st_mode = isonum_733(pnt+4);			fstat_buf.st_nlink = isonum_733(pnt+12);			fstat_buf.st_uid = isonum_733(pnt+20);			fstat_buf.st_gid = isonum_733(pnt+28);		};		if(strncmp((char *)pnt, "NM", 2) == 0) {		/* Alternate Name */		  strncpy(name_buf, (char *)(pnt+5), pnt[2] - 5);		  name_buf[pnt[2] - 5] = 0;		}		if(strncmp((char *)pnt, "CE", 2) == 0) {		/* Continuation Area */			cont_extent = isonum_733(pnt+4);			cont_offset = isonum_733(pnt+12);			cont_size = isonum_733(pnt+20);		};		if(strncmp((char *)pnt, "PL", 2) == 0 || strncmp((char *)pnt, "CL", 2) == 0) {			extent = isonum_733(pnt+4);		};		if(strncmp((char *)pnt, "SL", 2) == 0) {		/* Symlink */		        int cflag;			cflag = pnt[4];			pnts = pnt+5;			slen = pnt[2] - 5;			while(slen >= 1){				switch(pnts[0] & 0xfe){				case 0:					strncat(symlinkname, (char *)(pnts+2), pnts[1]);					break;				case 2:					strcat (symlinkname, ".");					break;				case 4:					strcat (symlinkname, "..");					break;				case 8:					if((pnts[0] & 1) == 0)strcat (symlinkname, "/");					break;				case 16:					strcat(symlinkname,"/mnt");					printf("Warning - mount point requested");					break;				case 32:					strcat(symlinkname,"kafka");					printf("Warning - host_name requested");					break;				default:					printf("Reserved bit setting in symlink");					goof++;					break;				};				if((pnts[0] & 0xfe) && pnts[1] != 0) {					printf("Incorrect length in symlink component");				};				if((pnts[0] & 1) == 0) strcat(symlinkname,"/");				slen -= (pnts[1] + 2);				pnts += (pnts[1] + 2);				if(xname[0] == 0) strcpy(xname, "-> ");				strcat(xname, symlinkname);		       };			symlinkname[0] = 0;		};		len -= pnt[2];		pnt += pnt[2];		if(len <= 3 && cont_extent) {		  unsigned char sector[2048];		  lseek(fileno(infile), (cont_extent - sector_offset) << 11, 0);		  read(fileno(infile), sector, sizeof(sector));		  flag2 |= parse_rr(&sector[cont_offset], cont_size, 1);		};	};	return flag2;}voiddump_rr(idr)	struct iso_directory_record *idr;{	int len;	unsigned char * pnt;	len = idr->length[0] & 0xff;	len -= sizeof(struct iso_directory_record);	len += sizeof(idr->name);	len -= idr->name_len[0];	pnt = (unsigned char *) idr;	pnt += sizeof(struct iso_directory_record);	pnt -= sizeof(idr->name);	pnt += idr->name_len[0];	if((idr->name_len[0] & 1) == 0){		pnt++;		len--;	};	parse_rr(pnt, len, 0);}struct todo{  struct todo * next;  char * name;  int extent;  int length;};struct todo * todo_idr = NULL;char * months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",		       "Aug", "Sep", "Oct", "Nov", "Dec"};voiddump_stat(extent)	int	extent;{  int i;  char outline[80];  memset(outline, ' ', sizeof(outline));  if(S_ISREG(fstat_buf.st_mode))    outline[0] = '-';  else   if(S_ISDIR(fstat_buf.st_mode))    outline[0] = 'd';  else   if(S_ISLNK(fstat_buf.st_mode))    outline[0] = 'l';  else   if(S_ISCHR(fstat_buf.st_mode))    outline[0] = 'c';  else   if(S_ISBLK(fstat_buf.st_mode))    outline[0] = 'b';  else   if(S_ISFIFO(fstat_buf.st_mode))    outline[0] = 'f';  else   if(S_ISSOCK(fstat_buf.st_mode))    outline[0] = 's';  else    outline[0] = '?';  memset(outline+1, '-', 9);  if( fstat_buf.st_mode & S_IRUSR )    outline[1] = 'r';  if( fstat_buf.st_mode & S_IWUSR )    outline[2] = 'w';  if( fstat_buf.st_mode & S_IXUSR )    outline[3] = 'x';  if( fstat_buf.st_mode & S_IRGRP )    outline[4] = 'r';  if( fstat_buf.st_mode & S_IWGRP )

⌨️ 快捷键说明

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