Пример #1
0
int _stx_dns_cache_getaddrlist(const char *hostname, struct in_addr *addrs,
			       int *num_addrs, st_utime_t timeout,
			       int rotate)
{
    char host[128];
    int n, count;

    if (!_stx_dns_cache)
	return _stx_dns_getaddrlist(hostname, addrs, num_addrs, timeout);

    for (n = 0; n < sizeof(host) - 1 && hostname[n]; n++) {
	host[n] = tolower(hostname[n]);
    }
    host[n] = '\0';

    if (lookup_entry(host, addrs, num_addrs, rotate))
	return 0;

    count = MAX_HOST_ADDRS;
    if (_stx_dns_getaddrlist(host, addr_list, &count, timeout) < 0)
	return -1;
    n = STX_MIN(*num_addrs, count);
    memcpy(addrs, addr_list, n * sizeof(*addrs));
    *num_addrs = n;

    insert_entry(host, addr_list, count);
    return 0;
}
Пример #2
0
// Check if there are any JVM TI prefixes which have been applied to the native method name.
// If any are found, remove them before attemping the look up of the
// native implementation again.
// See SetNativeMethodPrefix in the JVM TI Spec for more details.
address NativeLookup::lookup_entry_prefixed(methodHandle method, bool& in_base_library, TRAPS) {
  ResourceMark rm(THREAD);

  int prefix_count;
  char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  char* in_name = method->name()->as_C_string();
  char* wrapper_name = in_name;
  // last applied prefix will be first -- go backwards
  for (int i = prefix_count-1; i >= 0; i--) {
    char* prefix = prefixes[i];
    size_t prefix_len = strlen(prefix);
    if (strncmp(prefix, wrapper_name, prefix_len) == 0) {
      // has this prefix remove it
      wrapper_name += prefix_len;
    }
  }
  if (wrapper_name != in_name) {
    // we have a name for a wrapping method
    int wrapper_name_len = (int)strlen(wrapper_name);
    TempNewSymbol wrapper_symbol = SymbolTable::probe(wrapper_name, wrapper_name_len);
    if (wrapper_symbol != NULL) {
      KlassHandle kh(method->method_holder());
      methodOop wrapper_method = Klass::cast(kh())->lookup_method(wrapper_symbol,
                                                                  method->signature());
      if (wrapper_method != NULL && !wrapper_method->is_native()) {
        // we found a wrapper method, use its native entry
        method->set_is_prefixed_native();
        return lookup_entry(wrapper_method, in_base_library, THREAD);
      }
    }
  }
  return NULL;
}
Пример #3
0
//-------------------------------------------------------------------------
// Delete a crate from the crate db
//-------------------------------------------------------------------------
int DelCrate()
{
	char	crateName[CRATE_NAME_SIZE + 1];
	int		index, numOfEntries;
	int		status = SUCCESS;

	static DESCRIPTOR( phy_name_p, "PHY_NAME" );
	static DYNAMIC_DESCRIPTOR( phy_name );

	// get user input
	str_free1_dx(&phy_name);				// per twf -- clear out field
	cli_get_value( &phy_name_p, &phy_name );
	str_upcase( &phy_name, &phy_name );
	// trim it...
	sprintf(crateName, "%.6s", phy_name.pointer);

	// check to see if db file memory mapped
	if( CRATEdbFileIsMapped == FALSE ) {			// is not, so try
		if( map_data_file(CRATE_DB) != SUCCESS ) {	// we're dead in the water
			status = FAILURE;		// MAP_ERROR;		[2001.07.12]
			goto DelCrate_Exit;
		}
	}

	// get number of current entries
	if( (numOfEntries = get_file_count(CRATE_DB)) == 0 ) {	// no entries in crate db file
		if( MSGLVL(IMPORTANT) )
			fprintf( stderr, "db file empty, no entries to remove\n" );

		status = FAILURE;		// DELCRATE_ERROR;		[2001.07.12]
		goto DelCrate_Exit;
	}

	// try to remove from crate.db
	if( (index = lookup_entry(CRATE_DB, crateName)) >= 0 ) {	// module does exist
		if( remove_entry(CRATE_DB, index) != SUCCESS ) {		// removal failed
			status = FAILURE;		// DELCRATE_ERROR;		[2001.07.12]
			goto DelCrate_Exit;
		}
	}
	else {		// no such module
		if( MSGLVL(IMPORTANT) )
			fprintf( stderr, "delcrate(): entry '%s' not found\n", crateName);

		status = FAILURE;		// DELCRATE_ERROR;		[2001.07.12]
		goto DelCrate_Exit;
	}

DelCrate_Exit:
	if( MSGLVL(DETAILS) ) {
		printf("DelCrate() status = %d\n", status);
	}

	return SUCCESS;
}
Пример #4
0
address NativeLookup::lookup_base(methodHandle method, bool& in_base_library, TRAPS) {
  address entry = NULL;
  ResourceMark rm(THREAD);

  entry = lookup_entry(method, in_base_library, THREAD);
  if (entry != NULL) return entry;

  // standard native method resolution has failed.  Check if there are any
  // JVM TI prefixes which have been applied to the native method name.
  entry = lookup_entry_prefixed(method, in_base_library, THREAD);
  if (entry != NULL) return entry;

  // Native function not found, throw UnsatisfiedLinkError
  THROW_MSG_0(vmSymbols::java_lang_UnsatisfiedLinkError(),
              method->name_and_sig_as_C_string());
}
Пример #5
0
//-------------------------------------------------------------------------
// translate a logical module name to a physical representation (ie 'Key' format)
//-------------------------------------------------------------------------
// Fri May 25 12:23:23 EDT 2001
// Fri Feb  8 10:42:57 EST 2002	-- fixed type of 'key->scsi_port'
//-------------------------------------------------------------------------
// input: 	logical module name
// output:	status, and modified data referenced by pointer
//-------------------------------------------------------------------------
int xlate_logicalname( char *Name, CamKey *key )
{
	int						i;
	int						status = SUCCESS;	// otpimistic
	struct Module_			Mod;
	extern struct MODULE	*CTSdb;
	extern int				CTSdbFileIsMapped;

	if( MSGLVL(FUNCTION_NAME) )
		printf( "xlate_logicalname()\n" );

	if( strchr(Name, ':') != NULL ) {			// invalid logical name ...
		status = ERROR;							// ... was passed a physical name
		goto Xlate_LogicalName_Exit;
	}

	// check to see if CTS db is memory mapped
	if( CTSdbFileIsMapped == FALSE ) {
		if( map_data_file( CTS_DB ) != SUCCESS ) {
			status = MAP_ERROR;					// not mapped, we're done :<
			goto Xlate_LogicalName_Exit;
		}
	}

	// look up entry in db file
	if( (i = lookup_entry( CTS_DB, Name )) < 0 ) {
		status = NO_DEVICE;
		goto Xlate_LogicalName_Exit;
	}

	parse_cts_db( CTSdb+i, &Mod );				// get info ...

	// load up struct with vital info
	key->scsi_port    = Mod.adapter +'A';		// SCSI host adapter	[2002.02.08]
	key->scsi_address = Mod.id;					// SCSI id
	key->crate        = Mod.crate;				// CAMAC crate number
	key->slot         = Mod.slot;				// CAMAC slot (ie station)

Xlate_LogicalName_Exit:
	if( MSGLVL(DETAILS) ) {
		printf( "xlate(): name['%s'] ==>> HA[%c] id[%d] crate[%02d] slot[%d]\n",
			Name, key->scsi_port, key->scsi_address, key->crate, key->slot
			);
	}

	return status;
}
Пример #6
0
int main(int argc, char *argv[])
{
    char *short_desc;
    FILE *inf_file;

    if (argc!=3)
    {
        usage(argv[0]);
        return(-1);
    }

    inf_file=sys_fopen(argv[1],"r");
    if (!inf_file)
    {
        fprintf(stderr,"Description file not found, bye\n");
        return(-1);
    }

    lookup_strings(inf_file);

    short_desc=find_desc(inf_file,argv[2]);
    if (short_desc==NULL)
    {
        fprintf(stderr,"Printer not found\n");
        return(-1);
    }
    else fprintf(stderr,"Found:%s\n",short_desc);

    lookup_entry(inf_file,"DestinationDirs");
    build_subdir();

    if((files_to_copy=(char *)malloc(2048*sizeof(char))) == NULL) {
        fprintf(stderr, "%s: malloc fail.\n", argv[0] );
        exit(1);
    }
    *files_to_copy='\0';
    scan_short_desc(inf_file,short_desc);
    fprintf(stdout,"%s:%s:%s:",
            argv[2],driverfile,datafile);
    fprintf(stdout,"%s:",
            helpfile?helpfile:"");
    fprintf(stdout,"%s:",
            languagemonitor?languagemonitor:"");
    fprintf(stdout,"%s:",datatype);
    fprintf(stdout,"%s\n",files_to_copy);
    return 0;
}
Пример #7
0
//-----------------------------------------------------------
// turn_crate_on_off_line()
//-----------------------------------------------------------
// Fri Jul 27 11:56:57 EDT 2001 -- changed calling sequence for CamPiow()
// Tue Jul 31 11:55:21 EDT 2001	-- added 'offline' support
//-----------------------------------------------------------
// Tue Apr 10 11:11:48 EDT 2001
// eg. *crate_name == "GKB509"
//-----------------------------------------------------------
int turn_crate_on_off_line( char *crate_name, int state )
{
	char					controller[12], *pController;
	short 					SCCdata;
	int						i, status = SUCCESS;		// optimistic ...
        int idx;
	TranslatedIosb 			iosb;
        extern struct CRATE *CRATEdb;
        int online;
        int enhanced;
        int crateStatus;

	if( MSGLVL(FUNCTION_NAME) )
		printf( "turn_crate_on_off_line('%s'=>%s)\n", crate_name, (state == ON) ? "ON" : "off" );

	// convert to all UPPER CASE
	for( i = 0; i < strlen(crate_name); ++i )
		toupper(*crate_name);

	// create full crate controller designation
	// NB! all crate controllers reside in slot 30
	sprintf( &controller[0], "%.6s:N30", crate_name );

	// lookup name -- make sure a valid device
	if( (idx = lookup_entry( CRATE_DB, crate_name )) < 0 ) {		// lookup actual device num
		if( MSGLVL(IMPORTANT) )
			fprintf( stderr, "no such crate in 'crate.db'\n" );

		status = NO_DEVICE;									// doesn't exist
		goto TurnCrateOnOffLine_Exit;
	}
	if( MSGLVL(DETAILS) )
		printf( "lookup OK -- found '%s'\n", crate_name );

	pController = &controller[0];

        if (CRATEdb[idx].HwyType != ('0'+JORWAY_73A)) {
	  SCCdata = 1;					// initiates Dataway Z
	  status = CamPiow(
			   pController,		// serial crate controller name
			   0,				// A	--\__ write status register
			   17,				// F	--/
			   &SCCdata,		// data value
			   16,				// mem == 16-bit data
			   &iosb			// *iosb
			   );
	  
	  SCCdata = (state == ON) ? 0 : 0x1000;	// clear status register
	  status = CamPiow(
			   pController,		// serial crate controller name
			   0,				// A	--\__ write status register
			   17,				// F	--/
			   &SCCdata, 		// data value
			   16,				// mem == 16-bit data
			   &iosb			// *iosb
			   );
	  if (status & 1)
	    {
	      status = get_crate_status(pController, &crateStatus);
	      online = ((crateStatus & 0x1000) != 0x1000)    ? TRUE  : FALSE;
	      if( !crateStatus || crateStatus == 0x3 )
		online = FALSE;
	      CRATEdb[idx].online = online ? '1' : '0';
	      enhanced = (online && (crateStatus & 0x4000)) ? TRUE  : FALSE;
	      CRATEdb[idx].enhanced = enhanced ? '1' : '0';          
	    }
	}
        else {
	    CRATEdb[idx].online = (state == ON) ? '1' : '0';
            CRATEdb[idx].enhanced = '0';
            status = 1;
	}

//-----------------------------------------------------------
TurnCrateOnOffLine_Exit:
	if( MSGLVL(DETAILS) )
		printf( "tcool(): status %d\n", status );

	return status;
}
Пример #8
0
int create_inode(char *pathname, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)
{
	long long start = sBlk->inode_table_start + start_block;
	squashfs_inode_header header;
	char *block_ptr;
	int bytes = lookup_entry(inode_table_hash, start), file_fd;

	TRACE("create_inode: pathname %s, start 0x%llx, offset %d\n", pathname, start, offset);

	if(bytes == -1) {
		ERROR("create_inode: inode block 0x%llx out of range!\n", start);
		return FALSE;
	}
	block_ptr = inode_table + bytes + offset;

	if(swap) {
		squashfs_base_inode_header sinode;
		memcpy(&sinode, block_ptr, sizeof(header.base));
		SQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));
	} else
		memcpy(&header.base, block_ptr, sizeof(header.base));

	if(created_inode[header.base.inode_number - 1]) {
		TRACE("create_inode: hard link\n");
		if(link(created_inode[header.base.inode_number - 1], pathname) == -1) {
			ERROR("create_inode: failed to create hardlink, because %s\n", strerror(errno));
			return FALSE;
		}

		return TRUE;
	}

	switch(header.base.inode_type) {
		case SQUASHFS_FILE_TYPE: {
			unsigned int frag_bytes;
			unsigned int blocks;
			unsigned int offset;
			long long start;
			squashfs_reg_inode_header *inode = &header.reg;

			if(swap) {
				squashfs_reg_inode_header sinode;
				memcpy(&sinode, block_ptr, sizeof(sinode));
				SQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);
			} else
				memcpy(inode, block_ptr, sizeof(*inode));

			frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;
			offset = inode->offset;
			blocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size
				+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>
				sBlk->block_log;
			start = inode->start_block;

			TRACE("create_inode: regular file, file_size %lld, blocks %d\n", inode->file_size, blocks);

			if(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,
					block_ptr + sizeof(*inode), inode->mode)) {
				set_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);
				file_count ++;
			}
			break;
		}	
		case SQUASHFS_LREG_TYPE: {
			unsigned int frag_bytes;
			unsigned int blocks;
			unsigned int offset;
			long long start;
			squashfs_lreg_inode_header *inode = &header.lreg;

			if(swap) {
				squashfs_lreg_inode_header sinode;
				memcpy(&sinode, block_ptr, sizeof(sinode));
				SQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);
			} else
				memcpy(inode, block_ptr, sizeof(*inode));

			frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;
			offset = inode->offset;
			blocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size
				+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>
				sBlk->block_log;
			start = inode->start_block;

			TRACE("create_inode: regular file, file_size %lld, blocks %d\n", inode->file_size, blocks);

			if(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,
					block_ptr + sizeof(*inode), inode->mode)) {
				set_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);
				file_count ++;
			}
			break;
		}	
		case SQUASHFS_SYMLINK_TYPE: {
			squashfs_symlink_inode_header *inodep = &header.symlink;
			char name[65536];

			if(swap) {
				squashfs_symlink_inode_header sinodep;
				memcpy(&sinodep, block_ptr, sizeof(sinodep));
				SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);
			} else
				memcpy(inodep, block_ptr, sizeof(*inodep));

			TRACE("create_inode: symlink, symlink_size %d\n", inodep->symlink_size);

			strncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);
			name[inodep->symlink_size] = '\0';

			if(symlink(name, pathname) == -1) {
				ERROR("create_inode: failed to create symlink %s, because %s\n", pathname,
					strerror(errno));
				break;
			}

			if(geteuid() == 0) {
				uid_t uid_value = (uid_t) uid_table[inodep->uid];
				uid_t guid_value = inodep->guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[inodep->guid];

				if(lchown(pathname, uid_value, guid_value) == -1)
					ERROR("create_inode: failed to change uid and gids on %s, because %s\n", pathname, strerror(errno));
			}

			sym_count ++;
			break;
		}
 		case SQUASHFS_BLKDEV_TYPE:
	 	case SQUASHFS_CHRDEV_TYPE: {
			squashfs_dev_inode_header *inodep = &header.dev;

			if(swap) {
				squashfs_dev_inode_header sinodep;
				memcpy(&sinodep, block_ptr, sizeof(sinodep));
				SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);
			} else
				memcpy(inodep, block_ptr, sizeof(*inodep));

			TRACE("create_inode: dev, rdev 0x%x\n", inodep->rdev);

			if(geteuid() == 0) {
				if(mknod(pathname, inodep->inode_type == SQUASHFS_CHRDEV_TYPE ? S_IFCHR : S_IFBLK,
							makedev((inodep->rdev >> 8) & 0xff, inodep->rdev & 0xff))
							== -1) {
					ERROR("create_inode: failed to create %s device %s, because %s\n",
						inodep->inode_type == SQUASHFS_CHRDEV_TYPE ? "character" : "block",
						pathname, strerror(errno));
					break;
				}
				set_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);
				dev_count ++;
			} else
				ERROR("create_inode: could not create %s device %s, because you're not superuser!\n",
					inodep->inode_type == SQUASHFS_CHRDEV_TYPE ? "character" : "block",
					pathname, strerror(errno));
			break;
			}
		case SQUASHFS_FIFO_TYPE:
			TRACE("create_inode: fifo\n");

			if(mknod(pathname, S_IFIFO, 0) == -1) {
				ERROR("create_inode: failed to create fifo %s, because %s\n",
					pathname, strerror(errno));
				break;
			}
			set_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,
				header.base.mtime, TRUE);
			fifo_count ++;
			break;
		case SQUASHFS_SOCKET_TYPE:
			TRACE("create_inode: socket\n");
			ERROR("create_inode: socket %s ignored\n", pathname);
			break;
		default:
			ERROR("Unknown inode type %d in create_inode_table!\n", header.base.inode_type);
			return FALSE;
	}
