ReactOS 0.4.16-dev-297-gc569aee
ext4_ext.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ext4_extent_tail
 
struct  ext4_extent
 
struct  ext4_extent_idx
 
struct  ext4_extent_header
 
struct  ext4_ext_path
 

Macros

#define EXT4_EXT_MAGIC   0xf30a
 
#define get_ext4_header(i)   ((struct ext4_extent_header *) (i)->i_block)
 
#define EXT4_EXTENT_TAIL_OFFSET(hdr)
 
#define EXT_INIT_MAX_LEN   (1UL << 15)
 
#define EXT_UNWRITTEN_MAX_LEN   (EXT_INIT_MAX_LEN - 1)
 
#define EXT_EXTENT_SIZE   sizeof(struct ext4_extent)
 
#define EXT_INDEX_SIZE   sizeof(struct ext4_extent_idx)
 
#define EXT_FIRST_EXTENT(__hdr__)
 
#define EXT_FIRST_INDEX(__hdr__)
 
#define EXT_HAS_FREE_INDEX(__path__)    ((__path__)->p_hdr->eh_entries < (__path__)->p_hdr->eh_max)
 
#define EXT_LAST_EXTENT(__hdr__)    (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_entries - 1)
 
#define EXT_LAST_INDEX(__hdr__)    (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_entries - 1)
 
#define EXT_MAX_EXTENT(__hdr__)    (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_max - 1)
 
#define EXT_MAX_INDEX(__hdr__)    (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_max - 1)
 
#define ext4_ext_dirty(icb, handle, inode, path)    __ext4_ext_dirty("", __LINE__, (icb), (handle), (inode), (path))
 
#define INODE_HAS_EXTENT(i)   ((i)->i_flags & EXT2_EXTENTS_FL)
 

Functions

struct ext4_extent __attribute__ ((__packed__)) EXT4_EXTENT
 
static struct ext4_extent_tailfind_ext4_extent_tail (struct ext4_extent_header *eh)
 
static struct ext4_extent_headerext_inode_hdr (struct inode *inode)
 
static struct ext4_extent_headerext_block_hdr (struct buffer_head *bh)
 
static unsigned short ext_depth (struct inode *inode)
 
static void ext4_ext_mark_uninitialized (struct ext4_extent *ext)
 
static int ext4_ext_is_uninitialized (struct ext4_extent *ext)
 
static uint16_t ext4_ext_get_actual_len (struct ext4_extent *ext)
 
static void ext4_ext_mark_initialized (struct ext4_extent *ext)
 
static void ext4_ext_mark_unwritten (struct ext4_extent *ext)
 
static int ext4_ext_is_unwritten (struct ext4_extent *ext)
 
static ext4_fsblk_t ext4_ext_pblock (struct ext4_extent *ex)
 
static ext4_fsblk_t ext4_idx_pblock (struct ext4_extent_idx *ix)
 
static void ext4_ext_store_pblock (struct ext4_extent *ex, ext4_fsblk_t pb)
 
static void ext4_idx_store_pblock (struct ext4_extent_idx *ix, ext4_fsblk_t pb)
 
static uint64_t ext_to_block (EXT4_EXTENT *extent)
 
static uint64_t idx_to_block (EXT4_EXTENT_IDX *idx)
 
int ext4_ext_get_blocks (void *icb, handle_t *handle, struct inode *inode, ext4_fsblk_t iblock, unsigned long max_blocks, struct buffer_head *bh_result, int create, int flags)
 
int ext4_ext_tree_init (void *icb, handle_t *handle, struct inode *inode)
 
int ext4_ext_truncate (void *icb, struct inode *inode, unsigned long start)
 

Variables

uint32_t ee_block
 
uint16_t ee_len
 
uint16_t ee_start_hi
 
uint32_t ee_start_lo
 
uint32_t ei_block
 
uint32_t ei_leaf_lo
 
uint16_t ei_leaf_hi
 
uint16_t ei_unused
 
uint16_t eh_magic
 
uint16_t eh_entries
 
uint16_t eh_max
 
