Esempio n. 1
0
//  Return non-NULL if success, NULL if object does not exist
struct ZSTLMapEntry *ZSTLMapUpdate(struct ZSTLMap *pm, char *pkey, uint32_t keylen, char *pdata, uint64_t datalen)
{
    ZSTLMapEntry_t   *pme;

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapUpdate: pm=%p, key=0x%lx, keylen=%d, pdata=%p, datalen=%ld\n", pm, *((uint64_t *) pkey), keylen, pdata, datalen);
    #endif

    pme = find_pme(pm, pkey, keylen, NULL);

    if (pme == NULL) {
	do_unlock(&(pm->mutex));
        return(NULL);
    }

    /* Update an existing entry. */

    // update the LRU list if necessary
    if (pm->max_entries != 0) {
	update_lru(pm, pme);
    }

    if (pm->replacement_callback) {
        //  return NULL for key so that it is not freed!
	(pm->replacement_callback)(pm->replacement_callback_data, pme->key, pme->keylen, pme->contents, pme->datalen);
    }

    pme->contents = pdata;
    pme->datalen  = datalen;

    do_unlock(&(pm->mutex));
    return(pme);
}
Esempio n. 2
0
//  Returns 1 if successful, 0 otherwise
//  Caller is responsible for freeing key and data
int ZSTLMapNextEnum(struct ZSTLMap *pm, struct ZSTLIterator *iterator, char **key, uint32_t *keylen, char **data, uint64_t *datalen) 
{
    ZSTLMapEntry_t    *pme_return;

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapNextEnum: pm=%p, iterator=%p, ", pm, iterator);
    #endif

    if (iterator->enum_entry == NULL) {
	do_unlock(&(pm->mutex));
	ZSTLFinishEnum(pm, iterator);

	#ifdef SANDISK_PRINTSTUFF
	    fprintf(stderr, "pdata=NULL, datalen=0\n");
	#endif

        *key     = NULL;
	*keylen  = 0;
        *data    = NULL;
	*datalen = 0;
        return(0);
    }
    pme_return = iterator->enum_entry;

    iterator->enum_entry = pme_return->next_lru;

    if (pme_return != NULL) {
	*key     = pme_return->key;
	*keylen  = pme_return->keylen;

	*data    = (char *) pme_return->contents;
	*datalen = pme_return->datalen;

	#ifdef SANDISK_PRINTSTUFF
	    fprintf(stderr, "key=%p, keylen=%d, pdata=%p, datalen=%ld, pme_return=%p\n", *key, *keylen, *data, *datalen, pme_return);
	#endif

	do_unlock(&(pm->mutex));
	return(1);
    } else {
	ZSTLFinishEnum(pm, iterator);

	#ifdef SANDISK_PRINTSTUFF
	    fprintf(stderr, "pdata=NULL, datalen=0\n");
	#endif

        *key     = NULL;
	*keylen  = 0;
        *data    = NULL;
	*datalen = 0;
	do_unlock(&(pm->mutex));
	return(0);
    }
}
Esempio n. 3
0
//  Return non-NULL if success, NULL if object exists
struct ZSTLMapEntry *ZSTLMapCreate(struct ZSTLMap *pm, char *pkey, uint32_t keylen, char *pdata, uint64_t datalen)
{
    ZSTLMapEntry_t   *pme;
    ZSTLMapBucket_t  *pb;

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapCreate: pm=%p, key=0x%lx, keylen=%d, pdata=%p, datalen=%ld, ", pm, *((uint64_t *) pkey), keylen, pdata, datalen);
    #endif

    pme = find_pme(pm, pkey, keylen, &pb);

    if (pme != NULL) {
	#ifdef SANDISK_PRINTSTUFF
	    fprintf(stderr, "pme=%p\n", pme);
	#endif

	do_unlock(&(pm->mutex));
        return(NULL);
    }

    /* Create a new entry. */

    pme = create_pme(pm, pkey, keylen, pdata, datalen);

    /* put myself on the bucket list */
    pme->bucket = pb;
    pme->next = pb->entry;
    pb->entry = pme;
    #ifdef LISTCHECK
        check_list(pb, pme);
    #endif

    pm->n_entries++;

    /* put myself on the lru list */
    {
        insert_lru(pm, pme);

	if ((pm->max_entries > 0) && (pm->n_entries > pm->max_entries)) {
	    // do an LRU replacement
	    replace_lru(pm, pme);
	}
    }

    do_unlock(&(pm->mutex));
    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "pme=%p\n", pme);
    #endif

    return(pme);
}
Esempio n. 4
0
int lock_main(int argc, char **argv)
{
	char **args = &argv[1];
	int c = argc - 1;

	while ((*args != NULL) && (*args)[0] == '-') {
		char *ch = *args;
		while (*(++ch) > 0) {
			switch(*ch) {
				case 'w':
					waitonly = 1;
					break;
				case 's':
					shared = 1;
					break;
				case 'u':
					unlock = 1;
					break;
			}
		}
		c--;
		args++;
	}

	if (c != 1)
		usage(argv[0]);

	file = *args;
	if (unlock)
		return do_unlock();
	else
		return do_lock();
}
Esempio n. 5
0
struct ZSTLIterator *ZSTLMapEnum(struct ZSTLMap *pm)
{
    ZSTLIterator_t    *iterator;

    pthread_mutex_lock(&(pm->enum_mutex));

    do_lock(&(pm->mutex));

    iterator = get_iterator(pm);
    zstlmap_assert(iterator);

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapEnum: pm=%p, iterator=%p, ", pm, iterator);
    #endif

