aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-03-23 04:27:58 +0000
committerErik Andersen <andersen@codepoet.org>2000-03-23 04:27:58 +0000
commite454fb68a3165ca5cf42c290b4b9dc92dbf9a235 (patch)
tree224162e67279711d00218e91d70f50eebd5bec9e
parent298854f02963bd8e43dfeb7224d88cfeb0c932cb (diff)
downloadbusybox-w32-e454fb68a3165ca5cf42c290b4b9dc92dbf9a235.tar.gz
busybox-w32-e454fb68a3165ca5cf42c290b4b9dc92dbf9a235.tar.bz2
busybox-w32-e454fb68a3165ca5cf42c290b4b9dc92dbf9a235.zip
More changes that are broken. It doesn't compile
yet, but is closer. -Erik
-rw-r--r--archival/tar.c100
-rw-r--r--tar.c100
2 files changed, 114 insertions, 86 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 8f83d04a6..99f166c3e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -141,41 +141,11 @@ typedef struct TarInfo TarInfo;
141static const unsigned long TarChecksumOffset = (const unsigned long)&(((TarHeader *)0)->chksum); 141static const unsigned long TarChecksumOffset = (const unsigned long)&(((TarHeader *)0)->chksum);
142 142
143 143
144/* 144/* Local procedures to restore files from a tar file. */
145 * Static data.
146 */
147static int inHeader; // <- check me
148static int badHeader;
149static int skipFileFlag;
150static int warnedRoot;
151static int eofFlag;
152static long dataCc;
153static int outFd;
154static const char *outName;
155
156static int mode;
157static int uid;
158static int gid;
159static time_t mtime;
160
161/*
162 * Static data associated with the tar file.
163 */
164static int tarFd;
165static dev_t tarDev;
166static ino_t tarInode;
167
168
169/*
170 * Local procedures to restore files from a tar file.
171 */
172static int readTarFile(const char* tarName, int extractFlag, int listFlag, 145static int readTarFile(const char* tarName, int extractFlag, int listFlag,
173 int tostdoutFlag, int verboseFlag); 146 int tostdoutFlag, int verboseFlag);
174static void readData(const char *cp, int count);
175static long getOctal(const char *cp, int len); 147static long getOctal(const char *cp, int len);
176static int parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header); 148static int parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header);
177static int wantFileName(const char *fileName,
178 int argc, char **argv);
179 149
180#ifdef BB_FEATURE_TAR_CREATE 150#ifdef BB_FEATURE_TAR_CREATE
181/* 151/*
@@ -286,10 +256,35 @@ extern int tar_main(int argc, char **argv)
286static void 256static void
287tarExtractRegularFile(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag) 257tarExtractRegularFile(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
288{ 258{
259 return;
260}
261
262static void
263tarExtractDirectory(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
264{
265 return;
266}
267
268static void
269tarExtractHardLink(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
270{
271 return;
272}
273
274static void
275tarExtractSymLink(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
276{
277 return;
278}
289 279
280static void
281tarExtractSpecial(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
282{
283 return;
290} 284}
291 285
292 286
287
293/* 288/*
294 * Read a tar file and extract or list the specified files within it. 289 * Read a tar file and extract or list the specified files within it.
295 * If the list is empty than all files are extracted or listed. 290 * If the list is empty than all files are extracted or listed.
@@ -327,6 +322,25 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
327 } 322 }
328 if ( *(header.name) == '\0' ) 323 if ( *(header.name) == '\0' )
329 goto endgame; 324 goto endgame;
325
326 if (extractFlag == FALSE) {
327 if (verboseFlag == TRUE) {
328 printf("%s %3d/%-d ", modeString(header.mode), header.uid, header.gid);
329 if (header.type==CHRTYPE || header.type==BLKTYPE)
330 printf("%4d,%4d %s ", MAJOR(header.device),
331 MINOR(header.device), timeString(header.mtime));
332 else
333 printf("%9ld %s ", header.size, timeString(header.mtime));
334 }
335 printf("%s", header.name);
336
337 if (header.type==LNKTYPE)
338 printf(" (link to \"%s\")", hp->linkName);
339 else if (header.type==SYMTYPE)
340 printf(" (symlink to \"%s\")", hp->linkName);
341 printf("\n");
342 continue;
343 }
330 344
331 /* If we got here, we can be certain we have a legitimate 345 /* If we got here, we can be certain we have a legitimate
332 * header to work with. So work with it. */ 346 * header to work with. So work with it. */
@@ -339,22 +353,20 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
339 tarExtractRegularFile(&header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 353 tarExtractRegularFile(&header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
340 break; 354 break;
341 } 355 }
342#if 0 356 case DIRTYPE:
343 case Directory:
344 tarExtractDirectory( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 357 tarExtractDirectory( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
345 break; 358 break;
346 case HardLink: 359 case LNKTYPE:
347 tarExtractHardLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 360 tarExtractHardLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
348 break; 361 break;
349 case SymbolicLink: 362 case SYMTYPE:
350 tarExtractSymLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 363 tarExtractSymLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
351 break; 364 break;
352 case CharacterDevice: 365 case CHRTYPE:
353 case BlockDevice: 366 case BLKTYPE:
354 case FIFO: 367 case FIFOTYPE:
355 tarExtractSpecial( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 368 tarExtractSpecial( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
356 break; 369 break;
357#endif
358 default: 370 default:
359 close( tarFd); 371 close( tarFd);
360 return( FALSE); 372 return( FALSE);
@@ -405,7 +417,9 @@ static long getOctal(const char *cp, int size)
405static int 417static int
406parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) 418parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
407{ 419{
408 long major, minor, chksum, sum; 420 int i;
421 long chksum, sum;
422 unsigned char *s = (unsigned char *)rawHeader;
409 423
410 header->name = rawHeader->name; 424 header->name = rawHeader->name;
411 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode)); 425 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode));
@@ -423,10 +437,10 @@ parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
423 sum = ' ' * sizeof(rawHeader->chksum); 437 sum = ' ' * sizeof(rawHeader->chksum);
424 for ( i = TarChecksumOffset; i > 0; i-- ) 438 for ( i = TarChecksumOffset; i > 0; i-- )
425 sum += *s++; 439 sum += *s++;
426 s += sizeof(h->chksum); 440 s += sizeof(rawHeader->chksum);
427 for ( i = (512 - TarChecksumOffset - sizeof(h->chksum)); i > 0; i-- ) 441 for ( i = (512 - TarChecksumOffset - sizeof(rawHeader->chksum)); i > 0; i-- )
428 sum += *s++; 442 sum += *s++;
429 if (sum == checksum ) 443 if (sum == chksum )
430 return ( TRUE); 444 return ( TRUE);
431 return( FALSE); 445 return( FALSE);
432} 446}
diff --git a/tar.c b/tar.c
index 8f83d04a6..99f166c3e 100644
--- a/tar.c
+++ b/tar.c
@@ -141,41 +141,11 @@ typedef struct TarInfo TarInfo;
141static const unsigned long TarChecksumOffset = (const unsigned long)&(((TarHeader *)0)->chksum); 141static const unsigned long TarChecksumOffset = (const unsigned long)&(((TarHeader *)0)->chksum);
142 142
143 143
144/* 144/* Local procedures to restore files from a tar file. */
145 * Static data.
146 */
147static int inHeader; // <- check me
148static int badHeader;
149static int skipFileFlag;
150static int warnedRoot;
151static int eofFlag;
152static long dataCc;
153static int outFd;
154static const char *outName;
155
156static int mode;
157static int uid;
158static int gid;
159static time_t mtime;
160
161/*
162 * Static data associated with the tar file.
163 */
164static int tarFd;
165static dev_t tarDev;
166static ino_t tarInode;
167
168
169/*
170 * Local procedures to restore files from a tar file.
171 */
172static int readTarFile(const char* tarName, int extractFlag, int listFlag, 145static int readTarFile(const char* tarName, int extractFlag, int listFlag,
173 int tostdoutFlag, int verboseFlag); 146 int tostdoutFlag, int verboseFlag);
174static void readData(const char *cp, int count);
175static long getOctal(const char *cp, int len); 147static long getOctal(const char *cp, int len);
176static int parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header); 148static int parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header);
177static int wantFileName(const char *fileName,
178 int argc, char **argv);
179 149
180#ifdef BB_FEATURE_TAR_CREATE 150#ifdef BB_FEATURE_TAR_CREATE
181/* 151/*
@@ -286,10 +256,35 @@ extern int tar_main(int argc, char **argv)
286static void 256static void
287tarExtractRegularFile(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag) 257tarExtractRegularFile(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
288{ 258{
259 return;
260}
261
262static void
263tarExtractDirectory(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
264{
265 return;
266}
267
268static void
269tarExtractHardLink(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
270{
271 return;
272}
273
274static void
275tarExtractSymLink(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
276{
277 return;
278}
289 279
280static void
281tarExtractSpecial(TarInfo *header, int extractFlag, int listFlag, int tostdoutFlag, int verboseFlag)
282{
283 return;
290} 284}
291 285
292 286
287
293/* 288/*
294 * Read a tar file and extract or list the specified files within it. 289 * Read a tar file and extract or list the specified files within it.
295 * If the list is empty than all files are extracted or listed. 290 * If the list is empty than all files are extracted or listed.
@@ -327,6 +322,25 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
327 } 322 }
328 if ( *(header.name) == '\0' ) 323 if ( *(header.name) == '\0' )
329 goto endgame; 324 goto endgame;
325
326 if (extractFlag == FALSE) {
327 if (verboseFlag == TRUE) {
328 printf("%s %3d/%-d ", modeString(header.mode), header.uid, header.gid);
329 if (header.type==CHRTYPE || header.type==BLKTYPE)
330 printf("%4d,%4d %s ", MAJOR(header.device),
331 MINOR(header.device), timeString(header.mtime));
332 else
333 printf("%9ld %s ", header.size, timeString(header.mtime));
334 }
335 printf("%s", header.name);
336
337 if (header.type==LNKTYPE)
338 printf(" (link to \"%s\")", hp->linkName);
339 else if (header.type==SYMTYPE)
340 printf(" (symlink to \"%s\")", hp->linkName);
341 printf("\n");
342 continue;
343 }
330 344
331 /* If we got here, we can be certain we have a legitimate 345 /* If we got here, we can be certain we have a legitimate
332 * header to work with. So work with it. */ 346 * header to work with. So work with it. */
@@ -339,22 +353,20 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
339 tarExtractRegularFile(&header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 353 tarExtractRegularFile(&header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
340 break; 354 break;
341 } 355 }
342#if 0 356 case DIRTYPE:
343 case Directory:
344 tarExtractDirectory( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 357 tarExtractDirectory( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
345 break; 358 break;
346 case HardLink: 359 case LNKTYPE:
347 tarExtractHardLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 360 tarExtractHardLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
348 break; 361 break;
349 case SymbolicLink: 362 case SYMTYPE:
350 tarExtractSymLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 363 tarExtractSymLink( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
351 break; 364 break;
352 case CharacterDevice: 365 case CHRTYPE:
353 case BlockDevice: 366 case BLKTYPE:
354 case FIFO: 367 case FIFOTYPE:
355 tarExtractSpecial( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag); 368 tarExtractSpecial( &header, extractFlag, listFlag, tostdoutFlag, verboseFlag);
356 break; 369 break;
357#endif
358 default: 370 default:
359 close( tarFd); 371 close( tarFd);
360 return( FALSE); 372 return( FALSE);
@@ -405,7 +417,9 @@ static long getOctal(const char *cp, int size)
405static int 417static int
406parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) 418parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
407{ 419{
408 long major, minor, chksum, sum; 420 int i;
421 long chksum, sum;
422 unsigned char *s = (unsigned char *)rawHeader;
409 423
410 header->name = rawHeader->name; 424 header->name = rawHeader->name;
411 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode)); 425 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode));
@@ -423,10 +437,10 @@ parseTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
423 sum = ' ' * sizeof(rawHeader->chksum); 437 sum = ' ' * sizeof(rawHeader->chksum);
424 for ( i = TarChecksumOffset; i > 0; i-- ) 438 for ( i = TarChecksumOffset; i > 0; i-- )
425 sum += *s++; 439 sum += *s++;
426 s += sizeof(h->chksum); 440 s += sizeof(rawHeader->chksum);
427 for ( i = (512 - TarChecksumOffset - sizeof(h->chksum)); i > 0; i-- ) 441 for ( i = (512 - TarChecksumOffset - sizeof(rawHeader->chksum)); i > 0; i-- )
428 sum += *s++; 442 sum += *s++;
429 if (sum == checksum ) 443 if (sum == chksum )
430 return ( TRUE); 444 return ( TRUE);
431 return( FALSE); 445 return( FALSE);
432} 446}