示例#1
0
void prepatch_partitions(void)
{
	MemPart p8, p11;

	if(!is_homebrews_runlevel()) {
		printk("%s: no need to patch partition, quit\n", __func__);

		return;
	}

	p8.meminfo = get_partition(8);
	p11.meminfo = get_partition(11);

	g_p8_size = p8.size = 1;
	
	if(p11.meminfo != NULL) {
		p8.offset = 56-4-p8.size;
	} else {
		p8.offset = 56-p8.size;
	}

	modify_partition(&p8);

	p11.size = 4;
	p11.offset = 56-4;
	modify_partition(&p11);
	display_meminfo();
}
示例#2
0
void get_partitions(unsigned char * data, unsigned disk)
{
	get_partition(data, disk, 446);
	get_partition(data, disk, 462);
	get_partition(data, disk, 478);
	get_partition(data, disk, 494);
}
示例#3
0
void patch_partitions(void) 
{
	MemPart p2, p9;
	int max_user_part_size;

	// shut up gcc warning
	(void)display_meminfo;

	p2.meminfo = get_partition(2);
	p9.meminfo = get_partition(9);

	if(g_p2_size == 24 && g_p9_size == 24) {
		p2.size = MAX_HIGH_MEMSIZE;
		p9.size = 0;
	} else {
		p2.size = g_p2_size;
		p9.size = g_p9_size;
	}

	if(get_partition(11) != NULL) {
		max_user_part_size = 56 - 4 - g_p8_size;
	} else {
		max_user_part_size = 56 - g_p8_size;
	}

	if (p2.size + p9.size > max_user_part_size) {
		// reserved 4MB for P11
		int reserved_len;

		reserved_len = p2.size + p9.size - max_user_part_size;

		if(p9.size > reserved_len) {
			p9.size -= reserved_len;
		} else {
			p2.size -= reserved_len - p9.size; 
			p9.size = 0;
		}
	}

	printk("%s: p2/p9 %d/%d\n", __func__, p2.size, p9.size);

	//reset partition length for next reboot
	sctrlHENSetMemory(24, 24);

	p2.offset = 0;
	modify_partition(&p2);

	p9.offset = p2.size;
	modify_partition(&p9);

	g_high_memory_enabled = 1;
	display_meminfo();
	unlock_high_memory(0);
}
/* Called when the state of tsk changes back to TASK_RUNNING.
 * We need to requeue the task.
 *
 * NOTE: If a sporadic task is suspended for a long time,
 * this might actually be an event-driven release of a new job.
 */
static void demo_task_resume(struct task_struct  *tsk)
{
        unsigned long flags;
        struct demo_cpu_state *state = cpu_state_for(get_partition(tsk));
        lt_t now;
        TRACE_TASK(tsk, "wake_up at %llu\n", litmus_clock());
        raw_spin_lock_irqsave(&state->local_queues.ready_lock, flags);

        now = litmus_clock();

        if (is_sporadic(tsk) && is_tardy(tsk, now)) {
                /* This sporadic task was gone for a "long" time and woke up past
                 * its deadline. Give it a new budget by triggering a job
                 * release. */
                release_at(tsk, now);
        }

        /* This check is required to avoid races with tasks that resume before
         * the scheduler "noticed" that it resumed. That is, the wake up may
         * race with the call to schedule(). */
        if (state->scheduled != tsk) {
                demo_requeue(tsk, state);
                if (edf_preemption_needed(&state->local_queues, state->scheduled)) {
                        preempt_if_preemptable(state->scheduled, state->cpu);
                }
        }

        raw_spin_unlock_irqrestore(&state->local_queues.ready_lock, flags);
}
static void demo_task_new(struct task_struct *tsk, int on_runqueue,
                          int is_running)
{
        /* We'll use this to store IRQ flags. */
        unsigned long flags;
        struct demo_cpu_state *state = cpu_state_for(get_partition(tsk));
        lt_t now;

        TRACE_TASK(tsk, "is a new RT task %llu (on runqueue:%d, running:%d)\n",
                   litmus_clock(), on_runqueue, is_running);

        /* Acquire the lock protecting the state and disable interrupts. */
        raw_spin_lock_irqsave(&state->local_queues.ready_lock, flags);

        now = litmus_clock();

        /* Release the first job now. */
        release_at(tsk, now);

        if (is_running) {
                /* If tsk is running, then no other task can be running
                 * on the local CPU. */
                BUG_ON(state->scheduled != NULL);
                state->scheduled = tsk;
        } else if (on_runqueue) {
                demo_requeue(tsk, state);
        }

        if (edf_preemption_needed(&state->local_queues, state->scheduled))
                preempt_if_preemptable(state->scheduled, state->cpu);

        raw_spin_unlock_irqrestore(&state->local_queues.ready_lock, flags);
}
示例#6
0
/*
 * Ask the user for new partition type information (logical, extended).
 * This function calls the actual partition adding logic - dos_add_partition.
 */
