void Log_Init(const char *filename) { time_t ltime; if (!filename) { return; } if (file_exists(filename)) { file_rotate(filename, 10); } logState.lock = mutex_alloc(); logState.f = fopen(filename, "a"); if (logState.f == NULL) { printf(LGPFX" Failed to create log file '%s'\n", filename); } file_chmod(filename, 0600); strncpy(logState.filePath, filename, sizeof logState.filePath); ltime = time(NULL); LogAlways(LGPFX" new log session: %s", asctime(localtime(<ime))); }
static int wallet_save_keys(struct wallet *wallet) { struct config *cfg; int res; int n; n = hashtable_getnumentries(wallet->hash_keys); Log(LGPFX" saving %u key%s in %sencrypted wallet %s.\n", n, n > 1 ? "s" : "", wallet->pass ? "encrypted" : "NON-", wallet->filename); cfg = config_create(); config_setint64(cfg, n, "numKeys"); if (wallet->pass) { char saltStr[80]; int64 count = 0; bool s; res = RAND_bytes(wallet->ckey->salt, sizeof wallet->ckey->salt); if (res != 1) { res = ERR_get_error(); Log(LGPFX" RAND_bytes failed: %d\n", res); goto exit; } str_snprintf_bytes(saltStr, sizeof saltStr, NULL, wallet->ckey->salt, sizeof wallet->ckey->salt); config_setstring(cfg, saltStr, "encryption.salt"); s = crypt_set_key_from_passphrase(wallet->pass, wallet->ckey, &count); ASSERT(s); ASSERT(count >= CRYPT_NUM_ITERATIONS_OLD); config_setint64(cfg, count, "encryption.numIterations"); } hashtable_for_each(wallet->hash_keys, wallet_save_key_cb, cfg); file_rotate(wallet->filename, 1); res = file_create(wallet->filename); if (res) { Log(LGPFX" failed to create file '%s': %s\n", wallet->filename, strerror(res)); goto exit; } res = file_chmod(wallet->filename, 0600); if (res) { Log(LGPFX" failed to chmod 0600 wallet.dat: %s\n", strerror(res)); goto exit; } res = config_write(cfg, wallet->filename); exit: config_free(cfg); return res; }
kern_return_t trivfs_S_file_chmod (struct trivfs_protid *cred, mach_port_t reply, mach_msg_type_name_t reply_type, mode_t mode) { /* Is this right? */ return cred ? file_chmod (cred->realnode, mode) : EOPNOTSUPP; }
static void chmod_file_in_list(FileView *view, int pos, const char *mode, const char *inv_mode, int recurse_dirs) { char path_buf[PATH_MAX]; get_full_path_at(view, pos, sizeof(path_buf), path_buf); file_chmod(path_buf, mode, inv_mode, recurse_dirs); }
static void chmod_file_in_list(FileView *view, int pos, const char *mode, const char *inv_mode, int recurse_dirs) { char *filename; char path_buf[PATH_MAX]; filename = view->dir_entry[pos].name; snprintf(path_buf, sizeof(path_buf), "%s/%s", view->curr_dir, filename); chosp(path_buf); file_chmod(path_buf, mode, inv_mode, recurse_dirs); }
int blockstore_init(struct config *config, struct blockstore **blockStore) { struct blockstore *bs; char *file; bool s; int res; int i; *blockStore = NULL; file = blockstore_get_filename(config); Log(LGPFX" Using headers at '%s.\n", file); if (!file_exists(file)) { Log(LGPFX" file '%s' does not exist. Creating..\n", file); res = file_create(file); if (res) { Warning(LGPFX" failed to create file: %s\n", strerror(res)); free(file); return res; } res = file_chmod(file, 0600); if (res != 0) { Warning(LGPFX" failed to chmod 0600 '%s': %s\n", file, strerror(res)); free(file); return res; } } bs = safe_calloc(1, sizeof *bs); bs->height = -1; bs->hash_blk = hashtable_create(); bs->hash_orphans = hashtable_create(); const struct block_cpt_entry_str *arrayStr; struct block_cpt_entry *array; int n; if (btc->testnet) { n = ARRAYSIZE(cpt_testnet); array = block_cpt_testnet; arrayStr = cpt_testnet; } else { n = ARRAYSIZE(cpt_main); array = block_cpt_main; arrayStr = cpt_main; } for (i = 0; i < n; i++) { array[i].height = arrayStr[i].height; s = uint256_from_str(arrayStr[i].hashStr, &array[i].hash); ASSERT(s); } memcpy(&bs->genesis_hash.data, &array[0].hash.data, sizeof bs->genesis_hash); Log(LGPFX" Genesis: %s\n", arrayStr[0].hashStr); res = blockset_open(bs, file); free(file); if (res != 0) { goto exit; } Log(LGPFX" loaded %d headers.\n", bs->height + 1); *blockStore = bs; return 0; exit: blockstore_exit(bs); return res; }
int txdb_open(struct config *config, char **errStr, struct txdb **out) { leveldb_iterator_t* iter; struct txdb *txdb; int res; txdb = safe_calloc(1, sizeof *txdb); txdb->hash_txo = hashtable_create(); /* index all interesting txos */ txdb->hash_tx = hashtable_create(); /* all TX brought to our attention */ txdb->path = txdb_get_db_path(config); txdb->tx_seq = 0; theTxdb = txdb; if (!file_exists(txdb->path)) { Log(LGPFX" txdb DB '%s' does not exist. Creating..\n", txdb->path); } res = txdb_open_db(txdb); if (res) { *errStr = "failed to open tx DB"; goto error; } res = file_chmod(txdb->path, 0700); if (res) { Log(LGPFX" Failed to chmod txdb to 0700: %s\n", strerror(res)); goto error; } *out = txdb; iter = leveldb_create_iterator(txdb->db, txdb->rd_opts); leveldb_iter_seek_to_first(iter); while (leveldb_iter_valid(iter) && btc->stop == 0) { const char *key; const char *val; size_t klen; size_t vlen; key = leveldb_iter_key(iter, &klen); val = leveldb_iter_value(iter, &vlen); Log(LGPFX" found entry \"%s\" klen=%zu vlen=%zu\n", key, klen, vlen); if (klen > 4 && strncmp(key, "/tx/", 4) == 0) { res = txdb_load_tx(txdb, key, klen, val, vlen); ASSERT(res == 0); } leveldb_iter_next(iter); } leveldb_iter_destroy(iter); txdb_export_tx_info(txdb); txdb_print_coins(txdb, 1); exit: return res; error: txdb_close(txdb); theTxdb = NULL; *out = NULL; goto exit; }
int main(int argc, char **argv) { if(argc == 1) { usage(); exit(1); } while((cret = getopt(argc,argv,"bwetvf:s:l:u: ")) != EOF) { switch(cret) { case 'f': /* Force factor */ x=atoi(optarg); if(x < 0) x=1; break; case 's': /* Size of files */ sz=atoi(optarg); if(optarg[strlen(optarg)-1]=='k' || optarg[strlen(optarg)-1]=='K') { sz = (1024 * atoi(optarg)); } if(optarg[strlen(optarg)-1]=='m' || optarg[strlen(optarg)-1]=='M') { sz = (1024 * 1024 * atoi(optarg)); } if(sz < 0) sz=1; break; case 'l': /* lower force value */ lower=atoi(optarg); range=1; if(lower < 0) lower=1; break; case 'v': /* version */ splash(); exit(0); break; case 'u': /* upper force value */ upper=atoi(optarg); range=1; if(upper < 0) upper=1; break; case 't': /* verbose */ verbose=1; break; case 'e': /* Excel */ excel=1; break; case 'b': /* Best */ best=1; break; case 'w': /* Worst */ worst=1; break; } } mbuffer=(char *)malloc(sz); memset(mbuffer,'a',sz); if(!excel) printf("\nFileop: File size is %d, Output is in Ops/sec. (A=Avg, B=Best, W=Worst)\n",sz); if(!verbose) { #ifdef Windows printf(" . %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n", "mkdir","rmdir","create","read","write","close","stat", "access","chmod","readdir","delete"," Total_files"); #else printf(" . %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n", "mkdir","rmdir","create","read","write","close","stat", "access","chmod","readdir","link ","unlink","delete", " Total_files"); #endif } if(x==0) x=1; if(range==0) lower=upper=x; for(i=lower; i<=upper; i++) { clear_stats(); x=i; /* * Dir Create test */ dir_create(x); if(verbose) { printf("mkdir: Dirs = %9lld ",stats[_STAT_DIR_CREATE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_DIR_CREATE].total_time); printf(" Avg mkdir(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time, stats[_STAT_DIR_CREATE].total_time/stats[_STAT_DIR_CREATE].counter); printf(" Best mkdir(s)/sec = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_CREATE].best,stats[_STAT_DIR_CREATE].best); printf(" Worst mkdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_CREATE].worst,stats[_STAT_DIR_CREATE].worst); } /* * Dir delete test */ dir_delete(x); if(verbose) { printf("rmdir: Dirs = %9lld ",stats[_STAT_DIR_DELETE].counter); printf("Total Time = %12.9f seconds\n",stats[_STAT_DIR_DELETE].total_time); printf(" Avg rmdir(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time, stats[_STAT_DIR_DELETE].total_time/stats[_STAT_DIR_DELETE].counter); printf(" Best rmdir(s)/sec = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_DELETE].best,stats[_STAT_DIR_DELETE].best); printf(" Worst rmdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_DELETE].worst,stats[_STAT_DIR_DELETE].worst); } /* * Create test */ file_create(x); if(verbose) { printf("create: Files = %9lld ",stats[_STAT_CREATE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_CREATE].total_time); printf(" Avg create(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time, stats[_STAT_CREATE].total_time/stats[_STAT_CREATE].counter); printf(" Best create(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_CREATE].best,stats[_STAT_CREATE].best); printf(" Worst create(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_CREATE].worst,stats[_STAT_CREATE].worst); printf("write: Files = %9lld ",stats[_STAT_WRITE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_WRITE].total_time); printf(" Avg write(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time, stats[_STAT_WRITE].total_time/stats[_STAT_WRITE].counter); printf(" Best write(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_WRITE].best,stats[_STAT_WRITE].best); printf(" Worst write(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_WRITE].worst,stats[_STAT_WRITE].worst); printf("close: Files = %9lld ",stats[_STAT_CLOSE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_CLOSE].total_time); printf(" Avg close(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time, stats[_STAT_CLOSE].total_time/stats[_STAT_CLOSE].counter); printf(" Best close(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_CLOSE].best,stats[_STAT_CLOSE].best); printf(" Worst close(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_CLOSE].worst,stats[_STAT_CLOSE].worst); } /* * Stat test */ file_stat(x); if(verbose) { printf("stat: Files = %9lld ",stats[_STAT_STAT].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_STAT].total_time); printf(" Avg stat(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time, stats[_STAT_STAT].total_time/stats[_STAT_STAT].counter); printf(" Best stat(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_STAT].best,stats[_STAT_STAT].best); printf(" Worst stat(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_STAT].worst,stats[_STAT_STAT].worst); } /* * Read test */ file_read(x); if(verbose) { printf("read: Files = %9lld ",stats[_STAT_READ].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_READ].total_time); printf(" Avg read(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_READ].counter/stats[_STAT_READ].total_time, stats[_STAT_READ].total_time/stats[_STAT_READ].counter); printf(" Best read(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_READ].best,stats[_STAT_READ].best); printf(" Worst read(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_READ].worst,stats[_STAT_READ].worst); } /* * Access test */ file_access(x); if(verbose) { printf("access: Files = %9lld ",stats[_STAT_ACCESS].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_ACCESS].total_time); printf(" Avg access(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time, stats[_STAT_ACCESS].total_time/stats[_STAT_ACCESS].counter); printf(" Best access(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_ACCESS].best,stats[_STAT_ACCESS].best); printf(" Worst access(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_ACCESS].worst,stats[_STAT_ACCESS].worst); } /* * Chmod test */ file_chmod(x); if(verbose) { printf("chmod: Files = %9lld ",stats[_STAT_CHMOD].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_CHMOD].total_time); printf(" Avg chmod(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time, stats[_STAT_CHMOD].total_time/stats[_STAT_CHMOD].counter); printf(" Best chmod(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_CHMOD].best,stats[_STAT_CHMOD].best); printf(" Worst chmod(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_CHMOD].worst,stats[_STAT_CHMOD].worst); } /* * readdir test */ file_readdir(x); if(verbose) { printf("readdir: Files = %9lld ",stats[_STAT_READDIR].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_READDIR].total_time); printf(" Avg readdir(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time, stats[_STAT_READDIR].total_time/stats[_STAT_READDIR].counter); printf(" Best readdir(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_READDIR].best,stats[_STAT_READDIR].best); printf(" Worst readdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_READDIR].worst,stats[_STAT_READDIR].worst); } #if !defined(Windows) /* * link test */ file_link(x); if(verbose) { printf("link: Files = %9lld ",stats[_STAT_LINK].counter); printf("Total Time = %12.9f seconds\n",stats[_STAT_LINK].total_time); printf(" Avg link(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time, stats[_STAT_LINK].total_time/stats[_STAT_LINK].counter); printf(" Best link(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_LINK].best,stats[_STAT_LINK].best); printf(" Worst link(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_LINK].worst,stats[_STAT_LINK].worst); } /* * unlink test */ file_unlink(x); if(verbose) { printf("unlink: Files = %9lld ",stats[_STAT_UNLINK].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_UNLINK].total_time); printf(" Avg unlink(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time, stats[_STAT_UNLINK].total_time/stats[_STAT_UNLINK].counter); printf(" Best unlink(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_UNLINK].best,stats[_STAT_UNLINK].best); printf(" Worst unlink(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_UNLINK].worst,stats[_STAT_UNLINK].worst); } #endif /* * Delete test */ file_delete(x); if(verbose) { printf("delete: Files = %9lld ",stats[_STAT_DELETE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_DELETE].total_time); printf(" Avg delete(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time, stats[_STAT_DELETE].total_time/stats[_STAT_DELETE].counter); printf(" Best delete(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_DELETE].best,stats[_STAT_DELETE].best); printf(" Worst delete(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_DELETE].worst,stats[_STAT_DELETE].worst); } if(!verbose) { printf("%c %4d %6.0f ",'A',x,stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time); printf("%6.0f ",stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time); printf("%6.0f ",stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time); printf("%6.0f ",stats[_STAT_READ].counter/stats[_STAT_READ].total_time); printf("%6.0f ",stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time); printf("%6.0f ",stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time); printf("%6.0f ",stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time); printf("%6.0f ",stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time); printf("%6.0f ",stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time); printf("%6.0f ",stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time); #ifndef Windows printf("%6.0f ",stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time); printf("%6.0f ",stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time); #endif printf("%6.0f ",stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time); printf("%12d ",x*x*x); printf("\n"); fflush(stdout); if(best) { printf("%c %4d %6.0f ",'B',x, 1/stats[_STAT_DIR_CREATE].best); printf("%6.0f ",1/stats[_STAT_DIR_DELETE].best); printf("%6.0f ",1/stats[_STAT_CREATE].best); printf("%6.0f ",1/stats[_STAT_READ].best); printf("%6.0f ",1/stats[_STAT_WRITE].best); printf("%6.0f ",1/stats[_STAT_CLOSE].best); printf("%6.0f ",1/stats[_STAT_STAT].best); printf("%6.0f ",1/stats[_STAT_ACCESS].best); printf("%6.0f ",1/stats[_STAT_CHMOD].best); printf("%6.0f ",1/stats[_STAT_READDIR].best); #ifndef Windows printf("%6.0f ",1/stats[_STAT_LINK].best); printf("%6.0f ",1/stats[_STAT_UNLINK].best); #endif printf("%6.0f ",1/stats[_STAT_DELETE].best); printf("%12d ",x*x*x); printf("\n"); fflush(stdout); } if(worst) { printf("%c %4d %6.0f ",'W',x, 1/stats[_STAT_DIR_CREATE].worst); printf("%6.0f ",1/stats[_STAT_DIR_DELETE].worst); printf("%6.0f ",1/stats[_STAT_CREATE].worst); printf("%6.0f ",1/stats[_STAT_READ].worst); printf("%6.0f ",1/stats[_STAT_WRITE].worst); printf("%6.0f ",1/stats[_STAT_CLOSE].worst); printf("%6.0f ",1/stats[_STAT_STAT].worst); printf("%6.0f ",1/stats[_STAT_ACCESS].worst); printf("%6.0f ",1/stats[_STAT_CHMOD].worst); printf("%6.0f ",1/stats[_STAT_READDIR].worst); #ifndef Windows printf("%6.0f ",1/stats[_STAT_LINK].worst); printf("%6.0f ",1/stats[_STAT_UNLINK].worst); #endif printf("%6.0f ",1/stats[_STAT_DELETE].worst); printf("%12d ",x*x*x); printf("\n"); fflush(stdout); } } } return(0); }