-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesystem.h
92 lines (75 loc) · 2.31 KB
/
filesystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/************************************************************************
*
* Filesystem stress and verify
*
* Authors: Goswin von Brederlow <[email protected]>
* Bernd Schubert <[email protected]>
*
* Copyright (C) 2007 Q-leap Networks, Goswin von Brederlow
* 2010 DataDirect Networks, Bernd Schubert
*
* 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 2 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, write_main to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
************************************************************************/
#include <pthread.h>
#ifndef __FILESYSTEM_H__
#define __FILESYSTEM_H__
struct StatsStamp {
time_t time;
uint64_t write, read;
uint64_t num_files, num_read_files, num_written_files;
};
class Filesystem
{
private:
Dir *root_dir;
uint64_t fssize;
uint64_t fsfree;
uint64_t fsused;
uint64_t fs_use_goal;
size_t goal_percent;
bool was_full;
unsigned long last_read_index; // last index read in
StatsStamp stats_old;
StatsStamp stats_now;
StatsStamp stats_all;
void update_stats(bool size_only);
void free_space(size_t fsize);
volatile bool error_detected;
volatile bool terminated;
// protect file and directory addition/removal and stats
pthread_mutex_t mutex;
public:
Filesystem(string dir, size_t percent);
~Filesystem(void);
void write_main(void);
void read_main(void);
// Global options
vector<Dir*> all_dirs;
vector<Dir*> active_dirs;
vector<File*> files;
vector<File*>::iterator file_iter;
void lock(void);
void unlock(void);
int trylock(void);
void check_terminate_and_sleep(unsigned int seconds);
private:
File *get_file_locked(unsigned idx)
{
return this->files.at(idx);
}
};
#endif // __FILESYSTEM_H__