Help and Support
Ask a question, report a problem, request a feature...
<<  Back To Forum

[Request] Please add really Fast Allocate support on Windows

by Guest on 2023/01/12 02:25:09 PM    
Now for Windows, "Fast Allocate" do the same as "Sparse Files" while doing "File Allocation". There are already many discussions here:

https://forum.tixati.com/support/524
https://forum.tixati.com/support/3056
https://forum.tixati.com/support/5764
https://forum.tixati.com/support/6406
https://forum.tixati.com/support/7116


In general, why we need "Fast Allocate"? Because other two do not do well:

1. "Full Pre-write" is slow and write twice.
2. "Sparse Files" makes too much file fragments, bad to HDD. (SDD is OK)


I have tested "Fast Allocate" on Windows, it is easy to implement, via use APIs SetFilePointerEx and SetEndOfFile, without Admin authority.
by Guest on 2023/01/12 03:15:33 PM    
Here is the test, use Python.


import ctypes
import os
import stat
import time

is_admin = ctypes.windll.shell32.IsUserAnAdmin()
print(f'This is{"" if is_admin else " not"} a elevated process.')

NULL = None
GENERIC_READ = 0x80000000
GENERIC_WRITE = 0x40000000
FILE_SHARE_READ = 0x00000001
FILE_SHARE_WRITE = 0x00000002
OPEN_ALWAYS = 4
FILE_ATTRIBUTE_NORMAL = 0x80
FILE_BEGIN = 0
INVALID_HANDLE_VALUE = -1

filepath = 'testfile'
filepath = os.path.abspath(filepath)
filesize = 100  # MB
offset = (1 << 20) * filesize
startn = time.time()

hFile = ctypes.windll.Kernel32.CreateFileW(
           filepath, GENERIC_READ | GENERIC_WRITE,
           FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
           FILE_ATTRIBUTE_NORMAL, NULL)
assert hFile != INVALID_HANDLE_VALUE
assert ctypes.windll.Kernel32.SetFilePointerEx(hFile, offset, NULL, FILE_BEGIN)
assert ctypes.windll.Kernel32.SetEndOfFile(hFile)
assert ctypes.windll.Kernel32.CloseHandle(hFile)

costn = (time.time() - startn) * 1e3
is_sparse = stat.FILE_ATTRIBUTE_SPARSE_FILE & os.stat(filepath).st_file_attributes

input(f'''
File "{filepath}" has been created.
   File Size: {filesize} MB
   Is Sparse: {bool(is_sparse)}
   Cost Time: {costn} ms

Press Enter to delete test file and exit...''')

os.remove(filepath)

by shag00 on 2023/11/11 03:17:34 AM    
It's not just Windows, Linux has the same problem.




This web site is powered by Super Simple Server