if (sqfs_disk_read(0, 1, *sblk) != 1) {
free(*sblk);
+ sblk = NULL;
return -EINVAL;
}
*actread = 0;
+ if (offset) {
+ /*
+ * TODO: implement reading at an offset in file
+ */
+ printf("Error: reading at a specific offset in a squashfs file is not supported yet.\n");
+ return -EINVAL;
+ }
+
/*
* sqfs_opendir will uncompress inode and directory tables, and will
* return a pointer to the directory that contains the requested file.
}
finfo.size = len;
+ } else {
+ len = finfo.size;
}
if (datablk_count) {
if (ret)
goto out;
- memcpy(buf + offset + *actread, datablock, dest_len);
+ if ((*actread + dest_len) > len)
+ dest_len = len - *actread;
+ memcpy(buf + *actread, datablock, dest_len);
*actread += dest_len;
} else {
- memcpy(buf + offset + *actread, data, table_size);
+ if ((*actread + table_size) > len)
+ table_size = len - *actread;
+ memcpy(buf + *actread, data, table_size);
*actread += table_size;
}
data_offset += table_size;
free(data_buffer);
data_buffer = NULL;
+ if (*actread >= len)
+ break;
}
/*
goto out;
}
- for (j = offset + *actread; j < finfo.size; j++) {
+ for (j = *actread; j < finfo.size; j++) {
memcpy(buf + j, &fragment_block[finfo.offset + j], 1);
(*actread)++;
}
} else if (finfo.frag && !finfo.comp) {
fragment_block = (void *)fragment + table_offset;
- for (j = offset + *actread; j < finfo.size; j++) {
+ for (j = *actread; j < finfo.size; j++) {
memcpy(buf + j, &fragment_block[finfo.offset + j], 1);
(*actread)++;
}
return ret;
}
+int sqfs_exists(const char *filename)
+{
+ struct fs_dir_stream *dirsp = NULL;
+ struct squashfs_dir_stream *dirs;
+ char *dir, *file;
+ struct fs_dirent *dent;
+ int ret;
+
+ sqfs_split_path(&file, &dir, filename);
+ /*
+ * sqfs_opendir will uncompress inode and directory tables, and will
+ * return a pointer to the directory that contains the requested file.
+ */
+ ret = sqfs_opendir(dir, &dirsp);
+ if (ret) {
+ ret = -EINVAL;
+ goto free_strings;
+ }
+
+ dirs = (struct squashfs_dir_stream *)dirsp;
+
+ while (!sqfs_readdir(dirsp, &dent)) {
+ ret = strcmp(dent->name, file);
+ if (!ret)
+ break;
+ free(dirs->entry);
+ dirs->entry = NULL;
+ }
+
+ sqfs_closedir(dirsp);
+
+free_strings:
+ free(dir);
+ free(file);
+
+ return ret == 0;
+}
+
void sqfs_close(void)
{
+ sqfs_decompressor_cleanup(&ctxt);
free(ctxt.sblk);
+ ctxt.sblk = NULL;
ctxt.cur_dev = NULL;
- sqfs_decompressor_cleanup(&ctxt);
}
void sqfs_closedir(struct fs_dir_stream *dirs)