"Fossies" - the Fresh Open Source Software Archive

Member "schily-2021-09-18/label/label.c" (20 Aug 2021, 5067 Bytes) of package /linux/privat/schily-2021-09-18.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* @(#)label.c  1.35 21/08/20 Copyright 1988-2021 J. Schilling */
    2 #include <schily/mconfig.h>
    3 #ifndef lint
    4 static  UConst char sccsid[] =
    5     "@(#)label.c    1.35 21/08/20 Copyright 1988-2021 J. Schilling";
    6 #endif
    7 /*
    8  *  Copyright (c) 1988-2021 J. Schilling
    9  */
   10 /*
   11  * The contents of this file are subject to the terms of the
   12  * Common Development and Distribution License, Version 1.0 only
   13  * (the "License").  You may not use this file except in compliance
   14  * with the License.
   15  *
   16  * See the file CDDL.Schily.txt in this distribution for details.
   17  * A copy of the CDDL is also available via the Internet at
   18  * http://www.opensource.org/licenses/cddl1.txt
   19  *
   20  * When distributing Covered Code, include this CDDL HEADER in each
   21  * file and include the License file CDDL.Schily.txt from this distribution.
   22  */
   23 
   24 #include <schily/stdio.h>
   25 #include <schily/stdlib.h>
   26 #include <schily/standard.h>
   27 #include <schily/param.h>   /* Include various defs needed with some OS */
   28 #include <schily/ioctl.h>
   29 #define GT_COMERR       /* #define comerr gtcomerr */
   30 #define GT_ERROR        /* #define error gterror   */
   31 #include <schily/schily.h>
   32 #include <schily/nlsdefs.h>
   33 #include "dsklabel.h"
   34 #include "fmt.h"
   35 
   36 struct disk cur_disk;
   37 struct  dk_label x_label;
   38 struct  dk_label *d_label = &x_label;
   39     char    *disknm;
   40 
   41 char    opt[] = "help,version,print,p,Prpart,P,set,s,if*,lproto*,of*,lname*,f*";
   42 
   43 extern char *Lname;
   44 extern char *Lproto;
   45 
   46 LOCAL   void    usage       __PR((int ret));
   47 EXPORT  int main        __PR((int, char **));
   48 EXPORT  void    disk_null   __PR((struct disk *dp, int init));
   49 
   50 void
   51 get_lgeom_defaults(scgp, dp)
   52     SCSI    *scgp;
   53     struct disk *dp;
   54 {
   55 }
   56 
   57 LOCAL void
   58 usage(ret)
   59     int ret;
   60 {
   61     error("Usage: label [options]\n");
   62     error("Options:\n");
   63     error(" -help       Print this help.\n");
   64     error(" -version    Print version number.\n");
   65     error("\t-print,-p\tonly print label\n");
   66     error("\t-set,-s\t\tset driver tables from disk label\n");
   67     error("\tof=name\t\tname of output Label (default: '%s')\n", Lname);
   68     error("\tlname=name\tname of output Label (default: '%s')\n", Lname);
   69     error("\tif=name\t\tname of input  Label (default: '%s')\n", Lproto);
   70     error("\tlproto=name\tname of input  Label (default: '%s')\n", Lproto);
   71     error("\tf=name\tname of input & output  Label\n");
   72     exit(ret);
   73 }
   74 
   75 int
   76 main(ac, av)
   77     int ac;
   78     char    *av[];
   79 {
   80     BOOL    help    = FALSE;
   81     BOOL    prversion = FALSE;
   82     int print   = 0;
   83     int Prpart  = 0;
   84     int set = 0;
   85     int cac = ac;
   86     char    *const *cav= av;
   87     SCSI    scg;
   88 
   89     save_args(ac, av);
   90 
   91     (void) setlocale(LC_ALL, "");
   92 
   93 #ifdef  USE_NLS
   94 #if !defined(TEXT_DOMAIN)   /* Should be defined by cc -D */
   95 #define TEXT_DOMAIN "p"     /* Use this only if it weren't */
   96 #endif
   97     { char  *dir;
   98     dir = searchfileinpath("share/locale", F_OK,
   99                     SIP_ANY_FILE|SIP_NO_PATH, NULL);
  100     if (dir)
  101         (void) bindtextdomain(TEXT_DOMAIN, dir);
  102     else
  103 #if defined(PROTOTYPES) && defined(INS_BASE)
  104     (void) bindtextdomain(TEXT_DOMAIN, INS_BASE "/share/locale");
  105 #else
  106     (void) bindtextdomain(TEXT_DOMAIN, "/usr/share/locale");
  107 #endif
  108     (void) textdomain(TEXT_DOMAIN);
  109     }
  110 #endif  /* USE_NLS */
  111 
  112     disk_null(&cur_disk, TRUE);
  113 
  114     cac--;
  115     cav++;  
  116     if (getallargs(&cac, &cav, opt, &help, &prversion,
  117                         &print, &print,
  118                         &Prpart, &Prpart,
  119                         &set, &set,
  120                         &Lproto, &Lproto,
  121                         &Lname, &Lname,
  122                         &disknm) < 0) {
  123         errmsgno(EX_BAD, "Bad flag: %s.\n", cav[0]);
  124         usage(EX_BAD);
  125     }
  126     if (help)
  127         usage(0);
  128     if (prversion) {
  129         gtprintf("Label release %s (%s-%s-%s) Copyright (C) 1988-2021 %s\n",
  130                 "1.35",
  131                 HOST_CPU, HOST_VENDOR, HOST_OS,
  132                 _("Jörg Schilling"));
  133         exit(0);
  134     }
  135 
  136     if (disknm)
  137         Lname = Lproto = disknm;
  138 
  139     if (print || Prpart || set) {
  140         if (readlabel(Lproto, d_label)) {
  141             cur_disk.labelread = 0;
  142 
  143             if (Prpart) {
  144                 prpartab(stdout, "UNKNOWN", d_label);
  145             } else {
  146                 printlabel(d_label);
  147                 checklabel(&cur_disk, d_label, 0);
  148             }
  149             if (!setval_from_label(&cur_disk, d_label))
  150                 comerrno(EX_BAD, "Bad Label '%s'\n", Lproto);
  151             if (set)
  152                 exit(setlabel(Lname, d_label));
  153             exit(0);
  154         }
  155         exit(-1);
  156     }
  157 
  158     if (readlabel(Lproto, d_label)) {
  159         cur_disk.labelread = 0;
  160         if (setval_from_label(&cur_disk, d_label))
  161             cur_disk.labelread = 1;
  162     }
  163     do {
  164         getlong("Enter number of physical cylinders",
  165                         &cur_disk.pcyl, 1L, 0xFFFE);
  166                         cur_disk.lpcyl = cur_disk.pcyl;
  167         getlong("Enter number of data cylinders",
  168                         &cur_disk.lncyl, 1L, 0xFFFE);
  169         getlong("Enter number of alternate cylinders (Label)",
  170                         &cur_disk.lacyl,0L, 10000);
  171         getlong("Enter number of data      heads     (Label)",
  172                         &cur_disk.lhead, 1L, 100);
  173         getlong("Enter number of data sectors/track  (Label)",
  174                         &cur_disk.lspt, 1L, 0xFFFE);
  175         getlong("Enter rpm of drive",
  176                         &cur_disk.rpm, 0L, 10000L);
  177 
  178         makelabel(&scg, &cur_disk, d_label);
  179         printlabel(d_label);
  180         checklabel(&cur_disk, d_label, 1);
  181     } while(!yes("Use this label? "));
  182     /*
  183      * fill in default vtmap if not done yet
  184      */
  185     check_vtmap(d_label, 1);
  186     writelabel(Lname, d_label);
  187     return (0);
  188 }
  189 
  190 EXPORT void
  191 disk_null(dp, init)
  192     struct disk *dp;
  193     int     init;
  194 {
  195     register int i = sizeof(struct disk);
  196     register char *p = (char *)dp;
  197 
  198     while (--i >= 0) {
  199         *p++ = -1;
  200     }
  201 }