Changeset 4bfad34 in mainline
- Timestamp:
- 2017-05-11T22:07:09Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be39fc6
- Parents:
- 71fe4723
- Location:
- uspace/lib/ext4
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/include/ext4/filesystem.h
r71fe4723 r4bfad34 36 36 37 37 #include <block.h> 38 #include "ext4/fstypes.h" 38 39 #include "ext4/types.h" 39 40 40 extern int ext4_filesystem_init(ext4_filesystem_t *, service_id_t,41 enum cache_mode);41 extern int ext4_filesystem_init(ext4_filesystem_t *, ext4fs_instance_t *, 42 service_id_t, enum cache_mode, aoff64_t *); 42 43 extern int ext4_filesystem_fini(ext4_filesystem_t *); 43 extern int ext4_filesystem_check_features(ext4_filesystem_t *, bool *);44 44 extern uint32_t ext4_filesystem_blockaddr2_index_in_group(ext4_superblock_t *, 45 45 uint32_t); -
uspace/lib/ext4/include/ext4/ops.h
r71fe4723 r4bfad34 35 35 36 36 #include <libfs.h> 37 #include "ext4/fstypes.h" 37 38 38 39 extern vfs_out_ops_t ext4fs_ops; … … 42 43 extern int ext4fs_global_fini(void); 43 44 45 extern int ext4fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t); 46 extern int ext4fs_node_put(fs_node_t *); 47 44 48 45 49 #endif -
uspace/lib/ext4/src/balloc.c
r71fe4723 r4bfad34 31 31 */ 32 32 /** 33 * @file libext4_balloc.c33 * @file balloc.c 34 34 * @brief Physical block allocator. 35 35 */ -
uspace/lib/ext4/src/bitmap.c
r71fe4723 r4bfad34 31 31 */ 32 32 /** 33 * @file libext4_bitmap.c33 * @file bitmap.c 34 34 * @brief Ext4 bitmap operations. 35 35 */ -
uspace/lib/ext4/src/block_group.c
r71fe4723 r4bfad34 32 32 */ 33 33 /** 34 * @file libext4_block_group.c34 * @file block_group.c 35 35 * @brief Ext4 block group structure operations. 36 36 */ -
uspace/lib/ext4/src/directory.c
r71fe4723 r4bfad34 32 32 */ 33 33 /** 34 * @file libext4_directory.c34 * @file directory.c 35 35 * @brief Ext4 directory structure operations. 36 36 */ -
uspace/lib/ext4/src/directory_index.c
r71fe4723 r4bfad34 31 31 */ 32 32 /** 33 * @file libext4_directory_index.c33 * @file directory_index.c 34 34 * @brief Ext4 directory index operations. 35 35 */ -
uspace/lib/ext4/src/extent.c
r71fe4723 r4bfad34 31 31 */ 32 32 /** 33 * @file libext4_extent.c33 * @file extent.c 34 34 * @brief Ext4 extent structures operations. 35 35 */ -
uspace/lib/ext4/src/filesystem.c
r71fe4723 r4bfad34 32 32 */ 33 33 /** 34 * @file libext4_filesystem.c34 * @file filesystem.c 35 35 * @brief More complex filesystem operations. 36 36 */ … … 42 42 #include <crypto.h> 43 43 #include <ipc/vfs.h> 44 #include <libfs.h> 44 45 #include <stdlib.h> 45 46 #include "ext4/balloc.h" … … 50 51 #include "ext4/ialloc.h" 51 52 #include "ext4/inode.h" 53 #include "ext4/ops.h" 52 54 #include "ext4/superblock.h" 55 56 static int ext4_filesystem_check_features(ext4_filesystem_t *, bool *); 53 57 54 58 /** Initialize filesystem and read all needed data. … … 56 60 * @param fs Filesystem instance to be initialized 57 61 * @param service_id Identifier if device with the filesystem 58 * 59 * @return Error code 60 * 61 */ 62 int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id, 63 enum cache_mode cmode) 62 * @param cmode Cache mode 63 * @param read_only Place to store read only flag 64 * @param index Output value - index of root node 65 * @param size Output value - size of root node 66 * @param lnkcnt Output value - link count of root node 67 * 68 * @return Error code 69 * 70 */ 71 int ext4_filesystem_init(ext4_filesystem_t *fs, ext4fs_instance_t *inst, 72 service_id_t service_id, enum cache_mode cmode, aoff64_t *size) 64 73 { 65 74 int rc; … … 118 127 goto err_2; 119 128 129 /* Check flags */ 130 bool read_only; 131 rc = ext4_filesystem_check_features(fs, &read_only); 132 if (rc != EOK) 133 goto err_2; 134 135 /* Read root node */ 136 fs_node_t *root_node; 137 rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX); 138 if (rc != EOK) 139 goto err_2; 140 120 141 /* Mark system as mounted */ 121 142 ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS); 122 143 rc = ext4_superblock_write_direct(fs->device, fs->superblock); 123 144 if (rc != EOK) 124 goto err_ 2;145 goto err_3; 125 146 126 147 uint16_t mnt_count = ext4_superblock_get_mount_count(fs->superblock); 127 148 ext4_superblock_set_mount_count(fs->superblock, mnt_count + 1); 128 149 150 ext4fs_node_t *enode = EXT4FS_NODE(root_node); 151 152 *size = ext4_inode_get_size(fs->superblock, enode->inode_ref->inode); 153 154 ext4fs_node_put(root_node); 129 155 return EOK; 130 156 err_3: 157 ext4fs_node_put(root_node); 131 158 err_2: 132 159 block_cache_fini(fs->device); … … 169 196 * 170 197 * @param fs Filesystem to be checked 171 * @param read_only Flag if filesystem should be mounted only for reading 172 * 173 * @return Error code 174 * 175 */ 176 int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *read_only) 198 * @param read_only Place to write flag saying whether filesystem 199 * should be mounted only for reading 200 * 201 * @return Error code 202 * 203 */ 204 static int ext4_filesystem_check_features(ext4_filesystem_t *fs, 205 bool *read_only) 177 206 { 178 207 /* Feature flags are present only in higher revisions */ -
uspace/lib/ext4/src/hash.c
r71fe4723 r4bfad34 31 31 */ 32 32 /** 33 * @file libext4_hash.c33 * @file hash.c 34 34 * @brief Hashing algorithms for ext4 HTree. 35 35 */ -
uspace/lib/ext4/src/ialloc.c
r71fe4723 r4bfad34 31 31 */ 32 32 /** 33 * @file libext4_ialloc.c33 * @file ialloc.c 34 34 * @brief I-node (de)allocation operations. 35 35 */ -
uspace/lib/ext4/src/inode.c
r71fe4723 r4bfad34 32 32 */ 33 33 /** 34 * @file libext4_inode.c34 * @file inode.c 35 35 * @brief Ext4 i-node structure operations. 36 36 */ -
uspace/lib/ext4/src/ops.c
r71fe4723 r4bfad34 32 32 */ 33 33 /** 34 * @file ext4fs_ops.c34 * @file ops.c 35 35 * @brief Operations for ext4 filesystem. 36 36 */ … … 46 46 #include <ipc/loc.h> 47 47 #include "ext4/ops.h" 48 //#include "../../vfs/vfs.h" 49 50 #define EXT4FS_NODE(node) \ 51 ((node) ? (ext4fs_node_t *) (node)->data : NULL) 52 53 /** 54 * Type for holding an instance of mounted partition. 55 */ 56 typedef struct ext4fs_instance { 57 link_t link; 58 service_id_t service_id; 59 ext4_filesystem_t *filesystem; 60 unsigned int open_nodes_count; 61 } ext4fs_instance_t; 62 63 /** 64 * Type for wrapping common fs_node and add some useful pointers. 65 */ 66 typedef struct ext4fs_node { 67 ext4fs_instance_t *instance; 68 ext4_inode_ref_t *inode_ref; 69 fs_node_t *fs_node; 70 ht_link_t link; 71 unsigned int references; 72 } ext4fs_node_t; 48 #include "ext4/fstypes.h" 73 49 74 50 /* Forward declarations of auxiliary functions */ … … 80 56 static bool ext4fs_is_dots(const uint8_t *, size_t); 81 57 static int ext4fs_instance_get(service_id_t, ext4fs_instance_t **); 82 static int ext4fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t);83 static int ext4fs_node_put_core(ext4fs_node_t *);84 58 85 59 /* Forward declarations of ext4 libfs operations. */ … … 89 63 static int ext4fs_node_get(fs_node_t **, service_id_t, fs_index_t); 90 64 static int ext4fs_node_open(fs_node_t *); 91 staticint ext4fs_node_put(fs_node_t *);65 int ext4fs_node_put(fs_node_t *); 92 66 static int ext4fs_create_node(fs_node_t **, service_id_t, int); 93 67 static int ext4fs_destroy_node(fs_node_t *); … … 373 347 * 374 348 */ 375 int ext4fs_node_put_core(ext4fs_node_t *enode)349 static int ext4fs_node_put_core(ext4fs_node_t *enode) 376 350 { 377 351 hash_table_remove_item(&open_nodes, &enode->link); … … 966 940 cmode = CACHE_MODE_WB; 967 941 968 /* Initialize the filesystem */969 int rc = ext4_filesystem_init(fs, service_id, cmode);970 if (rc != EOK) {971 free(fs);972 free(inst);973 return rc;974 }975 976 /* Check flags */977 bool read_only;978 rc = ext4_filesystem_check_features(fs, &read_only);979 if (rc != EOK) {980 ext4_filesystem_fini(fs);981 free(fs);982 free(inst);983 return rc;984 }985 986 942 /* Initialize instance */ 987 943 link_initialize(&inst->link); … … 990 946 inst->open_nodes_count = 0; 991 947 992 /* Read root node */ 993 fs_node_t *root_node; 994 rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX); 995 if (rc != EOK) { 996 ext4_filesystem_fini(fs); 948 /* Initialize the filesystem */ 949 aoff64_t rnsize; 950 int rc = ext4_filesystem_init(fs, inst, service_id, cmode, &rnsize); 951 if (rc != EOK) { 997 952 free(fs); 998 953 free(inst); … … 1005 960 fibril_mutex_unlock(&instance_list_mutex); 1006 961 1007 ext4fs_node_t *enode = EXT4FS_NODE(root_node);1008 1009 962 *index = EXT4_INODE_ROOT_INDEX; 1010 *size = ext4_inode_get_size(fs->superblock, enode->inode_ref->inode);963 *size = rnsize; 1011 964 *lnkcnt = 1; 1012 965 1013 return ext4fs_node_put(root_node);966 return EOK; 1014 967 } 1015 968 -
uspace/lib/ext4/src/superblock.c
r71fe4723 r4bfad34 33 33 34 34 /** 35 * @file libext4_superblock.c35 * @file superblock.c 36 36 * @brief Ext4 superblock operations. 37 37 */
Note:
See TracChangeset
for help on using the changeset viewer.