예제 #1
0
int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
{
	struct gfs2_sbd *sdp = per_node->i_sbd;
	struct gfs2_meta_header mh;
	char name[256];
	struct gfs2_inode *ip;
	unsigned int blocks = sdp->qcsize << (20 - sdp->sd_sb.sb_bsize_shift);
	unsigned int x;
	unsigned int hgt;
	struct gfs2_buffer_head *bh;

	memset(&mh, 0, sizeof(struct gfs2_meta_header));
	mh.mh_magic = GFS2_MAGIC;
	mh.mh_type = GFS2_METATYPE_QC;
	mh.mh_format = GFS2_FORMAT_QC;

	sprintf(name, "quota_change%u", j);
	ip = createi(per_node, name, S_IFREG | 0600, GFS2_DIF_SYSTEM);
	if (ip == NULL) {
		return errno;
	}

	hgt = calc_tree_height(ip, (blocks + 1) * sdp->bsize);
	build_height(ip, hgt);

	for (x = 0; x < blocks; x++) {
		bh = get_file_buf(ip, x, FALSE);
		if (!bh)
			return -1;

		memset(bh->b_data, 0, sdp->bsize);
		gfs2_meta_header_out(&mh, bh->b_data);
		bmodified(bh);
		brelse(bh);
	}

	if (cfg_debug) {
		printf("\nQuota Change %u:\n", j);
		gfs2_dinode_print(&ip->i_di);
	}

	inode_put(&ip);
	return 0;
}
예제 #2
0
파일: main.c 프로젝트: spinclick/pnglitch
int main(int argc, char* argv[]) {

  int mkdir_ret = mkdir(OUTPUT_DIRECTORY, S_IRWXU);

  if (mkdir_ret == -1 && errno != EEXIST)
    error_fatal(1, "problem creating directory", strerror(errno));
  else if (access(OUTPUT_DIRECTORY, W_OK | X_OK))
    error_fatal(1, "Problem accessing directory", strerror(errno));

  char path[500];

  //No commandline arguments, so prompt for path
  while (argc <= 1) {
    printf("Enter PNG file path: ");
    char *s = fgets(path, 499, stdin);

    if (s == NULL)
      continue;

    char *newline = strrchr(s, '\n');
    *newline = '\0';

    FILE *f = fopen(s, "r");

    if (f == NULL) {
      printf("Could not open file '%s'\n", s);
      continue;
    }

    fclose(f);
    argc++;
    
    argv[1] = path; //Is this out of bounds?
  }


  for (int i=1;i<argc;i++) {

    char *file_path = argv[i];

    FILE *f = fopen(file_path, "rb");

    if (f == NULL) {
      printf("Cannot open file '%s'\n", file_path);
      continue;
    }

    unsigned char* png_buf = calloc(1, 1);

    PNG_LENGTH = get_file_buf(f, &png_buf); 
    printf("Glitching file '%s' (%.2lfM)\n", file_path, PNG_LENGTH / 1024.0 / 1024.0);

    if (PNG_LENGTH <= 0) {
      printf("File '%s' is empty!\n", file_path);
      free(png_buf);
      continue;
    }

    file_path = basename(file_path);
    remove_filename_extension(file_path);

    //png_buf is passed around to callbacks for libpng, it will be free'd there
    begin(file_path, png_buf, PNG_LENGTH);
    fclose(f);
  }

  return 0;
}
예제 #3
0
/**
 * Intialise and write the data blocks for a new journal as a contiguous
 * extent. The indirect blocks pointing to these data blocks should have been
 * written separately using lgfs2_write_filemeta() and the extent should have
 * been allocated using lgfs2_file_alloc().
 * ip: The journal's inode
 * Returns 0 on success or -1 with errno set on error.
 */
