snapraid/cmdline/handle.h

77 lines
2.4 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-or-later
2026-04-02 16:25:49 +02:00
// Copyright (C) 2011 Andrea Mazzoleni
#ifndef __HANDLE_H
#define __HANDLE_H
#include "state.h"
#include "support.h"
2025-03-27 12:57:41 -07:00
#include "bw.h"
/****************************************************************************/
/* handle */
struct snapraid_handle {
char path[PATH_MAX]; /**< Path of the file. */
struct snapraid_disk* disk; /**< Disk of the file. */
struct snapraid_file* file; /**< File opened. When the file is closed, it's set to 0. */
int f; /**< Handle of the file. */
struct stat st; /**< Stat info of the opened file. */
2016-05-15 14:18:44 +02:00
struct advise_struct advise; /**< Advise information. */
data_off_t valid_size; /**< Size of the valid data. */
int created; /**< If the file was created, otherwise it was already existing. */
2025-03-27 12:57:41 -07:00
struct snapraid_bw* bw; /**< Context for bandwidth limiting. */
};
2011-03-18 22:38:11 +01:00
/**
2015-10-07 22:07:20 +02:00
* Create a file.
* The file is created if missing, and opened with write access.
* If the file is created, the handle->created is set.
* The initial size of the file is stored in the file->st struct.
* If the file cannot be opened for write access, it's opened with read-only access.
* The read-only access works only if the file has already the correct size and doesn't need to be modified.
*/
int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, int mode);
2014-12-28 19:11:58 +01:00
/**
* Truncate a file if required.
*/
int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file);
/**
2015-10-07 22:07:20 +02:00
* Open a file.
* The file is opened for reading.
*/
2026-06-03 20:49:36 +02:00
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, log_ptr* out_missing);
2011-03-12 23:36:37 +01:00
/**
2015-10-07 22:07:20 +02:00
* Close a file.
2011-03-12 23:36:37 +01:00
*/
2011-03-18 22:38:11 +01:00
int handle_close(struct snapraid_handle* handle);
2011-03-12 23:36:37 +01:00
/**
* Read a block from a file.
* If the read block is shorter, it's padded with 0.
2011-03-12 23:36:37 +01:00
*/
2026-06-04 00:34:51 +02:00
ssize_t handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out_missing);
2011-03-12 23:36:37 +01:00
/**
2015-10-07 22:07:20 +02:00
* Write a block to a file.
2011-03-12 23:36:37 +01:00
*/
int handle_write(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size);
/**
2015-10-07 22:07:20 +02:00
* Change the modification time of the file to the saved value.
*/
int handle_utime(struct snapraid_handle* handle);
/**
2015-10-07 22:07:20 +02:00
* Map the unsorted list of disk to an ordered vector.
* \param diskmax The size of the vector.
* \return The allocated vector of pointers.
*/
struct snapraid_handle* handle_mapping(struct snapraid_state* state, unsigned* diskmax);
#endif