aboutsummaryrefslogtreecommitdiff
path: root/libbb/find_root_device.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-15 17:42:16 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-15 17:42:16 +0000
commitc911a4389bbaa5ac85d725c8c05e452dfba8583d (patch)
treea0f435a6239c002578db8f019eb0fb427f1795b3 /libbb/find_root_device.c
parent15649c11f3568ed6f030953844f201438379e03c (diff)
downloadbusybox-w32-c911a4389bbaa5ac85d725c8c05e452dfba8583d.tar.gz
busybox-w32-c911a4389bbaa5ac85d725c8c05e452dfba8583d.tar.bz2
busybox-w32-c911a4389bbaa5ac85d725c8c05e452dfba8583d.zip
Patch from Vladimir:
1) fixed a bug that could crash df, mount, and umount applets if the root device name was longer then the word "root" (/dev/loop1 vs /dev/root) - 2) severl functions needed static declaration in the umount applet 3) update declaration for function in last_char_is() in libbb
Diffstat (limited to 'libbb/find_root_device.c')
-rw-r--r--libbb/find_root_device.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index de765ce44..75ed1a979 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -28,26 +28,27 @@
28#include <stdio.h> 28#include <stdio.h>
29#include <string.h> 29#include <string.h>
30#include <dirent.h> 30#include <dirent.h>
31#include <stdlib.h>
31#include "libbb.h" 32#include "libbb.h"
32 33
33 34
34 35
35extern int find_real_root_device_name(char* name) 36extern char *find_real_root_device_name(const char* name)
36{ 37{
37 DIR *dir; 38 DIR *dir;
38 struct dirent *entry; 39 struct dirent *entry;
39 struct stat statBuf, rootStat; 40 struct stat statBuf, rootStat;
40 char fileName[BUFSIZ]; 41 char *fileName;
41 42
42 if (stat("/", &rootStat) != 0) { 43 if (stat("/", &rootStat) != 0) {
43 error_msg("could not stat '/'"); 44 error_msg("could not stat '/'");
44 return( FALSE); 45 return NULL;
45 } 46 }
46 47
47 dir = opendir("/dev"); 48 dir = opendir("/dev");
48 if (!dir) { 49 if (!dir) {
49 error_msg("could not open '/dev'"); 50 error_msg("could not open '/dev'");
50 return( FALSE); 51 return NULL;
51 } 52 }
52 53
53 while((entry = readdir(dir)) != NULL) { 54 while((entry = readdir(dir)) != NULL) {
@@ -57,21 +58,20 @@ extern int find_real_root_device_name(char* name)
57 if (strcmp(entry->d_name, "..") == 0) 58 if (strcmp(entry->d_name, "..") == 0)
58 continue; 59 continue;
59 60
60 snprintf( fileName, strlen(name)+1, "/dev/%s", entry->d_name); 61 fileName = concat_path_file("/dev/", entry->d_name);
61 62
62 if (stat(fileName, &statBuf) != 0)
63 continue;
64 /* Some char devices have the same dev_t as block 63 /* Some char devices have the same dev_t as block
65 * devices, so make sure this is a block device */ 64 * devices, so make sure this is a block device */
66 if (! S_ISBLK(statBuf.st_mode)) 65 if (stat(fileName, &statBuf) == 0 &&
67 continue; 66 S_ISBLK(statBuf.st_mode)!=0 &&
68 if (statBuf.st_rdev == rootStat.st_rdev) { 67 statBuf.st_rdev == rootStat.st_rdev) {
69 strcpy(name, fileName); 68 return fileName;
70 return ( TRUE);
71 } 69 }
70 free(fileName);
72 } 71 }
72 closedir(dir);
73 73
74 return( FALSE); 74 return NULL;
75} 75}
76 76
77 77