Moving ABUSE closer to a working prototype.

This commit is contained in:
Adam Cozzette 2011-09-20 13:37:47 -07:00
parent 87d88effec
commit 32dd49fb46
3 changed files with 25 additions and 10 deletions

View File

@ -13,7 +13,7 @@
#include "abuse.h"
int abuse_main(int argc, char *argv[], struct abuse_operations *aop)
int abuse_main(int argc, char *argv[], const struct abuse_operations *aop, void *userdata)
{
int sp[2];
int nbd, sk, err, tmp_fd;
@ -25,6 +25,8 @@ int abuse_main(int argc, char *argv[], struct abuse_operations *aop)
struct nbd_reply reply;
void *chunk;
(void) userdata;
assert(argc == 2);
dev_file = argv[1];
@ -73,16 +75,17 @@ int abuse_main(int argc, char *argv[], struct abuse_operations *aop)
/* FIXME: these might need conversion from the network byte order. */
len = ntohl(request.len);
from = request.from;
(void) from;
assert(request.magic == htonl(NBD_REQUEST_MAGIC));
switch(ntohl(request.type)) {
case NBD_CMD_READ:
chunk = malloc(len + sizeof(struct nbd_reply));
memset((char *)chunk + sizeof(struct nbd_reply), 0, len);
aop->read((char *)chunk + sizeof(struct nbd_reply), len, from);
memcpy(chunk, &reply, sizeof(struct nbd_reply));
bytes_written = write(sk, chunk, len + sizeof(struct nbd_reply));
fprintf(stderr, "Wrote %d bytes.\n", bytes_written);
assert(bytes_written == len + sizeof(struct nbd_reply));
/* assert(bytes_written == len + sizeof(struct nbd_reply)); */
free(chunk);
break;
/* We'll not worry about the other cases for now. */

View File

@ -4,8 +4,8 @@
#include <sys/types.h>
struct abuse_operations {
void (*read)();
void (*write)();
int (*read)(void *buf, u_int32_t len, u_int64_t offset);
int (*write)(const void *buf, u_int32_t len, u_int64_t offset);
void (*disc)();
void (*flush)();
void (*trim)();
@ -13,6 +13,6 @@ struct abuse_operations {
u_int64_t size;
};
int abuse_main(int argc, char *argv[], struct abuse_operations *aop);
int abuse_main(int argc, char *argv[], const struct abuse_operations *aop, void *userdata);
#endif /* ABUSE_H_INCLUDED */

View File

@ -1,11 +1,23 @@
#include <stdlib.h>
#include <string.h>
#include "abuse.h"
static int xmp_read(void *buf, u_int32_t len, u_int64_t offset)
{
(void) offset;
memset(buf, 0, len);
return 0;
}
static struct abuse_operations aop = {
.read = xmp_read,
.size = 1024,
};
int main(int argc, char *argv[])
{
struct abuse_operations aop;
aop.size = 1024;
return abuse_main(argc, argv, &aop);
return abuse_main(argc, argv, &aop, NULL);
}