On 3/24/16 6:15 AM, jtulak@xxxxxxxxxx wrote: > From: Jan Tulak <jtulak@xxxxxxxxxx> > > Unify mkfs.xfs behaviour a bit and never truncate files. If the user > is trying to mkfs an existing file, we don't want to destroy anything > he did with the file before (sparse file, allocations...) Hm, I guess so ... What motivated this change? I see that it changes behavior, but I'm not sure what it unifies or fixes - can you explain more? a bit more below. > Signed-off-by: Jan Tulak <jtulak@xxxxxxxxxx> > --- > libxfs/init.c | 2 +- > mkfs/xfs_mkfs.c | 18 +++++++++++------- > 2 files changed, 12 insertions(+), 8 deletions(-) > > diff --git a/libxfs/init.c b/libxfs/init.c > index 268136f..5f4b6c4 100644 > --- a/libxfs/init.c > +++ b/libxfs/init.c > @@ -112,7 +112,7 @@ libxfs_device_open(char *path, int creat, int xflags, int setblksize) > > retry: > flags = (readonly ? O_RDONLY : O_RDWR) | \ > - (creat ? (O_CREAT|O_TRUNC) : 0) | \ > + (creat ? O_CREAT : 0) | \ > (dio ? O_DIRECT : 0) | \ > (excl ? O_EXCL : 0); > > diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c > index 9a6ae2c..2bb3b35 100644 > --- a/mkfs/xfs_mkfs.c > +++ b/mkfs/xfs_mkfs.c > @@ -1029,15 +1029,19 @@ check_device_type( > const char *optname) > { > struct stat64 statbuf; > + int statres; > > - if (*isfile && (no_size || no_name)) { > + statres = stat64(name, &statbuf); > + > + if (*isfile && statres != 0 && (no_size || no_name)) { statres !=0 doesn't imply ENOENT; it could be EACCES or several other errors. You'd need to check errno to know for sure. > fprintf(stderr, > - _("if -%s file then -%s name and -%s size are required\n"), > - optname, optname, optname); > + _("if -%s file and the file does not exists, " \ don't need a "\" there, and should read "does not exist" > + "then -%s name and -%s size are required\n"), Better, just tab it out if possible, though it's a long line... perhaps: _("-%s file requires -%s name and -%s size for file creation\n"); or something like that. > + optname, optname, optname); > usage(); > } > > - if (stat64(name, &statbuf)) { > + if (statres) { > if (errno == ENOENT && *isfile) { > if (create) > *create = 1; > @@ -1059,9 +1063,9 @@ check_device_type( > } > > /* > - * We only want to completely truncate and recreate an existing file if > - * we were specifically told it was a file. Set the create flag only in > - * this case to trigger that behaviour. > + * We only want to create a file only if we were specifically told > + * we want a file. Set the create flag only in this case to trigger > + * that behaviour. + * We only want to create a file if we were specifically told it is a + * file. Set the create flag only in this case to trigger that behaviour. > */ > if (S_ISREG(statbuf.st_mode)) { > if (!*isfile) > _______________________________________________ xfs mailing list xfs@xxxxxxxxxxx http://oss.sgi.com/mailman/listinfo/xfs