/*****************************************************************************/
/* File name: FAttributes.java                                               */
/* Purpose: to represent file attributes - the fattr structure in NFS        */
/* Last modified: 25.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*                                                                           */
/* This program is distributed in the hope that it will be useful, but       */
/* WITHOUT ANY WARRANTY; without even the implied warranty of                */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General */
/* Public License for more details.                                          */
/*                                                                           */
/* This software is distributed under the terms                              */
/* of the GNU General Public License as published                            */
/* by the Free Software Foundation; either version 2, or (at your option)    */
/* any later version.                                                        */
/* See file COPYING for your rights (GNU GPL)                                */
/*****************************************************************************/

package nfs;


public
class

FAttributes
{

  private final static String RCSID =
"$Header: /d/NFS/nfs/RCS/FAttributes.java,v 1.3 1999/06/25 18:50:41 vklimov Exp $";

  protected long type;
  protected long mode;
  protected long nlink;
  protected long uid;
  protected long gid;
  protected long size;
  protected long blocksize;
  protected long rdev;
  protected long blocks;
  protected long fsid;
  protected long fileid;
  protected Timeval atime = null;
  protected Timeval mtime = null;
  protected Timeval ctime = null;



  public

  FAttributes()
/*****************************************************************************/
/* Function name: FAttributes                                                */
/* File name: FAttributes.java                                               */
/* Purpose: constructor for the FAttributes class                            */
/* Parameters:                                                               */
/* Returns:                                                                  */
/* Last modified: 24.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
                                                       /* FAttributes */
/*---------------------------------------------------------------------------*/

      atime = new Timeval();
      mtime = new Timeval();
      ctime = new Timeval();

    }
/*end of FAttributes*/


  public
  void

  putItselfIntoRPCMessage( rpc.Message rpcMessage )
/*****************************************************************************/
/* Function name: putItselfIntoRPCMessage                                    */
/* File name: FAttributes.java                                               */
/* Purpose: to put this FAttributes object into a RPC message                */
/* Parameters: rpcMessage                                                    */
/* Returns:                                                                  */
/* Last modified: 24.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
                                              /* putItselfIntoRPCMessage */
/*---------------------------------------------------------------------------*/

      if ( (atime == null) ||
           (mtime == null) ||
           (ctime == null)
         )
        return;                                        /* return ! */
      else
        ;
    /*end of if*/

      rpcMessage.
        putUnsignedInteger( type );
      rpcMessage.
        putUnsignedInteger( mode );
      rpcMessage.
        putUnsignedInteger( nlink );
      rpcMessage.
        putUnsignedInteger( uid );
      rpcMessage.
        putUnsignedInteger( gid );
      rpcMessage.
        putUnsignedInteger( size );
      rpcMessage.
        putUnsignedInteger( blocksize );
      rpcMessage.
        putUnsignedInteger( rdev );
      rpcMessage.
        putUnsignedInteger( blocks );
      rpcMessage.
        putUnsignedInteger( fsid );
      rpcMessage.
        putUnsignedInteger( fileid );

      atime.putItselfIntoRPCMessage( rpcMessage );
      mtime.putItselfIntoRPCMessage( rpcMessage );
      ctime.putItselfIntoRPCMessage( rpcMessage );

    }
/*end of putItselfIntoRPCMessage*/


  public
  boolean

  getItselfFromRPCMessage( rpc.Message rpcMessage )
/*****************************************************************************/
/* Function name: getItselfFromRPCMessage                                    */
/* File name: FAttributes.java                                               */
/* Purpose: to get this FAttributes object from a RPC message                */
/* Parameters: rpcMessage                                                    */
/* Returns: true - if got OK, false - otherwise                              */
/* Last modified: 25.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
      boolean result;
                                              /* getItselfFromRPCMessage */
/*---------------------------------------------------------------------------*/

      if ( (atime == null) ||
           (mtime == null) ||
           (ctime == null)
         )
        return false;                                        /* return ! */
      else
        ;
    /*end of if*/

      type =
        rpcMessage.
          getUnsignedInteger();
      mode =
        rpcMessage.
          getUnsignedInteger();
      nlink =
        rpcMessage.
          getUnsignedInteger();
      uid =
        rpcMessage.
          getUnsignedInteger();
      gid =
        rpcMessage.
          getUnsignedInteger();
      size =
        rpcMessage.
          getUnsignedInteger();
      blocksize =
        rpcMessage.
          getUnsignedInteger();
      rdev =
        rpcMessage.
          getUnsignedInteger();
      blocks =
        rpcMessage.
          getUnsignedInteger();
      fsid =
        rpcMessage.
          getUnsignedInteger();
      fileid =
        rpcMessage.
          getUnsignedInteger();

      result = atime.getItselfFromRPCMessage( rpcMessage );

      if ( ! result ) return false;                        /* return ! */

      result = mtime.getItselfFromRPCMessage( rpcMessage );

      if ( ! result ) return false;                        /* return ! */

      result = ctime.getItselfFromRPCMessage( rpcMessage );

      if ( ! result ) return false;                        /* return ! */

      return true;

    }
/*end of getItselfFromRPCMessage*/


  public
  String

  toString()
/*****************************************************************************/
/* Function name: toString                                                   */
/* File name: FAttributes.java                                               */
/* Purpose: to represent this FAttributes object as a string                 */
/* Parameters:                                                               */
/* Returns: the string representation of the object                          */
/* Last modified: 24.06.99                                                   */
/* Author: Victor Klimov, 1999                                               */
/*****************************************************************************/
    {
      String result = "";
                                                       /* toString */
/*---------------------------------------------------------------------------*/

      result += "type=" + type + "\n" ;
      result += "mode=" + mode + "\n" ;
      result += "nlink=" + nlink + "\n" ;
      result += "uid=" + uid + "\n" ;
      result += "gid=" + gid + "\n" ;
      result += "size=" + size + "\n" ;
      result += "blocksize=" + blocksize + "\n" ;
      result += "rdev=" + rdev + "\n" ;
      result += "blocks=" + blocks + "\n" ;
      result += "fsid=" + fsid + "\n" ;
      result += "fileid=" + fileid + "\n" ;
      result += ( (atime == null) ? "atime is null" :
                  (atime.toString()) ) + "\n";
      result += ( (mtime == null) ? "mtime is null" :
                  (mtime.toString()) ) + "\n";
      result += ( (ctime == null) ? "ctime is null" :
                  (ctime.toString()) ) + "\n";

      return result;

    }
/*end of toString*/


} /* end of FAttributes class */

/*****************************************************************************/
/* End of file: FAttributes.java                                                 */
/*****************************************************************************/

