blob: 51a857d719680a0d8367e0738a898c1c70a93373 [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 *
Erik Andersen68a9ea42000-04-04 18:39:50 +00009 * Copyright (C) 2000 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 Andersencc8ed391999-10-05 16:24:54 +000055
Glenn L McGrath46f44d22000-12-10 01:57:30 +000056#ifdef BB_FEATURE_TAR_GZIP
57extern int unzip(int in, int out);
58extern int gunzip_init();
59#endif
60
Erik Andersen298854f2000-03-23 01:09:18 +000061/* Tar file constants */
Erik Andersen1ad302a2000-03-24 00:54:46 +000062#ifndef MAJOR
63#define MAJOR(dev) (((dev)>>8)&0xff)
64#define MINOR(dev) ((dev)&0xff)
65#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000066
Mark Whitley59ab0252001-01-23 22:30:04 +000067enum { NAME_SIZE = 100 }; /* because gcc won't let me use 'static const int' */
Eric Andersencc8ed391999-10-05 16:24:54 +000068
Erik Andersen298854f2000-03-23 01:09:18 +000069/* POSIX tar Header Block, from POSIX 1003.1-1990 */
70struct TarHeader
71{
72 /* byte offset */
Eric Andersen1b1cfde2000-09-24 00:54:37 +000073 char name[NAME_SIZE]; /* 0-99 */
Erik Andersen0817d132000-04-09 15:17:40 +000074 char mode[8]; /* 100-107 */
75 char uid[8]; /* 108-115 */
76 char gid[8]; /* 116-123 */
77 char size[12]; /* 124-135 */
78 char mtime[12]; /* 136-147 */
79 char chksum[8]; /* 148-155 */
80 char typeflag; /* 156-156 */
Eric Andersen1b1cfde2000-09-24 00:54:37 +000081 char linkname[NAME_SIZE]; /* 157-256 */
Erik Andersen0817d132000-04-09 15:17:40 +000082 char magic[6]; /* 257-262 */
83 char version[2]; /* 263-264 */
84 char uname[32]; /* 265-296 */
85 char gname[32]; /* 297-328 */
86 char devmajor[8]; /* 329-336 */
87 char devminor[8]; /* 337-344 */
88 char prefix[155]; /* 345-499 */
89 char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
Erik Andersen298854f2000-03-23 01:09:18 +000090};
91typedef struct TarHeader TarHeader;
Eric Andersencc8ed391999-10-05 16:24:54 +000092
Eric Andersencc8ed391999-10-05 16:24:54 +000093
Erik Andersen298854f2000-03-23 01:09:18 +000094/* A few useful constants */
95#define TAR_MAGIC "ustar" /* ustar and a null */
Erik Andersen0817d132000-04-09 15:17:40 +000096#define TAR_VERSION " " /* Be compatable with GNU tar format */
Mark Whitley59ab0252001-01-23 22:30:04 +000097static const int TAR_MAGIC_LEN = 6;
98static const int TAR_VERSION_LEN = 2;
99static const int TAR_BLOCK_SIZE = 512;
Erik Andersen298854f2000-03-23 01:09:18 +0000100
101/* A nice enum with all the possible tar file content types */
102enum TarFileType
103{
104 REGTYPE = '0', /* regular file */
105 REGTYPE0 = '\0', /* regular file (ancient bug compat)*/
106 LNKTYPE = '1', /* hard link */
107 SYMTYPE = '2', /* symbolic link */
108 CHRTYPE = '3', /* character special */
109 BLKTYPE = '4', /* block special */
110 DIRTYPE = '5', /* directory */
111 FIFOTYPE = '6', /* FIFO special */
112 CONTTYPE = '7', /* reserved */
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000113 GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
114 GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
Erik Andersen298854f2000-03-23 01:09:18 +0000115};
116typedef enum TarFileType TarFileType;
117
118/* This struct ignores magic, non-numeric user name,
119 * non-numeric group name, and the checksum, since
120 * these are all ignored by BusyBox tar. */
121struct TarInfo
122{
123 int tarFd; /* An open file descriptor for reading from the tarball */
124 char * name; /* File name */
125 mode_t mode; /* Unix mode, including device bits. */
126 uid_t uid; /* Numeric UID */
127 gid_t gid; /* Numeric GID */
128 size_t size; /* Size of file */
129 time_t mtime; /* Last-modified time */
130 enum TarFileType type; /* Regular, directory, link, etc */
131 char * linkname; /* Name for symbolic and hard links */
Erik Andersen1ad302a2000-03-24 00:54:46 +0000132 long devmajor; /* Major number for special device */
133 long devminor; /* Minor number for special device */
Erik Andersen298854f2000-03-23 01:09:18 +0000134};
135typedef struct TarInfo TarInfo;
136
Erik Andersene454fb62000-03-23 04:27:58 +0000137/* Local procedures to restore files from a tar file. */
Glenn L McGrath7541e3a2001-01-02 23:41:50 +0000138extern int readTarFile(int tarFd, int extractFlag, int listFlag,
Matt Kraaib92223b2000-09-04 08:25:42 +0000139 int tostdoutFlag, int verboseFlag, char** extractList,
140 char** excludeList);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000141
Erik Andersen05100cd2000-01-16 01:30:52 +0000142#ifdef BB_FEATURE_TAR_CREATE
Erik Andersen6acaa402000-03-26 14:03:20 +0000143/* Local procedures to save files into a tar file. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +0000144static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
145 char** excludeList);
Erik Andersen05100cd2000-01-16 01:30:52 +0000146#endif
147
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000148#ifdef BB_FEATURE_TAR_GZIP
149/* Signal handler for when child gzip process dies... */
150void child_died()
151{
152 fflush(stdout);
153 fflush(stderr);
154 exit(EXIT_FAILURE);
155}
156
Glenn L McGrath7541e3a2001-01-02 23:41:50 +0000157extern int tar_unzip_init(int tarFd)
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000158{
159 int child_pid;
160 static int unzip_pipe[2];
161 /* Cope if child dies... Otherwise we block forever in read()... */
162 signal(SIGCHLD, child_died);
163
164 if (pipe(unzip_pipe)!=0)
165 error_msg_and_die("pipe error\n");
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000166
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000167 if ( (child_pid = fork()) == -1)
168 error_msg_and_die("fork failure\n");
169
170 if (child_pid==0) {
171 /* child process */
Glenn L McGrath1d269432001-01-20 00:12:21 +0000172 close(unzip_pipe[0]);
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000173 gunzip_init();
174 unzip(tarFd, unzip_pipe[1]);
175 exit(EXIT_SUCCESS);
176 }
Glenn L McGrath1d269432001-01-20 00:12:21 +0000177 else {
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000178 /* return fd of uncompressed data to parent process */
Glenn L McGrath1d269432001-01-20 00:12:21 +0000179 close(unzip_pipe[1]);
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000180 return(unzip_pipe[0]);
Glenn L McGrath1d269432001-01-20 00:12:21 +0000181 }
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000182}
183#endif
184
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000185#if defined BB_FEATURE_TAR_EXCLUDE
186struct option longopts[] = {
187 { "exclude", 1, NULL, 'e' },
188 { NULL, 0, NULL, 0 }
189};
190#endif
191
Erik Andersene49d5ec2000-02-08 19:58:47 +0000192extern int tar_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +0000193{
Erik Andersenecd51242000-04-08 03:08:21 +0000194 char** excludeList=NULL;
Matt Kraaic119ab92000-11-30 04:44:54 +0000195 char** extractList=NULL;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000196 const char *tarName="-";
Erik Andersen0817d132000-04-09 15:17:40 +0000197#if defined BB_FEATURE_TAR_EXCLUDE
Erik Andersenecd51242000-04-08 03:08:21 +0000198 int excludeListSize=0;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000199 FILE *fileList;
200 char file[256];
Erik Andersen0817d132000-04-09 15:17:40 +0000201#endif
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000202#if defined BB_FEATURE_TAR_GZIP
203 int unzipFlag = FALSE;
204#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000205 int listFlag = FALSE;
206 int extractFlag = FALSE;
207 int createFlag = FALSE;
208 int verboseFlag = FALSE;
209 int tostdoutFlag = FALSE;
Eric Andersen02f3b2e2000-12-01 19:04:52 +0000210 int status = FALSE;
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000211 int opt;
Eric Andersencc8ed391999-10-05 16:24:54 +0000212
Erik Andersenecd51242000-04-08 03:08:21 +0000213 if (argc <= 1)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000214 usage(tar_usage);
Eric Andersencc8ed391999-10-05 16:24:54 +0000215
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000216 if (argv[1][0] != '-') {
217 char *tmp = xmalloc(strlen(argv[1]) + 2);
218 tmp[0] = '-';
219 strcpy(tmp + 1, argv[1]);
220 argv[1] = tmp;
221 }
222
223 while (
224#ifndef BB_FEATURE_TAR_EXCLUDE
225 (opt = getopt(argc, argv, "cxtzvOf:"))
226#else
227 (opt = getopt_long(argc, argv, "cxtzvOf:X:", longopts, NULL))
228#endif
229 > 0) {
230 switch (opt) {
231 case 'c':
232 if (extractFlag == TRUE || listFlag == TRUE)
233 goto flagError;
234 createFlag = TRUE;
235 break;
236 case 'x':
237 if (listFlag == TRUE || createFlag == TRUE)
238 goto flagError;
239 extractFlag = TRUE;
240 break;
241 case 't':
242 if (extractFlag == TRUE || createFlag == TRUE)
243 goto flagError;
244 listFlag = TRUE;
245 break;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000246#ifdef BB_FEATURE_TAR_GZIP
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000247 case 'z':
248 unzipFlag = TRUE;
249 break;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000250#endif
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000251 case 'v':
252 verboseFlag = TRUE;
253 break;
254 case 'O':
255 tostdoutFlag = TRUE;
256 break;
257 case 'f':
258 if (*tarName != '-')
259 error_msg_and_die( "Only one 'f' option allowed\n");
260 tarName = optarg;
261 break;
Erik Andersen0817d132000-04-09 15:17:40 +0000262#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000263 case 'e':
264 excludeList=xrealloc( excludeList,
265 sizeof(char *) * (excludeListSize+2));
266 excludeList[excludeListSize] = optarg;
267 /* Tack a NULL onto the end of the list */
268 excludeList[++excludeListSize] = NULL;
269 case 'X':
270 fileList = xfopen(optarg, "r");
271 while (fgets(file, sizeof(file), fileList) != NULL) {
272 excludeList = xrealloc(excludeList,
273 sizeof(char *) * (excludeListSize+2));
274 if (file[strlen(file)-1] == '\n')
275 file[strlen(file)-1] = '\0';
276 excludeList[excludeListSize] = xstrdup(file);
277 /* Tack a NULL onto the end of the list */
278 excludeList[++excludeListSize] = NULL;
279 }
280 fclose(fileList);
281 break;
Erik Andersen0817d132000-04-09 15:17:40 +0000282#endif
Erik Andersenecd51242000-04-08 03:08:21 +0000283 default:
Matt Kraai43c8c382000-09-04 16:51:55 +0000284 usage(tar_usage);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000285 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000286 }
287
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000288 /*
Erik Andersene49d5ec2000-02-08 19:58:47 +0000289 * Do the correct type of action supplying the rest of the
290 * command line arguments as the list of files to process.
291 */
292 if (createFlag == TRUE) {
Erik Andersende552872000-01-23 01:34:05 +0000293#ifndef BB_FEATURE_TAR_CREATE
Mark Whitleyf57c9442000-12-07 19:56:48 +0000294 error_msg_and_die( "This version of tar was not compiled with tar creation support.\n");
Erik Andersende552872000-01-23 01:34:05 +0000295#else
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000296#ifdef BB_FEATURE_TAR_GZIP
297 if (unzipFlag==TRUE)
298 error_msg_and_die("Creation of compressed not internally support by tar, pipe to busybox gunzip\n");
299#endif
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000300 status = writeTarFile(tarName, verboseFlag, argv + optind, excludeList);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000301#endif
Erik Andersen8ea7d8c2000-05-20 00:40:08 +0000302 }
303 if (listFlag == TRUE || extractFlag == TRUE) {
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000304 int tarFd;
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000305 if (argv[optind])
306 extractList = argv + optind;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000307 /* Open the tar file for reading. */
308 if (!strcmp(tarName, "-"))
309 tarFd = fileno(stdin);
310 else
311 tarFd = open(tarName, O_RDONLY);
312 if (tarFd < 0)
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000313 perror_msg_and_die("Error opening '%s'", tarName);
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000314
315#ifdef BB_FEATURE_TAR_GZIP
316 /* unzip tarFd in a seperate process */
317 if (unzipFlag == TRUE)
318 tarFd = tar_unzip_init(tarFd);
319#endif
320 status = readTarFile(tarFd, extractFlag, listFlag, tostdoutFlag,
Matt Kraai3e856ce2000-12-01 02:55:13 +0000321 verboseFlag, extractList, excludeList);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000322 }
Erik Andersende552872000-01-23 01:34:05 +0000323
Matt Kraai3e856ce2000-12-01 02:55:13 +0000324 if (status == TRUE)
325 return EXIT_SUCCESS;
326 else
327 return EXIT_FAILURE;
328
Erik Andersene49d5ec2000-02-08 19:58:47 +0000329 flagError:
Mark Whitleyf57c9442000-12-07 19:56:48 +0000330 error_msg_and_die( "Exactly one of 'c', 'x' or 't' must be specified\n");
Erik Andersen298854f2000-03-23 01:09:18 +0000331}
332
333static void
Erik Andersen6a34b532000-04-07 06:55:38 +0000334fixUpPermissions(TarInfo *header)
335{
336 struct utimbuf t;
337 /* Now set permissions etc for the new file */
338 chown(header->name, header->uid, header->gid);
339 chmod(header->name, header->mode);
340 /* Reset the time */
341 t.actime = time(0);
342 t.modtime = header->mtime;
343 utime(header->name, &t);
344}
345
346static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000347tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersen298854f2000-03-23 01:09:18 +0000348{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000349 size_t writeSize;
350 size_t readSize;
351 size_t actualWriteSz;
352 char buffer[BUFSIZ];
353 size_t size = header->size;
354 int outFd=fileno(stdout);
355
356 /* Open the file to be written, if a file is supposed to be written */
357 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000358 /* Create the path to the file, just in case it isn't there...
359 * This should not screw up path permissions or anything. */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000360 create_path(header->name, 0777);
Eric Andersen0c6a9702000-06-09 20:51:50 +0000361 if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
362 header->mode & ~S_IFMT)) < 0) {
Mark Whitleyf57c9442000-12-07 19:56:48 +0000363 error_msg(io_error, header->name, strerror(errno));
Eric Andersen0c6a9702000-06-09 20:51:50 +0000364 return( FALSE);
365 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000366 }
367
368 /* Write out the file, if we are supposed to be doing that */
369 while ( size > 0 ) {
370 actualWriteSz=0;
371 if ( size > sizeof(buffer) )
372 writeSize = readSize = sizeof(buffer);
373 else {
374 int mod = size % 512;
375 if ( mod != 0 )
376 readSize = size + (512 - mod);
377 else
378 readSize = size;
379 writeSize = size;
380 }
Mark Whitleyf57c9442000-12-07 19:56:48 +0000381 if ( (readSize = full_read(header->tarFd, buffer, readSize)) <= 0 ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000382 /* Tarball seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000383 error_msg("Unexpected EOF in archive\n");
Erik Andersen6a34b532000-04-07 06:55:38 +0000384 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000385 }
386 if ( readSize < writeSize )
387 writeSize = readSize;
388
389 /* Write out the file, if we are supposed to be doing that */
390 if (extractFlag==TRUE) {
391
Mark Whitleyf57c9442000-12-07 19:56:48 +0000392 if ((actualWriteSz=full_write(outFd, buffer, writeSize)) != writeSize ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000393 /* Output file seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000394 error_msg(io_error, header->name, strerror(errno));
Erik Andersen6a34b532000-04-07 06:55:38 +0000395 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000396 }
Erik Andersen0817d132000-04-09 15:17:40 +0000397 } else {
398 actualWriteSz=writeSize;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000399 }
400
401 size -= actualWriteSz;
402 }
403
404 /* Now we are done writing the file out, so try
405 * and fix up the permissions and whatnot */
406 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000407 close(outFd);
Erik Andersen6a34b532000-04-07 06:55:38 +0000408 fixUpPermissions(header);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000409 }
Erik Andersen6a34b532000-04-07 06:55:38 +0000410 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000411}
412
Erik Andersen6a34b532000-04-07 06:55:38 +0000413static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000414tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000415{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000416
417 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000418 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000419
Mark Whitleyf57c9442000-12-07 19:56:48 +0000420 if (create_path(header->name, header->mode) != TRUE) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000421 perror_msg("%s: Cannot mkdir", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000422 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000423 }
424 /* make the final component, just in case it was
Mark Whitleyf57c9442000-12-07 19:56:48 +0000425 * omitted by create_path() (which will skip the
Erik Andersen1ad302a2000-03-24 00:54:46 +0000426 * directory if it doesn't have a terminating '/') */
Matt Kraai541ffe32001-01-13 21:46:25 +0000427 if (mkdir(header->name, header->mode) < 0 && errno != EEXIST) {
428 perror_msg("%s", header->name);
429 return FALSE;
Erik Andersen6acaa402000-03-26 14:03:20 +0000430 }
Matt Kraai541ffe32001-01-13 21:46:25 +0000431
432 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000433 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000434}
435
Erik Andersen6a34b532000-04-07 06:55:38 +0000436static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000437tarExtractHardLink(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000438{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000439 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000440 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000441
442 if (link(header->linkname, header->name) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000443 perror_msg("%s: Cannot create hard link to '%s'", header->name,
444 header->linkname);
Erik Andersen6a34b532000-04-07 06:55:38 +0000445 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000446 }
447
448 /* Now set permissions etc for the new directory */
449 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000450 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000451}
452
Erik Andersen6a34b532000-04-07 06:55:38 +0000453static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000454tarExtractSymLink(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000455{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000456 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000457 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000458
459#ifdef S_ISLNK
460 if (symlink(header->linkname, header->name) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000461 perror_msg("%s: Cannot create symlink to '%s'", header->name,
462 header->linkname);
Erik Andersen6a34b532000-04-07 06:55:38 +0000463 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000464 }
465 /* Try to change ownership of the symlink.
466 * If libs doesn't support that, don't bother.
467 * Changing the pointed-to-file is the Wrong Thing(tm).
468 */
469#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
470 lchown(header->name, header->uid, header->gid);
471#endif
472
473 /* Do not change permissions or date on symlink,
474 * since it changes the pointed to file instead. duh. */
475#else
Mark Whitleyf57c9442000-12-07 19:56:48 +0000476 error_msg("%s: Cannot create symlink to '%s': %s\n",
Erik Andersen6a34b532000-04-07 06:55:38 +0000477 header->name, header->linkname,
478 "symlinks not supported");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000479#endif
Erik Andersen6a34b532000-04-07 06:55:38 +0000480 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000481}
482
Erik Andersen6a34b532000-04-07 06:55:38 +0000483static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000484tarExtractSpecial(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000485{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000486 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000487 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000488
489 if (S_ISCHR(header->mode) || S_ISBLK(header->mode) || S_ISSOCK(header->mode)) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000490 if (mknod(header->name, header->mode, makedev(header->devmajor, header->devminor)) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000491 perror_msg("%s: Cannot mknod", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000492 return( FALSE);
493 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000494 } else if (S_ISFIFO(header->mode)) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000495 if (mkfifo(header->name, header->mode) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000496 perror_msg("%s: Cannot mkfifo", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000497 return( FALSE);
498 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000499 }
500
501 /* Now set permissions etc for the new directory */
502 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000503 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000504}
505
Erik Andersen1ad302a2000-03-24 00:54:46 +0000506/* Read an octal value in a field of the specified width, with optional
Erik Andersen298854f2000-03-23 01:09:18 +0000507 * spaces on both sides of the number and with an optional null character
Erik Andersen1ad302a2000-03-24 00:54:46 +0000508 * at the end. Returns -1 on an illegal format. */
Erik Andersen298854f2000-03-23 01:09:18 +0000509static long getOctal(const char *cp, int size)
Eric Andersencc8ed391999-10-05 16:24:54 +0000510{
Erik Andersen298854f2000-03-23 01:09:18 +0000511 long val = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000512
Erik Andersen298854f2000-03-23 01:09:18 +0000513 for(;(size > 0) && (*cp == ' '); cp++, size--);
Mark Whitleyf57c9442000-12-07 19:56:48 +0000514 if ((size == 0) || !is_octal(*cp))
Erik Andersen298854f2000-03-23 01:09:18 +0000515 return -1;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000516 for(; (size > 0) && is_octal(*cp); size--) {
Erik Andersen298854f2000-03-23 01:09:18 +0000517 val = val * 8 + *cp++ - '0';
Eric Andersencc8ed391999-10-05 16:24:54 +0000518 }
Erik Andersen298854f2000-03-23 01:09:18 +0000519 for (;(size > 0) && (*cp == ' '); cp++, size--);
520 if ((size > 0) && *cp)
521 return -1;
522 return val;
523}
Eric Andersencc8ed391999-10-05 16:24:54 +0000524
Erik Andersen1ad302a2000-03-24 00:54:46 +0000525
Erik Andersen298854f2000-03-23 01:09:18 +0000526/* Parse the tar header and fill in the nice struct with the details */
527static int
Erik Andersen3364d782000-03-28 00:58:14 +0000528readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
Erik Andersen298854f2000-03-23 01:09:18 +0000529{
Erik Andersene454fb62000-03-23 04:27:58 +0000530 int i;
Erik Andersen84e09e42000-04-08 20:58:35 +0000531 long chksum, sum=0;
Erik Andersene454fb62000-03-23 04:27:58 +0000532 unsigned char *s = (unsigned char *)rawHeader;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000533
Erik Andersen298854f2000-03-23 01:09:18 +0000534 header->name = rawHeader->name;
Erik Andersen84e09e42000-04-08 20:58:35 +0000535 /* Check for and relativify any absolute paths */
536 if ( *(header->name) == '/' ) {
537 static int alreadyWarned=FALSE;
538
539 while (*(header->name) == '/')
540 ++*(header->name);
541
542 if (alreadyWarned == FALSE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +0000543 error_msg("Removing leading '/' from member names\n");
Erik Andersen84e09e42000-04-08 20:58:35 +0000544 alreadyWarned = TRUE;
545 }
546 }
547
Erik Andersen298854f2000-03-23 01:09:18 +0000548 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode));
549 header->uid = getOctal(rawHeader->uid, sizeof(rawHeader->uid));
550 header->gid = getOctal(rawHeader->gid, sizeof(rawHeader->gid));
551 header->size = getOctal(rawHeader->size, sizeof(rawHeader->size));
552 header->mtime = getOctal(rawHeader->mtime, sizeof(rawHeader->mtime));
553 chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum));
554 header->type = rawHeader->typeflag;
555 header->linkname = rawHeader->linkname;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000556 header->devmajor = getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor));
557 header->devminor = getOctal(rawHeader->devminor, sizeof(rawHeader->devminor));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000558
Erik Andersen298854f2000-03-23 01:09:18 +0000559 /* Check the checksum */
Erik Andersen84e09e42000-04-08 20:58:35 +0000560 for (i = sizeof(*rawHeader); i-- != 0;) {
Erik Andersen298854f2000-03-23 01:09:18 +0000561 sum += *s++;
Erik Andersen84e09e42000-04-08 20:58:35 +0000562 }
563 /* Remove the effects of the checksum field (replace
564 * with blanks for the purposes of the checksum) */
565 s = rawHeader->chksum;
566 for (i = sizeof(rawHeader->chksum) ; i-- != 0;) {
567 sum -= *s++;
568 }
569 sum += ' ' * sizeof(rawHeader->chksum);
Erik Andersene454fb62000-03-23 04:27:58 +0000570 if (sum == chksum )
Erik Andersen298854f2000-03-23 01:09:18 +0000571 return ( TRUE);
572 return( FALSE);
573}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000574
Matt Kraaibe7499c2001-01-03 17:22:10 +0000575int exclude_file(char **excluded_files, const char *file)
576{
577 int i;
578
579 if (excluded_files == NULL)
580 return 0;
581
582 for (i = 0; excluded_files[i] != NULL; i++) {
583 if (excluded_files[i][0] == '/') {
584 if (fnmatch(excluded_files[i], file,
585 FNM_PATHNAME | FNM_LEADING_DIR) == 0)
586 return 1;
587 } else {
588 const char *p;
589
590 for (p = file; p[0] != '\0'; p++) {
591 if ((p == file || p[-1] == '/') && p[0] != '/' &&
592 fnmatch(excluded_files[i], p,
593 FNM_PATHNAME | FNM_LEADING_DIR) == 0)
594 return 1;
595 }
596 }
597 }
598
599 return 0;
600}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000601
Matt Kraai8f8dab92001-01-22 05:25:19 +0000602int extract_file(char **extract_files, const char *file)
603{
604 int i;
605
606 if (extract_files == NULL)
607 return 1;
608
609 for (i = 0; extract_files[i] != NULL; i++) {
610 if (fnmatch(extract_files[i], file, FNM_LEADING_DIR) == 0)
611 return 1;
612 }
613
614 return 0;
615}
616
Erik Andersen1ad302a2000-03-24 00:54:46 +0000617/*
618 * Read a tar file and extract or list the specified files within it.
619 * If the list is empty than all files are extracted or listed.
620 */
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000621extern int readTarFile(int tarFd, int extractFlag, int listFlag,
Matt Kraaib92223b2000-09-04 08:25:42 +0000622 int tostdoutFlag, int verboseFlag, char** extractList,
623 char** excludeList)
Erik Andersen1ad302a2000-03-24 00:54:46 +0000624{
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000625 int status;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000626 int errorFlag=FALSE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000627 int skipNextHeaderFlag=FALSE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000628 TarHeader rawHeader;
629 TarInfo header;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000630
Erik Andersene49d5ec2000-02-08 19:58:47 +0000631 /* Set the umask for this process so it doesn't
Erik Andersen1ad302a2000-03-24 00:54:46 +0000632 * screw up permission setting for us later. */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000633 umask(0);
Eric Andersencc8ed391999-10-05 16:24:54 +0000634
Erik Andersen1ad302a2000-03-24 00:54:46 +0000635 /* Read the tar file, and iterate over it one file at a time */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000636 while ( (status = full_read(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
Erik Andersene2729152000-02-18 21:34:17 +0000637
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000638 /* Try to read the header */
Erik Andersen3364d782000-03-28 00:58:14 +0000639 if ( readTarHeader(&rawHeader, &header) == FALSE ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000640 if ( *(header.name) == '\0' ) {
641 goto endgame;
642 } else {
643 errorFlag=TRUE;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000644 error_msg("Bad tar header, skipping\n");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000645 continue;
646 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000647 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000648 if ( *(header.name) == '\0' )
649 goto endgame;
Erik Andersen0817d132000-04-09 15:17:40 +0000650 header.tarFd = tarFd;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000651
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000652 /* Skip funky extra GNU headers that precede long files */
653 if ( (header.type == GNULONGNAME) || (header.type == GNULONGLINK) ) {
654 skipNextHeaderFlag=TRUE;
Matt Kraaiab8f9e22000-11-18 01:28:57 +0000655 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
656 errorFlag = TRUE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000657 continue;
658 }
659 if ( skipNextHeaderFlag == TRUE ) {
660 skipNextHeaderFlag=FALSE;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000661 error_msg(name_longer_than_foo, NAME_SIZE);
Matt Kraaiab8f9e22000-11-18 01:28:57 +0000662 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
663 errorFlag = TRUE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000664 continue;
665 }
666
Erik Andersen0817d132000-04-09 15:17:40 +0000667#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraaibe7499c2001-01-03 17:22:10 +0000668 if (exclude_file(excludeList, header.name)) {
Erik Andersen0817d132000-04-09 15:17:40 +0000669 /* There are not the droids you're looking for, move along */
Matt Kraaibe7499c2001-01-03 17:22:10 +0000670 /* If it is a regular file, pretend to extract it with
671 * the extractFlag set to FALSE, so the junk in the tarball
672 * is properly skipped over */
673 if ( header.type==REGTYPE || header.type==REGTYPE0 ) {
674 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
675 errorFlag = TRUE;
676 }
677 continue;
Erik Andersen0817d132000-04-09 15:17:40 +0000678 }
679#endif
Matt Kraaibe7499c2001-01-03 17:22:10 +0000680
Matt Kraai8f8dab92001-01-22 05:25:19 +0000681 if (!extract_file(extractList, header.name)) {
Matt Kraaib92223b2000-09-04 08:25:42 +0000682 /* There are not the droids you're looking for, move along */
Matt Kraai8f8dab92001-01-22 05:25:19 +0000683 /* If it is a regular file, pretend to extract it with
684 * the extractFlag set to FALSE, so the junk in the tarball
685 * is properly skipped over */
686 if ( header.type==REGTYPE || header.type==REGTYPE0 ) {
687 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
688 errorFlag = TRUE;
Matt Kraaib92223b2000-09-04 08:25:42 +0000689 }
Matt Kraai8f8dab92001-01-22 05:25:19 +0000690 continue;
Matt Kraaib92223b2000-09-04 08:25:42 +0000691 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000692
Matt Kraai82cfbad2000-09-15 21:18:43 +0000693 if (listFlag == TRUE) {
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000694 /* Special treatment if the list (-t) flag is on */
695 if (verboseFlag == TRUE) {
696 int len, len1;
697 char buf[35];
698 struct tm *tm = localtime (&(header.mtime));
699
Mark Whitleyf57c9442000-12-07 19:56:48 +0000700 len=printf("%s ", mode_string(header.mode));
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000701 my_getpwuid(buf, header.uid);
702 if (! *buf)
703 len+=printf("%d", header.uid);
704 else
705 len+=printf("%s", buf);
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000706 my_getgrgid(buf, header.gid);
707 if (! *buf)
708 len+=printf("/%-d ", header.gid);
709 else
710 len+=printf("/%-s ", buf);
711
712 if (header.type==CHRTYPE || header.type==BLKTYPE) {
713 len1=snprintf(buf, sizeof(buf), "%ld,%-ld ",
714 header.devmajor, header.devminor);
715 } else {
716 len1=snprintf(buf, sizeof(buf), "%lu ", (long)header.size);
717 }
718 /* Jump through some hoops to make the columns match up */
719 for(;(len+len1)<31;len++)
720 printf(" ");
721 printf(buf);
722
723 /* Use ISO 8610 time format */
724 if (tm) {
725 printf ("%04d-%02d-%02d %02d:%02d:%02d ",
726 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
727 tm->tm_hour, tm->tm_min, tm->tm_sec);
728 }
729 }
Eric Andersenfdd51032000-08-02 18:48:26 +0000730 printf("%s", header.name);
Matt Kraai82cfbad2000-09-15 21:18:43 +0000731 if (verboseFlag == TRUE) {
732 if (header.type==LNKTYPE) /* If this is a link, say so */
733 printf(" link to %s", header.linkname);
734 else if (header.type==SYMTYPE)
735 printf(" -> %s", header.linkname);
736 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000737 printf("\n");
738 }
739
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000740 /* List contents if we are supposed to do that */
741 if (verboseFlag == TRUE && extractFlag == TRUE) {
742 /* Now the normal listing */
743 FILE *vbFd = stdout;
744 if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr
745 vbFd = stderr;
746 fprintf(vbFd, "%s\n", header.name);
747 }
748
Matt Kraaif4462972000-09-01 02:50:48 +0000749 /* Remove files if we would overwrite them */
Matt Kraaida542f32000-09-01 02:53:01 +0000750 if (extractFlag == TRUE && tostdoutFlag == FALSE)
Matt Kraaif4462972000-09-01 02:50:48 +0000751 unlink(header.name);
Eric Andersencc8ed391999-10-05 16:24:54 +0000752
Erik Andersen1ad302a2000-03-24 00:54:46 +0000753 /* If we got here, we can be certain we have a legitimate
754 * header to work with. So work with it. */
755 switch ( header.type ) {
756 case REGTYPE:
757 case REGTYPE0:
758 /* If the name ends in a '/' then assume it is
759 * supposed to be a directory, and fall through */
760 if (header.name[strlen(header.name)-1] != '/') {
Erik Andersen6a34b532000-04-07 06:55:38 +0000761 if (tarExtractRegularFile(&header, extractFlag, tostdoutFlag)==FALSE)
762 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000763 break;
764 }
765 case DIRTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000766 if (tarExtractDirectory( &header, extractFlag, tostdoutFlag)==FALSE)
767 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000768 break;
769 case LNKTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000770 if (tarExtractHardLink( &header, extractFlag, tostdoutFlag)==FALSE)
771 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000772 break;
773 case SYMTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000774 if (tarExtractSymLink( &header, extractFlag, tostdoutFlag)==FALSE)
775 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000776 break;
777 case CHRTYPE:
778 case BLKTYPE:
779 case FIFOTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000780 if (tarExtractSpecial( &header, extractFlag, tostdoutFlag)==FALSE)
781 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000782 break;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000783#if 0
784 /* Handled earlier */
785 case GNULONGNAME:
786 case GNULONGLINK:
787 skipNextHeaderFlag=TRUE;
788 break;
789#endif
Erik Andersen1ad302a2000-03-24 00:54:46 +0000790 default:
Mark Whitleyf57c9442000-12-07 19:56:48 +0000791 error_msg("Unknown file type '%c' in tar file\n", header.type);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000792 close( tarFd);
793 return( FALSE);
794 }
795 }
796 close(tarFd);
797 if (status > 0) {
798 /* Bummer - we read a partial header */
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000799 perror_msg("Error reading tar file");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000800 return ( FALSE);
801 }
Erik Andersen6a34b532000-04-07 06:55:38 +0000802 else if (errorFlag==TRUE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +0000803 error_msg( "Error exit delayed from previous errors\n");
Erik Andersen6a34b532000-04-07 06:55:38 +0000804 return( FALSE);
805 } else
Erik Andersen1ad302a2000-03-24 00:54:46 +0000806 return( status);
807
808 /* Stuff to do when we are done */
809endgame:
810 close( tarFd);
811 if ( *(header.name) == '\0' ) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000812 if (errorFlag==TRUE)
Mark Whitleyf57c9442000-12-07 19:56:48 +0000813 error_msg( "Error exit delayed from previous errors\n");
Erik Andersen6a34b532000-04-07 06:55:38 +0000814 else
Erik Andersen1ad302a2000-03-24 00:54:46 +0000815 return( TRUE);
816 }
817 return( FALSE);
818}
819
Erik Andersen6acaa402000-03-26 14:03:20 +0000820
821#ifdef BB_FEATURE_TAR_CREATE
822
Eric Andersen3d957c82000-12-07 00:34:58 +0000823/*
824** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
825** the only functions that deal with the HardLinkInfo structure.
826** Even these functions use the xxxHardLinkInfo() functions.
827*/
828typedef struct HardLinkInfo HardLinkInfo;
829struct HardLinkInfo
830{
831 HardLinkInfo *next; /* Next entry in list */
832 dev_t dev; /* Device number */
833 ino_t ino; /* Inode number */
834 short linkCount; /* (Hard) Link Count */
835 char name[1]; /* Start of filename (must be last) */
836};
837
Erik Andersen68a9ea42000-04-04 18:39:50 +0000838/* Some info to be carried along when creating a new tarball */
839struct TarBallInfo
840{
841 char* fileName; /* File name of the tarball */
842 int tarFd; /* Open-for-write file descriptor
843 for the tarball */
844 struct stat statBuf; /* Stat info for the tarball, letting
845 us know the inode and device that the
846 tarball lives, so we can avoid trying
847 to include the tarball into itself */
848 int verboseFlag; /* Whether to print extra stuff or not */
Erik Andersenecd51242000-04-08 03:08:21 +0000849 char** excludeList; /* List of files to not include */
Eric Andersen3d957c82000-12-07 00:34:58 +0000850 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
851 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
Erik Andersen68a9ea42000-04-04 18:39:50 +0000852};
853typedef struct TarBallInfo TarBallInfo;
854
855
Eric Andersen3d957c82000-12-07 00:34:58 +0000856/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
857static void
858addHardLinkInfo (HardLinkInfo **hlInfoHeadPtr, dev_t dev, ino_t ino,
859 short linkCount, const char *name)
860{
861 /* Note: hlInfoHeadPtr can never be NULL! */
862 HardLinkInfo *hlInfo;
863
864 hlInfo = (HardLinkInfo *)xmalloc(sizeof(HardLinkInfo)+strlen(name)+1);
865 if (hlInfo) {
866 hlInfo->next = *hlInfoHeadPtr;
867 *hlInfoHeadPtr = hlInfo;
868 hlInfo->dev = dev;
869 hlInfo->ino = ino;
870 hlInfo->linkCount = linkCount;
871 strcpy(hlInfo->name, name);
872 }
873 return;
874}
875
876static void
877freeHardLinkInfo (HardLinkInfo **hlInfoHeadPtr)
878{
879 HardLinkInfo *hlInfo = NULL;
880 HardLinkInfo *hlInfoNext = NULL;
881
882 if (hlInfoHeadPtr) {
883 hlInfo = *hlInfoHeadPtr;
884 while (hlInfo) {
885 hlInfoNext = hlInfo->next;
886 free(hlInfo);
887 hlInfo = hlInfoNext;
888 }
889 *hlInfoHeadPtr = NULL;
890 }
891 return;
892}
893
894/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
895static HardLinkInfo *
896findHardLinkInfo (HardLinkInfo *hlInfo, dev_t dev, ino_t ino)
897{
898 while(hlInfo) {
899 if ((ino == hlInfo->ino) && (dev == hlInfo->dev))
900 break;
901 hlInfo = hlInfo->next;
902 }
903 return(hlInfo);
904}
905
Erik Andersen6acaa402000-03-26 14:03:20 +0000906/* Put an octal string into the specified buffer.
907 * The number is zero and space padded and possibly null padded.
908 * Returns TRUE if successful. */
909static int putOctal (char *cp, int len, long value)
910{
911 int tempLength;
Erik Andersen6acaa402000-03-26 14:03:20 +0000912 char tempBuffer[32];
Erik Andersen5661fe02000-04-05 01:00:52 +0000913 char *tempString = tempBuffer;
Erik Andersen6acaa402000-03-26 14:03:20 +0000914
915 /* Create a string of the specified length with an initial space,
916 * leading zeroes and the octal number, and a trailing null. */
Erik Andersen5661fe02000-04-05 01:00:52 +0000917 sprintf (tempString, "%0*lo", len - 1, value);
Erik Andersen6acaa402000-03-26 14:03:20 +0000918
919 /* If the string is too large, suppress the leading space. */
Erik Andersen5661fe02000-04-05 01:00:52 +0000920 tempLength = strlen (tempString) + 1;
Erik Andersen6acaa402000-03-26 14:03:20 +0000921 if (tempLength > len) {
922 tempLength--;
923 tempString++;
924 }
925
926 /* If the string is still too large, suppress the trailing null. */
927 if (tempLength > len)
928 tempLength--;
929
930 /* If the string is still too large, fail. */
931 if (tempLength > len)
932 return FALSE;
933
934 /* Copy the string to the field. */
935 memcpy (cp, tempString, len);
936
937 return TRUE;
938}
939
Erik Andersen68a9ea42000-04-04 18:39:50 +0000940/* Write out a tar header for the specified file/directory/whatever */
Erik Andersen3364d782000-03-28 00:58:14 +0000941static int
Matt Kraaie80a2632000-12-19 20:45:49 +0000942writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
943 const char *real_name, struct stat *statbuf)
Erik Andersen6acaa402000-03-26 14:03:20 +0000944{
Erik Andersen5661fe02000-04-05 01:00:52 +0000945 long chksum=0;
946 struct TarHeader header;
947 const unsigned char *cp = (const unsigned char *) &header;
948 ssize_t size = sizeof(struct TarHeader);
Eric Andersenfdd51032000-08-02 18:48:26 +0000949
Erik Andersen5661fe02000-04-05 01:00:52 +0000950 memset( &header, 0, size);
Erik Andersen3364d782000-03-28 00:58:14 +0000951
Matt Kraaie80a2632000-12-19 20:45:49 +0000952 strncpy(header.name, header_name, sizeof(header.name));
Erik Andersenecd51242000-04-08 03:08:21 +0000953
Erik Andersen5661fe02000-04-05 01:00:52 +0000954 putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
955 putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
956 putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
957 putOctal(header.size, sizeof(header.size), 0); /* Regular file size is handled later */
958 putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
959 strncpy(header.magic, TAR_MAGIC TAR_VERSION,
960 TAR_MAGIC_LEN + TAR_VERSION_LEN );
Erik Andersen68a9ea42000-04-04 18:39:50 +0000961
Erik Andersen84e09e42000-04-08 20:58:35 +0000962 /* Enter the user and group names (default to root if it fails) */
Erik Andersen5661fe02000-04-05 01:00:52 +0000963 my_getpwuid(header.uname, statbuf->st_uid);
Erik Andersen5661fe02000-04-05 01:00:52 +0000964 if (! *header.uname)
Erik Andersen84e09e42000-04-08 20:58:35 +0000965 strcpy(header.uname, "root");
Erik Andersen5661fe02000-04-05 01:00:52 +0000966 my_getgrgid(header.gname, statbuf->st_gid);
967 if (! *header.uname)
Erik Andersen84e09e42000-04-08 20:58:35 +0000968 strcpy(header.uname, "root");
Erik Andersen5661fe02000-04-05 01:00:52 +0000969
Eric Andersen3d957c82000-12-07 00:34:58 +0000970 if (tbInfo->hlInfo) {
971 /* This is a hard link */
972 header.typeflag = LNKTYPE;
973 strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
974 } else if (S_ISLNK(statbuf->st_mode)) {
Eric Andersen3adffb72000-06-26 10:54:06 +0000975 int link_size=0;
Erik Andersen5661fe02000-04-05 01:00:52 +0000976 char buffer[BUFSIZ];
977 header.typeflag = SYMTYPE;
Matt Kraaie80a2632000-12-19 20:45:49 +0000978 link_size = readlink(real_name, buffer, sizeof(buffer) - 1);
Eric Andersen3adffb72000-06-26 10:54:06 +0000979 if ( link_size < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000980 perror_msg("Error reading symlink '%s'", header.name);
Erik Andersen5661fe02000-04-05 01:00:52 +0000981 return ( FALSE);
982 }
Eric Andersen3adffb72000-06-26 10:54:06 +0000983 buffer[link_size] = '\0';
Erik Andersen95c1c1e2000-04-14 21:45:29 +0000984 strncpy(header.linkname, buffer, sizeof(header.linkname));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000985 } else if (S_ISDIR(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000986 header.typeflag = DIRTYPE;
987 strncat(header.name, "/", sizeof(header.name));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000988 } else if (S_ISCHR(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000989 header.typeflag = CHRTYPE;
990 putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
991 putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000992 } else if (S_ISBLK(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000993 header.typeflag = BLKTYPE;
994 putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
995 putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000996 } else if (S_ISFIFO(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000997 header.typeflag = FIFOTYPE;
998 } else if (S_ISREG(statbuf->st_mode)) {
999 header.typeflag = REGTYPE;
1000 putOctal(header.size, sizeof(header.size), statbuf->st_size);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001001 } else {
Matt Kraaie80a2632000-12-19 20:45:49 +00001002 error_msg("%s: Unknown file type\n", real_name);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001003 return ( FALSE);
1004 }
Erik Andersen68a9ea42000-04-04 18:39:50 +00001005
Erik Andersen5661fe02000-04-05 01:00:52 +00001006 /* Calculate and store the checksum (i.e. the sum of all of the bytes of
1007 * the header). The checksum field must be filled with blanks for the
1008 * calculation. The checksum field is formatted differently from the
1009 * other fields: it has [6] digits, a null, then a space -- rather than
1010 * digits, followed by a null like the other fields... */
1011 memset(header.chksum, ' ', sizeof(header.chksum));
1012 cp = (const unsigned char *) &header;
1013 while (size-- > 0)
1014 chksum += *cp++;
1015 putOctal(header.chksum, 7, chksum);
1016
1017 /* Now write the header out to disk */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001018 if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
Matt Kraaie80a2632000-12-19 20:45:49 +00001019 error_msg(io_error, real_name, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001020 return ( FALSE);
1021 }
1022 /* Pad the header up to the tar block size */
1023 for (; size<TAR_BLOCK_SIZE; size++) {
1024 write(tbInfo->tarFd, "\0", 1);
1025 }
1026 /* Now do the verbose thing (or not) */
Eric Andersenfdd51032000-08-02 18:48:26 +00001027 if (tbInfo->verboseFlag==TRUE) {
1028 FILE *vbFd = stdout;
1029 if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr
1030 vbFd = stderr;
1031 fprintf(vbFd, "%s\n", header.name);
1032 }
Erik Andersen3364d782000-03-28 00:58:14 +00001033
1034 return ( TRUE);
1035}
1036
1037
Erik Andersen68a9ea42000-04-04 18:39:50 +00001038static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
Erik Andersen3364d782000-03-28 00:58:14 +00001039{
Erik Andersen68a9ea42000-04-04 18:39:50 +00001040 struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
Matt Kraaie80a2632000-12-19 20:45:49 +00001041 const char *header_name;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001042
Eric Andersen3d957c82000-12-07 00:34:58 +00001043 /*
1044 ** Check to see if we are dealing with a hard link.
1045 ** If so -
1046 ** Treat the first occurance of a given dev/inode as a file while
1047 ** treating any additional occurances as hard links. This is done
1048 ** by adding the file information to the HardLinkInfo linked list.
1049 */
1050 tbInfo->hlInfo = NULL;
1051 if (statbuf->st_nlink > 1) {
1052 tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf->st_dev,
1053 statbuf->st_ino);
1054 if (tbInfo->hlInfo == NULL)
1055 addHardLinkInfo (&tbInfo->hlInfoHead, statbuf->st_dev,
1056 statbuf->st_ino, statbuf->st_nlink, fileName);
1057 }
1058
Erik Andersen68a9ea42000-04-04 18:39:50 +00001059 /* It is against the rules to archive a socket */
1060 if (S_ISSOCK(statbuf->st_mode)) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001061 error_msg("%s: socket ignored\n", fileName);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001062 return( TRUE);
1063 }
1064
1065 /* It is a bad idea to store the archive we are in the process of creating,
1066 * so check the device and inode to be sure that this particular file isn't
1067 * the new tarball */
1068 if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
1069 tbInfo->statBuf.st_ino == statbuf->st_ino) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001070 error_msg("%s: file is the archive; skipping\n", fileName);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001071 return( TRUE);
1072 }
1073
Matt Kraaie80a2632000-12-19 20:45:49 +00001074 header_name = fileName;
1075 while (header_name[0] == '/') {
Matt Kraaia1f97752000-12-19 06:24:08 +00001076 static int alreadyWarned=FALSE;
1077 if (alreadyWarned==FALSE) {
1078 error_msg("Removing leading '/' from member names\n");
1079 alreadyWarned=TRUE;
1080 }
Matt Kraaie80a2632000-12-19 20:45:49 +00001081 header_name++;
Matt Kraaia1f97752000-12-19 06:24:08 +00001082 }
1083
Eric Andersen1b1cfde2000-09-24 00:54:37 +00001084 if (strlen(fileName) >= NAME_SIZE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001085 error_msg(name_longer_than_foo, NAME_SIZE);
Eric Andersen1b1cfde2000-09-24 00:54:37 +00001086 return ( TRUE);
1087 }
1088
Matt Kraaie80a2632000-12-19 20:45:49 +00001089 if (header_name[0] == '\0')
Matt Kraaia1f97752000-12-19 06:24:08 +00001090 return TRUE;
1091
1092#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraaibe7499c2001-01-03 17:22:10 +00001093 if (exclude_file(tbInfo->excludeList, header_name)) {
1094 return SKIP;
Matt Kraaia1f97752000-12-19 06:24:08 +00001095 }
1096#endif
1097
Matt Kraaie80a2632000-12-19 20:45:49 +00001098 if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001099 return( FALSE);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001100 }
Erik Andersen5661fe02000-04-05 01:00:52 +00001101
1102 /* Now, if the file is a regular file, copy it out to the tarball */
Eric Andersen3d957c82000-12-07 00:34:58 +00001103 if ((tbInfo->hlInfo == NULL)
1104 && (S_ISREG(statbuf->st_mode))) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001105 int inputFileFd;
1106 char buffer[BUFSIZ];
1107 ssize_t size=0, readSize=0;
1108
1109 /* open the file we want to archive, and make sure all is well */
1110 if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001111 error_msg("%s: Cannot open: %s\n", fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001112 return( FALSE);
1113 }
1114
1115 /* write the file to the archive */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001116 while ( (size = full_read(inputFileFd, buffer, sizeof(buffer))) > 0 ) {
1117 if (full_write(tbInfo->tarFd, buffer, size) != size ) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001118 /* Output file seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001119 error_msg(io_error, fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001120 return( FALSE);
1121 }
1122 readSize+=size;
1123 }
1124 if (size == -1) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001125 error_msg(io_error, fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001126 return( FALSE);
1127 }
1128 /* Pad the file up to the tar block size */
1129 for (; (readSize%TAR_BLOCK_SIZE) != 0; readSize++) {
1130 write(tbInfo->tarFd, "\0", 1);
1131 }
1132 close( inputFileFd);
1133 }
Erik Andersen68a9ea42000-04-04 18:39:50 +00001134
1135 return( TRUE);
Erik Andersen6acaa402000-03-26 14:03:20 +00001136}
1137
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001138static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
1139 char** excludeList)
Erik Andersen6acaa402000-03-26 14:03:20 +00001140{
Erik Andersen3364d782000-03-28 00:58:14 +00001141 int tarFd=-1;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001142 int errorFlag=FALSE;
Erik Andersen5661fe02000-04-05 01:00:52 +00001143 ssize_t size;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001144 struct TarBallInfo tbInfo;
1145 tbInfo.verboseFlag = verboseFlag;
Eric Andersen3d957c82000-12-07 00:34:58 +00001146 tbInfo.hlInfoHead = NULL;
Erik Andersen3364d782000-03-28 00:58:14 +00001147
1148 /* Make sure there is at least one file to tar up. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001149 if (*argv == NULL)
Mark Whitleyf57c9442000-12-07 19:56:48 +00001150 error_msg_and_die("Cowardly refusing to create an empty archive\n");
Erik Andersen6acaa402000-03-26 14:03:20 +00001151
1152 /* Open the tar file for writing. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001153 if (!strcmp(tarName, "-"))
Erik Andersen68a9ea42000-04-04 18:39:50 +00001154 tbInfo.tarFd = fileno(stdout);
Erik Andersen6acaa402000-03-26 14:03:20 +00001155 else
Erik Andersen68a9ea42000-04-04 18:39:50 +00001156 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1157 if (tbInfo.tarFd < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +00001158 perror_msg( "Error opening '%s'", tarName);
Eric Andersen3d957c82000-12-07 00:34:58 +00001159 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen6acaa402000-03-26 14:03:20 +00001160 return ( FALSE);
1161 }
Erik Andersenecd51242000-04-08 03:08:21 +00001162 tbInfo.excludeList=excludeList;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001163 /* Store the stat info for the tarball's file, so
1164 * can avoid including the tarball into itself.... */
1165 if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
Mark Whitleyf57c9442000-12-07 19:56:48 +00001166 error_msg_and_die(io_error, tarName, strerror(errno));
Erik Andersen6acaa402000-03-26 14:03:20 +00001167
1168 /* Set the umask for this process so it doesn't
1169 * screw up permission setting for us later. */
1170 umask(0);
1171
1172 /* Read the directory/files and iterate over them one at a time */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001173 while (*argv != NULL) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001174 if (recursive_action(*argv++, TRUE, FALSE, FALSE,
Erik Andersen68a9ea42000-04-04 18:39:50 +00001175 writeFileToTarball, writeFileToTarball,
1176 (void*) &tbInfo) == FALSE) {
1177 errorFlag = TRUE;
Erik Andersen3364d782000-03-28 00:58:14 +00001178 }
Erik Andersen6acaa402000-03-26 14:03:20 +00001179 }
Erik Andersen5661fe02000-04-05 01:00:52 +00001180 /* Write two empty blocks to the end of the archive */
1181 for (size=0; size<(2*TAR_BLOCK_SIZE); size++) {
1182 write(tbInfo.tarFd, "\0", 1);
1183 }
Erik Andersen0817d132000-04-09 15:17:40 +00001184
1185 /* To be pedantically correct, we would check if the tarball
Eric Andersen3c5ee9a2000-11-14 22:15:48 +00001186 * is smaller than 20 tar blocks, and pad it if it was smaller,
Erik Andersen0817d132000-04-09 15:17:40 +00001187 * but that isn't necessary for GNU tar interoperability, and
1188 * so is considered a waste of space */
1189
Erik Andersen68a9ea42000-04-04 18:39:50 +00001190 /* Hang up the tools, close up shop, head home */
Erik Andersen6acaa402000-03-26 14:03:20 +00001191 close(tarFd);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001192 if (errorFlag == TRUE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001193 error_msg("Error exit delayed from previous errors\n");
Eric Andersen3d957c82000-12-07 00:34:58 +00001194 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001195 return(FALSE);
1196 }
Eric Andersen3d957c82000-12-07 00:34:58 +00001197 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen6acaa402000-03-26 14:03:20 +00001198 return( TRUE);
1199}
1200
1201
1202#endif
1203