示例#1
0
        /// <returns>Record index</returns>
        public long?AllocateRecord(long searchStartIndex, long searchEndIndex, uint transactionID)
        {
            long bufferedVCN = -1;

            byte[] bufferedClusterBytes = null;

            for (long index = searchStartIndex; index <= searchEndIndex; index++)
            {
                long currentVCN = index / (Volume.BytesPerCluster * 8);
                if (currentVCN != bufferedVCN)
                {
                    bufferedClusterBytes = ReadCluster(currentVCN);
                    bufferedVCN          = currentVCN;
                }

                int bitOffsetInCluster = (int)(index % (Volume.BytesPerCluster * 8));
                if (IsBitClear(bufferedClusterBytes, bitOffsetInCluster))
                {
                    if (!this.AttributeRecord.IsResident)
                    {
                        BitmapRange bitmapRange   = new BitmapRange((uint)bitOffsetInCluster, 1);
                        byte[]      operationData = bitmapRange.GetBytes();
                        ulong       streamOffset  = (ulong)(currentVCN * Volume.BytesPerCluster);
                        Volume.LogClient.WriteLogRecord(FileRecord.BaseSegmentReference, this.AttributeRecord, streamOffset, Volume.BytesPerCluster, NTFSLogOperation.SetBitsInNonResidentBitMap, operationData, NTFSLogOperation.ClearBitsInNonResidentBitMap, operationData, transactionID);
                    }
                    SetBit(bufferedClusterBytes, bitOffsetInCluster);
                    WriteCluster(currentVCN, bufferedClusterBytes);
                    return(index);
                }
            }

            return(null);
        }
示例#2
0
        public void DeallocateRecord(long recordIndex, uint transactionID)
        {
            long currentVCN         = recordIndex / (Volume.BytesPerCluster * 8);
            int  bitOffsetInCluster = (int)(recordIndex % (Volume.BytesPerCluster * 8));

            byte[] clusterBytes = ReadCluster(currentVCN);
            if (!IsBitClear(clusterBytes, bitOffsetInCluster))
            {
                if (!this.AttributeRecord.IsResident)
                {
                    BitmapRange bitmapRange   = new BitmapRange((uint)bitOffsetInCluster, 1);
                    byte[]      operationData = bitmapRange.GetBytes();
                    ulong       streamOffset  = (ulong)(currentVCN * Volume.BytesPerCluster);
                    Volume.LogClient.WriteLogRecord(FileRecord.BaseSegmentReference, this.AttributeRecord, streamOffset, Volume.BytesPerCluster, NTFSLogOperation.ClearBitsInNonResidentBitMap, operationData, NTFSLogOperation.SetBitsInNonResidentBitMap, operationData, transactionID);
                }
                ClearBit(clusterBytes, bitOffsetInCluster);
                WriteCluster(currentVCN, clusterBytes);
            }
        }