Changeset de5b708 in mainline
- Timestamp:
- 2017-05-12T17:15:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 395df52
- Parents:
- be39fc6
- Location:
- uspace/lib/ext4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/include/ext4/filesystem.h
rbe39fc6 rde5b708 39 39 #include "ext4/types.h" 40 40 41 extern int ext4_filesystem_ init(ext4_filesystem_t *, ext4_instance_t *,42 service_id_t, enum cache_mode, aoff64_t*);43 extern int ext4_filesystem_ fini(ext4_filesystem_t *);41 extern int ext4_filesystem_open(ext4_instance_t *, service_id_t, 42 enum cache_mode, aoff64_t *, ext4_filesystem_t **); 43 extern int ext4_filesystem_close(ext4_filesystem_t *); 44 44 extern uint32_t ext4_filesystem_blockaddr2_index_in_group(ext4_superblock_t *, 45 45 uint32_t); -
uspace/lib/ext4/src/filesystem.c
rbe39fc6 rde5b708 56 56 static int ext4_filesystem_check_features(ext4_filesystem_t *, bool *); 57 57 58 /** Initialize filesystem and read all needed data. 58 /** Initialize filesystem for opening. 59 * 60 * But do not mark mounted just yet. 59 61 * 60 62 * @param fs Filesystem instance to be initialized 61 63 * @param service_id Identifier if device with the filesystem 62 64 * @param cmode Cache mode 63 * @param read_only Place to store read only flag64 * @param index Output value - index of root node65 * @param size Output value - size of root node66 * @param lnkcnt Output value - link count of root node67 65 * 68 66 * @return Error code 69 67 * 70 68 */ 71 int ext4_filesystem_init(ext4_filesystem_t *fs, ext4_instance_t *inst,72 service_id_t service_id, enum cache_mode cmode, aoff64_t *size)69 static int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id, 70 enum cache_mode cmode) 73 71 { 74 72 int rc; … … 122 120 goto err_2; 123 121 } 124 122 125 123 rc = ext4_superblock_check_sanity(fs->superblock); 126 124 if (rc != EOK) … … 133 131 goto err_2; 134 132 135 /* Read root node */136 fs_node_t *root_node;137 rc = ext4_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX);138 if (rc != EOK)139 goto err_2;140 141 /* Mark system as mounted */142 ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS);143 rc = ext4_superblock_write_direct(fs->device, fs->superblock);144 if (rc != EOK)145 goto err_3;146 147 uint16_t mnt_count = ext4_superblock_get_mount_count(fs->superblock);148 ext4_superblock_set_mount_count(fs->superblock, mnt_count + 1);149 150 ext4_node_t *enode = EXT4_NODE(root_node);151 152 *size = ext4_inode_get_size(fs->superblock, enode->inode_ref->inode);153 154 ext4_node_put(root_node);155 133 return EOK; 156 err_3:157 ext4_node_put(root_node);158 134 err_2: 159 135 block_cache_fini(fs->device); … … 166 142 } 167 143 168 /** Destroy filesystem instance (used by unmount operation). 144 /** Finalize filesystem. 145 * 146 * @param fs Filesystem to be finalized 147 * 148 */ 149 static void ext4_filesystem_fini(ext4_filesystem_t *fs) 150 { 151 /* Release memory space for superblock */ 152 free(fs->superblock); 153 154 /* Finish work with block library */ 155 block_cache_fini(fs->device); 156 block_fini(fs->device); 157 } 158 159 /** Open filesystem and read all needed data. 160 * 161 * @param fs Filesystem to be initialized 162 * @param inst Instance 163 * @param service_id Identifier if device with the filesystem 164 * @param cmode Cache mode 165 * @param size Output value - size of root node 166 * 167 * @return Error code 168 * 169 */ 170 int ext4_filesystem_open(ext4_instance_t *inst, service_id_t service_id, 171 enum cache_mode cmode, aoff64_t *size, ext4_filesystem_t **rfs) 172 { 173 ext4_filesystem_t *fs = NULL; 174 fs_node_t *root_node = NULL; 175 int rc; 176 177 fs = calloc(1, sizeof(ext4_filesystem_t)); 178 if (fs == NULL) { 179 rc = ENOMEM; 180 goto error; 181 } 182 183 inst->filesystem = fs; 184 185 /* Initialize the file system for opening */ 186 rc = ext4_filesystem_init(fs, service_id, cmode); 187 if (rc != EOK) 188 goto error; 189 190 /* Read root node */ 191 rc = ext4_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX); 192 if (rc != EOK) 193 goto error; 194 195 /* Mark system as mounted */ 196 ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS); 197 rc = ext4_superblock_write_direct(fs->device, fs->superblock); 198 if (rc != EOK) 199 goto error; 200 201 uint16_t mnt_count = ext4_superblock_get_mount_count(fs->superblock); 202 ext4_superblock_set_mount_count(fs->superblock, mnt_count + 1); 203 204 ext4_node_t *enode = EXT4_NODE(root_node); 205 206 *size = ext4_inode_get_size(fs->superblock, enode->inode_ref->inode); 207 208 ext4_node_put(root_node); 209 *rfs = fs; 210 return EOK; 211 error: 212 if (root_node != NULL) 213 ext4_node_put(root_node); 214 215 if (fs != NULL) { 216 ext4_filesystem_fini(fs); 217 free(fs); 218 } 219 220 return rc; 221 } 222 223 /** Close filesystem. 169 224 * 170 225 * @param fs Filesystem to be destroyed 171 226 * 172 * @return Error code 173 * 174 */ 175 int ext4_filesystem_fini(ext4_filesystem_t *fs) 227 * @return EOK or negative error code. On error the state of the file 228 * system is unchanged. 229 * 230 */ 231 int ext4_filesystem_close(ext4_filesystem_t *fs) 176 232 { 177 233 /* Write the superblock to the device */ 178 234 ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_VALID_FS); 179 235 int rc = ext4_superblock_write_direct(fs->device, fs->superblock); 180 181 /* Release memory space for superblock */ 182 free(fs->superblock); 183 184 /* Finish work with block library */ 185 block_cache_fini(fs->device); 186 block_fini(fs->device); 187 188 return rc; 236 if (rc != EOK) 237 return rc; 238 239 ext4_filesystem_fini(fs); 240 return EOK; 189 241 } 190 242 -
uspace/lib/ext4/src/ops.c
rbe39fc6 rde5b708 928 928 fs_index_t *index, aoff64_t *size, unsigned *lnkcnt) 929 929 { 930 /* Allocate libext4 filesystem structure */ 931 ext4_filesystem_t *fs = (ext4_filesystem_t *) 932 malloc(sizeof(ext4_filesystem_t)); 933 if (fs == NULL) 934 return ENOMEM; 930 ext4_filesystem_t *fs; 935 931 936 932 /* Allocate instance structure */ 937 933 ext4_instance_t *inst = (ext4_instance_t *) 938 934 malloc(sizeof(ext4_instance_t)); 939 if (inst == NULL) { 940 free(fs); 935 if (inst == NULL) 941 936 return ENOMEM; 942 }943 937 944 938 enum cache_mode cmode; … … 951 945 link_initialize(&inst->link); 952 946 inst->service_id = service_id; 953 inst->filesystem = fs;954 947 inst->open_nodes_count = 0; 955 948 956 949 /* Initialize the filesystem */ 957 950 aoff64_t rnsize; 958 int rc = ext4_filesystem_init(fs, inst, service_id, cmode, &rnsize); 959 if (rc != EOK) { 960 free(fs); 951 int rc = ext4_filesystem_open(inst, service_id, cmode, &rnsize, &fs); 952 if (rc != EOK) { 961 953 free(inst); 962 954 return rc; … … 1005 997 fibril_mutex_unlock(&open_nodes_lock); 1006 998 1007 return ext4_filesystem_fini(inst->filesystem); 999 rc = ext4_filesystem_close(inst->filesystem); 1000 if (rc != EOK) { 1001 fibril_mutex_lock(&instance_list_mutex); 1002 list_append(&inst->link, &instance_list); 1003 fibril_mutex_unlock(&instance_list_mutex); 1004 } 1005 1006 free(inst); 1007 return EOK; 1008 1008 } 1009 1009
Note:
See TracChangeset
for help on using the changeset viewer.