~ubuntu-branches/debian/jessie/btrfs-tools/jessie

« back to all changes in this revision

Viewing changes to cmds-restore.c

  • Committer: Package Import Robot
  • Author(s): Dimitri John Ledkov
  • Date: 2014-09-21 02:05:14 UTC
  • mfrom: (1.2.13) (6.1.38 sid)
  • Revision ID: package-import@ubuntu.com-20140921020514-kx4b23aw4grvevrc
Tags: 3.16-1
* New upstream release.
* Add asciidoc & xmlto build dependencies.
* Disable test-suites for now, should be run as autopkgtests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
 
116
116
        while (tot_in < tot_len) {
117
117
                in_len = read_compress_length(inbuf);
 
118
 
 
119
                if ((tot_in + LZO_LEN + in_len) > tot_len) {
 
120
                        fprintf(stderr, "bad compress length %lu\n",
 
121
                                (unsigned long)in_len);
 
122
                        return -1;
 
123
                }
 
124
 
118
125
                inbuf += LZO_LEN;
119
126
                tot_in += LZO_LEN;
120
127
 
404
411
        return ret;
405
412
}
406
413
 
407
 
static int ask_to_continue(const char *file)
 
414
enum loop_response {
 
415
        LOOP_STOP,
 
416
        LOOP_CONTINUE,
 
417
        LOOP_DONTASK
 
418
};
 
419
 
 
420
static enum loop_response ask_to_continue(const char *file)
408
421
{
409
422
        char buf[2];
410
423
        char *ret;
411
424
 
412
425
        printf("We seem to be looping a lot on %s, do you want to keep going "
413
 
               "on ? (y/N): ", file);
 
426
               "on ? (y/N/a): ", file);
414
427
again:
415
428
        ret = fgets(buf, 2, stdin);
416
429
        if (*ret == '\n' || tolower(*ret) == 'n')
417
 
                return 1;
 
430
                return LOOP_STOP;
 
431
        if (tolower(*ret) == 'a')
 
432
                return LOOP_DONTASK;
418
433
        if (tolower(*ret) != 'y') {
419
 
                printf("Please enter either 'y' or 'n': ");
 
434
                printf("Please enter one of 'y', 'n', or 'a': ");
420
435
                goto again;
421
436
        }
422
437
 
423
 
        return 0;
 
438
        return LOOP_CONTINUE;
424
439
}
425
440
 
426
441
 
588
603
        }
589
604
 
590
605
        while (1) {
591
 
                if (loops++ >= 1024) {
592
 
                        ret = ask_to_continue(file);
593
 
                        if (ret)
 
606
                if (loops >= 0 && loops++ >= 1024) {
 
607
                        enum loop_response resp;
 
608
 
 
609
                        resp = ask_to_continue(file);
 
610
                        if (resp == LOOP_STOP)
594
611
                                break;
595
 
                        loops = 0;
 
612
                        else if (resp == LOOP_CONTINUE)
 
613
                                loops = 0;
 
614
                        else if (resp == LOOP_DONTASK)
 
615
                                loops = -1;
596
616
                }
597
617
                if (path->slots[0] >= btrfs_header_nritems(leaf)) {
598
618
                        do {
1111
1131
        "-v              verbose",
1112
1132
        "-i              ignore errors",
1113
1133
        "-o              overwrite",
1114
 
        "-t <location>   tree location",
1115
 
        "-f <offset>     filesystem location",
1116
 
        "-u <block>      super mirror",
 
1134
        "-t <bytenr>     tree location",
 
1135
        "-f <bytenr>     filesystem location",
 
1136
        "-u <mirror>     super mirror",
1117
1137
        "-r <rootid>     root objectid",
1118
1138
        "-d              find dir",
1119
1139
        "-l              list tree roots",
1122
1142
        "                restore only filenames matching regex,",
1123
1143
        "                you have to use following syntax (possibly quoted):",
1124
1144
        "                ^/(|home(|/username(|/Desktop(|/.*))))$",
 
1145
        "-c              ignore case (--path-regrex only)",
1125
1146
        NULL
1126
1147
};
1127
1148
 
1180
1201
                                break;
1181
1202
                        case 'r':
1182
1203
                                root_objectid = arg_strtou64(optarg);
 
1204
                                if (!is_fstree(root_objectid)) {
 
1205
                                        fprintf(stderr, "objectid %llu is not a valid fs/file tree\n",
 
1206
                                                        root_objectid);
 
1207
                                        exit(1);
 
1208
                                }
1183
1209
                                break;
1184
1210
                        case 'l':
1185
1211
                                list_roots = 1;
1202
1228
                }
1203
1229
        }
1204
1230
 
1205
 
        if (!list_roots && optind + 1 >= argc)
1206
 
                usage(cmd_restore_usage);
1207
 
        else if (list_roots && optind >= argc)
1208
 
                usage(cmd_restore_usage);
 
1231
        set_argv0(argv);
 
1232
        if (!list_roots && check_argc_min(argc - optind, 2))
 
1233
                usage(cmd_restore_usage);
 
1234
        else if (list_roots && check_argc_min(argc - optind, 1))
 
1235
                usage(cmd_restore_usage);
 
1236
 
 
1237
        if (fs_location && root_objectid) {
 
1238
                fprintf(stderr, "don't use -f and -r at the same time.\n");
 
1239
                return 1;
 
1240
        }
1209
1241
 
1210
1242
        if ((ret = check_mounted(argv[optind])) < 0) {
1211
1243
                fprintf(stderr, "Could not check mount status: %s\n",
1228
1260
                root->node = read_tree_block(root, fs_location, root->leafsize, 0);
1229
1261
                if (!root->node) {
1230
1262
                        fprintf(stderr, "Failed to read fs location\n");
 
1263
                        ret = 1;
1231
1264
                        goto out;
1232
1265
                }
1233
1266
        }
1251
1284
                key.offset = (u64)-1;
1252
1285
                root = btrfs_read_fs_root(orig_root->fs_info, &key);
1253
1286
                if (IS_ERR(root)) {
1254
 
                        fprintf(stderr, "Error reading root\n");
 
1287
                        fprintf(stderr, "fail to read root %llu: %s\n",
 
1288
                                        root_objectid, strerror(-PTR_ERR(root)));
1255
1289
                        root = orig_root;
1256
1290
                        ret = 1;
1257
1291
                        goto out;