示例#1
0
void * APR_THREAD_FUNC consumer(apr_thread_t *thd, void *data) {
    apr_status_t rv;
    struct redis_command *command = NULL;

    info_print("enter: consumer thread\n");

    while (1) {
        rv = apr_queue_pop(queue, (void **)&command);

        if (rv == APR_EINTR)
            continue;

        if (rv == APR_EOF) {
    	    info_print("queue has terminated, consumer thread exit\n");
            break;
        }

        if (rv != APR_SUCCESS  ) {
            apr_sleep(1000* 1000); //sleep 1 second.
            continue;
        }

        if(command) {
            int res = _do_redis_command((const char **)command->argv,(const size_t *)command->argvlen, command->arg_count);
            free_command(command);
            command = NULL;
        }
    }

    info_print("exit:consumer thread\n");
    return NULL;
}
示例#2
0
void test01 ( int32_t argc, char * argv[] )
{
    //pr_t x = 10123457689, y;
    pr_t x = 1023456789, y;
    //pr_t x = 9814072356, y;
    //pr_t x = 10000004797, y;


    if ( 2==argc )
    {
        x = strtol(argv[1],NULL,10);
    }

    if ( is_prime(x) )
    {
        info_print("%llu is a prime",x);
    }
    else
    {
        info_print("%llu is not prime",x);
    }

    if ( is_pan(x) )
    {
        info_print("%llu is a pandigital",x);
    }
    else
    {
        info_print("%llu is a not pandigital",x);
    }

    return;
}
示例#3
0
void p37 ( void )
{
    uint32_t k,pr;
    int32_t cnt = 0;
    uint32_t sum = 0;

    for ( k=4; k<SMALL_PRIME_SZ; ++k )
    {
        pr = small_primes[k];
        if ( is_truncatable_prime(pr) )
        {
            cnt++;
            sum += pr;
            info_print("[%2d] %d",cnt,pr);
            if ( 11==cnt )
            {
                goto END;
            }
        }
    }

END:
    info_print("Sum = %d",sum);
    return;
}
示例#4
0
void test01 ( int32_t argc, char * argv[] )
{
    uint32_t x = 3797,y,cnt=0,sum=0;

    if ( 2==argc )
    {
        x = strtol(argv[1],NULL,10);
    }
    
    info_print("    Left truncate:");
    y = x;
    while ( y )
    {
        info_print("%d",y);
        y = ltrunk(y);
    }
    
    info_print("    Right truncate:");
    y = x;
    while ( y )
    {
        info_print("%d",y);
        y = rtrunk(y);
    }

}
示例#5
0
	void Server::main_loop()
	{
		sigset_t sigset_tmpl, sigset;
		pthread_sigmask(0, NULL, &sigset_tmpl);
		sigaddset(&sigset_tmpl, SIGUSR1);
		sigset = sigset_tmpl;
		auto_ptr<DataStream> stream;
		try{
			info_printf(err_cons, "Waiting for connections.");
			while (!shutting_down){
				auto_ptr<DataStream> stream = server.accept(sigset, shutting_down);
				Mutex::Locker l(open_sessions_mutex);
				if (!shutting_down && get_sessions_count() < get_config_max_sessions()){
					try{
						auto_ptr<PackageStream> pstream(new PackageCodec(stream, get_config_max_package_size()));
						shared_ptr<Session> new_session(new Session(*this, pstream));
						open_sessions[new_session->get_id()] = new_session;
						new_session->launch();
					} catch (LoximException &ex) {
						warning_print(err_cons, "Caught exception while creating new session:");
						warning_print(err_cons, ex.to_string());
					} catch (...) {
						warning_print(err_cons, "Caught unknown exception while creating new session");
					}
				}
			}
		} catch (OperationCancelled &ex) {
			//this is a normal way of exiting the server
		} catch (LoximException &ex){
			info_print(err_cons, "Caught exception in server loop, shutting down");
			debug_print(err_cons, ex.to_string());
		} catch (...) {
			info_print(err_cons, "Caught unknown exception in server loop, shutting down");
		}
		{
			Mutex::Locker l(open_sessions_mutex);
			shutting_down = 1;
			info_print(err_cons, "Quitting, telling sessions to shut down");
			for (set<pair<const uint64_t, shared_ptr<Session> > >::iterator i = open_sessions.begin(); i != open_sessions.end(); i++){
				i->second->shutdown(0);
			}
		}
		info_print(err_cons, "Joining threads");
		for (set<pair<const uint64_t, shared_ptr<Session> > >::iterator i = open_sessions.begin(); i != open_sessions.end(); i++){
			pthread_join(i->second->get_thread(), NULL);
		}
		open_sessions.clear();
		info_print(err_cons, "Threads joined");
	}
