Changeset 5cde90f in mainline for uspace/lib/libc/generic/vfs/vfs.c


Ignore:
Timestamp:
2010-02-19T17:16:46Z (14 years ago)
Author:
Pavel Rimsky <pavel@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
617652f
Parents:
b86d436 (diff), f41aa81 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Synchronizing with head (which has just been synchronized with this branch).

File:
1 edited

Legend:

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

    rb86d436 r5cde90f  
    3535#include <vfs/vfs.h>
    3636#include <vfs/canonify.h>
     37#include <macros.h>
    3738#include <stdlib.h>
    3839#include <unistd.h>
     
    120121    const char *opts, unsigned int flags)
    121122{
    122         int res;
     123        int null_id = -1;
     124        char null[DEVMAP_NAME_MAXLEN];
     125       
     126        if (str_cmp(fqdn, "") == 0) {
     127                /* No device specified, create a fresh
     128                   null/%d device instead */
     129                null_id = devmap_null_create();
     130               
     131                if (null_id == -1)
     132                        return ENOMEM;
     133               
     134                snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);
     135                fqdn = null;
     136        }
     137       
     138        dev_handle_t dev_handle;
     139        int res = devmap_device_get_handle(fqdn, &dev_handle, flags);
     140        if (res != EOK) {
     141                if (null_id != -1)
     142                        devmap_null_destroy(null_id);
     143               
     144                return res;
     145        }
     146       
     147        size_t mpa_size;
     148        char *mpa = absolutize(mp, &mpa_size);
     149        if (!mpa) {
     150                if (null_id != -1)
     151                        devmap_null_destroy(null_id);
     152               
     153                return ENOMEM;
     154        }
     155       
     156        futex_down(&vfs_phone_futex);
     157        async_serialize_start();
     158        vfs_connect();
     159       
     160        ipcarg_t rc_orig;
     161        aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     162        ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
     163        if (rc != EOK) {
     164                async_wait_for(req, &rc_orig);
     165                async_serialize_end();
     166                futex_up(&vfs_phone_futex);
     167                free(mpa);
     168               
     169                if (null_id != -1)
     170                        devmap_null_destroy(null_id);
     171               
     172                if (rc_orig == EOK)
     173                        return (int) rc;
     174                else
     175                        return (int) rc_orig;
     176        }
     177       
     178        rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));
     179        if (rc != EOK) {
     180                async_wait_for(req, &rc_orig);
     181                async_serialize_end();
     182                futex_up(&vfs_phone_futex);
     183                free(mpa);
     184               
     185                if (null_id != -1)
     186                        devmap_null_destroy(null_id);
     187               
     188                if (rc_orig == EOK)
     189                        return (int) rc;
     190                else
     191                        return (int) rc_orig;
     192        }
     193       
     194        rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
     195        if (rc != EOK) {
     196                async_wait_for(req, &rc_orig);
     197                async_serialize_end();
     198                futex_up(&vfs_phone_futex);
     199                free(mpa);
     200               
     201                if (null_id != -1)
     202                        devmap_null_destroy(null_id);
     203               
     204                if (rc_orig == EOK)
     205                        return (int) rc;
     206                else
     207                        return (int) rc_orig;
     208        }
     209       
     210        /* Ask VFS whether it likes fs_name. */
     211        rc = async_req_0_0(vfs_phone, IPC_M_PING);
     212        if (rc != EOK) {
     213                async_wait_for(req, &rc_orig);
     214                async_serialize_end();
     215                futex_up(&vfs_phone_futex);
     216                free(mpa);
     217               
     218                if (null_id != -1)
     219                        devmap_null_destroy(null_id);
     220               
     221                if (rc_orig == EOK)
     222                        return (int) rc;
     223                else
     224                        return (int) rc_orig;
     225        }
     226       
     227        async_wait_for(req, &rc);
     228        async_serialize_end();
     229        futex_up(&vfs_phone_futex);
     230        free(mpa);
     231       
     232        if ((rc != EOK) && (null_id != -1))
     233                devmap_null_destroy(null_id);
     234       
     235        return (int) rc;
     236}
     237
     238int unmount(const char *mp)
     239{
    123240        ipcarg_t rc;
    124241        ipcarg_t rc_orig;
    125242        aid_t req;
    126         dev_handle_t dev_handle;
    127        
    128         res = devmap_device_get_handle(fqdn, &dev_handle, flags);
    129         if (res != EOK)
    130                 return res;
    131        
    132243        size_t mpa_size;
    133         char *mpa = absolutize(mp, &mpa_size);
     244        char *mpa;
     245       
     246        mpa = absolutize(mp, &mpa_size);
    134247        if (!mpa)
    135248                return ENOMEM;
     
    139252        vfs_connect();
    140253       
    141         req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     254        req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL);
    142255        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    143256        if (rc != EOK) {
     
    152265        }
    153266       
    154         rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));
    155         if (rc != EOK) {
    156                 async_wait_for(req, &rc_orig);
    157                 async_serialize_end();
    158                 futex_up(&vfs_phone_futex);
    159                 free(mpa);
    160                 if (rc_orig == EOK)
    161                         return (int) rc;
    162                 else
    163                         return (int) rc_orig;
    164         }
    165 
    166         rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
    167         if (rc != EOK) {
    168                 async_wait_for(req, &rc_orig);
    169                 async_serialize_end();
    170                 futex_up(&vfs_phone_futex);
    171                 free(mpa);
    172                 if (rc_orig == EOK)
    173                         return (int) rc;
    174                 else
    175                         return (int) rc_orig;
    176         }
    177 
    178         /* Ask VFS whether it likes fs_name. */
    179         rc = async_req_0_0(vfs_phone, IPC_M_PING);
    180         if (rc != EOK) {
    181                 async_wait_for(req, &rc_orig);
    182                 async_serialize_end();
    183                 futex_up(&vfs_phone_futex);
    184                 free(mpa);
    185                 if (rc_orig == EOK)
    186                         return (int) rc;
    187                 else
    188                         return (int) rc_orig;
    189         }
    190        
     267
    191268        async_wait_for(req, &rc);
    192269        async_serialize_end();
     
    358435}
    359436
    360 off_t lseek(int fildes, off_t offset, int whence)
    361 {
    362         ipcarg_t rc;
    363 
    364         futex_down(&vfs_phone_futex);
    365         async_serialize_start();
    366         vfs_connect();
    367        
    368         ipcarg_t newoffs;
    369         rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence,
    370             &newoffs);
    371 
    372         async_serialize_end();
    373         futex_up(&vfs_phone_futex);
    374 
     437off64_t lseek(int fildes, off64_t offset, int whence)
     438{
     439        futex_down(&vfs_phone_futex);
     440        async_serialize_start();
     441        vfs_connect();
     442       
     443        ipcarg_t newoff_lo;
     444        ipcarg_t newoff_hi;
     445        ipcarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes,
     446            LOWER32(offset), UPPER32(offset), whence,
     447            &newoff_lo, &newoff_hi);
     448       
     449        async_serialize_end();
     450        futex_up(&vfs_phone_futex);
     451       
    375452        if (rc != EOK)
    376                 return (off_t) -1;
    377        
    378         return (off_t) newoffs;
    379 }
    380 
    381 int ftruncate(int fildes, off_t length)
    382 {
    383         ipcarg_t rc;
    384        
    385         futex_down(&vfs_phone_futex);
    386         async_serialize_start();
    387         vfs_connect();
    388        
    389         rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length);
    390         async_serialize_end();
    391         futex_up(&vfs_phone_futex);
     453                return (off64_t) -1;
     454       
     455        return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi);
     456}
     457
     458int ftruncate(int fildes, aoff64_t length)
     459{
     460        ipcarg_t rc;
     461       
     462        futex_down(&vfs_phone_futex);
     463        async_serialize_start();
     464        vfs_connect();
     465       
     466        rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes,
     467            LOWER32(length), UPPER32(length));
     468        async_serialize_end();
     469        futex_up(&vfs_phone_futex);
     470       
    392471        return (int) rc;
    393472}
     
    403482       
    404483        req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
    405         rc = async_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat));
     484        rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat));
    406485        if (rc != EOK) {
    407486                ipcarg_t rc_orig;
     
    477556        if (!abs) {
    478557                free(dirp);
    479                 return ENOMEM;
     558                return NULL;
    480559        }
    481560       
Note: See TracChangeset for help on using the changeset viewer.