Opening files in Kernel Mode: help

Ashwin Chandra ashcs at ucla.edu
Sun Feb 6 21:33:13 PST 2005


So this is the code I got from help from you hackers out there and templates in the /kern library. This compiles but causes a kernel panic. I was wondering if any of you knew why this was happening and if I am calling all the virtual node functions correctly?
 

***********************CODE BELOW************************

  register struct proc *p;
  struct nameidata nd;
  int flags = FWRITE | O_CREAT;
  struct ucred *uc;
  static struct   ucred *acctcred;
  char data[1000];

  acctcred = crhold(curthread->td_ucred);
  uc = crhold(acctcred);

  NDINIT(&nd, CREATE, FOLLOW, UIO_SYSSPACE, "/home/achandra/LOG", curthread);
  vn_open(&nd, &flags, 0,-1);
  NDFREE(&nd, NDF_ONLY_PNBUF);
  vref(nd.ni_vp);

  VOP_LEASE(nd.ni_vp, curthread, uc, LEASE_WRITE);

 sprintf(data, "%s", "asdsada");

  vn_rdwr(UIO_WRITE, nd.ni_vp, (caddr_t)data, strlen(data),
          (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, uc, NOCRED,
          (int *)0, curthread);

  vrele(nd.ni_vp);

  crfree(uc);
  vn_close(nd.ni_vp, flags, curthread->td_ucred, curthread);



More information about the freebsd-hackers mailing list