Jump to content

DosProtectQueryFileInfo: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Description==
Gets file information.
Gets file information.


Line 7: Line 6:
#include <os2.h>
#include <os2.h>


HFILE    hf;                 /*  File handle. */
HFILE    hf;                 /*  File handle. */
ULONG    ulInfoLevel;         /*  Level of file information required. */
ULONG    ulInfoLevel;       /*  Level of file information required. */
PVOID    pInfo;               /*  Address of the storage area where the system returns the requested level of file information. */
PVOID    pInfo;             /*  Address of the storage area where the system returns
ULONG    cbInfoBuf;           /*  The length, in bytes, of pInfo. */
                                  the requested level of file information. */
FHLOCK    fhFileHandleLockID; /*  The filehandle lockid returned by a previous DosProtectOpen. */
ULONG    cbInfoBuf;         /*  The length, in bytes, of pInfo. */
APIRET    ulrc;               /*  Return Code. */
FHLOCK    fhFileHandleLockID; /*  The filehandle lockid returned by a previous DosProtectOpen. */
APIRET    ulrc;               /*  Return Code. */


ulrc = DosProtectQueryFileInfo(hf, ulInfoLevel,
ulrc = DosProtectQueryFileInfo(hf, ulInfoLevel,
         pInfo, cbInfoBuf, fhFileHandleLockID);
         pInfo, cbInfoBuf, fhFileHandleLockID);
</PRE>


</PRE>
==Parameters==
==Parameters==
; hf (HFILE) - input : File handle.  
;hf (HFILE) - input : File handle.
;ulInfoLevel (ULONG) - input : Level of file information required.
:A value of 1, 2, or 3 can be specified, as shown in the following list:
::1 FIL_STANDARD - Level 1 file information
::2 FIL_QUERYEASIZE - Level 2 file information
::3 FIL_QUERYEASFROMLIST - Level 3 file information
::Level 4 is reserved.
:The structures described in pInfo indicate the information returned for each of these levels.
;pInfo (PVOID) - output: Address of the storage area where the system returns the requested level of file information.


; ulInfoLevel (ULONG) - input : Level of file information required.
File information, where applicable, is at least as accurate as the most recent DosProtectClose, DosResetBuffer, DosProtectSetFileInfo, or DosSetPathInfo.


Level 1 File Information (ulInfoLevel == FIL_STANDARD)


A value of 1, 2, or 3 can be specified, as shown in the following list:
pInfo contains the FILESTATUS3 data structure, to which file information is returned.
Level 2 File Information (ulInfoLevel == FIL_QUERYEASIZE)


    1 FIL_STANDARD
pInfo contains the FILESTATUS4 data structure. This is similar to the Level 1 structure, with the addition of the cbList field after the attrFile field.
    Level 1 file information
 
The cbList field is an 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.  
    2 FIL_QUERYEASIZE
    Level 2 file information
Level 3 File Information (ulInfoLevel == FIL_QUERYEASFROMLIST)
 
    3 FIL_QUERYEASFROMLIST
    Level 3 file information
 
    Level 4 is reserved.
 
The structures described in pInfo indicate the information returned for each of these levels.  
 
; pInfo (PVOID) - output: Address of the storage area where the system returns the requested level of file information.


File information, where applicable, is at least as accurate as the most recent DosProtectClose, DosResetBuffer, DosProtectSetFileInfo, or DosSetPathInfo.
Input


    Level 1 File Information (ulInfoLevel == FIL_STANDARD)
pInfo contains an EAOP2 data structure. fpGEA2List points to a GEA2 list defining the attribute names whose values are returned. The GEA2 data structures must be aligned on a doubleword boundary. Each oNextEntryOffset field must contain the number of bytes from the beginning of the current entry to the beginning of the next entry in the GEA2 list. The oNextEntryOffset field in the last entry of the GEA2 list must be zero. fpFEA2List points to a data area where the relevant FEA2 list is returned. The length field of this FEA2 list is valid, giving the size of the FEA2 list buffer. oError is ignored.  
        pInfo contains the FILESTATUS3 data structure, to which file information is returned.  
   
   
    Level 2 File Information (ulInfoLevel == FIL_QUERYEASIZE)
