Commit d3f25d08 authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov

use stat() instead of lstat()

parent bfadda82
...@@ -260,12 +260,12 @@ void parse_device(dev_t dev) ...@@ -260,12 +260,12 @@ void parse_device(dev_t dev)
{ {
char *buf = NULL, *ptr; char *buf = NULL, *ptr;
unsigned major, minor; unsigned major, minor;
struct stat stat; struct stat st;
size_t len; size_t len;
FILE *file; FILE *file;
/* since v2.6.26 */ /* since v2.6.26 */
file = fopen("/proc/self/mountinfo", "r"); file = fopen("/proc/self/mountinfoX", "r");
if (!file) if (!file)
goto old; goto old;
while (getline(&buf, &len, file) > 0) { while (getline(&buf, &len, file) > 0) {
...@@ -285,7 +285,7 @@ old: ...@@ -285,7 +285,7 @@ old:
while (getline(&buf, &len, file) > 0) { while (getline(&buf, &len, file) > 0) {
ptr = buf; ptr = buf;
strsep(&ptr, " "); strsep(&ptr, " ");
if (*buf != '/' || lstat(buf, &stat) || stat.st_rdev != dev) if (*buf != '/' || stat(buf, &st) || st.st_rdev != dev)
continue; continue;
strsep(&ptr, " "); strsep(&ptr, " ");
fstype = strdup(strsep(&ptr, " ")); fstype = strdup(strsep(&ptr, " "));
...@@ -315,7 +315,7 @@ void set_signal(int signo, void (*handler)(int)) ...@@ -315,7 +315,7 @@ void set_signal(int signo, void (*handler)(int))
int main (int argc, char **argv) int main (int argc, char **argv)
{ {
ssize_t ret_size; ssize_t ret_size;
struct stat stat; struct stat st;
int ret, flags; int ret, flags;
long long this_time, time_total; long long this_time, time_total;
...@@ -337,15 +337,15 @@ int main (int argc, char **argv) ...@@ -337,15 +337,15 @@ int main (int argc, char **argv)
if (direct) if (direct)
flags |= O_DIRECT; flags |= O_DIRECT;
if (lstat(path, &stat)) if (stat(path, &st))
err(2, "stat \"%s\" failed", path); err(2, "stat \"%s\" failed", path);
if (S_ISDIR(stat.st_mode) || S_ISREG(stat.st_mode)) { if (S_ISDIR(st.st_mode) || S_ISREG(st.st_mode)) {
if (S_ISDIR(stat.st_mode)) if (S_ISDIR(st.st_mode))
stat.st_size = offset + temp_wsize; st.st_size = offset + temp_wsize;
if (!quiet) if (!quiet)
parse_device(stat.st_dev); parse_device(st.st_dev);
} else if (S_ISBLK(stat.st_mode)) { } else if (S_ISBLK(st.st_mode)) {
unsigned long long blksize; unsigned long long blksize;
fd = open(path, flags); fd = open(path, flags);
...@@ -355,7 +355,7 @@ int main (int argc, char **argv) ...@@ -355,7 +355,7 @@ int main (int argc, char **argv)
ret = ioctl(fd, BLKGETSIZE64, &blksize); ret = ioctl(fd, BLKGETSIZE64, &blksize);
if (ret) if (ret)
err(2, "block get size ioctl failed"); err(2, "block get size ioctl failed");
stat.st_size = blksize; st.st_size = blksize;
fstype = "block"; fstype = "block";
device = "device"; device = "device";
...@@ -363,11 +363,11 @@ int main (int argc, char **argv) ...@@ -363,11 +363,11 @@ int main (int argc, char **argv)
errx(2, "unsupported destination: \"%s\"", path); errx(2, "unsupported destination: \"%s\"", path);
} }
if (offset + wsize > stat.st_size) if (offset + wsize > st.st_size)
errx(2, "target is too small for this"); errx(2, "target is too small for this");
if (!wsize) if (!wsize)
wsize = stat.st_size - offset; wsize = st.st_size - offset;
if (size > wsize) if (size > wsize)
errx(2, "request size is too big for this target"); errx(2, "request size is too big for this target");
...@@ -377,7 +377,7 @@ int main (int argc, char **argv) ...@@ -377,7 +377,7 @@ int main (int argc, char **argv)
errx(2, "buffer allocation failed"); errx(2, "buffer allocation failed");
memset(buf, '*', size); memset(buf, '*', size);
if (S_ISDIR(stat.st_mode)) { if (S_ISDIR(st.st_mode)) {
char *tmpl = "/ioping.XXXXXX"; char *tmpl = "/ioping.XXXXXX";
char *temp = malloc(strlen(path) + strlen(tmpl) + 1); char *temp = malloc(strlen(path) + strlen(tmpl) + 1);
...@@ -403,7 +403,7 @@ int main (int argc, char **argv) ...@@ -403,7 +403,7 @@ int main (int argc, char **argv)
if (fsync(fd)) if (fsync(fd))
err(2, "fsync failed"); err(2, "fsync failed");
free(temp); free(temp);
} else if (S_ISREG(stat.st_mode)) { } else if (S_ISREG(st.st_mode)) {
fd = open(path, flags); fd = open(path, flags);
if (fd < 0) if (fd < 0)
err(2, "failed to open \"%s\"", path); err(2, "failed to open \"%s\"", path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment