home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Utilities / vmount-0.6a-I / src / missing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-14  |  6.4 KB  |  239 lines

  1. /*
  2.  * Name: missing.c
  3.  * Description: Functions that are "missing" from the lowlevel interface to
  4.  *     the filesystems.
  5.  * Author: Christian Starkjohann <cs@hal.kph.tuwien.ac.at>
  6.  * Date: 1996-11-14
  7.  * Copyright: GNU-GPL
  8.  * Tabsize: 4
  9.  */
  10.  
  11. #include <asm/page.h>
  12. #include <linux/tasks.h>
  13. #include <linux/mm.h>
  14. #include <linux/fs.h>
  15. #include "my_defines.h"
  16. #include "cache.h"
  17.  
  18. /* ------------------------------------------------------------------------- */
  19.  
  20. extern void    *malloc(unsigned long size);
  21. extern void    free(void *obj);
  22. extern long lseek(int fd, long offset, int whence);
  23. extern int    read(int fd, void *buffer, int len);
  24. extern int    write(int fd, void *buffer, int len);
  25. extern void    perror(const char *s);
  26. extern void    bzero(void *block, int len);
  27.  
  28. /* ------------------------------------------------------------------------- */
  29.  
  30. #define    DPRINTF(arg)    if(debug_mode & DEBUG_MISSING)    dprintf arg
  31.  
  32. /* ------------------------------------------------------------------------- */
  33.  
  34. struct task_struct        *current_set[NR_CPUS];
  35. struct super_block        super_blocks[NR_SUPER];
  36.  
  37. int                        my_blocksize = 512;
  38.  
  39. /* ------------------------------------------------------------------------- */
  40.  
  41. unsigned long    __get_free_pages(int priority, unsigned long gfporder, int dma)
  42. {
  43.     return (unsigned long)malloc(PAGE_SIZE);
  44. }
  45.  
  46. /* ------------------------------------------------------------------------- */
  47.  
  48. void    free_pages(unsigned long addr, unsigned long order)
  49. {
  50.     free((void *)addr);
  51. }
  52.  
  53. /* ------------------------------------------------------------------------- */
  54.  
  55. int        permission(struct inode *i, int may_this)
  56. {
  57. /* leave a dummy for now. maybe nfs does the checking?
  58.  *     i->i_mode
  59.  * #define MAY_EXEC 1
  60.  * #define MAY_WRITE 2
  61.  * #define MAY_READ 4
  62.  */
  63.     return 0;
  64. }
  65.  
  66. /* ------------------------------------------------------------------------- */
  67.  
  68. void unlock_buffer(struct buffer_head *bh)
  69. {
  70.     clear_bit(BH_Lock, &bh->b_state);
  71. }
  72.  
  73. /* ------------------------------------------------------------------------- */
  74.  
  75. /*
  76.  * struct file_operations {
  77.  *     int (*lseek) (struct inode *, struct file *, off_t, int);
  78.  *     int (*read) (struct inode *, struct file *, char *, int);
  79.  *     int (*write) (struct inode *, struct file *, const char *, int);
  80.  *     int (*readdir) (struct inode *, struct file *, void *, filldir_t);
  81.  *     int (*select) (struct inode *, struct file *, int, select_table *);
  82.  *     int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
  83.  *     int (*mmap) (struct inode *, struct file *, struct vm_area_struct *);
  84.  *     int (*open) (struct inode *, struct file *);
  85.  *     void (*release) (struct inode *, struct file *);
  86.  *     int (*fsync) (struct inode *, struct file *);
  87.  *     int (*fasync) (struct inode *, struct file *, int);
  88.  *     int (*check_media_change) (kdev_t dev);
  89.  *     int (*revalidate) (kdev_t dev);
  90.  * };
  91.  * We don't want to support any blockdevice functions for now.
  92.  */
  93. struct file_operations    *get_blkfops(unsigned int rdev)
  94. {
  95. static struct file_operations    fops = {NULL};
  96.  
  97.     return &fops;
  98. }
  99.  
  100. /* ------------------------------------------------------------------------- */
  101.  
  102. void    ll_rw_block(int rw, int count, struct buffer_head * bh[])
  103. {
  104. int                        i;
  105. unsigned long            offset;
  106. extern unsigned long    part_offset;
  107. extern unsigned long    part_size;
  108.  
  109.     for(i=0;i<count;i++){
  110.         if(bh[i]->b_size != my_blocksize){
  111.             fatal_error("** ll_rw_block: blocksize is %d (should be %d)\n",
  112.                                             (int)bh[i]->b_size, my_blocksize);
  113.             return;
  114.         }
  115.         if((bh[i]->b_blocknr + part_offset/my_blocksize)
  116.                                             >= 0x00800000/my_blocksize*512){
  117.             fatal_error("** ll_rw_block: overflow in offset arithmetic\n");
  118.             return;
  119.         }
  120.         if(bh[i]->b_blocknr * my_blocksize + bh[i]->b_size > part_size){
  121.             fatal_error("** access to sectors outside parition (%ld)!\n",
  122.                                                             bh[i]->b_blocknr);
  123.             return;
  124.         }
  125.         offset = bh[i]->b_blocknr * my_blocksize + part_offset;
  126.         switch(rw){
  127.         case READ:
  128.         case READA:
  129.             DPRINTF(("reading block=%ld size=%ld\n",
  130.                                             bh[i]->b_blocknr, bh[i]->b_size));
  131.             cached_read(offset, bh[i]->b_data);
  132.             break;
  133.         case WRITE:
  134.         case WRITEA:
  135.             DPRINTF(("*** writing block=%ld size=%ld\n",
  136.                                             bh[i]->b_blocknr, bh[i]->b_size));
  137.             cached_write(offset, bh[i]->b_data);
  138.             clear_bit(BH_Dirty, &bh[i]->b_state);
  139.             break;
  140.         default:
  141.             eprintf("ll_rw_block(mode=%d) unknown mode!\n", rw);
  142.         }
  143.         set_bit(BH_Uptodate, &bh[i]->b_state);
  144.     }
  145. }
  146.  
  147. /* ------------------------------------------------------------------------- */
  148.  
  149. int generic_file_read(struct inode *inode, struct file *fp, char *buf, int len)
  150. {
  151. int                 (*bmap) (struct inode *,int);
  152. struct buffer_head    *bh;
  153. int                    offs, l, b, block, error = 0;
  154. int                    pos = fp->f_pos;
  155.  
  156.     bmap = inode->i_op->bmap;
  157.     if(bmap == NULL){
  158.         return -EPERM;
  159.     }
  160.     block = pos / my_blocksize;
  161.     offs = pos - block * my_blocksize;
  162.     l = my_blocksize - offs;
  163.     while(len > 0){
  164.         if(l > len)
  165.             l = len;
  166.         b = bmap(inode, block);
  167.         if(b != 0){
  168.             if((bh = bread(inode->i_dev, b, my_blocksize)) == NULL){
  169.                 error = -EIO;
  170.                 break;
  171.             }
  172.             memcpy(buf, bh->b_data + offs, l);
  173.             brelse(bh);
  174.         }else{
  175.             bzero(buf, l);
  176.         }
  177.         block ++;
  178.         buf += l;
  179.         error += l;    /* count bytes read */
  180.         len -= l;
  181.         offs = 0;
  182.         l = my_blocksize;
  183.     }
  184.     return error;
  185. }
  186.  
  187. /* ------------------------------------------------------------------------- */
  188.  
  189. void set_blocksize(kdev_t dev, int size)
  190. {
  191.     DPRINTF(("set_blocksize(size=%d)\n", size));
  192.     my_blocksize = size;
  193.     cache_set_bsize(size);
  194. }
  195.  
  196. /* ------------------------------------------------------------------------- */
  197.  
  198. void    missing_regular(void)
  199. {
  200. }
  201.  
  202. /* ------------------------------------------------------------------------- */
  203.  
  204. void    set_current_ids(int uid, int gid)
  205. {
  206.     current->uid = uid;
  207.     current->gid = gid;
  208.     current->fsuid = uid;
  209.     current->fsgid = gid;
  210. }
  211.  
  212. /* ------------------------------------------------------------------------- */
  213.  
  214. void    missing_init(void)
  215. {
  216. static struct task_struct        my_task;
  217. static struct fs_struct            my_fs;
  218. static struct mm_struct            my_mm;
  219. static struct vm_area_struct    vma;
  220. static struct files_struct        my_files;
  221.  
  222.     current_set[0] = &my_task;
  223.     current->rlim[RLIMIT_NOFILE].rlim_cur = 256;
  224.     current->rlim[RLIMIT_NOFILE].rlim_max = 256;
  225.     current->rlim[RLIMIT_FSIZE].rlim_cur = 2147483647;
  226.     current->rlim[RLIMIT_FSIZE].rlim_max = 2147483647;
  227.     current->fs = &my_fs;
  228.     current->mm = &my_mm;
  229.  
  230.     my_mm.mmap_avl = my_mm.mmap = &vma;
  231.     vma.vm_mm = &my_mm;
  232.     vma.vm_start = 0;
  233.     vma.vm_end = 0x7fffffffUL;
  234.     vma.vm_flags = VM_READ | VM_WRITE | VM_EXEC;
  235.     current->files = &my_files;
  236. }
  237.  
  238. /* ------------------------------------------------------------------------- */
  239.