Ejemplo n.º 1
0
        public static Org.Apache.Hadoop.Nfs.Nfs3.Response.FSINFO3Response Deserialize(XDR
                                                                                      xdr)
        {
            int status = xdr.ReadInt();

            xdr.ReadBoolean();
            Nfs3FileAttributes postOpObjAttr = Nfs3FileAttributes.Deserialize(xdr);
            int     rtmax       = 0;
            int     rtpref      = 0;
            int     rtmult      = 0;
            int     wtmax       = 0;
            int     wtpref      = 0;
            int     wtmult      = 0;
            int     dtpref      = 0;
            long    maxFileSize = 0;
            NfsTime timeDelta   = null;
            int     properties  = 0;

            if (status == Nfs3Status.Nfs3Ok)
            {
                rtmax       = xdr.ReadInt();
                rtpref      = xdr.ReadInt();
                rtmult      = xdr.ReadInt();
                wtmax       = xdr.ReadInt();
                wtpref      = xdr.ReadInt();
                wtmult      = xdr.ReadInt();
                dtpref      = xdr.ReadInt();
                maxFileSize = xdr.ReadHyper();
                timeDelta   = NfsTime.Deserialize(xdr);
                properties  = xdr.ReadInt();
            }
            return(new Org.Apache.Hadoop.Nfs.Nfs3.Response.FSINFO3Response(status, postOpObjAttr
                                                                           , rtmax, rtpref, rtmult, wtmax, wtpref, wtmult, dtpref, maxFileSize, timeDelta,
                                                                           properties));
        }
Ejemplo n.º 2
0
 public SETATTR3Request(FileHandle handle, SetAttr3 attr, bool check, NfsTime ctime
                        )
     : base(handle)
 {
     this.attr  = attr;
     this.check = check;
     this.ctime = ctime;
 }
Ejemplo n.º 3
0
        public static Org.Apache.Hadoop.Nfs.Nfs3.Response.WccAttr Deserialize(XDR xdr)
        {
            long    size  = xdr.ReadHyper();
            NfsTime mtime = NfsTime.Deserialize(xdr);
            NfsTime ctime = NfsTime.Deserialize(xdr);

            return(new Org.Apache.Hadoop.Nfs.Nfs3.Response.WccAttr(size, mtime, ctime));
        }
Ejemplo n.º 4
0
 public SetAttr3(int mode, int uid, int gid, long size, NfsTime atime, NfsTime mtime
                 , EnumSet <SetAttr3.SetAttrField> updateFields)
 {
     this.mode         = mode;
     this.uid          = uid;
     this.gid          = gid;
     this.size         = size;
     this.updateFields = updateFields;
 }
Ejemplo n.º 5
0
        public virtual void Deserialize(XDR xdr)
        {
            if (xdr.ReadBoolean())
            {
                mode = xdr.ReadInt();
                updateFields.AddItem(SetAttr3.SetAttrField.Mode);
            }
            if (xdr.ReadBoolean())
            {
                uid = xdr.ReadInt();
                updateFields.AddItem(SetAttr3.SetAttrField.Uid);
            }
            if (xdr.ReadBoolean())
            {
                gid = xdr.ReadInt();
                updateFields.AddItem(SetAttr3.SetAttrField.Gid);
            }
            if (xdr.ReadBoolean())
            {
                size = xdr.ReadHyper();
                updateFields.AddItem(SetAttr3.SetAttrField.Size);
            }
            int timeSetHow = xdr.ReadInt();

            if (timeSetHow == TimeSetToClientTime)
            {
                atime = NfsTime.Deserialize(xdr);
                updateFields.AddItem(SetAttr3.SetAttrField.Atime);
            }
            else
            {
                if (timeSetHow == TimeSetToServerTime)
                {
                    atime = new NfsTime(Runtime.CurrentTimeMillis());
                    updateFields.AddItem(SetAttr3.SetAttrField.Atime);
                }
            }
            timeSetHow = xdr.ReadInt();
            if (timeSetHow == TimeSetToClientTime)
            {
                mtime = NfsTime.Deserialize(xdr);
                updateFields.AddItem(SetAttr3.SetAttrField.Mtime);
            }
            else
            {
                if (timeSetHow == TimeSetToServerTime)
                {
                    mtime = new NfsTime(Runtime.CurrentTimeMillis());
                    updateFields.AddItem(SetAttr3.SetAttrField.Mtime);
                }
            }
        }
Ejemplo n.º 6
0
 public virtual void Serialize(XDR @out)
 {
     @out.WriteLongAsHyper(size);
     if (mtime == null)
     {
         mtime = new NfsTime(0);
     }
     mtime.Serialize(@out);
     if (ctime == null)
     {
         ctime = new NfsTime(0);
     }
     ctime.Serialize(@out);
 }