Пример #9
0
//-------------------------------------------------------------------------
// Fri Mar  9 15:12:40 EST 2001
// Thu Mar 15 13:40:01 EST 2001
// Mon Mar 26 13:49:08 EST 2001
// Tue Apr  3 16:45:23 EDT 2001
// Mon Apr 30 16:37:43 EDT 2001 -- added support for highway type
// Fri Jul  6 11:37:19 EDT 2001 -- 'tighten-up' search loop
//-------------------------------------------------------------------------
// lookup a CAMAC device (either a serial highway or a module) and
// return o/s specific device number, eg '/dev/sg#'
// puts value into crate.db; leaves unchanged if not found
// NB! called by 'autoconfig()' in cts::verbs
//-------------------------------------------------------------------------
int map_scsi_device( char *highway_name )
{
	char				line[80], *pline, tmp[7];
	char				dsf[3], hwytype;
	int					adapter, i, numOfEntries, scsi_id, sg_number;
	int					status = SUCCESS;		// optimistic
	int					found = FALSE;
	FILE				*fp, *fopen();
	extern struct CRATE	*CRATEdb;				// pointer to in-memory copy of data file

	if( MSGLVL(FUNCTION_NAME) )
		printf( "map_scsi_device('%s')\n", highway_name );

	// open '/proc' filesystem scsi info
	if( (fp = fopen(PROC_FILE, "r")) == NULL ) {
		if( MSGLVL(ALWAYS) )
			fprintf( stderr, "failure to open '%s'\n", PROC_FILE );

		status = FILE_ERROR; 	// serious error !!! no scsi devices to check
		goto MapScsiDevice_Exit;
	}

	// get current db file count
	if( (numOfEntries = get_file_count( CRATE_DB )) <= 0 ) {
		status = FILE_ERROR;
		goto MapScsiDevice_Exit;				// we're done  :<
	}
	if( MSGLVL(DETAILS) )
		printf( "crate.db count= %d\n", numOfEntries );

	// lookup highway name
	if( MSGLVL(DETAILS) )
		printf("msd() looking up '%s'\n", highway_name);
	if( (i = lookup_entry( CRATE_DB, highway_name )) < 0 ) {
		status = NO_DEVICE; 					// no such device in db file
		goto MapScsiDevice_Exit;
	}
	if( MSGLVL(DETAILS) )
		printf( "msd(): lookup index [%d]:%s\n", i, highway_name );

	// point to actual memory
	pline = &line[0];

	// scan all scsi devices
	sg_number = 0;		// start at the beginning
	while( !found && (pline = fgets(line, sizeof(line), fp)) != NULL ) {
		if( strncmp(pline, "Host:", 5) == EQUAL ) {
			sscanf(line, "Host: scsi%d Channel: %*2c Id: %d %*s", &adapter, &scsi_id);

			sprintf(tmp, "GK%c%d", 'A' + adapter, scsi_id);
			if( strncmp(tmp, highway_name, 4) == EQUAL ) {		// found it
				if( QueryHighwayType( tmp ) == SUCCESS )		// determine highway type
					hwytype = tmp[5];

				// we're done, so exit
				found = TRUE;
			}
			else
				sg_number++;
		} // end of if() ....
	} // end of while() ...

	// 'lock' file with semaphore
	if( lock_file() != SUCCESS ) {
		status = FAILURE;		// LOCK_ERROR;		[2001.07.12]
		goto MapScsiDevice_Exit;
	}

	// update memory mapped version
	if( found ) {
		sprintf(dsf, "%03d", sg_number);			// format conversion
		strncpy((CRATEdb+i)->DSFname, dsf, 3);		// real device number
		(CRATEdb+i)->HwyType = hwytype;				// highway type
	}
	else {
		strncpy((CRATEdb+i)->DSFname, "...", 3);	// place-holder device number
		(CRATEdb+i)->HwyType = '.';
	}

	// commit changes to file
	if( commit_entry( CRATE_DB ) != SUCCESS ) {
		status = FAILURE;		// COMMIT_ERROR;	[2001.07.12]
		goto MapScsiDevice_Exit;
	}
	if( MSGLVL(DETAILS) )
		printf( "'%.4s+%.3s+%c'\n", highway_name, (CRATEdb+i)->DSFname, (CRATEdb+i)->HwyType );

	// unlock file
	if( unlock_file() != SUCCESS ) {
		status = FAILURE;		// UNLOCK_ERROR;	[2001.07.12]
		goto MapScsiDevice_Exit;
	}

MapScsiDevice_Exit:
	// cleanup
	if( fp )
		fclose(fp);

	return status;
}
Пример #10
0
static void scan_short_desc(FILE *fichier, char *short_desc)
{
    int i=0;
    char *temp;
    char *copyfiles=0,*datasection=0;

    helpfile=0;
    languagemonitor=0;
    vendorsetup=0;
    datatype="RAW";
    if((temp=(char *)malloc(sizeof(pstring))) == NULL) {
        fprintf(stderr, "scan_short_desc: malloc fail !\n");
        exit(1);
    }

    driverfile=short_desc;
    datafile=short_desc;

    lookup_entry(fichier,short_desc);

    while(*buffer[i]!='\0') {
#ifdef DEBUGIT
        fprintf(stderr,"\tLookup up of %s\n",buffer[i]);
#endif
        if (strncasecmp(buffer[i],"CopyFiles",9)==0)
            copyfiles=scan(buffer[i],&temp);
        else if (strncasecmp(buffer[i],"DataSection",11)==0)
            datasection=scan(buffer[i],&temp);
        else if (strncasecmp(buffer[i],"DataFile",8)==0)
            datafile=scan(buffer[i],&temp);
        else if (strncasecmp(buffer[i],"DriverFile",10)==0)
            driverfile=scan(buffer[i],&temp);
        else if (strncasecmp(buffer[i],"HelpFile",8)==0)
            helpfile=scan(buffer[i],&temp);
        else if (strncasecmp(buffer[i],"LanguageMonitor",15)==0)
            languagemonitor=scan(buffer[i],&temp);
        else if (strncasecmp(buffer[i],"DefaultDataType",15)==0)
            datatype=scan(buffer[i],&temp);
        else if (strncasecmp(buffer[i],"VendorSetup",11)==0)
            vendorsetup=scan(buffer[i],&temp);
        i++;
    }

    if (datasection) {
        lookup_entry(fichier,datasection);

        i = 0;
        while(*buffer[i]!='\0') {
#ifdef DEBUGIT
            fprintf(stderr,"\tLookup up of %s\n",buffer[i]);
#endif
            if (strncasecmp(buffer[i],"CopyFiles",9)==0)
                copyfiles=scan(buffer[i],&temp);
            else if (strncasecmp(buffer[i],"DataSection",11)==0)
                datasection=scan(buffer[i],&temp);
            else if (strncasecmp(buffer[i],"DataFile",8)==0)
                datafile=scan(buffer[i],&temp);
            else if (strncasecmp(buffer[i],"DriverFile",10)==0)
                driverfile=scan(buffer[i],&temp);
            else if (strncasecmp(buffer[i],"HelpFile",8)==0)
                helpfile=scan(buffer[i],&temp);
            else if (strncasecmp(buffer[i],"LanguageMonitor",15)==0)
                languagemonitor=scan(buffer[i],&temp);
            else if (strncasecmp(buffer[i],"DefaultDataType",15)==0)
                datatype=scan(buffer[i],&temp);
            else if (strncasecmp(buffer[i],"VendorSetup",11)==0)
                vendorsetup=scan(buffer[i],&temp);
            i++;
        }
    }

    if (languagemonitor) {
        temp = strtok(languagemonitor,",");
        if (*temp == '"') ++temp;
        pstrcpy(languagemonitor,temp);
        if ((temp = strchr(languagemonitor,'"'))!=NULL) *temp = '\0';
    }

    if (i) fprintf(stderr,"End of section found\n");

    fprintf(stderr,"CopyFiles: %s\n",
            copyfiles?copyfiles:"(null)");
    fprintf(stderr,"Datasection: %s\n",
            datasection?datasection:"(null)");
    fprintf(stderr,"Datafile: %s\n",
            datafile?datafile:"(null)");
    fprintf(stderr,"Driverfile: %s\n",
            driverfile?driverfile:"(null)");
    fprintf(stderr,"Helpfile: %s\n",
            helpfile?helpfile:"(null)");
    fprintf(stderr,"LanguageMonitor: %s\n",
            languagemonitor?languagemonitor:"(null)");
    fprintf(stderr,"VendorSetup: %s\n",
            vendorsetup?vendorsetup:"(null)");
    if (copyfiles) scan_copyfiles(fichier,copyfiles);
}
Пример #11
0
struct inode *read_inode_3(unsigned int start_block, unsigned int offset)
{
	static squashfs_inode_header_3 header;
	long long start = sBlk.inode_table_start + start_block;
	int bytes = lookup_entry(inode_table_hash, start);
	char *block_ptr = inode_table + bytes + offset;
	static struct inode i;

