public async Task <IActionResult> Edit(int id, [Bind("ID,BarCode,Bank,Tag,CreateDate")] HardDisk hardDisk) { if (id != hardDisk.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(hardDisk); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HardDiskExists(hardDisk.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(hardDisk)); }
public override void OnSave(ConfigNode node) { try { node.AddValue("activated", ProcessorMode != ProcessorModes.OFF); if (HardDisk != null) { ConfigNode hdNode = HardDisk.ToConfigNode("harddisk"); node.AddNode(hdNode); } if (shared != null && shared.Cpu != null) { SafeHouse.Config.SaveConfig(); } base.OnSave(node); } catch (Exception ex) //Intentional Pokemon, if exceptions get out of here it can kill the craft { SafeHouse.Logger.Log("ONSAVE Exception: " + ex.TargetSite); SafeHouse.Logger.LogException(ex); } }
public static void SetArrayBlock(int index, byte value) { arrayBlock[index] = value; HardDisk.Write(new byte[1] { value }, SuperBlock.FSMStart + index); }
public static byte GetArrayInodeDirTable(int index) { byte[] buffer = new byte[1]; HardDisk.Read(ref buffer, SuperBlock.InodeDirTableStart + index); arrayInodeDirTable[index] = buffer[0]; return(arrayInodeDirTable[index]); }
public GptHardDrive(HardDisk hdd) { //check for MBR protective partition if (!MbrHardDisk.IsMbr(hdd)) { throw new Exception("Not MBR."); } if (MbrHardDisk.GetType(hdd, 0) != MbrPartitionType.GptProtective) { throw new Exception("Not GPT."); } mHeader = LoadHeader(hdd, SectorSize); var backup = LoadHeader(hdd, hdd.Length - SectorSize); List <PartitionEntry> parts = new List <PartitionEntry>(); for (int i = 0; i < mHeader.NumberOfPartitions; i++) { var partEnt = GetLba <PartitionEntry>(hdd, mHeader.StartingLbaOfPartitionEntries, i * mHeader.SizeOfPartitionEntry); if (partEnt.Type == Guid.Empty) { continue; } parts.Add(partEnt); } mPartition = parts.Where(p => sZfsPartitionTypes.Contains(p.Type)).Single(); Init(hdd, SectorSize * mPartition.FirstLba, SectorSize * (mPartition.LastLba - mPartition.FirstLba)); }
public static void SetArrayInodeDirTable(int index, byte value) { arrayInodeDirTable[index] = value; HardDisk.Write(new byte[1] { value }, SuperBlock.InodeDirTableStart + index); }
//public PartitionHardDisk[] Partition; public HardDisk[] GetDevice() { List <HardDisk> arrayHardDisk = new List <HardDisk>(); ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive"); foreach (ManagementObject queryObj in searcher.Get()) { HardDisk tempHardDisk = new HardDisk(); tempHardDisk.SerialNumber = queryObj["SerialNumber"] != null ? queryObj["SerialNumber"].ToString() : "Nodata"; tempHardDisk.Caption = queryObj["Caption"] != null ? queryObj["Caption"].ToString() : "Nodata"; tempHardDisk.Size = queryObj["Size"] != null ? (Convert.ToDouble(queryObj["Size"]) / 1073741824).ToString() : "Nodata"; tempHardDisk.PartitionValue = queryObj["Partitions"] != null ? queryObj["Partitions"].ToString() : "Nodata"; /* * try * { * ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition"); * * foreach (ManagementObject queryObj in searcher.Get()) * { * Console.WriteLine("Caption: {0}", queryObj["Caption"]); * Console.WriteLine("Size : {0}", (long.Parse(queryObj["Size"].ToString()) / 1073741824).ToString()); * Console.WriteLine("Type: {0}", queryObj["Type"]); * } * } * catch (ManagementException e) * { * ; * } */ arrayHardDisk.Add(tempHardDisk); } return(arrayHardDisk.ToArray()); }
public async Task <IActionResult> Edit(int id, [Bind("Naziv,Proizvodjac,Cijena,Kapacitet,Brzina,Id")] HardDisk hardDisk) { if (id != hardDisk.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(hardDisk); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HardDiskExists(hardDisk.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(hardDisk)); }
private void PlayMovie() { HardDisk.ProvideMovieData(); Cpu.Handle(); SoundCard.Show(); GraphicsCard.Play(); }
public async Task <IHttpActionResult> PostHardDisk(HardDisk HardDisk) { if (HardDisk == null) { return(BadRequest("Отсутствует тело элемента")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _db.HardDisks.Add(HardDisk); try { await _db.SaveChangesAsync(); } catch (DbUpdateException) { if (HardDiskExists(HardDisk.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = HardDisk.Id }, HardDisk)); }
public unsafe VdiHardDisk(HardDisk hdd) : base(hdd) { var headBytes = hdd.ReadBytes(0, sizeof(VdiHeader)); VdiHeader head = Program.ToStruct<VdiHeader>(headBytes); if (head.ImageSig != VdiMagic) throw new Exception("Wrong magic."); if (head.Version != VdiVersion) throw new Exception("Wrong version."); if (head.SizeOfHeader != VdiHeadSize) throw new Exception("Wrong size."); if (head.ImageType != ImageType.Dynamic) throw new NotImplementedException("Only dynamic is supported."); var dataOffset = head.OffsetData; mBlockOffsets = new long[head.BlocksInHdd]; mBlockSize = (int)head.BlockSize; for (long i = 0; i < head.BlocksInHdd; i++) { uint blockLoc; hdd.Get<uint>(head.OffsetBlocks + i * 4, out blockLoc); if (blockLoc == ~0u) mBlockOffsets[i] = -1; else mBlockOffsets[i] = dataOffset + blockLoc * mBlockSize; } }
private GptHeader LoadHeader(HardDisk hdd, long offset) { GptHeader ret; hdd.Get(offset, out ret); //LBA 1 if (ret.Signature != EfiMagic) { throw new Exception("Not a GPT."); } if (ret.Revision != CurrentRevision) { throw new Exception("Wrong rev."); } if (ret.HeaderSize < CurrentHeaderSize) { throw new Exception("Wrong header size."); } //TODO: check crc if (ret.SizeOfPartitionEntry != ParitionEntrySize) { throw new Exception("Wrong ParitionEntrySize."); } //TODO: check partition entry CRC if (ret.NumberOfPartitions == 0) { throw new Exception("No partitions!"); } return(ret); }
public static HardDisk Create(HardDisk hdd) { byte[] headBytes = hdd.ReadBytes(hdd.Length - 512, 512); VhdHeader head = Program.ToStructFromBigEndian <VhdHeader>(headBytes); if (head.CookieStr != "conectix") { throw new Exception("missing magic string"); } if (head.FileFormatVersion != 0x00010000) { throw new Exception("upsupported version"); } //TODO: validate checksum if (head.DiskType == DiskType.Fixed) { return(new FixedVhd(hdd, in head)); } else if (head.DiskType == DiskType.Dynamic) { return(new DynamicVhd(hdd, in head)); } else { throw new Exception("Only fixed size VHDs are supported."); } }
public static void SetInodeID(string name, int ID) { byte[] buffer = System.Text.Encoding.ASCII.GetBytes(name); HardDisk.Write(buffer, SuperBlock.InodeNameAndIDTableStart + ID * SuperBlock.InodeNameLength); nameInode[ID] = name; }
public object Add(HardDisk hardDisk) { _context.HardDiskSizes.Add(hardDisk); _context.SaveChanges(); return(new SuccessResponse()); }
public static MbrPartitionType GetType(HardDisk hdd, int index) { MbrHeader h; hdd.Get(0, out h); return(h.GetPartition(index).Type); }
public static bool IsMbr(HardDisk hdd) { MbrHeader h; hdd.Get(0, out h); return(h.BootSig == MbrHeader.MbrMagic); }
public ATA() { foreach (DiskElement drive in SystemConfig.Machine.Disks) { ATADrive newDrive; if (drive.Type == DriveType.HardDisk) { newDrive = new HardDisk(); } else if (drive.Type == DriveType.CDROM) { newDrive = new CDROM(); } else { break; } newDrive.LoadImage(drive.Image); diskDrives.Add(newDrive); } primarySelected = true; }
private static T GetLba <T>(HardDisk hdd, long absoluteLba, long extraOffset) where T : struct { long byteOffset = absoluteLba * SectorSize + extraOffset; T ret; hdd.Get <T>(byteOffset, out ret); return(ret); }
public void SetArrayFile(int index, int number) { byte[] buffer = new byte[4]; buffer = BitConverter.GetBytes(SuperBlock.InodeStart + SuperBlock.InodeSize * number); HardDisk.Write(buffer, SuperBlock.InodeDirStart + dirID * SuperBlock.InodeDirSize + 4 * index); arrayFile[index] = SuperBlock.InodeStart + SuperBlock.InodeSize * number; }
public int GetArrayBlock(int index) { byte[] buffer = new byte[4]; HardDisk.Read(ref buffer, SuperBlock.InodeStart + fileID * SuperBlock.InodeSize + 4 * index); arrayBlocks[index] = BitConverter.ToInt32(buffer, 0); return(arrayBlocks[index]); }
protected OffsetTableHardDisk(HardDisk hdd) { if (hdd == null) throw new ArgumentNullException(nameof(hdd)); mHdd = hdd; mReadBlock = readBlock; mGetBlockKey = getBlockKey; }
public static byte GetArrayBlock(int index) { byte[] buffer = new byte[1]; HardDisk.Read(ref buffer, SuperBlock.FSMStart + index); arrayBlock[index] = buffer[0]; return(arrayBlock[index]); }
public void SetArrayBlock(int index, int number) { byte[] buffer = new byte[4]; buffer = BitConverter.GetBytes(number * SuperBlock.BlockSize + SuperBlock.BlockStart); HardDisk.Write(buffer, SuperBlock.InodeStart + fileID * SuperBlock.InodeSize + 4 * index); arrayBlocks[index] = number * SuperBlock.BlockSize + SuperBlock.BlockStart; }
public int GetArrayDir(int index) { byte[] buffer = new byte[4]; HardDisk.Read(ref buffer, SuperBlock.InodeDirStart + dirID * SuperBlock.InodeDirSize + 4 * SuperBlock.InodeMaxCountInDir + 4 * index); arrayDir[index] = BitConverter.ToInt32(buffer, 0); return(arrayDir[index]); }
/// <summary> /// The method convert from EntityModel to model of hardDisk /// </summary> /// <param name="hardDisk">HardDisk hardDisk</param> /// <returns>Models.HardDisk</returns> public Models.HardDisk NewHardDisk(HardDisk hardDisk) { return(new Models.HardDisk { Id = hardDisk.Id, HDD = hardDisk.HDD, SSD = hardDisk.SSD }); }
public static HardDisk Create(HardDisk hdd, long offset, long size) { while (hdd is OffsetHardDisk) { var off = (OffsetHardDisk)hdd; offset += off.mOffset; hdd = off.mHdd; } return new OffsetHardDisk(hdd, offset, size); }
public static HardDisk Create(HardDisk hdd, long offset, long size) { while (hdd is OffsetHardDisk) { var off = (OffsetHardDisk)hdd; offset += off.mOffset; hdd = off.mHdd; } return(new OffsetHardDisk(hdd, offset, size)); }
public async Task <IActionResult> Create([Bind("Naziv,Proizvodjac,Cijena,Kapacitet,Brzina")] HardDisk hardDisk) { if (ModelState.IsValid) { _context.Add(hardDisk); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(hardDisk)); }
protected void Init(HardDisk hdd, long offset, long size) { if (offset < 0) throw new ArgumentOutOfRangeException(); if (offset + size > hdd.Length) throw new ArgumentOutOfRangeException(); mHdd = hdd; mOffset = offset; mSize = size; }
public LeafVdevInfo(HardDisk hdd) { this.HDD = hdd; var rentedBytes = Program.RentBytes(VDEV_PHYS_SIZE); try { if (!hdd.ReadLabelBytes(rentedBytes, VDEV_SKIP_SIZE)) throw new Exception("Invalid checksum on lable config data!"); Config = new NvList(rentedBytes); } finally { Program.ReturnBytes(rentedBytes); rentedBytes = default(ArraySegment<byte>); } //figure out how big the uber blocks are var vdevTree = Config.Get<NvList>("vdev_tree"); var ubShift = (int)vdevTree.Get<ulong>("ashift"); ubShift = Math.Max(ubShift, UBERBLOCK_SHIFT); ubShift = Math.Min(ubShift, MAX_UBERBLOCK_SHIFT); var ubSize = 1 << ubShift; var ubCount = VDEV_UBERBLOCK_RING >> ubShift; List<uberblock_t> blocks = new List<uberblock_t>(); var ubBytes = Program.RentBytes(ubSize); try { for (long i = 0; i < ubCount; i++) { var offset = VDEV_SKIP_SIZE + VDEV_PHYS_SIZE + ubSize * i; if (!hdd.ReadLabelBytes(ubBytes, offset)) continue; uberblock_t b = Program.ToStruct<uberblock_t>(ubBytes.Array, ubBytes.Offset); if (b.Magic == uberblock_t.UbMagic) { blocks.Add(b); } } } finally { Program.ReturnBytes(ubBytes); ubBytes = default(ArraySegment<byte>); } this.Uberblock = blocks.OrderByDescending(u => u.Txg).ThenByDescending(u => u.TimeStamp).First(); const int VDevLableSizeStart = 4 << 20; const int VDevLableSizeEnd = 512 << 10; hdd = OffsetHardDisk.Create(hdd, VDevLableSizeStart, hdd.Length - VDevLableSizeStart - VDevLableSizeEnd); this.HDD = hdd; }
public async Task <IActionResult> Create([Bind("ID,BarCode,Bank,Tag,CreateDate")] HardDisk hardDisk) { if (ModelState.IsValid) { _context.Add(hardDisk); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(hardDisk)); }
public async Task <bool> CreateHardDiskPart(HardDiskServiceModel hardDiskServiceModel) { HardDisk hardDiskEntity = hardDiskServiceModel.To <HardDisk>(); hardDiskEntity.Id = Guid.NewGuid().ToString(); bool result = await this.pCCDbContext.AddAsync(hardDiskEntity) != null; await this.pCCDbContext.SaveChangesAsync(); return(result); }
/// <summary> /// Constructor, initialize all attributes except id, state and date /// </summary> /// <param name="clientName">ClientName to initialize</param> /// <param name="os">Operative system to initialize</param> /// <param name="type">Computer type to initialize</param> /// <param name="processor">Processor to initialize</param> /// <param name="hardDisk">Hard disk to initialize</param> /// <param name="ram">RAM to initialize</param> /// <param name="desc">Description to initialize</param> /// <param name="graphicCard">Graphic card to initialize</param> public Computer(string clientName, OS os, ComType type, Processor processor, HardDisk hardDisk, RAM ram, string desc, GraphicCard graphicCard) { this.clientName = clientName; this.operativeSystem = os; this.type = type; this.processor = processor; this.hardDisk = hardDisk; this.ram = ram; this.desc = desc; this.date = DateTime.Now; this.state = State.Recibida; this.graphicCard = graphicCard; }
public Laptop(string model, string manufacturer, Processor processor, int ramMemory, string graphicsCard, HardDisk hardDisk, Screen screen, Battery battery, double price) { this.Model = model; this.Manufacturer = manufacturer; this.Processor = processor; this.RamMemory = ramMemory; this.GraphicsCard = graphicsCard; this.HardDisk = hardDisk; this.Screen = screen; this.Battery = battery; this.Price = price; }
public static HardDisk Create(HardDisk hdd) { VhdHeader head = GetHeader(hdd); if (head.CookieStr != "conectix") throw new Exception("missing magic string"); if (head.FileFormatVersion != 0x00010000) throw new Exception("upsupported version"); if (head.DiskType == DiskType.Fixed) { return new FixedVhd(hdd); } else if (head.DiskType == DiskType.Dynamic) { return new DynamicVhd(hdd); } else { throw new Exception("Only fixed size VHDs are supported."); } }
public DynamicVhd(HardDisk hdd) : base(hdd) { VhdHeader head = GetHeader(hdd); int dySize = Program.SizeOf<DynamicHeader>(); DynamicHeader dyhead = Program.ToStructByteSwap<DynamicHeader>(hdd.ReadBytes(head.DataOffset, dySize)); if (dyhead.CookieStr != "cxsparse") throw new Exception("missing magic string"); if (dyhead.HeaderVersion != 0x00010000) throw new NotSupportedException("wrong version"); if (dyhead.ParentUniqueID != Guid.Empty) throw new NotSupportedException("Differencing disks not supported."); mSize = head.CurrentSize; mBlockSize = dyhead.BlockSize; int sectorBitmapSize = (mBlockSize / SECTOR_SIZE) / 8; int numberOfBlocks = (int)(mSize / mBlockSize); if (numberOfBlocks > dyhead.MaxTableEntries) throw new Exception(); mBlockOffsets = new long[numberOfBlocks]; var bat = hdd.ReadBytes(dyhead.TableOffset, numberOfBlocks * 4); for (int i = 0; i < numberOfBlocks; i++) { Program.ByteSwap(typeof(int), bat, i * 4); long batEntry = Program.ToStruct<int>(bat, i * 4); if (batEntry != -1) { batEntry *= SECTOR_SIZE; //skip the sector bitmap, since we don't support differencing disks batEntry += sectorBitmapSize; } mBlockOffsets[i] = batEntry; } }
public FixedVhd(HardDisk hdd) { long size = hdd.Length - 512; var head = GetHeader(hdd); if (head.CurrentSize != size) throw new Exception(); Init(hdd, 0, size); }
static VhdHeader GetHeader(HardDisk hdd) { return Program.ToStructByteSwap<VhdHeader>(hdd.ReadBytes(hdd.Length - 512, 512)); }
private OffsetHardDisk(HardDisk hdd, long offset, long size) { Init(hdd, offset, size); }
public VhdxHardDisk(HardDisk hdd) : base(hdd) { VHDX_REGION_TABLE_ENTRY batRegion, metadataRegion; GetRegions(out batRegion, out metadataRegion); VHDX_FILE_PARAMETERS fileParams; uint logicalSectorSize; ReadMetadata(metadataRegion, out fileParams, out mVirtualDiskSize, out logicalSectorSize); if (fileParams.HasParent) throw new NotImplementedException("Differencing disk are not supported."); //check all these calculations to make sure our assumptions about data sizes are correct checked { mBlockSize = (int)fileParams.BlockSize; int chunkRatio = (int)((1L << 23) * logicalSectorSize / mBlockSize); int dataBlockCount = (int)Math.Ceiling((decimal)mVirtualDiskSize / mBlockSize); int sectorBitmapCount = (int)Math.Ceiling((decimal)dataBlockCount / chunkRatio); int totalBatEntries = dataBlockCount + (int)Math.Floor((dataBlockCount - 1) / (decimal)chunkRatio); if (batRegion.Length < Program.SizeOf<VHDX_BAT_ENTRY>() * totalBatEntries) throw new Exception("Bat region is not big enough to contain all the bat entries!"); var batBytes = mHdd.ReadBytes((long)batRegion.FileOffset, (int)batRegion.Length); mBlockOffsets = new long[dataBlockCount]; int fileOffsetsNdx = 0; for (int i = 0; i < totalBatEntries; i++) { var isSectorBitmap = i % (chunkRatio + 1) == chunkRatio; var entry = Program.ToStruct<VHDX_BAT_ENTRY>(batBytes, i * Program.SizeOf<VHDX_BAT_ENTRY>()); if (isSectorBitmap) { if (entry.SectorBitmapState != SectorBitmapState.NotPresent) throw new Exception("Present bat entry!"); } else { long offset; switch (entry.PayloadState) { case PayloadBlockState.NotPresent: case PayloadBlockState.Undefined: case PayloadBlockState.BlockZero: case PayloadBlockState.Unmapped: offset = 0; break; case PayloadBlockState.FullyPresent: offset = entry.FileOffsetMB << 20; break; case PayloadBlockState.PartiallyPresent: throw new NotSupportedException("Partially present blocks are not supported."); default: throw new Exception($"Unknown BAT entry state: {entry.PayloadState}"); } if (offset == 0) offset = -1; mBlockOffsets[fileOffsetsNdx++] = offset; } } } }
public static bool IsMbr(HardDisk hdd) { MbrHeader h; hdd.Get(0, out h); return h.BootSig == MbrHeader.MbrMagic; }
public MbrHardDisk(HardDisk hdd, int partition) { hdd.Get(0, out mHeader); //for now, always assume a GPT partition if (!MbrHardDisk.IsMbr(hdd)) throw new Exception("Expected a MBR hdd."); if (MbrHardDisk.GetType(hdd, 0) != MbrPartitionType.GptProtective) throw new Exception("Expected a GPT protective MBR entry."); mPartition = mHeader.GetPartition(partition); Init(hdd, (long)mPartition.FirstSectorLba * MbrHeader.SectorSize, (long)mPartition.NumberOfSectors * MbrHeader.SectorSize); }
public HddVdev(NvList config, LeafVdevInfo hdd) : base(config) { this.mHdd = hdd.HDD; }
public static MbrPartitionType GetType(HardDisk hdd, int index) { MbrHeader h; hdd.Get(0, out h); return h.GetPartition(index).Type; }