Example #1
0
        private void okButton_Click(object sender, EventArgs e)
        {
            Attributes attributes = new Attributes();
            attributes.readOnly = readOnlyCheckBox.Checked;
            attributes.hidden   = hiddenCheckBox.Checked;
            attributes.system   = systemCheckBox.Checked;
            Attributes = attributes;

            AccessRights accessRights = new AccessRights();
            accessRights.user.canRead      = userReadCheckBox.Checked;
            accessRights.user.canWrite     = userWriteCheckBox.Checked;
            accessRights.user.canExecute   = userExecuteCheckBox.Checked;
            accessRights.group.canRead     = groupReadCheckBox.Checked;
            accessRights.group.canWrite    = groupWriteCheckBox.Checked;
            accessRights.group.canExecute  = groupExecuteCheckBox.Checked;
            accessRights.others.canRead    = othersReadCheckBox.Checked;
            accessRights.others.canWrite   = othersWriteCheckBox.Checked;
            accessRights.others.canExecute = othersExecuteCheckBox.Checked;
            AccessRights = accessRights;
        }
Example #2
0
 /// <summary>
 /// Задаёт указанные атрибуты файлу или каталогу.
 /// Не изменяет текущий рабочий каталог.
 /// </summary>
 /// <param name="path">Путь к файлу или каталогу.</param>
 /// <param name="attributes">Атрибуты, которые будут заданы.</param>
 public void SetAttributes(string path, Attributes attributes)
 {
     FileSystem.SetAttributes(path, attributes);
 }
Example #3
0
        /// <summary>
        /// Задаёт указанные атрибуты файлу или каталогу.
        /// Не изменяет текущий рабочий каталог.
        /// </summary>
        /// <param name="path">Путь к файлу или каталогу.</param>
        /// <param name="attributes">Атрибуты, которые будут заданы.</param>
        public void SetAttributes(string path, Attributes attributes)
        {
            Directory current = CurrentDirectory;
            Utils.CheckPath(path);
            string fullPath = Utils.GetFullPath(path, CurrentDirectory.FullPath);
            string parentDirectoryPath = Utils.GetDirectoryName(fullPath);
            Directory directory = OpenDirectory(parentDirectoryPath);

            //AccessRights ar = directory.AccessRights;
            if (!Utils.GetAccessRightsGroup(UserId, GroupId, directory.UserId, directory.GroupId, directory.AccessRights).canExecute)
            {
                throw new UnauthorizedAccessException("Текущий пользователь не имеет доступа к изменению атрибутов объектов этого каталога!");
            }

            string fileName = Utils.GetFileName(path);
            MetaFile metaFile = directory.Find(fileName);

            if (metaFile == null)
            {
                throw new FileNotFoundException("Указанный файл или каталог не существует!", path);
            }

            Inode inode = new Inode();
            int sizeOfInode = Marshal.SizeOf(typeof(Inode));
            FileStream.Seek(_superblock.inodeArrayAddress + (metaFile.InodeId - 1) * sizeOfInode, SeekOrigin.Begin);
            inode = (Inode)ReadStruct(FileStream, typeof(Inode));
            inode.attributes = attributes.ToByte();
            FileStream.Seek(-sizeOfInode, SeekOrigin.Current);
            WriteStruct(FileStream, inode);

            FlushAll(false);

            CurrentDirectory = current;
        }
Example #4
0
        /// <summary>
        /// Записывает информацию о новом созданном файле на диск.
        /// </summary>
        /// <param name="fileName">Имя файла.</param>
        /// <param name="fileExtension">Расширение файла.</param>
        /// <param name="freeDirectoryRecordAddress">Адрес свободной записи в родительском каталоге.</param>
        /// <param name="freeInodeAddress">Адрес свободного индексного дескриптора.</param>
        /// <param name="freeInodeId">ID свободного индексного дескриптора.</param>
        /// <param name="freeDataClusterIndex">Индекс свободного блока данных.</param>
        private void FlushNewFile(string fileName, string fileExtension, int freeDirectoryRecordAddress, int freeInodeAddress, int freeInodeId, int freeDataClusterIndex)
        {
            DirectoryRecord newDirectoryRecord = new DirectoryRecord();
            newDirectoryRecord.fileName = fileName;
            newDirectoryRecord.fileExtension = fileExtension;
            newDirectoryRecord.fileInodeId = freeInodeId;

            Inode newFileInode = new Inode();
            newFileInode.fileType = FILE_INODE_TYPE;
            newFileInode.inodeId = freeInodeId;
            newFileInode.userId = UserId;
            newFileInode.groupId = GroupId;
            newFileInode.permissions = new AccessRights(true, true, false, true, false, false, true, false, false).ToInt16();
            Attributes attributes = new Attributes();
            attributes.hidden = false;
            attributes.readOnly = false;
            attributes.system = false;
            newFileInode.attributes = attributes.ToByte();
            newFileInode.fileSize = 0;
            newFileInode.datetimeFileCreated = Utils.GetTimestamp();
            newFileInode.datetimeFileModified = Utils.GetTimestamp();
            newFileInode.datetimeInodeModified = Utils.GetTimestamp();
            newFileInode.firstClusterIndex = freeDataClusterIndex;

            FileStream.Seek(freeDirectoryRecordAddress, SeekOrigin.Begin);
            WriteStruct(FileStream, newDirectoryRecord);
            FileStream.Seek(freeInodeAddress, SeekOrigin.Begin);
            WriteStruct(FileStream, newFileInode);
            FileStream.Seek(_superblock.dataAddress + (freeDataClusterIndex - 1) * CLUSTER_SIZE, SeekOrigin.Begin);

            // Записать один кластер файла
            FileStream.Write(BitConverter.GetBytes(LAST_CLUSTER_ID), 0, sizeof(int));
        }
