Пример #1
0
        // TODO: We should update the inode bitmap if necessary
        public void DeleteNode(BobFsNode node)
        {
            if (!IsDirectory)
            {
                throw new InvalidOperationException("Current node is not a directory.");
            }

            int      runner = 0;
            DirEntry entry  = new DirEntry();

            while (runner < Size)
            {
                entry.ReadFrom(this, runner);

                if (entry.Inum == node.Inum)
                {
                    int read;
                    while ((read = ReadAll(runner + (8 + entry.Name.Length), _tmpBuffer, 0, BobFs.BlockSize)) != 0)
                    {
                        WriteAll(runner, _tmpBuffer, 0, read);
                        runner += read;
                    }

                    Size -= (uint)(8 + entry.Name.Length);
                    return;
                }

                runner += 8 + entry.Name.Length; // Point to next direntry's inum
            }

            throw new Exception("Node not found.");
        }
Пример #2
0
        public BobFsNode FindNode(string name)
        {
            if (!IsDirectory)
            {
                throw new InvalidOperationException("Current node is not a directory.");
            }

            int      runner = 0;
            DirEntry entry  = new DirEntry();

            while (runner < Size)
            {
                entry.ReadFrom(this, runner);
                runner += 8 + entry.Name.Length; // Point to next inum
                if (entry.Name == name)
                {
                    return(new BobFsNode(_bobFs, entry.Inum));
                }
            }

            return(null);
        }