Skip to content

Commit

Permalink
Use an enum and bit fields for File Option flags.
Browse files Browse the repository at this point in the history
We will run out of bits for the fileopts on 32 bits so switch to a
proper bitmap and use the set_bit/clear_bit/bit_is_set macros.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 6947d77 commit a0098a6
Show file tree
Hide file tree
Showing 29 changed files with 407 additions and 342 deletions.
3 changes: 3 additions & 0 deletions src/dird/dird_conf.c
Expand Up @@ -1333,6 +1333,9 @@ bool FILESETRES::print_config(POOL_MEM &buff)
case 'X':
indent_config_item(cfg_str, 3, "Xattr = Yes\n");
break;
case 'x':
indent_config_item(cfg_str, 3, "AutoExclude = No\n");
break;
default:
Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p);
break;
Expand Down
19 changes: 15 additions & 4 deletions src/dird/inc_conf.c
Expand Up @@ -99,6 +99,7 @@ static RES_ITEM options_items[] = {
{ "xattrsupport", CFG_TYPE_OPTION, { 0 }, 0, 0, NULL },
{ "size", CFG_TYPE_OPTION, { 0 }, 0, 0, NULL },
{ "shadowing", CFG_TYPE_OPTION, { 0 }, 0, 0, NULL },
{ "autoexclude", CFG_TYPE_OPTION, { 0 }, 0, 0, NULL },
{ "meta", CFG_TYPE_META, { 0 }, 0, 0, 0 },
{ NULL, 0, { 0 }, 0, 0, NULL }
};
Expand Down Expand Up @@ -463,26 +464,36 @@ static void store_option(LEX *lc, RES_ITEM *item, int index, int pass)

inc_opts[0] = 0;
keyword = INC_KW_NONE;
/* Look up the keyword */
for (i=0; FS_option_kw[i].name; i++) {

/*
* Look up the keyword
*/
for (i = 0; FS_option_kw[i].name; i++) {
if (bstrcasecmp(item->name, FS_option_kw[i].name)) {
keyword = FS_option_kw[i].token;
break;
}
}

if (keyword == INC_KW_NONE) {
scan_err1(lc, _("Expected a FileSet keyword, got: %s"), lc->str);
}
/* Now scan for the value */

/*
* Now scan for the value
*/
scan_include_options(lc, keyword, inc_opts, sizeof(inc_opts));
if (pass == 1) {
bstrncat(res_incexe.current_opts->opts, inc_opts, MAX_FOPTS);
Dmsg2(900, "new pass=%d incexe opts=%s\n", pass, res_incexe.current_opts->opts);
}

scan_to_eol(lc);
}

/* If current_opts not defined, create first entry */
/*
* If current_opts not defined, create first entry
*/
static void setup_current_opts(void)
{
FOPTS *fo = (FOPTS *)malloc(sizeof(FOPTS));
Expand Down
6 changes: 5 additions & 1 deletion src/dird/inc_conf.h
Expand Up @@ -57,7 +57,8 @@ enum {
INC_KW_HONOR_NODUMP,
INC_KW_XATTR,
INC_KW_SIZE,
INC_KW_SHADOWING
INC_KW_SHADOWING,
INC_KW_AUTO_EXCLUDE
};

/*
Expand Down Expand Up @@ -94,6 +95,7 @@ static struct s_kw FS_option_kw[] = {
{ "xattrsupport", INC_KW_XATTR },
{ "size", INC_KW_SIZE },
{ "shadowing", INC_KW_SHADOWING },
{ "autoexclude", INC_KW_AUTO_EXCLUDE },
{ NULL, 0 }
};

Expand Down Expand Up @@ -175,6 +177,8 @@ static struct s_fs_opt FS_options[] = {
{ "globalwarn", INC_KW_SHADOWING, "d3" },
{ "globalremove", INC_KW_SHADOWING, "d4" },
{ "none", INC_KW_SHADOWING, "0" },
{ "yes", INC_KW_AUTO_EXCLUDE, "0" },
{ "no", INC_KW_AUTO_EXCLUDE, "x" },
{ NULL, 0, 0 }
};

Expand Down
51 changes: 27 additions & 24 deletions src/dird/testfind.c
Expand Up @@ -537,73 +537,73 @@ static void set_options(findFOPTS *fo, const char *opts)
case '0': /* no option */
break;
case 'e':
fo->flags |= FO_EXCLUDE;
set_bit(FO_EXCLUDE, fo->flags);
break;
case 'f':
fo->flags |= FO_MULTIFS;
set_bit(FO_MULTIFS, fo->flags);
break;
case 'h': /* no recursion */
fo->flags |= FO_NO_RECURSION;
set_bit(FO_NO_RECURSION, fo->flags);
break;
case 'H': /* no hard link handling */
fo->flags |= FO_NO_HARDLINK;
set_bit(FO_NO_HARDLINK, fo->flags);
break;
case 'i':
fo->flags |= FO_IGNORECASE;
set_bit(FO_IGNORECASE, fo->flags);
break;
case 'M': /* MD5 */
fo->flags |= FO_MD5;
set_bit(FO_MD5, fo->flags);
break;
case 'n':
fo->flags |= FO_NOREPLACE;
set_bit(FO_NOREPLACE, fo->flags);
break;
case 'p': /* use portable data format */
fo->flags |= FO_PORTABLE;
set_bit(FO_PORTABLE, fo->flags);
break;
case 'R': /* Resource forks and Finder Info */
fo->flags |= FO_HFSPLUS;
set_bit(FO_HFSPLUS, fo->flags);
case 'r': /* read fifo */
fo->flags |= FO_READFIFO;
set_bit(FO_READFIFO, fo->flags);
break;
case 'S':
switch(*(p + 1)) {
case ' ':
/* Old director did not specify SHA variant */
fo->flags |= FO_SHA1;
set_bit(FO_SHA1, fo->flags);
break;
case '1':
fo->flags |= FO_SHA1;
set_bit(FO_SHA1, fo->flags);
p++;
break;
#ifdef HAVE_SHA2
case '2':
fo->flags |= FO_SHA256;
set_bit(FO_SHA256, fo->flags);
p++;
break;
case '3':
fo->flags |= FO_SHA512;
set_bit(FO_SHA512, fo->flags);
p++;
break;
#endif
default:
/* Automatically downgrade to SHA-1 if an unsupported
* SHA variant is specified */
fo->flags |= FO_SHA1;
set_bit(FO_SHA1, fo->flags);
p++;
break;
}
break;
case 's':
fo->flags |= FO_SPARSE;
set_bit(FO_SPARSE, fo->flags);
break;
case 'm':
fo->flags |= FO_MTIMEONLY;
set_bit(FO_MTIMEONLY, fo->flags);
break;
case 'k':
fo->flags |= FO_KEEPATIME;
set_bit(FO_KEEPATIME, fo->flags);
break;
case 'A':
fo->flags |= FO_ACL;
set_bit(FO_ACL, fo->flags);
break;
case 'V': /* verify options */
/* Copy Verify Options */
Expand All @@ -616,27 +616,30 @@ static void set_options(findFOPTS *fo, const char *opts)
fo->VerifyOpts[j] = 0;
break;
case 'w':
fo->flags |= FO_IF_NEWER;
set_bit(FO_IF_NEWER, fo->flags);
break;
case 'W':
fo->flags |= FO_ENHANCEDWILD;
set_bit(FO_ENHANCEDWILD, fo->flags);
break;
case 'Z': /* compression */
p++; /* skip Z */
if (*p >= '0' && *p <= '9') {
fo->flags |= FO_COMPRESS;
set_bit(FO_COMPRESS, fo->flags);
fo->Compress_algo = COMPRESS_GZIP;
fo->Compress_level = *p - '0';
}
else if (*p == 'o') {
fo->flags |= FO_COMPRESS;
set_bit(FO_COMPRESS, fo->flags);
fo->Compress_algo = COMPRESS_LZO1X;
fo->Compress_level = 1; /* not used with LZO */
}
Dmsg2(200, "Compression alg=%d level=%d\n", fo->Compress_algo, fo->Compress_level);
break;
case 'x':
set_bit(FO_NO_AUTOEXCL, fo->flags);
break;
case 'X':
fo->flags |= FO_XATTR;
set_bit(FO_XATTR, fo->flags);
break;
default:
Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p);
Expand Down
5 changes: 4 additions & 1 deletion src/filed/accurate.c
Expand Up @@ -241,7 +241,10 @@ bool accurate_check_file(JCR *jcr, FF_PKT *ff_pkt)
case '1': /* Compare SHA1 */
if (!status && ff_pkt->type != FT_LNKSAVED &&
(S_ISREG(ff_pkt->statp.st_mode) &&
ff_pkt->flags & (FO_MD5 | FO_SHA1 | FO_SHA256 | FO_SHA512))) {
(bit_is_set(FO_MD5, ff_pkt->flags) ||
bit_is_set(FO_SHA1, ff_pkt->flags) ||
bit_is_set(FO_SHA256, ff_pkt->flags) ||
bit_is_set(FO_SHA512, ff_pkt->flags)))) {
if (!*payload->chksum && !jcr->rerunning) {
Jmsg(jcr, M_WARNING, 0, _("Cannot verify checksum for %s\n"), ff_pkt->fname);
status = true;
Expand Down

0 comments on commit a0098a6

Please sign in to comment.