/// <param name="io">The delegate I/O adapter</param>
 /// <param name="blockOff">The block offset address into the I/O adapter that maps to the start index (0) of this window
 ///     </param>
 /// <param name="len">The size of this window in bytes</param>
 public BlockAwareBinWindow(BlockAwareBin io, int blockOff, int len)
 {
     _bin      = io;
     _blockOff = blockOff;
     _len      = len;
     _disabled = false;
 }
Exemple #2
0
		/// <param name="io">The delegate I/O adapter</param>
		/// <param name="blockOff">The block offset address into the I/O adapter that maps to the start index (0) of this window
		/// 	</param>
		/// <param name="len">The size of this window in bytes</param>
		public BlockAwareBinWindow(BlockAwareBin io, int blockOff, int len)
		{
			_bin = io;
			_blockOff = blockOff;
			_len = len;
			_disabled = false;
		}
		/// <exception cref="Db4objects.Db4o.Ext.OldFormatException"></exception>
		/// <exception cref="Db4objects.Db4o.Ext.DatabaseReadOnlyException"></exception>
		protected sealed override void OpenImpl()
		{
			Config4Impl configImpl = ConfigImpl;
			IStorage storage = configImpl.Storage;
			bool isNew = !storage.Exists(FileName());
			if (isNew)
			{
				LogMsg(14, FileName());
				CheckReadOnly();
				_handlers.OldEncryptionOff();
			}
			bool readOnly = configImpl.IsReadOnly();
			bool lockFile = Debug4.lockFile && configImpl.LockFile() && (!readOnly);
			if (NeedsLockFileThread())
			{
				IBin fileBin = storage.Open(new BinConfiguration(FileName(), false, 0, false, configImpl
					.BlockSize()));
				IBin synchronizedBin = new SynchronizedBin(fileBin);
				_file = new BlockAwareBin(synchronizedBin);
			}
			else
			{
				IBin bin = storage.Open(new BinConfiguration(FileName(), lockFile, 0, readOnly, configImpl
					.BlockSize()));
				if (configImpl.AsynchronousSync())
				{
					bin = new ThreadedSyncBin(bin);
				}
				_file = new BlockAwareBin(bin);
			}
			if (isNew)
			{
				ConfigureNewFile();
				if (configImpl.ReservedStorageSpace() > 0)
				{
					Reserve(configImpl.ReservedStorageSpace());
				}
				CommitTransaction();
				WriteHeader(true, false);
			}
			else
			{
				ReadThis();
			}
		}
		private void ZeroFile(BlockAwareBin io, Slot slot)
		{
			if (io == null)
			{
				return;
			}
			byte[] zeroBytes = new byte[1024];
			int left = slot.Length();
			int offset = 0;
			while (left > zeroBytes.Length)
			{
				io.BlockWrite(slot.Address(), offset, zeroBytes, zeroBytes.Length);
				offset += zeroBytes.Length;
				left -= zeroBytes.Length;
			}
			if (left > 0)
			{
				io.BlockWrite(slot.Address(), offset, zeroBytes, left);
			}
		}
		private void CloseDatabaseFile()
		{
			try
			{
				SyncAndClose(_file);
			}
			finally
			{
				_file = null;
			}
		}