Changeset a8e9ab8d in mainline for uspace/lib/libfs/libfs.c


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().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.