1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or https://opensource.org/licenses/CDDL-1.0. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 #ifndef _SYS_ZFS_FILE_H 24 #define _SYS_ZFS_FILE_H 25 26 #include <sys/zfs_context.h> 27 28 /* 29 * loff_t is a Linux kernel/VFS type. glibc and musl expose it to user 30 * space via <fcntl.h>, but FreeBSD libc does not. For FreeBSD user 31 * space we map loff_t to off_t so the shared interfaces that use the 32 * loff_t name still compile. The FreeBSD kernel gets loff_t from its 33 * own linux-compat headers. 34 */ 35 #if !defined(_KERNEL) && defined(__FreeBSD__) 36 typedef off_t loff_t; 37 #endif 38 39 #ifndef _KERNEL 40 typedef struct zfs_file { 41 int f_fd; 42 int f_dump_fd; 43 } zfs_file_t; 44 #elif defined(__linux__) || defined(__FreeBSD__) 45 typedef struct file zfs_file_t; 46 #else 47 #error "unknown OS" 48 #endif 49 50 typedef struct zfs_file_attr { 51 uint64_t zfa_size; /* file size */ 52 mode_t zfa_mode; /* file type */ 53 } zfs_file_attr_t; 54 55 int zfs_file_open(const char *path, int flags, int mode, zfs_file_t **fp); 56 void zfs_file_close(zfs_file_t *fp); 57 58 int zfs_file_write(zfs_file_t *fp, const void *buf, size_t len, ssize_t *resid); 59 int zfs_file_pwrite(zfs_file_t *fp, const void *buf, size_t len, loff_t off, 60 uint8_t ashift, ssize_t *resid); 61 int zfs_file_read(zfs_file_t *fp, void *buf, size_t len, ssize_t *resid); 62 int zfs_file_pread(zfs_file_t *fp, void *buf, size_t len, loff_t off, 63 ssize_t *resid); 64 65 int zfs_file_seek(zfs_file_t *fp, loff_t *offp, int whence); 66 int zfs_file_getattr(zfs_file_t *fp, zfs_file_attr_t *zfattr); 67 int zfs_file_fsync(zfs_file_t *fp, int flags); 68 int zfs_file_deallocate(zfs_file_t *fp, loff_t offset, loff_t len); 69 loff_t zfs_file_off(zfs_file_t *fp); 70 int zfs_file_unlink(const char *); 71 72 zfs_file_t *zfs_file_get(int fd); 73 void zfs_file_put(zfs_file_t *fp); 74 void *zfs_file_private(zfs_file_t *fp); 75 76 #endif /* _SYS_ZFS_FILE_H */ 77