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
|
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/debugfs.h>
#include "ged_base.h"
#include "ged_debugFS.h"
#define GED_DEBUGFS_DIR_NAME "ged"
static struct dentry *gpsDebugFSEntryDir = NULL;
typedef struct _GED_DEBUGFS_PRIV_DATA_
{
struct seq_operations* psReadOps;
GED_ENTRY_WRITE_FUNC* pfnWrite;
void* pvData;
} GED_DEBUGFS_PRIV_DATA;
//-----------------------------------------------------------------------------
static GED_ERROR ged_debugFS_open(struct inode *psINode, struct file *psFile)
{
GED_DEBUGFS_PRIV_DATA *psPrivData = (GED_DEBUGFS_PRIV_DATA *)psINode->i_private;
int iResult;
iResult = seq_open(psFile, psPrivData->psReadOps);
if (iResult == 0)
{
struct seq_file *psSeqFile = psFile->private_data;
psSeqFile->private = psPrivData->pvData;
return GED_OK;
}
return GED_ERROR_FAIL;
}
//-----------------------------------------------------------------------------
static ssize_t ged_debugFS_write(
struct file* psFile,
const char __user* pszBuffer,
size_t uiCount,
loff_t* puiPosition)
{
struct inode *psINode = psFile->f_path.dentry->d_inode;
GED_DEBUGFS_PRIV_DATA *psPrivData = (GED_DEBUGFS_PRIV_DATA *)psINode->i_private;
if (psPrivData->pfnWrite == NULL)
{
return -EIO;
}
return psPrivData->pfnWrite(pszBuffer, uiCount, *puiPosition, psPrivData->pvData);
}
//-----------------------------------------------------------------------------
static const struct file_operations gsGEDDebugFSFileOps =
{
.owner = THIS_MODULE,
.open = ged_debugFS_open,
.read = seq_read,
.write = ged_debugFS_write,
.llseek = seq_lseek,
.release = seq_release,
};
//-----------------------------------------------------------------------------
GED_ERROR ged_debugFS_create_entry(
const char* pszName,
void* pvDir,
struct seq_operations* psReadOps,
GED_ENTRY_WRITE_FUNC* pfnWrite,
void* pvData,
struct dentry** ppsEntry)
{
GED_DEBUGFS_PRIV_DATA* psPrivData;
struct dentry* psEntry;
umode_t uiMode;
//assert(gpkDebugFSEntryDir != NULL);
psPrivData = ged_alloc(sizeof(GED_DEBUGFS_PRIV_DATA));
if (psPrivData == NULL)
{
return GED_ERROR_OOM;
}
psPrivData->psReadOps = psReadOps;
psPrivData->pfnWrite = pfnWrite;
psPrivData->pvData = pvData;
uiMode = S_IFREG;
if (psReadOps != NULL)
{
uiMode |= S_IRUGO;
}
if (pfnWrite != NULL)
{
uiMode |= S_IWUSR;
}
psEntry = debugfs_create_file(pszName,
uiMode,
(pvDir != NULL) ? (struct dentry *)pvDir : gpsDebugFSEntryDir,
psPrivData,
&gsGEDDebugFSFileOps);
if (IS_ERR(psEntry))
{
GED_LOGE("Failed to create '%s' debugfs entry\n", pszName);
return GED_ERROR_FAIL;
}
*ppsEntry = psEntry;
return GED_OK;
}
//-----------------------------------------------------------------------------
void ged_debugFS_remove_entry(struct dentry *psEntry)
{
if (psEntry->d_inode->i_private != NULL)
{
ged_free(psEntry->d_inode->i_private, sizeof(GED_DEBUGFS_PRIV_DATA));
}
debugfs_remove(psEntry);
}
//-----------------------------------------------------------------------------
GED_ERROR ged_debugFS_create_entry_dir(
const char* pszName,
struct dentry* psParentDir,
struct dentry** ppsDir)
{
struct dentry *psDir;
if (pszName == NULL || ppsDir == NULL)
{
return GED_ERROR_INVALID_PARAMS;
}
psDir = debugfs_create_dir(pszName, (psParentDir) ? psParentDir : gpsDebugFSEntryDir);
if (psDir == NULL)
{
GED_LOGE("Failed to create '%s' debugfs directory\n", pszName);
return GED_ERROR_OOM;
}
*ppsDir = psDir;
return GED_OK;
}
//-----------------------------------------------------------------------------
void ged_debugFS_remove_entry_dir(struct dentry *psDir)
{
debugfs_remove(psDir);
}
//-----------------------------------------------------------------------------
GED_ERROR ged_debugFS_init(void)
{
//assert(gpkDebugFSEntryDir == NULL);
gpsDebugFSEntryDir = debugfs_create_dir(GED_DEBUGFS_DIR_NAME, NULL);
if (gpsDebugFSEntryDir == NULL)
{
GED_LOGE("Failed to create '%s' debugfs root directory\n", GED_DEBUGFS_DIR_NAME);
return GED_ERROR_OOM;
}
return GED_OK;
}
//-----------------------------------------------------------------------------
void ged_debugFS_exit(void)
{
//assert(gpkDebugFSEntryDir != NULL);
debugfs_remove(gpsDebugFSEntryDir);
gpsDebugFSEntryDir = NULL;
}
//-----------------------------------------------------------------------------
|