1 17 package org.alfresco.filesys.smb.server; 18 19 import org.alfresco.filesys.server.filesys.FileInfo; 20 import org.alfresco.filesys.server.filesys.UnsupportedInfoLevelException; 21 import org.alfresco.filesys.smb.FileInfoLevel; 22 import org.alfresco.filesys.smb.NTTime; 23 import org.alfresco.filesys.smb.SMBDate; 24 import org.alfresco.filesys.smb.WinNT; 25 import org.alfresco.filesys.smb.server.ntfs.StreamInfo; 26 import org.alfresco.filesys.smb.server.ntfs.StreamInfoList; 27 import org.alfresco.filesys.util.DataBuffer; 28 29 34 public class QueryInfoPacker 35 { 36 37 47 public final static int packInfo(FileInfo info, DataBuffer buf, int infoLevel, boolean uni) 48 throws UnsupportedInfoLevelException 49 { 50 51 53 int curPos = buf.getPosition(); 54 55 switch (infoLevel) 56 { 57 58 60 case FileInfoLevel.PathStandard: 61 packInfoStandard(info, buf, false, uni); 62 break; 63 64 66 case FileInfoLevel.PathQueryEASize: 67 packInfoStandard(info, buf, true, uni); 68 break; 69 70 72 case FileInfoLevel.PathQueryEAsFromList: 73 break; 74 75 77 case FileInfoLevel.PathAllEAs: 78 break; 79 80 82 case FileInfoLevel.PathIsNameValid: 83 break; 84 85 87 case FileInfoLevel.PathFileBasicInfo: 88 case FileInfoLevel.NTFileBasicInfo: 89 packBasicFileInfo(info, buf); 90 break; 91 92 94 case FileInfoLevel.PathFileStandardInfo: 95 case FileInfoLevel.NTFileStandardInfo: 96 packStandardFileInfo(info, buf); 97 break; 98 99 101 case FileInfoLevel.PathFileEAInfo: 102 case FileInfoLevel.NTFileEAInfo: 103 packEAFileInfo(info, buf); 104 break; 105 106 108 case FileInfoLevel.PathFileNameInfo: 109 case FileInfoLevel.NTFileNameInfo: 110 packNameFileInfo(info, buf, uni); 111 break; 112 113 115 case FileInfoLevel.PathFileAllInfo: 116 case FileInfoLevel.NTFileAllInfo: 117 packAllFileInfo(info, buf, uni); 118 break; 119 120 122 case FileInfoLevel.PathFileAltNameInfo: 123 case FileInfoLevel.NTFileAltNameInfo: 124 packAlternateNameFileInfo(info, buf); 125 break; 126 127 129 case FileInfoLevel.PathFileStreamInfo: 130 case FileInfoLevel.NTFileStreamInfo: 131 packStreamFileInfo(info, buf, uni); 132 break; 133 134 136 case FileInfoLevel.PathFileCompressionInfo: 137 case FileInfoLevel.NTFileCompressionInfo: 138 packCompressionFileInfo(info, buf); 139 break; 140 141 143 case FileInfoLevel.NTFileInternalInfo: 144 packFileInternalInfo(info, buf); 145 break; 146 147 149 case FileInfoLevel.NTFilePositionInfo: 150 packFilePositionInfo(info, buf); 151 break; 152 153 155 case FileInfoLevel.NTAttributeTagInfo: 156 packFileAttributeTagInfo(info, buf); 157 break; 158 159 161 case FileInfoLevel.NTNetworkOpenInfo: 162 packFileNetworkOpenInfo(info, buf); 163 break; 164 } 165 166 168 return buf.getPosition() - curPos; 169 } 170 171 179 private static void packInfoStandard(FileInfo info, DataBuffer buf, boolean eaFlag, boolean uni) 180 { 181 182 194 196 SMBDate dateTime = new SMBDate(0); 197 198 if (info.hasCreationDateTime()) 199 { 200 dateTime.setTime(info.getCreationDateTime()); 201 buf.putShort(dateTime.asSMBDate()); 202 buf.putShort(dateTime.asSMBTime()); 203 } 204 else 205 buf.putZeros(4); 206 207 209 if (info.hasAccessDateTime()) 210 { 211 dateTime.setTime(info.getAccessDateTime()); 212 buf.putShort(dateTime.asSMBDate()); 213 buf.putShort(dateTime.asSMBTime()); 214 } 215 else 216 buf.putZeros(4); 217 218 220 if (info.hasModifyDateTime()) 221 { 222 dateTime.setTime(info.getModifyDateTime()); 223 buf.putShort(dateTime.asSMBDate()); 224 buf.putShort(dateTime.asSMBTime()); 225 } 226 else 227 buf.putZeros(4); 228 229 231 buf.putInt(info.getSizeInt()); 232 233 if (info.getAllocationSize() < info.getSize()) 234 buf.putInt(info.getSizeInt()); 235 else 236 buf.putInt(info.getAllocationSizeInt()); 237 238 240 buf.putShort(info.getFileAttributes()); 241 242 244 if (eaFlag == true) 245 buf.putZeros(4); 246 } 247 248 254 private static void packBasicFileInfo(FileInfo info, DataBuffer buf) 255 { 256 257 265 267 if (info.hasCreationDateTime()) 268 { 269 buf.putLong(NTTime.toNTTime(info.getCreationDateTime())); 270 } 271 else 272 buf.putZeros(8); 273 274 276 if (info.hasAccessDateTime()) 277 { 278 buf.putLong(NTTime.toNTTime(info.getAccessDateTime())); 279 } 280 else 281 buf.putZeros(8); 282 283 285 if (info.hasModifyDateTime()) 286 { 287 long ntTime = NTTime.toNTTime(info.getModifyDateTime()); 288 buf.putLong(ntTime); 289 buf.putLong(ntTime); 290 } 291 else 292 buf.putZeros(16); 293 294 296 buf.putInt(info.getFileAttributes()); 297 298 300 buf.putZeros(4); 301 } 302 303 309 private static void packStandardFileInfo(FileInfo info, DataBuffer buf) 310 { 311 312 320 322 if (info.getAllocationSize() < info.getSize()) 323 buf.putLong(info.getSize()); 324 else 325 buf.putLong(info.getAllocationSize()); 326 327 buf.putLong(info.getSize()); 328 329 331 buf.putInt(1); 332 333 335 buf.putByte(0); 336 buf.putByte(info.isDirectory() ? 1 : 0); 337 338 } 340 341 347 private static void packEAFileInfo(FileInfo info, DataBuffer buf) 348 { 349 350 353 355 buf.putInt(0); 356 } 357 358 365 private static void packNameFileInfo(FileInfo info, DataBuffer buf, boolean uni) 366 { 367 368 372 374 int nameLen = info.getFileName().length(); 375 if (uni) 376 nameLen *= 2; 377 378 buf.putInt(nameLen); 379 buf.putString(info.getFileName(), uni, false); 380 } 381 382 389 private static void packAllFileInfo(FileInfo info, DataBuffer buf, boolean uni) 390 { 391 392 409 411 if (info.hasCreationDateTime()) 412 { 413 buf.putLong(NTTime.toNTTime(info.getCreationDateTime())); 414 } 415 else 416 buf.putZeros(8); 417 418 420 if (info.hasAccessDateTime()) 421 { 422 buf.putLong(NTTime.toNTTime(info.getAccessDateTime())); 423 } 424 else 425 buf.putZeros(8); 426 427 429 if (info.hasModifyDateTime()) 430 { 431 long ntTime = NTTime.toNTTime(info.getModifyDateTime()); 432 buf.putLong(ntTime); 433 buf.putLong(ntTime); 434 } 435 else 436 buf.putZeros(16); 437 438 440 buf.putInt(info.getFileAttributes()); 441 442 444 buf.putInt(1); 445 446 448 if (info.getAllocationSize() < info.getSize()) 449 buf.putLong(info.getSize()); 450 else 451 buf.putLong(info.getAllocationSize()); 452 453 buf.putLong(info.getSize()); 454 455 457 buf.putByte(0); 458 buf.putByte(info.isDirectory() ? 1 : 0); 459 buf.putShort(0); 461 463 buf.putInt(0); 464 465 467 buf.putInt(0x00000003); 468 469 471 int nameLen = info.getFileName().length(); 472 if (uni) 473 nameLen *= 2; 474 475 buf.putInt(nameLen); 476 buf.putString(info.getFileName(), uni, false); 477 } 478 479 485 private static void packAlternateNameFileInfo(FileInfo info, DataBuffer buf) 486 { 487 } 488 489 496 private static void packStreamFileInfo(FileInfo info, DataBuffer buf, boolean uni) 497 { 498 499 506 508 String streamName = "::$DATA"; 509 510 buf.putInt(0); 512 int nameLen = streamName.length(); 513 if (uni) 514 nameLen *= 2; 515 buf.putInt(nameLen); 516 517 519 buf.putLong(info.getSize()); 520 521 523 if (info.getAllocationSize() < info.getSize()) 524 buf.putLong(info.getSize()); 525 else 526 buf.putLong(info.getAllocationSize()); 527 528 buf.putString(streamName, uni, false); 529 } 530 531 539 public static int packStreamFileInfo(StreamInfoList streams, DataBuffer buf, boolean uni) 540 { 541 542 549 551 int curPos = buf.getPosition(); 552 int startPos = curPos; 553 int pos = 0; 554 555 for (int i = 0; i < streams.numberOfStreams(); i++) 556 { 557 558 560 StreamInfo sinfo = streams.getStreamAt(i); 561 562 564 buf.putInt(0); 565 566 568 int nameLen = sinfo.getName().length(); 569 if (uni) 570 nameLen *= 2; 571 buf.putInt(nameLen); 572 573 575 buf.putLong(sinfo.getSize()); 576 577 579 if (sinfo.getAllocationSize() < sinfo.getSize()) 580 buf.putLong(sinfo.getSize()); 581 else 582 buf.putLong(sinfo.getAllocationSize()); 583 584 buf.putString(sinfo.getName(), uni, false); 585 586 588 buf.wordAlign(); 589 590 592 if (i < (streams.numberOfStreams() - 1)) 593 { 594 595 597 pos = buf.getPosition(); 598 buf.setPosition(startPos); 599 buf.putInt(pos - startPos); 600 buf.setPosition(pos); 601 startPos = pos; 602 } 603 } 604 605 607 return buf.getPosition() - curPos; 608 } 609 610 616 private static void packCompressionFileInfo(FileInfo info, DataBuffer buf) 617 { 618 619 623 buf.putLong(info.getSize()); 624 buf.putInt(WinNT.CompressionFormatNone); 625 } 626 627 633 private static void packFileInternalInfo(FileInfo info, DataBuffer buf) 634 { 635 636 640 buf.putInt(1); 641 buf.putInt(0); 642 } 643 644 650 private static void packFilePositionInfo(FileInfo info, DataBuffer buf) 651 { 652 653 657 buf.putInt(0); 658 buf.putInt(0); 659 } 660 661 667 private static void packFileNetworkOpenInfo(FileInfo info, DataBuffer buf) 668 { 669 670 680 682 if (info.hasCreationDateTime()) 683 { 684 buf.putLong(NTTime.toNTTime(info.getCreationDateTime())); 685 } 686 else 687 buf.putZeros(8); 688 689 691 if (info.hasAccessDateTime()) 692 { 693 buf.putLong(NTTime.toNTTime(info.getAccessDateTime())); 694 } 695 else 696 buf.putZeros(8); 697 698 700 if (info.hasModifyDateTime()) 701 { 702 long ntTime = NTTime.toNTTime(info.getModifyDateTime()); 703 buf.putLong(ntTime); 704 buf.putLong(ntTime); 705 } 706 else 707 buf.putZeros(16); 708 709 711 if (info.getAllocationSize() < info.getSize()) 712 buf.putLong(info.getSize()); 713 else 714 buf.putLong(info.getAllocationSize()); 715 716 buf.putLong(info.getSize()); 717 718 720 buf.putInt(info.getFileAttributes()); 721 722 724 buf.putInt(0); 725 } 726 727 733 private static void packFileAttributeTagInfo(FileInfo info, DataBuffer buf) 734 { 735 736 740 buf.putLong(0); 741 buf.putLong(0); 742 } 743 } 744 | Popular Tags |