	TRACE("read_inode: reading inode [%d:%d]\n", start_block,  offset);

	if(bytes == -1) {
		ERROR("read_inode: inode table block %lld not found\n", start); 
		return NULL;
	}

	if(swap) {
		squashfs_base_inode_header_3 sinode;
		memcpy(&sinode, block_ptr, sizeof(header.base));
		SQUASHFS_SWAP_BASE_INODE_HEADER_3(&header.base, &sinode,
			sizeof(squashfs_base_inode_header_3));
	} else
		memcpy(&header.base, block_ptr, sizeof(header.base));

	i.uid = (uid_t) uid_table[header.base.uid];
	i.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :
		(uid_t) guid_table[header.base.guid];
	i.mode = lookup_type[header.base.inode_type] | header.base.mode;
	i.type = header.base.inode_type;
	i.time = header.base.mtime;
	i.inode_number = header.base.inode_number;

	switch(header.base.inode_type) {
		case SQUASHFS_DIR_TYPE: {
			squashfs_dir_inode_header_3 *inode = &header.dir;

			if(swap) {
				squashfs_dir_inode_header_3 sinode;
				memcpy(&sinode, block_ptr, sizeof(header.dir));
				SQUASHFS_SWAP_DIR_INODE_HEADER_3(&header.dir,
					&sinode);
			} else
				memcpy(&header.dir, block_ptr, sizeof(header.dir));

			i.data = inode->file_size;
			i.offset = inode->offset;
			i.start = inode->start_block;
			break;
		}
		case SQUASHFS_LDIR_TYPE: {
			squashfs_ldir_inode_header_3 *inode = &header.ldir;

			if(swap) {
				squashfs_ldir_inode_header_3 sinode;
				memcpy(&sinode, block_ptr, sizeof(header.ldir));
				SQUASHFS_SWAP_LDIR_INODE_HEADER_3(&header.ldir,
					&sinode);
			} else
				memcpy(&header.ldir, block_ptr,
					sizeof(header.ldir));

			i.data = inode->file_size;
			i.offset = inode->offset;
			i.start = inode->start_block;
			break;
		}
		case SQUASHFS_FILE_TYPE: {
			squashfs_reg_inode_header_3 *inode = &header.reg;

			if(swap) {
				squashfs_reg_inode_header_3 sinode;
				memcpy(&sinode, block_ptr, sizeof(sinode));
				SQUASHFS_SWAP_REG_INODE_HEADER_3(inode,
					&sinode);
			} else
				memcpy(inode, block_ptr, sizeof(*inode));

			i.data = inode->file_size;
			i.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG
				?  0 : inode->file_size % sBlk.block_size;
			i.fragment = inode->fragment;
			i.offset = inode->offset;
			i.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?
				(inode->file_size + sBlk.block_size - 1) >>
				sBlk.block_log :
				inode->file_size >> sBlk.block_log;
			i.start = inode->start_block;
			i.sparse = 1;
			i.block_ptr = block_ptr + sizeof(*inode);
			break;
		}	
		case SQUASHFS_LREG_TYPE: {
			squashfs_lreg_inode_header_3 *inode = &header.lreg;

			if(swap) {
				squashfs_lreg_inode_header_3 sinode;
				memcpy(&sinode, block_ptr, sizeof(sinode));
				SQUASHFS_SWAP_LREG_INODE_HEADER_3(inode,
					&sinode);
			} else
				memcpy(inode, block_ptr, sizeof(*inode));

			i.data = inode->file_size;
			i.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG
				?  0 : inode->file_size % sBlk.block_size;
			i.fragment = inode->fragment;
			i.offset = inode->offset;
			i.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?
				(inode->file_size + sBlk.block_size - 1) >>
				sBlk.block_log :
				inode->file_size >> sBlk.block_log;
			i.start = inode->start_block;
			i.sparse = 1;
			i.block_ptr = block_ptr + sizeof(*inode);
			break;
		}	
		case SQUASHFS_SYMLINK_TYPE: {
			squashfs_symlink_inode_header_3 *inodep =
				&header.symlink;

			if(swap) {
				squashfs_symlink_inode_header_3 sinodep;
				memcpy(&sinodep, block_ptr, sizeof(sinodep));
				SQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(inodep,
					&sinodep);
			} else
				memcpy(inodep, block_ptr, sizeof(*inodep));

			i.symlink = malloc(inodep->symlink_size + 1);
			if(i.symlink == NULL)
				EXIT_UNSQUASH("read_inode: failed to malloc "
					"symlink data\n");
			strncpy(i.symlink, block_ptr +
				sizeof(squashfs_symlink_inode_header_3),
				inodep->symlink_size);
			i.symlink[inodep->symlink_size] = '\0';
			i.data = inodep->symlink_size;
			break;
		}
 		case SQUASHFS_BLKDEV_TYPE:
	 	case SQUASHFS_CHRDEV_TYPE: {
			squashfs_dev_inode_header_3 *inodep = &header.dev;

			if(swap) {
				squashfs_dev_inode_header_3 sinodep;
				memcpy(&sinodep, block_ptr, sizeof(sinodep));
				SQUASHFS_SWAP_DEV_INODE_HEADER_3(inodep,
					&sinodep);
			} else
				memcpy(inodep, block_ptr, sizeof(*inodep));

			i.data = inodep->rdev;
			break;
			}
		case SQUASHFS_FIFO_TYPE:
		case SQUASHFS_SOCKET_TYPE:
			i.data = 0;
			break;
		default:
			ERROR("Unknown inode type %d in read_inode!\n",
				header.base.inode_type);
			return NULL;
	}
	return &i;
}
Пример #12
0
//-------------------------------------------------------------------------
// assign a new module to CTS database
//-------------------------------------------------------------------------
int Assign()
{
	char	line[MODULE_ENTRY+1];
	int		dbFileSize, fd, i, nullMask, numOfEntries, rc;
	int		status = SUCCESS;				// assume the best

	static DESCRIPTOR( phy_name_p, "PHY_NAME" );
	static DYNAMIC_DESCRIPTOR( phy_name );

	static DESCRIPTOR( log_name_p, "LOG_NAME" );
	static DYNAMIC_DESCRIPTOR( log_name );

	static DESCRIPTOR( comment_p, "COMMENT" );
	static DYNAMIC_DESCRIPTOR( comment );

	// get user input
	cli_get_value( &phy_name_p, &phy_name );
	str_upcase( &phy_name, &phy_name );

	cli_get_value( &log_name_p, &log_name );
	str_upcase( &log_name, &log_name );

	str_free1_dx(&comment);					// per twf -- clear out comment field
	cli_get_value( &comment_p, &comment );

	// check to see if db file exists
	if( check_for_file(CTS_DB_FILE) != SUCCESS ) {	// does not exist, yet
		// try to creat (sic) it
		if( (fd = Creat(CTS_DB_FILE, 0666)) == ERROR ) {
			status = FAILURE;				// FILE_ERROR;		[2001.07.12]
			goto Assign_Exit;				// we're done  :<
		}
		else
			close(fd);
	}

	// check to see if db file is memory mapped
	if( CTSdbFileIsMapped == FALSE ) {				// is not, so try
		if( map_data_file(CTS_DB) != SUCCESS ) {	// we're dead in the water
			status = FAILURE;		// MAP_ERROR;		[2001.07.12]
			goto Assign_Exit;
		}
	}

	// get current db file count
	if( (numOfEntries = get_file_count(CTS_DB)) < 0 ) {
		status = FAILURE;			// FILE_ERROR;		[2001.07.12]
		goto Assign_Exit;
	}

	if( numOfEntries ) {		// 1 or more
		if( lookup_entry(CTS_DB, log_name.pointer) >= 0 ) {	// duplicate !
			if( MSGLVL(IMPORTANT) )
				fprintf( stderr, "duplicate module name '%s' -- not allowed\n", log_name.pointer );

			status = FAILURE;		// DUPLICATE;		[2001.07.12]
			goto Assign_Exit;
		}
	}

	// get db file size
	if( (dbFileSize = get_db_file_size(CTS_DB_FILE)) == ERROR ) {
		status = FAILURE;			// FILE_ERROR;		[2001.07.12]
		goto Assign_Exit;
	}
	dbFileSize /= MODULE_ENTRY;	// .. current maximum number of possible module entries

	// do we need to expand db file?
	if( (dbFileSize == 0) || (numOfEntries == dbFileSize) ) {		// ... yes
		if( expand_db(CTS_DB, numOfEntries) != SUCCESS ) {			// expand ...
			status = FAILURE;		// EXPAND_ERROR; [2001.07.12]	// ... failure
			goto Assign_Exit;
		}
	}		// else OK

	// create a temporary string
	sprintf( line, "%-32s %-10s %-40s\n", 
		log_name.pointer, 								// these were entered by the user
		phy_name.pointer, 
		comment.pointer ? comment.pointer : ""
		);

	// check comment field for null string, ie "(null)"
	nullMask = (1 << strlen(nullStr)) - 1;				// set all mask bits
	for( i = COMMENT_INDEX; i < COMMENT_INDEX + strlen(nullStr); ++i )
		if( line[i] == nullStr[i - COMMENT_INDEX] )
			nullMask &= ~(1 << (i - COMMENT_INDEX));	// clear a bit in mask

	if( nullMask == 0 )									// all mask bit have been reset, ie matched
		for( i = COMMENT_INDEX; i < COMMENT_INDEX + strlen(nullStr); ++i ) 
			line[i] = ' ';								// make it spaces

	// add it ...
	if( add_entry(CTS_DB, line) != SUCCESS ) {
		status = FAILURE;		// ASSIGN_ERROR;		[2001.07.12]
		goto Assign_Exit;
	}

#if NEED_WARM_N_FUZZY
	// write to a buffer file for a warm fuzzy ...
	if( (fd = Creat("buffer.db", 0666)) == ERROR ) {
		if( MSGLVL(ALWAYS) )
			perror("creat()");

		status = FAILURE;		// FILE_ERROR;			[2001.07.12]
		goto Assign_Exit;
	}

	rc = write(fd, line, sizeof(line));
	close(fd);
	if( rc != sizeof(line) ) {
		if( MSGLVL(ALWAYS) )
			perror("write()");

		status = FAILURE;		// FILE_ERROR;			[2001.07.12]
	}
#endif

Assign_Exit:			// we're done, so out'a here!
	if( MSGLVL(DETAILS) ) {
		printf("Assign(): "); ShowStatus(status);
	}

	return status;
}
Пример #13
0
//-------------------------------------------------------------------------
// Add a crate to the crate db
//-------------------------------------------------------------------------
int AddCrate()
{
	char	line[CRATE_ENTRY + 1];
	int		dbFileSize, fd, numOfEntries;
	int		status = SUCCESS;				// assume the best

	static DESCRIPTOR( phy_name_p, "PHY_NAME" );
	static DYNAMIC_DESCRIPTOR( phy_name );

	// get user input
	str_free1_dx(&phy_name);				// per twf -- clear out field
	cli_get_value( &phy_name_p, &phy_name );
	str_upcase( &phy_name, &phy_name );

	// [2002.01.08]
	if( CRATEdbFileIsMapped == FALSE ) {					// ... no
		if( check_for_file(CRATE_DB_FILE) != SUCCESS ) {	// ... no
			if( (fd = Creat(CRATE_DB_FILE, 0666)) == ERROR ) {	// no
				status = FAILURE;
				goto AddCrate_Exit;
			}
			else
				close(fd);										// yes
		}

		if( map_data_file(CRATE_DB) != SUCCESS ) {			// failure :(
			status = MAP_ERROR;
			goto AddCrate_Exit;
		} 													// else OK :)
	}

	// get current db file count
	if( (numOfEntries = get_file_count(CRATE_DB)) == FILE_ERROR ) {
		status = FAILURE;			// FILE_ERROR;		[2001.07.12]
		goto AddCrate_Exit;
	}

	if( numOfEntries ) {		// 1 or more
                char pname[7];
                sprintf(pname,"%.6s",phy_name.pointer);
		if( lookup_entry(CRATE_DB, pname) >= 0 ) {			// duplicate !
			if( MSGLVL(IMPORTANT) )
				fprintf( stderr, "duplicate crate name '%.6s' -- not allowed\n", phy_name.pointer );

			status = FAILURE;		// DUPLICATE;		[2001.07.12]
			goto AddCrate_Exit;
		}
	}

	// get db file size
	if( (dbFileSize = get_db_file_size(CRATE_DB_FILE)) == ERROR ) {
		status = FAILURE;			// FILE_ERROR;		[2001.07.12]
		goto AddCrate_Exit;
	}
	dbFileSize /= CRATE_ENTRY;	// .. current maximum number of possible crate entries

	// do we need to expand db file?
	if( (dbFileSize == 0) || (numOfEntries == dbFileSize) ) {				// ... yes
		if( (status = expand_db(CRATE_DB, numOfEntries)) != SUCCESS ) {		// expand
			status = FAILURE;	// EXPAND_ERROR; [2001.07.12]											// failure
			goto AddCrate_Exit;
		}
	}		// else OK

	// make an entry line, with online and enhanced set as undefined
	sprintf( line, "%-.6s:...:.:.:.\n",
		phy_name.pointer
		);

	// add it ...
	if( (status = add_entry(CRATE_DB, line)) != SUCCESS ) {
		status = FAILURE;			// ASSIGN_ERROR;		[2001.07.12]
		goto AddCrate_Exit;
	}

AddCrate_Exit:
	if( MSGLVL(DETAILS) ) {
		printf("AddCrate(): "); ShowStatus(status);
	}

	if( status == SUCCESS )			// if everything is OK ...
		Autoconfig();				// ... map crate to /dev/sg#

//ShowCrate();
	return status;
}
Пример #14
0
struct inode *read_inode_4(unsigned int start_block, unsigned int offset)
{
	static union squashfs_inode_header header;
	long long start = sBlk.s.inode_table_start + start_block;
	int bytes = lookup_entry(inode_table_hash, start);
	char *block_ptr = inode_table + bytes + offset;
	static struct inode i;

