1 #include <linux/module.h>
2 #include <linux/slab.h>
4 #include <linux/debugfs.h>
7 #include "ged_debugFS.h"
9 #define GED_DEBUGFS_DIR_NAME "ged"
11 static struct dentry
*gpsDebugFSEntryDir
= NULL
;
13 typedef struct _GED_DEBUGFS_PRIV_DATA_
15 struct seq_operations
* psReadOps
;
16 GED_ENTRY_WRITE_FUNC
* pfnWrite
;
18 } GED_DEBUGFS_PRIV_DATA
;
19 //-----------------------------------------------------------------------------
20 static int ged_debugFS_open(struct inode
*psINode
, struct file
*psFile
)
22 GED_DEBUGFS_PRIV_DATA
*psPrivData
= (GED_DEBUGFS_PRIV_DATA
*)psINode
->i_private
;
25 iResult
= seq_open(psFile
, psPrivData
->psReadOps
);
28 struct seq_file
*psSeqFile
= psFile
->private_data
;
30 psSeqFile
->private = psPrivData
->pvData
;
35 return GED_ERROR_FAIL
;
37 //-----------------------------------------------------------------------------
38 static ssize_t
ged_debugFS_write(
40 const char __user
* pszBuffer
,
44 struct inode
*psINode
= psFile
->f_path
.dentry
->d_inode
;
45 GED_DEBUGFS_PRIV_DATA
*psPrivData
= (GED_DEBUGFS_PRIV_DATA
*)psINode
->i_private
;
47 if (psPrivData
->pfnWrite
== NULL
)
52 return psPrivData
->pfnWrite(pszBuffer
, uiCount
, *puiPosition
, psPrivData
->pvData
);
54 //-----------------------------------------------------------------------------
55 static const struct file_operations gsGEDDebugFSFileOps
=
58 .open
= ged_debugFS_open
,
60 .write
= ged_debugFS_write
,
62 .release
= seq_release
,
64 //-----------------------------------------------------------------------------
65 GED_ERROR
ged_debugFS_create_entry(
68 struct seq_operations
* psReadOps
,
69 GED_ENTRY_WRITE_FUNC
* pfnWrite
,
71 struct dentry
** ppsEntry
)
73 GED_DEBUGFS_PRIV_DATA
* psPrivData
;
74 struct dentry
* psEntry
;
77 //assert(gpkDebugFSEntryDir != NULL);
79 psPrivData
= ged_alloc(sizeof(GED_DEBUGFS_PRIV_DATA
));
80 if (psPrivData
== NULL
)
85 psPrivData
->psReadOps
= psReadOps
;
86 psPrivData
->pfnWrite
= pfnWrite
;
87 psPrivData
->pvData
= pvData
;
91 if (psReadOps
!= NULL
)
98 uiMode
|= S_IWUSR
| S_IWGRP
| S_IWOTH
;
101 psEntry
= debugfs_create_file(pszName
,
103 (pvDir
!= NULL
) ? (struct dentry
*)pvDir
: gpsDebugFSEntryDir
,
105 &gsGEDDebugFSFileOps
);
108 GED_LOGE("Failed to create '%s' debugfs entry\n", pszName
);
109 return GED_ERROR_FAIL
;
116 //-----------------------------------------------------------------------------
117 void ged_debugFS_remove_entry(struct dentry
*psEntry
)
119 if (psEntry
->d_inode
->i_private
!= NULL
)
121 ged_free(psEntry
->d_inode
->i_private
, sizeof(GED_DEBUGFS_PRIV_DATA
));
124 debugfs_remove(psEntry
);
126 //-----------------------------------------------------------------------------
127 GED_ERROR
ged_debugFS_create_entry_dir(
129 struct dentry
* psParentDir
,
130 struct dentry
** ppsDir
)
132 struct dentry
*psDir
;
134 if (pszName
== NULL
|| ppsDir
== NULL
)
136 return GED_ERROR_INVALID_PARAMS
;
139 psDir
= debugfs_create_dir(pszName
, (psParentDir
) ? psParentDir
: gpsDebugFSEntryDir
);
142 GED_LOGE("Failed to create '%s' debugfs directory\n", pszName
);
143 return GED_ERROR_OOM
;
150 //-----------------------------------------------------------------------------
151 void ged_debugFS_remove_entry_dir(struct dentry
*psDir
)
153 debugfs_remove(psDir
);
155 //-----------------------------------------------------------------------------
156 GED_ERROR
ged_debugFS_init(void)
158 //assert(gpkDebugFSEntryDir == NULL);
160 gpsDebugFSEntryDir
= debugfs_create_dir(GED_DEBUGFS_DIR_NAME
, NULL
);
161 if (gpsDebugFSEntryDir
== NULL
)
163 GED_LOGE("Failed to create '%s' debugfs root directory\n", GED_DEBUGFS_DIR_NAME
);
164 return GED_ERROR_OOM
;
169 //-----------------------------------------------------------------------------
170 void ged_debugFS_exit(void)
172 //assert(gpkDebugFSEntryDir != NULL);
174 debugfs_remove(gpsDebugFSEntryDir
);
175 gpsDebugFSEntryDir
= NULL
;
177 //-----------------------------------------------------------------------------