X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E840B386C5B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1701167427; bh=kTGMag5shwGTZpVln5ZVxlg3SRVhk0v82ukC9piB24Y=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=SqIZd2skQHV4SnKQ6SUce7cmTJ0VNOaXFdsVCF3pZ6/hAmOQQXz7Bul9RGpepUfqH kjahINegTUA/b+R8T2Y8vTJkWANTihBotKK8cf/70J4343OeKtlErTPgtA8MBPZRYS Pzxavr1hqQk4sPhtvNyzsZI+0TA7Jww1ytyxpayA= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9E393858012 Date: Tue, 28 Nov 2023 11:29:51 +0100 To: cygwin AT cygwin DOT com Subject: Re: Cygwin api to punch a hole into a file? Message-ID: Mail-Followup-To: cygwin AT cygwin DOT com References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Corinna Vinschen via Cygwin Reply-To: cygwin AT cygwin DOT com Cc: Corinna Vinschen Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On Nov 24 12:01, Corinna Vinschen via Cygwin wrote: > On Nov 23 23:36, Cedric Blancher via Cygwin wrote: > > Linux has fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, ...) > > to punch a hole into a file, i.e. deallocate the blocks given and make > > the file a "sparse file". > > We don't support the Linux-specific fallocate(2) call, only ftruncate(2) > and posix_fallocate(3). Patches, as usual, thoughtfully considered. The next test release cygwin-3.5.0-0.485.g65831f88d6c4 introduces the Linux-specific fallocate(2) call. Naturally we can't support all flags, but the following flag combinations are allowed: - 0 same as posix_fallocate(3) - FALLOC_FL_KEEP_SIZE - FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE - FALLOC_FL_ZERO_RANGE - FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE A few comments: - With 0 and FALLOC_FL_KEEP_SIZE, sparse blocks in the given range are re-allocated as per the POSIX requirements. For that, it uses the same code as FALLOC_FL_ZERO_RANGE, but only for the holes within the range. - With FALLOC_FL_KEEP_SIZE, over-allocation is done by setting the allocation size of a file while keeping EOF the same. However, in contrast to your typical Linux filesystem, over- allocation on Windows filesystems is only temporary. The over-allocated blocks are returned to free blocks as soon as the last HANDLE to the file is closed. - With FALLOC_FL_KEEP_SIZE, no over-allocation is performed on sparse files. The reason is that over-allocation on sparse files has no effect on Windows. - FALLOC_FL_ZERO_RANGE is implemented as writing zeros to the given range. For parts of the range which are already allocated data blocks, as much zeros are written as necessary. For holes in sparse files, only a single zero byte is written to the hole per 64K chunk, which is the allocation granularity of sparse files. - FALLOC_FL_ZERO_RANGE is NOT atomic. Please give it a try. Corinna -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple