示例#1
0
        /// <summary>
        /// 根据 inode 建立 INodeDirectory
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="inode"></param>
        /// <returns></returns>
        public static INodeDirectory Load(VFSCore vfs, INode inode)
        {
            INodeDirectory t = new INodeDirectory(vfs, inode);

            t.Load();
            return(t);
        }
示例#2
0
 /// <summary>
 /// 创建一个新目录
 /// </summary>
 /// <param name="vfs"></param>
 /// <returns></returns>
 public static INodeDirectory Create(VFSCore vfs)
 {
     INode inode = vfs.AllocateINode(1, 2333);
     INodeDirectory t = new INodeDirectory(vfs, inode);
     t.AddSelf();
     return t;
 }
示例#3
0
文件: INode.cs 项目: bwbwbwbw/vfs
        /// <summary>
        /// 从存储介质中获取 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Load(VFSCore vfs, UInt32 index)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            INode inode = null;

            if (inodeInstances.ContainsKey(index))
            {
                inode = inodeInstances[index];
                return(inode);
            }
            else
            {
                _INode data = vfs.GetDevice().Read <_INode>(GetPosition(vfs, index));
                inode = new INode(vfs, data, index);
                inodeInstances[index] = inode;
            }

            inode.data.accessTime = (UInt64)DateTime.Now.Ticks;
            inode.Save();
            return(inode);
        }
示例#4
0
        /// <summary>
        /// 创建一个新目录
        /// </summary>
        /// <param name="vfs"></param>
        /// <returns></returns>
        public static INodeDirectory Create(VFSCore vfs)
        {
            INode          inode = vfs.AllocateINode(1, 2333);
            INodeDirectory t     = new INodeDirectory(vfs, inode);

            t.AddSelf();
            return(t);
        }
示例#5
0
        /// <summary>
        /// 创建一个全新的 SuperBlock
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="inodeCapacity"></param>
        /// <param name="blockSize"></param>
        /// <param name="blockCapacity"></param>
        /// <returns></returns>
        public static SuperBlock Create(VFSCore vfs, UInt32 inodeCapacity, UInt16 blockSize, UInt32 blockCapacity)
        {
            var _superBlock = new _SuperBlock(inodeCapacity, blockSize, blockCapacity);
            var superBlock  = new SuperBlock(vfs, _superBlock);

            superBlock.Save();
            return(superBlock);
        }
示例#6
0
        public SuperBlock(VFSCore vfs, _SuperBlock data)
        {
            this.vfs  = vfs;
            this.data = data;

            if (data.IsValid())
            {
                init();
            }
        }
示例#7
0
文件: INode.cs 项目: bwbwbwbw/vfs
        public INode(VFSCore vfs, _INode data, UInt32 index = UInt32.MaxValue)
        {
            this.vfs   = vfs;
            this.data  = data;
            this.index = index;

            UInt32 blockSize     = vfs.GetSuperBlock().data.blockSize;
            UInt32 IndexPerBlock = blockSize / sizeof(UInt32);

            BoundLv0 = 12 * blockSize;
            BoundLv1 = BoundLv0 + IndexPerBlock * blockSize;
        }
示例#8
0
文件: INode.cs 项目: bwbwbwbw/vfs
        /// <summary>
        /// 创建一个新的 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Create(VFSCore vfs, UInt32 index, UInt32 flags, UInt32 owner)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            _INode data  = new _INode(flags, owner);
            INode  inode = new INode(vfs, data, index);

            inode.Save();
            inodeInstances[index] = inode;

            return(inode);
        }
示例#9
0
            public Directory(VFSCore vfs, String path)
            {
                this.vfs = vfs;

                if (!path.EndsWith("/"))
                {
                    path += "/";
                }

                this.path = path;

                dir = INodeDirectory.Resolve(vfs, path);

                if (dir == null)
                {
                    throw new Exception("无效路径");
                }
            }
示例#10
0
            public Directory(VFSCore vfs, String path)
            {
                this.vfs = vfs;

                if (!path.EndsWith("/"))
                {
                    path += "/";
                }

                this.path = path;

                dir = INodeDirectory.Resolve(vfs, path);

                if (dir == null)
                {
                    throw new Exception("无效路径");
                }
            }
示例#11
0
        /// <summary>
        /// 根据路径解析目录,路径必须以 / 结尾
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static INodeDirectory Resolve(VFSCore vfs, String path)
        {
            INodeDirectory root = Load(vfs, 0);

            var pathCom = path.Split('/');
            var node    = root;

            for (var i = 1; i < pathCom.Length - 1; ++i)
            {
                if (node.Contains(pathCom[i]) && INode.Load(vfs, node.Find(pathCom[i])).IsDirectory())
                {
                    node = Load(vfs, node.Find(pathCom[i]));
                }
                else
                {
                    return(null);
                }
            }

            return(node);
        }