Output
        pInfo contains the FILESTATUS4 data structure. This is similar to the Level 1 structure, with the addition of the cbList field after the attrFile field.
        The cbList field is an 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.
    Level 3 File Information (ulInfoLevel == FIL_QUERYEASFROMLIST)


        Input
pInfo is unchanged. The buffer pointed to by fpFEA2List is filled in with the returned information. If the buffer that fpFEA2List points to is not large enough to hold the returned information (the return code is ERROR_BUFFER_OVERFLOW), cbList is still valid, assuming there is at least enough space for it. Its value is the size of the entire EA set on disk for the file, even though only a subset of attributes was requested.  
            pInfo contains an EAOP2 data structure. fpGEA2List points to a GEA2 list defining the attribute names whose values are returned. The GEA2 data structures must be aligned on a doubleword boundary. Each oNextEntryOffset field must contain the number of bytes from the beginning of the current entry to the beginning of the next entry in the GEA2 list. The oNextEntryOffset field in the last entry of the GEA2 list must be zero. fpFEA2List points to a data area where the relevant FEA2 list is returned. The length field of this FEA2 list is valid, giving the size of the FEA2 list buffer. oError is ignored.
        Output
            pInfo is unchanged. The buffer pointed to by fpFEA2List is filled in with the returned information. If the buffer that fpFEA2List points to is not large enough to hold the returned information (the return code is ERROR_BUFFER_OVERFLOW), cbList is still valid, assuming there is at least enough space for it. Its value is the size of the entire EA set on disk for the file, even though only a subset of attributes was requested.  


; cbInfoBuf (ULONG) - input : The length, in bytes, of pInfo.  
;cbInfoBuf (ULONG) - input : The length, in bytes, of pInfo.
;fhFileHandleLockID (FHLOCK) - input : The filehandle lockid returned by a previous DosProtectOpen.


; fhFileHandleLockID (FHLOCK) - input : The filehandle lockid returned by a previous DosProtectOpen.
==Return Code==
==Return Code==
ulrc (APIRET) - returns
;ulrc (APIRET) - returns:DosProtectQueryFileInfo returns one of the following values:
 
* 0 NO_ERROR
DosProtectQueryFileInfo returns one of the following values:
* 5 ERROR_ACCESS_DENIED
* 6 ERROR_INVALID_HANDLE
* 111 ERROR_BUFFER_OVERFLOW
* 124 ERROR_INVALID_LEVEL
* 130 ERROR_DIRECT_ACCESS_HANDLE
* 254 ERROR_INVALID_EA_NAME
* 255 ERROR_EA_LIST_INCONSISTENT


* 0    NO_ERROR
* 5    ERROR_ACCESS_DENIED
* 6    ERROR_INVALID_HANDLE
* 111        ERROR_BUFFER_OVERFLOW
* 124        ERROR_INVALID_LEVEL
* 130        ERROR_DIRECT_ACCESS_HANDLE
* 254        ERROR_INVALID_EA_NAME
* 255        ERROR_EA_LIST_INCONSISTENT
==Remarks==
==Remarks==
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.
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.
Line 81: Line 71:


DosProtectEnumAttribute returns the lengths of extended attributes. This information can be used to calculate what size pInfo needs to be to hold full-extended-attribute (FEA) information returned by DosProtectQueryFileInfo when Level 3 is specified. The size of the buffer is calculated as follows:
DosProtectEnumAttribute returns the lengths of extended attributes. This information can be used to calculate what size pInfo needs to be to hold full-extended-attribute (FEA) information returned by DosProtectQueryFileInfo when Level 3 is specified. The size of the buffer is calculated as follows:
 
Four bytes (for oNextEntryOffset) +
    Four bytes (for oNextEntryOffset) +
One byte (for fEA) +
    One byte (for fEA) +
One byte (for cbName) +
    One byte (for cbName) +
