home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / v1.3 / ramdisk-.001 / ramdisk-1.3.20.diff
Text File  |  1994-01-02  |  66KB  |  2,237 lines

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