void dos_new_partition(struct fdisk_context *cxt)
{
	int i, free_primary = 0;

	for (i = 0; i < 4; i++)
		free_primary += !ptes[i].part_table->sys_ind;

	if (!free_primary && partitions >= MAXIMUM_PARTS) {
		printf(_("The maximum number of partitions has been created\n"));
		return;
	}

	if (!free_primary) {
		if (extended_offset) {
			printf(_("All primary partitions are in use\n"));
			add_logical(cxt);
		} else
			printf(_("If you want to create more than four partitions, you must replace a\n"
				 "primary partition with an extended partition first.\n"));
	} else if (partitions >= MAXIMUM_PARTS) {
		printf(_("All logical partitions are in use\n"));
		printf(_("Adding a primary partition\n"));
		dos_add_partition(cxt, get_partition(cxt, 0, 4), LINUX_NATIVE);
	} else {
		char c, dflt, line[LINE_LENGTH];

		dflt = (free_primary == 1 && !extended_offset) ? 'e' : 'p';
		snprintf(line, sizeof(line),
			 _("Partition type:\n"
			   "   p   primary (%d primary, %d extended, %d free)\n"
			   "%s\n"
			   "Select (default %c): "),
			 4 - (extended_offset ? 1 : 0) - free_primary, extended_offset ? 1 : 0, free_primary,
			 extended_offset ? _("   l   logical (numbered from 5)") : _("   e   extended"),
			 dflt);

		c = tolower(read_chars(line));
		if (c == '\n') {
			c = dflt;
			printf(_("Using default response %c\n"), c);
		}
		if (c == 'p') {
			int i = get_nonexisting_partition(cxt, 0, 4);
			if (i >= 0)
				dos_add_partition(cxt, i, LINUX_NATIVE);
			return;
		} else if (c == 'l' && extended_offset) {
			add_logical(cxt);
			return;
		} else if (c == 'e' && !extended_offset) {
			int i = get_nonexisting_partition(cxt, 0, 4);
			if (i >= 0)
				dos_add_partition(cxt, i, EXTENDED);
			return;
		} else
			printf(_("Invalid partition type `%c'\n"), c);
	}
}
示例#7
0
文件: 714.cpp 项目: waiwai444/oj
void solve()
{
	long long tot = 0;
	for(int i = 0; i < m; i++)
		tot += book[i];
	long long min = search_min(tot);
	get_partition(min);
	print_result();
}
示例#8
0
feather_callback void do_sched_trace_task_param(unsigned long id, unsigned long _task)
{
	struct task_struct *t = (struct task_struct*) _task;
	struct st_event_record* rec = get_record(ST_PARAM, t);
	if (rec) {
		rec->data.param.wcet      = get_exec_cost(t);
		rec->data.param.period    = get_rt_period(t);
		rec->data.param.phase     = get_rt_phase(t);
		rec->data.param.partition = get_partition(t);
		put_record(rec);
	}
}
static void demo_task_exit(struct task_struct *tsk)
{
        unsigned long flags;
        struct demo_cpu_state *state = cpu_state_for(get_partition(tsk));
        raw_spin_lock_irqsave(&state->local_queues.ready_lock, flags);

        /* For simplicity, we assume here that the task is no longer queued anywhere else. This
         * is the case when tasks exit by themselves; additional queue management is
         * is required if tasks are forced out of real-time mode by other tasks. */

        if (state->scheduled == tsk) {
                state->scheduled = NULL;
        }

        raw_spin_unlock_irqrestore(&state->local_queues.ready_lock, flags);
}
示例#10
0
static void
xbsd_link_part(void)
{
    int k, i;
    struct partition *p;

    k = get_partition(1, g_partitions);

    if (!xbsd_check_new_partition(&i))
        return;

    p = get_part_table(k);

    xbsd_dlabel.d_partitions[i].p_size   = get_nr_sects(p);
    xbsd_dlabel.d_partitions[i].p_offset = get_start_sect(p);
    xbsd_dlabel.d_partitions[i].p_fstype = xbsd_translate_fstype(p->sys_ind);
}
示例#11
0
bool sdc_api::insert_dynamic(int table_id, const void *data)
{
	bool retval = false;
#if defined(DEBUG)
	scoped_debug<bool> debug(500, __PRETTY_FUNCTION__, (_("table_id={1}, data={2}") % table_id % data).str(SGLOCALE), &retval);
#endif

	int struct_size;
	int partition_id = get_partition(table_id, data, struct_size);
	if (partition_id < 0) {
		DBCT->_DBCT_error_code = DBCENOENT;
		return retval;
	}

	retval = insert(table_id, data, partition_id, struct_size);
	return retval;
}
示例#12
0
long sdc_api::update_dynamic(int table_id, int index_id, const void *old_data, const void *new_data)
{
	long retval = -1;
#if defined(DEBUG)
	scoped_debug<long> debug(500, __PRETTY_FUNCTION__, (_("table_id={1}, index_id={2}, old_data={3}, new_data={4}") % table_id % index_id % old_data % new_data).str(SGLOCALE), &retval);
#endif

	int struct_size;
	int partition_id = get_partition(table_id, old_data, struct_size);
	if (partition_id < 0) {
		DBCT->_DBCT_error_code = DBCENOENT;
		return retval;
	}

	retval = update(table_id, index_id, old_data, new_data, partition_id, struct_size);
	return retval;
}
示例#13
0
文件: mapper.hpp 项目: pkambadu/GWAS
 value_type get_adjacency (const int_type& number) const {
   const int_type first = get_partition (number);
   const int_type second = (number-sum_to_n(first));
   /* 
    * we need to add 1 to the row number because the entire triangle is 
    * shifted by 1 to account for the fact that there are no diagonals
    *
    * 0| 0                 0| X  
    * 1| 1 2               1| 0 X         
    * 2| 3 4 5    ------>  2| 1 2 X       
    * 3| 6 7 8 9           3| 3 4 5 X        
    *  ---------           4| 6 7 8 9 X 
    *   0 1 2 3              -----------     
    *                         0 1 2 3    
    * Also, returning in reverse order to match Aurelie's code.
    */
   return value_type (offset+second, offset+(1+first));
 }
