blob: fb8d84446a5369ad43d69a22db2c6d410579f285 [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 Andersencc8ed391999-10-05 16:24:54 +000039#include <stdio.h>
40#include <dirent.h>
41#include <errno.h>
42#include <fcntl.h>
43#include <signal.h>
44#include <time.h>
Erik Andersen7dc16072000-01-04 01:10:25 +000045#include <utime.h>
Eric Andersen96bcfd31999-11-12 01:30:18 +000046#include <sys/types.h>
Eric Andersen08b10341999-11-19 02:38:58 +000047#include <sys/sysmacros.h>
Matt Kraai43c8c382000-09-04 16:51:55 +000048#include <getopt.h>
Matt Kraaibe7499c2001-01-03 17:22:10 +000049#include <fnmatch.h>
Eric Andersened3ef502001-01-27 08:24:39 +000050#include <string.h>
51#include <stdlib.h>
52#include <unistd.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000053#include "busybox.h"
54#define BB_DECLARE_EXTERN
55#define bb_need_io_error
56#define bb_need_name_longer_than_foo
57#include "messages.c"
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);
Glenn L McGrath018e9e62001-03-28 07:27:26 +000061extern int gz_open(FILE *compressed_file, int *pid);
62extern void gz_close(int gunzip_pid);
Glenn L McGrath46f44d22000-12-10 01:57:30 +000063#endif
64
Erik Andersen298854f2000-03-23 01:09:18 +000065/* Tar file constants */
Erik Andersen1ad302a2000-03-24 00:54:46 +000066#ifndef MAJOR
67#define MAJOR(dev) (((dev)>>8)&0xff)
68#define MINOR(dev) ((dev)&0xff)
69#endif
Eric Andersencc8ed391999-10-05 16:24:54 +000070
Mark Whitley59ab0252001-01-23 22:30:04 +000071enum { NAME_SIZE = 100 }; /* because gcc won't let me use 'static const int' */
Eric Andersencc8ed391999-10-05 16:24:54 +000072
Erik Andersen298854f2000-03-23 01:09:18 +000073/* POSIX tar Header Block, from POSIX 1003.1-1990 */
74struct TarHeader
75{
76 /* byte offset */
Eric Andersen1b1cfde2000-09-24 00:54:37 +000077 char name[NAME_SIZE]; /* 0-99 */
Erik Andersen0817d132000-04-09 15:17:40 +000078 char mode[8]; /* 100-107 */
79 char uid[8]; /* 108-115 */
80 char gid[8]; /* 116-123 */
81 char size[12]; /* 124-135 */
82 char mtime[12]; /* 136-147 */
83 char chksum[8]; /* 148-155 */
84 char typeflag; /* 156-156 */
Eric Andersen1b1cfde2000-09-24 00:54:37 +000085 char linkname[NAME_SIZE]; /* 157-256 */
Erik Andersen0817d132000-04-09 15:17:40 +000086 char magic[6]; /* 257-262 */
87 char version[2]; /* 263-264 */
88 char uname[32]; /* 265-296 */
89 char gname[32]; /* 297-328 */
90 char devmajor[8]; /* 329-336 */
91 char devminor[8]; /* 337-344 */
92 char prefix[155]; /* 345-499 */
93 char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
Erik Andersen298854f2000-03-23 01:09:18 +000094};
95typedef struct TarHeader TarHeader;
Eric Andersencc8ed391999-10-05 16:24:54 +000096
Eric Andersencc8ed391999-10-05 16:24:54 +000097
Erik Andersen298854f2000-03-23 01:09:18 +000098/* A few useful constants */
99#define TAR_MAGIC "ustar" /* ustar and a null */
Erik Andersen0817d132000-04-09 15:17:40 +0000100#define TAR_VERSION " " /* Be compatable with GNU tar format */
Mark Whitley59ab0252001-01-23 22:30:04 +0000101static const int TAR_MAGIC_LEN = 6;
102static const int TAR_VERSION_LEN = 2;
103static const int TAR_BLOCK_SIZE = 512;
Erik Andersen298854f2000-03-23 01:09:18 +0000104
105/* A nice enum with all the possible tar file content types */
106enum TarFileType
107{
108 REGTYPE = '0', /* regular file */
109 REGTYPE0 = '\0', /* regular file (ancient bug compat)*/
110 LNKTYPE = '1', /* hard link */
111 SYMTYPE = '2', /* symbolic link */
112 CHRTYPE = '3', /* character special */
113 BLKTYPE = '4', /* block special */
114 DIRTYPE = '5', /* directory */
115 FIFOTYPE = '6', /* FIFO special */
116 CONTTYPE = '7', /* reserved */
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000117 GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
118 GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
Erik Andersen298854f2000-03-23 01:09:18 +0000119};
120typedef enum TarFileType TarFileType;
121
122/* This struct ignores magic, non-numeric user name,
123 * non-numeric group name, and the checksum, since
124 * these are all ignored by BusyBox tar. */
125struct TarInfo
126{
127 int tarFd; /* An open file descriptor for reading from the tarball */
128 char * name; /* File name */
129 mode_t mode; /* Unix mode, including device bits. */
130 uid_t uid; /* Numeric UID */
131 gid_t gid; /* Numeric GID */
132 size_t size; /* Size of file */
133 time_t mtime; /* Last-modified time */
134 enum TarFileType type; /* Regular, directory, link, etc */
135 char * linkname; /* Name for symbolic and hard links */
Erik Andersen1ad302a2000-03-24 00:54:46 +0000136 long devmajor; /* Major number for special device */
137 long devminor; /* Minor number for special device */
Erik Andersen298854f2000-03-23 01:09:18 +0000138};
139typedef struct TarInfo TarInfo;
140
Erik Andersene454fb62000-03-23 04:27:58 +0000141/* Local procedures to restore files from a tar file. */
Glenn L McGrath7541e3a2001-01-02 23:41:50 +0000142extern int readTarFile(int tarFd, int extractFlag, int listFlag,
Matt Kraaib92223b2000-09-04 08:25:42 +0000143 int tostdoutFlag, int verboseFlag, char** extractList,
144 char** excludeList);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000145
Erik Andersen05100cd2000-01-16 01:30:52 +0000146#ifdef BB_FEATURE_TAR_CREATE
Erik Andersen6acaa402000-03-26 14:03:20 +0000147/* Local procedures to save files into a tar file. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +0000148static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
149 char** excludeList);
Erik Andersen05100cd2000-01-16 01:30:52 +0000150#endif
151
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000152#if defined BB_FEATURE_TAR_EXCLUDE
Eric Andersen3e6ff902001-03-09 21:24:12 +0000153static struct option longopts[] = {
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000154 { "exclude", 1, NULL, 'e' },
155 { NULL, 0, NULL, 0 }
156};
157#endif
158
Erik Andersene49d5ec2000-02-08 19:58:47 +0000159extern int tar_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +0000160{
Erik Andersenecd51242000-04-08 03:08:21 +0000161 char** excludeList=NULL;
Matt Kraaic119ab92000-11-30 04:44:54 +0000162 char** extractList=NULL;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000163 const char *tarName="-";
Erik Andersen0817d132000-04-09 15:17:40 +0000164#if defined BB_FEATURE_TAR_EXCLUDE
Erik Andersenecd51242000-04-08 03:08:21 +0000165 int excludeListSize=0;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000166 FILE *fileList;
167 char file[256];
Erik Andersen0817d132000-04-09 15:17:40 +0000168#endif
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000169#if defined BB_FEATURE_TAR_GZIP
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000170 FILE *comp_file = NULL;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000171 int unzipFlag = FALSE;
172#endif
Erik Andersen298854f2000-03-23 01:09:18 +0000173 int listFlag = FALSE;
174 int extractFlag = FALSE;
175 int createFlag = FALSE;
176 int verboseFlag = FALSE;
177 int tostdoutFlag = FALSE;
Eric Andersen02f3b2e2000-12-01 19:04:52 +0000178 int status = FALSE;
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000179 int opt;
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000180 pid_t pid;
Eric Andersencc8ed391999-10-05 16:24:54 +0000181
Erik Andersenecd51242000-04-08 03:08:21 +0000182 if (argc <= 1)
Eric Andersen67991cf2001-02-14 21:23:06 +0000183 show_usage();
Eric Andersencc8ed391999-10-05 16:24:54 +0000184
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000185 if (argv[1][0] != '-') {
186 char *tmp = xmalloc(strlen(argv[1]) + 2);
187 tmp[0] = '-';
188 strcpy(tmp + 1, argv[1]);
189 argv[1] = tmp;
190 }
191
192 while (
193#ifndef BB_FEATURE_TAR_EXCLUDE
194 (opt = getopt(argc, argv, "cxtzvOf:"))
195#else
196 (opt = getopt_long(argc, argv, "cxtzvOf:X:", longopts, NULL))
197#endif
198 > 0) {
199 switch (opt) {
200 case 'c':
201 if (extractFlag == TRUE || listFlag == TRUE)
202 goto flagError;
203 createFlag = TRUE;
204 break;
205 case 'x':
206 if (listFlag == TRUE || createFlag == TRUE)
207 goto flagError;
208 extractFlag = TRUE;
209 break;
210 case 't':
211 if (extractFlag == TRUE || createFlag == TRUE)
212 goto flagError;
213 listFlag = TRUE;
214 break;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000215#ifdef BB_FEATURE_TAR_GZIP
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000216 case 'z':
217 unzipFlag = TRUE;
218 break;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000219#endif
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000220 case 'v':
221 verboseFlag = TRUE;
222 break;
223 case 'O':
224 tostdoutFlag = TRUE;
225 break;
226 case 'f':
227 if (*tarName != '-')
Matt Kraaidd19c692001-01-31 19:00:21 +0000228 error_msg_and_die( "Only one 'f' option allowed");
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000229 tarName = optarg;
230 break;
Erik Andersen0817d132000-04-09 15:17:40 +0000231#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000232 case 'e':
233 excludeList=xrealloc( excludeList,
234 sizeof(char *) * (excludeListSize+2));
235 excludeList[excludeListSize] = optarg;
236 /* Tack a NULL onto the end of the list */
237 excludeList[++excludeListSize] = NULL;
238 case 'X':
239 fileList = xfopen(optarg, "r");
240 while (fgets(file, sizeof(file), fileList) != NULL) {
241 excludeList = xrealloc(excludeList,
242 sizeof(char *) * (excludeListSize+2));
Matt Kraai05e782d2001-02-01 16:49:30 +0000243 chomp(file);
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000244 excludeList[excludeListSize] = xstrdup(file);
245 /* Tack a NULL onto the end of the list */
246 excludeList[++excludeListSize] = NULL;
247 }
248 fclose(fileList);
249 break;
Erik Andersen0817d132000-04-09 15:17:40 +0000250#endif
Erik Andersenecd51242000-04-08 03:08:21 +0000251 default:
Eric Andersen67991cf2001-02-14 21:23:06 +0000252 show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000253 }
Eric Andersencc8ed391999-10-05 16:24:54 +0000254 }
255
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000256 /*
Erik Andersene49d5ec2000-02-08 19:58:47 +0000257 * Do the correct type of action supplying the rest of the
258 * command line arguments as the list of files to process.
259 */
260 if (createFlag == TRUE) {
Erik Andersende552872000-01-23 01:34:05 +0000261#ifndef BB_FEATURE_TAR_CREATE
Matt Kraaidd19c692001-01-31 19:00:21 +0000262 error_msg_and_die( "This version of tar was not compiled with tar creation support.");
Erik Andersende552872000-01-23 01:34:05 +0000263#else
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000264#ifdef BB_FEATURE_TAR_GZIP
265 if (unzipFlag==TRUE)
Matt Kraaidd19c692001-01-31 19:00:21 +0000266 error_msg_and_die("Creation of compressed not internally support by tar, pipe to busybox gunzip");
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000267#endif
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000268 status = writeTarFile(tarName, verboseFlag, argv + optind, excludeList);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000269#endif
Erik Andersen8ea7d8c2000-05-20 00:40:08 +0000270 }
271 if (listFlag == TRUE || extractFlag == TRUE) {
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000272 int tarFd;
Matt Kraai3b3f5c32001-01-22 20:49:00 +0000273 if (argv[optind])
274 extractList = argv + optind;
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000275 /* Open the tar file for reading. */
276 if (!strcmp(tarName, "-"))
277 tarFd = fileno(stdin);
278 else
279 tarFd = open(tarName, O_RDONLY);
280 if (tarFd < 0)
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000281 perror_msg_and_die("Error opening '%s'", tarName);
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000282
283#ifdef BB_FEATURE_TAR_GZIP
284 /* unzip tarFd in a seperate process */
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000285 if (unzipFlag == TRUE) {
286 comp_file = fdopen(tarFd, "r");
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000287 if ((tarFd = gz_open(comp_file, &pid)) == EXIT_FAILURE) {
288 error_msg_and_die("Couldnt unzip file");
289 }
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000290 }
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000291#endif
292 status = readTarFile(tarFd, extractFlag, listFlag, tostdoutFlag,
Matt Kraai3e856ce2000-12-01 02:55:13 +0000293 verboseFlag, extractList, excludeList);
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000294 close(tarFd);
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000295#ifdef BB_FEATURE_TAR_GZIP
Glenn L McGrathae8ad352001-03-28 23:57:51 +0000296 if (unzipFlag == TRUE) {
297 gz_close(pid);
298 fclose(comp_file);
299 }
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000300#endif
Glenn L McGrathae8ad352001-03-28 23:57:51 +0000301 }
Glenn L McGrath018e9e62001-03-28 07:27:26 +0000302
Matt Kraai3e856ce2000-12-01 02:55:13 +0000303 if (status == TRUE)
304 return EXIT_SUCCESS;
305 else
306 return EXIT_FAILURE;
307
Erik Andersene49d5ec2000-02-08 19:58:47 +0000308 flagError:
Matt Kraaidd19c692001-01-31 19:00:21 +0000309 error_msg_and_die( "Exactly one of 'c', 'x' or 't' must be specified");
Erik Andersen298854f2000-03-23 01:09:18 +0000310}
311
312static void
Erik Andersen6a34b532000-04-07 06:55:38 +0000313fixUpPermissions(TarInfo *header)
314{
315 struct utimbuf t;
316 /* Now set permissions etc for the new file */
317 chown(header->name, header->uid, header->gid);
318 chmod(header->name, header->mode);
319 /* Reset the time */
320 t.actime = time(0);
321 t.modtime = header->mtime;
322 utime(header->name, &t);
323}
324
325static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000326tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersen298854f2000-03-23 01:09:18 +0000327{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000328 size_t writeSize;
329 size_t readSize;
330 size_t actualWriteSz;
331 char buffer[BUFSIZ];
332 size_t size = header->size;
333 int outFd=fileno(stdout);
334
335 /* Open the file to be written, if a file is supposed to be written */
336 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000337 /* Create the path to the file, just in case it isn't there...
338 * This should not screw up path permissions or anything. */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000339 create_path(header->name, 0777);
Eric Andersen0c6a9702000-06-09 20:51:50 +0000340 if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
341 header->mode & ~S_IFMT)) < 0) {
Mark Whitleyf57c9442000-12-07 19:56:48 +0000342 error_msg(io_error, header->name, strerror(errno));
Eric Andersen0c6a9702000-06-09 20:51:50 +0000343 return( FALSE);
344 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000345 }
346
347 /* Write out the file, if we are supposed to be doing that */
348 while ( size > 0 ) {
349 actualWriteSz=0;
350 if ( size > sizeof(buffer) )
351 writeSize = readSize = sizeof(buffer);
352 else {
353 int mod = size % 512;
354 if ( mod != 0 )
355 readSize = size + (512 - mod);
356 else
357 readSize = size;
358 writeSize = size;
359 }
Mark Whitleyf57c9442000-12-07 19:56:48 +0000360 if ( (readSize = full_read(header->tarFd, buffer, readSize)) <= 0 ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000361 /* Tarball seems to have a problem */
Matt Kraaidd19c692001-01-31 19:00:21 +0000362 error_msg("Unexpected EOF in archive");
Erik Andersen6a34b532000-04-07 06:55:38 +0000363 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000364 }
365 if ( readSize < writeSize )
366 writeSize = readSize;
367
368 /* Write out the file, if we are supposed to be doing that */
369 if (extractFlag==TRUE) {
370
Mark Whitleyf57c9442000-12-07 19:56:48 +0000371 if ((actualWriteSz=full_write(outFd, buffer, writeSize)) != writeSize ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000372 /* Output file seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000373 error_msg(io_error, header->name, strerror(errno));
Erik Andersen6a34b532000-04-07 06:55:38 +0000374 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000375 }
Erik Andersen0817d132000-04-09 15:17:40 +0000376 } else {
377 actualWriteSz=writeSize;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000378 }
379
380 size -= actualWriteSz;
381 }
382
383 /* Now we are done writing the file out, so try
384 * and fix up the permissions and whatnot */
385 if (extractFlag==TRUE && tostdoutFlag==FALSE) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000386 close(outFd);
Erik Andersen6a34b532000-04-07 06:55:38 +0000387 fixUpPermissions(header);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000388 }
Erik Andersen6a34b532000-04-07 06:55:38 +0000389 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000390}
391
Erik Andersen6a34b532000-04-07 06:55:38 +0000392static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000393tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000394{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000395
396 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000397 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000398
Mark Whitleyf57c9442000-12-07 19:56:48 +0000399 if (create_path(header->name, header->mode) != TRUE) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000400 perror_msg("%s: Cannot mkdir", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000401 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000402 }
403 /* make the final component, just in case it was
Mark Whitleyf57c9442000-12-07 19:56:48 +0000404 * omitted by create_path() (which will skip the
Erik Andersen1ad302a2000-03-24 00:54:46 +0000405 * directory if it doesn't have a terminating '/') */
Matt Kraai541ffe32001-01-13 21:46:25 +0000406 if (mkdir(header->name, header->mode) < 0 && errno != EEXIST) {
407 perror_msg("%s", header->name);
408 return FALSE;
Erik Andersen6acaa402000-03-26 14:03:20 +0000409 }
Matt Kraai541ffe32001-01-13 21:46:25 +0000410
411 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000412 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000413}
414
Erik Andersen6a34b532000-04-07 06:55:38 +0000415static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000416tarExtractHardLink(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000417{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000418 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000419 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000420
421 if (link(header->linkname, header->name) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000422 perror_msg("%s: Cannot create hard link to '%s'", header->name,
423 header->linkname);
Erik Andersen6a34b532000-04-07 06:55:38 +0000424 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000425 }
426
427 /* Now set permissions etc for the new directory */
428 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000429 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000430}
431
Erik Andersen6a34b532000-04-07 06:55:38 +0000432static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000433tarExtractSymLink(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000434{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000435 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000436 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000437
438#ifdef S_ISLNK
439 if (symlink(header->linkname, header->name) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000440 perror_msg("%s: Cannot create symlink to '%s'", header->name,
441 header->linkname);
Erik Andersen6a34b532000-04-07 06:55:38 +0000442 return( FALSE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000443 }
444 /* Try to change ownership of the symlink.
445 * If libs doesn't support that, don't bother.
446 * Changing the pointed-to-file is the Wrong Thing(tm).
447 */
448#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
449 lchown(header->name, header->uid, header->gid);
450#endif
451
452 /* Do not change permissions or date on symlink,
453 * since it changes the pointed to file instead. duh. */
454#else
Matt Kraaidd19c692001-01-31 19:00:21 +0000455 error_msg("%s: Cannot create symlink to '%s': %s",
Erik Andersen6a34b532000-04-07 06:55:38 +0000456 header->name, header->linkname,
457 "symlinks not supported");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000458#endif
Erik Andersen6a34b532000-04-07 06:55:38 +0000459 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000460}
461
Erik Andersen6a34b532000-04-07 06:55:38 +0000462static int
Erik Andersen1ad302a2000-03-24 00:54:46 +0000463tarExtractSpecial(TarInfo *header, int extractFlag, int tostdoutFlag)
Erik Andersene454fb62000-03-23 04:27:58 +0000464{
Erik Andersen1ad302a2000-03-24 00:54:46 +0000465 if (extractFlag==FALSE || tostdoutFlag==TRUE)
Erik Andersen6a34b532000-04-07 06:55:38 +0000466 return( TRUE);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000467
468 if (S_ISCHR(header->mode) || S_ISBLK(header->mode) || S_ISSOCK(header->mode)) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000469 if (mknod(header->name, header->mode, makedev(header->devmajor, header->devminor)) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000470 perror_msg("%s: Cannot mknod", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000471 return( FALSE);
472 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000473 } else if (S_ISFIFO(header->mode)) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000474 if (mkfifo(header->name, header->mode) < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000475 perror_msg("%s: Cannot mkfifo", header->name);
Erik Andersen6a34b532000-04-07 06:55:38 +0000476 return( FALSE);
477 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000478 }
479
480 /* Now set permissions etc for the new directory */
481 fixUpPermissions(header);
Erik Andersen6a34b532000-04-07 06:55:38 +0000482 return( TRUE);
Erik Andersene454fb62000-03-23 04:27:58 +0000483}
484
Erik Andersen1ad302a2000-03-24 00:54:46 +0000485/* Read an octal value in a field of the specified width, with optional
Erik Andersen298854f2000-03-23 01:09:18 +0000486 * spaces on both sides of the number and with an optional null character
Erik Andersen1ad302a2000-03-24 00:54:46 +0000487 * at the end. Returns -1 on an illegal format. */
Erik Andersen298854f2000-03-23 01:09:18 +0000488static long getOctal(const char *cp, int size)
Eric Andersencc8ed391999-10-05 16:24:54 +0000489{
Erik Andersen298854f2000-03-23 01:09:18 +0000490 long val = 0;
Eric Andersencc8ed391999-10-05 16:24:54 +0000491
Erik Andersen298854f2000-03-23 01:09:18 +0000492 for(;(size > 0) && (*cp == ' '); cp++, size--);
Mark Whitleyf57c9442000-12-07 19:56:48 +0000493 if ((size == 0) || !is_octal(*cp))
Erik Andersen298854f2000-03-23 01:09:18 +0000494 return -1;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000495 for(; (size > 0) && is_octal(*cp); size--) {
Erik Andersen298854f2000-03-23 01:09:18 +0000496 val = val * 8 + *cp++ - '0';
Eric Andersencc8ed391999-10-05 16:24:54 +0000497 }
Erik Andersen298854f2000-03-23 01:09:18 +0000498 for (;(size > 0) && (*cp == ' '); cp++, size--);
499 if ((size > 0) && *cp)
500 return -1;
501 return val;
502}
Eric Andersencc8ed391999-10-05 16:24:54 +0000503
Erik Andersen1ad302a2000-03-24 00:54:46 +0000504
Erik Andersen298854f2000-03-23 01:09:18 +0000505/* Parse the tar header and fill in the nice struct with the details */
506static int
Erik Andersen3364d782000-03-28 00:58:14 +0000507readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
Erik Andersen298854f2000-03-23 01:09:18 +0000508{
Erik Andersene454fb62000-03-23 04:27:58 +0000509 int i;
Erik Andersen84e09e42000-04-08 20:58:35 +0000510 long chksum, sum=0;
Erik Andersene454fb62000-03-23 04:27:58 +0000511 unsigned char *s = (unsigned char *)rawHeader;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000512
Erik Andersen298854f2000-03-23 01:09:18 +0000513 header->name = rawHeader->name;
Erik Andersen84e09e42000-04-08 20:58:35 +0000514 /* Check for and relativify any absolute paths */
515 if ( *(header->name) == '/' ) {
516 static int alreadyWarned=FALSE;
517
518 while (*(header->name) == '/')
519 ++*(header->name);
520
521 if (alreadyWarned == FALSE) {
Matt Kraaidd19c692001-01-31 19:00:21 +0000522 error_msg("Removing leading '/' from member names");
Erik Andersen84e09e42000-04-08 20:58:35 +0000523 alreadyWarned = TRUE;
524 }
525 }
526
Erik Andersen298854f2000-03-23 01:09:18 +0000527 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode));
528 header->uid = getOctal(rawHeader->uid, sizeof(rawHeader->uid));
529 header->gid = getOctal(rawHeader->gid, sizeof(rawHeader->gid));
530 header->size = getOctal(rawHeader->size, sizeof(rawHeader->size));
531 header->mtime = getOctal(rawHeader->mtime, sizeof(rawHeader->mtime));
532 chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum));
533 header->type = rawHeader->typeflag;
534 header->linkname = rawHeader->linkname;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000535 header->devmajor = getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor));
536 header->devminor = getOctal(rawHeader->devminor, sizeof(rawHeader->devminor));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000537
Erik Andersen298854f2000-03-23 01:09:18 +0000538 /* Check the checksum */
Erik Andersen84e09e42000-04-08 20:58:35 +0000539 for (i = sizeof(*rawHeader); i-- != 0;) {
Erik Andersen298854f2000-03-23 01:09:18 +0000540 sum += *s++;
Erik Andersen84e09e42000-04-08 20:58:35 +0000541 }
542 /* Remove the effects of the checksum field (replace
543 * with blanks for the purposes of the checksum) */
544 s = rawHeader->chksum;
545 for (i = sizeof(rawHeader->chksum) ; i-- != 0;) {
546 sum -= *s++;
547 }
548 sum += ' ' * sizeof(rawHeader->chksum);
Erik Andersene454fb62000-03-23 04:27:58 +0000549 if (sum == chksum )
Erik Andersen298854f2000-03-23 01:09:18 +0000550 return ( TRUE);
551 return( FALSE);
552}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000553
Eric Andersen3e6ff902001-03-09 21:24:12 +0000554static int exclude_file(char **excluded_files, const char *file)
Matt Kraaibe7499c2001-01-03 17:22:10 +0000555{
556 int i;
557
558 if (excluded_files == NULL)
559 return 0;
560
561 for (i = 0; excluded_files[i] != NULL; i++) {
562 if (excluded_files[i][0] == '/') {
563 if (fnmatch(excluded_files[i], file,
564 FNM_PATHNAME | FNM_LEADING_DIR) == 0)
565 return 1;
566 } else {
567 const char *p;
568
569 for (p = file; p[0] != '\0'; p++) {
570 if ((p == file || p[-1] == '/') && p[0] != '/' &&
571 fnmatch(excluded_files[i], p,
572 FNM_PATHNAME | FNM_LEADING_DIR) == 0)
573 return 1;
574 }
575 }
576 }
577
578 return 0;
579}
Erik Andersene49d5ec2000-02-08 19:58:47 +0000580
Eric Andersen3e6ff902001-03-09 21:24:12 +0000581static int extract_file(char **extract_files, const char *file)
Matt Kraai8f8dab92001-01-22 05:25:19 +0000582{
583 int i;
584
585 if (extract_files == NULL)
586 return 1;
587
588 for (i = 0; extract_files[i] != NULL; i++) {
589 if (fnmatch(extract_files[i], file, FNM_LEADING_DIR) == 0)
590 return 1;
591 }
592
593 return 0;
594}
595
Erik Andersen1ad302a2000-03-24 00:54:46 +0000596/*
597 * Read a tar file and extract or list the specified files within it.
598 * If the list is empty than all files are extracted or listed.
599 */
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000600extern int readTarFile(int tarFd, int extractFlag, int listFlag,
Matt Kraaib92223b2000-09-04 08:25:42 +0000601 int tostdoutFlag, int verboseFlag, char** extractList,
602 char** excludeList)
Erik Andersen1ad302a2000-03-24 00:54:46 +0000603{
Glenn L McGrath46f44d22000-12-10 01:57:30 +0000604 int status;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000605 int errorFlag=FALSE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000606 int skipNextHeaderFlag=FALSE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000607 TarHeader rawHeader;
608 TarInfo header;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000609
Erik Andersene49d5ec2000-02-08 19:58:47 +0000610 /* Set the umask for this process so it doesn't
Erik Andersen1ad302a2000-03-24 00:54:46 +0000611 * screw up permission setting for us later. */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000612 umask(0);
Eric Andersencc8ed391999-10-05 16:24:54 +0000613
Erik Andersen1ad302a2000-03-24 00:54:46 +0000614 /* Read the tar file, and iterate over it one file at a time */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000615 while ( (status = full_read(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
Erik Andersene2729152000-02-18 21:34:17 +0000616
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000617 /* Try to read the header */
Erik Andersen3364d782000-03-28 00:58:14 +0000618 if ( readTarHeader(&rawHeader, &header) == FALSE ) {
Erik Andersen1ad302a2000-03-24 00:54:46 +0000619 if ( *(header.name) == '\0' ) {
620 goto endgame;
621 } else {
622 errorFlag=TRUE;
Matt Kraaidd19c692001-01-31 19:00:21 +0000623 error_msg("Bad tar header, skipping");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000624 continue;
625 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000626 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000627 if ( *(header.name) == '\0' )
628 goto endgame;
Erik Andersen0817d132000-04-09 15:17:40 +0000629 header.tarFd = tarFd;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000630
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000631 /* Skip funky extra GNU headers that precede long files */
632 if ( (header.type == GNULONGNAME) || (header.type == GNULONGLINK) ) {
633 skipNextHeaderFlag=TRUE;
Matt Kraaiab8f9e22000-11-18 01:28:57 +0000634 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
635 errorFlag = TRUE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000636 continue;
637 }
638 if ( skipNextHeaderFlag == TRUE ) {
639 skipNextHeaderFlag=FALSE;
Mark Whitleyf57c9442000-12-07 19:56:48 +0000640 error_msg(name_longer_than_foo, NAME_SIZE);
Matt Kraaiab8f9e22000-11-18 01:28:57 +0000641 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
642 errorFlag = TRUE;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000643 continue;
644 }
645
Erik Andersen0817d132000-04-09 15:17:40 +0000646#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraaibe7499c2001-01-03 17:22:10 +0000647 if (exclude_file(excludeList, header.name)) {
Erik Andersen0817d132000-04-09 15:17:40 +0000648 /* There are not the droids you're looking for, move along */
Matt Kraaibe7499c2001-01-03 17:22:10 +0000649 /* If it is a regular file, pretend to extract it with
650 * the extractFlag set to FALSE, so the junk in the tarball
651 * is properly skipped over */
652 if ( header.type==REGTYPE || header.type==REGTYPE0 ) {
653 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
654 errorFlag = TRUE;
655 }
656 continue;
Erik Andersen0817d132000-04-09 15:17:40 +0000657 }
658#endif
Matt Kraaibe7499c2001-01-03 17:22:10 +0000659
Matt Kraai8f8dab92001-01-22 05:25:19 +0000660 if (!extract_file(extractList, header.name)) {
Matt Kraaib92223b2000-09-04 08:25:42 +0000661 /* There are not the droids you're looking for, move along */
Matt Kraai8f8dab92001-01-22 05:25:19 +0000662 /* If it is a regular file, pretend to extract it with
663 * the extractFlag set to FALSE, so the junk in the tarball
664 * is properly skipped over */
665 if ( header.type==REGTYPE || header.type==REGTYPE0 ) {
666 if (tarExtractRegularFile(&header, FALSE, FALSE) == FALSE)
667 errorFlag = TRUE;
Matt Kraaib92223b2000-09-04 08:25:42 +0000668 }
Matt Kraai8f8dab92001-01-22 05:25:19 +0000669 continue;
Matt Kraaib92223b2000-09-04 08:25:42 +0000670 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000671
Matt Kraai82cfbad2000-09-15 21:18:43 +0000672 if (listFlag == TRUE) {
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000673 /* Special treatment if the list (-t) flag is on */
674 if (verboseFlag == TRUE) {
675 int len, len1;
676 char buf[35];
677 struct tm *tm = localtime (&(header.mtime));
678
Mark Whitleyf57c9442000-12-07 19:56:48 +0000679 len=printf("%s ", mode_string(header.mode));
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000680 my_getpwuid(buf, header.uid);
681 if (! *buf)
682 len+=printf("%d", header.uid);
683 else
684 len+=printf("%s", buf);
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000685 my_getgrgid(buf, header.gid);
686 if (! *buf)
687 len+=printf("/%-d ", header.gid);
688 else
689 len+=printf("/%-s ", buf);
690
691 if (header.type==CHRTYPE || header.type==BLKTYPE) {
692 len1=snprintf(buf, sizeof(buf), "%ld,%-ld ",
693 header.devmajor, header.devminor);
694 } else {
695 len1=snprintf(buf, sizeof(buf), "%lu ", (long)header.size);
696 }
697 /* Jump through some hoops to make the columns match up */
698 for(;(len+len1)<31;len++)
699 printf(" ");
700 printf(buf);
701
702 /* Use ISO 8610 time format */
703 if (tm) {
704 printf ("%04d-%02d-%02d %02d:%02d:%02d ",
705 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
706 tm->tm_hour, tm->tm_min, tm->tm_sec);
707 }
708 }
Eric Andersenfdd51032000-08-02 18:48:26 +0000709 printf("%s", header.name);
Matt Kraai82cfbad2000-09-15 21:18:43 +0000710 if (verboseFlag == TRUE) {
711 if (header.type==LNKTYPE) /* If this is a link, say so */
712 printf(" link to %s", header.linkname);
713 else if (header.type==SYMTYPE)
714 printf(" -> %s", header.linkname);
715 }
Erik Andersen1ad302a2000-03-24 00:54:46 +0000716 printf("\n");
717 }
718
Matt Kraai6fc2a7d2000-09-15 22:23:41 +0000719 /* List contents if we are supposed to do that */
720 if (verboseFlag == TRUE && extractFlag == TRUE) {
721 /* Now the normal listing */
722 FILE *vbFd = stdout;
723 if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr
724 vbFd = stderr;
725 fprintf(vbFd, "%s\n", header.name);
726 }
727
Matt Kraaif4462972000-09-01 02:50:48 +0000728 /* Remove files if we would overwrite them */
Matt Kraaida542f32000-09-01 02:53:01 +0000729 if (extractFlag == TRUE && tostdoutFlag == FALSE)
Matt Kraaif4462972000-09-01 02:50:48 +0000730 unlink(header.name);
Eric Andersencc8ed391999-10-05 16:24:54 +0000731
Erik Andersen1ad302a2000-03-24 00:54:46 +0000732 /* If we got here, we can be certain we have a legitimate
733 * header to work with. So work with it. */
734 switch ( header.type ) {
735 case REGTYPE:
736 case REGTYPE0:
737 /* If the name ends in a '/' then assume it is
738 * supposed to be a directory, and fall through */
739 if (header.name[strlen(header.name)-1] != '/') {
Erik Andersen6a34b532000-04-07 06:55:38 +0000740 if (tarExtractRegularFile(&header, extractFlag, tostdoutFlag)==FALSE)
741 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000742 break;
743 }
744 case DIRTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000745 if (tarExtractDirectory( &header, extractFlag, tostdoutFlag)==FALSE)
746 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000747 break;
748 case LNKTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000749 if (tarExtractHardLink( &header, extractFlag, tostdoutFlag)==FALSE)
750 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000751 break;
752 case SYMTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000753 if (tarExtractSymLink( &header, extractFlag, tostdoutFlag)==FALSE)
754 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000755 break;
756 case CHRTYPE:
757 case BLKTYPE:
758 case FIFOTYPE:
Erik Andersen6a34b532000-04-07 06:55:38 +0000759 if (tarExtractSpecial( &header, extractFlag, tostdoutFlag)==FALSE)
760 errorFlag=TRUE;
Erik Andersen1ad302a2000-03-24 00:54:46 +0000761 break;
Eric Andersen1b1cfde2000-09-24 00:54:37 +0000762#if 0
763 /* Handled earlier */
764 case GNULONGNAME:
765 case GNULONGLINK:
766 skipNextHeaderFlag=TRUE;
767 break;
768#endif
Erik Andersen1ad302a2000-03-24 00:54:46 +0000769 default:
Matt Kraaidd19c692001-01-31 19:00:21 +0000770 error_msg("Unknown file type '%c' in tar file", header.type);
Erik Andersen1ad302a2000-03-24 00:54:46 +0000771 close( tarFd);
772 return( FALSE);
773 }
774 }
775 close(tarFd);
776 if (status > 0) {
777 /* Bummer - we read a partial header */
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000778 perror_msg("Error reading tar file");
Erik Andersen1ad302a2000-03-24 00:54:46 +0000779 return ( FALSE);
780 }
Erik Andersen6a34b532000-04-07 06:55:38 +0000781 else if (errorFlag==TRUE) {
Matt Kraaidd19c692001-01-31 19:00:21 +0000782 error_msg( "Error exit delayed from previous errors");
Erik Andersen6a34b532000-04-07 06:55:38 +0000783 return( FALSE);
784 } else
Erik Andersen1ad302a2000-03-24 00:54:46 +0000785 return( status);
786
787 /* Stuff to do when we are done */
788endgame:
789 close( tarFd);
790 if ( *(header.name) == '\0' ) {
Erik Andersen6a34b532000-04-07 06:55:38 +0000791 if (errorFlag==TRUE)
Matt Kraaidd19c692001-01-31 19:00:21 +0000792 error_msg( "Error exit delayed from previous errors");
Erik Andersen6a34b532000-04-07 06:55:38 +0000793 else
Erik Andersen1ad302a2000-03-24 00:54:46 +0000794 return( TRUE);
795 }
796 return( FALSE);
797}
798
Erik Andersen6acaa402000-03-26 14:03:20 +0000799
800#ifdef BB_FEATURE_TAR_CREATE
801
Eric Andersen3d957c82000-12-07 00:34:58 +0000802/*
803** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
804** the only functions that deal with the HardLinkInfo structure.
805** Even these functions use the xxxHardLinkInfo() functions.
806*/
807typedef struct HardLinkInfo HardLinkInfo;
808struct HardLinkInfo
809{
810 HardLinkInfo *next; /* Next entry in list */
811 dev_t dev; /* Device number */
812 ino_t ino; /* Inode number */
813 short linkCount; /* (Hard) Link Count */
814 char name[1]; /* Start of filename (must be last) */
815};
816
Erik Andersen68a9ea42000-04-04 18:39:50 +0000817/* Some info to be carried along when creating a new tarball */
818struct TarBallInfo
819{
820 char* fileName; /* File name of the tarball */
821 int tarFd; /* Open-for-write file descriptor
822 for the tarball */
823 struct stat statBuf; /* Stat info for the tarball, letting
824 us know the inode and device that the
825 tarball lives, so we can avoid trying
826 to include the tarball into itself */
827 int verboseFlag; /* Whether to print extra stuff or not */
Erik Andersenecd51242000-04-08 03:08:21 +0000828 char** excludeList; /* List of files to not include */
Eric Andersen3d957c82000-12-07 00:34:58 +0000829 HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
830 HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
Erik Andersen68a9ea42000-04-04 18:39:50 +0000831};
832typedef struct TarBallInfo TarBallInfo;
833
834
Eric Andersen3d957c82000-12-07 00:34:58 +0000835/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
836static void
837addHardLinkInfo (HardLinkInfo **hlInfoHeadPtr, dev_t dev, ino_t ino,
838 short linkCount, const char *name)
839{
840 /* Note: hlInfoHeadPtr can never be NULL! */
841 HardLinkInfo *hlInfo;
842
843 hlInfo = (HardLinkInfo *)xmalloc(sizeof(HardLinkInfo)+strlen(name)+1);
844 if (hlInfo) {
845 hlInfo->next = *hlInfoHeadPtr;
846 *hlInfoHeadPtr = hlInfo;
847 hlInfo->dev = dev;
848 hlInfo->ino = ino;
849 hlInfo->linkCount = linkCount;
850 strcpy(hlInfo->name, name);
851 }
852 return;
853}
854
855static void
856freeHardLinkInfo (HardLinkInfo **hlInfoHeadPtr)
857{
858 HardLinkInfo *hlInfo = NULL;
859 HardLinkInfo *hlInfoNext = NULL;
860
861 if (hlInfoHeadPtr) {
862 hlInfo = *hlInfoHeadPtr;
863 while (hlInfo) {
864 hlInfoNext = hlInfo->next;
865 free(hlInfo);
866 hlInfo = hlInfoNext;
867 }
868 *hlInfoHeadPtr = NULL;
869 }
870 return;
871}
872
873/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
874static HardLinkInfo *
875findHardLinkInfo (HardLinkInfo *hlInfo, dev_t dev, ino_t ino)
876{
877 while(hlInfo) {
878 if ((ino == hlInfo->ino) && (dev == hlInfo->dev))
879 break;
880 hlInfo = hlInfo->next;
881 }
882 return(hlInfo);
883}
884
Erik Andersen6acaa402000-03-26 14:03:20 +0000885/* Put an octal string into the specified buffer.
886 * The number is zero and space padded and possibly null padded.
887 * Returns TRUE if successful. */
888static int putOctal (char *cp, int len, long value)
889{
890 int tempLength;
Erik Andersen6acaa402000-03-26 14:03:20 +0000891 char tempBuffer[32];
Erik Andersen5661fe02000-04-05 01:00:52 +0000892 char *tempString = tempBuffer;
Erik Andersen6acaa402000-03-26 14:03:20 +0000893
894 /* Create a string of the specified length with an initial space,
895 * leading zeroes and the octal number, and a trailing null. */
Erik Andersen5661fe02000-04-05 01:00:52 +0000896 sprintf (tempString, "%0*lo", len - 1, value);
Erik Andersen6acaa402000-03-26 14:03:20 +0000897
898 /* If the string is too large, suppress the leading space. */
Erik Andersen5661fe02000-04-05 01:00:52 +0000899 tempLength = strlen (tempString) + 1;
Erik Andersen6acaa402000-03-26 14:03:20 +0000900 if (tempLength > len) {
901 tempLength--;
902 tempString++;
903 }
904
905 /* If the string is still too large, suppress the trailing null. */
906 if (tempLength > len)
907 tempLength--;
908
909 /* If the string is still too large, fail. */
910 if (tempLength > len)
911 return FALSE;
912
913 /* Copy the string to the field. */
914 memcpy (cp, tempString, len);
915
916 return TRUE;
917}
918
Erik Andersen68a9ea42000-04-04 18:39:50 +0000919/* Write out a tar header for the specified file/directory/whatever */
Erik Andersen3364d782000-03-28 00:58:14 +0000920static int
Matt Kraaie80a2632000-12-19 20:45:49 +0000921writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
922 const char *real_name, struct stat *statbuf)
Erik Andersen6acaa402000-03-26 14:03:20 +0000923{
Erik Andersen5661fe02000-04-05 01:00:52 +0000924 long chksum=0;
925 struct TarHeader header;
926 const unsigned char *cp = (const unsigned char *) &header;
927 ssize_t size = sizeof(struct TarHeader);
Eric Andersenfdd51032000-08-02 18:48:26 +0000928
Erik Andersen5661fe02000-04-05 01:00:52 +0000929 memset( &header, 0, size);
Erik Andersen3364d782000-03-28 00:58:14 +0000930
Matt Kraaie80a2632000-12-19 20:45:49 +0000931 strncpy(header.name, header_name, sizeof(header.name));
Erik Andersenecd51242000-04-08 03:08:21 +0000932
Erik Andersen5661fe02000-04-05 01:00:52 +0000933 putOctal(header.mode, sizeof(header.mode), statbuf->st_mode);
934 putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
935 putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
936 putOctal(header.size, sizeof(header.size), 0); /* Regular file size is handled later */
937 putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
938 strncpy(header.magic, TAR_MAGIC TAR_VERSION,
939 TAR_MAGIC_LEN + TAR_VERSION_LEN );
Erik Andersen68a9ea42000-04-04 18:39:50 +0000940
Erik Andersen84e09e42000-04-08 20:58:35 +0000941 /* Enter the user and group names (default to root if it fails) */
Erik Andersen5661fe02000-04-05 01:00:52 +0000942 my_getpwuid(header.uname, statbuf->st_uid);
Erik Andersen5661fe02000-04-05 01:00:52 +0000943 if (! *header.uname)
Erik Andersen84e09e42000-04-08 20:58:35 +0000944 strcpy(header.uname, "root");
Erik Andersen5661fe02000-04-05 01:00:52 +0000945 my_getgrgid(header.gname, statbuf->st_gid);
946 if (! *header.uname)
Erik Andersen84e09e42000-04-08 20:58:35 +0000947 strcpy(header.uname, "root");
Erik Andersen5661fe02000-04-05 01:00:52 +0000948
Eric Andersen3d957c82000-12-07 00:34:58 +0000949 if (tbInfo->hlInfo) {
950 /* This is a hard link */
951 header.typeflag = LNKTYPE;
952 strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
953 } else if (S_ISLNK(statbuf->st_mode)) {
Eric Andersen3adffb72000-06-26 10:54:06 +0000954 int link_size=0;
Erik Andersen5661fe02000-04-05 01:00:52 +0000955 char buffer[BUFSIZ];
956 header.typeflag = SYMTYPE;
Matt Kraaie80a2632000-12-19 20:45:49 +0000957 link_size = readlink(real_name, buffer, sizeof(buffer) - 1);
Eric Andersen3adffb72000-06-26 10:54:06 +0000958 if ( link_size < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +0000959 perror_msg("Error reading symlink '%s'", header.name);
Erik Andersen5661fe02000-04-05 01:00:52 +0000960 return ( FALSE);
961 }
Eric Andersen3adffb72000-06-26 10:54:06 +0000962 buffer[link_size] = '\0';
Erik Andersen95c1c1e2000-04-14 21:45:29 +0000963 strncpy(header.linkname, buffer, sizeof(header.linkname));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000964 } else if (S_ISDIR(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000965 header.typeflag = DIRTYPE;
966 strncat(header.name, "/", sizeof(header.name));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000967 } else if (S_ISCHR(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000968 header.typeflag = CHRTYPE;
969 putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
970 putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000971 } else if (S_ISBLK(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000972 header.typeflag = BLKTYPE;
973 putOctal(header.devmajor, sizeof(header.devmajor), MAJOR(statbuf->st_rdev));
974 putOctal(header.devminor, sizeof(header.devminor), MINOR(statbuf->st_rdev));
Erik Andersen68a9ea42000-04-04 18:39:50 +0000975 } else if (S_ISFIFO(statbuf->st_mode)) {
Erik Andersen5661fe02000-04-05 01:00:52 +0000976 header.typeflag = FIFOTYPE;
977 } else if (S_ISREG(statbuf->st_mode)) {
978 header.typeflag = REGTYPE;
979 putOctal(header.size, sizeof(header.size), statbuf->st_size);
Erik Andersen68a9ea42000-04-04 18:39:50 +0000980 } else {
Matt Kraaidd19c692001-01-31 19:00:21 +0000981 error_msg("%s: Unknown file type", real_name);
Erik Andersen68a9ea42000-04-04 18:39:50 +0000982 return ( FALSE);
983 }
Erik Andersen68a9ea42000-04-04 18:39:50 +0000984
Erik Andersen5661fe02000-04-05 01:00:52 +0000985 /* Calculate and store the checksum (i.e. the sum of all of the bytes of
986 * the header). The checksum field must be filled with blanks for the
987 * calculation. The checksum field is formatted differently from the
988 * other fields: it has [6] digits, a null, then a space -- rather than
989 * digits, followed by a null like the other fields... */
990 memset(header.chksum, ' ', sizeof(header.chksum));
991 cp = (const unsigned char *) &header;
992 while (size-- > 0)
993 chksum += *cp++;
994 putOctal(header.chksum, 7, chksum);
995
996 /* Now write the header out to disk */
Mark Whitleyf57c9442000-12-07 19:56:48 +0000997 if ((size=full_write(tbInfo->tarFd, (char*)&header, sizeof(struct TarHeader))) < 0) {
Matt Kraaie80a2632000-12-19 20:45:49 +0000998 error_msg(io_error, real_name, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +0000999 return ( FALSE);
1000 }
1001 /* Pad the header up to the tar block size */
1002 for (; size<TAR_BLOCK_SIZE; size++) {
1003 write(tbInfo->tarFd, "\0", 1);
1004 }
1005 /* Now do the verbose thing (or not) */
Eric Andersenfdd51032000-08-02 18:48:26 +00001006 if (tbInfo->verboseFlag==TRUE) {
1007 FILE *vbFd = stdout;
1008 if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr
1009 vbFd = stderr;
1010 fprintf(vbFd, "%s\n", header.name);
1011 }
Erik Andersen3364d782000-03-28 00:58:14 +00001012
1013 return ( TRUE);
1014}
1015
1016
Erik Andersen68a9ea42000-04-04 18:39:50 +00001017static int writeFileToTarball(const char *fileName, struct stat *statbuf, void* userData)
Erik Andersen3364d782000-03-28 00:58:14 +00001018{
Erik Andersen68a9ea42000-04-04 18:39:50 +00001019 struct TarBallInfo *tbInfo = (struct TarBallInfo *)userData;
Matt Kraaie80a2632000-12-19 20:45:49 +00001020 const char *header_name;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001021
Eric Andersen3d957c82000-12-07 00:34:58 +00001022 /*
1023 ** Check to see if we are dealing with a hard link.
1024 ** If so -
1025 ** Treat the first occurance of a given dev/inode as a file while
1026 ** treating any additional occurances as hard links. This is done
1027 ** by adding the file information to the HardLinkInfo linked list.
1028 */
1029 tbInfo->hlInfo = NULL;
1030 if (statbuf->st_nlink > 1) {
1031 tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf->st_dev,
1032 statbuf->st_ino);
1033 if (tbInfo->hlInfo == NULL)
1034 addHardLinkInfo (&tbInfo->hlInfoHead, statbuf->st_dev,
1035 statbuf->st_ino, statbuf->st_nlink, fileName);
1036 }
1037
Erik Andersen68a9ea42000-04-04 18:39:50 +00001038 /* It is against the rules to archive a socket */
1039 if (S_ISSOCK(statbuf->st_mode)) {
Matt Kraaidd19c692001-01-31 19:00:21 +00001040 error_msg("%s: socket ignored", fileName);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001041 return( TRUE);
1042 }
1043
1044 /* It is a bad idea to store the archive we are in the process of creating,
1045 * so check the device and inode to be sure that this particular file isn't
1046 * the new tarball */
1047 if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
1048 tbInfo->statBuf.st_ino == statbuf->st_ino) {
Matt Kraaidd19c692001-01-31 19:00:21 +00001049 error_msg("%s: file is the archive; skipping", fileName);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001050 return( TRUE);
1051 }
1052
Matt Kraaie80a2632000-12-19 20:45:49 +00001053 header_name = fileName;
1054 while (header_name[0] == '/') {
Matt Kraaia1f97752000-12-19 06:24:08 +00001055 static int alreadyWarned=FALSE;
1056 if (alreadyWarned==FALSE) {
Matt Kraaidd19c692001-01-31 19:00:21 +00001057 error_msg("Removing leading '/' from member names");
Matt Kraaia1f97752000-12-19 06:24:08 +00001058 alreadyWarned=TRUE;
1059 }
Matt Kraaie80a2632000-12-19 20:45:49 +00001060 header_name++;
Matt Kraaia1f97752000-12-19 06:24:08 +00001061 }
1062
Eric Andersen1b1cfde2000-09-24 00:54:37 +00001063 if (strlen(fileName) >= NAME_SIZE) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001064 error_msg(name_longer_than_foo, NAME_SIZE);
Eric Andersen1b1cfde2000-09-24 00:54:37 +00001065 return ( TRUE);
1066 }
1067
Matt Kraaie80a2632000-12-19 20:45:49 +00001068 if (header_name[0] == '\0')
Matt Kraaia1f97752000-12-19 06:24:08 +00001069 return TRUE;
1070
1071#if defined BB_FEATURE_TAR_EXCLUDE
Matt Kraaibe7499c2001-01-03 17:22:10 +00001072 if (exclude_file(tbInfo->excludeList, header_name)) {
1073 return SKIP;
Matt Kraaia1f97752000-12-19 06:24:08 +00001074 }
1075#endif
1076
Matt Kraaie80a2632000-12-19 20:45:49 +00001077 if (writeTarHeader(tbInfo, header_name, fileName, statbuf)==FALSE) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001078 return( FALSE);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001079 }
Erik Andersen5661fe02000-04-05 01:00:52 +00001080
1081 /* Now, if the file is a regular file, copy it out to the tarball */
Eric Andersen3d957c82000-12-07 00:34:58 +00001082 if ((tbInfo->hlInfo == NULL)
1083 && (S_ISREG(statbuf->st_mode))) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001084 int inputFileFd;
1085 char buffer[BUFSIZ];
1086 ssize_t size=0, readSize=0;
1087
1088 /* open the file we want to archive, and make sure all is well */
1089 if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
Matt Kraaidd19c692001-01-31 19:00:21 +00001090 error_msg("%s: Cannot open: %s", fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001091 return( FALSE);
1092 }
1093
1094 /* write the file to the archive */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001095 while ( (size = full_read(inputFileFd, buffer, sizeof(buffer))) > 0 ) {
1096 if (full_write(tbInfo->tarFd, buffer, size) != size ) {
Erik Andersen5661fe02000-04-05 01:00:52 +00001097 /* Output file seems to have a problem */
Mark Whitleyf57c9442000-12-07 19:56:48 +00001098 error_msg(io_error, fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001099 return( FALSE);
1100 }
1101 readSize+=size;
1102 }
1103 if (size == -1) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001104 error_msg(io_error, fileName, strerror(errno));
Erik Andersen5661fe02000-04-05 01:00:52 +00001105 return( FALSE);
1106 }
1107 /* Pad the file up to the tar block size */
1108 for (; (readSize%TAR_BLOCK_SIZE) != 0; readSize++) {
1109 write(tbInfo->tarFd, "\0", 1);
1110 }
1111 close( inputFileFd);
1112 }
Erik Andersen68a9ea42000-04-04 18:39:50 +00001113
1114 return( TRUE);
Erik Andersen6acaa402000-03-26 14:03:20 +00001115}
1116
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001117static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
1118 char** excludeList)
Erik Andersen6acaa402000-03-26 14:03:20 +00001119{
Erik Andersen3364d782000-03-28 00:58:14 +00001120 int tarFd=-1;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001121 int errorFlag=FALSE;
Erik Andersen5661fe02000-04-05 01:00:52 +00001122 ssize_t size;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001123 struct TarBallInfo tbInfo;
1124 tbInfo.verboseFlag = verboseFlag;
Eric Andersen3d957c82000-12-07 00:34:58 +00001125 tbInfo.hlInfoHead = NULL;
Erik Andersen3364d782000-03-28 00:58:14 +00001126
1127 /* Make sure there is at least one file to tar up. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001128 if (*argv == NULL)
Matt Kraaidd19c692001-01-31 19:00:21 +00001129 error_msg_and_die("Cowardly refusing to create an empty archive");
Erik Andersen6acaa402000-03-26 14:03:20 +00001130
1131 /* Open the tar file for writing. */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001132 if (!strcmp(tarName, "-"))
Erik Andersen68a9ea42000-04-04 18:39:50 +00001133 tbInfo.tarFd = fileno(stdout);
Erik Andersen6acaa402000-03-26 14:03:20 +00001134 else
Erik Andersen68a9ea42000-04-04 18:39:50 +00001135 tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1136 if (tbInfo.tarFd < 0) {
Matt Kraai1fa1ade2000-12-18 03:57:16 +00001137 perror_msg( "Error opening '%s'", tarName);
Eric Andersen3d957c82000-12-07 00:34:58 +00001138 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen6acaa402000-03-26 14:03:20 +00001139 return ( FALSE);
1140 }
Erik Andersenecd51242000-04-08 03:08:21 +00001141 tbInfo.excludeList=excludeList;
Erik Andersen68a9ea42000-04-04 18:39:50 +00001142 /* Store the stat info for the tarball's file, so
1143 * can avoid including the tarball into itself.... */
1144 if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
Mark Whitleyf57c9442000-12-07 19:56:48 +00001145 error_msg_and_die(io_error, tarName, strerror(errno));
Erik Andersen6acaa402000-03-26 14:03:20 +00001146
1147 /* Set the umask for this process so it doesn't
1148 * screw up permission setting for us later. */
1149 umask(0);
1150
1151 /* Read the directory/files and iterate over them one at a time */
Matt Kraaid8ad76c2000-11-08 02:35:47 +00001152 while (*argv != NULL) {
Mark Whitleyf57c9442000-12-07 19:56:48 +00001153 if (recursive_action(*argv++, TRUE, FALSE, FALSE,
Erik Andersen68a9ea42000-04-04 18:39:50 +00001154 writeFileToTarball, writeFileToTarball,
1155 (void*) &tbInfo) == FALSE) {
1156 errorFlag = TRUE;
Erik Andersen3364d782000-03-28 00:58:14 +00001157 }
Erik Andersen6acaa402000-03-26 14:03:20 +00001158 }
Erik Andersen5661fe02000-04-05 01:00:52 +00001159 /* Write two empty blocks to the end of the archive */
1160 for (size=0; size<(2*TAR_BLOCK_SIZE); size++) {
1161 write(tbInfo.tarFd, "\0", 1);
1162 }
Erik Andersen0817d132000-04-09 15:17:40 +00001163
1164 /* To be pedantically correct, we would check if the tarball
Eric Andersen3c5ee9a2000-11-14 22:15:48 +00001165 * is smaller than 20 tar blocks, and pad it if it was smaller,
Erik Andersen0817d132000-04-09 15:17:40 +00001166 * but that isn't necessary for GNU tar interoperability, and
1167 * so is considered a waste of space */
1168
Erik Andersen68a9ea42000-04-04 18:39:50 +00001169 /* Hang up the tools, close up shop, head home */
Erik Andersen6acaa402000-03-26 14:03:20 +00001170 close(tarFd);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001171 if (errorFlag == TRUE) {
Matt Kraaidd19c692001-01-31 19:00:21 +00001172 error_msg("Error exit delayed from previous errors");
Eric Andersen3d957c82000-12-07 00:34:58 +00001173 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen68a9ea42000-04-04 18:39:50 +00001174 return(FALSE);
1175 }
Eric Andersen3d957c82000-12-07 00:34:58 +00001176 freeHardLinkInfo(&tbInfo.hlInfoHead);
Erik Andersen6acaa402000-03-26 14:03:20 +00001177 return( TRUE);
1178}
1179
1180
1181#endif
1182