Lines Matching refs:filemon

27 __KERNEL_RCSID(0, "$NetBSD: filemon.c,v 1.3 2011/07/04 23:37:30 sjg Exp $");
45 #include "filemon.h"
47 MODULE(MODULE_CLASS_DRIVER, filemon, NULL);
81 static TAILQ_HEAD(, filemon) filemons_inuse =
89 filemon_output(struct filemon * filemon, char *msg, size_t len)
94 if (filemon->fm_fp == NULL)
118 (*filemon->fm_fp->f_ops->fo_write) (filemon->fm_fp,
119 &(filemon->fm_fp->f_offset),
124 filemon_comment(struct filemon * filemon)
128 len = snprintf(filemon->fm_msgbufr, sizeof(filemon->fm_msgbufr),
129 "# filemon version %d\n# Target pid %d\nV %d\n",
132 filemon_output(filemon, filemon->fm_msgbufr, len);
136 static struct filemon *
139 struct filemon *filemon;
141 TAILQ_FOREACH(filemon, &filemons_inuse, fm_link) {
142 if (p->p_pid == filemon->fm_pid)
143 return (filemon);
153 * return exclusive access to a filemon struct
155 struct filemon *
158 struct filemon *filemon;
161 filemon = filemon_pid_check(p);
162 if (filemon) {
163 rw_enter(&filemon->fm_mtx, RW_WRITER);
166 return filemon;
169 static struct filemon *
172 struct filemon *filemon;
175 filemon = fp->f_data;
176 if (filemon && lck) {
177 rw_enter(&filemon->fm_mtx, lck);
180 return filemon;
189 struct filemon *filemon;
197 filemon = kmem_alloc(sizeof(struct filemon), KM_SLEEP);
198 rw_init(&filemon->fm_mtx);
199 filemon->fm_fd = -1;
200 filemon->fm_fp = NULL;
201 filemon->fm_pid = curproc->p_pid;
204 TAILQ_INSERT_TAIL(&filemons_inuse, filemon, fm_link);
208 return fd_clone(fp, fd, oflags, &filemon_fileops, filemon);
215 struct filemon *filemon;
226 filemon = fp->f_data;
227 if (!filemon) {
232 TAILQ_REMOVE(&filemons_inuse, filemon, fm_link);
240 rw_enter(&filemon->fm_mtx, RW_WRITER);
241 if (filemon->fm_fp) {
242 fd_putfile(filemon->fm_fd); /* release our reference */
243 filemon->fm_fp = NULL;
245 rw_exit(&filemon->fm_mtx);
246 rw_destroy(&filemon->fm_mtx);
247 kmem_free(filemon, sizeof(struct filemon));
256 struct filemon *filemon;
264 * this ensures we cannot get filemon if it is closing.
266 filemon = filemon_fp_data(fp, RW_WRITER);
267 if (!filemon)
273 filemon->fm_fd = *((int *) data);
274 if ((filemon->fm_fp = fd_getfile(filemon->fm_fd)) == NULL) {
275 rw_exit(&filemon->fm_mtx);
279 filemon_comment(filemon);
284 filemon->fm_pid = *((pid_t *) data);
292 rw_exit(&filemon->fm_mtx);
352 error = devsw_attach("filemon", NULL, &bmajor,
363 log(LOG_INFO, "filemon: open=%d", n_open);