文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>android启动时如何使用loop设备

android启动时如何使用loop设备

时间:2009-04-27  来源:zqqa

如果在android启动时要加载一个压缩的文件系统镜像或者一个ext3的文件系统镜像,不可避免的要使用loop设备,可是android本省的init没有提供losetup功能,而且其mount功能中也没有loop设备相关处理,因此要自己动手添加一个losetup功能。 要修改的代码在 system/core/init目录下。   keywords.h中添加int do_losetup(int nargs, char **args);和 KEYWORD(losetup,     COMMAND, 2, do_losetup)两行。   parser.c中的lookup_keyword函数case 'l'部分添加一行 if (!strcmp(s, "osetup")) return K_losetup;   在builtins.c中添加do_losetup函数和setloop函数。   int do_losetup(int nargs, char **args) {  /* max 2 args,  no option*/
    if (nargs != 3)
        return -1;
 if (setloop(args[1], args[2], 0) < 0)
  return -2;
 return 0;
}
static int setloop(char *device, const char *file, unsigned long long offset)
{
 bb_loop_info loopinfo;
 struct stat statbuf;
 int dfd, ffd, mode, rc = -1;
 /* Open the file. */
 mode = O_RDONLY;
 ffd = open(file, mode);
 if (ffd < 0)
  return -errno;
 /* Ran out of block devices, return failure.  */
 if (stat(device, &statbuf) || !S_ISBLK(statbuf.st_mode)) {
  return -errno;
  }
 /* Open the sucker and check its loopiness.  */
 dfd = open(device, mode);
 if (dfd < 0)
  return -errno;
 rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo);  /* If device is free, claim it.  */
 if (rc && errno == ENXIO) {
  memset(&loopinfo, 0, sizeof(loopinfo));
  strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE);
  loopinfo.lo_offset = offset;
  /* Associate free loop device with file.  */
  if (!ioctl(dfd, LOOP_SET_FD, ffd)) {
   if (!ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo))
    rc = 0;
   else
    ioctl(dfd, LOOP_CLR_FD, 0);
  }
    }
 else
    return -errno;
 close(dfd);
 close(ffd);
 return rc;
}
重新编译,现在可以在init.rc中使用losetup功能。
相关阅读 更多 +
排行榜 更多 +
小蚂蚁供应链

小蚂蚁供应链

购物比价 下载
家链医疗

家链医疗

健康医疗 下载
中国象棋对弈打谱

中国象棋对弈打谱

动作格斗 下载