From 14a9ca5df458a0af344fe36c087d41f68c464772 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Fri, 6 May 2016 21:49:57 +0200 Subject: [PATCH] LARGE CHURN: reindent source code The source code seems to have, over time, become less self-consistent in style. In order to not have to keep this up manually, switch over indenting to clang-format. A .clang-format file is provided to give repeatable results. The main difference is switching from tabs to non-tabs usage. Otherwise the changes are mostly minor and leading to more consistency. Contributions to the format style welcome! Nota bene: this should have had no code impact. Any actual code changes (beyond indenting) are bugs in the re-indent process. --- .clang-format | 47 ++ .dir-locals.el | 5 + Makefile | 9 +- mt.c | 627 +++++++++++++------------ stinit.c | 1182 +++++++++++++++++++++++------------------------- 5 files changed, 930 insertions(+), 940 deletions(-) create mode 100644 .clang-format create mode 100644 .dir-locals.el diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1934b1a --- /dev/null +++ b/.clang-format @@ -0,0 +1,47 @@ +AccessModifierOffset: 0 +AlignEscapedNewlinesLeft: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackParameters: false +BreakBeforeBinaryOperators: false +BreakBeforeBraces: Linux +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 80 +CommentPragmas: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 0 +ContinuationIndentWidth: 0 +Cpp11BracedListStyle: false +DerivePointerBinding: false +IndentCaseLabels: false +IndentFunctionDeclarationAfterType: false +IndentWidth: 4 +Language: Cpp +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 100 +PenaltyBreakComment: 100 +PenaltyBreakFirstLessLess: 0 +PenaltyBreakString: 100 +PenaltyExcessCharacter: 1 +PenaltyReturnTypeOnItsOwnLine: 20 +PointerBindsToType: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..2ed9d9b --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,5 @@ +;;; Directory Local Variables +;;; For more information see (info "(emacs) Directory Variables") + +((c-mode + (c-basic-offset . 4))) diff --git a/Makefile b/Makefile index a207af0..337b75c 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,9 @@ DISTFILES = \ README.md \ stinit.8 \ stinit.c \ - stinit.def.examples + stinit.def.examples \ + .dir-locals.el \ + .clang-format VERSION=1.3 RELEASEDIR=mt-st-$(VERSION) @@ -82,4 +84,7 @@ release-tag: clean: rm -f *~ \#*\# *.o $(PROGS) version.h -.PHONY: dist distcheck clean +reindent: + clang-format -i mt.c stinit.c + +.PHONY: dist distcheck clean reindent diff --git a/mt.c b/mt.c index 4756716..887f904 100644 --- a/mt.c +++ b/mt.c @@ -1,12 +1,12 @@ /* This file contains the source of the 'mt' program intended for - Linux systems. The program supports the basic mt commands found - in most Unix-like systems. In addition to this the program - supports several commands designed for use with the Linux SCSI - tape drive. + Linux systems. The program supports the basic mt commands found + in most Unix-like systems. In addition to this the program + supports several commands designed for use with the Linux SCSI + tape drive. - Maintained by Iustin Pop (iustin@k1024.org). - Copyright by Kai Mäkisara, 1998 - 2008. The program may be distributed - according to the GNU Public License. + Maintained by Iustin Pop (iustin@k1024.org). + Copyright by Kai Mäkisara, 1998 - 2008. The program may be distributed + according to the GNU Public License. */ #include @@ -27,12 +27,12 @@ #include "version.h" #ifndef DEFTAPE -#define DEFTAPE "/dev/tape" /* default tape device */ -#endif /* DEFTAPE */ +#define DEFTAPE "/dev/tape" /* default tape device */ +#endif /* DEFTAPE */ typedef struct cmdef_tr cmdef_tr; -typedef int (* cmdfunc)(int, struct cmdef_tr *, int, char **); +typedef int (*cmdfunc)(int, struct cmdef_tr *, int, char **); struct cmdef_tr { char *cmd_name; @@ -44,24 +44,24 @@ struct cmdef_tr { int error_tests; }; -#define NO_FD 0 -#define FD_RDONLY 1 -#define FD_RDWR 2 +#define NO_FD 0 +#define FD_RDONLY 1 +#define FD_RDWR 2 -#define NO_ARGS 0 -#define ONE_ARG 1 -#define TWO_ARGS 2 -#define MANY_ARGS 255 +#define NO_ARGS 0 +#define ONE_ARG 1 +#define TWO_ARGS 2 +#define MANY_ARGS 255 -#define DO_BOOLEANS 1002 -#define SET_BOOLEANS 1003 +#define DO_BOOLEANS 1002 +#define SET_BOOLEANS 1003 #define CLEAR_BOOLEANS 1004 -#define ET_ONLINE 1 -#define ET_WPROT 2 +#define ET_ONLINE 1 +#define ET_WPROT 2 static void usage(int); -static void version() __attribute__ ((noreturn)); +static void version() __attribute__((noreturn)); static int do_standard(int, cmdef_tr *, int, char **); static int do_drvbuffer(int, cmdef_tr *, int, char **); static int do_options(int, cmdef_tr *, int, char **); @@ -255,168 +255,158 @@ static struct booleans { /* clang-format on */ }; -static char *tape_name; /* The tape name for messages */ +static char *tape_name; /* The tape name for messages */ - - int -main(int argc, char **argv) +int main(int argc, char **argv) { int mtfd, i, argn, oflags; unsigned int len; char *cmdstr; cmdef_tr *comp, *comp2; - for (argn=1; argn < argc; argn++) - if (*argv[argn] == '-') - switch (*(argv[argn] + 1)) { - case 'f': - case 't': - argn += 1; - if (argn >= argc) { - usage(0); - exit(1); - } - tape_name = argv[argn]; - break; - case 'h': - usage(1); - exit(0); - break; - case 'v': - version(); - break; - case '-': - if (*(argv[argn] + 1) == '-' && - *(argv[argn] + 2) == 'v') { - version(); - } - /* Fall through */ - default: - usage(0); - exit(1); - } - else - break; + for (argn = 1; argn < argc; argn++) + if (*argv[argn] == '-') + switch (*(argv[argn] + 1)) { + case 'f': + case 't': + argn += 1; + if (argn >= argc) { + usage(0); + exit(1); + } + tape_name = argv[argn]; + break; + case 'h': + usage(1); + exit(0); + break; + case 'v': + version(); + break; + case '-': + if (*(argv[argn] + 1) == '-' && *(argv[argn] + 2) == 'v') { + version(); + } + /* Fall through */ + default: + usage(0); + exit(1); + } + else + break; if (tape_name == NULL && (tape_name = getenv("TAPE")) == NULL) { - struct stat stbuf; + struct stat stbuf; - tape_name = DEFTAPE; - if (!stat(tape_name, &stbuf) && - !S_ISCHR(stbuf.st_mode)) { - fprintf(stderr, "The default '%s' is not a character device.\n\n", tape_name); - usage(1); - exit(1); - } + tape_name = DEFTAPE; + if (!stat(tape_name, &stbuf) && !S_ISCHR(stbuf.st_mode)) { + fprintf(stderr, "The default '%s' is not a character device.\n\n", tape_name); + usage(1); + exit(1); + } } - - if (argn >= argc ) { - usage(0); - exit(1); + + if (argn >= argc) { + usage(0); + exit(1); } cmdstr = argv[argn++]; len = strlen(cmdstr); for (comp = cmds; comp->cmd_name != NULL; comp++) - if (strncmp(cmdstr, comp->cmd_name, len) == 0) - break; + if (strncmp(cmdstr, comp->cmd_name, len) == 0) + break; if (comp->cmd_name == NULL) { - fprintf(stderr, "mt: unknown command \"%s\"\n", cmdstr); - usage(1); - exit(1); + fprintf(stderr, "mt: unknown command \"%s\"\n", cmdstr); + usage(1); + exit(1); } if (len != strlen(comp->cmd_name)) { - for (comp2 = comp + 1; comp2->cmd_name != NULL; comp2++) - if (strncmp(cmdstr, comp2->cmd_name, len) == 0) - break; - if (comp2->cmd_name != NULL) { - fprintf(stderr, "mt: ambiguous command \"%s\"\n", cmdstr); - usage(1); - exit(1); - } + for (comp2 = comp + 1; comp2->cmd_name != NULL; comp2++) + if (strncmp(cmdstr, comp2->cmd_name, len) == 0) + break; + if (comp2->cmd_name != NULL) { + fprintf(stderr, "mt: ambiguous command \"%s\"\n", cmdstr); + usage(1); + exit(1); + } } if (comp->arg_cnt != MANY_ARGS && comp->arg_cnt < argc - argn) { - fprintf(stderr, "mt: too many arguments for the command '%s'.\n", - comp->cmd_name); - exit(1); + fprintf(stderr, "mt: too many arguments for the command '%s'.\n", comp->cmd_name); + exit(1); } if (comp->cmd_fdtype != NO_FD) { - oflags = comp->cmd_fdtype == FD_RDONLY ? O_RDONLY : O_RDWR; - if ((comp->error_tests & ET_ONLINE) == 0) - oflags |= O_NONBLOCK; - if ((mtfd = open(tape_name, oflags)) < 0) { - perror(tape_name); - exit(1); - } - } - else - mtfd = (-1); + oflags = comp->cmd_fdtype == FD_RDONLY ? O_RDONLY : O_RDWR; + if ((comp->error_tests & ET_ONLINE) == 0) + oflags |= O_NONBLOCK; + if ((mtfd = open(tape_name, oflags)) < 0) { + perror(tape_name); + exit(1); + } + } else + mtfd = (-1); if (comp->cmd_function != NULL) { - i = comp->cmd_function(mtfd, comp, argc - argn, - (argc - argn > 0 ? argv + argn : NULL)); - if (i) { - if (errno == ENOSYS) - fprintf(stderr, "mt: Command not supported by this kernel.\n"); - else if (comp->error_tests != 0) - test_error(mtfd, comp); - } - } - else { - fprintf(stderr, "mt: Internal error: command without function.\n"); - i = 1; + i = comp->cmd_function(mtfd, comp, argc - argn, + (argc - argn > 0 ? argv + argn : NULL)); + if (i) { + if (errno == ENOSYS) + fprintf(stderr, "mt: Command not supported by this kernel.\n"); + else if (comp->error_tests != 0) + test_error(mtfd, comp); + } + } else { + fprintf(stderr, "mt: Internal error: command without function.\n"); + i = 1; } if (mtfd >= 0) - close(mtfd); + close(mtfd); return i; } - static void -version() +static void version() { - printf("mt-st v. %s\n", VERSION); - printf("default tape device: '%s'\n", DEFTAPE); - exit(0); + printf("mt-st v. %s\n", VERSION); + printf("default tape device: '%s'\n", DEFTAPE); + exit(0); } - static void -usage(int explain) +static void usage(int explain) { int ind; char line[100]; - fprintf(stderr, "usage: mt [-v] [--version] [-h] [ -f device ] command [ count ]\n"); + fprintf(stderr, "usage: mt [-v] [--version] [-h] [ -f device ] command [ " + "count ]\n"); if (explain) { - for (ind=0; cmds[ind].cmd_name != NULL; ) { - if (ind == 0) - strcpy(line, "commands: "); - else - strcpy(line, " "); - for ( ; cmds[ind].cmd_name != NULL; ind++) { - strcat(line, cmds[ind].cmd_name); - if (cmds[ind+1].cmd_name != NULL) - strcat(line, ", "); - else - strcat(line, "."); - if (strlen(line) >= 70 || cmds[ind+1].cmd_name == NULL) { - fprintf(stderr, "%s\n", line); - ind++; - break; - } - } - } + for (ind = 0; cmds[ind].cmd_name != NULL;) { + if (ind == 0) + strcpy(line, "commands: "); + else + strcpy(line, " "); + for (; cmds[ind].cmd_name != NULL; ind++) { + strcat(line, cmds[ind].cmd_name); + if (cmds[ind + 1].cmd_name != NULL) + strcat(line, ", "); + else + strcat(line, "."); + if (strlen(line) >= 70 || cmds[ind + 1].cmd_name == NULL) { + fprintf(stderr, "%s\n", line); + ind++; + break; + } + } + } } } - /* Do a command that simply feeds an argument to the MTIOCTOP ioctl */ - static int -do_standard(int mtfd, cmdef_tr *cmd, int argc, char **argv) +static int do_standard(int mtfd, cmdef_tr *cmd, int argc, char **argv) { int multiplier, max_count; struct mtop mt_com; @@ -425,32 +415,32 @@ do_standard(int mtfd, cmdef_tr *cmd, int argc, char **argv) mt_com.mt_op = cmd->cmd_code; mt_com.mt_count = (argc > 0 ? strtol(*argv, &endp, 0) : 1); if (argc > 0 && endp != *argv) { - multiplier = 1; - if (*endp == 'k') - multiplier = 1024; - else if (*endp == 'M') - multiplier = 1024 * 1024; - else if (*endp == 'G') - multiplier = 1024 * 1024 * 1024; - else if (*endp != 0) { - fprintf(stderr, "mt: illegal count unit.\n"); - return 3; - } - max_count = INT_MAX / multiplier; - if (abs(mt_com.mt_count) > max_count) { - fprintf(stderr, "mt: repeat count too large.\n"); - return 3; - } - mt_com.mt_count *= multiplier; + multiplier = 1; + if (*endp == 'k') + multiplier = 1024; + else if (*endp == 'M') + multiplier = 1024 * 1024; + else if (*endp == 'G') + multiplier = 1024 * 1024 * 1024; + else if (*endp != 0) { + fprintf(stderr, "mt: illegal count unit.\n"); + return 3; + } + max_count = INT_MAX / multiplier; + if (abs(mt_com.mt_count) > max_count) { + fprintf(stderr, "mt: repeat count too large.\n"); + return 3; + } + mt_com.mt_count *= multiplier; } mt_com.mt_count |= cmd->cmd_count_bits; if (mt_com.mt_op != MTMKPART && mt_com.mt_count < 0) { - fprintf(stderr, "mt: negative repeat count\n"); - return 1; + fprintf(stderr, "mt: negative repeat count\n"); + return 1; } if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } return 0; } @@ -458,33 +448,31 @@ do_standard(int mtfd, cmdef_tr *cmd, int argc, char **argv) /* The the drive buffering and other things with this (highly overloaded) ioctl function. (See also do_options below.) */ - static int -do_drvbuffer(int mtfd, cmdef_tr *cmd, int argc, char **argv) +static int do_drvbuffer(int mtfd, cmdef_tr *cmd, int argc, char **argv) { struct mtop mt_com; mt_com.mt_op = MTSETDRVBUFFER; mt_com.mt_count = (argc > 0 ? strtol(*argv, NULL, 0) : 1); if ((cmd->cmd_count_bits & MT_ST_OPTIONS) == MT_ST_DEF_OPTIONS) - mt_com.mt_count &= 0xfffff; + mt_com.mt_count &= 0xfffff; #ifdef MT_ST_TIMEOUTS else if ((cmd->cmd_count_bits & MT_ST_OPTIONS) == MT_ST_TIMEOUTS) - mt_com.mt_count &= 0x7ffffff; + mt_com.mt_count &= 0x7ffffff; #endif else - mt_com.mt_count &= 0xfffffff; + mt_com.mt_count &= 0xfffffff; mt_com.mt_count |= cmd->cmd_count_bits; if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } return 0; } /* Set the tape driver options */ - static int -do_options(int mtfd, cmdef_tr *cmd, int argc, char **argv) +static int do_options(int mtfd, cmdef_tr *cmd, int argc, char **argv) { int i, an; unsigned int len; @@ -492,63 +480,63 @@ do_options(int mtfd, cmdef_tr *cmd, int argc, char **argv) mt_com.mt_op = MTSETDRVBUFFER; if (argc == 0) - mt_com.mt_count = 0; + mt_com.mt_count = 0; else if (isdigit(**argv)) - mt_com.mt_count = strtol(*argv, NULL, 0) & ~MT_ST_OPTIONS; + mt_com.mt_count = strtol(*argv, NULL, 0) & ~MT_ST_OPTIONS; else - for (an = 0, mt_com.mt_count = 0; an < argc; an++) { - len = strlen(argv[an]); - for (i=0; boolean_tbl[i].name != NULL; i++) - if (!strncmp(boolean_tbl[i].name, argv[an], len)) { - mt_com.mt_count |= boolean_tbl[i].bitmask; - break; - } - if (boolean_tbl[i].name == NULL) { - fprintf(stderr, "Illegal property name '%s'.\n", argv[an]); - fprintf(stderr, "The implemented property names are:\n"); - for (i=0; boolean_tbl[i].name != NULL; i++) - fprintf(stderr, " %9s -> %s\n", boolean_tbl[i].name, - boolean_tbl[i].expl); - return 1; - } - if (len != strlen(boolean_tbl[i].name)) - for (i++ ; boolean_tbl[i].name != NULL; i++) - if (!strncmp(boolean_tbl[i].name, argv[an], len)) { - fprintf(stderr, "Property name '%s' ambiguous.\n", - argv[an]); - return 1; - } - } + for (an = 0, mt_com.mt_count = 0; an < argc; an++) { + len = strlen(argv[an]); + for (i = 0; boolean_tbl[i].name != NULL; i++) + if (!strncmp(boolean_tbl[i].name, argv[an], len)) { + mt_com.mt_count |= boolean_tbl[i].bitmask; + break; + } + if (boolean_tbl[i].name == NULL) { + fprintf(stderr, "Illegal property name '%s'.\n", argv[an]); + fprintf(stderr, "The implemented property names are:\n"); + for (i = 0; boolean_tbl[i].name != NULL; i++) + fprintf(stderr, " %9s -> %s\n", boolean_tbl[i].name, + boolean_tbl[i].expl); + return 1; + } + if (len != strlen(boolean_tbl[i].name)) + for (i++; boolean_tbl[i].name != NULL; i++) + if (!strncmp(boolean_tbl[i].name, argv[an], len)) { + fprintf(stderr, "Property name '%s' ambiguous.\n", argv[an]); + return 1; + } + } switch (cmd->cmd_code) { case DO_BOOLEANS: - mt_com.mt_count |= MT_ST_BOOLEANS; - break; + mt_com.mt_count |= MT_ST_BOOLEANS; + break; case SET_BOOLEANS: - mt_com.mt_count |= MT_ST_SETBOOLEANS; - break; + mt_com.mt_count |= MT_ST_SETBOOLEANS; + break; case CLEAR_BOOLEANS: - mt_com.mt_count |= MT_ST_CLEARBOOLEANS; - break; + mt_com.mt_count |= MT_ST_CLEARBOOLEANS; + break; } if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } return 0; } /* Tell where the tape is */ - static int -do_tell(int mtfd, cmdef_tr *cmd __attribute__((unused)), - int argc __attribute__((unused)), char **argv __attribute__((unused))) +static int do_tell(int mtfd, + cmdef_tr *cmd __attribute__((unused)), + int argc __attribute__((unused)), + char **argv __attribute__((unused))) { struct mtpos mt_pos; if (ioctl(mtfd, MTIOCPOS, (char *)&mt_pos) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } printf("At block %ld.\n", mt_pos.mt_blkno); return 0; @@ -556,22 +544,21 @@ do_tell(int mtfd, cmdef_tr *cmd __attribute__((unused)), /* Position the tape to a specific location within a specified partition */ - static int -do_partseek(int mtfd, cmdef_tr *cmd __attribute__((unused)), int argc, char **argv) +static int do_partseek(int mtfd, cmdef_tr *cmd __attribute__((unused)), int argc, char **argv) { struct mtop mt_com; mt_com.mt_op = MTSETPART; mt_com.mt_count = (argc > 0 ? strtol(*argv, NULL, 0) : 0); if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } mt_com.mt_op = MTSEEK; mt_com.mt_count = (argc > 1 ? strtol(argv[1], NULL, 0) : 0); if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } return 0; } @@ -579,35 +566,34 @@ do_partseek(int mtfd, cmdef_tr *cmd __attribute__((unused)), int argc, char **ar /* Position to start of file n. This might be implemented more intelligently some day. */ - static int -do_asf(int mtfd, cmdef_tr *cmd __attribute__((unused)), int argc, char **argv) +static int do_asf(int mtfd, cmdef_tr *cmd __attribute__((unused)), int argc, char **argv) { struct mtop mt_com; mt_com.mt_op = MTREW; mt_com.mt_count = 1; if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } mt_com.mt_count = (argc > 0 ? strtol(*argv, NULL, 0) : 0); if (mt_com.mt_count > 0) { - mt_com.mt_op = MTFSF; - if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { - perror(tape_name); - return 2; - } + mt_com.mt_op = MTFSF; + if (ioctl(mtfd, MTIOCTOP, (char *)&mt_com) < 0) { + perror(tape_name); + return 2; + } } return 0; } - /*** Decipher the status ***/ +/*** Decipher the status ***/ - static int -do_status(int mtfd, cmdef_tr *cmd __attribute__((unused)), - int argc __attribute__((unused)), - char **argv __attribute__((unused))) +static int do_status(int mtfd, + cmdef_tr *cmd __attribute__((unused)), + int argc __attribute__((unused)), + char **argv __attribute__((unused))) { struct mtget status; int dens; @@ -615,86 +601,80 @@ do_status(int mtfd, cmdef_tr *cmd __attribute__((unused)), char *type, *density; if (ioctl(mtfd, MTIOCGET, (char *)&status) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } if (status.mt_type == MT_ISSCSI1) - type = "SCSI 1"; + type = "SCSI 1"; else if (status.mt_type == MT_ISSCSI2) - type = "SCSI 2"; + type = "SCSI 2"; else if (status.mt_type == MT_ISONSTREAM_SC) - type = "OnStream SC-, DI-, DP-, or USB"; + type = "OnStream SC-, DI-, DP-, or USB"; else - type = NULL; + type = NULL; if (type == NULL) { - if (status.mt_type & 0x800000) - printf ("qic-117 drive type = 0x%05lx\n", status.mt_type & 0x1ffff); - else if (status.mt_type == 0) - printf("IDE-Tape (type code 0) ?\n"); - else - printf("Unknown tape drive type (type code %ld)\n", status.mt_type); - printf("File number=%d, block number=%d.\n", - status.mt_fileno, status.mt_blkno); - printf("mt_resid: %ld, mt_erreg: 0x%lx\n", - status.mt_resid, status.mt_erreg); - printf("mt_dsreg: 0x%lx, mt_gstat: 0x%lx\n", - status.mt_dsreg, status.mt_gstat); - } - else { - printf("%s tape drive:\n", type); - if (status.mt_type == MT_ISSCSI2) - printf("File number=%d, block number=%d, partition=%ld.\n", - status.mt_fileno, status.mt_blkno, (status.mt_resid & 0xff)); - else - printf("File number=%d, block number=%d.\n", - status.mt_fileno, status.mt_blkno); - if (status.mt_type == MT_ISSCSI1 || - status.mt_type == MT_ISSCSI2 || - status.mt_type == MT_ISONSTREAM_SC) { - dens = (status.mt_dsreg & MT_ST_DENSITY_MASK) >> MT_ST_DENSITY_SHIFT; - density = "no translation"; - for (i=0; i < NBR_DENSITIES; i++) - if (density_tbl[i].code == dens) { - density = density_tbl[i].name; - break; - } - printf("Tape block size %ld bytes. Density code 0x%x (%s).\n", - ((status.mt_dsreg & MT_ST_BLKSIZE_MASK) >> MT_ST_BLKSIZE_SHIFT), - dens, density); + if (status.mt_type & 0x800000) + printf("qic-117 drive type = 0x%05lx\n", status.mt_type & 0x1ffff); + else if (status.mt_type == 0) + printf("IDE-Tape (type code 0) ?\n"); + else + printf("Unknown tape drive type (type code %ld)\n", status.mt_type); + printf("File number=%d, block number=%d.\n", status.mt_fileno, status.mt_blkno); + printf("mt_resid: %ld, mt_erreg: 0x%lx\n", status.mt_resid, status.mt_erreg); + printf("mt_dsreg: 0x%lx, mt_gstat: 0x%lx\n", status.mt_dsreg, status.mt_gstat); + } else { + printf("%s tape drive:\n", type); + if (status.mt_type == MT_ISSCSI2) + printf("File number=%d, block number=%d, partition=%ld.\n", + status.mt_fileno, status.mt_blkno, (status.mt_resid & 0xff)); + else + printf("File number=%d, block number=%d.\n", status.mt_fileno, status.mt_blkno); + if (status.mt_type == MT_ISSCSI1 || status.mt_type == MT_ISSCSI2 || + status.mt_type == MT_ISONSTREAM_SC) { + dens = (status.mt_dsreg & MT_ST_DENSITY_MASK) >> MT_ST_DENSITY_SHIFT; + density = "no translation"; + for (i = 0; i < NBR_DENSITIES; i++) + if (density_tbl[i].code == dens) { + density = density_tbl[i].name; + break; + } + printf("Tape block size %ld bytes. Density code 0x%x (%s).\n", + ((status.mt_dsreg & MT_ST_BLKSIZE_MASK) >> MT_ST_BLKSIZE_SHIFT), + dens, density); - printf("Soft error count since last status=%ld\n", - (status.mt_erreg & MT_ST_SOFTERR_MASK) >> MT_ST_SOFTERR_SHIFT); - } + printf("Soft error count since last status=%ld\n", + (status.mt_erreg & MT_ST_SOFTERR_MASK) >> MT_ST_SOFTERR_SHIFT); + } } printf("General status bits on (%lx):\n", status.mt_gstat); if (GMT_EOF(status.mt_gstat)) - printf(" EOF"); + printf(" EOF"); if (GMT_BOT(status.mt_gstat)) - printf(" BOT"); + printf(" BOT"); if (GMT_EOT(status.mt_gstat)) - printf(" EOT"); + printf(" EOT"); if (GMT_SM(status.mt_gstat)) - printf(" SM"); + printf(" SM"); if (GMT_EOD(status.mt_gstat)) - printf(" EOD"); + printf(" EOD"); if (GMT_WR_PROT(status.mt_gstat)) - printf(" WR_PROT"); + printf(" WR_PROT"); if (GMT_ONLINE(status.mt_gstat)) - printf(" ONLINE"); + printf(" ONLINE"); if (GMT_D_6250(status.mt_gstat)) - printf(" D_6250"); + printf(" D_6250"); if (GMT_D_1600(status.mt_gstat)) - printf(" D_1600"); + printf(" D_1600"); if (GMT_D_800(status.mt_gstat)) - printf(" D_800"); + printf(" D_800"); if (GMT_DR_OPEN(status.mt_gstat)) - printf(" DR_OPEN"); + printf(" DR_OPEN"); if (GMT_IM_REP_EN(status.mt_gstat)) - printf(" IM_REP_EN"); + printf(" IM_REP_EN"); if (GMT_CLN(status.mt_gstat)) - printf(" CLN"); + printf(" CLN"); printf("\n"); return 0; } @@ -705,18 +685,17 @@ do_status(int mtfd, cmdef_tr *cmd __attribute__((unused)), #define ST_NBR_MODES (1 << ST_NBR_MODE_BITS) #define ST_MODE_SHIFT (7 - ST_NBR_MODE_BITS) #define ST_MODE_MASK ((ST_NBR_MODES - 1) << ST_MODE_SHIFT) -#define TAPE_NR(minor) ( (((minor) & ~255) >> (ST_NBR_MODE_BITS + 1)) | \ - ((minor) & ~(-1 << ST_MODE_SHIFT)) ) -#define TAPE_MODE(minor) (((minor) & ST_MODE_MASK) >> ST_MODE_SHIFT) -static const char *st_formats[] = { - "", "r", "k", "s", "l", "t", "o", "u", - "m", "v", "p", "x", "a", "y", "q", "z"}; +#define TAPE_NR(minor) \ + ((((minor) & ~255) >> (ST_NBR_MODE_BITS + 1)) | ((minor) & ~(-1 << ST_MODE_SHIFT))) +#define TAPE_MODE(minor) (((minor)&ST_MODE_MASK) >> ST_MODE_SHIFT) +static const char *st_formats[] = { "", "r", "k", "s", "l", "t", "o", "u", + "m", "v", "p", "x", "a", "y", "q", "z" }; /* Show the options if visible in sysfs */ static int do_show_options(int mtfd, - cmdef_tr *cmd __attribute__((unused)), - int argc __attribute__((unused)), - char **argv __attribute__((unused))) + cmdef_tr *cmd __attribute__((unused)), + int argc __attribute__((unused)), + char **argv __attribute__((unused))) { int i, fd, options, tapeminor, tapeno, tapemode; struct stat stat; @@ -724,42 +703,40 @@ static int do_show_options(int mtfd, char fname[100], buf[20]; if (uname(&uts) < 0) { - perror(tape_name); - return 2; + perror(tape_name); + return 2; } sscanf(uts.release, "%d.%d.%d", &i, &tapeno, &tapemode); if (fstat(mtfd, &stat) < 0) { - perror(tape_name); - return 1; + perror(tape_name); + return 1; } if (!(stat.st_mode & S_IFCHR)) { - fprintf(stderr, "mt: not a character device.\n"); - return 1; + fprintf(stderr, "mt: not a character device.\n"); + return 1; } tapeminor = minor(stat.st_rdev); tapeno = TAPE_NR(tapeminor); tapemode = TAPE_MODE(tapeminor); - tapemode <<= 4 - ST_NBR_MODE_BITS; /* from st.c */ - sprintf(fname, "/sys/class/scsi_tape/st%d%s/options", tapeno, - st_formats[tapemode]); + tapemode <<= 4 - ST_NBR_MODE_BITS; /* from st.c */ + sprintf(fname, "/sys/class/scsi_tape/st%d%s/options", tapeno, st_formats[tapemode]); /* printf("Trying file '%s' (st_rdev 0x%lx).\n", fname, stat.st_rdev); */ - if ((fd = open(fname, O_RDONLY)) < 0 || - read(fd, buf, 20) < 0) { - fprintf(stderr, "Can't read the sysfs file '%s'.\n", fname); - return 2; + if ((fd = open(fname, O_RDONLY)) < 0 || read(fd, buf, 20) < 0) { + fprintf(stderr, "Can't read the sysfs file '%s'.\n", fname); + return 2; } close(fd); options = strtol(buf, NULL, 0); printf("The options set:"); - for (i=0; boolean_tbl[i].name != NULL; i++) - if (options & boolean_tbl[i].bitmask) - printf(" %s", boolean_tbl[i].name); + for (i = 0; boolean_tbl[i].name != NULL; i++) + if (options & boolean_tbl[i].bitmask) + printf(" %s", boolean_tbl[i].name); printf("\n"); return 0; @@ -767,42 +744,42 @@ static int do_show_options(int mtfd, /* Print a list of possible density codes */ - static int -print_densities(int fd __attribute__((unused)), - cmdef_tr *cmd __attribute__((unused)), - int argc __attribute__((unused)), - char **argv __attribute__((unused))) +static int print_densities(int fd __attribute__((unused)), + cmdef_tr *cmd __attribute__((unused)), + int argc __attribute__((unused)), + char **argv __attribute__((unused))) { unsigned int i, offset; - printf("Some SCSI tape density codes:\ncode explanation code explanation\n"); + printf("Some SCSI tape density codes:\ncode explanation " + " code explanation\n"); offset = (NBR_DENSITIES + 1) / 2; - for (i=0; i < offset; i++) { - printf("0x%02x %-28s", density_tbl[i].code, density_tbl[i].name); - if (i + offset < NBR_DENSITIES) - printf(" 0x%02x %s\n", density_tbl[i + offset].code, density_tbl[i + offset].name); - else - printf("\n"); + for (i = 0; i < offset; i++) { + printf("0x%02x %-28s", density_tbl[i].code, density_tbl[i].name); + if (i + offset < NBR_DENSITIES) + printf(" 0x%02x %s\n", density_tbl[i + offset].code, + density_tbl[i + offset].name); + else + printf("\n"); } return 0; } /* Try to find out why the command failed */ - static void -test_error(int mtfd, cmdef_tr *cmd) +static void test_error(int mtfd, cmdef_tr *cmd) { struct mtget status; if (ioctl(mtfd, MTIOCGET, (char *)&status) < 0) - return; + return; if (status.mt_type != MT_ISSCSI1 && status.mt_type != MT_ISSCSI2) - return; + return; if ((cmd->error_tests & ET_ONLINE) && !GMT_ONLINE(status.mt_gstat)) - fprintf(stderr, "mt: The device is offline (not powered on, no tape ?).\n"); + fprintf(stderr, + "mt: The device is offline (not powered on, no tape ?).\n"); if ((cmd->error_tests & ET_WPROT) && !GMT_WR_PROT(status.mt_gstat)) - fprintf(stderr, "mt: The tape is write-protected.\n"); + fprintf(stderr, "mt: The tape is write-protected.\n"); } - diff --git a/stinit.c b/stinit.c index 27fadc1..acf6db4 100644 --- a/stinit.c +++ b/stinit.c @@ -30,7 +30,7 @@ #define TRUE 1 #define FALSE 0 #endif -#define SKIP_WHITE(p) for ( ; *p == ' ' || *p == '\t'; p++) +#define SKIP_WHITE(p) for (; *p == ' ' || *p == '\t'; p++) typedef struct _modepar_tr { int defined; @@ -73,47 +73,41 @@ typedef struct _devdef_tr { static int verbose = 0; /* The device directories being searched */ -typedef struct -{ +typedef struct { char dir[PATH_MAX]; int selective_scan; } devdir; -static devdir devdirs[] = { {"/dev/scsi", 0}, {"/dev", 1}, {"", 0}}; +static devdir devdirs[] = { { "/dev/scsi", 0 }, { "/dev", 1 }, { "", 0 } }; -#define DEVFS_PATH "/dev/tapes" +#define DEVFS_PATH "/dev/tapes" #define DEVFS_TAPEFMT DEVFS_PATH "/tape%d" /* The partial names of the tape devices being included in the search in selective scan */ -static char *tape_name_bases[] = { - "st", "nst", "rmt", "nrmt", "tape", NULL}; +static char *tape_name_bases[] = { "st", "nst", "rmt", "nrmt", "tape", NULL }; /* The list of standard definition files being searched */ -static char *std_databases[] = { - "/etc/stinit.def", - NULL}; +static char *std_databases[] = { "/etc/stinit.def", NULL }; - static FILE * -open_database(char *base) +static FILE *open_database(char *base) { int i; FILE *f; if (base != NULL) { - if ((f = fopen(base, "r")) == NULL) - fprintf(stderr, "stinit: Can't find SCSI tape database '%s'.\n", - base); - return f; + if ((f = fopen(base, "r")) == NULL) + fprintf(stderr, "stinit: Can't find SCSI tape database '%s'.\n", base); + return f; } - for (i=0; std_databases[i] != NULL; i++) { - if (verbose > 1) - fprintf(stderr, "Trying to open database '%s'.\n", std_databases[i]); - if ((f = fopen(std_databases[i], "r")) != NULL) { - if (verbose > 1) - fprintf(stderr, "Open succeeded.\n"); - return f; - } + for (i = 0; std_databases[i] != NULL; i++) { + if (verbose > 1) + fprintf(stderr, "Trying to open database '%s'.\n", std_databases[i]); + if ((f = fopen(std_databases[i], "r")) != NULL) { + if (verbose > 1) + fprintf(stderr, "Open succeeded.\n"); + return f; + } } fprintf(stderr, "Can't find the tape characteristics database.\n"); @@ -121,138 +115,131 @@ open_database(char *base) } - static char * -find_string(char *s, char *target, char *buf, int buflen) +static char *find_string(char *s, char *target, char *buf, int buflen) { int have_arg; char *cp, *cp2, c, *argp; if (buf != NULL && buflen > 0) - *buf = '\0'; + *buf = '\0'; - for ( ; *s != '\0'; ) { - SKIP_WHITE(s); - if (isalpha(*s)) { - for (cp=s ; isalnum(*cp) || *cp == '-'; cp++) - ; - cp2 = cp; - SKIP_WHITE(cp); - if (*cp == '=') { - cp++; - SKIP_WHITE(cp); - if (*cp == '"') { - cp++; - for (cp2=cp; *cp2 != '"' && *cp2 != '\0'; cp2++) - ; - } - else - for (cp2=cp+1; isalnum(*cp2) || *cp2 == '-'; cp2++) - ; - if (*cp2 == '\0') - return NULL; - have_arg = TRUE; - argp = cp; - } - else { - have_arg = FALSE; - argp = "1"; - } + for (; *s != '\0';) { + SKIP_WHITE(s); + if (isalpha(*s)) { + for (cp = s; isalnum(*cp) || *cp == '-'; cp++) + ; + cp2 = cp; + SKIP_WHITE(cp); + if (*cp == '=') { + cp++; + SKIP_WHITE(cp); + if (*cp == '"') { + cp++; + for (cp2 = cp; *cp2 != '"' && *cp2 != '\0'; cp2++) + ; + } else + for (cp2 = cp + 1; isalnum(*cp2) || *cp2 == '-'; cp2++) + ; + if (*cp2 == '\0') + return NULL; + have_arg = TRUE; + argp = cp; + } else { + have_arg = FALSE; + argp = "1"; + } - if (!strncmp(target, s, strlen(target))) { - c = *cp2; - *cp2 = '\0'; - if (buf == NULL) - buf = strdup(argp); - else { - if (strlen(argp) < (unsigned int)buflen) - strcpy(buf, argp); - else { - strncpy(buf, argp, buflen); - buf[buflen - 1] = '\0'; - } - } - if (have_arg && c == '"') - cp2++; - else - *cp2 = c; - if (*cp2 != '\0') - memmove(s, cp2, strlen(cp2) + 1); - else - *s = '\0'; - return buf; - } - s = cp2; - } - else - for ( ; *s != '\0' && *s != ' ' && *s != '\t'; s++) - ; + if (!strncmp(target, s, strlen(target))) { + c = *cp2; + *cp2 = '\0'; + if (buf == NULL) + buf = strdup(argp); + else { + if (strlen(argp) < (unsigned int)buflen) + strcpy(buf, argp); + else { + strncpy(buf, argp, buflen); + buf[buflen - 1] = '\0'; + } + } + if (have_arg && c == '"') + cp2++; + else + *cp2 = c; + if (*cp2 != '\0') + memmove(s, cp2, strlen(cp2) + 1); + else + *s = '\0'; + return buf; + } + s = cp2; + } else + for (; *s != '\0' && *s != ' ' && *s != '\t'; s++) + ; } return NULL; } - static int -num_arg(char *t) +static int num_arg(char *t) { int nbr; char *tt; nbr = strtol(t, &tt, 0); if (t != tt) { - if (*tt == 'k') - nbr *= 1024; - else if (*tt == 'M') - nbr *= 1024 * 1024; + if (*tt == 'k') + nbr *= 1024; + else if (*tt == 'M') + nbr *= 1024 * 1024; } return nbr; } - static int -next_block(FILE *dbf, char *buf, size_t buflen, int limiter) +static int next_block(FILE *dbf, char *buf, size_t buflen, int limiter) { size_t len; char *cp, *bp; static char lbuf[LINEMAX]; - if (limiter == 0) { /* Restart */ - rewind(dbf); - lbuf[0] = '\0'; - return TRUE; + if (limiter == 0) { /* Restart */ + rewind(dbf); + lbuf[0] = '\0'; + return TRUE; } - for (len = 0 ; ; ) { - bp = buf + len; - if ((cp = strchr(lbuf, limiter)) != NULL) { - *cp = '\0'; - strcpy(bp, lbuf); - cp++; - SKIP_WHITE(cp); - memmove(lbuf, cp, strlen(cp) + 1); - return TRUE; - } - if (len + strlen(lbuf) >= buflen) { - fprintf(stderr, "Too long definition: '%s'\n", buf); - return FALSE; - } - cp = lbuf; - SKIP_WHITE(cp); - strcpy(bp, cp); - strcat(bp, " "); - len += strlen(cp) + 1; - if (fgets(lbuf, LINEMAX, dbf) == NULL) - return FALSE; - if ((cp = strchr(lbuf, '#')) != NULL) - *cp = '\0'; - else - lbuf[strlen(lbuf) - 1] = '\0'; + for (len = 0;;) { + bp = buf + len; + if ((cp = strchr(lbuf, limiter)) != NULL) { + *cp = '\0'; + strcpy(bp, lbuf); + cp++; + SKIP_WHITE(cp); + memmove(lbuf, cp, strlen(cp) + 1); + return TRUE; + } + if (len + strlen(lbuf) >= buflen) { + fprintf(stderr, "Too long definition: '%s'\n", buf); + return FALSE; + } + cp = lbuf; + SKIP_WHITE(cp); + strcpy(bp, cp); + strcat(bp, " "); + len += strlen(cp) + 1; + if (fgets(lbuf, LINEMAX, dbf) == NULL) + return FALSE; + if ((cp = strchr(lbuf, '#')) != NULL) + *cp = '\0'; + else + lbuf[strlen(lbuf) - 1] = '\0'; } } - static int -find_pars(FILE *dbf, char *company, char *product, char *rev, devdef_tr *defs, - int parse_only) +static int +find_pars(FILE *dbf, char *company, char *product, char *rev, devdef_tr *defs, int parse_only) { int i, mode, modes_defined, errors; char line[LINEMAX], defstr[DEFMAX], comdef[DEFMAX], modebuf[DEFMAX]; @@ -267,199 +254,191 @@ find_pars(FILE *dbf, char *company, char *product, char *rev, devdef_tr *defs, defs->cleaning = (-1); defs->nowait = (-1); defs->sili = (-1); - for (i=0; i < NBR_MODES; i++) { - defs->modedefs[i].defined = FALSE; - defs->modedefs[i].blocksize = (-1); - defs->modedefs[i].density = (-1); - defs->modedefs[i].buffer_writes = (-1); - defs->modedefs[i].async_writes = (-1); - defs->modedefs[i].read_ahead = (-1); - defs->modedefs[i].two_fm = (-1); - defs->modedefs[i].compression = (-1); - defs->modedefs[i].auto_lock = (-1); - defs->modedefs[i].fast_eod = (-1); - defs->modedefs[i].can_bsr = (-1); - defs->modedefs[i].no_blklimits = (-1); - defs->modedefs[i].can_partitions = (-1); - defs->modedefs[i].scsi2logical = (-1); - defs->modedefs[i].sysv = (-1); - defs->modedefs[i].defs_for_writes = (-1); + for (i = 0; i < NBR_MODES; i++) { + defs->modedefs[i].defined = FALSE; + defs->modedefs[i].blocksize = (-1); + defs->modedefs[i].density = (-1); + defs->modedefs[i].buffer_writes = (-1); + defs->modedefs[i].async_writes = (-1); + defs->modedefs[i].read_ahead = (-1); + defs->modedefs[i].two_fm = (-1); + defs->modedefs[i].compression = (-1); + defs->modedefs[i].auto_lock = (-1); + defs->modedefs[i].fast_eod = (-1); + defs->modedefs[i].can_bsr = (-1); + defs->modedefs[i].no_blklimits = (-1); + defs->modedefs[i].can_partitions = (-1); + defs->modedefs[i].scsi2logical = (-1); + defs->modedefs[i].sysv = (-1); + defs->modedefs[i].defs_for_writes = (-1); } next_block(dbf, NULL, 0, 0); /* Find matching inquiry block */ - for (errors=0 ; ; ) { + for (errors = 0;;) { - if (!next_block(dbf, defstr, DEFMAX, '{')) - break; + if (!next_block(dbf, defstr, DEFMAX, '{')) + break; - find_string(defstr, "manuf", tmpcomp, LINEMAX); - find_string(defstr, "model", tmpprod, LINEMAX); - find_string(defstr, "rev", tmprev, LINEMAX); + find_string(defstr, "manuf", tmpcomp, LINEMAX); + find_string(defstr, "model", tmpprod, LINEMAX); + find_string(defstr, "rev", tmprev, LINEMAX); - if (!next_block(dbf, defstr, DEFMAX, '}')) { - fprintf(stderr, - "End of definition block not found for ('%s', '%s', '%s').\n", - tmpcomp, tmpprod, tmprev); - return FALSE; - } + if (!next_block(dbf, defstr, DEFMAX, '}')) { + fprintf(stderr, "End of definition block not found for ('%s', " + "'%s', '%s').\n", + tmpcomp, tmpprod, tmprev); + return FALSE; + } - if (!parse_only) { - if (tmpcomp[0] != '\0' && - strncmp(company, tmpcomp, strlen(tmpcomp))) - continue; - if (tmpprod[0] != '\0' && - strncmp(product, tmpprod, strlen(tmpprod))) - continue; - if (tmprev[0] != '\0' && - strncmp(rev, tmprev, strlen(tmprev))) - continue; - } - else if (verbose > 0) - printf("\nParsing modes for ('%s', '%s', '%s').\n", - tmpcomp, tmpprod, tmprev); + if (!parse_only) { + if (tmpcomp[0] != '\0' && strncmp(company, tmpcomp, strlen(tmpcomp))) + continue; + if (tmpprod[0] != '\0' && strncmp(product, tmpprod, strlen(tmpprod))) + continue; + if (tmprev[0] != '\0' && strncmp(rev, tmprev, strlen(tmprev))) + continue; + } else if (verbose > 0) + printf("\nParsing modes for ('%s', '%s', '%s').\n", tmpcomp, tmpprod, tmprev); - /* Block found, get the characteristics */ - for (nextdef=defstr; *nextdef != '\0' && - (*nextdef != 'm' || strncmp(nextdef, "mode", 2)); nextdef++) - ; - c = *nextdef; - *nextdef = '\0'; - strcpy(comdef, defstr); - *nextdef = c; - comptr = comdef; - SKIP_WHITE(comptr); + /* Block found, get the characteristics */ + for (nextdef = defstr; + *nextdef != '\0' && (*nextdef != 'm' || strncmp(nextdef, "mode", 2)); nextdef++) + ; + c = *nextdef; + *nextdef = '\0'; + strcpy(comdef, defstr); + *nextdef = c; + comptr = comdef; + SKIP_WHITE(comptr); - for ( ; *nextdef != '\0'; ) { - curdef = nextdef; - SKIP_WHITE(curdef); - for (nextdef++ ; *nextdef != '\0' && - (*nextdef != 'm' || strncmp(nextdef, "mode", 2)); nextdef++) - ; - c = *nextdef; - *nextdef = '\0'; + for (; *nextdef != '\0';) { + curdef = nextdef; + SKIP_WHITE(curdef); + for (nextdef++; *nextdef != '\0' && + (*nextdef != 'm' || strncmp(nextdef, "mode", 2)); + nextdef++) + ; + c = *nextdef; + *nextdef = '\0'; - mode = strtol(curdef + 4, &cp, 0) - 1; - if (mode < 0 || mode >= NBR_MODES) { - fprintf(stderr, - "Illegal mode for ('%s', '%s', '%s'):\n'%s'\n", - tmpcomp, tmpprod, tmprev, curdef); - *nextdef = c; - errors++; - continue; - } + mode = strtol(curdef + 4, &cp, 0) - 1; + if (mode < 0 || mode >= NBR_MODES) { + fprintf(stderr, "Illegal mode for ('%s', '%s', '%s'):\n'%s'\n", + tmpcomp, tmpprod, tmprev, curdef); + *nextdef = c; + errors++; + continue; + } - strcpy(modebuf, comptr); - strcat(modebuf, cp); - *nextdef = c; + strcpy(modebuf, comptr); + strcat(modebuf, cp); + *nextdef = c; - if (verbose > 1) - fprintf(stderr, "Mode %d definition: %s\n", mode + 1, modebuf); + if (verbose > 1) + fprintf(stderr, "Mode %d definition: %s\n", mode + 1, modebuf); - if ((t = find_string(modebuf, "disab", line, LINEMAX)) != NULL && - strtol(t, NULL, 0) != 0) { - defs->modedefs[mode].defined = FALSE; - continue; - } + if ((t = find_string(modebuf, "disab", line, LINEMAX)) != NULL && + strtol(t, NULL, 0) != 0) { + defs->modedefs[mode].defined = FALSE; + continue; + } - if ((t = find_string(modebuf, "drive-", line, LINEMAX)) != NULL) - defs->drive_buffering = num_arg(t); - if ((t = find_string(modebuf, "timeout", line, LINEMAX)) != NULL) - defs->timeout = num_arg(t); - if ((t = find_string(modebuf, "long-time", line, LINEMAX)) != NULL) - defs->long_timeout = num_arg(t); - if ((t = find_string(modebuf, "clean", line, LINEMAX)) != NULL) - defs->cleaning = num_arg(t); - if ((t = find_string(modebuf, "no-w", line, LINEMAX)) != NULL) - defs->nowait = num_arg(t); - if ((t = find_string(modebuf, "sili", line, LINEMAX)) != NULL) - defs->sili = num_arg(t); + if ((t = find_string(modebuf, "drive-", line, LINEMAX)) != NULL) + defs->drive_buffering = num_arg(t); + if ((t = find_string(modebuf, "timeout", line, LINEMAX)) != NULL) + defs->timeout = num_arg(t); + if ((t = find_string(modebuf, "long-time", line, LINEMAX)) != NULL) + defs->long_timeout = num_arg(t); + if ((t = find_string(modebuf, "clean", line, LINEMAX)) != NULL) + defs->cleaning = num_arg(t); + if ((t = find_string(modebuf, "no-w", line, LINEMAX)) != NULL) + defs->nowait = num_arg(t); + if ((t = find_string(modebuf, "sili", line, LINEMAX)) != NULL) + defs->sili = num_arg(t); - defs->modedefs[mode].defined = TRUE; - if ((t = find_string(modebuf, "block", line, LINEMAX)) != NULL) - defs->modedefs[mode].blocksize = num_arg(t); - if ((t = find_string(modebuf, "dens", line, LINEMAX)) != NULL) - defs->modedefs[mode].density = num_arg(t); - if ((t = find_string(modebuf, "buff", line, LINEMAX)) != NULL) - defs->modedefs[mode].buffer_writes = num_arg(t); - if ((t = find_string(modebuf, "async", line, LINEMAX)) != NULL) - defs->modedefs[mode].async_writes = num_arg(t); - if ((t = find_string(modebuf, "read", line, LINEMAX)) != NULL) - defs->modedefs[mode].read_ahead = num_arg(t); - if ((t = find_string(modebuf, "two", line, LINEMAX)) != NULL) - defs->modedefs[mode].two_fm = num_arg(t); - if ((t = find_string(modebuf, "comp", line, LINEMAX)) != NULL) - defs->modedefs[mode].compression = num_arg(t); - if ((t = find_string(modebuf, "auto", line, LINEMAX)) != NULL) - defs->modedefs[mode].auto_lock = num_arg(t); - if ((t = find_string(modebuf, "fast", line, LINEMAX)) != NULL) - defs->modedefs[mode].fast_eod = num_arg(t); - if ((t = find_string(modebuf, "can-b", line, LINEMAX)) != NULL) - defs->modedefs[mode].can_bsr = num_arg(t); - if ((t = find_string(modebuf, "noblk", line, LINEMAX)) != NULL) - defs->modedefs[mode].no_blklimits = num_arg(t); - if ((t = find_string(modebuf, "can-p", line, LINEMAX)) != NULL) - defs->modedefs[mode].can_partitions = num_arg(t); - if ((t = find_string(modebuf, "scsi2", line, LINEMAX)) != NULL) - defs->modedefs[mode].scsi2logical = num_arg(t); - if ((t = find_string(modebuf, "sysv", line, LINEMAX)) != NULL) - defs->modedefs[mode].sysv = num_arg(t); - if ((t = find_string(modebuf, "defs-for-w", line, LINEMAX)) != NULL) - defs->modedefs[mode].defs_for_writes = num_arg(t); + defs->modedefs[mode].defined = TRUE; + if ((t = find_string(modebuf, "block", line, LINEMAX)) != NULL) + defs->modedefs[mode].blocksize = num_arg(t); + if ((t = find_string(modebuf, "dens", line, LINEMAX)) != NULL) + defs->modedefs[mode].density = num_arg(t); + if ((t = find_string(modebuf, "buff", line, LINEMAX)) != NULL) + defs->modedefs[mode].buffer_writes = num_arg(t); + if ((t = find_string(modebuf, "async", line, LINEMAX)) != NULL) + defs->modedefs[mode].async_writes = num_arg(t); + if ((t = find_string(modebuf, "read", line, LINEMAX)) != NULL) + defs->modedefs[mode].read_ahead = num_arg(t); + if ((t = find_string(modebuf, "two", line, LINEMAX)) != NULL) + defs->modedefs[mode].two_fm = num_arg(t); + if ((t = find_string(modebuf, "comp", line, LINEMAX)) != NULL) + defs->modedefs[mode].compression = num_arg(t); + if ((t = find_string(modebuf, "auto", line, LINEMAX)) != NULL) + defs->modedefs[mode].auto_lock = num_arg(t); + if ((t = find_string(modebuf, "fast", line, LINEMAX)) != NULL) + defs->modedefs[mode].fast_eod = num_arg(t); + if ((t = find_string(modebuf, "can-b", line, LINEMAX)) != NULL) + defs->modedefs[mode].can_bsr = num_arg(t); + if ((t = find_string(modebuf, "noblk", line, LINEMAX)) != NULL) + defs->modedefs[mode].no_blklimits = num_arg(t); + if ((t = find_string(modebuf, "can-p", line, LINEMAX)) != NULL) + defs->modedefs[mode].can_partitions = num_arg(t); + if ((t = find_string(modebuf, "scsi2", line, LINEMAX)) != NULL) + defs->modedefs[mode].scsi2logical = num_arg(t); + if ((t = find_string(modebuf, "sysv", line, LINEMAX)) != NULL) + defs->modedefs[mode].sysv = num_arg(t); + if ((t = find_string(modebuf, "defs-for-w", line, LINEMAX)) != NULL) + defs->modedefs[mode].defs_for_writes = num_arg(t); - for (t=modebuf; *t == ' ' || *t == '\t'; t++) - ; - if (*t != '\0' && call_nbr <= 1) { - fprintf(stderr, - "Warning: errors in definition for ('%s', '%s', '%s'):\n%s\n", - tmpcomp, tmpprod, tmprev, modebuf); - errors++; - } - } + for (t = modebuf; *t == ' ' || *t == '\t'; t++) + ; + if (*t != '\0' && call_nbr <= 1) { + fprintf(stderr, "Warning: errors in definition for ('%s', " + "'%s', '%s'):\n%s\n", + tmpcomp, tmpprod, tmprev, modebuf); + errors++; + } + } } if (parse_only) { - if (verbose > 0) - printf("\n"); - printf("Definition parse completed. "); - if (errors) { - printf("Errors found!\n"); - return FALSE; - } - else { - printf("No errors found.\n"); - return TRUE; - } - } - else { - for (i=modes_defined=0; i < NBR_MODES; i++) - if (defs->modedefs[i].defined) - modes_defined++; - if (modes_defined == 0) { - fprintf(stderr, - "Warning: No modes in definition for ('%s', '%s', '%s').\n", - tmpcomp, tmpprod, tmprev); - errors++; - } + if (verbose > 0) + printf("\n"); + printf("Definition parse completed. "); + if (errors) { + printf("Errors found!\n"); + return FALSE; + } else { + printf("No errors found.\n"); + return TRUE; + } + } else { + for (i = modes_defined = 0; i < NBR_MODES; i++) + if (defs->modedefs[i].defined) + modes_defined++; + if (modes_defined == 0) { + fprintf(stderr, + "Warning: No modes in definition for ('%s', '%s', '%s').\n", + tmpcomp, tmpprod, tmprev); + errors++; + } } if (modes_defined) - return TRUE; + return TRUE; return FALSE; } static int sg_io_errcheck(struct sg_io_hdr *hdp) { - if ((hdp->status & 0x7e) == 0 || hdp->host_status == 0 || - hdp->driver_status == 0) - return 0; + if ((hdp->status & 0x7e) == 0 || hdp->host_status == 0 || hdp->driver_status == 0) + return 0; return EIO; } #define INQUIRY 0x12 -#define INQUIRY_CMDLEN 6 +#define INQUIRY_CMDLEN 6 #define SENSE_BUFF_LEN 32 #define DEF_TIMEOUT 60000 @@ -468,26 +447,24 @@ static int sg_io_errcheck(struct sg_io_hdr *hdp) #endif #define IOCTL_HEADER_LENGTH 8 - static int -do_inquiry(char *tname, char *company, char *product, char *rev, int print_non_found) +static int do_inquiry(char *tname, char *company, char *product, char *rev, int print_non_found) { int fn; int result, *ip, i; #define BUFLEN 256 unsigned char buffer[BUFLEN], *cmd, *inqptr; struct sg_io_hdr io_hdr; - unsigned char inqCmdBlk[INQUIRY_CMDLEN] = {INQUIRY, 0, 0, 0, 200, 0}; + unsigned char inqCmdBlk[INQUIRY_CMDLEN] = { INQUIRY, 0, 0, 0, 200, 0 }; unsigned char sense_b[SENSE_BUFF_LEN]; if ((fn = open(tname, O_RDONLY | O_NONBLOCK)) < 0) { - if (print_non_found || verbose > 0) { - if (errno == ENXIO) - fprintf(stderr, "Device '%s' not found by kernel.\n", tname); - else - fprintf(stderr, "Can't open tape device '%s' (errno %d).\n", - tname, errno); - } - return FALSE; + if (print_non_found || verbose > 0) { + if (errno == ENXIO) + fprintf(stderr, "Device '%s' not found by kernel.\n", tname); + else + fprintf(stderr, "Can't open tape device '%s' (errno %d).\n", tname, errno); + } + return FALSE; } /* Try SG_IO first, if it is not supported, use SCSI_IOCTL_SEND_COMMAND */ @@ -505,42 +482,41 @@ do_inquiry(char *tname, char *company, char *product, char *rev, int print_non_f result = ioctl(fn, SG_IO, &io_hdr); if (!result) - result = sg_io_errcheck(&io_hdr); + result = sg_io_errcheck(&io_hdr); if (result) { - if (errno == ENOTTY || errno == EINVAL) { - memset(buffer, 0, BUFLEN); - ip = (int *)&(buffer[0]); - *ip = 0; - *(ip+1) = BUFLEN - 13; + if (errno == ENOTTY || errno == EINVAL) { + memset(buffer, 0, BUFLEN); + ip = (int *)&(buffer[0]); + *ip = 0; + *(ip + 1) = BUFLEN - 13; - cmd = &(buffer[8]); - cmd[0] = INQUIRY; - cmd[4] = 200; + cmd = &(buffer[8]); + cmd[0] = INQUIRY; + cmd[4] = 200; - result = ioctl(fn, SCSI_IOCTL_SEND_COMMAND, buffer); - inqptr = buffer + IOCTL_HEADER_LENGTH; - } - if (result) { - close(fn); - sprintf((char *)buffer, - "The SCSI INQUIRY for device '%s' failed (power off?)", - tname); - perror((char *)buffer); - return FALSE; - } + result = ioctl(fn, SCSI_IOCTL_SEND_COMMAND, buffer); + inqptr = buffer + IOCTL_HEADER_LENGTH; + } + if (result) { + close(fn); + sprintf((char *)buffer, + "The SCSI INQUIRY for device '%s' failed (power off?)", tname); + perror((char *)buffer); + return FALSE; + } } memcpy(company, inqptr + 8, 8); - for (i=8; i > 0 && company[i-1] == ' '; i--) - ; + for (i = 8; i > 0 && company[i - 1] == ' '; i--) + ; company[i] = '\0'; memcpy(product, inqptr + 16, 16); - for (i=16; i > 0 && product[i-1] == ' '; i--) - ; + for (i = 16; i > 0 && product[i - 1] == ' '; i--) + ; product[i] = '\0'; memcpy(rev, inqptr + 32, 4); - for (i=4; i > 0 && rev[i-1] == ' '; i--) - ; + for (i = 4; i > 0 && rev[i - 1] == ' '; i--) + ; rev[i] = '\0'; close(fn); @@ -548,8 +524,7 @@ do_inquiry(char *tname, char *company, char *product, char *rev, int print_non_f } - static int -tapenum(char *name) +static int tapenum(char *name) { int dev; struct dirent *dent; @@ -559,61 +534,56 @@ tapenum(char *name) const devdir *dvd; struct stat statbuf; - if (strchr(name, '/') != NULL) { /* Complete name */ - if (stat(name, &statbuf) != 0) { - fprintf(stderr, "Can't stat '%s'.\n", name); - return (-1); - } - if (!S_ISCHR(statbuf.st_mode) || - major(statbuf.st_rdev) != SCSI_TAPE_MAJOR) - return (-1); - dev = minor(statbuf.st_rdev) & 31; - return dev; - } - else { /* Search from the device directories */ - for (dvd=devdirs; dvd->dir[0] != 0; dvd++) { - dn = dvd->dir; - if ((dirp = opendir(dn)) == NULL) - continue; + if (strchr(name, '/') != NULL) { /* Complete name */ + if (stat(name, &statbuf) != 0) { + fprintf(stderr, "Can't stat '%s'.\n", name); + return (-1); + } + if (!S_ISCHR(statbuf.st_mode) || major(statbuf.st_rdev) != SCSI_TAPE_MAJOR) + return (-1); + dev = minor(statbuf.st_rdev) & 31; + return dev; + } else { /* Search from the device directories */ + for (dvd = devdirs; dvd->dir[0] != 0; dvd++) { + dn = dvd->dir; + if ((dirp = opendir(dn)) == NULL) + continue; - for ( ; (dent = readdir(dirp)) != NULL; ) - if (!strcmp(dent->d_name, name)) { - strcpy(tmpname, dn); - strcat(tmpname, "/"); - strcat(tmpname, dent->d_name); - if (stat(tmpname, &statbuf) != 0) { - fprintf(stderr, "Can't stat '%s'.\n", tmpname); - continue; - } - if (!S_ISCHR(statbuf.st_mode) || - major(statbuf.st_rdev) != SCSI_TAPE_MAJOR) - continue; - dev = minor(statbuf.st_rdev) & 31; - closedir(dirp); - return dev; - } - closedir(dirp); - } + for (; (dent = readdir(dirp)) != NULL;) + if (!strcmp(dent->d_name, name)) { + strcpy(tmpname, dn); + strcat(tmpname, "/"); + strcat(tmpname, dent->d_name); + if (stat(tmpname, &statbuf) != 0) { + fprintf(stderr, "Can't stat '%s'.\n", tmpname); + continue; + } + if (!S_ISCHR(statbuf.st_mode) || major(statbuf.st_rdev) != SCSI_TAPE_MAJOR) + continue; + dev = minor(statbuf.st_rdev) & 31; + closedir(dirp); + return dev; + } + closedir(dirp); + } } return (-1); } - static int -accept_tape_name(char *name) +static int accept_tape_name(char *name) { char **npp; - for (npp=tape_name_bases; *npp; npp++) - if (!strncmp(name, *npp, strlen(*npp))) - return TRUE; + for (npp = tape_name_bases; *npp; npp++) + if (!strncmp(name, *npp, strlen(*npp))) + return TRUE; return FALSE; } - static int -find_devfiles(int tapeno, char **names) +static int find_devfiles(int tapeno, char **names) { int dev, mode, found; int non_rew[NBR_MODES]; @@ -627,254 +597,248 @@ find_devfiles(int tapeno, char **names) static devdir tmpdevdirs[MAX_TAPES + 1]; struct stat statbuf; - for (found=0; found < NBR_MODES; found++) { - *names[found] = '\0'; - non_rew[found] = FALSE; + for (found = 0; found < NBR_MODES; found++) { + *names[found] = '\0'; + non_rew[found] = FALSE; } if (dvd == NULL && !stat(DEVFS_PATH, &statbuf)) { - if (S_ISDIR(statbuf.st_mode) && (dirp=opendir(DEVFS_PATH)) != NULL) { - /* Assume devfs, one directory for each tape */ - for ( ; (dent = readdir(dirp)) != NULL; ) { - if (!strcmp (dent->d_name, ".") - || !strcmp (dent->d_name, "..")) - continue; - snprintf(tmpdevdirs[tmpdevdirsindex].dir, - sizeof(tmpdevdirs[tmpdevdirsindex].dir), - "%s/%s", DEVFS_PATH, dent->d_name); - tmpdevdirs[tmpdevdirsindex].selective_scan = FALSE; - if (++tmpdevdirsindex == MAX_TAPES) - break; - } - tmpdevdirs[tmpdevdirsindex].dir[0] = 0; - closedir(dirp); - dvd = &tmpdevdirs[0]; - } + if (S_ISDIR(statbuf.st_mode) && (dirp = opendir(DEVFS_PATH)) != NULL) { + /* Assume devfs, one directory for each tape */ + for (; (dent = readdir(dirp)) != NULL;) { + if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) + continue; + snprintf(tmpdevdirs[tmpdevdirsindex].dir, + sizeof(tmpdevdirs[tmpdevdirsindex].dir), "%s/%s", + DEVFS_PATH, dent->d_name); + tmpdevdirs[tmpdevdirsindex].selective_scan = FALSE; + if (++tmpdevdirsindex == MAX_TAPES) + break; + } + tmpdevdirs[tmpdevdirsindex].dir[0] = 0; + closedir(dirp); + dvd = &tmpdevdirs[0]; + } } if (dvd == NULL) - dvd = devdirs; + dvd = devdirs; - for (found=0, dvp=dvd; found < NBR_MODES && dvp->dir[0] != 0; dvp++) { - dn = dvp->dir; - if ((dirp = opendir(dn)) == NULL) - continue; + for (found = 0, dvp = dvd; found < NBR_MODES && dvp->dir[0] != 0; dvp++) { + dn = dvp->dir; + if ((dirp = opendir(dn)) == NULL) + continue; - for ( ; (dent = readdir(dirp)) != NULL; ) { - if (!strcmp (dent->d_name, ".") || !strcmp (dent->d_name, "..")) - continue; - /* Ignore non-tape devices to avoid loading all the modules */ - if (dvp->selective_scan && !accept_tape_name(dent->d_name)) - continue; - strcpy(tmpname, dn); - strcat(tmpname, "/"); - strcat(tmpname, dent->d_name); - if (stat(tmpname, &statbuf) != 0) { - fprintf(stderr, "Can't stat '%s'.\n", tmpname); - continue; - } - if (!S_ISCHR(statbuf.st_mode) || major(statbuf.st_rdev) != - SCSI_TAPE_MAJOR) - continue; - dev = minor(statbuf.st_rdev); - if ((dev & 31) != tapeno) - continue; - mode = (dev & 127) >> 5; - if (non_rew[mode]) - continue; - if (*names[mode] == '\0') - found++; - strcpy(names[mode], tmpname); - non_rew[mode] = (dev & 128) != 0; - } - closedir(dirp); + for (; (dent = readdir(dirp)) != NULL;) { + if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) + continue; + /* Ignore non-tape devices to avoid loading all the modules */ + if (dvp->selective_scan && !accept_tape_name(dent->d_name)) + continue; + strcpy(tmpname, dn); + strcat(tmpname, "/"); + strcat(tmpname, dent->d_name); + if (stat(tmpname, &statbuf) != 0) { + fprintf(stderr, "Can't stat '%s'.\n", tmpname); + continue; + } + if (!S_ISCHR(statbuf.st_mode) || major(statbuf.st_rdev) != SCSI_TAPE_MAJOR) + continue; + dev = minor(statbuf.st_rdev); + if ((dev & 31) != tapeno) + continue; + mode = (dev & 127) >> 5; + if (non_rew[mode]) + continue; + if (*names[mode] == '\0') + found++; + strcpy(names[mode], tmpname); + non_rew[mode] = (dev & 128) != 0; + } + closedir(dirp); } return (found > 0); } - static int -set_defs(devdef_tr *defs, char **fnames) +static int set_defs(devdef_tr *defs, char **fnames) { int i, tape; int clear_set[2]; struct mtop op; - for (i=0; i < NBR_MODES; i++) { - if (*fnames[i] == '\0' || !defs->modedefs[i].defined) - continue; + for (i = 0; i < NBR_MODES; i++) { + if (*fnames[i] == '\0' || !defs->modedefs[i].defined) + continue; - if ((tape = open(fnames[i], O_RDONLY | O_NONBLOCK)) < 0) { - fprintf(stderr, "Can't open the tape device '%s' for mode %d.\n", - fnames[i], i); - return FALSE; - } + if ((tape = open(fnames[i], O_RDONLY | O_NONBLOCK)) < 0) { + fprintf(stderr, "Can't open the tape device '%s' for mode %d.\n", + fnames[i], i); + return FALSE; + } - if (i == 0) { - if (defs->do_rewind) { - op.mt_op = MTREW; - op.mt_count = 1; - ioctl(tape, MTIOCTOP, &op); /* Don't worry about result */ - } + if (i == 0) { + if (defs->do_rewind) { + op.mt_op = MTREW; + op.mt_count = 1; + ioctl(tape, MTIOCTOP, &op); /* Don't worry about result */ + } - if (defs->drive_buffering >= 0) { - op.mt_op = MTSETDRVBUFFER; - op.mt_count = MT_ST_DEF_DRVBUFFER | defs->drive_buffering; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set drive buffering to %d.\n", - defs->drive_buffering); - } - } + if (defs->drive_buffering >= 0) { + op.mt_op = MTSETDRVBUFFER; + op.mt_count = MT_ST_DEF_DRVBUFFER | defs->drive_buffering; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, "Can't set drive buffering to %d.\n", defs->drive_buffering); + } + } - if (defs->timeout >= 0) { - op.mt_op = MTSETDRVBUFFER; - op.mt_count = MT_ST_SET_TIMEOUT | defs->timeout; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set device timeout %d s.\n", - defs->timeout); - } - } + if (defs->timeout >= 0) { + op.mt_op = MTSETDRVBUFFER; + op.mt_count = MT_ST_SET_TIMEOUT | defs->timeout; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, "Can't set device timeout %d s.\n", defs->timeout); + } + } - if (defs->long_timeout >= 0) { - op.mt_op = MTSETDRVBUFFER; - op.mt_count = MT_ST_SET_LONG_TIMEOUT | defs->long_timeout; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set device long timeout %d s.\n", - defs->long_timeout); - } - } + if (defs->long_timeout >= 0) { + op.mt_op = MTSETDRVBUFFER; + op.mt_count = MT_ST_SET_LONG_TIMEOUT | defs->long_timeout; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, "Can't set device long timeout %d s.\n", defs->long_timeout); + } + } - if (defs->cleaning >= 0) { - op.mt_op = MTSETDRVBUFFER; - op.mt_count = MT_ST_SET_CLN | defs->cleaning; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set cleaning request parameter to %x\n", - defs->cleaning); - } - } - } + if (defs->cleaning >= 0) { + op.mt_op = MTSETDRVBUFFER; + op.mt_count = MT_ST_SET_CLN | defs->cleaning; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, + "Can't set cleaning request parameter to %x\n", defs->cleaning); + } + } + } - op.mt_op = MTSETDRVBUFFER; + op.mt_op = MTSETDRVBUFFER; - clear_set[0] = clear_set[1] = 0; - if (defs->nowait >= 0) - clear_set[defs->nowait != 0] |= MT_ST_NOWAIT; - if (defs->sili >= 0) - clear_set[defs->sili != 0] |= MT_ST_SILI; - if (defs->modedefs[i].buffer_writes >= 0) - clear_set[defs->modedefs[i].buffer_writes != 0] |= MT_ST_BUFFER_WRITES; - if (defs->modedefs[i].async_writes >= 0) - clear_set[defs->modedefs[i].async_writes != 0] |= MT_ST_ASYNC_WRITES; - if (defs->modedefs[i].read_ahead >= 0) - clear_set[defs->modedefs[i].read_ahead != 0] |= MT_ST_READ_AHEAD; - if (defs->modedefs[i].two_fm >= 0) - clear_set[defs->modedefs[i].two_fm != 0] |= MT_ST_TWO_FM; - if (defs->modedefs[i].fast_eod >= 0) - clear_set[defs->modedefs[i].fast_eod != 0] |= MT_ST_FAST_MTEOM; - if (defs->modedefs[i].auto_lock >= 0) - clear_set[defs->modedefs[i].auto_lock != 0] |= MT_ST_AUTO_LOCK; - if (defs->modedefs[i].can_bsr >= 0) - clear_set[defs->modedefs[i].can_bsr != 0] |= MT_ST_CAN_BSR; - if (defs->modedefs[i].no_blklimits >= 0) - clear_set[defs->modedefs[i].no_blklimits != 0] |= MT_ST_NO_BLKLIMS; - if (defs->modedefs[i].can_partitions >= 0) - clear_set[defs->modedefs[i].can_partitions != 0] |= MT_ST_CAN_PARTITIONS; - if (defs->modedefs[i].scsi2logical >= 0) - clear_set[defs->modedefs[i].scsi2logical != 0] |= MT_ST_SCSI2LOGICAL; - if (defs->modedefs[i].sysv >= 0) - clear_set[defs->modedefs[i].sysv != 0] |= MT_ST_SYSV; - if (defs->modedefs[i].defs_for_writes >= 0) - clear_set[defs->modedefs[i].defs_for_writes != 0] |= MT_ST_DEF_WRITES; + clear_set[0] = clear_set[1] = 0; + if (defs->nowait >= 0) + clear_set[defs->nowait != 0] |= MT_ST_NOWAIT; + if (defs->sili >= 0) + clear_set[defs->sili != 0] |= MT_ST_SILI; + if (defs->modedefs[i].buffer_writes >= 0) + clear_set[defs->modedefs[i].buffer_writes != 0] |= MT_ST_BUFFER_WRITES; + if (defs->modedefs[i].async_writes >= 0) + clear_set[defs->modedefs[i].async_writes != 0] |= MT_ST_ASYNC_WRITES; + if (defs->modedefs[i].read_ahead >= 0) + clear_set[defs->modedefs[i].read_ahead != 0] |= MT_ST_READ_AHEAD; + if (defs->modedefs[i].two_fm >= 0) + clear_set[defs->modedefs[i].two_fm != 0] |= MT_ST_TWO_FM; + if (defs->modedefs[i].fast_eod >= 0) + clear_set[defs->modedefs[i].fast_eod != 0] |= MT_ST_FAST_MTEOM; + if (defs->modedefs[i].auto_lock >= 0) + clear_set[defs->modedefs[i].auto_lock != 0] |= MT_ST_AUTO_LOCK; + if (defs->modedefs[i].can_bsr >= 0) + clear_set[defs->modedefs[i].can_bsr != 0] |= MT_ST_CAN_BSR; + if (defs->modedefs[i].no_blklimits >= 0) + clear_set[defs->modedefs[i].no_blklimits != 0] |= MT_ST_NO_BLKLIMS; + if (defs->modedefs[i].can_partitions >= 0) + clear_set[defs->modedefs[i].can_partitions != 0] |= MT_ST_CAN_PARTITIONS; + if (defs->modedefs[i].scsi2logical >= 0) + clear_set[defs->modedefs[i].scsi2logical != 0] |= MT_ST_SCSI2LOGICAL; + if (defs->modedefs[i].sysv >= 0) + clear_set[defs->modedefs[i].sysv != 0] |= MT_ST_SYSV; + if (defs->modedefs[i].defs_for_writes >= 0) + clear_set[defs->modedefs[i].defs_for_writes != 0] |= MT_ST_DEF_WRITES; - if (clear_set[0] != 0) { - op.mt_count = MT_ST_CLEARBOOLEANS | clear_set[0]; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't clear the tape options (bits 0x%x, mode %d).\n", - clear_set[0], i); - } - } - if (clear_set[1] != 0) { - op.mt_count = MT_ST_SETBOOLEANS | clear_set[1]; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set the tape options (bits 0x%x, mode %d).\n", - clear_set[1], i); - } - } + if (clear_set[0] != 0) { + op.mt_count = MT_ST_CLEARBOOLEANS | clear_set[0]; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, + "Can't clear the tape options (bits 0x%x, mode %d).\n", + clear_set[0], i); + } + } + if (clear_set[1] != 0) { + op.mt_count = MT_ST_SETBOOLEANS | clear_set[1]; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, + "Can't set the tape options (bits 0x%x, mode %d).\n", + clear_set[1], i); + } + } - if (defs->modedefs[i].blocksize >= 0) { - op.mt_count = MT_ST_DEF_BLKSIZE | defs->modedefs[i].blocksize; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set blocksize %d for mode %d.\n", - defs->modedefs[i].blocksize, i); - } - } - if (defs->modedefs[i].density >= 0) { - op.mt_count = MT_ST_DEF_DENSITY | defs->modedefs[i].density; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set density %x for mode %d.\n", - defs->modedefs[i].density, i); - } - } - if (defs->modedefs[i].compression >= 0) { - op.mt_count = MT_ST_DEF_COMPRESSION | defs->modedefs[i].compression; - if (ioctl(tape, MTIOCTOP, &op) != 0) { - fprintf(stderr, "Can't set compression %d for mode %d.\n", - defs->modedefs[i].compression, i); - } - } + if (defs->modedefs[i].blocksize >= 0) { + op.mt_count = MT_ST_DEF_BLKSIZE | defs->modedefs[i].blocksize; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, "Can't set blocksize %d for mode %d.\n", + defs->modedefs[i].blocksize, i); + } + } + if (defs->modedefs[i].density >= 0) { + op.mt_count = MT_ST_DEF_DENSITY | defs->modedefs[i].density; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, "Can't set density %x for mode %d.\n", + defs->modedefs[i].density, i); + } + } + if (defs->modedefs[i].compression >= 0) { + op.mt_count = MT_ST_DEF_COMPRESSION | defs->modedefs[i].compression; + if (ioctl(tape, MTIOCTOP, &op) != 0) { + fprintf(stderr, "Can't set compression %d for mode %d.\n", + defs->modedefs[i].compression, i); + } + } - close(tape); + close(tape); } return TRUE; } - static int -define_tape(int tapeno, FILE *dbf, devdef_tr *defptr, int print_non_found) +static int define_tape(int tapeno, FILE *dbf, devdef_tr *defptr, int print_non_found) { int i; char company[10], product[20], rev[5], *tname, *fnames[NBR_MODES]; if (verbose > 0) - printf("\nstinit, processing tape %d\n", tapeno); + printf("\nstinit, processing tape %d\n", tapeno); if ((fnames[0] = calloc(NBR_MODES, PATH_MAX)) == NULL) { - fprintf(stderr, "Can't allocate name buffers.\n"); - return FALSE; + fprintf(stderr, "Can't allocate name buffers.\n"); + return FALSE; } - for (i=1; i < NBR_MODES; i++) - fnames[i] = fnames[i-1] + PATH_MAX; + for (i = 1; i < NBR_MODES; i++) + fnames[i] = fnames[i - 1] + PATH_MAX; - if (!find_devfiles(tapeno, fnames) || - *fnames[0] == '\0') { - if (print_non_found) - fprintf(stderr, "Can't find any device files for tape %d.\n", - tapeno); - free(fnames[0]); - return FALSE; + if (!find_devfiles(tapeno, fnames) || *fnames[0] == '\0') { + if (print_non_found) + fprintf(stderr, "Can't find any device files for tape %d.\n", tapeno); + free(fnames[0]); + return FALSE; } if (verbose > 1) - for (i=0; i < NBR_MODES; i++) - printf("Mode %d, name '%s'\n", i + 1, fnames[i]); + for (i = 0; i < NBR_MODES; i++) + printf("Mode %d, name '%s'\n", i + 1, fnames[i]); tname = fnames[0]; if (!do_inquiry(tname, company, product, rev, print_non_found)) { - free(fnames[0]); - return FALSE; + free(fnames[0]); + return FALSE; } if (verbose > 0) - printf("The manufacturer is '%s', product is '%s', and revision '%s'.\n", - company, product, rev); + printf( + "The manufacturer is '%s', product is '%s', and revision '%s'.\n", + company, product, rev); if (!find_pars(dbf, company, product, rev, defptr, FALSE)) { - fprintf(stderr, "Can't find defaults for tape number %d.\n", tapeno); - free(fnames[0]); - return FALSE; + fprintf(stderr, "Can't find defaults for tape number %d.\n", tapeno); + free(fnames[0]); + return FALSE; } if (!set_defs(defptr, fnames)) { - free(fnames[0]); - return FALSE; + free(fnames[0]); + return FALSE; } free(fnames[0]); @@ -882,17 +846,15 @@ define_tape(int tapeno, FILE *dbf, devdef_tr *defptr, int print_non_found) } - static char -usage(int retval) +static char usage(int retval) { - fprintf(stderr, - "Usage: stinit [-h] [-v] [--version] [-f dbname] [-p] [-r] [drivename_or_number ...]\n"); + fprintf(stderr, "Usage: stinit [-h] [-v] [--version] [-f dbname] [-p] [-r] " + "[drivename_or_number ...]\n"); exit(retval); } - int -main(int argc, char **argv) +int main(int argc, char **argv) { FILE *dbf = NULL; int argn; @@ -901,66 +863,60 @@ main(int argc, char **argv) devdef_tr defs; defs.do_rewind = FALSE; - for (argn=1; argn < argc && *argv[argn] == '-'; argn++) { - if (*(argv[argn] + 1) == 'v') - verbose++; - else if (*(argv[argn] + 1) == 'p') - parse_only = TRUE; - else if (*(argv[argn] + 1) == 'h') - usage(0); - else if (*(argv[argn] + 1) == 'r') - defs.do_rewind = TRUE; - else if (*(argv[argn] + 1) == 'f') { - argn += 1; - if (argn >= argc) - usage(1); - dbname = argv[argn]; - } - else if (*(argv[argn] + 1) == '-' && - *(argv[argn] + 2) == 'v') { - printf("stinit v. %s\n", VERSION); - exit(0); - break; - } - else - usage(1); + for (argn = 1; argn < argc && *argv[argn] == '-'; argn++) { + if (*(argv[argn] + 1) == 'v') + verbose++; + else if (*(argv[argn] + 1) == 'p') + parse_only = TRUE; + else if (*(argv[argn] + 1) == 'h') + usage(0); + else if (*(argv[argn] + 1) == 'r') + defs.do_rewind = TRUE; + else if (*(argv[argn] + 1) == 'f') { + argn += 1; + if (argn >= argc) + usage(1); + dbname = argv[argn]; + } else if (*(argv[argn] + 1) == '-' && *(argv[argn] + 2) == 'v') { + printf("stinit v. %s\n", VERSION); + exit(0); + break; + } else + usage(1); } if ((dbf = open_database(dbname)) == NULL) - return 1; + return 1; if (parse_only) { - if (argc > argn) - fprintf(stderr, "Extra arguments on command line ignored.\n"); - if (!find_pars(dbf, "xyz", "xyz", "xyz", &defs, TRUE)) - return 1; - return 0; + if (argc > argn) + fprintf(stderr, "Extra arguments on command line ignored.\n"); + if (!find_pars(dbf, "xyz", "xyz", "xyz", &defs, TRUE)) + return 1; + return 0; } - if (argc > argn) { /* Initialize specific drives */ - for ( ; argn < argc; argn++) { - if (*argv[argn] == '-') { - usage(1); - return 1; /* Never executed but makes gcc happy */ - } - else if (isdigit(*argv[argn])) - tapeno = strtol(argv[argn], NULL, 0); - else if ((tapeno = tapenum(argv[argn])) < 0) { - fprintf(stderr, "Can't find tape number for name '%s'.\n", - argv[argn]); - continue; - } - if (!define_tape(tapeno, dbf, &defs, TRUE)) - fprintf(stderr, "Definition for '%s' failed.\n", argv[argn]); - } - } - else { /* Initialize all SCSI tapes */ - for (tapeno=0; tapeno < MAX_TAPES; tapeno++) - if (!define_tape(tapeno, dbf, &defs, FALSE)) { - fprintf(stderr, "Initialized %d tape device%s.\n", - tapeno, (tapeno != 1 ? "s" : "")); - return 0; /* Process tapes until failure */ - } + if (argc > argn) { /* Initialize specific drives */ + for (; argn < argc; argn++) { + if (*argv[argn] == '-') { + usage(1); + return 1; /* Never executed but makes gcc happy */ + } else if (isdigit(*argv[argn])) + tapeno = strtol(argv[argn], NULL, 0); + else if ((tapeno = tapenum(argv[argn])) < 0) { + fprintf(stderr, "Can't find tape number for name '%s'.\n", argv[argn]); + continue; + } + if (!define_tape(tapeno, dbf, &defs, TRUE)) + fprintf(stderr, "Definition for '%s' failed.\n", argv[argn]); + } + } else { /* Initialize all SCSI tapes */ + for (tapeno = 0; tapeno < MAX_TAPES; tapeno++) + if (!define_tape(tapeno, dbf, &defs, FALSE)) { + fprintf(stderr, "Initialized %d tape device%s.\n", tapeno, + (tapeno != 1 ? "s" : "")); + return 0; /* Process tapes until failure */ + } } return 0;