OSErr
CreateCatalogNode ( ExtendedVCB *volume, HFSCatalogNodeID parentID, ConstUTF8Param name,
- UInt32 nodeType, HFSCatalogNodeID *catalogNodeID, UInt32 *catalogHint)
+ UInt32 nodeType, HFSCatalogNodeID *catalogNodeID, UInt32 *catalogHint,
+ UInt32 teHint)
{
CatalogKey *nodeKey;
CatalogRecord nodeData; // 520 bytes
InvalidateCatalogNodeCache(volume, parentsParentID);
//--- build key for new catalog node
+ textEncoding = teHint;
result = BuildCatalogKeyUTF8(volume, parentID, name, kUndefinedStrLen, nodeKey, &textEncoding);
ReturnIfError(result);
// if we did not find it by name, then look for an embedded file ID in a mangled name
if ( (result == cmNotFound) && isHFSPlus )
result = LocateCatalogNodeByMangledName(volume, parentID, name, kUndefinedStrLen, &key, &data, &nodeHint);
+
+ /*
+ * In Mac OS X there can also be HFS filenames that
+ * could not be encoded using the default encoding.
+ */
+ if (result == cmNotFound && !isHFSPlus && VCBTOHFS(volume)->hfs_encoding != 0) {
+ Str31 hfsName;
+
+ utf8_to_mac_roman(strlen(name), name, hfsName);
+ result = LocateCatalogNode(volume, parentID, (CatalogName*)hfsName,
+ 0, &key, &data, &nodeHint);
+ }
ReturnIfError(result);
nodeParentID = isHFSPlus ? key.hfsPlus.parentID : key.hfs.parentID; // establish real parent cnid
* could not be encoded using the default encoding.
* In which case they were encoded as MacRoman.
*/
- if (result == cmNotFound && !isHFSPlus) {
+ if (result == cmNotFound && !isHFSPlus && VCBTOHFS(volume)->hfs_encoding != 0) {
Str31 hfsName;
utf8_to_mac_roman(nameLen, name, hfsName);
cnp = (CatalogName*) ckp->hfs.nodeName;
result = hfs_to_utf8(vol, cnp->pstr, kdirentMaxNameBytes + 1,
&utf8chars, name);
- /*XXX ignoring error */
+ if (result) {
+ /*
+ * When an HFS name cannot be encoded with the current
+ * volume encoding we use MacRoman as a fallback.
+ */
+ result = mac_roman_to_utf8(cnp->pstr, MAXHFSVNODELEN + 1,
+ &utf8chars, name);
+ }
}
return DIRENTRY_SIZE(utf8chars);
OSErr
PositionIterator(CatalogIterator *cip, UInt32 offset, BTreeIterator *bip, UInt16 *op)
{
-#define CAT_START_OFFSET 0
+#define CAT_START_OFFSET (2 * sizeof(struct hfsdotentry))
ExtendedVCB * vol;
FCB * fcb;
OSErr result = 0;
pid = *idp;
curOffset = CAT_START_OFFSET;
- nextOffset = GetDirEntrySize(bip, vol);
+ nextOffset = CAT_START_OFFSET + GetDirEntrySize(bip, vol);
while (nextOffset < offset) {
result = BTIterateRecord( fcb, kBTreeNextRecord, bip, NULL, NULL );
nodeData->cnm_nameptr = NewPtr(utf8len+1);
nodeData->cnm_flags |= kCatNameIsAllocated;
result = hfs_to_utf8(volume, offspringName->pstr, utf8len + 1, &utf8len, nodeData->cnm_nameptr);
+ } else if (result) {
+ /*
+ * When an HFS name cannot be encoded with the current
+ * volume encoding we use MacRoman as a fallback.
+ */
+ result = mac_roman_to_utf8(offspringName->pstr, MAXHFSVNODELEN + 1,
+ &utf8len, nodeData->cnm_namespace);
}
} else {
OSErr
MoveRenameCatalogNode(ExtendedVCB *volume, HFSCatalogNodeID srcParentID, ConstUTF8Param srcName,
- UInt32 srcHint, HFSCatalogNodeID dstParentID, ConstUTF8Param dstName, UInt32 *newHint)
+ UInt32 srcHint, HFSCatalogNodeID dstParentID, ConstUTF8Param dstName,
+ UInt32 *newHint, UInt32 teHint)
{
CatalogKey srcKey; // 518 bytes
CatalogRecord srcRecord; // 520 bytes
short srcNameLen;
short dstNameLen;
-
+ textEncoding = teHint;
result = BuildCatalogKeyUTF8(volume, srcParentID, srcName, kUndefinedStrLen, &srcKey, &textEncoding);
ReturnIfError(result);
// if we did not find it by name, then look for an embedded file ID in a mangled name
if ( (result == cmNotFound) && isHFSPlus )
result = LocateCatalogNodeByMangledName(volume, srcParentID, srcName, kUndefinedStrLen, &srcKey, &srcRecord, &srcHint);
+ /*
+ * In Mac OS X there can also be HFS filenames that
+ * could not be encoded using the default encoding.
+ */
+ if (result == cmNotFound && !isHFSPlus && VCBTOHFS(volume)->hfs_encoding != 0) {
+ Str31 hfsName;
+
+ utf8_to_mac_roman(strlen(srcName), srcName, hfsName);
+ result = LocateCatalogNode(volume, srcParentID, (CatalogName*)hfsName,
+ 0, &srcKey, &srcRecord, &srcHint);
+ }
ReturnIfError(result);
srcParentID = (isHFSPlus ? srcKey.hfsPlus.parentID : srcKey.hfs.parentID);
if ( (result == cmNotFound) && isHFSPlus )
result = LocateCatalogNodeByMangledName(volume, parentID, name, kUndefinedStrLen, key, record, &hint);
+ /*
+ * In Mac OS X there can also be HFS filenames that
+ * could not be encoded using the default encoding.
+ */
+ if (result == cmNotFound && !isHFSPlus && VCBTOHFS(volume)->hfs_encoding != 0) {
+ Str31 hfsName;
+
+ utf8_to_mac_roman(strlen(name), name, hfsName);
+ result = LocateCatalogNode(volume, parentID, (CatalogName*)hfsName,
+ 0, key, record, &hint);
+ }
if (result == btNotFound)
result = cmNotFound;
// if we did not find it by name, then look for an embedded file ID in a mangled name
if ( (result == cmNotFound) && isHFSPlus )
result = LocateCatalogNodeByMangledName(volume, parentID, name, kUndefinedStrLen, &nodeKey, &nodeData, &nodeHint);
+ /*
+ * In Mac OS X there can also be HFS filenames that
+ * could not be encoded using the default encoding.
+ */
+ if ((result == cmNotFound) && !isHFSPlus && VCBTOHFS(volume)->hfs_encoding != 0) {
+ Str31 hfsName;
+
+ utf8_to_mac_roman(strlen(name), name, hfsName);
+ result = LocateCatalogNode(volume, parentID, (CatalogName*)hfsName,
+ 0, &nodeKey, &nodeData, &nodeHint);
+ }
ReturnIfError(result);
if (nodeData.recordType == kHFSPlusFileRecord)