Checks if parity and content options are pointing to the same file.

This commit is contained in:
Andrea Mazzoleni 2012-01-31 21:53:26 +01:00
parent 13596d07ea
commit 31abb8e323
3 changed files with 40 additions and 5 deletions

26
state.c
View file

@ -58,6 +58,8 @@ void state_done(struct snapraid_state* state)
*/
static void state_config_check(struct snapraid_state* state, const char* path, int skip_device)
{
tommy_node* i;
if (state->parity[0] == 0) {
fprintf(stderr, "No 'parity' specification in '%s'\n", path);
exit(EXIT_FAILURE);
@ -68,10 +70,24 @@ static void state_config_check(struct snapraid_state* state, const char* path, i
exit(EXIT_FAILURE);
}
/* checks for equal paths */
for(i=state->contentlist;i!=0;i=i->next) {
struct snapraid_content* content = i->data;
if (pathcmp(state->parity, content->content) == 0) {
fprintf(stderr, "Same path used for 'parity' and 'content' as '%s'\n", content->content);
exit(EXIT_FAILURE);
}
if (state->qarity[0] != 0 && pathcmp(state->qarity, content->content) == 0) {
fprintf(stderr, "Same path used for 'qarity' and 'content' as '%s'\n", content->content);
exit(EXIT_FAILURE);
}
}
/* count the content files */
if (!skip_device) {
unsigned content_count;
tommy_node* i;
content_count = 0;
for(i=state->contentlist;i!=0;i=i->next) {
@ -101,7 +117,6 @@ static void state_config_check(struct snapraid_state* state, const char* path, i
/* check if all the data and parity disks are different */
if (!skip_device) {
tommy_node* i;
for(i=state->disklist;i!=0;i=i->next) {
tommy_node* j;
struct snapraid_disk* disk = i->data;
@ -119,12 +134,13 @@ static void state_config_check(struct snapraid_state* state, const char* path, i
exit(EXIT_FAILURE);
}
if (disk->device == state->qarity_device) {
if (state->qarity[0] != 0 && disk->device == state->qarity_device) {
fprintf(stderr, "Disk '%s' and parity '%s' are on the same device.\n", disk->dir, state->qarity);
exit(EXIT_FAILURE);
}
}
if (state->parity_device == state->qarity_device) {
if (state->qarity[0] != 0 && state->parity_device == state->qarity_device) {
fprintf(stderr, "Parity '%s' and '%s' are on the same device.\n", state->parity, state->qarity);
exit(EXIT_FAILURE);
}
@ -280,7 +296,7 @@ void state_config(struct snapraid_state* state, const char* path, int verbose, i
exit(EXIT_FAILURE);
}
if (strcmp(buffer, "/dev/null") == 0 || strcmp(buffer, "NUL") == 0 || strcmp(buffer, "nul") == 0) {
if (pathcmp(buffer, "/dev/null") == 0 || pathcmp(buffer, "NUL") == 0) {
fprintf(stderr, "You cannot use the null device as 'content' specification in '%s' at line %u\n", path, line);
exit(EXIT_FAILURE);
}

13
util.c
View file

@ -640,6 +640,19 @@ void pathslash(char* dst, size_t size)
}
}
int pathcmp(const char* a, const char* b)
{
#ifdef _WIN32
char ai[PATH_MAX];
char bi[PATH_MAX];
pathimport(ai, sizeof(ai), a);
pathimport(bi, sizeof(bi), b);
return stricmp(ai, bi);
#else
return strcmp(a, b);
#endif
}
/****************************************************************************/
/* mem */

6
util.h
View file

@ -334,6 +334,12 @@ void pathprint(char* dst, size_t size, const char* format, ...);
*/
void pathslash(char* dst, size_t size);
/**
* Compare two paths.
* In Windows it's case insentive.
*/
int pathcmp(const char* a, const char* b);
/****************************************************************************/
/* memory */