add new commands, partnew and parttype, add one more sanity check for reiserfs.

This commit is contained in:
okuji 2000-09-29 18:55:27 +00:00
parent 69e36bc547
commit 225b464978
7 changed files with 245 additions and 5 deletions

View file

@ -15,7 +15,9 @@ OKUJI Yoshinori contributed many bugfixes and new features, such as
working LBA support, /sbin/grub support for configuration files, the working LBA support, /sbin/grub support for configuration files, the
script /sbin/grub-install, the utility /bin/mbchk, the new engine for script /sbin/grub-install, the utility /bin/mbchk, the new engine for
builtin commands, disk swapping support, keyboard configuration support, builtin commands, disk swapping support, keyboard configuration support,
network support, online help support, and command-line history support. network support, online help support, command-line history support,
hidden menu support, the new Linux loader, serial terminal support,
single-line editing support, and several new commands.
Peter Astrand added support for a color menu. Peter Astrand added support for a color menu.
@ -30,3 +32,5 @@ Jochen Hoenicke rewrote stage2/fsys_fat.c and wrote
stage2/fsys_reiserfs.c. stage2/fsys_reiserfs.c.
Christoph Plattner added support for Net Boot Image Proposal. Christoph Plattner added support for Net Boot Image Proposal.
Stefan Ondrejicka added the commands "partnew" and "parttype".

View file

@ -1,3 +1,24 @@
2000-09-30 OKUJI Yoshinori <okuji@gnu.org>
* stage2/fsys_reiserfs.c (reiserfs_mount): Check if the length
of the partition is less than the size of a super block, before
attempting to read the super block.
* grub/asmstub.c (console_putchar)
[HAVE_LIBCURSES_H && REFRESH_IMMEDIATELY]: Call refresh, to ease
debugging.
2000-09-30 OKUJI Yoshinori <okuji@gnu.org>
Added two new commands, "partnew" and "parttype", based on the
patch by Stefan Ondrejicka <ondrej@idata.sk>:
* stage2/builtins.c (partnew_func): New function.
(builtin_partnew): New variable.
(parttype_func): New function.
(builtin_parttype): New variable.
(builtin_table): Added pointers to BUILTIN_PARTNEW and to
BUILTIN_PARTTYPE.
2000-09-29 OKUJI Yoshinori <okuji@gnu.org> 2000-09-29 OKUJI Yoshinori <okuji@gnu.org>
* stage2/builtins.c (find_func): New variable GOT_FILE is set to * stage2/builtins.c (find_func): New variable GOT_FILE is set to

2
NEWS
View file

@ -42,6 +42,8 @@ New in 0.5.96 - XXXX-XX-XX:
you specify the option `--prefix'. you specify the option `--prefix'.
* The utility `grub-install' recognizes a separate boot partition * The utility `grub-install' recognizes a separate boot partition
automatically. automatically.
* New commands, "partnew" and "parttype". You can modify partition
tables with these commands.
New in 0.5.95 - 2000-06-27: New in 0.5.95 - 2000-06-27:
* NetBSD ELF kernel support is added. You have to specify the new option * NetBSD ELF kernel support is added. You have to specify the new option

1
THANKS
View file

@ -44,6 +44,7 @@ Pavel Roskin <pavel_roskin@geocities.com>
Per Lundberg <plundis@byggdok.se> Per Lundberg <plundis@byggdok.se>
Peter Astrand <altic@lysator.liu.se> Peter Astrand <altic@lysator.liu.se>
Ramon van Handel <vhandel@chem.vu.nl> Ramon van Handel <vhandel@chem.vu.nl>
Stefan Ondrejicka <ondrej@idata.sk>
Stephen Early <steve@greenend.org.uk> Stephen Early <steve@greenend.org.uk>
Takehiro Suzuki <takehiro@coral.ocn.ne.jp> Takehiro Suzuki <takehiro@coral.ocn.ne.jp>
Thierry DELHAISE <thierry.delhaise@delhaise.com> Thierry DELHAISE <thierry.delhaise@delhaise.com>

