[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 01/01: New upstream snapshot
From: |
Samuel Thibault |
Subject: |
[hurd] 01/01: New upstream snapshot |
Date: |
Thu, 20 Mar 2014 02:23:54 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream-merged
in repository hurd.
commit 27e489d189e1326353142803dea0bbe13c04004f
Author: Samuel Thibault <address@hidden>
Date: Wed Mar 19 17:52:15 2014 +0000
New upstream snapshot
---
auth/Makefile | 2 +-
auth/auth.c | 10 +-
libnetfs/get-source.c => auth/auth.h | 22 +-
auth/auth_mig.h | 5 -
auth/authmutations.h | 6 -
libnetfs/get-source.c => auth/mig-decls.h | 32 +-
libdiskfs/get-source.c => auth/mig-mutate.h | 18 +-
configure.ac | 3 +
console-client/console.c | 15 +-
console-client/current-vcs.c | 8 +-
console-client/trans.c | 30 +-
console-client/vga-dynafont.c | 13 +-
console-client/vga-dynafont.h | 2 +-
console-client/vga-hw.h | 5 +
console-client/vga-support.c | 49 +-
console-client/vga.c | 12 +-
exec/exec.c | 27 +-
exec/execmutations.h | 4 +-
ext2fs/Makefile | 2 +-
fatfs/Makefile | 2 +-
hurd/fs.defs | 19 +
hurd/fsys.defs | 20 +-
hurd/iioctl.defs | 4 +
isofs/Makefile | 2 +-
libdiskfs/Makefile | 2 +-
libdiskfs/boot-start.c | 18 +-
libdiskfs/diskfs.h | 31 +-
.../{fsys-get-children.c => file-get-children.c} | 16 +-
.../file-get-source.c | 14 +-
libdiskfs/fsmutations.h | 3 +
libdiskfs/fsys-getfile.c | 12 +-
libdiskfs/fsys-getroot.c | 9 +-
libdiskfs/fsys-goaway.c | 8 +-
libdiskfs/fsys-options.c | 16 +-
libdiskfs/fsys-syncfs.c | 10 +-
libdiskfs/get-source.c | 9 +-
libdiskfs/priv.h | 1 +
libnetfs/Makefile | 2 +-
.../{fsys-get-children.c => file-get-children.c} | 14 +-
libnetfs/{fsys-get-source.c => file-get-source.c} | 15 +-
libnetfs/fsys-get-options.c | 6 +-
libnetfs/fsys-getroot.c | 5 +-
libnetfs/fsys-goaway.c | 10 +-
libnetfs/fsys-set-options.c | 11 +-
libnetfs/fsys-syncfs.c | 2 +-
libnetfs/fsysstubs.c | 8 +-
libnetfs/get-source.c | 2 +-
libnetfs/mutations.h | 3 +
libnetfs/netfs.h | 15 +-
libnetfs/priv.h | 14 +
libpager/demuxer.c | 22 +-
libports/manage-multithread.c | 6 +
libstore/Makefile | 4 +-
libstore/do-bunzip2.c | 1778 +-------------------
libstore/do-gunzip.c | 80 +
libstore/gunzip.c | 27 +-
libstore/gzip.h | 315 ----
libstore/inflate.c | 954 -----------
libstore/tailor.h | 14 -
libstore/unzip.c | 199 ---
libstore/util.c | 257 +--
libtrivfs/Makefile | 8 +-
.../{fsys-get-children.c => file-get-children.c} | 4 +-
.../file-get-source.c | 7 +-
libtrivfs/get-source.c | 2 +-
libtrivfs/{migsupport.c => mig-decls.h} | 31 +-
libtrivfs/{fsmutations.h => mig-mutate.h} | 7 +-
libtrivfs/trivfs.h | 53 +-
mach-defpager/default_pager.c | 142 +-
mach-defpager/file_io.h | 6 +-
mach-defpager/kalloc.c | 2 +-
mach-defpager/setup.c | 6 +-
nfs/main.c | 14 +
pfinet/Makefile | 7 +-
pfinet/iioctl-ops.c | 42 +-
pfinet/main.c | 2 +-
pfinet/mig-decls.h | 55 +
pfinet/{mutations.h => mig-mutate.h} | 8 +-
pfinet/misc.c | 26 -
pfinet/pfinet.h | 9 -
term/Makefile | 3 +
libdiskfs/get-source.c => term/mig-mutate.h | 19 +-
term/ptyio.c | 48 +-
term/users.c | 307 ++--
tmpfs/tmpfs.c | 2 +-
trans/Makefile | 9 +-
trans/fakeroot.c | 11 +-
trans/ifsock.c | 9 +-
trans/mtab.c | 27 +-
trans/symlink.c | 15 -
utils/Makefile | 2 +-
utils/fakeauth.c | 10 +-
utils/fakeroot.sh | 10 +-
utils/remap.sh | 9 +-
utils/umount.c | 4 +-
95 files changed, 934 insertions(+), 4206 deletions(-)
diff --git a/auth/Makefile b/auth/Makefile
index 75910c7..b9eedda 100644
--- a/auth/Makefile
+++ b/auth/Makefile
@@ -25,6 +25,6 @@ target = auth
HURDLIBS = ports ihash shouldbeinlibc
OTHERLIBS = -lpthread
-MIGSFLAGS = -imacros $(srcdir)/authmutations.h
+MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
include ../Makeconf
diff --git a/auth/auth.c b/auth/auth.c
index e69c4f8..7d35bd3 100644
--- a/auth/auth.c
+++ b/auth/auth.c
@@ -35,6 +35,8 @@
#include "auth_S.h"
#include "auth_reply_U.h"
+#include "auth.h"
+
const char *argp_program_version = STANDARD_HURD_VERSION(auth);
@@ -72,14 +74,6 @@ destroy_authhandle (void *p)
idvec_free_contents (&h->auids);
idvec_free_contents (&h->agids);
}
-
-/* Called by server stub functions. */
-
-authhandle_t
-auth_port_to_handle (auth_t auth)
-{
- return ports_lookup_port (auth_bucket, auth, authhandle_portclass);
-}
/* id management. */
diff --git a/libnetfs/get-source.c b/auth/auth.h
similarity index 72%
copy from libnetfs/get-source.c
copy to auth/auth.h
index 71a9639..0bc341d 100644
--- a/libnetfs/get-source.c
+++ b/auth/auth.h
@@ -1,8 +1,6 @@
-/* Default version of netfs_get_source
-
- Copyright (C) 2013 Free Software Foundation, Inc.
-
- Written by Justus Winter <address@hidden>
+/*
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Written by Justus Winter.
This file is part of the GNU Hurd.
@@ -19,10 +17,12 @@
You should have received a copy of the GNU General Public License
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
-#include "priv.h"
+#ifndef __AUTH_H__
+#define __AUTH_H__
+
+#include <hurd/ports.h>
+
+extern struct port_bucket *auth_bucket;
+extern struct port_class *authhandle_portclass;
-error_t
-netfs_get_source (char *source)
-{
- return EOPNOTSUPP;
-}
+#endif /* __AUTH_H__ */
diff --git a/auth/auth_mig.h b/auth/auth_mig.h
deleted file mode 100644
index d919c1b..0000000
--- a/auth/auth_mig.h
+++ /dev/null
@@ -1,5 +0,0 @@
-typedef struct authhandle *authhandle_t;
-
-authhandle_t auth_port_to_handle (auth_t);
-
-#include <hurd/ports.h>
diff --git a/auth/authmutations.h b/auth/authmutations.h
deleted file mode 100644
index 63b2f54..0000000
--- a/auth/authmutations.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* CPP definitions for MiG processing of auth.defs for auth server. */
-
-#define AUTH_INTRAN authhandle_t auth_port_to_handle (auth_t)
-#define AUTH_DESTRUCTOR ports_port_deref (authhandle_t)
-
-#define AUTH_IMPORTS import "auth_mig.h";
diff --git a/libnetfs/get-source.c b/auth/mig-decls.h
similarity index 53%
copy from libnetfs/get-source.c
copy to auth/mig-decls.h
index 71a9639..09c7c70 100644
--- a/libnetfs/get-source.c
+++ b/auth/mig-decls.h
@@ -1,8 +1,6 @@
-/* Default version of netfs_get_source
-
- Copyright (C) 2013 Free Software Foundation, Inc.
-
- Written by Justus Winter <address@hidden>
+/*
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Written by Justus Winter.
This file is part of the GNU Hurd.
@@ -19,10 +17,26 @@
You should have received a copy of the GNU General Public License
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
-#include "priv.h"
+#ifndef __AUTH_MIG_DECLS_H__
+#define __AUTH_MIG_DECLS_H__
+
+#include "auth.h"
+
+typedef struct authhandle *authhandle_t;
+
+/* Called by server stub functions. */
-error_t
-netfs_get_source (char *source)
+static inline struct authhandle * __attribute__ ((unused))
+auth_port_to_handle (mach_port_t auth)
{
- return EOPNOTSUPP;
+ return ports_lookup_port (auth_bucket, auth, authhandle_portclass);
}
+
+static inline void __attribute__ ((unused))
+end_using_authhandle (struct authhandle *auth)
+{
+ if (auth)
+ ports_port_deref (auth);
+}
+
+#endif /* __AUTH_MIG_DECLS_H__ */
diff --git a/libdiskfs/get-source.c b/auth/mig-mutate.h
similarity index 66%
copy from libdiskfs/get-source.c
copy to auth/mig-mutate.h
index d0c143b..ea40c70 100644
--- a/libdiskfs/get-source.c
+++ b/auth/mig-mutate.h
@@ -1,8 +1,6 @@
-/* Default version of diskfs_get_source
-
- Copyright (C) 2013 Free Software Foundation, Inc.
-
- Written by Justus Winter <address@hidden>
+/*
+ Copyright (C) 1991,93,94,2014 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell.
This file is part of the GNU Hurd.
@@ -19,10 +17,8 @@
You should have received a copy of the GNU General Public License
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
-#include "priv.h"
+/* CPP definitions for MiG processing of auth.defs for auth server. */
-error_t
-diskfs_get_source (char *source)
-{
- return EOPNOTSUPP;
-}
+#define AUTH_INTRAN authhandle_t auth_port_to_handle (auth_t)
+#define AUTH_DESTRUCTOR end_using_authhandle (authhandle_t)
+#define AUTH_IMPORTS import "mig-decls.h";
diff --git a/configure.ac b/configure.ac
index d822dd2..b6f777e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -315,6 +315,9 @@ PKG_CHECK_MODULES([libblkid], [blkid],
AC_SUBST([libblkid_LIBS])
AC_SUBST([libblkid_CFLAGS])
+AC_CHECK_LIB(bz2, BZ2_bzCompress, , AC_MSG_ERROR([libbz2 is required.]))
+AC_CHECK_LIB(z, deflate, , AC_MSG_ERROR([libz is required.]))
+
AC_CONFIG_FILES([config.make ${makefiles}])
AC_OUTPUT
diff --git a/console-client/console.c b/console-client/console.c
index 2fb2fbe..2fa0533 100644
--- a/console-client/console.c
+++ b/console-client/console.c
@@ -226,10 +226,17 @@ console_switch_away (void)
if (driver->ops->save_status)
driver->ops->save_status (driver->handle);
- saved_id = active_vcons->id;
- saved_cons = active_vcons->cons;
- cons_vcons_close (active_vcons);
- active_vcons = NULL;
+ if (active_vcons)
+ {
+ saved_id = active_vcons->id;
+ saved_cons = active_vcons->cons;
+ cons_vcons_close (active_vcons);
+ active_vcons = NULL;
+ }
+ else
+ {
+ saved_cons = NULL;
+ }
pthread_mutex_unlock (&global_lock);
}
diff --git a/console-client/current-vcs.c b/console-client/current-vcs.c
index e88e549..fb05379 100644
--- a/console-client/current-vcs.c
+++ b/console-client/current-vcs.c
@@ -57,8 +57,10 @@ vcs_readlink (struct iouser *user, struct node *np, char
*buf)
ret = sprintf (buf, "%s/%d", cons_file, cur);
if (ret < 0)
- ret = errno;
+ ret = -errno;
}
+ else
+ ret = -ret;
return ret;
}
@@ -75,14 +77,14 @@ vcs_read (struct protid *user, char **data,
{
size = vcs_readlink (user->user, NULL, NULL);
if (size < 0)
- return size;
+ return -size;
buf = alloca (size);
err = vcs_readlink (user->user, NULL, buf);
if (err < 0)
- return err;
+ return -err;
if (offset + amount > size)
amount = size - offset;
diff --git a/console-client/trans.c b/console-client/trans.c
index 00c5407..d65161c 100644
--- a/console-client/trans.c
+++ b/console-client/trans.c
@@ -269,7 +269,20 @@ netfs_attempt_lookup (struct iouser *user, struct node
*dir,
{
if (cn->node == NULL)
{
- struct netnode *nn = calloc (1, sizeof *nn);
+ struct netnode *nn;
+ ssize_t size = 0;
+
+ if (cn->readlink)
+ {
+ size = cn->readlink (user, NULL, NULL);
+ if (size < 0)
+ {
+ err = -size;
+ goto out;
+ }
+ }
+
+ nn = calloc (1, sizeof *nn);
if (nn == NULL)
{
err = ENOMEM;
@@ -283,15 +296,10 @@ netfs_attempt_lookup (struct iouser *user, struct node
*dir,
(*node)->nn_stat.st_mode = (netfs_root_node->nn_stat.st_mode &
~S_IFMT & ~S_ITRANS);
(*node)->nn_stat.st_ino = 5;
if (cn->readlink)
- {
(*node)->nn_stat.st_mode |= S_IFLNK;
- (*node)->nn_stat.st_size = cn->readlink (user, NULL, NULL);
- }
else
- {
(*node)->nn_stat.st_mode |= S_IFCHR;
- (*node)->nn_stat.st_size = 0;
- }
+ (*node)->nn_stat.st_size = size;
cn->node = *node;
goto out;
}
@@ -508,7 +516,13 @@ netfs_attempt_readlink (struct iouser *user, struct node
*np,
char *buf)
{
if (np->nn->node && np->nn->node->readlink)
- return np->nn->node->readlink (user, np, buf);
+ {
+ error_t err = np->nn->node->readlink (user, np, buf);
+ if (err < 0)
+ return -err;
+ else
+ return 0;
+ }
return EOPNOTSUPP;
}
diff --git a/console-client/vga-dynafont.c b/console-client/vga-dynafont.c
index 6745e88..5e3bc6d 100644
--- a/console-client/vga-dynafont.c
+++ b/console-client/vga-dynafont.c
@@ -87,6 +87,9 @@ struct dynafont
/* The size of the VGA font (256 or 512). Must be a power of 2! */
int size;
+ /* The width of the VGA font (8 or 9). */
+ int width;
+
/* A hash containing a pointer to a struct mapped_character for each
UCS-4 character we map to a VGA font index. */
struct hurd_ihash charmap;
@@ -467,7 +470,8 @@ add_gnu_head (bdf_font_t font)
Code Page 437). */
error_t
dynafont_new (bdf_font_t font, bdf_font_t font_italic, bdf_font_t font_bold,
- bdf_font_t font_bold_italic, int size, dynafont_t *dynafont)
+ bdf_font_t font_bold_italic, int size, int width,
+ dynafont_t *dynafont)
{
dynafont_t df;
struct bdf_glyph *glyph = NULL;
@@ -490,6 +494,9 @@ dynafont_new (bdf_font_t font, bdf_font_t font_italic,
bdf_font_t font_bold,
df->font_bold = font_bold;
df->font_bold_italic = font_bold_italic;
df->size = size;
+ if (!width)
+ width = df->font->bbox.width;
+ df->width = width;
df->cursor_standout = 0;
df->charmap_data = calloc (size, sizeof (struct mapped_character));
@@ -509,7 +516,7 @@ dynafont_new (bdf_font_t font, bdf_font_t font_italic,
bdf_font_t font_bold,
hurd_ihash_init (&df->charmap, offsetof (struct mapped_character, locp));
- if (df->font->bbox.width == 9)
+ if (width == 9)
{
/* 32 from 256 font slots are for horizontal line graphic
characters. */
@@ -985,7 +992,7 @@ dynafont_activate (dynafont_t df)
display problems for the user if we don't also program the video
mode timings. The standard font height for 80x25 is 16. */
vga_set_font_height (height);
- vga_set_font_width (df->font->bbox.width % 8 ? 9 : 8);
+ vga_set_font_width (df->width);
active_dynafont = df;
dynafont_set_cursor (df, df->cursor_standout);
diff --git a/console-client/vga-dynafont.h b/console-client/vga-dynafont.h
index c2bab70..0e80e04 100644
--- a/console-client/vga-dynafont.h
+++ b/console-client/vga-dynafont.h
@@ -45,7 +45,7 @@ typedef struct dynafont *dynafont_t;
the font is changed with dynafont_change_font. */
error_t dynafont_new (bdf_font_t font, bdf_font_t font_italic,
bdf_font_t font_bold, bdf_font_t font_bold_italic,
- int size, dynafont_t *dynafont);
+ int size, int width, dynafont_t *dynafont);
/* Release a dynafont object and its associated resources. */
void dynafont_free (dynafont_t df);
diff --git a/console-client/vga-hw.h b/console-client/vga-hw.h
index 7275b03..b4212e6 100644
--- a/console-client/vga-hw.h
+++ b/console-client/vga-hw.h
@@ -132,6 +132,11 @@
#define VGA_ATTR_ADDR_DATA_REG 0x3c0
#define VGA_ATTR_DATA_READ_REG 0x3c1
+/* The Attribute Mode Control subregister. */
+#define VGA_ATTR_MODE_ADDR 0x10
+#define VGA_ATTR_MODE_LGE 0x04
+
+#define VGA_ATTR_ENABLE_ADDR 0x20
/* Other junk. */
#define VGA_INPUT_STATUS_1_REG 0x3da
diff --git a/console-client/vga-support.c b/console-client/vga-support.c
index 130bcc5..ce339e1 100644
--- a/console-client/vga-support.c
+++ b/console-client/vga-support.c
@@ -53,6 +53,8 @@ struct vga_state
unsigned char crt_cursor_high;
unsigned char crt_cursor_low;
+ unsigned char attr_mode;
+
char videomem[2 * 80 * 25];
unsigned char fontmem[2 * VGA_FONT_SIZE * VGA_FONT_HEIGHT];
};
@@ -124,6 +126,18 @@ vga_init (void)
outb (VGA_CRT_CURSOR_LOW, VGA_CRT_ADDR_REG);
vga_state->crt_cursor_low = inb (VGA_CRT_DATA_REG);
+ /* Side effect of reading the input status #1 register is to
+ reset the attribute mixed address/data register so that the
+ next write it expects is the address, not the data. */
+ inb (VGA_INPUT_STATUS_1_REG);
+ outb (VGA_ATTR_MODE_ADDR, VGA_ATTR_ADDR_DATA_REG);
+ vga_state->attr_mode = inb (VGA_ATTR_DATA_READ_REG);
+
+ /* Re-enable the screen. */
+ inb (VGA_INPUT_STATUS_1_REG);
+ outb (VGA_ATTR_ENABLE_ADDR, VGA_ATTR_ADDR_DATA_REG);
+ outb (0x00, VGA_ATTR_ADDR_DATA_REG);
+
/* Read/write in interleaved mode. */
outb (VGA_GFX_MISC_ADDR, VGA_GFX_ADDR_REG);
outb (VGA_GFX_MISC_CHAINOE | VGA_GFX_MISC_B8TOBF, VGA_GFX_DATA_REG);
@@ -180,6 +194,15 @@ vga_fini (void)
outb (VGA_CRT_CURSOR_LOW, VGA_CRT_ADDR_REG);
outb (vga_state->crt_cursor_low, VGA_CRT_DATA_REG);
+ inb (VGA_INPUT_STATUS_1_REG);
+ outb (VGA_ATTR_MODE_ADDR, VGA_ATTR_ADDR_DATA_REG);
+ outb (vga_state->attr_mode, VGA_ATTR_DATA_READ_REG);
+
+ /* Re-enable the screen. */
+ inb (VGA_INPUT_STATUS_1_REG);
+ outb (VGA_ATTR_ENABLE_ADDR, VGA_ATTR_ADDR_DATA_REG);
+ outb (0x00, VGA_ATTR_ADDR_DATA_REG);
+
ioperm (VGA_MIN_REG, VGA_MAX_REG - VGA_MIN_REG + 1, 0);
munmap (vga_videomem, VGA_VIDEO_MEM_LENGTH);
}
@@ -284,7 +307,7 @@ vga_set_font_height (int height)
}
-/* Get the font height in pixel. Can be 8 or 9. */
+/* Get the font width in pixel. Can be 8 or 9. */
int
vga_get_font_width (void)
{
@@ -292,7 +315,7 @@ vga_get_font_width (void)
return (inb (VGA_SEQ_DATA_REG) & VGA_SEQ_CLOCK_MODE_8) ? 8 : 9;
}
-/* Set the font height in pixel. WIDTH can be 8 or 9. */
+/* Set the font width in pixel. WIDTH can be 8 or 9. */
void
vga_set_font_width (int width)
{
@@ -308,6 +331,20 @@ vga_set_font_width (int width)
else
saved &= ~VGA_SEQ_CLOCK_MODE_8;
outb (saved, VGA_SEQ_DATA_REG);
+
+ inb (VGA_INPUT_STATUS_1_REG);
+ outb (VGA_ATTR_MODE_ADDR, VGA_ATTR_ADDR_DATA_REG);
+ saved = inb (VGA_ATTR_DATA_READ_REG);
+ if (width == 8)
+ saved |= ~VGA_ATTR_MODE_LGE;
+ else
+ saved &= VGA_ATTR_MODE_LGE;
+ outb (saved, VGA_ATTR_ADDR_DATA_REG);
+
+ /* Re-enable the screen. */
+ inb (VGA_INPUT_STATUS_1_REG);
+ outb (VGA_ATTR_ENABLE_ADDR, VGA_ATTR_ADDR_DATA_REG);
+ outb (0x00, VGA_ATTR_ADDR_DATA_REG);
}
@@ -423,12 +460,8 @@ vga_exchange_palette_attributes (unsigned char index,
{
unsigned char attr;
- /* Side effect of reading the input status #1 register is to
- reset the attribute mixed address/data register so that the
- next write it expects is the address, not the data. */
- inb (VGA_INPUT_STATUS_1_REG);
-
/* Set the address. */
+ inb (VGA_INPUT_STATUS_1_REG);
outb (index++, VGA_ATTR_ADDR_DATA_REG);
attr = inb (VGA_ATTR_DATA_READ_REG);
outb ((attr & ~077) | (*palette_attr & 077), VGA_ATTR_ADDR_DATA_REG);
@@ -438,6 +471,6 @@ vga_exchange_palette_attributes (unsigned char index,
/* Re-enable the screen, which was blanked during the palette
operation. */
inb (VGA_INPUT_STATUS_1_REG);
- outb (0x20, VGA_ATTR_ADDR_DATA_REG);
+ outb (VGA_ATTR_ENABLE_ADDR, VGA_ATTR_ADDR_DATA_REG);
outb (0x00, VGA_ATTR_ADDR_DATA_REG);
}
diff --git a/console-client/vga.c b/console-client/vga.c
index 8a3260b..cf6c8c3 100644
--- a/console-client/vga.c
+++ b/console-client/vga.c
@@ -65,6 +65,9 @@ static char *vga_display_font_bold_italic;
/* If false use all colors, else use double font slots. */
static int vga_display_max_glyphs;
+/* width of glyphs. */
+static int vga_display_font_width;
+
/* The timer used for flashing the screen. */
static struct timer_list vga_display_timer;
@@ -107,6 +110,7 @@ struct vga_display
/* The VGA font for this display. */
dynafont_t df;
int df_size;
+ int df_width;
/* The color palette. */
dynacolor_t dc;
@@ -209,6 +213,7 @@ static const struct argp_option options[] =
"Prefer a lot of colors above a lot of glyphs"},
{"max-glyphs", 'g', 0 , 0,
"Prefer a lot of glyphs above a lot of colors"},
+ {"font-width", 'w', "NUM" , 0, "Force using NUM pixel-wide glyphs"},
{ 0 }
};
@@ -251,6 +256,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
vga_display_max_glyphs = 1;
break;
+ case 'w':
+ vga_display_font_width = atoi (arg);
+ break;
+
case ARGP_KEY_END:
break;
@@ -292,6 +301,7 @@ vga_display_init (void **handle, int no_exit, int argc,
char *argv[],
return ENOMEM;
disp->df_size = vga_display_max_glyphs ? 512 : 256;
+ disp->df_width = vga_display_font_width;
disp->width = VGA_DISP_WIDTH;
disp->height = VGA_DISP_HEIGHT;
@@ -338,7 +348,7 @@ vga_display_start (void *handle)
LOAD_FONT (font_bold_italic, FONT_BOLD_ITALIC);
err = dynafont_new (font, font_italic, font_bold, font_bold_italic,
- disp->df_size, &disp->df);
+ disp->df_size, disp->df_width, &disp->df);
if (err)
{
free (disp);
diff --git a/exec/exec.c b/exec/exec.c
index fad9492..e693f63 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -1151,14 +1151,29 @@ do_exec (file_t file,
}
boot->user_entry = e.entry; /* already adjusted in `load' */
- /* Set the start_code and end_code values for this process.
- /hurd/exec is used to start /hurd/proc, so at this point there is
+ /* /hurd/exec is used to start /hurd/proc, so at this point there is
no proc server, so we need to be careful here. */
if (boot->portarray[INIT_PORT_PROC] != MACH_PORT_NULL)
- e.error = proc_set_code (boot->portarray[INIT_PORT_PROC],
- e.start_code, e.end_code);
- if (e.error)
- goto out;
+ {
+ /* Set the start_code and end_code values for this process. */
+ e.error = proc_set_code (boot->portarray[INIT_PORT_PROC],
+ e.start_code, e.end_code);
+ if (e.error)
+ goto out;
+
+ pid_t pid;
+ e.error = proc_task2pid (boot->portarray[INIT_PORT_PROC],
+ newtask, &pid);
+ if (e.error)
+ goto out;
+
+ char *name;
+ if (asprintf (&name, "%s(%d)", argv, pid) > 0)
+ {
+ task_set_name (newtask, name);
+ free (name);
+ }
+ }
/* Create the initial thread. */
e.error = thread_create (newtask, &thread);
diff --git a/exec/execmutations.h b/exec/execmutations.h
index 96b4772..ffcba9c 100644
--- a/exec/execmutations.h
+++ b/exec/execmutations.h
@@ -3,6 +3,8 @@
#define FILE_INTRAN trivfs_protid_t trivfs_begin_using_protid (file_t)
#define FILE_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t)
-#define EXEC_IMPORTS import "priv.h";
+#define EXEC_IMPORTS \
+ import "priv.h"; \
+ import "../libtrivfs/mig-decls.h"; \
#define SERVERCOPY 1
diff --git a/ext2fs/Makefile b/ext2fs/Makefile
index 983dbee..32e40f0 100644
--- a/ext2fs/Makefile
+++ b/ext2fs/Makefile
@@ -24,7 +24,7 @@ SRCS = balloc.c dir.c ext2fs.c getblk.c hyper.c ialloc.c \
inode.c pager.c pokel.c truncate.c storeinfo.c msg.c xinl.c
OBJS = $(SRCS:.c=.o)
HURDLIBS = diskfs pager iohelp fshelp store ports ihash shouldbeinlibc
-OTHERLIBS = -lpthread
+OTHERLIBS = -lpthread -lbz2 -lz
include ../Makeconf
diff --git a/fatfs/Makefile b/fatfs/Makefile
index c673b1b..2555669 100644
--- a/fatfs/Makefile
+++ b/fatfs/Makefile
@@ -23,7 +23,7 @@ SRCS = inode.c main.c dir.c pager.c fat.c virt-inode.c
node-create.c
OBJS = $(SRCS:.c=.o)
HURDLIBS = diskfs iohelp fshelp store pager ports ihash shouldbeinlibc
-OTHERLIBS = -lpthread
+OTHERLIBS = -lpthread -lbz2 -lz
include ../Makeconf
diff --git a/hurd/fs.defs b/hurd/fs.defs
index 52d83bd..2452682 100644
--- a/hurd/fs.defs
+++ b/hurd/fs.defs
@@ -352,3 +352,22 @@ routine file_reparent (
RPT
parent: mach_port_t;
out new_file: mach_port_send_t);
+
+/* Return any active translators bound to nodes below FILE. CHILDREN
+ is an argz vector containing file names relative to the root of the
+ receiving translator. */
+routine file_get_children (
+ file: file_t;
+ RPT
+ out children: data_t);
+
+/* Return information about the source of FILE. If the concept of a
+ source is applicable, SOURCE should refer to the source of FILE and
+ should be a description considered appropriate in the context of
+ the translator. For example, if FILE refers to a node on a
+ filesystems, SOURCE should be the file name of the underlying block
+ device. */
+routine file_get_source (
+ file: file_t;
+ RPT
+ out source: string_t);
diff --git a/hurd/fsys.defs b/hurd/fsys.defs
index 7f99f7f..b36b944 100644
--- a/hurd/fsys.defs
+++ b/hurd/fsys.defs
@@ -128,21 +128,5 @@ routine fsys_get_options (
RPT
out options: data_t, dealloc);
-/* Return any active translators bound to nodes of the receiving
- filesystem. CHILDREN is an argz vector containing file names
- relative to the root of the receiving translator. */
-routine fsys_get_children (
- server: fsys_t;
- RPT
- out children: data_t);
-
-/* Return information about the source of the receiving filesystem.
- If the concept of a source is applicable, SOURCE should refer to
- the source of the receiving translator and should be a description
- considered appropriate in the context of the translator. For
- example for the case of block device based filesystems, SOURCE
- should be the file name of the underlying block device. */
-routine fsys_get_source (
- server: fsys_t;
- RPT
- out source: string_t);
+skip; /* Was fsys_get_children */
+skip; /* Was fsys_get_source */
diff --git a/hurd/iioctl.defs b/hurd/iioctl.defs
index 4efe928..dfa8903 100644
--- a/hurd/iioctl.defs
+++ b/hurd/iioctl.defs
@@ -20,6 +20,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA
02139, USA. */
#include <hurd/hurd_types.defs>
+#ifdef IIOCTL_IMPORTS
+IIOCTL_IMPORTS
+#endif
+
INTR_INTERFACE
/* Ioctl class `i'; the subsystem is derived from calculations in
diff --git a/isofs/Makefile b/isofs/Makefile
index 053b622..9147c12 100644
--- a/isofs/Makefile
+++ b/isofs/Makefile
@@ -22,7 +22,7 @@ SRCS = inode.c main.c lookup.c pager.c rr.c
OBJS = $(SRCS:.c=.o)
HURDLIBS = diskfs iohelp fshelp store pager ports ihash shouldbeinlibc
-OTHERLIBS = -lpthread
+OTHERLIBS = -lpthread -lbz2 -lz
include ../Makeconf
diff --git a/libdiskfs/Makefile b/libdiskfs/Makefile
index 03c2e2b..aeebe4e 100644
--- a/libdiskfs/Makefile
+++ b/libdiskfs/Makefile
@@ -35,7 +35,7 @@ IOSRCS= io-async-icky.c io-async.c io-duplicate.c
io-get-conch.c io-revoke.c \
io-select.c io-stat.c io-stubs.c io-write.c io-version.c io-sigio.c
FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-startup.c fsys-getfile.c \
fsys-options.c fsys-syncfs.c fsys-forward.c \
- fsys-get-children.c fsys-get-source.c
+ file-get-children.c file-get-source.c
IFSOCKSRCS=ifsock.c
OTHERSRCS = conch-fetch.c conch-set.c dir-clear.c dir-init.c dir-renamed.c \
extern-inline.c \
diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c
index 6d9a773..7b8a84f 100644
--- a/libdiskfs/boot-start.c
+++ b/libdiskfs/boot-start.c
@@ -426,17 +426,16 @@ diskfs_execboot_fsys_startup (mach_port_t port, int flags,
/* Called by init to get the privileged ports as described
in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_getpriv (mach_port_t port,
+diskfs_S_fsys_getpriv (struct diskfs_control *init_bootstrap_port,
mach_port_t reply, mach_msg_type_name_t reply_type,
mach_port_t *host_priv, mach_msg_type_name_t *hp_type,
mach_port_t *dev_master, mach_msg_type_name_t *dm_type,
mach_port_t *fstask, mach_msg_type_name_t *task_type)
{
error_t err;
- struct port_info *init_bootstrap_port =
- ports_lookup_port (diskfs_port_bucket, port, diskfs_initboot_class);
- if (!init_bootstrap_port)
+ if (!init_bootstrap_port
+ || init_bootstrap_port->pi.class != diskfs_initboot_class)
return EOPNOTSUPP;
err = get_privileged_ports (host_priv, dev_master);
@@ -447,20 +446,17 @@ diskfs_S_fsys_getpriv (mach_port_t port,
*task_type = MACH_MSG_TYPE_COPY_SEND;
}
- ports_port_deref (init_bootstrap_port);
-
return err;
}
/* Called by init to give us ports to the procserver and authserver as
described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_init (mach_port_t port,
+diskfs_S_fsys_init (struct diskfs_control *pt,
mach_port_t reply, mach_msg_type_name_t replytype,
mach_port_t procserver,
mach_port_t authhandle)
{
- struct port_infe *pt;
static int initdone = 0;
mach_port_t host, startup;
error_t err;
@@ -468,10 +464,10 @@ diskfs_S_fsys_init (mach_port_t port,
struct protid *rootpi;
struct peropen *rootpo;
- pt = ports_lookup_port (diskfs_port_bucket, port, diskfs_initboot_class);
- if (!pt)
+ if (!pt
+ || pt->pi.class != diskfs_initboot_class)
return EOPNOTSUPP;
- ports_port_deref (pt);
+
if (initdone)
return EOPNOTSUPP;
initdone = 1;
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index 22262aa..359b11b 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -121,6 +121,11 @@ struct node
int author_tracks_uid;
};
+struct diskfs_control
+{
+ struct port_info pi;
+};
+
/* Possibly lookup types for diskfs_lookup call */
enum lookup_type
{
@@ -569,10 +574,11 @@ error_t (*diskfs_create_symlink_hook)(struct node *np,
const char *target);
error_t (*diskfs_read_symlink_hook)(struct node *np, char *target);
/* The user may define this function. The function must set source to
- the source device of the filesystem. The function may return an
- EOPNOTSUPP to indicate that the concept of a source device is not
- applicable. The default function always returns EOPNOTSUPP. */
-error_t diskfs_get_source (char *source);
+ the source of CRED. The function may return an EOPNOTSUPP to
+ indicate that the concept of a source device is not applicable. The
+ default function always returns EOPNOTSUPP. */
+error_t diskfs_get_source (struct protid *cred,
+ char *source, size_t source_len);
/* The library exports the following functions for general use */
@@ -794,8 +800,10 @@ error_t diskfs_start_protid (struct peropen *po, struct
protid **cred);
void diskfs_finish_protid (struct protid *cred, struct iouser *user);
extern struct protid * diskfs_begin_using_protid_port (file_t port);
+extern struct diskfs_control * diskfs_begin_using_control_port (fsys_t port);
extern void diskfs_end_using_protid_port (struct protid *cred);
+extern void diskfs_end_using_control_port (struct diskfs_control *cred);
#if defined(__USE_EXTERN_INLINES) || defined(DISKFS_DEFINE_EXTERN_INLINE)
@@ -808,6 +816,13 @@ diskfs_begin_using_protid_port (file_t port)
return ports_lookup_port (diskfs_port_bucket, port, diskfs_protid_class);
}
+/* And for the fsys interface. */
+DISKFS_EXTERN_INLINE struct diskfs_control *
+diskfs_begin_using_control_port (fsys_t port)
+{
+ return ports_lookup_port (diskfs_port_bucket, port, NULL);
+}
+
/* Called by MiG after server routines have been run; this
balances begin_using_protid_port, and is arranged for the io
and fs interfaces by fsmutations.h. */
@@ -818,6 +833,14 @@ diskfs_end_using_protid_port (struct protid *cred)
ports_port_deref (cred);
}
+/* And for the fsys interface. */
+DISKFS_EXTERN_INLINE void
+diskfs_end_using_control_port (struct diskfs_control *cred)
+{
+ if (cred)
+ ports_port_deref (cred);
+}
+
#endif /* Use extern inlines. */
/* Called when a protid CRED has no more references. (Because references\
diff --git a/libdiskfs/fsys-get-children.c b/libdiskfs/file-get-children.c
similarity index 89%
rename from libdiskfs/fsys-get-children.c
rename to libdiskfs/file-get-children.c
index 69c9963..4581e4e 100644
--- a/libdiskfs/fsys-get-children.c
+++ b/libdiskfs/file-get-children.c
@@ -1,4 +1,4 @@
-/* fsys_get_children
+/* file_get_children
Copyright (C) 2013 Free Software Foundation, Inc.
@@ -20,7 +20,7 @@
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
#include "priv.h"
-#include "fsys_S.h"
+#include "fs_S.h"
#include <argz.h>
@@ -28,18 +28,14 @@
filesystem. CHILDREN is an argz vector containing file names
relative to the root of the receiving translator. */
error_t
-diskfs_S_fsys_get_children (fsys_t server,
- mach_port_t reply,
- mach_msg_type_name_t replyPoly,
+diskfs_S_file_get_children (struct protid *cred,
char **children,
mach_msg_type_number_t *children_len)
{
error_t err;
-
- struct protid *cred = ports_lookup_port (diskfs_port_bucket,
- server,
- diskfs_protid_class);
- if (! cred)
+ if (! cred
+ || cred->pi.bucket != diskfs_port_bucket
+ || cred->pi.class != diskfs_protid_class)
return EOPNOTSUPP;
/* check_access performs the same permission check as is normally
diff --git a/libtrivfs/fsys-get-source.c b/libdiskfs/file-get-source.c
similarity index 76%
rename from libtrivfs/fsys-get-source.c
rename to libdiskfs/file-get-source.c
index 64aec2f..b5c3184 100644
--- a/libtrivfs/fsys-get-source.c
+++ b/libdiskfs/file-get-source.c
@@ -1,4 +1,4 @@
-/* fsys_get_source
+/* file_get_source
Copyright (C) 2013 Free Software Foundation, Inc.
@@ -20,14 +20,18 @@
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
#include "priv.h"
+#include "fs_S.h"
/* Return information about the source of the receiving
filesystem. */
error_t
-trivfs_S_fsys_get_source (trivfs_control_t server,
- mach_port_t reply,
- mach_msg_type_name_t replyPoly,
+diskfs_S_file_get_source (struct protid *cred,
char *source)
{
- return trivfs_get_source (source);
+ if (! cred
+ || cred->pi.bucket != diskfs_port_bucket
+ || cred->pi.class != diskfs_protid_class)
+ return EOPNOTSUPP;
+
+ return diskfs_get_source (cred, source, 1024 /* XXX */);
}
diff --git a/libdiskfs/fsmutations.h b/libdiskfs/fsmutations.h
index 5026810..68b6ae3 100644
--- a/libdiskfs/fsmutations.h
+++ b/libdiskfs/fsmutations.h
@@ -23,6 +23,9 @@
#define IO_INTRAN protid_t diskfs_begin_using_protid_port (io_t)
#define IO_DESTRUCTOR diskfs_end_using_protid_port (protid_t)
+#define FSYS_INTRAN control_t diskfs_begin_using_control_port (fsys_t)
+#define FSYS_DESTRUCTOR diskfs_end_using_control_port (control_t)
+
#define FILE_IMPORTS import "priv.h";
#define IO_IMPORTS import "priv.h";
#define FSYS_IMPORTS import "priv.h";
diff --git a/libdiskfs/fsys-getfile.c b/libdiskfs/fsys-getfile.c
index 2fe9495..9dd5d73 100644
--- a/libdiskfs/fsys-getfile.c
+++ b/libdiskfs/fsys-getfile.c
@@ -27,7 +27,7 @@
/* Return in FILE & FILE_TYPE the file in FSYS corresponding to the NFS file
handle HANDLE & HANDLE_LEN. */
error_t
-diskfs_S_fsys_getfile (mach_port_t fsys,
+diskfs_S_fsys_getfile (struct diskfs_control *pt,
mach_port_t reply, mach_msg_type_name_t reply_type,
uid_t *uids, mach_msg_type_number_t nuids,
gid_t *gids, mach_msg_type_number_t ngids,
@@ -41,15 +41,13 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
struct protid *new_cred;
struct peropen *new_po;
struct iouser *user;
- struct port_info *pt =
- ports_lookup_port (diskfs_port_bucket, fsys, diskfs_control_class);
- if (!pt)
+ if (!pt
+ || pt->pi.class != diskfs_control_class)
return EOPNOTSUPP;
if (handle_len != sizeof *f)
{
- ports_port_deref (pt);
return EINVAL;
}
@@ -58,14 +56,12 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
err = diskfs_cached_lookup (f->data.cache_id, &node);
if (err)
{
- ports_port_deref (pt);
return err;
}
if (node->dn_stat.st_gen != f->data.gen)
{
diskfs_nput (node);
- ports_port_deref (pt);
return ESTALE;
}
@@ -73,7 +69,6 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
if (err)
{
diskfs_nput (node);
- ports_port_deref (pt);
return err;
}
@@ -98,7 +93,6 @@ diskfs_S_fsys_getfile (mach_port_t fsys,
iohelp_free_iouser (user);
diskfs_nput (node);
- ports_port_deref (pt);
if (! err)
{
diff --git a/libdiskfs/fsys-getroot.c b/libdiskfs/fsys-getroot.c
index 85e1167..5212214 100644
--- a/libdiskfs/fsys-getroot.c
+++ b/libdiskfs/fsys-getroot.c
@@ -26,7 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA
02139, USA. */
/* Implement fsys_getroot as described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_getroot (fsys_t controlport,
+diskfs_S_fsys_getroot (struct diskfs_control *pt,
mach_port_t reply,
mach_msg_type_name_t replytype,
mach_port_t dotdot,
@@ -40,8 +40,6 @@ diskfs_S_fsys_getroot (fsys_t controlport,
file_t *returned_port,
mach_msg_type_name_t *returned_port_poly)
{
- struct port_info *pt = ports_lookup_port (diskfs_port_bucket, controlport,
- diskfs_control_class);
error_t err = 0;
mode_t type;
struct protid *newpi;
@@ -55,7 +53,8 @@ diskfs_S_fsys_getroot (fsys_t controlport,
path: NULL,
};
- if (!pt)
+ if (!pt
+ || pt->pi.class != diskfs_control_class)
return EOPNOTSUPP;
flags &= O_HURD;
@@ -200,8 +199,6 @@ diskfs_S_fsys_getroot (fsys_t controlport,
pthread_mutex_unlock (&diskfs_root_node->lock);
pthread_rwlock_unlock (&diskfs_fsys_lock);
- ports_port_deref (pt);
-
drop_idvec ();
return err;
diff --git a/libdiskfs/fsys-goaway.c b/libdiskfs/fsys-goaway.c
index 2aabce8..b910387 100644
--- a/libdiskfs/fsys-goaway.c
+++ b/libdiskfs/fsys-goaway.c
@@ -25,16 +25,15 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA
02139, USA. */
/* Implement fsys_goaway as described in <hurd/fsys.defs>. */
error_t
-diskfs_S_fsys_goaway (fsys_t controlport,
+diskfs_S_fsys_goaway (struct diskfs_control *pt,
mach_port_t reply,
mach_msg_type_name_t reply_type,
int flags)
{
- struct port_info *pt = ports_lookup_port (diskfs_port_bucket, controlport,
- diskfs_control_class);
error_t ret;
- if (!pt)
+ if (!pt
+ || pt->pi.class != diskfs_control_class)
return EOPNOTSUPP;
/* XXX FSYS_GOAWAY_NOWAIT not implemented. */
@@ -48,6 +47,5 @@ diskfs_S_fsys_goaway (fsys_t controlport,
exit (0);
}
- ports_port_deref (pt);
return ret;
}
diff --git a/libdiskfs/fsys-options.c b/libdiskfs/fsys-options.c
index bb18319..b366d14 100644
--- a/libdiskfs/fsys-options.c
+++ b/libdiskfs/fsys-options.c
@@ -28,15 +28,13 @@
/* Implement fsys_set_options as described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_set_options (fsys_t fsys,
+diskfs_S_fsys_set_options (struct diskfs_control *pt,
mach_port_t reply,
mach_msg_type_name_t replytype,
char *data, mach_msg_type_number_t len,
int do_children)
{
error_t err = 0;
- struct port_info *pt =
- ports_lookup_port (diskfs_port_bucket, fsys, diskfs_control_class);
error_t
helper (struct node *np)
@@ -60,7 +58,8 @@ diskfs_S_fsys_set_options (fsys_t fsys,
return error;
}
- if (!pt)
+ if (!pt
+ || pt->pi.class != diskfs_control_class)
return EOPNOTSUPP;
if (do_children)
@@ -77,13 +76,12 @@ diskfs_S_fsys_set_options (fsys_t fsys,
pthread_rwlock_unlock (&diskfs_fsys_lock);
}
- ports_port_deref (pt);
return err;
}
/* Implement fsys_get_options as described in <hurd/fsys.defs>. */
error_t
-diskfs_S_fsys_get_options (fsys_t fsys,
+diskfs_S_fsys_get_options (struct diskfs_control *port,
mach_port_t reply,
mach_msg_type_name_t replytype,
char **data, mach_msg_type_number_t *data_len)
@@ -91,10 +89,9 @@ diskfs_S_fsys_get_options (fsys_t fsys,
char *argz = 0;
size_t argz_len = 0;
error_t err;
- struct port_info *port =
- ports_lookup_port (diskfs_port_bucket, fsys, diskfs_control_class);
- if (!port)
+ if (!port
+ || port->pi.class != diskfs_control_class)
return EOPNOTSUPP;
err = argz_add (&argz, &argz_len, program_invocation_name);
@@ -111,6 +108,5 @@ diskfs_S_fsys_get_options (fsys_t fsys,
else
free (argz);
- ports_port_deref (port);
return err;
}
diff --git a/libdiskfs/fsys-syncfs.c b/libdiskfs/fsys-syncfs.c
index beb8881..4dceed7 100644
--- a/libdiskfs/fsys-syncfs.c
+++ b/libdiskfs/fsys-syncfs.c
@@ -24,14 +24,12 @@
/* Implement fsys_syncfs as described in <hurd/fsys.defs>. */
kern_return_t
-diskfs_S_fsys_syncfs (fsys_t controlport,
+diskfs_S_fsys_syncfs (struct diskfs_control *pi,
mach_port_t reply,
mach_msg_type_name_t replytype,
int wait,
int children)
{
- struct port_info *pi = ports_lookup_port (diskfs_port_bucket, controlport,
- diskfs_control_class);
error_t
helper (struct node *np)
{
@@ -49,7 +47,8 @@ diskfs_S_fsys_syncfs (fsys_t controlport,
return 0;
}
- if (!pi)
+ if (!pi
+ || pi->pi.class != diskfs_control_class)
return EOPNOTSUPP;
pthread_rwlock_rdlock (&diskfs_fsys_lock);
@@ -67,8 +66,5 @@ diskfs_S_fsys_syncfs (fsys_t controlport,
}
pthread_rwlock_unlock (&diskfs_fsys_lock);
-
- ports_port_deref (pi);
-
return 0;
}
diff --git a/libdiskfs/get-source.c b/libdiskfs/get-source.c
index d0c143b..4399446 100644
--- a/libdiskfs/get-source.c
+++ b/libdiskfs/get-source.c
@@ -22,7 +22,12 @@
#include "priv.h"
error_t
-diskfs_get_source (char *source)
+diskfs_get_source (struct protid *cred, char *source, size_t source_len)
{
- return EOPNOTSUPP;
+ if (diskfs_disk_name == NULL)
+ return EOPNOTSUPP;
+
+ strncpy (source, diskfs_disk_name, source_len - 1);
+ source[source_len - 1] = '\0';
+ return 0;
}
diff --git a/libdiskfs/priv.h b/libdiskfs/priv.h
index bd23ab9..b41fa43 100644
--- a/libdiskfs/priv.h
+++ b/libdiskfs/priv.h
@@ -73,6 +73,7 @@ extern int _diskfs_diskdirty;
/* Needed for MiG. */
typedef struct protid *protid_t;
+typedef struct diskfs_control *control_t;
/* Actually read or write a file. The file size must already permit
the requested access. NP is the file to read/write. DATA is a buffer
diff --git a/libnetfs/Makefile b/libnetfs/Makefile
index 1a71b49..c3830c0 100644
--- a/libnetfs/Makefile
+++ b/libnetfs/Makefile
@@ -45,7 +45,7 @@ IOSRCS= io-read.c io-readable.c io-seek.c io-write.c
io-stat.c io-async.c \
io-version.c
FSYSSRCS= fsys-syncfs.c fsys-getroot.c fsys-get-options.c fsys-set-options.c \
- fsys-goaway.c fsysstubs.c fsys-get-children.c fsys-get-source.c
+ fsys-goaway.c fsysstubs.c file-get-children.c file-get-source.c
IFSOCKSRCS=
OTHERSRCS= drop-node.c init-init.c make-node.c make-peropen.c make-protid.c \
diff --git a/libnetfs/fsys-get-children.c b/libnetfs/file-get-children.c
similarity index 91%
rename from libnetfs/fsys-get-children.c
rename to libnetfs/file-get-children.c
index fb3af91..80a727f 100644
--- a/libnetfs/fsys-get-children.c
+++ b/libnetfs/file-get-children.c
@@ -1,4 +1,4 @@
-/* fsys_get_children
+/* file_get_children
Copyright (C) 2013 Free Software Foundation, Inc.
@@ -27,18 +27,14 @@
filesystem. CHILDREN is an argz vector containing file names
relative to the root of the receiving translator. */
error_t
-netfs_S_fsys_get_children (fsys_t server,
- mach_port_t reply,
- mach_msg_type_name_t replyPoly,
+netfs_S_file_get_children (struct protid *cred,
char **children,
mach_msg_type_number_t *children_len)
{
error_t err;
-
- struct protid *cred = ports_lookup_port (netfs_port_bucket,
- server,
- netfs_protid_class);
- if (! cred)
+ if (! cred
+ || cred->pi.bucket != netfs_port_bucket
+ || cred->pi.class != netfs_protid_class)
return EOPNOTSUPP;
/* check_access performs the same permission check as is normally
diff --git a/libnetfs/fsys-get-source.c b/libnetfs/file-get-source.c
similarity index 77%
rename from libnetfs/fsys-get-source.c
rename to libnetfs/file-get-source.c
index 6143d10..8b73d5a 100644
--- a/libnetfs/fsys-get-source.c
+++ b/libnetfs/file-get-source.c
@@ -1,4 +1,4 @@
-/* fsys_get_source
+/* file_get_source
Copyright (C) 2013 Free Software Foundation, Inc.
@@ -20,15 +20,18 @@
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
#include "priv.h"
-#include "fsys_S.h"
+#include "fs_S.h"
/* Return information about the source of the receiving
filesystem. */
error_t
-netfs_S_fsys_get_source (fsys_t server,
- mach_port_t reply,
- mach_msg_type_name_t replyPoly,
+netfs_S_file_get_source (struct protid *cred,
char *source)
{
- return netfs_get_source (source);
+ if (! cred
+ || cred->pi.bucket != netfs_port_bucket
+ || cred->pi.class != netfs_protid_class)
+ return EOPNOTSUPP;
+
+ return netfs_get_source (cred, source, 1024 /* XXX */);
}
diff --git a/libnetfs/fsys-get-options.c b/libnetfs/fsys-get-options.c
index 54bd9a0..836806b 100644
--- a/libnetfs/fsys-get-options.c
+++ b/libnetfs/fsys-get-options.c
@@ -31,7 +31,7 @@
/* Implement fsys_get_options as described in <hurd/fsys.defs>. */
error_t
-netfs_S_fsys_get_options (fsys_t fsys,
+netfs_S_fsys_get_options (struct netfs_control *port,
mach_port_t reply,
mach_msg_type_name_t reply_type,
char **data, mach_msg_type_number_t *data_len)
@@ -39,8 +39,6 @@ netfs_S_fsys_get_options (fsys_t fsys,
error_t err;
char *argz = 0;
size_t argz_len = 0;
- struct port_info *port =
- ports_lookup_port (netfs_port_bucket, fsys, netfs_control_class);
if (!port)
return EOPNOTSUPP;
@@ -63,7 +61,5 @@ netfs_S_fsys_get_options (fsys_t fsys,
else
free (argz);
- ports_port_deref (port);
-
return err;
}
diff --git a/libnetfs/fsys-getroot.c b/libnetfs/fsys-getroot.c
index 0d80111..2d02120 100644
--- a/libnetfs/fsys-getroot.c
+++ b/libnetfs/fsys-getroot.c
@@ -25,7 +25,7 @@
#include <fcntl.h>
error_t
-netfs_S_fsys_getroot (mach_port_t cntl,
+netfs_S_fsys_getroot (struct netfs_control *pt,
mach_port_t reply,
mach_msg_type_name_t reply_type,
mach_port_t dotdot,
@@ -37,8 +37,6 @@ netfs_S_fsys_getroot (mach_port_t cntl,
mach_port_t *retry_port,
mach_msg_type_name_t *retry_port_type)
{
- struct port_info *pt = ports_lookup_port (netfs_port_bucket, cntl,
- netfs_control_class);
struct iouser *cred;
error_t err;
struct protid *newpi;
@@ -51,7 +49,6 @@ netfs_S_fsys_getroot (mach_port_t cntl,
if (!pt)
return EOPNOTSUPP;
- ports_port_deref (pt);
err = iohelp_create_complex_iouser (&cred, uids, nuids, gids, ngids);
if (err)
diff --git a/libnetfs/fsys-goaway.c b/libnetfs/fsys-goaway.c
index 0ac36d3..872d073 100644
--- a/libnetfs/fsys-goaway.c
+++ b/libnetfs/fsys-goaway.c
@@ -26,17 +26,15 @@
#include <hurd/ports.h>
error_t
-netfs_S_fsys_goaway (fsys_t control,
+netfs_S_fsys_goaway (struct netfs_control *pt,
mach_port_t reply,
mach_msg_type_name_t reply_type,
int flags)
{
error_t err;
- struct port_info *pt;
- pt = ports_lookup_port (netfs_port_bucket, control,
- netfs_control_class);
- if (! pt)
+
+ if (!pt)
return EOPNOTSUPP;
err = netfs_shutdown (flags);
@@ -46,7 +44,5 @@ netfs_S_fsys_goaway (fsys_t control,
exit (0);
}
- ports_port_deref (pt);
-
return err;
}
diff --git a/libnetfs/fsys-set-options.c b/libnetfs/fsys-set-options.c
index d7dc743..fb1c87e 100644
--- a/libnetfs/fsys-set-options.c
+++ b/libnetfs/fsys-set-options.c
@@ -31,15 +31,15 @@
/* Implement fsys_set_options as described in <hurd/fsys.defs>. */
error_t
-netfs_S_fsys_set_options (fsys_t fsys,
+netfs_S_fsys_set_options (struct netfs_control *pt,
mach_port_t reply,
mach_msg_type_name_t reply_type,
char *data, mach_msg_type_number_t data_len,
int do_children)
{
error_t err = 0;
- struct port_info *pt =
- ports_lookup_port (netfs_port_bucket, fsys, netfs_control_class);
+ if (!pt)
+ return EOPNOTSUPP;
error_t
helper (struct node *np)
@@ -64,9 +64,6 @@ netfs_S_fsys_set_options (fsys_t fsys,
return error;
}
- if (!pt)
- return EOPNOTSUPP;
-
#if NOT_YET
if (do_children)
{
@@ -87,7 +84,5 @@ netfs_S_fsys_set_options (fsys_t fsys,
#endif
}
- ports_port_deref (pt);
-
return err;
}
diff --git a/libnetfs/fsys-syncfs.c b/libnetfs/fsys-syncfs.c
index f57cb14..e232936 100644
--- a/libnetfs/fsys-syncfs.c
+++ b/libnetfs/fsys-syncfs.c
@@ -22,7 +22,7 @@
#include "fsys_S.h"
error_t
-netfs_S_fsys_syncfs (mach_port_t cntl,
+netfs_S_fsys_syncfs (struct netfs_control *cntl,
mach_port_t reply,
mach_msg_type_name_t reply_type,
int wait,
diff --git a/libnetfs/fsysstubs.c b/libnetfs/fsysstubs.c
index f44155d..a64fd64 100644
--- a/libnetfs/fsysstubs.c
+++ b/libnetfs/fsysstubs.c
@@ -23,7 +23,7 @@
#include "fsys_S.h"
error_t
-netfs_S_fsys_getfile (fsys_t cntl,
+netfs_S_fsys_getfile (struct netfs_control *cntl,
mach_port_t reply,
mach_msg_type_name_t reply_type,
uid_t *uids, mach_msg_type_number_t nuids,
@@ -35,7 +35,7 @@ netfs_S_fsys_getfile (fsys_t cntl,
}
error_t
-netfs_S_fsys_getpriv (fsys_t cntl,
+netfs_S_fsys_getpriv (struct netfs_control *cntl,
mach_port_t reply,
mach_msg_type_name_t reply_type,
mach_port_t *host, mach_msg_type_name_t *hosttp,
@@ -46,7 +46,7 @@ netfs_S_fsys_getpriv (fsys_t cntl,
}
error_t
-netfs_S_fsys_init (fsys_t cntl,
+netfs_S_fsys_init (struct netfs_control *cntl,
mach_port_t reply,
mach_msg_type_name_t reply_type,
mach_port_t proc, auth_t auth)
@@ -55,7 +55,7 @@ netfs_S_fsys_init (fsys_t cntl,
}
error_t
-netfs_S_fsys_forward (fsys_t cntl,
+netfs_S_fsys_forward (mach_port_t cntl,
mach_port_t reply,
mach_msg_type_name_t reply_type,
mach_port_t request,
diff --git a/libnetfs/get-source.c b/libnetfs/get-source.c
index 71a9639..73e48be 100644
--- a/libnetfs/get-source.c
+++ b/libnetfs/get-source.c
@@ -22,7 +22,7 @@
#include "priv.h"
error_t
-netfs_get_source (char *source)
+netfs_get_source (struct protid *cred, char *source, size_t source_len)
{
return EOPNOTSUPP;
}
diff --git a/libnetfs/mutations.h b/libnetfs/mutations.h
index e6700f5..51ca871 100644
--- a/libnetfs/mutations.h
+++ b/libnetfs/mutations.h
@@ -28,6 +28,9 @@
#define IO_INTRAN protid_t begin_using_protid_port (io_t)
#define IO_DESTRUCTOR end_using_protid_port (protid_t)
+#define FSYS_INTRAN control_t begin_using_control_port (fsys_t)
+#define FSYS_DESTRUCTOR end_using_control_port (control_t)
+
#define FILE_IMPORTS import "netfs.h"; import "priv.h";
#define IO_IMPORTS import "netfs.h"; import "priv.h";
#define FSYS_IMPORTS import "netfs.h"; import "priv.h";
diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h
index e10ccae..aef4a3d 100644
--- a/libnetfs/netfs.h
+++ b/libnetfs/netfs.h
@@ -100,6 +100,11 @@ struct node
struct dirmod *dirmod_reqs;
};
+struct netfs_control
+{
+ struct port_info pi;
+};
+
/* The user must define this variable. Set this to the name of the
filesystem server. */
extern char *netfs_server_name;
@@ -315,10 +320,11 @@ error_t netfs_file_get_storage_info (struct iouser *cred,
mach_msg_type_number_t *data_len);
/* The user may define this function. The function must set source to
- the source device of the filesystem. The function may return an
- EOPNOTSUPP to indicate that the concept of a source device is not
- applicable. The default function always returns EOPNOTSUPP. */
-error_t netfs_get_source (char *source);
+ the source of CRED. The function may return an EOPNOTSUPP to
+ indicate that the concept of a source device is not applicable. The
+ default function always returns EOPNOTSUPP. */
+error_t netfs_get_source (struct protid *cred,
+ char *source, size_t source_len);
/* Option parsing */
@@ -436,6 +442,7 @@ extern auth_t netfs_auth_server_port;
/* Mig gook. */
typedef struct protid *protid_t;
+typedef struct netfs_control *control_t;
#endif /* _HURD_NETFS_H_ */
diff --git a/libnetfs/priv.h b/libnetfs/priv.h
index 00db9fa..ba31080 100644
--- a/libnetfs/priv.h
+++ b/libnetfs/priv.h
@@ -37,4 +37,18 @@ end_using_protid_port (struct protid *cred)
if (cred)
ports_port_deref (cred);
}
+
+static inline struct netfs_control * __attribute__ ((unused))
+begin_using_control_port (fsys_t port)
+{
+ return ports_lookup_port (netfs_port_bucket, port, netfs_control_class);
+}
+
+static inline void __attribute__ ((unused))
+end_using_control_port (struct netfs_control *cred)
+{
+ if (cred)
+ ports_port_deref (cred);
+}
+
#endif
diff --git a/libpager/demuxer.c b/libpager/demuxer.c
index 79c0ddc..b4d4054 100644
--- a/libpager/demuxer.c
+++ b/libpager/demuxer.c
@@ -25,16 +25,16 @@ int
pager_demuxer (mach_msg_header_t *inp,
mach_msg_header_t *outp)
{
- extern int _pager_seqnos_memory_object_server (mach_msg_header_t *inp,
- mach_msg_header_t *outp);
- extern int _pager_seqnos_notify_server (mach_msg_header_t *inp,
- mach_msg_header_t *outp);
+ mig_routine_t routine;
+ if ((routine = _pager_seqnos_memory_object_server_routine (inp)) ||
+ (routine = _pager_seqnos_notify_server_routine (inp)))
+ {
+ (*routine) (inp, outp);
+ return TRUE;
+ }
- int result = _pager_seqnos_memory_object_server (inp, outp)
- || _pager_seqnos_notify_server (inp, outp);
- if (!result)
- /* Synchronize our bookkeeping of the port's seqno with the one consumed by
- this bogus message. */
- _pager_update_seqno (inp->msgh_local_port, inp->msgh_seqno);
- return result;
+ /* Synchronize our bookkeeping of the port's seqno with the one
+ consumed by this bogus message. */
+ _pager_update_seqno (inp->msgh_local_port, inp->msgh_seqno);
+ return FALSE;
}
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c
index 64e442f..2067cba 100644
--- a/libports/manage-multithread.c
+++ b/libports/manage-multithread.c
@@ -236,5 +236,11 @@ ports_manage_port_operations_multithread (struct
port_bucket *bucket,
return NULL;
}
+ /* XXX It is currently unsafe for most servers to terminate based on
+ inactivity because a request may arrive after a server has started
+ shutting down, causing the client to receive an error. Prevent the
+ master thread from going away. */
+ global_timeout = 0;
+
thread_function ((void *) 1);
}
diff --git a/libstore/Makefile b/libstore/Makefile
index 607940b..2bb5e4b 100644
--- a/libstore/Makefile
+++ b/libstore/Makefile
@@ -53,8 +53,8 @@ libstore.so-LDLIBS += $(PARTED_LIBS) -ldl
installhdrs=store.h
HURDLIBS = shouldbeinlibc
-LDLIBS += -lpthread
-GUNZIP_OBJS = unzip.o inflate.o util.o
+LDLIBS += -lpthread -lbz2 -lz
+GUNZIP_OBJS = do-gunzip.o util.o
BUNZIP2_OBJS = do-bunzip2.o
OBJS = $(SRCS:.c=.o) $(GUNZIP_OBJS) $(BUNZIP2_OBJS)
diff --git a/libstore/do-bunzip2.c b/libstore/do-bunzip2.c
index 716a0cd..d2bc9da 100644
--- a/libstore/do-bunzip2.c
+++ b/libstore/do-bunzip2.c
@@ -1,8 +1,25 @@
-/* bunzip2 engine, modified by address@hidden */
+/* bunzip2 decompression
-/* Stolen from util.c. */
-#include <stdio.h>
-#include <sys/types.h>
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Written by Ignazio Sgalmuzzo <address@hidden>
+
+ 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <bzlib.h>
/* I/O interface */
extern int (*unzip_read) (char *buf, size_t maxread);
@@ -14,1732 +31,57 @@ extern void (*unzip_error) (const char *msg);
#define INBUFSIZ 0x1000
#define OUTBUFSIZ 0x1000
-static unsigned char inbuf[INBUFSIZ];
-static unsigned char outbuf[OUTBUFSIZ];
-static unsigned inptr;
-static unsigned insize;
-static unsigned outcnt;
-
-/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty.
- */
-static int
-fill_inbuf (int eof_ok)
-{
- int len;
-
- /* Read as much as possible */
- insize = 0;
- do
- {
- len = (*unzip_read)((char*)inbuf+insize, INBUFSIZ-insize);
- if (len == 0 || len == EOF)
- break;
- insize += len;
- }
- while (insize < INBUFSIZ);
-
- if (insize == 0)
- {
- if (eof_ok)
- return EOF;
- unzip_read_error();
- }
-
- inptr = 1;
- return inbuf[0];
-}
-
-static void
-flush_outbuf (void)
-{
- if (outcnt == 0)
- return;
-
- (*unzip_write) ((char *) outbuf, outcnt);
- outcnt = 0;
-}
-
-static inline int
-bz2_getc (void *stream)
-{
- return inptr < insize ? inbuf[inptr++] : fill_inbuf (1);
-}
-
-static inline int
-bz2_putc (int c, void *stream)
-{
- if (outcnt == OUTBUFSIZ)
- flush_outbuf ();
- outbuf[outcnt++] = c;
- return c;
-}
-
-static inline int
-bz2_ferror (void *stream)
-{
- return 0;
-}
-
-static inline int
-bz2_fflush (void *stream)
-{
- flush_outbuf ();
- return 0;
-}
-
-static inline int
-bz2_fclose (void *stream)
-{
- flush_outbuf ();
- return 0;
-}
-
-#define fprintf(s, f...) /**/
-
-
-/*-----------------------------------------------------------*/
-/*--- A block-sorting, lossless compressor bzip2.c ---*/
-/*-----------------------------------------------------------*/
-
-/*--
- This program is bzip2, a lossless, block-sorting data compressor,
- version 0.1pl2, dated 29-Aug-1997.
-
- Copyright (C) 1996, 1997 by Julian Seward.
- Guildford, Surrey, UK
- email: address@hidden
-
- 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 of the License, 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.
-
- The GNU General Public License is contained in the file LICENSE.
-
- This program is based on (at least) the work of:
- Mike Burrows
- David Wheeler
- Peter Fenwick
- Alistair Moffat
- Radford Neal
- Ian H. Witten
- Robert Sedgewick
- Jon L. Bentley
-
- For more information on these sources, see the file ALGORITHMS.
---*/
-
-/*----------------------------------------------------*/
-/*--- IMPORTANT ---*/
-/*----------------------------------------------------*/
-
-/*--
- WARNING:
- This program (attempts to) compress data by performing several
- non-trivial transformations on it. Unless you are 100% familiar
- with *all* the algorithms contained herein, and with the
- consequences of modifying them, you should NOT meddle with the
- compression or decompression machinery. Incorrect changes can
- and very likely *will* lead to disastrous loss of data.
-
- DISCLAIMER:
- I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
- USE OF THIS PROGRAM, HOWSOEVER CAUSED.
-
- Every compression of a file implies an assumption that the
- compressed file can be decompressed to reproduce the original.
- Great efforts in design, coding and testing have been made to
- ensure that this program works correctly. However, the
- complexity of the algorithms, and, in particular, the presence
- of various special cases in the code which occur with very low
- but non-zero probability make it impossible to rule out the
- possibility of bugs remaining in the program. DO NOT COMPRESS
- ANY DATA WITH THIS PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE
- POSSIBILITY, HOWEVER SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
-
- That is not to say this program is inherently unreliable.
- Indeed, I very much hope the opposite is true. bzip2 has been
- carefully constructed and extensively tested.
-
- PATENTS:
- To the best of my knowledge, bzip2 does not use any patented
- algorithms. However, I do not have the resources available to
- carry out a full patent search. Therefore I cannot give any
- guarantee of the above statement.
---*/
-
-
-
-/*----------------------------------------------------*/
-/*--- and now for something much more pleasant :-) ---*/
-/*----------------------------------------------------*/
-
-/*---------------------------------------------*/
-/*--
- Place a 1 beside your platform, and 0 elsewhere.
---*/
-
-/*--
- Generic 32-bit Unix.
- Also works on 64-bit Unix boxes.
---*/
-#define BZ_UNIX 1
-
-/*--
- Win32, as seen by Jacob Navia's excellent
- port of (Chris Fraser & David Hanson)'s excellent
- lcc compiler.
---*/
-#define BZ_LCCWIN32 0
-
-
-
-/*---------------------------------------------*/
-/*--
- Some stuff for all platforms.
---*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#if DEBUG
- #include <assert.h>
-#endif
-#include <string.h>
-#include <signal.h>
-#include <math.h>
-
-#define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); }
-#define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); }
-#define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); }
-
-
-/*---------------------------------------------*/
-/*--
- Platform-specific stuff.
---*/
-
-#if BZ_UNIX
- #include <sys/types.h>
- #include <utime.h>
- #include <unistd.h>
- #include <malloc.h>
- #include <sys/stat.h>
- #include <sys/times.h>
-
- #define Int32 int
- #define UInt32 unsigned int
- #define Char char
- #define UChar unsigned char
- #define Int16 short
- #define UInt16 unsigned short
-
- #define PATH_SEP '/'
- #define MY_LSTAT lstat
- #define MY_S_IFREG S_ISREG
- #define MY_STAT stat
-
- #define APPEND_FILESPEC(root, name) \
- root=snocString((root), (name))
-
- #define SET_BINARY_MODE(fd) /**/
-
- /*--
- You should try very hard to persuade your C compiler
- to inline the bits marked INLINE. Otherwise bzip2 will
- run rather slowly. gcc version 2.x is recommended.
- --*/
- #ifdef __GNUC__
- #define INLINE inline
- #define NORETURN __attribute__ ((noreturn))
- #else
- #define INLINE /**/
- #define NORETURN /**/
- #endif
-#endif
-
-
-
-#if BZ_LCCWIN32
- #include <io.h>
- #include <fcntl.h>
- #include <sys\stat.h>
-
- #define Int32 int
- #define UInt32 unsigned int
- #define Int16 short
- #define UInt16 unsigned short
- #define Char char
- #define UChar unsigned char
-
- #define INLINE /**/
- #define NORETURN /**/
- #define PATH_SEP '\\'
- #define MY_LSTAT _stat
- #define MY_STAT _stat
- #define MY_S_IFREG(x) ((x) & _S_IFREG)
-
- #if 0
- /*-- lcc-win32 seems to expand wildcards itself --*/
- #define APPEND_FILESPEC(root, spec) \
- do { \
- if ((spec)[0] == '-') { \
- root = snocString((root), (spec)); \
- } else { \
- struct _finddata_t c_file; \
- long hFile; \
- hFile = _findfirst((spec), &c_file); \
- if ( hFile == -1L ) { \
- root = snocString ((root), (spec)); \
- } else { \
- int anInt = 0; \
- while ( anInt == 0 ) { \
- root = snocString((root), \
- &c_file.name[0]); \
- anInt = _findnext(hFile, &c_file); \
- } \
- } \
- } \
- } while ( 0 )
- #else
- #define APPEND_FILESPEC(root, name) \
- root = snocString ((root), (name))
- #endif
-
- #define SET_BINARY_MODE(fd) \
- do { \
- int retVal = setmode ( fileno ( fd ), \
- O_BINARY ); \
- ERROR_IF_MINUS_ONE ( retVal ); \
- } while ( 0 )
-
-#endif
-
-
-/*---------------------------------------------*/
-/*--
- Some more stuff for all platforms :-)
---*/
-
-#define Bool unsigned char
-#define True 1
-#define False 0
-
-/*--
- IntNative is your platform's `native' int size.
- Only here to avoid probs with 64-bit platforms.
---*/
-#define IntNative int
-
-
-/*--
- change to 1, or compile with -DDEBUG=1 to debug
---*/
-#ifndef DEBUG
-#define DEBUG 0
-#endif
-
-
-/*---------------------------------------------------*/
-/*--- ---*/
-/*---------------------------------------------------*/
-
-/*--
- Implementation notes, July 1997
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- Memory allocation
- ~~~~~~~~~~~~~~~~~
- All large data structures are allocated on the C heap,
- for better or for worse. That includes the various
- arrays of pointers, striped words, bytes, frequency
- tables and buffers for compression and decompression.
-
- bzip2 can operate at various block-sizes, ranging from
- 100k to 900k in 100k steps, and it allocates only as
- much as it needs to. When compressing, we know from the
- command-line options what the block-size is going to be,
- so all allocation can be done at start-up; if that
- succeeds, there can be no further allocation problems.
-
- Decompression is more complicated. Each compressed file
- contains, in its header, a byte indicating the block
- size used for compression. This means bzip2 potentially
- needs to reallocate memory for each file it deals with,
- which in turn opens the possibility for a memory allocation
- failure part way through a run of files, by encountering
- a file requiring a much larger block size than all the
- ones preceding it.
-
- The policy is to simply give up if a memory allocation
- failure occurs. During decompression, it would be
- possible to move on to subsequent files in the hope that
- some might ask for a smaller block size, but the
- complications for doing this seem more trouble than they
- are worth.
-
-
- Compressed file formats
- ~~~~~~~~~~~~~~~~~~~~~~~
- [This is now entirely different from both 0.21, and from
- any previous Huffman-coded variant of bzip.
- See the associated file bzip2.txt for details.]
-
-
- Error conditions
- ~~~~~~~~~~~~~~~~
- Dealing with error conditions is the least satisfactory
- aspect of bzip2. The policy is to try and leave the
- filesystem in a consistent state, then quit, even if it
- means not processing some of the files mentioned in the
- command line. `A consistent state' means that a file
- exists either in its compressed or uncompressed form,
- but not both. This boils down to the rule `delete the
- output file if an error condition occurs, leaving the
- input intact'. Input files are only deleted when we can
- be pretty sure the output file has been written and
- closed successfully.
-
- Errors are a dog because there's so many things to
- deal with. The following can happen mid-file, and
- require cleaning up.
-
- internal `panics' -- indicating a bug
- corrupted or inconsistent compressed file
- can't allocate enough memory to decompress this file
- I/O error reading/writing/opening/closing
- signal catches -- Control-C, SIGTERM, SIGHUP.
-
- Other conditions, primarily pertaining to file names,
- can be checked in-between files, which makes dealing
- with them easier.
---*/
-
-
-
-/*---------------------------------------------------*/
-/*--- Misc (file handling) data decls ---*/
-/*---------------------------------------------------*/
-
-static UInt32 bytesIn, bytesOut;
-static Int32 verbosity;
-static Bool smallMode;
-static UInt32 globalCrc;
-
-
-
-
-static void panic ( Char* );
-static void ioError ( void );
-static void uncompressOutOfMemory ( Int32, Int32 );
-static void blockOverrun ( void );
-static void badBlockHeader ( void );
-static void crcError ( UInt32, UInt32 );
-static void cleanUpAndFail ( Int32 );
-static void compressedStreamEOF ( void );
-
-
-
-/*---------------------------------------------------*/
-/*--- Data decls for the front end ---*/
-/*---------------------------------------------------*/
-
-/*--
- The overshoot bytes allow us to avoid most of
- the cost of pointer renormalisation during
- comparison of rotations in sorting.
- The figure of 20 is derived as follows:
- qSort3 allows an overshoot of up to 10.
- It then calls simpleSort, which calls
- fullGtU, also with max overshoot 10.
- fullGtU does up to 10 comparisons without
- renormalising, giving 10+10 == 20.
---*/
-#define NUM_OVERSHOOT_BYTES 20
-
-/*--
- These are the main data structures for
- the Burrows-Wheeler transform.
---*/
-
-/*--
- Pointers to compression and decompression
- structures. Set by
- allocateCompressStructures and
- setDecompressStructureSizes
-
- The structures are always set to be suitable
- for a block of size 100000 * blockSize100k.
---*/
-static UInt16 *ll16; /*-- small decompress --*/
-static UChar *ll4; /*-- small decompress --*/
-
-static Int32 *tt; /*-- fast decompress --*/
-static UChar *ll8; /*-- fast decompress --*/
-
-
-/*--
- freq table collected to save a pass over the data
- during decompression.
---*/
-static Int32 unzftab[256];
-
-
-/*--
- index of the last char in the block, so
- the block size == last + 1.
---*/
-static Int32 last;
-
-
-/*--
- index in zptr[] of original string after sorting.
---*/
-static Int32 origPtr;
-
-
-/*--
- always: in the range 0 .. 9.
- The current block size is 100000 * this number.
---*/
-static Int32 blockSize100k;
-
-
-/*--
- Used when sorting. If too many long comparisons
- happen, we stop sorting, randomise the block
- slightly, and try again.
---*/
-
-static Bool blockRandomised;
-
-
-
-/*---------------------------------------------------*/
-/*--- Data decls for the back end ---*/
-/*---------------------------------------------------*/
-
-#define MAX_ALPHA_SIZE 258
-#define MAX_CODE_LEN 23
-
-#define RUNA 0
-#define RUNB 1
-
-#define N_GROUPS 6
-#define G_SIZE 50
-#define N_ITERS 4
-
-#define MAX_SELECTORS (2 + (900000 / G_SIZE))
-
-static Bool inUse[256];
-static Int32 nInUse;
-
-static UChar seqToUnseq[256];
-static UChar unseqToSeq[256];
-
-static UChar selector [MAX_SELECTORS];
-static UChar selectorMtf[MAX_SELECTORS];
-
-static UChar len [N_GROUPS][MAX_ALPHA_SIZE];
-
-/*-- decompress only --*/
-static Int32 limit [N_GROUPS][MAX_ALPHA_SIZE];
-static Int32 base [N_GROUPS][MAX_ALPHA_SIZE];
-static Int32 perm [N_GROUPS][MAX_ALPHA_SIZE];
-static Int32 minLens[N_GROUPS];
-
-
-/*---------------------------------------------------*/
-/*--- 32-bit CRC grunge ---*/
-/*---------------------------------------------------*/
-
-/*--
- I think this is an implementation of the AUTODIN-II,
- Ethernet & FDDI 32-bit CRC standard. Vaguely derived
- from code by Rob Warnock, in Section 51 of the
- comp.compression FAQ.
---*/
-
-static UInt32 crc32Table[256] = {
-
- /*-- Ugly, innit? --*/
-
- 0x00000000UL, 0x04c11db7UL, 0x09823b6eUL, 0x0d4326d9UL,
- 0x130476dcUL, 0x17c56b6bUL, 0x1a864db2UL, 0x1e475005UL,
- 0x2608edb8UL, 0x22c9f00fUL, 0x2f8ad6d6UL, 0x2b4bcb61UL,
- 0x350c9b64UL, 0x31cd86d3UL, 0x3c8ea00aUL, 0x384fbdbdUL,
- 0x4c11db70UL, 0x48d0c6c7UL, 0x4593e01eUL, 0x4152fda9UL,
- 0x5f15adacUL, 0x5bd4b01bUL, 0x569796c2UL, 0x52568b75UL,
- 0x6a1936c8UL, 0x6ed82b7fUL, 0x639b0da6UL, 0x675a1011UL,
- 0x791d4014UL, 0x7ddc5da3UL, 0x709f7b7aUL, 0x745e66cdUL,
- 0x9823b6e0UL, 0x9ce2ab57UL, 0x91a18d8eUL, 0x95609039UL,
- 0x8b27c03cUL, 0x8fe6dd8bUL, 0x82a5fb52UL, 0x8664e6e5UL,
- 0xbe2b5b58UL, 0xbaea46efUL, 0xb7a96036UL, 0xb3687d81UL,
- 0xad2f2d84UL, 0xa9ee3033UL, 0xa4ad16eaUL, 0xa06c0b5dUL,
- 0xd4326d90UL, 0xd0f37027UL, 0xddb056feUL, 0xd9714b49UL,
- 0xc7361b4cUL, 0xc3f706fbUL, 0xceb42022UL, 0xca753d95UL,
- 0xf23a8028UL, 0xf6fb9d9fUL, 0xfbb8bb46UL, 0xff79a6f1UL,
- 0xe13ef6f4UL, 0xe5ffeb43UL, 0xe8bccd9aUL, 0xec7dd02dUL,
- 0x34867077UL, 0x30476dc0UL, 0x3d044b19UL, 0x39c556aeUL,
- 0x278206abUL, 0x23431b1cUL, 0x2e003dc5UL, 0x2ac12072UL,
- 0x128e9dcfUL, 0x164f8078UL, 0x1b0ca6a1UL, 0x1fcdbb16UL,
- 0x018aeb13UL, 0x054bf6a4UL, 0x0808d07dUL, 0x0cc9cdcaUL,
- 0x7897ab07UL, 0x7c56b6b0UL, 0x71159069UL, 0x75d48ddeUL,
- 0x6b93dddbUL, 0x6f52c06cUL, 0x6211e6b5UL, 0x66d0fb02UL,
- 0x5e9f46bfUL, 0x5a5e5b08UL, 0x571d7dd1UL, 0x53dc6066UL,
- 0x4d9b3063UL, 0x495a2dd4UL, 0x44190b0dUL, 0x40d816baUL,
- 0xaca5c697UL, 0xa864db20UL, 0xa527fdf9UL, 0xa1e6e04eUL,
- 0xbfa1b04bUL, 0xbb60adfcUL, 0xb6238b25UL, 0xb2e29692UL,
- 0x8aad2b2fUL, 0x8e6c3698UL, 0x832f1041UL, 0x87ee0df6UL,
- 0x99a95df3UL, 0x9d684044UL, 0x902b669dUL, 0x94ea7b2aUL,
- 0xe0b41de7UL, 0xe4750050UL, 0xe9362689UL, 0xedf73b3eUL,
- 0xf3b06b3bUL, 0xf771768cUL, 0xfa325055UL, 0xfef34de2UL,
- 0xc6bcf05fUL, 0xc27dede8UL, 0xcf3ecb31UL, 0xcbffd686UL,
- 0xd5b88683UL, 0xd1799b34UL, 0xdc3abdedUL, 0xd8fba05aUL,
- 0x690ce0eeUL, 0x6dcdfd59UL, 0x608edb80UL, 0x644fc637UL,
- 0x7a089632UL, 0x7ec98b85UL, 0x738aad5cUL, 0x774bb0ebUL,
- 0x4f040d56UL, 0x4bc510e1UL, 0x46863638UL, 0x42472b8fUL,
- 0x5c007b8aUL, 0x58c1663dUL, 0x558240e4UL, 0x51435d53UL,
- 0x251d3b9eUL, 0x21dc2629UL, 0x2c9f00f0UL, 0x285e1d47UL,
- 0x36194d42UL, 0x32d850f5UL, 0x3f9b762cUL, 0x3b5a6b9bUL,
- 0x0315d626UL, 0x07d4cb91UL, 0x0a97ed48UL, 0x0e56f0ffUL,
- 0x1011a0faUL, 0x14d0bd4dUL, 0x19939b94UL, 0x1d528623UL,
- 0xf12f560eUL, 0xf5ee4bb9UL, 0xf8ad6d60UL, 0xfc6c70d7UL,
- 0xe22b20d2UL, 0xe6ea3d65UL, 0xeba91bbcUL, 0xef68060bUL,
- 0xd727bbb6UL, 0xd3e6a601UL, 0xdea580d8UL, 0xda649d6fUL,
- 0xc423cd6aUL, 0xc0e2d0ddUL, 0xcda1f604UL, 0xc960ebb3UL,
- 0xbd3e8d7eUL, 0xb9ff90c9UL, 0xb4bcb610UL, 0xb07daba7UL,
- 0xae3afba2UL, 0xaafbe615UL, 0xa7b8c0ccUL, 0xa379dd7bUL,
- 0x9b3660c6UL, 0x9ff77d71UL, 0x92b45ba8UL, 0x9675461fUL,
- 0x8832161aUL, 0x8cf30badUL, 0x81b02d74UL, 0x857130c3UL,
- 0x5d8a9099UL, 0x594b8d2eUL, 0x5408abf7UL, 0x50c9b640UL,
- 0x4e8ee645UL, 0x4a4ffbf2UL, 0x470cdd2bUL, 0x43cdc09cUL,
- 0x7b827d21UL, 0x7f436096UL, 0x7200464fUL, 0x76c15bf8UL,
- 0x68860bfdUL, 0x6c47164aUL, 0x61043093UL, 0x65c52d24UL,
- 0x119b4be9UL, 0x155a565eUL, 0x18197087UL, 0x1cd86d30UL,
- 0x029f3d35UL, 0x065e2082UL, 0x0b1d065bUL, 0x0fdc1becUL,
- 0x3793a651UL, 0x3352bbe6UL, 0x3e119d3fUL, 0x3ad08088UL,
- 0x2497d08dUL, 0x2056cd3aUL, 0x2d15ebe3UL, 0x29d4f654UL,
- 0xc5a92679UL, 0xc1683bceUL, 0xcc2b1d17UL, 0xc8ea00a0UL,
- 0xd6ad50a5UL, 0xd26c4d12UL, 0xdf2f6bcbUL, 0xdbee767cUL,
- 0xe3a1cbc1UL, 0xe760d676UL, 0xea23f0afUL, 0xeee2ed18UL,
- 0xf0a5bd1dUL, 0xf464a0aaUL, 0xf9278673UL, 0xfde69bc4UL,
- 0x89b8fd09UL, 0x8d79e0beUL, 0x803ac667UL, 0x84fbdbd0UL,
- 0x9abc8bd5UL, 0x9e7d9662UL, 0x933eb0bbUL, 0x97ffad0cUL,
- 0xafb010b1UL, 0xab710d06UL, 0xa6322bdfUL, 0xa2f33668UL,
- 0xbcb4666dUL, 0xb8757bdaUL, 0xb5365d03UL, 0xb1f740b4UL
-};
-
-
-/*---------------------------------------------*/
-
-static void initialiseCRC ( void )
-{
- globalCrc = 0xffffffffUL;
-}
-
-
-/*---------------------------------------------*/
-
-static UInt32 getFinalCRC ( void )
-{
- return ~globalCrc;
-}
-
-
-/*---------------------------------------------*/
-
-static UInt32 getGlobalCRC ( void )
-{
- return globalCrc;
-}
-
-
-/*---------------------------------------------*/
-
-static void setGlobalCRC ( UInt32 newCrc )
-{
- globalCrc = newCrc;
-}
-
-
-/*---------------------------------------------*/
-
-#define UPDATE_CRC(crcVar,cha) \
-{ \
- crcVar = (crcVar << 8) ^ \
- crc32Table[(crcVar >> 24) ^ \
- ((UChar)cha)]; \
-}
-
-
-/*---------------------------------------------------*/
-/*--- Bit stream I/O ---*/
-/*---------------------------------------------------*/
-
-
-static UInt32 bsBuff;
-static Int32 bsLive;
-static void* bsStream;
-static Bool bsWriting;
-
-
-/*---------------------------------------------*/
-
-static void bsSetStream ( void* f, Bool wr )
-{
- if (bsStream != NULL) panic ( "bsSetStream" );
- bsStream = f;
- bsLive = 0;
- bsBuff = 0;
- bytesOut = 0;
- bytesIn = 0;
- bsWriting = wr;
-}
-
-
-/*---------------------------------------------*/
-
-static void bsFinishedWithStream ( void )
-{
- if (bsWriting)
- while (bsLive > 0) {
- bz2_putc ( (UChar)(bsBuff >> 24), bsStream );
- bsBuff <<= 8;
- bsLive -= 8;
- bytesOut++;
- }
- bsStream = NULL;
-}
-
-
-/*---------------------------------------------*/
-
-#define bsNEEDR(nz) \
-{ \
- while (bsLive < nz) { \
- Int32 zzi = bz2_getc ( bsStream ); \
- if (zzi == EOF) compressedStreamEOF(); \
- bsBuff = (bsBuff << 8) | (zzi & 0xffL); \
- bsLive += 8; \
- } \
-}
-
-
-/*---------------------------------------------*/
-
-#define bsR1(vz) \
-{ \
- bsNEEDR(1); \
- vz = (bsBuff >> (bsLive-1)) & 1; \
- bsLive--; \
-}
-
-
-/*---------------------------------------------*/
-
-static INLINE UInt32 bsR ( Int32 n )
-{
- UInt32 v;
- bsNEEDR ( n );
- v = (bsBuff >> (bsLive-n)) & ((1 << n)-1);
- bsLive -= n;
- return v;
-}
-
-
-/*---------------------------------------------*/
-
-static UChar bsGetUChar ( void )
-{
- return (UChar)bsR(8);
-}
-
-
-
-/*---------------------------------------------*/
-
-static Int32 bsGetUInt32 ( void )
-{
- UInt32 u;
- u = 0;
- u = (u << 8) | bsR(8);
- u = (u << 8) | bsR(8);
- u = (u << 8) | bsR(8);
- u = (u << 8) | bsR(8);
- return u;
-}
-
-
-/*---------------------------------------------*/
-
-static UInt32 bsGetIntVS ( UInt32 numBits )
-{
- return (UInt32)bsR(numBits);
-}
-
-
-
-/*---------------------------------------------------*/
-/*--- Huffman coding low-level stuff ---*/
-/*---------------------------------------------------*/
-
-
-/*---------------------------------------------*/
-
-static void hbCreateDecodeTables ( Int32 *limit,
- Int32 *base,
- Int32 *perm,
- UChar *length,
- Int32 minLen,
- Int32 maxLen,
- Int32 alphaSize )
-{
- Int32 pp, i, j, vec;
-
- pp = 0;
- for (i = minLen; i <= maxLen; i++)
- for (j = 0; j < alphaSize; j++)
- if (length[j] == i) { perm[pp] = j; pp++; };
-
- for (i = 0; i < MAX_CODE_LEN; i++) base[i] = 0;
- for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
-
- for (i = 1; i < MAX_CODE_LEN; i++) base[i] += base[i-1];
-
- for (i = 0; i < MAX_CODE_LEN; i++) limit[i] = 0;
- vec = 0;
-
- for (i = minLen; i <= maxLen; i++) {
- vec += (base[i+1] - base[i]);
- limit[i] = vec-1;
- vec <<= 1;
- }
- for (i = minLen + 1; i <= maxLen; i++)
- base[i] = ((limit[i-1] + 1) << 1) - base[i];
-}
-
-
-
-/*---------------------------------------------------*/
-/*--- Undoing the reversible transformation ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-
-#define SET_LL4(i,n) \
- { if (((i) & 0x1) == 0) \
- ll4[(i) >> 1] = (ll4[(i) >> 1] & 0xf0) | (n); else \
- ll4[(i) >> 1] = (ll4[(i) >> 1] & 0x0f) | ((n) << 4); \
- }
-
-
-#define GET_LL4(i) \
- (((UInt32)(ll4[(i) >> 1])) >> (((i) << 2) & 0x4) & 0xF)
-
-
-#define SET_LL(i,n) \
- { ll16[i] = (UInt16)(n & 0x0000ffff); \
- SET_LL4(i, n >> 16); \
- }
-
-
-#define GET_LL(i) \
- (((UInt32)ll16[i]) | (GET_LL4(i) << 16))
-
-
-/*---------------------------------------------*/
-/*--
- Manage memory for compression/decompression.
- When compressing, a single block size applies to
- all files processed, and that's set when the
- program starts. But when decompressing, each file
- processed could have been compressed with a
- different block size, so we may have to free
- and reallocate on a per-file basis.
-
- A call with argument of zero means
- `free up everything.' And a value of zero for
- blockSize100k means no memory is currently allocated.
---*/
-
-
-/*---------------------------------------------*/
-
-static void setDecompressStructureSizes ( Int32 newSize100k )
-{
- if (! (0 <= newSize100k && newSize100k <= 9 &&
- 0 <= blockSize100k && blockSize100k <= 9))
- panic ( "setDecompressStructureSizes" );
-
- if (newSize100k == blockSize100k) return;
-
- blockSize100k = newSize100k;
-
- if (ll16 != NULL) free ( ll16 );
- if (ll4 != NULL) free ( ll4 );
- if (ll8 != NULL) free ( ll8 );
- if (tt != NULL) free ( tt );
-
- if (newSize100k == 0) return;
-
- if (smallMode) {
-
- Int32 n = 100000 * newSize100k;
- ll16 = malloc ( n * sizeof(UInt16) );
- ll4 = malloc ( ((n+1) >> 1) * sizeof(UChar) );
-
- if (ll4 == NULL || ll16 == NULL) {
- Int32 totalDraw
- = n * sizeof(Int16) + ((n+1) >> 1) * sizeof(UChar);
- uncompressOutOfMemory ( totalDraw, n );
- }
-
- } else {
-
- Int32 n = 100000 * newSize100k;
- ll8 = malloc ( n * sizeof(UChar) );
- tt = malloc ( n * sizeof(Int32) );
-
- if (ll8 == NULL || tt == NULL) {
- Int32 totalDraw
- = n * sizeof(UChar) + n * sizeof(UInt32);
- uncompressOutOfMemory ( totalDraw, n );
- }
-
- }
-}
-
-
-
-/*---------------------------------------------------*/
-/*--- The new back end ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-
-static void makeMaps ( void )
-{
- Int32 i;
- nInUse = 0;
- for (i = 0; i < 256; i++)
- if (inUse[i]) {
- seqToUnseq[nInUse] = i;
- unseqToSeq[i] = nInUse;
- nInUse++;
- }
-}
-
-
-
-/*---------------------------------------------*/
-
-static void recvDecodingTables ( void )
-{
- Int32 i, j, t, nGroups, nSelectors, alphaSize;
- Int32 minLen, maxLen;
- Bool inUse16[16];
-
- /*--- Receive the mapping table ---*/
- for (i = 0; i < 16; i++)
- if (bsR(1) == 1)
- inUse16[i] = True; else
- inUse16[i] = False;
-
- for (i = 0; i < 256; i++) inUse[i] = False;
-
- for (i = 0; i < 16; i++)
- if (inUse16[i])
- for (j = 0; j < 16; j++)
- if (bsR(1) == 1) inUse[i * 16 + j] = True;
-
- makeMaps();
- alphaSize = nInUse+2;
-
- /*--- Now the selectors ---*/
- nGroups = bsR ( 3 );
- nSelectors = bsR ( 15 );
- for (i = 0; i < nSelectors; i++) {
- j = 0;
- while (bsR(1) == 1) j++;
- selectorMtf[i] = j;
- }
-
- /*--- Undo the MTF values for the selectors. ---*/
- {
- UChar pos[N_GROUPS], tmp, v;
- for (v = 0; v < nGroups; v++) pos[v] = v;
-
- for (i = 0; i < nSelectors; i++) {
- v = selectorMtf[i];
- tmp = pos[v];
- while (v > 0) { pos[v] = pos[v-1]; v--; }
- pos[0] = tmp;
- selector[i] = tmp;
- }
- }
-
- /*--- Now the coding tables ---*/
- for (t = 0; t < nGroups; t++) {
- Int32 curr = bsR ( 5 );
- for (i = 0; i < alphaSize; i++) {
- while (bsR(1) == 1) {
- if (bsR(1) == 0) curr++; else curr--;
- }
- len[t][i] = curr;
- }
- }
-
- /*--- Create the Huffman decoding tables ---*/
- for (t = 0; t < nGroups; t++) {
- minLen = 32;
- maxLen = 0;
- for (i = 0; i < alphaSize; i++) {
- if (len[t][i] > maxLen) maxLen = len[t][i];
- if (len[t][i] < minLen) minLen = len[t][i];
- }
- hbCreateDecodeTables (
- &limit[t][0], &base[t][0], &perm[t][0], &len[t][0],
- minLen, maxLen, alphaSize
- );
- minLens[t] = minLen;
- }
-}
-
-
-/*---------------------------------------------*/
-
-#define GET_MTF_VAL(lval) \
-{ \
- Int32 zt, zn, zvec, zj; \
- if (groupPos == 0) { \
- groupNo++; \
- groupPos = G_SIZE; \
- } \
- groupPos--; \
- zt = selector[groupNo]; \
- zn = minLens[zt]; \
- zvec = bsR ( zn ); \
- while (zvec > limit[zt][zn]) { \
- zn++; bsR1(zj); \
- zvec = (zvec << 1) | zj; \
- }; \
- lval = perm[zt][zvec - base[zt][zn]]; \
-}
-
-
-/*---------------------------------------------*/
-
-static void getAndMoveToFrontDecode ( void )
-{
- UChar yy[256];
- Int32 i, j, nextSym, limitLast;
- Int32 EOB, groupNo, groupPos;
-
- limitLast = 100000 * blockSize100k;
- origPtr = bsGetIntVS ( 24 );
-
- recvDecodingTables();
- EOB = nInUse+1;
- groupNo = -1;
- groupPos = 0;
-
- /*--
- Setting up the unzftab entries here is not strictly
- necessary, but it does save having to do it later
- in a separate pass, and so saves a block's worth of
- cache misses.
- --*/
- for (i = 0; i <= 255; i++) unzftab[i] = 0;
-
- for (i = 0; i <= 255; i++) yy[i] = (UChar) i;
-
- last = -1;
-
- GET_MTF_VAL(nextSym);
-
- while (True) {
-
- if (nextSym == EOB) break;
-
- if (nextSym == RUNA || nextSym == RUNB) {
- UChar ch;
- Int32 s = -1;
- Int32 N = 1;
- do {
- if (nextSym == RUNA) s = s + (0+1) * N; else
- if (nextSym == RUNB) s = s + (1+1) * N;
- N = N * 2;
- GET_MTF_VAL(nextSym);
- }
- while (nextSym == RUNA || nextSym == RUNB);
-
- s++;
- ch = seqToUnseq[yy[0]];
- unzftab[ch] += s;
-
- if (smallMode)
- while (s > 0) {
- last++;
- ll16[last] = ch;
- s--;
- }
- else
- while (s > 0) {
- last++;
- ll8[last] = ch;
- s--;
- };
-
- if (last >= limitLast) blockOverrun();
- continue;
-
- } else {
-
- UChar tmp;
- last++; if (last >= limitLast) blockOverrun();
-
- tmp = yy[nextSym-1];
- unzftab[seqToUnseq[tmp]]++;
- if (smallMode)
- ll16[last] = seqToUnseq[tmp]; else
- ll8[last] = seqToUnseq[tmp];
-
- /*--
- This loop is hammered during decompression,
- hence the unrolling.
-
- for (j = nextSym-1; j > 0; j--) yy[j] = yy[j-1];
- --*/
-
- j = nextSym-1;
- for (; j > 3; j -= 4) {
- yy[j] = yy[j-1];
- yy[j-1] = yy[j-2];
- yy[j-2] = yy[j-3];
- yy[j-3] = yy[j-4];
- }
- for (; j > 0; j--) yy[j] = yy[j-1];
-
- yy[0] = tmp;
- GET_MTF_VAL(nextSym);
- continue;
- }
- }
-}
-
-
-/*---------------------------------------------------*/
-/*--- Stuff for randomising repetitive blocks ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-static Int32 rNums[512] = {
- 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
- 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
- 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
- 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
- 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
- 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
- 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
- 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
- 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
- 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
- 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
- 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
- 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
- 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
- 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
- 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
- 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
- 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
- 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
- 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
- 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
- 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
- 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
- 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
- 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
- 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
- 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
- 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
- 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
- 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
- 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
- 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
- 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
- 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
- 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
- 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
- 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
- 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
- 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
- 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
- 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
- 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
- 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
- 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
- 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
- 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
- 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
- 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
- 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
- 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
- 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
- 936, 638
-};
-
-
-#define RAND_DECLS \
- Int32 rNToGo = 0; \
- Int32 rTPos = 0; \
-
-#define RAND_MASK ((rNToGo == 1) ? 1 : 0)
-
-#define RAND_UPD_MASK \
- if (rNToGo == 0) { \
- rNToGo = rNums[rTPos]; \
- rTPos++; if (rTPos == 512) rTPos = 0; \
- } \
- rNToGo--;
-
-
-
-/*---------------------------------------------------*/
-/*--- The Reversible Transformation (tm) ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-
-
-static INLINE Int32 indexIntoF ( Int32 indx, Int32 *cftab )
-{
- Int32 nb, na, mid;
- nb = 0;
- na = 256;
- do {
- mid = (nb + na) >> 1;
- if (indx >= cftab[mid]) nb = mid; else na = mid;
- }
- while (na - nb != 1);
- return nb;
-}
-
-
-
-#define GET_SMALL(cccc) \
- \
- cccc = indexIntoF ( tPos, cftab ); \
- tPos = GET_LL(tPos);
-
-
-
-static void undoReversibleTransformation_small ( void* dst )
-{
- Int32 cftab[257], cftabAlso[257];
- Int32 i, j, tmp, tPos;
- UChar ch;
-
- /*--
- We assume here that the global array unzftab will
- already be holding the frequency counts for
- ll8[0 .. last].
- --*/
-
- /*-- Set up cftab to facilitate generation of indexIntoF --*/
- cftab[0] = 0;
- for (i = 1; i <= 256; i++) cftab[i] = unzftab[i-1];
- for (i = 1; i <= 256; i++) cftab[i] += cftab[i-1];
-
- /*-- Make a copy of it, used in generation of T --*/
- for (i = 0; i <= 256; i++) cftabAlso[i] = cftab[i];
-
- /*-- compute the T vector --*/
- for (i = 0; i <= last; i++) {
- ch = (UChar)ll16[i];
- SET_LL(i, cftabAlso[ch]);
- cftabAlso[ch]++;
- }
-
- /*--
- Compute T^(-1) by pointer reversal on T. This is rather
- subtle, in that, if the original block was two or more
- (in general, N) concatenated copies of the same thing,
- the T vector will consist of N cycles, each of length
- blocksize / N, and decoding will involve traversing one
- of these cycles N times. Which particular cycle doesn't
- matter -- they are all equivalent. The tricky part is to
- make sure that the pointer reversal creates a correct
- reversed cycle for us to traverse. So, the code below
- simply reverses whatever cycle origPtr happens to fall into,
- without regard to the cycle length. That gives one reversed
- cycle, which for normal blocks, is the entire block-size long.
- For repeated blocks, it will be interspersed with the other
- N-1 non-reversed cycles. Providing that the F-subscripting
- phase which follows starts at origPtr, all then works ok.
- --*/
- i = origPtr;
- j = GET_LL(i);
- do {
- tmp = GET_LL(j);
- SET_LL(j, i);
- i = j;
- j = tmp;
- }
- while (i != origPtr);
-
- /*--
- We recreate the original by subscripting F through T^(-1).
- The run-length-decoder below requires characters incrementally,
- so tPos is set to a starting value, and is updated by
- the GET_SMALL macro.
- --*/
- tPos = origPtr;
-
- /*-------------------------------------------------*/
- /*--
- This is pretty much a verbatim copy of the
- run-length decoder present in the distribution
- bzip-0.21; it has to be here to avoid creating
- block[] as an intermediary structure. As in 0.21,
- this code derives from some sent to me by
- Christian von Roques.
-
- It allows dst==NULL, so as to support the test (-t)
- option without slowing down the fast decompression
- code.
- --*/
- {
- IntNative retVal;
- Int32 i2, count, chPrev, ch2;
- UInt32 localCrc;
-
- count = 0;
- i2 = 0;
- ch2 = 256; /*-- not a char and not EOF --*/
- localCrc = getGlobalCRC();
-
- {
- RAND_DECLS;
- while ( i2 <= last ) {
- chPrev = ch2;
- GET_SMALL(ch2);
- if (blockRandomised) {
- RAND_UPD_MASK;
- ch2 ^= (UInt32)RAND_MASK;
- }
- i2++;
-
- if (dst)
- retVal = bz2_putc ( ch2, dst );
-
- UPDATE_CRC ( localCrc, (UChar)ch2 );
-
- if (ch2 != chPrev) {
- count = 1;
- } else {
- count++;
- if (count >= 4) {
- Int32 j2;
- UChar z;
- GET_SMALL(z);
- if (blockRandomised) {
- RAND_UPD_MASK;
- z ^= RAND_MASK;
- }
- for (j2 = 0; j2 < (Int32)z; j2++) {
- if (dst) retVal = bz2_putc (ch2, dst);
- UPDATE_CRC ( localCrc, (UChar)ch2 );
- }
- i2++;
- count = 0;
- }
- }
- }
- }
-
- setGlobalCRC ( localCrc );
- }
- /*-- end of the in-line run-length-decoder. --*/
-}
-#undef GET_SMALL
-
-
-/*---------------------------------------------*/
-
-#define GET_FAST(cccc) \
- \
- cccc = ll8[tPos]; \
- tPos = tt[tPos];
-
-
-
-static void undoReversibleTransformation_fast ( void* dst )
-{
- Int32 cftab[257];
- Int32 i, tPos;
- UChar ch;
-
- /*--
- We assume here that the global array unzftab will
- already be holding the frequency counts for
- ll8[0 .. last].
- --*/
-
- /*-- Set up cftab to facilitate generation of T^(-1) --*/
- cftab[0] = 0;
- for (i = 1; i <= 256; i++) cftab[i] = unzftab[i-1];
- for (i = 1; i <= 256; i++) cftab[i] += cftab[i-1];
-
- /*-- compute the T^(-1) vector --*/
- for (i = 0; i <= last; i++) {
- ch = (UChar)ll8[i];
- tt[cftab[ch]] = i;
- cftab[ch]++;
- }
-
- /*--
- We recreate the original by subscripting L through T^(-1).
- The run-length-decoder below requires characters incrementally,
- so tPos is set to a starting value, and is updated by
- the GET_FAST macro.
- --*/
- tPos = tt[origPtr];
-
- /*-------------------------------------------------*/
- /*--
- This is pretty much a verbatim copy of the
- run-length decoder present in the distribution
- bzip-0.21; it has to be here to avoid creating
- block[] as an intermediary structure. As in 0.21,
- this code derives from some sent to me by
- Christian von Roques.
- --*/
- {
- IntNative retVal;
- Int32 i2, count, chPrev, ch2;
- UInt32 localCrc;
-
- count = 0;
- i2 = 0;
- ch2 = 256; /*-- not a char and not EOF --*/
- localCrc = getGlobalCRC();
-
- if (blockRandomised) {
- RAND_DECLS;
- while ( i2 <= last ) {
- chPrev = ch2;
- GET_FAST(ch2);
- RAND_UPD_MASK;
- ch2 ^= (UInt32)RAND_MASK;
- i2++;
-
- retVal = bz2_putc ( ch2, dst );
- UPDATE_CRC ( localCrc, (UChar)ch2 );
-
- if (ch2 != chPrev) {
- count = 1;
- } else {
- count++;
- if (count >= 4) {
- Int32 j2;
- UChar z;
- GET_FAST(z);
- RAND_UPD_MASK;
- z ^= RAND_MASK;
- for (j2 = 0; j2 < (Int32)z; j2++) {
- retVal = bz2_putc (ch2, dst);
- UPDATE_CRC ( localCrc, (UChar)ch2 );
- }
- i2++;
- count = 0;
- }
- }
- }
-
- } else {
-
- while ( i2 <= last ) {
- chPrev = ch2;
- GET_FAST(ch2);
- i2++;
-
- retVal = bz2_putc ( ch2, dst );
- UPDATE_CRC ( localCrc, (UChar)ch2 );
-
- if (ch2 != chPrev) {
- count = 1;
- } else {
- count++;
- if (count >= 4) {
- Int32 j2;
- UChar z;
- GET_FAST(z);
- for (j2 = 0; j2 < (Int32)z; j2++) {
- retVal = bz2_putc (ch2, dst);
- UPDATE_CRC ( localCrc, (UChar)ch2 );
- }
- i2++;
- count = 0;
- }
- }
- }
-
- } /*-- if (blockRandomised) --*/
-
- setGlobalCRC ( localCrc );
- }
- /*-- end of the in-line run-length-decoder. --*/
-}
-#undef GET_FAST
-
-
-
-/*---------------------------------------------------*/
-/*--- Processing of complete files and streams ---*/
-/*---------------------------------------------------*/
-
-/*---------------------------------------------*/
-
-static Bool uncompressStream ( void *zStream, void *stream )
-{
- UChar magic1, magic2, magic3, magic4;
- UChar magic5, magic6;
- UInt32 storedBlockCRC, storedCombinedCRC;
- UInt32 computedBlockCRC, computedCombinedCRC;
- Int32 currBlockNo;
- IntNative retVal;
-
- SET_BINARY_MODE(stream);
- SET_BINARY_MODE(zStream);
-
- ERROR_IF_NOT_ZERO ( bz2_ferror(stream) );
- ERROR_IF_NOT_ZERO ( bz2_ferror(zStream) );
-
- bsSetStream ( zStream, False );
-
- /*--
- A bad magic number is `recoverable from';
- return with False so the caller skips the file.
- --*/
- magic1 = bsGetUChar ();
- magic2 = bsGetUChar ();
- magic3 = bsGetUChar ();
- magic4 = bsGetUChar ();
- if (magic1 != 'B' ||
- magic2 != 'Z' ||
- magic3 != 'h' ||
- magic4 < '1' ||
- magic4 > '9') {
- bsFinishedWithStream();
- retVal = bz2_fclose ( stream );
- ERROR_IF_EOF ( retVal );
- return False;
- }
-
- setDecompressStructureSizes ( magic4 - '0' );
- computedCombinedCRC = 0;
-
- if (verbosity >= 2) fprintf ( stderr, "\n " );
- currBlockNo = 0;
-
- while (True) {
- magic1 = bsGetUChar ();
- magic2 = bsGetUChar ();
- magic3 = bsGetUChar ();
- magic4 = bsGetUChar ();
- magic5 = bsGetUChar ();
- magic6 = bsGetUChar ();
- if (magic1 == 0x17 && magic2 == 0x72 &&
- magic3 == 0x45 && magic4 == 0x38 &&
- magic5 == 0x50 && magic6 == 0x90) break;
-
- if (magic1 != 0x31 || magic2 != 0x41 ||
- magic3 != 0x59 || magic4 != 0x26 ||
- magic5 != 0x53 || magic6 != 0x59) badBlockHeader();
-
- storedBlockCRC = bsGetUInt32 ();
-
- if (bsR(1) == 1)
- blockRandomised = True; else
- blockRandomised = False;
-
- currBlockNo++;
- if (verbosity >= 2)
- fprintf ( stderr, "[%d: huff+mtf ", currBlockNo );
- getAndMoveToFrontDecode ();
- ERROR_IF_NOT_ZERO ( bz2_ferror(zStream) );
-
- initialiseCRC();
- if (verbosity >= 2) fprintf ( stderr, "rt+rld" );
- if (smallMode)
- undoReversibleTransformation_small ( stream );
- else
- undoReversibleTransformation_fast ( stream );
-
- ERROR_IF_NOT_ZERO ( bz2_ferror(stream) );
-
- computedBlockCRC = getFinalCRC();
- if (verbosity >= 3)
- fprintf ( stderr, " {0x%x, 0x%x}", storedBlockCRC, computedBlockCRC );
- if (verbosity >= 2) fprintf ( stderr, "] " );
-
- /*-- A bad CRC is considered a fatal error. --*/
- if (storedBlockCRC != computedBlockCRC)
- crcError ( storedBlockCRC, computedBlockCRC );
-
- computedCombinedCRC = (computedCombinedCRC << 1) | (computedCombinedCRC
>> 31);
- computedCombinedCRC ^= computedBlockCRC;
- };
-
- if (verbosity >= 2) fprintf ( stderr, "\n " );
-
- storedCombinedCRC = bsGetUInt32 ();
- if (verbosity >= 2)
- fprintf ( stderr,
- "combined CRCs: stored = 0x%x, computed = 0x%x\n ",
- storedCombinedCRC, computedCombinedCRC );
- if (storedCombinedCRC != computedCombinedCRC)
- crcError ( storedCombinedCRC, computedCombinedCRC );
-
-
- bsFinishedWithStream ();
- ERROR_IF_NOT_ZERO ( bz2_ferror(zStream) );
- retVal = bz2_fclose ( zStream );
- ERROR_IF_EOF ( retVal );
-
- ERROR_IF_NOT_ZERO ( bz2_ferror(stream) );
- retVal = bz2_fflush ( stream );
- ERROR_IF_NOT_ZERO ( retVal );
- return True;
-}
-
-
-#if 0
+static char inbuf[INBUFSIZ];
+static char outbuf[OUTBUFSIZ];
+#ifdef SMALL_BZIP2
+#define SMALL_MODE 1
+#else
+#define SMALL_MODE 0
#endif
-/*---------------------------------------------------*/
-/*--- Error [non-] handling grunge ---*/
-/*---------------------------------------------------*/
-
-
-
-static void
-myFree (void **p)
-{
- free (*p);
- *p = NULL;
-}
-
-/*---------------------------------------------*/
-/* Ugg... Orignal code doesn't free dynamic allocated memories. */
-
-static void cleanUpAndFail ( Int32 ec )
-{
- myFree ((void **) &ll16);
- myFree ((void **) &ll4);
- myFree ((void **) &ll8);
- myFree ((void **) &tt);
-
- (*unzip_error) (NULL);
-}
-
-
-/*---------------------------------------------*/
-
-static void panic ( Char* s )
-{
- cleanUpAndFail( 3 );
-}
-
-
-
-/*---------------------------------------------*/
-
-static void crcError ( UInt32 crcStored, UInt32 crcComputed )
-{
- cleanUpAndFail( 2 );
-}
-
-
-/*---------------------------------------------*/
-
-static void compressedStreamEOF ( void )
-{
- cleanUpAndFail( 2 );
-}
-
-
-/*---------------------------------------------*/
-
-static void ioError ( )
-{
- cleanUpAndFail( 1 );
-}
-
-/*---------------------------------------------*/
-
-static void blockOverrun ()
+void
+do_bunzip2 (void)
{
- cleanUpAndFail( 2 );
-}
+ int result;
+ bz_stream strm;
+ strm.bzalloc = NULL;
+ strm.bzfree = NULL;
+ strm.opaque = NULL;
-/*---------------------------------------------*/
-
-static void badBlockHeader ()
-{
- cleanUpAndFail( 2 );
-}
+ strm.avail_in = 0;
+ strm.next_out = outbuf;
+ strm.avail_out = OUTBUFSIZ;
+ result = BZ2_bzDecompressInit (&strm, 0, SMALL_MODE);
+ while (result == BZ_OK)
+ {
+ if (strm.avail_in == 0)
+ {
+ strm.next_in = inbuf;
+ strm.avail_in = (*unzip_read)(strm.next_in, INBUFSIZ);
-/*---------------------------------------------*/
-static void uncompressOutOfMemory ( Int32 draw, Int32 blockSize )
-{
- cleanUpAndFail(1);
-}
+ if (strm.avail_in == 0)
+ break;
+ }
+ result = BZ2_bzDecompress (&strm);
+ if ((result != BZ_OK) && (result != BZ_STREAM_END))
+ break;
-/*-----------------------------------------------------------*/
-/*--- end bzip2.c ---*/
-/*-----------------------------------------------------------*/
+ if ((strm.avail_out == 0) || (result == BZ_STREAM_END))
+ {
+ (*unzip_write) (outbuf, OUTBUFSIZ - strm.avail_out);
+ strm.next_out = outbuf;
+ strm.avail_out = OUTBUFSIZ;
+ }
+ }
-void
-do_bunzip2 (void)
-{
- Bool ret;
-
- /*-- Initialise --*/
- ll4 = NULL;
- ll16 = NULL;
- ll8 = NULL;
- tt = NULL;
-#ifdef SMALL_BZIP2
- smallMode = True;
-#else
- smallMode = False;
-#endif
- verbosity = 0;
- blockSize100k = 0;
- bsStream = NULL;
+ BZ2_bzDecompressEnd (&strm);
- outcnt = 0;
- inptr = 0;
- insize = 0;
-
- ret = uncompressStream ((void *)1, (void *)2); /* Arguments ignored. */
- if (ret != True)
- cleanUpAndFail(1);
+ if (result != BZ_STREAM_END)
+ (*unzip_error) (NULL);
}
diff --git a/libstore/do-gunzip.c b/libstore/do-gunzip.c
new file mode 100644
index 0000000..a9d019e
--- /dev/null
+++ b/libstore/do-gunzip.c
@@ -0,0 +1,80 @@
+/* gzip decompression
+
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Written by Ignazio Sgalmuzzo <address@hidden>
+
+ 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <zlib.h>
+
+/* I/O interface */
+extern int (*unzip_read) (char *buf, size_t maxread);
+extern void (*unzip_write) (const char *buf, size_t nwrite);
+extern void (*unzip_read_error) (void);
+extern void (*unzip_error) (const char *msg);
+
+#define INBUFSIZ 0x1000
+#define OUTBUFSIZ 0x1000
+
+static unsigned char inbuf[INBUFSIZ];
+static unsigned char outbuf[OUTBUFSIZ];
+
+void
+do_gunzip (void)
+{
+ int result;
+ z_stream strm;
+
+ strm.zalloc = NULL;
+ strm.zfree = NULL;
+ strm.opaque = NULL;
+
+ strm.avail_in = 0;
+ strm.next_out = outbuf;
+ strm.avail_out = OUTBUFSIZ;
+
+ result = inflateInit2 (&strm, 32 + MAX_WBITS);
+
+ while (result == Z_OK)
+ {
+ if (strm.avail_in == 0)
+ {
+ strm.next_in = inbuf;
+ strm.avail_in = (*unzip_read)((char*) strm.next_in, INBUFSIZ);
+
+ if (strm.avail_in == 0)
+ break;
+ }
+
+ result = inflate (&strm, Z_NO_FLUSH);
+
+ if ((result != Z_OK) && (result != Z_STREAM_END))
+ break;
+
+ if ((strm.avail_out == 0) || (result == Z_STREAM_END))
+ {
+ (*unzip_write) ((char*) outbuf, OUTBUFSIZ - strm.avail_out);
+ strm.next_out = outbuf;
+ strm.avail_out = OUTBUFSIZ;
+ }
+ }
+
+ inflateEnd (&strm);
+
+ if (result != Z_STREAM_END)
+ (*unzip_error) (NULL);
+}
diff --git a/libstore/gunzip.c b/libstore/gunzip.c
index 7c44940..f47c0b2 100644
--- a/libstore/gunzip.c
+++ b/libstore/gunzip.c
@@ -18,35 +18,14 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
-#include <stdio.h>
-#include <string.h>
-#include <setjmp.h>
-#include <sys/mman.h>
+#include <errno.h>
-#include "store.h"
-
-/* gzip.h makes several annoying defines & decls, which we have to work
- around. */
-#define file_t gzip_file_t
-#include "gzip.h"
-#undef file_t
-#undef head
+extern void do_gunzip (void); /* Entry point to gunzip engine. */
static error_t
DO_UNZIP (void)
{
- /* Entry points to unzip engine. */
- int get_method (int);
- extern long int bytes_out;
-
- if (get_method (0) != 0)
- /* Not a happy gzip file. */
- return EINVAL;
-
- /* Matched gzip magic number. Ready to unzip.
- Set up the output stream and let 'er rip. */
- bytes_out = 0;
- unzip (17, 23); /* Arguments ignored. */
+ do_gunzip ();
return 0;
}
diff --git a/libstore/gzip.h b/libstore/gzip.h
deleted file mode 100644
index aedc257..0000000
--- a/libstore/gzip.h
+++ /dev/null
@@ -1,315 +0,0 @@
-/* gzip.h -- common declarations for all gzip modules
- * Copyright (C) 1992-1993, 1996 Jean-loup Gailly.
- * This is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License, see the file COPYING.
- */
-
-#if defined(__STDC__) || defined(PROTO)
-# define OF(args) args
-#else
-# define OF(args) ()
-#endif
-
-#ifdef __STDC__
- typedef void *voidp;
-#else
- typedef char *voidp;
-#endif
-
-/* I don't like nested includes, but the string and io functions are used
- * too often
- */
-#include <stdio.h>
-#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
-# include <string.h>
-# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
-# include <memory.h>
-# endif
-# define memzero(s, n) memset ((voidp)(s), 0, (n))
-#else
-# include <strings.h>
-# define strchr index
-# define strrchr rindex
-# define memcpy(d, s, n) bcopy((s), (d), (n))
-# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
-# define memzero(s, n) bzero((s), (n))
-#endif
-
-#ifndef RETSIGTYPE
-# define RETSIGTYPE void
-#endif
-
-#define local static
-
-typedef unsigned char uch;
-typedef unsigned short ush;
-typedef unsigned long ulg;
-
-/* Return codes from gzip */
-#define OK 0
-#define ERROR 1
-#define WARNING 2
-
-/* Compression methods (see algorithm.doc) */
-#define STORED 0
-#define COMPRESSED 1
-#define PACKED 2
-#define LZHED 3
-/* methods 4 to 7 reserved */
-#define DEFLATED 8
-#define MAX_METHODS 9
-extern int method; /* compression method */
-
-/* To save memory for 16 bit systems, some arrays are overlaid between
- * the various modules:
- * deflate: prev+head window d_buf l_buf outbuf
- * unlzw: tab_prefix tab_suffix stack inbuf outbuf
- * inflate: window inbuf
- * unpack: window inbuf prefix_len
- * unlzh: left+right window c_table inbuf c_len
- * For compression, input is done in window[]. For decompression, output
- * is done in window except for unlzw.
- */
-
-#ifndef INBUFSIZ
-# ifdef SMALL_MEM
-# define INBUFSIZ 0x2000 /* input buffer size */
-# else
-# define INBUFSIZ 0x8000 /* input buffer size */
-# endif
-#endif
-#define INBUF_EXTRA 64 /* required by unlzw() */
-
-#ifndef OUTBUFSIZ
-# ifdef SMALL_MEM
-# define OUTBUFSIZ 8192 /* output buffer size */
-# else
-# define OUTBUFSIZ 16384 /* output buffer size */
-# endif
-#endif
-#define OUTBUF_EXTRA 2048 /* required by unlzw() */
-
-#ifndef DIST_BUFSIZE
-# ifdef SMALL_MEM
-# define DIST_BUFSIZE 0x2000 /* buffer for distances, see trees.c */
-# else
-# define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */
-# endif
-#endif
-
-#ifdef DYN_ALLOC
-# define EXTERN(type, array) extern type * near array
-# define DECLARE(type, array, size) type * near array
-# define ALLOC(type, array, size) { \
- array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
- if (array == NULL) error("insufficient memory"); \
- }
-# define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
-#else
-# define EXTERN(type, array) extern type array[]
-# define DECLARE(type, array, size) type array[size]
-# define ALLOC(type, array, size)
-# define FREE(array)
-#endif
-
-EXTERN(uch, inbuf); /* input buffer */
-EXTERN(uch, outbuf); /* output buffer */
-EXTERN(ush, d_buf); /* buffer for distances, see trees.c */
-EXTERN(uch, window); /* Sliding window and suffix table (unlzw) */
-#define tab_suffix window
-#ifndef MAXSEG_64K
-# define tab_prefix prev /* hash link (see deflate.c) */
-# define head (prev+WSIZE) /* hash head (see deflate.c) */
- EXTERN(ush, tab_prefix); /* prefix code (see unlzw.c) */
-#else
-# define tab_prefix0 prev
-# define head tab_prefix1
- EXTERN(ush, tab_prefix0); /* prefix for even codes */
- EXTERN(ush, tab_prefix1); /* prefix for odd codes */
-#endif
-
-extern unsigned insize; /* valid bytes in inbuf */
-extern unsigned inptr; /* index of next byte to be processed in inbuf */
-extern unsigned outcnt; /* bytes in output buffer */
-
-extern long bytes_in; /* number of input bytes */
-extern long bytes_out; /* number of output bytes */
-extern long header_bytes;/* number of bytes in gzip header */
-
-#define isize bytes_in
-/* for compatibility with old zip sources (to be cleaned) */
-
-extern int ifd; /* input file descriptor */
-extern int ofd; /* output file descriptor */
-extern char ifname[]; /* input file name or "stdin" */
-extern char ofname[]; /* output file name or "stdout" */
-extern char *progname; /* program name */
-
-extern long time_stamp; /* original time stamp (modification time) */
-extern long ifile_size; /* input file size, -1 for devices (debug only) */
-
-typedef int file_t; /* Do not use stdio */
-#define NO_FILE (-1) /* in memory compression */
-
-
-#define PACK_MAGIC "\037\036" /* Magic header for packed files */
-#define GZIP_MAGIC "\037\213" /* Magic header for gzip files, 1F 8B
*/
-#define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze
1.x */
-#define LZH_MAGIC "\037\240" /* Magic header for SCO LZH Compress
files*/
-#define PKZIP_MAGIC "\120\113\003\004" /* Magic header for pkzip files */
-
-/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
-
-/* internal file attribute */
-#define UNKNOWN 0xffff
-#define BINARY 0
-#define ASCII 1
-
-#ifndef WSIZE
-# define WSIZE 0x8000 /* window size--must be a power of two, and */
-#endif /* at least 32K for zip's deflate method */
-
-#define MIN_MATCH 3
-#define MAX_MATCH 258
-/* The minimum and maximum match lengths */
-
-#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
-/* Minimum amount of lookahead, except at the end of the input file.
- * See deflate.c for comments about the MIN_MATCH+1.
- */
-
-#define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
-/* In order to simplify the code, particularly on 16 bit machines, match
- * distances are limited to MAX_DIST instead of WSIZE.
- */
-
-extern int decrypt; /* flag to turn on decryption */
-extern int exit_code; /* program exit code */
-extern int verbose; /* be verbose (-v) */
-extern int quiet; /* be quiet (-q) */
-extern int level; /* compression level */
-extern int test; /* check .z file integrity */
-extern int to_stdout; /* output to stdout (-c) */
-extern int save_orig_name; /* set if original name must be saved */
-
-#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
-#define try_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
-
-/* put_byte is used for the compressed output, put_ubyte for the
- * uncompressed output. However unlzw() uses window for its
- * suffix table instead of its output buffer, so it does not use put_ubyte
- * (to be cleaned up).
- */
-#define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
- flush_outbuf();}
-#define put_ubyte(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
- flush_window();}
-
-/* Output a 16 bit value, lsb first */
-#define put_short(w) \
-{ if (outcnt < OUTBUFSIZ-2) { \
- outbuf[outcnt++] = (uch) ((w) & 0xff); \
- outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
- } else { \
- put_byte((uch)((w) & 0xff)); \
- put_byte((uch)((ush)(w) >> 8)); \
- } \
-}
-
-/* Output a 32 bit value to the bit stream, lsb first */
-#define put_long(n) { \
- put_short((n) & 0xffff); \
- put_short(((ulg)(n)) >> 16); \
-}
-
-#define seekable() 0 /* force sequential output */
-#define translate_eol 0 /* no option -a yet */
-
-#define tolow(c) (isupper(c) ? (c)-'A'+'a' : (c)) /* force to lower case */
-
-/* Macros for getting two-byte and four-byte header values */
-#define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
-#define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
-
-/* Diagnostic functions */
-#ifdef DEBUG
-# define Assert(cond,msg) {if(!(cond)) error(msg);}
-# define Trace(x) fprintf x
-# define Tracev(x) {if (verbose) fprintf x ;}
-# define Tracevv(x) {if (verbose>1) fprintf x ;}
-# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-# define Assert(cond,msg)
-# define Trace(x)
-# define Tracev(x)
-# define Tracevv(x)
-# define Tracec(c,x)
-# define Tracecv(c,x)
-#endif
-
-#define WARN(msg) {if (!quiet) fprintf msg ; \
- if (exit_code == OK) exit_code = WARNING;}
-
- /* in zip.c: */
-extern int zip OF((int in, int out));
-extern int file_read OF((char *buf, unsigned size));
-
- /* in unzip.c */
-extern int unzip OF((int in, int out));
-extern int check_zipfile OF((int in));
-
- /* in unpack.c */
-extern int unpack OF((int in, int out));
-
- /* in unlzh.c */
-extern int unlzh OF((int in, int out));
-
- /* in gzip.c */
-RETSIGTYPE abort_gzip OF((void));
-
- /* in deflate.c */
-void lm_init OF((int pack_level, ush *flags));
-ulg deflate OF((void));
-
- /* in trees.c */
-void ct_init OF((ush *attr, int *method));
-int ct_tally OF((int dist, int lc));
-ulg flush_block OF((char *buf, ulg stored_len, int eof));
-
- /* in bits.c */
-void bi_init OF((file_t zipfile));
-void send_bits OF((int value, int length));
-unsigned bi_reverse OF((unsigned value, int length));
-void bi_windup OF((void));
-void copy_block OF((char *buf, unsigned len, int header));
-extern int (*read_buf) OF((char *buf, unsigned size));
-
- /* in util.c: */
-extern int copy OF((int in, int out));
-extern ulg updcrc OF((uch *s, unsigned n));
-extern void clear_bufs OF((void));
-extern int fill_inbuf OF((int eof_ok));
-extern void flush_outbuf OF((void));
-extern void flush_window OF((void));
-extern void write_buf OF((int fd, voidp buf, unsigned cnt));
-extern char *strlwr OF((char *s));
-/* extern char *basename OF((char *fname));*/
-extern void make_simple_name OF((char *name));
-extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
-extern void error OF((char *m));
-extern void warn OF((char *a, char *b));
-extern void read_error OF((void));
-extern void write_error OF((void));
-extern void display_ratio OF((long num, long den, FILE *file));
-extern voidp xmalloc OF((unsigned int size));
-
- /* in inflate.c */
-extern int inflate OF((void));
diff --git a/libstore/inflate.c b/libstore/inflate.c
deleted file mode 100644
index c3be438..0000000
--- a/libstore/inflate.c
+++ /dev/null
@@ -1,954 +0,0 @@
-/* inflate.c -- Not copyrighted 1992 by Mark Adler
- version c10p1, 10 January 1993 */
-
-/* You can do whatever you like with this source file, though I would
- prefer that if you modify it and redistribute it that you include
- comments to that effect with your name and the date. Thank you.
- [The history has been moved to the file ChangeLog.]
- */
-
-/*
- Inflate deflated (PKZIP's method 8 compressed) data. The compression
- method searches for as much of the current string of bytes (up to a
- length of 258) in the previous 32K bytes. If it doesn't find any
- matches (of at least length 3), it codes the next byte. Otherwise, it
- codes the length of the matched string and its distance backwards from
- the current position. There is a single Huffman code that codes both
- single bytes (called "literals") and match lengths. A second Huffman
- code codes the distance information, which follows a length code. Each
- length or distance code actually represents a base value and a number
- of "extra" (sometimes zero) bits to get to add to the base value. At
- the end of each deflated block is a special end-of-block (EOB) literal/
- length code. The decoding process is basically: get a literal/length
- code; if EOB then done; if a literal, emit the decoded byte; if a
- length then get the distance and emit the referred-to bytes from the
- sliding window of previously emitted data.
-
- There are (currently) three kinds of inflate blocks: stored, fixed, and
- dynamic. The compressor deals with some chunk of data at a time, and
- decides which method to use on a chunk-by-chunk basis. A chunk might
- typically be 32K or 64K. If the chunk is uncompressible, then the
- "stored" method is used. In this case, the bytes are simply stored as
- is, eight bits per byte, with none of the above coding. The bytes are
- preceded by a count, since there is no longer an EOB code.
-
- If the data is compressible, then either the fixed or dynamic methods
- are used. In the dynamic method, the compressed data is preceded by
- an encoding of the literal/length and distance Huffman codes that are
- to be used to decode this block. The representation is itself Huffman
- coded, and so is preceded by a description of that code. These code
- descriptions take up a little space, and so for small blocks, there is
- a predefined set of codes, called the fixed codes. The fixed method is
- used if the block codes up smaller that way (usually for quite small
- chunks), otherwise the dynamic method is used. In the latter case, the
- codes are customized to the probabilities in the current block, and so
- can code it much better than the pre-determined fixed codes.
-
- The Huffman codes themselves are decoded using a mutli-level table
- lookup, in order to maximize the speed of decoding plus the speed of
- building the decoding tables. See the comments below that precede the
- lbits and dbits tuning parameters.
- */
-
-
-/*
- Notes beyond the 1.93a appnote.txt:
-
- 1. Distance pointers never point before the beginning of the output
- stream.
- 2. Distance pointers can point back across blocks, up to 32k away.
- 3. There is an implied maximum of 7 bits for the bit length table and
- 15 bits for the actual data.
- 4. If only one code exists, then it is encoded using one bit. (Zero
- would be more efficient, but perhaps a little confusing.) If two
- codes exist, they are coded using one bit each (0 and 1).
- 5. There is no way of sending zero distance codes--a dummy must be
- sent if there are none. (History: a pre 2.0 version of PKZIP would
- store blocks with no distance codes, but this was discovered to be
- too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
- zero distance codes, which is sent as one code of zero bits in
- length.
- 6. There are up to 286 literal/length codes. Code 256 represents the
- end-of-block. Note however that the static length tree defines
- 288 codes just to fill out the Huffman codes. Codes 286 and 287
- cannot be used though, since there is no length base or extra bits
- defined for them. Similarly, there are up to 30 distance codes.
- However, static trees define 32 codes (all 5 bits) to fill out the
- Huffman codes, but the last two had better not show up in the data.
- 7. Unzip can check dynamic Huffman blocks for complete code sets.
- The exception is that a single code would not be complete (see #4).
- 8. The five bits following the block type is really the number of
- literal codes sent minus 257.
- 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
- (1+6+6). Therefore, to output three times the length, you output
- three codes (1+1+1), whereas to output four times the same length,
- you only need two codes (1+3). Hmm.
- 10. In the tree reconstruction algorithm, Code = Code + Increment
- only if BitLength(i) is not zero. (Pretty obvious.)
- 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
- 12. Note: length code 284 can represent 227-258, but length code 285
- really is 258. The last length deserves its own, short code
- since it gets used a lot in very redundant files. The length
- 258 is special since 258 - 3 (the min match length) is 255.
- 13. The literal/length and distance code bit lengths are read as a
- single stream of lengths. It is possible (and advantageous) for
- a repeat code (16, 17, or 18) to go across the boundary between
- the two sets of lengths.
- */
-
-#ifdef RCSID
-static char rcsid[] = "$Id: inflate.c,v 1.1 1994/12/14 04:31:21 roland Exp $";
-#endif
-
-#include <sys/types.h>
-
-#include "tailor.h"
-
-#if defined(STDC_HEADERS) || !defined(NO_STDLIB_H)
-# include <stdlib.h>
-#endif
-
-#include "gzip.h"
-#define slide window
-
-/* Huffman code lookup table entry--this entry is four bytes for machines
- that have 16-bit pointers (e.g. PC's in the small or medium model).
- Valid extra bits are 0..13. e == 15 is EOB (end of block), e == 16
- means that v is a literal, 16 < e < 32 means that v is a pointer to
- the next table, which codes e - 16 bits, and lastly e == 99 indicates
- an unused code. If a code with e == 99 is looked up, this implies an
- error in the data. */
-struct huft {
- uch e; /* number of extra bits or operation */
- uch b; /* number of bits in this code or subcode */
- union {
- ush n; /* literal, length base, or distance base */
- struct huft *t; /* pointer to next level of table */
- } v;
-};
-
-
-/* Function prototypes */
-int huft_build OF((unsigned *, unsigned, unsigned, ush *, ush *,
- struct huft **, int *));
-int huft_free OF((struct huft *));
-int inflate_codes OF((struct huft *, struct huft *, int, int));
-int inflate_stored OF((void));
-int inflate_fixed OF((void));
-int inflate_dynamic OF((void));
-int inflate_block OF((int *));
-int inflate OF((void));
-
-
-/* The inflate algorithm uses a sliding 32K byte window on the uncompressed
- stream to find repeated byte strings. This is implemented here as a
- circular buffer. The index is updated simply by incrementing and then
- and'ing with 0x7fff (32K-1). */
-/* It is left to other modules to supply the 32K area. It is assumed
- to be usable as if it were declared "uch slide[32768];" or as just
- "uch *slide;" and then malloc'ed in the latter case. The definition
- must be in unzip.h, included above. */
-/* unsigned wp; current position in slide */
-#define wp outcnt
-#define flush_output(w) (wp=(w),flush_window())
-
-/* Tables for deflate from PKZIP's appnote.txt. */
-static unsigned border[] = { /* Order of the bit length code lengths */
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-static ush cplens[] = { /* Copy lengths for literal codes 257..285 */
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
- 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
- /* note: see note #13 above about the 258 in this list. */
-static ush cplext[] = { /* Extra bits for literal codes 257..285 */
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */
-static ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
- 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
- 8193, 12289, 16385, 24577};
-static ush cpdext[] = { /* Extra bits for distance codes */
- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
- 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
- 12, 12, 13, 13};
-
-
-
-/* Macros for inflate() bit peeking and grabbing.
- The usage is:
-
- NEEDBITS(j)
- x = b & mask_bits[j];
- DUMPBITS(j)
-
- where NEEDBITS makes sure that b has at least j bits in it, and
- DUMPBITS removes the bits from b. The macros use the variable k
- for the number of bits in b. Normally, b and k are register
- variables for speed, and are initialized at the beginning of a
- routine that uses these macros from a global bit buffer and count.
-
- If we assume that EOB will be the longest code, then we will never
- ask for bits with NEEDBITS that are beyond the end of the stream.
- So, NEEDBITS should not read any more bytes than are needed to
- meet the request. Then no bytes need to be "returned" to the buffer
- at the end of the last block.
-
- However, this assumption is not true for fixed blocks--the EOB code
- is 7 bits, but the other literal/length codes can be 8 or 9 bits.
- (The EOB code is shorter than other codes because fixed blocks are
- generally short. So, while a block always has an EOB, many other
- literal/length codes have a significantly lower probability of
- showing up at all.) However, by making the first table have a
- lookup of seven bits, the EOB code will be found in that first
- lookup, and so will not require that too many bits be pulled from
- the stream.
- */
-
-ulg bb; /* bit buffer */
-unsigned bk; /* bits in bit buffer */
-
-ush mask_bits[] = {
- 0x0000,
- 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
- 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
-};
-
-#ifdef CRYPT
- uch cc;
-# define NEXTBYTE() \
- (decrypt ? (cc = get_byte(), zdecode(cc), cc) : get_byte())
-#else
-# define NEXTBYTE() (uch)get_byte()
-#endif
-#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
-#define DUMPBITS(n) {b>>=(n);k-=(n);}
-
-
-/*
- Huffman code decoding is performed using a multi-level table lookup.
- The fastest way to decode is to simply build a lookup table whose
- size is determined by the longest code. However, the time it takes
- to build this table can also be a factor if the data being decoded
- is not very long. The most common codes are necessarily the
- shortest codes, so those codes dominate the decoding time, and hence
- the speed. The idea is you can have a shorter table that decodes the
- shorter, more probable codes, and then point to subsidiary tables for
- the longer codes. The time it costs to decode the longer codes is
- then traded against the time it takes to make longer tables.
-
- This results of this trade are in the variables lbits and dbits
- below. lbits is the number of bits the first level table for literal/
- length codes can decode in one step, and dbits is the same thing for
- the distance codes. Subsequent tables are also less than or equal to
- those sizes. These values may be adjusted either when all of the
- codes are shorter than that, in which case the longest code length in
- bits is used, or when the shortest code is *longer* than the requested
- table size, in which case the length of the shortest code in bits is
- used.
-
- There are two different values for the two tables, since they code a
- different number of possibilities each. The literal/length table
- codes 286 possible values, or in a flat code, a little over eight
- bits. The distance table codes 30 possible values, or a little less
- than five bits, flat. The optimum values for speed end up being
- about one bit more than those, so lbits is 8+1 and dbits is 5+1.
- The optimum values may differ though from machine to machine, and
- possibly even between compilers. Your mileage may vary.
- */
-
-
-int lbits = 9; /* bits in base literal/length lookup table */
-int dbits = 6; /* bits in base distance lookup table */
-
-
-/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
-#define BMAX 16 /* maximum bit length of any code (16 for explode) */
-#define N_MAX 288 /* maximum number of codes in any set */
-
-
-unsigned hufts; /* track memory usage */
-
-
-int huft_build(b, n, s, d, e, t, m)
-unsigned *b; /* code lengths in bits (all assumed <= BMAX) */
-unsigned n; /* number of codes (assumed <= N_MAX) */
-unsigned s; /* number of simple-valued codes (0..s-1) */
-ush *d; /* list of base values for non-simple codes */
-ush *e; /* list of extra bits for non-simple codes */
-struct huft **t; /* result: starting table */
-int *m; /* maximum lookup bits, returns actual */
-/* Given a list of code lengths and a maximum table size, make a set of
- tables to decode that set of codes. Return zero on success, one if
- the given code set is incomplete (the tables are still built in this
- case), two if the input is invalid (all zero length codes or an
- oversubscribed set of lengths), and three if not enough memory. */
-{
- unsigned a; /* counter for codes of length k */
- unsigned c[BMAX+1]; /* bit length count table */
- unsigned f; /* i repeats in table every f entries */
- int g; /* maximum code length */
- int h; /* table level */
- register unsigned i; /* counter, current code */
- register unsigned j; /* counter */
- register int k; /* number of bits in current code */
- int l; /* bits per table (returned in m) */
- register unsigned *p; /* pointer into c[], b[], or v[] */
- register struct huft *q; /* points to current table */
- struct huft r; /* table entry for structure assignment */
- struct huft *u[BMAX]; /* table stack */
- unsigned v[N_MAX]; /* values in order of bit length */
- register int w; /* bits before this table == (l * h) */
- unsigned x[BMAX+1]; /* bit offsets, then code stack */
- unsigned *xp; /* pointer into x */
- int y; /* number of dummy codes added */
- unsigned z; /* number of entries in current table */
-
-
- /* Generate counts for each bit length */
- memzero(c, sizeof(c));
- p = b; i = n;
- do {
- Tracecv(*p, (stderr, (n-i >= ' ' && n-i <= '~' ? "%c %d\n" : "0x%x %d\n"),
- n-i, *p));
- c[*p]++; /* assume all entries <= BMAX */
- p++; /* Can't combine with above line (Solaris bug) */
- } while (--i);
- if (c[0] == n) /* null input--all zero length codes */
- {
- *t = (struct huft *)NULL;
- *m = 0;
- return 0;
- }
-
-
- /* Find minimum and maximum length, bound *m by those */
- l = *m;
- for (j = 1; j <= BMAX; j++)
- if (c[j])
- break;
- k = j; /* minimum code length */
- if ((unsigned)l < j)
- l = j;
- for (i = BMAX; i; i--)
- if (c[i])
- break;
- g = i; /* maximum code length */
- if ((unsigned)l > i)
- l = i;
- *m = l;
-
-
- /* Adjust last length count to fill out codes, if needed */
- for (y = 1 << j; j < i; j++, y <<= 1)
- if ((y -= c[j]) < 0)
- return 2; /* bad input: more codes than bits */
- if ((y -= c[i]) < 0)
- return 2;
- c[i] += y;
-
-
- /* Generate starting offsets into the value table for each length */
- x[1] = j = 0;
- p = c + 1; xp = x + 2;
- while (--i) { /* note that i == g from above */
- *xp++ = (j += *p++);
- }
-
-
- /* Make a table of values in order of bit lengths */
- p = b; i = 0;
- do {
- if ((j = *p++) != 0)
- v[x[j]++] = i;
- } while (++i < n);
-
-
- /* Generate the Huffman codes and for each, make the table entries */
- x[0] = i = 0; /* first Huffman code is zero */
- p = v; /* grab values in bit order */
- h = -1; /* no tables yet--level -1 */
- w = -l; /* bits decoded == (l * h) */
- u[0] = (struct huft *)NULL; /* just to keep compilers happy */
- q = (struct huft *)NULL; /* ditto */
- z = 0; /* ditto */
-
- /* go through the bit lengths (k already is bits in shortest code) */
- for (; k <= g; k++)
- {
- a = c[k];
- while (a--)
- {
- /* here i is the Huffman code of length k bits for value *p */
- /* make tables up to required level */
- while (k > w + l)
- {
- h++;
- w += l; /* previous table always l bits */
-
- /* compute minimum size table less than or equal to l bits */
- z = (z = g - w) > (unsigned)l ? l : z; /* upper limit on table size */
- if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
- { /* too few codes for k-w bit table */
- f -= a + 1; /* deduct codes from patterns left */
- xp = c + k;
- while (++j < z) /* try smaller tables up to z bits */
- {
- if ((f <<= 1) <= *++xp)
- break; /* enough codes to use up j bits */
- f -= *xp; /* else deduct codes from patterns */
- }
- }
- z = 1 << j; /* table entries for j-bit table */
-
- /* allocate and link in new table */
- if ((q = (struct huft *)malloc((z + 1)*sizeof(struct huft))) ==
- (struct huft *)NULL)
- {
- if (h)
- huft_free(u[0]);
- return 3; /* not enough memory */
- }
- hufts += z + 1; /* track memory usage */
- *t = q + 1; /* link to list for huft_free() */
- *(t = &(q->v.t)) = (struct huft *)NULL;
- u[h] = ++q; /* table starts after link */
-
- /* connect to last table, if there is one */
- if (h)
- {
- x[h] = i; /* save pattern for backing up */
- r.b = (uch)l; /* bits to dump before this table */
- r.e = (uch)(16 + j); /* bits in this table */
- r.v.t = q; /* pointer to this table */
- j = i >> (w - l); /* (get around Turbo C bug) */
- u[h-1][j] = r; /* connect to last table */
- }
- }
-
- /* set up table entry in r */
- r.b = (uch)(k - w);
- if (p >= v + n)
- r.e = 99; /* out of values--invalid code */
- else if (*p < s)
- {
- r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
- r.v.n = (ush)(*p); /* simple code is just the value */
- p++; /* one compiler does not like *p++ */
- }
- else
- {
- r.e = (uch)e[*p - s]; /* non-simple--look up in lists */
- r.v.n = d[*p++ - s];
- }
-
- /* fill code-like entries with r */
- f = 1 << (k - w);
- for (j = i >> w; j < z; j += f)
- q[j] = r;
-
- /* backwards increment the k-bit code i */
- for (j = 1 << (k - 1); i & j; j >>= 1)
- i ^= j;
- i ^= j;
-
- /* backup over finished tables */
- while ((i & ((1 << w) - 1)) != x[h])
- {
- h--; /* don't need to update q */
- w -= l;
- }
- }
- }
-
-
- /* Return true (1) if we were given an incomplete table */
- return y != 0 && g != 1;
-}
-
-
-
-int huft_free(t)
-struct huft *t; /* table to free */
-/* Free the malloc'ed tables built by huft_build(), which makes a linked
- list of the tables it made, with the links in a dummy first entry of
- each table. */
-{
- register struct huft *p, *q;
-
-
- /* Go through linked list, freeing from the malloced (t[-1]) address. */
- p = t;
- while (p != (struct huft *)NULL)
- {
- q = (--p)->v.t;
- free((char*)p);
- p = q;
- }
- return 0;
-}
-
-
-int inflate_codes(tl, td, bl, bd)
-struct huft *tl, *td; /* literal/length and distance decoder tables */
-int bl, bd; /* number of bits decoded by tl[] and td[] */
-/* inflate (decompress) the codes in a deflated (compressed) block.
- Return an error code or zero if it all goes ok. */
-{
- register unsigned e; /* table entry flag/number of extra bits */
- unsigned n, d; /* length and index for copy */
- unsigned w; /* current window position */
- struct huft *t; /* pointer to table entry */
- unsigned ml, md; /* masks for bl and bd bits */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-
- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = wp; /* initialize window position */
-
- /* inflate the coded data */
- ml = mask_bits[bl]; /* precompute masks for speed */
- md = mask_bits[bd];
- for (;;) /* do until end of block */
- {
- NEEDBITS((unsigned)bl)
- if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b)
- e -= 16;
- NEEDBITS(e)
- } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
- DUMPBITS(t->b)
- if (e == 16) /* then it's a literal */
- {
- slide[w++] = (uch)t->v.n;
- Tracevv((stderr, "%c", slide[w-1]));
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- }
- else /* it's an EOB or a length */
- {
- /* exit if end of block */
- if (e == 15)
- break;
-
- /* get length of block to copy */
- NEEDBITS(e)
- n = t->v.n + ((unsigned)b & mask_bits[e]);
- DUMPBITS(e);
-
- /* decode distance of block to copy */
- NEEDBITS((unsigned)bd)
- if ((e = (t = td + ((unsigned)b & md))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b)
- e -= 16;
- NEEDBITS(e)
- } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
- DUMPBITS(t->b)
- NEEDBITS(e)
- d = w - t->v.n - ((unsigned)b & mask_bits[e]);
- DUMPBITS(e)
- Tracevv((stderr,"\\[%d,%d]", w-d, n));
-
- /* do the copy */
- do {
- n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
-#if !defined(NOMEMCPY) && !defined(DEBUG)
- if (w - d >= e) /* (this test assumes unsigned comparison) */
- {
- memcpy(slide + w, slide + d, e);
- w += e;
- d += e;
- }
- else /* do it slow to avoid memcpy() overlap */
-#endif /* !NOMEMCPY */
- do {
- slide[w++] = slide[d++];
- Tracevv((stderr, "%c", slide[w-1]));
- } while (--e);
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- } while (n);
- }
- }
-
-
- /* restore the globals from the locals */
- wp = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
-
- /* done */
- return 0;
-}
-
-
-
-int inflate_stored()
-/* "decompress" an inflated type 0 (stored) block. */
-{
- unsigned n; /* number of bytes in block */
- unsigned w; /* current window position */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-
- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = wp; /* initialize window position */
-
-
- /* go to byte boundary */
- n = k & 7;
- DUMPBITS(n);
-
-
- /* get the length and its complement */
- NEEDBITS(16)
- n = ((unsigned)b & 0xffff);
- DUMPBITS(16)
- NEEDBITS(16)
- if (n != (unsigned)((~b) & 0xffff))
- return 1; /* error in compressed data */
- DUMPBITS(16)
-
-
- /* read and output the compressed data */
- while (n--)
- {
- NEEDBITS(8)
- slide[w++] = (uch)b;
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- DUMPBITS(8)
- }
-
-
- /* restore the globals from the locals */
- wp = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
- return 0;
-}
-
-
-
-int inflate_fixed()
-/* decompress an inflated type 1 (fixed Huffman codes) block. We should
- either replace this with a custom decoder, or at least precompute the
- Huffman tables. */
-{
- int i; /* temporary variable */
- struct huft *tl; /* literal/length code table */
- struct huft *td; /* distance code table */
- int bl; /* lookup bits for tl */
- int bd; /* lookup bits for td */
- unsigned l[288]; /* length list for huft_build */
-
-
- /* set up literal table */
- for (i = 0; i < 144; i++)
- l[i] = 8;
- for (; i < 256; i++)
- l[i] = 9;
- for (; i < 280; i++)
- l[i] = 7;
- for (; i < 288; i++) /* make a complete, but wrong code set */
- l[i] = 8;
- bl = 7;
- if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
- return i;
-
-
- /* set up distance table */
- for (i = 0; i < 30; i++) /* make an incomplete code set */
- l[i] = 5;
- bd = 5;
- if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
- {
- huft_free(tl);
- return i;
- }
-
-
- /* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
- return 1;
-
-
- /* free the decoding tables, return */
- huft_free(tl);
- huft_free(td);
- return 0;
-}
-
-
-
-int inflate_dynamic()
-/* decompress an inflated type 2 (dynamic Huffman codes) block. */
-{
- int i; /* temporary variables */
- unsigned j;
- unsigned l; /* last length */
- unsigned m; /* mask for bit lengths table */
- unsigned n; /* number of lengths to get */
- struct huft *tl; /* literal/length code table */
- struct huft *td; /* distance code table */
- int bl; /* lookup bits for tl */
- int bd; /* lookup bits for td */
- unsigned nb; /* number of bit length codes */
- unsigned nl; /* number of literal/length codes */
- unsigned nd; /* number of distance codes */
-#ifdef PKZIP_BUG_WORKAROUND
- unsigned ll[288+32]; /* literal/length and distance code lengths */
-#else
- unsigned ll[286+30]; /* literal/length and distance code lengths */
-#endif
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-
- /* make local bit buffer */
- b = bb;
- k = bk;
-
-
- /* read in table lengths */
- NEEDBITS(5)
- nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */
- DUMPBITS(5)
- NEEDBITS(5)
- nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */
- DUMPBITS(5)
- NEEDBITS(4)
- nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
- DUMPBITS(4)
-#ifdef PKZIP_BUG_WORKAROUND
- if (nl > 288 || nd > 32)
-#else
- if (nl > 286 || nd > 30)
-#endif
- return 1; /* bad lengths */
-
-
- /* read in bit-length-code lengths */
- for (j = 0; j < nb; j++)
- {
- NEEDBITS(3)
- ll[border[j]] = (unsigned)b & 7;
- DUMPBITS(3)
- }
- for (; j < 19; j++)
- ll[border[j]] = 0;
-
-
- /* build decoding table for trees--single level, 7 bit lookup */
- bl = 7;
- if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
- {
- if (i == 1)
- huft_free(tl);
- return i; /* incomplete code set */
- }
-
-
- /* read in literal and distance code lengths */
- n = nl + nd;
- m = mask_bits[bl];
- i = l = 0;
- while ((unsigned)i < n)
- {
- NEEDBITS((unsigned)bl)
- j = (td = tl + ((unsigned)b & m))->b;
- DUMPBITS(j)
- j = td->v.n;
- if (j < 16) /* length of code in bits (0..15) */
- ll[i++] = l = j; /* save last length in l */
- else if (j == 16) /* repeat last length 3 to 6 times */
- {
- NEEDBITS(2)
- j = 3 + ((unsigned)b & 3);
- DUMPBITS(2)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = l;
- }
- else if (j == 17) /* 3 to 10 zero length codes */
- {
- NEEDBITS(3)
- j = 3 + ((unsigned)b & 7);
- DUMPBITS(3)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = 0;
- l = 0;
- }
- else /* j == 18: 11 to 138 zero length codes */
- {
- NEEDBITS(7)
- j = 11 + ((unsigned)b & 0x7f);
- DUMPBITS(7)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = 0;
- l = 0;
- }
- }
-
-
- /* free decoding table for trees */
- huft_free(tl);
-
-
- /* restore the global bit buffer */
- bb = b;
- bk = k;
-
-
- /* build the decoding tables for literal/length and distance codes */
- bl = lbits;
- if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
- {
- if (i == 1) {
- fprintf(stderr, " incomplete literal tree\n");
- huft_free(tl);
- }
- return i; /* incomplete code set */
- }
- bd = dbits;
- if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
- {
- if (i == 1) {
- fprintf(stderr, " incomplete distance tree\n");
-#ifdef PKZIP_BUG_WORKAROUND
- i = 0;
- }
-#else
- huft_free(td);
- }
- huft_free(tl);
- return i; /* incomplete code set */
-#endif
- }
-
-
- /* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
- return 1;
-
-
- /* free the decoding tables, return */
- huft_free(tl);
- huft_free(td);
- return 0;
-}
-
-
-
-int inflate_block(e)
-int *e; /* last block flag */
-/* decompress an inflated block */
-{
- unsigned t; /* block type */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-
- /* make local bit buffer */
- b = bb;
- k = bk;
-
-
- /* read in last block bit */
- NEEDBITS(1)
- *e = (int)b & 1;
- DUMPBITS(1)
-
-
- /* read in block type */
- NEEDBITS(2)
- t = (unsigned)b & 3;
- DUMPBITS(2)
-
-
- /* restore the global bit buffer */
- bb = b;
- bk = k;
-
-
- /* inflate that block type */
- if (t == 2)
- return inflate_dynamic();
- if (t == 0)
- return inflate_stored();
- if (t == 1)
- return inflate_fixed();
-
-
- /* bad block type */
- return 2;
-}
-
-
-
-int inflate()
-/* decompress an inflated entry */
-{
- int e; /* last block flag */
- int r; /* result code */
- unsigned h; /* maximum struct huft's malloc'ed */
-
-
- /* initialize window, bit buffer */
- wp = 0;
- bk = 0;
- bb = 0;
-
-
- /* decompress until the last block */
- h = 0;
- do {
- hufts = 0;
- if ((r = inflate_block(&e)) != 0)
- return r;
- if (hufts > h)
- h = hufts;
- } while (!e);
-
- /* Undo too much lookahead. The next read will be byte aligned so we
- * can discard unused bits in the last meaningful byte.
- */
- while (bk >= 8) {
- bk -= 8;
- inptr--;
- }
-
- /* flush out slide */
- flush_output(wp);
-
-
- /* return success */
-#ifdef DEBUG
- fprintf(stderr, "<%u> ", h);
-#endif /* DEBUG */
- return 0;
-}
diff --git a/libstore/tailor.h b/libstore/tailor.h
deleted file mode 100644
index d207af5..0000000
--- a/libstore/tailor.h
+++ /dev/null
@@ -1,14 +0,0 @@
-
-#ifndef get_char
-# define get_char() get_byte()
-#endif
-
-#ifndef put_char
-# define put_char(c) put_byte(c)
-#endif
-
-#include <stdio.h>
-#define fprintf(stream, fmt...) /* ignore useless error msgs */ ((void)0)
-
-void (*unzip_error) (const char *msg);
-#define error(msg) (*unzip_error) (msg)
diff --git a/libstore/unzip.c b/libstore/unzip.c
deleted file mode 100644
index d0f5bf1..0000000
--- a/libstore/unzip.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/* unzip.c -- decompress files in gzip or pkzip format.
- * Copyright (C) 1992-1993 Jean-loup Gailly
- * This is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License, see the file COPYING.
- *
- * The code in this file is derived from the file funzip.c written
- * and put in the public domain by Mark Adler.
- */
-
-/*
- This version can extract files in gzip or pkzip format.
- For the latter, only the first entry is extracted, and it has to be
- either deflated or stored.
- */
-
-#ifdef RCSID
-static char rcsid[] = "$Id: unzip.c,v 1.1 1994/12/14 04:30:25 roland Exp $";
-#endif
-
-#include "tailor.h"
-#include "gzip.h"
-#include "crypt.h"
-
-/* PKZIP header definitions */
-#define LOCSIG 0x04034b50L /* four-byte lead-in (lsb first) */
-#define LOCFLG 6 /* offset of bit flag */
-#define CRPFLG 1 /* bit for encrypted entry */
-#define EXTFLG 8 /* bit for extended local header */
-#define LOCHOW 8 /* offset of compression method */
-#define LOCTIM 10 /* file mod time (for decryption) */
-#define LOCCRC 14 /* offset of crc */
-#define LOCSIZ 18 /* offset of compressed size */
-#define LOCLEN 22 /* offset of uncompressed length */
-#define LOCFIL 26 /* offset of file name field length */
-#define LOCEXT 28 /* offset of extra field length */
-#define LOCHDR 30 /* size of local header, including sig */
-#define EXTHDR 16 /* size of extended local header, inc sig */
-
-
-/* Globals */
-
-int decrypt; /* flag to turn on decryption */
-char *key; /* not used--needed to link crypt.c */
-int pkzip = 0; /* set for a pkzip file */
-int ext_header = 0; /* set if extended local header */
-
-/* ===========================================================================
- * Check zip file and advance inptr to the start of the compressed data.
- * Get ofname from the local header if necessary.
- */
-int check_zipfile(in)
- int in; /* input file descriptors */
-{
- uch *h = inbuf + inptr; /* first local header */
-
- ifd = in;
-
- /* Check validity of local header, and skip name and extra fields */
- inptr += LOCHDR + SH(h + LOCFIL) + SH(h + LOCEXT);
-
- if (inptr > insize || LG(h) != LOCSIG) {
- fprintf(stderr, "\n%s: %s: not a valid zip file\n",
- progname, ifname);
- exit_code = ERROR;
- return ERROR;
- }
- method = h[LOCHOW];
- if (method != STORED && method != DEFLATED) {
- fprintf(stderr,
- "\n%s: %s: first entry not deflated or stored -- use unzip\n",
- progname, ifname);
- exit_code = ERROR;
- return ERROR;
- }
-
- /* If entry encrypted, decrypt and validate encryption header */
- if ((decrypt = h[LOCFLG] & CRPFLG) != 0) {
- fprintf(stderr, "\n%s: %s: encrypted file -- use unzip\n",
- progname, ifname);
- exit_code = ERROR;
- return ERROR;
- }
-
- /* Save flags for unzip() */
- ext_header = (h[LOCFLG] & EXTFLG) != 0;
- pkzip = 1;
-
- /* Get ofname and time stamp from local header (to be done) */
- return OK;
-}
-
-/* ===========================================================================
- * Unzip in to out. This routine works on both gzip and pkzip files.
- *
- * IN assertions: the buffer inbuf contains already the beginning of
- * the compressed data, from offsets inptr to insize-1 included.
- * The magic header has already been checked. The output buffer is cleared.
- */
-int unzip(in, out)
- int in, out; /* input and output file descriptors */
-{
- ulg orig_crc = 0; /* original crc */
- ulg orig_len = 0; /* original uncompressed length */
- int n;
- uch buf[EXTHDR]; /* extended local header */
-
- ifd = in;
- ofd = out;
-
- updcrc(NULL, 0); /* initialize crc */
-
- if (pkzip && !ext_header) { /* crc and length at the end otherwise */
- orig_crc = LG(inbuf + LOCCRC);
- orig_len = LG(inbuf + LOCLEN);
- }
-
- /* Decompress */
- if (method == DEFLATED) {
-
- int res = inflate();
-
- if (res == 3) {
- error("out of memory");
- } else if (res != 0) {
- error("invalid compressed data--format violated");
- }
-
- } else if (pkzip && method == STORED) {
-
- register ulg n = LG(inbuf + LOCLEN);
-
- if (n != LG(inbuf + LOCSIZ) - (decrypt ? RAND_HEAD_LEN : 0)) {
-
- fprintf(stderr, "len %ld, siz %ld\n", n, LG(inbuf + LOCSIZ));
- error("invalid compressed data--length mismatch");
- }
- while (n--) {
- uch c = (uch)get_byte();
-#ifdef CRYPT
- if (decrypt) zdecode(c);
-#endif
- put_ubyte(c);
- }
- flush_window();
- } else {
- error("internal error, invalid method");
- }
-
- /* Get the crc and original length */
- if (!pkzip) {
- /* crc32 (see algorithm.doc)
- * uncompressed input size modulo 2^32
- */
- for (n = 0; n < 8; n++) {
- buf[n] = (uch)get_byte(); /* may cause an error if EOF */
- }
- orig_crc = LG(buf);
- orig_len = LG(buf+4);
-
- } else if (ext_header) { /* If extended header, check it */
- /* signature - 4bytes: 0x50 0x4b 0x07 0x08
- * CRC-32 value
- * compressed size 4-bytes
- * uncompressed size 4-bytes
- */
- for (n = 0; n < EXTHDR; n++) {
- buf[n] = (uch)get_byte(); /* may cause an error if EOF */
- }
- orig_crc = LG(buf+4);
- orig_len = LG(buf+12);
- }
-
- /* Validate decompression */
- if (orig_crc != updcrc(outbuf, 0)) {
- error("invalid compressed data--crc error");
- }
- if (orig_len != (ulg)bytes_out) {
- error("invalid compressed data--length error");
- }
-
- /* Check if there are more entries in a pkzip file */
- if (pkzip && inptr + 4 < insize && LG(inbuf+inptr) == LOCSIG) {
- if (to_stdout) {
- WARN((stderr,
- "%s: %s has more than one entry--rest ignored\n",
- progname, ifname));
- } else {
- /* Don't destroy the input zip file */
- fprintf(stderr,
- "%s: %s has more than one entry -- unchanged\n",
- progname, ifname);
- exit_code = ERROR;
- ext_header = pkzip = 0;
- return ERROR;
- }
- }
- ext_header = pkzip = 0; /* for next file */
- return OK;
-}
diff --git a/libstore/util.c b/libstore/util.c
index 598586f..5908524 100644
--- a/libstore/util.c
+++ b/libstore/util.c
@@ -10,263 +10,10 @@
static char rcsid[] = "$Id: util.c,v 1.1 1994/12/14 04:29:37 roland Exp $";
#endif
-#include <ctype.h>
-#include <errno.h>
-#include <sys/types.h>
-
-#include "tailor.h"
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-#ifndef NO_FCNTL_H
-# include <fcntl.h>
-#endif
-
-#if defined(STDC_HEADERS) || !defined(NO_STDLIB_H)
-# include <stdlib.h>
-#else
- extern int errno;
-#endif
-
-#include "gzip.h"
-#include "crypt.h"
-
-/* cruft */
-int ifd, ofd;
-int to_stdout=1,quiet=1;
+#include <stddef.h>
/* I/O interface */
int (*unzip_read) (char *buf, size_t maxread);
void (*unzip_write) (const char *buf, size_t nwrite);
-#define read_error() (*unzip_read_error) ()
void (*unzip_read_error) (void);
-
-
-extern ulg crc_32_tab[]; /* crc table, defined below */
-
-int exit_code = OK; /* program exit code */
-int method = DEFLATED;/* compression method */
-unsigned insize; /* valid bytes in inbuf */
-unsigned inptr; /* index of next byte to be processed in inbuf */
-unsigned outcnt; /* bytes in output buffer */
-DECLARE(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
-DECLARE(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
-DECLARE(uch, window, 2L*WSIZE);
-
-
-/* This function stolen from gzip.c. */
-/* ========================================================================
- * Check the magic number of the input file and update ofname if an
- * original name was given and to_stdout is not set.
- * Return the compression method, -1 for error, -2 for warning.
- * Set inptr to the offset of the next byte to be processed.
- * Updates time_stamp if there is one and --no-time is not used.
- * This function may be called repeatedly for an input file consisting
- * of several contiguous gzip'ed members.
- * IN assertions: there is at least one remaining compressed member.
- * If the member is a zip file, it must be the only one.
- */
-int get_method(in)
- int in; /* input file descriptor */
-{
- uch flags; /* compression flags */
- char magic[2]; /* magic header */
- ulg stamp; /* time stamp */
-
- /* Prime the input buffer. */
- fill_inbuf(0);
- inptr = 0;
-
- magic[0] = (char)get_byte();
- magic[1] = (char)get_byte();
-
- method = -1; /* unknown yet */
-
- if (memcmp(magic, GZIP_MAGIC, 2) == 0
- || memcmp(magic, OLD_GZIP_MAGIC, 2) == 0) {
-
- method = (int)get_byte();
- if (method != DEFLATED)
- return -1;
-
- flags = (uch)get_byte();
- if ((flags & ENCRYPTED) != 0) return -1;
- if ((flags & CONTINUATION) != 0) return -1;
- if ((flags & RESERVED) != 0) return -1;
-
- stamp = (ulg)get_byte();
- stamp |= ((ulg)get_byte()) << 8;
- stamp |= ((ulg)get_byte()) << 16;
- stamp |= ((ulg)get_byte()) << 24;
-
- (void)get_byte(); /* Ignore extra flags for the moment */
- (void)get_byte(); /* Ignore OS type for the moment */
-
- if ((flags & CONTINUATION) != 0) {
- unsigned part = (unsigned)get_byte();
- part |= ((unsigned)get_byte())<<8;
- }
- if ((flags & EXTRA_FIELD) != 0) {
- unsigned len = (unsigned)get_byte();
- len |= ((unsigned)get_byte())<<8;
- while (len--) (void)get_byte();
- }
-
- /* Get original file name if it was truncated */
- if ((flags & ORIG_NAME) != 0) {
- /* Discard the old name */
- char c; /* dummy used for NeXTstep 3.0 cc optimizer bug */
- do {c=get_byte();} while (c != 0);
- }
-
- /* Discard file comment if any */
- if ((flags & COMMENT) != 0) {
- while (get_char() != 0) /* null */ ;
- }
- } else if (memcmp(magic, PKZIP_MAGIC, 2) == 0 && inptr == 2
- && memcmp((char*)inbuf, PKZIP_MAGIC, 4) == 0) {
- /* To simplify the code, we support a zip file when alone only.
- * We are thus guaranteed that the entire local header fits in inbuf.
- */
- inptr = 0;
- if (check_zipfile(in) == OK) return 0;
- }
-
- return method != DEFLATED;
-}
-
-
-/* ===========================================================================
- * Run a set of bytes through the crc shift register. If s is a NULL
- * pointer, then initialize the crc shift register contents instead.
- * Return the current crc in either case.
- */
-ulg updcrc(s, n)
- uch *s; /* pointer to bytes to pump through */
- unsigned n; /* number of bytes in s[] */
-{
- register ulg c; /* temporary variable */
-
- static ulg crc = (ulg)0xffffffffL; /* shift register contents */
-
- if (s == NULL) {
- c = 0xffffffffL;
- } else {
- c = crc;
- if (n) do {
- c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
- } while (--n);
- }
- crc = c;
- return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
-}
-
-/* ===========================================================================
- * Clear input and output buffers
- */
-void clear_bufs()
-{
- outcnt = 0;
- insize = inptr = 0;
-}
-
-/* ===========================================================================
- * Fill the input buffer. This is called only when the buffer is empty.
- */
-int fill_inbuf(eof_ok)
- int eof_ok; /* set if EOF acceptable as a result */
-{
- int len;
-
- /* Read as much as possible */
- insize = 0;
- do {
- len = (*unzip_read)((char*)inbuf+insize, INBUFSIZ-insize);
- if (len == 0 || len == EOF) break;
- insize += len;
- } while (insize < INBUFSIZ);
-
- if (insize == 0) {
- if (eof_ok) return EOF;
- read_error();
- }
-
- inptr = 1;
- return inbuf[0];
-}
-
-long int bytes_out;
-
-/* ===========================================================================
- * Write the output window window[0..outcnt-1] and update crc and bytes_out.
- * (Used for the decompressed data only.)
- */
-void flush_window()
-{
- if (outcnt == 0) return;
- updcrc(window, outcnt);
-
- (*unzip_write) ((char *) window, outcnt);
- bytes_out += outcnt;
-
- outcnt = 0;
-}
-
-/* ========================================================================
- * Table of CRC-32's of all single-byte values (made by makecrc.c)
- */
-ulg crc_32_tab[] = {
- 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
- 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
- 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
- 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
- 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
- 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
- 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
- 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
- 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
- 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
- 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
- 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
- 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
- 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
- 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
- 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
- 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
- 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
- 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
- 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
- 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
- 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
- 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
- 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
- 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
- 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
- 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
- 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
- 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
- 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
- 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
- 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
- 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
- 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
- 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
- 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
- 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
- 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
- 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
- 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
- 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
- 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
- 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
- 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
- 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
- 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
- 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
- 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
- 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
- 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
- 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
- 0x2d02ef8dL
-};
+void (*unzip_error) (const char *msg);
diff --git a/libtrivfs/Makefile b/libtrivfs/Makefile
index 241b76d..921acbe 100644
--- a/libtrivfs/Makefile
+++ b/libtrivfs/Makefile
@@ -35,10 +35,10 @@ IOSRCS=io-async-icky.c io-async.c io-duplicate.c io-map.c
io-modes-get.c \
FSYSSRCS=fsys-getroot.c fsys-goaway.c fsys-stubs.c fsys-syncfs.c \
fsys-forward.c fsys-set-options.c fsys-get-options.c \
- fsys-get-children.c fsys-get-source.c
+ file-get-children.c file-get-source.c
OTHERSRCS=demuxer.c protid-clean.c protid-dup.c cntl-create.c \
- cntl-clean.c migsupport.c times.c startup.c open.c \
+ cntl-clean.c times.c startup.c open.c \
runtime-argp.c set-options.c append-args.c dyn-classes.c \
protid-classes.c cntl-classes.c
@@ -49,7 +49,7 @@ MIGSTUBS=fsServer.o ioServer.o fsysServer.o fsys_replyUser.o
libname = libtrivfs
HURDLIBS = fshelp iohelp ports shouldbeinlibc
OBJS= $(sort $(subst .c,.o,$(SRCS)) $(MIGSTUBS))
-MIGSFLAGS=-imacros $(srcdir)/fsmutations.h
+MIGSFLAGS=-imacros $(srcdir)/mig-mutate.h
MIGCOMSFLAGS = -prefix trivfs_
installhdrs := trivfs.h
mig-sheader-prefix = trivfs_
@@ -59,4 +59,4 @@ endif
include ../Makeconf
-$(MIGSTUBS:%Server.o=%.sdefsi): $(srcdir)/fsmutations.h
+$(MIGSTUBS:%Server.o=%.sdefsi): $(srcdir)/mig-mutate.h
diff --git a/libtrivfs/fsys-get-children.c b/libtrivfs/file-get-children.c
similarity index 93%
rename from libtrivfs/fsys-get-children.c
rename to libtrivfs/file-get-children.c
index 4697cc5..a3afbba 100644
--- a/libtrivfs/fsys-get-children.c
+++ b/libtrivfs/file-get-children.c
@@ -1,4 +1,4 @@
-/* fsys_get_children
+/* file_get_children
Copyright (C) 2013 Free Software Foundation, Inc.
@@ -25,7 +25,7 @@
filesystem. CHILDREN is an argz vector containing file names
relative to the root of the receiving translator. */
error_t
-trivfs_S_fsys_get_children (trivfs_control_t server,
+trivfs_S_file_get_children (struct trivfs_protid *cred,
mach_port_t reply,
mach_msg_type_name_t replyPoly,
char **children,
diff --git a/libdiskfs/fsys-get-source.c b/libtrivfs/file-get-source.c
similarity index 86%
rename from libdiskfs/fsys-get-source.c
rename to libtrivfs/file-get-source.c
index 08f227c..35636b5 100644
--- a/libdiskfs/fsys-get-source.c
+++ b/libtrivfs/file-get-source.c
@@ -1,4 +1,4 @@
-/* fsys_get_source
+/* file_get_source
Copyright (C) 2013 Free Software Foundation, Inc.
@@ -20,15 +20,14 @@
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
#include "priv.h"
-#include "fsys_S.h"
/* Return information about the source of the receiving
filesystem. */
error_t
-diskfs_S_fsys_get_source (fsys_t server,
+trivfs_S_file_get_source (struct trivfs_protid *cred,
mach_port_t reply,
mach_msg_type_name_t replyPoly,
char *source)
{
- return diskfs_get_source (source);
+ return cred? trivfs_get_source (cred, source, 1024 /* XXX */): EOPNOTSUPP;
}
diff --git a/libtrivfs/get-source.c b/libtrivfs/get-source.c
index 9ea5693..2605dac 100644
--- a/libtrivfs/get-source.c
+++ b/libtrivfs/get-source.c
@@ -22,7 +22,7 @@
#include "priv.h"
error_t
-trivfs_get_source (char *source)
+trivfs_get_source (struct trivfs_protid *cred, char *source, size_t source_len)
{
return EOPNOTSUPP;
}
diff --git a/libtrivfs/migsupport.c b/libtrivfs/mig-decls.h
similarity index 76%
rename from libtrivfs/migsupport.c
rename to libtrivfs/mig-decls.h
index b2d98e1..2baaee8 100644
--- a/libtrivfs/migsupport.c
+++ b/libtrivfs/mig-decls.h
@@ -15,9 +15,26 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+#ifndef __TRIVFS_MIG_DECLS_H__
+#define __TRIVFS_MIG_DECLS_H__
+
#include "priv.h"
-struct trivfs_protid *
+/* Vectors of dynamically allocated port classes/buckets. */
+
+/* Protid port classes. */
+extern struct port_class **trivfs_dynamic_protid_port_classes;
+extern size_t trivfs_num_dynamic_protid_port_classes;
+
+/* Control port classes. */
+extern struct port_class **trivfs_dynamic_control_port_classes;
+extern size_t trivfs_num_dynamic_control_port_classes;
+
+/* Port buckets. */
+extern struct port_bucket **trivfs_dynamic_port_buckets;
+extern size_t trivfs_num_dynamic_port_buckets;
+
+static inline struct trivfs_protid * __attribute__ ((unused))
trivfs_begin_using_protid (mach_port_t port)
{
if (trivfs_protid_nportclasses + trivfs_num_dynamic_protid_port_classes > 1)
@@ -35,7 +52,7 @@ trivfs_begin_using_protid (mach_port_t port)
return (struct trivfs_protid *) pi;
ports_port_deref (pi);
}
-
+
return 0;
}
else if (trivfs_protid_nportclasses == 1)
@@ -44,14 +61,14 @@ trivfs_begin_using_protid (mach_port_t port)
return ports_lookup_port (0, port, trivfs_dynamic_protid_port_classes[0]);
}
-void
+static inline void __attribute__ ((unused))
trivfs_end_using_protid (struct trivfs_protid *cred)
{
if (cred)
ports_port_deref (cred);
}
-struct trivfs_control *
+static inline struct trivfs_control * __attribute__ ((unused))
trivfs_begin_using_control (mach_port_t port)
{
if (trivfs_cntl_nportclasses + trivfs_num_dynamic_control_port_classes > 1)
@@ -69,7 +86,7 @@ trivfs_begin_using_control (mach_port_t port)
return (struct trivfs_control *) pi;
ports_port_deref (pi);
}
-
+
return 0;
}
else if (trivfs_cntl_nportclasses == 1)
@@ -78,9 +95,11 @@ trivfs_begin_using_control (mach_port_t port)
return ports_lookup_port (0, port, trivfs_dynamic_control_port_classes[0]);
}
-void
+static inline void __attribute__ ((unused))
trivfs_end_using_control (struct trivfs_control *cred)
{
if (cred)
ports_port_deref (cred);
}
+
+#endif /* __TRIVFS_MIG_DECLS_H__ */
diff --git a/libtrivfs/fsmutations.h b/libtrivfs/mig-mutate.h
similarity index 90%
rename from libtrivfs/fsmutations.h
rename to libtrivfs/mig-mutate.h
index d81e5a8..fad5389 100644
--- a/libtrivfs/fsmutations.h
+++ b/libtrivfs/mig-mutate.h
@@ -21,13 +21,12 @@
#define FILE_INTRAN trivfs_protid_t trivfs_begin_using_protid (file_t)
#define FILE_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t)
+#define FILE_IMPORTS import "mig-decls.h";
#define IO_INTRAN trivfs_protid_t trivfs_begin_using_protid (io_t)
#define IO_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t)
+#define IO_IMPORTS import "mig-decls.h";
#define FSYS_INTRAN trivfs_control_t trivfs_begin_using_control (fsys_t)
#define FSYS_DESTRUCTOR trivfs_end_using_control (trivfs_control_t)
-
-#define FILE_IMPORTS import <hurd/trivfs.h>;
-#define IO_IMPORTS import <hurd/trivfs.h>;
-#define FSYS_IMPORTS import <hurd/trivfs.h>;
+#define FSYS_IMPORTS import "mig-decls.h";
diff --git a/libtrivfs/trivfs.h b/libtrivfs/trivfs.h
index cf817b5..bb456ff 100644
--- a/libtrivfs/trivfs.h
+++ b/libtrivfs/trivfs.h
@@ -37,11 +37,6 @@ struct trivfs_protid
struct trivfs_peropen *po;
};
-/* These can be used as `intran' and `destructor' functions for
- a MiG port type, to have the stubs called with the protid pointer. */
-struct trivfs_protid *trivfs_begin_using_protid (mach_port_t);
-void trivfs_end_using_protid (struct trivfs_protid *);
-
struct trivfs_peropen
{
void *hook; /* for user use */
@@ -62,11 +57,6 @@ struct trivfs_control
void *hook; /* for user use */
};
-/* These can be used as `intran' and `destructor' functions for
- a MiG port type, to have the stubs called with the control pointer. */
-struct trivfs_control *trivfs_begin_using_control (mach_port_t);
-void trivfs_end_using_control (struct trivfs_control *);
-
/* The user must define these variables. */
extern int trivfs_fstype;
@@ -235,10 +225,11 @@ error_t trivfs_append_args (struct trivfs_control *fsys,
char **argz, size_t *argz_len);
/* The user may define this function. The function must set source to
- the source device of the filesystem. The function may return an
- EOPNOTSUPP to indicate that the concept of a source device is not
- applicable. The default function always returns EOPNOTSUPP. */
-error_t trivfs_get_source (char *source);
+ the source device of CRED. The function may return an EOPNOTSUPP to
+ indicate that the concept of a source device is not applicable. The
+ default function always returns EOPNOTSUPP. */
+error_t trivfs_get_source (struct trivfs_protid *cred,
+ char *source, size_t source_len);
/* Add the port class *CLASS to the list of control port classes recognized
by trivfs; if *CLASS is 0, an attempt is made to allocate a new port
@@ -266,41 +257,9 @@ error_t trivfs_add_port_bucket (struct port_bucket
**bucket);
/* Remove the previously added dynamic port bucket BUCKET, freeing it
if it was allocated by trivfs_add_port_bucket. */
void trivfs_remove_port_bucket (struct port_bucket *bucket);
-
-/* This stuff is for the sake of MiG stubs and could be in a private
- header. But it might be handy for users that override parts of the
- library. Moreover, since the stub headers will use all the imports we
- need for the stubs, we couldn't make the stub headers public without
- making this public too. */
-
+/* Type-aliases for mig. */
typedef struct trivfs_protid *trivfs_protid_t;
typedef struct trivfs_control *trivfs_control_t;
-struct trivfs_protid *_trivfs_begin_using_protid (mach_port_t);
-void _trivfs_end_using_protid (struct trivfs_protid *);
-struct trivfs_control *_trivfs_begin_using_control (mach_port_t);
-void _trivfs_end_using_control (struct trivfs_control *);
-
-/* Vectors of dynamically allocated port classes/buckets. */
-
-/* Protid port classes. */
-extern struct port_class **trivfs_dynamic_protid_port_classes;
-extern size_t trivfs_num_dynamic_protid_port_classes;
-
-/* Control port classes. */
-extern struct port_class **trivfs_dynamic_control_port_classes;
-extern size_t trivfs_num_dynamic_control_port_classes;
-
-/* Port buckets. */
-extern struct port_bucket **trivfs_dynamic_port_buckets;
-extern size_t trivfs_num_dynamic_port_buckets;
-
-/* These are the MiG-generated headers that declare prototypes
- for the server functions. */
-#include <hurd/trivfs_fs_S.h>
-#include <hurd/trivfs_io_S.h>
-#include <hurd/trivfs_fsys_S.h>
-
-
#endif /* __TRIVFS_H__ */
diff --git a/mach-defpager/default_pager.c b/mach-defpager/default_pager.c
index 66b8587..8f8e13e 100644
--- a/mach-defpager/default_pager.c
+++ b/mach-defpager/default_pager.c
@@ -51,33 +51,43 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <stdarg.h>
#include <file_io.h>
+#include "memory_object_S.h"
+#include "memory_object_default_S.h"
#include "default_pager_S.h"
+#include "exc_S.h"
#define debug 0
static char my_name[] = "(default pager):";
-static pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER;
+static void __attribute__ ((format (printf, 1, 2), unused))
+synchronized_printf (const char *fmt, ...)
+{
+ static pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER;
+ va_list ap;
+
+ va_start (ap, fmt);
+ pthread_mutex_lock (&printf_lock);
+
+ vprintf (fmt, ap);
+ fflush (stdout);
+
+ pthread_mutex_unlock (&printf_lock);
+ va_end (ap);
+}
#if 0
-#define dprintf(f, x...) \
- ({ pthread_mutex_lock (&printf_lock); \
- printf (f , ##x); \
- fflush (stdout); \
- pthread_mutex_unlock (&printf_lock); })
+#define dprintf(f, x...) synchronized_printf (f, ##x)
#else
#define dprintf(f, x...)
#endif
#if 0
-#define ddprintf(f, x...) \
- ({ pthread_mutex_lock (&printf_lock); \
- printf (f , ##x); \
- fflush (stdout); \
- pthread_mutex_unlock (&printf_lock); })
+#define ddprintf(f, x...) synchronized_printf (f, ##x)
#else
#define ddprintf(f, x...)
#endif
@@ -95,10 +105,7 @@ static pthread_mutex_t printf_lock =
PTHREAD_MUTEX_INITIALIZER;
#define ptoa(p) ((p)*vm_page_size)
#define atop(a) ((a)/vm_page_size)
-
-/*
- */
/*
* Bitmap allocation.
*/
@@ -202,8 +209,6 @@ new_partition (const char *name, struct file_direct *fdp,
part = partition_of(i);
if (part && part->id == id)
{
- printf ("(default pager): Already paging to partition %s!\n",
- name);
pthread_mutex_unlock(&all_partitions.lock);
return 0;
}
@@ -246,7 +251,8 @@ new_partition (const char *name, struct file_direct *fdp,
{
/* Filesystem block size is smaller than page size,
so we must do several reads to get the whole page. */
- vm_address_t baddr, bsize;
+ vm_address_t baddr;
+ vm_size_t bsize;
rc = page_read_file_direct(part->file,
rsize, LINUX_PAGE_SIZE-rsize,
&baddr,
@@ -624,10 +630,7 @@ ddprintf
("pager_dealloc_page(%d,%x,%d)\n",pindex,page,lock_it);
if (lock_it)
pthread_mutex_unlock(&part->p_lock);
}
-
-/*
- */
/*
* Allocation info for each paging object.
*
@@ -756,7 +759,9 @@ pager_alloc(pager, part, size)
vm_size_t size; /* in BYTES */
{
int i;
+#ifdef CHECKSUM
dp_map_t mapptr, emapptr;
+#endif
pthread_mutex_init(&pager->lock, NULL);
#if DEBUG_READER_CONFLICTS
@@ -1095,8 +1100,6 @@ dealloc_direct (dp_map_t mapptr,
static void
pager_truncate(dpager_t pager, vm_size_t new_size) /* in pages */
{
- dp_map_t new_mapptr;
- dp_map_t old_mapptr;
int i;
vm_size_t old_size;
@@ -1703,11 +1706,7 @@ ok:
pager->cur_partition = choose_partition(0, P_INDEX_INVALID);
return TRUE;
}
-
-/*
- */
-
/*
* Read/write routines.
*/
@@ -1885,10 +1884,7 @@ default_has_page(ds, offset)
{
return ( ! no_block(pager_read_offset(ds, offset)) );
}
-/*
- */
-
/*
* Mapping between pager port and paging object.
*/
@@ -1994,7 +1990,7 @@ destroy_paging_partition(name, pp_private)
void **pp_private;
{
unsigned int id = part_id(name);
- partition_t part;
+ partition_t part = NULL;
boolean_t all_ok = TRUE;
default_pager_t entry;
int pindex;
@@ -2009,7 +2005,7 @@ destroy_paging_partition(name, pp_private)
part = partition_of(pindex);
if (part && (part->id == id)) break;
}
- if (pindex == all_partitions.n_partitions) {
+ if (! part) {
pthread_mutex_unlock(&all_partitions.lock);
return KERN_INVALID_ARGUMENT;
}
@@ -2509,7 +2505,6 @@ seqnos_memory_object_terminate(pager, seqno,
pager_request, pager_name)
mach_port_t pager_name;
{
default_pager_t ds;
- kern_return_t kr;
static char here[] = "%sterminate";
/*
@@ -2521,7 +2516,7 @@ seqnos_memory_object_terminate(pager, seqno,
pager_request, pager_name)
if (ds == DEFAULT_PAGER_NULL)
panic(here, my_name);
ddprintf ("seqnos_memory_object_terminate <%p>: pager_port_lock:
<%p>[s:%d,r:%d,w:%d,l:%d], %d\n",
- &kr, ds, ds->seqno, ds->readers, ds->writers, ds->lock.held, seqno);
+ &ds, ds, ds->seqno, ds->readers, ds->writers, ds->lock.held, seqno);
pager_port_lock(ds, seqno);
/*
@@ -2552,7 +2547,7 @@ ddprintf ("seqnos_memory_object_terminate <%p>:
pager_port_lock: <%p>[s:%d,r:%d,
ds->pager_name = MACH_PORT_NULL;
ds->name_refs = 0;
ddprintf ("seqnos_memory_object_terminate <%p>: pager_port_unlock:
<%p>[s:%d,r:%d,w:%d,l:%d]\n",
- &kr, ds, ds->seqno, ds->readers, ds->writers, ds->lock.held);
+ &ds, ds, ds->seqno, ds->readers, ds->writers, ds->lock.held);
pager_port_unlock(ds);
/*
@@ -2850,7 +2845,6 @@ seqnos_memory_object_data_write(pager, seqno,
pager_request,
vm_size_t tail_size = round_page(limit) - limit;
memset((void *) tail, 0, tail_size);
- unsigned *arr = (unsigned *)addr;
memory_object_data_supply(pager_request, trunc_page(limit), addr,
vm_page_size, TRUE, VM_PROT_NONE,
TRUE, MACH_PORT_NULL);
@@ -2921,13 +2915,13 @@ seqnos_memory_object_lock_completed (memory_object_t
pager,
kern_return_t
seqnos_memory_object_data_unlock(pager, seqno, pager_request,
- offset, addr, data_cnt)
+ offset, length, protection_required)
memory_object_t pager;
mach_port_seqno_t seqno;
mach_port_t pager_request;
vm_offset_t offset;
- pointer_t addr;
- vm_size_t data_cnt;
+ vm_size_t length;
+ vm_prot_t protection_required;
{
panic("%sdata_unlock",my_name);
return(KERN_FAILURE);
@@ -3019,7 +3013,6 @@ boolean_t default_pager_notify_server(in, out)
return TRUE;
}
-extern boolean_t seqnos_memory_object_server();
extern boolean_t seqnos_memory_object_default_server();
extern boolean_t default_pager_server();
extern boolean_t exc_server();
@@ -3028,6 +3021,37 @@ extern void bootstrap_compat();
mach_msg_size_t default_pager_msg_size_object = 128;
+/* Fill in default response. */
+static void
+mig_reply_setup (
+ const mach_msg_header_t *in,
+ mach_msg_header_t *out)
+{
+ static const mach_msg_type_t RetCodeType = {
+ /* msgt_name = */ MACH_MSG_TYPE_INTEGER_32,
+ /* msgt_size = */ 32,
+ /* msgt_number = */ 1,
+ /* msgt_inline = */ TRUE,
+ /* msgt_longform = */ FALSE,
+ /* msgt_deallocate = */ FALSE,
+ /* msgt_unused = */ 0
+ };
+
+#define InP (in)
+#define OutP ((mig_reply_header_t *) out)
+ OutP->Head.msgh_bits =
+ MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(InP->msgh_bits), 0);
+ OutP->Head.msgh_size = sizeof *OutP;
+ OutP->Head.msgh_remote_port = InP->msgh_remote_port;
+ OutP->Head.msgh_local_port = MACH_PORT_NULL;
+ OutP->Head.msgh_seqno = 0;
+ OutP->Head.msgh_id = InP->msgh_id + 100;
+ OutP->RetCodeType = RetCodeType;
+ OutP->RetCode = MIG_BAD_ID;
+#undef InP
+#undef OutP
+}
+
boolean_t
default_pager_demux_object(in, out)
mach_msg_header_t *in;
@@ -3038,15 +3062,23 @@ default_pager_demux_object(in, out)
* the memory_object_default interface.
*/
-int rval;
-ddprintf ("DPAGER DEMUX OBJECT <%p>: %d\n", in, in->msgh_id);
-rval =
- (seqnos_memory_object_server(in, out) ||
- seqnos_memory_object_default_server(in, out) ||
- default_pager_notify_server(in, out) ||
- default_pager_server(in, out));
-ddprintf ("DPAGER DEMUX OBJECT DONE <%p>: %d\n", in, in->msgh_id);
-return rval;
+ int rval = FALSE;
+ ddprintf ("DPAGER DEMUX OBJECT <%p>: %d\n", in, in->msgh_id);
+ mig_reply_setup (in, out);
+
+ mig_routine_t routine;
+ if ((routine = seqnos_memory_object_server_routine (in)) ||
+ (routine = seqnos_memory_object_default_server_routine (in)) ||
+ (routine = NULL, default_pager_notify_server (in, out)) ||
+ (routine = default_pager_server_routine (in)))
+ {
+ if (routine)
+ (*routine) (in, out);
+ rval = TRUE;
+ }
+
+ ddprintf ("DPAGER DEMUX OBJECT DONE <%p>: %d\n", in, in->msgh_id);
+ return rval;
}
mach_msg_size_t default_pager_msg_size_default = 8 * 1024;
@@ -3390,13 +3422,13 @@ S_default_pager_objects (mach_port_t pager,
mach_port_array_t *portsp,
natural_t *pcountp)
{
- vm_offset_t oaddr; /* memory for objects */
- vm_size_t osize; /* current size */
+ vm_offset_t oaddr = 0; /* memory for objects */
+ vm_size_t osize = 0; /* current size */
default_pager_object_t *objects;
natural_t opotential;
- vm_offset_t paddr; /* memory for ports */
- vm_size_t psize; /* current size */
+ vm_offset_t paddr = 0; /* memory for ports */
+ vm_size_t psize = 0; /* current size */
mach_port_t *ports;
natural_t ppotential;
@@ -3624,8 +3656,8 @@ S_default_pager_object_pages (mach_port_t pager,
default_pager_page_array_t *pagesp,
natural_t *countp)
{
- vm_offset_t addr; /* memory for page offsets */
- vm_size_t size; /* current memory size */
+ vm_offset_t addr = 0; /* memory for page offsets */
+ vm_size_t size = 0; /* current memory size */
default_pager_page_t *pages;
natural_t potential, actual;
kern_return_t kr;
@@ -3728,7 +3760,7 @@ S_default_pager_object_set_size (mach_port_t pager,
mach_port_seqno_t seqno,
vm_size_t limit)
{
- kern_return_t kr;
+ kern_return_t kr = KERN_SUCCESS;
default_pager_t ds;
ds = pager_port_lookup(pager);
diff --git a/mach-defpager/file_io.h b/mach-defpager/file_io.h
index d0b03f3..2721412 100644
--- a/mach-defpager/file_io.h
+++ b/mach-defpager/file_io.h
@@ -57,13 +57,13 @@ struct file_direct
int page_read_file_direct (struct file_direct *fdp,
vm_offset_t offset,
vm_size_t size,
- vm_offset_t *addr, /* out */
- mach_msg_type_number_t *size_read); /* out */
+ vm_offset_t *addr, /* out */
+ vm_size_t *size_read); /* out */
int page_write_file_direct(struct file_direct *fdp,
vm_offset_t offset,
vm_offset_t addr,
vm_size_t size,
- vm_offset_t *size_written); /* out */
+ vm_size_t *size_written); /* out */
#endif /* file_io.h */
diff --git a/mach-defpager/kalloc.c b/mach-defpager/kalloc.c
index 777cd3d..2f8f002 100644
--- a/mach-defpager/kalloc.c
+++ b/mach-defpager/kalloc.c
@@ -122,7 +122,7 @@ void kalloc_init(void)
*/
vm_offset_t kget_space(vm_offset_t size)
{
- vm_size_t space_to_add;
+ vm_size_t space_to_add = 0;
vm_offset_t new_space = 0;
vm_offset_t addr;
diff --git a/mach-defpager/setup.c b/mach-defpager/setup.c
index 080b0fa..7c1afbc 100644
--- a/mach-defpager/setup.c
+++ b/mach-defpager/setup.c
@@ -106,8 +106,8 @@ int
page_read_file_direct (struct file_direct *fdp,
vm_offset_t offset,
vm_size_t size,
- vm_offset_t *addr, /* out */
- mach_msg_type_number_t *size_read) /* out */
+ vm_offset_t *addr, /* out */
+ vm_size_t *size_read) /* out */
{
struct storage_run *r;
error_t err;
@@ -173,7 +173,7 @@ page_write_file_direct(struct file_direct *fdp,
vm_offset_t offset,
vm_offset_t addr,
vm_size_t size,
- vm_offset_t *size_written) /* out */
+ vm_size_t *size_written) /* out */
{
struct storage_run *r;
error_t err;
diff --git a/nfs/main.c b/nfs/main.c
index 3ce75a9..cd1c29a 100644
--- a/nfs/main.c
+++ b/nfs/main.c
@@ -269,6 +269,20 @@ netfs_append_args (char **argz, size_t *argz_len)
return err;
}
+/* The user may define this function. The function must set source to
+ the source of CRED. The function may return an EOPNOTSUPP to
+ indicate that the concept of a source device is not applicable. The
+ default function always returns EOPNOTSUPP. */
+error_t
+netfs_get_source (struct protid *cred, char *source, size_t source_len)
+{
+ if (! cred)
+ return EOPNOTSUPP;
+
+ snprintf (source, source_len, "%s:%s", host, remote_fs);
+ return 0;
+}
+
/* Extract the host and remote filesystem names from SPEC, which should use
either HOST:FS or address@hidden notation. Returns the malloced storage
into
which both REMOTE_FS and HOST point, or 0 if SPEC is invalid. */
diff --git a/pfinet/Makefile b/pfinet/Makefile
index d442629..10b90eb 100644
--- a/pfinet/Makefile
+++ b/pfinet/Makefile
@@ -139,9 +139,10 @@ asm/checksum.h: ../config.status
'#include "../linux-src/include/asm-$(asm_syntax)/checksum.h"'
mv -f address@hidden $@
-io-MIGSFLAGS = -imacros $(srcdir)/mutations.h
-socket-MIGSFLAGS = -imacros $(srcdir)/mutations.h
+io-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
+socket-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
+iioctl-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
# cpp doesn't automatically make dependencies for -imacros dependencies. argh.
-io_S.h ioServer.c socket_S.h socketServer.c: mutations.h
+io_S.h ioServer.c socket_S.h socketServer.c: mig-mutate.h
$(OBJS): config.h
diff --git a/pfinet/iioctl-ops.c b/pfinet/iioctl-ops.c
index 6777680..f1c503d 100644
--- a/pfinet/iioctl-ops.c
+++ b/pfinet/iioctl-ops.c
@@ -74,21 +74,20 @@ enum siocgif_type
#define SIOCGIF(name, type) \
kern_return_t
\
- S_iioctl_siocgif##name (io_t port, \
+ S_iioctl_siocgif##name (struct sock_user *user, \
ifname_t ifnam, \
sockaddr_t *addr) \
{ \
- return siocgifXaddr (port, ifnam, addr, type); \
+ return siocgifXaddr (user, ifnam, addr, type); \
}
/* Get some sockaddr type of info. */
static kern_return_t
-siocgifXaddr (io_t port,
+siocgifXaddr (struct sock_user *user,
ifname_t ifnam,
sockaddr_t *addr,
enum siocgif_type type)
{
- struct sock_user *user = begin_using_socket_port (port);
error_t err = 0;
struct device *dev;
struct sockaddr_in *sin = (struct sockaddr_in *) addr;
@@ -111,27 +110,25 @@ siocgifXaddr (io_t port,
}
pthread_mutex_unlock (&global_lock);
- end_using_socket_port (user);
return err;
}
#define SIOCSIF(name, type) \
kern_return_t
\
- S_iioctl_siocsif##name (io_t port, \
+ S_iioctl_siocsif##name (struct sock_user *user, \
ifname_t ifnam, \
sockaddr_t addr) \
{ \
- return siocsifXaddr (port, ifnam, &addr, type); \
+ return siocsifXaddr (user, ifnam, &addr, type); \
}
/* Set some sockaddr type of info. */
static kern_return_t
-siocsifXaddr (io_t port,
+siocsifXaddr (struct sock_user *user,
ifname_t ifnam,
sockaddr_t *addr,
enum siocgif_type type)
{
- struct sock_user *user = begin_using_socket_port(port);
error_t err = 0;
struct device *dev;
struct sockaddr_in *sin = (struct sockaddr_in *) addr;
@@ -158,7 +155,6 @@ siocsifXaddr (io_t port,
}
pthread_mutex_unlock (&global_lock);
- end_using_socket_port (user);
return err;
}
@@ -170,11 +166,10 @@ SIOCSIF (dstaddr, DSTADDR);
/* 16 SIOCSIFFLAGS -- Set flags of a network interface. */
kern_return_t
-S_iioctl_siocsifflags (io_t port,
+S_iioctl_siocsifflags (struct sock_user *user,
ifname_t ifnam,
short flags)
{
- struct sock_user *user = begin_using_socket_port (port);
error_t err = 0;
struct device *dev;
@@ -191,13 +186,12 @@ S_iioctl_siocsifflags (io_t port,
err = dev_change_flags (dev, flags);
pthread_mutex_unlock (&global_lock);
- end_using_socket_port (user);
return err;
}
/* 17 SIOCGIFFLAGS -- Get flags of a network interface. */
kern_return_t
-S_iioctl_siocgifflags (io_t port,
+S_iioctl_siocgifflags (struct sock_user *user,
char *name,
short *flags)
{
@@ -223,7 +217,7 @@ SIOCSIF (netmask, NETMASK);
/* 23 SIOCGIFMETRIC -- Get metric of a network interface. */
kern_return_t
-S_iioctl_siocgifmetric (io_t port,
+S_iioctl_siocgifmetric (struct sock_user *user,
ifname_t ifnam,
int *metric)
{
@@ -243,7 +237,7 @@ S_iioctl_siocgifmetric (io_t port,
/* 24 SIOCSIFMETRIC -- Set metric of a network interface. */
kern_return_t
-S_iioctl_siocsifmetric (io_t port,
+S_iioctl_siocsifmetric (struct sock_user *user,
ifname_t ifnam,
int metric)
{
@@ -252,7 +246,7 @@ S_iioctl_siocsifmetric (io_t port,
/* 25 SIOCDIFADDR -- Delete interface address. */
kern_return_t
-S_iioctl_siocdifaddr (io_t port,
+S_iioctl_siocdifaddr (struct sock_user *user,
ifname_t ifnam,
sockaddr_t addr)
{
@@ -273,14 +267,14 @@ SIOCGIF (netmask, NETMASK);
/* 39 SIOCGIFHWADDR -- Get the hardware address of a network interface. */
error_t
-S_iioctl_siocgifhwaddr (io_t port,
+S_iioctl_siocgifhwaddr (struct sock_user *user,
ifname_t ifname,
sockaddr_t *addr)
{
error_t err = 0;
struct device *dev;
- if (!port)
+ if (!user)
return EOPNOTSUPP;
dev = get_dev (ifname);
@@ -298,7 +292,7 @@ S_iioctl_siocgifhwaddr (io_t port,
/* 51 SIOCGIFMTU -- Get mtu of a network interface. */
error_t
-S_iioctl_siocgifmtu (io_t port,
+S_iioctl_siocgifmtu (struct sock_user *user,
ifname_t ifnam,
int *mtu)
{
@@ -318,11 +312,10 @@ S_iioctl_siocgifmtu (io_t port,
/* 51 SIOCSIFMTU -- Set mtu of a network interface. */
error_t
-S_iioctl_siocsifmtu (io_t port,
+S_iioctl_siocsifmtu (struct sock_user *user,
ifname_t ifnam,
int mtu)
{
- struct sock_user *user = begin_using_socket_port (port);
error_t err = 0;
struct device *dev;
@@ -348,13 +341,12 @@ S_iioctl_siocsifmtu (io_t port,
}
pthread_mutex_unlock (&global_lock);
- end_using_socket_port (user);
return err;
}
/* 100 SIOCGIFINDEX -- Get index number of a network interface. */
error_t
-S_iioctl_siocgifindex (io_t port,
+S_iioctl_siocgifindex (struct sock_user *user,
ifname_t ifnam,
int *index)
{
@@ -374,7 +366,7 @@ S_iioctl_siocgifindex (io_t port,
/* 101 SIOCGIFNAME -- Get name of a network interface from index number. */
error_t
-S_iioctl_siocgifname (io_t port,
+S_iioctl_siocgifname (struct sock_user *user,
ifname_t ifnam,
int *index)
{
diff --git a/pfinet/main.c b/pfinet/main.c
index a596e18..5b0262f 100644
--- a/pfinet/main.c
+++ b/pfinet/main.c
@@ -383,7 +383,7 @@ main (int argc,
/* Launch */
ports_manage_port_operations_multithread (pfinet_bucket,
pfinet_demuxer,
- 0, 0, 0);
+ 30 * 1000, 2 * 60 * 1000, 0);
return 0;
}
diff --git a/pfinet/mig-decls.h b/pfinet/mig-decls.h
new file mode 100644
index 0000000..ec8fb23
--- /dev/null
+++ b/pfinet/mig-decls.h
@@ -0,0 +1,55 @@
+/*
+ Copyright (C) 1995,96,2000 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell, p/BSG.
+
+ 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 the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef __PFINET_MIG_DECLS_H__
+#define __PFINET_MIG_DECLS_H__
+
+#include "pfinet.h"
+
+/* MiG bogosity */
+typedef struct sock_user *sock_user_t;
+typedef struct sock_addr *sock_addr_t;
+
+static inline struct sock_user * __attribute__ ((unused))
+begin_using_socket_port (mach_port_t port)
+{
+ return ports_lookup_port (pfinet_bucket, port, socketport_class);
+}
+
+static inline void __attribute__ ((unused))
+end_using_socket_port (struct sock_user *user)
+{
+ if (user)
+ ports_port_deref (user);
+}
+
+static inline struct sock_addr * __attribute__ ((unused))
+begin_using_sockaddr_port (mach_port_t port)
+{
+ return ports_lookup_port (pfinet_bucket, port, addrport_class);
+}
+
+static inline void __attribute__ ((unused))
+end_using_sockaddr_port (struct sock_addr *addr)
+{
+ if (addr)
+ ports_port_deref (addr);
+}
+
+#endif /* __PFINET_MIG_DECLS_H__ */
diff --git a/pfinet/mutations.h b/pfinet/mig-mutate.h
similarity index 88%
rename from pfinet/mutations.h
rename to pfinet/mig-mutate.h
index f63ad9b..0a1eeb8 100644
--- a/pfinet/mutations.h
+++ b/pfinet/mig-mutate.h
@@ -24,15 +24,17 @@
#define IO_INTRAN sock_user_t begin_using_socket_port (io_t)
#define IO_DESTRUCTOR end_using_socket_port (sock_user_t)
+#define IO_IMPORTS import "mig-decls.h";
+#define IIOCTL_IMPORTS import "mig-decls.h";
#define SOCKET_INTRAN sock_user_t begin_using_socket_port (socket_t)
#define SOCKET_DESTRUCTOR end_using_socket_port (sock_user_t)
+#define SOCKET_IMPORTS \
+ import "mig-decls.h"; \
+ import "../libtrivfs/mig-decls.h"; \
#define ADDRPORT_INTRAN sock_addr_t begin_using_sockaddr_port (addr_port_t)
#define ADDRPORT_DESTRUCTOR end_using_sockaddr_port (sock_addr_t)
#define PF_INTRAN trivfs_protid_t trivfs_begin_using_protid (pf_t)
#define PF_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t)
-
-#define IO_IMPORTS import "pfinet.h";
-#define SOCKET_IMPORTS import "pfinet.h";
diff --git a/pfinet/misc.c b/pfinet/misc.c
index 08b19e9..d0987eb 100644
--- a/pfinet/misc.c
+++ b/pfinet/misc.c
@@ -62,32 +62,6 @@ make_sockaddr_port (struct socket *sock,
return 0;
}
-struct sock_user *
-begin_using_socket_port (mach_port_t port)
-{
- return ports_lookup_port (pfinet_bucket, port, socketport_class);
-}
-
-void
-end_using_socket_port (struct sock_user *user)
-{
- if (user)
- ports_port_deref (user);
-}
-
-struct sock_addr *
-begin_using_sockaddr_port (mach_port_t port)
-{
- return ports_lookup_port (pfinet_bucket, port, addrport_class);
-}
-
-void
-end_using_sockaddr_port (struct sock_addr *addr)
-{
- if (addr)
- ports_port_deref (addr);
-}
-
/* Nothing need be done here. */
void
clean_addrport (void *arg)
diff --git a/pfinet/pfinet.h b/pfinet/pfinet.h
index 9725dab..46aa97b 100644
--- a/pfinet/pfinet.h
+++ b/pfinet/pfinet.h
@@ -83,18 +83,9 @@ void ip_rt_del (u_long, struct device *);
struct sock;
error_t tcp_tiocinq (struct sock *sk, mach_msg_type_number_t *amount);
-
-struct sock_user *begin_using_socket_port (socket_t);
-struct sock_addr *begin_using_sockaddr_port (socket_t);
-void end_using_socket_port (struct sock_user *);
-void end_using_sockaddr_port (struct sock_addr *);
void clean_addrport (void *);
void clean_socketport (void *);
-/* MiG bogosity */
-typedef struct sock_user *sock_user_t;
-typedef struct sock_addr *sock_addr_t;
-
/* pfinet6 port classes. */
enum {
PORTCLASS_INET,
diff --git a/term/Makefile b/term/Makefile
index 025a9b3..5006c0d 100644
--- a/term/Makefile
+++ b/term/Makefile
@@ -32,3 +32,6 @@ OBJS = $(subst .c,.o,$(SRCS)) termServer.o
device_replyServer.o tioctlServer.o o
include ../Makeconf
device_replyServer-CPPFLAGS = -DTypeCheck=0 -Wno-unused # XXX
+
+tioctl-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
+term-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h
diff --git a/libdiskfs/get-source.c b/term/mig-mutate.h
similarity index 63%
copy from libdiskfs/get-source.c
copy to term/mig-mutate.h
index d0c143b..a6b99fe 100644
--- a/libdiskfs/get-source.c
+++ b/term/mig-mutate.h
@@ -1,8 +1,6 @@
-/* Default version of diskfs_get_source
-
- Copyright (C) 2013 Free Software Foundation, Inc.
-
- Written by Justus Winter <address@hidden>
+/*
+ Copyright (C) 2014 Free Software Foundation, Inc.
+ Written by Justus Winter.
This file is part of the GNU Hurd.
@@ -19,10 +17,9 @@
You should have received a copy of the GNU General Public License
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
-#include "priv.h"
+/* Only CPP macro definitions should go in this file. */
-error_t
-diskfs_get_source (char *source)
-{
- return EOPNOTSUPP;
-}
+#define IO_INTRAN trivfs_protid_t trivfs_begin_using_protid (io_t)
+#define IO_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t)
+#define TIOCTL_IMPORTS import "../libtrivfs/mig-decls.h";
+#define TERM_IMPORTS import "../libtrivfs/mig-decls.h";
diff --git a/term/ptyio.c b/term/ptyio.c
index 2da7d6c..211e70a 100644
--- a/term/ptyio.c
+++ b/term/ptyio.c
@@ -512,12 +512,12 @@ pty_io_select (struct trivfs_protid *cred, mach_port_t
reply,
}
error_t
-S_tioctl_tiocsig (io_t port,
+S_tioctl_tiocsig (struct trivfs_protid *cred,
int sig)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket,
- port, pty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != pty_class)
return EOPNOTSUPP;
pthread_mutex_lock (&global_lock);
@@ -529,20 +529,18 @@ S_tioctl_tiocsig (io_t port,
send_signal (sig);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return 0;
}
error_t
-S_tioctl_tiocpkt (io_t port,
+S_tioctl_tiocpkt (struct trivfs_protid *cred,
int mode)
{
error_t err;
-
- struct trivfs_protid *cred = ports_lookup_port (term_bucket,
- port, pty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != pty_class)
return EOPNOTSUPP;
pthread_mutex_lock (&global_lock);
@@ -559,20 +557,18 @@ S_tioctl_tiocpkt (io_t port,
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
error_t
-S_tioctl_tiocucntl (io_t port,
+S_tioctl_tiocucntl (struct trivfs_protid *cred,
int mode)
{
error_t err;
-
- struct trivfs_protid *cred = ports_lookup_port (term_bucket,
- port, pty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != pty_class)
return EOPNOTSUPP;
pthread_mutex_lock (&global_lock);
@@ -589,19 +585,17 @@ S_tioctl_tiocucntl (io_t port,
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
error_t
-S_tioctl_tiocremote (io_t port,
+S_tioctl_tiocremote (struct trivfs_protid *cred,
int how)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket,
- port, pty_class);
-
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != pty_class)
return EOPNOTSUPP;
pthread_mutex_lock (&global_lock);
@@ -611,17 +605,16 @@ S_tioctl_tiocremote (io_t port,
clear_queue (rawq);
ptyio_notice_input_flushed ();
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return 0;
}
error_t
-S_tioctl_tiocext (io_t port,
+S_tioctl_tiocext (struct trivfs_protid *cred,
int mode)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket,
- port, pty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != pty_class)
return EOPNOTSUPP;
pthread_mutex_lock (&global_lock);
@@ -646,6 +639,5 @@ S_tioctl_tiocext (io_t port,
termstate.c_lflag &= ~EXTPROC;
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return 0;
}
diff --git a/term/users.c b/term/users.c
index eacd150..9ec9594 100644
--- a/term/users.c
+++ b/term/users.c
@@ -352,15 +352,15 @@ trivfs_modify_stat (struct trivfs_protid *cred, struct
stat *st)
/* Implement term_getctty as described in <hurd/term.defs>. */
kern_return_t
-S_term_getctty (mach_port_t arg,
+S_term_getctty (struct trivfs_protid *cred,
mach_port_t *id,
mach_msg_type_name_t *idtype)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket,
- arg, tty_class);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != tty_class)
return EOPNOTSUPP;
pthread_mutex_lock (&global_lock);
@@ -373,7 +373,6 @@ S_term_getctty (mach_port_t arg,
*idtype = MACH_MSG_TYPE_MAKE_SEND;
err = 0;
}
- ports_port_deref (cred);
pthread_mutex_unlock (&global_lock);
return err;
}
@@ -390,7 +389,6 @@ S_termctty_open_terminal (mach_port_t arg,
struct iouser *user;
struct trivfs_protid *newcred;
struct port_info *pi = ports_lookup_port (term_bucket, arg, cttyid_class);
-
if (!pi)
return EOPNOTSUPP;
@@ -417,7 +415,7 @@ S_termctty_open_terminal (mach_port_t arg,
/* Implement term_become_ctty as described in <hurd/term.defs>. */
kern_return_t
-S_term_open_ctty (mach_port_t arg,
+S_term_open_ctty (struct trivfs_protid *cred,
pid_t pid,
pid_t pgrp,
mach_port_t *newpt,
@@ -425,14 +423,14 @@ S_term_open_ctty (mach_port_t arg,
{
error_t err;
struct trivfs_protid *newcred;
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, arg, tty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != tty_class)
return EOPNOTSUPP;
if (pid <= 0 || pgrp <= 0)
{
- ports_port_deref (cred);
return EINVAL;
}
@@ -469,8 +467,6 @@ S_term_open_ctty (mach_port_t arg,
}
}
- ports_port_deref (cred);
-
return err;
}
@@ -902,19 +898,18 @@ trivfs_S_io_revoke (struct trivfs_protid *cred,
/* TIOCMODG ioctl -- Get modem state */
kern_return_t
-S_tioctl_tiocmodg (io_t port,
+S_tioctl_tiocmodg (struct trivfs_protid *cred,
int *state)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err = 0;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -922,24 +917,22 @@ S_tioctl_tiocmodg (io_t port,
err = (*bottom->mdmstate) (state);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCMODS ioctl -- Set modem state */
kern_return_t
-S_tioctl_tiocmods (io_t port,
+S_tioctl_tiocmods (struct trivfs_protid *cred,
int state)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -952,23 +945,21 @@ S_tioctl_tiocmods (io_t port,
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCEXCL ioctl -- Set exclusive use */
kern_return_t
-S_tioctl_tiocexcl (io_t port)
+S_tioctl_tiocexcl (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -983,24 +974,22 @@ S_tioctl_tiocexcl (io_t port)
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCNXCL ioctl -- Clear exclusive use */
kern_return_t
-S_tioctl_tiocnxcl (io_t port)
+S_tioctl_tiocnxcl (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1014,25 +1003,23 @@ S_tioctl_tiocnxcl (io_t port)
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCFLUSH ioctl -- Flush input, output, or both */
kern_return_t
-S_tioctl_tiocflush (io_t port,
+S_tioctl_tiocflush (struct trivfs_protid *cred,
int flags)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err = 0;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1056,26 +1043,23 @@ S_tioctl_tiocflush (io_t port,
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCGETA ioctl -- Get termios state */
kern_return_t
-S_tioctl_tiocgeta (io_t port,
+S_tioctl_tiocgeta (struct trivfs_protid *cred,
tcflag_t *modes,
cc_t *ccs,
speed_t *speeds)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
-
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1089,30 +1073,28 @@ S_tioctl_tiocgeta (io_t port,
speeds[1] = termstate.__ospeed;
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return 0;
}
/* Common code for the varios TIOCSET* commands. */
static error_t
-set_state (io_t port,
+set_state (struct trivfs_protid *cred,
tcflag_t *modes,
cc_t *ccs,
speed_t *speeds,
int draino,
int flushi)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
struct termios state;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1181,80 +1163,75 @@ set_state (io_t port,
leave:
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSETA -- Set termios state */
kern_return_t
-S_tioctl_tiocseta (io_t port,
+S_tioctl_tiocseta (struct trivfs_protid *cred,
tcflag_t *modes,
cc_t *ccs,
speed_t *speeds)
{
- return set_state (port, modes, ccs, speeds, 0, 0);
+ return set_state (cred, modes, ccs, speeds, 0, 0);
}
/* Drain output, then set term state. */
kern_return_t
-S_tioctl_tiocsetaw (io_t port,
+S_tioctl_tiocsetaw (struct trivfs_protid *cred,
tcflag_t *modes,
cc_t *ccs,
speed_t *speeds)
{
- return set_state (port, modes, ccs, speeds, 1, 0);
+ return set_state (cred, modes, ccs, speeds, 1, 0);
}
/* Flush input, drain output, then set term state. */
kern_return_t
-S_tioctl_tiocsetaf (io_t port,
+S_tioctl_tiocsetaf (struct trivfs_protid *cred,
tcflag_t *modes,
cc_t *ccs,
speed_t *speeds)
{
- return set_state (port, modes, ccs, speeds, 1, 1);
+ return set_state (cred, modes, ccs, speeds, 1, 1);
}
/* TIOCGETD -- Return line discipline */
kern_return_t
-S_tioctl_tiocgetd (io_t port,
+S_tioctl_tiocgetd (struct trivfs_protid *cred,
int *disc)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
-
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
*disc = 0;
- ports_port_deref (cred);
return 0;
}
/* TIOCSETD -- Set line discipline */
kern_return_t
-S_tioctl_tiocsetd (io_t port,
+S_tioctl_tiocsetd (struct trivfs_protid *cred,
int disc)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1268,24 +1245,22 @@ S_tioctl_tiocsetd (io_t port,
else
err = 0;
- ports_port_deref (cred);
return err;
}
/* TIOCDRAIN -- Wait for output to drain */
kern_return_t
-S_tioctl_tiocdrain (io_t port)
+S_tioctl_tiocdrain (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1293,31 +1268,28 @@ S_tioctl_tiocdrain (io_t port)
if (!(cred->po->openmodes & O_WRITE))
{
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return EBADF;
}
err = drain_output ();
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSWINSZ -- Set window size */
kern_return_t
-S_tioctl_tiocswinsz (io_t port,
+S_tioctl_tiocswinsz (struct trivfs_protid *cred,
struct winsize size)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1328,8 +1300,6 @@ S_tioctl_tiocswinsz (io_t port,
else
err = 0;
- ports_port_deref (cred);
-
if (! err
&& (size.ws_row != window_size.ws_row
|| size.ws_col != window_size.ws_col
@@ -1348,18 +1318,16 @@ S_tioctl_tiocswinsz (io_t port,
/* TIOCGWINSZ -- Fetch window size */
kern_return_t
-S_tioctl_tiocgwinsz (io_t port,
+S_tioctl_tiocgwinsz (struct trivfs_protid *cred,
struct winsize *size)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
-
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1367,25 +1335,23 @@ S_tioctl_tiocgwinsz (io_t port,
*size = window_size;
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return 0;
}
/* TIOCMGET -- Fetch all modem bits */
kern_return_t
-S_tioctl_tiocmget (io_t port,
+S_tioctl_tiocmget (struct trivfs_protid *cred,
int *bits)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err = 0;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1393,25 +1359,23 @@ S_tioctl_tiocmget (io_t port,
err = (*bottom->mdmstate) (bits);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCMSET -- Set all modem bits */
kern_return_t
-S_tioctl_tiocmset (io_t port,
+S_tioctl_tiocmset (struct trivfs_protid *cred,
int bits)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1422,25 +1386,23 @@ S_tioctl_tiocmset (io_t port,
err = (*bottom->mdmctl) (MDMCTL_SET, bits);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCMBIC -- Clear some modem bits */
kern_return_t
-S_tioctl_tiocmbic (io_t port,
+S_tioctl_tiocmbic (struct trivfs_protid *cred,
int bits)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1451,25 +1413,23 @@ S_tioctl_tiocmbic (io_t port,
err = (*bottom->mdmctl) (MDMCTL_BIC, bits);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCMBIS -- Set some modem bits */
kern_return_t
-S_tioctl_tiocmbis (io_t port,
+S_tioctl_tiocmbis (struct trivfs_protid *cred,
int bits)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1480,24 +1440,22 @@ S_tioctl_tiocmbis (io_t port,
else
err = (*bottom->mdmctl) (MDMCTL_BIS, bits);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSTART -- start output as if VSTART were typed */
kern_return_t
-S_tioctl_tiocstart (io_t port)
+S_tioctl_tiocstart (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1516,24 +1474,22 @@ S_tioctl_tiocstart (io_t port)
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSTOP -- stop output as if VSTOP were typed */
kern_return_t
-S_tioctl_tiocstop (io_t port)
+S_tioctl_tiocstop (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
pthread_mutex_lock (&global_lock);
@@ -1550,25 +1506,23 @@ S_tioctl_tiocstop (io_t port)
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSTI -- Simulate terminal input */
kern_return_t
-S_tioctl_tiocsti (io_t port,
+S_tioctl_tiocsti (struct trivfs_protid *cred,
char c)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1587,25 +1541,23 @@ S_tioctl_tiocsti (io_t port,
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCOUTQ -- return output queue size */
kern_return_t
-S_tioctl_tiocoutq (io_t port,
+S_tioctl_tiocoutq (struct trivfs_protid *cred,
int *queue_size)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1620,25 +1572,23 @@ S_tioctl_tiocoutq (io_t port,
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSPGRP -- set pgrp of terminal */
kern_return_t
-S_tioctl_tiocspgrp (io_t port,
+S_tioctl_tiocspgrp (struct trivfs_protid *cred,
int pgrp)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1653,25 +1603,23 @@ S_tioctl_tiocspgrp (io_t port,
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCGPGRP --- fetch pgrp of terminal */
kern_return_t
-S_tioctl_tiocgpgrp (io_t port,
+S_tioctl_tiocgpgrp (struct trivfs_protid *cred,
int *pgrp)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t ret;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1685,24 +1633,22 @@ S_tioctl_tiocgpgrp (io_t port,
}
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return ret;
}
/* TIOCCDTR -- clear DTR */
kern_return_t
-S_tioctl_tioccdtr (io_t port)
+S_tioctl_tioccdtr (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1713,24 +1659,22 @@ S_tioctl_tioccdtr (io_t port)
err = (*bottom->mdmctl) (MDMCTL_BIC, TIOCM_DTR);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSDTR -- set DTR */
kern_return_t
-S_tioctl_tiocsdtr (io_t port)
+S_tioctl_tiocsdtr (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1741,24 +1685,22 @@ S_tioctl_tiocsdtr (io_t port)
err = (*bottom->mdmctl) (MDMCTL_BIS, TIOCM_DTR);
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCCBRK -- Clear break condition */
kern_return_t
-S_tioctl_tioccbrk (io_t port)
+S_tioctl_tioccbrk (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1769,24 +1711,22 @@ S_tioctl_tioccbrk (io_t port)
err = (*bottom->clear_break) ();
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
/* TIOCSBRK -- Set break condition */
kern_return_t
-S_tioctl_tiocsbrk (io_t port)
+S_tioctl_tiocsbrk (struct trivfs_protid *cred)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0);
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket)
return EOPNOTSUPP;
if (cred->pi.class != pty_class
&& cred->pi.class != tty_class)
{
- ports_port_deref (cred);
return EOPNOTSUPP;
}
@@ -1797,7 +1737,6 @@ S_tioctl_tiocsbrk (io_t port)
err = (*bottom->set_break) ();
pthread_mutex_unlock (&global_lock);
- ports_port_deref (cred);
return err;
}
@@ -2189,62 +2128,62 @@ report_carrier_error (error_t err)
}
kern_return_t
-S_term_get_nodename (io_t arg,
+S_term_get_nodename (struct trivfs_protid *cred,
char *name)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, arg,
- tty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != tty_class)
return EOPNOTSUPP;
if (!cred->po->cntl->hook)
{
- ports_port_deref (cred);
return ENOENT;
}
strcpy (name, (char *)cred->po->cntl->hook);
- ports_port_deref (cred);
return 0;
}
kern_return_t
-S_term_set_nodename (io_t arg,
+S_term_set_nodename (struct trivfs_protid *cred,
char *name)
{
error_t err = 0;
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, arg, tty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != tty_class)
return EOPNOTSUPP;
if (strcmp (name, (char *)cred->po->cntl->hook) != 0)
err = EINVAL;
- ports_port_deref (cred);
return err;
}
kern_return_t
-S_term_set_filenode (io_t arg,
+S_term_set_filenode (struct trivfs_protid *cred,
file_t filenode)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, arg,
- tty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != tty_class)
return EOPNOTSUPP;
- ports_port_deref (cred);
return EINVAL;
}
kern_return_t
-S_term_get_peername (io_t arg,
+S_term_get_peername (struct trivfs_protid *cred,
char *name)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, arg, 0);
struct trivfs_control *peer;
+ if (!cred
+ || cred->pi.bucket != term_bucket)
+ return EOPNOTSUPP;
+
if (!cred || (cred->pi.class != tty_class && cred->pi.class != pty_class))
{
if (cred)
@@ -2261,47 +2200,45 @@ S_term_get_peername (io_t arg,
}
strcpy (name, (char *) peer->hook);
- ports_port_deref (cred);
return 0;
}
kern_return_t
-S_term_get_bottom_type (io_t arg,
+S_term_get_bottom_type (struct trivfs_protid *cred,
int *ttype)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket,
- arg, tty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != tty_class)
return EOPNOTSUPP;
- ports_port_deref (cred);
*ttype = bottom->type;
return 0;
}
kern_return_t
-S_term_on_machdev (io_t arg,
+S_term_on_machdev (struct trivfs_protid *cred,
device_t machdev)
{
- struct trivfs_protid *cred = ports_lookup_port (term_bucket, arg,
- tty_class);
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != term_bucket
+ || cred->pi.class != tty_class)
return EOPNOTSUPP;
- ports_port_deref (cred);
+
return EINVAL;
}
kern_return_t
-S_term_on_hurddev (io_t arg,
- io_t hurddev)
+S_term_on_hurddev (struct trivfs_protid *cred,
+ struct trivfs_protid *hurddev)
{
return EOPNOTSUPP;
}
kern_return_t
-S_term_on_pty (io_t arg,
- mach_port_t *master)
+S_term_on_pty (struct trivfs_protid *cred,
+ struct trivfs_protid **master)
{
return EOPNOTSUPP;
}
diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c
index 7da3dd5..a45d343 100644
--- a/tmpfs/tmpfs.c
+++ b/tmpfs/tmpfs.c
@@ -33,7 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA
02139, USA. */
char *diskfs_server_name = "tmpfs";
char *diskfs_server_version = HURD_VERSION;
char *diskfs_extra_version = "GNU Hurd";
-char *diskfs_disk_name = "swap";
+char *diskfs_disk_name = "none";
/* We ain't got to show you no stinkin' sync'ing. */
int diskfs_default_sync_interval = 0;
diff --git a/trans/Makefile b/trans/Makefile
index c0386d0..a294282 100644
--- a/trans/Makefile
+++ b/trans/Makefile
@@ -35,7 +35,12 @@ password-LDLIBS = $(LIBCRYPT)
password-MIGSFLAGS=\
"-DIO_INTRAN=trivfs_protid_t trivfs_begin_using_protid (io_t)" \
"-DIO_DESTRUCTOR=trivfs_end_using_protid (trivfs_protid_t)" \
- "-DPASSWORD_IMPORTS=import <hurd/trivfs.h>;"
+ "-DPASSWORD_IMPORTS=import \"../libtrivfs/mig-decls.h\";"
+
+ifsock-MIGSFLAGS=\
+ "-DFILE_INTRAN=trivfs_protid_t trivfs_begin_using_protid (io_t)" \
+ "-DFILE_DESTRUCTOR=trivfs_end_using_protid (trivfs_protid_t)" \
+ "-DIFSOCK_IMPORTS=import \"../libtrivfs/mig-decls.h\";"
include ../Makeconf
@@ -56,7 +61,7 @@ magic: ../libiohelp/libiohelp.a
hello: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a
../libports/libports.a ../libihash/libihash.a
fakeroot: ../libnetfs/libnetfs.a ../libfshelp/libfshelp.a
../libiohelp/libiohelp.a ../libports/libports.a ../libihash/libihash.a
remap: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a
../libports/libports.a ../libihash/libihash.a
-mtab: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a
../libihash/libihash.a fsysUser.o
+mtab: ../libtrivfs/libtrivfs.a ../libfshelp/libfshelp.a ../libports/libports.a
../libihash/libihash.a fsUser.o
$(targets): ../libshouldbeinlibc/libshouldbeinlibc.a
$(targets): %: %.o
diff --git a/trans/fakeroot.c b/trans/fakeroot.c
index 3038612..c519180 100644
--- a/trans/fakeroot.c
+++ b/trans/fakeroot.c
@@ -348,6 +348,10 @@ netfs_S_dir_lookup (struct protid *diruser,
redo_hash_lookup:
pthread_mutex_lock (&idport_ihash_lock);
pthread_mutex_lock (&dnp->lock);
+ /* The hashtable may not hold a true reference on the node. Acquire the
+ refcount lock so that, if a node is found, its reference counter cannot
+ drop to 0 before we get our own reference. */
+ pthread_spin_lock (&netfs_node_refcnt_lock);
struct netnode *nn = hurd_ihash_find (&idport_ihash, idport);
if (nn != NULL)
{
@@ -359,12 +363,17 @@ netfs_S_dir_lookup (struct protid *diruser,
/* But it might be in the process of being released. If so,
unlock the hash table to give the node a chance to actually
be removed and retry. */
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
pthread_mutex_unlock (&dnp->lock);
pthread_mutex_unlock (&idport_ihash_lock);
goto redo_hash_lookup;
}
+ /* Otherwise, reference it right away. */
np = nn->np;
+ np->references++;
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
+
mach_port_deallocate (mach_task_self (), idport);
if (np == dnp)
@@ -377,12 +386,12 @@ netfs_S_dir_lookup (struct protid *diruser,
pthread_mutex_unlock (&dnp->lock);
}
- netfs_nref (np);
err = check_openmodes (np->nn, (flags & (O_RDWR|O_EXEC)), file);
pthread_mutex_unlock (&idport_ihash_lock);
}
else
{
+ pthread_spin_unlock (&netfs_node_refcnt_lock);
err = new_node (file, idport, 1, flags, &np);
pthread_mutex_unlock (&dnp->lock);
if (!err)
diff --git a/trans/ifsock.c b/trans/ifsock.c
index 092bb40..4ed6589 100644
--- a/trans/ifsock.c
+++ b/trans/ifsock.c
@@ -131,15 +131,15 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
}
error_t
-S_ifsock_getsockaddr (file_t sockfile,
+S_ifsock_getsockaddr (struct trivfs_protid *cred,
mach_port_t *address)
{
- struct trivfs_protid *cred = ports_lookup_port (port_bucket, sockfile,
- node_class);
int perms;
error_t err;
- if (!cred)
+ if (!cred
+ || cred->pi.bucket != port_bucket
+ || cred->pi.class != node_class)
return EOPNOTSUPP;
err = file_check_access (cred->realnode, &perms);
@@ -148,6 +148,5 @@ S_ifsock_getsockaddr (file_t sockfile,
if (!err)
*address = address_port;
- ports_port_deref (cred);
return err;
}
diff --git a/trans/mtab.c b/trans/mtab.c
index 75ef1d3..da83e6f 100644
--- a/trans/mtab.c
+++ b/trans/mtab.c
@@ -36,7 +36,7 @@
#include <unistd.h>
#include <version.h>
-#include "fsys_U.h"
+#include "fs_U.h"
static char *target_path = NULL;
static int insecure = 0;
@@ -421,21 +421,14 @@ mtab_populate (struct mtab *mtab, const char *path, int
insecure)
argz_stringify (options, options_len, ',');
string_t source;
- err = fsys_get_source (node, source);
+ err = file_get_source (node, source);
if (err)
- {
- if (err == EOPNOTSUPP)
- {
- /* Guess based on the last argument. */
- err = map_device_to_path (argv[count - 1], &src);
- if (err)
- goto errout;
- }
- else
- goto errout;
- }
- else
- src = source;
+ goto errout;
+
+ /* Guess based on the last argument. */
+ err = map_device_to_path (source, &src);
+ if (err)
+ goto errout;
entry_len = asprintf (&entry, "%s %s %s %s 0 0\n", src, path, type,
options? options: MNTOPT_DEFAULTS);
@@ -450,7 +443,7 @@ mtab_populate (struct mtab *mtab, const char *path, int
insecure)
goto errout;
/* path has an active translator, query its children. */
- err = fsys_get_children (node, &children, &children_len);
+ err = file_get_children (node, &children, &children_len);
if (err == EOPNOTSUPP)
{
err = 0;
@@ -571,7 +564,7 @@ map_device_to_path (const char *device, char **path)
else if (looks_like_block_device (device))
asprintf (path, "/dev/%s", device);
else
- *path = strdup ("none");
+ *path = strdup (device);
if (! *path)
return ENOMEM;
diff --git a/trans/symlink.c b/trans/symlink.c
index 8562662..845a112 100644
--- a/trans/symlink.c
+++ b/trans/symlink.c
@@ -234,18 +234,3 @@ S_fsys_forward (mach_port_t server, mach_port_t requestor,
{
return EOPNOTSUPP;
}
-
-error_t
-S_fsys_get_children (mach_port_t server,
- char **children,
- mach_msg_type_number_t *children_len)
-{
- return EOPNOTSUPP;
-}
-
-error_t
-S_fsys_get_source (mach_port_t server,
- char *source)
-{
- return EOPNOTSUPP;
-}
diff --git a/utils/Makefile b/utils/Makefile
index 5ebb231..81fa293 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -73,7 +73,7 @@ rpctrace-CPPFLAGS = -DDATADIR=\"${datadir}\"
fakeauth: authServer.o auth_requestUser.o interruptServer.o \
../libports/libports.a ../libihash/libihash.a \
../libshouldbeinlibc/libshouldbeinlibc.a
-auth-MIGSFLAGS = -imacros $(srcdir)/../auth/authmutations.h
+auth-MIGSFLAGS = -imacros $(srcdir)/../auth/mig-mutate.h
fakeauth-CPPFLAGS = -I$(srcdir)/../auth
authServer-CPPFLAGS = -I$(srcdir)/../auth
auth_requestUser-CPPFLAGS = -I$(srcdir)/../auth
diff --git a/utils/fakeauth.c b/utils/fakeauth.c
index 660295f..590a421 100644
--- a/utils/fakeauth.c
+++ b/utils/fakeauth.c
@@ -30,6 +30,8 @@
#include "auth_request_U.h"
#include "interrupt_S.h"
+#include "../auth/auth.h"
+
/* Auth handles are server ports with sets of ids. */
struct authhandle
{
@@ -63,14 +65,6 @@ destroy_authhandle (void *p)
idvec_free_contents (&h->auids);
idvec_free_contents (&h->agids);
}
-
-/* Called by server stub functions. */
-
-authhandle_t
-auth_port_to_handle (auth_t auth)
-{
- return ports_lookup_port (auth_bucket, auth, authhandle_portclass);
-}
/* id management. */
diff --git a/utils/fakeroot.sh b/utils/fakeroot.sh
index a64e963..6993365 100644
--- a/utils/fakeroot.sh
+++ b/utils/fakeroot.sh
@@ -54,16 +54,12 @@ if [ $# -eq 0 ]; then
set -- ${SHELL:-/bin/sh}
fi
-TARGET=
-until [ $# -eq 0 ]; do
- TARGET="${TARGET} '$(echo "$1" | sed -e "s/'/'\\\\''/g")'"
- shift
-done
-
# We exec settrans, which execs the "fakeauth" command in the chroot context.
# The `pwd` is evaluated here and now, and that result interpreted inside
# the shell running under fakeauth to chdir there inside the chroot world.
# That shell then execs our arguments as a command line.
exec /bin/settrans --chroot \
- /bin/fakeauth /bin/sh -c "cd `pwd`; exec ${TARGET}" \
+ /bin/fakeauth \
+ /bin/sh -c 'cd "$1" || exit ; shift ; exec "$@"' \
+ "$1" "$PWD" "$@" \
-- / /hurd/fakeroot
diff --git a/utils/remap.sh b/utils/remap.sh
index 064f0f5..f24ed0e 100644
--- a/utils/remap.sh
+++ b/utils/remap.sh
@@ -57,16 +57,11 @@ if [ $# -eq 0 ]; then
set -- ${SHELL:-/bin/sh}
fi
-TARGET=
-until [ $# -eq 0 ]; do
- TARGET="${TARGET} '$(echo "$1" | sed -e "s/'/'\\\\''/g")'"
- shift
-done
-
# We exec settrans, which execs the "fakeauth" command in the chroot context.
# The `pwd` is evaluated here and now, and that result interpreted inside
# the shell running under fakeauth to chdir there inside the chroot world.
# That shell then execs our arguments as a command line.
exec /bin/settrans --chroot \
- /bin/sh -c "cd `pwd`; exec ${TARGET}" \
+ /bin/sh -c 'cd "$1" || exit ; shift ; exec "$@"' \
+ "$1" "$PWD" "$@" \
-- / /hurd/remap $MAPPED
diff --git a/utils/umount.c b/utils/umount.c
index 26d2b56..7901da6 100644
--- a/utils/umount.c
+++ b/utils/umount.c
@@ -40,7 +40,7 @@ static char *targets;
static size_t targets_len;
static int readonly;
static int verbose;
-static int passive_flags = FS_TRANS_SET;
+static int passive_flags;
static int active_flags = FS_TRANS_SET;
static int goaway_flags;
static int source_goaway;
@@ -139,7 +139,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
return 0;
}
-static const char doc[] = "Stop active and remove passive translators";
+static const char doc[] = "Stop active filesystem translators";
static const char args_doc[] = "DEVICE|DIRECTORY [DEVICE|DIRECTORY ...]";
static struct argp fstab_argp_mtab; /* Slightly modified version. */
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git