hurd: Add open.
* include/fcntl.h (O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_APPEND, O_TRUNC)[__GNU__]: Specialize for GNU. * lib/gnu/dir-lookup.c: New file. * lib/stdio/fopen.c (fopen): Use O_RDONLY. * lib/tests/posix/50-open-read.c (main): Likewise. * lib/tests/stdio/90-fseek.c (main): Likewise. * include/gnu/syscall.h (SYS__dir_lookup): New value. * lib/gnu/_open3.c: New file. * build-aux/configure-lib.sh (libc_SOURCES): Build them.
This commit is contained in:
parent
67d82a6de5
commit
89945751d9
|
@ -157,7 +157,9 @@ lib/string/strncmp.c
|
|||
|
||||
if test $mes_kernel = gnu; then
|
||||
libc_SOURCES="$libc_SOURCES
|
||||
lib/gnu/_open3.c
|
||||
lib/gnu/_read.c
|
||||
lib/gnu/dir-lookup.c
|
||||
lib/gnu/fd-read.c
|
||||
lib/gnu/io-read.c
|
||||
lib/stub/access.c
|
||||
|
@ -171,7 +173,6 @@ lib/stub/fork.c
|
|||
lib/stub/_getcwd.c
|
||||
lib/stub/gettimeofday.c
|
||||
lib/stub/ioctl.c
|
||||
lib/stub/_open3.c
|
||||
lib/stub/time.c
|
||||
lib/stub/unlink.c
|
||||
lib/stub/waitpid.c
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#else // ! SYSTEM_LIBC
|
||||
|
||||
// *INDENT-OFF*
|
||||
#if __linux__
|
||||
#define O_RDONLY 0
|
||||
#define O_WRONLY 1
|
||||
#define O_RDWR 2
|
||||
|
@ -38,6 +39,16 @@
|
|||
#define O_TRUNC 0x200
|
||||
#define O_APPEND 0x400
|
||||
#define O_DIRECTORY 0x10000
|
||||
#elif __GNU__
|
||||
#define O_RDONLY 1
|
||||
#define O_WRONLY 2
|
||||
#define O_RDWR 3
|
||||
#define O_CREAT 0x10
|
||||
#define O_APPEND 0x100
|
||||
#define O_TRUNC 0x10000
|
||||
#else
|
||||
#error platform not supported
|
||||
#endif
|
||||
// *INDENT-ON*
|
||||
|
||||
#define FD_CLOEXEC 1
|
||||
|
|
|
@ -38,6 +38,12 @@ enum
|
|||
SYS__task_get_special_port = 2058,
|
||||
};
|
||||
|
||||
// hurd/fsys.defs
|
||||
enum
|
||||
{
|
||||
SYS__dir_lookup = 20018,
|
||||
};
|
||||
|
||||
// hurd/io.defs
|
||||
enum
|
||||
{
|
||||
|
|
48
lib/gnu/_open3.c
Normal file
48
lib/gnu/_open3.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Commentary:
|
||||
Inspired by implementation in GNU C Library:
|
||||
__hurd_file_name_lookup, __hurd_file_name_lookup_retry
|
||||
Copyright (C) 1992-2016 Free Software Foundation, Inc.
|
||||
*/
|
||||
|
||||
#include <gnu/hurd.h>
|
||||
#include <gnu/hurd-types.h>
|
||||
#include <gnu/syscall.h>
|
||||
#include <mach/mach-init.h>
|
||||
|
||||
int
|
||||
_open3 (char const *file_name, int flags, int mode)
|
||||
{
|
||||
mach_port_t port;
|
||||
int do_retry;
|
||||
char retry_name[1024];
|
||||
int start_dir = (file_name[0] == '/') ? INIT_PORT_CRDIR : INIT_PORT_CWDIR;
|
||||
mach_port_t start_port = _hurd_startup_data.portarray[start_dir];
|
||||
while (file_name[0] == '/')
|
||||
file_name++;
|
||||
error_t e = __dir_lookup (start_port, file_name, flags, mode, &do_retry, retry_name, &port);
|
||||
if (e)
|
||||
return -1;
|
||||
int fd = _hurd_dtable_count++;
|
||||
_hurd_dtable[fd] = port;
|
||||
return fd;
|
||||
}
|
76
lib/gnu/dir-lookup.c
Normal file
76
lib/gnu/dir-lookup.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* GNU Mes is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gnu/syscall.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
struct mach_msg_string_int_int
|
||||
{
|
||||
mach_msg_header_t header;
|
||||
mach_msg_type_t type_one; string_t one;
|
||||
mach_msg_type_t type_two; int two;
|
||||
mach_msg_type_t type_three; int three;
|
||||
};
|
||||
|
||||
struct mach_msg_int_int_string_int
|
||||
{
|
||||
mach_msg_header_t header;
|
||||
mach_msg_type_t type_one; int one;
|
||||
mach_msg_type_t type_two; int two;
|
||||
mach_msg_type_t type_three; string_t three;
|
||||
mach_msg_type_t type_four; int four;
|
||||
};
|
||||
|
||||
mach_msg_type_t mach_msg_type_file_name =
|
||||
{
|
||||
/* msgt_name = */ (unsigned char) MACH_MSG_TYPE_STRING_C,
|
||||
/* msgt_size = */ 8,
|
||||
/* msgt_number = */ 1024,
|
||||
/* msgt_inline = */ 1,
|
||||
/* msgt_longform = */ 0,
|
||||
/* msgt_deallocate = */ 0,
|
||||
/* msgt_unused = */ 0
|
||||
};
|
||||
|
||||
kern_return_t __dir_lookup (file_t start_dir, string_t file_name, int flags, mode_t mode, retry_type *do_retry, string_t retry_name, mach_port_t *port)
|
||||
{
|
||||
union message
|
||||
{
|
||||
struct mach_msg_string_int_int request;
|
||||
struct mach_msg_int_int_string_int reply;
|
||||
};
|
||||
union message message = {0};
|
||||
message.request.header.msgh_size = sizeof (message.request);
|
||||
message.request.type_one = mach_msg_type_file_name;
|
||||
strcpy (message.request.one, file_name);
|
||||
message.request.type_two = mach_msg_type_int32;
|
||||
message.request.two = flags;
|
||||
message.request.type_three = mach_msg_type_int32;
|
||||
message.request.three = mode;
|
||||
|
||||
kern_return_t result = __syscall_get (start_dir, SYS__dir_lookup,
|
||||
&message.request.header,
|
||||
sizeof (message.reply));
|
||||
if (message.reply.one != KERN_SUCCESS)
|
||||
return message.reply.one;
|
||||
*port = message.reply.four;
|
||||
return result;
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include <gnu/syscall.h>
|
||||
|
||||
struct mach_msg_pointer_int
|
||||
struct mach_msg_pointer_loff
|
||||
{
|
||||
mach_msg_header_t header;
|
||||
mach_msg_type_long_t type_one; char *one;
|
||||
|
@ -30,8 +30,8 @@ struct mach_msg_pointer_int
|
|||
kern_return_t
|
||||
__io_write (io_t io, data_t data, mach_msg_type_number_t size, loff_t offset, vm_size_t *wrote)
|
||||
{
|
||||
struct mach_msg_pointer_int message = {0};
|
||||
message.header.msgh_size = sizeof (struct mach_msg_pointer_int);
|
||||
struct mach_msg_pointer_loff message = {0};
|
||||
message.header.msgh_size = sizeof (struct mach_msg_pointer_loff);
|
||||
message.type_one = mach_msg_type_pointer;
|
||||
message.one = data;
|
||||
message.type_two = mach_msg_type_int64;
|
||||
|
|
|
@ -54,7 +54,7 @@ fopen (char const *file_name, char const *opentype)
|
|||
fd = _open3 (file_name, flags, mode);
|
||||
}
|
||||
else
|
||||
fd = _open3 (file_name, 0, 0);
|
||||
fd = _open3 (file_name, O_RDONLY, 0);
|
||||
|
||||
if (__mes_debug ())
|
||||
{
|
||||
|
|
|
@ -41,7 +41,7 @@ main (int argc, char const *argv[])
|
|||
eputs ("test open:");
|
||||
eputs (file_name);
|
||||
eputs ("\n");
|
||||
int filedes = open (file_name, 0, 0);
|
||||
int filedes = open (file_name, O_RDONLY, 0);
|
||||
if (filedes <= 2)
|
||||
return 1;
|
||||
char buf[20];
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
int
|
||||
main ()
|
||||
{
|
||||
int fd = open ("../COPYING", 0);
|
||||
int fd = open ("../COPYING", O_RDONLY);
|
||||
if (fd <= 0)
|
||||
return 1;
|
||||
FILE *f = fdopen (fd, "r");
|
||||
|
|
Loading…
Reference in a new issue