2001-08-29 19:05:27 +00:00
|
|
|
/* $OpenBSD: linux_getcwd.c,v 1.2 2001/05/16 12:50:21 ho Exp $ */
|
|
|
|
/* $NetBSD: vfs_getcwd.c,v 1.3.2.3 1999/07/11 10:24:09 sommerfeld Exp $ */
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
2015-04-23 08:41:50 +00:00
|
|
|
* Copyright (c) 2015 The FreeBSD Foundation
|
2001-08-29 19:05:27 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Bill Sommerfeld.
|
|
|
|
*
|
2015-04-23 08:41:50 +00:00
|
|
|
* Portions of this software were developed by Edward Tomasz Napierala
|
|
|
|
* under sponsorship from the FreeBSD Foundation.
|
|
|
|
*
|
2001-08-29 19:05:27 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2003-06-10 21:29:12 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2006-03-19 11:10:33 +00:00
|
|
|
#include "opt_compat.h"
|
2001-08-29 19:05:27 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2002-09-02 22:46:05 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
2001-08-29 19:05:27 +00:00
|
|
|
#include <sys/proc.h>
|
2003-03-20 10:40:45 +00:00
|
|
|
#include <sys/malloc.h>
|
2001-08-29 19:05:27 +00:00
|
|
|
|
2005-01-14 04:44:56 +00:00
|
|
|
#ifdef COMPAT_LINUX32
|
2004-08-16 07:28:16 +00:00
|
|
|
#include <machine/../linux32/linux.h>
|
|
|
|
#include <machine/../linux32/linux32_proto.h>
|
2005-01-14 04:44:56 +00:00
|
|
|
#else
|
|
|
|
#include <machine/../linux/linux.h>
|
|
|
|
#include <machine/../linux/linux_proto.h>
|
2004-08-16 07:28:16 +00:00
|
|
|
#endif
|
2015-04-21 13:55:24 +00:00
|
|
|
#include <compat/linux/linux_misc.h>
|
2003-03-20 10:40:45 +00:00
|
|
|
#include <compat/linux/linux_util.h>
|
|
|
|
|
2001-08-29 19:05:27 +00:00
|
|
|
/*
|
|
|
|
* Find pathname of process's current directory.
|
|
|
|
*/
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
linux_getcwd(struct thread *td, struct linux_getcwd_args *args)
|
2001-08-29 19:05:27 +00:00
|
|
|
{
|
2015-04-23 08:41:50 +00:00
|
|
|
char *path;
|
|
|
|
int error, lenused;
|
2003-03-20 10:40:45 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2006-11-18 13:31:03 +00:00
|
|
|
if (ldebug(getcwd))
|
2006-11-18 17:27:39 +00:00
|
|
|
printf(ARGS(getcwd, "%p, %ld"), args->buf, (long)args->bufsize);
|
2003-03-20 10:40:45 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-23 08:41:50 +00:00
|
|
|
/*
|
|
|
|
* Linux returns ERANGE instead of EINVAL.
|
|
|
|
*/
|
|
|
|
if (args->bufsize < 2)
|
|
|
|
return (ERANGE);
|
2003-03-20 10:40:45 +00:00
|
|
|
|
2015-05-24 16:14:41 +00:00
|
|
|
path = malloc(LINUX_PATH_MAX, M_LINUX, M_WAITOK);
|
2003-03-20 10:40:45 +00:00
|
|
|
|
2015-04-23 08:41:50 +00:00
|
|
|
error = kern___getcwd(td, path, UIO_SYSSPACE, args->bufsize,
|
|
|
|
LINUX_PATH_MAX);
|
|
|
|
if (error == 0) {
|
2003-03-20 10:40:45 +00:00
|
|
|
lenused = strlen(path) + 1;
|
2015-04-23 08:41:50 +00:00
|
|
|
error = copyout(path, args->buf, lenused);
|
|
|
|
if (error == 0)
|
2003-03-20 10:40:45 +00:00
|
|
|
td->td_retval[0] = lenused;
|
|
|
|
}
|
2015-04-23 08:41:50 +00:00
|
|
|
|
2015-05-24 16:14:41 +00:00
|
|
|
free(path, M_LINUX);
|
2003-03-20 10:40:45 +00:00
|
|
|
return (error);
|
2001-08-29 19:05:27 +00:00
|
|
|
}
|