X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fveritysetup.c;h=cc2095dec3d545a185c519985eefcceea42732d5;hb=0946c704bf4f33524e5497134a77af9c6eac3df1;hp=abd8a9885813a066c085b722c2736e8e2149d33a;hpb=ff9db165eb8770c90fc67c6548ede089819b29f5;p=platform%2Fupstream%2Fcryptsetup.git diff --git a/src/veritysetup.c b/src/veritysetup.c index abd8a98..cc2095d 100644 --- a/src/veritysetup.c +++ b/src/veritysetup.c @@ -5,7 +5,8 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -78,17 +79,15 @@ static int action_format(int arg) struct crypt_device *cd = NULL; struct crypt_params_verity params = {}; uint32_t flags = CRYPT_VERITY_CREATE_HASH; - struct stat st; int r; /* Try to create hash image if doesn't exist */ - if (stat(action_argv[1], &st) < 0) { - log_dbg("Creating hash image %s.", action_argv[1]); - r = open(action_argv[1], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); - if (r < 0) { - log_err(_("Cannot create hash image %s for writing.\n"), action_argv[1]); - return -EINVAL; - } + r = open(action_argv[1], O_WRONLY | O_EXCL | O_CREAT, S_IRUSR | S_IWUSR); + if (r < 0 && errno != EEXIST) { + log_err(_("Cannot create hash image %s for writing.\n"), action_argv[1]); + return -EINVAL; + } else if (r >= 0) { + log_dbg("Created hash image %s.", action_argv[1]); close(r); }