Hi,
I fixed that. And reattach a patch.
> Do we have to do open() twice here? I doubt.
First open(), path is filename.
Second open(), path is directory name.
Best regards,
Taira
--- util-linux-ng.old/fsfreeze/fsfreeze.c 1970-01-01
09:00:00.000000000 +0900
+++ util-linux-ng/fsfreeze/fsfreeze.c 2010-05-12 13:42:15.000000000 +0900
@@ -0,0 +1,89 @@
+/* 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 <fcntl.h>
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+
+int freeze_f(int fd)
+{
+ return ioctl(fd, FIFREEZE, 0);
+}
+
+int unfreeze_f(int fd)
+{
+ return ioctl(fd, FITHAW, 0);
+}
+
+void usage()
+{
+ fprintf(stderr, "Usage: fsfreeze -f | -u <mount point>\n");
+ fprintf(stderr, "\n");
+}
+
+int main(int argc, char **argv)
+{
+ int fd;
+ int ret = -1;
+ char *path;
+
+ if(argc == 3) {
+ path = argv[2];
+ /* for file */
+ fd = open(path, O_WRONLY);
+ if(fd < 0) {
+ if (errno == EISDIR) {
+ /* for directory */
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ perror(path);
+ return ret;
+ }
+ } else {
+ perror(path);
+ return ret;
+ }
+ }
+
+ /* freeze operation */
+ if(strcmp(argv[1],"-f") == 0) {
+ ret = freeze_f(fd);
+ if (ret != 0) {
+ perror("freeze");
+ close(fd);
+ return ret;
+ }
+
+ }
+ /* unfreeze operation */
+ else if(strcmp(argv[1],"-u") == 0) {
+ ret = unfreeze_f(fd);
+ if (ret != 0) {
+ perror("unfreeze");
+ close(fd);
+ return ret;
+ }
+ } else {
+ close(fd);
+ usage();
+ }
+
+ close(fd);
+ } else {
+ usage();
+ }
+
+ return ret;
+}
(05/11/2010 19:01), Américo Wang wrote:
On Tue, May 11, 2010 at 01:25:09AM -0400, Hajime Taira wrote:
Hi,
Here is patch that add new command fsfreeze.
'fsfreeze' suspend and resume access to an filesystem (Linux Ext3/4, ReiserFS, JFS, XFS)
It like xfs_freeze command for XFS filesystem. I ported one for other filesystem.
Because util-linux-ng should have this. I think so.
<snip>
+
+int freeze_f(int fd)
+{
+ return ioctl(fd, FIFREEZE, 0);
+}
+
+int unfreeze_f(int fd)
+{
+ return ioctl(fd, FITHAW, 0);
+}
+
+void usage()
This needs to be "void usage(void)".
+{
+ fprintf(stderr, "fsfreeze -f | -u<mount point>\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "fsfreeze -f /mnt/target\n");
The last message is not necessary.
+}
+
+int main(int argc, char **argv)
+{
+ int fd;
+ int ret = -1;
+ char *path;
+
+ if(argc == 3)
+ {
+ path = argv[2];
+ fd = open(path, O_WRONLY);
+ if(fd< 0) {
Please keep one if-style in your code, either:
if (...) {
}
or:
if (...)
{
}
+ if (errno == EISDIR) {
+ fd = open(path, O_RDONLY);
+ if (fd< 0) {
+ perror(path);
+ return ret;
+ }
+ } else {
+ perror(path);
+ return ret;
+ }
+ }
Do we have to do open() twice here? I doubt.
--
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