static char *ext2fs_read_symlink(struct ext2fs_node *node) { char *symlink; struct ext2fs_node *diro = node; int status; if (!diro->inode_read) { status = ext2fs_read_inode (diro->data, diro->ino, &diro->inode); if (status == 0) { return (0); } } symlink = malloc (__le32_to_cpu (diro->inode.size) + 1); if (!symlink) { return (0); } /* If the filesize of the symlink is bigger than 60 the symlink is stored in a separate block, otherwise it is stored in the inode. */ if (__le32_to_cpu (diro->inode.size) <= 60) { strncpy (symlink, diro->inode.b.symlink, __le32_to_cpu (diro->inode.size)); } else { status = ext2fs_read_file (diro, 0, __le32_to_cpu (diro->inode.size), symlink); if (status == 0) { free (symlink); return (0); } } symlink[__le32_to_cpu (diro->inode.size)] = '\0'; return (symlink); }
int ext2fs_read (char *buf, unsigned len) { int status; if (ext2fs_root == NULL) { return (0); } if (ext2fs_file == NULL) { return (0); } status = ext2fs_read_file (ext2fs_file, 0, len, buf); return (status); }
quik_err_t ext2fs_read(char *buf, unsigned len) { quik_err_t err; if (ext2fs_root == NULL) { return ERR_FS_NOT_FOUND; } if (ext2fs_file == NULL) { return ERR_FS_NOT_FOUND; } err = ext2fs_read_file(ext2fs_file, 0, len, buf); return err; }
static quik_err_t ext2fs_read_symlink(ext2fs_node_t node, char **out) { char *symlink; struct ext2fs_node *diro = node; quik_err_t err; if (!diro->inode_read) { err = ext2fs_read_inode(diro->data, diro->ino, &diro->inode); if (err != ERR_NONE) { return err; } } symlink = malloc(__le32_to_cpu(diro->inode.size) + 1); if (!symlink) { return ERR_NO_MEM; } /* * If the filesize of the symlink is bigger than * 60 the symlink is stored in a separate block, * otherwise it is stored in the inode. */ if (__le32_to_cpu(diro->inode.size) <= 60) { strncpy(symlink, diro->inode.b.symlink, __le32_to_cpu(diro->inode.size)); } else { err = ext2fs_read_file(diro, 0, __le32_to_cpu(diro->inode.size), symlink); if (err != ERR_NONE) { free(symlink); return err; } } symlink[__le32_to_cpu(diro->inode.size)] = '\0'; *out = symlink; return ERR_NONE; }
int ext2fs_iterate_dir(struct ext2fs_node *dir, char *name, struct ext2fs_node **fnode, int *ftype) { unsigned int fpos = 0; int status; struct ext2fs_node *diro = (struct ext2fs_node *) dir; #ifdef DEBUG if (name != NULL) printf ("Iterate dir %s\n", name); #endif /* of DEBUG */ if (!diro->inode_read) { status = ext2fs_read_inode (diro->data, diro->ino, &diro->inode); if (status == 0) { return (0); } } /* Search the file. */ while (fpos < __le32_to_cpu (diro->inode.size)) { struct ext2_dirent dirent; status = ext2fs_read_file (diro, fpos, sizeof (struct ext2_dirent), (char *) &dirent); if (status < 1) { return (0); } if (dirent.namelen != 0) { char filename[dirent.namelen + 1]; struct ext2fs_node *fdiro; int type = FILETYPE_UNKNOWN; status = ext2fs_read_file (diro, fpos + sizeof (struct ext2_dirent), dirent.namelen, filename); if (status < 1) { return (0); } fdiro = malloc (sizeof (struct ext2fs_node)); if (!fdiro) { return (0); } fdiro->data = diro->data; fdiro->ino = __le32_to_cpu (dirent.inode); filename[dirent.namelen] = '\0'; if (dirent.filetype != FILETYPE_UNKNOWN) { fdiro->inode_read = 0; if (dirent.filetype == FILETYPE_DIRECTORY) { type = FILETYPE_DIRECTORY; } else if (dirent.filetype == FILETYPE_SYMLINK) { type = FILETYPE_SYMLINK; } else if (dirent.filetype == FILETYPE_REG) { type = FILETYPE_REG; } } else { /* The filetype can not be read from the dirent, get it from inode */ status = ext2fs_read_inode (diro->data, __le32_to_cpu(dirent.inode), &fdiro->inode); if (status == 0) { free (fdiro); return (0); } fdiro->inode_read = 1; if ((__le16_to_cpu (fdiro->inode.mode) & FILETYPE_INO_MASK) == FILETYPE_INO_DIRECTORY) { type = FILETYPE_DIRECTORY; } else if ((__le16_to_cpu (fdiro->inode.mode) & FILETYPE_INO_MASK) == FILETYPE_INO_SYMLINK) { type = FILETYPE_SYMLINK; } else if ((__le16_to_cpu (fdiro->inode.mode) & FILETYPE_INO_MASK) == FILETYPE_INO_REG) { type = FILETYPE_REG; } } #ifdef DEBUG printf ("iterate >%s<\n", filename); #endif /* of DEBUG */ if ((name != NULL) && (fnode != NULL) && (ftype != NULL)) { if (strcmp (filename, name) == 0) { *ftype = type; *fnode = fdiro; return (1); } } else { if (fdiro->inode_read == 0) { status = ext2fs_read_inode (diro->data, __le32_to_cpu (dirent.inode), &fdiro->inode); if (status == 0) { free (fdiro); return (0); } fdiro->inode_read = 1; } switch (type) { case FILETYPE_DIRECTORY: printf ("<DIR> "); break; case FILETYPE_SYMLINK: printf ("<SYM> "); break; case FILETYPE_REG: printf (" "); break; default: printf ("< ? > "); break; } printf ("%10d %s\n", __le32_to_cpu (fdiro->inode.size), filename); } free (fdiro); } fpos += __le16_to_cpu (dirent.direntlen); } return (0); }