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

/*
* Copyright (c) 2013, 2014, 2015 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* device.h
* Block device.
*/
2013-05-23 08:39:54 -04:00
#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;
size_t block_count;
size_t block_limit;
2013-05-23 08:39:54 -04:00
public:
2015-01-30 18:19:54 -05:00
void SpawnSyncThread();
Block* AllocateBlock();
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