Two bytes (for cbValue) +
    Two bytes (for cbValue) +
Value of cbName (for the name of the EA) +
    Value of cbName (for the name of the EA) +
One byte (for terminating NULL in cbName) +
    One byte (for terminating NULL in cbName) +
Value of cbValue (for the value of the EA)
    Value of cbValue (for the value of the EA)


==Example Code==
==Example Code==
Line 151: Line 140:
   return NO_ERROR;
   return NO_ERROR;
}
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosProtectClose|DosProtectClose]]
* [[DosProtectClose]]
* [[OS2 API:CPI:DosProtectOpen|DosProtectOpen]]
* [[DosProtectOpen]]
* [[OS2 API:CPI:DosProtectEnumAttribute|DosProtectEnumAttribute]]
* [[DosProtectEnumAttribute]]
* [[OS2 API:CPI:DosProtectSetFileInfo|DosProtectSetFileInfo]]
* [[DosProtectSetFileInfo]]
* [[OS2 API:CPI:DosQueryPathInfo|DosQueryPathInfo]]
* [[DosQueryPathInfo]]
* [[OS2 API:CPI:DosResetBuffer|DosResetBuffer]]
* [[DosResetBuffer]]
* [[OS2 API:CPI:DosProtectSetFileSize|DosProtectSetFileSize]]
* [[DosProtectSetFileSize]]
* [[OS2 API:CPI:DosSetPathInfo|DosSetPathInfo]]
* [[DosSetPathInfo]]
 


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 00:37, 27 May 2021

Gets file information.

Syntax

#define INCL_DOSFILEMGR
#include <os2.h>

HFILE     hf;                 /*  File handle. */
ULONG     ulInfoLevel;        /*  Level of file information required. */
PVOID     pInfo;              /*  Address of the storage area where the system returns
                                  the requested level of file information. */
ULONG     cbInfoBuf;          /*  The length, in bytes, of pInfo. */
FHLOCK    fhFileHandleLockID; /*  The filehandle lockid returned by a previous DosProtectOpen. */
APIRET    ulrc;               /*  Return Code. */

ulrc = DosProtectQueryFileInfo(hf, ulInfoLevel,
         pInfo, cbInfoBuf, fhFileHandleLockID);

Parameters

hf (HFILE) - input
File handle.
ulInfoLevel (ULONG) - input
Level of file information required.
A value of 1, 2, or 3 can be specified, as shown in the following list:
1 FIL_STANDARD - Level 1 file information
2 FIL_QUERYEASIZE - Level 2 file information
3 FIL_QUERYEASFROMLIST - Level 3 file information
Level 4 is reserved.
The structures described in pInfo indicate the information returned for each of these levels.
pInfo (PVOID) - output
Address of the storage area where the system returns the requested level of file information.

File information, where applicable, is at least as accurate as the most recent DosProtectClose, DosResetBuffer, DosProtectSetFileInfo, or DosSetPathInfo.

Level 1 File Information (ulInfoLevel == FIL_STANDARD)

pInfo contains the FILESTATUS3 data structure, to which file information is returned.

Level 2 File Information (ulInfoLevel == FIL_QUERYEASIZE)

pInfo contains the FILESTATUS4 data structure. This is similar to the Level 1 structure, with the addition of the cbList field after the attrFile field.

The cbList field is an 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.

Level 3 File Information (ulInfoLevel == FIL_QUERYEASFROMLIST)

Input

pInfo contains an EAOP2 data structure. fpGEA2List points to a GEA2 list defining the attribute names whose values are returned. The GEA2 data structures must be aligned on a doubleword boundary. Each oNextEntryOffset field must contain the number of bytes from the beginning of the current entry to the beginning of the next entry in the GEA2 list. The oNextEntryOffset field in the last entry of the GEA2 list must be zero. fpFEA2List points to a data area where the relevant FEA2 list is returned. The length field of this FEA2 list is valid, giving the size of the FEA2 list buffer. oError is ignored.

Output

