Example #1
0
QDataStream &operator<<(QDataStream &s, const QPen &p)
{
    QPenData *dd = static_cast<QPenData *>(p.d);
    if (s.version() < 3) {
        s << (quint8)p.style();
    } else if (s.version() < QDataStream::Qt_4_3) {
        s << (quint8)(p.style() | p.capStyle() | p.joinStyle());
    } else {
        s << (quint16)(p.style() | p.capStyle() | p.joinStyle());
        s << (bool)(dd->cosmetic);
    }

    if (s.version() < 7) {
        s << (quint8)p.width();
        s << p.color();
    } else {
        s << double(p.widthF());
        s << p.brush();
        s << double(p.miterLimit());
        if (sizeof(qreal) == sizeof(double)) {
            s << p.dashPattern();
        } else {
            // ensure that we write doubles here instead of streaming the pattern
            // directly; otherwise, platforms that redefine qreal might generate
            // data that cannot be read on other platforms.
            QVector<qreal> pattern = p.dashPattern();
            s << quint32(pattern.size());
            for (int i = 0; i < pattern.size(); ++i)
                s << double(pattern.at(i));
        }
        if (s.version() >= 9)
            s << double(p.dashOffset());
    }
    return s;
}
static int ethtool_get_drvinfo(struct net_device *dev, void *useraddr)
{
	struct ethtool_drvinfo info;
	struct ethtool_ops *ops = ethtool_ops;

	if (!ops->get_drvinfo)
		return -EOPNOTSUPP;

	memset(&info, 0, sizeof(info));
	info.cmd = ETHTOOL_GDRVINFO;
	ops->get_drvinfo(dev, &info);

	if (ops->self_test_count)
		info.testinfo_len = ops->self_test_count(dev);
	if (ops->get_stats_count)
		info.n_stats = ops->get_stats_count(dev);
	if (ops->get_regs_len)
		info.regdump_len = ops->get_regs_len(dev);
	if (ops->get_eeprom_len)
		info.eedump_len = ops->get_eeprom_len(dev);

	if (copy_to_user(useraddr, &info, sizeof(info)))
		return -EFAULT;
	return 0;
}
static int ethtool_self_test(struct net_device *dev, char *useraddr)
{
	struct ethtool_test test;
	struct ethtool_ops *ops = ethtool_ops;
	u64 *data;
	int ret;

	if (!ops->self_test || !ops->self_test_count)
		return -EOPNOTSUPP;

	if (copy_from_user(&test, useraddr, sizeof(test)))
		return -EFAULT;

	test.len = ops->self_test_count(dev);
	data = kmalloc(test.len * sizeof(u64), GFP_USER);
	if (!data)
		return -ENOMEM;

	ops->self_test(dev, &test, data);

	ret = -EFAULT;
	if (copy_to_user(useraddr, &test, sizeof(test)))
		goto out;
	useraddr += sizeof(test);
	if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
		goto out;
	ret = 0;

 out:
	kfree(data);
	return ret;
}
Example #4
0
static unsigned int lcm_compare_id(void)
{
	unsigned int id;
	unsigned char buffer[5];
	unsigned int array[5];
#ifdef BUILD_LK
	upmu_set_rg_vgp6_vosel(6);
	upmu_set_rg_vgp6_en(1);
#else
	hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_2800, "LCM");
#endif

	mt_set_gpio_mode(GPIO_LCD_RST_EN, GPIO_MODE_00);
	mt_set_gpio_dir(GPIO_LCD_RST_EN, GPIO_DIR_OUT);
	mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ONE);
	MDELAY(10);
	mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ZERO);
	MDELAY(10);
	mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ONE);
	MDELAY(100);

	push_table(lcm_compare_id_setting,
		   sizeof(lcm_compare_id_setting) /
		   sizeof(struct LCM_setting_table), 1);

	read_reg_v2(0xc5, buffer, 2);
	id = ((buffer[0] << 8) | buffer[1]);
#if defined(BUILD_LK)
	printf
	    ("%s, [rm68180_boe60_wcl]  buffer[0] = [0x%d] buffer[2] = [0x%d] ID = [0x%d]\n",
	     __func__, buffer[0], buffer[1], id);
