From: Stelian Pop Date: Mon, 29 Jul 2002 12:00:30 +0000 (+0000) Subject: Fix rmtopen() extended format... X-Git-Tag: release_0_4b31~2 X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=commitdiff_plain;h=ba3af39e8b08027d3338b5533bddc86a9c803a74 Fix rmtopen() extended format... --- diff --git a/CHANGES b/CHANGES index 0527157..2ba427c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,11 @@ -$Id: CHANGES,v 1.189 2002/07/25 09:56:47 stelian Exp $ +$Id: CHANGES,v 1.190 2002/07/29 12:00:30 stelian Exp $ + +Changes between versions 0.4b30 and 0.4b31 (released ?????????????) +=================================================================== + +1. Fixed rmt open flags transmission (GNU's symbolic syntax over + rmt) which I broke in 0.4b29. Thanks to Eros Albertazzi + for reporting the bug. Changes between versions 0.4b29 and 0.4b30 (released July 25, 2002) =================================================================== diff --git a/common/dumprmt.c b/common/dumprmt.c index 69ada17..f89a13d 100644 --- a/common/dumprmt.c +++ b/common/dumprmt.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: dumprmt.c,v 1.22 2002/07/19 14:57:39 stelian Exp $"; + "$Id: dumprmt.c,v 1.23 2002/07/29 12:00:33 stelian Exp $"; #endif /* not lint */ #include @@ -49,6 +49,7 @@ static const char rcsid[] = #include #include #include +#include #ifdef __linux__ #include #ifdef HAVE_EXT2FS_EXT2_FS_H @@ -76,6 +77,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -273,11 +275,17 @@ okname(const char *cp0) } int -rmtopen(const char *tape, const char *mode) +rmtopen(const char *tape, const int mode) { char buf[MAXPATHLEN]; - - (void)snprintf(buf, sizeof (buf), "O%s\n%s\n", tape, mode); + char *rmtflags; + + rmtflags = rmtflags_tochar(mode); + (void)snprintf(buf, sizeof (buf), "O%s\n%d %s\n", + tape, + mode & O_ACCMODE, + rmtflags); + free(rmtflags); rmtstate = TS_OPEN; return (rmtcall(tape, buf)); } diff --git a/compat/include/rmtflags.h b/compat/include/rmtflags.h new file mode 100644 index 0000000..e97d5a0 --- /dev/null +++ b/compat/include/rmtflags.h @@ -0,0 +1,50 @@ +/* + * Ported to Linux's Second Extended File System as part of the + * dump and restore backup suit + * Remy Card , 1994-1997 + * Stelian Pop , 1999-2000 + * Stelian Pop - Alcôve , 2000-2002 + * + * $Id: rmtflags.h,v 1.1 2002/07/29 12:00:33 stelian Exp $ + */ + +/* + * Copyright (c) 1983, 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 _RMTFLAGS_H_ +#define _RMTFLAGS_H_ + +int rmtflags_toint(char *filemode); +char *rmtflags_tochar(int filemode); + +#endif diff --git a/compat/lib/Makefile.in b/compat/lib/Makefile.in index 12d09cb..843828f 100644 --- a/compat/lib/Makefile.in +++ b/compat/lib/Makefile.in @@ -1,4 +1,4 @@ -# $Id: Makefile.in,v 1.5 2001/07/18 12:54:06 stelian Exp $ +# $Id: Makefile.in,v 1.6 2002/07/29 12:00:33 stelian Exp $ top_srcdir= @top_srcdir@ srcdir= @srcdir@ @@ -7,8 +7,8 @@ srcdir= @srcdir@ INC= -I$(top_srcdir)/compat/include CFLAGS= @CCOPTS@ -pipe $(OPT) $(GINC) $(INC) $(DEFS) -SRCS= compaterr.c fstab.c compatglob.c bylabel.c system.c -OBJS= compaterr.o fstab.o compatglob.o bylabel.o system.o +SRCS= compaterr.c fstab.c compatglob.c bylabel.c system.c rmtflags.c +OBJS= compaterr.o fstab.o compatglob.o bylabel.o system.o rmtflags.o LIB= libcompat.a all:: $(LIB) diff --git a/compat/lib/rmtflags.c b/compat/lib/rmtflags.c new file mode 100644 index 0000000..b009ff0 --- /dev/null +++ b/compat/lib/rmtflags.c @@ -0,0 +1,191 @@ +/* + * Ported to Linux's Second Extended File System as part of the + * dump and restore backup suit + * Remy Card , 1994-1997 + * Stelian Pop , 1999-2000 + * Stelian Pop - Alcôve , 2000-2002 + */ + +/* + * Copyright (c) 1983, 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 lint +static const char rcsid[] = + "$Id: rmtflags.c,v 1.1 2002/07/29 12:00:33 stelian Exp $"; +#endif /* not linux */ + +/* + * rmt + */ +#include +#include +#include +#include +#include +#include + +struct openflags { + char *name; + int value; +} openflags[] = { + { "O_RDONLY", O_RDONLY }, + { "O_WRONLY", O_WRONLY }, + { "O_RDWR", O_RDWR }, +#ifdef O_CREAT + { "O_CREAT", O_CREAT }, +#endif +#ifdef O_EXCL + { "O_EXCL", O_EXCL }, +#endif +#ifdef O_NOCTTY + { "O_NOCTTY", O_NOCTTY }, +#endif +#ifdef O_TRUNC + { "O_TRUNC", O_TRUNC }, +#endif +#ifdef O_APPEND + { "O_APPEND", O_APPEND }, +#endif +#ifdef O_NONBLOCK + { "O_NONBLOCK", O_NONBLOCK }, +#endif +#ifdef O_NDELAY + { "O_NDELAY", O_NDELAY }, +#endif +#ifdef O_SYNC + { "O_SYNC", O_SYNC }, +#endif +#ifdef O_FSYNC + { "O_FSYNC", O_FSYNC }, +#endif +#ifdef O_ASYNC + { "O_ASYNC", O_ASYNC }, +#endif +#ifdef O_TEXT + { "O_TEXT", O_TEXT }, +#endif +#ifdef O_DSYNC + { "O_DSYNC", O_DSYNC }, +#endif +#ifdef O_RSYNC + { "O_RSYNC", O_RSYNC }, +#endif +#ifdef O_PRIV + { "O_PRIV", O_PRIV }, +#endif +#ifdef O_LARGEFILE + { "O_LARGEFILE",O_LARGEFILE }, +#endif + { NULL, 0 } +}; + +/* Parts of this stolen again from Jörg Schilling's star package... */ +int +rmtflags_toint(char *filemode) +{ + char *p = filemode; + struct openflags *op; + int result = 0; + int numresult = 0; + int seentext = 0; + + do { + /* skip space */ + while (*p != '\0' && *p == ' ') + p++; + /* get O_XXXX constant */ + if (p[0] != 'O' || p[1] != '_') { + /* numeric syntax detected */ + numresult = atoi(filemode); + numresult &= O_RDONLY | O_WRONLY | O_RDWR; + while (*p != ' ' && *p != '\0') + p++; + while (*p != '\0' && *p == ' ') + p++; + } + + if (*p == '\0') + break; + + /* translate O_XXXX constant */ + for (op = openflags; op->name; op++) { + int slen = strlen(op->name); + if ((strncmp(op->name, p, slen) == 0) && + (p[slen] == '|' || p[slen] == ' ' || + p[slen] == '\0')) { + seentext = 1; + result |= op->value; + break; + } + } + + /* goto next constant */ + p = strchr(p, '|'); + } while (p && *p++ == '|'); + + if (!seentext) + result = numresult; + return result; +} + +char * +rmtflags_tochar(int filemode) +{ + struct openflags *op; + char *result = (char *) malloc(4096); /* enough space */ + + switch (filemode & O_ACCMODE) { + case O_RDONLY: + strcpy(result, "O_RDONLY"); + break; + case O_WRONLY: + strcpy(result, "O_WRONLY"); + break; + case O_RDWR: + strcpy(result, "O_RDWR"); + break; + default: + strcat(result, "ERROR"); + } + for (op = openflags; op->name; op++) { + if (op->value == O_RDONLY || + op->value == O_WRONLY || + op->value == O_RDWR) + continue; + if (filemode & op->value) { + strcat(result, "|"); + strcat(result, op->name); + } + } + return result; +} diff --git a/dump/dump.h b/dump/dump.h index e6d8e13..d6bae02 100644 --- a/dump/dump.h +++ b/dump/dump.h @@ -5,7 +5,7 @@ * Stelian Pop , 1999-2000 * Stelian Pop - Alcôve , 2000-2002 * - * $Id: dump.h,v 1.39 2002/06/05 13:29:15 stelian Exp $ + * $Id: dump.h,v 1.40 2002/07/29 12:00:33 stelian Exp $ */ /*- @@ -186,7 +186,7 @@ struct dinode *getino __P((dump_ino_t inum)); /* rdump routines */ #ifdef RDUMP int rmthost __P((const char *host)); -int rmtopen __P((const char *tape, const char *mode)); +int rmtopen __P((const char *tape, const int mode)); void rmtclose __P((void)); int rmtread __P((char *buf, size_t count)); int rmtwrite __P((const char *buf, size_t count)); diff --git a/dump/tape.c b/dump/tape.c index 70c1d1d..08c6f79 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.70 2002/07/19 14:57:39 stelian Exp $"; + "$Id: tape.c,v 1.71 2002/07/29 12:00:33 stelian Exp $"; #endif /* not lint */ #include @@ -546,7 +546,7 @@ trewind(void) #ifdef RDUMP if (host) { rmtclose(); - while (rmtopen(tape, "O_RDONLY") < 0) + while (rmtopen(tape, O_RDONLY) < 0) sleep(10); rmtclose(); } @@ -868,7 +868,7 @@ restore_check_point: msg("Dumping volume %d on %s\n", tapeno, tape); } #ifdef RDUMP - while ((tapefd = (host ? rmtopen(tape, "O_WRONLY|O_CREAT|O_TRUNC") : pipeout ? + while ((tapefd = (host ? rmtopen(tape, O_WRONLY|O_CREAT|O_TRUNC) : pipeout ? fileno(stdout) : OPEN(tape, O_WRONLY|O_CREAT|O_TRUNC, 0666))) < 0) #else diff --git a/restore/extern.h b/restore/extern.h index 6046e57..62deb0d 100644 --- a/restore/extern.h +++ b/restore/extern.h @@ -5,7 +5,7 @@ * Stelian Pop , 1999-2000 * Stelian Pop - Alcôve , 2000-2002 * - * $Id: extern.h,v 1.18 2002/05/21 15:48:46 stelian Exp $ + * $Id: extern.h,v 1.19 2002/07/29 12:00:34 stelian Exp $ */ /*- @@ -118,7 +118,7 @@ void xtrnull __P((char *, size_t)); void rmtclose __P((void)); int rmthost __P((const char *)); int rmtioctl __P((int, int)); -int rmtopen __P((const char *, const char *)); +int rmtopen __P((const char *, const int)); int rmtread __P((const char *, int)); int rmtseek __P((int, int)); diff --git a/restore/tape.c b/restore/tape.c index b9d0b02..3195ab5 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -46,7 +46,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.63 2002/07/19 14:57:40 stelian Exp $"; + "$Id: tape.c,v 1.64 2002/07/29 12:00:34 stelian Exp $"; #endif /* not lint */ #include @@ -285,7 +285,7 @@ setup(void) #ifdef RRESTORE if (host) - mt = rmtopen(temptape, "O_RDONLY"); + mt = rmtopen(temptape, O_RDONLY); else #endif if (pipein) @@ -541,7 +541,7 @@ again: } #ifdef RRESTORE if (host) - mt = rmtopen(magtape, "O_RDONLY"); + mt = rmtopen(magtape, O_RDONLY); else #endif mt = OPEN(magtape, O_RDONLY, 0); diff --git a/rmt/Makefile.in b/rmt/Makefile.in index 994239c..fa5ee34 100644 --- a/rmt/Makefile.in +++ b/rmt/Makefile.in @@ -1,4 +1,4 @@ -# $Id: Makefile.in,v 1.6 2002/01/02 10:13:16 stelian Exp $ +# $Id: Makefile.in,v 1.7 2002/07/29 12:00:34 stelian Exp $ top_srcdir= @top_srcdir@ srcdir= @srcdir@ @@ -8,24 +8,19 @@ srcdir= @srcdir@ CFLAGS= @CCOPTS@ -pipe $(OPT) $(GINC) $(INC) $(DEFS) LDFLAGS= @LDOPTS@ @STATIC@ LIBS= $(GLIBS) - -#DEBUG= -DFDEBUG -DTDEBUG -DWRITEDEBUG -#INC= -I../compat/include -#CFLAGS= -pipe $(DEFS) $(DEBUG) $(INC) $(GINC) $(OPT) -#DEPLIBS= ../compat/lib/libcompat.a -#LIBS= $(GLIBS) -L../compat/lib -lcompat +DEPLIBS= ../compat/lib/libcompat.a PROG= rmt SRCS= rmt.c OBJS= rmt.o MAN8= rmt.8 -all:: $(PROG) rmt.8 +all:: $(PROG) $(MAN8) $(PROG): $(OBJS) $(DEPLIBS) - $(CC) $(CFLAGS) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) + $(LD) $(CFLAGS) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) -rmt.8: rmt.8.in +$(MAN8): rmt.8.in sed -e "s|__DATE__|$(DATE)|g" \ -e "s|__VERSION__|$(VERSION)|g" $< > $@ diff --git a/rmt/rmt.c b/rmt/rmt.c index fc8ebce..fc6eb82 100644 --- a/rmt/rmt.c +++ b/rmt/rmt.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: rmt.c,v 1.20 2002/05/21 15:48:46 stelian Exp $"; + "$Id: rmt.c,v 1.21 2002/07/29 12:00:34 stelian Exp $"; #endif /* not linux */ /* @@ -49,6 +49,7 @@ static const char rcsid[] = */ #include #include +#include #include #include #include @@ -117,7 +118,6 @@ static int rmt_version = 0; char *checkbuf __P((char *, int)); void error __P((int)); void getstring __P((char *)); -int getopenflags __P((char *)); int main(int argc, char *argv[]) @@ -150,7 +150,7 @@ top: /* * Translate extended GNU syntax into its numeric platform equivalent */ - oflags = getopenflags(filemode); + oflags = rmtflags_toint(filemode); #ifdef O_TEXT /* * Default to O_BINARY the client may not know that we need it. @@ -458,96 +458,3 @@ error(int num) (void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num)); (void)write(1, resp, strlen(resp)); } - -struct openflags { - char *name; - int value; -} openflags[] = { - { "O_RDONLY", O_RDONLY }, - { "O_WRONLY", O_WRONLY }, - { "O_RDWR", O_RDWR }, -#ifdef O_CREAT - { "O_CREAT", O_CREAT }, -#endif -#ifdef O_EXCL - { "O_EXCL", O_EXCL }, -#endif -#ifdef O_NOCTTY - { "O_NOCTTY", O_NOCTTY }, -#endif -#ifdef O_TRUNC - { "O_TRUNC", O_TRUNC }, -#endif -#ifdef O_APPEND - { "O_APPEND", O_APPEND }, -#endif -#ifdef O_NONBLOCK - { "O_NONBLOCK", O_NONBLOCK }, -#endif -#ifdef O_NDELAY - { "O_NDELAY", O_NDELAY }, -#endif -#ifdef O_SYNC - { "O_SYNC", O_SYNC }, -#endif -#ifdef O_FSYNC - { "O_FSYNC", O_FSYNC }, -#endif -#ifdef O_ASYNC - { "O_ASYNC", O_ASYNC }, -#endif -#ifdef O_TEXT - { "O_TEXT", O_TEXT }, -#endif -#ifdef O_DSYNC - { "O_DSYNC", O_DSYNC }, -#endif -#ifdef O_RSYNC - { "O_RSYNC", O_RSYNC }, -#endif -#ifdef O_PRIV - { "O_PRIV", O_PRIV }, -#endif -#ifdef O_LARGEFILE - { "O_LARGEFILE",O_LARGEFILE }, -#endif - { NULL, 0 } -}; - -/* Parts of this stolen again from Jörg Schilling's star package... */ -int -getopenflags(char *filemode) -{ - char *p = filemode; - struct openflags *op; - int result = 0; - - do { - /* skip space */ - while (*p != '\0' && *p == ' ') - p++; - /* get O_XXXX constant */ - if (p[0] != 'O' || p[1] != '_') { - /* numeric syntax detected */ - result = atoi(filemode); - result &= O_RDONLY | O_WRONLY | O_RDWR; - return result; - } - - /* translate O_XXXX constant */ - for (op = openflags; op->name; op++) { - int slen = strlen(op->name); - if ((strncmp(op->name, p, slen) == 0) && - (p[slen] == '|' || p[slen] == ' ' || - p[slen] == '\0')) { - result |= op->value; - break; - } - } - - /* goto next constant */ - p = strchr(p, '|'); - } while (p && *p++ == '|'); - - return result; -}