]> git.saurik.com Git - apple/hfs.git/blame - fsck_hfs/dfalib/SCatalog.c
hfs-522.0.9.tar.gz
[apple/hfs.git] / fsck_hfs / dfalib / SCatalog.c
Content-type: text/html ]> git.saurik.com Git - apple/hfs.git/blame - fsck_hfs/dfalib/SCatalog.c


500 - Internal Server Error

Malformed UTF-8 character (fatal) at /usr/lib/x86_64-linux-gnu/perl5/5.40/HTML/Entities.pm line 485, <$fd> line 284.
CommitLineData
51e135ce
A
1/*
2 * Copyright (c) 1999-2000, 2002, 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#include "Scavenger.h"
25
26
27OSErr FlushCatalogFile( SVCB *vcb )
28{
29 OSErr err;
30
31 err = BTFlushPath(vcb->vcbCatalogFile);
32 if ( err == noErr )
33 {
34 if( ( vcb->vcbCatalogFile->fcbFlags & fcbModifiedMask ) != 0 )
35 {
36 (void) MarkVCBDirty( vcb );
37 err = FlushVolumeControlBlock( vcb );
38 }
39 }
40
41 return( err );
42}
43
44OSErr LocateCatalogNode(SFCB *fcb, BTreeIterator *iterator, FSBufferDescriptor *btRecord, UInt16 *reclen)
45{
46 CatalogRecord * recp;
47 CatalogKey * keyp;
48 CatalogName * namep = NULL;
49 UInt32 threadpid = 0;
50 OSErr result;
51 Boolean isHFSPlus = false;
52
53 result = BTSearchRecord(fcb, iterator, kInvalidMRUCacheKey, btRecord, reclen, iterator);
54 if (result == btNotFound)
55 result = cmNotFound;
56 ReturnIfError(result);
57
58 recp = (CatalogRecord *)btRecord->bufferAddress;
59 keyp = (CatalogKey*)&iterator->key;
60
61 /* if we got a thread record, then go look up real record */
62 switch (recp->recordType) {
63 case kHFSFileThreadRecord:
64 case kHFSFolderThreadRecord:
65 threadpid = recp->hfsThread.parentID;
66 namep = (CatalogName *) &recp->hfsThread.nodeName;
67 isHFSPlus = false;
68 break;
69
70 case kHFSPlusFileThreadRecord:
71 case kHFSPlusFolderThreadRecord:
72 threadpid = recp->hfsPlusThread.parentID;
73 namep = (CatalogName *) &recp->hfsPlusThread.nodeName;
74 isHFSPlus = true;
75 break;
76
77 default:
78 threadpid = 0;
79 break;
80 }
81
82 if (threadpid) {
83 (void) BTInvalidateHint(iterator);
84 BuildCatalogKey(threadpid, namep, isHFSPlus, keyp);
85 result = BTSearchRecord(fcb, iterator, kInvalidMRUCacheKey, btRecord, reclen, iterator);
86 }
87
88 return result;
89}
90
91
92OSErr
93UpdateFolderCount(SVCB *vcb, HFSCatalogNodeID pid, const CatalogName *name, SInt16 newType,
94 UInt32 hint, SInt16 valenceDelta)
95{
96 CatalogRecord tempData; // 520 bytes
97 HFSCatalogNodeID folderID;
98 UInt16 reclen;
99 OSErr result;
100 BTreeIterator btIterator;
101 FSBufferDescriptor btRecord;
102
103 btRecord.bufferAddress = &tempData;
104 btRecord.itemCount = 1;
105 btRecord.itemSize = sizeof(tempData);
106
107 ClearMemory(&btIterator, sizeof(btIterator));
108 btIterator.hint.nodeNum = hint;
109 BuildCatalogKey(pid, name, vcb->vcbSignature == kHFSPlusSigWord, (CatalogKey*)&btIterator.key);
110 result = LocateCatalogNode(vcb->vcbCatalogFile, &btIterator, &btRecord, &reclen);
111 ReturnIfError(result);
112
113 if (vcb->vcbSignature == kHFSPlusSigWord) {
114 UInt32 timeStamp;
115
116 timeStamp = GetTimeUTC();
117 tempData.hfsPlusFolder.valence += valenceDelta; // adjust valence
118 tempData.hfsPlusFolder.contentModDate = timeStamp; // set date/time last modified
119 folderID = tempData.hfsPlusFolder.folderID;
120 } else /* kHFSSigWord */ {
121 tempData.hfsFolder.valence += valenceDelta; // adjust valence
122 tempData.hfsFolder.modifyDate = GetTimeLocal(true); // set date/time last modified
123 folderID = tempData.hfsFolder.folderID;
124 }
125
126 result = BTReplaceRecord(vcb->vcbCatalogFile, &btIterator, &btRecord, reclen);
127 ReturnIfError(result);
128
129 if (folderID == kHFSRootFolderID) {
130 if (newType == kHFSFolderRecord || newType == kHFSPlusFolderRecord)
131 vcb->vcbNmRtDirs += valenceDelta; // adjust root folder count (undefined for HFS Plus)
132 else
133 vcb->vcbNmFls += valenceDelta; // adjust root file count (used by GetVolInfo)
134 }
135
136 if (newType == kHFSFolderRecord || newType == kHFSPlusFolderRecord)
137