Changeset 6c501f8 in mainline for uspace/srv/fs/ext4fs/ext4fs_ops.c
- Timestamp:
- 2011-09-30T20:00:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 00a8f1b
- Parents:
- 9875711
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/ext4fs/ext4fs_ops.c
r9875711 r6c501f8 37 37 38 38 #include <errno.h> 39 #include <fibril_synch.h> 40 #include <libext4.h> 39 41 #include <libfs.h> 42 #include <malloc.h> 40 43 #include <ipc/loc.h> 41 44 #include "ext4fs.h" 42 45 #include "../../vfs/vfs.h" 46 47 #define EXT4FS_NODE(node) ((node) ? (ext4fs_node_t *) (node)->data : NULL) 48 49 typedef struct ext4fs_instance { 50 link_t link; 51 service_id_t service_id; 52 ext4_filesystem_t *filesystem; 53 unsigned int open_nodes_count; 54 } ext4fs_instance_t; 55 56 typedef struct ext4fs_node { 57 ext4fs_instance_t *instance; 58 ext4_inode_ref_t *inode_ref; 59 fs_node_t *fs_node; 60 link_t link; 61 unsigned int references; 62 } ext4fs_node_t; 63 64 /* 65 * Forward declarations of auxiliary functions 66 */ 67 static int ext4fs_instance_get(service_id_t, ext4fs_instance_t **); 68 static int ext4fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t); 43 69 44 70 … … 63 89 static service_id_t ext4fs_service_get(fs_node_t *node); 64 90 91 /* 92 * Static variables 93 */ 94 static LIST_INITIALIZE(instance_list); 95 static FIBRIL_MUTEX_INITIALIZE(instance_list_mutex); 96 static FIBRIL_MUTEX_INITIALIZE(open_nodes_lock); 97 98 65 99 /** 66 100 * TODO comment … … 83 117 */ 84 118 119 int ext4fs_instance_get(service_id_t service_id, ext4fs_instance_t **inst) 120 { 121 ext4fs_instance_t *tmp; 122 123 fibril_mutex_lock(&instance_list_mutex); 124 125 if (list_empty(&instance_list)) { 126 fibril_mutex_unlock(&instance_list_mutex); 127 return EINVAL; 128 } 129 130 list_foreach(instance_list, link) { 131 tmp = list_get_instance(link, ext4fs_instance_t, link); 132 133 if (tmp->service_id == service_id) { 134 *inst = tmp; 135 fibril_mutex_unlock(&instance_list_mutex); 136 return EOK; 137 } 138 } 139 140 fibril_mutex_unlock(&instance_list_mutex); 141 return EINVAL; 142 } 143 85 144 int ext4fs_root_get(fs_node_t **rfn, service_id_t service_id) 86 145 { … … 99 158 // TODO 100 159 return 0; 160 } 161 162 int ext4fs_node_get_core(fs_node_t **rfn, ext4fs_instance_t *inst, 163 fs_index_t index) 164 { 165 // TODO 166 return EOK; 101 167 } 102 168 … … 210 276 fs_index_t *index, aoff64_t *size, unsigned *lnkcnt) 211 277 { 212 // TODO 278 279 int rc; 280 ext4_filesystem_t *fs; 281 ext4fs_instance_t *inst; 282 bool read_only; 283 284 /* Allocate libext4 filesystem structure */ 285 fs = (ext4_filesystem_t *) malloc(sizeof(ext4_filesystem_t)); 286 if (fs == NULL) { 287 return ENOMEM; 288 } 289 290 /* Allocate instance structure */ 291 inst = (ext4fs_instance_t *) malloc(sizeof(ext4fs_instance_t)); 292 if (inst == NULL) { 293 free(fs); 294 return ENOMEM; 295 } 296 297 /* Initialize the filesystem */ 298 rc = ext4_filesystem_init(fs, service_id); 299 if (rc != EOK) { 300 free(fs); 301 free(inst); 302 return rc; 303 } 304 305 /* Do some sanity checking */ 306 rc = ext4_filesystem_check_sanity(fs); 307 if (rc != EOK) { 308 ext4_filesystem_fini(fs); 309 free(fs); 310 free(inst); 311 return rc; 312 } 313 314 /* Check flags */ 315 rc = ext4_filesystem_check_flags(fs, &read_only); 316 if (rc != EOK) { 317 ext4_filesystem_fini(fs); 318 free(fs); 319 free(inst); 320 return rc; 321 } 322 323 /* Initialize instance */ 324 link_initialize(&inst->link); 325 inst->service_id = service_id; 326 inst->filesystem = fs; 327 inst->open_nodes_count = 0; 328 329 /* Read root node */ 330 fs_node_t *root_node; 331 rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX); 332 if (rc != EOK) { 333 ext4_filesystem_fini(fs); 334 free(fs); 335 free(inst); 336 return rc; 337 } 338 ext4fs_node_t *enode = EXT4FS_NODE(root_node); 339 340 /* Add instance to the list */ 341 fibril_mutex_lock(&instance_list_mutex); 342 list_append(&inst->link, &instance_list); 343 fibril_mutex_unlock(&instance_list_mutex); 344 345 *index = EXT4_INODE_ROOT_INDEX; 346 *size = 0; 347 *lnkcnt = ext4_inode_get_usage_count(enode->inode_ref->inode); 348 349 ext4fs_node_put(root_node); 350 213 351 return EOK; 214 352 } … … 216 354 static int ext4fs_unmounted(service_id_t service_id) 217 355 { 218 // TODO 356 357 int rc; 358 ext4fs_instance_t *inst; 359 360 rc = ext4fs_instance_get(service_id, &inst); 361 362 if (rc != EOK) { 363 return rc; 364 } 365 366 fibril_mutex_lock(&open_nodes_lock); 367 368 if (inst->open_nodes_count != 0) { 369 fibril_mutex_unlock(&open_nodes_lock); 370 return EBUSY; 371 } 372 373 /* Remove the instance from the list */ 374 fibril_mutex_lock(&instance_list_mutex); 375 list_remove(&inst->link); 376 fibril_mutex_unlock(&instance_list_mutex); 377 378 fibril_mutex_unlock(&open_nodes_lock); 379 380 ext4_filesystem_fini(inst->filesystem); 381 219 382 return EOK; 220 383 }
Note:
See TracChangeset
for help on using the changeset viewer.