Skip to content

Latest commit

 

History

History
186 lines (136 loc) · 5.1 KB

nf-fileapi-setendoffile.md

File metadata and controls

186 lines (136 loc) · 5.1 KB
UIDtitledescriptionhelpviewer_keywordsold-locationtech.rootms.assetidms.datems.keywordsreq.headerreq.include-headerreq.target-typereq.target-min-winverclntreq.target-min-winversvrreq.kmdf-verreq.umdf-verreq.ddi-compliancereq.unicode-ansireq.idlreq.max-supportreq.namespacereq.assemblyreq.type-libraryreq.libreq.dllreq.irqltargetosreq.typenamesreq.redistms.customf1_keywordsdev_langstopic_typeapi_typeapi_locationapi_name
NF:fileapi.SetEndOfFile
SetEndOfFile function (fileapi.h)
Sets the physical file size for the specified file to the current position of the file pointer.
SetEndOfFile
SetEndOfFile function [Files]
_win32_setendoffile
base.setendoffile
fileapi/SetEndOfFile
fs.setendoffile
winbase/SetEndOfFile
fs\setendoffile.htm
fs
2a579609-144a-4b77-8605-87aecf1f0957
12/05/2018
SetEndOfFile, SetEndOfFile function [Files], _win32_setendoffile, base.setendoffile, fileapi/SetEndOfFile, fs.setendoffile, winbase/SetEndOfFile
fileapi.h
Windows.h
Windows
Windows XP [desktop apps \| UWP apps]
Windows Server 2003 [desktop apps \| UWP apps]
Kernel32.lib
Kernel32.dll
Windows
19H1
SetEndOfFile
fileapi/SetEndOfFile
c++
APIRef
kbSyntax
DllExport
Kernel32.dll
API-MS-Win-Core-File-l1-1-0.dll
KernelBase.dll
API-MS-Win-Core-File-l1-2-0.dll
API-MS-Win-Core-File-l1-2-1.dll
API-MS-Win-Core-File-l1-2-2.dll
API-MS-Win-DownLevel-Kernel32-l1-1-0.dll
MinKernelBase.dll
SetEndOfFile

SetEndOfFile function

-description

Sets the physical file size for the specified file to the current position of the file pointer.

The physical file size is also referred to as the end of the file. The SetEndOfFile function can be used to truncate or extend a file. To set the logical end of a file, use the SetFileValidData function.

-parameters

-param hFile [in]

A handle to the file to be extended or truncated.

The file handle must be created with the GENERIC_WRITE access right. For more information, see File Security and Access Rights.

-returns

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero (0). To get extended error information, call GetLastError.

-remarks

The SetEndOfFile function can be used to truncate or extend a file. If the file is extended, the contents of the file between the old end of the file and the new end of the file are not defined.

Each file stream has the following:

  • File size: the size of the data in a file, to the byte.
  • Allocation size: the size of the space that is allocated for a file on a disk, which is always an even multiple of the cluster size.
  • Valid data length: the length of the data in a file that is actually written, to the byte. This value is always less than or equal to the file size.
The SetEndOfFile function sets the file size. Use SetFileValidData to set the valid data length.

If
CreateFileMapping is called to create a file mapping object for hFile, UnmapViewOfFile must be called first to unmap all views and call CloseHandle to close the file mapping object before you can call SetEndOfFile.

Transacted Operations

If there is a transaction bound to the handle, then the change in the end-of-file position is transacted.

In Windows 8 and Windows Server 2012, this function is supported by the following technologies.

TechnologySupported
Server Message Block (SMB) 3.0 protocol Yes
SMB 3.0 Transparent Failover (TFO) Yes
SMB 3.0 with Scale-out File Shares (SO) Yes
Cluster Shared Volume File System (CsvFS) Yes
Resilient File System (ReFS) Yes

-see-also

CloseHandle

CreateFile

CreateFileMapping

File Management Functions

SetFileInformationByHandle

SetFileValidData

UnmapViewOfFile

close