コード例 #1
0
 public Sector(BootSector bs, int SectorNumber)
 {
     sectorData = new byte[0]; //This is to shut the compiler up.
     BPB        = bs;
     sNumber    = SectorNumber;
     ReRead();
 }
コード例 #2
0
 public RootDirectory(BootSector boots)
 {
     BPB         = boots;
     RootSectors = BPB.ReadSectors(
         BPB.RootDirectorySector,
         RootDirectorySectors
         );
 }
コード例 #3
0
        public static BootSector Create(byte[] block, FileStream fstream)
        {
            BootSector ret = new BootSector();

            ret.FATStream = fstream;
            if (block.Length < 512)
            {
                throw new InvalidOperationException("Array must be >= 512 bytes");
            }
            //So much simpler :)
            Helpers.DataLayout.Fill <BootSector>(block, ret);
            ret.FATEntries = new FAT(ret, ret.FATStream);
            return(ret);
        }
コード例 #4
0
        public static Cluster Load(BootSector bs, ushort clusterNum)
        {
            Cluster       ret     = new Cluster();
            List <Sector> Sectors = new List <Sector>();

            for (int x = 0; x < bs.SectorsPerCluster; x++)
            {
                Sector tmp = new Sector(bs, x + bs.ClusterToSector(clusterNum));
                Sectors.Add(tmp);
            }
            ret.Sectors = Sectors.ToArray();
            ret.number  = clusterNum;
            ret.BPB     = bs;
            return(ret);
        }
コード例 #5
0
        public static BootSector Load(string filename)
        {
            FileInfo fi = new FileInfo(filename);
            //Don't bother error checking, Any exceptions
            //Will be passed up the call chain.
            //They can deal with any bee's or wasps they
            //Decide to anger.
            FileStream fs = fi.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            BootSector bs = Load(fs);

            //We opened it, The bee's won't get angry if we close it. :)
            //fs.Close();
            //Oh yes they will, Now that we use the stream for a long time
            //After its made. DO NOT ANGER THE BEES.
            return(bs);
        }
コード例 #6
0
 public static byte[] GetBytes(BootSector bs)
 {
     //This is going to be a pain in the arse.
     byte[] ret = new byte[512];
     //Lets copy the easy stuff first.
     //First arrays can be copied with Array.Copy
     Array.Copy(bs.jmpInstruction, ret, 3);
     Array.Copy(bs.OSBootCode, 0, ret, 0x3e, 448);
     //Next single byte values can be written out
     //Directly to the array
     ret[0x0D] = bs.SectorsPerCluster;
     ret[0x10] = bs.TotalFats;
     ret[0x15] = (byte)bs.Descriptor;
     ret[0x24] = (byte)bs.DiskType;
     ret[0x25] = bs.CurrentHead;
     ret[0x26] = bs.ExtendedBootSig;
     //And thats it for the 1 byte values.
     //Now, For the strings...
     Array.Copy(GetFSString(bs.OEMName, 8), 0, ret, 0x03, 8);
     Array.Copy(GetFSString(bs.FSType, 8), 0, ret, 0x36, 8);
     Array.Copy(GetFSString(bs.VolLabel, 11), 0, ret, 0x2b, 11);
     //And finally, All ushorts and uints
     //Array.Copy(BitConverter.GetBytes(bs.BytesPerSector), 0, ret, 0x0B, 2);
     GetAndCopy(bs.BytesPerSector, ret, 0x0B);
     GetAndCopy(bs.ReservedSectorCount, ret, 0x0e);
     GetAndCopy(bs.MaxRootEntries, ret, 0x11);
     GetAndCopy(bs.TotalSectors, ret, 0x13);
     GetAndCopy(bs.SectorsPerFAT, ret, 0x16);
     GetAndCopy(bs.SectorsPerTrack, ret, 0x18);
     GetAndCopy(bs.NumberOfHeads, ret, 0x1A);
     GetAndCopy(bs.HiddenSectors, ret, 0x1c);
     GetAndCopy(bs.TotalSectors32, ret, 0x20);
     GetAndCopy(bs.SerialNumber, ret, 0x27);
     GetAndCopy(bs.BootSig, ret, 0x1FE);
     //Finally, Return ret.
     return(ret);
 }