/* intialize the record by searching for the given string in the given folder. * * parent and r may be the same. */ int record_init_string_parent(record* r, record* parent, char* name) { hfsp_cat_key key; if (parent->record.type == HFSP_FOLDER) key.parent_cnid = parent->record.u.folder.id; else if(parent->record.type == HFSP_FOLDER_THREAD) key.parent_cnid = parent->key.parent_cnid; else HFSP_ERROR(-1, "record_init_string_parent: parent is not a folder."); key.key_length = 6 + unicode_asc2uni(&key.name,name); // 6 for minumum size return record_init_key(r, parent->tree, &key); fail: return -1; }
/* initialize a (catalog) record with given type and (ascii) name. * parent must be a HFSP_FOLDER or FOLDER_THREAD * You should normally call record_insert afterwards. */ int record_init_string(record* r, UInt16 type, char* name, record* parent) { int result = 0; hfsp_cat_key* key = &r->key; hfsp_cat_entry* entry = &r->record; UInt16 ptype = parent->record.type; memset(r, 0, sizeof *r); // **** Debugging only r->tree = parent->tree; r->node_index = 0; r->keyind = 0; key->key_length = 6 + 2 * unicode_asc2uni(&key->name,name); // 6 for minumum size if (ptype == HFSP_FOLDER) key->parent_cnid= parent->record.u.folder.id; else if (ptype == HFSP_FOLDER_THREAD) key->parent_cnid= parent->key.parent_cnid; else // no kind of folder ?? { hfsp_error = "parent for record_init_string is not a folder."; return EINVAL; } switch(type) { case HFSP_FOLDER : entry->type = type; record_initfolder(parent->tree->vol, &entry->u.folder); break; case HFSP_FILE : entry->type = type; record_initfile(parent->tree->vol, &entry->u.file); break; // Those are unsupported use the types above instead // record_init will care about the threads case HFSP_FOLDER_THREAD : case HFSP_FILE_THREAD : default: hfsp_error = "Unsupported type for record_init_string()"; result = -1; } return result; }