Esempio n. 1
0
void Desk_new_background(const char *p)
{
    bool makebmp;

    p = Desk_extended_rootCommand(p);
    if (p)
    {
        if (0 == _stricmp(p, "none"))
            p = "";
        if (0 == _stricmp(p, "style"))
            p = NULL;
    }
    if (false == Settings_enableBackground)
        p = "";
    else
    if (NULL == p)
        p = mStyle.rootCommand;

    makebmp = hDesktopWnd && Settings_smartWallpaper;
    if (0 == strcmp(Root.command, p) && *p && (Root.bmp || !makebmp))
        return;
	set_bitmap(load_desk_bitmap(p, makebmp));
    if (hDesktopWnd)
        Desk_SetPosition();
    strcpy(Root.command, p);
    if (g_usingVista && 0 == *p)
        SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);
}
Esempio n. 2
0
/*
 * this changes the io permissions bitmap in the current task.
 */
asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
	struct thread_struct * t = &current->thread;
	unsigned long *bitmap;
        struct physdev_set_iobitmap set_iobitmap = {0};

	if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
		return -EINVAL;
	if (turn_on && !capable(CAP_SYS_RAWIO))
		return -EPERM;

	/*
	 * If it's the first ioperm() call in this thread's lifetime, set the
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
	 * this is why we delay this operation until now:
	 */
	if (!t->io_bitmap_ptr) {
		bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
		if (!bitmap)
			return -ENOMEM;

		memset(bitmap, 0xff, IO_BITMAP_BYTES);
		t->io_bitmap_ptr = bitmap;

		set_iobitmap.bitmap = (char *)bitmap;
		set_iobitmap.nr_ports = IO_BITMAP_BITS;
		
		HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap, &set_iobitmap);
	}

	set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);

	return 0;
}
Esempio n. 3
0
void Desk_read_background(const char *p)
{
	bool makebmp;

	Desk_Reset(true);

	p = Desk_extended_rootCommand(p);
	if (p)
	{
		if (0 == _stricmp(p, "none"))
			p = "";
		if (0 == _stricmp(p, "style"))
			p = NULL;
	}
	if (false == Settings_enableBackground)
		p = "";
	else
		if (NULL == p)
			p = mStyle.rootCommand;

	makebmp = hDesktopWnd && Settings_smartWallpaper;
	if (0 == strcmp(Root.command, p) && *p && (Root.bmp || !makebmp))
		return;
	HBITMAP read_bitmap(const char* path, bool delete_after);
	set_bitmap(read_bitmap(p, makebmp));
	if (hDesktopWnd)
		Desk_SetPosition();
	strcpy(Root.command, p);
	if (g_usingVista && 0 == *p)
		SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);

	//PostMessage(BBhwnd, BB_REDRAWGUI, BBRG_DESK, 0);
}
Esempio n. 4
0
//******** cnopen *********************
//mode: FD_READ/FD_WRITE
int16_t cnopen(dir_ptr* dir, const char* name, uint8_t mode)
{
	stat_st stat_buf;
	if(cnstat(dir,name,&stat_buf) != 0)
	{
		if(mode == FD_WRITE) {
			check(cncreat(dir,name) == 0, "Could not create %s", name);
		}
		check(cnstat(dir,name,&stat_buf) == 0, "Could not stat %s", name);
	}
	//TODO: The fd bitmap is not 1 block long, hope we don't run out of fds
	int16_t fd = (int16_t)(uint16_t)find_free_bit((block*)fd_bm);
	set_bitmap((block*)fd_bm, fd);
	fd_tbl[fd].cursor = 0;
	fd_tbl[fd].state = mode;
	fd_tbl[fd].inode_id = stat_buf.inode_id;
	inode_read(stat_buf.inode_id, &fd_tbl[fd].inode);

	if(fd_tbl[fd].inode.blocks > 0)
	{
		fd_tbl[fd].data = calloc(fd_tbl[fd].inode.blocks,sizeof(block));
		llread(&fd_tbl[fd].inode, fd_tbl[fd].data);
	}
	else
	{
		fd_tbl[fd].data = NULL;
	}
	return fd;

error:
	return -1;
}
void t_campaign_selection_dialog::initialize()
{
	m_layout = g_layout.get();
//	std::fill( m_enabled, m_enabled + ELEMENTS_OF( m_enabled ), true );
	m_campaign_id = k_standard_campaign_none;

	//////////////////////////////////////////////////////////////////
 	// find dimensions & center
	t_screen_point        origin(0,0);
	t_bitmap_layer const* layer = m_layout->find( "background" );
	t_screen_rect		  rect = layer->get_rect();

	set_bitmap( layer );
	rect += t_screen_point( (get_parent()->get_width() - rect.width()) / 2, 
		                           (get_parent()->get_height() - rect.height()) / 2 );
	move( rect );
	set_drop_shadow();

	//////////////////////////////////////////////////////////////////

	// add title
	t_text_window* window;
	layer = m_layout->find( "title" );
	rect = layer->get_rect();
	window = new t_text_window( get_font( rect.height() ), rect, this, 
		                         k_score_title, t_pixel_24(0,0,0) );
	window->set_center_horizontal();
	window->set_center_vertical();
	window->set_drop_shadow( true, t_pixel_24(200,200,200));

	create_text();
	create_buttons();
	create_icons();
}
Esempio n. 6
0
/*
 * this changes the io permissions bitmap in the current task.
 */
asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
	unsigned int i, max_long, bytes, bytes_updated;
	struct thread_struct * t = &current->thread;
	struct tss_struct * tss;
	unsigned long *bitmap;

	if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
		return -EINVAL;
	if (turn_on && !capable(CAP_SYS_RAWIO))
		return -EPERM;

	/*
	 * If it's the first ioperm() call in this thread's lifetime, set the
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
	 * this is why we delay this operation until now:
	 */
	if (!t->io_bitmap_ptr) {
		bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
		if (!bitmap)
			return -ENOMEM;

		memset(bitmap, 0xff, IO_BITMAP_BYTES);
		t->io_bitmap_ptr = bitmap;
		set_thread_flag(TIF_IO_BITMAP);
	}

	/*
	 * do it in the per-thread copy and in the TSS ...
	 *
	 * Disable preemption via get_cpu() - we must not switch away
	 * because the ->io_bitmap_max value must match the bitmap
	 * contents:
	 */
	tss = &per_cpu(init_tss, get_cpu());

	set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);

	/*
	 * Search for a (possibly new) maximum. This is simple and stupid,
	 * to keep it obviously correct:
	 */
	max_long = 0;
	for (i = 0; i < IO_BITMAP_LONGS; i++)
		if (t->io_bitmap_ptr[i] != ~0UL)
			max_long = i;

	bytes = (max_long + 1) * sizeof(long);
	bytes_updated = max(bytes, t->io_bitmap_max);

	t->io_bitmap_max = bytes;

	/* Update the TSS: */
	memcpy(tss->io_bitmap, t->io_bitmap_ptr, bytes_updated);

	put_cpu();

	return 0;
}
Esempio n. 7
0
void snarf_region(unsigned int from, unsigned int num)
{
	if (from > IO_BITMAP_SIZE*32)
		return;
	if (from + num > IO_BITMAP_SIZE*32)
		num = IO_BITMAP_SIZE*32 - from;
	set_bitmap(ioport_registrar, from, num, 1);
	return;
}
Esempio n. 8
0
void inode_bitmap_init(void)
{
	block *inode_btm = calloc(1,sizeof(block));

	//Mark first inode as used
	set_bitmap(inode_btm, 0);

	blk_write(BLOCKID_INODE_BITMAP, inode_btm);
	free(inode_btm);
}
Esempio n. 9
0
void block_bitmap_init(void)
{
	block *block_btm = calloc(1,sizeof(block));

	//Mark all reserved blocks as used
	set_bitmap(block_btm, BLOCKID_SUPER);
	set_bitmap(block_btm, BLOCKID_BLOCK_BITMAP);
	set_bitmap(block_btm, BLOCKID_INODE_BITMAP);

	//Mark all inode table blocks as used
	for (uint16_t i = BLOCKID_INODE_TABLE; i < INODE_TABLE_BLOCKS + BLOCKID_INODE_TABLE; i++) {
		set_bitmap(block_btm, i);
	}

	//Mark root directory block as used
	set_bitmap(block_btm, INODE_TABLE_BLOCKS + BLOCKID_INODE_TABLE);

	blk_write(BLOCKID_BLOCK_BITMAP, block_btm);
	free(block_btm);
}
Esempio n. 10
0
int main(int argc, char **argv)
{
	if(argc != 4){
		printf("[# of threads] [max prime] [print y/n] \n");
		exit(EXIT_FAILURE);
	}
	int num = atoi(argv[1]);
	if(num > 0)
		num_threads = num;
	else{
		printf("invalid number of threads\n");
		exit(EXIT_FAILURE);
	}
	unsigned long max = atol(argv[2]);
	if(max < 1 || max > 4294967296){
		printf("invalid max number, using 4294967296\n");
		max_num = 4294967296;
	}
	else {
		max_num = max;
	}
	char print;
	if (argv[3][0] == 'y' || argv[3][0] == 'n') {
		print = argv[3][0];
	} else {
		printf("Invalid entry for print primes.\n");
		exit(EXIT_FAILURE);
	}
	printf("hello program\n");
	/*	struct sigaction raven;

	raven.sa_handler = nevermore;
	sigemptyset(&raven.sa_mask);
	raven.sa_flags = 0;

	sigaction(SIGQUIT, &raven, NULL);
	sigaction(SIGINT, &raven, NULL);
	sigaction(SIGHUP, &raven, NULL);
	*/
	printf("good thing we didn't do anything stupid here\n");
	//unsigned long primes_size = max_num / BITS_PER_WORD + 1;
	primes = (char *)malloc(sizeof(char)*((max_num/BITS_PER_WORD)+1));
	printf("Primes has been set\n");
	set_bitmap();
	printf("bitmap has been set\n");
	seed_primes();
	printf("seeding complete\n");
	create_threads();
	printf("threads have been created and died\n");
	printPrimes(print);
	free(primes);
	return 0;
}
Esempio n. 11
0
// -------------------------------------------------------------------
// window to display a skill icon
// -------------------------------------------------------------------
void t_spell_icon_window::set_spell( t_spell spell )
{
	if (spell == m_spell)
		return;
	m_spell = spell;
	set_visible( spell != k_spell_none );
	if (spell != k_spell_none )
	{
		set_bitmap( get_spell_icon( spell, m_height ));
		set_help_balloon_text( get_spell_name( spell ));
	}
}
Esempio n. 12
0
//*************reserve_block************
iptr reserve_block(void)
{
	superblock* super = (superblock*)&superblk_cache;
	if(super->free_block_count == 0)
	{
		return 0;
	}
	iptr blockid = find_free_bit(&block_bm_cache);
	set_bitmap(&block_bm_cache, blockid);
	super->free_block_count--;
	flush_metadata();
	return blockid;
}
Esempio n. 13
0
//*************reserve_inode************
iptr reserve_inode(void)
{
	superblock* super = (superblock*)&superblk_cache;
	if(super->free_inode_count == 0)
	{
		return 0;
	}
	iptr inode_ptr = find_free_bit(&inode_bm_cache);
	set_bitmap(&inode_bm_cache, inode_ptr);
	super->free_inode_count--;
	flush_metadata();
	return inode_ptr;
}
Esempio n. 14
0
/*
 * this changes the io permissions bitmap in the current task.
 */
asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
	struct thread_struct * t = &current->thread;
	struct tss_struct * tss;
	unsigned long *bitmap;

	if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
		return -EINVAL;
	if (turn_on && !capable(CAP_SYS_RAWIO))
		return -EPERM;

	/*
	 * If it's the first ioperm() call in this thread's lifetime, set the
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
	 * this is why we delay this operation until now:
	 */
	if (!t->io_bitmap_ptr) {
		bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
		if (!bitmap)
			return -ENOMEM;

		memset(bitmap, 0xff, IO_BITMAP_BYTES);
		t->io_bitmap_ptr = bitmap;
	}

	/*
	 * do it in the per-thread copy and in the TSS ...
	 */
	set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
	tss = init_tss + get_cpu();
	if (tss->io_bitmap_base == IO_BITMAP_OFFSET) { /* already active? */
		set_bitmap(tss->io_bitmap, from, num, !turn_on);
	} else {
		memcpy(tss->io_bitmap, t->io_bitmap_ptr, IO_BITMAP_BYTES);
		tss->io_bitmap_base = IO_BITMAP_OFFSET; /* Activate it in the TSS */
	}
	put_cpu();
	return 0;
}
Esempio n. 15
0
/*
 * this changes the io permissions bitmap in the current task.
 */
asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
	struct thread_struct * t = &current->thread;
	struct tss_struct * tss = init_tss + smp_processor_id();

	if ((from + num <= from) || (from + num > IO_BITMAP_SIZE*32))
		return -EINVAL;
	if (turn_on && !capable(CAP_SYS_RAWIO))
		return -EPERM;
	/*
	 * If it's the first ioperm() call in this thread's lifetime, set the
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
	 * this is why we delay this operation until now:
	 */
 	if (!t->io_bitmap_ptr) {
		t->io_bitmap_ptr = kmalloc((IO_BITMAP_SIZE+1)*4, GFP_KERNEL);
		if (!t->io_bitmap_ptr) 
			return -ENOMEM; 

		memset(t->io_bitmap_ptr,0xff,(IO_BITMAP_SIZE+1)*4);
		/*
		 * this activates it in the TSS
		 */
	}

	/*
	 * do it in the per-thread copy and in the TSS ...
	 */
	set_bitmap((unsigned long *) t->io_bitmap_ptr, from, num, !turn_on);
	if (tss->io_map_base != IO_BITMAP_OFFSET) { 
		memcpy(tss->io_bitmap, t->io_bitmap_ptr, sizeof(tss->io_bitmap));
		tss->io_map_base = IO_BITMAP_OFFSET;
	} else { 
	set_bitmap((unsigned long *) tss->io_bitmap, from, num, !turn_on);
	}

	return 0;
}
Esempio n. 16
0
/*
 * this changes the io permissions bitmap in the current task.
 */
asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
	struct thread_struct * t = &current->thread;
	struct tss_struct * tss;

	if ((from + num <= from) || (from + num > IO_BITMAP_SIZE*32))
		return -EINVAL;
	if (turn_on && !capable(CAP_SYS_RAWIO))
		return -EPERM;
	/*
	 * If it's the first ioperm() call in this thread's lifetime, set the
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
	 * this is why we delay this operation until now:
	 */
	preempt_disable();
	tss = init_tss + smp_processor_id();
	if (!t->ioperm) {
		/*
		 * just in case ...
		 */
		memset(t->io_bitmap,0xff,(IO_BITMAP_SIZE+1)*4);
		t->ioperm = 1;
		/*
		 * this activates it in the TSS
		 */
		tss->bitmap = IO_BITMAP_OFFSET;
	}

	/*
	 * do it in the per-thread copy and in the TSS ...
	 */
	set_bitmap(t->io_bitmap, from, num, !turn_on);
	set_bitmap(tss->io_bitmap, from, num, !turn_on);
	preempt_enable();

	return 0;
}
Esempio n. 17
0
/*
 * this changes the io permissions bitmap in the current task.
 */
asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
	if (from + num <= from)
		return -EINVAL;
	if (from + num > IO_BITMAP_SIZE*32)
		return -EINVAL;
	if (!suser())
		return -EPERM;

#ifdef IODEBUG
	printk("io: from=%d num=%d %s\n", from, num, (turn_on ? "on" : "off"));