uint16_t eh_depth
 
uint32_t eh_generation
 
struct ext4_ext_path __attribute__
 

Macro Definition Documentation

◆ ext4_ext_dirty

#define ext4_ext_dirty (   icb,
  handle,
  inode,
  path 
)     __ext4_ext_dirty("", __LINE__, (icb), (handle), (inode), (path))

Definition at line 225 of file ext4_ext.h.

◆ EXT4_EXT_MAGIC

#define EXT4_EXT_MAGIC   0xf30a

Definition at line 50 of file ext4_ext.h.

◆ EXT4_EXTENT_TAIL_OFFSET

#define EXT4_EXTENT_TAIL_OFFSET (   hdr)
Value:
(sizeof(struct ext4_extent_header) + \
uint16_t eh_max
Definition: ext4_ext.h:2
char hdr[14]
Definition: iptest.cpp:33
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Definition at line 53 of file ext4_ext.h.

◆ EXT_EXTENT_SIZE

#define EXT_EXTENT_SIZE   sizeof(struct ext4_extent)

Definition at line 104 of file ext4_ext.h.

◆ EXT_FIRST_EXTENT

#define EXT_FIRST_EXTENT (   __hdr__)
Value:
((struct ext4_extent *)(((char *)(__hdr__)) + \
sizeof(struct ext4_extent_header)))

Definition at line 107 of file ext4_ext.h.

◆ EXT_FIRST_INDEX

#define EXT_FIRST_INDEX (   __hdr__)
Value:
((struct ext4_extent_idx *)(((char *)(__hdr__)) + \
sizeof(struct ext4_extent_header)))

Definition at line 110 of file ext4_ext.h.

◆ EXT_HAS_FREE_INDEX

#define EXT_HAS_FREE_INDEX (   __path__)     ((__path__)->p_hdr->eh_entries < (__path__)->p_hdr->eh_max)

Definition at line 113 of file ext4_ext.h.

◆ EXT_INDEX_SIZE

#define EXT_INDEX_SIZE   sizeof(struct ext4_extent_idx)

Definition at line 105 of file ext4_ext.h.

◆ EXT_INIT_MAX_LEN

#define EXT_INIT_MAX_LEN   (1UL << 15)

Definition at line 101 of file ext4_ext.h.

◆ EXT_LAST_EXTENT

#define EXT_LAST_EXTENT (   __hdr__)     (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_entries - 1)

Definition at line 115 of file ext4_ext.h.

◆ EXT_LAST_INDEX

#define EXT_LAST_INDEX (   __hdr__)     (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_entries - 1)

Definition at line 117 of file ext4_ext.h.

◆ EXT_MAX_EXTENT

#define EXT_MAX_EXTENT (   __hdr__)     (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_max - 1)

Definition at line 119 of file ext4_ext.h.

◆ EXT_MAX_INDEX

#define EXT_MAX_INDEX (   __hdr__)     (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_max - 1)

Definition at line 121 of file ext4_ext.h.

◆ EXT_UNWRITTEN_MAX_LEN

#define EXT_UNWRITTEN_MAX_LEN   (EXT_INIT_MAX_LEN - 1)

Definition at line 102 of file ext4_ext.h.

◆ get_ext4_header

#define get_ext4_header (   i)    ((struct ext4_extent_header *) (i)->i_block)

Definition at line 51 of file ext4_ext.h.

◆ INODE_HAS_EXTENT

#define INODE_HAS_EXTENT (   i)    ((i)->i_flags & EXT2_EXTENTS_FL)

Definition at line 228 of file ext4_ext.h.

Function Documentation

◆ __attribute__()

struct ext4_extent __attribute__ ( (__packed__)  )

◆ ext4_ext_get_actual_len()

static uint16_t ext4_ext_get_actual_len ( struct ext4_extent ext)
inlinestatic

◆ ext4_ext_get_blocks()

int ext4_ext_get_blocks ( void icb,
handle_t handle,
struct inode inode,
ext4_fsblk_t  iblock,
unsigned long  max_blocks,
struct buffer_head bh_result,
int  create,
int  flags 
)

Definition at line 2384 of file ext4_extents.c.

2388{
2389 struct ext4_ext_path *path = NULL;
2390 struct ext4_extent newex, *ex;
2391 int goal, err = 0, depth;
2392 unsigned long allocated = 0;
2393 ext4_fsblk_t next, newblock;
2394
2395 clear_buffer_new(bh_result);
2396 /*mutex_lock(&ext4_I(inode)->truncate_mutex);*/
2397
2398 /* find extent for this block */
2399 path = ext4_find_extent(inode, iblock, NULL, 0);
2400 if (IS_ERR(path)) {
2401 err = PTR_ERR(path);
2402 path = NULL;
2403 goto out2;
2404 }
2405
2407
2408 /*
2409 * consistent leaf must not be empty
2410 * this situations is possible, though, _during_ tree modification
2411 * this is why assert can't be put in ext4_ext_find_extent()
2412 */
2413 BUG_ON(path[depth].p_ext == NULL && depth != 0);
2414
2415 if ((ex = path[depth].p_ext)) {
2416 ext4_lblk_t ee_block = le32_to_cpu(ex->ee_block);
2417 ext4_fsblk_t ee_start = ext4_ext_pblock(ex);
2418 unsigned short ee_len = ext4_ext_get_actual_len(ex);
2419 /* if found exent covers block, simple return it */
2420 if (iblock >= ee_block && iblock < ee_block + ee_len) {
2421
2422 /* number of remain blocks in the extent */
2423 allocated = ee_len + ee_block - iblock;
2424
2426 if (create) {
2427 newblock = iblock - ee_block + ee_start;
2429 icb, handle,
2430 inode,
2431 &path,
2432 iblock,
2433 allocated,
2434 flags);
2435 if (err)
2436 goto out2;
2437
2438 } else {
2439 newblock = 0;
2440 }
2441 } else {
2442 newblock = iblock - ee_block + ee_start;
2443 }
2444 goto out;
2445 }
2446 }
2447
2448 /*
2449 * requested block isn't allocated yet
2450 * we couldn't try to create block if create flag is zero
2451 */
2452 if (!create) {
2453 goto out2;
2454 }
2455
2456 /* find next allocated block so that we know how many
2457 * blocks we can allocate without ovelapping next extent */
2459 BUG_ON(next <= iblock);
2460 allocated = next - iblock;
2462 max_blocks = EXT_UNWRITTEN_MAX_LEN;
2463 if (allocated > max_blocks)
2464 allocated = max_blocks;
2465
2466 /* allocate new block */
2467 goal = ext4_ext_find_goal(inode, path, iblock);
2468
2469 newblock = ext4_new_meta_blocks(icb, handle, inode, goal, 0,
2470 &allocated, &err);
2471 if (!newblock)
2472 goto out2;
2473
2474 /* try to insert new extent into found leaf and return */
2475 newex.ee_block = cpu_to_le32(iblock);
2476 ext4_ext_store_pblock(&newex, newblock);
2477 newex.ee_len = cpu_to_le16(allocated);
2478 /* if it's fallocate, mark ex as unwritten */
2481 }
2482 err = ext4_ext_insert_extent(icb, handle, inode, &path, &newex,
2484
2485 if (err) {
2486 /* free data blocks we just allocated */
2489 goto out2;
2490 }
2491
2493
2494 /* previous routine could use block we allocated */
2495 if (ext4_ext_is_unwritten(&newex))
2496 newblock = 0;
2497 else
2498 newblock = ext4_ext_pblock(&newex);
2499
2500 set_buffer_new(bh_result);
2501
2502out:
2503 if (allocated > max_blocks)
2504 allocated = max_blocks;
2505
2507 set_buffer_mapped(bh_result);
2508 bh_result->b_bdev = inode->i_sb->s_bdev;
2509 bh_result->b_blocknr = newblock;
2510out2:
2511 if (path) {
2513 kfree(path);
2514 }
2515 /*mutex_unlock(&ext4_I(inode)->truncate_mutex);*/
2516
2517 return err ? err : allocated;
#define NULL
Definition: types.h:112
__u32 ext4_lblk_t
Definition: ext3_fs_i.h:31
unsigned long long ext4_fsblk_t
Definition: ext3_fs_i.h:27
#define EXT4_GET_BLOCKS_PRE_IO
Definition: ext4.h:31
static void ext4_ext_mark_unwritten(struct ext4_extent *ext)
Definition: ext4_ext.h:163
static int ext4_ext_is_unwritten(struct ext4_extent *ext)
Definition: ext4_ext.h:169
#define EXT_UNWRITTEN_MAX_LEN
Definition: ext4_ext.h:102
static unsigned short ext_depth(struct inode *inode)
Definition: ext4_ext.h:134
static ext4_fsblk_t ext4_ext_pblock(struct ext4_extent *ex)
Definition: ext4_ext.h:179
static void ext4_ext_store_pblock(struct ext4_extent *ex, ext4_fsblk_t pb)
Definition: ext4_ext.h:206
static uint16_t ext4_ext_get_actual_len(struct ext4_extent *ext)
Definition: ext4_ext.h:151
uint16_t ee_len
Definition: ext4_ext.h:1
uint32_t ee_block
Definition: ext4_ext.h:0
static int get_default_free_blocks_flags(struct inode *inode)
static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode, struct ext4_ext_path *path, ext4_lblk_t block)
Definition: ext4_extents.c:299
void ext4_ext_drop_refs(struct ext4_ext_path *path)
Definition: ext4_extents.c:379
static int ext4_ext_convert_to_initialized(void *icb, handle_t *handle, struct inode *inode, struct ext4_ext_path **ppath, ext4_lblk_t split, unsigned long blocks, int flags)
int ext4_ext_insert_extent(void *icb, handle_t *handle, struct inode *inode, struct ext4_ext_path **ppath, struct ext4_extent *newext, int gb_flags)
#define ext4_mark_inode_dirty(icb, handle, n)
Definition: ext4_extents.c:44
static void ext4_free_blocks(void *icb, handle_t *handle, struct inode *inode, void *fake, ext4_fsblk_t block, int count, int flags)
Definition: ext4_extents.c:77
struct ext4_ext_path * ext4_find_extent(struct inode *inode, ext4_lblk_t block, struct ext4_ext_path **orig_path, int flags)
Definition: ext4_extents.c:644
static ext4_fsblk_t ext4_new_meta_blocks(void *icb, handle_t *handle, struct inode *inode, ext4_fsblk_t goal, unsigned int flags, unsigned long *count, int *errp)
Definition: ext4_extents.c:52
ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_ext_path *path)
#define ext4_ext_show_leaf(inode, path)
Definition: ext4_extents.c:639
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLbitfield flags
Definition: glext.h:7161
static long IS_ERR(const void *ptr)
Definition: module.h:249
static long PTR_ERR(const void *ptr)
Definition: module.h:244
#define le16_to_cpu
Definition: module.h:151
#define cpu_to_le32
Definition: module.h:148
#define kfree(p)
Definition: module.h:1126
#define le32_to_cpu
Definition: module.h:149
#define BUG_ON(c)
Definition: module.h:255
#define cpu_to_le16
Definition: module.h:150
static const struct access_res create[16]
Definition: package.c:7505
static unsigned __int64 next
Definition: rand_nt.c:6
#define err(...)
static FILE * out
Definition: regtests2xml.c:44
struct block_device * b_bdev
Definition: module.h:731
blkcnt_t b_blocknr
Definition: module.h:733
Definition: comerr.c:44
Definition: fs.h:78
struct super_block * i_sb
Definition: fs.h:96

