int main( int argc, char *argv[]) { int c; int error; char *fsname; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; dm_attrname_t dmattr; size_t bufsz = 65536; dm_attrname_t *dmattrp = NULL; int verbose = V_PRINT; Progname = argv[0]; memset(&dmattr, 0, sizeof(dmattr)); while ((c = getopt(argc, argv, "a:b:vq")) != EOF) { switch (c) { case 'a': if (strlen(optarg) > (DM_ATTR_NAME_SIZE-1)){ printf("Arg for -a too long\n"); exit(1); } strcpy((char*)dmattr.an_chars, optarg); dmattrp = &dmattr; break; case 'b': bufsz = atoi(optarg); break; case 'v': verbose |= V_VERBOSE; break; case 'q': verbose &= ~V_PRINT; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can scan the filesystem */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Get the attributes of all files in the filesystem */ error = scan_fs(sid, fs_hanp, fs_hlen, dmattrp, bufsz, verbose); if (error) exit(1); /* * We're done, so we can shut down our session. */ if (dm_destroy_session(sid) == -1) { errno_msg("Can't close session"); exit(1); } return(0); }
int main( int argc, char *argv[]) { int c; int error; dm_off_t size; char *fsname; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; char *sizep = "0"; Progname = argv[0]; size = 0; while ((c = getopt(argc, argv, "s:")) != EOF) { switch (c) { case 's': sizep = optarg; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } /* * Verify the input size string is legit */ error = verify_size(sizep, &size); if (error) exit(1); fsname = argv[optind]; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can scan the filesystem */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Get the attributes of all files in the filesystem */ error = scan_fs(sid, fs_hanp, fs_hlen, size); if (error) exit(1); /* * We're done, so we can shut down our session. */ if (dm_destroy_session(sid) == -1) { errno_msg("Can't close session"); exit(1); } return(0); }
void FileStatsWorker::get_stats(bool need_all_files, bool split_by_owner_dialog_id, Promise<FileStats> promise) { if (!G()->parameters().use_chat_info_db) { split_by_owner_dialog_id = false; } if (!split_by_owner_dialog_id) { FileStats file_stats; file_stats.need_all_files = need_all_files; auto start = Time::now(); scan_fs([&](FsFileInfo &fs_info) { FullFileInfo info; info.file_type = fs_info.file_type; info.path = std::move(fs_info.path); info.size = fs_info.size; info.atime_nsec = fs_info.atime_nsec; info.mtime_nsec = fs_info.mtime_nsec; file_stats.add(std::move(info)); }); auto passed = Time::now() - start; LOG_IF(INFO, passed > 0.5) << "Get file stats took: " << format::as_time(passed); promise.set_value(std::move(file_stats)); } else { auto start = Time::now(); std::vector<FullFileInfo> full_infos; scan_fs([&](FsFileInfo &fs_info) { FullFileInfo info; info.file_type = fs_info.file_type; info.path = std::move(fs_info.path); info.size = fs_info.size; info.atime_nsec = fs_info.atime_nsec; info.mtime_nsec = fs_info.mtime_nsec; // LOG(INFO) << "Found file of size " << info.size << " at " << info.path; full_infos.push_back(std::move(info)); }); std::unordered_map<size_t, size_t> hash_to_pos; size_t pos = 0; for (auto &full_info : full_infos) { hash_to_pos[std::hash<std::string>()(full_info.path)] = pos; pos++; } scan_db([&](DbFileInfo &db_info) { auto it = hash_to_pos.find(std::hash<std::string>()(db_info.path)); if (it == hash_to_pos.end()) { return; } // LOG(INFO) << "Match! " << db_info.path << " from " << db_info.owner_dialog_id; full_infos[it->second].owner_dialog_id = db_info.owner_dialog_id; }); FileStats file_stats; file_stats.need_all_files = need_all_files; file_stats.split_by_owner_dialog_id = split_by_owner_dialog_id; for (auto &full_info : full_infos) { file_stats.add(std::move(full_info)); } auto passed = Time::now() - start; LOG_IF(INFO, passed > 0.5) << "Get file stats took: " << format::as_time(passed); promise.set_value(std::move(file_stats)); } }