2
* Copyright (C) 2002-2005 Novell/SUSE
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation, version 2 of the
13
#include <sys/types.h>
18
#include <linux/unistd.h>
20
#include "changehat.h"
22
/* A test to validate that we are properly handling the kernel appending
23
* (deleted) in d_path lookup.
24
* To acheive this the file is opened (the read/write of the file is just to
25
* make sure everything is working as expected), deleted without closing the
26
* file reference, and doing a changehat.
27
* The file is then used inside of the changehat. This forces the file
28
* access permission to be revalidated which will cause a path lookup and
29
* expose if the module is not handling the kernel appending (deleted).
31
int main(int argc, char *argv[])
34
int ret = 0; /* run through all tests to see what breaks */
35
const char *data="hello world";
40
fprintf(stderr, "usage: %s hat file\n",
42
for (i=0; i < argc; i++) {
43
fprintf(stderr, "arg%d: %s\n", i, argv[i]);
48
fd = open(argv[2], O_RDWR, 0);
50
fprintf(stderr, "FAIL: open %s before changehat failed - %s\n",
56
rc = write(fd, data, strlen(data));
57
if (rc != strlen(data)){
58
fprintf(stderr, "FAIL: write before changehat failed - %s\n",
65
fprintf(stderr, "FAIL: unlink before changehat failed - %s\n",
70
if (strcmp(argv[1], "nochange") != 0){
71
rc = change_hat(argv[1], SD_ID_MAGIC+1);
73
fprintf(stderr, "FAIL: changehat %s failed - %s\n",
74
argv[1], strerror(errno));
78
/******** The actual tests for (deleted) begin here *******/
80
/* changehat causes revalidation */
81
(void)lseek(fd, 0, SEEK_SET);
82
rc = read(fd, buf, sizeof(buf));
84
if (rc != strlen(data)){
85
fprintf(stderr, "FAIL: read1 after changehat failed - %s\n",
90
/* test that we can create the file. Not necessarily a (deleted)
91
* case but lets us flush out other combinations.
93
fd2=creat(argv[2], S_IRUSR | S_IWUSR);
95
fprintf(stderr, "FAIL: creat %s - %s\n",
102
/* reread after closing the created file, this should be revalidated
103
* and force a lookup that still has (deleted) appended
105
(void)lseek(fd, 0, SEEK_SET);
106
rc=read(fd, buf, sizeof(buf));
108
if (rc != strlen(data)){
109
fprintf(stderr, "FAIL: read2 after changehat failed - %s\n",
116
/* should be able to open it. Shouldn't have (deleted) */
117
fd=open(argv[2], O_RDWR, 0);
119
fprintf(stderr, "FAIL: open %s after creat failed - %s\n",
127
/* Hmm it would be nice to add a fork/exec test for (deleted) but
128
* changehat does it for now.