Referenced by Ext2DoExtentExpand(), and Ext2MapExtent().

◆ ext4_ext_is_uninitialized()

static int ext4_ext_is_uninitialized ( struct ext4_extent ext)
inlinestatic

Definition at line 145 of file ext4_ext.h.

146{
147 /* Extent with ee_len of 0x8000 is treated as an initialized extent */
148 return (ext->ee_len > EXT_INIT_MAX_LEN);
149}

◆ ext4_ext_is_unwritten()

static int ext4_ext_is_unwritten ( struct ext4_extent ext)
inlinestatic

Definition at line 169 of file ext4_ext.h.

170{
171 /* Extent with ee_len of 0x8000 is treated as an initialized extent */
172 return (ext->ee_len > EXT_INIT_MAX_LEN);
173}

Referenced by ext4_can_extents_be_merged(), ext4_ext_binsearch(), ext4_ext_get_blocks(), ext4_ext_insert_extent(), ext4_ext_try_to_merge_right(), and ext4_force_split_extent_at().

◆ ext4_ext_mark_initialized()

static void ext4_ext_mark_initialized ( struct ext4_extent ext)
inlinestatic

Definition at line 158 of file ext4_ext.h.

159{
161}

Referenced by ext4_split_extent_at().

◆ ext4_ext_mark_uninitialized()