	TRACE("read_inode: reading inode [%d:%d]\n", start_block,  offset);

	if(bytes == -1)
		EXIT_UNSQUASH("read_inode: inode table block %lld not found\n",
			start); 		

	SQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, block_ptr);

	i.uid = (uid_t) id_table[header.base.uid];
	i.gid = (uid_t) id_table[header.base.guid];
	i.mode = lookup_type[header.base.inode_type] | header.base.mode;
	i.type = header.base.inode_type;
	i.time = header.base.mtime;
	i.inode_number = header.base.inode_number;

	switch(header.base.inode_type) {
		case SQUASHFS_DIR_TYPE: {
			struct squashfs_dir_inode_header *inode = &header.dir;

			SQUASHFS_SWAP_DIR_INODE_HEADER(inode, block_ptr);

			i.data = inode->file_size;
			i.offset = inode->offset;
			i.start = inode->start_block;
			i.xattr = SQUASHFS_INVALID_XATTR;
			break;
		}
		case SQUASHFS_LDIR_TYPE: {
			struct squashfs_ldir_inode_header *inode = &header.ldir;

			SQUASHFS_SWAP_LDIR_INODE_HEADER(inode, block_ptr);

			i.data = inode->file_size;
			i.offset = inode->offset;
			i.start = inode->start_block;
			i.xattr = inode->xattr;
			break;
		}
		case SQUASHFS_FILE_TYPE: {
			struct squashfs_reg_inode_header *inode = &header.reg;

			SQUASHFS_SWAP_REG_INODE_HEADER(inode, block_ptr);

			i.data = inode->file_size;
			i.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG
				?  0 : inode->file_size % sBlk.s.block_size;
			i.fragment = inode->fragment;
			i.offset = inode->offset;
			i.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?
				(i.data + sBlk.s.block_size - 1) >>
				sBlk.s.block_log :
				i.data >> sBlk.s.block_log;
			i.start = inode->start_block;
			i.sparse = 0;
			i.block_ptr = block_ptr + sizeof(*inode);
			i.xattr = SQUASHFS_INVALID_XATTR;
			break;
		}	
		case SQUASHFS_LREG_TYPE: {
			struct squashfs_lreg_inode_header *inode = &header.lreg;

			SQUASHFS_SWAP_LREG_INODE_HEADER(inode, block_ptr);

			i.data = inode->file_size;
			i.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG
				?  0 : inode->file_size % sBlk.s.block_size;
			i.fragment = inode->fragment;
			i.offset = inode->offset;
			i.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?
				(inode->file_size + sBlk.s.block_size - 1) >>
				sBlk.s.block_log :
				inode->file_size >> sBlk.s.block_log;
			i.start = inode->start_block;
			i.sparse = inode->sparse != 0;
			i.block_ptr = block_ptr + sizeof(*inode);
			i.xattr = inode->xattr;
			break;
		}	
		case SQUASHFS_SYMLINK_TYPE:
		case SQUASHFS_LSYMLINK_TYPE: {
			struct squashfs_symlink_inode_header *inode = &header.symlink;

			SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inode, block_ptr);

			i.symlink = malloc(inode->symlink_size + 1);
			if(i.symlink == NULL)
				EXIT_UNSQUASH("read_inode: failed to malloc "
					"symlink data\n");
			strncpy(i.symlink, block_ptr +
				sizeof(struct squashfs_symlink_inode_header),
				inode->symlink_size);
			i.symlink[inode->symlink_size] = '\0';
			i.data = inode->symlink_size;

			if(header.base.inode_type == SQUASHFS_LSYMLINK_TYPE)
				SQUASHFS_SWAP_INTS(&i.xattr, block_ptr +
					sizeof(struct squashfs_symlink_inode_header) +
					inode->symlink_size, 1);
			else
				i.xattr = SQUASHFS_INVALID_XATTR;
			break;
		}
 		case SQUASHFS_BLKDEV_TYPE:
	 	case SQUASHFS_CHRDEV_TYPE: {
			struct squashfs_dev_inode_header *inode = &header.dev;

			SQUASHFS_SWAP_DEV_INODE_HEADER(inode, block_ptr);

			i.data = inode->rdev;
			i.xattr = SQUASHFS_INVALID_XATTR;
			break;
		}
 		case SQUASHFS_LBLKDEV_TYPE:
	 	case SQUASHFS_LCHRDEV_TYPE: {
			struct squashfs_ldev_inode_header *inode = &header.ldev;

			SQUASHFS_SWAP_LDEV_INODE_HEADER(inode, block_ptr);

			i.data = inode->rdev;
			i.xattr = inode->xattr;
			break;
		}
		case SQUASHFS_FIFO_TYPE:
		case SQUASHFS_SOCKET_TYPE:
			i.data = 0;
			i.xattr = SQUASHFS_INVALID_XATTR;
			break;
		case SQUASHFS_LFIFO_TYPE:
		case SQUASHFS_LSOCKET_TYPE: {
			struct squashfs_lipc_inode_header *inode = &header.lipc;

			SQUASHFS_SWAP_LIPC_INODE_HEADER(inode, block_ptr);

			i.data = 0;
			i.xattr = inode->xattr;
			break;
		}
		default:
			EXIT_UNSQUASH("Unknown inode type %d in read_inode!\n",
				header.base.inode_type);
	}
	return &i;
}
Пример #15
0
void handle_fuse_request(struct fuse *fuse, struct fuse_in_header *hdr, void *data, unsigned len)
{
    struct node *node;

    if ((len < sizeof(*hdr)) || (hdr->len != len)) {
        ERROR("malformed header\n");
        return;
    }

    len -= hdr->len;

    if (hdr->nodeid) {
        node = lookup_by_inode(fuse, hdr->nodeid);
        if (!node) {
            fuse_status(fuse, hdr->unique, -ENOENT);
            return;
        }
    } else {
        node = 0;
    }

    switch (hdr->opcode) {
    case FUSE_LOOKUP: { /* bytez[] -> entry_out */
        TRACE("LOOKUP %llx %s\n", hdr->nodeid, (char*) data);
        lookup_entry(fuse, node, (char*) data, hdr->unique);
        return;
    }
    case FUSE_FORGET: {
        struct fuse_forget_in *req = data;
        TRACE("FORGET %llx (%s) #%lld\n", hdr->nodeid, node->name, req->nlookup);
            /* no reply */
        while (req->nlookup--)
            node_release(node);
        return;
    }
    case FUSE_GETATTR: { /* getattr_in -> attr_out */
        struct fuse_getattr_in *req = data;
        struct fuse_attr_out out;

        TRACE("GETATTR flags=%x fh=%llx\n", req->getattr_flags, req->fh);

        memset(&out, 0, sizeof(out));
        node_get_attr(node, &out.attr);
        out.attr_valid = 10;

        fuse_reply(fuse, hdr->unique, &out, sizeof(out));
        return;
    }
    case FUSE_SETATTR: { /* setattr_in -> attr_out */
        struct fuse_setattr_in *req = data;
        struct fuse_attr_out out;
        char *path, buffer[PATH_BUFFER_SIZE];
        int res = 0;
        struct timespec times[2];

        TRACE("SETATTR fh=%llx id=%llx valid=%x\n",
              req->fh, hdr->nodeid, req->valid);

        /* XXX: incomplete implementation on purpose.   chmod/chown
         * should NEVER be implemented.*/

        path = node_get_path(node, buffer, 0);
        if (req->valid & FATTR_SIZE)
            res = truncate(path, req->size);
        if (res)
            goto getout;

        /* Handle changing atime and mtime.  If FATTR_ATIME_and FATTR_ATIME_NOW
         * are both set, then set it to the current time.  Else, set it to the
         * time specified in the request.  Same goes for mtime.  Use utimensat(2)
         * as it allows ATIME and MTIME to be changed independently, and has
         * nanosecond resolution which fuse also has.
         */
        if (req->valid & (FATTR_ATIME | FATTR_MTIME)) {
            times[0].tv_nsec = UTIME_OMIT;
            times[1].tv_nsec = UTIME_OMIT;
            if (req->valid & FATTR_ATIME) {
                if (req->valid & FATTR_ATIME_NOW) {
                  times[0].tv_nsec = UTIME_NOW;
                } else {
                  times[0].tv_sec = req->atime;
                  times[0].tv_nsec = req->atimensec;
                }
            }
            if (req->valid & FATTR_MTIME) {
                if (req->valid & FATTR_MTIME_NOW) {
                  times[1].tv_nsec = UTIME_NOW;
                } else {
                  times[1].tv_sec = req->mtime;
                  times[1].tv_nsec = req->mtimensec;
                }
            }
            TRACE("Calling utimensat on %s with atime %ld, mtime=%ld\n", path, times[0].tv_sec, times[1].tv_sec);
            res = utimensat(-1, path, times, 0);
        }

        getout:
        memset(&out, 0, sizeof(out));
        node_get_attr(node, &out.attr);
        out.attr_valid = 10;

        if (res)
            fuse_status(fuse, hdr->unique, -errno);
        else
            fuse_reply(fuse, hdr->unique, &out, sizeof(out));
        return;
    }
//    case FUSE_READLINK:
//    case FUSE_SYMLINK:
    case FUSE_MKNOD: { /* mknod_in, bytez[] -> entry_out */
        struct fuse_mknod_in *req = data;
        char *path, buffer[PATH_BUFFER_SIZE];
        char *name = ((char*) data) + sizeof(*req);
        int res;

        TRACE("MKNOD %s @ %llx\n", name, hdr->nodeid);
        path = node_get_path(node, buffer, name);

        req->mode = (req->mode & (~0777)) | 0664;
        res = mknod(path, req->mode, req->rdev); /* XXX perm?*/
        if (res < 0) {
            fuse_status(fuse, hdr->unique, -errno);
        } else {
            lookup_entry(fuse, node, name, hdr->unique);
        }
        return;
    }
    case FUSE_MKDIR: { /* mkdir_in, bytez[] -> entry_out */
        struct fuse_mkdir_in *req = data;
        struct fuse_entry_out out;
        char *path, buffer[PATH_BUFFER_SIZE];
        char *name = ((char*) data) + sizeof(*req);
        int res;

        TRACE("MKDIR %s @ %llx 0%o\n", name, hdr->nodeid, req->mode);
        path = node_get_path(node, buffer, name);

        req->mode = (req->mode & (~0777)) | 0775;
        res = mkdir(path, req->mode);
        if (res < 0) {
            fuse_status(fuse, hdr->unique, -errno);
        } else {
            lookup_entry(fuse, node, name, hdr->unique);
        }
        return;
    }
    case FUSE_UNLINK: { /* bytez[] -> */
        char *path, buffer[PATH_BUFFER_SIZE];
        int res;
        TRACE("UNLINK %s @ %llx\n", (char*) data, hdr->nodeid);
        path = node_get_path(node, buffer, (char*) data);
        res = unlink(path);
        fuse_status(fuse, hdr->unique, res ? -errno : 0);
        return;
    }
    case FUSE_RMDIR: { /* bytez[] -> */
        char *path, buffer[PATH_BUFFER_SIZE];
        int res;
        TRACE("RMDIR %s @ %llx\n", (char*) data, hdr->nodeid);
        path = node_get_path(node, buffer, (char*) data);
        res = rmdir(path);
        fuse_status(fuse, hdr->unique, res ? -errno : 0);
        return;
    }
    case FUSE_RENAME: { /* rename_in, oldname, newname ->  */
        struct fuse_rename_in *req = data;
        char *oldname = ((char*) data) + sizeof(*req);
        char *newname = oldname + strlen(oldname) + 1;
        char *oldpath, oldbuffer[PATH_BUFFER_SIZE];
        char *newpath, newbuffer[PATH_BUFFER_SIZE];
        struct node *target;
        struct node *newparent;
        int res;

        TRACE("RENAME %s->%s @ %llx\n", oldname, newname, hdr->nodeid);

        target = lookup_child_by_name(node, oldname);
        if (!target) {
            fuse_status(fuse, hdr->unique, -ENOENT);
            return;
        }
        oldpath = node_get_path(node, oldbuffer, oldname);

        newparent = lookup_by_inode(fuse, req->newdir);
        if (!newparent) {
            fuse_status(fuse, hdr->unique, -ENOENT);
            return;
        }
        if (newparent == node) {
            /* Special case for renaming a file where destination
             * is same path differing only by case.
             * In this case we don't want to look for a case insensitive match.
             * This allows commands like "mv foo FOO" to work as expected.
             */
            newpath = do_node_get_path(newparent, newbuffer, newname, NO_CASE_SENSITIVE_MATCH);
        } else {
            newpath = node_get_path(newparent, newbuffer, newname);
        }

        if (!remove_child(node, target->nid)) {
            ERROR("RENAME remove_child not found");
            fuse_status(fuse, hdr->unique, -ENOENT);
            return;
        }
        if (!rename_node(target, newname)) {
            fuse_status(fuse, hdr->unique, -ENOMEM);
            return;
        }
        add_node_to_parent(target, newparent);

        res = rename(oldpath, newpath);
        TRACE("RENAME result %d\n", res);

        fuse_status(fuse, hdr->unique, res ? -errno : 0);
        return;
    }
//    case FUSE_LINK:        
    case FUSE_OPEN: { /* open_in -> open_out */
        struct fuse_open_in *req = data;
        struct fuse_open_out out;
        char *path, buffer[PATH_BUFFER_SIZE];
        struct handle *h;

        h = malloc(sizeof(*h));
        if (!h) {
            fuse_status(fuse, hdr->unique, -ENOMEM);
            return;
        }

        path = node_get_path(node, buffer, 0);
        TRACE("OPEN %llx '%s' 0%o fh=%p\n", hdr->nodeid, path, req->flags, h);
        h->fd = open(path, req->flags);
        if (h->fd < 0) {
            ERROR("ERROR\n");
            fuse_status(fuse, hdr->unique, -errno);
            free(h);
            return;
        }
        out.fh = ptr_to_id(h);
        out.open_flags = 0;
        out.padding = 0;
        fuse_reply(fuse, hdr->unique, &out, sizeof(out));
        return;
    }
    case FUSE_READ: { /* read_in -> byte[] */
        char buffer[128 * 1024];
        struct fuse_read_in *req = data;
        struct handle *h = id_to_ptr(req->fh);
        int res;
        TRACE("READ %p(%d) %u@%llu\n", h, h->fd, req->size, req->offset);
        if (req->size > sizeof(buffer)) {
            fuse_status(fuse, hdr->unique, -EINVAL);
            return;
        }
        res = pread64(h->fd, buffer, req->size, req->offset);
        if (res < 0) {
            fuse_status(fuse, hdr->unique, -errno);
            return;
        }
        fuse_reply(fuse, hdr->unique, buffer, res);
        return;
    }
    case FUSE_WRITE: { /* write_in, byte[write_in.size] -> write_out */
        struct fuse_write_in *req = data;
        struct fuse_write_out out;
        struct handle *h = id_to_ptr(req->fh);
        int res;
        TRACE("WRITE %p(%d) %u@%llu\n", h, h->fd, req->size, req->offset);
        res = pwrite64(h->fd, ((char*) data) + sizeof(*req), req->size, req->offset);
        if (res < 0) {
            fuse_status(fuse, hdr->unique, -errno);
            return;
        }
        out.size = res;
        fuse_reply(fuse, hdr->unique, &out, sizeof(out));
        goto oops;
    }
    case FUSE_STATFS: { /* getattr_in -> attr_out */
        struct statfs stat;
        struct fuse_statfs_out out;
        int res;

        TRACE("STATFS\n");

        if (statfs(fuse->root.name, &stat)) {
            fuse_status(fuse, hdr->unique, -errno);
            return;
        }

        memset(&out, 0, sizeof(out));
        out.st.blocks = stat.f_blocks;
        out.st.bfree = stat.f_bfree;
        out.st.bavail = stat.f_bavail;
        out.st.files = stat.f_files;
        out.st.ffree = stat.f_ffree;
        out.st.bsize = stat.f_bsize;
        out.st.namelen = stat.f_namelen;
        out.st.frsize = stat.f_frsize;
        fuse_reply(fuse, hdr->unique, &out, sizeof(out));
        return;
    }
    case FUSE_RELEASE: { /* release_in -> */
        struct fuse_release_in *req = data;
        struct handle *h = id_to_ptr(req->fh);
        TRACE("RELEASE %p(%d)\n", h, h->fd);
        close(h->fd);
        free(h);
        fuse_status(fuse, hdr->unique, 0);
        return;
    }
//    case FUSE_FSYNC:
//    case FUSE_SETXATTR:
//    case FUSE_GETXATTR:
//    case FUSE_LISTXATTR:
//    case FUSE_REMOVEXATTR:
    case FUSE_FLUSH:
        fuse_status(fuse, hdr->unique, 0);
        return;
    case FUSE_OPENDIR: { /* open_in -> open_out */
        struct fuse_open_in *req = data;
        struct fuse_open_out out;
        char *path, buffer[PATH_BUFFER_SIZE];
        struct dirhandle *h;

        h = malloc(sizeof(*h));
        if (!h) {
            fuse_status(fuse, hdr->unique, -ENOMEM);
            return;
        }

        path = node_get_path(node, buffer, 0);
        TRACE("OPENDIR %llx '%s'\n", hdr->nodeid, path);
        h->d = opendir(path);
        if (h->d == 0) {
            ERROR("ERROR\n");
            fuse_status(fuse, hdr->unique, -errno);
            free(h);
            return;
        }
        out.fh = ptr_to_id(h);
        fuse_reply(fuse, hdr->unique, &out, sizeof(out));
        return;
    }
    case FUSE_READDIR: {
        struct fuse_read_in *req = data;
        char buffer[8192];
        struct fuse_dirent *fde = (struct fuse_dirent*) buffer;
        struct dirent *de;
        struct dirhandle *h = id_to_ptr(req->fh);
        TRACE("READDIR %p\n", h);
        if (req->offset == 0) {
            /* rewinddir() might have been called above us, so rewind here too */
            TRACE("calling rewinddir()\n");
            rewinddir(h->d);
        }
        de = readdir(h->d);
        if (!de) {
            fuse_status(fuse, hdr->unique, 0);
            return;
        }
        fde->ino = FUSE_UNKNOWN_INO;
        /* increment the offset so we can detect when rewinddir() seeks back to the beginning */
        fde->off = req->offset + 1;
        fde->type = de->d_type;
        fde->namelen = strlen(de->d_name);
        memcpy(fde->name, de->d_name, fde->namelen + 1);
        fuse_reply(fuse, hdr->unique, fde,
                   FUSE_DIRENT_ALIGN(sizeof(struct fuse_dirent) + fde->namelen));
        return;
    }
    case FUSE_RELEASEDIR: { /* release_in -> */
        struct fuse_release_in *req = data;
        struct dirhandle *h = id_to_ptr(req->fh);
        TRACE("RELEASEDIR %p\n",h);
        closedir(h->d);
        free(h);
        fuse_status(fuse, hdr->unique, 0);
        return;
    }
//    case FUSE_FSYNCDIR:
    case FUSE_INIT: { /* init_in -> init_out */
        struct fuse_init_in *req = data;
        struct fuse_init_out out;
        
        TRACE("INIT ver=%d.%d maxread=%d flags=%x\n",
                req->major, req->minor, req->max_readahead, req->flags);

        out.major = FUSE_KERNEL_VERSION;
        out.minor = FUSE_KERNEL_MINOR_VERSION;
        out.max_readahead = req->max_readahead;
        out.flags = FUSE_ATOMIC_O_TRUNC | FUSE_BIG_WRITES;
        out.max_background = 32;
        out.congestion_threshold = 32;
        out.max_write = 256 * 1024;

        fuse_reply(fuse, hdr->unique, &out, sizeof(out));
        return;
    }
    default: {
        struct fuse_out_header h;
        ERROR("NOTIMPL op=%d uniq=%llx nid=%llx\n",
                hdr->opcode, hdr->unique, hdr->nodeid);

        oops:
        h.len = sizeof(h);
        h.error = -ENOSYS;
        h.unique = hdr->unique;
        write(fuse->fd, &h, sizeof(h));
        break;
    }
    }   
}
Пример #16
0
struct inode *read_inode_1(unsigned int start_block, unsigned int offset)
{
	static squashfs_inode_header_1 header;
	long long start = sBlk.s.inode_table_start + start_block;
	int bytes = lookup_entry(inode_table_hash, start);
	char *block_ptr = inode_table + bytes + offset;
	static struct inode i;

