Ejemplo n.º 1
0
int		check_square(char **src, int y, int x)
{
  char		*zero;
  int		inc;

  if ((zero = malloc(sizeof(char) * 20)) == NULL)
    return (error_basic(3));
  zero = fill_zero(zero);
  inc = 0;
  while (inc < 9)
    {
      if ((square_by_square(src, zero, y, x)) == -1)
        return (-1);
      zero = fill_zero(zero);
      x += 3;
      inc++;
      if (x == 9)
        {
          y += 3;
          x = 0;
        }
    }
  free(zero);
  return (0);
}
Ejemplo n.º 2
0
static int punch_hole(struct inode *inode, loff_t offset, loff_t len)
{
	pgoff_t pg_start, pg_end;
	loff_t off_start, off_end;
	int ret = 0;

	if (!S_ISREG(inode->i_mode))
		return -EOPNOTSUPP;

	if (f2fs_has_inline_data(inode)) {
		ret = f2fs_convert_inline_inode(inode);
		if (ret)
			return ret;
	}

	pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT;
	pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT;

	off_start = offset & (PAGE_CACHE_SIZE - 1);
	off_end = (offset + len) & (PAGE_CACHE_SIZE - 1);

	if (pg_start == pg_end) {
		ret = fill_zero(inode, pg_start, off_start,
						off_end - off_start);
		if (ret)
			return ret;
	} else {
		if (off_start) {
			ret = fill_zero(inode, pg_start++, off_start,
						PAGE_CACHE_SIZE - off_start);
			if (ret)
				return ret;
		}
		if (off_end) {
			ret = fill_zero(inode, pg_end, 0, off_end);
			if (ret)
				return ret;
		}

		if (pg_start < pg_end) {
			struct address_space *mapping = inode->i_mapping;
			loff_t blk_start, blk_end;
			struct f2fs_sb_info *sbi = F2FS_I_SB(inode);

			f2fs_balance_fs(sbi);

			blk_start = pg_start << PAGE_CACHE_SHIFT;
			blk_end = pg_end << PAGE_CACHE_SHIFT;
			truncate_inode_pages_range(mapping, blk_start,
					blk_end - 1);

			f2fs_lock_op(sbi);
			ret = truncate_hole(inode, pg_start, pg_end);
			f2fs_unlock_op(sbi);
		}
	}

	return ret;
}
Ejemplo n.º 3
0
void HomeScene::setCatObject(PRODUCTS product,int id){
    /* rerender cat object graphics and set event listener*/
    _cat_objects[static_cast<int>(product)] = dynamic_cast<ui::Button*>(_home_bg->getChildByTag( 100 + static_cast<int>(product) ));
    
    _cat_objects[static_cast<int>(product)]->loadTextures("products/"+ fill_zero(id) + ".png",
                                                          "products/"+ fill_zero(id) + ".png" );
    
}
EFI_STATUS erase_blocks(EFI_HANDLE handle, EFI_BLOCK_IO *bio, UINT64 start, UINT64 end)
{
	EFI_STATUS ret;

	ret = storage_erase_blocks(handle, bio, start, end);
	if (ret == EFI_SUCCESS)
		return ret;

	debug(L"Fallbacking to filling with zeros");
	return fill_zero(bio, start, end);
}
Ejemplo n.º 5
0
static int punch_hole(struct inode *inode, loff_t offset, loff_t len, int mode)
{
	pgoff_t pg_start, pg_end;
	loff_t off_start, off_end;
	loff_t blk_start, blk_end;
	int ret = 0, ilock;
	struct hmfs_sb_info *sbi = HMFS_SB(inode->i_sb);

	pg_start = ((u64) offset) >> HMFS_PAGE_SIZE_BITS;
	pg_end = ((u64) offset + len) >> HMFS_PAGE_SIZE_BITS;
	off_start = offset & (HMFS_PAGE_SIZE - 1);
	off_end = (offset + len) & (HMFS_PAGE_SIZE - 1);

	if (pg_start == pg_end) {
		fill_zero(inode, pg_start, off_start, off_end - off_start);
	} else {
		if (off_start)
			fill_zero(inode, pg_start++, off_start,
				  HMFS_PAGE_SIZE - off_start);
		if (off_end)
			fill_zero(inode, pg_end, 0, off_end);

		if (pg_start < pg_end) {
			blk_start = pg_start << HMFS_PAGE_SIZE_BITS;
			blk_end = pg_end << HMFS_PAGE_SIZE_BITS;
			//FIXME: need this in mmap?
			//truncate_inode_pages_range(inode,blk_start,blk_end);

			ilock = mutex_lock_op(sbi);
			ret = truncate_hole(inode, pg_start, pg_end);
			mutex_unlock_op(sbi, ilock);
		}
	}

	if (!(mode & FALLOC_FL_KEEP_SIZE)
	    && i_size_read(inode) <= (offset + len)) {
		mark_size_dirty(inode, offset + len);
	}

	return ret;
}
Ejemplo n.º 6
0
int		verif(char **src)
{
  char		*zero;

  if ((zero = malloc(sizeof(char) * 20)) == NULL)
    return (error_basic(3));
  zero = fill_zero(zero);
  if ((check_line(src, zero, 1, 1) == -1)
      || (check_col(src, zero, 1, 2) == -1))
    return (-1);
  free(zero);
  return (0);
}
Ejemplo n.º 7
0
static char	*add_precision(t_format format, char *type, int *prcsn)
{
	char *str;

	str = NULL;
	if (format.precision == NULL)
		return (type);
	else if (format.precision[0] >= '0' && format.precision[0] <= '9')
		*prcsn = ft_atoi(format.precision) - ft_strlen(type);
	else
		return (type);
	if (type != NULL && (type[0] == '-' || type[0] == '+'))
		(*prcsn)++;
	str = fill_zero(format, type, *prcsn);
	if (str != NULL)
		return (str);
	return (type);
}
Ejemplo n.º 8
0
int		check_line(char **src, char *zero, int y, int x)
{
  int		inc;

  inc = 0;
  while (y < 10)
    {
      while (x < 20)
        {
          if ((src[y][x] >= '1') && (src[y][x] <= '9'))
            {
              if ((check_double(src[y][x], zero)) == -1)
                return (-1);
              zero[inc++] = src[y][x];
            }
            x++;
        }
      x = 0;
      inc = 0;
      zero = fill_zero(zero);
      y++;
    }
  return (0);
}
Ejemplo n.º 9
0
/*
 *  ======== process_image ========
 */
