github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/cmd/libsnap-confine-private/mount-opt.h (about) 1 /* 2 * Copyright (C) 2016 Canonical Ltd 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 3 as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 * 16 */ 17 18 #ifndef SNAP_CONFINE_MOUNT_OPT_H 19 #define SNAP_CONFINE_MOUNT_OPT_H 20 21 #include <stdbool.h> 22 #include <stddef.h> 23 24 /** 25 * Convert flags for mount(2) system call to a string representation. 26 **/ 27 const char *sc_mount_opt2str(char *buf, size_t buf_size, unsigned long flags); 28 29 /** 30 * Compute an equivalent mount(8) command from mount(2) arguments. 31 * 32 * This function serves as a human-readable representation of the mount system 33 * call. The return value is a string that looks like a shell mount command. 34 * 35 * Note that the returned command is may not be a valid mount command. No 36 * sanity checking is performed on the mount flags, source or destination 37 * arguments. 38 * 39 * The returned value is always buf, it is provided as a convenience. 40 **/ 41 const char *sc_mount_cmd(char *buf, size_t buf_size, const char *source, const char 42 *target, const char *fs_type, unsigned long mountflags, 43 const void *data); 44 45 /** 46 * Compute an equivalent umount(8) command from umount2(2) arguments. 47 * 48 * This function serves as a human-readable representation of the unmount 49 * system call. The return value is a string that looks like a shell unmount 50 * command. 51 * 52 * Note that some flags are not surfaced at umount command line level. For 53 * those flags a fake option is synthesized. 54 * 55 * Note that the returned command is may not be a valid umount command. No 56 * sanity checking is performed on the mount flags, source or destination 57 * arguments. 58 * 59 * The returned value is always buf, it is provided as a convenience. 60 **/ 61 const char *sc_umount_cmd(char *buf, size_t buf_size, const char *target, 62 int flags); 63 64 /** 65 * A thin wrapper around mount(2) with logging and error checks. 66 **/ 67 void sc_do_mount(const char *source, const char *target, 68 const char *fs_type, unsigned long mountflags, 69 const void *data); 70 71 /** 72 * A thin wrapper around mount(2) with logging and error checks. 73 * 74 * This variant is allowed to silently fail when mount fails with ENOENT. 75 * That is, it can be used to perform mount operations and if either the source 76 * or the destination is not present, carry on as if nothing had happened. 77 * 78 * The return value indicates if the operation was successful or not. 79 **/ 80 bool sc_do_optional_mount(const char *source, const char *target, 81 const char *fs_type, unsigned long mountflags, 82 const void *data); 83 84 /** 85 * A thin wrapper around umount(2) with logging and error checks. 86 **/ 87 void sc_do_umount(const char *target, int flags); 88 89 #endif // SNAP_CONFINE_MOUNT_OPT_H