src/server/daemon/vfs.c

changeset 58
66c22e54aa90
parent 57
b3a89736b23e
child 59
ab25c0a231d0
equal deleted inserted replaced
57:b3a89736b23e 58:66c22e54aa90
94 if(sys_acl_check(ctx, access_mask, &uid, &gid)) { 94 if(sys_acl_check(ctx, access_mask, &uid, &gid)) {
95 return NULL; 95 return NULL;
96 } 96 }
97 97
98 // open file 98 // open file
99 int fd = open(path, oflags); 99 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
100 int fd = open(path, oflags, mode);
100 if(fd == -1) { 101 if(fd == -1) {
101 if(ctx) { 102 if(ctx) {
102 ctx->vfs_errno = errno; 103 ctx->vfs_errno = errno;
103 sys_set_error_status(ctx); 104 sys_set_error_status(ctx);
104 } 105 }
408 } 409 }
409 410
410 int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { 411 int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) {
411 struct dirent *e = readdir(dir->data); 412 struct dirent *e = readdir(dir->data);
412 if(e) { 413 if(e) {
413 entry->name = e->d_name; 414 char *name = e->d_name;
414 if(getstat) { 415 if(!strcmp(name, ".") || !strcmp(name, "..")) {
415 // TODO: check ACLs again for new path 416 return sys_dir_read(dir, entry, getstat);
416 if(fstatat(dir->fd, e->d_name, &entry->stat, 0)) { 417 } else {
417 entry->stat_errno = errno; 418 entry->name = name;
419 if(getstat) {
420 // TODO: check ACLs again for new path
421 if(fstatat(dir->fd, e->d_name, &entry->stat, 0)) {
422 entry->stat_errno = errno;
423 }
424 entry->stat_extra = NULL;
418 } 425 }
419 } 426 return 1;
420 return 1; 427 }
421 } else { 428 } else {
422 return 0; 429 return 0;
423 } 430 }
424 } 431 }
425 432
433 } 440 }
434 441
435 int sys_unlink(VFSContext *ctx, char *path) { 442 int sys_unlink(VFSContext *ctx, char *path) {
436 return unlink(path); 443 return unlink(path);
437 } 444 }
445
446 /* public file api */
447
448 NSAPI_PUBLIC int system_fread(SYS_FILE fd, void *buf, int nbyte) {
449 return fd->io->read(fd, buf, nbyte);
450 }
451
452 NSAPI_PUBLIC int system_fwrite(SYS_FILE fd, const void *buf, int nbyte) {
453 return fd->io->write(fd, buf, nbyte);
454 }
455
456 NSAPI_PUBLIC int system_fclose(SYS_FILE fd) {
457 vfs_close(fd);
458 return 0;
459 }

mercurial