示例#6
0
void test02 ( int32_t argc, char * argv[] )
{
    char dig[] = "0123456789";
    uint64_t y = 10*9*8*7*6*5*4*3*2*1;

    g_cnt=0;
    permute(dig,0,10);
    info_print("y     = %llu",y);
    info_print("g_cnt = %llu",g_cnt);

    /*
    memset(d,0,11);
    memcpy(d,dig,k);
    permute(d,0,k);
    */
}
示例#7
0
	void Server::shutdown()
	{
		info_print(err_cons, "Server shutdown called");
		SystemStatsLib::StatsDumper::get_instance()->kill();
		SystemStatsLib::StatsDumper::get_instance()->join();
		pthread_kill(thread, SIGUSR1);
	}
示例#8
0
redisContext *_myredisConnect(struct config config) {
    redisContext *c = NULL;
    redisReply *reply;
    char cmd[256];
    int len;

   if (config.type == CONN_TCP) {
        c = redisConnect(config.tcp.host, config.tcp.port);
    } else if (config.type == CONN_UNIX_SOCK) {
        c = redisConnectUnix(config.unix_sock.path);
    } else {
        assert(NULL);
    }

    if (c->err && pFile) {
    	info_print("Connection error: %s\n", c->errstr);
	return c;
    }


    /* Authenticate */
    if (config.auth) {
        reply = redisCommand(c,"AUTH %s",config.password);
        if(reply) {
            freeReplyObject(reply);
	}
    }
    return c;
}
示例#9
0
/* main function*/
int main(int argc, char *argv[])
{	
	trace_print("\n %s %s(): Debug level set to %d\n",__FILE__,__func__,DEBUG);

	/* print the message */
	info_print ("\n** Hello word **\n");
	return 0;
}
示例#10
0
/* Internal Helper Functions */
redisContext *_redis_context_init() {
    if (!sredisContext) {
	sredisContext = _myredisConnect(cfg);
	info_print("try to connect to redis db \n");
    }
    if (!sredisContext) {
       return NULL;
    }
    return sredisContext;
}
示例#11
0
void Port_uart_swap()
{
#if Port_SwapMode_define == USBInterSwap
	info_print("Interconnect Line Swap");

	// UART Swap
	GPIO_Ctrl( uart_swap_pin1, GPIO_Type_DriveToggle, GPIO_Config_None );
#else
	warn_print("Unsupported");
#endif
}
示例#12
0
void p41 ( void )
{
    //char dig[] = "0123456789";
    char dig[] = "0123456789";
    //int32_t len = 10;

    permute(dig,0,10);
    info_print("g_pr = %llu",g_pr);

    return;
}
示例#13
0
int start_consumer_worker(void) {
    apr_status_t rv = -1;
    if(!mem_pool && !thrp) {
    	initialize_apr();

    	rv = apr_thread_pool_push(thrp, consumer, NULL, 0, NULL);
    	check_error(rv);

    	info_print("start_consumer_worker: initialize_apr,apr_thread_pool_push|rv= %d\n",rv);
    }
}
示例#14
0
void __acc_cdecl_va infoHeader(const char *format, ...)
{
    if (opt->info_mode <= 0)
        return;
    va_list args;
    char buf[1024];
    va_start(args,format);
    upx_vsnprintf(buf,sizeof(buf),format,args);
    va_end(args);
    info_print(buf);
    info_header = 1;
}
示例#15
0
long long _do_redis_command( const char ** args,const size_t * argvlen, size_t arg_count) {

    pthread_mutex_lock(&sredisContext_mutex);

    redisContext *c = NULL;
    redisReply *reply;


    c = (redisContext*)_redis_context_init();
    if (!c) {
	info_print("_redis_context_init return null, connect failed\n");
	pthread_mutex_unlock(&sredisContext_mutex);
	return -1;
    }

    debug_print("%s %s %s\n",args[0] ,args[1],args[2]);

    reply =  redisCommandArgv(c,arg_count,args,argvlen);
    if(!reply) {

    	c = (redisContext*)_redis_context_reinit();
        if (!c) {
            info_print("_do_redis_command, Cannot reconnect to redis\n ");
            pthread_mutex_unlock(&sredisContext_mutex);
            return -1;
        }
    	reply = redisCommandArgv(c,arg_count,args,argvlen);
        if (!reply) {
            info_print("_do_redis_command, reconnect to redis and re-execute redisCommandArgv failed\n ");
            pthread_mutex_unlock(&sredisContext_mutex);
            return -1;
        }
    }

	if(reply) {
	    freeReplyObject(reply);
	}
	pthread_mutex_unlock(&sredisContext_mutex);
    return 0;
}
示例#16
0
void __acc_cdecl_va info(const char *format, ...)
{
    if (opt->info_mode <= 0)
        return;
    va_list args;
    char buf[1024];
    const int n = 4 * info_header;
    memset(buf, ' ', n);
    va_start(args,format);
    upx_vsnprintf(buf+n,sizeof(buf)-n,format,args);
    va_end(args);
    info_print(buf);
}
示例#17
0
// Custom capability examples
// Refer to kll.h in Macros/PartialMap for state and stateType information
void CustomAction_action1_capability( uint8_t state, uint8_t stateType, uint8_t *args )
{
	// Display capability name
	// XXX This is required for debug cli to give you a list of capabilities
	if ( stateType == 0xFF && state == 0xFF )
	{
		print("CustomAction_action1_capability()");
		return;
	}

	// Prints Action1 info message to the debug cli
	info_print("Action1");
}
示例#18
0
/* Internal Helper Functions */
redisContext *_redis_context_reinit() {
    if (!sredisContext) {
    	sredisContext = _myredisConnect(cfg);
    }
    else {
    	info_print("try to reconnect to redis db \n");

    	redisFree(sredisContext);
    	sredisContext = NULL;
    	sredisContext = _myredisConnect(cfg);
    }

    return sredisContext;
}
示例#19
0
void Port_cross()
{
#if Port_SwapMode_define == USBInterSwap
	info_print("Interconnect Line Cross");

	// UART Tx/Rx cross-over
	GPIO_Ctrl( uart_cross_pin1, GPIO_Type_DriveToggle, GPIO_Config_None );

	// Reset interconnects
	Connect_reset();
#else
	warn_print("Unsupported");
#endif
}
示例#20
0
void Port_usb_swap()
{
#if Port_SwapMode_define == USBSwap || Port_SwapMode_define == USBInterSwap
	info_print("USB Port Swap");

	// USB Swap
	GPIO_Ctrl( usb_swap_pin1, GPIO_Type_DriveToggle, GPIO_Config_None );

	// Re-initialize usb
	// Call usb_configured() to check if usb is ready
	usb_reinit();
#else
	warn_print("Unsupported");
#endif
}
示例#21
0
/*	
set server info.
*/
my_bool redis_servers_set_v2_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {

    pthread_mutex_lock(&sredisContext_mutex);
	
   
    redisContext *c = NULL;
    if(args->arg_count < 2 || args->arg_type[0] != STRING_RESULT || args->arg_type[1] != INT_RESULT) {
         strncpy(message,"Wrong arguments to Redis function.  Usage: 'tcp.host' (string) 'tcp.port' (string)", MYSQL_ERRMSG_SIZE);
	 pthread_mutex_unlock(&sredisContext_mutex);
         return -1;
    }

    if(args->arg_count == 3 && args->arg_type[2] != STRING_RESULT) {
        strncpy(message,"Wrong arguments to Redis function1.  Usage: 'password' (string)", MYSQL_ERRMSG_SIZE);
        pthread_mutex_unlock(&sredisContext_mutex);
        return -2;
    }

    strncpy(cfg.tcp.host, (char*)args->args[0], 256);
    cfg.tcp.port = *((longlong*)args->args[1]);
    if (args->arg_count == 3) {
       cfg.auth = 1;
       strncpy(cfg.password, (char*)args->args[2], 256);
    }
     _redis_context_deinit();
     c = (redisContext*)_redis_context_init();;
    if (!c) {
          strncpy(message, "Failed to connect to Redis", MYSQL_ERRMSG_SIZE);
	  pthread_mutex_unlock(&sredisContext_mutex);
      return 2;
    }
	
	//open log file
    pFile = fopen(cfg.log_file,"a");

	//start consumer thread.
    start_consumer_worker();
    pthread_mutex_unlock(&sredisContext_mutex);

    info_print("redis_servers_set_v2_init done.\n ");
    return 0;
}
示例#22
0
void processKeyValue( uint8_t keyValue )
{
	// Finalize output buffer
	// Mask 8th bit
	keyValue &= 0x7F;

	// Interpret scan code
	switch ( keyValue )
	{
	case 0x40: // Clear buffer command
		info_print("CLEAR!");

		BufferReadyToClear = 1;
		break;
	case 0x7F:
		scan_lockKeyboard();
		_delay_ms(3000);
		scan_unlockKeyboard();

	default:
		// Make sure the key isn't already in the buffer
		for ( uint8_t c = 0; c < KeyIndex_BufferUsed + 1; c++ )
		{
			// Key isn't in the buffer yet
			if ( c == KeyIndex_BufferUsed )
			{
				Macro_bufferAdd( keyValue );
				break;
			}

			// Key already in the buffer
			if ( KeyIndex_Buffer[c] == keyValue )
				break;
		}
		break;
	}
}
示例#23
0
int opt_replace_const(expr *prog)
{
    if( !prog )
        return 0;

    // Get current number of variables, used to estimate the
    // memory usage of each new constant added to the program
    vars *v = pgm_get_vars( expr_get_program(prog) );
    unsigned nfloat  = vars_get_count(v, vtFloat);
    unsigned nstring = vars_get_count(v, vtString);
    unsigned nvar    = vars_get_total(v);

    // If not enough variables, exit
    if( nvar > 255 )
        return 0;

    // Search all constant values in the program and store
    // the value and number of times repeated
    cvalue_list *lst = darray_new(cvalue,256);
    int num = update_cvalue(prog, lst);

    // If no constant values, exit.
    if( !num )
    {
        darray_free(lst);
        return 0;
    }

    // Now, sort constant values by "usage gain"
    cvalue_list_sort(lst);

    // Extract all constant values that produce a gain:
    unsigned cs = 0, cn = 0;
    for(unsigned i=0; i<lst->len && nvar<256; i++)
    {
        cvalue *cv = lst->data + i;
        int bytes = cvalue_saved_bytes(cv);
        // Add one extra byte if the variable number is
        // more than 127:
        if( nvar > 127 )
            bytes += cv->count;

        if( bytes > 0 )
            continue;

        // Ok, we can replace the variable
        if( cv->str )
        {
            char name[256];
            sprintf(name, "__s%d", cs);
            cs++;
            nstring++;
            nvar++;
            info_print(expr_get_file_name(prog), 0, "replacing constant var %s$=\"%.*s\" (%d times, %d bytes)\n",
                       name, cv->slen, cv->str, cv->count, bytes);
            // Creates the variable
            cv->vid = vars_new_var(v, name, vtString, expr_get_file_name(prog), 0);
            cv->status = 1;
            // Replace all instances of the constant value with the variables
            replace_cvalue(prog, cv);
        }
        else
        {
            char name[256];
            if( cv->num < 100000 && cv->num == round(cv->num) )
            {
                if( cv->num >= 0 )
                    sprintf(name, "__n%.0f", cv->num);
                else
                    sprintf(name, "__n_%.0f", -cv->num);
            }
            else if( cv->num < 1000 && round(10000000 * cv->num) == 1000000 * round(10 * cv->num) )
            {
                if( cv->num >= 0 )
                    sprintf(name, "__n%.0f_%.0f", trunc(cv->num), 10 * (cv->num - trunc(cv->num)));
                else
                    sprintf(name, "__n_%.0f_%.0f", -trunc(cv->num), -10 * (cv->num - trunc(cv->num)) );
            }
            else
            {
                sprintf(name, "__nd%d", cn);
                cn++;
            }
            nfloat++;
            nvar++;
            info_print(expr_get_file_name(prog), 0, "replacing constant var %s=%g (%d times, %d bytes)\n",
                       name, cv->num, cv->count, bytes);
            cv->vid = vars_new_var(v, name, vtFloat, expr_get_file_name(prog), 0);
            cv->status = 1;
            // Replace all instances of the constant value with the variables
            replace_cvalue(prog, cv);
        }
    }

    // Sort again by absolute value, this tends to generate smaller code
    cvalue_list_sort_abs(lst);

    // Now, add all variable initializations to the program, first numeric, then strings:
    expr *init = 0, *last_stmt = 0, *dim = 0;
    for(unsigned i=0; i<lst->len; i++)
    {
        cvalue *cv = lst->data + i;
        if( cv->status == 1 && !cv->str )
        {
           last_stmt = create_num_assign(prog->mngr, lst, last_stmt, cv->num, cv->vid);
           if( !init ) init = last_stmt;
           cv->status = 2;
        }
    }
    // Now, all DIM expressions
    for(unsigned i=0; i<lst->len; i++)
    {
        cvalue *cv = lst->data + i;
        if( cv->status == 1 && cv->str )
        {
            dim = create_str_dim(prog->mngr, lst, dim, cv->slen, cv->vid);
            cv->status = 2;
        }
    }
    if( dim )
    {
        last_stmt = expr_new_stmt(prog->mngr, last_stmt, dim, STMT_DIM);
        if( !init ) init = last_stmt;
    }
    // And all string assignments
    for(unsigned i=0; i<lst->len; i++)
    {
        cvalue *cv = lst->data + i;
        if( cv->status == 2 && cv->str )
        {
            last_stmt = create_str_assign(prog->mngr, last_stmt, cv->str, cv->slen, cv->vid);
            if( !init ) init = last_stmt;
            cv->status = 2;
        }
    }

    add_to_prog(prog, init);

    darray_free(lst);
    return 0;
}
示例#24
0
int
main(int argc, char **argv)
{
	struct ata_cmd iocmd;
	int fd;

	if ((fd = open("/dev/ata", O_RDWR)) < 0)
		err(1, "control device not found");

	if (argc < 2)
		usage();

	bzero(&iocmd, sizeof(struct ata_cmd));

	if (argc > 2 && strcmp(argv[1], "create")) {
		int chan;

		if (!strcmp(argv[1], "delete") ||
		    !strcmp(argv[1], "status") ||
		    !strcmp(argv[1], "rebuild")) {
			if (!(sscanf(argv[2], "%d", &chan) == 1 ||
			      sscanf(argv[2], "ar%d", &chan) == 1))
				usage();
		}
		else {
			if (!(sscanf(argv[2], "%d", &chan) == 1 ||
			      sscanf(argv[2], "ata%d", &chan) == 1))
				usage();
		}
		iocmd.channel = chan;
	}

	if (!strcmp(argv[1], "list") && argc == 2) {
		int unit = 0;

		while (info_print(fd, unit++, 1) != ENXIO);
	}
	else if (!strcmp(argv[1], "info") && argc == 3) {
		info_print(fd, iocmd.channel, 0);
	}
	else if (!strcmp(argv[1], "cap") && argc == 4) {
		ata_cap_print(fd, iocmd.channel, atoi(argv[3]));
	}
	else if (!strcmp(argv[1], "enclosure") && argc == 4) {
		iocmd.device = atoi(argv[3]);
		iocmd.cmd = ATAENCSTAT;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			err(1, "ioctl(ATAENCSTAT)");
		printf("fan RPM: %d temp: %.1f 5V: %.2f 12V: %.2f\n",
			iocmd.u.enclosure.fan,
			(double)iocmd.u.enclosure.temp / 10,
			(double)iocmd.u.enclosure.v05 / 1000,
			(double)iocmd.u.enclosure.v12 / 1000);
	}
	else if (!strcmp(argv[1], "detach") && argc == 3) {
		iocmd.cmd = ATADETACH;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			err(1, "ioctl(ATADETACH)");
	}
	else if (!strcmp(argv[1], "attach") && argc == 3) {
		iocmd.cmd = ATAATTACH;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			err(1, "ioctl(ATAATTACH)");
		info_print(fd, iocmd.channel, 0);
	}
	else if (!strcmp(argv[1], "reinit") && argc == 3) {
		iocmd.cmd = ATAREINIT;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			warn("ioctl(ATAREINIT)");
		info_print(fd, iocmd.channel, 0);
	}
	else if (!strcmp(argv[1], "create")) {
		int disk, dev, offset;

		iocmd.cmd = ATARAIDCREATE;
		if (!strcmp(argv[2], "RAID0") || !strcmp(argv[2], "stripe"))
			iocmd.u.raid_setup.type = 1;
		if (!strcmp(argv[2], "RAID1") || !strcmp(argv[2],"mirror"))
			iocmd.u.raid_setup.type = 2;
		if (!strcmp(argv[2], "RAID0+1"))
			iocmd.u.raid_setup.type = 3;
		if (!strcmp(argv[2], "SPAN") || !strcmp(argv[2], "JBOD"))
			iocmd.u.raid_setup.type = 4;
		if (!iocmd.u.raid_setup.type)
		     usage();
		
		if (iocmd.u.raid_setup.type & 1) {
			if (!sscanf(argv[3], "%d",
				    &iocmd.u.raid_setup.interleave) == 1)
				usage();
			offset = 4;
		}
		else
			offset = 3;
		
		for (disk = 0; disk < 16 && (offset + disk) < argc; disk++) {
			if (!(sscanf(argv[offset + disk], "%d", &dev) == 1 ||
			      sscanf(argv[offset + disk], "ad%d", &dev) == 1))
				usage();
			iocmd.u.raid_setup.disks[disk] = dev;
		}
		iocmd.u.raid_setup.total_disks = disk;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			err(1, "ioctl(ATARAIDCREATE)");
		else
			printf("ar%d created\n", iocmd.u.raid_setup.unit);
	}
	else if (!strcmp(argv[1], "delete") && argc == 3) {
		iocmd.cmd = ATARAIDDELETE;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			warn("ioctl(ATARAIDDELETE)");
	}
	else if (!strcmp(argv[1], "rebuild") && argc == 3) {
		iocmd.cmd = ATARAIDREBUILD;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			warn("ioctl(ATARAIDREBUILD)");
	}
	else if (!strcmp(argv[1], "status") && argc == 3) {
		int i;

		iocmd.cmd = ATARAIDSTATUS;
		if (ioctl(fd, IOCATA, &iocmd) < 0)
			err(1, "ioctl(ATARAIDSTATUS)");
		printf("ar%d: ATA ", iocmd.channel);
		switch (iocmd.u.raid_status.type) {
		case AR_RAID0:
			printf("RAID0");
			break;
		case AR_RAID1:
			printf("RAID1");
			break;
		case AR_RAID0 | AR_RAID1:
			printf("RAID0+1");
			break;
		case AR_SPAN:
			printf("SPAN");
			break;
		}
		printf(" subdisks: ");
		for (i = 0; i < iocmd.u.raid_status.total_disks; i++) {
			if (iocmd.u.raid_status.disks[i] >= 0)
				printf("ad%d ", iocmd.u.raid_status.disks[i]);
			else
				printf("DOWN ");
		}
		printf("status: ");
		switch (iocmd.u.raid_status.status) {
		case AR_READY:
			printf("READY\n");
			break;
		case AR_READY | AR_DEGRADED:
			printf("DEGRADED\n");
			break;
		case AR_READY | AR_DEGRADED | AR_REBUILDING:
			printf("REBUILDING %d%% completed\n",
				iocmd.u.raid_status.progress);
			break;
		default:
			printf("BROKEN\n");
		}
	}
	else if (!strcmp(argv[1], "mode") && (argc == 3 || argc == 5)) {
		if (argc == 5) {
			iocmd.cmd = ATASMODE;
			iocmd.device = -1;
			iocmd.u.mode.mode[0] = str2mode(argv[3]);
			iocmd.u.mode.mode[1] = str2mode(argv[4]);
			if (ioctl(fd, IOCATA, &iocmd) < 0)
				warn("ioctl(ATASMODE)");
		}
		if (argc == 3 || argc == 5) {
			iocmd.cmd = ATAGMODE;
			iocmd.device = -1;
			if (ioctl(fd, IOCATA, &iocmd) < 0)
				err(1, "ioctl(ATAGMODE)");
			printf("Master = %s \nSlave  = %s\n",
				mode2str(iocmd.u.mode.mode[0]), 
				mode2str(iocmd.u.mode.mode[1]));
		}
	}
	else
	    	usage();
	exit(0);
}
示例#25
0
int
main(int argc, char **argv)
{
    int fd;

    if (argc < 2)
        usage();

    if (!strcmp(argv[1], "mode") && (argc == 3 || argc == 4)) {
        int disk, mode;
        char device[64];

        if (!(sscanf(argv[2], "ad%d", &disk) == 1 ||
                sscanf(argv[2], "acd%d", &disk) == 1 ||
                sscanf(argv[2], "afd%d", &disk) == 1 ||
                sscanf(argv[2], "ast%d", &disk) == 1)) {
            fprintf(stderr, "natacontrol: Invalid device %s\n",
                    argv[2]);
            exit(EX_USAGE);
        }
        sprintf(device, "/dev/%s", argv[2]);
        if ((fd = open(device, O_RDONLY)) < 0)
            err(1, "device not found");
        if (argc == 4) {
            mode = str2mode(argv[3]);
            if (ioctl(fd, IOCATASMODE, &mode) < 0)
                warn("ioctl(IOCATASMODE)");
        }
        if (argc == 3 || argc == 4) {
            if (ioctl(fd, IOCATAGMODE, &mode) < 0)
                err(1, "ioctl(IOCATAGMODE)");
            printf("current mode = %s\n", mode2str(mode));
        }
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "cap") && argc == 3) {
        int disk;
        char device[64];

        if (!(sscanf(argv[2], "ad%d", &disk) == 1 ||
                sscanf(argv[2], "acd%d", &disk) == 1 ||
                sscanf(argv[2], "afd%d", &disk) == 1 ||
                sscanf(argv[2], "ast%d", &disk) == 1)) {
            fprintf(stderr, "natacontrol: Invalid device %s\n",
                    argv[2]);
            exit(EX_USAGE);
        }
        sprintf(device, "/dev/%s", argv[2]);
        if ((fd = open(device, O_RDONLY)) < 0)
            err(1, "device not found");
        ata_cap_print(fd);
        exit(EX_OK);
    }

    if ((fd = open("/dev/ata", O_RDWR)) < 0)
        err(1, "control device not found");

    if (!strcmp(argv[1], "list") && argc == 2) {
        int maxchannel, channel;

        if (ioctl(fd, IOCATAGMAXCHANNEL, &maxchannel) < 0)
            err(1, "ioctl(IOCATAGMAXCHANNEL)");
        for (channel = 0; channel < maxchannel; channel++)
            info_print(fd, channel, 1);
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "info") && argc == 3) {
        int channel;

        if (!(sscanf(argv[2], "ata%d", &channel) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid channel %s\n", argv[2]);
            exit(EX_USAGE);
        }
        info_print(fd, channel, 0);
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "detach") && argc == 3) {
        int channel;

        if (!(sscanf(argv[2], "ata%d", &channel) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid channel %s\n", argv[2]);
            exit(EX_USAGE);
        }
        if (ioctl(fd, IOCATADETACH, &channel) < 0)
            err(1, "ioctl(IOCATADETACH)");
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "attach") && argc == 3) {
        int channel;

        if (!(sscanf(argv[2], "ata%d", &channel) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid channel %s\n", argv[2]);
            exit(EX_USAGE);
        }
        if (ioctl(fd, IOCATAATTACH, &channel) < 0)
            err(1, "ioctl(IOCATAATTACH)");
        info_print(fd, channel, 0);
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "reinit") && argc == 3) {
        int channel;

        if (!(sscanf(argv[2], "ata%d", &channel) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid channel %s\n", argv[2]);
            exit(EX_USAGE);
        }
        if (ioctl(fd, IOCATAREINIT, &channel) < 0)
            warn("ioctl(IOCATAREINIT)");
        info_print(fd, channel, 0);
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "create")) {
        int disk, dev, offset;
        struct ata_ioc_raid_config config;

        bzero(&config, sizeof(config));
        if (argc > 2) {
            if (!strcasecmp(argv[2], "RAID0") ||
                    !strcasecmp(argv[2], "stripe"))
                config.type = AR_RAID0;
            if (!strcasecmp(argv[2], "RAID1") ||
                    !strcasecmp(argv[2],"mirror"))
                config.type = AR_RAID1;
            if (!strcasecmp(argv[2], "RAID0+1") ||
                    !strcasecmp(argv[2],"RAID10"))
                config.type = AR_RAID01;
            if (!strcasecmp(argv[2], "RAID5"))
                config.type = AR_RAID5;
            if (!strcasecmp(argv[2], "SPAN"))
                config.type = AR_SPAN;
            if (!strcasecmp(argv[2], "JBOD"))
                config.type = AR_JBOD;
        }
        if (!config.type) {
            fprintf(stderr, "natacontrol: Invalid RAID type %s\n",
                    argv[2]);
            fprintf(stderr, "natacontrol: Valid RAID types: \n");
            fprintf(stderr, "             stripe | mirror | "
                    "RAID0 | RAID1 | RAID0+1 | RAID5 | "
                    "SPAN | JBOD\n");
            exit(EX_USAGE);
        }

        if (config.type == AR_RAID0 ||
                config.type == AR_RAID01 ||
                config.type == AR_RAID5) {
            if (argc < 4 ||
                    !sscanf(argv[3], "%d", &config.interleave) == 1) {
                fprintf(stderr,
                        "natacontrol: Invalid interleave %s\n",
                        argv[3]);
                exit(EX_USAGE);
            }
            offset = 4;
        }
        else
            offset = 3;

        for (disk = 0; disk < 16 && (offset + disk) < argc; disk++) {
            if (!(sscanf(argv[offset + disk], "ad%d", &dev) == 1)) {
                fprintf(stderr,
                        "natacontrol: Invalid disk %s\n",
                        argv[offset + disk]);
                exit(EX_USAGE);
            }
            config.disks[disk] = dev;
        }

        if ((config.type == AR_RAID1 || config.type == AR_RAID01) &&
                disk < 2) {
            fprintf(stderr, "natacontrol: At least 2 disks must be "
                    "specified\n");
            exit(EX_USAGE);
        }

        config.total_disks = disk;
        if (ioctl(fd, IOCATARAIDCREATE, &config) < 0)
            err(1, "ioctl(IOCATARAIDCREATE)");
        else
            printf("ar%d created\n", config.lun);
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "delete") && argc == 3) {
        int array;

        if (!(sscanf(argv[2], "ar%d", &array) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid array %s\n", argv[2]);
            exit(EX_USAGE);
        }
        if (ioctl(fd, IOCATARAIDDELETE, &array) < 0)
            warn("ioctl(IOCATARAIDDELETE)");
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "addspare") && argc == 4) {
        struct ata_ioc_raid_config config;

        if (!(sscanf(argv[2], "ar%d", &config.lun) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid array %s\n", argv[2]);
            usage();
        }
        if (!(sscanf(argv[3], "ad%d", &config.disks[0]) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid disk %s\n", argv[3]);
            usage();
        }
        if (ioctl(fd, IOCATARAIDADDSPARE, &config) < 0)
            warn("ioctl(IOCATARAIDADDSPARE)");
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "rebuild") && argc == 3) {
        int array;

        if (!(sscanf(argv[2], "ar%d", &array) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid array %s\n", argv[2]);
            usage();
        }
        if (ioctl(fd, IOCATARAIDREBUILD, &array) < 0)
            warn("ioctl(IOCATARAIDREBUILD)");
        else {
            char device[64];
            char *buffer;
            ssize_t len;
            int arfd;

            if (daemon(0, 1) == -1)
                err(1, "daemon");
            nice(20);
            snprintf(device, sizeof(device), "/dev/ar%d",
                     array);
            if ((arfd = open(device, O_RDONLY)) == -1)
                err(1, "open %s", device);
            if ((buffer = malloc(1024 * 1024)) == NULL)
                err(1, "malloc");
            while ((len = read(arfd, buffer, 1024 * 1024)) > 0)
                ;
            if (len == -1)
                err(1, "read");
            else
                fprintf(stderr,
                        "atacontrol: ar%d rebuild completed\n",
                        array);
            free(buffer);
            close(arfd);
        }
        exit(EX_OK);
    }
    if (!strcmp(argv[1], "status") && argc == 3) {
        struct ata_ioc_raid_config config;
        int i;

        if (!(sscanf(argv[2], "ar%d", &config.lun) == 1)) {
            fprintf(stderr,
                    "natacontrol: Invalid array %s\n", argv[2]);
            usage();
        }
        if (ioctl(fd, IOCATARAIDSTATUS, &config) < 0)
            err(1, "ioctl(IOCATARAIDSTATUS)");

        printf("ar%d: ATA ", config.lun);
        switch (config.type) {
        case AR_RAID0:
            printf("RAID0 stripesize=%d", config.interleave);
            break;
        case AR_RAID1:
            printf("RAID1");
            break;
        case AR_RAID01:
            printf("RAID0+1 stripesize=%d", config.interleave);
            break;
        case AR_RAID5:
            printf("RAID5 stripesize=%d", config.interleave);
            break;
        case AR_JBOD:
            printf("JBOD");
        case AR_SPAN:
            printf("SPAN");
            break;
        }
        printf(" subdisks: ");
        for (i = 0; i < config.total_disks; i++) {
            if (config.disks[i] >= 0)
                printf("ad%d ", config.disks[i]);
            else
                printf("DOWN ");
        }
        printf("status: ");
        switch (config.status) {
        case AR_READY:
            printf("READY\n");
            break;
        case AR_READY | AR_DEGRADED:
            printf("DEGRADED\n");
            break;
        case AR_READY | AR_DEGRADED | AR_REBUILDING:
            printf("REBUILDING %d%% completed\n",
                   config.progress);
            break;
        default:
            printf("BROKEN\n");
        }
        exit(EX_OK);
    }
    usage();
    exit(EX_OK);
}
static int __devinit	touch_tool_probe( struct platform_device *pdev )
{

	struct synaptics_rmi4_data	*rmi_data = ( struct synaptics_rmi4_data* )pdev->dev.platform_data;

	struct touch_tool_data		*tool_data;

	if( !rmi_data )
	{

		printk( "TTUCH : The pointer of RMI data is NULL\n" );

		return	-ENOMEM;

	}

	if( !( tool_data = allocate_memory() ) )
	{

		printk( "TTUCH : allocate Memory failed\n" );

		return	-ENOMEM;

	}

	if( !create_command_string_list( &tool_data->string ) )
	{

		printk( "TTUCH : Create command failed\n" );

		release_memory( tool_data );

		return	-EINVAL;

	}

	tool_data->rmi_data = rmi_data;

	if( load_command( &tool_data->command, get_load_command_pointer(), get_load_command_counter() ) )
	{

		struct control_node_load	file_node;

		// Create file node in sys/class/touch/rmi4
		file_node.class_name = "touch", file_node.device_name = "rmi4";

		file_node.file_node_data = tool_data, file_node.control_read = tool_command, file_node.control_write = tool_control, file_node.info_read = tool_info;

		tool_data->file_node_class	= control_file_node_register( &file_node );

		dev_set_drvdata( &pdev->dev, tool_data );

		info_print( INFO_BUFFER_INIT, NULL, tool_data->info_buffer, INFO_BUFFER_SIZE );

		INIT_LIST_HEAD( &tool_data->descriptor_list );

		get_page_description( tool_data );

		get_touch_ic_info( tool_data, log_print );
 
		printk( "TTUCH : Touch tool driver is ready\n" );

		return	0;

	}

	release_memory( tool_data );

	return	-EINVAL;

}