Purpose
DosQueryFileInfo gets file information.
Syntax
#define INCL DOSFILEMGR #include os2.h
APIRET DosQueryFileInfo
Parameters
hf HFILE) input
Specify a value
Level 1 file information
11
Level 11 file information
Level 2 file information
Level 12 file information
Level 3 file information
The structures described in pInfo indicate the information returned for each of these levels.
File information, where applicable, is at least as accurate as the most recent DosClose, DosResetBuffer, DosSetFileInfo, or DosSetPathInfo.
Level 1 File Information (ulInfoLevel == FIL_STANDARD)
The cbList field is an unsigned ULONG. On output, this field contains the size, in bytes, of the file s entire extended attribute (EA) set on disk. You can use this value to calculate the size of the buffer required to hold the EA information returned when a value of 3 is specified for ulInfoLevel. The buffer size is less than or equal to twice the size of the file s entire EA set on disk.
The cbList field is an unsigned ULONG. On output, this field contains the size, in bytes, of the file s entire extended attribute (EA) set on disk. You can use this value to calculate the size of the buffer required to hold the EA information returned when a value of 3 is specified for ulInfoLevel. The buffer size is less than or equal to twice the size of the file s entire EA set on disk.
Input
Returns
ulrc APIRET) returns
DosQueryFileInfo returns one of the following values
111
Remarks
Information levels designated L should be used in order to get complete size information for files larger than 2GB. If information levels designated L are not used, a size of one byte will be returned for files which are >2GB in size.
In the FAT file system, only date and time information contained in Level 1 file information can be modified. Zero is returned for the creation and access dates and times.
To return information contained in any of the file information levels, DosQueryFileInfo must be able to read the open file. DosQueryFileInfo works only when the file is opened for read access, with a deny-write sharing mode specified for access by other processes. If another process that has specified conflicting sharing and access modes has already opened the file, any call to DosOpenL will fail.
DosEnumAttribute returns the lengths of EAs. This information can be used to calculate what size pInfo needs to be to hold full-extended-attribute (FEA) information returned by DosQueryFileInfo when Level 3 is specified. The size of the buffer is calculated as follows
Four bytes (for oNextEntryOffset) + One byte (for
fEA +
One byte (for cbName) +
Two bytes (for cbValue) +
Value of cbName (for the name of the EA) +
One byte (for terminating NULL in cbName) +
Value of cbValue (for the value of the EA)
Related Functions
Example Code
This example obtains the information of the CONFIG.SYS file.
#define INCL_DOSFILEMGR /* File Manager values */#define INCL_DOSERRORS /* DOS error values */ #include os2.h #include stdio.h int main(VOID) UCHAR uchFileName 80 = "C \\CONFIG.SYS"; /* File to manipulate */ FILESTATUS3L fsts3ConfigInfo = 0 ; /* Buffer for file information */ ULONG ulBufSize = sizeof(FILESTATUS3L); /* Size of above buffer */ HFILE hfConfig = 0; /* Handle for Config file */ ULONG ulOpenAction = 0; /* Action taken by DosOpenL */ APIRET rc = NO_ERROR; /* Return code */ rc = DosOpenL(uchFileName, /* File to open (path and name) */ hfConfig, /* File handle returned */ ulOpenAction, /* Action taken by DosOpenL */ (LONGLONG)0,0L, /* Primary allocation and attributes (ignored) */ OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, /* Open an existing file only */ OPEN_FLAGS_NOINHERIT | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, /* Read access only */ 0L); /* Extended attributes (ignored)*/ if (rc != NO_ERROR) printf("DosOpenL error return code = %u\n", rc); return 1; rc = DosQueryFileInfo(hfConfig, /* Handle of file */ FIL_STANDARDL, /* Request standard (Level 11) info */ fsts3ConfigInfo, /* Buffer for file information */ ulBufSize); /* Size of buffer */ if (rc != NO_ERROR) printf("DosQueryFileInfo error return code = %u\n", rc); return 1; rc = DosClose(hfConfig); /* Close the file (check RC in real life) */ printf("%s --- File size %lld bytes\n",uchFileName, fsts3ConfigInfo.cbFile); printf("Last updated %d/%d/%d; %d %2.2d\n", fsts3ConfigInfo.fdateLastWrite.month, /* Month */ fsts3ConfigInfo.fdateLastWrite.day, /* Day */ (fsts3ConfigInfo.fdateLastWrite.year+1980L), /* Years since 1980 */ fsts3ConfigInfo.ftimeLastWrite.hours, /* Hours */ fsts3ConfigInfo.ftimeLastWrite.minutes); /* Minutes */ return NO_ERROR;