Re: [PATCH] fsfreeze: suspend and resume access to an filesystem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm sorry. My source code was so dirty.
I fixed all problem. Thank you for your advice.

Best regards,
Taira

/* fsfreeze.c -- Filesystem freeze/unfreeze IO for Linux
 * 
 * Copyright (C) 2010 Hajime Taira (htaira@xxxxxxxxxx)
 *                    Masatake Yamato (yamato@xxxxxxxxxx)
 *
 * This program is free software.  You can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation: either version 1 or
 * (at your option) any later version.
 */

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

int freeze_f(int fd)
{
	return ioctl(fd, FIFREEZE, 0);
}

int unfreeze_f(int fd)
{
	return ioctl(fd, FITHAW, 0);
}

void usage(void)
{
	fprintf(stderr, "Usage: fsfreeze -f | -u <mount point>\n");
	fprintf(stderr, "\n");
}

int main(int argc, char **argv)
{
	int fd;
	bool freeze; /* true is freeze_f()/false is unfreeze_f() */
	char *path;
	struct stat sb;

	if(argc != 3) {
		usage();
		return 1;
	}

	/* freeze operation */
        if(strcmp(argv[1],"-f") == 0) {
		freeze = true;
        }
        /* unfreeze operation */
        else if(strcmp(argv[1],"-u") == 0) {
		freeze = false;
        } else {
                usage();
                return 1;
        }

	path = argv[2];
	fd = open(path, O_RDONLY);
	if (fd < 0) {
		perror(path);
		return 2;
	}

	if(fstat(fd, &sb) == -1) {
		close(fd);
		perror(path);
		return 2;
	}

	if((sb.st_mode & S_IFMT) != S_IFDIR) {
		close(fd);
		usage();
		return 2;
	}

	/* freeze/unfreeze */
	if(freeze) {
		int ret;
		ret = freeze_f(fd);
		if (ret != 0) {
                        perror("freeze");
                        close(fd);
                        return 3;
		}
	} else {
		int ret;
		ret = unfreeze_f(fd);
		if (ret != 0) {
                        perror("unfreeze");
                        close(fd);
                        return 3;
                }
	}

	close(fd);

	return 0;
}



--
Best regards,

Hajime Taira <htaira@xxxxxxxxxx>
RHEL Solution Architect
Global Services
Red Hat K.K.

Ebisu Neonato 8F, 4-1-18, Ebisu,
Shibuya-ku, Tokyo, Japan 150-0013
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux