rmt.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Definitions for communicating with a remote tape drive.
  2. Copyright (C) 1988, 1992, 1996, 1997 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. extern char *rmt_path__;
  15. int rmt_open__ PARAMS ((const char *, int, int, const char *));
  16. int rmt_close__ PARAMS ((int));
  17. int rmt_read__ PARAMS ((int, char *, unsigned int));
  18. int rmt_write__ PARAMS ((int, char *, unsigned int));
  19. long rmt_lseek__ PARAMS ((int, off_t, int));
  20. int rmt_ioctl__ PARAMS ((int, int, char *));
  21. /* A filename is remote if it contains a colon not preceeded by a slash,
  22. to take care of `/:/' which is a shorthand for `/.../<CELL-NAME>/fs'
  23. on machines running OSF's Distributing Computing Environment (DCE) and
  24. Distributed File System (DFS). However, when --force-local, a
  25. filename is never remote. */
  26. #define _remdev(Path) \
  27. (!force_local_option && (rmt_path__ = strchr (Path, ':')) \
  28. && rmt_path__ > (Path) && rmt_path__[-1] != '/')
  29. #define _isrmt(Fd) \
  30. ((Fd) >= __REM_BIAS)
  31. #define __REM_BIAS 128
  32. #ifndef O_CREAT
  33. # define O_CREAT 01000
  34. #endif
  35. #define rmtopen(Path, Oflag, Mode, Command) \
  36. (_remdev (Path) ? rmt_open__ (Path, Oflag, __REM_BIAS, Command) \
  37. : open (Path, Oflag, Mode))
  38. #define rmtaccess(Path, Amode) \
  39. (_remdev (Path) ? 0 : access (Path, Amode))
  40. #define rmtstat(Path, Buffer) \
  41. (_remdev (Path) ? (errno = EOPNOTSUPP), -1 : stat (Path, Buffer))
  42. /* FIXME: errno should be read-only */
  43. #define rmtcreat(Path, Mode, Command) \
  44. (_remdev (Path) \
  45. ? rmt_open__ (Path, 1 | O_CREAT, __REM_BIAS, Command) \
  46. : creat (Path, Mode))
  47. #define rmtlstat(Path, Buffer) \
  48. (_remdev (Path) ? (errno = EOPNOTSUPP), -1 : lstat (Path, Buffer))
  49. /* FIXME: errno should be read-only */
  50. #define rmtread(Fd, Buffer, Length) \
  51. (_isrmt (Fd) ? rmt_read__ (Fd - __REM_BIAS, Buffer, Length) \
  52. : read (Fd, Buffer, Length))
  53. #define rmtwrite(Fd, Buffer, Length) \
  54. (_isrmt (Fd) ? rmt_write__ (Fd - __REM_BIAS, Buffer, Length) \
  55. : write (Fd, Buffer, Length))
  56. #define rmtlseek(Fd, Offset, Where) \
  57. (_isrmt (Fd) ? rmt_lseek__ (Fd - __REM_BIAS, Offset, Where) \
  58. : lseek (Fd, Offset, Where))
  59. #define rmtclose(Fd) \
  60. (_isrmt (Fd) ? rmt_close__ (Fd - __REM_BIAS) : close (Fd))
  61. #define rmtioctl(Fd, Request, Argument) \
  62. (_isrmt (Fd) ? rmt_ioctl__ (Fd - __REM_BIAS, Request, Argument) \
  63. : ioctl (Fd, Request, Argument))
  64. #define rmtdup(Fd) \
  65. (_isrmt (Fd) ? (errno = EOPNOTSUPP), -1 : dup (Fd))
  66. /* FIXME: errno should be read-only */
  67. #define rmtfstat(Fd, Buffer) \
  68. (_isrmt (Fd) ? (errno = EOPNOTSUPP), -1 : fstat (Fd, Buffer))
  69. /* FIXME: errno should be read-only */
  70. #define rmtfcntl(Fd, Command, Argument) \
  71. (_isrmt (Fd) ? (errno = EOPNOTSUPP), -1 : fcntl (Fd, Command, Argument))
  72. /* FIXME: errno should be read-only */
  73. #define rmtisatty(Fd) \
  74. (_isrmt (Fd) ? 0 : isatty (Fd))