本文整理汇总了C++中ISSET函数的典型用法代码示例。如果您正苦于以下问题:C++ ISSET函数的具体用法?C++ ISSET怎么用?C++ ISSET使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ISSET函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uftdi_param
Static int
uftdi_param(void *vsc, int portno, struct termios *t)
{
struct uftdi_softc *sc = vsc;
usb_device_request_t req;
usbd_status err;
int rate, data, flow;
DPRINTF(("uftdi_param: sc=%p\n", sc));
if (sc->sc_dying)
return (EIO);
req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
req.bRequest = FTDI_SIO_SET_BITMODE;
USETW(req.wValue, FTDI_BITMODE_RESET << 8 | 0x00);
USETW(req.wIndex, portno);
USETW(req.wLength, 0);
err = usbd_do_request(sc->sc_udev, &req, NULL);
if (err)
return (EIO);
switch (sc->sc_type) {
case UFTDI_TYPE_SIO:
switch (t->c_ospeed) {
case 300: rate = ftdi_sio_b300; break;
case 600: rate = ftdi_sio_b600; break;
case 1200: rate = ftdi_sio_b1200; break;
case 2400: rate = ftdi_sio_b2400; break;
case 4800: rate = ftdi_sio_b4800; break;
case 9600: rate = ftdi_sio_b9600; break;
case 19200: rate = ftdi_sio_b19200; break;
case 38400: rate = ftdi_sio_b38400; break;
case 57600: rate = ftdi_sio_b57600; break;
case 115200: rate = ftdi_sio_b115200; break;
default:
return (EINVAL);
}
break;
case UFTDI_TYPE_8U232AM:
switch(t->c_ospeed) {
case 300: rate = ftdi_8u232am_b300; break;
case 600: rate = ftdi_8u232am_b600; break;
case 1200: rate = ftdi_8u232am_b1200; break;
case 2400: rate = ftdi_8u232am_b2400; break;
case 4800: rate = ftdi_8u232am_b4800; break;
case 9600: rate = ftdi_8u232am_b9600; break;
case 19200: rate = ftdi_8u232am_b19200; break;
case 38400: rate = ftdi_8u232am_b38400; break;
case 57600: rate = ftdi_8u232am_b57600; break;
case 115200: rate = ftdi_8u232am_b115200; break;
case 230400: rate = ftdi_8u232am_b230400; break;
case 460800: rate = ftdi_8u232am_b460800; break;
case 921600: rate = ftdi_8u232am_b921600; break;
default:
return (EINVAL);
}
break;
default:
return (EINVAL);
}
req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
req.bRequest = FTDI_SIO_SET_BAUD_RATE;
USETW(req.wValue, rate);
USETW(req.wIndex, portno);
USETW(req.wLength, 0);
DPRINTFN(2,("uftdi_param: reqtype=0x%02x req=0x%02x value=0x%04x "
"index=0x%04x len=%d\n", req.bmRequestType, req.bRequest,
UGETW(req.wValue), UGETW(req.wIndex), UGETW(req.wLength)));
err = usbd_do_request(sc->sc_udev, &req, NULL);
if (err)
return (EIO);
if (ISSET(t->c_cflag, CSTOPB))
data = FTDI_SIO_SET_DATA_STOP_BITS_2;
else
data = FTDI_SIO_SET_DATA_STOP_BITS_1;
if (ISSET(t->c_cflag, PARENB)) {
if (ISSET(t->c_cflag, PARODD))
data |= FTDI_SIO_SET_DATA_PARITY_ODD;
else
data |= FTDI_SIO_SET_DATA_PARITY_EVEN;
} else
data |= FTDI_SIO_SET_DATA_PARITY_NONE;
switch (ISSET(t->c_cflag, CSIZE)) {
case CS5:
data |= FTDI_SIO_SET_DATA_BITS(5);
break;
case CS6:
data |= FTDI_SIO_SET_DATA_BITS(6);
break;
case CS7:
data |= FTDI_SIO_SET_DATA_BITS(7);
break;
case CS8:
data |= FTDI_SIO_SET_DATA_BITS(8);
break;
}
//.........这里部分代码省略.........
示例2: at91usart_attach_subr
void
at91usart_attach_subr(struct at91usart_softc *sc, struct at91bus_attach_args *sa)
{
struct tty *tp;
int err;
printf("\n");
if (bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0, &sc->sc_ioh))
panic("%s: Cannot map registers", device_xname(sc->sc_dev));
sc->sc_iot = sa->sa_iot;
sc->sc_hwbase = sa->sa_addr;
sc->sc_dmat = sa->sa_dmat;
sc->sc_pid = sa->sa_pid;
/* allocate fifos */
err = at91pdc_alloc_fifo(sc->sc_dmat, &sc->sc_rx_fifo, AT91USART_RING_SIZE, BUS_DMA_READ | BUS_DMA_STREAMING);
if (err)
panic("%s: cannot allocate rx fifo", device_xname(sc->sc_dev));
err = at91pdc_alloc_fifo(sc->sc_dmat, &sc->sc_tx_fifo, AT91USART_RING_SIZE, BUS_DMA_WRITE | BUS_DMA_STREAMING);
if (err)
panic("%s: cannot allocate tx fifo", device_xname(sc->sc_dev));
/* initialize uart */
at91_peripheral_clock(sc->sc_pid, 1);
at91usart_writereg(sc, US_IDR, -1);
at91usart_writereg(sc, US_RTOR, 12); // 12-bit timeout
at91usart_writereg(sc, US_PDC + PDC_PTCR, PDC_PTCR_TXTDIS | PDC_PTCR_RXTDIS);
at91_intr_establish(sa->sa_pid, IPL_TTY, INTR_HIGH_LEVEL, at91usart_intr, sc);
USART_INIT(sc, 115200U);
#ifdef NOTYET
if (sc->sc_iot == usart_cn_sc.sc_iot
&& sc->sc_hwbase == usart_cn_sc.sc_hwbase) {
usart_cn_sc.sc_attached = 1;
/* Make sure the console is always "hardwired". */
delay(10000); /* wait for output to finish */
SET(sc->sc_hwflags, COM_HW_CONSOLE);
SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
SET(sc->sc_ier, USART_INT_RXRDY);
USARTREG(USART_IER) = USART_INT_RXRDY; // @@@@@
}
#endif // NOTYET
tp = ttymalloc();
tp->t_oproc = at91usart_start;
tp->t_param = at91usart_param;
tp->t_hwiflow = at91usart_hwiflow;
sc->sc_tty = tp;
tty_attach(tp);
#if NOTYET
if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
int maj;
/* locate the major number */
maj = cdevsw_lookup_major(&at91usart_cdevsw);
cn_tab->cn_dev = makedev(maj, device_unit(sc->sc_dev));
aprint_normal("%s: console (maj %u min %u cn_dev %u)\n",
device_xname(sc->sc_dev), maj, device_unit(sc->sc_dev),
cn_tab->cn_dev);
}
#endif /* NOTYET */
sc->sc_si = softint_establish(SOFTINT_SERIAL, at91usart_soft, sc);
#if NRND > 0 && defined(RND_COM)
rnd_attach_source(&sc->rnd_source, device_xname(sc->sc_dev),
RND_TYPE_TTY, 0);
#endif
/* if there are no enable/disable functions, assume the device
is always enabled */
if (!sc->enable)
sc->enabled = 1;
/* XXX configure register */
/* xxx_config(sc) */
SET(sc->sc_hwflags, COM_HW_DEV_OK);
}
示例3: at91usart_open
int
at91usart_open(dev_t dev, int flag, int mode, struct lwp *l)
{
struct at91usart_softc *sc;
struct tty *tp;
int s;
int error;
sc = device_lookup_private(&at91usart_cd, COMUNIT(dev));
if (sc == NULL || !ISSET(sc->sc_hwflags, COM_HW_DEV_OK))
return (ENXIO);
if (!device_is_active(sc->sc_dev))
return (ENXIO);
#ifdef KGDB
/*
* If this is the kgdb port, no other use is permitted.
*/
if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
return (EBUSY);
#endif
tp = sc->sc_tty;
if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
return (EBUSY);
s = spltty();
/*
* Do the following iff this is a first open.
*/
if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
struct termios t;
tp->t_dev = dev;
if (sc->enable) {
if ((*sc->enable)(sc)) {
splx(s);
printf("%s: device enable failed\n",
device_xname(sc->sc_dev));
return (EIO);
}
sc->enabled = 1;
#if 0
/* XXXXXXXXXXXXXXX */
com_config(sc);
#endif
}
/* reset fifos: */
AT91PDC_RESET_FIFO(sc->sc_iot, sc->sc_ioh, sc->sc_dmat, US_PDC, &sc->sc_rx_fifo, 0);
AT91PDC_RESET_FIFO(sc->sc_iot, sc->sc_ioh, sc->sc_dmat, US_PDC, &sc->sc_tx_fifo, 1);
/* reset receive */
at91usart_writereg(sc, US_CR, US_CR_RSTSTA | US_CR_STTTO);
/* Turn on interrupts. */
sc->sc_ier = US_CSR_ENDRX|US_CSR_RXBUFF|US_CSR_TIMEOUT|US_CSR_RXBRK;
at91usart_writereg(sc, US_IER, sc->sc_ier);
/* enable DMA: */
at91usart_writereg(sc, US_PDC + PDC_PTCR, PDC_PTCR_RXTEN);
/*
* Initialize the termios status to the defaults. Add in the
* sticky bits from TIOCSFLAGS.
*/
t.c_ispeed = 0;
/* if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
t.c_ospeed = usart_cn_sc.sc_ospeed;
t.c_cflag = usart_cn_sc.sc_cflag;
} else*/ {
t.c_ospeed = TTYDEF_SPEED;
t.c_cflag = TTYDEF_CFLAG;
}
if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
SET(t.c_cflag, CLOCAL);
if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
SET(t.c_cflag, CRTSCTS);
if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
SET(t.c_cflag, MDMBUF);
/* Make sure at91usart_param() will do something. */
tp->t_ospeed = 0;
(void) at91usart_param(tp, &t);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_lflag = TTYDEF_LFLAG;
ttychars(tp);
ttsetwater(tp);
/* and unblock. */
CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
#ifdef COM_DEBUG
if (at91usart_debug)
comstatus(sc, "at91usart_open ");
//.........这里部分代码省略.........
示例4: nget_9p
__private_extern__ int
nget_9p(mount_9p *nmp, fid_9p fid, qid_9p qid, vnode_t dvp, vnode_t *vpp, struct componentname *cnp, vfs_context_t ctx)
{
#pragma unused(ctx)
struct vnode_fsparam fsp;
struct hnode_9p *nhp;
node_9p *np;
uint32_t vid;
int e, i;
TRACE();
nhp = HASH9P(nmp, qid.path);
loop:
lck_mtx_lock(nmp->nodelck);
LIST_FOREACH (np, nhp, next) {
if(np->dir.qid.path != qid.path)
continue;
if (ISSET(np->flags, NODE_INIT)) {
SET(np->flags, NODE_WAITINIT);
msleep(np, nmp->nodelck, PINOD|PDROP, "nget_9p_init", NULL);
goto loop;
}
if (ISSET(np->flags, NODE_RECL)) {
SET(np->flags, NODE_WAITRECL);
msleep(np, nmp->nodelck, PINOD|PDROP, "nget_9p_reclaim", NULL);
goto loop;
}
vid = vnode_vid(np->vp);
lck_mtx_unlock(nmp->nodelck);
if (vnode_getwithvid(np->vp, vid))
goto loop;
nlock_9p(np, NODE_LCK_EXCLUSIVE);
if (dvp && cnp && ISSET(cnp->cn_flags, MAKEENTRY) && np->dir.qid.vers!=0) {
// DEBUG("caching %s", np->dir->name);
cache_enter(dvp, np->vp, cnp);
} else {
// DEBUG("not in cache qid=%d %s", qid.vers, np->dir->name);
}
*vpp = np->vp;
return 0;
}
if (fid == NOFID)
return EFAULT;
np = malloc_9p(sizeof(*np));
if (np == NULL) {
err0:
lck_mtx_unlock(nmp->nodelck);
return ENOMEM;
}
np->lck = lck_rw_alloc_init(lck_grp_9p, LCK_ATTR_NULL);
if (np->lck == NULL) {
free_9p(np);
goto err0;
}
np->nmp = nmp;
np->fid = fid;
np->dir.qid = qid;
for (i=0; i<3; i++)
np->openfid[i].fid = NOFID;
SET(np->flags, NODE_INIT);
LIST_INSERT_HEAD(nhp, np, next);
nlock_9p(np, NODE_LCK_EXCLUSIVE);
lck_mtx_unlock(nmp->nodelck);
if ((e=ngetdir_9p(np))) {
err1:
nunlock_9p(np);
lck_mtx_lock(nmp->nodelck);
LIST_REMOVE(np, next);
CLR(np->flags, NODE_INIT);
if (ISSET(np->flags, NODE_WAITINIT)) {
CLR(np->flags, NODE_WAITINIT);
wakeup(np);
}
lck_mtx_unlock(nmp->nodelck);
lck_rw_free(np->lck, lck_grp_9p);
free_9p(np);
return e;
}
fsp.vnfs_mp = nmp->mp;
fsp.vnfs_str = fsname;
fsp.vnfs_dvp = dvp;
fsp.vnfs_fsnode = np;
fsp.vnfs_vops = vnode_op_9p;
fsp.vnfs_markroot = dvp==NULL? TRUE: FALSE;
fsp.vnfs_marksystem = FALSE;
fsp.vnfs_filesize = np->dir.length;
fsp.vnfs_cnp = cnp;
fsp.vnfs_flags = VNFS_ADDFSREF;
dirvtype_9p(&np->dir, ISSET(nmp->flags, F_DOTU), &fsp.vnfs_vtype, &fsp.vnfs_rdev);
if (!dvp || !cnp || !ISSET(cnp->cn_flags, MAKEENTRY) || qid.vers==0)
SET(fsp.vnfs_flags, VNFS_NOCACHE);
//.........这里部分代码省略.........
示例5: glGetUniformLocation
void AssimpShader::render(const glm::mat4& mv_matrix,
const glm::mat4& mv_it_matrix, const glm::mat4& mvp_matrix,
RenderData* render_data, Material* material) {
Mesh* mesh = render_data->mesh();
Texture* texture;
int feature_set = material->get_shader_feature_set();
/* Get the texture only diffuse texture is set */
if (ISSET(feature_set, AS_DIFFUSE_TEXTURE)) {
texture = material->getTexture("main_texture");
if (texture->getTarget() != GL_TEXTURE_2D) {
std::string error =
"TextureShader::render : texture with wrong target.";
throw error;
}
}
/* Based on feature set get the shader program, feature set cannot exceed program count */
program_ = program_list_[feature_set & (AS_TOTAL_GL_PROGRAM_COUNT - 1)];
u_mvp_ = glGetUniformLocation(program_->id(), "u_mvp");
u_texture_ = glGetUniformLocation(program_->id(), "u_texture");
u_diffuse_color_ = glGetUniformLocation(program_->id(), "u_diffuse_color");
u_ambient_color_ = glGetUniformLocation(program_->id(), "u_ambient_color");
u_color_ = glGetUniformLocation(program_->id(), "u_color");
u_opacity_ = glGetUniformLocation(program_->id(), "u_opacity");
/* Get common attributes and uniforms from material */
glm::vec3 color = material->getVec3("color");
float opacity = material->getFloat("opacity");
#if _GVRF_USE_GLES3_
mesh->generateVAO();
glUseProgram(program_->id());
glUniformMatrix4fv(u_mvp_, 1, GL_FALSE, glm::value_ptr(mvp_matrix));
if (ISSET(feature_set, AS_DIFFUSE_TEXTURE)) {
glActiveTexture (GL_TEXTURE0);
glBindTexture(texture->getTarget(), texture->getId());
glUniform1i(u_texture_, 0);
} else {
glm::vec4 diffuse_color = material->getVec4("diffuse_color");
glm::vec4 ambient_color = material->getVec4("ambient_color");
glUniform4f(u_diffuse_color_, diffuse_color.r, diffuse_color.g,
diffuse_color.b, diffuse_color.a);
glUniform4f(u_ambient_color_, ambient_color.r, ambient_color.g,
ambient_color.b, ambient_color.a);
}
/* Set up bones if AS_SKINNING is set */
if (ISSET(feature_set, AS_SKINNING)) {
a_bone_indices_ = glGetAttribLocation(program_->id(), "a_bone_indices");
a_bone_weights_ = glGetAttribLocation(program_->id(), "a_bone_weights");
u_bone_matrices_ = glGetUniformLocation(program_->id(), "u_bone_matrix[0]");
if (u_bone_matrices_ == -1) {
LOGD("Warning! Unable to get the location of uniform u_bone_matrix[0]\n");
}
mesh->setBoneLoc(a_bone_indices_, a_bone_weights_);
mesh->generateBoneArrayBuffers();
glm::mat4 finalTransform;
int nBones = MIN(mesh->getVertexBoneData().getNumBones(), MAX_BONES);
for (int i = 0; i < nBones; ++i) {
finalTransform = mesh->getVertexBoneData().getFinalBoneTransform(i);
glUniformMatrix4fv(u_bone_matrices_ + i, 1, GL_FALSE, glm::value_ptr(finalTransform));
}
}
glUniform3f(u_color_, color.r, color.g, color.b);
glUniform1f(u_opacity_, opacity);
glBindVertexArray(mesh->getVAOId(Material::ASSIMP_SHADER));
glDrawElements(render_data->draw_mode(), mesh->indices().size(), GL_UNSIGNED_SHORT,
0);
glBindVertexArray(0);
#else
glUseProgram(program_->id());
glVertexAttribPointer(a_position_, 3, GL_FLOAT, GL_FALSE, 0,
mesh->vertices().data());
glEnableVertexAttribArray(a_position_);
glVertexAttribPointer(a_tex_coord_, 2, GL_FLOAT, GL_FALSE, 0,
mesh->tex_coords().data());
glEnableVertexAttribArray(a_tex_coord_);
glUniformMatrix4fv(u_mvp_, 1, GL_FALSE, glm::value_ptr(mvp_matrix));
if (ISSET(feature_set, AS_DIFFUSE_TEXTURE)) {
glActiveTexture (GL_TEXTURE0);
glBindTexture(texture->getTarget(), texture->getId());
glUniform1i(u_texture_, 0);
} else {
glm::vec4 diffuse_color = material->getVec4("diffuse_color");
glm::vec4 ambient_color = material->getVec4("ambient_color");
glUniform4f(u_diffuse_color_, diffuse_color.x, diffuse_color.y, diffuse_color.z, diffuse_color.w);
glUniform4f(u_ambient_color_, ambient_color.x, ambient_color.y, ambient_color.z, ambient_color.w);
}
//.........这里部分代码省略.........
示例6: vnop_readdir_9p
static int
vnop_readdir_9p(struct vnop_readdir_args *ap)
{
struct direntry de64;
struct dirent de32;
vnode_t vp;
node_9p *np;
dir_9p *dp;
fid_9p fid;
off_t off;
uio_t uio;
uint32_t i, nd, nlen, plen;
void *p;
int e;
TRACE();
vp = ap->a_vp;
uio = ap->a_uio;
np = NTO9P(vp);
if (!vnode_isdir(vp))
return ENOTDIR;
if (ISSET(ap->a_flags, VNODE_READDIR_REQSEEKOFF))
return EINVAL;
off = uio_offset(uio);
if (off < 0)
return EINVAL;
if (uio_resid(uio) == 0)
return 0;
e = 0;
nlock_9p(np, NODE_LCK_EXCLUSIVE);
fid = np->openfid[OREAD].fid;
if (fid == NOFID) {
e = EBADF;
goto error;
}
if (ap->a_eofflag)
ap->a_eofflag = 0;
if (off == 0 || np->direntries==NULL) {
if((e=readdirs_9p(np->nmp, fid, &np->direntries, &np->ndirentries)))
goto error;
if (np->ndirentries && np->direntries==NULL)
panic("bug in readdir");
}
dp = np->direntries;
nd = np->ndirentries;
for (i=off; i<nd; i++) {
if (ISSET(ap->a_flags, VNODE_READDIR_EXTENDED)) {
bzero(&de64, sizeof(de64));
de64.d_ino = QTOI(dp[i].qid);
de64.d_type = dp[i].mode&DMDIR? DT_DIR: DT_REG;
nlen = strlen(dp[i].name);
de64.d_namlen = MIN(nlen, sizeof(de64.d_name)-1);
bcopy(dp[i].name, de64.d_name, de64.d_namlen);
de64.d_reclen = DIRENT64_LEN(de64.d_namlen);
plen = de64.d_reclen;
p = &de64;
} else {
bzero(&de32, sizeof(de32));
de32.d_ino = QTOI(dp[i].qid);
de32.d_type = dp[i].mode&DMDIR? DT_DIR: DT_REG;
nlen = strlen(dp[i].name);
de32.d_namlen = MIN(nlen, sizeof(de32.d_name)-1);
bcopy(dp[i].name, de32.d_name, de32.d_namlen);
de32.d_reclen = DIRENT32_LEN(de32.d_namlen);
plen = de32.d_reclen;
p = &de32;
}
if (uio_resid(uio) < plen)
break;
if ((e=uiomove(p, plen, uio)))
goto error;
}
uio_setoffset(uio, i);
if (ap->a_numdirent)
*ap->a_numdirent = i - off;
if (i==nd && ap->a_eofflag) {
*ap->a_eofflag = 1;
free_9p(np->direntries);
np->direntries = NULL;
np->ndirentries = 0;
}
error:
nunlock_9p(np);
return e;
}
示例7: vnop_open_9p
static int
vnop_open_9p(struct vnop_open_args *ap)
{
openfid_9p *op;
node_9p *np;
fid_9p fid;
qid_9p qid;
uint32_t iounit;
int e, flags, mode;
TRACE();
flags = 0;
if (ap->a_mode)
flags = OFLAGS(ap->a_mode);
mode = flags & O_ACCMODE;
CLR(flags, O_ACCMODE);
CLR(flags, O_DIRECTORY|O_NONBLOCK|O_NOFOLLOW);
CLR(flags, O_APPEND);
/* locks implemented on the vfs layer */
CLR(flags, O_EXLOCK|O_SHLOCK);
if (ISSET(flags, O_TRUNC)) {
SET(mode, OTRUNC);
CLR(flags, O_TRUNC);
}
if (ISSET(flags, O_CLOEXEC)) {
SET(mode, OCEXEC);
CLR(flags, O_CLOEXEC);
}
if (ISSET(flags, O_EXCL)) {
SET(mode, OEXCL);
CLR(flags, O_EXCL);
}
/* vnop_creat just called */
CLR(flags, O_CREAT);
if (ISSET(flags, O_EVTONLY))
CLR(flags, O_EVTONLY);
if (ISSET(flags, FNOCACHE))
CLR(flags, FNOCACHE);
if (ISSET(flags, FNORDAHEAD))
CLR(flags, FNORDAHEAD);
if (flags) {
DEBUG("unexpected open mode %x", flags);
return ENOTSUP;
}
np = NTO9P(ap->a_vp);
nlock_9p(np, NODE_LCK_EXCLUSIVE);
op = ofidget(np, ap->a_mode);
if (op->fid == NOFID) {
if ((e=walk_9p(np->nmp, np->fid, NULL, 0, &fid, &qid)))
goto error;
if ((e=open_9p(np->nmp, fid, mode, &qid, &iounit)))
goto error;
np->iounit = iounit;
op->fid = fid;
}
/* no cache for dirs, .u or synthetic files */
if (!vnode_isreg(np->vp) || np->dir.qid.vers==0) {
vnode_setnocache(np->vp);
vnode_setnoreadahead(np->vp);
}
OSIncrementAtomic(&op->ref);
nunlock_9p(np);
return 0;
error:
clunk_9p(np->nmp, fid);
nunlock_9p(np);
return e;
}
示例8: ucomopen
int
ucomopen(dev_t dev, int flag, int mode, struct lwp *l)
{
int unit = UCOMUNIT(dev);
usbd_status err;
struct ucom_softc *sc = device_lookup_private(&ucom_cd, unit);
struct ucom_buffer *ub;
struct tty *tp;
int s, i;
int error;
if (sc == NULL)
return (ENXIO);
if (sc->sc_dying)
return (EIO);
if (!device_is_active(sc->sc_dev))
return (ENXIO);
tp = sc->sc_tty;
DPRINTF(("ucomopen: unit=%d, tp=%p\n", unit, tp));
if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
return (EBUSY);
s = spltty();
/*
* Do the following iff this is a first open.
*/
while (sc->sc_opening)
tsleep(&sc->sc_opening, PRIBIO, "ucomop", 0);
if (sc->sc_dying) {
splx(s);
return (EIO);
}
sc->sc_opening = 1;
if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
struct termios t;
tp->t_dev = dev;
if (sc->sc_methods->ucom_open != NULL) {
error = sc->sc_methods->ucom_open(sc->sc_parent,
sc->sc_portno);
if (error) {
ucom_cleanup(sc);
sc->sc_opening = 0;
wakeup(&sc->sc_opening);
splx(s);
return (error);
}
}
ucom_status_change(sc);
/* Clear PPS capture state on first open. */
mutex_spin_enter(&timecounter_lock);
memset(&sc->sc_pps_state, 0, sizeof(sc->sc_pps_state));
sc->sc_pps_state.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
pps_init(&sc->sc_pps_state);
mutex_spin_exit(&timecounter_lock);
/*
* Initialize the termios status to the defaults. Add in the
* sticky bits from TIOCSFLAGS.
*/
t.c_ispeed = 0;
t.c_ospeed = TTYDEF_SPEED;
t.c_cflag = TTYDEF_CFLAG;
if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
SET(t.c_cflag, CLOCAL);
if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
SET(t.c_cflag, CRTSCTS);
if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
SET(t.c_cflag, MDMBUF);
/* Make sure ucomparam() will do something. */
tp->t_ospeed = 0;
(void) ucomparam(tp, &t);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_lflag = TTYDEF_LFLAG;
ttychars(tp);
ttsetwater(tp);
/*
* Turn on DTR. We must always do this, even if carrier is not
* present, because otherwise we'd have to use TIOCSDTR
* immediately after setting CLOCAL, which applications do not
* expect. We always assert DTR while the device is open
* unless explicitly requested to deassert it. Ditto RTS.
*/
ucom_dtr(sc, 1);
ucom_rts(sc, 1);
DPRINTF(("ucomopen: open pipes in=%d out=%d\n",
//.........这里部分代码省略.........
示例9: ucomparam
static int
ucomparam(struct tty *tp, struct termios *t)
{
struct ucom_softc *sc = device_lookup_private(&ucom_cd,
UCOMUNIT(tp->t_dev));
int error;
if (sc == NULL || sc->sc_dying)
return (EIO);
/* Check requested parameters. */
if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
return (EINVAL);
/*
* For the console, always force CLOCAL and !HUPCL, so that the port
* is always active.
*/
if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR)) {
SET(t->c_cflag, CLOCAL);
CLR(t->c_cflag, HUPCL);
}
/*
* If there were no changes, don't do anything. This avoids dropping
* input and improves performance when all we did was frob things like
* VMIN and VTIME.
*/
if (tp->t_ospeed == t->c_ospeed &&
tp->t_cflag == t->c_cflag)
return (0);
/* XXX lcr = ISSET(sc->sc_lcr, LCR_SBREAK) | cflag2lcr(t->c_cflag); */
/* And copy to tty. */
tp->t_ispeed = 0;
tp->t_ospeed = t->c_ospeed;
tp->t_cflag = t->c_cflag;
if (sc->sc_methods->ucom_param != NULL) {
error = sc->sc_methods->ucom_param(sc->sc_parent, sc->sc_portno,
t);
if (error)
return (error);
}
/* XXX worry about CHWFLOW */
/*
* Update the tty layer's idea of the carrier bit, in case we changed
* CLOCAL or MDMBUF. We don't hang up here; we only do that by
* explicit request.
*/
DPRINTF(("ucomparam: l_modem\n"));
(void) (*tp->t_linesw->l_modem)(tp, ISSET(sc->sc_msr, UMSR_DCD));
#if 0
XXX what if the hardware is not open
if (!ISSET(t->c_cflag, CHWFLOW)) {
if (sc->sc_tx_stopped) {
sc->sc_tx_stopped = 0;
ucomstart(tp);
}
}
#endif
return (0);
}
示例10: fts_build
/*
* This is the tricky part -- do not casually change *anything* in here. The
* idea is to build the linked list of entries that are used by yfts_children
* and yfts_read. There are lots of special cases.
*
* The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is
* set and it's a physical walk (so that symbolic links can't be directories),
* we can do things quickly. First, if it's a 4.4BSD file system, the type
* of the file is in the directory entry. Otherwise, we assume that the number
* of subdirectories in a node is equal to the number of links to the parent.
* The former skips all stat calls. The latter skips stat calls in any leaf
* directories and for any files after the subdirectories in the directory have
* been found, cutting the stat calls by about 2/3.
*/
static FTSENT *
fts_build(FTS * sp, int type)
{
struct dirent *dp;
FTSENT *p, *head;
int nitems;
FTSENT *cur, *tail;
#ifdef _win_
dird dirpd;
struct DIR *dirp;
#else
DIR *dirp;
#endif
void *oldaddr;
int cderrno, descend, len, level, maxlen, nlinks, saved_errno,
nostat, doadjust;
char *cp;
/* Set current node pointer. */
cur = sp->fts_cur;
/*
* Open the directory for reading. If this fails, we're done.
* If being called from yfts_read, set the fts_info field.
*/
#ifdef FTS_WHITEOUT
if (ISSET(FTS_WHITEOUT))
oflag = DTF_NODUP|DTF_REWIND;
else
oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
#else
#define __opendir2(path, flag) opendir(path)
#endif
if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
if (type == BREAD) {
cur->fts_info = FTS_DNR;
cur->fts_errno = errno;
}
return (NULL);
}
#ifdef _win_
dirpd = get_dird(cur->fts_accpath);
#endif
/*
* Nlinks is the number of possible entries of type directory in the
* directory if we're cheating on stat calls, 0 if we're not doing
* any stat calls at all, -1 if we're doing stats on everything.
*/
if (type == BNAMES) {
nlinks = 0;
/* Be quiet about nostat, GCC. */
nostat = 0;
} else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
nostat = 1;
} else {
nlinks = -1;
nostat = 0;
}
#ifdef notdef
(void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);
(void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
#endif
/*
* If we're going to need to stat anything or we want to descend
* and stay in the directory, chdir. If this fails we keep going,
* but set a flag so we don't chdir after the post-order visit.
* We won't be able to stat anything, but we can still return the
* names themselves. Note, that since yfts_read won't be able to
* chdir into the directory, it will have to return different path
* names than before, i.e. "a/b" instead of "b". Since the node
* has already been visited in pre-order, have to wait until the
* post-order visit to return the error. There is a special case
* here, if there was nothing to stat then it's not an error to
* not be able to stat. This is all fairly nasty. If a program
* needed sorted entries or stat information, they had better be
* checking FTS_NS on the returned nodes.
*/
cderrno = 0;
if (nlinks || type == BREAD) {
//.........这里部分代码省略.........
示例11: file_open_shaper
int file_open_shaper(struct shaper *my, char *fname, char *flags)
{
char line[1024], group[256]="(unnamed)";
float sum=0, load=0, peak=0;
float scale[12][31][7][24];
char ff[1024];
/* clear everything */
memset(scale,0,sizeof(scale));
linenum=0;
file=fname;
/* "-" means stdin */
my->fp = (strcmp(fname,"-")==0?stdin:(gl_findfile(fname,NULL,R_OK,ff,sizeof(ff))?fopen(ff,flags):NULL));
if (my->fp==NULL)
{
gl_error("shaper file %s: %s", fname, strerror(errno));
my->status = TS_DONE;
return 0;
}
my->status=TS_OPEN;
my->type = FT_FILE;
/* TODO: these should be read from the shape file, or better yet, inferred from it */
my->step = 3600; /* default interval step is one hour */
my->interval = 24; /* default unint shape integrated over one day */
memset(my->shape,0,sizeof(my->shape));
/* load the file into the shape */
while (fgets(line,sizeof(line),my->fp)!=NULL)
{
unsigned char *hours, *days, *months, *weekdays;
char min[256],hour[256],day[256],month[256],weekday[256],value[32];
char *p=line;
linenum++;
while (isspace(*p)) p++;
if (p[0]=='\0' || p[0]=='#') continue;
if (strcmp(group,"")!=0 && (isdigit(p[0]) || p[0]=='*'))
{ /* shape value */
int h, d, m, w;
if (sscanf(line,"%s %s %s %s %[^,],%[^,\n]",min,hour,day,month,weekday,value)<6)
{
gl_error("%s(%d) : shape '%s' has specification '%s'", file, linenum, group, line);
continue;
}
/* minutes are ignored right now */
if (min[0]!='*') gl_warning("%s(%d) : minutes are ignored in '%s'", file, linenum, line);
hours=hourmap(hour);
days=daymap(day);
months=monthmap(month);
weekdays=weekdaymap(weekday);
load = (float)atof(value);
for (m=0; m<12; m++)
{
if (!ISSET(months,m)) continue;
for (w=0; w<7; w++)
{
if (!ISSET(weekdays,w)) continue;
for (d=0; d<31; d++)
{
if (!ISSET(days,d)) continue;
for (h=0; h<24; h++)
{
if (!ISSET(hours,h)) continue;
scale[m][d][w][h] = -load; /* negative indicates unscaled value */
}
}
}
}
sum += load; /* integrate over shape */
if (load>peak) peak=load; /* keep the highest load in the shape (that's going to be 255) */
}
else if (p[0]=='}')
{ /* end shape group */
int h, d, m, w;
my->scale = peak/255/sum;
/* rescale group */
for (m=0; m<12; m++)
{
for (w=0; w<7; w++)
{
for (d=0; d<31; d++)
{
for (h=0; h<24; h++)
{
if (scale[m][d][w][h]<0)
my->shape[m][d][w][h] = (unsigned char)(-scale[m][d][w][h] / peak * 255 +0.5); /* negative removes scaled value indicator */
}
}
}
}
strcpy(group,"");
}
else if (sscanf(p,"%s {",group)==1)
{ /* new shape group */
sum=0;
}
else
{ /* syntax error */
gl_error("%s(%d) : shape specification '%s' is not valid", file, linenum, line);
}
}
//.........这里部分代码省略.........
示例12: yfts_children
FTSENT *
yfts_children(FTS * sp, int instr)
{
FTSENT *p;
dird fd;
if (instr && instr != FTS_NAMEONLY) {
errno = EINVAL;
return (NULL);
}
/* Set current node pointer. */
p = sp->fts_cur;
/*
* Errno set to 0 so user can distinguish empty directory from
* an error.
*/
errno = 0;
/* Fatal errors stop here. */
if (ISSET(FTS_STOP))
return (NULL);
/* Return logical hierarchy of user's arguments. */
if (p->fts_info == FTS_INIT)
return (p->fts_link);
/*
* If not a directory being visited in pre-order, stop here. Could
* allow FTS_DNR, assuming the user has fixed the problem, but the
* same effect is available with FTS_AGAIN.
*/
if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)
return (NULL);
/* Free up any previous child list. */
if (sp->fts_child)
fts_lfree(sp->fts_child);
if (instr == FTS_NAMEONLY) {
SET(FTS_NAMEONLY);
instr = BNAMES;
} else
instr = BCHILD;
/*
* If using chdir on a relative path and called BEFORE yfts_read does
* its chdir to the root of a traversal, we can lose -- we need to
* chdir into the subdirectory, and we don't know where the current
* directory is, so we can't get back so that the upcoming chdir by
* yfts_read will work.
*/
if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == LOCSLASH_C ||
ISSET(FTS_NOCHDIR))
return (sp->fts_child = fts_build(sp, instr));
if (valid_dird(fd = get_cwdd()))
return (NULL);
sp->fts_child = fts_build(sp, instr);
if (chdir_dird(fd)) {
close_dird(fd);
return (NULL);
}
close_dird(fd);
return (sp->fts_child);
}
示例13: yfts_read
FTSENT *
yfts_read(FTS * sp) {
FTSENT *p, *tmp;
int instr;
char *t;
int saved_errno;
ClearLastSystemError();
/* If finished or unrecoverable error, return NULL. */
if (sp->fts_cur == NULL || ISSET(FTS_STOP))
return (NULL);
/* Set current node pointer. */
p = sp->fts_cur;
/* Save and zero out user instructions. */
instr = p->fts_instr;
p->fts_instr = FTS_NOINSTR;
/* Any type of file may be re-visited; re-stat and re-turn. */
if (instr == FTS_AGAIN) {
p->fts_info = fts_stat(sp, p, 0);
return (p);
}
/*
* Following a symlink -- SLNONE test allows application to see
* SLNONE and recover. If indirecting through a symlink, have
* keep a pointer to current location. If unable to get that
* pointer, follow fails.
*/
if (instr == FTS_FOLLOW &&
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
p->fts_info = fts_stat(sp, p, 1);
if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
if (valid_dird(p->fts_symfd = get_cwdd())) {
p->fts_errno = errno;
p->fts_info = FTS_ERR;
} else
p->fts_flags |= FTS_SYMFOLLOW;
}
return (p);
}
/* Directory in pre-order. */
if (p->fts_info == FTS_D) {
/* If skipped or crossed mount point, do post-order visit. */
if (instr == FTS_SKIP ||
(ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
if (p->fts_flags & FTS_SYMFOLLOW)
close_dird(p->fts_symfd);
if (sp->fts_child) {
fts_lfree(sp->fts_child);
sp->fts_child = NULL;
}
p->fts_info = FTS_DP;
return (p);
}
/* Rebuild if only read the names and now traversing. */
if (sp->fts_child && ISSET(FTS_NAMEONLY)) {
CLR(FTS_NAMEONLY);
fts_lfree(sp->fts_child);
sp->fts_child = NULL;
}
/*
* Cd to the subdirectory.
*
* If have already read and now fail to chdir, whack the list
* to make the names come out right, and set the parent errno
* so the application will eventually get an error condition.
* Set the FTS_DONTCHDIR flag so that when we logically change
* directories back to the parent we don't do a chdir.
*
* If haven't read do so. If the read fails, fts_build sets
* FTS_STOP or the fts_info field of the node.
*/
if (sp->fts_child) {
if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
p->fts_errno = errno;
p->fts_flags |= FTS_DONTCHDIR;
for (p = sp->fts_child; p; p = p->fts_link)
p->fts_accpath =
p->fts_parent->fts_accpath;
}
} else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
if (ISSET(FTS_STOP))
return (NULL);
return (p);
}
p = sp->fts_child;
sp->fts_child = NULL;
goto name;
}
/* Move to the next node on this level. */
next:
tmp = p;
//.........这里部分代码省略.........
示例14: yfts_open
FTS *
yfts_open(char * const * argv, int options, int (*compar) (const FTSENT **, const FTSENT **))
{
FTS *sp;
FTSENT *p, *root;
int nitems;
FTSENT *parent, *tmp;
int len;
errno = 0;
/* Options check. */
if (options & ~FTS_OPTIONMASK) {
errno = EINVAL;
return (NULL);
}
/* Allocate/initialize the stream */
if ((sp = (FTS*)malloc(sizeof(FTS))) == NULL)
return (NULL);
memset(sp, 0, sizeof(FTS));
sp->fts_compar = compar;
sp->fts_options = options;
/* Shush, GCC. */
tmp = NULL;
/* Logical walks turn on NOCHDIR; symbolic links are too hard. */
if (ISSET(FTS_LOGICAL))
SET(FTS_NOCHDIR);
/*
* Start out with 1K of path space, and enough, in any case,
* to hold the user's paths.
*/
if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
goto mem1;
/* Allocate/initialize root's parent. */
if ((parent = fts_alloc(sp, "", 0)) == NULL)
goto mem2;
parent->fts_level = FTS_ROOTPARENTLEVEL;
/* Allocate/initialize root(s). */
for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) {
/* Don't allow zero-length paths. */
len = strlen(*argv);
//Any subsequent windows call will expect no trailing slashes so we will remove them here
#ifdef _win_
while (len && ((*argv)[len-1] == '\\' || (*argv)[len-1] == '/')) {
--len;
}
#endif
if (len == 0) {
errno = ENOENT;
goto mem3;
}
p = fts_alloc(sp, *argv, len);
p->fts_level = FTS_ROOTLEVEL;
p->fts_parent = parent;
p->fts_accpath = p->fts_name;
p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
/* Command-line "." and ".." are real directories. */
if (p->fts_info == FTS_DOT)
p->fts_info = FTS_D;
/*
* If comparison routine supplied, traverse in sorted
* order; otherwise traverse in the order specified.
*/
if (compar) {
p->fts_link = root;
root = p;
} else {
p->fts_link = NULL;
if (root == NULL)
tmp = root = p;
else {
tmp->fts_link = p;
tmp = p;
}
}
}
if (compar && nitems > 1)
root = fts_sort(sp, root, nitems);
/*
* Allocate a dummy pointer and make yfts_read think that we've just
* finished the node before the root(s); set p->fts_info to FTS_INIT
* so that everything about the "current" node is ignored.
*/
if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
goto mem3;
sp->fts_cur->fts_level = FTS_ROOTLEVEL;
sp->fts_cur->fts_link = root;
//.........这里部分代码省略.........
示例15: getnewbuf
/*
* Find a buffer which is available for use.
*
* We must notify getblk if we slept during the buffer allocation. When
* that happens, we allocate a buffer anyway (unless tsleep is interrupted
* or times out) and return !0.
*/
int
getnewbuf(int slpflag, int slptimeo, struct buf **bpp)
{
struct buf *bp;
int s, ret, error;
*bpp = NULL;
ret = 0;
start:
s = splbio();
/*
* Wake up cleaner if we're getting low on buffers.
*/
if (numdirtypages >= hidirtypages)
wakeup(&bd_req);
if ((numcleanpages <= locleanpages) &&
curproc != syncerproc && curproc != cleanerproc) {
needbuffer++;
error = tsleep(&needbuffer, slpflag|(PRIBIO+1), "getnewbuf",
slptimeo);
splx(s);
if (error)
return (1);
ret = 1;
goto start;
}
if ((bp = TAILQ_FIRST(&bufqueues[BQ_CLEAN])) == NULL) {
/* wait for a free buffer of any kind */
nobuffers = 1;
error = tsleep(&nobuffers, slpflag|(PRIBIO-3),
"getnewbuf", slptimeo);
splx(s);
if (error)
return (1);
ret = 1;
goto start;
}
bremfree(bp);
/* Buffer is no longer on free lists. */
SET(bp->b_flags, B_BUSY);
#ifdef DIAGNOSTIC
if (ISSET(bp->b_flags, B_DELWRI))
panic("Dirty buffer on BQ_CLEAN");
#endif
/* disassociate us from our vnode, if we had one... */
if (bp->b_vp)
brelvp(bp);
splx(s);
#ifdef DIAGNOSTIC
/* CLEAN buffers must have no dependencies */
if (LIST_FIRST(&bp->b_dep) != NULL)
panic("BQ_CLEAN has buffer with dependencies");
#endif
/* clear out various other fields */
bp->b_flags = B_BUSY;
bp->b_dev = NODEV;
bp->b_blkno = bp->b_lblkno = 0;
bp->b_iodone = 0;
bp->b_error = 0;
bp->b_resid = 0;
bp->b_bcount = 0;
bp->b_dirtyoff = bp->b_dirtyend = 0;
bp->b_validoff = bp->b_validend = 0;
bremhash(bp);
*bpp = bp;
return (ret);
}