mirror of
https://github.com/opnsense/src.git
synced 2026-06-11 09:41:03 -04:00
remove_drive: correctly obliterate the magic number.
Reported-by: phk
This commit is contained in:
parent
cf53cf132b
commit
46aebdeaea
1 changed files with 15 additions and 7 deletions
|
|
@ -261,20 +261,28 @@ close_locked_drive(struct drive *drive)
|
|||
|
||||
/*
|
||||
* Remove drive from the configuration.
|
||||
* Caller must ensure that it isn't active
|
||||
* Caller must ensure that it isn't active.
|
||||
*/
|
||||
void
|
||||
remove_drive(int driveno)
|
||||
{
|
||||
struct drive *drive = &vinum_conf.drive[driveno];
|
||||
int64_t nomagic = VINUM_NOMAGIC; /* no magic number */
|
||||
struct vinum_hdr *vhdr; /* buffer for header */
|
||||
int error;
|
||||
|
||||
if (drive->state > drive_referenced) { /* real drive */
|
||||
if (drive->state == drive_up)
|
||||
write_drive(drive, /* obliterate the magic, but leave a hint */
|
||||
(char *) &nomagic,
|
||||
8,
|
||||
VINUM_LABEL_OFFSET);
|
||||
if (drive->state == drive_up) {
|
||||
vhdr = (struct vinum_hdr *) Malloc(VINUMHEADERLEN); /* allocate buffer */
|
||||
CHECKALLOC(vhdr, "Can't allocate memory");
|
||||
error = read_drive(drive, (void *) vhdr, VINUMHEADERLEN, VINUM_LABEL_OFFSET);
|
||||
if (error)
|
||||
drive->lasterror = error;
|
||||
else {
|
||||
vhdr->magic = VINUM_NOMAGIC; /* obliterate the magic, but leave the rest */
|
||||
write_drive(drive, (void *) vhdr, VINUMHEADERLEN, VINUM_LABEL_OFFSET);
|
||||
}
|
||||
Free(vhdr);
|
||||
}
|
||||
free_drive(drive); /* close it and free resources */
|
||||
save_config(); /* and save the updated configuration */
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue