Changeset 852b801 in mainline for uspace/srv/fs/devfs/devfs_ops.c


Ignore:
Timestamp:
2009-06-28T18:59:02Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
75160a6
Parents:
4198f9c3
Message:

Introduce VFS_IN_FSTAT and VFS_OUT_STAT.
Provide libc fstat() and devfs_stat().
This functionality replaces VFS_IN_NODE
and VFS_IN/OUT_DEVICE. FAT and TMPFS
still do not implement this and VFS_IN_STAT
and stat() need implementation as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/devfs/devfs_ops.c

    r4198f9c3 r852b801  
    4444#include <fibril_sync.h>
    4545#include <adt/hash_table.h>
     46#include <sys/stat.h>
    4647#include "devfs.h"
    4748#include "devfs_ops.h"
     
    278279}
    279280
    280 void devfs_device(ipc_callid_t rid, ipc_call_t *request)
    281 {
     281void devfs_stat(ipc_callid_t rid, ipc_call_t *request)
     282{
     283        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    282284        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     285       
     286        ipc_callid_t callid;
     287        size_t size;
     288        if (!ipc_data_read_receive(&callid, &size) ||
     289            size < sizeof(struct stat)) {
     290                ipc_answer_0(callid, EINVAL);
     291                ipc_answer_0(rid, EINVAL);
     292                return;
     293        }
     294
     295        struct stat *stat = malloc(sizeof(struct stat));
     296        if (!stat) {
     297                ipc_answer_0(callid, ENOMEM);
     298                ipc_answer_0(rid, ENOMEM);
     299                return;
     300        }
     301        memset(stat, 0, sizeof(struct stat));
     302
     303        stat->fs_handle = devfs_reg.fs_handle;
     304        stat->dev_handle = dev_handle;
     305        stat->index = index;
     306        stat->lnkcnt = 1;
     307        stat->is_file = (index != 0);
     308        stat->size = 0;
    283309       
    284310        if (index != 0) {
     
    289315                fibril_mutex_lock(&devices_mutex);
    290316                link_t *lnk = hash_table_find(&devices, key);
    291                 if (lnk == NULL) {
    292                         fibril_mutex_unlock(&devices_mutex);
    293                         ipc_answer_0(rid, ENOENT);
    294                         return;
    295                 }
     317                if (lnk != NULL)
     318                        stat->devfs_stat.device = (dev_handle_t)index;
    296319                fibril_mutex_unlock(&devices_mutex);
    297                
    298                 ipc_answer_1(rid, EOK, (ipcarg_t) index);
    299         } else
    300                 ipc_answer_0(rid, ENOTSUP);
     320        }
     321
     322        ipc_data_read_finalize(callid, stat, sizeof(struct stat));
     323        ipc_answer_0(rid, EOK);
     324
     325        free(stat);
    301326}
    302327
Note: See TracChangeset for help on using the changeset viewer.