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

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