From owner-freebsd-fs@FreeBSD.ORG Sat Apr 16 02:15:09 2011 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 864BE106564A for ; Sat, 16 Apr 2011 02:15:09 +0000 (UTC) (envelope-from z0.0z.furukawa@gmail.com) Received: from mail-pz0-f54.google.com (mail-pz0-f54.google.com [209.85.210.54]) by mx1.freebsd.org (Postfix) with ESMTP id 59F0E8FC17 for ; Sat, 16 Apr 2011 02:15:09 +0000 (UTC) Received: by pzk27 with SMTP id 27so1594365pzk.13 for ; Fri, 15 Apr 2011 19:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:content-type:content-transfer-encoding; bh=tKxDKsggTi/Bcy3x9JTm9llfhGwQgkuMI+8CyPAmyYE=; b=Bi/LcXM0rdzLMHJzvMh9y5lg32krbw2F7tNGbs99Iq7y76zTWusZO0cuxr/Xni110O S/fY/cK2TvOY/9HriT9QO6e3KSPuSMkEoRY4ntAuQ5+iwvWPfTKIuavBN3AoYbg2kmaD /YpOSoDWX8TRKb10m2oreE+50k5F2mjqKI1+A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=W80j0L56fU+tVdKMqExIl/LPsegVjC4WyyN4rKGYCsUYpkzXCFx44jQFhI1m6+toTT FQ4qkgYbQoofEKcVhVeQiKtHSm+Aqr7JPXtHdAryvlKcdLIsKkFluNjKPSfY1d4cdSn9 QYFeFj9fybZLGrl6X883xyb4fe6k65gxt1H8w= Received: by 10.142.120.38 with SMTP id s38mr1176774wfc.128.1302918765406; Fri, 15 Apr 2011 18:52:45 -0700 (PDT) Received: from [172.16.211.46] (atago.c.csce.kyushu-u.ac.jp [133.5.17.150]) by mx.google.com with ESMTPS id y2sm4395730wfd.20.2011.04.15.18.52.43 (version=SSLv3 cipher=OTHER); Fri, 15 Apr 2011 18:52:44 -0700 (PDT) Message-ID: <4DA8F664.9030008@gmail.com> Date: Sat, 16 Apr 2011 10:52:36 +0900 From: Jun Furukawa User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; ja; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: freebsd-fs@freebsd.org Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Subject: cdp_c has incomplete type error X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Apr 2011 02:15:09 -0000 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 /* module */ #include /* module */ #include /* module */ #include /* size_t, copyin, copyout, malloc */ #include /* copyin, copyout */ #include /* struct thread */ #include /* vnops */ #include /* msdosfs_vnodeops */ #include /* malloc */ #include /* 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