Ejemplo n.º 1
0
        public void readPartitionTable()
        {
            currentPartitionList.Clear();
            if (selected.diskname == null || selected.diskname == "")
            {
                return;
            }
            var mbr = DiskRW.read(selected.diskname, 0);

            parse(mbr);
        }
Ejemplo n.º 2
0
        public static ErrorCode SetFileInfo(string drivename, FileInfo fat)
        {
            byte[] buffer = DiskRW.read(drivename, fat.Location);

            //name
            for (int i = 0; i < 63; i++)
            {
                buffer[i] = 0;
            }
            byte[] name = Encoding.Unicode.GetBytes(fat.Name);
            name.CopyTo(buffer, 0);

            name = Encoding.Unicode.GetBytes(fat.Extension);
            name.CopyTo(buffer, 64);

            //文件号 权限号 权限标记
            buffer[77] = fat.Type;
            buffer[78] = fat.AccessCode;
            buffer[79] = fat.AccessMode;

            //作者
            name = Encoding.Unicode.GetBytes(fat.Author);
            name.CopyTo(buffer, 80);
            //最后修改人
            name = Encoding.Unicode.GetBytes(fat.LastEditor);
            name.CopyTo(buffer, 112);

            //创建日期
            buffer[144] = (byte)(fat.CreateTime);
            buffer[145] = (byte)(fat.CreateTime >> 8);
            buffer[146] = (byte)(fat.CreateTime >> 16);
            buffer[147] = (byte)(fat.CreateTime >> 24);
            //修改日期
            buffer[148] = (byte)(fat.LastEditTime);
            buffer[149] = (byte)(fat.LastEditTime >> 8);
            buffer[150] = (byte)(fat.LastEditTime >> 16);
            buffer[151] = (byte)(fat.LastEditTime >> 24);

            //尾字节长
            buffer[152] = (byte)fat.Rest;
            buffer[153] = (byte)(fat.Rest >> 8);

            bool res = DiskRW.write(drivename, fat.Location, buffer);

            if (!res)
            {
                return(ErrorCode.Fail);
            }
            return(ErrorCode.Success);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取卷信息
        /// </summary>
        /// <param name="drivename">驱动器名</param>
        /// <param name="sectorstart">卷开始扇区</param>
        /// <returns>卷信息结构体</returns>
        static public VolumeInfo GetVolumeInfo(string drivename, UInt32 sectorstart)
        {
            VolumeInfo volumeinfo = new VolumeInfo();

            byte[] content = DiskRW.read(drivename, sectorstart);

            byte[] tmp = new byte[32];
            Array.Copy(content, tmp, 32);
            volumeinfo.VolumeName = System.Text.Encoding.Unicode.GetString(tmp);

            UInt32 s1 = content[32];
            UInt32 s2 = content[33];
            UInt32 s3 = content[34];
            UInt32 s4 = content[35];

            volumeinfo.SectorStart = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1;

            s1 = content[36];
            s2 = content[37];
            s3 = content[38];
            s4 = content[39];
            volumeinfo.SectorCount = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1;

            volumeinfo.Cluster = (UInt16)(((UInt16)content[40]) << 9);

            volumeinfo.VolumeLabel = content[41];

            s1 = content[42];
            s2 = content[43];
            s3 = content[44];
            s4 = content[45];
            volumeinfo.FreeTableStart = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1;

            volumeinfo.EncryptionType = content[48];

            return(volumeinfo);
        }
Ejemplo n.º 4
0
        void readPartitionTable()
        {
            currentPartitionList.Clear();
            byte[] MBR = DiskRW.read(Data.DriveName, 0);
            for (int i = 0, j = 0x1BE; i < 4; i++, j += 16)
            {
                var part = new Partition();

                //起始扇区偏移
                UInt32 s1   = MBR[8 + j];
                UInt32 s2   = MBR[9 + j];
                UInt32 s3   = MBR[10 + j];
                UInt32 s4   = MBR[11 + j];
                UInt32 temp = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1;
                part.StartSector = temp.ToString();
                part.SS          = temp;

                //长度 (扇区)
                s1      = MBR[12 + j];
                s2      = MBR[13 + j];
                s3      = MBR[14 + j];
                s4      = MBR[15 + j];
                temp    = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1;
                part.SC = temp;

                //长度为零说明没有这个分区
                if (temp == 0)
                {
                    continue;
                }

                part.SectorCount = temp.ToString();

                currentPartitionList.Add(part);
            }
        }