Exemplo n.º 1
0
        public static void create_file(string name, string path, string user_name)
        {
            file f = new file();

            f.name = name; // задаем имя
                           // поиск свободного inode в блоках
            f.attributes = function_inode.Search_free_inode();
            f.attributes.inode_number  = 2;
            f.attributes.free          = false; // устанавливаем inode как занятый
            f.attributes.di_size       = 1024;
            f.attributes.di_uid        = user_name;
            f.attributes.di_mtime      = DateTime.Now;
            f.attributes.di_ctime      = DateTime.Now;
            f.attributes.dimode.type   = "file";
            f.attributes.dimode.rights = "rw---";
            f.attributes.di_addr[0]    = function_inode.Search_free_cluster();
            function_inode.SetFalse(f.attributes.di_addr[0]);

            //Если файл с таким именем еще нет, то создаем, иначе оповещаем пользователя
            if (!Is_file(name, path))
            {
                // cоздание папки по пути
                string[] path_l = path.Split('/');
                catalog  temp   = new catalog();
                temp.attributes = Main.Root.attributes;
                temp.name       = Main.Root.name;
                temp.List       = Main.Root.List;

                for (int i = 0; i < path_l.Count() - 1; i++)
                {
                    temp.name = path_l[i];
                    for (int j = 0; j < temp.List.Count; j++)
                    {
                        if ((temp.List[j].name == path_l[i]) && (i != path_l.Count()))
                        {
                            temp.attributes = temp.List[j].attributes;
                            temp.name       = temp.List[j].name;
                            catalog ab = (catalog)temp.List[j];
                            temp.List = ab.List;
                        }
                    }
                }
                temp.List.Add(f);
                Program.myForm.Log.Text += "Файл '" + name + "' создан \n\n";
            }
            else
            {
                Program.myForm.Log.Text += "Файл с именем '" + f.name + "' уже существует!\n\n";
            }
        }
Exemplo n.º 2
0
 public static void modify_file(file f, string text = "")
 {
     //Сохраняем консоль
     Form1.history = Program.myForm.Log.Text;
     //Очищаем консоль и позволяем пользователю писать в ней,
     //при этом блокируем поле для ввода команд
     Program.myForm.Log.Text         = "";
     Program.myForm.Log.ReadOnly     = false;
     Program.myForm.Command.ReadOnly = true;
     Program.myForm.Log.Select();
     //Наполняем содержимым файла, если мы его редактируем
     if (text != "")
     {
         Program.myForm.Log.Text = text;
     }
     f.attributes.di_mtime = DateTime.Now;
     //Указываем файл, в который будем записывать
     Form1.record = f;
 }