示例#14
0
/**
 * get_unique_guid_for_partition() - gets the GUID for a partition identified
 * by a string name
 *
 * @ops: contains AVB ops handlers
 * @partition: partition name (NUL-terminated UTF-8 string)
 * @guid_buf: buf, used to copy in GUID string. Example of value:
 *      527c1c6d-6361-4593-8842-3c78fcd39219
 * @guid_buf_size: @guid_buf buffer size
 *
 * @return:
 *      AVB_IO_RESULT_OK, on success (GUID found)
 *      AVB_IO_RESULT_ERROR_IO, if incorrect buffer size (@guid_buf_size) was
 *             provided
 *      AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION, if partition was not found
 */
static AvbIOResult get_unique_guid_for_partition(AvbOps *ops,
						 const char *partition,
						 char *guid_buf,
						 size_t guid_buf_size)
{
	struct mmc_part *part;
	size_t uuid_size;

	part = get_partition(ops, partition);
	if (!part)
		return AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION;

	uuid_size = sizeof(part->info.uuid);
	if (uuid_size > guid_buf_size)
		return AVB_IO_RESULT_ERROR_IO;

	memcpy(guid_buf, part->info.uuid, uuid_size);
	guid_buf[uuid_size - 1] = 0;

	return AVB_IO_RESULT_OK;
}
示例#15
0
long sdc_api::find_dynamic(int table_id, int index_id, const void *data, void *result, long max_rows)
{
	long retval = -1;
#if defined(DEBUG)
	scoped_debug<long> debug(500, __PRETTY_FUNCTION__, (_("table_id={1}, index_id={2}, data={3}, result={4}, max_rows={5}") % table_id % index_id % data % result % max_rows).str(SGLOCALE), &retval);
#endif

	int struct_size;
	int partition_id = get_partition(table_id, data, struct_size);
	if (partition_id < 0) {
		DBCT->_DBCT_error_code = DBCENOENT;
		return retval;
	}

	if (DBCT->_DBCT_login && local(table_id, partition_id)) {
		dbc_mgr.set_user(DBCT->_DBCT_user_id);
		retval = dbc_mgr.find(table_id, index_id, data, result, max_rows);
	} else {
		retval = find(table_id, index_id, data, result, max_rows, partition_id, struct_size);
	}

	return retval;
}
示例#16
0
static struct mtd_info *nand_mtd(void)
{

	ppt = get_partition();
	if (NULL == ppt)
		return NULL;

	memset(&Mtd, 0, sizeof(Mtd));

