Summary description for diropargs.
Ejemplo n.º 1
0
        private void RmDir(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String removePath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;

            Console.WriteLine(@"RmDir: {0}", removePath);

            fhandle fh = FileTable.LookupFileHandle(removePath);

            try
            {
                new DirectoryInfo(removePath).Delete(false);
            }
            catch (IOException)
            {
                if (new DirectoryInfo(removePath).GetFileSystemInfos().Length > 0)
                {
                    throw new NFSStatusException(NFSStatus.NFSERR_NOTEMPTY);
                }
                else
                {
                    throw new NFSStatusException(NFSStatus.NFSERR_PERM);
                }
            }

            if (fh != null)
            {
                FileTable.Remove(fh);
            }

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Ejemplo n.º 2
0
        private void Remove(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String removePath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;

            FileInfo info = new FileInfo(removePath);

            if (info.Exists == false)
            {
                removePath += ".sl";
                info        = new FileInfo(removePath);
            }

            Console.WriteLine(@"Remove: {0}", removePath);

            fhandle fh = FileTable.LookupFileHandle(removePath);

            info.Delete();
            // If UnauthorizedAccessException is thrown & caught should
            // probably stat file to determine if the cause is because
            // the path is a dir rather than a directory.

            if (fh != null)
            {
                FileTable.Remove(fh);
            }

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Ejemplo n.º 3
0
        private void Lookup(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String lookupPath        = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;
            String symLinkLookupPath = lookupPath + ".sl";

#if DEBUG
            //Console.WriteLine(@"Lookup: {0}", lookupPath);
#endif

            fhandle fh = null;

#if DEBUG
            try
            {
#endif
            if ((fh = FileTable.LookupFileHandle(lookupPath)) == null)
            {
                //Console.WriteLine(@"Lookup (symlink): {0}", symLinkLookupPath);

                fh = FileTable.LookupFileHandle(symLinkLookupPath);
            }

            // Entry (for file or symlink) not in FileTable
            if (fh == null)
            {
                // Try non-SL first
                fh = FileTable.Add(new FileEntry(lookupPath));

                try
                {
                    diropres.PackSuccess(packer, fh, new fattr(fh));
                }
                catch
                {
                    FileTable.Remove(fh);

                    fh = FileTable.Add(new FileEntry(symLinkLookupPath));
                }
            }
            // Case where fh is in FileTable and used when neither was but
            // regular file/dir has not been found so add entry for SL
#if DEBUG
        }

        catch
        {
            Console.WriteLine(@"Lookup EXCEPTION: {0}", lookupPath);
            throw;
        }
#endif
            diropres.PackSuccess(packer, fh, new fattr(fh));
        }
Ejemplo n.º 4
0
        private void SymLink(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);
            string    path = cracker.get_String();
            sattr     attr = new sattr(cracker);

            String createPath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName + ".sl";

            Console.WriteLine("Symlink: {0}->{1}", createPath, path);

            fhandle fh;

            if ((fh = FileTable.LookupFileHandle(createPath)) == null)
            {
                fh = FileTable.Add(new FileEntry(createPath));
            }

            try
            {
                FileStream symlink = new FileStream(createPath, FileMode.CreateNew, FileAccess.Write);

                try
                {
                    UTF8Encoding pathUTF8 = new UTF8Encoding();

                    byte[] buf = pathUTF8.GetBytes(path);

                    symlink.Write(buf, 0, buf.Length);

                    packer.setUint32((uint)NFSStatus.NFS_OK);
                }
                finally
                {
                    symlink.Close();
                }
            }
            catch (IOException)
            {
                if (new FileInfo(createPath).Exists == true)
                {
                    throw new NFSStatusException(NFSStatus.NFSERR_EXIST);
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 5
0
        private void Rename(rpcCracker cracker, rpcPacker packer)
        {
            diropargs from = new diropargs(cracker);
            diropargs to   = new diropargs(cracker);

            string fromPath = FileTable.LookupFileEntry(from.DirHandle).Name + @"\" + from.FileName;
            string toPath   = FileTable.LookupFileEntry(to.DirHandle).Name + @"\" + to.FileName;

            Console.WriteLine("Rename {0} to {1}", fromPath, toPath);

            if (File.Exists(toPath) == true)
            {
                File.Delete(toPath);
            }

            File.Move(fromPath, toPath);

            // Only bother updating the FileTable if the operation was successful
            FileTable.Rename(fromPath, toPath);

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Ejemplo n.º 6
0
        private void SymLink(rpcCracker cracker, rpcPacker packer)
        {
            diropargs	args	= new diropargs(cracker);
            string		path	= cracker.get_String();
            sattr		attr	= new sattr(cracker);

            String createPath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName + ".sl";

            Console.WriteLine("Symlink: {0}->{1}", createPath, path);

            fhandle fh;

            if ((fh = FileTable.LookupFileHandle(createPath)) == null)
                fh = FileTable.Add(new FileEntry(createPath));

            try
            {
                FileStream symlink = new FileStream(createPath, FileMode.CreateNew, FileAccess.Write);

                try
                {
                    UTF8Encoding pathUTF8 = new UTF8Encoding();

                    byte[] buf = pathUTF8.GetBytes(path);

                    symlink.Write(buf, 0, buf.Length);

                    packer.setUint32((uint)NFSStatus.NFS_OK);
                }
                finally
                {
                    symlink.Close();
                }
            }
            catch(IOException)
            {
                if (new FileInfo(createPath).Exists == true)
                    throw new NFSStatusException(NFSStatus.NFSERR_EXIST);
                else
                    throw;
            }
        }
Ejemplo n.º 7
0
        private void RmDir(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String removePath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;

            Console.WriteLine(@"RmDir: {0}", removePath);

            fhandle fh = FileTable.LookupFileHandle(removePath);

            try
            {
                new DirectoryInfo(removePath).Delete(false);
            }
            catch (IOException)
            {
                if (new DirectoryInfo(removePath).GetFileSystemInfos().Length > 0)
                    throw new NFSStatusException(NFSStatus.NFSERR_NOTEMPTY);
                else
                        throw new NFSStatusException(NFSStatus.NFSERR_PERM);
            }

            if (fh != null) FileTable.Remove(fh);

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Ejemplo n.º 8
0
        private void Rename(rpcCracker cracker, rpcPacker packer)
        {
            diropargs from	= new diropargs(cracker);
            diropargs to	= new diropargs(cracker);

            string fromPath = FileTable.LookupFileEntry(from.DirHandle).Name + @"\" + from.FileName;
            string toPath = FileTable.LookupFileEntry(to.DirHandle).Name + @"\" + to.FileName;

            Console.WriteLine("Rename {0} to {1}", fromPath, toPath);

            if (File.Exists(toPath) == true)
                File.Delete(toPath);

            File.Move(fromPath, toPath);

            // Only bother updating the FileTable if the operation was successful
            FileTable.Rename(fromPath, toPath);

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Ejemplo n.º 9
0
        private void Remove(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String removePath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;

            FileInfo info = new FileInfo(removePath);

            if (info.Exists == false)
            {
                removePath += ".sl";
                info = new FileInfo(removePath);
            }

            Console.WriteLine(@"Remove: {0}", removePath);

            fhandle fh = FileTable.LookupFileHandle(removePath);

            info.Delete();
            // If UnauthorizedAccessException is thrown & caught should
            // probably stat file to determine if the cause is because
            // the path is a dir rather than a directory.

            if (fh != null) FileTable.Remove(fh);

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Ejemplo n.º 10
0
        private void Lookup(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String lookupPath			= FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;
            String symLinkLookupPath	= lookupPath + ".sl";

            #if DEBUG
            //Console.WriteLine(@"Lookup: {0}", lookupPath);
            #endif

            fhandle fh = null;

            #if DEBUG
            try
            {
            #endif
            if ((fh = FileTable.LookupFileHandle(lookupPath)) == null)
            {
                //Console.WriteLine(@"Lookup (symlink): {0}", symLinkLookupPath);

                fh = FileTable.LookupFileHandle(symLinkLookupPath);
            }

            // Entry (for file or symlink) not in FileTable
            if (fh == null)
            {
                // Try non-SL first
                fh = FileTable.Add(new FileEntry(lookupPath));

                try
                {
                    diropres.PackSuccess(packer, fh, new fattr(fh));
                }
                catch
                {
                    FileTable.Remove(fh);

                    fh = FileTable.Add(new FileEntry(symLinkLookupPath));
                }
            }
            // Case where fh is in FileTable and used when neither was but
            // regular file/dir has not been found so add entry for SL
            #if DEBUG
            }
            catch
            {
                Console.WriteLine(@"Lookup EXCEPTION: {0}", lookupPath);
                throw;
            }
            #endif
            diropres.PackSuccess(packer, fh, new fattr(fh));
        }
Ejemplo n.º 11
0
 public createargs(rpcCracker cracker)
 {
     where      = new diropargs(cracker);
     attributes = new sattr(cracker);
 }
Ejemplo n.º 12
0
 public createargs(rpcCracker cracker)
 {
     where		= new diropargs(cracker);
     attributes	= new sattr(cracker);
 }