Exemplo n.º 1
0
static int
_do_madrpc(int port_id, void *sndbuf, void *rcvbuf, int agentid, int len,
	   int timeout)
{
	uint32_t trid; /* only low 32 bits */
	int retries;
	int length, status;

	if (!timeout)
		timeout = def_madrpc_timeout;

	if (ibdebug > 1) {
		IBWARN(">>> sending: len %d pktsz %zu", len, umad_size() + len);
		xdump(stderr, "send buf\n", sndbuf, umad_size() + len);
	}

	if (save_mad) {
		memcpy(save_mad, umad_get_mad(sndbuf),
		       save_mad_len < len ? save_mad_len : len);
		save_mad = 0;
	}

	trid = mad_get_field64(umad_get_mad(sndbuf), 0, IB_MAD_TRID_F);

	for (retries = 0; retries < madrpc_retries; retries++) {
		if (retries) {
			ERRS("retry %d (timeout %d ms)", retries, timeout);
		}

		length = len;
		if (umad_send(port_id, agentid, sndbuf, length, timeout, 0) < 0) {
			IBWARN("send failed; %s", strerror(errno));
			return -1;
		}

		/* Use same timeout on receive side just in case */
		/* send packet is lost somewhere. */
		do {
			if (umad_recv(port_id, rcvbuf, &length, timeout) < 0) {
				IBWARN("recv failed: %s", strerror(errno));
				return -1;
			}

			if (ibdebug > 1) {
				IBWARN("rcv buf:");
				xdump(stderr, "rcv buf\n", umad_get_mad(rcvbuf), IB_MAD_SIZE);
			}
		} while ((uint32_t)mad_get_field64(umad_get_mad(rcvbuf), 0, IB_MAD_TRID_F) != trid);

		status = umad_status(rcvbuf);
		if (!status)
			return length;		/* done */
		if (status == ENOMEM)
			return length;
	}

	ERRS("timeout after %d retries, %d ms", retries, timeout * retries);
	return -1;
}
Exemplo n.º 2
0
	char* GetStr(){
		if(mystr==NULL){
			ERRS("tried to retrieve a string when string is not initialized, not even \"\" (NULL)");
			ERRS("we created a \"\" and returned to you just so this won't crash");
			mystr=(char*)malloc(1*sizeof(char));
			mystr[0]='\0';
		}
		return mystr;
	}