Exemplo n.º 3
0
        public static DateTime edit_file(file t)
        {
            string l = Program.myForm.Log.Text;

            Program.myForm.Log.Text = "";
            //Если учетная запись админа или если создателю можно записывать, или если другим пользователям можно записывать

            /*if ((Main.Sess.user_name == "admin") ||
             *  ((t.attributes.di_uid == Main.Sess.user_name) && (function_inode.rights_for_all(t)[1])) ||
             *  ((function_inode.rights_for_all(t)[3])))
             * {*/
            if (l.Length <= Main.claster)     // размер не превышает размеры кластера
            {
                for (int i = 0; i < t.attributes.di_addr.Count(); i++)
                {
                    int k;
                    k = t.attributes.di_addr[i];
                    for (int j = 0; j < Main.Super.Blocks.Count; j++)
                    {
                        for (int y = 0; y < Main.Super.Blocks[j].claster.Count(); y++)
                        {
                            if (k == Main.Super.Blocks[j].claster[y].number)
                            {
                                Main.Super.Blocks[j].claster[y].data = l;
                                return(DateTime.Now);
                            }
                        }
                    }
                }
            }

            //если выходит за пределы кластера

            //начальный адрес выделения подстроки
            int    count = Main.claster;
            string q     = l.Substring(0, count);

            int n = t.attributes.di_addr[0];

            for (int j = 0; j < Main.Super.Blocks.Count; j++)
            {
                for (int y = 0; y < Main.Super.Blocks[j].claster.Count(); y++)
                {
                    if (n == Main.Super.Blocks[j].claster[y].number)
                    {
                        {
                            Main.Super.Blocks[j].claster[y].data = q;
                        }
                    }
                }
            }


            while ((l.Length > count + Main.claster))                      //пока позиция меньше или равна количеству символов в строке
            {
                q = l.Substring(count, Main.claster);                      //выделяем подстроку
                {
                    int u = function_inode.Search_free_cluster();          //ищем свободный кластер
                    for (int e = 0; e < t.attributes.di_addr.Count(); e++) //проход по списку кластеров
                    {
                        if (t.attributes.di_addr[e] == 0)                  //свободная запись для номера кластера
                        {
                            t.attributes.di_addr[e] = u;                   //присваиваем новый номер
                            function_inode.SetFalse(u);                    //устанавливаем его в false
                            break;
                        }
                    }
                    for (int j = 0; j < Main.Super.Blocks.Count; j++)
                    {
                        for (int y = 0; y < Main.Super.Blocks[j].claster.Count(); y++)
                        {
                            if (u == Main.Super.Blocks[j].claster[y].number)
                            {
                                {
                                    Main.Super.Blocks[j].claster[y].data = q;
                                }
                            }
                        }
                    }
                }
                count += Main.claster;     // следующая позиция
            }
            if (l.Count() > 0)
            {
                q = l.Substring(count);
                int u = function_inode.Search_free_cluster();          //ищем свободный кластер
                for (int e = 0; e < t.attributes.di_addr.Count(); e++) //проход по списку кластеров
                {
                    if (t.attributes.di_addr[e] == 0)                  //свободная запись для номера кластера
                    {
                        t.attributes.di_addr[e] = u;                   //присваиваем новый номер
                        function_inode.SetFalse(u);                    //устанавливаем его в false
                        break;
                    }
                }
                for (int j = 0; j < Main.Super.Blocks.Count; j++)
                {
                    for (int y = 0; y < Main.Super.Blocks[j].claster.Count(); y++)
                    {
                        if (u == Main.Super.Blocks[j].claster[y].number)
                        {
                            {
                                Main.Super.Blocks[j].claster[y].data = q;
                            }
                        }
                    }
                }
            }
            Program.myForm.Log.Text += "Файл '" + t.name + "' записан\n\n";

            /*}
             * else
             * {
             *  Program.myForm.Log.Text += "Вам не разрешено записывать в этот файл. \nВы не являетесь владельцем данного файла.\n\n";
             * }*/
            return(DateTime.Now);
        }
