2
* FL-COW by Davide Libenzi ( File Links Copy On Write )
3
* Copyright (C) 2003 Davide Libenzi
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Davide Libenzi <davidel@xmailserver.org>
28
#include <sys/types.h>
36
#define DUMMY_DATA1 "FLCOW Test Data Before"
37
#define DUMMY_DATA2 "FLCOW Test Data After"
40
static int create_file(char const *name, char const *data) {
43
if ((fd = open(name, O_WRONLY | O_CREAT, 0666)) == -1) {
47
write(fd, data, strlen(data));
55
int main(int argc, char **argv) {
56
struct stat stb1, stb2;
57
char buf[512], name1[512], name2[512];
59
getcwd(buf, sizeof(buf) - 1);
60
setenv("FLCOW_PATH", buf, 1);
62
sprintf(name1, ",,flcow-test1++.%u", getpid());
63
if (create_file(name1, DUMMY_DATA1) < 0) {
64
fprintf(stdout, "Test Result\t\t[ FAILED ]\n");
67
fprintf(stdout, "File Creation\t\t[ OK ]\n");
69
sprintf(name2, ",,flcow-test2++.%u", getpid());
70
if (link(name1, name2) < 0) {
72
fprintf(stdout, "Test Result\t\t[ FAILED ]\n");
75
fprintf(stdout, "Link Creation\t\t[ OK ]\n");
79
if (stb1.st_nlink < 2 || stb2.st_nlink < 2) {
82
fprintf(stdout, "Link Check\t\t[ FAILED ]\n");
85
fprintf(stdout, "Link Check\t\t[ OK ]\n");
87
if (create_file(name1, DUMMY_DATA2) < 0) {
90
fprintf(stdout, "File Rewrite\t\t[ FAILED ]\n");
93
fprintf(stdout, "File Rewrite\t\t[ OK ]\n");
97
if (stb1.st_nlink > 1 || stb2.st_nlink > 1) {
100
fprintf(stdout, "COW Check\t\t[ FAILED ]\n");
103
fprintf(stdout, "COW Check\t\t[ OK ]\n");
108
fprintf(stdout, "Test Result\t\t[ OK ]\n");