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 void tt_fileMarkSize(struct cmd_syndesc *as, char *arock);
40 #define ERROR(evalue) \
49 #include "AFS_component_version_number.c"
58 struct sigaction intaction, oldaction;
59 struct cmd_syndesc *cptr;
61 memset((char *)&intaction, 0, sizeof(intaction));
62 intaction.sa_handler = (int (*)())quitFms;
64 sigaction(SIGINT, &intaction, &oldaction);
67 cmd_CreateSyntax(NULL, tt_fileMarkSize, 0,
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);
75 tt_fileMarkSize(as, arock)
76 struct cmd_syndesc *as;
81 tapeDevice = as->parms[0].items->data;
83 fileMarkSize(tapeDevice);
87 fileMarkSize(tapeDevice)
90 afs_uint32 nFileMarks, nBlocks, nbfTape;
91 double tpSize, fmSize;
92 afs_uint32 bufferSize = 16384;
99 afs_int32 rewindTape();
102 usd_Open(tapeDevice, (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
104 printf("Can't open tape device %s\n", tapeDevice);
109 logFile = fopen("fms.log", "w+");
110 if (logFile == NULL) {
111 printf("Can't open log file\n");
115 fprintf(logFile, "fms test started\n");
118 code = rewindTape(hTape);
120 fprintf(logFile, "Can't rewind tape\n");
125 /* measure capacity of tape */
129 code = dataBlock(hTape, bufferSize);
138 printf("\rwrote block: %d", nbfTape);
143 fprintf(logFile, "wrote %d blocks\n", nbfTape);
145 printf("\rwrote %d blocks\n", nbfTape);
146 printf("Finished data capacity test - rewinding\n");
147 /* reset the tape device */
148 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);
156 usd_Open(tapeDevice, (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
158 fprintf(logFile, "Can't open tape device for pass 2\n");
160 printf("Can't open tape device %s\n", tapeDevice);
164 code = rewindTape(hTape);
166 fprintf(logFile, "Can't rewind tape\n");
171 /* now measure file mark size */
177 code = dataBlock(hTape, bufferSize);
181 code = fileMark(hTape);
190 printf("\rwrote %d blocks, %d filemarks", nBlocks, nFileMarks);
194 printf("\nFinished filemark test\n");
195 tpSize = (double)nbfTape *(double)bufferSize;
198 (double)nBlocks) * (double)bufferSize) / (double)nFileMarks;
199 printf("Tape capacity is %.0f bytes\n", tpSize);
200 printf("File marks are %.0f bytes\n", fmSize);
201 fprintf(logFile, "Tape capacity is %.0f bytes\n", tpSize);
202 fprintf(logFile, "File marks are %.0f bytes\n", fmSize);
217 /* --------------------------
218 * device handling routines
219 * --------------------------
222 /* rewindTape() - rewinds tape to beginning */
224 rewindTape(usd_handle_t hTape)
229 tapeop.tp_op = USDTAPE_REW;
231 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
235 /* write an EOF marker */
237 fileMark(usd_handle_t hTape)
242 tapeop.tp_op = USDTAPE_WEOF;
244 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
249 * write a block of data on tape
251 * blocksize - size of block in bytes
254 dataBlock(usd_handle_t hTape, afs_int32 reqSize)
256 static char *dB_buffer = 0;
257 static afs_int32 dB_buffersize = 0;
258 static int dB_count = 0;
260 afs_int32 code = 0, xferd;
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)