@@ -179,10 +179,10 @@ MfsEnsureRecordSpace(
179179 size_t sectorCount = (size_t )(DIVUP ((spaceRequired - entry -> AllocatedSize ), mfs -> SectorSize ));
180180 size_t bucketCount = DIVUP (sectorCount , mfs -> SectorsPerBucket );
181181 uint32_t bucketPointer , previousBucketPointer ;
182- MapRecord_t iterator , link ;
182+ MapRecord_t iterator , record ;
183183
184184 // Perform the allocation of buckets
185- if (MFSBucketMapAllocate (mfs , bucketCount , & link ) != OS_EOK ) {
185+ if (MFSBucketMapAllocate (mfs , bucketCount , & record ) != OS_EOK ) {
186186 ERROR ("Failed to allocate %u buckets for file" , bucketCount );
187187 return OS_EDEVFAULT ;
188188 }
@@ -193,20 +193,24 @@ MfsEnsureRecordSpace(
193193 while (bucketPointer != MFS_ENDOFCHAIN ) {
194194 previousBucketPointer = bucketPointer ;
195195 if (MFSBucketMapGetLengthAndLink (mfs , bucketPointer , & iterator ) != OS_EOK ) {
196- ERROR ("MfsEnsureRecordSpace failed to get link for bucket %u" , bucketPointer );
196+ ERROR ("MfsEnsureRecordSpace: failed to get record for bucket %u" , bucketPointer );
197197 return OS_EDEVFAULT ;
198198 }
199199 bucketPointer = iterator .Link ;
200200 }
201201
202202 // We have a special case if previous == MFS_ENDOFCHAIN
203203 if (previousBucketPointer == MFS_ENDOFCHAIN ) {
204+ TRACE ("MfsEnsureRecordSpace: initializing record %ms to start=0x%x, length=0x%x" ,
205+ entry -> Name , record .Link , record .Length );
204206 // This means file had nothing allocated
205- entry -> StartBucket = link .Link ;
206- entry -> StartLength = link .Length ;
207+ entry -> StartBucket = record .Link ;
208+ entry -> StartLength = record .Length ;
207209 } else {
208- if (MFSBucketMapSetLinkAndLength (mfs , previousBucketPointer , link .Link , link .Length , true) != OS_EOK ) {
209- ERROR ("Failed to set link for bucket %u" , previousBucketPointer );
210+ TRACE ("MfsEnsureRecordSpace: extending record %ms at bucket=0x%x with link=0x%x, length=0x%x" ,
211+ entry -> Name , previousBucketPointer , record .Link , record .Length );
212+ if (MFSBucketMapSetLinkAndLength (mfs , previousBucketPointer , record .Link , 0 , false) != OS_EOK ) {
213+ ERROR ("Failed to set record for bucket %u" , previousBucketPointer );
210214 return OS_EDEVFAULT ;
211215 }
212216 }
@@ -233,33 +237,40 @@ MFSCloneBucketData(
233237oserr_t
234238MFSAdvanceToNextBucket (
235239 _In_ FileSystemMFS_t * mfs ,
236- _In_ MFSEntry_t * entry ,
237- _In_ size_t bucketSizeBytes )
240+ _In_ MFSEntry_t * entry )
238241{
239- MapRecord_t link ;
242+ MapRecord_t record ;
240243 uint32_t nextDataBucketPosition ;
244+ size_t bucketSizeBytes = mfs -> SectorsPerBucket * mfs -> SectorSize ;
245+ size_t currentLinkLength ;
241246
242- // We have to look up the link for current bucket
243- if (MFSBucketMapGetLengthAndLink (mfs , entry -> DataBucketPosition , & link ) != OS_EOK ) {
244- ERROR ("MFSAdvanceToNextBucket failed to get link for bucket %u" , entry -> DataBucketPosition );
247+ // We have to look up the record for current bucket
248+ if (MFSBucketMapGetLengthAndLink (mfs , entry -> DataBucketPosition , & record ) != OS_EOK ) {
249+ ERROR ("MFSAdvanceToNextBucket failed to get record for bucket %u" , entry -> DataBucketPosition );
245250 return OS_EDEVFAULT ;
246251 }
252+ TRACE ("MFSAdvanceToNextBucket: bucket 0x%x, record=0x%x, length=0x%x" ,
253+ entry -> DataBucketPosition , record .Link , record .Length );
247254
248255 // Check for EOL
249- if (link .Link == MFS_ENDOFCHAIN ) {
256+ if (record .Link == MFS_ENDOFCHAIN ) {
250257 return OS_ENOENT ;
251258 }
252- nextDataBucketPosition = link .Link ;
253259
254- // Lookup length of link
255- if (MFSBucketMapGetLengthAndLink (mfs , entry -> DataBucketPosition , & link ) != OS_EOK ) {
260+ currentLinkLength = (record .Length * bucketSizeBytes );
261+ nextDataBucketPosition = record .Link ;
262+
263+ // Lookup length of record
264+ if (MFSBucketMapGetLengthAndLink (mfs , record .Link , & record ) != OS_EOK ) {
256265 ERROR ("Failed to get length for bucket %u" , entry -> DataBucketPosition );
257266 return OS_EDEVFAULT ;
258267 }
268+ TRACE ("MFSAdvanceToNextBucket: bucket 0x%x, record=0x%x, length=0x%x" ,
269+ nextDataBucketPosition , record .Link , record .Length );
259270
260271 // Store length & Update bucket boundary
272+ entry -> BucketByteBoundary += currentLinkLength ;
261273 entry -> DataBucketPosition = nextDataBucketPosition ;
262- entry -> DataBucketLength = link .Length ;
263- entry -> BucketByteBoundary += (link .Length * bucketSizeBytes );
274+ entry -> DataBucketLength = record .Length ;
264275 return OS_EOK ;
265276}
0 commit comments