#endif

	return ((LCM_RM68180_ID == id)? 1 : 0);
}
Example #5
0
static const char *
trapname(int trapno) {
    static const char * const excnames[] = {
        "Divide error",
        "Debug",
        "Non-Maskable Interrupt",
        "Breakpoint",
        "Overflow",
        "BOUND Range Exceeded",
        "Invalid Opcode",
        "Device Not Available",
        "Double Fault",
        "Coprocessor Segment Overrun",
        "Invalid TSS",
        "Segment Not Present",
        "Stack Fault",
        "General Protection",
        "Page Fault",
        "(unknown trap)",
        "x87 FPU Floating-Point Error",
        "Alignment Check",
        "Machine-Check",
        "SIMD Floating-Point Exception"
    };

    if (trapno < sizeof(excnames)/sizeof(const char * const)) {
        return excnames[trapno];
    }
    if (trapno >= IRQ_OFFSET && trapno < IRQ_OFFSET + 16) {
        return "Hardware Interrupt";
    }
    return "(unknown trap)";
}
Example #6
0
Stack CreateStack(int MaxElements)
{
    Stack S;

    S = (Stack) malloc (sizeof(struct StackRecord));
    if(S == 0) {
        printf("No memory for stack!\n");
        return 0;
    }

    S->Array = (ElementType*) malloc (sizeof(ElementType)*MaxElements);
    if(S->Array == 0) {
        printf("No memory for stack array\n");
        free(S);
        return 0;
    }

    S->MArray = (ElementType*) malloc (sizeof(ElementType)*MaxElements);
    if(S->MArray == 0) {
        printf("No memory for stack min array\n");
        free(S->Array);
        free(S);
        return 0;
    }

    S->TopOfStack = EmptyTOS;
    S->TopOfMStack = EmptyTOS;
    S->Capacity = MaxElements;

    return S;
}
Example #7
0
shared_ptr<Dic> IndexPersister::readIndexFromFile(string termFile, string postingsFile)
{
    cout << "Reading index from disk.." << endl;
    ifstream termStream(termFile, ios::binary);
    ifstream postingsStream(postingsFile,ios::binary);
    shared_ptr<Dic> dic(new Dic());
    char charCount;
    while(termStream.read(&charCount, sizeof(charCount)))
    {
        char term_cstr[255];
        termStream.read(term_cstr, charCount);
        term_cstr[charCount] = 0;
        string term(term_cstr);
        int docNum = 0;
        termStream.read(reinterpret_cast<char *>(&docNum), sizeof(docNum));
        shared_ptr<List> list(new List(term));
        
        for(int i = 0; i < docNum; i++)
        {
            int docId;
            postingsStream.read(reinterpret_cast<char *>(&docId), sizeof(docId));
            list->addPosting(docId);
        }
        dic->addList(term, *list);
    }
    dic->setSorted(true);
    return dic;
}
Example #8
0
struct MessageArrays MallocMessageArrays(uint32_t num_bytes,
                                         uint32_t num_handles) {
  struct MessageArrays arrays;
  arrays.bytes = (void*)malloc(num_bytes * sizeof(void));
  arrays.handles = (MojoHandle*)malloc(num_handles * sizeof(MojoHandle));
  return arrays;
}
Example #9
0
/**
 * limExtractApCapability()
 *
 *FUNCTION:
 * This function is called to extract AP's HCF/WME/WSM capability
 * from the IEs received from it in Beacon/Probe Response frames
 *
 *LOGIC:
 *
 *ASSUMPTIONS:
 * NA
 *
 *NOTE:
 *
 * @param   pMac      Pointer to Global MAC structure
 * @param   pIE       Pointer to starting IE in Beacon/Probe Response
 * @param   ieLen     Length of all IEs combined
 * @param   qosCap    Bits are set according to capabilities
 * @return  0 - If AP does not assert HCF capability & 1 - otherwise
 */