static int process_image()
{
    int i;
    struct Elf32_Ehdr *hdr;
    struct Elf32_Shdr *shdr, *s, *s1, *s2;
    struct Elf32_Shdr vers_shdr;
    struct Elf32_Phdr *phdr, *p;
    struct Elf32_Sym *sym, *sm;
    int co = 0;
    int scnt = 0;
    int len = 0;

    printf("\nStart combining images....\n\n");

    /* copy the header */
    if (core0_info.e_hdr->e_entry != core1_info.e_hdr->e_entry) {
        printf("entry points are different in both the images.\n");
        return -1;
    }
    hdr = core0_info.e_hdr;
    memcpy(cores_info.e_hdr, core0_info.e_hdr, sizeof(struct Elf32_Ehdr));
    cores_info.e_hdr->e_phnum = core0_info.e_hdr->e_phnum +
                                    core1_info.e_hdr->e_phnum;
    fwrite(cores_info.e_hdr, 1, sizeof(struct Elf32_Ehdr), cores_info.fp);
    co += sizeof(struct Elf32_Ehdr);

    /* process the program data of Core0 ELF file */
    printf("Processing Core0 program data sections....\n");
    p = core0_info.p_hdrs;
    phdr = cores_info.p_hdrs;
    for (i = 0; i < core0_info.e_hdr->e_phnum; i++, p++, phdr++) {
        DEBUG_PRINT("Program Section #%d\n", i);
        DEBUG_PRINT("  input ");
        print_proghdr_info(p);
        memcpy((void *)phdr, p, sizeof(struct Elf32_Phdr));

        /* copy the program data only if file size is non-zero */
        co += fill_zero(co, p->p_align);
        if (p->p_filesz) {
            if (core0_info.data + p->p_offset == core0_info.rsc_table) {
                fixup_rsc_table(core0_info.data + p->p_offset);
            }
            fwrite(core0_info.data + p->p_offset, 1, p->p_filesz,
                                                            cores_info.fp);
        }
        phdr->p_offset = co;
        co += p->p_filesz;
        DEBUG_PRINT("  output");
        print_proghdr_info(phdr);
        DEBUG_PRINT("  Phdr_offset = 0x%x co = 0x%x\n", phdr->p_offset, co);
    }
    printf("Core0 program data processed for %d sections.\n", i);

    /* process the program data of Core1 ELF file */
    printf("\nProcessing Core1 program data sections....\n");
    p = core1_info.p_hdrs;
    for (i = 0; i < core1_info.e_hdr->e_phnum; i++, p++, phdr++) {
        DEBUG_PRINT("Program Section #%d\n", i);
        DEBUG_PRINT("  input ");
        print_proghdr_info(p);
        memcpy((void *)phdr, p, sizeof(struct Elf32_Phdr));

        /* copy the program data only if file size is non-zero */
        co += fill_zero(co, p->p_align);
        if (p->p_filesz) {
            fwrite(core1_info.data + p->p_offset, 1, p->p_filesz,
                                                            cores_info.fp);
        }
        phdr->p_offset = co;
        co += p->p_filesz;
        DEBUG_PRINT("  output");
        print_proghdr_info(phdr);
        DEBUG_PRINT("  Phdr_offset = 0x%x co = 0x%x\n", phdr->p_offset, co);
    }
    cores_info.last_phoffset = co;
    printf("Core1 program data processed for %d sections.\n", i);

    printf("\nProcessing Core0 section data....\n");
    /* process the section data of Core0 ELF file */
    shdr = cores_info.s_hdrs;
    s = core0_info.s_hdrs;
    /* Skip the last 5 sections, these need to be combined */
    /*
     * TODO: Add check to ensure if these sections are different between the
     *       two images
     */
    for (i = 0; i < core0_info.e_hdr->e_shnum - 5; i++, s++) {
        /* skip the ".version" section, will write at the end */
        if (!strcmp(core0_info.shstrtab + s->sh_name, ELF_SHDR_VERSION)) {
            memcpy(&vers_shdr, s, sizeof(struct Elf32_Shdr));
            len = strlen(core0_info.shstrtab + s->sh_name);
            DEBUG_PRINT("[%d: %s] section strlen = %d\n",
                            i, (char *)((u32)core0_info.shstrtab + s->sh_name),
                            len);
            len = strlen(core0_info.version);
            memcpy(cores_info.version + cores_info.version_size,
                        core0_info.version, len);
            cores_info.version_size += len;
            DEBUG_PRINT("  skip processing of this section, size = %d\n",
                            s->sh_size);
            continue;
        }

        memcpy((void *)shdr, s, sizeof(struct Elf32_Shdr));
        scnt++;

        /* copy the section name into the new section string table */
        shdr->sh_name = cores_info.shstrtab_size; /* doesn't matter */
        len = strlen(core0_info.shstrtab + s->sh_name);
        DEBUG_PRINT("[%d: %s] section strlen = %d\n",
                        i, (char *)((u32)core0_info.shstrtab + s->sh_name), len);
        memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                    core0_info.shstrtab + s->sh_name, len + 1);
        DEBUG_PRINT("  check copied name [%s] new offset = %d \n",
                (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
                cores_info.shstrtab_size);
        cores_info.shstrtab_size += (len + 1);

        /* process the ".stack" section specially - no offset adjustment */
        if (!strcmp(core0_info.shstrtab + s->sh_name, ELF_SHDR_STACK)) {
            DEBUG_PRINT("  input ");
            print_secthdr_info(s);
            DEBUG_PRINT("  output");
            print_secthdr_info(shdr);
            shdr++;
            continue;
        }

        if (s->sh_offset >= core0_info.last_phoffset) {
            if ((s->sh_type == SHT_PROGBITS && s->sh_size) ||
                 (s->sh_type == SHT_ARMATTRIBUTES) ||
                 (s->sh_type == SHT_STRTAB)) {
                fwrite(core0_info.data + s->sh_offset, 1, s->sh_size,
                                                            cores_info.fp);
                shdr->sh_offset = co;
                co += s->sh_size;
            }
            else if (s->sh_type == SHT_SYMTAB) {
                co += fill_zero(co, 4);
                fwrite(core0_info.data + s->sh_offset, 1, s->sh_size,
                                                            cores_info.fp);
                shdr->sh_offset = co;
                co += s->sh_size;
            }
            else if (s->sh_type == SHT_NOBITS) {
                DEBUG_PRINT("    offsets = 0x%x 0x%x 0x%x\n",
                            cores_info.last_phoffset,
                            core0_info.last_phoffset, s->sh_offset);
                shdr->sh_offset = cores_info.last_phoffset
                                    - core0_info.last_phoffset + s->sh_offset;
            }
            DEBUG_PRINT("    sh_offset = 0x%x co = 0x%x\n", shdr->sh_offset, co);
        }

        DEBUG_PRINT("  input ");
        print_secthdr_info(s);
        DEBUG_PRINT("  output");
        print_secthdr_info(shdr);
        shdr++;
    }
    s1 = s;
    printf("Core0 section data processed for %d sections.\n", scnt);

    printf("\nProcessing Core1 section data....\n");
    /* process the section data of Core1 ELF file */
    s = core1_info.s_hdrs;

    /* Skip the last 5 sections, these need to be combined */
    /*
     * TODO: Add check to ensure if these sections are different between the
     *       two images
     */
    for (i = 0; i < core1_info.e_hdr->e_shnum - 5; i++, s++) {
        /* skip the first null section */
        if (s->sh_type == SHT_NULL) {
            continue;
        }

        /* skip the ".version" section, will write at the end */
        if (!strcmp(core1_info.shstrtab + s->sh_name, ELF_SHDR_VERSION)) {
            len = strlen(core1_info.shstrtab + s->sh_name);
            DEBUG_PRINT("[%d: %s] section strlen = %d\n",
                            i, (char *)((u32)core1_info.shstrtab + s->sh_name),
                            len);
            len = strlen(core1_info.version);
            memcpy(cores_info.version + cores_info.version_size,
                        core1_info.version, len);
            cores_info.version_size += len;
            DEBUG_PRINT("  skip processing of this section, size = %d\n",
                            s->sh_size);
            continue;
        }

        memcpy((void *)shdr, s, sizeof(struct Elf32_Shdr));
        scnt++;

        /* copy the section name into the new section string table */
        shdr->sh_name = cores_info.shstrtab_size;
        len = strlen(core1_info.shstrtab + s->sh_name);
        DEBUG_PRINT("[%d: %s] section strlen = %d\n", i,
                        (char *)((u32)core1_info.shstrtab + s->sh_name), len);
        memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                    core1_info.shstrtab + s->sh_name, len + 1);
        DEBUG_PRINT("  check copied name [%s] new offset = %d\n",
                (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
                cores_info.shstrtab_size);
        cores_info.shstrtab_size += (len + 1);

        /* process the ".stack" section specially - no offset adjustment */
        if (!strcmp(core1_info.shstrtab + s->sh_name, ELF_SHDR_STACK)) {
            DEBUG_PRINT("  input ");
            print_secthdr_info(s);
            DEBUG_PRINT("  output");
            print_secthdr_info(shdr);
            shdr++;
            continue;
        }

        if (s->sh_offset && s->sh_offset < core1_info.last_phoffset) {
            shdr->sh_offset = s->sh_offset - hdr->e_ehsize +
                                                    core0_info.last_phoffset;
        }
        else if (s->sh_offset >= core1_info.last_phoffset) {
            if ((s->sh_type == SHT_PROGBITS && s->sh_size) ||
                 (s->sh_type == SHT_ARMATTRIBUTES) ||
                 (s->sh_type == SHT_STRTAB)) {
                fwrite(core1_info.data + s->sh_offset, 1, s->sh_size,
                                                            cores_info.fp);
                shdr->sh_offset = co;
                co += s->sh_size;
            }
            else if (s->sh_type == SHT_SYMTAB) {
                co += fill_zero(co, 4);
                fwrite(core1_info.data + s->sh_offset, 1, s->sh_size,
                                                            cores_info.fp);
                shdr->sh_offset = co;
                co += s->sh_size;
            }
            else if (s->sh_type == SHT_NOBITS) {
                DEBUG_PRINT("    offsets = 0x%x 0x%x 0x%x\n",
                            cores_info.last_phoffset,
                            core1_info.last_phoffset, s->sh_offset);
                shdr->sh_offset = cores_info.last_phoffset
                                    - core1_info.last_phoffset + s->sh_offset;
            }
            DEBUG_PRINT("    sh_offset = 0x%x co = 0x%x\n", shdr->sh_offset, co);
        }

        DEBUG_PRINT("  input ");
        print_secthdr_info(s);
        DEBUG_PRINT("  output");
        print_secthdr_info(shdr);
        shdr++;
    }
    s2 = s;
    printf("Core1 section data processed for %d sections.\n", scnt);

    printf("\nWriting combined section data....\n");
    /* write the version section */
    if (cores_info.version_size) {
        DEBUG_PRINT("Process version section....\n");
        memcpy((void *)shdr, &vers_shdr, sizeof(struct Elf32_Shdr));
        scnt++;

        shdr->sh_name = cores_info.shstrtab_size;
        len = strlen(core0_info.shstrtab + vers_shdr.sh_name);
        DEBUG_PRINT("[%d: %s] section strlen = %d\n", scnt - 1,
                (char *)core0_info.shstrtab + vers_shdr.sh_name, len);
        memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                    core0_info.shstrtab + vers_shdr.sh_name, len + 1);
        DEBUG_PRINT("  check copied name [%s] new offset = %d\n",
            (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
            cores_info.shstrtab_size);
        cores_info.shstrtab_size += (len + 1);

        *(char *)(cores_info.version + cores_info.version_size) = 0;
        cores_info.version_size++;
        fwrite(cores_info.version, 1, cores_info.version_size, cores_info.fp);
        shdr->sh_offset = co;
        shdr->sh_size = cores_info.version_size;
        co += cores_info.version_size;
        shdr++;
        DEBUG_PRINT("  co = 0x%x\n", co);
    }
    printf("Version section processed.\n");

    /* write the ARM attributes section */
    if ((s1->sh_type == SHT_ARMATTRIBUTES) &&
        (s2->sh_type == SHT_ARMATTRIBUTES)/* && (s1->sh_size == s2->sh_size) &&
        (!memcmp(core0_info.data + s1->sh_offset,
                    core1_info.data + s2->sh_offset, s1->sh_size)) &&
        (!strcmp(core0_info.shstrtab + s1->sh_name,
                    core1_info.shstrtab + s2->sh_name))*/) {
        DEBUG_PRINT("\nProcess ARM attributes section....\n");
        memcpy((void *)shdr, s1, sizeof(struct Elf32_Shdr));
        scnt++;

        shdr->sh_name = cores_info.shstrtab_size;
        len = strlen(core0_info.shstrtab + s1->sh_name);
        DEBUG_PRINT("[%d: %s] section strlen = %d\n", scnt - 1,
                (char *)core0_info.shstrtab + s1->sh_name, len);
        memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                    core0_info.shstrtab + s1->sh_name, len + 1);
        DEBUG_PRINT("  check copied name [%s] new offset = %d \n",
            (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
            cores_info.shstrtab_size);
        cores_info.shstrtab_size += (len + 1);

        fwrite(core0_info.data + s1->sh_offset, 1, s1->sh_size,
                                                    cores_info.fp);
        shdr->sh_offset = co;
        co += s1->sh_size;
        shdr++;
        DEBUG_PRINT("  co = 0x%x\n", co);
    }
    else {
        printf("ARM attributes section is mismatched between the two ELF"
                "images.\n");
        return -1;
    }
    printf("ARM attributes section processed.\n");

    /* write the symtab section */
    DEBUG_PRINT("\nProcess Symbol Table section....\n");
    s1++; s2++;
    if (s1->sh_type != SHT_SYMTAB && s2->sh_type != SHT_SYMTAB &&
            (!strcmp(core0_info.shstrtab + s1->sh_name,
                        core1_info.shstrtab + s2->sh_name))) {
        printf("Expected symbol table section not found in the two ELF "
                "images.\n");
        return -1;
    }

    memcpy((void *)shdr, s1, sizeof(struct Elf32_Shdr));
    scnt++;
    co += fill_zero(co, 4);
    shdr->sh_offset = co;
    shdr->sh_name = cores_info.shstrtab_size;
    shdr->sh_link = scnt + 1;
    len = strlen(core0_info.shstrtab + s1->sh_name);
    DEBUG_PRINT("[%d: %s] section strlen = %d\n", scnt - 1,
            (char *)core0_info.shstrtab + s1->sh_name, len);
    memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                core0_info.shstrtab + s1->sh_name, len + 1);
    DEBUG_PRINT("  check copied name [%s] new offset = %d\n",
        (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
        cores_info.shstrtab_size);
    cores_info.shstrtab_size += (len + 1);

    /* combine the symtab section */
    DEBUG_PRINT("  Processing Core0 symbols....\n");
    sym = cores_info.symtab;
    sm = (struct Elf32_Sym *) (core0_info.data + s1->sh_offset);
    for (i = 0; i < s1->sh_size/s1->sh_entsize; i++, sm++) {
        memcpy(sym, sm, sizeof(struct Elf32_Sym));

        /* copy the symbol name into the new string table */
        sym->st_name = cores_info.strtab_size;
        len = strlen(core0_info.strtab + sm->st_name);
        DEBUG_PRINT("    [%d] symbol string length = %d new = %d\n", i, len,
                                                cores_info.strtab_size);
        memcpy(cores_info.strtab + cores_info.strtab_size,
                    core0_info.strtab + sm->st_name, len + 1);
        cores_info.strtab_size += (len + 1);

        DEBUG_PRINT("      input ");
        print_symbol_info(sm);
        DEBUG_PRINT("      output");
        print_symbol_info(sym);
        sym++;
    }
    DEBUG_PRINT("  Core0 symbols processed.\n");
    DEBUG_PRINT("  Processing Core1 symbols\n");
    sm = (struct Elf32_Sym *) (core1_info.data + s2->sh_offset);
    for (i = 0; i < s2->sh_size/s2->sh_entsize; i++, sm++) {
        if (sm->st_shndx == STN_UNDEF) {
            continue;
        }

        memcpy(sym, sm, sizeof(struct Elf32_Sym));

        /* copy the symbol name into the new string table */
        sym->st_name = cores_info.strtab_size;
        len = strlen(core1_info.strtab + sm->st_name);
        DEBUG_PRINT("    [%d] symbol string length = %d new = %d\n", i, len,
                                                cores_info.strtab_size);
        memcpy(cores_info.strtab + cores_info.strtab_size,
                    core1_info.strtab + sm->st_name, len + 1);
        cores_info.strtab_size += (len + 1);

        /* adjust the symbol section */
        if (sm->st_shndx < (core1_info.e_hdr->e_shnum - 5)) {
            sym->st_shndx += (core0_info.e_hdr->e_shnum - 5);
        }

        DEBUG_PRINT("      input ");
        print_symbol_info(sm);
        DEBUG_PRINT("      output");
        print_symbol_info(sym);
        shdr->sh_size += s2->sh_entsize;
        sym++;
    }
    DEBUG_PRINT("  Core1 symbols processed.\n");
    DEBUG_PRINT("  Writing symbols to file....\n");
    DEBUG_PRINT("    output strtab size = 0x%x scnt = %d\n",
                    cores_info.strtab_size, scnt);
    fwrite(cores_info.symtab, 1, shdr->sh_size, cores_info.fp);
    co += shdr->sh_size;
    shdr++;
    DEBUG_PRINT("    co = 0x%x\n", co);
    DEBUG_PRINT("  Symbols written.\n");
    printf("Symbol Table section processed.\n");

    /* write the TI section flags section */
    DEBUG_PRINT("\nProcess TI section flags section....\n");
    s1++; s2++;
    if ((s1->sh_type == SHT_PROGBITS) &&
        (s2->sh_type == SHT_PROGBITS) && (s1->sh_size == s2->sh_size) &&
        (!memcmp(core0_info.data + s1->sh_offset,
                    core1_info.data + s2->sh_offset, s1->sh_size)) &&
        (!strcmp(core0_info.shstrtab + s1->sh_name,
                    core1_info.shstrtab + s2->sh_name))) {
            memcpy((void *)shdr, s1, sizeof(struct Elf32_Shdr));
            scnt++;

            shdr->sh_name = cores_info.shstrtab_size;
            len = strlen(core0_info.shstrtab + s1->sh_name);
            DEBUG_PRINT("[%d: %s] section string length = %d\n",
                        scnt - 1, (char *)core0_info.shstrtab + s1->sh_name,
                                    len);
            memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                        core0_info.shstrtab + s1->sh_name, len + 1);
            DEBUG_PRINT("  check copied name [%s] new offset = %d \n",
                (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
                cores_info.shstrtab_size);
            cores_info.shstrtab_size += (len + 1);

            fwrite(core0_info.data + s1->sh_offset, 1, s1->sh_size,
                                                        cores_info.fp);
            shdr->sh_offset = co;
            co += s1->sh_size;
            shdr++;
            DEBUG_PRINT("  co = 0x%x\n", co);
    }
    else {
        printf("TI Section Flags section is mismatched between the two ELF"
                "images.\n");
        return -1;
    }
    printf("TI Section Flags section processed.\n");

    /* write the strtab section */
    DEBUG_PRINT("\nProcess String table section....\n");
    s1++; s2++;
    if ((s1->sh_type == SHT_STRTAB) && (s2->sh_type == SHT_STRTAB) &&
        (!strcmp(core0_info.shstrtab + s1->sh_name,
                    core1_info.shstrtab + s2->sh_name))) {
            memcpy((void *)shdr, s1, sizeof(struct Elf32_Shdr));
            scnt++;

            shdr->sh_name = cores_info.shstrtab_size;
            len = strlen(core0_info.shstrtab + s1->sh_name);
            DEBUG_PRINT("[%d: %s] section strlen = %d\n",
                scnt - 1, (char *)core0_info.shstrtab + s1->sh_name, len);
            memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                        core0_info.shstrtab + s1->sh_name, len + 1);
            DEBUG_PRINT("check copied name [%s] new offset = %d\n",
                (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
                cores_info.shstrtab_size);
            cores_info.shstrtab_size += (len + 1);

            fwrite(cores_info.strtab, 1, cores_info.strtab_size, cores_info.fp);
            shdr->sh_offset = co;
            shdr->sh_size = cores_info.strtab_size;
            co +=  cores_info.strtab_size;
            shdr++;
            DEBUG_PRINT("  co = 0x%x\n", co);
    }
    else {
        printf("String Table section is mismatched between the two ELF "
                "images.\n");
        return -1;
    }
    printf("String Table section processed.\n");

    /* write the shstrtab section */
    DEBUG_PRINT("\nProcess Section header string table section....\n");
    s1++; s2++;
    if ((s1->sh_type == SHT_STRTAB) && (s2->sh_type == SHT_STRTAB) &&
        (!strcmp(core0_info.shstrtab + s1->sh_name,
                    core1_info.shstrtab + s2->sh_name))) {
            memcpy((void *)shdr, s1, sizeof(struct Elf32_Shdr));
            scnt++;

            shdr->sh_name = cores_info.shstrtab_size;
            len = strlen(core0_info.shstrtab + s1->sh_name);
            DEBUG_PRINT("[%d: %s] section strlen = %d\n", scnt - 1,
               (char *)core0_info.shstrtab + s1->sh_name, len);
            memcpy(cores_info.shstrtab + cores_info.shstrtab_size,
                        core0_info.shstrtab + s1->sh_name, len + 1);
            DEBUG_PRINT("check copied name [%s] new offset = %d\n",
                (char *)((u32)cores_info.shstrtab + cores_info.shstrtab_size),
                cores_info.shstrtab_size);
            cores_info.shstrtab_size += (len + 1);

            fwrite(cores_info.shstrtab, 1, cores_info.shstrtab_size,
                                                                cores_info.fp);
            shdr->sh_offset = co;
            shdr->sh_size = cores_info.shstrtab_size;
            co +=  cores_info.shstrtab_size;
            DEBUG_PRINT("  co = 0x%x\n", co);
    }
    else {
        printf("String Table section is mismatched between the two ELF "
                "images.\n");
        return -1;
    }
    printf("Section Header string table processed.\n");
    printf("Combined sections data processed.\n");

    /* write the program headers */
    printf("\nWriting new program headers....");
    DEBUG_PRINT("\n  prev phoffset = 0x%x co = 0x%x\n",
                                                cores_info.e_hdr->e_phoff, co);
    cores_info.e_hdr->e_phoff = co;
    cores_info.e_hdr->e_shnum = scnt;
    cores_info.e_hdr->e_shstrndx = scnt - 1;
    fwrite(cores_info.p_hdrs, 1,
            cores_info.e_hdr->e_phnum * cores_info.e_hdr->e_phentsize,
            cores_info.fp);
    co += cores_info.e_hdr->e_phnum * cores_info.e_hdr->e_phentsize;
    printf("done.\n");

    /* write the section headers */
    printf("Writing new section headers....");
    DEBUG_PRINT("\n  prev shoffset = 0x%x co = 0x%x\n",
                                                cores_info.e_hdr->e_shoff, co);
    cores_info.e_hdr->e_shoff = co;
    fwrite(cores_info.s_hdrs, 1,
            cores_info.e_hdr->e_shnum * cores_info.e_hdr->e_shentsize,
            cores_info.fp);
    co += cores_info.e_hdr->e_shnum * cores_info.e_hdr->e_shentsize;
    printf("done.\n");

    /* rewrite the new ELF header */
    printf("Writing new ELF header....");
    fflush(cores_info.fp);
    rewind(cores_info.fp);
    fwrite(cores_info.e_hdr, 1, sizeof(struct Elf32_Ehdr), cores_info.fp);
    fflush(cores_info.fp);
    printf("done.\n");
    printf("\nCombined Output image created!\n");

    return 0;
}
Ejemplo n.º 10
0
static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
								int mode)
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
	struct address_space *mapping = inode->i_mapping;
	pgoff_t index, pg_start, pg_end;
	loff_t new_size = i_size_read(inode);
	loff_t off_start, off_end;
	int ret = 0;

	if (!S_ISREG(inode->i_mode))
		return -EINVAL;

	ret = inode_newsize_ok(inode, (len + offset));
	if (ret)
		return ret;

	f2fs_balance_fs(sbi);

	if (f2fs_has_inline_data(inode)) {
		ret = f2fs_convert_inline_inode(inode);
		if (ret)
			return ret;
	}

	ret = filemap_write_and_wait_range(mapping, offset, offset + len - 1);
	if (ret)
		return ret;

	truncate_pagecache_range(inode, offset, offset + len - 1);

	pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT;
	pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT;

	off_start = offset & (PAGE_CACHE_SIZE - 1);
	off_end = (offset + len) & (PAGE_CACHE_SIZE - 1);

	if (pg_start == pg_end) {
		ret = fill_zero(inode, pg_start, off_start,
						off_end - off_start);
		if (ret)
			return ret;

		if (offset + len > new_size)
			new_size = offset + len;
		new_size = max_t(loff_t, new_size, offset + len);
	} else {
		if (off_start) {
			ret = fill_zero(inode, pg_start++, off_start,
						PAGE_CACHE_SIZE - off_start);
			if (ret)
				return ret;

			new_size = max_t(loff_t, new_size,
						pg_start << PAGE_CACHE_SHIFT);
		}

		for (index = pg_start; index < pg_end; index++) {
			struct dnode_of_data dn;
			struct page *ipage;

			f2fs_lock_op(sbi);

			ipage = get_node_page(sbi, inode->i_ino);
			if (IS_ERR(ipage)) {
				ret = PTR_ERR(ipage);
				f2fs_unlock_op(sbi);
				goto out;
			}

			set_new_dnode(&dn, inode, ipage, NULL, 0);
			ret = f2fs_reserve_block(&dn, index);
			if (ret) {
				f2fs_unlock_op(sbi);
				goto out;
			}

			if (dn.data_blkaddr != NEW_ADDR) {
				invalidate_blocks(sbi, dn.data_blkaddr);

				dn.data_blkaddr = NEW_ADDR;
				set_data_blkaddr(&dn);

				dn.data_blkaddr = NULL_ADDR;
				f2fs_update_extent_cache(&dn);
			}
			f2fs_put_dnode(&dn);
			f2fs_unlock_op(sbi);

			new_size = max_t(loff_t, new_size,
					(index + 1) << PAGE_CACHE_SHIFT);
		}

		if (off_end) {
			ret = fill_zero(inode, pg_end, 0, off_end);
			if (ret)
				goto out;

			new_size = max_t(loff_t, new_size, offset + len);
		}
	}

