コード例 #1
0
        /// <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);
            }
            }
        }
コード例 #2
0
        /// <exception cref="System.IO.IOException"/>
        private IList <AclEntry> GetAclEntryList(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.LoadAclEntries(f.GetAcl(), stringTable));
            }

            case FsImageProto.INodeSection.INode.Type.Directory:
            {
                FsImageProto.INodeSection.INodeDirectory d = inode.GetDirectory();
                return(FSImageFormatPBINode.Loader.LoadAclEntries(d.GetAcl(), stringTable));
            }

            default:
            {
                return(new AList <AclEntry>());
            }
            }
        }
コード例 #3
0
 // byte representation of inodes, sorted by id
 public int Compare(byte[] o1, byte[] o2)
 {
     try
     {
         FsImageProto.INodeSection.INode l = FsImageProto.INodeSection.INode.ParseFrom(o1);
         FsImageProto.INodeSection.INode r = FsImageProto.INodeSection.INode.ParseFrom(o2);
         if (l.GetId() < r.GetId())
         {
             return(-1);
         }
         else
         {
             if (l.GetId() > r.GetId())
             {
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
     }
     catch (InvalidProtocolBufferException e)
     {
         throw new RuntimeException(e);
     }
 }
コード例 #4
0
        /// <exception cref="System.IO.IOException"/>
        private IList <IDictionary <string, object> > GetFileStatusList(string path)
        {
            IList <IDictionary <string, object> > list = new AList <IDictionary <string, object> >(
                );
            long id = Lookup(path);

            FsImageProto.INodeSection.INode inode = FromINodeId(id);
            if (inode.GetType() == FsImageProto.INodeSection.INode.Type.Directory)
            {
                if (!dirmap.Contains(id))
                {
                    // if the directory is empty, return empty list
                    return(list);
                }
                long[] children = dirmap[id];
                foreach (long cid in children)
                {
                    list.AddItem(GetFileStatus(FromINodeId(cid), true));
                }
            }
            else
            {
                list.AddItem(GetFileStatus(inode, false));
            }
            return(list);
        }
コード例 #5
0
 /// <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");
 }
コード例 #6
0
            private INode LoadINode(FsImageProto.INodeSection.INode n)
            {
                switch (n.GetType())
                {
                case FsImageProto.INodeSection.INode.Type.File:
                {
                    return(LoadINodeFile(n));
                }

                case FsImageProto.INodeSection.INode.Type.Directory:
                {
                    return(LoadINodeDirectory(n, parent.GetLoaderContext()));
                }

                case FsImageProto.INodeSection.INode.Type.Symlink:
                {
                    return(LoadINodeSymlink(n));
                }

                default:
                {
                    break;
                }
                }
                return(null);
            }
コード例 #7
0
 public virtual void PutDir(FsImageProto.INodeSection.INode p)
 {
     Preconditions.CheckState(!dirMap.Contains(p.GetId()));
     PBImageTextWriter.InMemoryMetadataDB.Dir dir = new PBImageTextWriter.InMemoryMetadataDB.Dir
                                                        (p.GetId(), p.GetName().ToStringUtf8());
     dirMap[p.GetId()] = dir;
 }
コード例 #8
0
            private void LoadRootINode(FsImageProto.INodeSection.INode p)
            {
                INodeDirectory root    = LoadINodeDirectory(p, parent.GetLoaderContext());
                QuotaCounts    q       = root.GetQuotaCounts();
                long           nsQuota = q.GetNameSpace();
                long           dsQuota = q.GetStorageSpace();

                if (nsQuota != -1 || dsQuota != -1)
                {
                    dir.rootDir.GetDirectoryWithQuotaFeature().SetQuota(nsQuota, dsQuota);
                }
                EnumCounters <StorageType> typeQuotas = q.GetTypeSpaces();

                if (typeQuotas.AnyGreaterOrEqual(0))
                {
                    dir.rootDir.GetDirectoryWithQuotaFeature().SetQuota(typeQuotas);
                }
                dir.rootDir.CloneModificationTime(root);
                dir.rootDir.ClonePermissionStatus(root);
                AclFeature af = root.GetFeature(typeof(AclFeature));

                if (af != null)
                {
                    dir.rootDir.AddAclFeature(af);
                }
                // root dir supports having extended attributes according to POSIX
                XAttrFeature f = root.GetXAttrFeature();

                if (f != null)
                {
                    dir.rootDir.AddXAttrFeature(f);
                }
                dir.AddRootDirToEncryptionZone(f);
            }
コード例 #9
0
        /// <exception cref="System.IO.IOException"/>
        private FsImageProto.INodeSection.INode FromINodeId(long id)
        {
            int l = 0;
            int r = inodes.Length;

            while (l < r)
            {
                int mid = l + (r - l) / 2;
                FsImageProto.INodeSection.INode n = FsImageProto.INodeSection.INode.ParseFrom(inodes
                                                                                              [mid]);
                long nid = n.GetId();
                if (id > nid)
                {
                    l = mid + 1;
                }
                else
                {
                    if (id < nid)
                    {
                        r = mid;
                    }
                    else
                    {
                        return(n);
                    }
                }
            }
            return(null);
        }
コード例 #10
0
        /// <summary>Return the JSON formatted FileStatus of the specified file.</summary>
        /// <param name="path">a path specifies a file</param>
        /// <returns>JSON formatted FileStatus</returns>
        /// <exception cref="System.IO.IOException">if failed to serialize fileStatus to JSON.
        ///     </exception>
        internal virtual string GetFileStatus(string path)
        {
            ObjectMapper mapper = new ObjectMapper();

            FsImageProto.INodeSection.INode inode = FromINodeId(Lookup(path));
            return("{\"FileStatus\":\n" + mapper.WriteValueAsString(GetFileStatus(inode, false
                                                                                  )) + "\n}\n");
        }
コード例 #11
0
 /// <exception cref="System.IO.IOException"/>
 private void Save(OutputStream @out, INodeDirectory n)
 {
     FsImageProto.INodeSection.INodeDirectory.Builder b = BuildINodeDirectory(n, parent
                                                                              .GetSaverContext());
     FsImageProto.INodeSection.INode r = ((FsImageProto.INodeSection.INode)BuildINodeCommon
                                              (n).SetType(FsImageProto.INodeSection.INode.Type.Directory).SetDirectory(b).Build
                                              ());
     r.WriteDelimitedTo(@out);
 }
コード例 #12
0
 /// <exception cref="System.IO.IOException"/>
 private void Save(OutputStream @out, INodeSymlink n)
 {
     FSImageFormatProtobuf.SaverContext             state = parent.GetSaverContext();
     FsImageProto.INodeSection.INodeSymlink.Builder b     = FsImageProto.INodeSection.INodeSymlink
                                                            .NewBuilder().SetPermission(BuildPermissionStatus(n, state.GetStringMap())).SetTarget
                                                                (ByteString.CopyFrom(n.GetSymlink())).SetModificationTime(n.GetModificationTime(
                                                                                                                              )).SetAccessTime(n.GetAccessTime());
     FsImageProto.INodeSection.INode r = ((FsImageProto.INodeSection.INode)BuildINodeCommon
                                              (n).SetType(FsImageProto.INodeSection.INode.Type.Symlink).SetSymlink(b).Build());
     r.WriteDelimitedTo(@out);
 }
コード例 #13
0
            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);
            }
