From owner-freebsd-hackers Wed Jun 27 10:53:12 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from hawk.mail.pas.earthlink.net (hawk.mail.pas.earthlink.net [207.217.120.22]) by hub.freebsd.org (Postfix) with ESMTP id 37DA237B407 for ; Wed, 27 Jun 2001 10:53:09 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from mindspring.com (dialup-209.245.141.189.Dial1.SanJose1.Level3.net [209.245.141.189]) by hawk.mail.pas.earthlink.net (EL-8_9_3_3/8.9.3) with ESMTP id KAA07563; Wed, 27 Jun 2001 10:52:58 -0700 (PDT) Message-ID: <3B3A1D94.5895DCD0@mindspring.com> Date: Wed, 27 Jun 2001 10:53:24 -0700 From: Terry Lambert Reply-To: tlambert2@mindspring.com X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: "Eugene L. Vorokov" Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: accessing files from kld module References: <200106271617.f5RGH0243541@bugz.infotecs.ru> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG "Eugene L. Vorokov" wrote: > probably this question was asked here many times before, > but I'm new to kernel mode hacks ... Is it somehow possible > to access files from my kld module ? I have seen functions > like printf(), MALLOC() for kernel mode, but nothing like > open() ... using open() syscall directly seems impossible > too because generally I don't have struct proc entry. > > I would be very thankful for any information regarding this issue. Kernel file handling in FreeBSD is significantly inferior to that of many other operating systems; notably, AIX has vastly superior file handling, which can be used from its kernel threads, etc. (AIX has the best I've seen). For FreeBSD, you can do file handling, with some effort; the main problem is that vnode pointer references are not considered "opens" by the resource tracking system (as they are in SVR4 and Solaris and several other SVR3/SVR4 derived OS's). The place you want to look is: /sys/kern/vfs_vnops.c I/O is tricky; if you are reading/writing to a buffer in kernel space, you have to use the combined vn_rdwr() routine. Make sure you set segflg to UIO_SYSSPACE. This really is easier than direct calls to VOP_WRITE(), or trying to allocate and manage fp's without a real process, and calling vn_read() or vn_write(), which, contrary to their names, do not operate on vnodes, they operate on fp's. You won't be able to use ioctl(), poll(), kqfilter(), etc., without at least consing up a fake fp, and since the parts used vary, you'd be better off with a real one. Good luck. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message