blob: 3082914550a32672d10dcd8ed4270092be31219e [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersencc8ed391999-10-05 16:24:54 +00002/*
Erik Andersen68a9ea42000-04-04 18:39:50 +00003 * Mini tar implementation for busybox
Erik Andersen6acaa402000-03-26 14:03:20 +00004 *
Erik Andersen61677fe2000-04-13 01:18:56 +00005 * Note, that as of BusyBox-0.43, tar has been completely rewritten from the
6 * ground up. It still has remnents of the old code lying about, but it is
7 * very different now (i.e. cleaner, less global variables, etc)
Eric Andersenc4996011999-10-20 22:08:37 +00008 *
Eric Andersen8ec10a92001-01-27 09:33:39 +00009 * Copyright (C) 1999,2000,2001 by Lineo, inc.
Erik Andersen1ad302a2000-03-24 00:54:46 +000010 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
Eric Andersen96bcfd31999-11-12 01:30:18 +000011 *
Erik Andersen6acaa402000-03-26 14:03:20 +000012 * Based in part in the tar implementation in sash
13 * Copyright (c) 1999 by David I. Bell
14 * Permission is granted to use, distribute, or modify this source,
15 * provided that this copyright notice remains intact.
16 * Permission to distribute sash derived code under the GPL has been granted.
17 *
Erik Andersen68a9ea42000-04-04 18:39:50 +000018 * Based in part on the tar implementation from busybox-0.28
Erik Andersen6acaa402000-03-26 14:03:20 +000019 * Copyright (C) 1995 Bruce Perens
20 * This is free software under the GNU General Public License.
21 *
Eric Andersenc4996011999-10-20 22:08:37 +000022 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 *
Eric Andersencc8ed391999-10-05 16:24:54 +000036 */
37
38
Eric Andersen3570a342000-09-25 21:45:58 +000039#include "busybox.h"
Erik Andersen1ad302a2000-03-24 00:54:46 +000040#define BB_DECLARE_EXTERN
41#define bb_need_io_error
Eric Andersen3c5ee9a2000-11-14 22:15:48 +000042#define bb_need_name_longer_than_foo
Erik Andersen1ad302a2000-03-24 00:54:46 +000043#include "messages.c"
Eric Andersencc8ed391999-10-05 16:24:54 +000044#include <stdio.h>
45#include <dirent.h>
46#include <errno.h>
47#include <fcntl.h>
48#include <signal.h>
49#include <time.h>
Erik Andersen7dc16072000-01-04 01:10:25 +000050#include <utime.h>
Eric Andersen96bcfd31999-11-12 01:30:18 +000051#include <sys/types.h>
Eric Andersen08b10341999-11-19 02:38:58 +000052#include <sys/sysmacros.h>
Matt Kraai43c8c382000-09-04 16:51:55 +000053#include <getopt.h>
Matt Kraaibe7499c2001-01-03 17:22:10 +000054#include <fnmatch.h>
Eric Andersened3ef502001-01-27 08:24:39 +000055#include <string.h>
56#include <stdlib.h>
57#include <unistd.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000058
Glenn L McGrath46f44d22000-12-10 01:57:30 +000059#ifdef BB_FEATURE_TAR_GZIP
60extern int unzip(int in, int out);
61extern int gunzip_init();
62#endif
63
Erik Andersen298854f2000-03-23 01:09:18 +000064/* Tar file constants */
Erik Andersen1ad302a2000-03-24 00:54:46 +000065#ifndef MAJOR
66#define MAJOR(dev) (((dev)>>8)&0xff)
67#define MINOR(dev) ((dev)&0xff)
68#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000069
Mark Whitley59ab0252001-01-23 22:30:04 +000070enum { NAME_SIZE = 100 }; /* because gcc won't let me use 'static const int' */
Eric Andersencc8ed391999-10-05 16:24:54 +000071
Erik Andersen298854f2000-03-23 01:09:18 +000072/* POSIX tar Header Block, from POSIX 1003.1-1990 */
73struct TarHeader
74{
75 /* byte offset */
Eric Andersen1b1cfde2000-09-24 00:54:37 +000076 char name[NAME_SIZE]; /* 0-99 */
Erik Andersen0817d132000-04-09 15:17:40 +000077 char mode[8]; /* 100-107 */
78 char uid[8]; /* 108-115 */
79 char gid[8]; /* 116-123 */
80 char size[12]; /* 124-135 */
81 char mtime[12]; /* 136-147 */
82 char chksum[8]; /* 148-155 */
83 char typeflag; /* 156-156 */
Eric Andersen1b1cfde2000-09-24 00:54:37 +000084 char linkname[NAME_SIZE]; /* 157-256 */
Erik Andersen0817d132000-04-09 15:17:40 +000085 char magic[6]; /* 257-262 */
86 char version[2]; /* 263-264 */
87 char uname[32]; /* 265-296 */
88 char gname[32]; /* 297-328 */
89 char devmajor[8]; /* 329-336 */
90 char devminor[8]; /* 337-344 */
91 char prefix[155]; /* 345-499 */
92 char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
Erik Andersen298854f2000-03-23 01:09:18 +000093};
94typedef struct TarHeader TarHeader;
Eric Andersencc8ed391999-10-05 16:24:54 +000095
Eric Andersencc8ed391999-10-05 16:24:54 +000096
Erik Andersen298854f2000-03-23 01:09:18 +000097/* A few useful constants */
98#define TAR_MAGIC "ustar" /* ustar and a null */
Erik Andersen0817d132000-04-09 15:17:40 +000099#define TAR_VERSION " " /* Be compatable with GNU tar format */
Mark Whitley59ab0252001-01-23 22:30:04 +0000100static const int TAR_MAGIC_LEN = 6;
101static const int TAR_VERSION_LEN = 2;
102static const int TAR_BLOCK_SIZE = 512;
Erik Andersen298854f2000-03-23 01:09:18 +0000103
104/* A nice enum with all the possible tar file content types */
105enum TarFileType
106{
107 REGTYPE = '0', /* regular file */
108 REGTYPE0 = '\0', /* regular file (ancient bug compat)*/
109 LNKTYPE = '1', /* hard link */
110 SYMTYPE = '2', /* symbolic link */
111 CHRTYPE = '3', /* character special */
112 BLKTYPE = '4', /* block special */
113 DIRTYPE = '5', /* directory */
114 FIFOTYPE = '6', /* FIFO special */
115 CONTTYPE = '7', /* reserved */
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000116 GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
117 GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
Erik Andersen298854f2000-03-23 01:09:18 +0000118};
119typedef enum TarFileType TarFileType;
120
121/* This struct ignores magic, non-numeric user name,
122 * non-numeric group name, and the checksum, since
123 * these are all ignored by BusyBox tar. */
124struct TarInfo
125{
126 int tarFd; /* An open file descriptor for reading from the tarball */
127 char * name; /* File name */
128 mode_t mode; /* Unix mode, including device bits. */
129 uid_t uid; /* Numeric UID */
130 gid_t gid; /* Numeric GID */
131 size_t size; /* Size of file */
132 time_t mtime; /* Last-modified time */
133 enum TarFileType type; /* Regular, directory, link, etc */
134 char * linkname; /* Name for symbolic and hard links */
Erik Andersen1ad302a2000-03-24 00:54:46 +0000135 long devmajor; /* Major number for special device */
136 long devminor; /* Minor number for special device */
Erik Andersen298854f2000-03-23 01:09:18 +0000137};
138typedef struct TarInfo TarInfo;
139
Erik Andersene454fb62000-03-23 04:27:58 +0000140/* Local procedures to restore files from a tar file. */
Glenn L McGrath7541e3a2001-01-02 23:41:50 +0000141extern int readTarFile(int tarFd, int extractFlag, int listFlag,
Matt Kraaib92223b2000-09-04 08:25:42 +0000142 int tostdoutFlag, int verboseFlag, char** extractList,
143 char** excludeList);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000144
Erik Andersen05100cd2000-01-16 01:30:52 +0000145#ifdef BB_FEATURE_TAR_CREATE
Erik Andersen6acaa402000-03-26 14:03:20 +0000146/* Local procedures to save files into a tar file. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +0000147static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
148 char** excludeList);
Erik Andersen05100cd2000-01-16 01:30:52 +0000149#endif
150
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000151#ifdef BB_FEATURE_TAR_GZIP
152/* Signal handler for when child gzip process dies... */
153void child_died()
154{
155 fflush(stdout);
156 fflush(stderr);
157 exit(EXIT_FAILURE);
158}
159
Glenn L McGrath7541e3a2001-01-02 23:41:50 +0000160extern int tar_unzip_init(int tarFd)
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000161{
162 int child_pid;
163 static int unzip_pipe[2];
164 /* Cope if child dies... Otherwise we block forever in read()... */
165 signal(SIGCHLD, child_died);
166
167 if (pipe(unzip_pipe)!=0)
168 error_msg_and_die("pipe error\n");
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000169
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000170 if ( (child_pid = fork()) == -1)
171 error_msg_and_die("fork failure\n");
172
173 if (child_pid==0) {
174 /* child process */
Glenn L McGrath1d269432001-01-20 00:12:21 +0000175 close(unzip_pipe[0]);
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000176 gunzip_init();
177 unzip(tarFd, unzip_pipe[1]);
178 exit(EXIT_SUCCESS);
179 }
Glenn L McGrath1d269432001-01-20 00:12:21 +0000180 else {
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000181 /* return fd of uncompressed data to parent process */
Glenn L McGrath1d269432001-01-20 00:12:21 +0000182 close(unzip_pipe[1]);
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000183 return(unzip_pipe[0]);
Glenn L McGrath1d269432001-01-20 00:12:21 +0000184 }
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000185}
186#endif
187
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000188#if defined BB_FEATURE_TAR_EXCLUDE
189struct option longopts[] = {
190 { "exclude", 1, NULL, 'e' },
191 { NULL, 0, NULL, 0 }
192};
193#endif
194
Erik Andersene49d5ec2000-02-08 19:58:47 +0000195extern int tar_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +0000196{
Erik Andersenecd51242000-04-08 03:08:21 +0000197 char** excludeList=NULL;
Matt Kraaic119ab92000-11-30 04:44:54 +0000198 char** extractList=NULL;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000199 const char *tarName="-";
Erik Andersen0817d132000-04-09 15:17:40 +0000200#if defined BB_FEATURE_TAR_EXCLUDE
Erik Andersenecd51242000-04-08 03:08:21 +0000201 int excludeListSize=0;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000202 FILE *fileList;
203 char file[256];
Erik Andersen0817d132000-04-09 15:17:40 +0000204#endif
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000205#if defined BB_FEATURE_TAR_GZIP
206 int unzipFlag = FALSE;
207#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000208 int listFlag = FALSE;
209 int extractFlag = FALSE;
210 int createFlag = FALSE;
211 int verboseFlag = FALSE;
212 int tostdoutFlag = FALSE;
Eric Andersen02f3b2e2000-12-01 19:04:52 +0000213 int status = FALSE;
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000214 int opt;
Eric Andersencc8ed391999-10-05 16:24:54 +0000215
Erik Andersenecd51242000-04-08 03:08:21 +0000216 if (argc <= 1)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000217 usage(tar_usage);
Eric Andersencc8ed391999-10-05 16:24:54 +0000218
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000219 if (argv[1][0] != '-') {
220 char *tmp = xmalloc(strlen(argv[1]) + 2);
221 tmp[0] = '-';
222 strcpy(tmp + 1, argv[1]);
223 argv[1] = tmp;
224 }
225
226 while (
227#ifndef BB_FEATURE_TAR_EXCLUDE
228 (opt = getopt(argc, argv, "cxtzvOf:"))
229#else
230 (opt = getopt_long(argc, argv, "cxtzvOf:X:", longopts, NULL))
231#endif
232 > 0) {
233 switch (opt) {
234 case 'c':
235 if (extractFlag == TRUE || listFlag == TRUE)
236 goto flagError;
237 createFlag = TRUE;
238 break;
239 case 'x':
240 if (listFlag == TRUE || createFlag == TRUE)
241 goto flagError;
242 extractFlag = TRUE;
243 break;
244 case 't':
245 if (extractFlag == TRUE || createFlag == TRUE)
246 goto flagError;
247 listFlag = TRUE;
248 break;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000249#ifdef BB_FEATURE_TAR_GZIP
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000250 case 'z':
251 unzipFlag = TRUE;
252 break;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000253#endif
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000254 case 'v':
255 verboseFlag = TRUE;
256 break;
257 case 'O':
258 tostdoutFlag = TRUE;
259 break;
260 case 'f':
261 if (*tarName != '-')
262 error_msg_and_die( "Only one 'f' option allowed\n");
263 tarName = optarg;
264 break;
Erik Andersen0817d132000-04-09 15:17:40 +0000265#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000266 case 'e':
267 excludeList=xrealloc( excludeList,
268 sizeof(char *) * (excludeListSize+2));
269 excludeList[excludeListSize] = optarg;
270 /* Tack a NULL onto the end of the list */
271 excludeList[++excludeListSize] = NULL;
272 case 'X':
273 fileList = xfopen(optarg, "r");
274 while (fgets(file, sizeof(file), fileList) != NULL) {
275 excludeList = xrealloc(excludeList,
276 sizeof(char *) * (excludeListSize+2));
277 if (file[strlen(file)-1] == '\n')
278 file[strlen(file)-1] = '\0';
279 excludeList[excludeListSize] = xstrdup(file);
280 /* Tack a NULL onto the end of the list */
281 excludeList[++excludeListSize] = NULL;
282 }
283 fclose(fileList);
284 break;
Erik Andersen0817d132000-04-09 15:17:40 +0000285#endif
Erik Andersenecd51242000-04-08 03:08:21 +0000286 default:
Matt Kraai43c8c382000-09-04 16:51:55 +0000287 usage(tar_usage);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000288 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000289 }
290
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000291 /*
Erik Andersene49d5ec2000-02-08 19:58:47 +0000292 * Do the correct type of action supplying the rest of the
293 * command line arguments as the list of files to process.
294 */
295 if (createFlag == TRUE) {
Erik Andersende552872000-01-23 01:34:05 +0000296#ifndef BB_FEATURE_TAR_CREATE
Mark Whitleyf57c9442000-12-07 19:56:48 +0000297 error_msg_and_die( "This version of tar was not compiled with tar creation support.\n");
Erik Andersende552872000-01-23 01:34:05 +0000298#else
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000299#ifdef BB_FEATURE_TAR_GZIP
300 if (unzipFlag==TRUE)
301 error_msg_and_die("Creation of compressed not internally support by tar, pipe to busybox gunzip\n");
302#endif
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000303 status = writeTarFile(tarName, verboseFlag, argv + optind, excludeList);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000304#endif
Erik Andersen8ea7d8c2000-05-20 00:40:08 +0000305 }
306 if (listFlag == TRUE || extractFlag == TRUE) {
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000307 int tarFd;
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000308 if (argv[optind])
309 extractList = argv + optind;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000310 /* Open the tar file for reading. */
311 if (!strcmp(tarName, "-"))
312 tarFd = fileno(stdin);
313 else
314 tarFd = open(tarName, O_RDONLY);
315 if (tarFd < 0)
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000316 perror_msg_and_die("Error opening '%s'", tarName);
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000317
318#ifdef BB_FEATURE_TAR_GZIP
319 /* unzip tarFd in a seperate process */
320 if (unzipFlag == TRUE)
321 tarFd = tar_unzip_init(tarFd);
322#endif
323 status = readTarFile(tarFd, extractFlag, listFlag, tostdoutFlag,
Matt Kraai3e856ce2000-12-01 02:55:13 +0000324 verboseFlag, extractList, excludeList);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000325 }
Erik Andersende552872000-01-23 01:34:05 +0000326
Matt Kraai3e856ce2000-12-01 02:55:13 +0000327 if (status == TRUE)
328 return EXIT_SUCCESS;
329 else
330 return EXIT_FAILURE;
331
Erik Andersene49d5ec2000-02-08 19:58:47 +0000332 flagError:
Mark Whitleyf57c9442000-12-07 19:56:48 +0000333 error_msg_and_die( "Exactly one of 'c', 'x' or 't' must be specified\n");
Erik Andersen298854f2000-03-23 01:09:18 +0000334}
335
336static void
Erik Andersen6a34b532000-04-07 06:55:38 +0000337fixUpPermissions(TarInfo *header)
338{
339 struct utimbuf t;
340 /* Now set permissions etc for the new file */
341 chown(header->name, header->uid, header->gid);
342 chmod(header->name, header->mode);
343 /* Reset the time */
344 t.actime = time(0);
345 t.modtime = header->mtime;
346 utime(header->name, &t);
347}
348
349static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000350tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersen298854f2000-03-23 01:09:18 +0000351{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000352 size_t writeSize;
353 size_t readSize;
354 size_t actualWriteSz;
355 char buffer[BUFSIZ];
356 size_t size = header->size;
357 int outFd=fileno(stdout);
358
359 /* Open the file to be written, if a file is supposed to be written */
360 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000361 /* Create the path to the file, just in case it isn't there...
362 * This should not screw up path permissions or anything. */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000363 create_path(header->name, 0777);
Eric Andersen0c6a9702000-06-09 20:51:50 +0000364 if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
365 header->mode & ~S_IFMT)) < 0) {
Mark Whitleyf57c9442000-12-07 19:56:48 +0000366 error_msg(io_error, header->name, strerror(errno));
Eric Andersen0c6a9702000-06-09 20:51:50 +0000367 return( FALSE);
368 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000369 }
370
371 /* Write out the file, if we are supposed to be doing that */
372 while ( size > 0 ) {
373 actualWriteSz=0;
374 if ( size > sizeof(buffer) )
375 writeSize = readSize = sizeof(buffer);
376 else {
377 int mod = size % 512;
378 if ( mod != 0 )
379 readSize = size + (512 - mod);
380 else
381 readSize = size;
382 writeSize = size;
383 }
Mark Whitleyf57c9442000-12-07 19:56:48 +0000384 if ( (readSize = full_read(header->tarFd, buffer, readSize)) <= 0 ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000385 /* Tarball seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000386 error_msg("Unexpected EOF in archive\n");
Erik Andersen6a34b532000-04-07 06:55:38 +0000387 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000388 }
389 if ( readSize < writeSize )
390 writeSize = readSize;
391
392 /* Write out the file, if we are supposed to be doing that */
393 if (extractFlag==TRUE) {
394
Mark Whitleyf57c9442000-12-07 19:56:48 +0000395 if ((actualWriteSz=full_write(outFd, buffer, writeSize)) != writeSize ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000396 /* Output file seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000397 error_msg(io_error, header->name, strerror(errno));
Erik Andersen6a34b532000-04-07 06:55:38 +0000398 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000399 }
Erik Andersen0817d132000-04-09 15:17:40 +0000400 } else {
401 actualWriteSz=writeSize;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000402 }
403
404 size -= actualWriteSz;
405 }
406
407 /* Now we are done writing the file out, so try
408 * and fix up the permissions and whatnot */
409 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000410 close(outFd);
Erik Andersen6a34b532000-04-07 06:55:38 +0000411 fixUpPermissions(header);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000412 }
Erik Andersen6a34b532000-04-07 06:55:38 +0000413 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000414}
415
Erik Andersen6a34b532000-04-07 06:55:38 +0000416static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000417tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000418{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000419
420 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000421 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000422
Mark Whitleyf57c9442000-12-07 19:56:48 +0000423 if (create_path(header->name, header->mode) != TRUE) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000424 perror_msg("%s: Cannot mkdir", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000425 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000426 }
427 /* make the final component, just in case it was
Mark Whitleyf57c9442000-12-07 19:56:48 +0000428 * omitted by create_path() (which will skip the
Erik Andersen1ad302a2000-03-24 00:54:46 +0000429 * directory if it doesn't have a terminating '/') */
Matt Kraai541ffe32001-01-13 21:46:25 +0000430 if (mkdir(header->name, header->mode) < 0 && errno != EEXIST) {
431 perror_msg("%s", header->name);
432 return FALSE;
Erik Andersen6acaa402000-03-26 14:03:20 +0000433 }
Matt Kraai541ffe32001-01-13 21:46:25 +0000434
435 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000436 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000437}
438
Erik Andersen6a34b532000-04-07 06:55:38 +0000439static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000440tarExtractHardLink(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000441{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000442 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000443 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000444
445 if (link(header->linkname, header->name) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000446 perror_msg("%s: Cannot create hard link to '%s'", header->name,
447 header->linkname);
Erik Andersen6a34b532000-04-07 06:55:38 +0000448 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000449 }
450
451 /* Now set permissions etc for the new directory */
452 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000453 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000454}
455
Erik Andersen6a34b532000-04-07 06:55:38 +0000456static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000457tarExtractSymLink(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000458{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000459 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000460 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000461
462#ifdef S_ISLNK
463 if (symlink(header->linkname, header->name) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000464 perror_msg("%s: Cannot create symlink to '%s'", header->name,
465 header->linkname);
Erik Andersen6a34b532000-04-07 06:55:38 +0000466 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000467 }
468 /* Try to change ownership of the symlink.
469 * If libs doesn't support that, don't bother.
470 * Changing the pointed-to-file is the Wrong Thing(tm).
471 */
472#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
473 lchown(header->name, header->uid, header->gid);
474#endif
475
476 /* Do not change permissions or date on symlink,
477 * since it changes the pointed to file instead. duh. */
478#else
Mark Whitleyf57c9442000-12-07 19:56:48 +0000479 error_msg("%s: Cannot create symlink to '%s': %s\n",
Erik Andersen6a34b532000-04-07 06:55:38 +0000480 header->name, header->linkname,
481 "symlinks not supported");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000482#endif
Erik Andersen6a34b532000-04-07 06:55:38 +0000483 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000484}
485
Erik Andersen6a34b532000-04-07 06:55:38 +0000486static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000487tarExtractSpecial(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000488{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000489 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000490 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000491
492 if (S_ISCHR(header->mode) || S_ISBLK(header->mode) || S_ISSOCK(header->mode)) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000493 if (mknod(header->name, header->mode, makedev(header->devmajor, header->devminor)) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000494 perror_msg("%s: Cannot mknod", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000495 return( FALSE);
496 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000497 } else if (S_ISFIFO(header->mode)) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000498 if (mkfifo(header->name, header->mode) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000499 perror_msg("%s: Cannot mkfifo", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000500 return( FALSE);
501 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000502 }
503
504 /* Now set permissions etc for the new directory */
505 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000506 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000507}
508
Erik Andersen1ad302a2000-03-24 00:54:46 +0000509/* Read an octal value in a field of the specified width, with optional
Erik Andersen298854f2000-03-23 01:09:18 +0000510 * spaces on both sides of the number and with an optional null character
Erik Andersen1ad302a2000-03-24 00:54:46 +0000511 * at the end. Returns -1 on an illegal format. */
Erik Andersen298854f2000-03-23 01:09:18 +0000512static long getOctal(const char *cp, int size)
Eric Andersencc8ed391999-10-05 16:24:54 +0000513{
Erik Andersen298854f2000-03-23 01:09:18 +0000514 long val = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000515
Erik Andersen298854f2000-03-23 01:09:18 +0000516 for(;(size > 0) && (*cp == ' '); cp++, size--);
Mark Whitleyf57c9442000-12-07 19:56:48 +0000517 if ((size == 0) || !is_octal(*cp))
Erik Andersen298854f2000-03-23 01:09:18 +0000518 return -1;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000519 for(; (size > 0) && is_octal(*cp); size--) {
Erik Andersen298854f2000-03-23 01:09:18 +0000520 val = val * 8 + *cp++ - '0';
Eric Andersencc8ed391999-10-05 16:24:54 +0000521 }
Erik Andersen298854f2000-03-23 01:09:18 +0000522 for (;(size > 0) && (*cp == ' '); cp++, size--);
523 if ((size > 0) && *cp)
524 return -1;
525 return val;
526}
Eric Andersencc8ed391999-10-05 16:24:54 +0000527
Erik Andersen1ad302a2000-03-24 00:54:46 +0000528
Erik Andersen298854f2000-03-23 01:09:18 +0000529/* Parse the tar header and fill in the nice struct with the details */
530static int
Erik Andersen3364d782000-03-28 00:58:14 +0000531readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
Erik Andersen298854f2000-03-23 01:09:18 +0000532{
Erik Andersene454fb62000-03-23 04:27:58 +0000533 int i;
Erik Andersen84e09e42000-04-08 20:58:35 +0000534 long chksum, sum=0;
Erik Andersene454fb62000-03-23 04:27:58 +0000535 unsigned char *s = (unsigned char *)rawHeader;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000536
Erik Andersen298854f2000-03-23 01:09:18 +0000537 header->name = rawHeader->name;
Erik Andersen84e09e42000-04-08 20:58:35 +0000538 /* Check for and relativify any absolute paths */
539 if ( *(header->name) == '/' ) {
540 static int alreadyWarned=FALSE;
541
542 while (*(header->name) == '/')
543 ++*(header->name);
544
545 if (alreadyWarned == FALSE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +0000546 error_msg("Removing leading '/' from member names\n");
Erik Andersen84e09e42000-04-08 20:58:35 +0000547 alreadyWarned = TRUE;
548 }
549 }
550
Erik Andersen298854f2000-03-23 01:09:18 +0000551 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode));
552 header->uid = getOctal(rawHeader->uid, sizeof(rawHeader->uid));
553 header->gid = getOctal(rawHeader->gid, sizeof(rawHeader->gid));
554 header->size = getOctal(rawHeader->size, sizeof(rawHeader->size));
555 header->mtime = getOctal(rawHeader->mtime, sizeof(rawHeader->mtime));
556 chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum));
557 header->type = rawHeader->typeflag;
558 header->linkname = rawHeader->linkname;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000559 header->devmajor = getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor));
560 header->devminor = getOctal(rawHeader->devminor, sizeof(rawHeader->devminor));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000561
Erik Andersen298854f2000-03-23 01:09:18 +0000562 /* Check the checksum */
Erik Andersen84e09e42000-04-08 20:58:35 +0000563 for (i = sizeof(*rawHeader); i-- != 0;) {
Erik Andersen298854f2000-03-23 01:09:18 +0000564 sum += *s++;
Erik Andersen84e09e42000-04-08 20:58:35 +0000565 }
566 /* Remove the effects of the checksum field (replace
567 * with blanks for the purposes of the checksum) */
568 s = rawHeader->chksum;
569 for (i = sizeof(rawHeader->chksum) ; i-- != 0;) {
570 sum -= *s++;
571 }
572 sum += ' ' * sizeof(rawHeader->chksum);
Erik Andersene454fb62000-03-23 04:27:58 +0000573 if (sum == chksum )
Erik Andersen298854f2000-03-23 01:09:18 +0000574 return ( TRUE);
575 return( FALSE);
576}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000577
Matt Kraaibe7499c2001-01-03 17:22:10 +0000578int exclude_file(char **excluded_files, const char *file)
579{
580 int i;
581
582 if (excluded_files == NULL)
583 return 0;
584
585 for (i = 0; excluded_files[i] != NULL; i++) {
586 if (excluded_files[i][0] == '/') {
587 if (fnmatch(excluded_files[i], file,
588 FNM_PATHNAME | FNM_LEADING_DIR) == 0)
589 return 1;
590 } else {
591 const char *p;
592
593 for (p = file; p[0] != '\0'; p++) {
594 if ((p == file || p[-1] == '/') && p[0] != '/' &&
595 fnmatch(excluded_files[i], p,
596 FNM_PATHNAME | FNM_LEADING_DIR) == 0)
597 return 1;
598 }
599 }
600 }
601
602 return 0;
603}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000604
Matt Kraai8f8dab92001-01-22 05:25:19 +0000605int extract_file(char **extract_files, const char *file)
606{
607 int i;
608
609 if (extract_files == NULL)
610 return 1;
611
612 for (i = 0; extract_files[i] != NULL; i++) {
613 if (fnmatch(extract_files[i], file, FNM_LEADING_DIR) == 0)
614 return 1;
615 }
616
617 return 0;
618}
619
Erik Andersen1ad302a2000-03-24 00:54:46 +0000620/*
621 * Read a tar file and extract or list the specified files within it.
622 * If the list is empty than all files are extracted or listed.
623 */
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000624extern int readTarFile(int tarFd, int extractFlag, int listFlag,
Matt Kraaib92223b2000-09-04 08:25:42 +0000625 int tostdoutFlag, int verboseFlag, char** extractList,
626 char** excludeList)
Erik Andersen1ad302a2000-03-24 00:54:46 +0000627{
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000628 int status;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000629 int errorFlag=FALSE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000630 int skipNextHeaderFlag=FALSE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000631 TarHeader rawHeader;
632 TarInfo header;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000633
Erik Andersene49d5ec2000-02-08 19:58:47 +0000634 /* Set the umask for this process so it doesn't
Erik Andersen1ad302a2000-03-24 00:54:46 +0000635 * screw up permission setting for us later. */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000636 umask(0);
Eric Andersencc8ed391999-10-05 16:24:54 +0000637
Erik Andersen1ad302a2000-03-24 00:54:46 +0000638 /* Read the tar file, and iterate over it one file at a time */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000639 while ( (status = full_read(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
Erik Andersene2729152000-02-18 21:34:17 +0000640
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000641 /* Try to read the header */
Erik Andersen3364d782000-03-28 00:58:14 +0000642 if ( readTarHeader(&rawHeader, &header) == FALSE ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000643 if ( *(header.name) == '\0' ) {
644 goto endgame;
645 } else {
646 errorFlag=TRUE;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000647 error_msg("Bad tar header, skipping\n");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000648 continue;
649 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000650 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000651 if ( *(header.name) == '\0' )
652 goto endgame;
Erik Andersen0817d132000-04-09 15:17:40 +0000653 header.tarFd = tarFd;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000654
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000655 /* Skip funky extra GNU headers that precede long files */
656 if ( (header.type == GNULONGNAME) || (header.type == GNULONGLINK) ) {
657 skipNextHeaderFlag=TRUE;
Matt Kraaiab8f9e22000-11-18 01:28:57 +0000658 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
659 errorFlag = TRUE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000660 continue;
661 }
662 if ( skipNextHeaderFlag == TRUE ) {
663 skipNextHeaderFlag=FALSE;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000664 error_msg(name_longer_than_foo, NAME_SIZE);
Matt Kraaiab8f9e22000-11-18 01:28:57 +0000665 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
666 errorFlag = TRUE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000667 continue;
668 }
669
Erik Andersen0817d132000-04-09 15:17:40 +0000670#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraaibe7499c2001-01-03 17:22:10 +0000671 if (exclude_file(excludeList, header.name)) {
Erik Andersen0817d132000-04-09 15:17:40 +0000672 /* There are not the droids you're looking for, move along */
Matt Kraaibe7499c2001-01-03 17:22:10 +0000673 /* If it is a regular file, pretend to extract it with
674 * the extractFlag set to FALSE, so the junk in the tarball
675 * is properly skipped over */
676 if ( header.type==REGTYPE || header.type==REGTYPE0 ) {
677 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
678 errorFlag = TRUE;
679 }
680 continue;
Erik Andersen0817d132000-04-09 15:17:40 +0000681 }
682#endif
Matt Kraaibe7499c2001-01-03 17:22:10 +0000683
Matt Kraai8f8dab92001-01-22 05:25:19 +0000684 if (!extract_file(extractList, header.name)) {
Matt Kraaib92223b2000-09-04 08:25:42 +0000685 /* There are not the droids you're looking for, move along */
Matt Kraai8f8dab92001-01-22 05:25:19 +0000686 /* If it is a regular file, pretend to extract it with
687 * the extractFlag set to FALSE, so the junk in the tarball
688 * is properly skipped over */
689 if ( header.type==REGTYPE || header.type==REGTYPE0 ) {
690 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
691 errorFlag = TRUE;
Matt Kraaib92223b2000-09-04 08:25:42 +0000692 }
Matt Kraai8f8dab92001-01-22 05:25:19 +0000693 continue;
Matt Kraaib92223b2000-09-04 08:25:42 +0000694 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000695
Matt Kraai82cfbad2000-09-15 21:18:43 +0000696 if (listFlag == TRUE) {
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000697 /* Special treatment if the list (-t) flag is on */
698 if (verboseFlag == TRUE) {
699 int len, len1;
700 char buf[35];
701 struct tm *tm = localtime (&(header.mtime));
702
Mark Whitleyf57c9442000-12-07 19:56:48 +0000703 len=printf("%s ", mode_string(header.mode));
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000704 my_getpwuid(buf, header.uid);
705 if (! *buf)
706 len+=printf("%d", header.uid);
707 else
708 len+=printf("%s", buf);
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000709 my_getgrgid(buf, header.gid);
710 if (! *buf)
711 len+=printf("/%-d ", header.gid);
712 else
713 len+=printf("/%-s ", buf);
714
715 if (header.type==CHRTYPE || header.type==BLKTYPE) {
716 len1=snprintf(buf, sizeof(buf), "%ld,%-ld ",
717 header.devmajor, header.devminor);
718 } else {
719 len1=snprintf(buf, sizeof(buf), "%lu ", (long)header.size);
720 }
721 /* Jump through some hoops to make the columns match up */
722 for(;(len+len1)<31;len++)
723 printf(" ");
724 printf(buf);
725
726 /* Use ISO 8610 time format */
727 if (tm) {
728 printf ("%04d-%02d-%02d %02d:%02d:%02d ",
729 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
730 tm->tm_hour, tm->tm_min, tm->tm_sec);
731 }
732 }
Eric Andersenfdd51032000-08-02 18:48:26 +0000733 printf("%s", header.name);
Matt Kraai82cfbad2000-09-15 21:18:43 +0000734 if (verboseFlag == TRUE) {
735 if (header.type==LNKTYPE) /* If this is a link, say so */
736 printf(" link to %s", header.linkname);
737 else if (header.type==SYMTYPE)
738 printf(" -> %s", header.linkname);
739 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000740 printf("\n");
741 }
742
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000743 /* List contents if we are supposed to do that */
744 if (verboseFlag == TRUE && extractFlag == TRUE) {
745 /* Now the normal listing */
746 FILE *vbFd = stdout;
747 if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr
748 vbFd = stderr;
749 fprintf(vbFd, "%s\n", header.name);
750 }
751
Matt Kraaif4462972000-09-01 02:50:48 +0000752 /* Remove files if we would overwrite them */
Matt Kraaida542f32000-09-01 02:53:01 +0000753 if (extractFlag == TRUE && tostdoutFlag == FALSE)
Matt Kraaif4462972000-09-01 02:50:48 +0000754 unlink(header.name);
Eric Andersencc8ed391999-10-05 16:24:54 +0000755
Erik Andersen1ad302a2000-03-24 00:54:46 +0000756 /* If we got here, we can be certain we have a legitimate
757 * header to work with. So work with it. */
758 switch ( header.type ) {
759 case REGTYPE:
760 case REGTYPE0:
761 /* If the name ends in a '/' then assume it is
762 * supposed to be a directory, and fall through */
763 if (header.name[strlen(header.name)-1] != '/') {
Erik Andersen6a34b532000-04-07 06:55:38 +0000764 if (tarExtractRegularFile(&header, extractFlag, tostdoutFlag)==FALSE)
765 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000766 break;
767 }
768 case DIRTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000769 if (tarExtractDirectory( &header, extractFlag, tostdoutFlag)==FALSE)
770 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000771 break;
772 case LNKTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000773 if (tarExtractHardLink( &header, extractFlag, tostdoutFlag)==FALSE)
774 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000775 break;
776 case SYMTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000777 if (tarExtractSymLink( &header, extractFlag, tostdoutFlag)==FALSE)
778 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000779 break;
780 case CHRTYPE:
781 case BLKTYPE:
782 case FIFOTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000783 if (tarExtractSpecial( &header, extractFlag, tostdoutFlag)==FALSE)
784 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000785 break;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000786#if 0
787 /* Handled earlier */
788 case GNULONGNAME:
789 case GNULONGLINK:
790 skipNextHeaderFlag=TRUE;
791 break;
792#endif
Erik Andersen1ad302a2000-03-24 00:54:46 +0000793 default:
Mark Whitleyf57c9442000-12-07 19:56:48 +0000794 error_msg("Unknown file type '%c' in tar file\n", header.type);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000795 close( tarFd);
796 return( FALSE);
797 }
798 }
799 close(tarFd);
800 if (status > 0) {
801 /* Bummer - we read a partial header */
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000802 perror_msg("Error reading tar file");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000803 return ( FALSE);
804 }
Erik Andersen6a34b532000-04-07 06:55:38 +0000805 else if (errorFlag==TRUE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +0000806 error_msg( "Error exit delayed from previous errors\n");
Erik Andersen6a34b532000-04-07 06:55:38 +0000807 return( FALSE);
808 } else
Erik Andersen1ad302a2000-03-24 00:54:46 +0000809 return( status);
810
811 /* Stuff to do when we are done */
812endgame:
813 close( tarFd);
814 if ( *(header.name) == '\0' ) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000815 if (errorFlag==TRUE)
Mark Whitleyf57c9442000-12-07 19:56:48 +0000816 error_msg( "Error exit delayed from previous errors\n");
Erik Andersen6a34b532000-04-07 06:55:38 +0000817 else
Erik Andersen1ad302a2000-03-24 00:54:46 +0000818 return( TRUE);
819 }
820 return( FALSE);
821}
822
Erik Andersen6acaa402000-03-26 14:03:20 +0000823
824#ifdef BB_FEATURE_TAR_CREATE
825
Eric Andersen3d957c82000-12-07 00:34:58 +0000826/*
827** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
828** the only functions that deal with the HardLinkInfo structure.
829** Even these functions use the xxxHardLinkInfo() functions.
830*/
831typedef struct HardLinkInfo HardLinkInfo;
832struct HardLinkInfo
833{
834 HardLinkInfo *next; /* Next entry in list */
835 dev_t dev; /* Device number */
836 ino_t ino; /* Inode number */
837 short linkCount; /* (Hard) Link Count */
838 char name[1]; /* Start of filename (must be last) */
839};
840
Erik Andersen68a9ea42000-04-04 18:39:50 +0000841/* Some info to be carried along when creating a new tarball */
842struct TarBallInfo
843{
844 char* fileName; /* File name of the tarball */
845 int tarFd; /* Open-for-write file descriptor
846 for the tarball */
847 struct stat statBuf; /* Stat info for the tarball, letting
848 us know the inode and device that the
849 tarball lives, so we can avoid trying
850 to include the tarball into itself */
851 int verboseFlag; /* Whether to print extra stuff or not */
Erik Andersenecd51242000-04-08 03:08:21 +0000852 char** excludeList; /* List of files to not include */
Eric Andersen3d957c82000-12-07 00:34:58 +0000853 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
854 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
Erik Andersen68a9ea42000-04-04 18:39:50 +0000855};
856typedef struct TarBallInfo TarBallInfo;
857
858
Eric Andersen3d957c82000-12-07 00:34:58 +0000859/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
860static void
861addHardLinkInfo (HardLinkInfo **hlInfoHeadPtr, dev_t dev, ino_t ino,
862 short linkCount, const char *name)
863{
864 /* Note: hlInfoHeadPtr can never be NULL! */
865 HardLinkInfo *hlInfo;
866
867 hlInfo = (HardLinkInfo *)xmalloc(sizeof(HardLinkInfo)+strlen(name)+1);
868 if (hlInfo) {
869 hlInfo->next = *hlInfoHeadPtr;
870 *hlInfoHeadPtr = hlInfo;
871 hlInfo->dev = dev;
872 hlInfo->ino = ino;
873 hlInfo->linkCount = linkCount;
874 strcpy(hlInfo->name, name);
875 }
876 return;
877}
878
879static void
880freeHardLinkInfo (HardLinkInfo **hlInfoHeadPtr)
881{
882 HardLinkInfo *hlInfo = NULL;
883 HardLinkInfo *hlInfoNext = NULL;
884
885 if (hlInfoHeadPtr) {
886 hlInfo = *hlInfoHeadPtr;
887 while (hlInfo) {
888 hlInfoNext = hlInfo->next;
889 free(hlInfo);
890 hlInfo = hlInfoNext;
891 }
892 *hlInfoHeadPtr = NULL;
893 }
894 return;
895}
896
897/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
898static HardLinkInfo *
899findHardLinkInfo (HardLinkInfo *hlInfo, dev_t dev, ino_t ino)
900{
901 while(hlInfo) {
902 if ((ino == hlInfo->ino) && (dev == hlInfo->dev))
903 break;
904 hlInfo = hlInfo->next;
905 }
906 return(hlInfo);
907}
908
Erik Andersen6acaa402000-03-26 14:03:20 +0000909/* Put an octal string into the specified buffer.
910 * The number is zero and space padded and possibly null padded.
911 * Returns TRUE if successful. */
912static int putOctal (char *cp, int len, long value)
913{
914 int tempLength;
Erik Andersen6acaa402000-03-26 14:03:20 +0000915 char tempBuffer[32];
Erik Andersen5661fe02000-04-05 01:00:52 +0000916 char *tempString = tempBuffer;
Erik Andersen6acaa402000-03-26 14:03:20 +0000917
918 /* Create a string of the specified length with an initial space,
919 * leading zeroes and the octal number, and a trailing null. */
Erik Andersen5661fe02000-04-05 01:00:52 +0000920 sprintf (tempString, "%0*lo", len - 1, value);
Erik Andersen6acaa402000-03-26 14:03:20 +0000921
922 /* If the string is too large, suppress the leading space. */
Erik Andersen5661fe02000-04-05 01:00:52 +0000923 tempLength = strlen (tempString) + 1;
Erik Andersen6acaa402000-03-26 14:03:20 +0000924 if (tempLength > len) {
925 tempLength--;
926 tempString++;
927 }
928
929 /* If the string is still too large, suppress the trailing null. */
930 if (tempLength > len)
931 tempLength--;
932
933 /* If the string is still too large, fail. */
934 if (tempLength > len)
935 return FALSE;
936
937 /* Copy the string to the field. */
938 memcpy (cp, tempString, len);
939
940 return TRUE;
941}
942
Erik Andersen68a9ea42000-04-04 18:39:50 +0000943/* Write out a tar header for the specified file/directory/whatever */
Erik Andersen3364d782000-03-28 00:58:14 +0000944static int
Matt Kraaie80a2632000-12-19 20:45:49 +0000945writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
946 const char *real_name, struct stat *statbuf)
Erik Andersen6acaa402000-03-26 14:03:20 +0000947{
Erik Andersen5661fe02000-04-05 01:00:52 +0000948 long chksum=0;
949 struct TarHeader header;
950 const unsigned char *cp = (const unsigned char *) &header;
951 ssize_t size = sizeof(struct TarHeader);
Eric Andersenfdd51032000-08-02 18:48:26 +0000952
Erik Andersen5661fe02000-04-05 01:00:52 +0000953 memset( &header, 0, size);
Erik Andersen3364d782000-03-28 00:58:14 +0000954
Matt Kraaie80a2632000-12-19 20:45:49 +0000955 strncpy(header.name, header_name, sizeof(header.name));
Erik Andersenecd51242000-04-08 03:08:21 +0000956
Erik Andersen5661fe02000-04-05 01:00:52 +0000957 putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
958 putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
959 putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
960 putOctal(header.size, sizeof(header.size), 0); /* Regular file size is handled later */
961 putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
962 strncpy(header.magic, TAR_MAGIC TAR_VERSION,
963 TAR_MAGIC_LEN + TAR_VERSION_LEN );
Erik Andersen68a9ea42000-04-04 18:39:50 +0000964
Erik Andersen84e09e42000-04-08 20:58:35 +0000965 /* Enter the user and group names (default to root if it fails) */
Erik Andersen5661fe02000-04-05 01:00:52 +0000966 my_getpwuid(header.uname, statbuf->st_uid);
Erik Andersen5661fe02000-04-05 01:00:52 +0000967 if (! *header.uname)
Erik Andersen84e09e42000-04-08 20:58:35 +0000968 strcpy(header.uname, "root");
Erik Andersen5661fe02000-04-05 01:00:52 +0000969 my_getgrgid(header.gname, statbuf->st_gid);
970 if (! *header.uname)
Erik Andersen84e09e42000-04-08 20:58:35 +0000971 strcpy(header.uname, "root");
Erik Andersen5661fe02000-04-05 01:00:52 +0000972
Eric Andersen3d957c82000-12-07 00:34:58 +0000973 if (tbInfo->hlInfo) {
974 /* This is a hard link */
975 header.typeflag = LNKTYPE;
976 strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
977 } else if (S_ISLNK(statbuf->st_mode)) {
Eric Andersen3adffb72000-06-26 10:54:06 +0000978 int link_size=0;
Erik Andersen5661fe02000-04-05 01:00:52 +0000979 char buffer[BUFSIZ];
980 header.typeflag = SYMTYPE;
Matt Kraaie80a2632000-12-19 20:45:49 +0000981 link_size = readlink(real_name, buffer, sizeof(buffer) - 1);
Eric Andersen3adffb72000-06-26 10:54:06 +0000982 if ( link_size < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000983 perror_msg("Error reading symlink '%s'", header.name);
Erik Andersen5661fe02000-04-05 01:00:52 +0000984 return ( FALSE);
985 }
Eric Andersen3adffb72000-06-26 10:54:06 +0000986 buffer[link_size] = '\0';
Erik Andersen95c1c1e2000-04-14 21:45:29 +0000987 strncpy(header.linkname, buffer, sizeof(header.linkname));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000988 } else if (S_ISDIR(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000989 header.typeflag = DIRTYPE;
990 strncat(header.name, "/", sizeof(header.name));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000991 } else if (S_ISCHR(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000992 header.typeflag = CHRTYPE;
993 putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
994 putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000995 } else if (S_ISBLK(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000996 header.typeflag = BLKTYPE;
997 putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
998 putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000999 } else if (S_ISFIFO(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001000 header.typeflag = FIFOTYPE;
1001 } else if (S_ISREG(statbuf->st_mode)) {
1002 header.typeflag = REGTYPE;
1003 putOctal(header.size, sizeof(header.size), statbuf->st_size);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001004 } else {
Matt Kraaie80a2632000-12-19 20:45:49 +00001005 error_msg("%s: Unknown file type\n", real_name);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001006 return ( FALSE);
1007 }
Erik Andersen68a9ea42000-04-04 18:39:50 +00001008
Erik Andersen5661fe02000-04-05 01:00:52 +00001009 /* Calculate and store the checksum (i.e. the sum of all of the bytes of
1010 * the header). The checksum field must be filled with blanks for the
1011 * calculation. The checksum field is formatted differently from the
1012 * other fields: it has [6] digits, a null, then a space -- rather than
1013 * digits, followed by a null like the other fields... */
1014 memset(header.chksum, ' ', sizeof(header.chksum));
1015 cp = (const unsigned char *) &header;
1016 while (size-- > 0)
1017 chksum += *cp++;
1018 putOctal(header.chksum, 7, chksum);
1019
1020 /* Now write the header out to disk */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001021 if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
Matt Kraaie80a2632000-12-19 20:45:49 +00001022 error_msg(io_error, real_name, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001023 return ( FALSE);
1024 }
1025 /* Pad the header up to the tar block size */
1026 for (; size<TAR_BLOCK_SIZE; size++) {
1027 write(tbInfo->tarFd, "\0", 1);
1028 }
1029 /* Now do the verbose thing (or not) */
Eric Andersenfdd51032000-08-02 18:48:26 +00001030 if (tbInfo->verboseFlag==TRUE) {
1031 FILE *vbFd = stdout;
1032 if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr
1033 vbFd = stderr;
1034 fprintf(vbFd, "%s\n", header.name);
1035 }
Erik Andersen3364d782000-03-28 00:58:14 +00001036
1037 return ( TRUE);
1038}
1039
1040
Erik Andersen68a9ea42000-04-04 18:39:50 +00001041static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
Erik Andersen3364d782000-03-28 00:58:14 +00001042{
Erik Andersen68a9ea42000-04-04 18:39:50 +00001043 struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
Matt Kraaie80a2632000-12-19 20:45:49 +00001044 const char *header_name;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001045
Eric Andersen3d957c82000-12-07 00:34:58 +00001046 /*
1047 ** Check to see if we are dealing with a hard link.
1048 ** If so -
1049 ** Treat the first occurance of a given dev/inode as a file while
1050 ** treating any additional occurances as hard links. This is done
1051 ** by adding the file information to the HardLinkInfo linked list.
1052 */
1053 tbInfo->hlInfo = NULL;
1054 if (statbuf->st_nlink > 1) {
1055 tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf->st_dev,
1056 statbuf->st_ino);
1057 if (tbInfo->hlInfo == NULL)
1058 addHardLinkInfo (&tbInfo->hlInfoHead, statbuf->st_dev,
1059 statbuf->st_ino, statbuf->st_nlink, fileName);
1060 }
1061
Erik Andersen68a9ea42000-04-04 18:39:50 +00001062 /* It is against the rules to archive a socket */
1063 if (S_ISSOCK(statbuf->st_mode)) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001064 error_msg("%s: socket ignored\n", fileName);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001065 return( TRUE);
1066 }
1067
1068 /* It is a bad idea to store the archive we are in the process of creating,
1069 * so check the device and inode to be sure that this particular file isn't
1070 * the new tarball */
1071 if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
1072 tbInfo->statBuf.st_ino == statbuf->st_ino) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001073 error_msg("%s: file is the archive; skipping\n", fileName);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001074 return( TRUE);
1075 }
1076
Matt Kraaie80a2632000-12-19 20:45:49 +00001077 header_name = fileName;
1078 while (header_name[0] == '/') {
Matt Kraaia1f97752000-12-19 06:24:08 +00001079 static int alreadyWarned=FALSE;
1080 if (alreadyWarned==FALSE) {
1081 error_msg("Removing leading '/' from member names\n");
1082 alreadyWarned=TRUE;
1083 }
Matt Kraaie80a2632000-12-19 20:45:49 +00001084 header_name++;
Matt Kraaia1f97752000-12-19 06:24:08 +00001085 }
1086
Eric Andersen1b1cfde2000-09-24 00:54:37 +00001087 if (strlen(fileName) >= NAME_SIZE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001088 error_msg(name_longer_than_foo, NAME_SIZE);
Eric Andersen1b1cfde2000-09-24 00:54:37 +00001089 return ( TRUE);
1090 }
1091
Matt Kraaie80a2632000-12-19 20:45:49 +00001092 if (header_name[0] == '\0')
Matt Kraaia1f97752000-12-19 06:24:08 +00001093 return TRUE;
1094
1095#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraaibe7499c2001-01-03 17:22:10 +00001096 if (exclude_file(tbInfo->excludeList, header_name)) {
1097 return SKIP;
Matt Kraaia1f97752000-12-19 06:24:08 +00001098 }
1099#endif
1100
Matt Kraaie80a2632000-12-19 20:45:49 +00001101 if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001102 return( FALSE);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001103 }
Erik Andersen5661fe02000-04-05 01:00:52 +00001104
1105 /* Now, if the file is a regular file, copy it out to the tarball */
Eric Andersen3d957c82000-12-07 00:34:58 +00001106 if ((tbInfo->hlInfo == NULL)
1107 && (S_ISREG(statbuf->st_mode))) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001108 int inputFileFd;
1109 char buffer[BUFSIZ];
1110 ssize_t size=0, readSize=0;
1111
1112 /* open the file we want to archive, and make sure all is well */
1113 if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001114 error_msg("%s: Cannot open: %s\n", fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001115 return( FALSE);
1116 }
1117
1118 /* write the file to the archive */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001119 while ( (size = full_read(inputFileFd, buffer, sizeof(buffer))) > 0 ) {
1120 if (full_write(tbInfo->tarFd, buffer, size) != size ) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001121 /* Output file seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001122 error_msg(io_error, fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001123 return( FALSE);
1124 }
1125 readSize+=size;
1126 }
1127 if (size == -1) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001128 error_msg(io_error, fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001129 return( FALSE);
1130 }
1131 /* Pad the file up to the tar block size */
1132 for (; (readSize%TAR_BLOCK_SIZE) != 0; readSize++) {
1133 write(tbInfo->tarFd, "\0", 1);
1134 }
1135 close( inputFileFd);
1136 }
Erik Andersen68a9ea42000-04-04 18:39:50 +00001137
1138 return( TRUE);
Erik Andersen6acaa402000-03-26 14:03:20 +00001139}
1140
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001141static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
1142 char** excludeList)
Erik Andersen6acaa402000-03-26 14:03:20 +00001143{
Erik Andersen3364d782000-03-28 00:58:14 +00001144 int tarFd=-1;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001145 int errorFlag=FALSE;
Erik Andersen5661fe02000-04-05 01:00:52 +00001146 ssize_t size;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001147 struct TarBallInfo tbInfo;
1148 tbInfo.verboseFlag = verboseFlag;
Eric Andersen3d957c82000-12-07 00:34:58 +00001149 tbInfo.hlInfoHead = NULL;
Erik Andersen3364d782000-03-28 00:58:14 +00001150
1151 /* Make sure there is at least one file to tar up. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001152 if (*argv == NULL)
Mark Whitleyf57c9442000-12-07 19:56:48 +00001153 error_msg_and_die("Cowardly refusing to create an empty archive\n");
Erik Andersen6acaa402000-03-26 14:03:20 +00001154
1155 /* Open the tar file for writing. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001156 if (!strcmp(tarName, "-"))
Erik Andersen68a9ea42000-04-04 18:39:50 +00001157 tbInfo.tarFd = fileno(stdout);
Erik Andersen6acaa402000-03-26 14:03:20 +00001158 else
Erik Andersen68a9ea42000-04-04 18:39:50 +00001159 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1160 if (tbInfo.tarFd < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +00001161 perror_msg( "Error opening '%s'", tarName);
Eric Andersen3d957c82000-12-07 00:34:58 +00001162 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen6acaa402000-03-26 14:03:20 +00001163 return ( FALSE);
1164 }
Erik Andersenecd51242000-04-08 03:08:21 +00001165 tbInfo.excludeList=excludeList;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001166 /* Store the stat info for the tarball's file, so
1167 * can avoid including the tarball into itself.... */
1168 if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
Mark Whitleyf57c9442000-12-07 19:56:48 +00001169 error_msg_and_die(io_error, tarName, strerror(errno));
Erik Andersen6acaa402000-03-26 14:03:20 +00001170
1171 /* Set the umask for this process so it doesn't
1172 * screw up permission setting for us later. */
1173 umask(0);
1174
1175 /* Read the directory/files and iterate over them one at a time */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001176 while (*argv != NULL) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001177 if (recursive_action(*argv++, TRUE, FALSE, FALSE,
Erik Andersen68a9ea42000-04-04 18:39:50 +00001178 writeFileToTarball, writeFileToTarball,
1179 (void*) &tbInfo) == FALSE) {
1180 errorFlag = TRUE;
Erik Andersen3364d782000-03-28 00:58:14 +00001181 }
Erik Andersen6acaa402000-03-26 14:03:20 +00001182 }
Erik Andersen5661fe02000-04-05 01:00:52 +00001183 /* Write two empty blocks to the end of the archive */
1184 for (size=0; size<(2*TAR_BLOCK_SIZE); size++) {
1185 write(tbInfo.tarFd, "\0", 1);
1186 }
Erik Andersen0817d132000-04-09 15:17:40 +00001187
1188 /* To be pedantically correct, we would check if the tarball
Eric Andersen3c5ee9a2000-11-14 22:15:48 +00001189 * is smaller than 20 tar blocks, and pad it if it was smaller,
Erik Andersen0817d132000-04-09 15:17:40 +00001190 * but that isn't necessary for GNU tar interoperability, and
1191 * so is considered a waste of space */
1192
Erik Andersen68a9ea42000-04-04 18:39:50 +00001193 /* Hang up the tools, close up shop, head home */
Erik Andersen6acaa402000-03-26 14:03:20 +00001194 close(tarFd);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001195 if (errorFlag == TRUE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001196 error_msg("Error exit delayed from previous errors\n");
Eric Andersen3d957c82000-12-07 00:34:58 +00001197 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001198 return(FALSE);
1199 }
Eric Andersen3d957c82000-12-07 00:34:58 +00001200 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen6acaa402000-03-26 14:03:20 +00001201 return( TRUE);
1202}
1203
1204
1205#endif
1206