Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/util-linux/fdisk_osf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 1  Line 1 
 #if ENABLE_FEATURE_OSF_LABEL  
1  /*  /*
2   * Copyright (c) 1987, 1988 Regents of the University of California.   * Copyright (c) 1987, 1988 Regents of the University of California.
3   * All rights reserved.   * All rights reserved.
# Line 32  Line 31 
31   * SUCH DAMAGE.   * SUCH DAMAGE.
32   */   */
33    
34    #if ENABLE_FEATURE_OSF_LABEL
35    
36  #ifndef BSD_DISKMAGIC  #ifndef BSD_DISKMAGIC
37  #define BSD_DISKMAGIC     ((uint32_t) 0x82564557)  #define BSD_DISKMAGIC     ((uint32_t) 0x82564557)
# Line 45  Line 45 
45    
46  #if defined(i386) || defined(__sparc__) || defined(__arm__) \  #if defined(i386) || defined(__sparc__) || defined(__arm__) \
47   || defined(__m68k__) || defined(__mips__) || defined(__s390__) \   || defined(__m68k__) || defined(__mips__) || defined(__s390__) \
48   || defined(__sh__) || defined(__x86_64__)   || defined(__s390__) || defined(__s390x__) \
49  #define BSD_LABELSECTOR   1   || defined(__sh__) || defined(__x86_64__) || defined(__avr32__)
50  #define BSD_LABELOFFSET   0  # define BSD_LABELSECTOR   1
51    # define BSD_LABELOFFSET   0
52  #elif defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \  #elif defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \
53   || defined(__hppa__)   || defined(__hppa__)
54  #define BSD_LABELSECTOR   0  # define BSD_LABELSECTOR   0
55  #define BSD_LABELOFFSET   64  # define BSD_LABELOFFSET   64
 #elif defined(__s390__) || defined(__s390x__)  
 #define BSD_LABELSECTOR   1  
 #define BSD_LABELOFFSET   0  
