Exemplo n.º 1
0
 public void createFile(string name, string rights)
 {
     if (MainProgram.fs.files.Count < MaxCountOfFiles)
     {
         DateTime dt = new DateTime();
         dt = DateTime.Now;
         // get first cluster
         ushort f_cl_ind = getFreeClust(true);
         if (f_cl_ind > 0)
         {
             myFile f = new myFile(myFile.generateID(), name, "txt",
                                   dt.ToString(), f_cl_ind, 0, rights, curDir, MainProgram.currentuser.getLogin());
             f.First_clust = f_cl_ind;
             // set value to listCl
             MainProgram.fs.listCl[f_cl_ind] = 500;
             MainProgram.fs.files.Add(f);
             MainProgram.fs.files[getIndOfCurFile()].Size++;
             output.Text += "Файл успешно создан" + Environment.NewLine + path + ">";
         }
         else
         {
             output.Text += "Нет свободных кластеров" + Environment.NewLine + path + ">";
         }
     }
     else
     {
         output.Text += "Превышено допустимое количество файлов/папок" + Environment.NewLine + path + ">";
     }
 }
Exemplo n.º 2
0
        public static void createRootDir()
        {
            string dt = "01.01.2015 01:01:01";
            myFile f  = new myFile(0, "ROOT", "",
                                   dt.ToString(), 0, 0, "rw", -1, "SYS");

            MainProgram.fs.files.Add(f);
        }
Exemplo n.º 3
0
 public void createFolder(string name, string rights)
 {
     if (MainProgram.fs.files.Count < MaxCountOfFiles)
     {
         DateTime dt = new DateTime();
         dt = DateTime.Now;
         myFile f = new myFile(myFile.generateID(), name, "",
                               dt.ToString(), 0, 0, rights, curDir, MainProgram.currentuser.getLogin());
         MainProgram.fs.files.Add(f);
         MainProgram.fs.files[getIndOfCurFile()].Size++;
         output.Text += "Папка успешно создана" + Environment.NewLine + path + ">";
     }
     else
     {
         output.Text += "Превышено допустимое количество файлов/папок" + Environment.NewLine + path + ">";
     }
 }
Exemplo n.º 4
0
        public static void FS_Start()
        {
            SuperBlock sb;

            ushort[]      listCl;
            List <myFile> listFiles;

            curDir = 0;
            //     int countOfFiles = CLUST_SIZE * (FILES_FIRST_CLUST - ROOT_FIRST_CLUST + 1) / FILE_STRUCT_SIZE; // 487 files can be created

            if (!File.Exists("MyFS.dat"))
            {
                sb = new SuperBlock("MyFS", CLUST_SIZE, FAT_FIRST_CLUST, ROOT_FIRST_CLUST, FILES_FIRST_CLUST, FILES_CLUST_COUNT);
                //   listCl = new ushort[CLUST_SIZE * (FILES_CLUST_COUNT - FILES_FIRST_CLUST + 1) / (CLUST_SIZE + FILE_STRUCT_SIZE)];
                //   listCl = new ushort[FILES_CLUST_COUNT - FILES_FIRST_CLUST+1];
                listCl    = new ushort[FILES_CLUST_COUNT];
                listFiles = new List <myFile>();
            }
            else
            {
                BinaryReader br = new BinaryReader(File.Open("MyFS.dat", FileMode.Open), Encoding.UTF8);

                sb = new SuperBlock(br.ReadString(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16());
                //  listCl = new ushort[CLUST_SIZE * (FILES_CLUST_COUNT - FILES_FIRST_CLUST + 1) / (CLUST_SIZE + FILE_STRUCT_SIZE)];
                listCl = new ushort[FILES_CLUST_COUNT - FILES_FIRST_CLUST + 1];
                br.BaseStream.Seek((FAT_FIRST_CLUST - 1) * CLUST_SIZE, SeekOrigin.Begin);
                int iCl = 0;                       // number of cluster
                while (iCl < listCl.Length && br.BaseStream.Position < (ROOT_FIRST_CLUST - 1) * CLUST_SIZE)
                {                                  //br.PeekChar() != -1 &&
                    listCl[iCl] = br.ReadUInt16(); // value for cluster iCl
                    iCl++;
                }
                listFiles = new List <myFile>();
                br.BaseStream.Seek((ROOT_FIRST_CLUST - 1) * CLUST_SIZE, SeekOrigin.Begin);
                int iFile = 0;  // number of file
                while (br.PeekChar() != -1 && ((FILES_FIRST_CLUST - 1) * CLUST_SIZE) >= br.BaseStream.Position + FILE_STRUCT_SIZE)
                {
                    myFile temp = new myFile();
                    listFiles.Add(temp);
                    listFiles[iFile].id = br.ReadInt32();
                    if (listFiles[iFile].id == -1)
                    {
                        listFiles.Remove(temp);
                        break;
                    }
                    listFiles[iFile].Name = br.ReadString();

                    /*  if (listFiles[iFile].Name == "")
                     * {
                     *    listFiles.Remove(temp);
                     *    break;
                     * } */
                    listFiles[iFile].Extend      = br.ReadString();
                    listFiles[iFile].Date_time   = br.ReadString();
                    listFiles[iFile].First_clust = br.ReadUInt16();
                    listFiles[iFile].Size        = br.ReadInt32();
                    listFiles[iFile].Rights      = br.ReadString();
                    listFiles[iFile].Parent_dir  = br.ReadInt32();
                    listFiles[iFile].Owner       = br.ReadString(); // ...
                    iFile++;
                }
                br.Close();
            }
            MainProgram.fs = new FS(sb, listCl, listFiles);
            if (MainProgram.fs.files.Count == 0)
            {
                createRootDir(); FS_Save();
            }
        }