Exemplo n.º 1
0
int
ncp_conn_frag_rq(struct ncp_conn *conn, struct proc *p, struct ncp_conn_frag *nfp){
	int error = 0, i, rpsize;
	u_int32_t fsize;
	NW_FRAGMENT *fp;
	DECLARE_RQ;

	ncp_rq_head(rqp,NCP_REQUEST,nfp->fn,p,p->p_ucred);
	if (nfp->rqfcnt) {
		for(fp = nfp->rqf, i = 0; i < nfp->rqfcnt; i++, fp++) {
			checkbad(ncp_rq_usermem(rqp,(caddr_t)fp->fragAddress, fp->fragSize));
		}
	}
	checkbad(ncp_request(conn, rqp));
	rpsize = rqp->rpsize;
	if (rpsize && nfp->rpfcnt) {
		for(fp = nfp->rpf, i = 0; i < nfp->rpfcnt; i++, fp++) {
			checkbad(copyin(&fp->fragSize, &fsize, sizeof (fsize)));
			fsize = min(fsize, rpsize);
			checkbad(ncp_rp_usermem(rqp,(caddr_t)fp->fragAddress, fsize));
			rpsize -= fsize;
			checkbad(copyout(&fsize, &fp->fragSize, sizeof (fsize)));
		}
	}
	nfp->cs = rqp->cs;
	nfp->cc = rqp->cc;
	NCP_RQ_EXIT;
	return error;
}
Exemplo n.º 2
0
static void *create_bbt(struct mtd_info *mtd)
{
	struct nand_chip *chip = mtd->priv;
	int len, i, numblocks, ret;
	loff_t from = 0;
	void *buf;
	uint8_t *bbt;

	if ((chip->bbt_td && chip->bbt_td->pages[0] != -1) ||
			(chip->bbt_md && chip->bbt_md->pages[0] != -1)) {
		printf("Flash bbt already present\n");
		return ERR_PTR(-EEXIST);
	}

	len = mtd->size >> (chip->bbt_erase_shift + 2);

	/* Allocate memory (2bit per block) and clear the memory bad block table */
	bbt = kzalloc(len, GFP_KERNEL);
	if (!bbt)
		return ERR_PTR(-ENOMEM);

	buf = malloc(mtd->writesize);
	if (!buf) {
		ret = -ENOMEM;
		goto out2;
	}

	numblocks = mtd->size >> (chip->bbt_erase_shift - 1);

	for (i = 0; i < numblocks;) {
		ret = checkbad(mtd, from, buf);
		if (ret < 0)
			goto out1;

		if (ret) {
			bbt[i >> 3] |= 0x03 << (i & 0x6);
			printf("Bad eraseblock %d at 0x%08x\n", i >> 1,
					(unsigned int)from);
		}

		i += 2;
		from += (1 << chip->bbt_erase_shift);
	}

	return bbt;

out1:
	free(buf);
out2:
	free(bbt);

	return ERR_PTR(ret);
}
Exemplo n.º 3
0
/* 
 * Connect to specified server via IP
 */