Ejemplo n.º 7
0
 public Nfs3FileAttributes(Nfs3FileAttributes other)
 {
     this.type   = other.GetType();
     this.mode   = other.GetMode();
     this.nlink  = other.GetNlink();
     this.uid    = other.GetUid();
     this.gid    = other.GetGid();
     this.size   = other.GetSize();
     this.used   = other.GetUsed();
     this.rdev   = new Nfs3FileAttributes.Specdata3();
     this.fsid   = other.GetFsid();
     this.fileId = other.GetFileId();
     this.mtime  = new NfsTime(other.GetMtime());
     this.atime  = new NfsTime(other.GetAtime());
     this.ctime  = new NfsTime(other.GetCtime());
 }
Ejemplo n.º 8
0
 public Nfs3FileAttributes(NfsFileType nfsType, int nlink, short mode, int uid, int
                           gid, long size, long fsid, long fileId, long mtime, long atime, Nfs3FileAttributes.Specdata3
                           rdev)
 {
     this.type   = nfsType.ToValue();
     this.mode   = mode;
     this.nlink  = nlink;
     this.uid    = uid;
     this.gid    = gid;
     this.size   = size;
     this.used   = this.size;
     this.rdev   = new Nfs3FileAttributes.Specdata3();
     this.fsid   = fsid;
     this.fileId = fileId;
     this.mtime  = new NfsTime(mtime);
     this.atime  = atime != 0 ? new NfsTime(atime) : this.mtime;
     this.ctime  = this.mtime;
     this.rdev   = rdev;
 }
Ejemplo n.º 9
0
        public static Nfs3FileAttributes Deserialize(XDR xdr)
        {
            Nfs3FileAttributes attr = new Nfs3FileAttributes();

            attr.type   = xdr.ReadInt();
            attr.mode   = xdr.ReadInt();
            attr.nlink  = xdr.ReadInt();
            attr.uid    = xdr.ReadInt();
            attr.gid    = xdr.ReadInt();
            attr.size   = xdr.ReadHyper();
            attr.used   = xdr.ReadHyper();
            attr.rdev   = new Nfs3FileAttributes.Specdata3(xdr.ReadInt(), xdr.ReadInt());
            attr.fsid   = xdr.ReadHyper();
            attr.fileId = xdr.ReadHyper();
            attr.atime  = NfsTime.Deserialize(xdr);
            attr.mtime  = NfsTime.Deserialize(xdr);
            attr.ctime  = NfsTime.Deserialize(xdr);
            return(attr);
        }
Ejemplo n.º 10
0
        /* A client may request that the server check that the object is in an
         * expected state before performing the SETATTR operation. If guard.check is
         * TRUE, the server must compare the value of ctime to the current ctime of
         * the object. If the values are different, the server must preserve the
         * object attributes and must return a status of NFS3ERR_NOT_SYNC. If check is
         * FALSE, the server will not perform this check.
         */
        /// <exception cref="System.IO.IOException"/>
        public static Org.Apache.Hadoop.Nfs.Nfs3.Request.SETATTR3Request Deserialize(XDR
                                                                                     xdr)
        {
            FileHandle handle = ReadHandle(xdr);
            SetAttr3   attr   = new SetAttr3();

            attr.Deserialize(xdr);
            bool    check = xdr.ReadBoolean();
            NfsTime ctime;

            if (check)
            {
                ctime = NfsTime.Deserialize(xdr);
            }
            else
            {
                ctime = null;
            }
            return(new Org.Apache.Hadoop.Nfs.Nfs3.Request.SETATTR3Request(handle, attr, check
                                                                          , ctime));
        }
Ejemplo n.º 11
0
        public virtual NfsPacket SetAttr(uint xid, NfsPacket packet)
        {
            try {
                FileHandle f        = new FileHandle(packet);
                String     fileName = GetNameFromHandle(f.Handle, xid);

                // the attributes
                int     mode  = (int)packet.GetUInt();
                int     uid   = (int)packet.GetUInt();
                int     gid   = (int)packet.GetUInt();
                int     size  = (int)packet.GetUInt();
                NfsTime atime = new NfsTime(packet);
                NfsTime mtime = new NfsTime(packet);

                // the only attribute that can be set is the size can be set to 0 to truncate the file
                if (size == 0)
                {
                    // truncate by deleting and recreating the file
                    using (var fs = new FileStream(fileName, FileMode.Truncate, FileAccess.ReadWrite)) { }
                }

                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(xid);
                reply.SetUInt((uint)NfsReply.OK);

                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(fileName);
                fa.Emit(ref reply);

                return(reply);
            }
            catch (FileNotFoundException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_NOENT);
            }
            catch (IOException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_PERM);
            }
        }
