Changeset 5973fd0 in mainline for uspace/srv/fs/tmpfs


Ignore:
Timestamp:
2008-01-18T23:45:16Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ae78b530
Parents:
62da45a
Message:

Finish implementation of readdir(). Functions from this family are implemented
via using file descriptors for directories. For example, readdir() is
implemented as read() from an open directory. Of course, FS implementations
must understand that they are asked to read a directory and behave accordingly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r62da45a r5973fd0  
    4646#include <string.h>
    4747#include <stdio.h>
     48#include <assert.h>
    4849#include <sys/types.h>
    4950#include <libadt/hash_table.h>
     
    308309        }
    309310
    310         size_t bytes = max(0, min(dentry->size - pos, len));
    311         (void) ipc_data_read_finalize(callid, dentry->data + pos, bytes);
     311        size_t bytes;
     312        if (dentry->type == TMPFS_FILE) {
     313                bytes = max(0, min(dentry->size - pos, len));
     314                (void) ipc_data_read_finalize(callid, dentry->data + pos,
     315                    bytes);
     316        } else {
     317                int i;
     318                tmpfs_dentry_t *cur = dentry->child;
     319               
     320                assert(dentry->type == TMPFS_DIRECTORY);
     321               
     322                /*
     323                 * Yes, we really use O(n) algorithm here.
     324                 * If it bothers someone, it could be fixed by introducing a
     325                 * hash table.
     326                 */
     327                for (i = 0, cur = dentry->child; i < pos && cur; i++,
     328                    cur = cur->sibling)
     329                        ;
     330
     331                if (!cur) {
     332                        ipc_answer_0(callid, ENOENT);
     333                        ipc_answer_1(rid, ENOENT, 0);
     334                        return;
     335                }
     336
     337                (void) ipc_data_read_finalize(callid, cur->name,
     338                    strlen(cur->name) + 1);
     339                bytes = 1;
     340        }
    312341
    313342        /*
Note: See TracChangeset for help on using the changeset viewer.