1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 static int sync_win32 (void);
38 if (sync_disks () == -1) {
39 reply_with_perror ("sync");
46 /* Older versions of libguestfs used to issue separate 'umount_all'
47 * and 'sync' commands just before closing the handle. Since
48 * libguestfs 1.9.7 the library issues this 'internal_autosync'
49 * internal operation instead, allowing more control in the daemon.
52 do_internal_autosync (void)
63 /* This is a replacement for sync(2) which is called from
64 * this file and from other places in the daemon. It works
70 #if defined(HAVE_SYNC)
76 #error "no known sync() API"
86 n1 = GetLogicalDriveStrings (0, NULL);
90 TCHAR buffer[n1+2]; /* sic */
91 n2 = GetLogicalDriveStrings (n1, buffer);
97 /* The MSDN example code itself assumes that there is always one
98 * drive in the system. However we will be better than that and not
99 * make the assumption ...
106 fprintf (stderr, "sync_win32: examining drive %s\n", p);
108 /* Ignore removable drives. */
109 drive_type = GetDriveType (p);
110 if (drive_type == DRIVE_FIXED) {
111 /* To open the volume you have to specify the volume name, not
112 * the mount point. MSDN documents use of the constant 50
116 if (!GetVolumeNameForVolumeMountPoint (p, volname, 50))
119 drive = CreateFile (volname, GENERIC_READ|GENERIC_WRITE,
120 FILE_SHARE_READ|FILE_SHARE_WRITE,
121 NULL, OPEN_EXISTING, 0, 0);
122 if (drive == INVALID_HANDLE_VALUE)
125 fprintf (stderr, "sync_win32: flushing %s\n", volname);
128 /* This always fails in Wine:
129 * http://bugs.winehq.org/show_bug.cgi?id=14915
131 r = FlushFileBuffers (drive);
137 /* Skip to next \0 character. */