-
Notifications
You must be signed in to change notification settings - Fork 20
/
statistics.c
281 lines (251 loc) · 8.01 KB
/
statistics.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "sdfat.h"
#define SDFAT_VF_CLUS_MAX 7 /* 512 Byte ~ 32 KByte */
#define SDFAT_EF_CLUS_MAX 17 /* 512 Byte ~ 32 MByte */
enum {
SDFAT_MNT_FAT12,
SDFAT_MNT_FAT16,
SDFAT_MNT_FAT32,
SDFAT_MNT_EXFAT,
SDFAT_MNT_RO,
SDFAT_MNT_MAX
};
enum {
SDFAT_OP_EXFAT_MNT,
SDFAT_OP_MKDIR,
SDFAT_OP_CREATE,
SDFAT_OP_READ,
SDFAT_OP_WRITE,
SDFAT_OP_TRUNC,
SDFAT_OP_MAX
};
enum {
SDFAT_VOL_4G,
SDFAT_VOL_8G,
SDFAT_VOL_16G,
SDFAT_VOL_32G,
SDFAT_VOL_64G,
SDFAT_VOL_128G,
SDFAT_VOL_256G,
SDFAT_VOL_512G,
SDFAT_VOL_XTB,
SDFAT_VOL_MAX
};
static struct sdfat_statistics {
u32 clus_vfat[SDFAT_VF_CLUS_MAX];
u32 clus_exfat[SDFAT_EF_CLUS_MAX];
u32 mnt_cnt[SDFAT_MNT_MAX];
u32 nofat_op[SDFAT_OP_MAX];
u32 vol_size[SDFAT_VOL_MAX];
} statistics;
static struct kset *sdfat_statistics_kset;
static ssize_t vfat_cl_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
return snprintf(buff, PAGE_SIZE, "\"VCL_512B_I\":\"%u\","
"\"VCL_1K_I\":\"%u\",\"VCL_2K_I\":\"%u\","
"\"VCL_4K_I\":\"%u\",\"VCL_8K_I\":\"%u\","
"\"VCL_16K_I\":\"%u\",\"VCL_32K_I\":\"%u\"\n",
statistics.clus_vfat[0], statistics.clus_vfat[1],
statistics.clus_vfat[2], statistics.clus_vfat[3],
statistics.clus_vfat[4], statistics.clus_vfat[5],
statistics.clus_vfat[6]);
}
static ssize_t exfat_cl_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
return snprintf(buff, PAGE_SIZE, "\"ECL_512B_I\":\"%u\","
"\"ECL_1K_I\":\"%u\",\"ECL_2K_I\":\"%u\","
"\"ECL_4K_I\":\"%u\",\"ECL_8K_I\":\"%u\","
"\"ECL_16K_I\":\"%u\",\"ECL_32K_I\":\"%u\","
"\"ECL_64K_I\":\"%u\",\"ECL_128K_I\":\"%u\","
"\"ECL_256K_I\":\"%u\",\"ECL_512K_I\":\"%u\","
"\"ECL_1M_I\":\"%u\",\"ECL_2M_I\":\"%u\","
"\"ECL_4M_I\":\"%u\",\"ECL_8M_I\":\"%u\","
"\"ECL_16M_I\":\"%u\",\"ECL_32M_I\":\"%u\"\n",
statistics.clus_exfat[0], statistics.clus_exfat[1],
statistics.clus_exfat[2], statistics.clus_exfat[3],
statistics.clus_exfat[4], statistics.clus_exfat[5],
statistics.clus_exfat[6], statistics.clus_exfat[7],
statistics.clus_exfat[8], statistics.clus_exfat[9],
statistics.clus_exfat[10], statistics.clus_exfat[11],
statistics.clus_exfat[12], statistics.clus_exfat[13],
statistics.clus_exfat[14], statistics.clus_exfat[15],
statistics.clus_exfat[16]);
}
static ssize_t mount_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
return snprintf(buff, PAGE_SIZE, "\"FAT12_MNT_I\":\"%u\","
"\"FAT16_MNT_I\":\"%u\",\"FAT32_MNT_I\":\"%u\","
"\"EXFAT_MNT_I\":\"%u\",\"RO_MNT_I\":\"%u\"\n",
statistics.mnt_cnt[SDFAT_MNT_FAT12],
statistics.mnt_cnt[SDFAT_MNT_FAT16],
statistics.mnt_cnt[SDFAT_MNT_FAT32],
statistics.mnt_cnt[SDFAT_MNT_EXFAT],
statistics.mnt_cnt[SDFAT_MNT_RO]);
}
static ssize_t nofat_op_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
return snprintf(buff, PAGE_SIZE, "\"NOFAT_MOUNT_I\":\"%u\","
"\"NOFAT_MKDIR_I\":\"%u\",\"NOFAT_CREATE_I\":\"%u\","
"\"NOFAT_READ_I\":\"%u\",\"NOFAT_WRITE_I\":\"%u\","
"\"NOFAT_TRUNC_I\":\"%u\"\n",
statistics.nofat_op[SDFAT_OP_EXFAT_MNT],
statistics.nofat_op[SDFAT_OP_MKDIR],
statistics.nofat_op[SDFAT_OP_CREATE],
statistics.nofat_op[SDFAT_OP_READ],
statistics.nofat_op[SDFAT_OP_WRITE],
statistics.nofat_op[SDFAT_OP_TRUNC]);
}
static ssize_t vol_size_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
return snprintf(buff, PAGE_SIZE, "\"VOL_4G_I\":\"%u\","
"\"VOL_8G_I\":\"%u\",\"VOL_16G_I\":\"%u\","
"\"VOL_32G_I\":\"%u\",\"VOL_64G_I\":\"%u\","
"\"VOL_128G_I\":\"%u\",\"VOL_256G_I\":\"%u\","
"\"VOL_512G_I\":\"%u\",\"VOL_XTB_I\":\"%u\"\n",
statistics.vol_size[SDFAT_VOL_4G],
statistics.vol_size[SDFAT_VOL_8G],
statistics.vol_size[SDFAT_VOL_16G],
statistics.vol_size[SDFAT_VOL_32G],
statistics.vol_size[SDFAT_VOL_64G],
statistics.vol_size[SDFAT_VOL_128G],
statistics.vol_size[SDFAT_VOL_256G],
statistics.vol_size[SDFAT_VOL_512G],
statistics.vol_size[SDFAT_VOL_XTB]);
}
static struct kobj_attribute vfat_cl_attr = __ATTR_RO(vfat_cl);
static struct kobj_attribute exfat_cl_attr = __ATTR_RO(exfat_cl);
static struct kobj_attribute mount_attr = __ATTR_RO(mount);
static struct kobj_attribute nofat_op_attr = __ATTR_RO(nofat_op);
static struct kobj_attribute vol_size_attr = __ATTR_RO(vol_size);
static struct attribute *attributes_statistics[] = {
&vfat_cl_attr.attr,
&exfat_cl_attr.attr,
&mount_attr.attr,
&nofat_op_attr.attr,
&vol_size_attr.attr,
NULL,
};
static struct attribute_group attr_group_statistics = {
.attrs = attributes_statistics,
};
int sdfat_statistics_init(struct kset *sdfat_kset)
{
int err;
sdfat_statistics_kset = kset_create_and_add("statistics", NULL, &sdfat_kset->kobj);
if (!sdfat_statistics_kset) {
pr_err("[SDFAT] failed to create sdfat statistics kobj\n");
return -ENOMEM;
}
err = sysfs_create_group(&sdfat_statistics_kset->kobj, &attr_group_statistics);
if (err) {
pr_err("[SDFAT] failed to create sdfat statistics attributes\n");
kset_unregister(sdfat_statistics_kset);
sdfat_statistics_kset = NULL;
return err;
}
return 0;
}
void sdfat_statistics_uninit(void)
{
if (sdfat_statistics_kset) {
sysfs_remove_group(&sdfat_statistics_kset->kobj, &attr_group_statistics);
kset_unregister(sdfat_statistics_kset);
sdfat_statistics_kset = NULL;
}
memset(&statistics, 0, sizeof(struct sdfat_statistics));
}
void sdfat_statistics_set_mnt(FS_INFO_T *fsi)
{
if (fsi->vol_type == EXFAT) {
statistics.mnt_cnt[SDFAT_MNT_EXFAT]++;
statistics.nofat_op[SDFAT_OP_EXFAT_MNT] = 1;
if (fsi->sect_per_clus_bits < SDFAT_EF_CLUS_MAX)
statistics.clus_exfat[fsi->sect_per_clus_bits]++;
else
statistics.clus_exfat[SDFAT_EF_CLUS_MAX - 1]++;
return;
}
if (fsi->vol_type == FAT32)
statistics.mnt_cnt[SDFAT_MNT_FAT32]++;
else if (fsi->vol_type == FAT16)
statistics.mnt_cnt[SDFAT_MNT_FAT16]++;
else if (fsi->vol_type == FAT12)
statistics.mnt_cnt[SDFAT_MNT_FAT12]++;
if (fsi->sect_per_clus_bits < SDFAT_VF_CLUS_MAX)
statistics.clus_vfat[fsi->sect_per_clus_bits]++;
else
statistics.clus_vfat[SDFAT_VF_CLUS_MAX - 1]++;
}
void sdfat_statistics_set_mnt_ro(void)
{
statistics.mnt_cnt[SDFAT_MNT_RO]++;
}
void sdfat_statistics_set_mkdir(u8 flags)
{
if (flags != 0x03)
return;
statistics.nofat_op[SDFAT_OP_MKDIR] = 1;
}
void sdfat_statistics_set_create(u8 flags)
{
if (flags != 0x03)
return;
statistics.nofat_op[SDFAT_OP_CREATE] = 1;
}
/* flags : file or dir flgas, 0x03 means no fat-chain.
* clu_offset : file or dir logical cluster offset
* create : BMAP_ADD_CLUSTER or not
*
* File or dir have BMAP_ADD_CLUSTER is no fat-chain write
* when they have 0x03 flag and two or more clusters.
* And don`t have BMAP_ADD_CLUSTER is no fat-chain read
* when above same condition.
*/
void sdfat_statistics_set_rw(u8 flags, u32 clu_offset, s32 create)
{
if ((flags == 0x03) && (clu_offset > 1)) {
if (create)
statistics.nofat_op[SDFAT_OP_WRITE] = 1;
else
statistics.nofat_op[SDFAT_OP_READ] = 1;
}
}
/* flags : file or dir flgas, 0x03 means no fat-chain.
* clu : cluster chain
*
* Set no fat-chain trunc when file or dir have 0x03 flag
* and two or more clusters.
*/
void sdfat_statistics_set_trunc(u8 flags, CHAIN_T *clu)
{
if ((flags == 0x03) && (clu->size > 1))
statistics.nofat_op[SDFAT_OP_TRUNC] = 1;
}
void sdfat_statistics_set_vol_size(struct super_block *sb)
{
u64 vol_size;
FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);
vol_size = (u64)fsi->num_sectors << sb->s_blocksize_bits;
if (vol_size <= ((u64)1 << 32))
statistics.vol_size[SDFAT_VOL_4G]++;
else if (vol_size <= ((u64)1 << 33))
statistics.vol_size[SDFAT_VOL_8G]++;
else if (vol_size <= ((u64)1 << 34))
statistics.vol_size[SDFAT_VOL_16G]++;
else if (vol_size <= ((u64)1 << 35))
statistics.vol_size[SDFAT_VOL_32G]++;
else if (vol_size <= ((u64)1 << 36))
statistics.vol_size[SDFAT_VOL_64G]++;
else if (vol_size <= ((u64)1 << 37))
statistics.vol_size[SDFAT_VOL_128G]++;
else if (vol_size <= ((u64)1 << 38))
statistics.vol_size[SDFAT_VOL_256G]++;
else if (vol_size <= ((u64)1 << 39))
statistics.vol_size[SDFAT_VOL_512G]++;
else
statistics.vol_size[SDFAT_VOL_XTB]++;
}