rmt.h 3.2 KB

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