    iterator->enum_entry = pm->lru_head;

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "pme=%p, enum_entry=%p\n", pm, iterator->enum_entry);
    #endif

    do_unlock(&(pm->mutex));

    return(iterator);
}
Esempio n. 6
0
//  Decrement the reference count for this entry
//  rc=1 if entry is found, rc=0 otherwise
int ZSTLMapRelease(struct ZSTLMap *pm, char *key, uint32_t keylen)
{
    ZSTLMapEntry_t   *pme;
    int                rc = 0;

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapRelease: pm=%p, key=0x%lx, keylen=%d", pm, *((uint64_t *) key), keylen);
    #endif

    pme = find_pme(pm, key, keylen, NULL);

    if (pme != NULL) {
// fprintf(stderr, ", after release [0x%lx] =%d\n", *((uint64_t *) key), pme->refcnt - 1);
	#ifdef SANDISK_PRINTSTUFF
	    fprintf(stderr, ", after release refcnt=%d\n", pme->refcnt - 1);
	#endif
        (pme->refcnt)--;
	rc = 1;
    } else {
	#ifdef SANDISK_PRINTSTUFF
	    fprintf(stderr, " (KEY NOT FOUND!)\n");
	#endif
    }

    do_unlock(&(pm->mutex));
    return(rc);
}
Esempio n. 7
0
void queue_push( int data, queue_t *queue ) {
    int done = 0;

    do_lock( &queue->operation_lock );

    while ( queue_is_full( queue ) ) {    
        do_unlock( &queue->operation_lock );
        __asm__("hlt");
        do_lock( &queue->operation_lock );
    }
    queue->data[queue->head] = data;
    queue->head = QUEUE_WRAP( queue->head + 1 );
    done = 1;

    do_unlock( &queue->operation_lock );
}
PHP_COUCHBASE_LOCAL
void php_couchbase_unlock_impl(INTERNAL_FUNCTION_PARAMETERS, int oo)
{
	char *key;
	char *cas = NULL;
	char *cas_e;
	long klen = 0;
	long cas_len = 0;
	lcb_cas_t cas_v = 0;
	php_couchbase_res *couchbase_res;
	lcb_error_t retval;

	int arg = (oo) ? PHP_COUCHBASE_ARG_F_OO : PHP_COUCHBASE_ARG_F_FUNCTIONAL;

	PHP_COUCHBASE_GET_PARAMS(couchbase_res,  arg,
							 "ss", &key, &klen, &cas, &cas_len);

	if (klen == 0) {
		couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo,
							   cb_illegal_key_exception,
							   "Failed to schedule set request: Empty key");
		return ;
	}

	if (cas_len == 0) {
		couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo,
							   cb_illegal_key_exception,
							   "No CAS specified: Empty cas");
		return ;
	}

	cas_v = (lcb_cas_t)strtoull(cas, &cas_e, 10);
	if (*cas_e != '\0') {
		couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo,
							   cb_illegal_key_exception,
							   "Invalid CAS specified");
		return;
	}


	if (couchbase_res->prefix_key_len) {
		klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key);
	}

	retval = do_unlock(couchbase_res->handle, key, klen, cas_v);
	couchbase_res->rc = retval;

	if (couchbase_res->prefix_key_len) {
		efree(key);
	}

	if (retval == LCB_SUCCESS) {
		RETVAL_TRUE;
	} else {
		couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, oo,
							   cb_lcb_exception,
							   "Failed to unlock the document: %s",
							   lcb_strerror(couchbase_res->handle, retval));
	}
}
Esempio n. 9
0
void char_walk( CHAR_DATA *ch )
{
	int        dir = -1;
	bool close = FALSE;
	bool lock = FALSE;
	ROOM_INDEX_DATA *prev_room;

	if ( !ch || ch->walking == 0 )
	return;

	if ( ch->in_room->vnum == ch->walking || ch->in_room->vnum == -1 * ch->walking )
	{
		ch->walking = 0;
		return;
	}

	if ( ch->walking > 0 )
	dir = find_path( ch->in_room->vnum, ch->walking, ch, 40000, TRUE );
	else if ( ch->walking < 0 )
	dir = find_path( ch->in_room->vnum, -1 * ch->walking, ch, 40000, FALSE );

	if ( dir < 0 || dir >= MAX_DIR )
	{
		ch->walking = 0;
		return;
	}

	if ( IS_SET( ch->in_room->exit[dir]->exit_info, EX_LOCKED ) )
	{
		do_unlock( ch, (char *) eng_dir_name[dir] );
		lock = TRUE;
	}

	if ( IS_SET( ch->in_room->exit[dir]->exit_info, EX_CLOSED ) )
	{
		do_open( ch, (char *) eng_dir_name[dir] );
		close = TRUE;
	}

	if ( IS_SET( sector_table[ch->in_room->exit[dir]->u1.to_room->sector_type].flag, SECT_UNDERWATER ) )
		return;

	prev_room = ch->in_room;
	move_char( ch, dir, FALSE, NULL );

	if ( ch->in_room->vnum == ch->walking || ch->in_room->vnum == -1 * ch->walking )
	ch->walking = 0;

	if ( ch->in_room == prev_room )
	return;

	if ( close )
	do_close( ch, (char *) eng_dir_name[rev_dir[dir]] );

	if ( lock )
	do_lock( ch, (char *) eng_dir_name[rev_dir[dir]] );

	return;
}
Esempio n. 10
0
/** Set/lock a lock (user interface).
 * \verbatim
 * This implements @lock.
 * \endverbatim
 * \param player the enactor.
 * \param name name of object to lock.
 * \param keyname key to lock the lock to, as a string.
 * \param type type of lock to lock.
 */
void
do_lock(dbref player, const char *name, const char *keyname, lock_type type)
{
  lock_type real_type;
  dbref thing;
  boolexp key;

  /* check for '@lock <object>/<atr>'  */
  if (strchr(name, '/')) {
    do_atrlock(player, name, "on");
    return;
  }
  if (!keyname || !*keyname) {
    do_unlock(player, name, type);
    return;
  }
  switch (thing = match_result(player, name, NOTYPE, MAT_EVERYTHING)) {
  case NOTHING:
    notify(player, T("I don't see what you want to lock!"));
    return;
  case AMBIGUOUS:
    notify(player, T("I don't know which one you want to lock!"));
    return;
  default:
    if (!controls(player, thing)) {
      notify(player, T("You can't lock that!"));
      return;
    }
    if (IsGarbage(thing)) {
      notify(player, T("Why would you want to lock garbage?"));
      return;
    }
    break;
  }

  key = parse_boolexp(player, keyname, type);

  /* do the lock */
  if (key == TRUE_BOOLEXP) {
    notify(player, T("I don't understand that key."));
  } else {
    if ((real_type = check_lock_type(player, thing, type)) != NULL) {
      /* everything ok, do it */
      if (add_lock(player, thing, real_type, key, LF_DEFAULT)) {
        if (!AreQuiet(player, thing))
          notify_format(player, T("%s(%s) - %s locked."),
                        AName(thing, AN_SYS, NULL), unparse_dbref(thing),
                        real_type);
        if (!IsPlayer(thing))
          ModTime(thing) = mudtime;
      } else {
        notify(player, T("Permission denied."));
        /*  Done by a failed add_lock()  // free_boolexp(key); */
      }
    } else
      free_boolexp(key);
  }
}
Esempio n. 11
0
unsigned char rc_get_seqnbr(void)
{
	FILE *sf;
	int tries = 1;
	int seq_nbr, pos;
	char *seqfile = rc_conf_str("seqfile");

	if ((sf = fopen(seqfile, "a+")) == NULL)
	{
		rc_log(LOG_ERR,"rc_get_seqnbr: couldn't open sequence file %s: %s", seqfile, strerror(errno));
		/* well, so guess a sequence number */
		return rc_guess_seqnbr();
	}

	while (do_lock_exclusive(fileno(sf))!= 0)
	{
		if (errno != EWOULDBLOCK) {
			rc_log(LOG_ERR, "rc_get_seqnbr: flock failure: %s: %s", seqfile, strerror(errno));
			fclose(sf);
			return rc_guess_seqnbr();
		}
		tries++;
		if (tries <= 10)
			rc_mdelay(500);
		else
			break;
	}

	if (tries > 10) {
		rc_log(LOG_ERR,"rc_get_seqnbr: couldn't get lock after %d tries: %s", tries-1, seqfile);
		fclose(sf);
		return rc_guess_seqnbr();
	}

	pos = ftell(sf);
	rewind(sf);
	if (fscanf(sf, "%d", &seq_nbr) != 1) {
		if (pos != ftell(sf)) {
			/* file was not empty */
			rc_log(LOG_ERR,"rc_get_seqnbr: fscanf failure: %s", seqfile);
		}
		seq_nbr = rc_guess_seqnbr();
	}

	rewind(sf);
	ftruncate(fileno(sf),0);
	fprintf(sf,"%d\n", (seq_nbr+1) & UCHAR_MAX);

	fflush(sf); /* fflush because a process may read it between the do_unlock and fclose */

	if (do_unlock(fileno(sf)) != 0)
		rc_log(LOG_ERR, "rc_get_seqnbr: couldn't release lock on %s: %s", seqfile, strerror(errno));

	fclose(sf);

	return (unsigned char)seq_nbr;
}
int
main(int argc, char **argv)
{
  if (!do_unlock()) {
    printf("Failed to unlock LSM protect.\n");
    exit(EXIT_FAILURE);
  }

  exit(EXIT_SUCCESS);
}
Esempio n. 13
0
int queue_pull( queue_t *queue ) {
    int ret = 0x12344321;
    int done = 0;
    
    do_lock( &queue->operation_lock );

    while ( queue_is_empty( queue ) ) {
        do_unlock( &queue->operation_lock );
        __asm__("hlt");
        do_lock( &queue->operation_lock );
    }
    ret = queue->data[queue->tail];
    queue->tail = QUEUE_WRAP( queue->tail + 1 );
    done = 1;

    do_unlock( &queue->operation_lock );
    
    return ret;
}
Esempio n. 14
0
//  Returns non-NULL if successful, NULL otherwise
struct ZSTLMapEntry *ZSTLMapGet(struct ZSTLMap *pm, char *key, uint32_t keylen, char **pdata, uint64_t *pdatalen)
{
    uint64_t           datalen;
    ZSTLMapEntry_t   *pme;
    char              *data;

    do_lock(&(pm->mutex));

    pme = find_pme(pm, key, keylen, NULL);

