Subversion Repositories HelenOS

Rev

Rev 2597 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2597 Rev 2619
Line 82... Line 82...
82
    /*
82
    /*
83
     * Now, we expect the client to send us data with the name of the file
83
     * Now, we expect the client to send us data with the name of the file
84
     * system and the path of the mountpoint.
84
     * system and the path of the mountpoint.
85
     */
85
     */
86
    ipc_callid_t callid;
86
    ipc_callid_t callid;
87
    ipc_call_t call;
-
 
88
    size_t size;
87
    size_t size;
89
    if (!ipc_data_receive(&callid, &call, NULL, &size)) {
88
    if (!ipc_data_receive(&callid, NULL, &size)) {
90
        ipc_answer_fast_0(callid, EINVAL);
89
        ipc_answer_0(callid, EINVAL);
91
        ipc_answer_fast_0(rid, EINVAL);
90
        ipc_answer_0(rid, EINVAL);
92
        return;
91
        return;
93
    }
92
    }
94
 
93
 
95
    /*
94
    /*
96
     * There is no sense in receiving data that can't hold a single
95
     * There is no sense in receiving data that can't hold a single
97
     * character of path. We won't accept data that exceed certain limits
96
     * character of path. We won't accept data that exceed certain limits
98
     * either.
97
     * either.
99
     */
98
     */
100
    if ((size < FS_NAME_MAXLEN + 1) ||
99
    if ((size < FS_NAME_MAXLEN + 1) ||
101
        (size > FS_NAME_MAXLEN + MAX_PATH_LEN)) {
100
        (size > FS_NAME_MAXLEN + MAX_PATH_LEN)) {
102
        ipc_answer_fast_0(callid, EINVAL);
101
        ipc_answer_0(callid, EINVAL);
103
        ipc_answer_fast_0(rid, EINVAL);
102
        ipc_answer_0(rid, EINVAL);
104
        return;
103
        return;
105
    }
104
    }
106
 
105
 
107
    /*
106
    /*
108
     * Allocate buffer for the data being received.
107
     * Allocate buffer for the data being received.
109
     */
108
     */
110
    uint8_t *buf;
109
    uint8_t *buf;
111
    buf = malloc(size);
110
    buf = malloc(size);
112
    if (!buf) {
111
    if (!buf) {
113
        ipc_answer_fast_0(callid, ENOMEM);
112
        ipc_answer_0(callid, ENOMEM);
114
        ipc_answer_fast_0(rid, ENOMEM);
113
        ipc_answer_0(rid, ENOMEM);
115
        return;
114
        return;
116
    }
115
    }
117
 
116
 
118
    /*
117
    /*
119
     * Deliver the data.
118
     * Deliver the data.
120
     */
119
     */
121
    (void) ipc_data_deliver(callid, &call, buf, size);
120
    (void) ipc_data_deliver(callid, buf, size);
122
 
121
 
123
    char fs_name[FS_NAME_MAXLEN + 1];
122
    char fs_name[FS_NAME_MAXLEN + 1];
124
    memcpy(fs_name, buf, FS_NAME_MAXLEN);
123
    memcpy(fs_name, buf, FS_NAME_MAXLEN);
125
    fs_name[FS_NAME_MAXLEN] = '\0';
124
    fs_name[FS_NAME_MAXLEN] = '\0';
126
 
125
 
Line 129... Line 128...
129
     * This will also give us its file system handle.
128
     * This will also give us its file system handle.
130
     */
129
     */
131
    int fs_handle = fs_name_to_handle(fs_name, true);
130
    int fs_handle = fs_name_to_handle(fs_name, true);
132
    if (!fs_handle) {
131
    if (!fs_handle) {
133
        free(buf);
132
        free(buf);
134
        ipc_answer_fast_0(rid, ENOENT);
133
        ipc_answer_0(rid, ENOENT);
135
        return;
134
        return;
136
    }
135
    }
137
 
136
 
