1 /* Definitions for communicating with a remote tape drive.
3 Copyright (C) 1988, 1992, 1996, 1997, 2001, 2003, 2004, 2007 Free
4 Software Foundation, Inc.
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 3, or (at your option)
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.
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. */
20 extern char const *rmt_command;
21 extern char const *rmt_dev_name__;
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 *);
30 extern bool force_local_option;
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. */
38 #define _remdev(dev_name) \
39 (!force_local_option && (rmt_dev_name__ = strchr (dev_name, ':')) \
40 && rmt_dev_name__ > (dev_name) \
41 && ! memchr (dev_name, '/', rmt_dev_name__ - (dev_name)))
46 #define __REM_BIAS (1 << 30)
49 # define O_CREAT 01000
52 #define rmtopen(dev_name, oflag, mode, command) \
53 (_remdev (dev_name) ? rmt_open__ (dev_name, oflag, __REM_BIAS, command) \
54 : open (dev_name, oflag, mode))
56 #define rmtaccess(dev_name, amode) \
57 (_remdev (dev_name) ? 0 : access (dev_name, amode))
59 #define rmtstat(dev_name, buffer) \
60 (_remdev (dev_name) ? (errno = EOPNOTSUPP), -1 : stat (dev_name, buffer))
62 #define rmtcreat(dev_name, mode, command) \
64 ? rmt_open__ (dev_name, O_CREAT | O_WRONLY, __REM_BIAS, command) \
65 : creat (dev_name, mode))
67 #define rmtlstat(dev_name, muffer) \
68 (_remdev (dev_name) ? (errno = EOPNOTSUPP), -1 : lstat (dev_name, buffer))
70 #define rmtread(fd, buffer, length) \
71 (_isrmt (fd) ? rmt_read__ (fd - __REM_BIAS, buffer, length) \
72 : safe_read (fd, buffer, length))
74 #define rmtwrite(fd, buffer, length) \
75 (_isrmt (fd) ? rmt_write__ (fd - __REM_BIAS, buffer, length) \
76 : full_write (fd, buffer, length))
78 #define rmtlseek(fd, offset, where) \
79 (_isrmt (fd) ? rmt_lseek__ (fd - __REM_BIAS, offset, where) \
80 : lseek (fd, offset, where))
82 #define rmtclose(fd) \
83 (_isrmt (fd) ? rmt_close__ (fd - __REM_BIAS) : close (fd))
85 #define rmtioctl(fd, request, argument) \
86 (_isrmt (fd) ? rmt_ioctl__ (fd - __REM_BIAS, request, argument) \
87 : ioctl (fd, request, argument))
90 (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : dup (fd))
92 #define rmtfstat(fd, buffer) \
93 (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : fstat (fd, buffer))
95 #define rmtfcntl(cd, command, argument) \
96 (_isrmt (fd) ? (errno = EOPNOTSUPP), -1 : fcntl (fd, command, argument))
98 #define rmtisatty(fd) \
99 (_isrmt (fd) ? 0 : isatty (fd))