Exemplo n.º 4
0
        public void MainMenu()
        {
            if (Sess.user_id != 0)
            {
                switch (Program.myForm.Command.Text)
                {
                case "process":
                {
                    Core core = new Core(4);
                    core.init();
                    Core.proc[1].Memory = Core.proc[0].Memory;
                    Core.mem[0].process.Add(Core.proc[1].PID);
                    core.Planning();

                    break;
                }

                case "mount":
                {
                    mount();
                    break;
                }

                case "user_to_file":
                {
                    Serializing_User.Ser(Sess.user_list);
                    break;
                }

                case "inode_map":
                {
                    Program.myForm.Log.Text += "Block.Inode" + "\n";
                    List <string> t = Super.FreeInode();
                    for (int i = 0; i < t.Count; i++)
                    {
                        Program.myForm.Log.Text += t[i] + "\n";
                    }
                    break;
                }

                case "claster_map":
                {
                    Program.myForm.Log.Text += "Block.Claster" + "\n";
                    List <string> t = Super.FreeClaster();
                    for (int i = 0; i < t.Count; i++)
                    {
                        Program.myForm.Log.Text += t[i] + "\n";
                    }
                    break;
                }

                case "exit":
                {
                    function_user.new_session();
                    break;
                }

                case "lf":
                {
                    catalog t = new catalog();
                    t = function_dir.See_folder(Sess.path);
                    if (t.List.Count == 0)
                    {
                        Program.myForm.Log.Text += "В папке '" + t.name + "' пусто!\n\n";
                    }
                    else
                    {
                        Program.myForm.Log.Text += "Папка '" + t.name + "' содержит:" + "\n";
                        for (int i = 0; i < t.List.Count; i++)
                        {
                            Program.myForm.Log.Text += t.List[i].name + " (" + t.List[i].attributes.dimode.type + ")\n";
                        }
                        Program.myForm.Log.Text += "\n";
                    }
                    break;
                }

                default:
                {
                    Regex  regex   = new Regex(@"^(?<command>[A-Za-z_]+)[ ]*");
                    Match  matches = regex.Match(Program.myForm.Command.Text);
                    string command = String.Empty;
                    if (matches.Success)
                    {
                        command = matches.Groups["command"].Value.ToString();
                    }
                    switch (command)
                    {
//--------------------------------------- пользователи
                    case "create_user":
                    {
                        if (Main.Sess.user_name == "admin")
                        {
                            function_user.Create_user(Program.myForm.Command.Text);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Для добавления учетной записи нужны права администратора!\n\n";
                        }
                        break;
                    }

                    case "del_user":
                    {
                        if (Main.Sess.user_name == "admin")
                        {
                            function_user.Delete_user(Program.myForm.Command.Text);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Для удаления учетной записи нужны права администратора!\n\n";
                        }
                        break;
                    }

                    case "reset_pass":
                    {
                        if (Main.Sess.user_name == "admin")
                        {
                            function_user.resetPass(Program.myForm.Command.Text);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Для изменения пароля учетной записи нужны права администратора!\n\n";
                        }
                        break;
                    }

//--------------------------------------- папки
                    case "create_dir":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<dir>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["dir"].Value.ToString();
                            function_dir.create_dir(dir, Sess.path, Sess.user_name);
                            Serializing.Ser(Super.Blocks);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректое имя директории!\n\n";
                        }
                        break;
                    }

                    case "way":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<dir>[./A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["dir"].Value.ToString();
                            if (dir == "./")
                            {
                                string[] match = Sess.path.Split('/');
                                Sess.path = "";
                                for (int i = 0; i < match.Count() - 2; i++)
                                {
                                    Sess.path += match[i] + '/';
                                }
                            }
                            else
                            {
                                Sess.path = function_dir.Search_folder(dir, Sess.path);
                            }
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректый путь!\n\n";
                        }
                        break;
                    }

                    case "rename":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<folder>[A-Za-z0-9]+)[|](?<rename>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["folder"].Value.ToString();
                            string rename = matches.Groups["rename"].Value.ToString();
                            {
                                string c = Sess.path + dir + "/";
                                function_dir.ren_folder(c, rename);
                                Serializing.Ser(Super.Blocks);
                            }
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введена команда!\nВведите rename <oldName>|<newName>\n\n";
                        }
                        break;
                    }

                    case "del_dir":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<folder>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["folder"].Value.ToString();
                            {
                                function_dir.Dell_folder(Sess.path, dir);
                                Serializing.Ser(Super.Blocks);
                            }
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя директории!\n\n";
                        }
                        break;
                    }