Ejemplo n.º 12
0
 public WccAttr()
 {
     this.size = 0;
     mtime     = null;
     ctime     = null;
 }
Ejemplo n.º 13
0
        public uint Load(String path)
        {
            if (!File.Exists(path) && !Directory.Exists(path))
            {
                throw new FileNotFoundException();
            }

            mode = 0;

            FileAttributes fileAttributes = File.GetAttributes(path);
            Boolean        isDirectory    = fileAttributes.Is(FileAttributes.Directory);
            Boolean        canRead        = NfsFileAttributes.CanRead(path);
            Boolean        canWrite       = NfsFileAttributes.CanWrite(path);

            if (!isDirectory)
            {
                type = FileType.NFREG;
                mode = FilePermissions.UPFILE;
            }
            else if (isDirectory)
            {
                type = FileType.NFDIR;
                mode = FilePermissions.UPDIR;
            }
            else
            {
                Console.Error.WriteLine("NfsFileAttributes.Load: " + path + " has unknown type");
                type = FileType.NFNON;
                mode = 0;                 // don't know what kind of file system object this is
            }

            //if (!isDirectory) {
            //	using (var fs = new FileStream(path, FileMode.Open)) {
            //		canRead = fs.CanRead;
            //		canWrite = fs.CanWrite;
            //	}
            //}
            //else {
            //	canRead = true;
            //	canWrite = !fileAttributes.Is(FileAttributes.ReadOnly);
            //}

            if (canRead)
            {
                mode |= FilePermissions.UP_OREAD | FilePermissions.UP_GREAD | FilePermissions.UP_WREAD;
                mode |= FilePermissions.UP_OEXEC | FilePermissions.UP_GEXEC | FilePermissions.UP_WEXEC;
            }
            if (canWrite)
            {
                mode |= FilePermissions.UP_OWRITE | FilePermissions.UP_GWRITE | FilePermissions.UP_WWRITE;
            }

            // from now on assume either file or directory
            if (!isDirectory)
            {
                nlink = 1;
            }
            else               // directories always have 2 links
            {
                nlink = 2;
            }

            FileInfo file = new FileInfo(path);

            uid       = 0;
            gid       = 0;
            size      = isDirectory ? 512 : (uint)(new FileInfo(path).Length);
            blocksize = 512;             // XXX common value, how do I get this in java?
            rdev      = 0;
            blocks    = (size + blocksize - 1) / blocksize;
            fsid      = isDirectory ? 0 : GetFileSystemId(file);
            fileid    = (uint)HandleManager.Current.GetHandle(path);

            lastAccessed = new NfsTime(file.LastAccessTime);
            lastChanged  = new NfsTime(file.LastWriteTime);
            lastModified = new NfsTime(file.LastWriteTime);

            return((uint)NfsReply.OK);
        }
Ejemplo n.º 14
0
        public FSINFO3Response(int status, Nfs3FileAttributes postOpAttr, int rtmax, int
                               rtpref, int rtmult, int wtmax, int wtpref, int wtmult, int dtpref, long maxFileSize
                               , NfsTime timeDelta, int properties)
            : base(status)
        {
            /*
             * The maximum size in bytes of a READ request supported by the server. Any
             * READ with a number greater than rtmax will result in a short read of rtmax
             * bytes or less.
             */
            /*
             * The preferred size of a READ request. This should be the same as rtmax
             * unless there is a clear benefit in performance or efficiency.
             */
            /* The suggested multiple for the size of a READ request. */

            /*
             * The maximum size of a WRITE request supported by the server. In general,
             * the client is limited by wtmax since there is no guarantee that a server
             * can handle a larger write. Any WRITE with a count greater than wtmax will
             * result in a short write of at most wtmax bytes.
             */
            /*
             * The preferred size of a WRITE request. This should be the same as wtmax
             * unless there is a clear benefit in performance or efficiency.
             */
            /*
             * The suggested multiple for the size of a WRITE request.
             */
            /* The preferred size of a READDIR request. */
            /* The maximum size of a file on the file system. */

            /*
             * The server time granularity. When setting a file time using SETATTR, the
             * server guarantees only to preserve times to this accuracy. If this is {0,
             * 1}, the server can support nanosecond times, {0, 1000000} denotes
             * millisecond precision, and {1, 0} indicates that times are accurate only to
             * the nearest second.
             */
            /*
             * A bit mask of file system properties. The following values are defined:
             *
             * FSF_LINK If this bit is 1 (TRUE), the file system supports hard links.
             *
             * FSF_SYMLINK If this bit is 1 (TRUE), the file system supports symbolic
             * links.
             *
             * FSF_HOMOGENEOUS If this bit is 1 (TRUE), the information returned by
             * PATHCONF is identical for every file and directory in the file system. If
             * it is 0 (FALSE), the client should retrieve PATHCONF information for each
             * file and directory as required.
             *
             * FSF_CANSETTIME If this bit is 1 (TRUE), the server will set the times for a
             * file via SETATTR if requested (to the accuracy indicated by time_delta). If
             * it is 0 (FALSE), the server cannot set times as requested.
             */
            this.postOpAttr  = postOpAttr;
            this.rtmax       = rtmax;
            this.rtpref      = rtpref;
            this.rtmult      = rtmult;
            this.wtmax       = wtmax;
            this.wtpref      = wtpref;
            this.wtmult      = wtmult;
            this.dtpref      = dtpref;
            this.maxFileSize = maxFileSize;
            this.timeDelta   = timeDelta;
            this.properties  = properties;
        }
