1 /* Copyright 1997,2000-2002,2009 Alain Knaff.
2 * This file is part of mtools.
4 * Mtools is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Mtools is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
18 * Display the space occupied by an MSDOS directory
21 #include "sysincludes.h"
31 typedef struct Arg_t {
42 static void usage(int ret) NORETURN;
43 static void usage(int ret)
45 fprintf(stderr, "Mtools version %s, dated %s\n",
47 fprintf(stderr, "Usage: %s: msdosdirectory\n",
52 static int file_mdu(direntry_t *entry, MainParam_t *mp)
55 Arg_t * arg = (Arg_t *) (mp->arg);
57 blocks = countBlocks(entry->Dir,getStart(entry->Dir, &entry->dir));
58 if(arg->all || !arg->inDir) {
59 fprintPwd(stdout, entry,0);
60 printf(" %d\n", blocks);
62 arg->blocks += blocks;
67 static int dir_mdu(direntry_t *entry, MainParam_t *mp)
69 Arg_t *parentArg = (Arg_t *) (mp->arg);
74 arg.mp.arg = (void *) &arg;
75 arg.parent = parentArg;
78 /* account for the space occupied by the directory itself */
79 if(!isRootDir(entry->Dir)) {
80 arg.blocks = countBlocks(entry->Dir,
81 getStart(entry->Dir, &entry->dir));
87 ret = mp->loop(mp->File, &arg.mp, "*");
88 if(!arg.summary || !parentArg->inDir) {
89 fprintPwd(stdout, entry,0);
90 printf(" %d\n", arg.blocks);
92 arg.parent->blocks += arg.blocks;
96 void mdu(int argc, char **argv, int type UNUSEDP)
104 if(helpFlag(argc, argv))
106 while ((c = getopt(argc, argv, "i:ash")) != EOF) {
109 set_cmd_line_image(optarg);
127 if(arg.summary && arg.all) {
128 fprintf(stderr,"-a and -s options are mutually exclusive\n");
133 arg.mp.callback = file_mdu;
134 arg.mp.openflags = O_RDONLY;
135 arg.mp.dirCallback = dir_mdu;
137 arg.mp.arg = (void *) &arg;
138 arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN_DIRS | NO_DOTS;
139 exit(main_loop(&arg.mp, argv + optind, argc - optind));