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>
19 #define BUILD_CRAMDISK
21 extern int get_filesystem_list(char * buf);
23 extern asmlinkage long sys_mount(char *dev_name, char *dir_name, char *type,
24 unsigned long flags, void *data);
25 extern asmlinkage long sys_mkdir(const char *name, int mode);
26 extern asmlinkage long sys_chdir(const char *name);
27 extern asmlinkage long sys_fchdir(int fd);
28 extern asmlinkage long sys_chroot(const char *name);
29 extern asmlinkage long sys_unlink(const char *name);
30 extern asmlinkage long sys_symlink(const char *old, const char *new);
31 extern asmlinkage long sys_mknod(const char *name, int mode, dev_t dev);
32 extern asmlinkage long sys_umount(char *name, int flags);
33 extern asmlinkage long sys_ioctl(int fd, int cmd, unsigned long arg);
35 #ifdef CONFIG_BLK_DEV_INITRD
36 unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */
37 static int __initdata mount_initrd = 1;
39 static int __init no_initrd(char *str)
45 __setup("noinitrd", no_initrd);
47 static int __initdata mount_initrd = 0;
50 int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */
52 int root_mountflags = MS_RDONLY | MS_VERBOSE;
53 static char root_device_name[64];
55 /* this is initialized in init/main.c */
58 static int do_devfs = 0;
60 static int __init load_ramdisk(char *str)
62 rd_doload = simple_strtol(str,NULL,0) & 3;
65 __setup("load_ramdisk=", load_ramdisk);
67 static int __init readonly(char *str)
71 root_mountflags |= MS_RDONLY;
75 static int __init readwrite(char *str)
79 root_mountflags &= ~MS_RDONLY;
83 __setup("ro", readonly);
84 __setup("rw", readwrite);
86 static struct dev_name_struct {
89 } root_dev_names[] __initdata = {
140 { "cdu535", 0x1800 },
141 { "sonycd", 0x1800 },
143 { "cm206cd", 0x2000 },
154 { "apblock", APBLOCK_MAJOR << 8},
155 { "ddv", DDV_MAJOR << 8},
156 { "jsfd", JSFD_MAJOR << 8},
157 #if defined(CONFIG_ARCH_S390)
158 { "dasda", (DASD_MAJOR << MINORBITS) },
159 { "dasdb", (DASD_MAJOR << MINORBITS) + (1 << 2) },
160 { "dasdc", (DASD_MAJOR << MINORBITS) + (2 << 2) },
161 { "dasdd", (DASD_MAJOR << MINORBITS) + (3 << 2) },
162 { "dasde", (DASD_MAJOR << MINORBITS) + (4 << 2) },
163 { "dasdf", (DASD_MAJOR << MINORBITS) + (5 << 2) },
164 { "dasdg", (DASD_MAJOR << MINORBITS) + (6 << 2) },
165 { "dasdh", (DASD_MAJOR << MINORBITS) + (7 << 2) },
167 #if defined(CONFIG_BLK_CPQ_DA) || defined(CONFIG_BLK_CPQ_DA_MODULE)
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 },
192 #if defined(CONFIG_BLK_CPQ_CISS_DA) || defined(CONFIG_BLK_CPQ_CISS_DA_MODULE)
193 { "cciss/c0d0p",0x6800 },
194 { "cciss/c0d1p",0x6810 },
195 { "cciss/c0d2p",0x6820 },
196 { "cciss/c0d3p",0x6830 },
197 { "cciss/c0d4p",0x6840 },
198 { "cciss/c0d5p",0x6850 },
199 { "cciss/c0d6p",0x6860 },
200 { "cciss/c0d7p",0x6870 },
201 { "cciss/c0d8p",0x6880 },
202 { "cciss/c0d9p",0x6890 },
203 { "cciss/c0d10p",0x68A0 },
204 { "cciss/c0d11p",0x68B0 },
205 { "cciss/c0d12p",0x68C0 },
206 { "cciss/c0d13p",0x68D0 },
207 { "cciss/c0d14p",0x68E0 },
208 { "cciss/c0d15p",0x68F0 },
209 { "cciss/c1d0p",0x6900 },
210 { "cciss/c2d0p",0x6A00 },
211 { "cciss/c3d0p",0x6B00 },
212 { "cciss/c4d0p",0x6C00 },
213 { "cciss/c5d0p",0x6D00 },
214 { "cciss/c6d0p",0x6E00 },
215 { "cciss/c7d0p",0x6F00 },
217 { "ataraid/d0p",0x7200 },
218 { "ataraid/d1p",0x7210 },
219 { "ataraid/d2p",0x7220 },
220 { "ataraid/d3p",0x7230 },
221 { "ataraid/d4p",0x7240 },
222 { "ataraid/d5p",0x7250 },
223 { "ataraid/d6p",0x7260 },
224 { "ataraid/d7p",0x7270 },
225 { "ataraid/d8p",0x7280 },
226 { "ataraid/d9p",0x7290 },
227 { "ataraid/d10p",0x72A0 },
228 { "ataraid/d11p",0x72B0 },
229 { "ataraid/d12p",0x72C0 },
230 { "ataraid/d13p",0x72D0 },
231 { "ataraid/d14p",0x72E0 },
232 { "ataraid/d15p",0x72F0 },
241 { "mtdblock", 0x1f00 },
245 kdev_t __init name_to_kdev_t(char *line)
250 if (strncmp(line,"/dev/",5) == 0) {
251 struct dev_name_struct *dev = root_dev_names;
254 int len = strlen(dev->name);
255 if (strncmp(line,dev->name,len) == 0) {
263 offs = simple_strtoul(line, &end, base?10:16);
266 return to_kdev_t(base + offs);
269 static int __init root_dev_setup(char *line)
274 ROOT_DEV = name_to_kdev_t(line);
275 memset (root_device_name, 0, sizeof root_device_name);
276 if (strncmp (line, "/dev/", 5) == 0) line += 5;
277 for (i = 0; i < sizeof root_device_name - 1; ++i)
280 if ( isspace (ch) || (ch == ',') || (ch == '\0') ) break;
281 root_device_name[i] = ch;
286 __setup("root=", root_dev_setup);
288 static char * __initdata root_mount_data;
289 static int __init root_data_setup(char *str)
291 root_mount_data = str;
295 static char * __initdata root_fs_names;
296 static int __init fs_names_setup(char *str)
302 __setup("rootflags=", root_data_setup);
303 __setup("rootfstype=", fs_names_setup);
305 static void __init get_fs_names(char *page)
310 strcpy(page, root_fs_names);
316 int len = get_filesystem_list(page);
320 for (p = page-1; p; p = next) {
321 next = strchr(++p, '\n');
324 while ((*s++ = *p++) != '\n')
331 static void __init mount_block_root(char *name, int flags)
333 char *fs_names = __getname();
336 get_fs_names(fs_names);
338 for (p = fs_names; *p; p += strlen(p)+1) {
339 int err = sys_mount(name, "/root", p, flags, root_mount_data);
350 * Allow the user to distinguish between failed open
351 * and bad superblock on root device.
353 printk ("VFS: Cannot open root device \"%s\" or %s\n",
354 root_device_name, kdevname (ROOT_DEV));
355 printk ("Please append a correct \"root=\" boot option\n");
356 panic("VFS: Unable to mount root fs on %s",
359 panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
363 ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev;
364 printk("VFS: Mounted root (%s filesystem)%s.\n",
365 current->fs->pwdmnt->mnt_sb->s_type->name,
366 (current->fs->pwdmnt->mnt_sb->s_flags & MS_RDONLY) ? " readonly" : "");
369 #ifdef CONFIG_ROOT_NFS
370 static int __init mount_nfs_root(void)
372 void *data = nfs_root_data();
374 if (data && sys_mount("/dev/root","/root","nfs",root_mountflags,data) == 0)
380 static int __init create_dev(char *name, kdev_t dev, char *devfs_name)
388 return sys_mknod(name, S_IFBLK|0600, kdev_t_to_nr(dev));
390 handle = devfs_find_handle(NULL, dev ? NULL : devfs_name,
391 MAJOR(dev), MINOR(dev), DEVFS_SPECIAL_BLK, 1);
394 n = devfs_generate_path(handle, path + 5, sizeof (path) - 5);
397 return sys_symlink(path + n + 5, name);
400 #if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD)
401 static void __init change_floppy(char *fmt, ...)
403 struct termios termios;
409 vsprintf(buf, fmt, args);
411 fd = open("/dev/root", O_RDWR | O_NDELAY, 0);
413 sys_ioctl(fd, FDEJECT, 0);
416 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
417 fd = open("/dev/console", O_RDWR, 0);
419 sys_ioctl(fd, TCGETS, (long)&termios);
420 termios.c_lflag &= ~ICANON;
421 sys_ioctl(fd, TCSETSF, (long)&termios);
423 termios.c_lflag |= ICANON;
424 sys_ioctl(fd, TCSETSF, (long)&termios);
430 #ifdef CONFIG_BLK_DEV_RAM
432 int __initdata rd_prompt = 1; /* 1 = prompt for RAM disk, 0 = don't prompt */
434 static int __init prompt_ramdisk(char *str)
436 rd_prompt = simple_strtol(str,NULL,0) & 1;
439 __setup("prompt_ramdisk=", prompt_ramdisk);
441 int __initdata rd_image_start; /* starting block # of image */
443 static int __init ramdisk_start_setup(char *str)
445 rd_image_start = simple_strtol(str,NULL,0);
448 __setup("ramdisk_start=", ramdisk_start_setup);
450 static int __init crd_load(int in_fd, int out_fd);
453 * This routine tries to find a RAM disk image to load, and returns the
454 * number of blocks to read for a non-compressed image, 0 if the image
455 * is a compressed image, and -1 if an image with the right magic
456 * numbers could not be found.
458 * We currently check for the following magic numbers:
465 identify_ramdisk_image(int fd, int start_block)
467 const int size = 512;
468 struct minix_super_block *minixsb;
469 struct ext2_super_block *ext2sb;
470 struct romfs_super_block *romfsb;
474 buf = kmalloc(size, GFP_KERNEL);
478 minixsb = (struct minix_super_block *) buf;
479 ext2sb = (struct ext2_super_block *) buf;
480 romfsb = (struct romfs_super_block *) buf;
481 memset(buf, 0xe5, size);
484 * Read block 0 to test for gzipped kernel
486 lseek(fd, start_block * BLOCK_SIZE, 0);
490 * If it matches the gzip magic numbers, return -1
492 if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) {
494 "RAMDISK: Compressed image found at block %d\n",
500 /* romfs is at block zero too */
501 if (romfsb->word0 == ROMSB_WORD0 &&
502 romfsb->word1 == ROMSB_WORD1) {
504 "RAMDISK: romfs filesystem found at block %d\n",
506 nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
511 * Read block 1 to test for minix and ext2 superblock
513 lseek(fd, (start_block+1) * BLOCK_SIZE, 0);
517 if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
518 minixsb->s_magic == MINIX_SUPER_MAGIC2) {
520 "RAMDISK: Minix filesystem found at block %d\n",
522 nblocks = minixsb->s_nzones << minixsb->s_log_zone_size;
527 if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
529 "RAMDISK: ext2 filesystem found at block %d\n",
531 nblocks = le32_to_cpu(ext2sb->s_blocks_count);
536 "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n",
540 lseek(fd, start_block * BLOCK_SIZE, 0);
546 static int __init rd_load_image(char *from)
550 #ifdef CONFIG_BLK_DEV_RAM
552 unsigned long rd_blocks, devblocks;
555 unsigned short rotate = 0;
556 #if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_PPC_ISERIES)
557 char rotator[4] = { '|' , '/' , '-' , '\\' };
560 out_fd = open("/dev/ram", O_RDWR, 0);
564 in_fd = open(from, O_RDONLY, 0);
568 nblocks = identify_ramdisk_image(in_fd, rd_image_start);
573 #ifdef BUILD_CRAMDISK
574 if (crd_load(in_fd, out_fd) == 0)
575 goto successful_load;
578 "RAMDISK: Kernel does not support compressed "
579 "RAM disk images\n");
585 * NOTE NOTE: nblocks suppose that the blocksize is BLOCK_SIZE, so
586 * rd_load_image will work only with filesystem BLOCK_SIZE wide!
587 * So make sure to use 1k blocksize while generating ext2fs
590 if (sys_ioctl(out_fd, BLKGETSIZE, (unsigned long)&rd_blocks) < 0)
595 if (nblocks > rd_blocks) {
596 printk("RAMDISK: image too big! (%d/%lu blocks)\n",
602 * OK, time to copy in the data
604 buf = kmalloc(BLOCK_SIZE, GFP_KERNEL);
606 printk(KERN_ERR "RAMDISK: could not allocate buffer\n");
610 if (sys_ioctl(in_fd, BLKGETSIZE, (unsigned long)&devblocks) < 0)
615 if (strcmp(from, "/dev/initrd") == 0)
618 if (devblocks == 0) {
619 printk(KERN_ERR "RAMDISK: could not determine device size\n");
623 printk(KERN_NOTICE "RAMDISK: Loading %d blocks [%ld disk%s] into ram disk... ",
624 nblocks, ((nblocks-1)/devblocks)+1, nblocks>devblocks ? "s" : "");
625 for (i=0; i < nblocks; i++) {
626 if (i && (i % devblocks == 0)) {
627 printk("done disk #%ld.\n", i/devblocks);
630 printk("Error closing the disk.\n");
633 change_floppy("disk #%d", i/devblocks+1);
634 in_fd = open(from, O_RDONLY, 0);
636 printk("Error opening disk.\n");
639 printk("Loading disk #%ld... ", i/devblocks+1);
641 read(in_fd, buf, BLOCK_SIZE);
642 write(out_fd, buf, BLOCK_SIZE);
643 #if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_PPC_ISERIES)
645 printk("%c\b", rotator[rotate & 0x3]);
660 sys_unlink("/dev/ram");
665 static int __init rd_load_disk(int n)
667 #ifdef CONFIG_BLK_DEV_RAM
669 change_floppy("root floppy disk to be loaded into RAM disk");
670 create_dev("/dev/ram", MKDEV(RAMDISK_MAJOR, n), NULL);
672 return rd_load_image("/dev/root");
675 #ifdef CONFIG_DEVFS_FS
677 static void __init convert_name(char *prefix, char *name, char *p, int part)
679 int host, bus, target, lun;
684 /* Decode "c#b#t#u#" */
687 host = simple_strtol(p, &p, 10);
690 bus = simple_strtol(p, &p, 10);
693 target = simple_strtol(p, &p, 10);
696 lun = simple_strtol(p, &p, 10);
698 sprintf(dest, "%s/host%d/bus%d/target%d/lun%d",
699 prefix, host, bus, target, lun);
700 else if (*p++ == 'p')
701 sprintf(dest, "%s/host%d/bus%d/target%d/lun%d/part%s",
702 prefix, host, bus, target, lun, p);
704 sprintf(dest, "%s/host%d/bus%d/target%d/lun%d/disc",
705 prefix, host, bus, target, lun);
707 sprintf(src, "/dev/%s", name);
708 sys_mkdir(src, 0755);
710 sprintf(src, "/dev/%s", name);
711 sys_symlink(dest, src);
714 static void __init devfs_make_root(char *name)
717 if (!strncmp(name, "sd/", 3))
718 convert_name("../scsi", name, name+3, 1);
719 else if (!strncmp(name, "sr/", 3))
720 convert_name("../scsi", name, name+3, 0);
721 else if (!strncmp(name, "ide/hd/", 7))
722 convert_name("..", name, name + 7, 1);
723 else if (!strncmp(name, "ide/cd/", 7))
724 convert_name("..", name, name + 7, 0);
727 static void __init devfs_make_root(char *name)
732 static void __init mount_root(void)
734 #ifdef CONFIG_ROOT_NFS
735 if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) {
736 if (mount_nfs_root()) {
738 ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev;
739 printk("VFS: Mounted root (nfs filesystem).\n");
742 printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n");
743 ROOT_DEV = MKDEV(FLOPPY_MAJOR, 0);
746 devfs_make_root(root_device_name);
747 create_dev("/dev/root", ROOT_DEV, root_device_name);
748 #ifdef CONFIG_BLK_DEV_FD
749 if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) {
750 /* rd_doload is 2 for a dual initrd/ramload setup */
752 if (rd_load_disk(1)) {
753 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 1);
754 create_dev("/dev/root", ROOT_DEV, NULL);
757 change_floppy("root floppy");
760 mount_block_root("/dev/root", root_mountflags);
763 #ifdef CONFIG_BLK_DEV_INITRD
764 static int old_fd, root_fd;
765 static int do_linuxrc(void * shell)
767 static char *argv[] = { "linuxrc", NULL, };
768 extern char * envp_init[];
776 (void) open("/dev/console",O_RDWR,0);
779 return execve(shell, argv, envp_init);
784 static void __init handle_initrd(void)
786 #ifdef CONFIG_BLK_DEV_INITRD
787 int ram0 = kdev_t_to_nr(MKDEV(RAMDISK_MAJOR,0));
791 create_dev("/dev/root.old", ram0, NULL);
792 /* mount initrd on rootfs' /root */
793 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
794 sys_mkdir("/old", 0700);
795 root_fd = open("/", 0, 0);
796 old_fd = open("/old", 0, 0);
797 /* move initrd over / and chdir/chroot in initrd root */
799 sys_mount(".", "/", NULL, MS_MOVE, NULL);
803 pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
805 while (pid != wait(&i))
809 /* move initrd to rootfs' /old */
811 sys_mount("/", ".", NULL, MS_MOVE, NULL);
812 /* switch root and cwd back to / of rootfs */
815 sys_umount("/old/dev", 0);
817 if (real_root_dev == ram0) {
822 ROOT_DEV = real_root_dev;
825 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
826 error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
830 int fd = open("/dev/root.old", O_RDWR, 0);
832 printk(KERN_NOTICE "Unmounting old root\n");
833 sys_umount("/old", MNT_DETACH);
834 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
838 error = sys_ioctl(fd, BLKFLSBUF, 0);
841 printk(!error ? "okay\n" : "failed\n");
846 static int __init initrd_load(void)
848 #ifdef CONFIG_BLK_DEV_INITRD
849 create_dev("/dev/ram", MKDEV(RAMDISK_MAJOR, 0), NULL);
850 create_dev("/dev/initrd", MKDEV(RAMDISK_MAJOR, INITRD_MINOR), NULL);
852 return rd_load_image("/dev/initrd");
856 * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
858 void prepare_namespace(void)
860 int is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
861 #ifdef CONFIG_ALL_PPC
862 extern void arch_discover_root(void);
863 arch_discover_root();
864 #endif /* CONFIG_ALL_PPC */
865 #ifdef CONFIG_BLK_DEV_INITRD
868 real_root_dev = ROOT_DEV;
870 sys_mkdir("/dev", 0700);
871 sys_mkdir("/root", 0700);
872 sys_mknod("/dev/console", S_IFCHR|0600, MKDEV(TTYAUX_MAJOR, 1));
873 #ifdef CONFIG_DEVFS_FS
874 sys_mount("devfs", "/dev", "devfs", 0, NULL);
878 create_dev("/dev/root", ROOT_DEV, NULL);
880 if (initrd_load() && ROOT_DEV != MKDEV(RAMDISK_MAJOR, 0)) {
884 } else if (is_floppy && rd_doload && rd_load_disk(0))
885 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
888 sys_umount("/dev", 0);
889 sys_mount(".", "/", NULL, MS_MOVE, NULL);
894 //REX:added by Rex to test /etc availability
895 printk("Try to mount /etc on Flash...\n");
896 if (sys_mount("/dev/mtdblock3", "/etc", "jffs2", MS_MGC_VAL, 0))
898 printk("Cannot mount MTD device!\n");
905 //test the integrity of /etc on the flash
906 if ((fd = sys_open("/etc/rc.d/rcS", MS_RDONLY, 0)) < 0)
908 //The etc is corrupted. Umount the /etc on flash
909 //And pass the job to rcS
911 sys_umount("/etc", MS_MGC_VAL);
912 printk("Bad flash file system!\n");
916 if ((fd1 = sys_open("/etc/.nflag_100", MS_RDONLY, 0)) < 0)
918 //The /etc is old-fashion. Umount the /etc on flash
919 //And pass the job to rcS
921 sys_umount("/etc", MS_MGC_VAL);
922 printk("Old format of flash file system!\n");
931 #if defined(BUILD_CRAMDISK) && defined(CONFIG_BLK_DEV_RAM)
937 #define OF(args) args
940 #define memzero(s, n) memset ((s), 0, (n))
943 typedef unsigned char uch;
944 typedef unsigned short ush;
945 typedef unsigned long ulg;
947 #define INBUFSIZ 4096
948 #define WSIZE 0x8000 /* window size--must be a power of two, and */
949 /* at least 32K for zip's deflate method */
954 static unsigned insize; /* valid bytes in inbuf */
955 static unsigned inptr; /* index of next byte to be processed in inbuf */
956 static unsigned outcnt; /* bytes in output buffer */
957 static int exit_code;
958 static long bytes_out;
959 static int crd_infd, crd_outfd;
961 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
963 /* Diagnostic functions (stubbed out) */
964 #define Assert(cond,msg)
971 #define STATIC static
973 static int fill_inbuf(void);
974 static void flush_window(void);
975 static void *malloc(int size);
976 static void free(void *where);
977 static void error(char *m);
978 static void gzip_mark(void **);
979 static void gzip_release(void **);
981 #include "../lib/inflate.c"
983 static void __init *malloc(int size)
985 return kmalloc(size, GFP_KERNEL);
988 static void __init free(void *where)
993 static void __init gzip_mark(void **ptr)
997 static void __init gzip_release(void **ptr)
1002 /* ===========================================================================
1003 * Fill the input buffer. This is called only when the buffer is empty
1004 * and at least one byte is really needed.
1006 static int __init fill_inbuf(void)
1008 if (exit_code) return -1;
1010 insize = read(crd_infd, inbuf, INBUFSIZ);
1011 if (insize == 0) return -1;
1018 /* ===========================================================================
1019 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
1020 * (Used for the decompressed data only.)
1022 static void __init flush_window(void)
1024 ulg c = crc; /* temporary variable */
1028 write(crd_outfd, window, outcnt);
1030 for (n = 0; n < outcnt; n++) {
1032 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
1035 bytes_out += (ulg)outcnt;
1039 static void __init error(char *x)
1041 printk(KERN_ERR "%s", x);
1045 static int __init crd_load(int in_fd, int out_fd)
1049 insize = 0; /* valid bytes in inbuf */
1050 inptr = 0; /* index of next byte to be processed in inbuf */
1051 outcnt = 0; /* bytes in output buffer */
1054 crc = (ulg)0xffffffffL; /* shift register contents */
1058 inbuf = kmalloc(INBUFSIZ, GFP_KERNEL);
1060 printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
1063 window = kmalloc(WSIZE, GFP_KERNEL);
1065 printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n");
1076 #endif /* BUILD_CRAMDISK && CONFIG_BLK_DEV_RAM */