1 /*************************************************************************
3 * File...........: s390-tools/tape390/tape390_common.c
4 * Author(s)......: Frank Munzert <munzert@de.ibm.com>
5 * Michael Holzheu <holzheu@de.ibm.com>
7 * Copyright IBM Corp. 2006,2007
9 *************************************************************************/
16 #include "tape390_common.h"
18 #define PROC_DEVICES_FILE "/proc/devices"
19 #define PROC_DEVICES_FILE_WIDTH 100
21 char *prog_name
; /* Name of tool */
26 void set_prog_name(char *name
)
32 * Check whether specified device node is tape device
34 int is_not_tape(char *device
)
37 char line
[PROC_DEVICES_FILE_WIDTH
];
38 char last_line
[PROC_DEVICES_FILE_WIDTH
];
40 struct stat stat_struct
;
42 if (stat(device
, &stat_struct
)) {
43 ERRMSG("%s: Unable to get device status for "
44 "'%s'. \n", prog_name
, device
);
48 fh
= fopen(PROC_DEVICES_FILE
,"r");
50 ERRMSG("%s: WARNING: Cannot check for tape in file "
51 PROC_DEVICES_FILE
".\n", prog_name
);
53 return(0); /* check not possible, just continue */
55 while (!found
&& (fscanf(fh
, "%s", line
) != EOF
)) {
56 if (strcmp(line
, "tape") == 0)
59 strcpy(last_line
, line
);
62 if (found
&& (major(stat_struct
.st_rdev
) ==
63 (unsigned int) atoi(last_line
)))
66 ERRMSG("%s: '%s' is not a tape device. \n", prog_name
, device
);
72 * Open the tape device
74 int open_tape(char *device
)
77 fd
= open(device
,O_RDONLY
);
79 ERRMSG("%s: Cannot open device %s.\n",