(root)/
util-linux-2.39/
disk-utils/
minix_programs.h
       1  #ifndef UTIL_LINUX_MINIX_PROGRAMS_H
       2  #define UTIL_LINUX_MINIX_PROGRAMS_H
       3  
       4  #include "minix.h"
       5  
       6  /*
       7   * Global variables.
       8   */
       9  extern int fs_version;
      10  extern char *super_block_buffer;
      11  
      12  #define Super (*(struct minix_super_block *) super_block_buffer)
      13  #define Super3 (*(struct minix3_super_block *) super_block_buffer)
      14  
      15  #define INODE_SIZE (sizeof(struct minix_inode))
      16  #define INODE2_SIZE (sizeof(struct minix2_inode))
      17  
      18  #define BITS_PER_BLOCK (MINIX_BLOCK_SIZE << 3)
      19  
      20  #define UPPER(size,n) ((size+((n)-1))/(n))
      21  
      22  /*
      23   * Inline functions.
      24   */
      25  static inline unsigned long get_ninodes(void)
      26  {
      27  	switch (fs_version) {
      28  	case 3:
      29  		return Super3.s_ninodes;
      30  	default:
      31  		return Super.s_ninodes;
      32  	}
      33  }
      34  
      35  static inline unsigned long get_nzones(void)
      36  {
      37  	switch (fs_version) {
      38  	case 3:
      39  		return Super3.s_zones;
      40  	case 2:
      41  		return Super.s_zones;
      42  	default:
      43  		return Super.s_nzones;
      44  	}
      45  }
      46  
      47  static inline unsigned long get_nimaps(void)
      48  {
      49  	switch (fs_version) {
      50  	case 3:
      51  		return Super3.s_imap_blocks;
      52  	default:
      53  		return Super.s_imap_blocks;
      54  	}
      55  }
      56  
      57  static inline unsigned long get_nzmaps(void)
      58  {
      59  	switch (fs_version) {
      60  	case 3:
      61  		return Super3.s_zmap_blocks;
      62  	default:
      63  		return Super.s_zmap_blocks;
      64  	}
      65  }
      66  
      67  static inline off_t get_first_zone(void)
      68  {
      69  	switch (fs_version) {
      70  	case 3:
      71  		return Super3.s_firstdatazone;
      72  	default:
      73  		return Super.s_firstdatazone;
      74  	}
      75  }
      76  
      77  static inline size_t get_zone_size(void)
      78  {
      79  	switch (fs_version) {
      80  	case 3:
      81  		return Super3.s_log_zone_size;
      82  	default:
      83  		return Super.s_log_zone_size;
      84  	}
      85  }
      86  
      87  static inline size_t get_max_size(void)
      88  {
      89  	switch (fs_version) {
      90  	case 3:
      91  		return Super3.s_max_size;
      92  	default:
      93  		return Super.s_max_size;
      94  	}
      95  }
      96  
      97  static inline unsigned long inode_blocks(void)
      98  {
      99  	switch (fs_version) {
     100  	case 3:
     101  	case 2:
     102  		return UPPER(get_ninodes(), MINIX2_INODES_PER_BLOCK);
     103  	default:
     104  		return UPPER(get_ninodes(), MINIX_INODES_PER_BLOCK);
     105  	}
     106  }
     107  
     108  static inline off_t first_zone_data(void)
     109  {
     110  	return 2 + get_nimaps() + get_nzmaps() + inode_blocks();
     111  }
     112  
     113  static inline size_t get_inode_buffer_size(void)
     114  {
     115  	return inode_blocks() * MINIX_BLOCK_SIZE;
     116  }
     117  
     118  #endif				/* UTIL_LINUX_MINIX_PROGRAMS_H */