mirror of https://github.com/0intro/wmii
removed grab from /ctl, instead use wmiir create
This commit is contained in:
parent
0db44d2642
commit
be8a984d73
29
cmd/wm/fs.c
29
cmd/wm/fs.c
|
@ -473,6 +473,28 @@ xwalk(IXPConn *c, Fcall *fcall)
|
|||
return nil;
|
||||
}
|
||||
|
||||
static char *
|
||||
xcreate(IXPConn *c, Fcall *fcall)
|
||||
{
|
||||
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
||||
|
||||
if(!(fcall->mode | IXP_OWRITE))
|
||||
return Enomode;
|
||||
if(!m)
|
||||
return Enofid;
|
||||
if(!strncmp(fcall->name, ".", 2) || !strncmp(fcall->name, "..", 3))
|
||||
return "illegal file name";
|
||||
if(qpath_type(m->qid.path) != Dkeys)
|
||||
return Enoperm;
|
||||
grab_key(create_key(fcall->name));
|
||||
mkqid(&m->qid, fcall->name, &m->qid, False);
|
||||
fcall->id = RCREATE;
|
||||
fcall->qid = m->qid;
|
||||
fcall->iounit = WMII_IOUNIT;
|
||||
ixp_server_respond_fcall(c, fcall);
|
||||
return nil;
|
||||
}
|
||||
|
||||
static char *
|
||||
xopen(IXPConn *c, Fcall *fcall)
|
||||
{
|
||||
|
@ -1042,10 +1064,6 @@ xwrite(IXPConn *c, Fcall *fcall)
|
|||
attach_detached_client();
|
||||
else if(!strncmp(buf, "select", 6))
|
||||
select_page(&buf[7]);
|
||||
else if(!strncmp(buf, "grab ", 5)) {
|
||||
if(strlen(&buf[5]))
|
||||
grab_key(create_key(&buf[5]));
|
||||
}
|
||||
else
|
||||
return Enocommand;
|
||||
break;
|
||||
|
@ -1211,6 +1229,8 @@ xwrite(IXPConn *c, Fcall *fcall)
|
|||
}
|
||||
update_bar_geometry();
|
||||
break;
|
||||
case Fkey:
|
||||
break;
|
||||
default:
|
||||
return "invalid write";
|
||||
break;
|
||||
|
@ -1247,6 +1267,7 @@ do_fcall(IXPConn *c)
|
|||
case TVERSION: errstr = xversion(c, &fcall); break;
|
||||
case TATTACH: errstr = xattach(c, &fcall); break;
|
||||
case TWALK: errstr = xwalk(c, &fcall); break;
|
||||
case TCREATE: errstr = xcreate(c, &fcall); break;
|
||||
case TOPEN: errstr = xopen(c, &fcall); break;
|
||||
case TREMOVE: errstr = xremove(c, &fcall); break;
|
||||
case TREAD: errstr = xread(c, &fcall); break;
|
||||
|
|
12
cmd/wmiir.c
12
cmd/wmiir.c
|
@ -55,9 +55,8 @@ xcreate(char *file)
|
|||
fprintf(stderr, "wmiir: cannot walk to '%s': %s\n", file, c.errstr);
|
||||
return -1;
|
||||
}
|
||||
/* create */
|
||||
p++;
|
||||
if(ixp_client_create(&c, fid, p, (unsigned int) 0xff, IXP_OWRITE) == -1) {
|
||||
if(ixp_client_create(&c, fid, p, DMWRITE, IXP_OWRITE) == -1) {
|
||||
fprintf(stderr, "wmiir: cannot create file '%s': %s\n", p, c.errstr);
|
||||
return -1;
|
||||
}
|
||||
|
@ -169,14 +168,12 @@ xread(char *file)
|
|||
size_t ndircontent = 0;
|
||||
unsigned long long offset = 0;
|
||||
|
||||
/* open */
|
||||
if(ixp_client_open(&c, fid, file, IXP_OREAD) == -1) {
|
||||
fprintf(stderr, "wmiir: cannot open file '%s': %s\n", file, c.errstr);
|
||||
return -1;
|
||||
}
|
||||
is_directory = !c.fcall.nwqid || (c.fcall.qid.type == IXP_QTDIR);
|
||||
|
||||
/* read */
|
||||
while((count = ixp_client_read(&c, fid, offset, result, IXP_MAX_MSG)) > 0) {
|
||||
if(is_directory) {
|
||||
if(ndircontent + count > dircontentsz) {
|
||||
|
@ -216,7 +213,6 @@ xremove(char *file)
|
|||
{
|
||||
unsigned int fid;
|
||||
|
||||
/* remove */
|
||||
fid = c.root_fid << 2;
|
||||
if(ixp_client_remove(&c, fid, file) == -1) {
|
||||
fprintf(stderr, "wmiir: cannot remove file '%s': %s\n", file, c.errstr);
|
||||
|
@ -259,8 +255,8 @@ main(int argc, char *argv[])
|
|||
fprintf(stderr, "%s", "wmiir: error: $WMII_ADDRESS not set\n");
|
||||
usage();
|
||||
}
|
||||
/* open socket */
|
||||
if(ixp_client_init(&c, address, getpid()) == -1) {
|
||||
|
||||
if(ixp_client_dial(&c, address, getpid()) == -1) {
|
||||
fprintf(stderr, "wmiir: %s\n", c.errstr);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -277,7 +273,7 @@ main(int argc, char *argv[])
|
|||
usage();
|
||||
|
||||
/* close socket */
|
||||
ixp_client_deinit(&c);
|
||||
ixp_client_hangup(&c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,31 +36,29 @@ ixp_client_do_fcall(IXPClient * c)
|
|||
}
|
||||
|
||||
int
|
||||
ixp_client_init(IXPClient *c, char *sockfile, unsigned int rootfid)
|
||||
ixp_client_dial(IXPClient *c, char *sockfile, unsigned int rootfid)
|
||||
{
|
||||
if((c->fd = ixp_connect_sock(sockfile)) < 0) {
|
||||
c->errstr = "cannot connect server";
|
||||
return -1;
|
||||
}
|
||||
/* version */
|
||||
c->fcall.id = TVERSION;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.maxmsg = IXP_MAX_MSG;
|
||||
cext_strlcpy(c->fcall.version, IXP_VERSION, sizeof(c->fcall.version));
|
||||
if(ixp_client_do_fcall(c) == -1) {
|
||||
fprintf(stderr, "error: %s\n", c->fcall.errstr);
|
||||
ixp_client_deinit(c);
|
||||
ixp_client_hangup(c);
|
||||
return -1;
|
||||
}
|
||||
if(strncmp(c->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) {
|
||||
fprintf(stderr, "error: %s\n", c->fcall.errstr);
|
||||
c->errstr = "9P versions differ";
|
||||
ixp_client_deinit(c);
|
||||
ixp_client_hangup(c);
|
||||
return -1; /* we cannot handle this version */
|
||||
}
|
||||
c->root_fid = rootfid;
|
||||
|
||||
/* attach */
|
||||
c->fcall.id = TATTACH;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = c->root_fid;
|
||||
|
@ -69,7 +67,7 @@ ixp_client_init(IXPClient *c, char *sockfile, unsigned int rootfid)
|
|||
c->fcall.aname[0] = 0;
|
||||
if(ixp_client_do_fcall(c) == -1) {
|
||||
fprintf(stderr, "error: %s\n", c->fcall.errstr);
|
||||
ixp_client_deinit(c);
|
||||
ixp_client_hangup(c);
|
||||
return -1;
|
||||
}
|
||||
c->root_qid = c->fcall.qid;
|
||||
|
@ -81,7 +79,6 @@ ixp_client_remove(IXPClient * c, unsigned int newfid, char *filepath)
|
|||
{
|
||||
if(ixp_client_walk(c, newfid, filepath) == -1)
|
||||
return -1;
|
||||
/* remove */
|
||||
c->fcall.id = TREMOVE;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = newfid;
|
||||
|
@ -92,7 +89,6 @@ int
|
|||
ixp_client_create(IXPClient * c, unsigned int dirfid, char *name,
|
||||
unsigned int perm, unsigned char mode)
|
||||
{
|
||||
/* create */
|
||||
c->fcall.id = TCREATE;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = dirfid;
|
||||
|
@ -107,7 +103,6 @@ ixp_client_walk(IXPClient * c, unsigned int newfid, char *filepath)
|
|||
{
|
||||
unsigned int i;
|
||||
char *wname[IXP_MAX_WELEM];
|
||||
/* walk */
|
||||
c->fcall.id = TWALK;
|
||||
c->fcall.fid = c->root_fid;
|
||||
c->fcall.newfid = newfid;
|
||||
|
@ -128,7 +123,6 @@ ixp_client_open(IXPClient * c, unsigned int newfid, char *filepath,
|
|||
if(ixp_client_walk(c, newfid, filepath) == -1)
|
||||
return -1;
|
||||
|
||||
/* open */
|
||||
c->fcall.id = TOPEN;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = newfid;
|
||||
|
@ -142,7 +136,6 @@ ixp_client_read(IXPClient * c, unsigned int fid, unsigned long long offset,
|
|||
{
|
||||
unsigned int bytes = c->fcall.iounit;
|
||||
|
||||
/* read */
|
||||
c->fcall.id = TREAD;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = fid;
|
||||
|
@ -164,7 +157,6 @@ ixp_client_write(IXPClient * c, unsigned int fid,
|
|||
c->errstr = "iounit exceeded";
|
||||
return -1;
|
||||
}
|
||||
/* write */
|
||||
c->fcall.id = TWRITE;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = fid;
|
||||
|
@ -179,7 +171,6 @@ ixp_client_write(IXPClient * c, unsigned int fid,
|
|||
int
|
||||
ixp_client_close(IXPClient * c, unsigned int fid)
|
||||
{
|
||||
/* clunk */
|
||||
c->fcall.id = TCLUNK;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = fid;
|
||||
|
@ -187,7 +178,7 @@ ixp_client_close(IXPClient * c, unsigned int fid)
|
|||
}
|
||||
|
||||
void
|
||||
ixp_client_deinit(IXPClient * c)
|
||||
ixp_client_hangup(IXPClient * c)
|
||||
{
|
||||
/* session finished, now shutdown */
|
||||
if(c->fd) {
|
||||
|
|
|
@ -231,8 +231,8 @@ typedef struct {
|
|||
} IXPClient;
|
||||
|
||||
/* client.c */
|
||||
int ixp_client_init(IXPClient *c, char *address, unsigned int rootfid);
|
||||
void ixp_client_deinit(IXPClient *c);
|
||||
int ixp_client_dial(IXPClient *c, char *address, unsigned int rootfid);
|
||||
void ixp_client_hangup(IXPClient *c);
|
||||
int ixp_client_remove(IXPClient *c, unsigned int newfid, char *filepath);
|
||||
int ixp_client_create(IXPClient *c, unsigned int dirfid, char *name,
|
||||
unsigned int perm, unsigned char mode);
|
||||
|
|
Loading…
Reference in New Issue