コード例 #14
0
 /// <exception cref="System.IO.IOException"/>
 private void OutputINodes(InputStream @in)
 {
     FsImageProto.INodeSection s = FsImageProto.INodeSection.ParseDelimitedFrom(@in);
     Log.Info("Found {} INodes in the INode section", s.GetNumInodes());
     for (int i = 0; i < s.GetNumInodes(); ++i)
     {
         FsImageProto.INodeSection.INode p = FsImageProto.INodeSection.INode.ParseDelimitedFrom
                                                 (@in);
         string parentPath = metadataMap.GetParentPath(p.GetId());
         @out.WriteLine(GetEntry(parentPath, p));
         if (Log.IsDebugEnabled() && i % 100000 == 0)
         {
             Log.Debug("Outputted {} INodes.", i);
         }
     }
     Log.Info("Outputted {} INodes.", s.GetNumInodes());
 }
コード例 #15
0
            private INodeFile LoadINodeFile(FsImageProto.INodeSection.INode n)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .File);
                FsImageProto.INodeSection.INodeFile f  = n.GetFile();
                IList <HdfsProtos.BlockProto>       bp = f.GetBlocksList();
                short replication = (short)f.GetReplication();

                FSImageFormatProtobuf.LoaderContext state = parent.GetLoaderContext();
                BlockInfoContiguous[] blocks = new BlockInfoContiguous[bp.Count];
                for (int i = 0; i < e; ++i)
                {
                    blocks[i] = new BlockInfoContiguous(PBHelper.Convert(bp[i]), replication);
                }
                PermissionStatus permissions = LoadPermission(f.GetPermission(), parent.GetLoaderContext
                                                                  ().GetStringTable());
                INodeFile file = new INodeFile(n.GetId(), n.GetName().ToByteArray(), permissions,
                                               f.GetModificationTime(), f.GetAccessTime(), blocks, replication, f.GetPreferredBlockSize
                                                   (), unchecked ((byte)f.GetStoragePolicyID()));

                if (f.HasAcl())
                {
                    int[] entries = AclEntryStatusFormat.ToInt(LoadAclEntries(f.GetAcl(), state.GetStringTable
                                                                                  ()));
                    file.AddAclFeature(new AclFeature(entries));
                }
                if (f.HasXAttrs())
                {
                    file.AddXAttrFeature(new XAttrFeature(LoadXAttrs(f.GetXAttrs(), state.GetStringTable
                                                                         ())));
                }
                // under-construction information
                if (f.HasFileUC())
                {
                    FsImageProto.INodeSection.FileUnderConstructionFeature uc = f.GetFileUC();
                    file.ToUnderConstruction(uc.GetClientName(), uc.GetClientMachine());
                    if (blocks.Length > 0)
                    {
                        BlockInfoContiguous lastBlk = file.GetLastBlock();
                        // replace the last block of file
                        file.SetBlock(file.NumBlocks() - 1, new BlockInfoContiguousUnderConstruction(lastBlk
                                                                                                     , replication));
                    }
                }
                return(file);
            }
