kernel里如何打开文件并打印出error

来源:互联网 发布:淘宝家具安装价格 编辑:程序博客网 时间:2024/05/22 13:13

 

 

static void * open_image(char *filename)
{
 struct file *fp;
 fp = filp_open(filename, O_RDONLY, 0);
 //fp = open_namei(AT_FDCWD, filename, O_RD, 0);
 /*
  * 2.6.11 (FC4) supports filp_open() but later revs don't?
  * Alternative:
  * fp = open_namei(AT_FDCWD, filename, O_RD, 0);                      //这里打开是否成功用IS_ERR来判断
  * ???
  */
 
  if (IS_ERR(fp)){
   printk("cyx dhdadpter open_image PTR_ERR(fp)=%d\n",PTR_ERR(fp));     //如果失败,可用PTR_ERR来打印error no
  fp = NULL;
  }
 

  return fp;
}

 

static void close_image(void *image)
{
 if (image)
  filp_close((struct file *)image, NULL);
}

0 0
原创粉丝点击