Exemple #1
0
int32_t ext4_fill_file(const struct ext4_super_block *sb, const struct ext4_extent *ext, size_t size, uint8_t *buf)
{
  int32_t blk_sz = 0;
  __le64 offset = 0;
  int32_t ret = 0;

  ret = ext4_fill_blk_sz(sb, &blk_sz);
  if (ret != 0) {
    return -1;
  }

  offset = (((__le64)ext->ee_start_hi << 32) | (__le64)ext->ee_start_lo) * blk_sz;

  ret = io_fseek(offset);
  if (ret != 0) {
    return -1;
  }

  ret = io_fread((uint8_t *)buf, size);
  if (ret != 0) {
    return -1;
  }

  return 0;
}
Exemple #2
0
/*
 * Function Definition
 */
int32_t fat_fill_file(const struct fat_super_block *sb, int32_t cluster, size_t size, uint8_t *buf)
{
  int32_t sector = 0;
  int32_t offset = 0;
  int32_t ret = 0;

  ret = fat_fill_clus2sec(sb, cluster, &sector);
  if (ret != 0) {
    return -1;
  }

  offset = sector * (int32_t)GET_UNALIGNED_LE16(sb->bs.sector_size);

  ret = io_fseek(offset);
  if (ret != 0) {
    return -1;
  }

  ret = io_fread(buf, size);
  if (ret != 0) {
    return -1;
  }

  return 0;
}
Exemple #3
0
int packOpen(const char* filename)
{
	packItem* temp = NULL;
	temp = fileItem;
	if(fileItem==NULL) return -1;
	while( strcmp(filename,(char*)temp->date.name) ) {
		temp = temp->next;
		if(temp==NULL)
			return -1; }
	io_fseek(fd,temp->date.offset,IO_SEEK_SET);
	return fd;
}
Exemple #4
0
int packOpenAsync(const char* filename)
{
	int fd = -1;
	packItem* temp = NULL;
	temp = fileItem;
	if(fileItem==NULL) return -1;
	while( strcmp(filename,(char*)temp->date.name) ) {
		temp = temp->next;
		if(temp==NULL)
			return -1; }
	fd = io_fopen(name,IO_RDONLY);
	io_fseek(fd,temp->date.offset,IO_SEEK_SET);
	return fd;
}
Exemple #5
0
int packInit(const char* filename)
{
	int i = 0;
	packItem* temp = NULL;
	packCleanRes();
	fd = io_fopen(filename,IO_RDONLY);
	if(fd <= 0)
		return -1;
	fileInfo = (packInfo*) safe_malloc (sizeof(packInfo));
	io_fseek(fd,(int)(-sizeof(packInfo)),IO_SEEK_END);
	io_fread(fileInfo,sizeof(packInfo),1,fd);
	if(fileInfo->VER!=0x01000000) {	// 如果不是pack压缩包则取消读取
		packCleanRes();
		return -1; }
	io_fseek(fd,(int)(-(sizeof(packInfo)+sizeof(packDate)*fileInfo->nums)),IO_SEEK_END);
	for(i=0;i<fileInfo->nums;i++)
	{
		if(fileItem==NULL) {
			fileItem = (packItem*) safe_malloc (sizeof(packItem));
			temp = fileItem;
			io_fread(&temp->date,sizeof(packDate),1,fd);
			temp->next = NULL; }
		if((i!=0) && (temp->next==NULL)) {
			temp->next = (packItem*) safe_malloc (sizeof(packItem));
			temp = temp->next;
			io_fread(&temp->date,sizeof(packDate),1,fd);
			temp->next = NULL; }
	}
	if(name==NULL) {
		name = (char*) safe_malloc (strlen(filename));
		strcpy(name,filename); }
	//rewind((FILE*)fd);
	io_fseek(fd,0,IO_SEEK_SET);
	//printf("first fd address: 0x%x\n",fd);
	return fd;
}
Exemple #6
0
int32_t fat_fill_sb(struct fat_super_block *sb)
{
  int32_t offset = 0;
  size_t sz = 0;
  int32_t is_fat32_fs = 0;
  int32_t ret = 0;

  /*
   * Fill in FAT boot sector
   */
  offset = 0;
  ret = io_fseek(offset);
  if (ret != 0) {
    return -1;
  }

  sz = sizeof(struct fat_boot_sector);
  ret = io_fread((uint8_t *)&sb->bs, sz);
  if (ret != 0) {
    memset((void *)&sb->bs, 0, sz);
    return -1;
  }

  if (!fat_is_valid_sec_sz((uint8_t *)sb->bs.sector_size, 2)
      || !IS_POWER_OF_2(sb->bs.sec_per_clus)
      || sb->bs.reserved == 0
      || sb->bs.fats == 0
      || !fat_is_valid_media((uint32_t)sb->bs.media)) {
    return -1;
  }

  ret = fat_is_fat32_fs((const struct fat_super_block *)sb, &is_fat32_fs);
  if (ret != 0) {
    return -1;
  }

  /*
   * Fill in FAT boot bsx
   */
  if (is_fat32_fs) {
    offset = FAT32_BSX_OFFSET;
  } else {
    offset = FAT16_BSX_OFFSET;
  }

  ret = io_fseek(offset);
  if (ret != 0) {
    return -1;
  }

  sz = sizeof(struct fat_boot_bsx);
  ret = io_fread((uint8_t *)&sb->bb, sz);
  if (ret != 0) {
    memset((void *)&sb->bb, 0, sz);
    return -1;
  }

  if (is_fat32_fs) {
    /*
     * Fill in FAT32 boot fsinfo
     */
    offset = sb->bs.info_sector == 0 ? GET_UNALIGNED_LE16(sb->bs.sector_size) : sb->bs.info_sector * GET_UNALIGNED_LE16(sb->bs.sector_size);

    ret = io_fseek(offset);
    if (ret != 0) {
      return -1;
    }

    sz = sizeof(struct fat_boot_fsinfo);
    ret = io_fread((uint8_t *)&sb->bf, sz);
    if (ret != 0) {
      memset((void *)&sb->bf, 0, sz);
      return -1;
    }

    if (sb->bf.signature1 != FAT_FSINFO_SIG1 || sb->bf.signature2 != FAT_FSINFO_SIG2) {
      return -1;
    }
  }

  return 0;
}