SYS_FINFO, // 75 - Get file information
SYS_SEEK, // 76 - Seek to a new position in the file
SYS_TELL, // 77 - Return the current file position
+ SYS_CHDIR, // 78 - Change current directory
+ SYS_GETCWD, // 79 - Get current directory
NUM_SYSCALLS,
SYS_DEBUG = 0x100 // 0x100 - Print a debug string
};
"","","","","SYS_OPEN","SYS_REOPEN",
"SYS_CLOSE","SYS_READ","SYS_WRITE","SYS_IOCTL","SYS_READDIR","SYS_MKDIR",
"SYS_SYMLINK","SYS_GETACL","SYS_SETACL","SYS_FINFO","SYS_SEEK","SYS_TELL",
- ""
+ "SYS_CHDIR","SYS_GETCWD",""
};
#endif
%define SYS_FINFO 75 ; Get file information
%define SYS_SEEK 76 ; Seek to a new position in the file
%define SYS_TELL 77 ; Return the current file position
+%define SYS_CHDIR 78 ; Change current directory
+%define SYS_GETCWD 79 ; Get current directory
extern Uint Binary_Load(char *file, Uint *entryPoint);
extern int VFS_FInfo(int FD, void *Dest, int MaxACLs);
extern int VFS_GetACL(int FD, void *Dest);
+extern int VFS_ChDir(char *Dest);
extern int Threads_SetName(char *NewName);
extern int Threads_GetPID();
extern int Threads_GetTID();
extern int Threads_GetUID();
extern int Threads_GetGID();
+// === PROTOTYPES ===
+ int Syscall_ValidString(Uint Addr);
+ int Syscall_Valid(int Size, Uint Addr);
+
// === CODE ===
// TODO: Do sanity checking on arguments, ATM the user can really fuck with the kernel
void SyscallHandler(tSyscallRegs *Regs)
LOG("Syscall %s", cSYSCALL_NAMES[Regs->Num]);
LOG("Arg1: 0x%x, Arg2: 0x%x, Arg3: 0x%x", Regs->Arg1, Regs->Arg2, Regs->Arg3);
#endif
+
switch(Regs->Num)
{
// -- Exit the current thread
case SYS_FINFO:
ret = VFS_FInfo( Regs->Arg1, (void*)Regs->Arg2, Regs->Arg3 );
break;
-
+
+ // Get ACL Value
case SYS_GETACL:
+ if( !Syscall_Valid(8, Regs->Arg1) ) {
+ err = -EINVAL;
+ ret = -1;
+ break;
+ }
ret = VFS_GetACL( Regs->Arg1, (void*)Regs->Arg2 );
break;
-
+
+ // Read Directory
case SYS_READDIR:
+ if( !Syscall_ValidString(Regs->Arg2) ) {
+ err = -EINVAL;
+ ret = -1;
+ break;
+ }
ret = VFS_ReadDir( Regs->Arg1, (void*)Regs->Arg2 );
break;
+ // Change Directory
+ case SYS_CHDIR:
+ if( !Syscall_ValidString(Regs->Arg1) ) {
+ err = -EINVAL;
+ ret = -1;
+ break;
+ }
+ ret = VFS_ChDir( (void*)Regs->Arg1 );
+ break;
+
// -- Debug
case SYS_DEBUG:
Log((char*)Regs->Arg1,
#endif
}
+/**
+ * \fn int Syscall_ValidString(Uint Addr)
+ * \brief Checks if a memory address contains a valid string
+ */
+int Syscall_ValidString(Uint Addr)
+{
+ // Check 1st page
+ if(!MM_GetPhysAddr(Addr)) return 0;
+
+ // Traverse String
+ while(*(char*)Addr)
+ {
+ if(!MM_GetPhysAddr(Addr)) return 0;
+ // Increment string pointer
+ Addr ++;
+ }
+
+ return 1;
+}
+
+/**
+ * \fn int Syscall_Valid(int Size, Uint Addr)
+ * \brief Checks if a memory address is valid
+ */
+int Syscall_Valid(int Size, Uint Addr)
+{
+ while(Size--)
+ {
+ if(!MM_GetPhysAddr(Addr)) return 0;
+ Addr ++;
+ }
+ return 1;
+}
SYS_FINFO Get file information
SYS_SEEK Seek to a new position in the file
SYS_TELL Return the current file position
+SYS_CHDIR Change current directory
+SYS_GETCWD Get current directory
h->Node = NULL;
}
+/**
+ * \fn int VFS_ChDir(char *New)
+ * \brief Change current working directory
+ */
+int VFS_ChDir(char *New)
+{
+ char *buf;
+ tVFS_Node *node;
+
+ // Create Absolute
+ buf = VFS_GetAbsPath(New);
+ if(buf == NULL) return -1;
+
+ // Check if path is valid
+ node = VFS_ParsePath(buf, NULL);
+ if(!node) return -1;
+
+ // Check if is a directory
+ if( !(node->Flags & VFS_FFLAG_DIRECTORY) ) {
+ if(node->Close) node->Close(node);
+ return -1;
+ }
+ // Close node
+ if(node->Close) node->Close(node);
+
+ // Copy over
+ strcpy(buf, New);
+
+ // Free old and set new
+ free( CFGPTR(CFG_VFS_CWD) );
+ CFGPTR(CFG_VFS_CWD) = buf;
+
+ return 1;
+}
+
/**
* \fn tVFS_Handle *VFS_GetHandle(int FD)
* \brief Gets a pointer to the handle information structure
free(gsCurrentDirectory);\r
gsCurrentDirectory = malloc(strlen(tmpPath)+1);\r
strcpy(gsCurrentDirectory, tmpPath);\r
+ \r
+ // Register change with kernel\r
+ chdir( gsCurrentDirectory );\r
}\r
\r
/**\r
int clone(int flags, void *stack);
int execve(char *path, char **argv, char **envp);
// --- VFS ---
+ int chdir(char *dir);
int open(char *path, int flags);
int reopen(int fd, char *path, int flags);
void close(int fd);