	Mtd.size = ppt->PageCount * ppt->byteperpage;
	Mtd.erasesize = ppt->pageperblock * ppt->byteperpage;
	Mtd.writesize =  ppt->byteperpage;
	Mtd.erasesize_shift = ffs(Mtd.erasesize) - 1;
	Mtd.writesize_shift = ffs(Mtd.writesize) - 1;
	Mtd.name = ppt->name;
	Mtd._erase = block_erase;
	Mtd._read = page_read;
	Mtd._write = panic_page_write;
	Mtd._panic_write = panic_page_write;
	Mtd._block_isbad = block_isbad;
	Mtd._block_markbad = block_markbad;

	return &Mtd;
}
示例#17
0
static void count_segs_sb(const AV1_COMMON *cm, MACROBLOCKD *xd,
                          const TileInfo *tile, MODE_INFO **mi,
                          unsigned *no_pred_segcounts,
                          unsigned (*temporal_predictor_count)[2],
                          unsigned *t_unpred_seg_counts, int mi_row, int mi_col,
                          BLOCK_SIZE bsize) {
  const int mis = cm->mi_stride;
  const int bs = mi_size_wide[bsize], hbs = bs / 2;
#if CONFIG_EXT_PARTITION_TYPES
  PARTITION_TYPE partition;
#else
  int bw, bh;
#endif  // CONFIG_EXT_PARTITION_TYPES

  if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return;

#if CONFIG_EXT_PARTITION_TYPES
  if (bsize == BLOCK_8X8)
    partition = PARTITION_NONE;
  else
    partition = get_partition(cm, mi_row, mi_col, bsize);
  switch (partition) {
    case PARTITION_NONE:
      count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
                 t_unpred_seg_counts, bs, bs, mi_row, mi_col);
      break;
    case PARTITION_HORZ:
      count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
                 t_unpred_seg_counts, bs, hbs, mi_row, mi_col);
      count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, bs, hbs,
                 mi_row + hbs, mi_col);
      break;
    case PARTITION_VERT:
      count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
                 t_unpred_seg_counts, hbs, bs, mi_row, mi_col);
      count_segs(cm, xd, tile, mi + hbs, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, bs, mi_row,
                 mi_col + hbs);
      break;
    case PARTITION_HORZ_A:
      count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
                 t_unpred_seg_counts, hbs, hbs, mi_row, mi_col);
      count_segs(cm, xd, tile, mi + hbs, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, hbs,
                 mi_row, mi_col + hbs);
      count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, bs, hbs,
                 mi_row + hbs, mi_col);
      break;
    case PARTITION_HORZ_B:
      count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
                 t_unpred_seg_counts, bs, hbs, mi_row, mi_col);
      count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, hbs,
                 mi_row + hbs, mi_col);
      count_segs(cm, xd, tile, mi + hbs + hbs * mis, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, hbs,
                 mi_row + hbs, mi_col + hbs);
      break;
    case PARTITION_VERT_A:
      count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
                 t_unpred_seg_counts, hbs, hbs, mi_row, mi_col);
      count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, hbs,
                 mi_row + hbs, mi_col);
      count_segs(cm, xd, tile, mi + hbs, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, bs, mi_row,
                 mi_col + hbs);
      break;
    case PARTITION_VERT_B:
      count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
                 t_unpred_seg_counts, hbs, bs, mi_row, mi_col);
      count_segs(cm, xd, tile, mi + hbs, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, hbs,
                 mi_row, mi_col + hbs);
      count_segs(cm, xd, tile, mi + hbs + hbs * mis, no_pred_segcounts,
                 temporal_predictor_count, t_unpred_seg_counts, hbs, hbs,
                 mi_row + hbs, mi_col + hbs);
      break;
    case PARTITION_SPLIT: {
      const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize];
      int n;

      assert(num_8x8_blocks_wide_lookup[mi[0]->mbmi.sb_type] < bs &&
             num_8x8_blocks_high_lookup[mi[0]->mbmi.sb_type] < bs);

      for (n = 0; n < 4; n++) {
        const int mi_dc = hbs * (n & 1);
        const int mi_dr = hbs * (n >> 1);

        count_segs_sb(cm, xd, tile, &mi[mi_dr * mis + mi_dc], no_pred_segcounts,
                      temporal_predictor_count, t_unpred_seg_counts,
                      mi_row + mi_dr, mi_col + mi_dc, subsize);
      }
    } break;
    default: assert(0);
  }