out:
	if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size) {
		i_size_write(inode, new_size);
		mark_inode_dirty(inode);
		update_inode_page(inode);
	}

	return ret;
}
Ejemplo n.º 11
0
/* Permits arbitrary ASCII characters.  Useful for storing numeric data */
static void
genome_writeraw_file (FILE *refgenome_fp, FILE *input, 
		      IIT_T contig_iit, IIT_T altstrain_iit, char *fileroot, int index1part) {
  char Buffer[BUFFERSIZE], Reverse[BUFFERSIZE], *segment;
  char *accession, c;
  Genomicpos_T leftposition, rightposition, startposition, endposition, truelength, 
    maxposition = 0, currposition = 0;
  int contigtype;
  int strlength;
  int i;
  bool revcompp;
#ifdef ALTSTRAIN
  int altstrain_index, altstrain_offset;
#endif
  int ncontigs = 0;

  for (i = 0; i < WRITEBLOCK; i++) {
    Empty[i] = 0;
  }

  while (fgets(Buffer,BUFFERSIZE,input) != NULL) {
    if (Buffer[0] != '>') {
      fprintf(stderr,"Expecting to see a new FASTA entry\n");
      fprintf(stderr,"Instead, saw %d (%c)\n",(int) Buffer[0],Buffer[0]);
      exit(9);
    } else {
      /* HEADER */
      accession = parse_accession(Buffer);
      find_positions(&revcompp,&leftposition,&rightposition,&startposition,&endposition,
		     &truelength,&contigtype,accession,contig_iit);
      if (++ncontigs < 50) {
	if (revcompp == true) {
	  fprintf(stderr,"Writing contig %s to universal coordinates %u..%u in genome %s\n",
		  accession,startposition,endposition,fileroot);
	} else {
	  fprintf(stderr,"Writing contig %s to universal coordinates %u..%u in genome %s\n",
		  accession,startposition+1U,endposition+1U,fileroot);
	}
      } else if (ncontigs == 50) {
	fprintf(stderr,"More than 50 contigs.  Will stop printing messages\n");
      }

      if (contigtype > 0) {
#ifdef ALTSTRAIN
	fprintf(stderr," (alternate strain %s)",IIT_typestring(altstrain_iit,contigtype));
#endif
      }
      FREE(accession);

      if (contigtype > 0) {
#ifdef ALTSTRAIN
	/* Initialize file pointer for alternate strain */
	altstrain_index = IIT_get_exact(altstrain_iit,/*divstring*/NULL,leftposition,rightposition,contigtype);
	if (revcompp == true) {
	  altstrain_offset = rightposition + 1U - leftposition;
	} else {
	  altstrain_offset = 0;
	}
	debug(printf("Setting altstrain_offset to be %d\n",altstrain_offset));
#endif
      }

      /* Handles case where true length is greater than provided
         coordinates.  This needs to be after call to IIT_get_exact */
      if (leftposition + truelength - 1U > rightposition) {
	debug(fprintf(stderr,"Extending endposition for truelength of %u\n",truelength));
	rightposition = leftposition + truelength;
	if (revcompp == true) {
	  endposition = startposition - truelength;
	} else {
	  endposition = startposition + truelength;
	}
      }

      /* In both cases, set file pointer for reference strain,
         although we won't write sequence of alternate strain.  For an
         alternate strain, ensure that we fill the reference strain
         with sufficient X's. */
      if (startposition > maxposition) {
	/* Start beyond end of file */
	debug(printf("Filling with zeroes from %u to %u-1\n",maxposition,startposition));
	fill_zero(refgenome_fp,maxposition,startposition,/*uncompressedp*/true,index1part);
	  
	if (contigtype > 0) {
#ifdef ALTSTRAIN
	  fill_zero(refgenome_fp,leftposition,rightposition + 1,/*uncompressedp*/true,index1part);
	  maxposition = currposition = rightposition + 1;
#endif
	} else {
	  maxposition = rightposition;
	  currposition = startposition;
	}

      } else {
	/* Start within file */
	if (contigtype > 0) {
#ifdef ALTSTRAIN
	  if (rightposition + 1 > maxposition) {
	    debug(printf("Filling with zeroes from %u to %u-1\n",maxposition,rightposition+1));
	    fill_zero(refgenome_fp,maxposition,rightposition + 1,/*uncompressedp*/true,index1part);
	    maxposition = currposition = rightposition + 1;
	  }
#endif
	} else {
	  debug(printf("Moving to %u\n",startposition));
	  move_absolute(refgenome_fp,startposition);
	  currposition = startposition;
	}
      }

      /* SEQUENCE */
      fprintf(stderr,"Processing %u characters\n",truelength);
      while (truelength > 0) {
	if (truelength > BUFFERSIZE) {
	  if ((strlength = fread(Buffer,sizeof(char),BUFFERSIZE,input)) < BUFFERSIZE) {
	    fprintf(stderr,"Expecting %u more characters, but saw end of file\n",truelength);
	    exit(9);
	  }
	  truelength -= BUFFERSIZE;
	} else {
	  if ((strlength = fread(Buffer,sizeof(char),truelength,input)) < truelength) {
	    fprintf(stderr,"Expecting %u more characters, but saw end of file\n",truelength);
	    exit(9);
	  }
	  truelength = 0;
	}

	if (revcompp == true) {
	  make_reverse_buffered(Reverse,Buffer,strlength);
	  segment = Reverse;
	} else {
	  segment = Buffer;
	}

	if (contigtype > 0) {
#ifdef ALTSTRAING
	  /* Write alternate strain.  It is likely that IIT commands
	     will fail because they depend on \0 to terminate the segment.  */
	  if (revcompp == true) {
	    altstrain_offset -= strlength;
	    debug(printf("Writing alternate strain at %u\n",altstrain_offset));
	    IIT_backfill_sequence(altstrain_iit,altstrain_index,altstrain_offset,segment);
	  } else {
	    debug(printf("Writing alternate strain at %u\n",altstrain_offset));
	    IIT_backfill_sequence(altstrain_iit,altstrain_index,altstrain_offset,segment);
	    altstrain_offset += strlength;
	  }
#endif
	} else {
	  /* Write reference strain */
	  if (revcompp == true) {
	    debug(printf("Filling with sequence from %u-1 to %u\n",currposition,currposition-strlength));
	    currposition -= strlength;
	    fwrite(segment,sizeof(char),strlength,refgenome_fp);
	  } else {
	    debug(printf("Filling with sequence from %u to %u-1\n",currposition,currposition+strlength));
	    fwrite(segment,sizeof(char),strlength,refgenome_fp);
	    currposition += strlength;
	    if (currposition > maxposition) {
	      maxposition = currposition;
	    }
	  }
	}
      }

      if ((c = fgetc(input)) != EOF && c != '\n') {
	fprintf(stderr,"Expecting linefeed at end of sequence.  Saw %d instead\n",
		c);
	exit(9);
      }

    }
  }

  return;
}