#endif
	set_bitmap((unsigned long *)current->tss.io_bitmap, from, num, !turn_on);
	return 0;
}
Esempio n. 18
0
// --------------------------------------------------------
// change the bitmap
// --------------------------------------------------------
void t_bitmap_layer_window::set_bitmap( t_bitmap_layer const* bitmap, bool use_offset )
{
	t_screen_point point = get_parent()->to_client( get_screen_rect().top_left() );

	if (use_offset)
	{
		if (m_bitmap != 0)
			point -= m_bitmap->get_rect().top_left();
	}
	else
	{
		if (bitmap != 0)
			point -= bitmap->get_rect().top_left();
	}
	set_bitmap( bitmap, point );
}
Esempio n. 19
0
void t_combat_results_dialog::initialize()
{
	m_layout = g_layout.get();
	m_creatures_lost_layout = k_creature_select_bitmaps.get();

	//////////////////////////////////////////////////////////////////
 	// find dimensions & center
	t_screen_point        origin(0,0);
	t_bitmap_layer const* layer = m_layout->find( "background" );
	t_screen_rect		  rect = layer->get_rect();

	set_bitmap( layer );
	rect += t_screen_point( (get_parent()->get_width() - rect.width()) / 2, 
		                           (get_parent()->get_height() - rect.height()) / 2 );
	move( rect );
	set_drop_shadow();

	//////////////////////////////////////////////////////////////////

	// add title
	std::string           text;

	layer = m_layout->find( "title" );
	rect = layer->get_rect();
	m_title = new t_text_window( get_font( rect.height() ), rect, this, 
		                         k_combat_results_title, t_pixel_24(0,0,0) );
	m_title->set_center_horizontal();
	m_title->set_center_vertical();
	m_title->set_drop_shadow( true, t_pixel_24(200,200,200));

	create_text();
	create_icons();
	create_buttons();

	// add title
//	text = replace_keywords( k_text_combat_results_creatures, "%creatures", m_traits->plural_name );
	// make it all upper case
//	std::transform( text.begin(), text.end(), text.begin(), toupper );
//	m_title->set_text( text );

}
Esempio n. 20
0
void t_score_dialog::initialize()
{
	// calculate the final scores
	calculate_scores( m_map, m_winner_team, m_scores );

	m_layout = g_layout.get();
	m_difficulty_icons = g_difficulty_icons.get();

	//////////////////////////////////////////////////////////////////
 	// find dimensions & center
	t_screen_point        origin(0,0);
	t_bitmap_layer const* layer = m_layout->find( "background" );
	t_screen_rect		  rect = layer->get_rect();

	set_bitmap( layer );
	rect += t_screen_point( (get_parent()->get_width() - rect.width()) / 2, 
		                           (get_parent()->get_height() - rect.height()) / 2 );
	move( rect );
	set_drop_shadow();

	//////////////////////////////////////////////////////////////////

	// add title
	t_text_window* window;
	layer = m_layout->find( "title" );
	rect = layer->get_rect();
	window = new t_text_window( get_font( rect.height() ), rect, this, 
		                         k_score_title, t_pixel_24(0,0,0) );
	window->set_center_horizontal();
	window->set_center_vertical();
	window->set_drop_shadow( true, t_pixel_24(200,200,200));

	create_text();
	create_icons();
	create_buttons();
}
Esempio n. 21
0
static ssize_t lssu_print_suinfo(struct nilfs *nilfs, __u64 segnum,
				 ssize_t nsi, __u64 protseq,
				 unsigned long* bitmap)
{
	ssize_t i, n = 0;
	int all = 1;

	for (i = 0; i < nsi; i++, segnum++) {
		if (!all && nilfs_suinfo_clean(&suinfos[i]))
			continue;

			log_mesg(3, 0, 0, fs_opt.debug, "%s: seg %llu, %c %c %c , %i\n",
			       __FILE__, (unsigned long long)segnum,
			       nilfs_suinfo_active(&suinfos[i]) ? 'a' : '-',
			       nilfs_suinfo_dirty(&suinfos[i]) ? 'd' : '-',
			       nilfs_suinfo_error(&suinfos[i]) ? 'e' : '-',
			       suinfos[i].sui_nblocks);
		if  (nilfs_suinfo_active(&suinfos[i]) || nilfs_suinfo_dirty(&suinfos[i])){
		    set_bitmap(bitmap, (unsigned long long)segnum,  suinfos[i].sui_nblocks);
		}
		n++;
	}
	return n;
}
Esempio n. 22
0
uint8_t* ramdisk_init(){
	int i;
	uint8_t* ramdisk;
	int root_bid;
	struct rd_inode* root_inode;
	struct rd_super_block* InitSuperBlock;
#ifdef UL_DEBUG
	if(!(ramdisk=(uint8_t*)malloc(RAMDISK_SIZE*sizeof(uint8_t)))){
		fprintf(stderr,"No sufficient mem space for ramdisk!\n");
		exit(-1);
	}
#endif

#ifndef UL_DEBUG
	if(!(ramdisk=(uint8_t*)vmalloc(RAMDISK_SIZE*sizeof(uint8_t)))){
		printk("<1> No sufficient mem space for ramdisk!\n");
		return NULL;
	}
#endif

	//Nullify all the data in ramdisk
	memset(ramdisk,0,RAMDISK_SIZE);

	//Init the bitmap
	for(i=0;i<=(BITMAP_LIMIT+1)/RD_BLOCK_SIZE;i++){
		set_bitmap(ramdisk,i);
	}

	//Init the root directory
	root_bid=find_next_free_block(ramdisk);//BlockNO for root dir
#ifdef UL_DEBUG
	if(!(root_inode=(struct rd_inode*)malloc(sizeof(struct rd_inode)))){
		fprintf(stderr, "No sufficient mem space for root dir!\n");
		exit(-1);
	}
#endif
#ifndef UL_DEBUG
	if(!(root_inode=(struct rd_inode*)vmalloc(sizeof(struct rd_inode)))){
		printk("<1> No sufficient mem space for root dir!\n");
		return NULL;
	}
#endif

	root_inode->type=0;
	root_inode->size=0;
	root_inode->BlockPointer[0]=root_bid;
	update_inode(ramdisk,0,root_inode);
	
	//Init the superblock
#ifdef UL_DEBUG
	if(!(InitSuperBlock=(struct rd_super_block*)malloc(sizeof(struct rd_super_block)))){
		fprintf(stderr,"No sufficient mem\n");
		exit(-1);
	}
#endif 
#ifndef UL_DEBUG
	if(!(InitSuperBlock=(struct rd_super_block*)vmalloc(sizeof(struct rd_super_block)))){
		printk("<1> No sufficient mem\n");
		return NULL;
	}
#endif 

	InitSuperBlock->FreeBlockNum=BLOCK_NUM-(BITMAP_LIMIT+1)/RD_BLOCK_SIZE;
	InitSuperBlock->FreeInodeNum=INODE_NUM-1;//The root dir takes one inode
	memset(InitSuperBlock->InodeBitmap,0,INODEBITMAP_SIZE);
	update_superblock(ramdisk,InitSuperBlock);
	
	//Init the inode bitmap in superblock
	set_inode_bitmap(ramdisk,0);

#ifndef UL_DEBUG
	vfree(root_inode);
#endif
	return ramdisk;	

}
Esempio n. 23
0
/*
 * this changes the io permissions bitmap in the current task.
 */
asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
	struct thread_struct * t = &current->thread;
	struct tss_struct * tss;
	unsigned int i, max_long, bytes, bytes_updated;

	if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
		return -EINVAL;
#ifdef CONFIG_GRKERNSEC_IO
	if (turn_on) {
		gr_handle_ioperm();
		return -EPERM;
	}
#endif
	if (turn_on && !capable(CAP_SYS_RAWIO))
		return -EPERM;

	/*
	 * If it's the first ioperm() call in this thread's lifetime, set the
	 * IO bitmap up. ioperm() is much less timing critical than clone(),
	 * this is why we delay this operation until now:
	 */
	if (!t->io_bitmap_ptr) {
		unsigned long *bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);

		if (!bitmap)
			return -ENOMEM;

		memset(bitmap, 0xff, IO_BITMAP_BYTES);
		t->io_bitmap_ptr = bitmap;
		set_thread_flag(TIF_IO_BITMAP);
	}

	/*
	 * do it in the per-thread copy and in the TSS ...
	 *
	 * Disable preemption via get_cpu() - we must not switch away
	 * because the ->io_bitmap_max value must match the bitmap
	 * contents:
	 */
	tss = init_tss + get_cpu();

	set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);

	/*
	 * Search for a (possibly new) maximum. This is simple and stupid,
	 * to keep it obviously correct:
	 */
	max_long = 0;
	for (i = 0; i < IO_BITMAP_LONGS; i++)
		if (t->io_bitmap_ptr[i] != ~0UL)
			max_long = i;

	bytes = (max_long + 1) * sizeof(unsigned long);
	bytes_updated = max(bytes, t->io_bitmap_max);

	t->io_bitmap_max = bytes;

#ifdef CONFIG_X86_32
	/*
	 * Sets the lazy trigger so that the next I/O operation will
	 * reload the correct bitmap.
	 * Reset the owner so that a process switch will not set
	 * tss->io_bitmap_base to IO_BITMAP_OFFSET.
	 */
	tss->x86_tss.io_bitmap_base = INVALID_IO_BITMAP_OFFSET_LAZY;
	tss->io_bitmap_owner = NULL;
#else
	/* Update the TSS: */
	memcpy(tss->io_bitmap, t->io_bitmap_ptr, bytes_updated);
