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; }
/** * Function: ixp_srv_writectl * * This utility function is meant to simplify the writing of * pseudo files to which single-lined commands are written. * In order to use this function, the P<aux> member of * P<req>->fid must be nul or an S<IxpFileId>. Each line of the * written data is stripped of its trailing newline, * nul-terminated, and stored in an S<IxpMsg>. For each line * thus prepared, P<fn> is called with the IxpMsg pointer and * the the P<p> member of the IxpFileId. */ char* ixp_srv_writectl(Ixp9Req *req, char* (*fn)(void*, IxpMsg*)) { char *err, *s, *p, c; IxpFileId *file; IxpMsg msg; file = req->fid->aux; ixp_srv_data2cstring(req); s = req->ifcall.io.data; err = nil; c = *s; while(c != '\0') { while(*s == '\n') s++; p = s; while(*p != '\0' && *p != '\n') p++; c = *p; *p = '\0'; msg = ixp_message(s, p-s, 0); s = fn(file->p, &msg); if(s) err = s; s = p + 1; } return err; }
/* * Metadata Management */ void unpfs_stat(Ixp9Req *r) { int ret = 0; struct stat stbuf; struct unpfs_fid *fid = r->fid->aux; int size; IxpMsg m; struct IxpStat s; char *buf, *name = strdup(fid->path); unpfs_log(LOG_NOTICE, "%s: fid=%u real_path=%s\n", __func__, r->fid->fid, fid->real_path); if (!name || lstat(fid->real_path, &stbuf) < 0) { ret = errno; goto out; } stat_posix_to_9p(&s, basename(name), &stbuf); /* Pack the stat to the binary */ size = ixp_sizeof_stat(&s); buf = ixp_emallocz(size); m = ixp_message(buf, size, MsgPack); ixp_pstat(&m, &s); zfree(&name); r->fid->qid = s.qid; r->ofcall.rstat.nstat = size; r->ofcall.rstat.stat = (uint8_t *)m.data; out: respond(r, ret); }
void ixp_srv_readdir(Ixp9Req *req, IxpLookupFn lookup, void (*dostat)(IxpStat*, IxpFileId*)) { IxpMsg msg; IxpFileId *file, *tfile; IxpStat stat; char *buf; ulong size, n; uint64_t offset; file = req->fid->aux; size = req->ifcall.io.count; if(size > req->fid->iounit) size = req->fid->iounit; buf = emallocz(size); msg = ixp_message(buf, size, MsgPack); file = lookup(file, nil); tfile = file; /* Note: The first file is ".", so we skip it. */ offset = 0; for(file=file->next; file; file=file->next) { dostat(&stat, file); n = ixp_sizeof_stat(&stat); if(offset >= req->ifcall.io.offset) { if(size < n) break; ixp_pstat(&msg, &stat); size -= n; } offset += n; } while((file = tfile)) { tfile=tfile->next; ixp_srv_freefile(file); } req->ofcall.io.count = msg.pos - msg.data; req->ofcall.io.data = msg.data; ixp_respond(req, nil); }
static int xls(int argc, char *argv[]) { IxpMsg m; Stat *stat; IxpCFid *fid; char *file, *buf; int lflag, dflag, count, nstat, mstat, i; lflag = dflag = 0; ARGBEGIN{ case 'l': lflag++; break; case 'd': dflag++; break; default: usage(); }ARGEND; file = EARGF(usage()); stat = ixp_stat(client, file); if(stat == nil) fatal("cannot stat file '%s': %s\n", file, ixp_errbuf()); if(dflag || (stat->mode&P9_DMDIR) == 0) { print_stat(stat, lflag); ixp_freestat(stat); return 0; } ixp_freestat(stat); fid = ixp_open(client, file, P9_OREAD); if(fid == nil) fatal("Can't open file '%s': %s\n", file, ixp_errbuf()); nstat = 0; mstat = 16; stat = emalloc(sizeof(*stat) * mstat); 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 = ixp_erealloc(stat, sizeof(*stat) * mstat); } ixp_pstat(&m, &stat[nstat++]); } } qsort(stat, nstat, sizeof(*stat), comp_stat); for(i = 0; i < nstat; i++) { print_stat(&stat[i], lflag); ixp_freestat(&stat[i]); } free(stat); if(count == -1) fatal("cannot read directory '%s': %s\n", file, ixp_errbuf()); return 0; }
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; }
int main(int argc, char *argv[]) { IxpMsg m; char **oargv; char *wmiirc, *s; int i; quotefmtinstall(); fmtinstall('r', errfmt); fmtinstall('a', afmt); fmtinstall('C', Cfmt); extern int fmtevent(Fmt*); fmtinstall('E', fmtevent); wmiirc = "wmiirc"; oargv = argv; ARGBEGIN{ case 'a': address = EARGF(usage()); break; case 'r': wmiirc = EARGF(usage()); break; case 'v': print("%s", version); exit(0); case 'D': s = EARGF(usage()); m = ixp_message(s, strlen(s), 0); msg_debug(&m); break; default: usage(); break; }ARGEND; if(argc) usage(); setlocale(LC_CTYPE, ""); starting = true; initdisplay(); traperrors(true); selectinput(&scr.root, EnterWindowMask | SubstructureRedirectMask); if(traperrors(false)) fatal("another window manager is already running"); passwd = getpwuid(getuid()); user = estrdup(passwd->pw_name); init_environment(); fmtinstall('F', Ffmt); ixp_printfcall = printfcall; sock = ixp_announce(address); if(sock < 0) fatal("Can't create socket '%s': %r", address); closeexec(ConnectionNumber(display)); closeexec(sock); if(wmiirc[0]) spawn_command(wmiirc); init_traps(); init_cursors(); init_lock_keys(); ewmh_init(); xext_init(); srv.preselect = check_preselect; ixp_listen(&srv, sock, &p9srv, serve_9pcon, nil); ixp_listen(&srv, ConnectionNumber(display), nil, check_x_event, closedisplay); def.border = 1; def.colmode = Colstack; def.font = loadfont(FONT); def.incmode = ISqueeze; def.mod = Mod1Mask; strcpy(def.grabmod, "Mod1"); loadcolor(&def.focuscolor, FOCUSCOLORS); loadcolor(&def.normcolor, NORMCOLORS); disp.sel = pointerscreen(); init_screens(); root_init(); disp.focus = nil; setfocus(screen->barwin, RevertToParent); view_select("1"); scan_wins(); starting = false; view_update_all(); ewmh_updateviews(); event("FocusTag %s\n", selview->name); i = ixp_serverloop(&srv); if(i) fprint(2, "%s: error: %r\n", argv0); else event("Quit"); cleanup(); if(exitsignal) raise(exitsignal); if(execstr) { char *toks[32]; int n; n = unquote(strdup(execstr), toks, nelem(toks)-1); toks[n] = nil; execvp(toks[0], toks); fprint(2, "%s: failed to exec %q: %r\n", argv0, execstr); execvp(argv0, oargv); fatal("failed to exec myself"); } return i; }