home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / netz / nwfinf / nwfinf.cpp next >
Encoding:
C/C++ Source or Header  |  1994-05-12  |  6.1 KB  |  234 lines

  1. // Project     : NWFINF
  2. // Description : Application to show functions for getting Netware file info
  3. // Module      : NWFINF.CPP
  4. // Version     : 1.00 - 11/05/1994
  5. // Written by  : David A. Mair
  6. // Copyright   : Who cares, help yourself.
  7.  
  8.  
  9. #include "NWFINF.H"
  10.  
  11.  
  12. // Tell the user all about the program (Well a little about it anyway)
  13. void AboutApp(void)
  14.     {
  15.     cout << "\nNWFINF v1.00 - 1994 by David A. Mair\n\n";
  16.     }
  17.  
  18.  
  19. // Get the file info and display it
  20. void DisplayFileInfo(char *pszFileName)
  21.     {
  22.     struct TFileInformation tFileInfo;
  23.     struct TBinderyObjectInfo tBinderyObjectInfo;
  24.  
  25.     // For the first call to GetFileInformation for a given FileName
  26.     // string we must intialise tFileInfo.wSequence to 0xFFFF, for
  27.     // subsequent calls with the same filename string we should leave
  28.     // the value that is returned.  This allows a wildcard to be used
  29.     tFileInfo.wSequence = 0xFFFF;
  30.  
  31.     // Get the Netware file information record for the file
  32.     if (GetFileInformation(pszFileName, &tFileInfo) != 0)
  33.         {
  34.         cout << "ERROR: Could not get Netware file info for " << pszFileName << "\n";
  35.         cout << "       The file may not be on a Netware volume\n\n";
  36.         return;
  37.         }
  38.  
  39.     // Display the filename and the date information
  40.     cout << pszFileName << "\n";
  41.     // The date bit fields are in hi-lo byte order so they must be swapped
  42.     SwapDWord(&tFileInfo.dwFileSize);
  43.     cout << "    Size: " << tFileInfo.dwFileSize << "\n";
  44.     SwapWord((WORD far *)&tFileInfo.dtCreated);
  45.     cout << " Created: " << tFileInfo.dtCreated.dtDay << "/";
  46.     cout << tFileInfo.dtCreated.dtMonth << "/";
  47.     cout << (1980 + tFileInfo.dtCreated.dtYear) << "\n";
  48.     SwapWord((WORD far *)&tFileInfo.dtLastAccessed);
  49.     cout << "Accessed: " << tFileInfo.dtLastAccessed.dtDay << "/";
  50.     cout << tFileInfo.dtLastAccessed.dtMonth << "/";
  51.     cout << (1980 + tFileInfo.dtLastAccessed.dtYear) << "\n";
  52.  
  53.     // Using the returned owner object ID get the owner's name
  54.     if (GetBinderyObjectName(tFileInfo.dwOwner, &tBinderyObjectInfo) != 0)
  55.         {
  56.         SwapDWord(&(tFileInfo.dwOwner));
  57.         cout << "ERROR: Could not get Netware bindery info for file's owner: " << tFileInfo.dwOwner << "\n";
  58.         return;
  59.         }
  60.  
  61.     // Display the file's owner
  62.     cout << "   Owner: " << tBinderyObjectInfo.sName << "\n\n";
  63.     }
  64.  
  65.  
  66. // Get the netware file information for a file specified in:
  67. // <VOL>:\[SUBDIR\][SUBDIR\][...][<FILENAME>.<EXT>
  68. // eg, SYS:\LOGIN\LOGIN.EXE
  69. BYTE GetFileInformation(char *pszFileName, struct TFileInformation far *tFileInfo)
  70.     {
  71.     BYTE byCCode = 0;
  72.     TFileInfoRequest tRequestBuffer;
  73.  
  74.     // Fill in the request buffer
  75.     tRequestBuffer.byMagicNumber = 0x0F;
  76.     tRequestBuffer.wSequence = tFileInfo->wSequence;
  77.  
  78.     // Assume we have a complete file specification
  79.     tRequestBuffer.byDirHandle = 0;    // This need not always be the case
  80.  
  81.     // Search for all files
  82.     tRequestBuffer.saHiddenFiles = 1;
  83.     tRequestBuffer.saSystemFiles = 1;
  84.     tRequestBuffer.byFileNameLength = (BYTE)strlen(pszFileName);
  85.     strncpy(tRequestBuffer.sFileName, pszFileName, 256);
  86.     tRequestBuffer.wBuffLen = sizeof(tRequestBuffer) - 2;
  87.  
  88.     // Fill in the reply buffer
  89.     tFileInfo->wBuffLen = sizeof(*tFileInfo) - 2;
  90.  
  91.     // Make the call to the Netware API
  92.     asm {
  93.         les        di, dword ptr [tFileInfo]    // ES:DI -> Reply Buffer
  94.  
  95.         push    ds
  96.         mov        ax, ss
  97.         mov        ds, ax
  98.         lea        si, ds:tRequestBuffer        // DS:SI -> Request Buffer
  99.  
  100.         mov        ah, 0xE3
  101.         int        0x21
  102.  
  103.         pop        ds
  104.  
  105.         mov        byte ptr [byCCode], al
  106.         }
  107.  
  108.     return byCCode;
  109.     }
  110.  
  111.  
  112. // Return true if a file exists
  113. BOOL IsFile(char *pszFileName)
  114.     {
  115.     // If the parameter is the name of a file we should be able to open it
  116.     int hFile = open(pszFileName, O_RDONLY);
  117.  
  118.     // If we couldn't open the file
  119.     if (hFile == -1)
  120.         {
  121.         // It possibly isn't a file
  122.         return FALSE;
  123.         }
  124.  
  125.     // Don't forget to close the file
  126.     close(hFile);
  127.  
  128.     return TRUE;
  129.     }
  130.  
  131.  
  132. // Get the name for a bindery object ID
  133. BYTE GetBinderyObjectName(DWORD dwBinderyObjectID, TBinderyObjectInfo far *tBinderyObjectInfo)
  134.     {
  135.     BYTE byCCode = 0;
  136.     TBinderyObjectInfoRequest tBinderyReq;
  137.  
  138.     // Fill in the request parameters
  139.     tBinderyReq.wBuffLen = sizeof(tBinderyReq) - 2;
  140.     tBinderyReq.byMagicNumber = 0x36;
  141.     tBinderyReq.dwLastID = dwBinderyObjectID; // In this case I know the byte order has been swapped
  142.  
  143.     // Fill in the required parts of the reply buffer
  144.     tBinderyObjectInfo->wBuffLen = sizeof(*tBinderyObjectInfo) - 2;
  145.  
  146.     // Call the Netware API function
  147.     asm {
  148.         les        di, dword ptr [tBinderyObjectInfo]    // ES:DI -> Reply Buffer
  149.  
  150.         push    ds
  151.         mov        ax, ss
  152.         mov        ds, ax
  153.         lea        si, ds:tBinderyReq                    // DS:SI -> Request Buffer
  154.  
  155.         mov        ah, 0xE3
  156.         int        0x21
  157.  
  158.         pop        ds
  159.  
  160.         mov        byte ptr [byCCode], al
  161.         }
  162.  
  163.     return byCCode;
  164.     }
  165.  
  166.  
  167. // What can I add
  168. void ShowSyntax(void)
  169.     {
  170.     cout << "USAGE: NWFINF <filespec>\n";
  171.     cout << "Where: <filespec> is the fully qualified name of a file on a network disc\n\n";
  172.     }
  173.  
  174.  
  175. // Change the byte ordering of a
  176. void SwapDWord(DWORD far *dwToSwap)
  177.     {
  178.     // Do it in assembler, probably quicker
  179.     asm {
  180.         les        di, dword ptr [dwToSwap]
  181.         mov        ax, word ptr es:[di]
  182.         mov        bx, word ptr es:[di + 2]
  183.         xchg    ah, al
  184.         xchg    bh, bl
  185.         mov        word ptr es:[di], bx
  186.         mov        word ptr es:[di + 2], ax
  187.         }
  188.     }
  189.  
  190.  
  191. // Swap the byte ordering of a WORD
  192. void SwapWord(WORD far *wToSwap)
  193.     {
  194.     asm {
  195.         les        di, dword ptr [wToSwap]
  196.         mov        ax, word ptr es:[di]
  197.         xchg    ah, al
  198.         mov        word ptr es:[di], ax
  199.         }
  200.     }
  201.  
  202.  
  203. // The entry point, expects one parameter of the form
  204. // <VOL>:\[SUBDIR LIST\]<FILENAME>.<EXT>
  205. // For example SYS:\LOGIN\LOGIN.EXE
  206. // There is no code to select a server, the default will normally
  207. // be the one you last selected a mapped drive of
  208. int main(int argc, char *argv[])
  209.     {
  210.     // Tell the world who we are
  211.     AboutApp();
  212.  
  213.     // We must have one parameter, a file
  214.     if (argc != 2)
  215.         {
  216.         ShowSyntax();
  217.         return 1;
  218.         }
  219.  
  220.     // The parameter must be a file, this may not work because of the
  221.     // method of specifying the filename, if so comment out the whole
  222.     // if statement.
  223.     if (!IsFile(argv[1]))
  224.         {
  225.         cout << "ERROR: Cannot use file: " << argv[1] << "\n";
  226.         return 1;
  227.         }
  228.  
  229.     // Output the file information
  230.     DisplayFileInfo(argv[1]);
  231.  
  232.     return 0;
  233.     }
  234.