	TRACE("read_inode: reading inode [%d:%d]\n", start_block,  offset);

	if(bytes == -1)
		EXIT_UNSQUASH("read_inode: inode table block %lld not found\n",
			 start); 

	if(swap) {
		squashfs_base_inode_header_1 sinode;
		memcpy(&sinode, block_ptr, sizeof(header.base));
		SQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode,
			sizeof(squashfs_base_inode_header_1));
	} else
		memcpy(&header.base, block_ptr, sizeof(header.base));

	i.uid = (uid_t) uid_table[(header.base.inode_type - 1) /
		SQUASHFS_TYPES * 16 + header.base.uid];
	if(header.base.inode_type == SQUASHFS_IPC_TYPE) {
		squashfs_ipc_inode_header_1 *inodep = &header.ipc;

		if(swap) {
			squashfs_ipc_inode_header_1 sinodep;
			memcpy(&sinodep, block_ptr, sizeof(sinodep));
			SQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);
		} else
			memcpy(inodep, block_ptr, sizeof(*inodep));

		if(inodep->type == SQUASHFS_SOCKET_TYPE) {
			i.mode = S_IFSOCK | header.base.mode;
			i.type = SQUASHFS_SOCKET_TYPE;
		} else {
			i.mode = S_IFIFO | header.base.mode;
			i.type = SQUASHFS_FIFO_TYPE;
		}
		i.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];
	} else {
		i.mode = lookup_type[(header.base.inode_type - 1) %
			SQUASHFS_TYPES + 1] | header.base.mode;
		i.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;
	}

	i.xattr = SQUASHFS_INVALID_XATTR;
	i.gid = header.base.guid == 15 ? i.uid :
		(uid_t) guid_table[header.base.guid];
	i.time = sBlk.s.mkfs_time;
	i.inode_number = inode_number ++;

	switch(i.type) {
		case SQUASHFS_DIR_TYPE: {
			squashfs_dir_inode_header_1 *inode = &header.dir;

			if(swap) {
				squashfs_dir_inode_header_1 sinode;
				memcpy(&sinode, block_ptr, sizeof(header.dir));
				SQUASHFS_SWAP_DIR_INODE_HEADER_1(inode,
					&sinode);
			} else
			memcpy(inode, block_ptr, sizeof(header.dir));

			i.data = inode->file_size;
			i.offset = inode->offset;
			i.start = inode->start_block;
			i.time = inode->mtime;
			break;
		}
		case SQUASHFS_FILE_TYPE: {
			squashfs_reg_inode_header_1 *inode = &header.reg;

			if(swap) {
				squashfs_reg_inode_header_1 sinode;
				memcpy(&sinode, block_ptr, sizeof(sinode));
				SQUASHFS_SWAP_REG_INODE_HEADER_1(inode,
					&sinode);
			} else
				memcpy(inode, block_ptr, sizeof(*inode));

			i.data = inode->file_size;
			i.time = inode->mtime;
			i.blocks = (inode->file_size + sBlk.s.block_size - 1) >>
				sBlk.s.block_log;
			i.start = inode->start_block;
			i.block_ptr = block_ptr + sizeof(*inode);
			i.fragment = 0;
			i.frag_bytes = 0;
			i.offset = 0;
			i.sparse = 0;
			break;
		}	
		case SQUASHFS_SYMLINK_TYPE: {
			squashfs_symlink_inode_header_1 *inodep =
				&header.symlink;

			if(swap) {
				squashfs_symlink_inode_header_1 sinodep;
				memcpy(&sinodep, block_ptr, sizeof(sinodep));
				SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep,
					&sinodep);
			} else
				memcpy(inodep, block_ptr, sizeof(*inodep));

			i.symlink = malloc(inodep->symlink_size + 1);
			if(i.symlink == NULL)
				EXIT_UNSQUASH("read_inode: failed to malloc "
					"symlink data\n");
			strncpy(i.symlink, block_ptr +
				sizeof(squashfs_symlink_inode_header_1),
				inodep->symlink_size);
			i.symlink[inodep->symlink_size] = '\0';
			i.data = inodep->symlink_size;
			break;
		}
 		case SQUASHFS_BLKDEV_TYPE:
	 	case SQUASHFS_CHRDEV_TYPE: {
			squashfs_dev_inode_header_1 *inodep = &header.dev;

			if(swap) {
				squashfs_dev_inode_header_1 sinodep;
				memcpy(&sinodep, block_ptr, sizeof(sinodep));
				SQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep,
					&sinodep);
			} else
				memcpy(inodep, block_ptr, sizeof(*inodep));

			i.data = inodep->rdev;
			break;
			}
		case SQUASHFS_FIFO_TYPE:
		case SQUASHFS_SOCKET_TYPE: {
			i.data = 0;
			break;
			}
		default:
			EXIT_UNSQUASH("Unknown inode type %d in "
				" read_inode_header_1!\n",
				header.base.inode_type);
	}
	return &i;
}
Пример #17
0
struct dir *squashfs_opendir_1(unsigned int block_start, unsigned int offset,
	struct inode **i)
{
	squashfs_dir_header_2 dirh;
	char buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1]
		__attribute__((aligned));
	squashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;
	long long start;
	int bytes;
	int dir_count, size;
	struct dir_ent *new_dir;
	struct dir *dir;

	TRACE("squashfs_opendir: inode start block %d, offset %d\n",
		block_start, offset);

	*i = s_ops.read_inode(block_start, offset);

	dir = malloc(sizeof(struct dir));
	if(dir == NULL)
		EXIT_UNSQUASH("squashfs_opendir: malloc failed!\n");

	dir->dir_count = 0;
	dir->cur_entry = 0;
	dir->mode = (*i)->mode;
	dir->uid = (*i)->uid;
	dir->guid = (*i)->gid;
	dir->mtime = (*i)->time;
	dir->xattr = (*i)->xattr;
	dir->dirs = NULL;

	if ((*i)->data == 0)
		/*
		 * if the directory is empty, skip the unnecessary
		 * lookup_entry, this fixes the corner case with
		 * completely empty filesystems where lookup_entry correctly
		 * returning -1 is incorrectly treated as an error
		 */
		return dir;
		
	start = sBlk.s.directory_table_start + (*i)->start;
	bytes = lookup_entry(directory_table_hash, start);
	if(bytes == -1)
		EXIT_UNSQUASH("squashfs_opendir: directory block %d not "
			"found!\n", block_start);

	bytes += (*i)->offset;
	size = (*i)->data + bytes;

	while(bytes < size) {			
		if(swap) {
			squashfs_dir_header_2 sdirh;
			memcpy(&sdirh, directory_table + bytes, sizeof(sdirh));
			SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
		} else
			memcpy(&dirh, directory_table + bytes, sizeof(dirh));
	
		dir_count = dirh.count + 1;
		TRACE("squashfs_opendir: Read directory header @ byte position "
			"%d, %d directory entries\n", bytes, dir_count);
		bytes += sizeof(dirh);

		/* dir_count should never be larger than 256 */
		if(dir_count > 256)
			goto corrupted;

		while(dir_count--) {
			if(swap) {
				squashfs_dir_entry_2 sdire;
				memcpy(&sdire, directory_table + bytes,
					sizeof(sdire));
				SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
			} else
				memcpy(dire, directory_table + bytes,
					sizeof(*dire));
			bytes += sizeof(*dire);

			/* size should never be larger than SQUASHFS_NAME_LEN */
			if(dire->size > SQUASHFS_NAME_LEN)
				goto corrupted;

			memcpy(dire->name, directory_table + bytes,
				dire->size + 1);
			dire->name[dire->size + 1] = '\0';
			TRACE("squashfs_opendir: directory entry %s, inode "
				"%d:%d, type %d\n", dire->name,
				dirh.start_block, dire->offset, dire->type);
			if((dir->dir_count % DIR_ENT_SIZE) == 0) {
				new_dir = realloc(dir->dirs, (dir->dir_count +
					DIR_ENT_SIZE) * sizeof(struct dir_ent));
				if(new_dir == NULL)
					EXIT_UNSQUASH("squashfs_opendir: "
						"realloc failed!\n");
				dir->dirs = new_dir;
			}
			strcpy(dir->dirs[dir->dir_count].name, dire->name);
			dir->dirs[dir->dir_count].start_block =
				dirh.start_block;
			dir->dirs[dir->dir_count].offset = dire->offset;
			dir->dirs[dir->dir_count].type = dire->type;
			dir->dir_count ++;
			bytes += dire->size + 1;
		}
	}

	return dir;

