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);
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, 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);
88 fileMarkSize(tapeDevice)
91 afs_uint32 nFileMarks, nBlocks, nbfTape;
92 double tpSize, fmSize;
93 afs_uint32 bufferSize = 16384;
100 afs_int32 rewindTape();
103 usd_Open(tapeDevice, (USD_OPEN_RDWR | USD_OPEN_WLOCK), 0777, &hTape);
105 printf("Can't open tape device %s\n", tapeDevice);
110 logFile = fopen("fms.log", "w+");
111 if (logFile == NULL) {
112 printf("Can't open log file\n");
116 fprintf(logFile, "fms test started\n");
119 code = rewindTape(hTape);
121 fprintf(logFile, "Can't rewind tape\n");
126 /* measure capacity of tape */
130 code = dataBlock(hTape, bufferSize);
139 printf("\rwrote block: %d", nbfTape);
144 fprintf(logFile, "wrote %d blocks\n", nbfTape);
146 printf("\rwrote %d blocks\n", nbfTape);
147 printf("Finished data capacity test - rewinding\n");
148 /* reset the tape device */
149 code = USD_CLOSE(hTape);
151 fprintf(logFile, "Can't close tape device at end of pass 1\n");
153 printf("Can't close tape device %s\n", tapeDevice);
157 usd_Open(tapeDevice, (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);
167 fprintf(logFile, "Can't rewind tape\n");
172 /* now measure file mark size */
178 code = dataBlock(hTape, bufferSize);
182 code = fileMark(hTape);
191 printf("\rwrote %d blocks, %d filemarks", nBlocks, nFileMarks);
195 printf("\nFinished filemark test\n");
196 tpSize = (double)nbfTape *(double)bufferSize;
199 (double)nBlocks) * (double)bufferSize) / (double)nFileMarks;
200 printf("Tape capacity is %.0f bytes\n", tpSize);
201 printf("File marks are %.0f bytes\n", fmSize);
202 fprintf(logFile, "Tape capacity is %.0f bytes\n", tpSize);
203 fprintf(logFile, "File marks are %.0f bytes\n", fmSize);
218 /* --------------------------
219 * device handling routines
220 * --------------------------
223 /* rewindTape() - rewinds tape to beginning */
225 rewindTape(usd_handle_t hTape)
230 tapeop.tp_op = USDTAPE_REW;
232 rcode = USD_IOCTL(hTape, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
236 /* write an EOF marker */
238 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 */
266 && (dB_buffersize != reqSize)
272 if (dB_buffer == 0) {
273 dB_buffer = (char *)malloc(reqSize);
276 dB_buffersize = reqSize;
277 memset(dB_buffer, 0, dB_buffersize);
280 ptr = (int *)dB_buffer;
283 code = USD_WRITE(hTape, dB_buffer, dB_buffersize, &xferd);
284 if (code || xferd != dB_buffersize)