From fd5f2edf35326fd0f0254c1020a4e075112c48dc Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 23 May 2013 02:43:33 +0200 Subject: [PATCH] mkfs: only complain about failing stat with -d mkfs -d is a feature that needs a stat() of the mkfs binary, which often fails (as mkfs is often not invoked with a full path or from the same directory). it makes setup look a bit messy as the error is always printed while installing the system, for each created FS, even though the situation is harmless. This change only complains when the stat is actually needed (-d). Change-Id: I54ac01505aa97c1cbe40456c04a35aed5a7ee953 --- usr.sbin/mkfs.mfs/mkfs.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/usr.sbin/mkfs.mfs/mkfs.c b/usr.sbin/mkfs.mfs/mkfs.c index 414938dd9..ee58ef45f 100644 --- a/usr.sbin/mkfs.mfs/mkfs.c +++ b/usr.sbin/mkfs.mfs/mkfs.c @@ -143,27 +143,11 @@ main(int argc, char *argv[]) int nread, mode, usrid, grpid, ch, extra_space_percent; block_t blocks, maxblocks; ino_t inodes, root_inum; - time_t bin_time; char *token[MAX_TOKENS], line[LINE_LEN], *sfx; - struct stat statbuf; struct fs_size fssize; progname = argv[0]; - /* Get two times, the current time and the mod time of the binary of - * mkfs itself. When the -d flag is used, the later time is put into - * the i_mtimes of all the files. This feature is useful when - * producing a set of file systems, and one wants all the times to be - * identical. First you set the time of the mkfs binary to what you - * want, then go. - */ - current_time = time((time_t *) 0); /* time mkfs is being run */ - if (stat(progname, &statbuf)) { - perror("stat of itself"); - bin_time = current_time; /* provide some default value */ - } else - bin_time = statbuf.st_mtime; /* time when mkfs binary was last modified */ - /* Process switches. */ blocks = 0; inodes = 0; @@ -199,7 +183,6 @@ main(int argc, char *argv[]) break; case 'd': dflag = 1; - current_time = bin_time; break; case 'i': inodes = strtoul(optarg, (char **) NULL, 0); @@ -214,6 +197,21 @@ main(int argc, char *argv[]) if (argc == optind) usage(); + /* Get the current time, set it to the mod time of the binary of + * mkfs itself when the -d flag is used. The 'current' time is put into + * the i_mtimes of all the files. This -d feature is useful when + * producing a set of file systems, and one wants all the times to be + * identical. First you set the time of the mkfs binary to what you + * want, then go. + */ + current_time = time((time_t *) 0); /* time mkfs is being run */ + if(dflag) { + struct stat statbuf; + if (stat(progname, &statbuf)) { + perror("stat of itself"); + } else current_time = statbuf.st_mtime; + } + /* Percentage of extra size must be nonnegative. * It can legitimately be bigger than 100 but has to make some sort of sense. */ -- 2.44.0