Changeset e1e3b26 in mainline


Ignore:
Timestamp:
2008-04-10T05:08:30Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e22632a9
Parents:
44882c8
Message:

Commit progress on the FAT file system server implementation.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libfs/libfs.c

    r44882c8 re1e3b26  
    198198                                else
    199199                                        nodep = ops->node_get(dev_handle,
    200                                             index);
     200                                            index, ops->index_get(cur));
    201201                                if (nodep) {
    202202                                        if (!ops->link(cur, nodep, component)) {
     
    261261                                nodep = ops->create(lflag);
    262262                        else
    263                                 nodep = ops->node_get(dev_handle, index);
     263                                nodep = ops->node_get(dev_handle, index,
     264                                    ops->index_get(cur));
    264265                        if (nodep) {
    265266                                if (!ops->link(cur, nodep, component)) {
  • uspace/lib/libfs/libfs.h

    r44882c8 re1e3b26  
    4444typedef struct {
    4545        void * (* match)(void *, const char *);
    46         void * (* node_get)(dev_handle_t, fs_index_t);
     46        void * (* node_get)(dev_handle_t, fs_index_t, fs_index_t);
    4747        void * (* create)(int);
    4848        void (* destroy)(void *);
     
    6767extern int fs_register(int, fs_reg_t *, vfs_info_t *, async_client_conn_t);
    6868
    69 extern int block_read(int, unsigned long, void *);
    70 extern int block_write(int, unsigned long, void *);
    71 
    72 extern void node_add_mp(int, unsigned long);
    73 extern void node_del_mp(int, unsigned long);
    74 extern bool node_is_mp(int, unsigned long);
    75 
    7669extern void libfs_lookup(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
    7770
  • uspace/srv/fs/fat/fat.h

    r44882c8 re1e3b26  
    5959        uint16_t        headcnt;        /**< Number of heads. */
    6060        uint32_t        hidden_sec;     /**< Hidden sectors. */
    61         uint32_t        totseci32;      /**< Total sectors. 32-bit version. */
     61        uint32_t        totsec32;       /**< Total sectors. 32-bit version. */
    6262
    6363        union {
     
    141141
    142142typedef enum {
     143        FAT_INVALID,
    143144        FAT_DIRECTORY,
    144145        FAT_FILE
     
    150151        /** VFS index is the node's first allocated cluster. */
    151152        fs_index_t              index;
     153        /** VFS index of the parent node. */
     154        fs_index_t              pindex;
    152155        dev_handle_t            dev_handle;
    153156        /** FAT in-core node hash table link. */
    154157        link_t                  fin_link;
     158        /** FAT in-core node free list link. */
     159        link_t                  ffn_link;
    155160        size_t                  size;
    156161        unsigned                lnkcnt;
     162        unsigned                refcnt;
     163        bool                    dirty;
    157164} fat_node_t;
    158165
  • uspace/srv/fs/fat/fat_ops.c

    r44882c8 re1e3b26  
    4444#include <string.h>
    4545#include <byteorder.h>
     46#include <libadt/hash_table.h>
     47#include <libadt/list.h>
     48#include <assert.h>
     49
     50/** Hash table of FAT in-core nodes. */
     51hash_table_t fin_hash;
     52
     53/** List of free FAT in-core nodes. */
     54link_t ffn_head;
    4655
    4756#define FAT_NAME_LEN            8
     
    93102}
    94103
    95 static block_t *fat_block_get(fat_node_t *node, off_t offset) {
     104static block_t *fat_block_get(dev_handle_t dev_handle, fs_index_t index,
     105    off_t offset) {
    96106        return NULL;    /* TODO */
    97107}
     
    102112}
    103113
    104 static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index)
    105 {
    106         return NULL;    /* TODO */
     114static void fat_node_initialize(fat_node_t *node)
     115{
     116        node->type = 0;
     117        node->index = 0;
     118        node->pindex = 0;
     119        node->dev_handle = 0;
     120        link_initialize(&node->fin_link);
     121        link_initialize(&node->ffn_link);
     122        node->size = 0;
     123        node->lnkcnt = 0;
     124        node->refcnt = 0;
     125        node->dirty = false;
     126}
     127
     128static void fat_sync_node(fat_node_t *node)
     129{
     130        /* TODO */
     131}
     132
     133static void *
     134fat_node_get(dev_handle_t dev_handle, fs_index_t index, fs_index_t pindex)
     135{
     136        link_t *lnk;
     137        fat_node_t *node = NULL;
     138        block_t *bb;
     139        block_t *b;
     140        fat_dentry_t *d;
     141        unsigned bps;           /* bytes per sector */
     142        unsigned dps;           /* dentries per sector */
     143
     144        unsigned long key[] = {
     145                dev_handle,
     146                index
     147        };
     148
     149        lnk = hash_table_find(&fin_hash, key);
     150        if (lnk) {
     151                /*
     152                 * The in-core node was found in the hash table.
     153                 */
     154                node = hash_table_get_instance(lnk, fat_node_t, fin_link);
     155                if (!node->refcnt++)
     156                        list_remove(&node->ffn_link);
     157                return (void *) node;   
     158        }
     159
     160        if (!list_empty(&ffn_head)) {
     161                /*
     162                 * We are going to reuse a node from the free list.
     163                 */
     164                lnk = ffn_head.next;
     165                list_remove(lnk);
     166                node = list_get_instance(lnk, fat_node_t, ffn_link);
     167                assert(!node->refcnt);
     168                if (node->dirty)
     169                        fat_sync_node(node);
     170        } else {
     171                /*
     172                 * We need to allocate a new node.
     173                 */
     174                node = malloc(sizeof(fat_node_t));
     175                if (!node)
     176                        return NULL;
     177        }
     178        fat_node_initialize(node);
     179
     180        if (!pindex) {
     181               
     182        } else {
     183        }
     184
    107185}
    108186
     
    131209                unsigned dentries;
    132210               
    133                 b = fat_block_get(parentp, i);
     211                b = fat_block_get(parentp->dev_handle, parentp->index, i);
    134212                if (!b)
    135213                        return NULL;
     
    165243                                /* hit */
    166244                                void *node = fat_node_get(parentp->dev_handle,
    167                                     (fs_index_t)uint16_t_le2host(d->firstc));
     245                                    (fs_index_t)uint16_t_le2host(d->firstc),
     246                                    parentp->index);
    168247                                block_put(b);
    169248                                return node;
     
    174253
    175254        return NULL;
     255}
     256
     257static fs_index_t fat_index_get(void *node)
     258{
     259        fat_node_t *fnodep = (fat_node_t *)node;
     260        if (!fnodep)
     261                return 0;
     262        return fnodep->index;
     263}
     264
     265static size_t fat_size_get(void *node)
     266{
     267        return ((fat_node_t *)node)->size;
     268}
     269
     270static unsigned fat_lnkcnt_get(void *node)
     271{
     272        return ((fat_node_t *)node)->lnkcnt;
     273}
     274
     275static bool fat_is_directory(void *node)
     276{
     277        return ((fat_node_t *)node)->type == FAT_DIRECTORY;
     278}
     279
     280static bool fat_is_file(void *node)
     281{
     282        return ((fat_node_t *)node)->type == FAT_FILE;
    176283}
    177284
     
    184291        .link = NULL,
    185292        .unlink = NULL,
    186         .index_get = NULL,
    187         .size_get = NULL,
    188         .lnkcnt_get = NULL,
     293        .index_get = fat_index_get,
     294        .size_get = fat_size_get,
     295        .lnkcnt_get = fat_lnkcnt_get,
    189296        .has_children = NULL,
    190297        .root_get = NULL,
    191298        .plb_get_char = NULL,
    192         .is_directory = NULL,
    193         .is_file = NULL
     299        .is_directory = fat_is_directory,
     300        .is_file = fat_is_file
    194301};
    195302
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r44882c8 re1e3b26  
    7171/* Forward declarations of static functions. */
    7272static void *tmpfs_match(void *, const char *);
    73 static void *tmpfs_node_get(dev_handle_t, fs_index_t);
     73static void *tmpfs_node_get(dev_handle_t, fs_index_t, fs_index_t);
    7474static void *tmpfs_create_node(int);
    7575static bool tmpfs_link_node(void *, void *, const char *);
     
    267267
    268268void *
    269 tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
     269tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index, fs_index_t pindex)
    270270{
    271271        unsigned long key = index;
Note: See TracChangeset for help on using the changeset viewer.