#else
  bw = mi_size_wide[mi[0]->mbmi.sb_type];
  bh = mi_size_high[mi[0]->mbmi.sb_type];

  if (bw == bs && bh == bs) {
    count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
               t_unpred_seg_counts, bs, bs, mi_row, mi_col);
  } else if (bw == bs && bh < bs) {
    count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
               t_unpred_seg_counts, bs, hbs, mi_row, mi_col);
    count_segs(cm, xd, tile, mi + hbs * mis, no_pred_segcounts,
               temporal_predictor_count, t_unpred_seg_counts, bs, hbs,
               mi_row + hbs, mi_col);
  } else if (bw < bs && bh == bs) {
    count_segs(cm, xd, tile, mi, no_pred_segcounts, temporal_predictor_count,
               t_unpred_seg_counts, hbs, bs, mi_row, mi_col);
    count_segs(cm, xd, tile, mi + hbs, no_pred_segcounts,
               temporal_predictor_count, t_unpred_seg_counts, hbs, bs, mi_row,
               mi_col + hbs);
  } else {
    const BLOCK_SIZE subsize = subsize_lookup[PARTITION_SPLIT][bsize];
    int n;

    assert(bw < bs && bh < bs);

    for (n = 0; n < 4; n++) {
      const int mi_dc = hbs * (n & 1);
      const int mi_dr = hbs * (n >> 1);

      count_segs_sb(cm, xd, tile, &mi[mi_dr * mis + mi_dc], no_pred_segcounts,
                    temporal_predictor_count, t_unpred_seg_counts,
                    mi_row + mi_dr, mi_col + mi_dc, subsize);
    }
  }
#endif  // CONFIG_EXT_PARTITION_TYPES
}
void
bootinfo_init_program(void)
{
	char *base;
	int proplen;
	phandle_t chosen;
	int tag, taglen, script, scriptlen, scriptvalid, entity, chrp;
	char tagbuf[128], c;
	char *device, *filename, *directory, *partition;
	int current, size;
	char *bootscript;
        char *tmp;
	char bootpath[1024];

	/* Parse the boot script */

	chosen = find_dev("/chosen");
	tmp = get_property(chosen, "bootpath", &proplen);
	memcpy(bootpath, tmp, proplen);
	bootpath[proplen] = 0;

	DPRINTF("bootpath %s\n", bootpath);

	device = get_device(bootpath);
	partition = get_partition(bootpath);
	filename = get_filename(bootpath, &directory);

	feval("load-base");
	base = (char*)cell2pointer(POP());

	feval("load-size");
	size = POP();

	/* Some bootinfo scripts contain a binary payload after the
	   NULL-terminated Forth string such as OS 9. Restrict our
	   size to just the Forth section, otherwise we end up trying
	   to allocate memory for the entire binary which might fail. */
	size = strnlen(base, size);

	bootscript = malloc(size);
	if (bootscript == NULL) {
		DPRINTF("Can't malloc %d bytes\n", size);
		return;
	}

	if (!is_bootinfo(base)) {
		DPRINTF("Not a valid bootinfo memory image\n");
                free(bootscript);
		return;
	}

	chrp = 0;
	tag = 0;
	taglen = 0;
	script = 0;
	scriptvalid = 0;
	scriptlen = 0;
	entity = 0;
	current = 0;
	while (current < size) {

		c = base[current++];

		if (c == '<') {
			script = 0;
			tag = 1;
			taglen = 0;
		} else if (c == '>') {
			tag = 0;
			tagbuf[taglen] = '\0';
			if (strncasecmp(tagbuf, "chrp-boot", 9) == 0) {
				chrp = 1;
			} else if (chrp == 1) {
				if (strncasecmp(tagbuf, "boot-script", 11) == 0) {
					script = 1;
					scriptlen = 0;
				} else if (strncasecmp(tagbuf, "/boot-script", 12) == 0) {

					script = 0;
					bootscript[scriptlen] = '\0';

					DPRINTF("got bootscript %s\n",
						bootscript);

					scriptvalid = -1;

					break;
				} else if (strncasecmp(tagbuf, "/chrp-boot", 10) == 0)
					break;
			}
		} else if (tag && taglen < sizeof(tagbuf)) {
			tagbuf[taglen++] = c;
		} else if (script && c == '&') {
			entity = 1;
			taglen = 0;
		} else if (entity && c ==';') {
			entity = 0;
			tagbuf[taglen] = '\0';
			if (strncasecmp(tagbuf, "lt", 2) == 0) {
				bootscript[scriptlen++] = '<';
			} else if (strncasecmp(tagbuf, "gt", 2) == 0) {
				bootscript[scriptlen++] = '>';
			} else if (strncasecmp(tagbuf, "device", 6) == 0) {
				strcpy(bootscript + scriptlen, device);
				scriptlen += strlen(device);
			} else if (strncasecmp(tagbuf, "partition", 9) == 0) {
				strcpy(bootscript + scriptlen, partition);
				scriptlen += strlen(partition);
			} else if (strncasecmp(tagbuf, "directory", 9) == 0) {
				strcpy(bootscript + scriptlen, directory);
				scriptlen += strlen(directory);
			} else if (strncasecmp(tagbuf, "filename", 8) == 0) {
				strcpy(bootscript + scriptlen, filename);
				scriptlen += strlen(filename);
			} else if (strncasecmp(tagbuf, "full-path", 9) == 0) {
				strcpy(bootscript + scriptlen, bootpath);
				scriptlen += strlen(bootpath);
			} else { /* unknown, keep it */
				bootscript[scriptlen] = '&';
				strcpy(bootscript + scriptlen + 1, tagbuf);
				scriptlen += taglen + 1;
				bootscript[scriptlen] = ';';
				scriptlen++;
			}
		} else if (entity && taglen < sizeof(tagbuf)) {
			tagbuf[taglen++] = c;
		} else if (script && scriptlen < size) {
			bootscript[scriptlen++] = c;
		}
	}

	/* If the payload is bootinfo then we execute it immediately */
	if (scriptvalid) {
		DPRINTF("bootscript: %s\n", bootscript);
		feval(bootscript);
	}
	else
		DPRINTF("Unable to parse bootinfo bootscript\n");
}
示例#19
0
static AvbIOResult mmc_byte_io(AvbOps *ops,
			       const char *partition,
			       s64 offset,
			       size_t num_bytes,
			       void *buffer,
			       size_t *out_num_read,
			       enum mmc_io_type io_type)
{
	ulong ret;
	struct mmc_part *part;
	u64 start_offset, start_sector, sectors, residue;
	u8 *tmp_buf;
	size_t io_cnt = 0;

