diff options
65 files changed, 262 insertions, 4228 deletions
diff --git a/acpi/acpi.c b/acpi/acpi.c index 63066aaf..acbf79c7 100644 --- a/acpi/acpi.c +++ b/acpi/acpi.c @@ -139,8 +139,6 @@ acpi_get_num_tables(size_t *num_tables) err = mmap_phys_acpi_header(acpi_ptr32, &next, &virt_addr2, fd_mem); } - char name[5] = { 0 }; - snprintf(name, 5, "%s", &next->signature[0]); if (next->signature[0] == '\0' || next->length == 0) { munmap(virt_addr2, ESCD_SIZE); continue; @@ -257,8 +255,6 @@ acpi_get_tables(struct acpi_table **tables) } } - char name[5] = { 0 }; - snprintf(name, 5, "%s", &next->signature[0]); if (next->signature[0] == '\0' || next->length == 0) { munmap(virt_addr2, ESCD_SIZE); continue; diff --git a/config.make.in b/config.make.in index 349fca87..e4f856f2 100644 --- a/config.make.in +++ b/config.make.in @@ -93,6 +93,10 @@ libblkid_LIBS = @libblkid_LIBS@ # Whether Sun RPC support is available. HAVE_SUN_RPC = @HAVE_SUN_RPC@ +# How to compile and link against libtirpc. +libtirpc_CFLAGS = @libtirpc_CFLAGS@ +libtirpc_LIBS = @libtirpc_LIBS@ + # Whether we found libcrypt. HAVE_LIBCRYPT = @HAVE_LIBCRYPT@ diff --git a/configure.ac b/configure.ac index 182548f2..9f131e9a 100644 --- a/configure.ac +++ b/configure.ac @@ -317,9 +317,10 @@ AC_DEFINE_UNQUOTED([X11_PREFIX], "$X11_PREFIX") AC_SUBST([X11_KEYSYMDEF_H]) # Check for Sun RPC headers and library. -AC_CHECK_HEADER([rpc/types.h], [HAVE_SUN_RPC=yes], [HAVE_SUN_RPC=no]) -AC_SEARCH_LIBS([clnt_create], [], [:], [HAVE_SUN_RPC=no]) +PKG_CHECK_MODULES([libtirpc], [libtirpc], [HAVE_SUN_RPC=yes], [HAVE_SUN_RPC=no]) AC_SUBST([HAVE_SUN_RPC]) +AC_SUBST([libtirpc_CFLAGS]) +AC_SUBST([libtirpc_LIBS]) if test -f ./$ac_unique_file; then # Configuring in source directory; don't create any Makefiles. diff --git a/console/console.c b/console/console.c index 6e83fbbc..7306b6b8 100644 --- a/console/console.c +++ b/console/console.c @@ -750,7 +750,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir, mach_msg_type_number_t *data_len, vm_size_t max_data_len, int *data_entries) { - error_t err; + error_t err = 0; int count = 0; size_t size = 0; /* Total size of our return block. */ struct vcons *first_vcons = NULL; @@ -813,11 +813,16 @@ netfs_get_dirents (struct iouser *cred, struct node *dir, bump_size ("input"); } - /* Allocate it. */ - *data = mmap (0, size, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); - err = ((void *) *data == (void *) -1) ? errno : 0; + if (!size) + *data_len = *data_entries = 0; + else + { + /* Allocate it. */ + *data = mmap (0, size, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + err = ((void *) *data == (void *) -1) ? errno : 0; + } - if (! err) + if (size && !err) /* Copy out the result. */ { char *p = *data; diff --git a/doc/hurd.texi b/doc/hurd.texi index 0a38ca77..54c9049b 100644 --- a/doc/hurd.texi +++ b/doc/hurd.texi @@ -2999,9 +2999,6 @@ If @option{--name} is specified, the client must use the device name in created by some other programs, for example by eth-multiplexer. -FIXME: a chapter on libtreefs and libdirmgt will probably go here - - @node Stores @chapter Stores diff --git a/exec/exec.c b/exec/exec.c index 617dc8e8..d72ad886 100644 --- a/exec/exec.c +++ b/exec/exec.c @@ -81,26 +81,13 @@ load_section (void *section, struct execdata *u) addr += u->info.elf.loadbase; else { -#if 0 - /* XXX: gnumach currently does not support high bits set in mask to prevent - * loading at high addresses. - * Instead, in rtld we prevent mappings there through a huge mapping done by - * fmh(). - */ - switch (elf_machine) - { - case EM_386: - case EM_486: - /* On the i386, programs normally load at 0x08000000, and - expect their data segment to be able to grow dynamically - upward from its start near that address. We need to make - sure that the dynamic linker is not mapped in a conflicting - address. */ - /* mask = 0xf8000000UL; */ /* XXX */ - break; - default: - break; - } +#ifdef __i386__ + /* On the i386, programs normally load at 0x08000000, and + expect their data segment to be able to grow dynamically + upward from its start near that address. We need to make + sure that the dynamic linker is not mapped in a conflicting + address. */ + mask = 0xf0000000UL; /* XXX */ #endif } if (anywhere && addr < vm_page_size) diff --git a/ext2fs/ext2fs.h b/ext2fs/ext2fs.h index 2b49d2ea..ba0eaecd 100644 --- a/ext2fs/ext2fs.h +++ b/ext2fs/ext2fs.h @@ -505,7 +505,9 @@ record_global_poke (void *ptr) block_t block = boffs_block (bptr_offs (ptr)); void *block_ptr = bptr (block); ext2_debug ("(%p = %p)", ptr, block_ptr); +#ifdef EXT2FS_DEBUG assert_backtrace (disk_cache_block_is_ref (block)); +#endif global_block_modified (block); pokel_add (&global_pokel, block_ptr, block_size); } @@ -531,7 +533,9 @@ record_indir_poke (struct node *node, void *ptr) block_t block = boffs_block (bptr_offs (ptr)); void *block_ptr = bptr (block); ext2_debug ("(%llu, %p)", node->cache_id, ptr); +#ifdef EXT2FS_DEBUG assert_backtrace (disk_cache_block_is_ref (block)); +#endif global_block_modified (block); pokel_add (&diskfs_node_disknode (node)->indir_pokel, block_ptr, block_size); } diff --git a/ext2fs/inode.c b/ext2fs/inode.c index d73d0bca..3bfbdfdb 100644 --- a/ext2fs/inode.c +++ b/ext2fs/inode.c @@ -632,6 +632,18 @@ diskfs_set_translator (struct node *np, const char *name, unsigned namelen, if (namelen && !blkno) { + mode_t newmode = 0; + + if (S_ISLNK (np->dn_stat.st_mode)) + { + /* Avoid storing both a symlink and a translator, + * e2fsck does not like it. */ + newmode = (np->dn_stat.st_mode & ~S_IFMT) | S_IFREG; + err = diskfs_validate_mode_change (np, newmode); + if (err) + return err; + } + /* Allocate block for translator */ blkno = ext2_new_block ((diskfs_node_disknode (np)->info.i_block_group @@ -645,6 +657,13 @@ diskfs_set_translator (struct node *np, const char *name, unsigned namelen, return ENOSPC; } + if (newmode) + { + /* Clear previous data */ + diskfs_truncate (np, 0); + np->dn_stat.st_mode = newmode; + } + di->i_translator = blkno; diskfs_node_disknode (np)->info_i_translator = blkno; record_global_poke (di); diff --git a/ext2fs/truncate.c b/ext2fs/truncate.c index 265f7f2c..44aab3c7 100644 --- a/ext2fs/truncate.c +++ b/ext2fs/truncate.c @@ -240,7 +240,7 @@ force_delayed_copies (struct node *node, off_t length) mach_port_t obj; pager_change_attributes (pager, MAY_CACHE, MEMORY_OBJECT_COPY_NONE, 1); - obj = diskfs_get_filemap (node, VM_PROT_READ); + obj = diskfs_get_filemap (node, VM_PROT_READ | VM_PROT_WRITE); if (obj != MACH_PORT_NULL) { /* XXX should cope with errors from diskfs_get_filemap */ @@ -296,6 +296,19 @@ diskfs_truncate (struct node *node, off_t length) is true for fast symlinks, and also apparently for some device nodes in linux. */ { + off_t froblen = node->dn_stat.st_size; + off_t frobmax = sizeof(diskfs_node_disknode (node)->info.i_data); + + if (froblen > frobmax) + { + ext2_warning ("inline data was %lld, more than max %lld", + (long long) froblen, (long long) frobmax); + froblen = frobmax; + } + froblen -= length; + memset (((char *) (diskfs_node_disknode (node)->info.i_data)) + length, + 0, froblen); + node->dn_stat.st_size = length; node->dn_set_mtime = 1; node->dn_set_ctime = 1; diff --git a/libdirmgt/Makefile b/libdirmgt/Makefile deleted file mode 100644 index f4e9f758..00000000 --- a/libdirmgt/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (C) 1995, 2012 Free Software Foundation -# Written by Michael I. Bushnell. -# -# This file is part of the GNU Hurd. -# -# The GNU Hurd 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 2, or (at -# your option) any later version. -# -# The GNU Hurd 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 this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -dir := libdirmgt -makemode := misc - -include ../Makeconf diff --git a/libdirmgt/dirmgt.h b/libdirmgt/dirmgt.h deleted file mode 100644 index 15921609..00000000 --- a/libdirmgt/dirmgt.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright (C) 1994 Free Software Foundation - - This program 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 2, or (at - your option) any later version. - - This program 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* This library manages directories for users who want to - write filesystem servers. */ - -/* Search directory DIR for name NAME. If NODEP is nonzero, then - set *NODEP to the node found. If TYPE is nonzero, then - set *TYPE to the type of the node found. */ -error_t -dirmgt_lookup (struct directory *dir, char *name, struct node **nodep, - int *type); - -/* Add NODE to DIR under name NAME. If NAME is already present in - the directory, the existing entry under that name is replaced without - further notice. TYPE is the DT_* name for the type of node. */ -error_t -dirmgt_enter (struct directory *dir, char *name, struct node *node, - int type); - -/* Add SUBDIR to DIR under name NAME. If NAME is already present in - the directory, then EBUSY is returned. */ -error_t -dirmgt_enter_dir (struct directory *dir, char *name, struct directory *subdir); - -/* Return directory contents to a user; args are exactly as for - the fs.defs:dir_readdir RPC. */ -error_t -dirmgt_readdir (struct directory *dir, char **data, u_int *datacnt, - int entry, int nentries, vm_size_t bufsiz, int *amt); - -/* If this routine is defined, then it will be called when a lookup on - a directory fails. If this routine returns success, the lookup will - then be repeated. If it returns an error, then the lookup will fail - with the reported error. */ -error_t -(*dirmgt_find_entry)(struct directory *dir, char *name); diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c index 0ae90144..5c4c3248 100644 --- a/libdiskfs/boot-start.c +++ b/libdiskfs/boot-start.c @@ -489,6 +489,7 @@ diskfs_S_fsys_init (struct diskfs_control *pt, mach_port_t host, startup; error_t err; mach_port_t root_pt; + mach_port_t bootstrap; struct protid *rootpi; struct peropen *rootpo; @@ -516,9 +517,11 @@ diskfs_S_fsys_init (struct diskfs_control *pt, mach_port_deallocate (mach_task_self (), diskfs_auth_server_port); diskfs_auth_server_port = authhandle; + err = task_get_bootstrap_port (mach_task_self (), &bootstrap); + assert_perror_backtrace (err); + if (diskfs_exec_server_task != MACH_PORT_NULL) { - mach_port_t bootstrap; process_t execprocess; err = proc_task2proc (procserver, diskfs_exec_server_task, &execprocess); @@ -535,28 +538,15 @@ diskfs_S_fsys_init (struct diskfs_control *pt, execprocess, MACH_MSG_TYPE_COPY_SEND)); mach_port_deallocate (mach_task_self (), execprocess); - /* Give the real bootstrap filesystem an fsys_init RPC of its own */ - err = task_get_bootstrap_port (mach_task_self (), &bootstrap); - assert_perror_backtrace (err); - if (bootstrap != MACH_PORT_NULL) - { - err = fsys_init (bootstrap, procserver, MACH_MSG_TYPE_COPY_SEND, - authhandle); - mach_port_deallocate (mach_task_self (), bootstrap); - assert_perror_backtrace (err); - } - /* We don't need this anymore. */ mach_port_deallocate (mach_task_self (), diskfs_exec_server_task); diskfs_exec_server_task = MACH_PORT_NULL; } else - { - mach_port_t bootstrap; - process_t parent_proc; - - assert_backtrace (parent_task != MACH_PORT_NULL); + assert_backtrace (parent_task != MACH_PORT_NULL); + if (parent_task != MACH_PORT_NULL) + { /* Tell the proc server that our parent task is our child. This makes the process hierarchy fail to represent the real order of who created whom, but it sets the owner and authentication ids to @@ -568,6 +558,15 @@ diskfs_S_fsys_init (struct diskfs_control *pt, err = proc_child (procserver, parent_task); assert_perror_backtrace (err); + } + + if (bootstrap != MACH_PORT_NULL) + { + /* Give our parent (the real bootstrap filesystem) an fsys_init + RPC of its own, as init would have sent it. */ + process_t parent_proc; + + assert_backtrace (parent_task != MACH_PORT_NULL); /* Get the parent's proc server port so we can send it in the fsys_init RPC just as init would. */ @@ -580,15 +579,12 @@ diskfs_S_fsys_init (struct diskfs_control *pt, proc_mark_exec (parent_proc); - /* Give our parent (the real bootstrap filesystem) an fsys_init - RPC of its own, as init would have sent it. */ - err = task_get_bootstrap_port (mach_task_self (), &bootstrap); - assert_perror_backtrace (err); err = fsys_init (bootstrap, parent_proc, MACH_MSG_TYPE_COPY_SEND, authhandle); + assert_perror_backtrace (err); + mach_port_deallocate (mach_task_self (), parent_proc); mach_port_deallocate (mach_task_self (), bootstrap); - assert_perror_backtrace (err); } /* Get a port to the root directory to put in the library's diff --git a/libdiskfs/node-cache.c b/libdiskfs/node-cache.c index d2815883..1ff19ade 100644 --- a/libdiskfs/node-cache.c +++ b/libdiskfs/node-cache.c @@ -163,6 +163,10 @@ diskfs_try_dropping_softrefs (struct node *np) hurd_ihash_locp_remove (&nodecache, np->slot); np->slot = NULL; + + /* Flush node if needed, before forgetting it */ + diskfs_node_update (np, diskfs_synchronous); + diskfs_nrele_light (np); } pthread_rwlock_unlock (&nodecache_lock); diff --git a/libmachdev/ds_routines.c b/libmachdev/ds_routines.c index c2de4b26..ac915166 100644 --- a/libmachdev/ds_routines.c +++ b/libmachdev/ds_routines.c @@ -315,13 +315,13 @@ void machdev_device_init() } } -void machdev_device_shutdown(mach_port_t dosync_handle) +void machdev_device_sync() { int i; for (i = 0; i < num_emul; i++) { - if (emulation_list[i]->shutdown) - emulation_list[i]->shutdown(dosync_handle); + if (emulation_list[i]->sync) + emulation_list[i]->sync(); } } diff --git a/libmachdev/machdev-device_emul.h b/libmachdev/machdev-device_emul.h index 7748f37f..9f7b0b21 100644 --- a/libmachdev/machdev-device_emul.h +++ b/libmachdev/machdev-device_emul.h @@ -64,7 +64,7 @@ struct machdev_device_emulation_ops recnum_t, vm_offset_t, vm_size_t); io_return_t (*writev_trap) (void *, dev_mode_t, recnum_t, io_buf_vec_t *, vm_size_t); - void (*shutdown) (mach_port_t); + void (*sync) (void); }; #endif /* _MACHDEV_DEVICE_EMUL_H_ */ diff --git a/libmachdev/machdev.h b/libmachdev/machdev.h index 5d0eed02..7ac42eed 100644 --- a/libmachdev/machdev.h +++ b/libmachdev/machdev.h @@ -30,7 +30,7 @@ void machdev_register (struct machdev_device_emulation_ops *ops); void machdev_device_init(void); -void machdev_device_shutdown(mach_port_t dosync_handle); +void machdev_device_sync(void); void * machdev_server(void *); error_t machdev_create_device_port (size_t size, void *result); int machdev_trivfs_init(int argc, char **argv, mach_port_t bootstrap_resume_task, const char *name, const char *path, mach_port_t *bootstrap); diff --git a/libmachdev/trivfs_server.c b/libmachdev/trivfs_server.c index bbd73555..029a8da7 100644 --- a/libmachdev/trivfs_server.c +++ b/libmachdev/trivfs_server.c @@ -289,17 +289,26 @@ trivfs_S_fsys_init (struct trivfs_control *fsys, retry_type retry; string_t retry_name; mach_port_t right = MACH_PORT_NULL; - process_t proc, parent_proc; /* Traverse to the bootstrapping server first */ task_get_bootstrap_port (mach_task_self (), &bootstrap); if (bootstrap) { + process_t parent_proc; err = proc_task2proc (procserver, parent_task, &parent_proc); assert_perror_backtrace (err); + + /* We don't need this anymore. */ + mach_port_deallocate (mach_task_self (), parent_task); + parent_task = MACH_PORT_NULL; + + proc_mark_exec(parent_proc); + err = fsys_init (bootstrap, parent_proc, MACH_MSG_TYPE_COPY_SEND, authhandle); assert_perror_backtrace (err); + + mach_port_deallocate (mach_task_self (), parent_proc); } err = fsys_getroot (control_port, MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND, idlist, 3, idlist, 3, 0, @@ -322,18 +331,6 @@ trivfs_S_fsys_init (struct trivfs_control *fsys, _hurd_libc_proc_init(machdev_argv); #endif - /* Mark us as important. */ - proc = getproc (); - assert_backtrace (proc); - err = proc_mark_important (proc); - if (err && err != EPERM) - assert_perror_backtrace (err); - err = proc_mark_exec (proc); - assert_perror_backtrace (err); - err = proc_set_exe (proc, program_invocation_short_name); - assert_perror_backtrace (err); - mach_port_deallocate (mach_task_self (), proc); - if (bootstrapping) { if (devnode) @@ -493,7 +490,7 @@ machdev_trivfs_init(int argc, char **argv, mach_port_t bootstrap_resume_task, return 0; } -/* The system is going down. Sync data, then call trivfs_goaway() */ +/* The system is going down, sync data. */ error_t S_startup_dosync (mach_port_t handle) { @@ -505,10 +502,10 @@ S_startup_dosync (mach_port_t handle) ports_port_deref (inpi); - /* Sync and close device(s) */ - machdev_device_shutdown (handle); + /* Sync device(s) */ + machdev_device_sync (); - return trivfs_goaway (NULL, FSYS_GOAWAY_FORCE); + return 0; } error_t diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h index 95f95270..a7f610ec 100644 --- a/libnetfs/netfs.h +++ b/libnetfs/netfs.h @@ -409,7 +409,8 @@ void netfs_init (void); /* Starts the netfs server. Called after netfs_init. BOOTSTRAP is the bootstrap port. FLAGS indicate how to open the underlying node - (Cf. hurd/fsys.defs). */ + that's being translated (Cf. hurd/fsys.defs). Returns a port to + such node. */ mach_port_t netfs_startup (mach_port_t bootstrap, int flags); /* Normally called as the last function in main. The netfs server now diff --git a/libshouldbeinlibc/assert-backtrace.h b/libshouldbeinlibc/assert-backtrace.h index f49a537e..c1e51594 100644 --- a/libshouldbeinlibc/assert-backtrace.h +++ b/libshouldbeinlibc/assert-backtrace.h @@ -45,16 +45,16 @@ void __assert_perror_fail_backtrace (int errnum, __attribute__ ((noreturn, unused)); #define assert_backtrace(expr) \ - ((expr) \ + (__builtin_expect(!!(expr), 1) \ ? (void) 0 \ : __assert_fail_backtrace (__STRING(expr), \ __FILE__, __LINE__, \ __PRETTY_FUNCTION__)) #define assert_perror_backtrace(expr) \ - ((expr == 0) \ + (__builtin_expect(((expr) == 0), 1) \ ? (void) 0 \ - : __assert_perror_fail_backtrace (expr, \ + : __assert_perror_fail_backtrace ((expr), \ __FILE__, __LINE__, \ __PRETTY_FUNCTION__)) diff --git a/libstore/device.c b/libstore/device.c index 0d4ca477..098506a0 100644 --- a/libstore/device.c +++ b/libstore/device.c @@ -52,7 +52,12 @@ dev_read (struct store *store, store_offset_t addr, size_t index, mach_msg_type_number_t amount, void **buf, mach_msg_type_number_t *len) { - return dev_error (device_read (store->port, 0, addr, amount, + recnum_t recnum = addr; + + if (recnum != addr) + return EOVERFLOW; + + return dev_error (device_read (store->port, 0, recnum, amount, (io_buf_ptr_t *)buf, len)); } @@ -62,10 +67,17 @@ dev_write (struct store *store, const void *buf, mach_msg_type_number_t len, mach_msg_type_number_t *amount) { - error_t err = dev_error (device_write (store->port, 0, addr, + recnum_t recnum = addr; + error_t err; + int amount_r; + + if (recnum != addr) + return EOVERFLOW; + + err = dev_error (device_write (store->port, 0, addr, (io_buf_ptr_t)buf, len, - (int *) amount)); - *amount = *(int *) amount; /* stupid device.defs uses int */ + &amount_r)); + *amount = amount_r; return err; } diff --git a/libtreefs/Makefile b/libtreefs/Makefile deleted file mode 100644 index 025040cf..00000000 --- a/libtreefs/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -# Makefile for libtreefs -# -# Copyright (C) 1995, 2012 Free Software Foundation, Inc. -# -# This program 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 2, or (at -# your option) any later version. -# -# This program 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 this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -dir := libtreefs -makemode := library - -libname = libtreefs -installhdrs = treefs.h -# RPC stubs -S_SRCS = s-file.c s-dir.c s-io.c s-fsys.c -OTHERSRCS = defhooks.c dir-hooks.c dir-lookup.c fsys-getroot.c fsys-hooks.c \ - fsys-startup.c hooks.c mdir.c nlist.c node-hooks.c rights.c \ - trans-help.c trans-start.c xinl.c -SRCS = $(OTHERSRCS) $(S_SRCS) - -MIGSTUBS = fsServer.o ioServer.o fsysServer.o -OBJS = $(sort $(SRCS:.c=.o)) $(MIGSTUBS) - -MIGSFLAGS = -imacros fs-mutate.h -MIGCOMSFLAGS = -prefix treefs_ -notify-MIGSFLAGS = -DSEQNOS - -include ../Makeconf diff --git a/libtreefs/defhooks.c b/libtreefs/defhooks.c deleted file mode 100644 index bed0b550..00000000 --- a/libtreefs/defhooks.c +++ /dev/null @@ -1,80 +0,0 @@ -/* Default functions for the hook vector - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" -#include "treefs-s-hooks.h" - -typedef void (*vf)(); - -static error_t unsupp () { return EOPNOTSUPP; } -static error_t nop () { return 0; } -static int true () { return 1; } - -/* Most hooks return an error_t, so the default for anything not mentioned in - this array is to return EOPNOTSUPP. Any hooks returning different types, - or with some different default behavior should be mentioned here. */ -treefs_hook_vector_init_t treefs_default_hooks = -{ - /* directory rpcs */ - [TREEFS_HOOK_S_DIR_LOOKUP] = (vf)_treefs_s_dir_lookup, - - [TREEFS_HOOK_S_FSYS_GETROOT] = (vf)_treefs_s_fsys_getroot, - [TREEFS_HOOK_S_FSYS_SYNCFS] = (vf)nop, - - /* Non-rpc fsys hooks */ - [TREEFS_HOOK_FSYS_CREATE_NODE] = (vf)_treefs_fsys_create_node, - [TREEFS_HOOK_FSYS_DESTROY_NODE] = (vf)_treefs_fsys_destroy_node, - [TREEFS_HOOK_FSYS_GET_ROOT] = (vf)_treefs_fsys_get_root, - - /* Node hooks */ - [TREEFS_HOOK_NODE_TYPE] = (vf)_treefs_node_type, - [TREEFS_HOOK_NODE_UNLINKED] = (vf)true, - [TREEFS_HOOK_NODE_MOD_LINK_COUNT] = (vf)_treefs_node_mod_link_count, - [TREEFS_HOOK_DIR_LOOKUP] = (vf)_treefs_dir_lookup, - [TREEFS_HOOK_DIR_NOENT] = (vf)_treefs_dir_noent, - [TREEFS_HOOK_DIR_CREATE_CHILD] = (vf)_treefs_dir_create_child, - [TREEFS_HOOK_DIR_LINK] = (vf)_treefs_dir_link, - [TREEFS_HOOK_DIR_UNLINK] = (vf)_treefs_dir_unlink, - [TREEFS_HOOK_NODE_OWNED] = (vf)_treefs_node_owned, - [TREEFS_HOOK_NODE_ACCESS] = (vf)_treefs_node_access, - [TREEFS_HOOK_NODE_START_TRANSLATOR] = (vf)_treefs_node_start_translator, - [TREEFS_HOOK_NODE_INIT] = (vf)nop, - [TREEFS_HOOK_DIR_INIT] = (vf)nop, - [TREEFS_HOOK_NODE_INIT_PEROPEN] = (vf)nop, - [TREEFS_HOOK_NODE_INIT_HANDLE] = (vf)nop, - [TREEFS_HOOK_NODE_FINALIZE] = (vf)nop, - [TREEFS_HOOK_NODE_FINALIZE_PEROPEN] = (vf)nop, - [TREEFS_HOOK_NODE_FINALIZE_HANDLE] = (vf)nop, - - /* Reference counting support */ - [TREEFS_HOOK_NODE_NEW_REFS] = (vf)nop, - [TREEFS_HOOK_NODE_LOST_REFS] = (vf)nop, - [TREEFS_HOOK_NODE_TRY_DROPPING_WEAK_REFS] = (vf)nop, -}; - -void _treefs_init_defhooks() -{ - int i; - for (i = 0; i < TREEFS_NUM_HOOKS; i++) - if (!treefs_default_hooks[i]) - treefs_default_hooks[i] = (vf)unsupp; -} diff --git a/libtreefs/dir-hooks.c b/libtreefs/dir-hooks.c deleted file mode 100644 index 5c54039a..00000000 --- a/libtreefs/dir-hooks.c +++ /dev/null @@ -1,136 +0,0 @@ -/* Default hooks for directory nodes - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <sys/fcntl.h> - -#include "treefs.h" - -/* ---------------------------------------------------------------- */ - -/* Return in CHILD a new node with one reference, presumably a possible child - of DIR, with a mode MODE. All attempts to create a new node go through - this hook, so it may be overridden to easily control creation (e.g., - replacing it with a hook that always returns EPERM). Note that this - routine doesn't actually enter the child into the directory, or give the - node a non-zero link count, that should be done by the caller. */ -error_t -_treefs_dir_create_child (struct treefs_node *dir, - mode_t mode, struct treefs_auth *auth, - struct treefs_node **child) -{ - error_t err; - - if (!treefs_node_isdir (dir)) - return ENOTDIR; - - err = treefs_fsys_create_node (dir->fsys, dir, mode, auth, child); - if (err) - return err; - - return 0; -} - -/* ---------------------------------------------------------------- */ - -/* Lookup NAME in DIR, returning the result in CHILD; AUTH should be used to - do authentication. FLAGS is the open flags; if FLAGS contains O_CREAT, - and NAME is not found, then an entry should be created with a mode of - CREATE_MODE (which includes the S_IFMT bits, e.g., S_IFREG means a normal - file), unless O_EXCL is also set, in which case EEXIST should be returned. - Possible special errors returned include: EAGAIN -- result would be the - parent of our filesystem root. */ -error_t -_treefs_dir_lookup (struct treefs_node *dir, char *name, - struct treefs_auth *auth, - int flags, int create_mode, - struct treefs_node **child) -{ - error_t err; - - if (strcmp (name, "..") == 0 && dir == dir->fsys->root) - /* Whoops, the result is above our heads. */ - err = EAGAIN; - else - /* See if we've got an in-core entry for this file. */ - err = treefs_mdir_get (dir, name, child); - - if (err == 0 && (flags & O_EXCL)) - return EEXIST; - - if (err == ENOENT) - /* See if there's some other way of getting this file. */ - err = treefs_dir_noent (dir, name, auth, flags, create_mode, child); - - if (err == ENOENT && (flags & O_CREAT)) - /* No such file, but the user wants to create it. */ - { - err = treefs_dir_create_child (dir, create_mode, auth, child); - if (!err) - { - err = treefs_dir_link (dir, name, *child, auth); - if (err) - treefs_node_unref (*child); - } - } - - return err; -} - -/* ---------------------------------------------------------------- */ - -/* Link the node CHILD into DIR as NAME, using AUTH to check authentication. - DIR should be locked and CHILD shouldn't be. The default hook puts it - into DIR's in-core directory, and uses a reference to CHILD. */ -error_t -_treefs_dir_link (struct treefs_node *dir, char *name, - struct treefs_node *child, struct treefs_auth *auth) -{ - struct treefs_node *old_child; - error_t err = treefs_node_mod_link_count (child, 1); - if (!err) - { - err = treefs_mdir_add (dir, name, child, &old_child); - if (err) - /* back out */ - treefs_node_mod_link_count (child, -1); - else if (old_child) - treefs_node_mod_link_count (old_child, -1); - } - return err; -} - -/* Remove the entry NAME from DIR, using AUTH to check authentication. DIR - should be locked. The default hook removes NAME from DIR's in-core - directory. */ -error_t -_treefs_dir_unlink (struct treefs_node *dir, char *name, - struct treefs_auth *auth) -{ - struct treefs_node *old_child; - error_t err = treefs_mdir_remove (dir, name, &old_child); - if (!err && old_child) - { - treefs_node_mod_link_count (old_child, -1); - treefs_node_unref (old_child); - } - return err; -} diff --git a/libtreefs/dir-lookup.c b/libtreefs/dir-lookup.c deleted file mode 100644 index 33fefe69..00000000 --- a/libtreefs/dir-lookup.c +++ /dev/null @@ -1,313 +0,0 @@ -/* Default treefs_s_dir_lookup hook - - Copyright (C) 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <fcntl.h> -#include <string.h> - -#include <hurd/fsys.h> - -#include "treefs.h" -#include "treefs-s-hooks.h" - -/* Default dir_lookup hook. This code was originally copied from diskfs. */ -error_t -_treefs_s_dir_lookup (struct treefs_handle *h, - char *path, int flags, mode_t mode, - enum retry_type *retry, char *retry_name, - file_t *result, mach_msg_type_name_t *result_type) -{ - struct treefs_node *dir; - struct treefs_node *node; - unsigned symlink_expansions = 0; - error_t err = 0; - char *path_buf = 0; - int path_buf_len = 0; - int lastcomp = 0; - int mustbedir = 0; - - flags &= O_HURD; - mode &= ~S_IFMT; - - /* Skip leading slashes */ - while (path[0] == '/') - path++; - - *result_type = MACH_MSG_TYPE_MAKE_SEND; - *retry = FS_RETRY_NORMAL; - retry_name[0] = '\0'; - - if (path[0] == '\0') - { - /* Set things up in the state expected by the code from gotit: on. */ - dir = 0; - node = h->po->node; - pthread_mutex_lock (&node->lock); - treefs_node_ref (node); - goto gotit; - } - - dir = h->po->node; - pthread_mutex_lock (&dir->lock); - node = 0; - - treefs_node_ref (dir); /* acquire a ref for later node_release */ - - do - { - char *nextname; - - assert_backtrace (!lastcomp); - - /* Find the name of the next pathname component */ - nextname = index (path, '/'); - - if (nextname) - { - *nextname++ = '\0'; - while (*nextname == '/') - nextname++; - if (*nextname == '\0') - { - /* These are the rules for filenames ending in /. */ - nextname = 0; - lastcomp = 1; - mustbedir = 1; - - } - else - lastcomp = 0; - } - else - lastcomp = 1; - - node = 0; - - /* Lookup the next pathname component. */ - if (!lastcomp) - err = treefs_dir_lookup (dir, path, h->auth, 0, 0, &node); - else - /* ... and in this case, the last. Note that the S_IFREG only - applies in the case of O_CREAT, which is turned off for - directories anyway. */ - err = - treefs_dir_lookup (dir, path, h->auth, flags, mode | S_IFREG, &node); - - /* If we get an error we're done */ - if (err == EAGAIN) - { - if (h->po->parent_port != MACH_PORT_NULL) - { - *retry = FS_RETRY_REAUTH; - *result = h->po->parent_port; - *result_type = MACH_MSG_TYPE_COPY_SEND; - if (!lastcomp) - strcpy (retry_name, nextname); - err = 0; - goto out; - } - else - /* The global filesystem root... .. == . */ - { - err = 0; - node = dir; - treefs_node_ref (node); - } - } - - if (err) - goto out; - - /* If this is translated, start the translator (if necessary) - and return. */ - /* The check for `node != dir' simplifies this code a great - deal. Such a translator should already have been started, - so there's no lossage in doing it this way. */ - if ((!lastcomp || !(flags & O_NOTRANS)) - && node != dir) - { - file_t dir_port = MACH_PORT_NULL, child_fsys; - - /* Be very careful not to hold an inode lock while fetching - a translator lock and vice versa. */ - - pthread_mutex_unlock (&node->lock); - pthread_mutex_unlock (&dir->lock); - - do - { - err = - treefs_node_get_active_trans (node, dir, h->po->parent_port, - &dir_port, &child_fsys); - if (err == 0 && child_fsys != MACH_PORT_NULL) - { - err = - fsys_getroot (child_fsys, dir_port, - MACH_MSG_TYPE_COPY_SEND, - h->auth->uids, h->auth->nuids, - h->auth->gids, h->auth->ngids, - lastcomp ? flags : 0, - retry, retry_name, result); - /* If we got MACH_SEND_INVALID_DEST or MIG_SERVER_DIED, then - the server is dead. Zero out the old control port and try - everything again. */ - if (err == MACH_SEND_INVALID_DEST || err == EMIG_SERVER_DIED) - treefs_node_drop_active_trans (node, child_fsys); - } - } - while (err == MACH_SEND_INVALID_DEST || err == EMIG_SERVER_DIED); - - if (err || child_fsys) - { - /* We're done; return to the user. If there are more - components after this name, be sure to append them to the - user's retry path. */ - if (!err && !lastcomp) - { - strcat (retry_name, "/"); - strcat (retry_name, nextname); - } - - *result_type = MACH_MSG_TYPE_MOVE_SEND; - - treefs_node_unref (dir); - treefs_node_unref (node); - if (dir_port) - mach_port_deallocate (mach_task_self (), dir_port); - - return err; - } - - /* We're here if we tried the translator check, and it - failed. Lock everything back, and make sure we do it - in the right order. */ - if (strcmp (path, "..") != 0) - { - if (pthread_mutex_trylock (&dir->lock)) - { - pthread_mutex_unlock (&node->lock); - pthread_mutex_lock (&dir->lock); - pthread_mutex_lock (&node->lock); - } - } - else - pthread_mutex_lock (&dir->lock); - } - - if (treefs_node_type (node) == S_IFLNK - && !(lastcomp && (flags & (O_NOLINK|O_NOTRANS)))) - /* Handle symlink interpretation */ - { - unsigned nextname_len = nextname ? strlen (nextname) + 1 : 0; - /* max space we currently have for the sym link */ - unsigned sym_len = path_buf_len - nextname_len - 1; - - if (symlink_expansions++ > node->fsys->max_symlinks) - { - err = ELOOP; - goto out; - } - - err = treefs_node_get_symlink (node, path_buf, &sym_len); - if (err == E2BIG) - /* Symlink contents + extra path won't fit in our buffer, so - reallocate it and try again. */ - { - path_buf_len = sym_len + nextname_len + 1 + 1; - path_buf = alloca (path_buf_len); - err = treefs_node_get_symlink (node, path_buf, &sym_len); - } - if (err) - goto out; - - if (nextname) - { - path_buf[sym_len] = '/'; - bcopy (nextname, path_buf + sym_len + 1, nextname_len - 1); - } - if (mustbedir) - { - path_buf[nextnamelen + sym_len] = '/'; - path_buf[nextnamelen + sym_len + 1] = '\0'; - } - else - path_buf[nextname_len + sym_len] = '\0'; - - if (path_buf[0] == '/') - { - /* Punt to the caller. */ - *retry = FS_RETRY_MAGICAL; - *result = MACH_PORT_NULL; - strcpy (retry_name, path_buf); - goto out; - } - - path = path_buf; - mustbedir = 0; - if (lastcomp) - { - lastcomp = 0; - /* Symlinks to nonexistent files aren't allowed to cause - creation, so clear the flag here. */ - flags &= ~O_CREAT; - } - treefs_node_release (node); - node = 0; - } - else - { - /* Handle normal nodes */ - path = nextname; - if (node == dir) - treefs_node_unref (dir); - else - treefs_node_release (dir); - if (!lastcomp) - { - dir = node; - node = 0; - } - else - dir = 0; - } - } while (path && *path); - - gotit: - /* At this point, node is the node to return. */ - - if (mustbedir && !treefs_node_isdir (node)) - err = ENOTDIR; - if (err) - goto out; - - err = treefs_node_create_right (node, flags, h->po->parent_port, h->auth, - result); - - out: - if (node) - { - if (dir == node) - treefs_node_unref (node); - else - treefs_node_release (node); - } - if (dir) - treefs_node_release (dir); - return err; -} diff --git a/libtreefs/fs-mutate.h b/libtreefs/fs-mutate.h deleted file mode 100644 index 6ddec3fa..00000000 --- a/libtreefs/fs-mutate.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Automagic type transformation for our mig interfaces - - Copyright (C) 1994 Free Software Foundation - - This program 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 2, or (at - your option) any later version. - - This program 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Only CPP macro definitions should go in this file. */ - -#define FILE_INTRAN treefs_handle_t treefs_begin_using_handle_port (file_t) -#define FILE_DESTRUCTOR treefs_end_using_handle_port (treefs_handle_t) - -#define IO_INTRAN treefs_handle_t treefs_begin_using_handle_port (io_t) -#define IO_DESTRUCTOR treefs_end_using_handle_port (treefs_handle_t) - -#define FILE_IMPORTS import "mig-decls.h"; -#define IO_IMPORTS import "mig-decls.h"; -#define FSYS_IMPORTS import "mig-decls.h"; -#define IFSOCK_IMPORTS import "mig-decls.h"; diff --git a/libtreefs/fsys-getroot.c b/libtreefs/fsys-getroot.c deleted file mode 100644 index cd735bfe..00000000 --- a/libtreefs/fsys-getroot.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include <fcntl.h> - -#include <hurd/fsys.h> - -#include "treefs.h" - -error_t -_treefs_s_fsys_getroot (struct treefs_fsys *fsys, - mach_port_t dotdot, - uid_t *uids, unsigned nuids, - uid_t *gids, unsigned ngids, - int flags, retry_type *retry, char *retry_name, - file_t *result, mach_msg_type_name_t *result_type) -{ - error_t err; - mode_t type; - struct treefs_node *root; - struct treefs_auth *auth; - - flags &= O_HURD; - - err = treefs_fsys_get_root (fsys, &root); - if (err) - return err; - - if (!(flags & O_NOTRANS)) - /* Try starting up any translator on the root node. */ - { - fsys_t child_fsys; - - do - { - err = - treefs_node_get_active_trans (root, 0, 0, &dotdot, &child_fsys); - if (err == 0 && child_fsys != MACH_PORT_NULL) - /* We think there's an active translator; try contacting it. */ - { - err = - fsys_getroot (child_fsys, dotdot, MACH_MSG_TYPE_COPY_SEND, - uids, nuids, gids, ngids, - flags, retry, retry_name, result); - /* If we got MACH_SEND_INVALID_DEST or MIG_SERVER_DIED, then - the server is dead. Zero out the old control port and try - everything again. */ - if (err == MACH_SEND_INVALID_DEST || err == EMIG_SERVER_DIED) - treefs_node_drop_active_trans (root, control_port); - } - } - while (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED); - - /* If we got a translator, or an error trying, return immediately. */ - if (err || child_fsys) - { - if (!err && *result != MACH_PORT_NULL) - *result_type = MACH_MSG_TYPE_MOVE_SEND; - else - *result_type = MACH_MSG_TYPE_COPY_SEND; - - if (!err) - mach_port_deallocate (mach_task_self (), dotdot); - treefs_node_unref (root); - - return err; - } - } - - pthread_mutex_lock (&root->lock); - - type = treefs_node_type (root); - if (type == S_IFLNK && !(flags & (O_NOLINK | O_NOTRANS))) - /* Handle symlink interpretation */ - { - int sym_len = 1000; - char path_buf[sym_len + 1], *path = path_buf; - - err = treefs_node_get_symlink (root, path, &sym_len); - if (err == E2BIG) - /* Symlink contents won't fit in our buffer, so - reallocate it and try again. */ - { - path = alloca (sym_len + 1); - err = treefs_node_get_symlink (node, path, &sym_len); - } - - if (err) - goto out; - - if (*path == '/') - { - *retry = FS_RETRY_MAGICAL; - *result = MACH_PORT_NULL; - *result_type = MACH_MSG_TYPE_COPY_SEND; - mach_port_deallocate (mach_task_self (), dotdot); - } - else - { - *retry = FS_RETRY_REAUTH; - *result = dotdot; - *result_type = MACH_MSG_TYPE_COPY_SEND; - } - - strcpy (retry_name, path); - goto out; - } - - err = treefs_node_create_auth (root, uids, nuids, gids, ngids, &auth); - if (err) - goto out; - - *retry = FS_RETRY_NORMAL; - *retry_name = '\0'; - *result_type = MACH_MSG_TYPE_MAKE_SEND; - - err = treefs_node_create_right (root, dotdot, flags, auth, result); - - treefs_node_auth_unref (root, auth); - - out: - treefs_node_release (root); - - return err; -} diff --git a/libtreefs/fsys-hooks.c b/libtreefs/fsys-hooks.c deleted file mode 100644 index ecff092b..00000000 --- a/libtreefs/fsys-hooks.c +++ /dev/null @@ -1,91 +0,0 @@ -/* Default hooks for filesystems - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -/* Called to get the root node of the a filesystem, with a reference, - returning it in ROOT, or return an error if it can't be had. The default - hook just returns FSYS->root or an error if it's NULL. Note that despite - the similar name, this is very different from fsys_s_getroot! FSYS must - not be locked. */ -error_t -_treefs_fsys_get_root (struct treefs_fsys *fsys, struct treefs_node **root) -{ - pthread_mutex_lock (&fsys->lock); - *root = fsys->root; - if (*root != NULL) - treefs_node_ref (*root); - pthread_mutex_unlock (&fsys->lock); - - return *root ? 0 : EOPNOTSUPP; -} - -/* Called on a filesystem to create a new node in that filesystem, returning - it in NODE. DIR, if non-NULL, is the nominal parent directory, and MODE - and CRED are the desired mode and user info respectively. This hook - should also call node_init_stat & node_init to initialize the various user - bits. */ -error_t -_treefs_fsys_create_node (struct treefs_fsys *fsys, - struct treefs_node *dir, - mode_t mode, struct treefs_protid *cred, - struct treefs_node **node) -{ - error_t err = treefs_create_node (fsys, node); - - if (err) - return err; - - err = treefs_node_init_stat (*node, dir, mode, cred); - if (!err) - err = treefs_node_init (*node, dir, mode, cred); - if (S_ISDIR (mode)) - { - treefs_dir_init (*node, dir, mode, cred); - treefs_mdir_init (*node, dir, mode, cred); - } - if (err) - { - /* There shouldn't be any other state to free at this point -- - node_init_stat shouldn't do more than init the stat structure, and - if node_init fails, it should clean up after itself. */ - treefs_free_node (*node); - return err; - } - - return 0; -} - -/* Called on a filesystem to destroy a node in that filesystem. This call - should *really* destroy it, i.e., it's only called once all references are - gone. */ -void -_treefs_fsys_destroy_node (struct treefs_fsys *fsys, struct treefs_node *node) -{ - if (treefs_node_isdir (node)) - { - treefs_mdir_finalize (node); - treefs_dir_finalize (node); - } - treefs_node_finalize (node); - treefs_free_node (node); -} diff --git a/libtreefs/fsys-startup.c b/libtreefs/fsys-startup.c deleted file mode 100644 index e2d138ba..00000000 --- a/libtreefs/fsys-startup.c +++ /dev/null @@ -1,36 +0,0 @@ -/* fsys startup RPC - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -error_t -treefs_S_fsys_startup (mach_port_t child_boot_port, mach_port_t control_port, - mach_port_t *real, mach_msg_type_name_t *real_type) -{ - error_t err; - struct port_info *child_boot = - ports_check_port_type (child_boot_port, PT_TRANSBOOT); - - assert_backtrace (child_boot); /* XXX deal with exec server boot */ - err = fshelp_handle_fsys_startup (child_boot, control_port, real, real_type); - ports_done_with_port (child_boot); - - return err; -} diff --git a/libtreefs/fsys.c b/libtreefs/fsys.c deleted file mode 100644 index fe1b9178..00000000 --- a/libtreefs/fsys.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -/* ---------------------------------------------------------------- */ - -/* Create a basic node, with one reference and no user-specific fields - initialized, and return it in NODE */ -error_t -treefs_create_node (struct treefs_fsys *fsys, struct treefs_node **node) -{ - struct treefs_node *n = malloc (sizeof (struct treefs_node)); - - if (n == NULL) - return ENOMEM; - - n->fsys = fsys; - n->refs = 1; - n->light_refs = 0; - n->hooks = fsys->hooks; - n->children = NULL; - n->u = NULL; - pthread_mutex_init (&n->lock, NULL); - fshelp_init_trans_link (&n->active_trans); - fshelp_lock_init (&n->lock_box); - - *node = n; - return 0; -} - -/* Immediately destroy NODE, with no user-finalization. */ -error_t -treefs_free_node (struct treefs_node *node) -{ - free (node); -} - -/* ---------------------------------------------------------------- */ - -/* Returns a new filesystem in FSYS. */ -error_t -treefs_create_fsys (struct port_bucket *port_bucket, - treefs_hook_vector_t hook_overrides, - struct treefs_fsys **fsys) -{ - treefs_hook_vector_t hooks = treefs_default_hooks; - - if (hook_overrides) - { - hooks = treefs_hooks_clone (hooks); - treefs_hooks_override (hooks, hooks_overrides); - } - - *fsys = - ports_allocate_port (port_bucket, sizeof (struct trivfs_control), - treefs_fsys_port_class); - if (*fsys == NULL) - return ENOMEM; - - pthread_mutex_init (&(*fsys)->lock, NULL); - (*fsys)->root = NULL; - - (*fsys)->underlying_port = MACH_PORT_NULL; - memset (&(*fsys)->underlying_stat, 0, sizeof(struct stat)); - - (*fsys)->flags = treefs_default_flags; - (*fsys)->max_symlinks = treefs_default_max_symlinks; - (*fsys)->sync_interval = treefs_default_sync_interval; - - (*fsys)->fs_type = treefs_default_fsys_type; - (*fsys)->fs_id = getpid(); - - (*fsys)->hooks = hooks; - - (*fsys)->port_bucket = port_bucket; - (*fsys)->protid_ports_class = treefs_protid_port_class; - - (*fsys)->u = NULL; - - return 0; -} - - -void ACKACKACK() -{ - /* Create a fake root node to bootstrap the filesystem. */ - err = treefs_create_node(*fsys, &fake_root); - if (err) - goto barf; - - /* Remember stat info for the node we're mounted on. */ - memset (&(*fsys)->underlying_stat, 0, sizeof (struct stat)); - file_stat (realnode, &(*fsys)->underlying_stat); - - /* Note that it points to *FSYS, but *FSYS's root doesn't point to it... - If the user wants this to be the real root, it's his responsility to - initialize if further and install it. */ - fake_root->fsys = *fsys; - bcopy (&(*fsys)->underlying_stat, &fake_root->stat); - err = treefs_fsys_init (fake_root); - if (err) - goto barf; - - /* See if the silly user has in fact done so. */ - if ((*fsys)->root != fake_root) - treefs_free_node (fake_root); -} diff --git a/libtreefs/hooks.c b/libtreefs/hooks.c deleted file mode 100644 index b8ec103f..00000000 --- a/libtreefs/hooks.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Functions for manipulating hook vectors. - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -#define HV_SIZE (sizeof (void (*)()) * TREEFS_NUM_HOOKS) - -/* Returns a copy of the treefs hook vector HOOKS, or a zero'd vector if HOOKS - is NULL. If HOOKS is NULL, treefs_default_hooks is used. If a memory - allocation error occurs, NULL is returned. */ -treefs_hook_vector_t -treefs_hooks_clone (treefs_hook_vector_t hooks) -{ - treefs_hook_vector_t clone = malloc (HV_SIZE); - if (clone != NULL) - { - if (hooks == NULL) - hooks = treefs_default_hooks; - bcopy (hooks, clone, HV_SIZE); - } - return clone; -} - -/* Copies each non-NULL entry in OVERRIDES into HOOKS. */ -void -treefs_hooks_override (treefs_hook_vector_t hooks, - treefs_hook_vector_t overrides) -{ - int num; - for (num = 0; num < TREEFS_NUM_HOOKS; num++) - if (overrides[num] != NULL) - hooks[num] = overrides[num]; -} - -/* Sets the hook NUM in HOOKS to HOOK. */ -void -treefs_hooks_set (treefs_hook_vector_t hooks, unsigned num, void (*hook)()) -{ - hooks[num] = hook; -} diff --git a/libtreefs/mdir.c b/libtreefs/mdir.c deleted file mode 100644 index ddc1516a..00000000 --- a/libtreefs/mdir.c +++ /dev/null @@ -1,92 +0,0 @@ -/* Low-level directory manipulation functions - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Low level dir management routines. If called on a non-dir, ENOTDIR is - returned. */ - -/* Add CHILD to DIR as NAME, replacing any existing entry. If OLD_CHILD is - NULL, and NAME already exists in dir, EEXIST is returned, otherwise, any - previous child is replaced and returned in OLD_CHILD. DIR should be - locked. */ -error_t -treefs_mdir_add (struct treefs_node *dir, char *name, - struct treefs_node *child, struct treefs_node **old_child) -{ - if (!treefs_node_isdir (dir)) - return ENOTDIR; - else - { - if (dir->children == NULL) - { - dir->children = treefs_make_node_list (); - if (dir->children == NULL) - return ENOMEM; - } - return treefs_node_list_add (dir->children, name, child, old_child); - } -} - -/* Remove any entry in DIR called NAME. If there is no such entry, ENOENT is - returned. If OLD_CHILD is non-NULL, any removed entry is returned in it. - DIR should be locked. */ -error_t -treefs_mdir_remove (struct treefs_node *dir, char *name, - struct treefs_node *old_child) -{ - if (!treefs_node_isdir (dir)) - return ENOTDIR; - else if (dir->children == NULL) - /* Normally this shouldn't happen. */ - return ENOENT; - else - return treefs_node_list_remove (dir->children, name, old_child); -} - -/* Returns in CHILD any entry called NAME in DIR, or NULL (and ENOENT) if - there isn't such. DIR should be locked. */ -error_t -treefs_mdir_get (struct treefs_node *dir, char *name, - struct treefs_node **child) -{ - if (!treefs_node_isdir (dir)) - return ENOTDIR; - else if (dir->children == NULL) - /* Normally this shouldn't happen. */ - return ENOENT; - else - return treefs_node_list_get (dir->children, name, child); -} - -/* Call FUN on each child of DIR; if FUN returns a non-zero value at any - point, stop iterating and return that value immediately. */ -error_t -treefs_mdir_for_each (struct treefs_node *dir, - error_t (*fun)(char *name, struct treefs_node *child)) -{ - if (!treefs_node_isdir (dir)) - return ENOTDIR; - else if (dir->children == NULL) - /* Normally this shouldn't happen. */ - return 0; - else - return treefs_node_list_for_each (dir->children, fun); -} diff --git a/libtreefs/mig-decls.h b/libtreefs/mig-decls.h deleted file mode 100644 index e17f6196..00000000 --- a/libtreefs/mig-decls.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Type decls for mig-produced server stubs - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -/* For mig */ -typedef struct treefs_handle *treefs_handle_t; - -extern treefs_handle_t treefs_begin_using_handle_port(mach_port_t port); -extern void treefs_end_using_handle_port (treefs_handle_t handle); - -#if defined(__USE_EXTERN_INLINES) || defined(TREEFS_DEFINE_EI) -TREEFS_EI -treefs_handle_t treefs_begin_using_handle_port(mach_port_t port) -{ - return - (struct treefs_handle *) - ports_lookup_port (0, port, treefs_fsys_port_class); -} - -TREEFS_EI void -treefs_end_using_handle_port (treefs_handle_t handle) -{ - if (handle != NULL) - ports_port_deref (&handle->pi); -} -#endif /* Use extern inlines. */ diff --git a/libtreefs/nlist.c b/libtreefs/nlist.c deleted file mode 100644 index 326bb0f8..00000000 --- a/libtreefs/nlist.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Functions for dealing with node lists - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -/* ---------------------------------------------------------------- */ -struct treefs_node_list -{ - unsigned short num_nodes, nodes_alloced; - -}; - -/* Return a new node list, or NULL if a memory allocation error occurs. */ -struct treefs_node_list * -treefs_make_node_list () -{ - struct treefs_node_list *nl = malloc (sizeof (struct treefs_node_list)); - if (!nl) - return NULL; - - nl->nodes_alloced = 0; - nl->num_nodes = 0; - - return nl; -} - -/* Add NODE to LIST as NAME, replacing any existing entry. If OLD_NODE is - NULL, and an entry NAME already exists, EEXIST is returned, otherwise, any - previous child is replaced and returned in OLD_NODE. */ -error_t -treefs_node_list_add (struct treefs_node_list *list, char *name, - struct treefs_node *node, struct treefs_node **old_node) -{ - -} - -/* Remove any entry in LIST called NAME. If there is no such entry, ENOENT is - returned. If OLD_NODE is non-NULL, any removed entry is returned in it. */ -error_t -treefs_node_list_remove (struct treefs_node_list *list, char *name, - struct treefs_node **old_node) -{ -} - -/* Returns in NODE any entry called NAME in LIST, or NULL (and ENOENT) if - there isn't such. */ -error_t -treefs_node_list_get (struct treefs_node_list *list, char *name, - struct treefs_node **node) -{ -} diff --git a/libtreefs/node-hooks.c b/libtreefs/node-hooks.c deleted file mode 100644 index faffcd6a..00000000 --- a/libtreefs/node-hooks.c +++ /dev/null @@ -1,176 +0,0 @@ -/* Default hooks for nodes - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -/* ---------------------------------------------------------------- */ -/* These default hooks depend on stat information being correct. */ - -/* Returns the type of NODE, as an S_IFMT value (e.g., S_IFDIR). The - default routine just looks at NODE's stat mode. */ -int -_treefs_node_type (struct treefs_node *node) -{ - return node->stat.st_mode & S_IFMT; -} - -/* Return TRUE if NODE is `unlinked' -- that is, can be deleted when all - (in-memory) references go away. */ -int -_treefs_node_unlinked (struct treefs_node *node) -{ - return node->stat.st_nlinks == 0; -} - -/* Changes the link count of NODE by CHANGE; if any error is returned, the - operation trying to change the link count will fail, so filesystems that - don't support real links can restrict it to 1 or 0. This is mostly used - by the in-core directory code when it makes a link. The default hook uses - the link field of NODE's stat entry. */ -error_t -_treefs_node_mod_link_count (struct treefs_node *node, int change) -{ - node->stat.st_nlinks += change; -} - - -/* ---------------------------------------------------------------- */ -/* These default hooks depend on stat information being correct. */ - -/* Returns the user and group that a newly started translator should be - authenticated as. The default just returns the owner/group of NODE. */ -error_t -_treefs_node_get_trans_auth (struct treefs_node *node, uid_t *uid, gid_t *gid) -{ - *uid = node->stat.st_uid; - *gid = node->stat.st_gid; - return 0; -} - -/* Check to see is the user identified by AUTH is permitted to do - operation OP on node NP. Op is one of S_IREAD, S_IWRITE, or S_IEXEC. - Return 0 if the operation is permitted and EACCES if not. */ -error_t -_treefs_node_access (struct treefs_node *node, - int op, struct treefs_auth *auth) -{ - int gotit; - if (diskfs_auth_has_uid (auth, 0)) - gotit = 1; - else if (auth->nuids == 0 && (node->stat.st_mode & S_IUSEUNK)) - gotit = node->stat.st_mode & (op << S_IUNKSHIFT); - else if (!treefs_node_owned (node, auth)) - gotit = node->stat.st_mode & op; - else if (treefs_auth_in_group (auth, node->stat.st_gid)) - gotit = node->stat.st_mode & (op >> 3); - else - gotit = node->stat.st_mode & (op >> 6); - return gotit ? 0 : EACCES; -} - -/* Check to see if the user identified by AUTH is permitted to do owner-only - operations on node NP; if so, return 0; if not, return EPERM. */ -error_t -_treefs_node_owned (struct treefs_node *node, struct treefs_auth *auth) -{ - /* Permitted if the user is the owner, superuser, or if the user - is in the group of the file and has the group ID as their user - ID. (This last is colloquially known as `group leader'.) */ - if (treefs_auth_has_uid (auth, node->stat.st_uid) - || treefs_auth_has_uid (auth, 0) - || (treefs_auth_in_group (auth, node->stat.st_gid) - && treefs_auth_has_uid (auth, node->stat.st_gid))) - return 0; - else - return EPERM; -} - -/* ---------------------------------------------------------------- */ - -error_t -_treefs_node_init_stat (struct treefs_node *node, struct treefs_node *dir, - mode_t mode, struct treefs_auth *auth) -{ - if (auth->nuids) - node->stat.st_uid = auth->uids[0]; - else - { - mode &= ~S_ISUID; - if (dir) - node->stat.st_uid = dir->stat.st_uid; - else - node->stat.st_uid = -1; /* XXX */ - } - - if (dir && diskfs_ingroup (dir->stat.st_gid, auth)) - node->stat.st_gid = dir->stat.st_gid; - else if (auth->ngids) - node->stat.st_gid = auth->gids[0]; - else - { - mode &= ~S_ISGID; - if (dir) - node->stat.st_gid = dir->stat.st_gid; - else - node->stat.st_gid = -1; /* XXX */ - } - - node->stat.st_rdev = 0; - node->stat.st_nlink = 0; - node->stat.st_mode = mode; - - node->stat.st_blocks = 0; - node->stat.st_size = 0; - node->stat.st_flags = 0; - - return 0; -} - -/* ---------------------------------------------------------------- */ - -/* Called when the new peropen structure PO is made for NODE, with the - authorization in AUTH, opened with the flags FLAGS. If an error is - returned, the open will fail with that error. The default hook does - explicit authorization checks against AUTH using treefs_node_access, and - otherwise does nothing. */ -error_t -_treefs_init_peropen (struct treefs_node *node, struct treefs_peropen *po, - int flags, struct treefs_auth *auth) -{ - error_t err; - - if (flags & O_READ) - err = treefs_node_access (node, S_IREAD, auth); - if (!err && (flags & O_EXEC)) - err = treefs_node_access (node, S_IEXEC, auth); - if (!err && (flags & O_WRITE)) - { - if (type == S_IFDIR) - err = EISDIR; - else if (auth->po->node->fsys->readonly) - err = EROFS; - else - err = treefs_node_access (node, S_IWRITE, auth); - } - - return err; -} diff --git a/libtreefs/rights.c b/libtreefs/rights.c deleted file mode 100644 index f803b029..00000000 --- a/libtreefs/rights.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Functions for making send rights in various ways - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Return in PORT a send right for a new protid, pointing at the peropen PO, - with rights initialized from AUTH. */ -error_t -treefs_peropen_create_right (struct treefs_peropen *po, - struct treefs_auth *auth, - mach_port_t *port) -{ - struct treefs_node *node = po->node; - struct treefs_fsys *fsys = node->fsys; - struct treefs_handle *handle = - ports_allocate_port (fsys->port_bucket, - sizeof (struct treefs_handle), - fsys->handle_port_class); - - if (handle == NULL) - return MACH_PORT_NULL; - - handle->po = po; - po->refs++; - handle->auth = auth; - auth->refs++; - - err = treefs_node_init_handle (node, handle); - if (err) - { - po->refs--; - auth->refs--; - } - - *port = ports_get_right (handle); - - return 0; -} - -/* Return in PORT a send right for a new handle and a new peropen, pointing - at NODE, with rights initialized from AUTH. FLAGS and PARENT_PORT are used - to initialize the corresponding fields in the new peropen. */ -error_t -treefs_node_create_right (struct treefs_node *node, int flags, - mach_port_t parent_port, struct treefs_auth *auth, - mach_port_t *port) -{ - struct treefs_peropen *po = malloc (sizeof (struct treefs_peropen)); - - if (po == NULL) - return ENOMEM; - - /* Initialize the peropen structure. */ - po->refs = 0; - po->node = node; - po->open_flags = flags; - po->user_lock_state = LOCK_UN; - po->parent_port = parent_port; - if (parent_port != MACH_PORT_NULL) - mach_port_mod_refs (mach_task_self (), - parent_port, MACH_PORT_RIGHT_SEND, 1); - - treefs_node_ref (node); - - err = treefs_node_init_peropen (node, po, flags, auth); - if (err) - goto puke; - - err = treefs_peropen_create_right (po, auth, port); - if (err) - goto puke; - - return 0; - - puke: - treefs_node_unref (node); - free (po); - return err; -} diff --git a/libtreefs/s-dir.c b/libtreefs/s-dir.c deleted file mode 100644 index 08c4eb99..00000000 --- a/libtreefs/s-dir.c +++ /dev/null @@ -1,112 +0,0 @@ -/* File_t rpc stubs for directories; see <hurd/fs.defs> for more info - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - Note that since the user overrides the builtin routines via hook vectors - instead of declaring his own stubs, it doesn't make a lot of sense to put - these routines in separate files like diskfs. This way should compile - faster; with dynamic libraries it won't matter in any case. - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -error_t -treefs_S_dir_notice_changes (struct treefs_protid *cred, - mach_port_t notify) -{ - if (cred == NULL) - return EOPNOTSUPP; - return treefs_s_dir_notice_changes (cred, notify); -} - -error_t -treefs_S_dir_link (struct treefs_protid *dir_cred, - struct treefs_protid *file_cred, - char *name) -{ - if (cred == NULL) - return EOPNOTSUPP; - return treefs_s_dir_link (dir_cred, file_cred, name); -} - -error_t -treefs_S_dir_lookup (struct treefs_protid *cred, - char *path, int flags, mode_t mode, - enum retry_type *retry, char *retry_name, - file_t *result, mach_msg_type_name_t *result_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_dir_lookup (cred, path, flags, mode, retry, retry_name, - result, result_type); -} - -error_t -treefs_S_dir_mkdir (struct treefs_protid *cred, char *name, mode_t mode) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_dir_mkdir (cred, name, mode); -} - -error_t -treefs_S_dir_mkfile (struct treefs_protid *cred, - int flags, mode_t mode, - mach_port_t *newnode, mach_msg_type_name_t *newnode_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_dir_mkfile (cred, flags, mode, newnode, newnode_type); -} - -error_t -treefs_S_dir_readdir (struct treefs_protid *cred, - char **data, unsigned *datacnt, - int entry, int num_entries, - vm_size_t bufsiz, int *amt) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_dir_readdir (cred, data, datacnt, - entry, num_entries, bufsiz, amt); -} - -error_t -treefs_S_dir_rename (struct treefs_protid *cred, char *name, - struct treefs_protid *to_cred, char *to_name) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_dir_rename (cred, name, to_cred, to_name); -} - -error_t -treefs_S_dir_rmdir (struct treefs_protid *cred, char *name) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_dir_rmdir (cred, name); -} - -error_t -treefs_S_dir_unlink (struct treefs_protid *cred, char *name) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_dir_unlink (cred, name); -} diff --git a/libtreefs/s-file.c b/libtreefs/s-file.c deleted file mode 100644 index 6ba67e3c..00000000 --- a/libtreefs/s-file.c +++ /dev/null @@ -1,263 +0,0 @@ -/* File_t rpc stubs; see <hurd/fs.defs> for more info - - Copyright (C) 1995, 1997 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - Note that since the user overrides the builtin routines via hook vectors - instead of declaring his own stubs, it doesn't make a lot of sense to put - these routines in separate files (like diskfs). This way should compile - faster, with dynamic libraries it won't matter in any case. - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -error_t -treefs_S_file_check_access (struct treefs_protid *cred, int *type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_check_access (cred, type); -} - -error_t -treefs_S_file_chauthor (struct treefs_protid *cred, uid_t author) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_chauthor (cred, author); -} - -error_t -treefs_S_file_chflags (struct treefs_protid *cred, int flags) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_chflags (cred, flags); -} - -error_t -treefs_S_file_notice_changes (struct treefs_protid *cred, mach_port_t notify) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_notice_changes (cred, notify); -} - -error_t -treefs_S_file_chmod (struct treefs_protid *cred, mode_t mode) -{ - if (!cred) - return EOPNOTSUPP; - mode &= ~(S_IFMT | S_ISPARE | S_ITRANS); - return treefs_s_file_chmod (cred, mode); -} - -error_t -treefs_S_file_chown (struct treefs_protid *cred, uid_t uid, gid_t gid) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_chown (cred, uid, gid); -} - -error_t -treefs_S_file_exec (struct treefs_protid *cred, - task_t task, int flags, - char *argv, unsigned argv_len, - char *envp, unsigned envp_len, - mach_port_t *fds, unsigned fds_len, - mach_port_t *ports, unsigned ports_len, - int *ints, unsigned ints_len, - mach_port_t *dealloc, unsigned dealloc_len, - mach_port_t *destroy, unsigned destroy_len) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_exec (cred, task, flags, argv, argv_len, envp, envp_len, - fds, fds_len, ports, ports_len, ints, ints_len, - dealloc, dealloc_len, destroy, destroy_len); -} - -error_t -treefs_S_file_get_translator (struct treefs_protid *cred, - char **trans, unsigned *trans_len) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_get_translator (cred, trans, trans_len); -} - -error_t -treefs_S_file_get_translator_cntl (struct treefs_protid *cred, - mach_port_t *ctl, - mach_msg_type_name_t *ctl_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_get_translator_cntl (cred, ctl, ctl_type); -} - -error_t -treefs_S_file_getcontrol (struct treefs_protid *cred, - mach_port_t *control, - mach_msg_type_name_t *control_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_getcontrol (cred, control, control_type); -} - -error_t -treefs_S_file_getfh (struct treefs_protid *cred, - char **data, unsigned *data_len) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_getfh (cred, data, data_len); -} - -error_t -treefs_S_file_getlinknode (struct treefs_protid *cred, - file_t *port, mach_msg_type_name_t *port_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_t (cred, port, port_type); -} - -error_t -treefs_S_file_invoke_translator (struct treefs_protid *cred, - int flags, - retry_type *retry, char *retry_name, - mach_port_t *retry_port, - mach_msg_type_name_t *retry_port_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_invoke_translator (cred, flags, retry, retry_name, - retry_port, retry_port_type); -} - -error_t -treefs_S_file_lock_stat (struct treefs_protid *cred, - int *self_status, int *other_status) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_lock_stat (cred, self_status, other_status); -} - -error_t -treefs_S_file_lock (struct treefs_protid *cred, int flags) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_lock (cred, flags); -} - -error_t -treefs_S_file_pathconf (struct treefs_protid *cred, int name, int *value) - { - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_pathconf (cred, name, value); -} - -error_t -treefs_S_file_set_translator (struct treefs_protid *cred, - int passive_flags, int active_flags, - int killtrans_flags, - char *passive, unsigned passive_len, - fsys_t active) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_set_translator (cred, passive_flags, active_flags, - killtrans_flags, passive, passive_len, - active); -} - -error_t -treefs_S_file_statfs (struct treefs_protid *cred, fsys_statfsbuf_t *statbuf) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_statfs (cred, statbuf); -} - -error_t -treefs_S_file_sync (struct treefs_protid *cred, int wait) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_sync (cred, wait); -} - -error_t -treefs_S_file_syncfs (struct treefs_protid *cred, int wait, int recurse) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_syncfs (cred, wait, recurse); -} - -error_t -treefs_S_file_set_size (struct treefs_protid *cred, off_t size) -{ - if (!cred) - return EOPNOTSUPP; - else if (size < 0) - return EINVAL; - return treefs_s_file_set_size (cred, size); -} - -error_t -treefs_S_file_utimes (struct treefs_protid *cred, - time_value_t atime, time_value_t mtime) -{ - if (!cred) - return EOPNOTSUPP; - - struct timespec atim, mtim; - - if (atime.microseconds == -1) - { - atim.tv_sec = 0; - atim.tv_nsec = UTIME_NOW; - } - else - TIME_VALUE_TO_TIMESPEC (&atime, &atim); - - if (mtime.microseconds == -1) - { - mtim.tv_sec = 0; - mtim.tv_nsec = UTIME_NOW; - } - else - TIME_VALUE_TO_TIMESPEC (&mtime, &mtim); - - return treefs_s_file_utimens (cred, atim, mtim); -} - -error_t -treefs_S_file_utimens (struct treefs_protid *cred, - struct timespec atime, struct timespec mtime) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_file_utimens (cred, atime, mtime); -} diff --git a/libtreefs/s-fsys.c b/libtreefs/s-fsys.c deleted file mode 100644 index e218a963..00000000 --- a/libtreefs/s-fsys.c +++ /dev/null @@ -1,76 +0,0 @@ -/* fsys_t rpc stubs; see <hurd/fsys.defs> for more info - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -#define CALL_FSYS_HOOK(hook, fsys_port, args...) \ -{ \ - error_t _err; \ - struct treefs_fsys *_fsys = (struct treefs_fsys *) \ - ports_lookup_port (0, fsys_port, treefs_fsys_port_class); \ - if (!_fsys) \ - return EOPNOTSUPP; \ - err = hook(_fsys , ##args); \ - ports_port_deref (&_fsys->pi); \ - return _err; \ -} - -error_t -treefs_S_fsys_getroot (fsys_t fsys_port, mach_port_t dotdot, - uid_t *uids, unsigned nuids, - gid_t *gids, unsigned ngids, - int flags, retry_type *retry, char *retry_name, - file_t *result, mach_msg_type_name_t *result_type) -{ - CALL_FSYS_HOOK(treefs_s_fsys_getroot, fsys_port, dotdot, uids, nuids, gids, - ngids, flags, retry, retry_name, result, result_type); -} - -error_t -treefs_S_fsys_set_options (fsys_t fsys_port, - char *data, unsigned len, int recurse) -{ - CALL_FSYS_HOOK(treefs_s_fsys_set_options, fsys_port, data, len, recurse); -} - -error_t -treefs_S_fsys_goaway (fsys_t fsys_port, int flags) -{ - CALL_FSYS_HOOK(treefs_s_fsys_goaway, fsys_port, flags); -} - -error_t -treefs_S_fsys_getfile (mach_port_t fsys_port, - uid_t *gen_uids, unsigned ngen_uids, - gid_t *gen_gids, unsigned ngen_gids, - char *handle, unsigned handle_len, - mach_port_t *file, mach_msg_type_name_t *file_type) -{ - CALL_FSYS_HOOK(treefs_s_fsys_getfile, fsys_port, gen_uids, ngen_uids, - gen_gids, ngen_gids, handle, handle_len, file, file_type); -} - -error_t -treefs_S_fsys_syncfs (fsys_t fsys_port, int wait, int recurse) -{ - CALL_FSYS_HOOK(treefs_s_fsys_syncfs, fsys_port, wait, recurse); -} diff --git a/libtreefs/s-io.c b/libtreefs/s-io.c deleted file mode 100644 index 6fdc504a..00000000 --- a/libtreefs/s-io.c +++ /dev/null @@ -1,284 +0,0 @@ -/* io_t rpc stubs; see <hurd/io.defs> for more info - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - Note that since the user overrides the builtin routines via hook vectors - instead of declaring his own stubs, it doesn't make a lot of sense to put - these routines in separate files (like diskfs). This way should compile - faster, with dynamic libraries it won't matter in any case. - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -error_t -treefs_S_io_get_icky_async_id (struct treefs_protid *cred, - mach_port_t *id, mach_msg_type_name_t *id_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_get_icky_async_id (cred, id, id_type); -} - -error_t -treefs_S_io_async (struct treefs_protid *cred, - mach_port_t notify, - mach_port_t *id, mach_msg_type_name_t *id_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_async (cred, notify, id, id_type); -} - -error_t -treefs_S_io_duplicate (struct treefs_protid *cred, - mach_port_t *port, - mach_msg_type_name_t *port_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_duplicate (cred, port, port_type); -} - -error_t -treefs_S_io_get_conch (struct treefs_protid *cred) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_get_conch (cred); -} - -error_t -treefs_S_io_interrupt (struct treefs_protid *cred) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_interrupt (cred); -} - -error_t -treefs_S_io_map_cntl (struct treefs_protid *cred, - memory_object_t *ctlobj, - mach_msg_type_name_t *ctlobj_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_map_cntl (cred, ctlobj, ctlobj_type); -} - -error_t -treefs_S_io_map (struct treefs_protid *cred, - memory_object_t *rdobj, mach_msg_type_name_t *rd_type, - memory_object_t *wrobj, mach_msg_type_name_t *wr_type) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_map (cred, rdobj, rd_type, wrobj, wr_type); -} - -error_t -treefs_S_io_get_openmodes (struct treefs_protid *cred, int *bits) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_get_openmodes (cred, bits); -} - -error_t -treefs_S_io_clear_some_openmodes (struct treefs_protid *cred, int bits) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_clear_some_openmodes (cred, bits); -} - -error_t -treefs_S_io_set_some_openmodes (struct treefs_protid *cred, int bits) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_set_some_openmodes (cred, bits); -} - -error_t -treefs_S_io_set_all_openmodes (struct treefs_protid *cred, int bits) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_set_all_openmodes (cred, bits); -} - -error_t -treefs_S_io_get_owner (struct treefs_protid *cred, pid_t *owner) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_get_owner (cred, owner); -} - -error_t -treefs_S_io_mod_owner (struct treefs_protid *cred, pid_t owner) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_mod_owner (cred, owner); -} - -error_t -treefs_S_io_prenotify (struct treefs_protid *cred, - vm_offset_t start, vm_offset_t end) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_prenotify (cred, start, end); -} - -error_t -treefs_S_io_read (struct treefs_protid *cred, - char **data, - mach_msg_type_number_t *data_len, - off_t offset, - mach_msg_type_number_t max) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_read (cred, data, data_len, offset, max); -} - -error_t -treefs_S_io_readable (struct treefs_protid *cred, - mach_msg_type_number_t *amount) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_readable (cred, amount); -} - -error_t -treefs_S_io_reauthenticate (struct treefs_protid *cred, mach_port_t rend_port) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_reauthenticate (cred, rend_port); -} - -error_t -treefs_S_io_release_conch (struct treefs_protid *cred) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_release_conch (cred); -} - -error_t -treefs_S_io_restrict_auth (struct treefs_protid *cred, - mach_port_t *newport, - mach_msg_type_name_t *newport_type, - uid_t *uids, unsigned nuids, - gid_t *gids, unsigned ngids) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_restrict_auth (cred, newport, newport_type, - uids, nuids, gids, ngids); -} - -error_t -treefs_S_io_seek (struct treefs_protid *cred, - off_t offset, int whence, off_t *new_offset) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_seek (cred, offset, whence, new_offset); -} - -error_t -treefs_S_io_select (struct treefs_protid *cred, int *type, int *tag) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_select (cred, type, tag); -} - -error_t -treefs_S_io_sigio (struct treefs_protid *cred) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_sigio (cred); -} - -error_t -treefs_S_io_stat (struct treefs_protid *cred, io_statbuf_t *statbuf) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_statbuf_t (cred, statbuf); -} - -error_t -treefs_S_io_readsleep (struct treefs_protid *cred) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_readsleep (cred); -} - -error_t -treefs_S_io_eofnotify (struct treefs_protid *cred) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_eofnotify (cred); -} - -error_t -treefs_S_io_postnotify (struct treefs_protid *cred, - vm_offset_t start, vm_offset_t end) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_postnotify (cred, start, end); -} - -error_t -treefs_S_io_readnotify (struct treefs_protid *cred) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_readnotify (cred); -} - -error_t -treefs_S_io_server_version (struct treefs_protid *cred, - char *server_name, - int *major, int *minor, int *edit) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_server_version (cred, server_version, major, minor, edit); -} - -error_t -treefs_S_io_write (struct treefs_protid *cred, - char *data, mach_msg_type_number_t data_len, - off_t offset, mach_msg_type_number_t *amount) -{ - if (!cred) - return EOPNOTSUPP; - return treefs_s_io_write (cred, data, data_len, offset, amount); -} diff --git a/libtreefs/trans-help.c b/libtreefs/trans-help.c deleted file mode 100644 index 7d3841c0..00000000 --- a/libtreefs/trans-help.c +++ /dev/null @@ -1,129 +0,0 @@ -/* Helper routines for dealing with translators - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "trivfs.h" - -/* Return the active translator control port for NODE. If there is no - translator, active or passive, MACH_PORT_NULL is returned in CONTROL_PORT. - If there is a translator, it is started if necessary, and returned in - CONTROL_PORT. *DIR_PORT should be a port right to use as the new - translators parent directory. If it is MACH_PORT_NULL, a port is created - from DIR and PARENT_PORT and stored in *DIR_PORT; otherwise DIR and - PARENT_PORT are not used. Neither NODE or DIR should be locked when - calling this function. */ -error_t -treefs_node_get_active_trans (struct treefs_node *node, - struct treefs_node *dir, - mach_port_t parent_port, - mach_port_t *control_port, - mach_port_t *dir_port) -{ - /* Fill in dir_port */ - void make_dir_port () - { - pthread_mutex_lock (&dir->lock); - *dir_port = treefs_node_make_right (dir, 0, parent_port, 0); - mach_port_insert_right (mach_task_self (), - *dir_port, *dir_port, MACH_MSG_TYPE_MAKE_SEND); - pthread_mutex_unlock (&dir->lock); - } - - pthread_mutex_lock (&node->active_trans.lock); - - if (node->active_trans.control != MACH_PORT_NULL) - { - mach_port_t control = node->active_trans.control; - mach_port_mod_refs (mach_task_self (), control, - MACH_PORT_RIGHT_SEND, 1); - pthread_mutex_unlock (&node->active_trans.lock); - - /* Now we have a copy of the translator port that isn't - dependent on the translator lock itself. Relock - the directory, make a port from it, and then call - fsys_getroot. */ - - if (*dir_port == MACH_PORT_NULL) - make_dir_port (); - - *control_port = control; - - return 0; - } - - pthread_mutex_unlock (&node->active_trans.lock); - - /* If we get here, then we have no active control port. - Check to see if there is a passive translator, and if so - repeat the translator check. */ - pthread_mutex_lock (&node->lock); - if (!node->istranslated) - { - *control_port = MACH_PORT_NULL; - return 0; - } - - err = treefs_node_get_translator (node, trans, &trans_len); - if (err == E2BIG) - { - trans = alloca (trans_len); - err = treefs_node_get_translator (node, trans, &trans_len); - } - if (err) - { - pthread_mutex_unlock (&node->lock); - return err; - } - - if (*dir_port == MACH_PORT_NULL) - { - pthread_mutex_unlock (&node->lock); - make_dir_port (); - pthread_mutex_lock (&node->lock); - } - - /* Try starting the translator (this unlocks NODE). */ - err = treefs_start_translator (node, trans, trans_len, *dir_port); - if (err) - return err; - - /* Try again now that we've started the translator... This call - should be tail recursive. */ - return - treefs_node_get_active_trans (node, dir, parent_port, - control_port, dir_port); -} - -/* Drop the active translator CONTROL_PORT on NODE, unless it's no longer the - current active translator, in which case just drop a reference to it. */ -void -treefs_node_drop_active_trans (struct treefs_node *node, - mach_port_t control_port) -{ - pthread_mutex_lock (&node->active_trans.lock); - /* Only zero the control port if it hasn't changed. */ - if (node->active_trans.control == control) - fshelp_translator_drop (&node->active_trans); - pthread_mutex_unlock (&node->active_trans.lock); - - /* And we're done with this port. */ - mach_port_deallocate (mach_task_self (), control_port); -} diff --git a/libtreefs/trans-start.c b/libtreefs/trans-start.c deleted file mode 100644 index b27c38f4..00000000 --- a/libtreefs/trans-start.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Starting a passive translator - - Copyright (C) 1994, 1995, 1999 Free Software Foundation, Inc. - - This program 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 2, or (at - your option) any later version. - - This program 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "treefs.h" - -#include <fcntl.h> - -int fshelp_transboot_port_type = PT_TRANSBOOT; - -/* Start the translator TRANS (of length TRANS_LEN) on NODE, which should be - locked, and will be unlocked when this function returns. PARENT_PORT is - a send right to use as the parent port passed to the translator. */ -error_t -_treefs_node_start_translator (struct treefs_node *node, - char *trans, unsigned trans_len, - file_t parent_port) -{ - error_t err; - int mode = O_READ | O_EXEC; - struct treefs_auth *auth; - file_t node_port; - uid_t uid, gid; - - err = treefs_node_get_trans_auth (node, &auth); - if (err) - return err; - - if (!node->fsys->readonly && treefs_node_type (node) == S_IFREG) - mode |= O_WRITE; - - /* Create the REALNODE port for the new filesystem. */ - node_port = treefs_node_make_right (node, mode, parent_port, auth); - mach_port_insert_right (mach_task_self (), node_port, node_port, - MACH_MSG_TYPE_MAKE_SEND); - - - pthread_mutex_unlock (&node->lock); - - /* XXXX Change libfshelp so that it take more than 1 uid/gid? */ - uid = auth->nuids > 0 ? auth->uids[0] : -1; - gid = auth->ngids > 0 ? auth->gids[0] : -1; - - /* XXX this should use fshelp_start_translator_long. */ - err = - fshelp_start_translator (&node->active_trans, NULL, trans, trans_len, - parent_port, node_port, uid, gid); - - treefs_node_auth_unref (node, auth); - - return err; -} diff --git a/libtreefs/treefs-hooks.h b/libtreefs/treefs-hooks.h deleted file mode 100644 index 49dbb419..00000000 --- a/libtreefs/treefs-hooks.h +++ /dev/null @@ -1,401 +0,0 @@ -/* Hooks in libtreefs (also see "treefs-s-hooks.h") - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __TREEFS_HOOKS_H__ -#define __TREEFS_HOOKS_H__ - -#include "treefs.h" - -/* ---------------------------------------------------------------- */ - -/* Hook indices */ -enum -{ - /* file rpcs */ - TREEFS_HOOK_S_FILE_EXEC, TREEFS_HOOK_S_FILE_CHOWN, - TREEFS_HOOK_S_FILE_CHAUTHOR, TREEFS_HOOK_S_FILE_CHMOD, - TREEFS_HOOK_S_FILE_CHFLAGS, TREEFS_HOOK_S_FILE_UTIMENS, - TREEFS_HOOK_S_FILE_SET_SIZE, TREEFS_HOOK_S_FILE_LOCK, - TREEFS_HOOK_S_FILE_LOCK_STAT, TREEFS_HOOK_S_FILE_ACCESS, - TREEFS_HOOK_S_FILE_NOTICE, TREEFS_HOOK_S_FILE_SYNC, - TREEFS_HOOK_S_FILE_GET_LINK_NODE, - - /* io rpcs */ - TREEFS_HOOK_S_IO_WRITE, TREEFS_HOOK_S_IO_READ, TREEFS_HOOK_S_IO_SEEK, - TREEFS_HOOK_S_IO_READABLE, TREEFS_HOOK_S_IO_SET_ALL_OPENMODES, - TREEFS_HOOK_S_IO_GET_OPENMODES, TREEFS_HOOK_S_IO_SET_SOME_OPENMODES, - TREEFS_HOOK_S_IO_CLEAR_SOME_OPENMODES, TREEFS_HOOK_S_IO_ASYNC, - TREEFS_HOOK_S_IO_MOD_OWNER, TREEFS_HOOK_S_IO_GET_OWNER, - TREEFS_HOOK_S_IO_GET_ICKY_ASYNC_ID, TREEFS_HOOK_S_IO_SELECT, - TREEFS_HOOK_S_IO_STAT, TREEFS_HOOK_S_IO_REAUTHENTICATE, - TREEFS_HOOK_S_IO_RESTRICT_AUTH, TREEFS_HOOK_S_IO_DUPLICATE, - TREEFS_HOOK_S_IO_SERVER_VERSION, TREEFS_HOOK_S_IO_MAP, - TREEFS_HOOK_S_IO_MAP_CNTL, TREEFS_HOOK_S_IO_RELEASE_CONCH, - TREEFS_HOOK_S_IO_EOFNOTIFY, TREEFS_HOOK_S_IO_PRENOTIFY, - TREEFS_HOOK_S_IO_POSTNOTIFY, TREEFS_HOOK_S_IO_READNOTIFY, - TREEFS_HOOK_S_IO_READSLEEP, TREEFS_HOOK_S_IO_SIGIO, - - /* directory rpcs */ - TREEFS_HOOK_S_DIR_LOOKUP, TREEFS_HOOK_S_DIR_READDIR, TREEFS_HOOK_S_DIR_MKDIR, - TREEFS_HOOK_S_DIR_RMDIR, TREEFS_HOOK_S_DIR_UNLINK, TREEFS_HOOK_S_DIR_LINK, - TREEFS_HOOK_S_DIR_RENAME, TREEFS_HOOK_S_DIR_MKFILE, - TREEFS_HOOK_S_DIR_NOTICE_CHANGES, - - /* filesystem rpcs */ - TREEFS_HOOK_S_FSYS_GETROOT, TREEFS_HOOK_S_FSYS_SET_OPTIONS, - TREEFS_HOOK_S_FSYS_SYNCFS, TREEFS_HOOK_S_FSYS_GETFILE, TREEFS_S_FSYS_GOAWAY, - - /* Non-rpc fsys hooks */ - TREEFS_HOOK_FSYS_CREATE_NODE, TREEFS_HOOK_FSYS_DESTROY_NODE, - TREEFS_HOOK_FSYS_GET_ROOT, - - /* Node hooks */ - TREEFS_HOOK_NODE_TYPE, - TREEFS_HOOK_NODE_UNLINKED, TREEFS_HOOK_NODE_MOD_LINK_COUNT, - TREEFS_HOOK_DIR_LOOKUP, TREEFS_HOOK_DIR_NOENT, - TREEFS_HOOK_DIR_CREATE_CHILD, TREEFS_HOOK_DIR_LINK, TREEFS_HOOK_DIR_UNLINK, - TREEFS_HOOK_NODE_OWNED, TREEFS_HOOK_NODE_ACCESS, - TREEFS_HOOK_NODE_GET_SYMLINK, TREEFS_HOOK_NODE_GET_PASSIVE_TRANS, - TREEFS_HOOK_NODE_START_TRANSLATOR, TREEFS_HOOK_NODE_GET_TRANS_AUTH, - TREEFS_HOOK_NODE_DROP, TREEFS_HOOK_NODE_INIT, TREEFS_HOOK_DIR_INIT, - TREEFS_HOOK_NODE_INIT_PEROPEN, TREEFS_HOOK_NODE_INIT_HANDLE, - TREEFS_HOOK_NODE_FINALIZE, TREEFS_HOOK_DIR_FINALIZE, - TREEFS_HOOK_NODE_FINALIZE_PEROPEN, TREEFS_HOOK_NODE_FINALIZE_HANDLE, - - /* Reference counting support */ - TREEFS_HOOK_NODE_NEW_REFS, TREEFS_HOOK_NODE_LOST_REFS, - TREEFS_HOOK_NODE_TRY_DROPPING_WEAK_REFS, - - TREEFS_NUM_HOOKS -}; - -/* ---------------------------------------------------------------- */ -/* Hook calling/defining macros */ - -/* Call the hook number HOOK in the hook vector HOOKS, whose function is of - type TYPE, with the args ARGS (my this is a useful comment). */ -#define TREEFS_CALL_HOOK(hooks, hook, type, args...) \ - ((type *)(hooks)[hook])(args) -#define TREEFS_CALL_HANDLE_HOOK(h, hook, type, args...) \ - ({struct treefs_handle *_tfs_cn_h = (h); \ - TREEFS_CALL_HOOK(_tfs_cn_h->po->node->hooks,hook,type, \ - _tfs_cn_h , ##args);}) -#define TREEFS_CALL_NODE_HOOK(node, hook, type, args...) \ - ({struct treefs_node *_tfs_cn_node = (node); \ - TREEFS_CALL_HOOK(_tfs_cn_node->hooks,hook,type, _tfs_cn_node , ##args);}) -#define TREEFS_CALL_FSYS_HOOK(fsys, hook, type, args...) \ - ({struct treefs_fsys *_tfs_cn_fsys = (fsys); \ - TREEFS_CALL_HOOK(_tfs_cn_fsys->hooks,hook,type, _tfs_cn_fsys , ##args);}) - -/* Shorthand form of TREEFS_CALL_*_HOOK (only used here). */ -#define _TREEFS_CHH(h, hook_id, type_id, args...) \ - TREEFS_CALL_HANDLE_HOOK(h, TREEFS_HOOK_##hook_id, treefs_##type_id##_t , ##args) -#define _TREEFS_CNH(node, hook_id, type_id, args...) \ - TREEFS_CALL_NODE_HOOK(node, TREEFS_HOOK_##hook_id, treefs_##type_id##_t , ##args) -#define _TREEFS_CFH(fsys, hook_id, type_id, args...) \ - TREEFS_CALL_FSYS_HOOK(fsys, TREEFS_HOOK_##hook_id, treefs_##type_id##_t , ##args) - -/* Forward declare some structures used before definition. */ -struct treefs_node; -struct treefs_fsys; -struct treefs_auth; -struct treefs_handle; -struct treefs_peropen; - -/* Shorthand for declaring the various hook types (each hook has an - associated type so that a user can type-check his hook routine). */ -#define DNH(name_sym, ret_type, argtypes...) \ - typedef ret_type treefs_##name_sym##_t (struct treefs_node * , ##argtypes); -#define DFH(name_sym, ret_type, argtypes...) \ - typedef ret_type treefs_##name_sym##_t (struct treefs_fsys * , ##argtypes); - -/* ---------------------------------------------------------------- */ -/* Non RPC hooks */ - -/* Called to get the root node of the a filesystem, with a reference, - returning it in ROOT, or return an error if it can't be had. The default - hook just returns FSYS->root or an error if it's NULL. Note that despite - the similar name, this is very different from fsys_s_getroot! FSYS must - not be locked. */ -DFH(fsys_get_root, error_t, struct treefs_node **root) -#define treefs_fsys_get_root(fsys, args...) \ - _TREEFS_CFH(fsys, FSYS_GET_ROOT, fsys_get_root , ##args) - -/* Called on a filesystem to create a new node in that filesystem, returning - it, with one reference, in NODE. DIR, if non-NULL, is the nominal parent - directory, and MODE and AUTH are the desired mode and user info - respectively. This hook should also call node_init_stat & node_init to - initialize the various user bits. */ -DFH(fsys_create_node, error_t, - struct treefs_node *dir, mode_t mode, struct treefs_auth *auth, - struct treefs_node **node) -#define treefs_fsys_create_node(fsys, args...) \ - _TREEFS_CFH(fsys, FSYS_CREATE_NODE, fsys_create_node , ##args) - -/* Called on a filesystem to destroy a node in that filesystem. This call - should *really* destroy it -- i.e., it's only called once all references - are gone. */ -DFH(fsys_destroy_node, void, struct treefs_node *node) -#define treefs_fsys_destroy_node(fsys, node) \ - _TREEFS_CFH(fsys, FSYS_DESTROY_NODE, fsys_destroy_node , ##args) - -/* Returns the type of NODE, as an S_IFMT value (e.g., S_IFDIR). The - default routine just looks at NODE's stat mode. */ -DNH(node_type, int); -#define treefs_node_type(node, args...) \ - _TREEFS_CNH(node, NODE_TYPE, node_type , ##args) - -#define treefs_node_isdir(node) (treefs_node_type(node) == S_IFDIR) -#define treefs_node_isreg(node) (treefs_node_type(node) == S_IFREG) - -/* Return TRUE if NODE is `unlinked' -- that is, can be deleted when all - (in-memory) references go away. */ -DNH(node_unlinked, int); -#define treefs_node_unlinked(node, args...) \ - _TREEFS_CNH(node, NODE_UNLINKED, node_unlinked , ##args) - -/* Changes the link count of NODE by CHANGE; if any error is returned, the - operation trying to change the link count will fail, so filesystems that - don't support real links can restrict it to 1 or 0. This is mostly used - by the in-core directory code when it makes a link. The default hook uses - the link field of NODE's stat entry. */ -DNH(node_mod_link_count, error_t, int change); -#define treefs_node_mod_link_count(node, args...) \ - _TREEFS_CNH(node, NODE_MOD_LINK_COUNT, node_mod_link_count , ##args) - -/* Lookup NAME in NODE, returning the result in CHILD; AUTH should be used to - do authentication. If FLAGS contains O_CREAT, and NAME is not found, then - an entry should be created with a mode of CREATE_MODE (which includes the - S_IFMT bits, e.g., S_IFREG means a normal file), unless O_EXCL is also - set, in which case EEXIST should be returned. Possible special errors - returned include: EAGAIN -- result would be the parent of our filesystem - root. Note that is a single-level lookup, unlike treefs_s_dir_lookup. */ -DNH(dir_lookup, error_t, - char *name, struct treefs_auth *auth, int flags, int create_mode, - struct treefs_node **child) -#define treefs_dir_lookup(dir, args...) \ - _TREEFS_CNH(dir, DIR_LOOKUP, dir_lookup , ##args) - -/* Called by the default implementation of treefs_dir_lookup (and possibly - user-versions as well) when a directory lookup returns ENOENT, before a - new node is created. This hook may return the desire node in CHILD and - return 0, or return an error code. Note that a returned node need not - actually be in the directory DIR, and indeed may be anonymous. */ -DNH(dir_noent, error_t, - char *name, struct treefs_auth *auth, int flags, int create_mode, - struct treefs_node **child); -#define treefs_dir_noent(dir, args...) \ - _TREEFS_CNH(dir, DIR_NOENT, dir_noent , ##args) - -/* Return in CHILD a new node with one reference, presumably a possible child - of DIR, with a mode MODE. All attempts to create a new node go through - this hook, so it may be overridden to easily control creation (e.g., - replacing it with a hook that always returns EPERM). Note that this - routine doesn't actually enter the child into the directory, or give the - node a non-zero link count, that should be done by the caller. */ -DNH(dir_create_child, error_t, - mode_t mode, struct treefs_auth *auth, struct treefs_node **child); -#define treefs_dir_create_child(dir, args...) \ - _TREEFS_CNH(dir, DIR_CREATE_CHILD, dir_create_child , ##args) - -/* Link the node CHILD into DIR as NAME, using AUTH to check authentication. - DIR should be locked and CHILD shouldn't be. The default hook puts it - into DIR's in-core directory, and uses a reference to CHILD (this way, a - node can be linked to both in-core and out-of-core directories and the - permanent link-count will be right). */ -DNH(dir_link, error_t, - char *name, struct treefs_node *child, struct treefs_auth *auth) -#define treefs_dir_link(dir, args...) \ - _TREEFS_CNH(dir, DIR_LINK, dir_link , ##args) - -/* Remove the entry NAME from DIR, using AUTH to check authentication. DIR - should be locked. The default hook removes NAME from DIR's in-core - directory. */ -DNH(dir_unlink, error_t, char *name, struct treefs_auth *auth) -#define treefs_dir_unlink(dir, args...) \ - _TREEFS_CNH(dir, DIR_UNLINK, dir_unlink , ##args) - -/* Check to see if the user identified by AUTH is permitted to do owner-only - operations on node NP; if so, return 0; if not, return EPERM. */ -DNH(node_owned, error_t, struct treefs_auth *auth) -#define treefs_node_owned(node, args...) \ - _TREEFS_CNH(node, NODE_OWNED, node_owned , ##args) - -/* Check to see is the user identified by AUTH is permitted to do - operation OP on node NP. Op is one of S_IREAD, S_IWRITE, or S_IEXEC. - Return 0 if the operation is permitted and EACCES if not. */ -DNH(node_access, error_t, int opt, struct treefs_auth *auth) -#define treefs_node_access(node, args...) \ - _TREEFS_CNH(node, NODE_ACCESS, node_access , ##args) - -/* NODE now has no more references; clean all state. The - _treefs_node_refcnt_lock must be held, and will be released upon return. - NODE must be locked. */ -DNH(node_drop, error_t); -#define treefs_node_drop(node, args...) \ - _TREEFS_CNH(node, NODE_DROP, node_drop , ##args) - -/* Called when a new directory is created, after trees_node_init. If this - routine returns an error, the new node will be destroyed and the create - will fail. */ -DNH(dir_init, error_t) -#define treefs_dir_init(dir, args...) \ - _TREEFS_CNH(dir, DIR_INIT, dir_init , ##args) - -/* If NODE is a symlink, copies the contents into BUF, which should have at - least *LEN bytes available, and returns 0; if the symlink is too big, - E2BIG is returned. Either way, the actual length of the symlink is - returned in *LEN (so if it's too big, you can allocate an appropriately - sized buffer and try again). If NODE is not a symlink, EINVAL is - returned. */ -DNH(node_get_symlink, error_t, char *buf, int *len) -#define treefs_node_get_symlink(node, args...) \ - _TREEFS_CNH(node, NODE_GET_SYMLINK, node_get_symlink , ##args) - -/* If NODE has a passive translator, copies the contents into BUF, which - should have at least *LEN bytes available, and returns 0; if the string is - too big, E2BIG is returned. Either way, the actual length of the - translator string is returned in *LEN (so if it's too big, you can - allocate an appropriately sized buffer and try again). If NODE has no - passive translator, EINVAL is returned. */ -DNH(node_get_passive_trans, error_t, char *buf, int *len) -#define treefs_node_get_passive_trans(node, args...) \ - _TREEFS_CNH(node, NODE_GET_PASSIVE_TRANS, node_get_passive_trans , ##args) - -/* Returns the user and group that a newly started translator should be - authenticated as. The default just returns the owner/group of NODE. */ -DNH(node_get_trans_auth, error_t, uid_t *uid, gid_t *gid) -#define treefs_node_get_trans_auth(node, args...) \ - _TREEFS_CNH(node, NODE_GET_TRANS_AUTH, node_get_trans_auth , ##args) - -/* Start the translator TRANS (of length TRANS_LEN) on NODE, which should be - locked, and will be unlocked during the execution of this function. - PARENT_PORT should be a send right to use as the parent port passed to the - translator. */ -DNH(node_start_translator, error_t, - char *trans, unsigned trans_len, file_t parent_port) -#define treefs_node_start_translator(node, args...) \ - _TREEFS_CNH(node, NODE_START_TRANSLATOR, node_start_translator , ##args) - -/* Called to initialize a new node's stat entry, after all default fields are - filled in (but before node_init is called). */ -DNH(node_init_stat, error_t, - struct treefs_node *dir, mode_t mode, struct treefs_auth *auth) -#define treefs_node_init_stat(node, args...) \ - _TREEFS_CNH(node, NODE_INIT_STAT, node_init_stat , ##args) - -/* Called to initialize a new node, after all default fields are filled in. - If this routine returns an error, the new node will be destroyed and the - create will fail. */ -DNH(node_init, error_t, - struct treefs_node *dir, mode_t mode, struct treefs_auth *auth) -#define treefs_node_init(node, args...) \ - _TREEFS_CNH(node, NODE_INIT, node_init , ##args) - -/* Called to cleanup node-specific info in a node about to be destroyed. */ -DNH(node_finalize, void) -#define treefs_node_finalize(node, args...) \ - _TREEFS_CNH(node, NODE_FINALIZE, node_finalize , ##args) - -/* Called to cleanup node-specific directory info in a node about to be - destroyed. Called before node_finalize. */ -DNH(dir_finalize, void) -#define treefs_dir_finalize(dir, args...) \ - _TREEFS_CNH(dir, DIR_FINALIZE, dir_finalize , ##args) - -/* Called when the new peropen structure PO is made for NODE, with the - authorization in AUTH, opened with the flags FLAGS (note that this a copy - of PO->flags, which the hook may modify). If an error is returned, the - open will fail with that error. The default hook does explicit checks - against AUTH using treefs_node_access, and otherwise does nothing. */ -DNH(node_init_peropen, error_t, - struct treefs_peropen *po, int flags, struct treefs_auth *auth) -#define treefs_node_init_peropen(node, args...) \ - _TREEFS_CNH(node, NODE_INIT_PEROPEN, node_init_peropen , ##args) - -/* Called the peropen structure PO for NODE is being destroyed. */ -DNH(node_finalize_peropen, void, struct treefs_peropen *po) -#define treefs_node_finalize_peropen(node, args...) \ - _TREEFS_CNH(node, NODE_FINALIZE_PEROPEN, node_finalize_peropen , ##args) - -/* Called when a new handle structure is made for a node. The default does - nothing. */ -DNH(node_init_handle, void, struct treefs_handle *handle) -#define treefs_node_init_handle(node, args...) \ - _TREEFS_CNH(node, NODE_INIT_HANDLE, node_init_handle , ##args) - -/* Called when the handle HANDLE for NODE is being destroyed. */ -DNH(node_finalize_handle, void, struct treefs_handle *handle) -#define treefs_node_finalize_handle(node, args...) \ - _TREEFS_CNH(node, NODE_FINALIZE_HANDLE, node_finalize_handle , ##args) - -/* ---------------------------------------------------------------- */ -/* Ref counting stuff */ - -/* NODE has just acquired a hard reference where it had none previously. It - is thus now OK again to have weak references without real users. NODE is - locked. */ -DNH(node_new_refs, void); -#define treefs_node_new_refs(node, args...) \ - _TREEFS_CNH(node, NODE_NEW_REFS, node_new_refs , ##args) - -/* NODE has some weak references but has just lost its last hard reference. - NP is locked. */ -DNH(node_lost_refs, void); -#define treefs_node_lost_refs(node, args...) \ - _TREEFS_CNH(node, NODE_LOST_REFS, node_lost_refs , ##args) - -/* NODE has some weak references, but has just lost its last hard references. - Take steps so that if any weak references can be freed, they are. NP is - locked as is the pager refcount lock. This function will be called after - treefs_node_lost_refs. */ -DNH(node_try_dropping_weak_refs, void); -#define treefs_node_try_dropping_weak_refs(node, args...) \ - _TREEFS_CNH(node, NODE_TRY_DROPPING_WEAK_REFS, node_try_dropping_weak_refs , ##args) - -/* Turn off our shorthand notation. */ -#undef DNH -#undef DFH - -/* ---------------------------------------------------------------- */ -/* Default routines for some hooks (each is the default value for the hook - with the same name minus the leading underscore). When you add something - here, you should also add it to the initialize code in defhooks.c. */ - -treefs_fsys_create_node_t _treefs_fsys_create_node; -treefs_fsys_destroy_node_t _treefs_fsys_destroy_node; -treefs_fsys_get_root_t _treefs_fsys_get_root; -treefs_node_type_t _treefs_node_type; -treefs_node_unlinked_t _treefs_node_unlinked; -treefs_node_mod_link_count_t _treefs_node_mod_link_count; -treefs_node_mod_link_count_t _treefs_mod_link_count; -treefs_dir_lookup_t _treefs_dir_lookup; -treefs_dir_noent_t _treefs_dir_noent; -treefs_dir_create_child_t _treefs_dir_create_child; -treefs_dir_link_t _treefs_dir_link; -treefs_dir_unlink_t _treefs_dir_unlink; -treefs_node_owned_t _treefs_node_owned; -treefs_node_access_t _treefs_node_access; -treefs_node_start_translator_t _treefs_node_start_translator; -treefs_node_get_trans_auth_t _treefs_node_get_trans_auth; - -#endif /* __TREEFS_HOOKS_H__ */ diff --git a/libtreefs/treefs-s-hooks.h b/libtreefs/treefs-s-hooks.h deleted file mode 100644 index 9b2489df..00000000 --- a/libtreefs/treefs-s-hooks.h +++ /dev/null @@ -1,231 +0,0 @@ -/* RPC server hooks in libtreefs (also see "treefs-hooks.h") - - Copyright (C) 1995 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.ai.mit.edu> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __TREEFS_S_HOOKS_H__ -#define __TREEFS_S_HOOKS_H__ - -#include "treefs-hooks.h" - -/* Shorthand for declaring the various hook types (each hook has an - associated type so that a user can type-check his hook routine). */ -#define DHH(name_sym, ret_type, argtypes...) \ - typedef ret_type treefs_##name_sym##_t (struct treefs_handle * , ##argtypes); -#define DFH(name_sym, ret_type, argtypes...) \ - typedef ret_type treefs_##name_sym##_t (struct treefs_fsys * , ##argtypes); - -/* ---------------------------------------------------------------- */ -/* Hooks for file RPCs. See <hurd/fs.defs> for more info. */ - -DHH(s_file_exec, error_t, - task_t, int, char *, unsigned, char *, unsigned, mach_port_t *, unsigned, - mach_port_t *, unsigned, int *, unsigned, - mach_port_t *, unsigned, mach_port_t *, unsigned) -#define treefs_s_file_exec(h, args...) \ - _TREEFS_CHH(h, S_FILE_EXEC, s_file_exec , ##args) -DHH(s_file_chown, error_t, uid_t, gid_t) -#define treefs_s_file_chown(h, args...) \ - _TREEFS_CHH(h, S_FILE_CHOWN, s_file_chown , ##args) -DHH(s_file_chauthor, error_t, uid_t) -#define treefs_s_file_chauthor(h, args...) \ - _TREEFS_CHH(h, S_FILE_CHAUTHOR, s_file_chauthor , ##args) -DHH(s_file_chmod, error_t, mode_t) -#define treefs_s_file_chmod(h, args...) \ - _TREEFS_CHH(h, S_FILE_CHMOD, s_file_chmod , ##args) -DHH(s_file_chflags, error_t, int) -#define treefs_s_file_chflags(h, args...) \ - _TREEFS_CHH(h, S_FILE_CHFLAGS, s_file_chflags , ##args) -DHH(s_file_utimens, error_t, struct timespec, struct timespec) -#define treefs_s_file_utimens(h, args...) \ - _TREEFS_CHH(h, S_FILE_UTIMENS, s_file_utimens , ##args) -DHH(s_file_truncate, error_t, off_t) -#define treefs_s_file_truncate(h, args...) \ - _TREEFS_CHH(h, S_FILE_TRUNCATE, s_file_truncate , ##args) -DHH(s_file_lock, error_t, struct treefs_handle *, int) -#define treefs_s_file_lock(h, args...) \ - _TREEFS_CHH(h, S_FILE_LOCK, s_file_lock , ##args) -DHH(s_file_lock_stat, error_t, int *, int *) -#define treefs_s_file_lock_stat(h, args...) \ - _TREEFS_CHH(h, S_FILE_LOCK_STAT, s_file_lock_stat , ##args) -DHH(s_file_notice_changes, error_t, mach_port_t) -#define treefs_s_file_notice_changes(h, args...) \ - _TREEFS_CHH(h, S_FILE_NOTICE, s_file_notice_changes , ##args) -DHH(s_file_sync, error_t, int) -#define treefs_s_file_sync(h, args...) \ - _TREEFS_CHH(h, S_FILE_SYNC, s_file_sync , ##args) -DHH(s_file_getlinknode, error_t, file_t *, mach_msg_type_name_t *) -#define treefs_s_file_getlinknode(h, args...) \ - _TREEFS_CHH(h, S_FILE_GET_LINK_NODE, s_file_getlinknode , ##args) - -/* ---------------------------------------------------------------- */ -/* Hooks for IO rpcs. See <hurd/io.defs> for more info. */ - -DHH(s_io_write, error_t, char *, unsigned, off_t, int *) -#define treefs_s_io_write(h, args...) \ - _TREEFS_CHH(h, S_IO_WRITE, s_io_write , ##args) -DHH(s_io_read, error_t, char **, unsigned *, off_t, int) -#define treefs_s_io_read(h, args...) \ - _TREEFS_CHH(h, S_IO_READ, s_io_read , ##args) -DHH(s_io_seek, error_t, off_t, int, off_t *) -#define treefs_s_io_seek(h, args...) \ - _TREEFS_CHH(h, S_IO_SEEK, s_io_seek , ##args) -DHH(s_io_readable, error_t, unsigned *) -#define treefs_s_io_readable(h, args...) \ - _TREEFS_CHH(h, S_IO_READABLE, s_io_readable , ##args) -DHH(s_io_set_all_openmodes, error_t, int) -#define treefs_s_io_set_all_openmodes(h, args...) \ - _TREEFS_CHH(h, S_IO_SET_ALL_OPENMODES, s_io_set_all_openmodes , ##args) -DHH(s_io_get_openmodes, error_t, int *) -#define treefs_s_io_get_openmodes(h, args...) \ - _TREEFS_CHH(h, S_IO_GET_OPENMODES, s_io_get_openmodes , ##args) -DHH(s_io_set_some_openmodes, error_t, int) -#define treefs_s_io_set_some_openmodes(h, args...) \ - _TREEFS_CHH(h, S_IO_SET_SOME_OPENMODES, s_io_set_some_openmodes , ##args) -DHH(s_io_clear_some_openmodes, error_t, int) -#define treefs_s_io_clear_some_openmodes(h, args...) \ - _TREEFS_CHH(h, S_IO_CLEAR_SOME_OPENMODES, s_io_clear_some_openmodes , ##args) -DHH(s_io_async, error_t, mach_port_t, mach_port_t *, mach_msg_type_name_t *) -#define treefs_s_io_async(h, args...) \ - _TREEFS_CHH(h, S_IO_ASYNC, s_io_async , ##args) -DHH(s_io_mod_owner, error_t, pid_t) -#define treefs_s_io_mod_owner(h, args...) \ - _TREEFS_CHH(h, S_IO_MOD_OWNER, s_io_mod_owner , ##args) -DHH(s_io_get_owner, error_t, pid_t *) -#define treefs_s_io_get_owner(h, args...) \ - _TREEFS_CHH(h, S_IO_GET_OWNER, s_io_get_owner , ##args) -DHH(s_io_get_icky_async_id, error_t, mach_port_t *, mach_msg_type_name_t *) -#define treefs_s_io_get_icky_async_id(h, args...) \ - _TREEFS_CHH(h, S_IO_GET_ICKY_ASYNC_ID, s_io_get_icky_async_id , ##args) -DHH(s_io_select, error_t, int *, int *) -#define treefs_s_io_select(h, args...) \ - _TREEFS_CHH(h, S_IO_SELECT, s_io_select , ##args) -DHH(s_io_stat, error_t, io_statbuf_t *) -#define treefs_s_io_stat(h, args...) \ - _TREEFS_CHH(h, S_IO_STAT, s_io_stat , ##args) -DHH(s_io_reauthenticate, error_t, mach_port_t *, mach_msg_type_name_t *) -#define treefs_s_io_reauthenticate(h, args...) \ - _TREEFS_CHH(h, S_IO_REAUTHENTICATE, s_io_reauthenticate , ##args) -DHH(s_io_restrict_auth, error_t, - mach_port_t *, mach_msg_type_name_t *, uid_t *, int, gid_t *, int); -#define treefs_s_io_restrict_auth(h, args...) \ - _TREEFS_CHH(h, S_IO_RESTRICT_AUTH, s_io_restrict_auth , ##args) -DHH(s_io_duplicate, error_t, mach_port_t *, mach_msg_type_name_t *) -#define treefs_s_io_duplicate(h, args...) \ - _TREEFS_CHH(h, S_IO_DUPLICATE, s_io_duplicate , ##args) -DHH(s_io_server_version, error_t, char *, int *, int *, int *) -#define treefs_s_io_server_version(h, args...) \ - _TREEFS_CHH(h, S_IO_SERVER_VERSION, s_io_server_version , ##args) -DHH(s_io_map, error_t, mach_port_t *, mach_msg_type_name_t *, mach_port_t *, mach_msg_type_name_t *) -#define treefs_s_io_map(h, args...) \ - _TREEFS_CHH(h, S_IO_MAP, s_io_map , ##args) -DHH(s_io_map_cntl, error_t, mach_port_t *, mach_msg_type_name_t *) -#define treefs_s_io_map_cntl(h, args...) \ - _TREEFS_CHH(h, S_IO_MAP_CNTL, s_io_map_cntl , ##args) -DHH(s_io_release_conch, error_t, struct treefs_handle *) -#define treefs_s_io_release_conch(h, args...) \ - _TREEFS_CHH(h, S_IO_RELEASE_CONCH, s_io_release_conch, ##args) -DHH(s_io_eofnotify, error_t); -#define treefs_s_io_eofnotify(h, args...) \ - _TREEFS_CHH(h, S_IO_EOFNOTIFY, s_io_eofnotify , ##args) -DHH(s_io_prenotify, error_t, vm_offset_t, vm_offset_t); -#define treefs_s_io_prenotify(h, args...) \ - _TREEFS_CHH(h, S_IO_PRENOTIFY, s_io_prenotify , ##args) -DHH(s_io_postnotify, error_t, vm_offset_t, vm_offset_t); -#define treefs_s_io_postnotify(h, args...) \ - _TREEFS_CHH(h, S_IO_POSTNOTIFY, s_io_postnotify , ##args) -DHH(s_io_readnotify, error_t); -#define treefs_s_io_readnotify(h, args...) \ - _TREEFS_CHH(h, S_IO_READNOTIFY, s_io_readnotify , ##args) -DHH(s_io_readsleep, error_t); -#define treefs_s_io_readsleep(h, args...) \ - _TREEFS_CHH(h, S_IO_READSLEEP, s_io_readsleep , ##args) -DHH(s_io_sigio, error_t); -#define treefs_s_io_sigio(h, args...) \ - _TREEFS_CHH(h, S_IO_SIGIO, s_io_sigio , ##args) - -/* ---------------------------------------------------------------- */ -/* Hooks for directory RPCs. See <hurd/fs.defs> for more info. */ - -DHH(s_dir_lookup, error_t, - char *, int, mode_t, enum retry_type *, char *, - file_t *, mach_msg_type_name_t *); -#define treefs_s_dir_lookup(h, args...) \ - _TREEFS_CHH(h, S_DIR_LOOKUP, s_dir_lookup , ##args) -DHH(s_dir_readdir, error_t, char **, unsigned, int, int, vm_size_t, int *); -#define treefs_s_dir_readdir(h, args...) \ - _TREEFS_CHH(h, S_DIR_READDIR, s_dir_readdir , ##args) -DHH(s_dir_mkdir, error_t, char *, mode_t); -#define treefs_s_dir_mkdir(h, args...) \ - _TREEFS_CHH(h, S_DIR_MKDIR, s_dir_mkdir , ##args) -DHH(s_dir_rmdir, error_t, char *); -#define treefs_s_dir_rmdir(h, args...) \ - _TREEFS_CHH(h, S_DIR_RMDIR, s_dir_rmdir , ##args) -DHH(s_dir_unlink, error_t, char *); -#define treefs_s_dir_unlink(h, args...) \ - _TREEFS_CHH(h, S_DIR_UNLINK, s_dir_unlink , ##args) -DHH(s_dir_link, error_t, file_t, char *); -#define treefs_s_dir_link(h, args...) \ - _TREEFS_CHH(h, S_DIR_LINK, s_dir_link , ##args) -DHH(s_dir_rename, error_t, char *, file_t, char *); -#define treefs_s_dir_rename(h, args...) \ - _TREEFS_CHH(h, S_DIR_RENAME, s_dir_rename , ##args) -DHH(s_dir_mkfile, error_t, int, mode_t, mach_port_t *, mach_msg_type_name_t *); -#define treefs_s_dir_mkfile(h, args...) \ - _TREEFS_CHH(h, S_DIR_MKFILE, s_dir_mkfile , ##args) -DHH(s_dir_notice_changes, error_t, mach_port_t *, mach_msg_type_name_t *); -#define treefs_s_dir_notice_changes(h, args...) \ - _TREEFS_CHH(h, S_DIR_NOTICE_CHANGES, s_dir_notice_changes , ##args) - -/* ---------------------------------------------------------------- */ -/* fsys RPCs (called on the filesystem itself) */ - -DFH(s_fsys_getroot, error_t, - mach_port_t, uid_t *, unsigned, gid_t *, unsigned, int, - retry_type *, char *, file_t *, mach_msg_type_name_t *) -#define treefs_s_fsys_getroot(fsys, args...) \ - _TREEFS_CFH(fsys, S_FSYS_GETROOT, s_fsys_getroot , ##args) -DFH(s_fsys_set_options, error_t, char *, unsigned, int) -#define treefs_s_fsys_set_options(fsys, args...) \ - _TREEFS_CFH(fsys, S_FSYS_SET_OPTIONS, s_fsys_set_options , ##args) -DFH(s_fsys_goaway, error_t, int) -#define treefs_s_fsys_goaway(fsys, args...) \ - _TREEFS_CFH(fsys, S_FSYS_GOAWAY, s_fsys_goaway , ##args) -DFH(s_fsys_getfile, error_t, - uid_t *, unsigned, gid_t *, unsigned, char *, unsigned, - mach_port_t *, mach_msg_type_name_t *) -#define treefs_s_fsys_getfile(fsys, args...) \ - _TREEFS_CFH(fsys, S_FSYS_GETFILE, s_fsys_getfile , ##args) -DFH(s_fsys_syncfs, error_t, int, int) -#define treefs_s_fsys_syncfs(fsys, args...) \ - _TREEFS_CFH(fsys, S_FSYS_SYNCFS, s_fsys_syncfs , ##args) - -/* Turn off our shorthand notation. */ -#undef DHH - -/* ---------------------------------------------------------------- */ -/* Default routines for some hooks (each is the default value for the hook - with the same name minus the leading underscore). When you add something - here, you should also add it to the initialize code in defhooks.c. */ - -treefs_s_dir_lookup_t _treefs_s_dir_lookup; -treefs_s_fsys_getroot_t _treefs_s_fsys_getroot; - -#endif /* __TREEFS_S_HOOKS_H__ */ diff --git a/libtreefs/treefs.h b/libtreefs/treefs.h deleted file mode 100644 index 50cf91fe..00000000 --- a/libtreefs/treefs.h +++ /dev/null @@ -1,493 +0,0 @@ -/* Hierarchial filesystem support - - Copyright (C) 1995, 2002 Free Software Foundation, Inc. - - Written by Miles Bader <miles@gnu.org> - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __TREEFS_H__ -#define __TREEFS_H__ - -#include <errno.h> -#include <pthread.h> -#include <assert-backtrace.h> -#include <features.h> - -#include <sys/stat.h> - -#include <hurd/hurd_types.h> -#include <hurd/ports.h> -#include <hurd/fshelp.h> - -/* Include the hook calling macros and non-rpc hook definitions (to get - those, include "trees-s-hooks.h"). */ -#include "treefs-hooks.h" - -#ifdef TREEFS_DEFINE_EI -#define TREEFS_EI -#else -#define TREEFS_EI __extern_inline -#endif - -/* ---------------------------------------------------------------- */ - -typedef void (**treefs_hook_vector_t)(); - -/* A list of nodes. */ -struct treefs_node_list; - -/* Each user port referring to a file points to one of these. */ -struct treefs_handle -{ - struct port_info pi; - struct treefs_auth *auth; /* User identification */ - struct treefs_peropen *po; /* The io object itself */ - void *u; /* for user use */ -}; - -/* An authentication cookie. */ -struct treefs_auth -{ - int refs; - uid_t *uids, *gids; - int nuids, ngids; - int isroot; - void *u; /* for user use */ -}; - -/* Bits the user is permitted to set with io_*_openmodes */ -#define TREEFS_SETTABLE_FLAGS (O_APPEND|O_ASYNC|O_FSYNC|O_NONBLOCK|O_NOATIME) - -/* Bits that are turned off after open */ -#define TREEFS_OPENONLY_FLAGS (O_CREAT|O_EXCL|O_NOLINK|O_NOTRANS|O_NONBLOCK) - -struct treefs_peropen -{ - int refs; - int open_flags; - int user_lock_state; - - /* A port to the directory through which this open file was reached. */ - mach_port_t parent_port; - - void *u; /* for user use */ - - struct treefs_node *node; -}; - -/* A filesystem node in the tree. */ -struct treefs_node -{ - io_statbuf_t stat; - struct treefs_fsys *fsys; - - struct trans_link active_trans; - char *passive_trans; - struct lock_box user_lock; - - pthread_mutex_t lock; - unsigned refs, weak_refs; - - /* Node ops */ - treefs_hook_vector_t hooks; - - /* If this node is a directory, then this is the directory state. */ - struct treefs_node_list *children; - - void *u; /* for user use */ -}; - -struct treefs_node_list -{ - struct treefs_node **nodes; - unsigned short num_nodes, nodes_alloced; - char *names; - unsigned short names_len, names_alloced; -}; - -struct treefs_fsys -{ - struct port_info pi; - pthread_mutex_t lock; - - /* The root node in this filesystem. */ - struct treefs_node *root; - - /* The port for the node which this filesystem is translating. */ - mach_port_t underlying_port; - /* And stat info for it. */ - io_statbuf_t underlying_stat; - - /* Flags from the TREEFS_FSYS_ set. */ - int flags; - /* Max number of symlink expansions allowed. */ - unsigned max_symlinks; - /* Sync interval (in seconds). 0 means all operations should be - synchronous, any negative value means never sync. */ - int sync_interval; - - /* Values to return from a statfs. */ - int fs_type; - int fs_id; - - /* This is the hook vector that each new node in this filesystem starts out - with. */ - treefs_hook_vector_t hooks; - - /* The port bucket to which all of our ports belongs. */ - struct ports_bucket *port_bucket; - - /* Various classes of ports we know about. */ - struct port_class *handle_port_class; - - void *u; /* for user use */ -}; - -/* Filesystem flags. */ -#define TREEFS_FSYS_READONLY 0x1 - -/* ---------------------------------------------------------------- */ -/* In-core directory management routines (`mdir' == `memory dir'). These are - intended for keeping non-permanent directory state. If called on a - non-dir, ENOTDIR is returned. */ - -/* Add CHILD to DIR as NAME, replacing any existing entry. If OLD_CHILD is - NULL, and NAME already exists in dir, EEXIST is returned, otherwise, any - previous child is replaced and returned in OLD_CHILD. DIR should be - locked. */ -error_t treefs_mdir_add (struct treefs_node *dir, char *name, - struct treefs_node *child, - struct treefs_node **old_child); - -/* Remove any entry in DIR called NAME. If there is no such entry, ENOENT is - returned. If OLD_CHILD is non-NULL, any removed entry is returned in it. - DIR should be locked. */ -error_t treefs_mdir_remove (struct treefs_node *dir, char *name, - struct treefs_node **old_child); - -/* Returns in NODE any entry called NAME in DIR, or NULL (and ENOENT) if - there isn't such. DIR should be locked. */ -error_t treefs_mdir_get (struct treefs_node *dir, char *name, - struct treefs_node **node); - -/* Call FUN on each child of DIR; if FUN returns a non-zero value at any - point, stop iterating and return that value immediately. */ -error_t treefs_mdir_for_each (struct treefs_node *dir, - error_t (*fun)(struct treefs_node *node)); - -/* ---------------------------------------------------------------- */ -/* Functions for dealing with node lists. */ - -/* Return a new node list, or NULL if a memory allocation error occurs. */ -struct treefs_node_list *treefs_make_node_list (); - -/* Add NODE to LIST as NAME, replacing any existing entry. If OLD_NODE is - NULL, and an entry NAME already exists, EEXIST is returned, otherwise, any - previous child is replaced and returned in OLD_NODE. */ -error_t treefs_node_list_add (struct treefs_node_list *list, char *name, - struct treefs_node *node, - struct treefs_node **old_node); - -/* Remove any entry in LIST called NAME. If there is no such entry, ENOENT is - returned. If OLD_NODE is non-NULL, any removed entry is returned in it. */ -error_t treefs_node_list_remove (struct treefs_node_list *list, char *name, - struct treefs_node **old_node); - -/* Returns in NODE any entry called NAME in LIST, or NULL (and ENOENT) if - there isn't such. */ -error_t treefs_node_list_get (struct treefs_node_list *list, char *name, - struct treefs_node **node); - -/* Call FUN on each node in LIST; if FUN returns a non-zero value at any - point, stop iterating and return that value immediately. */ -error_t treefs_node_list_for_each (struct treefs_node_list *list, - error_t (*fun)(char *name, - struct treefs_node *node)); - -/* ---------------------------------------------------------------- */ -/* Functions for manipulating hook vectors. */ - -typedef void (*treefs_hook_vector_init_t[TREEFS_NUM_HOOKS])(); - -extern treefs_hook_vector_init_t treefs_default_hooks; - -/* Returns a copy of the treefs hook vector HOOKS, or a zero'd vector if HOOKS - is NULL. If HOOKS is NULL, treefs_default_hooks is used. If a memory - allocation error occurs, NULL is returned. */ -treefs_hook_vector_t treefs_hooks_clone (treefs_hook_vector_t hooks); - -/* Copies each non-NULL entry in OVERRIDES into HOOKS. */ -void treefs_hooks_override (treefs_hook_vector_t hooks, - treefs_hook_vector_t overrides); - -/* Sets the hook NUM in HOOKS to HOOK. */ -void treefs_hooks_set (treefs_hook_vector_t hooks, - unsigned num, void (*hook)()); - -/* ---------------------------------------------------------------- */ -/* Reference counting function (largely stolen from diskfs). */ - -extern pthread_spinlock_t treefs_node_refcnt_lock; - -extern void treefs_node_ref (struct treefs_node *node); -extern void treefs_node_release (struct treefs_node *node); -extern void treefs_node_unref (struct treefs_node *node); -extern void treefs_node_ref_weak (struct treefs_node *node); -extern void treefs_node_release_weak (struct treefs_node *node); -extern void treefs_node_unref_weak (struct treefs_node *node); - -#if defined(__USE_EXTERN_INLINES) || defined(TREEFS_DEFINE_EI) -/* Add a hard reference to a node. If there were no hard - references previously, then the node cannot be locked - (because you must hold a hard reference to hold the lock). */ -TREEFS_EI void -treefs_node_ref (struct treefs_node *node) -{ - int new_ref; - pthread_spin_lock (&treefs_node_refcnt_lock); - node->refs++; - new_ref = (node->refs == 1); - pthread_spin_unlock (&treefs_node_refcnt_lock); - if (new_ref) - { - pthread_mutex_lock (&node->lock); - treefs_node_new_refs (node); - pthread_mutex_unlock (&node->lock); - } -} - -/* Unlock node NODE and release a hard reference; if this is the last - hard reference and there are no links to the file then request - weak references to be dropped. */ -TREEFS_EI void -treefs_node_release (struct treefs_node *node) -{ - int tried_drop_weak_refs = 0; - - loop: - pthread_spin_lock (&treefs_node_refcnt_lock); - assert_backtrace (node->refs); - node->refs--; - if (node->refs + node->weak_refs == 0) - treefs_node_drop (node); - else if (node->refs == 0 && !tried_drop_weak_refs) - { - pthread_spin_unlock (&treefs_node_refcnt_lock); - treefs_node_lost_refs (node); - if (treefs_node_unlinked (node)) - { - /* There are no links. If there are weak references that - can be dropped, we can't let them postpone deallocation. - So attempt to drop them. But that's a user-supplied - routine, which might result in further recursive calls to - the ref-counting system. So we have to reacquire our - reference around the call to forestall disaster. */ - pthread_spin_unlock (&treefs_node_refcnt_lock); - node->refs++; - pthread_spin_unlock (&treefs_node_refcnt_lock); - - treefs_node_try_dropping_weak_refs (node); - - /* But there's no value in looping forever in this - routine; only try to drop weak references once. */ - tried_drop_weak_refs = 1; - - /* Now we can drop the reference back... */ - goto loop; - } - } - else - pthread_spin_unlock (&treefs_node_refcnt_lock); - pthread_mutex_unlock (&node->lock); -} - -/* Release a hard reference on NODE. If NODE is locked by anyone, then - this cannot be the last hard reference (because you must hold a - hard reference in order to hold the lock). If this is the last - hard reference and there are no links, then request weak references - to be dropped. */ -TREEFS_EI void -treefs_node_unref (struct treefs_node *node) -{ - int tried_drop_weak_refs = 0; - - loop: - pthread_spin_lock (&treefs_node_refcnt_lock); - assert_backtrace (node->refs); - node->refs--; - if (node->refs + node->weak_refs == 0) - { - pthread_mutex_lock (&node->lock); - treefs_node_drop (node); - } - else if (node->refs == 0) - { - pthread_mutex_lock (&node->lock); - pthread_spin_unlock (&treefs_node_refcnt_lock); - treefs_node_lost_refs (node); - if (treefs_node_unlinked(node) && !tried_drop_weak_refs) - { - /* Same issue here as in nodeut; see that for explanation */ - pthread_spin_unlock (&treefs_node_refcnt_lock); - node->refs++; - pthread_spin_unlock (&treefs_node_refcnt_lock); - - treefs_node_try_dropping_weak_refs (node); - tried_drop_weak_refs = 1; - - /* Now we can drop the reference back... */ - pthread_mutex_unlock (&node->lock); - goto loop; - } - pthread_mutex_unlock (&node->lock); - } - else - pthread_spin_unlock (&treefs_node_refcnt_lock); -} - -/* Add a weak reference to a node. */ -TREEFS_EI void -treefs_node_ref_weak (struct treefs_node *node) -{ - pthread_spin_lock (&treefs_node_refcnt_lock); - node->weak_refs++; - pthread_spin_unlock (&treefs_node_refcnt_lock); -} - -/* Unlock node NODE and release a weak reference */ -TREEFS_EI void -treefs_node_release_weak (struct treefs_node *node) -{ - pthread_spin_lock (&treefs_node_refcnt_lock); - assert_backtrace (node->weak_refs); - node->weak_refs--; - if (node->refs + node->weak_refs == 0) - treefs_node_drop (node); - else - { - pthread_spin_unlock (&treefs_node_refcnt_lock); - pthread_mutex_unlock (&node->lock); - } -} - -/* Release a weak reference on NODE. If NODE is locked by anyone, then - this cannot be the last reference (because you must hold a - hard reference in order to hold the lock). */ -TREEFS_EI void -treefs_node_unref_weak (struct treefs_node *node) -{ - pthread_spin_lock (&treefs_node_refcnt_lock); - assert_backtrace (node->weak_refs); - node->weak_refs--; - if (node->refs + node->weak_refs == 0) - { - pthread_mutex_lock (&node->lock); - treefs_node_drop (node); - } - else - pthread_spin_unlock (&treefs_node_refcnt_lock); -} -#endif /* Use extern inlines. */ - -/* ---------------------------------------------------------------- */ - -/* Return in PORT a send right for a new handle, pointing at the peropen PO, - with rights initialized from AUTH. */ -error_t -treefs_peropen_create_right (struct treefs_peropen *po, - struct treefs_auth *auth, - mach_port_t *port); - -/* Return a send right for a new handle and a new peropen, pointing at NODE, - with rights initialized from AUTH. MODE and PARENT_PORT are used to - initialize the corresponding fields in the new peropen. */ -error_t -treefs_node_create_right (struct treefs_node *node, int flags, - mach_port_t parent_port, struct treefs_auth *auth, - mach_port_t *port); - -/* ---------------------------------------------------------------- */ -/* Auth functions; copied from diskfs. */ - -extern int treefs_auth_has_uid (struct treefs_auth *auth, uid_t uid); -extern int treefs_auth_in_group (struct treefs_auth *auth, gid_t gid); - -#if defined(__USE_EXTERN_INLINES) || defined(TREEFS_DEFINE_EI) -/* Return nonzero iff the user identified by AUTH has uid UID. */ -TREEFS_EI int -treefs_auth_has_uid (struct treefs_auth *auth, uid_t uid) -{ - int i; - for (i = 0; i < auth->nuids; i++) - if (auth->uids[i] == uid) - return 1; - return 0; -} - -/* Return nonzero iff the user identified by AUTH has group GID. */ -TREEFS_EI int -treefs_auth_in_group (struct treefs_auth *auth, gid_t gid) -{ - int i; - for (i = 0; i < auth->ngids; i++) - if (auth->gids[i] == gid) - return 1; - return 0; -} -#endif /* Use extern inlines. */ - -/* ---------------------------------------------------------------- */ -/* Helper routines for dealing with translators. */ - -/* Return the active translator control port for NODE. If there is no - translator, active or passive, MACH_PORT_NULL is returned in CONTROL_PORT. - If there is a translator, it is started if necessary, and returned in - CONTROL_PORT. *DIR_PORT should be a port right to use as the new - translators parent directory. If it is MACH_PORT_NULL, a port is created - from DIR and PARENT_PORT and stored in *DIR_PORT; otherwise DIR and - PARENT_PORT are not used. Neither NODE or DIR should be locked when - calling this function. */ -error_t treefs_node_get_active_trans (struct treefs_node *node, - struct treefs_node *dir, - mach_port_t parent_port, - mach_port_t *control_port, - mach_port_t *dir_port); - -/* Drop the active translator CONTROL_PORT on NODE, unless it's no longer the - current active translator, in which case just drop a reference to it. */ -void treefs_node_drop_active_trans (struct treefs_node *node, - mach_port_t control_port); - -/* ---------------------------------------------------------------- */ -/* Basic node creation. */ - -/* Create a basic node, with one reference and no user-specific fields - initialized, and return it in NODE */ -error_t -treefs_create_node (struct treefs_fsys *fsys, struct treefs_node **node); - -/* Immediately destroy NODE, with no user-finalization. */ -error_t treefs_free_node (struct treefs_node *node); - -/* ---------------------------------------------------------------- */ -/* Some global variables. */ - -/* The port class used by treefs to make filesystem control ports. */ -struct port_class *treefs_fsys_port_class; - -#endif /* __TREEFS_H__ */ diff --git a/libtreefs/xinl.c b/libtreefs/xinl.c deleted file mode 100644 index ca7073a4..00000000 --- a/libtreefs/xinl.c +++ /dev/null @@ -1,5 +0,0 @@ -#define TREEFS_DEFINE_EI -#include "treefs.h" -#include "mig-decls.h" - -pthread_spinlock_t treefs_node_refcnt_lock = PTHREAD_SPINLOCK_INITIALIZER; diff --git a/mach-defpager/Makefile b/mach-defpager/Makefile index 9bf394e7..310be710 100644 --- a/mach-defpager/Makefile +++ b/mach-defpager/Makefile @@ -23,7 +23,7 @@ dir := mach-defpager makemode:= server target := mach-defpager -SRCS := default_pager.c kalloc.c wiring.c main.c setup.c +SRCS := default_pager.c wiring.c main.c setup.c OBJS := $(SRCS:.c=.o) \ $(addsuffix Server.o,\ memory_object default_pager memory_object_default exc) \ diff --git a/mach-defpager/default_pager.c b/mach-defpager/default_pager.c index 0596704e..8b1f37d3 100644 --- a/mach-defpager/default_pager.c +++ b/mach-defpager/default_pager.c @@ -47,12 +47,12 @@ #include "queue.h" #include "wiring.h" -#include "kalloc.h" #include "default_pager.h" #include <assert-backtrace.h> #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <stdarg.h> @@ -186,14 +186,14 @@ new_partition (const char *name, struct file_direct *fdp, size = atop(fdp->fd_size * fdp->fd_bsize); bmsize = howmany(size, NB_BM) * sizeof(bm_entry_t); - part = (partition_t) kalloc(sizeof(struct part)); + part = (partition_t) malloc(sizeof(struct part)); pthread_mutex_init(&part->p_lock, NULL); - part->name = (char*) kalloc(n + 1); + part->name = (char*) malloc(n + 1); strcpy(part->name, name); part->total_size = size; part->free = size; part->id = id; - part->bitmap = (bm_entry_t *)kalloc(bmsize); + part->bitmap = (bm_entry_t *)malloc(bmsize); part->going_away= FALSE; part->file = fdp; @@ -337,9 +337,9 @@ new_partition (const char *name, struct file_direct *fdp, hdr->version, name); vm_deallocate(mach_task_self(), raddr, rsize); - kfree(part->bitmap, bmsize); - kfree(part->name, strlen(part->name) + 1); - kfree(part, sizeof *part); + free(part->bitmap); + free(part->name); + free(part); return 0; } else @@ -389,9 +389,9 @@ new_partition (const char *name, struct file_direct *fdp, "Cannot find Linux swap signature page! " "SKIPPING %s (%uk partition)!", name, part->total_size * (vm_page_size / 1024)); - kfree(part->bitmap, bmsize); - kfree(part->name, strlen(part->name) + 1); - kfree(part, sizeof *part); + free(part->bitmap); + free(part->name); + free(part); part = 0; } else @@ -433,7 +433,7 @@ create_paging_partition(const char *name, n = i ? (i<<1) : 2; new_list = (partition_t *) - kalloc( n * sizeof(partition_t) ); + malloc( n * sizeof(partition_t) ); if (new_list == 0) no_paging_space(TRUE); memset (new_list, 0, n * sizeof(partition_t)); if (i) { @@ -442,7 +442,7 @@ create_paging_partition(const char *name, } all_partitions.partition_list = new_list; all_partitions.n_partitions = n; - if (i) kfree(old_list, i*sizeof(partition_t)); + if (i) free(old_list); } set_partition_of(i, part); } @@ -635,7 +635,7 @@ dp_map_t pager_get_direct_map(pager) init_value = (dp_map_t)NO_BLOCK; } - mapptr = (dp_map_t) kalloc(alloc_size); + mapptr = (dp_map_t) malloc(alloc_size); for (emapptr = &mapptr[(alloc_size-1) / sizeof(vm_offset_t)]; emapptr >= mapptr; emapptr--) @@ -686,11 +686,11 @@ pager_alloc(pager, part, size) #ifdef CHECKSUM if (INDIRECT_PAGEMAP(size)) { mapptr = (vm_offset_t *) - kalloc(INDIRECT_PAGEMAP_SIZE(size)); + malloc(INDIRECT_PAGEMAP_SIZE(size)); for (i = INDIRECT_PAGEMAP_ENTRIES(size); --i >= 0;) mapptr[i] = 0; } else { - mapptr = (vm_offset_t *) kalloc(PAGEMAP_SIZE(size)); + mapptr = (vm_offset_t *) malloc(PAGEMAP_SIZE(size)); for (i = 0; i < size; i++) mapptr[i] = NO_CHECKSUM; } @@ -834,24 +834,24 @@ pager_extend(pager, new_size) * a larger indirect block. */ new_mapptr = (dp_map_t) - kalloc(INDIRECT_PAGEMAP_SIZE(new_size)); + malloc(INDIRECT_PAGEMAP_SIZE(new_size)); old_mapptr = pager_get_direct_map(pager); for (i = 0; i < INDIRECT_PAGEMAP_ENTRIES(old_size); i++) new_mapptr[i] = old_mapptr[i]; for (; i < INDIRECT_PAGEMAP_ENTRIES(new_size); i++) new_mapptr[i].indirect = (dp_map_t)0; - kfree((char *)old_mapptr, INDIRECT_PAGEMAP_SIZE(old_size)); + free((char *)old_mapptr); pager->map = new_mapptr; pager->size = new_size; #ifdef CHECKSUM new_mapptr = (vm_offset_t *) - kalloc(INDIRECT_PAGEMAP_SIZE(new_size)); + malloc(INDIRECT_PAGEMAP_SIZE(new_size)); old_mapptr = pager->checksum; for (i = 0; i < INDIRECT_PAGEMAP_ENTRIES(old_size); i++) new_mapptr[i] = old_mapptr[i]; for (; i < INDIRECT_PAGEMAP_ENTRIES(new_size); i++) new_mapptr[i] = 0; - kfree((char *)old_mapptr, INDIRECT_PAGEMAP_SIZE(old_size)); + free((char *)old_mapptr); pager->checksum = new_mapptr; #endif /* CHECKSUM */ #if DEBUG_READER_CONFLICTS @@ -879,13 +879,13 @@ pager_extend(pager, new_size) /* * Allocate new second-level map first. */ - new_mapptr = (dp_map_t) kalloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); + new_mapptr = (dp_map_t) malloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); old_mapptr = pager_get_direct_map(pager); for (i = 0; i < old_size; i++) new_mapptr[i] = old_mapptr[i]; for (; i < PAGEMAP_ENTRIES; i++) invalidate_block(new_mapptr[i]); - kfree((char *)old_mapptr, PAGEMAP_SIZE(old_size)); + free((char *)old_mapptr); old_mapptr = new_mapptr; #if 0 @@ -900,7 +900,7 @@ pager_extend(pager, new_size) * Now allocate indirect map. */ new_mapptr = (dp_map_t) - kalloc(INDIRECT_PAGEMAP_SIZE(new_size)); + malloc(INDIRECT_PAGEMAP_SIZE(new_size)); new_mapptr[0].indirect = old_mapptr; for (i = 1; i < INDIRECT_PAGEMAP_ENTRIES(new_size); i++) new_mapptr[i].indirect = 0; @@ -910,20 +910,20 @@ pager_extend(pager, new_size) /* * Allocate new second-level map first. */ - new_mapptr = (vm_offset_t *)kalloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); + new_mapptr = (vm_offset_t *)malloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); old_mapptr = pager->checksum; for (i = 0; i < old_size; i++) new_mapptr[i] = old_mapptr[i]; for (; i < PAGEMAP_ENTRIES; i++) new_mapptr[i] = NO_CHECKSUM; - kfree((char *)old_mapptr, PAGEMAP_SIZE(old_size)); + free((char *)old_mapptr); old_mapptr = new_mapptr; /* * Now allocate indirect map. */ new_mapptr = (vm_offset_t *) - kalloc(INDIRECT_PAGEMAP_SIZE(new_size)); + malloc(INDIRECT_PAGEMAP_SIZE(new_size)); new_mapptr[0] = (vm_offset_t) old_mapptr; for (i = 1; i < INDIRECT_PAGEMAP_ENTRIES(new_size); i++) new_mapptr[i] = 0; @@ -938,24 +938,24 @@ pager_extend(pager, new_size) /* * Enlarging a direct block. */ - new_mapptr = (dp_map_t) kalloc(PAGEMAP_SIZE(new_size)); + new_mapptr = (dp_map_t) malloc(PAGEMAP_SIZE(new_size)); old_mapptr = pager_get_direct_map(pager); for (i = 0; i < old_size; i++) new_mapptr[i] = old_mapptr[i]; for (; i < new_size; i++) invalidate_block(new_mapptr[i]); - kfree((char *)old_mapptr, PAGEMAP_SIZE(old_size)); + free((char *)old_mapptr); pager->map = new_mapptr; pager->size = new_size; #ifdef CHECKSUM new_mapptr = (vm_offset_t *) - kalloc(PAGEMAP_SIZE(new_size)); + malloc(PAGEMAP_SIZE(new_size)); old_mapptr = pager->checksum; for (i = 0; i < old_size; i++) new_mapptr[i] = old_mapptr[i]; for (; i < new_size; i++) new_mapptr[i] = NO_CHECKSUM; - kfree((char *)old_mapptr, PAGEMAP_SIZE(old_size)); + free((char *)old_mapptr); pager->checksum = new_mapptr; #endif /* CHECKSUM */ #if DEBUG_READER_CONFLICTS @@ -1016,7 +1016,7 @@ pager_truncate(dpager_t pager, vm_size_t new_size) /* in pages */ const dp_map_t mapptr = pager->map[i].indirect; pager->map[i].indirect = (dp_map_t)0; dealloc_direct (mapptr, PAGEMAP_ENTRIES, 0); - kfree ((char *)mapptr, PAGEMAP_SIZE(PAGEMAP_ENTRIES)); + free ((char *)mapptr); } /* Now truncate what's now the final nonempty direct block. */ @@ -1027,9 +1027,9 @@ pager_truncate(dpager_t pager, vm_size_t new_size) /* in pages */ if (INDIRECT_PAGEMAP (new_size)) { const dp_map_t old_mapptr = pager->map; - pager->map = (dp_map_t) kalloc (INDIRECT_PAGEMAP_SIZE(new_size)); + pager->map = (dp_map_t) malloc (INDIRECT_PAGEMAP_SIZE(new_size)); memcpy (pager->map, old_mapptr, INDIRECT_PAGEMAP_SIZE(new_size)); - kfree ((char *) old_mapptr, INDIRECT_PAGEMAP_SIZE (old_size)); + free ((char *) old_mapptr); } else { @@ -1037,7 +1037,7 @@ pager_truncate(dpager_t pager, vm_size_t new_size) /* in pages */ a one-level map. We already have that map, as the first and only nonempty element in our indirect map. */ const dp_map_t mapptr = pager->map[0].indirect; - kfree((char *)pager->map, INDIRECT_PAGEMAP_SIZE(old_size)); + free((char *)pager->map); pager->map = mapptr; } } @@ -1046,16 +1046,11 @@ pager_truncate(dpager_t pager, vm_size_t new_size) /* in pages */ { /* First deallocate pages in the truncated region. */ dealloc_direct (pager->map, old_size, new_size); - /* Now reduce the size of the direct map itself. We don't bother - with kalloc/kfree if it's not shrinking enough that kalloc.c - would actually use less. */ - if (PAGEMAP_SIZE (new_size) <= PAGEMAP_SIZE (old_size) / 2) - { - const dp_map_t old_mapptr = pager->map; - pager->map = (dp_map_t) kalloc (PAGEMAP_SIZE (new_size)); - memcpy (pager->map, old_mapptr, PAGEMAP_SIZE (new_size)); - kfree ((char *) old_mapptr, PAGEMAP_SIZE (old_size)); - } + /* Now reduce the size of the direct map itself. */ + const dp_map_t old_mapptr = pager->map; + pager->map = (dp_map_t) malloc (PAGEMAP_SIZE (new_size)); + memcpy (pager->map, old_mapptr, PAGEMAP_SIZE (new_size)); + free ((char *) old_mapptr); } done: @@ -1396,7 +1391,7 @@ pager_write_offset(pager, offset) int i; ddprintf ("pager_write_offset: allocating indirect\n"); - mapptr = (dp_map_t) kalloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); + mapptr = (dp_map_t) malloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); if (mapptr == 0) { /* out of space! */ no_paging_space(TRUE); @@ -1411,7 +1406,7 @@ pager_write_offset(pager, offset) int j; cksumptr = (vm_offset_t *) - kalloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); + malloc(PAGEMAP_SIZE(PAGEMAP_ENTRIES)); if (cksumptr == 0) { /* out of space! */ no_paging_space(TRUE); @@ -1510,21 +1505,20 @@ pager_dealloc(pager) pager_dealloc_page(block.block.p_index, block.block.p_offset, TRUE); } - kfree((char *)mapptr, PAGEMAP_SIZE(PAGEMAP_ENTRIES)); + free((char *)mapptr); pager->map[i].indirect = (dp_map_t) 0; } } - kfree((char *)pager->map, INDIRECT_PAGEMAP_SIZE(pager->size)); + free((char *)pager->map); pager->map = (dp_map_t) 0; #ifdef CHECKSUM for (i = INDIRECT_PAGEMAP_ENTRIES(pager->size); --i >= 0; ) { mapptr = (vm_offset_t *)pager->checksum[i]; if (mapptr) { - kfree((char *)mapptr, PAGEMAP_SIZE(PAGEMAP_ENTRIES)); + free((char *)mapptr); } } - kfree((char *)pager->checksum, - INDIRECT_PAGEMAP_SIZE(pager->size)); + free((char *)pager->checksum); #endif /* CHECKSUM */ } else { @@ -1535,10 +1529,10 @@ pager_dealloc(pager) pager_dealloc_page(block.block.p_index, block.block.p_offset, TRUE); } - kfree((char *)pager->map, PAGEMAP_SIZE(pager->size)); + free((char *)pager->map); pager->map = (dp_map_t) 0; #ifdef CHECKSUM - kfree((char *)pager->checksum, PAGEMAP_SIZE(pager->size)); + free((char *)pager->checksum); #endif /* CHECKSUM */ } } @@ -1911,9 +1905,9 @@ dprintf("Partition x%p (id x%x) for %s, all_ok %d\n", part, id, name, all_ok); set_partition_of(pindex, 0); *pp_private = part->file; - kfree(part->bitmap, howmany(part->total_size, NB_BM) * sizeof(bm_entry_t)); - kfree(part->name, strlen(part->name) + 1); - kfree(part, sizeof(struct part)); + free(part->bitmap); + free(part->name); + free(part); dprintf("%s Removed paging partition %s\n", my_name, name); return KERN_SUCCESS; } @@ -2124,7 +2118,7 @@ default_pager_t pager_port_alloc(size) default_pager_t ds; p_index_t part; - ds = (default_pager_t) kalloc(sizeof *ds); + ds = (default_pager_t) malloc(sizeof *ds); if (ds == DEFAULT_PAGER_NULL) panic("%spager_port_alloc",my_name); memset ((char *)ds, 0, sizeof *ds); @@ -2441,7 +2435,7 @@ void default_pager_no_senders(ds, seqno, mscount) /* * Do this *after* deallocating the port name */ - kfree((char *) ds, sizeof(*ds)); + free((char *) ds); /* * Recover memory that we might have wasted because @@ -2453,7 +2447,7 @@ void default_pager_no_senders(ds, seqno, mscount) ds = (default_pager_t) queue_first(&all_pagers.leak_queue); queue_remove_first(&all_pagers.leak_queue, ds, default_pager_t, links); - kfree((char *) ds, sizeof(*ds)); + free((char *) ds); } pthread_mutex_unlock(&all_pagers.lock); @@ -3011,7 +3005,7 @@ start_default_pager_thread(internal) kern_return_t kr; error_t err; - ndpt = (default_pager_thread_t *) kalloc(sizeof *ndpt); + ndpt = (default_pager_thread_t *) malloc(sizeof *ndpt); if (ndpt == 0) panic(my_name); @@ -3176,7 +3170,7 @@ S_default_pager_object_create (mach_port_t pager, &port); if (result != KERN_SUCCESS) { - kfree ((char *) ds, sizeof *ds); + free ((char *) ds); return result; } diff --git a/mach-defpager/kalloc.c b/mach-defpager/kalloc.c deleted file mode 100644 index 33566438..00000000 --- a/mach-defpager/kalloc.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1993-1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * File: kern/kalloc.c - * Author: Avadis Tevanian, Jr. - * Date: 1985 - * - * General kernel memory allocator. This allocator is designed - * to be used by the kernel to manage dynamic memory fast. - */ - -#include <mach.h> -#include <pthread.h> /* for spin locks */ -#include <malloc.h> /* for malloc_hook/free_hook */ - -#include "wiring.h" - -static void init_hook (void); -static void *malloc_hook (size_t size, const void *caller); -static void *realloc_hook (void *ptr, size_t size, const void *caller); -static void *memalign_hook (size_t alignment, size_t size, const void *caller); -static void free_hook (void *ptr, const void *caller); - -/* GNU libc 2.14 defines this macro to declare hook variables as volatile. - Define it as empty for older libc versions. */ -#ifndef __MALLOC_HOOK_VOLATILE -# define __MALLOC_HOOK_VOLATILE -#endif - -void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void) = init_hook; - - -/* #define DEBUG */ - -/* - * All allocations of size less than kalloc_max are rounded to the - * next highest power of 2. - */ -vm_size_t kalloc_max; /* max before we use vm_allocate */ -#define MINSIZE sizeof(vm_offset_t) /* minimum allocation size */ - -struct free_list { - pthread_spinlock_t lock; - vm_offset_t head; /* head of free list */ -#ifdef DEBUG - int count; -#endif /*DEBUG*/ -}; - -#define KLIST_MAX 13 - /* sizes: 4, 8, 16, 32, 64, - 128, 256, 512, 1024, - 2048, 4096, 8192, 16384 */ -struct free_list kfree_list[KLIST_MAX]; - -pthread_spinlock_t kget_space_lock; -vm_offset_t kalloc_next_space = 0; -vm_offset_t kalloc_end_of_space = 0; - -vm_size_t kalloc_wasted_space = 0; - -boolean_t kalloc_initialized = FALSE; - -/* - * Initialize the memory allocator. This should be called only - * once on a system wide basis (i.e. first processor to get here - * does the initialization). - * - * This initializes all of the zones. - */ - -void kalloc_init(void) -{ - int i; - - /* - * Support free lists for items up to vm_page_size or - * 16Kbytes, whichever is less. - */ - - if (vm_page_size > (MINSIZE << (KLIST_MAX-1))) - kalloc_max = (MINSIZE << (KLIST_MAX-1)); - else - kalloc_max = vm_page_size; - - for (i = 0; i < KLIST_MAX; i++) { - pthread_spin_init(&kfree_list[i].lock, PTHREAD_PROCESS_PRIVATE); - kfree_list[i].head = 0; - } - pthread_spin_init(&kget_space_lock, PTHREAD_PROCESS_PRIVATE); - - /* - * Do not allocate memory at address 0. - */ - kalloc_next_space = vm_page_size; - kalloc_end_of_space = vm_page_size; -} - -/* - * Contiguous space allocator for items of less than a page size. - */ -vm_offset_t kget_space(vm_offset_t size) -{ - vm_size_t space_to_add = 0; - vm_offset_t new_space = 0; - vm_offset_t addr; - - pthread_spin_lock(&kget_space_lock); - while (kalloc_next_space + size > kalloc_end_of_space) { - /* - * Add at least one page to allocation area. - */ - space_to_add = round_page(size); - - if (new_space == 0) { - /* - * Unlock and allocate memory. - * Try to make it contiguous with the last - * allocation area. - */ - pthread_spin_unlock(&kget_space_lock); - - new_space = kalloc_end_of_space; - if (vm_map(mach_task_self(), - &new_space, space_to_add, (vm_offset_t) 0, TRUE, - MEMORY_OBJECT_NULL, (vm_offset_t) 0, FALSE, - VM_PROT_DEFAULT, VM_PROT_ALL, VM_INHERIT_DEFAULT) - != KERN_SUCCESS) - return 0; - pthread_spin_lock(&kget_space_lock); - continue; - } - - /* - * Memory was allocated in a previous iteration. - * Check whether the new region is contiguous with the - * old one. - */ - if (new_space != kalloc_end_of_space) { - /* - * Throw away the remainder of the old space, - * and start a new one. - */ - kalloc_wasted_space += - kalloc_end_of_space - kalloc_next_space; - kalloc_next_space = new_space; - } - kalloc_end_of_space = new_space + space_to_add; - - new_space = 0; - } - - addr = kalloc_next_space; - kalloc_next_space += size; - pthread_spin_unlock(&kget_space_lock); - - if (new_space != 0) - (void) vm_deallocate(mach_task_self(), new_space, space_to_add); - - return addr; -} - -void *kalloc(vm_size_t size) -{ - vm_size_t allocsize; - vm_offset_t addr; - struct free_list *fl; - - if (!kalloc_initialized) { - kalloc_init(); - kalloc_initialized = TRUE; - } - - /* compute the size of the block that we will actually allocate */ - - allocsize = size; - if (size <= kalloc_max) { - allocsize = MINSIZE; - fl = kfree_list; - while (allocsize < size) { - allocsize <<= 1; - fl++; - } - } - - /* - * If our size is still small enough, check the queue for that size - * and allocate. - */ - - if (allocsize <= kalloc_max) { - pthread_spin_lock(&fl->lock); - if ((addr = fl->head) != 0) { - fl->head = *(vm_offset_t *)addr; -#ifdef DEBUG - fl->count--; -#endif - pthread_spin_unlock(&fl->lock); - } - else { - pthread_spin_unlock(&fl->lock); - addr = kget_space(allocsize); - } - } - else { - if (vm_allocate(mach_task_self(), &addr, allocsize, TRUE) - != KERN_SUCCESS) - addr = 0; - } - return (void *) addr; -} - -void -kfree( void *data, - vm_size_t size) -{ - vm_size_t freesize; - struct free_list *fl; - - freesize = size; - if (size <= kalloc_max) { - freesize = MINSIZE; - fl = kfree_list; - while (freesize < size) { - freesize <<= 1; - fl++; - } - } - - if (freesize <= kalloc_max) { - pthread_spin_lock(&fl->lock); - *(vm_offset_t *)data = fl->head; - fl->head = (vm_offset_t) data; -#ifdef DEBUG - fl->count++; -#endif - pthread_spin_unlock(&fl->lock); - } - else { - (void) vm_deallocate(mach_task_self(), (vm_offset_t)data, freesize); - } -} - -static void -init_hook (void) -{ - __malloc_hook = malloc_hook; - __realloc_hook = realloc_hook; - __memalign_hook = memalign_hook; - __free_hook = free_hook; -} - -static void * -malloc_hook (size_t size, const void *caller) -{ - return (void *) kalloc ((vm_size_t) size); -} - -static void * -realloc_hook (void *ptr, size_t size, const void *caller) -{ - panic("realloc_hook not implemented"); -} - -static void * -memalign_hook (size_t alignment, size_t size, const void *caller) -{ - if (alignment > vm_page_size) - panic("memalign_hook not implemented"); - return malloc_hook(size, caller); -} - -static void -free_hook (void *ptr, const void *caller) -{ - /* Just ignore harmless attempts at cleanliness. */ - /* panic("free not implemented"); */ -} - -void malloc_fork_prepare() -{ -} - -void malloc_fork_parent() -{ -} - -void malloc_fork_child() -{ -} diff --git a/mach-defpager/kalloc.h b/mach-defpager/kalloc.h deleted file mode 100644 index 8f52f1a5..00000000 --- a/mach-defpager/kalloc.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Backing store access callbacks for Hurd version of Mach default pager. - Copyright (C) 2012 Free Software Foundation, Inc. - - This file is part of the GNU Hurd. - - The GNU Hurd 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 2, or (at - your option) any later version. - - The GNU Hurd 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* - * General kernel memory allocator. - */ - -#ifndef _KALLOC_H_ -#define _KALLOC_H_ - -void *kalloc (vm_size_t size); -void kfree (void *data, vm_size_t size); - -#endif /* _KALLOC_H_ */ diff --git a/mach-defpager/main.c b/mach-defpager/main.c index 71615c8f..95e66703 100644 --- a/mach-defpager/main.c +++ b/mach-defpager/main.c @@ -32,6 +32,7 @@ #include <error.h> #include <signal.h> #include <string.h> +#include <sys/mman.h> /* XXX */ #include <fcntl.h> @@ -89,6 +90,10 @@ main (int argc, char **argv) if (err) error (1, err, "cannot get privileged ports"); + err = mlockall(MCL_CURRENT | MCL_FUTURE); + if (err) + error (1, errno, "cannot lock all memory"); + defpager = MACH_PORT_NULL; err = vm_set_default_memory_manager (bootstrap_master_host_port, &defpager); if (err) diff --git a/mach-defpager/setup.c b/mach-defpager/setup.c index 94685c0e..0fc4d9d4 100644 --- a/mach-defpager/setup.c +++ b/mach-defpager/setup.c @@ -24,9 +24,9 @@ #include <mach.h> #include <string.h> #include <strings.h> +#include <stdlib.h> #include "default_pager.h" -#include "kalloc.h" #include "file_io.h" #include "default_pager_S.h" @@ -74,7 +74,7 @@ S_default_pager_paging_storage (mach_port_t pager, /* We can't write disk blocks larger than pages. */ return EINVAL; - fdp = kalloc (offsetof (struct file_direct, runs[nrun])); + fdp = malloc (offsetof (struct file_direct, runs[nrun])); if (fdp == 0) return ENOMEM; @@ -89,7 +89,7 @@ S_default_pager_paging_storage (mach_port_t pager, fdp->runs[i].length = runs[i + 1]; if (fdp->runs[i].start + fdp->runs[i].length > devsize) { - kfree (fdp, offsetof (struct file_direct, runs[nrun])); + free (fdp); return EINVAL; } fdp->fd_size += fdp->runs[i].length; @@ -269,7 +269,7 @@ add_paging_file(master_device_port, file_name, linux_signature) else { struct file_direct *fdp; - fdp = kalloc (offsetof (struct file_direct, runs[1])); + fdp = malloc (offsetof (struct file_direct, runs[1])); if (fdp == 0) return ENOMEM; @@ -301,7 +301,7 @@ remove_paging_file (char *file_name) if (kr == KERN_SUCCESS && fdp != 0) { mach_port_deallocate (mach_task_self (), fdp->device); - kfree (fdp, (char *) &fdp->runs[fdp->nruns] - (char *) fdp); + free (fdp); } return kr; } diff --git a/nfs/Makefile b/nfs/Makefile index 265d0273..32cf4f53 100644 --- a/nfs/Makefile +++ b/nfs/Makefile @@ -30,3 +30,6 @@ HURDLIBS = netfs fshelp iohelp ports ihash shouldbeinlibc LDLIBS = -lpthread include ../Makeconf + +CFLAGS += $(libtirpc_CFLAGS) +LDLIBS += $(libtirpc_LIBS) diff --git a/nfs/mount.c b/nfs/mount.c index 29b203aa..f8318c27 100644 --- a/nfs/mount.c +++ b/nfs/mount.c @@ -20,6 +20,7 @@ #define malloc a_byte_for_every_bozotic_sun_lossage_and_youd_need_a_lotta_ram #include <rpc/types.h> +#include <rpc/xdr.h> #undef TRUE /* Get rid of sun defs. */ #undef FALSE #undef malloc diff --git a/nfsd/Makefile b/nfsd/Makefile index 5dc9a4da..ef75db03 100644 --- a/nfsd/Makefile +++ b/nfsd/Makefile @@ -30,3 +30,6 @@ LDLIBS = -lpthread include ../Makeconf CPPFLAGS += -DLOCALSTATEDIR=\"$(localstatedir)\" + +CFLAGS += $(libtirpc_CFLAGS) +LDLIBS += $(libtirpc_LIBS) diff --git a/nfsd/cache.c b/nfsd/cache.c index 45234d89..d3ee7659 100644 --- a/nfsd/cache.c +++ b/nfsd/cache.c @@ -32,11 +32,11 @@ #include "nfsd.h" -#undef TRUE -#undef FALSE #define malloc spoogie_woogie /* ugh^2. */ #include <rpc/types.h> #include <rpc/auth.h> +#undef TRUE +#undef FALSE #undef malloc #define IDHASH_TABLE_SIZE 1024 diff --git a/nfsd/loop.c b/nfsd/loop.c index f2d6d546..d94c5d10 100644 --- a/nfsd/loop.c +++ b/nfsd/loop.c @@ -23,14 +23,14 @@ #include "nfsd.h" -#include <rpc/pmap_prot.h> #include "../nfs/mount.h" -#undef TRUE -#undef FALSE #define malloc spoogie_woogie /* barf */ -#include <rpc/xdr.h> #include <rpc/types.h> +#include <rpc/xdr.h> +#undef TRUE +#undef FALSE +#include <rpc/pmap_prot.h> #include <rpc/auth.h> #include <rpc/rpc_msg.h> #undef malloc diff --git a/nfsd/main.c b/nfsd/main.c index ee14e240..3f1fa9a5 100644 --- a/nfsd/main.c +++ b/nfsd/main.c @@ -21,6 +21,7 @@ #include "nfsd.h" #include <stdio.h> #include <unistd.h> +#include <rpc/xdr.h> #include <rpc/pmap_prot.h> #include <maptime.h> #include <hurd.h> @@ -31,6 +31,7 @@ #include "nfsd.h" #include "../nfs/mount.h" /* XXX */ +#include <rpc/xdr.h> #include <rpc/pmap_prot.h> static error_t diff --git a/pci-arbiter/main.c b/pci-arbiter/main.c index b2c37f79..510e7dbc 100644 --- a/pci-arbiter/main.c +++ b/pci-arbiter/main.c @@ -102,17 +102,6 @@ pci_device_close (void *d) return 0; } -static void -pci_device_shutdown (mach_port_t dosync_handle) -{ - // Free all libpciaccess resources - pci_system_cleanup (); - - ports_destroy_right (&pci_control_port); - - netfs_shutdown (FSYS_GOAWAY_FORCE); -} - static struct machdev_device_emulation_ops pci_arbiter_emulation_ops = { NULL, NULL, @@ -131,7 +120,7 @@ static struct machdev_device_emulation_ops pci_arbiter_emulation_ops = { NULL, NULL, NULL, - pci_device_shutdown, + NULL, }; int @@ -203,19 +192,19 @@ main (int argc, char **argv) { error_t err; mach_port_t bootstrap; - mach_port_t disk_server_task; + mach_port_t next_task; pthread_t t, nt; file_t underlying_node = MACH_PORT_NULL; /* Parse options */ alloc_file_system (&fs); argp_parse (netfs_runtime_argp, argc, argv, 0, 0, 0); - disk_server_task = fs->params.disk_server_task; + next_task = fs->params.next_task; - if (disk_server_task != MACH_PORT_NULL) + if (next_task != MACH_PORT_NULL) { machdev_register (&pci_arbiter_emulation_ops); - machdev_trivfs_init (argc, argv, disk_server_task, "pci", "/servers/bus/pci", &bootstrap); + machdev_trivfs_init (argc, argv, next_task, "pci", NULL /* _SERVERS_BUS "pci" */, &bootstrap); machdev_device_init (); err = pthread_create (&t, NULL, machdev_server, NULL); if (err) @@ -242,7 +231,7 @@ main (int argc, char **argv) if (err) error (1, err, "Starting the PCI system"); - if (disk_server_task != MACH_PORT_NULL) + if (next_task != MACH_PORT_NULL) { void *run_server(void *arg) { machdev_trivfs_server(bootstrap); @@ -255,7 +244,7 @@ main (int argc, char **argv) /* Timer started, quickly do all these next, before we call rump_init */ } - if (disk_server_task == MACH_PORT_NULL) + if (next_task == MACH_PORT_NULL) underlying_node = netfs_startup (bootstrap, O_READ); /* Create the root node first */ @@ -263,7 +252,7 @@ main (int argc, char **argv) if (err) error (1, err, "Creating the root node"); - if (disk_server_task != MACH_PORT_NULL) + if (next_task != MACH_PORT_NULL) pcifs_startup (bootstrap, O_READ); err = init_file_system (fs); diff --git a/pci-arbiter/options.c b/pci-arbiter/options.c index 141c69e3..73f74ca3 100644 --- a/pci-arbiter/options.c +++ b/pci-arbiter/options.c @@ -241,8 +241,8 @@ parse_opt (int opt, char *arg, struct argp_state *state) case 'n': h->ncache_len = atoi (arg); break; - case 'T': - h->disk_server_task = atoi (arg); + case 'N': + h->next_task = atoi (arg); break; case 'H': h->host_priv_port = atoi (arg); @@ -259,7 +259,7 @@ parse_opt (int opt, char *arg, struct argp_state *state) h->permsets = 0; h->num_permsets = 0; h->ncache_len = NODE_CACHE_MAX; - h->disk_server_task = MACH_PORT_NULL; + h->next_task = MACH_PORT_NULL; h->host_priv_port = MACH_PORT_NULL; h->dev_master_port = MACH_PORT_NULL; err = parse_hook_add_set (h); @@ -299,7 +299,7 @@ parse_opt (int opt, char *arg, struct argp_state *state) fs->params.node_cache_max = h->ncache_len; /* Set bootstrap ports */ - fs->params.disk_server_task = h->disk_server_task; + fs->params.next_task = h->next_task; _hurd_host_priv = h->host_priv_port; _hurd_device_master = h->dev_master_port; @@ -381,8 +381,8 @@ netfs_append_args (char **argz, size_t * argz_len) if (fs->params.node_cache_max != NODE_CACHE_MAX) ADD_OPT ("--ncache=%u", fs->params.node_cache_max); - if (fs->params.disk_server_task != MACH_PORT_NULL) - ADD_OPT ("--disk-server-task=%lu", fs->params.disk_server_task); + if (fs->params.next_task != MACH_PORT_NULL) + ADD_OPT ("--next-task=%lu", fs->params.next_task); #undef ADD_OPT return err; } diff --git a/pci-arbiter/options.h b/pci-arbiter/options.h index 2666bc4d..3d123261 100644 --- a/pci-arbiter/options.h +++ b/pci-arbiter/options.h @@ -47,7 +47,7 @@ struct parse_hook size_t ncache_len; /* Mach ports */ - mach_port_t disk_server_task; + mach_port_t next_task; mach_port_t host_priv_port; mach_port_t dev_master_port; }; @@ -70,7 +70,7 @@ static const struct argp_option options[] = { {0, 0, 0, 0, "Global configuration options:", 3}, {"ncache", 'n', "LENGTH", 0, "Node cache length. " STR (NODE_CACHE_MAX) " by default"}, - {"disk-server-task", 'T', "TASK", 0, "Task for bootstrapping disk server"}, + {"next-task", 'N', "TASK", 0, "Next bootstrap task"}, {"host-priv-port", 'H', "PORT", 0, "Port for bootstrapping host"}, {"device-master-port", 'P', "PORT", 0, "Port for bootstrapping device master"}, {0} diff --git a/pci-arbiter/pcifs.h b/pci-arbiter/pcifs.h index ba16ebaa..18f2141c 100644 --- a/pci-arbiter/pcifs.h +++ b/pci-arbiter/pcifs.h @@ -135,14 +135,14 @@ struct pcifs_perm int32_t gid; }; -/* Various parameters that can be used to change the behavior of an ftpfs. */ +/* Various parameters that can be used to change the behavior of a pcifs. */ struct pcifs_params { /* The size of the node cache. */ size_t node_cache_max; - /* Bootstrap disk server task */ - mach_port_t disk_server_task; + /* Next bootstrap task */ + mach_port_t next_task; /* FS permissions. */ struct pcifs_perm *perms; diff --git a/rumpdisk/block-rump.c b/rumpdisk/block-rump.c index 9c6fa10c..398289fb 100644 --- a/rumpdisk/block-rump.c +++ b/rumpdisk/block-rump.c @@ -149,6 +149,7 @@ rumpdisk_device_init (void) || ! device_open (device_master, D_READ, "hd2", &device)) { fprintf(stderr, "Kernel is already driving an IDE device, skipping probing disks\n"); + fflush(stderr); disabled = 1; return; } @@ -160,6 +161,7 @@ rumpdisk_device_init (void) || ! device_open (device_master, D_READ, "sd3", &device)) { fprintf(stderr, "Kernel is already driving a SATA device, skipping probing disks\n"); + fflush(stderr); disabled = 1; return; } @@ -193,19 +195,12 @@ rumpdisk_device_dealloc (void *d) } static void -rumpdisk_device_shutdown (mach_port_t dosync_handle) +rumpdisk_device_sync (void) { - struct block_data *bd = block_head; - if (disabled) return; - while (bd) - { - rumpdisk_device_close((void *)bd); - bd = bd->next; - } - rump_sys_reboot (0, NULL); + rump_sys_sync (); } static io_return_t @@ -293,6 +288,8 @@ rumpdisk_device_write (void *d, mach_port_t reply_port, return D_INVALID_OPERATION; written = rump_sys_pwrite (bd->rump_fd, (const void *)data, (size_t)count, (off_t)bn * bd->block_size); + vm_deallocate (mach_task_self (), (vm_address_t) data, count); + if (written < 0) { *bytes_written = 0; @@ -312,10 +309,11 @@ rumpdisk_device_read (void *d, mach_port_t reply_port, unsigned *bytes_read) { struct block_data *bd = d; - char *buf; + vm_address_t buf; int pagesize = sysconf (_SC_PAGE_SIZE); int npages = (count + pagesize - 1) / pagesize; ssize_t err; + kern_return_t ret; if ((bd->mode & D_READ) == 0) return D_INVALID_OPERATION; @@ -324,22 +322,24 @@ rumpdisk_device_read (void *d, mach_port_t reply_port, return D_SUCCESS; *data = 0; - buf = mmap (NULL, npages * pagesize, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - if (buf == MAP_FAILED) - return errno; + ret = vm_allocate (mach_task_self (), &buf, npages * pagesize, TRUE); + if (ret != KERN_SUCCESS) + return ENOMEM; + + /* Ensure physical allocation. */ + memset (buf, 0, npages * pagesize); err = rump_sys_pread (bd->rump_fd, (void *)buf, (size_t)count, (off_t)bn * bd->block_size); if (err < 0) { *bytes_read = 0; - munmap (buf, npages * pagesize); + vm_deallocate (mach_task_self (), buf, npages * pagesize); return EIO; } else { *bytes_read = err; - *data = buf; + *data = (void*) buf; return D_SUCCESS; } } @@ -417,7 +417,7 @@ static struct machdev_device_emulation_ops rump_block_emulation_ops = { NULL, NULL, NULL, - rumpdisk_device_shutdown + rumpdisk_device_sync }; void diff --git a/rumpdisk/main.c b/rumpdisk/main.c index c5f44fb7..bafe0250 100644 --- a/rumpdisk/main.c +++ b/rumpdisk/main.c @@ -36,7 +36,7 @@ mach_port_t bootstrap_resume_task = MACH_PORT_NULL; static const struct argp_option options[] = { {"host-priv-port", 'h', "PORT", 0, "Host private port PORT"}, {"device-master-port",'d', "PORT", 0, "Device master port PORT"}, - {"filesystem-task", 'f', "TASK", 0, "Filesystem task TASK"}, + {"next-task", 'N', "TASK", 0, "Next bootstrap task TASK"}, {0} }; @@ -51,7 +51,7 @@ parse_opt (int key, char *arg, struct argp_state *state) { int host_priv; int dev_master; - int fs_task; + int next_task; } *values = state->hook; switch (key) @@ -62,8 +62,8 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'd': values->dev_master = atoi(arg); break; - case 'f': - values->fs_task = atoi(arg); + case 'N': + values->next_task = atoi(arg); break; case ARGP_KEY_INIT: @@ -79,7 +79,7 @@ parse_opt (int key, char *arg, struct argp_state *state) /* All options parsed successfully */ _hurd_host_priv = values->host_priv; _hurd_device_master = values->dev_master; - bootstrap_resume_task = values->fs_task; + bootstrap_resume_task = values->next_task; break; default: diff --git a/startup/startup.c b/startup/startup.c index 9faeb462..bc0ff73a 100644 --- a/startup/startup.c +++ b/startup/startup.c @@ -1462,13 +1462,9 @@ S_startup_essential_task (mach_port_t server, char *name, mach_port_t credential) { - static int authinit, procinit, execinit; + static int authinit, procinit, execinit, fsinit; int fail; - /* Always deallocate the extra reference this message carries. */ - if (MACH_PORT_VALID (credential)) - mach_port_deallocate (mach_task_self (), credential); - if (credential != host_priv) return EPERM; @@ -1480,6 +1476,10 @@ S_startup_essential_task (mach_port_t server, if (fail) return fail; + /* Always deallocate the extra reference this message carries. */ + if (MACH_PORT_VALID (credential)) + mach_port_deallocate (mach_task_self (), credential); + if (!booted) { if (!strcmp (name, "auth")) @@ -1494,11 +1494,21 @@ S_startup_essential_task (mach_port_t server, } else if (!strcmp (name, "proc")) procinit = 1; + else if (!strcmp (name, "ext2fs")) + fsinit = 1; + else + { + mach_port_t otherproc; + proc_child (procserver, task); + proc_task2proc (procserver, task, &otherproc); + proc_mark_important (otherproc); + proc_set_exe (otherproc, name); + } if (verbose) fprintf (stderr, " still waiting for:"); - if (authinit && execinit && procinit) + if (authinit && execinit && procinit && fsinit) { if (verbose) fprintf (stderr, " none!\n"); @@ -1524,6 +1534,8 @@ S_startup_essential_task (mach_port_t server, fprintf (stderr, " exec"); if (! procinit) fprintf (stderr, " proc"); + if (! fsinit) + fprintf (stderr, " fs"); fprintf (stderr, "\n"); } } |