예제 #1
0
int ext2fs_ls (const char *dirname) {
    struct ext2fs_node *dirnode;
    int status;

    if (ext2fs_root == NULL) {
        return (0);
    }

    status = ext2fs_find_file (dirname, &ext2fs_root->diropen, &dirnode,
                   FILETYPE_DIRECTORY);
    if (status != 1) {
        printf ("** Can not find directory. **\n");
        return (1);
    }
    ext2fs_iterate_dir (dirnode, NULL, NULL, NULL);
    ext2fs_free_node (dirnode, &ext2fs_root->diropen);
    return (0);
}
예제 #2
0
파일: ext2fs.c 프로젝트: andreiw/iQUIK
quik_err_t
ext2fs_ls(char *dirname)
{
   ext2fs_node_t dirnode;
   quik_err_t err;

   if (ext2fs_root == NULL) {
      return ERR_FS_NOT_FOUND;
   }

   err = ext2fs_find_file(dirname, &ext2fs_root->diropen, &dirnode,
                          FILETYPE_DIRECTORY);
   if (err != ERR_NONE) {
      return err;
   }

   ext2fs_iterate_dir(dirnode, NULL, NULL, NULL);
   ext2fs_free_node(dirnode, &ext2fs_root->diropen);
   return ERR_NONE;
}
예제 #3
0
int ext2fs_find_file1
    (const char *currpath, struct ext2fs_node *currroot,
        struct ext2fs_node **currfound, int *foundtype)
{
    char fpath[strlen (currpath) + 1];
    char *name = fpath;
    char *next;
    int status;
    int type = FILETYPE_DIRECTORY;
    struct ext2fs_node *currnode = currroot;
    struct ext2fs_node *oldnode = currroot;

    strncpy (fpath, currpath, strlen (currpath) + 1);

    /* Remove all leading slashes.  */
    while (*name == '/') {
        name++;
    }
    if (!*name) {
        *currfound = currnode;
        return (1);
    }

    for (;;) {
        int found;

        /* Extract the actual part from the pathname.  */
        next = strchr (name, '/');
        if (next) {
            /* Remove all leading slashes.  */
            while (*next == '/') {
                *(next++) = '\0';
            }
        }

        /* At this point it is expected that the current node is a directory, check if this is true.  */
        if (type != FILETYPE_DIRECTORY) {
            ext2fs_free_node (currnode, currroot);
            return (0);
        }

        oldnode = currnode;

        /* Iterate over the directory.  */
        found = ext2fs_iterate_dir (currnode, name, &currnode, &type);
        if (found == 0) {
            return (0);
        }
        if (found == -1) {
            break;
        }

        /* Read in the symlink and follow it.  */
        if (type == FILETYPE_SYMLINK) {
            char *symlink;

            /* Test if the symlink does not loop.  */
            if (++symlinknest == 8) {
                ext2fs_free_node (currnode, currroot);
                ext2fs_free_node (oldnode, currroot);
                return (0);
            }

            symlink = ext2fs_read_symlink (currnode);
            ext2fs_free_node (currnode, currroot);

            if (!symlink) {
                ext2fs_free_node (oldnode, currroot);
                return (0);
            }
#ifdef DEBUG
            printf ("Got symlink >%s<\n", symlink);
#endif /* of DEBUG */
            /* The symlink is an absolute path, go back to the root inode.  */
            if (symlink[0] == '/') {
                ext2fs_free_node (oldnode, currroot);
                oldnode = &ext2fs_root->diropen;
            }

            /* Lookup the node the symlink points to.  */
            status = ext2fs_find_file1 (symlink, oldnode,
                            &currnode, &type);

            free (symlink);

            if (status == 0) {
                ext2fs_free_node (oldnode, currroot);
                return (0);
            }
        }

        ext2fs_free_node (oldnode, currroot);

        /* Found the node!  */
        if (!next || *next == '\0') {
            *currfound = currnode;
            *foundtype = type;
            return (1);
        }
        name = next;
    }
    return (-1);
}