1
/* @(#)testosu.c 19.1 (ESO-IPG) 02/25/03 14:33:06 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
* Define _POSIX_SOURCE to indicate
30
* that this is a POSIX program
32
#define _POSIX_SOURCE 1
34
#include <sys/types.h>
44
char *name; /* Unit Name */
45
long int usize; /* Size in blocks, non meaningful for tapes */
46
int blocksize; /* Density / Sector size */
47
int density; /* Density / Sector size */
48
char device_type; /* ? D T */
51
int opentape(), closetape(), skiptape();
52
int wfmtape(), readtape(), writetape(), quit(), nothing();
53
int gfilenum(), skipblk(), gblknum();
56
static char name[80] = "ns2!/dev/nrst2";
60
static int verbose = 0;
66
"\n0- ***** MENU *****\n", nothing,
67
"1- Open a tape device\n", opentape,
68
"2- Close a tape device\n", closetape,
69
"3- Read a sector\n", readtape,
70
"4- Write a sector\n", writetape,
71
"5- Close a file\n", wfmtape,
72
"6- File seek \n", skiptape,
73
"7- Get current file number\n", gfilenum,
86
if ( argc == 2 && strcmp(argv[1],"-v")) verbose =1;
88
* I check now for DEVCAPFILE otherwise it will fail later in the
90
* A default place for DEVCAPFILE used to be:
91
* $MIDASHOME/$MIDVERS/incl/devcap.dat
93
if ( ! oshenv("DEVCAPFILE", (char *)0) ) {
94
printf("Warning: variable DEVCAPFILE is undefined\n");
99
signal(SIGINT,returnhere);
102
while(m_c->msg != (char *)0)
104
printf("\nOption: ");
105
if (!gets(buff)) break;
106
if ((opt=atoi(buff)) >= (sizeof(msg_cmd)/sizeof(struct msg_cmd)))
107
printf("Bad option\n");
109
(*msg_cmd[opt].cmd)();
116
char aname[80], input[8];
120
printf("\nOPEN TAPE\n");
121
printf("Enter name of device (%s): ",name);
124
if (strlen(aname) != 0)
127
printf("Enter open mode (2:READ_WRITE): ");
128
mode=atoi(gets(input));
129
if (strlen(input) == 0)
132
printf("Enter density of device (0): ");
133
den=atoi(gets(input));
135
if ((pfd = osuopen(name,mode,den)) == -1) {
136
printf("Error opening %s, %s\n",
141
printf("OPEN %s succeded. \n",name);
146
printf("\nCLOSE TAPE\n");
147
if (osuclose(fd) == -1) {
148
printf("Error closing device, %s\n",osmsg());
151
printf("CLOSE succeded\n");
162
printf("Enter mode of addressing (0=FILE_START):");
163
mode = atoi(gets(name));
165
printf("Enter file to seek (0):");
166
offset = atoi(gets(name));
168
printf("\nSKIPPING TO FILE:%d IN MODE:%d\n",offset,mode);
169
if ((file_no = osufseek(fd,offset,mode)) == -1) {
170
printf("Error skipping to file %d in mode %d. %s\n",
171
offset,mode,osmsg());
174
printf("SKIP succeded. Current file: %d\n",file_no);
179
printf("\nCLOSING A FILE\n");
180
if (osufclose(fd) == -1) {
181
printf("Error closing a file: %s\n",
185
printf("CLOSING A FILE succeded\n");
196
printf("\nWRITE A BUFFER\n");
197
printf("Enter number of bytes to be written (1024): ");
198
n_bytes = atoi(gets(name));
199
if ( strlen(name) == 0)
202
if ((pbuf = malloc(n_bytes)) == (char *)0 ) {
203
printf("Max. memory allocation: %d bytes\n",n_bytes);
207
printf("Buffer allocated\n");
208
printf("Enter pattern for buffer ('A'): ");
209
if (strlen(gets(name)) == 0)
214
printf("Pattern=%c\n",pattern);
216
for (i=0; i<n_bytes; i++)
219
/* for(i=0; i<n_bytes; i++)
220
/* printf("%c ",pbuf[i]);
223
if (osuwrite(fd,pbuf,n_bytes) == -1) {
224
printf("Error writting %d bytes, %s\n",
228
printf("WRITE %d bytes succeded\n",n_bytes);
240
printf("\nREAD A BUFFER\n");
241
printf("Enter number of bytes to be read (1024): ");
242
n_bytes = atoi(gets(name));
243
if ( strlen(name) == 0)
246
if ((pbuf = malloc(n_bytes)) == (char *)0 ) {
247
printf("Max. memory allocation: %d bytes\n",n_bytes);
251
printf("Buffer allocated\n");
253
if ((length = osuread(fd,pbuf,n_bytes)) == -1) {
254
printf("Error reading %d bytes, %s\n",
259
printf("\nREAD %d bytes succeded.\n",length);
261
printf("Pattern=%c\n",pbuf[0]);
264
for(i=0; i<length; i++)
265
if (pattern != pbuf[i])
266
printf("Byte %d (%c) differs of pattern(%c)\n",
275
printf("\nGETTING CURRENT FILE NUMBER\n");
276
if ((file_no = osuftell(fd)) == -1) {
277
printf("Error getting current file number\n",
281
printf("CURRENT FILE NUMBER: %d\n",file_no);