2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
19 #include <sys/types.h> /* for mtio.h */
21 #include <afs/procmgmt.h>
24 /* structure for writing data to tape */
25 typedef struct tapeDataBuffer {
26 struct tapeDataBuffer *tdb_next;
29 typedef tapeDataBufferT *tapeDataBufferP;
32 char *tapeDevice = 0; /* device pathname */
33 afs_int32 eotEnabled = 1;
36 int fileMark(usd_handle_t hTape);
37 int fileMarkSize(char *tapeDevice);
38 static int tt_fileMarkSize(struct cmd_syndesc *as, void *arock);
39 afs_int32 rewindTape(usd_handle_t hTape);
40 int dataBlock(usd_handle_t, afs_int32);
42 #define ERROR(evalue) do { \
50 #include "AFS_component_version_number.c"
56 main(int argc, char **argv)
58 struct sigaction intaction, oldaction;
59 struct cmd_syndesc *cptr;
61 memset(&intaction, 0, sizeof(intaction));
62 intaction.sa_handler = quitFms;
64 sigaction(SIGINT, &intaction, &oldaction);
67 cmd_CreateSyntax(NULL, tt_fileMarkSize, NULL,
68 "write a tape full of file marks");
69 cmd_AddParm(cptr, "-tape", CMD_SINGLE, CMD_REQUIRED, "tape special file");
71 cmd_Dispatch(argc, argv);
76 tt_fileMarkSize(struct cmd_syndesc *as, void *arock)
80 tapeDevice = as->parms[0].items->data;
82 fileMarkSize(tapeDevice);
89 fileMarkSize(char *tapeDevice)
91 afs_uint32 nFileMarks, nBlocks, nbfTape;
92 double tpSize, fmSize;
93 afs_uint32 bufferSize = 16384;
101 usd_Open(tapeDevice, (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
103 printf("Can't open tape device %s\n", tapeDevice);
108 logFile = fopen("fms.log", "w+");
109 if (logFile == NULL) {
110 printf("Can't open log file\n");
114 fprintf(logFile, "fms test started\n");
117 code = rewindTape(hTape);
119 fprintf(logFile, "Can't rewind tape\n");
124 /* measure capacity of tape */
128 code = dataBlock(hTape, bufferSize);
137 printf("\rwrote block: %d", nbfTape);
142 fprintf(logFile, "wrote %d blocks\n", nbfTape);
144 printf("\rwrote %d blocks\n", nbfTape);
145 printf("Finished data capacity test - rewinding\n");
146 /* reset the tape device */
147 code = USD_CLOSE(hTape);
149 fprintf(logFile, "Can't close tape device at end of pass 1\n");
151 printf("Can't close tape device %s\n", tapeDevice);
155 usd_Open(tapeDevice, (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
157 fprintf(logFile, "Can't open tape device for pass 2\n");
159 printf("Can't open tape device %s\n", tapeDevice);
163 code = rewindTape(hTape);
165 fprintf(logFile, "Can't rewind tape\n");
170 /* now measure file mark size */
176 code = dataBlock(hTape, bufferSize);
180 code = fileMark(hTape);
189 printf("\rwrote %d blocks, %d filemarks", nBlocks, nFileMarks);
193 printf("\nFinished filemark test\n");
194 tpSize = (double)nbfTape *(double)bufferSize;
197 (double)nBlocks) * (double)bufferSize) / (double)nFileMarks;
198 printf("Tape capacity is %.0f bytes\n", tpSize);
199 printf("File marks are %.0f bytes\n", fmSize);
200 fprintf(logFile, "Tape capacity is %.0f bytes\n", tpSize);
201 fprintf(logFile, "File marks are %.0f bytes\n", fmSize);
216 /* --------------------------
217 * device handling routines
218 * --------------------------
221 /* rewindTape() - rewinds tape to beginning */
223 rewindTape(usd_handle_t hTape)
228 tapeop.tp_op = USDTAPE_REW;
230 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
234 /* write an EOF marker */
236 fileMark(usd_handle_t hTape)
241 tapeop.tp_op = USDTAPE_WEOF;
243 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
248 * write a block of data on tape
250 * blocksize - size of block in bytes
253 dataBlock(usd_handle_t hTape, afs_int32 reqSize)
255 static char *dB_buffer = 0;
256 static afs_int32 dB_buffersize = 0;
257 static int dB_count = 0;
262 /* dbBuffersize is only valid when dB_buffer is non-zero */
265 && (dB_buffersize != reqSize)
271 if (dB_buffer == 0) {
272 dB_buffer = (char *)malloc(reqSize);
275 dB_buffersize = reqSize;
276 memset(dB_buffer, 0, dB_buffersize);
279 ptr = (int *)dB_buffer;
282 code = USD_WRITE(hTape, dB_buffer, dB_buffersize, &xferd);
283 if (code || xferd != dB_buffersize)