1 | /* Definitions for communicating with a remote tape drive.
|
---|
2 |
|
---|
3 | Copyright (C) 1988, 1992, 1996, 1997, 2001, 2003, 2004 Free
|
---|
4 | Software Foundation, Inc.
|
---|
5 |
|
---|
6 | This program is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | This program is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | GNU General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with this program; if not, write to the Free Software Foundation,
|
---|
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
---|
19 |
|
---|
20 | extern char *rmt_command;
|
---|
21 | extern char *rmt_dev_name__;
|
---|
22 |
|
---|
23 | int rmt_open__ (const char *, int, int, const char *);
|
---|
24 | int rmt_close__ (int);
|
---|
25 | size_t rmt_read__ (int, char *, size_t);
|
---|
26 | size_t rmt_write__ (int, char *, size_t);
|
---|
27 | off_t rmt_lseek__ (int, off_t, int);
|
---|
28 | int rmt_ioctl__ (int, int, char *);
|
---|
29 |
|
---|
30 | extern bool force_local_option;
|
---|
31 |
|
---|
32 | /* A filename is remote if it contains a colon not preceded by a slash,
|
---|
33 | to take care of `/:/' which is a shorthand for `/.../<CELL-NAME>/fs'
|
---|
34 | on machines running OSF's Distributing Computing Environment (DCE) and
|
---|
35 | Distributed File System (DFS). However, when --force-local, a
|
---|
36 | filename is never remote. */
|
---|
37 |
|
---|
38 | #if !FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
|
---|
39 | # define _remdev(dev_name) \
|
---|
40 | (!force_local_option && (rmt_dev_name__ = strchr (dev_name, ':')) \
|
---|
41 | && rmt_dev_name__ > (dev_name) \
|
---|
42 | && ! memchr (dev_name, '/', rmt_dev_name__ - (dev_name)))
|
---|
43 | #else
|
---|
44 | # define _remdev(dev_name) \
|
---|
45 | (!force_local_option && (rmt_dev_name__ = strchr (dev_name, ':')) \
|
---|
46 | && rmt_dev_name__ > (dev_name) \
|
---|
47 | && rmt_dev_name__ > (dev_name) != 1 \
|
---|
48 | && ! memchr (dev_name, '/', rmt_dev_name__ - (dev_name)))
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #define _isrmt(fd) \
|
---|
52 | ((fd) >= __REM_BIAS)
|
---|
53 |
|
---|
54 | #define __REM_BIAS (1 << 30)
|
---|
55 |
|
---|
56 | #ifndef O_CREAT
|
---|
57 | # define O_CREAT 01000
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | #define rmtopen(dev_name, oflag, mode, command) \
|
---|
61 | (_remdev (dev_name) ? rmt_open__ (dev_name, oflag, __REM_BIAS, command) \
|
---|
62 | : open (dev_name, oflag, mode))
|
---|
63 |
|
---|
64 | #define rmtaccess(dev_name, amode) \
|
---|
65 | (_remdev (dev_name) ? 0 : access (dev_name, amode))
|
---|
66 |
|
---|
67 | #define rmtstat(dev_name, buffer) \
|
---|
68 | (_remdev (dev_name) ? (errno = EOPNOTSUPP), -1 : stat (dev_name, buffer))
|
---|
69 |
|
---|
70 | #define rmtcreat(dev_name, mode, command) \
|
---|
71 | (_remdev (dev_name) \
|
---|
72 | ? rmt_open__ (dev_name, 1 | O_CREAT, __REM_BIAS, command) \
|
---|
73 | : creat (dev_name, mode))
|
---|
74 |
|
---|
75 | #define rmtlstat(dev_name, muffer) \
|
---|
76 | (_remdev (dev_name) ? (errno = EOPNOTSUPP), -1 : lstat (dev_name, buffer))
|
---|
77 |
|
---|
78 | #define rmtread(fd, buffer, length) \
|
---|
79 | (_isrmt (fd) ? rmt_read__ (fd - __REM_BIAS, buffer, length) \
|
---|
80 | : safe_read (fd, buffer, length))
|
---|
81 |
|
---|
82 | #define rmtwrite(fd, buffer, length) \
|
---|
83 | (_isrmt (fd) ? rmt_write__ (fd - __REM_BIAS, buffer, length) \
|
---|
84 | : full_write (fd, buffer, length))
|
---|
85 |
|
---|
86 | #define rmtlseek(fd, offset, where) \
|
---|
87 | (_isrmt (fd) ? rmt_lseek__ (fd - __REM_BIAS, offset, where) \
|
---|
88 | : lseek (fd, offset, where))
|
---|
89 |
|
---|
90 | #define rmtclose(fd) \
|
---|
91 | (_isrmt (fd) ? rmt_close__ (fd - __REM_BIAS) : close (fd))
|
---|
92 |
|
---|
93 | #define rmtioctl(fd, request, argument) \
|
---|
94 | (_isrmt (fd) ? rmt_ioctl__ (fd - __REM_BIAS, request, argument) \
|
---|
95 | : ioctl (fd, request, argument))
|
---|
96 |
|
---|
97 | #define rmtdup(fd) \
|
---|
98 | (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : dup (fd))
|
---|
99 |
|
---|
100 | #define rmtfstat(fd, buffer) \
|
---|
101 | (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : fstat (fd, buffer))
|
---|
102 |
|
---|
103 | #define rmtfcntl(cd, command, argument) \
|
---|
104 | (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : fcntl (fd, command, argument))
|
---|
105 |
|
---|
106 | #define rmtisatty(fd) \
|
---|
107 | (_isrmt (fd) ? 0 : isatty (fd))
|
---|