[BACK]Return to interact.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sbin / disklabel

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sbin/disklabel/interact.c between version 1.13 and 1.13.4.1

version 1.13, 1999/12/17 13:06:49 version 1.13.4.1, 2000/10/18 02:53:09
Line 58  static void cmd_round __P((struct diskla
Line 58  static void cmd_round __P((struct diskla
 static void cmd_name __P((struct disklabel *, char *, int));  static void cmd_name __P((struct disklabel *, char *, int));
 static int runcmd __P((char *, struct disklabel *, int));  static int runcmd __P((char *, struct disklabel *, int));
 static int getinput __P((const char *, const char *, const char *, char *));  static int getinput __P((const char *, const char *, const char *, char *));
   static int alphacmp __P((const void *, const void *));
 static void defnum __P((char *, struct disklabel *, int));  static void defnum __P((char *, struct disklabel *, int));
   static void dumpnames __P((const char *, const char * const *, size_t));
 static int getnum __P((char *, int, struct disklabel *));  static int getnum __P((char *, int, struct disklabel *));
 static void deffstypename __P((char *, int));  
 static int getfstypename __P((const char *));  
   
 static int rounding = 0;        /* sector rounding */  static int rounding = 0;        /* sector rounding */
 static int chaining = 0;        /* make partitions contiguous */  static int chaining = 0;        /* make partitions contiguous */
Line 111  cmd_chain(lp, s, fd)
Line 111  cmd_chain(lp, s, fd)
   
         i = getinput(":", "Automatically adjust partitions",          i = getinput(":", "Automatically adjust partitions",
             chaining ? "yes" : "no", line);              chaining ? "yes" : "no", line);
   
         if (i <= 0)          if (i <= 0)
                 return;                  return;
   
Line 156  cmd_info(lp, s, fd)
Line 155  cmd_info(lp, s, fd)
 {  {
         char line[BUFSIZ];          char line[BUFSIZ];
         char def[BUFSIZ];          char def[BUFSIZ];
         const char * const *cpp;  
         const char *t;  
         int v, i;          int v, i;
         u_int32_t u;          u_int32_t u;
   
         printf("# Current values:\n");          printf("# Current values:\n");
         showinfo(stdout, lp);          showinfo(stdout, lp);
   
         /* d_typename */          /* d_type */
         for (;;) {          for (;;) {
                 strncpy(def, lp->d_typename, sizeof(def));                  i = lp->d_type;
                 def[sizeof(def) - 1] = '\0';                  if (i < 0 || i >= DKMAXTYPES)
                 i = getinput(":", "Disk type", def, line);                          i = 0;
                 if (i <= 0)                  snprintf(def, sizeof(def), "%s", dktypenames[i]);
                         break;                  i = getinput(":", "Disk type [?]", def, line);
                 cpp = dktypenames;                  if (i == -1)
                 for (; cpp < &dktypenames[DKMAXTYPES]; cpp++)                          return;
                         if ((t = *cpp) && !strcmp(t, line)) {                  else if (i == 0)
                                 lp->d_type = cpp - dktypenames;                          break;
                   if (!strcmp(line, "?")) {
                           dumpnames("Supported disk types", dktypenames,
                               DKMAXTYPES);
                           continue;
                   }
                   for (i = 0; i < DKMAXTYPES; i++) {
                           if (!strcasecmp(dktypenames[i], line)) {
                                   lp->d_type = i;
                                 goto done_typename;                                  goto done_typename;
                         }                          }
                   }
                 v = atoi(line);                  v = atoi(line);
                 if ((unsigned)v >= DKMAXTYPES) {                  if ((unsigned)v >= DKMAXTYPES) {
                         warnx("unknown disk type: %s", line);                          warnx("Unknown disk type: %s", line);
                         continue;                          continue;
                 }                  }
                 lp->d_type = v;                  lp->d_type = v;
Line 187  done_typename:
Line 193  done_typename:
                 break;                  break;
         }          }
   
           /* d_typename */
           snprintf(def, sizeof(def), "%.*s",
               (int) sizeof(lp->d_typename), lp->d_typename);
           i = getinput(":", "Disk name", def, line);
           if (i == -1)
                   return;
           else if (i == 1)
                   (void) strncpy(lp->d_typename, line, sizeof(lp->d_typename));
   
         /* d_packname */          /* d_packname */
         cmd_name(lp, s, fd);          cmd_name(lp, s, fd);
   
         /* d_npartitions */          /* d_npartitions */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_npartitions);                  snprintf(def, sizeof(def), "%u", lp->d_npartitions);
                 i = getinput(":", "Number of partitions", def, line);                  i = getinput(":", "Number of partitions", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid number of partitions `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_npartitions = u;                  lp->d_npartitions = u;
Line 206  done_typename:
Line 223  done_typename:
   
         /* d_secsize */          /* d_secsize */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_secsize);                  snprintf(def, sizeof(def), "%u", lp->d_secsize);
                 i = getinput(":", "Sector size (bytes)", def, line);                  i = getinput(":", "Sector size (bytes)", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid sector size `%s'\n", line);
Line 220  done_typename:
Line 239  done_typename:
   
         /* d_nsectors */          /* d_nsectors */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_nsectors);                  snprintf(def, sizeof(def), "%u", lp->d_nsectors);
                 i = getinput(":", "Number of sectors per track", def, line);                  i = getinput(":", "Number of sectors per track", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid number of sector `%s'\n", line);                          printf("Invalid number of sectors `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_nsectors = u;                  lp->d_nsectors = u;
Line 234  done_typename:
Line 255  done_typename:
   
         /* d_ntracks */          /* d_ntracks */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_ntracks);                  snprintf(def, sizeof(def), "%u", lp->d_ntracks);
                 i = getinput(":", "Number of tracks per cylinder", def, line);                  i = getinput(":", "Number of tracks per cylinder", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid number of tracks `%s'\n", line);                          printf("Invalid number of tracks `%s'\n", line);
Line 248  done_typename:
Line 271  done_typename:
   
         /* d_secpercyl */          /* d_secpercyl */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_secpercyl);                  snprintf(def, sizeof(def), "%u", lp->d_secpercyl);
                 i = getinput(":", "Number of sectors/cylinder", def, line);                  i = getinput(":", "Number of sectors/cylinder", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid number of sector/cylinder `%s'\n", line);                          printf("Invalid number of sector/cylinder `%s'\n",
                               line);
                         continue;                          continue;
                 }                  }
                 lp->d_secpercyl = u;                  lp->d_secpercyl = u;
Line 262  done_typename:
Line 288  done_typename:
   
         /* d_ncylinders */          /* d_ncylinders */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_ncylinders);                  snprintf(def, sizeof(def), "%u", lp->d_ncylinders);
                 i = getinput(":", "Total number of cylinders", def, line);                  i = getinput(":", "Total number of cylinders", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid sector size `%s'\n", line);
Line 276  done_typename:
Line 304  done_typename:
   
         /* d_secperunit */          /* d_secperunit */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_secperunit);                  snprintf(def, sizeof(def), "%u", lp->d_secperunit);
                 i = getinput(":", "Total number of sectors", def, line);                  i = getinput(":", "Total number of sectors", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid number of sector `%s'\n", line);                          printf("Invalid number of sectors `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_secperunit = u;                  lp->d_secperunit = u;
Line 292  done_typename:
Line 322  done_typename:
   
         /* d_interleave */          /* d_interleave */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_interleave);                  snprintf(def, sizeof(def), "%u", lp->d_interleave);
                 i = getinput(":", "Hardware sectors interleave", def, line);                  i = getinput(":", "Hardware sectors interleave", def, line);
                   if (i == -1)
                 if (i <= 0)                          return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid sector interleave `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_interleave = u;                  lp->d_interleave = u;
Line 307  done_typename:
Line 338  done_typename:
   
         /* d_trackskew */          /* d_trackskew */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_trackskew);                  snprintf(def, sizeof(def), "%u", lp->d_trackskew);
                 i = getinput(":", "Sector 0 skew, per track", def, line);                  i = getinput(":", "Sector 0 skew, per track", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid track sector skew `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_trackskew = u;                  lp->d_trackskew = u;
Line 321  done_typename:
Line 354  done_typename:
   
         /* d_cylskew */          /* d_cylskew */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_cylskew);                  snprintf(def, sizeof(def), "%u", lp->d_cylskew);
                 i = getinput(":", "Sector 0 skew, per cylinder", def, line);                  i = getinput(":", "Sector 0 skew, per cylinder", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid cylinder sector `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_cylskew = u;                  lp->d_cylskew = u;
Line 335  done_typename:
Line 370  done_typename:
   
         /* d_headswitch */          /* d_headswitch */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_headswitch);                  snprintf(def, sizeof(def), "%u", lp->d_headswitch);
                 i = getinput(":", "Head switch time (usec)", def, line);                  i = getinput(":", "Head switch time (usec)", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid head switch time `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_headswitch = u;                  lp->d_headswitch = u;
Line 349  done_typename:
Line 386  done_typename:
   
         /* d_trkseek */          /* d_trkseek */
         for (;;) {          for (;;) {
                 snprintf(def, sizeof def, "%u", lp->d_trkseek);                  snprintf(def, sizeof(def), "%u", lp->d_trkseek);
                 i = getinput(":", "Track seek time (usec)", def, line);                  i = getinput(":", "Track seek time (usec)", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if (sscanf(line, "%u", &u) != 1) {                  if (sscanf(line, "%u", &u) != 1) {
                         printf("Invalid sector size `%s'\n", line);                          printf("Invalid track seek time `%s'\n", line);
                         continue;                          continue;
                 }                  }
                 lp->d_trkseek = u;                  lp->d_trkseek = u;
                 break;                  break;
         }          }
   
 }  }
   
 static void  static void
Line 370  cmd_name(lp, s, fd)
Line 408  cmd_name(lp, s, fd)
         int fd;          int fd;
 {  {
         char line[BUFSIZ];          char line[BUFSIZ];
         int i = getinput(":", "Label name", lp->d_packname, line);          char def[BUFSIZ];
           int i;
   
           snprintf(def, sizeof(def), "%.*s",
               (int) sizeof(lp->d_packname), lp->d_packname);
           i = getinput(":", "Label name", def, line);
         if (i <= 0)          if (i <= 0)
                 return;                  return;
         (void) strncpy(lp->d_packname, line, sizeof(lp->d_packname));          (void) strncpy(lp->d_packname, line, sizeof(lp->d_packname));
Line 387  cmd_round(lp, s, fd)
Line 429  cmd_round(lp, s, fd)
         char line[BUFSIZ];          char line[BUFSIZ];
   
         i = getinput(":", "Rounding", rounding ? "cylinders" : "sectors", line);          i = getinput(":", "Rounding", rounding ? "cylinders" : "sectors", line);
   
         if (i <= 0)          if (i <= 0)
                 return;                  return;
   
Line 420  cmd_part(lp, s, fd)
Line 461  cmd_part(lp, s, fd)
                 lp->d_npartitions = part + 1;                  lp->d_npartitions = part + 1;
   
         for (;;) {          for (;;) {
                 deffstypename(def, p->p_fstype);                  i = p->p_fstype;
                 i = getinput(":", "Filesystem type", def, line);                  if (i < 0 || i >= FSMAXTYPES)
                 if (i <= 0)                          i = 0;
                   snprintf(def, sizeof(def), "%s", fstypenames[i]);
                   i = getinput(":", "Filesystem type [?]", def, line);
                   if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if ((i = getfstypename(line)) == -1) {                  if (!strcmp(line, "?")) {
                         printf("Invalid file system typename `%s'\n", line);                          dumpnames("Supported file system types",
                               fstypenames, FSMAXTYPES);
                         continue;                          continue;
                 }                  }
                 p->p_fstype = i;                  for (i = 0; i < FSMAXTYPES; i++)
                           if (!strcasecmp(line, fstypenames[i])) {
                                   p->p_fstype = i;
                                   goto done_typename;
                           }
                   printf("Invalid file system typename `%s'\n", line);
                   continue;
   done_typename:
                 break;                  break;
         }          }
         for (;;) {          for (;;) {
                 defnum(def, lp, p->p_offset);                  defnum(def, lp, p->p_offset);
                 i = getinput(":", "Start offset", def, line);                  i = getinput(":", "Start offset", def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if ((i = getnum(line, 0, lp)) == -1) {                  if ((i = getnum(line, 0, lp)) == -1) {
                         printf("Bad offset `%s'\n", line);                          printf("Bad offset `%s'\n", line);
Line 447  cmd_part(lp, s, fd)
Line 503  cmd_part(lp, s, fd)
                 defnum(def, lp, p->p_size);                  defnum(def, lp, p->p_size);
                 i = getinput(":", "Partition size ('$' for all remaining)",                  i = getinput(":", "Partition size ('$' for all remaining)",
                     def, line);                      def, line);
                 if (i <= 0)                  if (i == -1)
                           return;
                   else if (i == 0)
                         break;                          break;
                 if ((i = getnum(line, lp->d_secperunit - p->p_offset, lp))                  if ((i = getnum(line, lp->d_secperunit - p->p_offset, lp))
                     == -1) {                      == -1) {
Line 482  cmd_label(lp, s, fd)
Line 540  cmd_label(lp, s, fd)
         int i;          int i;
   
         i = getinput("?", "Label disk", "n", line);          i = getinput("?", "Label disk", "n", line);
   
         if (i <= 0 || (*line != 'y' && *line != 'Y') )          if (i <= 0 || (*line != 'y' && *line != 'Y') )
                 return;                  return;
   
Line 555  getinput(sep, prompt, def, line)
Line 612  getinput(sep, prompt, def, line)
         }          }
 }  }
   
   static int
   alphacmp(a, b)
           const void *a, *b;
   {
   
           return (strcasecmp(*(const char **)a, *(const char **)b));
   }
   
   
   static void
   dumpnames(prompt, olist, numentries)
           const char *prompt;
           const char * const *olist;
           size_t numentries;
   {
           int i, j, w;
           int columns, width, lines;
           const char *p;
           const char **list;
   
           list = (const char **)malloc(sizeof(char *) * numentries);
           width = 0;
           printf("%s:\n", prompt);
           for (i = 0; i < numentries; i++) {
                   list[i] = olist[i];
                   w = strlen(list[i]);
                   if (w > width)
                           width = w;
           }
   #if 0
           for (i = 0; i < numentries; i++)
                   printf("%s%s", i == 0 ? "" : ", ", list[i]);
           puts("");
   #endif
           (void)qsort((void *)list, numentries, sizeof(char *), alphacmp);
           width++;                /* want two spaces between items */
           width = (width + 8) &~ 7;
   
   #define ttywidth 72
           columns = ttywidth / width;
   #undef ttywidth
           if (columns == 0)
                   columns = 1;
           lines = (numentries + columns - 1) / columns;
           for (i = 0; i < lines; i++) {
                   for (j = 0; j < columns; j++) {
                           p = list[j * lines + i];
                           if (j == 0)
                                   putc('\t', stdout);
                           if (p) {
                                   fputs(p, stdout);
                           }
                           if (j * lines + i + lines >= numentries) {
                                   putc('\n', stdout);
                                   break;
                           }
                           w = strlen(p);
                           while (w < width) {
                                   w = (w + 8) &~ 7;
                                   putc('\t', stdout);
                           }
                   }
           }
           free(list);
   }
   
   
 static void  static void
 defnum(buf, lp, size)  defnum(buf, lp, size)
Line 598  getnum(buf, max, lp)
Line 721  getnum(buf, max, lp)
                 rv = (int) (d * lp->d_secpercyl);                  rv = (int) (d * lp->d_secpercyl);
                 break;                  break;
   
           case 'm':
         case 'M':          case 'M':
                 rv =  (int) (d * 1024 * 1024 / lp->d_secsize);                  rv =  (int) (d * 1024 * 1024 / lp->d_secsize);
                 break;                  break;
Line 614  getnum(buf, max, lp)
Line 738  getnum(buf, max, lp)
 }  }
   
   
 static void  
 deffstypename(buf, i)  
         char *buf;  
         int i;  
 {  
         if (i < 0 || i >= FSMAXTYPES)  
                 i = 0;  
         (void) strcpy(buf, fstypenames[i]);  
 }  
   
   
 static int  
 getfstypename(buf)  
         const char *buf;  
 {  
         int i;  
   
         for (i = 0; i < FSMAXTYPES; i++)  
                 if (strcmp(buf, fstypenames[i]) == 0)  
                         return i;  
         return -1;  
 }  
   
   
 void  void
 interact(lp, fd)  interact(lp, fd)
         struct disklabel *lp;          struct disklabel *lp;

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.13.4.1

CVSweb <webmaster@jp.NetBSD.org>