Exemplo n.º 3
0
void Error(char *param) 
{
    switch (errno) {
        case ENOTEMPTY:
            ERRS("Directory not empty");
            break;
        case ENOSPC:
            ERRS("disk full");
            break;          
        case EEXIST:
            ERRS("File exists");
            break;
        case ENAMETOOLONG:
            ERRS("path is too long");
            break;
        case ENOENT:
            ERRS("No such file or directory");
            break;
        case ENOTDIR:
            ERRS("Not a directory");
            break;
        case EISDIR:
            ERRS("Is a directory");
        default:
            ERRS("Permission denied");
    };
}
Exemplo n.º 4
0
void Cwd(char *param)
{
    char tmp[PATH_MAX];
    
    if (param[0] == '/') 
		MakePath(tmp, "", param); 
	else 
		MakePath(tmp, path, param);
    if (chdir(tmp) == -1) {
        Error(param);
    } else {
        if (getcwd(tmp, PATH_MAX) == NULL) 
			ERRS("Permission denied");
        else {
            if (anonymous_login) {
                if (strncmp(basedir, tmp, strlen(basedir)) != 0) {
                    chdir(basedir);
                    strcpy(path, "/");
                } else {
                    strncpy(path, &tmp[strlen(basedir)], PATH_MAX);
                    strcat(path, "/");
                };
            } else strcpy(path, tmp);
            outs("250 CWD command successful.");
        };
    };
};
Exemplo n.º 5
0
void *
mad_rpc_rmpp(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport,
	     ib_rmpp_hdr_t *rmpp, void *data)
{
	const struct ibmad_port *p = port_id;
	int status, len;
	uint8_t sndbuf[1024], rcvbuf[1024], *mad;

	memset(sndbuf, 0, umad_size() + IB_MAD_SIZE);

	DEBUG("rmpp %p data %p", rmpp, data);

	if ((len = mad_build_pkt(sndbuf, rpc, dport, rmpp, data)) < 0)
		return 0;

	if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf,
			      p->class_agents[rpc->mgtclass],
			      len, rpc->timeout)) < 0) {
		IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
		return 0;
	}

	mad = umad_get_mad(rcvbuf);

	if ((status = mad_get_field(mad, 0, IB_MAD_STATUS_F)) != 0) {
		ERRS("MAD completed with error status 0x%x; dport (%s)",
			status, portid2str(dport));
		return 0;
	}

	if (ibdebug) {
		IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz);
		xdump(stderr, "rmpp mad data\n", mad + rpc->dataoffs,
		      rpc->datasz);
	}

	if (rmpp) {
		rmpp->flags = mad_get_field(mad, 0, IB_SA_RMPP_FLAGS_F);
		if ((rmpp->flags & 0x3) &&
		    mad_get_field(mad, 0, IB_SA_RMPP_VERS_F) != 1) {
			IBWARN("bad rmpp version");
			return 0;
		}
		rmpp->type = mad_get_field(mad, 0, IB_SA_RMPP_TYPE_F);
		rmpp->status = mad_get_field(mad, 0, IB_SA_RMPP_STATUS_F);
		DEBUG("rmpp type %d status %d", rmpp->type, rmpp->status);
		rmpp->d1.u = mad_get_field(mad, 0, IB_SA_RMPP_D1_F);
		rmpp->d2.u = mad_get_field(mad, 0, IB_SA_RMPP_D2_F);
	}

	if (data)
		memcpy(data, mad + rpc->dataoffs, rpc->datasz);

	rpc->recsz = mad_get_field(mad, 0, IB_SA_ATTROFFS_F);

	return data;
}
Exemplo n.º 6
0
	void Set(int propindex, cell_t value)
	{
		if(propindex>=OBJ_ELEMENTSIZE){
			ERRS("element prop index out of bounds: %d / max %d",propindex,OBJ_ELEMENTSIZE);
		}
		else{
			cells[propindex]=value;
		}
	}
Exemplo n.º 7
0
	cell_t Get(int propindex)
	{
		if(propindex>=OBJ_ELEMENTSIZE){
			ERRS("element prop index out of bounds: %d / max %d",propindex,OBJ_ELEMENTSIZE);
			return 0;
		}
		else{
			return cells[propindex];
		}
	}
