コード例 #1
0
        public FCB ReadFCB(int disknum, int item, string harddisk)
        {
            FileStream Disk   = new FileStream(harddisk, FileMode.Open);
            FCB        buffer = new FCB();

            Disk.Seek(64 * (disknum - 1) + 8 * (item - 1), SeekOrigin.Begin);
            Disk.Read(buffer.Name, 0, 3);
            buffer.Type      = Convert.ToByte(Disk.ReadByte());
            buffer.Attribute = Convert.ToByte(Disk.ReadByte());
            buffer.Address   = Convert.ToByte(Disk.ReadByte());
            buffer.Length    = Convert.ToChar(Disk.ReadByte());
            Disk.Close();
            return(buffer);
        }
コード例 #2
0
        public void WriteFile(int disknumber, int Itemnumber, FCB buffer, string harddisk)
        {
            FileStream Disk = new FileStream(harddisk, FileMode.Open);

            if (disknumber > 0 && Itemnumber > 0)
            {
                Disk.Seek(64 * (disknumber - 1) + 8 * (Itemnumber - 1), SeekOrigin.Begin);
                Disk.Write(buffer.Name, 0, buffer.Name.Length);
                Disk.Seek(0, SeekOrigin.Current);
                Disk.WriteByte(buffer.Type);
                Disk.Seek(0, SeekOrigin.Current);
                Disk.WriteByte(buffer.Attribute);
                Disk.Seek(0, SeekOrigin.Current);
                Disk.WriteByte(buffer.Address);
                Disk.Seek(0, SeekOrigin.Current);
                Disk.WriteByte(Convert.ToByte(buffer.Length));
            }
            Disk.Close();
        }
コード例 #3
0
        public void DeepCopyFile(string pathname1, string pathname2, string harddisk1, string harddisk2)
        {
            string[]     pnames       = pathname1.Split(new char[] { '\\', '.' });
            string       halfpathname = pathname1.Remove(pathname1.Length - 6);
            char         attribute    = Convert.ToChar(pnames[pnames.Length - 1]);
            UTF8Encoding utf          = new UTF8Encoding();

            byte[] name = utf.GetBytes(pnames[pnames.Length - 2]);
            int    disknum;

            if (pnames.Length == 3)   //c:\aaa.e
            {
                disknum = 3;
            }
            else
            {
                disknum = Search(halfpathname, harddisk1);
            }
            int item   = FindItem(disknum, name, attribute, harddisk1)[0]; //获取文件在目录的第几项
            FCB buffer = ReadFCB(disknum, item, harddisk1);

            int [] dnums = FindDiskNumber(buffer.Address, harddisk1);   //获取文件占用的所有盘块号

            //读取文件的内容
            FileStream Disk = new FileStream(harddisk1, FileMode.Open);

            byte[] content = new byte[64 * dnums.Length];
            for (int i = 0; i < dnums.Length; i++)
            {
                Disk.Seek(64 * (dnums[i] - 1), SeekOrigin.Begin);
                Disk.Read(content, 64 * i, 64);
            }
            Disk.Close();

            pathname2 = pathname2 + '\\' + pnames[pnames.Length - 2] + '.' + pnames[pnames.Length - 1];
            DialogResult result = new DialogResult();

            if (Search(pathname2, harddisk2) == 2)
            {
                result = MessageBox.Show("文件存在,是否覆盖?", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                if (result == DialogResult.OK)
                {
                    DeleteFile(pathname2, harddisk2);
                    int[] nums = SearchFAT(dnums.Length, harddisk2);                                            //获取空盘块
                    RecordFileFAT(nums, harddisk2);                                                             //记录文件FAT
                    WriteContent(nums, content, harddisk2);                                                     //写入文件内容
                    CreateFile(pathname2, buffer.Attribute, Convert.ToByte(nums[0]), buffer.Length, harddisk2); //FCB写入新目录内
                }
                if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            else
            {
                int[] nums = SearchFAT(dnums.Length, harddisk2);                                            //获取空盘块
                RecordFileFAT(nums, harddisk2);                                                             //记录文件FAT
                WriteContent(nums, content, harddisk2);                                                     //写入文件内容
                CreateFile(pathname2, buffer.Attribute, Convert.ToByte(nums[0]), buffer.Length, harddisk2); //FCB写入新目录内
            }
        }