/// <summary>
        /// Delayed root construction, to permit default permissions / identity info to be
        /// set before root is created.
        /// </summary>
        /// <returns>The root directory.</returns>
        private BuilderDirectory GetRoot()
        {
            if (_rootDir == null)
            {
                _rootDir = new BuilderDirectory();
                _rootDir.Mode = DefaultDirectoryPermissions;
            }

            return _rootDir;
        }
        private BuilderDirectory CreateDirectory(string path, int user, int group, UnixFilePermissions permissions)
        {
            BuilderDirectory currentDir = GetRoot();
            string[] elems = path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < elems.Length; ++i)
            {
                BuilderNode nextDirAsNode = currentDir.GetChild(elems[i]);
                BuilderDirectory nextDir = nextDirAsNode as BuilderDirectory;

                if (nextDirAsNode == null)
                {
                    nextDir = new BuilderDirectory()
                    {
                        UserId = user,
                        GroupId = group,
                        Mode = permissions,
                        ModificationTime = DateTime.Now,
                    };

                    currentDir.AddChild(elems[i], nextDir);
                }
                else if (nextDir == null)
                {
                    throw new FileNotFoundException("Found " + nextDirAsNode.Inode.Type + ", expecting Directory", string.Join("\\", elems, 0, i + 1));
                }

                currentDir = nextDir;
            }

            return currentDir;
        }
        /// <summary>
        /// Adds a directory to the file system.
        /// </summary>
        /// <param name="path">The full path to the directory.</param>
        /// <param name="user">The owner of the directory.</param>
        /// <param name="group">The group of the directory.</param>
        /// <param name="permissions">The access permission of the directory.</param>
        /// <param name="modificationTime">The modification time of the directory.</param>
        /// <remarks>
        /// <para>The created directory with have the default owner, group, permissions and the
        /// current time as it's modification time.  Any missing parent directories will be
        /// created with the specified owner, group, and directory permissions.  The current time
        /// will be used as the modification time.</para>
        /// </remarks>
        public void AddDirectory(string path, int user, int group, UnixFilePermissions permissions, DateTime modificationTime)
        {
            BuilderDirectory dir = new BuilderDirectory();
            dir.UserId = user;
            dir.GroupId = group;
            dir.Mode = permissions;
            dir.ModificationTime = modificationTime;

            BuilderDirectory parentDir = CreateDirectory(
                Utilities.GetDirectoryFromPath(path),
                user,
                group,
                permissions);
            parentDir.AddChild(Utilities.GetFileFromPath(path), dir);
        }