2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
29 * $Id: output-null.c,v 1.7 2003/03/06 21:43:57 martinea Exp $
31 * tapeio.c virtual tape interface for a null device.
37 #include "output-null.h"
38 #include "fileheader.h"
44 static long *amount_written = NULL;
45 static int open_count = 0;
48 null_tape_open(filename, flags, mask)
55 if ((flags & 3) != O_RDONLY) {
59 if ((fd = open("/dev/null", flags, mask)) >= 0) {
60 tapefd_setinfo_fake_label(fd, 1);
61 amtable_alloc((void **)&amount_written,
63 sizeof(*amount_written),
67 amount_written[fd] = 0;
73 null_tapefd_read(fd, buffer, count)
78 return read(fd, buffer, count);
82 null_tapefd_write(fd, buffer, count)
87 int write_count = count;
92 if (write_count <= 0) {
93 return 0; /* special case */
96 if ((length = tapefd_getinfo_length(fd)) > 0) {
97 kbytes_left = length - amount_written[fd];
98 if (write_count / 1024 > kbytes_left) {
99 write_count = kbytes_left * 1024;
102 amount_written[fd] += (write_count + 1023) / 1024;
103 if (write_count <= 0) {
107 r = write(fd, buffer, write_count);
113 null_tapefd_close(fd)
120 null_tapefd_resetofs(fd)
126 null_tapefd_status(fd, stat)
128 struct am_mt_status *stat;
130 memset((void *)stat, 0, sizeof(*stat));
131 stat->online_valid = 1;
137 null_tape_stat(filename, buf)
141 return stat("/dev/null", buf);
145 null_tape_access(filename, mode)
149 return access("/dev/null", mode);
153 null_tapefd_rewind(fd)
156 amount_written[fd] = 0;
161 null_tapefd_unload(fd)
164 amount_written[fd] = 0;
169 null_tapefd_fsf(fd, count)
176 null_tapefd_weof(fd, count)
183 null_tapefd_can_fork(fd)