Index: branches/ErmaC/Enoch/i386/libsaio/fake_efi.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/fake_efi.h (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/fake_efi.h (revision 2587) @@ -29,7 +29,7 @@ #define __LIBSAIO_FAKE_EFI_H /* Set up space for up to 10 configuration table entries */ -#define MAX_CONFIGURATION_TABLE_ENTRIES 10 +#define MAX_CONFIGURATION_TABLE_ENTRIES (uint32_t)10 extern void setupFakeEfi(void); Index: branches/ErmaC/Enoch/i386/libsaio/xml.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/xml.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/xml.c (revision 2587) @@ -2,15 +2,15 @@ * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * Portions Copyright (c) 2003 Apple Computer, Inc. All Rights - * Reserved. + * Reserved. * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 2.0 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. - * + * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -18,7 +18,7 @@ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. - * + * * @APPLE_LICENSE_HEADER_END@ */ @@ -27,15 +27,25 @@ #include "sl.h" #include "xml.h" +#ifndef DEBUG_XML +#define DEBUG_XML 0 +#endif + +#if DEBUG_XML +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + string_ref *ref_strings = NULL; /// TODO: remove below -static char* buffer_start = NULL; +static char *buffer_start = NULL; // TODO: redo the next two functions -void SaveRefString(char* string, int id) +void SaveRefString(char *string, int id) { //printf("Adding Ref String %d (%s)\n", id, string); - string_ref* tmp = ref_strings; + string_ref *tmp = ref_strings; while(tmp) { if(tmp->id == id) @@ -49,15 +59,15 @@ string_ref* new_ref = malloc(sizeof(string_ref)); new_ref->string = malloc(strlen(string)+1); - sprintf(new_ref->string, "%s", string); + snprintf(new_ref->string, (strlen(string)+1)* sizeof(char),"%s", string); new_ref->id = id; new_ref->next = ref_strings; ref_strings = new_ref; } -char* GetRefString(int id) +char *GetRefString(int id) { - string_ref* tmp = ref_strings; + string_ref *tmp = ref_strings; while(tmp) { if(tmp->id == id) return tmp->string; @@ -127,13 +137,13 @@ //========================================================================== // XMLGetProperty -TagPtr -XMLGetProperty(TagPtr dict, const char * key) +TagPtr XMLGetProperty(TagPtr dict, const char *key) { TagPtr tagList, tag; - if (dict->type != kTagTypeDict) { - return 0; + if (dict->type != kTagTypeDict) + { + return NULL; } tag = 0; @@ -142,26 +152,28 @@ tag = tagList; tagList = tag->tagNext; - if ((tag->type != kTagTypeKey) || (tag->string == 0)) { + if ((tag->type != kTagTypeKey) || (tag->string == 0)) + { continue; } - if (!strcmp(tag->string, key)) { + if (!strcmp(tag->string, key)) + { return tag->tag; } } - return 0; + return NULL; } //========================================================================== // XMLGetProperty -TagPtr -XMLGetKey( TagPtr dict, int id ) +TagPtr XMLGetKey( TagPtr dict, int id ) { TagPtr tagList, tag; - - if (dict->type != kTagTypeDict) { + + if (dict->type != kTagTypeDict) + { return 0; } @@ -173,12 +185,14 @@ tag = tagList; tagList = tag->tagNext; - if ((tag->type != kTagTypeKey) || (tag->string == 0)) { + if ((tag->type != kTagTypeKey) || (tag->string == 0)) + { continue; } element++; - if(id == element) { + if(id == element) + { return tag; } @@ -188,7 +202,8 @@ TagPtr XMLGetValueForKey(TagPtr key) { - if (!key || key->type != kTagTypeKey) { + if (!key || key->type != kTagTypeKey) + { return 0; } @@ -204,7 +219,8 @@ int count = 0; TagPtr tagList, tag; - if (dict->type != kTagTypeDict && dict->type != kTagTypeArray) { + if (dict->type != kTagTypeDict && dict->type != kTagTypeArray) + { return 0; } @@ -214,24 +230,26 @@ { tag = tagList; tagList = tag->tagNext; - + if (((tag->type != kTagTypeKey) && ((tag->string == 0) || (tag->string[0] == 0))) && (dict->type != kTagTypeArray) // If we are an array, any element is valid - ) { + ) + { continue; } - + //if(tag->type == kTagTypeKey) printf("Located key %s\n", tag->string); count++; } - + return count; } TagPtr XMLGetElement( TagPtr dict, int id ) { - if(dict->type != kTagTypeArray) { + if(dict->type != kTagTypeArray) + { return 0; } @@ -243,33 +261,36 @@ element++; tmp = tmp->tagNext; } - + return tmp; } + /* Function for basic XML character entities parsing */ +typedef const struct XMLEntity { + const char *name; + size_t nameLen; + char value; +} XMLEntity; -char* -XMLDecode(const char* src) +/* This is ugly, but better than specifying the lengths by hand */ +// +#define _e(str,c) {str,sizeof(str)-1,c} +const XMLEntity ents[] = { + _e("quot;",'"'), // double quotation mark + _e("apos;",'\''), // ampersand + _e("lt;", '<'), // apostrophe (apostrophe-quote) + _e("gt;", '>'), // less-than sign + _e("amp;", '&') // greater-than sign +}; + +char *XMLDecode(const char *src) { - typedef const struct XMLEntity { - const char* name; - size_t nameLen; - char value; - } XMLEntity; - - /* This is ugly, but better than specifying the lengths by hand */ - #define _e(str,c) {str,sizeof(str)-1,c} - const XMLEntity ents[] = { - _e("quot;",'"'), _e("apos;",'\''), - _e("lt;", '<'), _e("gt;", '>'), - _e("amp;", '&') - }; - size_t len; const char *s; char *out, *o; - if ( !src || !(len = strlen(src)) || !(out = malloc(len+1)) ) { + if ( !src || !(len = strlen(src)) || !(out = malloc(len+1)) ) + { return 0; } @@ -277,19 +298,22 @@ s = src; while (s <= src+len) /* Make sure the terminator is also copied */ { - if ( *s == '&' ) { + if ( *s == '&' ) + { bool entFound = false; int i; s++; for ( i = 0; i < sizeof(ents)/sizeof(ents[0]); i++) { - if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 ) { + if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 ) + { entFound = true; break; } } - if ( entFound ) { + if ( entFound ) + { *o++ = ents[i].value; s += ents[i].nameLen; @@ -303,7 +327,6 @@ return out; } -//#if UNUSED //========================================================================== // XMLParseFile // Expects to see one dictionary in the XML file, the final pos will be returned @@ -311,111 +334,139 @@ // Puts the first dictionary it finds in the // tag pointer and returns the end of the dic, or returns -1 if not found. // -long -XMLParseFile( char * buffer, TagPtr * dict ) +long XMLParseFile( char * buffer, TagPtr *dict ) { - long length, pos; - TagPtr tag; - pos = 0; - char *configBuffer; + long length; + long pos = 0; + TagPtr tag; + char *configBuffer; int strlength = strlen(buffer); configBuffer = malloc(strlength+1); bcopy(buffer, configBuffer, strlength); + configBuffer[strlength] = 0; buffer_start = configBuffer; - while (1) - { - length = XMLParseNextTag(configBuffer + pos, &tag); - if (length == -1) break; + while (1) + { + length = XMLParseNextTag(configBuffer + pos, &tag); + if (length == -1) break; - pos += length; + pos += length; - if (tag == 0) continue; - if (tag->type == kTagTypeDict) break; - - XMLFreeTag(tag); - } + if (tag == 0) + { + continue; + } + + if (tag->type == kTagTypeDict) + { + break; + } + + XMLFreeTag(tag); + } free(configBuffer); - if (length < 0) { - return -1; - } - *dict = tag; - return pos; + if (length < 0) + { + return -1; + } + *dict = tag; + return pos; } -//#endif /* UNUSED */ //========================================================================== // ParseNextTag -// TODO: cleanup -long -XMLParseNextTag( char * buffer, TagPtr * tag ) + +long XMLParseNextTag( char *buffer, TagPtr *tag ) { - long length, pos; - char * tagName; + long length = 0; + long pos = 0; + char *tagName = NULL; length = GetNextTag(buffer, &tagName, 0); - if (length == -1) { + if (length == -1) + { return -1; } pos = length; - if (!strncmp(tagName, kXMLTagPList, 6)) { + if (!strncmp(tagName, kXMLTagPList, 6)) + { length = 0; // just a header; nothing to parse // return-via-reference tag should be left alone } /***** dict ****/ - else if (!strcmp(tagName, kXMLTagDict)) + else if (!strncmp(tagName, kXMLTagDict, sizeof(kXMLTagDict))) { length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); - } else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') { + } + else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') + { length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); - } else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) { + } + else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) + { length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); } /***** key ****/ - else if (!strcmp(tagName, kXMLTagKey)) { + else if (!strncmp(tagName, kXMLTagKey, sizeof(kXMLTagKey))) + { length = ParseTagKey(buffer + pos, tag); } /***** string ****/ - else if (!strcmp(tagName, kXMLTagString)) { + else if (!strncmp(tagName, kXMLTagString, sizeof(kXMLTagString))) + { length = ParseTagString(buffer + pos, tag); - } else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) { + } + else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) + { // TODO: save tag if if found - if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) { + if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) + { // ID= int id = 0; int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\""); - while(*val) { - if ((*val >= '0' && *val <= '9')) { // 0 - 9 + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { id = (id * 10) + (*val++ - '0'); - } else { + } + else + { printf("ParseStringID error (0x%x)\n", *val); getchar(); return -1; } } length = ParseTagString(buffer + pos, tag); - + SaveRefString(buffer + pos, id); - } else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) { + } + else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) + { // IDREF= int id = 0; int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\""); - while(*val) { - if ((*val >= '0' && *val <= '9')) { // 0 - 9 + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { id = (id * 10) + (*val++ - '0'); - } else { + } + else + { printf("ParseStringIDREF error (0x%x)\n", *val); getchar(); return -1; @@ -430,54 +481,73 @@ tmpTag->tagNext = 0; tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; *tag = tmpTag; - + length = 0; //printf("Located IDREF, id = %d, string = %s\n", id, str); } } /***** integer ****/ - else if (!strcmp(tagName, kXMLTagInteger)) { + else if (!strncmp(tagName, kXMLTagInteger, sizeof(kXMLTagInteger))) + { length = ParseTagInteger(buffer + pos, tag); - } else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) { - if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) { + } + else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) + { + if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) + { // ID= int id = 0; int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\""); - while(*val) { - if ((*val >= '0' && *val <= '9')) { // 0 - 9 + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { id = (id * 10) + (*val++ - '0'); - } else { + } + else + { printf("ParseIntegerID error (0x%x)\n", *val); getchar(); return -1; } } length = ParseTagInteger(buffer + pos, tag); - + SaveRefString((*tag)->string, id); - } else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) { + } + else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) + { // IDREF= int id = 0; int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1; while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++; tagName[cnt] = 0; char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\""); - while(*val) { - if ((*val >= '0' && *val <= '9')) { // 0 - 9 + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { id = (id * 10) + (*val++ - '0'); - } else { + } + else + { printf("ParseStringIDREF error (0x%x)\n", *val); getchar(); return -1; } } int integer = (int)GetRefString(id); - + TagPtr tmpTag = NewTag(); + if (tmpTag == 0) + { + return -1; + } + tmpTag->type = kTagTypeInteger; tmpTag->string = (char*) integer; tmpTag->tag = 0; @@ -485,22 +555,26 @@ tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0; *tag = tmpTag; - + length = 0; //printf("Located IDREF, id = %d, string = %s\n", id, str); - } else { + } + else + { length = ParseTagInteger(buffer + pos, tag); } } /***** false ****/ - else if (!strcmp(tagName, kXMLTagFalse)) { + else if (!strncmp(tagName, kXMLTagFalse, sizeof(kXMLTagFalse))) + { length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); } /***** true ****/ - else if (!strcmp(tagName, kXMLTagTrue)) { + else if (!strncmp(tagName, kXMLTagTrue, sizeof(kXMLTagTrue))) + { length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); } @@ -511,35 +585,49 @@ /***** data ****/ - else if (!strcmp(tagName, kXMLTagData)) { + else if (!strncmp(tagName, kXMLTagData, sizeof(kXMLTagData))) + { length = ParseTagData(buffer + pos, tag); - } else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) { + } + else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) + { length = ParseTagData(buffer + pos, tag); - } else if (!strcmp(tagName, kXMLTagDate)) { + } + + else if (!strncmp(tagName, kXMLTagDate, sizeof(kXMLTagDate))) + { length = ParseTagDate(buffer + pos, tag); } /***** date ****/ - else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) { + else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) + { length = ParseTagDate(buffer + pos, tag); - } /***** array ****/ - else if (!strcmp(tagName, kXMLTagArray)) { + } + /***** array ****/ + else if (!strncmp(tagName, kXMLTagArray, sizeof(kXMLTagArray) )) + { length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); } - else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) { + else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) + { length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); - } else if (!strcmp(tagName, kXMLTagArray "/")) { + } + else if (!strncmp(tagName, kXMLTagArray "/", strlen(kXMLTagArray "/"))) + { length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); } /***** unknown ****/ - else { - // it wasn't parsed so we consumed no additional characters - *tag = 0; + else + { + // it wasn't parsed so we consumed no additional characters + *tag = NULL; length = 0; } - if (length == -1) { + if (length == -1) + { return -1; } @@ -549,40 +637,45 @@ //========================================================================== // ParseTagList -static long -ParseTagList( char * buffer, TagPtr * tag, long type, long empty ) +static long ParseTagList( char *buffer, TagPtr *tag, long type, long empty ) { - long length, pos; - TagPtr tagList, tmpTag; + long pos = 0; + long length = 0; + TagPtr tagList = NULL; + TagPtr tmpTag; + - tagList = 0; - pos = 0; - - if (!empty) { - while (1) { + if (!empty) + { + while (1) + { length = XMLParseNextTag(buffer + pos, &tmpTag); - if (length == -1) { + if (length == -1) + { break; } pos += length; // detect end of list - if (tmpTag == 0) { + if (tmpTag == NULL) + { break; } tmpTag->tagNext = tagList; tagList = tmpTag; } - if (length == -1) { + if (length == -1) + { XMLFreeTag(tagList); return -1; } } tmpTag = NewTag(); - if (tmpTag == 0) { + if (tmpTag == NULL) + { XMLFreeTag(tagList); return -1; } @@ -601,31 +694,36 @@ //========================================================================== // ParseTagKey -static long -ParseTagKey( char * buffer, TagPtr * tag ) +static long ParseTagKey( char *buffer, TagPtr *tag ) { - long length, length2; - char *string; - TagPtr tmpTag, subTag; + long length = 0; + long length2 = 0; + char *string; + TagPtr tmpTag; + TagPtr subTag; length = FixDataMatchingTag(buffer, kXMLTagKey); - if (length == -1) { + if (length == -1) + { return -1; } length2 = XMLParseNextTag(buffer + length, &subTag); - if (length2 == -1) { + if (length2 == -1) + { return -1; } tmpTag = NewTag(); - if (tmpTag == 0) { + if (tmpTag == NULL) + { XMLFreeTag(subTag); return -1; } string = NewSymbol(buffer); - if (string == 0) { + if (string == NULL) + { XMLFreeTag(subTag); XMLFreeTag(tmpTag); return -1; @@ -638,40 +736,42 @@ tmpTag->tagNext = 0; *tag = tmpTag; - + return length + length2; } //========================================================================== // ParseTagString -static long -ParseTagString( char * buffer, TagPtr * tag ) +static long ParseTagString( char *buffer, TagPtr *tag ) { - long length; - char * string; + long length = 0; + char *string; length = FixDataMatchingTag(buffer, kXMLTagString); - if (length == -1) { + if (length == -1) + { return -1; } TagPtr tmpTag = NewTag(); - if (tmpTag == 0) { + if (tmpTag == NULL) + { return -1; } - + string = NewSymbol(buffer); - if (string == 0) { + if (string == NULL) + { XMLFreeTag(tmpTag); return -1; } tmpTag->type = kTagTypeString; tmpTag->string = string; - tmpTag->tag = 0; + tmpTag->tag = NULL; + tmpTag->tagNext = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; - tmpTag->tagNext = 0; *tag = tmpTag; return length; @@ -680,8 +780,7 @@ //========================================================================== // ParseTagInteger -static long -ParseTagInteger( char * buffer, TagPtr * tag ) +static long ParseTagInteger( char *buffer, TagPtr *tag ) { long length, integer; bool negative = false; @@ -704,46 +803,62 @@ return 0; } - + size = length = FixDataMatchingTag(buffer, kXMLTagInteger); - if (length == -1) { + if (length == -1) + { return -1; } tmpTag = NewTag(); - if (tmpTag == 0) { + if (tmpTag == 0) + { return -1; } integer = 0; - if(size > 1 && (val[1] == 'x' || val[1] == 'X')) { // Hex value + if(size > 1 && (val[1] == 'x' || val[1] == 'X')) // Hex value + { val += 2; - while(*val) { - if ((*val >= '0' && *val <= '9')) { // 0 - 9 - + while(*val) + { + if ((*val >= '0' && *val <= '9')) // 0 - 9 + { integer = (integer * 16) + (*val++ - '0'); - } else if ((*val >= 'a' && *val <= 'f')) { // a - f + } + else if ((*val >= 'a' && *val <= 'f')) // a - f + { integer = (integer * 16) + (*val++ - 'a' + 10); - } else if ((*val >= 'A' && *val <= 'F')) { // A - F + } + else if ((*val >= 'A' && *val <= 'F')) // A - F + { integer = (integer * 16) + (*val++ - 'A' + 10); - } else { + } + else + { printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer); getchar(); XMLFreeTag(tmpTag); return -1; } } - } else if ( size ) { // Decimal value - if (*val == '-') { + } + else if ( size ) // Decimal value + { + if (*val == '-') + { negative = true; val++; size--; } - for (integer = 0; size > 0; size--) { - if(*val) { // UGLY HACK, fix me. - if (*val < '0' || *val > '9') { + for (integer = 0; size > 0; size--) + { + if(*val) // UGLY HACK, fix me. + { + if (*val < '0' || *val > '9') + { printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer); getchar(); return -1; @@ -760,9 +875,9 @@ tmpTag->type = kTagTypeInteger; tmpTag->string = (char *)integer; - tmpTag->tag = 0; + tmpTag->tag = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; - tmpTag->tagNext = 0; + tmpTag->tagNext = NULL; *tag = tmpTag; @@ -772,30 +887,38 @@ //========================================================================== // ParseTagData -static long -ParseTagData( char * buffer, TagPtr * tag ) +static long ParseTagData( char *buffer, TagPtr *tag ) { - int actuallen = 0; - long length; - TagPtr tmpTag; + int actuallen = 0; + long length = 0; + TagPtr tmpTag; + char *string; length = FixDataMatchingTag(buffer, kXMLTagData); - if (length == -1) return -1; + if (length == -1) + { + return -1; + } tmpTag = NewTag(); - if (tmpTag == 0) return -1; + if (tmpTag == NULL) + { + return -1; + } //printf("ParseTagData unimplimented\n"); //printf("Data: %s\n", buffer); // getchar(); - char* string = BASE64Decode(buffer, strlen(buffer), &actuallen); + string = BASE64Decode(buffer, strlen(buffer), &actuallen); tmpTag->type = kTagTypeData; tmpTag->string = string; - tmpTag->tag = 0; + + tmpTag->tag = NULL; tmpTag->offset = actuallen; // buffer_start ? buffer - buffer_start: 0; - tmpTag->tagNext = 0; + tmpTag->tagNext = NULL; + *tag = tmpTag; return length; @@ -804,26 +927,31 @@ //========================================================================== // ParseTagDate -static long -ParseTagDate( char * buffer, TagPtr * tag ) +static long ParseTagDate( char *buffer, TagPtr *tag ) { - long length; - TagPtr tmpTag; + long length = 0; + TagPtr tmpTag; length = FixDataMatchingTag(buffer, kXMLTagDate); - if (length == -1) return -1; + if (length == -1) + { + return -1; + } tmpTag = NewTag(); - if (tmpTag == 0) return -1; + if (tmpTag == NULL) + { + return -1; + } printf("ParseTagDate unimplimented\n"); getchar(); tmpTag->type = kTagTypeDate; - tmpTag->string = 0; - tmpTag->tag = 0; + tmpTag->string = NULL; + tmpTag->tag = NULL; + tmpTag->tagNext = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; - tmpTag->tagNext = 0; *tag = tmpTag; @@ -833,20 +961,23 @@ //========================================================================== // ParseTagBoolean -long -ParseTagBoolean( char * buffer, TagPtr * tag, long type ) +long ParseTagBoolean( char *buffer, TagPtr *tag, long type ) { TagPtr tmpTag; tmpTag = NewTag(); - if (tmpTag == 0) return -1; + if (tmpTag == NULL) + { + return -1; + } tmpTag->type = type; - tmpTag->string = 0; - tmpTag->tag = 0; + tmpTag->string = NULL; + tmpTag->tag = NULL; + tmpTag->tagNext = NULL; tmpTag->offset = buffer_start ? buffer - buffer_start: 0; - tmpTag->tagNext = 0; + *tag = tmpTag; return 0; @@ -855,32 +986,44 @@ //========================================================================== // GetNextTag -static long -GetNextTag( char * buffer, char ** tag, long * start ) +static long GetNextTag( char *buffer, char **tag, long *start ) { - long cnt, cnt2; + long cnt; + long cnt2; - if (tag == 0) { + if (tag == NULL) + { return -1; } // Find the start of the tag. cnt = 0; - while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++; - if (buffer[cnt] == '\0') { + while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) + { + cnt++; + } + + if (buffer[cnt] == '\0') + { return -1; } // Find the end of the tag. cnt2 = cnt + 1; - while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++; - if (buffer[cnt2] == '\0') { + while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) + { + cnt2++; + } + + if (buffer[cnt2] == '\0') + { return -1; } // Fix the tag data. *tag = buffer + cnt + 1; buffer[cnt2] = '\0'; - if (start) { + if (start) + { *start = cnt; } @@ -893,25 +1036,33 @@ // Returns the length of the data found, counting the end tag, // or -1 if the end tag was not found. -static long -FixDataMatchingTag( char * buffer, char * tag ) +static long FixDataMatchingTag( char *buffer, char *tag ) { - long length, start, stop; - char * endTag; - - start = 0; - while (1) - { - length = GetNextTag(buffer + start, &endTag, &stop); - if (length == -1) return -1; - - if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break; - start += length; - } - - buffer[start + stop] = '\0'; - - return start + length; + long length; + long start; + long stop; + char *endTag; + + start = 0; + while (1) + { + length = GetNextTag(buffer + start, &endTag, &stop); + if (length == -1) + { + return -1; + } + + if ((*endTag == '/') && !strcmp(endTag + 1, tag)) + { + break; + } + + start += length; + } + + buffer[start + stop] = '\0'; + + return start + length; } //========================================================================== @@ -919,50 +1070,52 @@ #define kTagsPerBlock (0x1000) -static TagPtr gTagsFree; - -static TagPtr -NewTag( void ) +static TagPtr gTagsFree = NULL; +static TagPtr NewTag( void ) { - long cnt; - TagPtr tag; + long cnt; + TagPtr tag; - if (gTagsFree == 0) - { - tag = (TagPtr)malloc(kTagsPerBlock * sizeof(Tag)); - if (tag == 0) return 0; - - // Initalize the new tags. - for (cnt = 0; cnt < kTagsPerBlock; cnt++) - { - tag[cnt].type = kTagTypeNone; - tag[cnt].string = 0; - tag[cnt].tag = 0; - tag[cnt].tagNext = tag + cnt + 1; - } - tag[kTagsPerBlock - 1].tagNext = 0; + if (gTagsFree == NULL) + { + tag = (TagPtr)malloc(kTagsPerBlock *sizeof(Tag)); + if (tag == NULL) + { + return NULL; + } - gTagsFree = tag; - } + // Initalize the new tags. + for (cnt = 0; cnt < kTagsPerBlock; cnt++) + { + tag[cnt].type = kTagTypeNone; + tag[cnt].string = 0; + tag[cnt].tag = 0; + tag[cnt].tagNext = tag + cnt + 1; + } + tag[kTagsPerBlock - 1].tagNext = 0; - tag = gTagsFree; - gTagsFree = tag->tagNext; - - return tag; + gTagsFree = tag; + } + + tag = gTagsFree; + gTagsFree = tag->tagNext; + + return tag; } //========================================================================== // XMLFreeTag -void -XMLFreeTag( TagPtr tag ) +void XMLFreeTag( TagPtr tag ) { #if DOFREE - if (tag == 0) { + if (tag == NULL) + { return; } - if (!XMLIsInteger(tag) && tag->string) { + if (!XMLIsInteger(tag) && tag->string) + { FreeSymbol(tag->string); } @@ -971,8 +1124,8 @@ // Clear and free the tag. tag->type = kTagTypeNone; - tag->string = 0; - tag->tag = 0; + tag->string = NULL; + tag->tag = NULL; tag->offset = 0; tag->tagNext = gTagsFree; gTagsFree = tag; @@ -992,26 +1145,28 @@ }; typedef struct Symbol Symbol, *SymbolPtr; -static SymbolPtr FindSymbol(char * string, SymbolPtr * prevSymbol); +static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol); -static SymbolPtr gSymbolsHead; +static SymbolPtr gSymbolsHead = NULL; //========================================================================== // NewSymbol -static char * -NewSymbol( char * string ) +static char *NewSymbol( char *string ) { static SymbolPtr lastGuy = 0; - SymbolPtr symbol; + SymbolPtr symbol; + // Look for string in the list of symbols. symbol = FindSymbol(string, 0); - // Add the new symbol. - if (symbol == 0) { + // Add the new symbol. + if (symbol == NULL) + { symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string)); - if (symbol == 0) { //return 0; + if (symbol == NULL) + { stop("NULL symbol!"); } @@ -1027,7 +1182,8 @@ // Update the refCount and return the string. symbol->refCount++; - if (lastGuy && lastGuy->next != 0) { + if (lastGuy && lastGuy->next != 0) + { stop("last guy not last!"); } @@ -1038,29 +1194,33 @@ // FreeSymbol #if DOFREE -static void -FreeSymbol( char * string ) +static void FreeSymbol( char *string ) { SymbolPtr symbol, prev; - prev = 0; + prev = NULL; // Look for string in the list of symbols. symbol = FindSymbol(string, &prev); - if (symbol == 0) { + if (symbol == NULL) + { return; } // Update the refCount. symbol->refCount--; - if (symbol->refCount != 0) { + if (symbol->refCount != 0) + { return; } // Remove the symbol from the list. - if (prev != 0) { + if (prev != NULL) + { prev->next = symbol->next; - } else { + } + else + { gSymbolsHead = symbol->next; } @@ -1072,16 +1232,22 @@ //========================================================================== // FindSymbol -static SymbolPtr -FindSymbol( char * string, SymbolPtr * prevSymbol ) +static SymbolPtr FindSymbol( char *string, SymbolPtr *prevSymbol ) { SymbolPtr symbol, prev; - + + if (string == NULL) + { + return NULL; + } + symbol = gSymbolsHead; - prev = 0; + prev = NULL; - while (symbol != 0) { - if (!strcmp(symbol->string, string)) { + while (symbol != NULL) + { + if (!strcmp(symbol->string, string)) + { break; } @@ -1089,7 +1255,8 @@ symbol = symbol->next; } - if ((symbol != 0) && (prevSymbol != 0)) { + if ((symbol != NULL) && (prevSymbol != NULL)) + { *prevSymbol = prev; } @@ -1098,7 +1265,8 @@ bool XMLIsType(TagPtr dict, enum xmltype type) { - if(!dict) { + if(!dict) + { return (type == kTagTypeNone); } return (dict->type == type); @@ -1112,10 +1280,13 @@ TagPtr XMLCastArray(TagPtr dict) { - if(!dict) { + if(!dict) + { return NULL; } - if(dict->type == kTagTypeArray) { + + if(dict->type == kTagTypeArray) + { return dict; } else { return NULL; @@ -1134,12 +1305,17 @@ TagPtr XMLCastDict(TagPtr dict) { - if(!dict) { + if(!dict) + { return NULL; } - if(dict->type == kTagTypeDict) { + + if(dict->type == kTagTypeDict) + { return dict; - } else { + } + else + { return NULL; } } @@ -1149,26 +1325,30 @@ return entry && ((entry->type == kTagTypeString) || (entry->type == kTagTypeKey)); } -char* XMLCastString(TagPtr dict) +char *XMLCastString(TagPtr dict) { - if(!dict) { + if(!dict) + { return NULL; } - if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) { + if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) + { return dict->string; } return NULL; } -char* XMLCastData(TagPtr dict, int* length) +char *XMLCastData(TagPtr dict, int* length) { - if(!dict) { + if(!dict) + { return NULL; } - if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) { + if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) + { *length = dict->offset; return dict->string; } @@ -1179,9 +1359,12 @@ long XMLCastStringOffset(TagPtr dict) { - if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) { + if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) + { return dict->offset; - } else { + } + else + { return -1; } } @@ -1193,10 +1376,13 @@ bool XMLCastBoolean(TagPtr dict) { - if(!dict) { + if(!dict) + { return false; } - if(dict->type == kTagTypeTrue) { + + if(dict->type == kTagTypeTrue) + { return true; } return false; @@ -1209,19 +1395,23 @@ int XMLCastInteger(TagPtr dict) { - if(!dict) { + if(!dict) + { //printf("XMLCastInteger: null dict\n"); return 0; } - if(dict->type == kTagTypeInteger) { + + if(dict->type == kTagTypeInteger) + { return (int)(dict->string); } return 0; } -bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value) +bool XMLAddTagToDictionary(TagPtr dict, char *key, TagPtr value) { - if (!dict || dict->type != kTagTypeDict) { + if (!dict || dict->type != kTagTypeDict) + { return false; } @@ -1229,12 +1419,14 @@ char* string; tmpTag = NewTag(); - if (tmpTag == 0) { + if (tmpTag == 0) + { return false; } string = NewSymbol(key); - if (string == 0) { + if (string == 0) + { XMLFreeTag(tmpTag); return false; } @@ -1246,13 +1438,15 @@ tmpTag->tagNext = 0; TagPtr tagList = dict->tag; - if(!tagList) { + if(!tagList) + { // First tag dict->tag = tmpTag; return true; } while(tagList && tagList->tagNext) tagList = tagList->tagNext; - if(tagList) { + if(tagList) + { tagList->tagNext = tmpTag; return true; } Index: branches/ErmaC/Enoch/i386/libsaio/xml.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/xml.h (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/xml.h (revision 2587) @@ -2,7 +2,7 @@ * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * Portions Copyright (c) 2003 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public @@ -10,7 +10,7 @@ * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. - * + * * The Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -18,7 +18,7 @@ * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. - * + * * @APPLE_LICENSE_HEADER_END@ */ @@ -40,13 +40,13 @@ struct string_ref { - char* string; + char *string; int id; - struct string_ref* next; + struct string_ref *next; }; typedef struct string_ref string_ref; -extern string_ref* ref_strings; +extern string_ref *ref_strings; #define kXMLTagPList "plist " #define kXMLTagDict "dict" @@ -63,27 +63,17 @@ #define kXMLStringID "ID=" #define kXMLStringIDRef "IDREF=" -#define kPropCFBundleIdentifier ("CFBundleIdentifier") -#define kPropCFBundleExecutable ("CFBundleExecutable") -#define kPropOSBundleRequired ("OSBundleRequired") -#define kPropOSBundleLibraries ("OSBundleLibraries") -#define kPropIOKitPersonalities ("IOKitPersonalities") -#define kPropIONameMatch ("IONameMatch") +#define kPropCFBundleIdentifier ("CFBundleIdentifier") +#define kPropCFBundleExecutable ("CFBundleExecutable") +#define kPropOSBundleRequired ("OSBundleRequired") +#define kPropOSBundleLibraries ("OSBundleLibraries") +#define kPropIOKitPersonalities ("IOKitPersonalities") +#define kPropIONameMatch ("IONameMatch") -/* -struct Tag { - long type; - char *string; - struct Tag *tag; - struct Tag *tagNext; -}; -typedef struct Tag Tag, *TagPtr; - */ - extern long gImageFirstBootXAddr; extern long gImageLastKernelAddr; -TagPtr XMLGetProperty( TagPtr dict, const char * key ); +TagPtr XMLGetProperty( TagPtr dict, const char *key ); TagPtr XMLGetElement( TagPtr dict, int id ); TagPtr XMLGetKey( TagPtr dict, int id ); TagPtr XMLGetValueForKey(TagPtr key); @@ -98,7 +88,7 @@ int XMLCastInteger ( TagPtr dict ); TagPtr XMLCastDict ( TagPtr dict ); TagPtr XMLCastArray( TagPtr dict ); -char* XMLCastData( TagPtr dict, int* length ); +char* XMLCastData( TagPtr dict, int *length ); bool XMLIsBoolean(TagPtr entry); bool XMLIsString (TagPtr entry); @@ -108,7 +98,7 @@ bool XMLIsData (TagPtr entry); -bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value); +bool XMLAddTagToDictionary(TagPtr dict, char *key, TagPtr value); long XMLParseNextTag(char *buffer, TagPtr *tag); void XMLFreeTag(TagPtr tag); @@ -119,11 +109,11 @@ // Puts the first dictionary it finds in the // tag pointer and returns 0, or returns -1 if not found. // -long XMLParseFile( char * buffer, TagPtr * dict ); +long XMLParseFile( char *buffer, TagPtr *dict ); //========================================================================== // ParseTag* -long ParseTagBoolean( char * buffer, TagPtr * tag, long type ); +long ParseTagBoolean( char *buffer, TagPtr *tag, long type ); #endif /* __LIBSAIO_XML_H */ Index: branches/ErmaC/Enoch/i386/libsaio/efi.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/efi.h (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/efi.h (revision 2587) @@ -254,7 +254,7 @@ IN EFI_UINTN DescriptorSize, IN EFI_UINT32 DescriptorVersion, IN EFI_MEMORY_DESCRIPTOR * VirtualMap - ); + ) __attribute__((regparm(0))); typedef EFI_RUNTIMESERVICE @@ -262,7 +262,7 @@ (EFIAPI *EFI_CONVERT_POINTER) ( IN EFI_UINTN DebugDisposition, IN OUT VOID **Address - ); + ) __attribute__((regparm(0))); // Variable attributes @@ -281,7 +281,7 @@ OUT EFI_UINT32 * Attributes OPTIONAL, IN OUT EFI_UINTN * DataSize, OUT VOID * Data - ); + ) __attribute__((regparm(0))); typedef EFI_RUNTIMESERVICE @@ -290,7 +290,7 @@ IN OUT EFI_UINTN * VariableNameSize, IN OUT EFI_CHAR16 * VariableName, IN OUT EFI_GUID * VendorGuid - ); + ) __attribute__((regparm(0))); typedef EFI_RUNTIMESERVICE @@ -301,7 +301,7 @@ IN EFI_UINT32 Attributes, IN EFI_UINTN DataSize, IN VOID * Data - ); + ) __attribute__((regparm(0))); // EFI Time @@ -318,14 +318,14 @@ (EFIAPI *EFI_GET_TIME) ( OUT EFI_TIME * Time, OUT EFI_TIME_CAPABILITIES * Capabilities OPTIONAL - ); + ) __attribute__((regparm(0))); typedef EFI_RUNTIMESERVICE EFI_STATUS (EFIAPI *EFI_SET_TIME) ( IN EFI_TIME * Time - ); + ) __attribute__((regparm(0))); typedef EFI_RUNTIMESERVICE @@ -334,7 +334,7 @@ OUT EFI_BOOLEAN * Enabled, OUT EFI_BOOLEAN * Pending, OUT EFI_TIME * Time - ); + ) __attribute__((regparm(0))); typedef EFI_RUNTIMESERVICE @@ -342,7 +342,7 @@ (EFIAPI *EFI_SET_WAKEUP_TIME) ( IN EFI_BOOLEAN Enable, IN EFI_TIME * Time OPTIONAL - ); + ) __attribute((regparm(0))); typedef enum { EfiResetCold, @@ -363,7 +363,7 @@ IN EFI_STATUS ResetStatus, IN EFI_UINTN DataSize, IN EFI_CHAR16 * ResetData OPTIONAL - ); + ) __attribute__((regparm(0))); typedef EFI_RUNTIMESERVICE @@ -391,7 +391,7 @@ IN EFI_UINT32 Instance, IN EFI_GUID * CallerId OPTIONAL, IN EFI_STATUS_CODE_DATA * Data OPTIONAL - ); + ) __attribute__((regparm(0))); #endif // Index: branches/ErmaC/Enoch/i386/libsaio/vbe.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/vbe.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/vbe.c (revision 2587) @@ -129,7 +129,7 @@ #define kC 30.0 // C = (C'-J) * (K/256) + J #define kM 300.0 // M = K/256 * M' -int Round(double f) +static int Round(double f) { return (int)(f + 0.5); } Index: branches/ErmaC/Enoch/i386/libsaio/device_tree.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/device_tree.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/device_tree.c (revision 2587) @@ -82,8 +82,7 @@ //============================================================================== -Property * -DT__AddProperty(Node *node, const char *name, uint32_t length, void *value) +Property *DT__AddProperty(Node *node, const char *name, uint32_t length, void *value) { Property *prop; @@ -143,8 +142,7 @@ //============================================================================== -Node * -DT__AddChild(Node *parent, const char *name) +Node *DT__AddChild(Node *parent, const char *name) { Node *node; @@ -206,8 +204,7 @@ //============================================================================== -void -DT__FreeProperty(Property *prop) +void DT__FreeProperty(Property *prop) { prop->next = freeProperties; freeProperties = prop; @@ -215,8 +212,7 @@ //============================================================================== -void -DT__FreeNode(Node *node) +void DT__FreeNode(Node *node) { node->next = freeNodes; freeNodes = node; @@ -224,8 +220,7 @@ //============================================================================== -void -DT__Initialize(void) +void DT__Initialize(void) { DPRINTF("DT__Initialize\n"); @@ -246,8 +241,7 @@ /* * Free up memory used by in-memory representation of device tree. */ -void -DT__Finalize(void) +void DT__Finalize(void) { Node *node; Property *prop; @@ -280,8 +274,7 @@ //============================================================================== -static void * -FlattenNodes(Node *node, void *buffer) +static void *FlattenNodes(Node *node, void *buffer) { Property *prop; DeviceTreeNode *flatNode; @@ -325,8 +318,7 @@ * To use your own buffer, call with *result = &buffer. */ -void -DT__FlattenDeviceTree(void **buffer_p, uint32_t *length) +void DT__FlattenDeviceTree(void **buffer_p, uint32_t *length) { uint32_t totalSize; void * buf; @@ -378,8 +370,7 @@ //============================================================================== -char * -DT__GetName(Node *node) +char *DT__GetName(Node *node) { Property *prop; @@ -400,8 +391,7 @@ //============================================================================== // Bungo -Property * -DT__GetProperty(Node *node, const char *name) +Property *DT__GetProperty(Node *node, const char *name) { Property *prop; @@ -418,8 +408,7 @@ //============================================================================== -Node * -DT__FindNode(const char *path, bool createIfMissing) +Node *DT__FindNode(const char *path, bool createIfMissing) { Node *node, *child; DTPropertyNameBuf nameBuf; @@ -486,8 +475,7 @@ //============================================================================== -void -DT__PrintNode(Node *node, int level) +void DT__PrintNode(Node *node, int level) { char spaces[10], *cp = spaces; Property *prop; @@ -524,8 +512,7 @@ //============================================================================== -static void -_PrintTree(Node *node, int level) +static void _PrintTree(Node *node, int level) { DT__PrintNode(node, level); @@ -539,8 +526,7 @@ //============================================================================== -void -DT__PrintTree(Node *node) +void DT__PrintTree(Node *node) { if (node == 0) node = rootNode; _PrintTree(node, 0); @@ -548,8 +534,7 @@ //============================================================================== -void -DT__PrintFlattenedNode(DTEntry entry, int level) +void DT__PrintFlattenedNode(DTEntry entry, int level) { char spaces[10], *cp = spaces; DTPropertyIterator propIter; @@ -580,8 +565,7 @@ //============================================================================== -static void -_PrintFlattenedTree(DTEntry entry, int level) +static void _PrintFlattenedTree(DTEntry entry, int level) { DTEntryIterator entryIter; @@ -602,16 +586,14 @@ //============================================================================== -void -DT__PrintFlattenedTree(DTEntry entry) +void DT__PrintFlattenedTree(DTEntry entry) { _PrintFlattenedTree(entry, 0); } //============================================================================== -int -main(int argc, char **argv) +int main(int argc, char **argv) { DTEntry dtEntry; DTPropertyIterator propIter; Index: branches/ErmaC/Enoch/i386/libsaio/hfs.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/hfs.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/hfs.c (revision 2587) @@ -295,7 +295,7 @@ char entry[512]; char devStr[12]; u_int32_t dirID; - long result, flags; + long result, flags = 0; if (HFSInitPartition(ih) == -1) { @@ -647,6 +647,8 @@ *flags = kFileTypeUnknown; tmpTime = 0; break; + default: + break; } if (time != 0) @@ -920,6 +922,12 @@ curNode = SWAP_BE32(gBTHeaders[btree]->rootNode); nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize); nodeBuf = (char *)malloc(nodeSize); + + if (!nodeBuf) + { + return -1; + } + node = (BTNodeDescriptor *)nodeBuf; while (1) @@ -992,7 +1000,7 @@ } // Return error if the file was not found. - if (result != 0) + if (result != 0 || !recordData) { free(nodeBuf); return -1; @@ -1018,6 +1026,8 @@ break; case kHFSPlusFileThreadRecord : entrySize = 264; break; + default: + break; } } else Index: branches/ErmaC/Enoch/i386/libsaio/spd.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/spd.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/spd.c (revision 2587) @@ -126,7 +126,7 @@ #define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x) /** Read from spd *used* values only*/ -static void init_spd(char * spd, uint32_t base, int slot) +static void init_spd(char *spd, uint32_t base, int slot) { int i; for (i = 0; i < SPD_INDEXES_SIZE; i++) @@ -232,7 +232,7 @@ #define SLST(a) ((uint8_t)(spd[a] & 0x0f)) /* Get DDR3 or DDR2 serial number, 0 most of the times, always return a valid ptr */ -const char *getDDRSerial(const char* spd) +const char *getDDRSerial(const char *spd) { static char asciiSerial[17]; Index: branches/ErmaC/Enoch/i386/libsaio/networking.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/networking.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/networking.c (revision 2587) @@ -22,29 +22,33 @@ #define DBG(x...) #endif -uint32_t builtin_set = 0; +uint32_t builtin_set = 0; +uint8_t builtin = 0; extern uint32_t devices_number; //extern uint32_t onboard_number; int devprop_add_network_template(DevPropDevice *device, uint16_t vendor_id) { - uint8_t builtin = 0x00; + builtin = 0; if(device) { - + if((vendor_id != 0x168c) && (builtin_set == 0)) { builtin_set = 1; builtin = 0x01; } - if(!devprop_add_value(device, "device_type", (uint8_t*)"ethernet", 8)) + + if(!devprop_add_value(device, "built-in", (uint8_t *)&builtin, 1)) { return 0; } - if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1)) + + if(!devprop_add_value(device, "device_type", (uint8_t *)"Ethernet Controller", 20)) { return 0; } + devices_number++; return 1; } @@ -111,44 +115,43 @@ static network_device generic_ethernet_cards[] = { - { 0x0000, 0x0000, "Generic Ethernet Controller" }, - { 0x10EC, 0x0000, "Realtek Ethernet Controller" }, - { 0x11AB, 0x0000, "Marvell Ethernet Controller" }, + { 0x0000, 0x0000, "Generic Ethernet Controller" }, + { 0x10EC, 0x0000, "Realtek Ethernet Controller" }, + { 0x11AB, 0x0000, "Marvell Ethernet Controller" }, { 0x1969, 0x0000, "Atheros Ethernet Controller" }, - { 0x8086, 0x0000, "Intel(R) Ethernet Controller" }, + { 0x8086, 0x0000, "Intel(R) Ethernet Controller" }, }; char *get_ethernet_model(uint32_t vendor_id, uint32_t device_id) { - int i = 0; - for( ; i < sizeof(known_ethernet_cards) / sizeof(known_ethernet_cards[0]); i++) - { - if(vendor_id == known_ethernet_cards[i].vendor_id && - device_id == known_ethernet_cards[i].device_id) - { - return known_ethernet_cards[i].model; - } - } - i = 0; - for ( ; i < sizeof(generic_ethernet_cards) / sizeof(generic_ethernet_cards[0]); i++) - { - if (vendor_id == generic_ethernet_cards[i].vendor_id) - { - return generic_ethernet_cards[i].model; - } - } - return generic_ethernet_cards[0].model; + int i = 0; + for( ; i < sizeof(known_ethernet_cards) / sizeof(known_ethernet_cards[0]); i++) + { + if(vendor_id == known_ethernet_cards[i].vendor_id && device_id == known_ethernet_cards[i].device_id) + { + return known_ethernet_cards[i].model; + } + } + i = 0; + for ( ; i < sizeof(generic_ethernet_cards) / sizeof(generic_ethernet_cards[0]); i++) + { + if (vendor_id == generic_ethernet_cards[i].vendor_id) + { + return generic_ethernet_cards[i].model; + } + } + return generic_ethernet_cards[0].model; } void setup_eth_builtin(pci_dt_t *eth_dev) { - char *devicepath = get_pci_dev_path(eth_dev); - char *name_model = NULL; - - DevPropDevice *device = (DevPropDevice*)malloc(sizeof(DevPropDevice)); - + char *devicepath = get_pci_dev_path(eth_dev); + char *name_model = NULL; + + DevPropDevice *device = (DevPropDevice *)malloc(sizeof(DevPropDevice)); + verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath); - + if (!string) { string = devprop_create_string(); @@ -163,14 +166,15 @@ { verbose("Setting up lan keys\n"); name_model = get_ethernet_model(eth_dev->vendor_id, eth_dev->device_id); - + devprop_add_network_template(device, eth_dev->vendor_id); - devprop_add_value(device, "model", (uint8_t*)name_model, (strlen(name_model) + 1)); - devprop_add_value(device, "device_type", (uint8_t*)"ethernet", 9); + devprop_add_value(device, "model", (uint8_t *)name_model, (strlen(name_model) + 1)); + devprop_add_value(device, "device_type", (uint8_t *)"Ethernet Controller", 20); + stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length); if(stringdata) { - memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length); + memcpy(stringdata, (uint8_t *)devprop_generate_string(string), string->length); stringlength = string->length; } } @@ -197,12 +201,12 @@ void setup_wifi_airport(pci_dt_t *wlan_dev) // ARPT { char tmp[16]; - uint8_t BuiltIn = 0x00; + builtin = 0; DevPropDevice *device ; char *devicepath = get_pci_dev_path(wlan_dev); - + verbose("Wifi Controller [%04x:%04x]\n", wlan_dev->vendor_id, wlan_dev->device_id); - + if (!string) { string = devprop_create_string(); @@ -215,28 +219,28 @@ device = devprop_add_device(string, devicepath); if(device) { - //sprintf(tmp, sizeof(tmp),"Airport"); - sprintf(tmp, "AirPort"); + snprintf(tmp, sizeof(tmp),"Airport"); devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1); devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1); - devprop_add_value(device, "built-in", (uint8_t *)&BuiltIn, 1); - - int i = 0; + devprop_add_value(device, "built-in", (uint8_t *)&builtin, 1); + + unsigned int i = 0; for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++) { if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id && wlan_dev->device_id == known_wifi_cards[i].device_id) { verbose("Setting up wifi keys\n"); - devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1)); + + devprop_add_value(device, "model", (uint8_t *)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1)); // NOTE: I would set the subsystem id and subsystem vendor id here, // however, those values seem to be ovverriden in the boot process. // A better method would be injecting the DTGP dsdt method // and then injecting the subsystem id there. - stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length); + stringdata = (uint8_t *)malloc(sizeof(uint8_t) *string->length); if(stringdata) { - memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length); + memcpy(stringdata, (uint8_t *)devprop_generate_string(string), string->length); stringlength = string->length; } return; Index: branches/ErmaC/Enoch/i386/libsaio/gma.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/gma.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/gma.c (revision 2587) @@ -630,11 +630,11 @@ case GMA_HASWELL_ULT_M_GT2: // 0a16 case GMA_HASWELL_ULT_E_GT2: // 0a1e verbose("Injecting a valid desktop GPU device id (0x0412) instead of patching kexts.\n"); - device_id = 0x0412; // Inject a valid desktop GPU device id (0x0412) instead of patching kexts + device_id = 0x00000412; // Inject a valid desktop GPU device id (0x0412) instead of patching kexts devprop_add_value(device, "vendor-id", (uint8_t *)INTEL_VENDORID, 4); devprop_add_value(device, "device-id", (uint8_t *)&device_id, sizeof(device_id)); devprop_add_value(device, "compatible", (uint8_t *)"pci8086,0412", 13); // GT2 Desktop - devprop_add_value(device, "IOName", (uint8_t *)"pci8086,0412", 13); // GT2 Desktop +// devprop_add_value(device, "IOName", (uint8_t *)"pci8086,0412", 13); // GT2 Desktop devprop_add_value(device, "name", (uint8_t *)"pci8086,0412", 13); // GT2 Desktop verbose("Injeting done: was [%04x:%04x] now is [%04x:%04x]\n", gma_dev->vendor_id, gma_dev->device_id, gma_dev->vendor_id, device_id); Index: branches/ErmaC/Enoch/i386/libsaio/pci_root.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/pci_root.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/pci_root.c (revision 2587) @@ -49,7 +49,7 @@ void *new_dsdt; const char *val; - int len,fsize; + int len, fsize; const char * dsdt_filename = NULL; extern int search_and_get_acpi_fd(const char *, const char **); Index: branches/ErmaC/Enoch/i386/libsaio/nvidia.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/nvidia.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/nvidia.c (revision 2587) @@ -2322,11 +2322,11 @@ devprop_add_nvidia_template(device); devprop_add_value(device, "NVCAP", default_NVCAP, NVCAP_LEN); devprop_add_value(device, "NVPM", default_NVPM, NVPM_LEN); - devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&videoRam, 4); - devprop_add_value(device, "model", (uint8_t*)model, strlen(model) + 1); - devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, strlen(biosVersion) + 1); - devprop_add_value(device, "@0,display-cfg", default_dcfg_0, DCFG0_LEN); - devprop_add_value(device, "@1,display-cfg", default_dcfg_1, DCFG1_LEN); + devprop_add_value(device, "VRAM,totalsize", (uint8_t *)&videoRam, 4); + devprop_add_value(device, "model", (uint8_t *)model, strlen(model) + 1); + devprop_add_value(device, "rom-revision", (uint8_t *)biosVersion, strlen(biosVersion) + 1); + devprop_add_value(device, "@0,display-cfg", (uint8_t *)&default_dcfg_0, DCFG0_LEN); + devprop_add_value(device, "@1,display-cfg", (uint8_t *)&default_dcfg_1, DCFG1_LEN); /******************** Added Marchrius.**********************/ // For the AppleBacklightDisplay // Index: branches/ErmaC/Enoch/i386/libsaio/ati.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/ati.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/ati.c (revision 2587) @@ -68,7 +68,7 @@ {"Ipomoea", 3}, {"Muskgrass", 4}, {"Juncus", 4}, - {"Osmunda", 4}, + {"Osmunda", 4}, {"Pondweed", 3}, {"Spikerush", 4}, {"Typha", 5}, @@ -835,24 +835,27 @@ { static uint32_t v = 0; - if (v) { + if (v) + { return false; } - if (!card->posted) { + if (!card->posted) + { return false; } v = 1; val->type = kCst; val->size = 4; val->data = (uint8_t *)&v; - + return true; } bool get_dual_link_val(value_t *val) { bool doit = false; - if(getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit) { + if(getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit) + { uint8_t AAPL00_value[] = {0x01, 0x00, 0x00, 0x00}; val->type = kStr; val->size = strlen("AAPL00,DualLink") + 1; @@ -865,7 +868,8 @@ bool get_hdmiaudio(value_t * val) { bool doit = false; - if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit) { + if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit) + { val->type = kStr; val->size = strlen("onboard-1") + 1; val->data = (uint8_t *)"onboard-1"; @@ -1420,11 +1424,12 @@ } #endif +static char name[24]; +static char name_parent[24]; + static bool init_card(pci_dt_t *pci_dev) { bool add_vbios = true; - char name[24]; - char name_parent[24]; int i; int n_ports = 0; Index: branches/ErmaC/Enoch/i386/libsaio/load.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/load.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/load.c (revision 2587) @@ -57,17 +57,20 @@ struct fat_arch *fap = (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header)); cpu_type_t fapcputype; uint32_t fapoffset; - uint32_t fapsize; + uint32_t fapsize; if (fhp->magic == FAT_MAGIC)/* 0xcafebabe */ { nfat = fhp->nfat_arch; swapped = 0; - } else if (fhp->magic == FAT_CIGAM)/* 0xbebafeca */ + } + else if (fhp->magic == FAT_CIGAM)/* 0xbebafeca */ { nfat = OSSwapInt32(fhp->nfat_arch); swapped = 1; - } else { + } + else + { return -1; } @@ -78,7 +81,9 @@ fapcputype = OSSwapInt32(fap->cputype); fapoffset = OSSwapInt32(fap->offset); fapsize = OSSwapInt32(fap->size); - } else { + } + else + { fapcputype = fap->cputype; fapoffset = fap->offset; fapsize = fap->size; @@ -258,12 +263,14 @@ segname = segCmd->segname; #ifdef DEBUG - printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", - segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, - (unsigned) segCmd->nsects, (unsigned)segCmd->flags); - getchar(); + printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", + segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, + (unsigned) segCmd->nsects, (unsigned)segCmd->flags); + getchar(); #endif - } else { + } + else + { struct segment_command *segCmd; segCmd = (struct segment_command *)cmdBase; @@ -276,7 +283,7 @@ #ifdef DEBUG printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", - segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags); + segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags); getchar(); #endif } @@ -289,21 +296,25 @@ } if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) || - (vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) { + (vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) + { stop("Kernel overflows available space"); } - if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) { + if (vmsize && ((strncmp(segname, "__PRELINK_INFO", sizeof("__PRELINK_INFO")) == 0) || (strncmp(segname, "__PRELINK", sizeof("__PRELINK")) == 0))) + { gHaveKernelCache = true; } // Copy from file load area. - if (vmsize>0 && filesize > 0) { + if (vmsize>0 && filesize > 0) + { bcopy((char *)fileaddr, (char *)vmaddr, vmsize > filesize ? filesize : vmsize); } // Zero space at the end of the segment. - if (vmsize > filesize) { + if (vmsize > filesize) + { bzero((char *)(vmaddr + filesize), vmsize - filesize); } @@ -317,7 +328,8 @@ static long DecodeUnixThread(long cmdBase, unsigned int *entry) { - switch (archCpuType) { + switch (archCpuType) + { case CPU_TYPE_I386: { i386_thread_state_t *i386ThreadState; @@ -355,8 +367,8 @@ symTab = (struct symtab_command *)cmdBase; #if DEBUG - - printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize); + printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", + symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize); getchar(); #endif Index: branches/ErmaC/Enoch/i386/libsaio/disk.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/disk.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/disk.c (revision 2587) @@ -263,7 +263,7 @@ return errname; } - sprintf(errorstr, "Error 0x%02x", errnum); + snprintf(errorstr, sizeof(errorstr), "Error 0x%02x", errnum); return errorstr; // No string, print error code only } @@ -844,7 +844,7 @@ // same as Apple ZFS //EFI_GUID const GPT_ZFS_GUID = { 0x6A898CC3, 0x1DD2, 0x11B2, { 0x99, 0xA6, 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }; // 0xBF01 "Solaris /usr & Apple ZFS -BVRef newGPTBVRef( int biosdev, +static BVRef newGPTBVRef( int biosdev, int partno, unsigned int blkoff, const gpt_ent *part, @@ -975,7 +975,13 @@ { // Create a new mapping. - map = (struct DiskBVMap *)malloc(sizeof(*map)); + map = (struct DiskBVMap *) malloc(sizeof(*map)); + + if ( !map ) + { + return NULL; + } + if ( map ) { map->biosdev = biosdev; @@ -1325,7 +1331,7 @@ dpme.dpme_boot_block); */ - if (strcmp(dpme_p->dpme_type, "Apple_HFS") == 0) + if (strncmp(dpme_p->dpme_type, "Apple_HFS",sizeof("Apple_HFS")) == 0) { bvr = newAPMBVRef(biosdev, i, @@ -1430,7 +1436,7 @@ // Determine whether the partition header signature is present. - if (memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG))) + if ( memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)) ) { goto scanErr; } @@ -1493,6 +1499,8 @@ goto scanErr; } + bzero(buffer,bufferSize); + if (readBytes(biosdev, gptBlock, 0, bufferSize, buffer) != 0) { goto scanErr; @@ -1717,7 +1725,7 @@ if (!valid) { // OS X Standard - sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/SystemVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no); + snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/System/Library/CoreServices/SystemVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no); if (!loadConfigFile(dirSpec, &systemVersion)) { @@ -1727,7 +1735,7 @@ else { // OS X Server - sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/ServerVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no); + snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/System/Library/CoreServices/ServerVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no); if (!loadConfigFile(dirSpec, &systemVersion)) { @@ -1736,7 +1744,7 @@ } /* else { - sprintf(dirSpec, "hd(%d,%d)/.IAProductInfo", BIOS_DEV_UNIT(bvr), bvr->part_no); + snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/.IAProductInfo", BIOS_DEV_UNIT(bvr), bvr->part_no); if (!loadConfigFile(dirSpec, &systemVersion)) { @@ -1776,7 +1784,7 @@ if(!valid) { int fh = -1; - sprintf(dirSpec, "hd(%d,%d)/.PhysicalMediaInstall", BIOS_DEV_UNIT(bvr), bvr->part_no); + snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/.PhysicalMediaInstall", BIOS_DEV_UNIT(bvr), bvr->part_no); fh = open(dirSpec, 0); if (fh >= 0) @@ -1788,7 +1796,7 @@ } else { - sprintf(dirSpec, "hd(%d,%d)/.IAPhysicalMedia", BIOS_DEV_UNIT(bvr), bvr->part_no); + snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/.IAPhysicalMedia", BIOS_DEV_UNIT(bvr), bvr->part_no); fh = open(dirSpec, 0); if (fh >= 0) @@ -1828,12 +1836,14 @@ // if (bvr->flags & kBVFlagBooter) { - sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no); - strcpy(fileSpec, ".disk_label.contentDetails"); + snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no); + strlcpy(fileSpec, ".disk_label.contentDetails", sizeof(fileSpec)); ret = GetFileInfo(dirSpec, fileSpec, &flags, &time); if (!ret) { - fh = open(strcat(dirSpec, fileSpec), 0); + strlcat(dirSpec, fileSpec, sizeof(dirSpec)); + fh = open(dirSpec,0); + fileSize = file_size(fh); if (fileSize > 0 && fileSize < BVSTRLEN) { @@ -1852,7 +1862,7 @@ if (!error) { label[fileSize] = '\0'; - strcpy(bvr->altlabel, label); + strlcpy(bvr->altlabel, label, sizeof(bvr->altlabel)); } } } @@ -2183,7 +2193,7 @@ } // Try to match hd(x,y) first. - sprintf(testStr, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no); + snprintf(testStr, sizeof(testStr),"hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no); if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) ) { return true; @@ -2218,7 +2228,7 @@ * hd(x,y)|uuid|"label" "alias";hd(m,n)|uuid|"label" "alias"; etc... */ -bool getVolumeLabelAlias(BVRef bvr, char* str, long strMaxLen) +static bool getVolumeLabelAlias(BVRef bvr, char* str, long strMaxLen) { char *aliasList, *entryStart, *entryNext; @@ -2328,7 +2338,7 @@ if (name == NULL) { - sprintf(p, "TYPE %02X", type); + snprintf(p, strMaxLen, "TYPE %02X", type); } else { @@ -2337,7 +2347,7 @@ } // Set the devices label - sprintf(bvr->label, p); + snprintf(bvr->label, sizeof(bvr->label), p); } Index: branches/ErmaC/Enoch/i386/libsaio/pci_setup.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/pci_setup.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/pci_setup.c (revision 2587) @@ -4,6 +4,16 @@ #include "pci.h" #include "modules.h" +#ifndef DEBUG_PCI_SETUP +#define DEBUG_PCI_SETUP 0 +#endif + +#if DEBUG_PCI_SETUP +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + extern bool setup_ati_devprop(pci_dt_t *ati_dev); extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev); extern bool setup_gma_devprop(pci_dt_t *gma_dev); @@ -35,15 +45,15 @@ switch (current->class_id) { case PCI_CLASS_BRIDGE_HOST: - //DBG("Setup BRIDGE_HOST \n"); + DBG("Setup BRIDGE_HOST \n"); if (current->dev.addr == PCIADDR(0, 0, 0)) { dram_controller_dev = current; } break; // PCI_CLASS_BRIDGE_HOST - - case PCI_CLASS_NETWORK_ETHERNET: - //DBG("Setup ETHERNET %s enabled\n", do_eth_devprop?"":"no"); + + case PCI_CLASS_NETWORK_ETHERNET: + DBG("Setup ETHERNET %s enabled\n", do_eth_devprop? "is":"is not"); if (do_eth_devprop) { setup_eth_builtin(current); @@ -51,7 +61,7 @@ break; // PCI_CLASS_NETWORK_ETHERNET case PCI_CLASS_NETWORK_OTHER: - //DBG("Setup WIRELESS %s enabled\n", do_wifi_devprop?"":"no"); + DBG("Setup WIRELESS %s enabled\n", do_wifi_devprop? "is":"is not"); if (do_wifi_devprop) { setup_wifi_airport(current); @@ -59,7 +69,7 @@ break; // PCI_CLASS_NETWORK_OTHER case PCI_CLASS_DISPLAY_VGA: - //DBG("GraphicsEnabler %s enabled\n", do_gfx_devprop?"":"no"); + DBG("GraphicsEnabler %s enabled\n", do_gfx_devprop? "is":"is not"); if (do_gfx_devprop) { switch (current->vendor_id) @@ -104,7 +114,7 @@ break; // PCI_CLASS_DISPLAY_VGA case PCI_CLASS_MULTIMEDIA_AUDIO_DEV: - //DBG("Setup HDEF %s enabled\n", do_hda_devprop?"":"no"); + DBG("Setup HDEF %s enabled\n", do_hda_devprop? "is":"is not"); if (do_hda_devprop) { setup_hda_devprop(current); @@ -112,16 +122,16 @@ break; // PCI_CLASS_MULTIMEDIA_AUDIO_DEV case PCI_CLASS_SERIAL_USB: - //DBG("USB fix \n"); + DBG("USB\n"); notify_usb_dev(current); - /*if (do_usb_devprop) + /*if (do_usb_devprop) { set_usb_devprop(current); }*/ break; // PCI_CLASS_SERIAL_USB case PCI_CLASS_BRIDGE_ISA: - //DBG("Force HPET %s enabled\n", do_enable_hpet?"":"no"); + DBG("Force HPET %s enabled\n", do_enable_hpet? "is":"is not"); if (do_enable_hpet) { force_enable_hpet(current); @@ -131,7 +141,7 @@ } execute_hook("PCIDevice", current, NULL, NULL, NULL); - //DBG("setup_pci_devs current devID=%08x\n", current->device_id); + DBG("setup_pci_devs current device ID = [%04x:%04x]\n", current->vendor_id, current->device_id); setup_pci_devs(current->children); current = current->next; } Index: branches/ErmaC/Enoch/i386/libsaio/smbios.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios.h (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/smbios.h (revision 2587) @@ -833,7 +833,7 @@ typedef struct SMBOemProcessorBusSpeed { SMB_STRUCT_HEADER // Type 132 - SMBWord ProcessorBusSpeed; // MT/s unit + SMBWord ProcessorBusSpeed; // MT/s unit } __attribute__((packed)) SMBOemProcessorBusSpeed; //---------------------------------------------------------------------------------------------------------- Index: branches/ErmaC/Enoch/i386/libsaio/nvidia_helper.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/nvidia_helper.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/nvidia_helper.c (revision 2587) @@ -52,28 +52,28 @@ */ -cardList_t* cardList = NULL; +cardList_t *cardList = NULL; -void add_card(char* model, uint32_t id, uint32_t subid, uint64_t videoRam) +void add_card(char *model, uint32_t id, uint32_t subid, uint64_t videoRam) { - cardList_t* new_card = malloc(sizeof(cardList_t)); + cardList_t *new_card = malloc(sizeof(cardList_t)); if (new_card) { new_card->next = cardList; cardList = new_card; - new_card->id = id; - new_card->subid = subid; - new_card->videoRam = videoRam; - new_card->model = model; + new_card->id = id; + new_card->subid = subid; + new_card->videoRam = videoRam; + new_card->model = model; } } -cardList_t* FindCardWithIds(uint32_t id, uint32_t subid) +cardList_t *FindCardWithIds(uint32_t id, uint32_t subid) { - cardList_t* entry = cardList; + cardList_t *entry = cardList; while(entry) { if((entry->id == id) && (entry->subid == subid)) @@ -108,12 +108,16 @@ void fill_card_list(void) { unsigned int i, count; - TagPtr NVDIATag; - char *model_name = NULL, *match_id = NULL, *sub_id = NULL, *vram_size = NULL; - uint32_t dev_id = 0, subdev_id = 0; - uint64_t VramSize = 0; + TagPtr NVDIATag; + char *model_name = NULL; + char *match_id = NULL; + char *sub_id = NULL; + char *vram_size = NULL; + uint32_t dev_id = 0; + uint32_t subdev_id = 0; + uint64_t VramSize = 0; - if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"NVIDIA")))) + if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char *)"NVIDIA")))) { count = XMLTagCount(NVDIATag); @@ -127,15 +131,18 @@ model_name = XMLCastString(XMLGetProperty(element, (const char*)"Chipset Name")); vram_size = XMLCastString(XMLGetProperty(element, (const char*)"VRam Size")); - if (match_id) { + if (match_id) + { dev_id = strtoul(match_id, NULL, 16); } - if (sub_id) { + if (sub_id) + { subdev_id = strtoul(sub_id, NULL, 16); } - if (vram_size) { + if (vram_size) + { VramSize = strtoul(vram_size, NULL, 10); } Index: branches/ErmaC/Enoch/i386/libsaio/pci.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/pci.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/pci.c (revision 2587) @@ -14,9 +14,9 @@ #endif #if DEBUG_PCI -#define DBG(x...) printf(x) +#define DBG(x...) printf(x) #else -#define DBG(x...) +#define DBG(x...) msglog(x) #endif pci_dt_t *root_pci_dev; @@ -213,7 +213,7 @@ while (current) { printf("%02x:%02x.%x [%04x%02x] [%04x:%04x] (subsys [%04x:%04x]):: %s\n", current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func, - current->class_id, 0 /* FIXME: what should this be? */, + current->class_id, current->progif, current->vendor_id, current->device_id, current->subsys_id.subsys.vendor_id, current->subsys_id.subsys.device_id, get_pci_dev_path(current)); Index: branches/ErmaC/Enoch/i386/libsaio/msdos.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/msdos.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/msdos.c (revision 2587) @@ -807,7 +807,7 @@ } // Calculate a fake timestamp using modification date and time values. - *time = (dirp->deMDate & 0x7FFF) << (16 + dirp->deMTime); + *time = (dirp->deMDate & 0x7FFF) << (16 + dirp->deMTime); if (infoValid) { Index: branches/ErmaC/Enoch/i386/libsaio/md5c.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/md5c.c (revision 2586) +++ branches/ErmaC/Enoch/i386/libsaio/md5c.c (revision 2587) @@ -166,11 +166,14 @@ partLen); MD5Transform (context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) { + for (i = partLen; i + 63 < inputLen; i += 64) + { MD5Transform (context->state, &((const unsigned char *)input)[i]); } index = 0; - } else { + } + else + { i = 0; } Index: branches/ErmaC/Enoch/i386/boot2/graphics.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/graphics.c (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/graphics.c (revision 2587) @@ -1120,8 +1120,8 @@ unsigned long numbers[], unsigned long maxArrayCount ) { - char *propStr; - unsigned long count = 0; + char *propStr; + unsigned long count = 0; propStr = newStringForKey((char *)propKey , &bootInfo->chameleonConfig); Index: branches/ErmaC/Enoch/i386/boot2/drivers.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/drivers.c (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/drivers.c (revision 2587) @@ -740,11 +740,12 @@ //========================================================================== // MatchLibraries -static long -MatchLibraries( void ) +static long MatchLibraries( void ) { - TagPtr prop, prop2; - ModulePtr module, module2; + TagPtr prop; + TagPtr prop2; + ModulePtr module; + ModulePtr module2; long done; do { @@ -798,8 +799,7 @@ // FindModule #if NOTDEF -static ModulePtr -FindModule( char * name ) +static ModulePtr FindModule( char *name ) { ModulePtr module; TagPtr prop; @@ -825,15 +825,14 @@ //========================================================================== // ParseXML -static long -ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities ) +static long ParseXML( char *buffer, ModulePtr *module, TagPtr *personalities ) { - long length, pos; - TagPtr moduleDict, required; - ModulePtr tmpModule; - - pos = 0; - + long length; + long pos = 0; + TagPtr moduleDict; + TagPtr required; + ModulePtr tmpModule; + while (1) { length = XMLParseNextTag(buffer + pos, &moduleDict); Index: branches/ErmaC/Enoch/i386/boot2/mboot.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/mboot.c (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/mboot.c (revision 2587) @@ -290,8 +290,8 @@ continue_at_low_address(); // Now fix our return address. - // JrCs: this macro should be rewritten because the code generated by XCode 4.x - // change the value of the argument passed as parameter (multiboot_magic) + // JrCs: this macro should be rewritten because the code generated by XCode 4.x + // change the value of the argument passed as parameter (multiboot_magic) // FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic); // We can now do just about anything, including return to our caller correctly. @@ -404,7 +404,7 @@ else doSelectDevice = true; } - + if(getValueForBootKey(mi->mi_cmdline, "timeout", &val, &size)) { char *endptr; @@ -415,8 +415,8 @@ multiboot_timeout = intVal; multiboot_timeout_set = 1; } - } - + } + if(getValueForBootKey(mi->mi_cmdline, "partno", &val, &size)) { char *endptr; Index: branches/ErmaC/Enoch/i386/boot2/lzvn.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/lzvn.c (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/lzvn.c (revision 2587) @@ -57,9 +57,9 @@ } while (0) -size_t lzvn_decode(void * dst, +size_t lzvn_decode(void *dst, size_t dst_size, - const void * src, + const void *src, size_t src_size) { size_t rax = 0; Index: branches/ErmaC/Enoch/i386/boot2/Makefile =================================================================== --- branches/ErmaC/Enoch/i386/boot2/Makefile (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/Makefile (revision 2587) @@ -42,9 +42,14 @@ # The ordering is important; # boot2.o must be first. -OBJS = boot2.o boot.o graphics.o drivers.o prompt.o options.o lzss.o lzvn.o mboot.o \ - ramdisk.o picopng.o resume.o bmdecompress.o graphic_utils.o gui.o modules.o \ - modules_support.o boot_modules.o +OBJS = boot2.o boot.o graphics.o \ + drivers.o prompt.o options.o \ + lzss.o lzvn.o mboot.o \ + ramdisk.o \ + picopng.o resume.o \ + bmdecompress.o graphic_utils.o gui.o \ + modules.o \ + modules_support.o boot_modules.o # button.o browser.o scrollbar.o == NOTYET OBJS := $(addprefix $(OBJROOT)/, $(OBJS)) Index: branches/ErmaC/Enoch/i386/boot2/modules.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/modules.c (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/modules.c (revision 2587) @@ -25,8 +25,8 @@ #define DBGPAUSE() #endif -static inline void rebase_location(UInt32* location, char* base, int type); -static inline void bind_location(UInt32* location, char* value, UInt32 addend, int type); +static inline void rebase_location(UInt32 *location, char *base, int type); +static inline void bind_location(UInt32 *location, char *value, UInt32 addend, int type); // NOTE: Global so that modules can link with this static UInt64 textAddress = 0; @@ -118,7 +118,7 @@ last = mod->mm_string; } - char* name = strdup(last); + char *name = strdup(last); name[strlen(last) - sizeof("dylib")] = 0; DBG("Loading multiboot module %s\n", name); @@ -271,7 +271,7 @@ * adjust it's internal symbol list (sort) to optimize locating new symbols * NOTE: returns the address if the symbol is "start", else returns 0xFFFFFFFF */ -long long add_symbol(char* symbol, long long addr, char is64) +long long add_symbol(char *symbol, long long addr, char is64) { // This only can handle 32bit symbols symbolList_t* entry; @@ -300,7 +300,7 @@ */ void module_loaded(const char* name, void* start, const char* author, const char* description, UInt32 version, UInt32 compat) { - moduleList_t* new_entry = malloc(sizeof(moduleList_t)); + moduleList_t *new_entry = malloc(sizeof(moduleList_t)); new_entry->next = loadedModules; loadedModules = new_entry; @@ -1229,9 +1229,9 @@ return 0; } -void start_built_in_module(const char* name, - const char* author, - const char* description, +void start_built_in_module(const char *name, + const char *author, + const char *description, UInt32 version, UInt32 compat, void(*start_function)(void)) Index: branches/ErmaC/Enoch/i386/boot2/modules.h =================================================================== --- branches/ErmaC/Enoch/i386/boot2/modules.h (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/modules.h (revision 2587) @@ -34,14 +34,14 @@ typedef struct callbackList_t { void(*callback)(void*, void*, void*, void*); - struct callbackList_t* next; + struct callbackList_t *next; } callbackList_t; typedef struct moduleHook_t { - const char* name; - callbackList_t* callbacks; - struct moduleHook_t* next; + const char *name; + callbackList_t *callbacks; + struct moduleHook_t *next; } moduleHook_t; typedef struct modulesList_t @@ -68,7 +68,7 @@ int load_module(char* module); int is_module_loaded(const char* name); -void module_loaded(const char* name, void* start, const char* author, const char* description, UInt32 version, UInt32 compat); +void module_loaded(const char *name, void *start, const char *author, const char *description, UInt32 version, UInt32 compat); @@ -76,35 +76,35 @@ /********************************************************************************/ /* Symbol Functions */ /********************************************************************************/ -long long add_symbol(char* symbol, long long addr, char is64); -unsigned int lookup_all_symbols(const char* name); +long long add_symbol(char *symbol, long long addr, char is64); +unsigned int lookup_all_symbols(const char *name); /********************************************************************************/ /* Macho Parser */ /********************************************************************************/ -void* parse_mach(void* binary, +void* parse_mach(void *binary, int(*dylib_loader)(char*), long long(*symbol_handler)(char*, long long, char), - void (*section_handler)(char* section, char* segment, void* cmd, UInt64 offset, UInt64 address) + void (*section_handler)(char *section, char *segment, void *cmd, UInt64 offset, UInt64 address) ); unsigned int handle_symtable(UInt32 base, - struct symtab_command* symtabCommand, + struct symtab_command *symtabCommand, long long(*symbol_handler)(char*, long long, char), char is64); -void rebase_macho(void* base, char* rebase_stream, UInt32 size); +void rebase_macho(void *base, char *rebase_stream, UInt32 size); -void bind_macho(void* base, UInt8* bind_stream, UInt32 size); +void bind_macho(void *base, UInt8 *bind_stream, UInt32 size); /********************************************************************************/ /* Module Interface */ /********************************************************************************/ -int replace_function(const char* symbol, void* newAddress); -int execute_hook(const char* name, void*, void*, void*, void*); -void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*)); -moduleHook_t* hook_exists(const char* name); +int replace_function(const char *symbol, void *newAddress); +int execute_hook(const char *name, void*, void*, void*, void*); +void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*)); +moduleHook_t *hook_exists(const char* name); #if DEBUG_MODULES void print_hook_list(); Index: branches/ErmaC/Enoch/i386/boot2/gui.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/gui.c (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/gui.c (revision 2587) @@ -13,6 +13,16 @@ #include "appleboot.h" #include "vers.h" +#ifndef DEBUG_GUI +#define DEBUG_GUI 0 +#endif + +#if DEBUG_GUI +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + #define IMG_REQUIRED -1 #define THEME_NAME_DEFAULT "Default" static const char *theme_name = THEME_NAME_DEFAULT; @@ -483,6 +493,8 @@ initFont( &font_console, &images[iFontConsole]); initFont( &font_small, &images[iFontSmall]); +// DBG("Graphic objects successfully loaded !!\n",theme_name); + return 0; } @@ -551,13 +563,18 @@ int createBackBuffer( window_t *window ) { gui.backbuffer = malloc(sizeof(pixmap_t)); - if(!gui.backbuffer) { + if(!gui.backbuffer) + { +// DBG("Unable to allocate memory for gui.backbuffer"); return 1; } + gui.backbuffer->pixels = malloc( window->width * window->height * 4 ); - if(!gui.backbuffer->pixels) { + if(!gui.backbuffer->pixels) + { free(gui.backbuffer); gui.backbuffer = 0; +// DBG("Unable to allocate memory for gui.backbuffer->pixels"); return 1; } @@ -572,14 +589,18 @@ int createWindowBuffer( window_t *window ) { window->pixmap = malloc(sizeof(pixmap_t)); - if(!window->pixmap) { + if(!window->pixmap) + { +// DBG("Unable to allocate memory for window->pixmap"); return 1; } window->pixmap->pixels = malloc( window->width * window->height * 4 ); - if(!window->pixmap->pixels) { + if(!window->pixmap->pixels) + { free(window->pixmap); window->pixmap = 0; +// DBG("Unable to allocate memory for window->pixmap->pixels"); return 1; } @@ -593,11 +614,13 @@ int freeWindowBuffer( window_t *window ) { - if (window->pixmap && window->pixmap->pixels) { + if (window->pixmap && window->pixmap->pixels) + { free(window->pixmap->pixels); free(window->pixmap); return 0; } + return 1; } @@ -647,18 +670,22 @@ int val, len; const char *string; - if(getIntForKey("devices_max_visible", &val, theme )) { + if(getIntForKey("devices_max_visible", &val, theme )) + { gui.maxdevices = MIN( val, gDeviceCount ); } - if(getIntForKey("devices_iconspacing", &val, theme )) { + if(getIntForKey("devices_iconspacing", &val, theme )) + { gui.devicelist.iconspacing = val; } // check layout for horizontal or vertical gui.layout = HorizontalLayout; - if(getValueForKey( "devices_layout", &string, &len, theme)) { - if (!strcmp (string, "vertical")) { + if(getValueForKey( "devices_layout", &string, &len, theme)) + { + if (!strncmp (string, "vertical",sizeof("vertical"))) + { gui.layout = VerticalLayout; } } @@ -783,7 +810,7 @@ gui.countdown.pos.y = pixel; } - /* + /* * Parse devicelist parameters */ setupDeviceList(theme); @@ -934,7 +961,11 @@ return 1; } #else + +// DBG("Unable to load %s theme plist.\n",theme_name); + return 1; + #endif } // parse display size parameters @@ -958,23 +989,32 @@ gui.screen.height = screen_params[1]; // load graphics otherwise fail and return - if (loadGraphics() == 0) { + if (loadGraphics() == 0) + { loadThemeValues(&bootInfo->themeConfig); colorFont(&font_small, gui.screen.font_small_color); colorFont(&font_console, gui.screen.font_console_color); // create the screen & window buffers - if (createBackBuffer(&gui.screen) == 0) { - if (createWindowBuffer(&gui.screen) == 0) { - if (createWindowBuffer(&gui.devicelist) == 0) { - if (createWindowBuffer(&gui.bootprompt) == 0) { - if (createWindowBuffer(&gui.infobox) == 0) { - if (createWindowBuffer(&gui.menu) == 0) { + if (createBackBuffer(&gui.screen) == 0) + { + if (createWindowBuffer(&gui.screen) == 0) + { + if (createWindowBuffer(&gui.devicelist) == 0) + { + if (createWindowBuffer(&gui.bootprompt) == 0) + { + if (createWindowBuffer(&gui.infobox) == 0) + { + if (createWindowBuffer(&gui.menu) == 0) + { gui.logo.draw = true; drawBackground(); // lets copy the screen into the back buffer memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); + setVideoMode( GRAPHICS_MODE, 0 ); + gui.initialised = true; return 0; } @@ -985,15 +1025,17 @@ } } - // not available memory, freeing resources - freeWindowBuffer(&gui.menu); - freeWindowBuffer(&gui.infobox); - freeWindowBuffer(&gui.bootprompt); - freeWindowBuffer(&gui.devicelist); - freeWindowBuffer(&gui.screen); - freeBackBuffer(&gui.screen); - unloadGraphics(); + DBG("Loading error occurred, reseting...\n",theme_name); + // Loading error occurred, freeing resources + freeWindowBuffer(&gui.menu); + freeWindowBuffer(&gui.infobox); + freeWindowBuffer(&gui.bootprompt); + freeWindowBuffer(&gui.devicelist); + freeWindowBuffer(&gui.screen); + freeBackBuffer(&gui.screen); + unloadGraphics(); + return 1; } @@ -1161,7 +1203,8 @@ } // draw visible device icons - for (i = 0; i < gui.maxdevices; i++) { + for (i = 0; i < gui.maxdevices; i++) + { BVRef param = menuItems[start + i].param; bool isSelected = ((start + i) == selection) ? true : false; @@ -1203,10 +1246,12 @@ drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected); - if (gui.layout == HorizontalLayout) { + if (gui.layout == HorizontalLayout) + { p.x += images[iSelection].image->width + gui.devicelist.iconspacing; } - if (gui.layout == VerticalLayout) { + if (gui.layout == VerticalLayout) + { p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); } } @@ -1234,7 +1279,8 @@ //prompt_pos=0; - if( gui.bootprompt.draw == true ) { + if(gui.bootprompt.draw == true ) + { gui.bootprompt.draw = false; gui.redraw = true; // this causes extra frames to be drawn @@ -1276,17 +1322,25 @@ static inline void vramwrite (void *data, int width, int height) { - if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) { + if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) + { memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height)); - } else { - uint32_t r, g, b; + } + else + { + uint32_t r; + uint32_t g; + uint32_t b; int i, j; - for (i = 0; i < VIDEO (height); i++) { - for (j = 0; j < VIDEO (width); j++) { + for (i = 0; i < VIDEO (height); i++) + { + for (j = 0; j < VIDEO (width); j++) + { b = ((uint8_t *) data)[4*i*width + 4*j]; g = ((uint8_t *) data)[4*i*width + 4*j + 1]; r = ((uint8_t *) data)[4*i*width + 4*j + 2]; - switch (VIDEO (depth)) { + switch (VIDEO (depth)) + { case 32: *(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16); break; @@ -1301,6 +1355,8 @@ case 15: *(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7); break; + default: + break; } } } @@ -1311,24 +1367,30 @@ void updateVRAM() { - if (gui.redraw) { - if (gui.devicelist.draw) { + if (gui.redraw) + { + if (gui.devicelist.draw) + { blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos ); } - if (gui.bootprompt.draw) { + if (gui.bootprompt.draw) + { blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos ); } - if (gui.menu.draw) { - blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos ); + if (gui.menu.draw) + { + blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos ); } - if (gui.infobox.draw) { + if (gui.infobox.draw) + { blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos ); } } vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height ); - if (gui.redraw) { + if (gui.redraw) + { memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); gui.redraw = false; } @@ -1347,8 +1409,10 @@ static int sputc(int c, struct putc_info * pi) //Azi: same as above { - if (pi->last_str) { - if (pi->str == pi->last_str) { + if (pi->last_str) + { + if (pi->str == pi->last_str) + { *(pi->str) = '\0'; return 0; } @@ -1364,10 +1428,11 @@ char *formattedtext; va_list ap; - + struct putc_info pi; - if ((formattedtext = malloc(1024)) != NULL) { + if ((formattedtext = malloc(1024)) != NULL) + { // format the text va_start(ap, fmt); pi.str = formattedtext; @@ -1391,42 +1456,49 @@ font_t *font = &font_console; - for( i=0; i< strlen(formattedtext); i++ ) { + for( i=0; i< strlen(formattedtext); i++ ) + { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) { + if( formattedtext[i] == '\n' ) + { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) { + if ( cursor.y > bounds.y ) + { cursor.y = origin.y; } continue; } // tab ? - if( formattedtext[i] == '\t' ) { + if( formattedtext[i] == '\t' ) + { cursor.x += ( font->chars[0]->width * 5 ); } // draw the character - if( font->chars[character]) { + if( font->chars[character]) + { blend(font->chars[character], window->pixmap, cursor); } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) { + if ( cursor.x > bounds.x ) + { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > bounds.y ) { + if ( cursor.y > bounds.y ) + { cursor.y = origin.y; } } @@ -1448,12 +1520,13 @@ char *formattedtext; va_list ap; - + //window = &gui.debug; struct putc_info pi; - - if ((formattedtext = malloc(1024)) != NULL) { + + if ((formattedtext = malloc(1024)) != NULL) + { // format the text va_start(ap, fmt); pi.str = formattedtext; @@ -1463,10 +1536,10 @@ va_end(ap); position_t origin, cursor, bounds; - + int i; int character; - + origin.x = MAX( gui.debug.cursor.x, window->hborder ); origin.y = MAX( gui.debug.cursor.y, window->vborder ); @@ -1477,40 +1550,47 @@ font_t *font = &font_console; - for( i=0; i< strlen(formattedtext); i++ ) { + for( i=0; i< strlen(formattedtext); i++ ) + { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) { + if( formattedtext[i] == '\n' ) + { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) { + if ( cursor.y > bounds.y ) + { cursor.y = origin.y; } continue; } // tab ? - if( formattedtext[i] == '\t' ) { + if( formattedtext[i] == '\t' ) + { cursor.x += ( font->chars[0]->width * 5 ); } // draw the character - if( font->chars[character]) { + if( font->chars[character]) + { blend(font->chars[character], gui.backbuffer, cursor); } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) { + if ( cursor.x > bounds.x ) + { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > bounds.y ) { + if ( cursor.y > bounds.y ) + { cursor.y = origin.y; } } @@ -1540,7 +1620,8 @@ position_t origin, cursor, bounds; font_t *font = &font_console; - if ((formattedtext = malloc(1024)) != NULL) { + if ((formattedtext = malloc(1024)) != NULL) + { // format the text pi.str = formattedtext; pi.last_str = 0; @@ -1553,15 +1634,18 @@ bounds.y = ( window->height - ( window->vborder * 2 ) ); cursor = origin; - for( i=0; i< strlen(formattedtext); i++ ) { + for( i=0; i< strlen(formattedtext) ; i++ ) + { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) { + if( formattedtext[i] == '\n' ) + { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) { + if ( cursor.y > bounds.y ) + { gui.redraw = true; updateVRAM(); cursor.y = window->vborder; @@ -1571,26 +1655,30 @@ } // tab ? - if( formattedtext[i] == '\t' ) { + if( formattedtext[i] == '\t' ) + { cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 ); continue; } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) { + if ( cursor.x > bounds.x ) + { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > ( bounds.y + font->chars[0]->height) ) { + if ( cursor.y > ( bounds.y + font->chars[0]->height) ) + { gui.redraw = true; updateVRAM(); cursor.y = window->vborder; } // draw the character - if( font->chars[character]) { + if( font->chars[character]) + { blend(font->chars[character], gui.backbuffer, cursor); } } @@ -1605,9 +1693,11 @@ // ==================================================================== -pixmap_t* charToPixmap(unsigned char ch, font_t *font) { +pixmap_t *charToPixmap(unsigned char ch, font_t *font) +{ unsigned int cha = (unsigned int)ch - 32; - if (cha >= font->count) { + if (cha >= font->count) + { // return ? if the font for the char doesn't exists cha = '?' - 32; } @@ -1616,12 +1706,16 @@ // ==================================================================== -position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) { +position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) +{ pixmap_t* pm = charToPixmap(ch, font); - if (pm && ((p.x + pm->width) < blendInto->width)) { + if (pm && ((p.x + pm->width) < blendInto->width)) + { blend(pm, blendInto, p); return pos(p.x + pm->width, p.y); - } else { + } + else + { return p; } } @@ -1633,16 +1727,19 @@ int i=0; position_t current_pos = pos(p.x, p.y); - for (i=0; i < strlen(ch); i++) { + for (i=0; i < strlen(ch); i++) + { // newline ? - if ( ch[i] == '\n' ) { + if ( ch[i] == '\n' ) + { current_pos.x = p.x; current_pos.y += font->height; continue; } // tab ? - if ( ch[i] == '\t' ) { + if ( ch[i] == '\t' ) + { current_pos.x += TAB_PIXELS_WIDTH; continue; } @@ -1661,19 +1758,27 @@ int height = font->height; // calculate the width in pixels - for (i=0; i < strlen(text); i++) { - if (text[i] == '\n') { + for (i=0; i < strlen(text); i++) + { + if (text[i] == '\n') + { width = 0; height += font->height; - } else if (text[i] == '\t') { + } + else if (text[i] == '\t') + { width += TAB_PIXELS_WIDTH; - } else { + } + else + { pixmap_t* pm = charToPixmap(text[i], font); - if (pm) { + if (pm) + { width += pm->width; } } - if (width > max_width) { + if (width > max_width) + { max_width = width; } } @@ -1689,9 +1794,12 @@ int destroyFont(font_t *font) { int i; - for (i = 0; i < CHARACTERS_COUNT; i++) { - if (font->chars[i]) { - if (font->chars[i]->pixels) { + for (i = 0; i < CHARACTERS_COUNT; i++) + { + if (font->chars[i]) + { + if (font->chars[i]->pixels) + { free (font->chars[i]->pixels); } free (font->chars[i]); @@ -1713,44 +1821,53 @@ font->height = data->image->height; - for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) { + for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) + { start = end; // if the pixel is red we've reached the end of the char - if( pixel( data->image, x, 0 ).value == 0xFFFF0000) { + if( pixel( data->image, x, 0 ).value == 0xFFFF0000) + { end = x + 1; - if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) { + if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) + { font->chars[count]->width = ( end - start) - 1; font->chars[count]->height = font->height; - - if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) { + + if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) + { space += ( font->chars[count]->width * data->image->height * 4 ); // we skip the first line because there are just the red pixels for the char width - for( y = 1; y< (font->height); y++) { - for( x2 = start, x3 = 0; x2 < end; x2++, x3++) { + for( y = 1; y< (font->height); y++) + { + for( x2 = start, x3 = 0; x2 < end; x2++, x3++) + { pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y ); } } - + // check if font is monospaced - if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) { + if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) + { monospaced = true; } font->width = font->chars[count]->width; - + count++; } } } } - for (x = count; x < CHARACTERS_COUNT; x++) { + for (x = count; x < CHARACTERS_COUNT; x++) + { font->chars[x] = NULL; } - if(monospaced) { + if(monospaced) + { font->width = 0; } @@ -1763,7 +1880,8 @@ void colorFont(font_t *font, uint32_t color) { - if( !color ) { + if( !color ) + { return; } @@ -1771,13 +1889,17 @@ int count = 0; pixel_t *buff; - while( font->chars[count++] ) { + while( font->chars[count++] ) + { width = font->chars[count-1]->width; height = font->chars[count-1]->height; - for( y = 0; y < height; y++ ) { - for( x = 0; x < width; x++ ) { + for( y = 0; y < height; y++ ) + { + for( x = 0; x < width; x++ ) + { buff = &(pixel( font->chars[count-1], x, y )); - if( buff->ch.a ) { + if( buff->ch.a ) + { buff->ch.r = (color & 0xFFFF0000) >> 16; buff->ch.g = (color & 0xFF00FF00) >> 8; buff->ch.b = (color & 0xFF0000FF); @@ -1812,10 +1934,13 @@ uint8_t alpha=0; - for( y=0; y<10; y++) { - for( x=0; x<10; x++) { + for( y=0; y<10; y++) + { + for( x=0; x<10; x++) + { // skip if the pixel should be visible - if(roundedCorner[y][x] != 0xFF) { + if(roundedCorner[y][x] != 0xFF) + { alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 ); // Upper left corner pixel(p, x, y).ch.a = alpha; @@ -1876,23 +2001,32 @@ visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1; // lets display the text and allow scroll thru using up down / arrows - while(1) { + while(1) + { // move to current line in text - for( offset = 0, i = 0; offset < strlen(text); offset++ ) { - if( currentline == i) { + for( offset = 0, i = 0; offset < strlen(text); offset++ ) + { + if( currentline == i) + { break; } - if( text[offset] =='\n') { + + if( text[offset] =='\n') + { i++; } } // find last visible line in text and place \0 - for( i = offset, cnt = 0; i < strlen(text); i++) { - if(text[i]=='\n') { + for( i = offset, cnt = 0; i < strlen(text); i++) + { + if(text[i]=='\n') + { cnt++; } - if ( cnt == visiblelines ) { + + if ( cnt == visiblelines ) + { text[i]='\0'; break; } @@ -1916,12 +2050,14 @@ position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y ); // draw prev indicator - if(offset) { + if(offset) + { blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator )); } // draw next indicator - if( lines > ( currentline + visiblelines ) ) { + if( lines > ( currentline + visiblelines ) ) + { pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) ); blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) ); } @@ -1933,7 +2069,7 @@ updateVRAM(); key = getchar(); - + if( key == KEY_UP ) { if( currentline > 0 ) { currentline--; @@ -1972,7 +2108,8 @@ { int y; - if( time18() > lasttime) { + if( time18() > lasttime) + { lasttime = time18(); pixmap_t *buffBar = images[iProgressBar].image; @@ -1988,7 +2125,6 @@ } } #endif - // ==================================================================== void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress) @@ -2165,6 +2301,8 @@ return buff; } break; + default: + break; } return DO_NOT_BOOT; } @@ -2186,7 +2324,8 @@ char dirspec[256]; - if ((strlen(theme_name) + 24) > sizeof(dirspec)) { + if ((strlen(theme_name) + 24) > sizeof(dirspec)) + { usePngImage = false; return; } Index: branches/ErmaC/Enoch/i386/boot2/graphic_utils.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/graphic_utils.c (revision 2586) +++ branches/ErmaC/Enoch/i386/boot2/graphic_utils.c (revision 2587) @@ -78,7 +78,8 @@ uint32_t x; register uint8_t tempB; - for (x = 0; x < (p->height) * (p->width) ; x++) { + for (x = 0; x < (p->height) * (p->width) ; x++) + { tempB = (p->pixels[x]).ch.b; (p->pixels[x]).ch.b = (p->pixels[x]).ch.r; (p->pixels[x]).ch.r = tempB; Index: branches/ErmaC/Enoch/i386/modules/Resolution/Resolution.c =================================================================== --- branches/ErmaC/Enoch/i386/modules/Resolution/Resolution.c (revision 2586) +++ branches/ErmaC/Enoch/i386/modules/Resolution/Resolution.c (revision 2587) @@ -9,11 +9,11 @@ void Resolution_start(); void Resolution_start() { - UInt32 bp = 0; - UInt32 x, y; + UInt32 bp = 0; + UInt32 x, y; patchVideoBios(); - getResolution(&x, &y, &bp); - gui.screen.width = x; - gui.screen.height = y; + getResolution(&x, &y, &bp); + gui.screen.width = x; + gui.screen.height = y; } Index: branches/ErmaC/Enoch/i386/modules/Keylayout/Keylayout.c =================================================================== --- branches/ErmaC/Enoch/i386/modules/Keylayout/Keylayout.c (revision 2586) +++ branches/ErmaC/Enoch/i386/modules/Keylayout/Keylayout.c (revision 2587) @@ -13,9 +13,20 @@ #include "Keylayout.h" #include "bootstruct.h" +#ifndef DEBUG_KLAYOUT +#define DEBUG_KLAYOUT 0 +#endif + +#if DEBUG_KLAYOUT +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + #define kKeyboardLayout "KeyboardLayout" struct keyboard_layout *current_layout = NULL; +int getchar_replacement(); int getchar_replacement() { int code = bgetc(); @@ -50,46 +61,57 @@ return (code); } -static uint32_t load_keyboard_layout_file(const char *filename) { +static uint32_t load_keyboard_layout_file(const char *filename) +{ int fd; char magic[KEYBOARD_LAYOUTS_MAGIC_SIZE]; uint32_t version; - if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { + if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) + { goto fail; // fail } - if (read(fd, magic, sizeof(magic)) != sizeof(magic)) { + if (read(fd, magic, sizeof(magic)) != sizeof(magic)) + { printf("Can't find magic in keyboard layout file: %s\n", filename); goto fail; } - if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0) { + if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0) + { printf("Invalid magic code in keyboard layout file: %s\n", filename); goto fail; - } + } - if (read(fd, (char*) &version, sizeof(version)) != sizeof(version)) { + if (read(fd, (char*) &version, sizeof(version)) != sizeof(version)) + { printf("Can't get version of keyboard layout file: %s\n", filename); goto fail; } - if (version != KEYBOARD_LAYOUTS_VERSION) { + if (version != KEYBOARD_LAYOUTS_VERSION) + { verbose("Bad version for keyboard layout file %s expected v%d found v%d\n", - filename, KEYBOARD_LAYOUTS_VERSION, version); + filename, KEYBOARD_LAYOUTS_VERSION, version); goto fail; } if (current_layout) + { free(current_layout); - + } + current_layout = malloc(sizeof(*current_layout)); if (!current_layout) + { goto fail; + } b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0); - if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout)) { + if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout)) + { printf("Wrong keyboard layout file %s size\n", filename); goto fail; } @@ -97,10 +119,11 @@ close(fd); return 1; - - fail: + +fail: - if (current_layout) { + if (current_layout) + { free(current_layout); current_layout = NULL; } @@ -113,17 +136,21 @@ const char *val; int len; - if (getValueForKey("KeyLayout", &val, &len, &bootInfo->chameleonConfig)) { - sprintf(layoutPath, "/Extra/Keymaps/%s", val); + if (getValueForKey("KeyLayout", &val, &len, &bootInfo->chameleonConfig)) + { + snprintf(layoutPath, sizeof(layoutPath),"/Extra/Keymaps/%s", val); // Add the extension if needed - if (len <= 4 || strcmp(val+len-4,".lyt") != 0) - strncat(layoutPath, ".lyt", sizeof(layoutPath) - strlen(layoutPath) - 1); + if (len <= 4 || strncmp(val+len-4,".lyt", sizeof(".lyt")) != 0) + strlcat(layoutPath, ".lyt", sizeof(layoutPath)); - if (!load_keyboard_layout_file(layoutPath)) { - printf("Can't load %s keyboard layout file. Keylayout will not be used !\n", - layoutPath); + if (!load_keyboard_layout_file(layoutPath)) + { + DBG("Can't load %s keyboard layout file. Keylayout will not be used !\n", + layoutPath); sleep(2); - } else if (!replace_function("_getchar", &getchar_replacement)) { + } + else if (!replace_function("_getchar", &getchar_replacement)) + { printf("Can't replace function getchar: Keylayout module can't be used !\n"); sleep(2); } Index: branches/ErmaC/Enoch/i386/modules/AcpiCodec/acpi_codec.c =================================================================== --- branches/ErmaC/Enoch/i386/modules/AcpiCodec/acpi_codec.c (revision 2586) +++ branches/ErmaC/Enoch/i386/modules/AcpiCodec/acpi_codec.c (revision 2587) @@ -4330,7 +4330,7 @@ { DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"ACPIDropTables")); if (DropTables_p) DropTables_tag_count = XMLTagCount(DropTables_p) ; - } + } U32 new_table = 0ul; U8 new_table_index = 0, table_added = 0; Index: branches/ErmaC/Enoch/i386/util/segsize.c =================================================================== --- branches/ErmaC/Enoch/i386/util/segsize.c (revision 2586) +++ branches/ErmaC/Enoch/i386/util/segsize.c (revision 2587) @@ -103,7 +103,7 @@ // bool isDATA; // unsigned vmsize; -#define lcp ((struct load_command *)cp) +#define lcp ((struct load_command *)cp) switch(swap(lcp->cmd)) { case LC_SEGMENT: Index: branches/ErmaC/Enoch/package/Scripts.templates/AddOption/postinstall =================================================================== --- branches/ErmaC/Enoch/package/Scripts.templates/AddOption/postinstall (revision 2586) +++ branches/ErmaC/Enoch/package/Scripts.templates/AddOption/postinstall (revision 2587) @@ -3,9 +3,9 @@ set -u configFile='/private/tmp/InstallConfig.plist' -v_mntptDev=$( /usr/libexec/plistbuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' ) -v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//' ) +v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} ) +v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' ) key="@optionKey@" value="@optionValue@" @@ -33,10 +33,10 @@ case "$type" in bool|text) - /usr/libexec/plistbuddy -c "Add :${key} string ${value}" "$bootPListFile" + /usr/libexec/PlistBuddy -c "Add :${key} string ${value}" "$bootPListFile" ;; list) - current_values=$( /usr/libexec/plistbuddy -c "Print :${key}" \ + current_values=$( /usr/libexec/PlistBuddy -c "Print :${key}" \ "$bootPListFile" 2>/dev/null ) result=$? current_values="${current_values// /\\ }" # Escape spaces @@ -49,12 +49,12 @@ else new_values="${current_values}\ ${value}" fi - /usr/libexec/plistbuddy -c "Set :${key} ${new_values}" \ + /usr/libexec/PlistBuddy -c "Set :${key} ${new_values}" \ "$bootPListFile" else # Create a new option new_values="${value}" - /usr/libexec/plistbuddy -c "Add :${key} string ${new_values}" \ + /usr/libexec/PlistBuddy -c "Add :${key} string ${new_values}" \ "$bootPListFile" fi ;; Index: branches/ErmaC/Enoch/package/Scripts.templates/Post/postinstall =================================================================== --- branches/ErmaC/Enoch/package/Scripts.templates/Post/postinstall (revision 2586) +++ branches/ErmaC/Enoch/package/Scripts.templates/Post/postinstall (revision 2587) @@ -5,6 +5,7 @@ # $3 = Installation volume (mountpoint) to receive the payload # $4 = Root directory for the system +logName="@LOG_FILENAME@" mainLine="==============================================================================" subLine="------------------------------------------------------------------------------" @@ -19,33 +20,33 @@ configFile='/private/tmp/InstallConfig.plist' v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} ) -v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//' ) +v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//') targetDevice=$( /usr/libexec/PlistBuddy -c "Print :targetdev" ${configFile} ) -choicedVolume=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//' ) +choicedVolume=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' ) backupRootDir="${targetVolume}/Chameleon.Backups" backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} ) # Check target exists -if [ ! -d "${targetVolume}" ]; then - echo "Target volume does not exist !" >&2 +if [ ! -d "${v_mntpt}" ]; then + echo "Ram disk volume does not exist !" exit 1 fi -if [ ! -d "${v_mntpt}" ]; then - echo "Ram disk volume does not exist !" >&2 + +exec > >(tee -a "${v_mntpt}/${logName}") 2>&1 + +if [ ! -d "${targetVolume}" ]; then + echo "Target volume does not exist !" exit 1 fi + if [ ! -d "${choicedVolume}" ]; then - echo "${choicedVolume} volume does not exist !" >&2 + echo "${choicedVolume} volume does not exist !" exit 1 fi -logName="@LOG_FILENAME@" - -exec > >(tee -a "${v_mntpt}/${logName}") 2>&1 - echo "$mainLine" echo "Running Post postinstall script" echo "Target volume = ${choicedVolume}" @@ -55,9 +56,10 @@ echo "Moving Extra folder to ${choicedVolume}" cp -R "${v_mntpt}/Extra" "${choicedVolume}"/ -echo "NOTE: any Themes or modules you have must be there since this now is the boot partition," -echo " ACPI tables, SMBios.plist and the org.chameleon.Boot.plist (with custom settings" -echo " for the target OSX must be in each partition that contanin it.)" +echo "NOTE: any Themes or modules you have must be there since this now" +echo " is the boot partition. ACPI tables, SMBios.plist and the" +echo " org.chameleon.Boot.plist (with custom settings for the target" +echo " OSX must be in each partition that contain it.)" echo "$subLine" echo "Post postinstall script complete" Index: branches/ErmaC/Enoch/package/Scripts.templates/Pre/preinstall =================================================================== --- branches/ErmaC/Enoch/package/Scripts.templates/Pre/preinstall (revision 2586) +++ branches/ErmaC/Enoch/package/Scripts.templates/Pre/preinstall (revision 2587) @@ -29,8 +29,8 @@ } RAM_DISK() { - if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \ - grep -x "${v_mntpt}" ) ]; then + if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' | grep -x "${v_mntpt}" ) ]; then devToUmount=$( LC_ALL=C diskutil info "${v_mntpt}" | grep -i 'Device Node:' | awk '{print $3}' ) UMOUNT_VDISK $devToUmount fi @@ -45,6 +45,7 @@ exit 1 fi + dev=$( echo "${dev}" | tr -d " \t\n" ) rm -f $configFile # adding the Ram disk device to InstallConfig.plist to be shared with other packages /usr/libexec/PlistBuddy -c "Add :ramdisk string ${dev}" $configFile @@ -53,8 +54,8 @@ RAM_DISK # ensure that ram disk has "/Volumes/BOOTRAMDISK" mount point -v_mntpt=$( LC_ALL=C diskutil info ${dev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//' ) +v_mntpt=$( LC_ALL=C diskutil info ${dev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' ) if [ ! -d "${v_mntpt}" ]; then echo "Ram Disk not found!" exit Index: branches/ErmaC/Enoch/package/Scripts.templates/InstallTheme/postinstall =================================================================== --- branches/ErmaC/Enoch/package/Scripts.templates/InstallTheme/postinstall (revision 2586) +++ branches/ErmaC/Enoch/package/Scripts.templates/InstallTheme/postinstall (revision 2587) @@ -3,10 +3,9 @@ set -u configFile='/private/tmp/InstallConfig.plist' -v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' ) -v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//' ) - +v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} ) +v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' ) themeName="@themeName@" themeDir="@themeDir@" logName="@LOG_FILENAME@" Index: branches/ErmaC/Enoch/package/Scripts.templates/InstallModule/postinstall =================================================================== --- branches/ErmaC/Enoch/package/Scripts.templates/InstallModule/postinstall (revision 2586) +++ branches/ErmaC/Enoch/package/Scripts.templates/InstallModule/postinstall (revision 2587) @@ -3,9 +3,9 @@ set -u configFile='/private/tmp/InstallConfig.plist' -v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' ) -v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//' ) +v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} ) +v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' ) moduleName="@moduleName@" moduleFile="@moduleFile@" Index: branches/ErmaC/Enoch/package/Scripts/Main/ESPpostinstall =================================================================== --- branches/ErmaC/Enoch/package/Scripts/Main/ESPpostinstall (revision 2586) +++ branches/ErmaC/Enoch/package/Scripts/Main/ESPpostinstall (revision 2587) @@ -1,14 +1,18 @@ #!/bin/bash # -------------------------------------------------------------------------------------------------------- -# Install.sh v1.3, script to install Chameleon +# Install.sh v1.5, script to install Chameleon # Created by Miky1979 on December 8th, 2014 # -------------------------------------------------------------------------------------------------------- targetVolume="${3}" InstallToESP="1" InstallBootloader="0" +espmtp="/Volumes/ESP" +WINDOWS_EXIST="0" +opt="u" configFile="/private/tmp/InstallConfig.plist" +if [ "${InstallToESP}" == "1" ]; then TYPE="ESP"; else TYPE="Standard"; fi if [[ $( /usr/libexec/PlistBuddy -c "Print bootloader" ${configFile} ) == "true" ]];then # installing stage 0, 1 and 2 only if user want this: # ie only if have no selected noboot choice @@ -23,28 +27,26 @@ choicedVolume="${targetVolume}" ESP_MOUNTED="0" # -------------------------------------------------------------------------------------------------------- -v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' ) -v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//') +v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} ) +v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' ) backupRootDir="${targetVolume}/Chameleon.Backups" backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} ) logName="Chameleon_Installer_Log.txt" logFile="${v_mntpt}/${logName}" # -------------------------------------------------------------------------------------------------------- -stage0Loader="boot0" -stage0LoaderDualBoot="boot0md" stage1LoaderHFS="boot1h" stage1LoaderFAT="boot1f32" stage1LoaderExFAT="boot1x" stage2Loader="boot" versionToInstall=$(cat "${i386Dir}/Boot" | grep -a 'Darwin/x86 boot v' ) # -------------------------------------------------------------------------------------------------------- -localdd="/bin/dd" SS="${usrLocalBin}/sectorsize" # -------------------------------------------------------------------------------------------------------- # Scanning all Variables. We are switching to the target Volume or its ESP. # This function is usefull to rescan the new target "at need" SCAN() { + bootDevice=$( LC_ALL=C diskutil info / | grep -i 'Device Node:' | awk '{print $NF}' ) targetDevice=$( LC_ALL=C diskutil info "${choicedVolume}" | grep -i 'Device Node:' | awk '{print $NF}' ) targetDeviceRaw=${targetDevice/disk/rdisk} targetDisk=${targetDevice%s*} @@ -52,9 +54,9 @@ targetSlice=${targetDevice#*disk*s} IOContent=$( LC_ALL=C diskutil info "${targetDisk}" | grep -i 'Content (IOContent)' | awk '{print $NF}' ) FS=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'Type (Bundle)' | \ - awk '{print $NF}' | awk '{print tolower($0)}' ) + awk '{print $NF}' | awk '{print tolower($0)}' ) disksignature=$( dd 2>/dev/null if="${targetDisk}" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | \ - perl -ne '@a=split"";for(@a){printf"%02x",ord}' ) + perl -ne '@a=split"";for(@a){printf"%02x",ord}' ) if [ $InstallBootloader = "1" ];then blocksize=$( "${SS}" "${targetDeviceRaw}" | awk '{ print $2 }' ) @@ -69,10 +71,9 @@ # Create a folder inside the Desktop called "DebugChameleon", and the log will be full DEBUG() { echo "$mainLine" - echo "DEBUG: display script variables (ESPpostinstall)" + echo "DEBUG: display script variables (${TYPE}postinstall)" echo "$mainLine" - echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader} (or boot0hfs)" - echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot} (or boot0hfs)" + echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}" echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}" echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}" echo "DEBUG: stage1LoaderExFAT: Partition loader is ${stage1LoaderExFAT}" @@ -83,6 +84,7 @@ echo "DEBUG: targetDisk: Disk device is ${targetDisk}" echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}" echo "DEBUG: targetSlice: Volume slice is ${targetSlice}" + echo "DEBUG: bootDevice: Current Volume device is ${bootDevice}" echo "DEBUG: versionToInstall: version to install is ${versionToInstall}" echo "DEBUG: IOContent: partition scheme is ${IOContent}" echo "DEBUG: FS: file System is ${FS}" @@ -93,8 +95,8 @@ # -------------------------------------------------------------------------------------------------------- # Checking for unsupported FAT16 filesystem CHECK_FAT16() { - pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' \ - | awk '{print $NF}' | awk '{print tolower($0)}' ) + pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' | \ + awk '{print $NF}' | awk '{print tolower($0)}' ) case $pers in fat16) @@ -102,7 +104,7 @@ exit 1 ;; *) - echo "First Check Passed!" + echo "First Check Passed (not Fat16)!" ;; esac } @@ -116,9 +118,9 @@ CHECK_ESP_MOUNTPOINT() { # umount the ESP by its Mount Point # and checking it if is busy by another ESP - if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \ - grep -x '/Volumes/ESP' ) ]; then - umount -f /Volumes/ESP + if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \ + grep -x "${espmtp}" ) ]; then + umount -f ${espmtp} ESP_MOUNTED="0" fi } @@ -128,7 +130,7 @@ if [ $( df | grep "${espDisk}" | awk '{print $1}' | grep -x "${espDisk}" ) ];then # ESP is already mounted, so now we aquire the Mount Point espmtp=$( LC_ALL=C diskutil info ${espDisk} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ - sed -e 's/^[ \t]*//' ) + sed -e 's/^ *//' | sed -e 's/ *$//' ) if [ -d "${espmtp}" ];then echo "ESP Mount Point is:${espmtp}, using that as target Volume!" choicedVolume="${espmtp}" @@ -144,13 +146,15 @@ fi if [ $ESP_MOUNTED = "0" ];then - mkdir -p /Volumes/ESP + mkdir -p "${espmtp}" case $( fstyp $espDisk ) in hfs) - mount -t hfs $espDisk /Volumes/ESP + echo "Mounting $espDisk on $espmtp as hfs Volume.." + mount -t hfs $espDisk "${espmtp}" ;; msdos) - mount -t msdos $espDisk /Volumes/ESP + echo "Mounting $espDisk on $espmtp as msdos Volume.." + mount -t msdos $espDisk "${espmtp}" ;; *) echo "ESP fileSystem unsupported, Installing to ${targetVolume}!" @@ -159,10 +163,11 @@ esac sleep 0.3 - if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \ - grep -x '/Volumes/ESP' ) ]; then + if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \ + grep -x "${espmtp}" ) ]; then + echo "EFI System Partition mounted!" ESP_MOUNTED="1" - choicedVolume="/Volumes/ESP" + choicedVolume="${espmtp}" SCAN else echo "ESP can't be mounted, Installing to ${targetVolume}!" @@ -202,7 +207,6 @@ # -------------------------------------------------------------------------------------------------------- # Writing stage 0 CHECK_WINDOWS() { - WINDOWS_EXIST="0" if [ "${disksignature}" = "00000000" ]; then echo "Windows installation not found on ${targetDisk}." else @@ -214,55 +218,21 @@ WRITE_STAGE0() { if [ $InstallBootloader = "1" ];then echo -e "${mainLine}\nWRITING STAGE 0:" - CHECK_WINDOWS - case "$1" in - hfs) - if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0hfs"; else stage0Loader="boot0"; fi - ;; - msdos) - if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0md"; else stage0Loader="boot0";fi - ;; - exfat) - stage0Loader="boot0" - ;; - esac - "${usrLocalBin}/fdisk440" -u -f "${i386Dir}/${stage0Loader}" -y ${targetDisk} echo "${stage0Loader} writed to ${targetDisk}" fi } - # -------------------------------------------------------------------------------------------------------- -# Writing stage 1 on different filesystems -WRITE_STAGE1_HFS() { +# Writing stage 1 +WRITE_STAGE1() { if [ $InstallBootloader = "1" ];then - echo -e "${mainLine}\nWRITING STAGE 1 HFS:" - $localdd if="${i386Dir}/${stage1LoaderHFS}" of=${targetDeviceRaw} - echo "${stage1LoaderHFS} (hfs) writed to ${targetDeviceRaw}." - fi -} - -WRITE_STAGE1_EXFAT() { - if [ $InstallBootloader = "1" ];then - echo -e "${mainLine}\nWRITING STAGE 1 ExFAT:" + echo -e "${mainLine}\nWRITING STAGE 1 ${2}:" cp -R "${usrLocalBin}/boot1-install" "${v_mntpt}"/ - cp -R "${i386Dir}/${stage1LoaderExFAT}" "${v_mntpt}"/ - "${v_mntpt}/boot1-install" -y -u -f "${v_mntpt}/${stage1LoaderExFAT}" ${targetDeviceRaw} - echo "${stage1LoaderExFAT} (ExFAT) writed to ${targetDeviceRaw}." + cp -R "${i386Dir}/${1}" "${v_mntpt}"/ + "${v_mntpt}/boot1-install" -y "-${3}" -f "${v_mntpt}/${1}" ${targetDeviceRaw} + echo "${stage1Loader} (${2}) writed to ${targetDeviceRaw}." fi } - -WRITE_STAGE1_FAT32() { - if [ $InstallBootloader = "1" ];then - echo -e "${mainLine}\nWRITING STAGE 1 FAT32:" - $localdd if=${targetDeviceRaw} count=1 bs=512 of="${v_mntpt}/origbs" - cp "${i386Dir}/${stage1LoaderFAT}" "${v_mntpt}/newbs" - $localdd if="${v_mntpt}/origbs" of="${v_mntpt}/newbs" skip=3 seek=3 bs=1 count=87 conv=notrunc - $localdd if="${v_mntpt}/newbs" of="${targetDeviceRaw}" count=1 bs=512 - - echo "${stage1LoaderFAT} (Fat32) writed to ${targetDeviceRaw}." - fi -} # -------------------------------------------------------------------------------------------------------- # Writing stage 2 WRITE_STAGE2() { @@ -275,15 +245,22 @@ } # -------------------------------------------------------------------------------------------------------- # Waiting for targhet Volume was re-mounted before proceeding.. -# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..) -WAIT_REMOUNT() { +# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..). +# exception is the EFI partition: in Mavericks autoremount...in Yosemite not.. +REMOUNT() { if [ $InstallBootloader = "1" ];then - if [ ! -d "${choicedVolume}" ]; then - echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:" - until [ -d "${choicedVolume}" ]; do - sleep 0.3 - done - echo "${choicedVolume} is mounted!" + if [ "${InstallToESP}" == "1" ]; then + if [ ! -d "${choicedVolume}" ]; then + MOUNT_ESP + fi + else + if [ ! -d "${choicedVolume}" ]; then + echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:" + until [ -d "${choicedVolume}" ]; do + sleep 0.3 + done + echo "${choicedVolume} is mounted!" + fi fi fi } @@ -298,7 +275,7 @@ else echo "Extra folder already exist on ${choicedVolume}, copying to the Ram Disk.." cp -R "${choicedVolume}/Extra" "${v_mntpt}"/ - ./clean_bootplist.pl "${v_mntpt}" >/dev/null + ./clean_bootplist.pl "${v_mntpt}" fi } # -------------------------------------------------------------------------------------------------------- @@ -332,7 +309,7 @@ exec > >(tee -a "${logFile}") 2>&1 echo "$mainLine" -echo "Main ESP Post-Install Script" +echo "Main ${TYPE} Post-Install Script" echo "Chameleon installer log - $( date )" if [ $InstallBootloader = "1" ];then echo "$versionToInstall"; else echo "no boot session"; fi echo "" @@ -355,7 +332,7 @@ echo "GPT partition Scheme detected.." espDisk="${targetDisk}s1" if [ $( LC_ALL=C diskutil info ${espDisk} | grep -i 'Partition Type:' | \ - awk '{print $NF}' ) = "EFI" ]; then + awk '{print $NF}' | sed -e 's/^ *//' | sed -e 's/ *$//' ) = "EFI" ]; then echo "EFI partition found is ${espDisk}, try to mount it.." MOUNT_ESP else @@ -364,6 +341,7 @@ fi ;; *) + InstallToESP = "0" echo "Can't install on the ESP, because does not exist.." echo "..continue installing to ${targetVolume}" ;; @@ -372,11 +350,6 @@ SCAN fi - -if [ -d "${HOME}/Desktop/DebugChameleon" ]; then - DEBUG -fi - # adding the chosen Volume dev id to the InstallConfig.plist /usr/libexec/PlistBuddy -c "Add :targetdev string ${targetDevice}" $configFile @@ -385,22 +358,22 @@ echo "${mainLine}" CHECK_FAT16 +CHECK_WINDOWS case "$FS" in hfs) echo "${targetDevice} is HFS formatted" - WRITE_STAGE0 hfs - WRITE_STAGE1_HFS + if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0hfs"; else stage0Loader="boot0"; fi + stage1Loader="${stage1LoaderHFS}" ;; msdos) echo "${targetDevice} is FAT32 formatted" - WRITE_STAGE0 msdos - WRITE_STAGE1_FAT32 + if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0md"; else stage0Loader="boot0"; fi + stage1Loader="${stage1LoaderFAT}" ;; exfat) echo "${targetDevice} is ExFAT formatted" - WRITE_STAGE0 exfat - WRITE_STAGE1_EXFAT - WAIT_REMOUNT + stage0Loader="boot0" + stage1Loader="${stage1LoaderExFAT}" ;; *) echo "FileSystem unsupported, aborting!" @@ -408,11 +381,19 @@ ;; esac +# Debug mode: create a "DebugChameleon" folder on your Desktop to debug this script +if [ -d "${HOME}/Desktop/DebugChameleon" ]; then DEBUG; fi +# if the target device is equal to the boot device keep the Volume mounted using boot1-install +if [ "${bootDevice}" = "${targetDevice}" ]; then opt="M"; fi + +WRITE_STAGE0 "${stage0Loader}" +WRITE_STAGE1 "${stage1Loader}" "${FS}" "${opt}" +if [ "${bootDevice}" != "${targetDevice}" ]; then REMOUNT; fi WRITE_STAGE2 PARTITION_ACTIVE_IF echo "$mainLine" -echo "END - ESP Post-Install Script" +echo "END - ${TYPE} Post-Install Script" # -------------------------------------------------------------------------------------------------------- exit 0 Index: branches/ErmaC/Enoch/package/Scripts/Main/Standardpostinstall =================================================================== --- branches/ErmaC/Enoch/package/Scripts/Main/Standardpostinstall (revision 2586) +++ branches/ErmaC/Enoch/package/Scripts/Main/Standardpostinstall (revision 2587) @@ -1,14 +1,18 @@ #!/bin/bash # -------------------------------------------------------------------------------------------------------- -# Install.sh v1.3, script to install Chameleon +# Install.sh v1.5, script to install Chameleon # Created by Miky1979 on December 8th, 2014 # -------------------------------------------------------------------------------------------------------- targetVolume="${3}" InstallToESP="0" InstallBootloader="0" +espmtp="/Volumes/ESP" +WINDOWS_EXIST="0" +opt="u" configFile="/private/tmp/InstallConfig.plist" +if [ "${InstallToESP}" == "1" ]; then TYPE="ESP"; else TYPE="Standard"; fi if [[ $( /usr/libexec/PlistBuddy -c "Print bootloader" ${configFile} ) == "true" ]];then # installing stage 0, 1 and 2 only if user want this: # ie only if have no selected noboot choice @@ -23,28 +27,26 @@ choicedVolume="${targetVolume}" ESP_MOUNTED="0" # -------------------------------------------------------------------------------------------------------- -v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' ) -v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \ - | sed -e 's/^[ \t]*//') +v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} ) +v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ + sed -e 's/^ *//' | sed -e 's/ *$//' ) backupRootDir="${targetVolume}/Chameleon.Backups" backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} ) logName="Chameleon_Installer_Log.txt" logFile="${v_mntpt}/${logName}" # -------------------------------------------------------------------------------------------------------- -stage0Loader="boot0" -stage0LoaderDualBoot="boot0md" stage1LoaderHFS="boot1h" stage1LoaderFAT="boot1f32" stage1LoaderExFAT="boot1x" stage2Loader="boot" versionToInstall=$(cat "${i386Dir}/Boot" | grep -a 'Darwin/x86 boot v' ) # -------------------------------------------------------------------------------------------------------- -localdd="/bin/dd" SS="${usrLocalBin}/sectorsize" # -------------------------------------------------------------------------------------------------------- # Scanning all Variables. We are switching to the target Volume or its ESP. # This function is usefull to rescan the new target "at need" SCAN() { + bootDevice=$( LC_ALL=C diskutil info / | grep -i 'Device Node:' | awk '{print $NF}' ) targetDevice=$( LC_ALL=C diskutil info "${choicedVolume}" | grep -i 'Device Node:' | awk '{print $NF}' ) targetDeviceRaw=${targetDevice/disk/rdisk} targetDisk=${targetDevice%s*} @@ -52,9 +54,9 @@ targetSlice=${targetDevice#*disk*s} IOContent=$( LC_ALL=C diskutil info "${targetDisk}" | grep -i 'Content (IOContent)' | awk '{print $NF}' ) FS=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'Type (Bundle)' | \ - awk '{print $NF}' | awk '{print tolower($0)}' ) + awk '{print $NF}' | awk '{print tolower($0)}' ) disksignature=$( dd 2>/dev/null if="${targetDisk}" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | \ - perl -ne '@a=split"";for(@a){printf"%02x",ord}' ) + perl -ne '@a=split"";for(@a){printf"%02x",ord}' ) if [ $InstallBootloader = "1" ];then blocksize=$( "${SS}" "${targetDeviceRaw}" | awk '{ print $2 }' ) @@ -69,10 +71,9 @@ # Create a folder inside the Desktop called "DebugChameleon", and the log will be full DEBUG() { echo "$mainLine" - echo "DEBUG: display script variables (Standardpostinstall)" + echo "DEBUG: display script variables (${TYPE}postinstall)" echo "$mainLine" - echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader} (or boot0hfs)" - echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot} (or boot0hfs)" + echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}" echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}" echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}" echo "DEBUG: stage1LoaderExFAT: Partition loader is ${stage1LoaderExFAT}" @@ -83,6 +84,7 @@ echo "DEBUG: targetDisk: Disk device is ${targetDisk}" echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}" echo "DEBUG: targetSlice: Volume slice is ${targetSlice}" + echo "DEBUG: bootDevice: Current Volume device is ${bootDevice}" echo "DEBUG: versionToInstall: version to install is ${versionToInstall}" echo "DEBUG: IOContent: partition scheme is ${IOContent}" echo "DEBUG: FS: file System is ${FS}" @@ -93,8 +95,8 @@ # -------------------------------------------------------------------------------------------------------- # Checking for unsupported FAT16 filesystem CHECK_FAT16() { - pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' \ - | awk '{print $NF}' | awk '{print tolower($0)}' ) + pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' | \ + awk '{print $NF}' | awk '{print tolower($0)}' ) case $pers in fat16) @@ -102,7 +104,7 @@ exit 1 ;; *) - echo "First Check Passed!" + echo "First Check Passed (not Fat16)!" ;; esac } @@ -116,9 +118,9 @@ CHECK_ESP_MOUNTPOINT() { # umount the ESP by its Mount Point # and checking it if is busy by another ESP - if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \ - grep -x '/Volumes/ESP' ) ]; then - umount -f /Volumes/ESP + if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \ + grep -x "${espmtp}" ) ]; then + umount -f ${espmtp} ESP_MOUNTED="0" fi } @@ -128,7 +130,7 @@ if [ $( df | grep "${espDisk}" | awk '{print $1}' | grep -x "${espDisk}" ) ];then # ESP is already mounted, so now we aquire the Mount Point espmtp=$( LC_ALL=C diskutil info ${espDisk} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \ - sed -e 's/^[ \t]*//' ) + sed -e 's/^ *//' | sed -e 's/ *$//' ) if [ -d "${espmtp}" ];then echo "ESP Mount Point is:${espmtp}, using that as target Volume!" choicedVolume="${espmtp}" @@ -144,13 +146,15 @@ fi if [ $ESP_MOUNTED = "0" ];then - mkdir -p /Volumes/ESP + mkdir -p "${espmtp}" case $( fstyp $espDisk ) in hfs) - mount -t hfs $espDisk /Volumes/ESP + echo "Mounting $espDisk on $espmtp as hfs Volume.." + mount -t hfs $espDisk "${espmtp}" ;; msdos) - mount -t msdos $espDisk /Volumes/ESP + echo "Mounting $espDisk on $espmtp as msdos Volume.." + mount -t msdos $espDisk "${espmtp}" ;; *) echo "ESP fileSystem unsupported, Installing to ${targetVolume}!" @@ -159,10 +163,11 @@ esac sleep 0.3 - if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \ - grep -x '/Volumes/ESP' ) ]; then + if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \ + grep -x "${espmtp}" ) ]; then + echo "EFI System Partition mounted!" ESP_MOUNTED="1" - choicedVolume="/Volumes/ESP" + choicedVolume="${espmtp}" SCAN else echo "ESP can't be mounted, Installing to ${targetVolume}!" @@ -202,7 +207,6 @@ # -------------------------------------------------------------------------------------------------------- # Writing stage 0 CHECK_WINDOWS() { - WINDOWS_EXIST="0" if [ "${disksignature}" = "00000000" ]; then echo "Windows installation not found on ${targetDisk}." else @@ -214,54 +218,21 @@ WRITE_STAGE0() { if [ $InstallBootloader = "1" ];then echo -e "${mainLine}\nWRITING STAGE 0:" - CHECK_WINDOWS - case "$1" in - hfs) - if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0hfs"; else stage0Loader="boot0"; fi - ;; - msdos) - if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0md"; else stage0Loader="boot0";fi - ;; - exfat) - stage0Loader="boot0" - ;; - esac - "${usrLocalBin}/fdisk440" -u -f "${i386Dir}/${stage0Loader}" -y ${targetDisk} echo "${stage0Loader} writed to ${targetDisk}" fi } # -------------------------------------------------------------------------------------------------------- -# Writing stage 1 on different filesystems -WRITE_STAGE1_HFS() { +# Writing stage 1 +WRITE_STAGE1() { if [ $InstallBootloader = "1" ];then - echo -e "${mainLine}\nWRITING STAGE 1 HFS:" - $localdd if="${i386Dir}/${stage1LoaderHFS}" of=${targetDeviceRaw} - echo "${stage1LoaderHFS} (hfs) writed to ${targetDeviceRaw}." - fi -} - -WRITE_STAGE1_EXFAT() { - if [ $InstallBootloader = "1" ];then - echo -e "${mainLine}\nWRITING STAGE 1 ExFAT:" + echo -e "${mainLine}\nWRITING STAGE 1 ${2}:" cp -R "${usrLocalBin}/boot1-install" "${v_mntpt}"/ - cp -R "${i386Dir}/${stage1LoaderExFAT}" "${v_mntpt}"/ - "${v_mntpt}/boot1-install" -y -u -f "${v_mntpt}/${stage1LoaderExFAT}" ${targetDeviceRaw} - echo "${stage1LoaderExFAT} (ExFAT) writed to ${targetDeviceRaw}." + cp -R "${i386Dir}/${1}" "${v_mntpt}"/ + "${v_mntpt}/boot1-install" -y "-${3}" -f "${v_mntpt}/${1}" ${targetDeviceRaw} + echo "${stage1Loader} (${2}) writed to ${targetDeviceRaw}." fi } - -WRITE_STAGE1_FAT32() { - if [ $InstallBootloader = "1" ];then - echo -e "${mainLine}\nWRITING STAGE 1 FAT32:" - $localdd if=${targetDeviceRaw} count=1 bs=512 of="${v_mntpt}/origbs" - cp "${i386Dir}/${stage1LoaderFAT}" "${v_mntpt}/newbs" - $localdd if="${v_mntpt}/origbs" of="${v_mntpt}/newbs" skip=3 seek=3 bs=1 count=87 conv=notrunc - $localdd if="${v_mntpt}/newbs" of="${targetDeviceRaw}" count=1 bs=512 - - echo "${stage1LoaderFAT} (Fat32) writed to ${targetDeviceRaw}." - fi -} # -------------------------------------------------------------------------------------------------------- # Writing stage 2 WRITE_STAGE2() { @@ -274,15 +245,22 @@ } # -------------------------------------------------------------------------------------------------------- # Waiting for targhet Volume was re-mounted before proceeding.. -# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..) -WAIT_REMOUNT() { +# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..). +# exception is the EFI partition: in Mavericks autoremount...in Yosemite not.. +REMOUNT() { if [ $InstallBootloader = "1" ];then - if [ ! -d "${choicedVolume}" ]; then - echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:" - until [ -d "${choicedVolume}" ]; do - sleep 0.3 - done - echo "${choicedVolume} is mounted!" + if [ "${InstallToESP}" == "1" ]; then + if [ ! -d "${choicedVolume}" ]; then + MOUNT_ESP + fi + else + if [ ! -d "${choicedVolume}" ]; then + echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:" + until [ -d "${choicedVolume}" ]; do + sleep 0.3 + done + echo "${choicedVolume} is mounted!" + fi fi fi } @@ -297,7 +275,7 @@ else echo "Extra folder already exist on ${choicedVolume}, copying to the Ram Disk.." cp -R "${choicedVolume}/Extra" "${v_mntpt}"/ - ./clean_bootplist.pl "${v_mntpt}" >/dev/null + ./clean_bootplist.pl "${v_mntpt}" fi } # -------------------------------------------------------------------------------------------------------- @@ -331,7 +309,7 @@ exec > >(tee -a "${logFile}") 2>&1 echo "$mainLine" -echo "Main Standard Post-Install Script" +echo "Main ${TYPE} Post-Install Script" echo "Chameleon installer log - $( date )" if [ $InstallBootloader = "1" ];then echo "$versionToInstall"; else echo "no boot session"; fi echo "" @@ -354,7 +332,7 @@ echo "GPT partition Scheme detected.." espDisk="${targetDisk}s1" if [ $( LC_ALL=C diskutil info ${espDisk} | grep -i 'Partition Type:' | \ - awk '{print $NF}' ) = "EFI" ]; then + awk '{print $NF}' | sed -e 's/^ *//' | sed -e 's/ *$//' ) = "EFI" ]; then echo "EFI partition found is ${espDisk}, try to mount it.." MOUNT_ESP else @@ -363,6 +341,7 @@ fi ;; *) + InstallToESP = "0" echo "Can't install on the ESP, because does not exist.." echo "..continue installing to ${targetVolume}" ;; @@ -371,11 +350,6 @@ SCAN fi - -if [ -d "${HOME}/Desktop/DebugChameleon" ]; then - DEBUG -fi - # adding the chosen Volume dev id to the InstallConfig.plist /usr/libexec/PlistBuddy -c "Add :targetdev string ${targetDevice}" $configFile @@ -384,22 +358,22 @@ echo "${mainLine}" CHECK_FAT16 +CHECK_WINDOWS case "$FS" in hfs) echo "${targetDevice} is HFS formatted" - WRITE_STAGE0 hfs - WRITE_STAGE1_HFS + if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0hfs"; else stage0Loader="boot0"; fi + stage1Loader="${stage1LoaderHFS}" ;; msdos) echo "${targetDevice} is FAT32 formatted" - WRITE_STAGE0 msdos - WRITE_STAGE1_FAT32 + if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0md"; else stage0Loader="boot0"; fi + stage1Loader="${stage1LoaderFAT}" ;; exfat) echo "${targetDevice} is ExFAT formatted" - WRITE_STAGE0 exfat - WRITE_STAGE1_EXFAT - WAIT_REMOUNT + stage0Loader="boot0" + stage1Loader="${stage1LoaderExFAT}" ;; *) echo "FileSystem unsupported, aborting!" @@ -407,11 +381,19 @@ ;; esac +# Debug mode: create a "DebugChameleon" folder on your Desktop to debug this script +if [ -d "${HOME}/Desktop/DebugChameleon" ]; then DEBUG; fi +# if the target device is equal to the boot device keep the Volume mounted using boot1-install +if [ "${bootDevice}" = "${targetDevice}" ]; then opt="M"; fi + +WRITE_STAGE0 "${stage0Loader}" +WRITE_STAGE1 "${stage1Loader}" "${FS}" "${opt}" +if [ "${bootDevice}" != "${targetDevice}" ]; then REMOUNT; fi WRITE_STAGE2 PARTITION_ACTIVE_IF echo "$mainLine" -echo "END - Standard Post-Install Script" +echo "END - ${TYPE} Post-Install Script" # -------------------------------------------------------------------------------------------------------- exit 0 Index: branches/ErmaC/Enoch/package/buildpkg.sh =================================================================== --- branches/ErmaC/Enoch/package/buildpkg.sh (revision 2586) +++ branches/ErmaC/Enoch/package/buildpkg.sh (revision 2587) @@ -475,6 +475,7 @@ ditto --noextattr --noqtn ${SYMROOT}/i386/boot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386 ditto --noextattr --noqtn ${SYMROOT}/i386/boot0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386 ditto --noextattr --noqtn ${SYMROOT}/i386/boot0md ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386 + ditto --noextattr --noqtn ${SYMROOT}/i386/boot0hfs ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386 ditto --noextattr --noqtn ${SYMROOT}/i386/boot1x ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386