138
    /*
137
    /*
139
     * Lookup the root node of the filesystem being mounted.
138
     * Lookup the root node of the filesystem being mounted.
Line 144... Line 143...
144
    int rc;
143
    int rc;
145
    vfs_triplet_t mounted_root;
144
    vfs_triplet_t mounted_root;
146
    rc = lookup_root(fs_handle, dev_handle, &mounted_root);
145
    rc = lookup_root(fs_handle, dev_handle, &mounted_root);
147
    if (rc != EOK) {
146
    if (rc != EOK) {
148
        free(buf);
147
        free(buf);
149
        ipc_answer_fast_0(rid, rc);
148
        ipc_answer_0(rid, rc);
150
        return;
149
        return;
151
    }
150
    }
152
    vfs_node_t *mr_node = vfs_node_get(&mounted_root);
151
    vfs_node_t *mr_node = vfs_node_get(&mounted_root);
153
    if (!mr_node) {
152
    if (!mr_node) {
154
        free(buf);
153
        free(buf);
155
        ipc_answer_fast_0(rid, ENOMEM);
154
        ipc_answer_0(rid, ENOMEM);
156
        return;
155
        return;
157
    }
156
    }
158
 
157
 
159
    /*
158
    /*
160
     * Finally, we need to resolve the path to the mountpoint.
159
     * Finally, we need to resolve the path to the mountpoint.
Line 174... Line 173...
174
             */
173
             */
175
            futex_up(&unlink_futex);
174
            futex_up(&unlink_futex);
176
            futex_up(&rootfs_futex);
175
            futex_up(&rootfs_futex);
177
            vfs_node_put(mr_node);  /* failed -> drop reference */
176
            vfs_node_put(mr_node);  /* failed -> drop reference */
178
            free(buf);
177
            free(buf);
179
            ipc_answer_fast_0(rid, rc);
178
            ipc_answer_0(rid, rc);
180
            return;
179
            return;
181
        }
180
        }
182
        mp_node = vfs_node_get(&mp);
181
        mp_node = vfs_node_get(&mp);
183
        if (!mp_node) {
182
        if (!mp_node) {
184
            futex_up(&unlink_futex);
183
            futex_up(&unlink_futex);
185
            futex_up(&rootfs_futex);
184
            futex_up(&rootfs_futex);
186
            vfs_node_put(mr_node);  /* failed -> drop reference */
185
            vfs_node_put(mr_node);  /* failed -> drop reference */
187
            free(buf);
186
            free(buf);
188
            ipc_answer_fast_0(rid, ENOMEM);
187
            ipc_answer_0(rid, ENOMEM);
189
            return;
188
            return;
190
        }
189
        }
191
        /*
190
        /*
192
         * Now we hold a reference to mp_node.
191
         * Now we hold a reference to mp_node.
193
         * It will be dropped upon the corresponding VFS_UNMOUNT.
192
         * It will be dropped upon the corresponding VFS_UNMOUNT.
Line 204... Line 203...
204
             * For this simple, but important case, we are done.
203
             * For this simple, but important case, we are done.
205
             */
204
             */
206
            rootfs = mounted_root;
205
            rootfs = mounted_root;
207
            futex_up(&rootfs_futex);
206
            futex_up(&rootfs_futex);
208
            free(buf);
207
            free(buf);
209
            ipc_answer_fast_0(rid, EOK);
208
            ipc_answer_0(rid, EOK);
210
            return;
209
            return;
211
        } else {
210
        } else {
212
            /*
211
            /*
213
             * We can't resolve this without the root filesystem
212
             * We can't resolve this without the root filesystem
214
             * being mounted first.
213
             * being mounted first.
215
             */
214
             */
216
            futex_up(&rootfs_futex);
215
            futex_up(&rootfs_futex);
217
            free(buf);
216
            free(buf);
218
            vfs_node_put(mr_node);  /* failed -> drop reference */
217
            vfs_node_put(mr_node);  /* failed -> drop reference */
219
            ipc_answer_fast_0(rid, ENOENT);
218
            ipc_answer_0(rid, ENOENT);
220
            return;
219
            return;
221
        }
220
        }
222
    }
221
    }
223
    futex_up(&rootfs_futex);
222
    futex_up(&rootfs_futex);
224
   
223
   
Line 252... Line 251...
252
        if (mp_node)
251
        if (mp_node)
253
            vfs_node_put(mp_node);
252
            vfs_node_put(mp_node);
254
    }
253
    }
255
   
254
   
256
    if (rc2 == EOK)
255
    if (rc2 == EOK)
257
        ipc_answer_fast_0(rid, rc1);
256
        ipc_answer_0(rid, rc1);
258
    else if (rc1 == EOK)
257
    else if (rc1 == EOK)
259
        ipc_answer_fast_0(rid, rc2);
258
        ipc_answer_0(rid, rc2);
260
    else
259
    else
261
        ipc_answer_fast_0(rid, rc1);
260
        ipc_answer_0(rid, rc1);
262
}
261
}
263
 
262
 
264
/**
263
/**
265
 * @}
264
 * @}
266
 */
265
 */