forked from linux-nvme/nvme-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvme-filters.c
104 lines (81 loc) · 1.79 KB
/
nvme-filters.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
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "nvme.h"
/* global, used for controller specific namespace filter */
int current_index;
int scan_ctrl_namespace_filter(const struct dirent *d)
{
int c, i, n;
if (d->d_name[0] == '.')
return 0;
if (strstr(d->d_name, "nvme")) {
if (sscanf(d->d_name, "nvme%dc%dn%d", &i, &c, &n) == 3)
return 1;
if (sscanf(d->d_name, "nvme%dn%d", &i, &n) == 2)
return 1;
}
return 0;
}
int scan_namespace_filter(const struct dirent *d)
{
int i, n;
if (d->d_name[0] == '.')
return 0;
if (strstr(d->d_name, "nvme"))
if (sscanf(d->d_name, "nvme%dn%d", &i, &n) == 2)
return 1;
return 0;
}
int scan_ctrl_paths_filter(const struct dirent *d)
{
int id, cntlid, nsid;
if (d->d_name[0] == '.')
return 0;
if (strstr(d->d_name, "nvme")) {
if (sscanf(d->d_name, "nvme%dc%dn%d", &id, &cntlid, &nsid) == 3)
return 1;
if (sscanf(d->d_name, "nvme%dn%d", &id, &nsid) == 2)
return 1;
}
return 0;
}
int scan_ctrls_filter(const struct dirent *d)
{
int id, nsid;
if (d->d_name[0] == '.')
return 0;
if (strstr(d->d_name, "nvme")) {
if (sscanf(d->d_name, "nvme%dn%d", &id, &nsid) == 2)
return 0;
if (sscanf(d->d_name, "nvme%dn", &id) == 1)
return 1;
return 0;
}
return 0;
}
int scan_subsys_filter(const struct dirent *d)
{
int id;
if (d->d_name[0] == '.')
return 0;
if (strstr(d->d_name, "nvme-subsys")) {
if (sscanf(d->d_name, "nvme-subsys%d", &id) != 1)
return 0;
return 1;
}
return 0;
}
int scan_dev_filter(const struct dirent *d)
{
int ctrl, ns, part;
if (d->d_name[0] == '.')
return 0;
if (strstr(d->d_name, "nvme")) {
if (sscanf(d->d_name, "nvme%dn%dp%d", &ctrl, &ns, &part) == 3)
return 0;
if (sscanf(d->d_name, "nvme%dn%d", &ctrl, &ns) == 2)
return ctrl == current_index;
}
return 0;
}