QString PowerStatus::getStat(const QString& stat)
{
    QFile statFile(stat);
    statFile.open(QIODevice::ReadOnly | QIODevice::Text);
    QTextStream in(&statFile);
    return in.readLine();
}
Example #2
0
uint8_t SDHashClass::appendFile(SDHFilehandle fh, uint8_t* data, SDHDataSize len) {
	if (data == NULL || len < 1) return SDH_ERR_INVALID_ARGUMENT;

	FileInfo finfo;
	SDHAddress seg0addr;
	uint8_t ret = statFile(fh, &finfo, &seg0addr);
	if (ret != SDH_OK) return ret;

	// bring the hash 'up to date'
	for(SDHSegmentCount cnt = 0; cnt < finfo.segments_count; ++cnt) {
		fh = _incHash(fh);
	}

	SDHDataSize seg_len;
	do {
		seg_len = min(kSDHashSegmentDataSize, len);
		SDHAddress seg_addr = _foldHash(fh);

		ret = findSeg(0, &seg_addr);
		if (ret == SDH_ERR_FILE_NOT_FOUND) {
			ret = _writeSegment(seg0addr, seg_addr, data, seg_len);
			if (ret != SDH_OK) return ret;

			len -= seg_len;
			data += seg_len;
			fh = _incHash(fh);
			finfo.segments_count += 1;
		} else return ret;
	} while (len > 0);

	_updateSeg0SegmentsCount(seg0addr, finfo.segments_count);
	
	return SDH_OK;
}
Example #3
0
int main(int argc, char **argv)
{
    int ret = EXIT_SUCCESS, result;

    /* Verify command-line arguments. */
    if (argc <= 1)
    {
	printf("uso: %s FICHERO ...\r\n",
		argv[0]);
	return EXIT_FAILURE;
    }    
    /* Perform a stat for each file. */
    for (int i = 0; i < argc - 1; i++)
    {
	/* Stat the file immediately. */
	result = statFile(argv[0], argv[i + 1]);
	
	/* Update exit status, if needed. */
	if (result > ret)
	{
	    ret = result;
	}
    }    
    /* Success. */
    return ret;
}
Example #4
0
/**
 * @fn childrenPids
 */