56  #else  #else
57  #error unknown architecture  # error unknown architecture
58  #endif  #endif
59    
60  #define BSD_BBSIZE        8192          /* size of boot area, with label */  #define BSD_BBSIZE        8192          /* size of boot area, with label */
# Line 67  struct xbsd_disklabel { Line 65  struct xbsd_disklabel {
65   int16_t    d_type;                 /* drive type */   int16_t    d_type;                 /* drive type */
66   int16_t    d_subtype;              /* controller/d_type specific */   int16_t    d_subtype;              /* controller/d_type specific */
67   char       d_typename[16];         /* type name, e.g. "eagle" */   char       d_typename[16];         /* type name, e.g. "eagle" */
68   char       d_packname[16];                 /* pack identifier */   char       d_packname[16];         /* pack identifier */
69   /* disk geometry: */   /* disk geometry: */
70   uint32_t   d_secsize;              /* # of bytes per sector */   uint32_t   d_secsize;              /* # of bytes per sector */
71   uint32_t   d_nsectors;             /* # of data sectors per track */   uint32_t   d_nsectors;             /* # of data sectors per track */
72   uint32_t   d_ntracks;              /* # of tracks per cylinder */   uint32_t   d_ntracks;              /* # of tracks per cylinder */
# Line 89  struct xbsd_disklabel { Line 87  struct xbsd_disklabel {
87   */   */
88   uint32_t   d_acylinders;           /* # of alt. cylinders per unit */   uint32_t   d_acylinders;           /* # of alt. cylinders per unit */
89    
90   /* hardware characteristics: */   /* hardware characteristics: */
91   /*   /*
92   * d_interleave, d_trackskew and d_cylskew describe perturbations   * d_interleave, d_trackskew and d_cylskew describe perturbations
93   * in the media format used to compensate for a slow controller.   * in the media format used to compensate for a slow controller.
# Line 119  struct xbsd_disklabel { Line 117  struct xbsd_disklabel {
117   uint32_t   d_spare[NSPARE];        /* reserved for future use */   uint32_t   d_spare[NSPARE];        /* reserved for future use */
118   uint32_t   d_magic2;               /* the magic number (again) */   uint32_t   d_magic2;               /* the magic number (again) */
119   uint16_t   d_checksum;             /* xor of data incl. partitions */   uint16_t   d_checksum;             /* xor of data incl. partitions */
120   /* filesystem and partition information: */   /* filesystem and partition information: */
121   uint16_t   d_npartitions;          /* number of partitions in following */   uint16_t   d_npartitions;          /* number of partitions in following */
122   uint32_t   d_bbsize;               /* size of boot area at sn0, bytes */   uint32_t   d_bbsize;               /* size of boot area at sn0, bytes */
123   uint32_t   d_sbsize;               /* max size of fs superblock, bytes */   uint32_t   d_sbsize;               /* max size of fs superblock, bytes */
124   struct xbsd_partition    {      /* the partition table */   struct xbsd_partition { /* the partition table */
125   uint32_t   p_size;         /* number of sectors in partition */   uint32_t   p_size;         /* number of sectors in partition */
126   uint32_t   p_offset;       /* starting sector */   uint32_t   p_offset;       /* starting sector */
127   uint32_t   p_fsize;        /* filesystem basic fragment size */   uint32_t   p_fsize;        /* filesystem basic fragment size */
# Line 149  struct xbsd_disklabel { Line 147  struct xbsd_disklabel {
147  #define BSD_DSTYPE_DOSPART(s)   ((s) & 3)       /* dos partition number */  #define BSD_DSTYPE_DOSPART(s)   ((s) & 3)       /* dos partition number */
148  #define BSD_DSTYPE_GEOMETRY     0x10            /* drive params in label */  #define BSD_DSTYPE_GEOMETRY     0x10            /* drive params in label */
149    
150  static const char * const xbsd_dktypenames[] = {  static const char *const xbsd_dktypenames[] = {
151   "unknown",   "unknown",
152   "SMD",   "SMD",
153   "MSCP",   "MSCP",
# Line 163  static const char * const xbsd_dktypenam Line 161  static const char * const xbsd_dktypenam
161   "floppy",   "floppy",
162   0   0
163  };  };
164  #define BSD_DKMAXTYPES  (sizeof(xbsd_dktypenames) / sizeof(xbsd_dktypenames[0]) - 1)  
165    
166  /*  /*
167   * Filesystem type and version.   * Filesystem type and version.
# Line 195  static const char * const xbsd_dktypenam Line 193  static const char * const xbsd_dktypenam
193  #define BSD_FS_MSDOS    8               /* MS-DOS file system */  #define BSD_FS_MSDOS    8               /* MS-DOS file system */
194  #endif  #endif
195    
196  static const struct systypes xbsd_fstypes[] = {  static const char *const xbsd_fstypes[] = {
197   { "\x00" "unused" },            /* BSD_FS_UNUSED  */   "\x00" "unused",            /* BSD_FS_UNUSED  */
198   { "\x01" "swap" },              /* BSD_FS_SWAP    */   "\x01" "swap",              /* BSD_FS_SWAP    */
199   { "\x02" "Version 6" },         /* BSD_FS_V6      */   "\x02" "Version 6",         /* BSD_FS_V6      */
200   { "\x03" "Version 7" },         /* BSD_FS_V7      */   "\x03" "Version 7",         /* BSD_FS_V7      */
201   { "\x04" "System V" },          /* BSD_FS_SYSV    */   "\x04" "System V",          /* BSD_FS_SYSV    */
202   { "\x05" "4.1BSD" },            /* BSD_FS_V71K    */   "\x05" "4.1BSD",            /* BSD_FS_V71K    */
203   { "\x06" "Eighth Edition" },    /* BSD_FS_V8      */   "\x06" "Eighth Edition",    /* BSD_FS_V8      */
204   { "\x07" "4.2BSD" },            /* BSD_FS_BSDFFS  */   "\x07" "4.2BSD",            /* BSD_FS_BSDFFS  */
205  #ifdef __alpha__  #ifdef __alpha__
206   { "\x08" "ext2" },              /* BSD_FS_EXT2    */   "\x08" "ext2",              /* BSD_FS_EXT2    */
207  #else  #else
208   { "\x08" "MS-DOS" },            /* BSD_FS_MSDOS   */   "\x08" "MS-DOS",            /* BSD_FS_MSDOS   */
209  #endif  #endif
210   { "\x09" "4.4LFS" },            /* BSD_FS_BSDLFS  */   "\x09" "4.4LFS",            /* BSD_FS_BSDLFS  */
211   { "\x0a" "unknown" },           /* BSD_FS_OTHER   */   "\x0a" "unknown",           /* BSD_FS_OTHER   */
212   { "\x0b" "HPFS" },              /* BSD_FS_HPFS    */   "\x0b" "HPFS",              /* BSD_FS_HPFS    */
213   { "\x0c" "ISO-9660" },          /* BSD_FS_ISO9660 */   "\x0c" "ISO-9660",          /* BSD_FS_ISO9660 */
214   { "\x0d" "boot" },              /* BSD_FS_BOOT    */   "\x0d" "boot",              /* BSD_FS_BOOT    */
215   { "\x0e" "ADOS" },              /* BSD_FS_ADOS    */   "\x0e" "ADOS",              /* BSD_FS_ADOS    */
216   { "\x0f" "HFS" },               /* BSD_FS_HFS     */   "\x0f" "HFS",               /* BSD_FS_HFS     */
217   { "\x10" "AdvFS" },             /* BSD_FS_ADVFS   */   "\x10" "AdvFS",             /* BSD_FS_ADVFS   */
218   { NULL }   NULL
219  };  };
 #define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1)  
220    
221    
222  /*  /*
# Line 241  static const struct systypes xbsd_fstype Line 238  static const struct systypes xbsd_fstype
238     Also fixed unaligned accesses in alpha_bootblock_checksum()     Also fixed unaligned accesses in alpha_bootblock_checksum()
239  */  */
240    
 static int possibly_osf_label;  
   
241  #define FREEBSD_PARTITION       0xa5  #define FREEBSD_PARTITION       0xa5
242  #define NETBSD_PARTITION        0xa9  #define NETBSD_PARTITION        0xa9
243    
# Line 257  static int xbsd_get_part_index(int max); Line 252  static int xbsd_get_part_index(int max);
252  static int xbsd_check_new_partition(int *i);  static int xbsd_check_new_partition(int *i);
253  static void xbsd_list_types(void);  static void xbsd_list_types(void);
254  static uint16_t xbsd_dkcksum(struct xbsd_disklabel *lp);  static uint16_t xbsd_dkcksum(struct xbsd_disklabel *lp);
255  static int xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d);  static int xbsd_initlabel(struct partition *p);
256  static int xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d);  static int xbsd_readlabel(struct partition *p);
257  static int xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d);  static int xbsd_writelabel(struct partition *p);
258    
259  #if defined(__alpha__)  #if defined(__alpha__)
260  static void alpha_bootblock_checksum(char *boot);  static void alpha_bootblock_checksum(char *boot);
# Line 272  static struct partition *xbsd_part; Line 267  static struct partition *xbsd_part;
267  static int xbsd_part_index;  static int xbsd_part_index;
268  #endif  #endif
269    
270    
271    /* Group big globals data and allocate it in one go */
272    struct bsd_globals {
273  /* We access this through a uint64_t * when checksumming */  /* We access this through a uint64_t * when checksumming */
274  /* hopefully xmalloc gives us required alignment */  /* hopefully xmalloc gives us required alignment */
275  static char *disklabelbuffer; /*[BSD_BBSIZE]*/   char disklabelbuffer[BSD_BBSIZE];
276     struct xbsd_disklabel xbsd_dlabel;
277    };
278    
279  static struct xbsd_disklabel xbsd_dlabel;  static struct bsd_globals *bsd_globals_ptr;
280    
281    #define disklabelbuffer (bsd_globals_ptr->disklabelbuffer)
282    #define xbsd_dlabel     (bsd_globals_ptr->xbsd_dlabel)
283    
284    
285    /* Code */
286    
287  #define bsd_cround(n) \  #define bsd_cround(n) \
288   (display_in_cyl_units ? ((n)/xbsd_dlabel.d_secpercyl) + 1 : (n))   (display_in_cyl_units ? ((n)/xbsd_dlabel.d_secpercyl) + 1 : (n))
# Line 290  static struct xbsd_disklabel xbsd_dlabel Line 296  static struct xbsd_disklabel xbsd_dlabel
296  static int  static int
297  check_osf_label(void)  check_osf_label(void)
298  {  {
299   if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)   if (xbsd_readlabel(NULL) == 0)
300   return 0;   return 0;
301   return 1;   return 1;
302  }  }
# Line 298  check_osf_label(void) Line 304  check_osf_label(void)
304  static int  static int
305  bsd_trydev(const char * dev)  bsd_trydev(const char * dev)
306  {  {
307   if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)   if (xbsd_readlabel(NULL) == 0)
308   return -1;   return -1;
309   printf(_("\nBSD label for device: %s\n"), dev);   printf("\nBSD label for device: %s\n", dev);
310   xbsd_print_disklabel(0);   xbsd_print_disklabel(0);
311   return 0;   return 0;
312  }  }
# Line 308  bsd_trydev(const char * dev) Line 314  bsd_trydev(const char * dev)
314  static void  static void
315  bsd_menu(void)  bsd_menu(void)
316  {  {
317   puts(_("Command action"));   puts("Command Action");
318   puts(_("\td\tdelete a BSD partition"));   puts("d\tdelete a BSD partition");
319   puts(_("\te\tedit drive data"));   puts("e\tedit drive data");
320   puts(_("\ti\tinstall bootstrap"));   puts("i\tinstall bootstrap");
321   puts(_("\tl\tlist known filesystem types"));   puts("l\tlist known filesystem types");
322   puts(_("\tm\tprint this menu"));   puts("n\tadd a new BSD partition");
323   puts(_("\tn\tadd a new BSD partition"));   puts("p\tprint BSD partition table");
324   puts(_("\tp\tprint BSD partition table"));   puts("q\tquit without saving changes");
325   puts(_("\tq\tquit without saving changes"));   puts("r\treturn to main menu");
326   puts(_("\tr\treturn to main menu"));   puts("s\tshow complete disklabel");
327   puts(_("\ts\tshow complete disklabel"));   puts("t\tchange a partition's filesystem id");
328   puts(_("\tt\tchange a partition's filesystem id"));   puts("u\tchange units (cylinders/sectors)");
329   puts(_("\tu\tchange units (cylinders/sectors)"));   puts("w\twrite disklabel to disk");
  puts(_("\tw\twrite disklabel to disk"));  
330  #if !defined(__alpha__)  #if !defined(__alpha__)
331   puts(_("\tx\tlink BSD partition to non-BSD partition"));   puts("x\tlink BSD partition to non-BSD partition");
332  #endif  #endif
333  }  }
334    
# Line 358  bsd_select(void) Line 363  bsd_select(void)
363   xbsd_part_index = t;   xbsd_part_index = t;
364   ss = get_start_sect(xbsd_part);   ss = get_start_sect(xbsd_part);
365   if (ss == 0) {   if (ss == 0) {
366   fprintf(stderr, _("Partition %s has invalid starting sector 0.\n"),   printf("Partition %s has invalid starting sector 0\n",
367   partname(disk_device, t+1, 0));   partname(disk_device, t+1, 0));
368   return;   return;
369   }   }
370   printf(_("Reading disklabel of %s at sector %d.\n"),   printf("Reading disklabel of %s at sector %u\n",
371   partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR);   partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR);
372   if (xbsd_readlabel(xbsd_part, &xbsd_dlabel) == 0)   if (xbsd_readlabel(xbsd_part) == 0)
373   if (xbsd_create_disklabel() == 0)   if (xbsd_create_disklabel() == 0)
374   return;   return;
375   break;   break;
# Line 372  bsd_select(void) Line 377  bsd_select(void)
377   }   }
378    
379   if (t == 4) {   if (t == 4) {
380   printf(_("There is no *BSD partition on %s.\n"), disk_device);   printf("There is no *BSD partition on %s\n", disk_device);
381   return;   return;
382   }   }
383    
384  #elif defined(__alpha__)  #elif defined(__alpha__)
385    
386   if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)   if (xbsd_readlabel(NULL) == 0)
387   if (xbsd_create_disklabel() == 0)   if (xbsd_create_disklabel() == 0)
388   exit(EXIT_SUCCESS);   exit(EXIT_SUCCESS);
389    
390  #endif  #endif
391    
392   while (1) {   while (1) {
393   putchar('\n');   bb_putchar('\n');
394   switch (tolower(read_nonempty(_("BSD disklabel command (m for help): ")))) {   switch (tolower(read_nonempty("BSD disklabel command (m for help): "))) {
395   case 'd':   case 'd':
396   xbsd_delete_part();   xbsd_delete_part();
397   break;   break;
# Line 406  bsd_select(void) Line 411  bsd_select(void)
411   xbsd_print_disklabel(0);   xbsd_print_disklabel(0);
412   break;   break;
413   case 'q':   case 'q':
414   close(fd);   if (ENABLE_FEATURE_CLEAN_UP)
415     close_dev_fd();
416   exit(EXIT_SUCCESS);   exit(EXIT_SUCCESS);
417   case 'r':   case 'r':
418   return;   return;
# Line 466  xbsd_new_part(void) Line 472  xbsd_new_part(void)
472   end = xbsd_dlabel.d_secperunit - 1;   end = xbsd_dlabel.d_secperunit - 1;
473  #endif  #endif
474    
475   snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));   snprintf(mesg, sizeof(mesg), "First %s", str_units(SINGULAR));
476   begin = read_int(bsd_cround(begin), bsd_cround(begin), bsd_cround(end),   begin = read_int(bsd_cround(begin), bsd_cround(begin), bsd_cround(end),
477   0, mesg);   0, mesg);
478    
479   if (display_in_cyl_units)   if (display_in_cyl_units)
480   begin = (begin - 1) * xbsd_dlabel.d_secpercyl;   begin = (begin - 1) * xbsd_dlabel.d_secpercyl;
481    
482   snprintf(mesg, sizeof(mesg), _("Last %s or +size or +sizeM or +sizeK"),   snprintf(mesg, sizeof(mesg), "Last %s or +size or +sizeM or +sizeK",
483   str_units(SINGULAR));   str_units(SINGULAR));
484   end = read_int(bsd_cround(begin), bsd_cround(end), bsd_cround(end),   end = read_int(bsd_cround(begin), bsd_cround(end), bsd_cround(end),
485   bsd_cround(begin), mesg);   bsd_cround(begin), mesg);
# Line 494  xbsd_print_disklabel(int show_all) Line 500  xbsd_print_disklabel(int show_all)
500   int i, j;   int i, j;
501    
502   if (show_all) {   if (show_all) {
503     static const int d_masks[] = { BSD_D_REMOVABLE, BSD_D_ECC, BSD_D_BADSECT };
504    
505  #if defined(__alpha__)  #if defined(__alpha__)
506   printf("# %s:\n", disk_device);   printf("# %s:\n", disk_device);
507  #else  #else
508   printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));   printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));
509  #endif  #endif
510   if ((unsigned) lp->d_type < BSD_DKMAXTYPES)   if ((unsigned) lp->d_type < ARRAY_SIZE(xbsd_dktypenames)-1)
511   printf(_("type: %s\n"), xbsd_dktypenames[lp->d_type]);   printf("type: %s\n", xbsd_dktypenames[lp->d_type]);
512   else   else
513   printf(_("type: %d\n"), lp->d_type);   printf("type: %u\n", lp->d_type);
514   printf(_("disk: %.*s\n"), (int) sizeof(lp->d_typename), lp->d_typename);   printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
515   printf(_("label: %.*s\n"), (int) sizeof(lp->d_packname), lp->d_packname);   printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
516   printf(_("flags:"));   printf("flags: ");
517   if (lp->d_flags & BSD_D_REMOVABLE)   print_flags_separated(d_masks, "removable\0""ecc\0""badsect\0", lp->d_flags, " ");
518   printf(_(" removable"));   bb_putchar('\n');
  if (lp->d_flags & BSD_D_ECC)  
  printf(_(" ecc"));  
  if (lp->d_flags & BSD_D_BADSECT)  
  printf(_(" badsect"));  
  puts("");  
