📄 isoinfo.c
字号:
outline[5] = 'w'; if( fstat_buf.st_mode & S_IXGRP ) outline[6] = 'x'; if( fstat_buf.st_mode & S_IROTH ) outline[7] = 'r'; if( fstat_buf.st_mode & S_IWOTH ) outline[8] = 'w'; if( fstat_buf.st_mode & S_IXOTH ) outline[9] = 'x'; sprintf(outline+11, "%3ld", (long)fstat_buf.st_nlink); sprintf(outline+15, "%4lo", (unsigned long)fstat_buf.st_uid); sprintf(outline+20, "%4lo", (unsigned long)fstat_buf.st_gid); sprintf(outline+33, "%8ld", (long)fstat_buf.st_size); if( date_buf[1] >= 1 && date_buf[1] <= 12 ) { memcpy(outline+42, months[date_buf[1]-1], 3); } sprintf(outline+46, "%2d", date_buf[2]); sprintf(outline+49, "%4d", date_buf[0]+1900); sprintf(outline+54, "[%6d]", extent); for(i=0; i<63; i++) if(outline[i] == 0) outline[i] = ' '; outline[63] = 0; printf("%s %s %s\n", outline, name_buf, xname);}voidextract_file(idr) struct iso_directory_record *idr;{ int extent, len, tlen; unsigned char buff[2048]; extent = isonum_733((unsigned char *)idr->extent); len = isonum_733((unsigned char *)idr->size); while(len > 0) { lseek(fileno(infile), (extent - sector_offset) << 11, 0); tlen = (len > sizeof(buff) ? sizeof(buff) : len); read(fileno(infile), buff, tlen); len -= tlen; extent++; write(1, buff, tlen); }}voidparse_dir(rootname, extent, len) char *rootname; int extent; int len;{ char testname[256]; struct todo * td; int i; struct iso_directory_record * idr; if( do_listing) printf("\nDirectory listing of %s\n", rootname); while(len > 0 ) { lseek(fileno(infile), (extent - sector_offset) << 11, 0); read(fileno(infile), buffer, sizeof(buffer)); len -= sizeof(buffer); extent++; i = 0; while(1==1){ idr = (struct iso_directory_record *) &buffer[i]; if(idr->length[0] == 0) break; memset(&fstat_buf, 0, sizeof(fstat_buf)); name_buf[0] = xname[0] = 0; fstat_buf.st_size = isonum_733((unsigned char *)idr->size); if( idr->flags[0] & 2) fstat_buf.st_mode |= S_IFDIR; else fstat_buf.st_mode |= S_IFREG; if(idr->name_len[0] == 1 && idr->name[0] == 0) strcpy(name_buf, "."); else if(idr->name_len[0] == 1 && idr->name[0] == 1) strcpy(name_buf, ".."); else { switch(ucs_level) { case 3: case 2: case 1: /* * Unicode name. Convert as best we can. */ { int j; for(j=0; j < idr->name_len[0] / 2; j++) { name_buf[j] = idr->name[j*2+1]; } name_buf[idr->name_len[0]/2] = '\0'; } break; case 0: /* * Normal non-Unicode name. */ strncpy(name_buf, idr->name, idr->name_len[0]); name_buf[idr->name_len[0]] = 0; break; default: /* * Don't know how to do these yet. Maybe they are the same * as one of the above. */ exit(1); } }; memcpy(date_buf, idr->date, 9); if(use_rock) dump_rr(idr); if( (idr->flags[0] & 2) != 0 && (idr->name_len[0] != 1 || (idr->name[0] != 0 && idr->name[0] != 1))) { /* * Add this directory to the todo list. */ td = todo_idr; if( td != NULL ) { while(td->next != NULL) td = td->next; td->next = (struct todo *) malloc(sizeof(*td)); td = td->next; } else { todo_idr = td = (struct todo *) malloc(sizeof(*td)); } td->next = NULL; td->extent = isonum_733((unsigned char *)idr->extent); td->length = isonum_733((unsigned char *)idr->size); td->name = (char *) malloc(strlen(rootname) + strlen(name_buf) + 2); strcpy(td->name, rootname); strcat(td->name, name_buf); strcat(td->name, "/"); } else { strcpy(testname, rootname); strcat(testname, name_buf); if(xtract && strcmp(xtract, testname) == 0) { extract_file(idr); } } if( do_find && (idr->name_len[0] != 1 || (idr->name[0] != 0 && idr->name[0] != 1))) { strcpy(testname, rootname); strcat(testname, name_buf); printf("%s\n", testname); } if(do_listing) dump_stat(isonum_733((unsigned char *)idr->extent)); i += buffer[i]; if (i > 2048 - sizeof(struct iso_directory_record)) break; } }}voidusage(excode) int excode;{ errmsgno(EX_BAD, "Usage: %s [options]\n", get_progname()); error("Options:\n"); error("\t-h Print this help\n"); error("\t-d Print information from the primary volume descriptor\n"); error("\t-f Generate output similar to 'find . -print'\n"); error("\t-J Print information from from Joliet extensions\n"); error("\t-l Generate output similar to 'ls -lR'\n"); error("\t-p Print Path Table\n"); error("\t-R Print information from from Rock Ridge extensions\n"); error("\t-N sector Sector number where ISO image should start on CD\n"); error("\t-T sector Sector number where actual session starts on CD\n"); error("\t-i filename Filename to read ISO-9660 image from\n"); error("\t-x pathname Extract specified file to stdout\n"); exit(excode);}intmain(argc, argv) int argc; char *argv[];{ int c; char * filename = NULL; int toc_offset = 0; struct todo * td; struct iso_primary_descriptor ipd; struct iso_directory_record * idr; save_args(argc, argv); if(argc < 2) usage(EX_BAD); while ((c = getopt(argc, argv, "hdpi:JRlx:fN:T:")) != EOF) switch (c) { case 'h': usage(0); break; case 'd': do_pvd++; break; case 'f': do_find++; break; case 'p': do_pathtab++; break; case 'R': use_rock++; break; case 'J': use_joliet++; break; case 'l': do_listing++; break; case 'T': /* * This is used if we have a complete multi-session * disc that we want/need to play with. * Here we specify the offset where we want to * start searching for the TOC. */ toc_offset = atol(optarg); break; case 'N': /* * Use this if we have an image of a single session * and we need to list the directory contents. * This is the session block number of the start * of the session. */ sector_offset = atol(optarg); break; case 'i': filename = optarg; break; case 'x': xtract = optarg; break; default: usage(EX_BAD); } if( filename == NULL ) {#ifdef USE_LIBSCHILY comerrno(EX_BAD, "Error - file not specified\n");#else fprintf(stderr, "Error - file not specified\n"); exit(1);#endif } infile = fopen(filename,"rb"); if( infile == NULL ) {#ifdef USE_LIBSCHILY comerr("Unable to open file %s\n", filename);#else fprintf(stderr,"Unable to open file %s\n", filename); exit(1);#endif } /* * Absolute sector offset, so don't subtract sector_offset here. */ lseek(fileno(infile), (16 + toc_offset) <<11, 0); read(fileno(infile), &ipd, sizeof(ipd)); if (do_pvd) { printf("CD-ROM is in ISO 9660 format\n"); printf("System id: "); printchars(ipd.system_id, 32); putchar('\n'); printf("Volume id: "); printchars(ipd.volume_id, 32); putchar('\n'); printf("Volume set id: "); printchars(ipd.volume_set_id, 128); putchar('\n'); printf("Publisher id: "); printchars(ipd.publisher_id, 128); putchar('\n'); printf("Data preparer id: "); printchars(ipd.preparer_id, 128); putchar('\n'); printf("Application id: "); printchars(ipd.application_id, 128); putchar('\n'); printf("Copyright File id: "); printchars(ipd.copyright_file_id, 37); putchar('\n'); printf("Abstract File id: "); printchars(ipd.abstract_file_id, 37); putchar('\n'); printf("Bibliographic File id: "); printchars(ipd.bibliographic_file_id, 37); putchar('\n'); printf("Volume set size is: %d\n", isonum_723(ipd.volume_set_size)); printf("Volume set seqence number is: %d\n", isonum_723(ipd.volume_sequence_number)); printf("Logical block size is: %d\n", isonum_723(ipd.logical_block_size)); printf("Volume size is: %d\n", isonum_733((unsigned char *)ipd.volume_space_size)); exit(0); } if( use_joliet ) { int block = 16; while( (unsigned char) ipd.type[0] != ISO_VD_END ) { if( (unsigned char) ipd.type[0] == ISO_VD_SUPPLEMENTARY ) /* * Find the UCS escape sequence. */ if( ipd.escape_sequences[0] == '%' && ipd.escape_sequences[1] == '/' && ipd.escape_sequences[3] == '\0' && ( ipd.escape_sequences[2] == '@' || ipd.escape_sequences[2] == 'C' || ipd.escape_sequences[2] == 'E') ) { break; } block++; lseek(fileno(infile), (block + toc_offset) <<11, 0); read(fileno(infile), &ipd, sizeof(ipd)); } if( (unsigned char) ipd.type[0] == ISO_VD_END ) {#ifdef USE_LIBSCHILY comerrno(EX_BAD, "Unable to find Joliet SVD\n");#else fprintf(stderr, "Unable to find Joliet SVD\n"); exit(1);#endif } switch(ipd.escape_sequences[2]) { case '@': ucs_level = 1; break; case 'C': ucs_level = 2; break; case 'E': ucs_level = 3; break; } if( ucs_level > 3 ) {#ifdef USE_LIBSCHILY comerrno(EX_BAD, "Don't know what ucs_level == %d means\n", ucs_level);#else fprintf(stderr, "Don't know what ucs_level == %d means\n", ucs_level); exit(1);#endif } } idr = (struct iso_directory_record *)ipd.root_directory_record; if( do_pathtab ) { dump_pathtab(isonum_731(ipd.type_l_path_table), isonum_733((unsigned char *)ipd.path_table_size)); } parse_dir("/", isonum_733((unsigned char *)idr->extent), isonum_733((unsigned char *)idr->size)); td = todo_idr; while(td) { parse_dir(td->name, td->extent, td->length); td = td->next; } fclose(infile); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -