public BlowerByLyf(IBlockDevice dev, uint npages) : base(dev,npages) { windowSize = npages * 1 / 2; //readLimit = (int)npages / 3; //writeLimit = (int)npages * 2 / 3; }
public LIRS_ByWu(IBlockDevice dev, uint npages, float hirPercent) : base(dev, npages) { hirSize = Math.Max((int)(npages * hirPercent),1); lirSize = npages - hirSize; lirNum = 0; }
/// <summary> /// Creates a new <see cref="SuperFloppyFormatter"/> for the specified /// <see cref="IBlockDevice"/>. /// </summary> /// <param name="device"></param> /// <exception cref="System.IO.IOException">IOException on error accessing the specified device</exception> private SuperFloppyFormatter(IBlockDevice device) { this.device = device; oemName = DEFAULT_OEM_NAME; fatCount = DEFAULT_FAT_COUNT; SetFatType(FatTypeFromDevice()); }
public FLRU(IBlockDevice dev, uint npages) : base(dev, npages) { //this.ratio = ratio; cacheSize = npages; readList = new FLIRSQueue(false); writeList = new FLIRSQueue(true); }
protected Sector(IBlockDevice device, long offset, int size) { this.offset = offset; this.device = device; var buf = new byte[size]; Buffer = new MemoryStream(buf); dirty = true; }
/// <summary> /// Writes a copy of this boot sector to the specified device, if a copy /// is requested. /// </summary> /// <param name="device">the device to write the boot sector copy to</param> /// <exception cref="System.IO.IOException">IOException on write error</exception> /// <seealso cref="GetBootSectorCopySector"/> public void WriteCopy(IBlockDevice device) { if (GetBootSectorCopySector() > 0) { long offset = GetBootSectorCopySector() * SIZE; Buffer.Position = 0; device.Write(offset, Buffer); } }
private IEnumerable <T> GetAllBlockDevices <T> () where T : IBlockDevice { foreach (Hal.Device hal_device in manager.FindDeviceByCapabilityAsDevice("block")) { IBlockDevice device = BlockDevice.Resolve <T> (manager, hal_device); if (device != null) { yield return((T)device); } } }
public static IBlockDevice Create(Uri.Locator resource) { IBlockDevice result = BlockDevice.Open(resource, System.IO.FileMode.Create); if (result.IsNull() && resource.NotNull()) { System.IO.Directory.CreateDirectory(resource.Path.FolderPath.PlatformPath); result = BlockDevice.Open(resource, System.IO.FileMode.Create); } return(result); }
private Fat16RootDirectory(Fat16BootSector bs, bool readOnly) : base(bs.GetRootDirEntryCount(), readOnly, true) { if (bs.GetRootDirEntryCount() <= 0) { throw new ArgumentException( "root directory size is " + bs.GetRootDirEntryCount()); } deviceOffset = FatUtils.GetRootDirOffset(bs); device = bs.GetDevice(); }
private Fat(BootSector bs, long offset) { this.bs = bs; fatType = bs.GetFatType(); if (bs.GetSectorsPerFat() > int.MaxValue) { throw new ArgumentException("FAT too large"); } if (bs.GetSectorsPerFat() <= 0) { throw new IOException( "boot sector says there are " + bs.GetSectorsPerFat() + " sectors per FAT"); } if (bs.GetBytesPerSector() <= 0) { throw new IOException( "boot sector says there are " + bs.GetBytesPerSector() + " bytes per sector"); } sectorCount = (int)bs.GetSectorsPerFat(); sectorSize = bs.GetBytesPerSector(); device = bs.GetDevice(); this.offset = offset; lastAllocatedCluster = FIRST_CLUSTER; if (bs.GetDataClusterCount() > int.MaxValue) { throw new IOException("too many data clusters"); } if (bs.GetDataClusterCount() == 0) { throw new IOException("no data clusters"); } lastClusterIndex = (int)bs.GetDataClusterCount() + FIRST_CLUSTER; entries = new long[(int)((sectorCount * sectorSize) / fatType.GetEntrySize())]; if (lastClusterIndex > entries.Length) { throw new IOException( "file system has " + lastClusterIndex + "clusters but only " + entries.Length + " FAT entries"); } }
/// <summary> /// Constructor for FatFileSystem in specified readOnly mode /// </summary> /// <param name="device">the <see cref="IBlockDevice"/> holding the file system</param> /// <param name="readOnly"></param> /// <param name="ignoreFatDifferences"></param> /// <exception cref="IOException">IOException on read error</exception> private FatFileSystem(IBlockDevice device, bool readOnly, bool ignoreFatDifferences) : base(readOnly) { bs = BootSector.Read(device); if (bs.GetNrFats() <= 0) { throw new IOException( "boot sector says there are no FATs"); } filesOffset = FatUtils.GetFilesOffset(bs); fatType = bs.GetFatType(); fat = Fat.Read(bs, 0); if (!ignoreFatDifferences) { for (var i = 1; i < bs.GetNrFats(); i++) { var tmpFat = Fat.Read(bs, i); if (!fat.Equals(tmpFat)) { throw new IOException("FAT " + i + " differs from FAT 0"); } } } if (fatType == FatType.BaseFat32) { var f32Bs = (Fat32BootSector)bs; var rootDirFile = new ClusterChain(fat, f32Bs.GetRootDirFirstCluster(), IsReadOnly()); rootDirStore = ClusterChainDirectory.ReadRoot(rootDirFile); fsiSector = FsInfoSector.Read(f32Bs); if (fsiSector.GetFreeClusterCount() != fat.GetFreeClusterCount()) { throw new IOException("free cluster count mismatch - fat: " + fat.GetFreeClusterCount() + " - fsinfo: " + fsiSector.GetFreeClusterCount()); } } else { rootDirStore = Fat16RootDirectory.Read((Fat16BootSector)bs, readOnly); fsiSector = null; } rootDir = new FatLfnDirectory(rootDirStore, fat, IsReadOnly()); }
static IBlockDevice Open(Uri.Locator resource, System.IO.FileMode mode) { IBlockDevice result = null; if (resource.NotNull()) { switch (resource.Scheme) { case "assembly": result = resource.Authority == "" ? BlockDevice.Open(System.Reflection.Assembly.GetEntryAssembly(), resource.Path) : BlockDevice.Open(System.Reflection.Assembly.Load(new System.Reflection.AssemblyName(resource.Authority)), resource.Path); break; case "file": try { System.IO.FileStream stream = System.IO.File.Open(System.IO.Path.GetFullPath(resource.PlatformPath), mode, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite); if (stream.NotNull()) { result = new BlockDevice(stream, resource); } } catch (System.IO.DirectoryNotFoundException) { result = null; } catch (System.IO.FileNotFoundException) { result = null; } break; case "http": case "https": if (mode == System.IO.FileMode.Open) { // TODO: support http and https. } break; } } return(result); }
public ClusterChain(Fat fat, long startCluster, bool readOnly) : base(readOnly) { this.fat = fat; if (startCluster != 0) { this.fat.TestCluster(startCluster); if (this.fat.IsFreeCluster(startCluster)) { throw new ArgumentException( "cluster " + startCluster + " is free"); } } device = fat.GetDevice(); dataOffset = FatUtils.GetFilesOffset(fat.GetBootSector()); this.startCluster = startCluster; clusterSize = fat.GetBootSector().GetBytesPerCluster(); }
public static DevStatInfo[] GatherStatistics(IBlockDevice dev, int level, int index, bool suppress) { IBufferManager mgr = dev as IBufferManager; ManagerGroup grp = mgr as ManagerGroup; DevStatInfo info = new DevStatInfo(); info.Id = new string(' ', level) + (mgr == null ? "Dev" : grp == null ? "Mgr" : "Group") + (index < 0 ? "" : index.ToString()); info.Name = new string(' ', level) + dev.Name; info.Description = (dev.Description == null ? "" : dev.Description); //........lyf....... dev = mgr.BaseDevice; info.Read = dev.ReadCount; info.Write = dev.WriteCount; info.Flush = 0; info.Cost = Utils.CalcTotalCost(dev); info.Suppress = suppress; if (mgr == null) return new DevStatInfo[] { info }; List<DevStatInfo> infos = new List<DevStatInfo>(); info.Flush = mgr.FlushCount; infos.Add(info); if (grp == null) ;//infos.AddRange(GatherStatistics(mgr.AssociatedDevice, level + 1, -1, false)); else for (int i = 0; i < grp.Count; i++) infos.AddRange(GatherStatistics(grp[i], level + 1, i, true)); return infos.ToArray(); }
public BlockBuffer(IBlockDevice blockDevice) { BlockDevice = blockDevice; _buffer = BlockDevice.ReadBlock(0); _readBuffer = BlockDevice.ReadBlock(0); }
static IBufferManager CreateCFLRU(IBlockDevice dev, uint npages, string[] args) { return new CFLRU(dev, npages, float.Parse(args[0])); }
static IBufferManager CreateTrival(IBlockDevice dev, uint npages, string[] args) { return new TrivalManager(dev); }
static IBufferManager CreateLIRS(IBlockDevice dev, uint npages, string[] args) { return new LIRS_ByWu(dev, npages, float.Parse(args[0])); }
public TrivalManager(IBlockDevice dev) : base(dev, 0) { }
public DiscVolume(DeviceArguments arguments, IBlockDevice b) : base(arguments, b) { }
public static BlockStream Wrap(IBlockDevice device) { return device.NotNull() ? new BlockStream(device) { CatchClose = true } : null; }
public SimpleFS(IBlockDevice blockDevice) { BlockDevice = blockDevice; BlockBuffer = new BlockBuffer(BlockDevice); }
public static BootSector Read(IBlockDevice device) { var b = new byte[512]; var bb = new MemoryStream(b); device.Read(0, bb); bb.Position = 510; if (bb.ReadByte() != 0x55) { throw new IOException( "missing boot sector signature"); } bb.Position = 511; if (bb.ReadByte() != 0xaa) { throw new IOException( "missing boot sector signature"); } bb.Position = SECTORS_PER_CLUSTER_OFFSET; var sectorsPerCluster = (byte)bb.ReadByte(); if (sectorsPerCluster <= 0) { throw new IOException( "suspicious sectors per cluster count " + sectorsPerCluster); } var rootDirEntriesB = new byte[2]; bb.Position = Fat16BootSector.ROOT_DIR_ENTRIES_OFFSET; bb.Read(rootDirEntriesB, 0, 2); if (!BitConverter.IsLittleEndian) { Array.Reverse(rootDirEntriesB, 0, 2); } int rootDirEntries = BitConverter.ToUInt16(rootDirEntriesB, 0); var rootDirSectors = ((rootDirEntries * 32) + (device.GetSectorSize() - 1)) / device.GetSectorSize(); var total16B = new byte[2]; bb.Position = TOTAL_SECTORS_16_OFFSET; bb.Read(total16B, 0, 2); if (!BitConverter.IsLittleEndian) { Array.Reverse(total16B, 0, 2); } int total16 = BitConverter.ToUInt16(total16B, 0); var total32B = new byte[4]; bb.Position = TOTAL_SECTORS_32_OFFSET; bb.Read(total32B, 0, 4); if (!BitConverter.IsLittleEndian) { Array.Reverse(total32B, 0, 4); } long total32 = BitConverter.ToUInt32(total32B, 0); var totalSectors = total16 == 0 ? total32 : total16; var fatSz16B = new byte[2]; bb.Position = Fat16BootSector.SECTORS_PER_FAT_OFFSET; bb.Read(fatSz16B, 0, 2); if (!BitConverter.IsLittleEndian) { Array.Reverse(fatSz16B, 0, 2); } int fatSz16 = BitConverter.ToUInt16(fatSz16B, 0); var fatSz32B = new byte[4]; bb.Position = Fat32BootSector.SECTORS_PER_FAT_OFFSET; bb.Read(fatSz32B, 0, 4); if (!BitConverter.IsLittleEndian) { Array.Reverse(fatSz32B, 0, 4); } long fatSz32 = BitConverter.ToUInt32(fatSz32B, 0); var fatSz = fatSz16 == 0 ? fatSz32 : fatSz16; var reservedSectorsB = new byte[2]; bb.Position = RESERVED_SECTORS_OFFSET; bb.Read(reservedSectorsB, 0, 2); if (!BitConverter.IsLittleEndian) { Array.Reverse(reservedSectorsB, 0, 2); } int reservedSectors = BitConverter.ToUInt16(reservedSectorsB, 0); bb.Position = FAT_COUNT_OFFSET; var fatCount = bb.ReadByte(); var dataSectors = totalSectors - (reservedSectors + (fatCount * fatSz) + rootDirSectors); var clusterCount = dataSectors / sectorsPerCluster; var result = (clusterCount > Fat16BootSector.MAX_FAT16_CLUSTERS) ? (BootSector) new Fat32BootSector(device) : (BootSector) new Fat16BootSector(device); result.Read(); return(result); }
protected BootSector(IBlockDevice device) : base(device, 0, SIZE) { MarkDirty(); }
/// <summary> /// Reads the file system structure from the specified <see cref="IBlockDevice"/> /// and returns a fresh <see cref="FatFileSystem"/> instance to read or modify it. /// </summary> /// <param name="device">the <see cref="IBlockDevice"/> holding the file system</param> /// <param name="readOnly">if the <see cref="FatFileSystem"/> should be in read-only mode</param> /// <returns>the <see cref="FatFileSystem"/> instance for the device</returns> /// <exception cref="IOException">IOException on read error or if the file system structure could /// not be parsed</exception> public static FatFileSystem Read(IBlockDevice device, bool readOnly) { return(new FatFileSystem(device, readOnly)); }
/// <summary> /// Retruns a <see cref="SuperFloppyFormatter"/> instance suitable for formatting /// the specified device. /// </summary> /// <param name="dev">the device that should be formatted</param> /// <returns>the formatter for the device</returns> /// <exception cref="System.IO.IOException">IOException on error creating the formatter</exception> public static SuperFloppyFormatter Get(IBlockDevice dev) { return(new SuperFloppyFormatter(dev)); }
private static void GenerateOutput(IBlockDevice dev, TextWriter output) { DevStatInfo[] infos = GroupOp.GatherStatistics(dev, 0, -1, false); int[] maxlens = { 0, 0, 0, 0, 0 }; foreach (var info in infos) { maxlens[0] = Math.Max(maxlens[0], info.Id.Length); maxlens[1] = Math.Max(maxlens[1], info.Read.ToString().Length); maxlens[2] = Math.Max(maxlens[2], info.Write.ToString().Length); maxlens[3] = Math.Max(maxlens[3], info.Flush.ToString().Length); maxlens[4] = Math.Max(maxlens[4], info.Cost.ToString().Length); } string formatId = string.Format("{{0,{0}}} ", -maxlens[0]); string formatCost = string.Format( "R:{{0,{0}}} W:{{1,{1}}} F:{{2,{2}}} C:{{3,{3}}} ", maxlens[1], maxlens[2], maxlens[3], maxlens[4]); string emptyCost = new string(' ', string.Format(formatCost, 0, 0, 0, 0).Length); foreach (var info in infos) { Utils.PushColor(ConsoleColor.Yellow); output.Write(formatId, info.Id); Utils.PopColor(); //if (info.Suppress) //output.Write(emptyCost); //else output.Write(formatCost, info.Read, info.Write, info.Flush, info.Cost); Utils.PushColor(ConsoleColor.Cyan); output.Write(info.Name + " "); Utils.PopColor(); Utils.PushColor(ConsoleColor.DarkGray); output.Write(info.Description); Utils.PopColor(); output.WriteLine(); } }
public Volume(DeviceArguments arguments, IBlockDevice blockdevice) : base(arguments) { block_parent = blockdevice; }
public CFLRU(IBlockDevice dev, uint npages, float windowSize) : base(dev, npages) { this.windowSize = windowSize; this.maxNonwindowLength = (int)(npages * (1 - windowSize)); }
// 已实现的 public BufferManagerBase(IBlockDevice device, uint npages) { this.dev = (device == null ? new NullBlockDevice() : device); this.pool = (npages == 0 ? null : new Pool(npages, dev.PageSize, OnPoolFull)); this.PageSize = dev.PageSize; }
private FsInfoSector(IBlockDevice device, long offset) : base(device, offset, BootSector.SIZE) { }
public LRUWSR(IBlockDevice dev, uint npages) : base(dev, npages) { }
static IBufferManager CreateCRAW(IBlockDevice dev, uint npages, string[] args) { return new CRAW(dev, npages, Ratio); }
public static BlockStream Open(IBlockDevice device) { return device.NotNull() ? new BlockStream(device) : null; }
static IBufferManager CreateLRUWSR(IBlockDevice dev, uint npages, string[] args) { return new LRUWSR(dev, npages); }
/// <summary> /// Creates a new <see cref="IFileSystem"/> for the specified device. When /// using this method, care must be taken that there is only one /// <see cref="IFileSystem"/> accessing the specified <see cref="IBlockDevice"/>. /// Otherwise severe file system corruption may occur. /// </summary> /// <param name="device">the device to create the file system for</param> /// <param name="readOnly">if the file system should be openend read-only</param> /// <returns>a new <see cref="IFileSystem"/> instance for the specified device</returns> /// <exception cref="UnknownFileSystemException">if the file system type could /// not be determined</exception> /// <exception cref="System.IO.IOException">IOException on read error</exception> public static IFileSystem Create(IBlockDevice device, bool readOnly) { return(FatFileSystem.Read(device, readOnly)); }
static IBufferManager CreateCCFLRU(IBlockDevice dev, uint npages, string[] args) { return new CCFLRU(dev, npages); }
protected override void Dispose(bool disposing) { if (this.backend.NotNull()) { this.backend.Dispose(); this.backend = null; } base.Dispose(disposing); }
static IBufferManager CreateCMFT(IBlockDevice dev, uint npages, string[] args) { return new CMFTByCat(dev, npages); }
BlockStream(IBlockDevice backend) { this.backend = backend; }
public CCFLRU(IBlockDevice dev, uint npages) : base(dev, npages) { }
FatFileSystem(IBlockDevice api, bool readOnly) : this(api, readOnly, false) { }
public FrameBasedManager(IBlockDevice dev, uint npages) : base(dev, npages) { }
/// <summary> /// Creates a new instance of <see cref="UnknownFileSystemException"/>. /// </summary> /// <param name="device">the <see cref="IBlockDevice"/> whose file system could not /// be determined</param> public UnknownFileSystemException(IBlockDevice device) : base("cannot determine file system type") { this.device = device; }
/// <summary> /// Creates a new <see cref="Fat16BootSector"/> for the specified device. /// </summary> /// <param name="device">the <see cref="IBlockDevice"/> holding the boot sector</param> public Fat16BootSector(IBlockDevice device) : base(device) { }
public CMFTByLyf(IBlockDevice dev, uint npages) : base(dev, npages) { }