Jump to content

DosProtectSetFileSize: 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==
Changes the size of a file.
Changes the size of a file.


==Syntax==
==Syntax==
<PRE>
  DosProtectSetFileSize(hFile, cbSize, fhFileHandleLockID)
#define INCL_DOSFILEMGR
#include <os2.h>
 
HFILE    hFile;              /*  Handle of the file whose size to be changed. */
ULONG    cbSize;              /*  New size, in bytes, of the file. */
FHLOCK    fhFileHandleLockID;  /*  The filehandle lockid obtained from DosProtectOpen. */
APIRET    ulrc;                /* Return Code. */
 
ulrc = DosProtectSetFileSize(hFile, cbSize, fhFileHandleLockID);


</PRE>
==Parameters==
==Parameters==
; hFile (HFILE) - input : Handle of the file whose size to be changed.  
;hFile ([[HFILE]]) - input: Handle of the file whose size to be changed.
 
;cbSize (ULONG) - input: New size, in bytes, of the file.
; cbSize (ULONG) - input : New size, in bytes, of the file.  
;fhFileHandleLockID ([[FHLOCK]]) - input : The filehandle lockid obtained from DosProtectOpen.
 
; fhFileHandleLockID (FHLOCK) - input : The filehandle lockid obtained from DosProtectOpen.  


==Return Code==
==Return Code==
ulrc (APIRET) - returns
;ulrc (APIRET) - returns:DosProtectSetFileSize returns one of the following values:
* 0 NO_ERROR
* 5 ERROR_ACCESS_DENIED
* 6 ERROR_INVALID_HANDLE
* 26 ERROR_NOT_DOS_DISK
* 33 ERROR_LOCK_VIOLATION
* 87 ERROR_INVALID_PARAMETER
* 112 ERROR_DISK_FULL


DosProtectSetFileSize returns one of the following values:
* 0    NO_ERROR
* 5        ERROR_ACCESS_DENIED
* 6        ERROR_INVALID_HANDLE
* 26        ERROR_NOT_DOS_DISK
* 33        ERROR_LOCK_VIOLATION
* 87        ERROR_INVALID_PARAMETER
* 112        ERROR_DISK_FULL
==Remarks==
==Remarks==
When DosProtectSetFileSize is issued, the file must be open in a mode that allows write access.
When DosProtectSetFileSize is issued, the file must be open in a mode that allows write access.


The size of the open file can be truncated or extended. If the file size is being extended, the file system tries to allocate additional bytes in a contiguous (or nearly contiguous) space on the medium. The values of the new bytes are undefined.  
The size of the open file can be truncated or extended. If the file size is being extended, the file system tries to allocate additional bytes in a contiguous (or nearly contiguous) space on the medium. The values of the new bytes are undefined.


==Example Code==
==Example Code==
Line 91: Line 76:
   return NO_ERROR;
   return NO_ERROR;
}
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosProtectOpen|DosProtectOpen]]
* [[DosProtectOpen]]
* [[OS2 API:CPI:DosProtectQueryFileInfo|DosProtectQueryFileInfo]]
* [[DosProtectQueryFileInfo]]
* [[OS2 API:CPI:DosQueryPathInfo|DosQueryPathInfo]]
* [[DosQueryPathInfo]]
 


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

Latest revision as of 14:45, 18 June 2018

Changes the size of a file.

Syntax

DosProtectSetFileSize(hFile, cbSize, fhFileHandleLockID)

Parameters

hFile (HFILE) - input
Handle of the file whose size to be changed.
cbSize (ULONG) - input
New size, in bytes, of the file.
fhFileHandleLockID (FHLOCK) - input
The filehandle lockid obtained from DosProtectOpen.

Return Code

ulrc (APIRET) - returns
DosProtectSetFileSize returns one of the following values:
  • 0 NO_ERROR
  • 5 ERROR_ACCESS_DENIED
  • 6 ERROR_INVALID_HANDLE
  • 26 ERROR_NOT_DOS_DISK
  • 33 ERROR_LOCK_VIOLATION
  • 87 ERROR_INVALID_PARAMETER
  • 112 ERROR_DISK_FULL

Remarks

When DosProtectSetFileSize is issued, the file must be open in a mode that allows write access.

The size of the open file can be truncated or extended. If the file size is being extended, the file system tries to allocate additional bytes in a contiguous (or nearly contiguous) space on the medium. The values of the new bytes are undefined.

Example Code

This example writes to a file named "DOSPMAN.DAT", resets the buffer, and changes the size of the file using DosProtect functions.

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

int main(VOID) {
   HFILE  hfFileHandle   = 0L;     /* Handle for file being manipulated */
   ULONG  ulAction       = 0;      /* Action taken by DosOpen */
   FHLOCK FileHandleLock = 0;      /* File handle lock   */

   ULONG  ulWrote        = 0;      /* Number of bytes written by DosWrite */
   UCHAR  uchFileName[20]  = "dospman.dat",     /* Name of file */
          uchFileData[4]   = "DATA";            /* Data to write to file */
   APIRET rc             = NO_ERROR;            /* Return code */

   /* Open the file dosman.dat.  Use an existing file or create a new */
   /* one if it doesn't exist.                                      */
   rc = DosProtectOpen(uchFileName, &hfFileHandle, &ulAction, 4L,
              FILE_ARCHIVED | FILE_NORMAL,
              OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
              OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE  |
              OPEN_ACCESS_READWRITE, 0L, &FileHandleLock);
   if (rc != NO_ERROR) {
      printf("DosOpen error: return code = %u\n", rc);
      return 1;
   }

   rc = DosProtectWrite (hfFileHandle, (PVOID) uchFileData,
                  sizeof (uchFileData), &ulWrote, FileHandleLock);
   if (rc != NO_ERROR) {
      printf("DosWrite error: return code = %u\n", rc);
      return 1;
   }

   rc = DosResetBuffer (hfFileHandle);
   if (rc != NO_ERROR) {
      printf("DosResetBuffer error: return code = %u\n", rc);
      return 1;
   } /* endif */

   rc = DosProtectSetFileSize (hfFileHandle, 8L, FileHandleLock);
   if (rc != NO_ERROR) {
      printf("DosSetFileSize error: return code = %u\n", rc);
      return 1;
   }

   return NO_ERROR;
}

Related Functions