ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

fsfreeze.c (899B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sys/ioctl.h>
      3 #include <sys/stat.h>
      4 #include <sys/types.h>
      5 
      6 #include <fcntl.h>
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 #include <unistd.h>
     10 
     11 #include "util.h"
     12 
     13 #define FIFREEZE	_IOWR('X', 119, int)	/* Freeze */
     14 #define FITHAW		_IOWR('X', 120, int)	/* Thaw */
     15 
     16 static void
     17 usage(void)
     18 {
     19 	eprintf("usage: %s (-f | -u) mountpoint\n", argv0);
     20 }
     21 
     22 int
     23 main(int argc, char *argv[])
     24 {
     25 	int fflag = 0;
     26 	int uflag = 0;
     27 	long p = 1;
     28 	int fd;
     29 
     30 	ARGBEGIN {
     31 	case 'f':
     32 		fflag = 1;
     33 		break;
     34 	case 'u':
     35 		uflag = 1;
     36 		break;
     37 	default:
     38 		usage();
     39 	} ARGEND;
     40 
     41 	if (argc != 1)
     42 		usage();
     43 
     44 	if ((fflag ^ uflag) == 0)
     45 		usage();
     46 
     47 	fd = open(argv[0], O_RDONLY);
     48 	if (fd < 0)
     49 		eprintf("open: %s:", argv[0]);
     50 	if (ioctl(fd, fflag == 1 ? FIFREEZE : FITHAW, &p) < 0)
     51 		eprintf("%s %s:", fflag == 1 ? "FIFREEZE" : "FITHAW", argv[0]);
     52 	close(fd);
     53 	return 0;
     54 }