* 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
+ * 3. 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.
*
#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.24 2003/03/30 15:40:40 stelian Exp $";
#endif /* not linux */
/*
*/
#include <config.h>
#include <compatlfs.h>
+#include <rmtflags.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/mtio.h>
char *checkbuf __P((char *, int));
void error __P((int));
void getstring __P((char *));
-int getopenflags __P((char *));
int
main(int argc, char *argv[])
{
- int rval = 0;
+ OFF_T rval = 0;
char c;
int n, i, cc, oflags;
unsigned long block = 0;
/*
* 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.
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)atoll(count), atoi(pos));
if (rval < 0)
goto ioerror;
goto respond;
rval = read(tape, record, n);
if (rval < 0)
goto ioerror;
- (void)sprintf(resp, "A%d\n", rval);
+ (void)sprintf(resp, "A%lld\n", (long long)rval);
(void)write(1, resp, strlen(resp));
(void)write(1, record, rval);
block += n >> 10;
if (ioctl(tape, MTIOCGET, (char *)&mtget) < 0)
goto ioerror;
rval = sizeof (mtget);
- (void)sprintf(resp, "A%d\n", rval);
+ (void)sprintf(resp, "A%lld\n", (long long)rval);
(void)write(1, resp, strlen(resp));
(void)write(1, (char *)&mtget, sizeof (mtget));
goto top;
exit(3);
}
respond:
- DEBUG1("rmtd: A %d\n", rval);
- (void)sprintf(resp, "A%d\n", rval);
+ DEBUG1("rmtd: A %lld\n", (long long)rval);
+ (void)sprintf(resp, "A%lld\n", (long long)rval);
(void)write(1, resp, strlen(resp));
goto top;
ioerror:
(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;
-}