2010-02-01 Chris Johns <chrisj@rtems.org>

* libmisc/shell/fts.c: Updated to the latest NetBSD version to
        resolve heap allocation bugs.
        * libmisc/shell/main_ls.c, libmisc/shell/print-ls.c: Fix printing
        size bugs.
        * libnetworking/rtems/mkrootfs.c: Fix byte order bug when creating
        the loopback interface address.
This commit is contained in:
Chris Johns
2010-02-01 00:03:02 +00:00
parent 1027f1534b
commit 42c4de823f
5 changed files with 177 additions and 127 deletions

View File

@@ -1,3 +1,12 @@
2010-02-01 Chris Johns <chrisj@rtems.org>
* libmisc/shell/fts.c: Updated to the latest NetBSD version to
resolve heap allocation bugs.
* libmisc/shell/main_ls.c, libmisc/shell/print-ls.c: Fix printing
size bugs.
* libnetworking/rtems/mkrootfs.c: Fix byte order bug when creating
the loopback interface address.
2010-01-28 Sebastian Huber <sebastian.huber@embedded-brains.de> 2010-01-28 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libblock/src/bdbuf.c: Fixed invalid chain extract. * libblock/src/bdbuf.c: Fixed invalid chain extract.

View File

@@ -1,4 +1,4 @@
/* $NetBSD: fts.c,v 1.26 2005/10/22 20:55:13 christos Exp $ */ /* $NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $ */
/*- /*-
* Copyright (c) 1990, 1993, 1994 * Copyright (c) 1990, 1993, 1994
@@ -29,10 +29,6 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if HAVE_NBTOOL_CONFIG_H #if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h" #include "nbtool_config.h"
#endif #endif
@@ -42,10 +38,13 @@
#if 0 #if 0
static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
#else #else
__RCSID("$NetBSD: fts.c,v 1.26 2005/10/22 20:55:13 christos Exp $"); __RCSID("$NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $");
#endif #endif
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#ifndef __rtems__
#include "namespace.h"
#endif
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -63,21 +62,28 @@ __RCSID("$NetBSD: fts.c,v 1.26 2005/10/22 20:55:13 christos Exp $");
#define dirfd(dp) __dirfd(dp) #define dirfd(dp) __dirfd(dp)
#if ! HAVE_NBTOOL_CONFIG_H #if ! HAVE_NBTOOL_CONFIG_H
#define HAVE_STRUCT_DIRENT_D_NAMLEN 1 #define HAVE_STRUCT_DIRENT_D_NAMLEN
#endif #endif
static FTSENT *fts_alloc __P((FTS *, const char *, size_t)); static FTSENT *fts_alloc(FTS *, const char *, size_t);
static FTSENT *fts_build __P((FTS *, int)); static FTSENT *fts_build(FTS *, int);
static void fts_lfree __P((FTSENT *)); static void fts_free(FTSENT *);
static void fts_load __P((FTS *, FTSENT *)); static void fts_lfree(FTSENT *);
static size_t fts_maxarglen __P((char * const *)); static void fts_load(FTS *, FTSENT *);
static size_t fts_pow2 __P((size_t)); static size_t fts_maxarglen(char * const *);
static int fts_palloc __P((FTS *, size_t)); static size_t fts_pow2(size_t);
static void fts_padjust __P((FTS *, FTSENT *)); static int fts_palloc(FTS *, size_t);
static FTSENT *fts_sort __P((FTS *, FTSENT *, size_t)); static void fts_padjust(FTS *, FTSENT *);
static u_short fts_stat __P((FTS *, FTSENT *, int)); static FTSENT *fts_sort(FTS *, FTSENT *, size_t);
static int fts_safe_changedir __P((const FTS *, const FTSENT *, int, static unsigned short fts_stat(FTS *, FTSENT *, int);
const char *)); static int fts_safe_changedir(const FTS *, const FTSENT *, int,
const char *);
#if defined(ALIGNBYTES) && defined(ALIGN)
#define FTS_ALLOC_ALIGNED 1
#else
#undef FTS_ALLOC_ALIGNED
#endif
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) #define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
@@ -98,10 +104,8 @@ static int fts_safe_changedir __P((const FTS *, const FTSENT *, int,
#endif #endif
FTS * FTS *
fts_open( fts_open(char * const *argv, int options,
char * const *argv, int (*compar)(const FTSENT **, const FTSENT **))
int options,
int (*compar) (const FTSENT **, const FTSENT **) )
{ {
FTS *sp; FTS *sp;
FTSENT *p, *root; FTSENT *p, *root;
@@ -118,7 +122,7 @@ fts_open(
} }
/* Allocate/initialize the stream */ /* Allocate/initialize the stream */
if ((sp = malloc((u_int)sizeof(FTS))) == NULL) if ((sp = malloc((unsigned int)sizeof(FTS))) == NULL)
return (NULL); return (NULL);
memset(sp, 0, sizeof(FTS)); memset(sp, 0, sizeof(FTS));
sp->fts_compar = compar; sp->fts_compar = compar;
@@ -204,20 +208,21 @@ fts_open(
SET(FTS_NOCHDIR); SET(FTS_NOCHDIR);
} }
} }
free(parent);
if (nitems == 0)
fts_free(parent);
return (sp); return (sp);
mem3: fts_lfree(root); mem3: fts_lfree(root);
free(parent); fts_free(parent);
mem2: free(sp->fts_path); mem2: free(sp->fts_path);
mem1: free(sp); mem1: free(sp);
return (NULL); return (NULL);
} }
static void static void
fts_load( fts_load(FTS *sp, FTSENT *p)
FTS *sp,
FTSENT *p)
{ {
size_t len; size_t len;
char *cp; char *cp;
@@ -244,8 +249,7 @@ fts_load(
} }
int int
fts_close( fts_close(FTS *sp)
FTS *sp)
{ {
FTSENT *freep, *p; FTSENT *freep, *p;
int saved_errno = 0; int saved_errno = 0;
@@ -258,14 +262,14 @@ fts_close(
* list which has a valid parent pointer. * list which has a valid parent pointer.
*/ */
if (sp->fts_cur) { if (sp->fts_cur) {
if (ISSET(FTS_SYMFOLLOW)) if (sp->fts_cur->fts_flags & FTS_SYMFOLLOW)
(void)close(sp->fts_cur->fts_symfd); (void)close(sp->fts_cur->fts_symfd);
for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
freep = p; freep = p;
p = p->fts_link ? p->fts_link : p->fts_parent; p = p->fts_link ? p->fts_link : p->fts_parent;
free(freep); fts_free(freep);
} }
free(p); fts_free(p);
} }
/* Free up child linked list, sort array, path buffer. */ /* Free up child linked list, sort array, path buffer. */
@@ -277,23 +281,23 @@ fts_close(
/* Return to original directory, save errno if necessary. */ /* Return to original directory, save errno if necessary. */
if (!ISSET(FTS_NOCHDIR)) { if (!ISSET(FTS_NOCHDIR)) {
if (fchdir(sp->fts_rfd)) if (fchdir(sp->fts_rfd) == -1)
saved_errno = errno; saved_errno = errno;
(void)close(sp->fts_rfd); (void)close(sp->fts_rfd);
} }
/* Free up the stream pointer. */ /* Free up the stream pointer. */
free(sp); free(sp);
/* ISSET() is illegal after this, since the macro touches sp */
/* Set errno and return. */
if (saved_errno) { if (saved_errno) {
errno = saved_errno; errno = saved_errno;
return (-1); return -1;
} }
return (0);
return 0;
} }
#if !defined(__FTS_COMPAT_TAILINGSLASH)
/* /*
* Special case of "/" at the end of the path so that slashes aren't * Special case of "/" at the end of the path so that slashes aren't
* appended which would cause paths to be written as "....//foo". * appended which would cause paths to be written as "....//foo".
@@ -302,9 +306,23 @@ fts_close(
(p->fts_path[p->fts_pathlen - 1] == '/' \ (p->fts_path[p->fts_pathlen - 1] == '/' \
? p->fts_pathlen - 1 : p->fts_pathlen) ? p->fts_pathlen - 1 : p->fts_pathlen)
#else /* !defined(__FTS_COMPAT_TAILINGSLASH) */
/*
* compatibility with the old behaviour.
*
* Special case a root of "/" so that slashes aren't appended which would
* cause paths to be written as "//foo".
*/
#define NAPPEND(p) \
(p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \
p->fts_path[0] == '/' ? 0 : p->fts_pathlen)
#endif /* !defined(__FTS_COMPAT_TAILINGSLASH) */
FTSENT * FTSENT *
fts_read( fts_read(FTS *sp)
FTS *sp )
{ {
FTSENT *p, *tmp; FTSENT *p, *tmp;
int instr; int instr;
@@ -408,7 +426,7 @@ fts_read(
/* Move to the next node on this level. */ /* Move to the next node on this level. */
next: tmp = p; next: tmp = p;
if ((p = p->fts_link) != NULL) { if ((p = p->fts_link) != NULL) {
free(tmp); fts_free(tmp);
/* /*
* If reached the top, return to the original directory, and * If reached the top, return to the original directory, and
@@ -455,14 +473,14 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent);
/* Move up to the parent node. */ /* Move up to the parent node. */
p = tmp->fts_parent; p = tmp->fts_parent;
free(tmp); fts_free(tmp);
if (p->fts_level == FTS_ROOTPARENTLEVEL) { if (p->fts_level == FTS_ROOTPARENTLEVEL) {
/* /*
* Done; free everything up and set errno to 0 so the user * Done; free everything up and set errno to 0 so the user
* can distinguish between error and EOF. * can distinguish between error and EOF.
*/ */
free(p); fts_free(p);
errno = 0; errno = 0;
return (sp->fts_cur = NULL); return (sp->fts_cur = NULL);
} }
@@ -506,10 +524,7 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent);
*/ */
/* ARGSUSED */ /* ARGSUSED */
int int
fts_set( fts_set(FTS *sp, FTSENT *p, int instr)
FTS *sp __attribute__((unused)),
FTSENT *p,
int instr)
{ {
_DIAGASSERT(sp != NULL); _DIAGASSERT(sp != NULL);
@@ -525,9 +540,7 @@ fts_set(
} }
FTSENT * FTSENT *
fts_children( fts_children(FTS *sp, int instr)
FTS *sp,
int instr )
{ {
FTSENT *p; FTSENT *p;
int fd; int fd;
@@ -611,17 +624,17 @@ fts_children(
* been found, cutting the stat calls by about 2/3. * been found, cutting the stat calls by about 2/3.
*/ */
static FTSENT * static FTSENT *
fts_build( fts_build(FTS *sp, int type)
FTS *sp,
int type)
{ {
struct dirent *dp; struct dirent *dp;
FTSENT *p, *head; FTSENT *p, *head;
size_t nitems; size_t nitems;
FTSENT *cur, *tail; FTSENT *cur, *tail;
DIR *dirp; DIR *dirp;
int adjust, cderrno, descend, len, level, nlinks, saved_errno, nostat; void *oldaddr;
size_t maxlen; size_t dnamlen;
int cderrno, descend, level, nlinks, saved_errno, nostat, doadjust;
size_t len, maxlen;
#ifdef FTS_WHITEOUT #ifdef FTS_WHITEOUT
int oflag; int oflag;
#endif #endif
@@ -642,7 +655,7 @@ fts_build(
else else
oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
#else #else
#define __opendir2(path, flag) opendir(path) #define __opendir2(path, flag) opendir(path)
#endif #endif
if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
if (type == BREAD) { if (type == BREAD) {
@@ -719,25 +732,35 @@ fts_build(
len++; len++;
maxlen = sp->fts_pathlen - len; maxlen = sp->fts_pathlen - len;
#if defined(__FTS_COMPAT_LEVEL)
if (cur->fts_level == SHRT_MAX) {
(void)closedir(dirp);
cur->fts_info = FTS_ERR;
SET(FTS_STOP);
errno = ENAMETOOLONG;
return (NULL);
}
#endif
level = cur->fts_level + 1; level = cur->fts_level + 1;
/* Read the directory, attaching each entry to the `link' pointer. */ /* Read the directory, attaching each entry to the `link' pointer. */
adjust = 0; doadjust = 0;
for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)) != NULL;) { for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)) != NULL;) {
size_t dlen;
if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
continue; continue;
#if HAVE_STRUCT_DIRENT_D_NAMLEN #if defined(HAVE_STRUCT_DIRENT_D_NAMLEN)
dlen = dp->d_namlen; dnamlen = dp->d_namlen;
#else #else
dlen = strlen(dp->d_name); dnamlen = strlen(dp->d_name);
#endif #endif
if ((p = fts_alloc(sp, dp->d_name, dlen)) == NULL) if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL)
goto mem1; goto mem1;
if (dlen >= maxlen) { /* include space for NUL */ if (dnamlen >= maxlen) { /* include space for NUL */
if (fts_palloc(sp, len + dlen + 1)) { oldaddr = sp->fts_path;
if (fts_palloc(sp, dnamlen + len + 1)) {
/* /*
* No more memory for path or structures. Save * No more memory for path or structures. Save
* errno, free up the current structure and the * errno, free up the current structure and the
@@ -745,7 +768,7 @@ fts_build(
*/ */
mem1: saved_errno = errno; mem1: saved_errno = errno;
if (p) if (p)
free(p); fts_free(p);
fts_lfree(head); fts_lfree(head);
(void)closedir(dirp); (void)closedir(dirp);
errno = saved_errno; errno = saved_errno;
@@ -753,15 +776,36 @@ mem1: saved_errno = errno;
SET(FTS_STOP); SET(FTS_STOP);
return (NULL); return (NULL);
} }
adjust = 1; /* Did realloc() change the pointer? */
if (ISSET(FTS_NOCHDIR)) if (oldaddr != sp->fts_path) {
cp = sp->fts_path + len; doadjust = 1;
if (ISSET(FTS_NOCHDIR))
cp = sp->fts_path + len;
}
maxlen = sp->fts_pathlen - len; maxlen = sp->fts_pathlen - len;
} }
p->fts_pathlen = len + dlen; #if defined(__FTS_COMPAT_LENGTH)
p->fts_parent = sp->fts_cur; if (len + dnamlen >= USHRT_MAX) {
/*
* In an FTSENT, fts_pathlen is an unsigned short
* so it is possible to wraparound here.
* If we do, free up the current structure and the
* structures already allocated, then error out
* with ENAMETOOLONG.
*/
fts_free(p);
fts_lfree(head);
(void)closedir(dirp);
cur->fts_info = FTS_ERR;
SET(FTS_STOP);
errno = ENAMETOOLONG;
return (NULL);
}
#endif
p->fts_level = level; p->fts_level = level;
p->fts_pathlen = len + dnamlen;
p->fts_parent = sp->fts_cur;
#ifdef FTS_WHITEOUT #ifdef FTS_WHITEOUT
if (dp->d_type == DT_WHT) if (dp->d_type == DT_WHT)
@@ -774,8 +818,8 @@ mem1: saved_errno = errno;
p->fts_errno = cderrno; p->fts_errno = cderrno;
} /* else } /* else
p->fts_info = FTS_NSOK; p->fts_info = FTS_NSOK;
*/ */
/* Coverity Scan Id 1 says above is dead code */ /* Coverity Scan Id 1 says above is dead code */
p->fts_accpath = cur->fts_accpath; p->fts_accpath = cur->fts_accpath;
} else if (nlinks == 0 } else if (nlinks == 0
#ifdef DT_DIR #ifdef DT_DIR
@@ -819,7 +863,7 @@ mem1: saved_errno = errno;
* If had to realloc the path, adjust the addresses for the rest * If had to realloc the path, adjust the addresses for the rest
* of the tree. * of the tree.
*/ */
if (adjust) if (doadjust)
fts_padjust(sp, head); fts_padjust(sp, head);
/* /*
@@ -827,7 +871,7 @@ mem1: saved_errno = errno;
* state. * state.
*/ */
if (ISSET(FTS_NOCHDIR)) { if (ISSET(FTS_NOCHDIR)) {
if (cp - 1 > sp->fts_path) if (len == sp->fts_pathlen || nitems == 0)
--cp; --cp;
*cp = '\0'; *cp = '\0';
} }
@@ -861,11 +905,8 @@ mem1: saved_errno = errno;
return (head); return (head);
} }
static u_short static unsigned short
fts_stat( fts_stat(FTS *sp, FTSENT *p, int follow)
FTS *sp,
FTSENT *p,
int follow )
{ {
FTSENT *t; FTSENT *t;
dev_t dev; dev_t dev;
@@ -948,10 +989,7 @@ err: memset(sbp, 0, sizeof(*sbp));
} }
static FTSENT * static FTSENT *
fts_sort( fts_sort(FTS *sp, FTSENT *head, size_t nitems)
FTS *sp,
FTSENT *head,
size_t nitems )
{ {
FTSENT **ap, *p; FTSENT **ap, *p;
@@ -977,7 +1015,7 @@ fts_sort(
for (ap = sp->fts_array, p = head; p; p = p->fts_link) for (ap = sp->fts_array, p = head; p; p = p->fts_link)
*ap++ = p; *ap++ = p;
qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *),
(int (*) __P((const void *, const void *)))sp->fts_compar); (int (*)(const void *, const void *))sp->fts_compar);
for (head = *(ap = sp->fts_array); --nitems; ++ap) for (head = *(ap = sp->fts_array); --nitems; ++ap)
ap[0]->fts_link = ap[1]; ap[0]->fts_link = ap[1];
ap[0]->fts_link = NULL; ap[0]->fts_link = NULL;
@@ -985,18 +1023,17 @@ fts_sort(
} }
static FTSENT * static FTSENT *
fts_alloc( fts_alloc(FTS *sp, const char *name, size_t namelen)
FTS *sp,
const char *name,
size_t namelen )
{ {
FTSENT *p; FTSENT *p;
#if defined(FTS_ALLOC_ALIGNED)
size_t len; size_t len;
#endif
_DIAGASSERT(sp != NULL); _DIAGASSERT(sp != NULL);
_DIAGASSERT(name != NULL); _DIAGASSERT(name != NULL);
#if defined(ALIGNBYTES) && defined(ALIGN) #if defined(FTS_ALLOC_ALIGNED)
/* /*
* The file name is a variable length array and no stat structure is * The file name is a variable length array and no stat structure is
* necessary if the user has set the nostat bit. Allocate the FTSENT * necessary if the user has set the nostat bit. Allocate the FTSENT
@@ -1012,8 +1049,8 @@ fts_alloc(
return (NULL); return (NULL);
if (!ISSET(FTS_NOSTAT)) if (!ISSET(FTS_NOSTAT))
p->fts_statp = p->fts_statp = (__fts_stat_t *)ALIGN(
(__fts_stat_t *)ALIGN((u_long)(p->fts_name + namelen + 2)); (unsigned long)(p->fts_name + namelen + 2));
#else #else
if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL) if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL)
return (NULL); return (NULL);
@@ -1025,6 +1062,9 @@ fts_alloc(
} }
#endif #endif
if (ISSET(FTS_NOSTAT))
p->fts_statp = NULL;
/* Copy the name plus the trailing NULL. */ /* Copy the name plus the trailing NULL. */
memmove(p->fts_name, name, namelen + 1); memmove(p->fts_name, name, namelen + 1);
@@ -1039,8 +1079,17 @@ fts_alloc(
} }
static void static void
fts_lfree( fts_free(FTSENT *p)
FTSENT *head ) {
#if !defined(FTS_ALLOC_ALIGNED)
if (p->fts_statp)
free(p->fts_statp);
#endif
free(p);
}
static void
fts_lfree(FTSENT *head)
{ {
FTSENT *p; FTSENT *p;
@@ -1049,18 +1098,12 @@ fts_lfree(
/* Free a linked list of structures. */ /* Free a linked list of structures. */
while ((p = head) != NULL) { while ((p = head) != NULL) {
head = head->fts_link; head = head->fts_link;
fts_free(p);
#if !defined(ALIGNBYTES) || !defined(ALIGN)
if (p->fts_statp)
free(p->fts_statp);
#endif
free(p);
} }
} }
static size_t static size_t
fts_pow2( fts_pow2(size_t x)
size_t x )
{ {
x--; x--;
@@ -1086,18 +1129,16 @@ fts_pow2(
* so we don't realloc the path 2 bytes at a time. * so we don't realloc the path 2 bytes at a time.
*/ */
static int static int
fts_palloc( fts_palloc(FTS *sp, size_t size)
FTS *sp,
size_t size )
{ {
char *new; char *new;
_DIAGASSERT(sp != NULL); _DIAGASSERT(sp != NULL);
#if 1 #ifdef __FTS_COMPAT_LENGTH
/* Protect against fts_pathlen overflow. */ /* Protect against fts_pathlen overflow. */
if (size > USHRT_MAX + 1) { if (size > USHRT_MAX + 1) {
errno = ENOMEM; errno = ENAMETOOLONG;
return (1); return (1);
} }
#endif #endif
@@ -1115,9 +1156,7 @@ fts_palloc(
* already returned. * already returned.
*/ */
static void static void
fts_padjust( fts_padjust(FTS *sp, FTSENT *head)
FTS *sp,
FTSENT *head )
{ {
FTSENT *p; FTSENT *p;
char *addr; char *addr;
@@ -1145,8 +1184,7 @@ fts_padjust(
} }
static size_t static size_t
fts_maxarglen( fts_maxarglen(char * const *argv)
char * const *argv )
{ {
size_t len, max; size_t len, max;
@@ -1164,11 +1202,7 @@ fts_maxarglen(
* Assumes p->fts_dev and p->fts_ino are filled in. * Assumes p->fts_dev and p->fts_ino are filled in.
*/ */
static int static int
fts_safe_changedir( fts_safe_changedir(const FTS *sp, const FTSENT *p, int fd, const char *path)
const FTS *sp,
const FTSENT *p,
int fd,
const char *path)
{ {
int oldfd = fd, ret = -1; int oldfd = fd, ret = -1;
__fts_stat_t sb; __fts_stat_t sb;

View File

@@ -360,7 +360,8 @@ main_ls(rtems_shell_ls_globals* globals, int argc, char *argv[])
if (!kflag) if (!kflag)
(void)getbsize(NULL, &blocksize); (void)getbsize(NULL, &blocksize);
#else #else
blocksize = 1024; /* Make equal to 1 so ls -l shows the actual blcok count */
blocksize = 512;
#endif #endif
blocksize /= 512; blocksize /= 512;
} }
@@ -542,6 +543,7 @@ display(rtems_shell_ls_globals* globals, FTSENT *p, FTSENT *list)
btotal = stotal = maxblock = maxsize = 0; btotal = stotal = maxblock = maxsize = 0;
maxmajor = maxminor = 0; maxmajor = maxminor = 0;
for (cur = list, entries = 0; cur; cur = cur->fts_link) { for (cur = list, entries = 0; cur; cur = cur->fts_link) {
uint64_t size;
if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) { if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
warnx("%s: %s", warnx("%s: %s",
cur->fts_name, strerror(cur->fts_errno)); cur->fts_name, strerror(cur->fts_errno));
@@ -571,14 +573,17 @@ display(rtems_shell_ls_globals* globals, FTSENT *p, FTSENT *list)
maxlen = cur->fts_namelen; maxlen = cur->fts_namelen;
if (needstats) { if (needstats) {
sp = cur->fts_statp; sp = cur->fts_statp;
size = ((uint64_t) sp->st_blocks) * sp->st_blksize;
if (size < 0x100000000ULL)
size = sp->st_size;
if (sp->st_blocks > maxblock) if (sp->st_blocks > maxblock)
maxblock = sp->st_blocks; maxblock = sp->st_blocks;
if (sp->st_ino > maxinode) if (sp->st_ino > maxinode)
maxinode = sp->st_ino; maxinode = sp->st_ino;
if (sp->st_nlink > maxnlink) if (sp->st_nlink > maxnlink)
maxnlink = sp->st_nlink; maxnlink = sp->st_nlink;
if (sp->st_size > maxsize) if (size > maxsize)
maxsize = sp->st_size; maxsize = size;
if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) { if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode)) {
bcfile = 1; bcfile = 1;
if (major(sp->st_rdev) > maxmajor) if (major(sp->st_rdev) > maxmajor)
@@ -588,7 +593,7 @@ display(rtems_shell_ls_globals* globals, FTSENT *p, FTSENT *list)
} }
btotal += sp->st_blocks; btotal += sp->st_blocks;
stotal += sp->st_size; stotal += size;
if (f_longform) { if (f_longform) {
if (f_numericonly || if (f_numericonly ||
(user = user_from_uid(sp->st_uid, 0)) == (user = user_from_uid(sp->st_uid, 0)) ==

View File

@@ -161,11 +161,13 @@ printlong(rtems_shell_ls_globals* globals, DISPLAY *dp)
(void)printf("%*s ", dp->s_size, szbuf); (void)printf("%*s ", dp->s_size, szbuf);
} else { } else {
#endif #endif
(void)printf("%*llu ", dp->s_size, {
(long long)sp->st_size); unsigned long long size = sp->st_blocks;
#if RTEMS_REMOVED size *= sp->st_blksize;
if (size < 0x100000000ULL)
size = sp->st_size;
(void)printf("%*llu ", dp->s_size, size);
} }
#endif
if (f_accesstime) if (f_accesstime)
printtime(globals, sp->st_atime); printtime(globals, sp->st_atime);
else if (f_statustime) else if (f_statustime)

View File

@@ -328,7 +328,7 @@ rtems_create_root_fs (void)
* Create a `/etc/hosts' file. * Create a `/etc/hosts' file.
*/ */
if (rtems_rootfs_append_host_rec (0x7f000001, "localhost", "localdomain")) if (rtems_rootfs_append_host_rec (htonl (0x7f000001), "localhost", "localdomain"))
return -1; return -1;
return 0; return 0;