//--------------------------------------- файлы
                    case "create_file":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<fil>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string fil = String.Empty;
                        if (matches.Success)
                        {
                            fil = matches.Groups["fil"].Value.ToString();
                            function_file.create_file(fil, Sess.path, Sess.user_name);
                            Serializing.Ser(Super.Blocks);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя файла!\n\n";
                        }
                        break;
                    }

                    case "del_file":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<fil>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string fil = String.Empty;
                        if (matches.Success)
                        {
                            fil = matches.Groups["fil"].Value.ToString();
                            {
                                string c = Sess.path;
                                function_dir.Dell_folder(c, fil);
                                Serializing.Ser(Super.Blocks);
                            }
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя файла!\n\n";
                        }
                        break;
                    }

                    case "insert_file":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<files>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["files"].Value.ToString();
                            Boolean tr = function_file.Is_file(dir, Main.Sess.path);
                            if (tr)
                            {
                                file f = new file();                                     //нужный файл
                                f = function_file.search_file_retf(dir, Main.Sess.path); //поиск нужного файла
                                                                                         //Если учетная запись админа или если создателю можно записывать, или если другим пользователям можно записывать
                                if ((Main.Sess.user_name == "admin") ||
                                    ((f.attributes.di_uid == Main.Sess.user_name) && (function_inode.rights_for_all(f)[1])) ||
                                    ((function_inode.rights_for_all(f)[3])))
                                {
                                    function_file.modify_file(f);
                                }
                                else
                                {
                                    Program.myForm.Log.Text += "Вам не разрешено редактировать этот файл. \nВы не являетесь владельцем данного файла.\n\n";
                                }
                            }
                            else
                            {
                                Program.myForm.Log.Text += "Файл не существует или у вас нет прав для доступа к нему\n\n";
                            }
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя файла!\n\n";
                        }
                        break;
                    }


                    case "edit_file":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<files>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["files"].Value.ToString();
                            Boolean tr = function_file.Is_file(dir, Main.Sess.path);
                            if (tr)
                            {
                                //Находим текст файла
                                file f = new file();                                     //нужный файл
                                f = function_file.search_file_retf(dir, Main.Sess.path); //поиск нужного файла
                                //Если учетная запись админа или если создателю можно записывать, или если другим пользователям можно записывать
                                if ((Main.Sess.user_name == "admin") ||
                                    ((f.attributes.di_uid == Main.Sess.user_name) && (function_inode.rights_for_all(f)[1])) ||
                                    ((function_inode.rights_for_all(f)[3])))
                                {
                                    string text = function_file.see_file(dir, Main.Sess.path);
                                    function_file.modify_file(f, text);
                                }
                                else
                                {
                                    Program.myForm.Log.Text += "Вам не разрешено редактировать этот файл. \nВы не являетесь владельцем данного файла.\n\n";
                                }
                            }
                            else
                            {
                                Program.myForm.Log.Text += "Файл не существует или у вас нет прав на его редактирование\n\n";
                            }
                            Serializing.Ser(Super.Blocks);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя файла!\n\n";
                        }
                        break;
                    }

                    case "watch_file":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<files>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["files"].Value.ToString();
                            Program.myForm.Log.Text += function_file.see_file(dir, Main.Sess.path) + "\n\n";
                            Serializing.Ser(Super.Blocks);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя файла!\n\n";
                        }
                        break;
                    }

                    case "attr":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<files>[A-Za-z0-9]+)");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir = String.Empty;
                        if (matches.Success)
                        {
                            dir = matches.Groups["files"].Value.ToString();
                            Program.myForm.Log.Text += function_file.attr(dir, Main.Sess.path);
                            Serializing.Ser(Super.Blocks);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя!\n\n";
                        }
                        break;
                    }

                    case "rights":
                    {
                        Regex regex_d = new Regex(@"^(?<command>[A-Za-z_]+)[ ](?<files>[A-Za-z0-9]+)[ ](?<rights>[r-][w-]-[r-][w-])");
                        matches = regex_d.Match(Program.myForm.Command.Text);
                        string dir    = String.Empty;
                        string rights = String.Empty;
                        if (matches.Success)
                        {
                            dir    = matches.Groups["files"].Value.ToString();
                            rights = matches.Groups["rights"].Value.ToString();
                            function_inode.rights(dir, Main.Sess.path, rights);
                            Serializing.Ser(Super.Blocks);
                        }
                        else
                        {
                            Program.myForm.Log.Text += "Некорректно введено имя или права!\n\n";
                        }
                        break;
                    }

                    default:
                    {
                        Program.myForm.Log.Text += Program.myForm.Command.Text + ": Неизвестная команда\n\n";
                        break;
                    }
                    }
                    break;
                }
                }
            }
            else
            {
                if (Program.myForm.Command.Text != "")
                {
                    bool result = Start(Program.myForm.Command.Text);
                    if (!result)
                    {
                        Program.myForm.Log.Text += "Необходимо войти в систему!\n\n";
                    }
                }
            }
        }