Date: Sat, 16 Apr 2011 10:52:36 +0900 From: Jun Furukawa <z0.0z.furukawa@gmail.com> To: freebsd-fs@freebsd.org Subject: cdp_c has incomplete type error Message-ID: <4DA8F664.9030008@gmail.com>
next in thread | raw e-mail | index | archive | help
When I compiled the following C language code which hooks vn_write function on FreeBSD8.2, I get "error: field 'cdp_c' has incomplete type" error. Here we list the C source code, Makefile and the compiler messages. Can anyone help me please? ************************vn_hook.c*********************************** #include <sys/param.h> /* module */ #include <sys/module.h> /* module */ #include <sys/kernel.h> /* module */ #include <sys/types.h> /* size_t, copyin, copyout, malloc */ #include <sys/systm.h> /* copyin, copyout */ #include <sys/proc.h> /* struct thread */ #include <sys/file.h> /* vnops */ #include <fs/msdosfs/msdosfs_vnops.c> /* msdosfs_vnodeops */ #include <sys/malloc.h> /* malloc */ #include <fs/devfs/devfs_int.h> /* cdpd_data */ typedef int (*vnw_t)(struct file*, struct uio*, struct ucred*, int flags, struct thread*); int vn_write_hook(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td); int caesar_encrypt (char *str, int len, int key); vnw_t old_vn_write; /* caesar encription */ int caesar_encrypt (char *str, int len, int key) { int i; for (i = 0; i < len ; i++) { if (str[i] != '\0') { str[i] += key; } } return 0; } /* vn_write hook */ int vn_write_hook(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td) { /* The definition of struct file */ /* from /usr/include/sys/file.h */ //struct file { // ... // struct vnode *f_vnode; /* NULL or applicable vnode */ // ... for f_offset */ // // struct cdev_privdata *f_cdevpriv; /* (d) Private data // for the cdev. */ //}; /* The definition of vnode */ /* from /usr/include/sys/vnode.h */ //struct vnode { // ... // const char *v_tag; /* u type of // underlying data */ // ... //}; /* The definition of struct iovec */ /* from /usr/include/sys/_iovec.h */ //struct iovec { // void *iov_base; /* Base address. */ // size_t iov_len; /* Length. */ //}; /* The definition of struct uio */ /* from /usr/include/sys/uio.h */ //struct uio { //struct iovec *uio_iov; /* scatter/gather list */ //... //}; /* struct cdev_privdata */ /* from /usr/include/fs/devfs/devfs_int.h */ //struct cdev_privdata { // struct file *cdpd_fp; // void *cdpd_data; // void (*cdpd_dtr)(void *); // LIST_ENTRY(cdev_privdata) cdpd_list; //}; /* Is the destination msdosfs ? */ if(!strncmp("msdosfs",fp->f_vnode->v_tag,7)) { int error; int iov_len; char *mybuf; iov_len = uio->uio_iov->iov_len; mybuf = (char *)malloc(iov_len,M_TEMP,M_NOWAIT|M_ZERO); /* copy data from user land to kernel land */ error = copyin(uio->uio_iov->iov_base, mybuf, iov_len); if (error != 0) { uprintf("Cannot write data to kernel space\n"); } /* debug */ // uprintf("cdev_priv:%p", // (char *)fp->f_cdevpriv->cdpd_data); /* encrypt by caesar algorithm */ caesar_encrypt(mybuf, iov_len, 3); /* copy data from kernel land to user land */ error = copyout(mybuf, uio->uio_iov->iov_base, iov_len); if (error != 0) { uprintf("Cannot write data to user space\n"); } free(mybuf,M_TEMP); } return (old_vn_write(fp, uio, active_cred, flags, td)); } /* The function called at load/unload */ static int load(struct module *module, int cmd, void *arg) { int error = 0; /* the initial value of vnops */ /* from /usr/src/sys/kern/vfs_vnops.c */ //struct fileops vnops = { // .fo_read = vn_read, // .fo_write = vn_write, // .fo_truncate = vn_truncate, // .fo_ioctl = vn_ioctl, // .fo_poll = vn_poll, // .fo_kqfilter = vn_kqfilter, // .fo_stat = vn_statfile, // .fo_close = vn_closefile, // .fo_flags = DFLAG_PASSABLE | DFLAG_SEEKABLE //}; switch (cmd) { case MOD_LOAD: uprintf("Module has loaded\n"); /* Replace vn_write with vn_write_hook. */ old_vn_write = (vnw_t)(vnops.fo_write); vnops.fo_write = vn_write_hook; break; case MOD_UNLOAD: uprintf("Module has unloaded\n"); /* Change everyhting back to normal. */ vnops.fo_write = old_vn_write; break; default: error = EOPNOTSUPP; break; } return (error); } static moduledata_t vn_write_hook_mod = { "vn_write_hook", /* module name */ load, /* event handler */ NULL /* EXTRA DATA */ }; DECLARE_MODULE(vn_write_hook, vn_write_hook_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); ************************vn_hook.c*********************************** ************************Makefile************************************ KMOD = vn_hook # Name of KLD to build. SRCS = vnode_if.h vn_hook.c # List of source files. .include <bsd.kmod.mk ************************Makefile*********************************** ************************Compiler Message**************************** Warning: Object directory not changed from original /usr/home/jun/vn_hook cc -O2 -pipe -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc -I. -I@ -I@/contrib/altq -finline-limit=8000 --param inline-unit-growth=100 --param large-function-growth=1000 -fno-common -mno-align-long-strings -mpreferred-stack-boundary=2 -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -ffreestanding -fstack-protector -std=iso9899:1999 -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -fformat-extensions -c vn_hook.c *** Error code 1 Stop in /usr/home/jun/vn_hook. Warning: Object directory not changed from original /usr/home/jun/vn_hook cc -O2 -pipe -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc -I. -I@ -I@/contrib/altq -finline-limit=8000 --param inline-unit-growth=100 --param large-function-growth=1000 -fno-common -mno-align-long-strings -mpreferred-stack-boundary=2 -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -ffreestanding -fstack-protector -std=iso9899:1999 -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -fformat-extensions -c vn_hook.c In file included from vn_hook.c:10: @/fs/devfs/devfs_int.h:50: error: field 'cdp_c' has incomplete type *** Error code 1 Stop in /usr/home/jun/vn_hook. ************************Compiler Message***************************** Jun Furukawa
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4DA8F664.9030008>