pang-io: rework api for memory-mapped io
On real hardwareit will use memory-mapped io. Rework pang-io so that it more closely aligns with this paradigm. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
		@@ -7,21 +7,22 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "fat12.h"
 | 
			
		||||
#include "io.h"
 | 
			
		||||
 | 
			
		||||
static int make_image(const char *name, uint32_t size) {
 | 
			
		||||
 | 
			
		||||
    int fd = open(name, O_WRONLY | O_CREAT, 0777);
 | 
			
		||||
    if (-1 == fd) {
 | 
			
		||||
    struct pang_io *io = pang_open(name);
 | 
			
		||||
    if (!io) {
 | 
			
		||||
        fprintf(stderr, "couldn't open %s: %s\n", name, strerror(errno));
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (-1 == fat12_mkfs(fd, size)) {
 | 
			
		||||
    if (-1 == fat12_mkfs(io, size)) {
 | 
			
		||||
        fprintf(stderr, "couldn't make fat12 on %s: %s\n", name, strerror(errno));
 | 
			
		||||
        close(fd);
 | 
			
		||||
        pang_close(&io);
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    close(fd);
 | 
			
		||||
    pang_close(&io);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,21 +7,22 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "fat12.h"
 | 
			
		||||
#include "io.h"
 | 
			
		||||
 | 
			
		||||
static int make_image(const char *name, uint32_t size) {
 | 
			
		||||
 | 
			
		||||
    int fd = open(name, O_WRONLY | O_CREAT, 0777);
 | 
			
		||||
    if (-1 == fd) {
 | 
			
		||||
    struct pang_io *io = pang_open(name);
 | 
			
		||||
    if (!io) {
 | 
			
		||||
        fprintf(stderr, "couldn't open %s: %s\n", name, strerror(errno));
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (-1 == fat12_mkfs(fd, size)) {
 | 
			
		||||
    if (-1 == fat12_mkfs(io, size)) {
 | 
			
		||||
        fprintf(stderr, "couldn't make fat12 on %s: %s\n", name, strerror(errno));
 | 
			
		||||
        close(fd);
 | 
			
		||||
        pang_close(&io);
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    close(fd);
 | 
			
		||||
    pang_close(&io);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user