File: disk.c

package info (click to toggle)
quik 2.1-9.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 772 kB
  • ctags: 969
  • sloc: ansic: 3,813; asm: 524; makefile: 105; perl: 74; sh: 43
file content (91 lines) | stat: -rw-r--r-- 1,877 bytes parent folder | download | duplicates (3)
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
81
82
83
84
85
86
87
88
89
90
91
#include "quik.h"
#include "prom.h"

char bootdevice[512];
static char current_devname[512];
static ihandle current_dev;

int open(char *device)
{
    current_dev = call_prom("open", 1, 1, device);
    if (current_dev == (ihandle) 0 || current_dev == (ihandle) -1) {
	qprintf("\nCouldn't open %s\n", device);
	return -1;
    }
    strcpy(current_devname, device);
    return 0;
}

char * strstr(const char * s1,const char * s2)
{
	int l1, l2;

	l2 = qstrlen(s2);
	if (!l2)
		return (char *) s1;
	l1 = qstrlen(s1);
	while (l1 >= l2) {
		l1--;
		if (!memcmp(s1,s2,l2))
			return (char *) s1;
		s1++;
	}
	return NULL;
}

int diskinit()
{
    char *p;
    extern unsigned int is_chrp;

    prom_get_chosen("bootpath", bootdevice, sizeof(bootdevice));
    if (bootdevice[0] == 0) {
	prom_get_options("boot-device", bootdevice, sizeof(bootdevice));
	if (bootdevice[0] == 0)
	    fatal("Couldn't determine boot device");
    }
    p = strchr(bootdevice, ':');
    if (p != 0)
	*p = 0;
    /*
     * Hack for the time being.  We need at the raw disk device, not
     * just a few partitions. -- Cort
     */
    if ( is_chrp )
	    qsprintf(bootdevice, "disk:0");
    if( open(bootdevice) )
    {
	    /*
	     * Some chrp machines do not have a 'disk' alias so
	     * try this if disk:0 fails
	     *   -- Cort
	     */
	    qsprintf(bootdevice, "/pci@fee00000/scsi@c/sd@8:0");
	    return open(bootdevice);
    }
    return 0;
}

int read(char *buf, int nbytes, long long offset)
{
    int nr;

    if (nbytes == 0)
	return 0;
    nr = (int)call_prom("seek", 3, 1, current_dev, (unsigned int) (offset >> 32),
	      (unsigned int) (offset & 0xFFFFFFFF));
    nr = (int) call_prom("read", 3, 1, current_dev, buf, nbytes);
    return nr;
}

void close()
{
}

int setdisk(char *device)
{
    if (strcmp(device, current_devname) == 0)
	return 0;
    close();
    return open(device);
}