home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0646.ZIP / CCE_0646.PD / MFS606S / MINIXFS / MINIXFS.H < prev    next >
C/C++ Source or Header  |  1993-07-24  |  13KB  |  347 lines

  1. #ifndef minixfs_h
  2. #define minixfs_h
  3.  
  4. #include <sys/types.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. #include "atarierr.h"
  9. #include "filesys.h"
  10.  
  11. #include "kernel.h"
  12.  
  13. #include "config.h"
  14.  
  15. #define DOM_TOS 0
  16. #define DOM_MINT 1
  17. #define NUM_DRIVES 32
  18.  
  19. #ifndef NULL
  20. #define NULL 0L
  21. #endif
  22.  
  23. /* Useful macro , is non zero only if 'x' is not a power of two */
  24.  
  25. #define NPOW2(x) ( ( (x) & (x-1) )!=0)
  26.  
  27. /* Dates smaller than 1st Jan 1980 confuse dostime _corr avoids them */
  28.  
  29. #define _corr(t) ( (t > 315532800L) ? t : 315532800L)
  30.  
  31. #define SIZEOF sizeof
  32.  
  33. /* General types we will use */
  34. typedef unsigned short unshort;
  35. typedef unsigned short ushort;
  36. typedef unsigned char unchar;
  37.  
  38. /* Constants for fscntl */
  39.  
  40. #define MFS_BASE    0x100
  41. #define MFS_VERIFY    (MFS_BASE)    /* Return minixfs magic number */
  42. #define MFS_SYNC    (MFS_BASE|0x01)    /* Sync the filesystem */
  43. #define MFS_CINVALID    (MFS_BASE|0x02)    /* Invalidate cache entries */
  44. #define MFS_FINVALID    (MFS_BASE|0x03)    /* Invalidate Fileptrs */
  45. #define MFS_INFO    (MFS_BASE|0x04)    /* Get info about filesystem */
  46. #define MFS_USAGE    (MFS_BASE|0x05)    /* Get block allocation of a file */
  47. #define MFS_IMODE    (MFS_BASE|0x06)    /* Change all bits in an inode mode */
  48. #define MFS_GTRANS    (MFS_BASE|0x07) /* Get filename translation mode */ 
  49. #define MFS_STRANS    (MFS_BASE|0x08) /* Set filename translation mode */
  50. #define MFS_PHYS    (MFS_BASE|0x09) /* Get physical partition info */
  51. #define MFS_IADDR    (MFS_BASE|0x0a) /* Get start address of minixfs */
  52. #define MFS_UPDATE    (MFS_BASE|0x0b) /* Update daemon controls */
  53.  
  54. #define MFS_MAGIC    0x18970431    /* Magic number from MFS_VERIFY */
  55.  
  56. /* Filename translation modes */
  57.  
  58. #define SRCH_TOS    0x01        /* search with tosify , tos domain  */
  59. #define SRCH_MNT    0x02        /* search with tosify , mint domain */
  60. #define DIR_TOS        0x04        /* dir compat tosify  , tos domain  */
  61. #define DIR_MNT        0x08        /* dir compat tosify  , mint domain */
  62. #define LWR_TOS        0x10        /* lower case creat   , tos domain  */
  63. #define LWR_MNT        0x20        /* lower case creat   , mint domain */
  64. #define AEXEC_TOS    0x40        /* auto 'x' ,   tos domain.   */
  65. #define AEXEC_MNT    0x80        /* auto 'x' ,    mint domain. */
  66.  
  67.  
  68. typedef struct {
  69. long total_inodes,total_zones;
  70. long free_inodes,free_zones;
  71. int version;            /* Filesystem version 1=V1 2=V2 */
  72. int increment;            /* Directory increment */
  73. long res1,res2,res3,res4;    /* Reserved for future use */
  74. } mfs_info;
  75.  
  76. #ifdef NDEBUG
  77. #define assert(expression)
  78. #else
  79. # ifdef __STDC__
  80. #define assert(expression) \
  81.     ((expression) ? 0 : FATAL("assert(`%s') failed at line %ld of %s.", \
  82.         #expression, (long)__LINE__, __FILE__))
  83. # else
  84. #define assert(expression) if(expression) FATAL("assert(%s) failed", \
  85.         "expression")
  86. # endif
  87. #endif
  88.  
  89.  
  90.  
  91. /* Macro to determine maximum filename length for a given increment */
  92.  
  93. #define MMAX_FNAME(x) ( ( (x)<<4 ) -2)
  94.  
  95. /* Absolute maximum filename length */
  96.  
  97. #define MNAME_MAX MMAX_FNAME(MAX_INCREMENT)
  98.  
  99. #define BLOCK_SIZE    1024    /* # bytes in a disk block */
  100. #define L_BS        10    /* log 2 bytes/block */
  101.  
  102. #define MAJOR             8    /* major device = (dev>>MAJOR) & 0377 */
  103. #define MINOR             0    /* minor device = (dev>>MINOR) & 0377 */
  104. #define NOLAST    (unshort *) 0    /* We dont want parent directory of a file */
  105.  
  106. /* Flag bits for i_mode in the inode. */
  107.  
  108. #define I_SYMLINK    0160000 /* symbolic link (not standard minix) */
  109.  
  110. #define I_TYPE        0170000    /* this field gives inode type */
  111. #define I_REGULAR    0100000    /* regular file, not dir or special */
  112. #define I_BLOCK_SPECIAL 0060000    /* block special file */
  113. #define I_DIRECTORY    0040000    /* file is a directory */
  114. #define I_CHAR_SPECIAL    0020000    /* character special file */
  115. #define I_NAMED_PIPE    0010000 /* named pipe (FIFO) */
  116. #define I_SET_UID_BIT    0004000    /* set effective uid on exec */
  117. #define I_SET_GID_BIT    0002000    /* set effective gid on exec */
  118. #define I_STICKY    0001000 /* sticky bit */
  119. #define ALL_MODES    0007777    /* all bits for user, group and others */
  120. #define RWX_MODES    0000777    /* mode bits for RWX only */
  121. #define R_BIT        0000004    /* Rwx protection bit */
  122. #define W_BIT        0000002    /* rWx protection bit */
  123. #define X_BIT        0000001    /* rwX protection bit */
  124. #define I_NOT_ALLOC    0000000    /* this inode is free */
  125.  
  126. /* Useful macros */
  127. #define IS_DIR(m)    ((m.i_mode & I_TYPE)==I_DIRECTORY)
  128. #define IS_REG(m)    ((m.i_mode & I_TYPE)==I_REGULAR)
  129.  
  130. /* Flag bits for cookie 'aux' field */
  131. #define AUX_DEL     1    /* file marked for deletion */
  132. #define AUX_SYNC 2    /* l_sync() on next write */
  133.  
  134. /* Tables sizes */
  135. #define NR_ZONE_NUMS       9    /* # zone numbers in an inode */
  136. #define NR_ZONE_NUMS2      10    /* #zone numbers in v2 inode */
  137.  
  138. /* Miscellaneous constants */
  139. #define SUPER_MAGIC   0x137F    /* magic number contained in super-block */
  140. #define SUPER_V2      0x2468    /* v2 magic number */
  141.  
  142. #define FIND        0    /* tells search_dir to search for file */
  143. #define ADD        1    /* tells search_dir to add a dir entry */
  144. #define KILL        2    /* tells search_dir to kill entry     */
  145. #define POS        3    /* tells search_dir to find position   */
  146.  
  147. #define INVALID        0    /* Cache entry is garbage */
  148. #define CLEAN           1    /* Cache entry same as disk */
  149. #define DIRTY           2    /* Cache entry is more recent than disk */
  150. #define LOCKED           4    /* do not overwrite entry */
  151.  
  152. #define NOLOCK           3    /* Bits not connected with locks */
  153.  
  154. #define BOOT_BLOCK  0        /* block number of boot block */
  155. #define SUPER_BLOCK 1        /* block number of super block */
  156. #define ROOT_INODE  (unshort)1    /* inode number for root directory */
  157.  
  158.  
  159. /* Derived sizes */
  160. #define ZONE_NUM_SIZE     (SIZEOF(unshort))         /* # bytes in zone nr  */
  161. #define NR_DZONE_NUM     (NR_ZONE_NUMS-2)         /* # zones in inode    */
  162. #define DIR_ENTRY_SIZE     (SIZEOF(dir_struct))         /* # bytes/dir entry   */
  163. #define L_DIR_SIZE     4                 /* log2 bytes/dir entry */    
  164. #define INODES_PER_BLOCK (BLOCK_SIZE/INODE_SIZE)     /* # inodes/disk blk   */
  165. #define L_IPB         5                 /* log2 inodes/blk */
  166. #define INODE_SIZE     (SIZEOF(d_inode1))         /* bytes in disk inode */
  167. #define NR_DIR_ENTRIES     (BLOCK_SIZE/DIR_ENTRY_SIZE) /* # dir entries/block */
  168. #define NR_INDIRECTS     (BLOCK_SIZE/ZONE_NUM_SIZE)  /* # zones/indir block */
  169. #define LNR_IND         9                 /* log 2 NR_INDIRECTS */
  170. #define NR_DBL         (NR_DZONE_NUM+NR_INDIRECTS) /* 1st zone in dbl ind */
  171. #define INTS_PER_BLOCK     (BLOCK_SIZE/SIZEOF(int))    /* # integers/block    */
  172. #define SUPER_SIZE     (SIZEOF(struct super_block)) /* super_block size    */
  173. #define PIPE_SIZE     (NR_DZONE_NUM*BLOCK_SIZE)   /* pipe size in bytes  */
  174. #define MAX_ZONES (NR_DZONE_NUM+(NR_INDIRECTS+1l)*NR_INDIRECTS)
  175.  
  176. #define NR_ZONE_NUMS2    10
  177. #define NR_DZONE_NUM2    (NR_ZONE_NUMS2-3)
  178. #define ZONE_NUM_SIZE2    (SIZEOF(long))
  179. #define INODES_PER_BLOCK2 (BLOCK_SIZE/INODE_SIZE2)
  180. #define L_IPB2        4
  181. #define INODE_SIZE2    (SIZEOF(d_inode))
  182. #define NR_INDIRECTS2    (BLOCK_SIZE/ZONE_NUM_SIZE2)
  183. #define LNR_IND2    8
  184. #define NR_DBL2        (NR_DZONE_NUM2+NR_INDIRECTS2)
  185. #define MAX_ZONES2 (NR_DZONE_NUMS2+(NR_INDIRECTS2+1l)*NR_INDIRECTS2)
  186.  
  187. #ifndef SEEK_SET
  188. /* lseek() origins */
  189. #define    SEEK_SET    0        /* from beginning of file */
  190. #define    SEEK_CUR    1        /* from current location */
  191. #define    SEEK_END    2        /* from end of file */
  192. #endif
  193.  
  194.  
  195. #ifndef min
  196. #define min(a,b) ((a)>(b) ? (b) : (a))
  197. #endif
  198.  
  199. typedef struct    {
  200.   unshort s_ninodes;        /* # usable inodes on the minor device */
  201.   unshort s_nzones;        /* total device size, including bit maps etc */
  202.   unshort s_imap_blks;        /* # of blocks used by inode bit map */
  203.   unshort s_zmap_blks;        /* # of blocks used by zone bit map */
  204.   unshort s_firstdatazn;    /* number of first data zone */
  205.   short int s_log_zsize;    /* log2 of blocks/zone */
  206.   long s_max_size;        /* maximum file size on this device */
  207.   short s_magic;        /* magic number to recognize super-blocks */
  208.   short pad;            /* padding */
  209.   long s_zones;            /* long version of s_nzones for v2 */
  210. } super_block;
  211.  
  212. /* super_info contains information about each Minix filesystem */
  213.  
  214. typedef struct  {
  215.     super_block sblk;    /* Actual super block */
  216.     int dev;        /* Device this belongs to */
  217.     long serialno;        /* Serial number of disk (ignored for now)*/
  218.     long ioff;        /* Offset to inode 1 */
  219.     ushort *ibitmap;
  220.     ushort idirty;        /* Set if ibitmap changed after last write */
  221.     long ilast;        /* search start for free inodes */
  222.     ushort *zbitmap;
  223.     ushort zdirty;        /* zbitmap dirty flag */
  224.     long zlast;        /* search start for free zones */
  225.  
  226. /* This lot is filled in as appropriate for each FS type */
  227.  
  228.     char version;        /* 0 for V1, 1 for V2 : -1 for 'dummy' */
  229.     unsigned ipb;        /* Inodes per block */
  230.     unsigned zpind;        /* zones per indirection block */
  231.     unsigned dzpi;        /* direct zones per inode */
  232.     unsigned ndbl;        /* first zone number in double indirect block */
  233.     int increment;        /* num of dir_structs per dir entry */
  234. } super_info;
  235.  
  236. #define DFS ((super_info *) -1)
  237.  
  238. /* This is what a directory entry on the disk looks like. Note: we can use
  239.  * a dirty trick to use this same structure for large filenames > 14 chars
  240.  * the idea is to use only a fraction of the total entries , so that if
  241.  * say the filename size is 30 we just use entries 0,2,4,6,8 etc. d_name
  242.  * then occupies all of the next entry. This forces the max filename size
  243.  * to be 2 less than a power of two (and certainly less than 1022), normally
  244.  * 30 should be more than adequate to cover every filename you'll ever see.
  245.  * 62 is for paranoids, but remember the path name limit of 128 characters.
  246.  */
  247.  
  248. typedef struct {        /* directory entry */
  249.   unshort d_inum;        /* inode number */
  250.   char d_name[MMAX_FNAME(1)];    /* character string */
  251. } dir_struct;
  252.  
  253. typedef struct {        /* disk inode. */
  254.   unshort i_mode;        /* file type, protection, etc. */
  255.   unshort i_uid;        /* user id of the file's owner */
  256.   long i_size;            /* current file size in bytes */
  257.   long i_mtime;            /* when was file data last changed */
  258.   unchar i_gid;            /* group number */
  259.   unchar i_nlinks;        /* how many links to this file */
  260.   unshort i_zone[NR_ZONE_NUMS];    /* block nums for direct, ind, and dbl ind */
  261. } d_inode1;
  262.  
  263. typedef struct {        /* V2.x disk inode */
  264.   ushort i_mode;        /* file type, protection, etc. */
  265.   ushort i_nlinks;        /* how many links to this file. HACK! */
  266.   ushort i_uid;            /* user id of the file's owner. */
  267.   ushort i_gid;            /* group number HACK! */
  268.   long i_size;            /* current file size in bytes */
  269.   long i_atime;            /* when was file data last accessed */
  270.   long i_mtime;            /* when was file data last changed */
  271.   long i_ctime;            /* when was inode data last changed */
  272.   long i_zone[NR_ZONE_NUMS2];    /* block nums for direct, ind, and dbl ind */
  273. } d_inode;
  274.  
  275. typedef
  276.   union {
  277.     char bdata[BLOCK_SIZE];        /* ordinary user data */
  278.     dir_struct bdir[NR_DIR_ENTRIES];    /* directory block */
  279.     unshort bind1[NR_INDIRECTS];        /* indirect block */
  280.     long    bind[NR_INDIRECTS2];        /* v2 indirect block */
  281.     d_inode1 binode1[INODES_PER_BLOCK];    /* inode block */
  282.     d_inode binode[INODES_PER_BLOCK2]; /* v2 inode block */
  283.   } bufr;
  284.  
  285. typedef struct {
  286.     bufr    *buffer;
  287.     long     block;        /* Block number bufr contains */
  288.     short    drive;        /* Drive of bufr */
  289.     int    status;        
  290. /* Valid status values:
  291.  * 0=invalid
  292.  * 1=valid&clean 
  293.  * 2=dirty
  294.  * 3=dirty but not essential (i.e. don't complain if not written out)
  295.  */
  296.  
  297. } cache;
  298.  
  299. typedef struct {
  300.     cache *pos,*start,*end;
  301. } cache_control;
  302.  
  303. /* This is a special FILEPTR structure, it is pointed to by the devinfo field,
  304.  * this speeds up read and write. 
  305.  *    For write, 'zones' contains only the current writing block, which
  306.  * is used if lots of small writes take place. For reading it contains a list
  307.  * of the next few zones to read. Care is needed as an O_TRUNC (or a truncate
  308.  * which  nothing uses at  present) can invalidate all  of this.  lckfirst
  309.  * contains a pointer to where a pointer to the first lock is contained. This
  310.  * means that if the first lock is deleted then only *lckfirst need be altered.
  311.  * Following this is a series of 'guesses' as to where relevant info for a file
  312.  * may be contained. This means that most of the time functions can find the
  313.  * cache entry almost immediately, instead of searching. Since the cache is
  314.  * dynamic and entries can be overwritten, the guess is not perfect and is
  315.  * checked before use. If it is invalid then the guess is updated after a
  316.  * successful load or search.
  317.  */
  318.  
  319. typedef struct {
  320.     long    zones[PRE_READ];    /* Zonecache for pre-read,write */
  321.     long     fzone;            /* chunk number in zone[0] */
  322.     long    lzone;            /* Last valid chunk number */
  323.     LOCK     **lfirst;        /* pointer to pointer with first lock */
  324.     #define NOGUESS ( (cache **) 0) /* Don't guess cache entry */
  325.     cache     *iguess;        /* Guess at inode cache position */
  326.     cache    *zguess;        /* Guess at zone cache position */ 
  327.     cache    *izguess;        /* Ind zone guess */
  328.     cache    *dizguess;        /* Dbl ind zone guess */
  329. } f_cache;
  330.  
  331. /* Physical partition structure */
  332. struct phys_part {
  333. long start;        /* Physical partition start sector number */
  334. long finish;        /* End sector number */
  335. char shadow;        /* Rwabs dev number to access this drive at */
  336. char scsiz;        /* sector size 1=512 bytes 0=1K */
  337. };
  338.  
  339. /* Macros for indirection blocks */
  340.  
  341. #define PIND(vers,tmp,index) \
  342.     ( (vers) ? (tmp->bind[index]) : (tmp->bind1[index]) )
  343. #define IND(vers,temp,index) \
  344.     ( (vers) ? (temp.bind[index]) : (temp.bind1[index]) )
  345.  
  346. #endif
  347.