From owner-freebsd-drivers@FreeBSD.ORG Mon Mar 26 02:41:17 2012 Return-Path: Delivered-To: drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7A464106566B for ; Mon, 26 Mar 2012 02:41:17 +0000 (UTC) (envelope-from yong.fan@exar.com) Received: from smtp1.exar.com (webmail.exar.com [204.154.183.83]) by mx1.freebsd.org (Postfix) with ESMTP id 595AC8FC20 for ; Mon, 26 Mar 2012 02:41:16 +0000 (UTC) Received: from FRE1-CAS2.hq.exar.com (10.127.1.158) by FRE1-CAS.hq.exar.com (10.127.1.162) with Microsoft SMTP Server (TLS) id 8.1.436.0; Sun, 25 Mar 2012 19:41:16 -0700 Received: from HZU1EXCH02.hq.exar.com (172.18.10.52) by FRE1-CAS2.hq.exar.com (10.127.1.158) with Microsoft SMTP Server (TLS) id 8.1.436.0; Sun, 25 Mar 2012 19:41:16 -0700 Received: from HZU1EXCH02.hq.exar.com ([fe80::5528:f080:2385:1c90]) by HZU1EXCH02.hq.exar.com ([fe80::5528:f080:2385:1c90%13]) with mapi; Mon, 26 Mar 2012 10:41:11 +0800 From: Yong Fan To: "drivers@FreeBSD.org" Date: Mon, 26 Mar 2012 10:41:09 +0800 Thread-Topic: operate file in kernel space Thread-Index: Ac0K+eZDcDMddpvjR+i0sUSbIWy00A== Message-ID: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFB5B@HZU1EXCH02.hq.exar.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, zh-CN MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: operate file in kernel space X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2012 02:41:17 -0000 Hi all, I want to operate file in kernel space. At present, I have found the following kernel routines, which operate file: Kern_open(), kern_close(), kern_readv() and kern_writev(). Now, I have some doubt about these routines? 1 kern_open() doesn't return a file handle or file pointer? As we know, filp_open(), which is a Linux kernel routine, returns a file po= inter. ZwCreateFile(), which is a Windows kernel routine, returns a file handle. 2 how can I "seek" a file in kernel space? The function of "seek" routine is similar with generic_file_llseek()(Linux)= or ZwSetInformationFile()(windows). Thanks Yongfan ________________________________ The information and any attached documents contained in this message may be confidential and/or legally privileged. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, dissemination, or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender immediately by return e-mail and destroy all copies of the original message. From owner-freebsd-drivers@FreeBSD.ORG Mon Mar 26 14:48:09 2012 Return-Path: Delivered-To: drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C2A071065678; Mon, 26 Mar 2012 14:48:09 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 947818FC1A; Mon, 26 Mar 2012 14:48:09 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 3EA9B46B35; Mon, 26 Mar 2012 10:48:09 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 9A067B94E; Mon, 26 Mar 2012 10:48:08 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Date: Mon, 26 Mar 2012 10:14:30 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p10; KDE/4.5.5; amd64; ; ) References: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFB5B@HZU1EXCH02.hq.exar.com> In-Reply-To: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFB5B@HZU1EXCH02.hq.exar.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201203261014.30542.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 26 Mar 2012 10:48:08 -0400 (EDT) Cc: Yong Fan , "drivers@FreeBSD.org" Subject: Re: operate file in kernel space X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2012 14:48:09 -0000 On Sunday, March 25, 2012 10:41:09 pm Yong Fan wrote: > Hi all, > > I want to operate file in kernel space. > At present, I have found the following kernel routines, which operate file: > Kern_open(), kern_close(), kern_readv() and kern_writev(). > Now, I have some doubt about these routines? > 1 kern_open() doesn't return a file handle or file pointer? > As we know, filp_open(), which is a Linux kernel routine, returns a file pointer. > ZwCreateFile(), which is a Windows kernel routine, returns a file handle. > > 2 how can I "seek" a file in kernel space? > The function of "seek" routine is similar with generic_file_llseek()(Linux) or ZwSetInformationFile()(windows). file descriptors in FreeBSD are generally tied to a file descriptor table (so a process). What you can do is locate a vnode directly (e.g. using namei() to do a pathname lookup) and then use vn_rdwr() to access the data in the file. vn_rdwr() accepts a uio and you would manage your own "seek" location and that gets set in the uio_offset of the uio you pass to vn_rdwr(). -- John Baldwin From owner-freebsd-drivers@FreeBSD.ORG Mon Mar 26 14:48:09 2012 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C2A071065678; Mon, 26 Mar 2012 14:48:09 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 947818FC1A; Mon, 26 Mar 2012 14:48:09 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 3EA9B46B35; Mon, 26 Mar 2012 10:48:09 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 9A067B94E; Mon, 26 Mar 2012 10:48:08 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Date: Mon, 26 Mar 2012 10:14:30 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p10; KDE/4.5.5; amd64; ; ) References: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFB5B@HZU1EXCH02.hq.exar.com> In-Reply-To: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFB5B@HZU1EXCH02.hq.exar.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201203261014.30542.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 26 Mar 2012 10:48:08 -0400 (EDT) Cc: Yong Fan , "drivers@FreeBSD.org" Subject: Re: operate file in kernel space X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2012 14:48:09 -0000 On Sunday, March 25, 2012 10:41:09 pm Yong Fan wrote: > Hi all, > > I want to operate file in kernel space. > At present, I have found the following kernel routines, which operate file: > Kern_open(), kern_close(), kern_readv() and kern_writev(). > Now, I have some doubt about these routines? > 1 kern_open() doesn't return a file handle or file pointer? > As we know, filp_open(), which is a Linux kernel routine, returns a file pointer. > ZwCreateFile(), which is a Windows kernel routine, returns a file handle. > > 2 how can I "seek" a file in kernel space? > The function of "seek" routine is similar with generic_file_llseek()(Linux) or ZwSetInformationFile()(windows). file descriptors in FreeBSD are generally tied to a file descriptor table (so a process). What you can do is locate a vnode directly (e.g. using namei() to do a pathname lookup) and then use vn_rdwr() to access the data in the file. vn_rdwr() accepts a uio and you would manage your own "seek" location and that gets set in the uio_offset of the uio you pass to vn_rdwr(). -- John Baldwin From owner-freebsd-drivers@FreeBSD.ORG Tue Mar 27 02:01:33 2012 Return-Path: Delivered-To: drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10BC1106564A; Tue, 27 Mar 2012 02:01:33 +0000 (UTC) (envelope-from yong.fan@exar.com) Received: from smtp1.exar.com (webmail.exar.com [204.154.183.83]) by mx1.freebsd.org (Postfix) with ESMTP id E517A8FC0A; Tue, 27 Mar 2012 02:01:32 +0000 (UTC) Received: from HZU1EXCH02.hq.exar.com (172.18.10.52) by FRE1-CAS.hq.exar.com (10.127.1.162) with Microsoft SMTP Server (TLS) id 8.1.436.0; Mon, 26 Mar 2012 19:01:32 -0700 Received: from HZU1EXCH02.hq.exar.com ([fe80::5528:f080:2385:1c90]) by HZU1EXCH02.hq.exar.com ([fe80::5528:f080:2385:1c90%13]) with mapi; Tue, 27 Mar 2012 10:01:28 +0800 From: Yong Fan To: John Baldwin , "freebsd-drivers@freebsd.org" Date: Tue, 27 Mar 2012 10:01:27 +0800 Thread-Topic: operate file in kernel space Thread-Index: Ac0LX3jHaefjAwZ+TeOKy2arMzJcxwAXdtzg Message-ID: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFCAA@HZU1EXCH02.hq.exar.com> References: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFB5B@HZU1EXCH02.hq.exar.com> <201203261014.30542.jhb@freebsd.org> In-Reply-To: <201203261014.30542.jhb@freebsd.org> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, zh-CN Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "drivers@FreeBSD.org" Subject: RE: operate file in kernel space X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Mar 2012 02:01:33 -0000 Thanks your warm reply. I will have a try. Yongfan Thanks -----Original Message----- From: John Baldwin [mailto:jhb@freebsd.org] Sent: Monday, March 26, 2012 8:15 AM To: freebsd-drivers@freebsd.org Cc: Yong Fan; drivers@FreeBSD.org Subject: Re: operate file in kernel space On Sunday, March 25, 2012 10:41:09 pm Yong Fan wrote: > Hi all, > > I want to operate file in kernel space. > At present, I have found the following kernel routines, which operate fil= e: > Kern_open(), kern_close(), kern_readv() and kern_writev(). > Now, I have some doubt about these routines? > 1 kern_open() doesn't return a file handle or file pointer? > As we know, filp_open(), which is a Linux kernel routine, returns a file pointer. > ZwCreateFile(), which is a Windows kernel routine, returns a file handle. > > 2 how can I "seek" a file in kernel space? > The function of "seek" routine is similar with generic_file_llseek()(Linu= x) or ZwSetInformationFile()(windows). file descriptors in FreeBSD are generally tied to a file descriptor table (= so a process). What you can do is locate a vnode directly (e.g. using namei()= to do a pathname lookup) and then use vn_rdwr() to access the data in the file= . vn_rdwr() accepts a uio and you would manage your own "seek" location and t= hat gets set in the uio_offset of the uio you pass to vn_rdwr(). -- John Baldwin The information and any attached documents contained in this message may be confidential and/or legally privileged. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, dissemination, or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender immediately by return e-mail and destroy all copies of the original message. From owner-freebsd-drivers@FreeBSD.ORG Tue Mar 27 02:01:33 2012 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10BC1106564A; Tue, 27 Mar 2012 02:01:33 +0000 (UTC) (envelope-from yong.fan@exar.com) Received: from smtp1.exar.com (webmail.exar.com [204.154.183.83]) by mx1.freebsd.org (Postfix) with ESMTP id E517A8FC0A; Tue, 27 Mar 2012 02:01:32 +0000 (UTC) Received: from HZU1EXCH02.hq.exar.com (172.18.10.52) by FRE1-CAS.hq.exar.com (10.127.1.162) with Microsoft SMTP Server (TLS) id 8.1.436.0; Mon, 26 Mar 2012 19:01:32 -0700 Received: from HZU1EXCH02.hq.exar.com ([fe80::5528:f080:2385:1c90]) by HZU1EXCH02.hq.exar.com ([fe80::5528:f080:2385:1c90%13]) with mapi; Tue, 27 Mar 2012 10:01:28 +0800 From: Yong Fan To: John Baldwin , "freebsd-drivers@freebsd.org" Date: Tue, 27 Mar 2012 10:01:27 +0800 Thread-Topic: operate file in kernel space Thread-Index: Ac0LX3jHaefjAwZ+TeOKy2arMzJcxwAXdtzg Message-ID: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFCAA@HZU1EXCH02.hq.exar.com> References: <88AB8EB2D3F1D249AE07FAFFF17A396F0384CEFB5B@HZU1EXCH02.hq.exar.com> <201203261014.30542.jhb@freebsd.org> In-Reply-To: <201203261014.30542.jhb@freebsd.org> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, zh-CN Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "drivers@FreeBSD.org" Subject: RE: operate file in kernel space X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Mar 2012 02:01:33 -0000 Thanks your warm reply. I will have a try. Yongfan Thanks -----Original Message----- From: John Baldwin [mailto:jhb@freebsd.org] Sent: Monday, March 26, 2012 8:15 AM To: freebsd-drivers@freebsd.org Cc: Yong Fan; drivers@FreeBSD.org Subject: Re: operate file in kernel space On Sunday, March 25, 2012 10:41:09 pm Yong Fan wrote: > Hi all, > > I want to operate file in kernel space. > At present, I have found the following kernel routines, which operate fil= e: > Kern_open(), kern_close(), kern_readv() and kern_writev(). > Now, I have some doubt about these routines? > 1 kern_open() doesn't return a file handle or file pointer? > As we know, filp_open(), which is a Linux kernel routine, returns a file pointer. > ZwCreateFile(), which is a Windows kernel routine, returns a file handle. > > 2 how can I "seek" a file in kernel space? > The function of "seek" routine is similar with generic_file_llseek()(Linu= x) or ZwSetInformationFile()(windows). file descriptors in FreeBSD are generally tied to a file descriptor table (= so a process). What you can do is locate a vnode directly (e.g. using namei()= to do a pathname lookup) and then use vn_rdwr() to access the data in the file= . vn_rdwr() accepts a uio and you would manage your own "seek" location and t= hat gets set in the uio_offset of the uio you pass to vn_rdwr(). -- John Baldwin The information and any attached documents contained in this message may be confidential and/or legally privileged. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, dissemination, or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender immediately by return e-mail and destroy all copies of the original message.