static void ext4_ext_mark_uninitialized ( struct ext4_extent ext)
inlinestatic

Definition at line 139 of file ext4_ext.h.

140{
141 /* We can not have an uninitialized extent of zero length! */
142 ext->ee_len |= EXT_INIT_MAX_LEN;
143}

◆ ext4_ext_mark_unwritten()

static void ext4_ext_mark_unwritten ( struct ext4_extent ext)
inlinestatic

Definition at line 163 of file ext4_ext.h.

164{
165 /* We can not have an unwritten extent of zero length! */
166 ext->ee_len |= EXT_INIT_MAX_LEN;
167}

Referenced by ext4_ext_get_blocks(), ext4_ext_insert_extent(), ext4_ext_try_to_merge_right(), and ext4_split_extent_at().

◆ ext4_ext_pblock()

static ext4_fsblk_t ext4_ext_pblock ( struct ext4_extent ex)
inlinestatic

◆ ext4_ext_store_pblock()

static void ext4_ext_store_pblock ( struct ext4_extent ex,
ext4_fsblk_t  pb 
)
inlinestatic

Definition at line 206 of file ext4_ext.h.

208{
209 ex->ee_start_lo = (uint32_t)(pb & 0xffffffff);
210 ex->ee_start_hi = (uint16_t)((pb >> 31) >> 1) & 0xffff;
211}
#define uint32_t
Definition: nsiface.idl:61
#define uint16_t
Definition: nsiface.idl:60

