MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / SysFStat

Function SysFStat

Kernel/src/arch/x86_64/syscalls.cpp:529–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

527}
528
529long SysFStat(regs64_t* r){
530 stat_t* stat = (stat_t*)SC_ARG0(r);
531 int fd = SC_ARG1(r);
532
533 if(fd >= static_cast<int>(Scheduler::GetCurrentProcess()->fileDescriptors.get_length())){
534 Log::Warning("sys_fstat: Invalid File Descriptor, %d", fd);
535 return -EBADF;
536 }
537 FsNode* node = Scheduler::GetCurrentProcess()->fileDescriptors.get_at(fd)->node;
538 if(!node){
539 Log::Warning("sys_fstat: Invalid File Descriptor, %d", fd);
540 return -EBADF;
541 }
542
543 stat->st_dev = 0;
544 stat->st_ino = node->inode;
545 stat->st_mode = 0;
546
547 if(node->flags == FS_NODE_DIRECTORY) stat->st_mode |= S_IFDIR;
548 if(node->flags == FS_NODE_FILE) stat->st_mode |= S_IFREG;
549 if(node->flags == FS_NODE_BLKDEVICE) stat->st_mode |= S_IFBLK;
550 if(node->flags == FS_NODE_CHARDEVICE) stat->st_mode |= S_IFCHR;
551 if(node->flags == FS_NODE_SYMLINK) stat->st_mode |= S_IFLNK;
552 if(node->flags == FS_NODE_SOCKET) stat->st_mode |= S_IFSOCK;
553
554 stat->st_nlink = 0;
555 stat->st_uid = node->uid;
556 stat->st_gid = 0;
557 stat->st_rdev = 0;
558 stat->st_size = node->size;
559 stat->st_blksize = 0;
560 stat->st_blocks = 0;
561
562 return 0;
563}
564
565long SysStat(regs64_t* r){
566 stat_t* stat = (stat_t*)SC_ARG0(r);

Callers

nothing calls this directly

Calls 4

GetCurrentProcessFunction · 0.85
WarningFunction · 0.85
get_atMethod · 0.80
get_lengthMethod · 0.45

Tested by

no test coverage detected