1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) tons of folks. Tracking down who wrote what
6 * isn't something I'm going to worry about... If you wrote something
7 * here, please feel free to acknowledge your work.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
24 * Permission has been granted to redistribute this code under the GPL.
29 #if defined (BB_CHMOD_CHOWN_CHGRP) \
30 || defined (BB_CP_MV) \
31 || defined (BB_FIND) \
33 || defined (BB_INSMOD)
34 /* same conditions as recursiveAction */
35 #define bb_need_name_too_long
37 #define BB_DECLARE_EXTERN
50 #include <sys/param.h> /* for PATH_MAX */
52 #if defined BB_FEATURE_MOUNT_LOOP
54 #include <sys/ioctl.h>
55 #include <linux/loop.h>
59 #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
60 # if defined BB_FEATURE_USE_PROCFS
61 const char mtab_file[] = "/proc/mounts";
64 const char mtab_file[] = "/etc/mtab";
66 # error With (BB_MOUNT||BB_UMOUNT||BB_DF) defined, you must define either BB_MTAB or BB_FEATURE_USE_PROCFS
72 extern void usage(const char *usage)
74 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
76 fprintf(stderr, "Usage: %s\n", usage);
80 extern void errorMsg(char *s, ...)
86 fprintf(stderr, "\n");
87 vfprintf(stderr, s, p);
88 fprintf(stderr, "\n");
92 extern void fatalError(char *s, ...)
98 fprintf(stderr, "\n");
99 vfprintf(stderr, s, p);
100 fprintf(stderr, "\n");
105 #if defined (BB_INIT) || defined (BB_PS)
107 #if ! defined BB_FEATURE_USE_PROCFS
108 #error Sorry, I depend on the /proc filesystem right now.
110 /* Returns kernel version encoded as major*65536 + minor*256 + patch,
111 * so, for example, to check if the kernel is greater than 2.2.11:
112 * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
114 int get_kernel_revision()
117 int major = 0, minor = 0, patch = 0;
119 file = fopen("/proc/sys/kernel/osrelease", "r");
121 /* bummer, /proc must not be mounted... */
124 fscanf(file, "%d.%d.%d", &major, &minor, &patch);
126 return major * 65536 + minor * 256 + patch;
128 #endif /* BB_INIT || BB_PS */
132 #if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN)
134 * Return TRUE if a fileName is a directory.
135 * Nonexistant files return FALSE.
137 int isDirectory(const char *fileName, const int followLinks, struct stat *statBuf)
142 if (statBuf == NULL) {
143 statBuf = (struct stat *)xmalloc(sizeof(struct stat));
147 if (followLinks == TRUE)
148 status = stat(fileName, statBuf);
150 status = lstat(fileName, statBuf);
152 if (status < 0 || !(S_ISDIR(statBuf->st_mode))) {
165 #if defined (BB_CP_MV)
167 * Copy one file to another, while possibly preserving its modes, times,
168 * and modes. Returns TRUE if successful, or FALSE on a failure with an
169 * error message output. (Failure is not indicted if the attributes cannot
174 copyFile(const char *srcName, const char *destName,
175 int setModes, int followLinks)
182 struct stat srcStatBuf;
183 struct stat dstStatBuf;
184 struct utimbuf times;
186 if (followLinks == TRUE)
187 status = stat(srcName, &srcStatBuf);
189 status = lstat(srcName, &srcStatBuf);
196 if (followLinks == TRUE)
197 status = stat(destName, &dstStatBuf);
199 status = lstat(destName, &dstStatBuf);
202 dstStatBuf.st_ino = -1;
203 dstStatBuf.st_dev = -1;
206 if ((srcStatBuf.st_dev == dstStatBuf.st_dev) &&
207 (srcStatBuf.st_ino == dstStatBuf.st_ino)) {
208 fprintf(stderr, "Copying file \"%s\" to itself\n", srcName);
212 if (S_ISDIR(srcStatBuf.st_mode)) {
213 //fprintf(stderr, "copying directory %s to %s\n", srcName, destName);
214 /* Make sure the directory is writable */
215 status = mkdir(destName, 0777777 ^ umask(0));
216 if (status < 0 && errno != EEXIST) {
220 } else if (S_ISLNK(srcStatBuf.st_mode)) {
221 char link_val[PATH_MAX + 1];
224 //fprintf(stderr, "copying link %s to %s\n", srcName, destName);
225 /* Warning: This could possibly truncate silently, to PATH_MAX chars */
226 link_size = readlink(srcName, &link_val[0], PATH_MAX);
231 link_val[link_size] = '\0';
232 status = symlink(link_val, destName);
237 #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
238 if (setModes == TRUE) {
239 if (lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) {
246 } else if (S_ISFIFO(srcStatBuf.st_mode)) {
247 //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName);
248 if (mkfifo(destName, 0644) < 0) {
252 } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode)
253 || S_ISSOCK(srcStatBuf.st_mode)) {
254 //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName);
255 if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) {
259 } else if (S_ISREG(srcStatBuf.st_mode)) {
260 //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName);
261 rfd = open(srcName, O_RDONLY);
268 open(destName, O_WRONLY | O_CREAT | O_TRUNC,
276 while ((rcc = read(rfd, buf, sizeof(buf))) > 0) {
277 if (fullWrite(wfd, buf, rcc) < 0)
285 if (close(wfd) < 0) {
290 if (setModes == TRUE) {
291 /* This is fine, since symlinks never get here */
292 if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) {
296 if (chmod(destName, srcStatBuf.st_mode) < 0) {
300 times.actime = srcStatBuf.st_atime;
301 times.modtime = srcStatBuf.st_mtime;
302 if (utime(destName, ×) < 0) {
317 #endif /* BB_CP_MV */
321 #if defined BB_TAR || defined BB_LS
323 #define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
324 #define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
326 /* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
327 static const mode_t SBIT[] = {
333 /* The 9 mode bits to test */
334 static const mode_t MBIT[] = {
335 S_IRUSR, S_IWUSR, S_IXUSR,
336 S_IRGRP, S_IWGRP, S_IXGRP,
337 S_IROTH, S_IWOTH, S_IXOTH
340 #define MODE1 "rwxrwxrwx"
341 #define MODE0 "---------"
342 #define SMODE1 "..s..s..t"
343 #define SMODE0 "..S..S..T"
346 * Return the standard ls-like mode string from a file mode.
347 * This is static and so is overwritten on each call.
349 const char *modeString(int mode)
355 buf[0] = TYPECHAR(mode);
356 for (i = 0; i < 9; i++) {
358 buf[i + 1] = (mode & MBIT[i]) ? SMODE1[i] : SMODE0[i];
360 buf[i + 1] = (mode & MBIT[i]) ? MODE1[i] : MODE0[i];
364 #endif /* BB_TAR || BB_LS */
369 * Return the standard ls-like time string from a time_t
370 * This is static and so is overwritten on each call.
372 const char *timeString(time_t timeVal)
380 str = ctime(&timeVal);
382 strcpy(buf, &str[4]);
385 if ((timeVal > now) || (timeVal < now - 365 * 24 * 60 * 60L)) {
386 strcpy(&buf[7], &str[20]);
394 #if defined BB_TAR || defined BB_CP_MV
396 * Write all of the supplied buffer out to a file.
397 * This does multiple writes as necessary.
398 * Returns the amount written, or -1 on an error.
400 int fullWrite(int fd, const char *buf, int len)
408 cc = write(fd, buf, len);
420 #endif /* BB_TAR || BB_CP_MV */
423 #if defined BB_TAR || defined BB_TAIL
425 * Read all of the supplied buffer from a file.
426 * This does multiple reads as necessary.
427 * Returns the amount read, or -1 on an error.
428 * A short read is returned on an end of file.
430 int fullRead(int fd, char *buf, int len)
438 cc = read(fd, buf, len);
453 #endif /* BB_TAR || BB_TAIL */
456 #if defined (BB_CHMOD_CHOWN_CHGRP) \
457 || defined (BB_CP_MV) \
458 || defined (BB_FIND) \
460 || defined (BB_INSMOD)
462 * Walk down all the directories under the specified
463 * location, and do something (something specified
464 * by the fileAction and dirAction function pointers).
466 * Unfortunatly, while nftw(3) could replace this and reduce
467 * code size a bit, nftw() wasn't supported before GNU libc 2.1,
468 * and so isn't sufficiently portable to take over since glibc2.1
469 * is so stinking huge.
471 int recursiveAction(const char *fileName,
472 int recurse, int followLinks, int depthFirst,
473 int (*fileAction) (const char *fileName,
474 struct stat * statbuf),
475 int (*dirAction) (const char *fileName,
476 struct stat * statbuf))
482 if (followLinks == TRUE)
483 status = stat(fileName, &statbuf);
485 status = lstat(fileName, &statbuf);
488 #ifdef BB_DEBUG_PRINT_SCAFFOLD
490 "status=%d followLinks=%d TRUE=%d\n",
491 status, followLinks, TRUE);
497 if ((followLinks == FALSE) && (S_ISLNK(statbuf.st_mode))) {
498 if (fileAction == NULL)
501 return fileAction(fileName, &statbuf);
504 if (recurse == FALSE) {
505 if (S_ISDIR(statbuf.st_mode)) {
506 if (dirAction != NULL)
507 return (dirAction(fileName, &statbuf));
513 if (S_ISDIR(statbuf.st_mode)) {
516 dir = opendir(fileName);
521 if (dirAction != NULL && depthFirst == FALSE) {
522 status = dirAction(fileName, &statbuf);
523 if (status == FALSE) {
528 while ((next = readdir(dir)) != NULL) {
529 char nextFile[PATH_MAX + 1];
531 if ((strcmp(next->d_name, "..") == 0)
532 || (strcmp(next->d_name, ".") == 0)) {
535 if (strlen(fileName) + strlen(next->d_name) + 1 > PATH_MAX) {
536 fprintf(stderr, name_too_long, "ftw");
539 sprintf(nextFile, "%s/%s", fileName, next->d_name);
541 recursiveAction(nextFile, TRUE, followLinks, depthFirst,
542 fileAction, dirAction);
548 status = closedir(dir);
553 if (dirAction != NULL && depthFirst == TRUE) {
554 status = dirAction(fileName, &statbuf);
555 if (status == FALSE) {
561 if (fileAction == NULL)
564 return fileAction(fileName, &statbuf);
569 #endif /* BB_CHMOD_CHOWN_CHGRP || BB_CP_MV || BB_FIND || BB_LS || BB_INSMOD */
573 #if defined (BB_TAR) || defined (BB_MKDIR)
575 * Attempt to create the directories along the specified path, except for
576 * the final component. The mode is given for the final directory only,
577 * while all previous ones get default protections. Errors are not reported
578 * here, as failures to restore files can be reported later.
580 extern int createPath(const char *name, int mode)
584 char buf[PATH_MAX + 1];
588 for (cp = buf; *cp == '/'; cp++);
589 cp = strchr(cp, '/');
592 cp = strchr(cp + 1, '/');
594 retVal = mkdir(buf, cp ? 0777 : mode);
595 if (retVal != 0 && errno != EEXIST) {
603 #endif /* BB_TAR || BB_MKDIR */
607 #if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR)
608 /* [ugoa]{+|-|=}[rwxst] */
612 extern int parse_mode(const char *s, mode_t * theMode)
616 S_ISVTX | S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
629 groups |= S_ISUID | S_IRWXU;
632 groups |= S_ISGID | S_IRWXG;
638 groups |= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
644 if (groups == 0) /* The default is "all" */
646 S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
649 if (isdigit(c) && c >= '0' && c <= '7' &&
650 mode == 0 && groups == 0) {
651 *theMode = strtol(--s, NULL, 8);
659 while ((c = *s++) != '\0') {
664 mode |= S_IRUSR | S_IRGRP | S_IROTH;
667 mode |= S_IWUSR | S_IWGRP | S_IWOTH;
670 mode |= S_IXUSR | S_IXGRP | S_IXOTH;
673 mode |= S_IXGRP | S_ISUID | S_ISGID;
687 andMode &= ~(groups);
690 orMode |= mode & groups;
693 andMode &= ~(mode & groups);
704 #endif /* BB_CHMOD_CHOWN_CHGRP || BB_MKDIR */
712 #if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_PS)
714 /* Use this to avoid needing the glibc NSS stuff
715 * This uses storage buf to hold things.
717 uid_t my_getid(const char *filename, char *name, uid_t id)
720 char *rname, *start, *end, buf[128];
723 file = fopen(filename, "r");
729 while (fgets(buf, 128, file) != NULL) {
734 end = strchr(start, ':');
741 end = strchr(start, ':');
746 rid = (uid_t) strtol(start, &end, 10);
751 if (0 == strcmp(rname, name)) {
756 if (id != -1 && id == rid) {
757 strncpy(name, rname, 8);
766 uid_t my_getpwnam(char *name)
768 return my_getid("/etc/passwd", name, -1);
771 gid_t my_getgrnam(char *name)
773 return my_getid("/etc/group", name, -1);
776 void my_getpwuid(char *name, uid_t uid)
778 my_getid("/etc/passwd", name, uid);
781 void my_getgrgid(char *group, gid_t gid)
783 my_getid("/etc/group", group, gid);
787 #endif /* BB_CHMOD_CHOWN_CHGRP || BB_PS */
792 #if (defined BB_CHVT) || (defined BB_DEALLOCVT)
795 #include <linux/kd.h>
796 #include <sys/ioctl.h>
798 int is_a_console(int fd)
803 return (ioctl(fd, KDGKBTYPE, &arg) == 0
804 && ((arg == KB_101) || (arg == KB_84)));
807 static int open_a_console(char *fnam)
812 fd = open(fnam, O_RDWR);
814 /* if failed, try read-only */
815 if (fd < 0 && errno == EACCES)
816 fd = open(fnam, O_RDONLY);
818 /* if failed, try write-only */
819 if (fd < 0 && errno == EACCES)
820 fd = open(fnam, O_WRONLY);
822 /* if failed, fail */
826 /* if not a console, fail */
827 if (!is_a_console(fd)) {
837 * Get an fd for use with kbd/console ioctls.
838 * We try several things because opening /dev/console will fail
839 * if someone else used X (which does a chown on /dev/console).
841 * if tty_name is non-NULL, try this one instead.
844 int get_console_fd(char *tty_name)
849 if (-1 == (fd = open_a_console(tty_name)))
855 fd = open_a_console("/dev/tty");
859 fd = open_a_console("/dev/tty0");
863 fd = open_a_console("/dev/console");
867 for (fd = 0; fd < 3; fd++)
868 if (is_a_console(fd))
872 "Couldnt get a file descriptor referring to the console\n");
873 return -1; /* total failure */
877 #endif /* BB_CHVT || BB_DEALLOCVT */
880 #if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED)
882 /* Do a case insensitive strstr() */
883 char *stristr(char *haystack, const char *needle)
885 int len = strlen(needle);
888 if (!strncasecmp(haystack, needle, len))
899 /* This tries to find a needle in a haystack, but does so by
900 * only trying to match literal strings (look 'ma, no regexps!)
901 * This is short, sweet, and carries _very_ little baggage,
902 * unlike its beefier cousin in regexp.c
905 extern int find_match(char *haystack, char *needle, int ignoreCase)
908 if (ignoreCase == FALSE)
909 haystack = strstr(haystack, needle);
911 haystack = stristr(haystack, needle);
912 if (haystack == NULL)
918 /* This performs substitutions after a string match has been found. */
919 extern int replace_match(char *haystack, char *needle, char *newNeedle,
923 char *where, *slider, *slider1, *oldhayStack;
925 if (ignoreCase == FALSE)
926 where = strstr(haystack, needle);
928 where = stristr(haystack, needle);
930 if (strcmp(needle, newNeedle) == 0)
933 oldhayStack = (char *) malloc((unsigned) (strlen(haystack)));
934 while (where != NULL) {
936 strcpy(oldhayStack, haystack);
938 if (strlen(newNeedle) > strlen(needle)) {
940 (char *) realloc(haystack,
941 (unsigned) (strlen(haystack) -
946 for (slider = haystack, slider1 = oldhayStack; slider != where;
947 slider++, slider1++);
949 haystack = strcat(haystack, newNeedle);
950 slider1 += strlen(needle);
951 haystack = strcat(haystack, slider1);
952 where = strstr(slider, needle);
962 #endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */
967 * Routine to see if a text string is matched by a wildcard pattern.
968 * Returns TRUE if the text is matched, or FALSE if it is not matched
969 * or if the pattern is invalid.
970 * * matches zero or more characters
971 * ? matches a single character
972 * [abc] matches 'a', 'b' or 'c'
973 * \c quotes character c
974 * Adapted from code written by Ingo Wilken, and
975 * then taken from sash, Copyright (c) 1999 by David I. Bell
976 * Permission is granted to use, distribute, or modify this source,
977 * provided that this copyright notice remains intact.
978 * Permission to distribute this code under the GPL has been granted.
980 extern int check_wildcard_match(const char *text, const char *pattern)
982 const char *retryPat;
983 const char *retryText;
990 while (*text || *pattern) {
1002 while ((ch = *pattern++) != ']') {
1014 if (found == TRUE) {
1019 /* fall into next case */
1022 if (*text++ == '\0')
1033 /* fall into next case */
1051 if (pattern == NULL)
1057 #endif /* BB_FIND */
1062 #if defined BB_DF || defined BB_MTAB
1064 * Given a block device, find the mount table entry if that block device
1067 * Given any other file (or directory), find the mount table entry for its
1070 extern struct mntent *findMountPoint(const char *name, const char *table)
1075 struct mntent *mountEntry;
1077 if (stat(name, &s) != 0)
1080 if ((s.st_mode & S_IFMT) == S_IFBLK)
1081 mountDevice = s.st_rdev;
1083 mountDevice = s.st_dev;
1086 if ((mountTable = setmntent(table, "r")) == 0)
1089 while ((mountEntry = getmntent(mountTable)) != 0) {
1090 if (strcmp(name, mountEntry->mnt_dir) == 0
1091 || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
1093 if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
1095 if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
1098 endmntent(mountTable);
1101 #endif /* BB_DF || BB_MTAB */
1105 #if defined BB_DD || defined BB_TAIL
1107 * Read a number with a possible multiplier.
1108 * Returns -1 if the number format is illegal.
1110 extern long getNum(const char *cp)
1114 if (!isDecimal(*cp))
1119 while (isDecimal(*cp))
1120 value = value * 10 + *cp++ - '0';
1124 case 'm': /* `tail' uses it traditionally */
1152 #endif /* BB_DD || BB_TAIL */
1155 #if defined BB_INIT || defined BB_SYSLOGD
1156 /* try to open up the specified device */
1157 extern int device_open(char *device, int mode)
1161 m = mode | O_NONBLOCK;
1163 /* Retry up to 5 times */
1164 for (f = 0; f < 5; f++)
1165 if ((fd = open(device, m, 0600)) >= 0)
1169 /* Reset original flags. */
1171 fcntl(fd, F_SETFL, mode);
1174 #endif /* BB_INIT BB_SYSLOGD */
1177 #if defined BB_INIT || defined BB_HALT || defined BB_REBOOT
1179 #if ! defined BB_FEATURE_USE_PROCFS
1180 #error Sorry, I depend on the /proc filesystem right now.
1184 * This finds the pid of init (which is not always 1).
1185 * Currently, it's implemented by rummaging through the proc filesystem.
1189 * pid when init's pid is found.
1191 extern pid_t findInitPid()
1197 /* no need to opendir ;) */
1198 for (init_pid = 1; init_pid < 65536; init_pid++) {
1201 sprintf(filename, "/proc/%d/status", init_pid);
1202 status = fopen(filename, "r");
1206 fgets(buffer, 256, status);
1209 if ((strstr(buffer, "init\n") != NULL)) {
1215 #endif /* BB_INIT || BB_HALT || BB_REBOOT */
1217 #if defined BB_GUNZIP \
1218 || defined BB_GZIP \
1219 || defined BB_PRINTF \
1221 extern void *xmalloc(size_t size)
1223 void *cp = malloc(size);
1226 errorMsg("out of memory");
1231 #endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */
1233 #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
1234 extern int vdprintf(int d, const char *format, va_list ap)
1239 len = vsprintf(buf, format, ap);
1240 return write(d, buf, len);
1242 #endif /* BB_SYSLOGD */
1244 #if defined BB_FEATURE_MOUNT_LOOP
1245 extern int del_loop(const char *device)
1249 if ((fd = open(device, O_RDONLY)) < 0) {
1253 if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
1254 perror("ioctl: LOOP_CLR_FD");
1261 extern int set_loop(const char *device, const char *file, int offset,
1264 struct loop_info loopinfo;
1267 mode = *loopro ? O_RDONLY : O_RDWR;
1268 if ((ffd = open(file, mode)) < 0 && !*loopro
1269 && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) {
1273 if ((fd = open(device, mode)) < 0) {
1278 *loopro = (mode == O_RDONLY);
1280 memset(&loopinfo, 0, sizeof(loopinfo));
1281 strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
1282 loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
1284 loopinfo.lo_offset = offset;
1286 loopinfo.lo_encrypt_key_size = 0;
1287 if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
1288 perror("ioctl: LOOP_SET_FD");
1293 if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
1294 (void) ioctl(fd, LOOP_CLR_FD, 0);
1295 perror("ioctl: LOOP_SET_STATUS");
1305 extern char *find_unused_loop_device(void)
1309 struct stat statbuf;
1310 struct loop_info loopinfo;
1312 for (i = 0; i <= 7; i++) {
1313 sprintf(dev, "/dev/loop%d", i);
1314 if (stat(dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
1315 if ((fd = open(dev, O_RDONLY)) >= 0) {
1316 if (ioctl(fd, LOOP_GET_STATUS, &loopinfo) == -1) {
1317 if (errno == ENXIO) { /* probably free */
1328 #endif /* BB_FEATURE_MOUNT_LOOP */
1331 #define whine_if_fstab_is_missing() {}
1333 extern void whine_if_fstab_is_missing()
1335 struct stat statBuf;
1337 if (stat("/etc/fstab", &statBuf) < 0)
1339 "/etc/fstab file missing -- install one to name /dev/root.\n\n");