Exemplo n.º 8
0
void *
mad_rpc(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport, void *payload,
	void *rcvdata)
{
	const struct ibmad_port *p = port_id;
	int status, len;
	uint8_t sndbuf[1024], rcvbuf[1024], *mad;

	len = 0;
	memset(sndbuf, 0, umad_size() + IB_MAD_SIZE);

	if ((len = mad_build_pkt(sndbuf, rpc, dport, 0, payload)) < 0)
		return 0;

	if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf,
			      p->class_agents[rpc->mgtclass],
			      len, rpc->timeout)) < 0) {
		IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
		return 0;
	}

	mad = umad_get_mad(rcvbuf);

	if ((status = mad_get_field(mad, 0, IB_DRSMP_STATUS_F)) != 0) {
		ERRS("MAD completed with error status 0x%x; dport (%s)",
			status, portid2str(dport));
		return 0;
	}

	if (ibdebug) {
		IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz);
		xdump(stderr, "mad data\n", mad + rpc->dataoffs, rpc->datasz);
	}

	if (rcvdata)
		memcpy(rcvdata, mad + rpc->dataoffs, rpc->datasz);

	return rcvdata;
}
Exemplo n.º 9
0
	ElementStruct* GetElement(int elementindex){
		if(elementindex>=Size()||elementindex<0)
		{
			//if(isSTATIC){
				ERRS("index out of bounds! tried to access %d, size of %d",elementindex,Size());
				return NULL;
			//}
			/*else{ //dynamically add
				for( int i=size;i<  elementindex  ;i++){
					ElementStruct* element=new ElementStruct();
					for(int j=0;j<OBJ_ELEMENTSIZE;j++){ //initialize all to zero
						element->Set(j,0);
					}
					mynewobj->push_back(element);
				}
				//if(elementindex>200){
				//	ERRS("WARNING, AUTO GREW object to over 200");
				//}
			}*/
		}
		
		return mynewobj->at(elementindex);
		
	}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
    int res = EXIT_FAILURE;
    int buflen;
    int err;
    struct stat st;
    char *buf;
    struct planex_hdr *hdr;
    sha1_context ctx;
    uint32_t t = HOST_TO_BE32(2);

    FILE *outfile, *infile;

    progname = basename(argv[0]);

    while ( 1 ) {
        int c;

        c = getopt(argc, argv, "i:o:v:h");
        if (c == -1)
            break;

        switch (c) {
        case 'i':
            ifname = optarg;
            break;
        case 'o':
            ofname = optarg;
            break;
        case 'v':
            version = optarg;
            break;
        case 'h':
            usage(EXIT_SUCCESS);
            break;
        default:
            usage(EXIT_FAILURE);
            break;
        }
    }

    if (ifname == NULL) {
        ERR("no input file specified");
        goto err;
    }

    if (ofname == NULL) {
        ERR("no output file specified");
        goto err;
    }

    err = stat(ifname, &st);
    if (err) {
        ERRS("stat failed on %s", ifname);
        goto err;
    }

    buflen = (st.st_size + 3) & ~3;
    buflen += sizeof(*hdr);

    buf = malloc(buflen);
    if (!buf) {
        ERR("no memory for buffer\n");
        goto err;
    }

    memset(buf, 0xff, buflen);
    hdr = (struct planex_hdr *)buf;

    hdr->datalen = HOST_TO_BE32(buflen - sizeof(*hdr));
    hdr->unk1[0] = 0x04;
    hdr->unk1[1] = 0x08;

    snprintf(hdr->version, sizeof(hdr->version), "%s", version);

    infile = fopen(ifname, "r");
    if (infile == NULL) {
        ERRS("could not open \"%s\" for reading", ifname);
        goto err_free;
    }

    errno = 0;
    fread(buf +  sizeof(*hdr), st.st_size, 1, infile);
    if (errno != 0) {
        ERRS("unable to read from file %s", ifname);
        goto err_close_in;
    }

    sha1_starts(&ctx);
    sha1_update(&ctx, (uchar *) &t, sizeof(t));
    sha1_update(&ctx, buf + sizeof(*hdr), buflen - sizeof(*hdr));
    sha1_finish(&ctx, hdr->sha1sum);

    outfile = fopen(ofname, "w");
    if (outfile == NULL) {
        ERRS("could not open \"%s\" for writing", ofname);
        goto err_close_in;
    }

    errno = 0;
    fwrite(buf, buflen, 1, outfile);
    if (errno) {
        ERRS("unable to write to file %s", ofname);
        goto err_close_out;
    }

    res = EXIT_SUCCESS;

out_flush:
    fflush(outfile);

err_close_out:
    fclose(outfile);
    if (res != EXIT_SUCCESS) {
        unlink(ofname);
    }

err_close_in:
    fclose(infile);

err_free:
    free(buf);

