home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / win95 / ext2tool.exe / LINUX / EXT2_FS.H
C/C++ Source or Header  |  1995-03-01  |  16KB  |  490 lines

  1. /*
  2.  *  linux/include/linux/ext2_fs.h
  3.  *
  4.  *  Copyright (C) 1992, 1993, 1994  Remy Card (card@masi.ibp.fr)
  5.  *                                  Laboratoire MASI - Institut Blaise Pascal
  6.  *                                  Universite Pierre et Marie Curie (Paris VI)
  7.  *
  8.  *  from
  9.  *
  10.  *  linux/include/linux/minix_fs.h
  11.  *
  12.  *  Copyright (C) 1991, 1992  Linus Torvalds
  13.  */
  14.  
  15. #ifndef _LINUX_EXT2_FS_H
  16. #define _LINUX_EXT2_FS_H
  17.  
  18. /*
  19.  * The second extended filesystem constants/structures
  20.  */
  21.  
  22. /*
  23.  * Define EXT2FS_DEBUG to produce debug messages
  24.  */
  25. #undef EXT2FS_DEBUG
  26.  
  27. /*
  28.  * Define EXT2FS_DEBUG_CACHE to produce cache debug messages
  29.  */
  30. #undef EXT2FS_DEBUG_CACHE
  31.  
  32. /*
  33.  * Define EXT2FS_CHECK_CACHE to add some checks to the name cache code
  34.  */
  35. #undef EXT2FS_CHECK_CACHE
  36.  
  37. /*
  38.  * Define EXT2FS_PRE_02B_COMPAT to convert ext 2 fs prior to 0.2b
  39.  */
  40. #undef EXT2FS_PRE_02B_COMPAT
  41.  
  42. /*
  43.  * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
  44.  */
  45. #define EXT2_PREALLOCATE
  46.  
  47. /*
  48.  * The second extended file system version
  49.  */
  50. #define EXT2FS_DATE        "94/10/23"
  51. #define EXT2FS_VERSION        "0.5a"
  52.  
  53. /*
  54.  * Special inodes numbers
  55.  */
  56. #define    EXT2_BAD_INO         1    /* Bad blocks inode */
  57. #define EXT2_ROOT_INO         2    /* Root inode */
  58. #define EXT2_ACL_IDX_INO     3    /* ACL inode */
  59. #define EXT2_ACL_DATA_INO     4    /* ACL inode */
  60. #define EXT2_BOOT_LOADER_INO     5    /* Boot loader inode */
  61. #define EXT2_UNDEL_DIR_INO     6    /* Undelete directory inode */
  62. #define EXT2_FIRST_INO        11    /* First non reserved inode */
  63.  
  64. /*
  65.  * The second extended file system magic number
  66.  */
  67. #define EXT2_PRE_02B_MAGIC    0xEF51
  68. #define EXT2_SUPER_MAGIC    0xEF53
  69.  
  70. /*
  71.  * Maximal count of links to a file
  72.  */
  73. #define EXT2_LINK_MAX        32000
  74.  
  75. /*
  76.  * Macro-instructions used to manage several block sizes
  77.  */
  78. #define EXT2_MIN_BLOCK_SIZE        1024
  79. #define    EXT2_MAX_BLOCK_SIZE        4096
  80. #define EXT2_MIN_BLOCK_LOG_SIZE          10
  81. #ifdef __KERNEL__
  82. # define EXT2_BLOCK_SIZE(s)        ((s)->s_blocksize)
  83. #else
  84. # define EXT2_BLOCK_SIZE(s)        (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
  85. #endif
  86. #define EXT2_ACLE_PER_BLOCK(s)        (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
  87. #define    EXT2_ADDR_PER_BLOCK(s)        (EXT2_BLOCK_SIZE(s) / sizeof (unsigned long))
  88. #ifdef __KERNEL__
  89. # define EXT2_BLOCK_SIZE_BITS(s)    ((s)->u.ext2_sb.s_es->s_log_block_size + 10)
  90. #else
  91. # define EXT2_BLOCK_SIZE_BITS(s)    ((s)->s_log_block_size + 10)
  92. #endif
  93. #define    EXT2_INODES_PER_BLOCK(s)    (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_inode))
  94.  
  95. /*
  96.  * Macro-instructions used to manage fragments
  97.  */
  98. #define EXT2_MIN_FRAG_SIZE        1024
  99. #define    EXT2_MAX_FRAG_SIZE        4096
  100. #define EXT2_MIN_FRAG_LOG_SIZE          10
  101. #ifdef __KERNEL__
  102. # define EXT2_FRAG_SIZE(s)        ((s)->u.ext2_sb.s_frag_size)
  103. # define EXT2_FRAGS_PER_BLOCK(s)    ((s)->u.ext2_sb.s_frags_per_block)
  104. #else
  105. # define EXT2_FRAG_SIZE(s)        (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
  106. # define EXT2_FRAGS_PER_BLOCK(s)    (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
  107. #endif
  108.  
  109. /*
  110.  * ACL structures
  111.  */
  112. struct ext2_acl_header    /* Header of Access Control Lists */
  113. {
  114.     unsigned long aclh_size;
  115.     unsigned long aclh_file_count;
  116.     unsigned long aclh_acle_count;
  117.     unsigned long aclh_first_acle;
  118. };
  119.  
  120. struct ext2_acl_entry    /* Access Control List Entry */
  121. {
  122.     unsigned long  acle_size;
  123.     unsigned short acle_perms;    /* Access permissions */
  124.     unsigned short acle_type;    /* Type of entry */
  125.     unsigned short acle_tag;    /* User or group identity */
  126.     unsigned short acle_pad1;
  127.     unsigned long  acle_next;    /* Pointer on next entry for the */
  128.                     /* same inode or on next free entry */
  129. };
  130.  
  131. /*
  132.  * Structure of a blocks group descriptor
  133.  */
  134. struct ext2_old_group_desc
  135. {
  136.     unsigned long  bg_block_bitmap;        /* Blocks bitmap block */
  137.     unsigned long  bg_inode_bitmap;        /* Inodes bitmap block */
  138.     unsigned long  bg_inode_table;        /* Inodes table block */
  139.     unsigned short bg_free_blocks_count;    /* Free blocks count */
  140.     unsigned short bg_free_inodes_count;    /* Free inodes count */
  141. };
  142.  
  143. struct ext2_group_desc
  144. {
  145.     unsigned long  bg_block_bitmap;        /* Blocks bitmap block */
  146.     unsigned long  bg_inode_bitmap;        /* Inodes bitmap block */
  147.     unsigned long  bg_inode_table;        /* Inodes table block */
  148.     unsigned short bg_free_blocks_count;    /* Free blocks count */
  149.     unsigned short bg_free_inodes_count;    /* Free inodes count */
  150.     unsigned short bg_used_dirs_count;    /* Directories count */
  151.     unsigned short bg_pad;
  152.     unsigned long  bg_reserved[3];
  153. };
  154.  
  155. /*
  156.  * Macro-instructions used to manage group descriptors
  157.  */
  158. #ifdef __KERNEL__
  159. # define EXT2_BLOCKS_PER_GROUP(s)    ((s)->u.ext2_sb.s_blocks_per_group)
  160. # define EXT2_DESC_PER_BLOCK(s)        ((s)->u.ext2_sb.s_desc_per_block)
  161. # define EXT2_INODES_PER_GROUP(s)    ((s)->u.ext2_sb.s_inodes_per_group)
  162. #else
  163. # define EXT2_BLOCKS_PER_GROUP(s)    ((s)->s_blocks_per_group)
  164. # define EXT2_DESC_PER_BLOCK(s)        (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
  165. # define EXT2_INODES_PER_GROUP(s)    ((s)->s_inodes_per_group)
  166. #endif
  167.  
  168. /*
  169.  * Constants relative to the data blocks
  170.  */
  171. #define    EXT2_NDIR_BLOCKS        12
  172. #define    EXT2_IND_BLOCK            EXT2_NDIR_BLOCKS
  173. #define    EXT2_DIND_BLOCK            (EXT2_IND_BLOCK + 1)
  174. #define    EXT2_TIND_BLOCK            (EXT2_DIND_BLOCK + 1)
  175. #define    EXT2_N_BLOCKS            (EXT2_TIND_BLOCK + 1)
  176.  
  177. /*
  178.  * Inode flags
  179.  */
  180. #define    EXT2_SECRM_FL            0x00000001 /* Secure deletion */
  181. #define    EXT2_UNRM_FL            0x00000002 /* Undelete */
  182. #define    EXT2_COMPR_FL            0x00000004 /* Compress file */
  183. #define EXT2_SYNC_FL            0x00000008 /* Synchronous updates */
  184. #define EXT2_IMMUTABLE_FL        0x00000010 /* Immutable file */
  185. #define EXT2_APPEND_FL            0x00000020 /* writes to file may only append */
  186. #define EXT2_NODUMP_FL            0x00000040 /* do not dump file */
  187.  
  188. /*
  189.  * ioctl commands
  190.  */
  191. #define    EXT2_IOC_GETFLAGS        _IOR('f', 1, long)
  192. #define    EXT2_IOC_SETFLAGS        _IOW('f', 2, long)
  193. #define    EXT2_IOC_GETVERSION        _IOR('v', 1, long)
  194. #define    EXT2_IOC_SETVERSION        _IOW('v', 2, long)
  195.  
  196. /*
  197.  * Structure of an inode on the disk
  198.  */
  199. struct ext2_inode {
  200.     unsigned short i_mode;        /* File mode */
  201.     unsigned short i_uid;        /* Owner Uid */
  202.     unsigned long  i_size;        /* Size in bytes */
  203.     unsigned long  i_atime;        /* Access time */
  204.     unsigned long  i_ctime;        /* Creation time */
  205.     unsigned long  i_mtime;        /* Modification time */
  206.     unsigned long  i_dtime;        /* Deletion Time */
  207.     unsigned short i_gid;        /* Group Id */
  208.     unsigned short i_links_count;    /* Links count */
  209.     unsigned long  i_blocks;    /* Blocks count */
  210.     unsigned long  i_flags;        /* File flags */
  211.     union {
  212.         struct {
  213.             unsigned long  l_i_reserved1;
  214.         } linux1;
  215.         struct {
  216.             unsigned long  h_i_translator;
  217.         } hurd1;
  218.         struct {
  219.             unsigned long  m_i_reserved1;
  220.         } masix1;
  221.     } osd1;                /* OS dependent 1 */
  222.     unsigned long  i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  223.     unsigned long  i_version;    /* File version (for NFS) */
  224.     unsigned long  i_file_acl;    /* File ACL */
  225.     unsigned long  i_dir_acl;    /* Directory ACL */
  226.     unsigned long  i_faddr;        /* Fragment address */
  227.     union {
  228.         struct {
  229.             unsigned char  l_i_frag;    /* Fragment number */
  230.             unsigned char  l_i_fsize;    /* Fragment size */
  231.             unsigned short i_pad1;
  232.             unsigned long  l_i_reserved2[2];
  233.         } linux2;
  234.         struct {
  235.             unsigned char  h_i_frag;    /* Fragment number */
  236.             unsigned char  h_i_fsize;    /* Fragment size */
  237.             unsigned short h_i_mode_high;
  238.             unsigned short h_i_uid_high;
  239.             unsigned short h_i_gid_high;
  240.             unsigned long  h_i_author;
  241.         } hurd2;
  242.         struct {
  243.             unsigned char  m_i_frag;    /* Fragment number */
  244.             unsigned char  m_i_fsize;    /* Fragment size */
  245.             unsigned short m_pad1;
  246.             unsigned long  m_i_reserved2[2];
  247.         } masix2;
  248.     } osd2;                /* OS dependent 2 */
  249. };
  250.  
  251. #ifdef    __linux__
  252. #define i_reserved1    osd1.linux1.l_i_reserved1
  253. #define i_frag        osd2.linux2.l_i_frag
  254. #define i_fsize        osd2.linux2.l_i_fsize
  255. #define i_reserved2    osd2.linux2.l_i_reserved2
  256. #endif
  257.  
  258. #ifdef    __hurd__
  259. #define i_translator    osd1.hurd1.h_i_translator
  260. #define i_frag        osd2.hurd2.h_i_frag;
  261. #define i_fsize        osd2.hurd2.h_i_fsize;
  262. #define i_uid_high    osd2.hurd2.h_i_uid_high
  263. #define i_gid_high    osd2.hurd2.h_i_gid_high
  264. #define i_author    osd2.hurd2.h_i_author
  265. #endif
  266.  
  267. #ifdef    __masix__
  268. #define i_reserved1    osd1.masix1.m_i_reserved1
  269. #define i_frag        osd2.masix2.m_i_frag
  270. #define i_fsize        osd2.masix2.m_i_fsize
  271. #define i_reserved2    osd2.masix2.m_i_reserved2
  272. #endif
  273.  
  274. /*
  275.  * File system states
  276.  */
  277. #define    EXT2_VALID_FS            0x0001    /* Unmounted cleanly */
  278. #define    EXT2_ERROR_FS            0x0002    /* Errors detected */
  279.  
  280. /*
  281.  * Mount flags
  282.  */
  283. #define EXT2_MOUNT_CHECK_NORMAL        0x0001    /* Do some more checks */
  284. #define EXT2_MOUNT_CHECK_STRICT        0x0002    /* Do again more checks */
  285. #define EXT2_MOUNT_CHECK        (EXT2_MOUNT_CHECK_NORMAL | \
  286.                      EXT2_MOUNT_CHECK_STRICT)
  287. #define EXT2_MOUNT_GRPID        0x0004    /* Create files with directory's group */
  288. #define EXT2_MOUNT_DEBUG        0x0008    /* Some debugging messages */
  289. #define EXT2_MOUNT_ERRORS_CONT        0x0010    /* Continue on errors */
  290. #define EXT2_MOUNT_ERRORS_RO        0x0020    /* Remount fs ro on errors */
  291. #define EXT2_MOUNT_ERRORS_PANIC        0x0040    /* Panic on errors */
  292. #define EXT2_MOUNT_MINIX_DF        0x0080    /* Mimics the Minix statfs */
  293.  
  294. #define clear_opt(o, opt)        o &= ~EXT2_MOUNT_##opt
  295. #define set_opt(o, opt)            o |= EXT2_MOUNT_##opt
  296. #define test_opt(sb, opt)        ((sb)->u.ext2_sb.s_mount_opt & \
  297.                      EXT2_MOUNT_##opt)
  298. /*
  299.  * Maximal mount counts between two filesystem checks
  300.  */
  301. #define EXT2_DFL_MAX_MNT_COUNT        20    /* Allow 20 mounts */
  302. #define EXT2_DFL_CHECKINTERVAL        0    /* Don't use interval check */
  303.  
  304. /*
  305.  * Behaviour when detecting errors
  306.  */
  307. #define EXT2_ERRORS_CONTINUE        1    /* Continue execution */
  308. #define EXT2_ERRORS_RO            2    /* Remount fs read-only */
  309. #define EXT2_ERRORS_PANIC        3    /* Panic */
  310. #define EXT2_ERRORS_DEFAULT        EXT2_ERRORS_CONTINUE
  311.  
  312. /*
  313.  * Structure of the super block
  314.  */
  315. struct ext2_super_block {
  316.     unsigned long  s_inodes_count;    /* Inodes count */
  317.     unsigned long  s_blocks_count;    /* Blocks count */
  318.     unsigned long  s_r_blocks_count;/* Reserved blocks count */
  319.     unsigned long  s_free_blocks_count;/* Free blocks count */
  320.     unsigned long  s_free_inodes_count;/* Free inodes count */
  321.     unsigned long  s_first_data_block;/* First Data Block */
  322.     unsigned long  s_log_block_size;/* Block size */
  323.     long           s_log_frag_size;    /* Fragment size */
  324.     unsigned long  s_blocks_per_group;/* # Blocks per group */
  325.     unsigned long  s_frags_per_group;/* # Fragments per group */
  326.     unsigned long  s_inodes_per_group;/* # Inodes per group */
  327.     unsigned long  s_mtime;        /* Mount time */
  328.     unsigned long  s_wtime;        /* Write time */
  329.     unsigned short s_mnt_count;    /* Mount count */
  330.     short          s_max_mnt_count;    /* Maximal mount count */
  331.     unsigned short s_magic;        /* Magic signature */
  332.     unsigned short s_state;        /* File system state */
  333.     unsigned short s_errors;    /* Behaviour when detecting errors */
  334.     unsigned short s_pad;
  335.     unsigned long  s_lastcheck;    /* time of last check */
  336.     unsigned long  s_checkinterval;    /* max. time between checks */
  337.     unsigned long  s_creator_os;    /* OS */
  338.     unsigned long  s_rev_level;    /* Revision level */
  339.     unsigned short s_def_resuid;    /* Default uid for reserved blocks */
  340.     unsigned short s_def_resgid;    /* Default gid for reserved blocks */
  341.     unsigned long  s_reserved[235];    /* Padding to the end of the block */
  342. };
  343.  
  344. #define EXT2_OS_LINUX        0
  345. #define EXT2_OS_HURD        1
  346. #define EXT2_OS_MASIX        2
  347.  
  348. #define EXT2_CURRENT_REV    0
  349.  
  350. #define    EXT2_DEF_RESUID        0
  351. #define    EXT2_DEF_RESGID        0
  352.  
  353. /*
  354.  * Structure of a directory entry
  355.  */
  356. #define EXT2_NAME_LEN 255
  357.  
  358. struct ext2_dir_entry {
  359.     unsigned long  inode;            /* Inode number */
  360.     unsigned short rec_len;            /* Directory entry length */
  361.     unsigned short name_len;        /* Name length */
  362.     char           name[EXT2_NAME_LEN];    /* File name */
  363. };
  364.  
  365. /*
  366.  * EXT2_DIR_PAD defines the directory entries boundaries
  367.  *
  368.  * NOTE: It must be a multiple of 4
  369.  */
  370. #define EXT2_DIR_PAD             4
  371. #define EXT2_DIR_ROUND             (EXT2_DIR_PAD - 1)
  372. #define EXT2_DIR_REC_LEN(name_len)    (((name_len) + 8 + EXT2_DIR_ROUND) & \
  373.                      ~EXT2_DIR_ROUND)
  374.  
  375. #ifdef __KERNEL__
  376. /*
  377.  * Function prototypes
  378.  */
  379.  
  380. /*
  381.  * Ok, these declarations are also in <linux/kernel.h> but none of the
  382.  * ext2 source programs needs to include it so they are duplicated here.
  383.  */
  384. #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
  385. # define NORET_TYPE    __volatile__
  386. # define ATTRIB_NORET  /**/
  387. # define NORET_AND     /**/
  388. #else
  389. # define NORET_TYPE    /**/
  390. # define ATTRIB_NORET  __attribute__((noreturn))
  391. # define NORET_AND     noreturn,
  392. #endif
  393.  
  394. /* acl.c */
  395. extern int ext2_permission (struct inode *, int);
  396.  
  397. /* balloc.c */
  398. extern int ext2_new_block (struct super_block *, unsigned long,
  399.                unsigned long *, unsigned long *);
  400. extern void ext2_free_blocks (struct super_block *, unsigned long,
  401.                   unsigned long);
  402. extern unsigned long ext2_count_free_blocks (struct super_block *);
  403. extern void ext2_check_blocks_bitmap (struct super_block *);
  404.  
  405. /* bitmap.c */
  406. extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
  407.  
  408. /* dir.c */
  409. extern int ext2_check_dir_entry (char *, struct inode *,
  410.                  struct ext2_dir_entry *, struct buffer_head *,
  411.                  unsigned long);
  412.  
  413. /* file.c */
  414. extern int ext2_read (struct inode *, struct file *, char *, int);
  415. extern int ext2_write (struct inode *, struct file *, char *, int);
  416.  
  417. /* fsync.c */
  418. extern int ext2_sync_file (struct inode *, struct file *);
  419.  
  420. /* ialloc.c */
  421. extern struct inode * ext2_new_inode (const struct inode *, int);
  422. extern void ext2_free_inode (struct inode *);
  423. extern unsigned long ext2_count_free_inodes (struct super_block *);
  424. extern void ext2_check_inodes_bitmap (struct super_block *);
  425.  
  426. /* inode.c */
  427. extern int ext2_bmap (struct inode *, int);
  428.  
  429. extern struct buffer_head * ext2_getblk (struct inode *, long, int, int *);
  430. extern struct buffer_head * ext2_bread (struct inode *, int, int, int *);
  431.  
  432. extern int ext2_getcluster (struct inode * inode, long block);
  433. extern void ext2_read_inode (struct inode *);
  434. extern void ext2_write_inode (struct inode *);
  435. extern void ext2_put_inode (struct inode *);
  436. extern int ext2_sync_inode (struct inode *);
  437. extern void ext2_discard_prealloc (struct inode *);
  438.  
  439. /* ioctl.c */
  440. extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
  441.                unsigned long);
  442.  
  443. /* namei.c */
  444. extern void ext2_release (struct inode *, struct file *);
  445. extern int ext2_lookup (struct inode *,const char *, int, struct inode **);
  446. extern int ext2_create (struct inode *,const char *, int, int,
  447.             struct inode **);
  448. extern int ext2_mkdir (struct inode *, const char *, int, int);
  449. extern int ext2_rmdir (struct inode *, const char *, int);
  450. extern int ext2_unlink (struct inode *, const char *, int);
  451. extern int ext2_symlink (struct inode *, const char *, int, const char *);
  452. extern int ext2_link (struct inode *, struct inode *, const char *, int);
  453. extern int ext2_mknod (struct inode *, const char *, int, int, int);
  454. extern int ext2_rename (struct inode *, const char *, int,
  455.             struct inode *, const char *, int);
  456.  
  457. /* super.c */
  458. extern void ext2_error (struct super_block *, const char *, const char *, ...)
  459.     __attribute__ ((format (printf, 3, 4)));
  460. extern NORET_TYPE void ext2_panic (struct super_block *, const char *,
  461.                    const char *, ...)
  462.     __attribute__ ((NORET_AND format (printf, 3, 4)));
  463. extern void ext2_warning (struct super_block *, const char *, const char *, ...)
  464.     __attribute__ ((format (printf, 3, 4)));
  465. extern void ext2_put_super (struct super_block *);
  466. extern void ext2_write_super (struct super_block *);
  467. extern int ext2_remount (struct super_block *, int *, char *);
  468. extern struct super_block * ext2_read_super (struct super_block *,void *,int);
  469. extern void ext2_statfs (struct super_block *, struct statfs *);
  470.  
  471. /* truncate.c */
  472. extern void ext2_truncate (struct inode *);
  473.  
  474. /*
  475.  * Inodes and files operations
  476.  */
  477.  
  478. /* dir.c */
  479. extern struct inode_operations ext2_dir_inode_operations;
  480.  
  481. /* file.c */
  482. extern struct inode_operations ext2_file_inode_operations;
  483.  
  484. /* symlink.c */
  485. extern struct inode_operations ext2_symlink_inode_operations;
  486.  
  487. #endif    /* __KERNEL__ */
  488.  
  489. #endif    /* _LINUX_EXT2_FS_H */
  490.