Example #5
0
        /// <summary>
        /// Записывает информацию о новом созданном каталоге на диск.
        /// </summary>
        /// <param name="direcoryName">Имя каталога.</param>
        /// <param name="freeDirectoryRecordAddress">Адрес свободной записи в родительском каталоге.</param>
        /// <param name="freeInodeAddress">Адрес свободного индексного дескриптора.</param>
        /// <param name="freeInodeId">ID свободного индексного дескриптора.</param>
        /// <param name="parentInodeId">ID индексного дескриптора родительского каталога.</param>
        /// <param name="freeDataClusterIndex">Индекс свободного блока данных.</param>
        private void FlushNewDirectory(string direcoryName, int freeDirectoryRecordAddress, int freeInodeAddress, int freeInodeId, int parentInodeId, int freeDataClusterIndex)
        {
            DirectoryRecord newDirectoryRecord = new DirectoryRecord();
            newDirectoryRecord.fileName = direcoryName;
            newDirectoryRecord.fileExtension = string.Empty;
            newDirectoryRecord.fileInodeId = freeInodeId;

            Inode newDirectoryInode = new Inode();
            newDirectoryInode.fileType = DIRECTORY_INODE_TYPE;
            newDirectoryInode.inodeId = freeInodeId;
            newDirectoryInode.userId = UserId;
            newDirectoryInode.groupId = GroupId;
            newDirectoryInode.permissions = new AccessRights(true, true, true, true, false, true, true, false, true).ToInt16();
            Attributes attributes = new Attributes();
            attributes.hidden = false;
            attributes.readOnly = false;
            attributes.system = false;
            newDirectoryInode.attributes = attributes.ToByte();
            newDirectoryInode.fileSize = _superblock.clusterFactor * DISK_BYTES_PER_SECTOR;
            newDirectoryInode.datetimeFileCreated = Utils.GetTimestamp();
            newDirectoryInode.datetimeFileModified = Utils.GetTimestamp();
            newDirectoryInode.datetimeInodeModified = Utils.GetTimestamp();
            newDirectoryInode.firstClusterIndex = freeDataClusterIndex;

            FileStream.Seek(freeDirectoryRecordAddress, SeekOrigin.Begin);
            WriteStruct(FileStream, newDirectoryRecord);
            FileStream.Seek(freeInodeAddress, SeekOrigin.Begin);
            WriteStruct(FileStream, newDirectoryInode);
            FileStream.Seek(_superblock.dataAddress + (freeDataClusterIndex - 1) * CLUSTER_SIZE, SeekOrigin.Begin);

            // Записать один кластер каталога
            FileStream.Write(BitConverter.GetBytes(LAST_CLUSTER_ID), 0, sizeof(int));
            DirectoryRecord current = new DirectoryRecord();
            current.fileName = ".";
            current.fileExtension = "";
            current.fileInodeId = freeInodeId;
            DirectoryRecord parent = new DirectoryRecord();
            parent.fileName = "..";
            parent.fileExtension = "";
            parent.fileInodeId = parentInodeId;
            WriteStruct(FileStream, current);
            WriteStruct(FileStream, parent);

            int upperBound = (CLUSTER_SIZE - sizeof(int)) / Marshal.SizeOf(typeof(DirectoryRecord)) - 2;
            for (int i = 0; i < upperBound; i++)
            {
                DirectoryRecord directoryRecord = new DirectoryRecord();
                directoryRecord.fileInodeId = FREE_DIRECTORY_RECORD;
                directoryRecord.fileName = "";
                directoryRecord.fileExtension = "";
                WriteStruct(FileStream, directoryRecord);
            }
        }
Example #6
0
 public PropertiesForm(Attributes attributes, AccessRights accessRights)
     : this()
 {
     Attributes = attributes;
     AccessRights = accessRights;
 }