int lgfs2_write_journal_data(struct gfs2_inode *ip)
{
	struct gfs2_log_header lh = {
		.lh_header.mh_magic = GFS2_MAGIC,
		.lh_header.mh_type = GFS2_METATYPE_LH,
		.lh_header.mh_format = GFS2_FORMAT_LH,
		.lh_tail = 0,
		.lh_blkno = 0,
		.lh_hash = 0,
#ifdef GFS2_HAS_LH_V2
		.lh_flags = GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_USERSPACE,
		.lh_crc = 0,
		.lh_nsec = 0,
		.lh_sec = 0,
		.lh_jinode = ip->i_di.di_num.no_addr,
		.lh_statfs_addr = 0,
		.lh_quota_addr = 0,
		.lh_local_total = 0,
		.lh_local_free = 0,
		.lh_local_dinodes = 0,
#else
		.lh_flags = GFS2_LOG_HEAD_UNMOUNT,
#endif
	};
	struct gfs2_buffer_head *bh;
	struct gfs2_sbd *sdp = ip->i_sbd;
	unsigned blocks = (ip->i_di.di_size + sdp->bsize - 1) / sdp->bsize;
	uint64_t jext0 = ip->i_di.di_num.no_addr + ip->i_di.di_blocks - blocks;
	uint64_t seq = ((blocks) * (random() / (RAND_MAX + 1.0)));

	bh = bget(sdp, jext0);
	if (bh == NULL)
		return -1;

	crc32c_optimization_init();
	do {
		struct gfs2_log_header *buflh = (struct gfs2_log_header *)bh->b_data;

		lh.lh_sequence = seq;
		lh.lh_blkno = bh->b_blocknr - jext0;
		gfs2_log_header_out(&lh, bh->b_data);

		buflh->lh_hash = cpu_to_be32(lgfs2_log_header_hash(bh->b_data));
#ifdef GFS2_HAS_LH_V2
		buflh->lh_addr = cpu_to_be64(bh->b_blocknr);
		buflh->lh_crc = cpu_to_be32(lgfs2_log_header_crc(bh->b_data, sdp->bsize));
#endif

		if (bwrite(bh)) {
			free(bh);
			return -1;
		}

		if (++seq == blocks)
			seq = 0;

	} while (++bh->b_blocknr < jext0 + blocks);

	free(bh);
	return 0;
}

int write_journal(struct gfs2_inode *jnl, unsigned bsize, unsigned int blocks)
{
	struct gfs2_log_header lh;
	unsigned int x;
	uint64_t seq = ((blocks) * (random() / (RAND_MAX + 1.0)));
	uint32_t hash;
	unsigned int height;

	/* Build the height up so our journal blocks will be contiguous and */
	/* not broken up by indirect block pages.                           */
	height = calc_tree_height(jnl, (blocks + 1) * bsize);
	build_height(jnl, height);

	memset(&lh, 0, sizeof(struct gfs2_log_header));
	lh.lh_header.mh_magic = GFS2_MAGIC;
	lh.lh_header.mh_type = GFS2_METATYPE_LH;
	lh.lh_header.mh_format = GFS2_FORMAT_LH;
	lh.lh_flags = GFS2_LOG_HEAD_UNMOUNT;
#ifdef GFS2_HAS_LH_V2
	lh.lh_flags |= GFS2_LOG_HEAD_USERSPACE;
	lh.lh_jinode = jnl->i_di.di_num.no_addr;
#endif
	for (x = 0; x < blocks; x++) {
		struct gfs2_buffer_head *bh = get_file_buf(jnl, x, TRUE);
		if (!bh)
			return -1;
		bmodified(bh);
		brelse(bh);
	}
	crc32c_optimization_init();
	for (x = 0; x < blocks; x++) {
		struct gfs2_buffer_head *bh = get_file_buf(jnl, x, FALSE);
		if (!bh)
			return -1;

		memset(bh->b_data, 0, bsize);
		lh.lh_sequence = seq;
		lh.lh_blkno = x;
		gfs2_log_header_out(&lh, bh->b_data);
		hash = lgfs2_log_header_hash(bh->b_data);
		((struct gfs2_log_header *)bh->b_data)->lh_hash = cpu_to_be32(hash);
#ifdef GFS2_HAS_LH_V2
		((struct gfs2_log_header *)bh->b_data)->lh_addr = cpu_to_be64(bh->b_blocknr);
		hash = lgfs2_log_header_crc(bh->b_data, bsize);
		((struct gfs2_log_header *)bh->b_data)->lh_crc = cpu_to_be32(hash);
#endif
		bmodified(bh);
		brelse(bh);

		if (++seq == blocks)
			seq = 0;
	}

	return 0;
}

int build_journal(struct gfs2_sbd *sdp, int j, struct gfs2_inode *jindex)
{
	char name[256];
	int ret;

	sprintf(name, "journal%u", j);
	sdp->md.journal[j] = createi(jindex, name, S_IFREG | 0600,
				     GFS2_DIF_SYSTEM);
	if (sdp->md.journal[j] == NULL) {
		return errno;
	}
	ret = write_journal(sdp->md.journal[j], sdp->bsize,
			    sdp->jsize << 20 >> sdp->sd_sb.sb_bsize_shift);
	return ret;
}