~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to mount/lomount.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
        if (info->lo_device != info64->lo_device ||
53
53
            info->lo_rdevice != info64->lo_rdevice ||
54
54
            info->lo_inode != info64->lo_inode ||
55
 
            info->lo_offset != info64->lo_offset)
 
55
            info->lo_offset < 0 ||
 
56
            (uint64_t) info->lo_offset != info64->lo_offset)
56
57
                return -EOVERFLOW;
57
58
 
58
59
        return 0;
64
65
struct looplist {
65
66
        int             flag;           /* scanning options */
66
67
        FILE            *proc;          /* /proc/partitions */
67
 
        int             ncur;           /* current possition */
 
68
        int             ncur;           /* current position */
68
69
        int             *minors;        /* ary of minor numbers (when scan whole /dev) */
69
70
        int             nminors;        /* number of items in *minors */
70
71
        char            name[128];      /* device name */
284
285
static int
285
286
cmpnum(const void *p1, const void *p2)
286
287
{
287
 
        return (* (int *) p1) > (* (int *) p2);
 
288
        return (*(int *) p1 > *(int *) p2) - (*(int *) p1 < *(int *) p2);
288
289
}
289
290
 
290
291
/*
291
292
 * The classic scandir() is more expensive and less portable.
292
 
 * We needn't full loop device names -- minor numers (loop<N>)
 
293
 * We needn't full loop device names -- minor numbers (loop<N>)
293
294
 * are enough.
294
295
 */
295
296
static int
384
385
                ll->flag &= ~LLFLG_DFLT;
385
386
        }
386
387
 
387
 
        /* C) the worst posibility, scan all /dev or /dev/loop
 
388
        /* C) the worst possibility, scan all /dev or /dev/loop
388
389
         */
389
390
        if (!ll->minors) {
390
391
                ll->nminors = (ll->flag & LLFLG_SUBDIR) ?
925
926
        }
926
927
 
927
928
        /*
928
 
         * HACK: here we're leeking a file descriptor,
 
929
         * HACK: here we're leaking a file descriptor,
929
930
         * but mount is a short-lived process anyway.
930
931
         */
931
932
        if (!(*options & SETLOOP_AUTOCLEAR))
1009
1010
#include <stdarg.h>
1010
1011
 
1011
1012
static void
1012
 
usage(FILE *f) {
1013
 
        fprintf(f, _("\nUsage:\n"
1014
 
  " %1$s loop_device                             give info\n"
1015
 
  " %1$s -a | --all                              list all used\n"
1016
 
  " %1$s -d | --detach <loopdev> [<loopdev> ...] delete\n"
1017
 
  " %1$s -f | --find                             find unused\n"
1018
 
  " %1$s -c | --set-capacity <loopdev>           resize\n"
1019
 
  " %1$s -j | --associated <file> [-o <num>]     list all associated with <file>\n"
1020
 
  " %1$s [ options ] {-f|--find|loopdev} <file>  setup\n"),
1021
 
                progname);
1022
 
 
1023
 
        fprintf(f, _("\nOptions:\n"
1024
 
  " -e | --encryption <type> enable data encryption with specified <name/num>\n"
1025
 
  " -h | --help              this help\n"
1026
 
  " -o | --offset <num>      start at offset <num> into file\n"
1027
 
  "      --sizelimit <num>   loop limited to only <num> bytes of the file\n"
1028
 
  " -p | --pass-fd <num>     read passphrase from file descriptor <num>\n"
1029
 
  " -r | --read-only         setup read-only loop device\n"
1030
 
  "      --show              print device name (with -f <file>)\n"
1031
 
  " -v | --verbose           verbose mode\n\n"));
1032
 
 
1033
 
        exit(f == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 
1013
usage(FILE *out) {
 
1014
 
 
1015
  fputs(_("\nUsage:\n"), out);
 
1016
  fprintf(out,
 
1017
        _(" %1$s loop_device                             give info\n"
 
1018
          " %1$s -a | --all                              list all used\n"
 
1019
          " %1$s -d | --detach <loopdev> [<loopdev> ...] delete\n"
 
1020
          " %1$s -f | --find                             find unused\n"
 
1021
          " %1$s -c | --set-capacity <loopdev>           resize\n"
 
1022
          " %1$s -j | --associated <file> [-o <num>]     list all associated with <file>\n"
 
1023
          " %1$s [options] {-f|--find|loopdev} <file>    setup\n"),
 
1024
        progname);
 
1025
 
 
1026
  fputs(_("\nOptions:\n"), out);
 
1027
  fputs(_(" -e, --encryption <type> enable data encryption with specified <name/num>\n"
 
1028
          " -h, --help              this help\n"
 
1029
          " -o, --offset <num>      start at offset <num> into file\n"
 
1030
          "     --sizelimit <num>   loop limited to only <num> bytes of the file\n"
 
1031
          " -p, --pass-fd <num>     read passphrase from file descriptor <num>\n"
 
1032
          " -r, --read-only         setup read-only loop device\n"
 
1033
          "     --show              print device name (with -f <file>)\n"
 
1034
          " -v, --verbose           verbose mode\n\n"), out);
 
1035
 
 
1036
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
1034
1037
 }
1035
1038
 
1036
1039
int
1042
1045
        int ro = 0;
1043
1046
        int pfd = -1;
1044
1047
        uintmax_t off = 0, slimit = 0;
1045
 
        struct option longopts[] = {
 
1048
 
 
1049
        static const struct option longopts[] = {
1046
1050
                { "all", 0, 0, 'a' },
1047
1051
                { "set-capacity", 0, 0, 'c' },
1048
1052
                { "detach", 0, 0, 'd' },
1130
1134
                if (capacity || all || assoc || argc < optind || argc > optind+1)
1131
1135
                        usage(stderr);
1132
1136
        } else if (all) {
1133
 
                if (argc > 2)
 
1137
                /* only -v is allowed */
 
1138
                if ((argc == 3 && verbose == 0) || argc > 3)
1134
1139
                        usage(stderr);
1135
1140
        } else if (assoc) {
1136
1141
                if (capacity || encryption || showdev || passfd || ro)