Example #1
0
static PyObject *
Wmii_ls(Wmii *self, PyObject *args)
{
    const char *file;
    char *buf;
    PyArg_ParseTuple(args, "s", &file);
    int count;
    PyObject *list;

    IxpCFid *fid;
    IxpStat stat;
    IxpMsg msg;

    fid = ixp_open(self->client, file, P9_OREAD);
    buf = malloc(fid->iounit);

    list = PyList_New(0);

    while( (count = ixp_read(fid, buf, fid->iounit)) > 0 )
    {

        msg = ixp_message(buf, count, MsgUnpack);
        while(msg.pos < msg.end)
        {
            ixp_pstat(&msg, &stat);
            PyList_Append(list, PyString_FromString(stat.name));
        }
    }

    ixp_close(fid);
    free(buf);
    return list;
}
Example #2
0
static PyObject *
Wmii_write(Wmii *self, PyObject *args)
{
    const char *file;
    const char *data;

    IxpCFid *fid;

    if (!PyArg_ParseTuple(args, "ss", &file,  &data)) {
        PyErr_SetString(PyExc_TypeError, "Wmii.write() takes exactly 2 arguments");
        return NULL;
    }

    fid = ixp_open(self->client, file, P9_OWRITE);
    if(fid == NULL)
    {
        PyErr_SetObject(PyExc_IOError, PyString_FromFormat("Can't open file '%s'\n", file));
        return NULL;
    }

    ixp_write(fid, data, strlen(data));

    ixp_close(fid);

    Py_RETURN_NONE;
}
Example #3
0
File: wmiir.c Project: bartman/wmii
static int
xread(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file, *buf;
	int count;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	if(argc == 0)
		usage();
	file = EARGF(usage());
	do {
		fid = ixp_open(client, file, P9_OREAD);
		if(fid == nil)
			fatal("Can't open file '%s': %r\n", file);

		buf = emalloc(fid->iounit);
		while((count = ixp_read(fid, buf, fid->iounit)) > 0)
			write(1, buf, count);
		ixp_close(fid);

		if(count == -1)
			fprint(2, "%s: cannot read file '%s': %r\n", argv0, file);
	} while((file = ARGF()));

	return 0;
}
Example #4
0
static PyObject *
Wmii_create(Wmii *self, PyObject *args)
{
    IxpCFid *fid;
    const char *file;
    const char *data;

    if (!PyArg_ParseTuple(args, "s|s", &file, &data)) {
        PyErr_SetString(PyExc_TypeError, "Wmii.create() requires 1 argument");
        return NULL;
    }

    fid = ixp_create(self->client, file, 0777, P9_OWRITE);
    if(fid == NULL)
    {
        PyErr_SetObject(PyExc_IOError, PyString_FromFormat("Can't create file '%s'\n", file));
    }

    if((fid->qid.type&P9_DMDIR) == 0)
    {
        if(strlen(data)) {
            ixp_write(fid, data, strlen(data));
        }
    }
    ixp_close(fid);
    Py_RETURN_NONE;
}
Example #5
0
File: wmiir.c Project: bartman/wmii
static int
xawrite(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file, *buf;
	int nbuf, i;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	file = EARGF(usage());
	fid = ixp_open(client, file, P9_OWRITE);
	if(fid == nil)
		fatal("Can't open file '%s': %r\n", file);

	nbuf = 1;
	for(i=0; i < argc; i++)
		nbuf += strlen(argv[i]) + (i > 0);
	buf = emalloc(nbuf);
	buf[0] = '\0';
	while(argc) {
		strcat(buf, ARGF());
		if(argc)
			strcat(buf, " ");
	}

	if(ixp_write(fid, buf, nbuf) == -1)
		fatal("cannot write file '%s': %r\n", file);
	ixp_close(fid);
	free(buf);
	return 0;
}
Example #6
0
char*
readctl(char *key) {
	char *s, *p;
	int nkey, n;

	if(ctlfid == nil) {
		ctlfid = ixp_open(client, "ctl", OREAD);
		n = ixp_read(ctlfid, ctl, 1023);
		ectl = ctl + n;
		ixp_close(ctlfid);
	}

	nkey = strlen(key);
	p = ctl - 1;
	do {
		p++;
		if(!strncmp(p, key, nkey)) {
			p += nkey;
			s = strchr(p, '\n');
			n = (s ? s : ectl) - p;
			s = freelater(emalloc(n + 1));
			s[n] = '\0';
			return strncpy(s, p, n);
		}
	} while((p = strchr(p, '\n')));
	return "";
}
Example #7
0
static PyObject *
Wmii_read(Wmii *self, PyObject *args)
{
    const char *file;

    char *readbuf;
    unsigned int count = 1;

    char *buf;
    unsigned int len;
    unsigned int size;

    PyObject *outstr;

    IxpCFid *fid;

    PyArg_ParseTuple(args, "s", &file);

    fid = ixp_open(self->client, file, P9_OREAD);

    readbuf = malloc(fid->iounit);

    len = 1;
    size = fid->iounit;
    buf = malloc(size);
    buf[0] = '\0';

    while( (count = ixp_read(fid, readbuf, fid->iounit)) > 0 )
    {
        while( (len+count) > size )
        {
            size <<= 1;
            buf = realloc(buf, size);
        }
        strcpy(&buf[len-1], readbuf);
        len += count;
    }

    ixp_close(fid);
    outstr = PyString_FromString(buf);

    free(buf);
    free(readbuf);

    return outstr;

}
Example #8
0
File: wmiir.c Project: bartman/wmii
/* Service Functions */
static int
xwrite(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	file = EARGF(usage());
	fid = ixp_open(client, file, P9_OWRITE);
	if(fid == nil)
		fatal("Can't open file '%s': %r\n", file);

	write_data(fid, file);
	ixp_close(fid);
	return 0;
}
Example #9
0
File: wmiir.c Project: bartman/wmii
static int
xcreate(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	file = EARGF(usage());
	fid = ixp_create(client, file, 0777, P9_OWRITE);
	if(fid == nil)
		fatal("Can't create file '%s': %r\n", file);

	if((fid->qid.type&P9_DMDIR) == 0)
		write_data(fid, file);
	ixp_close(fid);
	return 0;
}
Example #10
0
File: wmiir.c Project: bartman/wmii
static int
xls(int argc, char *argv[]) {
	IxpMsg m;
	Stat *stat;
	IxpCFid *fid;
	char *file;
	char *buf;
	int lflag, dflag, pflag;
	int count, nstat, mstat, i;

	lflag = dflag = pflag = 0;

	ARGBEGIN{
	case 'l':
		lflag++;
		break;
	case 'd':
		dflag++;
		break;
	case 'p':
		pflag++;
		break;
	default:
		usage();
	}ARGEND;

	count = 0;
	file = EARGF(usage());
	do {
		stat = ixp_stat(client, file);
		if(stat == nil)
			fatal("cannot stat file '%s': %r\n", file);

		i = strlen(file);
		if(file[i-1] == '/') {
			file[i-1] = '\0';
			if(!(stat->mode&P9_DMDIR))
				fatal("%s: not a directory", file);
		}
		if(dflag || (stat->mode&P9_DMDIR) == 0) {
			print_stat(stat, lflag, file, pflag);
			ixp_freestat(stat);
			continue;
		}
		ixp_freestat(stat);

		fid = ixp_open(client, file, P9_OREAD);
		if(fid == nil)
			fatal("Can't open file '%s': %r\n", file);

		nstat = 0;
		mstat = 16;
		stat = emalloc(mstat * sizeof *stat);
		buf = emalloc(fid->iounit);
		while((count = ixp_read(fid, buf, fid->iounit)) > 0) {
			m = ixp_message(buf, count, MsgUnpack);
			while(m.pos < m.end) {
				if(nstat == mstat) {
					mstat <<= 1;
					stat = erealloc(stat, mstat * sizeof *stat);
				}
				ixp_pstat(&m, &stat[nstat++]);
			}
		}
		ixp_close(fid);

		qsort(stat, nstat, sizeof *stat, comp_stat);
		for(i = 0; i < nstat; i++) {
			print_stat(&stat[i], lflag, file, pflag);
			ixp_freestat(&stat[i]);
		}
		free(stat);
	} while((file = ARGF()));

	if(count == -1)
		fatal("cannot read directory '%s': %r\n", file);
	return 0;
}