#endif

	put_cpu();

	return 0;
}
Esempio n. 24
0
extern void readbitmap(char* device, image_head image_hdr, unsigned long* bitmap, int pui)
{

    xfs_agnumber_t  agno = 0;
    xfs_agblock_t   first_agbno;
    xfs_agnumber_t  num_ags;
    ag_header_t     ag_hdr;
    xfs_daddr_t     read_ag_off;
    int             read_ag_length;
    void            *read_ag_buf = NULL;
    xfs_off_t	    read_ag_position;            /* xfs_types.h: typedef __s64 */
    uint64_t	    sk, res, s_pos = 0;
    void            *btree_buf_data = NULL;
    int		    btree_buf_length;
    xfs_off_t	    btree_buf_position;
    xfs_agblock_t   bno;
    uint	    current_level;
    uint	    btree_levels;
    xfs_daddr_t     begin, next_begin, ag_begin, new_begin, ag_end;
						/* xfs_types.h: typedef __s64*/
    xfs_off_t       pos;
    xfs_alloc_ptr_t *ptr;
    xfs_alloc_rec_t *rec_ptr;
    int		    length;
    int		    i;
    uint64_t        size, sizeb;
    xfs_off_t	    w_position;
    int		    w_length;
    int		    wblocks;
    int		    w_size = 1 * 1024 * 1024;
    uint64_t        numblocks = 0;

    xfs_off_t	    logstart, logend;
    xfs_off_t	    logstart_pos, logend_pos;
    int		    log_length;

    struct xfs_btree_block *block;
    uint64_t current_block, block_count, prog_cur_block = 0;

    int start = 0;
    int bit_size = 1;
    progress_bar        prog;

    uint64_t bused = 0;
    uint64_t bfree = 0;

    /// init progress
    progress_init(&prog, start, image_hdr.totalblock, image_hdr.totalblock, BITMAP, bit_size);

    fs_open(device);

    first_agbno = (((XFS_AGFL_DADDR(mp) + 1) * source_sectorsize) + first_residue) / source_blocksize;

    num_ags = mp->m_sb.sb_agcount;

    log_mesg(1, 0, 0, fs_opt.debug, "ags = %i\n", num_ags);
    for (agno = 0; agno < num_ags ; agno++)  {
	/* read in first blocks of the ag */

	/* initial settings */
	log_mesg(2, 0, 0, fs_opt.debug, "read ag %i header\n", agno);

	read_ag_off = XFS_AG_DADDR(mp, agno, XFS_SB_DADDR);
	read_ag_length = first_agbno * source_blocksize;
	read_ag_position = (xfs_off_t) read_ag_off * (xfs_off_t) BBSIZE;
	read_ag_buf = malloc(read_ag_length);
	if(read_ag_buf == NULL){
	    log_mesg(0, 1, 1, fs_opt.debug, "%s, %i, ERROR:%s", __func__, __LINE__, strerror(errno));
	}
	memset(read_ag_buf, 0, read_ag_length);

	log_mesg(2, 0, 0, fs_opt.debug, "seek to read_ag_position %lli\n", read_ag_position);
	sk = lseek(source_fd, read_ag_position, SEEK_SET);
	current_block = (sk/source_blocksize);
	block_count = (read_ag_length/source_blocksize);
	set_bitmap(bitmap, sk, read_ag_length);
	log_mesg(2, 0, 0, fs_opt.debug, "read ag header fd = %llu(%i), length = %i(%i)\n", sk, current_block, read_ag_length, block_count);
	if ((res = read(source_fd, read_ag_buf, read_ag_length)) < 0)  {
	    log_mesg(1, 0, 1, fs_opt.debug, "read failure at offset %lld\n", read_ag_position);
	}

	ag_hdr.xfs_sb = (xfs_dsb_t *) (read_ag_buf);
	ASSERT(be32_to_cpu(ag_hdr.xfs_sb->sb_magicnum) == XFS_SB_MAGIC);
	ag_hdr.xfs_agf = (xfs_agf_t *) (read_ag_buf + source_sectorsize);
	ASSERT(be32_to_cpu(ag_hdr.xfs_agf->agf_magicnum) == XFS_AGF_MAGIC);
	ag_hdr.xfs_agi = (xfs_agi_t *) (read_ag_buf + 2 * source_sectorsize);
	ASSERT(be32_to_cpu(ag_hdr.xfs_agi->agi_magicnum) == XFS_AGI_MAGIC);
	ag_hdr.xfs_agfl = (xfs_agfl_t *) (read_ag_buf + 3 * source_sectorsize);
	log_mesg(2, 0, 0, fs_opt.debug, "ag header read ok\n");


	/* save what we need (agf) in the btree buffer */

	btree_buf_data = malloc(source_blocksize);
	if(btree_buf_data == NULL){
	    log_mesg(0, 1, 1, fs_opt.debug, "%s, %i, ERROR:%s", __func__, __LINE__, strerror(errno));
	}
	memset(btree_buf_data, 0, source_blocksize);
	memmove(btree_buf_data, ag_hdr.xfs_agf, source_sectorsize);
	ag_hdr.xfs_agf = (xfs_agf_t *) btree_buf_data;
	btree_buf_length = source_blocksize;

	///* traverse btree until we get to the leftmost leaf node */

	bno = be32_to_cpu(ag_hdr.xfs_agf->agf_roots[XFS_BTNUM_BNOi]);
	current_level = 0;
	btree_levels = be32_to_cpu(ag_hdr.xfs_agf->agf_levels[XFS_BTNUM_BNOi]);

	ag_end = XFS_AGB_TO_DADDR(mp, agno, be32_to_cpu(ag_hdr.xfs_agf->agf_length) - 1) + source_blocksize / BBSIZE;

	for (;;) {
	    /* none of this touches the w_buf buffer */

	    current_level++;

	    btree_buf_position = pos = (xfs_off_t)XFS_AGB_TO_DADDR(mp,agno,bno) << BBSHIFT;
	    btree_buf_length = source_blocksize;

	    sk = lseek(source_fd, btree_buf_position, SEEK_SET);
	    current_block = (sk/source_blocksize);
	    block_count = (btree_buf_length/source_blocksize);
	    set_bitmap(bitmap, sk, btree_buf_length);
	    log_mesg(2, 0, 0, fs_opt.debug, "read btree sf = %llu(%i), length = %i(%i)\n", sk, current_block, btree_buf_length, block_count);
	    read(source_fd, btree_buf_data, btree_buf_length);
	    block = (struct xfs_btree_block *)((char *)btree_buf_data + pos - btree_buf_position);

	    if (be16_to_cpu(block->bb_level) == 0)
		break;

	    ptr = XFS_ALLOC_PTR_ADDR(mp, block, 1, mp->m_alloc_mxr[1]);
	    bno = be32_to_cpu(ptr[0]);
	}
	log_mesg(2, 0, 0, fs_opt.debug, "btree read done\n");

	/* align first data copy but don't overwrite ag header */

	pos = read_ag_position >> BBSHIFT;
	length = read_ag_length >> BBSHIFT;
	next_begin = pos + length;
	ag_begin = next_begin;


	///* handle the rest of the ag */

	for (;;) {
	    if (be16_to_cpu(block->bb_level) != 0)  {
		log_mesg(0, 1, 1, fs_opt.debug, "WARNING:  source filesystem inconsistent.\nA leaf btree rec isn't a leaf. Aborting now.\n");
	    }

	    rec_ptr = XFS_ALLOC_REC_ADDR(mp, block, 1);
	    for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++, rec_ptr++)  {
		/* calculate in daddr's */

		begin = next_begin;

		/*
		 * protect against pathological case of a
		 * hole right after the ag header in a
		 * mis-aligned case
		 */

		if (begin < ag_begin)
		    begin = ag_begin;

		/*
		 * round size up to ensure we copy a
		 * range bigger than required
		 */

		log_mesg(3, 0, 0, fs_opt.debug, "XFS_AGB_TO_DADDR = %llu, agno = %i, be32_to_cpu=%llu\n", XFS_AGB_TO_DADDR(mp, agno, be32_to_cpu(rec_ptr->ar_startblock)), agno, be32_to_cpu(rec_ptr->ar_startblock));
		sizeb = XFS_AGB_TO_DADDR(mp, agno, be32_to_cpu(rec_ptr->ar_startblock)) - begin;
		size = roundup(sizeb <<BBSHIFT, source_sectorsize);
		log_mesg(3, 0, 0, fs_opt.debug, "BB = %i size %i and sizeb %llu brgin = %llu\n", BBSHIFT, size, sizeb, begin);

		if (size > 0)  {
		    /* copy extent */

		    log_mesg(2, 0, 0, fs_opt.debug, "copy extent\n");
		    w_position = (xfs_off_t)begin << BBSHIFT;

		    while (size > 0)  {
			/*
			 * let lower layer do alignment
			 */
			if (size > w_size)  {
			    w_length = w_size;
			    size -= w_size;
			    sizeb -= wblocks;
			    numblocks += wblocks;
			} else  {
			    w_length = size;
			    numblocks += sizeb;
			    size = 0;
			}

			//read_wbuf(source_fd, &w_buf, mp);
			sk = lseek(source_fd, w_position, SEEK_SET);
			current_block = (sk/source_blocksize);
			block_count = (w_length/source_blocksize);
			set_bitmap(bitmap, sk, w_length);
			log_mesg(2, 0, 0, fs_opt.debug, "read ext sourcefd to w_buf source_fd=%llu(%i), length=%i(%i)\n", sk, current_block, w_length, block_count);
			sk = lseek(source_fd, w_length, SEEK_CUR);

			w_position += w_length;
		    }
		}

		/* round next starting point down */

		new_begin = XFS_AGB_TO_DADDR(mp, agno, be32_to_cpu(rec_ptr->ar_startblock) + be32_to_cpu(rec_ptr->ar_blockcount));
		next_begin = rounddown(new_begin, source_sectorsize >> BBSHIFT);
	    }

	    if (be32_to_cpu(block->bb_u.s.bb_rightsib) == NULLAGBLOCK){
		log_mesg(2, 0, 0, fs_opt.debug, "NULLAGBLOCK\n");
		break;
	    }

	    /* read in next btree record block */

	    btree_buf_position = pos = (xfs_off_t)XFS_AGB_TO_DADDR(mp, agno, be32_to_cpu(block->bb_u.s.bb_rightsib)) << BBSHIFT;
	    btree_buf_length = source_blocksize;

	    /* let read_wbuf handle alignment */

	    //read_wbuf(source_fd, &btree_buf, mp);
	    sk = lseek(source_fd, btree_buf_position, SEEK_SET);
	    current_block = (sk/source_blocksize);
	    block_count = (btree_buf_length/source_blocksize);
	    set_bitmap(bitmap, sk, btree_buf_length);
	    log_mesg(2, 0, 0, fs_opt.debug, "read btreebuf fd = %llu(%i), length = %i(%i) \n", sk, current_block, btree_buf_length, block_count);
	    read(source_fd, btree_buf_data, btree_buf_length);

	    block = (struct xfs_btree_block *)((char *) btree_buf_data + pos - btree_buf_position);
	    ASSERT(be32_to_cpu(block->bb_magic) == XFS_ABTB_MAGIC);

	}
	/*
	 * write out range of used blocks after last range
	 * of free blocks in AG
	 */
	if (next_begin < ag_end)  {
	    begin = next_begin;

	    sizeb = ag_end - begin;
	    size = roundup(sizeb << BBSHIFT, source_sectorsize);

	    if (size > 0)  {
		/* copy extent */

		w_position = (xfs_off_t) begin << BBSHIFT;

		while (size > 0)  {
		    /*
		     * let lower layer do alignment
		     */
		    if (size > w_size)  {
			w_length = w_size;
			size -= w_size;
			sizeb -= wblocks;
			numblocks += wblocks;
		    } else  {
			w_length = size;
			numblocks += sizeb;
			size = 0;
		    }

		    sk = lseek(source_fd, w_position, SEEK_SET);
		    current_block = (sk/source_blocksize);
		    block_count = (w_length/source_blocksize);
		    set_bitmap(bitmap, sk, w_length);
		    log_mesg(2, 0, 0, fs_opt.debug, "read ext fd = %llu(%i), length = %i(%i)\n", sk, current_block, w_length, block_count);
		    //read_wbuf(source_fd, &w_buf, mp);
		    lseek(source_fd, w_length, SEEK_CUR);
		    w_position += w_length;
		}
	    }
	}

	log_mesg(2, 0, 0, fs_opt.debug, "write a clean log\n");
	log_length = 1 * 1024 * 1024;
	logstart = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart) << BBSHIFT;
	logstart_pos = rounddown(logstart, (xfs_off_t)log_length);
	if (logstart % log_length)  {  /* unaligned */
	    sk = lseek(source_fd, logstart_pos, SEEK_SET);
	    current_block = (sk/source_blocksize);
	    block_count = (log_length/source_blocksize);
	    set_bitmap(bitmap, sk, log_length);
	    log_mesg(2, 0, 0, fs_opt.debug, "read log start from %llu(%i) %i(%i)\n", sk, current_block, log_length, block_count);
	    sk = lseek(source_fd, log_length, SEEK_CUR);
	}

	logend = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart) << BBSHIFT;
	logend += XFS_FSB_TO_B(mp, mp->m_sb.sb_logblocks);
	logend_pos = rounddown(logend, (xfs_off_t)log_length);
	if (logend % log_length)  {    /* unaligned */
	    sk = lseek(source_fd, logend_pos, SEEK_SET);
	    current_block = (sk/source_blocksize);
	    block_count = (log_length/source_blocksize);
	    set_bitmap(bitmap, sk, log_length);
	    log_mesg(2, 0, 0, fs_opt.debug, "read log end  from %llu(%i) %i(%i)\n", sk, current_block, log_length, block_count);
	    sk = lseek(source_fd, log_length, SEEK_CUR);
	}

	log_mesg(2, 0, 0, fs_opt.debug, "write a clean log done\n");

	prog_cur_block = image_hdr.totalblock/num_ags*(agno+1)-1;
	update_pui(&prog, prog_cur_block, prog_cur_block, 0);
    }

    for(current_block = 0; current_block <= image_hdr.totalblock; current_block++){
	if(pc_test_bit(current_block, bitmap))
	    bused++;
	else
	    bfree++;
    }
    log_mesg(0, 0, 0, fs_opt.debug, "bused = %lli, bfree = %lli\n", bused, bfree);

    fs_close();
    update_pui(&prog, 1, 1, 1);

}
Esempio n. 25
0
int main(int argc, char **argv)
{
	if(argc != 5){
		printf("[P or T] [# of P or T] [max prime] [print y/n] \n");
		exit(EXIT_FAILURE);
	}
	char type = argv[1][0];
	if(type != 'p' && type != 'P' && type != 't' && type != 'T'){
		printf("invalid process type, need either p or t\n");
		exit(EXIT_FAILURE);
	}
	int num = atoi(argv[2]);
	if(num > 0)
		num_proc = num;
	else{
		printf("invalid number of p/t\n");
		exit(EXIT_FAILURE);
	}
	unsigned long max;
	if((max = atol(argv[3])) > 0)
		max_num = max;
	else{
		printf("invalid max number\n");
		exit(EXIT_FAILURE);
	}
	char print;
	if (argv[4][0] == 'y' || argv[4][0] == 'n') {
		print = argv[4][0];
	} else {
		printf("Invalid entry for print primes.\n")
		exit(EXIT_FAILURE);
	}
	struct sigaction act;

	sigemptyset(&act.sa_mask);
	act.sa_handler = nevermore;
	act.sa_flags = 0;

	sigaction(SIGQUIT, &act, NULL);
	sigaction(SIGINT, &act, NULL);
	sigaction(SIGHUP, &act, NULL);

	printf("hello progra\nm");
	unsigned long primes_size = max_num / BITS_PER_WORD + 1;
	printf("shouldn't be an error before here\n");
	void *addr = mount_shmem(SHM_NAME, primes_size);
	printf("memory is mounted");
	primes = (unsigned char *) addr;
	printf("primes did something I don't understand\n");
	set_bitmap();
	printf("bitmap is set");
	seed_primes();
	printf("primes are seeded");
	fork();
	printf("children have lived and died");
	shm_unlink(SHM_NAME);
	int pid = 0;
	while((pid=wait(NULL))!= -1)
		continue;
	if(errno!=ECHILD)
		perror("couldn't kill child processes");
	free(process_array);
	printf("everything has been freed");
	return 0;
}
Esempio n. 26
0
void Desk_Reset(bool all)
{
    if (all)
        set_bitmap(NULL);
    Root.command [0] = 0;
}