Exemplo n.º 1
0
/*
 *  ======== DriverAdapter_reclaim ========
 */
Void DriverAdapter_reclaim(DriverAdapter_Object *obj, 
    DriverTypes_Packet **packet, Error_Block *eb)
{
    List_Handle fromDriver;

    fromDriver = DriverAdapter_Instance_State_fromDriver(obj);

    /* Should never ever get this assert */
    Assert_isTrue(!List_empty(fromDriver), DriverAdapter_A_noReadyPacket);

    *packet = (DriverTypes_Packet *)List_get(fromDriver);
}
Exemplo n.º 2
0
/**
 * Recomputes the distance map.
 * @param map The map.
 * @param cars The cars on the track.
 */
void recomputeDistances(Map map, Car cars[3])
{
	int i;
	List takenPositions = List_new();

	for(i = 0; i < 3; i++)
		if(Car_hasArrived(cars[i]))
			List_insert(takenPositions, Car_getPosition(cars[i]));

	Map_recomputeDistances(map, takenPositions);

	List_empty(takenPositions);
	List_delete(takenPositions);
}
Exemplo n.º 3
0
Bool SrcFile_pop( SrcFile *self )
{
	FileStackElem *elem;
	
	if ( List_empty( self->file_stack ) )
		return FALSE;
		
	if ( self->file != NULL )
		myfclose( self->file );
		
	elem = List_pop( self->file_stack );
	self->file		= elem->file;
	self->filename	= elem->filename;
	self->line_nr	= elem->line_nr;
	
	m_free( elem );
	return TRUE;
}
Exemplo n.º 4
0
bool SrcFile_pop( SrcFile *self )
{
	FileStackElem *elem;
	
	if ( List_empty( self->file_stack ) )
		return false;
		
	if ( self->file != NULL )
		xfclose( self->file );
		
	elem = List_pop( self->file_stack );
	self->file		= elem->file;
	self->filename = elem->filename;
	self->line_filename = elem->line_filename;
	self->line_nr   = elem->line_nr;
	self->line_inc = elem->line_inc;
	self->is_c_source = elem->is_c_source;

	m_free( elem );
	return true;
}
Exemplo n.º 5
0
/*
 *  ======== Notify_unregisterEvent ========
 */
Int Notify_unregisterEvent(UInt16                 procId,
                           UInt16                 lineId,
                           UInt32                 eventId,
                           Notify_FnNotifyCbck    fnNotifyCbck,
                           UArg                   cbckArg)
{
    UInt32  strippedEventId = (eventId & 0xFFFF);
    UInt16  clusterId = ti_sdo_utils_MultiProc_getClusterId(procId);
    Int     status;
    UInt    sysKey, modKey;
    ti_sdo_ipc_Notify_Object *obj;
    List_Handle eventList;
    ti_sdo_ipc_Notify_EventListener *listener;
    UInt    count = 0;

    Assert_isTrue(procId < ti_sdo_utils_MultiProc_numProcessors && lineId <
                  ti_sdo_ipc_Notify_numLines, ti_sdo_ipc_Notify_A_invArgument);
    Assert_isTrue(strippedEventId < ti_sdo_ipc_Notify_numEvents,
                  ti_sdo_ipc_Notify_A_invArgument);
    Assert_isTrue(ISRESERVED(eventId), ti_sdo_ipc_Notify_A_reservedEvent);

    modKey = Gate_enterModule();

    obj = (ti_sdo_ipc_Notify_Object *)
          Notify_module->notifyHandles[clusterId][lineId];

    Assert_isTrue(obj != NULL, ti_sdo_ipc_Notify_A_notRegistered);

    eventList = List_Object_get(obj->eventList, strippedEventId);

    if (List_empty(eventList)) {
        return (Notify_E_NOTFOUND);
    }

    /* Get the first listener on the list */
    listener = (ti_sdo_ipc_Notify_EventListener *)List_next(eventList, NULL);

    while (listener != NULL) {
        count++;
        if (listener->callback.fnNotifyCbck == (Fxn)fnNotifyCbck &&
                listener->callback.cbckArg == cbckArg ) {
            break;      /* found a match! */
        }
        listener = (ti_sdo_ipc_Notify_EventListener *)
                   List_next(eventList, (List_Elem *)listener);
    }

    if (listener == NULL) {
        /* Event listener not found */
        status = Notify_E_NOTFOUND;
    }
    else {
        if (count == 1 && List_next(eventList, (List_Elem *)listener) == NULL) {
            /*
             *  If only one element counted so far and the List_next returns
             *  NULL, the list will be empty after unregistering.  Therefore,
             *  unregister the callback function.
             */
            status = Notify_unregisterEventSingle(procId, lineId, eventId);
            /* unregisterEvent should always suceed */
            Assert_isTrue(status == Notify_S_SUCCESS,
                          ti_sdo_ipc_Notify_A_internal);

            /*  No need to protect the list removal: the event's unregistered */
            List_remove(eventList, (List_Elem *)listener);
        }
        else {
            /*
             *  Need to atomically remove from the list using the system gate
             *  because Notify_exec might preempt List_remove (the event is
             *  still registered)
             */
            sysKey = Hwi_disable();
            List_remove(eventList, (List_Elem *)listener);
            Hwi_restore(sysKey);
        }

        /* Free the memory alloc'ed for the event listener */
        Memory_free(ti_sdo_ipc_Notify_Object_heap(), listener,
                    sizeof(ti_sdo_ipc_Notify_EventListener));

        status = Notify_S_SUCCESS;
    }

    Gate_leaveModule(modKey);

    return (status);
}
Exemplo n.º 6
0
/*
 *  ======== Notify_registerEvent ========
 */
Int Notify_registerEvent(UInt16                 procId,
                         UInt16                 lineId,
                         UInt32                 eventId,
                         Notify_FnNotifyCbck    fnNotifyCbck,
                         UArg                   cbckArg)
{
    UInt32               strippedEventId = (eventId & 0xFFFF);
    UInt16 clusterId =   ti_sdo_utils_MultiProc_getClusterId(procId);
    Int                  status;
    ti_sdo_ipc_Notify_Object        *obj;
    UInt                 modKey;
    List_Handle          eventList;
    ti_sdo_ipc_Notify_EventListener *listener;
    Bool                 listWasEmpty;
    Error_Block          eb;

    Assert_isTrue(procId < ti_sdo_utils_MultiProc_numProcessors &&
                  lineId < ti_sdo_ipc_Notify_numLines, ti_sdo_ipc_Notify_A_invArgument);
    Assert_isTrue(strippedEventId < ti_sdo_ipc_Notify_numEvents,
                  ti_sdo_ipc_Notify_A_invArgument);
    Assert_isTrue(ISRESERVED(eventId), ti_sdo_ipc_Notify_A_reservedEvent);

    Error_init(&eb);

    modKey = Gate_enterModule();

    obj = (ti_sdo_ipc_Notify_Object *)
          Notify_module->notifyHandles[clusterId][lineId];

    Assert_isTrue(obj != NULL, ti_sdo_ipc_Notify_A_notRegistered);

    /* Allocate a new EventListener */
    listener = Memory_alloc(ti_sdo_ipc_Notify_Object_heap(),
                            sizeof(ti_sdo_ipc_Notify_EventListener), 0, &eb);
    if (listener == NULL) {
        /* Listener memory allocation failed.  Leave module gate & return */
        Gate_leaveModule(modKey);

        return (Notify_E_MEMORY);
    }

    listener->callback.fnNotifyCbck = (Fxn)fnNotifyCbck;
    listener->callback.cbckArg = cbckArg;

    eventList = List_Object_get(obj->eventList, strippedEventId);

    /*
     *  Store whether the list was empty so we know whether to register the
     *  callback
     */
    listWasEmpty = List_empty(eventList);

    /*
     *  Need to atomically add to the list using the system gate because
     *  Notify_exec might preempt List_remove.  List_put is atomic.
     */
    List_put(eventList, (List_Elem *)listener);

    if (listWasEmpty) {
        /*
         *  Registering this event for the first time.  Need to register the
         *  callback function.
         */
        status = Notify_registerEventSingle(procId, lineId, eventId,
                                            Notify_execMany, (UArg)obj);

        /* Notify_registerEventSingle should always succeed */
        Assert_isTrue(status == Notify_S_SUCCESS,
                      ti_sdo_ipc_Notify_A_internal);
    }

    status = Notify_S_SUCCESS;

    Gate_leaveModule(modKey);

    return (status);
}
Exemplo n.º 7
0
/* get the next line of input, normalize end of line termination (i.e. convert
   "\r", "\r\n" and "\n\r" to "\n"
   Calls the new_line_cb call back and returns the pointer to the null-terminated 
   text data in Str *line, including the final "\n".
   Returns NULL on end of file. */