corrupted:
	free(dir->dirs);
	free(dir);
	return NULL;
}
Пример #18
0
struct dir *squashfs_opendir_3(unsigned int block_start, unsigned int offset,
	struct inode **i)
{
	squashfs_dir_header_3 dirh;
	char buffer[sizeof(squashfs_dir_entry_3) + SQUASHFS_NAME_LEN + 1];
	squashfs_dir_entry_3 *dire = (squashfs_dir_entry_3 *) buffer;
	long long start;
	int bytes;
	int dir_count, size;
	struct dir_ent *new_dir;
	struct dir *dir;

	TRACE("squashfs_opendir: inode start block %d, offset %d\n",
		block_start, offset);

	if((*i = s_ops.read_inode(block_start, offset)) == NULL) {
		ERROR("squashfs_opendir: failed to read directory inode %d\n",
			block_start);
		return NULL;
	}

	start = sBlk.directory_table_start + (*i)->start;
	bytes = lookup_entry(directory_table_hash, start);

	if(bytes == -1) {
		ERROR("squashfs_opendir: directory block %d not found!\n",
			block_start);
		return NULL;
	}

	bytes += (*i)->offset;
	size = (*i)->data + bytes - 3;

	if((dir = malloc(sizeof(struct dir))) == NULL) {
		ERROR("squashfs_opendir: malloc failed!\n");
		return NULL;
	}

