Exemplo n.º 1
0
        public DokanError MoveFile(string oldName, string newName, bool replace, DokanFileInfo info)
        {
            //Console.WriteLine("MoveFile: {0} -> {1}, replace = {2}", oldName, newName, replace);

            var dirNameOld = Util.GetPathDirectory(oldName);
            var dirNameNew = Util.GetPathDirectory(newName);
            if (dirNameNew.IndexOf(dirNameOld) > -1 && dirNameNew != dirNameOld)
            {
                return DokanError.ErrorError;
            }

            var dirOld = new Directory(dirNameOld);
            var dirNew = new Directory(dirNameNew);

            if (!dirOld.Exists() || !dirNew.Exists())
            {
                return DokanError.ErrorPathNotFound;
            }

            var nameOld = Util.GetPathFileName(oldName);
            var nameNew = Util.GetPathFileName(newName);

            if (dirNew.Contains(nameNew))
            {
                return DokanError.ErrorAlreadyExists;
            }

            var inode = dirOld.GetItemINodeIndex(nameOld);
            dirOld.Delete(nameOld);
            dirNew.AddItem(nameNew, inode);

            return DokanError.ErrorSuccess;
        }
Exemplo n.º 2
0
        public DokanError SetEndOfFile(string fileName, long length, DokanFileInfo info)
        {
            Directory dir = new Directory(Util.GetPathDirectory(fileName));
            if (!dir.Exists())
            {
                return DokanError.ErrorPathNotFound;
            }

            String name = Util.GetPathFileName(fileName);
            if (!dir.Contains(name))
            {
                return DokanError.ErrorFileNotFound;
            }

            INode inode = Disk.iNodes[dir.GetItemINodeIndex(name)];
            inode.SetEndOfFile((int)length);
            return DokanError.ErrorSuccess;
        }
Exemplo n.º 3
0
        public File(string path, System.IO.FileMode fileMode)
        {
            this.path = path;
            var dir = new Directory(Util.GetPathDirectory(path));
            var name = Util.GetPathFileName(path);

            switch (fileMode)
            {
                case System.IO.FileMode.Append:
                    // 不支持
                    throw new NotImplementedException();
                    break;
                case System.IO.FileMode.Create:
                    if (dir.Contains(name))
                    {
                        this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)];
                        this.inode.SetEndOfFile(0);
                    }
                    else
                    {
                        this.inode = Disk.AllocateNewINode(System.IO.FileAttributes.Normal);
                        dir.AddItem(name, inode.index);
                    }
                    break;
                case System.IO.FileMode.CreateNew:
                    //Console.WriteLine("*** CreateNew {0}", name);
                    if (dir.Contains(name))
                    {
                        throw new System.IO.IOException();
                    }
                    this.inode = Disk.AllocateNewINode(System.IO.FileAttributes.Normal);
                    dir.AddItem(name, inode.index);
                    break;
                case System.IO.FileMode.Open:
                    //Console.WriteLine("*** Open {0}", name);
                    if (!dir.Contains(name))
                    {
                        throw new System.IO.FileNotFoundException();
                    }
                    this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)];
                    break;
                case System.IO.FileMode.OpenOrCreate:
                    if (!dir.Contains(name))
                    {
                        this.inode = Disk.AllocateNewINode(System.IO.FileAttributes.Normal);
                        dir.AddItem(name, inode.index);
                    }
                    else
                    {
                        this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)];
                    }
                    break;
                case System.IO.FileMode.Truncate:
                    if (!dir.Contains(name))
                    {
                        throw new System.IO.FileNotFoundException();
                    }
                    this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)];
                    this.inode.SetEndOfFile(0);
                    break;
            }
        }