    if (pme != NULL) {
        data    = pme->contents;
	datalen = pme->datalen;

	// update the LRU list if necessary
	if (pm->max_entries != 0) {
	    update_lru(pm, pme);
	}

    } else {
        data    = NULL;
	datalen = 0;
    }

    #ifdef SANDISK_PRINTSTUFF
        if (pme != NULL) {
	    fprintf(stderr, "ZSTLMapGet: pm=%p, key=0x%lx, keylen=%d, pdata=%p, datalen=%ld, refcnt=%d, pme=%p\n", pm, *((uint64_t *) key), keylen, data, datalen, pme->refcnt, pme);
	} else {
	    fprintf(stderr, "ZSTLMapGet: pm=%p, key=0x%lx, keylen=%d, pdata=%p, datalen=%ld, pme=%p\n", pm, *((uint64_t *) key), keylen, data, datalen, pme);
	}

	#ifdef notdef
	    void* tracePtrs[100];
	    int count = backtrace( tracePtrs, 100 );

	    char** funcNames = backtrace_symbols( tracePtrs, count );

	    // Print the stack trace
	    printf("---------------------------------------------------------------------------\n");
	    for( int ii = 0; ii < count; ii++ ) {
		printf( "%s\n", funcNames[ii] );
	    }
	    printf("---------------------------------------------------------------------------\n");

	    // Free the string pointers
	    free( funcNames );
	#endif
    #endif

    do_unlock(&(pm->mutex));
    *pdatalen = datalen;
    *pdata    = data;
    return(pme);
}
Esempio n. 15
0
void ZSTLFinishEnum(struct ZSTLMap *pm, struct ZSTLIterator *iterator)
{
    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLFinishEnum: pm=%p, iterator=%p\n", pm, iterator);
    #endif

    free_iterator(pm, iterator);
    pthread_mutex_unlock(&(pm->enum_mutex));
    do_unlock(&(pm->mutex));
}
Esempio n. 16
0
/*   Return 0 if succeeds, 1 if object doesn't exist.
 */