int
ncp_sock_connect_in(struct ncp_conn *conn) {
	struct sockaddr_in sin;
	struct thread *td = conn->td;
	int addrlen=sizeof(sin), error;

	conn->flags = 0;
	bzero(&sin,addrlen);
	conn->ncp_so = conn->wdg_so = NULL;
	checkbad(socreate(AF_INET, &conn->ncp_so, SOCK_DGRAM, IPPROTO_UDP, td));
	sin.sin_family = AF_INET;
	sin.sin_len = addrlen;
	checkbad(sobind(conn->ncp_so, (struct sockaddr *)&sin, td));
	checkbad(ncp_soconnect(conn->ncp_so,(struct sockaddr*)&conn->li.addr, td));
	if  (!error)
		conn->flags |= NCPFL_SOCONN;
	return error;
bad:
	ncp_sock_disconnect(conn);
	return (error);
}
Exemplo n.º 4
0
static int 
__P(sncp_connect(struct proc *p, struct sncp_connect_args *uap)){
	int connHandle = 0, error;
	struct ncp_conn *conn;
	struct ncp_handle *handle;
	struct ncp_conn_args li;

	checkbad(copyin(uap->li,&li,sizeof(li)));
	checkbad(copyout(&connHandle,uap->connHandle,sizeof(connHandle))); /* check before */
	li.password = li.user = NULL;
	error = ncp_conn_getattached(&li, p, p->p_ucred, NCPM_WRITE | NCPM_EXECUTE, &conn);
	if (error) {
		error = ncp_connect(&li, p, p->p_ucred, &conn);
	}
	if (!error) {
		error = ncp_conn_gethandle(conn, p, &handle);
		copyout(&handle->nh_id, uap->connHandle, sizeof(uap->connHandle));
		ncp_conn_unlock(conn,p);
	}
bad:
	p->p_retval[0]=error;
	return error;
}
Exemplo n.º 5
0
int
ncp_write(struct ncp_conn *conn, ncp_fh *file, struct uio *uiop, struct ucred *cred)
{
	int error = 0, len, tsiz, backup;
	DECLARE_RQ;

	if (uiop->uio_iovcnt != 1) {
		printf("%s: can't handle iovcnt>1 !!!\n", __FUNCTION__);
		return EIO;
	}
	tsiz = uiop->uio_resid;
	while (tsiz > 0) {
		len = min(4096 - (uiop->uio_offset % 4096), tsiz);
		len = min(len, conn->buffer_size);
		if (len == 0) {
			printf("gotcha!\n");
		}
		/* rq head */
		NCP_RQ_HEAD(73,uiop->uio_procp,cred);
		ncp_rq_byte(rqp, 0);
		ncp_rq_mem(rqp, (caddr_t)file, 6);
		ncp_rq_dword(rqp, htonl(uiop->uio_offset));
		ncp_rq_word_hl(rqp, len);
		nwfs_uiotombuf(uiop,&rqp->mrq,len,&rqp->bpos);
		checkbad(ncp_request(conn,rqp));
		if (len == 0)
			break;
		NCP_RQ_EXIT;
		if (error) {
			backup = len;
			uiop->uio_iov->iov_base -= backup;
			uiop->uio_iov->iov_len += backup;
			uiop->uio_offset -= backup;
			uiop->uio_resid += backup;
			break;
		}
		tsiz -= len;
	}
	if (error)
		uiop->uio_resid = tsiz;
	switch (error) {
	    case NWE_INSUFFICIENT_SPACE:
		error = ENOSPC;
		break;
	}
	return (error);
}
Exemplo n.º 6
0
int
ncp_read(struct ncp_conn *conn, ncp_fh *file, struct uio *uiop, struct ucred *cred) {
	int error = 0, len = 0, retlen=0, tsiz, burstio;
	DECLARE_RQ;

	tsiz = uiop->uio_resid;
#ifdef NCPBURST
	burstio = (ncp_burst_enabled && tsiz > conn->buffer_size);
#else
	burstio = 0;
#endif

	while (tsiz > 0) {
		if (!burstio) {
			len = min(4096 - (uiop->uio_offset % 4096), tsiz);
			len = min(len, conn->buffer_size);
			NCP_RQ_HEAD(72,uiop->uio_procp,cred);
			ncp_rq_byte(rqp, 0);
			ncp_rq_mem(rqp, (caddr_t)file, 6);
			ncp_rq_dword(rqp, htonl(uiop->uio_offset));
			ncp_rq_word(rqp, htons(len));
			checkbad(ncp_request(conn,rqp));
			retlen = ncp_rp_word_hl(rqp);
			if (uiop->uio_offset & 1)
				ncp_rp_byte(rqp);
			error = nwfs_mbuftouio(&rqp->mrp,uiop,retlen,&rqp->bpos);
			NCP_RQ_EXIT;
		} else {
#ifdef NCPBURST
			error = ncp_burst_read(conn, file, tsiz, &len, &retlen, uiop, cred);
#endif
		}
		if (error) break;
		tsiz -= retlen;
		if (retlen < len)
			break;
	}
	return (error);
}
Exemplo n.º 7
0
int
ncp_get_bindery_object_id(struct ncp_conn *conn, 
		u_int16_t object_type, char *object_name, 
		struct ncp_bindery_object *target,
		struct proc *p,struct ucred *cred)
{
	int error;
	DECLARE_RQ;

