Changeset de5b708 in mainline for uspace/lib/ext4/src/filesystem.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.