コード例 #16
0
        /// <summary>Return the INodeId of the specified path.</summary>
        /// <exception cref="System.IO.IOException"/>
        private long Lookup(string path)
        {
            Preconditions.CheckArgument(path.StartsWith("/"));
            long id = INodeId.RootInodeId;

            for (int offset = 0; offset < path.Length; offset = next)
            {
                next = path.IndexOf('/', offset + 1);
                if (next == -1)
                {
                    next = path.Length;
                }
                if (offset + 1 > next)
                {
                    break;
                }
                string component = Sharpen.Runtime.Substring(path, offset + 1, next);
                if (component.IsEmpty())
                {
                    continue;
                }
                long[] children = dirmap[id];
                if (children == null)
                {
                    throw new FileNotFoundException(path);
                }
                bool found = false;
                foreach (long cid in children)
                {
                    FsImageProto.INodeSection.INode child = FromINodeId(cid);
                    if (component.Equals(child.GetName().ToStringUtf8()))
                    {
                        found = true;
                        id    = child.GetId();
                        break;
                    }
                }
                if (!found)
                {
                    throw new FileNotFoundException(path);
                }
            }
            return(id);
        }
コード例 #17
0
 /// <exception cref="System.IO.IOException"/>
 internal void LoadINodeSection(InputStream @in)
 {
     FsImageProto.INodeSection s = FsImageProto.INodeSection.ParseDelimitedFrom(@in);
     fsn.dir.ResetLastInodeId(s.GetLastInodeId());
     Log.Info("Loading " + s.GetNumInodes() + " INodes.");
     for (int i = 0; i < s.GetNumInodes(); ++i)
     {
         FsImageProto.INodeSection.INode p = FsImageProto.INodeSection.INode.ParseDelimitedFrom
                                                 (@in);
         if (p.GetId() == INodeId.RootInodeId)
         {
             LoadRootINode(p);
         }
         else
         {
             INode n = LoadINode(p);
             dir.AddToInodeMap(n);
         }
     }
 }