示例#12
0
        /// <summary>
        /// 根据路径解析目录,路径必须以 / 结尾
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static INodeDirectory Resolve(VFSCore vfs, String path)
        {
            INodeDirectory root = Load(vfs, 0);

            var pathCom = path.Split('/');
            var node = root;

            for (var i = 1; i < pathCom.Length - 1; ++i)
            {
                if (node.Contains(pathCom[i]) && INode.Load(vfs, node.Find(pathCom[i])).IsDirectory())
                {
                    node = Load(vfs, node.Find(pathCom[i]));
                }
                else
                {
                    return null;
                }
            }

            return node;
        }
示例#13
0
文件: VFS.cs 项目: SummerWish/vfs
 public VFS(AbstractDevice device)
 {
     vfs = new VFSCore(device);
 }
示例#14
0
 /// <summary>
 /// 从存储介质上还原 SuperBlock
 /// </summary>
 /// <param name="vfs"></param>
 /// <returns></returns>
 public static SuperBlock Load(VFSCore vfs)
 {
     var _superBlock = vfs.GetDevice().Read<_SuperBlock>(0);
     return new SuperBlock(vfs, _superBlock);
 }
示例#15
0
 /// <summary>
 /// 创建一个全新的 SuperBlock
 /// </summary>
 /// <param name="vfs"></param>
 /// <param name="inodeCapacity"></param>
 /// <param name="blockSize"></param>
 /// <param name="blockCapacity"></param>
 /// <returns></returns>
 public static SuperBlock Create(VFSCore vfs, UInt32 inodeCapacity, UInt16 blockSize, UInt32 blockCapacity)
 {
     var _superBlock = new _SuperBlock(inodeCapacity, blockSize, blockCapacity);
     var superBlock = new SuperBlock(vfs, _superBlock);
     superBlock.Save();
     return superBlock;
 }
示例#16
0
        public SuperBlock(VFSCore vfs, _SuperBlock data)
        {
            this.vfs = vfs;
            this.data = data;

            if (data.IsValid())
            {
                init();
            }
        }
示例#17
0
文件: VFS.File.cs 项目: bwbwbwbw/vfs
            public File(VFSCore vfs, String path, FileMode fileMode)
            {
                this.vfs = vfs;

                var directory = VFS.GetPathDirectory(path);
                var name      = VFS.GetPathName(path);

                VFS.AssertNameValid(name);

                INodeDirectory dir = INodeDirectory.Resolve(vfs, directory);

                if (dir == null)
                {
                    throw new Exception("无法访问目录");
                }
                switch (fileMode)
                {
                case FileMode.CreateNew:
                    if (dir.Contains(name))
                    {
                        throw new Exception("文件已存在");
                    }
                    CreateFile(dir, name);
                    break;

                case FileMode.Create:
                    if (dir.Contains(name))
                    {
                        OpenFile(dir, name);
                        inode.Resize(0);
                    }
                    else
                    {
                        CreateFile(dir, name);
                    }
                    break;

                case FileMode.Open:
                    if (!dir.Contains(name))
                    {
                        throw new Exception("文件未找到");
                    }
                    OpenFile(dir, name);
                    break;

                case FileMode.OpenOrCreate:
                    if (dir.Contains(name))
                    {
                        OpenFile(dir, name);
                    }
                    else
                    {
                        CreateFile(dir, name);
                    }
                    break;

                case FileMode.Truncate:
                    if (!dir.Contains(name))
                    {
                        throw new Exception("文件未找到");
                    }
                    OpenFile(dir, name);
                    inode.Resize(0);
                    break;

                case FileMode.Append:
                    if (!dir.Contains(name))
                    {
                        CreateFile(dir, name);
                    }
                    else
                    {
                        OpenFile(dir, name);
                        position = inode.data.sizeByte;
                    }
                    break;

                default:
                    throw new ArgumentException();
                }
            }
示例#18
0
文件: INode.cs 项目: bwbwbwbw/vfs
 public static UInt32 GetPosition(VFSCore vfs, UInt32 index)
 {
     return(vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize <_INode>());
 }
示例#19
0
 public INodeDirectory(VFSCore vfs, INode inode)
 {
     this.vfs     = vfs;
     this.inode   = inode;
     this.entries = new Dictionary <String, UInt32>();
 }
示例#20
0
 /// <summary>
 /// 根据 inode 建立 INodeDirectory
 /// </summary>
 /// <param name="vfs"></param>
 /// <param name="inode"></param>
 /// <returns></returns>
 public static INodeDirectory Load(VFSCore vfs, INode inode)
 {
     INodeDirectory t = new INodeDirectory(vfs, inode);
     t.Load();
     return t;
 }
示例#21
0
 /// <summary>
 /// 根据 inode index 建立 INodeDirectory
 /// </summary>
 /// <param name="vfs"></param>
 /// <param name="inodeIndex"></param>
 /// <returns></returns>
 public static INodeDirectory Load(VFSCore vfs, UInt32 inodeIndex)
 {
     INode inode = INode.Load(vfs, inodeIndex);
     return Load(vfs, inode);
 }
