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

Function SysLink

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

Source from the content-addressed store, hash-verified

395}
396
397long SysLink(regs64_t* r){
398 const char* oldpath = (const char*)SC_ARG0(r);
399 const char* newpath = (const char*)SC_ARG1(r);
400
401 process_t* proc = Scheduler::GetCurrentProcess();
402
403 if(!(Memory::CheckUsermodePointer(SC_ARG0(r), 1, proc->addressSpace) && Memory::CheckUsermodePointer(SC_ARG1(r), 1, proc->addressSpace))){
404 Log::Warning("sys_link: Invalid path pointer");
405 return -EFAULT;
406 }
407
408 FsNode* file = fs::ResolvePath(oldpath);
409 if(!file){
410 Log::Warning("sys_link: Could not resolve path: %s", oldpath);
411 return -ENOENT;
412 }
413
414 FsNode* parentDirectory = fs::ResolveParent(newpath, proc->workingDir);
415 char* linkName = fs::BaseName(newpath);
416
417 Log::Info("sys_link: Attempting to create link %s at path %s", linkName, newpath);
418
419 if(!parentDirectory){
420 Log::Warning("sys_link: Could not resolve path: %s", newpath);
421 return -ENOENT;
422 }
423
424 if((parentDirectory->flags & FS_NODE_TYPE) != FS_NODE_DIRECTORY){
425 Log::Warning("sys_link: Could not resolve path: Parent not a directory: %s", newpath);
426 return -ENOTDIR;
427 }
428
429 DirectoryEntry entry;
430 strcpy(entry.name, linkName);
431 return parentDirectory->Link(file, &entry);
432}
433
434long SysUnlink(regs64_t* r){
435 const char* path = (const char*)SC_ARG0(r);

Callers

nothing calls this directly

Calls 9

GetCurrentProcessFunction · 0.85
CheckUsermodePointerFunction · 0.85
WarningFunction · 0.85
ResolvePathFunction · 0.85
ResolveParentFunction · 0.85
BaseNameFunction · 0.85
InfoFunction · 0.85
strcpyFunction · 0.85
LinkMethod · 0.45

Tested by

no test coverage detected