View file

@ -514,7 +514,12 @@ console_putchar (int c)
move (y + 1, x); move (y + 1, x);
} }
else else
addch (c); {
addch (c);
#ifdef REFRESH_IMMEDIATELY
refresh ();
#endif
}
} }
else else
#endif #endif

View file

@ -2375,6 +2375,209 @@ static struct builtin builtin_modulenounzip =
" disabled." " disabled."
}; };
/* partnew PART TYPE START LEN */
static int
partnew_func (char *arg, int flags)
{
int new_type, new_start, new_len;
int start_cl, start_ch, start_dh;
int end_cl, end_ch, end_dh;
int entry;
char *mbr = (char *) SCRATCHADDR;
/* Convert a LBA address to a CHS address in the INT 13 format. */
auto void lba_to_chs (int lba, int *cl, int *ch, int *dh);
void lba_to_chs (int lba, int *cl, int *ch, int *dh)
{
int cylinder, head, sector;
sector = lba % buf_geom.sectors + 1;
head = (lba / buf_geom.sectors) % buf_geom.heads;
cylinder = lba / (buf_geom.sectors * buf_geom.heads);
if (cylinder >= buf_geom.cylinders)
cylinder = buf_geom.cylinders - 1;
*cl = sector | ((cylinder & 0x300) >> 2);
*ch = cylinder & 0xFF;
*dh = head;
}
/* Get the drive and the partition. */
if (! set_device (arg))
return 1;
/* The drive must be a hard disk. */
if (! (current_drive & 0x80))
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
/* The partition must a primary partition. */
if ((current_partition >> 16) > 3
|| (current_partition & 0xFFFF) != 0xFFFF)
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
entry = current_partition >> 16;
/* Get the new partition type. */
arg = skip_to (0, arg);
if (! safe_parse_maxint (&arg, &new_type))
return 1;
/* The partition type is unsigned char. */
if (new_type > 0xFF)
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
/* Get the new partition start. */
arg = skip_to (0, arg);
if (! safe_parse_maxint (&arg, &new_start))
return 1;
/* Get the new partition length. */
arg = skip_to (0, arg);
if (! safe_parse_maxint (&arg, &new_len))
return 1;
/* Read the MBR. */
if (! rawread (current_drive, 0, 0, SECTOR_SIZE, mbr))
return 1;
/* Check if the new partition will fit in the disk. */
if (new_start + new_len > buf_geom.total_sectors)
{
errnum = ERR_GEOM;
return 1;
}
/* Store the partition information in the MBR. */
lba_to_chs (new_start, &start_cl, &start_ch, &start_dh);
lba_to_chs (new_start + new_len - 1, &end_cl, &end_ch, &end_dh);
PC_SLICE_FLAG (mbr, entry) = 0;
PC_SLICE_HEAD (mbr, entry) = start_dh;
PC_SLICE_SEC (mbr, entry) = start_cl;
PC_SLICE_CYL (mbr, entry) = start_ch;
PC_SLICE_TYPE (mbr, entry) = new_type;
PC_SLICE_EHEAD (mbr, entry) = end_dh;
PC_SLICE_ESEC (mbr, entry) = end_cl;
PC_SLICE_ECYL (mbr, entry) = end_ch;
PC_SLICE_START (mbr, entry) = new_start;
PC_SLICE_LENGTH (mbr, entry) = new_len;
/* Make sure that the MBR has a valid signature. */
PC_MBR_SIG (mbr) = PC_MBR_SIGNATURE;
/* Write back the MBR to the disk. */
buf_track = -1;
if (biosdisk (BIOSDISK_WRITE, current_drive, &buf_geom, 0, 1, SCRATCHSEG))
{
errnum = ERR_WRITE;
return 1;
}
return 0;
}
static struct builtin builtin_partnew =
{
"partnew",
partnew_func,
BUILTIN_CMDLINE | BUILTIN_MENU,
"partnew PART TYPE START LEN",
"Create a primary partition at the starting address START with the"
" length LEN, with the type TYPE. START and LEN are in sector units."
};
/* parttype PART TYPE */
static int
parttype_func (char *arg, int flags)
{
int new_type;
unsigned long part = 0xFFFFFF;
unsigned long start, len, offset, ext_offset;
int entry, type;
char *mbr = (char *) SCRATCHADDR;
/* Get the drive and the partition. */
if (! set_device (arg))
return 1;
/* The drive must be a hard disk. */
if (! (current_drive & 0x80))
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
/* The partition must be a PC slice. */
if ((current_partition >> 16) == 0xFF
|| (current_partition & 0xFFFF) != 0xFFFF)
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
/* Get the new partition type. */
arg = skip_to (0, arg);
if (! safe_parse_maxint (&arg, &new_type))
return 1;
/* The partition type is unsigned char. */
if (new_type > 0xFF)
{
errnum = ERR_BAD_ARGUMENT;
return 1;
}
/* Look for the partition. */
while (next_partition (current_drive, 0xFFFFFF, &part, &type,
&start, &len, &offset, &entry,
&ext_offset, mbr))
{
if (part == current_partition)
{
/* Found. */
/* Set the type to NEW_TYPE. */
PC_SLICE_TYPE (mbr, entry) = new_type;
/* Write back the MBR to the disk. */
buf_track = -1;
if (biosdisk (BIOSDISK_WRITE, current_drive, &buf_geom,
offset, 1, SCRATCHSEG))
{
errnum = ERR_WRITE;
return 1;
}
/* Succeed. */
return 0;
}
}
/* The partition was not found. ERRNUM was set by next_partition. */
return 1;
}
static struct builtin builtin_parttype =
{
"parttype",
parttype_func,
BUILTIN_CMDLINE | BUILTIN_MENU,
"parttype PART TYPE",
"Change the type of the partition PART to TYPE."
};
/* password */ /* password */
static int static int
@ -3778,6 +3981,8 @@ struct builtin *builtin_table[] =
&builtin_map, &builtin_map,
&builtin_module, &builtin_module,
&builtin_modulenounzip, &builtin_modulenounzip,
&builtin_partnew,
&builtin_parttype,
&builtin_password, &builtin_password,
&builtin_pause, &builtin_pause,
#ifdef GRUB_UTIL #ifdef GRUB_UTIL