示例#22
0
 public VFS(AbstractDevice device)
 {
     vfs = new VFSCore(device);
 }
示例#23
0
        /// <summary>
        /// 从存储介质上还原 SuperBlock
        /// </summary>
        /// <param name="vfs"></param>
        /// <returns></returns>
        public static SuperBlock Load(VFSCore vfs)
        {
            var _superBlock = vfs.GetDevice().Read <_SuperBlock>(0);

            return(new SuperBlock(vfs, _superBlock));
        }
示例#24
0
 public INodeDirectory(VFSCore vfs, INode inode)
 {
     this.vfs = vfs;
     this.inode = inode;
     this.entries = new Dictionary<String, UInt32>();
 }
示例#25
0
文件: INode.cs 项目: SummerWish/vfs
 public static UInt32 GetPosition(VFSCore vfs, UInt32 index)
 {
     return vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize<_INode>();
 }
示例#26
0
文件: INode.cs 项目: SummerWish/vfs
        /// <summary>
        /// 创建一个新的 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Create(VFSCore vfs, UInt32 index, UInt32 flags, UInt32 owner)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            _INode data = new _INode(flags, owner);
            INode inode = new INode(vfs, data, index);
            inode.Save();
            inodeInstances[index] = inode;

            return inode;
        }
示例#27
0
文件: INode.cs 项目: SummerWish/vfs
        /// <summary>
        /// 从存储介质中获取 inode
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static INode Load(VFSCore vfs, UInt32 index)
        {
            if (index >= vfs.GetSuperBlock().data.inodeCapacity)
            {
                throw new Exception("无效 inode 编号");
            }

            INode inode = null;

            if (inodeInstances.ContainsKey(index))
            {
                inode = inodeInstances[index];
                return inode;
            }
            else
            {
                _INode data = vfs.GetDevice().Read<_INode>(GetPosition(vfs, index));
                inode = new INode(vfs, data, index);
                inodeInstances[index] = inode;
            }

            inode.data.accessTime = (UInt64)DateTime.Now.Ticks;
            inode.Save();
            return inode;
        }
示例#28
0
            public File(VFSCore vfs, String path, FileMode fileMode)
            {
                this.vfs = vfs;

                var directory = VFS.GetPathDirectory(path);
                var name = VFS.GetPathName(path);
                VFS.AssertNameValid(name);

                INodeDirectory dir = INodeDirectory.Resolve(vfs, directory);
                if (dir == null)
                {
                    throw new Exception("无法访问目录");
                }
                switch (fileMode)
                {
                    case FileMode.CreateNew:
                        if (dir.Contains(name))
                        {
                            throw new Exception("文件已存在");
                        }
                        CreateFile(dir, name);
                        break;
                    case FileMode.Create:
                        if (dir.Contains(name))
                        {
                            OpenFile(dir, name);
                            inode.Resize(0);
                        }
                        else
                        {
                            CreateFile(dir, name);
                        }
                        break;
                    case FileMode.Open:
                        if (!dir.Contains(name))
                        {
                            throw new Exception("文件未找到");
                        }
                        OpenFile(dir, name);
                        break;
                    case FileMode.OpenOrCreate:
                        if (dir.Contains(name))
                        {
                            OpenFile(dir, name);
                        }
                        else
                        {
                            CreateFile(dir, name);
                        }
                        break;
                    case FileMode.Truncate:
                        if (!dir.Contains(name))
                        {
                            throw new Exception("文件未找到");
                        }
                        OpenFile(dir, name);
                        inode.Resize(0);
                        break;
                    case FileMode.Append:
                        if (!dir.Contains(name))
                        {
                            CreateFile(dir, name);
                        }
                        else
                        {
                            OpenFile(dir, name);
                            position = inode.data.sizeByte;
                        }
                        break;
                    default:
                        throw new ArgumentException();
                }
            }
示例#29
0
        /// <summary>
        /// 根据 inode index 建立 INodeDirectory
        /// </summary>
        /// <param name="vfs"></param>
        /// <param name="inodeIndex"></param>
        /// <returns></returns>
        public static INodeDirectory Load(VFSCore vfs, UInt32 inodeIndex)
        {
            INode inode = INode.Load(vfs, inodeIndex);

            return(Load(vfs, inode));
        }
示例#30
0
文件: INode.cs 项目: SummerWish/vfs
        public INode(VFSCore vfs, _INode data, UInt32 index = UInt32.MaxValue)
        {
            this.vfs = vfs;
            this.data = data;
            this.index = index;

            UInt32 blockSize = vfs.GetSuperBlock().data.blockSize;
            UInt32 IndexPerBlock = blockSize / sizeof(UInt32);
            BoundLv0 = 12 * blockSize;
            BoundLv1 = BoundLv0 + IndexPerBlock * blockSize;
        }