err:
    return res;
}
Exemplo n.º 11
0
static int pad_image(char *name, uint32_t pad_mask)
{
	char *buf;
	int fd;
	ssize_t in_len;
	ssize_t out_len;
	int ret = -1;

	buf = malloc(BUF_SIZE);
	if (!buf) {
		ERR("No memory for buffer");
		goto out;
	}

	fd = open(name, O_RDWR);
	if (fd < 0) {
		ERRS("Unable to open %s", name);
		goto free_buf;
	}

	in_len = lseek(fd, 0, SEEK_END);
	if (in_len < 0)
		goto close;

	memset(buf, '\xff', BUF_SIZE);

	out_len = in_len;
	while (pad_mask) {
		uint32_t mask;
		ssize_t t;
		int i;

		for (i = 10; i < 32; i++) {
			mask = 1UL << i;
			if (pad_mask & mask)
				break;
		}

		in_len = ALIGN(in_len, mask);

		for (i = 10; i < 32; i++) {
			mask = 1UL << i;
			if ((in_len & (mask - 1)) == 0)
				pad_mask &= ~mask;
		}

		printf("padding image to %08x\n", (unsigned int) in_len);

		while (out_len < in_len) {
			ssize_t len;

			len = in_len - out_len;
			if (len > BUF_SIZE)
				len = BUF_SIZE;

			t = write(fd, buf, len);
			if (t != len) {
				ERRS("Unable to write to %s", name);
				goto close;
			}

			out_len += len;
		}

		/* write out the JFFS end-of-filesystem marker */
		t = write(fd, eof_mark, 4);
		if (t != 4) {
			ERRS("Unable to write to %s", name);
			goto close;
		}
		out_len += 4;
	}

	ret = 0;

close:
	close(fd);
free_buf:
	free(buf);
out:
	return ret;
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
	int res = EXIT_FAILURE;
	int buflen;
	int err;
	struct stat st;
	char *buf;
	int pos, rem, i;
	uint8_t csum;

	FILE *outfile, *infile;

	progname = basename(argv[0]);

	while ( 1 ) {
		int c;

		c = getopt(argc, argv, "B:i:o:v:r:H:h");
		if (c == -1)
			break;

		switch (c) {
		case 'B':
			board_id = optarg;
			break;
		case 'i':
			ifname = optarg;
			break;
		case 'o':
			ofname = optarg;
			break;
		case 'v':
			version = optarg;
			break;
		case 'r':
			region = optarg;
			break;
		case 'H':
			hd_id = optarg;
			break;
		case 'h':
			usage(EXIT_SUCCESS);
			break;
		default:
			usage(EXIT_FAILURE);
			break;
		}
	}

	if (board_id == NULL) {
		ERR("no board specified");
		goto err;
	}

	if (ifname == NULL) {
		ERR("no input file specified");
		goto err;
	}

	if (ofname == NULL) {
		ERR("no output file specified");
		goto err;
	}

	err = stat(ifname, &st);
	if (err){
		ERRS("stat failed on %s", ifname);
		goto err;
	}

	buflen = st.st_size + DNI_HDR_LEN + 1;
	buf = malloc(buflen);
	if (!buf) {
		ERR("no memory for buffer\n");
		goto err;
	}

	memset(buf, 0, DNI_HDR_LEN);
	pos = snprintf(buf, DNI_HDR_LEN, "device:%s\nversion:V%s\nregion:%s\n",
		       board_id, version, region);
	rem = DNI_HDR_LEN - pos;
	if (pos >= 0 && rem > 1 && hd_id) {
		snprintf(buf + pos, rem, "hd_id:%s\n", hd_id);
	}

	infile = fopen(ifname, "r");
	if (infile == NULL) {
		ERRS("could not open \"%s\" for reading", ifname);
		goto err_free;
	}

	errno = 0;
	fread(buf +  DNI_HDR_LEN, st.st_size, 1, infile);
	if (errno != 0) {
		ERRS("unable to read from file %s", ifname);
		goto err_close_in;
	}

	csum = 0;
	for (i = 0; i < (st.st_size + DNI_HDR_LEN); i++)
		csum += buf[i];

	csum = 0xff - csum;
	buf[st.st_size + DNI_HDR_LEN] = csum;

	outfile = fopen(ofname, "w");
	if (outfile == NULL) {
		ERRS("could not open \"%s\" for writing", ofname);
		goto err_close_in;
	}

	errno = 0;
	fwrite(buf, buflen, 1, outfile);
	if (errno) {
		ERRS("unable to write to file %s", ofname);
		goto err_close_out;
	}

	res = EXIT_SUCCESS;

 out_flush:
	fflush(outfile);

 err_close_out:
	fclose(outfile);
	if (res != EXIT_SUCCESS) {
		unlink(ofname);
	}

 err_close_in:
	fclose(infile);

 err_free:
	free(buf);

 err:
	return res;
}