2019-07-01 22:42:23 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DEVICE_UTILS_H__
|
|
|
|
#define __DEVICE_UTILS_H__
|
|
|
|
|
2022-09-14 15:06:52 +00:00
|
|
|
#include "kerncompat.h"
|
|
|
|
#include <sys/stat.h>
|
2021-10-05 06:23:02 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
2023-08-22 19:07:13 +00:00
|
|
|
#include "kernel-shared/uapi/btrfs.h"
|
2019-07-01 22:42:23 +00:00
|
|
|
|
2021-04-29 16:56:00 +00:00
|
|
|
/*
|
|
|
|
* Options for btrfs_prepare_device
|
|
|
|
*/
|
2019-07-01 22:42:23 +00:00
|
|
|
#define PREP_DEVICE_ZERO_END (1U << 0)
|
|
|
|
#define PREP_DEVICE_DISCARD (1U << 1)
|
|
|
|
#define PREP_DEVICE_VERBOSE (1U << 2)
|
2021-04-26 06:27:33 +00:00
|
|
|
#define PREP_DEVICE_ZONED (1U << 3)
|
2019-07-01 22:42:23 +00:00
|
|
|
|
2021-05-06 22:34:26 +00:00
|
|
|
/* Placeholder to denote no results for the zone_unusable sysfs value */
|
|
|
|
#define DEVICE_ZONE_UNUSABLE_UNKNOWN ((u64)-1)
|
|
|
|
|
2021-04-29 16:56:00 +00:00
|
|
|
/*
|
|
|
|
* Generic block device helpers
|
|
|
|
*/
|
2021-04-29 16:34:05 +00:00
|
|
|
int device_discard_blocks(int fd, u64 start, u64 len);
|
2021-10-05 06:23:02 +00:00
|
|
|
int device_zero_blocks(int fd, off_t start, size_t len, const bool direct);
|
2021-04-29 16:36:44 +00:00
|
|
|
u64 device_get_partition_size(const char *dev);
|
2021-04-29 18:13:49 +00:00
|
|
|
u64 device_get_partition_size_fd(int fd);
|
2022-09-30 13:36:16 +00:00
|
|
|
u64 device_get_partition_size_fd_stat(int fd, const struct stat *st);
|
2021-04-29 16:56:00 +00:00
|
|
|
int device_get_queue_param(const char *file, const char *param, char *buf, size_t len);
|
2021-05-06 22:34:26 +00:00
|
|
|
u64 device_get_zone_unusable(int fd, u64 flags);
|
2021-06-24 20:38:59 +00:00
|
|
|
u64 device_get_zone_size(int fd, const char *name);
|
2022-09-14 14:42:53 +00:00
|
|
|
int device_get_rotational(const char *file);
|
2023-08-22 19:07:13 +00:00
|
|
|
int device_get_info(int fd, u64 devid, struct btrfs_ioctl_dev_info_args *di_args);
|
2021-04-29 16:56:00 +00:00
|
|
|
/*
|
|
|
|
* Updates to devices with btrfs-specific changs
|
|
|
|
*/
|
2019-07-01 22:42:23 +00:00
|
|
|
int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret,
|
|
|
|
u64 max_block_count, unsigned opflags);
|
2023-05-09 11:48:38 +00:00
|
|
|
ssize_t btrfs_direct_pread(int fd, void *buf, size_t count, off_t offset);
|
|
|
|
ssize_t btrfs_direct_pwrite(int fd, const void *buf, size_t count, off_t offset);
|
2021-10-05 06:23:02 +00:00
|
|
|
|
|
|
|
#ifdef BTRFS_ZONED
|
2023-05-09 11:48:39 +00:00
|
|
|
static inline ssize_t btrfs_pwrite(int fd, const void *buf, size_t count,
|
2021-10-05 06:23:02 +00:00
|
|
|
off_t offset, bool direct)
|
|
|
|
{
|
|
|
|
if (!direct)
|
|
|
|
return pwrite(fd, buf, count, offset);
|
|
|
|
|
2023-05-09 11:48:38 +00:00
|
|
|
return btrfs_direct_pwrite(fd, buf, count, offset);
|
2021-10-05 06:23:02 +00:00
|
|
|
}
|
2023-05-09 11:48:39 +00:00
|
|
|
static inline ssize_t btrfs_pread(int fd, void *buf, size_t count,
|
|
|
|
off_t offset, bool direct)
|
2021-10-05 06:23:03 +00:00
|
|
|
{
|
|
|
|
if (!direct)
|
|
|
|
return pread(fd, buf, count, offset);
|
|
|
|
|
2023-05-09 11:48:38 +00:00
|
|
|
return btrfs_direct_pread(fd, buf, count, offset);
|
2021-10-05 06:23:03 +00:00
|
|
|
}
|
2021-10-05 06:23:02 +00:00
|
|
|
#else
|
|
|
|
#define btrfs_pwrite(fd, buf, count, offset, direct) \
|
|
|
|
({ (void)(direct); pwrite(fd, buf, count, offset); })
|
2021-10-05 06:23:03 +00:00
|
|
|
#define btrfs_pread(fd, buf, count, offset, direct) \
|
|
|
|
({ (void)(direct); pread(fd, buf, count, offset); })
|
2021-10-05 06:23:02 +00:00
|
|
|
#endif
|
2019-07-01 22:42:23 +00:00
|
|
|
|
|
|
|
#endif
|