/// <exception cref="System.IO.IOException"/> private void DumpINodeSection(InputStream @in) { FsImageProto.INodeSection s = FsImageProto.INodeSection.ParseDelimitedFrom(@in); @out.Write("<INodeSection>"); O("lastInodeId", s.GetLastInodeId()); for (int i = 0; i < s.GetNumInodes(); ++i) { FsImageProto.INodeSection.INode p = FsImageProto.INodeSection.INode.ParseDelimitedFrom (@in); @out.Write("<inode>"); O("id", p.GetId()).O("type", p.GetType()).O("name", p.GetName().ToStringUtf8()); if (p.HasFile()) { DumpINodeFile(p.GetFile()); } else { if (p.HasDirectory()) { DumpINodeDirectory(p.GetDirectory()); } else { if (p.HasSymlink()) { DumpINodeSymlink(p.GetSymlink()); } } } @out.Write("</inode>\n"); } @out.Write("</INodeSection>\n"); }
/// <exception cref="System.IO.IOException"/> private PermissionStatus GetPermissionStatus(string path) { long id = Lookup(path); FsImageProto.INodeSection.INode inode = FromINodeId(id); switch (inode.GetType()) { case FsImageProto.INodeSection.INode.Type.File: { FsImageProto.INodeSection.INodeFile f = inode.GetFile(); return(FSImageFormatPBINode.Loader.LoadPermission(f.GetPermission(), stringTable)); } case FsImageProto.INodeSection.INode.Type.Directory: { FsImageProto.INodeSection.INodeDirectory d = inode.GetDirectory(); return(FSImageFormatPBINode.Loader.LoadPermission(d.GetPermission(), stringTable)); } case FsImageProto.INodeSection.INode.Type.Symlink: { FsImageProto.INodeSection.INodeSymlink s = inode.GetSymlink(); return(FSImageFormatPBINode.Loader.LoadPermission(s.GetPermission(), stringTable)); } default: { return(null); } } }
private INodeSymlink LoadINodeSymlink(FsImageProto.INodeSection.INode n) { System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type .Symlink); FsImageProto.INodeSection.INodeSymlink s = n.GetSymlink(); PermissionStatus permissions = LoadPermission(s.GetPermission(), parent.GetLoaderContext ().GetStringTable()); INodeSymlink sym = new INodeSymlink(n.GetId(), n.GetName().ToByteArray(), permissions , s.GetModificationTime(), s.GetAccessTime(), s.GetTarget().ToStringUtf8()); return(sym); }
private IDictionary <string, object> GetFileStatus(FsImageProto.INodeSection.INode inode, bool printSuffix) { IDictionary <string, object> map = Maps.NewHashMap(); switch (inode.GetType()) { case FsImageProto.INodeSection.INode.Type.File: { FsImageProto.INodeSection.INodeFile f = inode.GetFile(); PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(f.GetPermission() , stringTable); map["accessTime"] = f.GetAccessTime(); map["blockSize"] = f.GetPreferredBlockSize(); map["group"] = p.GetGroupName(); map["length"] = GetFileSize(f); map["modificationTime"] = f.GetModificationTime(); map["owner"] = p.GetUserName(); map["pathSuffix"] = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty; map["permission"] = ToString(p.GetPermission()); map["replication"] = f.GetReplication(); map["type"] = inode.GetType(); map["fileId"] = inode.GetId(); map["childrenNum"] = 0; return(map); } case FsImageProto.INodeSection.INode.Type.Directory: { FsImageProto.INodeSection.INodeDirectory d = inode.GetDirectory(); PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(d.GetPermission() , stringTable); map["accessTime"] = 0; map["blockSize"] = 0; map["group"] = p.GetGroupName(); map["length"] = 0; map["modificationTime"] = d.GetModificationTime(); map["owner"] = p.GetUserName(); map["pathSuffix"] = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty; map["permission"] = ToString(p.GetPermission()); map["replication"] = 0; map["type"] = inode.GetType(); map["fileId"] = inode.GetId(); map["childrenNum"] = dirmap.Contains(inode.GetId()) ? dirmap[inode.GetId()].Length : 0; return(map); } case FsImageProto.INodeSection.INode.Type.Symlink: { FsImageProto.INodeSection.INodeSymlink d = inode.GetSymlink(); PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(d.GetPermission() , stringTable); map["accessTime"] = d.GetAccessTime(); map["blockSize"] = 0; map["group"] = p.GetGroupName(); map["length"] = 0; map["modificationTime"] = d.GetModificationTime(); map["owner"] = p.GetUserName(); map["pathSuffix"] = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty; map["permission"] = ToString(p.GetPermission()); map["replication"] = 0; map["type"] = inode.GetType(); map["symlink"] = d.GetTarget().ToStringUtf8(); map["fileId"] = inode.GetId(); map["childrenNum"] = 0; return(map); } default: { return(null); } } }
protected internal override string GetEntry(string parent, FsImageProto.INodeSection.INode inode) { StringBuilder buffer = new StringBuilder(); string inodeName = inode.GetName().ToStringUtf8(); Path path = new Path(parent.IsEmpty() ? "/" : parent, inodeName.IsEmpty() ? "/" : inodeName); buffer.Append(path.ToString()); PermissionStatus p = null; switch (inode.GetType()) { case FsImageProto.INodeSection.INode.Type.File: { FsImageProto.INodeSection.INodeFile file = inode.GetFile(); p = GetPermission(file.GetPermission()); Append(buffer, file.GetReplication()); Append(buffer, FormatDate(file.GetModificationTime())); Append(buffer, FormatDate(file.GetAccessTime())); Append(buffer, file.GetPreferredBlockSize()); Append(buffer, file.GetBlocksCount()); Append(buffer, FSImageLoader.GetFileSize(file)); Append(buffer, 0); // NS_QUOTA Append(buffer, 0); // DS_QUOTA break; } case FsImageProto.INodeSection.INode.Type.Directory: { FsImageProto.INodeSection.INodeDirectory dir = inode.GetDirectory(); p = GetPermission(dir.GetPermission()); Append(buffer, 0); // Replication Append(buffer, FormatDate(dir.GetModificationTime())); Append(buffer, FormatDate(0)); // Access time. Append(buffer, 0); // Block size. Append(buffer, 0); // Num blocks. Append(buffer, 0); // Num bytes. Append(buffer, dir.GetNsQuota()); Append(buffer, dir.GetDsQuota()); break; } case FsImageProto.INodeSection.INode.Type.Symlink: { FsImageProto.INodeSection.INodeSymlink s = inode.GetSymlink(); p = GetPermission(s.GetPermission()); Append(buffer, 0); // Replication Append(buffer, FormatDate(s.GetModificationTime())); Append(buffer, FormatDate(s.GetAccessTime())); Append(buffer, 0); // Block size. Append(buffer, 0); // Num blocks. Append(buffer, 0); // Num bytes. Append(buffer, 0); // NS_QUOTA Append(buffer, 0); // DS_QUOTA break; } default: { break; } } System.Diagnostics.Debug.Assert(p != null); Append(buffer, p.GetPermission().ToString()); Append(buffer, p.GetUserName()); Append(buffer, p.GetGroupName()); return(buffer.ToString()); }