Changeset d6084ef in mainline


Ignore:
Timestamp:
2008-03-02T15:05:26Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dadcec1
Parents:
9bb85f3
Message:

Make VFS canonify path names on lookup.

Location:
uspace/srv/vfs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs.h

    r9bb85f3 rd6084ef  
    251251extern int fs_name_to_handle(char *, bool);
    252252
    253 extern int vfs_lookup_internal(char *, size_t, int, vfs_lookup_res_t *,
    254     vfs_pair_t *);
     253extern int vfs_lookup_internal(char *, int, vfs_lookup_res_t *, vfs_pair_t *);
    255254
    256255extern bool vfs_nodes_init(void);
  • uspace/srv/vfs/vfs_lookup.c

    r9bb85f3 rd6084ef  
    5050
    5151/* Forward static declarations. */
    52 static char *canonify(char *path);
     52static char *canonify(char *path, size_t *lenp);
    5353
    5454atomic_t plb_futex = FUTEX_INITIALIZER;
     
    5858/** Perform a path lookup.
    5959 *
    60  * @param path          Path to be resolved; it needn't be an ASCIIZ string.
    61  * @param len           Number of path characters pointed by path.
     60 * @param path          Path to be resolved; it must be a NULL-terminated
     61 *                      string.
    6262 * @param lflag         Flags to be used during lookup.
    6363 * @param result        Empty structure where the lookup result will be stored.
     
    6868 * @return              EOK on success or an error code from errno.h.
    6969 */
    70 int vfs_lookup_internal(char *path, size_t len, int lflag,
    71     vfs_lookup_res_t *result, vfs_pair_t *altroot)
     70int vfs_lookup_internal(char *path, int lflag, vfs_lookup_res_t *result,
     71    vfs_pair_t *altroot)
    7272{
    7373        vfs_pair_t *root;
    74 
    75         if (!len)
    76                 return EINVAL;
    7774
    7875        if (altroot)
     
    8380        if (!root->fs_handle)
    8481                return ENOENT;
     82       
     83        size_t len;
     84        path = canonify(path, &len);
     85        if (!path)
     86                return EINVAL;
    8587       
    8688        futex_down(&plb_futex);
     
    274276static void terminate_slash(token_t *t, token_t *tfsl, token_t *tlcomp)
    275277{
    276         tfsl->stop[1] = '\0';
     278        if (tfsl->stop[1])      /* avoid writing to a well-formatted path */
     279                tfsl->stop[1] = '\0';
    277280}
    278281static void remove_trailing_slash(token_t *t, token_t *tfsl, token_t *tlcomp)
     
    435438 * It works in-place and requires a NULL-terminated input string.
    436439 *
    437  * @param               Path to be canonified.
     440 * @param path          Path to be canonified.
     441 * @param lenp          Pointer where the length of the final path will be
     442 *                      stored. Can be NULL.
    438443 *
    439444 * @return              Canonified path or NULL on failure.
    440445 */
    441 char *canonify(char *path)
     446char *canonify(char *path, size_t *lenp)
    442447{
    443448        state_t state;
     
    451456        state = S_INI;
    452457        t = tfsl;
     458        tlcomp = tfsl;
    453459        while (state != S_ACCEPT && state != S_RESTART && state != S_REJECT) {
    454460                if (trans[state][t.kind].f)
     
    464470                return NULL;
    465471        case S_ACCEPT:
     472                if (lenp)
     473                        *lenp = (size_t)((tlcomp.stop - tfsl.start) + 1);
    466474                return tfsl.start;
    467475        default:
  • uspace/srv/vfs/vfs_ops.c

    r9bb85f3 rd6084ef  
    7676        };
    7777
    78         return vfs_lookup_internal("/", strlen("/"), L_DIRECTORY, result,
    79             &altroot);
     78        return vfs_lookup_internal("/", L_DIRECTORY, result, &altroot);
    8079}
    8180
     
    150149        /* Allocate buffer for the mount point data being received. */
    151150        uint8_t *buf;
    152         buf = malloc(size);
     151        buf = malloc(size + 1);
    153152        if (!buf) {
    154153                ipc_answer_0(callid, ENOMEM);
     
    159158        /* Deliver the mount point. */
    160159        (void) ipc_data_write_finalize(callid, buf, size);
     160        buf[size] = '\0';
    161161
    162162        /*
     
    187187                /* We already have the root FS. */
    188188                rwlock_write_lock(&namespace_rwlock);
    189                 rc = vfs_lookup_internal(buf, size, L_DIRECTORY, &mp_res,
    190                     NULL);
     189                rc = vfs_lookup_internal(buf, L_DIRECTORY, &mp_res, NULL);
    191190                if (rc != EOK) {
    192191                        /* The lookup failed for some reason. */
     
    315314         * directly into the PLB using some kind of a callback.
    316315         */
    317         char *path = malloc(len);
     316        char *path = malloc(len + 1);
    318317       
    319318        if (!path) {
     
    329328                return;
    330329        }
     330        path[len] = '\0';
    331331       
    332332        /*
     
    342342        /* The path is now populated and we can call vfs_lookup_internal(). */
    343343        vfs_lookup_res_t lr;
    344         rc = vfs_lookup_internal(path, len, lflag, &lr, NULL);
     344        rc = vfs_lookup_internal(path, lflag, &lr, NULL);
    345345        if (rc) {
    346346                if (lflag & L_CREATE)
     
    637637         * directly into the PLB using some kind of a callback.
    638638         */
    639         char *path = malloc(len);
     639        char *path = malloc(len + 1);
    640640       
    641641        if (!path) {
     
    651651                return;
    652652        }
     653        path[len] = '\0';
    653654       
    654655        rwlock_write_lock(&namespace_rwlock);
    655656        int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE;
    656         rc = vfs_lookup_internal(path, len, lflag, NULL, NULL);
     657        rc = vfs_lookup_internal(path, lflag, NULL, NULL);
    657658        rwlock_write_unlock(&namespace_rwlock);
    658659        free(path);
     
    679680         * directly into the PLB using some kind of a callback.
    680681         */
    681         char *path = malloc(len);
     682        char *path = malloc(len + 1);
    682683       
    683684        if (!path) {
     
    693694                return;
    694695        }
     696        path[len] = '\0';
    695697       
    696698        rwlock_write_lock(&namespace_rwlock);
    697699        lflag &= L_DIRECTORY;   /* sanitize lflag */
    698700        vfs_lookup_res_t lr;
    699         rc = vfs_lookup_internal(path, len, lflag | L_DESTROY, &lr, NULL);
     701        rc = vfs_lookup_internal(path, lflag | L_DESTROY, &lr, NULL);
    700702        free(path);
    701703        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.