char *SrcFile_getline( SrcFile *self )
{
    int c, c1;
    Bool found_newline;
    char *line;

    /* clear result string */
    str_clear( self->line );

    /* check for line stack */
    if ( ! List_empty( self->line_stack ) )
    {
        line = List_pop( self->line_stack );

        /* we own the string now and need to release memory */
		str_set( self->line, line );
        m_free( line );

        /* dont increment line number as we are still on same file input line */
        return str_data(self->line);
    }

    /* check for EOF condition */
    if ( self->file == NULL )
        return NULL;

    /* read characters */
    found_newline = FALSE;
    while ( ! found_newline && ( c = getc( self->file ) ) != EOF )
    {
        switch ( c )
        {
        case '\r':
        case '\n':
            c1 = getc( self->file );

            if ( ( c1 == '\r' || c1 == '\n' ) &&	/* next char also newline */
                    c1 != c )						/* "\r\n" or "\n\r" */
            {
                /* c1 will be discarded */
            }
            else								/* not composite newline - push back */
            {
                if ( c1 != EOF )
                {
                    ungetc( c1, self->file );	/* push back except EOF */
                }
            }

            /* normalize newline and fall through to default */
            found_newline = TRUE;
            c = '\n';

        default:
            str_append_char( self->line, c );
        }
    }

    /* terminate string if needed */
    if ( str_len(self->line) > 0 && ! found_newline )
        str_append_char( self->line, '\n' );

	/* signal new line, even empty one, to show end line in list */
    self->line_nr++;
	call_new_line_cb( self->filename, self->line_nr, str_data(self->line) );

	/* check for end of file
	   even if EOF found, we need to return any chars in line first */
    if ( str_len(self->line) > 0 )		
    {
        return str_data(self->line);
    }
    else
    {
        /* EOF - close file */
        myfclose( self->file );				/* close input */
        self->file = NULL;

//		call_new_line_cb( NULL, 0, NULL );
        return NULL;						/* EOF */
    }
}
Exemplo n.º 8
0
List doPathfinding(Map map, Car cars[3])
{
	Heap openSet = Heap_new(State_compare);
	List closedSet = List_new();
	List finalPath = List_new();
	List neighbors;
	Position neighbor;
	State state, newState;
	Vector newSpeed, acceleration;
	int end = 0, i, j, useBoost, positionTaken, distance;
	float cost;

	LOGINFO("A* doin' da werk!");

	state = State_new(Car_getPosition(cars[0]), Car_getSpeed(cars[0]), Car_getBoosts(cars[0]), map);
	Heap_insert(openSet, state);

	while(!Heap_isEmpty(openSet) && !end)
	{
		state = Heap_extractMin(openSet);

		if(Map_getTile(map, State_getPosition(state)->x, State_getPosition(state)->y) == ARRIVAL)
		{
			end = 1;
			break;
		}

		distance = Map_getDistance(map, State_getPosition(state)->x, State_getPosition(state)->y);
		neighbors = Map_getReachablePositions(map, State_getPosition(state), State_getSpeed(state), State_getBoosts(state));

		List_foreach(neighbors, neighbor, i)
		{
			if(Map_getDistance(map, neighbor->x, neighbor->y) > distance)
			{
				Position_delete(neighbor);
				continue;
			}

			cost = State_getRealCost(state) + 1;
			newSpeed = Position_findOffset(State_getPosition(state), neighbor);
			acceleration = Vector_copy(newSpeed);
			Vector_substract(acceleration, State_getSpeed(state));
			useBoost = 0;
			positionTaken = 0;

			if(Vector_squaredLength(acceleration) > 2)
			{
				useBoost = 1;
			}

			for(j = 1; j < 3; j++)
			{
				if(Position_equal(neighbor, Car_getPosition(cars[j])))
				{
					positionTaken = 1;
				}
			}

			if(!positionTaken)
			{
				newState = State_new(neighbor, newSpeed, State_getBoosts(state) - useBoost, map);
				State_setRealCost(newState, cost);
				State_setParent(newState, state);

				Heap_insert(openSet, newState);
			}

			Vector_delete(newSpeed);
			Vector_delete(acceleration);
			Position_delete(neighbor);
		}

		List_insert(closedSet, state);

		List_empty(neighbors);
		List_delete(neighbors);
	}

	while(state != NULL)
	{
		List_insert(finalPath, Position_copy(State_getPosition(state)));

		state = State_getParent(state);
	}

	List_head(closedSet);
	while(!List_isEmpty(closedSet))
	{
		state = List_getCurrent(closedSet);
		List_remove(closedSet);
		State_delete(state);
	}

	List_delete(closedSet);

	while((state = Heap_extractMin(openSet)) != NULL)
	{
		State_delete(state);
	}

	Heap_delete(openSet);

	LOGINFO("A* is done mate");

	return finalPath;
}
Exemplo n.º 9
0
Errors Command_compare(StringList                      *archiveFileNameList,
                       EntryList                       *includeEntryList,
                       PatternList                     *excludePatternList,
                       JobOptions                      *jobOptions,
                       ArchiveGetCryptPasswordFunction archiveGetCryptPasswordFunction,
                       void                            *archiveGetCryptPasswordUserData
                      )
{
  byte              *archiveBuffer,*buffer;
  FragmentList      fragmentList;
  String            archiveFileName;
  Errors            failError;
  Errors            error;
  ArchiveInfo       archiveInfo;
  ArchiveFileInfo   archiveFileInfo;
  ArchiveEntryTypes archiveEntryType;
  FragmentNode      *fragmentNode;

  assert(archiveFileNameList != NULL);
  assert(includeEntryList != NULL);
  assert(excludePatternList != NULL);
  assert(jobOptions != NULL);

  /* allocate resources */
  archiveBuffer = (byte*)malloc(BUFFER_SIZE);
  if (archiveBuffer == NULL)
  {
    HALT_INSUFFICIENT_MEMORY();
  }
  buffer = malloc(BUFFER_SIZE);
  if (buffer == NULL)
  {
    free(archiveBuffer);
    HALT_INSUFFICIENT_MEMORY();
  }
  FragmentList_init(&fragmentList);
  archiveFileName = String_new();

  failError = ERROR_NONE;
  while (   !StringList_empty(archiveFileNameList)
         && (failError == ERROR_NONE)
        )
  {
    StringList_getFirst(archiveFileNameList,archiveFileName);
    printInfo(1,"Comparing archive '%s':\n",String_cString(archiveFileName));

    /* open archive */
    error = Archive_open(&archiveInfo,
                         archiveFileName,
                         jobOptions,
                         archiveGetCryptPasswordFunction,
                         archiveGetCryptPasswordUserData
                        );
    if (error != ERROR_NONE)
    {
      printError("Cannot open archive file '%s' (error: %s)!\n",
                 String_cString(archiveFileName),
                 Errors_getText(error)
                );
      if (failError == ERROR_NONE) failError = error;
      continue;
    }

    /* read files */
    while (   !Archive_eof(&archiveInfo)
           && (failError == ERROR_NONE)
          )
    {
      /* get next archive entry type */
      error = Archive_getNextArchiveEntryType(&archiveInfo,
                                              &archiveFileInfo,
                                              &archiveEntryType
                                             );
      if (error != ERROR_NONE)
      {
        printError("Cannot not read next entry in archive '%s' (error: %s)!\n",
                   String_cString(archiveFileName),
                   Errors_getText(error)
                  );
        if (failError == ERROR_NONE) failError = error;
        break;
      }

      switch (archiveEntryType)
      {
        case ARCHIVE_ENTRY_TYPE_FILE:
          {
            String       fileName;
            FileInfo     fileInfo;
            uint64       fragmentOffset,fragmentSize;
            FragmentNode *fragmentNode;
//            FileInfo   localFileInfo;
            FileHandle   fileHandle;
            bool         equalFlag;
            uint64       length;
            ulong        n;
            ulong        diffIndex;

            /* read file */
            fileName = String_new();
            error = Archive_readFileEntry(&archiveInfo,
                                          &archiveFileInfo,
                                          NULL,
                                          NULL,
                                          NULL,
                                          fileName,
                                          &fileInfo,
                                          &fragmentOffset,
                                          &fragmentSize
                                         );
            if (error != ERROR_NONE)
            {
              printError("Cannot not read 'file' content of archive '%s' (error: %s)!\n",
                         String_cString(archiveFileName),
                         Errors_getText(error)
                        );
              String_delete(fileName);
              if (failError == ERROR_NONE) failError = error;
              break;
            }

            if (   (List_empty(includeEntryList) || EntryList_match(includeEntryList,fileName,PATTERN_MATCH_MODE_EXACT))
                && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT)
               )
            {
              printInfo(2,"  Compare file '%s'...",String_cString(fileName));

              /* check file */
              if (!File_exists(fileName))
              {
                printInfo(2,"FAIL!\n");
                printError("File '%s' not found!\n",String_cString(fileName));
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILE_NOT_FOUND;
                }
                break;
              }
              if (File_getType(fileName) != FILE_TYPE_FILE)
              {
                printInfo(2,"FAIL!\n");
                printError("'%s' is not a file!\n",String_cString(fileName));
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_WRONG_FILE_TYPE;
                }
                break;
              }

              /* get file fragment list */
              fragmentNode = FragmentList_find(&fragmentList,fileName);
              if (fragmentNode == NULL)
              {
                fragmentNode = FragmentList_add(&fragmentList,fileName,fileInfo.size);
              }
//FragmentList_print(fragmentNode,String_cString(fileName));

              /* open file */
              error = File_open(&fileHandle,fileName,FILE_OPENMODE_READ);
              if (error != ERROR_NONE)
              {
                printInfo(2,"FAIL!\n");
                printError("Cannot open file '%s' (error: %s)\n",
                           String_cString(fileName),
                           Errors_getText(error)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = error;
                }
                continue;
              }

              /* check file size */
              if (fileInfo.size != File_getSize(&fileHandle))
              {
                printInfo(2,"FAIL!\n");
                printError("'%s' differ in size: expected %lld bytes, found %lld bytes\n",
                           String_cString(fileName),
                           fileInfo.size,
                           File_getSize(&fileHandle)
                          );
                File_close(&fileHandle);
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILES_DIFFER;
                }
                continue;
              }

              /* check file content */
              error = File_seek(&fileHandle,fragmentOffset);
              if (error != ERROR_NONE)
              {
                printInfo(2,"FAIL!\n");
                printError("Cannot read file '%s' (error: %s)\n",
                           String_cString(fileName),
                           Errors_getText(error)
                          );
                File_close(&fileHandle);
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = error;
                }
                continue;
              }
              length    = 0;
              equalFlag = TRUE;
              diffIndex = 0;
              while ((length < fragmentSize) && equalFlag)
              {
                n = MIN(fragmentSize-length,BUFFER_SIZE);

                /* read archive, file */
                error = Archive_readData(&archiveFileInfo,archiveBuffer,n);
                if (error != ERROR_NONE)
                {
                  printInfo(2,"FAIL!\n");
                  printError("Cannot not read content of archive '%s' (error: %s)!\n",
                             String_cString(archiveFileName),
                             Errors_getText(error)
                            );
                  if (failError == ERROR_NONE) failError = error;
                  break;
                }
                error = File_read(&fileHandle,buffer,n,NULL);
                if (error != ERROR_NONE)
                {
                  printInfo(2,"FAIL!\n");
                  printError("Cannot read file '%s' (error: %s)\n",
                             String_cString(fileName),
                             Errors_getText(error)
                            );
                  if (jobOptions->stopOnErrorFlag)
                  {
                    failError = error;
                  }
                  break;
                }

                /* compare */
                diffIndex = compare(archiveBuffer,buffer,n);
                equalFlag = (diffIndex >= n);
                if (!equalFlag)
                {
                  printInfo(2,"FAIL!\n");
                  printError("'%s' differ at offset %llu\n",
                             String_cString(fileName),
                             fragmentOffset+length+(uint64)diffIndex
                            );
                  if (jobOptions->stopOnErrorFlag)
                  {
                    failError = ERROR_FILES_DIFFER;
                  }
                  break;
                }

                length += n;
              }
              File_close(&fileHandle);
              if (failError != ERROR_NONE)
              {
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                continue;
              }

#if 0
              /* get local file info */
              /* check file time, permissions, file owner/group */
#endif /* 0 */
              printInfo(2,"ok\n");

              /* add fragment to file fragment list */
              FragmentList_addEntry(fragmentNode,fragmentOffset,fragmentSize);

              /* discard fragment list if file is complete */
              if (FragmentList_checkEntryComplete(fragmentNode))
              {
                FragmentList_remove(&fragmentList,fragmentNode);
              }

              /* free resources */
            }
            else
            {
              /* skip */
              printInfo(3,"  Compare '%s'...skipped\n",String_cString(fileName));
            }

            /* close archive file, free resources */
            Archive_closeEntry(&archiveFileInfo);
            String_delete(fileName);
          }
          break;
        case ARCHIVE_ENTRY_TYPE_IMAGE:
          {
            String       imageName;
            DeviceInfo   deviceInfo;
            uint64       blockOffset,blockCount;
            FragmentNode *fragmentNode;
            DeviceHandle deviceHandle;
            bool         equalFlag;
            uint64       block;
            ulong        bufferBlockCount;
            ulong        diffIndex;

            /* read image */
            imageName = String_new();
            error = Archive_readImageEntry(&archiveInfo,
                                           &archiveFileInfo,
                                           NULL,
                                           NULL,
                                           NULL,
                                           imageName,
                                           &deviceInfo,
                                           &blockOffset,
                                           &blockCount
                                          );
            if (error != ERROR_NONE)
            {
              printError("Cannot not read 'image' content of archive '%s' (error: %s)!\n",
                         String_cString(archiveFileName),
                         Errors_getText(error)
                        );
              String_delete(imageName);
              if (failError == ERROR_NONE) failError = error;
              break;
            }

            if (   (List_empty(includeEntryList) || EntryList_match(includeEntryList,imageName,PATTERN_MATCH_MODE_EXACT))
                && !PatternList_match(excludePatternList,imageName,PATTERN_MATCH_MODE_EXACT)
               )
            {
              printInfo(2,"  Compare image '%s'...",String_cString(imageName));

              /* check if device exists */
              if (!File_exists(imageName))
              {
                printInfo(2,"FAIL!\n");
                printError("Device '%s' not found!\n",String_cString(imageName));
                Archive_closeEntry(&archiveFileInfo);
                String_delete(imageName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILE_NOT_FOUND;
                }
                break;
              }

              /* get image fragment list */
              fragmentNode = FragmentList_find(&fragmentList,imageName);
              if (fragmentNode == NULL)
              {
                fragmentNode = FragmentList_add(&fragmentList,imageName,deviceInfo.size);
              }

              /* open device */
              error = Device_open(&deviceHandle,imageName,DEVICE_OPENMODE_READ);
              if (error != ERROR_NONE)
              {
                printInfo(2,"FAIL!\n");
                printError("Cannot open file '%s' (error: %s)\n",
                           String_cString(imageName),
                           Errors_getText(error)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(imageName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = error;
                }
                continue;
              }

              /* check image size */
              if (deviceInfo.size != Device_getSize(&deviceHandle))
              {
                printInfo(2,"FAIL!\n");
                printError("'%s' differ in size: expected %lld bytes, found %lld bytes\n",
                           String_cString(imageName),
                           deviceInfo.size,
                           Device_getSize(&deviceHandle)
                          );
                Device_close(&deviceHandle);
                Archive_closeEntry(&archiveFileInfo);
                String_delete(imageName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILES_DIFFER;
                }
                continue;
              }

              /* check image content */
              error = Device_seek(&deviceHandle,blockOffset*(uint64)deviceInfo.blockSize);
              if (error != ERROR_NONE)
              {
                printInfo(2,"FAIL!\n");
                printError("Cannot read file '%s' (error: %s)\n",
                           String_cString(imageName),
                           Errors_getText(error)
                          );
                Device_close(&deviceHandle);
                Archive_closeEntry(&archiveFileInfo);
                String_delete(imageName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = error;
                }
                continue;
              }
              block     = 0LL;
              equalFlag = TRUE;
              diffIndex = 0;
              while ((block < blockCount) && equalFlag)
              {
                assert(deviceInfo.blockSize > 0);
                bufferBlockCount = MIN(blockCount-block,BUFFER_SIZE/deviceInfo.blockSize);

                /* read archive, file */
                error = Archive_readData(&archiveFileInfo,archiveBuffer,bufferBlockCount*deviceInfo.blockSize);
                if (error != ERROR_NONE)
                {
                  printInfo(2,"FAIL!\n");
                  printError("Cannot not read content of archive '%s' (error: %s)!\n",
                             String_cString(archiveFileName),
                             Errors_getText(error)
                            );
                  if (failError == ERROR_NONE) failError = error;
                  break;
                }
                error = Device_read(&deviceHandle,buffer,bufferBlockCount*deviceInfo.blockSize,NULL);
                if (error != ERROR_NONE)
                {
                  printInfo(2,"FAIL!\n");
                  printError("Cannot read file '%s' (error: %s)\n",
                             String_cString(imageName),
                             Errors_getText(error)
                            );
                  if (jobOptions->stopOnErrorFlag)
                  {
                    failError = error;
                  }
                  break;
                }

                /* compare */
                diffIndex = compare(archiveBuffer,buffer,bufferBlockCount*deviceInfo.blockSize);
                equalFlag = (diffIndex >= bufferBlockCount*deviceInfo.blockSize);
                if (!equalFlag)
                {
                  printInfo(2,"FAIL!\n");
                  printError("'%s' differ at offset %llu\n",
                             String_cString(imageName),
                             blockOffset*(uint64)deviceInfo.blockSize+block*(uint64)deviceInfo.blockSize+(uint64)diffIndex
                            );
                  if (jobOptions->stopOnErrorFlag)
                  {
                    failError = ERROR_FILES_DIFFER;
                  }
                  break;
                }

                block += (uint64)bufferBlockCount;
              }
              Device_close(&deviceHandle);
              if (failError != ERROR_NONE)
              {
                Archive_closeEntry(&archiveFileInfo);
                String_delete(imageName);
                continue;
              }

#if 0
              /* get local file info */
              /* check file time, permissions, file owner/group */
#endif /* 0 */
              printInfo(2,"ok\n");

              /* add fragment to file fragment list */
              FragmentList_addEntry(fragmentNode,blockOffset*(uint64)deviceInfo.blockSize,blockCount*(uint64)deviceInfo.blockSize);

              /* discard fragment list if file is complete */
              if (FragmentList_checkEntryComplete(fragmentNode))
              {
                FragmentList_remove(&fragmentList,fragmentNode);
              }

              /* free resources */
            }
            else
            {
              /* skip */
              printInfo(3,"  Compare '%s'...skipped\n",String_cString(imageName));
            }

            /* close archive file, free resources */
            Archive_closeEntry(&archiveFileInfo);
            String_delete(imageName);
          }
          break;
        case ARCHIVE_ENTRY_TYPE_DIRECTORY:
          {
            String   directoryName;
            FileInfo fileInfo;
//            String   localFileName;
//            FileInfo localFileInfo;

            /* read directory */
            directoryName = String_new();
            error = Archive_readDirectoryEntry(&archiveInfo,
                                               &archiveFileInfo,
                                               NULL,
                                               NULL,
                                               directoryName,
                                               &fileInfo
                                              );
            if (error != ERROR_NONE)
            {
              printError("Cannot not read 'directory' content of archive '%s' (error: %s)!\n",
                         String_cString(archiveFileName),
                         Errors_getText(error)
                        );
              String_delete(directoryName);
              if (failError == ERROR_NONE) failError = error;
              break;
            }

            if (   (List_empty(includeEntryList) || EntryList_match(includeEntryList,directoryName,PATTERN_MATCH_MODE_EXACT))
                && !PatternList_match(excludePatternList,directoryName,PATTERN_MATCH_MODE_EXACT)
               )
            {
              printInfo(2,"  Compare directory '%s'...",String_cString(directoryName));

              /* check directory */
              if (!File_exists(directoryName))
              {
                printInfo(2,"FAIL!\n");
                printError("Directory '%s' does not exists!\n",String_cString(directoryName));
                Archive_closeEntry(&archiveFileInfo);
                String_delete(directoryName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILE_NOT_FOUND;
                }
                break;
              }
              if (File_getType(directoryName) != FILE_TYPE_DIRECTORY)
              {
                printInfo(2,"FAIL!\n");
                printError("'%s' is not a directory!\n",
                           String_cString(directoryName)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(directoryName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_WRONG_FILE_TYPE;
                }
                break;
              }

#if 0
              /* get local file info */
              error = File_getFileInfo(directoryName,&localFileInfo);
              if (error != ERROR_NONE)
              {
                printError("Cannot not read local directory '%s' (error: %s)!\n",
                           String_cString(directoryName),
                           Errors_getText(error)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(directoryName);
                if (failError == ERROR_NONE) failError = error;
                break;
              }

              /* check file time, permissions, file owner/group */
#endif /* 0 */
              printInfo(2,"ok\n");

              /* free resources */
            }
            else
            {
              /* skip */
              printInfo(3,"  Compare '%s'...skipped\n",String_cString(directoryName));
            }

            /* close archive file */
            Archive_closeEntry(&archiveFileInfo);
            String_delete(directoryName);
          }
          break;
        case ARCHIVE_ENTRY_TYPE_LINK:
          {
            String   linkName;
            String   fileName;
            FileInfo fileInfo;
            String   localFileName;
//            FileInfo localFileInfo;

            /* read link */
            linkName = String_new();
            fileName = String_new();
            error = Archive_readLinkEntry(&archiveInfo,
                                          &archiveFileInfo,
                                          NULL,
                                          NULL,
                                          linkName,
                                          fileName,
                                          &fileInfo
                                         );
            if (error != ERROR_NONE)
            {
              printError("Cannot not read 'link' content of archive '%s' (error: %s)!\n",
                         String_cString(archiveFileName),
                         Errors_getText(error)
                        );
              String_delete(fileName);
              String_delete(linkName);
              if (failError == ERROR_NONE) failError = error;
              break;
            }

            if (   (List_empty(includeEntryList) || EntryList_match(includeEntryList,linkName,PATTERN_MATCH_MODE_EXACT))
                && !PatternList_match(excludePatternList,linkName,PATTERN_MATCH_MODE_EXACT)
               )
            {
              printInfo(2,"  Compare link '%s'...",String_cString(linkName));

              /* check link */
              if (!File_exists(linkName))
              {
                printInfo(2,"FAIL!\n");
                printError("Link '%s' -> '%s' does not exists!\n",
                           String_cString(linkName),
                           String_cString(fileName)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                String_delete(linkName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILE_NOT_FOUND;
                }
                break;
              }
              if (File_getType(linkName) != FILE_TYPE_LINK)
              {
                printInfo(2,"FAIL!\n");
                printError("'%s' is not a link!\n",
                           String_cString(linkName)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                String_delete(linkName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_WRONG_FILE_TYPE;
                }
                break;
              }

              /* check link content */
              localFileName = String_new();
              error = File_readLink(linkName,localFileName);
              if (error != ERROR_NONE)
              {
                printError("Cannot not read local file '%s' (error: %s)!\n",
                           String_cString(linkName),
                           Errors_getText(error)
                          );
                String_delete(localFileName);
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                String_delete(linkName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = error;
                }
                break;
              }
              if (!String_equals(fileName,localFileName))
              {
                printInfo(2,"FAIL!\n");
                printError("Link '%s' does not contain file '%s'!\n",
                           String_cString(linkName),
                           String_cString(fileName)
                          );
                String_delete(localFileName);
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                String_delete(linkName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILES_DIFFER;
                }
                break;
              }
              String_delete(localFileName);

#if 0
              /* get local file info */
              error = File_getFileInfo(linkName,&localFileInfo);
              if (error != ERROR_NONE)
              {
                printError("Cannot not read local file '%s' (error: %s)!\n",
                           String_cString(linkName),
                           Errors_getText(error)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                String_delete(linkName);
                if (failError == ERROR_NONE) failError = error;
                break;
              }

              /* check file time, permissions, file owner/group */
#endif /* 0 */
              printInfo(2,"ok\n");

              /* free resources */
            }
            else
            {
              /* skip */
              printInfo(3,"  Compare '%s'...skipped\n",String_cString(linkName));
            }

            /* close archive file */
            Archive_closeEntry(&archiveFileInfo);
            String_delete(fileName);
            String_delete(linkName);
          }
          break;
        case ARCHIVE_ENTRY_TYPE_SPECIAL:
          {
            String   fileName;
            FileInfo fileInfo;
            FileInfo localFileInfo;

            /* read special */
            fileName = String_new();
            error = Archive_readSpecialEntry(&archiveInfo,
                                             &archiveFileInfo,
                                             NULL,
                                             NULL,
                                             fileName,
                                             &fileInfo
                                            );
            if (error != ERROR_NONE)
            {
              printError("Cannot not read 'special' content of archive '%s' (error: %s)!\n",
                         String_cString(archiveFileName),
                         Errors_getText(error)
                        );
              String_delete(fileName);
              if (failError == ERROR_NONE) failError = error;
              break;
            }

            if (   (List_empty(includeEntryList) || EntryList_match(includeEntryList,fileName,PATTERN_MATCH_MODE_EXACT))
                && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT)
               )
            {
              printInfo(2,"  Compare special device '%s'...",String_cString(fileName));

              /* check special device */
              if (!File_exists(fileName))
              {
                printInfo(2,"FAIL!\n");
                printError("Special device '%s' does not exists!\n",
                           String_cString(fileName)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_FILE_NOT_FOUND;
                }
                break;
              }
              if (File_getType(fileName) != FILE_TYPE_SPECIAL)
              {
                printInfo(2,"FAIL!\n");
                printError("'%s' is not a special device!\n",
                           String_cString(fileName)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = ERROR_WRONG_FILE_TYPE;
                }
                break;
              }

              /* check special settings */
              error = File_getFileInfo(fileName,&localFileInfo);
              if (error != ERROR_NONE)
              {
                printError("Cannot not read local file '%s' (error: %s)!\n",
                           String_cString(fileName),
                           Errors_getText(error)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = error;
                }
                break;
              }
              if (fileInfo.specialType != localFileInfo.specialType)
              {
                printError("Different types of special device '%s'!\n",
                           String_cString(fileName)
                          );
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                if (jobOptions->stopOnErrorFlag)
                {
                  failError = error;
                }
                break;
              }
              if (   (fileInfo.specialType == FILE_SPECIAL_TYPE_CHARACTER_DEVICE)
                  || (fileInfo.specialType == FILE_SPECIAL_TYPE_BLOCK_DEVICE)
                 )
              {
                if (fileInfo.major != localFileInfo.major)
                {
                  printError("Different major numbers of special device '%s'!\n",
                             String_cString(fileName)
                            );
                  Archive_closeEntry(&archiveFileInfo);
                  String_delete(fileName);
                  if (jobOptions->stopOnErrorFlag)
                  {
                    failError = error;
                  }
                  break;
                }
                if (fileInfo.minor != localFileInfo.minor)
                {
                  printError("Different minor numbers of special device '%s'!\n",
                             String_cString(fileName)
                            );
                  Archive_closeEntry(&archiveFileInfo);
                  String_delete(fileName);
                  if (jobOptions->stopOnErrorFlag)
                  {
                    failError = error;
                  }
                  break;
                }
              }

#if 0

              /* check file time, permissions, file owner/group */
#endif /* 0 */

              printInfo(2,"ok\n");

              /* free resources */
            }
            else
            {
              /* skip */
              printInfo(3,"  Compare '%s'...skipped\n",String_cString(fileName));
            }

            /* close archive file */
            Archive_closeEntry(&archiveFileInfo);
            String_delete(fileName);
          }
          break;
        default:
          #ifndef NDEBUG
            HALT_INTERNAL_ERROR_UNHANDLED_SWITCH_CASE();
          #endif /* NDEBUG */
          break; /* not reached */
      }
    }

    /* close archive */
    Archive_close(&archiveInfo);
  }

  /* check fragment lists */
  for (fragmentNode = fragmentList.head; fragmentNode != NULL; fragmentNode = fragmentNode->next)
  {
    if (!FragmentList_checkEntryComplete(fragmentNode))
    {
      printInfo(0,"Warning: incomplete entry '%s'\n",String_cString(fragmentNode->name));
      if (failError == ERROR_NONE) failError = ERROR_FILE_INCOMPLETE;
    }
  }

  /* free resources */
  String_delete(archiveFileName);
  FragmentList_done(&fragmentList);
  free(buffer);
  free(archiveBuffer);

  return failError;
}
Exemplo n.º 10
0
Void ListTest(Void)
{
    List_Params listParams;
    List_Handle listHandle;
    List_Elem *elem;
    ListNode *node;
    UInt32 i, value;
    Bool failed = FALSE;

    IGateProvider_Handle gateHandle;

    List_Params_init(&listParams);

    gateHandle = (IGateProvider_Handle) GateMutex_create();
    if(gateHandle == NULL) {
        Osal_printf("ListTest: GateMutex_create failed.\n");
        goto exit;
    }

    listParams.gateHandle = gateHandle;
    listHandle = List_create(&listParams);
    if(listHandle == NULL) {
        Osal_printf("ListTest: List_create failed.\n");
        goto gateExit;
    }

    node = Memory_alloc(NULL, LIST_SIZE * sizeof(ListNode), 0);
    if(node == NULL) {
        Osal_printf("ListTest: Memory_alloc failed.\n");
        goto listExit;
    }

    // Put some nodes into the list
    for(i = 0; i < LIST_SIZE; i++) {
        node[i].value = i;
        List_put(listHandle, (List_Elem *)&node[i]);
    }

    // Traverse the list
    for(i = 0, elem = List_next(listHandle, NULL);
        elem != NULL && !failed;
        i++, elem = List_next(listHandle, elem)) {
        value = ((ListNode *)elem)->value;

        // Check against expected value
        if(value != i) {
            Osal_printf("ListTest: data mismatch, expected "
                "0x%x, actual 0x%x\n", i, i, value);
            failed = TRUE;
        }
    }

    // Remove nodes
    for(i = 0; i < LIST_SIZE && !List_empty(listHandle); i++) {
        // Get first element and put it back to test List_get and List_putHead
        elem = List_get(listHandle);
        List_putHead(listHandle, elem);

        // Now remove it permanently to test List_remove
        if(elem != NULL) {
            List_remove(listHandle, elem);
        }
    }
    // Did we remove the expected number of nodes?
    if(i != LIST_SIZE)
    {
        Osal_printf("ListTest: removed %d node(s), expected %d\n",
            i, LIST_SIZE);
        failed = TRUE;
    }

    if(!List_empty(listHandle))
    {
        Osal_printf("ListTest: list not empty!\n");
        failed = TRUE;
    }

    if(failed)
        Osal_printf("ListTest: FAILED!\n");
    else
        Osal_printf("ListTest: PASSED!\n");

listExit:
    List_delete(&listHandle);
gateExit:
    GateMutex_delete((GateMutex_Handle *)&gateHandle);
exit:
    return;
}
Exemplo n.º 11
0
Errors Command_restore(StringList                      *archiveFileNameList,
                       PatternList                     *includePatternList,
                       PatternList                     *excludePatternList,
                       JobOptions                      *jobOptions,
                       ArchiveGetCryptPasswordFunction archiveGetCryptPasswordFunction,
                       void                            *archiveGetCryptPasswordUserData,
                       RestoreStatusInfoFunction       restoreStatusInfoFunction,
                       void                            *restoreStatusInfoUserData,
                       bool                            *pauseFlag,
                       bool                            *requestedAbortFlag
                      )
{
    RestoreInfo       restoreInfo;
    byte              *buffer;
    FileFragmentList  fileFragmentList;
    String            archiveFileName;
    Errors            error;
    ArchiveInfo       archiveInfo;
    ArchiveFileInfo   archiveFileInfo;
    FileTypes         fileType;
    FileFragmentNode  *fileFragmentNode;

    assert(archiveFileNameList != NULL);
    assert(includePatternList != NULL);
    assert(excludePatternList != NULL);
    assert(jobOptions != NULL);

    /* initialize variables */
    restoreInfo.includePatternList           = includePatternList;
    restoreInfo.excludePatternList           = excludePatternList;
    restoreInfo.jobOptions                   = jobOptions;
    restoreInfo.pauseFlag                    = pauseFlag;
    restoreInfo.requestedAbortFlag           = requestedAbortFlag;
    restoreInfo.error                        = ERROR_NONE;
    restoreInfo.statusInfoFunction           = restoreStatusInfoFunction;
    restoreInfo.statusInfoUserData           = restoreStatusInfoUserData;
    restoreInfo.statusInfo.doneFiles         = 0L;
    restoreInfo.statusInfo.doneBytes         = 0LL;
    restoreInfo.statusInfo.skippedFiles      = 0L;
    restoreInfo.statusInfo.skippedBytes      = 0LL;
    restoreInfo.statusInfo.errorFiles        = 0L;
    restoreInfo.statusInfo.errorBytes        = 0LL;
    restoreInfo.statusInfo.fileName          = String_new();
    restoreInfo.statusInfo.fileDoneBytes     = 0LL;
    restoreInfo.statusInfo.fileTotalBytes    = 0LL;
    restoreInfo.statusInfo.storageName       = String_new();
    restoreInfo.statusInfo.storageDoneBytes  = 0LL;
    restoreInfo.statusInfo.storageTotalBytes = 0LL;

    /* allocate resources */
    buffer = malloc(BUFFER_SIZE);
    if (buffer == NULL)
    {
        HALT_INSUFFICIENT_MEMORY();
    }
    FileFragmentList_init(&fileFragmentList);
    archiveFileName = String_new();

    while (   ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag))
              && !StringList_empty(archiveFileNameList)
              && (restoreInfo.error == ERROR_NONE)
          )
    {
        /* pause */
        while ((restoreInfo.pauseFlag != NULL) && (*restoreInfo.pauseFlag))
        {
            Misc_udelay(500*1000);
        }

        StringList_getFirst(archiveFileNameList,archiveFileName);
        printInfo(0,"Restore archive '%s':\n",String_cString(archiveFileName));

        /* open archive */
        error = Archive_open(&archiveInfo,
                             archiveFileName,
                             jobOptions,
                             archiveGetCryptPasswordFunction,
                             archiveGetCryptPasswordUserData
                            );
        if (error != ERROR_NONE)
        {
            printError("Cannot open archive file '%s' (error: %s)!\n",
                       String_cString(archiveFileName),
                       Errors_getText(error)
                      );
            if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
            continue;
        }
        String_set(restoreInfo.statusInfo.storageName,archiveFileName);
        updateStatusInfo(&restoreInfo);

        /* read files */
        while (   ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag))
                  && !Archive_eof(&archiveInfo)
                  && (restoreInfo.error == ERROR_NONE)
              )
        {
            /* pause */
            while ((restoreInfo.pauseFlag != NULL) && (*restoreInfo.pauseFlag))
            {
                Misc_udelay(500*1000);
            }

            /* get next file type */
            error = Archive_getNextFileType(&archiveInfo,
                                            &archiveFileInfo,
                                            &fileType
                                           );
            if (error != ERROR_NONE)
            {
                printError("Cannot not read next entry in archive '%s' (error: %s)!\n",
                           String_cString(archiveFileName),
                           Errors_getText(error)
                          );
                if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                break;
            }

            switch (fileType)
            {
            case FILE_TYPE_FILE:
            {
                String           fileName;
                FileInfo         fileInfo;
                uint64           fragmentOffset,fragmentSize;
                FileFragmentNode *fileFragmentNode;
                String           destinationFileName;
                String           directoryName;
//            FileInfo         localFileInfo;
                FileHandle       fileHandle;
                uint64           length;
                ulong            n;

                /* read file */
                fileName = String_new();
                error = Archive_readFileEntry(&archiveInfo,
                                              &archiveFileInfo,
                                              NULL,
                                              NULL,
                                              NULL,
                                              fileName,
                                              &fileInfo,
                                              &fragmentOffset,
                                              &fragmentSize
                                             );
                if (error != ERROR_NONE)
                {
                    printError("Cannot not read 'file' content of archive '%s' (error: %s)!\n",
                               String_cString(archiveFileName),
                               Errors_getText(error)
                              );
                    String_delete(fileName);
                    if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                    continue;
                }

                if (   (List_empty(includePatternList) || PatternList_match(includePatternList,fileName,PATTERN_MATCH_MODE_EXACT))
                        && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT)
                   )
                {
                    String_set(restoreInfo.statusInfo.fileName,fileName);
                    restoreInfo.statusInfo.fileDoneBytes = 0LL;
                    restoreInfo.statusInfo.fileTotalBytes = fragmentSize;
                    updateStatusInfo(&restoreInfo);

                    /* get destination filename */
                    destinationFileName = getDestinationFileName(String_new(),
                                          fileName,
                                          jobOptions->directory,
                                          jobOptions->directoryStripCount
                                                                );


                    /* check if file fragment exists */
                    fileFragmentNode = FileFragmentList_findFile(&fileFragmentList,fileName);
                    if (fileFragmentNode != NULL)
                    {
                        if (!jobOptions->overwriteFilesFlag && FileFragmentList_checkExists(fileFragmentNode,fragmentOffset,fragmentSize))
                        {
                            printInfo(1,"  Restore file '%s'...skipped (file part %ll..%ll exists)\n",
                                      String_cString(destinationFileName),
                                      fragmentOffset,
                                      (fragmentSize > 0)?fragmentOffset+fragmentSize-1:fragmentOffset
                                     );
                            String_delete(destinationFileName);
                            Archive_closeEntry(&archiveFileInfo);
                            String_delete(fileName);
                            continue;
                        }
                    }
                    else
                    {
                        if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName))
                        {
                            printInfo(1,"  Restore file '%s'...skipped (file exists)\n",String_cString(destinationFileName));
                            String_delete(destinationFileName);
                            Archive_closeEntry(&archiveFileInfo);
                            String_delete(fileName);
                            continue;
                        }
                        fileFragmentNode = FileFragmentList_addFile(&fileFragmentList,fileName,fileInfo.size);
                    }

                    printInfo(2,"  Restore file '%s'...",String_cString(destinationFileName));

                    /* create directory if not existing */
                    directoryName = File_getFilePathName(String_new(),destinationFileName);
                    if (!File_exists(directoryName))
                    {
                        /* create directory */
                        error = File_makeDirectory(directoryName,
                                                   FILE_DEFAULT_USER_ID,
                                                   FILE_DEFAULT_GROUP_ID,
                                                   fileInfo.permission
                                                  );
                        if (error != ERROR_NONE)
                        {
                            printInfo(2,"FAIL!\n");
                            printError("Cannot create directory '%s' (error: %s)\n",
                                       String_cString(directoryName),
                                       Errors_getText(error)
                                      );
                            String_delete(directoryName);
                            String_delete(destinationFileName);
                            Archive_closeEntry(&archiveFileInfo);
                            String_delete(fileName);
                            if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                            continue;
                        }

                        /* set owner ship */
                        error = File_setOwner(directoryName,
                                              (jobOptions->owner.userId  != FILE_DEFAULT_USER_ID )?jobOptions->owner.userId:fileInfo.userId,
                                              (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID)?jobOptions->owner.groupId:fileInfo.groupId
                                             );
                        if (error != ERROR_NONE)
                        {
                            if (jobOptions->stopOnErrorFlag)
                            {
                                printInfo(2,"FAIL!\n");
                                printError("Cannot set owner ship of directory '%s' (error: %s)\n",
                                           String_cString(directoryName),
                                           Errors_getText(error)
                                          );
                                String_delete(directoryName);
                                String_delete(destinationFileName);
                                Archive_closeEntry(&archiveFileInfo);
                                String_delete(fileName);
                                if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                                continue;
                            }
                            else
                            {
                                printWarning("Cannot set owner ship of directory '%s' (error: %s)\n",
                                             String_cString(directoryName),
                                             Errors_getText(error)
                                            );
                            }
                        }
                    }
                    String_delete(directoryName);

                    /* write file data */
//if (fileFragmentNode == NULL) File_delete(destinationFileName,TRUE);
                    error = File_open(&fileHandle,destinationFileName,FILE_OPENMODE_WRITE);
                    if (error != ERROR_NONE)
                    {
                        printInfo(2,"FAIL!\n");
                        printError("Cannot create/write to file '%s' (error: %s)\n",
                                   String_cString(destinationFileName),
                                   Errors_getText(error)
                                  );
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        if (jobOptions->stopOnErrorFlag)
                        {
                            restoreInfo.error = error;
                        }
                        continue;
                    }
                    error = File_seek(&fileHandle,fragmentOffset);
                    if (error != ERROR_NONE)
                    {
                        printInfo(2,"FAIL!\n");
                        printError("Cannot write file '%s' (error: %s)\n",
                                   String_cString(destinationFileName),
                                   Errors_getText(error)
                                  );
                        File_close(&fileHandle);
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        if (jobOptions->stopOnErrorFlag)
                        {
                            restoreInfo.error = error;
                        }
                        continue;
                    }

                    length = 0;
                    while (   ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag))
                              && (length < fragmentSize)
                          )
                    {
                        /* pause */
                        while ((restoreInfo.pauseFlag != NULL) && (*restoreInfo.pauseFlag))
                        {
                            Misc_udelay(500*1000);
                        }

                        n = MIN(fragmentSize-length,BUFFER_SIZE);

                        error = Archive_readFileData(&archiveFileInfo,buffer,n);
                        if (error != ERROR_NONE)
                        {
                            printInfo(2,"FAIL!\n");
                            printError("Cannot not read content of archive '%s' (error: %s)!\n",
                                       String_cString(archiveFileName),
                                       Errors_getText(error)
                                      );
                            if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                            break;
                        }
                        error = File_write(&fileHandle,buffer,n);
                        if (error != ERROR_NONE)
                        {
                            printInfo(2,"FAIL!\n");
                            printError("Cannot write file '%s' (error: %s)\n",
                                       String_cString(destinationFileName),
                                       Errors_getText(error)
                                      );
                            if (jobOptions->stopOnErrorFlag)
                            {
                                restoreInfo.error = error;
                            }
                            break;
                        }
                        restoreInfo.statusInfo.fileDoneBytes += n;
                        updateStatusInfo(&restoreInfo);

                        length += n;
                    }
                    if (File_getSize(&fileHandle) > fileInfo.size)
                    {
                        File_truncate(&fileHandle,fileInfo.size);
                    }
                    File_close(&fileHandle);
                    if ((restoreInfo.requestedAbortFlag != NULL) && (*restoreInfo.requestedAbortFlag))
                    {
                        printInfo(2,"ABORTED\n");
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        continue;
                    }
