예제 #1
0
  /**
   * Pack a file information object into the specified buffer. Use the standard information level if
   * the EA size flag is false, else add the EA size field.
   *
   * @param info File information to be packed.
   * @param buf Buffer to pack the data into.
   * @param EAflag Add EA size field if true.
   * @param uni Pack Unicode strings if true, else pack ASCII strings
   */
  protected static final void packInfoStandard(
      FileInfo info, DataBuffer buf, boolean EAflag, boolean uni) {

    //  Information format :-
    //    SMB_DATE  CreationDate
    //    SMB_TIME  CreationTime
    //    SMB_DATE  LastAccessDate
    //    SMB_TIME  LastAccessTime
    //    SMB_DATE  LastWriteDate
    //    SMB_TIME  LastWriteTime
    //    ULONG     File size
    //    ULONG     Allocation size
    //    USHORT    File attributes
    //  [ ULONG     EA size ]
    //    UCHAR     File name length
    //    STRING    File name, null terminated

    //  Pack the creation date/time

    SMBDate date = new SMBDate(0);

    if (info.hasCreationDateTime()) {
      date.setTime(info.getCreationDateTime());
      buf.putShort(date.asSMBDate());
      buf.putShort(date.asSMBTime());
    } else buf.putZeros(4);

    //  Pack the last access date/time

    if (info.hasAccessDateTime()) {
      date.setTime(info.getAccessDateTime());
      buf.putShort(date.asSMBDate());
      buf.putShort(date.asSMBTime());
    } else buf.putZeros(4);

    //  Pack the last write date/time

    if (info.hasModifyDateTime()) {
      date.setTime(info.getModifyDateTime());
      buf.putShort(date.asSMBDate());
      buf.putShort(date.asSMBTime());
    } else buf.putZeros(4);

    //  Pack the file size and allocation size

    buf.putInt(info.getSizeInt());

    if (info.getAllocationSize() < info.getSize()) buf.putInt(info.getSizeInt());
    else buf.putInt(info.getAllocationSizeInt());

    //  Pack the file attributes

    buf.putShort(info.getFileAttributes());

    //  Pack the EA size, always 4.

    if (EAflag)
      //    	buf.putInt(4);
      buf.putInt(0);

    //	Pack the file name

    if (uni == true) {

      //	Pack the number of bytes followed by the Unicode name word aligned

      buf.putByte(info.getFileName().length() * 2);
      buf.wordAlign();
      buf.putString(info.getFileName(), uni, true);
    } else {

      //	Pack the number of bytes followed by the ASCII name

      buf.putByte(info.getFileName().length());
      buf.putString(info.getFileName(), uni, true);
    }
  }