Cleaned up the README. Copied some constants and struct definitions to buse.h so
that the code doesn't rely on a hard-coded location of nbd.h.
This commit is contained in:
parent
d1704eb381
commit
e49ded9330
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ OBJS := $(TARGET:=.o) $(LIBOBJS)
|
|||
STATIC_LIB := libbuse.a
|
||||
|
||||
CC := /usr/bin/gcc
|
||||
CFLAGS := -g -pedantic -Wall -Wextra -std=c99 -I$(HOME)/src/nbd
|
||||
CFLAGS := -g -pedantic -Wall -Wextra -std=c99
|
||||
LDFLAGS := -L. -lbuse
|
||||
|
||||
.PHONY: all clean
|
||||
|
|
16
README
16
README
|
@ -1,14 +1,12 @@
|
|||
BUSE - A block device in user space
|
||||
BUSE - A block device in userspace
|
||||
|
||||
Adam Cozzette
|
||||
Fall 2011
|
||||
|
||||
This piece of code was inspired by FUSE, which allows the development of Linux
|
||||
file systems that run in user space. The goal of BUSE is to allow virtual block
|
||||
devices to run in user space as well.
|
||||
|
||||
Currently BUSE is a work in progress and the existing code is hacked together.
|
||||
Soon I hope to finish implementing everything robustly.
|
||||
This piece of software was inspired by FUSE, which allows the development of
|
||||
Linux file systems that run in userspace. The goal of BUSE is to allow virtual
|
||||
block devices to run in userspace as well. Currently BUSE is experimental and
|
||||
should not be used for production code.
|
||||
|
||||
Implementing a block device with BUSE is fairly straightforward. Simply fill
|
||||
struct buse_operations (declared in buse.h) with function pointers that define
|
||||
|
@ -19,5 +17,5 @@ struct. busexmp.c is a simple example example that shows how this is done.
|
|||
The implementation of BUSE itself relies on NBD, the Linux network block device,
|
||||
which allows a remote machine to serve requests for reads and writes to a
|
||||
virtual block device on the local machine. BUSE sets up an NBD server and client
|
||||
on the same machine, with the server running executing the code defined by the
|
||||
BUSE user.
|
||||
on the same machine, with the server executing the code defined by the BUSE
|
||||
user.
|
||||
|
|
1
buse.c
1
buse.c
|
@ -2,7 +2,6 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/types.h>
|
||||
#include <nbd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
49
buse.h
49
buse.h
|
@ -1,8 +1,57 @@
|
|||
#ifndef BUSE_H_INCLUDED
|
||||
#define BUSE_H_INCLUDED
|
||||
|
||||
/* Most of this file was copied from nbd.h in the nbd distribution. */
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define NBD_SET_SOCK _IO( 0xab, 0 )
|
||||
#define NBD_SET_BLKSIZE _IO( 0xab, 1 )
|
||||
#define NBD_SET_SIZE _IO( 0xab, 2 )
|
||||
#define NBD_DO_IT _IO( 0xab, 3 )
|
||||
#define NBD_CLEAR_SOCK _IO( 0xab, 4 )
|
||||
#define NBD_CLEAR_QUE _IO( 0xab, 5 )
|
||||
#define NBD_PRINT_DEBUG _IO( 0xab, 6 )
|
||||
#define NBD_SET_SIZE_BLOCKS _IO( 0xab, 7 )
|
||||
#define NBD_DISCONNECT _IO( 0xab, 8 )
|
||||
#define NBD_SET_TIMEOUT _IO( 0xab, 9 )
|
||||
#define NBD_SET_FLAGS _IO( 0xab, 10 )
|
||||
|
||||
enum {
|
||||
NBD_CMD_READ = 0,
|
||||
NBD_CMD_WRITE = 1,
|
||||
NBD_CMD_DISC = 2,
|
||||
NBD_CMD_FLUSH = 3,
|
||||
NBD_CMD_TRIM = 4
|
||||
};
|
||||
|
||||
/* Magic numbers */
|
||||
#define NBD_REQUEST_MAGIC 0x25609513
|
||||
#define NBD_REPLY_MAGIC 0x67446698
|
||||
|
||||
/*
|
||||
* This is the packet used for communication between client and
|
||||
* server. All data are in network byte order.
|
||||
*/
|
||||
struct nbd_request {
|
||||
__be32 magic;
|
||||
__be32 type; /* == READ || == WRITE */
|
||||
char handle[8];
|
||||
__be64 from;
|
||||
__be32 len;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/*
|
||||
* This is the reply packet that nbd-server sends back to the client after
|
||||
* it has completed an I/O request (or an error occurs).
|
||||
*/
|
||||
struct nbd_reply {
|
||||
__be32 magic;
|
||||
__be32 error; /* 0 = ok, else error */
|
||||
char handle[8]; /* handle you got from request */
|
||||
};
|
||||
|
||||
struct buse_operations {
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue