2015-12-22 12:55:44 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the UCB release of Plan 9. It is subject to the license
|
|
|
|
* terms in the LICENSE file found in the top-level directory of this
|
|
|
|
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
|
|
|
|
* part of the UCB release of Plan 9, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms contained
|
|
|
|
* in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <u.h>
|
2017-04-19 23:33:14 +02:00
|
|
|
#include <lib9.h>
|
2016-12-01 00:09:42 +01:00
|
|
|
#include <9P2000.h>
|
2015-12-22 12:55:44 +01:00
|
|
|
|
|
|
|
int
|
2016-11-25 17:18:40 +01:00
|
|
|
read9pmsg(int fd, void *abuf, uint32_t n)
|
2015-12-22 12:55:44 +01:00
|
|
|
{
|
|
|
|
int m, len;
|
|
|
|
uint8_t *buf;
|
|
|
|
|
|
|
|
buf = abuf;
|
|
|
|
|
|
|
|
/* read count */
|
|
|
|
m = readn(fd, buf, BIT32SZ);
|
|
|
|
if(m != BIT32SZ){
|
|
|
|
if(m < 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = GBIT32(buf);
|
|
|
|
if(len <= BIT32SZ || len > n){
|
|
|
|
werrstr("bad length in 9P2000 message header");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
len -= BIT32SZ;
|
|
|
|
m = readn(fd, buf+BIT32SZ, len);
|
|
|
|
if(m < len)
|
|
|
|
return 0;
|
|
|
|
return BIT32SZ+m;
|
|
|
|
}
|