qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: phind.uet@gmail.com
To: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
	Stefan Weil <sw@weilnetz.de>
Cc: Nguyen Dinh Phi <phind.uet@gmail.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Subject: [PATCH 2/2] util: Move qemu_ftruncate64 from block/file-win32.c to oslib-win32.c
Date: Tue, 16 Dec 2025 00:45:12 +0800	[thread overview]
Message-ID: <20251215164512.322786-3-phind.uet@gmail.com> (raw)
In-Reply-To: <20251215164512.322786-1-phind.uet@gmail.com>

From: Nguyen Dinh Phi <phind.uet@gmail.com>

qemu_ftruncate64() is utility function that may be used outside of the block 
layer. Move it to util/oslib-win32.c where other Windows-specific utility 
functions reside.

Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
---
 block/file-win32.c | 32 --------------------------------
 util/oslib-win32.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/block/file-win32.c b/block/file-win32.c
index af9aea631c..8a44853389 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -170,38 +170,6 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile,
     return thread_pool_submit_aio(aio_worker, acb, cb, opaque);
 }
 
-int qemu_ftruncate64(int fd, int64_t length)
-{
-    LARGE_INTEGER li;
-    DWORD dw;
-    LONG high;
-    HANDLE h;
-    BOOL res;
-
-    if ((GetVersion() & 0x80000000UL) && (length >> 32) != 0)
-        return -1;
-
-    h = (HANDLE)_get_osfhandle(fd);
-
-    /* get current position, ftruncate do not change position */
-    li.HighPart = 0;
-    li.LowPart = SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT);
-    if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
-        return -1;
-    }
-
-    high = length >> 32;
-    dw = SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN);
-    if (dw == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
-        return -1;
-    }
-    res = SetEndOfFile(h);
-
-    /* back to old position */
-    SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN);
-    return res ? 0 : -1;
-}
-
 static int set_sparse(int fd)
 {
     DWORD returned;
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 839b8a4170..766c602172 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -899,3 +899,37 @@ int qemu_shm_alloc(size_t size, Error **errp)
     error_setg(errp, "Shared memory is not supported.");
     return -1;
 }
+
+int qemu_ftruncate64(int fd, int64_t length)
+{
+    LARGE_INTEGER li;
+    DWORD dw;
+    LONG high;
+    HANDLE h;
+    BOOL res;
+
+    if ((GetVersion()&0x80000000UL) && (length >> 32) != 0) {
+        return -1;
+    }
+
+    h = (HANDLE)_get_osfhandle(fd);
+
+    /* get current position, ftruncate do not change position */
+    li.HighPart = 0;
+    li.LowPart = SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT);
+    if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
+        return -1;
+    }
+
+    high = length >> 32;
+    dw = SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN);
+    if (dw == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
+        return -1;
+    }
+    res = SetEndOfFile(h);
+
+    /* back to old position */
+    SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN);
+    return res ? 0 : -1;
+}
+
-- 
2.43.0



  parent reply	other threads:[~2025-12-15 16:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 16:45 [PATCH 0/2] Fix Windows build issues with newer MinGW phind.uet
2025-12-15 16:45 ` [PATCH 1/2] qga/vss-win32: Fix ConvertStringToBSTR redefinition " phind.uet
2025-12-16  6:26   ` Marc-André Lureau
2025-12-16  9:53     ` Kostiantyn Kostiuk
2025-12-17 18:13       ` Pierrick Bouvier
2025-12-16 23:00   ` Pierrick Bouvier
2025-12-15 16:45 ` phind.uet [this message]
2025-12-15 17:33   ` [PATCH 2/2] util: Move qemu_ftruncate64 from block/file-win32.c to oslib-win32.c Philippe Mathieu-Daudé
2025-12-16 23:00   ` Pierrick Bouvier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251215164512.322786-3-phind.uet@gmail.com \
    --to=phind.uet@gmail.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).