Ejemplo n.º 15
0
        public virtual NfsPacket SetAttr(uint xid, NfsPacket packet)
        {
            try {
                FileHandle f = new FileHandle(packet);
                String fileName = GetNameFromHandle(f.Handle, xid);

                // the attributes
                int mode = (int)packet.GetUInt();
                int uid = (int)packet.GetUInt();
                int gid = (int)packet.GetUInt();
                int size = (int)packet.GetUInt();
                NfsTime atime = new NfsTime(packet);
                NfsTime mtime = new NfsTime(packet);

                // the only attribute that can be set is the size can be set to 0 to truncate the file
                if (size == 0) {
                    // truncate by deleting and recreating the file
                    using (var fs = new FileStream(fileName, FileMode.Truncate, FileAccess.ReadWrite)) { }
                }

                NfsPacket reply = new NfsPacket(128);
                reply.AddReplyHeader(xid);
                reply.SetUInt((uint)NfsReply.OK);

                NfsFileAttributes fa = new NfsFileAttributes();
                fa.Load(fileName);
                fa.Emit(ref reply);

                return reply;
            }
            catch (FileNotFoundException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_NOENT);
            }
            catch (IOException) {
                throw new NFSException(xid, (uint)NfsReply.ERR_PERM);
            }
        }
Ejemplo n.º 16
0
        public uint Load(String path)
        {
            if (!File.Exists(path) && !Directory.Exists(path)) {
                throw new FileNotFoundException();
            }

            mode = 0;

            FileAttributes fileAttributes = File.GetAttributes(path);
            Boolean isDirectory = fileAttributes.Is(FileAttributes.Directory);
            Boolean canRead = NfsFileAttributes.CanRead(path);
            Boolean canWrite = NfsFileAttributes.CanWrite(path);

            if (!isDirectory) {
                type = FileType.NFREG;
                mode = FilePermissions.UPFILE;
            }
            else if (isDirectory) {
                type = FileType.NFDIR;
                mode = FilePermissions.UPDIR;
            }
            else {
                Console.Error.WriteLine("NfsFileAttributes.Load: " + path + " has unknown type");
                type = FileType.NFNON;
                mode = 0; // don't know what kind of file system object this is
            }

            //if (!isDirectory) {
            //	using (var fs = new FileStream(path, FileMode.Open)) {
            //		canRead = fs.CanRead;
            //		canWrite = fs.CanWrite;
            //	}
            //}
            //else {
            //	canRead = true;
            //	canWrite = !fileAttributes.Is(FileAttributes.ReadOnly);
            //}

            if (canRead) {
                mode |= FilePermissions.UP_OREAD | FilePermissions.UP_GREAD | FilePermissions.UP_WREAD;
                mode |= FilePermissions.UP_OEXEC | FilePermissions.UP_GEXEC | FilePermissions.UP_WEXEC;
            }
            if (canWrite) {
                mode |= FilePermissions.UP_OWRITE | FilePermissions.UP_GWRITE | FilePermissions.UP_WWRITE;
            }

            // from now on assume either file or directory
            if (!isDirectory) {
                nlink = 1;
            }
            else { // directories always have 2 links
                nlink = 2;
            }

            FileInfo file = new FileInfo(path);

            uid = 0;
            gid = 0;
            size = isDirectory ? 512 : (uint)(new FileInfo(path).Length);
            blocksize = 512; // XXX common value, how do I get this in java?
            rdev = 0;
            blocks = (size + blocksize - 1) / blocksize;
            fsid = isDirectory ? 0 : GetFileSystemId(file);
            fileid = (uint)HandleManager.Current.GetHandle(path);

            lastAccessed = new NfsTime(file.LastAccessTime);
            lastChanged = new NfsTime(file.LastWriteTime);
            lastModified = new NfsTime(file.LastWriteTime);

            return (uint)NfsReply.OK;
        }
Ejemplo n.º 17
0
 public WccAttr(long size, NfsTime mtime, NfsTime ctime)
 {
     this.size  = size;
     this.mtime = mtime;
     this.ctime = ctime;
 }