2006-10-13 01:00:44 +05:30
|
|
|
/*
|
|
|
|
* Copyright (c) 1987, 1988 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgment:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
2017-08-02 17:56:33 +05:30
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND
|
2006-10-13 01:00:44 +05:30
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2008-12-07 06:22:58 +05:30
|
|
|
#if ENABLE_FEATURE_OSF_LABEL
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
#ifndef BSD_DISKMAGIC
|
|
|
|
#define BSD_DISKMAGIC ((uint32_t) 0x82564557)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef BSD_MAXPARTITIONS
|
|
|
|
#define BSD_MAXPARTITIONS 16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BSD_LINUX_BOOTDIR "/usr/ucb/mdec"
|
|
|
|
|
2011-01-31 10:25:52 +05:30
|
|
|
#if defined(__alpha__) \
|
|
|
|
|| defined(__powerpc__) \
|
|
|
|
|| defined(__ia64__) \
|
2007-01-02 22:15:05 +05:30
|
|
|
|| defined(__hppa__)
|
2009-08-10 03:38:35 +05:30
|
|
|
# define BSD_LABELSECTOR 0
|
|
|
|
# define BSD_LABELOFFSET 64
|
2006-10-13 01:00:44 +05:30
|
|
|
#else
|
2011-01-31 10:25:52 +05:30
|
|
|
# define BSD_LABELSECTOR 1
|
|
|
|
# define BSD_LABELOFFSET 0
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BSD_BBSIZE 8192 /* size of boot area, with label */
|
|
|
|
#define BSD_SBSIZE 8192 /* max size of fs superblock */
|
|
|
|
|
|
|
|
struct xbsd_disklabel {
|
|
|
|
uint32_t d_magic; /* the magic number */
|
|
|
|
int16_t d_type; /* drive type */
|
|
|
|
int16_t d_subtype; /* controller/d_type specific */
|
|
|
|
char d_typename[16]; /* type name, e.g. "eagle" */
|
2009-09-16 06:33:13 +05:30
|
|
|
char d_packname[16]; /* pack identifier */
|
|
|
|
/* disk geometry: */
|
2006-10-13 01:00:44 +05:30
|
|
|
uint32_t d_secsize; /* # of bytes per sector */
|
|
|
|
uint32_t d_nsectors; /* # of data sectors per track */
|
|
|
|
uint32_t d_ntracks; /* # of tracks per cylinder */
|
|
|
|
uint32_t d_ncylinders; /* # of data cylinders per unit */
|
|
|
|
uint32_t d_secpercyl; /* # of data sectors per cylinder */
|
|
|
|
uint32_t d_secperunit; /* # of data sectors per unit */
|
|
|
|
/*
|
|
|
|
* Spares (bad sector replacements) below
|
|
|
|
* are not counted in d_nsectors or d_secpercyl.
|
|
|
|
* Spare sectors are assumed to be physical sectors
|
|
|
|
* which occupy space at the end of each track and/or cylinder.
|
|
|
|
*/
|
|
|
|
uint16_t d_sparespertrack; /* # of spare sectors per track */
|
|
|
|
uint16_t d_sparespercyl; /* # of spare sectors per cylinder */
|
|
|
|
/*
|
|
|
|
* Alternate cylinders include maintenance, replacement,
|
|
|
|
* configuration description areas, etc.
|
|
|
|
*/
|
|
|
|
uint32_t d_acylinders; /* # of alt. cylinders per unit */
|
|
|
|
|
2009-09-16 06:33:13 +05:30
|
|
|
/* hardware characteristics: */
|
2006-10-13 01:00:44 +05:30
|
|
|
/*
|
|
|
|
* d_interleave, d_trackskew and d_cylskew describe perturbations
|
|
|
|
* in the media format used to compensate for a slow controller.
|
|
|
|
* Interleave is physical sector interleave, set up by the formatter
|
|
|
|
* or controller when formatting. When interleaving is in use,
|
|
|
|
* logically adjacent sectors are not physically contiguous,
|
|
|
|
* but instead are separated by some number of sectors.
|
|
|
|
* It is specified as the ratio of physical sectors traversed
|
|
|
|
* per logical sector. Thus an interleave of 1:1 implies contiguous
|
|
|
|
* layout, while 2:1 implies that logical sector 0 is separated
|
|
|
|
* by one sector from logical sector 1.
|
|
|
|
* d_trackskew is the offset of sector 0 on track N
|
|
|
|
* relative to sector 0 on track N-1 on the same cylinder.
|
|
|
|
* Finally, d_cylskew is the offset of sector 0 on cylinder N
|
|
|
|
* relative to sector 0 on cylinder N-1.
|
|
|
|
*/
|
|
|
|
uint16_t d_rpm; /* rotational speed */
|
|
|
|
uint16_t d_interleave; /* hardware sector interleave */
|
|
|
|
uint16_t d_trackskew; /* sector 0 skew, per track */
|
|
|
|
uint16_t d_cylskew; /* sector 0 skew, per cylinder */
|
|
|
|
uint32_t d_headswitch; /* head switch time, usec */
|
|
|
|
uint32_t d_trkseek; /* track-to-track seek, usec */
|
|
|
|
uint32_t d_flags; /* generic flags */
|
|
|
|
#define NDDATA 5
|
|
|
|
uint32_t d_drivedata[NDDATA]; /* drive-type specific information */
|
|
|
|
#define NSPARE 5
|
|
|
|
uint32_t d_spare[NSPARE]; /* reserved for future use */
|
|
|
|
uint32_t d_magic2; /* the magic number (again) */
|
|
|
|
uint16_t d_checksum; /* xor of data incl. partitions */
|
2009-09-16 06:33:13 +05:30
|
|
|
/* filesystem and partition information: */
|
2006-10-13 01:00:44 +05:30
|
|
|
uint16_t d_npartitions; /* number of partitions in following */
|
|
|
|
uint32_t d_bbsize; /* size of boot area at sn0, bytes */
|
|
|
|
uint32_t d_sbsize; /* max size of fs superblock, bytes */
|
2009-09-16 06:33:13 +05:30
|
|
|
struct xbsd_partition { /* the partition table */
|
2006-10-13 01:00:44 +05:30
|
|
|
uint32_t p_size; /* number of sectors in partition */
|
|
|
|
uint32_t p_offset; /* starting sector */
|
|
|
|
uint32_t p_fsize; /* filesystem basic fragment size */
|
|
|
|
uint8_t p_fstype; /* filesystem type, see below */
|
|
|
|
uint8_t p_frag; /* filesystem fragments per block */
|
|
|
|
uint16_t p_cpg; /* filesystem cylinders per group */
|
|
|
|
} d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* d_type values: */
|
|
|
|
#define BSD_DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
|
|
|
|
#define BSD_DTYPE_MSCP 2 /* MSCP */
|
|
|
|
#define BSD_DTYPE_DEC 3 /* other DEC (rk, rl) */
|
|
|
|
#define BSD_DTYPE_SCSI 4 /* SCSI */
|
|
|
|
#define BSD_DTYPE_ESDI 5 /* ESDI interface */
|
|
|
|
#define BSD_DTYPE_ST506 6 /* ST506 etc. */
|
|
|
|
#define BSD_DTYPE_HPIB 7 /* CS/80 on HP-IB */
|
|
|
|
#define BSD_DTYPE_HPFL 8 /* HP Fiber-link */
|
|
|
|
#define BSD_DTYPE_FLOPPY 10 /* floppy */
|
|
|
|
|
|
|
|
/* d_subtype values: */
|
|
|
|
#define BSD_DSTYPE_INDOSPART 0x8 /* is inside dos partition */
|
|
|
|
#define BSD_DSTYPE_DOSPART(s) ((s) & 3) /* dos partition number */
|
|
|
|
#define BSD_DSTYPE_GEOMETRY 0x10 /* drive params in label */
|
|
|
|
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char *const xbsd_dktypenames[] = {
|
2006-10-13 01:00:44 +05:30
|
|
|
"unknown",
|
|
|
|
"SMD",
|
|
|
|
"MSCP",
|
|
|
|
"old DEC",
|
|
|
|
"SCSI",
|
|
|
|
"ESDI",
|
|
|
|
"ST506",
|
|
|
|
"HP-IB",
|
|
|
|
"HP-FL",
|
|
|
|
"type 9",
|
|
|
|
"floppy",
|
|
|
|
0
|
|
|
|
};
|
2007-06-25 16:25:35 +05:30
|
|
|
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Filesystem type and version.
|
|
|
|
* Used to interpret other filesystem-specific
|
|
|
|
* per-partition information.
|
|
|
|
*/
|
|
|
|
#define BSD_FS_UNUSED 0 /* unused */
|
|
|
|
#define BSD_FS_SWAP 1 /* swap */
|
|
|
|
#define BSD_FS_V6 2 /* Sixth Edition */
|
|
|
|
#define BSD_FS_V7 3 /* Seventh Edition */
|
|
|
|
#define BSD_FS_SYSV 4 /* System V */
|
|
|
|
#define BSD_FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
|
|
|
|
#define BSD_FS_V8 6 /* Eighth Edition, 4K blocks */
|
|
|
|
#define BSD_FS_BSDFFS 7 /* 4.2BSD fast file system */
|
|
|
|
#define BSD_FS_BSDLFS 9 /* 4.4BSD log-structured file system */
|
|
|
|
#define BSD_FS_OTHER 10 /* in use, but unknown/unsupported */
|
|
|
|
#define BSD_FS_HPFS 11 /* OS/2 high-performance file system */
|
|
|
|
#define BSD_FS_ISO9660 12 /* ISO-9660 filesystem (cdrom) */
|
|
|
|
#define BSD_FS_ISOFS BSD_FS_ISO9660
|
|
|
|
#define BSD_FS_BOOT 13 /* partition contains bootstrap */
|
|
|
|
#define BSD_FS_ADOS 14 /* AmigaDOS fast file system */
|
|
|
|
#define BSD_FS_HFS 15 /* Macintosh HFS */
|
|
|
|
#define BSD_FS_ADVFS 16 /* Digital Unix AdvFS */
|
|
|
|
|
|
|
|
/* this is annoying, but it's also the way it is :-( */
|
|
|
|
#ifdef __alpha__
|
|
|
|
#define BSD_FS_EXT2 8 /* ext2 file system */
|
|
|
|
#else
|
|
|
|
#define BSD_FS_MSDOS 8 /* MS-DOS file system */
|
|
|
|
#endif
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
static const char *const xbsd_fstypes[] = {
|
|
|
|
"\x00" "unused", /* BSD_FS_UNUSED */
|
|
|
|
"\x01" "swap", /* BSD_FS_SWAP */
|
|
|
|
"\x02" "Version 6", /* BSD_FS_V6 */
|
|
|
|
"\x03" "Version 7", /* BSD_FS_V7 */
|
|
|
|
"\x04" "System V", /* BSD_FS_SYSV */
|
|
|
|
"\x05" "4.1BSD", /* BSD_FS_V71K */
|
|
|
|
"\x06" "Eighth Edition", /* BSD_FS_V8 */
|
|
|
|
"\x07" "4.2BSD", /* BSD_FS_BSDFFS */
|
2006-10-13 01:00:44 +05:30
|
|
|
#ifdef __alpha__
|
2007-03-19 20:13:38 +05:30
|
|
|
"\x08" "ext2", /* BSD_FS_EXT2 */
|
2006-10-13 01:00:44 +05:30
|
|
|
#else
|
2007-03-19 20:13:38 +05:30
|
|
|
"\x08" "MS-DOS", /* BSD_FS_MSDOS */
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
2007-03-19 20:13:38 +05:30
|
|
|
"\x09" "4.4LFS", /* BSD_FS_BSDLFS */
|
|
|
|
"\x0a" "unknown", /* BSD_FS_OTHER */
|
|
|
|
"\x0b" "HPFS", /* BSD_FS_HPFS */
|
|
|
|
"\x0c" "ISO-9660", /* BSD_FS_ISO9660 */
|
|
|
|
"\x0d" "boot", /* BSD_FS_BOOT */
|
|
|
|
"\x0e" "ADOS", /* BSD_FS_ADOS */
|
|
|
|
"\x0f" "HFS", /* BSD_FS_HFS */
|
|
|
|
"\x10" "AdvFS", /* BSD_FS_ADVFS */
|
|
|
|
NULL
|
2006-10-13 01:00:44 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flags shared by various drives:
|
|
|
|
*/
|
|
|
|
#define BSD_D_REMOVABLE 0x01 /* removable media */
|
|
|
|
#define BSD_D_ECC 0x02 /* supports ECC */
|
|
|
|
#define BSD_D_BADSECT 0x04 /* supports bad sector forw. */
|
|
|
|
#define BSD_D_RAMDISK 0x08 /* disk emulator */
|
|
|
|
#define BSD_D_CHAIN 0x10 /* can do back-back transfers */
|
|
|
|
#define BSD_D_DOSPART 0x20 /* within MSDOS partition */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Changes:
|
|
|
|
19990319 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> - i18n/nls
|
|
|
|
|
|
|
|
20000101 - David Huggins-Daines <dhuggins@linuxcare.com> - Better
|
|
|
|
support for OSF/1 disklabels on Alpha.
|
|
|
|
Also fixed unaligned accesses in alpha_bootblock_checksum()
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define FREEBSD_PARTITION 0xa5
|
|
|
|
#define NETBSD_PARTITION 0xa9
|
|
|
|
|
|
|
|
static void xbsd_delete_part(void);
|
|
|
|
static void xbsd_new_part(void);
|
|
|
|
static void xbsd_write_disklabel(void);
|
|
|
|
static int xbsd_create_disklabel(void);
|
|
|
|
static void xbsd_edit_disklabel(void);
|
|
|
|
static void xbsd_write_bootstrap(void);
|
|
|
|
static void xbsd_change_fstype(void);
|
|
|
|
static int xbsd_get_part_index(int max);
|
|
|
|
static int xbsd_check_new_partition(int *i);
|
|
|
|
static void xbsd_list_types(void);
|
2006-12-20 02:02:02 +05:30
|
|
|
static uint16_t xbsd_dkcksum(struct xbsd_disklabel *lp);
|
2007-03-19 20:13:38 +05:30
|
|
|
static int xbsd_initlabel(struct partition *p);
|
|
|
|
static int xbsd_readlabel(struct partition *p);
|
|
|
|
static int xbsd_writelabel(struct partition *p);
|
2006-10-13 01:00:44 +05:30
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
static void alpha_bootblock_checksum(char *boot);
|
|
|
|
#endif
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
static int xbsd_translate_fstype(int linux_type);
|
|
|
|
static void xbsd_link_part(void);
|
|
|
|
static struct partition *xbsd_part;
|
|
|
|
static int xbsd_part_index;
|
|
|
|
#endif
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
|
|
|
|
/* Group big globals data and allocate it in one go */
|
|
|
|
struct bsd_globals {
|
2006-10-13 01:00:44 +05:30
|
|
|
/* We access this through a uint64_t * when checksumming */
|
2007-01-03 08:28:54 +05:30
|
|
|
/* hopefully xmalloc gives us required alignment */
|
2007-03-19 20:13:38 +05:30
|
|
|
char disklabelbuffer[BSD_BBSIZE];
|
|
|
|
struct xbsd_disklabel xbsd_dlabel;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct bsd_globals *bsd_globals_ptr;
|
|
|
|
|
|
|
|
#define disklabelbuffer (bsd_globals_ptr->disklabelbuffer)
|
2007-03-20 17:00:28 +05:30
|
|
|
#define xbsd_dlabel (bsd_globals_ptr->xbsd_dlabel)
|
2006-10-13 01:00:44 +05:30
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
|
|
|
|
/* Code */
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
#define bsd_cround(n) \
|
|
|
|
(display_in_cyl_units ? ((n)/xbsd_dlabel.d_secpercyl) + 1 : (n))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test whether the whole disk has BSD disk label magic.
|
|
|
|
*
|
|
|
|
* Note: often reformatting with DOS-type label leaves the BSD magic,
|
|
|
|
* so this does not mean that there is a BSD disk label.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
check_osf_label(void)
|
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
if (xbsd_readlabel(NULL) == 0)
|
2006-10-13 01:00:44 +05:30
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-01-03 08:28:54 +05:30
|
|
|
bsd_trydev(const char * dev)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
if (xbsd_readlabel(NULL) == 0)
|
2006-10-13 01:00:44 +05:30
|
|
|
return -1;
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("\nBSD label for device: %s\n", dev);
|
2007-01-02 22:15:05 +05:30
|
|
|
xbsd_print_disklabel(0);
|
2006-10-13 01:00:44 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-01-03 08:28:54 +05:30
|
|
|
bsd_menu(void)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
puts("Command Action");
|
|
|
|
puts("d\tdelete a BSD partition");
|
|
|
|
puts("e\tedit drive data");
|
|
|
|
puts("i\tinstall bootstrap");
|
|
|
|
puts("l\tlist known filesystem types");
|
|
|
|
puts("n\tadd a new BSD partition");
|
|
|
|
puts("p\tprint BSD partition table");
|
|
|
|
puts("q\tquit without saving changes");
|
|
|
|
puts("r\treturn to main menu");
|
|
|
|
puts("s\tshow complete disklabel");
|
|
|
|
puts("t\tchange a partition's filesystem id");
|
|
|
|
puts("u\tchange units (cylinders/sectors)");
|
|
|
|
puts("w\twrite disklabel to disk");
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2007-03-19 20:13:38 +05:30
|
|
|
puts("x\tlink BSD partition to non-BSD partition");
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
static int
|
|
|
|
hidden(int type)
|
|
|
|
{
|
|
|
|
return type ^ 0x10;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_bsd_partition_type(int type)
|
|
|
|
{
|
|
|
|
return (type == FREEBSD_PARTITION ||
|
|
|
|
type == hidden(FREEBSD_PARTITION) ||
|
|
|
|
type == NETBSD_PARTITION ||
|
|
|
|
type == hidden(NETBSD_PARTITION));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
2006-10-14 21:46:03 +05:30
|
|
|
bsd_select(void)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
int t, ss;
|
|
|
|
struct partition *p;
|
|
|
|
|
|
|
|
for (t = 0; t < 4; t++) {
|
|
|
|
p = get_part_table(t);
|
|
|
|
if (p && is_bsd_partition_type(p->sys_ind)) {
|
|
|
|
xbsd_part = p;
|
|
|
|
xbsd_part_index = t;
|
|
|
|
ss = get_start_sect(xbsd_part);
|
|
|
|
if (ss == 0) {
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Partition %s has invalid starting sector 0\n",
|
2006-10-13 01:00:44 +05:30
|
|
|
partname(disk_device, t+1, 0));
|
|
|
|
return;
|
|
|
|
}
|
2009-09-16 06:33:13 +05:30
|
|
|
printf("Reading disklabel of %s at sector %u\n",
|
2006-10-13 01:00:44 +05:30
|
|
|
partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR);
|
2016-06-19 21:45:33 +05:30
|
|
|
if (xbsd_readlabel(xbsd_part) == 0) {
|
2006-10-13 01:00:44 +05:30
|
|
|
if (xbsd_create_disklabel() == 0)
|
|
|
|
return;
|
|
|
|
break;
|
2016-06-19 21:45:33 +05:30
|
|
|
}
|
2006-10-13 01:00:44 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t == 4) {
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("There is no *BSD partition on %s\n", disk_device);
|
2006-10-13 01:00:44 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#elif defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
if (xbsd_readlabel(NULL) == 0)
|
2006-10-13 01:00:44 +05:30
|
|
|
if (xbsd_create_disklabel() == 0)
|
2007-01-02 22:15:05 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (1) {
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2007-03-19 20:13:38 +05:30
|
|
|
switch (tolower(read_nonempty("BSD disklabel command (m for help): "))) {
|
2006-10-13 01:00:44 +05:30
|
|
|
case 'd':
|
|
|
|
xbsd_delete_part();
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
xbsd_edit_disklabel();
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
xbsd_write_bootstrap();
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
xbsd_list_types();
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
xbsd_new_part();
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
xbsd_print_disklabel(0);
|
|
|
|
break;
|
|
|
|
case 'q':
|
2008-04-17 05:42:10 +05:30
|
|
|
if (ENABLE_FEATURE_CLEAN_UP)
|
2008-04-17 07:22:28 +05:30
|
|
|
close_dev_fd();
|
2006-10-13 01:00:44 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 'r':
|
|
|
|
return;
|
|
|
|
case 's':
|
|
|
|
xbsd_print_disklabel(1);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
xbsd_change_fstype();
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
change_units();
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
xbsd_write_disklabel();
|
|
|
|
break;
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
case 'x':
|
|
|
|
xbsd_link_part();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2007-01-03 08:28:54 +05:30
|
|
|
bsd_menu();
|
2006-10-13 01:00:44 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_delete_part(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = xbsd_get_part_index(xbsd_dlabel.d_npartitions);
|
|
|
|
xbsd_dlabel.d_partitions[i].p_size = 0;
|
|
|
|
xbsd_dlabel.d_partitions[i].p_offset = 0;
|
|
|
|
xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
|
|
|
|
if (xbsd_dlabel.d_npartitions == i + 1)
|
|
|
|
while (xbsd_dlabel.d_partitions[xbsd_dlabel.d_npartitions-1].p_size == 0)
|
|
|
|
xbsd_dlabel.d_npartitions--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_new_part(void)
|
|
|
|
{
|
|
|
|
off_t begin, end;
|
|
|
|
char mesg[256];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!xbsd_check_new_partition(&i))
|
|
|
|
return;
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__)
|
2006-10-13 01:00:44 +05:30
|
|
|
begin = get_start_sect(xbsd_part);
|
|
|
|
end = begin + get_nr_sects(xbsd_part) - 1;
|
|
|
|
#else
|
|
|
|
begin = 0;
|
|
|
|
end = xbsd_dlabel.d_secperunit - 1;
|
|
|
|
#endif
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
snprintf(mesg, sizeof(mesg), "First %s", str_units(SINGULAR));
|
2006-10-13 01:00:44 +05:30
|
|
|
begin = read_int(bsd_cround(begin), bsd_cround(begin), bsd_cround(end),
|
|
|
|
0, mesg);
|
|
|
|
|
|
|
|
if (display_in_cyl_units)
|
|
|
|
begin = (begin - 1) * xbsd_dlabel.d_secpercyl;
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
snprintf(mesg, sizeof(mesg), "Last %s or +size or +sizeM or +sizeK",
|
2006-10-13 01:00:44 +05:30
|
|
|
str_units(SINGULAR));
|
2007-01-02 22:15:05 +05:30
|
|
|
end = read_int(bsd_cround(begin), bsd_cround(end), bsd_cround(end),
|
|
|
|
bsd_cround(begin), mesg);
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
if (display_in_cyl_units)
|
|
|
|
end = end * xbsd_dlabel.d_secpercyl - 1;
|
|
|
|
|
|
|
|
xbsd_dlabel.d_partitions[i].p_size = end - begin + 1;
|
|
|
|
xbsd_dlabel.d_partitions[i].p_offset = begin;
|
|
|
|
xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_print_disklabel(int show_all)
|
|
|
|
{
|
|
|
|
struct xbsd_disklabel *lp = &xbsd_dlabel;
|
|
|
|
struct xbsd_partition *pp;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (show_all) {
|
2008-06-07 20:40:29 +05:30
|
|
|
static const int d_masks[] = { BSD_D_REMOVABLE, BSD_D_ECC, BSD_D_BADSECT };
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
printf("# %s:\n", disk_device);
|
|
|
|
#else
|
|
|
|
printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));
|
|
|
|
#endif
|
2007-06-25 16:25:35 +05:30
|
|
|
if ((unsigned) lp->d_type < ARRAY_SIZE(xbsd_dktypenames)-1)
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("type: %s\n", xbsd_dktypenames[lp->d_type]);
|
2006-10-13 01:00:44 +05:30
|
|
|
else
|
2009-09-16 06:33:13 +05:30
|
|
|
printf("type: %u\n", lp->d_type);
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
|
|
|
|
printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
|
2008-06-07 20:40:29 +05:30
|
|
|
printf("flags: ");
|
2008-06-16 09:39:25 +05:30
|
|
|
print_flags_separated(d_masks, "removable\0""ecc\0""badsect\0", lp->d_flags, " ");
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2006-10-13 01:00:44 +05:30
|
|
|
/* On various machines the fields of *lp are short/int/long */
|
|
|
|
/* In order to avoid problems, we cast them all to long. */
|
2009-09-16 06:33:13 +05:30
|
|
|
printf("bytes/sector: %lu\n", (long) lp->d_secsize);
|
|
|
|
printf("sectors/track: %lu\n", (long) lp->d_nsectors);
|
|
|
|
printf("tracks/cylinder: %lu\n", (long) lp->d_ntracks);
|
|
|
|
printf("sectors/cylinder: %lu\n", (long) lp->d_secpercyl);
|
|
|
|
printf("cylinders: %lu\n", (long) lp->d_ncylinders);
|
|
|
|
printf("rpm: %u\n", lp->d_rpm);
|
|
|
|
printf("interleave: %u\n", lp->d_interleave);
|
|
|
|
printf("trackskew: %u\n", lp->d_trackskew);
|
|
|
|
printf("cylinderskew: %u\n", lp->d_cylskew);
|
|
|
|
printf("headswitch: %lu\t\t# milliseconds\n",
|
2006-10-13 01:00:44 +05:30
|
|
|
(long) lp->d_headswitch);
|
2009-09-16 06:33:13 +05:30
|
|
|
printf("track-to-track seek: %lu\t# milliseconds\n",
|
2006-10-13 01:00:44 +05:30
|
|
|
(long) lp->d_trkseek);
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("drivedata: ");
|
2006-10-13 01:00:44 +05:30
|
|
|
for (i = NDDATA - 1; i >= 0; i--)
|
|
|
|
if (lp->d_drivedata[i])
|
|
|
|
break;
|
|
|
|
if (i < 0)
|
|
|
|
i = 0;
|
|
|
|
for (j = 0; j <= i; j++)
|
2009-09-16 06:33:13 +05:30
|
|
|
printf("%lu ", (long) lp->d_drivedata[j]);
|
2006-10-13 01:00:44 +05:30
|
|
|
}
|
2009-09-16 06:33:13 +05:30
|
|
|
printf("\n%u partitions:\n", lp->d_npartitions);
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("# start end size fstype [fsize bsize cpg]\n");
|
2006-10-13 01:00:44 +05:30
|
|
|
pp = lp->d_partitions;
|
|
|
|
for (i = 0; i < lp->d_npartitions; i++, pp++) {
|
|
|
|
if (pp->p_size) {
|
|
|
|
if (display_in_cyl_units && lp->d_secpercyl) {
|
2009-09-16 06:33:13 +05:30
|
|
|
printf(" %c: %8lu%c %8lu%c %8lu%c ",
|
2006-10-13 01:00:44 +05:30
|
|
|
'a' + i,
|
2009-09-16 06:33:13 +05:30
|
|
|
(unsigned long) pp->p_offset / lp->d_secpercyl + 1,
|
2006-10-13 01:00:44 +05:30
|
|
|
(pp->p_offset % lp->d_secpercyl) ? '*' : ' ',
|
2009-09-16 06:33:13 +05:30
|
|
|
(unsigned long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl,
|
2006-10-13 01:00:44 +05:30
|
|
|
((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ',
|
|
|
|
(long) pp->p_size / lp->d_secpercyl,
|
|
|
|
(pp->p_size % lp->d_secpercyl) ? '*' : ' '
|
|
|
|
);
|
|
|
|
} else {
|
2009-09-16 06:33:13 +05:30
|
|
|
printf(" %c: %8lu %8lu %8lu ",
|
2006-10-13 01:00:44 +05:30
|
|
|
'a' + i,
|
|
|
|
(long) pp->p_offset,
|
|
|
|
(long) pp->p_offset + pp->p_size - 1,
|
|
|
|
(long) pp->p_size
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-06-25 16:25:35 +05:30
|
|
|
if ((unsigned) pp->p_fstype < ARRAY_SIZE(xbsd_fstypes)-1)
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("%8.8s", xbsd_fstypes[pp->p_fstype]);
|
2006-10-13 01:00:44 +05:30
|
|
|
else
|
|
|
|
printf("%8x", pp->p_fstype);
|
|
|
|
|
|
|
|
switch (pp->p_fstype) {
|
|
|
|
case BSD_FS_UNUSED:
|
2009-09-16 06:33:13 +05:30
|
|
|
printf(" %5lu %5lu %5.5s ",
|
2006-10-13 01:00:44 +05:30
|
|
|
(long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, "");
|
|
|
|
break;
|
|
|
|
case BSD_FS_BSDFFS:
|
2009-09-16 06:33:13 +05:30
|
|
|
printf(" %5lu %5lu %5u ",
|
2006-10-13 01:00:44 +05:30
|
|
|
(long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, pp->p_cpg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%22.22s", "");
|
|
|
|
break;
|
|
|
|
}
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2006-10-13 01:00:44 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_write_disklabel(void)
|
|
|
|
{
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__)
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Writing disklabel to %s\n", disk_device);
|
|
|
|
xbsd_writelabel(NULL);
|
2006-10-13 01:00:44 +05:30
|
|
|
#else
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Writing disklabel to %s\n",
|
2006-10-13 01:00:44 +05:30
|
|
|
partname(disk_device, xbsd_part_index + 1, 0));
|
2007-03-19 20:13:38 +05:30
|
|
|
xbsd_writelabel(xbsd_part);
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
|
|
|
reread_partition_table(0); /* no exit yet */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xbsd_create_disklabel(void)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__)
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("%s contains no disklabel\n", disk_device);
|
2006-10-13 01:00:44 +05:30
|
|
|
#else
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("%s contains no disklabel\n",
|
2006-10-13 01:00:44 +05:30
|
|
|
partname(disk_device, xbsd_part_index + 1, 0));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (1) {
|
2007-03-19 20:13:38 +05:30
|
|
|
c = read_nonempty("Do you want to create a disklabel? (y/n) ");
|
2009-11-07 06:01:14 +05:30
|
|
|
if ((c|0x20) == 'y') {
|
2006-10-13 01:00:44 +05:30
|
|
|
if (xbsd_initlabel(
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__) || defined(__powerpc__) || defined(__hppa__) || \
|
|
|
|
defined(__s390__) || defined(__s390x__)
|
2007-03-19 20:13:38 +05:30
|
|
|
NULL
|
2006-10-13 01:00:44 +05:30
|
|
|
#else
|
2007-03-19 20:13:38 +05:30
|
|
|
xbsd_part
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
2008-04-17 05:42:10 +05:30
|
|
|
) == 1) {
|
2007-01-02 22:15:05 +05:30
|
|
|
xbsd_print_disklabel(1);
|
2006-10-13 01:00:44 +05:30
|
|
|
return 1;
|
2008-04-17 05:42:10 +05:30
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-07 06:01:14 +05:30
|
|
|
if ((c|0x20) == 'n')
|
2006-10-13 01:00:44 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-01-30 04:21:44 +05:30
|
|
|
edit_int(int def, const char *mesg)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
2009-09-16 06:33:13 +05:30
|
|
|
mesg = xasprintf("%s (%u): ", mesg, def);
|
2006-10-13 01:00:44 +05:30
|
|
|
do {
|
2007-01-22 12:51:38 +05:30
|
|
|
if (!read_line(mesg))
|
|
|
|
goto ret;
|
2006-10-13 01:00:44 +05:30
|
|
|
} while (!isdigit(*line_ptr));
|
2007-01-22 12:51:38 +05:30
|
|
|
def = atoi(line_ptr);
|
|
|
|
ret:
|
2007-01-30 04:21:44 +05:30
|
|
|
free((char*)mesg);
|
2007-01-22 12:51:38 +05:30
|
|
|
return def;
|
2006-10-13 01:00:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_edit_disklabel(void)
|
|
|
|
{
|
|
|
|
struct xbsd_disklabel *d;
|
|
|
|
|
|
|
|
d = &xbsd_dlabel;
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__) || defined(__ia64__)
|
2007-03-19 20:13:38 +05:30
|
|
|
d->d_secsize = edit_int(d->d_secsize , "bytes/sector");
|
|
|
|
d->d_nsectors = edit_int(d->d_nsectors , "sectors/track");
|
|
|
|
d->d_ntracks = edit_int(d->d_ntracks , "tracks/cylinder");
|
|
|
|
d->d_ncylinders = edit_int(d->d_ncylinders , "cylinders");
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
|
|
|
|
2006-12-20 02:02:02 +05:30
|
|
|
/* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */
|
2006-10-13 01:00:44 +05:30
|
|
|
while (1) {
|
2006-12-20 02:02:02 +05:30
|
|
|
d->d_secpercyl = edit_int(d->d_nsectors * d->d_ntracks,
|
2007-03-19 20:13:38 +05:30
|
|
|
"sectors/cylinder");
|
2006-10-13 01:00:44 +05:30
|
|
|
if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks)
|
|
|
|
break;
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Must be <= sectors/track * tracks/cylinder (default)\n");
|
2006-10-13 01:00:44 +05:30
|
|
|
}
|
2007-03-19 20:13:38 +05:30
|
|
|
d->d_rpm = edit_int(d->d_rpm , "rpm");
|
|
|
|
d->d_interleave = edit_int(d->d_interleave, "interleave");
|
|
|
|
d->d_trackskew = edit_int(d->d_trackskew , "trackskew");
|
|
|
|
d->d_cylskew = edit_int(d->d_cylskew , "cylinderskew");
|
|
|
|
d->d_headswitch = edit_int(d->d_headswitch, "headswitch");
|
|
|
|
d->d_trkseek = edit_int(d->d_trkseek , "track-to-track seek");
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-12-20 02:02:02 +05:30
|
|
|
xbsd_get_bootstrap(char *path, void *ptr, int size)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
|
|
|
int fdb;
|
|
|
|
|
2008-06-29 10:40:47 +05:30
|
|
|
fdb = open_or_warn(path, O_RDONLY);
|
2006-12-20 02:02:02 +05:30
|
|
|
if (fdb < 0) {
|
2006-10-13 01:00:44 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2008-06-29 10:40:47 +05:30
|
|
|
if (full_read(fdb, ptr, size) < 0) {
|
|
|
|
bb_simple_perror_msg(path);
|
2006-10-13 01:00:44 +05:30
|
|
|
close(fdb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
printf(" ... %s\n", path);
|
|
|
|
close(fdb);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_disks(void)
|
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Syncing disks\n");
|
2006-10-13 01:00:44 +05:30
|
|
|
sync();
|
2007-03-19 20:13:38 +05:30
|
|
|
/* sleep(4); What? */
|
2006-10-13 01:00:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_write_bootstrap(void)
|
|
|
|
{
|
2017-10-31 20:29:19 +05:30
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
# define MAXPATHLEN 1024
|
|
|
|
#endif
|
2006-10-13 01:00:44 +05:30
|
|
|
char path[MAXPATHLEN];
|
2007-01-30 04:21:44 +05:30
|
|
|
const char *bootdir = BSD_LINUX_BOOTDIR;
|
|
|
|
const char *dkbasename;
|
2006-10-13 01:00:44 +05:30
|
|
|
struct xbsd_disklabel dl;
|
|
|
|
char *d, *p, *e;
|
|
|
|
int sector;
|
|
|
|
|
|
|
|
if (xbsd_dlabel.d_type == BSD_DTYPE_SCSI)
|
|
|
|
dkbasename = "sd";
|
|
|
|
else
|
|
|
|
dkbasename = "wd";
|
|
|
|
|
2007-01-22 12:51:38 +05:30
|
|
|
snprintf(path, sizeof(path), "Bootstrap: %sboot -> boot%s (%s): ",
|
2006-10-13 01:00:44 +05:30
|
|
|
dkbasename, dkbasename, dkbasename);
|
2007-01-22 12:51:38 +05:30
|
|
|
if (read_line(path)) {
|
2006-10-13 01:00:44 +05:30
|
|
|
dkbasename = line_ptr;
|
|
|
|
}
|
|
|
|
snprintf(path, sizeof(path), "%s/%sboot", bootdir, dkbasename);
|
|
|
|
if (!xbsd_get_bootstrap(path, disklabelbuffer, (int) xbsd_dlabel.d_secsize))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We need a backup of the disklabel (xbsd_dlabel might have changed). */
|
|
|
|
d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE];
|
|
|
|
memmove(&dl, d, sizeof(struct xbsd_disklabel));
|
|
|
|
|
|
|
|
/* The disklabel will be overwritten by 0's from bootxx anyway */
|
|
|
|
memset(d, 0, sizeof(struct xbsd_disklabel));
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "%s/boot%s", bootdir, dkbasename);
|
2006-12-01 02:41:01 +05:30
|
|
|
if (!xbsd_get_bootstrap(path, &disklabelbuffer[xbsd_dlabel.d_secsize],
|
2006-12-20 02:02:02 +05:30
|
|
|
(int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize))
|
2006-10-13 01:00:44 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
e = d + sizeof(struct xbsd_disklabel);
|
|
|
|
for (p = d; p < e; p++)
|
|
|
|
if (*p) {
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Bootstrap overlaps with disk label!\n");
|
2006-10-13 01:00:44 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
memmove(d, &dl, sizeof(struct xbsd_disklabel));
|
|
|
|
|
2006-12-20 02:02:02 +05:30
|
|
|
#if defined(__powerpc__) || defined(__hppa__)
|
2006-10-13 01:00:44 +05:30
|
|
|
sector = 0;
|
2006-12-20 02:02:02 +05:30
|
|
|
#elif defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
sector = 0;
|
|
|
|
alpha_bootblock_checksum(disklabelbuffer);
|
|
|
|
#else
|
|
|
|
sector = get_start_sect(xbsd_part);
|
|
|
|
#endif
|
|
|
|
|
2008-06-29 10:40:47 +05:30
|
|
|
seek_sector(sector);
|
|
|
|
xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
|
2006-10-13 01:00:44 +05:30
|
|
|
|
2006-12-20 02:02:02 +05:30
|
|
|
#if defined(__alpha__)
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Bootstrap installed on %s\n", disk_device);
|
2006-10-13 01:00:44 +05:30
|
|
|
#else
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("Bootstrap installed on %s\n",
|
2006-12-20 02:02:02 +05:30
|
|
|
partname(disk_device, xbsd_part_index+1, 0));
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
sync_disks();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_change_fstype(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = xbsd_get_part_index(xbsd_dlabel.d_npartitions);
|
|
|
|
xbsd_dlabel.d_partitions[i].p_fstype = read_hex(xbsd_fstypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xbsd_get_part_index(int max)
|
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
char prompt[sizeof("Partition (a-%c): ") + 16];
|
2006-10-13 01:00:44 +05:30
|
|
|
char l;
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
snprintf(prompt, sizeof(prompt), "Partition (a-%c): ", 'a' + max - 1);
|
2006-10-13 01:00:44 +05:30
|
|
|
do
|
|
|
|
l = tolower(read_nonempty(prompt));
|
|
|
|
while (l < 'a' || l > 'a' + max - 1);
|
|
|
|
return l - 'a';
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xbsd_check_new_partition(int *i)
|
|
|
|
{
|
|
|
|
/* room for more? various BSD flavours have different maxima */
|
|
|
|
if (xbsd_dlabel.d_npartitions == BSD_MAXPARTITIONS) {
|
|
|
|
int t;
|
|
|
|
|
|
|
|
for (t = 0; t < BSD_MAXPARTITIONS; t++)
|
|
|
|
if (xbsd_dlabel.d_partitions[t].p_size == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (t == BSD_MAXPARTITIONS) {
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("The maximum number of partitions has been created\n");
|
2006-10-13 01:00:44 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-20 02:02:02 +05:30
|
|
|
*i = xbsd_get_part_index(BSD_MAXPARTITIONS);
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
if (*i >= xbsd_dlabel.d_npartitions)
|
|
|
|
xbsd_dlabel.d_npartitions = (*i) + 1;
|
|
|
|
|
|
|
|
if (xbsd_dlabel.d_partitions[*i].p_size != 0) {
|
2007-03-19 20:13:38 +05:30
|
|
|
printf("This partition already exists\n");
|
2006-10-13 01:00:44 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_list_types(void)
|
|
|
|
{
|
|
|
|
list_types(xbsd_fstypes);
|
|
|
|
}
|
|
|
|
|
2006-12-20 02:02:02 +05:30
|
|
|
static uint16_t
|
2006-10-13 01:00:44 +05:30
|
|
|
xbsd_dkcksum(struct xbsd_disklabel *lp)
|
|
|
|
{
|
2006-12-20 02:02:02 +05:30
|
|
|
uint16_t *start, *end;
|
|
|
|
uint16_t sum = 0;
|
2006-10-13 01:00:44 +05:30
|
|
|
|
2006-12-20 02:02:02 +05:30
|
|
|
start = (uint16_t *) lp;
|
|
|
|
end = (uint16_t *) &lp->d_partitions[lp->d_npartitions];
|
2006-10-13 01:00:44 +05:30
|
|
|
while (start < end)
|
|
|
|
sum ^= *start++;
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-03-19 20:13:38 +05:30
|
|
|
xbsd_initlabel(struct partition *p)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
struct xbsd_disklabel *d = &xbsd_dlabel;
|
2006-10-13 01:00:44 +05:30
|
|
|
struct xbsd_partition *pp;
|
|
|
|
|
|
|
|
get_geometry();
|
|
|
|
memset(d, 0, sizeof(struct xbsd_disklabel));
|
|
|
|
|
|
|
|
d->d_magic = BSD_DISKMAGIC;
|
|
|
|
|
2015-03-12 22:18:34 +05:30
|
|
|
if (is_prefixed_with(disk_device, "/dev/sd"))
|
2006-10-13 01:00:44 +05:30
|
|
|
d->d_type = BSD_DTYPE_SCSI;
|
|
|
|
else
|
|
|
|
d->d_type = BSD_DTYPE_ST506;
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
d->d_flags = BSD_D_DOSPART;
|
|
|
|
#else
|
|
|
|
d->d_flags = 0;
|
|
|
|
#endif
|
|
|
|
d->d_secsize = SECTOR_SIZE; /* bytes/sector */
|
2007-12-16 22:52:33 +05:30
|
|
|
d->d_nsectors = g_sectors; /* sectors/track */
|
|
|
|
d->d_ntracks = g_heads; /* tracks/cylinder (heads) */
|
|
|
|
d->d_ncylinders = g_cylinders;
|
|
|
|
d->d_secpercyl = g_sectors * g_heads;/* sectors/cylinder */
|
2006-10-13 01:00:44 +05:30
|
|
|
if (d->d_secpercyl == 0)
|
|
|
|
d->d_secpercyl = 1; /* avoid segfaults */
|
|
|
|
d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
|
|
|
|
|
|
|
|
d->d_rpm = 3600;
|
|
|
|
d->d_interleave = 1;
|
|
|
|
d->d_trackskew = 0;
|
|
|
|
d->d_cylskew = 0;
|
|
|
|
d->d_headswitch = 0;
|
|
|
|
d->d_trkseek = 0;
|
|
|
|
|
|
|
|
d->d_magic2 = BSD_DISKMAGIC;
|
|
|
|
d->d_bbsize = BSD_BBSIZE;
|
|
|
|
d->d_sbsize = BSD_SBSIZE;
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
d->d_npartitions = 4;
|
2007-01-02 22:15:05 +05:30
|
|
|
pp = &d->d_partitions[2]; /* Partition C should be NetBSD partition */
|
|
|
|
|
2006-10-13 01:00:44 +05:30
|
|
|
pp->p_offset = get_start_sect(p);
|
|
|
|
pp->p_size = get_nr_sects(p);
|
|
|
|
pp->p_fstype = BSD_FS_UNUSED;
|
2007-01-02 22:15:05 +05:30
|
|
|
pp = &d->d_partitions[3]; /* Partition D should be whole disk */
|
|
|
|
|
2006-10-13 01:00:44 +05:30
|
|
|
pp->p_offset = 0;
|
|
|
|
pp->p_size = d->d_secperunit;
|
|
|
|
pp->p_fstype = BSD_FS_UNUSED;
|
2007-03-19 20:13:38 +05:30
|
|
|
#else
|
2006-10-13 01:00:44 +05:30
|
|
|
d->d_npartitions = 3;
|
2013-01-14 20:27:44 +05:30
|
|
|
pp = &d->d_partitions[2]; /* Partition C should be the whole disk */
|
2006-10-13 01:00:44 +05:30
|
|
|
pp->p_offset = 0;
|
|
|
|
pp->p_size = d->d_secperunit;
|
|
|
|
pp->p_fstype = BSD_FS_UNUSED;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a xbsd_disklabel from sector 0 or from the starting sector of p.
|
|
|
|
* If it has the right magic, return 1.
|
|
|
|
*/
|
|
|
|
static int
|
2007-03-19 20:13:38 +05:30
|
|
|
xbsd_readlabel(struct partition *p)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
struct xbsd_disklabel *d;
|
2006-10-13 01:00:44 +05:30
|
|
|
int t, sector;
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
if (!bsd_globals_ptr)
|
|
|
|
bsd_globals_ptr = xzalloc(sizeof(*bsd_globals_ptr));
|
|
|
|
|
|
|
|
d = &xbsd_dlabel;
|
2007-01-03 08:28:54 +05:30
|
|
|
|
2006-10-13 01:00:44 +05:30
|
|
|
/* p is used only to get the starting sector */
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
sector = (p ? get_start_sect(p) : 0);
|
2007-03-19 20:13:38 +05:30
|
|
|
#else
|
2006-10-13 01:00:44 +05:30
|
|
|
sector = 0;
|
|
|
|
#endif
|
|
|
|
|
2008-06-29 10:40:47 +05:30
|
|
|
seek_sector(sector);
|
|
|
|
if (BSD_BBSIZE != full_read(dev_fd, disklabelbuffer, BSD_BBSIZE))
|
2006-10-13 01:00:44 +05:30
|
|
|
fdisk_fatal(unable_to_read);
|
|
|
|
|
|
|
|
memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
|
2013-01-14 20:27:44 +05:30
|
|
|
sizeof(struct xbsd_disklabel));
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (t = d->d_npartitions; t < BSD_MAXPARTITIONS; t++) {
|
|
|
|
d->d_partitions[t].p_size = 0;
|
|
|
|
d->d_partitions[t].p_offset = 0;
|
|
|
|
d->d_partitions[t].p_fstype = BSD_FS_UNUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->d_npartitions > BSD_MAXPARTITIONS)
|
2009-09-16 06:33:13 +05:30
|
|
|
printf("Warning: too many partitions (%u, maximum is %u)\n",
|
2006-10-13 01:00:44 +05:30
|
|
|
d->d_npartitions, BSD_MAXPARTITIONS);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-03-19 20:13:38 +05:30
|
|
|
xbsd_writelabel(struct partition *p)
|
2006-10-13 01:00:44 +05:30
|
|
|
{
|
2007-03-19 20:13:38 +05:30
|
|
|
struct xbsd_disklabel *d = &xbsd_dlabel;
|
2006-10-13 01:00:44 +05:30
|
|
|
unsigned int sector;
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__)
|
2006-10-13 01:00:44 +05:30
|
|
|
sector = get_start_sect(p) + BSD_LABELSECTOR;
|
|
|
|
#else
|
2009-11-07 06:01:14 +05:30
|
|
|
(void)p; /* silence warning */
|
2006-10-13 01:00:44 +05:30
|
|
|
sector = BSD_LABELSECTOR;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
d->d_checksum = 0;
|
2007-01-02 22:15:05 +05:30
|
|
|
d->d_checksum = xbsd_dkcksum(d);
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
/* This is necessary if we want to write the bootstrap later,
|
|
|
|
otherwise we'd write the old disklabel with the bootstrap.
|
|
|
|
*/
|
|
|
|
memmove(&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
|
|
|
|
d, sizeof(struct xbsd_disklabel));
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__) && BSD_LABELSECTOR == 0
|
2006-12-01 02:41:01 +05:30
|
|
|
alpha_bootblock_checksum(disklabelbuffer);
|
2008-06-29 10:40:47 +05:30
|
|
|
seek_sector(0);
|
|
|
|
xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
|
2006-10-13 01:00:44 +05:30
|
|
|
#else
|
2008-06-29 10:40:47 +05:30
|
|
|
seek_sector(sector);
|
|
|
|
lseek(dev_fd, BSD_LABELOFFSET, SEEK_CUR);
|
|
|
|
xwrite(dev_fd, d, sizeof(*d));
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif
|
|
|
|
sync_disks();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if !defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
static int
|
|
|
|
xbsd_translate_fstype(int linux_type)
|
|
|
|
{
|
|
|
|
switch (linux_type) {
|
|
|
|
case 0x01: /* DOS 12-bit FAT */
|
|
|
|
case 0x04: /* DOS 16-bit <32M */
|
|
|
|
case 0x06: /* DOS 16-bit >=32M */
|
|
|
|
case 0xe1: /* DOS access */
|
|
|
|
case 0xe3: /* DOS R/O */
|
|
|
|
case 0xf2: /* DOS secondary */
|
|
|
|
return BSD_FS_MSDOS;
|
|
|
|
case 0x07: /* OS/2 HPFS */
|
|
|
|
return BSD_FS_HPFS;
|
|
|
|
default:
|
|
|
|
return BSD_FS_OTHER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xbsd_link_part(void)
|
|
|
|
{
|
|
|
|
int k, i;
|
|
|
|
struct partition *p;
|
|
|
|
|
2007-12-16 22:52:33 +05:30
|
|
|
k = get_partition(1, g_partitions);
|
2006-10-13 01:00:44 +05:30
|
|
|
|
|
|
|
if (!xbsd_check_new_partition(&i))
|
|
|
|
return;
|
|
|
|
|
|
|
|
p = get_part_table(k);
|
|
|
|
|
|
|
|
xbsd_dlabel.d_partitions[i].p_size = get_nr_sects(p);
|
|
|
|
xbsd_dlabel.d_partitions[i].p_offset = get_start_sect(p);
|
|
|
|
xbsd_dlabel.d_partitions[i].p_fstype = xbsd_translate_fstype(p->sys_ind);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-01-02 22:15:05 +05:30
|
|
|
#if defined(__alpha__)
|
2006-10-13 01:00:44 +05:30
|
|
|
static void
|
|
|
|
alpha_bootblock_checksum(char *boot)
|
|
|
|
{
|
|
|
|
uint64_t *dp, sum;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dp = (uint64_t *)boot;
|
|
|
|
sum = 0;
|
|
|
|
for (i = 0; i < 63; i++)
|
|
|
|
sum += dp[i];
|
|
|
|
dp[63] = sum;
|
|
|
|
}
|
|
|
|
#endif /* __alpha__ */
|
|
|
|
|
2007-03-19 20:13:38 +05:30
|
|
|
/* Undefine 'global' tricks */
|
|
|
|
#undef disklabelbuffer
|
|
|
|
#undef xbsd_dlabel
|
|
|
|
|
2006-10-13 01:00:44 +05:30
|
|
|
#endif /* OSF_LABEL */
|