2 * Copyright (C) 2018 Facebook
4 * This file is part of libbtrfsutil.
6 * libbtrfsutil is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * libbtrfsutil is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with libbtrfsutil. If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/ioctl.h>
25 #include "btrfsutil_internal.h"
27 PUBLIC
enum btrfs_util_error
btrfs_util_sync(const char *path
)
29 enum btrfs_util_error err
;
32 fd
= open(path
, O_RDONLY
);
34 return BTRFS_UTIL_ERROR_OPEN_FAILED
;
36 err
= btrfs_util_sync_fd(fd
);
37 SAVE_ERRNO_AND_CLOSE(fd
);
41 PUBLIC
enum btrfs_util_error
btrfs_util_sync_fd(int fd
)
45 ret
= ioctl(fd
, BTRFS_IOC_SYNC
, NULL
);
47 return BTRFS_UTIL_ERROR_SYNC_FAILED
;
52 PUBLIC
enum btrfs_util_error
btrfs_util_start_sync(const char *path
,
55 enum btrfs_util_error err
;
58 fd
= open(path
, O_RDONLY
);
60 return BTRFS_UTIL_ERROR_OPEN_FAILED
;
62 err
= btrfs_util_start_sync_fd(fd
, transid
);
63 SAVE_ERRNO_AND_CLOSE(fd
);
67 PUBLIC
enum btrfs_util_error
btrfs_util_start_sync_fd(int fd
, uint64_t *transid
)
71 ret
= ioctl(fd
, BTRFS_IOC_START_SYNC
, transid
);
73 return BTRFS_UTIL_ERROR_START_SYNC_FAILED
;
78 PUBLIC
enum btrfs_util_error
btrfs_util_wait_sync(const char *path
,
81 enum btrfs_util_error err
;
84 fd
= open(path
, O_RDONLY
);
86 return BTRFS_UTIL_ERROR_OPEN_FAILED
;
88 err
= btrfs_util_wait_sync_fd(fd
, transid
);
89 SAVE_ERRNO_AND_CLOSE(fd
);
93 PUBLIC
enum btrfs_util_error
btrfs_util_wait_sync_fd(int fd
, uint64_t transid
)
97 ret
= ioctl(fd
, BTRFS_IOC_WAIT_SYNC
, &transid
);
99 return BTRFS_UTIL_ERROR_WAIT_SYNC_FAILED
;
101 return BTRFS_UTIL_OK
;