QList<Q_PID> QueuedProcess::childrenPids() const
{
    QStringList allDirectories
        = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
    QStringList directories = allDirectories.filter(QRegExp("(\\d+)"));

    QList<Q_PID> pids
        = std::accumulate(directories.cbegin(), directories.cend(), QList<Q_PID>(),
                          [this](QList<Q_PID> &list, const QString &dir) {
                              QFile statFile(QString("/proc/%1/stat").arg(dir));
                              if (!statFile.open(QIODevice::ReadOnly | QIODevice::Text))
                                  return list;

                              QString output = statFile.readAll();
                              output.remove(QRegExp("\\d+ \\(.*\\) . "));
                              Q_PID ppid = output.split(' ').first().toLongLong();
                              if (ppid == pid())
                                  list.append(dir.toLongLong());

                              statFile.close();

                              return list;
                          });

    return pids;
}
Example #5
0
uint8_t SDHashClass::truncateFile(SDHFilehandle fh, SDHSegmentCount count) {
	FileInfo finfo;
	SDHAddress seg0addr;
	uint8_t ret = statFile(fh, &finfo, &seg0addr);
	if (ret != SDH_OK) return ret;

	if (count > finfo.segments_count) {
		return SDH_ERR_INVALID_ARGUMENT;
	}
	
	while (count) {
		SDHAddress seg_addr;
		finfo.segments_count-=1;
		ret = findSeg(fh, finfo.segments_count, &seg_addr);
		if (ret != SDH_OK) return ret;
		
		uint8_t ret = zero(seg_addr, 1);
		if (ret != SDH_OK) return ret;

		count-=1;
	}
	
	// update segments count
	return _updateSeg0SegmentsCount(seg0addr, finfo.segments_count);
}
bool getFileModificationTime(const String& path, time_t& result)
{
    struct _stat64 st;
    if (!statFile(path, st))
        return false;
    result = st.st_mtime;
    return true;
}
bool getFileSize(const String& path, long long& result)
{
    struct _stat64 sb;
    if (!statFile(path, sb))
        return false;
    result = sb.st_size;
    return true;
}
Example #8
0
uint8_t SDHashClass::createFile(SDHFilehandle fh, const char *filename, uint8_t *data, SDHDataSize len) {
	SDHAddress addr;
	if (statFile(fh, NULL, &addr) == SDH_ERR_FILE_NOT_FOUND) {
		Serial_print("addr=");
		Serial_println(addr);

		uint8_t namelen = strlen(filename);
		char name_padding = kSDHashMaxFilenameLength - namelen;
		if (name_padding <= 0) return SDH_ERR_FILENAME;
		name_padding+=1;

		if(!_card.writeStart(addr, 1)) return SDH_ERR_SD;
		
		uint8_t ofs = 0;
		uint8_t type = kSDHashSegment0;

		if(!_card.writeData(&type, sizeof type, ofs)) return SDH_ERR_SD;
		ofs+= sizeof type;

		if(!_card.writeData((uint8_t*)&fh, sizeof fh, ofs)) return SDH_ERR_SD;
		ofs += sizeof fh;

		uint16_t seg_count = _BSWAP16(1);
		if(!_card.writeData((uint8_t*)&seg_count, sizeof seg_count, ofs)) return SDH_ERR_SD;
		ofs += sizeof seg_count;

		if(!_card.writeData((uint8_t*)filename, namelen, ofs)) return SDH_ERR_SD;
		ofs += namelen;

		for(uint8_t cnt = 0; cnt < name_padding; ++cnt) {
			if(!_card.writeData((uint8_t*)&name_padding, sizeof name_padding, ofs)) return SDH_ERR_SD;
			ofs += sizeof name_padding;
		}
		
		if(!_card.writeDataPadding(512 - ofs)) return SDH_ERR_SD;
		
		if(!_card.writeStop()) return SDH_ERR_SD;

#ifdef LOGGING_ENABLED
		if (namelen >=kSDHashHiddenFilenamePrefixLen) {
			if (memcmp(filename, kSDHashHiddenFilenamePrefix, kSDHashHiddenFilenamePrefixLen)) {
				uint8_t ret = _appendLog(kSDHashLogCreate, addr);
				if (ret != SDH_OK) return ret;
			}
		}
#endif
		if (data && len) return appendFile(fh, data, len); 

		return SDH_OK;
	}
	else return SDH_ERR_FILE_EXISTS;
}
Example #9
0
uint8_t SDHashClass::replaceSegment(SDHFilehandle fh, uint16_t segNumber, uint8_t *data, SDHDataSize len) {
	if (segNumber == 0) return SDH_ERR_INVALID_ARGUMENT;

	SDHAddress seg_addr;
	uint8_t ret = findSeg(fh, segNumber, &seg_addr);
	if (ret == SDH_OK) {
		SDHAddress seg0addr;
		ret = statFile(fh, NULL, &seg0addr);
		if (ret == SDH_OK) {
			return _writeSegment(seg0addr, seg_addr, data, len);
		} else return ret;
	} else return ret;
}
Example #10
0
uint8_t SDHashClass::readFile(SDHFilehandle fh, uint32_t offset, uint8_t *dest, uint16_t *len) {
	FileInfo finfo;
	SDHAddress seg0addr;
	uint8_t ret;

	ret = statFile(fh, &finfo, &seg0addr);
	if (ret != SDH_OK) return ret;
	
	// the first segment doesn't hold data, so skip it
	for (finfo.segments_count-=1; finfo.segments_count; finfo.segments_count-=1) {
		fh = _incHash(fh);
		SDHAddress addr = _foldHash(fh);

		ret = findSeg(seg0addr, &addr);
		if (ret == SDH_OK) {
			SegmentInfo sinfo;
			ret = statSeg(addr, &sinfo);
			if (ret != SDH_OK) return ret;

			if (offset > sinfo.length) {
				// offset is past this segment, break out
				// and do the next segment
				offset -= sinfo.length;
			} else {
				// offset is inside this segment, so do a read
				// keeping in mind to skip the metadata
				uint16_t bytesRead = min(sinfo.length-offset, *len);
				if(!_card.readData(addr, kSDHashSegmentMetaSize+offset, bytesRead, dest)) return SDH_ERR_SD;
				if (bytesRead < *len) {
					// reading this segment wasn't enough to fill dest.
					// We need to read into one or more subsequent
					// segments, and always at their offset 0
					dest += bytesRead;
					*len -= bytesRead;
					offset = 0;
				} else {
					// we fulfilled the requirements of len,
					// nothing left to do
					*len = 0;
					return SDH_OK;
				}
			}
		} else if (ret == SDH_ERR_FILE_NOT_FOUND) return SDH_ERR_MISSIG_SEGMENT;
		else return ret;
	}

	return SDH_OK;
}
Example #11
0
uint8_t SDHashClass::findSeg(SDHFilehandle fh, uint16_t segmentNumber, SDHAddress *addr) {
	uint8_t ret = statFile(fh, NULL, addr);
	if (ret == SDH_OK) {
		if (segmentNumber == 0) SDH_OK;
		else {
			SDHAddress seg0addr = *addr;
			while(segmentNumber) {
				fh = _incHash(fh);
				segmentNumber -= 1;
			}

			*addr = _foldHash(fh);
			return findSeg(seg0addr, addr);
		}
	} else return ret;
}
Example #12
0
uint8_t SDHashClass::deleteFile(SDHFilehandle fh) {
	FileInfo finfo;
	SDHAddress seg0addr;
	uint8_t type[1] = {kSDHashFreeSegment};

	uint8_t ret = statFile(fh, &finfo, &seg0addr);
	if (ret != SDH_OK) return ret;

#ifdef LOGGING_ENABLED	
	// check to see if this is a hidden file
	uint8_t prefix[kSDHashHiddenFilenamePrefixLen];
	if (!_card.readData(seg0addr, kSDHashSegment0MetaHeaderSize,sizeof prefix, prefix)) {
		return SDH_ERR_SD;
	}

	if (memcmp(prefix, kSDHashHiddenFilenamePrefix, sizeof prefix)) {
		// if it ISN'T then append operation to the log
		ret = _appendLog(kSDHashLogDelete, seg0addr);
		if (ret != SDH_OK) return ret;
	}
#endif
	if (!_card.writeBlock(seg0addr, type, sizeof type)) {
		return SDH_ERR_SD;
	}

	finfo.segments_count-=1;

	SDHAddress seg_addr;
	while(finfo.segments_count) {
		fh = _incHash(fh);
		seg_addr = _foldHash(fh);
		ret = findSeg(seg0addr, &seg_addr);

		if (ret == SDH_OK) {
///			Serial_print("addr=");
///			Serial_println(seg_addr);
			if (!_card.writeBlock(seg_addr, type, sizeof type)) return SDH_ERR_SD;
		}
		// if a segment isn't found, don't stop. Otherwise a single
		// missing segment could lead to a whole bunch of zombie ones
		else if (ret != SDH_ERR_FILE_NOT_FOUND) return ret;

		finfo.segments_count-=1;
	}

	return SDH_OK;
}
void StatFile(int fd){

	struct fileStat* buf = (struct fileStat*)malloc(sizeof(struct fileStat));
	
	statFile(fd, buf);
	                //printing the info for the file
	                printf("\nfilesize is %Zu\n", buf->file_size);
	                printf("creation time: %s\n", buf->ctime);
					char atime[30], mtime[30];
					struct tm* timeinfo;
					timeinfo = localtime(&(buf->access_time));
					strftime(atime, 30, "%b %d %H:%M", timeinfo);
					printf("access time: %s\n", atime);
    
					timeinfo = localtime(&(buf->mod_time));
					strftime(mtime, 30, "%b %d %H:%M", timeinfo);
					printf("modi time: %s\n", mtime);
}
Example #14
0
void
gtBaseOpts::processConfigFile (const std::string& configFilename,
                               const bpo::options_description& desc,
                               bpo::variables_map &vm)
{
   if (statFile (configFilename) != 0)
   {
      commandLineError ("unable to open config file '" + configFilename + "'.");
   }

   std::ifstream inputFile (configFilename.c_str());

   if (!inputFile)
   {
      commandLineError ("unable to open config file '" + configFilename + "'.");
   }

   bpo::store (bpo::parse_config_file (inputFile, desc), vm);
}
Example #15
0
int64_t fgetsize(const char* fileName) {
    
    if (!fileName) return 0;
    
    struct stat st;
    memset(&st, 0, sizeof(struct stat));
    if (statFile(fileName, &st) < 0) {
        return 0;
    }
    return st.st_size;

// --old implementation--
//    if (fileName) {
//        FILE* f = fileOpen(fileName, "rb");
//        if (f) {
//            size_t size = fgetsize(f);
//            fclose(f);
//            return size;
//        }
//    }
//    return 0;
}
Example #16
0
void MCpuMonitorPrivate::getCpuUsageInformation(unsigned long &total, unsigned long &idle)
{
    QFile statFile("/proc/stat");

    if (statFile.exists() && statFile.open(QIODevice::ReadOnly)) {
        char buf[256];
        QStringList l;
        unsigned long sum = 0;
        unsigned long tmp;

        qint64 readBytes = statFile.readLine(buf, 256);
        if (readBytes > 0)
            l = QString::fromAscii(buf).split(' ');

        int idx = 0;
        QStringList::const_iterator end = l.constEnd();
        for (QStringList::const_iterator i = l.constBegin(); i != end; ++i) {
            if (!i->isEmpty()) {
                if (idx) {
                    bool success = true;

                    tmp = i->toULong(&success);
                    if (success) {
                        sum += tmp;

                        if (idx == 4)
                            idle = tmp;
                    }
                }

                idx++;
            }
        }

        total = sum;
    }
}
Example #17
0
bool SimpleRunoff::run()
{
	setOutflowType(ofAllSides);

	size_t nSizeX = 20;
	size_t nSizeY = 20;
	double pixelSize = 10;
	double slope = 1.0;
	double elevation = 100;
	StatFile statFile("statfile");
	
	DblRasterMx terrain;
	// init terrain: let an 1 pixel width edge at the boundary of the terrain
	// to collect the rain
	mapattr(nSizeY+2,nSizeX+2,pixelSize,0.0, terrain);
	for (size_t i = 1; i < nSizeX; i++){
		for (size_t j = 1; j <= nSizeY; j++){
			terrain(i,j)=elevation + (i+j)*slope;	
		}
	}

	IntRasterMx terrain_pixel_types;
	find_special_points(terrain, ridge | peak | col | channel, terrain_pixel_types);
	MultiflowDMatrix  mxMLDD;
	multiflowLDD( 1.0, terrain, mxMLDD, true);

	MultiflowDMatrix  mxMultiflowAngles;
	multiflowAngles(terrain, mxMultiflowAngles,true);

	//legyyen rain intesity
	double rainSpeed = pixelSize/10000; // [length_unit/time_unit]
	double amount_of_rain = pixelSize/100; // [length_unit]
	double accumulated_rain = 0.0; //[length_unit]
	double iteration_time = 1.0; // [time_unit]
	
	DblRasterMx mxRain;
	mapattr(nSizeY+2,nSizeX+2,pixelSize,0.0, mxRain);

	// legyen mxFlowDepth
	DblRasterMx mxFluid;
	mapattr(nSizeY+2,nSizeX+2,pixelSize,0.0, mxFluid);

	double velocity_coefficent = pixelSize*pixelSize;

	double rain_full_volume = amount_of_rain * pixelSize * pixelSize * nSizeX * nSizeY;
	while (true) {
		
		double rain = iteration_time * rainSpeed;
		rain = min(rain, amount_of_rain - accumulated_rain);
		
		if (rain > 0.0) {
			for (size_t i = 1; i <= nSizeY; i++){
				for (size_t j = 1; j <= nSizeX; j++){
					mxRain(i,j)=rain;	
				}
			}
			mxFluid = mxFluid + mxRain;
			accumulated_rain += rain;
		}
		
		MultiflowDMatrix flux_distribution;
		compute_flux_distribution(mxMLDD, mxFluid, flux_distribution);

		MultiflowDMatrix velocity_mldd;
		double time_interval = compute_velocity_mldd(flux_distribution, mxMultiflowAngles, velocity_coefficent,  velocity_mldd);

		MultiflowDMatrix mxOutflowFlux;
		compute_outflow_flux_mldd( velocity_mldd, flux_distribution, time_interval,mxOutflowFlux);

		DblRasterMx mxInFlow;
		DblRasterMx mxOutFlow;
		compute_material_movement(mxOutflowFlux,mxInFlow, mxOutFlow);

		mxFluid = mxFluid - mxOutFlow + mxInFlow;

		double fluid_outside_of_terrain = 0.0;

		for (size_t i = 0; i < nSizeX+2; ++i) {
			fluid_outside_of_terrain +=  mxFluid(0, i);
			fluid_outside_of_terrain += mxFluid(nSizeY+1, i);
		}

		for (size_t i = 1; i <= nSizeY; ++i) {
			fluid_outside_of_terrain +=  mxFluid(i, 0);
			fluid_outside_of_terrain += mxFluid(i, nSizeX + 1);
		}
		fluid_outside_of_terrain*= pixelSize*pixelSize;
		std::cout << "Fluid outside:" << fluid_outside_of_terrain << "/" << rain_full_volume << std::endl;

		/*
		if ( fluid_outside_of_terrain >=rain_full_volume - DoubleUtil::sDeltaD3)
			break;
			*/
		
	}

	return true;
}
bool fileExists(const String& path) 
{
    struct _stat64 st;
    return statFile(path, st);
}
Example #19
0
void RSPReader::ReadForStatistics(unsigned beamletCount)
{
	long unsigned timesteps = TimeStepCount(beamletCount);
	long unsigned stepSize = 1024;
	std::vector<BeamletStatistics>
		statistics(beamletCount),
		timeStartStatistics(beamletCount);

	std::vector<std::ofstream *> statFile(beamletCount);
	for(unsigned i=0;i<beamletCount;++i)
	{
		std::ostringstream str;
		str << "rsp-statistics" << i << ".txt";
		statFile[i] = new std::ofstream(str.str().c_str());
	}

	double startTime = -1.0, periodStartTime = -1.0;
	
	for(unsigned long timestepIndex=0;timestepIndex<timesteps;timestepIndex += stepSize)
	{
		//Read the data
		unsigned long end = timestepIndex+stepSize;
		if(end > timesteps) end = timesteps;
		std::pair<TimeFrequencyData,TimeFrequencyMetaDataPtr> dataPair = ReadAllBeamlets(timestepIndex, end, beamletCount);
		const TimeFrequencyData &data = dataPair.first;
		if(startTime == -1.0) {
			startTime = dataPair.second->ObservationTimes()[0];
			periodStartTime = startTime;
		}

		//Count the statistics
		for(unsigned imageIndex=0;imageIndex < data.ImageCount();++imageIndex)
		{
			Image2DCPtr image = data.GetImage(imageIndex);
			for(unsigned y=0;y<image->Height();++y) {
				for(unsigned x=0;x<image->Width();++x) {
					int value = (int) image->Value(x, y);
					if(value < 0) {
						value = -value;
						++(statistics[y].bitUseCount[15]);
					}
					unsigned highestBit = (value!=0) ? 1 : 0;
					for(unsigned bit=0;bit<15;++bit) {
						if((value & (2<<bit)) != 0) {
							highestBit = bit+1;
						}
					}
					for(unsigned bit=0;bit<highestBit;++bit)
						++(statistics[y].bitUseCount[bit]);
					++(statistics[y].totalCount);
				}
			}
		}
		if((timestepIndex/stepSize)%100000==0 || timestepIndex+stepSize>=timesteps)
		{
			for(unsigned i=0;i<beamletCount;++i)
			{
				Logger::Info << "Beamlet index " << i << ":\n";
				statistics[i].Print();
			}
		}
		if((dataPair.second->ObservationTimes()[0] - periodStartTime) > 60.0)
		{
			Logger::Debug << "Processed 1 minute of data (" << (dataPair.second->ObservationTimes()[0] - startTime) << "s)\n";
			for(unsigned i=0;i<beamletCount;++i)
			{
				(*statFile[i])
					<< (periodStartTime - startTime) << '\t'
					<< (statistics[i].totalCount - timeStartStatistics[i].totalCount);
				statistics[i].totalCount = timeStartStatistics[i].totalCount;
				for(unsigned bit=0;bit<15;++bit)
				{
					(*statFile[i]) << '\t' << (statistics[i].bitUseCount[bit] - timeStartStatistics[i].bitUseCount[bit]);
					timeStartStatistics[i].bitUseCount[bit] = statistics[i].bitUseCount[bit];
				}
				(*statFile[i]) << '\n';
			}

			periodStartTime = dataPair.second->ObservationTimes()[0];
		}
	}
	
	for(unsigned i=0;i<beamletCount;++i)
	{
		Logger::Info << "Beamlet index " << i << ":\n";
		statistics[i].Print();
		delete statFile[i];
	}
}
Example #20
0
void
gtBaseOpts::parse (int ac, char **av)
{
    bool haveRestrictConfigFile = !statFile (m_sys_restrict_cfg_file.c_str ());
    bool haveDefaultConfigFile = !statFile (m_sys_cfg_file.c_str ());
    bool haveUserConfigFile = false;

    try
    {
        add_options ();
        add_positionals ();

        bpo::command_line_parser parser (ac, av);
        parser.options (m_all_desc);
        parser.positional (m_pos);

        bpo::variables_map cli_vm; // CLI and non-restricted Config File options.
        bpo::variables_map res_vm; // Restricted Config File options.

        bpo::store (parser.run(), cli_vm);

        if (cli_vm.count (OPT_VERBOSE))
            m_haveVerboseOnCli = true;

        if (cli_vm.count (OPT_CFG_FILE))
            haveUserConfigFile = true;

        if (haveRestrictConfigFile)
            processConfigFile (m_sys_restrict_cfg_file, m_cfg_desc, res_vm);

        // Store config file variables on cli variables map
        if (haveRestrictConfigFile &&
            res_vm.count (OPT_NO_USER_CFG_FILE))
        {
            // Restricted config disallows user-supplied config file
            if (haveUserConfigFile)
                commandLineError ("Restricted configuration file disallows the "
                                  "use of the '" OPT_CFG_FILE "' option.");

            if (haveDefaultConfigFile)
                processConfigFile (m_sys_cfg_file, m_cfg_desc, cli_vm);
        }
        else
        {
            // Prefer user-supplied config file over default config file
            if (haveUserConfigFile)
            {
                std::string cfgPath = cli_vm[OPT_CFG_FILE].as<std::string>();
                processConfigFile (cfgPath, m_cfg_desc, cli_vm);
            }
            else if (haveDefaultConfigFile)
            {
                processConfigFile (m_sys_cfg_file, m_cfg_desc, cli_vm);
            }
        }

        if (haveRestrictConfigFile)
        {
            processConfigFile (m_sys_restrict_cfg_file, m_cfg_desc, cli_vm);
            checkForIllegalOverrides(res_vm, cli_vm);
        }
        // This call signals that the variables_map is now "finalized"
        // and calls notifiers to set variables to option values
        // (which we don't currently use)
        bpo::notify (cli_vm);

        m_vm = cli_vm;
    }
    catch (bpo::error &e)
    {
        std::ostringstream msg ("Options Error: ");
        msg << e.what();
        commandLineError (msg.str());
    }

    if (m_vm.count (OPT_HELP))
        displayHelp ();

    if (m_vm.count (OPT_VERSION))
        displayVersion ();

    processOptions ();

//    log_options_used ();
}
Example #21
0
uint8_t SDHashClass::begin() {
	_validCard = false;
	pinMode(10, OUTPUT); 
	_card.init();

	// stop any reads and writes that were in progress
	// when serial monitor started/stopped, or if we got
	// reset while the SD card didn't
	_card.writeStop();
	_card.readEnd();

	if (_getHashInfo()) {
		_validCard = true;
		Serial_print("found SDHash, version=");
		Serial_print(_hashInfo.version, DEC);
		Serial_print(" buckets=");
		Serial_println(_hashInfo.buckets);

		// make sure our buckets count is smaller than cardsize
		// otherwise things are going to go haywire
		if (_hashInfo.buckets > _card.cardSize()) {
			Serial_println("card isn't big enough");
			return SDH_ERR_CARD;
		}
#ifdef LOGGING_ENABLED
		if (statFile(kSDHashLogFilenameHash, NULL, NULL) == SDH_ERR_FILE_NOT_FOUND) {
			return SDHash.createFile(kSDHashLogFilenameHash, kSDHashLogFilename);
		}
#endif
		return SDH_OK;
	} else {
		_hashInfo.version = 1;
		_hashInfo.buckets = _card.cardSize();

		if (_hashInfo.buckets) {
			uint8_t header[kSDHashHeaderSize];
			memcpy(header, kSDHashMagic, sizeof kSDHashMagic);
			header[sizeof kSDHashMagic] = _hashInfo.version;

			_hashInfo.buckets = _BSWAP32(_hashInfo.buckets);
			memcpy(header + sizeof kSDHashMagic + 1, &_hashInfo.buckets, sizeof _hashInfo.buckets);

			if (_card.writeBlock(0, header, sizeof header)) {
				Serial_println("card marked as SDHash");
				_validCard = true;
			} else {
				Serial_print("failed to write header=0x");
				Serial_println(_card.errorCode(), HEX);
				return SDH_ERR_SD;
			}
#ifdef LOGGING_ENABLED
			SDHash.deleteFile(kSDHashLogFilenameHash);
			return SDHash.createFile(kSDHashLogFilenameHash, kSDHashLogFilename);
#else
			return SDH_OK;
#endif
		} else {
			Serial_println("card has no buckets?");
			return SDH_ERR_CARD;
		}
	}
}