Changeset 72bde81 in mainline
- Timestamp:
- 2008-01-27T14:59:32Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2db4ac8
- Parents:
- 1fe186f
- Location:
- uspace
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/vfs/vfs1.c
r1fe186f r72bde81 31 31 #include <stdlib.h> 32 32 #include <string.h> 33 #include <sys/types.h>34 33 #include <vfs.h> 35 34 #include <unistd.h> 36 35 #include <fcntl.h> 37 36 #include <dirent.h> 37 #include <sys/types.h> 38 #include <sys/stat.h> 38 39 #include "../tester.h" 39 40 … … 43 44 return "Mount failed.\n"; 44 45 46 if (mkdir("/mydir", 0) != 0) 47 return "mkdir() failed.\n"; 45 48 46 49 DIR *dirp; -
uspace/lib/libc/generic/vfs.c
r1fe186f r72bde81 38 38 #include <dirent.h> 39 39 #include <fcntl.h> 40 #include <sys/stat.h> 41 #include <sys/types.h> 40 42 #include <ipc/ipc.h> 41 43 #include <ipc/services.h> … … 132 134 } 133 135 136 int close(int fildes) 137 { 138 return 0; /* TODO */ 139 } 140 134 141 ssize_t read(int fildes, void *buf, size_t nbyte) 135 142 { … … 210 217 off_t newoffs; 211 218 rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, 212 &newoffs);219 (ipcarg_t)&newoffs); 213 220 214 221 async_serialize_end(); … … 275 282 } 276 283 277 int close(int fildes) 278 { 279 return 0; /* TODO */ 284 int mkdir(const char *path, mode_t mode) 285 { 286 int res; 287 ipcarg_t rc; 288 ipc_call_t answer; 289 aid_t req; 290 291 futex_down(&vfs_phone_futex); 292 async_serialize_start(); 293 if (vfs_phone < 0) { 294 res = vfs_connect(); 295 if (res < 0) { 296 async_serialize_end(); 297 futex_up(&vfs_phone_futex); 298 return res; 299 } 300 } 301 req = async_send_1(vfs_phone, VFS_MKDIR, mode, &answer); 302 rc = ipc_data_write_start(vfs_phone, path, strlen(path)); 303 if (rc != EOK) { 304 async_wait_for(req, NULL); 305 async_serialize_end(); 306 futex_up(&vfs_phone_futex); 307 return (int) rc; 308 } 309 async_wait_for(req, &rc); 310 async_serialize_end(); 311 futex_up(&vfs_phone_futex); 312 return EOK; 280 313 } 281 314 -
uspace/lib/libc/include/sys/types.h
r1fe186f r72bde81 41 41 typedef signed long ssize_t; 42 42 typedef long off_t; 43 typedef int mode_t; 43 44 44 45 #endif -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r1fe186f r72bde81 212 212 const char *component, int lflag) 213 213 { 214 return 0; 214 assert(dentry->type == TMPFS_DIRECTORY); 215 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 216 217 tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); 218 if (!node) 219 return 0; 220 size_t len = strlen(component); 221 char *name = malloc(len + 1); 222 if (!name) { 223 free(node); 224 return 0; 225 } 226 strcpy(name, component); 227 228 tmpfs_dentry_initialize(node); 229 node->index = tmpfs_next_index++; 230 node->name = name; 231 node->parent = dentry; 232 if (lflag & L_DIRECTORY) 233 node->type = TMPFS_DIRECTORY; 234 else 235 node->type = TMPFS_FILE; 236 237 /* Insert the new node into the namespace. */ 238 if (dentry->child) { 239 tmpfs_dentry_t *tmp = dentry->child; 240 while (tmp->sibling) 241 tmp = tmp->sibling; 242 tmp->sibling = node; 243 } else { 244 dentry->child = node; 245 } 246 247 /* Insert the new node into the dentry hash table. */ 248 hash_table_insert(&dentries, &node->index, &node->dh_link); 249 return node->index; 215 250 } 216 251 … … 257 292 component[len++] = PLB_GET_CHAR(next); 258 293 next++; /* process next character */ 259 if (next <= last) 294 if (next <= last) 260 295 continue; 261 296 } … … 280 315 unsigned long index = create_node(dcur, 281 316 component, lflag); 282 if (index ) {317 if (index > 0) { 283 318 ipc_answer_4(rid, EOK, 284 319 tmpfs_reg.fs_handle, dev_handle, -
uspace/srv/vfs/vfs.c
r1fe186f r72bde81 106 106 vfs_truncate(callid, &call); 107 107 break; 108 case VFS_UNMOUNT: 109 case VFS_CLOSE: 110 case VFS_UNLINK: 111 case VFS_RENAME: 112 case VFS_OPENDIR: 113 case VFS_READDIR: 114 case VFS_CLOSEDIR: 108 case VFS_MKDIR: 109 vfs_mkdir(callid, &call); 110 break; 115 111 default: 116 112 ipc_answer_0(callid, ENOTSUP); -
uspace/srv/vfs/vfs.h
r1fe186f r72bde81 57 57 VFS_READDIR, 58 58 VFS_CLOSEDIR, 59 VFS_MKDIR, 59 60 VFS_UNLINK, 60 61 VFS_MOUNT, … … 262 263 extern void vfs_seek(ipc_callid_t, ipc_call_t *); 263 264 extern void vfs_truncate(ipc_callid_t, ipc_call_t *); 265 extern void vfs_mkdir(ipc_callid_t, ipc_call_t *); 264 266 265 267 #endif -
uspace/srv/vfs/vfs_lookup.c
r1fe186f r72bde81 58 58 * @param lflag Flags to be used during lookup. 59 59 * @param result Empty structure where the lookup result will be stored. 60 * Can be NULL. 60 61 * @param altroot If non-empty, will be used instead of rootfs as the root 61 62 * of the whole VFS tree. … … 163 164 futex_up(&plb_futex); 164 165 165 if ( rc == EOK) {166 if ((rc == EOK) && result) { 166 167 result->triplet.fs_handle = (int) IPC_GET_ARG1(answer); 167 168 result->triplet.dev_handle = (int) IPC_GET_ARG2(answer); -
uspace/srv/vfs/vfs_ops.c
r1fe186f r72bde81 116 116 } 117 117 118 /* 119 * Deliver the file system name. 120 */ 118 /* Deliver the file system name. */ 121 119 char fs_name[FS_NAME_MAXLEN + 1]; 122 120 (void) ipc_data_write_finalize(callid, fs_name, size); … … 133 131 } 134 132 135 /* 136 * Now, we want the client to send us the mount point. 137 */ 133 /* Now, we want the client to send us the mount point. */ 138 134 if (!ipc_data_write_receive(&callid, &size)) { 139 135 ipc_answer_0(callid, EINVAL); … … 142 138 } 143 139 144 /* 145 * Check whether size is reasonable wrt. the mount point. 146 */ 140 /* Check whether size is reasonable wrt. the mount point. */ 147 141 if (size < 1 || size > MAX_PATH_LEN) { 148 142 ipc_answer_0(callid, EINVAL); … … 150 144 return; 151 145 } 152 /* 153 * Allocate buffer for the mount point data being received. 154 */ 146 /* Allocate buffer for the mount point data being received. */ 155 147 uint8_t *buf; 156 148 buf = malloc(size); … … 161 153 } 162 154 163 /* 164 * Deliver the mount point. 165 */ 155 /* Deliver the mount point. */ 166 156 (void) ipc_data_write_finalize(callid, buf, size); 167 157 … … 187 177 } 188 178 189 /* 190 * Finally, we need to resolve the path to the mountpoint. 191 */ 179 /* Finally, we need to resolve the path to the mountpoint. */ 192 180 vfs_lookup_res_t mp_res; 193 181 futex_down(&rootfs_futex); 194 182 if (rootfs.fs_handle) { 195 /* 196 * We already have the root FS. 197 */ 183 /* We already have the root FS. */ 198 184 rwlock_write_lock(&namespace_rwlock); 199 185 rc = vfs_lookup_internal(buf, size, L_DIRECTORY, &mp_res, 200 186 NULL); 201 187 if (rc != EOK) { 202 /* 203 * The lookup failed for some reason. 204 */ 188 /* The lookup failed for some reason. */ 205 189 rwlock_write_unlock(&namespace_rwlock); 206 190 futex_up(&rootfs_futex); … … 226 210 rwlock_write_unlock(&namespace_rwlock); 227 211 } else { 228 /* 229 * We still don't have the root file system mounted. 230 */ 212 /* We still don't have the root file system mounted. */ 231 213 if ((size == 1) && (buf[0] == '/')) { 232 /* 233 * For this simple, but important case, we are done. 234 */ 214 /* For this simple, but important case, we are done. */ 235 215 rootfs = mr_res.triplet; 236 216 futex_up(&rootfs_futex); … … 348 328 rwlock_read_lock(&namespace_rwlock); 349 329 350 /* 351 * The path is now populated and we can call vfs_lookup_internal(). 352 */ 330 /* The path is now populated and we can call vfs_lookup_internal(). */ 353 331 vfs_lookup_res_t lr; 354 332 rc = vfs_lookup_internal(path, len, lflag, &lr, NULL); … … 360 338 } 361 339 362 /* 363 * Path is no longer needed. 364 */ 340 /** Path is no longer needed. */ 365 341 free(path); 366 342 … … 391 367 vfs_node_put(node); 392 368 393 /* 394 * Success! Return the new file descriptor to the client. 395 */ 369 /* Success! Return the new file descriptor to the client. */ 396 370 ipc_answer_1(rid, EOK, fd); 397 371 } … … 412 386 int fd = IPC_GET_ARG1(*request); 413 387 414 /* 415 * Lookup the file structure corresponding to the file descriptor. 416 */ 388 /* Lookup the file structure corresponding to the file descriptor. */ 417 389 vfs_file_t *file = vfs_file_get(fd); 418 390 if (!file) { … … 454 426 int fs_phone = vfs_grab_phone(file->node->fs_handle); 455 427 456 /* 457 * Make a VFS_READ/VFS_WRITE request at the destination FS server. 458 */ 428 /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */ 459 429 aid_t msg; 460 430 ipc_call_t answer; … … 472 442 vfs_release_phone(fs_phone); 473 443 474 /* 475 * Wait for reply from the FS server. 476 */ 444 /* Wait for reply from the FS server. */ 477 445 ipcarg_t rc; 478 446 async_wait_for(msg, &rc); 479 447 size_t bytes = IPC_GET_ARG1(answer); 480 448 481 /* 482 * Unlock the VFS node. 483 */ 449 /* Unlock the VFS node. */ 484 450 if (read) 485 451 rwlock_read_unlock(&file->node->contents_rwlock); … … 490 456 } 491 457 492 /* 493 * Update the position pointer and unlock the open file. 494 */ 458 /* Update the position pointer and unlock the open file. */ 495 459 file->pos += bytes; 496 460 futex_up(&file->lock); … … 520 484 521 485 522 /* 523 * Lookup the file structure corresponding to the file descriptor. 524 */ 486 /* Lookup the file structure corresponding to the file descriptor. */ 525 487 vfs_file_t *file = vfs_file_get(fd); 526 488 if (!file) { … … 582 544 rwlock_write_lock(&file->node->contents_rwlock); 583 545 int fs_phone = vfs_grab_phone(file->node->fs_handle); 584 rc = async_req_3_0(fs_phone, VFS_TRUNCATE, (ipcarg_t)file->node->dev_handle, 585 (ipcarg_t)file->node->index, (ipcarg_t)size); 546 rc = async_req_3_0(fs_phone, VFS_TRUNCATE, 547 (ipcarg_t)file->node->dev_handle, (ipcarg_t)file->node->index, 548 (ipcarg_t)size); 586 549 vfs_release_phone(fs_phone); 587 550 if (rc == EOK) … … 593 556 } 594 557 558 void vfs_mkdir(ipc_callid_t rid, ipc_call_t *request) 559 { 560 int mode = IPC_GET_ARG1(*request); 561 size_t len; 562 563 ipc_callid_t callid; 564 565 if (!ipc_data_write_receive(&callid, &len)) { 566 ipc_answer_0(callid, EINVAL); 567 ipc_answer_0(rid, EINVAL); 568 return; 569 } 570 571 /* 572 * Now we are on the verge of accepting the path. 573 * 574 * There is one optimization we could do in the future: copy the path 575 * directly into the PLB using some kind of a callback. 576 */ 577 char *path = malloc(len); 578 579 if (!path) { 580 ipc_answer_0(callid, ENOMEM); 581 ipc_answer_0(rid, ENOMEM); 582 return; 583 } 584 585 int rc; 586 if ((rc = ipc_data_write_finalize(callid, path, len))) { 587 ipc_answer_0(rid, rc); 588 free(path); 589 return; 590 } 591 592 rwlock_write_lock(&namespace_rwlock); 593 int lflag = L_DIRECTORY | L_CREATE | L_EXCLUSIVE; 594 rc = vfs_lookup_internal(path, len, lflag, NULL, NULL); 595 rwlock_write_unlock(&namespace_rwlock); 596 free(path); 597 ipc_answer_0(rid, rc); 598 } 599 595 600 /** 596 601 * @}
Note:
See TracChangeset
for help on using the changeset viewer.