#if 0
                    if (restoreInfo.error != ERROR_NONE)
                    {
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        continue;
                    }
#endif /* 0 */

                    /* set file time, file owner/group */
                    if (jobOptions->owner.userId  != FILE_DEFAULT_USER_ID ) fileInfo.userId  = jobOptions->owner.userId;
                    if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId;
                    error = File_setFileInfo(destinationFileName,&fileInfo);
                    if (error != ERROR_NONE)
                    {
                        if (jobOptions->stopOnErrorFlag)
                        {
                            printInfo(2,"FAIL!\n");
                            printError("Cannot set file info of '%s' (error: %s)\n",
                                       String_cString(destinationFileName),
                                       Errors_getText(error)
                                      );
                            String_delete(destinationFileName);
                            Archive_closeEntry(&archiveFileInfo);
                            String_delete(fileName);
                            restoreInfo.error = error;
                            continue;
                        }
                        else
                        {
                            printWarning("Cannot set file info of '%s' (error: %s)\n",
                                         String_cString(destinationFileName),
                                         Errors_getText(error)
                                        );
                        }
                    }

                    /* add fragment to file fragment list */
                    FileFragmentList_add(fileFragmentNode,fragmentOffset,fragmentSize);
//FileFragmentList_print(fileFragmentNode,String_cString(fileName));

                    /* discard fragment list if file is complete */
                    if (FileFragmentList_checkComplete(fileFragmentNode))
                    {
                        FileFragmentList_removeFile(&fileFragmentList,fileFragmentNode);
                    }

                    /* free resources */
                    String_delete(destinationFileName);

                    printInfo(2,"ok\n");
                }
                else
                {
                    /* skip */
                    printInfo(3,"  Restore '%s'...skipped\n",String_cString(fileName));
                }

                /* close archive file, free resources */
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
            }
            break;
            case FILE_TYPE_DIRECTORY:
            {
                String   directoryName;
                FileInfo fileInfo;
                String   destinationFileName;
//            FileInfo localFileInfo;

                /* read directory */
                directoryName = String_new();
                error = Archive_readDirectoryEntry(&archiveInfo,
                                                   &archiveFileInfo,
                                                   NULL,
                                                   NULL,
                                                   directoryName,
                                                   &fileInfo
                                                  );
                if (error != ERROR_NONE)
                {
                    printError("Cannot not read 'directory' content of archive '%s' (error: %s)!\n",
                               String_cString(archiveFileName),
                               Errors_getText(error)
                              );
                    String_delete(directoryName);
                    if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                    break;
                }

                if (   (List_empty(includePatternList) || PatternList_match(includePatternList,directoryName,PATTERN_MATCH_MODE_EXACT))
                        && !PatternList_match(excludePatternList,directoryName,PATTERN_MATCH_MODE_EXACT)
                   )
                {
                    String_set(restoreInfo.statusInfo.fileName,directoryName);
                    restoreInfo.statusInfo.fileDoneBytes = 0LL;
                    restoreInfo.statusInfo.fileTotalBytes = 00L;
                    updateStatusInfo(&restoreInfo);

                    /* get destination filename */
                    destinationFileName = getDestinationFileName(String_new(),
                                          directoryName,
                                          jobOptions->directory,
                                          jobOptions->directoryStripCount
                                                                );


                    /* check if directory already exists */
                    if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName))
                    {
                        printInfo(1,
                                  "  Restore directory '%s'...skipped (file exists)\n",
                                  String_cString(destinationFileName)
                                 );
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(directoryName);
                        continue;
                    }

                    printInfo(2,"  Restore directory '%s'...",String_cString(destinationFileName));

                    /* create directory */
                    error = File_makeDirectory(destinationFileName,
                                               FILE_DEFAULT_USER_ID,
                                               FILE_DEFAULT_GROUP_ID,
                                               fileInfo.permission
                                              );
                    if (error != ERROR_NONE)
                    {
                        printInfo(2,"FAIL!\n");
                        printError("Cannot create directory '%s' (error: %s)\n",
                                   String_cString(destinationFileName),
                                   Errors_getText(error)
                                  );
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(directoryName);
                        if (jobOptions->stopOnErrorFlag)
                        {
                            restoreInfo.error = error;
                        }
                        continue;
                    }

                    /* set file time, file owner/group */
                    if (jobOptions->owner.userId  != FILE_DEFAULT_USER_ID ) fileInfo.userId  = jobOptions->owner.userId;
                    if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId;
                    error = File_setFileInfo(destinationFileName,&fileInfo);
                    if (error != ERROR_NONE)
                    {
                        if (jobOptions->stopOnErrorFlag)
                        {
                            printInfo(2,"FAIL!\n");
                            printError("Cannot set directory info of '%s' (error: %s)\n",
                                       String_cString(destinationFileName),
                                       Errors_getText(error)
                                      );
                            String_delete(destinationFileName);
                            Archive_closeEntry(&archiveFileInfo);
                            String_delete(directoryName);
                            if (jobOptions->stopOnErrorFlag)
                            {
                                restoreInfo.error = error;
                            }
                            continue;
                        }
                        else
                        {
                            printWarning("Cannot set directory info of '%s' (error: %s)\n",
                                         String_cString(destinationFileName),
                                         Errors_getText(error)
                                        );
                        }
                    }

                    /* free resources */
                    String_delete(destinationFileName);

                    printInfo(2,"ok\n");
                }
                else
                {
                    /* skip */
                    printInfo(3,"  Restore '%s'...skipped\n",String_cString(directoryName));
                }

                /* close archive file */
                Archive_closeEntry(&archiveFileInfo);
                String_delete(directoryName);
            }
            break;
            case FILE_TYPE_LINK:
            {
                String   linkName;
                String   fileName;
                FileInfo fileInfo;
                String   destinationFileName;
//            FileInfo localFileInfo;

                /* read link */
                linkName = String_new();
                fileName = String_new();
                error = Archive_readLinkEntry(&archiveInfo,
                                              &archiveFileInfo,
                                              NULL,
                                              NULL,
                                              linkName,
                                              fileName,
                                              &fileInfo
                                             );
                if (error != ERROR_NONE)
                {
                    printError("Cannot not read 'link' content of archive '%s' (error: %s)!\n",
                               String_cString(archiveFileName),
                               Errors_getText(error)
                              );
                    String_delete(fileName);
                    String_delete(linkName);
                    if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                    break;
                }

                if (   (List_empty(includePatternList) || PatternList_match(includePatternList,linkName,PATTERN_MATCH_MODE_EXACT))
                        && !PatternList_match(excludePatternList,linkName,PATTERN_MATCH_MODE_EXACT)
                   )
                {
                    String_set(restoreInfo.statusInfo.fileName,linkName);
                    restoreInfo.statusInfo.fileDoneBytes = 0LL;
                    restoreInfo.statusInfo.fileTotalBytes = 00L;
                    updateStatusInfo(&restoreInfo);

                    /* get destination filename */
                    destinationFileName = getDestinationFileName(String_new(),
                                          linkName,
                                          jobOptions->directory,
                                          jobOptions->directoryStripCount
                                                                );


                    /* create link */
                    if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName))
                    {
                        printInfo(1,
                                  "  Restore link '%s'...skipped (file exists)\n",
                                  String_cString(destinationFileName)
                                 );
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        String_delete(linkName);
                        if (jobOptions->stopOnErrorFlag)
                        {
                            restoreInfo.error = ERROR_FILE_EXITS;
                        }
                        continue;
                    }

                    printInfo(2,"  Restore link '%s'...",String_cString(destinationFileName));

                    error = File_makeLink(destinationFileName,fileName);
                    if (error != ERROR_NONE)
                    {
                        printInfo(2,"FAIL!\n");
                        printError("Cannot create link '%s' -> '%s' (error: %s)\n",
                                   String_cString(destinationFileName),
                                   String_cString(fileName),
                                   Errors_getText(error)
                                  );
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        String_delete(linkName);
                        if (jobOptions->stopOnErrorFlag)
                        {
                            restoreInfo.error = error;
                        }
                        continue;
                    }

                    /* set file time, file owner/group */
                    if (jobOptions->owner.userId  != FILE_DEFAULT_USER_ID ) fileInfo.userId  = jobOptions->owner.userId;
                    if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId;
                    error = File_setFileInfo(destinationFileName,&fileInfo);
                    if (error != ERROR_NONE)
                    {
                        if (jobOptions->stopOnErrorFlag)
                        {
                            printInfo(2,"FAIL!\n");
                            printError("Cannot set file info of '%s' (error: %s)\n",
                                       String_cString(destinationFileName),
                                       Errors_getText(error)
                                      );
                            String_delete(destinationFileName);
                            Archive_closeEntry(&archiveFileInfo);
                            String_delete(fileName);
                            String_delete(linkName);
                            if (jobOptions->stopOnErrorFlag)
                            {
                                restoreInfo.error = error;
                            }
                            continue;
                        }
                        else
                        {
                            printWarning("Cannot set file info of '%s' (error: %s)\n",
                                         String_cString(destinationFileName),
                                         Errors_getText(error)
                                        );
                        }
                    }

                    /* free resources */
                    String_delete(destinationFileName);

                    printInfo(2,"ok\n");
                }
                else
                {
                    /* skip */
                    printInfo(3,"  Restore '%s'...skipped\n",String_cString(linkName));
                }

                /* close archive file */
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
                String_delete(linkName);
            }
            break;
            case FILE_TYPE_SPECIAL:
            {
                String   fileName;
                FileInfo fileInfo;
                String   destinationFileName;
//            FileInfo localFileInfo;

                /* read special device */
                fileName = String_new();
                error = Archive_readSpecialEntry(&archiveInfo,
                                                 &archiveFileInfo,
                                                 NULL,
                                                 NULL,
                                                 fileName,
                                                 &fileInfo
                                                );
                if (error != ERROR_NONE)
                {
                    printError("Cannot not read 'special' content of archive '%s' (error: %s)!\n",
                               String_cString(archiveFileName),
                               Errors_getText(error)
                              );
                    String_delete(fileName);
                    if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error;
                    break;
                }

                if (   (List_empty(includePatternList) || PatternList_match(includePatternList,fileName,PATTERN_MATCH_MODE_EXACT))
                        && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT)
                   )
                {
                    String_set(restoreInfo.statusInfo.fileName,fileName);
                    restoreInfo.statusInfo.fileDoneBytes = 0LL;
                    restoreInfo.statusInfo.fileTotalBytes = 00L;
                    updateStatusInfo(&restoreInfo);

                    /* get destination filename */
                    destinationFileName = getDestinationFileName(String_new(),
                                          fileName,
                                          jobOptions->directory,
                                          jobOptions->directoryStripCount
                                                                );


                    /* create special device */
                    if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName))
                    {
                        printInfo(1,
                                  "  Restore special device '%s'...skipped (file exists)\n",
                                  String_cString(destinationFileName)
                                 );
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        if (jobOptions->stopOnErrorFlag)
                        {
                            restoreInfo.error = ERROR_FILE_EXITS;
                        }
                        continue;
                    }

                    printInfo(2,"  Restore special device '%s'...",String_cString(destinationFileName));

                    error = File_makeSpecial(destinationFileName,
                                             fileInfo.specialType,
                                             fileInfo.major,
                                             fileInfo.minor
                                            );
                    if (error != ERROR_NONE)
                    {
                        printInfo(2,"FAIL!\n");
                        printError("Cannot create special device '%s' (error: %s)\n",
                                   String_cString(fileName),
                                   Errors_getText(error)
                                  );
                        String_delete(destinationFileName);
                        Archive_closeEntry(&archiveFileInfo);
                        String_delete(fileName);
                        if (jobOptions->stopOnErrorFlag)
                        {
                            restoreInfo.error = error;
                        }
                        continue;
                    }

                    /* set file time, file owner/group */
                    if (jobOptions->owner.userId  != FILE_DEFAULT_USER_ID ) fileInfo.userId  = jobOptions->owner.userId;
                    if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId;
                    error = File_setFileInfo(destinationFileName,&fileInfo);
                    if (error != ERROR_NONE)
                    {
                        if (jobOptions->stopOnErrorFlag)
                        {
                            printInfo(2,"FAIL!\n");
                            printError("Cannot set file info of '%s' (error: %s)\n",
                                       String_cString(destinationFileName),
                                       Errors_getText(error)
                                      );
                            String_delete(destinationFileName);
                            Archive_closeEntry(&archiveFileInfo);
                            String_delete(fileName);
                            if (jobOptions->stopOnErrorFlag)
                            {
                                restoreInfo.error = error;
                            }
                            continue;
                        }
                        else
                        {
                            printWarning("Cannot set file info of '%s' (error: %s)\n",
                                         String_cString(destinationFileName),
                                         Errors_getText(error)
                                        );
                        }
                    }

                    /* free resources */
                    String_delete(destinationFileName);

                    printInfo(2,"ok\n");
                }
                else
                {
                    /* skip */
                    printInfo(3,"  Restore '%s'...skipped\n",String_cString(fileName));
                }

                /* close archive file */
                Archive_closeEntry(&archiveFileInfo);
                String_delete(fileName);
            }
            break;
            default:
#ifndef NDEBUG
                HALT_INTERNAL_ERROR_UNHANDLED_SWITCH_CASE();
#endif /* NDEBUG */
                break; /* not reached */
            }
        }

        /* close archive */
        Archive_close(&archiveInfo);
    }

    /* check fragment lists */
    if ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag))
    {
        for (fileFragmentNode = fileFragmentList.head; fileFragmentNode != NULL; fileFragmentNode = fileFragmentNode->next)
        {
            if (!FileFragmentList_checkComplete(fileFragmentNode))
            {
                printInfo(0,"Warning: incomplete file '%s'\n",String_cString(fileFragmentNode->fileName));
                if (restoreInfo.error == ERROR_NONE) restoreInfo.error = ERROR_FILE_INCOMPLETE;
            }
        }
    }

    /* free resources */
    String_delete(archiveFileName);
    FileFragmentList_done(&fileFragmentList);
    free(buffer);
    String_delete(restoreInfo.statusInfo.fileName);
    String_delete(restoreInfo.statusInfo.storageName);

    if ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag))
    {
        return restoreInfo.error;
    }
    else
    {
        return ERROR_ABORTED;
    }
}