Changeset 852b801 in mainline


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.

Location:
uspace
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/vfs/vfs.c

    r4198f9c3 r852b801  
    3939#include <dirent.h>
    4040#include <fcntl.h>
     41#include <stdio.h>
    4142#include <sys/stat.h>
    42 #include <stdio.h>
    4343#include <sys/types.h>
    4444#include <ipc/ipc.h>
     
    315315}
    316316
    317 int fd_phone(int fildes)
    318 {
    319         futex_down(&vfs_phone_futex);
    320         async_serialize_start();
    321         vfs_connect();
    322        
    323         ipcarg_t device;
    324         ipcarg_t rc = async_req_1_1(vfs_phone, VFS_IN_DEVICE, fildes, &device);
    325        
    326         async_serialize_end();
    327         futex_up(&vfs_phone_futex);
    328        
    329         if (rc != EOK)
    330                 return -1;
    331        
    332         return devmap_device_connect((dev_handle_t) device, 0);
    333 }
    334 
    335 int fd_node(int fildes, fdi_node_t *node)
    336 {
    337         futex_down(&vfs_phone_futex);
    338         async_serialize_start();
    339         vfs_connect();
    340        
    341         ipcarg_t fs_handle;
    342         ipcarg_t dev_handle;
    343         ipcarg_t index;
    344         ipcarg_t rc = async_req_1_3(vfs_phone, VFS_IN_NODE, fildes, &fs_handle,
    345             &dev_handle, &index);
    346        
    347         async_serialize_end();
    348         futex_up(&vfs_phone_futex);
    349        
    350         if (rc == EOK) {
    351                 node->fs_handle = (fs_handle_t) fs_handle;
    352                 node->dev_handle = (dev_handle_t) dev_handle;
    353                 node->index = (fs_index_t) index;
    354         }
    355        
    356         return rc;
    357 }
    358 
    359317int fsync(int fildes)
    360318{
     
    404362        futex_up(&vfs_phone_futex);
    405363        return (int) rc;
     364}
     365
     366int fstat(int fildes, struct stat *stat)
     367{
     368        ipcarg_t rc;
     369        ipc_call_t answer;
     370        aid_t req;
     371
     372        futex_down(&vfs_phone_futex);
     373        async_serialize_start();
     374        vfs_connect();
     375       
     376        req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
     377        rc = ipc_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat));
     378        if (rc != EOK) {
     379                async_wait_for(req, NULL);
     380                async_serialize_end();
     381                futex_up(&vfs_phone_futex);
     382                return (ssize_t) rc;
     383        }
     384        async_wait_for(req, &rc);
     385        async_serialize_end();
     386        futex_up(&vfs_phone_futex);
     387
     388        return rc;
    406389}
    407390
     
    599582}
    600583
     584int fd_phone(int fildes)
     585{
     586        struct stat stat;
     587        int rc;
     588
     589        rc = fstat(fildes, &stat);
     590
     591        if (!stat.devfs_stat.device)
     592                return -1;
     593       
     594        return devmap_device_connect(stat.devfs_stat.device, 0);
     595}
     596
     597int fd_node(int fildes, fdi_node_t *node)
     598{
     599        struct stat stat;
     600        int rc;
     601
     602        rc = fstat(fildes, &stat);
     603       
     604        if (rc == EOK) {
     605                node->fs_handle = stat.fs_handle;
     606                node->dev_handle = stat.dev_handle;
     607                node->index = stat.index;
     608        }
     609       
     610        return rc;
     611}
     612
    601613/** @}
    602614 */
  • uspace/lib/libc/include/ipc/vfs.h

    r4198f9c3 r852b801  
    6464        VFS_IN_SEEK,
    6565        VFS_IN_TRUNCATE,
     66        VFS_IN_FSTAT,
    6667        VFS_IN_CLOSE,
    6768        VFS_IN_MOUNT,
     
    7374        VFS_IN_UNLINK,
    7475        VFS_IN_RENAME,
     76        VFS_IN_STAT,
    7577        VFS_IN_NODE
    7678} vfs_in_request_t;
     
    8789        VFS_OUT_DEVICE,
    8890        VFS_OUT_SYNC,
     91        VFS_OUT_STAT,
    8992        VFS_OUT_LOOKUP,
    9093        VFS_OUT_DESTROY,
  • uspace/lib/libc/include/sys/stat.h

    r4198f9c3 r852b801  
    3737
    3838#include <sys/types.h>
     39#include <bool.h>
     40#include <ipc/vfs.h>
     41#include <ipc/devmap.h>
    3942
     43struct stat {
     44        fs_handle_t     fs_handle;
     45        dev_handle_t    dev_handle;
     46        fs_index_t      index;
     47        unsigned        lnkcnt;
     48        bool            is_file;
     49        off_t           size;
     50        union {
     51                struct {
     52                        dev_handle_t    device;
     53                } devfs_stat;
     54        };
     55};
     56
     57extern int fstat(int, struct stat *);
    4058extern int mkdir(const char *, mode_t);
    4159
  • uspace/srv/fs/devfs/devfs.c

    r4198f9c3 r852b801  
    8080                        devfs_open_node(callid, &call);
    8181                        break;
    82                 case VFS_OUT_DEVICE:
    83                         devfs_device(callid, &call);
     82                case VFS_OUT_STAT:
     83                        devfs_stat(callid, &call);
    8484                        break;
    8585                case VFS_OUT_READ:
  • 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
  • uspace/srv/fs/devfs/devfs_ops.h

    r4198f9c3 r852b801  
    4343extern void devfs_lookup(ipc_callid_t, ipc_call_t *);
    4444extern void devfs_open_node(ipc_callid_t, ipc_call_t *);
    45 extern void devfs_device(ipc_callid_t, ipc_call_t *);
     45extern void devfs_stat(ipc_callid_t, ipc_call_t *);
    4646extern void devfs_sync(ipc_callid_t, ipc_call_t *);
    4747extern void devfs_read(ipc_callid_t, ipc_call_t *);
  • uspace/srv/fs/fat/fat.c

    r4198f9c3 r852b801  
    110110                        fat_truncate(callid, &call);
    111111                        break;
     112                case VFS_OUT_STAT:
     113                        fat_stat(callid, &call);
     114                        break;
    112115                case VFS_OUT_CLOSE:
    113116                        fat_close(callid, &call);
     
    118121                case VFS_OUT_OPEN_NODE:
    119122                        fat_open_node(callid, &call);
    120                         break;
    121                 case VFS_OUT_DEVICE:
    122                         fat_device(callid, &call);
    123123                        break;
    124124                case VFS_OUT_SYNC:
  • uspace/srv/fs/fat/fat.h

    r4198f9c3 r852b801  
    208208extern void fat_write(ipc_callid_t, ipc_call_t *);
    209209extern void fat_truncate(ipc_callid_t, ipc_call_t *);
     210extern void fat_stat(ipc_callid_t, ipc_call_t *);
    210211extern void fat_close(ipc_callid_t, ipc_call_t *);
    211212extern void fat_destroy(ipc_callid_t, ipc_call_t *);
    212213extern void fat_open_node(ipc_callid_t, ipc_call_t *);
    213 extern void fat_device(ipc_callid_t, ipc_call_t *);
     214extern void fat_stat(ipc_callid_t, ipc_call_t *);
    214215extern void fat_sync(ipc_callid_t, ipc_call_t *);
    215216
  • uspace/srv/fs/fat/fat_ops.c

    r4198f9c3 r852b801  
    12031203}
    12041204
    1205 void fat_device(ipc_callid_t rid, ipc_call_t *request)
     1205void fat_stat(ipc_callid_t rid, ipc_call_t *request)
    12061206{
    12071207        ipc_answer_0(rid, ENOTSUP);
  • uspace/srv/fs/tmpfs/tmpfs.c

    r4198f9c3 r852b801  
    126126                        tmpfs_open_node(callid, &call);
    127127                        break;
    128                 case VFS_OUT_DEVICE:
    129                         tmpfs_device(callid, &call);
     128                case VFS_OUT_STAT:
     129                        tmpfs_stat(callid, &call);
    130130                        break;
    131131                case VFS_OUT_SYNC:
  • uspace/srv/fs/tmpfs/tmpfs.h

    r4198f9c3 r852b801  
    8787extern void tmpfs_write(ipc_callid_t, ipc_call_t *);
    8888extern void tmpfs_truncate(ipc_callid_t, ipc_call_t *);
     89extern void tmpfs_stat(ipc_callid_t, ipc_call_t *);
    8990extern void tmpfs_close(ipc_callid_t, ipc_call_t *);
    9091extern void tmpfs_destroy(ipc_callid_t, ipc_call_t *);
    9192extern void tmpfs_open_node(ipc_callid_t, ipc_call_t *);
    92 extern void tmpfs_device(ipc_callid_t, ipc_call_t *);
    9393extern void tmpfs_sync(ipc_callid_t, ipc_call_t *);
    9494
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r4198f9c3 r852b801  
    629629}
    630630
    631 void tmpfs_device(ipc_callid_t rid, ipc_call_t *request)
     631void tmpfs_stat(ipc_callid_t rid, ipc_call_t *request)
    632632{
    633633        ipc_answer_0(rid, ENOTSUP);
  • uspace/srv/vfs/vfs.c

    r4198f9c3 r852b801  
    108108                        vfs_truncate(callid, &call);
    109109                        break;
     110                case VFS_IN_FSTAT:
     111                        vfs_fstat(callid, &call);
     112                        break;
     113                case VFS_IN_STAT:
     114                        vfs_stat(callid, &call);
     115                        break;
    110116                case VFS_IN_MKDIR:
    111117                        vfs_mkdir(callid, &call);
     
    117123                        vfs_rename(callid, &call);
    118124                        break;
    119                 case VFS_IN_DEVICE:
    120                         vfs_device(callid, &call);
    121                         break;
    122125                case VFS_IN_SYNC:
    123126                        vfs_sync(callid, &call);
    124                         break;
    125                 case VFS_IN_NODE:
    126                         vfs_node(callid, &call);
    127127                        break;
    128128                default:
  • uspace/srv/vfs/vfs.h

    r4198f9c3 r852b801  
    199199extern void vfs_open(ipc_callid_t, ipc_call_t *);
    200200extern void vfs_open_node(ipc_callid_t, ipc_call_t *);
    201 extern void vfs_device(ipc_callid_t, ipc_call_t *);
    202201extern void vfs_sync(ipc_callid_t, ipc_call_t *);
    203 extern void vfs_node(ipc_callid_t, ipc_call_t *);
    204202extern void vfs_close(ipc_callid_t, ipc_call_t *);
    205203extern void vfs_read(ipc_callid_t, ipc_call_t *);
     
    207205extern void vfs_seek(ipc_callid_t, ipc_call_t *);
    208206extern void vfs_truncate(ipc_callid_t, ipc_call_t *);
     207extern void vfs_fstat(ipc_callid_t, ipc_call_t *);
     208extern void vfs_fstat(ipc_callid_t, ipc_call_t *);
     209extern void vfs_stat(ipc_callid_t, ipc_call_t *);
    209210extern void vfs_mkdir(ipc_callid_t, ipc_call_t *);
    210211extern void vfs_unlink(ipc_callid_t, ipc_call_t *);
  • uspace/srv/vfs/vfs_ops.c

    r4198f9c3 r852b801  
    642642}
    643643
    644 void vfs_node(ipc_callid_t rid, ipc_call_t *request)
    645 {
    646         int fd = IPC_GET_ARG1(*request);
    647        
    648         /* Lookup the file structure corresponding to the file descriptor. */
    649         vfs_file_t *file = vfs_file_get(fd);
    650         if (!file) {
    651                 ipc_answer_0(rid, ENOENT);
    652                 return;
    653         }
    654        
    655         ipc_answer_3(rid, EOK, file->node->fs_handle, file->node->dev_handle,
    656             file->node->index);
    657 }
    658 
    659 void vfs_device(ipc_callid_t rid, ipc_call_t *request)
    660 {
    661         int fd = IPC_GET_ARG1(*request);
    662        
    663         /* Lookup the file structure corresponding to the file descriptor. */
    664         vfs_file_t *file = vfs_file_get(fd);
    665         if (!file) {
    666                 ipc_answer_0(rid, ENOENT);
    667                 return;
    668         }
    669        
    670         /*
    671          * Lock the open file structure so that no other thread can manipulate
    672          * the same open file at a time.
    673          */
    674         fibril_mutex_lock(&file->lock);
    675         int fs_phone = vfs_grab_phone(file->node->fs_handle);
    676        
    677         /* Make a VFS_OUT_DEVICE request at the destination FS server. */
    678         aid_t msg;
    679         ipc_call_t answer;
    680         msg = async_send_2(fs_phone, VFS_OUT_DEVICE, file->node->dev_handle,
    681             file->node->index, &answer);
    682 
    683         /* Wait for reply from the FS server. */
    684         ipcarg_t rc;
    685         async_wait_for(msg, &rc);
    686 
    687         vfs_release_phone(fs_phone);
    688         fibril_mutex_unlock(&file->lock);
    689        
    690         ipc_answer_1(rid, EOK, IPC_GET_ARG1(answer));
    691 }
    692 
    693644void vfs_sync(ipc_callid_t rid, ipc_call_t *request)
    694645{
     
    975926        fibril_mutex_unlock(&file->lock);
    976927        ipc_answer_0(rid, (ipcarg_t)rc);
     928}
     929
     930void vfs_fstat(ipc_callid_t rid, ipc_call_t *request)
     931{
     932        int fd = IPC_GET_ARG1(*request);
     933        size_t size = IPC_GET_ARG2(*request);
     934        ipcarg_t rc;
     935
     936        vfs_file_t *file = vfs_file_get(fd);
     937        if (!file) {
     938                ipc_answer_0(rid, ENOENT);
     939                return;
     940        }
     941
     942        ipc_callid_t callid;
     943        if (!ipc_data_read_receive(&callid, NULL)) {
     944                ipc_answer_0(callid, EINVAL);
     945                ipc_answer_0(rid, EINVAL);
     946                return;
     947        }
     948
     949        fibril_mutex_lock(&file->lock);
     950
     951        int fs_phone = vfs_grab_phone(file->node->fs_handle);
     952       
     953        aid_t msg;
     954        msg = async_send_3(fs_phone, VFS_OUT_STAT, file->node->dev_handle,
     955            file->node->index, true, NULL);
     956        ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
     957        async_wait_for(msg, &rc);
     958        vfs_release_phone(fs_phone);
     959
     960        fibril_mutex_unlock(&file->lock);
     961        ipc_answer_0(rid, rc);
     962}
     963
     964void vfs_stat(ipc_callid_t rid, ipc_call_t *request)
     965{
    977966}
    978967
Note: See TracChangeset for help on using the changeset viewer.