home *** CD-ROM | disk | FTP | other *** search
- // Project : NWFINF
- // Description : Application to show functions for getting Netware file info
- // Module : NWFINF.CPP
- // Version : 1.00 - 11/05/1994
- // Written by : David A. Mair
- // Copyright : Who cares, help yourself.
-
-
- #include "NWFINF.H"
-
-
- // Tell the user all about the program (Well a little about it anyway)
- void AboutApp(void)
- {
- cout << "\nNWFINF v1.00 - 1994 by David A. Mair\n\n";
- }
-
-
- // Get the file info and display it
- void DisplayFileInfo(char *pszFileName)
- {
- struct TFileInformation tFileInfo;
- struct TBinderyObjectInfo tBinderyObjectInfo;
-
- // For the first call to GetFileInformation for a given FileName
- // string we must intialise tFileInfo.wSequence to 0xFFFF, for
- // subsequent calls with the same filename string we should leave
- // the value that is returned. This allows a wildcard to be used
- tFileInfo.wSequence = 0xFFFF;
-
- // Get the Netware file information record for the file
- if (GetFileInformation(pszFileName, &tFileInfo) != 0)
- {
- cout << "ERROR: Could not get Netware file info for " << pszFileName << "\n";
- cout << " The file may not be on a Netware volume\n\n";
- return;
- }
-
- // Display the filename and the date information
- cout << pszFileName << "\n";
- // The date bit fields are in hi-lo byte order so they must be swapped
- SwapDWord(&tFileInfo.dwFileSize);
- cout << " Size: " << tFileInfo.dwFileSize << "\n";
- SwapWord((WORD far *)&tFileInfo.dtCreated);
- cout << " Created: " << tFileInfo.dtCreated.dtDay << "/";
- cout << tFileInfo.dtCreated.dtMonth << "/";
- cout << (1980 + tFileInfo.dtCreated.dtYear) << "\n";
- SwapWord((WORD far *)&tFileInfo.dtLastAccessed);
- cout << "Accessed: " << tFileInfo.dtLastAccessed.dtDay << "/";
- cout << tFileInfo.dtLastAccessed.dtMonth << "/";
- cout << (1980 + tFileInfo.dtLastAccessed.dtYear) << "\n";
-
- // Using the returned owner object ID get the owner's name
- if (GetBinderyObjectName(tFileInfo.dwOwner, &tBinderyObjectInfo) != 0)
- {
- SwapDWord(&(tFileInfo.dwOwner));
- cout << "ERROR: Could not get Netware bindery info for file's owner: " << tFileInfo.dwOwner << "\n";
- return;
- }
-
- // Display the file's owner
- cout << " Owner: " << tBinderyObjectInfo.sName << "\n\n";
- }
-
-
- // Get the netware file information for a file specified in:
- // <VOL>:\[SUBDIR\][SUBDIR\][...][<FILENAME>.<EXT>
- // eg, SYS:\LOGIN\LOGIN.EXE
- BYTE GetFileInformation(char *pszFileName, struct TFileInformation far *tFileInfo)
- {
- BYTE byCCode = 0;
- TFileInfoRequest tRequestBuffer;
-
- // Fill in the request buffer
- tRequestBuffer.byMagicNumber = 0x0F;
- tRequestBuffer.wSequence = tFileInfo->wSequence;
-
- // Assume we have a complete file specification
- tRequestBuffer.byDirHandle = 0; // This need not always be the case
-
- // Search for all files
- tRequestBuffer.saHiddenFiles = 1;
- tRequestBuffer.saSystemFiles = 1;
- tRequestBuffer.byFileNameLength = (BYTE)strlen(pszFileName);
- strncpy(tRequestBuffer.sFileName, pszFileName, 256);
- tRequestBuffer.wBuffLen = sizeof(tRequestBuffer) - 2;
-
- // Fill in the reply buffer
- tFileInfo->wBuffLen = sizeof(*tFileInfo) - 2;
-
- // Make the call to the Netware API
- asm {
- les di, dword ptr [tFileInfo] // ES:DI -> Reply Buffer
-
- push ds
- mov ax, ss
- mov ds, ax
- lea si, ds:tRequestBuffer // DS:SI -> Request Buffer
-
- mov ah, 0xE3
- int 0x21
-
- pop ds
-
- mov byte ptr [byCCode], al
- }
-
- return byCCode;
- }
-
-
- // Return true if a file exists
- BOOL IsFile(char *pszFileName)
- {
- // If the parameter is the name of a file we should be able to open it
- int hFile = open(pszFileName, O_RDONLY);
-
- // If we couldn't open the file
- if (hFile == -1)
- {
- // It possibly isn't a file
- return FALSE;
- }
-
- // Don't forget to close the file
- close(hFile);
-
- return TRUE;
- }
-
-
- // Get the name for a bindery object ID
- BYTE GetBinderyObjectName(DWORD dwBinderyObjectID, TBinderyObjectInfo far *tBinderyObjectInfo)
- {
- BYTE byCCode = 0;
- TBinderyObjectInfoRequest tBinderyReq;
-
- // Fill in the request parameters
- tBinderyReq.wBuffLen = sizeof(tBinderyReq) - 2;
- tBinderyReq.byMagicNumber = 0x36;
- tBinderyReq.dwLastID = dwBinderyObjectID; // In this case I know the byte order has been swapped
-
- // Fill in the required parts of the reply buffer
- tBinderyObjectInfo->wBuffLen = sizeof(*tBinderyObjectInfo) - 2;
-
- // Call the Netware API function
- asm {
- les di, dword ptr [tBinderyObjectInfo] // ES:DI -> Reply Buffer
-
- push ds
- mov ax, ss
- mov ds, ax
- lea si, ds:tBinderyReq // DS:SI -> Request Buffer
-
- mov ah, 0xE3
- int 0x21
-
- pop ds
-
- mov byte ptr [byCCode], al
- }
-
- return byCCode;
- }
-
-
- // What can I add
- void ShowSyntax(void)
- {
- cout << "USAGE: NWFINF <filespec>\n";
- cout << "Where: <filespec> is the fully qualified name of a file on a network disc\n\n";
- }
-
-
- // Change the byte ordering of a
- void SwapDWord(DWORD far *dwToSwap)
- {
- // Do it in assembler, probably quicker
- asm {
- les di, dword ptr [dwToSwap]
- mov ax, word ptr es:[di]
- mov bx, word ptr es:[di + 2]
- xchg ah, al
- xchg bh, bl
- mov word ptr es:[di], bx
- mov word ptr es:[di + 2], ax
- }
- }
-
-
- // Swap the byte ordering of a WORD
- void SwapWord(WORD far *wToSwap)
- {
- asm {
- les di, dword ptr [wToSwap]
- mov ax, word ptr es:[di]
- xchg ah, al
- mov word ptr es:[di], ax
- }
- }
-
-
- // The entry point, expects one parameter of the form
- // <VOL>:\[SUBDIR LIST\]<FILENAME>.<EXT>
- // For example SYS:\LOGIN\LOGIN.EXE
- // There is no code to select a server, the default will normally
- // be the one you last selected a mapped drive of
- int main(int argc, char *argv[])
- {
- // Tell the world who we are
- AboutApp();
-
- // We must have one parameter, a file
- if (argc != 2)
- {
- ShowSyntax();
- return 1;
- }
-
- // The parameter must be a file, this may not work because of the
- // method of specifying the filename, if so comment out the whole
- // if statement.
- if (!IsFile(argv[1]))
- {
- cout << "ERROR: Cannot use file: " << argv[1] << "\n";
- return 1;
- }
-
- // Output the file information
- DisplayFileInfo(argv[1]);
-
- return 0;
- }
-