void
limExtractApCapability(tpAniSirGlobal pMac, tANI_U8 *pIE, tANI_U16 ieLen,
                       tANI_U8 *qosCap, tANI_U16 *propCap, tANI_U8 *uapsd, 
                       tPowerdBm *localConstraint,
                       tpPESession psessionEntry
                       )
{
    tSirProbeRespBeacon *pBeaconStruct;
#if !defined WLAN_FEATURE_VOWIFI
    tANI_U32            localPowerConstraints = 0;
#endif
    
    pBeaconStruct = vos_mem_malloc(sizeof(tSirProbeRespBeacon));

    if ( NULL == pBeaconStruct )
    {
        limLog(pMac, LOGE, FL("Unable to allocate memory in limExtractApCapability") );
        return;
    }

    vos_mem_set( (tANI_U8 *) pBeaconStruct, sizeof(tSirProbeRespBeacon), 0);
    *qosCap = 0;
    *propCap = 0;
    *uapsd = 0;
    PELOG3(limLog( pMac, LOG3,
        FL("In limExtractApCapability: The IE's being received are:"));
    sirDumpBuf( pMac, SIR_LIM_MODULE_ID, LOG3, pIE, ieLen );)
    if (sirParseBeaconIE(pMac, pBeaconStruct, pIE, (tANI_U32)ieLen) == eSIR_SUCCESS)
Example #10
0
struct DuplicateBufferHandleParams MallocDuplicateBufferHandleParams() {
  struct DuplicateBufferHandleParams p;
  p.duplicate = (MojoHandle*)malloc(sizeof(MojoHandle));
  p.opts = (struct MojoDuplicateBufferHandleOptions*)malloc(
      sizeof(struct MojoDuplicateBufferHandleOptions));
  return p;
}
Example #11
0
struct CreateSharedBufferParams MallocCreateSharedBufferParams() {
  struct CreateSharedBufferParams p;
  p.handle = (MojoHandle*)malloc(sizeof(MojoHandle));
  p.opts = (struct MojoCreateSharedBufferOptions*)malloc(
      sizeof(struct MojoCreateSharedBufferOptions));
  return p;
}
static void
set_rime_addr(void)
{
  rimeaddr_t addr;
  int i;

  memset(&addr, 0, sizeof(rimeaddr_t));
#if UIP_CONF_IPV6
  memcpy(addr.u8, ds2411_id, sizeof(addr.u8));
#else
  if(node_id == 0) {
    for(i = 0; i < sizeof(rimeaddr_t); ++i) {
      addr.u8[i] = ds2411_id[7 - i];
    }
  } else {
    addr.u8[0] = node_id & 0xff;
    addr.u8[1] = node_id >> 8;
  }
#endif
  rimeaddr_set_node_addr(&addr);
  PRINTF("Rime started with address ");
  for(i = 0; i < sizeof(addr.u8) - 1; i++) {
    PRINTF("%d.", addr.u8[i]);
  }
  PRINTF("%d\n", addr.u8[i]);
}
Example #13
0
STRING_ARG(iguana,addcoin,newcoin)
{
    char *symbol,*seedip; int32_t retval;
    if ( (symbol= newcoin) == 0 && coin != 0 )
        symbol = coin->symbol;
    if ( symbol != 0 )
    {
        if ( (seedip= jstr(json,"seedipaddr")) != 0 )
            safecopy(myinfo->seedipaddr,seedip,sizeof(myinfo->seedipaddr));
        printf(">> addcoin.%s seedipaddr.%s\n",symbol,myinfo->seedipaddr);
#ifdef __PNACL__
        //        if ( strcmp(symbol,"BTC") == 0 )
        //            return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}"));
#endif
        if ( (retval= iguana_launchcoin(myinfo,symbol,json,0)) > 0 )
        {
            if ( myinfo->rpcsymbol[0] == 0 )
                safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol));
            return(clonestr("{\"result\":\"coin added\"}"));
        }
        else if ( retval == 0 )
            return(clonestr("{\"result\":\"coin already there\"}"));
        else return(clonestr("{\"error\":\"error adding coin\"}"));
    } else return(clonestr("{\"error\":\"addcoin needs newcoin\"}"));
}
Example #14
0
/*
=============
idStr::FloatArrayToString
=============
*/
const char *idStr::FloatArrayToString( const float *array, const int length, const int precision ) {
	static int index = 0;
	static char str[4][16384];	// in case called by nested functions
	int i, n;
	char format[16], *s;

	// use an array of string so that multiple calls won't collide
	s = str[ index ];
	index = (index + 1) & 3;

	idStr::snPrintf( format, sizeof( format ), "%%.%df", precision );
	n = idStr::snPrintf( s, sizeof( str[0] ), format, array[0] );
	if ( precision > 0 ) {
		while( n > 0 && s[n-1] == '0' ) s[--n] = '\0';
		while( n > 0 && s[n-1] == '.' ) s[--n] = '\0';
	}
	idStr::snPrintf( format, sizeof( format ), " %%.%df", precision );
	for ( i = 1; i < length; i++ ) {
		n += idStr::snPrintf( s + n, sizeof( str[0] ) - n, format, array[i] );
		if ( precision > 0 ) {
			while( n > 0 && s[n-1] == '0' ) s[--n] = '\0';
			while( n > 0 && s[n-1] == '.' ) s[--n] = '\0';
		}
	}
	return s;
}
Example #15
0
void *MEM_mallocN(size_t len, const char *str)
{
	MemHead *memh;

	mem_lock_thread();

	len = (len + 3 ) & ~3; 	/* allocate in units of 4 */
	
	memh= (MemHead *)malloc(len+sizeof(MemHead)+sizeof(MemTail));

	if(memh) {
		make_memhead_header(memh, len, str);
		mem_unlock_thread();
		if(malloc_debug_memset && len)
			memset(memh+1, 255, len);

#ifdef DEBUG_MEMCOUNTER
		if(_mallocn_count==DEBUG_MEMCOUNTER_ERROR_VAL)
			memcount_raise("MEM_mallocN");
		memh->_count= _mallocn_count++;
#endif
		return (++memh);
	}
	mem_unlock_thread();
	print_error("Malloc returns null: len=" SIZET_FORMAT " in %s, total %u\n", SIZET_ARG(len), str, mem_in_use);
	return NULL;
}
Example #16
0
int main () {
  int count;
  int i, j, k;
  int n;

  scanf ("%d", &count);
  for (i=0; i<count; i++) {
    memset (flag, 0, sizeof(int)*N);
    scanf ("%d", &n);
    getchar();
    for (j=0; j<n; j++)
      fgets (s[j], sizeof(s[j][0])*M, stdin); 
    for (j=0; j<n; j++)
      fgets (d[j], sizeof(d[j][0])*M, stdin);

    /* find immobile sequence */
    for (j=n-1, k=n-1; j>=0; j--) {
      if (!strcmp (s[j],d[k])) { 
        flag[k] = 1;
        k -= 1;
      }
    }
    /* output mobile sequence */
    for (j=n-1; j>=0; j--) {
      if (flag[j] != 1)
        printf ("%s", d[j]);
    }

    printf ("\n");
  }
  return 0;
}
void InputDevice_DualShock::Power(void)
{
 combo_anatoggle_counter = -2;
 lastts = 0;
 //
 //

 dtr = 0;

 buttons[0] = buttons[1] = 0;

 command_phase = 0;

 bitpos = 0;

 receive_buffer = 0;

 command = 0;

 memset(transmit_buffer, 0, sizeof(transmit_buffer));

 transmit_pos = 0;
 transmit_count = 0;

 analog_mode_locked = false;

 mad_munchkins = false;
 memset(rumble_magic, 0xFF, sizeof(rumble_magic));
 memset(rumble_param, 0, sizeof(rumble_param));

 da_rumble_compat = true;

 prev_ana_button_state = false;
}
static int callerid_write(struct ast_channel *chan, char *cmd, char *data,
			  const char *value)
{
	if (!value)
		return -1;

	if (!strncasecmp("all", data, 3)) {
		char name[256];
		char num[256];

		if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
			ast_set_callerid(chan, num, name, num);
	} else if (!strncasecmp("name", data, 4)) {
		ast_set_callerid(chan, NULL, value, NULL);
	} else if (!strncasecmp("num", data, 3) ||
		   !strncasecmp("number", data, 6)) {
		ast_set_callerid(chan, value, NULL, NULL);
	} else if (!strncasecmp("ani", data, 3)) {
		ast_set_callerid(chan, NULL, NULL, value);
	} else if (!strncasecmp("dnid", data, 4)) {
		/* do we need to lock chan here? */
		if (chan->cid.cid_dnid)
			free(chan->cid.cid_dnid);
		chan->cid.cid_dnid = ast_strdup(value);
	} else if (!strncasecmp("rdnis", data, 5)) {
		/* do we need to lock chan here? */
		if (chan->cid.cid_rdnis)
			free(chan->cid.cid_rdnis);
		chan->cid.cid_rdnis = ast_strdup(value);
	} else {
		ast_log(LOG_ERROR, "Unknown callerid data type.\n");
	}

	return 0;
}
Example #19
0
void calculate_rsa_ckaid(osw_public_key *pub)
{
    if(pub->alg == PUBKEY_ALG_RSA) {
        struct RSA_public_key *rsa = &pub->u.rsa;

        if(rsa->key_rfc3110.len == 0) {
            /* key has no 3110 representation, need to cons up one */
            unsigned int e_size     = mpz_sizeinbase(&rsa->e, 256);
            unsigned int key3110len = rsa->k + 1 + e_size;
            rsa->key_rfc3110.ptr = alloc_bytes(key3110len, "rfc3110 format of public key [created]");
            rsa->key_rfc3110.len = key3110len;
            unsigned char *here = rsa->key_rfc3110.ptr;

            here[0] = e_size;
            here++;
            mpz_export(here, NULL, 1, 1, 1, 0, &rsa->e);
            here += e_size;
            mpz_export(here, NULL, 1, 1, 1, 0, &rsa->n);
        }

        /* maybe #ifdef SHA2 ? */
        /* calculate the hash of the public key, using SHA-2 */
        sha256_hash_buffer(rsa->key_rfc3110.ptr, rsa->key_rfc3110.len,
                           pub->key_ckaid, sizeof(pub->key_ckaid));

        datatot(pub->key_ckaid, sizeof(pub->key_ckaid), 'G',
                pub->key_ckaid_print_buf, sizeof(pub->key_ckaid_print_buf));
    }
}
Example #20
0
/*
 * Get a captured packet.
 */
