Changeset a8e9ab8d in mainline for uspace/lib


Ignore:
Timestamp:
2008-03-09T17:18:30Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4072980
Parents:
2664838b
Message:

Support for rename().

Location:
uspace/lib
Files:
4 edited

Legend:

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

    r2664838b ra8e9ab8d  
    469469}
    470470
     471int rename(const char *old, const char *new)
     472{
     473        int res;
     474        ipcarg_t rc;
     475        aid_t req;
     476       
     477        char *olda = absolutize(old);
     478        if (!olda)
     479                return ENOMEM;
     480        size_t oldc_len;
     481        char *oldc = canonify(olda, &oldc_len);
     482        if (!oldc) {
     483                free(olda);
     484                return EINVAL;
     485        }
     486        char *newa = absolutize(new);
     487        if (!newa) {
     488                free(olda);
     489                return ENOMEM;
     490        }
     491        size_t newc_len;
     492        char *newc = canonify(newa, &newc_len);
     493        if (!newc) {
     494                free(olda);
     495                free(newa);
     496                return EINVAL;
     497        }
     498
     499        futex_down(&vfs_phone_futex);
     500        async_serialize_start();
     501        if (vfs_phone < 0) {
     502                res = vfs_connect();
     503                if (res < 0) {
     504                        async_serialize_end();
     505                        futex_up(&vfs_phone_futex);
     506                        free(olda);
     507                        free(newa);
     508                        return res;
     509                }
     510        }
     511        req = async_send_0(vfs_phone, VFS_RENAME, NULL);
     512        rc = ipc_data_write_start(vfs_phone, oldc, oldc_len);
     513        if (rc != EOK) {
     514                async_wait_for(req, NULL);
     515                async_serialize_end();
     516                futex_up(&vfs_phone_futex);
     517                free(olda);
     518                free(newa);
     519                return (int) rc;
     520        }
     521        rc = ipc_data_write_start(vfs_phone, newc, newc_len);
     522        if (rc != EOK) {
     523                async_wait_for(req, NULL);
     524                async_serialize_end();
     525                futex_up(&vfs_phone_futex);
     526                free(olda);
     527                free(newa);
     528                return (int) rc;
     529        }
     530        async_wait_for(req, &rc);
     531        async_serialize_end();
     532        futex_up(&vfs_phone_futex);
     533        free(olda);
     534        free(newa);
     535        return rc;
     536}
     537
    471538int chdir(const char *path)
    472539{
  • uspace/lib/libc/include/stdio.h

    r2664838b ra8e9ab8d  
    6868#define fprintf(f, fmt, ...) printf(fmt, ##__VA_ARGS__)
    6969
     70extern int rename(const char *, const char *);
     71
    7072#endif
    7173
  • uspace/lib/libfs/libfs.c

    r2664838b ra8e9ab8d  
    142142        int dev_handle = IPC_GET_ARG3(*request);
    143143        int lflag = IPC_GET_ARG4(*request);
     144        int index = IPC_GET_ARG5(*request); /* when L_LINK specified */
    144145
    145146        if (last < next)
     
    181182                /* handle miss: match amongst siblings */
    182183                if (!tmp) {
    183                         if ((next > last) && (lflag & L_CREATE)) {
    184                                 /* no components left and L_CREATE specified */
     184                        if (next <= last) {
     185                                /* there are unprocessed components */
     186                                ipc_answer_0(rid, ENOENT);
     187                                return;
     188                        }
     189                        /* miss in the last component */
     190                        if (lflag & (L_CREATE | L_LINK)) {
     191                                /* request to create a new link */
    185192                                if (!ops->is_directory(cur)) {
    186193                                        ipc_answer_0(rid, ENOTDIR);
    187194                                        return;
    188                                 }
    189                                 void *nodep = ops->create(lflag);
     195                                }
     196                                void *nodep;
     197                                if (lflag & L_CREATE)
     198                                        nodep = ops->create(lflag);
     199                                else
     200                                        nodep = ops->node_get(fs_handle,
     201                                            dev_handle, index);
    190202                                if (nodep) {
    191203                                        if (!ops->link(cur, nodep, component)) {
    192                                                 ops->destroy(nodep);
     204                                                if (lflag & L_CREATE)
     205                                                        ops->destroy(nodep);
    193206                                                ipc_answer_0(rid, ENOSPC);
    194207                                        } else {
    195208                                                ipc_answer_5(rid, EOK,
    196209                                                    fs_handle, dev_handle,
    197                                                     ops->index_get(nodep), 0,
     210                                                    ops->index_get(nodep),
     211                                                    ops->size_get(nodep),
    198212                                                    ops->lnkcnt_get(nodep));
    199213                                        }
     
    202216                                }
    203217                                return;
    204                         }
     218                        } else if (lflag & L_PARENT) {
     219                                /* return parent */
     220                                ipc_answer_5(rid, EOK, fs_handle, dev_handle,
     221                                    ops->index_get(cur), ops->size_get(cur),
     222                                    ops->lnkcnt_get(cur));
     223                        }
    205224                        ipc_answer_0(rid, ENOENT);
    206225                        return;
     
    215234        /* handle miss: excessive components */
    216235        if (!tmp && next <= last) {
    217                 if (lflag & L_CREATE) {
     236                if (lflag & (L_CREATE | L_LINK)) {
    218237                        if (!ops->is_directory(cur)) {
    219238                                ipc_answer_0(rid, ENOTDIR);
     
    240259                        len = 0;
    241260                               
    242                         void *nodep = ops->create(lflag);
     261                        void *nodep;
     262                        if (lflag & L_CREATE)
     263                                nodep = ops->create(lflag);
     264                        else
     265                                nodep = ops->node_get(fs_handle, dev_handle,
     266                                    index);
    243267                        if (nodep) {
    244268                                if (!ops->link(cur, nodep, component)) {
    245                                         ops->destroy(nodep);
     269                                        if (lflag & L_CREATE)
     270                                                ops->destroy(nodep);
    246271                                        ipc_answer_0(rid, ENOSPC);
    247272                                } else {
    248273                                        ipc_answer_5(rid, EOK,
    249274                                            fs_handle, dev_handle,
    250                                             ops->index_get(nodep), 0,
     275                                            ops->index_get(nodep),
     276                                            ops->size_get(nodep),
    251277                                            ops->lnkcnt_get(nodep));
    252278                                }
     
    261287
    262288        /* handle hit */
    263         if (lflag & L_DESTROY) {
     289        if (lflag & L_PARENT) {
     290                cur = par;
     291                if (!cur) {
     292                        ipc_answer_0(rid, ENOENT);
     293                        return;
     294                }
     295        }
     296        if (lflag & L_UNLINK) {
    264297                unsigned old_lnkcnt = ops->lnkcnt_get(cur);
    265298                int res = ops->unlink(par, cur);
     
    268301                return;
    269302        }
    270         if ((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) {
     303        if (((lflag & (L_CREATE | L_EXCLUSIVE)) == (L_CREATE | L_EXCLUSIVE)) ||
     304            (lflag & L_LINK)) {
    271305                ipc_answer_0(rid, EEXIST);
    272306                return;
  • uspace/lib/libfs/libfs.h

    r2664838b ra8e9ab8d  
    4444typedef struct {
    4545        bool (* match)(void *, void *, const char *);
     46        void * (* node_get)(int, int, unsigned long);
    4647        void * (* create)(int);
    4748        void (* destroy)(void *);
Note: See TracChangeset for help on using the changeset viewer.