home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / alt_os / mint / mfs6011 / source / minixfs / misc.c < prev    next >
C/C++ Source or Header  |  1994-01-24  |  2KB  |  131 lines

  1. /* This file is part of 'minixfs' Copyright 1991,1992,1993 S.N. Henson */
  2.  
  3. #include "minixfs.h"
  4. #include "proto.h"
  5. #include "global.h"
  6.  
  7. /* inode_busy() scans the list for a given inode, this is used to stop
  8.  * unlink blowing away a busy inode. In addition f->aux flag is set if 'flag'
  9.  * is non zero. This is to allow a subsequent close to recognise that the inode
  10.  * is marked for zapping.
  11.  */
  12.  
  13. int inode_busy(inum,drive,flag)
  14. unsigned inum;
  15. int drive;
  16. int flag;    /* Propagate AUX_DEL */
  17. {
  18.     FILEPTR *f;
  19.     int found;
  20.  
  21.     found=0;
  22.     for(f=firstptr;f;f=f->next)
  23.     {
  24.     if((f->fc.index==inum) && (f->fc.dev==drive))
  25.     {
  26.         if(flag) f->fc.aux|=AUX_DEL;
  27.         if(found!=2) found++;
  28.     }
  29.     else if(found) break; /* Since same files consecutive, halt search */
  30.     }
  31.     return (found);
  32. }
  33.  
  34.  
  35. /* Copy characters from 'from' to 'to' translating backslashes to slashes */
  36.  
  37. void btos_cpy(to,from)
  38. char *to;
  39. const char *from;
  40. {
  41.     char c;
  42.     do {
  43.         c=*from++;    
  44.         if(c=='\\')*to++='/';
  45.         else *to++=c;
  46.     }
  47.     while(c);
  48. }
  49.  
  50. /* Translate slashes to backslashes , return zero if all characters copied */
  51.  
  52. int stob_ncpy(to,from,n)
  53. char *to;
  54. const char *from;
  55. long n;
  56. {
  57.     char c;
  58.  
  59.     if(n==0) return 0;
  60.  
  61.     do
  62.     {
  63.         c=*from++;
  64.         if(c=='/')*to++='\\';
  65.         else *to++=c;
  66.     }
  67.     while(--n && c );
  68.  
  69.     if(c)
  70.     {
  71.         *--to='\0';
  72.         return 1;
  73.     }
  74.     return 0;
  75. }
  76.  
  77. /* Check for access 'access' for given uid/gid/mode
  78.  * return 0 if access allowed.
  79.  */
  80.  
  81. int check_mode(euid,egid,rip,access)
  82. int euid,egid,access;
  83. d_inode *rip;
  84. {
  85.     if(!euid) return 0;
  86.     if( euid==rip->i_uid && (rip->i_mode & access) ) return 0;
  87.     if( egid==rip->i_gid && (rip->i_mode & (access >> 3) ) ) return 0;
  88.     if( rip->i_mode & ( access >>6 ) ) return 0;
  89.     return 1;
  90. }
  91.  
  92. /*
  93.  * Check an fcookie for a mount point, if mounted translate to the new FS.
  94.  * Return 1 if it is a mount point.
  95.  */
  96.  
  97. int check_mount(fc)
  98. fcookie *fc;
  99. {
  100.     super_info *psblk;
  101.     /* Go through list of filesystems mounted on this device */
  102.     for(psblk=super_ptr[fc->dev]->mnt_first;psblk;psblk=psblk->mnt_next)
  103.     {
  104.         if(psblk->mnt_inode==fc->index)
  105.         {
  106.             fc->dev=psblk->dev;
  107.             fc->index=ROOT_INODE;
  108.             fc->aux=0;
  109.             return 1;
  110.         }
  111.     }
  112.     return 0;
  113. }
  114.  
  115. /*
  116.  * Change an to the point it is mounted on.
  117.  * Returns zero for success or EMOUNT for failure.
  118.  */
  119.  
  120. int cross_mount(fc)
  121. fcookie *fc;
  122. {
  123.     super_info *psblk;
  124.     psblk=super_ptr[fc->dev];
  125.     if(!psblk->mnt_inode) return EMOUNT;
  126.     fc->dev=psblk->mnt_dev;
  127.     fc->index=psblk->mnt_inode;
  128.     fc->aux=0;
  129.     return 0;
  130. }
  131.