File: diskfile.c

package info (click to toggle)
unar 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,664 kB
  • sloc: ansic: 52,939; objc: 39,563; cpp: 4,074; makefile: 99; perl: 10
file content (161 lines) | stat: -rwxr-xr-x 4,905 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef XADMASTER_DISKFILE_C
#define XADMASTER_DISKFILE_C

/*  $Id: diskfile.c,v 1.7 2005/06/23 14:54:37 stoecker Exp $
    file extraction from disk images

    XAD library system for archive handling
    Copyright (C) 1998 and later by Dirk Stˆcker <soft@dstoecker.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "include/functions.h"

FUNCxadGetDiskInfo /* struct xadArchiveInfoP *ai, xadTAGPTR tags */
{
  xadERROR err;
  xadINT32 noext = 0;
  struct xadImageInfo *ii;
  xadTAGPTR ti, ti2 = tags;
  xadUINT32 onlyflags = 0, ignoreflags = 0;

#ifdef DEBUG
  DebugTagList("xadGetDiskInfoA", tags);
#endif

  while((ti = NextTagItem(&ti2)))
  {
    switch(ti->ti_Tag)
    {
    case XAD_STARTCLIENT: ai->xaip_ArchiveInfo.xai_Client
    = (struct xadClient *)(uintptr_t) ti->ti_Data; break;
    case XAD_NOEXTERN: noext = ti->ti_Data; break;
    case XAD_NOEMPTYERROR:
      if(ti->ti_Data)
        ai->xaip_ArchiveInfo.xai_Flags |= XADAIF_NOEMPTYERROR;
      else
        ai->xaip_ArchiveInfo.xai_Flags &= ~XADAIF_NOEMPTYERROR;
      break;
    case XAD_IGNOREFLAGS: ignoreflags = ti->ti_Data; break;
    case XAD_ONLYFLAGS:   onlyflags = ti->ti_Data; break;
    }
  }

  if(noext)
    ignoreflags |= XADCF_EXTERN;

  ai->xaip_ArchiveInfo.xai_Flags |= XADAIF_ONLYIN;
  err = xadGetHookAccessA(XADM_PRIV XADM_AI(ai), tags);
  ai->xaip_ArchiveInfo.xai_Flags &= ~XADAIF_ONLYIN;

  if(!err)
  {
    if((ii = (struct xadImageInfo *) xadAllocObjectA(XADM XADOBJ_IMAGEINFO,
    0)))
    {
      struct xadClient *xc;
      ai->xaip_InHookParam.xhp_Command = XADHC_IMAGEINFO;
      ai->xaip_InHookParam.xhp_CommandData = (xadSignSize)(uintptr_t)ii;
      if(CallHookPkt(ai->xaip_InHook, ai, &ai->xaip_InHookParam))
      {
#ifdef DEBUG
  DebugOther("xadGetDiskInfoA: got no image info, using defaults");
#endif
        ii->xii_SectorSize = 512;
//        ii->xii_FirstSector = 0;
        ii->xii_NumSectors = ii->xii_TotalSectors = ai->xaip_InSize/512;
      }
      ai->xaip_ArchiveInfo.xai_ImageInfo = ii;

      xc = xadMasterBase->xmb_FirstClient;
      err = XADERR_FILESYSTEM;
      if(ai->xaip_ArchiveInfo.xai_Client)
      { /* do not use it directly to disable wrong pointer errors */
        while(xc && xc != ai->xaip_ArchiveInfo.xai_Client)
          xc = xc->xc_Next;
#ifdef DEBUG
  if(xc)
    DebugRunTime("xadGetDiskInfoA: Starting with client %s",
    xc->xc_ArchiverName);
#endif
        if(!xc)
        {
#ifdef DEBUG
  DebugError("xadGetDiskInfoA: Wrong start client pointer");
#endif
          err = XADERR_BADPARAMS;
        }
        ai->xaip_ArchiveInfo.xai_Client = 0; /* reset that field */
      }
      while(xc && err == XADERR_FILESYSTEM)
      {
        if((xc->xc_Flags & XADCF_FILESYSTEM) &&
        !(xc->xc_Flags & ignoreflags) && ((xc->xc_Flags & onlyflags)
        == onlyflags))
        {
#ifdef DEBUG
  DebugOther("xadGetDiskInfoA: Testing client %s", xc->xc_ArchiverName);
#endif
          err = 0;
          if(ai->xaip_ArchiveInfo.xai_InPos)
            err = xadHookAccess(XADM XADAC_INPUTSEEK,
            -ai->xaip_ArchiveInfo.xai_InPos, 0, XADM_AI(ai));
          if(!err)
          {
            ai->xaip_ArchiveInfo.xai_Client = xc;
            err = Callback_GetInfo(xc, ai, xadMasterBase);
          }
#ifdef DEBUG
  if(err == XADERR_FILESYSTEM)
  {
    if(ai->xaip_ArchiveInfo.xai_PrivateClient)
      DebugError("%s set PrivateClient field", xc->xc_ArchiverName);
    if(ai->xaip_ArchiveInfo.xai_FileInfo)
      DebugError("%s set FileInfo field", xc->xc_ArchiverName);
    if(ai->xaip_ArchiveInfo.xai_DiskInfo)
      DebugError("%s set DiskInfo field", xc->xc_ArchiverName);
  }
#endif
        }
        xc = xc->xc_Next;
      }
    }
    else
      err = XADERR_NOMEMORY;
  }

  if(!err && !ai->xaip_ArchiveInfo.xai_FileInfo &&
  !(ai->xaip_ArchiveInfo.xai_Flags & XADAIF_NOEMPTYERROR))
    err = XADERR_EMPTY;

  callprogress(ai, err, err ? XADPMODE_ERROR : XADPMODE_GETINFOEND,
  xadMasterBase);
  if(err)
    xadFreeInfo(XADM_PRIV XADM_AI(ai));

#ifdef DEBUG
  if(err)
  {
    DebugError("xadGetDiskInfo returns \"%s\" (%ld)",
    xadGetErrorText(XADM err), err);
  }
#endif

  return err;
}
ENDFUNC

#endif  /* XADMASTER_DISKFILE_C */