commit 55e8f6e55caa6d2799a4ecb6a604db931fd37e8f
parent 67e974ae086d60ee5430d9bcd40479f11f4916ec
Author: Anthony Martin <ality@pbrane.org>
Date: Thu, 23 Mar 2006 03:53:41 -0800
cleaned up formatting in libixp
Diffstat:
| libixp/client.c | | | 230 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| libixp/convert.c | | | 187 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| libixp/ixp.h | | | 268 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
| libixp/message.c | | | 540 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| libixp/server.c | | | 63 | +++++++++++++++++++++++++++++++-------------------------------- |
| libixp/socket.c | | | 172 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| libixp/transport.c | | | 89 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
7 files changed, 769 insertions(+), 780 deletions(-)
diff --git a/libixp/client.c b/libixp/client.c
@@ -13,89 +13,88 @@
#include "cext.h"
#include "ixp.h"
-
int
ixp_client_do_fcall(IXPClient * c)
{
static unsigned char msg[IXP_MAX_MSG];
- unsigned int msize = ixp_fcall2msg(msg, &c->fcall, IXP_MAX_MSG);
- c->errstr = 0;
- if(ixp_send_message(c->fd, msg, msize, &c->errstr) != msize)
- return -1;
- if(!ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &c->errstr))
- return -1;
- if(!(msize = ixp_msg2fcall(&c->fcall, msg, IXP_MAX_MSG))) {
- c->errstr = "received bad message";
- return -1;
- }
- if(c->fcall.id == RERROR) {
- c->errstr = c->fcall.errstr;
- return -1;
- }
- return 0;
+ unsigned int msize = ixp_fcall2msg(msg, &c->fcall, IXP_MAX_MSG);
+ c->errstr = 0;
+ if(ixp_send_message(c->fd, msg, msize, &c->errstr) != msize)
+ return -1;
+ if(!ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &c->errstr))
+ return -1;
+ if(!(msize = ixp_msg2fcall(&c->fcall, msg, IXP_MAX_MSG))) {
+ c->errstr = "received bad message";
+ return -1;
+ }
+ if(c->fcall.id == RERROR) {
+ c->errstr = c->fcall.errstr;
+ return -1;
+ }
+ return 0;
}
int
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;
- }
- 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) {
+ if((c->fd = ixp_connect_sock(sockfile)) < 0) {
+ c->errstr = "cannot connect server";
+ return -1;
+ }
+ 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_hangup(c);
- return -1;
- }
- if(strncmp(c->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) {
+ 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_hangup(c);
- return -1; /* we cannot handle this version */
- }
- c->root_fid = rootfid;
-
- c->fcall.id = TATTACH;
- c->fcall.tag = IXP_NOTAG;
- c->fcall.fid = c->root_fid;
- c->fcall.afid = IXP_NOFID;
- cext_strlcpy(c->fcall.uname, getenv("USER"), sizeof(c->fcall.uname));
- c->fcall.aname[0] = 0;
- if(ixp_client_do_fcall(c) == -1) {
+ c->errstr = "9P versions differ";
+ ixp_client_hangup(c);
+ return -1; /* we cannot handle this version */
+ }
+ c->root_fid = rootfid;
+
+ c->fcall.id = TATTACH;
+ c->fcall.tag = IXP_NOTAG;
+ c->fcall.fid = c->root_fid;
+ c->fcall.afid = IXP_NOFID;
+ cext_strlcpy(c->fcall.uname, getenv("USER"), sizeof(c->fcall.uname));
+ c->fcall.aname[0] = 0;
+ if(ixp_client_do_fcall(c) == -1) {
fprintf(stderr, "error: %s\n", c->fcall.errstr);
- ixp_client_hangup(c);
- return -1;
- }
- c->root_qid = c->fcall.qid;
- return 0;
+ ixp_client_hangup(c);
+ return -1;
+ }
+ c->root_qid = c->fcall.qid;
+ return 0;
}
int
ixp_client_remove(IXPClient * c, unsigned int newfid, char *filepath)
{
- if(ixp_client_walk(c, newfid, filepath) == -1)
- return -1;
- c->fcall.id = TREMOVE;
- c->fcall.tag = IXP_NOTAG;
- c->fcall.fid = newfid;
- return ixp_client_do_fcall(c);
+ if(ixp_client_walk(c, newfid, filepath) == -1)
+ return -1;
+ c->fcall.id = TREMOVE;
+ c->fcall.tag = IXP_NOTAG;
+ c->fcall.fid = newfid;
+ return ixp_client_do_fcall(c);
}
int
ixp_client_create(IXPClient * c, unsigned int dirfid, char *name,
- unsigned int perm, unsigned char mode)
+ unsigned int perm, unsigned char mode)
{
- c->fcall.id = TCREATE;
- c->fcall.tag = IXP_NOTAG;
- c->fcall.fid = dirfid;
- cext_strlcpy(c->fcall.name, name, sizeof(c->fcall.name));
- c->fcall.perm = perm;
- c->fcall.mode = mode;
- return ixp_client_do_fcall(c);
+ c->fcall.id = TCREATE;
+ c->fcall.tag = IXP_NOTAG;
+ c->fcall.fid = dirfid;
+ cext_strlcpy(c->fcall.name, name, sizeof(c->fcall.name));
+ c->fcall.perm = perm;
+ c->fcall.mode = mode;
+ return ixp_client_do_fcall(c);
}
int
@@ -103,86 +102,85 @@ ixp_client_walk(IXPClient * c, unsigned int newfid, char *filepath)
{
unsigned int i;
char *wname[IXP_MAX_WELEM];
- c->fcall.id = TWALK;
- c->fcall.fid = c->root_fid;
- c->fcall.newfid = newfid;
- if(filepath) {
- cext_strlcpy(c->fcall.name, filepath, sizeof(c->fcall.name));
- c->fcall.nwname =
- cext_tokenize(wname, IXP_MAX_WELEM, c->fcall.name, '/');
+ c->fcall.id = TWALK;
+ c->fcall.fid = c->root_fid;
+ c->fcall.newfid = newfid;
+ if(filepath) {
+ cext_strlcpy(c->fcall.name, filepath, sizeof(c->fcall.name));
+ c->fcall.nwname =
+ cext_tokenize(wname, IXP_MAX_WELEM, c->fcall.name, '/');
for(i = 0; i < c->fcall.nwname; i++)
cext_strlcpy(c->fcall.wname[i], wname[i], sizeof(c->fcall.wname[i]));
- }
- return ixp_client_do_fcall(c);
+ }
+ return ixp_client_do_fcall(c);
}
int
ixp_client_open(IXPClient * c, unsigned int newfid, char *filepath,
- unsigned char mode)
+ unsigned char mode)
{
- if(ixp_client_walk(c, newfid, filepath) == -1)
- return -1;
-
- c->fcall.id = TOPEN;
- c->fcall.tag = IXP_NOTAG;
- c->fcall.fid = newfid;
- c->fcall.mode = mode;
- return ixp_client_do_fcall(c);
+ if(ixp_client_walk(c, newfid, filepath) == -1)
+ return -1;
+
+ c->fcall.id = TOPEN;
+ c->fcall.tag = IXP_NOTAG;
+ c->fcall.fid = newfid;
+ c->fcall.mode = mode;
+ return ixp_client_do_fcall(c);
}
int
ixp_client_read(IXPClient * c, unsigned int fid, unsigned long long offset,
- void *result, unsigned int res_len)
+ void *result, unsigned int res_len)
{
- unsigned int bytes = c->fcall.iounit;
-
- c->fcall.id = TREAD;
- c->fcall.tag = IXP_NOTAG;
- c->fcall.fid = fid;
- c->fcall.offset = offset;
- c->fcall.count = res_len < bytes ? res_len : bytes;
- if(ixp_client_do_fcall(c) == -1)
- return -1;
- memcpy(result, c->fcall.data, c->fcall.count);
- return c->fcall.count;
+ unsigned int bytes = c->fcall.iounit;
+
+ c->fcall.id = TREAD;
+ c->fcall.tag = IXP_NOTAG;
+ c->fcall.fid = fid;
+ c->fcall.offset = offset;
+ c->fcall.count = res_len < bytes ? res_len : bytes;
+ if(ixp_client_do_fcall(c) == -1)
+ return -1;
+ memcpy(result, c->fcall.data, c->fcall.count);
+ return c->fcall.count;
}
int
ixp_client_write(IXPClient * c, unsigned int fid,
- unsigned long long offset, unsigned int count,
- unsigned char *data)
+ unsigned long long offset, unsigned int count,
+ unsigned char *data)
{
- if(count > c->fcall.iounit)
- {
- c->errstr = "iounit exceeded";
- return -1;
- }
- c->fcall.id = TWRITE;
- c->fcall.tag = IXP_NOTAG;
- c->fcall.fid = fid;
- c->fcall.offset = offset;
- c->fcall.count = count;
- memcpy(c->fcall.data, data, count);
- if(ixp_client_do_fcall(c) == -1)
- return -1;
- return c->fcall.count;
+ if(count > c->fcall.iounit) {
+ c->errstr = "iounit exceeded";
+ return -1;
+ }
+ c->fcall.id = TWRITE;
+ c->fcall.tag = IXP_NOTAG;
+ c->fcall.fid = fid;
+ c->fcall.offset = offset;
+ c->fcall.count = count;
+ memcpy(c->fcall.data, data, count);
+ if(ixp_client_do_fcall(c) == -1)
+ return -1;
+ return c->fcall.count;
}
int
ixp_client_close(IXPClient * c, unsigned int fid)
{
- c->fcall.id = TCLUNK;
- c->fcall.tag = IXP_NOTAG;
- c->fcall.fid = fid;
- return ixp_client_do_fcall(c);
+ c->fcall.id = TCLUNK;
+ c->fcall.tag = IXP_NOTAG;
+ c->fcall.fid = fid;
+ return ixp_client_do_fcall(c);
}
void
ixp_client_hangup(IXPClient * c)
{
- /* session finished, now shutdown */
- if(c->fd) {
- shutdown(c->fd, SHUT_RDWR);
- close(c->fd);
- }
+ /* session finished, now shutdown */
+ if(c->fd) {
+ shutdown(c->fd, SHUT_RDWR);
+ close(c->fd);
+ }
}
diff --git a/libixp/convert.c b/libixp/convert.c
@@ -12,170 +12,167 @@
void *
ixp_enc_u8(unsigned char *msg, unsigned char val)
{
- msg[0] = val;
- return &msg[1];
+ msg[0] = val;
+ return &msg[1];
}
void *
ixp_dec_u8(unsigned char *msg, unsigned char *val)
{
- *val = msg[0];
- return &msg[1];
+ *val = msg[0];
+ return &msg[1];
}
void *
ixp_enc_u16(unsigned char *msg, unsigned short val)
{
- msg[0] = val;
- msg[1] = val >> 8;
- return &msg[2];
+ msg[0] = val;
+ msg[1] = val >> 8;
+ return &msg[2];
}
void *
ixp_dec_u16(unsigned char *msg, unsigned short *val)
{
- *val = msg[0] | (msg[1] << 8);
- return &msg[2];
+ *val = msg[0] | (msg[1] << 8);
+ return &msg[2];
}
void *
ixp_enc_u32(unsigned char *msg, unsigned int val)
{
- msg[0] = val;
- msg[1] = val >> 8;
- msg[2] = val >> 16;
- msg[3] = val >> 24;
- return &msg[4];
+ msg[0] = val;
+ msg[1] = val >> 8;
+ msg[2] = val >> 16;
+ msg[3] = val >> 24;
+ return &msg[4];
}
void *
ixp_dec_u32(unsigned char *msg, unsigned int *val)
{
- *val = msg[0] | (msg[1] << 8) | (msg[2] << 16) | (msg[3] << 24);
- return &msg[4];
+ *val = msg[0] | (msg[1] << 8) | (msg[2] << 16) | (msg[3] << 24);
+ return &msg[4];
}
void *
ixp_enc_u64(unsigned char *msg, unsigned long long val)
{
- msg[0] = val;
- msg[1] = val >> 8;
- msg[2] = val >> 16;
- msg[3] = val >> 24;
- msg[4] = val >> 32;
- msg[5] = val >> 40;
- msg[6] = val >> 48;
- msg[7] = val >> 56;
- return &msg[8];
+ msg[0] = val;
+ msg[1] = val >> 8;
+ msg[2] = val >> 16;
+ msg[3] = val >> 24;
+ msg[4] = val >> 32;
+ msg[5] = val >> 40;
+ msg[6] = val >> 48;
+ msg[7] = val >> 56;
+ return &msg[8];
}
void *
ixp_dec_u64(unsigned char *msg, unsigned long long *val)
{
- *val =
- (unsigned long long) msg[0] | ((unsigned long long) msg[1] << 8) |
- ((unsigned long long) msg[2] << 16) | ((unsigned long long) msg[3]
- << 24) | ((unsigned long
- long) msg[4] <<
- 32) | ((unsigned
- long long)
- msg[5] <<
- 40) |
- ((unsigned long long) msg[6] << 48) | ((unsigned long long) msg[7]
- << 56);
- return &msg[8];
+ *val = (unsigned long long) msg[0] |
+ ((unsigned long long) msg[1] << 8) |
+ ((unsigned long long) msg[2] << 16) |
+ ((unsigned long long) msg[3] << 24) |
+ ((unsigned long long) msg[4] << 32) |
+ ((unsigned long long) msg[5] << 40) |
+ ((unsigned long long) msg[6] << 48) |
+ ((unsigned long long) msg[7] << 56);
+ return &msg[8];
}
void *
ixp_enc_string(unsigned char *msg, const char *s)
{
- unsigned short len = s ? strlen(s) : 0;
- msg = ixp_enc_u16(msg, len);
- if(s)
- memcpy(msg, s, len);
- return &msg[len];
+ unsigned short len = s ? strlen(s) : 0;
+ msg = ixp_enc_u16(msg, len);
+ if(s)
+ memcpy(msg, s, len);
+ return &msg[len];
}
void *
ixp_dec_string(unsigned char *msg, char *string, unsigned short stringlen,
- unsigned short *len)
+ unsigned short *len)
{
- msg = ixp_dec_u16(msg, len);
- if(!(*len))
- return msg;
- if(*len > stringlen - 1)
- /* might never happen if stringlen == IXP_MAX_MSG */
- string[0] = 0;
- else {
- memcpy(string, msg, *len);
- string[*len] = 0;
- }
- return &msg[*len];
+ msg = ixp_dec_u16(msg, len);
+ if(!(*len))
+ return msg;
+ if(*len > stringlen - 1)
+ /* might never happen if stringlen == IXP_MAX_MSG */
+ string[0] = 0;
+ else {
+ memcpy(string, msg, *len);
+ string[*len] = 0;
+ }
+ return &msg[*len];
}
void *
ixp_enc_data(unsigned char *msg, unsigned char *data, unsigned int datalen)
{
- memcpy(msg, data, datalen);
- return &msg[datalen];
+ memcpy(msg, data, datalen);
+ return &msg[datalen];
}
void *
ixp_dec_data(unsigned char *msg, unsigned char *data, unsigned int datalen)
{
- memcpy(data, msg, datalen);
- return &msg[datalen];
+ memcpy(data, msg, datalen);
+ return &msg[datalen];
}
void *
ixp_enc_prefix(unsigned char *msg, unsigned int size, unsigned char id,
- unsigned short tag)
+ unsigned short tag)
{
- msg = ixp_enc_u32(msg, size);
- msg = ixp_enc_u8(msg, id);
- return ixp_enc_u16(msg, tag);
+ msg = ixp_enc_u32(msg, size);
+ msg = ixp_enc_u8(msg, id);
+ return ixp_enc_u16(msg, tag);
}
void *
ixp_dec_prefix(unsigned char *msg, unsigned int *size, unsigned char *id,
- unsigned short *tag)
+ unsigned short *tag)
{
- msg = ixp_dec_u32(msg, size);
- msg = ixp_dec_u8(msg, id);
- return ixp_dec_u16(msg, tag);
+ msg = ixp_dec_u32(msg, size);
+ msg = ixp_dec_u8(msg, id);
+ return ixp_dec_u16(msg, tag);
}
void *
ixp_enc_qid(unsigned char *msg, Qid * qid)
{
- msg = ixp_enc_u8(msg, qid->type);
- msg = ixp_enc_u32(msg, qid->version);
- return ixp_enc_u64(msg, qid->path);
+ msg = ixp_enc_u8(msg, qid->type);
+ msg = ixp_enc_u32(msg, qid->version);
+ return ixp_enc_u64(msg, qid->path);
}
void *
ixp_dec_qid(unsigned char *msg, Qid * qid)
{
- msg = ixp_dec_u8(msg, &qid->type);
- msg = ixp_dec_u32(msg, &qid->version);
- return ixp_dec_u64(msg, &qid->path);
+ msg = ixp_dec_u8(msg, &qid->type);
+ msg = ixp_dec_u32(msg, &qid->version);
+ return ixp_dec_u64(msg, &qid->path);
}
void *
ixp_enc_stat(unsigned char *msg, Stat * stat)
{
- msg = ixp_enc_u16(msg, ixp_sizeof_stat(stat) - sizeof(unsigned short));
- msg = ixp_enc_u16(msg, stat->type);
- msg = ixp_enc_u32(msg, stat->dev);
- msg = ixp_enc_qid(msg, &stat->qid);
- msg = ixp_enc_u32(msg, stat->mode);
- msg = ixp_enc_u32(msg, stat->atime);
- msg = ixp_enc_u32(msg, stat->mtime);
- msg = ixp_enc_u64(msg, stat->length);
- msg = ixp_enc_string(msg, stat->name);
- msg = ixp_enc_string(msg, stat->uid);
- msg = ixp_enc_string(msg, stat->gid);
- return ixp_enc_string(msg, stat->muid);
+ msg = ixp_enc_u16(msg, ixp_sizeof_stat(stat) - sizeof(unsigned short));
+ msg = ixp_enc_u16(msg, stat->type);
+ msg = ixp_enc_u32(msg, stat->dev);
+ msg = ixp_enc_qid(msg, &stat->qid);
+ msg = ixp_enc_u32(msg, stat->mode);
+ msg = ixp_enc_u32(msg, stat->atime);
+ msg = ixp_enc_u32(msg, stat->mtime);
+ msg = ixp_enc_u64(msg, stat->length);
+ msg = ixp_enc_string(msg, stat->name);
+ msg = ixp_enc_string(msg, stat->uid);
+ msg = ixp_enc_string(msg, stat->gid);
+ return ixp_enc_string(msg, stat->muid);
}
void *
@@ -183,15 +180,15 @@ ixp_dec_stat(unsigned char *msg, Stat * stat)
{
unsigned short dummy;
msg += sizeof(unsigned short);
- msg = ixp_dec_u16(msg, &stat->type);
- msg = ixp_dec_u32(msg, &stat->dev);
- msg = ixp_dec_qid(msg, &stat->qid);
- msg = ixp_dec_u32(msg, &stat->mode);
- msg = ixp_dec_u32(msg, &stat->atime);
- msg = ixp_dec_u32(msg, &stat->mtime);
- msg = ixp_dec_u64(msg, &stat->length);
- msg = ixp_dec_string(msg, stat->name, sizeof(stat->name), &dummy);
- msg = ixp_dec_string(msg, stat->uid, sizeof(stat->uid), &dummy);
- msg = ixp_dec_string(msg, stat->gid, sizeof(stat->gid), &dummy);
- return ixp_dec_string(msg, stat->muid, sizeof(stat->muid), &dummy);
+ msg = ixp_dec_u16(msg, &stat->type);
+ msg = ixp_dec_u32(msg, &stat->dev);
+ msg = ixp_dec_qid(msg, &stat->qid);
+ msg = ixp_dec_u32(msg, &stat->mode);
+ msg = ixp_dec_u32(msg, &stat->atime);
+ msg = ixp_dec_u32(msg, &stat->mtime);
+ msg = ixp_dec_u64(msg, &stat->length);
+ msg = ixp_dec_string(msg, stat->name, sizeof(stat->name), &dummy);
+ msg = ixp_dec_string(msg, stat->uid, sizeof(stat->uid), &dummy);
+ msg = ixp_dec_string(msg, stat->gid, sizeof(stat->gid), &dummy);
+ return ixp_dec_string(msg, stat->muid, sizeof(stat->muid), &dummy);
}
diff --git a/libixp/ixp.h b/libixp/ixp.h
@@ -9,15 +9,15 @@
#define nil 0
#endif
-#define IXP_VERSION "9P2000"
-#define IXP_MAX_VERSION 32
-#define IXP_MAX_ERROR 128
-#define IXP_MAX_CACHE 32
-#define IXP_MAX_MSG 8192
-#define IXP_MAX_FLEN 128
-#define IXP_MAX_ULEN 32
-#define IXP_MAX_STAT 64
-#define IXP_MAX_WELEM 16 /*MAXWELEM */
+#define IXP_VERSION "9P2000"
+#define IXP_MAX_VERSION 32
+#define IXP_MAX_ERROR 128
+#define IXP_MAX_CACHE 32
+#define IXP_MAX_MSG 8192
+#define IXP_MAX_FLEN 128
+#define IXP_MAX_ULEN 32
+#define IXP_MAX_STAT 64
+#define IXP_MAX_WELEM 16 /*MAXWELEM */
#define IXP_MAX_TFUNCS 14
@@ -51,53 +51,55 @@
size[4] Rwstat tag[2]
stat[n]:
- size[2] total byte count of the following data
- type[2] for kernel use
- dev[4] for kernel use
- qid.type[1] the type of the file (directory, etc.),
- represented as a bit vector corresponding to the high 8 bits of the file's mode word.
- qid.vers[4] version number for given path
- qid.path[8] the file server's unique identification for the file
- mode[4] permissions and flags
- atime[4] last access time
- mtime[4] last modification time
- length[8] length of file in bytes
- name[ s ] file name; must be / if the file is the root directory of the server
- uid[ s ] owner name
- gid[ s ] group name
+ size[2] total byte count of the following data
+ type[2] for kernel use
+ dev[4] for kernel use
+ qid.type[1] the type of the file (directory, etc.),
+ represented as a bit vector corresponding to the high 8
+ bits of the file's mode word.
+ qid.vers[4] version number for given path
+ qid.path[8] the file server's unique identification for the file
+ mode[4] permissions and flags
+ atime[4] last access time
+ mtime[4] last modification time
+ length[8] length of file in bytes
+ name[ s ] file name; must be / if the file is the root directory of
+ the server
+ uid[ s ] owner name
+ gid[ s ] group name
muid[ s ]
*/
/*9P message types */
enum {
- TVERSION = 100,
- RVERSION,
- TAUTH = 102,
- RAUTH,
- TATTACH = 104,
- RATTACH,
- TERROR = 106,
- RERROR,
- TFLUSH = 108,
- RFLUSH,
- TWALK = 110,
- RWALK,
- TOPEN = 112,
- ROPEN,
- TCREATE = 114,
- RCREATE,
- TREAD = 116,
- RREAD,
- TWRITE = 118,
- RWRITE,
- TCLUNK = 120,
- RCLUNK,
- TREMOVE = 122,
- RREMOVE,
- TSTAT = 124,
- RSTAT,
- TWSTAT = 126,
- RWSTAT,
+ TVERSION = 100,
+ RVERSION,
+ TAUTH = 102,
+ RAUTH,
+ TATTACH = 104,
+ RATTACH,
+ TERROR = 106,
+ RERROR,
+ TFLUSH = 108,
+ RFLUSH,
+ TWALK = 110,
+ RWALK,
+ TOPEN = 112,
+ ROPEN,
+ TCREATE = 114,
+ RCREATE,
+ TREAD = 116,
+ RREAD,
+ TWRITE = 118,
+ RWRITE,
+ TCLUNK = 120,
+ RCLUNK,
+ TREMOVE = 122,
+ RREMOVE,
+ TSTAT = 124,
+ RSTAT,
+ TWSTAT = 126,
+ RWSTAT,
};
/* borrowed from libc.h of Plan 9 */
@@ -114,84 +116,84 @@ enum {
/* modes */
enum {
- IXP_OREAD = 0x00,
- IXP_OWRITE = 0x01,
- IXP_ORDWR = 0x02,
- IXP_OEXEC = 0x03,
- IXP_OEXCL = 0x04,
- IXP_OTRUNC = 0x10,
- IXP_OREXEC = 0x20,
- IXP_ORCLOSE = 0x40,
- IXP_OAPPEND = 0x80,
+ IXP_OREAD = 0x00,
+ IXP_OWRITE = 0x01,
+ IXP_ORDWR = 0x02,
+ IXP_OEXEC = 0x03,
+ IXP_OEXCL = 0x04,
+ IXP_OTRUNC = 0x10,
+ IXP_OREXEC = 0x20,
+ IXP_ORCLOSE = 0x40,
+ IXP_OAPPEND = 0x80,
};
/* qid.types */
enum {
- IXP_QTDIR = 0x80,
- IXP_QTAPPEND = 0x40,
- IXP_QTEXCL = 0x20,
- IXP_QTMOUNT = 0x10,
- IXP_QTAUTH = 0x08,
- IXP_QTTMP = 0x04,
- IXP_QTSYMLINK = 0x02,
- IXP_QTLINK = 0x01,
- IXP_QTFILE = 0x00,
+ IXP_QTDIR = 0x80,
+ IXP_QTAPPEND = 0x40,
+ IXP_QTEXCL = 0x20,
+ IXP_QTMOUNT = 0x10,
+ IXP_QTAUTH = 0x08,
+ IXP_QTTMP = 0x04,
+ IXP_QTSYMLINK = 0x02,
+ IXP_QTLINK = 0x01,
+ IXP_QTFILE = 0x00,
};
-#define IXP_NOTAG (unsigned short)~0U /*Dummy tag */
-#define IXP_NOFID (unsigned int)~0 /*No auth */
+#define IXP_NOTAG (unsigned short)~0U /*Dummy tag */
+#define IXP_NOFID (unsigned int)~0 /*No auth */
typedef struct Qid Qid;
struct Qid {
- unsigned char type;
- unsigned int version;
- unsigned long long path;
+ unsigned char type;
+ unsigned int version;
+ unsigned long long path;
/* internal use only */
unsigned char dir_type;
};
/*stat structure */
typedef struct {
- unsigned short type;
- unsigned int dev;
- Qid qid;
- unsigned int mode;
- unsigned int atime;
- unsigned int mtime;
- unsigned long long length;
- char name[IXP_MAX_FLEN];
- char uid[IXP_MAX_ULEN];
- char gid[IXP_MAX_ULEN];
- char muid[IXP_MAX_ULEN];
+ unsigned short type;
+ unsigned int dev;
+ Qid qid;
+ unsigned int mode;
+ unsigned int atime;
+ unsigned int mtime;
+ unsigned long long length;
+ char name[IXP_MAX_FLEN];
+ char uid[IXP_MAX_ULEN];
+ char gid[IXP_MAX_ULEN];
+ char muid[IXP_MAX_ULEN];
} Stat;
typedef struct {
- unsigned char id;
- unsigned short tag;
- unsigned int fid;
- unsigned int maxmsg; /*Tversion, Rversion */
- char version[IXP_MAX_VERSION]; /*Tversion, Rversion */
- unsigned short oldtag; /*Tflush */
- char errstr[IXP_MAX_ERROR]; /*Rerror */
- Qid qid; /*Rattach, Ropen, Rcreate */
- unsigned int iounit; /*Ropen, Rcreate */
- Qid aqid; /*Rauth */
- unsigned int afid; /*Tauth, Tattach */
- char uname[IXP_MAX_ULEN]; /*Tauth, Tattach */
- char aname[IXP_MAX_FLEN]; /*Tauth, Tattach */
- unsigned int perm; /*Tcreate */
- char name[IXP_MAX_FLEN]; /*Tcreate */
- unsigned char mode; /*Tcreate, Topen */
- unsigned int newfid; /*Twalk */
- unsigned short nwname; /*Twalk */
- char wname[IXP_MAX_WELEM][IXP_MAX_FLEN]; /*Twalk */
- unsigned short nwqid; /*Rwalk */
- Qid wqid[IXP_MAX_WELEM]; /*Rwalk */
- unsigned long long offset; /*Tread, Twrite */
- unsigned int count; /*Tread, Twrite, Rread */
- Stat stat; /*Rstat */
- unsigned short nstat; /*Twstat, Rstat */
- unsigned char data[IXP_MAX_MSG]; /*Twrite, Rread, Twstat, *Rstat */
+ unsigned char id;
+ unsigned short tag;
+ unsigned int fid;
+ unsigned int maxmsg; /*Tversion, Rversion */
+ char version[IXP_MAX_VERSION]; /*Tversion, Rversion */
+ unsigned short oldtag; /*Tflush */
+ char errstr[IXP_MAX_ERROR]; /*Rerror */
+ Qid qid; /*Rattach, Ropen, Rcreate */
+ unsigned int iounit; /*Ropen, Rcreate */
+ Qid aqid; /*Rauth */
+ unsigned int afid; /*Tauth, Tattach */
+ char uname[IXP_MAX_ULEN]; /*Tauth, Tattach */
+ char aname[IXP_MAX_FLEN]; /*Tauth, Tattach */
+ unsigned int perm; /*Tcreate */
+ char name[IXP_MAX_FLEN]; /*Tcreate */
+ unsigned char mode; /*Tcreate, Topen */
+ unsigned int newfid; /*Twalk */
+ unsigned short nwname; /*Twalk */
+ char wname[IXP_MAX_WELEM][IXP_MAX_FLEN]; /*Twalk */
+ unsigned short nwqid; /*Rwalk */
+ Qid wqid[IXP_MAX_WELEM]; /*Rwalk */
+ unsigned long long offset; /*Tread, Twrite */
+ unsigned int count; /*Tread, Twrite, Rread */
+ Stat stat; /*Rstat */
+ unsigned short nstat; /*Twstat, Rstat */
+ unsigned char data[IXP_MAX_MSG]; /*Twrite, Rread, Twstat, *Rstat */
} Fcall;
typedef struct IXPServer IXPServer;
@@ -204,10 +206,10 @@ struct IXPMap {
};
struct IXPConn {
- int fd;
+ int fd;
IXPServer *srv;
- void (*read) (IXPConn *);
- void (*close) (IXPConn *);
+ void (*read) (IXPConn *);
+ void (*close) (IXPConn *);
IXPMap **map;
unsigned int mapsz;
Fcall pending;
@@ -215,19 +217,19 @@ struct IXPConn {
};
struct IXPServer {
- int running;
+ int running;
IXPConn **conn;
unsigned int connsz;
- int maxfd;
- fd_set rd;
+ int maxfd;
+ fd_set rd;
};
typedef struct {
- int fd;
- unsigned int root_fid;
- Qid root_qid;
- Fcall fcall;
- char *errstr;
+ int fd;
+ unsigned int root_fid;
+ Qid root_qid;
+ Fcall fcall;
+ char *errstr;
} IXPClient;
/* client.c */
@@ -235,16 +237,16 @@ 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);
+ unsigned int perm, unsigned char mode);
int ixp_client_walk(IXPClient *c, unsigned int newfid, char *filepath);
int ixp_client_open(IXPClient *c, unsigned int newfid, char *filepath,
- unsigned char mode);
+ unsigned char mode);
int ixp_client_read(IXPClient *c, unsigned int fid,
- unsigned long long offset, void *result,
- unsigned int res_len);
+ unsigned long long offset, void *result,
+ unsigned int res_len);
int ixp_client_write(IXPClient *c, unsigned int fid,
- unsigned long long offset,
- unsigned int count, unsigned char *data);
+ unsigned long long offset,
+ unsigned int count, unsigned char *data);
int ixp_client_close(IXPClient *c, unsigned int fid);
int ixp_client_do_fcall(IXPClient * c);
@@ -259,15 +261,15 @@ void *ixp_enc_u64(unsigned char *msg, unsigned long long val);
void *ixp_dec_u64(unsigned char *msg, unsigned long long *val);
void *ixp_enc_string(unsigned char *msg, const char *s);
void *ixp_dec_string(unsigned char *msg, char *string,
- unsigned short stringlen, unsigned short *len);
+ unsigned short stringlen, unsigned short *len);
void *ixp_enc_data(unsigned char *msg, unsigned char *data,
- unsigned int datalen);
+ unsigned int datalen);
void *ixp_dec_data(unsigned char *msg, unsigned char *data,
- unsigned int datalen);
+ unsigned int datalen);
void *ixp_enc_prefix(unsigned char *msg, unsigned int size,
- unsigned char id, unsigned short tag);
+ unsigned char id, unsigned short tag);
void *ixp_dec_prefix(unsigned char *msg, unsigned int *size,
- unsigned char *id, unsigned short *tag);
+ unsigned char *id, unsigned short *tag);
void *ixp_enc_qid(unsigned char *msg, Qid *qid);
void *ixp_dec_qid(unsigned char *msg, Qid *qid);
void *ixp_enc_stat(unsigned char *msg, Stat *stat);
diff --git a/libixp/message.c b/libixp/message.c
@@ -9,309 +9,303 @@
#include "ixp.h"
#define IXP_QIDSZ (sizeof(unsigned char) + sizeof(unsigned int)\
- + sizeof(unsigned long long))
+ + sizeof(unsigned long long))
static unsigned short
sizeof_string(const char *s)
{
- return sizeof(unsigned short) + strlen(s);
+ return sizeof(unsigned short) + strlen(s);
}
unsigned short
ixp_sizeof_stat(Stat * stat)
{
- return IXP_QIDSZ
- + 2 * sizeof(unsigned short)
- + 4 * sizeof(unsigned int)
- + sizeof(unsigned long long)
- + sizeof_string(stat->name)
- + sizeof_string(stat->uid)
- + sizeof_string(stat->gid)
- + sizeof_string(stat->muid);
+ return IXP_QIDSZ
+ + 2 * sizeof(unsigned short)
+ + 4 * sizeof(unsigned int)
+ + sizeof(unsigned long long)
+ + sizeof_string(stat->name)
+ + sizeof_string(stat->uid)
+ + sizeof_string(stat->gid)
+ + sizeof_string(stat->muid);
}
unsigned int
ixp_fcall2msg(void *msg, Fcall *fcall, unsigned int msglen)
{
- unsigned int i, msize =
- sizeof(unsigned char) + sizeof(unsigned short) +
- sizeof(unsigned int);
- void *p = msg;
+ unsigned int i, msize =
+ sizeof(unsigned char) + sizeof(unsigned short) +
+ sizeof(unsigned int);
+ void *p = msg;
- switch (fcall->id) {
- case TVERSION:
- case RVERSION:
- msize += sizeof(unsigned int) + sizeof_string(fcall->version);
- break;
- case TAUTH:
- msize +=
- sizeof(unsigned int) + sizeof_string(fcall->uname) +
- sizeof_string(fcall->aname);
- break;
- case RAUTH:
- case RATTACH:
- msize += IXP_QIDSZ;
- break;
- case TATTACH:
- msize +=
- 2 * sizeof(unsigned int) + sizeof_string(fcall->uname) +
- sizeof_string(fcall->aname);
- break;
- case RERROR:
- msize += sizeof_string(fcall->errstr);
- break;
- case RWRITE:
- case TCLUNK:
- case TREMOVE:
- case TSTAT:
- msize += sizeof(unsigned int);
- break;
- case TWALK:
- msize += sizeof(unsigned short) + 2 * sizeof(unsigned int);
- for(i = 0; i < fcall->nwname; i++)
- msize += sizeof_string(fcall->wname[i]);
- break;
- case TFLUSH:
- msize += sizeof(unsigned short);
- break;
- case RWALK:
- msize += sizeof(unsigned short) + fcall->nwqid * IXP_QIDSZ;
- break;
- case TOPEN:
- msize += sizeof(unsigned int) + sizeof(unsigned char);
- break;
- case ROPEN:
- case RCREATE:
- msize += IXP_QIDSZ + sizeof(unsigned int);
- break;
- case TCREATE:
- msize +=
- sizeof(unsigned char) + 2 * sizeof(unsigned int) +
- sizeof_string(fcall->name);
- break;
- case TREAD:
- msize += 2 * sizeof(unsigned int) + sizeof(unsigned long long);
- break;
- case RREAD:
- msize += sizeof(unsigned int) + fcall->count;
- break;
- case TWRITE:
- msize +=
- 2 * sizeof(unsigned int) + sizeof(unsigned long long) +
- fcall->count;
- break;
- case RSTAT:
- msize += sizeof(unsigned short) + ixp_sizeof_stat(&fcall->stat);
- break;
- case TWSTAT:
- msize += sizeof(unsigned int) + sizeof(unsigned short) + ixp_sizeof_stat(&fcall->stat);
- break;
- default:
- break;
- }
+ switch (fcall->id) {
+ case TVERSION:
+ case RVERSION:
+ msize += sizeof(unsigned int) + sizeof_string(fcall->version);
+ break;
+ case TAUTH:
+ msize += sizeof(unsigned int) + sizeof_string(fcall->uname)
+ + sizeof_string(fcall->aname);
+ break;
+ case RAUTH:
+ case RATTACH:
+ msize += IXP_QIDSZ;
+ break;
+ case TATTACH:
+ msize += 2 * sizeof(unsigned int) + sizeof_string(fcall->uname)
+ + sizeof_string(fcall->aname);
+ break;
+ case RERROR:
+ msize += sizeof_string(fcall->errstr);
+ break;
+ case RWRITE:
+ case TCLUNK:
+ case TREMOVE:
+ case TSTAT:
+ msize += sizeof(unsigned int);
+ break;
+ case TWALK:
+ msize += sizeof(unsigned short) + 2 * sizeof(unsigned int);
+ for(i = 0; i < fcall->nwname; i++)
+ msize += sizeof_string(fcall->wname[i]);
+ break;
+ case TFLUSH:
+ msize += sizeof(unsigned short);
+ break;
+ case RWALK:
+ msize += sizeof(unsigned short) + fcall->nwqid * IXP_QIDSZ;
+ break;
+ case TOPEN:
+ msize += sizeof(unsigned int) + sizeof(unsigned char);
+ break;
+ case ROPEN:
+ case RCREATE:
+ msize += IXP_QIDSZ + sizeof(unsigned int);
+ break;
+ case TCREATE:
+ msize += sizeof(unsigned char) + 2 * sizeof(unsigned int)
+ + sizeof_string(fcall->name);
+ break;
+ case TREAD:
+ msize += 2 * sizeof(unsigned int) + sizeof(unsigned long long);
+ break;
+ case RREAD:
+ msize += sizeof(unsigned int) + fcall->count;
+ break;
+ case TWRITE:
+ msize += 2 * sizeof(unsigned int) + sizeof(unsigned long long)
+ + fcall->count;
+ break;
+ case RSTAT:
+ msize += sizeof(unsigned short) + ixp_sizeof_stat(&fcall->stat);
+ break;
+ case TWSTAT:
+ msize += sizeof(unsigned int) + sizeof(unsigned short)
+ + ixp_sizeof_stat(&fcall->stat);
+ break;
+ default:
+ break;
+ }
- if(msize > msglen)
- return 0;
- p = ixp_enc_prefix(p, msize, fcall->id, fcall->tag);
+ if(msize > msglen)
+ return 0;
+ p = ixp_enc_prefix(p, msize, fcall->id, fcall->tag);
- switch (fcall->id) {
- case TVERSION:
- case RVERSION:
- p = ixp_enc_u32(p, fcall->maxmsg);
- p = ixp_enc_string(p, fcall->version);
- break;
- case TAUTH:
- p = ixp_enc_u32(p, fcall->afid);
- p = ixp_enc_string(p, fcall->uname);
- p = ixp_enc_string(p, fcall->aname);
- break;
- case RAUTH:
- p = ixp_enc_qid(p, &fcall->aqid);
- break;
- case RATTACH:
- p = ixp_enc_qid(p, &fcall->qid);
- break;
- case TATTACH:
- p = ixp_enc_u32(p, fcall->fid);
- p = ixp_enc_u32(p, fcall->afid);
- p = ixp_enc_string(p, fcall->uname);
- p = ixp_enc_string(p, fcall->aname);
- break;
- case RERROR:
- p = ixp_enc_string(p, fcall->errstr);
- break;
- case TFLUSH:
- p = ixp_enc_u16(p, fcall->oldtag);
- break;
- case TWALK:
- p = ixp_enc_u32(p, fcall->fid);
- p = ixp_enc_u32(p, fcall->newfid);
- p = ixp_enc_u16(p, fcall->nwname);
- for(i = 0; i < fcall->nwname; i++)
- p = ixp_enc_string(p, fcall->wname[i]);
- break;
- case RWALK:
- p = ixp_enc_u16(p, fcall->nwqid);
- for(i = 0; i < fcall->nwqid; i++)
- p = ixp_enc_qid(p, &fcall->wqid[i]);
- break;
- case TOPEN:
- p = ixp_enc_u32(p, fcall->fid);
- p = ixp_enc_u8(p, fcall->mode);
- break;
- case ROPEN:
- case RCREATE:
- p = ixp_enc_qid(p, &fcall->qid);
- p = ixp_enc_u32(p, fcall->iounit);
- break;
- case TCREATE:
- p = ixp_enc_u32(p, fcall->fid);
- p = ixp_enc_string(p, fcall->name);
- p = ixp_enc_u32(p, fcall->perm);
- p = ixp_enc_u8(p, fcall->mode);
- break;
- case TREAD:
- p = ixp_enc_u32(p, fcall->fid);
- p = ixp_enc_u64(p, fcall->offset);
- p = ixp_enc_u32(p, fcall->count);
- break;
- case RREAD:
- p = ixp_enc_u32(p, fcall->count);
- p = ixp_enc_data(p, fcall->data, fcall->count);
- break;
- case TWRITE:
- p = ixp_enc_u32(p, fcall->fid);
- p = ixp_enc_u64(p, fcall->offset);
- p = ixp_enc_u32(p, fcall->count);
- p = ixp_enc_data(p, fcall->data, fcall->count);
- break;
- case RWRITE:
- p = ixp_enc_u32(p, fcall->count);
- break;
- case TCLUNK:
- case TREMOVE:
- case TSTAT:
- p = ixp_enc_u32(p, fcall->fid);
- break;
- case RSTAT:
+ switch (fcall->id) {
+ case TVERSION:
+ case RVERSION:
+ p = ixp_enc_u32(p, fcall->maxmsg);
+ p = ixp_enc_string(p, fcall->version);
+ break;
+ case TAUTH:
+ p = ixp_enc_u32(p, fcall->afid);
+ p = ixp_enc_string(p, fcall->uname);
+ p = ixp_enc_string(p, fcall->aname);
+ break;
+ case RAUTH:
+ p = ixp_enc_qid(p, &fcall->aqid);
+ break;
+ case RATTACH:
+ p = ixp_enc_qid(p, &fcall->qid);
+ break;
+ case TATTACH:
+ p = ixp_enc_u32(p, fcall->fid);
+ p = ixp_enc_u32(p, fcall->afid);
+ p = ixp_enc_string(p, fcall->uname);
+ p = ixp_enc_string(p, fcall->aname);
+ break;
+ case RERROR:
+ p = ixp_enc_string(p, fcall->errstr);
+ break;
+ case TFLUSH:
+ p = ixp_enc_u16(p, fcall->oldtag);
+ break;
+ case TWALK:
+ p = ixp_enc_u32(p, fcall->fid);
+ p = ixp_enc_u32(p, fcall->newfid);
+ p = ixp_enc_u16(p, fcall->nwname);
+ for(i = 0; i < fcall->nwname; i++)
+ p = ixp_enc_string(p, fcall->wname[i]);
+ break;
+ case RWALK:
+ p = ixp_enc_u16(p, fcall->nwqid);
+ for(i = 0; i < fcall->nwqid; i++)
+ p = ixp_enc_qid(p, &fcall->wqid[i]);
+ break;
+ case TOPEN:
+ p = ixp_enc_u32(p, fcall->fid);
+ p = ixp_enc_u8(p, fcall->mode);
+ break;
+ case ROPEN:
+ case RCREATE:
+ p = ixp_enc_qid(p, &fcall->qid);
+ p = ixp_enc_u32(p, fcall->iounit);
+ break;
+ case TCREATE:
+ p = ixp_enc_u32(p, fcall->fid);
+ p = ixp_enc_string(p, fcall->name);
+ p = ixp_enc_u32(p, fcall->perm);
+ p = ixp_enc_u8(p, fcall->mode);
+ break;
+ case TREAD:
+ p = ixp_enc_u32(p, fcall->fid);
+ p = ixp_enc_u64(p, fcall->offset);
+ p = ixp_enc_u32(p, fcall->count);
+ break;
+ case RREAD:
+ p = ixp_enc_u32(p, fcall->count);
+ p = ixp_enc_data(p, fcall->data, fcall->count);
+ break;
+ case TWRITE:
+ p = ixp_enc_u32(p, fcall->fid);
+ p = ixp_enc_u64(p, fcall->offset);
+ p = ixp_enc_u32(p, fcall->count);
+ p = ixp_enc_data(p, fcall->data, fcall->count);
+ break;
+ case RWRITE:
+ p = ixp_enc_u32(p, fcall->count);
+ break;
+ case TCLUNK:
+ case TREMOVE:
+ case TSTAT:
+ p = ixp_enc_u32(p, fcall->fid);
+ break;
+ case RSTAT:
p = ixp_enc_u16(p, ixp_sizeof_stat(&fcall->stat));
- p = ixp_enc_stat(p, &fcall->stat);
- break;
- case TWSTAT:
- p = ixp_enc_u32(p, fcall->fid);
+ p = ixp_enc_stat(p, &fcall->stat);
+ break;
+ case TWSTAT:
+ p = ixp_enc_u32(p, fcall->fid);
p = ixp_enc_u16(p, ixp_sizeof_stat(&fcall->stat));
- p = ixp_enc_stat(p, &fcall->stat);
- break;
- }
+ p = ixp_enc_stat(p, &fcall->stat);
+ break;
+ }
if(msg + msize == p)
- return msize;
+ return msize;
return 0;
}
unsigned int
ixp_msg2fcall(Fcall *fcall, void *msg, unsigned int msglen)
{
- unsigned int i, msize;
- unsigned short len;
- void *p = ixp_dec_prefix(msg, &msize, &fcall->id, &fcall->tag);
-
- if(msize > msglen) /* bad message */
- return 0;
-
- switch (fcall->id) {
- case TVERSION:
- case RVERSION:
- p = ixp_dec_u32(p, &fcall->maxmsg);
- p = ixp_dec_string(p, fcall->version, sizeof(fcall->version), &len);
- break;
- case TAUTH:
- p = ixp_dec_u32(p, &fcall->afid);
- p = ixp_dec_string(p, fcall->uname, sizeof(fcall->uname), &len);
- p = ixp_dec_string(p, fcall->aname, sizeof(fcall->aname), &len);
- break;
- case RAUTH:
- p = ixp_dec_qid(p, &fcall->aqid);
- break;
- case RATTACH:
- p = ixp_dec_qid(p, &fcall->qid);
- break;
- case TATTACH:
- p = ixp_dec_u32(p, &fcall->fid);
- p = ixp_dec_u32(p, &fcall->afid);
- p = ixp_dec_string(p, fcall->uname, sizeof(fcall->uname), &len);
- p = ixp_dec_string(p, fcall->aname, sizeof(fcall->aname), &len);
- break;
- case RERROR:
- p = ixp_dec_string(p, fcall->errstr, sizeof(fcall->errstr), &len);
- break;
- case TFLUSH:
- p = ixp_dec_u16(p, &fcall->oldtag);
- break;
- case TWALK:
- p = ixp_dec_u32(p, &fcall->fid);
- p = ixp_dec_u32(p, &fcall->newfid);
- p = ixp_dec_u16(p, &fcall->nwname);
- for(i = 0; i < fcall->nwname; i++) {
-
- p = ixp_dec_string(p, fcall->wname[i], IXP_MAX_FLEN, &len);
- }
- break;
- case RWALK:
- p = ixp_dec_u16(p, &fcall->nwqid);
- for(i = 0; i < fcall->nwqid; i++)
- p = ixp_dec_qid(p, &fcall->wqid[i]);
- break;
- case TOPEN:
- p = ixp_dec_u32(p, &fcall->fid);
- p = ixp_dec_u8(p, &fcall->mode);
- break;
- case ROPEN:
- case RCREATE:
- p = ixp_dec_qid(p, &fcall->qid);
- p = ixp_dec_u32(p, &fcall->iounit);
- break;
- case TCREATE:
- p = ixp_dec_u32(p, &fcall->fid);
- p = ixp_dec_string(p, fcall->name, sizeof(fcall->name), &len);
- p = ixp_dec_u32(p, &fcall->perm);
- p = ixp_dec_u8(p, &fcall->mode);
- break;
- case TREAD:
- p = ixp_dec_u32(p, &fcall->fid);
- p = ixp_dec_u64(p, &fcall->offset);
- p = ixp_dec_u32(p, &fcall->count);
- break;
- case RREAD:
- p = ixp_dec_u32(p, &fcall->count);
- p = ixp_dec_data(p, fcall->data, fcall->count);
- break;
- case TWRITE:
- p = ixp_dec_u32(p, &fcall->fid);
- p = ixp_dec_u64(p, &fcall->offset);
- p = ixp_dec_u32(p, &fcall->count);
- p = ixp_dec_data(p, fcall->data, fcall->count);
- break;
- case RWRITE:
- p = ixp_dec_u32(p, &fcall->count);
- break;
- case TCLUNK:
- case TREMOVE:
- case TSTAT:
- p = ixp_dec_u32(p, &fcall->fid);
- break;
- case RSTAT:
+ unsigned int i, msize;
+ unsigned short len;
+ void *p = ixp_dec_prefix(msg, &msize, &fcall->id, &fcall->tag);
+
+ if(msize > msglen) /* bad message */
+ return 0;
+ switch (fcall->id) {
+ case TVERSION:
+ case RVERSION:
+ p = ixp_dec_u32(p, &fcall->maxmsg);
+ p = ixp_dec_string(p, fcall->version, sizeof(fcall->version), &len);
+ break;
+ case TAUTH:
+ p = ixp_dec_u32(p, &fcall->afid);
+ p = ixp_dec_string(p, fcall->uname, sizeof(fcall->uname), &len);
+ p = ixp_dec_string(p, fcall->aname, sizeof(fcall->aname), &len);
+ break;
+ case RAUTH:
+ p = ixp_dec_qid(p, &fcall->aqid);
+ break;
+ case RATTACH:
+ p = ixp_dec_qid(p, &fcall->qid);
+ break;
+ case TATTACH:
+ p = ixp_dec_u32(p, &fcall->fid);
+ p = ixp_dec_u32(p, &fcall->afid);
+ p = ixp_dec_string(p, fcall->uname, sizeof(fcall->uname), &len);
+ p = ixp_dec_string(p, fcall->aname, sizeof(fcall->aname), &len);
+ break;
+ case RERROR:
+ p = ixp_dec_string(p, fcall->errstr, sizeof(fcall->errstr), &len);
+ break;
+ case TFLUSH:
+ p = ixp_dec_u16(p, &fcall->oldtag);
+ break;
+ case TWALK:
+ p = ixp_dec_u32(p, &fcall->fid);
+ p = ixp_dec_u32(p, &fcall->newfid);
+ p = ixp_dec_u16(p, &fcall->nwname);
+ for(i = 0; i < fcall->nwname; i++)
+ p = ixp_dec_string(p, fcall->wname[i], IXP_MAX_FLEN, &len);
+ break;
+ case RWALK:
+ p = ixp_dec_u16(p, &fcall->nwqid);
+ for(i = 0; i < fcall->nwqid; i++)
+ p = ixp_dec_qid(p, &fcall->wqid[i]);
+ break;
+ case TOPEN:
+ p = ixp_dec_u32(p, &fcall->fid);
+ p = ixp_dec_u8(p, &fcall->mode);
+ break;
+ case ROPEN:
+ case RCREATE:
+ p = ixp_dec_qid(p, &fcall->qid);
+ p = ixp_dec_u32(p, &fcall->iounit);
+ break;
+ case TCREATE:
+ p = ixp_dec_u32(p, &fcall->fid);
+ p = ixp_dec_string(p, fcall->name, sizeof(fcall->name), &len);
+ p = ixp_dec_u32(p, &fcall->perm);
+ p = ixp_dec_u8(p, &fcall->mode);
+ break;
+ case TREAD:
+ p = ixp_dec_u32(p, &fcall->fid);
+ p = ixp_dec_u64(p, &fcall->offset);
+ p = ixp_dec_u32(p, &fcall->count);
+ break;
+ case RREAD:
+ p = ixp_dec_u32(p, &fcall->count);
+ p = ixp_dec_data(p, fcall->data, fcall->count);
+ break;
+ case TWRITE:
+ p = ixp_dec_u32(p, &fcall->fid);
+ p = ixp_dec_u64(p, &fcall->offset);
+ p = ixp_dec_u32(p, &fcall->count);
+ p = ixp_dec_data(p, fcall->data, fcall->count);
+ break;
+ case RWRITE:
+ p = ixp_dec_u32(p, &fcall->count);
+ break;
+ case TCLUNK:
+ case TREMOVE:
+ case TSTAT:
+ p = ixp_dec_u32(p, &fcall->fid);
+ break;
+ case RSTAT:
p = ixp_dec_u16(p, &len);
- p = ixp_dec_stat(p, &fcall->stat);
- break;
- case TWSTAT:
- p = ixp_dec_u32(p, &fcall->fid);
+ p = ixp_dec_stat(p, &fcall->stat);
+ break;
+ case TWSTAT:
+ p = ixp_dec_u32(p, &fcall->fid);
p = ixp_dec_u16(p, &len);
- p = ixp_dec_stat(p, &fcall->stat);
- break;
- }
+ p = ixp_dec_stat(p, &fcall->stat);
+ break;
+ }
if(msg + msize == p)
- return msize;
+ return msize;
return 0;
}
diff --git a/libixp/server.c b/libixp/server.c
@@ -20,7 +20,7 @@
static unsigned char *msg[IXP_MAX_MSG];
IXPConn *ixp_server_open_conn(IXPServer *s, int fd, void (*read)(IXPConn *c),
- void (*close)(IXPConn *c))
+ void (*close)(IXPConn *c))
{
IXPConn *c = cext_emallocz(sizeof(IXPConn));
c->fd = fd;
@@ -28,7 +28,7 @@ IXPConn *ixp_server_open_conn(IXPServer *s, int fd, void (*read)(IXPConn *c),
c->read = read;
c->close = close;
s->conn = (IXPConn **)cext_array_attach((void **)s->conn, c,
- sizeof(IXPConn *), &s->connsz);
+ sizeof(IXPConn *), &s->connsz);
return c;
}
@@ -51,45 +51,44 @@ ixp_server_close_conn(IXPConn *c)
static void
prepare_select(IXPServer *s)
{
- int i;
- FD_ZERO(&s->rd);
- for(i = 0; (i < s->connsz) && s->conn[i]; i++) {
- if(s->maxfd < s->conn[i]->fd)
- s->maxfd = s->conn[i]->fd;
- if(s->conn[i]->read)
- FD_SET(s->conn[i]->fd, &s->rd);
- }
+ int i;
+ FD_ZERO(&s->rd);
+ for(i = 0; (i < s->connsz) && s->conn[i]; i++) {
+ if(s->maxfd < s->conn[i]->fd)
+ s->maxfd = s->conn[i]->fd;
+ if(s->conn[i]->read)
+ FD_SET(s->conn[i]->fd, &s->rd);
+ }
}
static void
handle_conns(IXPServer *s)
{
- int i;
- for(i = 0; (i < s->connsz) && s->conn[i]; i++)
- if(FD_ISSET(s->conn[i]->fd, &s->rd) && s->conn[i]->read)
- /* call read handler */
- s->conn[i]->read(s->conn[i]);
+ int i;
+ for(i = 0; (i < s->connsz) && s->conn[i]; i++)
+ if(FD_ISSET(s->conn[i]->fd, &s->rd) && s->conn[i]->read)
+ /* call read handler */
+ s->conn[i]->read(s->conn[i]);
}
char *
ixp_server_loop(IXPServer *s)
{
- int r;
- s->running = 1;
-
- /* main loop */
- while(s->running && s->conn) {
+ int r;
+ s->running = 1;
- prepare_select(s);
+ /* main loop */
+ while(s->running && s->conn) {
+ prepare_select(s);
- r = select(s->maxfd + 1, &s->rd, 0, 0, 0);
- if(r == -1 && errno == EINTR)
- continue;
- if(r < 0)
- return "fatal select error";
- else if(r > 0)
- handle_conns(s);
- }
+ r = select(s->maxfd + 1, &s->rd, 0, 0, 0);
+ if(r == -1 && errno == EINTR)
+ continue;
+ if(r < 0)
+ return "fatal select error";
+ else if(r > 0)
+ handle_conns(s);
+ }
return nil;
}
@@ -106,14 +105,14 @@ ixp_server_fid2map(IXPConn *c, unsigned int fid)
unsigned int
ixp_server_receive_fcall(IXPConn *c, Fcall *fcall)
{
- unsigned int msize;
- char *errstr = 0;
+ unsigned int msize;
+ char *errstr = 0;
if(!(msize = ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &errstr))) {
if(c->close)
c->close(c);
return 0;
}
- return ixp_msg2fcall(fcall, msg, IXP_MAX_MSG);
+ return ixp_msg2fcall(fcall, msg, IXP_MAX_MSG);
}
int
diff --git a/libixp/socket.c b/libixp/socket.c
@@ -21,29 +21,29 @@
static int
connect_unix_sock(char *address)
{
- int fd = 0;
- struct sockaddr_un addr = { 0 };
- socklen_t su_len;
-
- /* init */
- addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, address, sizeof(addr.sun_path));
- su_len = sizeof(struct sockaddr) + strlen(addr.sun_path);
-
- if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
- return -1;
- if(connect(fd, (struct sockaddr *) &addr, su_len)) {
- close(fd);
- return -1;
- }
- return fd;
+ int fd = 0;
+ struct sockaddr_un addr = { 0 };
+ socklen_t su_len;
+
+ /* init */
+ addr.sun_family = AF_UNIX;
+ strncpy(addr.sun_path, address, sizeof(addr.sun_path));
+ su_len = sizeof(struct sockaddr) + strlen(addr.sun_path);
+
+ if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ return -1;
+ if(connect(fd, (struct sockaddr *) &addr, su_len)) {
+ close(fd);
+ return -1;
+ }
+ return fd;
}
static int
connect_inet_sock(char *host)
{
- int fd = 0;
- struct sockaddr_in addr = { 0 };
+ int fd = 0;
+ struct sockaddr_in addr = { 0 };
struct hostent *hp;
char *port = strrchr(host, '!');
const char *errstr = nil;
@@ -55,19 +55,19 @@ connect_inet_sock(char *host)
if(errstr)
return -1;
- /* init */
- if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- return -1;
+ /* init */
+ if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ return -1;
hp = gethostbyname(host);
- addr.sin_family = AF_INET;
+ addr.sin_family = AF_INET;
addr.sin_port = htons(prt);
bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
- if(connect(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
- close(fd);
- return -1;
- }
- return fd;
+ if(connect(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
+ close(fd);
+ return -1;
+ }
+ return fd;
}
int
@@ -79,7 +79,7 @@ ixp_connect_sock(char *address)
if(!p)
return -1;
*p = 0;
-
+
addr = &p[1];
type = address; /* unix, inet */
@@ -87,23 +87,23 @@ ixp_connect_sock(char *address)
return connect_unix_sock(addr);
else if(!strncmp(type, "tcp", 4))
return connect_inet_sock(addr);
- return -1;
+ return -1;
}
int
ixp_accept_sock(int fd)
{
- socklen_t su_len;
- struct sockaddr_un addr = { 0 };
+ socklen_t su_len;
+ struct sockaddr_un addr = { 0 };
- su_len = sizeof(struct sockaddr);
- return accept(fd, (struct sockaddr *) &addr, &su_len);
+ su_len = sizeof(struct sockaddr);
+ return accept(fd, (struct sockaddr *) &addr, &su_len);
}
static int
create_inet_sock(char *host, char **errstr)
{
- int fd;
+ int fd;
struct sockaddr_in addr = { 0 };
char *port = strrchr(host, '!');
unsigned int prt;
@@ -117,66 +117,66 @@ create_inet_sock(char *host, char **errstr)
prt = cext_strtonum(port, 1024, 65535, (const char **)errstr);
if(*errstr)
return -1;
- signal(SIGPIPE, SIG_IGN);
- if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- *errstr = "cannot open socket";
- return -1;
- }
- addr.sin_family = AF_INET;
+ signal(SIGPIPE, SIG_IGN);
+ if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ *errstr = "cannot open socket";
+ return -1;
+ }
+ addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(prt);
- if(bind(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) < 0) {
- *errstr = "cannot bind socket";
- close(fd);
- return -1;
- }
-
- if(listen(fd, IXP_MAX_CACHE) < 0) {
- *errstr = "cannot listen on socket";
- close(fd);
- return -1;
- }
- return fd;
+ if(bind(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) < 0) {
+ *errstr = "cannot bind socket";
+ close(fd);
+ return -1;
+ }
+
+ if(listen(fd, IXP_MAX_CACHE) < 0) {
+ *errstr = "cannot listen on socket";
+ close(fd);
+ return -1;
+ }
+ return fd;
}
static int
create_unix_sock(char *file, char **errstr)
{
- int fd;
- int yes = 1;
- struct sockaddr_un addr = { 0 };
- socklen_t su_len;
-
- signal(SIGPIPE, SIG_IGN);
- if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- *errstr = "cannot open socket";
- return -1;
- }
- if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
- (char *) &yes, sizeof(yes)) < 0) {
- *errstr = "cannot set socket options";
- close(fd);
- return -1;
- }
- addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, file, sizeof(addr.sun_path));
- su_len = sizeof(struct sockaddr) + strlen(addr.sun_path);
+ int fd;
+ int yes = 1;
+ struct sockaddr_un addr = { 0 };
+ socklen_t su_len;
+
+ signal(SIGPIPE, SIG_IGN);
+ if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ *errstr = "cannot open socket";
+ return -1;
+ }
+ if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &yes, sizeof(yes)) < 0) {
+ *errstr = "cannot set socket options";
+ close(fd);
+ return -1;
+ }
+ addr.sun_family = AF_UNIX;
+ strncpy(addr.sun_path, file, sizeof(addr.sun_path));
+ su_len = sizeof(struct sockaddr) + strlen(addr.sun_path);
unlink(file); /* remove old socket, if any */
- if(bind(fd, (struct sockaddr *) &addr, su_len) < 0) {
- *errstr = "cannot bind socket";
- close(fd);
- return -1;
- }
- chmod(file, S_IRWXU);
-
- if(listen(fd, IXP_MAX_CACHE) < 0) {
- *errstr = "cannot listen on socket";
- close(fd);
- return -1;
- }
- return fd;
+ if(bind(fd, (struct sockaddr *) &addr, su_len) < 0) {
+ *errstr = "cannot bind socket";
+ close(fd);
+ return -1;
+ }
+ chmod(file, S_IRWXU);
+
+ if(listen(fd, IXP_MAX_CACHE) < 0) {
+ *errstr = "cannot listen on socket";
+ close(fd);
+ return -1;
+ }
+ return fd;
}
int
@@ -190,7 +190,7 @@ ixp_create_sock(char *address, char **errstr)
return -1;
}
*p = 0;
-
+
addr = &p[1];
type = address; /* unix, inet */
@@ -200,5 +200,5 @@ ixp_create_sock(char *address, char **errstr)
return create_inet_sock(addr, errstr);
else
*errstr = "unkown socket type";
- return -1;
+ return -1;
}
diff --git a/libixp/transport.c b/libixp/transport.c
@@ -20,62 +20,61 @@
unsigned int
ixp_send_message(int fd, void *msg, unsigned int msize, char **errstr)
{
- unsigned int num = 0;
- int r;
+ unsigned int num = 0;
+ int r;
- /* send message */
- while(num < msize) {
- r = write(fd, msg + num, msize - num);
- if(r == -1 && errno == EINTR)
- continue;
- if(r < 1) {
- *errstr = "broken pipe";
- return 0;
- }
- num += r;
- }
- return num;
+ /* send message */
+ while(num < msize) {
+ r = write(fd, msg + num, msize - num);
+ if(r == -1 && errno == EINTR)
+ continue;
+ if(r < 1) {
+ *errstr = "broken pipe";
+ return 0;
+ }
+ num += r;
+ }
+ return num;
}
static unsigned int
ixp_recv_data(int fd, void *msg, unsigned int msize, char **errstr)
{
- unsigned int num = 0;
- int r = 0;
+ unsigned int num = 0;
+ int r = 0;
- /* receive data */
- while(num < msize) {
- r = read(fd, msg + num, msize - num);
- if(r == -1 && errno == EINTR)
- continue;
- if(r < 1) {
- *errstr = "broken pipe";
- return 0;
- }
- num += r;
- }
- return num;
+ /* receive data */
+ while(num < msize) {
+ r = read(fd, msg + num, msize - num);
+ if(r == -1 && errno == EINTR)
+ continue;
+ if(r < 1) {
+ *errstr = "broken pipe";
+ return 0;
+ }
+ num += r;
+ }
+ return num;
}
unsigned int
ixp_recv_message(int fd, void *msg, unsigned int msglen, char **errstr)
{
- unsigned int msize;
+ unsigned int msize;
- /* receive header */
- if(ixp_recv_data(fd, msg, sizeof(unsigned int), errstr) !=
- sizeof(unsigned int))
- return 0;
- ixp_dec_u32(msg, &msize);
- if(msize > msglen) {
- *errstr = "invalid message header";
- return 0;
- }
- /* receive message */
- if(ixp_recv_data
- (fd, msg + sizeof(unsigned int), msize - sizeof(unsigned int),
- errstr)
- != msize - sizeof(unsigned int))
- return 0;
- return msize;
+ /* receive header */
+ if(ixp_recv_data(fd, msg, sizeof(unsigned int), errstr) !=
+ sizeof(unsigned int))
+ return 0;
+ ixp_dec_u32(msg, &msize);
+ if(msize > msglen) {
+ *errstr = "invalid message header";
+ return 0;
+ }
+ /* receive message */
+ if(ixp_recv_data(fd, msg + sizeof(unsigned int),
+ msize - sizeof(unsigned int), errstr)
+ != msize - sizeof(unsigned int))
+ return 0;
+ return msize;
}