size_t get_packet(uint8_t *buff, size_t size)
{
    if (size <= sizeof(struct ethhdr))
    {
        return 0;
    }

    ssize_t result;
    do
    {
        result = recv(socket_divert, buff + sizeof(struct ethhdr),
            size - sizeof(struct ethhdr), 0);
        if (result < 0)
        {
            warning("failed to read packet from netfilter socket");
            continue;
        }
    }
    while (false);

    // Add fake ethhdr
    struct ethhdr *eth_header = (struct ethhdr *)buff;
    memset(&eth_header->h_dest, 0x0, ETH_ALEN);
    memset(&eth_header->h_source, 0x0, ETH_ALEN);
    eth_header->h_proto = htons(ETH_P_IP);

    return (size_t)result + sizeof(struct ethhdr);
}
Example #21
0
void IndexPersister::saveIndexToFile(shared_ptr<Dic> index, string termFile, string postingsFile)
{
    cout << "Saving index to disk.." << endl;
    ofstream termStream(termFile, std::ios::binary);
    ofstream postingsStream(postingsFile, std::ios::binary);
    for(Dic::list_iterator list = index->begin(); list != index->end(); list++)
    {
        string term = list->getTerm();
        if (term.length() > 255)
        {
            cout << "We don't index terms larger than 255 characters!" << endl;
            continue;
        }
        char charCount = term.length();
        termStream.write(reinterpret_cast<const char *>(&charCount), sizeof(charCount));
        termStream << term;
        int docNum = list->getLength();
        termStream.write(reinterpret_cast<const char *>(&docNum), sizeof(docNum));
        auto posting = list->getPostings();
        while(posting != NULL)
        {
            int docId = posting->getDocId();
            postingsStream.write(reinterpret_cast<const char *>(&docId), sizeof(docId));
            posting = posting->next;
        }
    }
}
Example #22
0
int
get_client_socket()
{
	int sock_fd, err;
	struct sockaddr_in addr;

	memset(&addr, 0, sizeof (addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
	addr.sin_port = htons(DAEMON_PORT);

	sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
	if (!sock_fd) {
		printw("ui socket error: %s\n", strerror(errno));
		refresh();
	}

	for (;;) {
		err = connect(sock_fd, (struct sockaddr *)&addr, sizeof (addr));
		if (err == 0) {
			return (sock_fd);
		}

		printw("ui connect error: %s\n", strerror(errno));
		refresh();
		sleep(1);
	}
}
Example #23
0
void
print_trapframe(struct trapframe *tf) {
    cprintf("trapframe at %p\n", tf);
    print_regs(&tf->tf_regs);
    cprintf("  ds   0x----%04x\n", tf->tf_ds);
    cprintf("  es   0x----%04x\n", tf->tf_es);
    cprintf("  fs   0x----%04x\n", tf->tf_fs);
    cprintf("  gs   0x----%04x\n", tf->tf_gs);
    cprintf("  trap 0x%08x %s\n", tf->tf_trapno, trapname(tf->tf_trapno));
    cprintf("  err  0x%08x\n", tf->tf_err);
    cprintf("  eip  0x%08x\n", tf->tf_eip);
    cprintf("  cs   0x----%04x\n", tf->tf_cs);
    cprintf("  flag 0x%08x ", tf->tf_eflags);

    int i, j;
    for (i = 0, j = 1; i < sizeof(IA32flags) / sizeof(IA32flags[0]); i ++, j <<= 1) {
        if ((tf->tf_eflags & j) && IA32flags[i] != NULL) {
            cprintf("%s,", IA32flags[i]);
        }
    }
    cprintf("IOPL=%d\n", (tf->tf_eflags & FL_IOPL_MASK) >> 12);

    if (!trap_in_kernel(tf)) {
        cprintf("  esp  0x%08x\n", tf->tf_esp);
        cprintf("  ss   0x----%04x\n", tf->tf_ss);
    }
}
Example #24
0
int
init_list_for_dir(char *dir)
{
	int i, amount;
	struct dir_contents *contents;
	fileobj **list;

	amount = count_dir_entries(".", false, false);
	if (amount == 0)
		return (-1);

	contents = malloc(sizeof (contents));
	if (!contents) {
		return (-1);
	}

	list = malloc(sizeof (contents->list) * amount);
	if (!list) {
		return (-1);
	}

	for (i = 0; i < amount; i++) {
		list[i] = malloc(NAME_MAX + 1);
		if (!list[i]) {
			return (-1);
		}
	}

	contents->list = list;
	contents->amount = amount;

	file_list.contents = contents;

	return (0);
}
Example #25
0
void
InsertString (stringlist_t * list, char *string)
{

  if (!list->list)
    {
      list->max_index = list->block_size;
      list->num_strings = 0;
      list->list = (char **) malloc (list->max_index * sizeof (char *));
      if (!list->list)
	{
	  LogError ("malloc() error in %s line %d: %s\n", __FILE__, __LINE__,
		    strerror (errno));
	  exit (250);
	}
    }
  list->list[list->num_strings++] = string ? strdup (string) : NULL;

  if (list->num_strings == list->max_index)
    {
      list->max_index += list->block_size;
      list->list =
	(char **) realloc (list->list, list->max_index * sizeof (char *));
      if (!list->list)
	{
	  LogError ("realloc() error in %s line %d: %s\n", __FILE__, __LINE__,
		    strerror (errno));
	  exit (250);
	}
    }

}				// End of InsertString
Example #26
0
/*
 * Load the fuid table(s) into memory.
 */
static void
zfs_fuid_init(zfsvfs_t *zfsvfs, dmu_tx_t *tx)
{
	int error = 0;

	rw_enter(&zfsvfs->z_fuid_lock, RW_WRITER);

	if (zfsvfs->z_fuid_loaded) {
		rw_exit(&zfsvfs->z_fuid_lock);
		return;
	}

	if (zfsvfs->z_fuid_obj == 0) {

		/* first make sure we need to allocate object */

		error = zap_lookup(zfsvfs->z_os, MASTER_NODE_OBJ,
		    ZFS_FUID_TABLES, 8, 1, &zfsvfs->z_fuid_obj);
		if (error == ENOENT && tx != NULL) {
			zfsvfs->z_fuid_obj = dmu_object_alloc(zfsvfs->z_os,
			    DMU_OT_FUID, 1 << 14, DMU_OT_FUID_SIZE,
			    sizeof (uint64_t), tx);
			VERIFY(zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
			    ZFS_FUID_TABLES, sizeof (uint64_t), 1,
			    &zfsvfs->z_fuid_obj, tx) == 0);
		}
	}

	zfsvfs->z_fuid_size = zfs_fuid_table_load(zfsvfs->z_os,
	    zfsvfs->z_fuid_obj, &zfsvfs->z_fuid_idx, &zfsvfs->z_fuid_domain);

	zfsvfs->z_fuid_loaded = B_TRUE;
	rw_exit(&zfsvfs->z_fuid_lock);
}
static int ethtool_get_regs(struct net_device *dev, char *useraddr)
{
	struct ethtool_regs regs;
	struct ethtool_ops *ops = ethtool_ops;
	void *regbuf;
	int reglen, ret;

	if (!ops->get_regs || !ops->get_regs_len)
		return -EOPNOTSUPP;

	if (copy_from_user(&regs, useraddr, sizeof(regs)))
		return -EFAULT;

	reglen = ops->get_regs_len(dev);
	if (regs.len > reglen)
		regs.len = reglen;

	regbuf = kmalloc(reglen, GFP_USER);
	if (!regbuf)
		return -ENOMEM;

	ops->get_regs(dev, &regs, regbuf);

	ret = -EFAULT;
	if (copy_to_user(useraddr, &regs, sizeof(regs)))
		goto out;
	useraddr += offsetof(struct ethtool_regs, data);
	if (copy_to_user(useraddr, regbuf, reglen))
		goto out;
	ret = 0;

 out:
	kfree(regbuf);
	return ret;
}
Example #28
0
static int
proc_setup(struct pci_dev *d, int rw)
{
  struct pci_access *a = d->access;

  if (a->cached_dev != d || a->fd_rw < rw)
    {
      char buf[1024];
      int e;
      if (a->fd >= 0)
	close(a->fd);
      e = snprintf(buf, sizeof(buf), "%s/%02x/%02x.%d",
		   pci_get_param(a, "proc.path"),
		   d->bus, d->dev, d->func);
      if (e < 0 || e >= (int) sizeof(buf))
	a->error("File name too long");
      a->fd_rw = a->writeable || rw;
      a->fd = open(buf, a->fd_rw ? O_RDWR : O_RDONLY);
      if (a->fd < 0)
	a->warning("Cannot open %s", buf);
      a->cached_dev = d;
      a->fd_pos = 0;
    }
  return a->fd;
}
static int ethtool_get_stats(struct net_device *dev, void *useraddr)
{
	struct ethtool_stats stats;
	struct ethtool_ops *ops = ethtool_ops;
	u64 *data;
	int ret;

	if (!ops->get_ethtool_stats || !ops->get_stats_count)
		return -EOPNOTSUPP;

	if (copy_from_user(&stats, useraddr, sizeof(stats)))
		return -EFAULT;

	stats.n_stats = ops->get_stats_count(dev);
	data = kmalloc(stats.n_stats * sizeof(u64), GFP_USER);
	if (!data)
		return -ENOMEM;

	ops->get_ethtool_stats(dev, &stats, data);

	ret = -EFAULT;
	if (copy_to_user(useraddr, &stats, sizeof(stats)))
		goto out;
	useraddr += sizeof(stats);
	if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
		goto out;
	ret = 0;

 out:
	kfree(data);
	return ret;
}
Example #30
0
void   read4file(char *fname, float **s0, float **sinit, float **s, int nx, int nz)
{
    //int i;
    FILE *fp;

    if((fp=fopen(fname, "rb"))==NULL) {
	printf("Cannot open file.\n");
    }

    /* nm 
    if(fread(&i, sizeof(int), 1, fp) != 1) {
	if (feof(fp))
	    printf("File read error - nm.");
    }
    assert(i == nx*nz); */

    /* m0 */
    if(fread(s0[0], sizeof(float), nx*nz, fp) != nx*nz) {
	if (feof(fp))
	    printf("File read error - too small.");
    }

    /* minit */
    if(fread(sinit[0], sizeof(float), nx*nz, fp) != nx*nz) {
	if (feof(fp))
	    printf("File read error - too small.");
    }
    /* s */
    if(fread(s[0], sizeof(float), nx*nz, fp) != nx*nz) {
	if (!feof(fp))
	    printf("File read error - too big.");
    }

    fclose(fp);
}