int ZSTLMapDelete(struct ZSTLMap *pm, char *key, uint32_t keylen)
{
    uint64_t            h;
    ZSTLMapEntry_t   **ppme;
    ZSTLMapEntry_t    *pme;
    ZSTLMapBucket_t   *pb;
    char               *key2;

    key2 = (char *) *((uint64_t *) key);

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapDelete: pm=%p, key=0x%lx, keylen=%d\n", pm, *((uint64_t *) key), keylen);
    #endif

    h = zs_hash((const unsigned char *) key, sizeof(uint64_t), 0) % pm->nbuckets;
    pb = &(pm->buckets[h]);

    zstlmap_assert(keylen == 8); // remove this! xxxzzz

    for (ppme = &(pb->entry); (*ppme) != NULL; ppme = &((*ppme)->next)) {
	pme = *ppme;
	if (pme->key == key2) {

	    //  Remove from the LRU list if necessary
	    remove_lru(pm, pme);
	    pm->n_entries--;

            *ppme = pme->next;
            free_pme(pm, pme);
	    do_unlock(&(pm->mutex));
            return (0);
        }
    }
    do_unlock(&(pm->mutex));
    return (1);
}
Esempio n. 17
0
static void reply_lockingX_error(struct blocking_lock_record *blr, NTSTATUS status)
{
	files_struct *fsp = blr->fsp;
	uint16 num_ulocks = SVAL(blr->req->vwv+6, 0);
	uint64_t count = (uint64_t)0, offset = (uint64_t) 0;
	uint32 lock_pid;
	unsigned char locktype = CVAL(blr->req->vwv+3, 0);
	bool large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
	uint8_t *data;
	int i;

	data = (uint8_t *)blr->req->buf
		+ ((large_file_format ? 20 : 10)*num_ulocks);

	/* 
	 * Data now points at the beginning of the list
	 * of smb_lkrng structs.
	 */

	/*
	 * Ensure we don't do a remove on the lock that just failed,
	 * as under POSIX rules, if we have a lock already there, we
	 * will delete it (and we shouldn't) .....
	 */

	for(i = blr->lock_num - 1; i >= 0; i--) {
		bool err;

		lock_pid = get_lock_pid( data, i, large_file_format);
		count = get_lock_count( data, i, large_file_format);
		offset = get_lock_offset( data, i, large_file_format, &err);

		/*
		 * We know err cannot be set as if it was the lock
		 * request would never have been queued. JRA.
		 */

		do_unlock(smbd_messaging_context(),
			fsp,
			lock_pid,
			count,
			offset,
			WINDOWS_LOCK);
	}

	generic_blocking_lock_error(blr, status);
}
Esempio n. 18
0
static void undo_locks_obtained(struct blocking_lock_record *blr)
{
	files_struct *fsp = blr->fsp;
	uint16 num_ulocks = SVAL(blr->req->vwv+6, 0);
	uint64_t count = (uint64_t)0, offset = (uint64_t) 0;
	uint64_t smblctx;
	unsigned char locktype = CVAL(blr->req->vwv+3, 0);
	bool large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
	uint8_t *data;
	int i;

	data = discard_const_p(uint8_t, blr->req->buf)
		+ ((large_file_format ? 20 : 10)*num_ulocks);

	/*
	 * Data now points at the beginning of the list
	 * of smb_lkrng structs.
	 */

	/*
	 * Ensure we don't do a remove on the lock that just failed,
	 * as under POSIX rules, if we have a lock already there, we
	 * will delete it (and we shouldn't) .....
	 */

	for(i = blr->lock_num - 1; i >= 0; i--) {
		bool err;

		smblctx = get_lock_pid( data, i, large_file_format);
		count = get_lock_count( data, i, large_file_format);
		offset = get_lock_offset( data, i, large_file_format, &err);

		/*
		 * We know err cannot be set as if it was the lock
		 * request would never have been queued. JRA.
		 */

		do_unlock(fsp->conn->sconn->msg_ctx,
			fsp,
			smblctx,
			count,
			offset,
			WINDOWS_LOCK);
	}
}
Esempio n. 19
0
//  Decrement the reference count for this entry
int ZSTLMapReleaseEntry(struct ZSTLMap *pm, struct ZSTLMapEntry *pme)
{
    int rc = 0;

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapReleaseEntry: pm=%p, pme=%p\n", pm, pme);
    #endif

    if (pme != NULL) {
        (pme->refcnt)--;
	rc = 1;
    }

    do_unlock(&(pm->mutex));
    return(rc);
}
Esempio n. 20
0
static void reply_lockingX_error(blocking_lock_record *blr, NTSTATUS status)
{
	char *inbuf = blr->inbuf;
	files_struct *fsp = blr->fsp;
	connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
	uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
	SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT) 0;
	uint16 lock_pid;
	unsigned char locktype = CVAL(inbuf,smb_vwv3);
	BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
	char *data;
	int i;

	data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks);
	
	/* 
	 * Data now points at the beginning of the list
	 * of smb_lkrng structs.
	 */

	/*
	 * Ensure we don't do a remove on the lock that just failed,
	 * as under POSIX rules, if we have a lock already there, we
	 * will delete it (and we shouldn't) .....
	 */
	
	for(i = blr->lock_num - 1; i >= 0; i--) {
		BOOL err;
		
		lock_pid = get_lock_pid( data, i, large_file_format);
		count = get_lock_count( data, i, large_file_format);
		offset = get_lock_offset( data, i, large_file_format, &err);
		
		/*
		 * We know err cannot be set as if it was the lock
		 * request would never have been queued. JRA.
		 */
		
		do_unlock(fsp,conn,lock_pid,count,offset);
	}
	
	generic_blocking_lock_error(blr, status);
}
Esempio n. 21
0
void ZSTLMapCheckRefcnts(struct ZSTLMap *pm)
{
    uint64_t           i;
    ZSTLMapEntry_t   *pme;

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapCheckRefcnts: pm=%p\n", pm);
    #endif

    for (i=0; i<pm->nbuckets; i++) {
	for (pme = pm->buckets[i].entry; pme != NULL; pme = pme->next) {
	    if (pme->refcnt != 0) {
		fprintf(stderr, "*****************   ZSTLMapCheckRefcnts: [pm=%p]: key 0x%lx refcnt=%d!\n", pm, *((uint64_t *) pme->key), pme->refcnt);
	    }
	}
    }
    do_unlock(&(pm->mutex));
}
Esempio n. 22
0
void ZSTLMapClear(struct ZSTLMap *pm)
{
    ZSTLMapEntry_t   *pme, *pme_next;

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapClear: pm=%p\n", pm);
    #endif

    //  Go through LRU list and free entries
    //  This is much faster than examining all of the buckets!

    for (pme=pm->lru_head; pme != NULL; pme = pme_next) {
        pme_next = pme->next_lru;
	pme->bucket->entry = NULL;
        free_pme(pm, pme);
    }

    pm->n_entries     = 0;
    pm->lru_head      = NULL;
    pm->lru_tail      = NULL;
    do_unlock(&(pm->mutex));
}
Esempio n. 23
0
int restore_line(const char *filename,uint64_t lv,char *line) {
	char *ptr;
	uint32_t ts;
	int status;
	char* errormsgs[]={ ERROR_STRINGS };

	status = ERROR_MISMATCH;
	ptr = line;

	EAT(ptr,filename,lv,':');
	EAT(ptr,filename,lv,' ');
	GETU32(ts,ptr);
	EAT(ptr,filename,lv,'|');
	switch (*ptr) {
		case 'A':
			if (strncmp(ptr,"ACCESS",6)==0) {
				status = do_access(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"ATTR",4)==0) {
				status = do_attr(filename,lv,ts,ptr+4);
			} else if (strncmp(ptr,"APPEND",6)==0) {
				status = do_append(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"ACQUIRE",7)==0) {
				status = do_acquire(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"AQUIRE",6)==0) {
				status = do_acquire(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'C':
			if (strncmp(ptr,"CREATE",6)==0) {
				status = do_create(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"CUSTOMER",8)==0) {	// deprecated
				status = do_session(filename,lv,ts,ptr+8);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'E':
			if (strncmp(ptr,"EMPTYTRASH",10)==0) {
				status = do_emptytrash(filename,lv,ts,ptr+10);
			} else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
				status = do_emptyreserved(filename,lv,ts,ptr+13);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'F':
			if (strncmp(ptr,"FREEINODES",10)==0) {
				status = do_freeinodes(filename,lv,ts,ptr+10);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'I':
			if (strncmp(ptr,"INCVERSION",10)==0) {
				status = do_incversion(filename,lv,ts,ptr+10);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'L':
			if (strncmp(ptr,"LENGTH",6)==0) {
				status = do_length(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"LINK",4)==0) {
				status = do_link(filename,lv,ts,ptr+4);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'M':
			if (strncmp(ptr,"MOVE",4)==0) {
				status = do_move(filename,lv,ts,ptr+4);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'P':
			if (strncmp(ptr,"PURGE",5)==0) {
				status = do_purge(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'Q':
			if (strncmp(ptr,"QUOTA",5)==0) {
				status = do_quota(filename,lv,ts,ptr+5);
			}
			break;
		case 'R':
			if (strncmp(ptr,"RELEASE",7)==0) {
				status = do_release(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"REPAIR",6)==0) {
				status = do_repair(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'S':
			if (strncmp(ptr,"SETEATTR",8)==0) {
				status = do_seteattr(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SETGOAL",7)==0) {
				status = do_setgoal(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SETPATH",7)==0) {
				status = do_setpath(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
				status = do_settrashtime(filename,lv,ts,ptr+12);
			} else if (strncmp(ptr,"SETXATTR",8)==0) {
				status = do_setxattr(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SNAPSHOT",8)==0) {
				status = do_snapshot(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SYMLINK",7)==0) {
				status = do_symlink(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SESSION",7)==0) {
				status = do_session(filename,lv,ts,ptr+7);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'T':
			if (strncmp(ptr,"TRUNC",5)==0) {
				status = do_trunc(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'U':
			if (strncmp(ptr,"UNLINK",6)==0) {
				status = do_unlink(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"UNDEL",5)==0) {
				status = do_undel(filename,lv,ts,ptr+5);
			} else if (strncmp(ptr,"UNLOCK",6)==0) {
				status = do_unlock(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'W':
			if (strncmp(ptr,"WRITE",5)==0) {
				status = do_write(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		default:
			printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
	}
	if (status>STATUS_OK) {
		printf("%s:%"PRIu64": error: %d (%s)\n",filename,lv,status,errormsgs[status]);
	}
	return status;
}
Esempio n. 24
0
int main(int argc, char **argv)
{
	int opt;
	int len, rc;
	struct sigaction sigact;
	char *rest;
	int oflags = 0;
	int no_tag;

	memset(&sigact, 0, sizeof(sigact));
	sigact.sa_handler = sighandler;

	if (sigaction(SIGALRM, &sigact, NULL) == -1)
		return 1;

	if (sigaction(SIGPIPE, &sigact, NULL) == -1)
		return 1;

	input = stdin;
	output = stdout;
	/* now parsing options with getopt */
	while ((opt = getopt(argc, argv, options)) != EOF) {
		switch (opt) {
		case 'c':
			rc = chdir(optarg);
			if (rc == -1) {
				fprintf(stderr,
					"Can not change dir to %s errno = %d \"%s\"\n",
					optarg, errno, strerror(errno));
				exit(1);
			}
			break;

		case 'q':
			quiet = true;
			break;

		case 'd':
			duperrors = true;
			break;

		case 's':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -s\n");

			oflags |= 1;
			script = true;
			strncpy(server, optarg, MAXSTR);
			break;

		case 'x':
			if ((oflags & 7) != 0)
				show_usage(1,
					   "Can not combine -x and -s/-p/-n\n");

			oflags |= 8;
			script = true;
			input = fopen(optarg, "r");

			if (input == NULL)
				fatal("Could not open %s\n", optarg);
			break;

		case 'n':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -n\n");

			oflags |= 2;
			strncpy(name, optarg, MAXSTR);
			break;

		case 'p':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -p\n");

			oflags |= 4;
			strncpy(portstr, optarg, MAXSTR);
			port = atoi(optarg);
			break;

		case '?':
		case 'h':
		default:
			/* display the help */
			show_usage(0, "Help\n");
		}
	}

	if (oflags > 0 && oflags < 7)
		show_usage(1, "Must specify -s, -p, and -n together\n");

	if (oflags == 7)
		openserver();

	while (1) {
		len = readln(input, line, MAXSTR * 2);
		if (len < 0) {
			if (script)
				fatal("End of file on input\n");
			else
				break;
		} else {
			struct response resp;

			lno++;
			memset(&resp, 0, sizeof(resp));

			rest = SkipWhite(line, REQUIRES_MORE, "Invalid line");

			/* Skip totally blank line */
			if (rest == NULL)
				continue;

			if (script && !quiet)
				fprintf(stdout, "%s\n", rest);

			/* If line doesn't start with a tag, that's ok */
			no_tag = (!isdigit(*rest) && (*rest != '$'));

			/* Parse request into response structure */
			rest = parse_request(rest, &resp, no_tag);

			if (rest == NULL) {
				resp.r_status = STATUS_ERRNO;
				resp.r_errno = errno;
			} else {
				/* Make sure default status is ok */
				resp.r_status = STATUS_OK;

				if (*rest != '\0' && *rest != '#')
					fprintf_stderr(
					     "Command line not consumed, rest=\"%s\"\n",
					     rest);

				switch (resp.r_cmd) {
				case CMD_OPEN:
					do_open(&resp);
					break;
				case CMD_CLOSE:
					do_close(&resp);
					break;
				case CMD_LOCKW:
					do_lock(&resp);
					break;
				case CMD_LOCK:
					do_lock(&resp);
					break;
				case CMD_UNLOCK:
					do_unlock(&resp);
					break;
				case CMD_TEST:
					do_test(&resp);
					break;
				case CMD_LIST:
					do_list(&resp);
					break;
				case CMD_HOP:
					do_hop(&resp);
					break;
				case CMD_UNHOP:
					do_unhop(&resp);
					break;
				case CMD_SEEK:
					do_seek(&resp);
					break;
				case CMD_READ:
					do_read(&resp);
					break;
				case CMD_WRITE:
					do_write(&resp);
					break;
				case CMD_ALARM:
					do_alarm(&resp);
					break;

				case CMD_HELLO:
				case CMD_COMMENT:
				case CMD_QUIT:
					resp.r_status = STATUS_OK;
					break;

				case NUM_COMMANDS:
					fprintf_stderr("Invalid command %s\n",
						       line);
					continue;
				}
			}

			respond(&resp);

			if (resp.r_cmd == CMD_QUIT)
				exit(0);
		}
	}

	return 0;
}
Esempio n. 25
0
int ifdhandler_process(ct_socket_t * sock, ifd_reader_t * reader,
		       ct_buf_t * argbuf, ct_buf_t * resbuf)
{
	unsigned char cmd, unit;
	ct_tlv_parser_t args;
	ct_tlv_builder_t resp;
	int rc;

	/* Get command and target unit */
	if (ct_buf_get(argbuf, &cmd, 1) < 0 || ct_buf_get(argbuf, &unit, 1) < 0)
		return IFD_ERROR_INVALID_MSG;

	ifd_debug(1, "ifdhandler_process(cmd=%s, unit=%u)",
		  get_cmd_name(cmd), unit);

	/* First, handle commands that don't do TLV encoded
	 * arguments - currently this is only CT_CMD_TRANSACT. */
	if (cmd == CT_CMD_TRANSACT_OLD) {
		/* Security - deny any APDUs if there's an
		 * exclusive lock held by some other client. */
		if ((rc =
		     ifdhandler_check_lock(sock, unit, IFD_LOCK_EXCLUSIVE)) < 0)
			return rc;
		return do_transact_old(reader, unit, argbuf, resbuf);
	}

	if ((rc = do_before_command(reader)) < 0) {
		return rc;
	}

	memset(&args, 0, sizeof(args));
	if (ct_tlv_parse(&args, argbuf) < 0)
		return IFD_ERROR_INVALID_MSG;
	if (args.use_large_tags)
		sock->use_large_tags = 1;

	ct_tlv_builder_init(&resp, resbuf, sock->use_large_tags);

	switch (cmd) {
	case CT_CMD_STATUS:
		rc = do_status(reader, unit, &args, &resp);
		break;

	case CT_CMD_OUTPUT:
		rc = do_output(reader, unit, &args, &resp);
		break;

	case CT_CMD_RESET:
	case CT_CMD_REQUEST_ICC:
		rc = do_reset(reader, unit, &args, &resp);
		break;

	case CT_CMD_EJECT_ICC:
		rc = do_eject(reader, unit, &args, &resp);
		break;

	case CT_CMD_PERFORM_VERIFY:
		rc = do_verify(reader, unit, &args, &resp);
		break;

	case CT_CMD_LOCK:
		rc = do_lock(sock, reader, unit, &args, &resp);
		break;

	case CT_CMD_UNLOCK:
		rc = do_unlock(sock, reader, unit, &args, &resp);
		break;

	case CT_CMD_MEMORY_READ:
		rc = do_memory_read(reader, unit, &args, &resp);
		break;

	case CT_CMD_MEMORY_WRITE:
		rc = do_memory_write(reader, unit, &args, &resp);
		break;

	case CT_CMD_TRANSACT:
		rc = do_transact(reader, unit, &args, &resp);
		break;
	case CT_CMD_SET_PROTOCOL:
		rc = do_set_protocol(reader, unit, &args, &resp);
		break;
	default:
		return IFD_ERROR_INVALID_CMD;
	}

	if (rc >= 0)
		rc = resp.error;

	/*
	 * TODO consider checking error
	 */
	do_after_command(reader);

	return rc;
}
int
main(int argc, char **argv)
{
  switch (detect_device()) {
  case DEVICE_SBM203SH_S0024:
    mmc_protect_part = mmc_protect_part_sbm203sh_s0024;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH04E_01_00_02:
    mmc_protect_part = mmc_protect_part_sh04e_01_00_02;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH04E_01_00_03:
    mmc_protect_part = mmc_protect_part_sh04e_01_00_03;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH04E_01_00_04:
    mmc_protect_part = mmc_protect_part_sh04e_01_00_04;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH05E_01_00_05:
    mmc_protect_part = mmc_protect_part_sh05e_01_00_05;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE2;
    break;

  case DEVICE_SH05E_01_00_06:
    mmc_protect_part = mmc_protect_part_sh05e_01_00_06;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE2;
    break;

  case DEVICE_SH06E_01_00_01:
    mmc_protect_part = mmc_protect_part_sh06e_01_00_01;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH06E_01_00_06:
    mmc_protect_part = mmc_protect_part_sh06e_01_00_06;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH06E_01_00_07:
    mmc_protect_part = mmc_protect_part_sh06e_01_00_07;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH07E_01_00_03:
    mmc_protect_part = mmc_protect_part_sh07e_01_00_03;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE1;
    break;

  case DEVICE_SH09D_02_00_03:
    mmc_protect_part = mmc_protect_part_sh09d_02_00_03;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE2;
    break;

  case DEVICE_SHL21_01_00_09:
    mmc_protect_part = mmc_protect_part_shl21_01_00_09;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE2;
    break;

  case DEVICE_SHL21_01_01_02:
    mmc_protect_part = mmc_protect_part_shl21_01_01_02;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE2;
    break;

  default:
    mmc_protect_part = 0;
    mmc_protect_part_type = MMC_PROTECT_PART_TYPE_UNKNOWN;
  }

  if (!do_unlock()) {
    printf("Failed to unlock MMC protect.\n");
    exit(EXIT_FAILURE);
  }

  exit(EXIT_SUCCESS);
}
Esempio n. 27
0
int replay(const char *log_data) {
	uint64_t fv,lv; //fv = filesystem's version lv = log's version
	uint32_t ts;
	uint8_t status;
	char buff[10000];
	char *ptr;
	char* errormsgs[]={ ERROR_STRINGS };

	char *test_ptr;

	sprintf(buff,"%s",log_data);
	ptr = buff;
//for test
	test_ptr = buff;
	fv = shadow_fs_getversion();
	GETU64(lv,ptr);
	if(lv < fv) {
		MFSLOG(LOG_ERR,"the changelog's verison %lu is smaller than filesystem's version %lu",lv,fv);
		//more complicated method to ensure consistency
	} else {
		status = ERROR_MISMATCH; 
                EAT(ptr,lv,':');
                EAT(ptr,lv,' ');
                GETU32(ts,ptr);
                EAT(ptr,lv,'|');
                switch (*ptr) {
                	case 'A':
                                if (strncmp(ptr,"ACCESS",6)==0) {
                                        status = do_access(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"ATTR",4)==0) {
                                        status = do_attr(lv,ts,ptr+4);
                                } else if (strncmp(ptr,"APPEND",6)==0) {
                                        status = do_append(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"AQUIRE",6)==0) {
                                        status = do_aquire(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'C':
                                if (strncmp(ptr,"CREATE",6)==0) {
                                        status = do_create(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"CUSTOMER",8)==0) {      // deprecated
                                        status = do_session(lv,ts,ptr+8);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'E':
                                if (strncmp(ptr,"EMPTYTRASH",10)==0) {
                                        status = do_emptytrash(lv,ts,ptr+10);
                                } else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
                                        status = do_emptyreserved(lv,ts,ptr+13);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'F': 
                                if (strncmp(ptr,"FREEINODES",10)==0) {
                                        status = do_freeinodes(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'I':
                                if (strncmp(ptr,"INCVERSION",10)==0) {
                                        status = do_incversion(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'L':
                                if (strncmp(ptr,"LENGTH",6)==0) {
                                        status = do_length(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"LINK",4)==0) {
                                        status = do_link(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'M':
                                if (strncmp(ptr,"MOVE",4)==0) {
                                        status = do_move(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'P':
                                if (strncmp(ptr,"PURGE",5)==0) {
                                        status = do_purge(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'R':
                                if (strncmp(ptr,"RELEASE",7)==0) {
                                        status = do_release(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"REPAIR",6)==0) {
                                        status = do_repair(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'S':
                                if (strncmp(ptr,"SETEATTR",8)==0) {
                                        status = do_seteattr(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SETGOAL",7)==0) {
                                        status = do_setgoal(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETPATH",7)==0) {
                                        status = do_setpath(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
                                        status = do_settrashtime(lv,ts,ptr+12);
                                } else if (strncmp(ptr,"SNAPSHOT",8)==0) {
                                        status = do_snapshot(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SYMLINK",7)==0) {
                                        status = do_symlink(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SESSION",7)==0) {
                                        status = do_session(lv,ts,ptr+7);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'T':
                                if (strncmp(ptr,"TRUNC",5)==0) {
                                        status = do_trunc(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'U':
                                if (strncmp(ptr,"UNLINK",6)==0) {
                                        status = do_unlink(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"UNDEL",5)==0) {
                                        status = do_undel(lv,ts,ptr+5);
                                } else if (strncmp(ptr,"UNLOCK",6)==0) {
                                        status = do_unlock(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'W':
                                if (strncmp(ptr,"WRITE",5)==0) {
                                        status = do_write(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        default:
                                MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                        }
			/**
			  * if master is down, slave switch, we may missed some metadata 
			  * return 0 to let the process continue, otherwise, we will reply the 
			  * log forever.
			  * 
			  * Dongyang, Zhang
			  */				
			if (status!=STATUS_OK) {
				MFSLOG(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s),the log is (%s)",lv,status,errormsgs[status],test_ptr);
//                                syslog(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s)",lv,status,errormsgs[status]);
                           return 1;
                        }               
                        fv = shadow_fs_getversion();
                        if (lv+1!=fv) {
                                MFSLOG(LOG_ERR,"%"PRIu64": version mismatch fsversion:%"PRIu64"",lv,fv);
                                return 1;
                        }
	}
	return 0;
}                
Esempio n. 28
0
File: lock.c Progetto: jillest/pkg
static int
exec_lock_unlock(int argc, char **argv, enum action action)
{
	struct pkgdb	*db = NULL;
	struct pkgdb_it	*it = NULL;
	struct pkg	*pkg = NULL;
	const char	*pkgname;
	int		 match = MATCH_EXACT;
	int		 retcode;
	int		 exitcode = EX_OK;
	int		 ch;
	bool		 show_locked = false;

	struct option longopts[] = {
		{ "all",		no_argument,	NULL,	'a' },
		{ "case-sensitive",	no_argument,	NULL,	'C' },
		{ "glob",		no_argument,	NULL,	'g' },
		{ "show-locked",	no_argument,	NULL,	'l' },
		{ "quiet",		no_argument,	NULL,	'q' },
		{ "regex",		no_argument,	NULL,	'x' },
		{ "yes",		no_argument,	NULL,	'y' },
		{ NULL,		0,			NULL,	0   },
	};

	while ((ch = getopt_long(argc, argv, "aCgilqxy", longopts, NULL)) != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
			break;
		case 'C':
			pkgdb_set_case_sensitivity(true);
			break;
		case 'g':
			match = MATCH_GLOB;
			break;
		case 'i':
			pkgdb_set_case_sensitivity(false);
			break;
		case 'l':
			show_locked = true;
			break;
		case 'q':
			quiet = true;
			break;
		case 'x':
			match = MATCH_REGEX;
			break;
		case 'y':
			yes = true;
			break;
		default:
			usage_lock();
			return (EX_USAGE);
		}
        }
	argc -= optind;
	argv += optind;

	

	if (!(match == MATCH_ALL && argc == 0) && argc != 1 && !show_locked) {
		usage_lock();
		return (EX_USAGE);
	}

	if (match == MATCH_ALL)
		pkgname = NULL;
	else
		pkgname = argv[0];

	retcode = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE,
			       PKGDB_DB_LOCAL);
	if (retcode == EPKG_ENODB) {
		if (match == MATCH_ALL)
			return (EX_OK);
		if (!quiet)
			warnx("No packages installed.  Nothing to do!");
		return (EX_OK);
	} else if (retcode == EPKG_ENOACCESS) {
		warnx("Insufficient privileges to modify the package database");
		return (EX_NOPERM);
	} else if (retcode != EPKG_OK) {
		warnx("Error accessing the package database");
		return (EX_SOFTWARE);
	}

	retcode = pkgdb_open(&db, PKGDB_DEFAULT);
	if (retcode != EPKG_OK)
		return (EX_IOERR);

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_EXCLUSIVE) != EPKG_OK) {
		pkgdb_close(db);
		warnx("Cannot get an exclusive lock on database. "
		      "It is locked by another process");
		return (EX_TEMPFAIL);
	}

	if (match == MATCH_ALL || argc != 0) {
		if ((it = pkgdb_query(db, pkgname, match)) == NULL) {
			exitcode = EX_IOERR;
			goto cleanup;
		}

		while ((retcode = pkgdb_it_next(it, &pkg, 0)) == EPKG_OK) {
			if (action == LOCK)
				retcode = do_lock(db, pkg);
			else
				retcode = do_unlock(db, pkg);

			if (retcode != EPKG_OK) {
				exitcode = EX_IOERR;
				goto cleanup;
			}
		}
	}

	if (show_locked) 
		retcode = list_locked(db);

	if (retcode != EPKG_END)
		exitcode = EX_IOERR;

cleanup:
	if (pkg != NULL)
		pkg_free(pkg);
	if (it != NULL)
		pkgdb_it_free(it);

	pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);
	pkgdb_close(db);

	return (exitcode);
}
Esempio n. 29
0
static void do_action(int action, struct cardstate *cs,
		      struct bc_state *bcs,
		      struct at_state_t **p_at_state, char **pp_command,
		      int *p_genresp, int *p_resp_code,
		      struct event_t *ev)
{
	struct at_state_t *at_state = *p_at_state;
	struct bc_state *bcs2;
	unsigned long flags;

	int channel;

	unsigned char *s, *e;
	int i;
	unsigned long val;

	switch (action) {
	case ACT_NOTHING:
		break;
	case ACT_TIMEOUT:
		at_state->waiting = 1;
		break;
	case ACT_INIT:
		cs->at_state.pending_commands &= ~PC_INIT;
		cs->cur_at_seq = SEQ_NONE;
		cs->mode = M_UNIMODEM;
		spin_lock_irqsave(&cs->lock, flags);
		if (!cs->cidmode) {
			spin_unlock_irqrestore(&cs->lock, flags);
			gigaset_free_channels(cs);
			cs->mstate = MS_READY;
			break;
		}
		spin_unlock_irqrestore(&cs->lock, flags);
		cs->at_state.pending_commands |= PC_CIDMODE;
		gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE");
		cs->commands_pending = 1;
		break;
	case ACT_FAILINIT:
		dev_warn(cs->dev, "Could not initialize the device.\n");
		cs->dle = 0;
		init_failed(cs, M_UNKNOWN);
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_CONFIGMODE:
		init_failed(cs, M_CONFIG);
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_SETDLE1:
		cs->dle = 1;
		/* cs->inbuf[0].inputstate |= INS_command | INS_DLE_command; */
		cs->inbuf[0].inputstate &=
			~(INS_command | INS_DLE_command);
		break;
	case ACT_SETDLE0:
		cs->dle = 0;
		cs->inbuf[0].inputstate =
			(cs->inbuf[0].inputstate & ~INS_DLE_command)
			| INS_command;
		break;
	case ACT_CMODESET:
		if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) {
			gigaset_free_channels(cs);
			cs->mstate = MS_READY;
		}
		cs->mode = M_CID;
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_UMODESET:
		cs->mode = M_UNIMODEM;
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_FAILCMODE:
		cs->cur_at_seq = SEQ_NONE;
		if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) {
			init_failed(cs, M_UNKNOWN);
			break;
		}
		if (reinit_and_retry(cs, -1) < 0)
			schedule_init(cs, MS_RECOVER);
		break;
	case ACT_FAILUMODE:
		cs->cur_at_seq = SEQ_NONE;
		schedule_init(cs, MS_RECOVER);
		break;
	case ACT_HUPMODEM:
		/* send "+++" (hangup in unimodem mode) */
		if (cs->connected) {
			struct cmdbuf_t *cb;

			cb = kmalloc(sizeof(struct cmdbuf_t) + 3, GFP_ATOMIC);
			if (!cb) {
				dev_err(cs->dev, "%s: out of memory\n",
					__func__);
				return;
			}
			memcpy(cb->buf, "+++", 3);
			cb->len = 3;
			cb->offset = 0;
			cb->next = NULL;
			cb->wake_tasklet = NULL;
			cs->ops->write_cmd(cs, cb);
		}
		break;
	case ACT_RING:
		/* get fresh AT state structure for new CID */
		at_state = get_free_channel(cs, ev->parameter);
		if (!at_state) {
			dev_warn(cs->dev,
				 "RING ignored: could not allocate channel structure\n");
			break;
		}

		/* initialize AT state structure
		 * note that bcs may be NULL if no B channel is free
		 */
		at_state->ConState = 700;
		for (i = 0; i < STR_NUM; ++i) {
			kfree(at_state->str_var[i]);
			at_state->str_var[i] = NULL;
		}
		at_state->int_var[VAR_ZCTP] = -1;

		spin_lock_irqsave(&cs->lock, flags);
		at_state->timer_expires = RING_TIMEOUT;
		at_state->timer_active = 1;
		spin_unlock_irqrestore(&cs->lock, flags);
		break;
	case ACT_ICALL:
		handle_icall(cs, bcs, at_state);
		break;
	case ACT_FAILSDOWN:
		dev_warn(cs->dev, "Could not shut down the device.\n");
		/* fall through */
	case ACT_FAKESDOWN:
	case ACT_SDOWN:
		cs->cur_at_seq = SEQ_NONE;
		finish_shutdown(cs);
		break;
	case ACT_CONNECT:
		if (cs->onechannel) {
			at_state->pending_commands |= PC_DLE1;
			cs->commands_pending = 1;
			break;
		}
		bcs->chstate |= CHS_D_UP;
		gigaset_isdn_connD(bcs);
		cs->ops->init_bchannel(bcs);
		break;
	case ACT_DLE1:
		cs->cur_at_seq = SEQ_NONE;
		bcs = cs->bcs + cs->curchannel;

		bcs->chstate |= CHS_D_UP;
		gigaset_isdn_connD(bcs);
		cs->ops->init_bchannel(bcs);
		break;
	case ACT_FAKEHUP:
		at_state->int_var[VAR_ZSAU] = ZSAU_NULL;
		/* fall through */
	case ACT_DISCONNECT:
		cs->cur_at_seq = SEQ_NONE;
		at_state->cid = -1;
		if (!bcs) {
			disconnect_nobc(p_at_state, cs);
		} else if (cs->onechannel && cs->dle) {
			/* Check for other open channels not needed:
			 * DLE only used for M10x with one B channel.
			 */
			at_state->pending_commands |= PC_DLE0;
			cs->commands_pending = 1;
		} else {
			disconnect_bc(at_state, cs, bcs);
		}
		break;
	case ACT_FAKEDLE0:
		at_state->int_var[VAR_ZDLE] = 0;
		cs->dle = 0;
		/* fall through */
	case ACT_DLE0:
		cs->cur_at_seq = SEQ_NONE;
		bcs2 = cs->bcs + cs->curchannel;
		disconnect_bc(&bcs2->at_state, cs, bcs2);
		break;
	case ACT_ABORTHUP:
		cs->cur_at_seq = SEQ_NONE;
		dev_warn(cs->dev, "Could not hang up.\n");
		at_state->cid = -1;
		if (!bcs)
			disconnect_nobc(p_at_state, cs);
		else if (cs->onechannel)
			at_state->pending_commands |= PC_DLE0;
		else
			disconnect_bc(at_state, cs, bcs);
		schedule_init(cs, MS_RECOVER);
		break;
	case ACT_FAILDLE0:
		cs->cur_at_seq = SEQ_NONE;
		dev_warn(cs->dev, "Error leaving DLE mode.\n");
		cs->dle = 0;
		bcs2 = cs->bcs + cs->curchannel;
		disconnect_bc(&bcs2->at_state, cs, bcs2);
		schedule_init(cs, MS_RECOVER);
		break;
	case ACT_FAILDLE1:
		cs->cur_at_seq = SEQ_NONE;
		dev_warn(cs->dev,
			 "Could not enter DLE mode. Trying to hang up.\n");
		channel = cs->curchannel;
		cs->bcs[channel].at_state.pending_commands |= PC_HUP;
		cs->commands_pending = 1;
		break;

	case ACT_CID: /* got cid; start dialing */
		cs->cur_at_seq = SEQ_NONE;
		channel = cs->curchannel;
		if (ev->parameter > 0 && ev->parameter <= 65535) {
			cs->bcs[channel].at_state.cid = ev->parameter;
			cs->bcs[channel].at_state.pending_commands |=
				PC_DIAL;
			cs->commands_pending = 1;
			break;
		}
		/* bad cid: fall through */
	case ACT_FAILCID:
		cs->cur_at_seq = SEQ_NONE;
		channel = cs->curchannel;
		if (reinit_and_retry(cs, channel) < 0) {
			dev_warn(cs->dev,
				 "Could not get a call ID. Cannot dial.\n");
			bcs2 = cs->bcs + channel;
			disconnect_bc(&bcs2->at_state, cs, bcs2);
		}
		break;
	case ACT_ABORTCID:
		cs->cur_at_seq = SEQ_NONE;
		bcs2 = cs->bcs + cs->curchannel;
		disconnect_bc(&bcs2->at_state, cs, bcs2);
		break;

	case ACT_DIALING:
	case ACT_ACCEPTED:
		cs->cur_at_seq = SEQ_NONE;
		break;

	case ACT_ABORTACCEPT:	/* hangup/error/timeout during ICALL procssng */
		if (bcs)
			disconnect_bc(at_state, cs, bcs);
		else
			disconnect_nobc(p_at_state, cs);
		break;

	case ACT_ABORTDIAL:	/* error/timeout during dial preparation */
		cs->cur_at_seq = SEQ_NONE;
		at_state->pending_commands |= PC_HUP;
		cs->commands_pending = 1;
		break;

	case ACT_REMOTEREJECT:	/* DISCONNECT_IND after dialling */
	case ACT_CONNTIMEOUT:	/* timeout waiting for ZSAU=ACTIVE */
	case ACT_REMOTEHUP:	/* DISCONNECT_IND with established connection */
		at_state->pending_commands |= PC_HUP;
		cs->commands_pending = 1;
		break;
	case ACT_GETSTRING: /* warning: RING, ZDLE, ...
			       are not handled properly anymore */
		at_state->getstring = 1;
		break;
	case ACT_SETVER:
		if (!ev->ptr) {
			*p_genresp = 1;
			*p_resp_code = RSP_ERROR;
			break;
		}
		s = ev->ptr;

		if (!strcmp(s, "OK")) {
			/* OK without version string: assume old response */
			*p_genresp = 1;
			*p_resp_code = RSP_NONE;
			break;
		}

		for (i = 0; i < 4; ++i) {
			val = simple_strtoul(s, (char **) &e, 10);
			if (val > INT_MAX || e == s)
				break;
			if (i == 3) {
				if (*e)
					break;
			} else if (*e != '.')
				break;
			else
				s = e + 1;
			cs->fwver[i] = val;
		}
		if (i != 4) {
			*p_genresp = 1;
			*p_resp_code = RSP_ERROR;
			break;
		}
		cs->gotfwver = 0;
		break;
	case ACT_GOTVER:
		if (cs->gotfwver == 0) {
			cs->gotfwver = 1;
			gig_dbg(DEBUG_EVENT,
				"firmware version %02d.%03d.%02d.%02d",
				cs->fwver[0], cs->fwver[1],
				cs->fwver[2], cs->fwver[3]);
			break;
		}
		/* fall through */
	case ACT_FAILVER:
		cs->gotfwver = -1;
		dev_err(cs->dev, "could not read firmware version.\n");
		break;
	case ACT_ERROR:
		gig_dbg(DEBUG_ANY, "%s: ERROR response in ConState %d",
			__func__, at_state->ConState);
		cs->cur_at_seq = SEQ_NONE;
		break;
	case ACT_DEBUG:
		gig_dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d",
			__func__, ev->type, at_state->ConState);
		break;
	case ACT_WARN:
		dev_warn(cs->dev, "%s: resp_code %d in ConState %d!\n",
			 __func__, ev->type, at_state->ConState);
		break;
	case ACT_ZCAU:
		dev_warn(cs->dev, "cause code %04x in connection state %d.\n",
			 ev->parameter, at_state->ConState);
		break;

	/* events from the LL */

	case ACT_DIAL:
		if (!ev->ptr) {
			*p_genresp = 1;
			*p_resp_code = RSP_ERROR;
			break;
		}
		start_dial(at_state, ev->ptr, ev->parameter);
		break;
	case ACT_ACCEPT:
		start_accept(at_state);
		break;
	case ACT_HUP:
		at_state->pending_commands |= PC_HUP;
		gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP");
		cs->commands_pending = 1;
		break;

	/* hotplug events */

	case ACT_STOP:
		do_stop(cs);
		break;
	case ACT_START:
		do_start(cs);
		break;

	/* events from the interface */

	case ACT_IF_LOCK:
		cs->cmd_result = ev->parameter ? do_lock(cs) : do_unlock(cs);
		cs->waiting = 0;
		wake_up(&cs->waitqueue);
		break;
	case ACT_IF_VER:
		if (ev->parameter != 0)
			cs->cmd_result = -EINVAL;
		else if (cs->gotfwver != 1) {
			cs->cmd_result = -ENOENT;
		} else {
			memcpy(ev->arg, cs->fwver, sizeof cs->fwver);
			cs->cmd_result = 0;
		}
		cs->waiting = 0;
		wake_up(&cs->waitqueue);
		break;

	/* events from the proc file system */

	case ACT_PROC_CIDMODE:
		spin_lock_irqsave(&cs->lock, flags);
		if (ev->parameter != cs->cidmode) {
			cs->cidmode = ev->parameter;
			if (ev->parameter) {
				cs->at_state.pending_commands |= PC_CIDMODE;
				gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE");
			} else {
				cs->at_state.pending_commands |= PC_UMMODE;
				gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE");
			}
			cs->commands_pending = 1;
		}
		spin_unlock_irqrestore(&cs->lock, flags);
		cs->waiting = 0;
		wake_up(&cs->waitqueue);
		break;

	/* events from the hardware drivers */

	case ACT_NOTIFY_BC_DOWN:
		bchannel_down(bcs);
		break;
	case ACT_NOTIFY_BC_UP:
		bchannel_up(bcs);
		break;
	case ACT_SHUTDOWN:
		do_shutdown(cs);
		break;


	default:
		if (action >= ACT_CMD && action < ACT_CMD + AT_NUM) {
			*pp_command = at_state->bcs->commands[action - ACT_CMD];
			if (!*pp_command) {
				*p_genresp = 1;
				*p_resp_code = RSP_NULL;
			}
		} else
			dev_err(cs->dev, "%s: action==%d!\n", __func__, action);
	}
}
Esempio n. 30
0
int restore(void) {
        FILE *fd;
        char buff[10000];
        char *ptr;
        uint64_t v,lv;
        uint32_t ts;
        uint8_t status;
	uint32_t dplen;
	char *datapath = NULL;
	char *logpath = NULL;
        char* errormsgs[]={ ERROR_STRINGS };
        
        v = shadow_fs_getversion();
        lv = 0;

        MFSLOG(LOG_NOTICE,"meta data version: %"PRIu64"",v);
        
	datapath = strdup(DATA_PATH);
	dplen = strlen(datapath);
	logpath = malloc(dplen+sizeof("/changelog.0.mfs"));
	memcpy(logpath,datapath,dplen);
	memcpy(logpath+dplen,"/changelog.0.mfs",sizeof("/changelog.0.mfs"));
        fd = fopen(logpath,"r");
        if (fd==NULL) {
                MFSLOG(LOG_NOTICE,"can't open changemeta file: %s",logpath);
                return 1;
        }
        while (fgets(buff,10000,fd)) {
                ptr = buff;
                GETU64(lv,ptr);
                if (lv<v) {
                        // skip
                } else {
                        status = ERROR_MISMATCH;
                        EAT(ptr,lv,':');
                        EAT(ptr,lv,' ');
                        GETU32(ts,ptr);
                        EAT(ptr,lv,'|');
                        switch (*ptr) {
                        case 'A':
                                if (strncmp(ptr,"ACCESS",6)==0) {
                                        status = do_access(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"ATTR",4)==0) {
                                        status = do_attr(lv,ts,ptr+4);
                                } else if (strncmp(ptr,"APPEND",6)==0) {
                                        status = do_append(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"AQUIRE",6)==0) {
                                        status = do_aquire(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'C':
                                if (strncmp(ptr,"CREATE",6)==0) {
                                        status = do_create(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"CUSTOMER",8)==0) {      // deprecated
                                        status = do_session(lv,ts,ptr+8);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'E':
                                if (strncmp(ptr,"EMPTYTRASH",10)==0) {
                                        status = do_emptytrash(lv,ts,ptr+10);
                                } else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
                                        status = do_emptyreserved(lv,ts,ptr+13);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'F':
                                if (strncmp(ptr,"FREEINODES",10)==0) {
                                        status = do_freeinodes(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'I':
                                if (strncmp(ptr,"INCVERSION",10)==0) {
                                        status = do_incversion(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'L':
                                if (strncmp(ptr,"LENGTH",6)==0) {
                                        status = do_length(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"LINK",4)==0) {
                                        status = do_link(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'M':
                                if (strncmp(ptr,"MOVE",4)==0) {
                                        status = do_move(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'P':
                                if (strncmp(ptr,"PURGE",5)==0) {
                                        status = do_purge(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'R':
                                if (strncmp(ptr,"RELEASE",7)==0) {
                                        status = do_release(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"REPAIR",6)==0) {
                                        status = do_repair(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'S':
                                if (strncmp(ptr,"SETEATTR",8)==0) {
                                        status = do_seteattr(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SETGOAL",7)==0) {
                                        status = do_setgoal(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETPATH",7)==0) {
                                        status = do_setpath(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
                                        status = do_settrashtime(lv,ts,ptr+12);
                                } else if (strncmp(ptr,"SNAPSHOT",8)==0) {
                                        status = do_snapshot(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SYMLINK",7)==0) {
                                        status = do_symlink(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SESSION",7)==0) {
                                        status = do_session(lv,ts,ptr+7);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'T':
                                if (strncmp(ptr,"TRUNC",5)==0) {
                                        status = do_trunc(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'U':
                                if (strncmp(ptr,"UNLINK",6)==0) {
                                        status = do_unlink(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"UNDEL",5)==0) {
                                        status = do_undel(lv,ts,ptr+5);
                                } else if (strncmp(ptr,"UNLOCK",6)==0) {
                                        status = do_unlock(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'W':
                                if (strncmp(ptr,"WRITE",5)==0) {
                                        status = do_write(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        default:
                                MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                        }
			    /**
			      *  let the restore continue if we missed some meta data, otherwise the 
			      *
			      * Dongyang Zhang
			      */
                        if (status!=STATUS_OK) {
                                MFSLOG(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s)",lv,status,errormsgs[status]);
                                return 1;
                        }
                        v = shadow_fs_getversion();
                        if (lv+1!=v) {
                                MFSLOG(LOG_ERR,"%"PRIu64": version mismatch",lv);
                                return 1;
                        }
                }
        }
        fclose(fd);
        MFSLOG(LOG_NOTICE,"version after applying changelog: %"PRIu64"",v);
        return 0;
}