	dir->dir_count = 0;
	dir->cur_entry = 0;
	dir->mode = (*i)->mode;
	dir->uid = (*i)->uid;
	dir->guid = (*i)->gid;
	dir->mtime = (*i)->time;
	dir->dirs = NULL;

	while(bytes < size) {			
		if(swap) {
			squashfs_dir_header_3 sdirh;
			memcpy(&sdirh, directory_table + bytes, sizeof(sdirh));
			SQUASHFS_SWAP_DIR_HEADER_3(&dirh, &sdirh);
		} else
			memcpy(&dirh, directory_table + bytes, sizeof(dirh));
	
		dir_count = dirh.count + 1;
		TRACE("squashfs_opendir: Read directory header @ byte position "
			"%d, %d directory entries\n", bytes, dir_count);
		bytes += sizeof(dirh);

		while(dir_count--) {
			if(swap) {
				squashfs_dir_entry_3 sdire;
				memcpy(&sdire, directory_table + bytes,
					sizeof(sdire));
				SQUASHFS_SWAP_DIR_ENTRY_3(dire, &sdire);
			} else
				memcpy(dire, directory_table + bytes,
					sizeof(*dire));
			bytes += sizeof(*dire);

			memcpy(dire->name, directory_table + bytes,
				dire->size + 1);
			dire->name[dire->size + 1] = '\0';
			TRACE("squashfs_opendir: directory entry %s, inode "
				"%d:%d, type %d\n", dire->name,
				dirh.start_block, dire->offset, dire->type);
			if((dir->dir_count % DIR_ENT_SIZE) == 0) {
				new_dir = realloc(dir->dirs, (dir->dir_count +
					DIR_ENT_SIZE) * sizeof(struct dir_ent));
				if(new_dir == NULL) {
					ERROR("squashfs_opendir: realloc "
						"failed!\n");
					free(dir->dirs);
					free(dir);
					return NULL;
				}
				dir->dirs = new_dir;
			}
			strcpy(dir->dirs[dir->dir_count].name, dire->name);
			dir->dirs[dir->dir_count].start_block =
				dirh.start_block;
			dir->dirs[dir->dir_count].offset = dire->offset;
			dir->dirs[dir->dir_count].type = dire->type;
			dir->dir_count ++;
			bytes += dire->size + 1;
		}
	}

