2011-03-04 20:59:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 Andrea Mazzoleni
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __HANDLE_H
|
|
|
|
|
#define __HANDLE_H
|
|
|
|
|
|
2011-09-23 21:48:50 +02:00
|
|
|
#include "state.h"
|
2015-02-02 23:39:46 +01:00
|
|
|
#include "support.h"
|
2011-09-23 21:48:50 +02:00
|
|
|
|
2011-03-04 20:59:21 +01:00
|
|
|
/****************************************************************************/
|
|
|
|
|
/* handle */
|
|
|
|
|
|
|
|
|
|
struct snapraid_handle {
|
|
|
|
|
char path[PATH_MAX]; /**< Path of the file. */
|
|
|
|
|
struct snapraid_disk* disk; /**< Disk of the file. */
|
2013-04-28 19:01:36 +02:00
|
|
|
struct snapraid_file* file; /**< File opened. When the file is closed, it's set to 0. */
|
2011-03-04 20:59:21 +01:00
|
|
|
int f; /**< Handle of the file. */
|
2011-03-19 22:00:08 +01:00
|
|
|
struct stat st; /**< Stat info of the opened file. */
|
2011-10-09 07:51:25 +02:00
|
|
|
data_off_t valid_size; /**< Size of the valid data. */
|
2013-06-01 22:49:38 +02:00
|
|
|
int created; /**< If the file was created, otherwise it was already existing. */
|
2011-03-04 20:59:21 +01:00
|
|
|
};
|
|
|
|
|
|
2011-03-18 22:38:11 +01:00
|
|
|
/**
|
2015-10-07 22:07:20 +02:00
|
|
|
* Create a file.
|
2011-06-11 09:38:19 +02:00
|
|
|
* The file is created if missing, and opened with write access.
|
2013-06-01 22:49:38 +02:00
|
|
|
* If the file is created, the handle->created is set.
|
2011-06-12 14:18:36 +02:00
|
|
|
* The initial size of the file is stored in the file->st struct.
|
2011-06-11 09:38:19 +02:00
|
|
|
* 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.
|
2011-03-04 20:59:21 +01:00
|
|
|
*/
|
2014-09-04 22:52:04 +02:00
|
|
|
int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, int mode);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
2014-12-28 19:11:58 +01:00
|
|
|
/**
|
|
|
|
|
* Truncate a file if required.
|
|
|
|
|
*/
|
|
|
|
|
int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file);
|
|
|
|
|
|
2011-03-04 20:59:21 +01:00
|
|
|
/**
|
2015-10-07 22:07:20 +02:00
|
|
|
* Open a file.
|
2011-03-04 20:59:21 +01:00
|
|
|
* The file is opened for reading.
|
|
|
|
|
*/
|
2015-04-19 21:21:49 +02:00
|
|
|
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out, fptr* out_missing);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
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-04 20:59:21 +01:00
|
|
|
|
2011-03-12 23:36:37 +01:00
|
|
|
/**
|
|
|
|
|
* Read a block from a file.
|
2011-04-23 21:38:26 +02:00
|
|
|
* If the read block is shorter, it's padded with 0.
|
2011-03-12 23:36:37 +01:00
|
|
|
*/
|
2015-10-03 10:43:02 +02:00
|
|
|
int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, fptr* out, fptr* out_missing);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
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
|
|
|
*/
|
2015-10-03 10:43:02 +02:00
|
|
|
int handle_write(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
2011-08-31 23:33:43 +02:00
|
|
|
/**
|
2015-10-07 22:07:20 +02:00
|
|
|
* Change the modification time of the file to the saved value.
|
2011-08-31 23:33:43 +02:00
|
|
|
*/
|
|
|
|
|
int handle_utime(struct snapraid_handle* handle);
|
|
|
|
|
|
2011-09-23 21:48:50 +02:00
|
|
|
/**
|
2015-10-07 22:07:20 +02:00
|
|
|
* Map the unsorted list of disk to an ordered vector.
|
2011-09-23 21:48:50 +02:00
|
|
|
* \param diskmax The size of the vector.
|
|
|
|
|
* \return The allocated vector of pointers.
|
|
|
|
|
*/
|
|
|
|
|
struct snapraid_handle* handle_map(struct snapraid_state* state, unsigned* diskmax);
|
|
|
|
|
|
2011-03-04 20:59:21 +01:00
|
|
|
#endif
|
|
|
|
|
|