2 #include "lib/fastbuf.h"
13 int main(int argc, char **argv)
16 die("Usage: du -sb * | fit <block-size> <num-blocks>");
17 int bs = atol(argv[1]);
18 int m = atol(argv[2]);
21 struct fastbuf *in = bopen_fd(0, NULL);
23 struct file *files = NULL;
27 while (bgets(in, buf, sizeof(buf)))
29 char *c = strchr(buf, '\t');
31 die("Syntax error in input: %s", buf);
34 files = (struct file *) bb_grow(&files_buf, sizeof(struct file) * (n+1));
35 files[n].name = xstrdup(c);
36 files[n].blocks = (atol(buf) + bs - 1) / bs;
37 printf("#%d: %s (%d blocks)\n", n, files[n].name, files[n].blocks);
38 tb += files[n].blocks;
41 printf("%d files of %d blocks total\n\n", n, tb);
43 char *map = xmalloc_zero(m+1);
45 for (int i=0; i<n; i++)
47 int s = files[i].blocks;
48 for (int j=m-s; j>=0; j--)
49 if (map[j] && !map[j+s])
56 printf("Found subset with %d blocks of %d (%.2f%%):\n", max, m, 100.*max/m);
61 printf("%7d\t%s\n", files[f].blocks, files[f].name);
62 max -= files[f].blocks;
64 printf("%7d\t*FREE*\n", free);