这篇教程C++ uprintf函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中uprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ uprintf函数的具体用法?C++ uprintf怎么用?C++ uprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了uprintf函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: display_argsstatic void display_args(int argc, char **argv) { int i; for(i=0;i<argc;i++) uprintf(" argv[%d]=/"%s/"/r/n",i,argv[i]);}
开发者ID:afrendybayu,项目名称:kapalinduk,代码行数:5,
示例2: DownloadFile/* * Download a file from an URL * Mostly taken from http://support.microsoft.com/kb/234913 * If hProgressDialog is not NULL, this function will send INIT and EXIT messages * to the dialog in question, with WPARAM being set to nonzero for EXIT on success * and also attempt to indicate progress using an IDC_PROGRESS control */DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog){ HWND hProgressBar = NULL; BOOL r = FALSE; DWORD dwFlags, dwSize, dwDownloaded, dwTotalSize; FILE* fd = NULL; LONG progress_style; const char* accept_types[] = {"*/*/0", NULL}; unsigned char buf[DOWNLOAD_BUFFER_SIZE]; char agent[64], hostname[64], urlpath[128]; HINTERNET hSession = NULL, hConnection = NULL, hRequest = NULL; URL_COMPONENTSA UrlParts = {sizeof(URL_COMPONENTSA), NULL, 1, (INTERNET_SCHEME)0, hostname, sizeof(hostname), 0, NULL, 1, urlpath, sizeof(urlpath), NULL, 1}; size_t last_slash; int i; DownloadStatus = 0; if (hProgressDialog != NULL) { // Use the progress control provided, if any hProgressBar = GetDlgItem(hProgressDialog, IDC_PROGRESS); if (hProgressBar != NULL) { progress_style = GetWindowLong(hProgressBar, GWL_STYLE); SetWindowLong(hProgressBar, GWL_STYLE, progress_style & (~PBS_MARQUEE)); SendMessage(hProgressBar, PBM_SETPOS, 0, 0); } SendMessage(hProgressDialog, UM_PROGRESS_INIT, 0, 0); } if (file == NULL) goto out; for (last_slash = safe_strlen(file); last_slash != 0; last_slash--) { if ((file[last_slash] == '/') || (file[last_slash] == '//')) { last_slash++; break; } } PrintInfo(0, MSG_240, &file[last_slash]); uprintf("Downloading '%s' from %s/n", &file[last_slash], url); if ( (!InternetCrackUrlA(url, (DWORD)safe_strlen(url), 0, &UrlParts)) || (UrlParts.lpszHostName == NULL) || (UrlParts.lpszUrlPath == NULL)) { uprintf("Unable to decode URL: %s/n", WinInetErrorString()); goto out; } hostname[sizeof(hostname)-1] = 0; // Open an Internet session for (i=5; (i>0) && (!InternetGetConnectedState(&dwFlags, 0)); i--) { Sleep(1000); } if (i <= 0) { // http://msdn.microsoft.com/en-us/library/windows/desktop/aa384702.aspx is wrong... SetLastError(ERROR_INTERNET_NOT_INITIALIZED); uprintf("Network is unavailable: %s/n", WinInetErrorString()); goto out; } safe_sprintf(agent, ARRAYSIZE(agent), APPLICATION_NAME "/%d.%d.%d (Windows NT %d.%d%s)", rufus_version[0], rufus_version[1], rufus_version[2], nWindowsVersion>>4, nWindowsVersion&0x0F, is_x64()?"; WOW64":""); hSession = InternetOpenA(agent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (hSession == NULL) { uprintf("Could not open Internet session: %s/n", WinInetErrorString()); goto out; } hConnection = InternetConnectA(hSession, UrlParts.lpszHostName, UrlParts.nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)NULL); if (hConnection == NULL) { uprintf("Could not connect to server %s:%d: %s/n", UrlParts.lpszHostName, UrlParts.nPort, WinInetErrorString()); goto out; } hRequest = HttpOpenRequestA(hConnection, "GET", UrlParts.lpszUrlPath, NULL, NULL, accept_types, INTERNET_FLAG_HYPERLINK|INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP|INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS|INTERNET_FLAG_NO_COOKIES| INTERNET_FLAG_NO_UI|INTERNET_FLAG_NO_CACHE_WRITE, (DWORD_PTR)NULL); if (hRequest == NULL) { uprintf("Could not open URL %s: %s/n", url, WinInetErrorString()); goto out; } if (!HttpSendRequestA(hRequest, NULL, 0, NULL, 0)) { uprintf("Unable to send request: %s/n", WinInetErrorString()); goto out; } // Get the file size dwSize = sizeof(DownloadStatus); DownloadStatus = 404; HttpQueryInfoA(hRequest, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, (LPVOID)&DownloadStatus, &dwSize, NULL); if (DownloadStatus != 200) { error_code = ERROR_INTERNET_ITEM_NOT_FOUND; uprintf("Unable to access file: %d/n", DownloadStatus);//.........这里部分代码省略.........
开发者ID:BruceLEO1969,项目名称:rufus,代码行数:101,
示例3: trap//.........这里部分代码省略......... * We decode the 68881 status register which locore * stashed in code for us. */ ksi.ksi_signo = SIGFPE; ksi.ksi_code = fpsr2siginfocode(code); break; /* * FPU faults in supervisor mode. */ case T_ILLINST: /* fnop generates this, apparently. */ case T_FPEMULI: case T_FPEMULD: { extern label_t *nofault; if (nofault) /* If we're probing. */ longjmp(nofault); if (type == T_ILLINST) printf("Kernel Illegal Instruction trap./n"); else printf("Kernel FPU trap./n"); goto dopanic; } /* * Unimplemented FPU instructions/datatypes. */ case T_FPEMULI|T_USER: case T_FPEMULD|T_USER:#ifdef FPU_EMULATE if (fpu_emulate(fp, &pcb->pcb_fpregs, &ksi) == 0) ; /* XXX - Deal with tracing? (fp->f_sr & PSL_T) */#else uprintf("pid %d killed: no floating point support./n", p->p_pid); ksi.ksi_signo = SIGILL; ksi.ksi_code = ILL_ILLOPC;#endif break; case T_COPERR: /* Kernel coprocessor violation */ case T_FMTERR: /* Kernel format error */ case T_FMTERR|T_USER: /* User format error */ /* * The user has most likely trashed the RTE or FP state info * in the stack frame of a signal handler. */ printf("pid %d: kernel %s exception/n", p->p_pid, type==T_COPERR ? "coprocessor" : "format"); type |= T_USER; mutex_enter(p->p_lock); SIGACTION(p, SIGILL).sa_handler = SIG_DFL; sigdelset(&p->p_sigctx.ps_sigignore, SIGILL); sigdelset(&p->p_sigctx.ps_sigcatch, SIGILL); sigdelset(&l->l_sigmask, SIGILL); mutex_exit(p->p_lock); ksi.ksi_signo = SIGILL; ksi.ksi_addr = (void *)(int)fp->f_format; /* XXX was ILL_RESAD_FAULT */ ksi.ksi_code = (type == T_COPERR) ? ILL_COPROC : ILL_ILLOPC; break; /* * XXX: Trace traps are a nightmare. *
开发者ID:krytarowski,项目名称:netbsd-current-src-sys,代码行数:67,
示例4: chkiq/* * Check the inode limit, applying corrective action. */intchkiq(struct inode *ip, int change, struct ucred *cred, int flags){ struct dquot *dq; int i, error, warn, do_check;#ifdef DIAGNOSTIC if ((flags & CHOWN) == 0) chkdquot(ip);#endif if (change == 0) return (0); if (change < 0) { for (i = 0; i < MAXQUOTAS; i++) { if ((dq = ip->i_dquot[i]) == NODQUOT) continue; DQI_LOCK(dq); DQI_WAIT(dq, PINOD+1, "chkiq1"); if (dq->dq_curinodes >= -change) dq->dq_curinodes += change; else dq->dq_curinodes = 0; dq->dq_flags &= ~DQ_INODS; dq->dq_flags |= DQ_MOD; DQI_UNLOCK(dq); } return (0); } if ((flags & FORCE) == 0 && priv_check_cred(cred, PRIV_VFS_EXCEEDQUOTA, 0)) do_check = 1; else do_check = 0; for (i = 0; i < MAXQUOTAS; i++) { if ((dq = ip->i_dquot[i]) == NODQUOT) continue; warn = 0; DQI_LOCK(dq); DQI_WAIT(dq, PINOD+1, "chkiq2"); if (do_check) { error = chkiqchg(ip, change, cred, i, &warn); if (error) { /* * Roll back user quota changes when * group quota failed. */ while (i > 0) { --i; dq = ip->i_dquot[i]; if (dq == NODQUOT) continue; DQI_LOCK(dq); DQI_WAIT(dq, PINOD+1, "chkiq3"); if (dq->dq_curinodes >= change) dq->dq_curinodes -= change; else dq->dq_curinodes = 0; dq->dq_flags &= ~DQ_INODS; dq->dq_flags |= DQ_MOD; DQI_UNLOCK(dq); } return (error); } } /* Reset timer when crossing soft limit */ if (dq->dq_curinodes + change >= dq->dq_isoftlimit && dq->dq_curinodes < dq->dq_isoftlimit) dq->dq_itime = time_second + ip->i_ump->um_itime[i]; dq->dq_curinodes += change; dq->dq_flags |= DQ_MOD; DQI_UNLOCK(dq); if (warn) uprintf("/n%s: warning, %s inode quota exceeded/n", ITOV(ip)->v_mount->mnt_stat.f_mntonname, quotatypes[i]); } return (0);}
开发者ID:jamesbjackson,项目名称:src,代码行数:81,
示例5: Zoltan_PHG_Partition/* Main partitioning function for hypergraph partitioning. */int Zoltan_PHG_Partition ( ZZ *zz, /* Zoltan data structure */ HGraph *hg, /* Input hypergraph to be partitioned */ int p, /* Input: number partitions to be generated */ float *part_sizes, /* Input: array of length p containing percentages of work to be assigned to each partition */ Partition parts, /* Input: initial partition #s; aligned with vtx arrays. Output: computed partition #s */ PHGPartParams *hgp) /* Input: parameters for hgraph partitioning. */{ PHGComm *hgc = hg->comm; VCycle *vcycle=NULL, *del=NULL; int i, err = ZOLTAN_OK, middle; ZOLTAN_GNO_TYPE origVpincnt; /* for processor reduction test */ ZOLTAN_GNO_TYPE prevVcnt = 2*hg->dist_x[hgc->nProc_x]; /* initialized so that the */ ZOLTAN_GNO_TYPE prevVedgecnt = 2*hg->dist_y[hgc->nProc_y]; /* while loop will be entered before any coarsening */ ZOLTAN_GNO_TYPE tot_nPins, local_nPins; MPI_Datatype zoltan_gno_mpi_type; char *yo = "Zoltan_PHG_Partition"; int do_timing = (hgp->use_timers > 1); int fine_timing = (hgp->use_timers > 2); int vcycle_timing = (hgp->use_timers > 4 && hgp->ProRedL == 0); short refine = 0; struct phg_timer_indices *timer = Zoltan_PHG_LB_Data_timers(zz); int reset_geometric_matching = 0; char reset_geometric_string[4]; ZOLTAN_TRACE_ENTER(zz, yo); zoltan_gno_mpi_type = Zoltan_mpi_gno_type(); if (do_timing) { if (timer->vcycle < 0) timer->vcycle = Zoltan_Timer_Init(zz->ZTime, 0, "Vcycle"); if (timer->procred < 0) timer->procred = Zoltan_Timer_Init(zz->ZTime, 0, "Processor Reduction"); if (timer->match < 0) timer->match = Zoltan_Timer_Init(zz->ZTime, 1, "Matching"); if (timer->coarse < 0) timer->coarse = Zoltan_Timer_Init(zz->ZTime, 1, "Coarsening"); if (timer->coarsepart < 0) timer->coarsepart = Zoltan_Timer_Init(zz->ZTime, 1, "Coarse_Partition"); if (timer->refine < 0) timer->refine = Zoltan_Timer_Init(zz->ZTime, 1, "Refinement"); if (timer->project < 0) timer->project = Zoltan_Timer_Init(zz->ZTime, 1, "Project_Up"); ZOLTAN_TIMER_START(zz->ZTime, timer->vcycle, hgc->Communicator); } local_nPins = (ZOLTAN_GNO_TYPE)hg->nPins; MPI_Allreduce(&local_nPins,&tot_nPins,1,zoltan_gno_mpi_type,MPI_SUM,hgc->Communicator); origVpincnt = tot_nPins; if (!(vcycle = newVCycle(zz, hg, parts, NULL, vcycle_timing))) { ZOLTAN_PRINT_ERROR (zz->Proc, yo, "VCycle is NULL."); ZOLTAN_TRACE_EXIT(zz, yo); return ZOLTAN_MEMERR; } /* For geometric coarsening, hgp->matching pointer and string are reset * after geometric_levels of coarsening. Will need to reset them after * this vcycle is completed. Capture that fact now! */ if (!strcasecmp(hgp->redm_str, "rcb") || !strcasecmp(hgp->redm_str, "rib")) { reset_geometric_matching = 1; strcpy(reset_geometric_string, hgp->redm_str); } /****** Coarsening ******/ #define COARSEN_FRACTION_LIMIT 0.9 /* Stop if we don't make much progress */ while ((hg->redl>0) && (hg->dist_x[hgc->nProc_x] > (ZOLTAN_GNO_TYPE)hg->redl) && ((hg->dist_x[hgc->nProc_x] < (ZOLTAN_GNO_TYPE) (COARSEN_FRACTION_LIMIT * prevVcnt + 0.5)) /* prevVcnt initialized to 2*hg->dist_x[hgc->nProc_x] */ || (hg->dist_y[hgc->nProc_y] < (ZOLTAN_GNO_TYPE) (COARSEN_FRACTION_LIMIT * prevVedgecnt + 0.5))) /* prevVedgecnt initialized to 2*hg->dist_y[hgc->nProc_y] */ && hg->dist_y[hgc->nProc_y] && hgp->matching) { ZOLTAN_GNO_TYPE *match = NULL; VCycle *coarser=NULL, *redistributed=NULL; prevVcnt = hg->dist_x[hgc->nProc_x]; prevVedgecnt = hg->dist_y[hgc->nProc_y];#ifdef _DEBUG /* UVC: load balance stats */ Zoltan_PHG_LoadBalStat(zz, hg);#endif if (hgp->output_level >= PHG_DEBUG_LIST) { uprintf(hgc, "START %3d |V|=%6d |E|=%6d #pins=%6d %d/%s/%s/%s p=%d.../n", hg->info, hg->nVtx, hg->nEdge, hg->nPins, hg->redl, hgp->redm_str, hgp->coarsepartition_str, hgp->refinement_str, p); if (hgp->output_level > PHG_DEBUG_LIST) { err = Zoltan_HG_Info(zz, hg);//.........这里部分代码省略.........
开发者ID:00liujj,项目名称:trilinos,代码行数:101,
示例6: ffs_balloc_ufs1//.........这里部分代码省略......... if (error) { brelse(bp); goto fail; } bap = (ufs1_daddr_t *)bp->b_data; nb = bap[indirs[i].in_off]; if (i == num) break; i += 1; if (nb != 0) { bqrelse(bp); continue; } UFS_LOCK(ump); /* * If parent indirect has just been allocated, try to cluster * immediately following it. */ if (pref == 0) pref = ffs_blkpref_ufs1(ip, lbn, i - num - 1, (ufs1_daddr_t *)0); if ((error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, flags | IO_BUFLOCKED, cred, &newb)) != 0) { brelse(bp); if (++reclaimed == 1) { UFS_LOCK(ump); softdep_request_cleanup(fs, vp, cred, FLUSH_BLOCKS_WAIT); UFS_UNLOCK(ump); goto retry; } if (ppsratecheck(&lastfail, &curfail, 1)) { ffs_fserr(fs, ip->i_number, "filesystem full"); uprintf("/n%s: write failed, filesystem " "is full/n", fs->fs_fsmnt); } goto fail; } pref = newb + fs->fs_frag; nb = newb; *allocblk++ = nb; *lbns_remfree++ = indirs[i].in_lbn; nbp = getblk(vp, indirs[i].in_lbn, fs->fs_bsize, 0, 0, 0); nbp->b_blkno = fsbtodb(fs, nb); vfs_bio_clrbuf(nbp); if (DOINGSOFTDEP(vp)) { softdep_setup_allocindir_meta(nbp, ip, bp, indirs[i - 1].in_off, nb); bdwrite(nbp); } else { /* * Write synchronously so that indirect blocks * never point at garbage. */ if ((error = bwrite(nbp)) != 0) { brelse(bp); goto fail; } } bap[indirs[i - 1].in_off] = nb; if (allocib == NULL && unwindidx < 0) unwindidx = i - 1; /* * If required, write synchronously, otherwise use * delayed write. */
开发者ID:JabirTech,项目名称:Source,代码行数:67,
示例7: c_serial_handlerVOID c_serial_handler( VOID ){ atomic_up(); CharIn = '/0'; BYTE interrupt_status; interrupt_status = SERIAL1_USR; SERIAL1_IMR = 3; if( interrupt_status & 1 ) { CharIn = SERIAL1_RD; CharOut = CharIn; } while (!(interrupt_status & 4)) { interrupt_status = SERIAL1_USR; } SERIAL1_IMR = 2; if ( interrupt_status & 4 ) { switch(CharIn){ case '/r': uprintf(crlfgt); if(command_flag == 1){ store_message((CHAR)'/0'); void * p = request_memory_block(); send_message(KCD_PID,write_message(p, kcd_msg)); command_flag = 0; clear_message(); } break; case '%': SERIAL1_WD = '%'; command_flag = 1; break; case '!': SERIAL1_WD = CharOut; display_queue_all(); sleep(6); break; case '@': SERIAL1_WD = CharOut; task_manager(); sleep(6); break; case '#': display_mailbox(); sleep(6); break; default: if(command_flag == 1){ store_message((CHAR)CharOut); } SERIAL1_WD = CharOut; break; } } atomic_down(); return;}
开发者ID:Bhavya,项目名称:Pea-OS,代码行数:62,
示例8: test_rwstatic unsigned int test_rw(HANDLE hDrive, blk_t last_block, size_t block_size, blk_t first_block, size_t blocks_at_once, int nb_passes){ unsigned char *buffer = NULL, *read_buffer; const unsigned int pattern[] = {0xaa, 0x55, 0xff, 0x00}; int i, pat_idx; unsigned int bb_count = 0; blk_t got, tryout, recover_block = ~0, *blk_id; size_t id_offset; if ((nb_passes < 1) || (nb_passes > 4)) { uprintf("%sInvalid number of passes/n", bb_prefix); cancel_ops = -1; return 0; } buffer = allocate_buffer(2 * blocks_at_once * block_size); read_buffer = buffer + blocks_at_once * block_size; if (!buffer) { uprintf("%sError while allocating buffers/n", bb_prefix); cancel_ops = -1; return 0; } uprintf("%sChecking from block %lu to %lu/n", bb_prefix, (unsigned long) first_block, (unsigned long) last_block - 1); nr_pattern = nb_passes; cur_pattern = 0; for (pat_idx = 0; pat_idx < nb_passes; pat_idx++) { if (cancel_ops) goto out; srand((unsigned int)GetTickCount()); id_offset = rand()* (block_size-sizeof(blk_t)) / RAND_MAX; pattern_fill(buffer, pattern[pat_idx], blocks_at_once * block_size); uprintf("%sUsing offset %d for fake device check/n", bb_prefix, id_offset); num_blocks = last_block - 1; currently_testing = first_block; if (s_flag | v_flag) uprintf("%sWriting test pattern 0x%02X/n", bb_prefix, pattern[pat_idx]); cur_op = OP_WRITE; tryout = blocks_at_once; while (currently_testing < last_block) { if (cancel_ops) goto out; if (max_bb && bb_count >= max_bb) { if (s_flag || v_flag) { uprintf(abort_msg); fprintf(log_fd, abort_msg); fflush(log_fd); } cancel_ops = -1; goto out; } if (currently_testing + tryout > last_block) tryout = last_block - currently_testing; if (detect_fakes) { /* Add the block number at a fixed (random) offset during each pass to allow for the detection of 'fake' media (eg. 2GB USB masquerading as 16GB) */ for (i=0; i<(int)blocks_at_once; i++) { blk_id = (blk_t*)(intptr_t)(buffer + id_offset+ i*block_size); *blk_id = (blk_t)(currently_testing + i); } } got = do_write(hDrive, buffer, tryout, block_size, currently_testing); if (v_flag > 1) print_status(); if (got == 0 && tryout == 1) bb_count += bb_output(currently_testing++, WRITE_ERROR); currently_testing += got; if (got != tryout) { tryout = 1; if (recover_block == ~0) recover_block = currently_testing - got + blocks_at_once; continue; } else if (currently_testing == recover_block) { tryout = blocks_at_once; recover_block = ~0; } } num_blocks = 0; if (s_flag | v_flag) uprintf("%sReading and comparing/n", bb_prefix); cur_op = OP_READ; num_blocks = last_block; currently_testing = first_block; tryout = blocks_at_once; while (currently_testing < last_block) { if (cancel_ops) goto out; if (max_bb && bb_count >= max_bb) { if (s_flag || v_flag) { uprintf(abort_msg); fprintf(log_fd, abort_msg); fflush(log_fd); } cancel_ops = -1; goto out;//.........这里部分代码省略.........
开发者ID:Kronimo,项目名称:rufus,代码行数:101,
示例9: fl_read/* * Perform a read to flush the buffer. */void fl_read( void ){ int err; /* Result from system call */ int left; /* Bytes left */ char *more; /* Pointer to next byte to read */ /* * Clear the count of errors. This only applies to a single call to * fl_read. We leave read_error_flag alone; it is only turned off by * higher level software. */ r_error_count = 0; /* Clear error count */ /* * If we are about to wipe out a record that somebody needs to keep, copy * it out to a holding area and adjust somebody's pointer to it. */ if (save_rec && *save_rec >= ar_record && *save_rec < ar_last) { record_save_area = **save_rec; *save_rec = &record_save_area; }error_loop:#if defined(MSDOS) && !defined(__NO_PHYS__) if (f_phys) err = physread(ar_block->charptr, blocksize); else#endif err = read(archive, ar_block->charptr, blocksize); if (err == blocksize) return; if (err < 0) { readerror(); goto error_loop; /* Try again */ } more = ar_block->charptr + err; left = blocksize - err;#ifndef MSDOS if (baserec != 0) /* multi-volume support on read -- JER */ { uprintf(ftty,"/ntar: End of volume. Change volumes and press [Enter]: "); while (ugetc(ftty) != '/n') ; lseek(archive, 0L, 0); goto error_loop_2; }#endifagain: if (0 == (((unsigned) left) % RECORDSIZE)) { /* FIXME, for size=0, multi vol support */ /* On the first block, warn about the problem */ if (!f_reblock && baserec == 0 && f_verbose) { annorec(stderr, tar); fprintf(stderr, "Blocksize = %d records/n", err / RECORDSIZE); } ar_last = ar_block + ((unsigned) (blocksize - left)) / RECORDSIZE; return; } if (f_reblock) { /* * User warned us about this. Fix up. */ if (left > 0) { error_loop_2:#if defined(MSDOS) && !defined(__NO_PHYS__) if (f_phys) err = physread(more, left); else#endif err = read(archive, more, left); if (err < 0) { readerror(); goto error_loop_2; /* Try again */ } if (err == 0) { annorec(stderr, tar); fprintf(stderr, "%s: eof not on block boundary, strange.../n", ar_file); exit(EX_BADARCH); } left -= err; more += err; goto again;//.........这里部分代码省略.........
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:101,
示例10: afspag_PSetTokensint afspag_PSetTokens(char *ain, afs_int32 ainSize, afs_ucred_t **acred){ afs_int32 i; register struct unixuser *tu; struct afspag_cell *tcell; struct ClearToken clear; char *stp; int stLen; afs_int32 flag, set_parent_pag = 0; afs_int32 pag, uid; AFS_STATCNT(PSetTokens); if (!afs_resourceinit_flag) { return EIO; } memcpy((char *)&i, ain, sizeof(afs_int32)); ain += sizeof(afs_int32); stp = ain; /* remember where the ticket is */ if (i < 0 || i > MAXKTCTICKETLEN) return EINVAL; /* malloc may fail */ stLen = i; ain += i; /* skip over ticket */ memcpy((char *)&i, ain, sizeof(afs_int32)); ain += sizeof(afs_int32); if (i != sizeof(struct ClearToken)) { return EINVAL; } memcpy((char *)&clear, ain, sizeof(struct ClearToken)); if (clear.AuthHandle == -1) clear.AuthHandle = 999; /* more rxvab compat stuff */ ain += sizeof(struct ClearToken); if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) { /* still stuff left? we've got primary flag and cell name. Set these */ memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */ ain += sizeof(afs_int32); /* skip id field */ /* rest is cell name, look it up */ /* some versions of gcc appear to need != 0 in order to get this right */ if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */ flag &= ~0x8000; set_parent_pag = 1; } tcell = afspag_GetCell(ain); } else { /* default to primary cell, primary id */ flag = 1; /* primary id */ tcell = afspag_GetPrimaryCell(); } if (!tcell) return ESRCH; if (set_parent_pag) {#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)# if defined(AFS_DARWIN_ENV) afs_proc_t *p = current_proc(); /* XXX */# else afs_proc_t *p = curproc; /* XXX */# endif# ifndef AFS_DARWIN80_ENV uprintf("Process %d (%s) tried to change pags in PSetTokens/n", p->p_pid, p->p_comm);# endif setpag(p, acred, -1, &pag, 1);#else setpag(acred, -1, &pag, 1);#endif } pag = PagInCred(*acred); uid = (pag == NOPAG) ? afs_cr_uid(*acred) : pag; /* now we just set the tokens */ tu = afs_GetUser(uid, tcell->cellnum, WRITE_LOCK); if (!tu->cellinfo) tu->cellinfo = (void *)tcell; tu->vid = clear.ViceId; if (tu->stp != NULL) { afs_osi_Free(tu->stp, tu->stLen); } tu->stp = (char *)afs_osi_Alloc(stLen); tu->stLen = stLen; memcpy(tu->stp, stp, stLen); tu->ct = clear;#ifndef AFS_NOSTATS afs_stats_cmfullperf.authent.TicketUpdates++; afs_ComputePAGStats();#endif /* AFS_NOSTATS */ tu->states |= UHasTokens; tu->states &= ~UTokensBad; afs_SetPrimary(tu, flag); tu->tokenTime = osi_Time(); afs_PutUser(tu, WRITE_LOCK); return 0;}
开发者ID:stevenjenkins,项目名称:openafs,代码行数:90,
示例11: trap//.........这里部分代码省略......... ksi.ksi_signo = SIGILL; ksi.ksi_addr = (void *)(int)tf->tf_format; ksi.ksi_code = (type == T_COPERR) ? ILL_COPROC : ILL_ILLOPC; break; case T_COPERR|T_USER: /* user coprocessor violation */ /* What is a proper response here? */ ksi.ksi_signo = SIGFPE; ksi.ksi_code = FPE_FLTINV; break; case T_FPERR|T_USER: /* 68881 exceptions */ /* * We pass along the 68881 status register which locore stashed * in code for us. */ ksi.ksi_signo = SIGFPE; ksi.ksi_code = fpsr2siginfocode(code); break; case T_FPEMULI: /* FPU faults in supervisor mode */ case T_FPEMULD: if (nofault) /* Doing FPU probe? */ longjmp(nofault); goto dopanic; case T_FPEMULI|T_USER: /* unimplemented FP instruction */ case T_FPEMULD|T_USER: /* unimplemented FP data type */#ifdef FPU_EMULATE if (fpu_emulate(tf, &pcb->pcb_fpregs, &ksi) == 0) ; /* XXX - Deal with tracing? (tf->tf_sr & PSL_T) */#else uprintf("pid %d killed: no floating point support/n", p->p_pid); ksi.ksi_signo = SIGILL; ksi.ksi_code = ILL_ILLOPC;#endif break; case T_ILLINST|T_USER: /* illegal instruction fault */ case T_PRIVINST|T_USER: /* privileged instruction fault */ ksi.ksi_addr = (void *)(int)tf->tf_format; ksi.ksi_signo = SIGILL; ksi.ksi_code = (type == (T_PRIVINST|T_USER)) ? ILL_PRVOPC : ILL_ILLOPC; break; case T_ZERODIV|T_USER: /* Divide by zero */ ksi.ksi_code = FPE_FLTDIV; case T_CHKINST|T_USER: /* CHK instruction trap */ case T_TRAPVINST|T_USER: /* TRAPV instruction trap */ ksi.ksi_addr = (void *)(int)tf->tf_format; ksi.ksi_signo = SIGFPE; break; /* * XXX: Trace traps are a nightmare. * * HP-UX uses trap #1 for breakpoints, * NetBSD/m68k uses trap #2, * SUN 3.x uses trap #15, * DDB and KGDB uses trap #15 (for kernel breakpoints; * handled elsewhere). * * NetBSD and HP-UX traps both get mapped by locore.s into T_TRACE. * SUN 3.x traps get passed through as T_TRAP15 and are not really
开发者ID:ryo,项目名称:netbsd-src,代码行数:67,
示例12: http_serv_putstatic int http_serv_put(struct netconn *conn, http_parser_t *http_parser, char *responseBuf, uint16_t max_resp_size){ int responseBuf_len = 0; cJSON *json_root = NULL; json_root = cJSON_Parse(http_parser->content); if(http_parser->num_token == 4 && http_parser->val_token[2] == HUE_URL_TOKEN_LIGHTS) { cJSON *json_light_name; uint16_t light_id; /* this is rename light command */ light_id = strtol(http_parser->url_token[3], NULL, 10); if(json_root) { json_light_name = cJSON_GetObjectItem(json_root,"name"); if(!json_light_name) uprintf(UPRINT_INFO, UPRINT_BLK_HUE, "rename light: not found light name!/n"); else { uprintf(UPRINT_INFO, UPRINT_BLK_HUE, "rename light %d:%s/n", light_id, json_light_name->valuestring); memcpy(responseBuf, http_json_hdr, sizeof(http_json_hdr)-1); responseBuf_len += sizeof(http_json_hdr)-1; responseBuf_len += process_hue_api_rename_light(light_id, json_light_name->valuestring, &responseBuf[responseBuf_len], max_resp_size-responseBuf_len); } } } else if(http_parser->val_token[2] == HUE_URL_TOKEN_LIGHTS && http_parser->val_token[4] == HUE_URL_TOKEN_STATE) { uint32_t bitmap=0; cJSON *json_state; hue_light_t *in_light; uint16_t light_id; light_id = strtol(http_parser->url_token[3], NULL, 10); /* set light state command */ // in_light will be freed by hue task in_light = malloc(sizeof(hue_light_t)); assert(in_light); in_light->id = light_id; if(json_root) { json_state = cJSON_GetObjectItem(json_root, "on"); if(json_state) { bitmap |= (1<<HUE_STATE_BIT_ON); in_light->on = json_state->valueint; } json_state = cJSON_GetObjectItem(json_root, "bri"); if(json_state) { bitmap |= (1<<HUE_STATE_BIT_BRI); in_light->bri= json_state->valueint; } json_state = cJSON_GetObjectItem(json_root, "hue"); if(json_state) { bitmap |= (1<<HUE_STATE_BIT_HUE); in_light->hue = (json_state->valueint >> 8); } json_state = cJSON_GetObjectItem(json_root, "sat"); if(json_state) { bitmap |= (1<<HUE_STATE_BIT_SAT); in_light->sat= json_state->valueint; } json_state = cJSON_GetObjectItem(json_root, "xy"); if(json_state && (json_state->type == cJSON_Array)) { cJSON *json_x, *json_y; json_x = cJSON_GetArrayItem(json_state, 0); json_y = cJSON_GetArrayItem(json_state, 1); if(json_x && json_y) { bitmap |= (1<<HUE_STATE_BIT_XY); in_light->x = json_x->valuedouble * (1<<16); // xy in Q0.16 in_light->y = json_y->valuedouble * (1<<16); uprintf(UPRINT_INFO, UPRINT_BLK_HUE, "set xy [%d %d]/n", in_light->x, in_light->y); } } json_state = cJSON_GetObjectItem(json_root, "ct"); if(json_state) { bitmap |= (1<<HUE_STATE_BIT_CT); in_light->ct= json_state->valueint; } } uprintf(UPRINT_INFO, UPRINT_BLK_HUE, "set light %d bitmap: 0x%x/n", light_id, bitmap);//.........这里部分代码省略.........
开发者ID:phuuix,项目名称:probability,代码行数:101,
示例13: GetDriveHandle/* * Open a drive or volume with optional write and lock access * Returns INVALID_HANDLE_VALUE (/!/ which is DIFFERENT from NULL /!/) on failure. * This call is quite risky (left unchecked, inadvertently passing 0 as index would * return a handle to C:, which we might then proceed to unknowingly repartition!), * so we apply the following mitigation factors: * - Valid indexes must belong to a specific range [DRIVE_INDEX_MIN; DRIVE_INDEX_MAX] * - When opening for write access, we lock the volume. If that fails, which would * typically be the case on C:/ or any other drive in use, we report failure * - We report the full path of any drive that was successfully opened for write acces */HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BOOL bLockDrive){ BOOL r; DWORD size; HANDLE hDrive = INVALID_HANDLE_VALUE; STORAGE_DEVICE_NUMBER_REDEF device_number = {0}; UINT drive_type; char drives[26*4]; /* "D:/", "E:/", etc. */ char *drive = drives; char logical_drive[] = "////.//#:"; char physical_drive[24]; if ((DriveIndex < DRIVE_INDEX_MIN) || (DriveIndex > DRIVE_INDEX_MAX)) { uprintf("WARNING: Bad index value. Please check the code!/n"); } DriveIndex -= DRIVE_INDEX_MIN; // If no drive letter is requested, open a physical drive if (DriveLetter == NULL) { safe_sprintf(physical_drive, sizeof(physical_drive), "////.//PHYSICALDRIVE%d", DriveIndex); hDrive = CreateFileA(physical_drive, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0), FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); if (hDrive == INVALID_HANDLE_VALUE) { uprintf("Could not open drive %s: %s/n", physical_drive, WindowsErrorString()); goto out; } if (bWriteAccess) { uprintf("Caution: Opened %s drive for write access/n", physical_drive); } } else { *DriveLetter = ' '; size = GetLogicalDriveStringsA(sizeof(drives), drives); if (size == 0) { uprintf("GetLogicalDriveStrings failed: %s/n", WindowsErrorString()); goto out; } if (size > sizeof(drives)) { uprintf("GetLogicalDriveStrings: buffer too small (required %d vs %d)/n", size, sizeof(drives)); goto out; } hDrive = INVALID_HANDLE_VALUE; for ( ;*drive; drive += safe_strlen(drive)+1) { if (!isalpha(*drive)) continue; *drive = (char)toupper((int)*drive); if (*drive < 'C') { continue; } /* IOCTL_STORAGE_GET_DEVICE_NUMBER's STORAGE_DEVICE_NUMBER.DeviceNumber is not unique! An HDD, a DVD and probably other drives can have the same value there => Use GetDriveType() to filter out unwanted devices. See https://github.com/pbatard/rufus/issues/32 for details. */ drive_type = GetDriveTypeA(drive); // NB: the HP utility allows drive_type == DRIVE_FIXED, which we don't allow by default // Using Alt-F in Rufus does enable listing, but this mode is unsupported. if ((drive_type != DRIVE_REMOVABLE) && ((!enable_fixed_disks) || (drive_type != DRIVE_FIXED))) continue; safe_sprintf(logical_drive, sizeof(logical_drive), "////.//%c:", drive[0]); hDrive = CreateFileA(logical_drive, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0), FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); if (hDrive == INVALID_HANDLE_VALUE) { uprintf("Warning: could not open drive %c: %s/n", drive[0], WindowsErrorString()); continue; } r = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &device_number, sizeof(device_number), &size, NULL); if ((!r) || (size <= 0)) { uprintf("IOCTL_STORAGE_GET_DEVICE_NUMBER failed for device %s: %s/n", logical_drive, WindowsErrorString()); } else if (device_number.DeviceNumber == DriveIndex) { break; } safe_closehandle(hDrive); } if (hDrive == INVALID_HANDLE_VALUE) { goto out; } if (bWriteAccess) { uprintf("Caution: Opened %s drive for write access/n", logical_drive); } *DriveLetter = *drive?*drive:' '; } if ((bLockDrive) && (!DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL))) { uprintf("Could not get exclusive access to %s %s/n", logical_drive, WindowsErrorString());//.........这里部分代码省略.........
开发者ID:kthguru,项目名称:rufus,代码行数:101,
示例14: portTASK_FUNCTIONstatic portTASK_FUNCTION( vComRxTask, pvParameters ) {signed char cExpectedByte, cByteRxed;portBASE_TYPE xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;portBASE_TYPE xGotChar;int ch, mm=0;char s[30]; /* Just to stop compiler warnings. */ ( void ) pvParameters; vTaskDelay(1); //vSerialPutString(xPort, "mulakan/r/n", 9); init_banner(); //set_env_default(); baca_konfig_rom(); // hardware/iap.c //load_data_rtc(); cmd_shell(); st_hw.init++; #ifdef PAKAI_RTC //init_RTC_sh(); start_uptime(); #endif #ifdef PAKAI_SDCARD st_hw.sdc = 0; //disk_initialize(SDC); disk_initialize(0); set_fs_mount(); cek_fs_free(); //mount_disk(0); // 0: SDCARD //uprintf("Cek Memori SDCARD: ..."); //cek_free_cluster(); st_hw.sdc = 1; #endif #ifdef configUSE_IDLE_HOOK st_hw.init++; #endif do { vTaskDelay(100); } while (st_hw.init != uxTaskGetNumberOfTasks()); //vTaskDelay(100); #ifdef PAKAI_SDCARD //uprintf("Cek Memori SDCARD: ..."); //cek_free_cluster(); #endif vTaskDelay(100); sprintf(s, "%s$ ", PROMPT); #ifdef PAKAI_FREERTOS_CLI // gak jadi pake FreeRTOS-CLI uprintf(s); vRegisterCLICommands(); for(;;) { //uprintf("Merdeka!!!/r/n"); //vSerialPutString(xPort, "tes/r/n", 5); xGotChar = xSerialGetChar( xPort, &ch, 10 ); if( xGotChar == pdTRUE ) { //if( xSerialGetChar( xPort, &ch, comRX_BLOCK_TIME ) ) { // comRX_BLOCK_TIME = 0xffff //tinysh_char_in((unsigned char) ch); toogle_led_utama(); if ((uchr) ch=='/r') { sprintf(s, "/r/n%s$ ", PROMPT); uprintf(s); } } vTaskDelay(10); } #endif #ifdef PAKAI_TINYSH tinysh_set_prompt(s); tinysh_char_in('/r'); vTaskDelay(500); for( ;; ) { //vTaskDelay(10); //printf("testing/r/n"); xGotChar = xSerialGetChar( xPort, &ch, 10 ); if( xGotChar == pdTRUE ) { tinysh_char_in((unsigned char) ch); toogle_led_utama(); } if (st_hw.mm>=120) { // cron tiap 1 menit //if (st_hw.mm >= 10) { // cron tiap 10detik //if (st_hw.mm>=2) { // cron tiap 1 detik st_hw.mm = 0; st_hw.uuwaktu++; #ifdef PAKAI_FILE_SIMPAN simpan_file_data(); #endif } qrprintf(0);//.........这里部分代码省略.........
开发者ID:afrendybayu,项目名称:kapalinduk,代码行数:101,
示例15: SearchProcessThreadstatic DWORD WINAPI SearchProcessThread(LPVOID param){ const char *access_rights_str[8] = { "n", "r", "w", "rw", "x", "rx", "wx", "rwx" }; char tmp[MAX_PATH]; NTSTATUS status = STATUS_SUCCESS; PSYSTEM_HANDLE_INFORMATION_EX handles = NULL; POBJECT_NAME_INFORMATION buffer = NULL; ULONG_PTR i; ULONG_PTR pid[2]; ULONG_PTR last_access_denied_pid = 0; ULONG bufferSize; USHORT wHandleNameLen; WCHAR *wHandleName = NULL; HANDLE dupHandle = NULL; HANDLE processHandle = NULL; BOOLEAN bFound = FALSE, bGotExePath, verbose = !_bQuiet; ULONG access_rights = 0; DWORD size; char exe_path[MAX_PATH] = { 0 }; wchar_t wexe_path[MAX_PATH]; int cur_pid; PF_INIT_OR_SET_STATUS(NtQueryObject, Ntdll); PF_INIT_OR_SET_STATUS(NtDuplicateObject, NtDll); PF_INIT_OR_SET_STATUS(NtClose, NtDll); StrArrayClear(&BlockingProcess); if (NT_SUCCESS(status)) status = PhCreateHeap(); if (NT_SUCCESS(status)) status = PhEnumHandlesEx(&handles); if (!NT_SUCCESS(status)) { uprintf("Warning: Could not enumerate process handles: %s", NtStatusError(status)); goto out; } pid[0] = (ULONG_PTR)0; cur_pid = 1; wHandleName = utf8_to_wchar(_HandleName); wHandleNameLen = (USHORT)wcslen(wHandleName); bufferSize = 0x200; buffer = PhAllocate(bufferSize); if (buffer == NULL) goto out; for (i = 0; ; i++) { ULONG attempts = 8; PSYSTEM_HANDLE_TABLE_ENTRY_INFO_EX handleInfo = (i < handles->NumberOfHandles) ? &handles->Handles[i] : NULL; if ((dupHandle != NULL) && (processHandle != NtCurrentProcess())) { pfNtClose(dupHandle); dupHandle = NULL; } // Update the current handle's process PID and compare against last // Note: Be careful about not trying to overflow our list! pid[cur_pid] = (handleInfo != NULL) ? handleInfo->UniqueProcessId : -1; if (pid[0] != pid[1]) { cur_pid = (cur_pid + 1) % 2; // If we're switching process and found a match, print it if (bFound) { vuprintf("● '%s' (pid: %ld, access: %s)", exe_path, pid[cur_pid], access_rights_str[access_rights & 0x7]); static_sprintf(tmp, "● %s (%s)", exe_path, access_rights_str[access_rights & 0x7]); StrArrayAdd(&BlockingProcess, tmp, TRUE); bFound = FALSE; access_rights = 0; } // Close the previous handle if (processHandle != NULL) { if (processHandle != NtCurrentProcess()) pfNtClose(processHandle); processHandle = NULL; } } CHECK_FOR_USER_CANCEL; // Exit loop condition if (i >= handles->NumberOfHandles) break; // Don't bother with processes we can't access if (handleInfo->UniqueProcessId == last_access_denied_pid) continue; // Filter out handles that aren't opened with Read (bit 0), Write (bit 1) or Execute (bit 5) access if ((handleInfo->GrantedAccess & 0x23) == 0) continue; // Open the process to which the handle we are after belongs, if not already opened if (pid[0] != pid[1]) {//.........这里部分代码省略.........
开发者ID:zod331,项目名称:rufus,代码行数:101,
示例16: htab_hash/* * This is the search function. It uses double hashing with open addressing. * We use a trick to speed up the lookup. The table is created with one * more element available. This enables us to use the index zero special. * This index will never be used because we store the first hash index in * the field used where zero means not used. Every other value means used. * The used field can be used as a first fast comparison for equality of * the stored and the parameter value. This helps to prevent unnecessary * expensive calls of strcmp. */uint32_t htab_hash(char* str, htab_table* htab){ uint32_t hval, hval2; uint32_t idx; uint32_t r = 0; int c; char* sz = str; if ((htab == NULL) || (htab->table == NULL) || (str == NULL)) { return 0; } // Compute main hash value using sdbm's algorithm (empirically // shown to produce half the collisions as djb2's). // See http://www.cse.yorku.ca/~oz/hash.html while ((c = *sz++) != 0) r = c + (r << 6) + (r << 16) - r; if (r == 0) ++r; // compute table hash: simply take the modulus hval = r % htab->size; if (hval == 0) ++hval; // Try the first index idx = hval; if (htab->table[idx].used) { if ( (htab->table[idx].used == hval) && (safe_strcmp(str, htab->table[idx].str) == 0) ) { // existing hash return idx; } // uprintf("hash collision ('%s' vs '%s')/n", str, htab_table[idx].str); // Second hash function, as suggested in [Knuth] hval2 = 1 + hval % (htab->size - 2); do { // Because size is prime this guarantees to step through all available indexes if (idx <= hval2) { idx = ((uint32_t)htab->size) + idx - hval2; } else { idx -= hval2; } // If we visited all entries leave the loop unsuccessfully if (idx == hval) { break; } // If entry is found use it. if ( (htab->table[idx].used == hval) && (safe_strcmp(str, htab->table[idx].str) == 0) ) { return idx; } } while (htab->table[idx].used); } // Not found => New entry // If the table is full return an error if (htab->filled >= htab->size) { uprintf("hash table is full (%d entries)", htab->size); return 0; } safe_free(htab->table[idx].str); htab->table[idx].used = hval; htab->table[idx].str = (char*) malloc(safe_strlen(str)+1); if (htab->table[idx].str == NULL) { uprintf("could not duplicate string for hash table/n"); return 0; } memcpy(htab->table[idx].str, str, safe_strlen(str)+1); ++htab->filled; return idx;}
开发者ID:Cheesebaron,项目名称:rufus,代码行数:91,
示例17: cq_test/* CQ allocation and modification test */int cq_test(struct mlx4_dev *dev, char* log) { struct mlx4_cq *cq; struct mlx4_mtt *mtt; struct mlx4_uar *uar; struct mlx4_db *db; int err; int expected_rc = 0; int collapsed = 0; int timestamp_en = 0; int npages = 1; int page_shift = get_order(dev->caps.cqe_size) + PAGE_SHIFT; int ret_val = FAIL; int vector = 0; int nent = 2 * MLX4_NUM_TUNNEL_BUFS; u16 count = 88; u16 period = 0; u64 mtt_addr; uar = malloc(sizeof *uar ,M_CQ_VAL, M_WAITOK ); VL_CHECK_MALLOC(uar, goto without_free, log); mtt = malloc(sizeof *mtt ,M_CQ_VAL, M_WAITOK ); VL_CHECK_MALLOC(mtt, goto free_uar, log); cq = malloc(sizeof *cq ,M_CQ_VAL, M_WAITOK ); VL_CHECK_MALLOC(cq, goto free_mtt, log); db = malloc(sizeof *db ,M_CQ_VAL, M_WAITOK ); VL_CHECK_MALLOC(db, goto free_cq, log); err = mlx4_mtt_init(dev, npages, page_shift, mtt); VL_CHECK_RC(err, expected_rc, goto free_db , log, "failed to initialize MTT"); uprintf("MTT was initialized successfuly/n"); VL_CHECK_INT_VALUE(mtt->order, 0, goto cleanup_mtt, log, "mtt->order is wrong"); VL_CHECK_INT_VALUE(mtt->page_shift, 12, goto cleanup_mtt, log, "mtt->page_shift is wrong"); mtt_addr = mlx4_mtt_addr(dev, mtt); uprintf("MTT address is: %lu/n", mtt_addr); err = mlx4_uar_alloc(dev, uar); VL_CHECK_RC(err, expected_rc, goto cleanup_mtt , log, "failed to allocate UAR"); uprintf("UAR was allocated successfuly/n"); err = mlx4_db_alloc(dev, db, 1); VL_CHECK_RC(err, expected_rc, goto dealloc_uar , log, "failed to allocate DB"); uprintf("DB was allocated successfuly/n"); err = mlx4_cq_alloc(dev, nent, mtt, uar, db->dma, cq, vector, collapsed, timestamp_en); VL_CHECK_RC(err, expected_rc, goto dealloc_db , log, "failed to allocate CQ"); uprintf("CQ allocated successfuly/n"); VL_CHECK_INT_VALUE(cq->cons_index, 0, goto dealloc_cq, log, "cq->cons_index is wrong"); VL_CHECK_INT_VALUE(cq->arm_sn, 1, goto dealloc_cq, log, "cq->arm_sn is wrong"); uprintf("cq->cqn = %d, cq->uar->pfn = %lu, cq->eqn = %d, cq->irq = %u/n", cq->cqn, cq->uar->pfn, cq->eqn, cq->irq ); VL_CHECK_UNSIGNED_INT_VALUE(cq->cons_index, (unsigned int)0, goto dealloc_cq, log, "cq->cons_index != 0"); VL_CHECK_INT_VALUE(cq->arm_sn, 1, goto dealloc_cq, log, "cq->arm_sn != 1"); err = mlx4_cq_modify(dev, cq, count, period); VL_CHECK_RC(err, expected_rc, goto dealloc_cq , log, "failed to modify CQ"); uprintf("CQ was modifyed successfuly/n"); ret_val = SUCCESS;dealloc_cq: mlx4_cq_free(dev, cq); uprintf("CQ was freed successfuly/n");dealloc_db: mlx4_db_free(dev, db); uprintf( "DB free was successful/n");dealloc_uar: mlx4_uar_free(dev,uar); uprintf("UAR free was successful/n");cleanup_mtt: mlx4_mtt_cleanup(dev, mtt); uprintf( "mtt clean-up was successful/n");free_db: free(db, M_CQ_VAL);free_cq: free(cq, M_CQ_VAL);free_mtt: free(mtt, M_CQ_VAL);free_uar: free(uar, M_CQ_VAL);without_free: return ret_val;}
开发者ID:ldesiqueira,项目名称:freebsd_mlx5en,代码行数:97,
示例18: FileIO/* * read or write I/O to a file * buffer is allocated by the procedure. path is UTF-8 */BOOL FileIO(BOOL save, char* path, char** buffer, DWORD* size){ SECURITY_ATTRIBUTES s_attr, *ps = NULL; SECURITY_DESCRIPTOR s_desc; PSID sid = NULL; HANDLE handle; BOOL r; BOOL ret = FALSE; // Change the owner from admin to regular user sid = GetSID(); if ( (sid != NULL) && InitializeSecurityDescriptor(&s_desc, SECURITY_DESCRIPTOR_REVISION) && SetSecurityDescriptorOwner(&s_desc, sid, FALSE) ) { s_attr.nLength = sizeof(SECURITY_ATTRIBUTES); s_attr.bInheritHandle = FALSE; s_attr.lpSecurityDescriptor = &s_desc; ps = &s_attr; } else { uprintf("Could not set security descriptor: %s/n", WindowsErrorString()); } if (!save) { *buffer = NULL; } handle = CreateFileU(path, save?GENERIC_WRITE:GENERIC_READ, FILE_SHARE_READ, ps, save?CREATE_ALWAYS:OPEN_EXISTING, 0, NULL); if (handle == INVALID_HANDLE_VALUE) { uprintf("Could not %s file '%s'/n", save?"create":"open", path); goto out; } if (save) { r = WriteFile(handle, *buffer, *size, size, NULL); } else { *size = GetFileSize(handle, NULL); *buffer = (char*)malloc(*size); if (*buffer == NULL) { uprintf("Could not allocate buffer for reading file/n"); goto out; } r = ReadFile(handle, *buffer, *size, size, NULL); } if (!r) { uprintf("I/O Error: %s/n", WindowsErrorString()); goto out; } PrintStatus(0, TRUE, save?MSG_216:MSG_215, path); ret = TRUE;out: CloseHandle(handle); if (!ret) { // Only leave a buffer allocated if successful *size = 0; if (!save) { safe_free(*buffer); } } return ret;}
开发者ID:Cheesebaron,项目名称:rufus,代码行数:68,
示例19: SetLGPBOOL SetLGP(BOOL bRestore, BOOL* bExistingKey, const char* szPath, const char* szPolicy, DWORD dwValue){ LONG r; DWORD disp, regtype, val=0, val_size=sizeof(DWORD); HRESULT hr; IGroupPolicyObject* pLGPO; // Along with global 'existing_key', this static value is used to restore initial state static DWORD original_val; HKEY path_key = NULL, policy_key = NULL; // MSVC is finicky about these ones => redefine them const IID my_IID_IGroupPolicyObject = { 0xea502723, 0xa23d, 0x11d1, { 0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3 } }; const IID my_CLSID_GroupPolicyObject = { 0xea502722, 0xa23d, 0x11d1, { 0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3 } }; GUID ext_guid = REGISTRY_EXTENSION_GUID; // Can be anything really GUID snap_guid = { 0x3D271CFC, 0x2BC6, 0x4AC2, {0xB6, 0x33, 0x3B, 0xDF, 0xF5, 0xBD, 0xAB, 0x2A} }; // We need an IGroupPolicyObject instance to set a Local Group Policy hr = CoCreateInstance(&my_CLSID_GroupPolicyObject, NULL, CLSCTX_INPROC_SERVER, &my_IID_IGroupPolicyObject, (LPVOID*)&pLGPO); if (FAILED(hr)) { uprintf("SetLGP: CoCreateInstance failed; hr = %x/n", hr); goto error; } hr = pLGPO->lpVtbl->OpenLocalMachineGPO(pLGPO, GPO_OPEN_LOAD_REGISTRY); if (FAILED(hr)) { uprintf("SetLGP: OpenLocalMachineGPO failed - error %x/n", hr); goto error; } hr = pLGPO->lpVtbl->GetRegistryKey(pLGPO, GPO_SECTION_MACHINE, &path_key); if (FAILED(hr)) { uprintf("SetLGP: GetRegistryKey failed - error %x/n", hr); goto error; } // The DisableSystemRestore is set in Software/Policies/Microsoft/Windows/DeviceInstall/Settings r = RegCreateKeyExA(path_key, szPath, 0, NULL, 0, KEY_SET_VALUE | KEY_QUERY_VALUE, NULL, &policy_key, &disp); if (r != ERROR_SUCCESS) { uprintf("SetLGP: Failed to open LGPO path %s - error %x/n", szPath, hr); goto error; } if ((disp == REG_OPENED_EXISTING_KEY) && (!bRestore) && (!(*bExistingKey))) { // backup existing value for restore *bExistingKey = TRUE; regtype = REG_DWORD; r = RegQueryValueExA(policy_key, szPolicy, NULL, ®type, (LPBYTE)&original_val, &val_size); if (r == ERROR_FILE_NOT_FOUND) { // The Key exists but not its value, which is OK *bExistingKey = FALSE; } else if (r != ERROR_SUCCESS) { uprintf("SetLGP: Failed to read original %s policy value - error %x/n", szPolicy, r); } } if ((!bRestore) || (*bExistingKey)) { val = (bRestore)?original_val:dwValue; r = RegSetValueExA(policy_key, szPolicy, 0, REG_DWORD, (BYTE*)&val, sizeof(val)); } else { r = RegDeleteValueA(policy_key, szPolicy); } if (r != ERROR_SUCCESS) { uprintf("SetLGP: RegSetValueEx / RegDeleteValue failed - error %x/n", r); } RegCloseKey(policy_key); policy_key = NULL; // Apply policy hr = pLGPO->lpVtbl->Save(pLGPO, TRUE, (bRestore)?FALSE:TRUE, &ext_guid, &snap_guid); if (r != S_OK) { uprintf("SetLGP: Unable to apply %s policy - error %x/n", szPolicy, hr); goto error; } else { if ((!bRestore) || (*bExistingKey)) { uprintf("SetLGP: Successfully %s %s policy to 0x%08X/n", (bRestore)?"restored":"set", szPolicy, val); } else { uprintf("SetLGP: Successfully removed %s policy key/n", szPolicy); } } RegCloseKey(path_key); pLGPO->lpVtbl->Release(pLGPO); return TRUE;error: if (path_key != NULL) RegCloseKey(path_key); if (policy_key != NULL) RegCloseKey(policy_key); if (pLGPO != NULL) pLGPO->lpVtbl->Release(pLGPO); return FALSE;}
开发者ID:Cheesebaron,项目名称:rufus,代码行数:93,
示例20: chkdq/* * Update disk usage, and take corrective action. */intchkdq(struct inode *ip, ufs2_daddr_t change, struct ucred *cred, int flags){ struct dquot *dq; ufs2_daddr_t ncurblocks; struct vnode *vp = ITOV(ip); int i, error, warn, do_check; /* * Disk quotas must be turned off for system files. Currently * snapshot and quota files. */ if ((vp->v_vflag & VV_SYSTEM) != 0) return (0); /* * XXX: Turn off quotas for files with a negative UID or GID. * This prevents the creation of 100GB+ quota files. */ if ((int)ip->i_uid < 0 || (int)ip->i_gid < 0) return (0);#ifdef DIAGNOSTIC if ((flags & CHOWN) == 0) chkdquot(ip);#endif if (change == 0) return (0); if (change < 0) { for (i = 0; i < MAXQUOTAS; i++) { if ((dq = ip->i_dquot[i]) == NODQUOT) continue; DQI_LOCK(dq); DQI_WAIT(dq, PINOD+1, "chkdq1"); ncurblocks = dq->dq_curblocks + change; if (ncurblocks >= 0) dq->dq_curblocks = ncurblocks; else dq->dq_curblocks = 0; dq->dq_flags &= ~DQ_BLKS; dq->dq_flags |= DQ_MOD; DQI_UNLOCK(dq); } return (0); } if ((flags & FORCE) == 0 && priv_check_cred(cred, PRIV_VFS_EXCEEDQUOTA, 0)) do_check = 1; else do_check = 0; for (i = 0; i < MAXQUOTAS; i++) { if ((dq = ip->i_dquot[i]) == NODQUOT) continue; warn = 0; DQI_LOCK(dq); DQI_WAIT(dq, PINOD+1, "chkdq2"); if (do_check) { error = chkdqchg(ip, change, cred, i, &warn); if (error) { /* * Roll back user quota changes when * group quota failed. */ while (i > 0) { --i; dq = ip->i_dquot[i]; if (dq == NODQUOT) continue; DQI_LOCK(dq); DQI_WAIT(dq, PINOD+1, "chkdq3"); ncurblocks = dq->dq_curblocks - change; if (ncurblocks >= 0) dq->dq_curblocks = ncurblocks; else dq->dq_curblocks = 0; dq->dq_flags &= ~DQ_BLKS; dq->dq_flags |= DQ_MOD; DQI_UNLOCK(dq); } return (error); } } /* Reset timer when crossing soft limit */ if (dq->dq_curblocks + change >= dq->dq_bsoftlimit && dq->dq_curblocks < dq->dq_bsoftlimit) dq->dq_btime = time_second + ip->i_ump->um_btime[i]; dq->dq_curblocks += change; dq->dq_flags |= DQ_MOD; DQI_UNLOCK(dq); if (warn) uprintf("/n%s: warning, %s disk quota exceeded/n", ITOV(ip)->v_mount->mnt_stat.f_mntonname, quotatypes[i]); } return (0);}
开发者ID:jamesbjackson,项目名称:src,代码行数:97,
示例21: mtopenstatic intmtopen(dev_t dev, int flag, int mode, struct lwp *l){ struct mt_softc *sc; int req_den; int error; sc = device_lookup_private(&mt_cd, UNIT(dev)); if (sc == NULL) return ENXIO; if ((sc->sc_flags & MTF_EXISTS) == 0) return ENXIO; dlog(LOG_DEBUG, "%s open: flags 0x%x", device_xname(sc->sc_dev), sc->sc_flags); if (sc->sc_flags & MTF_OPEN) return EBUSY; sc->sc_flags |= MTF_OPEN; sc->sc_ttyp = tprintf_open(l->l_proc); if ((sc->sc_flags & MTF_ALIVE) == 0) { error = mtcommand(dev, MTRESET, 0); if (error != 0 || (sc->sc_flags & MTF_ALIVE) == 0) goto errout; if ((sc->sc_stat1 & (SR1_BOT | SR1_ONLINE)) == SR1_ONLINE) (void) mtcommand(dev, MTREW, 0); } for (;;) { if ((error = mtcommand(dev, MTNOP, 0)) != 0) goto errout; if (!(sc->sc_flags & MTF_REW)) break; if (tsleep((void *) &lbolt, PCATCH | (PZERO + 1), "mt", 0) != 0) { error = EINTR; goto errout; } } if ((flag & FWRITE) && (sc->sc_stat1 & SR1_RO)) { error = EROFS; goto errout; } if (!(sc->sc_stat1 & SR1_ONLINE)) { uprintf("%s: not online/n", device_xname(sc->sc_dev)); error = EIO; goto errout; } /* * Select density: * - find out what density the drive is set to * (i.e. the density of the current tape) * - if we are going to write * - if we're not at the beginning of the tape * - complain if we want to change densities * - otherwise, select the mtcommand to set the density * * If the drive doesn't support it then don't change the recorded * density. * * The original MOREbsd code had these additional conditions * for the mid-tape change * * req_den != T_BADBPI && * sc->sc_density != T_6250BPI * * which suggests that it would be possible to write multiple * densities if req_den == T_BAD_BPI or the current tape * density was 6250. Testing of our 7980 suggests that the * device cannot change densities mid-tape. * * [email C++ uprv_free函数代码示例 C++ uprint函数代码示例
|