1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/ext/device.h

65 lines
1.7 KiB
C
Raw Normal View History

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