1/* 2 * Copyright (c) 2011 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#include <errno.h> 25#include <unistd.h> 26#include <System/sys/fsctl.h> 27 28/* 29 * Sync a mounted filesystem, without syncing others. 30 * There are currently two flags that can be used: 31 * 32 * SYNC_VOLUME_FULLSYNC causes it to try to push the 33 * data to the platter (otherwise, it just pushes it 34 * to the disk drive, where it may remain in cache 35 * for a while). 36 * 37 * SYNC_VOLUME_WAIT causes it to wait until the writes 38 * have completed. Otherwise, it'll return as soon 39 * as the requests have been made. 40 * 41 * The functions are a simple wrapper for fsctl, and 42 * return what it does. 43 */ 44 45int 46sync_volume_np(const char *path, int flags) { 47 int full_sync = 0; 48 int terrno; 49 int rv; 50 51 if (flags & SYNC_VOLUME_FULLSYNC) 52 full_sync |= FSCTL_SYNC_FULLSYNC; 53 54 if (flags & SYNC_VOLUME_WAIT) 55 full_sync |= FSCTL_SYNC_WAIT; 56 57 terrno = errno; 58 rv = (fsctl(path, FSCTL_SYNC_VOLUME, &full_sync, 0) == -1) ? errno : 0; 59 errno = terrno; 60 return rv; 61} 62 63int 64fsync_volume_np(int fd, int flags) { 65 int full_sync = 0; 66 int terrno; 67 int rv; 68 69 if (flags & SYNC_VOLUME_FULLSYNC) 70 full_sync |= FSCTL_SYNC_FULLSYNC; 71 72 if (flags & SYNC_VOLUME_WAIT) 73 full_sync |= FSCTL_SYNC_WAIT; 74 75 terrno = errno; 76 rv = (ffsctl(fd, FSCTL_SYNC_VOLUME, &full_sync, 0) == -1) ? errno : 0; 77 errno = terrno; 78 return rv; 79} 80 81