site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=GEaeIAjKfwFXB4VYUl9hfo91CqLWoTCGYQQzG2Efw1KZfjTozIdQdaX+uttVcd1slVrt1C5io8K88Hs2Zox2NphyNSEjmHte6LtB1fq0D5TlAVnzQGFdss1VzqgNc8gRH1b2RHmiip1BD53nZt/E8SmfAjQFETj9bpLn1O/K46o= ; Hi I am quite new to the Mac world...I am trying to write(using xcode on tiger) a simple character driver(openbsd.org example) and am facing few problems... During compile, struct uio is not recognized and I get a dereferencing pointer to incomplete type error...can somebody help...maybe I am not including the correct libraries... my code is as follows #include <mach/mach_types.h> #include <sys/types.h> #include <sys/proc.h> #include <sys/dkstat.h> #include <sys/fcntl.h> //#include <sys/module.h> #include <sys/systm.h> /* uprintf */ #include <sys/errno.h> #include <sys/param.h> /* defines used in kernel.h */ #include <sys/kernel.h> /* types used in module initialization */ #include <sys/conf.h> /* cdevsw struct */ #include <sys/uio.h> /* uio struct */ #include <sys/malloc.h> #include <sys/kernel_types.h> #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #define BUFFERSIZE 256 /* Function prototypes */ d_open_t echo_open; d_close_t echo_close; d_read_t echo_read; d_write_t echo_write; /* Character device entry points */ static struct cdevsw echo_cdevsw = { echo_open, echo_close, echo_read, echo_write, 0, 0, 0, 0, "echo", 33, /* reserved for lkms - /usr/src/sys/conf/majors */ 0, 0, 2, -1 }; struct s_echo { char msg[BUFFERSIZE]; int len; } ; /* vars */ static dev_t sdev; static int count; static struct s_echo *echomsg; //MALLOC_DECLARE(M_ECHOBUF); //MALLOC_DEFINE(M_ECHOBUF, "echobuffer", "buffer for echo module"); kern_return_t chardriver_start (kmod_info_t * ki, void * d) { return KERN_SUCCESS; } kern_return_t chardriver_stop (kmod_info_t * ki, void * d) { return KERN_SUCCESS; } /* * This function is called by the kld[un]load(2) system calls to * determine what actions to take when a module is loaded or unloaded. static int echo_loader(struct module *m, int what, void *arg) { int err = 0; switch (what) { case MOD_LOAD: kldload sdev = make_dev(&echo_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "echo"); kmalloc memory for use by this driver MALLOC(echomsg, struct s_echo *, sizeof(struct s_echo), M_ECHOBUF, M_WAITOK); printf("Echo device loaded.\n"); break; case MOD_UNLOAD: destroy_dev(sdev); FREE(echomsg,M_ECHOBUF); printf("Echo device unloaded.\n"); break; default: err = EINVAL; break; } return(err); }*/ int echo_open(dev_t dev, int oflags, int devtype, struct proc *p) { int err = 0; uprintf("Opened device \"echo\" successfully.\n"); return(err); } int echo_close(dev_t dev, int fflag, int devtype, struct proc *p) { uprintf("Closing device \"echo.\"\n"); return(0); } /* * The read function just takes the buf that was saved via * echo_write() and returns it to userland for accessing. * uio(9) */ int echo_read(dev_t dev, struct uio *uio, int ioflag) { int err = 0; int amt=echomsg->len; // struct uio trial; /* * How big is this read operation? Either as big as the user wants, * or as big as the remaining data */ amt = MIN(uio->uio_resid, (echomsg->len - uio->uio_offset > 0) ? echomsg->len - uio->uio_offset : 0); if ((err = uiomove(echomsg->msg + uio->uio_offset,amt,uio)) != 0) { uprintf("uiomove failed!\n"); } return(err); } /* * echo_write takes in a character string and saves it * to buf for later accessing. */ int echo_write(dev_t dev, struct uio *uio, int ioflag) { int err = 0; /* Copy the string in from user memory to kernel memory */ err = copyin(uio->uio_iov->iov_base, echomsg->msg,MIN(uio->uio_iov->iov_len, BUFFERSIZE - 1)); /* Now we need to null terminate, then record the length */ *(echomsg->msg + MIN(uio->uio_iov->iov_len, BUFFERSIZE - 1)) = 0; echomsg->len = MIN(uio->uio_iov->iov_len, BUFFERSIZE); if (err != 0) { uprintf("Write failed: bad address!\n"); } count++; return(err); } regards Sugumaran CL __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
sugumaran narayanan