asst3-Virtual Memory Translation/kern/syscall/file_syscalls.c
int
sys_open(const_userptr_t upath, int flags, mode_t mode, int *retval)
{
	const int allflags =
		O_ACCMODE | O_CREAT | O_EXCL | O_TRUNC | O_APPEND | O_NOCTTY;

	char *kpath;
	struct openfile *file;
	int result;

	if ((flags & allflags) != flags) {
		/* unknown flags were set */
		return EINVAL;
	}

	kpath = kmalloc(PATH_MAX);
	if (kpath == NULL) {
		return ENOMEM;
	}

	/* Get the pathname. */
	result = copyinstr(upath, kpath, PATH_MAX, NULL);
	if (result) {
		kfree(kpath);
		return result;
	}

	/*
	 * Open the file. Code lower down (in vfs_open) checks that
	 * flags & O_ACCMODE is a valid value.
	 */
	result = openfile_open(kpath, flags, mode, &file);
	if (result) {
		kfree(kpath);
		return result;
	}
	kfree(kpath);

	/*
	 * Place the file in our process's file table, which gives us
	 * the result file descriptor.
	 */
	result = filetable_place(curproc->p_filetable, file, retval);
	if (result) {
		openfile_decref(file);
		return result;
	}

	return 0;
}
/*
 * open() - get the path with copyinstr, then use openfile_open and
 * filetable_place to do the real work.
 */
get the path with copyinstr, then use openfile_open and
filetable_place to do the real work.
get the path with copyinstr then use openfile_open and filetable_place to do the real work .
int
sys_open(const_userptr_t upath, int flags, mode_t mode, int *retval)
{
	const int allflags =
		O_ACCMODE | O_CREAT | O_EXCL | O_TRUNC | O_APPEND | O_NOCTTY;
	char *kpath;
	struct openfile *file;
	int result;
	if ((flags & allflags) != flags) {
		return EINVAL;
	}
	kpath = kmalloc(PATH_MAX);
	if (kpath == NULL) {
		return ENOMEM;
	}
	result = copyinstr(upath, kpath, PATH_MAX, NULL);
	if (result) {
		kfree(kpath);
		return result;
	}
	result = openfile_open(kpath, flags, mode, &file);
	if (result) {
		kfree(kpath);
		return result;
	}
	kfree(kpath);
	result = filetable_place(curproc->p_filetable, file, retval);
	if (result) {
		openfile_decref(file);
		return result;
	}
	return 0;
}
int sys_open ( const_userptr_t upath , int flags , mode_t mode , int * retval ) { const int allflags = O_ACCMODE | O_CREAT | O_EXCL | O_TRUNC | O_APPEND | O_NOCTTY ; char * kpath ; struct openfile * file ; int result ; if ( ( flags & allflags ) != flags ) { return EINVAL ; } kpath = kmalloc ( PATH_MAX ) ; if ( kpath == NULL ) { return ENOMEM ; } result = copyinstr ( upath , kpath , PATH_MAX , NULL ) ; if ( result ) { kfree ( kpath ) ; return result ; } result = openfile_open ( kpath , flags , mode , & file ) ; if ( result ) { kfree ( kpath ) ; return result ; } kfree ( kpath ) ; result = filetable_place ( curproc -> p_filetable , file , retval ) ; if ( result ) { openfile_decref ( file ) ; return result ; } return 0 ; }
open() - get the path with copyinstr, then use openfile_open and
 filetable_place to do the real work.
open () - get the path with copyinstr then use openfile_open and filetable_place to do the real work .
/* unknown flags were set */ /* Get the pathname. */ /*
	 * Open the file. Code lower down (in vfs_open) checks that
	 * flags & O_ACCMODE is a valid value.
	 */ /*
	 * Place the file in our process's file table, which gives us
	 * the result file descriptor.
	 */