root/include/linux/ext2_fs.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


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

/* [previous][next][first][last][top][bottom][index][help] */