Пример #1
0
int __getcwd(char *path, size_t size)
{
    struct stat above, current, tmp;
    struct dirent *entry;
    DIR *d;
    char *p, *up, *dotdot;
    int cycle;

    if (path == NULL || size <= 1) {
        errno= EINVAL;
        return -1;
    }

    p= path + size;
    *--p = 0;

    if (stat(".", &current) < 0) return -1;

    while (1) {
        dotdot= "..";
        if (stat(dotdot, &above) < 0) {
            recover(p);
            return -1;
        }

        if (above.st_dev == current.st_dev
                && above.st_ino == current.st_ino)
            break;	/* Root dir found */

        if ((d= opendir(dotdot)) == NULL) {
            recover(p);
            return -1;
        }

        /* Cycle is 0 for a simple inode nr search, or 1 for a search
         * for inode *and* device nr.
         */
        cycle= above.st_dev == current.st_dev ? 0 : 1;

        do {
            char name[3 + NAME_MAX + 1];

            tmp.st_ino= 0;
            if ((entry= readdir(d)) == NULL) {
                switch (++cycle) {
                case 1:
                    rewinddir(d);
                    continue;
                case 2:
                    closedir(d);
                    errno= ENOENT;
                    recover(p);
                    return -1;
                }
            }
            if (strcmp(entry->d_name, ".") == 0) continue;
            if (strcmp(entry->d_name, "..") == 0) continue;

            switch (cycle) {
            case 0:
                /* Simple test on inode nr. */
                if (entry->d_ino != current.st_ino) continue;
            /*FALL THROUGH*/

            case 1:
                /* Current is mounted. */
                strcpy(name, "../");
                strcpy(name+3, entry->d_name);
                if (stat(name, &tmp) < 0) continue;
                break;
            }
        } while (tmp.st_ino != current.st_ino
                 || tmp.st_dev != current.st_dev);

        up= p;
        if (addpath(path, &up, entry->d_name) < 0) {
            closedir(d);
            errno = ERANGE;
            recover(p);
            return -1;
        }
        closedir(d);

        if (chdir(dotdot) < 0) {
            recover(p);
            return -1;
        }
        p= up;

        current= above;
    }
    if (recover(p) < 0) return -1;	/* Undo all those chdir("..")'s. */
    if (*p == 0) *--p = '/';	/* Cwd is "/" if nothing added */
    if (p > path) strcpy(path, p);	/* Move string to start of path. */
    return 0;
}
Пример #2
0
void testmem(char *msg, char *page, enum rmode mode)
{
	printf("%s page %p\n", msg, page);
	poison(msg, page, mode);
	recover(msg, page, mode);
}
Пример #3
0
bool RecoveryEngine::recover(FileAgent * faultyFa) {
	FileRecovery fr(faultyFa);
	bool recovered = recover(&fr);
	return recovered;
}
Пример #4
0
bool RecoveryEngine::recover(EnvironmentAgent * faultyEa) {
	EnvironmentRecovery er(faultyEa);
	bool recovered = recover(&er);
	return recovered;
}
Пример #5
0
bool RecoveryEngine::recover(ProcessAgent * faultyPa) {
	ProcessRecovery pr(faultyPa);
	bool recovered = recover(&pr);
	return recovered;
}