static int smbfs_smb_seteof(struct smbnode *np, int64_t newsize, struct smb_cred *scred) { struct smb_t2rq *t2p; struct smb_share *ssp = np->n_mount->sm_share; struct mbchain *mbp; int error; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_FILE_INFORMATION, scred, &t2p); if (error) return error; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_mem(mbp, (caddr_t)&np->n_fid, 2, MB_MSYSTEM); mb_put_uint16le(mbp, SMB_SET_FILE_END_OF_FILE_INFO); mb_put_uint32le(mbp, 0); mbp = &t2p->t2_tdata; mb_init(mbp); mb_put_int64le(mbp, newsize); mb_put_uint32le(mbp, 0); /* padding */ mb_put_uint16le(mbp, 0); t2p->t2_maxpcount = 2; t2p->t2_maxdcount = 0; error = smb_t2_request(t2p); smb_t2_done(t2p); return error; }
/* * NT level. Specially for win9x */ int smbfs_smb_setpattrNT(struct smbnode *np, u_short attr, struct timespec *mtime, struct timespec *atime, struct smb_cred *scred) { struct smb_t2rq *t2p; struct smb_share *ssp = np->n_mount->sm_share; struct smb_vc *vcp = SSTOVC(ssp); struct mbchain *mbp; int64_t tm; int error, tzoff; /* * SMB_SET_FILE_BASIC_INFO isn't supported for * SMB_TRANS2_SET_PATH_INFORMATION, * so use SMB_SET_FILE_BASIC_INFORMATION instead, * but it requires SMB_CAP_INFOLEVEL_PASSTHRU capability. */ if ((SMB_CAPS(vcp) & SMB_CAP_INFOLEVEL_PASSTHRU) == 0) return smbfs_smb_setptime2(np, mtime, atime, attr, scred); error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_PATH_INFORMATION, scred, &t2p); if (error) return error; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_uint16le(mbp, SMB_SET_FILE_BASIC_INFORMATION); mb_put_uint32le(mbp, 0); /* MBZ */ error = smbfs_fullpath(mbp, vcp, np, NULL, 0); if (error) { smb_t2_done(t2p); return error; } tzoff = vcp->vc_sopt.sv_tz; mbp = &t2p->t2_tdata; mb_init(mbp); mb_put_int64le(mbp, 0); /* creation time */ if (atime) { smb_time_local2NT(atime, tzoff, &tm); } else tm = 0; mb_put_int64le(mbp, tm); if (mtime) { smb_time_local2NT(mtime, tzoff, &tm); } else tm = 0; mb_put_int64le(mbp, tm); mb_put_int64le(mbp, tm); /* change time */ mb_put_uint32le(mbp, attr); /* attr */ mb_put_uint32le(mbp, 0); /* padding */ t2p->t2_maxpcount = 2; t2p->t2_maxdcount = 0; error = smb_t2_request(t2p); smb_t2_done(t2p); return error; }
/* * Note, win95 doesn't support this call. */ int smbfs_smb_setptime2(struct smbnode *np, struct timespec *mtime, struct timespec *atime, int attr, struct smb_cred *scred) { struct smb_t2rq *t2p; struct smb_share *ssp = np->n_mount->sm_share; struct smb_vc *vcp = SSTOVC(ssp); struct mbchain *mbp; u_int16_t date, time; int error, tzoff; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_PATH_INFORMATION, scred, &t2p); if (error) return error; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_uint16le(mbp, SMB_INFO_STANDARD); mb_put_uint32le(mbp, 0); /* MBZ */ /* mb_put_uint8(mbp, SMB_DT_ASCII); specs incorrect */ error = smbfs_fullpath(mbp, vcp, np, NULL, 0); if (error) { smb_t2_done(t2p); return error; } tzoff = vcp->vc_sopt.sv_tz; mbp = &t2p->t2_tdata; mb_init(mbp); mb_put_uint32le(mbp, 0); /* creation time */ if (atime) smb_time_unix2dos(atime, tzoff, &date, &time, NULL); else time = date = 0; mb_put_uint16le(mbp, date); mb_put_uint16le(mbp, time); if (mtime) smb_time_unix2dos(mtime, tzoff, &date, &time, NULL); else time = date = 0; mb_put_uint16le(mbp, date); mb_put_uint16le(mbp, time); mb_put_uint32le(mbp, 0); /* file size */ mb_put_uint32le(mbp, 0); /* allocation unit size */ mb_put_uint16le(mbp, attr); /* DOS attr */ mb_put_uint32le(mbp, 0); /* EA size */ t2p->t2_maxpcount = 5 * 2; t2p->t2_maxdcount = vcp->vc_txmax; error = smb_t2_request(t2p); smb_t2_done(t2p); return error; }
static int smb_rq_new(struct smb_rq *rqp, u_char cmd) { struct smb_vc *vcp = rqp->sr_vc; struct mbchain *mbp = &rqp->sr_rq; int error; rqp->sr_sendcnt = 0; mb_done(mbp); md_done(&rqp->sr_rp); error = mb_init(mbp); if (error) return error; mb_put_mem(mbp, SMB_SIGNATURE, SMB_SIGLEN, MB_MSYSTEM); mb_put_uint8(mbp, cmd); mb_put_uint32le(mbp, 0); /* DosError */ mb_put_uint8(mbp, vcp->vc_hflags); mb_put_uint16le(mbp, vcp->vc_hflags2); mb_put_mem(mbp, tzero, 12, MB_MSYSTEM); rqp->sr_rqtid = (u_int16_t*)mb_reserve(mbp, sizeof(u_int16_t)); mb_put_uint16le(mbp, 1 /*scred->sc_p->p_pid & 0xffff*/); rqp->sr_rquid = (u_int16_t*)mb_reserve(mbp, sizeof(u_int16_t)); mb_put_uint16le(mbp, rqp->sr_mid); return 0; }
/* shortems() for model-based initializer. */ void shortems_mb(int n,int p,int nclass,double *pi,double **X,double **Mu, double **LTSigma,int maxshortiter,double shorteps){ int i, iter, totiter = 0, n_par = p * (p + 1) / 2; double *oldpi, **oldMu, **oldLTSigma, oldllh = -Inf, llhval; MAKE_VECTOR(oldpi, nclass); MAKE_MATRIX(oldMu, nclass, p); MAKE_MATRIX(oldLTSigma, nclass, n_par); do{ mb_init(X, n, p, nclass, oldpi, oldMu, oldLTSigma); iter = maxshortiter - totiter; iter = shortemcluster(n, p, nclass, oldpi, X, oldMu, oldLTSigma, iter, shorteps, &llhval); if(llhval >= oldllh){ oldllh = llhval; cpy(oldMu, nclass, p, Mu); cpy(oldLTSigma, nclass, n_par, LTSigma); for(i = 0; i < nclass; i++) pi[i] = oldpi[i]; } totiter += iter; } while(totiter < maxshortiter); FREE_MATRIX(oldMu); FREE_MATRIX(oldLTSigma); FREE_VECTOR(oldpi); } /* End of shortems_mb(). */
static int smb_rq_new(struct smb_rq *rqp, uchar_t cmd) { struct mbchain *mbp = &rqp->sr_rq; struct smb_vc *vcp = rqp->sr_vc; int error; ASSERT(rqp != NULL); rqp->sr_sendcnt = 0; rqp->sr_cmd = cmd; mb_done(mbp); md_done(&rqp->sr_rp); error = mb_init(mbp); if (error) return (error); /* * Is this the right place to save the flags? */ rqp->sr_rqflags = vcp->vc_hflags; rqp->sr_rqflags2 = vcp->vc_hflags2; /* * The SMB header is filled in later by * smb_rq_fillhdr (see below) * Just reserve space here. */ mb_put_mem(mbp, NULL, SMB_HDRLEN, MB_MZERO); return (0); }
int smb_rq_init(struct smb_ctx *ctx, u_char cmd, size_t rpbufsz, struct smb_rq **rqpp) { struct smb_rq *rqp; rqp = malloc(sizeof(*rqp)); if (rqp == NULL) return ENOMEM; bzero(rqp, sizeof(*rqp)); rqp->rq_cmd = cmd; rqp->rq_ctx = ctx; mb_init(&rqp->rq_rq, M_MINSIZE); mb_init(&rqp->rq_rp, rpbufsz); *rqpp = rqp; return 0; }
static void _on_startup(void) { #if _USE_MEM_POOL _open_mem_pool(); mb_set_memory_manager(_pop_mem, _push_mem); #endif /* _USE_MEM_POOL */ _create_code(); #ifdef _HAS_TICKS srand((unsigned)_ticks()); #endif /* _HAS_TICKS */ mb_init(); mb_open(&bas); mb_debug_set_stepped_handler(bas, _on_stepped); mb_set_error_handler(bas, _on_error); mb_set_import_handler(bas, _on_import); #ifdef _HAS_TICKS mb_reg_fun(bas, ticks); #endif /* _HAS_TICKS */ mb_reg_fun(bas, now); mb_reg_fun(bas, set_importing_dirs); mb_reg_fun(bas, os); mb_reg_fun(bas, sys); mb_reg_fun(bas, trace); mb_reg_fun(bas, raise); mb_reg_fun(bas, gc); mb_reg_fun(bas, beep); }
/* * NT level. Specially for win9x */ int smbfs_smb_setpattrNT(struct smbnode *np, u_short attr, struct timespec *mtime, struct timespec *atime, struct smb_cred *scred) { struct smb_t2rq *t2p; struct smb_share *ssp = np->n_mount->sm_share; struct smb_vc *vcp = SSTOVC(ssp); struct mbchain *mbp; int64_t tm; int error, tzoff; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_PATH_INFORMATION, scred, &t2p); if (error) return error; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_uint16le(mbp, SMB_SET_FILE_BASIC_INFO); mb_put_uint32le(mbp, 0); /* MBZ */ /* mb_put_uint8(mbp, SMB_DT_ASCII); specs incorrect */ error = smbfs_fullpath(mbp, vcp, np, NULL, 0); if (error) { smb_t2_done(t2p); return error; } tzoff = vcp->vc_sopt.sv_tz; mbp = &t2p->t2_tdata; mb_init(mbp); mb_put_int64le(mbp, 0); /* creation time */ if (atime) { smb_time_local2NT(atime, tzoff, &tm); } else tm = 0; mb_put_int64le(mbp, tm); if (mtime) { smb_time_local2NT(mtime, tzoff, &tm); } else tm = 0; mb_put_int64le(mbp, tm); mb_put_int64le(mbp, tm); /* change time */ mb_put_uint32le(mbp, attr); /* attr */ t2p->t2_maxpcount = 24; t2p->t2_maxdcount = 56; error = smb_t2_request(t2p); smb_t2_done(t2p); return error; }
static lzo_bool alloc_mem(lzo_uint32 s1, lzo_uint32 s2, lzo_uint32 w) { lzo_bool r = 1; #if defined(USE_MALLOC) r &= mb_alloc(&block1, s1, ALIGN_SIZE); r &= mb_alloc(&block2, s2, ALIGN_SIZE); r &= mb_alloc(&wrkmem, w, ALIGN_SIZE); #else r &= mb_init(&block1, s1, ALIGN_SIZE, heap_block1, sizeof(heap_block1)); r &= mb_init(&block2, s2, ALIGN_SIZE, heap_block2, sizeof(heap_block2)); r &= mb_init(&wrkmem, w, ALIGN_SIZE, heap_wrkmem, sizeof(heap_wrkmem)); #endif if (!r) free_mem(); return r; }
/* * Set DOS file attributes. * Looks like this call can be used only if SMB_CAP_NT_SMBS bit is on. */ int smbfs_smb_setfattrNT(struct smbnode *np, u_int16_t attr, struct timespec *mtime, struct timespec *atime, struct smb_cred *scred) { struct smb_t2rq *t2p; struct smb_share *ssp = np->n_mount->sm_share; struct mbchain *mbp; int64_t tm; int error, svtz; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_SET_FILE_INFORMATION, scred, &t2p); if (error) return error; svtz = SSTOVC(ssp)->vc_sopt.sv_tz; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_mem(mbp, (caddr_t)&np->n_fid, 2, MB_MSYSTEM); mb_put_uint16le(mbp, SMB_SET_FILE_BASIC_INFO); mb_put_uint32le(mbp, 0); mbp = &t2p->t2_tdata; mb_init(mbp); mb_put_int64le(mbp, 0); /* creation time */ if (atime) { smb_time_local2NT(atime, svtz, &tm); } else tm = 0; mb_put_int64le(mbp, tm); if (mtime) { smb_time_local2NT(mtime, svtz, &tm); } else tm = 0; mb_put_int64le(mbp, tm); mb_put_int64le(mbp, tm); /* change time */ mb_put_uint16le(mbp, attr); mb_put_uint32le(mbp, 0); /* padding */ mb_put_uint16le(mbp, 0); t2p->t2_maxpcount = 2; t2p->t2_maxdcount = 0; error = smb_t2_request(t2p); smb_t2_done(t2p); return error; }
static int smb_cpdatain(struct mbchain *mbp, int len, caddr_t data) { int error; if (len == 0) return 0; error = mb_init(mbp); if (error) return error; return mb_put_mem(mbp, data, len, MB_MUSER); }
/** * Main function * Initialize controller and handle Modbus requests **/ int main(void) { uint8_t i; // load config data from eeprom loadEepromValues(); // init modules led_init(); adc_init(); windspeed_init(&windspeed, &errcnt, &cnt); onewiretemp_init(); mb_init(); mb_setIP(config.ip); // register adc handlers adc_register(0, read_temperature); adc_register(1, read_winddir); // register Modbus handlers and registers mb_addReadRegister(ENABLENUM, &(config.enable)); mb_addReadRegister(3, (uint16_t*)&winddir); mb_addReadRegister(4, (uint16_t*)&windspeed); mb_addReadRegister(5, (uint16_t*)&temperature); mb_addReadRegister(6, (uint16_t*)&errcnt); mb_addReadRegister(7, (uint16_t*)&cnt); mb_addReadRegister(8, (uint16_t*)&insideTemperature); mb_addWriteRegister(IP_HIGH, write_IP); mb_addWriteRegister(IP_LOW, write_IP); mb_addWriteRegister(ENABLENUM, write_enable); for (i = TEMPNUM; i < TEMPNUM+2*ARRAY_SIZE(config.temperatureCalibration); i++) mb_addWriteRegister(i, write_temperatureCalibration); // set DDR for sensor on/off SENS_DDR |= _BV(SENS_PIN); // enable interrupts sei(); // start proccessing setSensorStatus(); while (1) { // apply new IP address if requested if (renewIP) { renewIP = 0; mb_setIP(config.ip); } mb_handleRequest(); onewiretemp_update(&insideTemperature); } }
int main() { int d, pid[5]; char buf[BUFSIZE]; d = shm_open("/mailbox", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); ftruncate(d, sizeof(struct shared)); shm = mmap(NULL, sizeof(struct shared), PROT_READ | PROT_WRITE, MAP_SHARED, d, 0); mb_init(); pid[0] = fork(); if(pid[0] != 0) pid[1] = fork(); if(pid[0] == 0) { send("hello", getppid()); printf("%d here, I just sent something to %d\n", getpid(), getppid()); } else if(pid[1] == 0) { send("hi there", getppid()); printf("%d here, I just sent something to %d\n", getpid(), getppid()); sleep(2); printf("%d here, is there anything from %d?\n", getpid(), getppid()); if(receive(buf, getppid()) == 0) printf("Received: %s\n", buf); } else { sleep(1); printf("%d here, is there anything from %d?\n", getpid(), pid[0]); if(receive(buf, pid[0]) == 0) printf("Received: %s\n", buf); printf("%d here, is there anything from %d?\n", getpid(), pid[1]); if(receive(buf, pid[1]) == 0) printf("Received: %s\n", buf); send("welcome, my son", pid[1]); printf("%d here, I just sent something to %d\n", getpid(), pid[1]); sleep(5); } return 0; }
int userfw_domain_send_to_socket(struct socket *so, unsigned char *buf, size_t len) { struct mbchain m; int err; mb_init(&m); err = mb_put_mem(&m, buf, len, MB_MSYSTEM); if (err != 0) { mb_done(&m); return err; } sbappendstream(&(so->so_rcv), mb_detach(&m)); sorwakeup(so); return 0; }
int smbfs_smb_statfs2(struct smb_share *ssp, struct statfs *sbp, struct smb_cred *scred) { struct smb_t2rq *t2p; struct mbchain *mbp; struct mdchain *mdp; u_int16_t bsize; u_int32_t units, bpu, funits; int error; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_QUERY_FS_INFORMATION, scred, &t2p); if (error) return error; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_uint16le(mbp, SMB_INFO_ALLOCATION); t2p->t2_maxpcount = 4; t2p->t2_maxdcount = 4 * 4 + 2; error = smb_t2_request(t2p); if (error) { smb_t2_done(t2p); return error; } mdp = &t2p->t2_rdata; md_get_uint32(mdp, NULL); /* fs id */ md_get_uint32le(mdp, &bpu); md_get_uint32le(mdp, &units); md_get_uint32le(mdp, &funits); md_get_uint16le(mdp, &bsize); sbp->f_bsize = bpu * bsize; /* fundamental filesystem block size */ sbp->f_blocks= units; /* total data blocks in filesystem */ sbp->f_bfree = funits; /* free blocks in fs */ sbp->f_bavail= funits; /* free blocks avail to non-superuser */ sbp->f_files = 0xffff; /* total file nodes in filesystem */ sbp->f_ffree = 0xffff; /* free file nodes in fs */ smb_t2_done(t2p); return 0; }
static int smbfs_query_info_fs(struct smb_share *ssp, struct statfs *sbp, struct smb_cred *scred) { struct smb_t2rq *t2p; struct mbchain *mbp; struct mdchain *mdp; uint32_t bsize, bpu; int64_t units, funits; int error; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_QUERY_FS_INFORMATION, scred, &t2p); if (error) return (error); mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_uint16le(mbp, SMB_QUERY_FS_SIZE_INFO); t2p->t2_maxpcount = 2; t2p->t2_maxdcount = sizeof(int64_t) * 2 + sizeof(uint32_t) * 2; error = smb_t2_request(t2p); if (error) { smb_t2_done(t2p); return (error); } mdp = &t2p->t2_rdata; md_get_int64le(mdp, &units); md_get_int64le(mdp, &funits); md_get_uint32le(mdp, &bpu); md_get_uint32le(mdp, &bsize); sbp->f_bsize = bpu * bsize; /* fundamental filesystem block size */ sbp->f_blocks= (uint64_t)units; /* total data blocks in filesystem */ sbp->f_bfree = (uint64_t)funits;/* free blocks in fs */ sbp->f_bavail= (uint64_t)funits;/* free blocks avail to non-superuser */ sbp->f_files = 0xffff; /* total file nodes in filesystem */ sbp->f_ffree = 0xffff; /* free file nodes in fs */ smb_t2_done(t2p); return (0); }
static int smb_rq_new(struct smb_rq *rqp, u_char cmd) { struct smb_vc *vcp = rqp->sr_vc; struct mbchain *mbp = &rqp->sr_rq; int error; u_int16_t flags2; rqp->sr_sendcnt = 0; mb_done(mbp); md_done(&rqp->sr_rp); error = mb_init(mbp); if (error) return error; mb_put_mem(mbp, SMB_SIGNATURE, SMB_SIGLEN, MB_MSYSTEM); mb_put_uint8(mbp, cmd); mb_put_uint32le(mbp, 0); /* DosError */ mb_put_uint8(mbp, vcp->vc_hflags); flags2 = vcp->vc_hflags2; if (cmd == SMB_COM_TRANSACTION || cmd == SMB_COM_TRANSACTION_SECONDARY) flags2 &= ~SMB_FLAGS2_UNICODE; if (cmd == SMB_COM_NEGOTIATE) flags2 &= ~SMB_FLAGS2_SECURITY_SIGNATURE; mb_put_uint16le(mbp, flags2); if ((flags2 & SMB_FLAGS2_SECURITY_SIGNATURE) == 0) { mb_put_mem(mbp, tzero, 12, MB_MSYSTEM); rqp->sr_rqsig = NULL; } else { mb_put_uint16le(mbp, 0 /*scred->sc_p->p_pid >> 16*/); rqp->sr_rqsig = (u_int8_t *)mb_reserve(mbp, 8); mb_put_uint16le(mbp, 0); } rqp->sr_rqtid = mb_reserve(mbp, sizeof(u_int16_t)); mb_put_uint16le(mbp, 1 /*scred->sc_p->p_pid & 0xffff*/); rqp->sr_rquid = mb_reserve(mbp, sizeof(u_int16_t)); mb_put_uint16le(mbp, rqp->sr_mid); return 0; }
int main(void) { // Initialization of various modules. timers_init(); leds_init(); gpiote_init(); buttons_init(); ble_stack_init(); scheduler_init(); device_manager_init(); mb_init(); // Start scanning for peripherals bt_scan_start(); for (;; ) { app_sched_execute(); power_manage(); } }
int ncp_rq_init_any(struct ncp_rq *rqp, u_int32_t ptype, u_int8_t fn, struct ncp_conn *ncp, struct thread *td, struct ucred *cred) { struct ncp_rqhdr *rq; struct ncp_bursthdr *brq; struct mbchain *mbp; int error; bzero(rqp, sizeof(*rqp)); error = ncp_conn_access(ncp, cred, NCPM_EXECUTE); if (error) return error; rqp->nr_td = td; rqp->nr_cred = cred; rqp->nr_conn = ncp; mbp = &rqp->rq; if (mb_init(mbp) != 0) return ENOBUFS; switch(ptype) { case NCP_PACKET_BURST: brq = (struct ncp_bursthdr*)mb_reserve(mbp, sizeof(*brq)); brq->bh_type = ptype; brq->bh_streamtype = 0x2; break; default: rq = (struct ncp_rqhdr*)mb_reserve(mbp, sizeof(*rq)); rq->type = ptype; rq->seq = 0; /* filled later */ rq->fn = fn; break; } rqp->nr_minrplen = -1; return 0; }
void lockTests() { ULT_Yield(ULT_ANY); startAlarmHelper(); interruptsQuiet(); /* * One mailbox */ Mailbox *mb = (Mailbox *)malloc(sizeof(Mailbox)); assert(mb); mb_init(mb, 2, MAXMAIL); ULT_CreateThread((void (*)(void *))mbWorker0, mb); while(!mb_checkDone(mb)){ ULT_Yield(ULT_ANY); } int jj; for(jj = 0; jj < 1000; jj++){ ULT_Yield(ULT_ANY); } assert(mb_checkDone(mb)); free(mb); printf("One mailbox, two threads OK\n"); /* * Two mailboxen */ mb = (Mailbox *)malloc(sizeof(Mailbox)); assert(mb); mb_init(mb, 2, MAXMAIL); Mailbox *mb2 = (Mailbox *)malloc(sizeof(Mailbox)); assert(mb2); mb_init(mb2, 2, MAXMAIL); ULT_CreateThread((void (*)(void *))mbWorker0, mb); ULT_CreateThread((void (*)(void *))mbWorker0, mb2); while(!mb_checkDone(mb)){ ULT_Yield(ULT_ANY); } for(jj = 0; jj < 1000; jj++){ ULT_Yield(ULT_ANY); } assert(mb_checkDone(mb)); while(!mb_checkDone(mb2)){ ULT_Yield(ULT_ANY); } for(jj = 0; jj < 1000; jj++){ ULT_Yield(ULT_ANY); } assert(mb_checkDone(mb2)); free(mb); free(mb2); printf("Two mailboxen, four threads OK\n"); printf("lockTests OK\n"); }
void condTests() { int tryProd; int tryCons; int tryColor; int tryBuf; int nProd; int nCons; int nColors; int nBuf; for(tryProd = 0; tryProd < 2; tryProd++){ if(tryProd == 0){ nProd = 1; } else{ nProd = 10; } for(tryCons = 0; tryCons < 2; tryCons++){ if(tryCons == 0){ nCons = 1; } else{ nCons = 10; } for(tryColor = 0; tryColor < 2; tryColor++){ if(tryColor == 0 || nProd == 1 || nCons == 1){ nColors = 1; } else{ nColors = 5; } for(tryBuf = 0; tryBuf < 3; tryBuf++){ if(tryBuf == 0){ nBuf = 1; } else if(tryBuf == 1){ nBuf = 5; } else{ nBuf = 50; } printf("condTests: nProd=%d nCons=%d nColors=%d nBuf=%d start\n", nProd, nCons, nColors, nBuf); Mailbox *mb = (Mailbox *)malloc(sizeof(Mailbox)); assert(mb); mb_init(mb, 1, nProd + nCons); PC *pc = (PC *)malloc(sizeof(PC)); assert(pc); PC_Init(pc, nBuf, nColors); doPCTest(nProd, nCons, nColors, pc, mb); while(!mb_checkDone(mb)){ /* Real code would make mb_checkDone block... */ } if(verbose){ printf("Free mb and pc\n"); } free(mb); free(pc); printf("condTests: nProd=%d nCons=%d nColors=%d nBuf=%d OK\n", nProd, nCons, nColors, nBuf); } } } } }
const char * set_encoding( char * name, /* Name of encoding specified */ char * env, /* Name of environment variable */ int pragma /* 2: #pragma setlocale, 1: #pragma __setlocale, 0: not #pragma */ ) /* * Search the encoding specified and re-initialize mbchar settings. */ { const char * unknown_encoding = "Unknown encoding: %s%.0ld%.0s"; /* _W1_ */ const char * too_long = "Too long encoding name: %s%.0ld%.0s"; /* _E_ */ const char * loc = ""; int alias; char norm[ NAMLEN]; /* * Normalized name (removed 'xxxxx.', stripped '_', '-', '.' * and lowered. */ if (strlen( name) >= NAMLEN) { if ((env || pragma) && (warn_level & 1)) { cwarn( too_long, name, 0L, NULL); } else { mcpp_fprintf( ERR, too_long, name); mcpp_fputc( '\n', ERR); } } strcpy( norm, name); if (norm[ 5] == '.') memmove( norm, norm + 5, strlen( norm + 5) + 1); /* Remove initial 'xxxxx.' as 'ja_JP.', 'en_US.' or any other */ conv_case( norm, norm + strlen( norm), LOWER); strip_bar( norm); if (strlen( name) == 0) { /* "" */ mbchar = MBCHAR; /* Restore to the default encoding */ } else if (memcmp( norm, "iso8859", 7) == 0 /* iso8859* */ || memcmp( norm, "latin", 5) == 0 /* latin* */ || memcmp( norm, "en", 2) == 0) { /* en* */ mbchar = 0; /* No multi-byte character */ } else { alias = 2; #if COMPILER == MSC if (pragma == SETLOCALE) /* #pragma setlocale */ alias = 0; #endif loc = search_encoding( norm, alias); /* Search the name */ } if (loc == NULL) { if ((env || pragma) && (warn_level & 1)) { cwarn( unknown_encoding, name, 0L, NULL); } else { /* -m option */ mcpp_fprintf( ERR, unknown_encoding, name); mcpp_fputc( '\n', ERR); } } else { mb_init(); /* Re-initialize */ } return loc; }
/* * TRANS2_FIND_FIRST2/NEXT2, used for NT LM12 dialect */ static int smbfs_smb_trans2find2(struct smbfs_fctx *ctx) { struct smb_t2rq *t2p; struct smb_vc *vcp = SSTOVC(ctx->f_ssp); struct mbchain *mbp; struct mdchain *mdp; u_int16_t tw, flags; int error; if (ctx->f_t2) { smb_t2_done(ctx->f_t2); ctx->f_t2 = NULL; } ctx->f_flags &= ~SMBFS_RDD_GOTRNAME; flags = 8 | 2; /* <resume> | <close if EOS> */ if (ctx->f_flags & SMBFS_RDD_FINDSINGLE) { flags |= 1; /* close search after this request */ ctx->f_flags |= SMBFS_RDD_NOCLOSE; } if (ctx->f_flags & SMBFS_RDD_FINDFIRST) { error = smb_t2_alloc(SSTOCP(ctx->f_ssp), SMB_TRANS2_FIND_FIRST2, ctx->f_scred, &t2p); if (error) return error; ctx->f_t2 = t2p; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_uint16le(mbp, ctx->f_attrmask); mb_put_uint16le(mbp, ctx->f_limit); mb_put_uint16le(mbp, flags); mb_put_uint16le(mbp, ctx->f_infolevel); mb_put_uint32le(mbp, 0); error = smbfs_fullpath(mbp, vcp, ctx->f_dnp, ctx->f_wildcard, ctx->f_wclen); if (error) return error; } else { error = smb_t2_alloc(SSTOCP(ctx->f_ssp), SMB_TRANS2_FIND_NEXT2, ctx->f_scred, &t2p); if (error) return error; ctx->f_t2 = t2p; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_mem(mbp, (caddr_t)&ctx->f_Sid, 2, MB_MSYSTEM); mb_put_uint16le(mbp, ctx->f_limit); mb_put_uint16le(mbp, ctx->f_infolevel); mb_put_uint32le(mbp, 0); /* resume key */ mb_put_uint16le(mbp, flags); if (ctx->f_rname) mb_put_mem(mbp, ctx->f_rname, ctx->f_rnamelen + 1, MB_MSYSTEM); else mb_put_uint8(mbp, 0); /* resume file name */ #if 0 struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 200 * 1000; /* 200ms */ if (vcp->vc_flags & SMBC_WIN95) { /* * some implementations suggests to sleep here * for 200ms, due to the bug in the Win95. * I've didn't notice any problem, but put code * for it. */ pause("fix95", tvtohz(&tv)); } #endif } t2p->t2_maxpcount = 5 * 2; t2p->t2_maxdcount = vcp->vc_txmax; error = smb_t2_request(t2p); if (error) return error; mdp = &t2p->t2_rparam; if (ctx->f_flags & SMBFS_RDD_FINDFIRST) { if ((error = md_get_uint16(mdp, &ctx->f_Sid)) != 0) return error; ctx->f_flags &= ~SMBFS_RDD_FINDFIRST; } if ((error = md_get_uint16le(mdp, &tw)) != 0) return error; ctx->f_ecnt = tw; if ((error = md_get_uint16le(mdp, &tw)) != 0) return error; if (tw) ctx->f_flags |= SMBFS_RDD_EOF | SMBFS_RDD_NOCLOSE; if ((error = md_get_uint16le(mdp, &tw)) != 0) return error; if ((error = md_get_uint16le(mdp, &tw)) != 0) return error; if (ctx->f_ecnt == 0) { ctx->f_flags |= SMBFS_RDD_EOF | SMBFS_RDD_NOCLOSE; return ENOENT; } ctx->f_rnameofs = tw; mdp = &t2p->t2_rdata; if (mdp->md_top == NULL) { printf("bug: ecnt = %d, but data is NULL (please report)\n", ctx->f_ecnt); return ENOENT; } if (mdp->md_top->m_len == 0) { printf("bug: ecnt = %d, but m_len = 0 and m_next = %p (please report)\n", ctx->f_ecnt,mbp->mb_top->m_next); return ENOENT; } ctx->f_eofs = 0; return 0; }
static int smbfs_smb_qpathinfo(struct smbnode *np, struct smbfattr *fap, struct smb_cred *scred, short infolevel) { struct smb_share *ssp = np->n_mount->sm_share; struct smb_vc *vcp = SSTOVC(ssp); struct smb_t2rq *t2p; int error, svtz, timesok = 1; struct mbchain *mbp; struct mdchain *mdp; u_int16_t date, time, wattr; int64_t lint; u_int32_t size, dattr; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_QUERY_PATH_INFORMATION, scred, &t2p); if (error) return error; mbp = &t2p->t2_tparam; mb_init(mbp); if (!infolevel) { if (SMB_DIALECT(vcp) < SMB_DIALECT_NTLM0_12) infolevel = SMB_QUERY_FILE_STANDARD; else infolevel = SMB_QUERY_FILE_BASIC_INFO; } mb_put_uint16le(mbp, infolevel); mb_put_uint32le(mbp, 0); /* mb_put_uint8(mbp, SMB_DT_ASCII); specs are wrong */ error = smbfs_fullpath(mbp, vcp, np, NULL, 0); if (error) { smb_t2_done(t2p); return error; } t2p->t2_maxpcount = 2; t2p->t2_maxdcount = vcp->vc_txmax; error = smb_t2_request(t2p); if (error) { smb_t2_done(t2p); if (infolevel == SMB_QUERY_FILE_STANDARD || error != EINVAL) return error; return smbfs_smb_qpathinfo(np, fap, scred, SMB_QUERY_FILE_STANDARD); } mdp = &t2p->t2_rdata; svtz = vcp->vc_sopt.sv_tz; switch (infolevel) { case SMB_QUERY_FILE_STANDARD: timesok = 0; md_get_uint16le(mdp, NULL); md_get_uint16le(mdp, NULL); /* creation time */ md_get_uint16le(mdp, &date); md_get_uint16le(mdp, &time); /* access time */ if (date || time) { timesok++; smb_dos2unixtime(date, time, 0, svtz, &fap->fa_atime); } md_get_uint16le(mdp, &date); md_get_uint16le(mdp, &time); /* modify time */ if (date || time) { timesok++; smb_dos2unixtime(date, time, 0, svtz, &fap->fa_mtime); } md_get_uint32le(mdp, &size); fap->fa_size = size; md_get_uint32(mdp, NULL); /* allocation size */ md_get_uint16le(mdp, &wattr); fap->fa_attr = wattr; break; case SMB_QUERY_FILE_BASIC_INFO: timesok = 0; md_get_int64(mdp, NULL); /* creation time */ md_get_int64le(mdp, &lint); if (lint) { timesok++; smb_time_NT2local(lint, svtz, &fap->fa_atime); } md_get_int64le(mdp, &lint); if (lint) { timesok++; smb_time_NT2local(lint, svtz, &fap->fa_mtime); } md_get_int64le(mdp, &lint); if (lint) { timesok++; smb_time_NT2local(lint, svtz, &fap->fa_ctime); } md_get_uint32le(mdp, &dattr); fap->fa_attr = dattr; md_get_uint32(mdp, NULL); /* XXX could use ALL_INFO to get size */ break; default: SMBERROR("unexpected info level %d\n", infolevel); error = EINVAL; } smb_t2_done(t2p); /* * if all times are zero (observed with FAT on NT4SP6) * then fall back to older info level */ if (!timesok) { if (infolevel != SMB_QUERY_FILE_STANDARD) return smbfs_smb_qpathinfo(np, fap, scred, SMB_QUERY_FILE_STANDARD); error = EINVAL; } return error; }
void note_initialize(void) { mb = mb_init(sizeof(struct node), 64); note_pool = npool_init(); }
int mcpp_lib_main #else int main #endif ( int argc, char ** argv ) { char * in_file = NULL; char * out_file = NULL; char * stdin_name = "<stdin>"; if (setjmp( error_exit) == -1) { errors++; goto fatal_error_exit; } #if MCPP_LIB /* Initialize global and static variables. */ init_main(); init_directive(); init_eval(); init_support(); init_system(); #endif fp_in = stdin; fp_out = stdout; fp_err = stderr; fp_debug = stdout; /* * Debugging information is output to stdout in order to * synchronize with preprocessed output. */ inc_dirp = &null; /* Initialize to current (null) directory */ cur_fname = cur_fullname = "(predefined)"; /* For predefined macros */ init_defines(); /* Predefine macros */ mb_init(); /* Should be initialized prior to get options */ do_options( argc, argv, &in_file, &out_file); /* Command line options */ /* Open input file, "-" means stdin. */ if (in_file != NULL && ! str_eq( in_file, "-")) { if ((fp_in = fopen( in_file, "r")) == NULL) { mcpp_fprintf( ERR, "Can't open input file \"%s\".\n", in_file); errors++; #if MCPP_LIB goto fatal_error_exit; #else return( IO_ERROR); #endif } } else { in_file = stdin_name; } /* Open output file, "-" means stdout. */ if (out_file != NULL && ! str_eq( out_file, "-")) { if ((fp_out = fopen( out_file, "w")) == NULL) { mcpp_fprintf( ERR, "Can't open output file \"%s\".\n", out_file); errors++; #if MCPP_LIB goto fatal_error_exit; #else return( IO_ERROR); #endif } fp_debug = fp_out; } if (option_flags.q) { /* Redirect diagnostics */ if ((fp_err = fopen( "mcpp.err", "a")) == NULL) { errors++; mcpp_fprintf( OUT, "Can't open \"mcpp.err\"\n"); #if MCPP_LIB goto fatal_error_exit; #else return( IO_ERROR); #endif } } init_sys_macro(); /* Initialize system-specific macros */ add_file( fp_in, NULL, in_file, in_file, FALSE); /* "open" main input file */ infile->dirp = inc_dirp; infile->sys_header = FALSE; cur_fullname = in_file; if (mkdep && str_eq( infile->real_fname, stdin_name) == FALSE) put_depend( in_file); /* Putout target file name */ at_start(); /* Do the pre-main commands */ mcpp_main(); /* Process main file */ if (mkdep) put_depend( NULL); /* Append '\n' to dependency line */ at_end(); /* Do the final commands */ fatal_error_exit: #if MCPP_LIB /* Free malloced memory */ if (mcpp_debug & MACRO_CALL) { if (in_file != stdin_name) free( in_file); } clear_filelist(); clear_symtable(); #endif if (fp_in != stdin) fclose( fp_in); if (fp_out != stdout) fclose( fp_out); if (fp_err != stderr) fclose( fp_err); if (mcpp_debug & MEMORY) print_heap(); if (errors > 0 && option_flags.no_source_line == FALSE) { mcpp_fprintf( ERR, "%d error%s in preprocessor.\n", errors, (errors == 1) ? "" : "s"); return IO_ERROR; } return IO_SUCCESS; /* No errors */ }
int smbfs_smb_statvfs(struct smb_share *ssp, struct statvfs *sbp, struct smb_cred *scred) { unsigned long bsize; /* Block (allocation unit) size */ unsigned long bavail, bfree; /* * The SMB request work with notion of sector size and * allocation units. Allocation unit is what 'block' * means in Unix context, sector size might be HW sector size. */ if (SMB_DIALECT(SSTOVC(ssp)) >= SMB_DIALECT_LANMAN2_0) { struct smb_t2rq *t2p; struct mbchain *mbp; struct mdchain *mdp; u_int16_t secsz; u_int32_t units, bpu, funits; int error; error = smb_t2_alloc(SSTOCP(ssp), SMB_TRANS2_QUERY_FS_INFORMATION, scred, &t2p); if (error) return error; mbp = &t2p->t2_tparam; mb_init(mbp); mb_put_uint16le(mbp, SMB_INFO_ALLOCATION); t2p->t2_maxpcount = 4; t2p->t2_maxdcount = 4 * 4 + 2; error = smb_t2_request(t2p); if (error) { smb_t2_done(t2p); return error; } mdp = &t2p->t2_rdata; md_get_uint32(mdp, NULL); /* fs id */ md_get_uint32le(mdp, &bpu); /* Number of sectors per unit */ md_get_uint32le(mdp, &units); /* Total number of units */ md_get_uint32le(mdp, &funits); /* Number of available units */ md_get_uint16le(mdp, &secsz); /* Number of bytes per sector */ smb_t2_done(t2p); bsize = bpu * secsz; bavail = units; bfree = funits; } else { struct smb_rq *rqp; struct mdchain *mdp; u_int16_t units, bpu, secsz, funits; int error; error = smb_rq_alloc(SSTOCP(ssp), SMB_COM_QUERY_INFORMATION_DISK, scred, &rqp); if (error) return error; smb_rq_wstart(rqp); smb_rq_wend(rqp); smb_rq_bstart(rqp); smb_rq_bend(rqp); error = smb_rq_simple(rqp); if (error) { smb_rq_done(rqp); return error; } smb_rq_getreply(rqp, &mdp); md_get_uint16le(mdp, &units); /* Total units per server */ md_get_uint16le(mdp, &bpu); /* Blocks per allocation unit */ md_get_uint16le(mdp, &secsz); /* Block size (in bytes) */ md_get_uint16le(mdp, &funits); /* Number of free units */ smb_rq_done(rqp); bsize = bpu * secsz; bavail = units; bfree = funits; } sbp->f_bsize = bsize; /* fundamental file system block size */ sbp->f_frsize = bsize; /* fundamental file system frag size */ sbp->f_iosize = bsize; /* optimal I/O size */ sbp->f_blocks = bavail; /* total data blocks in file system */ sbp->f_bfree = bfree; /* free blocks in fs */ sbp->f_bresvd = 0; /* reserved blocks in fs */ sbp->f_bavail= bfree; /* free blocks avail to non-superuser */ sbp->f_files = 0xffff; /* total file nodes in file system */ sbp->f_ffree = 0xffff; /* free file nodes to non-superuser */ sbp->f_favail = 0xffff; /* free file nodes in fs */ sbp->f_fresvd = 0; /* reserved file nodes in fs */ return 0; }
void *blkmgr_alloc(blkmgr_t *self, uint32_t size, uint32_t alignment)/*{{{*/ { void *memory = NULL; if (alignment) { DEBUG("\033[37;1mRequested block of size %u aligned to %u bytes boundary.\033[0m\n", size, alignment); } else { DEBUG("\033[37;1mRequested block of size %u.\033[0m\n", size); } arealst_wrlock(&self->blklst); /* looking for an area with free space */ area_t *area = (area_t *)self->blklst.local.next; mb_list_t *list = NULL; while (!area_is_guard(area)) { I(area_is_ready(area)); DEBUG("searching for free block in [$%.8x; %u; $%.2x]\n", (uint32_t)area, area->size, area->flags0); list = mb_list_from_area(area); memory = (alignment > 0) ? mb_alloc_aligned(list, size, alignment) : mb_alloc(list, size, FALSE); if (memory) break; area = area->local.next; } /* the area was not found - we must make some space */ if (memory == NULL) { uint32_t area_size = size + sizeof(area_t) + sizeof(mb_list_t) + sizeof(mb_t); if (alignment > 0) area_size += alignment; DEBUG("Trying to merge adjacent pages to managed areas.\n"); areamgr_prealloc_area(self->areamgr, SIZE_IN_PAGES(area_size)); area = (area_t *)self->blklst.local.next; bool merged = FALSE; while (!area_is_guard(area)) { mb_list_t *list = mb_list_from_area(area); uint32_t oldsize = area->size; if (areamgr_expand_area(self->areamgr, &area, SIZE_IN_PAGES(area_size), LEFT)) { mb_list_t *to_merge = mb_list_from_area(area); mb_init(to_merge, area->size - oldsize - sizeof(area_t)); list = mb_list_merge(to_merge, list, sizeof(area_t)); merged = TRUE; } else if (areamgr_expand_area(self->areamgr, &area, SIZE_IN_PAGES(area_size), RIGHT)) { mb_list_t *to_merge = (mb_list_t *)((uint32_t)area_end(area) - (area->size - oldsize)); mb_init(to_merge, area->size - oldsize - sizeof(area_t)); list = mb_list_merge(list, to_merge, sizeof(area_t)); merged = TRUE; } if (merged) { mb_list_t *to_merge = mb_list_from_area(area->local.next); if (area_end(area) == area_begining(area->local.next)) { I(area->local.next == area->global.next); arealst_remove_area(&self->blklst, area->local.next, DONTLOCK); arealst_join_area(&self->areamgr->global, area, area->global.next, LOCK); list = mb_list_merge(list, to_merge, sizeof(area_t)); } memory = alignment ? mb_alloc_aligned(list, size, alignment) : mb_alloc(list, size, FALSE); break; } area = area->local.next; } if (memory == NULL) { DEBUG("No adjacent areas found - try to create new blocks' manager.\n"); area_t *newarea = areamgr_alloc_area(self->areamgr, SIZE_IN_PAGES(area_size)); if (newarea != NULL) { mb_list_t *list = mb_list_from_area(newarea); mb_init(list, newarea->size - sizeof(area_t)); newarea->ready = TRUE; newarea->manager = AREA_MGR_BLKMGR; area_touch(newarea); arealst_insert_area_by_addr(&self->blklst, (void *)newarea, DONTLOCK); memory = alignment ? mb_alloc_aligned(list, size, alignment) : mb_alloc(list, size, FALSE); } } } arealst_unlock(&self->blklst); return memory; }/*}}}*/
int main() { mb_id_t mbid; pid_t pid; int nb_loops; int status; unsigned long mbcheck; const char *tagmb = "test_mailbox"; cm_openlog("test_mailbox", CM_TRACE_LEVEL_NOTICE); mbid = mb_create(tagmb, MB_LEN); if (mbid == MB_INVALID_ID) { return (1); } pid = fork(); if (pid == 0) { /* * Child - process callback */ mb_id_t child_mbid = mb_init(tagmb, act_callback); if (mb_len(mbid) != MB_LEN) { cm_trace(CM_TRACE_LEVEL_ERROR, "mb_len returns bad result"); exit(1); } while (1) { if (mb_hbt(child_mbid, NULL) != MB_OK) { cm_trace(CM_TRACE_LEVEL_ERROR, "mb_hbt failed %s", strerror(errno)); exit(1); } usleep(100000); } } else if (pid == -1) { cm_trace(CM_TRACE_LEVEL_ERROR, "fork failed"); exit(1); } /* * Father - check service state machine */ if (wait_for(mbid, SRV_READY) < 0) { cm_trace(CM_TRACE_LEVEL_ERROR, "failed to init"); kill(pid, SIGKILL); return (1); } if (wait_for(mbid, SRV_RUNNING) < 0) { cm_trace(CM_TRACE_LEVEL_ERROR, "failed to start"); kill(pid, SIGKILL); return (1); } if (mb_read(mbid, &mbcheck, MB_OFFSET, sizeof(mbcheck)) == MB_ERROR) { cm_trace(CM_TRACE_LEVEL_ERROR, "mb_read failed"); kill(pid, SIGKILL); return (1); } if (mbcheck != MB_CHECK) { cm_trace(CM_TRACE_LEVEL_ERROR, "mb_read returns wrong result"); kill(pid, SIGKILL); return (1); } if (wait_for(mbid, SRV_READY) < 0) { cm_trace(CM_TRACE_LEVEL_ERROR, "failed to stop"); kill(pid, SIGKILL); return (1); } if (mb_setexpectedstate(mbid, SRV_DESTROY) == MB_ERROR) { cm_trace(CM_TRACE_LEVEL_ERROR, "failed to destroy"); kill(pid, SIGKILL); return (1); } nb_loops = 0; do { pid_t wpid = waitpid(pid, &status, WNOHANG); if (wpid == pid) { break; } else if (wpid < 0) { cm_trace(CM_TRACE_LEVEL_ERROR, "waitpid failed"); kill(pid, SIGKILL); return (1); } usleep(100000); } while (nb_loops++ < 5); if (nb_loops >= 5) { cm_trace(CM_TRACE_LEVEL_ERROR, "destroy failed"); kill(pid, SIGKILL); return (1); } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { cm_trace(CM_TRACE_LEVEL_ERROR, "bad exit status"); kill(pid, SIGKILL); return (1); } cm_trace(CM_TRACE_LEVEL_NOTICE, "mailbox test passed"); cm_closelog(); return (0); }