summaryrefslogtreecommitdiff
path: root/package/aboot/src/fs/dummy.c
blob: 82d73d44103958fe9b8b66aec0d0486a30e12253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * This is a set of functions that provides access to a Linux kernel
 * starting at sector BOOT_SECT+aboot_size/SECT_SIZE
 *
 * Michael Schwingen (rincewind@discworld.oche.de).
 */
#include "system.h"

#include <config.h>
#include <aboot.h>
#include <bootfs.h>
#include <cons.h>
#include <utils.h>

#define BLOCKSIZE (16*SECT_SIZE)

static int dummy_mount(long cons_dev, long p_offset, long quiet);
static int dummy_bread(int fd, long blkno, long nblks, char *buffer);
static int dummy_open(const char *filename);
static void dummy_close(int fd);

struct bootfs dummyfs = {
	0, BLOCKSIZE,
	dummy_mount,
	dummy_open,  dummy_bread,  dummy_close
};

static long dev = -1;


/*
 * Initialize 'filesystem' 
 * Returns 0 if successful, -1 on failure.
 */
static int
dummy_mount(long cons_dev, long p_offset, long quiet)
{
	dev = cons_dev;
	return 0;
}


/*
 * Read block number "blkno".
 */
static int
dummy_bread(int fd, long blkno, long nblks, char *buffer)
{
	extern char _end;
	static long aboot_size = 0;

	if (!aboot_size) {
		aboot_size = &_end - (char *) BOOT_ADDR + SECT_SIZE - 1;
		aboot_size &= ~(SECT_SIZE - 1);
	}

	if (cons_read(dev, buffer, nblks*BLOCKSIZE, 
		      BOOT_SECTOR*SECT_SIZE + blkno*BLOCKSIZE + aboot_size)
	    != nblks*BLOCKSIZE)
	{
		printf("dummy_bread: read error\n");
		return -1;
	}
	return nblks*BLOCKSIZE;
}


/*
 * Unix-like open routine.  Returns a small integer 
 * (does not care what file, we say it's OK)
 */
static int dummy_open(const char *filename)
{
	return 1;
}


static void dummy_close(int fd)
{
}