View file

@ -560,7 +560,8 @@ reiserfs_mount (void)
struct reiserfs_super_block super; struct reiserfs_super_block super;
int superblock = REISERFS_DISK_OFFSET_IN_BYTES >> SECTOR_BITS; int superblock = REISERFS_DISK_OFFSET_IN_BYTES >> SECTOR_BITS;
if (! devread (superblock, 0, sizeof (struct reiserfs_super_block), if (part_length < sizeof (struct reiserfs_super_block)
|| ! devread (superblock, 0, sizeof (struct reiserfs_super_block),
(char *) &super) (char *) &super)
|| (substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0 || (substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0
&& substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) > 0) && substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) > 0)
@ -570,8 +571,9 @@ reiserfs_mount (void)
{ {
/* Try old super block position */ /* Try old super block position */
superblock = REISERFS_OLD_DISK_OFFSET_IN_BYTES >> SECTOR_BITS; superblock = REISERFS_OLD_DISK_OFFSET_IN_BYTES >> SECTOR_BITS;
if (! devread (superblock, 0, sizeof (struct reiserfs_super_block), if (part_length < sizeof (struct reiserfs_super_block)
(char *) &super)) || ! devread (superblock, 0, sizeof (struct reiserfs_super_block),
(char *) &super))
return 0; return 0;
if (substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0 if (substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0