1 #define __KERNEL_SYSCALLS__
2 #include <linux/config.h>
3 #include <linux/slab.h>
4 #include <linux/devfs_fs_kernel.h>
5 #include <linux/unistd.h>
6 #include <linux/ctype.h>
10 #include <linux/init.h>
12 #include <linux/nfs_fs.h>
13 #include <linux/nfs_fs_sb.h>
14 #include <linux/nfs_mount.h>
15 #include <linux/minix_fs.h>
16 #include <linux/ext2_fs.h>
17 #include <linux/romfs_fs.h>
18 #include <linux/cramfs_fs.h>
20 #define BUILD_CRAMDISK
22 extern int get_filesystem_list(char * buf);
24 extern asmlinkage long sys_mount(char *dev_name, char *dir_name, char *type,
25 unsigned long flags, void *data);
26 extern asmlinkage long sys_mkdir(const char *name, int mode);
27 extern asmlinkage long sys_chdir(const char *name);
28 extern asmlinkage long sys_fchdir(int fd);
29 extern asmlinkage long sys_chroot(const char *name);
30 extern asmlinkage long sys_unlink(const char *name);
31 extern asmlinkage long sys_symlink(const char *old, const char *new);
32 extern asmlinkage long sys_mknod(const char *name, int mode, dev_t dev);
33 extern asmlinkage long sys_umount(char *name, int flags);
34 extern asmlinkage long sys_ioctl(int fd, int cmd, unsigned long arg);
36 #ifdef CONFIG_BLK_DEV_INITRD
37 unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */
38 static int __initdata mount_initrd = 1;
40 static int __init no_initrd(char *str)
46 __setup("noinitrd", no_initrd);
48 static int __initdata mount_initrd = 0;
51 int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */
53 int root_mountflags = MS_RDONLY | MS_VERBOSE;
54 static char root_device_name[64];
56 /* this is initialized in init/main.c */
59 static int do_devfs = 0;
61 static int __init load_ramdisk(char *str)
63 rd_doload = simple_strtol(str,NULL,0) & 3;
66 __setup("load_ramdisk=", load_ramdisk);
68 static int __init readonly(char *str)
72 root_mountflags |= MS_RDONLY;
76 static int __init readwrite(char *str)
80 root_mountflags &= ~MS_RDONLY;
84 __setup("ro", readonly);
85 __setup("rw", readwrite);
87 static struct dev_name_struct {
90 } root_dev_names[] __initdata = {
91 { "nfs", MKDEV(NFS_MAJOR, NFS_MINOR) },
141 { "cdu535", 0x1800 },
142 { "sonycd", 0x1800 },
144 { "cm206cd", 0x2000 },
155 { "apblock", APBLOCK_MAJOR << 8},
156 { "ddv", DDV_MAJOR << 8},
157 { "jsfd", JSFD_MAJOR << 8},
158 #if defined(CONFIG_ARCH_S390)
159 { "dasda", (DASD_MAJOR << MINORBITS) },
160 { "dasdb", (DASD_MAJOR << MINORBITS) + (1 << 2) },
161 { "dasdc", (DASD_MAJOR << MINORBITS) + (2 << 2) },
162 { "dasdd", (DASD_MAJOR << MINORBITS) + (3 << 2) },
163 { "dasde", (DASD_MAJOR << MINORBITS) + (4 << 2) },
164 { "dasdf", (DASD_MAJOR << MINORBITS) + (5 << 2) },
165 { "dasdg", (DASD_MAJOR << MINORBITS) + (6 << 2) },
166 { "dasdh", (DASD_MAJOR << MINORBITS) + (7 << 2) },
168 { "ida/c0d0p",0x4800 },
169 { "ida/c0d1p",0x4810 },
170 { "ida/c0d2p",0x4820 },
171 { "ida/c0d3p",0x4830 },
172 { "ida/c0d4p",0x4840 },
173 { "ida/c0d5p",0x4850 },
174 { "ida/c0d6p",0x4860 },
175 { "ida/c0d7p",0x4870 },
176 { "ida/c0d8p",0x4880 },
177 { "ida/c0d9p",0x4890 },
178 { "ida/c0d10p",0x48A0 },
179 { "ida/c0d11p",0x48B0 },
180 { "ida/c0d12p",0x48C0 },
181 { "ida/c0d13p",0x48D0 },
182 { "ida/c0d14p",0x48E0 },
183 { "ida/c0d15p",0x48F0 },
184 { "ida/c1d0p",0x4900 },
185 { "ida/c2d0p",0x4A00 },
186 { "ida/c3d0p",0x4B00 },
187 { "ida/c4d0p",0x4C00 },
188 { "ida/c5d0p",0x4D00 },
189 { "ida/c6d0p",0x4E00 },
190 { "ida/c7d0p",0x4F00 },
191 { "cciss/c0d0p",0x6800 },
192 { "cciss/c0d1p",0x6810 },
193 { "cciss/c0d2p",0x6820 },
194 { "cciss/c0d3p",0x6830 },
195 { "cciss/c0d4p",0x6840 },
196 { "cciss/c0d5p",0x6850 },
197 { "cciss/c0d6p",0x6860 },
198 { "cciss/c0d7p",0x6870 },
199 { "cciss/c0d8p",0x6880 },
200 { "cciss/c0d9p",0x6890 },
201 { "cciss/c0d10p",0x68A0 },
202 { "cciss/c0d11p",0x68B0 },
203 { "cciss/c0d12p",0x68C0 },
204 { "cciss/c0d13p",0x68D0 },
205 { "cciss/c0d14p",0x68E0 },
206 { "cciss/c0d15p",0x68F0 },
207 { "cciss/c1d0p",0x6900 },
208 { "cciss/c2d0p",0x6A00 },
209 { "cciss/c3d0p",0x6B00 },
210 { "cciss/c4d0p",0x6C00 },
211 { "cciss/c5d0p",0x6D00 },
212 { "cciss/c6d0p",0x6E00 },
213 { "cciss/c7d0p",0x6F00 },
214 { "ataraid/d0p",0x7200 },
215 { "ataraid/d1p",0x7210 },
216 { "ataraid/d2p",0x7220 },
217 { "ataraid/d3p",0x7230 },
218 { "ataraid/d4p",0x7240 },
219 { "ataraid/d5p",0x7250 },
220 { "ataraid/d6p",0x7260 },
221 { "ataraid/d7p",0x7270 },
222 { "ataraid/d8p",0x7280 },
223 { "ataraid/d9p",0x7290 },
224 { "ataraid/d10p",0x72A0 },
225 { "ataraid/d11p",0x72B0 },
226 { "ataraid/d12p",0x72C0 },
227 { "ataraid/d13p",0x72D0 },
228 { "ataraid/d14p",0x72E0 },
229 { "ataraid/d15p",0x72F0 },
230 { "rd/c0d0p",0x3000 },
231 { "rd/c0d0p1",0x3001 },
232 { "rd/c0d0p2",0x3002 },
233 { "rd/c0d0p3",0x3003 },
234 { "rd/c0d0p4",0x3004 },
235 { "rd/c0d0p5",0x3005 },
236 { "rd/c0d0p6",0x3006 },
237 { "rd/c0d0p7",0x3007 },
238 { "rd/c0d0p8",0x3008 },
239 { "rd/c0d1p",0x3008 },
240 { "rd/c0d1p1",0x3009 },
241 { "rd/c0d1p2",0x300a },
242 { "rd/c0d1p3",0x300b },
243 { "rd/c0d1p4",0x300c },
244 { "rd/c0d1p5",0x300d },
245 { "rd/c0d1p6",0x300e },
246 { "rd/c0d1p7",0x300f },
247 { "rd/c0d1p8",0x3010 },
256 { "mtdblock", 0x1f00 },
261 kdev_t __init name_to_kdev_t(char *line)
266 if (strncmp(line,"/dev/",5) == 0) {
267 struct dev_name_struct *dev = root_dev_names;
270 int len = strlen(dev->name);
271 if (strncmp(line,dev->name,len) == 0) {
279 offs = simple_strtoul(line, &end, base?10:16);
282 return to_kdev_t(base + offs);
285 static int __init root_dev_setup(char *line)
290 ROOT_DEV = name_to_kdev_t(line);
291 memset (root_device_name, 0, sizeof root_device_name);
292 if (strncmp (line, "/dev/", 5) == 0) line += 5;
293 for (i = 0; i < sizeof root_device_name - 1; ++i)
296 if ( isspace (ch) || (ch == ',') || (ch == '\0') ) break;
297 root_device_name[i] = ch;
302 __setup("root=", root_dev_setup);
304 static char * __initdata root_mount_data;
305 static int __init root_data_setup(char *str)
307 root_mount_data = str;
311 static char * __initdata root_fs_names;
312 static int __init fs_names_setup(char *str)
318 __setup("rootflags=", root_data_setup);
319 __setup("rootfstype=", fs_names_setup);
321 static void __init get_fs_names(char *page)
326 strcpy(page, root_fs_names);
332 int len = get_filesystem_list(page);
336 for (p = page-1; p; p = next) {
337 next = strchr(++p, '\n');
340 while ((*s++ = *p++) != '\n')
347 static void __init mount_block_root(char *name, int flags)
349 char *fs_names = __getname();
352 get_fs_names(fs_names);
354 for (p = fs_names; *p; p += strlen(p)+1) {
355 int err = sys_mount(name, "/root", p, flags, root_mount_data);
367 * Allow the user to distinguish between failed open
368 * and bad superblock on root device.
370 printk ("VFS: Cannot open root device \"%s\" or %s\n",
371 root_device_name, kdevname (ROOT_DEV));
372 printk ("Please append a correct \"root=\" boot option\n");
373 panic("VFS: Unable to mount root fs on %s",
376 panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
380 ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev;
381 printk("VFS: Mounted root (%s filesystem)%s.\n",
382 current->fs->pwdmnt->mnt_sb->s_type->name,
383 (current->fs->pwdmnt->mnt_sb->s_flags & MS_RDONLY) ? " readonly" : "");
386 #ifdef CONFIG_ROOT_NFS
387 static int __init mount_nfs_root(void)
389 void *data = nfs_root_data();
391 if (data && sys_mount("/dev/root","/root","nfs",root_mountflags,data) == 0)
397 static int __init create_dev(char *name, kdev_t dev, char *devfs_name)
405 return sys_mknod(name, S_IFBLK|0600, kdev_t_to_nr(dev));
407 handle = devfs_find_handle(NULL, dev ? NULL : devfs_name,
408 MAJOR(dev), MINOR(dev), DEVFS_SPECIAL_BLK, 1);
411 n = devfs_generate_path(handle, path + 5, sizeof (path) - 5);
414 return sys_symlink(path + n + 5, name);
417 #if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD)
418 static void __init change_floppy(char *fmt, ...)
420 struct termios termios;
426 vsprintf(buf, fmt, args);
428 fd = open("/dev/root", O_RDWR | O_NDELAY, 0);
430 sys_ioctl(fd, FDEJECT, 0);
433 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
434 fd = open("/dev/console", O_RDWR, 0);
436 sys_ioctl(fd, TCGETS, (long)&termios);
437 termios.c_lflag &= ~ICANON;
438 sys_ioctl(fd, TCSETSF, (long)&termios);
440 termios.c_lflag |= ICANON;
441 sys_ioctl(fd, TCSETSF, (long)&termios);
447 #ifdef CONFIG_BLK_DEV_RAM
449 int __initdata rd_prompt = 1; /* 1 = prompt for RAM disk, 0 = don't prompt */
451 static int __init prompt_ramdisk(char *str)
453 rd_prompt = simple_strtol(str,NULL,0) & 1;
456 __setup("prompt_ramdisk=", prompt_ramdisk);
458 int __initdata rd_image_start; /* starting block # of image */
460 static int __init ramdisk_start_setup(char *str)
462 rd_image_start = simple_strtol(str,NULL,0);
465 __setup("ramdisk_start=", ramdisk_start_setup);
467 static int __init crd_load(int in_fd, int out_fd);
470 * This routine tries to find a RAM disk image to load, and returns the
471 * number of blocks to read for a non-compressed image, 0 if the image
472 * is a compressed image, and -1 if an image with the right magic
473 * numbers could not be found.
475 * We currently check for the following magic numbers:
483 identify_ramdisk_image(int fd, int start_block)
485 const int size = 512;
486 struct minix_super_block *minixsb;
487 struct ext2_super_block *ext2sb;
488 struct romfs_super_block *romfsb;
489 struct cramfs_super *cramfsb;
493 buf = kmalloc(size, GFP_KERNEL);
497 minixsb = (struct minix_super_block *) buf;
498 ext2sb = (struct ext2_super_block *) buf;
499 romfsb = (struct romfs_super_block *) buf;
500 cramfsb = (struct cramfs_super *) buf;
501 memset(buf, 0xe5, size);
504 * Read block 0 to test for gzipped kernel
506 lseek(fd, start_block * BLOCK_SIZE, 0);
510 * If it matches the gzip magic numbers, return -1
512 if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) {
514 "RAMDISK: Compressed image found at block %d\n",
520 /* romfs is at block zero too */
521 if (romfsb->word0 == ROMSB_WORD0 &&
522 romfsb->word1 == ROMSB_WORD1) {
524 "RAMDISK: romfs filesystem found at block %d\n",
526 nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
530 if (cramfsb->magic == CRAMFS_MAGIC) {
532 "RAMDISK: cramfs filesystem found at block %d\n",
534 nblocks = (cramfsb->size + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS;
539 * Read block 1 to test for minix and ext2 superblock
541 lseek(fd, (start_block+1) * BLOCK_SIZE, 0);
545 if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
546 minixsb->s_magic == MINIX_SUPER_MAGIC2) {
548 "RAMDISK: Minix filesystem found at block %d\n",
550 nblocks = minixsb->s_nzones << minixsb->s_log_zone_size;
555 if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
557 "RAMDISK: ext2 filesystem found at block %d\n",
559 nblocks = le32_to_cpu(ext2sb->s_blocks_count);
564 "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n",
568 lseek(fd, start_block * BLOCK_SIZE, 0);
574 static int __init rd_load_image(char *from)
578 #ifdef CONFIG_BLK_DEV_RAM
580 unsigned long rd_blocks, devblocks;
583 unsigned short rotate = 0;
584 #if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_PPC_ISERIES)
585 char rotator[4] = { '|' , '/' , '-' , '\\' };
588 out_fd = open("/dev/ram", O_RDWR, 0);
592 in_fd = open(from, O_RDONLY, 0);
596 nblocks = identify_ramdisk_image(in_fd, rd_image_start);
601 #ifdef BUILD_CRAMDISK
602 if (crd_load(in_fd, out_fd) == 0)
603 goto successful_load;
606 "RAMDISK: Kernel does not support compressed "
607 "RAM disk images\n");
613 * NOTE NOTE: nblocks suppose that the blocksize is BLOCK_SIZE, so
614 * rd_load_image will work only with filesystem BLOCK_SIZE wide!
615 * So make sure to use 1k blocksize while generating ext2fs
618 if (sys_ioctl(out_fd, BLKGETSIZE, (unsigned long)&rd_blocks) < 0)
623 if (nblocks > rd_blocks) {
624 printk("RAMDISK: image too big! (%d/%lu blocks)\n",
630 * OK, time to copy in the data
632 buf = kmalloc(BLOCK_SIZE, GFP_KERNEL);
634 printk(KERN_ERR "RAMDISK: could not allocate buffer\n");
638 if (sys_ioctl(in_fd, BLKGETSIZE, (unsigned long)&devblocks) < 0)
643 if (strcmp(from, "/dev/initrd") == 0)
646 if (devblocks == 0) {
647 printk(KERN_ERR "RAMDISK: could not determine device size\n");
651 printk(KERN_NOTICE "RAMDISK: Loading %d blocks [%ld disk%s] into ram disk... ",
652 nblocks, ((nblocks-1)/devblocks)+1, nblocks>devblocks ? "s" : "");
653 for (i=0; i < nblocks; i++) {
654 if (i && (i % devblocks == 0)) {
655 printk("done disk #%ld.\n", i/devblocks);
658 printk("Error closing the disk.\n");
661 change_floppy("disk #%d", i/devblocks+1);
662 in_fd = open(from, O_RDONLY, 0);
664 printk("Error opening disk.\n");
667 printk("Loading disk #%ld... ", i/devblocks+1);
669 read(in_fd, buf, BLOCK_SIZE);
670 write(out_fd, buf, BLOCK_SIZE);
671 #if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_PPC_ISERIES)
673 printk("%c\b", rotator[rotate & 0x3]);
688 sys_unlink("/dev/ram");
693 static int __init rd_load_disk(int n)
695 #ifdef CONFIG_BLK_DEV_RAM
697 change_floppy("root floppy disk to be loaded into RAM disk");
698 create_dev("/dev/ram", MKDEV(RAMDISK_MAJOR, n), NULL);
700 return rd_load_image("/dev/root");
703 #ifdef CONFIG_DEVFS_FS
705 static void __init convert_name(char *prefix, char *name, char *p, int part)
707 int host, bus, target, lun;
712 /* Decode "c#b#t#u#" */
715 host = simple_strtol(p, &p, 10);
718 bus = simple_strtol(p, &p, 10);
721 target = simple_strtol(p, &p, 10);
724 lun = simple_strtol(p, &p, 10);
726 sprintf(dest, "%s/host%d/bus%d/target%d/lun%d",
727 prefix, host, bus, target, lun);
728 else if (*p++ == 'p')
729 sprintf(dest, "%s/host%d/bus%d/target%d/lun%d/part%s",
730 prefix, host, bus, target, lun, p);
732 sprintf(dest, "%s/host%d/bus%d/target%d/lun%d/disc",
733 prefix, host, bus, target, lun);
735 sprintf(src, "/dev/%s", name);
736 sys_mkdir(src, 0755);
738 sprintf(src, "/dev/%s", name);
739 sys_symlink(dest, src);
742 static void __init devfs_make_root(char *name)
745 if (!strncmp(name, "sd/", 3))
746 convert_name("../scsi", name, name+3, 1);
747 else if (!strncmp(name, "sr/", 3))
748 convert_name("../scsi", name, name+3, 0);
749 else if (!strncmp(name, "ide/hd/", 7))
750 convert_name("..", name, name + 7, 1);
751 else if (!strncmp(name, "ide/cd/", 7))
752 convert_name("..", name, name + 7, 0);
755 static void __init devfs_make_root(char *name)
760 static void __init mount_root(void)
762 #ifdef CONFIG_ROOT_NFS
763 if (MAJOR(ROOT_DEV) == NFS_MAJOR
764 && MINOR(ROOT_DEV) == NFS_MINOR) {
765 if (mount_nfs_root()) {
767 ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev;
768 printk("VFS: Mounted root (nfs filesystem).\n");
771 printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n");
772 ROOT_DEV = MKDEV(FLOPPY_MAJOR, 0);
775 devfs_make_root(root_device_name);
776 create_dev("/dev/root", ROOT_DEV, root_device_name);
777 #ifdef CONFIG_BLK_DEV_FD
778 if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) {
779 /* rd_doload is 2 for a dual initrd/ramload setup */
781 if (rd_load_disk(1)) {
782 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 1);
783 create_dev("/dev/root", ROOT_DEV, NULL);
786 change_floppy("root floppy");
789 mount_block_root("/dev/root", root_mountflags);
792 #ifdef CONFIG_BLK_DEV_INITRD
793 static int old_fd, root_fd;
794 static int do_linuxrc(void * shell)
796 static char *argv[] = { "linuxrc", NULL, };
797 extern char * envp_init[];
805 (void) open("/dev/console",O_RDWR,0);
808 return execve(shell, argv, envp_init);
813 static void __init handle_initrd(void)
815 #ifdef CONFIG_BLK_DEV_INITRD
816 int ram0 = kdev_t_to_nr(MKDEV(RAMDISK_MAJOR,0));
820 create_dev("/dev/root.old", ram0, NULL);
821 /* mount initrd on rootfs' /root */
822 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
823 sys_mkdir("/old", 0700);
824 root_fd = open("/", 0, 0);
825 old_fd = open("/old", 0, 0);
826 /* move initrd over / and chdir/chroot in initrd root */
828 sys_mount(".", "/", NULL, MS_MOVE, NULL);
832 pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
834 while (pid != wait(&i))
838 /* move initrd to rootfs' /old */
840 sys_mount("/", ".", NULL, MS_MOVE, NULL);
841 /* switch root and cwd back to / of rootfs */
844 sys_umount("/old/dev", 0);
848 if (real_root_dev == ram0) {
853 ROOT_DEV = real_root_dev;
856 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
857 error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
861 int fd = open("/dev/root.old", O_RDWR, 0);
863 printk(KERN_NOTICE "Unmounting old root\n");
864 sys_umount("/old", MNT_DETACH);
865 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
869 error = sys_ioctl(fd, BLKFLSBUF, 0);
872 printk(!error ? "okay\n" : "failed\n");
877 static int __init initrd_load(void)
879 #ifdef CONFIG_BLK_DEV_INITRD
880 create_dev("/dev/ram", MKDEV(RAMDISK_MAJOR, 0), NULL);
881 create_dev("/dev/initrd", MKDEV(RAMDISK_MAJOR, INITRD_MINOR), NULL);
883 return rd_load_image("/dev/initrd");
887 * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
889 void prepare_namespace(void)
891 int is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
892 #ifdef CONFIG_ALL_PPC
893 extern void arch_discover_root(void);
894 arch_discover_root();
895 #endif /* CONFIG_ALL_PPC */
896 #ifdef CONFIG_BLK_DEV_INITRD
899 real_root_dev = ROOT_DEV;
901 sys_mkdir("/dev", 0700);
902 sys_mkdir("/root", 0700);
903 sys_mknod("/dev/console", S_IFCHR|0600, MKDEV(TTYAUX_MAJOR, 1));
904 #ifdef CONFIG_DEVFS_FS
905 sys_mount("devfs", "/dev", "devfs", 0, NULL);
909 create_dev("/dev/root", ROOT_DEV, NULL);
911 if (initrd_load() && ROOT_DEV != MKDEV(RAMDISK_MAJOR, 0)) {
915 } else if (is_floppy && rd_doload && rd_load_disk(0))
916 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
919 sys_umount("/dev", 0);
920 sys_mount(".", "/", NULL, MS_MOVE, NULL);
925 #ifdef CONFIG_BLK_DEV_RAM
927 #if defined(BUILD_CRAMDISK) && defined(CONFIG_BLK_DEV_RAM)
933 #define OF(args) args
936 #define memzero(s, n) memset ((s), 0, (n))
939 typedef unsigned char uch;
940 typedef unsigned short ush;
941 typedef unsigned long ulg;
943 #define INBUFSIZ 4096
944 #define WSIZE 0x8000 /* window size--must be a power of two, and */
945 /* at least 32K for zip's deflate method */
950 static unsigned insize; /* valid bytes in inbuf */
951 static unsigned inptr; /* index of next byte to be processed in inbuf */
952 static unsigned outcnt; /* bytes in output buffer */
953 static int exit_code;
954 static long bytes_out;
955 static int crd_infd, crd_outfd;
957 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
959 /* Diagnostic functions (stubbed out) */
960 #define Assert(cond,msg)
967 #define STATIC static
969 static int fill_inbuf(void);
970 static void flush_window(void);
971 static void *malloc(int size);
972 static void free(void *where);
973 static void error(char *m);
974 static void gzip_mark(void **);
975 static void gzip_release(void **);
977 #include "../lib/inflate.c"
979 static void __init *malloc(int size)
981 return kmalloc(size, GFP_KERNEL);
984 static void __init free(void *where)
989 static void __init gzip_mark(void **ptr)
993 static void __init gzip_release(void **ptr)
998 /* ===========================================================================
999 * Fill the input buffer. This is called only when the buffer is empty
1000 * and at least one byte is really needed.
1002 static int __init fill_inbuf(void)
1004 if (exit_code) return -1;
1006 insize = read(crd_infd, inbuf, INBUFSIZ);
1007 if (insize == 0) return -1;
1014 /* ===========================================================================
1015 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
1016 * (Used for the decompressed data only.)
1018 static void __init flush_window(void)
1020 ulg c = crc; /* temporary variable */
1024 write(crd_outfd, window, outcnt);
1026 for (n = 0; n < outcnt; n++) {
1028 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
1031 bytes_out += (ulg)outcnt;
1035 static void __init error(char *x)
1037 printk(KERN_ERR "%s", x);
1041 static int __init crd_load(int in_fd, int out_fd)
1045 insize = 0; /* valid bytes in inbuf */
1046 inptr = 0; /* index of next byte to be processed in inbuf */
1047 outcnt = 0; /* bytes in output buffer */
1050 crc = (ulg)0xffffffffL; /* shift register contents */
1054 inbuf = kmalloc(INBUFSIZ, GFP_KERNEL);
1056 printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
1059 window = kmalloc(WSIZE, GFP_KERNEL);
1061 printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n");
1072 #endif /* BUILD_CRAMDISK && CONFIG_BLK_DEV_RAM */
1073 #endif /* CONFIG_BLK_DEV_RAM */