Referenced by ext4_ext_get_blocks(), ext4_ext_insert_extent(), ext4_ext_rm_leaf(), and ext4_split_extent_at().

◆ ext4_ext_tree_init()

int ext4_ext_tree_init ( void icb,
handle_t handle,
struct inode inode 
)

Definition at line 2319 of file ext4_extents.c.

2321{
2322 struct ext4_extent_header *eh;
2323
2324 eh = ext_inode_hdr(inode);
2325 eh->eh_depth = 0;
2326 eh->eh_entries = 0;
2330 return 0;
static struct ext4_extent_header * ext_inode_hdr(struct inode *inode)
Definition: ext4_ext.h:124
#define EXT4_EXT_MAGIC
Definition: ext4_ext.h:50
static int ext4_ext_space_root(struct inode *inode, int check)
Definition: ext4_extents.c:140
uint16_t eh_depth
Definition: ext4_ext.h:45
uint16_t eh_max
Definition: ext4_ext.h:44
uint16_t eh_magic
Definition: ext4_ext.h:42
uint16_t eh_entries
Definition: ext4_ext.h:43

Referenced by Ext2CreateInode(), Ext2DoExtentExpand(), and Ext2MapExtent().

◆ ext4_ext_truncate()

int ext4_ext_truncate ( void icb,
struct inode inode,
unsigned long  start 
)

Definition at line 2519 of file ext4_extents.c.

2521{
2522 int ret = ext4_ext_remove_space(icb, inode, start);
2523
2524 /* Save modifications on i_blocks field of the inode. */
2525 if (!ret)
2527
2528 return ret;
int ext4_ext_remove_space(void *icb, struct inode *inode, unsigned long start)
GLuint start
Definition: gl.h:1545
int ret

Referenced by Ext2TruncateExtent().

◆ ext4_idx_pblock()

static ext4_fsblk_t ext4_idx_pblock ( struct ext4_extent_idx ix)
inlinestatic

◆ ext4_idx_store_pblock()

static void ext4_idx_store_pblock ( struct ext4_extent_idx ix,
ext4_fsblk_t  pb 
)
inlinestatic

Definition at line 218 of file ext4_ext.h.

220{
221 ix->ei_leaf_lo = (uint32_t)(pb & 0xffffffff);
222 ix->ei_leaf_hi = (uint16_t)((pb >> 31) >> 1) & 0xffff;
223}

Referenced by ext4_ext_grow_indepth(), ext4_ext_insert_index(), and ext4_ext_split().

◆ ext_block_hdr()

◆ ext_depth()

◆ ext_inode_hdr()

static struct ext4_extent_header * ext_inode_hdr ( struct inode inode)
inlinestatic

Definition at line 124 of file ext4_ext.h.

125{
126 return get_ext4_header(inode);
127}
#define get_ext4_header(i)
Definition: ext4_ext.h:51

Referenced by ext4_ext_check_inode(), ext4_ext_grow_indepth(), ext4_ext_remove_space(), ext4_ext_tree_init(), ext4_find_extent(), and ext_depth().

◆ ext_to_block()

static uint64_t ext_to_block ( EXT4_EXTENT *  extent)
inlinestatic

Definition at line 230 of file ext4_ext.h.

231{
233
234 block = (uint64_t)extent->ee_start_lo;
235 block |= ((uint64_t) extent->ee_start_hi << 31) << 1;
236
237 return block;
238}
UINT64 uint64_t
Definition: types.h:77
#define uint64_t
Definition: nsiface.idl:62

◆ find_ext4_extent_tail()

static struct ext4_extent_tail * find_ext4_extent_tail ( struct ext4_extent_header eh)
inlinestatic

Definition at line 58 of file ext4_ext.h.

59{
60 return (struct ext4_extent_tail *)(((char *)eh) +
62}
#define EXT4_EXTENT_TAIL_OFFSET(hdr)
Definition: ext4_ext.h:53

Referenced by __ext4_ext_check(), and ext4_extent_block_csum_set().

◆ idx_to_block()

static uint64_t idx_to_block ( EXT4_EXTENT_IDX *  idx)
inlinestatic

Definition at line 240 of file ext4_ext.h.

241{
243
244 block = (uint64_t)idx->ei_leaf_lo;
245 block |= ((uint64_t) idx->ei_leaf_hi << 31) << 1;
246
247 return block;
248}
unsigned int idx
Definition: utils.c:41

Variable Documentation

◆ __attribute__

◆ ee_block

◆ ee_len

◆ ee_start_hi

uint16_t ee_start_hi

Definition at line 2 of file ext4_ext.h.

◆ ee_start_lo

uint32_t ee_start_lo

Definition at line 3 of file ext4_ext.h.

◆ eh_depth

uint16_t eh_depth

Definition at line 3 of file ext4_ext.h.

◆ eh_entries

uint16_t eh_entries

Definition at line 1 of file ext4_ext.h.

◆ eh_generation

uint32_t eh_generation

Definition at line 4 of file ext4_ext.h.

◆ eh_magic

uint16_t eh_magic

Definition at line 0 of file ext4_ext.h.

◆ eh_max

uint16_t eh_max

Definition at line 2 of file ext4_ext.h.

◆ ei_block

◆ ei_leaf_hi

uint16_t ei_leaf_hi

Definition at line 3 of file ext4_ext.h.

◆ ei_leaf_lo

uint32_t ei_leaf_lo

Definition at line 1 of file ext4_ext.h.

◆ ei_unused

uint16_t ei_unused

Definition at line 4 of file ext4_ext.h.