コード例 #18
0
            /// <summary>save all the snapshottable directories and snapshots to fsimage</summary>
            /// <exception cref="System.IO.IOException"/>
            public void SerializeSnapshotSection(OutputStream @out)
            {
                SnapshotManager sm = fsn.GetSnapshotManager();

                FsImageProto.SnapshotSection.Builder b = FsImageProto.SnapshotSection.NewBuilder(
                    ).SetSnapshotCounter(sm.GetSnapshotCounter()).SetNumSnapshots(sm.GetNumSnapshots
                                                                                      ());
                INodeDirectory[] snapshottables = sm.GetSnapshottableDirs();
                foreach (INodeDirectory sdir in snapshottables)
                {
                    b.AddSnapshottableDir(sdir.GetId());
                }
                ((FsImageProto.SnapshotSection)b.Build()).WriteDelimitedTo(@out);
                int i = 0;

                foreach (INodeDirectory sdir_1 in snapshottables)
                {
                    foreach (Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s in sdir_1.GetDirectorySnapshottableFeature
                                 ().GetSnapshotList())
                    {
                        Snapshot.Root sroot = s.GetRoot();
                        FsImageProto.SnapshotSection.Snapshot.Builder sb = FsImageProto.SnapshotSection.Snapshot
                                                                           .NewBuilder().SetSnapshotId(s.GetId());
                        FsImageProto.INodeSection.INodeDirectory.Builder db = FSImageFormatPBINode.Saver.BuildINodeDirectory
                                                                                  (sroot, parent.GetSaverContext());
                        FsImageProto.INodeSection.INode r = ((FsImageProto.INodeSection.INode)FsImageProto.INodeSection.INode
                                                             .NewBuilder().SetId(sroot.GetId()).SetType(FsImageProto.INodeSection.INode.Type.
                                                                                                        Directory).SetName(ByteString.CopyFrom(sroot.GetLocalNameBytes())).SetDirectory(
                                                                 db).Build());
                        ((FsImageProto.SnapshotSection.Snapshot)sb.SetRoot(r).Build()).WriteDelimitedTo(@out
                                                                                                        );
                        i++;
                        if (i % FSImageFormatProtobuf.Saver.CheckCancelInterval == 0)
                        {
                            context.CheckCancelled();
                        }
                    }
                }
                Preconditions.CheckState(i == sm.GetNumSnapshots());
                parent.CommitSection(headers, FSImageFormatProtobuf.SectionName.Snapshot);
            }
コード例 #19
0
        /// <summary>Load the filenames of the directories from the INode section.</summary>
        /// <exception cref="System.IO.IOException"/>
        private void LoadDirectoriesInINodeSection(InputStream @in)
        {
            FsImageProto.INodeSection s = FsImageProto.INodeSection.ParseDelimitedFrom(@in);
            Log.Info("Loading directories in INode section.");
            int numDirs = 0;

            for (int i = 0; i < s.GetNumInodes(); ++i)
            {
                FsImageProto.INodeSection.INode p = FsImageProto.INodeSection.INode.ParseDelimitedFrom
                                                        (@in);
                if (Log.IsDebugEnabled() && i % 10000 == 0)
                {
                    Log.Debug("Scanned {} inodes.", i);
                }
                if (p.HasDirectory())
                {
                    metadataMap.PutDir(p);
                    numDirs++;
                }
            }
            Log.Info("Found {} directories in INode section.", numDirs);
        }
コード例 #20
0
 /// <exception cref="System.IO.IOException"/>
 private void Run(InputStream @in)
 {
     FsImageProto.INodeSection s = FsImageProto.INodeSection.ParseDelimitedFrom(@in);
     for (int i = 0; i < s.GetNumInodes(); ++i)
     {
         FsImageProto.INodeSection.INode p = FsImageProto.INodeSection.INode.ParseDelimitedFrom
                                                 (@in);
         if (p.GetType() == FsImageProto.INodeSection.INode.Type.File)
         {
             ++totalFiles;
             FsImageProto.INodeSection.INodeFile f = p.GetFile();
             totalBlocks += f.GetBlocksCount();
             long fileSize = 0;
             foreach (HdfsProtos.BlockProto b in f.GetBlocksList())
             {
                 fileSize += b.GetNumBytes();
             }
             maxFileSize = Math.Max(fileSize, maxFileSize);
             totalSpace += fileSize * f.GetReplication();
             int bucket = fileSize > maxSize ? distribution.Length - 1 : (int)Math.Ceil((double
                                                                                         )fileSize / steps);
             ++distribution[bucket];
         }
         else
         {
             if (p.GetType() == FsImageProto.INodeSection.INode.Type.Directory)
             {
                 ++totalDirectories;
             }
         }
         if (i % (1 << 20) == 0)
         {
             @out.WriteLine("Processed " + i + " inodes.");
         }
     }
 }
