1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright 2023 Red Hat 4 */ 5 6 #ifndef UDS_IO_FACTORY_H 7 #define UDS_IO_FACTORY_H 8 9 #include <linux/dm-bufio.h> 10 11 /* 12 * The I/O factory manages all low-level I/O operations to the underlying storage device. Its main 13 * clients are the index layout and the volume. The buffered reader and buffered writer interfaces 14 * are helpers for accessing data in a contiguous range of storage blocks. 15 */ 16 17 struct buffered_reader; 18 struct buffered_writer; 19 20 struct io_factory; 21 22 enum { 23 UDS_BLOCK_SIZE = 4096, 24 SECTORS_PER_BLOCK = UDS_BLOCK_SIZE >> SECTOR_SHIFT, 25 }; 26 27 int __must_check uds_make_io_factory(struct block_device *bdev, 28 struct io_factory **factory_ptr); 29 30 int __must_check uds_replace_storage(struct io_factory *factory, 31 struct block_device *bdev); 32 33 void uds_put_io_factory(struct io_factory *factory); 34 35 size_t __must_check uds_get_writable_size(struct io_factory *factory); 36 37 int __must_check uds_make_bufio(struct io_factory *factory, off_t block_offset, 38 size_t block_size, unsigned int reserved_buffers, 39 struct dm_bufio_client **client_ptr); 40 41 int __must_check uds_make_buffered_reader(struct io_factory *factory, off_t offset, 42 u64 block_count, 43 struct buffered_reader **reader_ptr); 44 45 void uds_free_buffered_reader(struct buffered_reader *reader); 46 47 int __must_check uds_read_from_buffered_reader(struct buffered_reader *reader, u8 *data, 48 size_t length); 49 50 int __must_check uds_verify_buffered_data(struct buffered_reader *reader, const u8 *value, 51 size_t length); 52 53 int __must_check uds_make_buffered_writer(struct io_factory *factory, off_t offset, 54 u64 block_count, 55 struct buffered_writer **writer_ptr); 56 57 void uds_free_buffered_writer(struct buffered_writer *buffer); 58 59 int __must_check uds_write_to_buffered_writer(struct buffered_writer *writer, 60 const u8 *data, size_t length); 61 62 int __must_check uds_flush_buffered_writer(struct buffered_writer *writer); 63 64 #endif /* UDS_IO_FACTORY_H */ 65