Lines Matching refs:fs
39 void error_behavior(struct ext2_data *fs, const char *msg) in error_behavior() argument
49 switch (fs->sblock.s_errors) { in error_behavior()
55 fs->flags |= EXT2_DATA_FLAGS_RO; in error_behavior()
89 struct ext2_block *ext2_get_block(struct ext2_data *fs, uint32_t block) in ext2_get_block() argument
99 ret = fs->backend_ops->read_block(fs, b->data, block); in ext2_get_block()
108 struct ext2_block *ext2_get_empty_block(struct ext2_data *fs) in ext2_get_empty_block() argument
117 memset(b->data, 0, fs->block_size); in ext2_get_empty_block()
121 int ext2_write_block(struct ext2_data *fs, struct ext2_block *b) in ext2_write_block() argument
129 ret = fs->backend_ops->write_block(fs, b->data, b->num); in ext2_write_block()
148 void ext2_init_blocks_slab(struct ext2_data *fs) in ext2_init_blocks_slab() argument
158 k_mem_slab_init(&ext2_block_memory_slab, __ext2_block_memory_buffer, fs->block_size, in ext2_init_blocks_slab()
162 int ext2_assign_block_num(struct ext2_data *fs, struct ext2_block *b) in ext2_assign_block_num() argument
171 new_block = ext2_alloc_block(fs); in ext2_assign_block_num()
191 struct ext2_data *fs = &__fs; in ext2_init_storage() local
194 *fsp = fs; in ext2_init_storage()
195 fs->open_inodes = 0; in ext2_init_storage()
196 fs->flags = 0; in ext2_init_storage()
197 fs->bgroup.num = -1; in ext2_init_storage()
199 ret = ext2_init_disk_access_backend(fs, storage_dev, flags); in ext2_init_storage()
204 dev_size = fs->backend_ops->get_device_size(fs); in ext2_init_storage()
210 write_size = fs->backend_ops->get_write_size(fs); in ext2_init_storage()
225 fs->device_size = dev_size; in ext2_init_storage()
226 fs->write_size = write_size; in ext2_init_storage()
308 int ext2_init_fs(struct ext2_data *fs) in ext2_init_fs() argument
313 ret = ext2_fetch_superblock(fs); in ext2_init_fs()
318 if (!(fs->flags & EXT2_DATA_FLAGS_RO)) { in ext2_init_fs()
320 fs->sblock.s_state = EXT2_ERROR_FS; in ext2_init_fs()
321 fs->sblock.s_mnt_count += 1; in ext2_init_fs()
322 ret = ext2_commit_superblock(fs); in ext2_init_fs()
328 ret = ext2_fetch_block_group(fs, 0); in ext2_init_fs()
332 ret = ext2_fetch_bg_ibitmap(&fs->bgroup); in ext2_init_fs()
336 ret = ext2_fetch_bg_bbitmap(&fs->bgroup); in ext2_init_fs()
343 struct ext2_superblock *sb = &fs->sblock; in ext2_init_fs()
346 set = ext2_bitmap_count_set(BGROUP_BLOCK_BITMAP(&fs->bgroup), fs_blocks); in ext2_init_fs()
349 error_behavior(fs, "Wrong number of used blocks in superblock and bitmap"); in ext2_init_fs()
353 set = ext2_bitmap_count_set(BGROUP_INODE_BITMAP(&fs->bgroup), sb->s_inodes_count); in ext2_init_fs()
356 error_behavior(fs, "Wrong number of used inodes in superblock and bitmap"); in ext2_init_fs()
362 int ext2_close_fs(struct ext2_data *fs) in ext2_close_fs() argument
367 for (int32_t i = 0; i < fs->open_inodes; ++i) { in ext2_close_fs()
368 if (fs->inode_pool[i] != NULL) { in ext2_close_fs()
369 ext2_inode_drop(fs->inode_pool[i]); in ext2_close_fs()
374 if (!(fs->flags & (EXT2_DATA_FLAGS_RO | EXT2_DATA_FLAGS_ERR))) { in ext2_close_fs()
375 fs->sblock.s_state = EXT2_VALID_FS; in ext2_close_fs()
376 ret = ext2_commit_superblock(fs); in ext2_close_fs()
383 ext2_drop_block(fs->bgroup.inode_table); in ext2_close_fs()
384 ext2_drop_block(fs->bgroup.inode_bitmap); in ext2_close_fs()
385 ext2_drop_block(fs->bgroup.block_bitmap); in ext2_close_fs()
387 if (fs->backend_ops->sync(fs) < 0) { in ext2_close_fs()
393 int ext2_close_struct(struct ext2_data *fs) in ext2_close_struct() argument
395 memset(fs, 0, sizeof(struct ext2_data)); in ext2_close_struct()
408 int ext2_lookup_inode(struct ext2_data *fs, struct ext2_lookup_args *args) in ext2_lookup_inode() argument
417 rc = ext2_inode_get(fs, EXT2_ROOT_INODE, &cur_dir); in ext2_lookup_inode()
465 rc = ext2_inode_get(fs, ino, &next); in ext2_lookup_inode()
498 rc = ext2_inode_get(fs, ino, &next); in ext2_lookup_inode()
568 struct ext2_data *fs = inode->i_fs; in find_dir_entry() local
572 block = offset / fs->block_size; in find_dir_entry()
573 block_off = offset % fs->block_size; in find_dir_entry()
765 static int write_one_block(struct ext2_data *fs, struct ext2_block *b) in write_one_block() argument
770 ret = ext2_assign_block_num(fs, b); in write_one_block()
776 ret = ext2_write_block(fs, b); in write_one_block()
783 struct ext2_data *fs = inode->i_fs; in ext2_inode_sync() local
789 ret = write_one_block(fs, inode->blocks[i]); in ext2_inode_sync()
793 ret = fs->backend_ops->sync(fs); in ext2_inode_sync()
809 struct ext2_data *fs = dir->f_inode->i_fs; in ext2_get_direntry() local
812 uint32_t block = dir->f_off / fs->block_size; in ext2_get_direntry()
813 uint32_t block_off = dir->f_off % fs->block_size; in ext2_get_direntry()
852 rc = ext2_inode_get(fs, de->de_inode, &inode); in ext2_get_direntry()
874 static int ext2_create_inode(struct ext2_data *fs, struct ext2_inode *parent, in ext2_create_inode() argument
878 int32_t ino = ext2_alloc_inode(fs); in ext2_create_inode()
885 inode->i_fs = fs; in ext2_create_inode()
897 fs->bgroup.bg_used_dirs_count += 1; in ext2_create_inode()
898 rc = ext2_commit_bg(fs); in ext2_create_inode()
1026 struct ext2_data *fs = parent->i_fs; in ext2_create_file() local
1028 rc = ext2_create_inode(fs, args->inode, new_inode, FS_DIR_ENTRY_FILE); in ext2_create_file()
1060 struct ext2_data *fs = parent->i_fs; in ext2_create_dir() local
1063 rc = ext2_create_inode(fs, args->inode, new_inode, FS_DIR_ENTRY_DIR); in ext2_create_dir()
1441 int ext2_inode_get(struct ext2_data *fs, uint32_t ino, struct ext2_inode **ret) in ext2_inode_get() argument
1446 for (int i = 0; i < fs->open_inodes; ++i) { in ext2_inode_get()
1447 inode = fs->inode_pool[i]; in ext2_inode_get()
1456 if (fs->open_inodes >= MAX_INODES) { in ext2_inode_get()
1468 int rc2 = ext2_fetch_inode(fs, ino, inode); in ext2_inode_get()
1476 fs->inode_pool[fs->open_inodes] = inode; in ext2_inode_get()
1477 fs->open_inodes++; in ext2_inode_get()
1479 inode->i_fs = fs; in ext2_inode_get()
1491 struct ext2_data *fs = inode->i_fs; in ext2_inode_drop() local
1493 if (fs->open_inodes <= 0) { in ext2_inode_drop()
1506 while (offset < MAX_INODES && fs->inode_pool[offset] != inode) { in ext2_inode_drop()
1531 uint32_t last = fs->open_inodes - 1; in ext2_inode_drop()
1533 fs->inode_pool[offset] = fs->inode_pool[last]; in ext2_inode_drop()
1534 fs->open_inodes--; in ext2_inode_drop()