	return dir;
}
Пример #19
0
static void scan_copyfiles(FILE *fichier, char *chaine)
{
    char *part;
    char *mpart;
    int i;
    pstring direc;
#ifdef DEBUGIT
    fprintf(stderr,"In scan_copyfiles Lookup up of %s\n",chaine);
#endif
    fprintf(stderr,"\nCopy the following files to your printer$ share location:\n");
    part=strtok(chaine,",");
    do {
        /* If the entry start with a @ then it's a file to copy
        else it's an entry refering to files to copy
        the main difference is when it's an entry
        you can have a directory to append before the file name
        */
        if (*part=='@') {
            if (strlen(files_to_copy) != 0)
                pstrcat(files_to_copy,",");
            pstrcat(files_to_copy,&part[1]);
            fprintf(stderr,"%s\n",&part[1]);
        } else {
            lookup_entry(fichier,part);
            i=0;
            pstrcpy(direc,"");
            while (*sub_dir[i][0]!='\0') {
#ifdef DEBUGIT
                fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]);
#endif
                if (strcmp(sub_dir[i][0],part)==0)
                    pstrcpy(direc,sub_dir[i][1]);
                i++;
            }
            i=0;
            while (*buffer[i]!='\0') {
                /*
                 * HP inf files have strange entries that this attempts to address
                 * Entries in the Copy sections normally have only a single file name
                 * on each line. I have seen the following format in various HP inf files:
                 *
                 * pscript.hlp =  pscript.hl_
                 * hpdcmon.dll,hpdcmon.dl_
                 * MSVCRT.DLL,MSVCRT.DL_,,32
                 * ctl3dv2.dll,ctl3dv2.dl_,ctl3dv2.tmp
                 *
                 * In the first 2 cases you want the first file name - in the last case
                 * you only want the last file name (at least that is what a Win95
                 * machine sent). In the third case you also want the first file name
                 * (detect by the last component being just a number ?).
                 * This may still be wrong but at least I get the same list
                 * of files as seen on a printer test page.
                 */
                part = strchr(buffer[i],'=');
                if (part) {
                    /*
                     * Case (1) eg. pscript.hlp =  pscript.hl_ - chop after the first name.
                     */

                    *part = '\0';

                    /*
                     * Now move back to the start and print that.
                     */

                    while (--part > buffer[i]) {
                        if ((*part == ' ') || (*part =='\t'))
                            *part = '\0';
                        else
                            break;
                    }
                } else {
                    part = strchr(buffer[i],',');
                    if (part) {
                        /*
                         * Cases (2-4)
                         */

                        if ((mpart = strrchr(part+1,','))!=NULL) {
                            /*
                             * Second ',' - case 3 or 4.
                             * Check if the last part is just a number,
                             * if so we need the first part.
                             */

                            char *endptr = NULL;
                            BOOL isnumber = False;

                            mpart++;
                            (void)strtol(mpart, &endptr, 10);

                            isnumber = ((endptr > mpart) && isdigit(*mpart));
                            if(!isnumber)
                                pstrcpy(buffer[i],mpart+1);
                            else
                                *part = '\0';
                        } else {
                            *part = '\0';
                        }
                        while (--part > buffer[i])
                            if ((*part == ' ') || (*part =='\t')) *part = '\0';
                            else break;
                    }
                }
                if (*buffer[i] != ';') {
                    if (strlen(files_to_copy) != 0)
                        pstrcat(files_to_copy,",");
                    pstrcat(files_to_copy,direc);
                    pstrcat(files_to_copy,buffer[i]);
                    fprintf(stderr,"%s%s\n",direc,buffer[i]);
                }
                i++;
            } /* end while */
        }
        part=strtok(NULL,",");
        if (part) {
            while( *part ==' ' && *part != '\0') {
                part++;
            }
        }
    } while (part!=NULL);
    fprintf(stderr,"\n");
}