sortix-mirror/ext/device.h

65 lines
1.7 KiB
C
Raw Normal View History

2013-05-23 12:39:54 +00:00
/*******************************************************************************
2015-07-02 20:10:26 +00:00
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014, 2015.
2013-05-23 12:39:54 +00:00
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/>.
device.h
Block device.
*******************************************************************************/
#ifndef DEVICE_H
#define DEVICE_H
class Block;
2015-07-02 20:10:26 +00:00
static const size_t DEVICE_HASH_LENGTH = 1 << 16;
2013-05-23 12:39:54 +00:00
class Device
{
public:
2015-02-16 14:44:21 +00:00
Device(int fd, const char* path, uint32_t block_size, bool write);
2013-05-23 12:39:54 +00:00
~Device();
public:
2015-01-30 23:19:54 +00:00
pthread_t sync_thread;
pthread_cond_t sync_thread_cond;
pthread_cond_t sync_thread_idle_cond;
pthread_mutex_t sync_thread_lock;
2013-05-23 12:39:54 +00:00
Block* mru_block;
Block* lru_block;
2014-10-01 20:27:19 +00:00
Block* dirty_block;
2013-05-23 12:39:54 +00:00
Block* hash_blocks[DEVICE_HASH_LENGTH];
off_t device_size;
2015-02-16 14:44:21 +00:00
const char* path;
2013-05-23 12:39:54 +00:00
uint32_t block_size;
int fd;
bool write;
2015-01-30 23:19:54 +00:00
bool has_sync_thread;
bool sync_thread_should_exit;
bool sync_in_transit;
2013-05-23 12:39:54 +00:00
public:
2015-01-30 23:19:54 +00:00
void SpawnSyncThread();
2013-05-23 12:39:54 +00:00
Block* GetBlock(uint32_t block_id);
Block* GetBlockZeroed(uint32_t block_id);
Block* GetCachedBlock(uint32_t block_id);
void Sync();
2015-01-30 23:19:54 +00:00
void SyncThread();
2013-05-23 12:39:54 +00:00
};
#endif