From: Stelian Pop Date: Fri, 27 Apr 2001 15:22:47 +0000 (+0000) Subject: LFS fixes (explicit use of open64/etc) X-Git-Tag: release_0_4b22~3 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=95c74f382492999827000f544fcb6844150cda81;p=dump.git LFS fixes (explicit use of open64/etc) --- diff --git a/CHANGES b/CHANGES index c5fb0ca..984575d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -$Id: CHANGES,v 1.112 2001/04/12 13:14:14 stelian Exp $ +$Id: CHANGES,v 1.113 2001/04/27 15:22:47 stelian Exp $ Changes between versions 0.4b21 and 0.4b22 (released ????????????????) ====================================================================== @@ -54,6 +54,11 @@ Changes between versions 0.4b21 and 0.4b22 (released ????????????????) 3 file descriptors per dump process (and there is one dump process per tape). +11. Fixed dump large file system support, by explicit use of + open64/lseek64/etc functions (explicit use needed because + e2fsprogs libraries don't behave well when compiled with + FILE_OFFSET_BITS=64). + Changes between versions 0.4b20 and 0.4b21 (released January 13, 2001) ====================================================================== diff --git a/compat/include/compatlfs.h b/compat/include/compatlfs.h new file mode 100644 index 0000000..fef642d --- /dev/null +++ b/compat/include/compatlfs.h @@ -0,0 +1,66 @@ +/* + * Ported to Linux's Second Extended File System as part of the + * dump and restore backup suit + * Stelian Pop - AlcĂ´ve , 2000 + * + * $Id: compatlfs.h,v 1.1 2001/04/27 15:22:47 stelian Exp $ + */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _COMPATLFS_H_ +#define _COMPATLFS_H_ + +#include + +#ifdef USE_LFS + +#define _LARGEFILE64_SOURCE +#define OPEN open64 +#define LSEEK lseek64 +#define STAT stat64 +#define LSTAT lstat64 +#define FTRUNCATE ftruncate64 + +#else + +#define OPEN open +#define LSEEK lseek +#define STAT stat +#define LSTAT lstat +#define FTRUNCATE ftruncate + +#endif /* USE_LFS */ + +#endif /* !_COMPATLFS_H_ */ diff --git a/compat/lib/bylabel.c b/compat/lib/bylabel.c index 065d529..07f0dd9 100644 --- a/compat/lib/bylabel.c +++ b/compat/lib/bylabel.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -55,11 +56,11 @@ get_label_uuid(const char *device, char **label, char *uuid) { int fd; struct ext2_super_block e2sb; - fd = open(device, O_RDONLY); + fd = OPEN(device, O_RDONLY); if (fd < 0) return 1; - if (lseek(fd, EXT2_SUPER_OFFSET, SEEK_SET) != EXT2_SUPER_OFFSET || + if (LSEEK(fd, EXT2_SUPER_OFFSET, SEEK_SET) != EXT2_SUPER_OFFSET || read(fd, (char *) &e2sb, EXT2_SUPER_SIZE) != EXT2_SUPER_SIZE || ext2magic(e2sb) != EXT2_SUPER_MAGIC) { close(fd); diff --git a/config.h.in b/config.h.in index 311292a..b483fce 100644 --- a/config.h.in +++ b/config.h.in @@ -54,8 +54,8 @@ /* Define this is you want old style F script (no arguments) */ #undef OLD_STYLE_FSCRIPT -/* Define this to 64 if you want Large File System support */ -#undef _FILE_OFFSET_BITS +/* Define this if you want Large File System support */ +#undef USE_LFS /* Define this if you have zlib compression library */ #undef HAVE_ZLIB diff --git a/configure b/configure index b4ce3b2..958ddc7 100755 --- a/configure +++ b/configure @@ -1402,7 +1402,7 @@ if test "${enable_largefile+set}" = set; then if test "$enableval" = "yes" then cat >> confdefs.h <<\EOF -#define _FILE_OFFSET_BITS 64 +#define USE_LFS 1 EOF fi diff --git a/configure.in b/configure.in index b5dd89c..a7b608e 100644 --- a/configure.in +++ b/configure.in @@ -129,7 +129,7 @@ AC_ARG_ENABLE([largefile], [ --enable-largefile enable Large File System support (your glibc needs to support it)], if test "$enableval" = "yes" then - AC_DEFINE(_FILE_OFFSET_BITS,64) + AC_DEFINE(USE_LFS) fi , echo "Not enabling Large File System support" diff --git a/dump.spec b/dump.spec index ef872e9..032ab05 100644 --- a/dump.spec +++ b/dump.spec @@ -1,6 +1,6 @@ %define _sbindir /sbin # XXX --enable-kerberos needs krcmd -%define myoptions --with-binmode=6755 --with-manowner=root --with-mangrp=root --with-manmode=0644 --with-dumpdates="%{_sysconfdir}/dumpdates" --enable-readline +%define myoptions --with-binmode=6755 --with-manowner=root --with-mangrp=root --with-manmode=0644 --with-dumpdates="%{_sysconfdir}/dumpdates" --enable-readline --enable-largefile Summary: Programs for backing up and restoring filesystems. Name: dump diff --git a/dump/main.c b/dump/main.c index 0c89673..82ff7f2 100644 --- a/dump/main.c +++ b/dump/main.c @@ -41,10 +41,11 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.47 2001/04/27 12:23:23 stelian Exp $"; + "$Id: main.c,v 1.48 2001/04/27 15:22:47 stelian Exp $"; #endif /* not lint */ #include +#include #include #include #include @@ -124,7 +125,7 @@ main(int argc, char *argv[]) register int ch; int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1; dump_ino_t maxino; - struct stat statbuf; + struct STAT statbuf; dev_t filedev = 0; #ifdef __linux__ errcode_t retval; @@ -543,7 +544,7 @@ main(int argc, char *argv[]) msg("The ENTIRE dump is aborted.\n"); exit(X_STARTUP); } - if ((diskfd = open(disk, O_RDONLY)) < 0) { + if ((diskfd = OPEN(disk, O_RDONLY)) < 0) { msg("Cannot open %s\n", disk); msg("The ENTIRE dump is aborted.\n"); exit(X_STARTUP); @@ -604,7 +605,7 @@ main(int argc, char *argv[]) nonodump = spcl.c_level < honorlevel; - if (!sizeest) { + if (!sizest) { msg("Label: %s\n", spcl.c_label); if (compressed) @@ -622,7 +623,7 @@ main(int argc, char *argv[]) if (directory[0] == 0) anydirskipped = mapfiles(maxino, &tapesize); else { - if (stat(pathname, &statbuf) == -1) { + if (STAT(pathname, &statbuf) == -1) { msg("File cannot be accessed (%s).\n", pathname); msg("The ENTIRE dump is aborted.\n"); exit(X_STARTUP); @@ -639,7 +640,7 @@ main(int argc, char *argv[]) int anydirskipped2; char *p = *argv; /* check if file is available */ - if (stat(p, &statbuf) == -1) { + if (STAT(p, &statbuf) == -1) { msg("File cannot be accessed (%s).\n", p); msg("The ENTIRE dump is aborted.\n"); exit(X_STARTUP); diff --git a/dump/tape.c b/dump/tape.c index cf1f5fb..1464812 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -41,10 +41,11 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.44 2001/04/24 10:59:12 stelian Exp $"; + "$Id: tape.c,v 1.45 2001/04/27 15:22:47 stelian Exp $"; #endif /* not lint */ #include +#include #include #include #include @@ -547,7 +548,7 @@ trewind(void) #endif { (void) close(tapefd); - while ((f = open(tape, 0)) < 0) + while ((f = OPEN(tape, 0)) < 0) sleep (10); (void) close(f); } @@ -861,10 +862,10 @@ restore_check_point: #ifdef RDUMP while ((tapefd = (host ? rmtopen(tape, 2) : pipeout ? fileno(stdout) : - open(tape, O_WRONLY|O_CREAT, 0666))) < 0) + OPEN(tape, O_WRONLY|O_CREAT, 0666))) < 0) #else while ((tapefd = (pipeout ? fileno(stdout) : - open(tape, O_RDWR|O_CREAT, 0666))) < 0) + OPEN(tape, O_RDWR|O_CREAT, 0666))) < 0) #endif { msg("Cannot open output \"%s\".\n", tape); @@ -1062,7 +1063,7 @@ doslave(int cmd, int slave_number) * Need our own seek pointer. */ (void) close(diskfd); - if ((diskfd = open(disk, O_RDONLY)) < 0) + if ((diskfd = OPEN(disk, O_RDONLY)) < 0) quit("slave couldn't reopen disk: %s\n", strerror(errno)); #ifdef __linux__ ext2fs_close(fs); diff --git a/restore/main.c b/restore/main.c index 09aa8c7..2a261f6 100644 --- a/restore/main.c +++ b/restore/main.c @@ -41,10 +41,11 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.23 2001/04/26 08:59:32 stelian Exp $"; + "$Id: main.c,v 1.24 2001/04/27 15:22:47 stelian Exp $"; #endif /* not lint */ #include +#include #include #include #include @@ -315,14 +316,14 @@ main(int argc, char *argv[]) * Compare contents of tape. */ case 'C': { - struct stat stbuf; + struct STAT stbuf; Vprintf(stdout, "Begin compare restore\n"); compare_ignore_not_found = 0; compare_errors = 0; setup(); printf("filesys = %s\n", filesys); - if (stat(filesys, &stbuf) < 0) + if (STAT(filesys, &stbuf) < 0) err(1, "cannot stat directory %s", filesys); if (chdir(filesys) < 0) err(1, "cannot cd to %s", filesys); diff --git a/restore/tape.c b/restore/tape.c index e5e995d..f5a8d55 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -46,10 +46,11 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.36 2001/04/27 12:23:23 stelian Exp $"; + "$Id: tape.c,v 1.37 2001/04/27 15:22:47 stelian Exp $"; #endif /* not lint */ #include +#include #include #include #include @@ -251,7 +252,7 @@ void setup(void) { int i, j, *ip; - struct stat stbuf; + struct STAT stbuf; struct mtget mt_stat; Vprintf(stdout, "Verify tape and initialize maps\n"); @@ -263,7 +264,7 @@ setup(void) if (pipein) mt = 0; else - mt = open(magtape, O_RDONLY, 0); + mt = OPEN(magtape, O_RDONLY, 0); if (mt < 0) err(1, "%s", magtape); volno = 1; @@ -327,7 +328,7 @@ setup(void) } dumptime = spcl.c_ddate; dumpdate = spcl.c_date; - if (stat(".", &stbuf) < 0) + if (STAT(".", &stbuf) < 0) err(1, "cannot stat ."); if (stbuf.st_blksize > 0 && stbuf.st_blksize < TP_BSIZE ) fssize = TP_BSIZE; @@ -470,7 +471,7 @@ again: mt = rmtopen(magtape, 0); else #endif - mt = open(magtape, O_RDONLY, 0); + mt = OPEN(magtape, O_RDONLY, 0); if (mt == -1) { fprintf(stderr, "Cannot open %s\n", magtape); @@ -738,7 +739,7 @@ extractfile(char *name) } if (uflag) (void)unlink(name); - if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, + if ((ofile = OPEN(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { warn("%s: cannot create file", name); skipfile(); @@ -848,11 +849,15 @@ loop: } if (size > 0) { fprintf(stderr, "Missing blocks at the end of %s, assuming hole\n", curfile.name); - (*skip)(clearedbuf, size); + while (size > 0) { + size_t skp = size > TP_BSIZE ? TP_BSIZE : size; + (*skip)(clearedbuf, skp); + size -= skp; + } last_write_was_hole = 1; } if (last_write_was_hole) { - ftruncate(ofile, origsize); + FTRUNCATE(ofile, origsize); } findinode(&spcl); gettingfile = 0; @@ -880,7 +885,7 @@ static void xtrskip(char *buf, size_t size) { - if (lseek(ofile, (off_t)size, SEEK_CUR) == -1) + if (LSEEK(ofile, (off_t)size, SEEK_CUR) == -1) err(1, "seek error extracting inode %lu, name %s\nlseek", (unsigned long)curfile.ino, curfile.name); } @@ -1038,12 +1043,12 @@ int #else void #endif -cmpfiles(char *tapefile, char *diskfile, struct stat *sbuf_disk) +cmpfiles(char *tapefile, char *diskfile, struct STAT *sbuf_disk) { - struct stat sbuf_tape; + struct STAT sbuf_tape; int fd_tape, fd_disk; - if (stat(tapefile, &sbuf_tape) != 0) { + if (STAT(tapefile, &sbuf_tape) != 0) { panic("Can't lstat tmp file %s: %s\n", tapefile, strerror(errno)); compare_errors = 1; @@ -1061,11 +1066,11 @@ cmpfiles(char *tapefile, char *diskfile, struct stat *sbuf_disk) #endif } - if ((fd_tape = open(tapefile, O_RDONLY)) < 0) { + if ((fd_tape = OPEN(tapefile, O_RDONLY)) < 0) { panic("Can't open %s: %s\n", tapefile, strerror(errno)); compare_errors = 1; } - if ((fd_disk = open(diskfile, O_RDONLY)) < 0) { + if ((fd_disk = OPEN(diskfile, O_RDONLY)) < 0) { close(fd_tape); panic("Can't open %s: %s\n", diskfile, strerror(errno)); compare_errors = 1; @@ -1120,14 +1125,14 @@ void comparefile(char *name) { int mode; - struct stat sb; + struct STAT sb; int r; #if !COMPARE_ONTHEFLY static char *tmpfile = NULL; - struct stat stemp; + struct STAT stemp; #endif - if ((r = lstat(name, &sb)) != 0) { + if ((r = LSTAT(name, &sb)) != 0) { warn("%s: does not exist (%d)", name, r); compare_errors = 1; skipfile(); @@ -1220,7 +1225,7 @@ comparefile(char *name) case IFREG: #if COMPARE_ONTHEFLY - if ((ifile = open(name, O_RDONLY)) < 0) { + if ((ifile = OPEN(name, O_RDONLY)) < 0) { panic("Can't open %s: %s\n", name, strerror(errno)); skipfile(); compare_errors = 1; @@ -1246,11 +1251,11 @@ comparefile(char *name) snprintf(tmpfilename, sizeof(tmpfilename), "%s/restoreCXXXXXX", tmpdir); tmpfile = mktemp(&tmpfilename[0]); } - if ((stat(tmpfile, &stemp) == 0) && (unlink(tmpfile) != 0)) { + if ((STAT(tmpfile, &stemp) == 0) && (unlink(tmpfile) != 0)) { panic("cannot delete tmp file %s: %s\n", tmpfile, strerror(errno)); } - if ((ofile = open(tmpfile, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) { + if ((ofile = OPEN(tmpfile, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) { panic("cannot create file temp file %s: %s\n", name, strerror(errno)); } @@ -1399,7 +1404,7 @@ getmore: seek_failed = (rmtseek(i, 1) < 0); else #endif - seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1); + seek_failed = (LSEEK(mt, i, SEEK_CUR) == (off_t)-1); if (seek_failed) { warn("continuation failed"); diff --git a/rmt/rmt.c b/rmt/rmt.c index 64fc4ab..e23d0a3 100644 --- a/rmt/rmt.c +++ b/rmt/rmt.c @@ -41,13 +41,14 @@ #ifndef lint static const char rcsid[] = - "$Id: rmt.c,v 1.13 2001/03/28 12:59:49 stelian Exp $"; + "$Id: rmt.c,v 1.14 2001/04/27 15:22:47 stelian Exp $"; #endif /* not linux */ /* * rmt */ #include +#include #include #include #include @@ -114,7 +115,7 @@ top: * specify the permission bits; allow rw for everyone, * as modified by the users umask */ - tape = open(device, atoi(filemode), 0666); + tape = OPEN(device, atoi(filemode), 0666); if (tape < 0) goto ioerror; block = 0; @@ -133,7 +134,7 @@ top: getstring(count); getstring(pos); DEBUG2("rmtd: L %s %s\n", count, pos); - rval = lseek(tape, (off_t)atol(count), atoi(pos)); + rval = LSEEK(tape, (off_t)atol(count), atoi(pos)); if (rval < 0) goto ioerror; goto respond;