📄 extrafld.c
字号:
c_ef += z->cext; if ( verbose ) { print_extra_info(); } /** ** ** Now add the local version of the field. **/ make_extrafield_JLEE(l_ef); z->ext += EB_L_JLEE_SIZE; /** ** ** Now add the central version of the field. ** It's identical to the local header. I wonder why ?? * the first two fields are in Intel little-endian format */ make_extrafield_JLEE(c_ef); z->cext += EB_C_JLEE_SIZE; return ZE_OK;}/** This is an implementation of Johnny Lee's extra field.* I never saw Johnny Lee's code. My code is based on the extra-field* definition mac (see latest appnote 1997-03-11)* and on some experiments with Johnny Lee's Zip-app version 1.0, 1992** Unfortunately I cannot agree with his extra-field layout.* - it wasted space* - and holds not all mac-specific information** I coded this extra-field only for testing purposes.* I don't want support this extra-field. Please use my implementation.** This is old implementation of Johnny Lee's extra field.* All native datas are in Motorola (=big-endian) format*/static void make_extrafield_JLEE(char *ef){ Assert_it(ef, "make_extrafield_JLEE","") if (MacZip.isMacStatValid == false) { fprintf(stderr,"Internal Logic Error: [%d/%s] MacStat is out of sync !", __LINE__,__FILE__); exit(-1); } /* the first two fields are in Intel little-endian format */ *ef++ = 0xC8; /* tag for this extra block */ *ef++ = 0x07; *ef++ = (char)(EB_L_JLEE_LEN); /* total data size this block */ *ef++ = (char)((EB_L_JLEE_LEN) >> 8); /* the following fields are in motorola big-endian format */ *ef++ = 'J'; /* extra field signature: 4 Bytes */ *ef++ = 'L'; /* the old style extra field */ *ef++ = 'E'; *ef++ = 'E'; /* Start Macintosh Finder FInfo structure 16 Bytes overall */ /* Type: 4 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 24); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 16); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType); /* Creator: 4 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 24); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 16); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator); /* file Finder Flags: 2 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags); /* Finders Icon position of a file*/ /* V/Y-Position: 2 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.v >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.v); /* H/X-Position: 2 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.h >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.h); /* fdFldr Folder containing file 2 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFldr >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFldr); /* End Macintosh Finder FInfo structure */ /* Creation-time 4 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat >> 24); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat >> 16); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat); /* Modification-time 4 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat >> 24); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat >> 16); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat); /* info Bits 4 Bytes */ *ef++ = 0x00; *ef++ = 0x00; *ef++ = 0x00; if (MacZip.DataForkOnly) { /* don't convert filename for unzipping */ /* 0x01 = data-fork; 0x00 = resource-fork */ *ef++ = (char) (MacZip.CurrentFork == DataFork) | 2; } else { *ef++ = (char) (MacZip.CurrentFork == DataFork); } /* file's location folder ID 4 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlParID >> 24); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlParID >> 16); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlParID >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlParID); /* ============ */ /* 40 Bytes */}/** Build and add the new mac extra field* All native data are stored in Intel (=little-endian) format*/static int add_MAC3_ef( struct zlist far *z ){ char *l_ef = NULL; char *c_ef = NULL; char *attrbuff = NULL; off_t attrsize = (EB_L_MAC3_FINFO_LEN + EB_MAX_OF_VARDATA); char *compbuff = NULL; unsigned compsize = 0; unsigned m3_compr; Boolean compress_data = true; Assert_it(z, "add_MAC3_ef","") UserStop(); /* do event handling and let the user stop */ if( verbose ) { print_extra_info(); } /* allocate temporary buffer to collect the Mac extra field info */ attrbuff = (char *)malloc( (size_t)attrsize ); if( attrbuff == NULL ) { return ZE_MEM; } /* fill the attribute buffer, to get its (uncompressed) size */ attrsize = make_extrafield_MAC3(attrbuff); if (compress_data && ((compbuff = (char *)malloc((size_t)attrsize + MEMCOMPRESS_OVERHEAD)) != NULL)) { /* Try compressing the data */ compsize = memcompress( compbuff, (size_t)attrsize + MEMCOMPRESS_OVERHEAD, attrbuff, (size_t)attrsize );#ifdef MAC_EXTRAFLD_UNCMPR compsize = attrsize;#endif } else { compsize = attrsize; } if ((compsize) < attrsize) { /* compression gained some space ... */ free(attrbuff); /* no longer needed ... */ m3_compr = EB_M3_FL_COMPRESS; } else { /* compression does not help, store data in uncompressed mode */ if (compbuff != NULL) free(compbuff); compbuff = attrbuff; compsize = attrsize; m3_compr = EB_M3_FL_UNCMPR; } /* Check to make sure we've got enough room in the extra fields. */ if( z->ext + (EB_L_MAC3_SIZE + compsize) > EXTRAFLD_MAX || z->cext + EB_C_MAC3_SIZE > EXTRAFLD_MAX ) { if (compbuff != NULL) free(compbuff); return ZE_MEM; } /* Allocate memory for the local extra fields. */ if( z->extra && z->ext != 0 ) { l_ef = (char *)realloc( z->extra, z->ext + EB_L_MAC3_SIZE + compsize); } else { l_ef = (char *)malloc( EB_L_MAC3_SIZE + compsize); z->ext = 0; } if( l_ef == NULL ) { return ZE_MEM; } z->extra = l_ef; l_ef += z->ext; /* Allocate memory for the central extra fields. */ if( z->cextra && z->cext != 0 ) { c_ef = (char *)realloc( z->cextra, z->cext + EB_C_MAC3_SIZE); } else { c_ef = (char *)malloc( EB_C_MAC3_SIZE ); z->cext = 0; } if( c_ef == NULL ) { return ZE_MEM; } z->cextra = c_ef; c_ef += z->cext; /** ** Now add the local version of the field. **/ l_ef = make_EF_Head_MAC3(l_ef, compsize, (ulg)attrsize, m3_compr); memcpy(l_ef, compbuff, (size_t)compsize); l_ef += compsize; z->ext += EB_L_MAC3_SIZE + compsize; free(compbuff); /* And the central version. */ c_ef = make_EF_Head_MAC3(c_ef, 0, (ulg)attrsize, m3_compr); z->cext += EB_C_MAC3_SIZE; return ZE_OK;}/** Build the new mac local extra field header.* It's identical with the central extra field.* All native data are in Intel (=little-endian) format*/static char *make_EF_Head_MAC3(char *ef, unsigned compsize, ulg attrsize, unsigned flag){ unsigned info_flag = flag; Assert_it(ef, "make_EF_Head_MAC3","") /* the first four fields are in Intel little-endian format */ *ef++ = 'M'; /* tag for this extra block 2 Bytes */ *ef++ = '3'; /* total data size this block 2 Bytes */ *ef++ = (char) (EB_MAC3_HLEN + compsize); *ef++ = (char)((EB_MAC3_HLEN + compsize) >> 8); *ef++ = (char)(attrsize); *ef++ = (char)(attrsize >> 8); *ef++ = (char)(attrsize >> 16); *ef++ = (char)(attrsize >> 24); /* info Bits (flags) 2 Bytes */ if (MacZip.DataForkOnly) info_flag |= (EB_M3_FL_DATFRK | EB_M3_FL_NOCHANGE); if (MacZip.CurrentFork == DataFork) info_flag |= EB_M3_FL_DATFRK; if (!MacZip.HaveGMToffset) info_flag |= EB_M3_FL_NOUTC; *ef++ = (char)info_flag; *ef++ = (char)0x00; /* reserved at the moment */ /* Note: Apple defined File-Type/-Creator as OSType ( =unsigned long, see Universal Headers 3.1). However, File-Type/-Creator are a unique four-character sequence. Therefore the byteorder of the File-Type/-Creator are NOT changed. The native format is used. */ /* Type: 4 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 24); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 16); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType); /* Creator: 4 Bytes */ *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 24); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 16); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 8); *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -