> I knew, my point is why do you try to open it as a file first, > then as a directory? If you really have to do so, how about > using stat() to check if it's a file first then do open()? Ok, done. I changed open() to stat(). Thanks --- util-linux-ng.old/fsfreeze/fsfreeze.c 1970-01-01 09:00:00.000000000 +0900 +++ util-linux-ng/fsfreeze/fsfreeze.c 2010-05-12 14:30:21.000000000 +0900 @@ -0,0 +1,94 @@ +/* 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> +#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; + int ret = -1; + char *path; + struct stat sb; + + if(argc == 3) { + path = argv[2]; + + if(stat(path, &sb) == -1) { + perror(path); + return ret; + } + + if((sb.st_mode & S_IFMT) == S_IFDIR) { + fd = open(path, O_RDONLY); + if (fd < 0) { + perror(path); + return ret; + } + } else { + usage(); + 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(); + return ret; + } + + close(fd); + } else { + usage(); + } + + return ret; +} Best regards, Taira ----- 元のメッセージ ----- From: "Américo Wang" <xiyou.wangcong@xxxxxxxxx> To: "Hajime Taira" <htaira@xxxxxxxxxx> Cc: "Américo Wang" <xiyou.wangcong@xxxxxxxxx>, util-linux-ng@xxxxxxxxxxxxxxx 送信済み: 2010年5月12日, 水曜日 午後 2:09:34 GMT+09:00日本 件名: Re: [PATCH] fsfreeze: suspend and resume access to an filesystem On Wed, May 12, 2010 at 01:50:35PM +0900, Hajime Taira wrote: >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. I knew, my point is why do you try to open it as a file first, then as a directory? If you really have to do so, how about using stat() to check if it's a file first then do open()? Thanks. -- 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