summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2013-08-08 03:16:15 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2013-08-08 03:16:15 +0000
commit3c4293cd3c0d7409e63fd2f879d9c9780d409376 (patch)
treedd81d16e1d216156e2249b82563ecea26f121b50
parent5691fda083ff85fb8c581329e5da7414269ed7b8 (diff)
Prep for big ino_t: cast to unsigned long long and format with %ll or %q
httpd correction and ok kettenis@
-rw-r--r--gnu/usr.bin/cvs/src/hardlink.c239
-rw-r--r--gnu/usr.sbin/mkhybrid/src/tree.c4
-rw-r--r--lib/libfuse/fuse_ops.c25
-rw-r--r--usr.sbin/httpd/src/main/http_protocol.c6
-rw-r--r--usr.sbin/lpr/lpr/lpr.c6
5 files changed, 144 insertions, 136 deletions
diff --git a/gnu/usr.bin/cvs/src/hardlink.c b/gnu/usr.bin/cvs/src/hardlink.c
index 51bd2a60567..245ce3d2e29 100644
--- a/gnu/usr.bin/cvs/src/hardlink.c
+++ b/gnu/usr.bin/cvs/src/hardlink.c
@@ -41,96 +41,6 @@ List *hardlist; /* Record hardlink information for working files */
char *working_dir; /* The top-level working directory, used for
constructing full pathnames. */
-/* For check_link_proc: list all of the files named in an inode list. */
-static int
-list_files_proc (node, vstrp)
- Node *node;
- void *vstrp;
-{
- char **strp, *file;
- int len;
-
- /* Get the file's basename. This is because -- VERY IMPORTANT --
- the `hardlinks' field is presently defined only to include links
- within a directory. So the hardlinks field might be `foo' or
- `mumble grump flink', but not `foo bar com/baz' or `wham ../bam
- ../thank/you'. Someday it would be nice to extend this to
- permit cross-directory links, but the issues involved are
- hideous. */
-
- file = strrchr (node->key, '/');
- if (file)
- ++file;
- else
- file = node->key;
-
- /* Is it safe to cast vstrp to (char **) here, and then play with
- the contents? I think so, since vstrp will have started out
- a char ** to begin with, so we should not have alignment bugs. */
- strp = (char **) vstrp;
- len = (*strp == NULL ? 0 : strlen (*strp));
- *strp = (char *) xrealloc (*strp, len + strlen (file) + 2);
- if (*strp == NULL)
- {
- error (0, errno, "could not allocate memory");
- return 1;
- }
- if (sprintf (*strp + len, "%s ", file) < 0)
- {
- error (0, errno, "could not compile file list");
- return 1;
- }
-
- return 0;
-}
-
-/* Set the link field of each hardlink_info node to `data', which is a
- list of linked files. */
-static int
-set_hardlink_field_proc (node, data)
- Node *node;
- void *data;
-{
- struct hardlink_info *hlinfo = (struct hardlink_info *) node->data;
- hlinfo->links = xstrdup ((char *) data);
-
- return 0;
-}
-
-/* For each file being checked in, compile a list of the files linked
- to it, and cache the list in the file's hardlink_info field. */
-int
-cache_hardlinks_proc (node, data)
- Node *node;
- void *data;
-{
- List *inode_links;
- char *p, *linked_files = NULL;
- int err;
-
- inode_links = (List *) node->data;
-
- /* inode->data is a list of hardlink_info structures: all the
- files linked to this inode. We compile a string of each file
- named in this list, in alphabetical order, separated by spaces.
- Then store this string in the `links' field of each
- hardlink_info structure, so that RCS_checkin can easily add
- it to the `hardlinks' field of a new delta node. */
-
- sortlist (inode_links, fsortcmp);
- err = walklist (inode_links, list_files_proc, &linked_files);
- if (err)
- return err;
-
- /* Trim trailing whitespace. */
- p = linked_files + strlen(linked_files) - 1;
- while (p > linked_files && isspace (*p))
- *p-- = '\0';
-
- err = walklist (inode_links, set_hardlink_field_proc, linked_files);
- return err;
-}
-
/* Return a pointer to FILEPATH's node in the hardlist. This means
looking up its inode, retrieving the list of files linked to that
inode, and then looking up FILE in that list. If the file doesn't
@@ -153,10 +63,10 @@ lookup_file_by_inode (filepath)
/* inodestr contains the hexadecimal representation of an
inode, so it requires two bytes of text to represent
each byte of the inode number. */
- inodestr = (char *) xmalloc (2*sizeof(ino_t)*sizeof(char) + 1);
+ inodestr = (char *) xmalloc (2*sizeof(ino_t) + 1);
if (stat (file, &sb) < 0)
{
- if (errno == ENOENT)
+ if (existence_error (errno))
{
/* The file doesn't exist; we may be doing an update on a
file that's been removed. A nonexistent file has no
@@ -167,7 +77,7 @@ lookup_file_by_inode (filepath)
error (1, errno, "cannot stat %s", file);
}
- sprintf (inodestr, "%lx", (unsigned long) sb.st_ino);
+ sprintf (inodestr, "%llx", (unsigned long long) sb.st_ino);
/* Find out if this inode is already in the hardlist, adding
a new entry to the list if not. */
@@ -175,7 +85,7 @@ lookup_file_by_inode (filepath)
if (hp == NULL)
{
hp = getnode ();
- hp->type = UNKNOWN;
+ hp->type = NT_UNKNOWN;
hp->key = inodestr;
hp->data = (char *) getlist();
hp->delproc = dellist;
@@ -190,7 +100,7 @@ lookup_file_by_inode (filepath)
if (p == NULL)
{
p = getnode();
- p->type = UNKNOWN;
+ p->type = NT_UNKNOWN;
p->key = xstrdup (filepath);
p->data = NULL;
(void) addnode ((List *) hp->data, p);
@@ -218,7 +128,7 @@ update_hardlink_info (file)
/* file is a relative pathname; assume it's from the current
working directory. */
char *dir = xgetwd();
- path = xmalloc (sizeof(char) * (strlen(dir) + strlen(file) + 2));
+ path = xmalloc (strlen(dir) + strlen(file) + 2);
sprintf (path, "%s/%s", dir, file);
free (dir);
}
@@ -237,26 +147,28 @@ update_hardlink_info (file)
hlinfo = (struct hardlink_info *) n->data;
hlinfo->status = T_UPTODATE;
hlinfo->checked_out = 1;
- hlinfo->links = NULL;
}
-/* Return a string listing all the files known to be linked to FILE in
+/* Return a List with all the files known to be linked to FILE in
the working directory. Used by special_file_mismatch, to determine
- whether it is safe to merge two files. */
-char *
-list_files_linked_to (file)
- const char *file;
+ whether it is safe to merge two files.
+
+ FIXME: What is the memory allocation for the return value? We seem
+ to sometimes allocate a new list (getlist() call below) and sometimes
+ return an existing list (where we return n->data). */
+List *
+list_linked_files_on_disk (file)
+ char *file;
{
- char *inodestr, *filelist, *path;
+ char *inodestr, *path;
struct stat sb;
Node *n;
- int err;
/* If hardlist is NULL, we have not been doing an operation that
would permit us to know anything about the file's hardlinks
- (cvs update, cvs commit, etc). Return an empty string. */
+ (cvs update, cvs commit, etc). Return an empty list. */
if (hardlist == NULL)
- return xstrdup ("");
+ return getlist();
/* Get the full pathname of file (assuming the working directory) */
if (file[0] == '/')
@@ -264,8 +176,7 @@ list_files_linked_to (file)
else
{
char *dir = xgetwd();
- path = (char *) xmalloc (sizeof(char) *
- (strlen(dir) + strlen(file) + 2));
+ path = (char *) xmalloc (strlen(dir) + strlen(file) + 2);
sprintf (path, "%s/%s", dir, file);
free (dir);
}
@@ -281,18 +192,114 @@ list_files_linked_to (file)
/* inodestr contains the hexadecimal representation of an
inode, so it requires two bytes of text to represent
each byte of the inode number. */
- inodestr = (char *) xmalloc (2*sizeof(ino_t)*sizeof(char) + 1);
- sprintf (inodestr, "%lx", (unsigned long) sb.st_ino);
+ inodestr = (char *) xmalloc (2*sizeof(ino_t) + 1);
+ sprintf (inodestr, "%llx", (unsigned long long) sb.st_ino);
/* Make sure the files linked to this inode are sorted. */
n = findnode (hardlist, inodestr);
sortlist ((List *) n->data, fsortcmp);
- filelist = NULL;
- err = walklist ((List *) n->data, list_files_proc, &filelist);
- if (err)
- error (1, 0, "cannot get list of hardlinks for %s", file);
-
free (inodestr);
- return filelist;
+ return (List *) n->data;
}
+
+/* Compare the files in the `key' fields of two lists, returning 1 if
+ the lists are equivalent and 0 otherwise.
+
+ Only the basenames of each file are compared. This is an awful hack
+ that exists because list_linked_files_on_disk returns full paths
+ and the `hardlinks' structure of a RCSVers node contains only
+ basenames. That in turn is a result of the awful hack that only
+ basenames are stored in the RCS file. If anyone ever solves the
+ problem of correctly managing cross-directory hardlinks, this
+ function (along with most functions in this file) must be fixed. */
+
+int
+compare_linkage_lists (links1, links2)
+ List *links1;
+ List *links2;
+{
+ Node *n1, *n2;
+ char *p1, *p2;
+
+ sortlist (links1, fsortcmp);
+ sortlist (links2, fsortcmp);
+
+ n1 = links1->list->next;
+ n2 = links2->list->next;
+
+ while (n1 != links1->list && n2 != links2->list)
+ {
+ /* Get the basenames of both files. */
+ p1 = strrchr (n1->key, '/');
+ if (p1 == NULL)
+ p1 = n1->key;
+ else
+ ++p1;
+
+ p2 = strrchr (n2->key, '/');
+ if (p2 == NULL)
+ p2 = n2->key;
+ else
+ ++p2;
+
+ /* Compare the files' basenames. */
+ if (strcmp (p1, p2) != 0)
+ return 0;
+
+ n1 = n1->next;
+ n2 = n2->next;
+ }
+
+ /* At this point we should be at the end of both lists; if not,
+ one file has more links than the other, and return 1. */
+ return (n1 == links1->list && n2 == links2->list);
+}
+
+/* Find a checked-out file in a list of filenames. Used by RCS_checkout
+ when checking out a new hardlinked file, to decide whether this file
+ can be linked to any others that already exist. The return value
+ is not currently used. */
+
+int
+find_checkedout_proc (node, data)
+ Node *node;
+ void *data;
+{
+ Node **uptodate = (Node **) data;
+ Node *link;
+ char *dir = xgetwd();
+ char *path;
+ struct hardlink_info *hlinfo;
+
+ /* If we have already found a file, don't do anything. */
+ if (*uptodate != NULL)
+ return 0;
+
+ /* Look at this file in the hardlist and see whether the checked_out
+ field is 1, meaning that it has been checked out during this CVS run. */
+ path = (char *)
+ xmalloc (strlen (dir) + strlen (node->key) + 2);
+ sprintf (path, "%s/%s", dir, node->key);
+ link = lookup_file_by_inode (path);
+ free (path);
+ free (dir);
+
+ if (link == NULL)
+ {
+ /* We haven't seen this file -- maybe it hasn't been checked
+ out yet at all. */
+ return 0;
+ }
+
+ hlinfo = (struct hardlink_info *) link->data;
+ if (hlinfo->checked_out)
+ {
+ /* This file has been checked out recently, so it's safe to
+ link to it. */
+ *uptodate = link;
+ }
+
+ return 0;
+}
+
diff --git a/gnu/usr.sbin/mkhybrid/src/tree.c b/gnu/usr.sbin/mkhybrid/src/tree.c
index 39882c344a1..071bbdb405b 100644
--- a/gnu/usr.sbin/mkhybrid/src/tree.c
+++ b/gnu/usr.sbin/mkhybrid/src/tree.c
@@ -1184,9 +1184,9 @@ FDECL3(insert_file_entry,struct directory *, this_dir,
/* NON-HFS change - print just a warning *if* this ever happens */
fprintf(stderr,"Warning: Directory loop (%s)\n", whole_path);
#else
- fprintf(stderr,"Directory loop - fatal goof (%s %lx %lu).\n",
+ fprintf(stderr,"Directory loop - fatal goof (%s %lx %llu).\n",
whole_path, (unsigned long) statbuf.st_dev,
- (unsigned long) STAT_INODE(statbuf));
+ (unsigned long long) STAT_INODE(statbuf));
exit(1);
#endif
}
diff --git a/lib/libfuse/fuse_ops.c b/lib/libfuse/fuse_ops.c
index 7b7dd1c0b0a..868994b1392 100644
--- a/lib/libfuse/fuse_ops.c
+++ b/lib/libfuse/fuse_ops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fuse_ops.c,v 1.5 2013/06/14 20:56:11 syl Exp $ */
+/* $OpenBSD: fuse_ops.c,v 1.6 2013/08/08 03:16:13 guenther Exp $ */
/*
* Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
@@ -23,7 +23,8 @@
#include "debug.h"
#define CHECK_OPT(opname) DPRINTF("Opcode:\t%s\n", #opname); \
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino); \
+ DPRINTF("Inode:\t%llu\n", \
+ (unsigned long long)fbuf->fb_ino); \
if (!f->op.opname) { \
fbuf->fb_err = -ENOSYS; \
fbuf->fb_len = 0; \
@@ -102,7 +103,7 @@ ifuse_ops_getattr(struct fuse *f, struct fusebuf *fbuf)
char *realname;
DPRINTF("Opcode:\tgetattr\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
bzero(&st, sizeof(st));
fbuf->fb_len = FUSEFDSIZE;
@@ -149,7 +150,7 @@ ifuse_ops_open(struct fuse *f, struct fusebuf *fbuf)
char *realname;
DPRINTF("Opcode:\topen\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
CHECK_OPT(open);
@@ -179,7 +180,7 @@ ifuse_ops_opendir(struct fuse *f, struct fusebuf *fbuf)
char *realname;
DPRINTF("Opcode:\topendir\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
memset(&ffi, 0, sizeof(ffi));
ffi.flags = fbuf->fb_io_flags;
@@ -291,7 +292,7 @@ ifuse_ops_readdir(struct fuse *f, struct fusebuf *fbuf)
uint32_t startsave;
DPRINTF("Opcode:\treaddir\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
DPRINTF("Offset:\t%llu\n", fbuf->fb_io_off);
DPRINTF("Size:\t%lu\n", fbuf->fb_io_len);
@@ -350,7 +351,7 @@ ifuse_ops_releasedir(struct fuse *f, struct fusebuf *fbuf)
char *realname;
DPRINTF("Opcode:\treleasedir\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
bzero(&ffi, sizeof(ffi));
ffi.fh = fbuf->fb_io_fd;
@@ -408,7 +409,7 @@ ifuse_ops_lookup(struct fuse *f, struct fusebuf *fbuf)
char *realname;
DPRINTF("Opcode:\tlookup\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
DPRINTF("For file %s\n", fbuf->fb_dat);
vn = get_vn_by_name_and_parent(f, fbuf->fb_dat, fbuf->fb_ino);
@@ -423,7 +424,7 @@ ifuse_ops_lookup(struct fuse *f, struct fusebuf *fbuf)
set_vn(f, vn); /*XXX*/
}
- DPRINTF("new ino %i\n", vn->ino);
+ DPRINTF("new ino %llu\n", (unsigned long long)vn->ino);
fbuf->fb_len = FUSEFDSIZE;
realname = build_realname(f, vn->ino);
@@ -607,7 +608,7 @@ ifuse_ops_readlink(struct fuse *f, struct fusebuf *fbuf)
int len, ret;
DPRINTF("Opcode:\treadlink\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
vn = tree_get(&f->vnode_tree, fbuf->fb_ino);
@@ -716,7 +717,7 @@ ifuse_ops_setattr(struct fuse *f, struct fusebuf *fbuf)
gid_t gid;
DPRINTF("Opcode:\tsetattr\n");
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
vn = tree_get(&f->vnode_tree, fbuf->fb_ino);
realname = build_realname(f, vn->ino);
@@ -911,7 +912,7 @@ ifuse_exec_opcode(struct fuse *f, struct fusebuf *fbuf)
break;
default:
DPRINTF("Opcode:\t%i not supported\n", fbuf->fb_type);
- DPRINTF("Inode:\t%i\n", fbuf->fb_ino);
+ DPRINTF("Inode:\t%llu\n", (unsigned long long)fbuf->fb_ino);
fbuf->fb_err = -ENOSYS;
fbuf->fb_len = 0;
diff --git a/usr.sbin/httpd/src/main/http_protocol.c b/usr.sbin/httpd/src/main/http_protocol.c
index 2ddd8c997a5..e26c60ab883 100644
--- a/usr.sbin/httpd/src/main/http_protocol.c
+++ b/usr.sbin/httpd/src/main/http_protocol.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: http_protocol.c,v 1.37 2010/02/25 07:49:53 pyr Exp $ */
+/* $OpenBSD: http_protocol.c,v 1.38 2013/08/08 03:16:13 guenther Exp $ */
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -681,8 +681,8 @@ API_EXPORT(char *) ap_make_etag_orig(request_rec *r, int force_weak)
components = ap_make_array(r->pool, 4, sizeof(char *));
if (etag_bits & ETAG_INODE) {
ent = (char **) ap_push_array(components);
- *ent = ap_psprintf(r->pool, "%lx",
- (unsigned long) r->finfo.st_ino);
+ *ent = ap_psprintf(r->pool, "%qx",
+ (unsigned long long) r->finfo.st_ino);
}
if (etag_bits & ETAG_SIZE) {
ent = (char **) ap_push_array(components);
diff --git a/usr.sbin/lpr/lpr/lpr.c b/usr.sbin/lpr/lpr/lpr.c
index 8533853dbee..d8f31192fe2 100644
--- a/usr.sbin/lpr/lpr/lpr.c
+++ b/usr.sbin/lpr/lpr/lpr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpr.c,v 1.43 2013/02/15 08:28:08 mpi Exp $ */
+/* $OpenBSD: lpr.c,v 1.44 2013/08/08 03:16:14 guenther Exp $ */
/* $NetBSD: lpr.c,v 1.19 2000/10/11 20:23:52 is Exp $ */
/*
@@ -328,8 +328,8 @@ main(int argc, char **argv)
continue; /* file unreasonable */
if (sflag && (cp = linked(arg)) != NULL) {
- (void)snprintf(buf, sizeof(buf), "%d %d",
- statb.st_dev, statb.st_ino);
+ (void)snprintf(buf, sizeof(buf), "%d %llu",
+ statb.st_dev, (unsigned long long)statb.st_ino);
card('S', buf);
if (format == 'p')
card('T', title ? title : arg);