Changeset bd5f3b7 in mainline for uspace/lib/c/generic/vfs/vfs.c


Ignore:
Timestamp:
2011-08-21T13:07:35Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00aece0, f1a9e87
Parents:
86a34d3e (diff), a6480d5 (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:

Merge mainline changes.

File:
1 edited

Legend:

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

    r86a34d3e rbd5f3b7  
    5151#include <assert.h>
    5252#include <str.h>
    53 #include <devmap.h>
     53#include <loc.h>
    5454#include <ipc/vfs.h>
    55 #include <ipc/devmap.h>
     55#include <ipc/loc.h>
    5656
    5757static FIBRIL_MUTEX_INITIALIZE(vfs_mutex);
     
    6969 *
    7070 */
    71 static async_exch_t *vfs_exchange_begin(void)
     71async_exch_t *vfs_exchange_begin(void)
    7272{
    7373        fibril_mutex_lock(&vfs_mutex);
     
    8787 *
    8888 */
    89 static void vfs_exchange_end(async_exch_t *exch)
     89void vfs_exchange_end(async_exch_t *exch)
    9090{
    9191        async_exchange_end(exch);
     
    142142}
    143143
    144 int mount(const char *fs_name, const char *mp, const char *fqdn,
     144int mount(const char *fs_name, const char *mp, const char *fqsn,
    145145    const char *opts, unsigned int flags)
    146146{
    147147        int null_id = -1;
    148         char null[DEVMAP_NAME_MAXLEN];
    149        
    150         if (str_cmp(fqdn, "") == 0) {
     148        char null[LOC_NAME_MAXLEN];
     149       
     150        if (str_cmp(fqsn, "") == 0) {
    151151                /* No device specified, create a fresh
    152152                   null/%d device instead */
    153                 null_id = devmap_null_create();
     153                null_id = loc_null_create();
    154154               
    155155                if (null_id == -1)
    156156                        return ENOMEM;
    157157               
    158                 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);
    159                 fqdn = null;
    160         }
    161        
    162         devmap_handle_t devmap_handle;
    163         int res = devmap_device_get_handle(fqdn, &devmap_handle, flags);
     158                snprintf(null, LOC_NAME_MAXLEN, "null/%d", null_id);
     159                fqsn = null;
     160        }
     161       
     162        service_id_t service_id;
     163        int res = loc_service_get_id(fqsn, &service_id, flags);
    164164        if (res != EOK) {
    165165                if (null_id != -1)
    166                         devmap_null_destroy(null_id);
     166                        loc_null_destroy(null_id);
    167167               
    168168                return res;
     
    173173        if (!mpa) {
    174174                if (null_id != -1)
    175                         devmap_null_destroy(null_id);
     175                        loc_null_destroy(null_id);
    176176               
    177177                return ENOMEM;
     
    181181
    182182        sysarg_t rc_orig;
    183         aid_t req = async_send_2(exch, VFS_IN_MOUNT, devmap_handle, flags, NULL);
     183        aid_t req = async_send_2(exch, VFS_IN_MOUNT, service_id, flags, NULL);
    184184        sysarg_t rc = async_data_write_start(exch, (void *) mpa, mpa_size);
    185185        if (rc != EOK) {
     
    189189               
    190190                if (null_id != -1)
    191                         devmap_null_destroy(null_id);
     191                        loc_null_destroy(null_id);
    192192               
    193193                if (rc_orig == EOK)
     
    204204               
    205205                if (null_id != -1)
    206                         devmap_null_destroy(null_id);
     206                        loc_null_destroy(null_id);
    207207               
    208208                if (rc_orig == EOK)
     
    219219               
    220220                if (null_id != -1)
    221                         devmap_null_destroy(null_id);
     221                        loc_null_destroy(null_id);
    222222               
    223223                if (rc_orig == EOK)
     
    235235               
    236236                if (null_id != -1)
    237                         devmap_null_destroy(null_id);
     237                        loc_null_destroy(null_id);
    238238               
    239239                if (rc_orig == EOK)
     
    248248       
    249249        if ((rc != EOK) && (null_id != -1))
    250                 devmap_null_destroy(null_id);
     250                loc_null_destroy(null_id);
    251251       
    252252        return (int) rc;
     
    329329}
    330330
    331 int open_node(fdi_node_t *node, int oflag)
    332 {
    333         async_exch_t *exch = vfs_exchange_begin();
    334        
    335         ipc_call_t answer;
    336         aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,
    337             node->devmap_handle, node->index, oflag, &answer);
    338        
    339         vfs_exchange_end(exch);
    340 
    341         sysarg_t rc;
    342         async_wait_for(req, &rc);
    343        
    344         if (rc != EOK)
    345                 return (int) rc;
    346        
    347         return (int) IPC_GET_ARG1(answer);
    348 }
    349 
    350331int close(int fildes)
    351332{
     
    415396        else
    416397                return -1;
     398}
     399
     400/** Read entire buffer.
     401 *
     402 * In face of short reads this function continues reading until either
     403 * the entire buffer is read or no more data is available (at end of file).
     404 *
     405 * @param fildes        File descriptor
     406 * @param buf           Buffer, @a nbytes bytes long
     407 * @param nbytes        Number of bytes to read
     408 *
     409 * @return              On success, positive number of bytes read.
     410 *                      On failure, negative error code from read().
     411 */
     412ssize_t read_all(int fildes, void *buf, size_t nbyte)
     413{
     414        ssize_t cnt = 0;
     415        size_t nread = 0;
     416        uint8_t *bp = (uint8_t *) buf;
     417
     418        do {
     419                bp += cnt;
     420                nread += cnt;
     421                cnt = read(fildes, bp, nbyte - nread);
     422        } while (cnt > 0 && (nbyte - nread - cnt) > 0);
     423
     424        if (cnt < 0)
     425                return cnt;
     426
     427        return nread + cnt;
     428}
     429
     430/** Write entire buffer.
     431 *
     432 * This function fails if it cannot write exactly @a len bytes to the file.
     433 *
     434 * @param fildes        File descriptor
     435 * @param buf           Data, @a nbytes bytes long
     436 * @param nbytes        Number of bytes to write
     437 *
     438 * @return              EOK on error, return value from write() if writing
     439 *                      failed.
     440 */
     441ssize_t write_all(int fildes, const void *buf, size_t nbyte)
     442{
     443        ssize_t cnt = 0;
     444        ssize_t nwritten = 0;
     445        const uint8_t *bp = (uint8_t *) buf;
     446
     447        do {
     448                bp += cnt;
     449                nwritten += cnt;
     450                cnt = write(fildes, bp, nbyte - nwritten);
     451        } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0);
     452
     453        if (cnt < 0)
     454                return cnt;
     455
     456        if ((ssize_t)nbyte - nwritten - cnt > 0)
     457                return EIO;
     458
     459        return nbyte;
    417460}
    418461
     
    749792        }
    750793       
    751         if (!stat.device) {
     794        if (!stat.service) {
    752795                errno = ENOENT;
    753796                return NULL;
    754797        }
    755798       
    756         return devmap_device_connect(mgmt, stat.device, 0);
    757 }
    758 
    759 int fd_node(int fildes, fdi_node_t *node)
    760 {
    761         struct stat stat;
    762         int rc = fstat(fildes, &stat);
    763        
    764         if (rc == EOK) {
    765                 node->fs_handle = stat.fs_handle;
    766                 node->devmap_handle = stat.devmap_handle;
    767                 node->index = stat.index;
    768         }
    769        
    770         return rc;
     799        return loc_service_connect(mgmt, stat.service, 0);
    771800}
    772801
     
    786815}
    787816
     817int fd_wait(void)
     818{
     819        async_exch_t *exch = vfs_exchange_begin();
     820       
     821        sysarg_t ret;
     822        sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret);
     823       
     824        vfs_exchange_end(exch);
     825       
     826        if (rc == EOK)
     827                return (int) ret;
     828       
     829        return (int) rc;
     830}
     831
    788832/** @}
    789833 */
Note: See TracChangeset for help on using the changeset viewer.