xref: /minix3/minix/commands/ramdisk/ramdisk.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1  
2  #include <minix/paths.h>
3  
4  #include <sys/ioc_memory.h>
5  #include <stdio.h>
6  #include <fcntl.h>
7  #include <stdlib.h>
8  
9  int
10  main(int argc, char *argv[])
11  {
12  	int fd;
13  	signed long size;
14  	char *d;
15  
16  	if(argc < 2 || argc > 3) {
17  		fprintf(stderr, "usage: %s <size in kB> [device]\n",
18  			argv[0]);
19  		return 1;
20  	}
21  
22  	d = argc == 2 ? _PATH_RAMDISK : argv[2];
23  	if((fd=open(d, O_RDONLY)) < 0) {
24  		perror(d);
25  		return 1;
26  	}
27  
28  #define KFACTOR 1024
29  	size = atol(argv[1])*KFACTOR;
30  
31  	if(size < 0) {
32  		fprintf(stderr, "size should be non-negative.\n");
33  		return 1;
34  	}
35  
36  	if(ioctl(fd, MIOCRAMSIZE, &size) < 0) {
37  		perror("MIOCRAMSIZE");
38  		return 1;
39  	}
40  
41  	fprintf(stderr, "size on %s set to %ldkB\n", d, size/KFACTOR);
42  
43  	return 0;
44  }
45  
46