Преглед на файлове

GPXE code cleanup and purge.

tags/v0.9.3
Michael Brown преди 18 години
родител
ревизия
a2b15fd1fe
променени са 52 файла, в които са добавени 0 реда и са изтрити 16693 реда
  1. 0
    68
      src/filo/Config
  2. 0
    125
      src/filo/README.filo
  3. 0
    48
      src/filo/README.filo_in_etherboot
  4. 0
    15
      src/filo/README.usb
  5. 0
    1129
      src/filo/drivers/ide_x.c
  6. 0
    383
      src/filo/fs/blockdev.c
  7. 0
    147
      src/filo/fs/eltorito.c
  8. 0
    100
      src/filo/fs/fat.h
  9. 0
    233
      src/filo/fs/filesys.h
  10. 0
    779
      src/filo/fs/fsys_ext2fs.c
  11. 0
    494
      src/filo/fs/fsys_fat.c
  12. 0
    348
      src/filo/fs/fsys_iso9660.c
  13. 0
    403
      src/filo/fs/fsys_jfs.c
  14. 0
    534
      src/filo/fs/fsys_minix.c
  15. 0
    1239
      src/filo/fs/fsys_reiserfs.c
  16. 0
    624
      src/filo/fs/fsys_xfs.c
  17. 0
    168
      src/filo/fs/iso9660.h
  18. 0
    601
      src/filo/fs/jfs.h
  19. 0
    1
      src/filo/fs/shared.h
  20. 0
    193
      src/filo/fs/vfs.c
  21. 0
    546
      src/filo/fs/xfs.h
  22. 0
    125
      src/filo/i386/context.c
  23. 0
    50
      src/filo/i386/context.h
  24. 0
    629
      src/filo/i386/linux_load.c
  25. 0
    129
      src/filo/i386/multiboot.c
  26. 0
    48
      src/filo/i386/segment.c
  27. 0
    29
      src/filo/i386/segment.h
  28. 0
    116
      src/filo/i386/switch.S
  29. 0
    29
      src/filo/i386/sys_info.c
  30. 0
    74
      src/filo/main/console_x.c
  31. 0
    398
      src/filo/main/elfload.c
  32. 0
    153
      src/filo/main/elfnote.c
  33. 0
    129
      src/filo/main/filo_x.c
  34. 0
    56
      src/filo/main/lib.c
  35. 0
    124
      src/filo/main/linuxbios_x.c
  36. 0
    45
      src/filo/main/malloc_x.c
  37. 0
    124
      src/filo/main/pci_x.c
  38. 0
    400
      src/filo/main/printf_x.c
  39. 0
    433
      src/filo/usb/debug_x.c
  40. 0
    18
      src/filo/usb/debug_x.h
  41. 0
    1437
      src/filo/usb/ohci.c
  42. 0
    316
      src/filo/usb/ohci.h
  43. 0
    226
      src/filo/usb/scsi.h
  44. 0
    512
      src/filo/usb/scsi_cmds.c
  45. 0
    14
      src/filo/usb/scsi_cmds.h
  46. 0
    1143
      src/filo/usb/uhci.c
  47. 0
    175
      src/filo/usb/uhci.h
  48. 0
    803
      src/filo/usb/usb.c
  49. 0
    435
      src/filo/usb/usb.h
  50. 0
    172
      src/filo/usb/usb_scsi_low.c
  51. 0
    10
      src/filo/usb/usb_scsi_low.h
  52. 0
    163
      src/filo/usb/usb_x.c

+ 0
- 68
src/filo/Config Целия файл

@@ -1,68 +0,0 @@
1
-# !!! NOTE !!!
2
-# Do NOT add spaces or comments at the end of option lines.
3
-# It confuses some versions of make.
4
-
5
-# Image filename for automatic boot and optional command line parameter
6
-#AUTOBOOT_FILE = "hda3:/boot/vmlinuz root=/dev/hda3 console=tty0 console=ttyS0,115200"
7
-AUTOBOOT_FILE = "hda2:/boot/vmlinuz initrd=/boot/initrd pci=noacpi ro root=/dev/hda2 console=tty0 console=ttyS0,115200"
8
-#AUTOBOOT_FILE = "mem@0xfff80000"
9
-#AUTOBOOT_FILE = "hde1@0"
10
-#AUTOBOOT_FILE = "uda1:/ram0_2.5_2.6.5_k8.2_mydisk7.elf"
11
-#AUTOBOOT_FILE = "hda5:/boot/vmlinuz initrd=/boot/initrd ro root=/dev/hda7 console=tty0 console=ttyS0,115200"
12
-
13
-# Time in second before booting AUTOBOOT_FILE
14
-AUTOBOOT_DELAY = 2
15
-
16
-# Driver for hard disk, CompactFlash, and CD-ROM on IDE bus
17
-IDE_DISK = 1
18
-
19
-# Driver for USB disk 
20
-USB_DISK = 1
21
-
22
-# Filesystems
23
-# To make filo.zelf < 32 k, You may not enable JFS, MINIX, XFS
24
-# Is anyone still using these file system? BY LYH
25
-FSYS_EXT2FS = 1
26
-FSYS_FAT = 1
27
-#FSYS_JFS = 1
28
-#FSYS_MINIX = 1
29
-FSYS_REISERFS = 1
30
-#FSYS_XFS = 1
31
-FSYS_ISO9660 = 1
32
-
33
-# Support for boot disk image in bootable CD-ROM (El Torito)
34
-ELTORITO = 1
35
-
36
-# PCI support
37
-SUPPORT_PCI = 1
38
-
39
-
40
-# Debugging
41
-#DEBUG_ALL = 1
42
-#DEBUG_ELFBOOT = 1
43
-#DEBUG_ELFNOTE = 1
44
-#DEBUG_LINUXBIOS = 1
45
-#DEBUG_MALLOC = 1
46
-#DEBUG_MULTIBOOT = 1
47
-#DEBUG_SEGMENT = 1
48
-#DEBUG_SYS_INFO = 1
49
-#DEBUG_TIMER = 1
50
-#DEBUG_BLOCKDEV = 1
51
-#DEBUG_PCI = 1
52
-#DEBUG_LINUXLOAD = 1
53
-#DEBUG_IDE = 1
54
-#DEBUG_USB = 1
55
-#DEBUG_ELTORITO = 1
56
-
57
-# i386 options
58
-
59
-# Loader for standard Linux kernel image, a.k.a. /vmlinuz
60
-LINUX_LOADER = 1
61
-
62
-# Boot FILO from Multiboot loader (eg. GRUB)
63
-# You need to modify i386/multiboot.c to use it. change mmrange to e820entries.
64
-# By LYH
65
-#MULTIBOOT_IMAGE = 1
66
-
67
-# Use PCI Configuration Mechanism #1 (most boards)
68
-PCI_CONFIG_1 = 1

+ 0
- 125
src/filo/README.filo Целия файл

@@ -1,125 +0,0 @@
1
-This is FILO, a bootloader which loads boot images from local filesystem,
2
-without help from legacy BIOS services.
3
-
4
-Expected usage is to flash it into the BIOS ROM together with LinuxBIOS.
5
-
6
-FEATURES
7
-
8
-    - Supported boot devices: IDE hard disk and CD-ROM, and system memory (ROM)
9
-    - Supported filesystems: ext2, fat, jfs, minix, reiserfs, xfs, and iso9660
10
-    - Supported image formats: ELF and [b]zImage (a.k.a. /vmlinuz)
11
-    - Supports boot disk image of El Torito bootable CD-ROM
12
-    - Supports loading image from raw device with user-specified offset
13
-    - Console on VGA + keyboard, serial port, or both
14
-    - Line editing with ^H, ^W and ^U keys to type arbitrary filename to boot
15
-    - Full support for the ELF Boot Proposal (where is it btw, Eric?)
16
-    - Auxiliary tool to compute checksum of ELF boot images
17
-    - Full 32-bit code, no BIOS calls
18
-
19
-REQUIREMENT
20
-
21
-    Only i386 PC architecture is currently supported.
22
-
23
-    x86-64 (AMD 64) machines in 32-bit mode should also work.
24
-    (It looks like LinuxBIOS uses 32-bit mode and Linux kernel does
25
-    the transition to 64-bit mode)
26
-
27
-    I'm using a VIA EPIA 5000 mini-ITX board, with a 2.5" IDE hard disk
28
-    and a 32x CD-RW, for testing, and Bochs and VMware for development.
29
-
30
-    Recent version of GNU toolchain is required to build.
31
-    I have tested with Debian/woody (gcc 2.95.4, binutils 2.12.90.0.1,
32
-    make 3.79.1) and Debian/sid (gcc 3.3.2, binutils 2.14.90.0.6,
33
-    make 3.80).
34
-
35
-INSTALL
36
-
37
-    First invocation of make creates the default Config file.
38
-	$ make
39
-    Edit this file as you like. It's fairly straightforward (I hope).
40
-	$ vi Config
41
-    Then running make again will build filo.elf, the ELF boot image of FILO.
42
-	$ make
43
-
44
-    Use filo.elf as your payload of LinuxBIOS, or a boot image for
45
-    Etherboot.
46
-
47
-    If you enable MULTIBOOT_IMAGE option in Config, you can
48
-    also boot filo.elf from GNU GRUB or other Multiboot bootloader.
49
-    This feature is intended for testing or development purpose.
50
-
51
-USING
52
-
53
-    When FILO starts, it displays "boot:" prompt.
54
-    At "boot:" prompt, type the name of your boot image, and optionally
55
-    the kernel parameter, in the form:
56
-	DEVICE:FILENAME[ PARAM]
57
-    for example:
58
-	boot: hda1:/vmlinuz root=/dev/hda1
59
-
60
-    Notation of DEVICE for IDE disk and CD-ROM is same as in Linux
61
-    (eg. hda1 means the first partition of master device on primary 
62
-    IDE channel).
63
-
64
-    FILENAME can be standard bzImage/zImage (vmlinuz) Linux kernels,
65
-    Linux-compatible images such as memtest.bin of Memtest86,
66
-    and any bootable ELF images, which include Linux kernel converted
67
-    by mkelfImage, Etherboot .elf and .zelf, Memtest86, FILO itself, etc.
68
-
69
-    If AUTOBOOT_FILE is set in Config, FILO tries to boot this file
70
-    first, and falls back to boot: prompt if it fails.
71
-
72
-    If AUTOBOOT_DELAY is also set, FILO waits for specified time in
73
-    seconds before booting AUTOBOOT_FILE. If <Esc> key is pressed
74
-    during this time period, automatic boot is canceled.
75
-    Pressing <Enter> key also cancels the delay, but in this case
76
-    AUTOBOOT_FILE is booted immediately.
77
-
78
-    Even if AUTOBOOT_DELAY is not set, automatic boot can be disabled
79
-    by pressing <Esc> key beforehand.
80
-
81
-    FILO can also load separate initrd images along with vmlinuz
82
-    kernels. (For ELF kernel, initrd images are embedded into the
83
-    ELF file and cannot be altered).
84
-    To do so, add "initrd=NAME" parameter to the kernel command line.
85
-    NAME uses the same notation as kernel image name.
86
-    (eg. boot: hda1:/vmlinuz initrd=hda1:/root.gz root=/dev/ram)
87
-
88
-    To boot an image in the BIOS flash (or whatever is mapped in the system
89
-    memory space), use the notation "mem@OFFSET[,LENGTH]", like:
90
-	boot: mem@0xfffe0000
91
-    In this example, it loads the boot image from the last 128KB of BIOS
92
-    flash.
93
-
94
-    The same notation can be used with IDE devices, eg:
95
-	boot: hda@512,697344 initrd=hda@1M,4M
96
-    In this case the 697344 bytes starting from second sector of IDE drive
97
-    is loaded as kernel, and 4M bytes of offset 1M bytes of the same disk
98
-    is loaded as initrd.
99
-    Note that when you load vmlinuz kernel or initrd this way,
100
-    you must specify the LENGTH parameter. You can omit it for ELF
101
-    images since they have segment length internally.
102
-    OFFSET and LENGTH parameters must be multiple of 512.
103
-
104
-BUG REPORTING
105
-
106
-    If you have problem with FILO, set DEBUG_ALL in Config and send its 
107
-    console output to me at <ts1@tsn.or.jp>.
108
-
109
-ACKNOWLEDGEMENTS
110
-
111
-    Filesystem code is taken from GNU GRUB and patches for it.
112
-    IDE driver is originally taken from Etherboot.
113
-    Steve Gehlbach wrote the original bzImage loader for FILO.
114
-
115
-    Besides, I have taken pieces of code and/or learned concepts
116
-    from various standalone programs, including GNU GRUB, Etherboot,
117
-    polled IDE patch by Adam Agnew, Memtest86, LinuxBIOS, and Linux.
118
-    I must say thanks to all the developers of these wonderful software,
119
-    especially to Eric Biederman for his great development work in this area.
120
-
121
-LICENSE
122
-
123
-    Copyright (C) 2003 by SONE Takeshi <ts1@tsn.or.jp> and others.
124
-    This program is licensed under the terms of GNU General Public License.
125
-    See the COPYING file for details.

+ 0
- 48
src/filo/README.filo_in_etherboot Целия файл

@@ -1,48 +0,0 @@
1
-Moved from FILO into Etherboot, yhlu add boot from SATA disk and move usb boot framework 
2
-from Steven James baremetal in LinuxBIOS, also add the OHCI support.
3
-
4
-
5
-1. refer to README.filo
6
-	but don't need to use make config. 
7
-2. CFLAG added
8
-	CONSOLE_BTEXT --- for btext console support
9
-	CONSOLE_PC_KBD  --- for direct pc keyboard support
10
-	CONFIG_FILO	--- It will make main call pci_init
11
-3. to make:
12
-	make bin/filo.zelf
13
-    or 
14
-	make bin/tg3--filo.zelf
15
-
16
-   You can not use filo and ide_disk at the same time.
17
-
18
-Some input for boot:
19
-
20
-boot from BIOS ROM area 
21
-4G-128K
22
-mem@0xfffe0000
23
-4G-512K
24
-mem@0xfff80000
25
-
26
-boot from suse 
27
-hda2:/boot/vmlinuz initrd=/boot/initrd ro root=/dev/hda2 console=tty0 console=ttyS0,115200
28
-for suse install from CD
29
-hdc:/boot/loader/linux initrd=/boot/loader/initrd ramdisk_size=65536 splash=silent showopts console=tty0 console=ttyS0,115200
30
-
31
-boot from RH
32
-for RH install from CD
33
-hdc:/isolinux/vmlinuz initrd=/isolinux/initrd.img expert nofb acpi=off devfs=nomount ramdisk_size=65536 console=ttyS0,115200
34
-
35
-for serial ATA support (using port1 and port2 only)
36
-1) if your kernel think SATA as SCSI
37
-hde2:/boot/vmlinuz initrd=/boot/initrd ro root=/dev/sda2 console=tty0 console=ttyS0,115200
38
-2) if your kernel think SATA as normal IDE
39
-hde2:/boot/vmlinuz initrd=/boot/initrd ro root=/dev/hde2 console=tty0 console=ttyS0,115200
40
-
41
-for usb support
42
-uda1:/ram0_2.5_2.6.5_k8.2_mydisk7.elf
43
-
44
-
45
-Yinghai Lu      yhlu@tyan.com
46
-
47
-to do:
48
-	add menu to filo boot 

+ 0
- 15
src/filo/README.usb Целия файл

@@ -1,15 +0,0 @@
1
-It is from steven james's baremetal in linuxbios util.
2
-yhlu seperate common functions from uhci.c to usb.c and create ohci.c to support ohci.
3
-ohci.c mainly cames from kernel 2.4.22 dirvers/usb/host/usb-ohci.c.
4
-it includes several parts
5
-1. UHCI+OHCI--->USB: privide usb init and usb_control_msg and usb_bulk_msg interface
6
-2. USB_SCSI: bulk only device 
7
-3. USB_X interface to FILO
8
-
9
-other changes in Etherboot
10
-1. Add allot2 and forget2, it will produce the required aligned memory.
11
-
12
-todo:
13
-1. EHCI support
14
-
15
-yhlu 6/2/2004

+ 0
- 1129
src/filo/drivers/ide_x.c
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 0
- 383
src/filo/fs/blockdev.c Целия файл

@@ -1,383 +0,0 @@
1
-#include <etherboot.h>
2
-
3
-#include <lib.h>
4
-#include <fs.h>
5
-
6
-#define DEBUG_THIS DEBUG_BLOCKDEV
7
-#include <debug.h>
8
-
9
-#define NUM_CACHE 64
10
-static unsigned char buf_cache[NUM_CACHE][512];
11
-static unsigned long cache_sect[NUM_CACHE];
12
-
13
-static char dev_name[256];
14
-
15
-int dev_type = -1;
16
-int dev_drive = -1;
17
-unsigned long part_start;
18
-unsigned long part_length;
19
-int using_devsize;
20
-
21
-static inline int has_pc_part_magic(unsigned char *sect)
22
-{
23
-    return sect[510]==0x55 && sect[511]==0xAA;
24
-}
25
-
26
-static inline int is_pc_extended_part(unsigned char type)
27
-{
28
-    return type==5 || type==0xf || type==0x85;
29
-}
30
-
31
-/* IBM-PC/MS-DOS style partitioning scheme */
32
-static int open_pc_partition(int part, unsigned long *start_p,
33
-	unsigned long *length_p)
34
-{
35
-    /* Layout of PC partition table */
36
-    struct pc_partition {
37
-	unsigned char boot;
38
-	unsigned char head;
39
-	unsigned char sector;
40
-	unsigned char cyl;
41
-	unsigned char type;
42
-	unsigned char e_head;
43
-	unsigned char e_sector;
44
-	unsigned char e_cyl;
45
-	unsigned char start_sect[4]; /* unaligned little endian */
46
-	unsigned char nr_sects[4]; /* ditto */
47
-    } *p;
48
-    unsigned char buf[512];
49
-
50
-    /* PC partition probe */
51
-    if (!devread(0, 0, sizeof(buf), buf)) {
52
-	debug("device read failed\n");
53
-	return 0;
54
-    }
55
-    if (!has_pc_part_magic(buf)) {
56
-	debug("pc partition magic number not found\n");
57
-	//debug_hexdump(buf, 512);
58
-	return PARTITION_UNKNOWN;
59
-    }
60
-    p = (struct pc_partition *) (buf + 0x1be);
61
-    if (part < 4) {
62
-	/* Primary partition */
63
-	p += part;
64
-	if (p->type==0 || is_pc_extended_part(p->type)) {
65
-	    printf("Partition %d does not exist\n", part+1);
66
-	    return 0;
67
-	}
68
-	*start_p = get_le32(p->start_sect);
69
-	*length_p = get_le32(p->nr_sects);
70
-	return 1;
71
-    } else {
72
-	/* Extended partition */
73
-	int i;
74
-	int cur_part;
75
-	unsigned long ext_start, cur_table;
76
-	/* Search for the extended partition
77
-	 * which contains logical partitions */
78
-	for (i = 0; i < 4; i++) {
79
-	    if (is_pc_extended_part(p[i].type))
80
-		break;
81
-	}
82
-	if (i >= 4) {
83
-	    printf("Extended partition not found\n");
84
-	    return 0;
85
-	}
86
-	debug("Extended partition at %d\n", i+1);
87
-	/* Visit each logical partition labels */
88
-	ext_start = get_le32(p[i].start_sect);
89
-	cur_table = ext_start;
90
-	cur_part = 4;
91
-	for (;;) {
92
-	    debug("cur_part=%d at %lu\n", cur_part, cur_table);
93
-	    if (!devread(cur_table, 0, sizeof(buf), buf))
94
-		return 0;
95
-	    if (!has_pc_part_magic(buf)) {
96
-		debug("no magic\n");
97
-		break;
98
-	    }
99
-
100
-	    p = (struct pc_partition *) (buf + 0x1be);
101
-	    /* First entry is the logical partition */
102
-	    if (cur_part == part) {
103
-		if (p->type==0) {
104
-		    printf("Partition %d is empty\n", part+1);
105
-		    return 0;
106
-		}
107
-		*start_p = cur_table + get_le32(p->start_sect);
108
-		*length_p = get_le32(p->nr_sects);
109
-		return 1;
110
-	    }
111
-	    /* Second entry is link to next partition */
112
-	    if (!is_pc_extended_part(p[1].type)) {
113
-		debug("no link\n");
114
-		break;
115
-	    }
116
-	    cur_table = ext_start + get_le32(p[1].start_sect);
117
-
118
-	    cur_part++;
119
-	}
120
-	printf("Logical partition %d not exist\n", part+1);
121
-	return 0;
122
-    }
123
-}
124
-
125
-static void flush_cache(void)
126
-{
127
-    int i;
128
-    for (i = 0; i < NUM_CACHE; i++)
129
-	cache_sect[i] = (unsigned long) -1;
130
-}
131
-
132
-static int parse_device_name(const char *name, int *type, int *drive,
133
-	int *part, uint64_t *offset, uint64_t *length)
134
-{
135
-    *offset = *length = 0;
136
-
137
-    if (memcmp(name, "hd", 2) == 0) {
138
-	*type = DISK_IDE;
139
-	name += 2;
140
-	if (*name < 'a' || *name > 'z') {
141
-	    printf("Invalid drive\n");
142
-	    return 0;
143
-	}
144
-	*drive = *name - 'a';
145
-	name++;
146
-    } else if (memcmp(name, "mem", 3) == 0) {
147
-	*type = DISK_MEM;
148
-	name += 3;
149
-	*drive = 0;
150
-    } else if (memcmp(name, "ud", 2) == 0) {
151
-        *type = DISK_USB;
152
-        name += 2;
153
-        if (*name < 'a' || *name > 'z') {
154
-            printf("Invalid drive\n");
155
-            return 0; 
156
-        }
157
-        *drive = *name - 'a';
158
-        name++;
159
-    } else {
160
-	printf("Unknown device type\n");
161
-	return 0;
162
-    }
163
-
164
-    *part = (int) simple_strtoull(name, (char **)&name, 0);
165
-
166
-    if (*name == '@') {
167
-	name++;
168
-	*offset = strtoull_with_suffix(name, (char **)&name, 0);
169
-	if (*name == ',')
170
-	    *length = strtoull_with_suffix(name+1, (char **)&name, 0);
171
-//	debug("offset=%#Lx length=%#Lx\n", *offset, *length);
172
-    }
173
-
174
-    if (*name != '\0') {
175
-	printf("Can't parse device name\n");
176
-	return 0;
177
-    }
178
-
179
-    return 1;
180
-}
181
-
182
-int devopen(const char *name, int *reopen)
183
-{
184
-    int type, drive, part;
185
-    uint64_t offset, length;
186
-    uint32_t disk_size = 0;
187
-
188
-    /* Don't re-open the device that's already open */
189
-    if (strcmp(name, dev_name) == 0) {
190
-	debug("already open\n");
191
-	*reopen = 1;
192
-	return 1;
193
-    }
194
-    *reopen = 0;
195
-
196
-    if (!parse_device_name(name, &type, &drive, &part, &offset, &length)) {
197
-	debug("failed to parse device name: %s\n", name);
198
-	return 0;
199
-    }
200
-
201
-    /* Do simple sanity check first */
202
-    if (offset & 0x1ff) {
203
-	printf("Device offset must be multiple of 512\n");
204
-	return 0;
205
-    }
206
-    if (length & 0x1ff) {
207
-	debugx("WARNING: length is rounded up to multiple of 512\n");
208
-	length = (length + 0x1ff) & ~0x1ff;
209
-    }
210
-
211
-    switch (type) {
212
-#ifdef IDE_DISK
213
-    case DISK_IDE:
214
-	if (ide_probe(drive) != 0) {
215
-	    debug("failed to open ide\n");
216
-	    return 0;
217
-	}
218
-	disk_size = (uint32_t) -1; /* FIXME */
219
-	break;
220
-#endif
221
-    case DISK_MEM:
222
-	disk_size = 1 << (32 - 9); /* 4GB/512-byte */
223
-	break;
224
-#ifdef USB_DISK
225
-    case DISK_USB:
226
-        if (usb_probe(drive) != 0) {
227
-            debug("failed to open usb\n");
228
-            return 0;
229
-        }
230
-        disk_size = (uint32_t) -1; /* FIXME */
231
-        break;
232
-#endif
233
-    default:
234
-	printf("Unknown device type %d\n", type);
235
-	return 0;
236
-    }
237
-
238
-    if (dev_type != type || dev_drive != drive)
239
-	flush_cache();
240
-
241
-    /* start with whole disk */
242
-    dev_type = type;
243
-    dev_drive = drive;
244
-    part_start = 0;
245
-    part_length = disk_size;
246
-    using_devsize = 1;
247
-
248
-    if (part != 0) {
249
-	/* partition is specified */
250
-	int ret;
251
-	ret = open_pc_partition(part - 1, &part_start, &part_length);
252
-	if (ret == PARTITION_UNKNOWN) {
253
-	    ret = open_eltorito_image(part - 1, &part_start, &part_length);
254
-	    if (ret == PARTITION_UNKNOWN) {
255
-		printf("Unrecognized partitioning scheme\n");
256
-		return 0;
257
-	    }
258
-	}
259
-	if (ret == 0) {
260
-	    debug("can't open partition %d\n", part);
261
-	    return 0;
262
-	}
263
-
264
-	debug("Partition %d start %lu length %lu\n", part,
265
-		part_start, part_length);
266
-    }
267
-
268
-    if (offset) {
269
-	if (offset >= (uint64_t) part_length << 9) {
270
-	    printf("Device offset is too high\n");
271
-	    return 0;
272
-	}
273
-	part_start += offset >> 9;
274
-	part_length -= offset >> 9;
275
-	debug("after offset: start %lu, length %lu\n", part_start, part_length);
276
-    }
277
-
278
-    if (length) {
279
-	if (length > (uint64_t) part_length << 9) {
280
-	    printf("Specified length exceeds the size of device\n");
281
-	    return 0;
282
-	}
283
-	part_length = length >> 9;
284
-	debug("after length: length %lu\n", part_length);
285
-	using_devsize = 0;
286
-    }
287
-
288
-    strncpy(dev_name, name, sizeof(dev_name)-1);
289
-
290
-    return 1;
291
-}
292
-
293
-/* Read a sector from opened device with simple/stupid buffer cache */
294
-static void *read_sector(unsigned long sector)
295
-{
296
-    unsigned int hash;
297
-    void *buf;
298
-    int i;
299
-
300
-    /* If reading memory, just return the memory as the buffer */
301
-    if (dev_type == DISK_MEM) {
302
-	unsigned long phys = sector << 9;
303
-	//debug("mem: %#lx\n", phys);
304
-	return phys_to_virt(phys);
305
-    }
306
-
307
-    /* Search in the cache */
308
-    hash = sector % NUM_CACHE;
309
-    buf = buf_cache[hash];
310
-    if (cache_sect[hash] != sector) {
311
-	cache_sect[hash] = (unsigned long) -1;
312
-	switch (dev_type) {
313
-#ifdef IDE_DISK
314
-	case DISK_IDE:
315
-	    if (ide_read(dev_drive, sector, buf) != 0)
316
-		goto readerr;
317
-	    break;
318
-#endif
319
-#ifdef USB_DISK
320
-        case DISK_USB:
321
-            if (usb_read(dev_drive, sector, buf) != 0)
322
-                goto readerr;
323
-            break;
324
-#endif
325
-	default:
326
-	    printf("read_sector: device not open\n");
327
-	    return 0;
328
-	}
329
-	cache_sect[hash] = sector;
330
-    }
331
-#if 0	
332
-    printf("in read_sector:\n");
333
-    for(i=0;i<128;i++) {
334
-             if((i%4)==0) printf("\n %08x:",i*4);
335
-             printf(" %08x ",(uint32_t)*((uint32_t *)buf+i));
336
-       }
337
-#endif
338
-
339
-    return buf;
340
-
341
-readerr:
342
-    printf("Disk read error dev_type=%d drive=%d sector=%x\n",
343
-	    dev_type, dev_drive, sector);
344
-    dev_name[0] = '\0'; /* force re-open the device next time */
345
-    return 0;
346
-}
347
-
348
-int devread(unsigned long sector, unsigned long byte_offset,
349
-	unsigned long byte_len, void *buf)
350
-{
351
-    char *sector_buffer;
352
-    char *dest = buf;
353
-    unsigned long len;
354
-    int i;
355
-
356
-    sector += byte_offset >> 9;
357
-    byte_offset &= 0x1ff;
358
-
359
-    if (sector + ((byte_len + 0x1ff) >> 9) > part_length) {
360
-	printf("Attempt to read out of device/partition\n");
361
-	debug("sector=%x part_length=%x byte_len=%x\n",
362
-		sector, part_length, byte_len);
363
-	return 0;
364
-    }
365
-
366
-    while (byte_len > 0) {
367
-	sector_buffer = read_sector(part_start + sector);
368
-	if (!sector_buffer) {
369
-	    debug("read sector failed\n");
370
-	    return 0;
371
-	}
372
-	len = 512 - byte_offset;
373
-	if (len > byte_len)
374
-	    len = byte_len;
375
-	memcpy(dest, sector_buffer + byte_offset, len);
376
-	sector++;
377
-	byte_offset = 0;
378
-	byte_len -= len;
379
-	dest += len;
380
-    }
381
-	
382
-    return 1;
383
-}

+ 0
- 147
src/filo/fs/eltorito.c Целия файл

@@ -1,147 +0,0 @@
1
-
2
-#include <etherboot.h>
3
-#include <fs.h>
4
-#include <lib.h>
5
-
6
-#define DEBUG_THIS DEBUG_ELTORITO
7
-#include <debug.h>
8
-
9
-#define ELTORITO_PLATFORM_X86 0
10
-#define ELTORITO_PLATFORM_PPC 1
11
-#define ELTORITO_PLATFORM_MAC 2
12
-#include <bits/eltorito.h>
13
-
14
-#ifndef ELTORITO_PLATFORM
15
-#error "ELTORITO_PLATFORM is not defined for this arch"
16
-#endif
17
-
18
-/* El Torito boot record at sector 0x11 of bootable CD */
19
-struct boot_record {
20
-    uint8_t ind;
21
-    uint8_t iso_id[5];
22
-    uint8_t version;
23
-    uint8_t boot_id[32];
24
-    uint8_t reserved[32];
25
-    uint8_t catalog_offset[4];
26
-};
27
-
28
-/* First entry of the catalog */
29
-struct validation_entry {
30
-    uint8_t header_id;
31
-    uint8_t platform;
32
-    uint8_t reserved[2];
33
-    uint8_t id[24];
34
-    uint8_t checksum[2];
35
-    uint8_t key55;
36
-    uint8_t keyAA;
37
-};
38
-
39
-/* Initial/Default catalog entry */
40
-struct default_entry {
41
-    uint8_t boot_id;
42
-    uint8_t media_type;
43
-#define MEDIA_MASK 0x0f
44
-#define MEDIA_NOEMU 0
45
-#define MEDIA_1200_FD 1
46
-#define MEDIA_1440_FD 2
47
-#define MEDIA_2880_FD 3
48
-#define MEDIA_HD 4
49
-    uint8_t load_segment[2];
50
-    uint8_t system_type;
51
-    uint8_t reserved;
52
-    uint8_t sector_count[2];
53
-    uint8_t start_sector[4];
54
-    uint8_t reserved_too[20];
55
-};
56
-
57
-/* Find El-Torito boot disk image */
58
-int open_eltorito_image(int part, unsigned long *offset_p,
59
-	unsigned long *length_p)
60
-{
61
-    struct boot_record boot_record;
62
-    uint32_t cat_offset;
63
-    uint8_t catalog[2048];
64
-    struct validation_entry *ve;
65
-    int i, sum;
66
-    struct default_entry *de;
67
-
68
-    /* We always use 512-byte "soft sector", but
69
-     * El-Torito uses 2048-byte CD-ROM sector */
70
-
71
-    /* Boot Record is at sector 0x11 */
72
-    if (!devread(0x11<<2, 0, sizeof boot_record, &boot_record))
73
-	return 0;
74
-
75
-    if (boot_record.ind != 0
76
-	    || memcmp(boot_record.iso_id, "CD001", 5) != 0
77
-	    || memcmp(boot_record.boot_id, "EL TORITO SPECIFICATION", 23)
78
-		!= 0) {
79
-	debug("No El-Torito signature\n");
80
-	return PARTITION_UNKNOWN;
81
-    }
82
-
83
-    if (part != 0) {
84
-	printf("El-Torito entries other than Initial/Default is not supported\n");
85
-	return 0;
86
-    }
87
-
88
-    cat_offset = get_le32(boot_record.catalog_offset);
89
-    debug("El-Torito boot catalog at sector %u\n", cat_offset);
90
-    if (!devread(cat_offset<<2, 0, 2048, catalog))
91
-	return 0;
92
-
93
-    /* Validate the catalog */
94
-    ve = (void *) catalog;
95
-    //debug_hexdump(ve, sizeof *ve);
96
-    if (ve->header_id != 1 || ve->key55 != 0x55 || ve->keyAA != 0xAA) {
97
-	printf("Invalid El Torito boot catalog\n");
98
-	return 0;
99
-    }
100
-    /* All words must sum up to zero */
101
-    sum = 0;
102
-    for (i = 0; i < sizeof(*ve); i += 2)
103
-	sum += get_le16(&catalog[i]);
104
-    sum &= 0xffff;
105
-    if (sum != 0) {
106
-	printf("El Torito boot catalog verify failed\n");
107
-	return 0;
108
-    }
109
-    debug("id='%.*s'\n", sizeof ve->id, ve->id);
110
-
111
-    /* Platform check is warning only, because we won't directly execute
112
-     * the image. Just mounting it should be safe. */
113
-    if (ve->platform != ELTORITO_PLATFORM){
114
-	debugx("WARNING: Boot disk for different platform: %d\n", ve->platform);
115
-	}
116
-
117
-    /* Just support initial/default entry for now */
118
-    de = (void *) (ve + 1);
119
-    if (de->boot_id != 0x88) {
120
-	debugx("WARNING: Default boot entry is not bootable\n");
121
-	}
122
-
123
-    switch (de->media_type & MEDIA_MASK) {
124
-    case MEDIA_NOEMU:
125
-	printf("Disc doesn't use boot disk emulation\n");
126
-	return 0;
127
-    case MEDIA_1200_FD:
128
-	*length_p = 1200*1024/512;
129
-	break;
130
-    case MEDIA_1440_FD:
131
-	*length_p = 1440*1024/512;
132
-	break;
133
-    case MEDIA_2880_FD:
134
-	*length_p = 2880*1024/512;
135
-	break;
136
-    case MEDIA_HD:
137
-	/* FIXME: read partition table and return first partition.
138
-	 * Spec states emulation HD has only one partition and it must
139
-	 * be the first partition */
140
-	printf("Disc uses hard disk emulation - not supported\n");
141
-	return 0;
142
-    }
143
-    *offset_p = get_le32(de->start_sector) << 2;
144
-    debug("offset=%#lx length=%#lx\n", *offset_p, *length_p);
145
-
146
-    return 1;
147
-}

+ 0
- 100
src/filo/fs/fat.h Целия файл

@@ -1,100 +0,0 @@
1
-/*
2
- *  GRUB  --  GRand Unified Bootloader
3
- *  Copyright (C) 2001  Free Software Foundation, Inc.
4
- *
5
- *  This program is free software; you can redistribute it and/or modify
6
- *  it under the terms of the GNU General Public License as published by
7
- *  the Free Software Foundation; either version 2 of the License, or
8
- *  (at your option) any later version.
9
- *
10
- *  This program is distributed in the hope that it will be useful,
11
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- *  GNU General Public License for more details.
14
- *
15
- *  You should have received a copy of the GNU General Public License
16
- *  along with this program; if not, write to the Free Software
17
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
- */
19
-
20
-
21
-/*
22
- *  Defines for the FAT BIOS Parameter Block (embedded in the first block
23
- *  of the partition.
24
- */
25
-
26
-typedef __signed__ char __s8;
27
-typedef unsigned char __u8;
28
-typedef __signed__ short __s16;
29
-typedef unsigned short __u16;
30
-typedef __signed__ int __s32;
31
-typedef unsigned int __u32;
32
-
33
-/* Note that some shorts are not aligned, and must therefore
34
- * be declared as array of two bytes.
35
- */
36
-struct fat_bpb {
37
-	__s8	ignored[3];	/* Boot strap short or near jump */
38
-	__s8	system_id[8];	/* Name - can be used to special case
39
-				   partition manager volumes */
40
-	__u8	bytes_per_sect[2];	/* bytes per logical sector */
41
-	__u8	sects_per_clust;/* sectors/cluster */
42
-	__u8	reserved_sects[2];	/* reserved sectors */
43
-	__u8	num_fats;	/* number of FATs */
44
-	__u8	dir_entries[2];	/* root directory entries */
45
-	__u8	short_sectors[2];	/* number of sectors */
46
-	__u8	media;		/* media code (unused) */
47
-	__u16	fat_length;	/* sectors/FAT */
48
-	__u16	secs_track;	/* sectors per track */
49
-	__u16	heads;		/* number of heads */
50
-	__u32	hidden;		/* hidden sectors (unused) */
51
-	__u32	long_sectors;	/* number of sectors (if short_sectors == 0) */
52
-
53
-	/* The following fields are only used by FAT32 */
54
-	__u32	fat32_length;	/* sectors/FAT */
55
-	__u16	flags;		/* bit 8: fat mirroring, low 4: active fat */
56
-	__u8	version[2];	/* major, minor filesystem version */
57
-	__u32	root_cluster;	/* first cluster in root directory */
58
-	__u16	info_sector;	/* filesystem info sector */
59
-	__u16	backup_boot;	/* backup boot sector */
60
-	__u16	reserved2[6];	/* Unused */
61
-};
62
-
63
-#define FAT_CVT_U16(bytarr) (* (__u16*)(bytarr))
64
-
65
-/*
66
- *  Defines how to differentiate a 12-bit and 16-bit FAT.
67
- */
68
-
69
-#define FAT_MAX_12BIT_CLUST       4087	/* 4085 + 2 */
70
-
71
-/*
72
- *  Defines for the file "attribute" byte
73
- */
74
-
75
-#define FAT_ATTRIB_OK_MASK        0x37
76
-#define FAT_ATTRIB_NOT_OK_MASK    0xC8
77
-#define FAT_ATTRIB_DIR            0x10
78
-#define FAT_ATTRIB_LONGNAME       0x0F
79
-
80
-/*
81
- *  Defines for FAT directory entries
82
- */
83
-
84
-#define FAT_DIRENTRY_LENGTH       32
85
-
86
-#define FAT_DIRENTRY_ATTRIB(entry) \
87
-  (*((unsigned char *) (entry+11)))
88
-#define FAT_DIRENTRY_VALID(entry) \
89
-  ( ((*((unsigned char *) entry)) != 0) \
90
-    && ((*((unsigned char *) entry)) != 0xE5) \
91
-    && !(FAT_DIRENTRY_ATTRIB(entry) & FAT_ATTRIB_NOT_OK_MASK) )
92
-#define FAT_DIRENTRY_FIRST_CLUSTER(entry) \
93
-  ((*((unsigned short *) (entry+26)))+(*((unsigned short *) (entry+20)) << 16))
94
-#define FAT_DIRENTRY_FILELENGTH(entry) \
95
-  (*((unsigned long *) (entry+28)))
96
-
97
-#define FAT_LONGDIR_ID(entry) \
98
-  (*((unsigned char *) (entry)))
99
-#define FAT_LONGDIR_ALIASCHECKSUM(entry) \
100
-  (*((unsigned char *) (entry+13)))

+ 0
- 233
src/filo/fs/filesys.h Целия файл

@@ -1,233 +0,0 @@
1
-/* GRUB compatibility header */
2
-
3
-/*
4
- *  GRUB  --  GRand Unified Bootloader
5
- *  Copyright (C) 1999,2000,2001,2003   Free Software Foundation, Inc.
6
- *
7
- *  This program is free software; you can redistribute it and/or modify
8
- *  it under the terms of the GNU General Public License as published by
9
- *  the Free Software Foundation; either version 2 of the License, or
10
- *  (at your option) any later version.
11
- *
12
- *  This program is distributed in the hope that it will be useful,
13
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- *  GNU General Public License for more details.
16
- *
17
- *  You should have received a copy of the GNU General Public License
18
- *  along with this program; if not, write to the Free Software
19
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
- */
21
-
22
-//#include <lib.h>
23
-#include <etherboot.h>
24
-
25
-#include <fs.h>
26
-
27
-/* This disables some portion of code */
28
-#define STAGE1_5 1
29
-
30
-static inline int 
31
-substring (const char *s1, const char *s2)
32
-{
33
-  while (*s1 == *s2)
34
-    {
35
-      /* The strings match exactly. */
36
-      if (! *(s1++))
37
-	return 0;
38
-      s2 ++;
39
-    }
40
-
41
-  /* S1 is a substring of S2. */
42
-  if (*s1 == 0)
43
-    return -1;
44
-
45
-  /* S1 isn't a substring. */
46
-  return 1;
47
-}
48
-
49
-#define grub_memmove memmove
50
-#define grub_strcmp strcmp
51
-
52
-#define MAXINT 0x7fffffff
53
-
54
-/* This is only used by fsys_* to determine if it's hard disk. If it is,
55
- * they try to guess filesystem type by partition type. I guess it is 
56
- * not necessory, so hardcoded to 0 (first floppy) --ts1 */
57
-#define current_drive 0
58
-
59
-/* Ditto */
60
-#define current_slice 0
61
-
62
-extern unsigned long part_start;
63
-extern unsigned long part_length;
64
-extern int filepos;
65
-extern int filemax;
66
-extern int fsmax;
67
-
68
-/* Error codes (descriptions are in common.c) */
69
-typedef enum
70
-{
71
-  ERR_NONE = 0,
72
-  ERR_BAD_FILENAME,
73
-  ERR_BAD_FILETYPE,
74
-  ERR_BAD_GZIP_DATA,
75
-  ERR_BAD_GZIP_HEADER,
76
-  ERR_BAD_PART_TABLE,
77
-  ERR_BAD_VERSION,
78
-  ERR_BELOW_1MB,
79
-  ERR_BOOT_COMMAND,
80
-  ERR_BOOT_FAILURE,
81
-  ERR_BOOT_FEATURES,
82
-  ERR_DEV_FORMAT,
83
-  ERR_DEV_VALUES,
84
-  ERR_EXEC_FORMAT,
85
-  ERR_FILELENGTH,
86
-  ERR_FILE_NOT_FOUND,
87
-  ERR_FSYS_CORRUPT,
88
-  ERR_FSYS_MOUNT,
89
-  ERR_GEOM,
90
-  ERR_NEED_LX_KERNEL,
91
-  ERR_NEED_MB_KERNEL,
92
-  ERR_NO_DISK,
93
-  ERR_NO_PART,
94
-  ERR_NUMBER_PARSING,
95
-  ERR_OUTSIDE_PART,
96
-  ERR_READ,
97
-  ERR_SYMLINK_LOOP,
98
-  ERR_UNRECOGNIZED,
99
-  ERR_WONT_FIT,
100
-  ERR_WRITE,
101
-  ERR_BAD_ARGUMENT,
102
-  ERR_UNALIGNED,
103
-  ERR_PRIVILEGED,
104
-  ERR_DEV_NEED_INIT,
105
-  ERR_NO_DISK_SPACE,
106
-  ERR_NUMBER_OVERFLOW,
107
-
108
-  MAX_ERR_NUM
109
-} grub_error_t;
110
-
111
-extern grub_error_t errnum;
112
-
113
-#define grub_open file_open
114
-#define grub_read file_read
115
-#define grub_seek file_seek
116
-#define grub_close file_close
117
-
118
-/* instrumentation variables */
119
-/* (Not used in FILO) */
120
-extern void (*disk_read_hook) (int, int, int);
121
-extern void (*disk_read_func) (int, int, int);
122
-
123
-#define FSYS_BUFLEN 0x8000
124
-extern char FSYS_BUF[FSYS_BUFLEN];
125
-
126
-#define print_possibilities 0
127
-
128
-#define SECTOR_SIZE 512
129
-#define SECTOR_BITS 9
130
-
131
-#ifdef FSYS_FAT
132
-int fat_mount (void);
133
-int fat_read (char *buf, int len);
134
-int fat_dir (char *dirname);
135
-#endif
136
-
137
-#ifdef FSYS_EXT2FS
138
-int ext2fs_mount (void);
139
-int ext2fs_read (char *buf, int len);
140
-int ext2fs_dir (char *dirname);
141
-#endif
142
-
143
-#ifdef FSYS_MINIX
144
-int minix_mount (void);
145
-int minix_read (char *buf, int len);
146
-int minix_dir (char *dirname);
147
-#endif
148
-
149
-#ifdef FSYS_REISERFS
150
-int reiserfs_mount (void);
151
-int reiserfs_read (char *buf, int len);
152
-int reiserfs_dir (char *dirname);
153
-int reiserfs_embed (int *start_sector, int needed_sectors);
154
-#endif
155
-
156
-#ifdef FSYS_JFS
157
-int jfs_mount (void);
158
-int jfs_read (char *buf, int len);
159
-int jfs_dir (char *dirname);
160
-int jfs_embed (int *start_sector, int needed_sectors);
161
-#endif
162
-
163
-#ifdef FSYS_XFS
164
-int xfs_mount (void);
165
-int xfs_read (char *buf, int len);
166
-int xfs_dir (char *dirname);
167
-#endif
168
-
169
-#ifdef FSYS_ISO9660
170
-int iso9660_mount (void);
171
-int iso9660_read (char *buf, int len);
172
-int iso9660_dir (char *dirname);
173
-#endif
174
-
175
-/* This is not a flag actually, but used as if it were a flag.  */
176
-#define PC_SLICE_TYPE_HIDDEN_FLAG	0x10
177
-
178
-#define PC_SLICE_TYPE_NONE         	0
179
-#define PC_SLICE_TYPE_FAT12        	1
180
-#define PC_SLICE_TYPE_FAT16_LT32M  	4
181
-#define PC_SLICE_TYPE_EXTENDED     	5
182
-#define PC_SLICE_TYPE_FAT16_GT32M  	6
183
-#define PC_SLICE_TYPE_FAT32		0xb
184
-#define PC_SLICE_TYPE_FAT32_LBA		0xc
185
-#define PC_SLICE_TYPE_FAT16_LBA		0xe
186
-#define PC_SLICE_TYPE_WIN95_EXTENDED	0xf
187
-#define PC_SLICE_TYPE_EZD        	0x55
188
-#define PC_SLICE_TYPE_MINIX		0x80
189
-#define PC_SLICE_TYPE_LINUX_MINIX	0x81
190
-#define PC_SLICE_TYPE_EXT2FS       	0x83
191
-#define PC_SLICE_TYPE_LINUX_EXTENDED	0x85
192
-#define PC_SLICE_TYPE_VSTAFS		0x9e
193
-#define PC_SLICE_TYPE_DELL_UTIL		0xde
194
-#define PC_SLICE_TYPE_LINUX_RAID	0xfd
195
-
196
-/* For convinience.  */
197
-/* Check if TYPE is a FAT partition type. Clear the hidden flag before
198
-   the check, to allow the user to mount a hidden partition in GRUB.  */
199
-#define IS_PC_SLICE_TYPE_FAT(type)	\
200
-  ({ int _type = (type) & ~PC_SLICE_TYPE_HIDDEN_FLAG; \
201
-     _type == PC_SLICE_TYPE_FAT12 \
202
-     || _type == PC_SLICE_TYPE_FAT16_LT32M \
203
-     || _type == PC_SLICE_TYPE_FAT16_GT32M \
204
-     || _type == PC_SLICE_TYPE_FAT16_LBA \
205
-     || _type == PC_SLICE_TYPE_FAT32 \
206
-     || _type == PC_SLICE_TYPE_FAT32_LBA \
207
-     || _type == PC_SLICE_TYPE_DELL_UTIL; })
208
-
209
-#define IS_PC_SLICE_TYPE_MINIX(type) \
210
-  (((type) == PC_SLICE_TYPE_MINIX)	\
211
-   || ((type) == PC_SLICE_TYPE_LINUX_MINIX))
212
-
213
-#define IS_PC_SLICE_TYPE_BSD_WITH_FS(type,fs) 0
214
-
215
-/* possible values for the *BSD-style partition type */
216
-#define	FS_UNUSED	0	/* unused */
217
-#define	FS_SWAP		1	/* swap */
218
-#define	FS_V6		2	/* Sixth Edition */
219
-#define	FS_V7		3	/* Seventh Edition */
220
-#define	FS_SYSV		4	/* System V */
221
-#define	FS_V71K		5	/* V7 with 1K blocks (4.1, 2.9) */
222
-#define	FS_V8		6	/* Eighth Edition, 4K blocks */
223
-#define	FS_BSDFFS	7	/* 4.2BSD fast file system */
224
-#define	FS_MSDOS	8	/* MSDOS file system */
225
-#define	FS_BSDLFS	9	/* 4.4BSD log-structured file system */
226
-#define	FS_OTHER	10	/* in use, but unknown/unsupported */
227
-#define	FS_HPFS		11	/* OS/2 high-performance file system */
228
-#define	FS_ISO9660	12	/* ISO 9660, normally CD-ROM */
229
-#define	FS_BOOT		13	/* partition contains bootstrap */
230
-#define	FS_ADOS		14	/* AmigaDOS fast file system */
231
-#define	FS_HFS		15	/* Macintosh HFS */
232
-#define	FS_FILECORE	16	/* Acorn Filecore Filing System */
233
-#define	FS_EXT2FS	17	/* Linux Extended 2 file system */

+ 0
- 779
src/filo/fs/fsys_ext2fs.c Целия файл

@@ -1,779 +0,0 @@
1
-/*
2
- *  GRUB  --  GRand Unified Bootloader
3
- *  Copyright (C) 1999, 2001  Free Software Foundation, Inc.
4
- *
5
- *  This program is free software; you can redistribute it and/or modify
6
- *  it under the terms of the GNU General Public License as published by
7
- *  the Free Software Foundation; either version 2 of the License, or
8
- *  (at your option) any later version.
9
- *
10
- *  This program is distributed in the hope that it will be useful,
11
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- *  GNU General Public License for more details.
14
- *
15
- *  You should have received a copy of the GNU General Public License
16
- *  along with this program; if not, write to the Free Software
17
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
- */
19
-
20
-#ifdef FSYS_EXT2FS
21
-
22
-#include "shared.h"
23
-#include "filesys.h"
24
-#include <lib.h>
25
-#include "string.h"
26
-
27
-static int mapblock1, mapblock2;
28
-
29
-/* sizes are always in bytes, BLOCK values are always in DEV_BSIZE (sectors) */
30
-#define DEV_BSIZE 512
31
-
32
-/* include/linux/fs.h */
33
-#define BLOCK_SIZE 1024		/* initial block size for superblock read */
34
-/* made up, defaults to 1 but can be passed via mount_opts */
35
-#define WHICH_SUPER 1
36
-/* kind of from fs/ext2/super.c */
37
-#define SBLOCK (WHICH_SUPER * BLOCK_SIZE / DEV_BSIZE)	/* = 2 */
38
-
39
-/* include/asm-i386/types.h */
40
-typedef __signed__ char __s8;
41
-typedef unsigned char __u8;
42
-typedef __signed__ short __s16;
43
-typedef unsigned short __u16;
44
-typedef __signed__ int __s32;
45
-typedef unsigned int __u32;
46
-
47
-/*
48
- * Constants relative to the data blocks, from ext2_fs.h
49
- */
50
-#define EXT2_NDIR_BLOCKS                12
51
-#define EXT2_IND_BLOCK                  EXT2_NDIR_BLOCKS
52
-#define EXT2_DIND_BLOCK                 (EXT2_IND_BLOCK + 1)
53
-#define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
54
-#define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
55
-
56
-/* include/linux/ext2_fs.h */
57
-struct ext2_super_block
58
-  {
59
-    __u32 s_inodes_count;	/* Inodes count */
60
-    __u32 s_blocks_count;	/* Blocks count */
61
-    __u32 s_r_blocks_count;	/* Reserved blocks count */
62
-    __u32 s_free_blocks_count;	/* Free blocks count */
63
-    __u32 s_free_inodes_count;	/* Free inodes count */
64
-    __u32 s_first_data_block;	/* First Data Block */
65
-    __u32 s_log_block_size;	/* Block size */
66
-    __s32 s_log_frag_size;	/* Fragment size */
67
-    __u32 s_blocks_per_group;	/* # Blocks per group */
68
-    __u32 s_frags_per_group;	/* # Fragments per group */
69
-    __u32 s_inodes_per_group;	/* # Inodes per group */
70
-    __u32 s_mtime;		/* Mount time */
71
-    __u32 s_wtime;		/* Write time */
72
-    __u16 s_mnt_count;		/* Mount count */
73
-    __s16 s_max_mnt_count;	/* Maximal mount count */
74
-    __u16 s_magic;		/* Magic signature */
75
-    __u16 s_state;		/* File system state */
76
-    __u16 s_errors;		/* Behaviour when detecting errors */
77
-    __u16 s_pad;
78
-    __u32 s_lastcheck;		/* time of last check */
79
-    __u32 s_checkinterval;	/* max. time between checks */
80
-    __u32 s_creator_os;		/* OS */
81
-    __u32 s_rev_level;		/* Revision level */
82
-    __u16 s_def_resuid;		/* Default uid for reserved blocks */
83
-    __u16 s_def_resgid;		/* Default gid for reserved blocks */
84
-    __u32 s_reserved[235];	/* Padding to the end of the block */
85
-  };
86
-
87
-struct ext2_group_desc
88
-  {
89
-    __u32 bg_block_bitmap;	/* Blocks bitmap block */
90
-    __u32 bg_inode_bitmap;	/* Inodes bitmap block */
91
-    __u32 bg_inode_table;	/* Inodes table block */
92
-    __u16 bg_free_blocks_count;	/* Free blocks count */
93
-    __u16 bg_free_inodes_count;	/* Free inodes count */
94
-    __u16 bg_used_dirs_count;	/* Directories count */
95
-    __u16 bg_pad;
96
-    __u32 bg_reserved[3];
97
-  };
98
-
99
-struct ext2_inode
100
-  {
101
-    __u16 i_mode;		/* File mode */
102
-    __u16 i_uid;		/* Owner Uid */
103
-    __u32 i_size;		/* 4: Size in bytes */
104
-    __u32 i_atime;		/* Access time */
105
-    __u32 i_ctime;		/* 12: Creation time */
106
-    __u32 i_mtime;		/* Modification time */
107
-    __u32 i_dtime;		/* 20: Deletion Time */
108
-    __u16 i_gid;		/* Group Id */
109
-    __u16 i_links_count;	/* 24: Links count */
110
-    __u32 i_blocks;		/* Blocks count */
111
-    __u32 i_flags;		/* 32: File flags */
112
-    union
113
-      {
114
-	struct
115
-	  {
116
-	    __u32 l_i_reserved1;
117
-	  }
118
-	linux1;
119
-	struct
120
-	  {
121
-	    __u32 h_i_translator;
122
-	  }
123
-	hurd1;
124
-	struct
125
-	  {
126
-	    __u32 m_i_reserved1;
127
-	  }
128
-	masix1;
129
-      }
130
-    osd1;			/* OS dependent 1 */
131
-    __u32 i_block[EXT2_N_BLOCKS];	/* 40: Pointers to blocks */
132
-    __u32 i_version;		/* File version (for NFS) */
133
-    __u32 i_file_acl;		/* File ACL */
134
-    __u32 i_dir_acl;		/* Directory ACL */
135
-    __u32 i_faddr;		/* Fragment address */
136
-    union
137
-      {
138
-	struct
139
-	  {
140
-	    __u8 l_i_frag;	/* Fragment number */
141
-	    __u8 l_i_fsize;	/* Fragment size */
142
-	    __u16 i_pad1;
143
-	    __u32 l_i_reserved2[2];
144
-	  }
145
-	linux2;
146
-	struct
147
-	  {
148
-	    __u8 h_i_frag;	/* Fragment number */
149
-	    __u8 h_i_fsize;	/* Fragment size */
150
-	    __u16 h_i_mode_high;
151
-	    __u16 h_i_uid_high;
152
-	    __u16 h_i_gid_high;
153
-	    __u32 h_i_author;
154
-	  }
155
-	hurd2;
156
-	struct
157
-	  {
158
-	    __u8 m_i_frag;	/* Fragment number */
159
-	    __u8 m_i_fsize;	/* Fragment size */
160
-	    __u16 m_pad1;
161
-	    __u32 m_i_reserved2[2];
162
-	  }
163
-	masix2;
164
-      }
165
-    osd2;			/* OS dependent 2 */
166
-  };
167
-
168
-/* linux/limits.h */
169
-#define NAME_MAX         255	/* # chars in a file name */
170
-
171
-/* linux/posix_type.h */
172
-typedef long linux_off_t;
173
-
174
-/* linux/ext2fs.h */
175
-#define EXT2_NAME_LEN 255
176
-struct ext2_dir_entry
177
-  {
178
-    __u32 inode;		/* Inode number */
179
-    __u16 rec_len;		/* Directory entry length */
180
-    __u8 name_len;		/* Name length */
181
-    __u8 file_type;
182
-    char name[EXT2_NAME_LEN];	/* File name */
183
-  };
184
-
185
-/* linux/ext2fs.h */
186
-/*
187
- * EXT2_DIR_PAD defines the directory entries boundaries
188
- *
189
- * NOTE: It must be a multiple of 4
190
- */
191
-#define EXT2_DIR_PAD                    4
192
-#define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
193
-#define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
194
-                                         ~EXT2_DIR_ROUND)
195
-
196
-
197
-/* ext2/super.c */
198
-#define log2(n) ffz(~(n))
199
-
200
-#define EXT2_SUPER_MAGIC      0xEF53	/* include/linux/ext2_fs.h */
201
-#define EXT2_ROOT_INO              2	/* include/linux/ext2_fs.h */
202
-#define PATH_MAX                1024	/* include/linux/limits.h */
203
-#define MAX_LINK_COUNT             5	/* number of symbolic links to follow */
204
-
205
-/* made up, these are pointers into FSYS_BUF */
206
-/* read once, always stays there: */
207
-#define SUPERBLOCK \
208
-    ((struct ext2_super_block *)(FSYS_BUF))
209
-#define GROUP_DESC \
210
-    ((struct ext2_group_desc *) \
211
-     ((int)SUPERBLOCK + sizeof(struct ext2_super_block)))
212
-#define INODE \
213
-    ((struct ext2_inode *)((int)GROUP_DESC + EXT2_BLOCK_SIZE(SUPERBLOCK)))
214
-#define DATABLOCK1 \
215
-    ((int)((int)INODE + sizeof(struct ext2_inode)))
216
-#define DATABLOCK2 \
217
-    ((int)((int)DATABLOCK1 + EXT2_BLOCK_SIZE(SUPERBLOCK)))
218
-
219
-/* linux/ext2_fs.h */
220
-#define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
221
-#define EXT2_ADDR_PER_BLOCK_BITS(s)		(log2(EXT2_ADDR_PER_BLOCK(s)))
222
-
223
-/* linux/ext2_fs.h */
224
-#define EXT2_BLOCK_SIZE_BITS(s)        ((s)->s_log_block_size + 10)
225
-/* kind of from ext2/super.c */
226
-#define EXT2_BLOCK_SIZE(s)	(1 << EXT2_BLOCK_SIZE_BITS(s))
227
-/* linux/ext2fs.h */
228
-#define EXT2_DESC_PER_BLOCK(s) \
229
-     (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
230
-/* linux/stat.h */
231
-#define S_IFMT  00170000
232
-#define S_IFLNK  0120000
233
-#define S_IFREG  0100000
234
-#define S_IFDIR  0040000
235
-#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)
236
-#define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
237
-#define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
238
-
239
-/* include/asm-i386/bitops.h */
240
-/*
241
- * ffz = Find First Zero in word. Undefined if no zero exists,
242
- * so code should check against ~0UL first..
243
- */
244
-static __inline__ unsigned long
245
-ffz (unsigned long word)
246
-{
247
-  __asm__ ("bsfl %1,%0"
248
-:	   "=r" (word)
249
-:	   "r" (~word));
250
-  return word;
251
-}
252
-
253
-/* check filesystem types and read superblock into memory buffer */
254
-int
255
-ext2fs_mount (void)
256
-{
257
-  int retval = 1;
258
-
259
-  if ((((current_drive & 0x80) || (current_slice != 0))
260
-       && (current_slice != PC_SLICE_TYPE_EXT2FS)
261
-       && (current_slice != PC_SLICE_TYPE_LINUX_RAID)
262
-       && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_EXT2FS))
263
-       && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER)))
264
-      || part_length < (SBLOCK + (sizeof (struct ext2_super_block) / DEV_BSIZE))
265
-      || !devread (SBLOCK, 0, sizeof (struct ext2_super_block),
266
-		   (char *) SUPERBLOCK)
267
-      || SUPERBLOCK->s_magic != EXT2_SUPER_MAGIC)
268
-      retval = 0;
269
-
270
-  return retval;
271
-}
272
-
273
-/* Takes a file system block number and reads it into BUFFER. */
274
-static int
275
-ext2_rdfsb (int fsblock, int buffer)
276
-{
277
-#ifdef E2DEBUG
278
-  printf ("fsblock %d buffer %d\n", fsblock, buffer);
279
-#endif /* E2DEBUG */
280
-  return devread (fsblock * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE), 0,
281
-		  EXT2_BLOCK_SIZE (SUPERBLOCK), (char *) buffer);
282
-}
283
-
284
-/* from
285
-  ext2/inode.c:ext2_bmap()
286
-*/
287
-/* Maps LOGICAL_BLOCK (the file offset divided by the blocksize) into
288
-   a physical block (the location in the file system) via an inode. */
289
-static int
290
-ext2fs_block_map (int logical_block)
291
-{
292
-
293
-#ifdef E2DEBUG
294
-  unsigned char *i;
295
-  for (i = (unsigned char *) INODE;
296
-       i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
297
-       i++)
298
-    {
299
-      printf ("%c", "0123456789abcdef"[*i >> 4]);
300
-      printf ("%c", "0123456789abcdef"[*i % 16]);
301
-      if (!((i + 1 - (unsigned char *) INODE) % 16))
302
-	{
303
-	  printf ("\n");
304
-	}
305
-      else
306
-	{
307
-	  printf (" ");
308
-	}
309
-    }
310
-  printf ("logical block %d\n", logical_block);
311
-#endif /* E2DEBUG */
312
-
313
-  /* if it is directly pointed to by the inode, return that physical addr */
314
-  if (logical_block < EXT2_NDIR_BLOCKS)
315
-    {
316
-#ifdef E2DEBUG
317
-      printf ("returning %d\n", (unsigned char *) (INODE->i_block[logical_block]));
318
-      printf ("returning %d\n", INODE->i_block[logical_block]);
319
-#endif /* E2DEBUG */
320
-      return INODE->i_block[logical_block];
321
-    }
322
-  /* else */
323
-  logical_block -= EXT2_NDIR_BLOCKS;
324
-  /* try the indirect block */
325
-  if (logical_block < EXT2_ADDR_PER_BLOCK (SUPERBLOCK))
326
-    {
327
-      if (mapblock1 != 1
328
-	  && !ext2_rdfsb (INODE->i_block[EXT2_IND_BLOCK], DATABLOCK1))
329
-	{
330
-	  errnum = ERR_FSYS_CORRUPT;
331
-	  return -1;
332
-	}
333
-      mapblock1 = 1;
334
-      return ((__u32 *) DATABLOCK1)[logical_block];
335
-    }
336
-  /* else */
337
-  logical_block -= EXT2_ADDR_PER_BLOCK (SUPERBLOCK);
338
-  /* now try the double indirect block */
339
-  if (logical_block < (1 << (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK) * 2)))
340
-    {
341
-      int bnum;
342
-      if (mapblock1 != 2
343
-	  && !ext2_rdfsb (INODE->i_block[EXT2_DIND_BLOCK], DATABLOCK1))
344
-	{
345
-	  errnum = ERR_FSYS_CORRUPT;
346
-	  return -1;
347
-	}
348
-      mapblock1 = 2;
349
-      if ((bnum = (((__u32 *) DATABLOCK1)
350
-		   [logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)]))
351
-	  != mapblock2
352
-	  && !ext2_rdfsb (bnum, DATABLOCK2))
353
-	{
354
-	  errnum = ERR_FSYS_CORRUPT;
355
-	  return -1;
356
-	}
357
-      mapblock2 = bnum;
358
-      return ((__u32 *) DATABLOCK2)
359
-	[logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
360
-    }
361
-  /* else */
362
-  mapblock2 = -1;
363
-  logical_block -= (1 << (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK) * 2));
364
-  if (mapblock1 != 3
365
-      && !ext2_rdfsb (INODE->i_block[EXT2_TIND_BLOCK], DATABLOCK1))
366
-    {
367
-      errnum = ERR_FSYS_CORRUPT;
368
-      return -1;
369
-    }
370
-  mapblock1 = 3;
371
-  if (!ext2_rdfsb (((__u32 *) DATABLOCK1)
372
-		   [logical_block >> (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)
373
-				      * 2)],
374
-		   DATABLOCK2))
375
-    {
376
-      errnum = ERR_FSYS_CORRUPT;
377
-      return -1;
378
-    }
379
-  if (!ext2_rdfsb (((__u32 *) DATABLOCK2)
380
-		   [(logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK))
381
-		    & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)],
382
-		   DATABLOCK2))
383
-    {
384
-      errnum = ERR_FSYS_CORRUPT;
385
-      return -1;
386
-    }
387
-  return ((__u32 *) DATABLOCK2)
388
-    [logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
389
-}
390
-
391
-/* preconditions: all preconds of ext2fs_block_map */
392
-int
393
-ext2fs_read (char *buf, int len)
394
-{
395
-  int logical_block;
396
-  int offset;
397
-  int map;
398
-  int ret = 0;
399
-  int size = 0;
400
-
401
-#ifdef E2DEBUG
402
-  static char hexdigit[] = "0123456789abcdef";
403
-  unsigned char *i;
404
-  for (i = (unsigned char *) INODE;
405
-       i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
406
-       i++)
407
-    {
408
-      printf ("%c", hexdigit[*i >> 4]);
409
-      printf ("%c", hexdigit[*i % 16]);
410
-      if (!((i + 1 - (unsigned char *) INODE) % 16))
411
-	{
412
-	  printf ("\n");
413
-	}
414
-      else
415
-	{
416
-	  printf (" ");
417
-	}
418
-    }
419
-#endif /* E2DEBUG */
420
-  while (len > 0)
421
-    {
422
-      /* find the (logical) block component of our location */
423
-      logical_block = filepos >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
424
-      offset = filepos & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
425
-      map = ext2fs_block_map (logical_block);
426
-#ifdef E2DEBUG
427
-      printf ("map=%d\n", map);
428
-#endif /* E2DEBUG */
429
-      if (map < 0)
430
-	break;
431
-
432
-      size = EXT2_BLOCK_SIZE (SUPERBLOCK);
433
-      size -= offset;
434
-      if (size > len)
435
-	size = len;
436
-
437
-      disk_read_func = disk_read_hook;
438
-
439
-      devread (map * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE),
440
-	       offset, size, buf);
441
-
442
-      disk_read_func = NULL;
443
-
444
-      buf += size;
445
-      len -= size;
446
-      filepos += size;
447
-      ret += size;
448
-    }
449
-
450
-  if (errnum)
451
-    ret = 0;
452
-
453
-  return ret;
454
-}
455
-
456
-
457
-/* Based on:
458
-   def_blk_fops points to
459
-   blkdev_open, which calls (I think):
460
-   sys_open()
461
-   do_open()
462
-   open_namei()
463
-   dir_namei() which accesses current->fs->root
464
-     fs->root was set during original mount:
465
-     (something)... which calls (I think):
466
-     ext2_read_super()
467
-     iget()
468
-     __iget()
469
-     read_inode()
470
-     ext2_read_inode()
471
-       uses desc_per_block_bits, which is set in ext2_read_super()
472
-       also uses group descriptors loaded during ext2_read_super()
473
-   lookup()
474
-   ext2_lookup()
475
-   ext2_find_entry()
476
-   ext2_getblk()
477
-
478
-*/
479
-
480
-/* preconditions: ext2fs_mount already executed, therefore supblk in buffer
481
- *   known as SUPERBLOCK
482
- * returns: 0 if error, nonzero iff we were able to find the file successfully
483
- * postconditions: on a nonzero return, buffer known as INODE contains the
484
- *   inode of the file we were trying to look up
485
- * side effects: messes up GROUP_DESC buffer area
486
- */
487
-int
488
-ext2fs_dir (char *dirname)
489
-{
490
-  int current_ino = EXT2_ROOT_INO;	/* start at the root */
491
-  int updir_ino = current_ino;	/* the parent of the current directory */
492
-  int group_id;			/* which group the inode is in */
493
-  int group_desc;		/* fs pointer to that group */
494
-  int desc;			/* index within that group */
495
-  int ino_blk;			/* fs pointer of the inode's information */
496
-  int str_chk = 0;		/* used to hold the results of a string compare */
497
-  struct ext2_group_desc *gdp;
498
-  struct ext2_inode *raw_inode;	/* inode info corresponding to current_ino */
499
-
500
-  char linkbuf[PATH_MAX];	/* buffer for following symbolic links */
501
-  int link_count = 0;
502
-
503
-  char *rest;
504
-  char ch;			/* temp char holder */
505
-
506
-  int off;			/* offset within block of directory entry (off mod blocksize) */
507
-  int loc;			/* location within a directory */
508
-  int blk;			/* which data blk within dir entry (off div blocksize) */
509
-  long map;			/* fs pointer of a particular block from dir entry */
510
-  struct ext2_dir_entry *dp;	/* pointer to directory entry */
511
-#ifdef E2DEBUG
512
-  unsigned char *i;
513
-#endif	/* E2DEBUG */
514
-
515
-  /* loop invariants:
516
-     current_ino = inode to lookup
517
-     dirname = pointer to filename component we are cur looking up within
518
-     the directory known pointed to by current_ino (if any)
519
-   */
520
-
521
-  while (1)
522
-    {
523
-#ifdef E2DEBUG
524
-      printf ("inode %d\n", current_ino);
525
-      printf ("dirname=%s\n", dirname);
526
-#endif /* E2DEBUG */
527
-
528
-      /* look up an inode */
529
-      group_id = (current_ino - 1) / (SUPERBLOCK->s_inodes_per_group);
530
-      group_desc = group_id >> log2 (EXT2_DESC_PER_BLOCK (SUPERBLOCK));
531
-      desc = group_id & (EXT2_DESC_PER_BLOCK (SUPERBLOCK) - 1);
532
-#ifdef E2DEBUG
533
-      printf ("ipg=%d, dpb=%d\n", SUPERBLOCK->s_inodes_per_group,
534
-	      EXT2_DESC_PER_BLOCK (SUPERBLOCK));
535
-      printf ("group_id=%d group_desc=%d desc=%d\n", group_id, group_desc, desc);
536
-#endif /* E2DEBUG */
537
-      if (!ext2_rdfsb (
538
-			(WHICH_SUPER + group_desc + SUPERBLOCK->s_first_data_block),
539
-			(int) GROUP_DESC))
540
-	{
541
-	  return 0;
542
-	}
543
-      gdp = GROUP_DESC;
544
-      ino_blk = gdp[desc].bg_inode_table +
545
-	(((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
546
-	 >> log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
547
-#ifdef E2DEBUG
548
-      printf ("inode table fsblock=%d\n", ino_blk);
549
-#endif /* E2DEBUG */
550
-      if (!ext2_rdfsb (ino_blk, (int) INODE))
551
-	{
552
-	  return 0;
553
-	}
554
-
555
-      /* reset indirect blocks! */
556
-      mapblock2 = mapblock1 = -1;
557
-
558
-      raw_inode = INODE +
559
-	((current_ino - 1)
560
-	 & (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode) - 1));
561
-#ifdef E2DEBUG
562
-      printf ("ipb=%d, sizeof(inode)=%d\n",
563
-	      (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)),
564
-	      sizeof (struct ext2_inode));
565
-      printf ("inode=%x, raw_inode=%x\n", INODE, raw_inode);
566
-      printf ("offset into inode table block=%d\n", (int) raw_inode - (int) INODE);
567
-      for (i = (unsigned char *) INODE; i <= (unsigned char *) raw_inode;
568
-	   i++)
569
-	{
570
-	  printf ("%c", "0123456789abcdef"[*i >> 4]);
571
-	  printf ("%c", "0123456789abcdef"[*i % 16]);
572
-	  if (!((i + 1 - (unsigned char *) INODE) % 16))
573
-	    {
574
-	      printf ("\n");
575
-	    }
576
-	  else
577
-	    {
578
-	      printf (" ");
579
-	    }
580
-	}
581
-      printf ("first word=%x\n", *((int *) raw_inode));
582
-#endif /* E2DEBUG */
583
-
584
-      /* copy inode to fixed location */
585
-      memmove ((void *) INODE, (void *) raw_inode, sizeof (struct ext2_inode));
586
-
587
-#ifdef E2DEBUG
588
-      printf ("first word=%x\n", *((int *) INODE));
589
-#endif /* E2DEBUG */
590
-
591
-      /* If we've got a symbolic link, then chase it. */
592
-      if (S_ISLNK (INODE->i_mode))
593
-	{
594
-	  int len;
595
-	  if (++link_count > MAX_LINK_COUNT)
596
-	    {
597
-	      errnum = ERR_SYMLINK_LOOP;
598
-	      return 0;
599
-	    }
600
-
601
-	  /* Find out how long our remaining name is. */
602
-	  len = 0;
603
-	  while (dirname[len] && !isspace (dirname[len]))
604
-	    len++;
605
-
606
-	  /* Get the symlink size. */
607
-	  filemax = (INODE->i_size);
608
-	  if (filemax + len > sizeof (linkbuf) - 2)
609
-	    {
610
-	      errnum = ERR_FILELENGTH;
611
-	      return 0;
612
-	    }
613
-
614
-	  if (len)
615
-	    {
616
-	      /* Copy the remaining name to the end of the symlink data.
617
-	         Note that DIRNAME and LINKBUF may overlap! */
618
-	      memmove (linkbuf + filemax, dirname, len);
619
-	    }
620
-	  linkbuf[filemax + len] = '\0';
621
-
622
-	  /* Read the symlink data. */
623
-	  if (INODE->i_blocks)
624
-	    {
625
-	      /* Read the necessary blocks, and reset the file pointer. */
626
-	      len = grub_read (linkbuf, filemax);
627
-	      filepos = 0;
628
-	      if (!len)
629
-		return 0;
630
-	    }
631
-	  else
632
-	    {
633
-	      /* Copy the data directly from the inode. */
634
-	      len = filemax;
635
-	      memmove (linkbuf, (char *) INODE->i_block, len);
636
-	    }
637
-
638
-#ifdef E2DEBUG
639
-	  printf ("symlink=%s\n", linkbuf);
640
-#endif
641
-
642
-	  dirname = linkbuf;
643
-	  if (*dirname == '/')
644
-	    {
645
-	      /* It's an absolute link, so look it up in root. */
646
-	      current_ino = EXT2_ROOT_INO;
647
-	      updir_ino = current_ino;
648
-	    }
649
-	  else
650
-	    {
651
-	      /* Relative, so look it up in our parent directory. */
652
-	      current_ino = updir_ino;
653
-	    }
654
-
655
-	  /* Try again using the new name. */
656
-	  continue;
657
-	}
658
-
659
-      /* if end of filename, INODE points to the file's inode */
660
-      if (!*dirname || isspace (*dirname))
661
-	{
662
-	  if (!S_ISREG (INODE->i_mode))
663
-	    {
664
-	      errnum = ERR_BAD_FILETYPE;
665
-	      return 0;
666
-	    }
667
-
668
-	  filemax = (INODE->i_size);
669
-	  return 1;
670
-	}
671
-
672
-      /* else we have to traverse a directory */
673
-      updir_ino = current_ino;
674
-
675
-      /* skip over slashes */
676
-      while (*dirname == '/')
677
-	dirname++;
678
-
679
-      /* if this isn't a directory of sufficient size to hold our file, abort */
680
-      if (!(INODE->i_size) || !S_ISDIR (INODE->i_mode))
681
-	{
682
-	  errnum = ERR_BAD_FILETYPE;
683
-	  return 0;
684
-	}
685
-
686
-      /* skip to next slash or end of filename (space) */
687
-      for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/';
688
-	   rest++);
689
-
690
-      /* look through this directory and find the next filename component */
691
-      /* invariant: rest points to slash after the next filename component */
692
-      *rest = 0;
693
-      loc = 0;
694
-
695
-      do
696
-	{
697
-
698
-#ifdef E2DEBUG
699
-	  printf ("dirname=%s, rest=%s, loc=%d\n", dirname, rest, loc);
700
-#endif /* E2DEBUG */
701
-
702
-	  /* if our location/byte offset into the directory exceeds the size,
703
-	     give up */
704
-	  if (loc >= INODE->i_size)
705
-	    {
706
-	      if (print_possibilities < 0)
707
-		{
708
-# if 0
709
-		  putchar ('\n');
710
-# endif
711
-		}
712
-	      else
713
-		{
714
-		  errnum = ERR_FILE_NOT_FOUND;
715
-		  *rest = ch;
716
-		}
717
-	      return (print_possibilities < 0);
718
-	    }
719
-
720
-	  /* else, find the (logical) block component of our location */
721
-	  blk = loc >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
722
-
723
-	  /* we know which logical block of the directory entry we are looking
724
-	     for, now we have to translate that to the physical (fs) block on
725
-	     the disk */
726
-	  map = ext2fs_block_map (blk);
727
-#ifdef E2DEBUG
728
-	  printf ("fs block=%d\n", map);
729
-#endif /* E2DEBUG */
730
-	  mapblock2 = -1;
731
-	  if ((map < 0) || !ext2_rdfsb (map, DATABLOCK2))
732
-	    {
733
-	      errnum = ERR_FSYS_CORRUPT;
734
-	      *rest = ch;
735
-	      return 0;
736
-	    }
737
-	  off = loc & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
738
-	  dp = (struct ext2_dir_entry *) (DATABLOCK2 + off);
739
-	  /* advance loc prematurely to next on-disk directory entry  */
740
-	  loc += dp->rec_len;
741
-
742
-	  /* NOTE: ext2fs filenames are NOT null-terminated */
743
-
744
-#ifdef E2DEBUG
745
-	  printf ("directory entry ino=%d\n", dp->inode);
746
-	  if (dp->inode)
747
-	    printf ("entry=%s\n", dp->name);
748
-#endif /* E2DEBUG */
749
-
750
-	  if (dp->inode)
751
-	    {
752
-	      int saved_c = dp->name[dp->name_len];
753
-
754
-	      dp->name[dp->name_len] = 0;
755
-	      str_chk = substring (dirname, dp->name);
756
-
757
-# ifndef STAGE1_5
758
-	      if (print_possibilities && ch != '/'
759
-		  && (!*dirname || str_chk <= 0))
760
-		{
761
-		  if (print_possibilities > 0)
762
-		    print_possibilities = -print_possibilities;
763
-		  print_a_completion (dp->name);
764
-		}
765
-# endif
766
-
767
-	      dp->name[dp->name_len] = saved_c;
768
-	    }
769
-
770
-	}
771
-      while (!dp->inode || (str_chk || (print_possibilities && ch != '/')));
772
-
773
-      current_ino = dp->inode;
774
-      *(dirname = rest) = ch;
775
-    }
776
-  /* never get here */
777
-}
778
-
779
-#endif /* FSYS_EXT2_FS */

+ 0
- 494
src/filo/fs/fsys_fat.c Целия файл

@@ -1,494 +0,0 @@
1
-/*
2
- *  GRUB  --  GRand Unified Bootloader
3
- *  Copyright (C) 2000, 2001   Free Software Foundation, Inc.
4
- *
5
- *  This program is free software; you can redistribute it and/or modify
6
- *  it under the terms of the GNU General Public License as published by
7
- *  the Free Software Foundation; either version 2 of the License, or
8
- *  (at your option) any later version.
9
- *
10
- *  This program is distributed in the hope that it will be useful,
11
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- *  GNU General Public License for more details.
14
- *
15
- *  You should have received a copy of the GNU General Public License
16
- *  along with this program; if not, write to the Free Software
17
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
- */
19
-
20
-#ifdef FSYS_FAT
21
-
22
-#include "shared.h"
23
-#include "filesys.h"
24
-#include "fat.h"
25
-#include <lib.h>
26
-#include "string.h"
27
-
28
-struct fat_superblock 
29
-{
30
-  int fat_offset;
31
-  int fat_length;
32
-  int fat_size;
33
-  int root_offset;
34
-  int root_max;
35
-  int data_offset;
36
-  
37
-  int num_sectors;
38
-  int num_clust;
39
-  int clust_eof_marker;
40
-  int sects_per_clust;
41
-  int sectsize_bits;
42
-  int clustsize_bits;
43
-  int root_cluster;
44
-  
45
-  int cached_fat;
46
-  int file_cluster;
47
-  int current_cluster_num;
48
-  int current_cluster;
49
-};
50
-
51
-/* pointer(s) into filesystem info buffer for DOS stuff */
52
-#define FAT_SUPER ( (struct fat_superblock *) \
53
- 		    ( FSYS_BUF + 32256) )/* 512 bytes long */
54
-#define FAT_BUF   ( FSYS_BUF + 30208 )	/* 4 sector FAT buffer */
55
-#define NAME_BUF  ( FSYS_BUF + 29184 )	/* Filename buffer (833 bytes) */
56
-
57
-#define FAT_CACHE_SIZE 2048
58
-
59
-static __inline__ unsigned long
60
-log2 (unsigned long word)
61
-{
62
-  __asm__ ("bsfl %1,%0"
63
-	   : "=r" (word)
64
-	   : "r" (word));
65
-  return word;
66
-}
67
-
68
-int
69
-fat_mount (void)
70
-{
71
-  struct fat_bpb bpb;
72
-  __u32 magic, first_fat;
73
-  
74
-  /* Check partition type for harddisk */
75
-  if (((current_drive & 0x80) || (current_slice != 0))
76
-      && ! IS_PC_SLICE_TYPE_FAT (current_slice)
77
-      && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_MSDOS)))
78
-    return 0;
79
-  
80
-  /* Read bpb */
81
-  if (! devread (0, 0, sizeof (bpb), (char *) &bpb))
82
-    return 0;
83
-
84
-  /* Check if the number of sectors per cluster is zero here, to avoid
85
-     zero division.  */
86
-  if (bpb.sects_per_clust == 0)
87
-    return 0;
88
-  
89
-  FAT_SUPER->sectsize_bits = log2 (FAT_CVT_U16 (bpb.bytes_per_sect));
90
-  FAT_SUPER->clustsize_bits
91
-    = FAT_SUPER->sectsize_bits + log2 (bpb.sects_per_clust);
92
-  
93
-  /* Fill in info about super block */
94
-  FAT_SUPER->num_sectors = FAT_CVT_U16 (bpb.short_sectors) 
95
-    ? FAT_CVT_U16 (bpb.short_sectors) : bpb.long_sectors;
96
-  
97
-  /* FAT offset and length */
98
-  FAT_SUPER->fat_offset = FAT_CVT_U16 (bpb.reserved_sects);
99
-  FAT_SUPER->fat_length = 
100
-    bpb.fat_length ? bpb.fat_length : bpb.fat32_length;
101
-  
102
-  /* Rootdir offset and length for FAT12/16 */
103
-  FAT_SUPER->root_offset = 
104
-    FAT_SUPER->fat_offset + bpb.num_fats * FAT_SUPER->fat_length;
105
-  FAT_SUPER->root_max = FAT_DIRENTRY_LENGTH * FAT_CVT_U16(bpb.dir_entries);
106
-  
107
-  /* Data offset and number of clusters */
108
-  FAT_SUPER->data_offset = 
109
-    FAT_SUPER->root_offset
110
-    + ((FAT_SUPER->root_max - 1) >> FAT_SUPER->sectsize_bits) + 1;
111
-  FAT_SUPER->num_clust = 
112
-    2 + ((FAT_SUPER->num_sectors - FAT_SUPER->data_offset) 
113
-	 / bpb.sects_per_clust);
114
-  FAT_SUPER->sects_per_clust = bpb.sects_per_clust;
115
-  
116
-  if (!bpb.fat_length)
117
-    {
118
-      /* This is a FAT32 */
119
-      if (FAT_CVT_U16(bpb.dir_entries))
120
- 	return 0;
121
-      
122
-      if (bpb.flags & 0x0080)
123
-	{
124
-	  /* FAT mirroring is disabled, get active FAT */
125
-	  int active_fat = bpb.flags & 0x000f;
126
-	  if (active_fat >= bpb.num_fats)
127
-	    return 0;
128
-	  FAT_SUPER->fat_offset += active_fat * FAT_SUPER->fat_length;
129
-	}
130
-      
131
-      FAT_SUPER->fat_size = 8;
132
-      FAT_SUPER->root_cluster = bpb.root_cluster;
133
-
134
-      /* Yes the following is correct.  FAT32 should be called FAT28 :) */
135
-      FAT_SUPER->clust_eof_marker = 0xffffff8;
136
-    } 
137
-  else 
138
-    {
139
-      if (!FAT_SUPER->root_max)
140
- 	return 0;
141
-      
142
-      FAT_SUPER->root_cluster = -1;
143
-      if (FAT_SUPER->num_clust > FAT_MAX_12BIT_CLUST) 
144
-	{
145
-	  FAT_SUPER->fat_size = 4;
146
-	  FAT_SUPER->clust_eof_marker = 0xfff8;
147
-	} 
148
-      else
149
-	{
150
-	  FAT_SUPER->fat_size = 3;
151
-	  FAT_SUPER->clust_eof_marker = 0xff8;
152
-	}
153
-    }
154
-  
155
-  
156
-  /* Now do some sanity checks */
157
-  
158
-  if (FAT_CVT_U16(bpb.bytes_per_sect) != (1 << FAT_SUPER->sectsize_bits)
159
-      || FAT_CVT_U16(bpb.bytes_per_sect) != SECTOR_SIZE
160
-      || bpb.sects_per_clust != (1 << (FAT_SUPER->clustsize_bits
161
- 				       - FAT_SUPER->sectsize_bits))
162
-      || FAT_SUPER->num_clust <= 2
163
-      || (FAT_SUPER->fat_size * FAT_SUPER->num_clust / (2 * SECTOR_SIZE)
164
- 	  > FAT_SUPER->fat_length))
165
-    return 0;
166
-  
167
-  /* kbs: Media check on first FAT entry [ported from PUPA] */
168
-
169
-  if (!devread(FAT_SUPER->fat_offset, 0,
170
-               sizeof(first_fat), (char *)&first_fat))
171
-    return 0;
172
-
173
-  if (FAT_SUPER->fat_size == 8)
174
-    {
175
-      first_fat &= 0x0fffffff;
176
-      magic = 0x0fffff00;
177
-    }
178
-  else if (FAT_SUPER->fat_size == 4)
179
-    {
180
-      first_fat &= 0x0000ffff;
181
-      magic = 0xff00;
182
-    }
183
-  else
184
-    {
185
-      first_fat &= 0x00000fff;
186
-      magic = 0x0f00;
187
-    }
188
-
189
-  if (first_fat != (magic | bpb.media))
190
-    return 0;
191
-
192
-  FAT_SUPER->cached_fat = - 2 * FAT_CACHE_SIZE;
193
-  return 1;
194
-}
195
-
196
-int
197
-fat_read (char *buf, int len)
198
-{
199
-  int logical_clust;
200
-  int offset;
201
-  int ret = 0;
202
-  int size;
203
-  int count = 64;
204
-  
205
-  if (FAT_SUPER->file_cluster < 0)
206
-    {
207
-      /* root directory for fat16 */
208
-      size = FAT_SUPER->root_max - filepos;
209
-      if (size > len)
210
- 	size = len;
211
-      if (!devread(FAT_SUPER->root_offset, filepos, size, buf))
212
- 	return 0;
213
-      filepos += size;
214
-      return size;
215
-    }
216
-  
217
-  logical_clust = filepos >> FAT_SUPER->clustsize_bits;
218
-  offset = (filepos & ((1 << FAT_SUPER->clustsize_bits) - 1));
219
-  if (logical_clust < FAT_SUPER->current_cluster_num)
220
-    {
221
-      FAT_SUPER->current_cluster_num = 0;
222
-      FAT_SUPER->current_cluster = FAT_SUPER->file_cluster;
223
-    }
224
-  
225
-  while (len > 0)
226
-    {
227
-      int sector;
228
-      while (logical_clust > FAT_SUPER->current_cluster_num)
229
-	{
230
-	  /* calculate next cluster */
231
-	  int fat_entry = 
232
-	    FAT_SUPER->current_cluster * FAT_SUPER->fat_size;
233
-	  int next_cluster;
234
-	  int cached_pos = (fat_entry - FAT_SUPER->cached_fat);
235
-	  
236
-	  if (cached_pos < 0 || 
237
-	      (cached_pos + FAT_SUPER->fat_size) > 2*FAT_CACHE_SIZE)
238
-	    {
239
-	      FAT_SUPER->cached_fat = (fat_entry & ~(2*SECTOR_SIZE - 1));
240
-	      cached_pos = (fat_entry - FAT_SUPER->cached_fat);
241
-	      sector = FAT_SUPER->fat_offset
242
-		+ FAT_SUPER->cached_fat / (2*SECTOR_SIZE);
243
-	      if (!devread (sector, 0, FAT_CACHE_SIZE, (char*) FAT_BUF))
244
-		return 0;
245
-	    }
246
-	  next_cluster = * (unsigned long *) (FAT_BUF + (cached_pos >> 1));
247
-	  if (FAT_SUPER->fat_size == 3)
248
-	    {
249
-	      if (cached_pos & 1)
250
-		next_cluster >>= 4;
251
-	      next_cluster &= 0xFFF;
252
-	    }
253
-	  else if (FAT_SUPER->fat_size == 4)
254
-	    next_cluster &= 0xFFFF;
255
-	  
256
-	  if (next_cluster >= FAT_SUPER->clust_eof_marker)
257
-	    return ret;
258
-	  if (next_cluster < 2 || next_cluster >= FAT_SUPER->num_clust)
259
-	    {
260
-	      errnum = ERR_FSYS_CORRUPT;
261
-	      return 0;
262
-	    }
263
-	  
264
-	  FAT_SUPER->current_cluster = next_cluster;
265
-	  FAT_SUPER->current_cluster_num++;
266
-	}
267
-      
268
-      sector = FAT_SUPER->data_offset +
269
-	((FAT_SUPER->current_cluster - 2) << (FAT_SUPER->clustsize_bits
270
- 					      - FAT_SUPER->sectsize_bits));
271
-      size = (1 << FAT_SUPER->clustsize_bits) - offset;
272
-      if (size > len)
273
-	size = len;
274
-      
275
-      disk_read_func = disk_read_hook;
276
-      
277
-      devread(sector, offset, size, buf);
278
-      
279
-      disk_read_func = NULL;
280
-      
281
-      len -= size;
282
-      buf += size;
283
-      ret += size;
284
-      filepos += size;
285
-      logical_clust++;
286
-      offset = 0;
287
-      if(count--==0) {
288
-	count = 32; 
289
-	printf(".");
290
-      }
291
-    }
292
-  
293
-//  printf("\n");
294
-  return errnum ? 0 : ret;
295
-}
296
-
297
-int
298
-fat_dir (char *dirname)
299
-{
300
-  char *rest, ch, dir_buf[FAT_DIRENTRY_LENGTH];
301
-  char *filename = (char *) NAME_BUF;
302
-  int attrib = FAT_ATTRIB_DIR;
303
-#ifndef STAGE1_5
304
-  int do_possibilities = 0;
305
-#endif
306
-  
307
-  /* XXX I18N:
308
-   * the positions 2,4,6 etc are high bytes of a 16 bit unicode char 
309
-   */
310
-  static unsigned char longdir_pos[] = 
311
-  { 1, 3, 5, 7, 9, 14, 16, 18, 20, 22, 24, 28, 30 };
312
-  int slot = -2;
313
-  int alias_checksum = -1;
314
-  
315
-  FAT_SUPER->file_cluster = FAT_SUPER->root_cluster;
316
-  filepos = 0;
317
-  FAT_SUPER->current_cluster_num = MAXINT;
318
-  
319
-  /* main loop to find desired directory entry */
320
- loop:
321
-  
322
-  /* if we have a real file (and we're not just printing possibilities),
323
-     then this is where we want to exit */
324
-  
325
-  if (!*dirname || isspace (*dirname))
326
-    {
327
-      if (attrib & FAT_ATTRIB_DIR)
328
-	{
329
-	  errnum = ERR_BAD_FILETYPE;
330
-	  return 0;
331
-	}
332
-      
333
-      return 1;
334
-    }
335
-  
336
-  /* continue with the file/directory name interpretation */
337
-  
338
-  while (*dirname == '/')
339
-    dirname++;
340
-  
341
-  if (!(attrib & FAT_ATTRIB_DIR))
342
-    {
343
-      errnum = ERR_BAD_FILETYPE;
344
-      return 0;
345
-    }
346
-  /* Directories don't have a file size */
347
-  filemax = MAXINT;
348
-  
349
-  for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/'; rest++);
350
-  
351
-  *rest = 0;
352
-  
353
-# ifndef STAGE1_5
354
-  if (print_possibilities && ch != '/')
355
-    do_possibilities = 1;
356
-# endif
357
-  
358
-  while (1)
359
-    {
360
-      if (fat_read (dir_buf, FAT_DIRENTRY_LENGTH) != FAT_DIRENTRY_LENGTH
361
-	  || dir_buf[0] == 0)
362
-	{
363
-	  if (!errnum)
364
-	    {
365
-# ifndef STAGE1_5
366
-	      if (print_possibilities < 0)
367
-		{
368
-#if 0
369
-		  putchar ('\n');
370
-#endif
371
-		  return 1;
372
-		}
373
-# endif /* STAGE1_5 */
374
-	      
375
-	      errnum = ERR_FILE_NOT_FOUND;
376
-	      *rest = ch;
377
-	    }
378
-	  
379
-	  return 0;
380
-	}
381
-      
382
-      if (FAT_DIRENTRY_ATTRIB (dir_buf) == FAT_ATTRIB_LONGNAME)
383
-	{
384
-	  /* This is a long filename.  The filename is build from back
385
-	   * to front and may span multiple entries.  To bind these
386
-	   * entries together they all contain the same checksum over
387
-	   * the short alias.
388
-	   *
389
-	   * The id field tells if this is the first entry (the last
390
-	   * part) of the long filename, and also at which offset this
391
-	   * belongs.
392
-	   *
393
-	   * We just write the part of the long filename this entry
394
-	   * describes and continue with the next dir entry.
395
-	   */
396
-	  int i, offset;
397
-	  unsigned char id = FAT_LONGDIR_ID(dir_buf);
398
-	  
399
-	  if ((id & 0x40)) 
400
-	    {
401
-	      id &= 0x3f;
402
-	      slot = id;
403
-	      filename[slot * 13] = 0;
404
-	      alias_checksum = FAT_LONGDIR_ALIASCHECKSUM(dir_buf);
405
-	    } 
406
-	  
407
-	  if (id != slot || slot == 0
408
-	      || alias_checksum != FAT_LONGDIR_ALIASCHECKSUM(dir_buf))
409
-	    {
410
-	      alias_checksum = -1;
411
-	      continue;
412
-	    }
413
-	  
414
-	  slot--;
415
-	  offset = slot * 13;
416
-	  
417
-	  for (i=0; i < 13; i++)
418
-	    filename[offset+i] = dir_buf[longdir_pos[i]];
419
-	  continue;
420
-	}
421
-      
422
-      if (!FAT_DIRENTRY_VALID (dir_buf))
423
-	continue;
424
-      
425
-      if (alias_checksum != -1 && slot == 0)
426
-	{
427
-	  int i;
428
-	  unsigned char sum;
429
-	  
430
-	  slot = -2;
431
-	  for (sum = 0, i = 0; i< 11; i++)
432
-	    sum = ((sum >> 1) | (sum << 7)) + dir_buf[i];
433
-	  
434
-	  if (sum == alias_checksum)
435
-	    {
436
-# ifndef STAGE1_5
437
-	      if (do_possibilities)
438
-		goto print_filename;
439
-# endif /* STAGE1_5 */
440
-	      
441
-	      if (substring (dirname, filename) == 0)
442
-		break;
443
-	    }
444
-	}
445
-      
446
-      /* XXX convert to 8.3 filename format here */
447
-      {
448
-	int i, j, c;
449
-	
450
-	for (i = 0; i < 8 && (c = filename[i] = tolower (dir_buf[i]))
451
-	       && !isspace (c); i++);
452
-	
453
-	filename[i++] = '.';
454
-	
455
-	for (j = 0; j < 3 && (c = filename[i + j] = tolower (dir_buf[8 + j]))
456
-	       && !isspace (c); j++);
457
-	
458
-	if (j == 0)
459
-	  i--;
460
-	
461
-	filename[i + j] = 0;
462
-      }
463
-      
464
-# ifndef STAGE1_5
465
-      if (do_possibilities)
466
-	{
467
-	print_filename:
468
-	  if (substring (dirname, filename) <= 0)
469
-	    {
470
-	      if (print_possibilities > 0)
471
-		print_possibilities = -print_possibilities;
472
-	      print_a_completion (filename);
473
-	    }
474
-	  continue;
475
-	}
476
-# endif /* STAGE1_5 */
477
-      
478
-      if (substring (dirname, filename) == 0)
479
-	break;
480
-    }
481
-  
482
-  *(dirname = rest) = ch;
483
-  
484
-  attrib = FAT_DIRENTRY_ATTRIB (dir_buf);
485
-  filemax = FAT_DIRENTRY_FILELENGTH (dir_buf);
486
-  filepos = 0;
487
-  FAT_SUPER->file_cluster = FAT_DIRENTRY_FIRST_CLUSTER (dir_buf);
488
-  FAT_SUPER->current_cluster_num = MAXINT;
489
-  
490
-  /* go back to main loop at top of function */
491
-  goto loop;
492
-}
493
-
494
-#endif /* FSYS_FAT */

+ 0
- 348
src/filo/fs/fsys_iso9660.c Целия файл

@@ -1,348 +0,0 @@
1
-/*
2
- *  ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader)
3
- *  including Rock Ridge Extensions support
4
- *
5
- *  Copyright (C) 1998, 1999  Kousuke Takai  <tak@kmc.kyoto-u.ac.jp>
6
- *
7
- *  This program is free software; you can redistribute it and/or modify
8
- *  it under the terms of the GNU General Public License as published by
9
- *  the Free Software Foundation; either version 2 of the License, or
10
- *  (at your option) any later version.
11
- *
12
- *  This program is distributed in the hope that it will be useful,
13
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- *  GNU General Public License for more details.
16
- *
17
- *  You should have received a copy of the GNU General Public License
18
- *  along with this program; if not, write to the Free Software
19
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
- */
21
-/*
22
- *  References:
23
- *	linux/fs/isofs/rock.[ch]
24
- *	mkisofs-1.11.1/diag/isoinfo.c
25
- *	mkisofs-1.11.1/iso9660.h
26
- *		(all are written by Eric Youngdale)
27
- *
28
- *  Modifications by:
29
- *	Leonid Lisovskiy   <lly@pisem.net>	2003
30
- */
31
-
32
-/*
33
- * Modified to make it work with FILO
34
- * 2003-10 by SONE Takeshi
35
- */
36
-
37
-#ifdef FSYS_ISO9660
38
-
39
-#include <lib.h>
40
-#include "string.h"
41
-#include "shared.h"
42
-#include "filesys.h"
43
-#include "iso9660.h"
44
-#define DEBUG_THIS 1
45
-#include <debug.h>
46
-
47
-struct iso_superblock {
48
-    unsigned long vol_sector;
49
-
50
-    unsigned long file_start;
51
-};
52
-
53
-#define ISO_SUPER	((struct iso_superblock *)(FSYS_BUF))
54
-#define PRIMDESC        ((struct iso_primary_descriptor *)(FSYS_BUF + 2048))
55
-#define DIRREC          ((struct iso_directory_record *)(FSYS_BUF + 4096))
56
-#define RRCONT_BUF      ((unsigned char *)(FSYS_BUF + 6144))
57
-#define NAME_BUF        ((unsigned char *)(FSYS_BUF + 8192))
58
-
59
-
60
-static inline unsigned long
61
-log2 (unsigned long word)
62
-{
63
-  asm volatile ("bsfl %1,%0"
64
-:          "=r" (word)
65
-:          "r" (word));
66
-  return word;
67
-}
68
-
69
-static int
70
-iso9660_devread (int sector, int byte_offset, int byte_len, char *buf)
71
-{
72
-  /* FILO uses 512-byte "soft" sector, and ISO-9660 uses 2048-byte
73
-   * CD-ROM sector */
74
-  return devread(sector<<2, byte_offset, byte_len, buf);
75
-}
76
-
77
-int
78
-iso9660_mount (void)
79
-{
80
-  unsigned int sector;
81
-
82
-  /*
83
-   *  Because there is no defined slice type ID for ISO-9660 filesystem,
84
-   *  this test will pass only either (1) if entire disk is used, or
85
-   *  (2) if current partition is BSD style sub-partition whose ID is
86
-   *  ISO-9660.
87
-   */
88
-  /*if ((current_partition != 0xFFFFFF)
89
-      && !IS_PC_SLICE_TYPE_BSD_WITH_FS(current_slice, FS_ISO9660))
90
-    return 0;*/
91
-
92
-  /*
93
-   *  Currently, only FIRST session of MultiSession disks are supported !!!
94
-   */
95
-  for (sector = 16 ; sector < 32 ; sector++)
96
-    {
97
-      if (!iso9660_devread(sector, 0, sizeof(*PRIMDESC), (char *)PRIMDESC)) 
98
-	break;
99
-      /* check ISO_VD_PRIMARY and ISO_STANDARD_ID */
100
-      if (CHECK4(&PRIMDESC->type, ISO_VD_PRIMARY, 'C', 'D', '0')
101
-	  && CHECK2(PRIMDESC->id + 3, '0', '1'))
102
-	{
103
-	  ISO_SUPER->vol_sector = sector;
104
-	  ISO_SUPER->file_start = 0;
105
-	  fsmax = PRIMDESC->volume_space_size.l;
106
-	  return 1;
107
-	}
108
-    }
109
-
110
-  return 0;
111
-}
112
-
113
-int
114
-iso9660_dir (char *dirname)
115
-{
116
-  struct iso_directory_record *idr;
117
-  RR_ptr_t rr_ptr;
118
-  struct rock_ridge *ce_ptr;
119
-  unsigned int pathlen;
120
-  int size;
121
-  unsigned int extent;
122
-  unsigned int rr_len;
123
-  unsigned char file_type;
124
-  unsigned char rr_flag;
125
-
126
-  idr = &PRIMDESC->root_directory_record;
127
-  ISO_SUPER->file_start = 0;
128
-
129
-  do
130
-  {
131
-      while (*dirname == '/')	/* skip leading slashes */
132
-	  dirname++;
133
-      /* pathlen = strcspn(dirname, "/\n\t "); */
134
-      for (pathlen = 0 ;
135
-	  dirname[pathlen]
136
-	     && !isspace(dirname[pathlen]) && dirname[pathlen] != '/' ;
137
-	  pathlen++)
138
-	;
139
-
140
-      size = idr->size.l;
141
-      extent = idr->extent.l;
142
-
143
-      while (size > 0)
144
-      {
145
-	  if (!iso9660_devread(extent, 0, ISO_SECTOR_SIZE, (char *)DIRREC))
146
-	  {
147
-	      errnum = ERR_FSYS_CORRUPT;
148
-	      return 0;
149
-	  }
150
-	  extent++;
151
-
152
-	  idr = (struct iso_directory_record *)DIRREC;
153
-	  for (; idr->length.l > 0;
154
-		 idr = (struct iso_directory_record *)((char *)idr + idr->length.l) )
155
-	  {
156
-	      const char *name = idr->name;
157
-	      unsigned int name_len = idr->name_len.l;
158
-
159
-	      file_type = (idr->flags.l & 2) ? ISO_DIRECTORY : ISO_REGULAR;
160
-	      if (name_len == 1)
161
-	      {
162
-		  if ((name[0] == 0) ||	/* self */
163
-		      (name[0] == 1)) 	/* parent */
164
-		    continue;
165
-	      }
166
-	      if (name_len > 2 && CHECK2(name + name_len - 2, ';', '1'))
167
-	      {
168
-		  name_len -= 2;	/* truncate trailing file version */
169
-		  if (name_len > 1 && name[name_len - 1] == '.')
170
-		    name_len--;		/* truncate trailing dot */
171
-	      }
172
-
173
-	      /*
174
-	       *  Parse Rock-Ridge extension
175
-	       */
176
-	      rr_len = (idr->length.l - idr->name_len.l
177
-			- (unsigned char)sizeof(struct iso_directory_record)
178
-			+ (unsigned char)sizeof(idr->name));
179
-	      rr_ptr.ptr = ((unsigned char *)idr + idr->name_len.l
180
-			    + sizeof(struct iso_directory_record)
181
-			    - sizeof(idr->name));
182
-	      if (rr_ptr.i & 1)
183
-		rr_ptr.i++, rr_len--;
184
-	      ce_ptr = NULL;
185
-	      rr_flag = RR_FLAG_NM | RR_FLAG_PX;
186
-
187
-	      while (rr_len >= 4)
188
-	      {
189
-		  if (rr_ptr.rr->version != 1)
190
-		  {
191
-#ifndef STAGE1_5
192
-		    if (debug)
193
-		      printf(
194
-			    "Non-supported version (%d) RockRidge chunk "
195
-			    "`%c%c'\n", rr_ptr.rr->version,
196
-			    rr_ptr.rr->signature & 0xFF,
197
-			    rr_ptr.rr->signature >> 8);
198
-#endif
199
-		  }
200
-		  else if (rr_ptr.rr->signature == RRMAGIC('R', 'R')
201
-			   && rr_ptr.rr->len >= 5)
202
-		    rr_flag &= rr_ptr.rr->u.rr.flags.l;
203
-		  else if (rr_ptr.rr->signature == RRMAGIC('N', 'M'))
204
-		  {
205
-		      name = rr_ptr.rr->u.nm.name;
206
-		      name_len = rr_ptr.rr->len - 5;
207
-		      rr_flag &= ~RR_FLAG_NM;
208
-		  }
209
-		  else if (rr_ptr.rr->signature == RRMAGIC('P', 'X')
210
-			   && rr_ptr.rr->len >= 36)
211
-		  {
212
-		      file_type = ((rr_ptr.rr->u.px.mode.l & POSIX_S_IFMT)
213
-				   == POSIX_S_IFREG
214
-				   ? ISO_REGULAR
215
-				   : ((rr_ptr.rr->u.px.mode.l & POSIX_S_IFMT)
216
-				      == POSIX_S_IFDIR
217
-				      ? ISO_DIRECTORY : ISO_OTHER));
218
-		      rr_flag &= ~RR_FLAG_PX;
219
-		  }
220
-		  else if (rr_ptr.rr->signature == RRMAGIC('C', 'E')
221
-			   && rr_ptr.rr->len >= 28)
222
-		    ce_ptr = rr_ptr.rr;
223
-		  if (!rr_flag)
224
-		    /*
225
-		     * There is no more extension we expects...
226
-		     */
227
-		    break;
228
-		  rr_len -= rr_ptr.rr->len;
229
-		  rr_ptr.ptr += rr_ptr.rr->len;
230
-		  if (rr_len < 4 && ce_ptr != NULL)
231
-		  {
232
-		      /* preserve name before loading new extent. */
233
-		      if( RRCONT_BUF <= (unsigned char *)name
234
-			  && (unsigned char *)name < RRCONT_BUF + ISO_SECTOR_SIZE )
235
-		      {
236
-			  memcpy(NAME_BUF, name, name_len);
237
-			  name = NAME_BUF;
238
-		      }
239
-		      rr_ptr.ptr = RRCONT_BUF + ce_ptr->u.ce.offset.l;
240
-		      rr_len = ce_ptr->u.ce.size.l;
241
-		      if (!iso9660_devread(ce_ptr->u.ce.extent.l, 0, ISO_SECTOR_SIZE, RRCONT_BUF))
242
-		      {
243
-			  errnum = 0;	/* this is not fatal. */
244
-			  break;
245
-		      }
246
-		      ce_ptr = NULL;
247
-		   }
248
-	      } /* rr_len >= 4 */
249
-
250
-	      filemax = MAXINT;
251
-	      if (name_len >= pathlen
252
-		  && !__builtin_memcmp(name, dirname, pathlen))
253
-	      {
254
-                if (dirname[pathlen] == '/' || !print_possibilities)
255
-		{
256
-		  /*
257
-		   *  DIRNAME is directory component of pathname,
258
-		   *  or we are to open a file.
259
-		   */
260
-		  if (pathlen == name_len)
261
-		  {
262
-		      if (dirname[pathlen] == '/')
263
-		      {
264
-		          if (file_type != ISO_DIRECTORY)
265
-		          {
266
-			      errnum = ERR_BAD_FILETYPE;
267
-			      return 0;
268
-			  }
269
-                          goto next_dir_level;
270
-		      }
271
-		      if (file_type != ISO_REGULAR)
272
-		      {
273
-		          errnum = ERR_BAD_FILETYPE;
274
-		          return 0;
275
-		      }
276
-		      ISO_SUPER->file_start = idr->extent.l;
277
-		      filepos = 0;
278
-		      filemax = idr->size.l;
279
-		      return 1;
280
-		  }
281
-		}
282
-	        else	/* Completion */
283
-	        {
284
-#ifndef STAGE1_5
285
- 		  if (print_possibilities > 0)
286
-		      print_possibilities = -print_possibilities;
287
-		  memcpy(NAME_BUF, name, name_len);
288
-		  NAME_BUF[name_len] = '\0';
289
-            	  print_a_completion (NAME_BUF);
290
-#endif
291
-	        }
292
-	      }
293
-	  } /* for */
294
-
295
-	  size -= ISO_SECTOR_SIZE;
296
-      } /* size>0 */
297
-
298
-      if (dirname[pathlen] == '/' || print_possibilities >= 0)
299
-      {
300
-	  errnum = ERR_FILE_NOT_FOUND;
301
-	  return 0;
302
-      }
303
-
304
-next_dir_level:
305
-      dirname += pathlen;
306
-
307
-  } while (*dirname == '/');
308
-
309
-  return 1;
310
-}
311
-
312
-int
313
-iso9660_read (char *buf, int len)
314
-{
315
-  int sector, blkoffset, size, ret;
316
-
317
-  if (ISO_SUPER->file_start == 0)
318
-    return 0;
319
-
320
-  ret = 0;
321
-  blkoffset = filepos & (ISO_SECTOR_SIZE - 1);
322
-  sector = filepos >> ISO_SECTOR_BITS;
323
-  while (len > 0)
324
-  {
325
-    size = ISO_SECTOR_SIZE - blkoffset;
326
-    if (size > len)
327
-        size = len;
328
-
329
-    disk_read_func = disk_read_hook;
330
-
331
-    if (!iso9660_devread(ISO_SUPER->file_start + sector, blkoffset, size, buf))
332
-	return 0;
333
-
334
-    disk_read_func = NULL;
335
-
336
-    len -= size;
337
-    buf += size;
338
-    ret += size;
339
-    filepos += size;
340
-    sector++;
341
-    blkoffset = 0;
342
-  }
343
-
344
-  return ret;
345
-}
346
-
347
-#endif /* FSYS_ISO9660 */
348
-

+ 0
- 403
src/filo/fs/fsys_jfs.c Целия файл

@@ -1,403 +0,0 @@
1
-/* fsys_jfs.c - an implementation for the IBM JFS file system */
2
-/*  
3
- *  GRUB  --  GRand Unified Bootloader
4
- *  Copyright (C) 2001,2002  Free Software Foundation, Inc.
5
- *
6
- *  This program is free software; you can redistribute it and/or modify
7
- *  it under the terms of the GNU General Public License as published by
8
- *  the Free Software Foundation; either version 2 of the License, or
9
- *  (at your option) any later version.
10
- *
11
- *  This program is distributed in the hope that it will be useful,
12
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- *  GNU General Public License for more details.
15
- *
16
- *  You should have received a copy of the GNU General Public License
17
- *  along with this program; if not, write to the Free Software
18
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
- */
20
-
21
-#ifdef FSYS_JFS
22
-
23
-#include "shared.h"
24
-#include "filesys.h"
25
-#include "jfs.h"
26
-
27
-#define MAX_LINK_COUNT	8
28
-
29
-#define DTTYPE_INLINE	0
30
-#define DTTYPE_PAGE	1
31
-
32
-struct jfs_info
33
-{
34
-	int bsize;
35
-	int l2bsize;
36
-	int bdlog;
37
-	int xindex;
38
-	int xlastindex;
39
-	int sindex;
40
-	int slastindex;
41
-	int de_index;
42
-	int dttype;
43
-	xad_t *xad;
44
-	ldtentry_t *de;
45
-};
46
-
47
-static struct jfs_info jfs;
48
-
49
-#define xtpage		((xtpage_t *)FSYS_BUF)
50
-#define dtpage		((dtpage_t *)((char *)FSYS_BUF + 4096))
51
-#define fileset		((dinode_t *)((char *)FSYS_BUF + 8192))
52
-#define inode		((dinode_t *)((char *)FSYS_BUF + 8192 + sizeof(dinode_t)))
53
-#define dtroot		((dtroot_t *)(&inode->di_btroot))
54
-
55
-static ldtentry_t de_always[2] = {
56
-	{1, -1, 2, {'.', '.'}},
57
-	{1, -1, 1, {'.'}}
58
-};
59
-
60
-static int
61
-isinxt (s64 key, s64 offset, s64 len)
62
-{
63
-	return (key >= offset) ? (key < offset + len ? 1 : 0) : 0;
64
-}
65
-
66
-static xad_t *
67
-first_extent (dinode_t *di)
68
-{
69
-	xtpage_t *xtp;
70
-
71
-	jfs.xindex = 2;
72
-	xtp = (xtpage_t *)&di->di_btroot;
73
-	jfs.xad = &xtp->xad[2];
74
-	if (xtp->header.flag & BT_LEAF) {
75
-	    	jfs.xlastindex = xtp->header.nextindex;
76
-	} else {
77
-		do {
78
-			devread (addressXAD (jfs.xad) << jfs.bdlog, 0,
79
-				 sizeof(xtpage_t), (char *)xtpage);
80
-			jfs.xad = &xtpage->xad[2];
81
-		} while (!(xtpage->header.flag & BT_LEAF));
82
-		jfs.xlastindex = xtpage->header.nextindex;
83
-	}
84
-
85
-	return jfs.xad;
86
-}
87
-
88
-static xad_t *
89
-next_extent (void)
90
-{
91
-	if (++jfs.xindex < jfs.xlastindex) {
92
-	} else if (xtpage->header.next) {
93
-		devread (xtpage->header.next << jfs.bdlog, 0,
94
-			 sizeof(xtpage_t), (char *)xtpage);
95
-		jfs.xlastindex = xtpage->header.nextindex;
96
-		jfs.xindex = XTENTRYSTART;
97
-		jfs.xad = &xtpage->xad[XTENTRYSTART];
98
-	} else {
99
-		return NULL;
100
-	}
101
-	return ++jfs.xad;
102
-}
103
-
104
-
105
-static void
106
-di_read (u32 inum, dinode_t *di)
107
-{
108
-	s64 key;
109
-	u32 xd, ioffset;
110
-	s64 offset;
111
-	xad_t *xad;
112
-	pxd_t pxd;
113
-
114
-	key = (((inum >> L2INOSPERIAG) << L2INOSPERIAG) + 4096) >> jfs.l2bsize;
115
-	xd = (inum & (INOSPERIAG - 1)) >> L2INOSPEREXT;
116
-	ioffset = ((inum & (INOSPERIAG - 1)) & (INOSPEREXT - 1)) << L2DISIZE;
117
-	xad = first_extent (fileset);
118
-	do {
119
-		offset = offsetXAD (xad);
120
-		if (isinxt (key, offset, lengthXAD (xad))) {
121
-			devread ((addressXAD (xad) + key - offset) << jfs.bdlog,
122
-				 3072 + xd*sizeof(pxd_t), sizeof(pxd_t), (char *)&pxd);
123
-			devread (addressPXD (&pxd) << jfs.bdlog,
124
-				 ioffset, DISIZE, (char *)di);
125
-			break;
126
-		}
127
-	} while ((xad = next_extent ()));
128
-}
129
-
130
-static ldtentry_t *
131
-next_dentry (void)
132
-{
133
-	ldtentry_t *de;
134
-	s8 *stbl;
135
-
136
-	if (jfs.dttype == DTTYPE_INLINE) {
137
-		if (jfs.sindex < jfs.slastindex) {
138
-			return (ldtentry_t *)&dtroot->slot[(int)dtroot->header.stbl[jfs.sindex++]];
139
-		}
140
-	} else {
141
-		de = (ldtentry_t *)dtpage->slot;
142
-		stbl = (s8 *)&de[(int)dtpage->header.stblindex];
143
-		if (jfs.sindex < jfs.slastindex) {
144
-			return &de[(int)stbl[jfs.sindex++]];
145
-		} else if (dtpage->header.next) {
146
-			devread (dtpage->header.next << jfs.bdlog, 0,
147
-				 sizeof(dtpage_t), (char *)dtpage);
148
-			jfs.slastindex = dtpage->header.nextindex;
149
-			jfs.sindex = 1;
150
-			return &de[(int)((s8 *)&de[(int)dtpage->header.stblindex])[0]];
151
-		}
152
-	}
153
-
154
-	return (jfs.de_index < 2) ? &de_always[jfs.de_index++] : NULL;
155
-}
156
-
157
-static ldtentry_t *
158
-first_dentry (void)
159
-{
160
-	dtroot_t *dtr;
161
-	pxd_t *xd;
162
-	idtentry_t *de;
163
-
164
-	dtr = (dtroot_t *)&inode->di_btroot;
165
-	jfs.sindex = 0;
166
-	jfs.de_index = 0;
167
-
168
-	de_always[0].inumber = inode->di_parent;
169
-	de_always[1].inumber = inode->di_number;
170
-	if (dtr->header.flag & BT_LEAF) {
171
-		jfs.dttype = DTTYPE_INLINE;
172
-		jfs.slastindex = dtr->header.nextindex;
173
-	} else {
174
-		de = (idtentry_t *)dtpage->slot;
175
-		jfs.dttype = DTTYPE_PAGE;
176
-		xd = &((idtentry_t *)dtr->slot)[(int)dtr->header.stbl[0]].xd;
177
-		for (;;) {
178
-			devread (addressPXD (xd) << jfs.bdlog, 0,
179
-				 sizeof(dtpage_t), (char *)dtpage);
180
-			if (dtpage->header.flag & BT_LEAF)
181
-				break;
182
-			xd = &de[(int)((s8 *)&de[(int)dtpage->header.stblindex])[0]].xd;
183
-		}
184
-		jfs.slastindex = dtpage->header.nextindex;
185
-	}
186
-
187
-	return next_dentry ();
188
-}
189
-
190
-
191
-static dtslot_t *
192
-next_dslot (int next)
193
-{
194
-	return (jfs.dttype == DTTYPE_INLINE)
195
-		? (dtslot_t *)&dtroot->slot[next]
196
-		: &((dtslot_t *)dtpage->slot)[next];
197
-}
198
-
199
-static void
200
-uni2ansi (UniChar *uni, char *ansi, int len)
201
-{
202
-	for (; len; len--, uni++)
203
-		*ansi++ = (*uni & 0xff80) ? '?' : *(char *)uni;
204
-}
205
-
206
-int
207
-jfs_mount (void)
208
-{
209
-	struct jfs_superblock super;
210
-
211
-	if (part_length < MINJFS >> SECTOR_BITS
212
-	    || !devread (SUPER1_OFF >> SECTOR_BITS, 0,
213
-			 sizeof(struct jfs_superblock), (char *)&super)
214
-	    || (super.s_magic != JFS_MAGIC)
215
-	    || !devread ((AITBL_OFF >> SECTOR_BITS) + FILESYSTEM_I,
216
-			 0, DISIZE, (char*)fileset)) {
217
-		return 0;
218
-	}
219
-
220
-	jfs.bsize = super.s_bsize;
221
-	jfs.l2bsize = super.s_l2bsize;
222
-	jfs.bdlog = jfs.l2bsize - SECTOR_BITS;
223
-
224
-	return 1;
225
-}
226
-
227
-int
228
-jfs_read (char *buf, int len)
229
-{
230
-	xad_t *xad;
231
-	s64 endofprev, endofcur;
232
-	s64 offset, xadlen;
233
-	int toread, startpos, endpos;
234
-
235
-	startpos = filepos;
236
-	endpos = filepos + len;
237
-	endofprev = (1ULL << 62) - 1;
238
-	xad = first_extent (inode);
239
-	do {
240
-		offset = offsetXAD (xad);
241
-		xadlen = lengthXAD (xad);
242
-		if (isinxt (filepos >> jfs.l2bsize, offset, xadlen)) {
243
-			endofcur = (offset + xadlen) << jfs.l2bsize; 
244
-			toread = (endofcur >= endpos)
245
-				  ? len : (endofcur - filepos);
246
-
247
-			disk_read_func = disk_read_hook;
248
-			devread (addressXAD (xad) << jfs.bdlog,
249
-				 filepos - (offset << jfs.l2bsize), toread, buf);
250
-			disk_read_func = NULL;
251
-
252
-			buf += toread;
253
-			len -= toread;
254
-			filepos += toread;
255
-		} else if (offset > endofprev) {
256
-			toread = ((offset << jfs.l2bsize) >= endpos)
257
-				  ? len : ((offset - endofprev) << jfs.l2bsize);
258
-			len -= toread;
259
-			filepos += toread;
260
-			for (; toread; toread--) {
261
-				*buf++ = 0;
262
-			}
263
-			continue;
264
-		}
265
-		endofprev = offset + xadlen; 
266
-		xad = next_extent ();
267
-	} while (len > 0 && xad);
268
-
269
-	return filepos - startpos;
270
-}
271
-
272
-int
273
-jfs_dir (char *dirname)
274
-{
275
-	char *ptr, *rest, ch;
276
-	ldtentry_t *de;
277
-	dtslot_t *ds;
278
-	u32 inum, parent_inum;
279
-	s64 di_size;
280
-	u32 di_mode;
281
-	int namlen, cmp, n, link_count;
282
-	char namebuf[JFS_NAME_MAX + 1], linkbuf[JFS_PATH_MAX];
283
-
284
-	parent_inum = inum = ROOT_I;
285
-	link_count = 0;
286
-	for (;;) {
287
-		di_read (inum, inode);
288
-		di_size = inode->di_size;
289
-		di_mode = inode->di_mode;
290
-
291
-		if ((di_mode & IFMT) == IFLNK) {
292
-			if (++link_count > MAX_LINK_COUNT) {
293
-				errnum = ERR_SYMLINK_LOOP;
294
-				return 0;
295
-			}
296
-			if (di_size < (di_mode & INLINEEA ? 256 : 128)) {
297
-				grub_memmove (linkbuf, inode->di_fastsymlink, di_size);
298
-				n = di_size;
299
-			} else if (di_size < JFS_PATH_MAX - 1) {
300
-				filepos = 0;
301
-				filemax = di_size;
302
-				n = jfs_read (linkbuf, filemax);
303
-			} else {
304
-				errnum = ERR_FILELENGTH;
305
-				return 0;
306
-			}
307
-
308
-			inum = (linkbuf[0] == '/') ? ROOT_I : parent_inum;
309
-			while (n < (JFS_PATH_MAX - 1) && (linkbuf[n++] = *dirname++));
310
-			linkbuf[n] = 0;
311
-			dirname = linkbuf;
312
-			continue;
313
-		}
314
-
315
-		if (!*dirname || isspace (*dirname)) {
316
-			if ((di_mode & IFMT) != IFREG) {
317
-				errnum = ERR_BAD_FILETYPE;
318
-				return 0;
319
-			}
320
-			filepos = 0;
321
-			filemax = di_size;
322
-			return 1;
323
-		}
324
-
325
-		if ((di_mode & IFMT) != IFDIR) {
326
-			errnum = ERR_BAD_FILETYPE;
327
-			return 0;
328
-		}
329
-
330
-		for (; *dirname == '/'; dirname++);
331
-
332
-		for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/'; rest++);
333
-		*rest = 0;
334
-
335
-		de = first_dentry ();
336
-		for (;;) {
337
-			namlen = de->namlen;
338
-			if (de->next == -1) {
339
-				uni2ansi (de->name, namebuf, namlen);
340
-				namebuf[namlen] = 0;
341
-			} else {
342
-				uni2ansi (de->name, namebuf, DTLHDRDATALEN);
343
-				ptr = namebuf;
344
-				ptr += DTLHDRDATALEN;
345
-				namlen -= DTLHDRDATALEN;
346
-				ds = next_dslot (de->next);
347
-				while (ds->next != -1) {
348
-					uni2ansi (ds->name, ptr, DTSLOTDATALEN);
349
-					ptr += DTSLOTDATALEN;
350
-					namlen -= DTSLOTDATALEN;
351
-					ds = next_dslot (ds->next);
352
-				}
353
-				uni2ansi (ds->name, ptr, namlen);
354
-				ptr += namlen;
355
-				*ptr = 0;
356
-			}
357
-
358
-			cmp = (!*dirname) ? -1 : substring (dirname, namebuf);
359
-#ifndef STAGE1_5
360
-			if (print_possibilities && ch != '/'
361
-			    && cmp <= 0) {
362
-				if (print_possibilities > 0)
363
-					print_possibilities = -print_possibilities;
364
-				print_a_completion (namebuf);
365
-			} else
366
-#endif
367
-			if (cmp == 0) {
368
-				parent_inum = inum;
369
-				inum = de->inumber;
370
-		        	*(dirname = rest) = ch;
371
-				break;
372
-			}
373
-			de = next_dentry ();
374
-			if (de == NULL) {
375
-				if (print_possibilities < 0)
376
-					return 1;
377
-
378
-				errnum = ERR_FILE_NOT_FOUND;
379
-				*rest = ch;
380
-				return 0;
381
-			}
382
-		}
383
-	}
384
-}
385
-
386
-int
387
-jfs_embed (int *start_sector, int needed_sectors)
388
-{
389
-	struct jfs_superblock super;
390
-
391
-	if (needed_sectors > 63
392
-	    || !devread (SUPER1_OFF >> SECTOR_BITS, 0,
393
-			 sizeof (struct jfs_superblock),
394
-			 (char *)&super)
395
-	    || (super.s_magic != JFS_MAGIC)) {
396
-		return 0;
397
-	}
398
-
399
-	*start_sector = 1;
400
-	return 1;
401
-}
402
-
403
-#endif /* FSYS_JFS */

+ 0
- 534
src/filo/fs/fsys_minix.c Целия файл

@@ -1,534 +0,0 @@
1
-/*
2
- *  GRUB  --  GRand Unified Bootloader
3
- *  Copyright (C) 1999,2000,2001,2002  Free Software Foundation, Inc.
4
- *
5
- *  This program is free software; you can redistribute it and/or modify
6
- *  it under the terms of the GNU General Public License as published by
7
- *  the Free Software Foundation; either version 2 of the License, or
8
- *  (at your option) any later version.
9
- *
10
- *  This program is distributed in the hope that it will be useful,
11
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- *  GNU General Public License for more details.
14
- *
15
- *  You should have received a copy of the GNU General Public License
16
- *  along with this program; if not, write to the Free Software
17
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
- */
19
-
20
-/* Restrictions:
21
-   This is MINIX V1 only (yet)
22
-   Disk creation is like:
23
-   mkfs.minix -c DEVICE 
24
-*/
25
-
26
-#ifdef FSYS_MINIX
27
-
28
-#include "shared.h"
29
-#include "filesys.h"
30
-
31
-/* #define DEBUG_MINIX */
32
-
33
-/* indirect blocks */
34
-static int mapblock1, mapblock2, namelen;
35
-
36
-/* sizes are always in bytes, BLOCK values are always in DEV_BSIZE (sectors) */
37
-#define DEV_BSIZE 512
38
-
39
-/* include/linux/fs.h */
40
-#define BLOCK_SIZE_BITS 10
41
-#define BLOCK_SIZE 	(1<<BLOCK_SIZE_BITS)
42
-
43
-/* made up, defaults to 1 but can be passed via mount_opts */
44
-#define WHICH_SUPER 1
45
-/* kind of from fs/ext2/super.c (is OK for minix) */
46
-#define SBLOCK (WHICH_SUPER * BLOCK_SIZE / DEV_BSIZE)	/* = 2 */
47
-
48
-/* include/asm-i386/type.h */
49
-typedef __signed__ char __s8;
50
-typedef unsigned char __u8;
51
-typedef __signed__ short __s16;
52
-typedef unsigned short __u16;
53
-typedef __signed__ int __s32;
54
-typedef unsigned int __u32;
55
-
56
-/* include/linux/minix_fs.h */
57
-#define MINIX_ROOT_INO 1
58
-
59
-/* Not the same as the bogus LINK_MAX in <linux/limits.h>. Oh well. */
60
-#define MINIX_LINK_MAX  250
61
-#define MINIX2_LINK_MAX 65530
62
-
63
-#define MINIX_I_MAP_SLOTS       8
64
-#define MINIX_Z_MAP_SLOTS       64
65
-#define MINIX_SUPER_MAGIC       0x137F          /* original minix fs */
66
-#define MINIX_SUPER_MAGIC2      0x138F          /* minix fs, 30 char names */
67
-#define MINIX2_SUPER_MAGIC      0x2468          /* minix V2 fs */
68
-#define MINIX2_SUPER_MAGIC2     0x2478          /* minix V2 fs, 30 char names */
69
-#define MINIX_VALID_FS          0x0001          /* Clean fs. */
70
-#define MINIX_ERROR_FS          0x0002          /* fs has errors. */
71
-
72
-#define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
73
-#define MINIX2_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix2_inode)))
74
-
75
-#define MINIX_V1                0x0001          /* original minix fs */
76
-#define MINIX_V2                0x0002          /* minix V2 fs */
77
-
78
-/* originally this is : 
79
-#define INODE_VERSION(inode)    inode->i_sb->u.minix_sb.s_version
80
-   here we have */
81
-#define INODE_VERSION(inode)	(SUPERBLOCK->s_version)
82
-
83
-/*
84
- * This is the original minix inode layout on disk.
85
- * Note the 8-bit gid and atime and ctime.
86
- */
87
-struct minix_inode {
88
-	__u16 i_mode;
89
-	__u16 i_uid;
90
-	__u32 i_size;
91
-	__u32 i_time;
92
-	__u8  i_gid;
93
-	__u8  i_nlinks;
94
-	__u16 i_zone[9];
95
-};
96
-
97
-/*
98
- * The new minix inode has all the time entries, as well as
99
- * long block numbers and a third indirect block (7+1+1+1
100
- * instead of 7+1+1). Also, some previously 8-bit values are
101
- * now 16-bit. The inode is now 64 bytes instead of 32.
102
- */
103
-struct minix2_inode {
104
-	__u16 i_mode;
105
-	__u16 i_nlinks;
106
-	__u16 i_uid;
107
-	__u16 i_gid;
108
-	__u32 i_size;
109
-	__u32 i_atime;
110
-	__u32 i_mtime;
111
-	__u32 i_ctime;
112
-	__u32 i_zone[10];
113
-};
114
-
115
-/*
116
- * minix super-block data on disk
117
- */
118
-struct minix_super_block {
119
-        __u16 s_ninodes;
120
-        __u16 s_nzones;
121
-        __u16 s_imap_blocks;
122
-        __u16 s_zmap_blocks;
123
-        __u16 s_firstdatazone;
124
-        __u16 s_log_zone_size;
125
-        __u32 s_max_size;
126
-        __u16 s_magic;
127
-        __u16 s_state;
128
-        __u32 s_zones;
129
-};
130
-
131
-struct minix_dir_entry {
132
-        __u16 inode;
133
-        char name[0];
134
-};
135
-
136
-/* made up, these are pointers into FSYS_BUF */
137
-/* read once, always stays there: */
138
-#define SUPERBLOCK \
139
-    ((struct minix_super_block *)(FSYS_BUF))
140
-#define INODE \
141
-    ((struct minix_inode *)((int) SUPERBLOCK + BLOCK_SIZE))
142
-#define DATABLOCK1 \
143
-    ((int)((int)INODE + sizeof(struct minix_inode)))
144
-#define DATABLOCK2 \
145
-    ((int)((int)DATABLOCK1 + BLOCK_SIZE))
146
-
147
-/* linux/stat.h */
148
-#define S_IFMT  00170000
149
-#define S_IFLNK  0120000
150
-#define S_IFREG  0100000
151
-#define S_IFDIR  0040000
152
-#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)
153
-#define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
154
-#define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
155
-
156
-#define PATH_MAX                1024	/* include/linux/limits.h */
157
-#define MAX_LINK_COUNT             5	/* number of symbolic links to follow */
158
-
159
-/* check filesystem types and read superblock into memory buffer */
160
-int
161
-minix_mount (void)
162
-{
163
-  if (((current_drive & 0x80) || current_slice != 0)
164
-      && ! IS_PC_SLICE_TYPE_MINIX (current_slice)
165
-      && ! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER))
166
-    return 0;			/* The partition is not of MINIX type */
167
-  
168
-  if (part_length < (SBLOCK +
169
-		     (sizeof (struct minix_super_block) / DEV_BSIZE)))
170
-    return 0;			/* The partition is too short */
171
-  
172
-  if (!devread (SBLOCK, 0, sizeof (struct minix_super_block),
173
-		(char *) SUPERBLOCK))
174
-    return 0;			/* Cannot read superblock */
175
-  
176
-  switch (SUPERBLOCK->s_magic)
177
-    {
178
-    case MINIX_SUPER_MAGIC:
179
-      namelen = 14;
180
-      break;
181
-    case MINIX_SUPER_MAGIC2:
182
-      namelen = 30;
183
-      break;
184
-    default:
185
-      return 0;			/* Unsupported type */
186
-    }
187
-
188
-  return 1;
189
-}
190
-
191
-/* Takes a file system block number and reads it into BUFFER. */
192
-static int
193
-minix_rdfsb (int fsblock, int buffer)
194
-{
195
-  return devread (fsblock * (BLOCK_SIZE / DEV_BSIZE), 0,
196
-		  BLOCK_SIZE, (char *) buffer);
197
-}
198
-
199
-/* Maps LOGICAL_BLOCK (the file offset divided by the blocksize) into
200
-   a physical block (the location in the file system) via an inode. */
201
-static int
202
-minix_block_map (int logical_block)
203
-{
204
-  int i;
205
-
206
-  if (logical_block < 7)
207
-    return INODE->i_zone[logical_block];
208
-
209
-  logical_block -= 7;
210
-  if (logical_block < 512)
211
-    {
212
-      i = INODE->i_zone[7];
213
-      
214
-      if (!i || ((mapblock1 != 1)
215
-		 && !minix_rdfsb (i, DATABLOCK1)))
216
-	{
217
-	  errnum = ERR_FSYS_CORRUPT;
218
-	  return -1;
219
-	}
220
-      mapblock1 = 1;
221
-      return ((__u16 *) DATABLOCK1) [logical_block];
222
-    }
223
-
224
-  logical_block -= 512;
225
-  i = INODE->i_zone[8];
226
-  if (!i || ((mapblock1 != 2)
227
-	     && !minix_rdfsb (i, DATABLOCK1)))
228
-    {
229
-      errnum = ERR_FSYS_CORRUPT;
230
-      return -1;
231
-    }
232
-  mapblock1 = 2;
233
-  i = ((__u16 *) DATABLOCK1)[logical_block >> 9];
234
-  if (!i || ((mapblock2 != i)
235
-	     && !minix_rdfsb (i, DATABLOCK2)))
236
-    {
237
-      errnum = ERR_FSYS_CORRUPT;
238
-      return -1;
239
-    }
240
-  mapblock2 = i;
241
-  return ((__u16 *) DATABLOCK2)[logical_block & 511];
242
-}
243
-
244
-/* read from INODE into BUF */
245
-int
246
-minix_read (char *buf, int len)
247
-{
248
-  int logical_block;
249
-  int offset;
250
-  int map;
251
-  int ret = 0;
252
-  int size = 0;
253
-
254
-  while (len > 0)
255
-    {
256
-      /* find the (logical) block component of our location */
257
-      logical_block = filepos >> BLOCK_SIZE_BITS;
258
-      offset = filepos & (BLOCK_SIZE - 1);
259
-      map = minix_block_map (logical_block);
260
-#ifdef DEBUG_MINIX
261
-      printf ("map=%d\n", map);
262
-#endif
263
-      if (map < 0)
264
-	break;
265
-
266
-      size = BLOCK_SIZE;
267
-      size -= offset;
268
-      if (size > len)
269
-	size = len;
270
-
271
-      disk_read_func = disk_read_hook;
272
-
273
-      devread (map * (BLOCK_SIZE / DEV_BSIZE),
274
-	       offset, size, buf);
275
-
276
-      disk_read_func = NULL;
277
-
278
-      buf += size;
279
-      len -= size;
280
-      filepos += size;
281
-      ret += size;
282
-    }
283
-
284
-  if (errnum)
285
-    ret = 0;
286
-
287
-  return ret;
288
-}
289
-
290
-/* preconditions: minix_mount already executed, therefore supblk in buffer
291
-     known as SUPERBLOCK
292
-   returns: 0 if error, nonzero iff we were able to find the file successfully
293
-   postconditions: on a nonzero return, buffer known as INODE contains the
294
-     inode of the file we were trying to look up
295
-   side effects: none yet  */
296
-int
297
-minix_dir (char *dirname)
298
-{
299
-  int current_ino = MINIX_ROOT_INO;  /* start at the root */
300
-  int updir_ino = current_ino;	     /* the parent of the current directory */
301
-  int ino_blk;			     /* fs pointer of the inode's info */
302
-
303
-  int str_chk = 0;		     /* used ot hold the results of a string
304
-				        compare */
305
-
306
-  struct minix_inode * raw_inode;    /* inode info for current_ino */
307
-
308
-  char linkbuf[PATH_MAX];	     /* buffer for following sym-links */
309
-  int link_count = 0;
310
-
311
-  char * rest;
312
-  char ch;
313
-
314
-  int off;			     /* offset within block of directory 
315
-					entry */
316
-  int loc;			     /* location within a directory */
317
-  int blk;			     /* which data blk within dir entry */
318
-  long map;			     /* fs pointer of a particular block from
319
-					dir entry */
320
-  struct minix_dir_entry * dp;	     /* pointer to directory entry */
321
-
322
-  /* loop invariants:
323
-     current_ino = inode to lookup
324
-     dirname = pointer to filename component we are cur looking up within
325
-     the directory known pointed to by current_ino (if any) */
326
-
327
-#ifdef DEBUG_MINIX
328
-  printf ("\n");
329
-#endif  
330
-
331
-  while (1)
332
-    {
333
-#ifdef DEBUG_MINIX
334
-      printf ("inode %d, dirname %s\n", current_ino, dirname);
335
-#endif
336
-
337
-      ino_blk = (2 + SUPERBLOCK->s_imap_blocks + SUPERBLOCK->s_zmap_blocks
338
-		 + (current_ino - 1) / MINIX_INODES_PER_BLOCK);
339
-      if (! minix_rdfsb (ino_blk, (int) INODE))
340
-	return 0;
341
-
342
-      /* reset indirect blocks! */
343
-      mapblock2 = mapblock1 = -1;
344
-
345
-      raw_inode = INODE + ((current_ino - 1) % MINIX_INODES_PER_BLOCK);
346
-
347
-      /* copy inode to fixed location */
348
-      memmove ((void *) INODE, (void *) raw_inode, 
349
-	       sizeof (struct minix_inode));
350
-
351
-      /* If we've got a symbolic link, then chase it. */
352
-      if (S_ISLNK (INODE->i_mode))
353
-	{
354
-	  int len;
355
-
356
-	  if (++link_count > MAX_LINK_COUNT)
357
-	    {
358
-	      errnum = ERR_SYMLINK_LOOP;
359
-	      return 0;
360
-	    }
361
-#ifdef DEBUG_MINIX
362
-	  printf ("S_ISLNK (%s)\n", dirname);
363
-#endif
364
-
365
-	  /* Find out how long our remaining name is. */
366
-	  len = 0;
367
-	  while (dirname[len] && !isspace (dirname[len]))
368
-	    len++;
369
-
370
-	  /* Get the symlink size. */
371
-	  filemax = (INODE->i_size);
372
-	  if (filemax + len > sizeof (linkbuf) - 2)
373
-	    {
374
-	      errnum = ERR_FILELENGTH;
375
-	      return 0;
376
-	    }
377
-
378
-	  if (len)
379
-	    {
380
-	      /* Copy the remaining name to the end of the symlink data.
381
-	         Note that DIRNAME and LINKBUF may overlap! */
382
-	      memmove (linkbuf + filemax, dirname, len);
383
-	    }
384
-	  linkbuf[filemax + len] = '\0';
385
-
386
-	  /* Read the necessary blocks, and reset the file pointer. */
387
-	  len = grub_read (linkbuf, filemax);
388
-	  filepos = 0;
389
-	  if (!len)
390
-	    return 0;
391
-
392
-#ifdef DEBUG_MINIX
393
-	  printf ("symlink=%s\n", linkbuf);
394
-#endif
395
-
396
-	  dirname = linkbuf;
397
-	  if (*dirname == '/')
398
-	    {
399
-	      /* It's an absolute link, so look it up in root. */
400
-	      current_ino = MINIX_ROOT_INO;
401
-	      updir_ino = current_ino;
402
-	    }
403
-	  else
404
-	    {
405
-	      /* Relative, so look it up in our parent directory. */
406
-	      current_ino = updir_ino;
407
-	    }
408
-
409
-	  /* Try again using the new name. */
410
-	  continue;
411
-	}
412
-
413
-      /* If end of filename, INODE points to the file's inode */
414
-      if (!*dirname || isspace (*dirname))
415
-	{
416
-	  if (!S_ISREG (INODE->i_mode))
417
-	    {
418
-	      errnum = ERR_BAD_FILETYPE;
419
-	      return 0;
420
-	    }
421
-
422
-	  filemax = (INODE->i_size);
423
-	  return 1;
424
-	}
425
-
426
-      /* else we have to traverse a directory */
427
-      updir_ino = current_ino;
428
-
429
-      /* skip over slashes */
430
-      while (*dirname == '/')
431
-	dirname++;
432
-
433
-      /* if this isn't a directory of sufficient size to hold our file, 
434
-	 abort */
435
-      if (!(INODE->i_size) || !S_ISDIR (INODE->i_mode))
436
-	{
437
-	  errnum = ERR_BAD_FILETYPE;
438
-	  return 0;
439
-	}
440
-
441
-      /* skip to next slash or end of filename (space) */
442
-      for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/';
443
-	   rest++);
444
-
445
-      /* look through this directory and find the next filename component */
446
-      /* invariant: rest points to slash after the next filename component */
447
-      *rest = 0;
448
-      loc = 0;
449
-
450
-      do
451
-	{
452
-#ifdef DEBUG_MINIX
453
-	  printf ("dirname=`%s', rest=`%s', loc=%d\n", dirname, rest, loc);
454
-#endif
455
-
456
-	  /* if our location/byte offset into the directory exceeds the size,
457
-	     give up */
458
-	  if (loc >= INODE->i_size)
459
-	    {
460
-	      if (print_possibilities < 0)
461
-		{
462
-#if 0
463
-		  putchar ('\n');
464
-#endif
465
-		}
466
-	      else
467
-		{
468
-		  errnum = ERR_FILE_NOT_FOUND;
469
-		  *rest = ch;
470
-		}
471
-	      return (print_possibilities < 0);
472
-	    }
473
-
474
-	  /* else, find the (logical) block component of our location */
475
-	  blk = loc >> BLOCK_SIZE_BITS;
476
-
477
-	  /* we know which logical block of the directory entry we are looking
478
-	     for, now we have to translate that to the physical (fs) block on
479
-	     the disk */
480
-	  map = minix_block_map (blk);
481
-#ifdef DEBUG_MINIX
482
-	  printf ("fs block=%d\n", map);
483
-#endif
484
-	  mapblock2 = -1;
485
-	  if ((map < 0) || !minix_rdfsb (map, DATABLOCK2))
486
-	    {
487
-	      errnum = ERR_FSYS_CORRUPT;
488
-	      *rest = ch;
489
-	      return 0;
490
-	    }
491
-	  off = loc & (BLOCK_SIZE - 1);
492
-	  dp = (struct minix_dir_entry *) (DATABLOCK2 + off);
493
-	  /* advance loc prematurely to next on-disk directory entry  */
494
-	  loc += sizeof (dp->inode) + namelen;
495
-
496
-	  /* NOTE: minix filenames are NULL terminated if < NAMELEN
497
-	     else exact */
498
-
499
-#ifdef DEBUG_MINIX
500
-	  printf ("directory entry ino=%d\n", dp->inode);
501
-	  if (dp->inode)
502
-	    printf ("entry=%s\n", dp->name);
503
-#endif
504
-
505
-	  if (dp->inode)
506
-	    {
507
-	      int saved_c = dp->name[namelen];
508
-
509
-	      dp->name[namelen] = 0;
510
-	      str_chk = substring (dirname, dp->name);
511
-
512
-# ifndef STAGE1_5
513
-	      if (print_possibilities && ch != '/'
514
-		  && (!*dirname || str_chk <= 0))
515
-		{
516
-		  if (print_possibilities > 0)
517
-		    print_possibilities = -print_possibilities;
518
-		  print_a_completion (dp->name);
519
-		}
520
-# endif
521
-
522
-	      dp->name[namelen] = saved_c;
523
-	    }
524
-
525
-	}
526
-      while (!dp->inode || (str_chk || (print_possibilities && ch != '/')));
527
-
528
-      current_ino = dp->inode;
529
-      *(dirname = rest) = ch;
530
-    }
531
-  /* never get here */
532
-}
533
-
534
-#endif /* FSYS_MINIX */

+ 0
- 1239
src/filo/fs/fsys_reiserfs.c
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 0
- 624
src/filo/fs/fsys_xfs.c Целия файл

@@ -1,624 +0,0 @@
1
-/* fsys_xfs.c - an implementation for the SGI XFS file system */
2
-/*  
3
- *  GRUB  --  GRand Unified Bootloader
4
- *  Copyright (C) 2001,2002  Free Software Foundation, Inc.
5
- *
6
- *  This program is free software; you can redistribute it and/or modify
7
- *  it under the terms of the GNU General Public License as published by
8
- *  the Free Software Foundation; either version 2 of the License, or
9
- *  (at your option) any later version.
10
- *
11
- *  This program is distributed in the hope that it will be useful,
12
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- *  GNU General Public License for more details.
15
- *
16
- *  You should have received a copy of the GNU General Public License
17
- *  along with this program; if not, write to the Free Software
18
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
- */
20
-
21
-#ifdef FSYS_XFS
22
-
23
-#include "shared.h"
24
-#include "filesys.h"
25
-#include "xfs.h"
26
-
27
-#define MAX_LINK_COUNT	8
28
-
29
-typedef struct xad {
30
-	xfs_fileoff_t offset;
31
-	xfs_fsblock_t start;
32
-	xfs_filblks_t len;
33
-} xad_t;
34
-
35
-struct xfs_info {
36
-	int bsize;
37
-	int dirbsize;
38
-	int isize;
39
-	unsigned int agblocks;
40
-	int bdlog;
41
-	int blklog;
42
-	int inopblog;
43
-	int agblklog;
44
-	int agnolog;
45
-	unsigned int nextents;
46
-	xfs_daddr_t next;
47
-	xfs_daddr_t daddr;
48
-	xfs_dablk_t forw;
49
-	xfs_dablk_t dablk;
50
-	xfs_bmbt_rec_32_t *xt;
51
-	xfs_bmbt_ptr_t ptr0;
52
-	int btnode_ptr0_off;
53
-	int i8param;
54
-	int dirpos;
55
-	int dirmax;
56
-	int blkoff;
57
-	int fpos;
58
-	xfs_ino_t rootino;
59
-};
60
-
61
-static struct xfs_info xfs;
62
-
63
-#define dirbuf		((char *)FSYS_BUF)
64
-#define filebuf		((char *)FSYS_BUF + 4096)
65
-#define inode		((xfs_dinode_t *)((char *)FSYS_BUF + 8192))
66
-#define icore		(inode->di_core)
67
-
68
-#define	mask32lo(n)	(((__uint32_t)1 << (n)) - 1)
69
-
70
-#define	XFS_INO_MASK(k)		((__uint32_t)((1ULL << (k)) - 1))
71
-#define	XFS_INO_OFFSET_BITS	xfs.inopblog
72
-#define	XFS_INO_AGBNO_BITS	xfs.agblklog
73
-#define	XFS_INO_AGINO_BITS	(xfs.agblklog + xfs.inopblog)
74
-#define	XFS_INO_AGNO_BITS	xfs.agnolog
75
-
76
-static inline xfs_agblock_t
77
-agino2agbno (xfs_agino_t agino)
78
-{
79
-	return agino >> XFS_INO_OFFSET_BITS;
80
-}
81
-
82
-static inline xfs_agnumber_t
83
-ino2agno (xfs_ino_t ino)
84
-{
85
-	return ino >> XFS_INO_AGINO_BITS;
86
-}
87
-
88
-static inline xfs_agino_t
89
-ino2agino (xfs_ino_t ino)
90
-{
91
-	return ino & XFS_INO_MASK(XFS_INO_AGINO_BITS);
92
-}
93
-
94
-static inline int
95
-ino2offset (xfs_ino_t ino)
96
-{
97
-	return ino & XFS_INO_MASK(XFS_INO_OFFSET_BITS);
98
-}
99
-
100
-static inline __const__ __uint16_t
101
-le16 (__uint16_t x)
102
-{
103
-	__asm__("xchgb %b0,%h0"	\
104
-		: "=q" (x) \
105
-		:  "0" (x)); \
106
-		return x;
107
-}
108
-
109
-static inline __const__ __uint32_t
110
-le32 (__uint32_t x)
111
-{
112
-#if 0
113
-        /* 386 doesn't have bswap.  */
114
-	__asm__("bswap %0" : "=r" (x) : "0" (x));
115
-#else
116
-	/* This is slower but this works on all x86 architectures.  */
117
-	__asm__("xchgb %b0, %h0" \
118
-		"\n\troll $16, %0" \
119
-		"\n\txchgb %b0, %h0" \
120
-		: "=q" (x) : "0" (x));
121
-#endif
122
-	return x;
123
-}
124
-
125
-static inline __const__ __uint64_t
126
-le64 (__uint64_t x)
127
-{
128
-	__uint32_t h = x >> 32;
129
-        __uint32_t l = x & ((1ULL<<32)-1);
130
-        return (((__uint64_t)le32(l)) << 32) | ((__uint64_t)(le32(h)));
131
-}
132
-
133
-
134
-static xfs_fsblock_t
135
-xt_start (xfs_bmbt_rec_32_t *r)
136
-{
137
-	return (((xfs_fsblock_t)(le32 (r->l1) & mask32lo(9))) << 43) | 
138
-	       (((xfs_fsblock_t)le32 (r->l2)) << 11) |
139
-	       (((xfs_fsblock_t)le32 (r->l3)) >> 21);
140
-}
141
-
142
-static xfs_fileoff_t
143
-xt_offset (xfs_bmbt_rec_32_t *r)
144
-{
145
-	return (((xfs_fileoff_t)le32 (r->l0) &
146
-		mask32lo(31)) << 23) |
147
-		(((xfs_fileoff_t)le32 (r->l1)) >> 9);
148
-}
149
-
150
-static xfs_filblks_t
151
-xt_len (xfs_bmbt_rec_32_t *r)
152
-{
153
-	return le32(r->l3) & mask32lo(21);
154
-}
155
-
156
-static inline int
157
-xfs_highbit32(__uint32_t v)
158
-{
159
-	int i;
160
-
161
-	if (--v) {
162
-		for (i = 0; i < 31; i++, v >>= 1) {
163
-			if (v == 0)
164
-				return i;
165
-		}
166
-	}
167
-	return 0;
168
-}
169
-
170
-static int
171
-isinxt (xfs_fileoff_t key, xfs_fileoff_t offset, xfs_filblks_t len)
172
-{
173
-	return (key >= offset) ? (key < offset + len ? 1 : 0) : 0;
174
-}
175
-
176
-static xfs_daddr_t
177
-agb2daddr (xfs_agnumber_t agno, xfs_agblock_t agbno)
178
-{
179
-	return ((xfs_fsblock_t)agno*xfs.agblocks + agbno) << xfs.bdlog;
180
-}
181
-
182
-static xfs_daddr_t
183
-fsb2daddr (xfs_fsblock_t fsbno)
184
-{
185
-	return agb2daddr ((xfs_agnumber_t)(fsbno >> xfs.agblklog),
186
-			 (xfs_agblock_t)(fsbno & mask32lo(xfs.agblklog)));
187
-}
188
-
189
-#undef offsetof
190
-#define offsetof(t,m)	((int)&(((t *)0)->m))
191
-
192
-static inline int
193
-btroot_maxrecs (void)
194
-{
195
-	int tmp = icore.di_forkoff ? (icore.di_forkoff << 3) : xfs.isize;
196
-
197
-	return (tmp - sizeof(xfs_bmdr_block_t) - offsetof(xfs_dinode_t, di_u)) /
198
-		(sizeof (xfs_bmbt_key_t) + sizeof (xfs_bmbt_ptr_t));
199
-}
200
-
201
-static int
202
-di_read (xfs_ino_t ino)
203
-{
204
-	xfs_agino_t agino;
205
-	xfs_agnumber_t agno;
206
-	xfs_agblock_t agbno;
207
-	xfs_daddr_t daddr;
208
-	int offset;
209
-
210
-	agno = ino2agno (ino);
211
-	agino = ino2agino (ino);
212
-	agbno = agino2agbno (agino);
213
-	offset = ino2offset (ino);
214
-	daddr = agb2daddr (agno, agbno);
215
-
216
-	devread (daddr, offset*xfs.isize, xfs.isize, (char *)inode);
217
-
218
-	xfs.ptr0 = *(xfs_bmbt_ptr_t *)
219
-		    (inode->di_u.di_c + sizeof(xfs_bmdr_block_t)
220
-		    + btroot_maxrecs ()*sizeof(xfs_bmbt_key_t));
221
-
222
-	return 1;
223
-}
224
-
225
-static void
226
-init_extents (void)
227
-{
228
-	xfs_bmbt_ptr_t ptr0;
229
-	xfs_btree_lblock_t h;
230
-
231
-	switch (icore.di_format) {
232
-	case XFS_DINODE_FMT_EXTENTS:
233
-		xfs.xt = inode->di_u.di_bmx;
234
-		xfs.nextents = le32 (icore.di_nextents);
235
-		break;
236
-	case XFS_DINODE_FMT_BTREE:
237
-		ptr0 = xfs.ptr0;
238
-		for (;;) {
239
-			xfs.daddr = fsb2daddr (le64(ptr0));
240
-			devread (xfs.daddr, 0,
241
-				 sizeof(xfs_btree_lblock_t), (char *)&h);
242
-			if (!h.bb_level) {
243
-				xfs.nextents = le16(h.bb_numrecs);
244
-				xfs.next = fsb2daddr (le64(h.bb_rightsib));
245
-				xfs.fpos = sizeof(xfs_btree_block_t);
246
-				return;
247
-			}
248
-			devread (xfs.daddr, xfs.btnode_ptr0_off,
249
-				 sizeof(xfs_bmbt_ptr_t), (char *)&ptr0);
250
-		}
251
-	}
252
-}
253
-
254
-static xad_t *
255
-next_extent (void)
256
-{
257
-	static xad_t xad;
258
-
259
-	switch (icore.di_format) {
260
-	case XFS_DINODE_FMT_EXTENTS:
261
-		if (xfs.nextents == 0)
262
-			return NULL;
263
-		break;
264
-	case XFS_DINODE_FMT_BTREE:
265
-		if (xfs.nextents == 0) {
266
-			xfs_btree_lblock_t h;
267
-			if (xfs.next == 0)
268
-				return NULL;
269
-			xfs.daddr = xfs.next;
270
-			devread (xfs.daddr, 0, sizeof(xfs_btree_lblock_t), (char *)&h);
271
-			xfs.nextents = le16(h.bb_numrecs);
272
-			xfs.next = fsb2daddr (le64(h.bb_rightsib));
273
-			xfs.fpos = sizeof(xfs_btree_block_t);
274
-		}
275
-		/* Yeah, I know that's slow, but I really don't care */
276
-		devread (xfs.daddr, xfs.fpos, sizeof(xfs_bmbt_rec_t), filebuf);
277
-		xfs.xt = (xfs_bmbt_rec_32_t *)filebuf;
278
-		xfs.fpos += sizeof(xfs_bmbt_rec_32_t);
279
-	}
280
-	xad.offset = xt_offset (xfs.xt);
281
-	xad.start = xt_start (xfs.xt);
282
-	xad.len = xt_len (xfs.xt);
283
-	++xfs.xt;
284
-	--xfs.nextents;
285
-
286
-	return &xad;
287
-}
288
-
289
-/*
290
- * Name lies - the function reads only first 100 bytes
291
- */
292
-static void
293
-xfs_dabread (void)
294
-{
295
-	xad_t *xad;
296
-	xfs_fileoff_t offset;;
297
-
298
-	init_extents ();
299
-	while ((xad = next_extent ())) {
300
-		offset = xad->offset;
301
-		if (isinxt (xfs.dablk, offset, xad->len)) {
302
-			devread (fsb2daddr (xad->start + xfs.dablk - offset),
303
-				 0, 100, dirbuf);
304
-			break;
305
-		}
306
-	}
307
-}
308
-
309
-static inline xfs_ino_t
310
-sf_ino (char *sfe, int namelen)
311
-{
312
-	void *p = sfe + namelen + 3;
313
-
314
-	return (xfs.i8param == 0)
315
-		? le64(*(xfs_ino_t *)p) : le32(*(__uint32_t *)p);
316
-}
317
-
318
-static inline xfs_ino_t
319
-sf_parent_ino (void)
320
-{
321
-	return (xfs.i8param == 0)
322
-		? le64(*(xfs_ino_t *)(&inode->di_u.di_dir2sf.hdr.parent))
323
-		: le32(*(__uint32_t *)(&inode->di_u.di_dir2sf.hdr.parent));
324
-}
325
-
326
-static inline int
327
-roundup8 (int n)
328
-{
329
-	return ((n+7)&~7);
330
-}
331
-
332
-static char *
333
-next_dentry (xfs_ino_t *ino)
334
-{
335
-	int namelen = 1;
336
-	int toread;
337
-	static char *usual[2] = {".", ".."};
338
-	static xfs_dir2_sf_entry_t *sfe;
339
-	char *name = usual[0];
340
-
341
-	if (xfs.dirpos >= xfs.dirmax) {
342
-		if (xfs.forw == 0)
343
-			return NULL;
344
-		xfs.dablk = xfs.forw;
345
-		xfs_dabread ();
346
-#define h	((xfs_dir2_leaf_hdr_t *)dirbuf)
347
-		xfs.dirmax = le16 (h->count) - le16 (h->stale);
348
-		xfs.forw = le32 (h->info.forw);
349
-#undef h
350
-		xfs.dirpos = 0;
351
-	}
352
-
353
-	switch (icore.di_format) {
354
-	case XFS_DINODE_FMT_LOCAL:
355
-		switch (xfs.dirpos) {
356
-		case -2:
357
-			*ino = 0;
358
-			break;
359
-		case -1:
360
-			*ino = sf_parent_ino ();
361
-			++name;
362
-			++namelen;
363
-			sfe = (xfs_dir2_sf_entry_t *)
364
-				(inode->di_u.di_c 
365
-				 + sizeof(xfs_dir2_sf_hdr_t)
366
-				 - xfs.i8param);
367
-			break;
368
-		default:
369
-			namelen = sfe->namelen;
370
-			*ino = sf_ino ((char *)sfe, namelen);
371
-			name = sfe->name;
372
-			sfe = (xfs_dir2_sf_entry_t *)
373
-				  ((char *)sfe + namelen + 11 - xfs.i8param);
374
-		}
375
-		break;
376
-	case XFS_DINODE_FMT_BTREE:
377
-	case XFS_DINODE_FMT_EXTENTS:
378
-#define dau	((xfs_dir2_data_union_t *)dirbuf)
379
-		for (;;) {
380
-			if (xfs.blkoff >= xfs.dirbsize) {
381
-				xfs.blkoff = sizeof(xfs_dir2_data_hdr_t);
382
-				filepos &= ~(xfs.dirbsize - 1);
383
-				filepos |= xfs.blkoff;
384
-			}
385
-			xfs_read (dirbuf, 4);
386
-			xfs.blkoff += 4;
387
-			if (dau->unused.freetag == XFS_DIR2_DATA_FREE_TAG) {
388
-				toread = roundup8 (le16(dau->unused.length)) - 4;
389
-				xfs.blkoff += toread;
390
-				filepos += toread;
391
-				continue;
392
-			}
393
-			break;
394
-		}
395
-		xfs_read ((char *)dirbuf + 4, 5);
396
-		*ino = le64 (dau->entry.inumber);
397
-		namelen = dau->entry.namelen;
398
-#undef dau
399
-		toread = roundup8 (namelen + 11) - 9;
400
-		xfs_read (dirbuf, toread);
401
-		name = (char *)dirbuf;
402
-		xfs.blkoff += toread + 5;
403
-	}
404
-	++xfs.dirpos;
405
-	name[namelen] = 0;
406
-
407
-	return name;
408
-}
409
-
410
-static char *
411
-first_dentry (xfs_ino_t *ino)
412
-{
413
-	xfs.forw = 0;
414
-	switch (icore.di_format) {
415
-	case XFS_DINODE_FMT_LOCAL:
416
-		xfs.dirmax = inode->di_u.di_dir2sf.hdr.count;
417
-		xfs.i8param = inode->di_u.di_dir2sf.hdr.i8count ? 0 : 4;
418
-		xfs.dirpos = -2;
419
-		break;
420
-	case XFS_DINODE_FMT_EXTENTS:
421
-	case XFS_DINODE_FMT_BTREE:
422
-		filepos = 0;
423
-		xfs_read (dirbuf, sizeof(xfs_dir2_data_hdr_t));
424
-		if (((xfs_dir2_data_hdr_t *)dirbuf)->magic == le32(XFS_DIR2_BLOCK_MAGIC)) {
425
-#define tail		((xfs_dir2_block_tail_t *)dirbuf)
426
-			filepos = xfs.dirbsize - sizeof(*tail);
427
-			xfs_read (dirbuf, sizeof(*tail));
428
-			xfs.dirmax = le32 (tail->count) - le32 (tail->stale);
429
-#undef tail
430
-		} else {
431
-			xfs.dablk = (1ULL << 35) >> xfs.blklog;
432
-#define h		((xfs_dir2_leaf_hdr_t *)dirbuf)
433
-#define n		((xfs_da_intnode_t *)dirbuf)
434
-			for (;;) {
435
-				xfs_dabread ();
436
-				if ((n->hdr.info.magic == le16(XFS_DIR2_LEAFN_MAGIC))
437
-				    || (n->hdr.info.magic == le16(XFS_DIR2_LEAF1_MAGIC))) {
438
-					xfs.dirmax = le16 (h->count) - le16 (h->stale);
439
-					xfs.forw = le32 (h->info.forw);
440
-					break;
441
-				}
442
-				xfs.dablk = le32 (n->btree[0].before);
443
-			}
444
-#undef n
445
-#undef h
446
-		}
447
-		xfs.blkoff = sizeof(xfs_dir2_data_hdr_t);
448
-		filepos = xfs.blkoff;
449
-		xfs.dirpos = 0;
450
-	}
451
-	return next_dentry (ino);
452
-}
453
-
454
-int
455
-xfs_mount (void)
456
-{
457
-	xfs_sb_t super;
458
-
459
-	if (!devread (0, 0, sizeof(super), (char *)&super)
460
-	    || (le32(super.sb_magicnum) != XFS_SB_MAGIC)
461
-	    || ((le16(super.sb_versionnum) 
462
-		& XFS_SB_VERSION_NUMBITS) != XFS_SB_VERSION_4) ) {
463
-		return 0;
464
-	}
465
-
466
-	xfs.bsize = le32 (super.sb_blocksize);
467
-	xfs.blklog = super.sb_blocklog;
468
-	xfs.bdlog = xfs.blklog - SECTOR_BITS;
469
-	xfs.rootino = le64 (super.sb_rootino);
470
-	xfs.isize = le16 (super.sb_inodesize);
471
-	xfs.agblocks = le32 (super.sb_agblocks);
472
-	xfs.dirbsize = xfs.bsize << super.sb_dirblklog;
473
-
474
-	xfs.inopblog = super.sb_inopblog;
475
-	xfs.agblklog = super.sb_agblklog;
476
-	xfs.agnolog = xfs_highbit32 (le32(super.sb_agcount));
477
-
478
-	xfs.btnode_ptr0_off =
479
-		((xfs.bsize - sizeof(xfs_btree_block_t)) /
480
-		(sizeof (xfs_bmbt_key_t) + sizeof (xfs_bmbt_ptr_t)))
481
-		 * sizeof(xfs_bmbt_key_t) + sizeof(xfs_btree_block_t);
482
-
483
-	return 1;
484
-}
485
-
486
-int
487
-xfs_read (char *buf, int len)
488
-{
489
-	xad_t *xad;
490
-	xfs_fileoff_t endofprev, endofcur, offset;
491
-	xfs_filblks_t xadlen;
492
-	int toread, startpos, endpos;
493
-
494
-	if (icore.di_format == XFS_DINODE_FMT_LOCAL) {
495
-		grub_memmove (buf, inode->di_u.di_c + filepos, len);
496
-		filepos += len;
497
-		return len;
498
-	}
499
-
500
-	startpos = filepos;
501
-	endpos = filepos + len;
502
-	endofprev = (xfs_fileoff_t)-1;
503
-	init_extents ();
504
-	while (len > 0 && (xad = next_extent ())) {
505
-		offset = xad->offset;
506
-		xadlen = xad->len;
507
-		if (isinxt (filepos >> xfs.blklog, offset, xadlen)) {
508
-			endofcur = (offset + xadlen) << xfs.blklog; 
509
-			toread = (endofcur >= endpos)
510
-				  ? len : (endofcur - filepos);
511
-
512
-			disk_read_func = disk_read_hook;
513
-			devread (fsb2daddr (xad->start),
514
-				 filepos - (offset << xfs.blklog), toread, buf);
515
-			disk_read_func = NULL;
516
-
517
-			buf += toread;
518
-			len -= toread;
519
-			filepos += toread;
520
-		} else if (offset > endofprev) {
521
-			toread = ((offset << xfs.blklog) >= endpos)
522
-				  ? len : ((offset - endofprev) << xfs.blklog);
523
-			len -= toread;
524
-			filepos += toread;
525
-			for (; toread; toread--) {
526
-				*buf++ = 0;
527
-			}
528
-			continue;
529
-		}
530
-		endofprev = offset + xadlen; 
531
-	}
532
-
533
-	return filepos - startpos;
534
-}
535
-
536
-int
537
-xfs_dir (char *dirname)
538
-{
539
-	xfs_ino_t ino, parent_ino, new_ino;
540
-	xfs_fsize_t di_size;
541
-	int di_mode;
542
-	int cmp, n, link_count;
543
-	char linkbuf[xfs.bsize];
544
-	char *rest, *name, ch;
545
-
546
-	parent_ino = ino = xfs.rootino;
547
-	link_count = 0;
548
-	for (;;) {
549
-		di_read (ino);
550
-		di_size = le64 (icore.di_size);
551
-		di_mode = le16 (icore.di_mode);
552
-
553
-		if ((di_mode & IFMT) == IFLNK) {
554
-			if (++link_count > MAX_LINK_COUNT) {
555
-				errnum = ERR_SYMLINK_LOOP;
556
-				return 0;
557
-			}
558
-			if (di_size < xfs.bsize - 1) {
559
-				filepos = 0;
560
-				filemax = di_size;
561
-				n = xfs_read (linkbuf, filemax);
562
-			} else {
563
-				errnum = ERR_FILELENGTH;
564
-				return 0;
565
-			}
566
-
567
-			ino = (linkbuf[0] == '/') ? xfs.rootino : parent_ino;
568
-			while (n < (xfs.bsize - 1) && (linkbuf[n++] = *dirname++));
569
-			linkbuf[n] = 0;
570
-			dirname = linkbuf;
571
-			continue;
572
-		}
573
-
574
-		if (!*dirname || isspace (*dirname)) {
575
-			if ((di_mode & IFMT) != IFREG) {
576
-				errnum = ERR_BAD_FILETYPE;
577
-				return 0;
578
-			}
579
-			filepos = 0;
580
-			filemax = di_size;
581
-			return 1;
582
-		}
583
-
584
-		if ((di_mode & IFMT) != IFDIR) {
585
-			errnum = ERR_BAD_FILETYPE;
586
-			return 0;
587
-		}
588
-
589
-		for (; *dirname == '/'; dirname++);
590
-
591
-		for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/'; rest++);
592
-		*rest = 0;
593
-
594
-		name = first_dentry (&new_ino);
595
-		for (;;) {
596
-			cmp = (!*dirname) ? -1 : substring (dirname, name);
597
-#ifndef STAGE1_5
598
-			if (print_possibilities && ch != '/' && cmp <= 0) {
599
-				if (print_possibilities > 0)
600
-					print_possibilities = -print_possibilities;
601
-				print_a_completion (name);
602
-			} else
603
-#endif
604
-			if (cmp == 0) {
605
-				parent_ino = ino;
606
-				if (new_ino)
607
-					ino = new_ino;
608
-		        	*(dirname = rest) = ch;
609
-				break;
610
-			}
611
-			name = next_dentry (&new_ino);
612
-			if (name == NULL) {
613
-				if (print_possibilities < 0)
614
-					return 1;
615
-
616
-				errnum = ERR_FILE_NOT_FOUND;
617
-				*rest = ch;
618
-				return 0;
619
-			}
620
-		}
621
-	}
622
-}
623
-
624
-#endif /* FSYS_XFS */

+ 0
- 168
src/filo/fs/iso9660.h Целия файл

@@ -1,168 +0,0 @@
1
-/*
2
- *  ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader)
3
- *  including Rock Ridge Extensions support
4
- *
5
- *  Copyright (C) 1998, 1999  Kousuke Takai  <tak@kmc.kyoto-u.ac.jp>
6
- *
7
- *  This program is free software; you can redistribute it and/or modify
8
- *  it under the terms of the GNU General Public License as published by
9
- *  the Free Software Foundation; either version 2 of the License, or
10
- *  (at your option) any later version.
11
- *
12
- *  This program is distributed in the hope that it will be useful,
13
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- *  GNU General Public License for more details.
16
- *
17
- *  You should have received a copy of the GNU General Public License
18
- *  along with this program; if not, write to the Free Software
19
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
- */
21
-/*
22
- *  References:
23
- *	linux/fs/isofs/rock.[ch]
24
- *	mkisofs-1.11.1/diag/isoinfo.c
25
- *	mkisofs-1.11.1/iso9660.h
26
- *		(all are written by Eric Youngdale)
27
- */
28
-
29
-/*
30
- * Modified by SONE Takeshi to work with FILO
31
- */
32
-
33
-#ifndef _ISO9660_H_
34
-#define _ISO9660_H_
35
-
36
-#define ISO_SECTOR_BITS              (11)
37
-#define ISO_SECTOR_SIZE              (1<<ISO_SECTOR_BITS)
38
-
39
-#define	ISO_REGULAR	1	/* regular file	*/
40
-#define	ISO_DIRECTORY	2	/* directory	*/
41
-#define	ISO_OTHER	0	/* other file (with Rock Ridge) */
42
-
43
-#define	RR_FLAG_PX	0x01	/* have POSIX file attributes */
44
-#define	RR_FLAG_NM	0x08	/* have alternate file name   */
45
-
46
-/* POSIX file attributes for Rock Ridge extensions */
47
-#define	POSIX_S_IFMT	0xF000
48
-#define	POSIX_S_IFREG	0x8000
49
-#define	POSIX_S_IFDIR	0x4000
50
-
51
-/* volume descriptor types */
52
-#define ISO_VD_PRIMARY 1
53
-#define ISO_VD_END 255
54
-
55
-#define ISO_STANDARD_ID "CD001"
56
-
57
-#ifndef ASM_FILE
58
-
59
-typedef uint8_t   u_int8_t;
60
-typedef uint16_t  u_int16_t;
61
-typedef uint32_t  u_int32_t;
62
-
63
-typedef	union {
64
- u_int8_t l,b;
65
-}	iso_8bit_t;
66
-
67
-typedef	struct __iso_16bit {
68
-	u_int16_t l, b;
69
-} iso_16bit_t __attribute__ ((packed));
70
-
71
-typedef	struct __iso_32bit {
72
-	u_int32_t l, b;
73
-} iso_32bit_t __attribute__ ((packed));
74
-
75
-typedef u_int8_t		iso_date_t[7];
76
-
77
-struct iso_directory_record {
78
-	iso_8bit_t	length;
79
-	iso_8bit_t	ext_attr_length;
80
-	iso_32bit_t	extent;
81
-	iso_32bit_t	size;
82
-	iso_date_t	date;
83
-	iso_8bit_t	flags;
84
-	iso_8bit_t	file_unit_size;
85
-	iso_8bit_t	interleave;
86
-	iso_16bit_t	volume_seq_number;
87
-	iso_8bit_t	name_len;
88
-	u_int8_t	name[1];
89
-} __attribute__ ((packed));
90
-
91
-struct iso_primary_descriptor {
92
-	iso_8bit_t	type;
93
-	u_int8_t	id[5];
94
-	iso_8bit_t	version;
95
-	u_int8_t	_unused1[1];
96
-	u_int8_t	system_id[32];
97
-	u_int8_t	volume_id[32];
98
-	u_int8_t	_unused2[8];
99
-	iso_32bit_t	volume_space_size;
100
-	u_int8_t	_unused3[32];
101
-	iso_16bit_t	volume_set_size;
102
-	iso_16bit_t	volume_seq_number;
103
-	iso_16bit_t	logical_block_size;
104
-	iso_32bit_t	path_table_size;
105
-	u_int8_t	type_l_path_table[4];
106
-	u_int8_t	opt_type_l_path_table[4];
107
-	u_int8_t	type_m_path_table[4];
108
-	u_int8_t	opt_type_m_path_table[4];
109
-	struct iso_directory_record root_directory_record;
110
-	u_int8_t	volume_set_id[128];
111
-	u_int8_t	publisher_id[128];
112
-	u_int8_t	preparer_id[128];
113
-	u_int8_t	application_id[128];
114
-	u_int8_t	copyright_file_id[37];
115
-	u_int8_t	abstract_file_id[37];
116
-	u_int8_t	bibliographic_file_id[37];
117
-	u_int8_t	creation_date[17];
118
-	u_int8_t	modification_date[17];
119
-	u_int8_t	expiration_date[17];
120
-	u_int8_t	effective_date[17];
121
-	iso_8bit_t	file_structure_version;
122
-	u_int8_t	_unused4[1];
123
-	u_int8_t	application_data[512];
124
-	u_int8_t	_unused5[653];
125
-} __attribute__ ((packed));
126
-
127
-struct rock_ridge {
128
-	u_int16_t	signature;
129
-	u_int8_t	len;
130
-	u_int8_t	version;
131
-	union {
132
-	  struct CE {
133
-	    iso_32bit_t	extent;
134
-	    iso_32bit_t	offset;
135
-	    iso_32bit_t	size;
136
-	  } ce;
137
-	  struct NM {
138
-	    iso_8bit_t	flags;
139
-	    u_int8_t	name[0];
140
-	  } nm;
141
-	  struct PX {
142
-	    iso_32bit_t	mode;
143
-	    iso_32bit_t	nlink;
144
-	    iso_32bit_t	uid;
145
-	    iso_32bit_t	gid;
146
-	  } px;
147
-	  struct RR {
148
-	    iso_8bit_t	flags;
149
-	  } rr;
150
-	} u;
151
-} __attribute__ ((packed));
152
-
153
-typedef	union RR_ptr {
154
-	struct rock_ridge *rr;
155
-	char		  *ptr;
156
-	int		   i;
157
-} RR_ptr_t;
158
-
159
-#define	RRMAGIC(c1, c2)	((c1)|(c2) << 8)
160
-
161
-#define	CHECK2(ptr, c1, c2) \
162
-	(*(unsigned short *)(ptr) == (((c1) | (c2) << 8) & 0xFFFF))
163
-#define	CHECK4(ptr, c1, c2, c3, c4) \
164
-	(*(unsigned long *)(ptr) == ((c1) | (c2)<<8 | (c3)<<16 | (c4)<<24))
165
-
166
-#endif /* !ASM_FILE */
167
-
168
-#endif /* _ISO9660_H_ */

+ 0
- 601
src/filo/fs/jfs.h Целия файл

@@ -1,601 +0,0 @@
1
-/* jfs.h - an extractions from linux/include/linux/jfs/jfs* into one file */
2
-/*   
3
- *  GRUB  --  GRand Unified Bootloader
4
- *  Copyright (C) 2000  International Business Machines  Corp.
5
- *  Copyright (C) 2001  Free Software Foundation, Inc.
6
- *
7
- *  This program is free software;  you can redistribute it and/or modify
8
- *  it under the terms of the GNU General Public License as published by
9
- *  the Free Software Foundation; either version 2 of the License, or 
10
- *  (at your option) any later version.
11
- * 
12
- *  This program is distributed in the hope that it will be useful,
13
- *  but WITHOUT ANY WARRANTY;  without even the implied warranty of
14
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15
- *  the GNU General Public License for more details.
16
- *
17
- *  You should have received a copy of the GNU General Public License
18
- *  along with this program;  if not, write to the Free Software 
19
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
- */
21
-
22
-#ifndef _JFS_H_
23
-#define _JFS_H_
24
-
25
-/* those are from jfs_filsys.h */
26
-
27
-/*
28
- *	 file system option (superblock flag)
29
- */
30
-/* platform option (conditional compilation) */
31
-#define JFS_AIX		0x80000000	/* AIX support */
32
-/*	POSIX name/directory  support */
33
-
34
-#define JFS_OS2		0x40000000	/* OS/2 support */
35
-/*	case-insensitive name/directory support */
36
-
37
-#define JFS_LINUX      	0x10000000	/* Linux support */
38
-/*	case-sensitive name/directory support */
39
-
40
-/* directory option */
41
-#define JFS_UNICODE	0x00000001	/* unicode name */
42
-
43
-/* bba */
44
-#define	JFS_SWAP_BYTES		0x00100000	/* running on big endian computer */
45
-
46
-
47
-/*
48
- *	buffer cache configuration
49
- */
50
-/* page size */
51
-#ifdef PSIZE
52
-#undef PSIZE
53
-#endif
54
-#define	PSIZE		4096	/* page size (in byte) */
55
-
56
-/*
57
- *	fs fundamental size
58
- *
59
- * PSIZE >= file system block size >= PBSIZE >= DISIZE
60
- */
61
-#define	PBSIZE		512	/* physical block size (in byte) */
62
-#define DISIZE		512	/* on-disk inode size (in byte) */
63
-#define L2DISIZE	9
64
-#define	INOSPERIAG	4096	/* number of disk inodes per iag */
65
-#define	L2INOSPERIAG	12
66
-#define INOSPEREXT	32	/* number of disk inode per extent */
67
-#define L2INOSPEREXT	5
68
-
69
-/* Minimum number of bytes supported for a JFS partition */
70
-#define MINJFS			(0x1000000)
71
-
72
-/*
73
- * fixed byte offset address
74
- */
75
-#define SUPER1_OFF	0x8000	/* primary superblock */
76
-
77
-#define AITBL_OFF	(SUPER1_OFF + PSIZE + (PSIZE << 1))
78
-
79
-/*
80
- *	fixed reserved inode number
81
- */
82
-/* aggregate inode */
83
-#define	AGGREGATE_I	1	/* aggregate inode map inode */
84
-#define	FILESYSTEM_I	16	/* 1st/only fileset inode in ait:
85
-				 * fileset inode map inode
86
-				 */
87
-
88
-/* per fileset inode */
89
-#define	ROOT_I		2	/* fileset root inode */
90
-
91
-/*
92
- *	directory configuration
93
- */
94
-#define JFS_NAME_MAX	255
95
-#define JFS_PATH_MAX	PSIZE
96
-
97
-typedef unsigned char u8;
98
-typedef char s8;
99
-typedef unsigned short u16;
100
-typedef short s16;
101
-typedef unsigned int u32;
102
-typedef int s32;
103
-typedef unsigned long long u64;
104
-typedef long long s64;
105
-
106
-typedef u16 UniChar;
107
-
108
-/* these from jfs_btree.h */
109
-
110
-/* btpaget_t flag */
111
-#define BT_TYPE		0x07	/* B+-tree index */
112
-#define	BT_ROOT		0x01	/* root page */
113
-#define	BT_LEAF		0x02	/* leaf page */
114
-#define	BT_INTERNAL	0x04	/* internal page */
115
-#define	BT_RIGHTMOST	0x10	/* rightmost page */
116
-#define	BT_LEFTMOST	0x20	/* leftmost page */
117
-
118
-/* those are from jfs_types.h */
119
-
120
-struct timestruc_t {
121
-	u32 tv_sec;
122
-	u32 tv_nsec;
123
-};
124
-
125
-/*
126
- *	physical xd (pxd)
127
- */
128
-typedef struct {
129
-	unsigned len:24;
130
-	unsigned addr1:8;
131
-	u32 addr2;
132
-} pxd_t;
133
-
134
-/* xd_t field extraction */
135
-#define	lengthPXD(pxd)	((pxd)->len)
136
-#define	addressPXD(pxd)	(((s64)((pxd)->addr1)) << 32 | ((pxd)->addr2))
137
-
138
-/*
139
- *	data extent descriptor (dxd)
140
- */
141
-typedef struct {
142
-	unsigned flag:8;	/* 1: flags */
143
-	unsigned rsrvd:24;	/* 3: */
144
-	u32 size;		/* 4: size in byte */
145
-	unsigned len:24;	/* 3: length in unit of fsblksize */
146
-	unsigned addr1:8;	/* 1: address in unit of fsblksize */
147
-	u32 addr2;		/* 4: address in unit of fsblksize */
148
-} dxd_t;			/* - 16 - */
149
-
150
-/*
151
- *	DASD limit information - stored in directory inode
152
- */
153
-typedef struct dasd {
154
-	u8 thresh;		/* Alert Threshold (in percent) */
155
-	u8 delta;		/* Alert Threshold delta (in percent)   */
156
-	u8 rsrvd1;
157
-	u8 limit_hi;		/* DASD limit (in logical blocks)       */
158
-	u32 limit_lo;		/* DASD limit (in logical blocks)       */
159
-	u8 rsrvd2[3];
160
-	u8 used_hi;		/* DASD usage (in logical blocks)       */
161
-	u32 used_lo;		/* DASD usage (in logical blocks)       */
162
-} dasd_t;
163
-
164
-
165
-/* from jfs_superblock.h */
166
-
167
-#define JFS_MAGIC 	0x3153464A	/* "JFS1" */
168
-
169
-struct jfs_superblock
170
-{
171
-	u32 s_magic;		/* 4: magic number */
172
-	u32 s_version;		/* 4: version number */
173
-
174
-	s64 s_size;		/* 8: aggregate size in hardware/LVM blocks;
175
-				 * VFS: number of blocks
176
-				 */
177
-	s32 s_bsize;		/* 4: aggregate block size in bytes; 
178
-				 * VFS: fragment size
179
-				 */
180
-	s16 s_l2bsize;		/* 2: log2 of s_bsize */
181
-	s16 s_l2bfactor;	/* 2: log2(s_bsize/hardware block size) */
182
-	s32 s_pbsize;		/* 4: hardware/LVM block size in bytes */
183
-	s16 s_l2pbsize;		/* 2: log2 of s_pbsize */
184
-	s16 pad;		/* 2: padding necessary for alignment */
185
-
186
-	u32 s_agsize;		/* 4: allocation group size in aggr. blocks */
187
-
188
-	u32 s_flag;		/* 4: aggregate attributes:
189
-				 *    see jfs_filsys.h
190
-				 */
191
-	u32 s_state;		/* 4: mount/unmount/recovery state: 
192
-				 *    see jfs_filsys.h
193
-				 */
194
-	s32 s_compress;		/* 4: > 0 if data compression */
195
-
196
-	pxd_t s_ait2;		/* 8: first extent of secondary
197
-				 *    aggregate inode table
198
-				 */
199
-
200
-	pxd_t s_aim2;		/* 8: first extent of secondary
201
-				 *    aggregate inode map
202
-				 */
203
-	u32 s_logdev;		/* 4: device address of log */
204
-	s32 s_logserial;	/* 4: log serial number at aggregate mount */
205
-	pxd_t s_logpxd;		/* 8: inline log extent */
206
-
207
-	pxd_t s_fsckpxd;	/* 8: inline fsck work space extent */
208
-
209
-	struct timestruc_t s_time;	/* 8: time last updated */
210
-
211
-	s32 s_fsckloglen;	/* 4: Number of filesystem blocks reserved for
212
-				 *    the fsck service log.  
213
-				 *    N.B. These blocks are divided among the
214
-				 *         versions kept.  This is not a per
215
-				 *         version size.
216
-				 *    N.B. These blocks are included in the 
217
-				 *         length field of s_fsckpxd.
218
-				 */
219
-	s8 s_fscklog;		/* 1: which fsck service log is most recent
220
-				 *    0 => no service log data yet
221
-				 *    1 => the first one
222
-				 *    2 => the 2nd one
223
-				 */
224
-	char s_fpack[11];	/* 11: file system volume name 
225
-				 *     N.B. This must be 11 bytes to
226
-				 *          conform with the OS/2 BootSector
227
-				 *          requirements
228
-				 */
229
-
230
-	/* extendfs() parameter under s_state & FM_EXTENDFS */
231
-	s64 s_xsize;		/* 8: extendfs s_size */
232
-	pxd_t s_xfsckpxd;	/* 8: extendfs fsckpxd */
233
-	pxd_t s_xlogpxd;	/* 8: extendfs logpxd */
234
-	/* - 128 byte boundary - */
235
-
236
-	/*
237
-	 *      DFS VFS support (preliminary) 
238
-	 */
239
-	char s_attach;		/* 1: VFS: flag: set when aggregate is attached
240
-				 */
241
-	u8 rsrvd4[7];		/* 7: reserved - set to 0 */
242
-
243
-	u64 totalUsable;	/* 8: VFS: total of 1K blocks which are
244
-				 * available to "normal" (non-root) users.
245
-				 */
246
-	u64 minFree;		/* 8: VFS: # of 1K blocks held in reserve for 
247
-				 * exclusive use of root.  This value can be 0,
248
-				 * and if it is then totalUsable will be equal 
249
-				 * to # of blocks in aggregate.  I believe this
250
-				 * means that minFree + totalUsable = # blocks.
251
-				 * In that case, we don't need to store both 
252
-				 * totalUsable and minFree since we can compute
253
-				 * one from the other.  I would guess minFree 
254
-				 * would be the one we should store, and 
255
-				 * totalUsable would be the one we should 
256
-				 * compute.  (Just a guess...)
257
-				 */
258
-
259
-	u64 realFree;		/* 8: VFS: # of free 1K blocks can be used by 
260
-				 * "normal" users.  It may be this is something
261
-				 * we should compute when asked for instead of 
262
-				 * storing in the superblock.  I don't know how
263
-				 * often this information is needed.
264
-				 */
265
-	/*
266
-	 *      graffiti area
267
-	 */
268
-};
269
-
270
-/* from jfs_dtree.h */
271
-
272
-/*
273
- *      entry segment/slot
274
- *
275
- * an entry consists of type dependent head/only segment/slot and
276
- * additional segments/slots linked vi next field;
277
- * N.B. last/only segment of entry is terminated by next = -1;
278
- */
279
-/*
280
- *	directory page slot
281
- */
282
-typedef struct {
283
-	s8 next;		/* 1: */
284
-	s8 cnt;			/* 1: */
285
-	UniChar name[15];	/* 30: */
286
-} dtslot_t;			/* (32) */
287
-
288
-#define DTSLOTDATALEN	15
289
-
290
-/*
291
- *	 internal node entry head/only segment
292
- */
293
-typedef struct {
294
-	pxd_t xd;		/* 8: child extent descriptor */
295
-
296
-	s8 next;		/* 1: */
297
-	u8 namlen;		/* 1: */
298
-	UniChar name[11];	/* 22: 2-byte aligned */
299
-} idtentry_t;			/* (32) */
300
-
301
-/*
302
- *	leaf node entry head/only segment
303
- *
304
- * 	For legacy filesystems, name contains 13 unichars -- no index field
305
- */
306
-typedef struct {
307
-	u32 inumber;		/* 4: 4-byte aligned */
308
-	s8 next;		/* 1: */
309
-	u8 namlen;		/* 1: */
310
-	UniChar name[11];	/* 22: 2-byte aligned */
311
-	u32 index;		/* 4: index into dir_table */
312
-} ldtentry_t;			/* (32) */
313
-
314
-#define DTLHDRDATALEN	11
315
-
316
-/*
317
- * dir_table used for directory traversal during readdir
318
-*/ 
319
-
320
-/*
321
- * Maximum entry in inline directory table
322
- */
323
-
324
-typedef struct dir_table_slot {
325
-	u8 rsrvd;	/* 1: */
326
-	u8 flag;	/* 1: 0 if free */
327
-	u8 slot;	/* 1: slot within leaf page of entry */
328
-	u8 addr1;	/* 1: upper 8 bits of leaf page address */
329
-	u32 addr2;	/* 4: lower 32 bits of leaf page address -OR-
330
-			      index of next entry when this entry was deleted */
331
-} dir_table_slot_t;	/* (8) */
332
-
333
-/*
334
- *	directory root page (in-line in on-disk inode):
335
- *
336
- * cf. dtpage_t below.
337
- */
338
-typedef union {
339
-	struct {
340
-		dasd_t DASD;	/* 16: DASD limit/usage info  F226941 */
341
-
342
-		u8 flag;	/* 1: */
343
-		s8 nextindex;	/* 1: next free entry in stbl */
344
-		s8 freecnt;	/* 1: free count */
345
-		s8 freelist;	/* 1: freelist header */
346
-
347
-		u32 idotdot;	/* 4: parent inode number */
348
-
349
-		s8 stbl[8];	/* 8: sorted entry index table */
350
-	} header;		/* (32) */
351
-
352
-	dtslot_t slot[9];
353
-} dtroot_t;
354
-
355
-/*
356
- *	directory regular page:
357
- *
358
- *	entry slot array of 32 byte slot
359
- *
360
- * sorted entry slot index table (stbl):
361
- * contiguous slots at slot specified by stblindex,
362
- * 1-byte per entry
363
- *   512 byte block:  16 entry tbl (1 slot)
364
- *  1024 byte block:  32 entry tbl (1 slot)
365
- *  2048 byte block:  64 entry tbl (2 slot)
366
- *  4096 byte block: 128 entry tbl (4 slot)
367
- *
368
- * data area:
369
- *   512 byte block:  16 - 2 =  14 slot
370
- *  1024 byte block:  32 - 2 =  30 slot
371
- *  2048 byte block:  64 - 3 =  61 slot
372
- *  4096 byte block: 128 - 5 = 123 slot
373
- *
374
- * N.B. index is 0-based; index fields refer to slot index
375
- * except nextindex which refers to entry index in stbl;
376
- * end of entry stot list or freelist is marked with -1.
377
- */
378
-typedef union {
379
-	struct {
380
-		s64 next;	/* 8: next sibling */
381
-		s64 prev;	/* 8: previous sibling */
382
-
383
-		u8 flag;	/* 1: */
384
-		s8 nextindex;	/* 1: next entry index in stbl */
385
-		s8 freecnt;	/* 1: */
386
-		s8 freelist;	/* 1: slot index of head of freelist */
387
-
388
-		u8 maxslot;	/* 1: number of slots in page slot[] */
389
-		s8 stblindex;	/* 1: slot index of start of stbl */
390
-		u8 rsrvd[2];	/* 2: */
391
-
392
-		pxd_t self;	/* 8: self pxd */
393
-	} header;		/* (32) */
394
-
395
-	dtslot_t slot[128];
396
-} dtpage_t;
397
-
398
-/* from jfs_xtree.h */
399
-
400
-/*
401
- *      extent allocation descriptor (xad)
402
- */
403
-typedef struct xad {
404
-	unsigned flag:8;	/* 1: flag */
405
-	unsigned rsvrd:16;	/* 2: reserved */
406
-	unsigned off1:8;	/* 1: offset in unit of fsblksize */
407
-	u32 off2;		/* 4: offset in unit of fsblksize */
408
-	unsigned len:24;	/* 3: length in unit of fsblksize */
409
-	unsigned addr1:8;	/* 1: address in unit of fsblksize */
410
-	u32 addr2;		/* 4: address in unit of fsblksize */
411
-} xad_t;			/* (16) */
412
-
413
-/* xad_t field extraction */
414
-#define offsetXAD(xad)	(((s64)((xad)->off1)) << 32 | ((xad)->off2))
415
-#define addressXAD(xad)	(((s64)((xad)->addr1)) << 32 | ((xad)->addr2))
416
-#define lengthXAD(xad)	((xad)->len)
417
-
418
-/* possible values for maxentry */
419
-#define XTPAGEMAXSLOT   256
420
-#define XTENTRYSTART    2
421
-
422
-/*
423
- *      xtree page:
424
- */
425
-typedef union {
426
-	struct xtheader {
427
-		s64 next;	/* 8: */
428
-		s64 prev;	/* 8: */
429
-
430
-		u8 flag;	/* 1: */
431
-		u8 rsrvd1;	/* 1: */
432
-		s16 nextindex;	/* 2: next index = number of entries */
433
-		s16 maxentry;	/* 2: max number of entries */
434
-		s16 rsrvd2;	/* 2: */
435
-
436
-		pxd_t self;	/* 8: self */
437
-	} header;		/* (32) */
438
-
439
-	xad_t xad[XTPAGEMAXSLOT];	/* 16 * maxentry: xad array */
440
-} xtpage_t;
441
-
442
-/* from jfs_dinode.h */
443
-
444
-struct dinode {
445
-	/*
446
-	 *      I. base area (128 bytes)
447
-	 *      ------------------------
448
-	 *
449
-	 * define generic/POSIX attributes
450
-	 */
451
-	u32 di_inostamp;	/* 4: stamp to show inode belongs to fileset */
452
-	s32 di_fileset;		/* 4: fileset number */
453
-	u32 di_number;		/* 4: inode number, aka file serial number */
454
-	u32 di_gen;		/* 4: inode generation number */
455
-
456
-	pxd_t di_ixpxd;		/* 8: inode extent descriptor */
457
-
458
-	s64 di_size;		/* 8: size */
459
-	s64 di_nblocks;		/* 8: number of blocks allocated */
460
-
461
-	u32 di_nlink;		/* 4: number of links to the object */
462
-
463
-	u32 di_uid;		/* 4: user id of owner */
464
-	u32 di_gid;		/* 4: group id of owner */
465
-
466
-	u32 di_mode;		/* 4: attribute, format and permission */
467
-
468
-	struct timestruc_t di_atime;	/* 8: time last data accessed */
469
-	struct timestruc_t di_ctime;	/* 8: time last status changed */
470
-	struct timestruc_t di_mtime;	/* 8: time last data modified */
471
-	struct timestruc_t di_otime;	/* 8: time created */
472
-
473
-	dxd_t di_acl;		/* 16: acl descriptor */
474
-
475
-	dxd_t di_ea;		/* 16: ea descriptor */
476
-
477
-	s32 di_next_index;  /* 4: Next available dir_table index */
478
-
479
-	s32 di_acltype;		/* 4: Type of ACL */
480
-
481
-	/*
482
-	 * 	Extension Areas.
483
-	 *
484
-	 *	Historically, the inode was partitioned into 4 128-byte areas,
485
-	 *	the last 3 being defined as unions which could have multiple
486
-	 *	uses.  The first 96 bytes had been completely unused until
487
-	 *	an index table was added to the directory.  It is now more
488
-	 *	useful to describe the last 3/4 of the inode as a single
489
-	 *	union.  We would probably be better off redesigning the
490
-	 *	entire structure from scratch, but we don't want to break
491
-	 *	commonality with OS/2's JFS at this time.
492
-	 */
493
-	union {
494
-		struct {
495
-			/*
496
-			 * This table contains the information needed to
497
-			 * find a directory entry from a 32-bit index.
498
-			 * If the index is small enough, the table is inline,
499
-			 * otherwise, an x-tree root overlays this table
500
-			 */
501
-			dir_table_slot_t _table[12];	/* 96: inline */
502
-
503
-			dtroot_t _dtroot;		/* 288: dtree root */
504
-		} _dir;					/* (384) */
505
-#define di_dirtable	u._dir._table
506
-#define di_dtroot	u._dir._dtroot
507
-#define di_parent       di_dtroot.header.idotdot
508
-#define di_DASD		di_dtroot.header.DASD
509
-
510
-		struct {
511
-			union {
512
-				u8 _data[96];		/* 96: unused */
513
-				struct {
514
-					void *_imap;	/* 4: unused */
515
-					u32 _gengen;	/* 4: generator */
516
-				} _imap;
517
-			} _u1;				/* 96: */
518
-#define di_gengen	u._file._u1._imap._gengen
519
-
520
-			union {
521
-				xtpage_t _xtroot;
522
-				struct {
523
-					u8 unused[16];	/* 16: */
524
-					dxd_t _dxd;	/* 16: */
525
-					union {
526
-						u32 _rdev;	/* 4: */
527
-						u8 _fastsymlink[128];
528
-					} _u;
529
-					u8 _inlineea[128];
530
-				} _special;
531
-			} _u2;
532
-		} _file;
533
-#define di_xtroot	u._file._u2._xtroot
534
-#define di_dxd		u._file._u2._special._dxd
535
-#define di_btroot	di_xtroot
536
-#define di_inlinedata	u._file._u2._special._u
537
-#define di_rdev		u._file._u2._special._u._rdev
538
-#define di_fastsymlink	u._file._u2._special._u._fastsymlink
539
-#define di_inlineea     u._file._u2._special._inlineea
540
-	} u;
541
-};
542
-
543
-typedef struct dinode dinode_t;
544
-
545
-/* di_mode */
546
-#define IFMT	0xF000		/* S_IFMT - mask of file type */
547
-#define IFDIR	0x4000		/* S_IFDIR - directory */
548
-#define IFREG	0x8000		/* S_IFREG - regular file */
549
-#define IFLNK	0xA000		/* S_IFLNK - symbolic link */
550
-
551
-/* extended mode bits (on-disk inode di_mode) */
552
-#define INLINEEA        0x00040000	/* inline EA area free */
553
-
554
-/* from jfs_imap.h */
555
-
556
-#define	EXTSPERIAG	128	/* number of disk inode extent per iag  */
557
-#define SMAPSZ		4	/* number of words per summary map      */
558
-#define	MAXAG		128	/* maximum number of allocation groups  */
559
-
560
-/*
561
- *	inode allocation map:
562
- * 
563
- * inode allocation map consists of 
564
- * . the inode map control page and
565
- * . inode allocation group pages (per 4096 inodes)
566
- * which are addressed by standard JFS xtree.
567
- */
568
-/*
569
- *	inode allocation group page (per 4096 inodes of an AG)
570
- */
571
-typedef struct {
572
-	s64 agstart;		/* 8: starting block of ag              */
573
-	s32 iagnum;		/* 4: inode allocation group number     */
574
-	s32 inofreefwd;		/* 4: ag inode free list forward        */
575
-	s32 inofreeback;	/* 4: ag inode free list back           */
576
-	s32 extfreefwd;		/* 4: ag inode extent free list forward */
577
-	s32 extfreeback;	/* 4: ag inode extent free list back    */
578
-	s32 iagfree;		/* 4: iag free list                     */
579
-
580
-	/* summary map: 1 bit per inode extent */
581
-	s32 inosmap[SMAPSZ];	/* 16: sum map of mapwords w/ free inodes;
582
-				 *      note: this indicates free and backed
583
-				 *      inodes, if the extent is not backed the
584
-				 *      value will be 1.  if the extent is
585
-				 *      backed but all inodes are being used the
586
-				 *      value will be 1.  if the extent is
587
-				 *      backed but at least one of the inodes is
588
-				 *      free the value will be 0.
589
-				 */
590
-	s32 extsmap[SMAPSZ];	/* 16: sum map of mapwords w/ free extents */
591
-	s32 nfreeinos;		/* 4: number of free inodes             */
592
-	s32 nfreeexts;		/* 4: number of free extents            */
593
-	/* (72) */
594
-	u8 pad[1976];		/* 1976: pad to 2048 bytes */
595
-	/* allocation bit map: 1 bit per inode (0 - free, 1 - allocated) */
596
-	u32 wmap[EXTSPERIAG];	/* 512: working allocation map  */
597
-	u32 pmap[EXTSPERIAG];	/* 512: persistent allocation map */
598
-	pxd_t inoext[EXTSPERIAG];	/* 1024: inode extent addresses */
599
-} iag_t;			/* (4096) */
600
-
601
-#endif /* _JFS_H_ */

+ 0
- 1
src/filo/fs/shared.h Целия файл

@@ -1 +0,0 @@
1
-/* Sorry, nothing is shared here ;) Just for GRUB compatibility. */

+ 0
- 193
src/filo/fs/vfs.c Целия файл

@@ -1,193 +0,0 @@
1
-/* Interface between GRUB's fs drivers and application code */
2
-#include <lib.h>
3
-
4
-#include "filesys.h"
5
-#include <fs.h>
6
-
7
-#define DEBUG_THIS DEBUG_VFS
8
-#include <debug.h>
9
-
10
-int filepos;
11
-int filemax;
12
-grub_error_t errnum;
13
-void (*disk_read_hook) (int, int, int);
14
-void (*disk_read_func) (int, int, int);
15
-char FSYS_BUF[FSYS_BUFLEN];
16
-int fsmax;
17
-
18
-struct fsys_entry {
19
-    char *name;
20
-    int (*mount_func) (void);
21
-    int (*read_func) (char *buf, int len);
22
-    int (*dir_func) (char *dirname);
23
-    void (*close_func) (void);
24
-    int (*embed_func) (int *start_sector, int needed_sectors);
25
-};
26
-
27
-struct fsys_entry fsys_table[] = {
28
-# ifdef FSYS_FAT
29
-    {"fat", fat_mount, fat_read, fat_dir, 0, 0},
30
-# endif
31
-# ifdef FSYS_EXT2FS
32
-    {"ext2fs", ext2fs_mount, ext2fs_read, ext2fs_dir, 0, 0},
33
-# endif
34
-# ifdef FSYS_MINIX
35
-    {"minix", minix_mount, minix_read, minix_dir, 0, 0},
36
-# endif
37
-# ifdef FSYS_REISERFS
38
-    {"reiserfs", reiserfs_mount, reiserfs_read, reiserfs_dir, 0,
39
-     reiserfs_embed},
40
-# endif
41
-# ifdef FSYS_JFS
42
-    {"jfs", jfs_mount, jfs_read, jfs_dir, 0, jfs_embed},
43
-# endif
44
-# ifdef FSYS_XFS
45
-    {"xfs", xfs_mount, xfs_read, xfs_dir, 0, 0},
46
-# endif
47
-# ifdef FSYS_ISO9660
48
-    {"iso9660", iso9660_mount, iso9660_read, iso9660_dir, 0, 0},
49
-# endif
50
-};
51
-
52
-/* NULLFS is used to read images from raw device */
53
-static int nullfs_dir(char *name)
54
-{
55
-    uint64_t dev_size;
56
-
57
-    if (name) {
58
-	debug("can't have a named file\n");
59
-	return 0;
60
-    }
61
-
62
-    dev_size = (uint64_t) part_length << 9;
63
-    /* GRUB code doesn't like 2GB or bigger files */
64
-    if (dev_size > 0x7fffffff)
65
-	dev_size = 0x7fffffff;
66
-    filemax = dev_size;
67
-    return 1;
68
-}
69
-
70
-static int nullfs_read(char *buf, int len)
71
-{
72
-    if (devread(filepos>>9, filepos&0x1ff, len, buf)) {
73
-	filepos += len;
74
-	return len;
75
-    } else
76
-	return 0;
77
-}
78
-
79
-static struct fsys_entry nullfs =
80
-    {"nullfs", 0, nullfs_read, nullfs_dir, 0, 0};
81
-
82
-static struct fsys_entry *fsys;
83
-
84
-int mount_fs(void)
85
-{
86
-    int i;
87
-
88
-    for (i = 0; i < sizeof(fsys_table)/sizeof(fsys_table[0]); i++) {
89
-	if (fsys_table[i].mount_func()) {
90
-	    fsys = &fsys_table[i];
91
-	    printf("Mounted %s\n", fsys->name);
92
-	    return 1;
93
-	}
94
-    }
95
-    fsys = 0;
96
-    printf("Unknown filesystem type\n");
97
-    return 0;
98
-}
99
-
100
-int file_open(const char *filename)
101
-{
102
-    
103
-    char dev[32];
104
-//    char *dev=0;
105
-    const char *path;
106
-    int len;
107
-    int retval = 0;
108
-    int reopen;
109
-
110
-    path = strchr(filename, ':');
111
-    if (path) {
112
-	len = path - filename;
113
-	path++;
114
-	//dev = malloc(len + 1);
115
-	memcpy(dev, filename, len);
116
-	dev[len] = '\0';
117
-    } else {
118
-	/* No colon is given. Is this device or filename? */
119
-	if (filename[0] == '/') {
120
-	    /* Anything starts with '/' must be a filename */
121
-	 //   dev = 0;
122
-	    dev[0]=0;
123
-
124
-	    path = filename;
125
-	} else {
126
-	    memcpy(dev, filename, 32);
127
-//	    dev = strdup(filename);
128
-	    path = 0;
129
-	}
130
-    }
131
-    debug("dev=%s, path=%s\n", dev, path);
132
-
133
-    if (dev && dev[0]) {
134
-	if (!devopen(dev, &reopen)) {
135
-	    fsys = 0;
136
-	    goto out;
137
-	}
138
-	if (!reopen)
139
-	    fsys = 0;
140
-    }
141
-
142
-    if (path) {
143
-	if (!fsys || fsys==&nullfs) {
144
-	    if (!mount_fs())
145
-		goto out;
146
-	}
147
-	using_devsize = 0;
148
-	if (!path[0]) {
149
-	    printf("No filename is given\n");
150
-	    goto out;
151
-	}
152
-    } else
153
-	fsys = &nullfs;
154
-
155
-    filepos = 0;
156
-    errnum = 0;
157
-    if (!fsys->dir_func((char *) path)) {
158
-	printf("errnum=%d\n",errnum);
159
-//	printf("File not found\n");
160
-	goto out;
161
-    }
162
-    retval = 1;
163
-out:
164
-//    if (dev)
165
-//	free(dev);
166
-    return retval;
167
-}
168
-
169
-int file_read(void *buf, unsigned long len)
170
-{
171
-    if (filepos < 0 || filepos > filemax)
172
-	filepos = filemax;
173
-    if (len < 0 || len > filemax-filepos)
174
-	len = filemax - filepos;
175
-    errnum = 0;
176
-    return fsys->read_func(buf, len);
177
-}
178
-
179
-int file_seek(unsigned long offset)
180
-{
181
-    filepos = offset;
182
-    return filepos;
183
-}
184
-
185
-unsigned long file_size(void)
186
-{
187
-    return filemax;
188
-}
189
-
190
-void file_close(void)
191
-{
192
-}
193
-

+ 0
- 546
src/filo/fs/xfs.h Целия файл

@@ -1,546 +0,0 @@
1
-/* xfs.h - an extraction from xfsprogs-1.3.5/include/xfs* into one file */
2
-/* 
3
- *  GRUB  --  GRand Unified Bootloader
4
- *  Copyright (C) 2000  Silicon Graphics, Inc.  All Rights Reserved.
5
- *  Copyright (C) 2001  Free Software Foundation, Inc.
6
- * 
7
- *  This program is free software; you can redistribute it and/or modify it
8
- *  under the terms of version 2 of the GNU General Public License as
9
- *  published by the Free Software Foundation.
10
- * 
11
- *  This program is distributed in the hope that it would be useful, but
12
- *  WITHOUT ANY WARRANTY; without even the implied warranty of
13
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
- * 
15
- *  Further, this software is distributed without any warranty that it is
16
- *  free of the rightful claim of any third person regarding infringement
17
- *  or the like.  Any license provided herein, whether implied or
18
- *  otherwise, applies only to this software file.  Patent licenses, if
19
- *  any, provided herein do not apply to combinations of this program with
20
- *  other software, or any other product whatsoever.
21
- * 
22
- *  You should have received a copy of the GNU General Public License along
23
- *  with this program; if not, write the Free Software Foundation, Inc., 59
24
- *  Temple Place - Suite 330, Boston MA 02111-1307, USA.
25
- * 
26
- *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27
- *  Mountain View, CA  94043, or:
28
- * 
29
- *  http://www.sgi.com 
30
- * 
31
- *  For further information regarding this notice, see: 
32
- * 
33
- *  http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34
- */
35
-
36
-#ifndef _BITS_TYPES_H
37
-typedef signed char	__int8_t;
38
-typedef unsigned char	__uint8_t;
39
-typedef short		__int16_t;
40
-typedef unsigned short	__uint16_t;
41
-typedef int		__int32_t;
42
-typedef unsigned int	__uint32_t;
43
-typedef long long	__int64_t;
44
-typedef unsigned long long __uint64_t;
45
-#endif
46
-
47
-typedef __uint64_t	xfs_ino_t;
48
-typedef	__uint32_t	xfs_agino_t;
49
-typedef __int64_t	xfs_daddr_t;
50
-typedef __int64_t	xfs_off_t;
51
-typedef __uint8_t	uuid_t[16];
52
-
53
-
54
-/* those are from xfs_types.h */
55
-
56
-typedef __uint32_t	xfs_agblock_t;	/* blockno in alloc. group */
57
-typedef	__uint32_t	xfs_extlen_t;	/* extent length in blocks */
58
-typedef	__uint32_t	xfs_agnumber_t;	/* allocation group number */
59
-typedef __int32_t	xfs_extnum_t;	/* # of extents in a file */
60
-typedef __int16_t	xfs_aextnum_t;	/* # extents in an attribute fork */
61
-typedef	__int64_t	xfs_fsize_t;	/* bytes in a file */
62
-
63
-typedef	__uint32_t	xfs_dablk_t;	/* dir/attr block number (in file) */
64
-typedef	__uint32_t	xfs_dahash_t;	/* dir/attr hash value */
65
-
66
-/*
67
- * Disk based types:
68
- */
69
-typedef __uint64_t	xfs_dfsbno_t;	/* blockno in filesystem (agno|agbno) */
70
-typedef __uint64_t	xfs_drfsbno_t;	/* blockno in filesystem (raw) */
71
-typedef	__uint64_t	xfs_drtbno_t;	/* extent (block) in realtime area */
72
-typedef	__uint64_t	xfs_dfiloff_t;	/* block number in a file */
73
-
74
-typedef	__uint64_t	xfs_fsblock_t;	/* blockno in filesystem (agno|agbno) */
75
-typedef	__uint64_t	xfs_fileoff_t;	/* block number in a file */
76
-typedef	__uint64_t	xfs_filblks_t;	/* number of blocks in a file */
77
-
78
-
79
-/* those are from xfs_sb.h */
80
-
81
-#define	XFS_SB_MAGIC		0x58465342	/* 'XFSB'*/
82
-#define	XFS_SB_VERSION_4	4		/* 6.2+ - bitmask version */
83
-#define	XFS_SB_VERSION_NUMBITS	0x000f
84
-
85
-typedef struct xfs_sb
86
-{
87
-	__uint32_t	sb_magicnum;	/* magic number == XFS_SB_MAGIC */
88
-	__uint32_t	sb_blocksize;	/* logical block size, bytes */
89
-	xfs_drfsbno_t	sb_dblocks;	/* number of data blocks */
90
-	xfs_drfsbno_t	sb_rblocks;	/* number of realtime blocks */
91
-	xfs_drtbno_t	sb_rextents;	/* number of realtime extents */
92
-	uuid_t		sb_uuid;	/* file system unique id */
93
-	xfs_dfsbno_t	sb_logstart;	/* starting block of log if internal */
94
-	xfs_ino_t	sb_rootino;	/* root inode number */
95
-	xfs_ino_t	sb_rbmino;	/* bitmap inode for realtime extents */
96
-	xfs_ino_t	sb_rsumino;	/* summary inode for rt bitmap */
97
-	xfs_agblock_t	sb_rextsize;	/* realtime extent size, blocks */
98
-	xfs_agblock_t	sb_agblocks;	/* size of an allocation group */
99
-	xfs_agnumber_t	sb_agcount;	/* number of allocation groups */
100
-	xfs_extlen_t	sb_rbmblocks;	/* number of rt bitmap blocks */
101
-	xfs_extlen_t	sb_logblocks;	/* number of log blocks */
102
-	__uint16_t	sb_versionnum;	/* header version == XFS_SB_VERSION */
103
-	__uint16_t	sb_sectsize;	/* volume sector size, bytes */
104
-	__uint16_t	sb_inodesize;	/* inode size, bytes */
105
-	__uint16_t	sb_inopblock;	/* inodes per block */
106
-	char		sb_fname[12];	/* file system name */
107
-	__uint8_t	sb_blocklog;	/* log2 of sb_blocksize */
108
-	__uint8_t	sb_sectlog;	/* log2 of sb_sectsize */
109
-	__uint8_t	sb_inodelog;	/* log2 of sb_inodesize */
110
-	__uint8_t	sb_inopblog;	/* log2 of sb_inopblock */
111
-	__uint8_t	sb_agblklog;	/* log2 of sb_agblocks (rounded up) */
112
-	__uint8_t	sb_rextslog;	/* log2 of sb_rextents */
113
-	__uint8_t	sb_inprogress;	/* mkfs is in progress, don't mount */
114
-	__uint8_t	sb_imax_pct;	/* max % of fs for inode space */
115
-					/* statistics */
116
-	/*
117
-	 * These fields must remain contiguous.  If you really
118
-	 * want to change their layout, make sure you fix the
119
-	 * code in xfs_trans_apply_sb_deltas().
120
-	 */
121
-	__uint64_t	sb_icount;	/* allocated inodes */
122
-	__uint64_t	sb_ifree;	/* free inodes */
123
-	__uint64_t	sb_fdblocks;	/* free data blocks */
124
-	__uint64_t	sb_frextents;	/* free realtime extents */
125
-	/*
126
-	 * End contiguous fields.
127
-	 */
128
-	xfs_ino_t	sb_uquotino;	/* user quota inode */
129
-	xfs_ino_t	sb_gquotino;	/* group quota inode */
130
-	__uint16_t	sb_qflags;	/* quota flags */
131
-	__uint8_t	sb_flags;	/* misc. flags */
132
-	__uint8_t	sb_shared_vn;	/* shared version number */
133
-	xfs_extlen_t	sb_inoalignmt;	/* inode chunk alignment, fsblocks */
134
-	__uint32_t	sb_unit;	/* stripe or raid unit */
135
-	__uint32_t	sb_width;	/* stripe or raid width */	
136
-	__uint8_t	sb_dirblklog;	/* log2 of dir block size (fsbs) */
137
-        __uint8_t       sb_dummy[7];    /* padding */
138
-} xfs_sb_t;
139
-
140
-
141
-/* those are from xfs_btree.h */
142
-
143
-/*
144
- * Long form header: bmap btrees.
145
- */
146
-typedef struct xfs_btree_lblock
147
-{
148
-	__uint32_t	bb_magic;	/* magic number for block type */
149
-	__uint16_t	bb_level;	/* 0 is a leaf */
150
-	__uint16_t	bb_numrecs;	/* current # of data records */
151
-	xfs_dfsbno_t	bb_leftsib;	/* left sibling block or NULLDFSBNO */
152
-	xfs_dfsbno_t	bb_rightsib;	/* right sibling block or NULLDFSBNO */
153
-} xfs_btree_lblock_t;
154
-
155
-/*
156
- * Combined header and structure, used by common code.
157
- */
158
-typedef struct xfs_btree_hdr
159
-{
160
-	__uint32_t	bb_magic;	/* magic number for block type */
161
-	__uint16_t	bb_level;	/* 0 is a leaf */
162
-	__uint16_t	bb_numrecs;	/* current # of data records */
163
-} xfs_btree_hdr_t;
164
-
165
-typedef struct xfs_btree_block
166
-{
167
-	xfs_btree_hdr_t	bb_h;		/* header */
168
-	union		{
169
-		struct	{
170
-			xfs_agblock_t	bb_leftsib;
171
-			xfs_agblock_t	bb_rightsib;
172
-		}	s;		/* short form pointers */
173
-		struct	{
174
-			xfs_dfsbno_t	bb_leftsib;
175
-			xfs_dfsbno_t	bb_rightsib;
176
-		}	l;		/* long form pointers */
177
-	}		bb_u;		/* rest */
178
-} xfs_btree_block_t;
179
-
180
-/* those are from xfs_bmap_btree.h */
181
-
182
-/*
183
- * Bmap root header, on-disk form only.
184
- */
185
-typedef struct xfs_bmdr_block
186
-{
187
-	__uint16_t	bb_level;	/* 0 is a leaf */
188
-	__uint16_t	bb_numrecs;	/* current # of data records */
189
-} xfs_bmdr_block_t;
190
-
191
-/*
192
- * Bmap btree record and extent descriptor.
193
- * For 32-bit kernels,
194
- *  l0:31 is an extent flag (value 1 indicates non-normal).
195
- *  l0:0-30 and l1:9-31 are startoff.
196
- *  l1:0-8, l2:0-31, and l3:21-31 are startblock.
197
- *  l3:0-20 are blockcount.
198
- * For 64-bit kernels,
199
- *  l0:63 is an extent flag (value 1 indicates non-normal).
200
- *  l0:9-62 are startoff.
201
- *  l0:0-8 and l1:21-63 are startblock.
202
- *  l1:0-20 are blockcount.
203
- */
204
-
205
-#define	BMBT_USE_64	1
206
-
207
-typedef struct xfs_bmbt_rec_32
208
-{
209
-	__uint32_t		l0, l1, l2, l3;
210
-} xfs_bmbt_rec_32_t;
211
-typedef struct xfs_bmbt_rec_64
212
-{
213
-	__uint64_t		l0, l1;
214
-} xfs_bmbt_rec_64_t;
215
-
216
-#if BMBT_USE_64
217
-typedef	__uint64_t	xfs_bmbt_rec_base_t;	/* use this for casts */
218
-typedef xfs_bmbt_rec_64_t xfs_bmbt_rec_t, xfs_bmdr_rec_t;
219
-#else	/* !BMBT_USE_64 */
220
-typedef	__uint32_t	xfs_bmbt_rec_base_t;	/* use this for casts */
221
-typedef xfs_bmbt_rec_32_t xfs_bmbt_rec_t, xfs_bmdr_rec_t;
222
-#endif	/* BMBT_USE_64 */
223
-
224
-/*
225
- * Key structure for non-leaf levels of the tree.
226
- */
227
-typedef struct xfs_bmbt_key
228
-{
229
-	xfs_dfiloff_t	br_startoff;	/* starting file offset */
230
-} xfs_bmbt_key_t, xfs_bmdr_key_t;
231
-
232
-typedef xfs_dfsbno_t xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;	/* btree pointer type */
233
-					/* btree block header type */
234
-typedef	struct xfs_btree_lblock xfs_bmbt_block_t;
235
-
236
-
237
-/* those are from xfs_dir2.h */
238
-/*
239
- * Directory version 2.
240
- * There are 4 possible formats:
241
- *	shortform
242
- *	single block - data with embedded leaf at the end
243
- *	multiple data blocks, single leaf+freeindex block
244
- *	data blocks, node&leaf blocks (btree), freeindex blocks
245
- *
246
- *	The shortform format is in xfs_dir2_sf.h.
247
- *	The single block format is in xfs_dir2_block.h.
248
- *	The data block format is in xfs_dir2_data.h.
249
- *	The leaf and freeindex block formats are in xfs_dir2_leaf.h.
250
- *	Node blocks are the same as the other version, in xfs_da_btree.h.
251
- */
252
-
253
-/*
254
- * Byte offset in data block and shortform entry.
255
- */
256
-typedef	__uint16_t	xfs_dir2_data_off_t;
257
-
258
-/*
259
- * Byte offset in a directory.
260
- */
261
-typedef	xfs_off_t		xfs_dir2_off_t;
262
-
263
-/* those are from xfs_da_btree.h */
264
-/*========================================================================
265
- * Directory Structure when greater than XFS_LBSIZE(mp) bytes.
266
- *========================================================================*/
267
-
268
-/*
269
- * This structure is common to both leaf nodes and non-leaf nodes in the Btree.
270
- *
271
- * Is is used to manage a doubly linked list of all blocks at the same
272
- * level in the Btree, and to identify which type of block this is.
273
- */
274
-#define	XFS_DIR2_LEAF1_MAGIC	0xd2f1	/* magic number: v2 dirlf single blks */
275
-#define	XFS_DIR2_LEAFN_MAGIC	0xd2ff	/* magic number: v2 dirlf multi blks */
276
-
277
-typedef struct xfs_da_blkinfo {
278
-	xfs_dablk_t forw;			/* previous block in list */
279
-	xfs_dablk_t back;			/* following block in list */
280
-	__uint16_t magic;			/* validity check on block */
281
-	__uint16_t pad;				/* unused */
282
-} xfs_da_blkinfo_t;
283
-
284
-/*
285
- * This is the structure of the root and intermediate nodes in the Btree.
286
- * The leaf nodes are defined above.
287
- *
288
- * Entries are not packed.
289
- *
290
- * Since we have duplicate keys, use a binary search but always follow
291
- * all match in the block, not just the first match found.
292
- */
293
-
294
-typedef struct xfs_da_intnode {
295
-	struct xfs_da_node_hdr {	/* constant-structure header block */
296
-		xfs_da_blkinfo_t info;	/* block type, links, etc. */
297
-		__uint16_t count;	/* count of active entries */
298
-		__uint16_t level;	/* level above leaves (leaf == 0) */
299
-	} hdr;
300
-	struct xfs_da_node_entry {
301
-		xfs_dahash_t hashval;	/* hash value for this descendant */
302
-		xfs_dablk_t before;	/* Btree block before this key */
303
-	} btree[1];			/* variable sized array of keys */
304
-} xfs_da_intnode_t;
305
-
306
-
307
-/* those are from xfs_dir2_data.h */
308
-/*
309
- * Directory format 2, data block structures.
310
- */
311
-
312
-/*
313
- * Constants.
314
- */
315
-#define	XFS_DIR2_DATA_FREE_TAG	0xffff
316
-#define	XFS_DIR2_DATA_FD_COUNT	3
317
-
318
-/*
319
- * Structures.
320
- */
321
-
322
-/*
323
- * Describe a free area in the data block.
324
- * The freespace will be formatted as a xfs_dir2_data_unused_t.
325
- */
326
-typedef struct xfs_dir2_data_free {
327
-	xfs_dir2_data_off_t	offset;		/* start of freespace */
328
-	xfs_dir2_data_off_t	length;		/* length of freespace */
329
-} xfs_dir2_data_free_t;
330
-
331
-/*
332
- * Header for the data blocks.
333
- * Always at the beginning of a directory-sized block.
334
- * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
335
- */
336
-typedef struct xfs_dir2_data_hdr {
337
-	__uint32_t		magic;		/* XFS_DIR2_DATA_MAGIC */
338
-						/* or XFS_DIR2_BLOCK_MAGIC */
339
-	xfs_dir2_data_free_t	bestfree[XFS_DIR2_DATA_FD_COUNT];
340
-} xfs_dir2_data_hdr_t;
341
-
342
-/*
343
- * Active entry in a data block.  Aligned to 8 bytes.
344
- * Tag appears as the last 2 bytes.
345
- */
346
-typedef struct xfs_dir2_data_entry {
347
-	xfs_ino_t		inumber;	/* inode number */
348
-	__uint8_t		namelen;	/* name length */
349
-	__uint8_t		name[1];	/* name bytes, no null */
350
-						/* variable offset */
351
-	xfs_dir2_data_off_t	tag;		/* starting offset of us */
352
-} xfs_dir2_data_entry_t;
353
-
354
-/*
355
- * Unused entry in a data block.  Aligned to 8 bytes.
356
- * Tag appears as the last 2 bytes.
357
- */
358
-typedef struct xfs_dir2_data_unused {
359
-	__uint16_t		freetag;	/* XFS_DIR2_DATA_FREE_TAG */
360
-	xfs_dir2_data_off_t	length;		/* total free length */
361
-						/* variable offset */
362
-	xfs_dir2_data_off_t	tag;		/* starting offset of us */
363
-} xfs_dir2_data_unused_t;
364
-
365
-typedef union {
366
-	xfs_dir2_data_entry_t	entry;
367
-	xfs_dir2_data_unused_t	unused;
368
-} xfs_dir2_data_union_t;
369
-
370
-
371
-/* those are from xfs_dir2_leaf.h */
372
-/*
373
- * Directory version 2, leaf block structures.
374
- */
375
-
376
-/*
377
- * Leaf block header.
378
- */
379
-typedef struct xfs_dir2_leaf_hdr {
380
-	xfs_da_blkinfo_t	info;		/* header for da routines */
381
-	__uint16_t		count;		/* count of entries */
382
-	__uint16_t		stale;		/* count of stale entries */
383
-} xfs_dir2_leaf_hdr_t;
384
-
385
-
386
-/* those are from xfs_dir2_block.h */
387
-/*
388
- * xfs_dir2_block.h
389
- * Directory version 2, single block format structures
390
- */
391
-
392
-/*
393
- * The single block format is as follows:
394
- * xfs_dir2_data_hdr_t structure
395
- * xfs_dir2_data_entry_t and xfs_dir2_data_unused_t structures
396
- * xfs_dir2_leaf_entry_t structures
397
- * xfs_dir2_block_tail_t structure
398
- */
399
-
400
-#define	XFS_DIR2_BLOCK_MAGIC	0x58443242	/* XD2B: for one block dirs */
401
-
402
-typedef struct xfs_dir2_block_tail {
403
-	__uint32_t	count;			/* count of leaf entries */
404
-	__uint32_t	stale;			/* count of stale lf entries */
405
-} xfs_dir2_block_tail_t;
406
-
407
-
408
-/* those are from xfs_dir2_sf.h */
409
-
410
-/*
411
- * Directory layout when stored internal to an inode.
412
- *
413
- * Small directories are packed as tightly as possible so as to
414
- * fit into the literal area of the inode.
415
- */
416
-
417
-/*
418
- * Inode number stored as 8 8-bit values.
419
- */
420
-typedef	struct { __uint8_t i[8]; } xfs_dir2_ino8_t;
421
-
422
-/*
423
- * Inode number stored as 4 8-bit values.
424
- * Works a lot of the time, when all the inode numbers in a directory
425
- * fit in 32 bits.
426
- */
427
-typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t;
428
-
429
-typedef union {
430
-	xfs_dir2_ino8_t	i8;
431
-	xfs_dir2_ino4_t	i4;
432
-} xfs_dir2_inou_t;
433
-
434
-/*
435
- * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t.
436
- * Only need 16 bits, this is the byte offset into the single block form.
437
- */
438
-typedef struct { __uint8_t i[2]; } xfs_dir2_sf_off_t;
439
-
440
-/*
441
- * The parent directory has a dedicated field, and the self-pointer must
442
- * be calculated on the fly.
443
- *
444
- * Entries are packed toward the top as tightly as possible.  The header
445
- * and the elements must be bcopy()'d out into a work area to get correct
446
- * alignment for the inode number fields.
447
- */
448
-typedef struct xfs_dir2_sf_hdr {
449
-	__uint8_t		count;		/* count of entries */
450
-	__uint8_t		i8count;	/* count of 8-byte inode #s */
451
-	xfs_dir2_inou_t		parent;		/* parent dir inode number */
452
-} xfs_dir2_sf_hdr_t;
453
-
454
-typedef struct xfs_dir2_sf_entry {
455
-	__uint8_t		namelen;	/* actual name length */
456
-	xfs_dir2_sf_off_t	offset;		/* saved offset */
457
-	__uint8_t		name[1];	/* name, variable size */
458
-	xfs_dir2_inou_t		inumber;	/* inode number, var. offset */
459
-} xfs_dir2_sf_entry_t;
460
-
461
-typedef struct xfs_dir2_sf {
462
-	xfs_dir2_sf_hdr_t	hdr;		/* shortform header */
463
-	xfs_dir2_sf_entry_t	list[1];	/* shortform entries */
464
-} xfs_dir2_sf_t;
465
-
466
-/* those are from xfs_dinode.h */
467
-
468
-#define	XFS_DINODE_VERSION_1	1
469
-#define	XFS_DINODE_VERSION_2	2
470
-#define	XFS_DINODE_MAGIC	0x494e	/* 'IN' */
471
-
472
-/*
473
- * Disk inode structure.
474
- * This is just the header; the inode is expanded to fill a variable size
475
- * with the last field expanding.  It is split into the core and "other"
476
- * because we only need the core part in the in-core inode.
477
- */
478
-typedef struct xfs_timestamp {
479
-	__int32_t	t_sec;		/* timestamp seconds */
480
-	__int32_t	t_nsec;		/* timestamp nanoseconds */
481
-} xfs_timestamp_t;
482
-
483
-/*
484
- * Note: Coordinate changes to this structure with the XFS_DI_* #defines
485
- * below and the offsets table in xfs_ialloc_log_di().
486
- */
487
-typedef struct xfs_dinode_core
488
-{
489
-	__uint16_t	di_magic;	/* inode magic # = XFS_DINODE_MAGIC */
490
-	__uint16_t	di_mode;	/* mode and type of file */
491
-	__int8_t	di_version;	/* inode version */
492
-	__int8_t	di_format;	/* format of di_c data */
493
-	__uint16_t	di_onlink;	/* old number of links to file */
494
-	__uint32_t	di_uid;		/* owner's user id */
495
-	__uint32_t	di_gid;		/* owner's group id */
496
-	__uint32_t	di_nlink;	/* number of links to file */
497
-	__uint16_t	di_projid;	/* owner's project id */
498
-	__uint8_t	di_pad[10];	/* unused, zeroed space */
499
-	xfs_timestamp_t	di_atime;	/* time last accessed */
500
-	xfs_timestamp_t	di_mtime;	/* time last modified */
501
-	xfs_timestamp_t	di_ctime;	/* time created/inode modified */
502
-	xfs_fsize_t	di_size;	/* number of bytes in file */
503
-	xfs_drfsbno_t	di_nblocks;	/* # of direct & btree blocks used */
504
-	xfs_extlen_t	di_extsize;	/* basic/minimum extent size for file */
505
-	xfs_extnum_t	di_nextents;	/* number of extents in data fork */
506
-	xfs_aextnum_t	di_anextents;	/* number of extents in attribute fork*/
507
-	__uint8_t	di_forkoff;	/* attr fork offs, <<3 for 64b align */
508
-	__int8_t	di_aformat;	/* format of attr fork's data */
509
-	__uint32_t	di_dmevmask;	/* DMIG event mask */
510
-	__uint16_t	di_dmstate;	/* DMIG state info */
511
-	__uint16_t	di_flags;	/* random flags, XFS_DIFLAG_... */
512
-	__uint32_t	di_gen;		/* generation number */
513
-} xfs_dinode_core_t;
514
-
515
-typedef struct xfs_dinode
516
-{
517
-	xfs_dinode_core_t	di_core;
518
-	xfs_agino_t		di_next_unlinked;/* agi unlinked list ptr */
519
-	union {
520
-		xfs_bmdr_block_t di_bmbt;	/* btree root block */
521
-		xfs_bmbt_rec_32_t di_bmx[1];	/* extent list */
522
-		xfs_dir2_sf_t	di_dir2sf;	/* shortform directory v2 */
523
-		char		di_c[1];	/* local contents */
524
-	} di_u;
525
-} xfs_dinode_t;
526
-
527
-/*
528
- * Values for di_format
529
- */
530
-typedef enum xfs_dinode_fmt
531
-{
532
-	XFS_DINODE_FMT_DEV,		/* CHR, BLK: di_dev */
533
-	XFS_DINODE_FMT_LOCAL,		/* DIR, REG: di_c */
534
-					/* LNK: di_symlink */
535
-	XFS_DINODE_FMT_EXTENTS,		/* DIR, REG, LNK: di_bmx */
536
-	XFS_DINODE_FMT_BTREE,		/* DIR, REG, LNK: di_bmbt */
537
-	XFS_DINODE_FMT_UUID 		/* MNT: di_uuid */
538
-} xfs_dinode_fmt_t;
539
-
540
-/*
541
- * File types (mode field)
542
- */
543
-#define	IFMT		0170000		/* type of file */
544
-#define	IFDIR		0040000		/* directory */
545
-#define	IFREG		0100000		/* regular */
546
-#define	IFLNK		0120000		/* symbolic link */

+ 0
- 125
src/filo/i386/context.c Целия файл

@@ -1,125 +0,0 @@
1
-/*
2
- * context switching
3
- * 2003-10 by SONE Takeshi
4
- */
5
-#include <etherboot.h>
6
-
7
-#include "segment.h"
8
-#include "context.h"
9
-
10
-#define MAIN_STACK_SIZE 16384
11
-#define IMAGE_STACK_SIZE 4096
12
-
13
-static void start_main(void); /* forward decl. */
14
-void __exit_context(void); /* assembly routine */
15
-
16
-/*
17
- * Main context structure 
18
- * It is placed at the bottom of our stack, and loaded by assembly routine
19
- * to start us up.
20
- */
21
-struct context main_ctx __attribute__((section (".initctx"))) = {
22
-    .gdt_base = (uint32_t) gdt,
23
-    .gdt_limit = GDT_LIMIT,
24
-    .cs = FLAT_CS,
25
-    .ds = FLAT_DS,
26
-    .es = FLAT_DS,
27
-    .fs = FLAT_DS,
28
-    .gs = FLAT_DS,
29
-    .ss = FLAT_DS,
30
-    .esp = (uint32_t) ESP_LOC(&main_ctx),
31
-    .eip = (uint32_t) start_main,
32
-    .return_addr = (uint32_t) __exit_context,
33
-};
34
-
35
-/* This is used by assembly routine to load/store the context which
36
- * it is to switch/switched.  */
37
-struct context *__context = &main_ctx;
38
-
39
-#if 0
40
-/* Stack for loaded ELF image */
41
-static uint8_t image_stack[IMAGE_STACK_SIZE];
42
-#endif
43
-
44
-/* Pointer to startup context (physical address) */
45
-unsigned long __boot_ctx;
46
-
47
-/*
48
- * Main starter
49
- * This is the C function that runs first.
50
- */
51
-static void start_main(void)
52
-{
53
-    int retval;
54
-    extern int filo(void);
55
-
56
-    /* Save startup context, so we can refer to it later.
57
-     * We have to keep it in physical address since we will relocate. */
58
-    __boot_ctx = virt_to_phys(__context);
59
-
60
-    /* Start the real fun */
61
-    retval = filo();
62
-
63
-    /* Pass return value to startup context. Bootloader may see it. */
64
-    boot_ctx->eax = retval;
65
-
66
-    /* Returning from here should jump to __exit_context */
67
-    __context = boot_ctx;
68
-}
69
-
70
-/* Setup a new context using the given stack.
71
- */
72
-struct context *
73
-init_context(uint8_t *stack, uint32_t stack_size, int num_params)
74
-{
75
-    struct context *ctx;
76
-
77
-    ctx = (struct context *)
78
-	(stack + stack_size - (sizeof(*ctx) + num_params*sizeof(uint32_t)));
79
-    memset(ctx, 0, sizeof(*ctx));
80
-
81
-    /* Fill in reasonable default for flat memory model */
82
-    ctx->gdt_base = virt_to_phys(gdt);
83
-    ctx->gdt_limit = GDT_LIMIT;
84
-    ctx->cs = FLAT_CS;
85
-    ctx->ds = FLAT_DS;
86
-    ctx->es = FLAT_DS;
87
-    ctx->fs = FLAT_DS;
88
-    ctx->gs = FLAT_DS;
89
-    ctx->ss = FLAT_DS;
90
-    ctx->esp = virt_to_phys(ESP_LOC(ctx));
91
-    ctx->return_addr = virt_to_phys(__exit_context);
92
-
93
-    return ctx;
94
-}
95
-
96
-/* Switch to another context. */
97
-struct context *switch_to(struct context *ctx)
98
-{
99
-    struct context *save, *ret;
100
-
101
-    save = __context;
102
-    __context = ctx;
103
-    asm ("pushl %cs; call __switch_context");
104
-    ret = __context;
105
-    __context = save;
106
-    return ret;
107
-}
108
-
109
-#if 0
110
-//We will use elf_start in Etherboot
111
-/* Start ELF Boot image */
112
-uint32_t start_elf(uint32_t entry_point, uint32_t param)
113
-{
114
-    struct context *ctx;
115
-
116
-    ctx = init_context(image_stack, sizeof image_stack, 1);
117
-    ctx->eip = entry_point;
118
-    ctx->param[0] = param;
119
-    ctx->eax = 0xe1fb007;
120
-    ctx->ebx = param;
121
-
122
-    ctx = switch_to(ctx);
123
-    return ctx->eax;
124
-}
125
-#endif

+ 0
- 50
src/filo/i386/context.h Целия файл

@@ -1,50 +0,0 @@
1
-#ifndef i386_CONTEXT_H
2
-#define i386_CONTEXT_H
3
-
4
-#include <stdint.h>
5
-
6
-struct context {
7
-    /* Stack Segment, placed here because of the alignment issue... */
8
-    uint16_t ss;
9
-    /* Used with sgdt/lgdt */
10
-    uint16_t gdt_limit;
11
-    uint32_t gdt_base;
12
-    /* General registers, accessed with pushal/popal */
13
-    uint32_t edi;
14
-    uint32_t esi;
15
-    uint32_t ebp;
16
-    uint32_t esp; /* points just below eax */
17
-    uint32_t ebx;
18
-    uint32_t edx;
19
-    uint32_t ecx;
20
-    uint32_t eax;
21
-#define ESP_LOC(ctx) (&(ctx)->gs)
22
-    /* Segment registers */
23
-    uint32_t gs;
24
-    uint32_t fs;
25
-    uint32_t es;
26
-    uint32_t ds;
27
-    /* Flags */
28
-    uint32_t eflags;
29
-    /* Code segment:offset */
30
-    uint32_t eip;
31
-    uint32_t cs;
32
-    /* Optional stack contents */
33
-    uint32_t return_addr;
34
-    uint32_t param[0];
35
-};
36
-
37
-/* Create a new context in the given stack */
38
-struct context *
39
-init_context(uint8_t *stack, uint32_t stack_size, int num_param);
40
-
41
-/* Switch context */
42
-struct context *switch_to(struct context *);
43
-
44
-/* Holds physical address of boot context */
45
-extern unsigned long __boot_ctx;
46
-
47
-/* This can always be safely used to refer to the boot context */
48
-#define boot_ctx ((struct context *) phys_to_virt(__boot_ctx))
49
-
50
-#endif /* i386_CONTEXT_H */

+ 0
- 629
src/filo/i386/linux_load.c Целия файл

@@ -1,629 +0,0 @@
1
-/*
2
- * Linux/i386 loader
3
- * Supports bzImage, zImage and Image format.
4
- *
5
- * Based on work by Steve Gehlbach.
6
- * Portions are taken from mkelfImage.
7
- *
8
- * 2003-09 by SONE Takeshi
9
- */
10
-#include <etherboot.h>
11
-
12
-#include <lib.h>
13
-
14
-#include <fs.h>
15
-#include <sys_info.h>
16
-
17
-#include "context.h"
18
-#include "segment.h"
19
-
20
-#define DEBUG_THIS DEBUG_LINUXLOAD
21
-#include <debug.h>
22
-
23
-#define LINUX_PARAM_LOC 0x90000
24
-#define COMMAND_LINE_LOC 0x91000
25
-#define GDT_LOC 0x92000
26
-#define STACK_LOC 0x93000
27
-
28
-/* The header of Linux/i386 kernel */
29
-struct linux_header {
30
-    uint8_t  reserved1[0x1f1];		/* 0x000 */
31
-    uint8_t  setup_sects;		/* 0x1f1 */
32
-    uint16_t root_flags;		/* 0x1f2 */
33
-    uint8_t  reserved2[6];		/* 0x1f4 */
34
-    uint16_t vid_mode;			/* 0x1fa */
35
-    uint16_t root_dev;			/* 0x1fc */
36
-    uint16_t boot_sector_magic;		/* 0x1fe */
37
-    /* 2.00+ */
38
-    uint8_t  reserved3[2];		/* 0x200 */
39
-    uint8_t  header_magic[4];		/* 0x202 */
40
-    uint16_t protocol_version;		/* 0x206 */
41
-    uint32_t realmode_swtch;		/* 0x208 */
42
-    uint16_t start_sys;			/* 0x20c */
43
-    uint16_t kver_addr;			/* 0x20e */
44
-    uint8_t  type_of_loader;		/* 0x210 */
45
-    uint8_t  loadflags;			/* 0x211 */
46
-    uint16_t setup_move_size;		/* 0x212 */
47
-    uint32_t code32_start;		/* 0x214 */
48
-    uint32_t ramdisk_image;		/* 0x218 */
49
-    uint32_t ramdisk_size;		/* 0x21c */
50
-    uint8_t  reserved4[4];		/* 0x220 */
51
-    /* 2.01+ */
52
-    uint16_t heap_end_ptr;		/* 0x224 */
53
-    uint8_t  reserved5[2];		/* 0x226 */
54
-    /* 2.02+ */
55
-    uint32_t cmd_line_ptr;		/* 0x228 */
56
-    /* 2.03+ */
57
-    uint32_t initrd_addr_max;		/* 0x22c */
58
-} __attribute__ ((packed));
59
-
60
-
61
-/* Paramters passed to 32-bit part of Linux
62
- * This is another view of the structure above.. */
63
-struct linux_params {
64
-    uint8_t  orig_x;			/* 0x00 */
65
-    uint8_t  orig_y;			/* 0x01 */
66
-    uint16_t ext_mem_k;			/* 0x02 -- EXT_MEM_K sits here */
67
-    uint16_t orig_video_page;		/* 0x04 */
68
-    uint8_t  orig_video_mode;		/* 0x06 */
69
-    uint8_t  orig_video_cols;		/* 0x07 */
70
-    uint16_t unused2;			/* 0x08 */
71
-    uint16_t orig_video_ega_bx;		/* 0x0a */
72
-    uint16_t unused3;			/* 0x0c */
73
-    uint8_t  orig_video_lines;		/* 0x0e */
74
-    uint8_t  orig_video_isVGA;		/* 0x0f */
75
-    uint16_t orig_video_points;		/* 0x10 */
76
-
77
-    /* VESA graphic mode -- linear frame buffer */
78
-    uint16_t lfb_width;			/* 0x12 */
79
-    uint16_t lfb_height;		/* 0x14 */
80
-    uint16_t lfb_depth;			/* 0x16 */
81
-    uint32_t lfb_base;			/* 0x18 */
82
-    uint32_t lfb_size;			/* 0x1c */
83
-    uint16_t cl_magic;			/* 0x20 */
84
-#define CL_MAGIC_VALUE 0xA33F
85
-    uint16_t cl_offset;			/* 0x22 */
86
-    uint16_t lfb_linelength;		/* 0x24 */
87
-    uint8_t  red_size;			/* 0x26 */
88
-    uint8_t  red_pos;			/* 0x27 */
89
-    uint8_t  green_size;		/* 0x28 */
90
-    uint8_t  green_pos;			/* 0x29 */
91
-    uint8_t  blue_size;			/* 0x2a */
92
-    uint8_t  blue_pos;			/* 0x2b */
93
-    uint8_t  rsvd_size;			/* 0x2c */
94
-    uint8_t  rsvd_pos;			/* 0x2d */
95
-    uint16_t vesapm_seg;		/* 0x2e */
96
-    uint16_t vesapm_off;		/* 0x30 */
97
-    uint16_t pages;			/* 0x32 */
98
-    uint8_t  reserved4[12];		/* 0x34 -- 0x3f reserved for future expansion */
99
-
100
-    //struct apm_bios_info apm_bios_info;	/* 0x40 */
101
-    uint8_t  apm_bios_info[0x40];
102
-    //struct drive_info_struct drive_info;	/* 0x80 */
103
-    uint8_t  drive_info[0x20];
104
-    //struct sys_desc_table sys_desc_table;	/* 0xa0 */
105
-    uint8_t  sys_desc_table[0x140];
106
-    uint32_t alt_mem_k;			/* 0x1e0 */
107
-    uint8_t  reserved5[4];		/* 0x1e4 */
108
-    uint8_t  e820_map_nr;		/* 0x1e8 */
109
-    uint8_t  reserved6[9];		/* 0x1e9 */
110
-    uint16_t mount_root_rdonly;		/* 0x1f2 */
111
-    uint8_t  reserved7[4];		/* 0x1f4 */
112
-    uint16_t ramdisk_flags;		/* 0x1f8 */
113
-#define RAMDISK_IMAGE_START_MASK  	0x07FF
114
-#define RAMDISK_PROMPT_FLAG		0x8000
115
-#define RAMDISK_LOAD_FLAG		0x4000	
116
-    uint8_t  reserved8[2];		/* 0x1fa */
117
-    uint16_t orig_root_dev;		/* 0x1fc */
118
-    uint8_t  reserved9[1];		/* 0x1fe */
119
-    uint8_t  aux_device_info;		/* 0x1ff */
120
-    uint8_t  reserved10[2];		/* 0x200 */
121
-    uint8_t  param_block_signature[4];	/* 0x202 */
122
-    uint16_t param_block_version;	/* 0x206 */
123
-    uint8_t  reserved11[8];		/* 0x208 */
124
-    uint8_t  loader_type;		/* 0x210 */
125
-#define LOADER_TYPE_LOADLIN         1
126
-#define LOADER_TYPE_BOOTSECT_LOADER 2
127
-#define LOADER_TYPE_SYSLINUX        3
128
-#define LOADER_TYPE_ETHERBOOT       4
129
-#define LOADER_TYPE_KERNEL          5
130
-    uint8_t  loader_flags;		/* 0x211 */
131
-    uint8_t  reserved12[2];		/* 0x212 */
132
-    uint32_t kernel_start;		/* 0x214 */
133
-    uint32_t initrd_start;		/* 0x218 */
134
-    uint32_t initrd_size;		/* 0x21c */
135
-    uint8_t  reserved12_5[8];		/* 0x220 */
136
-    uint32_t cmd_line_ptr;		/* 0x228 */
137
-    uint8_t  reserved13[164];		/* 0x22c */
138
-    struct e820entry e820_map[E820MAX];	/* 0x2d0 */
139
-    uint8_t  reserved16[688];		/* 0x550 */
140
-#define COMMAND_LINE_SIZE 256
141
-    /* Command line is copied here by 32-bit i386/kernel/head.S.
142
-     * So I will follow the boot protocol, rather than putting it
143
-     * directly here. --ts1 */
144
-    uint8_t  command_line[COMMAND_LINE_SIZE]; /* 0x800 */
145
-    uint8_t  reserved17[1792];		/* 0x900 - 0x1000 */
146
-};
147
-
148
-uint64_t forced_memsize;
149
-
150
-/* Load the first part the file and check if it's Linux */
151
-static uint32_t load_linux_header(struct linux_header *hdr)
152
-{
153
-    int load_high;
154
-    uint32_t kern_addr;
155
-
156
-    if (file_read(hdr, sizeof *hdr) != sizeof *hdr) {
157
-	debug("Can't read Linux header\n");
158
-	return 0;
159
-    }
160
-    if (hdr->boot_sector_magic != 0xaa55) {
161
-	debug("Not a Linux kernel image\n");
162
-	return 0;
163
-    }
164
-
165
-    /* Linux is found. Print some information */
166
-    if (memcmp(hdr->header_magic, "HdrS", 4) != 0) {
167
-	/* This may be floppy disk image or something.
168
-	 * Perform a simple (incomplete) sanity check. */
169
-	if (hdr->setup_sects >= 16
170
-		|| file_size() - (hdr->setup_sects<<9) >= 512<<10) {
171
-	    debug("This looks like a bootdisk image but not like Linux...\n");
172
-	    return 0;
173
-	}
174
-
175
-	debugx("Possible very old Linux");
176
-	/* This kernel does not even have a protocol version.
177
-	 * Force the value. */
178
-	hdr->protocol_version = 0; /* pre-2.00 */
179
-    } else
180
-	printf("Found Linux");
181
-    if (hdr->protocol_version >= 0x200 && hdr->kver_addr) {
182
-	char kver[256];
183
-	file_seek(hdr->kver_addr + 0x200);
184
-	if (file_read(kver, sizeof kver) != 0) {
185
-	    kver[255] = 0;
186
-	    printf(" version %s", kver);
187
-	}
188
-    }
189
-    debug(" (protocol %#x)", hdr->protocol_version);
190
-    load_high = 0;
191
-    if (hdr->protocol_version >= 0x200) {
192
-	debug(" (loadflags %#x)", hdr->loadflags);
193
-	load_high = hdr->loadflags & 1;
194
-    }
195
-    if (load_high) {
196
-	printf(" bzImage");
197
-	kern_addr = 0x100000;
198
-    } else {
199
-	printf(" zImage or Image");
200
-	kern_addr = 0x1000;
201
-    }
202
-    printf(".\n");
203
-
204
-    return kern_addr;
205
-}
206
-
207
-/* Set up parameters for 32-bit kernel */
208
-static void
209
-init_linux_params(struct linux_params *params, struct linux_header *hdr)
210
-{
211
-    debug("Setting up paramters at %#lx\n", virt_to_phys(params));
212
-    memset(params, 0, sizeof *params);
213
-
214
-    /* Copy some useful values from header */
215
-    params->mount_root_rdonly = hdr->root_flags;
216
-    params->orig_root_dev = hdr->root_dev;
217
-
218
-    /* Video parameters.
219
-     * This assumes we have VGA in standard 80x25 text mode,
220
-     * just like our vga.c does.
221
-     * Cursor position is filled later to allow some more printf's. */
222
-    params->orig_video_mode = 3;
223
-    params->orig_video_cols = 80;
224
-    params->orig_video_lines = 25;
225
-    params->orig_video_isVGA = 1;
226
-    params->orig_video_points = 16;
227
-
228
-    params->loader_type = 0xff; /* Unregistered Linux loader */
229
-}
230
-
231
-/* Memory map */
232
-static void
233
-set_memory_size(struct linux_params *params, struct sys_info *info)
234
-{
235
-    uint32_t i;
236
-    uint32_t ramtop = 0;
237
-    struct e820entry *linux_map;
238
-    struct e820entry *filo_map;	
239
-
240
-    linux_map = params->e820_map;
241
-    
242
-    filo_map = meminfo.map;
243
-    for (i = 0; i < meminfo.map_count; i++, linux_map++, filo_map++) {
244
-        if (i < E820MAX) {
245
-            /* Convert to BIOS e820 style */
246
-            linux_map->addr = filo_map->addr;
247
-            linux_map->size = filo_map->size;
248
-            linux_map->type = filo_map->type;
249
-//            debug("%016Lx - %016Lx\n", linux_map->addr,linux_map->addr + linux_map->size);
250
-            params->e820_map_nr = i+1;
251
-        }
252
-
253
-    }
254
-    ramtop = meminfo.memsize;
255
-    debug("ramtop=%#xk\n", ramtop);
256
-    /* Size of memory above 1MB in KB */
257
-    params->alt_mem_k = ramtop;
258
-    /* old style, 64MB max */
259
-    if (ramtop >= (64<<10))
260
-	params->ext_mem_k = (63<<10);
261
-    else
262
-	params->ext_mem_k = params->alt_mem_k;
263
-
264
-    debug("ext_mem_k=%d, alt_mem_k=%d\n", params->ext_mem_k, params->alt_mem_k);
265
-}
266
-
267
-/*
268
- * Parse command line
269
- * Some parameters, like initrd=<file>, are not passed to kernel,
270
- * we are responsible to process them.
271
- * Parameters for kernel are copied to kern_cmdline. Returns name of initrd.
272
- */
273
-static char *parse_command_line(const char *orig_cmdline, char *kern_cmdline)
274
-{
275
-    const char *start, *sep, *end, *val;
276
-    char name[64];
277
-    int len;
278
-    int k_len;
279
-    int to_kern;
280
-    char *initrd = 0;
281
-    int toolong = 0;
282
-
283
-    forced_memsize = 0;
284
-
285
-    if (!orig_cmdline) {
286
-	*kern_cmdline = 0;
287
-	return 0;
288
-    }
289
-
290
-    k_len = 0;
291
-    debug("original command line: \"%s\"\n", orig_cmdline);
292
-    debug("kernel command line at %#lx\n", virt_to_phys(kern_cmdline));
293
-
294
-    start = orig_cmdline;
295
-    while (*start == ' ')
296
-	start++;
297
-    while (*start) {
298
-	end = strchr(start, ' ');
299
-	if (!end)
300
-	    end = start + strlen(start);
301
-	sep = strchr(start, '=');
302
-	if (!sep || sep > end)
303
-	    sep = end;
304
-	len = sep - start;
305
-	if (len >= sizeof(name))
306
-	    len = sizeof(name) - 1;
307
-	memcpy(name, start, len);
308
-	name[len] = 0;
309
-
310
-	if (*sep == '=') {
311
-	    val = sep + 1;
312
-	    len = end - val;
313
-	} else {
314
-	    val = 0;
315
-	    len = 0;
316
-	}
317
-
318
-	/* Only initrd= and mem= are handled here. vga= is not,
319
-	 * which I believe is a paramter to the realmode part of Linux,
320
-	 * which we don't execute. */
321
-	if (strcmp(name, "initrd") == 0) {
322
-	    if (!val)
323
-		printf("Missing filename to initrd parameter\n");
324
-	    else {
325
-		initrd = allot(len + 1);
326
-		memcpy(initrd, val, len);
327
-		initrd[len] = 0;
328
-		debug("initrd=%s\n", initrd);
329
-	    }
330
-	    /* Don't pass this to kernel */
331
-	    to_kern = 0;
332
-	} else if (strcmp(name, "mem") == 0) {
333
-	    if (!val)
334
-		printf("Missing value for mem parameter\n");
335
-	    else {
336
-		forced_memsize = strtoull_with_suffix(val, (char**)&val, 0);
337
-		if (forced_memsize == 0)
338
-		    printf("Invalid mem option, ignored\n");
339
-		if (val != end) {
340
-		    printf("Garbage after mem=<size>, ignored\n");
341
-		    forced_memsize = 0;
342
-		}
343
-//		debug("mem=%Lu\n", forced_memsize);
344
-	    }
345
-	    /* mem= is for both loader and kernel */
346
-	    to_kern = 1;
347
-	} else
348
-	    to_kern = 1;
349
-
350
-	if (to_kern) {
351
-	    /* Copy to kernel command line buffer */
352
-	    if (k_len != 0)
353
-		kern_cmdline[k_len++] = ' '; /* put separator */
354
-	    len = end - start;
355
-	    if (k_len + len >= COMMAND_LINE_SIZE) {
356
-		len = COMMAND_LINE_SIZE - k_len - 1;
357
-		if (!toolong) {
358
-		    printf("Kernel command line is too long; truncated to "
359
-			    "%d bytes\n", COMMAND_LINE_SIZE-1);
360
-		    toolong = 1;
361
-		}
362
-	    }
363
-	    memcpy(kern_cmdline + k_len, start, len);
364
-	    k_len += len;
365
-	}
366
-
367
-	start = end;
368
-	while (*start == ' ')
369
-	    start++;
370
-    }
371
-    kern_cmdline[k_len] = 0;
372
-    debug("kernel command line (%d bytes): \"%s\"\n", k_len, kern_cmdline);
373
-
374
-    return initrd;
375
-}
376
-
377
-/* Set command line location */
378
-static void set_command_line_loc(struct linux_params *params,
379
-	struct linux_header *hdr)
380
-{
381
-    if (hdr->protocol_version >= 0x202) {
382
-	/* new style */
383
-	params->cmd_line_ptr = COMMAND_LINE_LOC;
384
-    } else {
385
-	/* old style */
386
-	params->cl_magic = CL_MAGIC_VALUE;
387
-	params->cl_offset = COMMAND_LINE_LOC - LINUX_PARAM_LOC;
388
-    }
389
-}
390
-
391
-/* Load 32-bit part of kernel */
392
-static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr)
393
-{
394
-    uint32_t kern_offset, kern_size;
395
-
396
-    if (hdr->setup_sects == 0)
397
-	hdr->setup_sects = 4;
398
-    kern_offset = (hdr->setup_sects + 1) * 512;
399
-    file_seek(kern_offset);
400
-    kern_size = file_size() - kern_offset;
401
-    debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size);
402
-
403
-    if (using_devsize) {
404
-	printf("Attempt to load up to end of device as kernel; "
405
-		"specify the image size\n");
406
-	return 0;
407
-    }
408
-
409
-    printf("Loading kernel... ");
410
-    if (file_read(phys_to_virt(kern_addr), kern_size) != kern_size) {
411
-	printf("Can't read kernel\n");
412
-	return 0;
413
-    }
414
-    printf("ok\n");
415
-
416
-    return kern_size;
417
-}
418
-
419
-static int load_initrd(struct linux_header *hdr, struct sys_info *info,
420
-	uint32_t kern_end, struct linux_params *params, const char *initrd_file)
421
-{
422
-    uint32_t max;
423
-    uint32_t start, end, size;
424
-    uint64_t forced;
425
-    extern char _virt_start[], _end[];
426
-
427
-    if (!file_open(initrd_file)) {
428
-	printf("Can't open initrd: %s\n", initrd_file);
429
-	return -1;
430
-    }
431
-    if (using_devsize) {
432
-	printf("Attempt to load up to end of device as initrd; "
433
-		"specify the image size\n");
434
-	return -1;
435
-    }
436
-    size = file_size();
437
-
438
-
439
-    /* Find out the kernel's restriction on how high the initrd can be
440
-     * placed */
441
-    if (hdr->protocol_version >= 0x203)
442
-	max = hdr->initrd_addr_max;
443
-    else
444
-	max = 0x38000000; /* Hardcoded value for older kernels */
445
-    
446
-    /* FILO itself is at the top of RAM. (relocated)
447
-     * So, try putting initrd just below us. */
448
-    end = virt_to_phys(_virt_start);
449
-    if (end > max)
450
-	end = max;
451
-
452
-    /* If "mem=" option is given, we have to put the initrd within
453
-     * the specified range. */
454
-    if (forced_memsize) {
455
-	forced = forced_memsize;
456
-	if (forced > max)
457
-	    forced = max;
458
-	/* If the "mem=" is lower, it's easy */
459
-	if (forced <= end)
460
-	    end = forced;
461
-	else {
462
-	    /* Otherwise, see if we can put it above us */
463
-	    if (virt_to_phys(_end) + size <= forced)
464
-		end = forced; /* Ok */
465
-	}
466
-    }
467
-
468
-    start = end - size;
469
-    start &= ~0xfff; /* page align */
470
-    end = start + size;
471
-
472
-    debug("start=%#x end=%#x\n", start, end);
473
-
474
-    if (start < kern_end) {
475
-	printf("Initrd is too big\n");
476
-	return -1;
477
-    }
478
-
479
-    printf("Loading initrd... ");
480
-    if (file_read(phys_to_virt(start), size) != size) {
481
-	printf("Can't read initrd\n");
482
-	return -1;
483
-    }
484
-    printf("ok\n");
485
-
486
-    params->initrd_start = start;
487
-    params->initrd_size = size;
488
-
489
-    return 0;
490
-}
491
-
492
-static void hardware_setup(void)
493
-{
494
-    /* Disable nmi */
495
-    outb(0x80, 0x70);
496
-
497
-    /* Make sure any coprocessor is properly reset.. */
498
-    outb(0, 0xf0);
499
-    outb(0, 0xf1);
500
-
501
-    /* we're getting screwed again and again by this problem of the 8259. 
502
-     * so we're going to leave this lying around for inclusion into 
503
-     * crt0.S on an as-needed basis. 
504
-     *
505
-     * well, that went ok, I hope. Now we have to reprogram the interrupts :-(
506
-     * we put them right after the intel-reserved hardware interrupts, at
507
-     * int 0x20-0x2F. There they won't mess up anything. Sadly IBM really
508
-     * messed this up with the original PC, and they haven't been able to
509
-     * rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f,
510
-     * which is used for the internal hardware interrupts as well. We just
511
-     * have to reprogram the 8259's, and it isn't fun.
512
-     */
513
-
514
-    outb(0x11, 0x20);		/* initialization sequence to 8259A-1 */
515
-    outb(0x11, 0xA0);		/* and to 8259A-2 */
516
-
517
-    outb(0x20, 0x21);		/* start of hardware int's (0x20) */
518
-    outb(0x28, 0xA1);		/* start of hardware int's 2 (0x28) */
519
-
520
-    outb(0x04, 0x21);		/* 8259-1 is master */
521
-    outb(0x02, 0xA1);		/* 8259-2 is slave */
522
-
523
-    outb(0x01, 0x21);		/* 8086 mode for both */
524
-    outb(0x01, 0xA1);
525
-
526
-    outb(0xFF, 0xA1);		/* mask off all interrupts for now */
527
-    outb(0xFB, 0x21);		/* mask all irq's but irq2 which is cascaded */
528
-}
529
-
530
-/* Start Linux */
531
-static int start_linux(uint32_t kern_addr, struct linux_params *params)
532
-{
533
-    struct segment_desc *linux_gdt;
534
-    struct context *ctx;
535
-#if 0
536
-    extern int cursor_x, cursor_y;
537
-#endif
538
-
539
-    ctx = init_context(phys_to_virt(STACK_LOC), 4096, 0);
540
-
541
-    /* Linux expects GDT being in low memory */
542
-    linux_gdt = phys_to_virt(GDT_LOC);
543
-    memset(linux_gdt, 0, 13*sizeof(struct segment_desc));
544
-    /* Normal kernel code/data segments */
545
-    linux_gdt[2] = gdt[FLAT_CODE];
546
-    linux_gdt[3] = gdt[FLAT_DATA];
547
-    /* 2.6 kernel uses 12 and 13, but head.S uses backward-compatible
548
-     * segments (2 and 3), so it SHOULD not be a problem. 
549
-     * However, some distro kernels (eg. RH9) with backported threading 
550
-     * patch use 12 and 13 also when booting... */
551
-    linux_gdt[12] = gdt[FLAT_CODE];
552
-    linux_gdt[13] = gdt[FLAT_DATA];
553
-    ctx->gdt_base = GDT_LOC;
554
-    ctx->gdt_limit = 14*8-1;
555
-    ctx->cs = 0x10;
556
-    ctx->ds = 0x18;
557
-    ctx->es = 0x18;
558
-    ctx->fs = 0x18;
559
-    ctx->gs = 0x18;
560
-    ctx->ss = 0x18;
561
-
562
-    /* Parameter location */
563
-    ctx->esi = virt_to_phys(params);
564
-
565
-    /* Entry point */
566
-    ctx->eip = kern_addr;
567
-
568
-    debug("eip=%#x\n", kern_addr);
569
-    printf("Jumping to entry point...\n");
570
-
571
-#ifdef VGA_CONSOLE
572
-    /* Update VGA cursor position.
573
-     * This must be here because the printf changes the value! */
574
-#if 0
575
-    params->orig_x = cursor_x;
576
-    params->orig_y = cursor_y;
577
-#endif
578
-#endif
579
-    
580
-    /* Go... */
581
-    ctx = switch_to(ctx);
582
-
583
-    /* It's impossible but... */
584
-    printf("Returned with eax=%#x\n", ctx->eax);
585
-
586
-    return ctx->eax;
587
-}
588
-
589
-int linux_load(struct sys_info *info, const char *file, const char *cmdline)
590
-{
591
-    struct linux_header hdr;
592
-    struct linux_params *params;
593
-    uint32_t kern_addr, kern_size;
594
-    char *initrd_file = 0;
595
-
596
-    if (!file_open(file))
597
-	return -1;
598
-	
599
-    kern_addr = load_linux_header(&hdr);
600
-    if (kern_addr == 0)
601
-	return LOADER_NOT_SUPPORT;
602
-
603
-    params = phys_to_virt(LINUX_PARAM_LOC);
604
-    init_linux_params(params, &hdr);
605
-    set_memory_size(params, info);
606
-    initrd_file = parse_command_line(cmdline, phys_to_virt(COMMAND_LINE_LOC));
607
-    set_command_line_loc(params, &hdr);
608
-
609
-    kern_size = load_linux_kernel(&hdr, kern_addr);
610
-    if (kern_size == 0) {
611
-	if (initrd_file)
612
-	    forget(initrd_file);
613
-	return -1;
614
-    }
615
-
616
-    if (initrd_file) {
617
-	if (load_initrd(&hdr, info, kern_addr+kern_size, params, initrd_file)
618
-		!= 0) {
619
-	    forget(initrd_file);
620
-	    return -1;
621
-	}
622
-	forget(initrd_file);
623
-    }
624
-
625
-    hardware_setup();
626
-
627
-    start_linux(kern_addr, params);
628
-    return 0;
629
-}

+ 0
- 129
src/filo/i386/multiboot.c Целия файл

@@ -1,129 +0,0 @@
1
-/* Support for Multiboot */
2
-#include <etherboot.h>
3
-
4
-#include <lib.h>
5
-#include <sys_info.h>
6
-#include <arch/io.h>
7
-
8
-#define DEBUG_THIS DEBUG_MULTIBOOT
9
-#include <debug.h>
10
-
11
-/* Multiboot header, gives information to loader */
12
-
13
-#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
14
-#define MULTIBOOT_HEADER_FLAGS 0x00000003
15
-
16
-struct mbheader {
17
-    unsigned int magic, flags, checksum;
18
-};
19
-const struct mbheader multiboot_header
20
-	__attribute__((section (".hdr"))) =
21
-{
22
-    MULTIBOOT_HEADER_MAGIC,
23
-    MULTIBOOT_HEADER_FLAGS,
24
-    -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
25
-};
26
-
27
-/* Multiboot information structure, provided by loader to us */
28
-
29
-struct multiboot_mmap {
30
-	unsigned entry_size;
31
-	unsigned base_lo, base_hi;
32
-	unsigned size_lo, size_hi;
33
-	unsigned type;
34
-};
35
-
36
-struct multiboot_info {
37
-        unsigned flags;
38
-#define MULTIBOOT_MEM_VALID       0x01
39
-#define MULTIBOOT_BOOT_DEV_VALID  0x02
40
-#define MULTIBOOT_CMDLINE_VALID   0x04
41
-#define MULTIBOOT_MODS_VALID      0x08
42
-#define MULTIBOOT_AOUT_SYMS_VALID 0x10
43
-#define MULTIBOOT_ELF_SYMS_VALID  0x20
44
-#define MULTIBOOT_MMAP_VALID      0x40
45
-	unsigned mem_lower;
46
-	unsigned mem_upper;
47
-	unsigned char boot_device[4];
48
-	unsigned command_line;
49
-	unsigned mods_count;
50
-	unsigned mods_addr;
51
-	unsigned syms_num;
52
-	unsigned syms_size;
53
-	unsigned syms_addr;
54
-	unsigned syms_shndx;
55
-	unsigned mmap_length;
56
-	unsigned mmap_addr;
57
-};
58
-
59
-void collect_multiboot_info(struct sys_info *info)
60
-{
61
-    struct multiboot_info *mbinfo;
62
-    struct multiboot_mmap *mbmem;
63
-    unsigned mbcount, mbaddr;
64
-    int i;
65
-    struct memrange *mmap;
66
-    int mmap_count;
67
-
68
-    if (info->boot_type != 0x2BADB002)
69
-	return;
70
-
71
-    debug("Using Multiboot information at %#lx\n", info->boot_data);
72
-
73
-    mbinfo = phys_to_virt(info->boot_data);
74
-
75
-    if (mbinfo->flags & MULTIBOOT_MMAP_VALID) {
76
-	/* convert mmap records */
77
-	mbmem = phys_to_virt(mbinfo->mmap_addr);
78
-	mbcount = mbinfo->mmap_length / (mbmem->entry_size + 4);
79
-	mmap = malloc(mbcount * sizeof *mmap);
80
-	mmap_count = 0;
81
-	mbaddr = mbinfo->mmap_addr;
82
-	for (i = 0; i < mbcount; i++) {
83
-	    mbmem = phys_to_virt(mbaddr);
84
-	    debug("%08x%08x %08x%08x (%d)\n",
85
-		    mbmem->base_hi,
86
-		    mbmem->base_lo,
87
-		    mbmem->size_hi,
88
-		    mbmem->size_lo,
89
-		    mbmem->type);
90
-	    if (mbmem->type == 1) { /* Only normal RAM */
91
-		mmap[mmap_count].base = mbmem->base_lo
92
-		    + (((unsigned long long) mbmem->base_hi) << 32);
93
-		mmap[mmap_count].size = mbmem->size_lo
94
-		    + (((unsigned long long) mbmem->size_hi) << 32);
95
-		mmap_count++;
96
-	    }
97
-	    mbaddr += mbmem->entry_size + 4;
98
-	    if (mbaddr >= mbinfo->mmap_addr + mbinfo->mmap_length)
99
-		break;
100
-	}
101
-	/* simple sanity check - there should be at least 2 RAM segments
102
-	 * (base 640k and extended) */
103
-	if (mmap_count >= 2)
104
-	    goto got_it;
105
-
106
-	printf("Multiboot mmap is broken\n");
107
-	free(mmap);
108
-	/* fall back to mem_lower/mem_upper */
109
-    }
110
-
111
-    if (mbinfo->flags & MULTIBOOT_MEM_VALID) {
112
-	/* use mem_lower and mem_upper */
113
-	mmap_count = 2;
114
-	mmap = malloc(2 * sizeof(*mmap));
115
-	mmap[0].base = 0;
116
-	mmap[0].size = mbinfo->mem_lower << 10;
117
-	mmap[1].base = 1 << 20; /* 1MB */
118
-	mmap[1].size = mbinfo->mem_upper << 10;
119
-	goto got_it;
120
-    }
121
-
122
-    printf("Can't get memory information from Multiboot\n");
123
-    return;
124
-
125
-got_it:
126
-    info->memrange = mmap;
127
-    info->n_memranges = mmap_count;
128
-    return;
129
-}

+ 0
- 48
src/filo/i386/segment.c Целия файл

@@ -1,48 +0,0 @@
1
-/* Segmentation of the i386 architecture.
2
- *
3
- * 2003-07 by SONE Takeshi
4
- */
5
-#include <etherboot.h>
6
-
7
-//#include <lib.h>
8
-#include <sys_info.h>
9
-#include "segment.h"
10
-
11
-#define DEBUG_THIS DEBUG_SEGMENT
12
-#include <debug.h>
13
-
14
-/* i386 lgdt argument */
15
-struct gdtarg {
16
-    unsigned short limit;
17
-    unsigned int base;
18
-} __attribute__((packed));
19
-
20
-/* GDT, the global descriptor table */
21
-struct segment_desc gdt[NUM_SEG] = {
22
-    /* 0x00: null segment */
23
-    {0, 0, 0, 0, 0, 0},
24
-    /* 0x08: flat code segment */
25
-    {0xffff, 0, 0, 0x9f, 0xcf, 0},
26
-    /* 0x10: flat data segment */
27
-    {0xffff, 0, 0, 0x93, 0xcf, 0},
28
-    /* 0x18: code segment for relocated execution */
29
-    {0xffff, 0, 0, 0x9f, 0xcf, 0},
30
-    /* 0x20: data segment for relocated execution */
31
-    {0xffff, 0, 0, 0x93, 0xcf, 0},
32
-};
33
-
34
-/* Copy GDT to new location and reload it */
35
-void move_gdt(unsigned long newgdt)
36
-{
37
-    struct gdtarg gdtarg;
38
-
39
-    debug("Moving GDT to %#lx...", newgdt);
40
-    memcpy(phys_to_virt(newgdt), gdt, sizeof gdt);
41
-    gdtarg.base = newgdt;
42
-    gdtarg.limit = GDT_LIMIT;
43
-    debug("reloading GDT...");
44
-    __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
45
-    debug("reloading CS for fun...");
46
-    __asm__ __volatile__ ("ljmp %0, $1f\n1:" : : "n" (RELOC_CS));
47
-    debug("ok\n");
48
-}

+ 0
- 29
src/filo/i386/segment.h Целия файл

@@ -1,29 +0,0 @@
1
-/* Segment indexes. Must match the gdt definition in segment.c. */
2
-enum {
3
-    NULL_SEG,
4
-    FLAT_CODE,
5
-    FLAT_DATA,
6
-    RELOC_CODE,
7
-    RELOC_DATA,
8
-    NUM_SEG,
9
-};
10
-
11
-/* Values for segment selector register */
12
-#define FLAT_CS (FLAT_CODE << 3)
13
-#define FLAT_DS (FLAT_DATA << 3)
14
-#define RELOC_CS (RELOC_CODE << 3)
15
-#define RELOC_DS (RELOC_DATA << 3)
16
-
17
-/* i386 segment descriptor */
18
-struct segment_desc {
19
-    unsigned short limit_0;
20
-    unsigned short base_0;
21
-    unsigned char base_16;
22
-    unsigned char types;
23
-    unsigned char flags;
24
-    unsigned char base_24;
25
-};
26
-
27
-extern struct segment_desc gdt[NUM_SEG];
28
-
29
-#define GDT_LIMIT ((NUM_SEG << 3) - 1)

+ 0
- 116
src/filo/i386/switch.S Целия файл

@@ -1,116 +0,0 @@
1
-	.globl	entry, __switch_context, __exit_context, halt
2
-
3
-	.text
4
-	.align	4
5
-
6
-/*
7
- * Entry point
8
- * We start execution from here.
9
- * It is assumed that CPU is in 32-bit protected mode and 
10
- * all segments are 4GB and base zero (flat model).
11
- */
12
-entry:
13
-	/* Save boot context and switch to our main context.
14
-	 * Main context is statically defined in C.
15
-	 */
16
-	pushl	%cs
17
-	call	__switch_context
18
-
19
-	/* We get here when the main context switches back to
20
-	 * the boot context.
21
-	 * Return to previous bootloader.
22
-	 */
23
-	ret
24
-
25
-/*
26
- * Switch execution context
27
- * This saves registers, segments, and GDT in the stack, then
28
- * switches the stack, and restores everything from the new stack.
29
- * This function takes no argument. New stack pointer is
30
- * taken from global variable __context, and old stack pointer
31
- * is also saved to __context. This way we can just jump to 
32
- * this routine to get back to the original context.
33
- *
34
- * Call this routine with lcall or pushl %cs; call.
35
- */
36
-__switch_context:
37
-	/* Save everything in current stack */
38
-	pushfl		    /* 56 */
39
-	pushl	%ds	    /* 52 */
40
-	pushl	%es	    /* 48 */
41
-	pushl	%fs	    /* 44 */
42
-	pushl	%gs	    /* 40 */
43
-	pushal		    /* 8 */
44
-	subl	$8, %esp
45
-	movw	%ss, (%esp) /* 0 */
46
-	sgdt	2(%esp)	    /* 2 */
47
-
48
-#if 0
49
-	/* Swap %cs and %eip on the stack, so lret will work */
50
-	movl	60(%esp), %eax
51
-	xchgl	%eax, 64(%esp)
52
-	movl	%eax, 60(%esp)
53
-#endif
54
-	
55
-	/* At this point we don't know if we are on flat segment
56
-	 * or relocated. So compute the address offset from %eip.
57
-	 * Assuming CS.base==DS.base==SS.base.
58
-	 */
59
-	call	1f
60
-1:	popl	%ebx
61
-	subl	$1b, %ebx
62
-
63
-	/* Interrupts are not allowed... */
64
-	cli
65
-	
66
-	/* Current context pointer is our stack pointer */
67
-	movl	%esp, %esi
68
-
69
-	/* Normalize the ctx pointer */
70
-	subl	%ebx, %esi
71
-
72
-	/* Swap it with new value */
73
-	xchgl	%esi, __context(%ebx)
74
-
75
-	/* Adjust new ctx pointer for current address offset */
76
-	addl	%ebx, %esi
77
-
78
-	/* Load new %ss and %esp to temporary */
79
-	movzwl	(%esi), %edx
80
-	movl	20(%esi), %eax
81
-
82
-	/* Load new GDT */
83
-	lgdt	2(%esi)
84
-
85
-	/* Load new stack segment with new GDT */
86
-	movl	%edx, %ss
87
-
88
-	/* Set new stack pointer, but we have to adjust it because
89
-	 * pushal saves %esp value before pushal, and we want the value
90
-	 * after pushal.
91
-	 */
92
-	leal	-32(%eax), %esp
93
-
94
-	/* Load the rest from new stack */
95
-	popal
96
-	popl	%gs
97
-	popl	%fs
98
-	popl	%es
99
-	popl	%ds
100
-	popfl
101
-
102
-	/* Finally, load new %cs and %eip */
103
-	lret
104
-
105
-__exit_context:
106
-	/* Get back to the original context */
107
-	pushl	%cs
108
-	call	__switch_context
109
-
110
-	/* We get here if the other context attempt to switch to this
111
-	 * dead context. This should not happen. */
112
-
113
-halt:
114
-	cli
115
-	hlt
116
-	jmp	halt

+ 0
- 29
src/filo/i386/sys_info.c Целия файл

@@ -1,29 +0,0 @@
1
-#include <etherboot.h>
2
-#include <sys_info.h>
3
-#include "context.h"
4
-#define DEBUG_THIS DEBUG_SYS_INFO
5
-#include <debug.h>
6
-
7
-void collect_multiboot_info(struct sys_info *);
8
-
9
-void collect_sys_info(struct sys_info *info)
10
-{
11
-
12
-    /* Pick up paramters given by bootloader to us */
13
-    info->boot_type = boot_ctx->eax;
14
-    info->boot_data = boot_ctx->ebx;
15
-    info->boot_arg = boot_ctx->param[0];
16
-    debug("boot eax = %#lx\n", info->boot_type);
17
-    debug("boot ebx = %#lx\n", info->boot_data);
18
-    debug("boot arg = %#lx\n", info->boot_arg);
19
-
20
-    collect_elfboot_info(info);
21
-    collect_linuxbios_info(info);
22
-#ifdef MULTIBOOT_IMAGE
23
-    collect_multiboot_info(info);
24
-#endif
25
-
26
-#if 0
27
-    debug("RAM %Ld MB\n", (meminfo.memsize + 512*1024) >> 20);
28
-#endif
29
-}

+ 0
- 74
src/filo/main/console_x.c Целия файл

@@ -1,74 +0,0 @@
1
-
2
-#include "etherboot.h"
3
-
4
-#include <lib.h>
5
-
6
-int getline(char *buf, int max)
7
-{               
8
-    int cur, ch, nonspace_seen;
9
-            
10
-    cur = 0;
11
-    while (buf[cur]) {
12
-        putchar(buf[cur]);
13
-        cur++;  
14
-    }
15
-    for (;;) {
16
-        ch = getchar();
17
-        switch (ch) {
18
-        /* end of line */
19
-        case '\r':
20
-        case '\n':
21
-            putchar('\n');
22
-            goto out;
23
-        /* backspace */
24
-        case '\b':
25
-        case '\x7f':
26
-            if (cur > 0) {
27
-                cur--;
28
-                putchar('\b');
29
-                putchar(' ');
30
-                putchar('\b');
31
-            }
32
-            break;
33
-        /* word erase */
34
-        case 'W' & 0x1f: /* ^W */
35
-            nonspace_seen = 0;
36
-            while (cur) {
37
-                if (buf[cur-1] != ' ')
38
-                    nonspace_seen = 1;
39
-                putchar('\b');
40
-                putchar(' ');
41
-                putchar('\b');
42
-                cur--;
43
-                if (nonspace_seen && cur < max-1 && cur > 0 && buf[cur-1]==' ')
44
-                    break;
45
-            }
46
-            break;
47
-        /* line erase */
48
-        case 'U' & 0x1f: /* ^U */
49
-            while (cur) {
50
-                putchar('\b');
51
-                putchar(' ');
52
-                putchar('\b');
53
-                cur--;
54
-            }
55
-            cur = 0;
56
-            break;
57
-        default:
58
-            if (ch < 0x20)
59
-                break; /* ignore control char */
60
-            if (ch >= 0x7f)
61
-                break;
62
-            if (cur + 1 < max) {
63
-                putchar(ch); /* echo back */
64
-                buf[cur] = ch;
65
-                cur++;
66
-            }
67
-        }
68
-    }
69
-out:
70
-    if (cur >= max)
71
-        cur = max - 1;
72
-    buf[cur] = '\0';
73
-    return cur;
74
-}                                                   

+ 0
- 398
src/filo/main/elfload.c Целия файл

@@ -1,398 +0,0 @@
1
-/* ELF Boot loader
2
- * As we have seek, this implementation can be straightforward.
3
- * 2003-07 by SONE Takeshi
4
- */
5
-#include <etherboot.h>
6
-#include <elf.h>
7
-#include <bits/elf_x.h>
8
-#include <elf_boot.h>
9
-#include <lib.h>
10
-#include <sys_info.h>
11
-
12
-#include <fs.h>
13
-#define DEBUG_THIS DEBUG_ELFBOOT
14
-#include <debug.h>
15
-
16
-#if 1
17
-//Use that in Etherboot
18
-extern int elf_start(unsigned long __unused_i386, unsigned long entry, unsigned long param);
19
-#define start_elf(x,y) elf_start(0, x, y)
20
-#else
21
-// original in filo
22
-extern unsigned int start_elf(unsigned long entry_point, unsigned long param);
23
-#endif
24
-
25
-extern char _virt_start[], _end[];
26
-
27
-static char *image_name, *image_version;
28
-
29
-static int check_mem_ranges(struct sys_info *info,
30
-	Elf_phdr *phdr, int phnum)
31
-{
32
-    int i, j;
33
-    unsigned long start, end;
34
-    unsigned long prog_start, prog_end;
35
-#if 0
36
-    struct memrange *mem;
37
-#else 
38
-    struct e820entry *mem;
39
-#endif
40
-
41
-    prog_start = virt_to_phys(&_virt_start);
42
-    prog_end = virt_to_phys(&_end);
43
-
44
-    for (i = 0; i < phnum; i++) {
45
-	if (phdr[i].p_type != PT_LOAD)
46
-	    continue;
47
-	start = phdr[i].p_paddr;
48
-	end = start + phdr[i].p_memsz;
49
-	if (start < prog_start && end > prog_start)
50
-	    goto conflict;
51
-	if (start < prog_end && end > prog_end)
52
-	    goto conflict;
53
-#if 0
54
-	for (j = 0; j < info->n_memranges; j++) {
55
-	    mem = &info->memrange[j];
56
-	    if (mem->base <= start && mem->base + mem->size >= end)
57
-		break;
58
-	}
59
-	if (j >= info->n_memranges)
60
-	    goto badseg;
61
-#else
62
-#define LB_MEM_RAM 1
63
-        for (j = 0; j < meminfo.map_count; j++) {
64
-            mem = &meminfo.map[j];
65
-	    if (mem->type!=LB_MEM_RAM) continue;
66
-            if (mem->addr <= start && mem->addr + mem->size >= end)
67
-                break;
68
-        }
69
-        if (j >= meminfo.map_count)
70
-            goto badseg;
71
-#endif
72
-    }
73
-    return 1;
74
-
75
-conflict:
76
-    printf("%s occupies [%#lx-%#lx]\n", program_name, prog_start, prog_end);
77
-
78
-badseg:
79
-    printf("Segment %d [%#lx-%#lx] doesn't fit into memory\n", i, start, end-1);
80
-    return 0;
81
-}
82
-
83
-static unsigned long process_image_notes(Elf_phdr *phdr, int phnum,
84
-	unsigned short *sum_ptr)
85
-{
86
-    int i;
87
-    char *buf = NULL;
88
-    int retval = 0;
89
-    unsigned long addr, end;
90
-    Elf_Nhdr *nhdr;
91
-    const char *name;
92
-    void *desc;
93
-
94
-    for (i = 0; i < phnum; i++) {
95
-	if (phdr[i].p_type != PT_NOTE)
96
-	    continue;
97
-	buf = allot(phdr[i].p_filesz);
98
-	file_seek(phdr[i].p_offset);
99
-	if (file_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) {
100
-	    printf("Can't read note segment\n");
101
-	    goto out;
102
-	}
103
-	addr = (unsigned long) buf;
104
-	end = addr + phdr[i].p_filesz;
105
-	while (addr < end) {
106
-	    nhdr = (Elf_Nhdr *) addr;
107
-	    addr += sizeof(Elf_Nhdr);
108
-	    name = (const char *) addr;
109
-	    addr += (nhdr->n_namesz+3) & ~3;
110
-	    desc = (void *) addr;
111
-	    addr += (nhdr->n_descsz+3) & ~3;
112
-
113
-	    if (nhdr->n_namesz==sizeof(ELF_NOTE_BOOT)
114
-		    && memcmp(name, ELF_NOTE_BOOT, sizeof(ELF_NOTE_BOOT))==0) {
115
-		if (nhdr->n_type == EIN_PROGRAM_NAME) {
116
-		    image_name = calloc(1, nhdr->n_descsz + 1);
117
-		    memcpy(image_name, desc, nhdr->n_descsz);
118
-		}
119
-		if (nhdr->n_type == EIN_PROGRAM_VERSION) {
120
-		    image_version = calloc(1, nhdr->n_descsz + 1);
121
-		    memcpy(image_version, desc, nhdr->n_descsz);
122
-		}
123
-		if (nhdr->n_type == EIN_PROGRAM_CHECKSUM) {
124
-		    *sum_ptr = *(unsigned short *) desc;
125
-		    debug("Image checksum: %04x\n", *sum_ptr);
126
-		    /* Where in the file */
127
-		    retval = phdr[i].p_offset
128
-			+ (unsigned long) desc - (unsigned long) buf;
129
-		}
130
-	    }
131
-	}
132
-    }
133
-out:
134
-    if (buf)
135
-	forget(buf);
136
-    return retval;
137
-}
138
-
139
-static int load_segments(Elf_phdr *phdr, int phnum,
140
-	unsigned long checksum_offset)
141
-{
142
-    unsigned long bytes;
143
-    unsigned int start_time, time;
144
-    int i;
145
-    int j;
146
-
147
-    bytes = 0;
148
-    start_time = currticks();
149
-#if 0
150
-    for (j = 0; j < phnum; j++) {
151
-        if (phdr[j].p_type != PT_LOAD) 
152
-            continue;
153
-        debug("0 segment %d addr:%#x file:%#x mem:%#x, phdr%#x\n",
154
-                j, phdr[j].p_paddr, phdr[j].p_filesz, phdr[j].p_memsz, virt_to_phys(&phdr[j]));
155
-    }
156
-#endif
157
-
158
-    for (i = 0; i < phnum; i++) {
159
-	if (phdr[i].p_type != PT_LOAD)
160
-	    continue;
161
-	debug("segment %d addr:%#x file:%#x mem:%#x phdr:%#x ",
162
-		i, phdr[i].p_paddr, phdr[i].p_filesz, phdr[i].p_memsz, virt_to_phys(&phdr[i]));
163
-	file_seek(phdr[i].p_offset);
164
-	debug("loading... ");
165
-	if (file_read(phys_to_virt(phdr[i].p_paddr), phdr[i].p_filesz)
166
-		!= phdr[i].p_filesz) {
167
-	    printf("Can't read program segment %d\n", i);
168
-	    return 0;
169
-	}
170
-	bytes += phdr[i].p_filesz;
171
-	debug("clearing... ");
172
-	memset(phys_to_virt(phdr[i].p_paddr + phdr[i].p_filesz), 0, 
173
-		phdr[i].p_memsz - phdr[i].p_filesz);
174
-	if (phdr[i].p_offset <= checksum_offset
175
-		&& phdr[i].p_offset + phdr[i].p_filesz >= checksum_offset+2) {
176
-	    debug("clearing checksum... ");
177
-	    memset(phys_to_virt(phdr[i].p_paddr + checksum_offset
178
-			- phdr[i].p_offset), 0, 2);
179
-	}
180
-	debug("ok\n");
181
-
182
-    }
183
-    time = (currticks() - start_time)*1000/18;
184
-    printf("Loaded %d bytes in %dms (%dKB/s)\n", bytes, time,
185
-	    time? bytes/time : 0);
186
-    return 1;
187
-}
188
-
189
-static int verify_image(Elf_ehdr *ehdr, Elf_phdr *phdr, int phnum,
190
-	unsigned short image_sum)
191
-{
192
-    unsigned short sum, part_sum;
193
-    unsigned long offset;
194
-    int i;
195
-
196
-    sum = 0;
197
-    offset = 0;
198
-
199
-    part_sum = ipchksum(ehdr, sizeof *ehdr);
200
-    sum = add_ipchksums(offset, sum, part_sum);
201
-    offset += sizeof *ehdr;
202
-
203
-    part_sum = ipchksum(phdr, phnum * sizeof(*phdr));
204
-    sum = add_ipchksums(offset, sum, part_sum);
205
-    offset += phnum * sizeof(*phdr);
206
-
207
-    for (i = 0; i < phnum; i++) {
208
-	if (phdr[i].p_type != PT_LOAD)
209
-	    continue;
210
-	part_sum = ipchksum(phys_to_virt(phdr[i].p_paddr), phdr[i].p_memsz);
211
-	sum = add_ipchksums(offset, sum, part_sum);
212
-	offset += phdr[i].p_memsz;
213
-    }
214
-
215
-    if (sum != image_sum) {
216
-	printf("Verify FAILED (image:%04x vs computed:%04x)\n",
217
-		image_sum, sum);
218
-	return 0;
219
-    }
220
-    return 1;
221
-}
222
-
223
-static inline unsigned const padded(unsigned s)
224
-{
225
-    return (s + 3) & ~3;
226
-}
227
-
228
-static Elf_Bhdr *add_boot_note(Elf_Bhdr *bhdr, const char *name,
229
-	unsigned type, const char *desc, unsigned descsz)
230
-{
231
-    Elf_Nhdr nhdr;
232
-    unsigned ent_size, new_size, pad;
233
-    char *addr;
234
-
235
-    if (!bhdr)
236
-	return NULL;
237
-
238
-    nhdr.n_namesz = name? strlen(name)+1 : 0;
239
-    nhdr.n_descsz = descsz;
240
-    nhdr.n_type = type;
241
-    ent_size = sizeof(nhdr) + padded(nhdr.n_namesz) + padded(nhdr.n_descsz);
242
-    if (bhdr->b_size + ent_size > 0xffff) {
243
-	printf("Boot notes too big\n");
244
-	forget(bhdr);
245
-	return NULL;
246
-    }
247
-    if (bhdr->b_size + ent_size > bhdr->b_checksum) {
248
-	do {
249
-	    new_size = bhdr->b_checksum * 2;
250
-	} while (new_size < bhdr->b_size + ent_size);
251
-	if (new_size > 0xffff)
252
-	    new_size = 0xffff;
253
-	debug("expanding boot note size to %u\n", new_size);
254
-	bhdr = realloc(bhdr, new_size);
255
-	bhdr->b_checksum = new_size;
256
-    }
257
-
258
-    addr = (char *) bhdr;
259
-    addr += bhdr->b_size;
260
-    memcpy(addr, &nhdr, sizeof(nhdr));
261
-    addr += sizeof(nhdr);
262
-
263
-    memcpy(addr, name, nhdr.n_namesz);
264
-    addr += nhdr.n_namesz;
265
-    pad = padded(nhdr.n_namesz) - nhdr.n_namesz;
266
-    memset(addr, 0, pad);
267
-    addr += pad;
268
-
269
-    memcpy(addr, desc, nhdr.n_descsz);
270
-    addr += nhdr.n_descsz;
271
-    pad = padded(nhdr.n_descsz) - nhdr.n_descsz;
272
-    memset(addr, 0, pad);
273
-    addr += pad;
274
-
275
-    bhdr->b_size += ent_size;
276
-    bhdr->b_records++;
277
-    return bhdr;
278
-}
279
-
280
-static inline Elf_Bhdr *add_note_string(Elf_Bhdr *bhdr, const char *name,
281
-	unsigned type, const char *desc)
282
-{
283
-    return add_boot_note(bhdr, name, type, desc, strlen(desc) + 1);
284
-}
285
-
286
-static Elf_Bhdr *build_boot_notes(struct sys_info *info, const char *cmdline)
287
-{
288
-    Elf_Bhdr *bhdr;
289
-
290
-    bhdr = allot(256);
291
-    bhdr->b_signature = ELF_BHDR_MAGIC;
292
-    bhdr->b_size = sizeof *bhdr;
293
-    bhdr->b_checksum = 256; /* XXX cache the current buffer size here */
294
-    bhdr->b_records = 0;
295
-
296
-    if (info->firmware)
297
-	bhdr = add_note_string(bhdr, NULL, EBN_FIRMWARE_TYPE, info->firmware);
298
-    bhdr = add_note_string(bhdr, NULL, EBN_BOOTLOADER_NAME, program_name);
299
-    bhdr = add_note_string(bhdr, NULL, EBN_BOOTLOADER_VERSION, program_version);
300
-    if (cmdline)
301
-	bhdr = add_note_string(bhdr, NULL, EBN_COMMAND_LINE, cmdline);
302
-    if (!bhdr)
303
-	return bhdr;
304
-    bhdr->b_checksum = 0;
305
-    bhdr->b_checksum = ipchksum(bhdr, bhdr->b_size);
306
-    return bhdr;
307
-}
308
-
309
-int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
310
-{
311
-    Elf_ehdr ehdr;
312
-    Elf_phdr *phdr = NULL;
313
-    unsigned long phdr_size;
314
-    unsigned long checksum_offset;
315
-    unsigned short checksum;
316
-    Elf_Bhdr *boot_notes = NULL;
317
-    int retval = -1;
318
-    int image_retval;
319
-
320
-    image_name = image_version = 0;
321
-
322
-    if (!file_open(filename))
323
-	goto out;
324
-
325
-    if (file_read(&ehdr, sizeof ehdr) != sizeof ehdr) {
326
-	debug("Can't read ELF header\n");
327
-	retval = LOADER_NOT_SUPPORT;
328
-	goto out;
329
-    }
330
-
331
-    if (ehdr.e_ident[EI_MAG0] != ELFMAG0
332
-	    || ehdr.e_ident[EI_MAG1] != ELFMAG1
333
-	    || ehdr.e_ident[EI_MAG2] != ELFMAG2
334
-	    || ehdr.e_ident[EI_MAG3] != ELFMAG3
335
-	    || ehdr.e_ident[EI_CLASS] != ARCH_ELF_CLASS
336
-	    || ehdr.e_ident[EI_DATA] != ARCH_ELF_DATA
337
-	    || ehdr.e_ident[EI_VERSION] != EV_CURRENT
338
-	    || ehdr.e_type != ET_EXEC
339
-	    || !ARCH_ELF_MACHINE_OK(ehdr.e_machine)
340
-	    || ehdr.e_version != EV_CURRENT
341
-	    || ehdr.e_phentsize != sizeof(Elf_phdr)) {
342
-	debug("Not a bootable ELF image\n");
343
-	retval = LOADER_NOT_SUPPORT;
344
-	goto out;
345
-    }
346
-
347
-    phdr_size = ehdr.e_phnum * sizeof *phdr;
348
-    phdr = allot(phdr_size);//hack LYH otherwise some one clear the last entry 
349
-    file_seek(ehdr.e_phoff);
350
-    if (file_read(phdr, phdr_size) != phdr_size) {
351
-	printf("Can't read program header\n");
352
-	goto out;
353
-    }
354
-
355
-    if (!check_mem_ranges(info, phdr, ehdr.e_phnum))
356
-	goto out;
357
-
358
-    checksum_offset = process_image_notes(phdr, ehdr.e_phnum, &checksum);
359
-
360
-    printf("Loading %s", image_name ? image_name : "image");
361
-    if (image_version)
362
-	printf(" version %s", image_version);
363
-    printf("...\n");
364
-
365
-    if (!load_segments(phdr, ehdr.e_phnum, checksum_offset))
366
-	goto out;
367
-
368
-    if (checksum_offset) {
369
-	if (!verify_image(&ehdr, phdr, ehdr.e_phnum, checksum))
370
-	    goto out;
371
-    }
372
-
373
-    boot_notes = build_boot_notes(info, cmdline);
374
-
375
-    debug("current time: %x\n", currticks());
376
-
377
-    debug("entry point is %#x\n", ehdr.e_entry);
378
-    printf("Jumping to entry point...\n");
379
-
380
-    image_retval = start_elf(ehdr.e_entry, virt_to_phys(boot_notes));
381
-#if 0
382
-    console_init();
383
-#endif
384
-
385
-    printf("Image returned with return value %#x\n", image_retval);
386
-    retval = 0;
387
-
388
-out:
389
-    if (phdr)
390
-	forget(phdr);
391
-    if (boot_notes)
392
-	forget(boot_notes);
393
-    if (image_name)
394
-	forget(image_name);
395
-    if (image_version)
396
-	forget(image_version);
397
-    return retval;
398
-}

+ 0
- 153
src/filo/main/elfnote.c Целия файл

@@ -1,153 +0,0 @@
1
-/* Support for ELF Boot Proposal as a boot image */
2
-
3
-#include <etherboot.h>
4
-#include <elf_boot.h>
5
-#include <sys_info.h>
6
-#include <lib.h>
7
-
8
-#include "version.h"
9
-#define DEBUG_THIS DEBUG_ELFNOTE
10
-#include <debug.h>
11
-
12
-/* ELF image notes provide information to the loader who boots us */
13
-
14
-/* This compiles and generates correct PT_NOTE segment for me.
15
- * If it doesn't, use assembly version below. */
16
-
17
-struct elf_image_note {
18
-    Elf_Nhdr hdr0;
19
-    char name0[sizeof(ELF_NOTE_BOOT)];
20
-    char prog_name[sizeof(PROGRAM_NAME)];
21
-
22
-    Elf_Nhdr hdr1;
23
-    char name1[sizeof(ELF_NOTE_BOOT)];
24
-    char version[sizeof(PROGRAM_VERSION)];
25
-
26
-    Elf_Nhdr hdr2;
27
-    char name2[sizeof(ELF_NOTE_BOOT)];
28
-    unsigned short checksum;
29
-};
30
-
31
-const struct elf_image_note elf_image_notes
32
-	__attribute__ ((section (".note.ELFBoot"))) =
33
-{
34
-    .hdr0 = {
35
-	.n_namesz = sizeof(ELF_NOTE_BOOT),
36
-	.n_descsz = sizeof(PROGRAM_NAME),
37
-	.n_type = EIN_PROGRAM_NAME,
38
-    },
39
-    .name0 = ELF_NOTE_BOOT,
40
-    .prog_name = PROGRAM_NAME,
41
-
42
-    .hdr1 = {
43
-	.n_namesz = sizeof(ELF_NOTE_BOOT),
44
-	.n_descsz = sizeof(PROGRAM_VERSION),
45
-	.n_type = EIN_PROGRAM_VERSION,
46
-    },
47
-    .name1 = ELF_NOTE_BOOT,
48
-    .version = PROGRAM_VERSION,
49
-
50
-    .hdr2 = {
51
-	.n_namesz = sizeof(ELF_NOTE_BOOT),
52
-	.n_descsz = sizeof(unsigned short),
53
-	.n_type = EIN_PROGRAM_CHECKSUM,
54
-    },
55
-    .name2 = ELF_NOTE_BOOT,
56
-    .checksum = 0, /* to be computed by external tool */
57
-};
58
-
59
-/* This is refered by other files */
60
-const char *program_name = elf_image_notes.prog_name;
61
-const char *program_version = elf_image_notes.version;
62
-
63
-#if 0
64
-
65
-	/* This tells the linker to make a PT_NOTE segment.
66
-	 * If the section is named just ".note", it will be
67
-	 * mixed up with useless .version notes generated by GCC.
68
-	 */
69
-	.section ".note.ELFBoot", "a"
70
-
71
-	.align 4
72
-	.int 2f - 1f
73
-	.int 4f - 3f
74
-	.int EIN_PROGRAM_NAME
75
-1:	.asciz "ELFBoot"
76
-2:	.align 4
77
-3:	.asciz PROGRAM_NAME
78
-4:
79
-
80
-	.align 4
81
-	.int 2f - 1f
82
-	.int 4f - 3f
83
-	.int EIN_PROGRAM_VERSION
84
-1:	.asciz "ELFBoot"
85
-2:	.align 4
86
-3:	.asciz PROGRAM_VERSION
87
-4:
88
-
89
-	.align 4
90
-	.int 2f - 1f
91
-	.int 4f - 3f
92
-	.int EIN_PROGRAM_CHECKSUM
93
-1:	.asciz "ELFBoot"
94
-2:	.align 4
95
-3:	.short 0
96
-4:
97
-#endif
98
-
99
-/* Collect information from the ELF bootloader
100
- * Note that we have to copy them to our own memory,
101
- * otherwise they might be overwritten afterward. */
102
-void collect_elfboot_info(struct sys_info *info)
103
-{
104
-    Elf_Bhdr *hdr = 0;
105
-    char *addr, *end;
106
-    Elf_Nhdr *nhdr;
107
-    char *name, *desc;
108
-
109
-    if (info->boot_type == ELF_BHDR_MAGIC)
110
-	hdr = phys_to_virt(info->boot_data);
111
-    else
112
-	hdr = phys_to_virt(info->boot_arg);
113
-
114
-    if (hdr->b_signature != ELF_BHDR_MAGIC)
115
-	return;
116
-
117
-    if (ipchksum(hdr, hdr->b_size) != 0) {
118
-	printf("Broken ELF boot notes\n");
119
-	return;
120
-    }
121
-
122
-    addr = (char *) (hdr + 1);
123
-    end = addr + hdr->b_size;
124
-    while (addr <  end) {
125
-	nhdr = (Elf_Nhdr *) addr;
126
-	addr += sizeof(Elf_Nhdr);
127
-	name = addr;
128
-	addr += (nhdr->n_namesz + 3) & ~3;
129
-	desc = addr;
130
-	addr += (nhdr->n_descsz + 3) & ~3;
131
-
132
-	if (nhdr->n_namesz == 0) {
133
-	    /* Standard notes */
134
-	    switch (nhdr->n_type) {
135
-	    case EBN_FIRMWARE_TYPE:
136
-		info->firmware = strdup(desc);
137
-		break;
138
-	    case EBN_BOOTLOADER_NAME:
139
-		debug("Bootloader: %s\n", desc);
140
-		break;
141
-	    case EBN_BOOTLOADER_VERSION:
142
-		debug("Version: %s\n", desc);
143
-		break;
144
-	    case EBN_COMMAND_LINE:
145
-		info->command_line = strdup(desc);
146
-		break;
147
-	    case EBN_LOADED_IMAGE:
148
-		debug("Image name: %s\n", desc);
149
-		break;
150
-	    }
151
-	}
152
-    }
153
-}

+ 0
- 129
src/filo/main/filo_x.c Целия файл

@@ -1,129 +0,0 @@
1
-#include <etherboot.h>
2
-
3
-#include <fs.h>
4
-#include <lib.h>
5
-#include <sys_info.h>
6
-
7
-#define ENTER '\r'
8
-#define ESCAPE '\x1b'
9
-
10
-#ifndef AUTOBOOT_FILE
11
-#define autoboot() ((void) 0) /* nop */
12
-#endif
13
-
14
-#ifndef AUTOBOOT_DELAY
15
-#define autoboot_delay() 0 /* success */
16
-#endif
17
-
18
-struct sys_info sys_info;
19
-
20
-static void init(void)
21
-{
22
-    collect_sys_info(&sys_info);
23
-
24
-    printf("%s version %s\n", program_name, program_version);
25
-
26
-}
27
-
28
-static void boot(const char *line)
29
-{
30
-    char file[256], *param;
31
-
32
-    /* Split filename and parameter */
33
-    memcpy(file, line,256);
34
-//    file = strdup(line);
35
-    param = strchr(file, ' ');
36
-    if (param) {
37
-	*param = '\0';
38
-	param++;
39
-    }
40
-    if (elf_load(&sys_info, file, param) == LOADER_NOT_SUPPORT){
41
-	if (linux_load(&sys_info, file, param) == LOADER_NOT_SUPPORT)
42
-	    printf("Unsupported image format\n");
43
-    }
44
-//    free(file);
45
-}
46
-
47
-#ifdef AUTOBOOT_FILE
48
-#if AUTOBOOT_DELAY
49
-
50
-static inline int autoboot_delay(void)
51
-{
52
-    unsigned int timeout;
53
-    int sec, tmp;
54
-    int key;
55
-    
56
-    key = 0;
57
-
58
-    printf("Press <Enter> for default boot, or <Esc> for boot prompt... ");
59
-    for (sec = AUTOBOOT_DELAY; sec>0 && key==0; sec--) {
60
-	printf("%d", sec);
61
-	timeout = currticks() + TICKS_PER_SEC;
62
-	while (currticks() < timeout) {
63
-	    if (iskey()) {
64
-		key = getchar();
65
-		if (key==ENTER || key==ESCAPE)
66
-		    break;
67
-	    }
68
-	}
69
-	for (tmp = sec; tmp; tmp /= 10)
70
-	    printf("\b \b");
71
-    }
72
-    if (key == 0) {
73
-	printf("timed out\n");
74
-	return 0; /* success */
75
-    } else {
76
-	putchar('\n');
77
-	if (key == ESCAPE)
78
-	    return -1; /* canceled */
79
-	else
80
-	    return 0; /* default accepted */
81
-    }
82
-}
83
-#endif /* AUTOBOOT_DELAY */
84
-
85
-static void autoboot(void)
86
-{
87
-    /* If Escape key is pressed already, skip autoboot */
88
-    if (iskey() && getchar()==ESCAPE)
89
-	return;
90
-
91
-    if (autoboot_delay()==0) {
92
-	printf("boot: %s\n", AUTOBOOT_FILE);
93
-	boot(AUTOBOOT_FILE);
94
-    }
95
-}
96
-#endif /* AUTOBOOT_FILE */
97
-
98
-/* The main routine */
99
-int filo(void)
100
-{
101
-    char line[256];
102
-
103
-    /* Initialize */
104
-
105
-    init();
106
-
107
-    /* Try default image */
108
-    autoboot();
109
-
110
-    /* The above didn't work, ask user */
111
-    while (iskey())
112
-	getchar();
113
-#ifdef AUTOBOOT_FILE
114
-    strncpy(line, AUTOBOOT_FILE, sizeof(line)-1);
115
-    line[sizeof(line)-1] = '\0';
116
-#else
117
-    line[0] = '\0';
118
-#endif
119
-    for (;;) {
120
-	printf("boot: ");
121
-	getline(line, sizeof line);
122
-// BY LYH add "quit" to exit filo
123
-	if (strcmp(line,"quit")==0) break;
124
-//	if (memcmp(line,"quit",4)==0) break;
125
-	if (line[0])
126
-	    boot(line);
127
-    }
128
-   return 0;
129
-}

+ 0
- 56
src/filo/main/lib.c Целия файл

@@ -1,56 +0,0 @@
1
-
2
-#include <etherboot.h>
3
-#include <lib.h>
4
-
5
-char *strdup(const char *s)
6
-{
7
-    size_t sz = strlen(s) + 1;
8
-    char *d = allot(sz);
9
-    memcpy(d, s, sz);
10
-    return d;
11
-}
12
-
13
-int isspace(int c)
14
-{
15
-    switch (c) {
16
-    case ' ': case '\f': case '\n':
17
-    case '\r': case '\t': case '\v':
18
-        return 1;
19
-    default:
20
-        return 0;
21
-    }
22
-}
23
-
24
-unsigned int get_le32(const unsigned char *p)
25
-{
26
-    return ((unsigned int) p[0] << 0)
27
-	| ((unsigned int) p[1] << 8)
28
-	| ((unsigned int) p[2] << 16)
29
-	| ((unsigned int) p[3] << 24);
30
-}
31
-
32
-unsigned int get_le16(const unsigned char *p)
33
-{
34
-    return ((unsigned int) p[0] << 0)
35
-	| ((unsigned int) p[1] << 8);
36
-}
37
-#if (DEBUG_ALL || DEBUG_ELFBOOT || DEBUG_ELFNOTE || DEBUG_LINUXBIOS || \
38
-	DEBUG_MALLOC || DEBUG_MULTIBOOT || DEBUG_SEGMENT || DEBUG_SYS_INFO ||\
39
-	DEBUG_TIMER || DEBUG_BLOCKDEV || DEBUG_PCI || DEBUG_LINUXLOAD ||\
40
-	DEBUG_IDE || DEBUG_ELTORITO)
41
-
42
-// It is needed by debug for filo
43
-void hexdump(const void *p, unsigned int len)
44
-{
45
-	int i;
46
-	const unsigned char *q = p;
47
-
48
-	for (i = 0; i < len; i++) {
49
-	    if (i%16==0)
50
-		printf("%04x: ", i);
51
-	    printf("%02x%c", q[i], i%16==15 ? '\n' : i%8==7 ? '-' : ' ');
52
-	}
53
-	if (i%16 != 0)
54
-	    putchar('\n');
55
-}
56
-#endif

+ 0
- 124
src/filo/main/linuxbios_x.c Целия файл

@@ -1,124 +0,0 @@
1
-/* Adapted from Etherboot 5.1.8 */
2
-#include <sys_info.h>
3
-#define DEBUG_THIS DEBUG_LINUXBIOS
4
-#include <debug.h>
5
-
6
-#if 0
7
-
8
-#define for_each_lbrec(head, rec) \
9
-	for(rec = (struct lb_record *)(((char *)head) + sizeof(*head)); \
10
-		(((char *)rec) < (((char *)head) + sizeof(*head) + head->table_bytes))  && \
11
-		(rec->size >= 1) && \
12
-		((((char *)rec) + rec->size) <= (((char *)head) + sizeof(*head) + head->table_bytes)); \
13
-		rec = (struct lb_record *)(((char *)rec) + rec->size)) 
14
-
15
-static void convert_memmap(struct lb_memory *lbmem, struct sys_info *info)
16
-{
17
-    int lbcount;
18
-    int i;
19
-
20
-    lbcount = lbmem->size / sizeof(struct lb_memory_range);
21
-    info->memrange = malloc(lbcount * sizeof(struct memrange));
22
-    info->n_memranges = 0;
23
-    for (i = 0; i < lbcount; i++) {
24
-	debug("%#016Lx %#016Lx %d\n",
25
-		lbmem->map[i].start, lbmem->map[i].size,
26
-		(int) lbmem->map[i].type);
27
-	if (lbmem->map[i].type != LB_MEM_RAM)
28
-	    continue;
29
-	info->memrange[info->n_memranges].base = lbmem->map[i].start;
30
-	info->memrange[info->n_memranges].size = lbmem->map[i].size;
31
-	info->n_memranges++;
32
-    }
33
-}
34
-static int read_lbtable(struct lb_header *head, struct sys_info *info)
35
-{
36
-	int retval = 0;
37
-
38
-	/* Read linuxbios tables... */
39
-	struct lb_record *rec;
40
-
41
-	for_each_lbrec(head, rec) {
42
-		switch(rec->tag) {
43
-		case LB_TAG_MEMORY:
44
-			convert_memmap((struct lb_memory *) rec, info);
45
-			retval = 1;
46
-			break;
47
-		};
48
-	}
49
-	return retval;
50
-}
51
-#endif
52
-#if 0
53
-//Use func in Etherboot
54
-static unsigned long count_lb_records(void *start, unsigned long length)
55
-{
56
-	struct lb_record *rec;
57
-	void *end;
58
-	unsigned long count;
59
-	count = 0;
60
-	end = ((char *)start) + length;
61
-	for(rec = start; ((void *)rec < end) &&
62
-		((signed long)rec->size <= (end - (void *)rec)); 
63
-		rec = (void *)(((char *)rec) + rec->size)) {
64
-		count++;
65
-	}
66
-	return count;
67
-}
68
-static int find_lb_table(void *start, void *end, struct lb_header **result)
69
-{
70
-	unsigned char *ptr;
71
-	/* For now be stupid.... */
72
-	for(ptr = start; (void *)ptr < end; ptr += 16) {
73
-		struct lb_header *head = (struct lb_header *)ptr;
74
-		if (	(head->signature[0] != 'L') || 
75
-			(head->signature[1] != 'B') ||
76
-			(head->signature[2] != 'I') ||
77
-			(head->signature[3] != 'O')) {
78
-			continue;
79
-		}
80
-		if (head->header_bytes != sizeof(*head))
81
-			continue;
82
-		debug("Found canidate at: %p\n", head);
83
-		if (ipchksum((uint16_t *)head, sizeof(*head)) != 0) 
84
-			continue;
85
-		debug("header checksum o.k.\n");
86
-		if (ipchksum((uint16_t *)(ptr + sizeof(*head)), head->table_bytes) !=
87
-			head->table_checksum) {
88
-			continue;
89
-		}
90
-		debug("table checksum o.k.\n");
91
-		if (count_lb_records(ptr + sizeof(*head), head->table_bytes) !=
92
-			head->table_entries) {
93
-			continue;
94
-		}
95
-		debug("record count o.k.\n");
96
-		*result = head;
97
-		return 1;
98
-	};
99
-	return 0;
100
-}
101
-#endif
102
-void collect_linuxbios_info(struct sys_info *info)
103
-{
104
-#if 0
105
-	struct lb_header *lb_table;
106
-	int found;
107
-	debug("Searching for LinuxBIOS tables...\n");
108
-	found = 0;
109
-	if (!found) {
110
-		found = find_lb_table(phys_to_virt(0x00000), phys_to_virt(0x01000), &lb_table);
111
-	}
112
-	if (!found) {
113
-		found = find_lb_table(phys_to_virt(0xf0000), phys_to_virt(0x100000), &lb_table);
114
-	}
115
-	if (!found)
116
-		return;
117
-
118
-	debug("Found LinuxBIOS table at: %p\n", lb_table);
119
-#endif 
120
-	info->firmware = "LinuxBIOS";
121
-#if 0
122
-	read_lbtable(lb_table, info);
123
-#endif
124
-}

+ 0
- 45
src/filo/main/malloc_x.c Целия файл

@@ -1,45 +0,0 @@
1
-#include <etherboot.h>
2
-
3
-#include <lib.h>
4
-
5
-void *calloc(size_t nmemb, size_t size)
6
-{
7
-    size_t alloc_size = nmemb * size;
8
-    void *mem;
9
-
10
-    if (alloc_size < nmemb || alloc_size < size) {
11
-        printf("calloc overflow: %u, %u\n", nmemb, size);
12
-        return 0;
13
-    }
14
-
15
-    mem = allot(alloc_size);
16
-    memset(mem, 0, alloc_size);
17
-
18
-    return mem;
19
-}
20
-
21
-void *realloc(void *mem, size_t size)
22
-{
23
-    size_t copy_size;
24
-    void *new_mem;
25
-        size_t *mark, addr;
26
-
27
-    if (mem == 0)
28
-        return allot(size);
29
-    if (size == 0) {
30
-        forget(mem);
31
-        return 0;
32
-    }
33
-
34
-        addr = virt_to_phys(mem);
35
-        mark = phys_to_virt(addr - sizeof(size_t));
36
-        copy_size = *mark;
37
-
38
-    if (size < copy_size)
39
-        copy_size = size;
40
-    /* XXX should optimze this */
41
-    new_mem = allot(size);
42
-    memcpy(new_mem, mem, copy_size);
43
-    forget(mem);
44
-    return new_mem;
45
-}

+ 0
- 124
src/filo/main/pci_x.c Целия файл

@@ -1,124 +0,0 @@
1
-#ifdef CONFIG_PCI
2
-                
3
-/*                      
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2, or (at
7
- * your option) any later version.
8
- */             
9
-                
10
-#include <etherboot.h>  
11
-#include <pci.h>
12
-#include <lib.h>
13
-
14
-#define DEBUG_THIS DEBUG_PCI
15
-
16
-#include <debug.h>
17
-
18
-struct pci_device *dev_list;
19
-int n_devs;
20
-
21
-static void pci_scan_bus(void)
22
-{
23
-
24
-        unsigned int first_bus, first_devfn;
25
-        unsigned int devfn, bus, buses;
26
-        
27
-	uint32_t class; 
28
-        uint16_t vendor, dev_id;
29
-	uint8_t hdr_type;
30
-
31
-
32
-        first_bus    = 0;
33
-        first_devfn  = 0;
34
-
35
-        buses=256;
36
-        for (bus = first_bus; bus < buses; ++bus) {
37
-          for (devfn = first_devfn; devfn < 0xff; ++devfn) {
38
-
39
-#if 1
40
-            if (PCI_FUNC(devfn) == 0)
41
-                      pcibios_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type);
42
-            else if (!(hdr_type & 0x80))    /* not a multi-function device */
43
-                      continue;
44
-#endif
45
-
46
-	    pcibios_read_config_word(bus,devfn, PCI_VENDOR_ID, &vendor);
47
-	    if (vendor==0xffff || vendor==0)
48
-		continue;
49
-	    
50
-	    if (dev_list) {
51
-		dev_list[n_devs].bus = bus;
52
-		dev_list[n_devs].devfn = devfn;
53
-		dev_list[n_devs].vendor = vendor;
54
-
55
-		pcibios_read_config_word(bus,devfn, PCI_DEVICE_ID, &dev_id);
56
-		dev_list[n_devs].dev_id = dev_id;
57
-
58
-                pcibios_read_config_dword(bus,devfn, PCI_CLASS_REVISION, &class);
59
-                dev_list[n_devs].class = class;
60
-
61
-	    }
62
-	    n_devs++;
63
-          }
64
-          first_devfn = 0;
65
-        }
66
-        first_bus = 0;
67
-
68
-}
69
-#define DEBUG 0
70
-
71
-void pci_init(void)
72
-{
73
-    /* Count devices */
74
-    dev_list = 0;
75
-    n_devs = 0;
76
-    debug("Scanning PCI: ");
77
-    pci_scan_bus();
78
-    debug("found %d devices\n", n_devs);
79
-
80
-    /* Make the list */
81
-    dev_list = allot(n_devs * sizeof(struct pci_device));
82
-    n_devs = 0;
83
-    pci_scan_bus();
84
-#if DEBUG
85
-    {
86
-	int i;
87
-	for (i = 0; i < n_devs; i++) {
88
-	    printf("%02x:%02x.%x %04x:%04x %04x %02x\n", 
89
-		    dev_list[i].bus,
90
-		    PCI_SLOT(dev_list[i].devfn),
91
-		    PCI_FUNC(dev_list[i].devfn),
92
-		    dev_list[i].vendor,
93
-		    dev_list[i].dev_id,((dev_list[i].class)>>16),
94
-		    ((dev_list[i].class)>>8 & 0xff));
95
-	}
96
-    }
97
-#endif
98
-}
99
-
100
-struct pci_device *pci_find_device_2(int vendor, int device, int devclass, int devclass2, int prog_if, int index)
101
-{
102
-    int i;
103
-
104
-    for (i=0; i<n_devs; i++) {
105
-	if (vendor < 0 || vendor==dev_list[i].vendor)
106
-	    if (device < 0 || device==dev_list[i].dev_id)
107
-		if (devclass < 0 || devclass==((dev_list[i].class)>>16) || devclass2==((dev_list[i].class)>>16))
108
-		    if (prog_if < 0 || prog_if==((dev_list[i].class)>>8 & 0xff)) {
109
-			if (index == 0)
110
-			    return &dev_list[i];
111
-			index--;
112
-		    }
113
-    }
114
-	
115
-    return NULL;
116
-}
117
-
118
-
119
-struct pci_device *pci_find_device(int vendor, int device, int devclass, int prog_if, int index)
120
-{
121
-	return pci_find_device_2(vendor, device, devclass, devclass, prog_if, index);
122
-}
123
-
124
-#endif

+ 0
- 400
src/filo/main/printf_x.c Целия файл

@@ -1,400 +0,0 @@
1
-/*  Adapted from LinuxBIOS */
2
-
3
-/*
4
- *
5
- *  linux/lib/vsprintf.c
6
- *
7
- *  Copyright (C) 1991, 1992  Linus Torvalds
8
- *
9
- */
10
-
11
-/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
12
-/*
13
- * Wirzenius wrote this portably, Torvalds fucked it up :-)
14
- */
15
-
16
-#include "etherboot.h"
17
-#include <stdarg.h>
18
-#include <lib.h>
19
-
20
-/* haha, don't need ctype.c */
21
-#define isdigit(c)	((c) >= '0' && (c) <= '9')
22
-#define is_digit isdigit
23
-#define isxdigit(c)	(((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
24
-#define islower(c)	((c) >= 'a' && (c) <= 'z')
25
-#define toupper(c) __toupper(c)
26
-
27
-static inline unsigned char __toupper(unsigned char c)
28
-{
29
-        if (islower(c))
30
-                c -= 'a'-'A';
31
-        return c;
32
-}
33
-
34
-
35
-unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base)
36
-{
37
-	unsigned long long result = 0,value;
38
-
39
-	if (!base) {
40
-		base = 10;
41
-		if (*cp == '0') {
42
-			base = 8;
43
-			cp++;
44
-			if ((*cp == 'x') && isxdigit(cp[1])) {
45
-				cp++;
46
-				base = 16;
47
-			}
48
-		}
49
-	}
50
-	while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
51
-	    ? toupper(*cp) : *cp)-'A'+10) < base) {
52
-		result = result*base + value;
53
-		cp++;
54
-	}
55
-	if (endp)
56
-		*endp = (char *)cp;
57
-	return result;
58
-}
59
-
60
-long long simple_strtoll(const char *cp,char **endp,unsigned int base)
61
-{
62
-	if(*cp=='-')
63
-		return -simple_strtoull(cp+1,endp,base);
64
-	return simple_strtoull(cp,endp,base);
65
-}
66
-
67
-unsigned long long strtoull_with_suffix(const char *cp,char **endp,unsigned int base)
68
-{
69
-	unsigned long long result;
70
-
71
-	if (!endp) {
72
-	    printf("%s must be called with endp\n", __FUNCTION__);
73
-	    return 0;
74
-	}
75
-	result = simple_strtoull(cp, endp, base);
76
-	switch (toupper(**endp)) {
77
-	case 'K':
78
-		result <<= 10;
79
-		++*endp;
80
-		break;
81
-	case 'M':
82
-		result <<= 20;
83
-		++*endp;
84
-		break;
85
-	case 'G':
86
-		result <<= 30;
87
-		++*endp;
88
-		break;
89
-	}
90
-	return result;
91
-}
92
-
93
-#if 0
94
-// it can be used to substitute the vsprintf.c in etherboot. And it has better 
95
-// support in numeric output suppot 
96
-//When you want to debug filo, you need to enable it and disable vsprintf.c
97
-// to get output from filo
98
-// BY LYH
99
-
100
-static int skip_atoi(const char **s)
101
-{
102
-	int i=0;
103
-
104
-	while (is_digit(**s))
105
-		i = i*10 + *((*s)++) - '0';
106
-	return i;
107
-}
108
-
109
-#define ZEROPAD	1		/* pad with zero */
110
-#define SIGN	2		/* unsigned/signed long */
111
-#define PLUS	4		/* show plus */
112
-#define SPACE	8		/* space if plus */
113
-#define LEFT	16		/* left justified */
114
-#define SPECIAL	32		/* 0x */
115
-#define LARGE	64		/* use 'ABCDEF' instead of 'abcdef' */
116
-
117
-#define do_div(n,base) ({ \
118
-int __res; \
119
-__res = ((unsigned long) n) % (unsigned) base; \
120
-n = ((unsigned long) n) / (unsigned) base; \
121
-__res; })
122
-
123
-static int number(int (*tx_byte)(int byte), long num, int base, int size, int precision
124
-	,int type)
125
-{
126
-	char c,sign,tmp[66];
127
-	const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
128
-	int i;
129
-	int count = 0;
130
-
131
-	if (type & LARGE)
132
-		digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
133
-	if (type & LEFT)
134
-		type &= ~ZEROPAD;
135
-	if (base < 2 || base > 36)
136
-		return 0;
137
-	c = (type & ZEROPAD) ? '0' : ' ';
138
-	sign = 0;
139
-	if (type & SIGN) {
140
-		if (num < 0) {
141
-			sign = '-';
142
-			num = -num;
143
-			size--;
144
-		} else if (type & PLUS) {
145
-			sign = '+';
146
-			size--;
147
-		} else if (type & SPACE) {
148
-			sign = ' ';
149
-			size--;
150
-		}
151
-	}
152
-	if (type & SPECIAL) {
153
-		if (base == 16)
154
-			size -= 2;
155
-		else if (base == 8)
156
-			size--;
157
-	}
158
-	i = 0;
159
-	if (num == 0)
160
-		tmp[i++]='0';
161
-	else while (num != 0)
162
-		tmp[i++] = digits[do_div(num,base)];
163
-	if (i > precision)
164
-		precision = i;
165
-	size -= precision;
166
-	if (!(type&(ZEROPAD+LEFT)))
167
-		while(size-->0)
168
-			tx_byte(' '), count++;
169
-	if (sign)
170
-		tx_byte(sign), count++;
171
-	if (type & SPECIAL) {
172
-		if (base==8)
173
-			tx_byte('0'), count++;
174
-		else if (base==16) {
175
-			tx_byte('0'), count++;
176
-			tx_byte(digits[33]), count++;
177
-		}
178
-	}
179
-	if (!(type & LEFT))
180
-		while (size-- > 0)
181
-			tx_byte(c), count++;
182
-	while (i < precision--)
183
-		tx_byte('0'), count++;
184
-	while (i-- > 0)
185
-		tx_byte(tmp[i]), count++;
186
-	while (size-- > 0)
187
-		tx_byte(' '), count++;
188
-	return count;
189
-}
190
-
191
-
192
-int vtxprintf(int (*tx_byte)(int byte), const char *fmt, va_list args)
193
-{
194
-	int len;
195
-	unsigned long num;
196
-	int i, base;
197
-	const char *s;
198
-
199
-	int flags;		/* flags to number() */
200
-
201
-	int field_width;	/* width of output field */
202
-	int precision;		/* min. # of digits for integers; max
203
-				   number of chars for from string */
204
-	int qualifier;		/* 'h', 'l', or 'L' for integer fields */
205
-	
206
-	int count;
207
-
208
-	for (count=0; *fmt ; ++fmt) {
209
-		if (*fmt != '%') {
210
-			tx_byte(*fmt), count++;
211
-			continue;
212
-		}
213
-			
214
-		/* process flags */
215
-		flags = 0;
216
-		repeat:
217
-			++fmt;		/* this also skips first '%' */
218
-			switch (*fmt) {
219
-				case '-': flags |= LEFT; goto repeat;
220
-				case '+': flags |= PLUS; goto repeat;
221
-				case ' ': flags |= SPACE; goto repeat;
222
-				case '#': flags |= SPECIAL; goto repeat;
223
-				case '0': flags |= ZEROPAD; goto repeat;
224
-				}
225
-		
226
-		/* get field width */
227
-		field_width = -1;
228
-		if (is_digit(*fmt))
229
-			field_width = skip_atoi(&fmt);
230
-		else if (*fmt == '*') {
231
-			++fmt;
232
-			/* it's the next argument */
233
-			field_width = va_arg(args, int);
234
-			if (field_width < 0) {
235
-				field_width = -field_width;
236
-				flags |= LEFT;
237
-			}
238
-		}
239
-
240
-		/* get the precision */
241
-		precision = -1;
242
-		if (*fmt == '.') {
243
-			++fmt;	
244
-			if (is_digit(*fmt))
245
-				precision = skip_atoi(&fmt);
246
-			else if (*fmt == '*') {
247
-				++fmt;
248
-				/* it's the next argument */
249
-				precision = va_arg(args, int);
250
-			}
251
-			if (precision < 0)
252
-				precision = 0;
253
-		}
254
-
255
-		/* get the conversion qualifier */
256
-		qualifier = -1;
257
-		if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
258
-			qualifier = *fmt;
259
-			++fmt;
260
-		}
261
-
262
-		/* default base */
263
-		base = 10;
264
-
265
-		switch (*fmt) {
266
-		case 'c':
267
-			if (!(flags & LEFT))
268
-				while (--field_width > 0)
269
-					tx_byte(' '), count++;
270
-			tx_byte((unsigned char) va_arg(args, int)), count++;
271
-			while (--field_width > 0)
272
-				tx_byte(' '), count++;
273
-			continue;
274
-
275
-		case 's':
276
-			s = va_arg(args, char *);
277
-			if (!s)
278
-				s = "<NULL>";
279
-
280
-			len = strnlen(s, precision);
281
-
282
-			if (!(flags & LEFT))
283
-				while (len < field_width--)
284
-					tx_byte(' '), count++;
285
-			for (i = 0; i < len; ++i)
286
-				tx_byte(*s++), count++;
287
-			while (len < field_width--)
288
-				tx_byte(' '), count++;
289
-			continue;
290
-
291
-		case 'p':
292
-			if (field_width == -1) {
293
-				field_width = 2*sizeof(void *);
294
-				flags |= ZEROPAD;
295
-			}
296
-			count += number(tx_byte,
297
-				(unsigned long) va_arg(args, void *), 16,
298
-				field_width, precision, flags);
299
-			continue;
300
-
301
-
302
-		case 'n':
303
-			if (qualifier == 'l') {
304
-				long * ip = va_arg(args, long *);
305
-				*ip = count;
306
-			} else {
307
-				int * ip = va_arg(args, int *);
308
-				*ip = count;
309
-			}
310
-			continue;
311
-
312
-		case '%':
313
-			tx_byte('%'), count++;
314
-			continue;
315
-
316
-		/* integer number formats - set up the flags and "break" */
317
-		case 'o':
318
-			base = 8;
319
-			break;
320
-
321
-		case 'X':
322
-			flags |= LARGE;
323
-		case 'x':
324
-			base = 16;
325
-			break;
326
-
327
-		case 'd':
328
-		case 'i':
329
-			flags |= SIGN;
330
-		case 'u':
331
-			break;
332
-
333
-		default:
334
-			tx_byte('%'), count++;
335
-			if (*fmt)
336
-				tx_byte(*fmt), count++;
337
-			else
338
-				--fmt;
339
-			continue;
340
-		}
341
-		if (qualifier == 'L')
342
-			num = va_arg(args, unsigned long long);
343
-		else if (qualifier == 'l')
344
-			num = va_arg(args, unsigned long);
345
-		else if (qualifier == 'h') {
346
-			num = (unsigned short) va_arg(args, int);
347
-			if (flags & SIGN)
348
-				num = (short) num;
349
-		} else if (flags & SIGN)
350
-			num = va_arg(args, int);
351
-		else
352
-			num = va_arg(args, unsigned int);
353
-		count += number(tx_byte, num, base, field_width, precision, flags);
354
-	}
355
-	return count;
356
-}
357
-
358
-/* FIXME this global makes vsprintf non-reentrant
359
- */
360
-static char *str_buf;
361
-static int str_tx_byte(int byte)
362
-{
363
-	*str_buf = byte;
364
-	str_buf++;
365
-	return byte;
366
-}
367
-
368
-int vsprintf(char * buf, const char *fmt, va_list args)
369
-{
370
-	int i;
371
-	str_buf = buf;
372
-	i = vtxprintf(str_tx_byte, fmt, args);
373
-	/* maeder/Ispiri -- The null termination was missing a deference */
374
-	/*                  and was just zeroing out the pointer instead */
375
-	*str_buf = '\0';
376
-	return i;
377
-}
378
-
379
-int sprintf(char * buf, const char *fmt, ...)
380
-{
381
-	va_list args;
382
-	int i;
383
-
384
-	va_start(args, fmt);
385
-	i=vsprintf(buf,fmt,args);
386
-	va_end(args);
387
-	return i;
388
-}
389
-
390
-void printf(const char *fmt, ...)
391
-{
392
-	va_list args;
393
-	int i;
394
-
395
-	va_start(args, fmt);
396
-	i = vtxprintf(putchar, fmt, args);
397
-	va_end(args);
398
-	return i;
399
-}
400
-#endif

+ 0
- 433
src/filo/usb/debug_x.c Целия файл

@@ -1,433 +0,0 @@
1
-#ifdef USB_DISK 
2
-/*******************************************************************************
3
- *
4
- *
5
- *	Copyright 2003 Steven James <pyro@linuxlabs.com> and
6
- *	LinuxLabs http://www.linuxlabs.com
7
- *
8
- *	This program is free software; you can redistribute it and/or modify
9
- *	it under the terms of the GNU General Public License as published by
10
- *	the Free Software Foundation; either version 2 of the License, or
11
- *	(at your option) any later version.
12
- *
13
- *	This program is distributed in the hope that it will be useful,
14
- *	but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- *	GNU General Public License for more details.
17
- *
18
- *	You should have received a copy of the GNU General Public License
19
- *	along with this program; if not, write to the Free Software
20
- *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
- *
22
- ******************************************************************************/
23
-
24
-#include <etherboot.h>
25
-#include <pci.h>
26
-#include <timer.h>
27
-#include <lib.h>
28
-
29
-#define DEBUG_THIS DEBUG_USB
30
-#include <debug.h>
31
-
32
-#define DPRINTF debug
33
-
34
-#include "usb.h"
35
-#include "uhci.h"
36
-#include "debug_x.h"
37
-
38
-//#include <string.h>
39
-
40
-
41
-void dump_link( link_pointer_t *link, char *prefix)
42
-{
43
-	DPRINTF("%saddr: %08x\n", prefix, MEM_ADDR(link->link) );
44
-	DPRINTF("%s raw addr: %04x\n", prefix, (link->link) <<4 );
45
-	DPRINTF("%sterminate: %x\n", prefix, link->terminate);
46
-	DPRINTF("%squeue: %x\n", prefix, link->queue);
47
-	DPRINTF("%sdepth: %x\n", prefix, link->depth);
48
-}
49
-
50
-void dump_frame_list( link_pointer_t *addr, char *prefix)
51
-{
52
-	int i;
53
-
54
-	DPRINTF("%sFRAMELIST:\n",prefix);
55
-
56
-	for(i=0;i<10; i++) {
57
-		dump_link(addr+i, prefix);
58
-		if(addr[i].queue)
59
-			dump_queue_head( MEM_ADDR(addr[i].link), "");
60
-		else
61
-			dump_td( MEM_ADDR(addr[i].link), "");
62
-	}
63
-}
64
-
65
-void dump_hex(uchar *data, int len, char *prefix)
66
-{
67
-	int i=0;
68
-
69
-	while(i<len) {
70
-		if(!i%16) {
71
-			DPRINTF("\n%s %04x: ", prefix, i);
72
-		}
73
-		else {
74
-			DPRINTF(": ");
75
-		}
76
-
77
-		DPRINTF("%02x", data[i++]);
78
-	}
79
-
80
-	DPRINTF("\n");
81
-}
82
-
83
-void dump_uhci(uint32_t port)
84
-{
85
-#if 0
86
-	unsigned long value;
87
-#endif
88
-
89
-	DPRINTF("HCI at %08x\n", port);
90
-#if 0
91
-	value = inw(port);
92
-	DPRINTF("Command: %04x\n", value);
93
-
94
-	value = inw(port+2);
95
-	DPRINTF("USBSTS: %04x\n", value);
96
-
97
-	value = inw(port+4);
98
-	DPRINTF("USBINTR: %04x\n", value);
99
-
100
-	value = inw(port+6);
101
-	DPRINTF("FRNUM: %04x\n", value);
102
-
103
-	value = inl(port+8);
104
-	DPRINTF("FLBASEADD: %08x\n", value);
105
-
106
-	value = inb(port+0x0c);
107
-	DPRINTF("SOFMOD: %02x\n", value);
108
-
109
-	value = inw(port+0x10);
110
-	DPRINTF("PORTSTS1: %04x\n", value);
111
-
112
-	value = inw(port+0x12);
113
-	DPRINTF("PORTSTS2: %04x\n", value);
114
-	
115
-#endif
116
-
117
-}
118
-
119
-void dump_td( td_t *td, char *prefix)
120
-{
121
-	char newpre[64];
122
-
123
-	newpre[0]='\t';
124
-	strcpy(newpre+1, prefix);
125
-
126
-	DPRINTF("%sTD(%08x):\n", prefix, td);
127
-
128
-	switch(td->packet_type) {
129
-		case SETUP_TOKEN:
130
-			DPRINTF("%stype: SETUP\n", prefix);
131
-			break;
132
-		case OUT_TOKEN:
133
-			DPRINTF("%stype: OUT\n", prefix);
134
-			break;
135
-		case IN_TOKEN:
136
-			DPRINTF("%stype: IN\n", prefix);
137
-			break;
138
-		default:
139
-			DPRINTF("%stype: INVALID (%02x)\n", prefix, td->packet_type);
140
-			break;
141
-	}
142
-
143
-	DPRINTF("%sretries: %x\n", prefix, td->retrys);
144
-
145
-	if(td->isochronous) {
146
-		DPRINTF("%sisochronous\n", prefix);
147
-	}
148
-
149
-	if(td->interrupt) {
150
-		DPRINTF("%sIOC\n", prefix);
151
-	}
152
-
153
-	if(td->lowspeed) {
154
-		DPRINTF("%slowspeed\n", prefix);
155
-	}
156
-
157
-	if(td->detect_short) {
158
-		DPRINTF("%sDETECT_SHORT\n", prefix);
159
-	}
160
-
161
-	DPRINTF("%sactive: %04x\n", prefix, td->active);
162
-	DPRINTF("%sdevice_addr: %02x\n", prefix, td->device_addr);
163
-	DPRINTF("%sendpoint: %1x\n", prefix, td->endpoint);
164
-	DPRINTF("%sdata_toggle: %1x\n", prefix, td->data_toggle);
165
-	DPRINTF("%smax_transfer: %x\n", prefix, td->max_transfer);
166
-	DPRINTF("%sactual: %x\n", prefix, td->actual);
167
-	DPRINTF("%slink:\n", prefix);
168
-
169
-	if(td->stall) {
170
-		DPRINTF("%sSTALL\n", prefix);
171
-	}
172
-
173
-	if(td->bitstuff) {
174
-		DPRINTF("%sBITSTUFF ERROR\n", prefix);
175
-	}
176
-
177
-	if(td->crc) {
178
-		DPRINTF("%sCRC ERROR\n", prefix);
179
-	}
180
-
181
-	if(td->nak) {
182
-		DPRINTF("%sNAK ERROR\n", prefix);
183
-	}
184
-
185
-	if(td->babble) {
186
-		DPRINTF("%sBABBLE ERROR\n", prefix);
187
-	}
188
-
189
-	if(td->buffer_error) {
190
-		DPRINTF("%sBUFFER ERROR\n", prefix);
191
-	}
192
-
193
-	if(MEM_ADDR(td->link.link) == td) {
194
-		DPRINTF("link loops back to me!\n");
195
-		return;
196
-	}
197
-
198
-	dump_link(&(td->link), newpre);
199
-	if(!td->link.terminate) {
200
-		if(td->link.queue)
201
-			dump_queue_head(MEM_ADDR(td->link.link), prefix );
202
-		else
203
-			dump_td(MEM_ADDR(td->link.link), prefix);
204
-	}
205
-}
206
-
207
-void dump_queue_head( queue_head_t *qh, char *prefix)
208
-{
209
-	char newpre[64];
210
-
211
-	newpre[0] = '\t';
212
-	strcpy(newpre+1, prefix);
213
-
214
-	DPRINTF("%sQUEUE HEAD(%x):\n", prefix, qh);
215
-	DPRINTF("%sdepth:\n", prefix);
216
-	dump_link( &(qh->depth), newpre);
217
-
218
-	if(!qh->depth.terminate) {
219
-		if(qh->depth.queue) {
220
-			dump_queue_head(MEM_ADDR(qh->depth.link), newpre);
221
-		}
222
-		else {
223
-			dump_td( MEM_ADDR(qh->depth.link), newpre);
224
-		}
225
-	}
226
-		
227
-
228
-	DPRINTF("%sbredth:\n", prefix);
229
-	dump_link( &(qh->bredth), newpre);
230
-	if(!qh->bredth.terminate) {
231
-		if(qh->bredth.queue) {
232
-			dump_queue_head(MEM_ADDR(qh->bredth.link), newpre);
233
-		}
234
-		else {
235
-			dump_td( MEM_ADDR(qh->bredth.link), newpre);
236
-		}
237
-	}
238
-}
239
-
240
-void dump_transaction( transaction_t *trans, char *prefix)
241
-{
242
-	char newpre[64];
243
-
244
-	newpre[0] = '\t';
245
-	strcpy(newpre+1, prefix);
246
-
247
-
248
-	DPRINTF("%s TRANSACTION(%x):\n", prefix, trans);
249
-	dump_queue_head( trans->qh, newpre);
250
-
251
-	DPRINTF("%s TDs:\n", prefix);
252
-	dump_td( trans->td_list, newpre);
253
-
254
-	DPRINTF("\n");
255
-	if(trans->next)
256
-		dump_transaction(trans->next, prefix);
257
-}
258
-
259
-void dump_usbdev( usbdev_t *dev, char *prefix)
260
-{
261
-	char newpre[64];
262
-	int i;
263
-
264
-	newpre[0] = '\t';
265
-	strcpy(newpre+1, prefix);
266
-
267
-	DPRINTF("%saddress: %x\n", prefix, dev->address);
268
-	DPRINTF("%sclass: %x\n", prefix, dev->class);
269
-	DPRINTF("%ssubclass: %x\n", prefix, dev->subclass);
270
-	DPRINTF("%sbulk_in: %x\n", prefix, dev->bulk_in);
271
-	DPRINTF("%sbulk_out: %x\n", prefix, dev->bulk_out);
272
-	DPRINTF("%sinterrupt: %x\n", prefix, dev->interrupt);
273
-
274
-	DPRINTF("%sep toggle:\n", prefix);
275
-		for(i=0;i<MAX_EP;i++) {
276
-			DPRINTF("%s%x\n", newpre, dev->toggle[i]);
277
-		}
278
-
279
-	DPRINTF("%sep max_packet:\n", prefix);
280
-		for(i=0;i<MAX_EP;i++) {
281
-			DPRINTF("%s%x\n", newpre, dev->max_packet[i]);
282
-		}
283
-}
284
-
285
-void dump_all_usbdev(char *prefix)
286
-{
287
-	int i;
288
-
289
-	for(i=0;i<MAX_USB_DEV;i++) {
290
-		if(usb_device[i].address) {
291
-			DPRINTF("%sDEVICE: %x\n", prefix, i);
292
-			dump_usbdev( usb_device +i, prefix);
293
-		}
294
-	}
295
-}
296
-
297
-void dump_device_descriptor( device_descriptor_t *des, char *prefix)
298
-{
299
-	DPRINTF("%sbLength: %02x\n", prefix, des->bLength);
300
-	DPRINTF("%stype: %02x\n", prefix, des->type);
301
-	DPRINTF("%sbcdVersion: %1x%1x\n", prefix, des->bcdVersion[1], des->bcdVersion[0]);
302
-	DPRINTF("%sClass: %02x\n",prefix, des->Class);
303
-	DPRINTF("%sSubClass: %02x\n",prefix, des->SubClass);
304
-	DPRINTF("%sprotocol: %02x\n",prefix, des->protocol);
305
-	DPRINTF("%smax_packet: %x\n",prefix, des->max_packet);
306
-	DPRINTF("%sidVendor: %04x\n", prefix, des->idVendor);
307
-	DPRINTF("%sidProduct: %04x\n", prefix, des->idProduct);
308
-	DPRINTF("%sbcdDeviceVersion: %1x%1x\n", prefix, des->bcdDevice[1], des->bcdDevice[0]);
309
-	DPRINTF("%siManufacturor: %02x\n", prefix, des->iManufacturor);
310
-	DPRINTF("%siProduct: %02x\n", prefix, des->iProduct);
311
-	DPRINTF("%siSerial: %02x\n", prefix, des->iSerial);
312
-	DPRINTF("%sbNumConfig: %02x\n", prefix, des->bNumConfig);
313
-
314
-}
315
-
316
-void dump_interface_descriptor( interface_descriptor_t *iface, char *prefix)
317
-{
318
-
319
-	DPRINTF("%sbLength: %02x\n", prefix, iface->bLength);
320
-	DPRINTF("%stype: %02x\n", prefix, iface->type);
321
-	DPRINTF("%sbInterfaceNumber: %02x\n", prefix, iface->bInterfaceNumber);
322
-	DPRINTF("%sbAlternateSetting: %02x\n", prefix, iface->bAlternateSetting);
323
-	DPRINTF("%sbNumEndpoints: %02x\n", prefix, iface->bNumEndpoints);
324
-	DPRINTF("%sbInterfaceClass: %02x\n", prefix, iface->bInterfaceClass);
325
-	DPRINTF("%sbInterfaceSubClass: %02x\n", prefix, iface->bInterfaceSubClass);
326
-	DPRINTF("%sbInterfaceProtocol: %02x\n", prefix, iface->bInterfaceProtocol);
327
-	DPRINTF("%siInterface: %02x\n", prefix, iface->iInterface);
328
-}
329
-
330
-void dump_endpoint_descriptor( endpoint_descriptor_t *ep, char *prefix)
331
-{
332
-
333
-	DPRINTF("%sbLength: %02x\n", prefix, ep->bLength);
334
-	DPRINTF("%stype: %02x\n", prefix, ep->type);
335
-	DPRINTF("%sbEndpointAddress: %02x\n", prefix, ep->bEndpointAddress);
336
-	DPRINTF("%sbmAttributes: %02x\n", prefix, ep->bmAttributes);
337
-	DPRINTF("%swMaxPacketSize: %02x\n", prefix, ep->wMaxPacketSize);
338
-	DPRINTF("%sbInterval: %02x\n", prefix, ep->bInterval);
339
-}
340
-
341
-void dump_config_descriptor( uchar *des, char *prefix)	// YES uchar *
342
-{
343
-	config_descriptor_t *config;
344
-	interface_descriptor_t *iface;
345
-	endpoint_descriptor_t *ep;
346
-	char newpre[64];
347
-	int i;
348
-
349
-	memset(newpre,0,sizeof(newpre));
350
-	newpre[0] = '\t';
351
-	strcpy(newpre+1, prefix);
352
-
353
-	config = (config_descriptor_t *) des;
354
-	iface = (interface_descriptor_t *) (des + config->bLength);
355
-	ep = (endpoint_descriptor_t *) (des + config->bLength + iface->bLength);
356
-	
357
-	// now, the config itself
358
-	DPRINTF("%sbLength: %02x\n", prefix, config->bLength);
359
-	DPRINTF("%stype: %02x\n", prefix, config->type);
360
-	DPRINTF("%swTotalLength: %04x\n", prefix, config->wTotalLength);
361
-	DPRINTF("%sbNumInterfaces: %02x\n", prefix, config->bNumInterfaces);
362
-	DPRINTF("%sbConfigurationValue: %02x\n", prefix, config->bConfigurationValue);
363
-	DPRINTF("%siConfiguration: %02x\n", prefix, config->iConfiguration);
364
-	DPRINTF("%sbmAttributes: %02x\n", prefix, config->bmAttributes);
365
-
366
-	DPRINTF("%sbMaxPower: %02x\n", prefix, config->bMaxPower);
367
-
368
-	DPRINTF("\n%sInterface(%x):\n", prefix, iface);
369
-	dump_interface_descriptor(iface, newpre);
370
-
371
-	newpre[1] = '\t';
372
-	strcpy(newpre+2, prefix);
373
-
374
-	for(i=0; i<iface->bNumEndpoints; i++) {
375
-		DPRINTF("\n%sEndpoint (%x):\n", newpre+1, ep+i);
376
-		dump_endpoint_descriptor( ep+i, newpre);
377
-	}
378
-}
379
-
380
-// Some control message bmRequestType defines
381
-#define CTRL_DEVICE 0
382
-#define CONTROL_INTERFACE 1
383
-#define CONTROL_ENDPOINT 2
384
-#define CONTROL_OTHER 3
385
-#define CONTROL_RECIPIENT_MASK 0x1f
386
-
387
-#define CONTROL_TYPE_STD 0
388
-#define CONTROL_TYPE_CLASS 0x20
389
-#define CONTROL_CLASS_VENDOR 0x40
390
-#define CONTROL_CLASS_MASK 0x60
391
-
392
-#define CONTROL_OUT 0
393
-#define CONTROL_IN 0x80
394
-#define CONTROL_DIR_MASK 0x80
395
-
396
-// bRequest values
397
-#define GET_STATUS 0
398
-#define CLEAR_FEATURE 1
399
-#define SET_FEATURE 3
400
-#define SET_ADDRESS 5
401
-
402
-#define GET_DESCRIPTOR 6
403
-#define SET_DESCRIPTOR 7
404
-
405
-#define GET_CONFIGURATION 8
406
-#define SET_CONFIGURATION 9
407
-
408
-#define GET_INTERFACE 10
409
-#define SET_INTERFACE 11
410
-
411
-#define SYNC_FRAME 12
412
-
413
-// descriptor types
414
-#define DEVICE_DESC 1
415
-#define CONFIGURATION_DESC 2
416
-#define STRING_DESC 3
417
-#define INTERFACE_DESC 4
418
-#define ENDPOINT_DESC 5
419
-#define OTHERSPEED_DESC 7
420
-#define POWER_DESC 8
421
-
422
-// features
423
-#define FEATURE_HALT 0
424
-void dump_ctrlmsg( ctrl_msg_t *msg, char *prefix)
425
-{
426
-	DPRINTF("%sbmRequestType: %02x\n", prefix, msg->bmRequestType);
427
-	DPRINTF("%sbRequest: %02x\n", prefix, msg->bRequest);
428
-	DPRINTF("%swValue: %04x\n", prefix, msg->wValue);
429
-	DPRINTF("%swIndex: %04x\n", prefix, msg->wIndex);
430
-	DPRINTF("%swLength: %04x\n", prefix, msg->wLength);
431
-}
432
-
433
-#endif

+ 0
- 18
src/filo/usb/debug_x.h Целия файл

@@ -1,18 +0,0 @@
1
-#ifndef _DEBUG_X_H
2
-#define _DEBUG_X_H
3
-
4
-void dump_hex(uchar *data, int len, char *prefix);
5
-void dump_link( link_pointer_t *link, char *prefix);
6
-void dump_td( td_t *td, char *prefix);
7
-void dump_queue_head( queue_head_t *qh, char *prefix);
8
-void dump_transaction( transaction_t *trans, char *prefix);
9
-void dump_usbdev( usbdev_t *dev, char *prefix);
10
-void dump_uhci(uint32_t port);
11
-//void dump_all_usbdev(char *prefix);
12
-void dump_device_descriptor( device_descriptor_t *des, char *prefix);
13
-void dump_interface_descriptor( interface_descriptor_t *iface, char *prefix);
14
-void dump_endpoint_descriptor( endpoint_descriptor_t *ep, char *prefix);
15
-void dump_config_descriptor( uchar *des, char *prefix);
16
-void dump_ctrlmsg( ctrl_msg_t *msg, char *prefix);
17
-
18
-#endif

+ 0
- 1437
src/filo/usb/ohci.c
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 0
- 316
src/filo/usb/ohci.h Целия файл

@@ -1,316 +0,0 @@
1
-#ifdef USB_DISK
2
-
3
-#ifndef _OHCI_H
4
-#define _OHCI_H
5
-
6
-/*******************************************************************************
7
- *
8
- *
9
- *	Copyright 2003 Steven James <pyro@linuxlabs.com> and
10
- *	LinuxLabs http://www.linuxlabs.com
11
- *
12
- *	This program is free software; you can redistribute it and/or modify
13
- *	it under the terms of the GNU General Public License as published by
14
- *	the Free Software Foundation; either version 2 of the License, or
15
- *	(at your option) any later version.
16
- *
17
- *	This program is distributed in the hope that it will be useful,
18
- *	but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
- *	GNU General Public License for more details.
21
- *
22
- *	You should have received a copy of the GNU General Public License
23
- *	along with this program; if not, write to the Free Software
24
- *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
- *
26
- ******************************************************************************/
27
-
28
-// for OHCI
29
-
30
-/* ED States */
31
-
32
-#define ED_NEW          0x00
33
-#define ED_UNLINK       0x01
34
-#define ED_OPER         0x02
35
-#define ED_DEL          0x04
36
-#define ED_URB_DEL      0x08
37
-
38
-/* usb_ohci_ed */
39
-struct ed {
40
-        u32 hwINFO;       
41
-        u32 hwTailP;
42
-        u32 hwHeadP;
43
-        u32 hwNextED;
44
-
45
-        struct ed * ed_prev;  
46
-        u8 int_period;  // No  use just for aligned
47
-        u8 int_branch;  // No use just for aligned
48
-        u8 int_load;    // No uae just for aligned
49
-        u8 int_interval; // No use just for aligned
50
-        u8 state;
51
-        u8 type;
52
-        u16 last_iso; // no use just for aligned
53
-        struct ed * ed_rm_list;  // No use just for aligned
54
-
55
-        void * dma;         
56
-
57
-        u32 unused[3];        
58
-};
59
-// __attribute((aligned(16)));   
60
-typedef struct ed ed_t;
61
-
62
-/* TD info field */
63
-#define TD_CC       0xf0000000
64
-#define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
65
-#define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
66
-#define TD_EC       0x0C000000
67
-#define TD_T        0x03000000
68
-#define TD_T_DATA0  0x02000000
69
-#define TD_T_DATA1  0x03000000
70
-#define TD_T_TOGGLE 0x00000000
71
-#define TD_R        0x00040000
72
-#define TD_DI       0x00E00000
73
-#define TD_DI_SET(X) (((X) & 0x07)<< 21)
74
-#define TD_DP       0x00180000
75
-#define TD_DP_SETUP 0x00000000
76
-#define TD_DP_IN    0x00100000
77
-#define TD_DP_OUT   0x00080000
78
-
79
-#define TD_ISO      0x00010000
80
-#define TD_DEL      0x00020000
81
-
82
-/* CC Codes */
83
-#define TD_CC_NOERROR      0x00
84
-#define TD_CC_CRC          0x01
85
-#define TD_CC_BITSTUFFING  0x02
86
-#define TD_CC_DATATOGGLEM  0x03
87
-#define TD_CC_STALL        0x04
88
-#define TD_DEVNOTRESP      0x05
89
-#define TD_PIDCHECKFAIL    0x06
90
-#define TD_UNEXPECTEDPID   0x07
91
-#define TD_DATAOVERRUN     0x08
92
-#define TD_DATAUNDERRUN    0x09
93
-#define TD_BUFFEROVERRUN   0x0C
94
-#define TD_BUFFERUNDERRUN  0x0D
95
-#define TD_NOTACCESSED     0x0F
96
-
97
-
98
-#define MAXPSW 1
99
-
100
-struct ohci_td {
101
-        u32 hwINFO;
102
-        u32 hwCBP;            /* Current Buffer Pointer */
103
-        u32 hwNextTD;         /* Next TD Pointer */
104
-        u32 hwBE;             /* Memory Buffer End Pointer */
105
-        u16 hwPSW[MAXPSW];
106
-        u8 unused;
107
-        u8 index;
108
-        struct ed * ed;
109
-        struct ohci_td * next_dl_td;
110
-        struct urb * urb;  //defined in usb.h
111
-        void * td_dma;
112
-        void * data_dma;
113
-        u32 unused2[2];
114
-}; 
115
-//__attribute((aligned(32)));   /* normally 16, iso needs 32 */
116
-typedef struct ohci_td ohci_td_t;
117
-
118
-#define OHCI_ED_SKIP    (1 << 14)
119
-
120
-/*
121
- * The HCCA (Host Controller Communications Area) is a 256 byte
122
- * structure defined in the OHCI spec. that the host controller is
123
- * told the base address of.  It must be 256-byte aligned.
124
- */
125
-
126
-#define NUM_INTS 32     /* part of the OHCI standard */
127
-struct ohci_hcca {
128
-        u32   int_table[NUM_INTS];    /* Interrupt ED table */
129
-        u16   frame_no;               /* current frame number */
130
-        u16   pad1;                   /* set to 0 on each frame_no change */
131
-        u32   done_head;              /* info returned for an interrupt */
132
-        u8              reserved_for_hc[116];
133
-} __attribute((aligned(256)));
134
-
135
-
136
-#define MAX_ROOT_PORTS 15
137
-
138
-struct ohci_regs {
139
-        /* control and status registers */
140
-        u32   revision;
141
-        u32   control;
142
-        u32   cmdstatus;
143
-        u32   intrstatus;
144
-        u32   intrenable;
145
-        u32   intrdisable;
146
-        /* memory pointers */
147
-        u32   hcca;
148
-        u32   ed_periodcurrent;
149
-        u32   ed_controlhead;
150
-        u32   ed_controlcurrent;
151
-        u32   ed_bulkhead;
152
-        u32   ed_bulkcurrent;
153
-        u32   donehead;
154
-        /* frame counters */
155
-        u32   fminterval;
156
-        u32   fmremaining;
157
-        u32   fmnumber;
158
-        u32   periodicstart;
159
-        u32   lsthresh;
160
-        /* Root hub ports */
161
-        struct  ohci_roothub_regs {
162
-                u32   a;
163
-                u32   b;
164
-                u32   status;
165
-                u32   portstatus[MAX_ROOT_PORTS];
166
-        } roothub;
167
-} __attribute((aligned(32))); 
168
-typedef struct ohci_regs ohci_regs_t;
169
-
170
-
171
-/* OHCI CONTROL AND STATUS REGISTER MASKS */
172
-
173
-/*
174
- * HcControl (control) register masks
175
- */
176
-#define OHCI_CTRL_CBSR  (3 << 0)        /* control/bulk service ratio */
177
-#define OHCI_CTRL_PLE   (1 << 2)        /* periodic list enable */
178
-#define OHCI_CTRL_IE    (1 << 3)        /* isochronous enable */
179
-#define OHCI_CTRL_CLE   (1 << 4)        /* control list enable */
180
-#define OHCI_CTRL_BLE   (1 << 5)        /* bulk list enable */
181
-#define OHCI_CTRL_HCFS  (3 << 6)        /* host controller functional state */
182
-#define OHCI_CTRL_IR    (1 << 8)        /* interrupt routing */
183
-#define OHCI_CTRL_RWC   (1 << 9)        /* remote wakeup connected */
184
-#define OHCI_CTRL_RWE   (1 << 10)       /* remote wakeup enable */
185
-
186
-/* pre-shifted values for HCFS */
187
-#       define OHCI_USB_RESET   (0 << 6)
188
-#       define OHCI_USB_RESUME  (1 << 6)
189
-#       define OHCI_USB_OPER    (2 << 6)
190
-#       define OHCI_USB_SUSPEND (3 << 6)
191
-
192
-/*
193
- * HcCommandStatus (cmdstatus) register masks
194
- */
195
-#define OHCI_HCR        (1 << 0)        /* host controller reset */
196
-#define OHCI_CLF        (1 << 1)        /* control list filled */
197
-#define OHCI_BLF        (1 << 2)        /* bulk list filled */
198
-#define OHCI_OCR        (1 << 3)        /* ownership change request */
199
-#define OHCI_SOC        (3 << 16)       /* scheduling overrun count */
200
-
201
-/*      
202
- * masks used with interrupt registers:
203
- * HcInterruptStatus (intrstatus)
204
- * HcInterruptEnable (intrenable)
205
- * HcInterruptDisable (intrdisable)
206
- */     
207
-#define OHCI_INTR_SO    (1 << 0)        /* scheduling overrun */
208
-#define OHCI_INTR_WDH   (1 << 1)        /* writeback of done_head */
209
-#define OHCI_INTR_SF    (1 << 2)        /* start frame */
210
-#define OHCI_INTR_RD    (1 << 3)        /* resume detect */
211
-#define OHCI_INTR_UE    (1 << 4)        /* unrecoverable error */
212
-#define OHCI_INTR_FNO   (1 << 5)        /* frame number overflow */
213
-#define OHCI_INTR_RHSC  (1 << 6)        /* root hub status change */
214
-#define OHCI_INTR_OC    (1 << 30)       /* ownership change */
215
-#define OHCI_INTR_MIE   (1 << 31)       /* master interrupt enable */
216
-
217
-
218
-/* For initializing controller (mask in an HCFS mode too) */
219
-#define OHCI_CONTROL_INIT \
220
-        (OHCI_CTRL_CBSR & 0x3) 
221
-//| OHCI_CTRL_IE | OHCI_CTRL_PLE   
222
-
223
-/* OHCI ROOT HUB REGISTER MASKS */
224
-
225
-/* roothub.portstatus [i] bits */
226
-#define RH_PS_CCS            0x00000001         /* current connect status */
227
-#define RH_PS_PES            0x00000002         /* port enable status*/
228
-#define RH_PS_PSS            0x00000004         /* port suspend status */
229
-#define RH_PS_POCI           0x00000008         /* port over current indicator */
230
-#define RH_PS_PRS            0x00000010         /* port reset status */
231
-#define RH_PS_PPS            0x00000100         /* port power status */
232
-#define RH_PS_LSDA           0x00000200         /* low speed device attached */
233
-#define RH_PS_CSC            0x00010000         /* connect status change */
234
-#define RH_PS_PESC           0x00020000         /* port enable status change */
235
-#define RH_PS_PSSC           0x00040000         /* port suspend status change */
236
-#define RH_PS_OCIC           0x00080000         /* over current indicator change */
237
-#define RH_PS_PRSC           0x00100000         /* port reset status change */
238
-
239
-/* roothub.status bits */
240
-#define RH_HS_LPS            0x00000001         /* local power status */
241
-#define RH_HS_OCI            0x00000002         /* over current indicator */
242
-#define RH_HS_DRWE           0x00008000         /* device remote wakeup enable */
243
-#define RH_HS_LPSC           0x00010000         /* local power status change */
244
-#define RH_HS_OCIC           0x00020000         /* over current indicator change */
245
-#define RH_HS_CRWE           0x80000000         /* clear remote wakeup enable */
246
-
247
-/* roothub.b masks */
248
-#define RH_B_DR         0x0000ffff              /* device removable flags */
249
-#define RH_B_PPCM       0xffff0000              /* port power control mask */
250
-
251
-/* roothub.a masks */
252
-#define RH_A_NDP        (0xff << 0)             /* number of downstream ports */
253
-#define RH_A_PSM        (1 << 8)                /* power switching mode */
254
-#define RH_A_NPS        (1 << 9)                /* no power switching */
255
-#define RH_A_DT         (1 << 10)               /* device type (mbz) */
256
-#define RH_A_OCPM       (1 << 11)               /* over current protection mode */
257
-#define RH_A_NOCP       (1 << 12)               /* no over current protection */
258
-#define RH_A_POTPGT     (0xff << 24)            /* power on to power good time */
259
-
260
-typedef struct
261
-{
262
-        ed_t * ed;
263
-        u16 length;   // number of tds associated with this request
264
-        u16 td_cnt;   // number of tds already serviced
265
-        int   state;
266
-#if 0
267
-        wait_queue_head_t * wait;
268
-#endif
269
-        ohci_td_t * td[0];   // list pointer to all corresponding TDs associated with this request
270
-
271
-} urb_priv_t;
272
-
273
-#define NUM_EDS 32              /* num of preallocated endpoint descriptors */
274
-
275
-typedef struct ohci {
276
-        struct ohci_hcca *hcca;         /* hcca */
277
-        void * hcca_dma;
278
-	
279
-        ohci_regs_t * regs;        /* OHCI controller's memory */
280
-        
281
-	ed_t * ed_bulktail;       /* last endpoint of bulk list */
282
-        ed_t * ed_controltail;    /* last endpoint of control list */
283
-
284
-        int intrstatus;
285
-        u32 hc_control;               /* copy of the hc control reg */
286
-
287
-	uint32_t ed_cnt;
288
-	ed_t   *ed;	// Allocate that from ed_buffer in ohc_init
289
-	usbdev_t *dev[NUM_EDS];
290
-	urb_t *urb; // one ohci one urb
291
-	urb_priv_t *urb_priv;
292
-	struct usb_ctrlrequest *dr; 
293
-} ohci_t;
294
-
295
-
296
-extern ohci_t _ohci_x[MAX_CONTROLLERS];
297
-
298
-#define usb_to_ohci(usb_dev) (&_ohci_x[(usb_dev)->controller])
299
-
300
-extern ohci_regs_t *ohci_regs;
301
-
302
-void clear_oport_stat(uint32_t port);
303
-int ohc_init(struct pci_device *dev);
304
-int poll_o_root_hub(uint32_t port, uchar controller);
305
-
306
-int ohci_bulk_transfer( uchar devnum, uchar ep, unsigned int data_len, uchar *data);
307
-int ohci_control_msg( uchar devnum, uchar request_type, uchar request, unsigned short wValue, unsigned short wIndex, unsigned short
308
-	wLength, void *data);
309
-void ohci_wait_urb_done(struct urb *urb, int timeout);
310
-
311
-void ohci_init(void);
312
-int ohc_init(struct pci_device *dev);
313
-int ohci_submit_urb (struct urb * urb);
314
-#endif
315
-
316
-#endif

+ 0
- 226
src/filo/usb/scsi.h Целия файл

@@ -1,226 +0,0 @@
1
-/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
2
-   This file is part of the GNU C Library.
3
-
4
-   The GNU C Library is free software; you can redistribute it and/or
5
-   modify it under the terms of the GNU Lesser General Public
6
-   License as published by the Free Software Foundation; either
7
-   version 2.1 of the License, or (at your option) any later version.
8
-
9
-   The GNU C Library is distributed in the hope that it will be useful,
10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
-   Lesser General Public License for more details.
13
-
14
-   You should have received a copy of the GNU Lesser General Public
15
-   License along with the GNU C Library; if not, write to the Free
16
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17
-   02111-1307 USA.  */
18
-
19
-/*
20
- * This header file contains public constants and structures used by
21
- * the scsi code for linux.
22
- */
23
-
24
-#ifndef _SCSI_SCSI_H
25
-#define _SCSI_SCSI_H	1
26
-
27
-//#include <features.h>
28
-
29
-/*
30
- *      SCSI opcodes
31
- */
32
-
33
-#define TEST_UNIT_READY       0x00
34
-#define REZERO_UNIT           0x01
35
-#define REQUEST_SENSE         0x03
36
-#define FORMAT_UNIT           0x04
37
-#define READ_BLOCK_LIMITS     0x05
38
-#define REASSIGN_BLOCKS       0x07
39
-#define READ_6                0x08
40
-#define WRITE_6               0x0a
41
-#define SEEK_6                0x0b
42
-#define READ_REVERSE          0x0f
43
-#define WRITE_FILEMARKS       0x10
44
-#define SPACE                 0x11
45
-#define INQUIRY               0x12
46
-#define RECOVER_BUFFERED_DATA 0x14
47
-#define MODE_SELECT           0x15
48
-#define RESERVE               0x16
49
-#define RELEASE               0x17
50
-#define COPY                  0x18
51
-#define ERASE                 0x19
52
-#define MODE_SENSE            0x1a
53
-#define START_STOP            0x1b
54
-#define RECEIVE_DIAGNOSTIC    0x1c
55
-#define SEND_DIAGNOSTIC       0x1d
56
-#define ALLOW_MEDIUM_REMOVAL  0x1e
57
-
58
-#define SET_WINDOW            0x24
59
-#define READ_CAPACITY         0x25
60
-#define READ_10               0x28
61
-#define WRITE_10              0x2a
62
-#define SEEK_10               0x2b
63
-#define WRITE_VERIFY          0x2e
64
-#define VERIFY                0x2f
65
-#define SEARCH_HIGH           0x30
66
-#define SEARCH_EQUAL          0x31
67
-#define SEARCH_LOW            0x32
68
-#define SET_LIMITS            0x33
69
-#define PRE_FETCH             0x34
70
-#define READ_POSITION         0x34
71
-#define SYNCHRONIZE_CACHE     0x35
72
-#define LOCK_UNLOCK_CACHE     0x36
73
-#define READ_DEFECT_DATA      0x37
74
-#define MEDIUM_SCAN           0x38
75
-#define COMPARE               0x39
76
-#define COPY_VERIFY           0x3a
77
-#define WRITE_BUFFER          0x3b
78
-#define READ_BUFFER           0x3c
79
-#define UPDATE_BLOCK          0x3d
80
-#define READ_LONG             0x3e
81
-#define WRITE_LONG            0x3f
82
-#define CHANGE_DEFINITION     0x40
83
-#define WRITE_SAME            0x41
84
-#define READ_TOC              0x43
85
-#define LOG_SELECT            0x4c
86
-#define LOG_SENSE             0x4d
87
-#define MODE_SELECT_10        0x55
88
-#define RESERVE_10            0x56
89
-#define RELEASE_10            0x57
90
-#define MODE_SENSE_10         0x5a
91
-#define PERSISTENT_RESERVE_IN 0x5e
92
-#define PERSISTENT_RESERVE_OUT 0x5f
93
-#define MOVE_MEDIUM           0xa5
94
-#define READ_12               0xa8
95
-#define WRITE_12              0xaa
96
-#define WRITE_VERIFY_12       0xae
97
-#define SEARCH_HIGH_12        0xb0
98
-#define SEARCH_EQUAL_12       0xb1
99
-#define SEARCH_LOW_12         0xb2
100
-#define READ_ELEMENT_STATUS   0xb8
101
-#define SEND_VOLUME_TAG       0xb6
102
-#define WRITE_LONG_2          0xea
103
-
104
-/*
105
- *  Status codes
106
- */
107
-
108
-#define GOOD                 0x00
109
-#define CHECK_CONDITION      0x01
110
-#define CONDITION_GOOD       0x02
111
-#define BUSY                 0x04
112
-#define INTERMEDIATE_GOOD    0x08
113
-#define INTERMEDIATE_C_GOOD  0x0a
114
-#define RESERVATION_CONFLICT 0x0c
115
-#define COMMAND_TERMINATED   0x11
116
-#define QUEUE_FULL           0x14
117
-
118
-#define STATUS_MASK          0x3e
119
-
120
-/*
121
- *  SENSE KEYS
122
- */
123
-
124
-#define NO_SENSE            0x00
125
-#define RECOVERED_ERROR     0x01
126
-#define NOT_READY           0x02
127
-#define MEDIUM_ERROR        0x03
128
-#define HARDWARE_ERROR      0x04
129
-#define ILLEGAL_REQUEST     0x05
130
-#define UNIT_ATTENTION      0x06
131
-#define DATA_PROTECT        0x07
132
-#define BLANK_CHECK         0x08
133
-#define COPY_ABORTED        0x0a
134
-#define ABORTED_COMMAND     0x0b
135
-#define VOLUME_OVERFLOW     0x0d
136
-#define MISCOMPARE          0x0e
137
-
138
-
139
-/*
140
- *  DEVICE TYPES
141
- */
142
-
143
-#define TYPE_DISK           0x00
144
-#define TYPE_TAPE           0x01
145
-#define TYPE_PROCESSOR      0x03    /* HP scanners use this */
146
-#define TYPE_WORM           0x04    /* Treated as ROM by our system */
147
-#define TYPE_ROM            0x05
148
-#define TYPE_SCANNER        0x06
149
-#define TYPE_MOD            0x07    /* Magneto-optical disk -
150
-				     * - treated as TYPE_DISK */
151
-#define TYPE_MEDIUM_CHANGER 0x08
152
-#define TYPE_ENCLOSURE	    0x0d    /* Enclosure Services Device */
153
-#define TYPE_NO_LUN         0x7f
154
-
155
-/*
156
- * standard mode-select header prepended to all mode-select commands
157
- *
158
- * moved here from cdrom.h -- kraxel
159
- */
160
-
161
-struct ccs_modesel_head
162
-  {
163
-    unsigned char _r1;			/* reserved.  */
164
-    unsigned char medium;		/* device-specific medium type.  */
165
-    unsigned char _r2;			/* reserved.  */
166
-    unsigned char block_desc_length;	/* block descriptor length.  */
167
-    unsigned char density;		/* device-specific density code.  */
168
-    unsigned char number_blocks_hi;	/* number of blocks in this block
169
-					   desc.  */
170
-    unsigned char number_blocks_med;
171
-    unsigned char number_blocks_lo;
172
-    unsigned char _r3;
173
-    unsigned char block_length_hi;	/* block length for blocks in this
174
-					   desc.  */
175
-    unsigned char block_length_med;
176
-    unsigned char block_length_lo;
177
-  };
178
-
179
-/*
180
- *  MESSAGE CODES
181
- */
182
-
183
-#define COMMAND_COMPLETE    0x00
184
-#define EXTENDED_MESSAGE    0x01
185
-#define     EXTENDED_MODIFY_DATA_POINTER    0x00
186
-#define     EXTENDED_SDTR                   0x01
187
-#define     EXTENDED_EXTENDED_IDENTIFY      0x02    /* SCSI-I only */
188
-#define     EXTENDED_WDTR                   0x03
189
-#define SAVE_POINTERS       0x02
190
-#define RESTORE_POINTERS    0x03
191
-#define DISCONNECT          0x04
192
-#define INITIATOR_ERROR     0x05
193
-#define ABORT               0x06
194
-#define MESSAGE_REJECT      0x07
195
-#define NOP                 0x08
196
-#define MSG_PARITY_ERROR    0x09
197
-#define LINKED_CMD_COMPLETE 0x0a
198
-#define LINKED_FLG_CMD_COMPLETE 0x0b
199
-#define BUS_DEVICE_RESET    0x0c
200
-
201
-#define INITIATE_RECOVERY   0x0f            /* SCSI-II only */
202
-#define RELEASE_RECOVERY    0x10            /* SCSI-II only */
203
-
204
-#define SIMPLE_QUEUE_TAG    0x20
205
-#define HEAD_OF_QUEUE_TAG   0x21
206
-#define ORDERED_QUEUE_TAG   0x22
207
-
208
-/*
209
- * Here are some scsi specific ioctl commands which are sometimes useful.
210
- */
211
-/* These are a few other constants only used by scsi devices.  */
212
-
213
-#define SCSI_IOCTL_GET_IDLUN 0x5382
214
-
215
-/* Used to turn on and off tagged queuing for scsi devices.  */
216
-
217
-#define SCSI_IOCTL_TAGGED_ENABLE 0x5383
218
-#define SCSI_IOCTL_TAGGED_DISABLE 0x5384
219
-
220
-/* Used to obtain the host number of a device.  */
221
-#define SCSI_IOCTL_PROBE_HOST 0x5385
222
-
223
-/* Used to get the bus number for a device.  */
224
-#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
225
-
226
-#endif /* scsi/scsi.h */

+ 0
- 512
src/filo/usb/scsi_cmds.c Целия файл

@@ -1,512 +0,0 @@
1
-#ifdef USB_DISK
2
-/*******************************************************************************
3
- *
4
- *
5
- *	Copyright 2003 Steven James <pyro@linuxlabs.com> and
6
- *	LinuxLabs http://www.linuxlabs.com
7
- *
8
- *	This program is free software; you can redistribute it and/or modify
9
- *	it under the terms of the GNU General Public License as published by
10
- *	the Free Software Foundation; either version 2 of the License, or
11
- *	(at your option) any later version.
12
- *
13
- *	This program is distributed in the hope that it will be useful,
14
- *	but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- *	GNU General Public License for more details.
17
- *
18
- *	You should have received a copy of the GNU General Public License
19
- *	along with this program; if not, write to the Free Software
20
- *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
- *
22
- ******************************************************************************/
23
-#include <etherboot.h>
24
-#include <pci.h>
25
-#include <timer.h>
26
-#include <lib.h>
27
-        
28
-#define DEBUG_THIS DEBUG_USB
29
-#include <debug.h>
30
-
31
-#define DPRINTF debug
32
-
33
-
34
-#include "scsi.h"
35
-
36
-
37
-#include "usb_scsi_low.h"
38
-
39
-#ifndef NULL
40
-#define NULL (void *) 0x0
41
-#endif
42
-
43
-#include "scsi_cmds.h"
44
-
45
-devhandle sgh;
46
-
47
-typedef struct sense_data {
48
-	uchar code;
49
-	
50
-	uchar sense_key:4;
51
-	uchar res1:4;
52
-
53
-	uchar additional_code;
54
-	uchar qualifier;
55
-
56
-	uchar res2[3];
57
-
58
-	uchar length;
59
-} __attribute__ ((packed)) sense_data_t;
60
-
61
-typedef struct fixed_sense_data {
62
-	uchar code:7;
63
-	uchar valid:1;
64
-
65
-	uchar obs1;
66
-
67
-	uchar sense_key:4;
68
-	uchar res1:1;
69
-	uchar ili:1;
70
-	uchar eom:1;
71
-	uchar mark:1;
72
-
73
-	unsigned int  info;
74
-
75
-	uchar add_len;
76
-} __attribute__ ((packed)) fixed_sense_data_t;
77
-
78
-typedef struct additional_fixed_data {
79
-	unsigned int info;
80
-	
81
-	uchar code;
82
-	uchar qualifier;
83
-	uchar fru;
84
-
85
-	uchar specific[3];
86
-} __attribute__ ((packed)) additional_fixed_data_t;
87
-	
88
-
89
-void PrintSense(uchar *sense, int len)
90
-{
91
-	int i;
92
-
93
-	DPRINTF( "sense data ");
94
-	for(i=0;i<len; i++) {
95
-		DPRINTF(  ":%02x", sense[i]);
96
-	}
97
-	DPRINTF("\n\n");
98
-
99
-	if( (sense[0] & 0x7f) >=0x72) {
100
-		sense_data_t *sd = (sense_data_t *) sense;
101
-		uchar *pos = sense+sizeof(sense_data_t);
102
-		uchar remaining = sd->length;
103
-		int dlen;
104
-		
105
-		DPRINTF("code = %02x, key = %1x, additional = %02x, qual = %02x\n", sd->code, sd->sense_key, sd->additional_code, sd->qualifier);
106
-
107
-		while(remaining) {
108
-			DPRINTF("type = %02x", pos[0]);
109
-			dlen = pos[1];
110
-			pos+=2;
111
-			remaining -=2;
112
-
113
-			for(i=0; i<dlen; i++) 
114
-				DPRINTF( ": %02x", pos[i]);
115
-
116
-			DPRINTF("\n");
117
-			pos+=i;
118
-			remaining -=i;
119
-		}
120
-
121
-	} else {
122
-		fixed_sense_data_t *fd = (fixed_sense_data_t *) sense;
123
-		uchar remaining = fd->add_len;
124
-		additional_fixed_data_t *afd;
125
-
126
-		
127
-		DPRINTF("code = %02x key = %1x\n", fd->code, fd->sense_key);
128
-		if(fd->mark) {
129
-			DPRINTF("filemark ");
130
-		}
131
-
132
-		if(fd->eom) {
133
-			DPRINTF(" End Of Media ");
134
-		}
135
-
136
-		if(fd->ili) {
137
-			DPRINTF("Illegal instruction");
138
-		}
139
-
140
-		DPRINTF("\n");
141
-
142
-		if(fd->valid) {
143
-			DPRINTF( "(valid) ");
144
-		}
145
-
146
-		DPRINTF( "Info: %08x\n", ntohl(fd->info));
147
-
148
-		afd = (additional_fixed_data_t *) (sense + 8);
149
-
150
-//		while(remaining) {
151
-		if(remaining) {
152
-			DPRINTF("command info = %08x\n", ntohl(afd->info));
153
-			DPRINTF("code = %02x, qual = %02x, fru = %02x\n", afd->code, afd->qualifier, afd->fru);
154
-			DPRINTF("sense key data = %02x:%02x:%02x\n\n", afd->specific[2], afd->specific[1], afd->specific[0]);
155
-
156
-			afd++;
157
-			remaining -= sizeof(additional_fixed_data_t);
158
-		}
159
-	}
160
-		
161
-}
162
-	
163
-typedef struct query_response {
164
-	uchar type:5;
165
-	uchar qualifier:3;
166
-
167
-	uchar reserved1:7;
168
-	uchar removable:1;
169
-
170
-	uchar version;
171
-
172
-	uchar ResponseDataFormat:4;	// should == 2
173
-	uchar HiSup:1;			// report luns cmd supported
174
-	uchar NormACA:1;
175
-	uchar obsolete:1;
176
-	uchar aerc:1;
177
-
178
-	uchar AdditionalLength;		// length of vendor specific data (beyond 96 bytes)
179
-
180
-	uchar reserved2:7;
181
-	uchar sccs:1;			// have raid controller
182
-
183
-	uchar addr16:1;			// 
184
-	uchar obsolete2:2;
185
-	uchar MChnger:1;		// media changer
186
-	uchar MultiP:1;			// multi port
187
-	uchar vs:1;			// ???
188
-	uchar EncServ:1;		// enclosure service
189
-	uchar BQue:1;			// basic command queueing
190
-
191
-	uchar vs2:1;
192
-	uchar CmdQue:1;			// full command queueing
193
-	uchar obsolete4:1;
194
-	uchar linked:1;
195
-	uchar sync:1;
196
-	uchar wbus16:1;			//
197
-	uchar obsolete3:1;
198
-	uchar RelAddr:1;		// treletive addressing
199
-
200
-	char vendor[8];
201
-	char product[16];
202
-	char revision[4];
203
-	char vendor_data[20];
204
-
205
-	uchar ius:1;
206
-	uchar qas:1;
207
-	uchar clocking:2;		// 
208
-	uchar reserved3:4;
209
-
210
-	unsigned short version_desc[8];
211
-
212
-	char reserved4[21];
213
-} query_response_t;
214
-
215
-typedef struct ReadBlockCMD {
216
-	uchar cmd;
217
-
218
-	uchar reladdr:1;
219
-	uchar reserved:2;
220
-	uchar fua:1;		// force unit access flush to media
221
-	uchar dpo:1;		// direct page out, do not cache
222
-	uchar reserved2:3;
223
-
224
-	unsigned int block_address;
225
-	uchar reserved3;
226
-	
227
-	unsigned short block_count;
228
-
229
-	uchar control;
230
-} __attribute__ ((packed)) ReadBlockCMD_t ;
231
-
232
-int ll_read_block(devhandle sgd, char *buffer, int blocknum, int count)
233
-{
234
-	int ret;
235
-	ReadBlockCMD_t rb;
236
-	char sensedat[32];
237
-
238
-	memset(&rb,0,sizeof(rb));
239
-	rb.cmd = READ_10;
240
-	rb.block_address = htonl(blocknum);
241
-	rb.block_count = htons(count);
242
-	
243
-	ret = scsi_command( sgd, (uint8_t *)&rb, sizeof(rb), SG_DXFER_FROM_DEV,  buffer, count * 512, sensedat, sizeof(sensedat));
244
-
245
-	if(ret<0) {
246
-		DPRINTF("ERROR: ll_read_block( %x, %x, %x, %x) = %d\n", sgd, buffer, blocknum, count, ret);
247
-		PrintSense(sensedat, 32);
248
-	}
249
-
250
-	return(ret);
251
-
252
-}
253
-
254
-int ll_write_block(devhandle sgd, char *buffer, int blocknum, int count)
255
-{
256
-	int ret;
257
-	ReadBlockCMD_t rb;
258
-	char sensedat[32];
259
-
260
-	memset(&rb,0,sizeof(rb));
261
-	rb.cmd = WRITE_10;
262
-	rb.block_address = htonl(blocknum);
263
-	rb.block_count = htons(count);
264
-	
265
-	ret = scsi_command( sgd, (uint8_t *)&rb, sizeof(rb), SG_DXFER_TO_DEV,  buffer, count * 512, sensedat, sizeof(sensedat));
266
-
267
-	return(ret);
268
-}
269
-
270
-typedef struct ReadLongCMD {
271
-	uchar cmd;
272
-
273
-	uchar reladdr:1;
274
-	uchar correct:1;
275
-	uchar reserved:5;
276
-
277
-	unsigned int block_address;
278
-	uchar reserved3;
279
-	
280
-	unsigned short length;
281
-
282
-	uchar control;
283
-} __attribute__ ((packed)) ReadLongCMD_t ;
284
-
285
-int ll_read_long(devhandle sgd, char *buffer, int blocknum, int size)
286
-{
287
-	int ret;
288
-	ReadLongCMD_t rb;
289
-	char sensedat[32];
290
-
291
-	memset(&rb,0,sizeof(rb));
292
-	rb.cmd = READ_LONG;
293
-	rb.block_address = htonl(blocknum);
294
-	rb.length = htons(size);
295
-	
296
-	ret = scsi_command( sgd, (uint8_t *)&rb, sizeof(rb), SG_DXFER_FROM_DEV,  buffer, size, sensedat, sizeof(sensedat));
297
-	return(ret);
298
-}
299
-
300
-unsigned char ReadCapacityCMD[10] = { READ_CAPACITY, 0, 0,0,0,0, 0,0,0, 0};
301
-
302
-struct ReadCapacityResponse {
303
-	unsigned int block_address;
304
-	unsigned int block_length;
305
-};
306
-
307
-int get_capacity(devhandle sgd, unsigned long *block_count, unsigned int *blk_len)
308
-{
309
-	int ret;
310
-	struct ReadCapacityResponse response;
311
-	char sensedat[32];
312
-
313
-	ret = scsi_command(sgd, ReadCapacityCMD, sizeof(ReadCapacityCMD), SG_DXFER_FROM_DEV, (uint8_t *)&response, sizeof(response), sensedat, sizeof(sensedat) );
314
-	if(ret<0) {
315
-		DPRINTF("ERROR:get capacity: %d\n", ret);
316
-		PrintSense(sensedat,32);
317
-	}
318
-
319
-
320
-	*block_count = ntohl(response.block_address) +1;
321
-	*blk_len = ntohl(response.block_length);
322
-
323
-	return(ret);
324
-}
325
-
326
-#define INQ_REP_LEN 96
327
-unsigned char InquiryCMD[6] = { INQUIRY, 0, 0, 0, INQ_REP_LEN, 0};
328
-
329
-int query(devhandle sgd, query_response_t *qr)
330
-{
331
-	int ret;
332
-	char sensedat[32];
333
-
334
-	ret = scsi_command(sgd, InquiryCMD, sizeof(InquiryCMD), SG_DXFER_FROM_DEV, (uint8_t *)qr, sizeof(query_response_t), sensedat, sizeof(sensedat) );
335
-
336
-	if(ret<0){
337
-		DPRINTF("query: IOCTL");
338
-	}
339
-
340
-	return(ret);
341
-}
342
-
343
-typedef struct lun_list {
344
-	unsigned int list_length;
345
-	unsigned int reserved;
346
-	unsigned long long lun[16];
347
-} lun_list_t;
348
-
349
-#define REPORT_LUNS 0xa0
350
-unsigned char ReportLunsCMD[12] = { REPORT_LUNS, 0, 2, 0, 0, 0, 0, 0, 0, 128, 0, 0 };
351
-
352
-int ReportLUNS(devhandle sgd, lun_list_t *list)
353
-{
354
-	int ret;
355
-	char sensedat[32];
356
-
357
-	memset (list, 0, sizeof(lun_list_t));
358
-	ret = scsi_command(sgd, ReportLunsCMD, sizeof(ReportLunsCMD), SG_DXFER_FROM_DEV, (uint8_t *)list, sizeof(lun_list_t), sensedat, sizeof(sensedat) );
359
-
360
-	if(ret<0) {
361
-		DPRINTF("Report Luns: IOCTL");
362
-	}
363
-
364
-	list->list_length = ntohl(list->list_length);
365
-
366
-	return(ret);
367
-}
368
-
369
-typedef struct command_descriptor {
370
-	uchar opcode;
371
-	uchar reserved;
372
-	unsigned short service_action;
373
-	uchar reserved2;
374
-
375
-	uchar action_valid:1;
376
-	uchar reserved3:7;
377
-
378
-	unsigned short cdb_len;
379
-} __attribute__ ((packed)) command_descriptor_t;
380
-
381
-typedef struct report_opcodes_result {
382
-	unsigned long length;
383
-
384
-	command_descriptor_t command[256];
385
-} __attribute__ ((packed)) report_opcode_result_t;
386
-
387
-
388
-#define REPORT_OPCODES 0xa3
389
-
390
-typedef struct report_opcodes_cmd {
391
-	uchar cmd;
392
-	uchar reserved[5];
393
-	unsigned int reply_len;
394
-	uchar reserved2;
395
-	uchar control;
396
-} __attribute__ ((packed)) ReportOpcodesCMD_t;
397
-
398
-//ReportOpcodesCMD_t ReportOpcodesCMD = { cmd : REPORT_OPCODES, reply_len: htonl(sizeof(report_opcode_result_t)) };
399
-
400
-int ReportOpCodes(devhandle sgd, report_opcode_result_t *list)
401
-{
402
-	int ret;
403
-	char sensedat[32];
404
-	ReportOpcodesCMD_t ReportOpcodesCMD;
405
-
406
-	memset (list, 0, sizeof(report_opcode_result_t));
407
-	ReportOpcodesCMD.cmd = REPORT_OPCODES;
408
-	ReportOpcodesCMD.reply_len = htonl( sizeof(report_opcode_result_t));
409
-
410
-	ret = scsi_command(sgd, (uint8_t *)&ReportOpcodesCMD, sizeof(ReportOpcodesCMD_t), SG_DXFER_FROM_DEV, (uint8_t *)list, sizeof(report_opcode_result_t), sensedat, sizeof(sensedat) );
411
-
412
-	if(ret<0) {
413
-		DPRINTF("Report Luns: IOCTL");
414
-	}
415
-
416
-	list->length = ntohl(list->length);
417
-
418
-	return(ret);
419
-}
420
-
421
-
422
-#define READ_ATTRIBUTE 0x8c
423
-#define VOLUME_LIST 2
424
-#define PARTITION_LIST 3
425
-
426
-typedef struct read_attribute_cmd {
427
-	uchar cmd;
428
-	
429
-	uchar action:5;
430
-	uchar res:3;
431
-
432
-	uchar restricted[3];
433
-
434
-	uchar volume;
435
-	uchar res2;
436
-	uchar partition;
437
-
438
-	ushort attribute;
439
-	unsigned int reply_len;
440
-	uchar res3;
441
-	uchar control;
442
-} __attribute__ ((packed)) ReadAttributeCMD_t;
443
-
444
-int CheckVolumes(devhandle sgd)
445
-{
446
-	int ret;
447
-	uchar reply[4];
448
-	uchar sensedat[32];
449
-	ReadAttributeCMD_t cmd;
450
-
451
-	memset(&cmd,0,sizeof(cmd));
452
-
453
-	cmd.cmd=READ_ATTRIBUTE;
454
-	cmd.action = VOLUME_LIST;
455
-	cmd.reply_len = htonl(4);
456
-
457
-	ret = scsi_command(sgd, (uint8_t *)&cmd, sizeof(cmd), SG_DXFER_FROM_DEV, reply, sizeof(reply), sensedat, sizeof(sensedat) );
458
-	if(ret<0) {
459
-		DPRINTF("Report Volumes: IOCTL");
460
-		return(-1);
461
-	}
462
-
463
-	if(! reply[0] && !reply[1])
464
-		return(0);
465
-
466
-	return(reply[3]);
467
-}
468
-
469
-int CheckPartitions(devhandle sgd)
470
-{
471
-	int ret;
472
-	uchar reply[4];
473
-	uchar sensedat[32];
474
-	ReadAttributeCMD_t cmd;
475
-
476
-	memset(&cmd,0,sizeof(cmd));
477
-
478
-	cmd.cmd=READ_ATTRIBUTE;
479
-	cmd.action = PARTITION_LIST;
480
-	cmd.reply_len = htonl(4);
481
-
482
-	ret = scsi_command(sgd, (uint8_t *)&cmd, sizeof(cmd), SG_DXFER_FROM_DEV, reply, sizeof(reply), sensedat, sizeof(sensedat) );
483
-	if(ret<0) {
484
-		DPRINTF("Report PARTITIONVolumes: IOCTL");
485
-		return(-1);
486
-	}
487
-
488
-	if(! reply[0] && !reply[1])
489
-		return(0);
490
-
491
-	return(reply[3]);
492
-}
493
-
494
-int UnitReady(devhandle sgd)
495
-{
496
-	uchar cmd[6];
497
-	uchar sensedat[32];
498
-	int ret;
499
-
500
-	memset(cmd,0,sizeof(cmd));
501
-	
502
-	ret = scsi_command(sgd, &cmd, sizeof(cmd), SG_DXFER_FROM_DEV, NULL, 0, sensedat, sizeof(sensedat) );
503
-	if(ret<0) {
504
-		DPRINTF("UnitReady :");
505
-		return(0);
506
-	}
507
-
508
-	return(1);
509
-}
510
-	
511
-
512
-#endif

+ 0
- 14
src/filo/usb/scsi_cmds.h Целия файл

@@ -1,14 +0,0 @@
1
-#ifndef _SCSI_CMDS_H
2
-#define _SCSI_CMDS_H
3
-
4
-#define devhandle uint8_t
5
-
6
-#define uchar uint8_t
7
-#define ushort uint16_t
8
-
9
-void PrintSense(uchar *sense, int len);
10
-int ll_read_block(devhandle sgd, char *buffer, int blocknum, int count);
11
-
12
-int get_capacity(devhandle sgd, unsigned long *block_count, unsigned int *blk_len);
13
-int UnitReady(uchar sgd);
14
-#endif

+ 0
- 1143
src/filo/usb/uhci.c
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 0
- 175
src/filo/usb/uhci.h Целия файл

@@ -1,175 +0,0 @@
1
-#ifndef _UHCI_H
2
-#define _UHCI_H
3
-
4
-/*
5
- * The link pointer is multi use. Some fields are valid only for some uses. 
6
- * In other cases, they must be 0
7
- *
8
- */
9
-
10
-#define MAX_POLLDEV 10
11
-
12
-#define MAX_TRANSACTIONS 10
13
-#define MAX_QUEUEHEAD 255
14
-#define MAX_TD 1024
15
-
16
-
17
-typedef struct link_pointer {
18
-        unsigned long terminate:1;
19
-        unsigned long queue:1;
20
-        unsigned long depth:1;
21
-        unsigned long reserved:1;
22
-        unsigned long link:28;
23
-} __attribute__((packed)) link_pointer_t;
24
-
25
-extern link_pointer_t *frame_list[];
26
-
27
-void init_framelist(uchar dev);
28
-
29
-
30
-#define SETUP_TOKEN 0x2d
31
-#define IN_TOKEN 0x69
32
-#define OUT_TOKEN 0xe1
33
-
34
-#define CTRL_RETRIES 3
35
-#define CONTROL_STS_RETRIES 0
36
-
37
-
38
-// some port features
39
-#define PORT_CONNECTION 0
40
-#define PORT_ENABLE 1
41
-#define PORT_SUSPEND 2
42
-#define PORT_OVER_CURRENT 3
43
-#define PORT_RESET 4
44
-#define PORT_POWER 8
45
-#define PORT_LOW_SPEED 9
46
-#define C_PORT_CONNECTION 16
47
-#define C_PORT_ENABLE 17
48
-#define C_PORT_SUSPEND 18
49
-#define C_PORT_OVER_CURRENT 19
50
-#define C_PORT_RESET 20
51
-
52
-// features
53
-#define FEATURE_HALT 0
54
-
55
-typedef struct td {
56
-	
57
-	link_pointer_t link;
58
-
59
-	unsigned long actual:11;	// actual length
60
-	unsigned long reserved2:5;
61
-
62
-// status/error flags
63
-	unsigned long res1:1;
64
-	unsigned long bitstuff:1;
65
-	unsigned long crc:1;
66
-	unsigned long nak:1;
67
-	unsigned long babble:1;
68
-	unsigned long buffer_error:1;
69
-	unsigned long stall:1;
70
-	unsigned long active:1;
71
-
72
-	unsigned long interrupt:1;	// interrupt on complete
73
-	unsigned long isochronous:1;
74
-	unsigned long lowspeed:1;
75
-	unsigned long retrys:2;
76
-	unsigned long detect_short:1;
77
-	unsigned long reserved3:2;
78
-
79
-	unsigned long packet_type:8;	// one of in (0x69), out (0xe1) or setup (0x2d)
80
-	unsigned long device_addr:7;
81
-	unsigned long endpoint:4;
82
-	unsigned long data_toggle:1;
83
-	unsigned long reserved:1;
84
-	unsigned long max_transfer:11;	// misnamed. Desired length might be better
85
-
86
-	void *buffer;
87
-	unsigned long data[4];	// free use by driver
88
-} __attribute__((packed)) td_t;
89
-
90
-typedef struct queue_head {
91
-	link_pointer_t bredth;	// depth must = 0
92
-	link_pointer_t depth;	// depth may vary randomly, ignore
93
-	unsigned long int udata[2];
94
-} __attribute__((packed)) queue_head_t;
95
-
96
-typedef struct transaction {
97
-	queue_head_t	*qh;
98
-	td_t		*td_list;
99
-	struct transaction *next;
100
-} transaction_t;
101
-
102
-//#####################################################
103
-int wait_head( queue_head_t *head, int count);
104
-
105
-extern queue_head_t *free_qh;
106
-extern queue_head_t *queue_heads;
107
-
108
-queue_head_t *new_queue_head(void);
109
-void free_queue_head( queue_head_t *qh);
110
-void init_qh(void);
111
-
112
-extern td_t *free_td_list;
113
-extern td_t *tds;
114
-
115
-void init_td(void);
116
-td_t *new_td(void);
117
-td_t *find_last_td(td_t *td);
118
-void free_td( td_t *td);
119
-link_pointer_t *queue_end( queue_head_t *queue);
120
-void add_td( queue_head_t *head, td_t *td);
121
-
122
-extern transaction_t transactions[MAX_TRANSACTIONS];
123
-extern transaction_t *free_transactions;
124
-
125
-void init_transactions(void);
126
-void free_transaction( transaction_t *trans );
127
-transaction_t *new_transaction(td_t *td);
128
-transaction_t *add_transaction( transaction_t *trans, td_t *td);
129
-
130
-
131
-#define USBCMD(x) hc_base[x]
132
-#define USBSTS(x) (hc_base[x] + 0x02)
133
-#define USBINTR(x) (hc_base[x] + 0x04)
134
-#define FRNUM(x) ( hc_base[x] + 0x06)
135
-#define FLBASE(x) ( hc_base[x] + 0x08)
136
-#define SOFMOD(x) ( hc_base[x] + 0x0c)
137
-#define PORTSC1(x) ( hc_base[x] + 0x10)
138
-#define PORTSC2(x) ( hc_base[x] + 0x12)
139
-
140
-#define USBCMDRUN 0x01
141
-#define USBCMD_DEBUG 0x20
142
-
143
-#define USBSTSHALTED 0x20
144
-
145
-
146
-void hc_reset(uchar dev);
147
-int hc_stop(void);
148
-int hc_start(uchar dev);
149
-
150
-extern queue_head_t *sched_queue[];
151
-
152
-void init_sched(uchar dev);
153
-int poll_queue_head( queue_head_t *qh);
154
-int wait_queue_complete( queue_head_t *qh);
155
-
156
-extern int num_polls;
157
-extern int (*devpoll[MAX_POLLDEV])(uchar);
158
-extern uchar parm[MAX_POLLDEV];
159
-
160
-transaction_t *_bulk_transfer( uchar devnum, uchar ep, unsigned int len, uchar *data);
161
-transaction_t *ctrl_msg(uchar devnum, uchar request_type, uchar request, unsigned short wValue, unsigned short wIndex, unsigned short wLength, uchar *data);
162
-int schedule_transaction( uchar dev, transaction_t *trans);
163
-int wait_transaction( transaction_t *trans);
164
-void unlink_transaction( uchar dev, transaction_t *trans);
165
-int uhci_bulk_transfer( uchar devnum, uchar ep, unsigned int len, uchar *data);
166
-int uhci_control_msg( uchar devnum, uchar request_type, uchar request, unsigned short wValue, unsigned short wIndex, unsigned short wLength, void *data);
167
-
168
-
169
-// defined in uhci.c
170
-int uhc_init(struct pci_device *dev);
171
-void uhci_init(void);
172
-void clear_uport_stat(unsigned short port);
173
-int poll_u_root_hub(unsigned short port, uchar controller);
174
-
175
-#endif

+ 0
- 803
src/filo/usb/usb.c Целия файл

@@ -1,803 +0,0 @@
1
-#ifdef USB_DISK
2
-
3
-/*******************************************************************************
4
- *
5
- *
6
- *	Copyright 2003 Steven James <pyro@linuxlabs.com> and
7
- *	LinuxLabs http://www.linuxlabs.com
8
- *
9
- *	This program is free software; you can redistribute it and/or modify
10
- *	it under the terms of the GNU General Public License as published by
11
- *	the Free Software Foundation; either version 2 of the License, or
12
- *	(at your option) any later version.
13
- *
14
- *	This program is distributed in the hope that it will be useful,
15
- *	but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- *	GNU General Public License for more details.
18
- *
19
- *	You should have received a copy of the GNU General Public License
20
- *	along with this program; if not, write to the Free Software
21
- *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
- *
23
- ******************************************************************************/
24
-
25
-#include <etherboot.h>
26
-#include <pci.h>
27
-#include <timer.h>
28
-#include <lib.h>
29
-        
30
-#define DEBUG_THIS DEBUG_USB
31
-#include <debug.h>
32
-
33
-#define DPRINTF debug
34
-
35
-
36
-#include "usb.h"
37
-#include "uhci.h"
38
-#include "ohci.h"
39
-#include "debug_x.h"
40
-
41
-
42
-#define ALLOCATE 1
43
-
44
-int usec_offset=0;
45
-
46
-int num_controllers=0;
47
-
48
-uint32_t hc_base[MAX_CONTROLLERS];
49
-uint8_t  hc_type[MAX_CONTROLLERS];
50
-
51
-
52
-void hci_init(void)
53
-{
54
-	int i;
55
-	struct pci_device *dev;
56
-	uint8_t prog_if;
57
-
58
-
59
-	for(i=0;i<MAX_CONTROLLERS; i++) {
60
-		hc_type[i] = 0xff;
61
-	}
62
-
63
-        /* Find a PCI_SERIAL_USB class device */
64
-	i=0;
65
-	num_controllers = 0;
66
-	while(num_controllers<MAX_CONTROLLERS) {
67
-	        dev = pci_find_device(-1, -1, 0x0c03, -1, i);
68
-		if(!dev) break;
69
-		
70
-		prog_if = ((dev->class>>8) & 0xff);
71
-		if(prog_if == 0x00 ) { // UHCI
72
-			hc_type[num_controllers] = prog_if;
73
-			uhc_init(dev);
74
-		}
75
-		else if(prog_if == 0x10) { // OHCI
76
-			hc_type[num_controllers] = prog_if;
77
-			ohc_init(dev);
78
-		}
79
-#if 0 
80
-		else if(prog_if == 0x20) { // EHCI
81
-			hc_type[num_controllers] = prog_if;
82
-			ehc_init(dev);
83
-		}
84
-#endif
85
-		i++;
86
-	}
87
-	// From now should not change num_controllers any more
88
-	
89
-	uhci_init();
90
-	ohci_init();
91
-}
92
-
93
-
94
-int next_usb_dev;
95
-usbdev_t usb_device[MAX_USB_DEV];
96
-
97
-void init_devices(void) 
98
-{
99
-
100
-	memset(usb_device,0,sizeof(usb_device));
101
-	usb_device[0].max_packet[0] = 8;
102
-	next_usb_dev=2; // 0 for all controller root hub, use MAX_CONTROLLERS instead??? 
103
-			// do we need have one for every controller ?? or just use hc_base and hc_type instead
104
-			// For example 0 --> controller 1 root hub
105
-			// 	       1 --> controller 2 root hub
106
-			//	       2 --> controller 3 root hub....
107
-}
108
-
109
-
110
-inline int set_address( uchar address)
111
-{
112
-	int ret;
113
-
114
-	ret = usb_control_msg(0, 0, SET_ADDRESS, address, 0, 0, NULL);
115
-
116
-	return(ret);
117
-}
118
-
119
-inline int clear_stall(uchar device, uchar endpoint)
120
-{
121
-	int ret;
122
-
123
-	ret = usb_control_msg(device, CONTROL_ENDPOINT, CLEAR_FEATURE, FEATURE_HALT, endpoint, 0, NULL);
124
-	if(hc_type[device]==0x00) {
125
-		usb_device[device].toggle[endpoint]=0;
126
-	}
127
-	else if(hc_type[device]==0x10) {
128
-		usb_settoggle(&usb_device[device], endpoint & 0xf, ((endpoint & 0x80)>>7)^1, 0);
129
-	}
130
-
131
-	return(ret);
132
-}
133
-
134
-inline int device_reset(uchar device) {
135
-	return usb_control_msg(device, 0x21, 0xff, 0, 0, 0, NULL);
136
-}
137
-
138
-///////////////////////////////////////////////////////////////////////////////////////
139
-//
140
-//	String Descriptors
141
-//
142
-//////////////////////////////////////////////////////////////////////////////////////
143
-
144
-#define STRING_DESCRIPTOR 0x0300
145
-
146
-int get_string( uchar addr, uchar string, int len, uchar *buffer)
147
-{
148
-	int ret;
149
-	int i,j;
150
-	int real_len;
151
-	ushort lang;
152
-
153
-	if(!string) {
154
-		strcpy(buffer, "unknown");
155
-		return(0);
156
-	}
157
-
158
-	ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, STRING_DESCRIPTOR | string, 0, 4, buffer);
159
-	real_len = buffer[0];
160
-	if(real_len>len)
161
-		real_len = len;
162
-
163
-	lang = buffer[2] | buffer[3]<<8;
164
-	ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, STRING_DESCRIPTOR | string, lang, real_len, buffer);
165
-
166
-	// de-unicode it!
167
-	for(i=0, j=2; j<real_len; i++, j+=2)
168
-		buffer[i] = buffer[j];
169
-
170
-	buffer[i]=0;
171
-	real_len/=2;
172
-
173
-	return(real_len);
174
-}
175
-
176
-int get_string2( uchar addr, uchar string, ushort lang, int len, uchar *buffer)
177
-{
178
-        int ret;
179
-        int i,j;
180
-        int real_len;
181
-
182
-
183
-        ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, STRING_DESCRIPTOR | string, lang, len, buffer);
184
-
185
-        real_len = buffer[0];
186
-        if(real_len>len)
187
-                real_len = len;
188
-
189
-	if(real_len<=4)  {
190
-		strcpy(buffer, "USB");
191
-		real_len = 3;
192
-		buffer[real_len] = 0;
193
-	} else {
194
-        	// de-unicode it!
195
-        	for(i=0, j=2; j<real_len; i++, j+=2)
196
-                	buffer[i] = buffer[j];
197
-
198
-        	buffer[i]=0;
199
-        	real_len/=2;
200
-	}
201
-
202
-        return(real_len);
203
-}
204
-ushort get_lang( uchar addr, uchar string, int len, uchar *buffer)
205
-{
206
-        int ret;
207
-        int i,j;
208
-        int real_len;
209
-	ushort lang;
210
-        
211
-        ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, STRING_DESCRIPTOR | string, 0, 4, buffer);
212
-	lang = buffer[2] | buffer[3]<<8;
213
-
214
-        return lang;
215
-}       
216
-
217
-///////////////////////////////////////////////////////////////////////////////////////
218
-//
219
-// HUB functions. This will be moved to it's own module soonishly
220
-//
221
-///////////////////////////////////////////////////////////////////////////////////////
222
-
223
-typedef struct port_charge {
224
-	ushort c_port_connection:1;
225
-	ushort c_port_enable:1;
226
-	ushort c_port_suspend:1;
227
-	ushort c_port_over_current:1;
228
-	ushort c_port_reset:1;
229
-	ushort reserved:11;
230
-} port_change_t;
231
-
232
-typedef struct port_status {
233
-	ushort port_connection:1;
234
-	ushort port_enable:1;
235
-	ushort port_suspend:1;
236
-	ushort port_over_current:1;
237
-	ushort port_reset:1;
238
-	ushort reserved:3;
239
-	ushort port_power:1;
240
-	ushort port_lowspeed:1;
241
-	ushort port_highspeed:1;
242
-	ushort port_test:1;
243
-	ushort port_indicator:1;
244
-} __attribute__ ((packed)) portstatus_t;
245
-
246
-
247
-typedef struct portstat {
248
-	portstatus_t  stat;
249
-	port_change_t change;
250
-} __attribute__ ((packed)) portstat_t;
251
-
252
-int hub_port_reset( uchar addr, uchar port)
253
-{
254
-	int ret;
255
-	int tries=100;
256
-	portstat_t status;
257
-
258
-	ret = usb_control_msg(addr, 0x23, SET_FEATURE, PORT_RESET, port, 0, NULL);	// reset port
259
-
260
-	while(tries--) {
261
-		udelay(10000);
262
-		ret = usb_control_msg(addr, 0xa3, GET_STATUS, 0x0, port, 4, &status);
263
-		if(!status.change.c_port_reset)
264
-			continue;
265
-
266
-		ret = usb_control_msg(addr, 0x23, CLEAR_FEATURE, C_PORT_RESET, port, 0, NULL);	// clear status
267
-		return(0);
268
-	}
269
-
270
-	DPRINTF("hub_port_reset(%x, %x) failed,\n", addr, port);
271
-	dump_hex((uint8_t *)&status, 4, "status=");
272
-
273
-	return(-1);
274
-}
275
-
276
-int hub_port_resume( uchar addr, uchar port)
277
-{
278
-	int ret;
279
-	int tries=100;
280
-	portstat_t status;
281
-
282
-	ret = usb_control_msg(addr, 0x23, CLEAR_FEATURE, PORT_SUSPEND, port, 0, NULL);	// reset port
283
-
284
-	while(tries--) {
285
-		udelay(10000);
286
-		ret = usb_control_msg(addr, 0xa3, GET_STATUS, 0x0, port, 4, &status);
287
-		if(!status.change.c_port_suspend)
288
-			continue;
289
-
290
-		ret = usb_control_msg(addr, 0x23, CLEAR_FEATURE, C_PORT_SUSPEND, port, 0, NULL);	// clear status
291
-		return(0);
292
-	}
293
-
294
-	return(-1);
295
-}
296
-
297
-int poll_hub(uchar addr)
298
-{
299
-	int i;
300
-	int ret;
301
-	uchar devaddr=0;
302
-	hub_descriptor_t *desc;
303
-	portstat_t status;
304
-
305
-	DPRINTF("Poll hub (%x)\n", addr);
306
-	desc = usb_device[addr].private;
307
-
308
-	for(i=1; i<= desc->bNbrPorts; i++) {
309
-		ret = usb_control_msg(addr, 0xa3, GET_STATUS, 0x0, i, 4, &status);
310
-//		DPRINTF("Get status for port %u returns: %d\n", i, ret);
311
-//		dump_hex(&status, 4, "status=");	
312
-
313
-		if(status.change.c_port_connection) {
314
-			ret = usb_control_msg(addr, 0x23, CLEAR_FEATURE, C_PORT_CONNECTION, i, 0, NULL);	// clear status
315
-
316
-			if(status.stat.port_connection) {
317
-				udelay(desc->bPwrOn2PwrGood * 20000);
318
-
319
-				hub_port_resume(addr, i);
320
-
321
-				ret = hub_port_reset(addr,i);
322
-				udelay(10);
323
-				ret = usb_control_msg(addr, 0x23, SET_FEATURE, PORT_ENABLE, i, 0, NULL);	// enable port
324
-
325
-//		ret = usb_control_msg(addr, 0xa3, GET_STATUS, 0x0, i, 4, &status);
326
-//		DPRINTF("*****Get status again  for port %u returns: %d\n", i, ret);
327
-//		dump_hex(&status, 4, "status=");	
328
-
329
-				devaddr = configure_device(i, usb_device[addr].controller, status.stat.port_lowspeed);
330
-
331
-				// configure
332
-			} else {
333
-				ret = usb_control_msg(addr, 0x23, SET_FEATURE, PORT_SUSPEND, i, 0, NULL);	// suspend port
334
-				ret = usb_control_msg(addr, 0x23, CLEAR_FEATURE, PORT_ENABLE, i, 0, NULL);	// disable port
335
-				DPRINTF("Hub %d, Port %04x disconnected\n", addr, i);
336
-				// deconfigure
337
-			}
338
-		}
339
-	}
340
-	return(devaddr);
341
-
342
-}
343
-
344
-int usb_hub_init( uchar addr) 
345
-{
346
-	int i;
347
-	int ret;
348
-	hub_descriptor_t *desc;
349
-
350
-	desc = allot(sizeof(hub_descriptor_t));
351
-
352
-	memset(desc, 0 , sizeof(hub_descriptor_t));
353
-
354
-	DPRINTF("hub init (%d)\n", addr);
355
-
356
-	ret = usb_control_msg(addr, 0xa0, GET_DESCRIPTOR, 0x2900, 0, 8, desc);
357
-	ret = usb_control_msg(addr, 0xa0, GET_DESCRIPTOR, 0x2900, 0, desc->bLength, desc);
358
-
359
-	usb_device[addr].private = desc;
360
-
361
-	for(i=1; i<=desc->bNbrPorts; i++)
362
-		ret = usb_control_msg(addr, 0x23, SET_FEATURE, PORT_POWER, i, 0, NULL);	// power port
363
-
364
-
365
-	// register hub to be polled
366
-
367
-	devpoll[num_polls] = poll_hub;
368
-	parm[num_polls++] = addr;
369
-
370
-	return(0);
371
-}
372
-
373
-extern void ohci_dump_x(uchar controller);
374
-
375
-// will set up whatever device is answering at address 0.
376
-int configure_device(uint32_t port, uchar controller, unsigned int lowspeed)
377
-{
378
-	device_descriptor_t *desc;
379
-	config_descriptor_t *conf;
380
-	interface_descriptor_t *iface;
381
-	endpoint_descriptor_t *epd;
382
-	int ret;
383
-	int i;
384
-	int addr = next_usb_dev++;
385
-	uchar buffer[512];
386
-	uchar string[255];
387
-	ushort lang;
388
-	uchar x[2];
389
-
390
-	desc = (device_descriptor_t *) buffer;
391
-
392
-	memset( &usb_device[addr], 0, sizeof(usbdev_t));
393
-
394
-	printf("New USB device, setting address %d\n", addr);
395
-	if(lowspeed) {
396
-		usb_device[addr].lowspeed = usb_device[0].lowspeed = 1;
397
-		DPRINTF("LOWSPEED\n");
398
-	} else
399
-		usb_device[addr].lowspeed = usb_device[0].lowspeed = 0;
400
-
401
-	usb_device[0].port = usb_device[addr].port = port;
402
-	usb_device[0].controller = usb_device[addr].controller = controller;
403
-	usb_device[addr].toggle2[0]=0;
404
-	usb_device[addr].toggle2[1]=0;
405
-
406
-//	hc_clear_stat();
407
-
408
-	ret = set_address(addr);
409
-	if(ret<0) {
410
-		DPRINTF("configure_device: set_address failed!\n");
411
-		next_usb_dev--;
412
-		return(-1);
413
-	}
414
-
415
-	mdelay(10);   /* Let the SET_ADDRESS settle */
416
-		
417
-	usb_device[addr].max_packet[0] = 8;
418
-	
419
-
420
-	DPRINTF("Fetching device descriptor length\n");
421
-	ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, 0x100, 0, 8, desc);
422
-
423
-	usb_device[addr].max_packet[0] = desc->max_packet;
424
-
425
-	DPRINTF("Fetching device descriptor\n");
426
-	ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, 0x100, 0, desc->bLength, desc);
427
-	if(ret < desc->bLength)
428
-		return(-1);
429
-
430
-	DPRINTF("Fetching config descriptor length\n");
431
-	conf = (config_descriptor_t *) (buffer + sizeof(device_descriptor_t));
432
-
433
-	ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, 0x200, 0, 8, conf);
434
-
435
-	DPRINTF("Fetching config descriptor\n");
436
-	ret = usb_control_msg(addr, 0x80, GET_DESCRIPTOR, 0x200, 0, conf->wTotalLength, conf);
437
-	if(ret < conf->wTotalLength)
438
-		return(-1);
439
-
440
-	iface = (interface_descriptor_t *) (buffer + sizeof(device_descriptor_t) + conf->bLength);
441
-	epd = (endpoint_descriptor_t *) (buffer + conf->bLength + iface->bLength + sizeof(device_descriptor_t));
442
-
443
-	DPRINTF("device:\n");
444
-	dump_device_descriptor( desc, "");
445
-	DPRINTF("config:\n");
446
-	dump_config_descriptor( (uchar *)conf, "");
447
-
448
-	DPRINTF("Selecting Configuration number %x:\n", conf->bConfigurationValue);
449
-	ret = usb_control_msg(addr, 0, SET_CONFIGURATION, conf->bConfigurationValue, 0, 0, NULL);
450
-	
451
-//	mdelay(20);
452
-
453
-#if 0
454
-	usb_control_msg(addr, 0x80,    GET_CONFIGURATION, 0, 0, 1 , x);
455
-	DPRINTF("Configuration number = %x\n", x[0]);
456
-
457
-        usb_control_msg(addr, 0x80, GET_STATUS, 0, addr, 2, x);
458
-        DPRINTF("status = %x %x\n", x[0], x[1]);
459
-
460
-        usb_control_msg(addr, 0x81, GET_STATUS, 0, 0, 2, x);
461
-        DPRINTF("status = %x %x\n", x[0], x[1]);
462
-#endif
463
-
464
-	for(i=0; i<iface->bNumEndpoints;i++) {
465
-		if(!epd[i].bEndpointAddress) {
466
-			usb_device[addr].max_packet[ 1 ] = epd[i].wMaxPacketSize & 0x3ff;
467
-		} else {
468
-			usb_device[addr].max_packet[ epd[i].bEndpointAddress & 0x7f ] = epd[i].wMaxPacketSize & 0x3ff;
469
-		}
470
-
471
-		if( (epd[i].bmAttributes & 0x03) == 0x01) // interrupt
472
-			usb_device[addr].interrupt = epd[i].bEndpointAddress;
473
-
474
-		if( (epd[i].bmAttributes & 0x03) == 0x02) { // bulk
475
-#if 0
476
-			DPRINTF("clear stall on ep=%x\n", epd[i].bEndpointAddress);
477
-			clear_stall(addr, epd[i].bEndpointAddress);	// to reset data toggle
478
-			udelay(10);
479
-#endif
480
-
481
-#if 0
482
-			usb_control_msg(addr, 0x82, GET_STATUS, 0, epd[i].bEndpointAddress, 2, x);
483
-			DPRINTF("status = %x %x\n", x[0], x[1]);
484
-#endif
485
-
486
-			if(epd[i].bEndpointAddress & 0x80){  //in
487
-				usb_device[addr].bulk_in = epd[i].bEndpointAddress; 
488
-			}
489
-			else { //out
490
-				usb_device[addr].bulk_out = epd[i].bEndpointAddress; 
491
-			}
492
-		}
493
-
494
-	}
495
-
496
-	// determine device class
497
-	if(desc->Class) {
498
-		usb_device[addr].class = desc->Class;
499
-		usb_device[addr].subclass = desc->SubClass;
500
-		usb_device[addr].protocol = desc->protocol;
501
-	} else {
502
-		usb_device[addr].class = iface->bInterfaceClass;
503
-		usb_device[addr].subclass = iface->bInterfaceSubClass;
504
-		usb_device[addr].protocol = iface->bInterfaceProtocol;
505
-	}
506
-
507
-	printf("%02x:%02x:%02x\n", usb_device[addr].class, usb_device[addr].subclass, usb_device[addr].protocol);
508
-#if 0
509
-	get_string(addr, desc->iManufacturor, sizeof(string), string);
510
-	printf("Manufacturor: %s\n", string);
511
-
512
-	get_string(addr, desc->iProduct, sizeof(string), string);
513
-	printf("Product: %s\n", string);
514
-
515
-	get_string(addr, desc->iSerial, sizeof(string), string);
516
-	printf("Serial: %s\n", string);
517
-#else	
518
-        lang = get_lang(addr, 0, sizeof(string), string);
519
-	
520
-	get_string2(addr, desc->iManufacturor, lang, sizeof(string), string);
521
-        printf("Manufacturor: %s\n", string);
522
-
523
-        get_string2(addr, desc->iProduct, lang,sizeof(string), string);
524
-        printf("Product: %s\n", string);
525
-
526
-        get_string2(addr, desc->iSerial, lang, sizeof(string), string);
527
-        printf("Serial: %s\n", string);
528
-#endif
529
-	
530
-	switch( usb_device[addr].class) {
531
-		case 0x09:	// hub
532
-			usb_hub_init(addr);
533
-			break;
534
-
535
-		default:
536
-			break;
537
-
538
-	}
539
-		
540
-	DPRINTF("DEVICE CONFIGURED\n");
541
-
542
-	return(addr);
543
-}
544
-
545
-int num_polls=0;
546
-int (*devpoll[MAX_POLLDEV])(uchar);
547
-uchar parm[MAX_POLLDEV];
548
-
549
-int poll_usb()
550
-{
551
-	int addr;
552
-	int found=0;
553
-	int i;
554
-	int j;
555
-
556
-	for(i=0; i<num_controllers; i++) {
557
-		debug("poll_usb1 i=%d\t", i);
558
-		// if addr >0, should probably see what was attached!
559
-		if(hc_type[i]==0x00) {
560
-			addr = poll_u_root_hub(PORTSC1(i), i);
561
-			if(addr && !found)
562
-				found=addr;
563
-
564
-			addr = poll_u_root_hub(PORTSC2(i), i);
565
-			if(addr && !found)
566
-				found=addr;
567
-		} 
568
-
569
-		else if(hc_type[i]==0x10) {
570
-			int NDP;
571
-			NDP = readl(&ohci_regs->roothub.a) & 0xff;
572
-			ohci_regs = (ohci_regs_t *)hc_base[i];
573
-			for(j=0;j<NDP;j++) { 
574
-	                        addr = poll_o_root_hub((uint32_t)&ohci_regs->roothub.portstatus[j], i);
575
-        	                if(addr && !found)
576
-                	                found=addr;
577
-			}
578
-			
579
-		}
580
-		
581
-	}
582
-
583
-	// now poll registered drivers (such as the hub driver
584
-	for(i=0;i<num_polls; i++) {
585
-		debug("poll_usb2 i=%d\t", i);
586
-		addr = devpoll[i](parm[i]);
587
-		if(addr && !found)
588
-			found=addr;
589
-	}
590
-
591
-	return(found);	
592
-}
593
-
594
-
595
-int usb_bulk_transfer( uchar devnum, uchar ep, unsigned int len, uchar *data)
596
-{
597
-	uint8_t hc_num = usb_device[devnum].controller;
598
-	if(ep&0x80) {
599
-		ep = usb_device[devnum].bulk_in;
600
-	} else {
601
-		ep = usb_device[devnum].bulk_out;
602
-	}
603
-	
604
-	if(hc_type[hc_num] == 0x00) { //UHCI
605
-		return uhci_bulk_transfer(devnum, ep, len, data);
606
-	} 
607
-	else if( hc_type[hc_num] == 0x10 ) {  //OHCI
608
-		return ohci_bulk_transfer(devnum, ep, len, data);
609
-	}
610
-#if 0 
611
-	else if (hc_type[hc_num] == 0x20 ) {  //EHCI
612
-		return ehci_bulk_transfer(devnum, ep, len, data);
613
-	}
614
-#endif
615
-	return 0;
616
-}
617
-int usb_control_msg( uchar devnum, uchar request_type, uchar request, unsigned short wValue, unsigned short wIndex, 
618
-	unsigned short wLength, void *data)
619
-{
620
-	
621
-	uint8_t hc_num = usb_device[devnum].controller;
622
-
623
-        if(hc_type[hc_num] == 0x00) { //UHCI
624
-                return uhci_control_msg(devnum, request_type, request, wValue, wIndex, wLength, data);
625
-        } 
626
-        else if( hc_type[hc_num] == 0x10 ) {  //OHCI
627
-                return ohci_control_msg(devnum, request_type, request, wValue, wIndex, wLength, data);
628
-        }
629
-#if 0 
630
-        else if (hc_type[hc_num] == 0x20 ) {  //EHCI
631
-                return ehci_control_msg(devnum, request_type, request, wValue, wIndex, wLength, data);
632
-        }
633
-#endif
634
-        return 0;	
635
-}
636
-
637
-
638
-struct urb *usb_alloc_urb(int controller)
639
-{
640
-        struct urb *urb;
641
-	ohci_t *ohci = NULL;
642
-#if URB_PRE_ALLOCATE!=1
643
-        urb = (struct urb *)allot2(sizeof(struct urb),0xff);
644
-        if (!urb) {
645
-                printf("usb_alloc_urb:  allot2 failed");
646
-                return NULL;
647
-        }
648
-#else 
649
-	if(hc_type[controller] == 0x10) { //OHCI
650
-		ohci = &_ohci_x[controller];
651
-		urb = ohci->urb;
652
-	} else {
653
-		urb = NULL;
654
-	}
655
-#endif
656
-
657
-        memset(urb, 0, sizeof(*urb));
658
-
659
-        return urb;
660
-}
661
-/**
662
- *      usb_free_urb - frees the memory used by a urb
663
- *      @urb: pointer to the urb to free
664
- *
665
- *      If an urb is created with a call to usb_create_urb() it should be
666
- *      cleaned up with a call to usb_free_urb() when the driver is finished
667
- *      with it.
668
- */
669
-void usb_free_urb(struct urb* urb)
670
-{
671
-#if URB_PRE_ALLOCATE!=1
672
-        if (urb)
673
-                forget2(urb);
674
-#endif
675
-}
676
-
677
-void usb_wait_urb_done(struct urb* urb, int timeout)
678
-{
679
-	usbdev_t *usb_dev = urb->dev;
680
-	if(hc_type[usb_dev->controller]==0x10) {
681
-		ohci_wait_urb_done(urb, timeout);
682
-	}
683
-	
684
-}
685
-
686
-
687
-int usb_submit_urb(struct urb *urb)
688
-{
689
-        if (urb && urb->dev) {
690
-#if 0
691
-		if(hc_type[urb->dev->controller] == 0x00) {
692
-                        return uhci_submit_urb(urb);
693
-                } else 
694
-#endif
695
-		if(hc_type[urb->dev->controller] == 0x10) {
696
-                	return ohci_submit_urb(urb);
697
-		} 
698
-#if 0
699
-		else if(hc_type[urb->dev->controller] == 0x20) {
700
-                        return ohci_submit_urb(urb);
701
-                }
702
-#endif
703
-		return 0;
704
-	}
705
-        else
706
-                return -ENODEV;
707
-}
708
-
709
-// Starts urb and waits for completion or timeout
710
-static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length)
711
-{ 
712
-        int status;
713
-        status = usb_submit_urb(urb);
714
-
715
-//for OHCI We will check the BLF and CLF, because HC after processing all td list, it will clear the BLF and CLF
716
-	usb_wait_urb_done(urb, timeout);
717
-//Add by LYH to call complete function
718
-	if(urb->complete!=0) urb->complete(urb);
719
-
720
-        if (actual_length)
721
-                *actual_length = urb->actual_length;
722
-
723
-        usb_free_urb(urb);
724
-        return status;
725
-}
726
-// returns status (negative) or length (positive)
727
-int usb_internal_control_msg(struct usbdev *usb_dev, unsigned int pipe,
728
-                            struct usb_ctrlrequest *cmd,  void *data, int len, int timeout, usb_complete_t complete)
729
-{
730
-        struct urb *urb;
731
-        int retv;
732
-        int length;
733
-
734
-        urb = usb_alloc_urb(usb_dev->controller);
735
-        if (!urb)
736
-                return -ENOMEM;
737
-
738
-        FILL_CONTROL_URB(urb, usb_dev, pipe, (unsigned char*)cmd, data, len,
739
-                   complete,0);
740
-
741
-        retv = usb_start_wait_urb(urb, timeout, &length);
742
-        if (retv < 0)
743
-                return retv;
744
-        else
745
-                return length;
746
-}
747
-int usb_control_msg_x(struct usbdev *dev, unsigned int pipe, u8 request, u8 requesttype,
748
-                         u16 value, u16 index, void *data, u16 size, int timeout, usb_complete_t complete)
749
-{
750
-        struct usb_ctrlrequest *dr;
751
-        int ret;
752
-	int controller = dev->controller;
753
-	ohci_t *ohci;
754
-
755
-#if URB_PRE_ALLOCATE!=1
756
-	dr = allot2(sizeof(struct usb_ctrlrequest), 0xf);
757
-        if (!dr) {
758
-		printf("usb_control_msg_x: dr allocate no MEM\n");
759
-                return -ENOMEM;
760
-	}
761
-#else
762
-        if(hc_type[controller] == 0x10) { //OHCI
763
-                ohci = &_ohci_x[controller];
764
-                dr = ohci->dr;
765
-        } else {
766
-		dr = NULL;
767
-	}
768
-	
769
-#endif
770
-
771
-        dr->bRequestType = requesttype;
772
-        dr->bRequest = request;
773
-        dr->wValue = cpu_to_le16p(&value);
774
-        dr->wIndex = cpu_to_le16p(&index);
775
-        dr->wLength = cpu_to_le16p(&size);
776
-
777
-        ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout, complete);
778
-
779
-#if URB_PRE_ALLOCATE!=1
780
-        forget2(dr);
781
-#endif
782
-
783
-        return ret;
784
-}
785
-int usb_bulk_msg_x(struct usbdev *usb_dev, unsigned int pipe,
786
-                        void *data, int len, int *actual_length, int timeout, usb_complete_t complete)
787
-{
788
-        struct urb *urb;
789
-
790
-        if (len < 0)
791
-                return -EINVAL;
792
-
793
-        urb=usb_alloc_urb(usb_dev->controller);
794
-        if (!urb)
795
-                return -ENOMEM;
796
-
797
-        FILL_BULK_URB(urb, usb_dev, pipe, data, len,
798
-                    complete, 0);
799
-
800
-        return usb_start_wait_urb(urb,timeout,actual_length);
801
-}
802
-
803
-#endif

+ 0
- 435
src/filo/usb/usb.h Целия файл

@@ -1,435 +0,0 @@
1
-#ifndef _USB_H
2
-#define _USB_H
3
-
4
-#define URB_PRE_ALLOCATE 1
5
-
6
-#define u32 uint32_t
7
-#define u16 uint16_t
8
-#define u8  uint8_t
9
-
10
-#define uchar uint8_t
11
-#define ushort uint16_t
12
-#define EBUSY  1
13
-#define ENOMEM 12
14
-#define ENODEV 19
15
-#define EINVAL 22
16
-#define EINPROGRESS 115
17
-
18
-#define LINK_ADDR(x) ( virt_to_bus(x) >> 4)
19
-#define MEM_ADDR(x) (void *) (  bus_to_virt( ((unsigned int) (x)) <<4) )
20
-
21
-#define MAX_CONTROLLERS 4
22
-
23
-extern int num_controllers;
24
-
25
-extern uint32_t hc_base[];
26
-extern uint8_t hc_type[];
27
-
28
-// Some control message bmRequestType defines
29
-#define CTRL_DEVICE 0
30
-#define CONTROL_INTERFACE 1
31
-#define CONTROL_ENDPOINT 2
32
-#define CONTROL_OTHER 3
33
-#define CONTROL_RECIPIENT_MASK 0x1f
34
-
35
-#define CONTROL_TYPE_STD 0
36
-#define CONTROL_TYPE_CLASS 0x20
37
-#define CONTROL_CLASS_VENDOR 0x40
38
-#define CONTROL_CLASS_MASK 0x60
39
-
40
-#define CONTROL_OUT 0
41
-#define CONTROL_IN 0x80
42
-#define CONTROL_DIR_MASK 0x80
43
-
44
-// bRequest values
45
-#define GET_STATUS 0
46
-#define CLEAR_FEATURE 1
47
-#define SET_FEATURE 3
48
-#define SET_ADDRESS 5
49
-
50
-#define GET_DESCRIPTOR 6
51
-#define SET_DESCRIPTOR 7
52
-
53
-#define GET_CONFIGURATION 8
54
-#define SET_CONFIGURATION 9
55
-
56
-#define GET_INTERFACE 10
57
-#define SET_INTERFACE 11
58
-
59
-#define SYNC_FRAME 12
60
-
61
-// descriptor types
62
-#define DEVICE_DESC 1
63
-#define CONFIGURATION_DESC 2
64
-#define STRING_DESC 3
65
-#define INTERFACE_DESC 4
66
-#define ENDPOINT_DESC 5
67
-#define OTHERSPEED_DESC 7
68
-#define POWER_DESC 8
69
-
70
-
71
-typedef struct device_descriptor {
72
-        uchar bLength;
73
-        uchar type;
74
-        
75
-        uchar bcdVersion[2];
76
-        uchar Class;
77
-        uchar SubClass;
78
-        uchar protocol;
79
-        uchar max_packet;
80
-        
81
-        unsigned short idVendor;
82
-        unsigned short idProduct;
83
-        
84
-        uchar bcdDevice[2];
85
-        uchar iManufacturor;
86
-        uchar iProduct;
87
-        uchar iSerial;
88
-        uchar bNumConfig;
89
-} __attribute__((packed)) device_descriptor_t;
90
-
91
-#define GET_DESCRIPTOR 6
92
-
93
-typedef struct config_descriptor {
94
-        uchar bLength;
95
-        uchar type;
96
-
97
-        unsigned short wTotalLength;
98
-        uchar bNumInterfaces;
99
-        uchar bConfigurationValue;
100
-        uchar iConfiguration;
101
-
102
-        uchar bmAttributes;
103
-        uchar bMaxPower;
104
-} __attribute__((packed)) config_descriptor_t;
105
-
106
-typedef struct interface_descriptor {
107
-        uchar bLength;
108
-        uchar type;
109
-
110
-        uchar bInterfaceNumber;
111
-        uchar bAlternateSetting;
112
-
113
-        uchar bNumEndpoints;
114
-        uchar bInterfaceClass;
115
-        uchar bInterfaceSubClass;
116
-        uchar bInterfaceProtocol;
117
-        uchar iInterface;
118
-} __attribute__((packed)) interface_descriptor_t;
119
-
120
-typedef struct endpoint_descriptor {
121
-        uchar bLength;
122
-        uchar type;
123
-
124
-        uchar bEndpointAddress;
125
-        uchar bmAttributes;
126
-        unsigned short wMaxPacketSize;
127
-        uchar bInterval;
128
-} __attribute__((packed)) endpoint_descriptor_t;
129
-
130
-typedef struct ctrl_msg {
131
-        uchar bmRequestType;
132
-        uchar bRequest;
133
-        unsigned short wValue;
134
-        unsigned short wIndex;
135
-        unsigned short wLength;
136
-} __attribute__((packed)) ctrl_msg_t;
137
-
138
-// Some descriptors for hubs, will be moved later
139
-typedef struct hub_descriptor {
140
-        uchar bLength;
141
-        uchar type;
142
-
143
-        uchar bNbrPorts;
144
-        ushort wHubCharacteristics;
145
-        uchar bPwrOn2PwrGood;
146
-        uchar bHubCntrCurrent;
147
-
148
-        uchar DeviceRemovable;  // assume bNbrPorts <=8
149
-        uchar PortPwrCntrMask;
150
-} __attribute__((packed)) hub_descriptor_t;
151
-
152
-#define MAX_USB_DEV 127
153
-#define MAX_EP 8
154
-        
155
-typedef struct usbdev {
156
-        uint32_t        port;
157
-        uchar           address;
158
-        uchar           controller;
159
-        uchar           class;
160
-        uchar           subclass;
161
-        uchar           protocol;
162
-        uchar           bulk_in;
163
-        uchar           bulk_out;
164
-        uchar           interrupt;
165
-        uchar           lowspeed;
166
-        uint32_t        toggle2[2]; //For OHCI
167
-	uint32_t	halted[2];
168
-	uchar		toggle[MAX_EP]; //for UHCI
169
-        unsigned short  max_packet[MAX_EP];
170
-        void            *private;
171
-} usbdev_t;
172
-
173
-// I will use urb as transaction for OHCI to remember the td and ed
174
-
175
-struct urb;
176
-typedef void (*usb_complete_t)(struct urb *);
177
-
178
-struct urb
179
-{
180
-#if 0
181
-        spinlock_t lock;                // lock for the URB
182
-#endif
183
-        void *hcpriv;                   // private data for host controller
184
-#if 0
185
-        struct list_head urb_list;      // list pointer to all active urbs 
186
-        struct urb *next;               // pointer to next URB  
187
-#endif
188
-        struct usbdev *dev;         // pointer to associated USB device
189
-        unsigned int pipe;              // pipe information
190
-        int status;                     // returned status
191
-        unsigned int transfer_flags;    // USB_DISABLE_SPD | USB_ISO_ASAP | etc.
192
-        void *transfer_buffer;          // associated data buffer
193
-        void *transfer_dma;        // dma addr for transfer_buffer
194
-        int transfer_buffer_length;     // data buffer length
195
-        int actual_length;              // actual data buffer length    
196
-        int bandwidth;                  // bandwidth for this transfer request (INT or ISO)
197
-        unsigned char *setup_packet;    // setup packet (control only)
198
-        void * setup_dma;           // dma addr for setup_packet
199
-        //
200
-        int start_frame;                // start frame (iso/irq only)
201
-        int number_of_packets;          // number of packets in this request (iso)
202
-        int interval;                   // polling interval (irq only)
203
-        int error_count;                // number of errors in this transfer (iso only)
204
-        int timeout;                    // timeout (in jiffies)
205
-        //
206
-        void *context;                  // context for completion routine
207
-        usb_complete_t complete;        // pointer to completion routine
208
-        //
209
-#if 0
210
-        struct iso_packet_descriptor iso_frame_desc[0];
211
-#endif
212
-};
213
-
214
-typedef struct urb urb_t;
215
-
216
-/*
217
- * urb->transfer_flags:
218
- */
219
-#define USB_DISABLE_SPD         0x0001
220
-#define URB_SHORT_NOT_OK        USB_DISABLE_SPD
221
-#define USB_ISO_ASAP            0x0002
222
-#define USB_ASYNC_UNLINK        0x0008
223
-#define USB_QUEUE_BULK          0x0010
224
-#define USB_NO_FSBR             0x0020
225
-#define USB_ZERO_PACKET         0x0040  // Finish bulk OUTs always with zero length packet
226
-#define URB_NO_INTERRUPT        0x0080  /* HINT: no non-error interrupt needed */
227
-                                        /* ... less overhead for QUEUE_BULK */
228
-#define USB_TIMEOUT_KILLED      0x1000  // only set by HCD!
229
-
230
-
231
-struct usb_ctrlrequest {
232
-        u8 bRequestType;
233
-        u8 bRequest;
234
-        u16 wValue;
235
-        u16 wIndex;
236
-        u16 wLength;
237
-} __attribute__ ((packed));
238
-
239
-/*
240
- * USB-status codes:
241
- * USB_ST* maps to -E* and should go away in the future
242
- */
243
-
244
-#define USB_ST_NOERROR          0
245
-#define USB_ST_CRC              (-EILSEQ)
246
-#define USB_ST_BITSTUFF         (-EPROTO)
247
-#define USB_ST_NORESPONSE       (-ETIMEDOUT)                    /* device not responding/handshaking */
248
-#define USB_ST_DATAOVERRUN      (-EOVERFLOW)
249
-#define USB_ST_DATAUNDERRUN     (-EREMOTEIO)
250
-#define USB_ST_BUFFEROVERRUN    (-ECOMM)
251
-#define USB_ST_BUFFERUNDERRUN   (-ENOSR)
252
-#define USB_ST_INTERNALERROR    (-EPROTO)                       /* unknown error */
253
-#define USB_ST_SHORT_PACKET     (-EREMOTEIO)
254
-#define USB_ST_PARTIAL_ERROR    (-EXDEV)                        /* ISO transfer only partially completed */
255
-#define USB_ST_URB_KILLED       (-ENOENT)                       /* URB canceled by user */
256
-#define USB_ST_URB_PENDING      (-EINPROGRESS)
257
-#define USB_ST_REMOVED          (-ENODEV)                       /* device not existing or removed */
258
-#define USB_ST_TIMEOUT          (-ETIMEDOUT)                    /* communication timed out, also in urb->status**/
259
-#define USB_ST_NOTSUPPORTED     (-ENOSYS)                       
260
-#define USB_ST_BANDWIDTH_ERROR  (-ENOSPC)                       /* too much bandwidth used */
261
-#define USB_ST_URB_INVALID_ERROR  (-EINVAL)                     /* invalid value/transfer type */
262
-#define USB_ST_URB_REQUEST_ERROR  (-ENXIO)                      /* invalid endpoint */
263
-#define USB_ST_STALL            (-EPIPE)                        /* pipe stalled, also in urb->status*/
264
-
265
-/**
266
- * FILL_CONTROL_URB - macro to help initialize a control urb
267
- * @URB: pointer to the urb to initialize.
268
- * @DEV: pointer to the struct usb_device for this urb.
269
- * @PIPE: the endpoint pipe
270
- * @SETUP_PACKET: pointer to the setup_packet buffer
271
- * @TRANSFER_BUFFER: pointer to the transfer buffer
272
- * @BUFFER_LENGTH: length of the transfer buffer
273
- * @COMPLETE: pointer to the usb_complete_t function
274
- * @CONTEXT: what to set the urb context to.
275
- *
276
- * Initializes a control urb with the proper information needed to submit
277
- * it to a device.  This macro is depreciated, the usb_fill_control_urb()
278
- * function should be used instead.
279
- */
280
-#define FILL_CONTROL_URB(URB,DEV,PIPE,SETUP_PACKET,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \
281
-    do {\
282
-        (URB)->dev=DEV;\
283
-        (URB)->pipe=PIPE;\
284
-        (URB)->setup_packet=SETUP_PACKET;\
285
-        (URB)->transfer_buffer=TRANSFER_BUFFER;\
286
-        (URB)->transfer_buffer_length=BUFFER_LENGTH;\
287
-        (URB)->complete=COMPLETE;\
288
-        (URB)->context=CONTEXT;\
289
-    } while (0)
290
-
291
-
292
-/**
293
- * FILL_BULK_URB - macro to help initialize a bulk urb
294
- * @URB: pointer to the urb to initialize.
295
- * @DEV: pointer to the struct usb_device for this urb.
296
- * @PIPE: the endpoint pipe
297
- * @TRANSFER_BUFFER: pointer to the transfer buffer
298
- * @BUFFER_LENGTH: length of the transfer buffer
299
- * @COMPLETE: pointer to the usb_complete_t function
300
- * @CONTEXT: what to set the urb context to.
301
- *
302
- * Initializes a bulk urb with the proper information needed to submit it
303
- * to a device.  This macro is depreciated, the usb_fill_bulk_urb()
304
- * function should be used instead.
305
- */
306
-#define FILL_BULK_URB(URB,DEV,PIPE,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \
307
-    do {\
308
-        (URB)->dev=DEV;\
309
-        (URB)->pipe=PIPE;\
310
-        (URB)->transfer_buffer=TRANSFER_BUFFER;\
311
-        (URB)->transfer_buffer_length=BUFFER_LENGTH;\
312
-        (URB)->complete=COMPLETE;\
313
-        (URB)->context=CONTEXT;\
314
-    } while (0)
315
-
316
-
317
-/*
318
- * USB directions
319
- */
320
-#define USB_DIR_OUT                     0               /* to device */
321
-#define USB_DIR_IN                      0x80            /* to host */
322
-
323
-/*
324
- * USB Packet IDs (PIDs)
325
- */
326
-#define USB_PID_UNDEF_0                 0xf0
327
-#define USB_PID_OUT                     0xe1
328
-#define USB_PID_ACK                     0xd2
329
-#define USB_PID_DATA0                   0xc3
330
-#define USB_PID_PING                    0xb4    /* USB 2.0 */
331
-#define USB_PID_SOF                     0xa5
332
-#define USB_PID_NYET                    0x96    /* USB 2.0 */
333
-#define USB_PID_DATA2                   0x87    /* USB 2.0 */
334
-#define USB_PID_SPLIT                   0x78    /* USB 2.0 */
335
-#define USB_PID_IN                      0x69
336
-#define USB_PID_NAK                     0x5a
337
-#define USB_PID_DATA1                   0x4b
338
-#define USB_PID_PREAMBLE                0x3c    /* Token mode */
339
-#define USB_PID_ERR                     0x3c    /* USB 2.0: handshake mode */
340
-#define USB_PID_SETUP                   0x2d
341
-#define USB_PID_STALL                   0x1e
342
-#define USB_PID_MDATA                   0x0f    /* USB 2.0 */
343
-
344
-#define PIPE_ISOCHRONOUS                0
345
-#define PIPE_INTERRUPT                  1
346
-#define PIPE_CONTROL                    2
347
-#define PIPE_BULK                       3
348
-
349
-#define usb_maxpacket(dev, pipe, out)   ((dev)->max_packet[usb_pipeendpoint(pipe)])
350
-#define usb_packetid(pipe)      (((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT)
351
-
352
-#define usb_pipeout(pipe)       ((((pipe) >> 7) & 1) ^ 1)
353
-#define usb_pipein(pipe)        (((pipe) >> 7) & 1)
354
-#define usb_pipedevice(pipe)    (((pipe) >> 8) & 0x7f)
355
-#define usb_pipe_endpdev(pipe)  (((pipe) >> 8) & 0x7ff)
356
-#define usb_pipeendpoint(pipe)  (((pipe) >> 15) & 0xf)
357
-#define usb_pipedata(pipe)      (((pipe) >> 19) & 1)
358
-#define usb_pipeslow(pipe)      (((pipe) >> 26) & 1)
359
-#define usb_pipetype(pipe)      (((pipe) >> 30) & 3)
360
-#define usb_pipeisoc(pipe)      (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
361
-#define usb_pipeint(pipe)       (usb_pipetype((pipe)) == PIPE_INTERRUPT)
362
-#define usb_pipecontrol(pipe)   (usb_pipetype((pipe)) == PIPE_CONTROL)
363
-#define usb_pipebulk(pipe)      (usb_pipetype((pipe)) == PIPE_BULK)
364
-
365
-#define PIPE_DEVEP_MASK         0x0007ff00
366
-
367
-
368
-/* The D0/D1 toggle bits */
369
-#define usb_gettoggle(dev, ep, out) (((dev)->toggle2[out] >> (ep)) & 1)
370
-#define usb_dotoggle(dev, ep, out)  ((dev)->toggle2[out] ^= (1 << (ep)))
371
-static inline void usb_settoggle(struct usbdev *dev,
372
-                                 unsigned int ep,
373
-                                 unsigned int out,
374
-                                 int bit)
375
-{
376
-        dev->toggle2[out] &= ~(1 << ep);
377
-        dev->toggle2[out] |= bit << ep;
378
-}
379
-
380
-
381
-/* Endpoint halt control/status */
382
-#define usb_endpoint_out(ep_dir)        (((ep_dir >> 7) & 1) ^ 1)
383
-#define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
384
-#define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
385
-#define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
386
-
387
-
388
-static inline unsigned int __create_pipe(usbdev_t *dev, unsigned int endpoint)
389
-{
390
-        return (dev->address << 8) | (endpoint << 15) |
391
-                ((dev->lowspeed == 1) << 26);
392
-}
393
-
394
-static inline unsigned int __default_pipe(struct usbdev *dev)
395
-{
396
-        return ((dev->lowspeed == 1) << 26);
397
-}
398
-
399
-/* Create various pipes... */
400
-#define usb_sndctrlpipe(dev,endpoint)   ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
401
-#define usb_rcvctrlpipe(dev,endpoint)   ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
402
-#if 0
403
-#define usb_sndisocpipe(dev,endpoint)   ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
404
-#define usb_rcvisocpipe(dev,endpoint)   ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
405
-#endif
406
-#define usb_sndbulkpipe(dev,endpoint)   ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
407
-#define usb_rcvbulkpipe(dev,endpoint)   ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
408
-#if 0
409
-#define usb_sndintpipe(dev,endpoint)    ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
410
-#define usb_rcvintpipe(dev,endpoint)    ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
411
-#endif
412
-#define usb_snddefctrl(dev)             ((PIPE_CONTROL << 30) | __default_pipe(dev))
413
-#define usb_rcvdefctrl(dev)             ((PIPE_CONTROL << 30) | __default_pipe(dev) | USB_DIR_IN)
414
-
415
-
416
-extern int next_usb_dev;
417
-usbdev_t usb_device[MAX_USB_DEV];
418
-
419
-void init_devices(void);
420
-void hci_init(void);
421
-int hc_init(struct pci_device *dev);
422
-inline int set_address(uchar address);
423
-inline int clear_stall(uchar device, uchar endpoint);
424
-int poll_usb();
425
-int configure_device(uint32_t  port, uchar controller, unsigned int lowspeed);
426
-int usb_bulk_transfer( uchar devnum, uchar ep, unsigned int len, uchar *data);
427
-int usb_control_msg( uchar devnum, uchar request_type, uchar request, unsigned short wValue, unsigned short wIndex,
428
-        unsigned short wLength, void *data);
429
-
430
-int usb_control_msg_x(struct usbdev *dev, unsigned int pipe, u8 request, u8 requesttype,
431
-                         u16 value, u16 index, void *data, u16 size, int timeout, usb_complete_t complete);
432
-int usb_bulk_msg_x(struct usbdev *usb_dev, unsigned int pipe,
433
-                        void *data, int len, int *actual_length, int timeout, usb_complete_t complete);
434
-
435
-#endif

+ 0
- 172
src/filo/usb/usb_scsi_low.c Целия файл

@@ -1,172 +0,0 @@
1
-#ifdef USB_DISK
2
-/*******************************************************************************
3
- *
4
- *
5
- *	Copyright 2003 Steven James <pyro@linuxlabs.com> and
6
- *	LinuxLabs http://www.linuxlabs.com
7
- *
8
- *	This program is free software; you can redistribute it and/or modify
9
- *	it under the terms of the GNU General Public License as published by
10
- *	the Free Software Foundation; either version 2 of the License, or
11
- *	(at your option) any later version.
12
- *
13
- *	This program is distributed in the hope that it will be useful,
14
- *	but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- *	GNU General Public License for more details.
17
- *
18
- *	You should have received a copy of the GNU General Public License
19
- *	along with this program; if not, write to the Free Software
20
- *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
- *
22
- ******************************************************************************/
23
-
24
-#include <etherboot.h>
25
-#include <pci.h>
26
-#include <timer.h>
27
-#include <lib.h>
28
-        
29
-#define DEBUG_THIS DEBUG_USB
30
-#include <debug.h>
31
-
32
-#define DPRINTF debug
33
-
34
-#define uchar uint8_t
35
-
36
-//#include "debug_x.h"
37
-#include "usb_scsi_low.h"
38
-
39
-int usb_bulk_transfer( uchar devnum, uchar ep, unsigned int len, uchar *data);
40
-
41
-#define SG_DXFER_FROM_DEV -3
42
-#define SG_DXFER_TO_DEV -2
43
-
44
-#define REQUEST_SENSE 0x03
45
-
46
-#define CBW_SIG 0x43425355
47
-
48
-typedef struct usb_cbw {
49
-	unsigned int 	signature;
50
-	unsigned int 	tag;
51
-	unsigned int 	transfer_len;	// this is exclusive of cbw and csw
52
-
53
-	uchar		res1:7;
54
-	uchar 		direction:1;	// 1 = device to host (read)
55
-	
56
-	uchar 		lun:4;
57
-	uchar		res:4;
58
-	
59
-	uchar		cbw_len:5;	// the length of the SCSI command
60
-	uchar		res3:3;
61
-
62
-	uchar		scsi_cmd[16];
63
-} __attribute__ ((packed)) usb_cbw_t;
64
-
65
-#define CSW_SIG 0x53425355
66
-
67
-typedef struct usb_csw {
68
-	unsigned int	signature;
69
-	unsigned int	tag;
70
-	unsigned int	residue;
71
-	uchar		status;
72
-} __attribute__ ((packed)) usb_csw_t;
73
-
74
-
75
-int scsi_command( uchar device, unsigned char *cmd, int cmd_len, int direction, unsigned char *data, int data_len, char *sense_data, int sense_len)
76
-{
77
-	usb_cbw_t cbw;
78
-	usb_csw_t csw;
79
-	int ret;
80
-
81
-	memset(&cbw,0,sizeof(usb_cbw_t));
82
-	memset(&csw,0,sizeof(usb_csw_t));
83
-
84
-	cbw.signature = CBW_SIG;
85
-	cbw.tag = 777;
86
-
87
-	memcpy(cbw.scsi_cmd, cmd, cmd_len);
88
-	cbw.cbw_len = cmd_len;
89
-
90
-	if(direction == SG_DXFER_FROM_DEV)
91
-		cbw.direction=1;
92
-
93
-	cbw.transfer_len = data_len;
94
-	
95
-	ret = usb_bulk_transfer(device, 2, sizeof(cbw), (uchar *) &cbw);
96
-	if(ret<0){
97
-		DPRINTF("ERROR:Bulk write:\n");
98
-	}
99
-
100
-	if(data_len) {
101
-		if(cbw.direction) {
102
-			DPRINTF("scsi_command reading %d bytes\n", data_len);
103
-			ret = usb_bulk_transfer(device, 0x81, data_len, data);
104
-			DPRINTF("scsi_command read %d bytes\n", ret);
105
-			if(ret<0 || ret <data_len) {
106
-				DPRINTF("ERROR:Bulk read data ret = %d\n", ret);
107
-			}
108
-		} else {
109
-//			DPRINTF("scsi_command writing %u bytes\n", data_len);
110
-			ret = usb_bulk_transfer(device, 0x2, data_len, data);
111
-//			DPRINTF("scsi_command wrote %u bytes\n", ret);
112
-			if(ret<0) {
113
-				DPRINTF("ERROR:Bulk write data\n");
114
-			}
115
-		}
116
-	}
117
-
118
-//	DPRINTF("scsi_command fetching csw\n");
119
-	ret = usb_bulk_transfer(device, 0x81, sizeof(csw), (uchar *) &csw);
120
-//	DPRINTF("scsi_command csw is %d bytes\n", ret);
121
-	if(ret<0 || ret < sizeof(csw)) {
122
-		DPRINTF("ERROR: Bulk read CSW ret = %d\n", ret);
123
-		return(-1);
124
-	}
125
-
126
-	if(csw.status) {
127
-		DPRINTF("CSW: residue = %08x, status = %02x\n", csw.residue, csw.status);
128
-		DPRINTF("Getting sense data\n");
129
-		request_sense( device, sense_data, sense_len);
130
-		return(-csw.status);
131
-	}
132
-
133
-	return(data_len - csw.residue);
134
-}
135
-
136
-int request_sense( uchar device, char *sense_data, int len)
137
-{
138
-	usb_cbw_t cbw;
139
-	usb_csw_t csw;
140
-	int ret;
141
-
142
-	memset(&cbw,0,sizeof(usb_cbw_t));
143
-	memset(&csw,0,sizeof(usb_csw_t));
144
-
145
-	cbw.signature = CBW_SIG;
146
-	cbw.tag = 666;
147
-
148
-	cbw.scsi_cmd[0] = REQUEST_SENSE;
149
-	cbw.scsi_cmd[4] = len;
150
-	cbw.cbw_len = 6;
151
-	cbw.direction=1;
152
-	cbw.transfer_len = len;
153
-
154
-	ret = usb_bulk_transfer(device, 2, sizeof(usb_cbw_t), (uchar *) &cbw);
155
-	if(ret<0 || ret < sizeof(usb_cbw_t)) {
156
-		DPRINTF("ERROR: sense Bulk write ret = %d\n", ret);
157
-	}
158
-
159
-	ret = usb_bulk_transfer(device, 0x81, len, sense_data);
160
-	if(ret<0 || ret < len) {
161
-		DPRINTF("ERROR: sense Bulk read data ret = %d\n", ret);
162
-	}
163
-
164
-	ret = usb_bulk_transfer(device, 0x81, sizeof(usb_csw_t), (uchar *) &csw);
165
-	if(ret<0 || ret < sizeof(usb_csw_t)) {
166
-		DPRINTF("ERROR: sense Bulk read CSW ret = %d\n", ret);
167
-	}
168
-
169
-	return(-csw.status);
170
-}
171
-
172
-#endif

+ 0
- 10
src/filo/usb/usb_scsi_low.h Целия файл

@@ -1,10 +0,0 @@
1
-#ifndef _USB_SCSI_LOW_H
2
-#define _USB_SCSI_LOW_H
3
-
4
-#define SG_DXFER_FROM_DEV -3
5
-#define SG_DXFER_TO_DEV -2
6
-
7
-int scsi_command( unsigned char device, unsigned char *cmd, int cmd_len, int direction, unsigned char *data, int data_len, char *sense_data, int sense_len);
8
-int request_sense( unsigned char device, char *sense_data, int len);
9
-
10
-#endif

+ 0
- 163
src/filo/usb/usb_x.c Целия файл

@@ -1,163 +0,0 @@
1
-#ifdef USB_DISK
2
-/*******************************************************************************
3
- *
4
- *
5
- *	Copyright 2003 Steven James <pyro@linuxlabs.com> and
6
- *	LinuxLabs http://www.linuxlabs.com
7
- *
8
- *	This program is free software; you can redistribute it and/or modify
9
- *	it under the terms of the GNU General Public License as published by
10
- *	the Free Software Foundation; either version 2 of the License, or
11
- *	(at your option) any later version.
12
- *
13
- *	This program is distributed in the hope that it will be useful,
14
- *	but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- *	GNU General Public License for more details.
17
- *
18
- *	You should have received a copy of the GNU General Public License
19
- *	along with this program; if not, write to the Free Software
20
- *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
- *
22
- ******************************************************************************/
23
-
24
-#include <etherboot.h>
25
-#include <pci.h>
26
-#include <timer.h>
27
-#include <lib.h>
28
-        
29
-#define DEBUG_THIS DEBUG_USB
30
-#include <debug.h>
31
-
32
-#define DPRINTF debug
33
-
34
-#include "usb.h"
35
-#include "scsi_cmds.h"
36
-
37
-struct usbdisk_info_t {
38
-        struct controller *ctrl;
39
-        uint16_t heads;
40
-        uint16_t cylinders;
41
-        uint16_t sectors_per_track;
42
-        uint8_t  model_number[41];
43
-        uint8_t  slave;
44
-        sector_t sectors;
45
-        int  address_mode;
46
-#define ADDRESS_MODE_CHS    0
47
-#define ADDRESS_MODE_LBA    1
48
-#define ADDRESS_MODE_LBA48  2
49
-#define ADDRESS_MODE_PACKET 3
50
-        uint32_t hw_sector_size;
51
-        unsigned drive_exists : 1;
52
-        unsigned slave_absent : 1;
53
-        unsigned removable : 1;
54
-	
55
-	unsigned char usb_device_address;	
56
-};
57
-
58
-struct usbdisk_info_t usbdisk_info;
59
-
60
-#define TEST 0
61
-
62
-#if TEST==1
63
-#include "usb_scsi_low.h"
64
-typedef struct partition_entry {
65
-        uchar boot_flag;
66
-
67
-        uchar chs[7];
68
-
69
-        unsigned int lba_start;
70
-        unsigned int lba_len;
71
-} __attribute__ ((packed)) partition_entry_t;
72
-
73
-typedef struct partition {
74
-        char loader[446];
75
-        partition_entry_t entry[4];
76
-        char sig[2];
77
-} __attribute__ ((packed)) partition_t;
78
-#endif
79
-
80
-int usb_probe(int drive)
81
-{
82
-	struct usbdisk_info_t *info = &usbdisk_info;
83
-#if TEST==1
84
-	partition_t part;
85
-	unsigned char sense_data[32];
86
-#endif
87
-        int i,res;
88
-        int error_count=100;
89
-
90
-	printf("LinuxLabs USB bootloader\n");
91
-
92
-//	outb( 0x30, 0x70);	// reset primary boot
93
-//	outb( 0xff, 0x71);
94
-	init_devices();
95
-	hci_init();
96
-
97
-	info->usb_device_address = 0;
98
-        // find first usb device
99
-
100
-        while(error_count && (res = poll_usb()))        // keep polling usb until no more devices are enumerated
101
-                if(res<0)
102
-                        if(!--error_count)
103
-                                printf("There is a USB device, but it won't init! This is a bad thing.\n");
104
-
105
-        for(i=0; i< next_usb_dev ; i++) {
106
-                if(usb_device[i].class == 0x08 && usb_device[i].subclass == 0x06 && usb_device[i].protocol == 0x50) {
107
-                        printf("Found USB block device %d\n", i);
108
-			if(drive==0) {
109
-                        	info->usb_device_address = i;
110
-				break;
111
-			}
112
-			drive--;
113
-                }
114
-        }
115
-	
116
-	if(info->usb_device_address == 0) return -1;
117
-
118
-	UnitReady(info->usb_device_address);
119
-
120
-#if TEST==1
121
-//Test
122
-        printf("Requesting initial sense data\n");
123
-        request_sense( info->usb_device_address, sense_data, 32);
124
-        PrintSense(sense_data, 32);
125
-
126
-        res = ll_read_block(info->usb_device_address, (uint8_t *)&part, 0, 1);
127
-
128
-        printf("ll_read_block returns %d\n", res);
129
-
130
-        res=-1;
131
-
132
-	debug("part address (phy) = %x, (virt) = %x\n", (uint32_t) virt_to_phys(&part), (uint32_t)&part);
133
-
134
-        for(i=0; i<4; i++) {
135
-                printf("%d: boot=%02x, start=%08x length=%08x\n",i,  part.entry[i].boot_flag, part.entry[i].lba_start, part.entry[i]
136
-.lba_len);
137
-                }
138
-
139
-
140
-#endif
141
-
142
-	return 0;
143
-}
144
-int usb_read(int drive, sector_t sector, void *buffer)
145
-{
146
-        struct usbdisk_info_t *info = &usbdisk_info;
147
-        int result;
148
-	int blocknum = sector;
149
-	int i;
150
-//	printf("sector= %d\t", blocknum);
151
-	result = ll_read_block(info->usb_device_address, buffer,blocknum, 1);
152
-#if 0
153
-       for(i=0;i<128;i++) {
154
-             if((i%4)==0) printf("\n %08x:",i*4);
155
-             printf(" %08x ",(uint32_t)*((uint32_t *)buffer+i));
156
-       }
157
-#endif
158
-
159
-        if(result!=512) return -1;	
160
-
161
-	return 0;	
162
-}
163
-#endif 

Loading…
Отказ
Запис