1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/*
*
* (C) Copyright IBM Corp. 2003
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: libmac.so
*
* File: commit.c
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <plugin.h>
#include "mac_plugin.h"
int do_mac_commit( LOGICALDISK *ld, DISKSEG *md,
DISKSEG *parent, boolean backup )
{
mac_partition_t *p = NULL;
char *pmap=NULL;
mac_disklabel_t *disklabel=NULL;
DISKSEG *seg;
char *buffer;
disk_private_data_t *disk_pdata;
int rc = 0, i;
seg_private_data_t *pdata;
int map_count=0;
int count=0;
int vsectors_per_block;
sector_count_t max_map_count=0;
char pname[PMAP_STRING_SIZE+1];
char ptype[PMAP_STRING_SIZE+1];
list_element_t iter;
LOG_ENTRY();
REQUIRE(ld);
REQUIRE(md);
disk_pdata = get_mac_disk_private_data(ld);
REQUIRE(disk_pdata);
buffer = malloc(md->size * EVMS_VSECTOR_SIZE);
REQUIRE(buffer != NULL);
disklabel = (mac_disklabel_t *) buffer;
// read mac info & verify we have valid disk label
rc = READ( ld, md->start, md->size, buffer );
if (!rc) {
if ( MAC_DISK_TO_CPU16(disklabel->signature) != MAC_DISK_MAGIC) {
rc = EINVAL;
}
}
if (!rc) {
vsectors_per_block = MAC_DISK_TO_CPU16(disklabel->block_size)>>EVMS_VSECTOR_SIZE_SHIFT;
pmap = buffer + (vsectors_per_block*EVMS_VSECTOR_SIZE);
max_map_count = md->size - vsectors_per_block;
}
else {
free(buffer);
LOG_EXIT_INT(rc);
return rc;
}
// walk through the partition table, removing all linux partition records
// by replacing them with Apple Scratch records
LOG_DEBUG("there should be %d partition records\n", disk_pdata->pcount);
for ( i=0; (i<max_map_count)&&(rc==0); i++ ) {
p = (mac_partition_t *) (pmap + (i*vsectors_per_block*EVMS_VSECTOR_SIZE));
strncpy(pname, p->name, PMAP_STRING_SIZE);
strncpy(ptype, p->type, PMAP_STRING_SIZE);
LOG_DEBUG( " Index (%d): type: %s name: %s\n", i, ptype, pname );
if ( MAC_DISK_TO_CPU32(p->status) & MAC_STATUS_VALID ) {
if ( isa_mac_data_partition(p) == TRUE ) {
LOG_DEBUG(" clearing the entry\n");
memset( (void *) p, 0, sizeof(mac_partition_t) );
}
else {
LOG_DEBUG(" not clearing entry\n");
}
}
else { // we have run off the end of the partition table
LOG_DEBUG("oops ... invalid partition record\n");
break;
}
}
// now walk through the segment list on this drive and add each
// segment to the PMAP
LIST_FOR_EACH( ld->parent_objects, iter, seg ) {
if (seg->data_type == DATA_TYPE) {
LOG_DEBUG(" adding segment %s to the pmap\n", seg->name);
pdata = (seg_private_data_t *) seg->private_data;
for ( i=0,rc=ENOSPC; (rc!=0) && (i<max_map_count); i++ ) {
p = (mac_partition_t *) (pmap + (i*vsectors_per_block*EVMS_VSECTOR_SIZE));
if ( isa_mac_null_partition(p)==TRUE) {
rc = 0;
}
}
if (!rc) {
memcpy( (void *) p, (void *) &pdata->p_record, sizeof(mac_partition_t) );
}
}
}
// tally up the partitions to get a current map count
map_count = 0;
for ( i=0; i<max_map_count; i++) {
p = (mac_partition_t *) (pmap + (i*vsectors_per_block*EVMS_VSECTOR_SIZE));
if ( MAC_DISK_TO_CPU32(p->status) & MAC_STATUS_VALID ) {
++map_count;
}
}
// keep map count current in the disk private data
disk_pdata->pcount = map_count;
// update the map_count in each partition record
count = 0;
for ( i=0; i<max_map_count && count<map_count; i++) {
p = (mac_partition_t *) (pmap + (i*vsectors_per_block*EVMS_VSECTOR_SIZE));
if ( MAC_DISK_TO_CPU32(p->status) & MAC_STATUS_VALID ) {
p->map_count = CPU_TO_MAC_DISK32(map_count);
++count;
}
}
// commit changes
if (backup) {
rc = EngFncs->save_metadata( parent->name, ld->name,
md->start, md->size, buffer );
} else {
rc = WRITE( ld, md->start, md->size, buffer );
}
LOG_EXIT_INT(rc);
return rc;
}
/*
* Function: commit_mac_metadata
*
* Called to commit the mac disk label information.
*/
int commit_mac_segments( DISKSEG *seg, LOGICALDISK *ld, uint commit_phase )
{
int rc=0;
LOG_ENTRY();
REQUIRE(ld != NULL);
REQUIRE(seg != NULL);
if (seg->data_type == META_DATA_TYPE) {
rc = do_mac_commit( ld, seg, NULL, FALSE );
if (!rc) {
seg->flags &= ~SOFLAG_DIRTY;
}
}
else {
seg->flags &= ~SOFLAG_DIRTY;
}
LOG_EXIT_INT(rc);
return rc;
}
|