	if (!partition || !buffer || io_type > IO_WRITE)
		return AVB_IO_RESULT_ERROR_IO;

	part = get_partition(ops, partition);
	if (!part)
		return AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION;

	start_offset = calc_offset(part, offset);
	while (num_bytes) {
		start_sector = start_offset / part->info.blksz;
		sectors = num_bytes / part->info.blksz;
		/* handle non block-aligned reads */
		if (start_offset % part->info.blksz ||
		    num_bytes < part->info.blksz) {
			tmp_buf = get_sector_buf();
			if (start_offset % part->info.blksz) {
				residue = part->info.blksz -
					(start_offset % part->info.blksz);
				if (residue > num_bytes)
					residue = num_bytes;
			} else {
				residue = num_bytes;
			}

			if (io_type == IO_READ) {
				ret = mmc_read_and_flush(part,
							 part->info.start +
							 start_sector,
							 1, tmp_buf);

				if (ret != 1) {
					printf("%s: read error (%ld, %lld)\n",
					       __func__, ret, start_sector);
					return AVB_IO_RESULT_ERROR_IO;
				}
				/*
				 * if this is not aligned at sector start,
				 * we have to adjust the tmp buffer
				 */
				tmp_buf += (start_offset % part->info.blksz);
				memcpy(buffer, (void *)tmp_buf, residue);
			} else {
				ret = mmc_read_and_flush(part,
							 part->info.start +
							 start_sector,
							 1, tmp_buf);

				if (ret != 1) {
					printf("%s: read error (%ld, %lld)\n",
					       __func__, ret, start_sector);
					return AVB_IO_RESULT_ERROR_IO;
				}
				memcpy((void *)tmp_buf +
					start_offset % part->info.blksz,
					buffer, residue);

				ret = mmc_write(part, part->info.start +
						start_sector, 1, tmp_buf);
				if (ret != 1) {
					printf("%s: write error (%ld, %lld)\n",
					       __func__, ret, start_sector);
					return AVB_IO_RESULT_ERROR_IO;
				}
			}

			io_cnt += residue;
			buffer += residue;
			start_offset += residue;
			num_bytes -= residue;
			continue;
		}

		if (sectors) {
			if (io_type == IO_READ) {
				ret = mmc_read_and_flush(part,
							 part->info.start +
							 start_sector,
							 sectors, buffer);
			} else {
				ret = mmc_write(part,
						part->info.start +
						start_sector,
						sectors, buffer);
			}

			if (!ret) {
				printf("%s: sector read error\n", __func__);
				return AVB_IO_RESULT_ERROR_IO;
			}

			io_cnt += ret * part->info.blksz;
			buffer += ret * part->info.blksz;
			start_offset += ret * part->info.blksz;
			num_bytes -= ret * part->info.blksz;
		}
	}

	/* Set counter for read operation */
	if (io_type == IO_READ && out_num_read)
		*out_num_read = io_cnt;