	NCP_RQ_HEAD_S(23,53,p,cred);
	ncp_rq_word_hl(rqp, object_type);
	ncp_rq_pstring(rqp, object_name);
	checkbad(ncp_request(conn,rqp));
	if (rqp->rpsize < 54) {
		printf("ncp_rp_size %d < 54\n", rqp->rpsize);
		error = EINVAL;
		goto bad;
	}
	target->object_id = ncp_rp_dword_hl(rqp);
	target->object_type = ncp_rp_word_hl(rqp);
	ncp_rp_mem(rqp,(caddr_t)target->object_name, 48);
	NCP_RQ_EXIT;
	return error;
}
Exemplo n.º 8
0
/*
 * Connect to specified server via IPX
 */
static int
ncp_sock_connect_ipx(struct ncp_conn *conn)
{
	struct sockaddr_ipx sipx;
	struct ipxpcb *npcb;
	struct thread *td = conn->td;
	int addrlen, error, count;

	sipx.sipx_port = htons(0);

	for (count = 0;;count++) {
		if (count > (IPXPORT_WELLKNOWN-IPXPORT_RESERVED)*2) {
			error = EADDRINUSE;
			goto bad;
		}
		conn->ncp_so = conn->wdg_so = NULL;
		checkbad(socreate(AF_IPX, &conn->ncp_so, SOCK_DGRAM, 0, td->td_ucred, td));
		if (conn->li.opt & NCP_OPT_WDOG)
			checkbad(socreate(AF_IPX, &conn->wdg_so, SOCK_DGRAM, 0, td->td_ucred, td));
		addrlen = sizeof(sipx);
		sipx.sipx_family = AF_IPX;
		ipx_setnullnet(sipx.sipx_addr);
		ipx_setnullhost(sipx.sipx_addr);
		sipx.sipx_len = addrlen;
		error = sobind(conn->ncp_so, (struct sockaddr *)&sipx, td);
		if (error == 0) {
			if ((conn->li.opt & NCP_OPT_WDOG) == 0)
				break;
			sipx.sipx_addr = sotoipxpcb(conn->ncp_so)->ipxp_laddr;
			sipx.sipx_port = htons(ntohs(sipx.sipx_port) + 1);
			ipx_setnullnet(sipx.sipx_addr);
			ipx_setnullhost(sipx.sipx_addr);
			error = sobind(conn->wdg_so, (struct sockaddr *)&sipx, td);
		}
		if (!error) break;
		if (error != EADDRINUSE) goto bad;
		sipx.sipx_port = htons((ntohs(sipx.sipx_port)+4) & 0xfff8);
		soclose(conn->ncp_so);
		if (conn->wdg_so)
			soclose(conn->wdg_so);
	}
	npcb = sotoipxpcb(conn->ncp_so);
	npcb->ipxp_dpt = IPXPROTO_NCP;
	/* IPXrouted must be running, i.e. route must be presented */
	conn->li.ipxaddr.sipx_len = sizeof(struct sockaddr_ipx);
	checkbad(ncp_soconnect(conn->ncp_so, &conn->li.saddr, td));
	if (conn->wdg_so) {
		sotoipxpcb(conn->wdg_so)->ipxp_laddr.x_net = npcb->ipxp_laddr.x_net;
		sotoipxpcb(conn->wdg_so)->ipxp_laddr.x_host= npcb->ipxp_laddr.x_host;
	}
	if (!error) {
		conn->flags |= NCPFL_SOCONN;
	}
#ifdef NCPBURST
	if (ncp_burst_enabled) {
		checkbad(socreate(AF_IPX, &conn->bc_so, SOCK_DGRAM, 0, td));
		bzero(&sipx, sizeof(sipx));
		sipx.sipx_len = sizeof(sipx);
		checkbad(sobind(conn->bc_so, (struct sockaddr *)&sipx, td));
		checkbad(ncp_soconnect(conn->bc_so, &conn->li.saddr, td));
	}
#endif
	if (!error) {
		conn->flags |= NCPFL_SOCONN;
		ncp_sock_checksum(conn, 0);
	}
	return error;
bad:
	ncp_sock_disconnect(conn);
	return (error);
}