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>
13 #include <afs/procmgmt.h>
19 /* structure for writing data to tape */
20 typedef struct tapeDataBuffer
{
21 struct tapeDataBuffer
*tdb_next
;
24 typedef tapeDataBufferT
*tapeDataBufferP
;
27 char *tapeDevice
= 0; /* device pathname */
28 afs_int32 eotEnabled
= 1;
31 int fileMark(usd_handle_t hTape
);
32 int fileMarkSize(char *tapeDevice
);
33 static int tt_fileMarkSize(struct cmd_syndesc
*as
, void *arock
);
34 afs_int32
rewindTape(usd_handle_t hTape
);
35 int dataBlock(usd_handle_t
, afs_int32
);
37 #define ERROR(evalue) do { \
45 #include "AFS_component_version_number.c"
51 main(int argc
, char **argv
)
53 struct sigaction intaction
, oldaction
;
54 struct cmd_syndesc
*cptr
;
56 memset(&intaction
, 0, sizeof(intaction
));
57 intaction
.sa_handler
= quitFms
;
59 sigaction(SIGINT
, &intaction
, &oldaction
);
62 cmd_CreateSyntax(NULL
, tt_fileMarkSize
, NULL
, 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
);
71 tt_fileMarkSize(struct cmd_syndesc
*as
, void *arock
)
75 tapeDevice
= as
->parms
[0].items
->data
;
77 fileMarkSize(tapeDevice
);
84 fileMarkSize(char *tapeDevice
)
86 afs_uint32 nFileMarks
, nBlocks
, nbfTape
;
87 double tpSize
, fmSize
;
88 afs_uint32 bufferSize
= 16384;
96 usd_Open(tapeDevice
, (USD_OPEN_RDWR
| USD_OPEN_WLOCK
), 0777, &hTape
);
98 printf("Can't open tape device %s\n", tapeDevice
);
103 logFile
= fopen("fms.log", "w+");
104 if (logFile
== NULL
) {
105 printf("Can't open log file\n");
109 fprintf(logFile
, "fms test started\n");
112 code
= rewindTape(hTape
);
114 fprintf(logFile
, "Can't rewind tape\n");
119 /* measure capacity of tape */
123 code
= dataBlock(hTape
, bufferSize
);
132 printf("\rwrote block: %d", nbfTape
);
137 fprintf(logFile
, "wrote %d blocks\n", nbfTape
);
139 printf("\rwrote %d blocks\n", nbfTape
);
140 printf("Finished data capacity test - rewinding\n");
141 /* reset the tape device */
142 code
= USD_CLOSE(hTape
);
144 fprintf(logFile
, "Can't close tape device at end of pass 1\n");
146 printf("Can't close tape device %s\n", tapeDevice
);
150 usd_Open(tapeDevice
, (USD_OPEN_RDWR
| USD_OPEN_WLOCK
), 0777, &hTape
);
152 fprintf(logFile
, "Can't open tape device for pass 2\n");
154 printf("Can't open tape device %s\n", tapeDevice
);
158 code
= rewindTape(hTape
);
160 fprintf(logFile
, "Can't rewind tape\n");
165 /* now measure file mark size */
171 code
= dataBlock(hTape
, bufferSize
);
175 code
= fileMark(hTape
);
184 printf("\rwrote %d blocks, %d filemarks", nBlocks
, nFileMarks
);
188 printf("\nFinished filemark test\n");
189 tpSize
= (double)nbfTape
*(double)bufferSize
;
192 (double)nBlocks
) * (double)bufferSize
) / (double)nFileMarks
;
193 printf("Tape capacity is %.0f bytes\n", tpSize
);
194 printf("File marks are %.0f bytes\n", fmSize
);
195 fprintf(logFile
, "Tape capacity is %.0f bytes\n", tpSize
);
196 fprintf(logFile
, "File marks are %.0f bytes\n", fmSize
);
211 /* --------------------------
212 * device handling routines
213 * --------------------------
216 /* rewindTape() - rewinds tape to beginning */
218 rewindTape(usd_handle_t hTape
)
223 tapeop
.tp_op
= USDTAPE_REW
;
225 rcode
= USD_IOCTL(hTape
, USD_IOCTL_TAPEOPERATION
, (void *)&tapeop
);
229 /* write an EOF marker */
231 fileMark(usd_handle_t hTape
)
236 tapeop
.tp_op
= USDTAPE_WEOF
;
238 rcode
= USD_IOCTL(hTape
, USD_IOCTL_TAPEOPERATION
, (void *)&tapeop
);
243 * write a block of data on tape
245 * blocksize - size of block in bytes
248 dataBlock(usd_handle_t hTape
, afs_int32 reqSize
)
250 static char *dB_buffer
= 0;
251 static afs_int32 dB_buffersize
= 0;
252 static int dB_count
= 0;
257 /* dbBuffersize is only valid when dB_buffer is non-zero */
260 && (dB_buffersize
!= reqSize
)
266 if (dB_buffer
== 0) {
267 dB_buffer
= calloc(1, reqSize
);
270 dB_buffersize
= reqSize
;
273 ptr
= (int *)dB_buffer
;
276 code
= USD_WRITE(hTape
, dB_buffer
, dB_buffersize
, &xferd
);
277 if (code
|| xferd
!= dB_buffersize
)