	return AVB_IO_RESULT_OK;
}
int main()
{
	/*
	* ------------- 변수설명-----------------
	* mbr_buf : mbr 영역의 덤프를 위한 버퍼
	* bpb_buf : bpb 영역의 덤프를 위한 버퍼
	* fat_buf : fat 영역의 덤프를 위한 버퍼
	* pPartition_arr : 파티션 정보 저장을 위한 구조체 변수
	* root_buf : Root Directory Entry 영역의 덤프를 위한 버퍼
	* sel_m_menu : 메인 메뉴에서의 선택을 위한 변수
	* sel_rec_entry : 복구하고자 하는 디렉토리 엔트리 입력 변수
	* -----------------------------------------
	*/

	U32 sel_m_menu;
	U32 sel_rec_entry;

	U8 mbr_buf[512];
	U8 bpb_buf[512];
	U32 fat_buf[128];
	U8* root_buf;
	PARTITION pPartition_arr[50];

	gVol.Drive = 0x2;
	gVol.VolBeginSec = 0x0;
	// 초기 HDD 덤프를 위한 장치번호와 시작 섹터 초기화

 	if(HDD_read(gVol.Drive, gVol.VolBeginSec, 1, mbr_buf)== 0)
	{
		printf( "Boot Sector Read Failed \n" );
		return 1;
	}
	// mbr 영역의 덤프를 위한 HDD_read 함수 호출
	
	get_partition(pPartition_arr, mbr_buf);
	// mbr 덤프를 이용한 파티션 정보 습득을 위한 get_partition 함수 호출
	
	gVol.VolBeginSec = pPartition_arr->LBA_Start;
	// 시작 위치를 Partition의 시작 섹터로 변경
	if(HDD_read(gVol.Drive, gVol.VolBeginSec, 1, bpb_buf)==0)
	{
		printf( "BPB Sector Read Failed \n");
		return 1;
	}
	// BPB 영역의 덤프를 위한 HDD_read 함수 호출

	if(get_BPB_info((FAT32_BPB *)bpb_buf, &gVol) == 0)
	{
		printf( "It is not FAT32 File System \n" );
		return 1;
	}
	// BPB 영역의 정보를 구조체에 저장하기 위한 get_BPB_info 함수 호출

	gVol.RootDirSecCnt = 10;
	gVol.RootEntCnt = 100;
	// Root Directory Entry 내 섹터를 읽어오기 위한 변수 설정
	/*
	* ---------------- 개선해야할 사항 ---------------- 
	* 단 고정된 값이 아니라 가변적인 값으로 처리할 방법을 구상해야함
    * ------------------------------------------------- 
	*/

	root_buf = (U8*)malloc(gVol.RootDirSecCnt*512);
	// Root Directory Entry 공간만큼의 동적할당

	if(HDD_read(gVol.Drive, gVol.RootDirSec, gVol.RootDirSecCnt, root_buf)==0)
	{
		printf("Root Directory Read Failed \n");
		return 1;
	}

	printf("============= USB Recovery Tool Ver.FAT32 =============\n");
	printf("1. Analyze USB \n");
	printf("2. Exit \n");
	printf("select 1 or 2 : ");
	scanf("%d", &sel_m_menu);
	// 메인 메뉴 출력 및 변수 입력

	switch(sel_m_menu)
	{
	case 1:
		show_del_dir((DirEntry*)root_buf);
		break;
	case 2:
		exit(1);
	}
	// 메인 메뉴 입력 변수에 따른 분기를 위한 switch 문
	// 1 : 지워진 파일/디렉토리 출력
	// 2 : 프로그램 종료

	printf("\n\n============= Recovery Mode =============\n");
	printf("복구하고자 하는 파일의 Entry Number를 입력하세요 : ");
	scanf("%d", &sel_rec_entry);
	// 복구 모드 출력 및 복구할 Directory Entry 선택

	if(HDD_read(gVol.Drive,gVol.FATStartSec, 1, fat_buf)==0)
	{
		printf( "FAT Sector Read Failed \n");
		return 1;
	}
	// FAT 영역의 덤프를 위한 HDD_read 함수 호출

	rec_file((DirEntry*)root_buf,sel_rec_entry,fat_buf, 0, 0);
	// 데이터의 복구를 위한 rec_file 함수 호출
	
	return 0;
}
示例#21
0
void tdo_scheme::init_partition_stack(int verbose_level)
{
	int k, at, f, c, l, i;
	int f_v = (verbose_level >= 1);
	int f_vv = (verbose_level >= 2);
	int f_vvv = (verbose_level >= 3);
	
	if (f_v) {
		cout << "tdo_scheme::init_partition_stack" << endl;
		}
	if (f_vv) {
		cout << "part_length=" << part_length << endl;
		cout << "row_level=" << row_level << endl;
		cout << "col_level=" << col_level << endl;
		cout << "verbose_level=" << verbose_level << endl;
		}
	mn = part[0];
	m = part[1];
	n = mn - m;
	if (part_length < 2) {
		cout << "part_length < 2" << endl;
		exit(1);
		}
	if (f_vvv) {
		cout << "init_partition_stack: m=" << m << " n=" << n << endl;
		int_vec_print(part, part_length + 1);
		cout << endl;
		}
	
	P = new partitionstack;
	P->allocate(m + n, 0 /* verbose_level */);
	//PB.init_partition_backtrack_basic(m, n, verbose_level - 10);
	if (f_vvv) {
		cout << "after PB.init_partition_backtrack_basic" << endl;
		}

	//partitionstack &P = PB.P;

	if (f_vvv) {
		cout << "initial partition stack: " << endl;
		P->print(cout);
		}
	for (k = 1; k < part_length; k++) {
		at = part[k];
		c = P->cellNumber[at];
		f = P->startCell[c];
		l = P->cellSize[c];
		if (f_vvv) {
			cout << "part[" << k << "]=" << at << endl;
			cout << "P->cellNumber[at]=" << c << endl;
			cout << "P->startCell[c]=" << f << endl;
			cout << "P->cellSize[c]=" << l << endl;
			cout << "f + l - at=" << f + l - at << endl;
			}
		P->subset_continguous(at, f + l - at);
		P->split_cell(FALSE);
		if (f_vvv) {
			cout << "after splitting at " << at << endl;
			P->print(cout);
			}
		if (P->ht == row_level) {
			l = P->ht;
			if (the_row_scheme) {
				FREE_int(the_row_scheme);
				the_row_scheme = NULL;
				}
			the_row_scheme = NEW_int(l * l);
			for (i = 0; i < l * l; i++) {
				the_row_scheme[i] = -1;
				}
			get_partition(ROW, l, verbose_level - 3);
			get_row_or_col_scheme(ROW, l, verbose_level - 3);
			}
			
		if (P->ht == col_level) {
			l = P->ht;
			if (the_col_scheme) {
				FREE_int(the_col_scheme);
				the_col_scheme = NULL;
				}
			the_col_scheme = NEW_int(l * l);
			for (i = 0; i < l * l; i++) {
				the_col_scheme[i] = -1;
				}
			get_partition(COL, l, verbose_level - 3);	
			get_row_or_col_scheme(COL, l, verbose_level - 3);
			}
			
		if (P->ht == extra_row_level) {
			l = P->ht;
			if (the_extra_row_scheme) {
				FREE_int(the_extra_row_scheme);
				the_extra_row_scheme = NULL;
				}
			the_extra_row_scheme = NEW_int(l * l);
			for (i = 0; i < l * l; i++) {
				the_extra_row_scheme[i] = -1;
				}
			get_partition(EXTRA_ROW, l, verbose_level - 3);
			get_row_or_col_scheme(EXTRA_ROW, l, verbose_level - 3);	
			}
			
		if (P->ht == extra_col_level) {
			l = P->ht;
			if (the_extra_col_scheme) {
				FREE_int(the_extra_col_scheme);
				the_extra_col_scheme = NULL;
				}
			the_extra_col_scheme = NEW_int(l * l);
			for (i = 0; i < l * l; i++) {
				the_extra_col_scheme[i] = -1;
				}
			get_partition(EXTRA_COL, l, verbose_level - 3);
			get_row_or_col_scheme(EXTRA_COL, l, verbose_level - 3);	
			}
			
		if (P->ht == lambda_level) {
			l = P->ht;
			get_partition(LAMBDA, l, verbose_level - 3);
			}
			
		} // next k
	
	if (f_vvv) {
		cout << "before complete_partition_info" << endl;
		}
	if (row_level >= 2) {
		complete_partition_info(ROW, 0/*verbose_level*/);
		}
	if (col_level >= 2) {
		complete_partition_info(COL, 0/*verbose_level*/);
		}
	if (extra_row_level >= 2) {
		complete_partition_info(EXTRA_ROW, 0/*verbose_level*/);
		}
	if (extra_col_level >= 2 && extra_col_level < part_length) {
		complete_partition_info(EXTRA_COL, 0/*verbose_level*/);
		}
	complete_partition_info(LAMBDA, 0/*verbose_level*/);
	
	if (f_vv) {
		if (row_level >= 2) {
			print_scheme(ROW, FALSE);
			}
		if (col_level >= 2) {
			print_scheme(COL, FALSE);
			}
		if (extra_row_level >= 2) {
			print_scheme(EXTRA_ROW, FALSE);
			}
		if (extra_col_level >= 2) {
			print_scheme(EXTRA_COL, FALSE);
			}
		print_scheme(LAMBDA, FALSE);
		}
}