ext2_fs.h

Go to the documentation of this file.
00001 /**
00002 *
00003 
00004  *  linux/include/linux/ext2_fs.h
00005  *
00006  *  Copyright (C) 1992, 1993, 1994  Remy Card (card@masi.ibp.fr)
00007  *                                  Laboratoire MASI - Institut Blaise Pascal
00008  *                                  Universite Pierre et Marie Curie (Paris VI)
00009  *
00010  *  from
00011  *
00012  *  linux/include/linux/minix_fs.h
00013  *
00014  *  Copyright (C) 1991, 1992  Linus Torvalds
00015 
00016 
00017 */
00018 
00019 #ifndef _LINUX_EXT2_FS_H
00020 #define _LINUX_EXT2_FS_H
00021 
00022 /**
00023 *
00024 
00025  * The second extended filesystem constants/structures
00026 
00027 
00028 */
00029 
00030 /**
00031 *
00032 
00033  * Define EXT2FS_DEBUG to produce debug messages
00034 
00035 
00036 */
00037 #undef EXT2FS_DEBUG
00038 
00039 /**
00040 *
00041 
00042  * Define EXT2FS_DEBUG_CACHE to produce cache debug messages
00043 
00044 
00045 */
00046 #undef EXT2FS_DEBUG_CACHE
00047 
00048 /**
00049 *
00050 
00051  * Define EXT2FS_CHECK_CACHE to add some checks to the name cache code
00052 
00053 
00054 */
00055 #undef EXT2FS_CHECK_CACHE
00056 
00057 /**
00058 *
00059 
00060  * Define EXT2FS_PRE_02B_COMPAT to convert ext 2 fs prior to 0.2b
00061 
00062 
00063 */
00064 #undef EXT2FS_PRE_02B_COMPAT
00065 
00066 /**
00067 *
00068 
00069  * Define DONT_USE_DCACHE to inhibit the directory cache
00070 
00071 
00072 */
00073 #define DONT_USE_DCACHE
00074 
00075 /**
00076 *
00077 
00078  * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
00079 
00080 
00081 */
00082 #define EXT2_PREALLOCATE
00083 
00084 /**
00085 *
00086 
00087  * The second extended file system version
00088 
00089 
00090 */
00091 #define EXT2FS_DATE             "94/03/10"
00092 #define EXT2FS_VERSION          "0.5"
00093 
00094 /**
00095 *
00096 
00097  * Debug code
00098 
00099 
00100 */
00101 #ifdef EXT2FS_DEBUG
00102 #       define ext2_debug(f, a...)      { \
00103                                         printk ("EXT2-fs DEBUG (%s, %d): %s:", \
00104                                                 __FILE__, __LINE__, __FUNCTION__); \
00105                                         printk (f, ## a); \
00106                                         }
00107 #else
00108 #       define ext2_debug(f, a...)      ///<
00109 #endif
00110 
00111 /**
00112 *
00113 
00114  * Special inodes numbers
00115 
00116 
00117 */
00118 #define EXT2_BAD_INO             1      ///< Bad blocks inode 
00119 #define EXT2_ROOT_INO            2      ///< Root inode 
00120 #define EXT2_ACL_IDX_INO         3      ///< ACL inode 
00121 #define EXT2_ACL_DATA_INO        4      ///< ACL inode 
00122 #define EXT2_BOOT_LOADER_INO     5      ///< Boot loader inode 
00123 #define EXT2_UNDEL_DIR_INO       6      ///< Undelete directory inode 
00124 #define EXT2_FIRST_INO          11      ///< First non reserved inode 
00125 
00126 /**
00127 *
00128 
00129  * The second extended file system magic number
00130 
00131 
00132 */
00133 #define EXT2_PRE_02B_MAGIC      0xEF51
00134 #define EXT2_SUPER_MAGIC        0xEF53
00135 
00136 /**
00137 *
00138 
00139  * Maximal count of links to a file
00140 
00141 
00142 */
00143 #define EXT2_LINK_MAX           32000
00144 
00145 /**
00146 *
00147 
00148  * Macro-instructions used to manage several block sizes
00149 
00150 
00151 */
00152 #define EXT2_MIN_BLOCK_SIZE             1024
00153 #define EXT2_MAX_BLOCK_SIZE             4096
00154 #define EXT2_MIN_BLOCK_LOG_SIZE           10
00155 #ifdef __KERNEL__
00156 # define EXT2_BLOCK_SIZE(s)             ((s)->s_blocksize)
00157 #else
00158 # define EXT2_BLOCK_SIZE(s)             (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
00159 #endif
00160 #define EXT2_ACLE_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
00161 #define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (unsigned long))
00162 #ifdef __KERNEL__
00163 # define EXT2_BLOCK_SIZE_BITS(s)        ((s)->u.ext2_sb.s_es->s_log_block_size + 10)
00164 #else
00165 # define EXT2_BLOCK_SIZE_BITS(s)        ((s)->s_log_block_size + 10)
00166 #endif
00167 #define EXT2_INODES_PER_BLOCK(s)        (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_inode))
00168 
00169 /**
00170 *
00171 
00172  * Macro-instructions used to manage fragments
00173 
00174 
00175 */
00176 #define EXT2_MIN_FRAG_SIZE              1024
00177 #define EXT2_MAX_FRAG_SIZE              4096
00178 #define EXT2_MIN_FRAG_LOG_SIZE            10
00179 #ifdef __KERNEL__
00180 # define EXT2_FRAG_SIZE(s)              ((s)->u.ext2_sb.s_frag_size)
00181 # define EXT2_FRAGS_PER_BLOCK(s)        ((s)->u.ext2_sb.s_frags_per_block)
00182 #else
00183 # define EXT2_FRAG_SIZE(s)              (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
00184 # define EXT2_FRAGS_PER_BLOCK(s)        (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
00185 #endif
00186 
00187 /**
00188 *
00189 
00190  * ACL structures
00191 
00192 
00193 */
00194 struct ext2_acl_header  ///< Header of Access Control Lists 
00195 {
00196         unsigned long aclh_size;
00197         unsigned long aclh_file_count;
00198         unsigned long aclh_acle_count;
00199         unsigned long aclh_first_acle;
00200 };
00201 
00202 struct ext2_acl_entry   ///< Access Control List Entry 
00203 {
00204         unsigned long  acle_size;
00205         unsigned short acle_perms;      ///< Access permissions 
00206         unsigned short acle_type;       ///< Type of entry 
00207         unsigned short acle_tag;        ///< User or group identity 
00208         unsigned short acle_pad1;
00209         unsigned long  acle_next;       ///< Pointer on next entry for the 
00210                                         /// same inode or on next free entry 
00211 };
00212 
00213 /**
00214 *
00215 
00216  * Structure of a blocks group descriptor
00217 
00218 
00219 */
00220 struct ext2_old_group_desc
00221 {
00222         unsigned long  bg_block_bitmap;         ///< Blocks bitmap block 
00223         unsigned long  bg_inode_bitmap;         ///< Inodes bitmap block 
00224         unsigned long  bg_inode_table;          ///< Inodes table block 
00225         unsigned short bg_free_blocks_count;    ///< Free blocks count 
00226         unsigned short bg_free_inodes_count;    ///< Free inodes count 
00227 };
00228 
00229 struct ext2_group_desc
00230 {
00231         unsigned long  bg_block_bitmap;         ///< Blocks bitmap block 
00232         unsigned long  bg_inode_bitmap;         ///< Inodes bitmap block 
00233         unsigned long  bg_inode_table;          ///< Inodes table block 
00234         unsigned short bg_free_blocks_count;    ///< Free blocks count 
00235         unsigned short bg_free_inodes_count;    ///< Free inodes count 
00236         unsigned short bg_used_dirs_count;      ///< Directories count 
00237         unsigned short bg_pad;
00238         unsigned long  bg_reserved[3];
00239 };
00240 
00241 /**
00242 *
00243 
00244  * Macro-instructions used to manage group descriptors
00245 
00246 
00247 */
00248 #ifdef __KERNEL__
00249 # define EXT2_BLOCKS_PER_GROUP(s)       ((s)->u.ext2_sb.s_blocks_per_group)
00250 # define EXT2_DESC_PER_BLOCK(s)         ((s)->u.ext2_sb.s_desc_per_block)
00251 # define EXT2_INODES_PER_GROUP(s)       ((s)->u.ext2_sb.s_inodes_per_group)
00252 #else
00253 # define EXT2_BLOCKS_PER_GROUP(s)       ((s)->s_blocks_per_group)
00254 # define EXT2_DESC_PER_BLOCK(s)         (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
00255 # define EXT2_INODES_PER_GROUP(s)       ((s)->s_inodes_per_group)
00256 #endif
00257 
00258 /**
00259 *
00260 
00261  * Constants relative to the data blocks
00262 
00263 
00264 */
00265 #define EXT2_NDIR_BLOCKS                12
00266 #define EXT2_IND_BLOCK                  EXT2_NDIR_BLOCKS
00267 #define EXT2_DIND_BLOCK                 (EXT2_IND_BLOCK + 1)
00268 #define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
00269 #define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
00270 
00271 /**
00272 *
00273 
00274  * Inode flags
00275 
00276 
00277 */
00278 #define EXT2_SECRM_FL                   0x0001  ///< Secure deletion 
00279 #define EXT2_UNRM_FL                    0x0002  ///< Undelete 
00280 #define EXT2_COMPR_FL                   0x0004  ///< Compress file 
00281 #define EXT2_SYNC_FL                    0x0008  ///< Synchronous updates 
00282 
00283 /**
00284 *
00285 
00286  * ioctl commands
00287 
00288 
00289 */
00290 #define EXT2_IOC_GETFLAGS               _IOR('f', 1, long)
00291 #define EXT2_IOC_SETFLAGS               _IOW('f', 2, long)
00292 #define EXT2_IOC_GETVERSION             _IOR('v', 1, long)
00293 #define EXT2_IOC_SETVERSION             _IOW('v', 2, long)
00294 
00295 /**
00296 *
00297 
00298  * Structure of an inode on the disk
00299 
00300 
00301 */
00302 struct ext2_inode {
00303         unsigned short i_mode;          ///< File mode 
00304         unsigned short i_uid;           ///< Owner Uid 
00305         unsigned long  i_size;          ///< Size in bytes 
00306         unsigned long  i_atime;         ///< Access time 
00307         unsigned long  i_ctime;         ///< Creation time 
00308         unsigned long  i_mtime;         ///< Modification time 
00309         unsigned long  i_dtime;         ///< Deletion Time 
00310         unsigned short i_gid;           ///< Group Id 
00311         unsigned short i_links_count;   ///< Links count 
00312         unsigned long  i_blocks;        ///< Blocks count 
00313         unsigned long  i_flags;         ///< File flags 
00314         unsigned long  i_reserved1;
00315         unsigned long  i_block[EXT2_N_BLOCKS];///< Pointers to blocks 
00316         unsigned long  i_version;       ///< File version (for NFS) 
00317         unsigned long  i_file_acl;      ///< File ACL 
00318         unsigned long  i_dir_acl;       ///< Directory ACL 
00319         unsigned long  i_faddr;         ///< Fragment address 
00320         unsigned char  i_frag;          ///< Fragment number 
00321         unsigned char  i_fsize;         ///< Fragment size 
00322         unsigned short i_pad1;
00323         unsigned long  i_reserved2[2];
00324 };
00325 
00326 /**
00327 *
00328 
00329  * File system states
00330 
00331 
00332 */
00333 #define EXT2_VALID_FS                   0x0001  ///< Unmounted cleany 
00334 #define EXT2_ERROR_FS                   0x0002  ///< Errors detected 
00335 
00336 /**
00337 *
00338 
00339  * Mount flags
00340 
00341 
00342 */
00343 #define EXT2_MOUNT_CHECK_NORMAL         0x0001  ///< Do some more checks 
00344 #define EXT2_MOUNT_CHECK_STRICT         0x0002  ///< Do again more checks 
00345 #define EXT2_MOUNT_CHECK                (EXT2_MOUNT_CHECK_NORMAL | \
00346                                          EXT2_MOUNT_CHECK_STRICT)
00347 #define EXT2_MOUNT_GRPID                0x0004  ///< Create files with directory's group 
00348 #define EXT2_MOUNT_DEBUG                0x0008  ///< Some debugging messages 
00349 #define EXT2_MOUNT_ERRORS_CONT          0x0010  ///< Continue on errors 
00350 #define EXT2_MOUNT_ERRORS_RO            0x0020  ///< Remount fs ro on errors 
00351 #define EXT2_MOUNT_ERRORS_PANIC         0x0040  ///< Panic on errors 
00352 
00353 #define clear_opt(o, opt)               o &= ~EXT2_MOUNT_##opt
00354 #define set_opt(o, opt)                 o |= EXT2_MOUNT_##opt
00355 #define test_opt(sb, opt)               ((sb)->u.ext2_sb.s_mount_opt & \
00356                                          EXT2_MOUNT_##opt)
00357 /**
00358 *
00359 
00360  * Maximal mount counts between two filesystem checks
00361 
00362 
00363 */
00364 #define EXT2_DFL_MAX_MNT_COUNT          20      ///< Allow 20 mounts 
00365 #define EXT2_DFL_CHECKINTERVAL          0       ///< Don't use interval check 
00366 
00367 /**
00368 *
00369 
00370  * Behaviour when detecting errors
00371 
00372 
00373 */
00374 #define EXT2_ERRORS_CONTINUE            1       ///< Continue execution 
00375 #define EXT2_ERRORS_RO                  2       ///< Remount fs read-only 
00376 #define EXT2_ERRORS_PANIC               3       ///< Panic 
00377 #define EXT2_ERRORS_DEFAULT             EXT2_ERRORS_CONTINUE
00378 
00379 /**
00380 *
00381 
00382  * Structure of the super block
00383 
00384 
00385 */
00386 struct ext2_super_block {
00387         unsigned long  s_inodes_count;  ///< Inodes count 
00388         unsigned long  s_blocks_count;  ///< Blocks count 
00389         unsigned long  s_r_blocks_count;///< Reserved blocks count 
00390         unsigned long  s_free_blocks_count;///< Free blocks count 
00391         unsigned long  s_free_inodes_count;///< Free inodes count 
00392         unsigned long  s_first_data_block;///< First Data Block 
00393         unsigned long  s_log_block_size;///< Block size 
00394         long           s_log_frag_size; ///< Fragment size 
00395         unsigned long  s_blocks_per_group;///< # Blocks per group 
00396         unsigned long  s_frags_per_group;///< # Fragments per group 
00397         unsigned long  s_inodes_per_group;///< # Inodes per group 
00398         unsigned long  s_mtime;         ///< Mount time 
00399         unsigned long  s_wtime;         ///< Write time 
00400         unsigned short s_mnt_count;     ///< Mount count 
00401         short          s_max_mnt_count; ///< Maximal mount count 
00402         unsigned short s_magic;         ///< Magic signature 
00403         unsigned short s_state;         ///< File system state 
00404         unsigned short s_errors;        ///< Behaviour when detecting errors 
00405         unsigned short s_pad;
00406         unsigned long  s_lastcheck;     ///< time of last check 
00407         unsigned long  s_checkinterval; ///< max. time between checks 
00408         unsigned long  s_reserved[238]; ///< Padding to the end of the block 
00409 };
00410 
00411 /**
00412 *
00413 
00414  * Structure of a directory entry
00415 
00416 
00417 */
00418 #define EXT2_NAME_LEN 255
00419 
00420 struct ext2_dir_entry {
00421         unsigned long  inode;                   ///< Inode number 
00422         unsigned short rec_len;                 ///< Directory entry length 
00423         unsigned short name_len;                ///< Name length 
00424         char           name[EXT2_NAME_LEN];     ///< File name 
00425 };
00426 
00427 /**
00428 *
00429 
00430  * EXT2_DIR_PAD defines the directory entries boundaries
00431  *
00432  * NOTE: It must be a multiple of 4
00433 
00434 
00435 */
00436 #define EXT2_DIR_PAD                    4
00437 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
00438 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
00439                                          ~EXT2_DIR_ROUND)
00440 
00441 #ifdef __KERNEL__
00442 /**
00443 *
00444 
00445  * Function prototypes
00446 
00447 
00448 */
00449 
00450 /**
00451 *
00452 
00453  * Ok, these declarations are also in <linux/kernel.h> but none of the
00454  * ext2 source programs needs to include it so they are duplicated here.
00455 
00456 
00457 */
00458 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
00459 # define NORET_TYPE    __volatile__
00460 # define ATTRIB_NORET  ///<
00461 # define NORET_AND     ///<
00462 #else
00463 # define NORET_TYPE    ///<
00464 # define ATTRIB_NORET  __attribute__((noreturn))
00465 # define NORET_AND     noreturn,
00466 #endif
00467 
00468 /// acl.c 
00469 extern int ext2_permission (struct inode *, int);
00470 
00471 /// balloc.c 
00472 extern int ext2_new_block (struct super_block *, unsigned long,
00473                            unsigned long *, unsigned long *);
00474 extern void ext2_free_blocks (struct super_block *, unsigned long,
00475                               unsigned long);
00476 extern unsigned long ext2_count_free_blocks (struct super_block *);
00477 extern void ext2_check_blocks_bitmap (struct super_block *);
00478 
00479 /// bitmap.c 
00480 extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
00481 
00482 #ifndef DONT_USE_DCACHE
00483 /// dcache.c 
00484 extern void ext2_dcache_invalidate (unsigned short);
00485 extern unsigned long ext2_dcache_lookup (unsigned short, unsigned long,
00486                                          const char *, int);
00487 extern void ext2_dcache_add (unsigned short, unsigned long, const char *,
00488                              int, unsigned long);
00489 extern void ext2_dcache_remove (unsigned short, unsigned long, const char *,
00490                                 int);
00491 #endif
00492 
00493 /// dir.c 
00494 extern int ext2_check_dir_entry (char *, struct inode *,
00495                                  struct ext2_dir_entry *, struct buffer_head *,
00496                                  unsigned long);
00497 
00498 /// file.c 
00499 extern int ext2_read (struct inode *, struct file *, char *, int);
00500 extern int ext2_write (struct inode *, struct file *, char *, int);
00501 
00502 /// fsync.c 
00503 extern int ext2_sync_file (struct inode *, struct file *);
00504 
00505 /// ialloc.c 
00506 extern struct inode * ext2_new_inode (const struct inode *, int);
00507 extern void ext2_free_inode (struct inode *);
00508 extern unsigned long ext2_count_free_inodes (struct super_block *);
00509 extern void ext2_check_inodes_bitmap (struct super_block *);
00510 
00511 /// inode.c 
00512 extern int ext2_bmap (struct inode *, int);
00513 
00514 extern struct buffer_head * ext2_getblk (struct inode *, long, int, int *);
00515 extern struct buffer_head * ext2_bread (struct inode *, int, int, int *);
00516 
00517 extern void ext2_read_inode (struct inode *);
00518 extern void ext2_write_inode (struct inode *);
00519 extern void ext2_put_inode (struct inode *);
00520 extern int ext2_sync_inode (struct inode *);
00521 extern void ext2_discard_prealloc (struct inode *);
00522 
00523 /// ioctl.c 
00524 extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
00525                        unsigned long);
00526 
00527 /// namei.c 
00528 extern int ext2_open (struct inode *, struct file *);
00529 extern void ext2_release (struct inode *, struct file *);
00530 extern int ext2_lookup (struct inode *,const char *, int, struct inode **);
00531 extern int ext2_create (struct inode *,const char *, int, int,
00532                         struct inode **);
00533 extern int ext2_mkdir (struct inode *, const char *, int, int);
00534 extern int ext2_rmdir (struct inode *, const char *, int);
00535 extern int ext2_unlink (struct inode *, const char *, int);
00536 extern int ext2_symlink (struct inode *, const char *, int, const char *);
00537 extern int ext2_link (struct inode *, struct inode *, const char *, int);
00538 extern int ext2_mknod (struct inode *, const char *, int, int, int);
00539 extern int ext2_rename (struct inode *, const char *, int,
00540                         struct inode *, const char *, int);
00541 
00542 /// super.c 
00543 extern void ext2_error (struct super_block *, const char *, const char *, ...)
00544         __attribute__ ((format (printf, 3, 4)));
00545 extern NORET_TYPE void ext2_panic (struct super_block *, const char *,
00546                                    const char *, ...)
00547         __attribute__ ((NORET_AND format (printf, 3, 4)));
00548 extern void ext2_warning (struct super_block *, const char *, const char *, ...)
00549         __attribute__ ((format (printf, 3, 4)));
00550 extern void ext2_put_super (struct super_block *);
00551 extern void ext2_write_super (struct super_block *);
00552 extern int ext2_remount (struct super_block *, int *, char *);
00553 extern struct super_block * ext2_read_super (struct super_block *,void *,int);
00554 extern void ext2_statfs (struct super_block *, struct statfs *);
00555 
00556 /// truncate.c 
00557 extern void ext2_truncate (struct inode *);
00558 
00559 /**
00560 *
00561 
00562  * Inodes and files operations
00563 
00564 
00565 */
00566 
00567 /// dir.c 
00568 extern struct inode_operations ext2_dir_inode_operations;
00569 
00570 /// file.c 
00571 extern struct inode_operations ext2_file_inode_operations;
00572 
00573 /// symlink.c 
00574 extern struct inode_operations ext2_symlink_inode_operations;
00575 
00576 #endif  // __KERNEL__ 
00577 
00578 #endif  // _LINUX_EXT2_FS_H 

Generated on Mon May 1 21:47:00 2006 for KernelAPI by  doxygen 1.4.6-5