-/* Prepare for multiple reads to a resource by caching a FILE * or NTFS
- * attribute pointer in the lookup table entry. */
-static int
-prepare_resource_for_read(struct wim_lookup_table_entry *lte
-
- #ifdef WITH_NTFS_3G
- , ntfs_inode **ni_ret
- #endif
- )
-{
- switch (lte->resource_location) {
- case RESOURCE_IN_FILE_ON_DISK:
- if (!lte->file_on_disk_fp) {
- lte->file_on_disk_fp = tfopen(lte->file_on_disk, T("rb"));
- if (!lte->file_on_disk_fp) {
- ERROR_WITH_ERRNO("Failed to open the file "
- "`%"TS"'", lte->file_on_disk);
- return WIMLIB_ERR_OPEN;
- }
- }
- break;
-#ifdef WITH_NTFS_3G
- case RESOURCE_IN_NTFS_VOLUME:
- if (!lte->attr) {
- struct ntfs_location *loc = lte->ntfs_loc;
- ntfs_inode *ni;
- wimlib_assert(loc);
- ni = ntfs_pathname_to_inode(*loc->ntfs_vol_p, NULL, loc->path);
- if (!ni) {
- ERROR_WITH_ERRNO("Failed to open inode `%"TS"' in NTFS "
- "volume", loc->path);
- return WIMLIB_ERR_NTFS_3G;
- }
- lte->attr = ntfs_attr_open(ni,
- loc->is_reparse_point ? AT_REPARSE_POINT : AT_DATA,
- loc->stream_name,
- loc->stream_name_nchars);
- if (!lte->attr) {
- ERROR_WITH_ERRNO("Failed to open attribute of `%"TS"' in "
- "NTFS volume", loc->path);
- ntfs_inode_close(ni);
- return WIMLIB_ERR_NTFS_3G;
- }
- *ni_ret = ni;
- }
- break;
-#endif
-#ifdef __WIN32__
- case RESOURCE_WIN32:
- if (lte->win32_file_on_disk_fp == INVALID_HANDLE_VALUE) {
- lte->win32_file_on_disk_fp =
- win32_open_file_data_only(lte->file_on_disk);
- if (lte->win32_file_on_disk_fp == INVALID_HANDLE_VALUE) {
- ERROR("Win32 API: Can't open %"TS, lte->file_on_disk);
- win32_error_last();
- return WIMLIB_ERR_OPEN;
- }
- }
- break;
-#endif
- default:
- break;
- }
- return 0;
-}
-
-/* Undo prepare_resource_for_read() by closing the cached FILE * or NTFS
- * attribute. */
-static void
-end_wim_resource_read(struct wim_lookup_table_entry *lte
- #ifdef WITH_NTFS_3G
- , ntfs_inode *ni
- #endif
- )
-{
- if (lte->resource_location == RESOURCE_IN_FILE_ON_DISK
- && lte->file_on_disk_fp)
- {
- fclose(lte->file_on_disk_fp);
- lte->file_on_disk_fp = NULL;
- }
-#ifdef WITH_NTFS_3G
- else if (lte->resource_location == RESOURCE_IN_NTFS_VOLUME) {
- if (lte->attr) {
- ntfs_attr_close(lte->attr);
- lte->attr = NULL;
- }
- if (ni)
- ntfs_inode_close(ni);
- }
-#endif
-#ifdef __WIN32__
- else if (lte->resource_location == RESOURCE_WIN32
- && lte->win32_file_on_disk_fp != INVALID_HANDLE_VALUE)
- {
- win32_close_file(lte->win32_file_on_disk_fp);
- lte->win32_file_on_disk_fp = INVALID_HANDLE_VALUE;
- }
-#endif
-}
-