コード例 #21
0
            /// <exception cref="System.IO.IOException"/>
            private void Save(OutputStream @out, INodeFile n)
            {
                FsImageProto.INodeSection.INodeFile.Builder b = BuildINodeFile(n, parent.GetSaverContext
                                                                                   ());
                if (n.GetBlocks() != null)
                {
                    foreach (Block block in n.GetBlocks())
                    {
                        b.AddBlocks(PBHelper.Convert(block));
                    }
                }
                FileUnderConstructionFeature uc = n.GetFileUnderConstructionFeature();

                if (uc != null)
                {
                    FsImageProto.INodeSection.FileUnderConstructionFeature f = ((FsImageProto.INodeSection.FileUnderConstructionFeature
                                                                                 )FsImageProto.INodeSection.FileUnderConstructionFeature.NewBuilder().SetClientName
                                                                                    (uc.GetClientName()).SetClientMachine(uc.GetClientMachine()).Build());
                    b.SetFileUC(f);
                }
                FsImageProto.INodeSection.INode r = ((FsImageProto.INodeSection.INode)BuildINodeCommon
                                                         (n).SetType(FsImageProto.INodeSection.INode.Type.File).SetFile(b).Build());
                r.WriteDelimitedTo(@out);
            }
コード例 #22
0
        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());
        }
コード例 #23
0
        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);
            }
            }
        }
コード例 #24
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void PutDir(FsImageProto.INodeSection.INode dir)
 {
     Preconditions.CheckArgument(dir.HasDirectory(), "INode %s (%s) is not a directory."
                                 , dir.GetId(), dir.GetName());
     dirMap.Put(ToBytes(dir.GetId()), ToBytes(dir.GetName().ToStringUtf8()));
 }
コード例 #25
0
 /// <summary>Get text output for the given inode.</summary>
 /// <param name="parent">the path of parent directory</param>
 /// <param name="inode">the INode object to output.</param>
 protected internal abstract string GetEntry(string parent, FsImageProto.INodeSection.INode
                                             inode);
コード例 #26
0
            public static INodeDirectory LoadINodeDirectory(FsImageProto.INodeSection.INode n
                                                            , FSImageFormatProtobuf.LoaderContext state)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .Directory);
                FsImageProto.INodeSection.INodeDirectory d = n.GetDirectory();
                PermissionStatus permissions = LoadPermission(d.GetPermission(), state.GetStringTable
                                                                  ());
                INodeDirectory dir = new INodeDirectory(n.GetId(), n.GetName().ToByteArray(), permissions
                                                        , d.GetModificationTime());
                long nsQuota = d.GetNsQuota();
                long dsQuota = d.GetDsQuota();

                if (nsQuota >= 0 || dsQuota >= 0)
                {
                    dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().NameSpaceQuota
                                                         (nsQuota).StorageSpaceQuota(dsQuota).Build());
                }
                EnumCounters <StorageType> typeQuotas = null;

                if (d.HasTypeQuotas())
                {
                    ImmutableList <QuotaByStorageTypeEntry> qes = LoadQuotaByStorageTypeEntries(d.GetTypeQuotas
                                                                                                    ());
                    typeQuotas = new EnumCounters <StorageType>(typeof(StorageType), HdfsConstants.QuotaReset
                                                                );
                    foreach (QuotaByStorageTypeEntry qe in qes)
                    {
                        if (qe.GetQuota() >= 0 && qe.GetStorageType() != null && qe.GetStorageType().SupportTypeQuota
                                ())
                        {
                            typeQuotas.Set(qe.GetStorageType(), qe.GetQuota());
                        }
                    }
                    if (typeQuotas.AnyGreaterOrEqual(0))
                    {
                        DirectoryWithQuotaFeature q = dir.GetDirectoryWithQuotaFeature();
                        if (q == null)
                        {
                            dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().TypeQuotas
                                                                 (typeQuotas).Build());
                        }
                        else
                        {
                            q.SetQuota(typeQuotas);
                        }
                    }
                }
                if (d.HasAcl())
                {
                    int[] entries = AclEntryStatusFormat.ToInt(LoadAclEntries(d.GetAcl(), state.GetStringTable
                                                                                  ()));
                    dir.AddAclFeature(new AclFeature(entries));
                }
                if (d.HasXAttrs())
                {
                    dir.AddXAttrFeature(new XAttrFeature(LoadXAttrs(d.GetXAttrs(), state.GetStringTable
                                                                        ())));
                }
                return(dir);
            }