Subject: RE: Kernel API question 2
To: None <>
From: Filka Michal <>
List: tech-kern
Date: 03/24/2006 10:42:46
Yes, this seems like thing I was looking for.=20

I have one more question. The last parameter of NDINIT is described as
"the calling process.". However, if I call it from my driver I needn't
to be in any process context ... So, is NULL allowed or should I use any
"kernel process identifier"?

Michal Filka

> I need to upload a firmware into a FPGA and I don't now if it is
> allowed to directly access files in NetBSD.

Others have pointed towards firmload(9) in -current.  But it's possible
to access files directly in older kernels too; you just have to do it
"by hand".  Here, for example, is a routine I once wrote (for a much
older OS version) to dump a debugging buffer to a file.  I can't
imagine it would be much harder to do something similar for read.  (My
use of IO_SYNC|IO_DSYNC was because this was known to be happening just
before a panic, and I wanted to have at least a fighting chance of the
data being there on reboot.)

static void save_buf_to_file(void)
 struct nameidata nd;
 int e;
 struct vnode *vp;
 struct uio uio;
 struct iovec iov;
 struct vattr vattr;

 e =3D vn_open(&nd,FREAD|FWRITE,0600);
 if (e)
  { printf("can't save buf: vn_open error %d\n",e);
 vp =3D nd.ni_vp;
 iov.iov_base =3D &dbgbuf[0];
 iov.iov_len =3D dbgptr;
 uio.uio_iov =3D &iov;
 uio.uio_offset =3D 0;
 uio.uio_segflg =3D UIO_SYSSPACE;
 uio.uio_rw =3D UIO_WRITE;
 uio.uio_resid =3D dbgptr;
 uio.uio_iovcnt =3D 1;
 uio.uio_procp =3D 0;
 e =3D VOP_WRITE(vp,&uio,IO_SYNC|IO_DSYNC,initproc->p_ucred);
 if (e)
  { printf("can't save buf: VOP_WRITE error %d\n",e);
 vattr.va_size =3D dbgptr;
 e =3D VOP_SETATTR(vp,&vattr,initproc->p_ucred,initproc);
 if (e)
  { printf("setting size: VOP_SETATTR error %d\n",e);

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B