Changeset cde485d in mainline


Ignore:
Timestamp:
2008-06-06T20:23:02Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b7b6753
Parents:
f49b0ea
Message:

Initialize global FAT IDX structures when the FAT server starts and initialize
per-file system FAT IDX structures when a file system gets mounted.

Location:
uspace/srv/fs/fat
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat.c

    rf49b0ea rcde485d  
    5656                [IPC_METHOD_TO_VFS_OP(VFS_TRUNCATE)] = VFS_OP_NULL,
    5757                [IPC_METHOD_TO_VFS_OP(VFS_MOUNT)] = VFS_OP_NULL,
     58                [IPC_METHOD_TO_VFS_OP(VFS_MOUNTED)] = VFS_OP_DEFINED,
    5859                [IPC_METHOD_TO_VFS_OP(VFS_UNMOUNT)] = VFS_OP_NULL,
    5960        }
     
    9899                callid = async_get_call(&call);
    99100                switch  (IPC_GET_METHOD(call)) {
     101                case VFS_MOUNTED:
     102                        fat_mounted(callid, &call);
     103                        break;
     104                case VFS_MOUNT:
     105                        fat_mount(callid, &call);
     106                        break;
    100107                case VFS_LOOKUP:
    101108                        fat_lookup(callid, &call);
     
    111118{
    112119        int vfs_phone;
     120        int rc;
    113121
    114122        printf("FAT: HelenOS FAT file system server.\n");
     123
     124        rc = fat_idx_init();
     125        if (rc != EOK)
     126                goto err;
    115127
    116128        vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0);
     
    120132        }
    121133       
    122         int rc;
    123134        rc = fs_register(vfs_phone, &fat_reg, &fat_vfs_info, fat_connection);
    124135        if (rc != EOK) {
    125                 printf("Failed to register the FAT file system (%d)\n", rc);
    126                 return rc;
     136                fat_idx_fini();
     137                goto err;
    127138        }
    128139       
     
    133144        /* not reached */
    134145        return 0;
     146
     147err:
     148        printf("Failed to register the FAT file system (%d)\n", rc);
     149        return rc;
    135150}
    136151
  • uspace/srv/fs/fat/fat.h

    rf49b0ea rcde485d  
    218218extern fs_reg_t fat_reg;
    219219
     220extern void fat_mounted(ipc_callid_t, ipc_call_t *);
     221extern void fat_mount(ipc_callid_t, ipc_call_t *);
    220222extern void fat_lookup(ipc_callid_t, ipc_call_t *);
    221223
    222224extern fat_idx_t *fat_idx_get_by_pos(dev_handle_t, fat_cluster_t, unsigned);
    223225extern fat_idx_t *fat_idx_get_by_index(dev_handle_t, fs_index_t);
     226
     227extern int fat_idx_init(void);
     228extern void fat_idx_fini(void);
     229extern int fat_idx_init_by_dev_handle(dev_handle_t);
     230extern void fat_idx_fini_by_dev_handle(dev_handle_t);
    224231
    225232#endif
  • uspace/srv/fs/fat/fat_idx.c

    rf49b0ea rcde485d  
    7474/** List of unused structures. */
    7575static LIST_INITIALIZE(unused_head);
     76
     77static void unused_initialize(unused_t *u, dev_handle_t dev_handle)
     78{
     79        link_initialize(&u->link);
     80        u->dev_handle = dev_handle;
     81        u->next = 0;
     82        u->remaining = ((uint64_t)((fs_index_t)-1)) + 1;
     83        list_initialize(&u->freed_head);
     84}
    7685
    7786/** Futex protecting the up_hash and ui_hash. */
     
    402411}
    403412
     413int fat_idx_init(void)
     414{
     415        if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops))
     416                return ENOMEM;
     417        if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) {
     418                hash_table_destroy(&up_hash);
     419                return ENOMEM;
     420        }
     421        return EOK;
     422}
     423
     424void fat_idx_fini(void)
     425{
     426        /* We assume the hash tables are empty. */
     427        hash_table_destroy(&up_hash);
     428        hash_table_destroy(&ui_hash);
     429}
     430
     431int fat_idx_init_by_dev_handle(dev_handle_t dev_handle)
     432{
     433        unused_t *u = (unused_t *) malloc(sizeof(unused_t));
     434        if (!u)
     435                return ENOMEM;
     436        unused_initialize(u, dev_handle);
     437        futex_down(&unused_futex);
     438        list_append(&u->link, &unused_head);
     439        futex_up(&unused_futex);
     440        return EOK;
     441}
     442
     443void fat_idx_fini_by_dev_handle(dev_handle_t dev_handle)
     444{
     445        unused_t *u;
     446        link_t *l;
     447
     448        futex_down(&unused_futex);
     449        for (l = unused_head.next; l != &unused_head; l = l->next) {
     450                u = list_get_instance(l, unused_t, link);
     451                if (u->dev_handle == dev_handle)
     452                        goto hit;
     453        }
     454        futex_up(&unused_futex);
     455
     456        assert(false);  /* should not happen */
     457
     458hit:
     459        list_remove(&u->link);
     460        futex_up(&unused_futex);
     461
     462        while (!list_empty(&u->freed_head)) {
     463                freed_t *f;
     464                f = list_get_instance(u->freed_head.next, freed_t, link);
     465                list_remove(&f->link);
     466                free(f);
     467        }
     468        free(u);
     469}
     470
     471/**
     472 * @}
     473 */
  • uspace/srv/fs/fat/fat_ops.c

    rf49b0ea rcde485d  
    559559};
    560560
     561void fat_mounted(ipc_callid_t rid, ipc_call_t *request)
     562{
     563        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     564        int rc;
     565
     566        rc = fat_idx_init_by_dev_handle(dev_handle);
     567        if (rc != EOK) {
     568                ipc_answer_0(rid, rc);
     569                return;
     570        }
     571
     572        ipc_answer_0(rid, EOK);
     573}
     574
     575void fat_mount(ipc_callid_t rid, ipc_call_t *request)
     576{
     577        ipc_answer_0(rid, ENOTSUP);
     578}
     579
    561580void fat_lookup(ipc_callid_t rid, ipc_call_t *request)
    562581{
Note: See TracChangeset for help on using the changeset viewer.