519   /* On various machines the fields of *lp are short/int/long */   /* On various machines the fields of *lp are short/int/long */
520   /* In order to avoid problems, we cast them all to long. */   /* In order to avoid problems, we cast them all to long. */
521   printf(_("bytes/sector: %ld\n"), (long) lp->d_secsize);   printf("bytes/sector: %lu\n", (long) lp->d_secsize);
522   printf(_("sectors/track: %ld\n"), (long) lp->d_nsectors);   printf("sectors/track: %lu\n", (long) lp->d_nsectors);
523   printf(_("tracks/cylinder: %ld\n"), (long) lp->d_ntracks);   printf("tracks/cylinder: %lu\n", (long) lp->d_ntracks);
524   printf(_("sectors/cylinder: %ld\n"), (long) lp->d_secpercyl);   printf("sectors/cylinder: %lu\n", (long) lp->d_secpercyl);
525   printf(_("cylinders: %ld\n"), (long) lp->d_ncylinders);   printf("cylinders: %lu\n", (long) lp->d_ncylinders);
526   printf(_("rpm: %d\n"), lp->d_rpm);   printf("rpm: %u\n", lp->d_rpm);
527   printf(_("interleave: %d\n"), lp->d_interleave);   printf("interleave: %u\n", lp->d_interleave);
528   printf(_("trackskew: %d\n"), lp->d_trackskew);   printf("trackskew: %u\n", lp->d_trackskew);
529   printf(_("cylinderskew: %d\n"), lp->d_cylskew);   printf("cylinderskew: %u\n", lp->d_cylskew);
530   printf(_("headswitch: %ld\t\t# milliseconds\n"),   printf("headswitch: %lu\t\t# milliseconds\n",
531   (long) lp->d_headswitch);   (long) lp->d_headswitch);
532   printf(_("track-to-track seek: %ld\t# milliseconds\n"),   printf("track-to-track seek: %lu\t# milliseconds\n",
533   (long) lp->d_trkseek);   (long) lp->d_trkseek);
534   printf(_("drivedata: "));   printf("drivedata: ");
535   for (i = NDDATA - 1; i >= 0; i--)   for (i = NDDATA - 1; i >= 0; i--)
536   if (lp->d_drivedata[i])   if (lp->d_drivedata[i])
537   break;   break;
538   if (i < 0)   if (i < 0)
539   i = 0;   i = 0;
540   for (j = 0; j <= i; j++)   for (j = 0; j <= i; j++)
541   printf("%ld ", (long) lp->d_drivedata[j]);   printf("%lu ", (long) lp->d_drivedata[j]);
542   }   }
543   printf(_("\n%d partitions:\n"), lp->d_npartitions);   printf("\n%u partitions:\n", lp->d_npartitions);
544   printf(_("#       start       end      size     fstype   [fsize bsize   cpg]\n"));   printf("#       start       end      size     fstype   [fsize bsize   cpg]\n");
545   pp = lp->d_partitions;   pp = lp->d_partitions;
546   for (i = 0; i < lp->d_npartitions; i++, pp++) {   for (i = 0; i < lp->d_npartitions; i++, pp++) {
547   if (pp->p_size) {   if (pp->p_size) {
548   if (display_in_cyl_units && lp->d_secpercyl) {   if (display_in_cyl_units && lp->d_secpercyl) {
549   printf("  %c: %8ld%c %8ld%c %8ld%c  ",   printf("  %c: %8lu%c %8lu%c %8lu%c  ",
550   'a' + i,   'a' + i,
551   (long) pp->p_offset / lp->d_secpercyl + 1,   (unsigned long) pp->p_offset / lp->d_secpercyl + 1,
552   (pp->p_offset % lp->d_secpercyl) ? '*' : ' ',   (pp->p_offset % lp->d_secpercyl) ? '*' : ' ',
553   (long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl,   (unsigned long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl,
554   ((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ',   ((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ',
555   (long) pp->p_size / lp->d_secpercyl,   (long) pp->p_size / lp->d_secpercyl,
556   (pp->p_size % lp->d_secpercyl) ? '*' : ' '   (pp->p_size % lp->d_secpercyl) ? '*' : ' '
557   );   );
558   } else {   } else {
559   printf("  %c: %8ld  %8ld  %8ld   ",   printf("  %c: %8lu  %8lu  %8lu   ",
560   'a' + i,   'a' + i,
561   (long) pp->p_offset,   (long) pp->p_offset,
562   (long) pp->p_offset + pp->p_size - 1,   (long) pp->p_offset + pp->p_size - 1,
# Line 561  xbsd_print_disklabel(int show_all) Line 564  xbsd_print_disklabel(int show_all)
564   );   );
565   }   }
566    
567   if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES)   if ((unsigned) pp->p_fstype < ARRAY_SIZE(xbsd_fstypes)-1)
568   printf("%8.8s", xbsd_fstypes[pp->p_fstype].name);   printf("%8.8s", xbsd_fstypes[pp->p_fstype]);
569   else   else
570   printf("%8x", pp->p_fstype);   printf("%8x", pp->p_fstype);
571    
572   switch (pp->p_fstype) {   switch (pp->p_fstype) {
573   case BSD_FS_UNUSED:   case BSD_FS_UNUSED:
574   printf("    %5ld %5ld %5.5s ",   printf("    %5lu %5lu %5.5s ",
575   (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, "");   (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, "");
576   break;   break;
577   case BSD_FS_BSDFFS:   case BSD_FS_BSDFFS:
578   printf("    %5ld %5ld %5d ",   printf("    %5lu %5lu %5u ",
579   (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, pp->p_cpg);   (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, pp->p_cpg);
580   break;   break;
581   default:   default:
582   printf("%22.22s", "");   printf("%22.22s", "");
583   break;   break;
584   }   }
585   puts("");   bb_putchar('\n');
586   }   }
587   }   }
588  }  }
# Line 588  static void Line 591  static void
591  xbsd_write_disklabel(void)  xbsd_write_disklabel(void)
592  {  {
593  #if defined(__alpha__)  #if defined(__alpha__)
594   printf(_("Writing disklabel to %s.\n"), disk_device);   printf("Writing disklabel to %s\n", disk_device);
595   xbsd_writelabel(NULL, &xbsd_dlabel);   xbsd_writelabel(NULL);
596  #else  #else
597   printf(_("Writing disklabel to %s.\n"),   printf("Writing disklabel to %s\n",
598   partname(disk_device, xbsd_part_index + 1, 0));   partname(disk_device, xbsd_part_index + 1, 0));
599   xbsd_writelabel(xbsd_part, &xbsd_dlabel);   xbsd_writelabel(xbsd_part);
600  #endif  #endif
601   reread_partition_table(0);      /* no exit yet */   reread_partition_table(0);      /* no exit yet */
602  }  }
# Line 604  xbsd_create_disklabel(void) Line 607  xbsd_create_disklabel(void)
607   char c;   char c;
608    
609  #if defined(__alpha__)  #if defined(__alpha__)
610   fprintf(stderr, _("%s contains no disklabel.\n"), disk_device);   printf("%s contains no disklabel\n", disk_device);
611  #else  #else
612   fprintf(stderr, _("%s contains no disklabel.\n"),   printf("%s contains no disklabel\n",
613   partname(disk_device, xbsd_part_index + 1, 0));   partname(disk_device, xbsd_part_index + 1, 0));
614  #endif  #endif
615    
616   while (1) {   while (1) {
617   c = read_nonempty(_("Do you want to create a disklabel? (y/n) "));   c = read_nonempty("Do you want to create a disklabel? (y/n) ");
618   if (c == 'y' || c == 'Y') {   if ((c|0x20) == 'y') {
619   if (xbsd_initlabel(   if (xbsd_initlabel(
620  #if defined(__alpha__) || defined(__powerpc__) || defined(__hppa__) || \  #if defined(__alpha__) || defined(__powerpc__) || defined(__hppa__) || \
621   defined(__s390__) || defined(__s390x__)   defined(__s390__) || defined(__s390x__)
622   NULL, &xbsd_dlabel   NULL
623  #else  #else
624   xbsd_part, &xbsd_dlabel/* not used, xbsd_part_index*/   xbsd_part
625  #endif  #endif
626   ) == 1) {   ) == 1) {
627   xbsd_print_disklabel(1);   xbsd_print_disklabel(1);
628   return 1;   return 1;
629   } else   }
630   return 0;   return 0;
631   } else if (c == 'n')   }
632     if ((c|0x20) == 'n')
633   return 0;   return 0;
634   }   }
635  }  }
636    
637  static int  static int
638  edit_int(int def, char *mesg)  edit_int(int def, const char *mesg)
639  {  {
640     mesg = xasprintf("%s (%u): ", mesg, def);
641   do {   do {
642   fputs(mesg, stdout);   if (!read_line(mesg))
643   printf(" (%d): ", def);   goto ret;
  if (!read_line())  
  return def;  
644   } while (!isdigit(*line_ptr));   } while (!isdigit(*line_ptr));
645   return atoi(line_ptr);   def = atoi(line_ptr);
646     ret:
647     free((char*)mesg);
648     return def;
649  }  }
650    
651  static void  static void
# Line 650  xbsd_edit_disklabel(void) Line 656  xbsd_edit_disklabel(void)
656   d = &xbsd_dlabel;   d = &xbsd_dlabel;
657    
658  #if defined(__alpha__) || defined(__ia64__)  #if defined(__alpha__) || defined(__ia64__)
659   d->d_secsize    = edit_int(d->d_secsize     ,_("bytes/sector"));   d->d_secsize    = edit_int(d->d_secsize     , "bytes/sector");
660   d->d_nsectors   = edit_int(d->d_nsectors    ,_("sectors/track"));   d->d_nsectors   = edit_int(d->d_nsectors    , "sectors/track");
661   d->d_ntracks    = edit_int(d->d_ntracks     ,_("tracks/cylinder"));   d->d_ntracks    = edit_int(d->d_ntracks     , "tracks/cylinder");
662   d->d_ncylinders = edit_int(d->d_ncylinders  ,_("cylinders"));   d->d_ncylinders = edit_int(d->d_ncylinders  , "cylinders");
663  #endif  #endif
664    
665   /* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */   /* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */
666   while (1) {   while (1) {
667   d->d_secpercyl = edit_int(d->d_nsectors * d->d_ntracks,   d->d_secpercyl = edit_int(d->d_nsectors * d->d_ntracks,
668   _("sectors/cylinder"));   "sectors/cylinder");
669   if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks)   if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks)
670   break;   break;
671    
672   printf(_("Must be <= sectors/track * tracks/cylinder (default).\n"));   printf("Must be <= sectors/track * tracks/cylinder (default)\n");
673   }   }
674   d->d_rpm        = edit_int(d->d_rpm       ,_("rpm"));   d->d_rpm        = edit_int(d->d_rpm       , "rpm");
675   d->d_interleave = edit_int(d->d_interleave,_("interleave"));   d->d_interleave = edit_int(d->d_interleave, "interleave");
676   d->d_trackskew  = edit_int(d->d_trackskew ,_("trackskew"));   d->d_trackskew  = edit_int(d->d_trackskew , "trackskew");
677   d->d_cylskew    = edit_int(d->d_cylskew   ,_("cylinderskew"));   d->d_cylskew    = edit_int(d->d_cylskew   , "cylinderskew");
678   d->d_headswitch = edit_int(d->d_headswitch,_("headswitch"));   d->d_headswitch = edit_int(d->d_headswitch, "headswitch");
679   d->d_trkseek    = edit_int(d->d_trkseek   ,_("track-to-track seek"));   d->d_trkseek    = edit_int(d->d_trkseek   , "track-to-track seek");
680    
681   d->d_secperunit = d->d_secpercyl * d->d_ncylinders;   d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
682  }  }
# Line 680  xbsd_get_bootstrap(char *path, void *ptr Line 686  xbsd_get_bootstrap(char *path, void *ptr
686  {  {
687   int fdb;   int fdb;
688    
689   fdb = open(path, O_RDONLY);   fdb = open_or_warn(path, O_RDONLY);
690   if (fdb < 0) {   if (fdb < 0) {
  perror(path);  
691   return 0;   return 0;
692   }   }
693   if (read(fdb, ptr, size) < 0) {   if (full_read(fdb, ptr, size) < 0) {
694   perror(path);   bb_simple_perror_msg(path);
695   close(fdb);   close(fdb);
696   return 0;   return 0;
697   }   }
# Line 698  xbsd_get_bootstrap(char *path, void *ptr Line 703  xbsd_get_bootstrap(char *path, void *ptr
703  static void  static void
704  sync_disks(void)  sync_disks(void)
705  {  {
706   printf(_("\nSyncing disks.\n"));   printf("Syncing disks\n");
707   sync();   sync();
708   sleep(4); /* What? */   /* sleep(4); What? */
709  }  }
710    
711  static void  static void
712  xbsd_write_bootstrap(void)  xbsd_write_bootstrap(void)
713  {  {
  char *bootdir = BSD_LINUX_BOOTDIR;  
714   char path[MAXPATHLEN];   char path[MAXPATHLEN];
715   char *dkbasename;   const char *bootdir = BSD_LINUX_BOOTDIR;
716     const char *dkbasename;
717   struct xbsd_disklabel dl;   struct xbsd_disklabel dl;
718   char *d, *p, *e;   char *d, *p, *e;
719   int sector;   int sector;
# Line 718  xbsd_write_bootstrap(void) Line 723  xbsd_write_bootstrap(void)
723   else   else
724   dkbasename = "wd";   dkbasename = "wd";
725    
726   printf(_("Bootstrap: %sboot -> boot%s (%s): "),   snprintf(path, sizeof(path), "Bootstrap: %sboot -> boot%s (%s): ",
727   dkbasename, dkbasename, dkbasename);   dkbasename, dkbasename, dkbasename);
728   if (read_line()) {   if (read_line(path)) {
  line_ptr[strlen(line_ptr)-1] = '\0';  
729   dkbasename = line_ptr;   dkbasename = line_ptr;
730   }   }
731   snprintf(path, sizeof(path), "%s/%sboot", bootdir, dkbasename);   snprintf(path, sizeof(path), "%s/%sboot", bootdir, dkbasename);
# Line 743  xbsd_write_bootstrap(void) Line 747  xbsd_write_bootstrap(void)
747   e = d + sizeof(struct xbsd_disklabel);   e = d + sizeof(struct xbsd_disklabel);
748   for (p = d; p < e; p++)   for (p = d; p < e; p++)
749   if (*p) {   if (*p) {
750   fprintf(stderr, _("Bootstrap overlaps with disk label!\n"));   printf("Bootstrap overlaps with disk label!\n");
751   exit(EXIT_FAILURE);   exit(EXIT_FAILURE);
752   }   }
753    
# Line 758  xbsd_write_bootstrap(void) Line 762  xbsd_write_bootstrap(void)
762   sector = get_start_sect(xbsd_part);   sector = get_start_sect(xbsd_part);
763  #endif  #endif
764    
765   if (lseek(fd, sector * SECTOR_SIZE, SEEK_SET) == -1)   seek_sector(sector);
766   fdisk_fatal(unable_to_seek);   xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
  if (BSD_BBSIZE != write(fd, disklabelbuffer, BSD_BBSIZE))  
  fdisk_fatal(unable_to_write);  
767    
768  #if defined(__alpha__)  #if defined(__alpha__)
769   printf(_("Bootstrap installed on %s.\n"), disk_device);   printf("Bootstrap installed on %s\n", disk_device);
770  #else  #else
771   printf(_("Bootstrap installed on %s.\n"),   printf("Bootstrap installed on %s\n",
772   partname(disk_device, xbsd_part_index+1, 0));   partname(disk_device, xbsd_part_index+1, 0));
773  #endif  #endif
774    
# Line 785  xbsd_change_fstype(void) Line 787  xbsd_change_fstype(void)
787  static int  static int
788  xbsd_get_part_index(int max)  xbsd_get_part_index(int max)
789  {  {
790   char prompt[256];   char prompt[sizeof("Partition (a-%c): ") + 16];
791   char l;   char l;
792    
793   snprintf(prompt, sizeof(prompt), _("Partition (a-%c): "), 'a' + max - 1);   snprintf(prompt, sizeof(prompt), "Partition (a-%c): ", 'a' + max - 1);
794   do   do
795   l = tolower(read_nonempty(prompt));   l = tolower(read_nonempty(prompt));
796   while (l < 'a' || l > 'a' + max - 1);   while (l < 'a' || l > 'a' + max - 1);
# Line 807  xbsd_check_new_partition(int *i) Line 809  xbsd_check_new_partition(int *i)
809   break;   break;
810    
811   if (t == BSD_MAXPARTITIONS) {   if (t == BSD_MAXPARTITIONS) {
812   fprintf(stderr, _("The maximum number of partitions "   printf("The maximum number of partitions has been created\n");
    "has been created\n"));  
813   return 0;   return 0;
814   }   }
815   }   }
# Line 819  xbsd_check_new_partition(int *i) Line 820  xbsd_check_new_partition(int *i)
820   xbsd_dlabel.d_npartitions = (*i) + 1;   xbsd_dlabel.d_npartitions = (*i) + 1;
821    
822   if (xbsd_dlabel.d_partitions[*i].p_size != 0) {   if (xbsd_dlabel.d_partitions[*i].p_size != 0) {
823   fprintf(stderr, _("This partition already exists.\n"));   printf("This partition already exists\n");
824   return 0;   return 0;
825   }   }
826    
# Line 846  xbsd_dkcksum(struct xbsd_disklabel *lp) Line 847  xbsd_dkcksum(struct xbsd_disklabel *lp)
847  }  }
848    
849  static int  static int
850  xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d)  xbsd_initlabel(struct partition *p)
851  {  {
852     struct xbsd_disklabel *d = &xbsd_dlabel;
853   struct xbsd_partition *pp;   struct xbsd_partition *pp;
854    
855   get_geometry();   get_geometry();
# Line 866  xbsd_initlabel(struct partition *p, stru Line 868  xbsd_initlabel(struct partition *p, stru
868   d->d_flags = 0;   d->d_flags = 0;
869  #endif  #endif
870   d->d_secsize = SECTOR_SIZE;           /* bytes/sector  */   d->d_secsize = SECTOR_SIZE;           /* bytes/sector  */
871   d->d_nsectors = sectors;              /* sectors/track */   d->d_nsectors = g_sectors;            /* sectors/track */
872   d->d_ntracks = heads;                 /* tracks/cylinder (heads) */   d->d_ntracks = g_heads;               /* tracks/cylinder (heads) */
873   d->d_ncylinders = cylinders;   d->d_ncylinders = g_cylinders;
874   d->d_secpercyl  = sectors * heads;    /* sectors/cylinder */   d->d_secpercyl  = g_sectors * g_heads;/* sectors/cylinder */
875   if (d->d_secpercyl == 0)   if (d->d_secpercyl == 0)
876   d->d_secpercyl = 1;           /* avoid segfaults */   d->d_secpercyl = 1;           /* avoid segfaults */
877   d->d_secperunit = d->d_secpercyl * d->d_ncylinders;   d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
# Line 897  xbsd_initlabel(struct partition *p, stru Line 899  xbsd_initlabel(struct partition *p, stru
899   pp->p_offset = 0;   pp->p_offset = 0;
900   pp->p_size   = d->d_secperunit;   pp->p_size   = d->d_secperunit;
901   pp->p_fstype = BSD_FS_UNUSED;   pp->p_fstype = BSD_FS_UNUSED;
902  #elif defined(__alpha__)  #else
903   d->d_npartitions = 3;   d->d_npartitions = 3;
904   pp = &d->d_partitions[2];             /* Partition C should be   pp = &d->d_partitions[2];             /* Partition C should be
905     the whole disk */     the whole disk */
# Line 914  xbsd_initlabel(struct partition *p, stru Line 916  xbsd_initlabel(struct partition *p, stru
916   * If it has the right magic, return 1.   * If it has the right magic, return 1.
917   */   */
918  static int  static int
919  xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d)  xbsd_readlabel(struct partition *p)
920  {  {
921     struct xbsd_disklabel *d;
922   int t, sector;   int t, sector;
923    
924   if (!disklabelbuffer)   if (!bsd_globals_ptr)
925   disklabelbuffer = xmalloc(BSD_BBSIZE);   bsd_globals_ptr = xzalloc(sizeof(*bsd_globals_ptr));
926    
927     d = &xbsd_dlabel;
928    
929   /* p is used only to get the starting sector */   /* p is used only to get the starting sector */
930  #if !defined(__alpha__)  #if !defined(__alpha__)
931   sector = (p ? get_start_sect(p) : 0);   sector = (p ? get_start_sect(p) : 0);
932  #elif defined(__alpha__)  #else
933   sector = 0;   sector = 0;
934  #endif  #endif
935    
936   if (lseek(fd, sector * SECTOR_SIZE, SEEK_SET) == -1)   seek_sector(sector);
937   fdisk_fatal(unable_to_seek);   if (BSD_BBSIZE != full_read(dev_fd, disklabelbuffer, BSD_BBSIZE))
  if (BSD_BBSIZE != read(fd, disklabelbuffer, BSD_BBSIZE))  
938   fdisk_fatal(unable_to_read);   fdisk_fatal(unable_to_read);
939    
940   memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],   memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
# Line 946  xbsd_readlabel(struct partition *p, stru Line 950  xbsd_readlabel(struct partition *p, stru
950   }   }
951    
952   if (d->d_npartitions > BSD_MAXPARTITIONS)   if (d->d_npartitions > BSD_MAXPARTITIONS)
953   fprintf(stderr, _("Warning: too many partitions "   printf("Warning: too many partitions (%u, maximum is %u)\n",
  "(%d, maximum is %d).\n"),  
954   d->d_npartitions, BSD_MAXPARTITIONS);   d->d_npartitions, BSD_MAXPARTITIONS);
955   return 1;   return 1;
956  }  }
957    
958  static int  static int
959  xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d)  xbsd_writelabel(struct partition *p)
960  {  {
961     struct xbsd_disklabel *d = &xbsd_dlabel;
962   unsigned int sector;   unsigned int sector;
963    
964  #if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__)  #if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__)
965   sector = get_start_sect(p) + BSD_LABELSECTOR;   sector = get_start_sect(p) + BSD_LABELSECTOR;
966  #else  #else
967     (void)p; /* silence warning */
968   sector = BSD_LABELSECTOR;   sector = BSD_LABELSECTOR;
969  #endif  #endif
970    
# Line 974  xbsd_writelabel(struct partition *p, str Line 979  xbsd_writelabel(struct partition *p, str
979    
980  #if defined(__alpha__) && BSD_LABELSECTOR == 0  #if defined(__alpha__) && BSD_LABELSECTOR == 0
981   alpha_bootblock_checksum(disklabelbuffer);   alpha_bootblock_checksum(disklabelbuffer);
982   if (lseek(fd, 0, SEEK_SET) == -1)   seek_sector(0);
983   fdisk_fatal(unable_to_seek);   xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
  if (BSD_BBSIZE != write(fd, disklabelbuffer, BSD_BBSIZE))  
  fdisk_fatal(unable_to_write);  
984  #else  #else
985   if (lseek(fd, sector * SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1)   seek_sector(sector);
986   fdisk_fatal(unable_to_seek);   lseek(dev_fd, BSD_LABELOFFSET, SEEK_CUR);
987   if (sizeof(struct xbsd_disklabel) != write(fd, d, sizeof(struct xbsd_disklabel)))   xwrite(dev_fd, d, sizeof(*d));
  fdisk_fatal(unable_to_write);  
988  #endif  #endif
989   sync_disks();   sync_disks();
990   return 1;   return 1;
# Line 1014  xbsd_link_part(void) Line 1016  xbsd_link_part(void)
1016   int k, i;   int k, i;
1017   struct partition *p;   struct partition *p;
1018    
1019   k = get_partition(1, partitions);   k = get_partition(1, g_partitions);
1020    
1021   if (!xbsd_check_new_partition(&i))   if (!xbsd_check_new_partition(&i))
1022   return;   return;
# Line 1028  xbsd_link_part(void) Line 1030  xbsd_link_part(void)
1030  #endif  #endif
1031    
1032  #if defined(__alpha__)  #if defined(__alpha__)
   
1033  static void  static void
1034  alpha_bootblock_checksum(char *boot)  alpha_bootblock_checksum(char *boot)
1035  {  {
# Line 1043  alpha_bootblock_checksum(char *boot) Line 1044  alpha_bootblock_checksum(char *boot)
1044  }  }
1045  #endif /* __alpha__ */  #endif /* __alpha__ */
1046    
1047    /* Undefine 'global' tricks */
1048    #undef disklabelbuffer
1049    #undef xbsd_dlabel
1050    
1051  #endif /* OSF_LABEL */  #endif /* OSF_LABEL */

Legend:
Removed from v.532  
changed lines
  Added in v.984