/// <summary> /// 查找指定偏移所在的块,若块不存在则返回无效块 /// </summary> /// <param name="position"></param> /// <returns></returns> public Block GetBlockAtPosition(UInt32 position, Boolean allocate = false) { UInt32 blockSize = vfs.GetSuperBlock().data.blockSize; UInt32 IndexPerBlock = blockSize / sizeof(UInt32); if (position < BoundLv0) { // 直接索引 UInt32 lv0_index = position / blockSize; return(new Block(vfs, data.dataBlockId[lv0_index])); } else if (position < BoundLv1) { // 一级间接索引 position -= BoundLv0; UInt32 lv0_index = 12; UInt32 lv1_index = position / blockSize; Block lv0_block = new Block(vfs, data.dataBlockId[lv0_index]); if (lv0_block.index == UInt32.MaxValue) { return(lv0_block); } return(new Block(vfs, lv0_block.Read <UInt32>(lv1_index * sizeof(UInt32)))); } else { // 二级间接索引 position -= BoundLv1; UInt32 lv0_index = 13; UInt32 lv1_index = (position / blockSize) / IndexPerBlock; UInt32 lv2_index = (position / blockSize) % IndexPerBlock; Block lv0_block = new Block(vfs, data.dataBlockId[lv0_index]); if (lv0_block.index == UInt32.MaxValue) { return(lv0_block); } Block lv1_block = new Block(vfs, lv0_block.Read <UInt32>(lv1_index * sizeof(UInt32))); if (lv1_block.index == UInt32.MaxValue) { return(lv1_block); } return(new Block(vfs, lv1_block.Read <UInt32>(lv2_index * sizeof(UInt32)))); } }
/// <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); }
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; }
/// <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); }
public static UInt32 GetPosition(VFSCore vfs, UInt32 index) { return(vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize <_INode>()); }
public _SuperBlock GetSuperBlock() { return(vfs.GetSuperBlock().data); }
/// <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; }
public static UInt32 GetPosition(VFSCore vfs, UInt32 index) { return vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize<_INode>(); }
/// <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; }