home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / v1.2 / ramdisk-.2 / ramdisk-1.2.10a.diff
Text File  |  1995-07-16  |  66KB  |  2,240 lines

  1. diff -u --recursive --new-file linux-1.2.11/drivers/block/Makefile linux/drivers/block/Makefile
  2. --- linux-1.2.11/drivers/block/Makefile    Sun Jul 16 20:46:04 1995
  3. +++ linux/drivers/block/Makefile    Sun Jul 16 20:48:00 1995
  4. @@ -21,8 +21,8 @@
  5.  # In the future, some of these should be built conditionally.
  6.  #
  7.  
  8. -OBJS := ll_rw_blk.o ramdisk.o genhd.o 
  9. -SRCS := ll_rw_blk.c ramdisk.c genhd.c 
  10. +OBJS := ll_rw_blk.o rd.o rd_gz_inflate.o rd_gz_unzip.o genhd.o 
  11. +SRCS := ll_rw_blk.c rd.c rd_gz_inflate.c rd_gz_unzip.c genhd.c 
  12.  BLOCK_MODULE_OBJS =
  13.  
  14.  ifdef CONFIG_BLK_DEV_FD
  15. diff -u --recursive --new-file linux-1.2.11/drivers/block/README.ramdisk linux/drivers/block/README.ramdisk
  16. --- linux-1.2.11/drivers/block/README.ramdisk    Wed Dec 31 17:00:00 1969
  17. +++ linux/drivers/block/README.ramdisk    Sun Jul 16 20:48:00 1995
  18. @@ -0,0 +1,34 @@
  19. +New RAMDISK driver README
  20. +-------------------------
  21. +
  22. +    This improved version of the ramdisk driver contains two major 
  23. +enhancements to the older ramdisk driver :
  24. +
  25. +    1.  It supports gzipped ramdisk images.  This, for example, makes 
  26. +the standard 1.44MB rootdisk shipped with Slackware 2.2 take up only 544K 
  27. +of disk space.  This feature can be used easily by gziping a standard 
  28. +rootdisk (or creating a larger one in a ramdisk), and copying it down to 
  29. +the floppy.
  30. +
  31. +    This can be extremely useful for certain rare situations (like if 
  32. +you only have a 720K disk to put a rootdisk on - using this ramdisk 
  33. +driver, you can put a full rootdisk on it...)
  34. +
  35. +(TODO:  Make the gzip loader read at 384K and 512K into the disk, so a 
  36. +kernel and a rootdisk can both be used.)
  37. +
  38. +    2.  It also supports multiple ramdisk devices (referencing 
  39. +straight to the buffer cache).  A buffer protection scheme has been added 
  40. +to the buffer.c system, which should keep the buffers safe.
  41. +
  42. +    You can create the devices by doing :
  43. +
  44. +    mknod /dev/ramX b 33 X
  45. +
  46. +    (X is the minor number - it can be up to 255.  Note that minor #0 
  47. +can be the static ramdisk as well, so I suggest that it not be mknoded.)
  48. +    
  49. +    Enjoy!
  50. +
  51. +    - Chad Page
  52. +     (cpage@best.com)
  53. diff -u --recursive --new-file linux-1.2.11/drivers/block/ll_rw_blk.c linux/drivers/block/ll_rw_blk.c
  54. --- linux-1.2.11/drivers/block/ll_rw_blk.c    Sun Jul 16 20:46:04 1995
  55. +++ linux/drivers/block/ll_rw_blk.c    Sun Jul 16 20:49:26 1995
  56. @@ -21,6 +21,24 @@
  57.  #include <asm/io.h>
  58.  #include "blk.h"
  59.  
  60. +/* The following #define, when uncommented, adds a penalty to the current
  61. +   processes priority (actually, it's dynamic count variable), which should
  62. +   discourage excessive i/o... it only does anything when it gets to low-level
  63. +   code, since the buffers go pretty fast anyway...
  64. +
  65. +   These changes do *nothing* if COUNTER_DEC is not defined.
  66. +*/
  67. +
  68. +/* #define COUNTER_DEC */
  69. +
  70. +#ifdef COUNTER_DEC
  71. +    #define COUNTER_DEC_BLOCK 50
  72. +    #define COUNTER_DEC_PAGE 200
  73. +#else
  74. +    #define COUNTER_DEC_BLOCK 0
  75. +    #define COUNTER_DEC_PAGE 0
  76. +#endif
  77. +
  78.  /*
  79.   * The request-struct contains all necessary data
  80.   * to load a nr of sectors into memory
  81. @@ -422,6 +440,11 @@
  82.          printk("Can't page to read-only device 0x%X\n",dev);
  83.          return;
  84.      }
  85. +
  86. +    current->counter -= COUNTER_DEC_PAGE;
  87. +    if (current->counter < 0) 
  88. +        current->counter = 0;
  89. +
  90.      req = get_request_wait(NR_REQUEST, dev);
  91.  /* fill up the request-info, and add it to the queue */
  92.      req->cmd = rw;
  93. @@ -489,6 +512,13 @@
  94.          goto sorry;
  95.      }
  96.  
  97. +    /* At this point, let's change current->counter so the program won't go 
  98. +             straight for the block device again - if things are loaded... */
  99. +
  100. +    current->counter -= COUNTER_DEC_BLOCK;
  101. +    if (current->counter < 0)     
  102. +        current->counter = 0; 
  103. +
  104.      /* If there are no pending requests for this device, then we insert
  105.         a dummy request for that device.  This will prevent the request
  106.         from starting until we have shoved all of the blocks into the
  107. @@ -597,7 +627,6 @@
  108.  #ifdef CONFIG_SBPCD
  109.      mem_start = sbpcd_init(mem_start, mem_end);
  110.  #endif CONFIG_SBPCD
  111. -    if (ramdisk_size)
  112. -        mem_start += rd_init(mem_start, ramdisk_size*1024);
  113. +    mem_start += rd_init(mem_start, ramdisk_size*1024);
  114.      return mem_start;
  115.  }
  116. diff -u --recursive --new-file linux-1.2.11/drivers/block/rd.c linux/drivers/block/rd.c
  117. --- linux-1.2.11/drivers/block/rd.c    Wed Dec 31 17:00:00 1969
  118. +++ linux/drivers/block/rd.c    Sun Jul 16 20:48:00 1995
  119. @@ -0,0 +1,613 @@
  120. +/*
  121. + *  ramdisk.c - Multiple ramdisk driver - gzip-loading version - v. 0.8 beta.
  122. + * 
  123. + *  (C) Chad Page et. al, 1995. 
  124. + *
  125. + *  This ramdisk is designed to have filesystems created on it and mounted
  126. + *  just like a regular floppy disk.  
  127. + *  
  128. + *  It also does something suggested by Linus : use the buffer cache as the
  129. + *  ramdisk data.  This makes it possible to dynamically allocate the ramdisk
  130. + *  buffer - with some consequences I have to deal with as I write this. 
  131. + *
  132. + *  This version is bimodal in that it supports BOTH static allocation and
  133. + *  dynamic allocation.  I added that because of unforseen bugs (as in, it
  134. + *  wouldn't boot!), and I've used a mmap call to do this.
  135. + *  
  136. + *  Based on the original ramdisk.c, written mostly by Theodore Ts'o in 1991.
  137. + * 
  138. + *  The gzip loader is self-activating, and automatically switches between
  139. + *  the two loading methods on whether or not get_method says it's a gzip file
  140. + *  or not (note : this isin't a clean printout yet!) 
  141. + *
  142. + */
  143. +
  144. +#include <linux/config.h>
  145. +#ifdef MODULE
  146. +#include <linux/module.h>
  147. +#include <linux/version.h>
  148. +
  149. +static char kernel_version[] = UTS_RELEASE;
  150. +#endif
  151. +#define DEVICE_NAME "ramdisk"
  152. +#define DEVICE_REQUEST rd_request
  153. +#define DEVICE_NR(device) (MINOR(device))
  154. +#define DEVICE_ON(device)
  155. +#define DEVICE_OFF(device)
  156. +
  157. +#include <linux/sched.h>
  158. +#include <linux/minix_fs.h>
  159. +#include <linux/ext2_fs.h>
  160. +#include <linux/fs.h>
  161. +#include <linux/kernel.h>
  162. +#include <linux/string.h>
  163. +#include <linux/mm.h>
  164. +#include <linux/mman.h>
  165. +#include <linux/malloc.h>
  166. +#include <linux/ioctl.h>
  167. +
  168. +#include <asm/system.h>
  169. +#include <asm/segment.h>
  170. +
  171. +extern void wait_for_keypress(void);
  172. +
  173. +#define MAJOR_NR 33 /* This is an official major number */
  174. +
  175. +#ifdef MODULE
  176. +    #include "/usr/src/linux/drivers/block/blk.h"
  177. +#else
  178. +    #include "blk.h"
  179. +    #define BUILD_CRAMDISK
  180. +
  181. +    void rd_load(void);
  182. +    int crd_load(struct inode *finode, struct file * fflip);
  183. +#endif
  184. +
  185. +/* Various static variables go here... mostly used within the ramdisk code only. */
  186. +
  187. +unsigned long rd_addr[256] = {0, };
  188. +
  189. +int rd_length[256];
  190. +int rd_blocksizes[256] = {1024, };
  191. +
  192. +/* This is the size of the rootdisk-loading ramdisk.  If it is 0, don't load 
  193. +   the rootdisk... */
  194. +
  195. +int rd_param; 
  196. +
  197. +/*
  198. + *  Basically, my strategy here is to set up a buffer-head which can't be
  199. + *  deleted, and make that my Ramdisk.  If the request is outside of the
  200. + *  allocated size, we must get rid of it...
  201. + *
  202. + */
  203. +
  204. +static void rd_request(void)
  205. +{
  206. +    unsigned int minor;
  207. +    int offset, len;
  208. +
  209. +repeat:
  210. +    INIT_REQUEST;
  211. +    
  212. +    minor = MINOR(CURRENT->dev);    
  213. +
  214. +    if ((rd_addr[minor] < 4096) && (minor == 0)) {
  215. +        end_request(0);
  216. +        goto repeat;
  217. +    }
  218. +
  219. +    offset = CURRENT->sector << 9;
  220. +    len = CURRENT->current_nr_sectors << 9;    
  221. +    
  222. +    if ((offset + len) > rd_length[minor]) {
  223. +        end_request(0);
  224. +        goto repeat;
  225. +    }
  226. +
  227. +    if (rd_addr[minor] < 4096) /* This is a buffer-cache-disk */
  228. +    {
  229. +        if (CURRENT->cmd == READ)
  230. +        {    
  231. +            memset(CURRENT->buffer, 0, len); 
  232. +        }
  233. +        CURRENT->bh->b_prot = 1;
  234. +    }
  235. +    else /* Conventional ramdisk */
  236. +    {
  237. +        if (CURRENT->cmd == READ)
  238. +        {
  239. +            memcpy(CURRENT->buffer, (char *)(rd_addr[minor] + offset), len);
  240. +        }
  241. +        if (CURRENT->cmd == WRITE)
  242. +        {
  243. +            memcpy((char *)(rd_addr[minor] + offset), CURRENT->buffer, len);
  244. +        }
  245. +    }
  246. +    end_request(1);
  247. +    goto repeat;
  248. +} 
  249. +
  250. +/* The implementation of BLKFLSBUF is stolen from ide.c.  Hopefully it's
  251. +   a good hack... */
  252. +
  253. +static int rd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
  254. +{
  255. +    if (!inode || !inode->i_rdev)     
  256. +        return -EINVAL;
  257. +
  258. +    switch (cmd) {
  259. +        case BLKFLSBUF:
  260. +            if (!suser()) return -EACCES;
  261. +            fsync_dev(inode->i_rdev);
  262. +            invalidate_buffers(inode->i_rdev);
  263. +            break;
  264. +        default:
  265. +            break;
  266. +    };
  267. +
  268. +    return 0;
  269. +}
  270. +
  271. +static struct file_operations fd_fops = {
  272. +    NULL,        /* lseek - default */
  273. +    block_read,    /* read - block dev write */
  274. +    block_write,    /* write - block dev write */
  275. +    NULL,        /* readdir - not here! */
  276. +    NULL,        /* select */
  277. +    rd_ioctl,     /* ioctl */
  278. +    NULL,        /* mmap */
  279. +    NULL,        /* no special open code... there should be! */
  280. +    NULL,        /* no special release code... */
  281. +    block_fsync        /* fsync */ 
  282. +};
  283. +
  284. +/* This is the registration and initialization section of the ramdisk driver */
  285. +
  286. +int main_rd_init(void)
  287. +{
  288. +    int count;
  289. +
  290. +    if (register_blkdev(MAJOR_NR, "ramdisk", &fd_fops)) {
  291. +        printk("RAMDISK2 : Could not get major %d", MAJOR_NR);
  292. +        return -EIO;
  293. +    }
  294. +
  295. +    blk_dev[MAJOR_NR].request_fn = &rd_request;
  296. +
  297. +    for (count = 0; count < 256; count++) {
  298. +        rd_length[count] = (16384 * 1024);
  299. +        rd_blocksizes[count] = 1024;
  300. +    }
  301. +
  302. +    blksize_size[MAJOR_NR] = rd_blocksizes;
  303. +
  304. +    return 0;
  305. +}
  306. +
  307. +/* Module init */
  308. +#ifdef MODULE
  309. +int init_module(void)
  310. +{
  311. +    return main_rd_init();
  312. +}
  313. +
  314. +void cleanup_module(void)
  315. +{
  316. +    unregister_blkdev(MAJOR_NR, "ramdisk");
  317. +}
  318. +#else
  319. +/* Non-modular init... */ 
  320. +
  321. +long rd_init(long mem_start, int length)
  322. +{
  323. +    main_rd_init();
  324. +
  325. +    rd_param = length;    
  326. +    rd_addr[0] = mem_start;
  327. +    rd_length[0] = length;
  328. +
  329. +    return length;
  330. +}
  331. +#endif
  332. +/* This is the non-modular section of the driver.  This is changed
  333. +   from the original in that the ramdisk blindly loads from block 0 without
  334. +   a filesystem check.  Peter Anvin told me that he and Linus agreed that it
  335. +   was no longer necessary, and that it took up space (which I am using to
  336. +   write all these comments :)
  337. +
  338. +   As usual, I am trying to maintain compatibility with the older ramdisk in
  339. +   the function calls used by the other parts of the kernel, to prevent
  340. +   kernel patching.
  341. +
  342. +   This code is diabled when this is compiled into modular form.
  343. +*/
  344. +
  345. +#ifndef MODULE
  346. +
  347. +void rd_load()
  348. +{
  349. +    struct inode inode;
  350. +    struct file flip;
  351. +    int device;
  352. +
  353. +    device = ROOT_DEV;
  354. +
  355. +    printk(KERN_NOTICE "VFS: Insert ramdisk floppy and press ENTER\n");
  356. +    wait_for_keypress();
  357. +
  358. +    if (MAJOR(device) != FLOPPY_MAJOR) return;
  359. +
  360. +    memset(&flip, 0, sizeof(flip));
  361. +    memset(&inode, 0, sizeof(inode));
  362. +    inode.i_rdev = device;
  363. +    flip.f_mode = 1; /* read only */
  364. +    flip.f_inode = &inode;
  365. +
  366. +    if (blkdev_open(&inode, &flip) != 0) return;
  367. +
  368. +#ifdef BUILD_CRAMDISK
  369. +    if (crd_load(&inode, &flip) == 1) { 
  370. +        if (flip.f_op -> release) flip.f_op -> release(&inode, &flip);
  371. +        return;
  372. +    }
  373. +
  374. +    if (flip.f_op -> lseek) flip.f_op -> lseek(&inode, &flip, 0, 0);
  375. +#endif
  376. +
  377. +    /* Now, copy the data... */
  378. +
  379. +    flip.f_op -> read(&inode, &flip, (char *)rd_addr[0], rd_param);
  380. +
  381. +    if (flip.f_op -> release) flip.f_op -> release(&inode, &flip);
  382. +
  383. +    invalidate_buffers(ROOT_DEV);
  384. +    ROOT_DEV = (MAJOR_NR << 8);  
  385. +}
  386. +
  387. +#ifdef BUILD_CRAMDISK
  388. +
  389. +/*
  390. + *  From linux/kernel/blk_drv/cramdisk.c
  391. + *
  392. + *  Written/adapted by Richard Lyons, 1FEB94, and hacked by Chad Page Apr. 95
  393. + *  to work with the new ramdisk driver. 
  394. + *
  395. + *  Parts of this file are copyright Jean-loup Gailly.
  396. + *  Parts of this file are not copyright Mark Adler.
  397. + *
  398. + */
  399. +
  400. +#include <linux/rd_gz_gzip.h>
  401. +#include <linux/rd_gz_lzw.h>
  402. +
  403. +#define EOF        -1 
  404. +
  405. +DECLARE(uch, inbuf, INBUFSIZ);
  406. +unsigned char *outbuf;
  407. +DECLARE(uch, window, WSIZE);
  408. +DECLARE(ulg, crc_32_tab, 256);
  409. +
  410. +#define fcalloc(a,b)    malloc((a) * (b))
  411. +#define fcfree(p)    free(p)
  412. +#define to_stdout    0
  413. +
  414. +unsigned int    insize;
  415. +unsigned int    inptr;
  416. +
  417. +unsigned char    *output_data;
  418. +unsigned long    output_ptr;
  419. +unsigned int    outcnt;
  420. +
  421. +int        method, exit_code, part_nb, last_member;
  422. +int        test = 0;
  423. +int        force = 0;
  424. +int        verbose = 1;
  425. +long        bytes_out;
  426. +
  427. +void        makecrc(void);
  428. +void        allocbufs(void);
  429. +void        freebufs(void);
  430. +local int    get_method(int in);
  431. +void        (*work)(int inf, int outf);
  432. +
  433. +struct inode *inode;
  434. +struct file *flip;
  435. +
  436. +/*
  437. + *  Unlike cramdisk, I use get_method to decide whether or not the rootdisk
  438. + *  is gzipped, and if it is I go here...
  439. + */
  440. +
  441. +int crd_load(struct inode * finode, struct file * fflip)
  442. +{
  443. +    inode = finode;
  444. +    flip = fflip; 
  445. +
  446. +    exit_code = OK;
  447. +    test = 0;
  448. +    part_nb = 0;
  449. +    allocbufs();
  450. +    clear_bufs();
  451. +    makecrc();
  452. +    method = get_method(0);
  453. +    if (method < 0)
  454. +    {
  455. +        printk("RAMDISK : gzip header not found - continuing with conventional load.\n");
  456. +    return 0;
  457. +    }
  458. +    printk("RAMDISK : starting gunzip of rootdisk image... ");
  459. +    work(0, 0);
  460. +    printk("done.\n");
  461. +    freebufs();
  462. +    invalidate_buffers(ROOT_DEV);
  463. +    if (exit_code == OK)
  464. +    ROOT_DEV = (MAJOR_NR << 8);
  465. +    return 1;
  466. +}
  467. +
  468. +void
  469. +allocbufs(void)
  470. +{
  471. +    ALLOC(uch, inbuf, INBUFSIZ); 
  472. +    outbuf = (unsigned char *)rd_addr[0];
  473. +    ALLOC(uch, window, WSIZE);
  474. +    ALLOC(ulg, crc_32_tab, 256);
  475. +}
  476. +
  477. +void
  478. +freebufs(void)
  479. +{
  480. +    FREE(crc_32_tab);
  481. +    FREE(window);
  482. +    FREE(inbuf);
  483. +}
  484. +
  485. +
  486. +/* ===========================================================================
  487. + * Clear input and output buffers
  488. + */
  489. +void clear_bufs()
  490. +{
  491. +    output_data = (unsigned char *)rd_addr[0];
  492. +    outcnt = output_ptr = 0;
  493. +    insize = inptr = 0;
  494. +    bytes_out = 0L;
  495. +}
  496. +
  497. +/*
  498. + * Code to compute the CRC-32 table. Borrowed from 
  499. + * gzip-1.0.3/makecrc.c.
  500. + */
  501. +
  502. +void
  503. +makecrc(void)
  504. +{
  505. +/* Not copyrighted 1990 Mark Adler    */
  506. +
  507. +  unsigned long c;      /* crc shift register */
  508. +  unsigned long e;      /* polynomial exclusive-or pattern */
  509. +  int i;                /* counter for all possible eight bit values */
  510. +  int k;                /* byte being shifted into crc apparatus */
  511. +
  512. +  /* terms of polynomial defining this crc (except x^32): */
  513. +  static int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  514. +
  515. +  /* Make exclusive-or pattern from polynomial */
  516. +  e = 0;
  517. +  for (i = 0; i < sizeof(p)/sizeof(int); i++)
  518. +    e |= 1L << (31 - p[i]);
  519. +
  520. +  crc_32_tab[0] = 0;
  521. +
  522. +  for (i = 1; i < 256; i++)
  523. +  {
  524. +    c = 0;
  525. +    for (k = i | 256; k != 1; k >>= 1)
  526. +    {
  527. +      c = c & 1 ? (c >> 1) ^ e : c >> 1;
  528. +      if (k & 1)
  529. +        c ^= e;
  530. +    }
  531. +    crc_32_tab[i] = c;
  532. +  }
  533. +}
  534. +
  535. +/* ===========================================================================
  536. + * Run a set of bytes through the crc shift register.  If s is a NULL
  537. + * pointer, then initialize the crc shift register contents instead.
  538. + * Return the current crc in either case.
  539. + */
  540. +ulg updcrc(s, n)
  541. +    uch *s;                 /* pointer to bytes to pump through */
  542. +    unsigned n;             /* number of bytes in s[] */
  543. +{
  544. +    register ulg c;         /* temporary variable */
  545. +
  546. +    static ulg crc = (ulg)0xffffffffL; /* shift register contents */
  547. +
  548. +    if (s == NULL) {
  549. +    c = 0xffffffffL;
  550. +    } else {
  551. +    c = crc;
  552. +    while (n--) {
  553. +        c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
  554. +    }
  555. +    }
  556. +    crc = c;
  557. +    return c ^ 0xffffffffL;       /* (instead of ~c for 64-bit machines) */
  558. +}
  559. +
  560. +void
  561. +error(char *s)
  562. +{
  563. +    printk("%s", s);
  564. +    exit_code = ERROR;
  565. +}
  566. +
  567. +/* ========================================================================
  568. + * Check the magic number of the input file and update ofname if an
  569. + * original name was given and to_stdout is not set.
  570. + * Return the compression method, -1 for error, -2 for warning.
  571. + * Set inptr to the offset of the next byte to be processed.
  572. + * This function may be called repeatedly for an input file consisting
  573. + * of several contiguous gzip'ed members.
  574. + * IN assertions: there is at least one remaining compressed member.
  575. + *   If the member is a zip file, it must be the only one.
  576. + */
  577. +local int get_method(in)
  578. +    int in;        /* input file descriptor */
  579. +{
  580. +    uch flags;
  581. +    char magic[2]; /* magic header */
  582. +
  583. +    magic[0] = (char)get_byte();
  584. +    magic[1] = (char)get_byte();
  585. +
  586. +    method = -1;                 /* unknown yet */
  587. +    part_nb++;                   /* number of parts in gzip file */
  588. +    last_member = 0;
  589. +    /* assume multiple members in gzip file except for record oriented I/O */
  590. +
  591. +    if (memcmp(magic, GZIP_MAGIC, 2) == 0
  592. +        || memcmp(magic, OLD_GZIP_MAGIC, 2) == 0) {
  593. +
  594. +    work = unzip;
  595. +    method = (int)get_byte();
  596. +    flags  = (uch)get_byte();
  597. +    if ((flags & ENCRYPTED) != 0) {
  598. +        error("Input is encrypted\n");
  599. +        exit_code = ERROR;
  600. +        return -1;
  601. +    }
  602. +    if ((flags & CONTINUATION) != 0) {
  603. +           error("Multi part input\n");
  604. +        exit_code = ERROR;
  605. +        if (force <= 1) return -1;
  606. +    }
  607. +    if ((flags & RESERVED) != 0) {
  608. +        error("Input has invalid flags\n");
  609. +        exit_code = ERROR;
  610. +        if (force <= 1) return -1;
  611. +    }
  612. +    inptr += 6;
  613. +
  614. +    if ((flags & CONTINUATION) != 0) {
  615. +        unsigned part = (unsigned)get_byte();
  616. +        part |= ((unsigned)get_byte())<<8;
  617. +        if (verbose) {
  618. +        error("Input is not part number 1\n");
  619. +        }
  620. +    }
  621. +    if ((flags & EXTRA_FIELD) != 0) {
  622. +        unsigned len = (unsigned)get_byte();
  623. +        len |= ((unsigned)get_byte())<<8;
  624. +        while (len--) (void)get_byte();
  625. +    }
  626. +
  627. +    /* Get original file name if it was truncated */
  628. +    if ((flags & ORIG_NAME) != 0) {
  629. +        if (to_stdout || part_nb > 1) {
  630. +        /* Discard the old name */
  631. +        while (get_byte() != 0) /* null */ ;
  632. +        } else {
  633. +
  634. +/* You won't believe how long not having this line in messed me up...
  635. +   in the gzip loader used by the kernel and cramdisk, it does not take
  636. +   into account the original file name, causing me literally hours of grief
  637. +   until I reverse-engineered gzip-1.0.3 from my Linux CD set to figure out
  638. +   how my gzip adaption was broken... then I put this line in, and presto!
  639. + */
  640. +         while (get_byte() != 0);
  641. +        } /* to_stdout */
  642. +    } /* orig_name */
  643. +
  644. +    /* Discard file comment if any */
  645. +    if ((flags & COMMENT) != 0) {
  646. +        while (get_byte() != 0) /* null */ ;
  647. +    }
  648. +
  649. +    } else if (memcmp(magic, PKZIP_MAGIC, 2) == 0 && inptr == 2
  650. +        && memcmp(inbuf, PKZIP_MAGIC, 4) == 0) {
  651. +    /* To simplify the code, we support a zip file when alone only.
  652. +         * We are thus guaranteed that the entire local header fits in inbuf.
  653. +         */
  654. +        inptr = 0;
  655. +    work = unzip;
  656. +    if (check_zipfile(in) == -1) return -1;
  657. +    /* check_zipfile may get ofname from the local header */
  658. +    last_member = 1;
  659. +
  660. +    } else if (memcmp(magic, PACK_MAGIC, 2) == 0) {
  661. +        error("packed input");
  662. +    } else if (memcmp(magic, LZW_MAGIC, 2) == 0) {
  663. +    error("compressed input");
  664. +    last_member = 1;
  665. +    }
  666. +    if (method == -1) {
  667. +    error("Corrupted input\n");
  668. +    if (exit_code != ERROR) exit_code = part_nb == 1 ? ERROR : WARNING;
  669. +    return part_nb == 1 ? -1 : -2;
  670. +    }
  671. +
  672. +    return method;
  673. +}
  674. +
  675. +/* I made this a real function while trying to debug this.  It isin't needed,
  676. +and will go away in alpha 4/beta-test 1. */
  677. +
  678. +int get_byte(void)
  679. +{
  680. +    if (inptr < insize) {
  681. +        return inbuf[inptr++];
  682. +    }
  683. +    else
  684. +        return fill_inbuf();
  685. +}
  686. +
  687. +int
  688. +fill_inbuf(void)
  689. +{
  690. +    if (exit_code != OK) return EOF;
  691. +
  692. +    insize = flip -> f_op -> read(inode, flip, inbuf, INBUFSIZ);
  693. +    if (insize == 0) return EOF;
  694. +
  695. +    inptr = 1;
  696. +
  697. +    return inbuf[0];
  698. +}
  699. +
  700. +/* ===========================================================================
  701. + * Write the output window window[0..outcnt-1] and update crc and bytes_out.
  702. + * (Used for the decompressed data only.)
  703. + */
  704. +void flush_window()
  705. +{
  706. +    if (outcnt == 0)
  707. +    return;
  708. +    if ((output_ptr + outcnt) > rd_length[0])
  709. +    error("CRAMDISK: compressed image too long\n");
  710. +    else {
  711. +    updcrc(window, outcnt);
  712. +
  713. +    memcpy(output_data + output_ptr, (char *)window, outcnt);
  714. +
  715. +    bytes_out += (ulg)outcnt;
  716. +    output_ptr += (ulg)outcnt;
  717. +    }
  718. +    outcnt = 0;
  719. +}
  720. +
  721. +
  722. +typedef struct {
  723. +    unsigned long    start;
  724. +    unsigned long    pages;
  725. +} chain;
  726. +
  727. +#define    MAX_MISSES (PAGE_SIZE/sizeof(chain))
  728. +
  729. +#endif
  730. +
  731. +#endif /* Non-modular portions */
  732. +
  733. diff -u --recursive --new-file linux-1.2.11/drivers/block/rd_gz_inflate.c linux/drivers/block/rd_gz_inflate.c
  734. --- linux-1.2.11/drivers/block/rd_gz_inflate.c    Wed Dec 31 17:00:00 1969
  735. +++ linux/drivers/block/rd_gz_inflate.c    Sun Jul 16 20:48:01 1995
  736. @@ -0,0 +1,812 @@
  737. +#define DEBG(x)
  738. +#define DEBG1(x)
  739. +/* inflate.c -- Not copyrighted 1992 by Mark Adler
  740. +   version c10p1, 10 January 1993 */
  741. +
  742. +/* 
  743. + * Adapted for booting Linux by Hannu Savolainen 1993
  744. + * based on gzip-1.0.3 
  745. + */
  746. +
  747. +#ifndef lint
  748. +static char rcsid[] = "$Id: inflate.c,v 0.10 1993/02/04 13:21:06 jloup Exp $";
  749. +#endif
  750. +
  751. +#include <linux/malloc.h>
  752. +
  753. +#include <linux/rd_gz_gzip.h>
  754. +#define slide window
  755. +
  756. +#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
  757. +#  include <sys/types.h>
  758. +#  include <stdlib.h>
  759. +#endif
  760. +
  761. +struct huft {
  762. +  uch e;                /* number of extra bits or operation */
  763. +  uch b;                /* number of bits in this code or subcode */
  764. +  union {
  765. +    ush n;              /* literal, length base, or distance base */
  766. +    struct huft *t;     /* pointer to next level of table */
  767. +  } v;
  768. +};
  769. +
  770. +
  771. +/* Function prototypes */
  772. +int huft_build OF((unsigned *, unsigned, unsigned, ush *, ush *,
  773. +                   struct huft **, int *));
  774. +int huft_free OF((struct huft *));
  775. +int inflate_codes OF((struct huft *, struct huft *, int, int));
  776. +int inflate_stored OF((void));
  777. +int inflate_fixed OF((void));
  778. +int inflate_dynamic OF((void));
  779. +int inflate_block OF((int *));
  780. +int inflate OF((void));
  781. +
  782. +
  783. +#define wp outcnt
  784. +#define flush_output(w) (wp=(w),flush_window())
  785. +
  786. +/* Tables for deflate from PKZIP's appnote.txt. */
  787. +static unsigned border[] = {    /* Order of the bit length code lengths */
  788. +        16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  789. +static ush cplens[] = {         /* Copy lengths for literal codes 257..285 */
  790. +        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  791. +        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  792. +        /* note: see note #13 above about the 258 in this list. */
  793. +static ush cplext[] = {         /* Extra bits for literal codes 257..285 */
  794. +        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
  795. +        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */
  796. +static ush cpdist[] = {         /* Copy offsets for distance codes 0..29 */
  797. +        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  798. +        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  799. +        8193, 12289, 16385, 24577};
  800. +static ush cpdext[] = {         /* Extra bits for distance codes */
  801. +        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
  802. +        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
  803. +        12, 12, 13, 13};
  804. +
  805. +
  806. +ulg bb;                         /* bit buffer */
  807. +unsigned bk;                    /* bits in bit buffer */
  808. +
  809. +ush mask_bits[] = {
  810. +    0x0000,
  811. +    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
  812. +    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
  813. +};
  814. +
  815. +#ifdef CRYPT
  816. +  uch cc;
  817. +#  define NEXTBYTE() \
  818. +     (decrypt ? (cc = get_byte(), zdecode(cc), cc) : get_byte())
  819. +#else
  820. +#  define NEXTBYTE()  (uch)get_byte()
  821. +#endif
  822. +#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
  823. +#define DUMPBITS(n) {b>>=(n);k-=(n);}
  824. +
  825. +int lbits = 9;          /* bits in base literal/length lookup table */
  826. +int dbits = 6;          /* bits in base distance lookup table */
  827. +
  828. +
  829. +/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
  830. +#define BMAX 16         /* maximum bit length of any code (16 for explode) */
  831. +#define N_MAX 288       /* maximum number of codes in any set */
  832. +
  833. +
  834. +unsigned hufts;         /* track memory usage */
  835. +
  836. +
  837. +int huft_build(b, n, s, d, e, t, m)
  838. +unsigned *b;            /* code lengths in bits (all assumed <= BMAX) */
  839. +unsigned n;             /* number of codes (assumed <= N_MAX) */
  840. +unsigned s;             /* number of simple-valued codes (0..s-1) */
  841. +ush *d;                 /* list of base values for non-simple codes */
  842. +ush *e;                 /* list of extra bits for non-simple codes */
  843. +struct huft **t;        /* result: starting table */
  844. +int *m;                 /* maximum lookup bits, returns actual */
  845. +/* Given a list of code lengths and a maximum table size, make a set of
  846. +   tables to decode that set of codes.  Return zero on success, one if
  847. +   the given code set is incomplete (the tables are still built in this
  848. +   case), two if the input is invalid (all zero length codes or an
  849. +   oversubscribed set of lengths), and three if not enough memory. */
  850. +{
  851. +  unsigned a;                   /* counter for codes of length k */
  852. +  unsigned c[BMAX+1];           /* bit length count table */
  853. +  unsigned f;                   /* i repeats in table every f entries */
  854. +  int g;                        /* maximum code length */
  855. +  int h;                        /* table level */
  856. +  register unsigned i;          /* counter, current code */
  857. +  register unsigned j;          /* counter */
  858. +  register int k;               /* number of bits in current code */
  859. +  int l;                        /* bits per table (returned in m) */
  860. +  register unsigned *p;         /* pointer into c[], b[], or v[] */
  861. +  register struct huft *q;      /* points to current table */
  862. +  struct huft r;                /* table entry for structure assignment */
  863. +  struct huft *u[BMAX];         /* table stack */
  864. +  unsigned v[N_MAX];            /* values in order of bit length */
  865. +  register int w;               /* bits before this table == (l * h) */
  866. +  unsigned x[BMAX+1];           /* bit offsets, then code stack */
  867. +  unsigned *xp;                 /* pointer into x */
  868. +  int y;                        /* number of dummy codes added */
  869. +  unsigned z;                   /* number of entries in current table */
  870. +
  871. +DEBG("huft1 ");
  872. +
  873. +  /* Generate counts for each bit length */
  874. +  memzero(c, sizeof(c));
  875. +  p = b;  i = n;
  876. +  do {
  877. +    c[*p++]++;                  /* assume all entries <= BMAX */
  878. +  } while (--i);
  879. +  if (c[0] == n)                /* null input--all zero length codes */
  880. +  {
  881. +    *t = (struct huft *)NULL;
  882. +    *m = 0;
  883. +    return 0;
  884. +  }
  885. +
  886. +DEBG("huft2 ");
  887. +
  888. +  /* Find minimum and maximum length, bound *m by those */
  889. +  l = *m;
  890. +  for (j = 1; j <= BMAX; j++)
  891. +    if (c[j])
  892. +      break;
  893. +  k = j;                        /* minimum code length */
  894. +  if ((unsigned)l < j)
  895. +    l = j;
  896. +  for (i = BMAX; i; i--)
  897. +    if (c[i])
  898. +      break;
  899. +  g = i;                        /* maximum code length */
  900. +  if ((unsigned)l > i)
  901. +    l = i;
  902. +  *m = l;
  903. +
  904. +DEBG("huft3 ");
  905. +
  906. +  /* Adjust last length count to fill out codes, if needed */
  907. +  for (y = 1 << j; j < i; j++, y <<= 1)
  908. +    if ((y -= c[j]) < 0)
  909. +      return 2;                 /* bad input: more codes than bits */
  910. +  if ((y -= c[i]) < 0)
  911. +    return 2;
  912. +  c[i] += y;
  913. +
  914. +DEBG("huft4 ");
  915. +
  916. +  /* Generate starting offsets into the value table for each length */
  917. +  x[1] = j = 0;
  918. +  p = c + 1;  xp = x + 2;
  919. +  while (--i) {                 /* note that i == g from above */
  920. +    *xp++ = (j += *p++);
  921. +  }
  922. +
  923. +DEBG("huft5 ");
  924. +
  925. +  /* Make a table of values in order of bit lengths */
  926. +  p = b;  i = 0;
  927. +  do {
  928. +    if ((j = *p++) != 0)
  929. +      v[x[j]++] = i;
  930. +  } while (++i < n);
  931. +
  932. +DEBG("h6 ");
  933. +
  934. +  /* Generate the Huffman codes and for each, make the table entries */
  935. +  x[0] = i = 0;                 /* first Huffman code is zero */
  936. +  p = v;                        /* grab values in bit order */
  937. +  h = -1;                       /* no tables yet--level -1 */
  938. +  w = -l;                       /* bits decoded == (l * h) */
  939. +  u[0] = (struct huft *)NULL;   /* just to keep compilers happy */
  940. +  q = (struct huft *)NULL;      /* ditto */
  941. +  z = 0;                        /* ditto */
  942. +DEBG("h6a ");
  943. +
  944. +  /* go through the bit lengths (k already is bits in shortest code) */
  945. +  for (; k <= g; k++)
  946. +  {
  947. +DEBG("h6b ");
  948. +    a = c[k];
  949. +    while (a--)
  950. +    {
  951. +DEBG("h6b1 ");
  952. +      /* here i is the Huffman code of length k bits for value *p */
  953. +      /* make tables up to required level */
  954. +      while (k > w + l)
  955. +      {
  956. +DEBG1("1 ");
  957. +        h++;
  958. +        w += l;                 /* previous table always l bits */
  959. +
  960. +        /* compute minimum size table less than or equal to l bits */
  961. +        z = (z = g - w) > (unsigned)l ? l : z;  /* upper limit on table size */
  962. +        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
  963. +        {                       /* too few codes for k-w bit table */
  964. +DEBG1("2 ");
  965. +          f -= a + 1;           /* deduct codes from patterns left */
  966. +          xp = c + k;
  967. +          while (++j < z)       /* try smaller tables up to z bits */
  968. +          {
  969. +            if ((f <<= 1) <= *++xp)
  970. +              break;            /* enough codes to use up j bits */
  971. +            f -= *xp;           /* else deduct codes from patterns */
  972. +          }
  973. +        }
  974. +DEBG1("3 ");
  975. +        z = 1 << j;             /* table entries for j-bit table */
  976. +
  977. +        /* allocate and link in new table */
  978. +        q = (struct huft *)malloc((z + 1)*sizeof(struct huft));
  979. +DEBG1("4 ");
  980. +        hufts += z + 1;         /* track memory usage */
  981. +        *t = q + 1;             /* link to list for huft_free() */
  982. +        *(t = &(q->v.t)) = (struct huft *)NULL;
  983. +        u[h] = ++q;             /* table starts after link */
  984. +
  985. +DEBG1("5 ");
  986. +        /* connect to last table, if there is one */
  987. +        if (h)
  988. +        {
  989. +          x[h] = i;             /* save pattern for backing up */
  990. +          r.b = (uch)l;         /* bits to dump before this table */
  991. +          r.e = (uch)(16 + j);  /* bits in this table */
  992. +          r.v.t = q;            /* pointer to this table */
  993. +          j = i >> (w - l);     /* (get around Turbo C bug) */
  994. +          u[h-1][j] = r;        /* connect to last table */
  995. +        }
  996. +DEBG1("6 ");
  997. +      }
  998. +DEBG("h6c ");
  999. +
  1000. +      /* set up table entry in r */
  1001. +      r.b = (uch)(k - w);
  1002. +      if (p >= v + n)
  1003. +        r.e = 99;               /* out of values--invalid code */
  1004. +      else if (*p < s)
  1005. +      {
  1006. +        r.e = (uch)(*p < 256 ? 16 : 15);    /* 256 is end-of-block code */
  1007. +        r.v.n = *p++;           /* simple code is just the value */
  1008. +      }
  1009. +      else
  1010. +      {
  1011. +        r.e = (uch)e[*p - s];   /* non-simple--look up in lists */
  1012. +        r.v.n = d[*p++ - s];
  1013. +      }
  1014. +DEBG("h6d ");
  1015. +
  1016. +      /* fill code-like entries with r */
  1017. +      f = 1 << (k - w);
  1018. +      for (j = i >> w; j < z; j += f)
  1019. +        q[j] = r;
  1020. +
  1021. +      /* backwards increment the k-bit code i */
  1022. +      for (j = 1 << (k - 1); i & j; j >>= 1)
  1023. +        i ^= j;
  1024. +      i ^= j;
  1025. +
  1026. +      /* backup over finished tables */
  1027. +      while ((i & ((1 << w) - 1)) != x[h])
  1028. +      {
  1029. +        h--;                    /* don't need to update q */
  1030. +        w -= l;
  1031. +      }
  1032. +DEBG("h6e ");
  1033. +    }
  1034. +DEBG("h6f ");
  1035. +  }
  1036. +
  1037. +DEBG("huft7 ");
  1038. +
  1039. +  /* Return true (1) if we were given an incomplete table */
  1040. +  return y != 0 && g != 1;
  1041. +}
  1042. +
  1043. +
  1044. +
  1045. +int huft_free(t)
  1046. +struct huft *t;         /* table to free */
  1047. +/* Free the malloc'ed tables built by huft_build(), which makes a linked
  1048. +   list of the tables it made, with the links in a dummy first entry of
  1049. +   each table. */
  1050. +{
  1051. +  register struct huft *p, *q;
  1052. +
  1053. +
  1054. +  /* Go through linked list, freeing from the malloced (t[-1]) address. */
  1055. +  p = t;
  1056. +  while (p != (struct huft *)NULL)
  1057. +  {
  1058. +    q = (--p)->v.t;
  1059. +    free(p);
  1060. +    p = q;
  1061. +  } 
  1062. +  return 0;
  1063. +}
  1064. +
  1065. +
  1066. +int inflate_codes(tl, td, bl, bd)
  1067. +struct huft *tl, *td;   /* literal/length and distance decoder tables */
  1068. +int bl, bd;             /* number of bits decoded by tl[] and td[] */
  1069. +/* inflate (decompress) the codes in a deflated (compressed) block.
  1070. +   Return an error code or zero if it all goes ok. */
  1071. +{
  1072. +  register unsigned e;  /* table entry flag/number of extra bits */
  1073. +  unsigned n, d;        /* length and index for copy */
  1074. +  unsigned w;           /* current window position */
  1075. +  struct huft *t;       /* pointer to table entry */
  1076. +  unsigned ml, md;      /* masks for bl and bd bits */
  1077. +  register ulg b;       /* bit buffer */
  1078. +  register unsigned k;  /* number of bits in bit buffer */
  1079. +
  1080. +
  1081. +  /* make local copies of globals */
  1082. +  b = bb;                       /* initialize bit buffer */
  1083. +  k = bk;
  1084. +  w = wp;                       /* initialize window position */
  1085. +
  1086. +  /* inflate the coded data */
  1087. +  ml = mask_bits[bl];           /* precompute masks for speed */
  1088. +  md = mask_bits[bd];
  1089. +  for (;;)                      /* do until end of block */
  1090. +  {
  1091. +    NEEDBITS((unsigned)bl)
  1092. +    if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
  1093. +      do {
  1094. +        if (e == 99)
  1095. +          return 1;
  1096. +        DUMPBITS(t->b)
  1097. +        e -= 16;
  1098. +        NEEDBITS(e)
  1099. +      } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
  1100. +    DUMPBITS(t->b)
  1101. +    if (e == 16)                /* then it's a literal */
  1102. +    {
  1103. +      slide[w++] = (uch)t->v.n;
  1104. +      if (w == WSIZE)
  1105. +      {
  1106. +        flush_output(w);
  1107. +        w = 0;
  1108. +      }
  1109. +    }
  1110. +    else                        /* it's an EOB or a length */
  1111. +    {
  1112. +      /* exit if end of block */
  1113. +      if (e == 15)
  1114. +        break;
  1115. +
  1116. +      /* get length of block to copy */
  1117. +      NEEDBITS(e)
  1118. +      n = t->v.n + ((unsigned)b & mask_bits[e]);
  1119. +      DUMPBITS(e);
  1120. +
  1121. +      /* decode distance of block to copy */
  1122. +      NEEDBITS((unsigned)bd)
  1123. +      if ((e = (t = td + ((unsigned)b & md))->e) > 16)
  1124. +        do {
  1125. +          if (e == 99)
  1126. +            return 1;
  1127. +          DUMPBITS(t->b)
  1128. +          e -= 16;
  1129. +          NEEDBITS(e)
  1130. +        } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
  1131. +      DUMPBITS(t->b)
  1132. +      NEEDBITS(e)
  1133. +      d = w - t->v.n - ((unsigned)b & mask_bits[e]);
  1134. +      DUMPBITS(e)
  1135. +
  1136. +      /* do the copy */
  1137. +      do {
  1138. +        n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
  1139. +#if !defined(NOMEMCPY) && !defined(DEBUG)
  1140. +        if (w - d >= e)         /* (this test assumes unsigned comparison) */
  1141. +        {
  1142. +          memcpy(slide + w, slide + d, e);
  1143. +          w += e;
  1144. +          d += e;
  1145. +        }
  1146. +        else                      /* do it slow to avoid memcpy() overlap */
  1147. +#endif /* !NOMEMCPY */
  1148. +          do {
  1149. +            slide[w++] = slide[d++];
  1150. +          } while (--e);
  1151. +        if (w == WSIZE)
  1152. +        {
  1153. +          flush_output(w);
  1154. +          w = 0;
  1155. +        }
  1156. +      } while (n);
  1157. +    }
  1158. +  }
  1159. +
  1160. +
  1161. +  /* restore the globals from the locals */
  1162. +  wp = w;                       /* restore global window pointer */
  1163. +  bb = b;                       /* restore global bit buffer */
  1164. +  bk = k;
  1165. +
  1166. +  /* done */
  1167. +  return 0;
  1168. +}
  1169. +
  1170. +
  1171. +
  1172. +int inflate_stored()
  1173. +/* "decompress" an inflated type 0 (stored) block. */
  1174. +{
  1175. +  unsigned n;           /* number of bytes in block */
  1176. +  unsigned w;           /* current window position */
  1177. +  register ulg b;       /* bit buffer */
  1178. +  register unsigned k;  /* number of bits in bit buffer */
  1179. +
  1180. +DEBG("<stor");
  1181. +
  1182. +  /* make local copies of globals */
  1183. +  b = bb;                       /* initialize bit buffer */
  1184. +  k = bk;
  1185. +  w = wp;                       /* initialize window position */
  1186. +
  1187. +
  1188. +  /* go to byte boundary */
  1189. +  n = k & 7;
  1190. +  DUMPBITS(n);
  1191. +
  1192. +
  1193. +  /* get the length and its complement */
  1194. +  NEEDBITS(16)
  1195. +  n = ((unsigned)b & 0xffff);
  1196. +  DUMPBITS(16)
  1197. +  NEEDBITS(16)
  1198. +  if (n != (unsigned)((~b) & 0xffff))
  1199. +    return 1;                   /* error in compressed data */
  1200. +  DUMPBITS(16)
  1201. +
  1202. +
  1203. +  /* read and output the compressed data */
  1204. +  while (n--)
  1205. +  {
  1206. +    NEEDBITS(8)
  1207. +    slide[w++] = (uch)b;
  1208. +    if (w == WSIZE)
  1209. +    {
  1210. +      flush_output(w);
  1211. +      w = 0;
  1212. +    }
  1213. +    DUMPBITS(8)
  1214. +  }
  1215. +
  1216. +
  1217. +  /* restore the globals from the locals */
  1218. +  wp = w;                       /* restore global window pointer */
  1219. +  bb = b;                       /* restore global bit buffer */
  1220. +  bk = k;
  1221. +
  1222. +  DEBG(">");
  1223. +  return 0;
  1224. +}
  1225. +
  1226. +
  1227. +
  1228. +int inflate_fixed()
  1229. +/* decompress an inflated type 1 (fixed Huffman codes) block.  We should
  1230. +   either replace this with a custom decoder, or at least precompute the
  1231. +   Huffman tables. */
  1232. +{
  1233. +  int i;                /* temporary variable */
  1234. +  struct huft *tl;      /* literal/length code table */
  1235. +  struct huft *td;      /* distance code table */
  1236. +  int bl;               /* lookup bits for tl */
  1237. +  int bd;               /* lookup bits for td */
  1238. +  unsigned l[288];      /* length list for huft_build */
  1239. +
  1240. +DEBG("<fix");
  1241. +
  1242. +  /* set up literal table */
  1243. +  for (i = 0; i < 144; i++)
  1244. +    l[i] = 8;
  1245. +  for (; i < 256; i++)
  1246. +    l[i] = 9;
  1247. +  for (; i < 280; i++)
  1248. +    l[i] = 7;
  1249. +  for (; i < 288; i++)          /* make a complete, but wrong code set */
  1250. +    l[i] = 8;
  1251. +  bl = 7;
  1252. +  if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
  1253. +    return i;
  1254. +
  1255. +
  1256. +  /* set up distance table */
  1257. +  for (i = 0; i < 30; i++)      /* make an incomplete code set */
  1258. +    l[i] = 5;
  1259. +  bd = 5;
  1260. +  if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
  1261. +  {
  1262. +    huft_free(tl);
  1263. +
  1264. +    DEBG(">");
  1265. +    return i;
  1266. +  }
  1267. +
  1268. +
  1269. +  /* decompress until an end-of-block code */
  1270. +  if (inflate_codes(tl, td, bl, bd))
  1271. +    return 1;
  1272. +
  1273. +
  1274. +  /* free the decoding tables, return */
  1275. +  huft_free(tl);
  1276. +  huft_free(td);
  1277. +  return 0;
  1278. +}
  1279. +
  1280. +
  1281. +
  1282. +int inflate_dynamic()
  1283. +/* decompress an inflated type 2 (dynamic Huffman codes) block. */
  1284. +{
  1285. +  int i;                /* temporary variables */
  1286. +  unsigned j;
  1287. +  unsigned l;           /* last length */
  1288. +  unsigned m;           /* mask for bit lengths table */
  1289. +  unsigned n;           /* number of lengths to get */
  1290. +  struct huft *tl;      /* literal/length code table */
  1291. +  struct huft *td;      /* distance code table */
  1292. +  int bl;               /* lookup bits for tl */
  1293. +  int bd;               /* lookup bits for td */
  1294. +  unsigned nb;          /* number of bit length codes */
  1295. +  unsigned nl;          /* number of literal/length codes */
  1296. +  unsigned nd;          /* number of distance codes */
  1297. +#ifdef PKZIP_BUG_WORKAROUND
  1298. +  unsigned ll[288+32];  /* literal/length and distance code lengths */
  1299. +#else
  1300. +  unsigned ll[286+30];  /* literal/length and distance code lengths */
  1301. +#endif
  1302. +  register ulg b;       /* bit buffer */
  1303. +  register unsigned k;  /* number of bits in bit buffer */
  1304. +
  1305. +DEBG("<dyn");
  1306. +
  1307. +  /* make local bit buffer */
  1308. +  b = bb;
  1309. +  k = bk;
  1310. +
  1311. +
  1312. +  /* read in table lengths */
  1313. +  NEEDBITS(5)
  1314. +  nl = 257 + ((unsigned)b & 0x1f);      /* number of literal/length codes */
  1315. +  DUMPBITS(5)
  1316. +  NEEDBITS(5)
  1317. +  nd = 1 + ((unsigned)b & 0x1f);        /* number of distance codes */
  1318. +  DUMPBITS(5)
  1319. +  NEEDBITS(4)
  1320. +  nb = 4 + ((unsigned)b & 0xf);         /* number of bit length codes */
  1321. +  DUMPBITS(4)
  1322. +#ifdef PKZIP_BUG_WORKAROUND
  1323. +  if (nl > 288 || nd > 32)
  1324. +#else
  1325. +  if (nl > 286 || nd > 30)
  1326. +#endif
  1327. +    return 1;                   /* bad lengths */
  1328. +
  1329. +DEBG("dyn1 ");
  1330. +
  1331. +  /* read in bit-length-code lengths */
  1332. +  for (j = 0; j < nb; j++)
  1333. +  {
  1334. +    NEEDBITS(3)
  1335. +    ll[border[j]] = (unsigned)b & 7;
  1336. +    DUMPBITS(3)
  1337. +  }
  1338. +  for (; j < 19; j++)
  1339. +    ll[border[j]] = 0;
  1340. +
  1341. +DEBG("dyn2 ");
  1342. +
  1343. +  /* build decoding table for trees--single level, 7 bit lookup */
  1344. +  bl = 7;
  1345. +  if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
  1346. +  {
  1347. +    if (i == 1)
  1348. +      huft_free(tl);
  1349. +    return i;                   /* incomplete code set */
  1350. +  }
  1351. +
  1352. +DEBG("dyn3 ");
  1353. +
  1354. +  /* read in literal and distance code lengths */
  1355. +  n = nl + nd;
  1356. +  m = mask_bits[bl];
  1357. +  i = l = 0;
  1358. +  while ((unsigned)i < n)
  1359. +  {
  1360. +    NEEDBITS((unsigned)bl)
  1361. +    j = (td = tl + ((unsigned)b & m))->b;
  1362. +    DUMPBITS(j)
  1363. +    j = td->v.n;
  1364. +    if (j < 16)                 /* length of code in bits (0..15) */
  1365. +      ll[i++] = l = j;          /* save last length in l */
  1366. +    else if (j == 16)           /* repeat last length 3 to 6 times */
  1367. +    {
  1368. +      NEEDBITS(2)
  1369. +      j = 3 + ((unsigned)b & 3);
  1370. +      DUMPBITS(2)
  1371. +      if ((unsigned)i + j > n)
  1372. +        return 1;
  1373. +      while (j--)
  1374. +        ll[i++] = l;
  1375. +    }
  1376. +    else if (j == 17)           /* 3 to 10 zero length codes */
  1377. +    {
  1378. +      NEEDBITS(3)
  1379. +      j = 3 + ((unsigned)b & 7);
  1380. +      DUMPBITS(3)
  1381. +      if ((unsigned)i + j > n)
  1382. +        return 1;
  1383. +      while (j--)
  1384. +        ll[i++] = 0;
  1385. +      l = 0;
  1386. +    }
  1387. +    else                        /* j == 18: 11 to 138 zero length codes */
  1388. +    {
  1389. +      NEEDBITS(7)
  1390. +      j = 11 + ((unsigned)b & 0x7f);
  1391. +      DUMPBITS(7)
  1392. +      if ((unsigned)i + j > n)
  1393. +        return 1;
  1394. +      while (j--)
  1395. +        ll[i++] = 0;
  1396. +      l = 0;
  1397. +    }
  1398. +  }
  1399. +
  1400. +DEBG("dyn4 ");
  1401. +
  1402. +  /* free decoding table for trees */
  1403. +  huft_free(tl);
  1404. +
  1405. +DEBG("dyn5 ");
  1406. +
  1407. +  /* restore the global bit buffer */
  1408. +  bb = b;
  1409. +  bk = k;
  1410. +
  1411. +DEBG("dyn5a ");
  1412. +
  1413. +  /* build the decoding tables for literal/length and distance codes */
  1414. +  bl = lbits;
  1415. +  if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
  1416. +  {
  1417. +DEBG("dyn5b ");
  1418. +    if (i == 1) {
  1419. +      error(" incomplete literal tree\n");
  1420. +      huft_free(tl);
  1421. +    }
  1422. +    return i;                   /* incomplete code set */
  1423. +  }
  1424. +DEBG("dyn5c ");
  1425. +  bd = dbits;
  1426. +  if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
  1427. +  {
  1428. +DEBG("dyn5d ");
  1429. +    if (i == 1) {
  1430. +      error(" incomplete distance tree\n");
  1431. +#ifdef PKZIP_BUG_WORKAROUND
  1432. +      i = 0;
  1433. +    }
  1434. +#else
  1435. +      huft_free(td);
  1436. +    }
  1437. +    huft_free(tl);
  1438. +    return i;                   /* incomplete code set */
  1439. +#endif
  1440. +  }
  1441. +
  1442. +DEBG("dyn6 ");
  1443. +
  1444. +  /* decompress until an end-of-block code */
  1445. +  if (inflate_codes(tl, td, bl, bd))
  1446. +    return 1;
  1447. +
  1448. +DEBG("dyn7 ");
  1449. +
  1450. +  /* free the decoding tables, return */
  1451. +  huft_free(tl);
  1452. +  huft_free(td);
  1453. +
  1454. +  DEBG(">");
  1455. +  return 0;
  1456. +}
  1457. +
  1458. +
  1459. +
  1460. +int inflate_block(e)
  1461. +int *e;                 /* last block flag */
  1462. +/* decompress an inflated block */
  1463. +{
  1464. +  unsigned t;           /* block type */
  1465. +  register ulg b;       /* bit buffer */
  1466. +  register unsigned k;  /* number of bits in bit buffer */
  1467. +
  1468. +  DEBG("<blk");
  1469. +
  1470. +  /* make local bit buffer */
  1471. +  b = bb;
  1472. +  k = bk;
  1473. +
  1474. +
  1475. +  /* read in last block bit */
  1476. +  NEEDBITS(1)
  1477. +  *e = (int)b & 1;
  1478. +  DUMPBITS(1)
  1479. +
  1480. +
  1481. +  /* read in block type */
  1482. +  NEEDBITS(2)
  1483. +  t = (unsigned)b & 3;
  1484. +  DUMPBITS(2)
  1485. +
  1486. +
  1487. +  /* restore the global bit buffer */
  1488. +  bb = b;
  1489. +  bk = k;
  1490. +
  1491. +  /* inflate that block type */
  1492. +  if (t == 2)
  1493. +    return inflate_dynamic();
  1494. +  if (t == 0)
  1495. +    return inflate_stored();
  1496. +  if (t == 1)
  1497. +    return inflate_fixed();
  1498. +
  1499. +  DEBG(">");
  1500. +
  1501. +  /* bad block type */
  1502. +  return 2;
  1503. +}
  1504. +
  1505. +
  1506. +
  1507. +int inflate()
  1508. +/* decompress an inflated entry */
  1509. +{
  1510. +  int e;                /* last block flag */
  1511. +  int r;                /* result code */
  1512. +  unsigned h;           /* maximum struct huft's malloc'ed */
  1513. +
  1514. +
  1515. +  /* initialize window, bit buffer */
  1516. +  wp = 0;
  1517. +  bk = 0;
  1518. +  bb = 0;
  1519. +
  1520. +
  1521. +  /* decompress until the last block */
  1522. +  h = 0;
  1523. +  do {
  1524. +    hufts = 0;
  1525. +    if ((r = inflate_block(&e)) != 0)
  1526. +      return r;
  1527. +    if (hufts > h)
  1528. +      h = hufts;
  1529. +  } while (!e);
  1530. +
  1531. +  /* Undo too much lookahead. The next read will be byte aligned so we
  1532. +   * can discard unused bits in the last meaningful byte.
  1533. +   */
  1534. +  while (bk >= 8) {
  1535. +    bk -= 8;
  1536. +    inptr--;
  1537. +  }
  1538. +
  1539. +  /* flush out slide */
  1540. +  flush_output(wp);
  1541. +
  1542. +
  1543. +  /* return success */
  1544. +#ifdef DEBUG
  1545. +  fprintf(stderr, "<%u> ", h);
  1546. +#endif /* DEBUG */
  1547. +  return 0;
  1548. +}
  1549. diff -u --recursive --new-file linux-1.2.11/drivers/block/rd_gz_unzip.c linux/drivers/block/rd_gz_unzip.c
  1550. --- linux-1.2.11/drivers/block/rd_gz_unzip.c    Wed Dec 31 17:00:00 1969
  1551. +++ linux/drivers/block/rd_gz_unzip.c    Sun Jul 16 20:48:01 1995
  1552. @@ -0,0 +1,185 @@
  1553. +/* unzip.c -- decompress files in gzip or pkzip format.
  1554. + * Copyright (C) 1992-1993 Jean-loup Gailly
  1555. + *
  1556. + * Adapted for Linux booting by Hannu Savolainen 1993
  1557. + *
  1558. + * This is free software; you can redistribute it and/or modify it under the
  1559. + * terms of the GNU General Public License, see the file COPYING.
  1560. + *
  1561. + * The code in this file is derived from the file funzip.c written
  1562. + * and put in the public domain by Mark Adler.
  1563. + */
  1564. +
  1565. +/*
  1566. +   This version can extract files in gzip or pkzip format.
  1567. +   For the latter, only the first entry is extracted, and it has to be
  1568. +   either deflated or stored.
  1569. + */
  1570. +
  1571. +#ifndef lint
  1572. +static char rcsid[] = "$Id: unzip.c,v 0.9 1993/02/10 16:07:22 jloup Exp $";
  1573. +#endif
  1574. +
  1575. +#include <linux/malloc.h>
  1576. +#include <linux/kernel.h>
  1577. +
  1578. +#include <linux/rd_gz_gzip.h>
  1579. +#include <linux/rd_gz_crypt.h>
  1580. +
  1581. +#include <stdio.h>
  1582. +
  1583. +/* PKZIP header definitions */
  1584. +#define LOCSIG 0x04034b50L      /* four-byte lead-in (lsb first) */
  1585. +#define LOCFLG 6                /* offset of bit flag */
  1586. +#define  CRPFLG 1               /*  bit for encrypted entry */
  1587. +#define  EXTFLG 8               /*  bit for extended local header */
  1588. +#define LOCHOW 8                /* offset of compression method */
  1589. +#define LOCTIM 10               /* file mod time (for decryption) */
  1590. +#define LOCCRC 14               /* offset of crc */
  1591. +#define LOCSIZ 18               /* offset of compressed size */
  1592. +#define LOCLEN 22               /* offset of uncompressed length */
  1593. +#define LOCFIL 26               /* offset of file name field length */
  1594. +#define LOCEXT 28               /* offset of extra field length */
  1595. +#define LOCHDR 30               /* size of local header, including sig */
  1596. +#define EXTHDR 16               /* size of extended local header, inc sig */
  1597. +
  1598. +
  1599. +/* Globals */
  1600. +
  1601. +int decrypt;      /* flag to turn on decryption */
  1602. +char *key;        /* not used--needed to link crypt.c */
  1603. +int pkzip = 0;    /* set for a pkzip file */
  1604. +int extended = 0; /* set if extended local header */
  1605. +
  1606. +/* ===========================================================================
  1607. + * Check zip file and advance inptr to the start of the compressed data.
  1608. + * Get ofname from the local header if necessary.
  1609. + */
  1610. +int check_zipfile(in)
  1611. +    int in;   /* input file descriptors */
  1612. +{
  1613. +    uch *h = inbuf + inptr; /* first local header */
  1614. +
  1615. +    /* ifd = in; */
  1616. +
  1617. +    /* Check validity of local header, and skip name and extra fields */
  1618. +    inptr += LOCHDR + SH(h + LOCFIL) + SH(h + LOCEXT);
  1619. +
  1620. +    if (inptr > insize || LG(h) != LOCSIG) {
  1621. +    error("input not a zip");
  1622. +    }
  1623. +    method = h[LOCHOW];
  1624. +    if (method != STORED && method != DEFLATED) {
  1625. +    error("first entry not deflated or stored--can't extract");
  1626. +    }
  1627. +
  1628. +    /* If entry encrypted, decrypt and validate encryption header */
  1629. +    if ((decrypt = h[LOCFLG] & CRPFLG) != 0) {
  1630. +    error("encrypted file\n");
  1631. +    exit_code = ERROR;
  1632. +    return -1;
  1633. +    }
  1634. +
  1635. +    /* Save flags for unzip() */
  1636. +    extended = (h[LOCFLG] & EXTFLG) != 0;
  1637. +    pkzip = 1;
  1638. +
  1639. +    /* Get ofname and time stamp from local header (to be done) */
  1640. +    return 0;
  1641. +}
  1642. +
  1643. +/* ===========================================================================
  1644. + * Unzip in to out.  This routine works on both gzip and pkzip files.
  1645. + *
  1646. + * IN assertions: the buffer inbuf contains already the beginning of
  1647. + *   the compressed data, from offsets inptr to insize-1 included.
  1648. + *   The magic header has already been checked. The output buffer is cleared.
  1649. + */
  1650. +void unzip(in, out)
  1651. +    int in, out;   /* input and output file descriptors */
  1652. +{
  1653. +    ulg orig_crc = 0;       /* original crc */
  1654. +    ulg orig_len = 0;       /* original uncompressed length */
  1655. +    int n;
  1656. +    uch buf[EXTHDR];        /* extended local header */
  1657. +
  1658. +    /* ifd = in;
  1659. +    ofd = out; */
  1660. +
  1661. +    updcrc(NULL, 0);           /* initialize crc */
  1662. +
  1663. +    if (pkzip && !extended) {  /* crc and length at the end otherwise */
  1664. +    orig_crc = LG(inbuf + LOCCRC);
  1665. +    orig_len = LG(inbuf + LOCLEN);
  1666. +    }
  1667. +
  1668. +    printk("%d\n", inptr); 
  1669. +
  1670. +    /* Decompress */
  1671. +    if (method == DEFLATED)  {
  1672. +
  1673. +    int res = inflate();
  1674. +
  1675. +    if (res == 3) {
  1676. +        error("out of memory");
  1677. +    } else if (res != 0) {
  1678. +        error("invalid compressed format");
  1679. +    }
  1680. +
  1681. +    } else if (pkzip && method == STORED) {
  1682. +
  1683. +    register ulg n = LG(inbuf + LOCLEN);
  1684. +
  1685. +    if (n != LG(inbuf + LOCSIZ) - (decrypt ? RAND_HEAD_LEN : 0)) {
  1686. +
  1687. +        error("length mismatch");
  1688. +    }
  1689. +    while (n--) {
  1690. +        uch c = (uch)get_byte();
  1691. +#ifdef CRYPT
  1692. +        if (decrypt) zdecode(c);
  1693. +#endif
  1694. +        if (!test) put_char(c);
  1695. +    }
  1696. +    } else {
  1697. +    error("internal error, invalid method");
  1698. +    }
  1699. +
  1700. +    /* Get the crc and original length */
  1701. +    if (!pkzip) {
  1702. +        /* crc32  (see algorithm.doc)
  1703. +     * uncompressed input size modulo 2^32
  1704. +         */
  1705. +    for (n = 0; n < 8; n++) {
  1706. +        buf[n] = (uch)get_byte(); /* may cause an error if EOF */
  1707. +    }
  1708. +    orig_crc = LG(buf);
  1709. +    orig_len = LG(buf+4);
  1710. +
  1711. +    } else if (extended) {  /* If extended header, check it */
  1712. +    /* signature - 4bytes: 0x50 0x4b 0x07 0x08
  1713. +     * CRC-32 value
  1714. +         * compressed size 4-bytes
  1715. +         * uncompressed size 4-bytes
  1716. +     */
  1717. +    for (n = 0; n < EXTHDR; n++) {
  1718. +        buf[n] = (uch)get_byte(); /* may cause an error if EOF */
  1719. +    }
  1720. +    orig_crc = LG(buf+4);
  1721. +    orig_len = LG(buf+12);
  1722. +    }
  1723. +
  1724. +    /* Validate decompression */
  1725. +    if (orig_crc != updcrc(outbuf, 0)) {
  1726. +    error("crc error");
  1727. +    }
  1728. +    if (orig_len != bytes_out) {
  1729. +    error("length error");
  1730. +    }
  1731. +
  1732. +    /* Check if there are more entries in a pkzip file */
  1733. +    if (pkzip && inptr + 4 < insize && LG(inbuf+inptr) == LOCSIG) {
  1734. +        error("zip file has more than one entry");
  1735. +    }
  1736. +    extended = pkzip = 0; /* for next file */
  1737. +}
  1738. diff -u --recursive --new-file linux-1.2.11/fs/buffer.c linux/fs/buffer.c
  1739. --- linux-1.2.11/fs/buffer.c    Sun Jul 16 20:46:16 1995
  1740. +++ linux/fs/buffer.c    Sun Jul 16 20:48:01 1995
  1741. @@ -185,7 +185,7 @@
  1742.               if (!bh->b_dirt || pass>=2)
  1743.                    continue;
  1744.               /* don't bother about locked buffers */
  1745. -             if (bh->b_lock)
  1746. +             if (bh->b_lock || bh->b_prot)
  1747.                   continue;
  1748.               bh->b_count++;
  1749.               bh->b_flushtime = 0;
  1750. @@ -262,6 +262,8 @@
  1751.          for (i = nr_buffers_type[nlist]*2 ; --i > 0 ; bh = bh->b_next_free) {
  1752.              if (bh->b_dev != dev)
  1753.                  continue;
  1754. +            if (bh->b_prot)
  1755. +                continue;    
  1756.              wait_on_buffer(bh);
  1757.              if (bh->b_dev != dev)
  1758.                  continue;
  1759. @@ -563,7 +565,7 @@
  1760.                   continue;
  1761.               };
  1762.               
  1763. -             if (bh->b_count || bh->b_size != size)
  1764. +             if (bh->b_prot || bh->b_count || bh->b_size != size)
  1765.                    continue;
  1766.               
  1767.               /* Buffers are written in the order they are placed 
  1768. @@ -605,6 +607,8 @@
  1769.          if(candidate[i] == bh) candidate[i] = NULL;  /* Got last one */
  1770.          if (bh->b_count || bh->b_size != size)
  1771.               panic("Busy buffer in candidate list\n");
  1772. +        if (bh->b_prot)
  1773. +            panic ("Protected buffer in candidate list\n");    
  1774.          if (mem_map[MAP_NR((unsigned long) bh->b_data)] != 1)
  1775.               panic("Shared buffer in candidate list\n");
  1776.          if (BADNESS(bh)) panic("Buffer in candidate list with BADNESS != 0\n");
  1777. @@ -634,7 +638,7 @@
  1778.                      continue;
  1779.                  };
  1780.                  
  1781. -                if (bh->b_count || bh->b_size != size)
  1782. +                if (bh->b_prot || bh->b_count || bh->b_size != size)
  1783.                       continue;
  1784.                  
  1785.                  /* Buffers are written in the order they are
  1786. @@ -1064,6 +1068,7 @@
  1787.      while (1) {
  1788.          arr[block++] = bh;
  1789.          bh->b_count = 1;
  1790. +        bh->b_prot = 0;    
  1791.          bh->b_dirt = 0;
  1792.          bh->b_flushtime = 0;
  1793.          bh->b_uptodate = 0;
  1794. @@ -1233,7 +1238,7 @@
  1795.      do {
  1796.          if (!tmp)
  1797.              return 0;
  1798. -        if (tmp->b_count || tmp->b_dirt || tmp->b_lock || tmp->b_wait)
  1799. +        if (tmp->b_prot || tmp->b_count || tmp->b_dirt || tmp->b_lock || tmp->b_wait)
  1800.              return 0;
  1801.          tmp = tmp->b_this_page;
  1802.      } while (tmp != bh);
  1803. @@ -1347,7 +1352,7 @@
  1804.          bh = free_list[isize];
  1805.          if(!bh) continue;
  1806.          for (i=0 ; !i || bh != free_list[isize]; bh = bh->b_next_free, i++) {
  1807. -            if (bh->b_count || !bh->b_this_page)
  1808. +            if (bh->b_count || bh->b_prot || !bh->b_this_page)
  1809.                   continue;
  1810.              if (try_to_free(bh, &bh))
  1811.                   return 1;
  1812. @@ -1367,7 +1372,7 @@
  1813.          for ( ; i-- > 0 ; bh = bh->b_next_free) {
  1814.              /* We may have stalled while waiting for I/O to complete. */
  1815.              if(bh->b_list != nlist) goto repeat1;
  1816. -            if (bh->b_count || !bh->b_this_page)
  1817. +            if (bh->b_prot || bh->b_count || !bh->b_this_page)
  1818.                   continue;
  1819.              if(size && bh->b_size != size) continue;
  1820.              if (bh->b_lock)
  1821. @@ -1396,7 +1401,7 @@
  1822.  void show_buffers(void)
  1823.  {
  1824.      struct buffer_head * bh;
  1825. -    int found = 0, locked = 0, dirty = 0, used = 0, lastused = 0;
  1826. +    int found = 0, locked = 0, protected = 0, dirty = 0, used = 0, lastused = 0;
  1827.      int shared;
  1828.      int nlist, isize;
  1829.  
  1830. @@ -1405,13 +1410,15 @@
  1831.      printk("Buffer blocks:   %6d\n",nr_buffers);
  1832.  
  1833.      for(nlist = 0; nlist < NR_LIST; nlist++) {
  1834. -      shared = found = locked = dirty = used = lastused = 0;
  1835. +      shared = found = locked = dirty = used = protected = lastused = 0;
  1836.        bh = lru_list[nlist];
  1837.        if(!bh) continue;
  1838.        do {
  1839.          found++;
  1840.          if (bh->b_lock)
  1841.              locked++;
  1842. +        if (bh->b_prot)
  1843. +            protected++;
  1844.          if (bh->b_dirt)
  1845.              dirty++;
  1846.          if(mem_map[MAP_NR(((unsigned long) bh->b_data))] !=1) shared++;
  1847. @@ -1419,8 +1426,8 @@
  1848.              used++, lastused = found;
  1849.          bh = bh->b_next_free;
  1850.            } while (bh != lru_list[nlist]);
  1851. -    printk("Buffer[%d] mem: %d buffers, %d used (last=%d), %d locked, %d dirty %d shrd\n",
  1852. -        nlist, found, used, lastused, locked, dirty, shared);
  1853. +    printk("Buffer[%d] mem: %d buffers, %d used (last=%d), %d locked, %d protected %d dirty %d shrd\n",
  1854. +        nlist, found, used, lastused, locked, protected, dirty, shared);
  1855.      };
  1856.      printk("Size    [LAV]     Free  Clean  Unshar     Lck    Lck1   Dirty  Shared\n");
  1857.      for(isize = 0; isize<NR_SIZES; isize++){
  1858. @@ -1453,8 +1460,7 @@
  1859.      do {
  1860.          if (!tmp)
  1861.               return 0;
  1862. -        
  1863. -        if (tmp->b_count || tmp->b_dirt || tmp->b_lock)
  1864. +        if (tmp->b_prot || tmp->b_count || tmp->b_dirt || tmp->b_lock)
  1865.               return 0;
  1866.          tmp = tmp->b_this_page;
  1867.      } while (tmp != bh);
  1868. @@ -1548,6 +1554,7 @@
  1869.          bh->b_dirt = 0;
  1870.          bh->b_flushtime = 0;
  1871.          bh->b_lock = 0;
  1872. +        bh->b_prot = 0;
  1873.          bh->b_uptodate = 0;
  1874.          bh->b_req = 0;
  1875.          bh->b_dev = dev;
  1876. @@ -1719,7 +1726,7 @@
  1877.                        continue;
  1878.                    }
  1879.                   
  1880. -                 if (bh->b_lock || !bh->b_dirt)
  1881. +                 if (bh->b_lock || !bh->b_dirt || bh->b_prot)
  1882.                        continue;
  1883.                   ndirty++;
  1884.                   if(bh->b_flushtime > jiffies) continue;
  1885. diff -u --recursive --new-file linux-1.2.11/include/linux/fs.h linux/include/linux/fs.h
  1886. --- linux-1.2.11/include/linux/fs.h    Sun Jul 16 20:46:21 1995
  1887. +++ linux/include/linux/fs.h    Sun Jul 16 20:48:01 1995
  1888. @@ -136,6 +136,7 @@
  1889.      unsigned short b_count;        /* users using this block */
  1890.      unsigned char b_uptodate;
  1891.      unsigned char b_dirt;        /* 0-clean,1-dirty */
  1892. +    unsigned char b_prot;        /* 0-regular,1-protected */
  1893.      unsigned char b_lock;        /* 0 - ok, 1 -locked */
  1894.      unsigned char b_req;        /* 0 if the buffer has been invalidated */
  1895.      unsigned char b_list;        /* List that this buffer appears */
  1896. diff -u --recursive --new-file linux-1.2.11/include/linux/rd_gz_crypt.h linux/include/linux/rd_gz_crypt.h
  1897. --- linux-1.2.11/include/linux/rd_gz_crypt.h    Wed Dec 31 17:00:00 1969
  1898. +++ linux/include/linux/rd_gz_crypt.h    Sun Jul 16 20:48:01 1995
  1899. @@ -0,0 +1,12 @@
  1900. +/* crypt.h (dummy version) -- do not perform encryption
  1901. + * Hardly worth copyrighting :-)
  1902. + */
  1903. +
  1904. +#ifdef CRYPT
  1905. +#  undef CRYPT      /* dummy version */
  1906. +#endif
  1907. +
  1908. +#define RAND_HEAD_LEN  12  /* length of encryption random header */
  1909. +
  1910. +#define zencode
  1911. +#define zdecode
  1912. diff -u --recursive --new-file linux-1.2.11/include/linux/rd_gz_gzip.h linux/include/linux/rd_gz_gzip.h
  1913. --- linux-1.2.11/include/linux/rd_gz_gzip.h    Wed Dec 31 17:00:00 1969
  1914. +++ linux/include/linux/rd_gz_gzip.h    Sun Jul 16 20:48:01 1995
  1915. @@ -0,0 +1,278 @@
  1916. +/* gzip.h -- common declarations for all gzip modules
  1917. + * Copyright (C) 1992-1993 Jean-loup Gailly.
  1918. + * This is free software; you can redistribute it and/or modify it under the
  1919. + * terms of the GNU General Public License, see the file COPYING.
  1920. + */
  1921. +
  1922. +#if defined(__STDC__) || defined(PROTO)
  1923. +#  define OF(args)  args
  1924. +#else
  1925. +#  define OF(args)  ()
  1926. +#endif
  1927. +
  1928. +#ifdef __STDC__
  1929. +   typedef void *voidp;
  1930. +#else
  1931. +   typedef char *voidp;
  1932. +#endif
  1933. +
  1934. +#ifndef NULL
  1935. +#define NULL 0
  1936. +#endif
  1937. +#define memzero(s, n) memset((s), 0, (n))
  1938. +#define malloc(size) kmalloc(size, GFP_KERNEL)
  1939. +#define free(ptr) kfree_s((ptr), 0)
  1940. +
  1941. +#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
  1942. +#  include <memory.h>
  1943. +#endif
  1944. +
  1945. +#ifndef RETSIGTYPE
  1946. +#  define RETSIGTYPE void
  1947. +#endif
  1948. +
  1949. +#define local static
  1950. +
  1951. +typedef unsigned char  uch;
  1952. +typedef unsigned short ush;
  1953. +typedef unsigned long  ulg;
  1954. +
  1955. +/* Return codes from gzip */
  1956. +#define OK      0
  1957. +#define ERROR   1
  1958. +#define WARNING 2
  1959. +
  1960. +/* Compression methods (see algorithm.doc) */
  1961. +#define STORED     0
  1962. +#define COMPRESSED 1
  1963. +#define PACKED     2
  1964. +/* methods 3 to 7 reserved */
  1965. +#define DEFLATED   8
  1966. +extern int method;         /* compression method */
  1967. +
  1968. +/* To save memory for 16 bit systems, some arrays are overlayed between
  1969. + * the various modules:
  1970. + * deflate:  prev+head   window      d_buf  l_buf  outbuf
  1971. + * unlzw:    tab_prefix  tab_suffix  stack  inbuf  outbuf
  1972. + * inflate:              window             inbuf
  1973. + * unpack:               window             inbuf
  1974. + * For compression, input is done in window[]. For decompression, output
  1975. + * is done in window except for unlzw.
  1976. + */
  1977. +
  1978. +#ifndef    INBUFSIZ
  1979. +#  define INBUFSIZ  0x800  /* input buffer size */
  1980. +#endif
  1981. +#define INBUF_EXTRA  64     /* required by unlzw() */
  1982. +
  1983. +#ifndef    OUTBUFSIZ
  1984. +#  define OUTBUFSIZ  0x800000  /* output buffer size */
  1985. +#endif
  1986. +#define OUTBUF_EXTRA 2048   /* required by unlzw() */
  1987. +
  1988. +#define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */
  1989. +
  1990. +#ifdef DYN_ALLOC
  1991. +#  define EXTERN(type, array)  extern type * near array
  1992. +#  define DECLARE(type, array, size)  type * near array
  1993. +#  define ALLOC(type, array, size) { \
  1994. +      array = (type*)fcalloc((unsigned)(((size)+1L)/2), 2*sizeof(type)); \
  1995. +      if (array == NULL) error("insufficient memory"); \
  1996. +   }
  1997. +#  define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
  1998. +#else
  1999. +#  define EXTERN(type, array)  extern type array[]
  2000. +#  define DECLARE(type, array, size)  type array[size]
  2001. +#  define ALLOC(type, array, size)
  2002. +#  define FREE(array)
  2003. +#endif
  2004. +
  2005. +EXTERN(uch, inbuf);
  2006. +extern unsigned char * outbuf;
  2007. +EXTERN(ush, d_buf);          /* buffer for distances, see trees.c */
  2008. +EXTERN(uch, window);         /* Sliding window and suffix table (unlzw) */
  2009. +#define tab_suffix window
  2010. +#ifndef MAXSEG_64K
  2011. +#  define tab_prefix prev    /* hash link (see deflate.c) */
  2012. +#  define head (prev+WSIZE)  /* hash head (see deflate.c) */
  2013. +   EXTERN(ush, tab_prefix);  /* prefix code (see unlzw.c) */
  2014. +#else
  2015. +#  define tab_prefix0 prev
  2016. +#  define head tab_prefix1
  2017. +   EXTERN(ush, tab_prefix0); /* prefix for even codes */
  2018. +   EXTERN(ush, tab_prefix1); /* prefix for odd  codes */
  2019. +#endif
  2020. +
  2021. +extern unsigned insize; /* valid bytes in inbuf */
  2022. +extern unsigned inptr;  /* index of next byte to be processed in inbuf */
  2023. +extern unsigned outcnt; /* bytes in output buffer */
  2024. +
  2025. +extern long bytes_in;   /* number of input bytes */
  2026. +extern long bytes_out;  /* number of output bytes */
  2027. +extern long overhead;   /* number of bytes in gzip header */
  2028. +
  2029. +#define isize bytes_in
  2030. +/* for compatibility with old zip sources (to be cleaned) */
  2031. +
  2032. +extern int  ifd;        /* input file descriptor */
  2033. +extern int  ofd;        /* output file descriptor */
  2034. +extern char ifname[];   /* input filename or "stdin" */
  2035. +extern char ofname[];   /* output filename or "stdout" */
  2036. +
  2037. +extern ulg time_stamp;  /* original time stamp (modification time) */
  2038. +extern long ifile_size; /* input file size, -1 for devices (debug only) */
  2039. +
  2040. +extern int exit_code;   /* program exit code */
  2041. +
  2042. +typedef int file_t;     /* Do not use stdio */
  2043. +#define NO_FILE  (-1)   /* in memory compression */
  2044. +
  2045. +
  2046. +#define    GZIP_MAGIC     "\037\213" /* Magic header for gzip files, 1F 8B */
  2047. +#define    OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */
  2048. +#define    PKZIP_MAGIC  "PK\003\004" /* Magic header for pkzip files */
  2049. +#define    PACK_MAGIC     "\037\036" /* Magic header for packed files */
  2050. +
  2051. +/* gzip flag byte */
  2052. +#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
  2053. +#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
  2054. +#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
  2055. +#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
  2056. +#define COMMENT      0x10 /* bit 4 set: file comment present */
  2057. +#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
  2058. +#define RESERVED     0xC0 /* bit 6,7:   reserved */
  2059. +
  2060. +/* internal file attribute */
  2061. +#define UNKNOWN (-1)
  2062. +#define BINARY  0
  2063. +#define ASCII   1
  2064. +
  2065. +#ifndef WSIZE
  2066. +#  define WSIZE 0x8000     /* window size--must be a power of two, and */
  2067. +#endif                     /*  at least 32K for zip's deflate method */
  2068. +
  2069. +#define MIN_MATCH  3
  2070. +#define MAX_MATCH  258
  2071. +/* The minimum and maximum match lengths */
  2072. +
  2073. +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  2074. +/* Minimum amount of lookahead, except at the end of the input file.
  2075. + * See deflate.c for comments about the MIN_MATCH+1.
  2076. + */
  2077. +
  2078. +#define MAX_DIST  (WSIZE-MIN_LOOKAHEAD)
  2079. +/* In order to simplify the code, particularly on 16 bit machines, match
  2080. + * distances are limited to MAX_DIST instead of WSIZE.
  2081. + */
  2082. +
  2083. +extern int decrypt;        /* flag to turn on decryption */
  2084. +extern int save_orig_name; /* set if original name must be saved */
  2085. +extern int verbose;        /* be verbose (-v) */
  2086. +extern int level;          /* compression level */
  2087. +extern int test;           /* check .z file integrity */
  2088. +extern int to_stdout;      /* output to stdout (-c) */
  2089. +
  2090. +extern int get_byte(void); 
  2091. +
  2092. +/* put_byte is used for the compressed output, put_char for the
  2093. + * uncompressed output. However unlzw() uses window for its
  2094. + * suffix table instead of its output buffer, so it does not use put_char.
  2095. + * (to be cleaned up).
  2096. + */
  2097. +#define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
  2098. +   flush_outbuf();}
  2099. +#define put_char(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
  2100. +   flush_window();}
  2101. +
  2102. +/* Output a 16 bit value, lsb first */
  2103. +#define put_short(w) \
  2104. +{ if (outcnt < OUTBUFSIZ-2) { \
  2105. +    outbuf[outcnt++] = (uch) ((w) & 0xff); \
  2106. +    outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
  2107. +  } else { \
  2108. +    put_byte((uch)((w) & 0xff)); \
  2109. +    put_byte((uch)((ush)(w) >> 8)); \
  2110. +  } \
  2111. +}
  2112. +
  2113. +/* Output a 32 bit value to the bit stream, lsb first */
  2114. +#define put_long(n) { \
  2115. +    put_short((n) & 0xffff); \
  2116. +    put_short(((ulg)(n)) >> 16); \
  2117. +}
  2118. +
  2119. +#define seekable()    0  /* force sequential output */
  2120. +#define translate_eol 0  /* no option -a yet */
  2121. +
  2122. +#define tolow(c)  (isupper(c) ? (c)-'A'+'a' : (c))    /* force to lower case */
  2123. +
  2124. +/* Macros for getting two-byte and four-byte header values */
  2125. +#define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
  2126. +#define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
  2127. +
  2128. +/* Diagnostic functions */
  2129. +#ifdef DEBUG
  2130. +#  define Assert(cond,msg) {if(!(cond)) error(msg);}
  2131. +#  define Trace(x) fprintf x
  2132. +#  define Tracev(x) {if (verbose) fprintf x ;}
  2133. +#  define Tracevv(x) {if (verbose>1) fprintf x ;}
  2134. +#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
  2135. +#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
  2136. +#else
  2137. +#  define Assert(cond,msg)
  2138. +#  define Trace(x)
  2139. +#  define Tracev(x)
  2140. +#  define Tracevv(x)
  2141. +#  define Tracec(c,x)
  2142. +#  define Tracecv(c,x)
  2143. +#endif
  2144. +
  2145. +    /* in zip.c: */
  2146. +extern void zip    OF((int in, int out));
  2147. +extern int file_read  OF((char *buf,  unsigned size));
  2148. +
  2149. +    /* in unzip.c */
  2150. +extern void unzip        OF((int in, int out));
  2151. +extern int check_zipfile OF((int in));
  2152. +
  2153. +    /* in unpack.c */
  2154. +extern void unpack        OF((int in, int out));
  2155. +
  2156. +    /* in gzip.c */
  2157. +RETSIGTYPE abort_gzip   OF((void));
  2158. +
  2159. +        /* in deflate.c */
  2160. +void lm_init OF((int pack_level, ush *flags));
  2161. +ulg  deflate OF((void));
  2162. +
  2163. +        /* in trees.c */
  2164. +void ct_init     OF((ush *attr, int *method));
  2165. +int  ct_tally    OF((int dist, int lc));
  2166. +ulg  flush_block OF((char *buf, ulg stored_len, int eof));
  2167. +
  2168. +        /* in bits.c */
  2169. +void     bi_init    OF((file_t zipfile));
  2170. +void     send_bits  OF((int value, int length));
  2171. +unsigned bi_reverse OF((unsigned value, int length));
  2172. +void     bi_windup  OF((void));
  2173. +void     copy_block OF((char *buf, unsigned len, int header));
  2174. +extern   int (*read_buf) OF((char *buf, unsigned size));
  2175. +
  2176. +    /* in util.c: */
  2177. +extern ulg  updcrc        OF((uch *s, unsigned n));
  2178. +extern void clear_bufs    OF((void));
  2179. +extern int  fill_inbuf    OF((void));
  2180. +extern void flush_outbuf  OF((void));
  2181. +extern void flush_window  OF((void));
  2182. +extern char *strlwr       OF((char *s));
  2183. +extern char *basename     OF((char *fname));
  2184. +extern char *add_envopt   OF((int *argcp, char ***argvp, char *env));
  2185. +extern void error         OF((char *m));
  2186. +extern void warn          OF((char *a, char *b));
  2187. +extern void read_error    OF((void));
  2188. +extern void write_error   OF((void));
  2189. +extern void display_ratio OF((long num, long den));
  2190. +extern voidp xmalloc      OF((unsigned int size));
  2191. +
  2192. +    /* in inflate.c */
  2193. +extern int inflate OF((void));
  2194. diff -u --recursive --new-file linux-1.2.11/include/linux/rd_gz_lzw.h linux/include/linux/rd_gz_lzw.h
  2195. --- linux-1.2.11/include/linux/rd_gz_lzw.h    Wed Dec 31 17:00:00 1969
  2196. +++ linux/include/linux/rd_gz_lzw.h    Sun Jul 16 20:48:01 1995
  2197. @@ -0,0 +1,42 @@
  2198. +/* lzw.h -- define the lzw functions.
  2199. + * Copyright (C) 1992-1993 Jean-loup Gailly.
  2200. + * This is free software; you can redistribute it and/or modify it under the
  2201. + * terms of the GNU General Public License, see the file COPYING.
  2202. + */
  2203. +
  2204. +#if !defined(OF) && defined(lint)
  2205. +#  include "gzip.h"
  2206. +#endif
  2207. +
  2208. +#ifndef BITS
  2209. +#  define BITS 16
  2210. +#endif
  2211. +#define INIT_BITS 9              /* Initial number of bits per code */
  2212. +
  2213. +#define    LZW_MAGIC  "\037\235"   /* Magic header for lzw files, 1F 9D */
  2214. +
  2215. +#define BIT_MASK    0x1f /* Mask for 'number of compression bits' */
  2216. +/* Mask 0x20 is reserved to mean a fourth header byte, and 0x40 is free.
  2217. + * It's a pity that old uncompress does not check bit 0x20. That makes
  2218. + * extension of the format actually undesirable because old compress
  2219. + * would just crash on the new format instead of giving a meaningful
  2220. + * error message. It does check the number of bits, but it's more
  2221. + * helpful to say "unsupported format, get a new version" than
  2222. + * "can only handle 16 bits".
  2223. + */
  2224. +
  2225. +#define BLOCK_MODE  0x80
  2226. +/* Block compression: if table is full and compression rate is dropping,
  2227. + * clear the dictionary.
  2228. + */
  2229. +
  2230. +#define LZW_RESERVED 0x60 /* reserved bits */
  2231. +
  2232. +#define    CLEAR  256       /* flush the dictionary */
  2233. +#define FIRST  (CLEAR+1) /* first free entry */
  2234. +
  2235. +extern int maxbits;      /* max bits per code for LZW */
  2236. +extern int block_mode;   /* block compress mode -C compatible with 2.0 */
  2237. +
  2238. +extern void lzw    OF((int in, int out));
  2239. +extern void unlzw  OF((int in, int out));
  2240.