Set() public method

public Set ( uint root, uint handle, uint readOnly ) : System.Boolean
root uint
handle uint
readOnly uint
return System.Boolean
コード例 #1
0
ファイル: NfsDirectory.cs プロジェクト: jklemmack/Snarf
        public virtual NfsPacket Create(uint xid, NfsPacket packet)
        {
            try {
                FileHandle dirFH   = new FileHandle(packet);
                string     entry   = packet.GetString();
                string     dirName = GetNameFromHandle(dirFH.Handle, xid);
                string     path    = Path.Combine(dirName, entry);

                // make the file

                if (File.Exists(path))
                {
                    throw new NFSException(xid, (uint)NfsReply.ERR_EXIST);
                }

                using (var file = File.Create(path)) { }

                // make a new handle for this file
                FileHandle fh     = new FileHandle();
                long       handle = HandleManager.Current.GetHandle(path);
                fh.Set(dirFH.Root, (uint)handle, dirFH.ReadOnly);

                // get the attributes of this new file
                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(path);

                // create the reply packet
                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(xid);
                reply.SetUInt((uint)NfsReply.OK);
                fh.Emit(ref reply);
                fa.Emit(ref reply);
                return(reply);
            }
            catch (FileNotFoundException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
            catch (IOException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
            catch (System.Security.SecurityException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_PERM);
            }
        }
コード例 #2
0
ファイル: NfsDirectory.cs プロジェクト: shellscape/Snarf
        public virtual NfsPacket Create(uint xid, NfsPacket packet)
        {
            try {
                FileHandle dirFH = new FileHandle(packet);
                string entry = packet.GetString();
                string dirName = GetNameFromHandle(dirFH.Handle, xid);
                string path = Path.Combine(dirName, entry);

                // make the file

                if (File.Exists(path)) {
                    throw new NFSException(xid, (uint)NfsReply.ERR_EXIST);
                }

                using (var file = File.Create(path)) { }

                // make a new handle for this file
                FileHandle fh = new FileHandle();
                long handle = HandleManager.Current.GetHandle(path);
                fh.Set(dirFH.Root, (uint)handle, dirFH.ReadOnly);

                // get the attributes of this new file
                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(path);

                // create the reply packet
                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(xid);
                reply.SetUInt((uint)NfsReply.OK);
                fh.Emit(ref reply);
                fa.Emit(ref reply);
                return reply;

            }
            catch (FileNotFoundException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
            catch (IOException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
            catch (System.Security.SecurityException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_PERM);
            }
        }
コード例 #3
0
ファイル: NfsDirectory.cs プロジェクト: jklemmack/Snarf
        public virtual NfsPacket Lookup(NfsPacket packet)
        {
            try {
                FileHandle dir      = new FileHandle(packet);
                String     entry    = packet.GetString();
                String     dirName  = GetNameFromHandle(dir.Handle, packet.XID);
                String     fileName = Path.Combine(dirName, entry);

                Console.WriteLine("Lookup -> " + entry);

                if (!File.Exists(fileName) && !Directory.Exists(fileName))
                {
                    throw new NFSException(packet.XID, (uint)NfsReply.ERR_NOENT);
                }

                NfsFileAttributes attributes = new NfsFileAttributes();
                attributes.Load(fileName);

                // make a FileHandle for this new path
                uint handleId = HandleManager.Current.GetHandle(fileName);

                FileHandle handle = new FileHandle();
                handle.Set(dir.Root, handleId, dir.ReadOnly);

                // make the reply
                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(packet.XID);
                reply.SetUInt((uint)NfsReply.OK);

                handle.Emit(ref reply);
                attributes.Emit(ref reply);

                return(reply);
            }
            catch (FileNotFoundException) {
                throw new NFSException(packet.XID, (uint)NfsReply.ERR_NOENT);
            }
        }
コード例 #4
0
ファイル: NfsDirectory.cs プロジェクト: jklemmack/Snarf
        public virtual NfsPacket Mkdir(uint xid, NfsPacket packet)
        {
            try {
                FileHandle fileHandle = new FileHandle(packet);
                string     entry      = packet.GetString();

                string dirName = GetNameFromHandle(fileHandle.Handle, xid);
                string newdir  = Path.Combine(dirName, entry);

                var dir = new DirectoryInfo(newdir);

                if (dir.Exists)
                {
                    throw new NFSException(xid, (uint)NfsReply.ERR_EXIST);
                }

                dir.Create();

                // make a FileHandle for this directory
                long       handle = HandleManager.Current.GetHandle(newdir);
                FileHandle newFH  = new FileHandle();
                newFH.Set(fileHandle.Root, (uint)handle, fileHandle.ReadOnly);

                // get the attributes
                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(newdir);

                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(xid);
                reply.SetUInt((uint)NfsReply.OK);
                newFH.Emit(ref reply);
                fa.Emit(ref reply);
                return(reply);
            }
            catch (FileNotFoundException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
        }
コード例 #5
0
        private void Mount(NfsPacket sourcePacket, IPEndPoint receivedFrom)
        {
            NfsReply  replyCode = NfsReply.OK;
            NfsPacket packet    = new NfsPacket(128);

            packet.AddReplyHeader(sourcePacket.XID);

            // skip past the authentication records
            sourcePacket.ReadAuthentication();
            sourcePacket.ReadAuthentication();

            // next should be a dirpath, which is a string.  Replace unix style path with local style path
            String path = sourcePacket.GetString();

            if (path == null)
            {
                replyCode = NfsReply.ERR_STALE;
            }
            else
            {
                String original = path.Clone() as String;

                path = NfsPath.ToWin(path);

                //Console.WriteLine("MountHandler.Mount : requested: " + original + ", actual: " + path);

                //if (!Directory.Exists(path)) {
                //	replyCode = NfsReply.ERR_EXIST;
                //}
            }

            // Try to validate this mount, if there is an error make an error packet, otherwise send back the handle.

            if (replyCode != NfsReply.OK)
            {
                packet.SetUInt((uint)replyCode);
            }
            else if (false)              //exports.Matches(packet.Source(), path) == false) {
            // No permission for this mount in the exports file
            //result.AddLong(NFS.NFSERR_PERM);
            //Console.Error.WriteLine("!!! Mount request for " + path + "from " + packet.Source() + " denied.\n");
            {
            }
            else
            {
                // put together a file handle
                uint handle     = HandleManager.Current.GetHandle(path);
                var  fileHandle = new FileSystem.FileHandle();

                fileHandle.Set(handle, (uint)handle, 0);

                packet.SetUInt((uint)replyCode);

                fileHandle.Emit(ref packet);
            }

            if (replyCode == NfsReply.OK)
            {
                MountManager.Current.Add(sourcePacket.RemoteHost, path);
            }

            Send(packet, receivedFrom);
        }
コード例 #6
0
ファイル: NfsDirectory.cs プロジェクト: shellscape/Snarf
        public virtual NfsPacket Mkdir(uint xid, NfsPacket packet)
        {
            try {
                FileHandle fileHandle = new FileHandle(packet);
                string entry = packet.GetString();

                string dirName = GetNameFromHandle(fileHandle.Handle, xid);
                string newdir = Path.Combine(dirName, entry);

                var dir = new DirectoryInfo(newdir);

                if (dir.Exists) {
                    throw new NFSException(xid, (uint)NfsReply.ERR_EXIST);
                }

                dir.Create();

                // make a FileHandle for this directory
                long handle = HandleManager.Current.GetHandle(newdir);
                FileHandle newFH = new FileHandle();
                newFH.Set(fileHandle.Root, (uint)handle, fileHandle.ReadOnly);

                // get the attributes
                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(newdir);

                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(xid);
                reply.SetUInt((uint)NfsReply.OK);
                newFH.Emit(ref reply);
                fa.Emit(ref reply);
                return reply;

            }
            catch (FileNotFoundException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_IO);
            }
        }
コード例 #7
0
ファイル: NfsDirectory.cs プロジェクト: shellscape/Snarf
        public virtual NfsPacket Lookup(NfsPacket packet)
        {
            try {
                FileHandle dir = new FileHandle(packet);
                String entry = packet.GetString();
                String dirName = GetNameFromHandle(dir.Handle, packet.XID);
                String fileName = Path.Combine(dirName, entry);

                Console.WriteLine("Lookup -> " + entry);

                if (!File.Exists(fileName) && !Directory.Exists(fileName)) {
                    throw new NFSException(packet.XID, (uint)NfsReply.ERR_NOENT);
                }

                NfsFileAttributes attributes = new NfsFileAttributes();
                attributes.Load(fileName);

                // make a FileHandle for this new path
                uint handleId = HandleManager.Current.GetHandle(fileName);

                FileHandle handle = new FileHandle();
                handle.Set(dir.Root, handleId, dir.ReadOnly);

                // make the reply
                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(packet.XID);
                reply.SetUInt((uint)NfsReply.OK);

                handle.Emit(ref reply);
                attributes.Emit(ref reply);

                return reply;

            }
            catch (FileNotFoundException) {
                throw new NFSException(packet.XID, (uint)NfsReply.ERR_NOENT);
            }
        }
コード例 #8
0
ファイル: MountHandler.cs プロジェクト: shellscape/Snarf
        private void Mount(NfsPacket sourcePacket, IPEndPoint receivedFrom)
        {
            NfsReply replyCode = NfsReply.OK;
            NfsPacket packet = new NfsPacket(128);

            packet.AddReplyHeader(sourcePacket.XID);

            // skip past the authentication records
            sourcePacket.ReadAuthentication();
            sourcePacket.ReadAuthentication();

            // next should be a dirpath, which is a string.  Replace unix style path with local style path
            String path = sourcePacket.GetString();

            if (path == null) {
                replyCode = NfsReply.ERR_STALE;
            }
            else {
                String original = path.Clone() as String;

                path = NfsPath.ToWin(path);

                //Console.WriteLine("MountHandler.Mount : requested: " + original + ", actual: " + path);

                //if (!Directory.Exists(path)) {
                //	replyCode = NfsReply.ERR_EXIST;
                //}
            }

            // Try to validate this mount, if there is an error make an error packet, otherwise send back the handle.

            if (replyCode != NfsReply.OK) {
                packet.SetUInt((uint)replyCode);

            }
            else if (false){ //exports.Matches(packet.Source(), path) == false) {
                // No permission for this mount in the exports file
                //result.AddLong(NFS.NFSERR_PERM);
                //Console.Error.WriteLine("!!! Mount request for " + path + "from " + packet.Source() + " denied.\n");
            }
            else {
                // put together a file handle
                uint handle = HandleManager.Current.GetHandle(path);
                var fileHandle = new FileSystem.FileHandle();

                fileHandle.Set(handle, (uint)handle, 0);

                packet.SetUInt((uint)replyCode);

                fileHandle.Emit(ref packet);
            }

            if (replyCode == NfsReply.OK) {
                MountManager.Current.Add(sourcePacket.RemoteHost, path);
            }

            Send(packet, receivedFrom);
        }