1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#!/bin/sh
. ./common
TEMPDIR="$(mktemp -d -t inodes.XXXXXXXXXX)"
trap "Unmount 2>/dev/null; rm -rf ${TEMPDIR}" EXIT
Setup () {
cat >${TEMPDIR}/inodes.cpp <<EOF
#include <dirent.h>
#include <sys/stat.h>
#include <map>
#include <iostream>
void perror_and_die (const char* s)
{
std::perror(s);
std::abort();
}
int
main(int argc, char *argv[])
{
int ret = EXIT_SUCCESS;
struct stat st;
std::map<ino_t, std::string> inodes;
DIR *dirp;
struct dirent *d;
if ((dirp = opendir("target")) == NULL) perror_and_die("opendir");
while ((d = readdir(dirp)) != NULL) {
const std::string filename = "target/" + std::string(d->d_name);
if (stat(filename.c_str(), &st) == -1)
perror_and_die("stat");
if (d->d_ino != st.st_ino) {
std::cerr << filename << ": inode from readdir does not match stat: "
<< d->d_ino << " != " << st.st_ino << std::endl;
ret = EXIT_FAILURE;
}
if (inodes.find(d->d_ino) == inodes.end()) {
inodes[d->d_ino] = filename;
} else {
std::cerr << filename << ": duplicate inode: " << d->d_ino
<< " used by " << inodes[d->d_ino] << std::endl;
ret = EXIT_FAILURE;
}
}
if (closedir(dirp) == -1) perror_and_die("closedir");
return ret;
}
EOF
c++ -Wall -Werror -pedantic -o${TEMPDIR}/inodes ${TEMPDIR}/inodes.cpp || \
Fail "Could not compile testcase"
}
Setup
Mount
${TEMPDIR}/inodes || Fail "inodes"
Unmount
|