pInfo is unchanged. The buffer pointed to by fpFEA2List is filled in with the returned information. If the buffer that fpFEA2List points to is not large enough to hold the returned information (the return code is ERROR_BUFFER_OVERFLOW), cbList is still valid, assuming there is at least enough space for it. Its value is the size of the entire EA set on disk for the file, even though only a subset of attributes was requested.

cbInfoBuf (ULONG) - input
The length, in bytes, of pInfo.
fhFileHandleLockID (FHLOCK) - input
The filehandle lockid returned by a previous DosProtectOpen.

Return Code

ulrc (APIRET) - returns
DosProtectQueryFileInfo returns one of the following values:
  • 0 NO_ERROR
  • 5 ERROR_ACCESS_DENIED
  • 6 ERROR_INVALID_HANDLE
  • 111 ERROR_BUFFER_OVERFLOW
  • 124 ERROR_INVALID_LEVEL
  • 130 ERROR_DIRECT_ACCESS_HANDLE
  • 254 ERROR_INVALID_EA_NAME
  • 255 ERROR_EA_LIST_INCONSISTENT

Remarks

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, DosProtectQueryFileInfo must be able to read the open file. DosProtectQueryFileInfo 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 DosProtectOpen will fail.

DosProtectEnumAttribute returns the lengths of extended attributes. This information can be used to calculate what size pInfo needs to be to hold full-extended-attribute (FEA) information returned by DosProtectQueryFileInfo 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)

Example Code

This example creates a read-only file named "DOSFDEL.DAT", then changes the file attributes to normal, and uses DosForceDelete to delete the file so that it can not be restored using UNDELETE.

 #define INCL_DOSFILEMGR   /* File Manager values */
 #define INCL_DOSERRORS    /* DOS error values    */
 #include <os2.h>
 #include <stdio.h>

 int main(VOID) {

 UCHAR       uchFileName[]   = "DOSFDEL.DAT";   /* File we want to delete    */
 HFILE       fhDelFile       = 0;               /* File handle from DosOpen  */
 FILESTATUS3 fsts3FileInfo   = {{0}};  /* Information associated with file   */
 ULONG       ulBufferSize    = sizeof(FILESTATUS3); /* File info buffer size */
 ULONG       ulOpenAction    = 0;                 /* Action taken by DosOpen */
 APIRET      rc              = NO_ERROR;          /* Return code             */
 FHLOCK      FHLock          = 0;                 /* File handle lock        */

                 /* Create a read-only file */

  rc = DosProtectOpen(uchFileName, &fhDelFile,
               &ulOpenAction, 10L, FILE_READONLY,
               OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
               OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L, &FHLock);
  if (rc != NO_ERROR) {
     printf("DosProtectOpen error: return code = %u\n", rc);
     return 1;
  }

  rc = DosProtectQueryFileInfo(fhDelFile, FIL_STANDARD,
               &fsts3FileInfo, ulBufferSize, FHLock);   /* Get standard info */
  if (rc != NO_ERROR) {
      printf("DosProtectQueryFileInfo error: return code = %u\n", rc);
      return 1;
  } else { printf("File %s created read-only.\n",uchFileName); }

    /*   Change the file attributes to be "normal"  */

    fsts3FileInfo.attrFile  = FILE_NORMAL;
    rc = DosProtectSetFileInfo(fhDelFile, FIL_STANDARD,
                        &fsts3FileInfo, ulBufferSize, FHLock);
    if (rc != NO_ERROR) {
        printf("DosProtectSetFileInfo error: return code = %u\n", rc);
        return 1;
    }

    rc = DosProtectClose(fhDelFile, FHLock);
    /* Should verify that (rc != NO_ERROR) here... */

           /* Delete the file */

    rc = DosForceDelete(uchFileName);
    if (rc != NO_ERROR) {
        printf("DosForceDelete error: return code = %u\n", rc);
        return 1;
    } else {
        printf("File %s has been deleted.\n",uchFileName);
    }  /* endif */

   return NO_ERROR;
}

Related Functions