blob: 2605ab12d838739d75a96772fa510ff6535ae8ad [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen9d3aba71999-10-06 09:04:55 +00002/*
Eric Andersencc8ed391999-10-05 16:24:54 +00003 * tiny-ls.c version 0.1.0: A minimalist 'ls'
4 * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
Eric Andersen11c65522000-09-07 17:24:47 +00005 *
Eric Andersencc8ed391999-10-05 16:24:54 +00006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21/*
22 * To achieve a small memory footprint, this version of 'ls' doesn't do any
23 * file sorting, and only has the most essential command line switches
Eric Andersen77d92682001-05-23 20:32:09 +000024 * (i.e., the ones I couldn't live without :-) All features which involve
Eric Andersencc8ed391999-10-05 16:24:54 +000025 * linking in substantial chunks of libc can be disabled.
26 *
27 * Although I don't really want to add new features to this program to
28 * keep it small, I *am* interested to receive bug fixes and ways to make
29 * it more portable.
30 *
31 * KNOWN BUGS:
Erik Andersen9ffdaa62000-02-11 21:55:04 +000032 * 1. ls -l of a directory doesn't give "total <blocks>" header
33 * 2. ls of a symlink to a directory doesn't list directory contents
34 * 3. hidden files can make column width too large
35 *
Eric Andersencc8ed391999-10-05 16:24:54 +000036 * NON-OPTIMAL BEHAVIOUR:
37 * 1. autowidth reads directories twice
38 * 2. if you do a short directory listing without filetype characters
39 * appended, there's no need to stat each one
40 * PORTABILITY:
41 * 1. requires lstat (BSD) - how do you do it without?
42 */
43
Eric Andersene57d54b2001-01-30 18:03:11 +000044enum {
Glenn L McGrathe3906fc2002-08-22 18:13:54 +000045 TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +000046 COLUMN_GAP = 2, /* includes the file type char */
Eric Andersene57d54b2001-01-30 18:03:11 +000047};
48
Eric Andersencc8ed391999-10-05 16:24:54 +000049/************************************************************************/
50
Eric Andersen11c65522000-09-07 17:24:47 +000051#include <sys/types.h>
52#include <sys/stat.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000053#include <stdio.h>
54#include <unistd.h>
55#include <dirent.h>
56#include <errno.h>
57#include <stdio.h>
Eric Andersen11c65522000-09-07 17:24:47 +000058#include <string.h>
Eric Andersened3ef502001-01-27 08:24:39 +000059#include <stdlib.h>
Eric Andersen5307eca2001-01-26 01:52:43 +000060#include <fcntl.h>
61#include <signal.h>
Eric Andersen8d79ce82001-07-22 23:00:15 +000062#include <termios.h>
Eric Andersen5307eca2001-01-26 01:52:43 +000063#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000064#include "busybox.h"
Eric Andersen9e480452003-07-03 10:07:04 +000065#ifdef CONFIG_SELINUX
66#include <fs_secure.h>
67#include <flask_util.h>
68#include <ss.h>
69#endif
Eric Andersen5307eca2001-01-26 01:52:43 +000070
Eric Andersenbdfd0d72001-10-24 05:00:29 +000071#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Eric Andersenf1142c52001-02-20 06:16:29 +000072#include <time.h>
73#endif
74
Eric Andersen30f64c32001-01-30 19:23:46 +000075#ifndef MAJOR
Erik Andersen1ad302a2000-03-24 00:54:46 +000076#define MAJOR(dev) (((dev)>>8)&0xff)
77#define MINOR(dev) ((dev)&0xff)
78#endif
79
Eric Andersen11c65522000-09-07 17:24:47 +000080/* what is the overall style of the listing */
Manuel Novoa III cad53642003-03-19 09:13:01 +000081#define STYLE_AUTO (0)
82#define STYLE_COLUMNS (1U<<21) /* fill columns */
83#define STYLE_LONG (2U<<21) /* one record per line, extended info */
84#define STYLE_SINGLE (3U<<21) /* one record per line */
85
86#define STYLE_MASK STYLE_SINGLE
87#define STYLE_ONE_RECORD_FLAG STYLE_LONG
Eric Andersencc8ed391999-10-05 16:24:54 +000088
Eric Andersen11c65522000-09-07 17:24:47 +000089/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
90/* what file information will be listed */
Manuel Novoa III cad53642003-03-19 09:13:01 +000091#define LIST_INO (1U<<0)
92#define LIST_BLOCKS (1U<<1)
93#define LIST_MODEBITS (1U<<2)
94#define LIST_NLINKS (1U<<3)
95#define LIST_ID_NAME (1U<<4)
96#define LIST_ID_NUMERIC (1U<<5)
Eric Andersen9e480452003-07-03 10:07:04 +000097#define LIST_CONTEXT (1U<<6)
98#define LIST_SIZE (1U<<7)
99#define LIST_DEV (1U<<8)
100#define LIST_DATE_TIME (1U<<9)
101#define LIST_FULLTIME (1U<<10)
102#define LIST_FILENAME (1U<<11)
103#define LIST_SYMLINK (1U<<12)
104#define LIST_FILETYPE (1U<<13)
105#define LIST_EXEC (1U<<14)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000106
107#define LIST_MASK ((LIST_EXEC << 1) - 1)
Eric Andersen11c65522000-09-07 17:24:47 +0000108
109/* what files will be displayed */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000110/* TODO -- We may be able to make DISP_NORMAL 0 to save a bit slot. */
111#define DISP_NORMAL (1U<<14) /* show normal filenames */
112#define DISP_DIRNAME (1U<<15) /* 2 or more items? label directories */
113#define DISP_HIDDEN (1U<<16) /* show filenames starting with . */
114#define DISP_DOT (1U<<17) /* show . and .. */
115#define DISP_NOLIST (1U<<18) /* show directory as itself, not contents */
116#define DISP_RECURSIVE (1U<<19) /* show directory and everything below it */
117#define DISP_ROWS (1U<<20) /* print across rows */
118
119#define DISP_MASK (((DISP_ROWS << 1) - 1) & ~(DISP_NORMAL - 1))
Eric Andersen11c65522000-09-07 17:24:47 +0000120
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000121#ifdef CONFIG_FEATURE_LS_SORTFILES
Eric Andersen11c65522000-09-07 17:24:47 +0000122/* how will the files be sorted */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000123#define SORT_ORDER_FORWARD 0 /* sort in reverse order */
124#define SORT_ORDER_REVERSE (1U<<27) /* sort in reverse order */
125
126#define SORT_NAME 0 /* sort by file name */
127#define SORT_SIZE (1U<<28) /* sort by file size */
128#define SORT_ATIME (2U<<28) /* sort by last access time */
129#define SORT_CTIME (3U<<28) /* sort by last change time */
130#define SORT_MTIME (4U<<28) /* sort by last modification time */
131#define SORT_VERSION (5U<<28) /* sort by version */
132#define SORT_EXT (6U<<28) /* sort by file name extension */
133#define SORT_DIR (7U<<28) /* sort by file or directory */
134
135#define SORT_MASK (7U<<28)
Eric Andersencc8ed391999-10-05 16:24:54 +0000136#endif
137
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000138#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Eric Andersen11c65522000-09-07 17:24:47 +0000139/* which of the three times will be used */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000140#define TIME_MOD 0
141#define TIME_CHANGE (1U<<23)
142#define TIME_ACCESS (1U<<24)
143
144#define TIME_MASK (3U<<23)
145#endif
146
147#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
148#define FOLLOW_LINKS (1U<<25)
149#endif
150#ifdef CONFIG_FEATURE_HUMAN_READABLE
151#define LS_DISP_HR (1U<<26)
Eric Andersencc8ed391999-10-05 16:24:54 +0000152#endif
153
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000154#define LIST_SHORT (LIST_FILENAME)
155#define LIST_ISHORT (LIST_INO | LIST_FILENAME)
156#define LIST_LONG (LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
157 LIST_DATE_TIME | LIST_FILENAME | LIST_SYMLINK)
158#define LIST_ILONG (LIST_INO | LIST_LONG)
Eric Andersencc8ed391999-10-05 16:24:54 +0000159
Manuel Novoa III cad53642003-03-19 09:13:01 +0000160#define SPLIT_DIR 1
161#define SPLIT_FILE 0
162#define SPLIT_SUBDIR 2
Eric Andersencc8ed391999-10-05 16:24:54 +0000163
Eric Andersen11c65522000-09-07 17:24:47 +0000164#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
165#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000166
Eric Andersend598d412002-04-27 09:19:39 +0000167#if defined(CONFIG_FEATURE_LS_FILETYPES) || defined(CONFIG_FEATURE_LS_COLOR)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000168# define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
Eric Andersen11c65522000-09-07 17:24:47 +0000169#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000170
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000171/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
172#ifdef CONFIG_FEATURE_LS_COLOR
173static int show_color = 0;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000174
175#define COLOR(mode) ("\000\043\043\043\042\000\043\043"\
176 "\000\000\044\000\043\000\000\040" [TYPEINDEX(mode)])
177#define ATTR(mode) ("\00\00\01\00\01\00\01\00"\
178 "\00\00\01\00\01\00\00\01" [TYPEINDEX(mode)])
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000179#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000180
Eric Andersen11c65522000-09-07 17:24:47 +0000181/*
182 * a directory entry and its stat info are stored here
183 */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000184struct dnode { /* the basic node */
185 char *name; /* the dir entry name */
186 char *fullname; /* the dir entry name */
187 struct stat dstat; /* the file stat info */
Eric Andersen9e480452003-07-03 10:07:04 +0000188#ifdef CONFIG_SELINUX
189 security_id_t sid;
190#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000191 struct dnode *next; /* point at the next node */
Eric Andersen11c65522000-09-07 17:24:47 +0000192};
193typedef struct dnode dnode_t;
194
Glenn L McGrath4d001292003-01-06 01:11:50 +0000195static struct dnode **list_dir(const char *);
Eric Andersen3e6ff902001-03-09 21:24:12 +0000196static struct dnode **dnalloc(int);
197static int list_single(struct dnode *);
Eric Andersen11c65522000-09-07 17:24:47 +0000198
Manuel Novoa III cad53642003-03-19 09:13:01 +0000199static unsigned int all_fmt;
Eric Andersen11c65522000-09-07 17:24:47 +0000200
Eric Andersen9e480452003-07-03 10:07:04 +0000201#ifdef CONFIG_SELINUX
202static int is_flask_enabled_flag;
203#endif
204
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000205#ifdef CONFIG_FEATURE_AUTOWIDTH
Eric Andersen8efe9672003-09-15 08:33:45 +0000206static int terminal_width = TERMINAL_WIDTH;
Eric Andersene57d54b2001-01-30 18:03:11 +0000207static unsigned short tabstops = COLUMN_GAP;
Eric Andersenf5d5e772001-01-24 23:34:48 +0000208#else
Glenn L McGrath4d001292003-01-06 01:11:50 +0000209#define tabstops COLUMN_GAP
210#define terminal_width TERMINAL_WIDTH
Eric Andersen11c65522000-09-07 17:24:47 +0000211#endif
Eric Andersencc8ed391999-10-05 16:24:54 +0000212
Matt Kraai33fdae52000-10-13 17:59:43 +0000213static int status = EXIT_SUCCESS;
214
Glenn L McGrath4d001292003-01-06 01:11:50 +0000215static struct dnode *my_stat(char *fullname, char *name)
Matt Kraai9a6e67c2000-10-13 18:03:21 +0000216{
Glenn L McGrath4d001292003-01-06 01:11:50 +0000217 struct stat dstat;
218 struct dnode *cur;
Eric Andersen9e480452003-07-03 10:07:04 +0000219#ifdef CONFIG_SELINUX
220 security_id_t sid;
221#endif
222 int rc;
Glenn L McGrath4d001292003-01-06 01:11:50 +0000223
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000224#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
Manuel Novoa III cad53642003-03-19 09:13:01 +0000225 if (all_fmt & FOLLOW_LINKS) {
Eric Andersen9e480452003-07-03 10:07:04 +0000226#ifdef CONFIG_SELINUX
227 if(is_flask_enabled_flag)
228 rc = stat_secure(fullname, &dstat, &sid);
229 else
230#endif
231 rc = stat(fullname, &dstat);
232 if(rc)
233 {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000234 bb_perror_msg("%s", fullname);
Matt Kraai9a6e67c2000-10-13 18:03:21 +0000235 status = EXIT_FAILURE;
Glenn L McGrath4d001292003-01-06 01:11:50 +0000236 return 0;
Matt Kraai9a6e67c2000-10-13 18:03:21 +0000237 }
238 } else
239#endif
Eric Andersen9e480452003-07-03 10:07:04 +0000240 {
241#ifdef CONFIG_SELINUX
242 if(is_flask_enabled_flag)
243 rc = lstat_secure(fullname, &dstat, &sid);
244 else
245#endif
246 rc = lstat(fullname, &dstat);
247 if(rc)
248 {
249 bb_perror_msg("%s", fullname);
250 status = EXIT_FAILURE;
251 return 0;
252 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000253 }
Glenn L McGrath4d001292003-01-06 01:11:50 +0000254
255 cur = (struct dnode *) xmalloc(sizeof(struct dnode));
256 cur->fullname = fullname;
257 cur->name = name;
258 cur->dstat = dstat;
Eric Andersen9e480452003-07-03 10:07:04 +0000259#ifdef CONFIG_SELINUX
260 cur->sid = sid;
261#endif
Glenn L McGrath4d001292003-01-06 01:11:50 +0000262 return cur;
Eric Andersen79565b62000-08-11 18:10:21 +0000263}
264
Eric Andersen11c65522000-09-07 17:24:47 +0000265/*----------------------------------------------------------------------*/
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000266#ifdef CONFIG_FEATURE_LS_COLOR
267static char fgcolor(mode_t mode)
268{
269 /* Check wheter the file is existing (if so, color it red!) */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000270 if (errno == ENOENT) {
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000271 return '\037';
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000272 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000273 if (LIST_EXEC && S_ISREG(mode)
274 && (mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000275 return COLOR(0xF000); /* File is executable ... */
276 return COLOR(mode);
277}
278
279/*----------------------------------------------------------------------*/
280static char bgcolor(mode_t mode)
281{
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000282 if (LIST_EXEC && S_ISREG(mode)
283 && (mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000284 return ATTR(0xF000); /* File is executable ... */
285 return ATTR(mode);
286}
287#endif
288
289/*----------------------------------------------------------------------*/
Eric Andersend598d412002-04-27 09:19:39 +0000290#if defined(CONFIG_FEATURE_LS_FILETYPES) || defined(CONFIG_FEATURE_LS_COLOR)
Eric Andersen11c65522000-09-07 17:24:47 +0000291static char append_char(mode_t mode)
Eric Andersen79565b62000-08-11 18:10:21 +0000292{
Manuel Novoa III cad53642003-03-19 09:13:01 +0000293 if (!(all_fmt & LIST_FILETYPE))
Eric Andersen11c65522000-09-07 17:24:47 +0000294 return '\0';
Manuel Novoa III cad53642003-03-19 09:13:01 +0000295 if ((all_fmt & LIST_EXEC) && S_ISREG(mode)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000296 && (mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
297 return '*';
298 return APPCHAR(mode);
Eric Andersen11c65522000-09-07 17:24:47 +0000299}
300#endif
Eric Andersen79565b62000-08-11 18:10:21 +0000301
Eric Andersen11c65522000-09-07 17:24:47 +0000302/*----------------------------------------------------------------------*/
Eric Andersencf1189f2000-11-29 21:52:06 +0000303
Manuel Novoa III cad53642003-03-19 09:13:01 +0000304#define countdirs(A,B) count_dirs((A), (B), 1)
305#define countsubdirs(A,B) count_dirs((A), (B), 0)
306
307static int count_dirs(struct dnode **dn, int nfiles, int notsubdirs)
Eric Andersen11c65522000-09-07 17:24:47 +0000308{
309 int i, dirs;
310
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000311 if (dn == NULL || nfiles < 1)
312 return (0);
313 dirs = 0;
314 for (i = 0; i < nfiles; i++) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000315 if (S_ISDIR(dn[i]->dstat.st_mode)
316 && (notsubdirs
317 || ((dn[i]->name[0] != '.')
318 || (dn[i]->name[1]
319 && ((dn[i]->name[1] != '.')
320 || dn[i]->name[2])))))
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000321 dirs++;
Eric Andersen11c65522000-09-07 17:24:47 +0000322 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000323 return (dirs);
Eric Andersen11c65522000-09-07 17:24:47 +0000324}
325
Eric Andersen3e6ff902001-03-09 21:24:12 +0000326static int countfiles(struct dnode **dnp)
Eric Andersen11c65522000-09-07 17:24:47 +0000327{
328 int nfiles;
329 struct dnode *cur;
330
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000331 if (dnp == NULL)
332 return (0);
333 nfiles = 0;
334 for (cur = dnp[0]; cur->next != NULL; cur = cur->next)
335 nfiles++;
Eric Andersen11c65522000-09-07 17:24:47 +0000336 nfiles++;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000337 return (nfiles);
Eric Andersen11c65522000-09-07 17:24:47 +0000338}
339
340/* get memory to hold an array of pointers */
Eric Andersen3e6ff902001-03-09 21:24:12 +0000341static struct dnode **dnalloc(int num)
Eric Andersen11c65522000-09-07 17:24:47 +0000342{
343 struct dnode **p;
344
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000345 if (num < 1)
346 return (NULL);
Eric Andersen11c65522000-09-07 17:24:47 +0000347
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000348 p = (struct dnode **) xcalloc((size_t) num,
349 (size_t) (sizeof(struct dnode *)));
350 return (p);
Eric Andersen11c65522000-09-07 17:24:47 +0000351}
352
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000353#ifdef CONFIG_FEATURE_LS_RECURSIVE
Eric Andersen3e6ff902001-03-09 21:24:12 +0000354static void dfree(struct dnode **dnp)
Eric Andersen11c65522000-09-07 17:24:47 +0000355{
356 struct dnode *cur, *next;
357
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000358 if (dnp == NULL)
359 return;
Eric Andersen11c65522000-09-07 17:24:47 +0000360
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000361 cur = dnp[0];
Eric Andersen11c65522000-09-07 17:24:47 +0000362 while (cur != NULL) {
Aaron Lehmanna170e1c2002-11-28 11:27:31 +0000363 free(cur->fullname); /* free the filename */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000364 next = cur->next;
365 free(cur); /* free the dnode */
366 cur = next;
Eric Andersen11c65522000-09-07 17:24:47 +0000367 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000368 free(dnp); /* free the array holding the dnode pointers */
Eric Andersen11c65522000-09-07 17:24:47 +0000369}
Eric Andersen20aab262001-07-19 22:28:02 +0000370#endif
Eric Andersen11c65522000-09-07 17:24:47 +0000371
Eric Andersen3e6ff902001-03-09 21:24:12 +0000372static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
Eric Andersen11c65522000-09-07 17:24:47 +0000373{
374 int dncnt, i, d;
375 struct dnode **dnp;
376
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000377 if (dn == NULL || nfiles < 1)
378 return (NULL);
Eric Andersen11c65522000-09-07 17:24:47 +0000379
380 /* count how many dirs and regular files there are */
Eric Andersencf1189f2000-11-29 21:52:06 +0000381 if (which == SPLIT_SUBDIR)
382 dncnt = countsubdirs(dn, nfiles);
383 else {
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000384 dncnt = countdirs(dn, nfiles); /* assume we are looking for dirs */
Eric Andersencf1189f2000-11-29 21:52:06 +0000385 if (which == SPLIT_FILE)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000386 dncnt = nfiles - dncnt; /* looking for files */
Eric Andersencf1189f2000-11-29 21:52:06 +0000387 }
Eric Andersen11c65522000-09-07 17:24:47 +0000388
389 /* allocate a file array and a dir array */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000390 dnp = dnalloc(dncnt);
Eric Andersen11c65522000-09-07 17:24:47 +0000391
392 /* copy the entrys into the file or dir array */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000393 for (d = i = 0; i < nfiles; i++) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000394 if (S_ISDIR(dn[i]->dstat.st_mode)) {
395 if (which & (SPLIT_DIR|SPLIT_SUBDIR)) {
396 if ((which & SPLIT_DIR)
397 || ((dn[i]->name[0] != '.')
398 || (dn[i]->name[1]
399 && ((dn[i]->name[1] != '.')
400 || dn[i]->name[2])))) {
401 dnp[d++] = dn[i];
402 }
403 }
404 } else if (!(which & (SPLIT_DIR|SPLIT_SUBDIR))) {
405 dnp[d++] = dn[i];
Eric Andersen11c65522000-09-07 17:24:47 +0000406 }
407 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000408 return (dnp);
Eric Andersen11c65522000-09-07 17:24:47 +0000409}
410
411/*----------------------------------------------------------------------*/
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000412#ifdef CONFIG_FEATURE_LS_SORTFILES
Eric Andersen3e6ff902001-03-09 21:24:12 +0000413static int sortcmp(struct dnode *d1, struct dnode *d2)
Eric Andersen11c65522000-09-07 17:24:47 +0000414{
Manuel Novoa III cad53642003-03-19 09:13:01 +0000415 unsigned int sort_opts = all_fmt & SORT_MASK;
416 int dif;
Eric Andersen11c65522000-09-07 17:24:47 +0000417
Manuel Novoa III cad53642003-03-19 09:13:01 +0000418 dif = 0; /* assume SORT_NAME */
Eric Andersen11c65522000-09-07 17:24:47 +0000419 if (sort_opts == SORT_SIZE) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000420 dif = (int) (d2->dstat.st_size - d1->dstat.st_size);
Eric Andersen11c65522000-09-07 17:24:47 +0000421 } else if (sort_opts == SORT_ATIME) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000422 dif = (int) (d2->dstat.st_atime - d1->dstat.st_atime);
Eric Andersen11c65522000-09-07 17:24:47 +0000423 } else if (sort_opts == SORT_CTIME) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000424 dif = (int) (d2->dstat.st_ctime - d1->dstat.st_ctime);
Eric Andersen11c65522000-09-07 17:24:47 +0000425 } else if (sort_opts == SORT_MTIME) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000426 dif = (int) (d2->dstat.st_mtime - d1->dstat.st_mtime);
Eric Andersen11c65522000-09-07 17:24:47 +0000427 } else if (sort_opts == SORT_DIR) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000428 dif = S_ISDIR(d2->dstat.st_mode) - S_ISDIR(d1->dstat.st_mode);
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000429 /* } else if (sort_opts == SORT_VERSION) { */
430 /* } else if (sort_opts == SORT_EXT) { */
Eric Andersen11c65522000-09-07 17:24:47 +0000431 }
432
Eric Andersen11c65522000-09-07 17:24:47 +0000433 if (dif == 0) {
434 /* sort by name- may be a tie_breaker for time or size cmp */
Glenn L McGrath4d001292003-01-06 01:11:50 +0000435#ifdef CONFIG_LOCALE_SUPPORT
436 dif = strcoll(d1->name, d2->name);
437#else
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000438 dif = strcmp(d1->name, d2->name);
Glenn L McGrath4d001292003-01-06 01:11:50 +0000439#endif
Eric Andersen11c65522000-09-07 17:24:47 +0000440 }
441
Manuel Novoa III cad53642003-03-19 09:13:01 +0000442 if (all_fmt & SORT_ORDER_REVERSE) {
443 dif = -dif;
Eric Andersen11c65522000-09-07 17:24:47 +0000444 }
Manuel Novoa III cad53642003-03-19 09:13:01 +0000445 return (dif);
Eric Andersen11c65522000-09-07 17:24:47 +0000446}
447
448/*----------------------------------------------------------------------*/
Eric Andersen3e6ff902001-03-09 21:24:12 +0000449static void shellsort(struct dnode **dn, int size)
Eric Andersen11c65522000-09-07 17:24:47 +0000450{
451 struct dnode *temp;
452 int gap, i, j;
453
454 /* shell short the array */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000455 if (dn == NULL || size < 2)
456 return;
Eric Andersen11c65522000-09-07 17:24:47 +0000457
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000458 for (gap = size / 2; gap > 0; gap /= 2) {
459 for (i = gap; i < size; i++) {
460 for (j = i - gap; j >= 0; j -= gap) {
461 if (sortcmp(dn[j], dn[j + gap]) <= 0)
Eric Andersen11c65522000-09-07 17:24:47 +0000462 break;
463 /* they are out of order, swap them */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000464 temp = dn[j];
465 dn[j] = dn[j + gap];
466 dn[j + gap] = temp;
Eric Andersen11c65522000-09-07 17:24:47 +0000467 }
468 }
469 }
470}
471#endif
472
473/*----------------------------------------------------------------------*/
Eric Andersen3e6ff902001-03-09 21:24:12 +0000474static void showfiles(struct dnode **dn, int nfiles)
Eric Andersen11c65522000-09-07 17:24:47 +0000475{
476 int i, ncols, nrows, row, nc;
Glenn L McGrath4d001292003-01-06 01:11:50 +0000477 int column = 0;
478 int nexttab = 0;
479 int column_width = 0; /* for STYLE_LONG and STYLE_SINGLE not used */
Eric Andersen11c65522000-09-07 17:24:47 +0000480
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000481 if (dn == NULL || nfiles < 1)
482 return;
Eric Andersen11c65522000-09-07 17:24:47 +0000483
Manuel Novoa III cad53642003-03-19 09:13:01 +0000484 if (all_fmt & STYLE_ONE_RECORD_FLAG) {
Glenn L McGrath4d001292003-01-06 01:11:50 +0000485 ncols = 1;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000486 } else {
487 /* find the longest file name- use that as the column width */
488 for (i = 0; i < nfiles; i++) {
Glenn L McGrath4d001292003-01-06 01:11:50 +0000489 int len = strlen(dn[i]->name) +
Eric Andersen9e480452003-07-03 10:07:04 +0000490#ifdef CONFIG_SELINUX
491 ((all_fmt & LIST_CONTEXT) ? 33 : 0) +
492#endif
Manuel Novoa III cad53642003-03-19 09:13:01 +0000493 ((all_fmt & LIST_INO) ? 8 : 0) +
494 ((all_fmt & LIST_BLOCKS) ? 5 : 0);
495 if (column_width < len)
496 column_width = len;
497 }
Glenn L McGrath4d001292003-01-06 01:11:50 +0000498 column_width += tabstops;
499 ncols = (int) (terminal_width / column_width);
Eric Andersen11c65522000-09-07 17:24:47 +0000500 }
501
Eric Andersene57d54b2001-01-30 18:03:11 +0000502 if (ncols > 1) {
503 nrows = nfiles / ncols;
Glenn L McGrath4d001292003-01-06 01:11:50 +0000504 if ((nrows * ncols) < nfiles)
505 nrows++; /* round up fractionals */
Eric Andersene57d54b2001-01-30 18:03:11 +0000506 } else {
507 nrows = nfiles;
508 ncols = 1;
509 }
Eric Andersen11c65522000-09-07 17:24:47 +0000510
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000511 for (row = 0; row < nrows; row++) {
512 for (nc = 0; nc < ncols; nc++) {
Eric Andersen79565b62000-08-11 18:10:21 +0000513 /* reach into the array based on the column and row */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000514 i = (nc * nrows) + row; /* assume display by column */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000515 if (all_fmt & DISP_ROWS)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000516 i = (row * ncols) + nc; /* display across row */
Eric Andersen11c65522000-09-07 17:24:47 +0000517 if (i < nfiles) {
Glenn L McGrath4d001292003-01-06 01:11:50 +0000518 if (column > 0) {
519 nexttab -= column;
520 while (nexttab--) {
521 putchar(' ');
522 column++;
523 }
Eric Andersen79565b62000-08-11 18:10:21 +0000524 }
Glenn L McGrath4d001292003-01-06 01:11:50 +0000525 nexttab = column + column_width;
526 column += list_single(dn[i]);
Eric Andersen79565b62000-08-11 18:10:21 +0000527 }
Glenn L McGrath4d001292003-01-06 01:11:50 +0000528 }
529 putchar('\n');
530 column = 0;
Eric Andersena42982e2000-06-07 17:28:53 +0000531 }
Eric Andersen11c65522000-09-07 17:24:47 +0000532}
533
534/*----------------------------------------------------------------------*/
Glenn L McGrathc4db0832004-03-06 09:12:55 +0000535static void showdirs(struct dnode **dn, int ndirs, int first)
Eric Andersen11c65522000-09-07 17:24:47 +0000536{
537 int i, nfiles;
538 struct dnode **subdnp;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000539
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000540#ifdef CONFIG_FEATURE_LS_RECURSIVE
Eric Andersen11c65522000-09-07 17:24:47 +0000541 int dndirs;
542 struct dnode **dnd;
543#endif
544
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000545 if (dn == NULL || ndirs < 1)
546 return;
Eric Andersen11c65522000-09-07 17:24:47 +0000547
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000548 for (i = 0; i < ndirs; i++) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000549 if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
Glenn L McGrathc4db0832004-03-06 09:12:55 +0000550 if (!first)
551 printf("\n");
552 first = 0;
553 printf("%s:\n", dn[i]->fullname);
Eric Andersen11c65522000-09-07 17:24:47 +0000554 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000555 subdnp = list_dir(dn[i]->fullname);
556 nfiles = countfiles(subdnp);
Eric Andersen11c65522000-09-07 17:24:47 +0000557 if (nfiles > 0) {
558 /* list all files at this level */
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000559#ifdef CONFIG_FEATURE_LS_SORTFILES
Eric Andersen11c65522000-09-07 17:24:47 +0000560 shellsort(subdnp, nfiles);
561#endif
562 showfiles(subdnp, nfiles);
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000563#ifdef CONFIG_FEATURE_LS_RECURSIVE
Manuel Novoa III cad53642003-03-19 09:13:01 +0000564 if (all_fmt & DISP_RECURSIVE) {
Eric Andersen11c65522000-09-07 17:24:47 +0000565 /* recursive- list the sub-dirs */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000566 dnd = splitdnarray(subdnp, nfiles, SPLIT_SUBDIR);
567 dndirs = countsubdirs(subdnp, nfiles);
Eric Andersen11c65522000-09-07 17:24:47 +0000568 if (dndirs > 0) {
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000569#ifdef CONFIG_FEATURE_LS_SORTFILES
Eric Andersen11c65522000-09-07 17:24:47 +0000570 shellsort(dnd, dndirs);
Matt Kraaia5bd2682000-10-28 06:40:09 +0000571#endif
Glenn L McGrathc4db0832004-03-06 09:12:55 +0000572 showdirs(dnd, dndirs, 0);
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000573 free(dnd); /* free the array of dnode pointers to the dirs */
Eric Andersen11c65522000-09-07 17:24:47 +0000574 }
575 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000576 dfree(subdnp); /* free the dnodes and the fullname mem */
Eric Andersen11c65522000-09-07 17:24:47 +0000577#endif
578 }
579 }
580}
581
582/*----------------------------------------------------------------------*/
Glenn L McGrath4d001292003-01-06 01:11:50 +0000583static struct dnode **list_dir(const char *path)
Eric Andersen11c65522000-09-07 17:24:47 +0000584{
585 struct dnode *dn, *cur, **dnp;
586 struct dirent *entry;
587 DIR *dir;
Eric Andersen11c65522000-09-07 17:24:47 +0000588 int i, nfiles;
589
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000590 if (path == NULL)
591 return (NULL);
Eric Andersen11c65522000-09-07 17:24:47 +0000592
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000593 dn = NULL;
594 nfiles = 0;
Eric Andersene7e1e2d2000-10-12 22:40:14 +0000595 dir = opendir(path);
Eric Andersen11c65522000-09-07 17:24:47 +0000596 if (dir == NULL) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000597 bb_perror_msg("%s", path);
Matt Kraai33fdae52000-10-13 17:59:43 +0000598 status = EXIT_FAILURE;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000599 return (NULL); /* could not open the dir */
Eric Andersen11c65522000-09-07 17:24:47 +0000600 }
601 while ((entry = readdir(dir)) != NULL) {
Glenn L McGrath4d001292003-01-06 01:11:50 +0000602 char *fullname;
603
Eric Andersen11c65522000-09-07 17:24:47 +0000604 /* are we going to list the file- it may be . or .. or a hidden file */
Glenn L McGrath4d001292003-01-06 01:11:50 +0000605 if (entry->d_name[0] == '.') {
606 if ((entry->d_name[1] == 0 || (
607 entry->d_name[1] == '.'
608 && entry->d_name[2] == 0))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000609 && !(all_fmt & DISP_DOT))
Matt Kraai782ab3c2001-04-23 01:07:00 +0000610 continue;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000611 if (!(all_fmt & DISP_HIDDEN))
Matt Kraai782ab3c2001-04-23 01:07:00 +0000612 continue;
Glenn L McGrath4d001292003-01-06 01:11:50 +0000613 }
614 fullname = concat_path_file(path, entry->d_name);
615 cur = my_stat(fullname, strrchr(fullname, '/') + 1);
616 if (!cur)
Eric Andersen11c65522000-09-07 17:24:47 +0000617 continue;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000618 cur->next = dn;
619 dn = cur;
Eric Andersen11c65522000-09-07 17:24:47 +0000620 nfiles++;
621 }
622 closedir(dir);
623
624 /* now that we know how many files there are
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000625 ** allocate memory for an array to hold dnode pointers
626 */
Glenn L McGrath4d001292003-01-06 01:11:50 +0000627 if (dn == NULL)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000628 return (NULL);
629 dnp = dnalloc(nfiles);
630 for (i = 0, cur = dn; i < nfiles; i++) {
631 dnp[i] = cur; /* save pointer to node in array */
632 cur = cur->next;
Eric Andersen11c65522000-09-07 17:24:47 +0000633 }
634
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000635 return (dnp);
Eric Andersen11c65522000-09-07 17:24:47 +0000636}
637
638/*----------------------------------------------------------------------*/
Eric Andersen3e6ff902001-03-09 21:24:12 +0000639static int list_single(struct dnode *dn)
Eric Andersen11c65522000-09-07 17:24:47 +0000640{
Glenn L McGrath4d001292003-01-06 01:11:50 +0000641 int i, column = 0;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000642
Matt Kraaia1bbde72002-03-08 16:25:33 +0000643#ifdef CONFIG_FEATURE_LS_USERNAME
Glenn L McGrath4d001292003-01-06 01:11:50 +0000644 char scratch[16];
Matt Kraaia1bbde72002-03-08 16:25:33 +0000645#endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000646#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Eric Andersen11c65522000-09-07 17:24:47 +0000647 char *filetime;
648 time_t ttime, age;
649#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000650#if defined(CONFIG_FEATURE_LS_FILETYPES) || defined (CONFIG_FEATURE_LS_COLOR)
Eric Andersen11c65522000-09-07 17:24:47 +0000651 struct stat info;
652 char append;
653#endif
654
Glenn L McGrath4d001292003-01-06 01:11:50 +0000655 if (dn->fullname == NULL)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000656 return (0);
Eric Andersen11c65522000-09-07 17:24:47 +0000657
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000658#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000659 ttime = dn->dstat.st_mtime; /* the default time */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000660 if (all_fmt & TIME_ACCESS)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000661 ttime = dn->dstat.st_atime;
Manuel Novoa III cad53642003-03-19 09:13:01 +0000662 if (all_fmt & TIME_CHANGE)
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000663 ttime = dn->dstat.st_ctime;
664 filetime = ctime(&ttime);
Eric Andersen11c65522000-09-07 17:24:47 +0000665#endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000666#ifdef CONFIG_FEATURE_LS_FILETYPES
Eric Andersen11c65522000-09-07 17:24:47 +0000667 append = append_char(dn->dstat.st_mode);
668#endif
669
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000670 for (i = 0; i <= 31; i++) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000671 switch (all_fmt & (1 << i)) {
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000672 case LIST_INO:
Glenn L McGrath4d001292003-01-06 01:11:50 +0000673 column += printf("%7ld ", (long int) dn->dstat.st_ino);
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000674 break;
675 case LIST_BLOCKS:
Eric Andersen8a2e56c2000-09-21 02:23:30 +0000676#if _FILE_OFFSET_BITS == 64
Glenn L McGrath4d001292003-01-06 01:11:50 +0000677 column += printf("%4lld ", dn->dstat.st_blocks >> 1);
Eric Andersen8a2e56c2000-09-21 02:23:30 +0000678#else
Glenn L McGrath4d001292003-01-06 01:11:50 +0000679 column += printf("%4ld ", dn->dstat.st_blocks >> 1);
Eric Andersen8a2e56c2000-09-21 02:23:30 +0000680#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000681 break;
682 case LIST_MODEBITS:
Manuel Novoa III cad53642003-03-19 09:13:01 +0000683 column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode));
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000684 break;
685 case LIST_NLINKS:
Glenn L McGrath4d001292003-01-06 01:11:50 +0000686 column += printf("%4ld ", (long) dn->dstat.st_nlink);
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000687 break;
688 case LIST_ID_NAME:
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000689#ifdef CONFIG_FEATURE_LS_USERNAME
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000690 my_getpwuid(scratch, dn->dstat.st_uid);
691 printf("%-8.8s ", scratch);
692 my_getgrgid(scratch, dn->dstat.st_gid);
693 printf("%-8.8s", scratch);
694 column += 17;
695 break;
Eric Andersen11c65522000-09-07 17:24:47 +0000696#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000697 case LIST_ID_NUMERIC:
Glenn L McGrath4d001292003-01-06 01:11:50 +0000698 column += printf("%-8d %-8d", dn->dstat.st_uid, dn->dstat.st_gid);
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000699 break;
700 case LIST_SIZE:
701 case LIST_DEV:
702 if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
Glenn L McGrath4d001292003-01-06 01:11:50 +0000703 column += printf("%4d, %3d ", (int) MAJOR(dn->dstat.st_rdev),
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000704 (int) MINOR(dn->dstat.st_rdev));
705 } else {
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000706#ifdef CONFIG_FEATURE_HUMAN_READABLE
Manuel Novoa III cad53642003-03-19 09:13:01 +0000707 if (all_fmt & LS_DISP_HR) {
Glenn L McGrath4d001292003-01-06 01:11:50 +0000708 column += printf("%9s ",
709 make_human_readable_str(dn->dstat.st_size, 1, 0));
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000710 } else
711#endif
712 {
Eric Andersen8a2e56c2000-09-21 02:23:30 +0000713#if _FILE_OFFSET_BITS == 64
Glenn L McGrath4d001292003-01-06 01:11:50 +0000714 column += printf("%9lld ", (long long) dn->dstat.st_size);
Eric Andersen8a2e56c2000-09-21 02:23:30 +0000715#else
Glenn L McGrath4d001292003-01-06 01:11:50 +0000716 column += printf("%9ld ", dn->dstat.st_size);
Eric Andersen8a2e56c2000-09-21 02:23:30 +0000717#endif
Eric Andersen11c65522000-09-07 17:24:47 +0000718 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000719 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000720 break;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000721#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000722 case LIST_FULLTIME:
Glenn L McGrath65b6d8b2004-01-18 05:41:30 +0000723 printf("%24.24s ", filetime);
724 column += 25;
725 break;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000726 case LIST_DATE_TIME:
Glenn L McGrath65b6d8b2004-01-18 05:41:30 +0000727 if ((all_fmt & LIST_FULLTIME) == 0) {
728 age = time(NULL) - ttime;
729 printf("%6.6s ", filetime + 4);
730 if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
731 /* hh:mm if less than 6 months old */
732 printf("%5.5s ", filetime + 11);
733 } else {
734 printf(" %4.4s ", filetime + 20);
735 }
736 column += 13;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000737 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000738 break;
Eric Andersen11c65522000-09-07 17:24:47 +0000739#endif
Eric Andersen9e480452003-07-03 10:07:04 +0000740#ifdef CONFIG_SELINUX
741 case LIST_CONTEXT:
742 {
743 char context[64];
744 int len = sizeof(context);
745 if(security_sid_to_context(dn->sid, context, &len))
746 {
747 strcpy(context, "unknown");
748 len = 7;
749 }
750 printf("%-32s ", context);
751 column += MAX(33, len);
752 }
753 break;
754#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000755 case LIST_FILENAME:
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000756#ifdef CONFIG_FEATURE_LS_COLOR
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000757 errno = 0;
758 if (show_color && !lstat(dn->fullname, &info)) {
759 printf("\033[%d;%dm", bgcolor(info.st_mode),
760 fgcolor(info.st_mode));
761 }
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000762#endif
Glenn L McGrath4d001292003-01-06 01:11:50 +0000763 column += printf("%s", dn->name);
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000764#ifdef CONFIG_FEATURE_LS_COLOR
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000765 if (show_color) {
766 printf("\033[0m");
767 }
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000768#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000769 break;
770 case LIST_SYMLINK:
771 if (S_ISLNK(dn->dstat.st_mode)) {
772 char *lpath = xreadlink(dn->fullname);
773
774 if (lpath) {
775 printf(" -> ");
776#if defined(CONFIG_FEATURE_LS_FILETYPES) || defined (CONFIG_FEATURE_LS_COLOR)
777 if (!stat(dn->fullname, &info)) {
778 append = append_char(info.st_mode);
Eric Andersen11c65522000-09-07 17:24:47 +0000779 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000780#endif
781#ifdef CONFIG_FEATURE_LS_COLOR
782 if (show_color) {
783 errno = 0;
784 printf("\033[%d;%dm", bgcolor(info.st_mode),
785 fgcolor(info.st_mode));
786 }
787#endif
Glenn L McGrath4d001292003-01-06 01:11:50 +0000788 column += printf("%s", lpath) + 4;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000789#ifdef CONFIG_FEATURE_LS_COLOR
790 if (show_color) {
791 printf("\033[0m");
792 }
793#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000794 free(lpath);
Eric Andersen11c65522000-09-07 17:24:47 +0000795 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000796 }
797 break;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000798#ifdef CONFIG_FEATURE_LS_FILETYPES
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000799 case LIST_FILETYPE:
800 if (append != '\0') {
801 printf("%1c", append);
802 column++;
803 }
804 break;
Eric Andersen11c65522000-09-07 17:24:47 +0000805#endif
806 }
807 }
808
Glenn L McGrath4d001292003-01-06 01:11:50 +0000809 return column;
Eric Andersen11c65522000-09-07 17:24:47 +0000810}
811
812/*----------------------------------------------------------------------*/
Manuel Novoa III cad53642003-03-19 09:13:01 +0000813
Glenn L McGrath792cae52004-01-18 05:15:16 +0000814/* "[-]Cadil1", POSIX mandated options, busybox always supports */
815/* "[-]gnsx", POSIX non-mandated options, busybox always supports */
816/* "[-]Ak" GNU options, busybox always supports */
817/* "[-]FLRctur", POSIX mandated options, busybox optionally supports */
818/* "[-]p", POSIX non-mandated options, busybox optionally supports */
819/* "[-]SXvThw", GNU options, busybox optionally supports */
820/* "[-]K", SELinux mandated options, busybox optionally supports */
821/* "[-]e", I think we made this one up */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000822
Glenn L McGrath792cae52004-01-18 05:15:16 +0000823#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
824# define LS_STR_TIMESTAMPS "cetu"
825#else
826# define LS_STR_TIMESTAMPS ""
827#endif
828
829#ifdef CONFIG_FEATURE_LS_SORTFILES
830# define LS_STR_SORTFILES "SXrv"
831#else
832# define LS_STR_SORTFILES ""
833#endif
834
835#ifdef CONFIG_FEATURE_LS_FILETYPES
836# define LS_STR_FILETYPES "Fp"
837#else
838# define LS_STR_FILETYPES ""
839#endif
840
841#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
842# define LS_STR_FOLLOW_LINKS "L"
843#else
844# define LS_STR_FOLLOW_LINKS ""
845#endif
846
847#ifdef CONFIG_FEATURE_LS_RECURSIVE
848# define LS_STR_RECURSIVE "R"
849#else
850# define LS_STR_RECURSIVE ""
851#endif
852
853#ifdef CONFIG_FEATURE_HUMAN_READABLE
854# define LS_STR_HUMAN_READABLE "h"
855#else
856# define LS_STR_HUMAN_READABLE ""
857#endif
858
859#ifdef CONFIG_SELINUX
860# define LS_STR_SELINUX "K"
861#else
862# define LS_STR_SELINUX ""
863#endif
864
865#ifdef CONFIG_FEATURE_AUTOWIDTH
866# define LS_STR_AUTOWIDTH "T:w:"
867#else
868# define LS_STR_AUTOWIDTH ""
869#endif
870
871static const char ls_options[]="Cadil1gnsxAk" \
872 LS_STR_TIMESTAMPS \
873 LS_STR_SORTFILES \
874 LS_STR_FILETYPES \
875 LS_STR_FOLLOW_LINKS \
876 LS_STR_RECURSIVE \
877 LS_STR_HUMAN_READABLE \
878 LS_STR_SELINUX \
879 LS_STR_AUTOWIDTH;
880
881#define LIST_MASK_TRIGGER LIST_SHORT
882#define STYLE_MASK_TRIGGER STYLE_MASK
883#define SORT_MASK_TRIGGER SORT_MASK
884#define DISP_MASK_TRIGGER DISP_ROWS
885#define TIME_MASK_TRIGGER TIME_MASK
Manuel Novoa III cad53642003-03-19 09:13:01 +0000886
887static const unsigned opt_flags[] = {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000888 LIST_SHORT | STYLE_COLUMNS, /* C */
Glenn L McGrath792cae52004-01-18 05:15:16 +0000889 DISP_HIDDEN | DISP_DOT, /* a */
890 DISP_NOLIST, /* d */
891 LIST_INO, /* i */
892 LIST_LONG | STYLE_LONG, /* l - remember LS_DISP_HR in mask! */
893 LIST_SHORT | STYLE_SINGLE, /* 1 */
894 0, /* g - ingored */
895 LIST_ID_NUMERIC, /* n */
896 LIST_BLOCKS, /* s */
897 DISP_ROWS, /* x */
898 DISP_HIDDEN, /* A */
899#ifdef CONFIG_SELINUX
900 LIST_CONTEXT, /* k */
901#else
902 0, /* k - ingored */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000903#endif
904#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Glenn L McGrath792cae52004-01-18 05:15:16 +0000905# ifdef CONFIG_FEATURE_LS_SORTFILES
Manuel Novoa III cad53642003-03-19 09:13:01 +0000906 TIME_CHANGE | SORT_CTIME, /* c */
Glenn L McGrath792cae52004-01-18 05:15:16 +0000907# else
908 TIME_CHANGE, /* c */
909# endif
910 LIST_FULLTIME, /* e */
911# ifdef CONFIG_FEATURE_LS_SORTFILES
912 SORT_MTIME, /* t */
913# else
914 0, /* t - ignored -- is this correct? */
915# endif
916# ifdef CONFIG_FEATURE_LS_SORTFILES
Manuel Novoa III cad53642003-03-19 09:13:01 +0000917 TIME_ACCESS | SORT_ATIME, /* u */
Glenn L McGrath792cae52004-01-18 05:15:16 +0000918# else
919 TIME_ACCESS, /* u */
920# endif
Manuel Novoa III cad53642003-03-19 09:13:01 +0000921#endif
922#ifdef CONFIG_FEATURE_LS_SORTFILES
Glenn L McGrath792cae52004-01-18 05:15:16 +0000923 SORT_SIZE, /* S */
Manuel Novoa III 1117c522004-03-08 10:54:29 +0000924 SORT_EXT, /* X */
925 SORT_ORDER_REVERSE, /* r */
Glenn L McGrath792cae52004-01-18 05:15:16 +0000926 SORT_VERSION, /* v */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000927#endif
Glenn L McGrath792cae52004-01-18 05:15:16 +0000928#ifdef CONFIG_FEATURE_LS_FILETYPES
929 LIST_FILETYPE | LIST_EXEC, /* F */
930 LIST_FILETYPE, /* p */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000931#endif
932#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
Glenn L McGrath792cae52004-01-18 05:15:16 +0000933 FOLLOW_LINKS, /* L */
934#endif
935#ifdef CONFIG_FEATURE_LS_RECURSIVE
936 DISP_RECURSIVE, /* R */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000937#endif
938#ifdef CONFIG_FEATURE_HUMAN_READABLE
Glenn L McGrath792cae52004-01-18 05:15:16 +0000939 LS_DISP_HR, /* h */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000940#endif
Glenn L McGrath792cae52004-01-18 05:15:16 +0000941#ifdef CONFIG_SELINUX
Eric Andersen9e480452003-07-03 10:07:04 +0000942 LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */
943#endif
Eric Andersend07cf592004-02-05 13:52:03 +0000944 (1U<<31)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000945};
946
947
948/*----------------------------------------------------------------------*/
949
Eric Andersen11c65522000-09-07 17:24:47 +0000950extern int ls_main(int argc, char **argv)
951{
Glenn L McGrath792cae52004-01-18 05:15:16 +0000952 struct dnode **dnd;
953 struct dnode **dnf;
954 struct dnode **dnp;
955 struct dnode *dn;
956 struct dnode *cur;
957 long opt;
958 int nfiles = 0;
959 int dnfiles;
960 int dndirs;
961 int oi;
962 int ac;
963 int i;
Eric Andersen11c65522000-09-07 17:24:47 +0000964 char **av;
Glenn L McGrath792cae52004-01-18 05:15:16 +0000965#ifdef CONFIG_FEATURE_AUTOWIDTH
966 char *tabstops_str = NULL;
967 char *terminal_width_str = NULL;
968#endif
969
Eric Andersen9e480452003-07-03 10:07:04 +0000970#ifdef CONFIG_SELINUX
971 is_flask_enabled_flag = is_flask_enabled();
972#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +0000973
Manuel Novoa III cad53642003-03-19 09:13:01 +0000974 all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000975#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Manuel Novoa III cad53642003-03-19 09:13:01 +0000976 | TIME_MOD
Eric Andersen11c65522000-09-07 17:24:47 +0000977#endif
Manuel Novoa III cad53642003-03-19 09:13:01 +0000978#ifdef CONFIG_FEATURE_LS_SORTFILES
979 | SORT_NAME | SORT_ORDER_FORWARD
980#endif
981 ;
Glenn L McGrath792cae52004-01-18 05:15:16 +0000982
Eric Andersen6d687812003-11-04 23:16:48 +0000983#ifdef CONFIG_FEATURE_AUTOWIDTH
Eric Andersen8efe9672003-09-15 08:33:45 +0000984 /* Obtain the terminal width. */
985 get_terminal_width_height(0, &terminal_width, NULL);
986 /* Go one less... */
987 terminal_width--;
Eric Andersen6d687812003-11-04 23:16:48 +0000988#endif
Eric Andersen11c65522000-09-07 17:24:47 +0000989
Eric Andersen3ad0bd92002-03-20 09:13:48 +0000990#ifdef CONFIG_FEATURE_LS_COLOR
991 if (isatty(fileno(stdout)))
992 show_color = 1;
993#endif
994
Eric Andersen11c65522000-09-07 17:24:47 +0000995 /* process options */
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000996#ifdef CONFIG_FEATURE_AUTOWIDTH
Glenn L McGrath792cae52004-01-18 05:15:16 +0000997 opt = bb_getopt_ulflags(argc, argv, ls_options, &tabstops_str, &terminal_width_str);
998 if (tabstops_str) {
999 tabstops = atoi(tabstops_str);
1000 }
1001 if (terminal_width_str) {
1002 terminal_width = atoi(terminal_width_str);
1003 }
1004#else
1005 opt = bb_getopt_ulflags(argc, argv, ls_options);
Manuel Novoa III cad53642003-03-19 09:13:01 +00001006#endif
Eric Andersend07cf592004-02-05 13:52:03 +00001007 for (i = 0; opt_flags[i] != (1U<<31); i++) {
Glenn L McGrath792cae52004-01-18 05:15:16 +00001008 if (opt & (1 << i)) {
1009 unsigned int flags = opt_flags[i];
Manuel Novoa III cad53642003-03-19 09:13:01 +00001010 if (flags & LIST_MASK_TRIGGER) {
1011 all_fmt &= ~LIST_MASK;
1012 }
1013 if (flags & STYLE_MASK_TRIGGER) {
1014 all_fmt &= ~STYLE_MASK;
1015 }
Eric Andersenb7ebc612003-07-14 19:20:46 +00001016#ifdef CONFIG_FEATURE_LS_SORTFILES
Manuel Novoa III cad53642003-03-19 09:13:01 +00001017 if (flags & SORT_MASK_TRIGGER) {
1018 all_fmt &= ~SORT_MASK;
1019 }
Eric Andersenb7ebc612003-07-14 19:20:46 +00001020#endif
Manuel Novoa III cad53642003-03-19 09:13:01 +00001021 if (flags & DISP_MASK_TRIGGER) {
1022 all_fmt &= ~DISP_MASK;
1023 }
Eric Andersenb7ebc612003-07-14 19:20:46 +00001024#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
Manuel Novoa III cad53642003-03-19 09:13:01 +00001025 if (flags & TIME_MASK_TRIGGER) {
1026 all_fmt &= ~TIME_MASK;
1027 }
Eric Andersenb7ebc612003-07-14 19:20:46 +00001028#endif
Eric Andersen9e480452003-07-03 10:07:04 +00001029 if (flags & LIST_CONTEXT) {
1030 all_fmt |= STYLE_SINGLE;
1031 }
Manuel Novoa III cad53642003-03-19 09:13:01 +00001032#ifdef CONFIG_FEATURE_HUMAN_READABLE
1033 if (opt == 'l') {
1034 all_fmt &= ~LS_DISP_HR;
1035 }
1036#endif
1037 all_fmt |= flags;
1038 }
Eric Andersen11c65522000-09-07 17:24:47 +00001039 }
1040
1041 /* sort out which command line options take precedence */
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001042#ifdef CONFIG_FEATURE_LS_RECURSIVE
Manuel Novoa III cad53642003-03-19 09:13:01 +00001043 if (all_fmt & DISP_NOLIST)
1044 all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */
Eric Andersen11c65522000-09-07 17:24:47 +00001045#endif
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001046#if defined (CONFIG_FEATURE_LS_TIMESTAMPS) && defined (CONFIG_FEATURE_LS_SORTFILES)
Manuel Novoa III cad53642003-03-19 09:13:01 +00001047 if (all_fmt & TIME_CHANGE)
1048 all_fmt = (all_fmt & ~SORT_MASK) | SORT_CTIME;
1049 if (all_fmt & TIME_ACCESS)
1050 all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME;
Eric Andersen11c65522000-09-07 17:24:47 +00001051#endif
Manuel Novoa III cad53642003-03-19 09:13:01 +00001052 if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* only for long list */
1053 all_fmt &= ~(LIST_ID_NUMERIC|LIST_FULLTIME|LIST_ID_NAME|LIST_ID_NUMERIC);
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001054#ifdef CONFIG_FEATURE_LS_USERNAME
Manuel Novoa III cad53642003-03-19 09:13:01 +00001055 if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC))
1056 all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */
Eric Andersen11c65522000-09-07 17:24:47 +00001057#endif
Manuel Novoa III cad53642003-03-19 09:13:01 +00001058
Eric Andersen11c65522000-09-07 17:24:47 +00001059 /* choose a display format */
Manuel Novoa III cad53642003-03-19 09:13:01 +00001060 if ((all_fmt & STYLE_MASK) == STYLE_AUTO)
1061#if STYLE_AUTO != 0
1062 all_fmt = (all_fmt & ~STYLE_MASK)
1063 | (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE);
1064#else
1065 all_fmt |= (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE);
1066#endif
Eric Andersen11c65522000-09-07 17:24:47 +00001067
1068 /*
1069 * when there are no cmd line args we have to supply a default "." arg.
1070 * we will create a second argv array, "av" that will hold either
1071 * our created "." arg, or the real cmd line args. The av array
1072 * just holds the pointers- we don't move the date the pointers
1073 * point to.
1074 */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001075 ac = argc - optind; /* how many cmd line args are left */
Eric Andersen11c65522000-09-07 17:24:47 +00001076 if (ac < 1) {
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001077 av = (char **) xcalloc((size_t) 1, (size_t) (sizeof(char *)));
Manuel Novoa III cad53642003-03-19 09:13:01 +00001078 av[0] = bb_xstrdup(".");
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001079 ac = 1;
Eric Andersen11c65522000-09-07 17:24:47 +00001080 } else {
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001081 av = (char **) xcalloc((size_t) ac, (size_t) (sizeof(char *)));
1082 for (oi = 0; oi < ac; oi++) {
1083 av[oi] = argv[optind++]; /* copy pointer to real cmd line arg */
Eric Andersen11c65522000-09-07 17:24:47 +00001084 }
1085 }
1086
1087 /* now, everything is in the av array */
1088 if (ac > 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +00001089 all_fmt |= DISP_DIRNAME; /* 2 or more items? label directories */
Eric Andersen11c65522000-09-07 17:24:47 +00001090
1091 /* stuff the command line file names into an dnode array */
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001092 dn = NULL;
1093 for (oi = 0; oi < ac; oi++) {
Manuel Novoa III cad53642003-03-19 09:13:01 +00001094 char *fullname = bb_xstrdup(av[oi]);
Glenn L McGrath4d001292003-01-06 01:11:50 +00001095
1096 cur = my_stat(fullname, fullname);
1097 if (!cur)
Eric Andersen11c65522000-09-07 17:24:47 +00001098 continue;
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001099 cur->next = dn;
1100 dn = cur;
Eric Andersen11c65522000-09-07 17:24:47 +00001101 nfiles++;
1102 }
1103
1104 /* now that we know how many files there are
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001105 ** allocate memory for an array to hold dnode pointers
1106 */
1107 dnp = dnalloc(nfiles);
1108 for (i = 0, cur = dn; i < nfiles; i++) {
1109 dnp[i] = cur; /* save pointer to node in array */
1110 cur = cur->next;
Eric Andersen11c65522000-09-07 17:24:47 +00001111 }
1112
Manuel Novoa III cad53642003-03-19 09:13:01 +00001113 if (all_fmt & DISP_NOLIST) {
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001114#ifdef CONFIG_FEATURE_LS_SORTFILES
Eric Andersen11c65522000-09-07 17:24:47 +00001115 shellsort(dnp, nfiles);
1116#endif
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001117 if (nfiles > 0)
1118 showfiles(dnp, nfiles);
Eric Andersen11c65522000-09-07 17:24:47 +00001119 } else {
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001120 dnd = splitdnarray(dnp, nfiles, SPLIT_DIR);
1121 dnf = splitdnarray(dnp, nfiles, SPLIT_FILE);
1122 dndirs = countdirs(dnp, nfiles);
1123 dnfiles = nfiles - dndirs;
Eric Andersen11c65522000-09-07 17:24:47 +00001124 if (dnfiles > 0) {
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001125#ifdef CONFIG_FEATURE_LS_SORTFILES
Eric Andersen11c65522000-09-07 17:24:47 +00001126 shellsort(dnf, dnfiles);
1127#endif
1128 showfiles(dnf, dnfiles);
1129 }
1130 if (dndirs > 0) {
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001131#ifdef CONFIG_FEATURE_LS_SORTFILES
Eric Andersen11c65522000-09-07 17:24:47 +00001132 shellsort(dnd, dndirs);
1133#endif
Glenn L McGrathc4db0832004-03-06 09:12:55 +00001134 showdirs(dnd, dndirs, dnfiles == 0);
Eric Andersen11c65522000-09-07 17:24:47 +00001135 }
1136 }
Glenn L McGrathe3906fc2002-08-22 18:13:54 +00001137 return (status);
Eric Andersencc8ed391999-10-05 16:24:54 +00001138}