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 <afs/param.h> /* for machine/host info */
14 #include <sys/types.h> /* for mtio.h */
16 #include <afs/procmgmt.h>
19 /* structure for writing data to tape */
20 typedef struct tapeDataBuffer
22 struct tapeDataBuffer *tdb_next;
25 typedef tapeDataBufferT *tapeDataBufferP;
28 char *tapeDevice = 0; /* device pathname */
29 afs_int32 eotEnabled = 1;
32 int fileMark(usd_handle_t hTape);
33 int fileMarkSize(char *tapeDevice);
34 void tt_fileMarkSize(struct cmd_syndesc *as, char *arock);
36 #define ERROR(evalue) \
45 #include "AFS_component_version_number.c"
54 struct sigaction intaction, oldaction;
55 struct cmd_syndesc *cptr;
57 bzero((char *)&intaction, sizeof(intaction));
58 intaction.sa_handler = (int (*)())quitFms;
60 sigaction(SIGINT, &intaction, &oldaction);
62 cptr = cmd_CreateSyntax((char *) 0, tt_fileMarkSize, 0,
63 "write a tape full of file marks");
64 cmd_AddParm(cptr, "-tape", CMD_SINGLE, CMD_REQUIRED, "tape special file");
66 cmd_Dispatch(argc, argv);
69 void tt_fileMarkSize(as, arock)
70 struct cmd_syndesc *as;
75 tapeDevice = as->parms[0].items->data;
77 fileMarkSize(tapeDevice);
81 fileMarkSize(tapeDevice)
84 afs_uint32 nFileMarks, nBlocks, nbfTape;
85 double tpSize, fmSize;
86 afs_uint32 bufferSize = 16384;
93 afs_int32 rewindTape();
95 code = usd_Open(tapeDevice,
96 (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
99 printf("Can't open tape device %s\n", tapeDevice);
104 logFile = fopen("fms.log", "w+");
105 if ( logFile == NULL )
107 printf("Can't open log file\n");
111 fprintf(logFile, "fms test started\n");
114 code = rewindTape(hTape);
117 fprintf(logFile, "Can't rewind tape\n");
122 /* measure capacity of tape */
127 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);
150 fprintf(logFile, "Can't close tape device at end of pass 1\n");
152 printf("Can't close tape device %s\n", tapeDevice);
155 code = usd_Open(tapeDevice,
156 (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
159 fprintf(logFile, "Can't open tape device for pass 2\n");
161 printf("Can't open tape device %s\n", tapeDevice);
165 code = rewindTape(hTape);
168 fprintf(logFile, "Can't rewind tape\n");
173 /* now measure file mark size */
180 code = dataBlock(hTape, bufferSize);
184 code = fileMark(hTape);
194 printf("\rwrote %d blocks, %d filemarks",
195 nBlocks, nFileMarks);
199 printf("\nFinished filemark test\n");
200 tpSize = (double)nbfTape*(double)bufferSize;
201 fmSize = (((double)nbfTape - (double)nBlocks)*(double)bufferSize)/(double)nFileMarks;
202 printf("Tape capacity is %.0f bytes\n", tpSize);
203 printf("File marks are %.0f bytes\n", fmSize);
204 fprintf(logFile, "Tape capacity is %.0f bytes\n", tpSize);
205 fprintf(logFile, "File marks are %.0f bytes\n", fmSize);
213 void quitFms(int sig)
219 /* --------------------------
220 * device handling routines
221 * --------------------------
224 /* rewindTape() - rewinds tape to beginning */
226 rewindTape(usd_handle_t hTape)
231 tapeop.tp_op = USDTAPE_REW;
233 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
237 /* write an EOF marker */
238 int fileMark(usd_handle_t hTape)
243 tapeop.tp_op = USDTAPE_WEOF;
245 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
250 * write a block of data on tape
252 * blocksize - size of block in bytes
255 dataBlock(usd_handle_t hTape, afs_int32 reqSize)
257 static char *dB_buffer = 0;
258 static afs_int32 dB_buffersize = 0;
259 static int dB_count = 0;
261 afs_int32 code = 0, xferd;
263 /* dbBuffersize is only valid when dB_buffer is non-zero */
265 if ( (dB_buffer != 0)
266 && (dB_buffersize != reqSize )
275 dB_buffer = (char *) malloc(reqSize);
276 if ( dB_buffer == 0 )
278 dB_buffersize = reqSize;
279 bzero(dB_buffer, dB_buffersize);
282 ptr = (int *) dB_buffer;
285 code = USD_WRITE(hTape, dB_buffer, dB_buffersize, &xferd);
286 if (code || xferd != dB_buffersize)