Module Name: src
Committed By: christos
Date: Thu Mar 20 03:13:18 UTC 2014
Modified Files:
src/sys/lib/libsa: cd9660.c dosfs.c ext2fs.c ls.c minixfs3.c nfs.c
nullfs.c tftp.c ufs.c ustarfs.c
Log Message:
reduce size by 1K by sharing the ls code.
To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/lib/libsa/cd9660.c
cvs rdiff -u -r1.19 -r1.20 src/sys/lib/libsa/dosfs.c \
src/sys/lib/libsa/ext2fs.c
cvs rdiff -u -r1.4 -r1.5 src/sys/lib/libsa/ls.c
cvs rdiff -u -r1.6 -r1.7 src/sys/lib/libsa/minixfs3.c
cvs rdiff -u -r1.47 -r1.48 src/sys/lib/libsa/nfs.c
cvs rdiff -u -r1.11 -r1.12 src/sys/lib/libsa/nullfs.c
cvs rdiff -u -r1.34 -r1.35 src/sys/lib/libsa/tftp.c \
src/sys/lib/libsa/ustarfs.c
cvs rdiff -u -r1.64 -r1.65 src/sys/lib/libsa/ufs.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/lib/libsa/cd9660.c
diff -u src/sys/lib/libsa/cd9660.c:1.29 src/sys/lib/libsa/cd9660.c:1.30
--- src/sys/lib/libsa/cd9660.c:1.29 Sun Jul 22 20:49:20 2012
+++ src/sys/lib/libsa/cd9660.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: cd9660.c,v 1.29 2012/07/23 00:49:20 mhitch Exp $ */
+/* $NetBSD: cd9660.c,v 1.30 2014/03/20 03:13:18 christos Exp $ */
/*
* Copyright (C) 1996 Wolfgang Solfrank.
@@ -401,10 +401,10 @@ cd9660_stat(struct open_file *f, struct
}
#if defined(LIBSA_ENABLE_LS_OP)
+#include "ls.h"
__compactcall void
cd9660_ls(struct open_file *f, const char *pattern)
{
- printf("Currently ls command is unsupported by cd9660\n");
- return;
+ lsunsup("cd9660");
}
#endif
Index: src/sys/lib/libsa/dosfs.c
diff -u src/sys/lib/libsa/dosfs.c:1.19 src/sys/lib/libsa/dosfs.c:1.20
--- src/sys/lib/libsa/dosfs.c:1.19 Sun Oct 20 13:15:42 2013
+++ src/sys/lib/libsa/dosfs.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: dosfs.c,v 1.19 2013/10/20 17:15:42 christos Exp $ */
+/* $NetBSD: dosfs.c,v 1.20 2014/03/20 03:13:18 christos Exp $ */
/*
* Copyright (c) 1996, 1998 Robert Nordier
@@ -406,11 +406,11 @@ dosfs_stat(struct open_file *fd, struct
}
#if defined(LIBSA_ENABLE_LS_OP)
+#include "ls.h"
__compactcall void
dosfs_ls(struct open_file *f, const char *pattern)
{
- printf("Currently ls command is unsupported by dosfs\n");
- return;
+ lsunsup("dosfs");
}
#endif
Index: src/sys/lib/libsa/ext2fs.c
diff -u src/sys/lib/libsa/ext2fs.c:1.19 src/sys/lib/libsa/ext2fs.c:1.20
--- src/sys/lib/libsa/ext2fs.c:1.19 Sun Oct 20 13:17:30 2013
+++ src/sys/lib/libsa/ext2fs.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ext2fs.c,v 1.19 2013/10/20 17:17:30 christos Exp $ */
+/* $NetBSD: ext2fs.c,v 1.20 2014/03/20 03:13:18 christos Exp $ */
/*
* Copyright (c) 1997 Manuel Bouyer.
@@ -146,30 +146,6 @@ struct file {
daddr_t f_buf_blkno; /* block number of data block */
};
-#if defined(LIBSA_ENABLE_LS_OP)
-
-#define NELEM(x) (sizeof (x) / sizeof(*x))
-
-typedef struct entry_t entry_t;
-struct entry_t {
- entry_t *e_next;
- ino32_t e_ino;
- uint8_t e_type;
- char e_name[1];
-};
-
-static const char *const typestr[] = {
- "unknown",
- "REG",
- "DIR",
- "CHR",
- "BLK",
- "FIFO",
- "SOCK",
- "LNK"
-};
-
-#endif /* LIBSA_ENABLE_LS_OP */
static int read_inode(ino32_t, struct open_file *);
static int block_map(struct open_file *, indp_t, indp_t *);
@@ -828,6 +804,20 @@ ext2fs_stat(struct open_file *f, struct
}
#if defined(LIBSA_ENABLE_LS_OP)
+
+#include "ls.h"
+
+static const char *const typestr[] = {
+ "unknown",
+ "REG",
+ "DIR",
+ "CHR",
+ "BLK",
+ "FIFO",
+ "SOCK",
+ "LNK"
+};
+
__compactcall void
ext2fs_ls(struct open_file *f, const char *pattern)
{
@@ -835,7 +825,7 @@ ext2fs_ls(struct open_file *f, const cha
size_t block_size = fp->f_fs->e2fs_bsize;
char *buf;
size_t buf_size;
- entry_t *names = 0, *n, **np;
+ lsentry_t *names = NULL;
fp->f_seekp = 0;
while (fp->f_seekp < (off_t)fp->f_di.e2di_size) {
@@ -874,47 +864,14 @@ ext2fs_ls(struct open_file *f, const cha
printf("bad dir entry\n");
goto out;
}
- if (pattern && !fnmatch(dp->e2d_name, pattern))
- continue;
- n = alloc(sizeof *n + strlen(dp->e2d_name));
- if (!n) {
- printf("%d: %s (%s)\n",
- fs2h32(dp->e2d_ino), dp->e2d_name, t);
- continue;
- }
- n->e_ino = fs2h32(dp->e2d_ino);
- n->e_type = dp->e2d_type;
- strcpy(n->e_name, dp->e2d_name);
- for (np = &names; *np; np = &(*np)->e_next) {
- if (strcmp(n->e_name, (*np)->e_name) < 0)
- break;
- }
- n->e_next = *np;
- *np = n;
+ lsadd(&names, pattern, dp->e2d_name,
+ strlen(dp->e2d_name), fs2h32(dp->e2d_ino), t);
}
fp->f_seekp += buf_size;
}
- if (names) {
- entry_t *p_names = names;
- do {
- n = p_names;
- printf("%d: %s (%s)\n",
- n->e_ino, n->e_name, typestr[n->e_type]);
- p_names = n->e_next;
- } while (p_names);
- } else {
- printf("not found\n");
- }
-out:
- if (names) {
- do {
- n = names;
- names = n->e_next;
- dealloc(n, 0);
- } while (names);
- }
- return;
+ lsprint(names);
+out: lsfree(names);
}
#endif
Index: src/sys/lib/libsa/ls.c
diff -u src/sys/lib/libsa/ls.c:1.4 src/sys/lib/libsa/ls.c:1.5
--- src/sys/lib/libsa/ls.c:1.4 Fri Mar 2 07:08:44 2012
+++ src/sys/lib/libsa/ls.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ls.c,v 1.4 2012/03/02 12:08:44 tsutsui Exp $ */
+/* $NetBSD: ls.c,v 1.5 2014/03/20 03:13:18 christos Exp $ */
/*-
* Copyright (c) 2011
@@ -85,6 +85,7 @@
#include "stand.h"
+#include "ls.h"
#include <sys/stat.h>
#include <lib/libkern/libkern.h>
@@ -160,3 +161,67 @@ ls(const char *path)
out:
close(fd);
}
+
+struct lsentry {
+ struct lsentry *e_next;
+ uint32_t e_ino;
+ const char *e_type;
+ char e_name[1];
+};
+
+__compactcall void
+lsadd(lsentry_t **names, const char *pattern, const char *name, size_t namelen,
+ uint32_t ino, const char *type)
+{
+ lsentry_t *n, **np;
+
+ if (pattern && !fnmatch(name, pattern))
+ return;
+
+ n = alloc(sizeof *n + namelen);
+ if (!n) {
+ printf("%d: %.*s (%s)\n", ino, (int)namelen, name, type);
+ return;
+ }
+
+ n->e_ino = ino;
+ n->e_type = type;
+ memcpy(n->e_name, name, namelen);
+ n->e_name[namelen] = '\0';
+
+ for (np = names; *np; np = &(*np)->e_next) {
+ if (strcmp(n->e_name, (*np)->e_name) < 0)
+ break;
+ }
+ n->e_next = *np;
+ *np = n;
+}
+
+__compactcall void
+lsprint(lsentry_t *names) {
+ if (!names) {
+ printf("not found\n");
+ return;
+ }
+ do {
+ lsentry_t *n = names;
+ printf("%d: %s (%s)\n", n->e_ino, n->e_name, n->e_type);
+ names = n->e_next;
+ } while (names);
+}
+
+__compactcall void
+lsfree(lsentry_t *names) {
+ if (!names)
+ return;
+ do {
+ lsentry_t *n = names;
+ names = n->e_next;
+ dealloc(n, 0);
+ } while (names);
+}
+
+__compactcall void
+lsunsup(const char *name) {
+ printf("The ls command is not currently supported for %s\n", name);
+}
Index: src/sys/lib/libsa/minixfs3.c
diff -u src/sys/lib/libsa/minixfs3.c:1.6 src/sys/lib/libsa/minixfs3.c:1.7
--- src/sys/lib/libsa/minixfs3.c:1.6 Sat Nov 2 20:44:34 2013
+++ src/sys/lib/libsa/minixfs3.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: minixfs3.c,v 1.6 2013/11/03 00:44:34 christos Exp $ */
+/* $NetBSD: minixfs3.c,v 1.7 2014/03/20 03:13:18 christos Exp $ */
/*-
* Copyright (c) 2012
@@ -169,20 +169,6 @@ struct file {
daddr_t f_buf_blkno; /* block number of data block */
};
-#if defined(LIBSA_ENABLE_LS_OP)
-
-#define NELEM(x) (sizeof (x) / sizeof(*x))
-
-typedef struct entry_t entry_t;
-struct entry_t {
- entry_t *e_next;
- ino32_t e_ino;
- char e_name[1];
-};
-
-#endif /* LIBSA_ENABLE_LS_OP */
-
-
static int read_inode(ino32_t, struct open_file *);
static int block_map(struct open_file *, block_t, block_t *);
static int buf_read_file(struct open_file *, void *, size_t *);
@@ -833,6 +819,7 @@ minixfs3_stat(struct open_file *f, struc
}
#if defined(LIBSA_ENABLE_LS_OP)
+#include "ls.h"
__compactcall void
minixfs3_ls(struct open_file *f, const char *pattern)
{
@@ -841,7 +828,7 @@ minixfs3_ls(struct open_file *f, const c
struct mfs_direct *dp;
struct mfs_direct *dbuf;
size_t buf_size;
- entry_t *names = 0, *n, **np;
+ lsentry_t *names = 0;
fp->f_seekp = 0;
while (fp->f_seekp < (off_t)fp->f_di.mdi_size) {
@@ -864,9 +851,6 @@ minixfs3_ls(struct open_file *f, const c
if (fs2h32(dp->mfsd_ino) == 0)
continue;
- if (pattern && !fnmatch(dp->mfsd_name, pattern))
- continue;
-
/* Compute the length of the name,
* We don't use strlen and strcpy, because original MFS
* code doesn't.
@@ -877,45 +861,13 @@ minixfs3_ls(struct open_file *f, const c
else
namlen = cp - (dp->mfsd_name);
- n = alloc(sizeof *n + namlen);
- if (!n) {
- printf("%d: %s\n",
- fs2h32(dp->mfsd_ino), dp->mfsd_name);
- continue;
- }
- n->e_ino = fs2h32(dp->mfsd_ino);
- strncpy(n->e_name, dp->mfsd_name, namlen);
- n->e_name[namlen] = '\0';
- for (np = &names; *np; np = &(*np)->e_next) {
- if (strcmp(n->e_name, (*np)->e_name) < 0)
- break;
- }
- n->e_next = *np;
- *np = n;
+ lsadd(&names, pattern, dp->mfsd_name, namlen,
+ fs2h32(dp->mfsd_ino), "?");
}
fp->f_seekp += buf_size;
}
-
- if (names) {
- entry_t *p_names = names;
- do {
- n = p_names;
- printf("%d: %s\n",
- n->e_ino, n->e_name);
- p_names = n->e_next;
- } while (p_names);
- } else {
- printf("not found\n");
- }
-out:
- if (names) {
- do {
- n = names;
- names = n->e_next;
- dealloc(n, 0);
- } while (names);
- }
- return;
+ lsprint(names);
+out: lsfree(names);
}
#endif
Index: src/sys/lib/libsa/nfs.c
diff -u src/sys/lib/libsa/nfs.c:1.47 src/sys/lib/libsa/nfs.c:1.48
--- src/sys/lib/libsa/nfs.c:1.47 Sun Dec 25 01:09:08 2011
+++ src/sys/lib/libsa/nfs.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs.c,v 1.47 2011/12/25 06:09:08 tsutsui Exp $ */
+/* $NetBSD: nfs.c,v 1.48 2014/03/20 03:13:18 christos Exp $ */
/*-
* Copyright (c) 1993 John Brezak
@@ -657,10 +657,10 @@ nfs_stat(struct open_file *f, struct sta
}
#if defined(LIBSA_ENABLE_LS_OP)
+#include "ls.h"
__compactcall void
nfs_ls(struct open_file *f, const char *pattern)
{
- printf("Currently ls command is unsupported by nfs\n");
- return;
+ lsunsup("nfs");
}
#endif
Index: src/sys/lib/libsa/nullfs.c
diff -u src/sys/lib/libsa/nullfs.c:1.11 src/sys/lib/libsa/nullfs.c:1.12
--- src/sys/lib/libsa/nullfs.c:1.11 Sun Dec 25 01:09:08 2011
+++ src/sys/lib/libsa/nullfs.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: nullfs.c,v 1.11 2011/12/25 06:09:08 tsutsui Exp $ */
+/* $NetBSD: nullfs.c,v 1.12 2014/03/20 03:13:18 christos Exp $ */
/*-
* Copyright (c) 1993
@@ -115,10 +115,10 @@ null_stat(struct open_file *f, struct st
}
#if defined(LIBSA_ENABLE_LS_OP)
+#include "ls.h"
__compactcall void
null_ls(struct open_file *f, const char *pattern)
{
- printf("Currently ls command is unsupported by nullfs\n");
- return;
+ lsunsup("nullfs");
}
#endif
Index: src/sys/lib/libsa/tftp.c
diff -u src/sys/lib/libsa/tftp.c:1.34 src/sys/lib/libsa/tftp.c:1.35
--- src/sys/lib/libsa/tftp.c:1.34 Sun Dec 25 01:09:08 2011
+++ src/sys/lib/libsa/tftp.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: tftp.c,v 1.34 2011/12/25 06:09:08 tsutsui Exp $ */
+/* $NetBSD: tftp.c,v 1.35 2014/03/20 03:13:18 christos Exp $ */
/*
* Copyright (c) 1996
@@ -430,11 +430,11 @@ tftp_stat(struct open_file *f, struct st
}
#if defined(LIBSA_ENABLE_LS_OP)
+#include "ls.h"
__compactcall void
tftp_ls(struct open_file *f, const char *pattern)
{
- printf("Currently ls command is unsupported by tftp\n");
- return;
+ lsunsup("tftp");
}
#endif
Index: src/sys/lib/libsa/ustarfs.c
diff -u src/sys/lib/libsa/ustarfs.c:1.34 src/sys/lib/libsa/ustarfs.c:1.35
--- src/sys/lib/libsa/ustarfs.c:1.34 Sun Dec 25 01:09:08 2011
+++ src/sys/lib/libsa/ustarfs.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ustarfs.c,v 1.34 2011/12/25 06:09:08 tsutsui Exp $ */
+/* $NetBSD: ustarfs.c,v 1.35 2014/03/20 03:13:18 christos Exp $ */
/* [Notice revision 2.2]
* Copyright (c) 1997, 1998 Avalon Computer Systems, Inc.
@@ -539,10 +539,11 @@ ustarfs_stat(struct open_file *f, struct
#if defined(LIBSA_ENABLE_LS_OP)
+#include "ls.h"
__compactcall void
ustarfs_ls(struct open_file *f, const char *pattern)
{
- printf("Currently ls command is unsupported by ustarfs\n");
+ lsunsup("ustarfs");
return;
}
#endif
Index: src/sys/lib/libsa/ufs.c
diff -u src/sys/lib/libsa/ufs.c:1.64 src/sys/lib/libsa/ufs.c:1.65
--- src/sys/lib/libsa/ufs.c:1.64 Sun Oct 20 13:17:30 2013
+++ src/sys/lib/libsa/ufs.c Wed Mar 19 23:13:18 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs.c,v 1.64 2013/10/20 17:17:30 christos Exp $ */
+/* $NetBSD: ufs.c,v 1.65 2014/03/20 03:13:18 christos Exp $ */
/*-
* Copyright (c) 1993
@@ -189,36 +189,6 @@ static void ffs_oldfscompat(struct fs *)
static int ffs_find_superblock(struct open_file *, struct fs *);
#endif
-#if defined(LIBSA_ENABLE_LS_OP)
-
-#define NELEM(x) (sizeof (x) / sizeof(*x))
-
-typedef struct entry_t entry_t;
-struct entry_t {
- entry_t *e_next;
- ino32_t e_ino;
- uint8_t e_type;
- char e_name[1];
-};
-
-static const char *const typestr[] = {
- "unknown",
- "FIFO",
- "CHR",
- 0,
- "DIR",
- 0,
- "BLK",
- 0,
- "REG",
- 0,
- "LNK",
- 0,
- "SOCK",
- 0,
- "WHT"
-};
-#endif /* LIBSA_ENABLE_LS_OP */
#ifdef LIBSA_LFS
/*
@@ -890,13 +860,34 @@ ufs_stat(struct open_file *f, struct sta
}
#if defined(LIBSA_ENABLE_LS_OP)
+
+#include "ls.h"
+
+static const char *const typestr[] = {
+ "unknown",
+ "FIFO",
+ "CHR",
+ 0,
+ "DIR",
+ 0,
+ "BLK",
+ 0,
+ "REG",
+ 0,
+ "LNK",
+ 0,
+ "SOCK",
+ 0,
+ "WHT"
+};
+
__compactcall void
ufs_ls(struct open_file *f, const char *pattern)
{
struct file *fp = (struct file *)f->f_fsdata;
char *buf;
size_t buf_size;
- entry_t *names = 0, *n, **np;
+ lsentry_t *names = NULL;
fp->f_seekp = 0;
while (fp->f_seekp < (off_t)fp->f_di.di_size) {
@@ -931,46 +922,13 @@ ufs_ls(struct open_file *f, const char *
printf("bad dir entry\n");
goto out;
}
- if (pattern && !fnmatch(dp->d_name, pattern))
- continue;
- n = alloc(sizeof *n + strlen(dp->d_name));
- if (!n) {
- printf("%d: %s (%s)\n",
- dp->d_ino, dp->d_name, t);
- continue;
- }
- n->e_ino = dp->d_ino;
- n->e_type = dp->d_type;
- strcpy(n->e_name, dp->d_name);
- for (np = &names; *np; np = &(*np)->e_next) {
- if (strcmp(n->e_name, (*np)->e_name) < 0)
- break;
- }
- n->e_next = *np;
- *np = n;
+ lsadd(&names, pattern, dp->d_name, strlen(dp->d_name),
+ dp->d_ino, t);
}
fp->f_seekp += buf_size;
}
-
- if (names) {
- entry_t *p_names = names;
- do {
- n = p_names;
- printf("%d: %s (%s)\n",
- n->e_ino, n->e_name, typestr[n->e_type]);
- p_names = n->e_next;
- } while (p_names);
- } else {
- printf("not found\n");
- }
-out:
- if (names) {
- do {
- n = names;
- names = n->e_next;
- dealloc(n, 0);
- } while (names);
- }
+ lsprint(names);
+out: lsfree(names);
}
#endif /* LIBSA_ENABLE_LS_OP */