diff --git a/pclsync/pbusinessaccount.c b/pclsync/pbusinessaccount.c index 21e207b..d561494 100644 --- a/pclsync/pbusinessaccount.c +++ b/pclsync/pbusinessaccount.c @@ -73,14 +73,14 @@ static int handle_result(const binresult *bres, uint64_t result, char **err) { if (strlen(errorret) == 0) errorret = papi_find_result2(bres, "message", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command gettreepublink returned error code %u message %s", (unsigned)result, errorret); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } @@ -365,7 +365,7 @@ void get_ba_member_email(uint64_t userid, char **email /*OUT*/, const char *resret = papi_find_result2(users->array[0], "email", PARAM_STR)->str; *length = strlen(resret); - *email = psync_strndup(resret, *length); + *email = putil_strndup(resret, *length); fname = papi_find_result2(users->array[0], "firstname", PARAM_STR)->str; lname = papi_find_result2(users->array[0], "lastname", PARAM_STR)->str; } @@ -430,7 +430,7 @@ void get_ba_team_name(uint64_t teamid, char **name /*OUT*/, const char *teamret = papi_find_result2(teams->array[0], "name", PARAM_STR)->str; *length = strlen(teamret); - *name = psync_strndup(teamret, *length); + *name = putil_strndup(teamret, *length); } free(bres); diff --git a/pclsync/pcryptofolder.c b/pclsync/pcryptofolder.c index cbbe9b8..4863a18 100644 --- a/pclsync/pcryptofolder.c +++ b/pclsync/pcryptofolder.c @@ -244,10 +244,10 @@ static int download_keys(unsigned char **rsapriv, size_t *rsaprivlen, unsigned c return pdbg_return_const(PSYNC_CRYPTO_START_UNKNOWN_ERROR); } data = papi_find_result2(res, "privatekey", PARAM_STR); - rsaprivstruct = psync_base64_decode((const unsigned char *)data->str, + rsaprivstruct = putil_base64_decode((const unsigned char *)data->str, data->length, &rsaprivstructlen); data = papi_find_result2(res, "publickey", PARAM_STR); - rsapubstruct = psync_base64_decode((const unsigned char *)data->str, + rsapubstruct = putil_base64_decode((const unsigned char *)data->str, data->length, &rsapubstructlen); free(res); sha1hex(rsaprivstruct, rsaprivstructlen, privatesha1); @@ -337,11 +337,11 @@ setup_upload(const unsigned char *rsapriv, size_t rsaprivlen, sha1hex(priv, offsetof(priv_key_ver1, key) + rsaprivlen, privatesha1); sha1hex(pub, offsetof(pub_key_ver1, key) + rsapublen, publicsha1); - b64priv = psync_base64_encode((unsigned char *)priv, + b64priv = putil_base64_encode((unsigned char *)priv, offsetof(priv_key_ver1, key) + rsaprivlen, &b64privlen); b64pub = - psync_base64_encode((unsigned char *)pub, + putil_base64_encode((unsigned char *)pub, offsetof(pub_key_ver1, key) + rsapublen, &b64publen); free(priv); free(pub); @@ -487,7 +487,7 @@ int pcryptofolder_get_hint(char **hint) { } return pdbg_return_const(PSYNC_CRYPTO_HINT_UNKNOWN_ERROR); } - *hint = psync_strdup(papi_find_result2(res, "hint", PARAM_STR)->str); + *hint = putil_strdup(papi_find_result2(res, "hint", PARAM_STR)->str); free(res); return PSYNC_CRYPTO_HINT_SUCCESS; } @@ -683,12 +683,12 @@ int pcryptofolder_unlock(const char *password) { return PSYNC_CRYPTO_START_SUCCESS; } -static void psync_fs_refresh_crypto_folders() { +static void pfs_refresh_crypto_folders() { psync_folderid_t *fids, *fid; fids = psync_crypto_folderids(); fid = fids; while (*fid != PSYNC_CRYPTO_INVALID_FOLDERID) { - psync_fs_refresh_folder(*fid); + pfs_refresh_folder(*fid); fid++; } free(fids); @@ -709,7 +709,7 @@ int pcryptofolder_lock() { pthread_rwlock_unlock(&crypto_lock); pdbg_logf(D_NOTICE, "stopped crypto"); pcryptofolder_cache_clean(); - psync_fs_refresh_crypto_folders(); + pfs_refresh_crypto_folders(); return PSYNC_CRYPTO_STOP_SUCCESS; } @@ -845,7 +845,7 @@ static psync_encrypted_symmetric_key_t download_fldr_enckey(psync_folderid_t fol pdbg_return_const(PSYNC_CRYPTO_API_ERR_INTERNAL)); } b64key = papi_find_result2(res, "key", PARAM_STR); - key = psync_base64_decode((const unsigned char *)b64key->str, b64key->length, + key = putil_base64_decode((const unsigned char *)b64key->str, b64key->length, &keylen); free(res); if (!key) @@ -898,7 +898,7 @@ static psync_encrypted_symmetric_key_t download_file_enckey(psync_fileid_t filei } result = papi_find_result2(res, "hash", PARAM_NUM)->num; b64key = papi_find_result2(res, "key", PARAM_STR); - key = psync_base64_decode((const unsigned char *)b64key->str, b64key->length, + key = putil_base64_decode((const unsigned char *)b64key->str, b64key->length, &keylen); free(res); if (!key) @@ -1136,7 +1136,7 @@ static pcrypto_textenc_t get_tmp_fldrencoder_safe(psync_fsfolderid_t folderid) { pdbg_return_const(PSYNC_CRYPTO_FOLDER_NOT_ENCRYPTED)); } b64enckey = (const unsigned char *)psync_get_lstring(row[0], &b64enckeylen); - enckey = psync_base64_decode(b64enckey, b64enckeylen, &enckeylen); + enckey = putil_base64_decode(b64enckey, b64enckeylen, &enckeylen); psql_free(res); if (enckey) { symkey = prsa_decrypt_data(crypto_privkey, enckey, enckeylen); @@ -1192,7 +1192,7 @@ static pcrypto_textdec_t get_tmp_fldrdecoder_safe(psync_fsfolderid_t folderid) { pdbg_return_const(PSYNC_CRYPTO_FOLDER_NOT_ENCRYPTED)); } b64enckey = (const unsigned char *)psync_get_lstring(row[0], &b64enckeylen); - enckey = psync_base64_decode(b64enckey, b64enckeylen, &enckeylen); + enckey = putil_base64_decode(b64enckey, b64enckeylen, &enckeylen); psql_free(res); if (enckey) { symkey = prsa_decrypt_data(crypto_privkey, enckey, enckeylen); @@ -1282,7 +1282,7 @@ char *pcryptofolder_flddecode_filename(pcrypto_textdec_t decoder, const char *name) { unsigned char *filenameenc, *filenamedec; size_t filenameenclen; - filenameenc = psync_base32_decode((const unsigned char *)name, strlen(name), + filenameenc = putil_base32_decode((const unsigned char *)name, strlen(name), &filenameenclen); if (!filenameenc) return NULL; @@ -1353,7 +1353,7 @@ char * pcryptofolder_fldencode_filename(pcrypto_textenc_t encoder, pcrypto_encode_text(encoder, (const unsigned char *)name, strlen(name), &filenameenc, &filenameenclen); filenameb32 = - psync_base32_encode(filenameenc, filenameenclen, &filenameenclen); + putil_base32_encode(filenameenc, filenameenclen, &filenameenclen); free(filenameenc); return (char *)filenameb32; } @@ -1421,7 +1421,7 @@ static pcrypto_sector_encdec_t get_fileencoder_tmp(psync_fsfileid_t fileid, switch (psync_get_number(row[0])) { case PSYNC_FS_TASK_CREAT: b64enckey = (const unsigned char *)psync_get_lstring(row[2], &b64enckeylen); - enckey = psync_base64_decode(b64enckey, b64enckeylen, &enckeylen); + enckey = putil_base64_decode(b64enckey, b64enckeylen, &enckeylen); psql_free(res); if (enckey) { symkey = prsa_decrypt_data(crypto_privkey, enckey, enckeylen); @@ -1504,7 +1504,7 @@ pcrypto_sector_encdec_t pcryptofolder_filencoder_from_binresult(psync_fileid_t f uint64_t hash; size_t keylen; b64key = papi_find_result2(res, "key", PARAM_STR); - key = psync_base64_decode((const unsigned char *)b64key->str, b64key->length, + key = putil_base64_decode((const unsigned char *)b64key->str, b64key->length, &keylen); if (!key) return (pcrypto_sector_encdec_t)errptr( @@ -1560,7 +1560,7 @@ static char *get_name_encoded(psync_folderid_t folderid, return (char *)enc; pcrypto_encode_text(enc, (const unsigned char *)name, strlen(name), &nameenc, &nameenclen); - ret = (char *)psync_base32_encode(nameenc, nameenclen, &nameenclen); + ret = (char *)putil_base32_encode(nameenc, nameenclen, &nameenclen); free_direncoder(folderid, enc); free(nameenc); return ret; @@ -1597,7 +1597,7 @@ static int get_fldr_name(psync_folderid_t folderid, const char *name, char **ename, const char **err) { if (folderid == 0) { - *ename = psync_strdup(name); + *ename = putil_strdup(name); return PSYNC_CRYPTO_SUCCESS; } else { psync_sql_res *res; @@ -1613,7 +1613,7 @@ static int get_fldr_name(psync_folderid_t folderid, if (enc) return get_cfldr_name(folderid, name, ename, err); else { - *ename = psync_strdup(name); + *ename = putil_strdup(name); return PSYNC_CRYPTO_SUCCESS; } } @@ -1681,7 +1681,7 @@ char *pcryptofolder_filencoder_key_get(psync_fsfileid_t fileid, encsym = get_file_enckey(fileid, hash, 0); if (is_err(encsym)) return (char *)encsym; - ret = (char *)psync_base64_encode(encsym->data, encsym->datalen, keylen); + ret = (char *)putil_base64_encode(encsym->data, encsym->datalen, keylen); free(encsym); return ret; } @@ -1709,7 +1709,7 @@ char *pcryptofolder_filencoder_key_new(uint32_t flags, size_t *keylen) { return (char *)errptr(pdbg_return_const(PSYNC_CRYPTO_RSA_ERROR)); } putil_wipe(&sym, sizeof(sym)); - ret = (char *)psync_base64_encode(encsym->data, encsym->datalen, keylen); + ret = (char *)putil_base64_encode(encsym->data, encsym->datalen, keylen); free(encsym); return ret; } @@ -1739,7 +1739,7 @@ char *pcryptofolder_filencoder_key_newplain( } *deckey = symkeyv1_to_symkey(&sym); putil_wipe(&sym, sizeof(sym)); - ret = (char *)psync_base64_encode(encsym->data, encsym->datalen, keylen); + ret = (char *)putil_base64_encode(encsym->data, encsym->datalen, keylen); free(encsym); return ret; } @@ -1779,7 +1779,7 @@ int pcryptofolder_mkdir(psync_folderid_t folderid, const char *name, pdbg_logf(D_ERROR, "RSA encryption failed"); return set_err(pdbg_return_const(PSYNC_CRYPTO_RSA_ERROR), err); } - b64encsym = psync_base64_encode(encsym->data, encsym->datalen, &b64encsymlen); + b64encsym = putil_base64_encode(encsym->data, encsym->datalen, &b64encsymlen); ret = psync_cloud_crypto_send_mkdir(folderid, ename, err, (char *)b64encsym, b64encsymlen, encsym, newfolderid); free(encsym); @@ -1888,8 +1888,8 @@ int psync_pcloud_crypto_reencode_key( prsa_free_private(priv); return to_err(rsasign); } - *privenc = (char *)psync_base64_encode(newpriv, newprivlen, &dummy); - *sign = (char *)psync_base64_encode(rsasign->data, rsasign->datalen, &dummy); + *privenc = (char *)putil_base64_encode(newpriv, newprivlen, &dummy); + *sign = (char *)putil_base64_encode(rsasign->data, rsasign->datalen, &dummy); free(rsasign); free(newpriv); prsa_free_public(pub); @@ -1963,8 +1963,8 @@ int psync_pcloud_crypto_encode_key(const char *newpassphrase, uint32_t flags, prsa_free_binary(rsapriv); return to_err(rsasign); } - *privenc = (char *)psync_base64_encode(newpriv, rsaprivlen, &dummy); - *sign = (char *)psync_base64_encode(rsasign->data, rsasign->datalen, &dummy); + *privenc = (char *)putil_base64_encode(newpriv, rsaprivlen, &dummy); + *sign = (char *)putil_base64_encode(rsasign->data, rsasign->datalen, &dummy); free(rsasign); putil_wipe(newpriv, rsaprivlen); free(newpriv); @@ -2069,13 +2069,13 @@ int pcryptofolder_change_pass(const char *oldpassphrase, } pdbg_logf(D_NOTICE, "downloaded user keys"); data = papi_find_result2(bres, "privatekey", PARAM_STR); - privkey = psync_base64_decode((const unsigned char *)data->str, + privkey = putil_base64_decode((const unsigned char *)data->str, data->length, &privkeylen); data = papi_find_result2(bres, "publickey", PARAM_STR); - pubkey = psync_base64_decode((const unsigned char *)data->str, data->length, + pubkey = putil_base64_decode((const unsigned char *)data->str, data->length, &pubkeylen); data = papi_find_result2(bres, "salt", PARAM_STR); - salt = psync_base64_decode((const unsigned char *)data->str, data->length, + salt = putil_base64_decode((const unsigned char *)data->str, data->length, &saltlen); free(bres); if (unlikely(!privkey || !pubkey)) { diff --git a/pclsync/pdbg.c b/pclsync/pdbg.c index b0f7d9d..0a4cc9d 100644 --- a/pclsync/pdbg.c +++ b/pclsync/pdbg.c @@ -88,7 +88,7 @@ char *psync_debug_path() { return sockpath; } -char *psync_fs_event_log_path() { +char *pfs_event_log_path() { const char *custom_path = getenv("PCLOUD_FS_EVENT_LOG"); if (custom_path && custom_path[0] != '\0') { size_t len = strlen(custom_path) + 1; @@ -148,7 +148,7 @@ int pdbg_printf(const char *file, const char *function, int unsigned line, int u /* Create empty fs event log file on first call if configured */ if (unlikely(!fs_event_log_initialized)) { fs_event_log_initialized = 1; - char *path = psync_fs_event_log_path(); + char *path = pfs_event_log_path(); if (path) { /* Create empty file if it doesn't exist, or open existing */ FILE *f = fopen(path, "a+"); @@ -160,7 +160,7 @@ int pdbg_printf(const char *file, const char *function, int unsigned line, int u } clock_gettime(CLOCK_REALTIME, &ts); - time_format(ts.tv_sec, ts.tv_nsec, dttime); + putil_time_format(ts.tv_sec, ts.tv_nsec, dttime); threadid = pthread_self(); memcpy(&u, &threadid, sizeof(u)); snprintf(format, sizeof(format), "%s %u %s %s: %s:%u (function %s): %s\n", @@ -208,7 +208,7 @@ static void do_reopen_log() { fclose(fs_event_log); fs_event_log = NULL; - path = psync_fs_event_log_path(); + path = pfs_event_log_path(); if (path) { new_log = fopen(path, "a+"); free(path); @@ -235,7 +235,7 @@ void pdbg_write_fs_event(const char *fmt, ...) { /* Open fs event log if not already open */ if (unlikely(!fs_event_log)) { - char *path = psync_fs_event_log_path(); + char *path = pfs_event_log_path(); if (!path) { /* FS event log not configured, skip */ pthread_mutex_unlock(&log_mutex); @@ -251,7 +251,7 @@ void pdbg_write_fs_event(const char *fmt, ...) { /* Get timestamp */ clock_gettime(CLOCK_REALTIME, &ts); - time_format(ts.tv_sec, ts.tv_nsec, dttime); + putil_time_format(ts.tv_sec, ts.tv_nsec, dttime); /* Write timestamp followed by event message */ fprintf(fs_event_log, "%s ", dttime); diff --git a/pclsync/pdevice.c b/pclsync/pdevice.c index 39cbe2d..386f0df 100644 --- a/pclsync/pdevice.c +++ b/pclsync/pdevice.c @@ -59,7 +59,7 @@ char *pdevice_id() { (de->d_name[1] != 0 && (de->d_name[1] != '.' || de->d_name[2] != 0))) { path = - psync_strcat("/sys/class/power_supply/", de->d_name, "/type", NULL); + putil_strcat("/sys/class/power_supply/", de->d_name, "/type", NULL); fd = open(path, O_RDONLY); free(path); if (fd == -1) @@ -74,19 +74,19 @@ char *pdevice_id() { } closedir(dh); } - device = psync_strcat(hardware, ", Linux", NULL); + device = putil_strcat(hardware, ", Linux", NULL); return device; } char *pdevice_name() { char *osname = pdevice_get_os(); - char *ret = psync_strcat(osname, ", ", psync_software_name, NULL); + char *ret = putil_strcat(osname, ", ", psync_software_name, NULL); free(osname); return ret; } char *pdevice_get_os() { - return psync_os_name ? psync_strdup(psync_os_name) : pdevice_id(); + return psync_os_name ? putil_strdup(psync_os_name) : pdevice_id(); } void pdevice_set_software(const char *snm) { diff --git a/pclsync/pdiff.c b/pclsync/pdiff.c index f888af4..3b64300 100644 --- a/pclsync/pdiff.c +++ b/pclsync/pdiff.c @@ -251,7 +251,7 @@ static int check_active_subscribtion(const binresult *res) { char *status; sub = papi_check_result2(res, "lastsubscription", PARAM_HASH); if (sub) { - status = psync_strdup(papi_find_result2(sub, "status", PARAM_STR)->str); + status = putil_strdup(papi_find_result2(sub, "status", PARAM_STR)->str); if (!strcmp(status, "active")) { free(status); return 1; @@ -332,7 +332,7 @@ static psock_t *get_connected_socket() { "REPLACE INTO setting (id, value) VALUES ('deviceid', ?)"); psql_bind_str(q, 1, deviceidhex); psql_run_free(q); - deviceid = psync_strdup(deviceidhex); + deviceid = putil_strdup(deviceidhex); } pdbg_logf(D_NOTICE, "using deviceid %s", deviceid); @@ -367,11 +367,11 @@ static psock_t *get_connected_socket() { } if (!auth && psync_my_auth[0]) - auth = psync_strdup(psync_my_auth); + auth = putil_strdup(psync_my_auth); if (!user && psync_my_user) - user = psync_strdup(psync_my_user); + user = putil_strdup(psync_my_user); if (!pass && psync_my_pass) - pass = psync_strdup(psync_my_pass); + pass = putil_strdup(psync_my_pass); if (!auth && (!pass || !user)) { if (tfa) { tfa = 0; @@ -463,7 +463,7 @@ static psock_t *get_connected_socket() { if (result == 2297) { free(psync_my_2fa_token); psync_my_2fa_token = - psync_strdup(papi_find_result2(res, "token", PARAM_STR)->str); + putil_strdup(papi_find_result2(res, "token", PARAM_STR)->str); psync_my_2fa_has_devices = papi_find_result2(res, "hasdevices", PARAM_BOOL)->num; psync_my_2fa_type = papi_find_result2(res, "tfatype", PARAM_NUM)->num; @@ -479,7 +479,7 @@ static psock_t *get_connected_socket() { if (result == 2306) { free(psync_my_verify_token); psync_my_verify_token = - psync_strdup(papi_find_result2(res, "verifytoken", PARAM_STR)->str); + putil_strdup(papi_find_result2(res, "verifytoken", PARAM_STR)->str); pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_VERIFYREQ); pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED); psock_close(sock); @@ -491,7 +491,7 @@ static psock_t *get_connected_socket() { cres = papi_check_result2(res, "location", PARAM_HASH); if (cres) { binapi = - psync_strdup(papi_find_result2(cres, "binapi", PARAM_STR)->str); + putil_strdup(papi_find_result2(cres, "binapi", PARAM_STR)->str); locationid = papi_find_result2(cres, "id", PARAM_NUM)->num; psync_set_apiserver(binapi, locationid); @@ -566,7 +566,7 @@ static psock_t *get_connected_socket() { psync_is_business = papi_find_result2(res, "business", PARAM_BOOL)->num; lid = psync_setting_get_uint(_PS(location_id)); psql_start(); - psync_strlcpy(psync_my_auth, papi_find_result2(res, "auth", PARAM_STR)->str, + putil_strlcpy(psync_my_auth, papi_find_result2(res, "auth", PARAM_STR)->str, sizeof(psync_my_auth)); if (luserid) { @@ -923,7 +923,7 @@ static void process_createfolder(const binresult *entry) { // Log remote folder creation (both synced and FUSE-only) { - char *folderpath = psync_fs_get_path_by_folderid(folderid); + char *folderpath = pfs_get_path_by_folderid(folderid); if (likely(folderpath)) { pdbg_write_fs_event("folder created %s", folderpath); free(folderpath); @@ -1091,7 +1091,7 @@ static void process_modifyfolder(const binresult *entry) { } // Get old folder path before database update (for move detection) - char *oldfolderpath = psync_fs_get_path_by_folderid(folderid); + char *oldfolderpath = pfs_get_path_by_folderid(folderid); char *oldfolderpath_rel = pfolder_path(folderid, NULL); mtime = papi_find_result2(meta, "modified", PARAM_NUM)->num; @@ -1111,7 +1111,7 @@ static void process_modifyfolder(const binresult *entry) { int is_move = (oldparentfolderid != parentfolderid || strcmp(name->str, oldname) != 0); if (is_move) { - char *newfolderpath = psync_fs_get_path_by_folderid(folderid); + char *newfolderpath = pfs_get_path_by_folderid(folderid); if (likely(oldfolderpath && newfolderpath)) { pdbg_write_fs_event("folder moved %s -> %s", oldfolderpath, newfolderpath); } @@ -1278,7 +1278,7 @@ static void process_deletefolder(const binresult *entry) { // Get folder path BEFORE deletion from database path = pfolder_path(folderid, NULL); - char *fullpath = psync_fs_get_path_by_folderid(folderid); + char *fullpath = pfs_get_path_by_folderid(folderid); if (psyncer_dl_has_folder(folderid)) { psyncer_dl_queue_del(folderid); @@ -1315,7 +1315,7 @@ static void process_deletefolder(const binresult *entry) { psql_bind_uint( st2, 2, papi_find_result2(meta, "parentfolderid", PARAM_NUM)->num); psql_run(st2); - psync_fs_folder_deleted(folderid); + pfs_xatr_folder_deleted(folderid); } if (path) free(path); @@ -1333,7 +1333,7 @@ static void check_for_deletedfileid(const binresult *meta) { res = psql_prepare("DELETE FROM file WHERE id=?"); psql_bind_uint(res, 1, delfileid->num); psql_run_free(res); - psync_fs_file_deleted(delfileid->num); + pfs_xatr_file_deleted(delfileid->num); } } @@ -1451,7 +1451,7 @@ static void process_createfile(const binresult *entry) { // Log all remote file creations (both synced and FUSE-only) { - char *filepath = psync_fs_get_path_by_fileid(fileid); + char *filepath = pfs_get_path_by_fileid(fileid); if (likely(filepath)) { pdbg_write_fs_event("file created %s", filepath); free(filepath); @@ -1542,7 +1542,7 @@ static void process_modifyfile(const binresult *entry) { // Get old path before database update (for move detection) oldparentfolderid = psync_get_number(row[0]); oldname = psync_get_lstring(row[4], &oldnamelen); - char *oldfilepath = psync_fs_get_path_by_fileid(fileid); + char *oldfilepath = pfs_get_path_by_fileid(fileid); char *oldfilepath_rel = pfolder_file_path(fileid, NULL); if (!st) @@ -1589,7 +1589,7 @@ static void process_modifyfile(const binresult *entry) { int is_content_change = (hash != psync_get_number(row[3]) || size != oldsize); if (is_move) { - char *newfilepath = psync_fs_get_path_by_fileid(fileid); + char *newfilepath = pfs_get_path_by_fileid(fileid); if (likely(oldfilepath && newfilepath)) { pdbg_write_fs_event("file moved %s -> %s", oldfilepath, newfilepath); } @@ -1601,7 +1601,7 @@ static void process_modifyfile(const binresult *entry) { } free(newfilepath_rel); } else if (is_content_change) { - char *filepath = psync_fs_get_path_by_fileid(fileid); + char *filepath = pfs_get_path_by_fileid(fileid); if (likely(filepath)) { pdbg_write_fs_event("file modified %s", filepath); free(filepath); @@ -1737,7 +1737,7 @@ static void process_deletefile(const binresult *entry) { } // Get path BEFORE deleting from database path = pfolder_file_path(fileid, NULL); - char *fullpath = psync_fs_get_path_by_fileid(fileid); + char *fullpath = pfs_get_path_by_fileid(fileid); psql_bind_uint(st, 1, fileid); psql_run(st); @@ -1751,7 +1751,7 @@ static void process_deletefile(const binresult *entry) { } if (papi_find_result2(meta, "ismine", PARAM_BOOL)->num) used_quota -= papi_find_result2(meta, "size", PARAM_NUM)->num; - psync_fs_file_deleted(fileid); + pfs_xatr_file_deleted(fileid); } if (path) free(path); @@ -2827,7 +2827,7 @@ static int cmp_folderid(const void *ptr1, const void *ptr2) { } static void psync_diff_refresh_fs_add_folder(psync_folderid_t folderid) { - if (psync_fs_need_per_folder_refresh()) { + if (pfs_need_per_folder_refresh()) { if (refresh_allocated == refresh_last) { if (refresh_allocated) refresh_allocated *= 2; @@ -2851,7 +2851,7 @@ static void psync_diff_refresh_thread(void *ptr) { lastfolderid = (psync_folderid_t)-1; for (i = 0; i < fr->refresh_last; i++) if (fr->refresh_folders[i] != lastfolderid) { - psync_fs_refresh_folder(fr->refresh_folders[i]); + pfs_refresh_folder(fr->refresh_folders[i]); lastfolderid = fr->refresh_folders[i]; } free(fr->refresh_folders); @@ -2859,7 +2859,7 @@ static void psync_diff_refresh_thread(void *ptr) { } static void psync_diff_refresh_fs(const binresult *entries) { - if (psync_fs_need_per_folder_refresh()) { + if (pfs_need_per_folder_refresh()) { const binresult *meta; refresh_folders_ptr_t *ptr; psync_folderid_t folderid, lastfolderid; @@ -2918,7 +2918,7 @@ static void psync_run_analyze_if_needed() { for (i = 0; i < ARRAY_SIZE(skiptables); i++) if (!strcmp(srow[0], skiptables[i])) goto skip; - tablenames[tablecnt++] = psync_strdup(srow[0]); + tablenames[tablecnt++] = putil_strdup(srow[0]); skip:; } psql_free(res); @@ -2926,7 +2926,7 @@ static void psync_run_analyze_if_needed() { while (tablecnt) { --tablecnt; pdbg_logf(D_NOTICE, "running ANALYZE on %s", tablenames[tablecnt]); - sql = psync_strcat("ANALYZE ", tablenames[tablecnt], ";", NULL); + sql = putil_strcat("ANALYZE ", tablenames[tablecnt], ";", NULL); free(tablenames[tablecnt]); psql_statement(sql); free(sql); @@ -3068,7 +3068,7 @@ restart: } } while (result); - psync_fs_refresh_folder(0); + pfs_refresh_folder(0); pdbg_logf(D_NOTICE, "initial sync finished"); if (psync_diff_check_quota(sock)) { psock_close(sock); diff --git a/pclsync/pdownload.c b/pclsync/pdownload.c index 2bd8e18..0d8d3db 100644 --- a/pclsync/pdownload.c +++ b/pclsync/pdownload.c @@ -114,7 +114,7 @@ static int task_mkdir(const char *path) { int err; while (1) { if (likely(!mkdir(path, PSYNC_DEFAULT_POSIX_FOLDER_MODE))) { // don't change to likely_log, as it may - // overwrite psync_fs_err; + // overwrite pfs_err; psync_set_local_full(0); return 0; } @@ -159,8 +159,8 @@ static void do_move(void *ptr, ppath_stat *st) { const char **arr; char *oldpath, *newpath; arr = (const char **)ptr; - oldpath = psync_strcat(arr[0], st->name, NULL); - newpath = psync_strcat(arr[1], st->name, NULL); + oldpath = putil_strcat(arr[0], st->name, NULL); + newpath = putil_strcat(arr[1], st->name, NULL); pfile_rename(oldpath, newpath); free(newpath); free(oldpath); @@ -717,7 +717,7 @@ static int task_download_file(download_task_t *dt) { if (!stat(dt->tmpname, &st) && pfile_stat_size(&st) >= PSYNC_MIN_SIZE_FOR_CHECKSUMS) { tmpold = - psync_strcat(dt->localpath, "/", dt->filename, + putil_strcat(dt->localpath, "/", dt->filename, "-old", PSYNC_APPEND_PARTIAL_FILES, NULL); if (pfile_rename_overwrite(dt->tmpname, tmpold)) { free(tmpold); @@ -740,7 +740,7 @@ static int task_download_file(download_task_t *dt) { hosts = papi_find_result2(res, "hosts", PARAM_ARRAY); requestpath = papi_find_result2(res, "path", PARAM_STR)->str; - psync_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", + putil_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", papi_find_result2(res, "dwltag", PARAM_STR)->str); buff = malloc(PSYNC_COPY_BUFFER_SIZE); http = NULL; @@ -975,7 +975,7 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, free(newfolder); return 0; } - newpath = psync_strcat(newfolder, "/", newname, NULL); + newpath = putil_strcat(newfolder, "/", newname, NULL); ret = 0; psync_stop_localscan(); if (pfile_rename_overwrite(oldpath, newpath)) { @@ -1198,8 +1198,8 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid, if (pdbg_unlikely(!localpath)) return 0; localname = - psync_strcat(localpath, "/", filename, NULL); - tmpname = psync_strcat(localpath, "/", filename, + putil_strcat(localpath, "/", filename, NULL); + tmpname = putil_strcat(localpath, "/", filename, PSYNC_APPEND_PARTIAL_FILES, NULL); len = strlen(filename); dt = (download_task_t *)malloc(offsetof(download_task_t, filename) + @@ -1337,7 +1337,7 @@ static void task_del_folder_rec_do(const char *localpath, psql_bind_uint(res, 2, syncid); while ((vrow = psql_fetch(res))) { pupload_del_tasks(psync_get_number(vrow[0])); - nm = psync_strcat(localpath, "/", + nm = putil_strcat(localpath, "/", psync_get_string(vrow[1]), NULL); pdbg_logf(D_NOTICE, "deleting %s", nm); pfile_delete(nm); @@ -1354,7 +1354,7 @@ static void task_del_folder_rec_do(const char *localpath, psql_bind_uint(res, 1, localfolderid); psql_bind_uint(res, 2, syncid); while ((vrow = psql_fetch(res))) { - nm = psync_strcat(localpath, "/", + nm = putil_strcat(localpath, "/", psync_get_string(vrow[1]), NULL); task_del_folder_rec_do(nm, psync_get_number(vrow[0]), syncid); free(nm); @@ -1420,7 +1420,7 @@ static int download_task(uint64_t taskid, uint32_t type, psync_syncid_t syncid, for (ptr = name; *ptr; ptr++) if (pfile_invalid_chars[(unsigned char)*ptr]) { if (!vname) - vname = psync_strdup(name); + vname = putil_strdup(name); vname[ptr - name] = PSYNC_REPLACE_INV_CH_IN_FILENAMES; } if (vname) { diff --git a/pclsync/pfile.c b/pclsync/pfile.c index fbf1d94..859b4ae 100644 --- a/pclsync/pfile.c +++ b/pclsync/pfile.c @@ -419,7 +419,7 @@ int pfile_run_update(const char *path) { dup2(fd, STDERR_FILENO); close(fd); setsid(); - ex = psync_strcat(PSYNC_RUN_CMD " \"", path, "\"", NULL); + ex = putil_strcat(PSYNC_RUN_CMD " \"", path, "\"", NULL); execl("/bin/sh", "/bin/sh", "-c", ex, NULL); pdbg_logf(D_ERROR, "exec of %s failed", ex); free(ex); diff --git a/pclsync/pfolder.c b/pclsync/pfolder.c index 812df6d..6f8e920 100644 --- a/pclsync/pfolder.c +++ b/pclsync/pfolder.c @@ -343,7 +343,7 @@ char *psync_join_string_list(const char *sep, psync_list *lst, size_t *retlen) { cnt++; } if (unlikely(!cnt)) - return psync_strdup(""); + return putil_strdup(""); seplen = strlen(sep); ret = str = malloc(slen + cnt * seplen + 1); psync_list_for_each_element(e, lst, string_list, list) { @@ -375,7 +375,7 @@ char *pfolder_path(psync_folderid_t folderid, size_t *retlen) { psync_free_string_list(&folderlist); if (!ret[0]) { free(ret); - ret = psync_strdup("/"); + ret = putil_strdup("/"); if (retlen) *retlen = 1; } @@ -397,7 +397,7 @@ char *pfolder_path_sep(psync_folderid_t folderid, const char *sep, psync_free_string_list(&folderlist); if (!ret[0]) { free(ret); - ret = psync_strdup(sep); + ret = putil_strdup(sep); if (retlen) *retlen = 1; } @@ -649,13 +649,13 @@ pfolder_list_t *pfolder_remote_folders(psync_folderid_t folderid, (psync_get_number(row[4]) & PSYNC_FOLDER_FLAG_ENCRYPTED) ? 1 : 0; if (parentencrypted && pcryptofolder_is_unlocked()) { tmp = (char *)psync_get_lstring(row[2], &namelen); - entry.name = get_decname_for_folder(folderid, tmp, namelen); + entry.name = pfs_fldr_get_decname(folderid, tmp, namelen); if (!entry.name) { pdbg_logf( D_BUG, "Can't decrypt folder name for folderid: %lu, parent folfderid: " "%lu, cryptoerr: %d, encrypted name: %s. Skippping ...", - entry.folder.folderid, folderid, psync_fsfolder_crypto_error(), + entry.folder.folderid, folderid, pfs_fldr_crypto_error(), tmp); continue; } @@ -822,12 +822,12 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) { strlens = 0; if (strlen(syncTypes) > 0) { - psync_slprintf(sql, 1024, + putil_slprintf(sql, 1024, "SELECT id, folderid, localpath, synctype FROM syncfolder " "WHERE folderid IS NOT NULL AND synctype IN (%s)", syncTypes); } else { - psync_slprintf(sql, 1024, + putil_slprintf(sql, 1024, "SELECT id, folderid, localpath, synctype FROM syncfolder " "WHERE folderid IS NOT NULL"); } @@ -851,7 +851,7 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) { folderid = psync_get_number(row[1]); str = pfolder_path(folderid, &l); if (unlikely(!str)) { - str = psync_strdup("/Invalid/Path"); + str = putil_strdup("/Invalid/Path"); l = strlen(str); } l++; @@ -945,7 +945,7 @@ psync_syncid_t pfolder_add_sync(const char *localpath, psync_folderid_t folderid mbedtls_md = 5; if (pdbg_unlikely(!pfile_stat_mode_ok(&st, mbedtls_md))) return_isyncid(PERROR_LOCAL_FOLDER_ACC_DENIED); - syncmp = psync_fs_getmountpoint(); + syncmp = pfs_getmountpoint(); if (syncmp) { size_t len = strlen(syncmp); if (!memcmp(syncmp, localpath, len) && diff --git a/pclsync/pfs.c b/pclsync/pfs.c index dca1a76..b5a72ad 100644 --- a/pclsync/pfs.c +++ b/pclsync/pfs.c @@ -76,12 +76,12 @@ typedef off_t fuse_off_t; #include #if IS_DEBUG -#define psync_fs_set_thread_name() \ +#define pfs_set_thread_name() \ do { \ psync_thread_name = __FUNCTION__; \ } while (0) #else -#define psync_fs_set_thread_name() \ +#define pfs_set_thread_name() \ do { \ } while (0) #endif @@ -100,8 +100,8 @@ static struct fuse_chan *psync_fuse_channel = NULL; static struct fuse *psync_fuse = NULL; static char *psync_current_mountpoint = NULL; static psync_generic_callback_t psync_start_callback = NULL; -char *psync_fake_prefix = NULL; -size_t psync_fake_prefix_len = 0; +char *pfs_fake_prefix = NULL; +size_t pfs_fake_prefix_len = 0; static int64_t psync_fake_fileid = INT64_MIN; static pthread_mutex_t start_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -117,7 +117,7 @@ extern int errno; static psync_tree *openfiles = PSYNC_TREE_EMPTY; -static int psync_fs_ftruncate_of_locked(psync_openfile_t *of, fuse_off_t size); +static int pfs_ftruncate_of_locked(psync_openfile_t *of, fuse_off_t size); static inline int psync_crypto_is_error(const void *ptr) { return (uintptr_t)ptr <= PSYNC_CRYPTO_MAX_ERROR; @@ -138,17 +138,17 @@ static void delete_log_files(psync_openfile_t *of) { fileidhex[sizeof(psync_fsfileid_t)] = 'l'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); pfile_delete(filename); free(filename); fileidhex[sizeof(psync_fsfileid_t)] = 'f'; filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); pfile_delete(filename); free(filename); } -int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, +int pfs_update_openfile(uint64_t taskid, uint64_t writeid, psync_fileid_t newfileid, uint64_t hash, uint64_t size, time_t ctime) { psync_sql_res *res; @@ -169,7 +169,7 @@ int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, tr = tr->right; else { fl = ptree_element(tr, psync_openfile_t, tree); - psync_fs_lock_file(fl); + pfs_lock_file(fl); if (fl->writeid == writeid) { if (fl->encrypted) { if (fl->logfile) { @@ -181,7 +181,7 @@ int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, psync_interval_tree_free(fl->authenticatedints); fl->authenticatedints = NULL; } - size = pfscrypto_plain_size(size); + size = pfs_crpt_plain_size(size); } pdbg_logf(D_NOTICE, "updating fileid %ld to %lu, hash %lu size %lu", (long)fileid, (unsigned long)newfileid, (unsigned long)hash, @@ -263,7 +263,7 @@ int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, return ret; } -/*void psync_fs_uploading_openfile(uint64_t taskid){ +/*void pfs_uploading_openfile(uint64_t taskid){ psync_openfile_t *fl; psync_tree *tr; psync_fsfileid_t fileid; @@ -279,7 +279,7 @@ int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, tr=tr->right; else{ fl=ptree_element(tr, psync_openfile_t, tree); - psync_fs_lock_file(fl); + pfs_lock_file(fl); fl->uploading=1; pthread_mutex_unlock(&fl->mutex); break; @@ -288,7 +288,7 @@ int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, psql_unlock(); }*/ -int psync_fs_rename_openfile_locked(psync_fsfileid_t fileid, +int pfs_rename_openfile_locked(psync_fsfileid_t fileid, psync_fsfolderid_t folderid, const char *name) { psync_openfile_t *fl; @@ -303,14 +303,14 @@ int psync_fs_rename_openfile_locked(psync_fsfileid_t fileid, tr = tr->right; else { fl = ptree_element(tr, psync_openfile_t, tree); - psync_fs_lock_file(fl); + pfs_lock_file(fl); if (fl->currentfolder->folderid != folderid) { - psync_fstask_release_folder_tasks_locked(fl->currentfolder); + pfs_task_release_folder_tasks_locked(fl->currentfolder); fl->currentfolder = - psync_fstask_get_or_create_folder_tasks_locked(folderid); + pfs_task_get_or_create_folder_tasks_locked(folderid); } free(fl->currentname); - fl->currentname = psync_strdup(name); + fl->currentname = putil_strdup(name); pthread_mutex_unlock(&fl->mutex); return 1; } @@ -318,7 +318,7 @@ int psync_fs_rename_openfile_locked(psync_fsfileid_t fileid, return 0; } -void psync_fs_mark_openfile_deleted(uint64_t taskid) { +void pfs_mark_openfile_deleted(uint64_t taskid) { psync_sql_res *res; psync_openfile_t *fl; psync_tree *tr; @@ -337,7 +337,7 @@ void psync_fs_mark_openfile_deleted(uint64_t taskid) { fl = ptree_element(tr, psync_openfile_t, tree); pdbg_logf(D_NOTICE, "file being deleted %s is still open, marking as deleted", fl->currentname); - psync_fs_lock_file(fl); + pfs_lock_file(fl); fl->deleted = 1; pthread_mutex_unlock(&fl->mutex); res = psql_prepare("UPDATE fstask SET status=12 WHERE id=?"); @@ -349,7 +349,7 @@ void psync_fs_mark_openfile_deleted(uint64_t taskid) { psql_unlock(); } -int64_t psync_fs_get_file_writeid(uint64_t taskid) { +int64_t pfs_get_file_writeid(uint64_t taskid) { psync_openfile_t *fl; psync_tree *tr; psync_sql_res *res; @@ -367,7 +367,7 @@ int64_t psync_fs_get_file_writeid(uint64_t taskid) { tr = tr->right; else { fl = ptree_element(tr, psync_openfile_t, tree); - psync_fs_lock_file(fl); + pfs_lock_file(fl); d = fl->writeid; pthread_mutex_unlock(&fl->mutex); psql_rdunlock(); @@ -385,7 +385,7 @@ int64_t psync_fs_get_file_writeid(uint64_t taskid) { return d; } -void psync_fs_update_openfile_fileid_locked(psync_openfile_t *of, +static void pfs_update_openfile_fileid_locked(psync_openfile_t *of, psync_fsfileid_t fileid) { psync_tree *tr; int64_t d; @@ -429,7 +429,7 @@ static void psync_row_to_folder_stat(psync_variant_row row, psync_fstask_folder_t *folder; folderid = psync_get_number(row[0]); mtime = psync_get_number(row[3]); - folder = psync_fstask_get_folder_tasks_rdlocked(folderid); + folder = pfs_task_get_folder_tasks_rdlocked(folderid); if (folder && folder->mtime) mtime = folder->mtime; memset(stbuf, 0, sizeof(struct FUSE_STAT)); @@ -455,7 +455,7 @@ static void psync_row_to_file_stat(psync_variant_row row, stbuf->st_ino = fileid_to_inode(psync_get_number(row[4])); size = psync_get_number(row[1]); if (flags & PSYNC_FOLDER_FLAG_ENCRYPTED) - size = pfscrypto_plain_size(size); + size = pfs_crpt_plain_size(size); memset(stbuf, 0, sizeof(struct FUSE_STAT)); #ifdef FUSE_STAT_HAS_BIRTHTIME stbuf->st_birthtime = psync_get_number(row[2]); @@ -476,7 +476,7 @@ static void psync_mkdir_to_folder_stat(psync_fstask_mkdir_t *mk, struct FUSE_STAT *stbuf) { uint64_t mtime; psync_fstask_folder_t *folder; - folder = psync_fstask_get_folder_tasks_rdlocked(mk->folderid); + folder = pfs_task_get_folder_tasks_rdlocked(mk->folderid); if (folder && folder->mtime) mtime = folder->mtime; else @@ -553,7 +553,7 @@ static int fill_stat_from_open_file(psync_fsfileid_t fileid, tr = tr->right; else { fl = ptree_element(tr, psync_openfile_t, tree); - psync_fs_lock_file(fl); + pfs_lock_file(fl); stbuf->st_size = fl->currentsize; pdbg_logf(D_NOTICE, "found open file with size %lu", (unsigned long)fl->currentsize); @@ -582,7 +582,7 @@ static int psync_creat_local_to_file_stat(psync_fstask_creat_t *cr, // int fd; char fileidhex[sizeof(psync_fsfileid_t) * 2 + 2]; int stret; - if (unlikely(psync_fs_need_per_folder_refresh_const() && + if (unlikely(pfs_need_per_folder_refresh_const() && cr->fileid < psync_fake_fileid)) return psync_creat_stat_fake_file(stbuf); fl = NULL; @@ -597,7 +597,7 @@ static int psync_creat_local_to_file_stat(psync_fstask_creat_t *cr, tr = tr->right; else { fl = ptree_element(tr, psync_openfile_t, tree); - psync_fs_lock_file(fl); + pfs_lock_file(fl); break; } } @@ -617,7 +617,7 @@ static int psync_creat_local_to_file_stat(psync_fstask_creat_t *cr, fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; cachepath = psync_setting_get_string(_PS(fscachepath)); filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); stret = stat(filename, &st); if (stret) pdbg_logf(D_NOTICE, "could not stat file %s", filename); @@ -629,7 +629,7 @@ static int psync_creat_local_to_file_stat(psync_fstask_creat_t *cr, osize=0; else{ fileidhex[sizeof(psync_fsfileid_t)]='i'; - filename=psync_strcat(cachepath, "/", fileidhex, + filename=putil_strcat(cachepath, "/", fileidhex, NULL); fd=pfile_open(filename, O_RDONLY, 0); free(filename); if (fd==INVALID_HANDLE_VALUE) return -EIO; stret=pfile_pread(fd, &osize, sizeof(osize), offsetof(index_header, copyfromoriginal)); @@ -651,7 +651,7 @@ static int psync_creat_local_to_file_stat(psync_fstask_creat_t *cr, if (fill_stat_from_open_file(cr->fileid, stbuf)) size = stbuf->st_size; else { - size = pfscrypto_plain_size(pfile_stat_size(&st)); + size = pfs_crpt_plain_size(pfile_stat_size(&st)); stbuf->st_size = size; } } else { @@ -669,7 +669,7 @@ static int psync_creat_static_to_file_stat(psync_fstask_creat_t *cr, struct FUSE_STAT *stbuf, uint32_t folderflags) { psync_fstask_local_creat_t *lc; - lc = psync_fstask_creat_get_local(cr); + lc = pfs_task_creat_get_local(cr); memset(stbuf, 0, sizeof(struct FUSE_STAT)); stbuf->st_ino = cr->taskid; #ifdef FUSE_STAT_HAS_BIRTHTIME @@ -701,7 +701,7 @@ static int psync_creat_to_file_stat(psync_fstask_creat_t *cr, return psync_creat_static_to_file_stat(cr, stbuf, folderflags); } -int psync_fs_crypto_err_to_errno(int cryptoerr) { +int pfs_crypto_err_to_errno(int cryptoerr) { switch (cryptoerr) { case PSYNC_CRYPTO_NOT_STARTED: return EACCES; @@ -724,7 +724,7 @@ int psync_fs_crypto_err_to_errno(int cryptoerr) { } } -static int psync_fs_getrootattr(struct FUSE_STAT *stbuf) { +static int pfs_getrootattr(struct FUSE_STAT *stbuf) { psync_sql_res *res; psync_variant_row row; res = psql_query_rdlock( @@ -754,25 +754,25 @@ static int psync_fs_getrootattr(struct FUSE_STAT *stbuf) { } \ } while (0) -static int psync_fs_getattr(const char *path, struct FUSE_STAT *stbuf) { +static int pfs_getattr(const char *path, struct FUSE_STAT *stbuf) { psync_sql_res *res; psync_variant_row row; psync_fspath_t *fpath; psync_fstask_folder_t *folder; psync_fstask_creat_t *cr; int crr; - psync_fs_set_thread_name(); + pfs_set_thread_name(); // pdbg_logf(D_NOTICE, "getattr %s", path); if (path[1] == 0 && path[0] == '/') - return psync_fs_getrootattr(stbuf); + return pfs_getrootattr(stbuf); psql_rdlock(); CHECK_LOGIN_RDLOCKED(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) { psql_rdunlock(); - crr = psync_fsfolder_crypto_error(); + crr = pfs_fldr_crypto_error(); if (crr) { - crr = -psync_fs_crypto_err_to_errno(crr); + crr = -pfs_crypto_err_to_errno(crr); pdbg_logf(D_NOTICE, "got crypto error for %s, returning %d", path, crr); return crr; } else { @@ -781,10 +781,10 @@ static int psync_fs_getattr(const char *path, struct FUSE_STAT *stbuf) { return -ENOENT; } } - folder = psync_fstask_get_folder_tasks_rdlocked(fpath->folderid); + folder = pfs_task_get_folder_tasks_rdlocked(fpath->folderid); if (folder) { psync_fstask_mkdir_t *mk; - mk = psync_fstask_find_mkdir(folder, fpath->name, 0); + mk = pfs_task_find_mkdir(folder, fpath->name, 0); if (mk) { if (mk->flags & PSYNC_FOLDER_FLAG_INVISIBLE) { psql_rdunlock(); @@ -797,7 +797,7 @@ static int psync_fs_getattr(const char *path, struct FUSE_STAT *stbuf) { return 0; } } - if (!folder || !psync_fstask_find_rmdir(folder, fpath->name, 0)) { + if (!folder || !pfs_task_find_rmdir(folder, fpath->name, 0)) { res = psql_query_nolock( "SELECT id, permissions, ctime, mtime, subdircnt FROM folder WHERE " "parentfolderid=? AND name=?"); @@ -820,9 +820,9 @@ static int psync_fs_getattr(const char *path, struct FUSE_STAT *stbuf) { psync_row_to_file_stat(row, stbuf, fpath->flags); psql_free(res); if (folder) { - if (psync_fstask_find_unlink(folder, fpath->name, 0)) + if (pfs_task_find_unlink(folder, fpath->name, 0)) row = NULL; - if (!row && (cr = psync_fstask_find_creat(folder, fpath->name, 0))) + if (!row && (cr = pfs_task_find_creat(folder, fpath->name, 0))) crr = psync_creat_to_file_stat(cr, stbuf, fpath->flags); else crr = -1; @@ -852,7 +852,7 @@ static int filler_decoded(pcrypto_textdec_t dec, return filler(buf, name, st, off); } -static int psync_fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, +static int pfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, fuse_off_t offset, struct fuse_file_info *fi) { psync_sql_res *res; psync_variant_row row; @@ -864,16 +864,16 @@ static int psync_fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, uint32_t flags; size_t namelen; struct FUSE_STAT st; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "readdir %s", path); psql_rdlock(); CHECK_LOGIN_RDLOCKED(); - folderid = psync_fsfolderid_by_path(path, &flags); + folderid = pfs_fldr_id_by_path(path, &flags); if (pdbg_unlikely(folderid == PSYNC_INVALID_FSFOLDERID)) { psql_rdunlock(); - if (psync_fsfolder_crypto_error()) + if (pfs_fldr_crypto_error()) return pdbg_return( - -psync_fs_crypto_err_to_errno(psync_fsfolder_crypto_error())); + -pfs_crypto_err_to_errno(pfs_fldr_crypto_error())); else return -pdbg_return_const(ENOENT); } @@ -882,14 +882,14 @@ static int psync_fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, if (psync_crypto_is_error(dec)) { psql_rdunlock(); return pdbg_return( - -psync_fs_crypto_err_to_errno(psync_crypto_to_error(dec))); + -pfs_crypto_err_to_errno(psync_crypto_to_error(dec))); } } else dec = NULL; filler(buf, ".", NULL, 0); if (folderid != 0) filler(buf, "..", NULL, 0); - folder = psync_fstask_get_folder_tasks_rdlocked(folderid); + folder = pfs_task_get_folder_tasks_rdlocked(folderid); if (folderid >= 0) { res = psql_query_nolock( "SELECT id, permissions, ctime, mtime, subdircnt, name FROM folder " @@ -903,8 +903,8 @@ static int psync_fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, #endif if (!name || !name[0]) continue; - if (folder && (psync_fstask_find_rmdir(folder, name, 0) || - psync_fstask_find_mkdir(folder, name, 0))) + if (folder && (pfs_task_find_rmdir(folder, name, 0) || + pfs_task_find_mkdir(folder, name, 0))) continue; psync_row_to_folder_stat(row, &st); filler_decoded(dec, filler, buf, name, &st, 0); @@ -921,7 +921,7 @@ static int psync_fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, #endif if (!name || !name[0]) continue; - if (folder && psync_fstask_find_unlink(folder, name, 0)) + if (folder && pfs_task_find_unlink(folder, name, 0)) continue; psync_row_to_file_stat(row, &st, flags); filler_decoded(dec, filler, buf, name, &st, 0); @@ -968,7 +968,7 @@ static int psync_fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, } static psync_openfile_t * -psync_fs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid, +pfs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid, uint64_t size, uint64_t hash, int lock, uint32_t writeid, psync_fstask_folder_t *folder, const char *name, pcrypto_sector_encdec_t encoder) { @@ -993,13 +993,13 @@ psync_fs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid, } else { fl = ptree_element(tr, psync_openfile_t, tree); if (lock) { - psync_fs_lock_file(fl); - psync_fs_inc_of_refcnt_locked(fl); + pfs_lock_file(fl); + pfs_inc_of_refcnt_locked(fl); } else - psync_fs_inc_of_refcnt(fl); + pfs_inc_of_refcnt(fl); pdbg_assertw(fl->currentfolder == folder); pdbg_assertw(!strcmp(fl->currentname, name)); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); if (encoder != PSYNC_CRYPTO_INVALID_ENCODER && encoder != PSYNC_CRYPTO_UNLOADED_SECTOR_ENCODER) @@ -1016,7 +1016,7 @@ psync_fs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid, } else { fl = malloc(sizeof(psync_openfile_t)); memset(fl, 0, sizeof(psync_openfile_t)); - size = pfscrypto_plain_size(size); + size = pfs_crpt_plain_size(size); } if (d < 0) ptree_add_before(&openfiles, tr, &fl->tree); @@ -1034,7 +1034,7 @@ psync_fs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid, pthread_mutex_init(&fl->mutex, NULL); #endif fl->currentfolder = folder; - fl->currentname = psync_strdup(name); + fl->currentname = putil_strdup(name); fl->fileid = fileid; fl->remotefileid = remotefileid; fl->hash = hash; @@ -1052,29 +1052,29 @@ psync_fs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid, fl->logfile = INVALID_HANDLE_VALUE; } if (lock) - psync_fs_lock_file(fl); + pfs_lock_file(fl); psql_unlock(); return fl; } -int64_t psync_fs_load_interval_tree(int fd, uint64_t size, +int64_t pfs_load_interval_tree(int fd, uint64_t size, psync_interval_tree_t **tree) { - psync_fs_index_record records[512]; + pfs_index_record records[512]; uint64_t cnt; uint64_t i; ssize_t rrd, rd, j; - if (unlikely(size < sizeof(psync_fs_index_header))) + if (unlikely(size < sizeof(pfs_index_header))) return 0; - size -= sizeof(psync_fs_index_header); - pdbg_assertw(size % sizeof(psync_fs_index_record) == 0); - cnt = size / sizeof(psync_fs_index_record); + size -= sizeof(pfs_index_header); + pdbg_assertw(size % sizeof(pfs_index_record) == 0); + cnt = size / sizeof(pfs_index_record); pdbg_logf(D_NOTICE, "loading %lu intervals", (unsigned long)cnt); for (i = 0; i < cnt; i += ARRAY_SIZE(records)) { rd = ARRAY_SIZE(records) > cnt - i ? cnt - i : ARRAY_SIZE(records); - rrd = pfile_pread(fd, records, rd * sizeof(psync_fs_index_record), - i * sizeof(psync_fs_index_record) + - sizeof(psync_fs_index_header)); - if (pdbg_unlikely(rrd != rd * sizeof(psync_fs_index_record))) + rrd = pfile_pread(fd, records, rd * sizeof(pfs_index_record), + i * sizeof(pfs_index_record) + + sizeof(pfs_index_header)); + if (pdbg_unlikely(rrd != rd * sizeof(pfs_index_record))) return -1; for (j = 0; j < rd; j++) psync_interval_tree_add(tree, records[j].offset, @@ -1099,20 +1099,20 @@ int64_t psync_fs_load_interval_tree(int fd, uint64_t size, } static int load_interval_tree(psync_openfile_t *of) { - psync_fs_index_header hdr; + pfs_index_header hdr; int64_t ifs; ifs = pfile_size(of->indexfile); if (pdbg_unlikely(ifs == -1)) return -1; - if (ifs < sizeof(psync_fs_index_header)) { + if (ifs < sizeof(pfs_index_header)) { pdbg_assertw(ifs == 0); - if (pfile_pwrite(of->indexfile, &hdr, sizeof(psync_fs_index_header), - 0) != sizeof(psync_fs_index_header)) + if (pfile_pwrite(of->indexfile, &hdr, sizeof(pfs_index_header), + 0) != sizeof(pfs_index_header)) return -1; else return 0; } - ifs = psync_fs_load_interval_tree(of->indexfile, ifs, &of->writeintervals); + ifs = pfs_load_interval_tree(of->indexfile, ifs, &of->writeintervals); if (ifs == -1) return -1; else { @@ -1137,7 +1137,7 @@ static int open_write_files(psync_openfile_t *of, int trunc) { cachepath = psync_setting_get_string(_PS(fscachepath)); if (of->datafile == INVALID_HANDLE_VALUE) { filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); of->datafile = pfile_open(filename, O_RDWR, O_CREAT | (trunc ? O_TRUNC : 0)); free(filename); @@ -1150,20 +1150,20 @@ static int open_write_files(psync_openfile_t *of, int trunc) { if (pdbg_unlikely(fs == -1)) return -EIO; if (of->encrypted) - of->currentsize = pfscrypto_plain_size(fs); + of->currentsize = pfs_crpt_plain_size(fs); else of->currentsize = fs; } else { pdbg_logf(D_NOTICE, "data file already open"); if (trunc) - return psync_fs_ftruncate_of_locked(of, 0); + return pfs_ftruncate_of_locked(of, 0); else return 0; } if (!of->newfile && of->indexfile == INVALID_HANDLE_VALUE) { fileidhex[sizeof(psync_fsfileid_t)] = 'i'; filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); of->indexfile = pfile_open(filename, O_RDWR, O_CREAT | (trunc ? O_TRUNC : 0)); free(filename); @@ -1183,7 +1183,7 @@ static int open_write_files(psync_openfile_t *of, int trunc) { if (of->logfile == INVALID_HANDLE_VALUE) { fileidhex[sizeof(psync_fsfileid_t)] = 'l'; filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); of->logfile = pfile_open(filename, O_RDWR, O_CREAT | O_TRUNC); free(filename); if (of->logfile == INVALID_HANDLE_VALUE) { @@ -1191,7 +1191,7 @@ static int open_write_files(psync_openfile_t *of, int trunc) { (long)of->fileid); return -EIO; } - ret = pfscrypto_init_log(of); + ret = pfs_crpt_init_log(of); if (ret) { pdbg_logf(D_ERROR, "could not init log file for fileid %ld", (long)of->fileid); @@ -1202,7 +1202,7 @@ static int open_write_files(psync_openfile_t *of, int trunc) { return 0; } -static void psync_fs_del_creat(psync_fspath_t *fpath, psync_openfile_t *of) { +static void pfs_del_creat(psync_fspath_t *fpath, psync_openfile_t *of) { psync_fstask_creat_t *cr; psync_fstask_folder_t *folder; psync_sql_res *res; @@ -1213,26 +1213,26 @@ static void psync_fs_del_creat(psync_fspath_t *fpath, psync_openfile_t *of) { psql_bind_uint(res, 1, -of->fileid); psql_run_free(res); if (psql_affected()) - psync_fsupload_wake(); + pfs_upld_wake(); res = psql_prepare("DELETE FROM fstask WHERE id=?"); psql_bind_uint(res, 1, -of->fileid); psql_run_free(res); psql_commit(); - folder = psync_fstask_get_or_create_folder_tasks_locked(fpath->folderid); + folder = pfs_task_get_or_create_folder_tasks_locked(fpath->folderid); if (likely(folder)) { - if (likely((cr = psync_fstask_find_creat(folder, fpath->name, 0)))) { + if (likely((cr = pfs_task_find_creat(folder, fpath->name, 0)))) { ptree_del(&folder->creats, &cr->tree); folder->taskscnt--; free(cr); } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } - psync_fs_dec_of_refcnt(of); + pfs_dec_of_refcnt(of); psql_unlock(); free(fpath); } -static int psync_fs_open(const char *path, struct fuse_file_info *fi) { +static int pfs_open(const char *path, struct fuse_file_info *fi) { psync_sql_res *res; psync_uint_row row; psync_fsfileid_t fileid; @@ -1246,17 +1246,17 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { size_t encsymkeylen; time_t ctime; int ret, status, type; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "open %s", path); fileid = writeid = hash = size = ctime = 0; psql_lock(); CHECK_LOGIN_LOCKED(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) { psql_unlock(); - ret = psync_fsfolder_crypto_error(); + ret = pfs_fldr_crypto_error(); if (ret) { - ret = -psync_fs_crypto_err_to_errno(ret); + ret = -pfs_crypto_err_to_errno(ret); return pdbg_return(ret); } else { pdbg_logf(D_NOTICE, "returning ENOENT for %s, folder not found", path); @@ -1276,9 +1276,9 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { free(fpath); return -EACCES; } - folder = psync_fstask_get_or_create_folder_tasks_locked(fpath->folderid); + folder = pfs_task_get_or_create_folder_tasks_locked(fpath->folderid); row = NULL; - if ((cr = psync_fstask_find_creat(folder, fpath->name, 0))) { + if ((cr = pfs_task_find_creat(folder, fpath->name, 0))) { if (cr->fileid > 0) { res = psql_query("SELECT id, size, hash, ctime FROM file WHERE id=?"); @@ -1321,15 +1321,15 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { if (fpath->flags & PSYNC_FOLDER_FLAG_ENCRYPTED) { encoder = pcryptofolder_filencoder_get(fileid, hash, 1); if (pdbg_unlikely(psync_crypto_is_error(encoder))) { - ret = -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encoder)); + ret = -pfs_crypto_err_to_errno(psync_crypto_to_error(encoder)); goto ex0; } } else encoder = PSYNC_CRYPTO_INVALID_ENCODER; - of = psync_fs_create_file(fileid, 0, 0, 0, 1, writeid, - psync_fstask_get_ref_locked(folder), + of = pfs_create_file(fileid, 0, 0, 0, 1, writeid, + pfs_task_get_ref_locked(folder), fpath->name, encoder); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); pdbg_logf(D_NOTICE, "opening new file %ld %s", (long)fileid, fpath->name); free(fpath); @@ -1339,7 +1339,7 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { pthread_mutex_unlock(&of->mutex); fi->fh = openfile_to_fh(of); if (pdbg_unlikely(ret)) { - psync_fs_dec_of_refcnt(of); + pfs_dec_of_refcnt(of); return ret; } else return ret; @@ -1375,15 +1375,15 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { if (fpath->flags & PSYNC_FOLDER_FLAG_ENCRYPTED) { encoder = pcryptofolder_filencoder_get(fileid, hash, 1); if (pdbg_unlikely(psync_crypto_is_error(encoder))) { - ret = -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encoder)); + ret = -pfs_crypto_err_to_errno(psync_crypto_to_error(encoder)); goto ex0; } } else encoder = PSYNC_CRYPTO_INVALID_ENCODER; - of = psync_fs_create_file(cr->fileid, fileid, size, hash, 1, writeid, - psync_fstask_get_ref_locked(folder), + of = pfs_create_file(cr->fileid, fileid, size, hash, 1, writeid, + pfs_task_get_ref_locked(folder), fpath->name, encoder); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fpath); of->newfile = 0; @@ -1392,19 +1392,19 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { pthread_mutex_unlock(&of->mutex); fi->fh = openfile_to_fh(of); if (pdbg_unlikely(ret)) { - psync_fs_dec_of_refcnt(of); + pfs_dec_of_refcnt(of); return ret; } else return ret; } else { /* cr->fileid==0 */ psync_fstask_local_creat_t *lc; - lc = psync_fstask_creat_get_local(cr); - of = psync_fs_create_file(INT64_MAX - (UINT64_MAX - cr->taskid), 0, + lc = pfs_task_creat_get_local(cr); + of = pfs_create_file(INT64_MAX - (UINT64_MAX - cr->taskid), 0, lc->datalen, 0, 1, 0, - psync_fstask_get_ref_locked(folder), + pfs_task_get_ref_locked(folder), fpath->name, PSYNC_CRYPTO_INVALID_ENCODER); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fpath); of->modified = 1; @@ -1417,7 +1417,7 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { } } if (!row && fpath->folderid >= 0 && - !psync_fstask_find_unlink(folder, fpath->name, 0)) { + !pfs_task_find_unlink(folder, fpath->name, 0)) { res = psql_query("SELECT id, size, hash, ctime FROM file WHERE " "parentfolderid=? AND name=?"); psql_bind_uint(res, 1, fpath->folderid); @@ -1443,14 +1443,14 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { if (row) { encoder = pcryptofolder_filencoder_get(fileid, hash, 0); if (pdbg_unlikely(psync_crypto_is_error(encoder))) { - ret = -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encoder)); + ret = -pfs_crypto_err_to_errno(psync_crypto_to_error(encoder)); goto ex0; } encsymkey = pcryptofolder_filencoder_key_get(fileid, hash, &encsymkeylen); if (pdbg_unlikely(psync_crypto_is_error(encsymkey))) { pcryptofolder_filencoder_release(fileid, hash, encoder); - ret = -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); + ret = -pfs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); goto ex0; } } else { @@ -1458,7 +1458,7 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { encsymkey = pcryptofolder_filencoder_key_newplain( 0, &encsymkeylen, &symkey); if (pdbg_unlikely(psync_crypto_is_error(encsymkey))) { - ret = -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); + ret = -pfs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); goto ex0; } encoder = pcrypto_sec_encdec_create(symkey); @@ -1475,23 +1475,23 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { encsymkeylen = 0; } cr = - psync_fstask_add_creat(folder, fpath->name, 0, encsymkey, encsymkeylen); + pfs_task_add_creat(folder, fpath->name, 0, encsymkey, encsymkeylen); free(encsymkey); if (pdbg_unlikely(!cr)) { ret = -EIO; goto ex0; } - of = psync_fs_create_file(cr->fileid, 0, 0, 0, 1, 0, - psync_fstask_get_ref_locked(folder), fpath->name, + of = pfs_create_file(cr->fileid, 0, 0, 0, 1, 0, + pfs_task_get_ref_locked(folder), fpath->name, encoder); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); of->newfile = 1; of->modified = 1; ret = open_write_files(of, 1); pthread_mutex_unlock(&of->mutex); if (pdbg_unlikely(ret)) { - psync_fs_del_creat(fpath, of); + pfs_del_creat(fpath, of); return ret; } free(fpath); @@ -1501,13 +1501,13 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { if (fpath->flags & PSYNC_FOLDER_FLAG_ENCRYPTED) { encoder = pcryptofolder_filencoder_get(fileid, hash, 1); if (pdbg_unlikely(psync_crypto_is_error(encoder))) { - ret = -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encoder)); + ret = -pfs_crypto_err_to_errno(psync_crypto_to_error(encoder)); goto ex0; } } else encoder = PSYNC_CRYPTO_INVALID_ENCODER; - of = psync_fs_create_file(fileid, fileid, size, hash, 0, 0, - psync_fstask_get_ref_locked(folder), fpath->name, + of = pfs_create_file(fileid, fileid, size, hash, 0, 0, + pfs_task_get_ref_locked(folder), fpath->name, encoder); of->origctime = ctime; fi->fh = openfile_to_fh(of); @@ -1515,23 +1515,23 @@ static int psync_fs_open(const char *path, struct fuse_file_info *fi) { } else ret = -ENOENT; ex0: - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fpath); return ret; } -static int psync_fs_file_exists_in_folder(psync_fstask_folder_t *folder, +static int pfs_file_exists_in_folder(psync_fstask_folder_t *folder, const char *name) { psync_fstask_creat_t *cr; psync_sql_res *res; psync_uint_row row; - cr = psync_fstask_find_creat(folder, name, 0); + cr = pfs_task_find_creat(folder, name, 0); if (cr) return 1; if (folder->folderid < 0) return 0; - if (psync_fstask_find_unlink(folder, name, 0)) + if (pfs_task_find_unlink(folder, name, 0)) return 0; res = psql_query("SELECT id FROM file WHERE parentfolderid=? AND name=?"); @@ -1542,7 +1542,7 @@ static int psync_fs_file_exists_in_folder(psync_fstask_folder_t *folder, return row ? 1 : 0; } -static int psync_fs_creat_fake_locked(psync_fspath_t *fpath, +static int pfs_creat_fake_locked(psync_fspath_t *fpath, struct fuse_file_info *fi) { psync_fstask_creat_t *cr; psync_fstask_folder_t *folder; @@ -1557,12 +1557,12 @@ static int psync_fs_creat_fake_locked(psync_fspath_t *fpath, cr->rfileid = 0; cr->taskid = fileid; memcpy(cr->name, fpath->name, len); - folder = psync_fstask_get_or_create_folder_tasks_locked(fpath->folderid); - psync_fstask_inject_creat(folder, cr); - of = psync_fs_create_file(fileid, 0, 0, 0, 0, 0, - psync_fstask_get_ref_locked(folder), fpath->name, + folder = pfs_task_get_or_create_folder_tasks_locked(fpath->folderid); + pfs_task_inject_creat(folder, cr); + of = pfs_create_file(fileid, 0, 0, 0, 0, 0, + pfs_task_get_ref_locked(folder), fpath->name, PSYNC_CRYPTO_INVALID_ENCODER); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); of->newfile = 0; of->modified = 0; psql_unlock(); @@ -1571,7 +1571,7 @@ static int psync_fs_creat_fake_locked(psync_fspath_t *fpath, return 0; } -static int psync_fs_creat(const char *path, mode_t mode, +static int pfs_creat(const char *path, mode_t mode, struct fuse_file_info *fi) { psync_fspath_t *fpath; psync_fstask_folder_t *folder; @@ -1582,25 +1582,25 @@ static int psync_fs_creat(const char *path, mode_t mode, size_t encsymkeylen; psync_openfile_t *of; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "creat %s", path); psql_lock(); CHECK_LOGIN_LOCKED(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) { psql_unlock(); - ret = psync_fsfolder_crypto_error(); + ret = pfs_fldr_crypto_error(); if (ret) { - ret = psync_fs_crypto_err_to_errno(ret); + ret = pfs_crypto_err_to_errno(ret); return pdbg_return(-ret); } else { pdbg_logf(D_NOTICE, "returning ENOENT for %s, folder not found", path); return -ENOENT; } } - if (unlikely(psync_fs_need_per_folder_refresh_const() && - !strncmp(psync_fake_prefix, fpath->name, psync_fake_prefix_len))) - return psync_fs_creat_fake_locked(fpath, fi); + if (unlikely(pfs_need_per_folder_refresh_const() && + !strncmp(pfs_fake_prefix, fpath->name, pfs_fake_prefix_len))) + return pfs_creat_fake_locked(fpath, fi); if (!(fpath->permissions & PSYNC_PERM_CREATE) || (fpath->flags & (PSYNC_FOLDER_FLAG_BACKUP_DEVICE_LIST | PSYNC_FOLDER_FLAG_BACKUP_DEVICE))) { @@ -1608,18 +1608,18 @@ static int psync_fs_creat(const char *path, mode_t mode, free(fpath); return -EACCES; } - folder = psync_fstask_get_or_create_folder_tasks_locked(fpath->folderid); - if (psync_fs_file_exists_in_folder(folder, fpath->name)) { - psync_fstask_release_folder_tasks_locked(folder); + folder = pfs_task_get_or_create_folder_tasks_locked(fpath->folderid); + if (pfs_file_exists_in_folder(folder, fpath->name)) { + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_NOTICE, "file %s already exists, processing as open", path); - ret = psync_fs_open(path, fi); + ret = pfs_open(path, fi); psql_unlock(); free(fpath); return ret; } if (fpath->flags & PSYNC_FOLDER_FLAG_ENCRYPTED) { if (psync_crypto_isexpired()) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fpath); return -pdbg_return_const(PSYNC_FS_ERR_CRYPTO_EXPIRED); @@ -1627,15 +1627,15 @@ static int psync_fs_creat(const char *path, mode_t mode, encsymkey = pcryptofolder_filencoder_key_newplain( 0, &encsymkeylen, &symkey); if (pdbg_unlikely(psync_crypto_is_error(encsymkey))) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fpath); - return -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); + return -pfs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); } encoder = pcrypto_sec_encdec_create(symkey); psymkey_free(symkey); if (pdbg_unlikely(encoder == PSYNC_CRYPTO_INVALID_ENCODER)) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fpath); free(encsymkey); @@ -1646,26 +1646,26 @@ static int psync_fs_creat(const char *path, mode_t mode, encsymkey = NULL; encsymkeylen = 0; } - cr = psync_fstask_add_creat(folder, fpath->name, 0, encsymkey, encsymkeylen); + cr = pfs_task_add_creat(folder, fpath->name, 0, encsymkey, encsymkeylen); if (encsymkey) free(encsymkey); if (pdbg_unlikely(!cr)) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fpath); return -EIO; } - of = psync_fs_create_file(cr->fileid, 0, 0, 0, 1, 0, - psync_fstask_get_ref_locked(folder), fpath->name, + of = pfs_create_file(cr->fileid, 0, 0, 0, 1, 0, + pfs_task_get_ref_locked(folder), fpath->name, encoder); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); of->newfile = 1; of->modified = 1; ret = open_write_files(of, 1); pthread_mutex_unlock(&of->mutex); if (pdbg_unlikely(ret)) { - psync_fs_del_creat(fpath, of); + pfs_del_creat(fpath, of); return ret; } free(fpath); @@ -1673,11 +1673,11 @@ static int psync_fs_creat(const char *path, mode_t mode, return 0; } -void psync_fs_inc_of_refcnt_locked(psync_openfile_t *of) { of->refcnt++; } +void pfs_inc_of_refcnt_locked(psync_openfile_t *of) { of->refcnt++; } -void psync_fs_inc_of_refcnt(psync_openfile_t *of) { - psync_fs_lock_file(of); - psync_fs_inc_of_refcnt_locked(of); +void pfs_inc_of_refcnt(psync_openfile_t *of) { + pfs_lock_file(of); + pfs_inc_of_refcnt_locked(of); pthread_mutex_unlock(&of->mutex); } @@ -1686,7 +1686,7 @@ static void close_if_valid(int fd) { pfile_close(fd); } -static void psync_fs_free_openfile(psync_openfile_t *of) { +static void pfs_free_openfile(psync_openfile_t *of) { pdbg_logf(D_NOTICE, "releasing file %s", of->currentname); if (unlikely(of->writetimer != PSYNC_INVALID_TIMER)) pdbg_logf(D_BUG, @@ -1701,7 +1701,7 @@ static void psync_fs_free_openfile(psync_openfile_t *of) { "UPDATE fstask SET status=11 WHERE id=? AND status=12"); psql_bind_uint(res, 1, -of->fileid); psql_run_free(res); - psync_fsupload_wake(); + pfs_upld_wake(); } if (of->encrypted) { if (of->encoder != PSYNC_CRYPTO_UNLOADED_SECTOR_ENCODER && @@ -1721,11 +1721,11 @@ static void psync_fs_free_openfile(psync_openfile_t *of) { close_if_valid(of->indexfile); if (of->writeintervals) psync_interval_tree_free(of->writeintervals); - if (unlikely(psync_fs_need_per_folder_refresh_const() && + if (unlikely(pfs_need_per_folder_refresh_const() && of->fileid < psync_fake_fileid)) { psync_fstask_creat_t *cr; psql_lock(); - cr = psync_fstask_find_creat(of->currentfolder, of->currentname, 0); + cr = pfs_task_find_creat(of->currentfolder, of->currentname, 0); if (cr) { ptree_del(&of->currentfolder->creats, &cr->tree); of->currentfolder->taskscnt--; @@ -1733,17 +1733,17 @@ static void psync_fs_free_openfile(psync_openfile_t *of) { } psql_unlock(); } - psync_fstask_release_folder_tasks(of->currentfolder); + pfs_task_release_folder_tasks(of->currentfolder); free(of->currentname); free(of); } -static void psync_fs_get_both_locks(psync_openfile_t *of) { +static void pfs_get_both_locks(psync_openfile_t *of) { retry: psql_lock(); if (pthread_mutex_trylock(&of->mutex)) { psql_unlock(); - psync_fs_lock_file(of); + pfs_lock_file(of); if (psql_trylock()) { pthread_mutex_unlock(&of->mutex); psys_sleep_milliseconds(1); @@ -1752,28 +1752,28 @@ retry: } } -void psync_fs_dec_of_refcnt(psync_openfile_t *of) { +void pfs_dec_of_refcnt(psync_openfile_t *of) { uint32_t refcnt; - psync_fs_get_both_locks(of); + pfs_get_both_locks(of); refcnt = --of->refcnt; if (!refcnt) ptree_del(&openfiles, &of->tree); psql_unlock(); pthread_mutex_unlock(&of->mutex); if (!refcnt) - psync_fs_free_openfile(of); + pfs_free_openfile(of); } -void psync_fs_inc_of_refcnt_and_readers(psync_openfile_t *of) { - psync_fs_lock_file(of); +void pfs_inc_of_refcnt_and_readers(psync_openfile_t *of) { + pfs_lock_file(of); of->refcnt++; of->runningreads++; pthread_mutex_unlock(&of->mutex); } -void psync_fs_dec_of_refcnt_and_readers(psync_openfile_t *of) { +void pfs_dec_of_refcnt_and_readers(psync_openfile_t *of) { uint32_t refcnt; - psync_fs_get_both_locks(of); + pfs_get_both_locks(of); of->runningreads--; refcnt = --of->refcnt; if (refcnt == 0) @@ -1781,7 +1781,7 @@ void psync_fs_dec_of_refcnt_and_readers(psync_openfile_t *of) { psql_unlock(); pthread_mutex_unlock(&of->mutex); if (!refcnt) - psync_fs_free_openfile(of); + pfs_free_openfile(of); } typedef struct { @@ -1789,7 +1789,7 @@ typedef struct { uint64_t writeid; } psync_openfile_writeid_t; -static void psync_fs_upload_release_timer(void *ptr) { +static void pfs_upload_release_timer(void *ptr) { psync_sql_res *res; psync_openfile_writeid_t *ofw; uint32_t aff; @@ -1805,7 +1805,7 @@ static void psync_fs_upload_release_timer(void *ptr) { aff = psql_affected(); psql_free(res); if (aff) - psync_fsupload_wake(); + pfs_upld_wake(); else { res = psql_prepare( "UPDATE fstask SET int1=? WHERE id=? AND int1writeid); psql_run_free(res); } - psync_fs_dec_of_refcnt(ofw->of); + pfs_dec_of_refcnt(ofw->of); free(ofw); pstatus_upload_recalc_async(); } -static void psync_fs_write_timer(psync_timer_t timer, void *ptr) { +static void pfs_write_timer(psync_timer_t timer, void *ptr) { psync_openfile_t *of; of = (psync_openfile_t *)ptr; - psync_fs_lock_file(of); + pfs_lock_file(of); ptimer_stop(timer); of->writetimer = PSYNC_INVALID_TIMER; pdbg_logf(D_NOTICE, "got write timer for file %s", of->currentname); @@ -1834,7 +1834,7 @@ static void psync_fs_write_timer(psync_timer_t timer, void *ptr) { pdbg_logf(D_ERROR, "file is static file, which should not generally happen"); goto unlock_ex; } - if (unlikely(of->encrypted && pfscrypto_flush(of))) { + if (unlikely(of->encrypted && pfs_crpt_flush(of))) { pdbg_logf(D_WARNING, "we are in timer and we failed to flush crypto file, life sux"); goto unlock_ex; @@ -1845,22 +1845,22 @@ static void psync_fs_write_timer(psync_timer_t timer, void *ptr) { ofw->writeid = of->writeid; pthread_mutex_unlock(&of->mutex); pdbg_logf(D_NOTICE, "running separate thread to release file for upload"); - prun_thread1("upload release timer", psync_fs_upload_release_timer, + prun_thread1("upload release timer", pfs_upload_release_timer, ofw); return; } else pdbg_logf(D_NOTICE, "file seems to be already uploaded"); unlock_ex: pthread_mutex_unlock(&of->mutex); - psync_fs_dec_of_refcnt(of); + pfs_dec_of_refcnt(of); } -static int psync_fs_flush(const char *path, struct fuse_file_info *fi) { +static int pfs_flush(const char *path, struct fuse_file_info *fi) { psync_openfile_t *of; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "flush %s", path); of = fh_to_openfile(fi->fh); - psync_fs_lock_file(of); + pfs_lock_file(of); if (of->modified) { psync_sql_res *res; uint64_t writeid; @@ -1872,7 +1872,7 @@ static int psync_fs_flush(const char *path, struct fuse_file_info *fi) { } writeid = of->writeid; if (of->encrypted) { - ret = pfscrypto_flush(of); + ret = pfs_crpt_flush(of); if (pdbg_unlikely(ret)) { pthread_mutex_unlock(&of->mutex); return ret; @@ -1897,7 +1897,7 @@ static int psync_fs_flush(const char *path, struct fuse_file_info *fi) { aff = psql_affected(); psql_free(res); if (aff) - psync_fsupload_wake(); + pfs_upld_wake(); else { res = psql_prepare( "UPDATE fstask SET int1=? WHERE id=? AND int1fh)); + pfs_flush(path, fi); + pfs_dec_of_refcnt(fh_to_openfile(fi->fh)); return 0; } -static int psync_fs_fsync(const char *path, int datasync, +static int pfs_fsync(const char *path, int datasync, struct fuse_file_info *fi) { psync_openfile_t *of; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "fsync %s", path); of = fh_to_openfile(fi->fh); - psync_fs_lock_file(of); + pfs_lock_file(of); if (!of->modified || of->staticfile) { pthread_mutex_unlock(&of->mutex); return 0; } if (of->encrypted) { - ret = pfscrypto_flush(of); + ret = pfs_crpt_flush(of); if (pdbg_unlikely(ret)) { pthread_mutex_unlock(&of->mutex); return ret; @@ -1951,9 +1951,9 @@ static int psync_fs_fsync(const char *path, int datasync, return 0; } -static int psync_fs_fsyncdir(const char *path, int datasync, +static int pfs_fsyncdir(const char *path, int datasync, struct fuse_file_info *fi) { - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "fsyncdir %s", path); if (pdbg_unlikely(psql_sync())) return -EIO; @@ -1990,14 +1990,14 @@ static int psync_read_staticfile(psync_openfile_t *of, char *buf, uint64_t size, return ret; } -static int psync_fs_read(const char *path, char *buf, size_t size, +static int pfs_read(const char *path, char *buf, size_t size, fuse_off_t offset, struct fuse_file_info *fi) { psync_openfile_t *of; time_t currenttime; - psync_fs_set_thread_name(); + pfs_set_thread_name(); of = fh_to_openfile(fi->fh); currenttime = ptimer_time(); - psync_fs_lock_file(of); + pfs_lock_file(of); if (of->currentsec == currenttime) { of->bytesthissec += size; if (of->currentspeed < of->bytesthissec) @@ -2016,9 +2016,9 @@ static int psync_fs_read(const char *path, char *buf, size_t size, } if (of->encrypted) { if (of->newfile) - return pfscrypto_read_new(of, buf, size, offset); + return pfs_crpt_read_new(of, buf, size, offset); else if (of->modified) - return pfscrypto_read_mod(of, buf, size, offset); + return pfs_crpt_read_mod(of, buf, size, offset); else return ppagecache_read_unmod_enc_locked(of, buf, size, offset); @@ -2035,19 +2035,19 @@ static int psync_fs_read(const char *path, char *buf, size_t size, } } -static void psync_fs_inc_writeid_locked(psync_openfile_t *of) { +static void pfs_inc_writeid_locked(psync_openfile_t *of) { if (unlikely(of->releasedforupload)) { if (unlikely(psql_trylock())) { pthread_mutex_unlock(&of->mutex); psql_lock(); - psync_fs_lock_file(of); + pfs_lock_file(of); } if (of->releasedforupload) { of->releasedforupload = 0; pdbg_logf(D_NOTICE, "stopping upload of file %s as new write arrived", of->currentname); pdbg_assertw(of->fileid < 0); - psync_fsupload_stop_upload_locked(-of->fileid); + pfs_upld_stop_upload_locked(-of->fileid); } psql_unlock(); } @@ -2055,13 +2055,13 @@ static void psync_fs_inc_writeid_locked(psync_openfile_t *of) { if (of->writetimer == PSYNC_INVALID_TIMER || !ptimer_stop(of->writetimer)) { if (of->writetimer == PSYNC_INVALID_TIMER) - psync_fs_inc_of_refcnt_locked(of); - of->writetimer = ptimer_register(psync_fs_write_timer, + pfs_inc_of_refcnt_locked(of); + of->writetimer = ptimer_register(pfs_write_timer, PSYNC_UPLOAD_NOWRITE_TIMER, of); } } -static int psync_fs_modfile_check_size_ok(psync_openfile_t *of, uint64_t size) { +static int pfs_modfile_check_size_ok(psync_openfile_t *of, uint64_t size) { if (unlikely(of->currentsize < size)) { pdbg_logf(D_NOTICE, "extending file %s from %lu to %lu bytes", of->currentname, (unsigned long)of->currentsize, (unsigned long)size); @@ -2071,7 +2071,7 @@ static int psync_fs_modfile_check_size_ok(psync_openfile_t *of, uint64_t size) { if (of->newfile) return 0; else { - psync_fs_index_record rec; + pfs_index_record rec; uint64_t ioff; pdbg_assertw(of->modified); ioff = of->indexoff++; @@ -2079,7 +2079,7 @@ static int psync_fs_modfile_check_size_ok(psync_openfile_t *of, uint64_t size) { rec.length = size - of->currentsize; if (pdbg_unlikely(pfile_pwrite(of->indexfile, &rec, sizeof(rec), sizeof(rec) * ioff + - sizeof(psync_fs_index_header)) != + sizeof(pfs_index_header)) != sizeof(rec))) return -1; psync_interval_tree_add(&of->writeintervals, of->currentsize, size); @@ -2090,7 +2090,7 @@ static int psync_fs_modfile_check_size_ok(psync_openfile_t *of, uint64_t size) { } PSYNC_NOINLINE static int -psync_fs_reopen_file_for_writing(psync_openfile_t *of) { +pfs_reopen_file_for_writing(psync_openfile_t *of) { psync_fstask_creat_t *cr; uint64_t size; char *encsymkey; @@ -2106,8 +2106,8 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { pthread_mutex_unlock(&of->mutex); enc = pcryptofolder_filencoder_get(of->remotefileid, of->hash, 0); if (unlikely(psync_crypto_is_error(enc))) - return -psync_fs_crypto_err_to_errno(psync_crypto_to_error(enc)); - psync_fs_lock_file(of); + return -pfs_crypto_err_to_errno(psync_crypto_to_error(enc)); + pfs_lock_file(of); if (of->encoder == PSYNC_CRYPTO_UNLOADED_SECTOR_ENCODER) of->encoder = enc; else @@ -2120,7 +2120,7 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { // case is still !of->newfile && !of->modified pthread_mutex_unlock(&of->mutex); psql_lock(); - psync_fs_lock_file(of); + pfs_lock_file(of); if (of->newfile || of->modified) { psql_unlock(); return 1; @@ -2131,12 +2131,12 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { psql_unlock(); return -pdbg_return_const(PSYNC_FS_ERR_CRYPTO_EXPIRED); } - size = pfscrypto_crypto_size(of->initialsize); + size = pfs_crpt_crypto_size(of->initialsize); encsymkey = pcryptofolder_filencoder_key_get(of->fileid, of->hash, &encsymkeylen); if (pdbg_unlikely(psync_crypto_is_error(encsymkey))) { psql_unlock(); - return -psync_fs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); + return -pfs_crypto_err_to_errno(psync_crypto_to_error(encsymkey)); } } else { encsymkey = NULL; @@ -2150,7 +2150,7 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { "we have all pages of file %s, convert it to new file as they are " "cheaper to work with", of->currentname); - cr = psync_fstask_add_creat(of->currentfolder, of->currentname, of->fileid, + cr = pfs_task_add_creat(of->currentfolder, of->currentname, of->fileid, encsymkey, encsymkeylen); if (pdbg_unlikely(!cr)) { psql_unlock(); @@ -2158,8 +2158,8 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { free(encsymkey); return -EIO; } - psync_fs_update_openfile_fileid_locked(of, cr->fileid); - psync_fs_file_to_task(of->remotefileid, cr->taskid); + pfs_update_openfile_fileid_locked(of, cr->fileid); + pfs_xatr_file_to_task(of->remotefileid, cr->taskid); psql_unlock(); of->newfile = 1; of->modified = 1; @@ -2183,7 +2183,7 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { of->currentsize = of->initialsize; return 1; } - cr = psync_fstask_add_modified_file(of->currentfolder, of->currentname, + cr = pfs_task_add_modified_file(of->currentfolder, of->currentname, of->fileid, of->hash, encsymkey, encsymkeylen); free(encsymkey); @@ -2191,7 +2191,7 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { psql_unlock(); return -EIO; } - psync_fs_update_openfile_fileid_locked(of, cr->fileid); + pfs_update_openfile_fileid_locked(of, cr->fileid); psql_unlock(); ret = open_write_files(of, 0); if (pdbg_unlikely(ret) || @@ -2210,7 +2210,7 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) { } PSYNC_NOINLINE static int -psync_fs_reopen_static_file_for_writing(psync_openfile_t *of) { +pfs_reopen_static_file_for_writing(psync_openfile_t *of) { psync_fstask_creat_t *cr; psync_fstask_unlink_t *un; uint64_t taskid; @@ -2222,7 +2222,7 @@ psync_fs_reopen_static_file_for_writing(psync_openfile_t *of) { // case is still !of->newfile && !of->modified pthread_mutex_unlock(&of->mutex); psql_lock(); - psync_fs_lock_file(of); + pfs_lock_file(of); if (!of->staticfile) { psql_unlock(); return 1; @@ -2231,20 +2231,20 @@ psync_fs_reopen_static_file_for_writing(psync_openfile_t *of) { taskid = UINT64_MAX - (INT64_MAX - of->fileid); pdbg_logf(D_NOTICE, "reopening static file %s for writing size %lu, taskid %lu", of->currentname, (unsigned long)of->currentsize, (unsigned long)taskid); - cr = psync_fstask_add_creat(of->currentfolder, of->currentname, 0, NULL, 0); + cr = pfs_task_add_creat(of->currentfolder, of->currentname, 0, NULL, 0); if (pdbg_unlikely(!cr)) { psql_unlock(); return -EIO; } - psync_fs_update_openfile_fileid_locked(of, cr->fileid); - psync_fs_static_to_task(taskid, cr->taskid); - cr = psync_fstask_find_creat(of->currentfolder, of->currentname, taskid); + pfs_update_openfile_fileid_locked(of, cr->fileid); + pfs_xatr_static_to_task(taskid, cr->taskid); + cr = pfs_task_find_creat(of->currentfolder, of->currentname, taskid); if (pdbg_likely(cr)) { ptree_del(&of->currentfolder->creats, &cr->tree); of->currentfolder->taskscnt--; free(cr); } - un = psync_fstask_find_unlink(of->currentfolder, of->currentname, taskid); + un = pfs_task_find_unlink(of->currentfolder, of->currentname, taskid); if (pdbg_likely(un)) { ptree_del(&of->currentfolder->unlinks, &un->tree); of->currentfolder->taskscnt--; @@ -2267,15 +2267,15 @@ psync_fs_reopen_static_file_for_writing(psync_openfile_t *of) { } PSYNC_NOINLINE static int -psync_fs_check_modified_file_write_space(psync_openfile_t *of, size_t size, +pfs_check_modified_file_write_space(psync_openfile_t *of, size_t size, fuse_off_t offset) { uint64_t from, to; psync_interval_tree_t *tr; if (of->encrypted) { - from = pfscrypto_sector_id(offset / + from = pfs_crpt_sector_id(offset / PSYNC_CRYPTO_SECTOR_SIZE) * PSYNC_CRYPTO_SECTOR_SIZE; - to = pfscrypto_sector_id((offset + size) / + to = pfs_crpt_sector_id((offset + size) / PSYNC_CRYPTO_SECTOR_SIZE) * PSYNC_CRYPTO_SECTOR_SIZE + (offset + size) % PSYNC_CRYPTO_SECTOR_SIZE; @@ -2291,7 +2291,7 @@ psync_fs_check_modified_file_write_space(psync_openfile_t *of, size_t size, return 0; } -static void psync_fs_throttle(size_t size, uint64_t speed) { +static void pfs_throttle(size_t size, uint64_t speed) { static pthread_mutex_t throttle_mutex = PTHREAD_MUTEX_INITIALIZER; static uint64_t writtenthissec = 0; static time_t thissec = 0; @@ -2323,7 +2323,7 @@ static void psync_fs_throttle(size_t size, uint64_t speed) { } } -PSYNC_NOINLINE static int psync_fs_do_check_write_space(psync_openfile_t *of, +PSYNC_NOINLINE static int pfs_do_check_write_space(psync_openfile_t *of, size_t size) { const char *cachepath; uint64_t minlocal, mult, speed; @@ -2379,7 +2379,7 @@ PSYNC_NOINLINE static int psync_fs_do_check_write_space(psync_openfile_t *of, if (freed || ppagecache_free_read(size) >= size) { pdbg_logf(D_NOTICE, "there is no active upload and we managed to free from " "cache, not throttling write"); - psync_fs_lock_file(of); + pfs_lock_file(of); return 1; } } @@ -2393,13 +2393,13 @@ PSYNC_NOINLINE static int psync_fs_do_check_write_space(psync_openfile_t *of, pdbg_logf(D_NOTICE, "limiting write speed to %luKb (%lub)/sec, speed multiplier %lu", (unsigned long)speed / 1024, (unsigned long)speed, (unsigned long)mult); - psync_fs_throttle(size, speed); + pfs_throttle(size, speed); pdbg_logf(D_NOTICE, "continuing write"); - psync_fs_lock_file(of); + pfs_lock_file(of); return 1; } -static int psync_fs_check_write_space(psync_openfile_t *of, size_t size, +static int pfs_check_write_space(psync_openfile_t *of, size_t size, fuse_off_t offset) { if (!of->throttle && of->writeid % 64 != 0) return 1; @@ -2407,18 +2407,18 @@ static int psync_fs_check_write_space(psync_openfile_t *of, size_t size, // if (of->newfile) // return 1; if (of->modified && - psync_fs_check_modified_file_write_space(of, size, offset)) + pfs_check_modified_file_write_space(of, size, offset)) return 1; } - return psync_fs_do_check_write_space(of, size); + return pfs_do_check_write_space(of, size); } -static int psync_fs_write_modified(psync_openfile_t *of, const char *buf, +static int pfs_write_modified(psync_openfile_t *of, const char *buf, size_t size, fuse_off_t offset) { - psync_fs_index_record rec; + pfs_index_record rec; uint64_t ioff; ssize_t bw; - if (pdbg_unlikely(psync_fs_modfile_check_size_ok(of, offset))) + if (pdbg_unlikely(pfs_modfile_check_size_ok(of, offset))) return -EIO; ioff = of->indexoff++; bw = pfile_pwrite(of->datafile, buf, size, offset); @@ -2428,7 +2428,7 @@ static int psync_fs_write_modified(psync_openfile_t *of, const char *buf, rec.length = bw; if (pdbg_unlikely(pfile_pwrite(of->indexfile, &rec, sizeof(rec), sizeof(rec) * ioff + - sizeof(psync_fs_index_header)) != + sizeof(pfs_index_header)) != sizeof(rec))) return -EIO; psync_interval_tree_add(&of->writeintervals, offset, offset + bw); @@ -2437,7 +2437,7 @@ static int psync_fs_write_modified(psync_openfile_t *of, const char *buf, return bw; } -static int psync_fs_write_newfile(psync_openfile_t *of, const char *buf, +static int pfs_write_newfile(psync_openfile_t *of, const char *buf, size_t size, fuse_off_t offset) { ssize_t bw; bw = pfile_pwrite(of->datafile, buf, size, offset); @@ -2446,25 +2446,25 @@ static int psync_fs_write_newfile(psync_openfile_t *of, const char *buf, return bw; } -static int psync_fs_write(const char *path, const char *buf, size_t size, +static int pfs_write(const char *path, const char *buf, size_t size, fuse_off_t offset, struct fuse_file_info *fi) { psync_openfile_t *of; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); // pdbg_logf(D_NOTICE, "write to %s of %lu at %lu", path, (unsigned long)size, // (unsigned long)offset); of = fh_to_openfile(fi->fh); - psync_fs_lock_file(of); - ret = psync_fs_check_write_space(of, size, offset); + pfs_lock_file(of); + ret = pfs_check_write_space(of, size, offset); if (pdbg_unlikely(ret <= 0)) return ret; - psync_fs_inc_writeid_locked(of); + pfs_inc_writeid_locked(of); retry: if (of->newfile) { if (of->encrypted) - return pfscrypto_write_new(of, buf, size, offset); + return pfs_crpt_write_new(of, buf, size, offset); else - ret = psync_fs_write_newfile(of, buf, size, offset); + ret = pfs_write_newfile(of, buf, size, offset); pthread_mutex_unlock(&of->mutex); if (pdbg_unlikely(ret == -1)) return -EIO; @@ -2472,7 +2472,7 @@ retry: return ret; } else { if (unlikely(!of->modified)) { - ret = psync_fs_reopen_file_for_writing(of); + ret = pfs_reopen_file_for_writing(of); if (ret == 1) goto retry; else if (ret < 0) { @@ -2481,12 +2481,12 @@ retry: } } if (of->encrypted) - return pfscrypto_write_mod(of, buf, size, offset); + return pfs_crpt_write_mod(of, buf, size, offset); else { pdbg_logf(D_NOTICE, "write of %lu bytes at offset %lu", (unsigned long)size, (unsigned long)offset); if (unlikely(of->staticfile)) { - ret = psync_fs_reopen_static_file_for_writing(of); + ret = pfs_reopen_static_file_for_writing(of); if (ret == 1) goto retry; else { @@ -2494,21 +2494,21 @@ retry: return ret; } } else - ret = psync_fs_write_modified(of, buf, size, offset); + ret = pfs_write_modified(of, buf, size, offset); } pthread_mutex_unlock(&of->mutex); return ret; } } -static int psync_fs_mkdir(const char *path, mode_t mode) { +static int pfs_mkdir(const char *path, mode_t mode) { psync_fspath_t *fpath; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "mkdir %s", path); psql_lock(); CHECK_LOGIN_LOCKED(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) ret = -ENOENT; else if (!(fpath->permissions & PSYNC_PERM_CREATE)) @@ -2520,7 +2520,7 @@ static int psync_fs_mkdir(const char *path, mode_t mode) { psync_crypto_isexpired()) ret = -PSYNC_FS_ERR_CRYPTO_EXPIRED; else - ret = psync_fstask_mkdir(fpath->folderid, fpath->name, fpath->flags); + ret = pfs_task_mkdir(fpath->folderid, fpath->name, fpath->flags); psql_unlock(); free(fpath); pdbg_logf(D_NOTICE, "mkdir %s=%d", path, ret); @@ -2528,19 +2528,19 @@ static int psync_fs_mkdir(const char *path, mode_t mode) { } #if defined(FUSE_HAS_CAN_UNLINK) -static int psync_fs_can_rmdir(const char *path) { +static int pfs_can_rmdir(const char *path) { psync_fspath_t *fpath; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "can_rmdir %s", path); psql_lock(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) ret = -ENOENT; else if (!(fpath->permissions & PSYNC_PERM_DELETE)) ret = -EACCES; else - ret = psync_fstask_can_rmdir(fpath->folderid, fpath->flags, fpath->name); + ret = pfs_task_can_rmdir(fpath->folderid, fpath->flags, fpath->name); psql_unlock(); free(fpath); pdbg_logf(D_NOTICE, "can_rmdir %s=%d", path, ret); @@ -2548,20 +2548,20 @@ static int psync_fs_can_rmdir(const char *path) { } #endif -static int psync_fs_rmdir(const char *path) { +static int pfs_rmdir(const char *path) { psync_fspath_t *fpath; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "rmdir %s", path); psql_lock(); CHECK_LOGIN_LOCKED(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) ret = -ENOENT; else if (!(fpath->permissions & PSYNC_PERM_DELETE)) ret = -EACCES; else - ret = psync_fstask_rmdir(fpath->folderid, fpath->flags, fpath->name); + ret = pfs_task_rmdir(fpath->folderid, fpath->flags, fpath->name); psql_unlock(); free(fpath); pdbg_logf(D_NOTICE, "rmdir %s=%d", path, ret); @@ -2569,19 +2569,19 @@ static int psync_fs_rmdir(const char *path) { } #if defined(FUSE_HAS_CAN_UNLINK) -static int psync_fs_can_unlink(const char *path) { +static int pfs_can_unlink(const char *path) { psync_fspath_t *fpath; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "can_unlink %s", path); psql_lock(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) ret = -ENOENT; else if (!(fpath->permissions & PSYNC_PERM_DELETE)) ret = -EACCES; else - ret = psync_fstask_can_unlink(fpath->folderid, fpath->name); + ret = pfs_task_can_unlink(fpath->folderid, fpath->name); psql_unlock(); free(fpath); pdbg_logf(D_NOTICE, "can_unlink %s=%d", path, ret); @@ -2589,20 +2589,20 @@ static int psync_fs_can_unlink(const char *path) { } #endif -static int psync_fs_unlink(const char *path) { +static int pfs_unlink(const char *path) { psync_fspath_t *fpath; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "unlink %s", path); psql_lock(); CHECK_LOGIN_LOCKED(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) ret = -ENOENT; else if (!(fpath->permissions & PSYNC_PERM_DELETE)) ret = -EACCES; else - ret = psync_fstask_unlink(fpath->folderid, fpath->name); + ret = pfs_task_unlink(fpath->folderid, fpath->name); psql_unlock(); if ((fpath->flags & PSYNC_FOLDER_FLAG_BACKUP) && ret == 0) { @@ -2619,7 +2619,7 @@ static int psync_fs_unlink(const char *path) { return ret; } -static int psync_fs_rename_static_file(psync_fstask_folder_t *srcfolder, +static int pfs_rename_static_file(psync_fstask_folder_t *srcfolder, psync_fstask_creat_t *srccr, psync_fsfolderid_t to_folderid, const char *new_name) { @@ -2627,12 +2627,12 @@ static int psync_fs_rename_static_file(psync_fstask_folder_t *srcfolder, psync_fstask_unlink_t *un; psync_fstask_folder_t *dstfolder; size_t len, addlen; - dstfolder = psync_fstask_get_or_create_folder_tasks_locked(to_folderid); - cr = psync_fstask_find_creat(dstfolder, new_name, 0); + dstfolder = pfs_task_get_or_create_folder_tasks_locked(to_folderid); + cr = pfs_task_find_creat(dstfolder, new_name, 0); if (unlikely(cr)) { pdbg_logf(D_NOTICE, "renaming over creat of file %s in folderid %ld", new_name, (long)to_folderid); - un = psync_fstask_find_unlink(dstfolder, new_name, cr->taskid); + un = pfs_task_find_unlink(dstfolder, new_name, cr->taskid); if (un) { ptree_del(&dstfolder->unlinks, &un->tree); free(un); @@ -2648,19 +2648,19 @@ static int psync_fs_rename_static_file(psync_fstask_folder_t *srcfolder, un->fileid = 0; un->taskid = srccr->taskid; memcpy(un->name, new_name, len); - psync_fstask_inject_unlink(dstfolder, un); - addlen = psync_fstask_creat_local_offset(len - 1); + pfs_task_inject_unlink(dstfolder, un); + addlen = pfs_task_creat_local_offset(len - 1); cr = (psync_fstask_creat_t *)malloc(addlen + sizeof(psync_fstask_local_creat_t)); cr->fileid = 0; cr->rfileid = 0; cr->taskid = srccr->taskid; memcpy(cr->name, new_name, len); - memcpy(((char *)cr) + addlen, psync_fstask_creat_get_local(srccr), + memcpy(((char *)cr) + addlen, pfs_task_creat_get_local(srccr), sizeof(psync_fstask_local_creat_t)); - psync_fstask_inject_creat(dstfolder, cr); - psync_fstask_release_folder_tasks_locked(dstfolder); - un = psync_fstask_find_unlink(srcfolder, srccr->name, srccr->taskid); + pfs_task_inject_creat(dstfolder, cr); + pfs_task_release_folder_tasks_locked(dstfolder); + un = pfs_task_find_unlink(srcfolder, srccr->name, srccr->taskid); if (pdbg_likely(un)) { ptree_del(&srcfolder->unlinks, &un->tree); free(un); @@ -2672,7 +2672,7 @@ static int psync_fs_rename_static_file(psync_fstask_folder_t *srcfolder, return 0; } -static int psync_fs_can_move(psync_fsfolderid_t fromfolderid, +static int pfs_can_move(psync_fsfolderid_t fromfolderid, uint32_t frompermissions, psync_fsfolderid_t tofolderid, uint32_t topermissions, int sameshare) { @@ -2691,45 +2691,45 @@ static int psync_fs_can_move(psync_fsfolderid_t fromfolderid, (topermissions & PSYNC_PERM_CREATE); } -static int psync_fs_rename_folder(psync_fsfolderid_t folderid, +static int pfs_rename_folder(psync_fsfolderid_t folderid, psync_fsfolderid_t parentfolderid, const char *name, uint32_t srcpermissions, psync_fsfolderid_t to_folderid, const char *new_name, uint32_t targetperms, uint32_t targetflags, int sameshare) { - if (!psync_fs_can_move(folderid, srcpermissions, to_folderid, targetperms, + if (!pfs_can_move(folderid, srcpermissions, to_folderid, targetperms, sameshare)) return -EACCES; - return psync_fstask_rename_folder(folderid, parentfolderid, name, to_folderid, + return pfs_task_rename_folder(folderid, parentfolderid, name, to_folderid, new_name, targetflags); } -static int psync_fs_rename_file(psync_fsfileid_t fileid, +static int pfs_rename_file(psync_fsfileid_t fileid, psync_fsfolderid_t parentfolderid, const char *name, uint32_t srcpermissions, psync_fsfolderid_t to_folderid, const char *new_name, uint32_t targetperms, int sameshare) { - if (!psync_fs_can_move(parentfolderid, srcpermissions, to_folderid, + if (!pfs_can_move(parentfolderid, srcpermissions, to_folderid, targetperms, sameshare)) return -EACCES; - return psync_fstask_rename_file(fileid, parentfolderid, name, to_folderid, + return pfs_task_rename_file(fileid, parentfolderid, name, to_folderid, new_name); } -static int psync_fs_is_file(psync_fsfolderid_t folderid, const char *name) { +static int pfs_is_file(psync_fsfolderid_t folderid, const char *name) { psync_fstask_folder_t *folder; psync_sql_res *res; int ret; - folder = psync_fstask_get_folder_tasks_locked(folderid); + folder = pfs_task_get_folder_tasks_locked(folderid); if (folder) { - if (psync_fstask_find_creat(folder, name, 0)) + if (pfs_task_find_creat(folder, name, 0)) ret = 2; - else if (psync_fstask_find_unlink(folder, name, 0)) + else if (pfs_task_find_unlink(folder, name, 0)) ret = 1; else ret = 0; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (ret) return ret - 1; } @@ -2745,19 +2745,19 @@ static int psync_fs_is_file(psync_fsfolderid_t folderid, const char *name) { return ret; } -static int psync_fs_is_folder(psync_fsfolderid_t folderid, const char *name) { +static int pfs_is_folder(psync_fsfolderid_t folderid, const char *name) { psync_fstask_folder_t *folder; psync_sql_res *res; int ret; - folder = psync_fstask_get_folder_tasks_locked(folderid); + folder = pfs_task_get_folder_tasks_locked(folderid); if (folder) { - if (psync_fstask_find_mkdir(folder, name, 0)) + if (pfs_task_find_mkdir(folder, name, 0)) ret = 2; - else if (psync_fstask_find_rmdir(folder, name, 0)) + else if (pfs_task_find_rmdir(folder, name, 0)) ret = 1; else ret = 0; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (ret) return ret - 1; } @@ -2773,43 +2773,43 @@ static int psync_fs_is_folder(psync_fsfolderid_t folderid, const char *name) { return ret; } -static int psync_fs_is_folder_nonempty(psync_fsfolderid_t folderid) { +static int pfs_is_folder_nonempty(psync_fsfolderid_t folderid) { psync_fstask_folder_t *folder; psync_sql_res *res; psync_str_row row; - folder = psync_fstask_get_folder_tasks_locked(folderid); + folder = pfs_task_get_folder_tasks_locked(folderid); if (folder && (folder->creats || folder->mkdirs)) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return 1; } if (folderid >= 0) { res = psql_query("SELECT name FROM file WHERE parentfolderid=?"); psql_bind_uint(res, 1, folderid); while ((row = psql_fetch_str(res))) - if (!folder || !psync_fstask_find_unlink(folder, row[0], 0)) { + if (!folder || !pfs_task_find_unlink(folder, row[0], 0)) { psql_free(res); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return 1; } psql_free(res); res = psql_query("SELECT name FROM folder WHERE parentfolderid=?"); psql_bind_uint(res, 1, folderid); while ((row = psql_fetch_str(res))) - if (!folder || !psync_fstask_find_rmdir(folder, row[0], 0)) { + if (!folder || !pfs_task_find_rmdir(folder, row[0], 0)) { psql_free(res); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return 1; } psql_free(res); } if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return 0; } -static int psync_fs_is_nonempty_folder(psync_fsfolderid_t parent_folderid, +static int pfs_is_nonempty_folder(psync_fsfolderid_t parent_folderid, const char *name) { psync_fstask_folder_t *folder; psync_fstask_mkdir_t *mk; @@ -2817,18 +2817,18 @@ static int psync_fs_is_nonempty_folder(psync_fsfolderid_t parent_folderid, psync_uint_row row; int ret; - folder = psync_fstask_get_folder_tasks_locked(parent_folderid); + folder = pfs_task_get_folder_tasks_locked(parent_folderid); if (folder) { - if ((mk = psync_fstask_find_mkdir(folder, name, 0))) { - ret = psync_fs_is_folder_nonempty(mk->folderid) + 1; - } else if (psync_fstask_find_rmdir(folder, name, 0)) { + if ((mk = pfs_task_find_mkdir(folder, name, 0))) { + ret = pfs_is_folder_nonempty(mk->folderid) + 1; + } else if (pfs_task_find_rmdir(folder, name, 0)) { ret = 1; } else { ret = 0; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (ret) return ret - 1; @@ -2840,7 +2840,7 @@ static int psync_fs_is_nonempty_folder(psync_fsfolderid_t parent_folderid, psql_bind_str(res, 2, name); if ((row = psql_fetch_int(res))) { - ret = psync_fs_is_folder_nonempty(row[0]); + ret = pfs_is_folder_nonempty(row[0]); } else { ret = 0; } @@ -2850,7 +2850,7 @@ static int psync_fs_is_nonempty_folder(psync_fsfolderid_t parent_folderid, return ret; } -static int psync_fs_rename(const char *old_path, const char *new_path) { +static int pfs_rename(const char *old_path, const char *new_path) { psync_fspath_t *fold_path, *fnew_path; psync_sql_res *res; psync_fstask_folder_t *folder; @@ -2864,13 +2864,13 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "rename %s to %s", old_path, new_path); folder = NULL; psql_lock(); CHECK_LOGIN_LOCKED(); - fold_path = psync_fsfolder_resolve_path(old_path); - fnew_path = psync_fsfolder_resolve_path(new_path); + fold_path = pfs_fldr_resolve_path(old_path); + fnew_path = pfs_fldr_resolve_path(new_path); if (!fold_path || !fnew_path) goto err_enoent; @@ -2889,21 +2889,21 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { goto finish; } - folder = psync_fstask_get_folder_tasks_locked(fold_path->folderid); + folder = pfs_task_get_folder_tasks_locked(fold_path->folderid); - new_fid = psync_get_folderid(fnew_path->folderid, fnew_path->name); - old_fid = psync_get_folderid(fold_path->folderid, fold_path->name); + new_fid = pfs_fldr_get_folderid(fnew_path->folderid, fnew_path->name); + old_fid = pfs_fldr_get_folderid(fold_path->folderid, fold_path->name); if (folder) { - if ((mkdir = psync_fstask_find_mkdir(folder, fold_path->name, 0))) { - if (psync_fs_is_file(fnew_path->folderid, fnew_path->name)) { + if ((mkdir = pfs_task_find_mkdir(folder, fold_path->name, 0))) { + if (pfs_is_file(fnew_path->folderid, fnew_path->name)) { ret = -ENOTDIR; - } else if (psync_fs_is_nonempty_folder(fnew_path->folderid, + } else if (pfs_is_nonempty_folder(fnew_path->folderid, fnew_path->name) && (new_fid != old_fid)) { ret = -ENOTEMPTY; } else { - ret = psync_fs_rename_folder(mkdir->folderid, fold_path->folderid, + ret = pfs_rename_folder(mkdir->folderid, fold_path->folderid, fold_path->name, fold_path->permissions, fnew_path->folderid, fnew_path->name, fnew_path->permissions, fnew_path->flags, @@ -2911,14 +2911,14 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { } goto finish; - } else if ((creat = psync_fstask_find_creat(folder, fold_path->name, 0))) { - if (psync_fs_is_folder(fnew_path->folderid, fnew_path->name)) + } else if ((creat = pfs_task_find_creat(folder, fold_path->name, 0))) { + if (pfs_is_folder(fnew_path->folderid, fnew_path->name)) ret = -EISDIR; else if (unlikely(creat->fileid == 0)) - ret = psync_fs_rename_static_file(folder, creat, fnew_path->folderid, + ret = pfs_rename_static_file(folder, creat, fnew_path->folderid, fnew_path->name); else - ret = psync_fs_rename_file( + ret = pfs_rename_file( creat->fileid, fold_path->folderid, fold_path->name, fold_path->permissions, fnew_path->folderid, fnew_path->name, fnew_path->permissions, fold_path->shareid == fnew_path->shareid); @@ -2926,7 +2926,7 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { } } - if (!folder || !psync_fstask_find_rmdir(folder, fold_path->name, 0)) { + if (!folder || !pfs_task_find_rmdir(folder, fold_path->name, 0)) { res = psql_query( "SELECT id, flags FROM folder WHERE parentfolderid=? AND name=?"); psql_bind_uint(res, 1, fold_path->folderid); @@ -2943,14 +2943,14 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { PSYNC_FOLDER_FLAG_BACKUP_DEVICE_LIST | PSYNC_FOLDER_FLAG_BACKUP_DEVICE | PSYNC_FOLDER_FLAG_BACKUP_ROOT))) ret = -EPERM; - else if (psync_fs_is_file(fnew_path->folderid, fnew_path->name)) + else if (pfs_is_file(fnew_path->folderid, fnew_path->name)) ret = -ENOTDIR; - else if (psync_fs_is_nonempty_folder(fnew_path->folderid, + else if (pfs_is_nonempty_folder(fnew_path->folderid, fnew_path->name) && (new_fid != old_fid)) { ret = -ENOTEMPTY; } else - ret = psync_fs_rename_folder( + ret = pfs_rename_folder( fid, fold_path->folderid, fold_path->name, fold_path->permissions, fnew_path->folderid, fnew_path->name, fnew_path->permissions, fnew_path->flags, fold_path->shareid == fnew_path->shareid); @@ -2959,7 +2959,7 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { psql_free(res); } - if (!folder || !psync_fstask_find_unlink(folder, fold_path->name, 0)) { + if (!folder || !pfs_task_find_unlink(folder, fold_path->name, 0)) { res = psql_query( "SELECT id FROM file WHERE parentfolderid=? AND name=?"); psql_bind_uint(res, 1, fold_path->folderid); @@ -2967,10 +2967,10 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { if ((row = psql_fetch_int(res))) { fid = row[0]; psql_free(res); - if (psync_fs_is_folder(fnew_path->folderid, fnew_path->name)) + if (pfs_is_folder(fnew_path->folderid, fnew_path->name)) ret = -EISDIR; else - ret = psync_fs_rename_file(fid, fold_path->folderid, fold_path->name, + ret = pfs_rename_file(fid, fold_path->folderid, fold_path->name, fold_path->permissions, fnew_path->folderid, fnew_path->name, fnew_path->permissions, fold_path->shareid == fnew_path->shareid); @@ -2982,7 +2982,7 @@ static int psync_fs_rename(const char *old_path, const char *new_path) { goto err_enoent; finish: if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fold_path); free(fnew_path); @@ -2990,7 +2990,7 @@ finish: new_path); err_enoent: if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); free(fold_path); free(fnew_path); @@ -2998,9 +2998,9 @@ err_enoent: return -ENOENT; } -static int psync_fs_statfs(const char *path, struct statvfs *stbuf) { +static int pfs_statfs(const char *path, struct statvfs *stbuf) { uint64_t q, uq; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "statfs %s", path); if (waitingforlogin) return -EACCES; @@ -3022,23 +3022,23 @@ static int psync_fs_statfs(const char *path, struct statvfs *stbuf) { return 0; } -static int psync_fs_chmod(const char *path, mode_t mode) { - psync_fs_set_thread_name(); +static int pfs_chmod(const char *path, mode_t mode) { + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "chmod %s %u", path, (unsigned)mode); return 0; } -int psync_fs_chown(const char *path, uid_t uid, gid_t gid) { - psync_fs_set_thread_name(); +static int pfs_chown(const char *path, uid_t uid, gid_t gid) { + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "chown %s %u %u", path, (unsigned)uid, (unsigned)gid); return 0; } -static int psync_fs_set_filetime_locked(psync_fsfileid_t fileid, +static int pfs_set_filetime_locked(psync_fsfileid_t fileid, const struct timespec *tv, int crtime, uint64_t current) { if (fileid > 0) - return psync_fstask_set_mtime(fileid, current, tv->tv_sec, crtime); + return pfs_task_set_mtime(fileid, current, tv->tv_sec, crtime); else { char fileidhex[sizeof(psync_fsfileid_t) * 2 + 2], *filename; const char *cachepath; @@ -3065,7 +3065,7 @@ static int psync_fs_set_filetime_locked(psync_fsfileid_t fileid, fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; cachepath = psync_setting_get_string(_PS(fscachepath)); filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); if (fl && fl->datafile != INVALID_HANDLE_VALUE) { pdbg_logf(D_NOTICE, "found open file for file id %ld", (long)fl->fileid); if (crtime) @@ -3088,7 +3088,7 @@ static int psync_fs_set_filetime_locked(psync_fsfileid_t fileid, } } -static int psync_fs_set_foldertime_locked(psync_fsfolderid_t folderid, +static int pfs_set_foldertime_locked(psync_fsfolderid_t folderid, const struct timespec *tv, int crtime, uint64_t current) { pdbg_logf(D_NOTICE, "request to set time of folderid %ld ignored", @@ -3096,7 +3096,7 @@ static int psync_fs_set_foldertime_locked(psync_fsfolderid_t folderid, return 0; } -static int psync_fs_set_time_locked(psync_fsfolderid_t folderid, +static int pfs_set_time_locked(psync_fsfolderid_t folderid, const char *name, const struct timespec *tv, int crtime) { psync_fstask_folder_t *folder; @@ -3106,9 +3106,9 @@ static int psync_fs_set_time_locked(psync_fsfolderid_t folderid, psync_fstask_rmdir_t *rm; psync_sql_res *res; psync_uint_row row; - folder = psync_fstask_get_folder_tasks_rdlocked(folderid); + folder = pfs_task_get_folder_tasks_rdlocked(folderid); if (folder) { - if ((creat = psync_fstask_find_creat(folder, name, 0))) { + if ((creat = pfs_task_find_creat(folder, name, 0))) { if (creat->fileid > 0) { res = psql_query_nolock("SELECT mtime, ctime FROM file WHERE id=?"); @@ -3116,7 +3116,7 @@ static int psync_fs_set_time_locked(psync_fsfolderid_t folderid, if ((row = psql_fetch_int(res))) { uint64_t ctm = row[crtime]; psql_free(res); - return psync_fs_set_filetime_locked(creat->fileid, tv, crtime, ctm); + return pfs_set_filetime_locked(creat->fileid, tv, crtime, ctm); } else { psql_free(res); pdbg_logf(D_WARNING, @@ -3126,12 +3126,12 @@ static int psync_fs_set_time_locked(psync_fsfolderid_t folderid, return -ENOENT; } } else - return psync_fs_set_filetime_locked(creat->fileid, tv, crtime, 0); + return pfs_set_filetime_locked(creat->fileid, tv, crtime, 0); } - if ((mkdir = psync_fstask_find_mkdir(folder, name, 0))) - return psync_fs_set_foldertime_locked(mkdir->folderid, tv, crtime, 0); - un = psync_fstask_find_unlink(folder, name, 0); - rm = psync_fstask_find_rmdir(folder, name, 0); + if ((mkdir = pfs_task_find_mkdir(folder, name, 0))) + return pfs_set_foldertime_locked(mkdir->folderid, tv, crtime, 0); + un = pfs_task_find_unlink(folder, name, 0); + rm = pfs_task_find_rmdir(folder, name, 0); } else { un = NULL; rm = NULL; @@ -3145,7 +3145,7 @@ static int psync_fs_set_time_locked(psync_fsfolderid_t folderid, uint64_t fileid = row[0]; uint64_t ctm = row[1 + crtime]; psql_free(res); - return psync_fs_set_filetime_locked(fileid, tv, crtime, ctm); + return pfs_set_filetime_locked(fileid, tv, crtime, ctm); } psql_free(res); } @@ -3161,65 +3161,65 @@ static int psync_fs_set_time_locked(psync_fsfolderid_t folderid, psql_free(res); if (!(permissions & PSYNC_PERM_MODIFY)) return -EACCES; - return psync_fs_set_foldertime_locked(folderid, tv, crtime, ctm); + return pfs_set_foldertime_locked(folderid, tv, crtime, ctm); } psql_free(res); } return -ENOENT; } -static int psync_fs_set_time(const char *path, const struct timespec *tv, +static int pfs_set_time(const char *path, const struct timespec *tv, int crtime) { psync_fspath_t *fpath; int ret; psql_lock(); CHECK_LOGIN_LOCKED(); - fpath = psync_fsfolder_resolve_path(path); + fpath = pfs_fldr_resolve_path(path); if (!fpath) ret = -ENOENT; else if (!(fpath->permissions & PSYNC_PERM_MODIFY)) ret = -EACCES; else - ret = psync_fs_set_time_locked(fpath->folderid, fpath->name, tv, crtime); + ret = pfs_set_time_locked(fpath->folderid, fpath->name, tv, crtime); psql_unlock(); free(fpath); return ret; } #if defined(FUSE_HAS_SETCRTIME) -static int psync_fs_setcrtime(const char *path, const struct timespec *tv) { - psync_fs_set_thread_name(); +static int pfs_setcrtime(const char *path, const struct timespec *tv) { + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "setcrtime %s %lu", path, tv->tv_sec); - return psync_fs_set_time(path, tv, 1); + return pfs_set_time(path, tv, 1); } #endif -static int psync_fs_utimens(const char *path, const struct timespec tv[2]) { - psync_fs_set_thread_name(); +static int pfs_utimens(const char *path, const struct timespec tv[2]) { + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "utimens %s %lu", path, tv[1].tv_sec); - return psync_fs_set_time(path, &tv[1], 0); + return pfs_set_time(path, &tv[1], 0); } -static int psync_fs_ftruncate_of_locked(psync_openfile_t *of, fuse_off_t size) { +static int pfs_ftruncate_of_locked(psync_openfile_t *of, fuse_off_t size) { int ret; if (of->currentsize == size) { pdbg_logf(D_NOTICE, "not truncating as size is already %lu", (long unsigned)size); return 0; } - psync_fs_inc_writeid_locked(of); + pfs_inc_writeid_locked(of); retry: if (unlikely(!of->newfile && !of->modified)) { - ret = psync_fs_reopen_file_for_writing(of); + ret = pfs_reopen_file_for_writing(of); if (ret == 1) goto retry; else if (ret < 0) return ret; } if (of->encrypted) - return pfscrypto_truncate(of, size); + return pfs_crpt_truncate(of, size); else { - if (psync_fs_modfile_check_size_ok(of, size)) + if (pfs_modfile_check_size_ok(of, size)) ret = -pdbg_return_const(EIO); else if (of->currentsize != size && (pfile_seek(of->datafile, size, SEEK_SET) == -1 || @@ -3233,36 +3233,36 @@ retry: return ret; } -static int psync_fs_ftruncate(const char *path, fuse_off_t size, +static int pfs_ftruncate(const char *path, fuse_off_t size, struct fuse_file_info *fi) { psync_openfile_t *of; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "ftruncate %s %lu", path, (unsigned long)size); of = fh_to_openfile(fi->fh); - psync_fs_lock_file(of); - ret = psync_fs_ftruncate_of_locked(of, size); + pfs_lock_file(of); + ret = pfs_ftruncate_of_locked(of, size); pthread_mutex_unlock(&of->mutex); return pdbg_returnf(ret, " for ftruncate of %s to %lu", path, (unsigned long)size); } -static int psync_fs_truncate(const char *path, fuse_off_t size) { +static int pfs_truncate(const char *path, fuse_off_t size) { struct fuse_file_info fi; int ret; - psync_fs_set_thread_name(); + pfs_set_thread_name(); pdbg_logf(D_NOTICE, "truncate %s %lu", path, (unsigned long)size); memset(&fi, 0, sizeof(fi)); - ret = psync_fs_open(path, &fi); + ret = pfs_open(path, &fi); if (ret) return ret; - ret = psync_fs_ftruncate(path, size, &fi); - psync_fs_flush(path, &fi); - psync_fs_release(path, &fi); + ret = pfs_ftruncate(path, size, &fi); + pfs_flush(path, &fi); + pfs_release(path, &fi); return ret; } -static void psync_fs_start_callback_timer(psync_timer_t timer, void *ptr) { +static void pfs_start_callback_timer(psync_timer_t timer, void *ptr) { psync_generic_callback_t callback; ptimer_stop(timer); callback = psync_start_callback; @@ -3270,7 +3270,7 @@ static void psync_fs_start_callback_timer(psync_timer_t timer, void *ptr) { prun_thread("fs start callback", callback); } -static void *psync_fs_init(struct fuse_conn_info *conn) { +static void *pfs_init(struct fuse_conn_info *conn) { #if defined(FUSE_CAP_ASYNC_READ) conn->want |= FUSE_CAP_ASYNC_READ; #endif @@ -3282,7 +3282,7 @@ static void *psync_fs_init(struct fuse_conn_info *conn) { #endif conn->max_readahead = 1024 * 1024; if (psync_start_callback) - ptimer_register(psync_fs_start_callback_timer, 1, NULL); + ptimer_register(pfs_start_callback_timer, 1, NULL); return 0; } @@ -3295,7 +3295,7 @@ static void psync_invalidate_os_cache_noret() { char *path; pthread_mutex_lock(&start_mutex); if (started == 1) - path = psync_strdup(psync_current_mountpoint); + path = putil_strdup(psync_current_mountpoint); else path = NULL; pthread_mutex_unlock(&start_mutex); @@ -3305,7 +3305,7 @@ static void psync_invalidate_os_cache_noret() { } } -static void psync_fs_refresh_timer(psync_timer_t timer, void *ptr) { +static void pfs_refresh_timer(psync_timer_t timer, void *ptr) { time_t ct; ct = ptimer_time(); ptimer_stop(timer); @@ -3317,7 +3317,7 @@ static void psync_fs_refresh_timer(psync_timer_t timer, void *ptr) { psync_invalidate_os_cache_noret); } -void psync_fs_refresh() { +void pfs_refresh() { time_t ct; int todo; if (!pfile_invalidate_os_cache_needed()) @@ -3339,19 +3339,19 @@ void psync_fs_refresh() { prun_thread("os cache invalidate", psync_invalidate_os_cache_noret); } else if (todo == 1) { pdbg_logf(D_NOTICE, "setting timer to invalidate cache"); - ptimer_register(psync_fs_refresh_timer, REFRESH_SEC, NULL); + ptimer_register(pfs_refresh_timer, REFRESH_SEC, NULL); } } -int psync_fs_need_per_folder_refresh_f() { -#if psync_fs_need_per_folder_refresh_const() +int pfs_need_per_folder_refresh_f() { +#if pfs_need_per_folder_refresh_const() return started == 1; #else return 0; #endif } -void psync_fs_refresh_folder(psync_folderid_t folderid) { +void pfs_refresh_folder(psync_folderid_t folderid) { char *path, *fpath; unsigned char rndbuff[20]; char rndhex[42]; @@ -3367,10 +3367,10 @@ void psync_fs_refresh_folder(psync_folderid_t folderid) { pthread_mutex_lock(&start_mutex); if (started == 1) { if (pfile_invalidate_os_cache_needed()) - fpath = psync_strcat(psync_current_mountpoint, path, NULL); + fpath = putil_strcat(psync_current_mountpoint, path, NULL); else - fpath = psync_strcat(psync_current_mountpoint, path, "/", - psync_fake_prefix, rndhex, NULL); + fpath = putil_strcat(psync_current_mountpoint, path, "/", + pfs_fake_prefix, rndhex, NULL); } else fpath = NULL; pthread_mutex_unlock(&start_mutex); @@ -3396,7 +3396,7 @@ static char *psync_fuse_get_mountpoint() { int stat_result; int stat_errno; - mp = psync_strdup(psync_setting_get_string(_PS(fsroot))); + mp = putil_strdup(psync_setting_get_string(_PS(fsroot))); stat_result = stat(mp, &st); stat_errno = errno; @@ -3432,26 +3432,26 @@ static char *psync_fuse_get_mountpoint() { return mp; } -char *psync_fs_getmountpoint() { +char *pfs_getmountpoint() { char *ret; pthread_mutex_lock(&start_mutex); if (started == 1) - ret = psync_strdup(psync_current_mountpoint); + ret = putil_strdup(psync_current_mountpoint); else ret = NULL; pthread_mutex_unlock(&start_mutex); return ret; } -void psync_fs_register_start_callback(psync_generic_callback_t callback) { +void pfs_register_start_callback(psync_generic_callback_t callback) { psync_start_callback = callback; } -char *psync_fs_get_path_by_folderid(psync_folderid_t folderid) { +char *pfs_get_path_by_folderid(psync_folderid_t folderid) { char *mp, *path, *ret; pthread_mutex_lock(&start_mutex); if (started == 1) - mp = psync_strdup(psync_current_mountpoint); + mp = putil_strdup(psync_current_mountpoint); else mp = NULL; pthread_mutex_unlock(&start_mutex); @@ -3463,17 +3463,17 @@ char *psync_fs_get_path_by_folderid(psync_folderid_t folderid) { free(mp); return NULL; } - ret = psync_strcat(mp, path, NULL); + ret = putil_strcat(mp, path, NULL); free(mp); free(path); return ret; } -char *psync_fs_get_path_by_fileid(psync_fileid_t fileid) { +char *pfs_get_path_by_fileid(psync_fileid_t fileid) { char *mp, *path, *ret; pthread_mutex_lock(&start_mutex); if (started == 1) - mp = psync_strdup(psync_current_mountpoint); + mp = putil_strdup(psync_current_mountpoint); else mp = NULL; pthread_mutex_unlock(&start_mutex); @@ -3484,7 +3484,7 @@ char *psync_fs_get_path_by_fileid(psync_fileid_t fileid) { free(mp); return NULL; } - ret = psync_strcat(mp, path, NULL); + ret = putil_strcat(mp, path, NULL); free(mp); free(path); return ret; @@ -3492,20 +3492,20 @@ char *psync_fs_get_path_by_fileid(psync_fileid_t fileid) { #if IS_DEBUG -static void psync_fs_dump_internals() { +static void pfs_dump_internals() { psync_openfile_t *of; pdbg_logf(D_NOTICE, "dumping internal state"); psql_rdlock(); ptree_for_each_element(of, openfiles, psync_openfile_t, tree) pdbg_logf(D_NOTICE, "open file %s fileid %ld folderid %ld", of->currentname, (long)of->fileid, (long)of->currentfolder->folderid); - psync_fstask_dump_state(); + pfs_task_dump_state(); psql_rdunlock(); } #endif -static void psync_fs_do_stop(void) { +static void pfs_do_stop(void) { if (!__sync_bool_compare_and_swap(&shutdown_in_progress, 0, 1)) { // prevent multiple executions return; @@ -3562,14 +3562,14 @@ static void psync_fs_do_stop(void) { } #if IS_DEBUG - psync_fs_dump_internals(); + pfs_dump_internals(); #endif free(mp); } pthread_mutex_unlock(&start_mutex); } -void psync_fs_stop() { psync_fs_do_stop(); } +void pfs_stop() { pfs_do_stop(); } static void psync_signal_handler(int sig) { pdbg_logf(D_NOTICE, "got signal %d", sig); @@ -3579,7 +3579,7 @@ static void psync_signal_handler(int sig) { #if IS_DEBUG static void psync_usr1_handler(int sig) { // pdbg_logf(D_NOTICE, "got signal %d", sig); - prun_thread("dump signal", psync_fs_dump_internals); + prun_thread("dump signal", pfs_dump_internals); } #endif @@ -3613,29 +3613,29 @@ static void psync_setup_signals() { psync_set_signal(SIGUSR2, psync_usr2_handler); } -static void psync_fs_init_once() { -#if psync_fs_need_per_folder_refresh_const() +static void pfs_init_once() { +#if pfs_need_per_folder_refresh_const() unsigned char rndbuff[16]; char rndhex[34]; pssl_rand_strong(rndbuff, sizeof(rndbuff)); psync_binhex(rndhex, rndbuff, sizeof(rndbuff)); rndhex[2 * sizeof(rndbuff)] = 0; - psync_fake_prefix = psync_strcat(".refresh", rndhex, NULL); - psync_fake_prefix_len = strlen(psync_fake_prefix); + pfs_fake_prefix = putil_strcat(".refresh", rndhex, NULL); + pfs_fake_prefix_len = strlen(pfs_fake_prefix); #endif - psync_fstask_init(); + pfs_task_init(); ppagecache_init(); - atexit(psync_fs_do_stop); + atexit(pfs_do_stop); psync_setup_signals(); - psync_fsstatic_add_files(); - psync_fstask_add_banned_folders(); + pfs_stat_add_files(); + pfs_task_add_banned_folders(); } static void psync_fuse_thread() { int fr; pthread_mutex_lock(&start_mutex); if (!initonce) { - psync_fs_init_once(); + pfs_init_once(); initonce = 1; } pthread_mutex_unlock(&start_mutex); @@ -3674,7 +3674,7 @@ static char is_fuse3_installed_on_system() { return outlen > 0; } -static int psync_fs_do_start() { +static int pfs_do_start() { char *mp; struct fuse_operations psync_oper; struct fuse_args args = FUSE_ARGS_INIT(0, NULL); @@ -3721,40 +3721,40 @@ static int psync_fs_do_start() { memset(&psync_oper, 0, sizeof(psync_oper)); - psync_oper.init = psync_fs_init; - psync_oper.getattr = psync_fs_getattr; - psync_oper.readdir = psync_fs_readdir; - psync_oper.open = psync_fs_open; - psync_oper.create = psync_fs_creat; - psync_oper.release = psync_fs_release; - psync_oper.flush = psync_fs_flush; - psync_oper.fsync = psync_fs_fsync; - psync_oper.fsyncdir = psync_fs_fsyncdir; - psync_oper.read = psync_fs_read; - psync_oper.write = psync_fs_write; - psync_oper.mkdir = psync_fs_mkdir; - psync_oper.rmdir = psync_fs_rmdir; - psync_oper.unlink = psync_fs_unlink; - psync_oper.rename = psync_fs_rename; - psync_oper.statfs = psync_fs_statfs; - psync_oper.chmod = psync_fs_chmod; - psync_oper.chown = psync_fs_chown; - psync_oper.utimens = psync_fs_utimens; - psync_oper.ftruncate = psync_fs_ftruncate; - psync_oper.truncate = psync_fs_truncate; + psync_oper.init = pfs_init; + psync_oper.getattr = pfs_getattr; + psync_oper.readdir = pfs_readdir; + psync_oper.open = pfs_open; + psync_oper.create = pfs_creat; + psync_oper.release = pfs_release; + psync_oper.flush = pfs_flush; + psync_oper.fsync = pfs_fsync; + psync_oper.fsyncdir = pfs_fsyncdir; + psync_oper.read = pfs_read; + psync_oper.write = pfs_write; + psync_oper.mkdir = pfs_mkdir; + psync_oper.rmdir = pfs_rmdir; + psync_oper.unlink = pfs_unlink; + psync_oper.rename = pfs_rename; + psync_oper.statfs = pfs_statfs; + psync_oper.chmod = pfs_chmod; + psync_oper.chown = pfs_chown; + psync_oper.utimens = pfs_utimens; + psync_oper.ftruncate = pfs_ftruncate; + psync_oper.truncate = pfs_truncate; - psync_oper.setxattr = psync_fs_setxattr; - psync_oper.getxattr = psync_fs_getxattr; - psync_oper.listxattr = psync_fs_listxattr; - psync_oper.removexattr = psync_fs_removexattr; + psync_oper.setxattr = pfs_xatr_set; + psync_oper.getxattr = pfs_xatr_get; + psync_oper.listxattr = pfs_xatr_list; + psync_oper.removexattr = pfs_xatr_remove; #if defined(FUSE_HAS_CAN_UNLINK) - psync_oper.can_unlink = psync_fs_can_unlink; - psync_oper.can_rmdir = psync_fs_can_rmdir; + psync_oper.can_unlink = pfs_can_unlink; + psync_oper.can_rmdir = pfs_can_rmdir; #endif #if defined(FUSE_HAS_SETCRTIME) - psync_oper.setcrtime = psync_fs_setcrtime; + psync_oper.setcrtime = pfs_setcrtime; #endif myuid = getuid(); @@ -3798,16 +3798,16 @@ err00: return -1; } -static void psync_fs_wait_start() { +static void pfs_wait_start() { pdbg_logf(D_NOTICE, "waiting for online status"); pstatus_wait(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE); if (psync_do_run) { pdbg_logf(D_NOTICE, "starting fs"); - psync_fs_do_start(); + pfs_do_start(); } } -static void psync_fs_wait_login() { +static void pfs_wait_login() { pdbg_logf(D_NOTICE, "waiting for online status"); pstatus_wait(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE); pdbg_logf(D_NOTICE, "waited for online status"); @@ -3816,19 +3816,19 @@ static void psync_fs_wait_login() { psql_unlock(); } -void psync_fs_pause_until_login() { +void pfs_pause_until_login() { psql_lock(); if (waitingforlogin == 0) { waitingforlogin = 1; pdbg_logf(D_NOTICE, "stopping fs until login"); - prun_thread("fs wait login", psync_fs_wait_login); + prun_thread("fs wait login", pfs_wait_login); } psql_unlock(); } -void psync_fs_clean_tasks() { psync_fstask_clean(); } +void pfs_clean_tasks() { pfs_task_clean(); } -int psync_fs_start() { +int pfs_start() { uint32_t status; int ret; pthread_mutex_lock(&start_mutex); @@ -3842,14 +3842,14 @@ int psync_fs_start() { status = pstatus_get(PSTATUS_TYPE_AUTH); pdbg_logf(D_NOTICE, "auth status=%u", status); if (status == PSTATUS_AUTH_PROVIDED) - return psync_fs_do_start(); + return pfs_do_start(); else { - prun_thread("fs wait login", psync_fs_wait_start); + prun_thread("fs wait login", pfs_wait_start); return 0; } } -int psync_fs_isstarted() { +int pfs_isstarted() { int s; pthread_mutex_lock(&start_mutex); s = started; @@ -3857,14 +3857,14 @@ int psync_fs_isstarted() { return s == 1; } -int psync_fs_remount() { +int pfs_remount() { int s; pthread_mutex_lock(&start_mutex); s = started; pthread_mutex_unlock(&start_mutex); if (s) { - psync_fs_stop(); - return psync_fs_start(); + pfs_stop(); + return pfs_start(); } else return 0; } diff --git a/pclsync/pfs.h b/pclsync/pfs.h index 38f5331..61975d5 100644 --- a/pclsync/pfs.h +++ b/pclsync/pfs.h @@ -45,11 +45,11 @@ #include "ptimer.h" #include "ptree.h" -#define psync_fs_need_per_folder_refresh() psync_fs_need_per_folder_refresh_f() -#define psync_fs_need_per_folder_refresh_const() 1 +#define pfs_need_per_folder_refresh() pfs_need_per_folder_refresh_f() +#define pfs_need_per_folder_refresh_const() 1 -extern char *psync_fake_prefix; -extern size_t psync_fake_prefix_len; +extern char *pfs_fake_prefix; +extern size_t pfs_fake_prefix_len; typedef struct { uint64_t frompage; @@ -129,19 +129,19 @@ typedef struct { typedef struct { uint64_t offset; uint64_t length; -} psync_fs_index_record; +} pfs_index_record; typedef struct { int dummy[0]; -} psync_fs_index_header; +} pfs_index_header; #if IS_DEBUG -#define psync_fs_lock_file(of) psync_fs_do_lock_file(of, __FILE__, __LINE__) +#define pfs_lock_file(of) pfs_do_lock_file(of, __FILE__, __LINE__) // FIXME: wtf... extern PSYNC_THREAD const char *psync_thread_name; -static inline void psync_fs_do_lock_file(psync_openfile_t *of, const char *file, +static inline void pfs_do_lock_file(psync_openfile_t *of, const char *file, unsigned long line) { if (unlikely(pthread_mutex_trylock(&of->mutex))) { struct timespec tm; @@ -160,35 +160,35 @@ static inline void psync_fs_do_lock_file(psync_openfile_t *of, const char *file, of->lockline = line; } #else -static inline void psync_fs_lock_file(psync_openfile_t *of) { +static inline void pfs_lock_file(psync_openfile_t *of) { pthread_mutex_lock(&of->mutex); } #endif -int psync_fs_crypto_err_to_errno(int cryptoerr); -int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, +int pfs_crypto_err_to_errno(int cryptoerr); +int pfs_update_openfile(uint64_t taskid, uint64_t writeid, psync_fileid_t newfileid, uint64_t hash, uint64_t size, time_t ctime); -// void psync_fs_uploading_openfile(uint64_t taskid); -int psync_fs_rename_openfile_locked(psync_fsfileid_t fileid, +// void pfs_uploading_openfile(uint64_t taskid); +int pfs_rename_openfile_locked(psync_fsfileid_t fileid, psync_fsfolderid_t folderid, const char *name); -void psync_fs_mark_openfile_deleted(uint64_t taskid); -int64_t psync_fs_get_file_writeid(uint64_t taskid); -int64_t psync_fs_load_interval_tree(int fd, uint64_t size, +void pfs_mark_openfile_deleted(uint64_t taskid); +int64_t pfs_get_file_writeid(uint64_t taskid); +int64_t pfs_load_interval_tree(int fd, uint64_t size, psync_interval_tree_t **tree); -int psync_fs_remount(); -void psync_fs_inc_of_refcnt_locked(psync_openfile_t *of); -void psync_fs_inc_of_refcnt(psync_openfile_t *of); -void psync_fs_dec_of_refcnt(psync_openfile_t *of); -void psync_fs_inc_of_refcnt_and_readers(psync_openfile_t *of); -void psync_fs_dec_of_refcnt_and_readers(psync_openfile_t *of); +int pfs_remount(); +void pfs_inc_of_refcnt_locked(psync_openfile_t *of); +void pfs_inc_of_refcnt(psync_openfile_t *of); +void pfs_dec_of_refcnt(psync_openfile_t *of); +void pfs_inc_of_refcnt_and_readers(psync_openfile_t *of); +void pfs_dec_of_refcnt_and_readers(psync_openfile_t *of); -void psync_fs_refresh(); -int psync_fs_need_per_folder_refresh_f(); -void psync_fs_refresh_folder(psync_folderid_t folderid); +void pfs_refresh(); +int pfs_need_per_folder_refresh_f(); +void pfs_refresh_folder(psync_folderid_t folderid); -void psync_fs_pause_until_login(); -void psync_fs_clean_tasks(); +void pfs_pause_until_login(); +void pfs_clean_tasks(); #endif diff --git a/pclsync/pfscrypto.c b/pclsync/pfscrypto.c index 498adca..f819d58 100644 --- a/pclsync/pfscrypto.c +++ b/pclsync/pfscrypto.c @@ -99,7 +99,7 @@ static const uint64_t max_level_size[PSYNC_CRYPTO_MAX_HASH_TREE_LEVEL + 1] = { 0x10204081000, 0x810204081000, 0x40810204081000}; psync_crypto_sectorid_t -pfscrypto_sector_id(psync_crypto_sectorid_t sectorid) { +pfs_crpt_sector_id(psync_crypto_sectorid_t sectorid) { psync_crypto_sectorid_t sect; sect = sectorid; while (sectorid >= PSYNC_CRYPTO_HASH_TREE_SECTORS) { @@ -110,7 +110,7 @@ pfscrypto_sector_id(psync_crypto_sectorid_t sectorid) { } static uint64_t -psync_fs_crypto_data_offset_by_sectorid(psync_crypto_sectorid_t sectorid) { +pfs_crypto_data_offset_by_sectorid(psync_crypto_sectorid_t sectorid) { uint64_t off; off = (uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE; while (sectorid >= PSYNC_CRYPTO_HASH_TREE_SECTORS) { @@ -121,7 +121,7 @@ psync_fs_crypto_data_offset_by_sectorid(psync_crypto_sectorid_t sectorid) { } /* works for all sectors of auth data except the last one of each level */ -static uint64_t psync_fs_crypto_auth_offset(uint32_t level, uint32_t id) { +static uint64_t pfs_crypto_auth_offset(uint32_t level, uint32_t id) { uint64_t ret; ret = max_level_size[level + 1] * (id + 1) - PSYNC_CRYPTO_SECTOR_SIZE; while (id >= PSYNC_CRYPTO_HASH_TREE_SECTORS) { @@ -131,7 +131,7 @@ static uint64_t psync_fs_crypto_auth_offset(uint32_t level, uint32_t id) { return ret; } -void pfscrypto_offset_by_size(uint64_t size, +void pfs_crpt_offset_by_size(uint64_t size, psync_crypto_offsets_t *offsets) { uint64_t off; psync_crypto_sectorid_t lastsectorid; @@ -147,7 +147,7 @@ void pfscrypto_offset_by_size(uint64_t size, lastsectorid--; lastsectorsize = PSYNC_CRYPTO_SECTOR_SIZE; } - off = psync_fs_crypto_data_offset_by_sectorid(lastsectorid) + lastsectorsize; + off = pfs_crypto_data_offset_by_sectorid(lastsectorid) + lastsectorsize; level = 0; size = (size + PSYNC_CRYPTO_SECTOR_SIZE - 1) / PSYNC_CRYPTO_SECTOR_SIZE; do { @@ -169,7 +169,7 @@ void pfscrypto_offset_by_size(uint64_t size, } static void -psync_fs_crypto_offsets_by_cryptosize(uint64_t size, +pfs_crypto_offsets_by_cryptosize(uint64_t size, psync_crypto_offsets_t *offsets) { uint64_t off, cnt; uint32_t level; @@ -204,7 +204,7 @@ psync_fs_crypto_offsets_by_cryptosize(uint64_t size, offsets->plainsize = size; } -int pfscrypto_init_log(psync_openfile_t *of) { +int pfs_crpt_init_log(psync_openfile_t *of) { char buff[PSYNC_CRYPTO_SECTOR_SIZE]; ssize_t wrt; pdbg_assert(sizeof(psync_crypto_master_record) <= PSYNC_CRYPTO_SECTOR_SIZE); @@ -220,7 +220,7 @@ int pfscrypto_init_log(psync_openfile_t *of) { return 0; } -static int psync_fs_crypto_read_newfile_full_sector_from_log( +static int pfs_crypto_read_newfile_full_sector_from_log( psync_openfile_t *of, char *buf, psync_sector_inlog_t *se) { unsigned char buff[PSYNC_CRYPTO_SECTOR_SIZE]; psync_crypto_log_header hdr; @@ -236,7 +236,7 @@ static int psync_fs_crypto_read_newfile_full_sector_from_log( return -EIO; } pdbg_assert(hdr.offset == - (uint64_t)pfscrypto_sector_id(se->sectorid) * + (uint64_t)pfs_crpt_sector_id(se->sectorid) * PSYNC_CRYPTO_SECTOR_SIZE); pdbg_assert(hdr.length <= PSYNC_CRYPTO_SECTOR_SIZE); rd = pfile_pread(of->logfile, buff, hdr.length, @@ -272,7 +272,7 @@ static psync_crypto_sectorid_t get_last_sectorid_by_size(uint64_t size) { #if defined(PSYNC_DO_LOCAL_FULL_TREE_CHECK) static int -psync_fs_crypto_do_local_tree_check(psync_openfile_t *of, +pfs_crypto_do_local_tree_check(psync_openfile_t *of, psync_crypto_sectorid_t sectorid, psync_crypto_offsets_t *offsets) { unsigned char buff[PSYNC_CRYPTO_SECTOR_SIZE]; @@ -290,7 +290,7 @@ psync_fs_crypto_do_local_tree_check(psync_openfile_t *of, off = offsets->lastauthsectoroff[0]; ssize = offsets->lastauthsectorlen[0]; } else { - off = psync_fs_crypto_auth_offset(0, sectorid); + off = pfs_crypto_auth_offset(0, sectorid); ssize = PSYNC_CRYPTO_SECTOR_SIZE; } // pdbg_logf(D_NOTICE, "reading first sector from offset %lu, size %u", (unsigned @@ -310,7 +310,7 @@ psync_fs_crypto_do_local_tree_check(psync_openfile_t *of, off = offsets->lastauthsectoroff[level]; ssize = offsets->lastauthsectorlen[level]; } else { - off = psync_fs_crypto_auth_offset(level, sectorid); + off = pfs_crypto_auth_offset(level, sectorid); ssize = PSYNC_CRYPTO_SECTOR_SIZE; } rd = pfile_pread(of->datafile, buff, ssize, off); @@ -330,7 +330,7 @@ psync_fs_crypto_do_local_tree_check(psync_openfile_t *of, } #endif -static int psync_fs_crypto_wait_no_extender_locked(psync_openfile_t *of) { +static int pfs_crypto_wait_no_extender_locked(psync_openfile_t *of) { int ret; while (of->extender && !of->extender->ready) { pdbg_logf(D_NOTICE, "waiting for extender to finish"); @@ -343,7 +343,7 @@ static int psync_fs_crypto_wait_no_extender_locked(psync_openfile_t *of) { do { pthread_mutex_unlock(&of->mutex); psys_sleep_milliseconds(1); - psync_fs_lock_file(of); + pfs_lock_file(of); } while (of->extender); pdbg_logf(D_NOTICE, "waited for extender to finish"); return ret; @@ -351,7 +351,7 @@ static int psync_fs_crypto_wait_no_extender_locked(psync_openfile_t *of) { return 0; } -static int psync_fs_crypto_wait_extender_after_locked(psync_openfile_t *of, +static int pfs_crypto_wait_extender_after_locked(psync_openfile_t *of, uint64_t offset) { while (of->extender && !of->extender->ready && of->extender->extendedto < offset) { @@ -370,7 +370,7 @@ static int psync_fs_crypto_wait_extender_after_locked(psync_openfile_t *of, return 0; } -static int psync_fs_crypto_kill_extender_locked(psync_openfile_t *of) { +static int pfs_crypto_kill_extender_locked(psync_openfile_t *of) { if (of->extender) { pdbg_logf(D_NOTICE, "killing extender of file %s", of->currentname); of->extender->kill = 1; @@ -380,7 +380,7 @@ static int psync_fs_crypto_kill_extender_locked(psync_openfile_t *of) { return 0; } -static int psync_fs_crypto_read_newfile_full_sector_from_datafile( +static int pfs_crypto_read_newfile_full_sector_from_datafile( psync_openfile_t *of, char *buf, psync_crypto_sectorid_t sectorid) { unsigned char buff[PSYNC_CRYPTO_SECTOR_SIZE]; pcrypto_sector_auth_t auth; @@ -393,7 +393,7 @@ static int psync_fs_crypto_read_newfile_full_sector_from_datafile( fs = pfile_size(of->datafile); if (pdbg_unlikely(fs == -1)) return -EIO; - psync_fs_crypto_offsets_by_cryptosize(fs, &offsets); + pfs_crypto_offsets_by_cryptosize(fs, &offsets); if ((uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE >= offsets.plainsize) return 0; if ((uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE + PSYNC_CRYPTO_SECTOR_SIZE > @@ -401,7 +401,7 @@ static int psync_fs_crypto_read_newfile_full_sector_from_datafile( ssize = offsets.plainsize - (uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE; else ssize = PSYNC_CRYPTO_SECTOR_SIZE; - off = psync_fs_crypto_data_offset_by_sectorid(sectorid); + off = pfs_crypto_data_offset_by_sectorid(sectorid); // pdbg_logf(D_NOTICE, "data offset=%lu", off); rd = pfile_pread(of->datafile, buff, ssize, off); if (pdbg_unlikely(rd != ssize)) @@ -411,7 +411,7 @@ static int psync_fs_crypto_read_newfile_full_sector_from_datafile( PSYNC_CRYPTO_HASH_TREE_SECTORS) off = offsets.lastauthsectoroff[0]; else - off = psync_fs_crypto_auth_offset(0, sectorid / + off = pfs_crypto_auth_offset(0, sectorid / PSYNC_CRYPTO_HASH_TREE_SECTORS); off += (sectorid % PSYNC_CRYPTO_HASH_TREE_SECTORS) * PSYNC_CRYPTO_AUTH_SIZE; // pdbg_logf(D_NOTICE, "auth offset=%lu", off); @@ -422,7 +422,7 @@ static int psync_fs_crypto_read_newfile_full_sector_from_datafile( of->encoder, buff, ssize, (unsigned char *)buf, auth, sectorid))) return -EIO; #if defined(PSYNC_DO_LOCAL_FULL_TREE_CHECK) - else if (psync_fs_crypto_do_local_tree_check(of, sectorid, &offsets)) + else if (pfs_crypto_do_local_tree_check(of, sectorid, &offsets)) return -EIO; #endif else @@ -430,7 +430,7 @@ static int psync_fs_crypto_read_newfile_full_sector_from_datafile( } static int -psync_fs_crypto_read_newfile_full_sector(psync_openfile_t *of, char *buf, +pfs_crypto_read_newfile_full_sector(psync_openfile_t *of, char *buf, psync_crypto_sectorid_t sectorid) { psync_crypto_sectorid_diff_t d; psync_sector_inlog_t *tr; @@ -442,20 +442,20 @@ psync_fs_crypto_read_newfile_full_sector(psync_openfile_t *of, char *buf, else if (d > 0) tr = ptree_element(tr->tree.right, psync_sector_inlog_t, tree); else - return psync_fs_crypto_read_newfile_full_sector_from_log(of, buf, tr); + return pfs_crypto_read_newfile_full_sector_from_log(of, buf, tr); } - return psync_fs_crypto_read_newfile_full_sector_from_datafile(of, buf, + return pfs_crypto_read_newfile_full_sector_from_datafile(of, buf, sectorid); } static int -psync_fs_crypto_read_newfile_partial_sector(psync_openfile_t *of, char *buf, +pfs_crypto_read_newfile_partial_sector(psync_openfile_t *of, char *buf, psync_crypto_sectorid_t sectorid, size_t size, off_t offset) { char buff[PSYNC_CRYPTO_SECTOR_SIZE]; int rd; pdbg_assert(offset + size <= PSYNC_CRYPTO_SECTOR_SIZE); - rd = psync_fs_crypto_read_newfile_full_sector(of, buff, sectorid); + rd = pfs_crypto_read_newfile_full_sector(of, buff, sectorid); if (rd <= 0) return rd; if (rd <= offset) @@ -467,12 +467,12 @@ psync_fs_crypto_read_newfile_partial_sector(psync_openfile_t *of, char *buf, return rd; } -static int psync_fs_unlock_ret(psync_openfile_t *of, int ret) { +static int pfs_unlock_ret(psync_openfile_t *of, int ret) { pthread_mutex_unlock(&of->mutex); return ret; } -int pfscrypto_read_new(psync_openfile_t *of, char *buf, +int pfs_crpt_read_new(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset) { uint64_t off2, offdiff; psync_crypto_sectorid_t sectorid; @@ -482,12 +482,12 @@ int pfscrypto_read_new(psync_openfile_t *of, char *buf, if (unlikely((size + offset + PSYNC_CRYPTO_SECTOR_SIZE - 1) / PSYNC_CRYPTO_SECTOR_SIZE > PSYNC_CRYPTO_MAX_SECTORID)) - return psync_fs_unlock_ret(of, -EINVAL); - ret = psync_fs_crypto_wait_extender_after_locked(of, offset + size); + return pfs_unlock_ret(of, -EINVAL); + ret = pfs_crypto_wait_extender_after_locked(of, offset + size); if (pdbg_unlikely(ret)) - return psync_fs_unlock_ret(of, ret); + return pfs_unlock_ret(of, ret); if (unlikely(!size || of->currentsize <= offset)) - return psync_fs_unlock_ret(of, 0); + return pfs_unlock_ret(of, 0); if (offset + size > of->currentsize) size = of->currentsize - offset; sectorid = offset / PSYNC_CRYPTO_SECTOR_SIZE; @@ -498,7 +498,7 @@ int pfscrypto_read_new(psync_openfile_t *of, char *buf, offdiff = PSYNC_CRYPTO_SECTOR_SIZE - off2; else offdiff = size; - ret = psync_fs_crypto_read_newfile_partial_sector(of, buf, sectorid, + ret = pfs_crypto_read_newfile_partial_sector(of, buf, sectorid, offdiff, off2); offset += offdiff; buf += offdiff; @@ -506,15 +506,15 @@ int pfscrypto_read_new(psync_openfile_t *of, char *buf, size -= offdiff; sectorid++; if (ret != offdiff) - return psync_fs_unlock_ret(of, ret); + return pfs_unlock_ret(of, ret); } while (size >= PSYNC_CRYPTO_SECTOR_SIZE) { - ret = psync_fs_crypto_read_newfile_full_sector(of, buf, sectorid); + ret = pfs_crypto_read_newfile_full_sector(of, buf, sectorid); if (ret != PSYNC_CRYPTO_SECTOR_SIZE) { if (ret < 0) - return psync_fs_unlock_ret(of, ret); + return pfs_unlock_ret(of, ret); else - return psync_fs_unlock_ret(of, ret + rd); + return pfs_unlock_ret(of, ret + rd); } buf += PSYNC_CRYPTO_SECTOR_SIZE; offset += PSYNC_CRYPTO_SECTOR_SIZE; @@ -524,12 +524,12 @@ int pfscrypto_read_new(psync_openfile_t *of, char *buf, } if (size) { ret = - psync_fs_crypto_read_newfile_partial_sector(of, buf, sectorid, size, 0); + pfs_crypto_read_newfile_partial_sector(of, buf, sectorid, size, 0); if (ret != size) { if (ret < 0) - return psync_fs_unlock_ret(of, ret); + return pfs_unlock_ret(of, ret); else - return psync_fs_unlock_ret(of, ret + rd); + return pfs_unlock_ret(of, ret + rd); } rd += size; } @@ -538,7 +538,7 @@ int pfscrypto_read_new(psync_openfile_t *of, char *buf, } static void -psync_fs_crypto_set_sector_log_offset(psync_openfile_t *of, +pfs_crypto_set_sector_log_offset(psync_openfile_t *of, psync_crypto_sectorid_t sectorid, uint32_t offset, unsigned char *auth) { psync_crypto_sectorid_diff_t d; @@ -576,7 +576,7 @@ psync_fs_crypto_set_sector_log_offset(psync_openfile_t *of, ptree_added_at(&of->sectorsinlog, &tr->tree, &ntr->tree); } -static int psync_fs_crypto_switch_sectors(psync_openfile_t *of, +static int pfs_crypto_switch_sectors(psync_openfile_t *of, psync_crypto_sectorid_t oldsectorid, psync_crypto_sectorid_t newsectorid, psync_crypto_auth_sector_t *autharr, @@ -602,7 +602,7 @@ static int psync_fs_crypto_switch_sectors(psync_openfile_t *of, sz = offsets->lastauthsectorlen[level]; } else { pdbg_assert(oldsecd < sizesecd); - hdr.offset = psync_fs_crypto_auth_offset(level, oldsecd); + hdr.offset = pfs_crypto_auth_offset(level, oldsecd); sz = PSYNC_CRYPTO_SECTOR_SIZE; } pdbg_assert(hdr.offset + sz <= @@ -643,7 +643,7 @@ static int psync_fs_crypto_switch_sectors(psync_openfile_t *of, if (pdbg_unlikely(filesize == -1)) return -EIO; if (filesize > PSYNC_CRYPTO_AUTH_SIZE) { - psync_fs_crypto_offsets_by_cryptosize(filesize, &ooffsets); + pfs_crypto_offsets_by_cryptosize(filesize, &ooffsets); level = 0; oldsecd = oldsectorid / PSYNC_CRYPTO_HASH_TREE_SECTORS; newsecd = newsectorid / PSYNC_CRYPTO_HASH_TREE_SECTORS; @@ -656,7 +656,7 @@ static int psync_fs_crypto_switch_sectors(psync_openfile_t *of, sz = ooffsets.lastauthsectorlen[level]; } else { pdbg_assert(newsecd < sizesecd); - off = psync_fs_crypto_auth_offset(level, newsecd); + off = pfs_crypto_auth_offset(level, newsecd); sz = PSYNC_CRYPTO_SECTOR_SIZE; } wrt = pfile_pread(of->datafile, &autharr[level], sz, off); @@ -680,7 +680,7 @@ static int psync_fs_crypto_switch_sectors(psync_openfile_t *of, } static int -psync_fs_crypto_write_master_auth(psync_openfile_t *of, +pfs_crypto_write_master_auth(psync_openfile_t *of, psync_crypto_auth_sector_t *autharr, psync_crypto_offsets_t *offsets) { ssize_t wrt; @@ -717,7 +717,7 @@ psync_fs_crypto_write_master_auth(psync_openfile_t *of, return 0; } -static int psync_fs_write_auth_tree_to_log(psync_openfile_t *of, +static int pfs_write_auth_tree_to_log(psync_openfile_t *of, psync_crypto_offsets_t *offsets) { psync_sector_inlog_t *sect; psync_crypto_sectorid_t lastsect; @@ -730,7 +730,7 @@ static int psync_fs_write_auth_tree_to_log(psync_openfile_t *of, while (sect) { if (lastsect / PSYNC_CRYPTO_HASH_TREE_SECTORS != sect->sectorid / PSYNC_CRYPTO_HASH_TREE_SECTORS) { - ret = psync_fs_crypto_switch_sectors(of, lastsect, sect->sectorid, + ret = pfs_crypto_switch_sectors(of, lastsect, sect->sectorid, authsect, offsets); if (ret) return pdbg_return(ret); @@ -741,12 +741,12 @@ static int psync_fs_write_auth_tree_to_log(psync_openfile_t *of, sect = ptree_element(ptree_get_next(§->tree), psync_sector_inlog_t, tree); } - ret = psync_fs_crypto_switch_sectors( + ret = pfs_crypto_switch_sectors( of, lastsect, PSYNC_CRYPTO_INVALID_SECTORID, authsect, offsets); if (ret) return pdbg_return(ret); if (offsets->needmasterauth && - (ret = psync_fs_crypto_write_master_auth(of, authsect, offsets))) + (ret = pfs_crypto_write_master_auth(of, authsect, offsets))) return pdbg_return(ret); pdbg_logf(D_NOTICE, "wrote tree to log, lastsectorid=%u, currentsize=%lu", (unsigned)lastsect, (unsigned long)of->currentsize); @@ -754,7 +754,7 @@ static int psync_fs_write_auth_tree_to_log(psync_openfile_t *of, } PSYNC_NOINLINE static int -psync_fs_crypto_check_log_hash(int lfd, +pfs_crypto_check_log_hash(int lfd, psync_crypto_master_record *mr) { char buff[PSYNC_CRYPTO_SECTOR_SIZE]; psync_fast_hash256_ctx ctx; @@ -795,10 +795,10 @@ psync_fs_crypto_check_log_hash(int lfd, } } -static int psync_fs_crypto_process_log(int lfd, int dfd, +static int pfs_crypto_process_log(int lfd, int dfd, int ifd, int checkhash) { char buff[PSYNC_CRYPTO_SECTOR_SIZE]; - psync_fs_index_record *records; + pfs_index_record *records; psync_crypto_master_record *mr; psync_crypto_log_header hdr; uint64_t off, size, ioff; @@ -831,7 +831,7 @@ static int psync_fs_crypto_process_log(int lfd, int dfd, offsetof(psync_crypto_master_record, crc))); return -1; } - if (unlikely(checkhash && psync_fs_crypto_check_log_hash(lfd, mr))) { + if (unlikely(checkhash && pfs_crypto_check_log_hash(lfd, mr))) { pdbg_logf(D_WARNING, "log checksum failed, skipping replay"); return -1; } @@ -842,11 +842,11 @@ static int psync_fs_crypto_process_log(int lfd, int dfd, return -1; if (ifd != INVALID_HANDLE_VALUE && pdbg_unlikely( - pfile_seek(ifd, sizeof(psync_fs_index_header), SEEK_SET) != - sizeof(psync_fs_index_header) || + pfile_seek(ifd, sizeof(pfs_index_header), SEEK_SET) != + sizeof(pfs_index_header) || pfile_truncate(ifd))) return -1; - records = (psync_fs_index_record *)buff; + records = (pfs_index_record *)buff; recid = 0; ioff = 0; while ((rd = pfile_pread(lfd, &hdr, sizeof(hdr), off)) != 0) { @@ -883,15 +883,15 @@ static int psync_fs_crypto_process_log(int lfd, int dfd, records[recid].offset = hdr.offset; records[recid].length = hdr.longlengthlo + ((uint64_t)hdr.longlengthhi << 32); - if (++recid >= PSYNC_CRYPTO_SECTOR_SIZE / sizeof(psync_fs_index_record)) { + if (++recid >= PSYNC_CRYPTO_SECTOR_SIZE / sizeof(pfs_index_record)) { rd = pfile_pwrite(ifd, records, - sizeof(psync_fs_index_record) * recid, - sizeof(psync_fs_index_record) * ioff + - sizeof(psync_fs_index_header)); - if (rd != sizeof(psync_fs_index_record) * recid) { + sizeof(pfs_index_record) * recid, + sizeof(pfs_index_record) * ioff + + sizeof(pfs_index_header)); + if (rd != sizeof(pfs_index_record) * recid) { pdbg_logf(D_ERROR, "error writing to index file, expected to write %u got %d", - (unsigned)(sizeof(psync_fs_index_record) * recid), (int)rd); + (unsigned)(sizeof(pfs_index_record) * recid), (int)rd); return -1; } ioff += recid; @@ -903,12 +903,12 @@ static int psync_fs_crypto_process_log(int lfd, int dfd, } } if (recid) { - rd = pfile_pwrite(ifd, records, sizeof(psync_fs_index_record) * recid, - sizeof(psync_fs_index_record) * ioff + - sizeof(psync_fs_index_header)); - if (rd != sizeof(psync_fs_index_record) * recid) { + rd = pfile_pwrite(ifd, records, sizeof(pfs_index_record) * recid, + sizeof(pfs_index_record) * ioff + + sizeof(pfs_index_header)); + if (rd != sizeof(pfs_index_record) * recid) { pdbg_logf(D_ERROR, "error writing to index file, expected to write %u got %d", - (unsigned)(sizeof(psync_fs_index_record) * recid), (int)rd); + (unsigned)(sizeof(pfs_index_record) * recid), (int)rd); return -1; } } @@ -924,7 +924,7 @@ static void wait_before_flush(psync_openfile_t *of, uint32_t millisec) { psys_sleep_milliseconds(millisec); } -/*static int psync_fs_flush_cache_dir(){ +/*static int pfs_flush_cache_dir(){ const char *path; int ret; path=psync_setting_get_string(_PS(fscachepath)); @@ -935,7 +935,7 @@ static void wait_before_flush(psync_openfile_t *of, uint32_t millisec) { return ret; }*/ -static int psync_fs_crypto_mark_log_finalized(psync_openfile_t *of, +static int pfs_crypto_mark_log_finalized(psync_openfile_t *of, uint64_t filesize) { psync_crypto_master_record mr; int64_t lsize; @@ -958,7 +958,7 @@ static int psync_fs_crypto_mark_log_finalized(psync_openfile_t *of, return 0; } -static int psync_fs_crypto_log_flush_and_process(psync_openfile_t *of, +static int pfs_crypto_log_flush_and_process(psync_openfile_t *of, const char *filename, int dowaits, int locked) { int fd; @@ -973,12 +973,12 @@ static int psync_fs_crypto_log_flush_and_process(psync_openfile_t *of, pdbg_logf(D_NOTICE, "flushed log data %s", filename); /* flushing directory does not seem to work on either Windows on Mac, disable for now, maybe look at SQLite code to see if they flush if - (pdbg_unlikely(psync_fs_flush_cache_dir())) goto err_eio; + (pdbg_unlikely(pfs_flush_cache_dir())) goto err_eio; */ // pdbg_assert(NULL=="break here to test log replay"); if (pdbg_unlikely( - psync_fs_crypto_process_log(fd, of->datafile, of->indexfile, 0))) + pfs_crypto_process_log(fd, of->datafile, of->indexfile, 0))) goto err_eio; pfile_close(fd); if (dowaits && !locked) @@ -999,7 +999,7 @@ err_eio: return -EIO; } -static int psync_fs_write_interval_tree_to_log(psync_openfile_t *of) { +static int pfs_write_interval_tree_to_log(psync_openfile_t *of) { psync_crypto_log_header logs[4096 / sizeof(psync_crypto_log_header)]; psync_interval_tree_t *itr; uint64_t len; @@ -1042,14 +1042,14 @@ static int psync_fs_write_interval_tree_to_log(psync_openfile_t *of) { return 0; } -static int psync_fs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) { +static int pfs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) { psync_crypto_offsets_t offsets; psync_fsfileid_t fileid; const char *cachepath; char *olog, *flog; char fileidhex[sizeof(psync_fsfileid_t) * 2 + 2]; int ret; - pfscrypto_offset_by_size(of->currentsize, &offsets); + pfs_crpt_offset_by_size(of->currentsize, &offsets); if (of->logoffset == PSYNC_CRYPTO_SECTOR_SIZE && offsets.masterauthoff + (offsets.needmasterauth ? PSYNC_CRYPTO_AUTH_SIZE : 0) == @@ -1059,19 +1059,19 @@ static int psync_fs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) { } pdbg_logf(D_NOTICE, "finalizing log of %s size %lu", of->currentname, (unsigned long)of->currentsize); - pfscrypto_offset_by_size(of->currentsize, &offsets); - ret = psync_fs_write_auth_tree_to_log(of, &offsets); + pfs_crpt_offset_by_size(of->currentsize, &offsets); + ret = pfs_write_auth_tree_to_log(of, &offsets); if (pdbg_unlikely(ret)) return ret; pdbg_logf(D_NOTICE, "wrote checksums to log of %s", of->currentname); if (!of->newfile) { pdbg_logf(D_NOTICE, "writing interval tree to log of %s", of->currentname); - ret = psync_fs_write_interval_tree_to_log(of); + ret = pfs_write_interval_tree_to_log(of); if (pdbg_unlikely(ret)) return ret; pdbg_logf(D_NOTICE, "wrote interval tree to log of %s", of->currentname); } - ret = psync_fs_crypto_mark_log_finalized( + ret = pfs_crypto_mark_log_finalized( of, offsets.masterauthoff + (offsets.needmasterauth ? PSYNC_CRYPTO_AUTH_SIZE : 0)); if (pdbg_unlikely(ret)) @@ -1087,49 +1087,49 @@ static int psync_fs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) { psync_binhex(fileidhex, &fileid, sizeof(psync_fsfileid_t)); fileidhex[sizeof(psync_fsfileid_t)] = 'l'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; - olog = psync_strcat(cachepath, "/", fileidhex, NULL); + olog = putil_strcat(cachepath, "/", fileidhex, NULL); fileidhex[sizeof(psync_fsfileid_t)] = 'f'; - flog = psync_strcat(cachepath, "/", fileidhex, NULL); + flog = putil_strcat(cachepath, "/", fileidhex, NULL); if (pdbg_unlikely(pfile_rename_overwrite(olog, flog)) || pdbg_unlikely((of->logfile = pfile_open(olog, O_RDWR, O_CREAT | O_TRUNC)) == INVALID_HANDLE_VALUE) || - pdbg_unlikely(pfscrypto_init_log(of))) { + pdbg_unlikely(pfs_crpt_init_log(of))) { free(olog); free(flog); return -EIO; } ptree_for_each_element_call_safe(of->sectorsinlog, psync_sector_inlog_t, tree, free); of->sectorsinlog = PSYNC_TREE_EMPTY; - ret = psync_fs_crypto_log_flush_and_process(of, flog, 0, 1); + ret = pfs_crypto_log_flush_and_process(of, flog, 0, 1); pfile_delete(flog); free(olog); free(flog); return pdbg_return_neg(ret); } -static int psync_fs_crypto_finalize_log(psync_openfile_t *of, int fullsync) { +static int pfs_crypto_finalize_log(psync_openfile_t *of, int fullsync) { int ret; if (of->extender) { pdbg_assert(of->currentsize == of->extender->extendto); of->currentsize = of->extender->extendedto; - ret = psync_fs_crypto_do_finalize_log(of, fullsync); + ret = pfs_crypto_do_finalize_log(of, fullsync); of->currentsize = of->extender->extendto; } else - ret = psync_fs_crypto_do_finalize_log(of, fullsync); + ret = pfs_crypto_do_finalize_log(of, fullsync); return ret; } -static void psync_fs_crypt_add_sector_to_interval_tree( +static void pfs_crypt_add_sector_to_interval_tree( psync_openfile_t *of, psync_crypto_sectorid_t sectorid, size_t size) { uint64_t offset; - offset = (uint64_t)pfscrypto_sector_id(sectorid) * + offset = (uint64_t)pfs_crpt_sector_id(sectorid) * PSYNC_CRYPTO_SECTOR_SIZE; psync_interval_tree_add(&of->writeintervals, offset, offset + size); } PSYNC_NOINLINE static void -psync_fs_crypto_reset_log_to_off(psync_openfile_t *of, uint32_t off) { +pfs_crypto_reset_log_to_off(psync_openfile_t *of, uint32_t off) { int64_t sz; sz = pfile_size(of->logfile); if (sz != off) @@ -1148,7 +1148,7 @@ psync_fs_crypto_reset_log_to_off(psync_openfile_t *of, uint32_t off) { of->currentname); return; } - of->currentsize = pfscrypto_plain_size(sz); + of->currentsize = pfs_crpt_plain_size(sz); pdbg_logf(D_WARNING, "emptying log"); pfile_close(of->logfile); cachepath = psync_setting_get_string(_PS(fscachepath)); @@ -1156,13 +1156,13 @@ psync_fs_crypto_reset_log_to_off(psync_openfile_t *of, uint32_t off) { psync_binhex(fileidhex, &fileid, sizeof(psync_fsfileid_t)); fileidhex[sizeof(psync_fsfileid_t)] = 'l'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; - log = psync_strcat(cachepath, "/", fileidhex, NULL); + log = putil_strcat(cachepath, "/", fileidhex, NULL); if (pfile_delete(log)) pdbg_logf(D_NOTICE, "could not delete old log file %s", log); of->logfile = pfile_open(log, O_RDWR, O_CREAT | O_TRUNC); if (of->logfile == INVALID_HANDLE_VALUE) pdbg_logf(D_WARNING, "could not create new file %s", log); - else if (pfscrypto_init_log(of)) + else if (pfs_crpt_init_log(of)) pdbg_logf(D_WARNING, "could not init log file %s", log); } else @@ -1170,7 +1170,7 @@ psync_fs_crypto_reset_log_to_off(psync_openfile_t *of, uint32_t off) { } static int -psync_fs_crypto_write_newfile_full_sector(psync_openfile_t *of, const char *buf, +pfs_crypto_write_newfile_full_sector(psync_openfile_t *of, const char *buf, psync_crypto_sectorid_t sectorid, size_t size) { psync_crypto_log_data_record rec; @@ -1185,41 +1185,41 @@ psync_fs_crypto_write_newfile_full_sector(psync_openfile_t *of, const char *buf, memset(&rec.header, 0, sizeof(psync_crypto_log_header)); rec.header.type = PSYNC_CRYPTO_LOG_DATA; rec.header.length = size; - rec.header.offset = psync_fs_crypto_data_offset_by_sectorid(sectorid); + rec.header.offset = pfs_crypto_data_offset_by_sectorid(sectorid); len = offsetof(psync_crypto_log_data_record, data) + size; wrt = pfile_pwrite(of->logfile, &rec, len, of->logoffset); if (unlikely(wrt != len)) { pdbg_logf(D_ERROR, "write to log of %u bytes returned %d", (unsigned)len, (int)wrt); - psync_fs_crypto_reset_log_to_off(of, of->logoffset); + pfs_crypto_reset_log_to_off(of, of->logoffset); return -EIO; } pcrc32c_fast_hash256_update(&of->loghashctx, &rec, len); - psync_fs_crypto_set_sector_log_offset(of, sectorid, of->logoffset, auth); + pfs_crypto_set_sector_log_offset(of, sectorid, of->logoffset, auth); of->logoffset += len; if (!of->newfile) - psync_fs_crypt_add_sector_to_interval_tree(of, sectorid, size); + pfs_crypt_add_sector_to_interval_tree(of, sectorid, size); return 0; } -static int psync_fs_crypto_write_newfile_partial_sector( +static int pfs_crypto_write_newfile_partial_sector( psync_openfile_t *of, const char *buf, psync_crypto_sectorid_t sectorid, size_t size, off_t offset) { char buff[PSYNC_CRYPTO_SECTOR_SIZE]; int rd; pdbg_assert(offset + size <= PSYNC_CRYPTO_SECTOR_SIZE); memset(buff, 0, sizeof(buff)); - rd = psync_fs_crypto_read_newfile_full_sector(of, buff, sectorid); + rd = pfs_crypto_read_newfile_full_sector(of, buff, sectorid); if (rd < 0) return rd; pdbg_assertw(rd >= offset); memcpy(buff + offset, buf, size); if (rd < size + offset) rd = size + offset; - return psync_fs_crypto_write_newfile_full_sector(of, buff, sectorid, rd); + return pfs_crypto_write_newfile_full_sector(of, buff, sectorid, rd); } -static int psync_fs_newfile_fillzero(psync_openfile_t *of, uint64_t size, +static int pfs_newfile_fillzero(psync_openfile_t *of, uint64_t size, uint64_t offset) { char buff[PSYNC_CRYPTO_SECTOR_SIZE]; uint64_t wr; @@ -1231,7 +1231,7 @@ static int psync_fs_newfile_fillzero(psync_openfile_t *of, uint64_t size, wr = PSYNC_CRYPTO_SECTOR_SIZE - (offset % PSYNC_CRYPTO_SECTOR_SIZE); if (wr > size) wr = size; - ret = psync_fs_crypto_write_newfile_partial_sector( + ret = pfs_crypto_write_newfile_partial_sector( of, buff, sectorid, wr, offset % PSYNC_CRYPTO_SECTOR_SIZE); if (ret < 0) goto fail; @@ -1246,7 +1246,7 @@ static int psync_fs_newfile_fillzero(psync_openfile_t *of, uint64_t size, wr = PSYNC_CRYPTO_SECTOR_SIZE; else wr = size; - ret = psync_fs_crypto_write_newfile_full_sector(of, buff, sectorid, wr); + ret = pfs_crypto_write_newfile_full_sector(of, buff, sectorid, wr); if (ret < 0) goto fail; size -= wr; @@ -1260,7 +1260,7 @@ fail: return pdbg_return(ret); } -static int pfscrypto_write_new_nu(psync_openfile_t *of, +static int pfs_crpt_write_new_nu(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset, @@ -1281,12 +1281,12 @@ static int pfscrypto_write_new_nu(psync_openfile_t *of, if (unlikely(!size)) return 0; if (checkextender) { - ret = psync_fs_crypto_wait_extender_after_locked(of, offset + size); + ret = pfs_crypto_wait_extender_after_locked(of, offset + size); if (pdbg_unlikely(ret)) return ret; } if (unlikely(of->currentsize < offset)) { - ret = psync_fs_newfile_fillzero(of, offset - of->currentsize, + ret = pfs_newfile_fillzero(of, offset - of->currentsize, of->currentsize); if (ret) return ret; @@ -1300,7 +1300,7 @@ static int pfscrypto_write_new_nu(psync_openfile_t *of, offdiff = PSYNC_CRYPTO_SECTOR_SIZE - off2; else offdiff = size; - ret = psync_fs_crypto_write_newfile_partial_sector(of, buf, sectorid, + ret = pfs_crypto_write_newfile_partial_sector(of, buf, sectorid, offdiff, off2); offset += offdiff; buf += offdiff; @@ -1313,7 +1313,7 @@ static int pfscrypto_write_new_nu(psync_openfile_t *of, of->currentsize = offset; } while (size >= PSYNC_CRYPTO_SECTOR_SIZE) { - ret = psync_fs_crypto_write_newfile_full_sector(of, buf, sectorid, + ret = pfs_crypto_write_newfile_full_sector(of, buf, sectorid, PSYNC_CRYPTO_SECTOR_SIZE); buf += PSYNC_CRYPTO_SECTOR_SIZE; offset += PSYNC_CRYPTO_SECTOR_SIZE; @@ -1327,9 +1327,9 @@ static int pfscrypto_write_new_nu(psync_openfile_t *of, } if (size) { if (offset == of->currentsize) - ret = psync_fs_crypto_write_newfile_full_sector(of, buf, sectorid, size); + ret = pfs_crypto_write_newfile_full_sector(of, buf, sectorid, size); else - ret = psync_fs_crypto_write_newfile_partial_sector(of, buf, sectorid, + ret = pfs_crypto_write_newfile_partial_sector(of, buf, sectorid, size, 0); if (ret) return ret; @@ -1339,22 +1339,22 @@ static int pfscrypto_write_new_nu(psync_openfile_t *of, } if (of->extender) { if (of->extender->finalizelog && of->logoffset >= PSYNC_CRYPTO_MAX_LOG_SIZE) - ret = psync_fs_crypto_finalize_log(of, 0); + ret = pfs_crypto_finalize_log(of, 0); } else if (of->logoffset >= PSYNC_CRYPTO_MAX_LOG_SIZE) - ret = psync_fs_crypto_finalize_log(of, 0); + ret = pfs_crypto_finalize_log(of, 0); if (ret) return ret; return wrt; } -int pfscrypto_write_new(psync_openfile_t *of, const char *buf, +int pfs_crpt_write_new(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset) { - int ret = pfscrypto_write_new_nu(of, buf, size, offset, 1); + int ret = pfs_crpt_write_new_nu(of, buf, size, offset, 1); pthread_mutex_unlock(&of->mutex); return ret; } -int pfscrypto_read_mod(psync_openfile_t *of, char *buf, +int pfs_crpt_read_mod(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset) { psync_interval_tree_t *itr; char *bufoff; @@ -1368,9 +1368,9 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf, if (unlikely((size + offset + PSYNC_CRYPTO_SECTOR_SIZE - 1) / PSYNC_CRYPTO_SECTOR_SIZE > PSYNC_CRYPTO_MAX_SECTORID)) - return psync_fs_unlock_ret(of, -EINVAL); + return pfs_unlock_ret(of, -EINVAL); if (unlikely(!size || offset >= of->currentsize)) - return psync_fs_unlock_ret(of, 0); + return pfs_unlock_ret(of, 0); if (offset + size > of->currentsize) size = of->currentsize - offset; firstsectorid = offset / PSYNC_CRYPTO_SECTOR_SIZE; @@ -1378,7 +1378,7 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf, rfr = 0; itr = NULL; for (sectorid = firstsectorid; sectorid <= lastsectorid; sectorid++) { - esectorid = pfscrypto_sector_id(sectorid); + esectorid = pfs_crpt_sector_id(sectorid); eoffset = (uint64_t)esectorid * PSYNC_CRYPTO_SECTOR_SIZE; if (itr && itr->from <= eoffset && itr->to > eoffset) rfr |= 1; @@ -1394,7 +1394,7 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf, if (rfr == 1) { pdbg_logf(D_NOTICE, "doing read at offset %lu size %lu from local changes", (unsigned long)offset, (unsigned long)size); - return pfscrypto_read_new(of, buf, size, offset); + return pfs_crpt_read_new(of, buf, size, offset); } else if (rfr == 2) { pdbg_logf(D_NOTICE, "doing read at offset %lu size %lu from remote only", (unsigned long)offset, (unsigned long)size); @@ -1411,17 +1411,17 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf, pdbg_logf(D_WARNING, "reading from remote failed with error %d", rfr); return rfr; } - psync_fs_lock_file(of); + pfs_lock_file(of); if (unlikely(offset + size > of->currentsize)) { pdbg_logf(D_NOTICE, "file size changed during read"); if (offset >= of->currentsize) - return psync_fs_unlock_ret(of, 0); + return pfs_unlock_ret(of, 0); size = of->currentsize - offset; lastsectorid = (offset + size - 1) / PSYNC_CRYPTO_SECTOR_SIZE; } offmod = offset % PSYNC_CRYPTO_SECTOR_SIZE; for (sectorid = firstsectorid; sectorid <= lastsectorid; sectorid++) { - esectorid = pfscrypto_sector_id(sectorid); + esectorid = pfs_crpt_sector_id(sectorid); eoffset = (uint64_t)esectorid * PSYNC_CRYPTO_SECTOR_SIZE; if (!(itr && itr->from <= eoffset && itr->to > eoffset)) { itr = psync_interval_tree_first_interval_containing_or_after( @@ -1433,10 +1433,10 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf, rd = PSYNC_CRYPTO_SECTOR_SIZE - offmod; if (rd > size) rd = size; - rfr = psync_fs_crypto_read_newfile_partial_sector(of, buf, sectorid, rd, + rfr = pfs_crypto_read_newfile_partial_sector(of, buf, sectorid, rd, offmod); if (pdbg_unlikely(rfr != rd)) - psync_fs_unlock_ret(of, rfr); + pfs_unlock_ret(of, rfr); } else { bufoff = buf + (sectorid - firstsectorid) * PSYNC_CRYPTO_SECTOR_SIZE - offmod; @@ -1446,23 +1446,23 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf, else rd = PSYNC_CRYPTO_SECTOR_SIZE; if (rd == PSYNC_CRYPTO_SECTOR_SIZE) - rfr = psync_fs_crypto_read_newfile_full_sector(of, bufoff, sectorid); + rfr = pfs_crypto_read_newfile_full_sector(of, bufoff, sectorid); else - rfr = psync_fs_crypto_read_newfile_partial_sector(of, bufoff, sectorid, + rfr = pfs_crypto_read_newfile_partial_sector(of, bufoff, sectorid, rd, 0); if (pdbg_unlikely(rfr != rd)) - psync_fs_unlock_ret(of, rfr); + pfs_unlock_ret(of, rfr); } } - return psync_fs_unlock_ret(of, size); + return pfs_unlock_ret(of, size); } -int pfscrypto_write_mod_nu(psync_openfile_t *of, +int pfs_crpt_write_mod_nu(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset, int checkextender); -static int psync_fs_modfile_fillzero(psync_openfile_t *of, uint64_t size, +static int pfs_modfile_fillzero(psync_openfile_t *of, uint64_t size, uint64_t offset, int checkextender) { char buff[PSYNC_CRYPTO_SECTOR_SIZE]; uint64_t wr; @@ -1479,7 +1479,7 @@ static int psync_fs_modfile_fillzero(psync_openfile_t *of, uint64_t size, else wr = size; } - ret = pfscrypto_write_mod_nu(of, buff, wr, offset, + ret = pfs_crpt_write_mod_nu(of, buff, wr, offset, checkextender); if (ret <= 0) return ret; @@ -1489,7 +1489,7 @@ static int psync_fs_modfile_fillzero(psync_openfile_t *of, uint64_t size, return 0; } -int pfscrypto_write_mod_nu(psync_openfile_t *of, +int pfs_crpt_write_mod_nu(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset, int checkextender) { @@ -1510,7 +1510,7 @@ int pfscrypto_write_mod_nu(psync_openfile_t *of, PSYNC_CRYPTO_MAX_SECTORID)) return -EINVAL; if (checkextender) { - ret = psync_fs_crypto_wait_extender_after_locked(of, offset + size); + ret = pfs_crypto_wait_extender_after_locked(of, offset + size); if (pdbg_unlikely(ret)) return ret; } @@ -1518,7 +1518,7 @@ int pfscrypto_write_mod_nu(psync_openfile_t *of, return 0; retry: if (unlikely(of->currentsize < offset)) { - ret = psync_fs_modfile_fillzero(of, offset - of->currentsize, + ret = pfs_modfile_fillzero(of, offset - of->currentsize, of->currentsize, 0); if (ret) return ret; @@ -1534,7 +1534,7 @@ retry: if ((uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE >= of->initialsize || (uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE >= of->currentsize) break; - esectorid = pfscrypto_sector_id(sectorid); + esectorid = pfs_crpt_sector_id(sectorid); eoffset = (uint64_t)esectorid * PSYNC_CRYPTO_SECTOR_SIZE; if (itr && itr->from <= eoffset && itr->to > eoffset) continue; @@ -1557,11 +1557,11 @@ retry: // already moved all trailing checksums to a new location and they would be // in of->writeintervals anyway. if (of->extender) - pfscrypto_offset_by_size(of->extender->extendedto, &offsets); + pfs_crpt_offset_by_size(of->extender->extendedto, &offsets); else - pfscrypto_offset_by_size(of->currentsize, &offsets); + pfs_crpt_offset_by_size(of->currentsize, &offsets); for (l = 0; l <= offsets.treelevels; l++) { - pfscrypto_get_auth_off(sectorid, l, &offsets, &eoffset, + pfs_crpt_get_auth_off(sectorid, l, &offsets, &eoffset, &asize, &aid); itr = psync_interval_tree_first_interval_containing_or_after( of->writeintervals, eoffset); @@ -1577,9 +1577,9 @@ retry: icnt = 0; isize = 0; if (of->currentsize < of->initialsize) - eoffset = pfscrypto_crypto_size(of->currentsize); + eoffset = pfs_crpt_crypto_size(of->currentsize); else - eoffset = pfscrypto_crypto_size(of->initialsize); + eoffset = pfs_crpt_crypto_size(of->initialsize); itr = psync_interval_tree_get_first(needtodwl); do { // if we are past initialsize, we are probably trying to download @@ -1618,7 +1618,7 @@ retry: psync_interval_tree_free(needtodwl); ret = ppagecache_readv_locked(of, ranges, icnt); // we are unlocked now - psync_fs_lock_file(of); + pfs_lock_file(of); if (unlikely(ret)) { free(ranges); free(tmpbuf); @@ -1667,18 +1667,18 @@ retry: } // now that we have all auth or partial data sectors, we proceed the same way // as if it is a new file write - return pfscrypto_write_new_nu(of, buf, size, offset, + return pfs_crpt_write_new_nu(of, buf, size, offset, checkextender); } -int pfscrypto_write_mod(psync_openfile_t *of, const char *buf, +int pfs_crpt_write_mod(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset) { - int ret = pfscrypto_write_mod_nu(of, buf, size, offset, 1); + int ret = pfs_crpt_write_mod_nu(of, buf, size, offset, 1); pthread_mutex_unlock(&of->mutex); return ret; } -static int pfscrypto_truncate_to_zero(psync_openfile_t *of) { +static int pfs_crpt_truncate_to_zero(psync_openfile_t *of) { int ret; pdbg_logf(D_NOTICE, "truncating file %s from %lu to zero", of->currentname, (unsigned long)of->currentsize); @@ -1687,23 +1687,23 @@ static int pfscrypto_truncate_to_zero(psync_openfile_t *of) { pdbg_logf(D_WARNING, "failed to truncate log file of %s", of->currentname); return -EIO; } - ret = pfscrypto_init_log(of); + ret = pfs_crpt_init_log(of); if (unlikely(ret)) return ret; if (!of->newfile) { psync_interval_tree_free(of->writeintervals); of->writeintervals = NULL; psync_interval_tree_add(&of->writeintervals, 0, - pfscrypto_crypto_size(of->initialsize)); + pfs_crpt_crypto_size(of->initialsize)); } ptree_for_each_element_call_safe(of->sectorsinlog, psync_sector_inlog_t, tree, free); of->sectorsinlog = PSYNC_TREE_EMPTY; of->currentsize = 0; - psync_fs_crypto_kill_extender_locked(of); + pfs_crypto_kill_extender_locked(of); return 0; } -static int pfscrypto_truncate_down(psync_openfile_t *of, uint64_t size) { +static int pfs_crpt_truncate_down(psync_openfile_t *of, uint64_t size) { char buf[PSYNC_CRYPTO_SECTOR_SIZE]; uint64_t writeid, lastsectoff, elastsectoroff; psync_interval_tree_t *intr; @@ -1719,7 +1719,7 @@ static int pfscrypto_truncate_down(psync_openfile_t *of, uint64_t size) { return of->extender->error; if (!of->extender->ready) { if (of->extender->extendedto > size) - psync_fs_crypto_kill_extender_locked(of); + pfs_crypto_kill_extender_locked(of); else { pdbg_logf(D_NOTICE, "extender is so far extended up to %lu, switching target from " @@ -1739,37 +1739,37 @@ static int pfscrypto_truncate_down(psync_openfile_t *of, uint64_t size) { lastsectoroldsize = PSYNC_CRYPTO_SECTOR_SIZE; else lastsectoroldsize = of->currentsize - lastsectoff; - elastsectorid = pfscrypto_sector_id(lastsectorid); + elastsectorid = pfs_crpt_sector_id(lastsectorid); elastsectoroff = (uint64_t)elastsectorid * PSYNC_CRYPTO_SECTOR_SIZE; retry: if (of->newfile || ((intr = psync_interval_tree_first_interval_containing_or_after( of->writeintervals, elastsectoroff)) && intr->from <= elastsectoroff)) { - ret = psync_fs_crypto_read_newfile_full_sector(of, buf, lastsectorid); + ret = pfs_crypto_read_newfile_full_sector(of, buf, lastsectorid); if (ret < 0) return ret; pdbg_assert(ret == lastsectoroldsize); } else { writeid = of->writeid; - ret = pfscrypto_read_mod(of, buf, lastsectoroldsize, + ret = pfs_crpt_read_mod(of, buf, lastsectoroldsize, lastsectoff); // unlocked now if (ret < 0) return ret; - psync_fs_lock_file(of); + pfs_lock_file(of); if (unlikely(of->writeid != writeid)) { pdbg_logf(D_NOTICE, "writeid changed, restarting"); goto retry; } // the write will push all the auth data we need to the datafile (it is // probably in cache from the read) - ret = pfscrypto_write_mod(of, buf, lastsectoroldsize, + ret = pfs_crpt_write_mod(of, buf, lastsectoroldsize, lastsectoff); // unlocked now if (ret < 0) return ret; - psync_fs_lock_file(of); + pfs_lock_file(of); if (unlikely(of->writeid != writeid)) { pdbg_logf(D_NOTICE, "writeid changed, restarting"); goto retry; @@ -1787,26 +1787,26 @@ retry: free(tr); tr = ntr; } - ret = psync_fs_crypto_write_newfile_full_sector(of, buf, lastsectorid, + ret = pfs_crypto_write_newfile_full_sector(of, buf, lastsectorid, lastsectornewsize); if (ret < 0) return ret; of->currentsize = size; if (!of->newfile) psync_interval_tree_cut_end(&of->writeintervals, - pfscrypto_crypto_size(size)); + pfs_crpt_crypto_size(size)); pdbg_logf(D_NOTICE, "file %s truncated to %lu", of->currentname, (unsigned long)size); return 0; } -static void psync_fs_extender_thread(void *ptr) { +static void pfs_extender_thread(void *ptr) { psync_openfile_t *of; psync_enc_file_extender_t *ext; uint64_t cs; int ret; of = (psync_openfile_t *)ptr; - psync_fs_lock_file(of); + pfs_lock_file(of); pdbg_assert(of->extender); ext = of->extender; while (!ext->kill && ext->extendedto < ext->extendto) { @@ -1818,9 +1818,9 @@ static void psync_fs_extender_thread(void *ptr) { } else cs = ext->extendto - ext->extendedto; if (of->newfile) - ret = psync_fs_newfile_fillzero(of, cs, ext->extendedto); + ret = pfs_newfile_fillzero(of, cs, ext->extendedto); else - ret = psync_fs_modfile_fillzero(of, cs, ext->extendedto, 0); + ret = pfs_modfile_fillzero(of, cs, ext->extendedto, 0); if (ret) { ext->error = ret; of->currentsize = ext->extendedto; @@ -1833,15 +1833,15 @@ static void psync_fs_extender_thread(void *ptr) { pdbg_logf(D_NOTICE, "extender at %lu of %lu", (unsigned long)ext->extendedto, (unsigned long)ext->extendto); sched_yield(); - psync_fs_lock_file(of); + pfs_lock_file(of); if (ext->waiters) { pthread_cond_broadcast(&ext->cond); pthread_mutex_unlock(&of->mutex); sched_yield(); - psync_fs_lock_file(of); + pfs_lock_file(of); } if (of->logoffset >= PSYNC_CRYPTO_MAX_LOG_SIZE) { - ret = psync_fs_crypto_finalize_log(of, 0); + ret = pfs_crypto_finalize_log(of, 0); if (ret) { ext->error = ret; of->currentsize = ext->extendedto; @@ -1861,16 +1861,16 @@ static void psync_fs_extender_thread(void *ptr) { pthread_cond_broadcast(&ext->cond); pthread_mutex_unlock(&of->mutex); psys_sleep_milliseconds(1); - psync_fs_lock_file(of); + pfs_lock_file(of); } of->extender = NULL; pthread_mutex_unlock(&of->mutex); pthread_cond_destroy(&ext->cond); free(ext); - psync_fs_dec_of_refcnt(of); + pfs_dec_of_refcnt(of); } -static int psync_fs_crypto_run_extender(psync_openfile_t *of, uint64_t size) { +static int pfs_crypto_run_extender(psync_openfile_t *of, uint64_t size) { psync_enc_file_extender_t *ext; pdbg_assert(of->currentsize < size); pdbg_assert(!of->extender); @@ -1887,12 +1887,12 @@ static int psync_fs_crypto_run_extender(psync_openfile_t *of, uint64_t size) { ext->kill = 0; ext->finalizelog = 1; of->extender = ext; - psync_fs_inc_of_refcnt_locked(of); - prun_thread1("extender", psync_fs_extender_thread, of); + pfs_inc_of_refcnt_locked(of); + prun_thread1("extender", pfs_extender_thread, of); return 0; } -int pfscrypto_truncate(psync_openfile_t *of, uint64_t size) { +int pfs_crpt_truncate(psync_openfile_t *of, uint64_t size) { int ret; pdbg_assert(of->modified); retry: @@ -1901,7 +1901,7 @@ retry: (unsigned long)of->currentsize, (unsigned long)size); if (of->extender) { if (of->extender->ready) { - ret = psync_fs_crypto_wait_no_extender_locked(of); + ret = pfs_crypto_wait_no_extender_locked(of); if (ret) return ret; else @@ -1923,7 +1923,7 @@ retry: // for files that are not new, there is a chance for a network error, // better catch it now there is no any significance in the size of the // write, even 1 byte write should download everything that we need - ret = psync_fs_modfile_fillzero(of, + ret = pfs_modfile_fillzero(of, of->currentsize % PSYNC_CRYPTO_SECTOR_SIZE + PSYNC_CRYPTO_SECTOR_SIZE, @@ -1931,45 +1931,45 @@ retry: if (ret) return ret; } - return psync_fs_crypto_run_extender(of, size); + return pfs_crypto_run_extender(of, size); } if (of->newfile) - ret = psync_fs_newfile_fillzero(of, size - of->currentsize, + ret = pfs_newfile_fillzero(of, size - of->currentsize, of->currentsize); else - ret = psync_fs_modfile_fillzero(of, size - of->currentsize, + ret = pfs_modfile_fillzero(of, size - of->currentsize, of->currentsize, 0); } else if (of->currentsize > size) { if (size == 0) - ret = pfscrypto_truncate_to_zero(of); + ret = pfs_crpt_truncate_to_zero(of); else - return pfscrypto_truncate_down(of, size); + return pfs_crpt_truncate_down(of, size); } else ret = 0; return ret; } -int pfscrypto_flush(psync_openfile_t *of) { - int ret = psync_fs_crypto_wait_no_extender_locked(of); +int pfs_crpt_flush(psync_openfile_t *of) { + int ret = pfs_crypto_wait_no_extender_locked(of); if (ret) return ret; - return psync_fs_crypto_finalize_log(of, 1); + return pfs_crypto_finalize_log(of, 1); } -uint64_t pfscrypto_plain_size(uint64_t cryptosize) { +uint64_t pfs_crpt_plain_size(uint64_t cryptosize) { psync_crypto_offsets_t offsets; - psync_fs_crypto_offsets_by_cryptosize(cryptosize, &offsets); + pfs_crypto_offsets_by_cryptosize(cryptosize, &offsets); return offsets.plainsize; } -uint64_t pfscrypto_crypto_size(uint64_t plainsize) { +uint64_t pfs_crpt_crypto_size(uint64_t plainsize) { psync_crypto_offsets_t offsets; - pfscrypto_offset_by_size(plainsize, &offsets); + pfs_crpt_offset_by_size(plainsize, &offsets); return offsets.masterauthoff + (offsets.needmasterauth ? PSYNC_CRYPTO_AUTH_SIZE : 0); } -void pfscrypto_get_auth_off(psync_crypto_sectorid_t sectorid, +void pfs_crpt_get_auth_off(psync_crypto_sectorid_t sectorid, uint32_t level, psync_crypto_offsets_t *offsets, uint64_t *offset, uint32_t *size, @@ -1990,13 +1990,13 @@ void pfscrypto_get_auth_off(psync_crypto_sectorid_t sectorid, *size = offsets->lastauthsectorlen[level]; } else { pdbg_assert(secd < sizesecd); - *offset = psync_fs_crypto_auth_offset(level, secd); + *offset = pfs_crypto_auth_offset(level, secd); *size = PSYNC_CRYPTO_SECTOR_SIZE; } *authid = aid; } -static void psync_fs_crypto_del_log(const char *path) { +static void pfs_crypto_del_log(const char *path) { pdbg_logf(D_NOTICE, "deleting not finalized log file %s", path); if (pfile_delete(path)) pdbg_logf(D_WARNING, "failed to delete %s", path); @@ -2011,7 +2011,7 @@ static unsigned conv_xdigit(char dig) { return dig - 'A' + 10; } -static void psync_fs_pause_task_by_name(const char *fn) { +static void pfs_pause_task_by_name(const char *fn) { uint64_t taskid, mul; psync_sql_res *res; taskid = 0; @@ -2027,7 +2027,7 @@ static void psync_fs_pause_task_by_name(const char *fn) { psql_run_free(res); } -static void psync_fs_crypto_check_log(char *path, const char *fn) { +static void pfs_crypto_check_log(char *path, const char *fn) { int lfd, dfd, ifd; size_t plen; int ret; @@ -2036,7 +2036,7 @@ static void psync_fs_crypto_check_log(char *path, const char *fn) { if (unlikely(lfd == INVALID_HANDLE_VALUE)) { pdbg_logf(D_WARNING, "could not open %s for reading, errno=%d", path, (int)errno); - psync_fs_pause_task_by_name(fn); + pfs_pause_task_by_name(fn); return; } pdbg_logf(D_NOTICE, "processing log file %s", path); @@ -2049,12 +2049,12 @@ static void psync_fs_crypto_check_log(char *path, const char *fn) { (int)errno); pfile_close(lfd); path[plen] = och; - psync_fs_crypto_del_log(path); + pfs_crypto_del_log(path); return; } path[plen] = 'i'; ifd = pfile_open(path, O_RDWR, 0); - ret = psync_fs_crypto_process_log(lfd, dfd, ifd, 1) || pfile_sync(dfd); + ret = pfs_crypto_process_log(lfd, dfd, ifd, 1) || pfile_sync(dfd); pfile_close(lfd); pfile_close(dfd); if (ifd != INVALID_HANDLE_VALUE) { @@ -2065,14 +2065,14 @@ static void psync_fs_crypto_check_log(char *path, const char *fn) { path[plen] = och; if (unlikely(ret)) { pdbg_logf(D_WARNING, "failed to process log file %s", path); - psync_fs_crypto_del_log(path); + pfs_crypto_del_log(path); } else { pfile_delete(path); pdbg_logf(D_NOTICE, "processed log file %s", path); } } -static void psync_fs_crypto_check_file(void *ptr, ppath_fast_stat *st) { +static void pfs_crypto_check_file(void *ptr, ppath_fast_stat *st) { size_t len; char *path; char ch; @@ -2083,18 +2083,18 @@ static void psync_fs_crypto_check_file(void *ptr, ppath_fast_stat *st) { return; ch = st->name[len - 1]; if (ch == 'l' || ch == 'f') { - path = psync_strcat((const char *)ptr, "/", st->name, + path = putil_strcat((const char *)ptr, "/", st->name, NULL); - psync_fs_crypto_check_log(path, st->name); + pfs_crypto_check_log(path, st->name); free(path); } } -void pfscrypto_check_logs() { +void pfs_crpt_check_logs() { const char *cachepath; cachepath = psync_setting_get_string(_PS(fscachepath)); pdbg_logf(D_NOTICE, "checking for unprocessed log files in %s", cachepath); - if (ppath_ls_fast(cachepath, psync_fs_crypto_check_file, + if (ppath_ls_fast(cachepath, pfs_crypto_check_file, (char *)cachepath)) pdbg_logf(D_WARNING, "list of %s failed", cachepath); pdbg_logf(D_NOTICE, "log check finished"); diff --git a/pclsync/pfscrypto.h b/pclsync/pfscrypto.h index 99ce415..b19a45a 100644 --- a/pclsync/pfscrypto.h +++ b/pclsync/pfscrypto.h @@ -53,18 +53,18 @@ typedef struct { typedef pcrypto_sector_auth_t psync_crypto_auth_sector_t[PSYNC_CRYPTO_HASH_TREE_SECTORS]; -int pfscrypto_init_log(psync_openfile_t *of); -int pfscrypto_read_new(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset); -int pfscrypto_write_new(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset); -int pfscrypto_read_mod(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset); -int pfscrypto_write_mod(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset); -int pfscrypto_truncate(psync_openfile_t *of, uint64_t size); -int pfscrypto_flush(psync_openfile_t *of); -psync_crypto_sectorid_t pfscrypto_sector_id(psync_crypto_sectorid_t sectorid); -void pfscrypto_offset_by_size(uint64_t size, psync_crypto_offsets_t *offsets); -uint64_t pfscrypto_plain_size(uint64_t cryptosize); -uint64_t pfscrypto_crypto_size(uint64_t plainsize); -void pfscrypto_get_auth_off(psync_crypto_sectorid_t sectorid, uint32_t level, psync_crypto_offsets_t *offsets, uint64_t *offset, uint32_t *size, uint32_t *authid); -void pfscrypto_check_logs(); +int pfs_crpt_init_log(psync_openfile_t *of); +int pfs_crpt_read_new(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset); +int pfs_crpt_write_new(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset); +int pfs_crpt_read_mod(psync_openfile_t *of, char *buf, uint64_t size, uint64_t offset); +int pfs_crpt_write_mod(psync_openfile_t *of, const char *buf, uint64_t size, uint64_t offset); +int pfs_crpt_truncate(psync_openfile_t *of, uint64_t size); +int pfs_crpt_flush(psync_openfile_t *of); +psync_crypto_sectorid_t pfs_crpt_sector_id(psync_crypto_sectorid_t sectorid); +void pfs_crpt_offset_by_size(uint64_t size, psync_crypto_offsets_t *offsets); +uint64_t pfs_crpt_plain_size(uint64_t cryptosize); +uint64_t pfs_crpt_crypto_size(uint64_t plainsize); +void pfs_crpt_get_auth_off(psync_crypto_sectorid_t sectorid, uint32_t level, psync_crypto_offsets_t *offsets, uint64_t *offset, uint32_t *size, uint32_t *authid); +void pfs_crpt_check_logs(); #endif diff --git a/pclsync/pfsfolder.c b/pclsync/pfsfolder.c index 0a7100e..26c008d 100644 --- a/pclsync/pfsfolder.c +++ b/pclsync/pfsfolder.c @@ -62,7 +62,7 @@ static char *get_encname_for_folder(psync_fsfolderid_t folderid, cryptoerr = psync_crypto_to_error(enc); return NULL; } - name = psync_strndup(path, len); + name = putil_strndup(path, len); encname = pcryptofolder_fldencode_filename(enc, name); pcryptofolder_fldencoder_release(folderid, enc); free(name); @@ -74,7 +74,7 @@ static psync_fspath_t *ret_folder_data(psync_fsfolderid_t folderid, uint32_t flags, uint32_t shareid) { psync_fspath_t *ret; if (flags & PSYNC_FOLDER_FLAG_ENCRYPTED && - strncmp(psync_fake_prefix, name, psync_fake_prefix_len)) { + strncmp(pfs_fake_prefix, name, pfs_fake_prefix_len)) { pcrypto_textenc_t enc; char *encname; size_t len; @@ -105,7 +105,7 @@ static psync_fspath_t *ret_folder_data(psync_fsfolderid_t folderid, return ret; } -char *get_decname_for_folder(psync_fsfolderid_t folderid, const char *path, +char *pfs_fldr_get_decname(psync_fsfolderid_t folderid, const char *path, size_t len) { char *name, *decname; pcrypto_textdec_t dec; @@ -114,7 +114,7 @@ char *get_decname_for_folder(psync_fsfolderid_t folderid, const char *path, cryptoerr = psync_crypto_to_error(dec); return NULL; } - name = psync_strndup(path, len); + name = putil_strndup(path, len); decname = pcryptofolder_flddecode_filename(dec, name); pcryptofolder_flddecoder_release(folderid, dec); free(name); @@ -147,7 +147,7 @@ static void check_userid(uint64_t userid, uint64_t folderid, do_check_userid(userid, folderid, shareid); } -psync_fspath_t *psync_fsfolder_resolve_path(const char *path) { +psync_fspath_t *pfs_fldr_resolve_path(const char *path) { psync_fsfolderid_t cfolderid; const char *sl; psync_fstask_folder_t *folder; @@ -211,10 +211,10 @@ psync_fspath_t *psync_fsfolder_resolve_path(const char *path) { elen = len; } row = psql_fetch_int(res); - folder = psync_fstask_get_folder_tasks_rdlocked(cfolderid); + folder = pfs_task_get_folder_tasks_rdlocked(cfolderid); if (folder) { - char *name = psync_strndup(ename, elen); - if ((mk = psync_fstask_find_mkdir(folder, name, 0))) { + char *name = putil_strndup(ename, elen); + if ((mk = pfs_task_find_mkdir(folder, name, 0))) { if (mk->flags & PSYNC_FOLDER_FLAG_INVISIBLE) { free(name); break; @@ -222,7 +222,7 @@ psync_fspath_t *psync_fsfolder_resolve_path(const char *path) { cfolderid = mk->folderid; flags = mk->flags; hasit = 1; - } else if (row && !psync_fstask_find_rmdir(folder, name, 0)) { + } else if (row && !pfs_task_find_rmdir(folder, name, 0)) { cfolderid = row[0]; permissions &= row[1]; flags = row[2]; @@ -254,7 +254,7 @@ psync_fspath_t *psync_fsfolder_resolve_path(const char *path) { return NULL; } -psync_fsfolderid_t psync_fsfolderid_by_path(const char *path, +psync_fsfolderid_t pfs_fldr_id_by_path(const char *path, uint32_t *pflags) { psync_fsfolderid_t cfolderid; const char *sl; @@ -305,14 +305,14 @@ psync_fsfolderid_t psync_fsfolderid_by_path(const char *path, elen = len; } row = psql_fetch_int(res); - folder = psync_fstask_get_folder_tasks_rdlocked(cfolderid); + folder = pfs_task_get_folder_tasks_rdlocked(cfolderid); if (folder) { - char *name = psync_strndup(ename, elen); - if ((mk = psync_fstask_find_mkdir(folder, name, 0))) { + char *name = putil_strndup(ename, elen); + if ((mk = pfs_task_find_mkdir(folder, name, 0))) { cfolderid = mk->folderid; flags = mk->flags; hasit = 1; - } else if (row && !psync_fstask_find_rmdir(folder, name, 0)) { + } else if (row && !pfs_task_find_rmdir(folder, name, 0)) { cfolderid = row[0]; flags = row[1]; hasit = 1; @@ -338,7 +338,7 @@ psync_fsfolderid_t psync_fsfolderid_by_path(const char *path, return PSYNC_INVALID_FSFOLDERID; } -psync_fsfolderid_t psync_fsfolderidperm_by_path(const char *path, +psync_fsfolderid_t pfs_fldr_idperm_by_path(const char *path, uint32_t *pflags, uint32_t *pPermissions) { psync_fsfolderid_t cfolderid; @@ -391,14 +391,14 @@ psync_fsfolderid_t psync_fsfolderidperm_by_path(const char *path, elen = len; } row = psql_fetch_int(res); - folder = psync_fstask_get_folder_tasks_rdlocked(cfolderid); + folder = pfs_task_get_folder_tasks_rdlocked(cfolderid); if (folder) { - char *name = psync_strndup(ename, elen); - if ((mk = psync_fstask_find_mkdir(folder, name, 0))) { + char *name = putil_strndup(ename, elen); + if ((mk = pfs_task_find_mkdir(folder, name, 0))) { cfolderid = mk->folderid; flags = mk->flags; hasit = 1; - } else if (row && !psync_fstask_find_rmdir(folder, name, 0)) { + } else if (row && !pfs_task_find_rmdir(folder, name, 0)) { cfolderid = row[0]; flags = row[1]; *pPermissions = row[2]; @@ -426,9 +426,9 @@ psync_fsfolderid_t psync_fsfolderidperm_by_path(const char *path, return PSYNC_INVALID_FSFOLDERID; } -int psync_fsfolder_crypto_error() { return cryptoerr; } +int pfs_fldr_crypto_error() { return cryptoerr; } -uint32_t psync_fsfolderflags_by_id(psync_fsfolderid_t folderid, +uint32_t pfs_fldr_flags_by_id(psync_fsfolderid_t folderid, uint32_t *pperm) { psync_sql_res *res; psync_uint_row row; @@ -458,7 +458,7 @@ retry: return ret; } /*********************************************************************************************************************/ -psync_fsfolderid_t psync_get_folderid(psync_fsfolderid_t parent_fid, +psync_fsfolderid_t pfs_fldr_get_folderid(psync_fsfolderid_t parent_fid, const char *name) { psync_fsfolderid_t folder_id = -1; psync_sql_res *res; diff --git a/pclsync/pfsfolder.h b/pclsync/pfsfolder.h index 769f3db..74a6f96 100644 --- a/pclsync/pfsfolder.h +++ b/pclsync/pfsfolder.h @@ -47,18 +47,18 @@ typedef struct { uint16_t flags; } psync_fspath_t; -psync_fspath_t *psync_fsfolder_resolve_path(const char *path); -psync_fsfolderid_t psync_fsfolderid_by_path(const char *path, uint32_t *pflags); -psync_fsfolderid_t psync_fsfolderidperm_by_path(const char *path, +psync_fspath_t *pfs_fldr_resolve_path(const char *path); +psync_fsfolderid_t pfs_fldr_id_by_path(const char *path, uint32_t *pflags); +psync_fsfolderid_t pfs_fldr_idperm_by_path(const char *path, uint32_t *pflags, uint32_t *pPermissions); -uint32_t psync_fsfolderflags_by_id(psync_fsfolderid_t folderid, +uint32_t pfs_fldr_flags_by_id(psync_fsfolderid_t folderid, uint32_t *pperm); -int psync_fsfolder_crypto_error(); -char *get_decname_for_folder(psync_fsfolderid_t folderid, const char *path, +int pfs_fldr_crypto_error(); +char *pfs_fldr_get_decname(psync_fsfolderid_t folderid, const char *path, size_t len); -psync_fsfolderid_t psync_get_folderid(psync_fsfolderid_t parent_fid, +psync_fsfolderid_t pfs_fldr_get_folderid(psync_fsfolderid_t parent_fid, const char *name); #endif diff --git a/pclsync/pfsstatic.c b/pclsync/pfsstatic.c index 7f23c29..7e83c20 100644 --- a/pclsync/pfsstatic.c +++ b/pclsync/pfsstatic.c @@ -546,9 +546,9 @@ static const unsigned char pcloudicon[] = { 0xf9, 0x7f, 0xb2, 0x54, 0x74, 0x86, 0x8e, 0x89, 0x9f, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82}; -void psync_fsstatic_add_files() { - psync_fstask_add_local_creat_static(0, ".directory", rootdir, +void pfs_stat_add_files() { + pfs_task_add_local_creat_static(0, ".directory", rootdir, strlen(rootdir)); - psync_fstask_add_local_creat_static(0, ".pcloudicon.png", pcloudicon, + pfs_task_add_local_creat_static(0, ".pcloudicon.png", pcloudicon, ARRAY_SIZE(pcloudicon)); } diff --git a/pclsync/pfsstatic.h b/pclsync/pfsstatic.h index 6266070..ad9e3fa 100644 --- a/pclsync/pfsstatic.h +++ b/pclsync/pfsstatic.h @@ -31,6 +31,6 @@ #ifndef _PSYNC_FSSTATIC_H #define _PSYNC_FSSTATIC_H -void psync_fsstatic_add_files(); +void pfs_stat_add_files(); #endif diff --git a/pclsync/pfstasks.c b/pclsync/pfstasks.c index e9704fd..ae4f532 100644 --- a/pclsync/pfstasks.c +++ b/pclsync/pfstasks.c @@ -66,37 +66,37 @@ static inline int psync_crypto_to_error(const void *ptr) { } psync_fstask_folder_t * -psync_fstask_get_or_create_folder_tasks(psync_fsfolderid_t folderid) { +pfs_task_get_or_create_folder_tasks(psync_fsfolderid_t folderid) { psync_fstask_folder_t *folder; psql_lock(); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); psql_unlock(); return folder; } psync_fstask_folder_t * -psync_fstask_get_folder_tasks(psync_fsfolderid_t folderid) { +pfs_task_get_folder_tasks(psync_fsfolderid_t folderid) { psync_fstask_folder_t *folder; psql_lock(); - folder = psync_fstask_get_folder_tasks_locked(folderid); + folder = pfs_task_get_folder_tasks_locked(folderid); psql_unlock(); return folder; } -void psync_fstask_release_folder_tasks(psync_fstask_folder_t *folder) { +void pfs_task_release_folder_tasks(psync_fstask_folder_t *folder) { psql_lock(); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); } psync_fstask_folder_t * -psync_fstask_get_ref_locked(psync_fstask_folder_t *folder) { +pfs_task_get_ref_locked(psync_fstask_folder_t *folder) { folder->refcnt++; return folder; } psync_fstask_folder_t * -psync_fstask_get_or_create_folder_tasks_locked(psync_fsfolderid_t folderid) { +pfs_task_get_or_create_folder_tasks_locked(psync_fsfolderid_t folderid) { psync_fstask_folder_t *folder; psync_tree *tr; int64_t d; @@ -137,7 +137,7 @@ psync_fstask_get_or_create_folder_tasks_locked(psync_fsfolderid_t folderid) { } psync_fstask_folder_t * -psync_fstask_get_folder_tasks_locked(psync_fsfolderid_t folderid) { +pfs_task_get_folder_tasks_locked(psync_fsfolderid_t folderid) { psync_fstask_folder_t *folder; psync_tree *tr; @@ -161,7 +161,7 @@ psync_fstask_get_folder_tasks_locked(psync_fsfolderid_t folderid) { } psync_fstask_folder_t * -psync_fstask_get_folder_tasks_rdlocked(psync_fsfolderid_t folderid) { +pfs_task_get_folder_tasks_rdlocked(psync_fsfolderid_t folderid) { psync_fstask_folder_t *folder; psync_tree *tr; tr = folders; @@ -177,7 +177,7 @@ psync_fstask_get_folder_tasks_rdlocked(psync_fsfolderid_t folderid) { return NULL; } -void psync_fstask_release_folder_tasks_locked(psync_fstask_folder_t *folder) { +void pfs_task_release_folder_tasks_locked(psync_fstask_folder_t *folder) { #if IS_DEBUG if ((!!folder->taskscnt) != (folder->creats || folder->mkdirs || folder->rmdirs || folder->unlinks)) @@ -192,7 +192,7 @@ void psync_fstask_release_folder_tasks_locked(psync_fstask_folder_t *folder) { } } -static psync_tree *psync_fstask_search_tree(psync_tree *tree, size_t nameoff, +static psync_tree *pfs_task_search_tree(psync_tree *tree, size_t nameoff, const char *name, uint64_t taskid, size_t taskidoff) { int c; @@ -229,7 +229,7 @@ static psync_tree *psync_fstask_search_tree(psync_tree *tree, size_t nameoff, } } -static psync_tree *psync_fstask_walk_tree(psync_tree *tree, uint64_t taskid, +static psync_tree *pfs_task_walk_tree(psync_tree *tree, uint64_t taskid, size_t taskidoff) { tree = ptree_get_first(tree); while (tree) { @@ -240,7 +240,7 @@ static psync_tree *psync_fstask_walk_tree(psync_tree *tree, uint64_t taskid, return NULL; } -static void psync_fstask_insert_into_tree(psync_tree **tree, size_t nameoff, +static void pfs_task_insert_into_tree(psync_tree **tree, size_t nameoff, psync_tree *element) { const char *name; psync_tree *node; @@ -278,65 +278,65 @@ static void psync_fstask_insert_into_tree(psync_tree **tree, size_t nameoff, } } -psync_fstask_mkdir_t *psync_fstask_find_mkdir(psync_fstask_folder_t *folder, +psync_fstask_mkdir_t *pfs_task_find_mkdir(psync_fstask_folder_t *folder, const char *name, uint64_t taskid) { return ptree_element( - psync_fstask_search_tree(folder->mkdirs, + pfs_task_search_tree(folder->mkdirs, offsetof(psync_fstask_mkdir_t, name), name, taskid, offsetof(psync_fstask_mkdir_t, taskid)), psync_fstask_mkdir_t, tree); } -psync_fstask_rmdir_t *psync_fstask_find_rmdir(psync_fstask_folder_t *folder, +psync_fstask_rmdir_t *pfs_task_find_rmdir(psync_fstask_folder_t *folder, const char *name, uint64_t taskid) { return ptree_element( - psync_fstask_search_tree(folder->rmdirs, + pfs_task_search_tree(folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), name, taskid, offsetof(psync_fstask_rmdir_t, taskid)), psync_fstask_rmdir_t, tree); } -psync_fstask_creat_t *psync_fstask_find_creat(psync_fstask_folder_t *folder, +psync_fstask_creat_t *pfs_task_find_creat(psync_fstask_folder_t *folder, const char *name, uint64_t taskid) { return ptree_element( - psync_fstask_search_tree(folder->creats, + pfs_task_search_tree(folder->creats, offsetof(psync_fstask_creat_t, name), name, taskid, offsetof(psync_fstask_creat_t, taskid)), psync_fstask_creat_t, tree); } -psync_fstask_unlink_t *psync_fstask_find_unlink(psync_fstask_folder_t *folder, +psync_fstask_unlink_t *pfs_task_find_unlink(psync_fstask_folder_t *folder, const char *name, uint64_t taskid) { return ptree_element( - psync_fstask_search_tree(folder->unlinks, + pfs_task_search_tree(folder->unlinks, offsetof(psync_fstask_unlink_t, name), name, taskid, offsetof(psync_fstask_unlink_t, taskid)), psync_fstask_unlink_t, tree); } psync_fstask_mkdir_t * -psync_fstask_find_mkdir_by_folderid(psync_fstask_folder_t *folder, +pfs_task_find_mkdir_by_folderid(psync_fstask_folder_t *folder, psync_fsfolderid_t folderid) { return ptree_element( - psync_fstask_walk_tree(folder->mkdirs, folderid, + pfs_task_walk_tree(folder->mkdirs, folderid, offsetof(psync_fstask_mkdir_t, folderid)), psync_fstask_mkdir_t, tree); } psync_fstask_creat_t * -psync_fstask_find_creat_by_fileid(psync_fstask_folder_t *folder, +pfs_task_find_creat_by_fileid(psync_fstask_folder_t *folder, psync_fsfileid_t fileid) { return ptree_element( - psync_fstask_walk_tree(folder->creats, fileid, + pfs_task_walk_tree(folder->creats, fileid, offsetof(psync_fstask_creat_t, fileid)), psync_fstask_creat_t, tree); } -static void psync_fstask_depend(uint64_t taskid, uint64_t dependontaskid) { +static void pfs_task_depend(uint64_t taskid, uint64_t dependontaskid) { psync_sql_res *res; res = psql_prepare("INSERT OR IGNORE INTO fstaskdepend " "(fstaskid, dependfstaskid) VALUES (?, ?)"); @@ -345,7 +345,7 @@ static void psync_fstask_depend(uint64_t taskid, uint64_t dependontaskid) { psql_run_free(res); } -static uint32_t psync_fstask_depend_on_name(uint64_t taskid, +static uint32_t pfs_task_depend_on_name(uint64_t taskid, psync_fsfolderid_t folderid, const char *name, size_t len) { psync_sql_res *res; @@ -361,7 +361,7 @@ static uint32_t psync_fstask_depend_on_name(uint64_t taskid, return psql_affected(); } -static uint32_t psync_fstask_depend_on_name2(uint64_t taskid, uint64_t taskid2, +static uint32_t pfs_task_depend_on_name2(uint64_t taskid, uint64_t taskid2, psync_fsfolderid_t folderid, const char *name, size_t len) { psync_sql_res *res; @@ -378,7 +378,7 @@ static uint32_t psync_fstask_depend_on_name2(uint64_t taskid, uint64_t taskid2, return psql_affected(); } -int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name, +int pfs_task_mkdir(psync_fsfolderid_t folderid, const char *name, uint32_t folderflags) { psync_sql_res *res; psync_uint_row row; @@ -389,7 +389,7 @@ int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name, size_t len, klen; time_t ctime; uint32_t depend; - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); len = strlen(name); if (folderid >= 0) { res = psql_query( @@ -398,14 +398,14 @@ int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name, psql_bind_lstr(res, 2, name, len); row = psql_fetch_int(res); psql_free(res); - if (row && !psync_fstask_find_rmdir(folder, name, 0)) { - psync_fstask_release_folder_tasks_locked(folder); + if (row && !pfs_task_find_rmdir(folder, name, 0)) { + pfs_task_release_folder_tasks_locked(folder); return -pdbg_return_const(EEXIST); } } - if ((task = psync_fstask_find_mkdir(folder, name, 0))) { + if ((task = pfs_task_find_mkdir(folder, name, 0))) { depend = task->flags; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (depend & PSYNC_FOLDER_FLAG_INVISIBLE) return -pdbg_return_const(EACCES); else @@ -416,8 +416,8 @@ int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name, key = pcryptofolder_filencoder_key_new(PSYNC_CRYPTO_SYM_FLAG_ISDIR, &klen); if (psync_crypto_is_error(key)) { - psync_fstask_release_folder_tasks_locked(folder); - return -psync_fs_crypto_err_to_errno(psync_crypto_to_error(key)); + pfs_task_release_folder_tasks_locked(folder); + return -pfs_crypto_err_to_errno(psync_crypto_to_error(key)); } } else key = NULL; @@ -436,13 +436,13 @@ int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name, psql_run_free(res); taskid = psql_insertid(); if (folderid < 0) { - psync_fstask_depend(taskid, -folderid); + pfs_task_depend(taskid, -folderid); depend = 1; } else depend = 0; - depend += psync_fstask_depend_on_name(taskid, folderid, name, len); + depend += pfs_task_depend_on_name(taskid, folderid, name, len); if (pdbg_unlikely(psql_commit())) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -EIO; } len++; @@ -454,18 +454,18 @@ int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name, task->subdircnt = 0; task->flags = folderflags & PSYNC_FOLDER_FLAG_ENCRYPTED; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->mkdirs, offsetof(psync_fstask_mkdir_t, name), &task->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (!depend) - psync_fsupload_wake(); + pfs_upld_wake(); if (folderid >= 0) ppathstatus_drive_fldr_changed(folderid); return 0; } -int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, +int pfs_task_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, const char *name) { psync_sql_res *res; psync_uint_row row; @@ -475,8 +475,8 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, psync_fsfolderid_t cfolderid; size_t len; len = strlen(name); - folder = psync_fstask_get_folder_tasks_locked(folderid); - if (folder && (mk = psync_fstask_find_mkdir(folder, name, 0))) + folder = pfs_task_get_folder_tasks_locked(folderid); + if (folder && (mk = pfs_task_find_mkdir(folder, name, 0))) cfolderid = mk->folderid; else { res = psql_query( @@ -484,9 +484,9 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, psql_bind_uint(res, 1, folderid); psql_bind_lstr(res, 2, name, len); row = psql_fetch_int(res); - if (!row || (folder && psync_fstask_find_rmdir(folder, name, 0))) { + if (!row || (folder && pfs_task_find_rmdir(folder, name, 0))) { psql_free(res); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -ENOENT; } cfolderid = row[0]; @@ -494,7 +494,7 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, !(parentflags & PSYNC_FOLDER_FLAG_ENCRYPTED)) { psql_free(res); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_WARNING, "attempt to delete encrypted folder %s in folderid %lu rejected", name, (unsigned long)folderid); @@ -502,11 +502,11 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, } psql_free(res); } - cfolder = psync_fstask_get_folder_tasks_locked(cfolderid); + cfolder = pfs_task_get_folder_tasks_locked(cfolderid); if (cfolder && (cfolder->creats || cfolder->mkdirs)) { - psync_fstask_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(cfolder); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name); return -ENOTEMPTY; } @@ -514,12 +514,12 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, res = psql_query("SELECT name FROM file WHERE parentfolderid=?"); psql_bind_uint(res, 1, cfolderid); while ((srow = psql_fetch_str(res))) - if (!cfolder || !psync_fstask_find_unlink(cfolder, srow[0], 0)) { + if (!cfolder || !pfs_task_find_unlink(cfolder, srow[0], 0)) { psql_free(res); if (cfolder) - psync_fstask_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(cfolder); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name); return -ENOTEMPTY; } @@ -527,25 +527,25 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, res = psql_query("SELECT name FROM folder WHERE parentfolderid=?"); psql_bind_uint(res, 1, cfolderid); while ((srow = psql_fetch_str(res))) - if (!cfolder || !psync_fstask_find_rmdir(cfolder, srow[0], 0)) { + if (!cfolder || !pfs_task_find_rmdir(cfolder, srow[0], 0)) { psql_free(res); if (cfolder) - psync_fstask_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(cfolder); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name); return -ENOTEMPTY; } psql_free(res); } if (cfolder) - psync_fstask_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(cfolder); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return 0; } -int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, +int pfs_task_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, const char *name) { psync_sql_res *res; psync_uint_row row; @@ -557,24 +557,24 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, psync_fsfolderid_t cfolderid; size_t len; len = strlen(name); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); - mk = psync_fstask_find_mkdir(folder, name, 0); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); + mk = pfs_task_find_mkdir(folder, name, 0); if (mk == NULL) { res = psql_query( "SELECT id, flags FROM folder WHERE parentfolderid=? AND name=?"); psql_bind_uint(res, 1, folderid); psql_bind_lstr(res, 2, name, len); row = psql_fetch_int(res); - if (!row || psync_fstask_find_rmdir(folder, name, 0)) { + if (!row || pfs_task_find_rmdir(folder, name, 0)) { psql_free(res); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -ENOENT; } cfolderid = row[0]; if ((row[1] & PSYNC_FOLDER_FLAG_ENCRYPTED) && !(parentflags & PSYNC_FOLDER_FLAG_ENCRYPTED)) { psql_free(res); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_WARNING, "attempt to delete encrypted folder %s in folderid %lu rejected", name, (unsigned long)folderid); @@ -587,10 +587,10 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, cfolderid = mk->folderid; folder->taskscnt--; } - cfolder = psync_fstask_get_folder_tasks_locked(cfolderid); + cfolder = pfs_task_get_folder_tasks_locked(cfolderid); if (cfolder && (cfolder->creats || cfolder->mkdirs)) { - psync_fstask_release_folder_tasks_locked(cfolder); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name); return -ENOTEMPTY; } @@ -598,11 +598,11 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, res = psql_query("SELECT name FROM file WHERE parentfolderid=?"); psql_bind_uint(res, 1, cfolderid); while ((srow = psql_fetch_str(res))) - if (!cfolder || !psync_fstask_find_unlink(cfolder, srow[0], 0)) { + if (!cfolder || !pfs_task_find_unlink(cfolder, srow[0], 0)) { psql_free(res); if (cfolder) - psync_fstask_release_folder_tasks_locked(cfolder); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name); return -ENOTEMPTY; } @@ -610,11 +610,11 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, res = psql_query("SELECT name FROM folder WHERE parentfolderid=?"); psql_bind_uint(res, 1, cfolderid); while ((srow = psql_fetch_str(res))) - if (!cfolder || !psync_fstask_find_rmdir(cfolder, srow[0], 0)) { + if (!cfolder || !pfs_task_find_rmdir(cfolder, srow[0], 0)) { psql_free(res); if (cfolder) - psync_fstask_release_folder_tasks_locked(cfolder); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(folder); pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name); return -ENOTEMPTY; } @@ -625,7 +625,7 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, free(mk); } if (cfolder) - psync_fstask_release_folder_tasks_locked(cfolder); + pfs_task_release_folder_tasks_locked(cfolder); psql_start(); res = psql_prepare( "INSERT INTO fstask (type, status, folderid, sfolderid, text1) VALUES " @@ -636,17 +636,17 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, psql_run_free(res); taskid = psql_insertid(); if (depend) - psync_fstask_depend(taskid, depend); + pfs_task_depend(taskid, depend); res = psql_query("SELECT id FROM fstask WHERE folderid=?"); psql_bind_int(res, 1, cfolderid); while ((row = psql_fetch_int(res))) { - psync_fstask_depend(taskid, row[0]); + pfs_task_depend(taskid, row[0]); depend++; } psql_free(res); - psync_fstask_depend_on_name(taskid, folderid, name, len); + pfs_task_depend_on_name(taskid, folderid, name, len); if (pdbg_unlikely(psql_commit())) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -EIO; } len++; @@ -655,16 +655,16 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, task->taskid = taskid; task->folderid = cfolderid; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &task->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (depend == 0) - psync_fsupload_wake(); + pfs_upld_wake(); return 0; } -psync_fstask_creat_t *psync_fstask_add_creat(psync_fstask_folder_t *folder, +psync_fstask_creat_t *pfs_task_add_creat(psync_fstask_folder_t *folder, const char *name, psync_fsfileid_t fileid, const char *encsymkey, @@ -692,8 +692,8 @@ psync_fstask_creat_t *psync_fstask_add_creat(psync_fstask_folder_t *folder, psql_run_free(res); taskid = psql_insertid(); if (folder->folderid < 0) - psync_fstask_depend(taskid, -folder->folderid); - psync_fstask_depend_on_name(taskid, folder->folderid, name, len); + pfs_task_depend(taskid, -folder->folderid); + pfs_task_depend_on_name(taskid, folder->folderid, name, len); if (pdbg_unlikely(psql_commit())) return NULL; len++; @@ -702,7 +702,7 @@ psync_fstask_creat_t *psync_fstask_add_creat(psync_fstask_folder_t *folder, un->fileid = -(psync_fsfileid_t)taskid; un->taskid = taskid; memcpy(un->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &un->tree); task = (psync_fstask_creat_t *)malloc( offsetof(psync_fstask_creat_t, name) + len); @@ -710,7 +710,7 @@ psync_fstask_creat_t *psync_fstask_add_creat(psync_fstask_folder_t *folder, task->rfileid = fileid; task->taskid = taskid; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &task->tree); folder->taskscnt += 2; if (folder->folderid >= 0) @@ -718,22 +718,22 @@ psync_fstask_creat_t *psync_fstask_add_creat(psync_fstask_folder_t *folder, return task; } -void psync_fstask_inject_creat(psync_fstask_folder_t *folder, +void pfs_task_inject_creat(psync_fstask_folder_t *folder, psync_fstask_creat_t *cr) { - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &cr->tree); folder->taskscnt++; } -void psync_fstask_inject_unlink(psync_fstask_folder_t *folder, +void pfs_task_inject_unlink(psync_fstask_folder_t *folder, psync_fstask_unlink_t *un) { - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_creat_t, name), &un->tree); folder->taskscnt++; } psync_fstask_creat_t * -psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name, +pfs_task_add_modified_file(psync_fstask_folder_t *folder, const char *name, psync_fsfileid_t fileid, uint64_t hash, const char *encsymkey, size_t encsymkeylen) { psync_sql_res *res; @@ -760,11 +760,11 @@ psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name, psql_run_free(res); taskid = psql_insertid(); if (folder->folderid < 0) - psync_fstask_depend(taskid, -folder->folderid); - psync_fstask_depend_on_name(taskid, folder->folderid, name, len); - task = psync_fstask_find_creat(folder, name, 0); + pfs_task_depend(taskid, -folder->folderid); + pfs_task_depend_on_name(taskid, folder->folderid, name, len); + task = pfs_task_find_creat(folder, name, 0); if (task) { - psync_fstask_depend(taskid, task->taskid); + pfs_task_depend(taskid, task->taskid); ptree_del(&folder->creats, &task->tree); free(task); folder->taskscnt--; @@ -777,7 +777,7 @@ psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name, un->fileid = fileid; un->taskid = taskid; memcpy(un->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &un->tree); task = (psync_fstask_creat_t *)malloc( offsetof(psync_fstask_creat_t, name) + len); @@ -785,7 +785,7 @@ psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name, task->rfileid = fileid; task->taskid = taskid; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &task->tree); if (folder->folderid >= 0) ppathstatus_drive_fldr_changed(folder->folderid); @@ -793,7 +793,7 @@ psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name, return task; } -int psync_fstask_set_mtime(psync_fileid_t fileid, uint64_t oldtm, +int pfs_task_set_mtime(psync_fileid_t fileid, uint64_t oldtm, uint64_t newtm, int is_ctime) { psync_sql_res *res; psql_start(); @@ -817,11 +817,11 @@ int psync_fstask_set_mtime(psync_fileid_t fileid, uint64_t oldtm, psql_run_free(res); if (pdbg_unlikely(psql_commit())) return -EIO; - psync_fsupload_wake(); + pfs_upld_wake(); return 0; } -int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid, +int pfs_task_add_local_creat_static(psync_fsfolderid_t folderid, const char *name, const void *data, size_t datalen) { psync_fstask_folder_t *folder; @@ -835,15 +835,15 @@ int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid, ret = -1; len = strlen(name); psql_lock(); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); - cr = psync_fstask_find_creat(folder, name, 0); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); + cr = pfs_task_find_creat(folder, name, 0); if (cr) { pdbg_logf(D_NOTICE, "not adding file %s to folderid %ld as creat already exists", name, (long)folderid); goto ex; } - if (folderid >= 0 && !psync_fstask_find_unlink(folder, name, 0)) { + if (folderid >= 0 && !pfs_task_find_unlink(folder, name, 0)) { res = psql_query( "SELECT id FROM file WHERE parentfolderid=? AND name=?"); psql_bind_uint(res, 1, folderid); @@ -866,9 +866,9 @@ int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid, un->taskid = psync_local_taskid; un->fileid = 0; memcpy(un->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &un->tree); - addlen = psync_fstask_creat_local_offset(len - 1); + addlen = pfs_task_creat_local_offset(len - 1); cr = (psync_fstask_creat_t *)malloc(addlen + sizeof(psync_fstask_local_creat_t)); cr->fileid = 0; @@ -879,13 +879,13 @@ int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid, lc->data = data; lc->datalen = datalen; lc->ctime = ptimer_time(); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &cr->tree); psync_local_taskid--; folder->taskscnt += 2; ret = 0; ex: - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); return ret; } @@ -904,20 +904,20 @@ static psync_fsfileid_t get_file_at_old_location(psync_fsfileid_t fileid) { rec = (file_history_record *)pcache_get(key); if (!rec) return 0; - folder = psync_fstask_get_folder_tasks_locked(rec->folderid); + folder = pfs_task_get_folder_tasks_locked(rec->folderid); if (folder) { - cr = psync_fstask_find_creat(folder, rec->name, 0); + cr = pfs_task_find_creat(folder, rec->name, 0); if (cr) { free(rec); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return cr->fileid; } - if (psync_fstask_find_unlink(folder, rec->name, 0)) { + if (pfs_task_find_unlink(folder, rec->name, 0)) { free(rec); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return 0; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } res = psql_query("SELECT id FROM file WHERE parentfolderid=? AND name=?"); @@ -932,14 +932,14 @@ static psync_fsfileid_t get_file_at_old_location(psync_fsfileid_t fileid) { return ret; } -void psync_fstask_stop_and_delete_file(psync_fsfileid_t fileid) { +void pfs_task_stop_and_delete_file(psync_fsfileid_t fileid) { psync_sql_res *res; pdbg_logf(D_NOTICE, "trying to stop upload of task %lu", (unsigned long)-fileid); - if (psync_fsupload_in_current_small_uploads_batch_locked(-fileid)) { + if (pfs_upld_in_current_small_uploads_batch_locked(-fileid)) { pdbg_logf(D_NOTICE, "file is in current small uploads batch"); return; } - psync_fsupload_stop_upload_locked(-fileid); + pfs_upld_stop_upload_locked(-fileid); res = psql_prepare("UPDATE fstask SET status=11 WHERE id=?"); psql_bind_uint(res, 1, -fileid); psql_run_free(res); @@ -947,38 +947,38 @@ void psync_fstask_stop_and_delete_file(psync_fsfileid_t fileid) { "UPDATE fstask SET status=11 WHERE fileid=? AND status!=10"); psql_bind_int(res, 1, fileid); psql_run_free(res); - psync_fs_mark_openfile_deleted(-fileid); + pfs_mark_openfile_deleted(-fileid); } -int psync_fstask_can_unlink(psync_fsfolderid_t folderid, const char *name) { +int pfs_task_can_unlink(psync_fsfolderid_t folderid, const char *name) { psync_sql_res *res; psync_uint_row row; psync_fstask_folder_t *folder; size_t len; len = strlen(name); - folder = psync_fstask_get_folder_tasks_locked(folderid); - if (folder && psync_fstask_find_creat(folder, name, 0)) - psync_fstask_release_folder_tasks_locked(folder); + folder = pfs_task_get_folder_tasks_locked(folderid); + if (folder && pfs_task_find_creat(folder, name, 0)) + pfs_task_release_folder_tasks_locked(folder); else { res = psql_query( "SELECT id FROM file WHERE parentfolderid=? AND name=?"); psql_bind_uint(res, 1, folderid); psql_bind_lstr(res, 2, name, len); row = psql_fetch_int(res); - if (!row || (folder && psync_fstask_find_unlink(folder, name, 0))) { + if (!row || (folder && pfs_task_find_unlink(folder, name, 0))) { psql_free(res); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -ENOENT; } psql_free(res); if (folder) - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } return 0; } -int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) { +int pfs_task_unlink(psync_fsfolderid_t folderid, const char *name) { psync_sql_res *res; psync_uint_row row; psync_fstask_folder_t *folder; @@ -989,17 +989,17 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) { psync_fileid_t rfileid; size_t len; len = strlen(name); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); - cr = psync_fstask_find_creat(folder, name, 0); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); + cr = pfs_task_find_creat(folder, name, 0); if (cr == NULL) { res = psql_query( "SELECT id FROM file WHERE parentfolderid=? AND name=?"); psql_bind_uint(res, 1, folderid); psql_bind_lstr(res, 2, name, len); row = psql_fetch_int(res); - if (!row || psync_fstask_find_unlink(folder, name, 0)) { + if (!row || pfs_task_find_unlink(folder, name, 0)) { psql_free(res); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -ENOENT; } fileid = row[0]; @@ -1009,7 +1009,7 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) { } else { rfileid = cr->rfileid; if (unlikely(cr->fileid == 0)) { - task = psync_fstask_find_unlink(folder, cr->name, cr->taskid); + task = pfs_task_find_unlink(folder, cr->name, cr->taskid); if (pdbg_likely(task)) { ptree_del(&folder->unlinks, &task->tree); folder->taskscnt--; @@ -1018,7 +1018,7 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) { ptree_del(&folder->creats, &cr->tree); free(cr); folder->taskscnt--; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return 0; } depend = cr->taskid; @@ -1032,7 +1032,7 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) { revoffileid = get_file_at_old_location(fileid); psql_start(); if (fileid < 0) - psync_fstask_stop_and_delete_file(fileid); + pfs_task_stop_and_delete_file(fileid); if (revoffileid) { res = psql_prepare( "INSERT INTO fstask (type, status, folderid, fileid, int1, text1, " @@ -1057,14 +1057,14 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) { } taskid = psql_insertid(); if (depend) - psync_fstask_depend(taskid, depend); + pfs_task_depend(taskid, depend); if (revoffileid < 0) - psync_fstask_depend(taskid, -revoffileid); + pfs_task_depend(taskid, -revoffileid); if (fileid < 0 && -fileid != depend) - psync_fstask_depend(taskid, -fileid); - psync_fstask_depend_on_name(taskid, folderid, name, len); + pfs_task_depend(taskid, -fileid); + pfs_task_depend_on_name(taskid, folderid, name, len); if (pdbg_unlikely(psql_commit())) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -EIO; } len++; @@ -1073,12 +1073,12 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) { task->taskid = taskid; task->fileid = fileid; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &task->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (depend == 0 || fileid < 0) - psync_fsupload_wake(); + pfs_upld_wake(); return 0; } @@ -1098,7 +1098,7 @@ static void add_history_record(psync_fileid_t fileid, psync_folderid_t folderid, pcache_add(key, rec, PSYNC_FS_FILE_LOC_HIST_SEC, free, 1); } -int psync_fstask_rename_file(psync_fsfileid_t fileid, +int pfs_task_rename_file(psync_fsfileid_t fileid, psync_fsfolderid_t parentfolderid, const char *name, psync_fsfolderid_t to_folderid, const char *new_name) { @@ -1116,8 +1116,8 @@ int psync_fstask_rename_file(psync_fsfileid_t fileid, new_name = name; nnlen = nlen; } - folder = psync_fstask_get_or_create_folder_tasks_locked(parentfolderid); - cr = psync_fstask_find_creat(folder, name, 0); + folder = pfs_task_get_or_create_folder_tasks_locked(parentfolderid); + cr = pfs_task_find_creat(folder, name, 0); if (cr) rfileid = cr->rfileid; else @@ -1148,18 +1148,18 @@ int psync_fstask_rename_file(psync_fsfileid_t fileid, psql_bind_int(res, 1, to_folderid); psql_bind_uint(res, 2, -fileid); psql_run_free(res); - psync_fstask_depend(ttaskid, -fileid); + pfs_task_depend(ttaskid, -fileid); } if (parentfolderid < 0) - psync_fstask_depend(ttaskid, -parentfolderid); + pfs_task_depend(ttaskid, -parentfolderid); if (to_folderid < 0 && to_folderid != parentfolderid) - psync_fstask_depend(ttaskid, -to_folderid); - psync_fstask_depend_on_name2(ttaskid, ftaskid, parentfolderid, name, nlen); - psync_fstask_depend_on_name(ttaskid, to_folderid, new_name, nnlen); + pfs_task_depend(ttaskid, -to_folderid); + pfs_task_depend_on_name2(ttaskid, ftaskid, parentfolderid, name, nlen); + pfs_task_depend_on_name(ttaskid, to_folderid, new_name, nnlen); if (cr) - psync_fstask_depend(ttaskid, cr->taskid); + pfs_task_depend(ttaskid, cr->taskid); if (pdbg_unlikely(psql_commit())) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -EIO; } if (cr) { @@ -1169,26 +1169,26 @@ int psync_fstask_rename_file(psync_fsfileid_t fileid, if (folder->folderid >= 0) ppathstatus_drive_fldr_changed(folder->folderid); } - psync_fs_rename_openfile_locked(fileid, to_folderid, new_name); + pfs_rename_openfile_locked(fileid, to_folderid, new_name); nlen++; rm = (psync_fstask_unlink_t *)malloc( offsetof(psync_fstask_unlink_t, name) + nlen); rm->taskid = ftaskid; rm->fileid = fileid; memcpy(rm->name, name, nlen); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &rm->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); - folder = psync_fstask_get_or_create_folder_tasks_locked(to_folderid); + folder = pfs_task_get_or_create_folder_tasks_locked(to_folderid); nnlen++; - cr = psync_fstask_find_creat(folder, new_name, 0); + cr = pfs_task_find_creat(folder, new_name, 0); if (cr) { pdbg_logf(D_NOTICE, "renaming over creat of file %s(%ld) in folder %lu", new_name, (long)cr->fileid, (unsigned long)to_folderid); if (cr->fileid < 0) - psync_fstask_stop_and_delete_file(cr->fileid); + pfs_task_stop_and_delete_file(cr->fileid); ptree_del(&folder->creats, &cr->tree); free(cr); folder->taskscnt--; @@ -1198,7 +1198,7 @@ int psync_fstask_rename_file(psync_fsfileid_t fileid, rm->fileid = fileid; rm->taskid = ttaskid; memcpy(rm->name, new_name, nnlen); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &rm->tree); cr = (psync_fstask_creat_t *)malloc( offsetof(psync_fstask_creat_t, name) + nnlen); @@ -1206,11 +1206,11 @@ int psync_fstask_rename_file(psync_fsfileid_t fileid, cr->rfileid = rfileid; cr->taskid = ttaskid; memcpy(cr->name, new_name, nnlen); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &cr->tree); folder->taskscnt += 2; - psync_fstask_release_folder_tasks_locked(folder); - psync_fsupload_wake(); + pfs_task_release_folder_tasks_locked(folder); + pfs_upld_wake(); if (fileid > 0 && parentfolderid >= 0) add_history_record(fileid, parentfolderid, name); else if (rfileid > 0 && parentfolderid >= 0) @@ -1245,7 +1245,7 @@ static void fill_mkdir_data(psync_fsfolderid_t folderid, } } -static uint64_t psync_fstask_delete_folder_if_ex(psync_fsfolderid_t folderid, +static uint64_t pfs_task_delete_folder_if_ex(psync_fsfolderid_t folderid, const char *name, psync_fsfolderid_t from_fid) { psync_sql_res *res; @@ -1258,17 +1258,17 @@ static uint64_t psync_fstask_delete_folder_if_ex(psync_fsfolderid_t folderid, cfolderid = 0; depend = 0; - folder = psync_fstask_get_folder_tasks_locked(folderid); + folder = pfs_task_get_folder_tasks_locked(folderid); if (folder) { - if ((mk = psync_fstask_find_mkdir(folder, name, 0))) { + if ((mk = pfs_task_find_mkdir(folder, name, 0))) { cfolderid = mk->folderid; depend = mk->taskid; - } else if (psync_fstask_find_rmdir(folder, name, 0)) { - psync_fstask_release_folder_tasks_locked(folder); + } else if (pfs_task_find_rmdir(folder, name, 0)) { + pfs_task_release_folder_tasks_locked(folder); return 0; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } len = strlen(name); @@ -1306,15 +1306,15 @@ static uint64_t psync_fstask_delete_folder_if_ex(psync_fsfolderid_t folderid, taskid = psql_insertid(); if (depend) - psync_fstask_depend(taskid, depend); + pfs_task_depend(taskid, depend); if (cfolderid < 0) - psync_fstask_depend(taskid, -cfolderid); + pfs_task_depend(taskid, -cfolderid); return taskid; } -int psync_fstask_rename_folder(psync_fsfolderid_t folderid, +int pfs_task_rename_folder(psync_fsfolderid_t folderid, psync_fsfolderid_t parentfolderid, const char *name, psync_fsfolderid_t to_folderid, const char *new_name, uint32_t targetflags) { @@ -1335,7 +1335,7 @@ int psync_fstask_rename_folder(psync_fsfolderid_t folderid, psql_start(); - rmtask = psync_fstask_delete_folder_if_ex(to_folderid, new_name, folderid); + rmtask = pfs_task_delete_folder_if_ex(to_folderid, new_name, folderid); res = psql_prepare( "INSERT INTO fstask (type, status, folderid, sfolderid, text1) VALUES " "(" NTO_STR(PSYNC_FS_TASK_RENFOLDER_FROM) ", 10, ?, ?, ?)"); @@ -1362,28 +1362,28 @@ int psync_fstask_rename_folder(psync_fsfolderid_t folderid, psql_bind_int(res, 1, to_folderid); psql_bind_int(res, 2, -folderid); psql_run_free(res); - psync_fstask_depend(ttaskid, -folderid); + pfs_task_depend(ttaskid, -folderid); } if (rmtask) - psync_fstask_depend(ttaskid, rmtask); + pfs_task_depend(ttaskid, rmtask); if (parentfolderid < 0) - psync_fstask_depend(ttaskid, -parentfolderid); + pfs_task_depend(ttaskid, -parentfolderid); if (to_folderid < 0 && to_folderid != parentfolderid) - psync_fstask_depend(ttaskid, -to_folderid); + pfs_task_depend(ttaskid, -to_folderid); - psync_fstask_depend_on_name2(ttaskid, ftaskid, parentfolderid, name, nlen); - psync_fstask_depend_on_name(ttaskid, folderid, new_name, nnlen); - folder = psync_fstask_get_or_create_folder_tasks_locked(parentfolderid); - mk = psync_fstask_find_mkdir(folder, name, 0); + pfs_task_depend_on_name2(ttaskid, ftaskid, parentfolderid, name, nlen); + pfs_task_depend_on_name(ttaskid, folderid, new_name, nnlen); + folder = pfs_task_get_or_create_folder_tasks_locked(parentfolderid); + mk = pfs_task_find_mkdir(folder, name, 0); if (mk) - psync_fstask_depend(ttaskid, mk->taskid); + pfs_task_depend(ttaskid, mk->taskid); if (pdbg_unlikely(psql_commit())) { - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); return -EIO; } @@ -1400,13 +1400,13 @@ int psync_fstask_rename_folder(psync_fsfolderid_t folderid, rm->folderid = folderid; memcpy(rm->name, name, nlen); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &rm->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); - folder = psync_fstask_get_or_create_folder_tasks_locked(to_folderid); - mk = psync_fstask_find_mkdir(folder, name, 0); + pfs_task_release_folder_tasks_locked(folder); + folder = pfs_task_get_or_create_folder_tasks_locked(to_folderid); + mk = pfs_task_find_mkdir(folder, name, 0); if (mk) { pdbg_logf(D_NOTICE, "renaming over mkdir %s", name); @@ -1421,7 +1421,7 @@ int psync_fstask_rename_folder(psync_fsfolderid_t folderid, rm->taskid = ttaskid; rm->folderid = folderid; memcpy(rm->name, new_name, nnlen); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &rm->tree); mk = (psync_fstask_mkdir_t *)malloc( @@ -1432,11 +1432,11 @@ int psync_fstask_rename_folder(psync_fsfolderid_t folderid, memcpy(mk->name, new_name, nnlen); fill_mkdir_data(folderid, mk); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->mkdirs, offsetof(psync_fstask_mkdir_t, name), &mk->tree); folder->taskscnt += 2; - psync_fstask_release_folder_tasks_locked(folder); - psync_fsupload_wake(); + pfs_task_release_folder_tasks_locked(folder); + pfs_upld_wake(); if (to_folderid >= 0) { ppathstatus_drive_fldr_changed(to_folderid); @@ -1456,23 +1456,23 @@ static int folder_cmp(const psync_tree *t1, const psync_tree *t2) { return 0; } -void psync_fstask_folder_created(psync_folderid_t parentfolderid, +void pfs_task_folder_created(psync_folderid_t parentfolderid, uint64_t taskid, psync_folderid_t folderid, const char *name) { psync_fstask_folder_t *folder; psync_fstask_mkdir_t *mk; int pchg; pchg = 0; - folder = psync_fstask_get_folder_tasks_locked(parentfolderid); + folder = pfs_task_get_folder_tasks_locked(parentfolderid); if (folder) { - mk = psync_fstask_find_mkdir(folder, name, taskid); + mk = pfs_task_find_mkdir(folder, name, taskid); if (mk) { ptree_del(&folder->mkdirs, &mk->tree); free(mk); folder->taskscnt--; pchg = 1; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } if (!folder || !mk) { psync_sql_res *res; @@ -1490,50 +1490,50 @@ void psync_fstask_folder_created(psync_folderid_t parentfolderid, else { sfolderid = row[0]; psql_free(res); - folder = psync_fstask_get_folder_tasks_locked(sfolderid); + folder = pfs_task_get_folder_tasks_locked(sfolderid); if (folder) { - mk = psync_fstask_find_mkdir_by_folderid(folder, + mk = pfs_task_find_mkdir_by_folderid(folder, -(psync_fsfolderid_t)taskid); if (mk) { pdbg_logf(D_NOTICE, "found taskid %lu in folderid %ld as %s", (unsigned long)taskid, (long)sfolderid, mk->name); mk->folderid = folderid; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } } } - folder = psync_fstask_get_folder_tasks_locked(-(psync_fsfolderid_t)taskid); + folder = pfs_task_get_folder_tasks_locked(-(psync_fsfolderid_t)taskid); if (folder) { pdbg_logf(D_NOTICE, "re-inserting into tree folder diffs of folder %ld as %lu", (long)folder->folderid, (unsigned long)folderid); ptree_del(&folders, &folder->tree); folder->folderid = folderid; ptree_add(&folders, &folder->tree, folder_cmp); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); ppathstatus_drive_fldr_changed(folderid); } if (pchg) ppathstatus_drive_fldr_changed(parentfolderid); } -void psync_fstask_folder_deleted(psync_folderid_t parentfolderid, +void pfs_task_folder_deleted(psync_folderid_t parentfolderid, uint64_t taskid, const char *name) { psync_fstask_folder_t *folder; psync_fstask_rmdir_t *rm; - folder = psync_fstask_get_folder_tasks_locked(parentfolderid); + folder = pfs_task_get_folder_tasks_locked(parentfolderid); if (folder) { - rm = psync_fstask_find_rmdir(folder, name, taskid); + rm = pfs_task_find_rmdir(folder, name, taskid); if (rm) { ptree_del(&folder->rmdirs, &rm->tree); free(rm); folder->taskscnt--; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } } -static void psync_fstask_look_for_creat_in_db(psync_folderid_t parentfolderid, +static void pfs_task_look_for_creat_in_db(psync_folderid_t parentfolderid, uint64_t taskid, const char *name, psync_fileid_t fileid) { psync_fstask_folder_t *folder; @@ -1553,9 +1553,9 @@ static void psync_fstask_look_for_creat_in_db(psync_folderid_t parentfolderid, } sfolderid = row[0]; psql_free(res); - folder = psync_fstask_get_folder_tasks_locked(sfolderid); + folder = pfs_task_get_folder_tasks_locked(sfolderid); if (folder) { - cr = psync_fstask_find_creat_by_fileid(folder, -(psync_fsfileid_t)taskid); + cr = pfs_task_find_creat_by_fileid(folder, -(psync_fsfileid_t)taskid); if (cr) { pdbg_logf(D_NOTICE, "found taskid %lu in folderid %ld as %s", (unsigned long)taskid, (long)sfolderid, cr->name); @@ -1565,24 +1565,24 @@ static void psync_fstask_look_for_creat_in_db(psync_folderid_t parentfolderid, "could not find creat (taskid %lu) for uploaded file %s in folder " "%lu even after looking in db", (unsigned long)taskid, name, (unsigned long)parentfolderid); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } } -void psync_fstask_file_created(psync_folderid_t parentfolderid, uint64_t taskid, +void pfs_task_file_created(psync_folderid_t parentfolderid, uint64_t taskid, const char *name, psync_fileid_t fileid) { psync_fstask_folder_t *folder; psync_fstask_creat_t *cr; psync_fstask_unlink_t *un; - folder = psync_fstask_get_folder_tasks_locked(parentfolderid); + folder = pfs_task_get_folder_tasks_locked(parentfolderid); if (folder) { - cr = psync_fstask_find_creat(folder, name, taskid); + cr = pfs_task_find_creat(folder, name, taskid); if (cr) { ptree_del(&folder->creats, &cr->tree); free(cr); folder->taskscnt--; } - un = psync_fstask_find_unlink(folder, name, taskid); + un = pfs_task_find_unlink(folder, name, taskid); if (un) { ptree_del(&folder->unlinks, &un->tree); free(un); @@ -1590,98 +1590,98 @@ void psync_fstask_file_created(psync_folderid_t parentfolderid, uint64_t taskid, } else pdbg_logf(D_NOTICE, "could not find unlink for file %s in folderid %lu", name, (unsigned long)parentfolderid); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (cr) ppathstatus_drive_fldr_changed(parentfolderid); } else pdbg_logf(D_NOTICE, "could not find unlink for file %s in folderid %lu", name, (unsigned long)parentfolderid); if (!folder || !cr) - psync_fstask_look_for_creat_in_db(parentfolderid, taskid, name, fileid); + pfs_task_look_for_creat_in_db(parentfolderid, taskid, name, fileid); } -void psync_fstask_file_modified(psync_folderid_t parentfolderid, +void pfs_task_file_modified(psync_folderid_t parentfolderid, uint64_t taskid, const char *name, psync_fileid_t fileid) { psync_fstask_folder_t *folder; psync_fstask_creat_t *cr; psync_fstask_unlink_t *un; - folder = psync_fstask_get_folder_tasks_locked(parentfolderid); + folder = pfs_task_get_folder_tasks_locked(parentfolderid); if (folder) { - cr = psync_fstask_find_creat(folder, name, taskid); + cr = pfs_task_find_creat(folder, name, taskid); if (cr) { ptree_del(&folder->creats, &cr->tree); free(cr); folder->taskscnt--; } - un = psync_fstask_find_unlink(folder, name, taskid); + un = pfs_task_find_unlink(folder, name, taskid); if (un) { ptree_del(&folder->unlinks, &un->tree); free(un); folder->taskscnt--; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (cr) ppathstatus_drive_fldr_changed(parentfolderid); } if (!folder || !cr) - psync_fstask_look_for_creat_in_db(parentfolderid, taskid, name, fileid); + pfs_task_look_for_creat_in_db(parentfolderid, taskid, name, fileid); } -void psync_fstask_file_deleted(psync_folderid_t parentfolderid, uint64_t taskid, +void pfs_task_file_deleted(psync_folderid_t parentfolderid, uint64_t taskid, const char *name) { psync_fstask_folder_t *folder; psync_fstask_unlink_t *un; - folder = psync_fstask_get_folder_tasks_locked(parentfolderid); + folder = pfs_task_get_folder_tasks_locked(parentfolderid); if (folder) { - un = psync_fstask_find_unlink(folder, name, taskid); + un = pfs_task_find_unlink(folder, name, taskid); if (un) { ptree_del(&folder->unlinks, &un->tree); free(un); folder->taskscnt--; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } } -void psync_fstask_file_renamed(psync_folderid_t folderid, uint64_t taskid, +void pfs_task_file_renamed(psync_folderid_t folderid, uint64_t taskid, const char *name, uint64_t frtaskid) { psync_sql_res *res; psync_fstask_folder_t *folder; psync_fstask_unlink_t *un; psync_fstask_creat_t *cr; psync_variant_row row; - folder = psync_fstask_get_folder_tasks_locked(folderid); + folder = pfs_task_get_folder_tasks_locked(folderid); if (folder) { - un = psync_fstask_find_unlink(folder, name, taskid); + un = pfs_task_find_unlink(folder, name, taskid); if (un) { ptree_del(&folder->unlinks, &un->tree); free(un); folder->taskscnt--; } - cr = psync_fstask_find_creat(folder, name, taskid); + cr = pfs_task_find_creat(folder, name, taskid); if (cr) { ptree_del(&folder->creats, &cr->tree); free(cr); folder->taskscnt--; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (cr) ppathstatus_drive_fldr_changed(folderid); } res = psql_query("SELECT id, folderid, text1 FROM fstask WHERE id=?"); psql_bind_uint(res, 1, frtaskid); if (pdbg_likely(row = psql_fetch(res))) { - folder = psync_fstask_get_folder_tasks_locked(psync_get_snumber(row[1])); + folder = pfs_task_get_folder_tasks_locked(psync_get_snumber(row[1])); if (folder) { - un = psync_fstask_find_unlink(folder, psync_get_string(row[2]), + un = pfs_task_find_unlink(folder, psync_get_string(row[2]), psync_get_number(row[0])); if (un) { ptree_del(&folder->unlinks, &un->tree); free(un); folder->taskscnt--; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } } psql_free(res); @@ -1690,13 +1690,13 @@ void psync_fstask_file_renamed(psync_folderid_t folderid, uint64_t taskid, psql_bind_uint(res, 1, frtaskid); psql_run_free(res); if (psql_affected()) - psync_fsupload_wake(); + pfs_upld_wake(); res = psql_prepare("DELETE FROM fstask WHERE id=?"); psql_bind_uint(res, 1, frtaskid); psql_run_free(res); } -void psync_fstask_folder_renamed(psync_folderid_t parentfolderid, +void pfs_task_folder_renamed(psync_folderid_t parentfolderid, uint64_t taskid, const char *name, uint64_t frtaskid) { psync_sql_res *res; @@ -1704,37 +1704,37 @@ void psync_fstask_folder_renamed(psync_folderid_t parentfolderid, psync_fstask_rmdir_t *rm; psync_fstask_mkdir_t *mk; psync_variant_row row; - folder = psync_fstask_get_folder_tasks_locked(parentfolderid); + folder = pfs_task_get_folder_tasks_locked(parentfolderid); if (folder) { - mk = psync_fstask_find_mkdir(folder, name, taskid); + mk = pfs_task_find_mkdir(folder, name, taskid); if (mk) { ptree_del(&folder->mkdirs, &mk->tree); free(mk); folder->taskscnt--; } - rm = psync_fstask_find_rmdir(folder, name, taskid); + rm = pfs_task_find_rmdir(folder, name, taskid); if (rm) { ptree_del(&folder->rmdirs, &rm->tree); free(rm); folder->taskscnt--; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (mk) ppathstatus_drive_fldr_changed(parentfolderid); } res = psql_query("SELECT id, folderid, text1 FROM fstask WHERE id=?"); psql_bind_uint(res, 1, frtaskid); if (pdbg_likely(row = psql_fetch(res))) { - folder = psync_fstask_get_folder_tasks_locked(psync_get_snumber(row[1])); + folder = pfs_task_get_folder_tasks_locked(psync_get_snumber(row[1])); if (folder) { - rm = psync_fstask_find_rmdir(folder, psync_get_string(row[2]), + rm = pfs_task_find_rmdir(folder, psync_get_string(row[2]), psync_get_number(row[0])); if (rm) { ptree_del(&folder->rmdirs, &rm->tree); free(rm); folder->taskscnt--; } - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } } psql_free(res); @@ -1743,7 +1743,7 @@ void psync_fstask_folder_renamed(psync_folderid_t parentfolderid, psql_bind_uint(res, 1, frtaskid); psql_run_free(res); if (psql_affected()) - psync_fsupload_wake(); + pfs_upld_wake(); res = psql_prepare("DELETE FROM fstask WHERE id=?"); psql_bind_uint(res, 1, frtaskid); psql_run_free(res); @@ -1761,7 +1761,7 @@ static void psync_init_task_mkdir(psync_variant_row row) { folderid = psync_get_snumber(row[2]); name = psync_get_lstring(row[4], &len); ctime = psync_get_number(row[6]); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); len++; task = (psync_fstask_mkdir_t *)malloc( offsetof(psync_fstask_mkdir_t, name) + len); @@ -1771,10 +1771,10 @@ static void psync_init_task_mkdir(psync_variant_row row) { task->subdircnt = 0; task->flags = psync_is_null(row[5]) ? 0 : PSYNC_FOLDER_FLAG_ENCRYPTED; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->mkdirs, offsetof(psync_fstask_mkdir_t, name), &task->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (folderid >= 0) ppathstatus_drive_fldr_changed(folderid); } @@ -1791,8 +1791,8 @@ static void psync_init_task_rmdir(psync_variant_row row) { folderid = psync_get_snumber(row[2]); name = psync_get_lstring(row[4], &len); cfolderid = psync_get_snumber(row[8]); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); - mk = psync_fstask_find_mkdir(folder, name, 0); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); + mk = pfs_task_find_mkdir(folder, name, 0); if (mk) { ptree_del(&folder->mkdirs, &mk->tree); free(mk); @@ -1804,10 +1804,10 @@ static void psync_init_task_rmdir(psync_variant_row row) { task->taskid = taskid; task->folderid = cfolderid; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &task->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } static void psync_init_task_creat(psync_variant_row row) { @@ -1821,14 +1821,14 @@ static void psync_init_task_creat(psync_variant_row row) { taskid = psync_get_number(row[0]); folderid = psync_get_snumber(row[2]); name = psync_get_lstring(row[4], &len); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); len++; un = (psync_fstask_unlink_t *)malloc( offsetof(psync_fstask_unlink_t, name) + len); un->fileid = -(psync_fsfileid_t)taskid; un->taskid = taskid; memcpy(un->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &un->tree); task = (psync_fstask_creat_t *)malloc( offsetof(psync_fstask_creat_t, name) + len); @@ -1836,10 +1836,10 @@ static void psync_init_task_creat(psync_variant_row row) { task->rfileid = psync_get_number(row[3]); task->taskid = taskid; memcpy(task->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &task->tree); folder->taskscnt += 2; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (folderid >= 0) ppathstatus_drive_fldr_changed(folderid); } @@ -1851,8 +1851,8 @@ static void psync_init_do_task_unlink(uint64_t taskid, psync_fstask_folder_t *folder; psync_fstask_unlink_t *task; psync_fstask_creat_t *cr; - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); - cr = psync_fstask_find_creat(folder, name, 0); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); + cr = pfs_task_find_creat(folder, name, 0); if (cr) { ptree_del(&folder->creats, &cr->tree); free(cr); @@ -1864,10 +1864,10 @@ static void psync_init_do_task_unlink(uint64_t taskid, task->taskid = taskid; task->fileid = fileid; memcpy(task->name, name, namelen); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &task->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } static void psync_init_task_unlink(psync_variant_row row) { @@ -1894,8 +1894,8 @@ static void psync_init_task_renfile_from(psync_variant_row row) { size_t len; name = psync_get_lstring(row[4], &len); folder = - psync_fstask_get_or_create_folder_tasks_locked(psync_get_number(row[2])); - if ((cr = psync_fstask_find_creat(folder, name, 0))) { + pfs_task_get_or_create_folder_tasks_locked(psync_get_number(row[2])); + if ((cr = pfs_task_find_creat(folder, name, 0))) { ptree_del(&folder->creats, &cr->tree); free(cr); folder->taskscnt--; @@ -1906,10 +1906,10 @@ static void psync_init_task_renfile_from(psync_variant_row row) { rm->taskid = psync_get_number(row[0]); rm->fileid = psync_get_snumber(row[3]); memcpy(rm->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &rm->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } static void psync_init_task_renfile_to(psync_variant_row row) { @@ -1923,8 +1923,8 @@ static void psync_init_task_renfile_to(psync_variant_row row) { size_t len; name = psync_get_lstring(row[4], &len); folderid = psync_get_snumber(row[2]); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); - cr = psync_fstask_find_creat(folder, name, 0); + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); + cr = pfs_task_find_creat(folder, name, 0); if (cr) { ptree_del(&folder->creats, &cr->tree); folder->taskscnt--; @@ -1938,7 +1938,7 @@ static void psync_init_task_renfile_to(psync_variant_row row) { un->fileid = fileid; un->taskid = taskid; memcpy(un->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_creat_t, name), &un->tree); cr = (psync_fstask_creat_t *)malloc( offsetof(psync_fstask_creat_t, name) + len); @@ -1946,11 +1946,11 @@ static void psync_init_task_renfile_to(psync_variant_row row) { cr->rfileid = psync_get_number(row[7]); cr->taskid = taskid; memcpy(cr->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &cr->tree); folder->taskscnt += 2; - psync_fstask_release_folder_tasks_locked(folder); - psync_fs_rename_openfile_locked(cr->fileid, folderid, name); + pfs_task_release_folder_tasks_locked(folder); + pfs_rename_openfile_locked(cr->fileid, folderid, name); if (folderid >= 0) ppathstatus_drive_fldr_changed(folderid); } @@ -1963,8 +1963,8 @@ static void psync_init_task_renfolder_from(psync_variant_row row) { size_t len; name = psync_get_lstring(row[4], &len); folder = - psync_fstask_get_or_create_folder_tasks_locked(psync_get_number(row[2])); - if ((mk = psync_fstask_find_mkdir(folder, name, 0))) { + pfs_task_get_or_create_folder_tasks_locked(psync_get_number(row[2])); + if ((mk = pfs_task_find_mkdir(folder, name, 0))) { ptree_del(&folder->mkdirs, &mk->tree); free(mk); folder->taskscnt--; @@ -1975,10 +1975,10 @@ static void psync_init_task_renfolder_from(psync_variant_row row) { rm->taskid = psync_get_number(row[0]); rm->folderid = psync_get_snumber(row[8]); memcpy(rm->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &rm->tree); folder->taskscnt++; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } static void psync_init_task_renfolder_to(psync_variant_row row) { @@ -1991,7 +1991,7 @@ static void psync_init_task_renfolder_to(psync_variant_row row) { size_t len; name = psync_get_lstring(row[4], &len); folder = - psync_fstask_get_or_create_folder_tasks_locked(psync_get_number(row[2])); + pfs_task_get_or_create_folder_tasks_locked(psync_get_number(row[2])); len++; taskid = psync_get_number(row[0]); folderid = psync_get_snumber(row[8]); @@ -2000,7 +2000,7 @@ static void psync_init_task_renfolder_to(psync_variant_row row) { rm->taskid = taskid; rm->folderid = folderid; memcpy(rm->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &rm->tree); mk = (psync_fstask_mkdir_t *)malloc( offsetof(psync_fstask_mkdir_t, name) + len); @@ -2009,10 +2009,10 @@ static void psync_init_task_renfolder_to(psync_variant_row row) { mk->flags = psync_get_number(row[7]); memcpy(mk->name, name, len); fill_mkdir_data(mk->folderid, mk); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->mkdirs, offsetof(psync_fstask_mkdir_t, name), &mk->tree); folder->taskscnt += 2; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); if (folderid >= 0) ppathstatus_drive_fldr_changed(folderid); } @@ -2026,9 +2026,9 @@ static void psync_init_task_modify(psync_variant_row row) { size_t len; name = psync_get_lstring(row[4], &len); folder = - psync_fstask_get_or_create_folder_tasks_locked(psync_get_number(row[2])); + pfs_task_get_or_create_folder_tasks_locked(psync_get_number(row[2])); taskid = psync_get_number(row[0]); - cr = psync_fstask_find_creat(folder, name, 0); + cr = pfs_task_find_creat(folder, name, 0); if (cr) { ptree_del(&folder->creats, &cr->tree); free(cr); @@ -2040,7 +2040,7 @@ static void psync_init_task_modify(psync_variant_row row) { un->fileid = psync_get_snumber(row[3]); un->taskid = taskid; memcpy(un->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->unlinks, offsetof(psync_fstask_unlink_t, name), &un->tree); cr = (psync_fstask_creat_t *)malloc( offsetof(psync_fstask_creat_t, name) + len); @@ -2048,12 +2048,12 @@ static void psync_init_task_modify(psync_variant_row row) { cr->rfileid = psync_get_number(row[3]); cr->taskid = taskid; memcpy(cr->name, name, len); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->creats, offsetof(psync_fstask_creat_t, name), &cr->tree); folder->taskscnt += 2; if (folder->folderid >= 0) ppathstatus_drive_fldr_changed(folder->folderid); - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); } typedef void (*psync_init_task_ptr)(psync_variant_row); @@ -2071,7 +2071,7 @@ static psync_init_task_ptr psync_init_task_func[] = { psync_init_task_modify, psync_init_task_unlink_set_rev}; -static void psync_fstask_free_tree(psync_tree *tr) { +static void pfs_task_free_tree(psync_tree *tr) { psync_tree *ntr; tr = ptree_get_first_safe(tr); while (tr) { @@ -2081,7 +2081,7 @@ static void psync_fstask_free_tree(psync_tree *tr) { } } -void psync_fstask_clean() { +void pfs_task_clean() { psync_fstask_folder_t *folder; psync_tree *tr; psql_lock(); @@ -2089,10 +2089,10 @@ void psync_fstask_clean() { while (tr) { folder = ptree_element(tr, psync_fstask_folder_t, tree); tr = ptree_get_next(tr); - psync_fstask_free_tree(folder->creats); - psync_fstask_free_tree(folder->unlinks); - psync_fstask_free_tree(folder->mkdirs); - psync_fstask_free_tree(folder->rmdirs); + pfs_task_free_tree(folder->creats); + pfs_task_free_tree(folder->unlinks); + pfs_task_free_tree(folder->mkdirs); + pfs_task_free_tree(folder->rmdirs); if (folder->refcnt == 0) { ptree_del(&folders, &folder->tree); free(folder); @@ -2107,7 +2107,7 @@ void psync_fstask_clean() { psql_unlock(); } -void psync_fstask_add_banned_folder(psync_fsfolderid_t folderid, +void pfs_task_add_banned_folder(psync_fsfolderid_t folderid, const char *name) { psync_fstask_folder_t *folder; psync_fstask_mkdir_t *mk; @@ -2128,21 +2128,21 @@ void psync_fstask_add_banned_folder(psync_fsfolderid_t folderid, rm->folderid = 0; memcpy(rm->name, name, len); psql_lock(); - folder = psync_fstask_get_or_create_folder_tasks_locked(folderid); - psync_fstask_insert_into_tree( + folder = pfs_task_get_or_create_folder_tasks_locked(folderid); + pfs_task_insert_into_tree( &folder->mkdirs, offsetof(psync_fstask_mkdir_t, name), &mk->tree); - psync_fstask_insert_into_tree( + pfs_task_insert_into_tree( &folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &rm->tree); folder->taskscnt += 2; - psync_fstask_release_folder_tasks_locked(folder); + pfs_task_release_folder_tasks_locked(folder); psql_unlock(); } -void psync_fstask_add_banned_folders() { +void pfs_task_add_banned_folders() { // noop } -void psync_fstask_init() { +void pfs_task_init() { unsigned long tp; psync_sql_res *res; psync_variant_row row; @@ -2163,12 +2163,12 @@ void psync_fstask_init() { psync_init_task_func[tp](row); } psql_free(res); - psync_fsupload_init(); + pfs_upld_init(); } #if IS_DEBUG -void psync_fstask_dump_state() { +void pfs_task_dump_state() { psync_fstask_folder_t *folder; psync_fstask_mkdir_t *mk; psync_fstask_rmdir_t *rm; diff --git a/pclsync/pfstasks.h b/pclsync/pfstasks.h index 55bb980..0faf8eb 100644 --- a/pclsync/pfstasks.h +++ b/pclsync/pfstasks.h @@ -106,7 +106,7 @@ typedef struct { uint32_t refcnt; } psync_fstask_folder_t; -static inline size_t psync_fstask_creat_local_offset(size_t namelen) { +static inline size_t pfs_task_creat_local_offset(size_t namelen) { return (offsetof(psync_fstask_creat_t, name) + namelen + psync_alignof(psync_fstask_local_creat_t)) / psync_alignof(psync_fstask_local_creat_t) * @@ -114,115 +114,115 @@ static inline size_t psync_fstask_creat_local_offset(size_t namelen) { } static inline psync_fstask_local_creat_t * -psync_fstask_creat_len_get_local(psync_fstask_creat_t *cr, size_t namelen) { +pfs_task_creat_len_get_local(psync_fstask_creat_t *cr, size_t namelen) { return ( psync_fstask_local_creat_t *)(((char *)cr) + - psync_fstask_creat_local_offset(namelen)); + pfs_task_creat_local_offset(namelen)); } static inline psync_fstask_local_creat_t * -psync_fstask_creat_get_local(psync_fstask_creat_t *cr) { - return psync_fstask_creat_len_get_local(cr, strlen(cr->name)); +pfs_task_creat_get_local(psync_fstask_creat_t *cr) { + return pfs_task_creat_len_get_local(cr, strlen(cr->name)); } -void psync_fstask_init(); +void pfs_task_init(); psync_fstask_folder_t * -psync_fstask_get_or_create_folder_tasks(psync_fsfolderid_t folderid); +pfs_task_get_or_create_folder_tasks(psync_fsfolderid_t folderid); psync_fstask_folder_t * -psync_fstask_get_folder_tasks(psync_fsfolderid_t folderid); -void psync_fstask_release_folder_tasks(psync_fstask_folder_t *folder); +pfs_task_get_folder_tasks(psync_fsfolderid_t folderid); +void pfs_task_release_folder_tasks(psync_fstask_folder_t *folder); psync_fstask_folder_t * -psync_fstask_get_ref_locked(psync_fstask_folder_t *folder); +pfs_task_get_ref_locked(psync_fstask_folder_t *folder); psync_fstask_folder_t * -psync_fstask_get_or_create_folder_tasks_locked(psync_fsfolderid_t folderid); +pfs_task_get_or_create_folder_tasks_locked(psync_fsfolderid_t folderid); psync_fstask_folder_t * -psync_fstask_get_folder_tasks_locked(psync_fsfolderid_t folderid); +pfs_task_get_folder_tasks_locked(psync_fsfolderid_t folderid); psync_fstask_folder_t * -psync_fstask_get_folder_tasks_rdlocked(psync_fsfolderid_t folderid); -void psync_fstask_release_folder_tasks_locked(psync_fstask_folder_t *folder); +pfs_task_get_folder_tasks_rdlocked(psync_fsfolderid_t folderid); +void pfs_task_release_folder_tasks_locked(psync_fstask_folder_t *folder); -void psync_fstask_folder_created(psync_folderid_t parentfolderid, +void pfs_task_folder_created(psync_folderid_t parentfolderid, uint64_t taskid, psync_folderid_t folderid, const char *name); -void psync_fstask_folder_deleted(psync_folderid_t parentfolderid, +void pfs_task_folder_deleted(psync_folderid_t parentfolderid, uint64_t taskid, const char *name); -void psync_fstask_file_created(psync_folderid_t parentfolderid, uint64_t taskid, +void pfs_task_file_created(psync_folderid_t parentfolderid, uint64_t taskid, const char *name, psync_fileid_t fileid); -void psync_fstask_file_modified(psync_folderid_t parentfolderid, +void pfs_task_file_modified(psync_folderid_t parentfolderid, uint64_t taskid, const char *name, psync_fileid_t fileid); -void psync_fstask_file_deleted(psync_folderid_t parentfolderid, uint64_t taskid, +void pfs_task_file_deleted(psync_folderid_t parentfolderid, uint64_t taskid, const char *name); -void psync_fstask_file_renamed(psync_folderid_t folderid, uint64_t taskid, +void pfs_task_file_renamed(psync_folderid_t folderid, uint64_t taskid, const char *name, uint64_t frtaskid); -void psync_fstask_folder_renamed(psync_folderid_t parentfolderid, +void pfs_task_folder_renamed(psync_folderid_t parentfolderid, uint64_t taskid, const char *name, uint64_t frtaskid); -psync_fstask_mkdir_t *psync_fstask_find_mkdir(psync_fstask_folder_t *folder, +psync_fstask_mkdir_t *pfs_task_find_mkdir(psync_fstask_folder_t *folder, const char *name, uint64_t taskid); -psync_fstask_rmdir_t *psync_fstask_find_rmdir(psync_fstask_folder_t *folder, +psync_fstask_rmdir_t *pfs_task_find_rmdir(psync_fstask_folder_t *folder, const char *name, uint64_t taskid); -psync_fstask_creat_t *psync_fstask_find_creat(psync_fstask_folder_t *folder, +psync_fstask_creat_t *pfs_task_find_creat(psync_fstask_folder_t *folder, const char *name, uint64_t taskid); -psync_fstask_unlink_t *psync_fstask_find_unlink(psync_fstask_folder_t *folder, +psync_fstask_unlink_t *pfs_task_find_unlink(psync_fstask_folder_t *folder, const char *name, uint64_t taskid); psync_fstask_mkdir_t * -psync_fstask_find_mkdir_by_folderid(psync_fstask_folder_t *folder, +pfs_task_find_mkdir_by_folderid(psync_fstask_folder_t *folder, psync_fsfolderid_t folderid); psync_fstask_creat_t * -psync_fstask_find_creat_by_fileid(psync_fstask_folder_t *folder, +pfs_task_find_creat_by_fileid(psync_fstask_folder_t *folder, psync_fsfileid_t fileid); -int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name, +int pfs_task_mkdir(psync_fsfolderid_t folderid, const char *name, uint32_t folderflags); -int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, +int pfs_task_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, const char *name); -int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, +int pfs_task_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags, const char *name); -psync_fstask_creat_t *psync_fstask_add_creat(psync_fstask_folder_t *folder, +psync_fstask_creat_t *pfs_task_add_creat(psync_fstask_folder_t *folder, const char *name, psync_fsfileid_t fileid, const char *encsymkey, size_t encsymkeylen); -void psync_fstask_inject_creat(psync_fstask_folder_t *folder, +void pfs_task_inject_creat(psync_fstask_folder_t *folder, psync_fstask_creat_t *cr); -void psync_fstask_inject_unlink(psync_fstask_folder_t *folder, +void pfs_task_inject_unlink(psync_fstask_folder_t *folder, psync_fstask_unlink_t *un); psync_fstask_creat_t * -psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name, +pfs_task_add_modified_file(psync_fstask_folder_t *folder, const char *name, psync_fsfileid_t fileid, uint64_t hash, const char *encsymkey, size_t encsymkeylen); -int psync_fstask_set_mtime(psync_fileid_t fileid, uint64_t oldtm, +int pfs_task_set_mtime(psync_fileid_t fileid, uint64_t oldtm, uint64_t newtm, int is_ctime); -int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid, +int pfs_task_add_local_creat_static(psync_fsfolderid_t folderid, const char *name, const void *data, size_t datalen); -int psync_fstask_can_unlink(psync_fsfolderid_t folderid, const char *name); -int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name); -int psync_fstask_rename_file(psync_fsfileid_t fileid, +int pfs_task_can_unlink(psync_fsfolderid_t folderid, const char *name); +int pfs_task_unlink(psync_fsfolderid_t folderid, const char *name); +int pfs_task_rename_file(psync_fsfileid_t fileid, psync_fsfolderid_t parentfolderid, const char *name, psync_fsfolderid_t to_folderid, const char *new_name); -int psync_fstask_rename_folder(psync_fsfolderid_t folderid, +int pfs_task_rename_folder(psync_fsfolderid_t folderid, psync_fsfolderid_t parentfolderid, const char *name, psync_fsfolderid_t to_folderid, const char *new_name, uint32_t targetflags); -void psync_fstask_clean(); +void pfs_task_clean(); -void psync_fstask_add_banned_folders(); +void pfs_task_add_banned_folders(); #if IS_DEBUG -void psync_fstask_dump_state(); +void pfs_task_dump_state(); #endif #endif diff --git a/pclsync/pfsupload.c b/pclsync/pfsupload.c index 0ac2c66..51fb141 100644 --- a/pclsync/pfsupload.c +++ b/pclsync/pfsupload.c @@ -155,13 +155,13 @@ static int psync_process_task_mkdir(fsupload_task_t *task) { folderid = papi_find_result2(meta, "folderid", PARAM_NUM)->num; task->int2 = folderid; pfileops_create_fldr(meta); - psync_fstask_folder_created(task->folderid, task->id, folderid, task->text1); - psync_fs_task_to_folder(task->id, folderid); + pfs_task_folder_created(task->folderid, task->id, folderid, task->text1); + pfs_xatr_task_to_folder(task->id, folderid); if (task->text2 && papi_find_result2(task->res, "created", PARAM_BOOL)->num) { psync_sql_res *res; unsigned char *enckey; size_t enckeylen; - enckey = psync_base64_decode((const unsigned char *)task->text2, + enckey = putil_base64_decode((const unsigned char *)task->text2, strlen(task->text2), &enckeylen); if (pdbg_likely(enckey)) { res = psql_prepare( @@ -193,14 +193,14 @@ static int handle_rmdir_api_error(uint64_t result, fsupload_task_t *task) { switch (result) { case 2005: /* folder does not exist, kind of success */ // pfileops_delete_fldr(task->sfolderid); - psync_fstask_folder_deleted(task->folderid, task->id, task->text1); + pfs_task_folder_deleted(task->folderid, task->id, task->text1); return 0; case 2003: /* access denied, skip*/ case 2006: /* not empty */ case 2028: /* folder is shared */ case 2287: /* public folder */ case 2345: /* backup */ - psync_fstask_folder_deleted(task->folderid, task->id, task->text1); + pfs_task_folder_deleted(task->folderid, task->id, task->text1); return 0; default: return -1; @@ -214,7 +214,7 @@ static int psync_process_task_rmdir(fsupload_task_t *task) { return handle_rmdir_api_error(result, task); pfileops_delete_fldr( papi_find_result2(task->res, "metadata", PARAM_HASH)); - psync_fstask_folder_deleted(task->folderid, task->id, task->text1); + pfs_task_folder_deleted(task->folderid, task->id, task->text1); pdbg_logf(D_NOTICE, "folder %lu/%s deleted", (unsigned long)task->folderid, task->text1); return 0; @@ -265,7 +265,7 @@ static int psync_send_task_creat_upload_small(psock_t *api, data = papi_prepare_alloc("uploadfile", params, size, size, &len); } if (pdbg_unlikely(pfile_read(fd, data + len, size) != size) || - pdbg_unlikely(psync_fs_get_file_writeid(task->id) != task->int1)) { + pdbg_unlikely(pfs_get_file_writeid(task->id) != task->int1)) { free(data); return -1; } @@ -361,14 +361,14 @@ static int handle_upload_api_error_taskid(uint64_t result, uint64_t taskid) { res = psql_prepare("UPDATE fstask SET folderid=0 WHERE id=?"); psql_bind_uint(res, 1, taskid); psql_run_free(res); - psync_fsupload_wake(); + pfs_upld_wake(); return -1; case 2001: /* invalid filename */ res = psql_prepare( "UPDATE fstask SET text1=\"Invalid Name Requested\" WHERE id=?"); psql_bind_uint(res, 1, taskid); psql_run_free(res); - psync_fsupload_wake(); + pfs_upld_wake(); return -1; case 2008: { /* overquota */ int locked = psql_locked(); @@ -402,7 +402,7 @@ static void set_key_for_fileid(psync_fileid_t fileid, uint64_t hash, unsigned char *enckey; size_t enckeylen; enckey = - psync_base64_decode((const unsigned char *)key, strlen(key), &enckeylen); + putil_base64_decode((const unsigned char *)key, strlen(key), &enckeylen); if (pdbg_likely(enckey)) { res = psql_prepare( "REPLACE INTO cryptofilekey (fileid, hash, enckey) VALUES (?, ?, ?)"); @@ -429,7 +429,7 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid, size = papi_find_result2(meta, "size", PARAM_NUM)->num; deleted = 0; psql_start(); - if (psync_fs_update_openfile( + if (pfs_update_openfile( taskid, writeid, fileid, hash, size, papi_find_result2(meta, "created", PARAM_NUM)->num)) { sql = psql_query_nolock("SELECT status FROM fstask WHERE id=?"); @@ -454,13 +454,13 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid, pfileops_create_file(meta); if (!deleted) ppagecache_creat(taskid, hash, 0); - psync_fstask_file_created(folderid, taskid, name, fileid); - psync_fs_task_to_file(taskid, fileid); + pfs_task_file_created(folderid, taskid, name, fileid); + pfs_xatr_task_to_file(taskid, fileid); } else { pfileops_update_file(meta); if (!deleted) ppagecache_modify(taskid, hash, oldhash); - psync_fstask_file_modified(folderid, taskid, name, fileid); + pfs_task_file_modified(folderid, taskid, name, fileid); } if (key) set_key_for_fileid(fileid, hash, key); @@ -469,7 +469,7 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid, psql_bind_uint(sql, 1, taskid); psql_run_free(sql); if (psql_affected()) - psync_fsupload_wake(); + pfs_upld_wake(); sql = psql_prepare("DELETE FROM fstaskupload WHERE fstaskid=?"); psql_bind_uint(sql, 1, taskid); psql_run_free(sql); @@ -492,7 +492,7 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid, if (!psql_affected()) { pdbg_logf(D_BUG, "upload of %s cancelled due to writeid mismatch, writeid %lu, " - "psync_fs_update_openfile should have catched that", + "pfs_update_openfile should have catched that", name, (long unsigned)writeid); psql_rollback(); return -1; @@ -590,14 +590,14 @@ static void perm_fail_upload_task(uint64_t taskid) { psql_bind_uint(sql, 1, taskid); psql_run_free(sql); if (psql_affected()) - psync_fsupload_wake(); + pfs_upld_wake(); sql = psql_prepare("DELETE FROM fstask WHERE fileid=?"); psql_bind_int(sql, 1, -(psync_fsfileid_t)taskid); psql_run_free(sql); sql = psql_prepare("DELETE FROM fstask WHERE id=?"); psql_bind_uint(sql, 1, taskid); psql_run_free(sql); - psync_fs_task_deleted(taskid); + pfs_xatr_task_deleted(taskid); psql_commit(); pstatus_upload_recalc_async(); } @@ -844,7 +844,7 @@ static int large_upload_creat(uint64_t taskid, psync_folderid_t folderid, psync_apipool_release(api); goto errs; } - if (psync_fs_get_file_writeid(taskid) != writeid) { + if (pfs_get_file_writeid(taskid) != writeid) { pdbg_logf(D_NOTICE, "%s changed while uploading as %lu/%s", filename, (unsigned long)folderid, name); psync_apipool_release(api); @@ -1000,7 +1000,7 @@ int upload_modify(uint64_t taskid, psync_folderid_t folderid, const char *name, } tree = NULL; if (pdbg_unlikely((fsize = pfile_size(fd)) == -1 || - psync_fs_load_interval_tree(fd, fsize, &tree) == -1)) { + pfs_load_interval_tree(fd, fsize, &tree) == -1)) { psync_interval_tree_free(tree); pfile_close(fd); return -1; @@ -1110,7 +1110,7 @@ int upload_modify(uint64_t taskid, psync_folderid_t folderid, const char *name, } psync_interval_tree_free(tree); pupload_bytes_sub(asize); - if (psync_fs_get_file_writeid(taskid) != writeid) { + if (pfs_get_file_writeid(taskid) != writeid) { pdbg_logf(D_NOTICE, "%s changed while uploading as %lu/%s", filename, (unsigned long)folderid, name); psync_apipool_release(api); @@ -1181,9 +1181,9 @@ static void large_upload() { fileidhex[sizeof(psync_fsfileid_t)] = 'd'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; cname = psync_setting_get_string(_PS(fscachepath)); - filename = psync_strcat(cname, "/", fileidhex, NULL); + filename = putil_strcat(cname, "/", fileidhex, NULL); fileidhex[sizeof(psync_fsfileid_t)] = 'i'; - indexname = psync_strcat(cname, "/", fileidhex, NULL); + indexname = putil_strcat(cname, "/", fileidhex, NULL); res = psql_query_rdlock("SELECT uploadid FROM fstaskupload WHERE " "fstaskid=? ORDER BY uploadid DESC LIMIT 1"); psql_bind_uint(res, 1, taskid); @@ -1220,7 +1220,7 @@ static void large_upload() { current_upload_taskid = 0; psql_free(res); if (uploadid != 2) - psync_fsupload_wake(); + pfs_upld_wake(); psys_sleep_milliseconds(PSYNC_SLEEP_ON_FAILED_UPLOAD); } free(indexname); @@ -1236,7 +1236,7 @@ static int psync_sent_task_creat_upload_large(fsupload_task_t *task) { res = psql_prepare( "UPDATE fstask SET status=2 WHERE id=? AND status=0"); psql_bind_uint(res, 1, task->id); - // psync_fs_uploading_openfile(task->id); + // pfs_uploading_openfile(task->id); if (!large_upload_running) { large_upload_running = 1; prun_thread("large file fs upload", large_upload); @@ -1245,7 +1245,7 @@ static int psync_sent_task_creat_upload_large(fsupload_task_t *task) { return 0; } -void psync_fsupload_stop_upload_locked(uint64_t taskid) { +void pfs_upld_stop_upload_locked(uint64_t taskid) { psync_sql_res *res; if (current_upload_taskid == taskid) stop_current_upload = 1; @@ -1255,7 +1255,7 @@ void psync_fsupload_stop_upload_locked(uint64_t taskid) { pdbg_assertw(psql_affected()); } -int psync_fsupload_in_current_small_uploads_batch_locked(uint64_t taskid) { +int pfs_upld_in_current_small_uploads_batch_locked(uint64_t taskid) { fsupload_task_t *task; if (!current_upload_batch) return 0; @@ -1269,7 +1269,7 @@ int psync_fsupload_in_current_small_uploads_batch_locked(uint64_t taskid) { psync_binhex(fileidhex, &task->id, sizeof(psync_fsfileid_t)); fileidhex[sizeof(psync_fsfileid_t)] = 'd'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; - filename = psync_strcat(psync_setting_get_string(_PS(fscachepath)), + filename = putil_strcat(psync_setting_get_string(_PS(fscachepath)), "/", fileidhex, NULL); stret = stat(filename, &st); if (stret) @@ -1296,7 +1296,7 @@ static int psync_send_task_creat(psock_t *api, fsupload_task_t *task) { psync_binhex(fileidhex, &task->id, sizeof(psync_fsfileid_t)); fileidhex[sizeof(psync_fsfileid_t)] = 'd'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; - filename = psync_strcat(psync_setting_get_string(_PS(fscachepath)), + filename = putil_strcat(psync_setting_get_string(_PS(fscachepath)), "/", fileidhex, NULL); fd = pfile_open(filename, O_RDONLY, 0); free(filename); @@ -1345,7 +1345,7 @@ static int psync_process_task_creat(fsupload_task_t *task) { meta = papi_find_result2(task->res, "metadata", PARAM_ARRAY)->array[0]; fileid = papi_find_result2(meta, "fileid", PARAM_NUM)->num; hash = papi_find_result2(meta, "hash", PARAM_NUM)->num; - if (psync_fs_update_openfile( + if (pfs_update_openfile( task->id, task->int1, fileid, hash, papi_find_result2(meta, "size", PARAM_NUM)->num, papi_find_result2(meta, "created", PARAM_NUM)->num)) { @@ -1354,10 +1354,10 @@ static int psync_process_task_creat(fsupload_task_t *task) { return -1; } pfileops_create_file(meta); - psync_fstask_file_created(task->folderid, task->id, task->text1, fileid); + pfs_task_file_created(task->folderid, task->id, task->text1, fileid); if (task->text2) set_key_for_fileid(fileid, hash, task->text2); - psync_fs_task_to_file(task->id, fileid); + pfs_xatr_task_to_file(task->id, fileid); task->int2 = fileid; pdbg_logf(D_NOTICE, "file %lu/%s uploaded", (unsigned long)task->folderid, task->text1); @@ -1436,10 +1436,10 @@ static int handle_unlink_api_error(uint64_t result, fsupload_task_t *task) { switch (result) { case 2009: /* file does not exist, kind of success */ // pfileops_delete_file(task->fileid); - psync_fstask_file_deleted(task->folderid, task->id, task->text1); + pfs_task_file_deleted(task->folderid, task->id, task->text1); return 0; case 2003: /* access denied, skip*/ - psync_fstask_file_deleted(task->folderid, task->id, task->text1); + pfs_task_file_deleted(task->folderid, task->id, task->text1); return 0; default: return -1; @@ -1453,7 +1453,7 @@ static int psync_process_task_unlink(fsupload_task_t *task) { return handle_unlink_api_error(result, task); pfileops_delete_file( papi_find_result2(task->res, "metadata", PARAM_HASH)); - psync_fstask_file_deleted(task->folderid, task->id, task->text1); + pfs_task_file_deleted(task->folderid, task->id, task->text1); pdbg_logf(D_NOTICE, "file %lu/%s deleted", (unsigned long)task->folderid, task->text1); return 0; @@ -1559,7 +1559,7 @@ static int handle_rename_file_api_error(uint64_t result, case 2284: /* public folder can't contain download */ case 2343: /* backup folders can't contain download links */ case 2346: /* you can't place this item in backup folders */ - psync_fstask_file_renamed(task->folderid, task->id, task->text1, + pfs_task_file_renamed(task->folderid, task->id, task->text1, task->int1); return 0; } @@ -1574,7 +1574,7 @@ static int psync_process_task_rename_file(fsupload_task_t *task) { return handle_rename_file_api_error(result, task); meta = papi_find_result2(task->res, "metadata", PARAM_HASH); pfileops_update_file(meta); - psync_fstask_file_renamed(task->folderid, task->id, task->text1, task->int1); + pfs_task_file_renamed(task->folderid, task->id, task->text1, task->int1); pdbg_logf(D_NOTICE, "file %lu/%s renamed", (unsigned long)task->folderid, task->text1); return 0; @@ -1594,11 +1594,11 @@ static void change_folder_name(fsupload_task_t *task) { if (et > task->text1 && et[0] == '(' && atol(et + 1) < 20) { nn = malloc(sizeof(char) * (et - task->text1 + 7)); memcpy(nn, task->text1, et - task->text1); - psync_slprintf(nn + (et - task->text1), 7, " (%d)", atoi(et + 1) + 1); + putil_slprintf(nn + (et - task->text1), 7, " (%d)", atoi(et + 1) + 1); } } if (!nn) { - nn = psync_strcat(task->text1, "(1)", NULL); + nn = putil_strcat(task->text1, "(1)", NULL); } res = psql_prepare("UPDATE fstask SET text1=? WHERE id=?"); psql_bind_str(res, 1, nn); @@ -1632,7 +1632,7 @@ static int handle_rename_folder_api_error(uint64_t result, case 2342: /* backup folders can't contain upload links */ case 2343: /* backup folders can't contain download links */ case 2346: /* you can't place this item in backup folder */ - psync_fstask_folder_renamed(task->folderid, task->id, task->text1, + pfs_task_folder_renamed(task->folderid, task->id, task->text1, task->int1); return 0; case 2004: /* destination folder already exists */ @@ -1643,7 +1643,7 @@ static int handle_rename_folder_api_error(uint64_t result, folder than the set limit */ pdbg_logf(D_ERROR, "Error 2352. Tried to move too many folders into a sahred " "folder at once."); - psync_fstask_folder_renamed(task->folderid, task->id, task->text1, + pfs_task_folder_renamed(task->folderid, task->id, task->text1, task->int1); pqevent_queue_eventid(PEVENT_SHARE_RENAME_F); return 0; @@ -1663,7 +1663,7 @@ static int psync_process_task_rename_folder(fsupload_task_t *task) { meta = papi_find_result2(task->res, "metadata", PARAM_HASH); pfileops_update_fldr(meta); - psync_fstask_folder_renamed(task->folderid, task->id, task->text1, + pfs_task_folder_renamed(task->folderid, task->id, task->text1, task->int1); pdbg_logf(D_NOTICE, "folder %lu/%s renamed", (unsigned long)task->folderid, task->text1); @@ -1679,13 +1679,13 @@ static void psync_delete_write_cache_file(uint64_t taskid, int index) { fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; cachepath = psync_setting_get_string(_PS(fscachepath)); filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); pdbg_assertw(pfile_delete(filename) == 0); free(filename); if (index) { fileidhex[sizeof(psync_fsfileid_t)] = 'i'; filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); pdbg_assertw(pfile_delete(filename) == 0); free(filename); } @@ -1696,7 +1696,7 @@ static int psync_cancel_task_creat(fsupload_task_t *task) { psync_uint_row row; psync_fileid_t fileid; psync_delete_write_cache_file(task->id, 0); - psync_fstask_file_created(task->folderid, task->id, task->text1, 0); + pfs_task_file_created(task->folderid, task->id, task->text1, 0); res = psql_query_rdlock( "SELECT fileid FROM fstaskfileid WHERE fstaskid=?"); psql_bind_uint(res, 1, task->id); @@ -1718,7 +1718,7 @@ static int psync_cancel_task_creat(fsupload_task_t *task) { } static int psync_cancel_task_rename_file(fsupload_task_t *task) { - psync_fstask_file_renamed(task->folderid, task->id, task->text1, task->int1); + pfs_task_file_renamed(task->folderid, task->id, task->text1, task->int1); pdbg_logf(D_NOTICE, "cancelled rename task %lu (from task %lu) for file %s", (unsigned long)task->id, (unsigned long)task->int1, task->text1); return 0; @@ -1727,7 +1727,7 @@ static int psync_cancel_task_rename_file(fsupload_task_t *task) { static int psync_cancel_task_modify(fsupload_task_t *task) { psync_sql_res *res; psync_delete_write_cache_file(task->id, 1); - psync_fstask_file_modified(task->folderid, task->id, task->text1, 0); + pfs_task_file_modified(task->folderid, task->id, task->text1, 0); res = psql_prepare("UPDATE fstask SET fileid=? WHERE fileid=?"); psql_bind_uint(res, 1, task->fileid); psql_bind_int(res, 2, -(psync_fsfileid_t)task->id); @@ -1760,7 +1760,7 @@ static int psync_cancel_task_unlink(fsupload_task_t *task) { psql_run_free(res); return -1; } - psync_fstask_file_deleted(task->folderid, task->id, task->text1); + pfs_task_file_deleted(task->folderid, task->id, task->text1); return 0; } @@ -1779,7 +1779,7 @@ static int psync_cancel_task_unlink_set_rev(fsupload_task_t *task) { psql_run_free(res); return -1; } - psync_fstask_file_deleted(task->folderid, task->id, task->text1); + pfs_task_file_deleted(task->folderid, task->id, task->text1); return 0; } @@ -1885,7 +1885,7 @@ static void pr_update_fileid(psync_fileid_t newfileid, psql_run_free(res); } -static void psync_fsupload_process_tasks(psync_list *tasks) { +static void pfs_upld_process_tasks(psync_list *tasks) { fsupload_task_t *task; uint32_t creats, cancels, dels; creats = 0; @@ -1937,7 +1937,7 @@ static void psync_fsupload_process_tasks(psync_list *tasks) { pdiff_wake(); } -static void psync_fsupload_run_tasks(psync_list *tasks) { +static void pfs_upld_run_tasks(psync_list *tasks) { async_result_reader reader; psock_t *api; fsupload_task_t *task, *rtask; @@ -1988,7 +1988,7 @@ static void psync_fsupload_run_tasks(psync_list *tasks) { } psync_apipool_release(api); papi_rdr_free(&reader); - psync_fsupload_process_tasks(tasks); + pfs_upld_process_tasks(tasks); if (np) { psql_start(); psync_list_for_each_element(task, tasks, fsupload_task_t, @@ -2000,7 +2000,7 @@ static void psync_fsupload_run_tasks(psync_list *tasks) { return; err0: psync_apipool_release_bad(api); - psync_fsupload_process_tasks(tasks); + pfs_upld_process_tasks(tasks); err: papi_rdr_free(&reader); ptimer_notify_exception(); @@ -2027,12 +2027,12 @@ static void clean_stuck_tasks() { fileidhex[sizeof(psync_fsfileid_t)] = 'd'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); pfile_delete(filename); free(filename); fileidhex[sizeof(psync_fsfileid_t)] = 'i'; filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); pfile_delete(filename); free(filename); psql_start(); @@ -2048,7 +2048,7 @@ static void clean_stuck_tasks() { free(fr); } -static void psync_fsupload_check_tasks() { +static void pfs_upld_check_tasks() { fsupload_task_t *task; psync_sql_res *res; psync_variant_row row; @@ -2112,14 +2112,14 @@ static void psync_fsupload_check_tasks() { if (cnt == PSYNC_FSUPLOAD_NUM_TASKS_PER_RUN) upload_wakes++; if (!psync_list_isempty(&tasks)) - psync_fsupload_run_tasks(&tasks); + pfs_upld_run_tasks(&tasks); psql_lock(); current_upload_batch = NULL; psql_unlock(); psync_list_for_each_element_call(&tasks, fsupload_task_t, list, free); } -static void psync_fsupload_thread() { +static void pfs_upld_thread() { int waited; clean_stuck_tasks(); waited = 0; @@ -2129,7 +2129,7 @@ static void psync_fsupload_thread() { // it is better to sleep a bit to give a chance for events to accumulate if (waited) psys_sleep_milliseconds(100); - psync_fsupload_check_tasks(); + pfs_upld_check_tasks(); pthread_mutex_lock(&upload_mutex); while (!upload_wakes) { pthread_cond_wait(&upload_cond, &upload_mutex); @@ -2140,13 +2140,13 @@ static void psync_fsupload_thread() { } } -void psync_fsupload_init() { - pfscrypto_check_logs(); - ptimer_exception_handler(psync_fsupload_wake); - prun_thread("fsupload main", psync_fsupload_thread); +void pfs_upld_init() { + pfs_crpt_check_logs(); + ptimer_exception_handler(pfs_upld_wake); + prun_thread("fsupload main", pfs_upld_thread); } -void psync_fsupload_wake() { +void pfs_upld_wake() { pthread_mutex_lock(&upload_mutex); if (!upload_wakes++) pthread_cond_signal(&upload_cond); diff --git a/pclsync/pfsupload.h b/pclsync/pfsupload.h index f9f8520..4d19dcb 100644 --- a/pclsync/pfsupload.h +++ b/pclsync/pfsupload.h @@ -34,9 +34,9 @@ #include -void psync_fsupload_init(); -void psync_fsupload_wake(); -void psync_fsupload_stop_upload_locked(uint64_t taskid); -int psync_fsupload_in_current_small_uploads_batch_locked(uint64_t taskid); +void pfs_upld_init(); +void pfs_upld_wake(); +void pfs_upld_stop_upload_locked(uint64_t taskid); +int pfs_upld_in_current_small_uploads_batch_locked(uint64_t taskid); #endif diff --git a/pclsync/pfsxattr.c b/pclsync/pfsxattr.c index a8cc233..1756239 100644 --- a/pclsync/pfsxattr.c +++ b/pclsync/pfsxattr.c @@ -41,16 +41,16 @@ #include "psql.h" #include "plibs.h" -// needed by psync_fs_set_thread_name +// needed by pfs_xatr_set_thread_name extern PSYNC_THREAD const char *psync_thread_name; #if IS_DEBUG -#define psync_fs_set_thread_name() \ +#define pfs_xatr_set_thread_name() \ do { \ psync_thread_name = __FUNCTION__; \ } while (0) #else -#define psync_fs_set_thread_name() \ +#define pfs_xatr_set_thread_name() \ do { \ } while (0) #endif @@ -90,15 +90,15 @@ static void delete_object_id(uint64_t oid) { psql_run_free(res); } -void psync_fs_file_deleted(psync_fileid_t fileid) { +void pfs_xatr_file_deleted(psync_fileid_t fileid) { delete_object_id(fileid_to_objid(fileid)); } -void psync_fs_folder_deleted(psync_folderid_t folderid) { +void pfs_xatr_folder_deleted(psync_folderid_t folderid) { delete_object_id(folderid_to_objid(folderid)); } -void psync_fs_task_deleted(uint64_t taskid) { +void pfs_xatr_task_deleted(uint64_t taskid) { delete_object_id(taskid_to_objid(taskid)); } @@ -111,20 +111,20 @@ static void update_object_id(uint64_t ooid, uint64_t noid) { psql_run_free(res); } -void psync_fs_task_to_file(uint64_t taskid, psync_fileid_t fileid) { +void pfs_xatr_task_to_file(uint64_t taskid, psync_fileid_t fileid) { update_object_id(taskid_to_objid(taskid), fileid_to_objid(fileid)); } -void psync_fs_task_to_folder(uint64_t taskid, psync_folderid_t folderid) { +void pfs_xatr_task_to_folder(uint64_t taskid, psync_folderid_t folderid) { update_object_id(taskid_to_objid(taskid), folderid_to_objid(folderid)); } -void psync_fs_static_to_task(uint64_t statictaskid, uint64_t taskid) { +void pfs_xatr_static_to_task(uint64_t statictaskid, uint64_t taskid) { update_object_id(static_taskid_to_objid(statictaskid), taskid_to_objid(taskid)); } -void psync_fs_file_to_task(psync_fileid_t fileid, uint64_t taskid) { +void pfs_xatr_file_to_task(psync_fileid_t fileid, uint64_t taskid) { update_object_id(fileid_to_objid(fileid), taskid_to_objid(taskid)); } @@ -139,16 +139,16 @@ static int64_t xattr_get_object_id_locked(const char *path) { int checkfile, checkfolder; if (path[1] == 0 && path[0] == '/') return 0; - fspath = psync_fsfolder_resolve_path(path); + fspath = pfs_fldr_resolve_path(path); if (!fspath) { pdbg_logf(D_NOTICE, "path component of %s not found", path); return -1; } checkfile = 1; checkfolder = 1; - folder = psync_fstask_get_folder_tasks_rdlocked(fspath->folderid); + folder = pfs_task_get_folder_tasks_rdlocked(fspath->folderid); if (folder) { - mk = psync_fstask_find_mkdir(folder, fspath->name, 0); + mk = pfs_task_find_mkdir(folder, fspath->name, 0); if (mk) { free(fspath); pdbg_assertw(mk->folderid != 0); @@ -157,7 +157,7 @@ static int64_t xattr_get_object_id_locked(const char *path) { else return taskid_to_objid(-mk->folderid); } - cr = psync_fstask_find_creat(folder, fspath->name, 0); + cr = pfs_task_find_creat(folder, fspath->name, 0); if (cr) { free(fspath); if (cr->fileid > 0) @@ -185,8 +185,8 @@ static int64_t xattr_get_object_id_locked(const char *path) { return ret; } } - checkfolder = !psync_fstask_find_rmdir(folder, fspath->name, 0); - checkfile = !psync_fstask_find_unlink(folder, fspath->name, 0); + checkfolder = !pfs_task_find_rmdir(folder, fspath->name, 0); + checkfile = !pfs_task_find_unlink(folder, fspath->name, 0); } if (fspath->folderid < 0) { free(fspath); @@ -248,12 +248,12 @@ static int64_t xattr_get_object_id_locked(const char *path) { } \ } while (0) -int psync_fs_setxattr(const char *path, const char *name, const char *value, +int pfs_xatr_set(const char *path, const char *name, const char *value, size_t size, int flags PFS_XATTR_IGN) { psync_sql_res *res; int64_t oid; int ret; - psync_fs_set_thread_name(); + pfs_xatr_set_thread_name(); pdbg_logf(D_NOTICE, "setting attribute %s of %s", name, path); LOCK_AND_LOOKUP(); if (flags & XATTR_CREATE) { @@ -291,12 +291,12 @@ int psync_fs_setxattr(const char *path, const char *name, const char *value, return ret; } -int psync_fs_getxattr(const char *path, const char *name, char *value, +int pfs_xatr_get(const char *path, const char *name, char *value, size_t size PFS_XATTR_IGN) { psync_sql_res *res; int64_t oid; int ret; - psync_fs_set_thread_name(); + pfs_xatr_set_thread_name(); LOCK_AND_LOOKUPRD(); if (size && value) { psync_variant_row row; @@ -341,13 +341,13 @@ int psync_fs_getxattr(const char *path, const char *name, char *value, return ret; } -int psync_fs_listxattr(const char *path, char *list, size_t size) { +int pfs_xatr_list(const char *path, char *list, size_t size) { psync_sql_res *res; int64_t oid; const char *str; size_t len; int ret; - psync_fs_set_thread_name(); + pfs_xatr_set_thread_name(); LOCK_AND_LOOKUPRD(); if (size && list) { psync_variant_row row; @@ -382,11 +382,11 @@ int psync_fs_listxattr(const char *path, char *list, size_t size) { return ret; } -int psync_fs_removexattr(const char *path, const char *name) { +int pfs_xatr_remove(const char *path, const char *name) { psync_sql_res *res; int64_t oid; uint32_t aff; - psync_fs_set_thread_name(); + pfs_xatr_set_thread_name(); LOCK_AND_LOOKUP(); res = psql_prepare( "DELETE FROM fsxattr WHERE objectid=? AND name=?"); diff --git a/pclsync/pfsxattr.h b/pclsync/pfsxattr.h index 49f4304..78a324e 100644 --- a/pclsync/pfsxattr.h +++ b/pclsync/pfsxattr.h @@ -38,20 +38,20 @@ #define PFS_XATTR_IGN -int psync_fs_setxattr(const char *path, const char *name, const char *value, +int pfs_xatr_set(const char *path, const char *name, const char *value, size_t size, int flags PFS_XATTR_IGN); -int psync_fs_getxattr(const char *path, const char *name, char *value, +int pfs_xatr_get(const char *path, const char *name, char *value, size_t size PFS_XATTR_IGN); -int psync_fs_listxattr(const char *path, char *list, size_t size); -int psync_fs_removexattr(const char *path, const char *name); +int pfs_xatr_list(const char *path, char *list, size_t size); +int pfs_xatr_remove(const char *path, const char *name); -void psync_fs_file_deleted(psync_fileid_t fileid); -void psync_fs_folder_deleted(psync_folderid_t folderid); -void psync_fs_task_deleted(uint64_t taskid); +void pfs_xatr_file_deleted(psync_fileid_t fileid); +void pfs_xatr_folder_deleted(psync_folderid_t folderid); +void pfs_xatr_task_deleted(uint64_t taskid); -void psync_fs_task_to_file(uint64_t taskid, psync_fileid_t fileid); -void psync_fs_task_to_folder(uint64_t taskid, psync_folderid_t folderid); -void psync_fs_static_to_task(uint64_t statictaskid, uint64_t taskid); -void psync_fs_file_to_task(psync_fileid_t fileid, uint64_t taskid); +void pfs_xatr_task_to_file(uint64_t taskid, psync_fileid_t fileid); +void pfs_xatr_task_to_folder(uint64_t taskid, psync_folderid_t folderid); +void pfs_xatr_static_to_task(uint64_t statictaskid, uint64_t taskid); +void pfs_xatr_file_to_task(psync_fileid_t fileid, uint64_t taskid); #endif diff --git a/pclsync/plibs.c b/pclsync/plibs.c index 63e27e3..806b2b5 100644 --- a/pclsync/plibs.c +++ b/pclsync/plibs.c @@ -92,7 +92,7 @@ int psync_rename_conflicted_file(const char *path) { num = 0; while (1) { if (num) - l = psync_slprintf(npath + dotidx, 32, " (conflicted %ld)", num); + l = putil_slprintf(npath + dotidx, 32, " (conflicted %ld)", num); else { l = 13; memcpy(npath + dotidx, " (conflicted)", l); diff --git a/pclsync/plibs.h b/pclsync/plibs.h index 6bd606b..cff4c4d 100644 --- a/pclsync/plibs.h +++ b/pclsync/plibs.h @@ -91,8 +91,8 @@ extern "C" { &(v)))) #define psync_dup_string(v) \ (likely((v).type == PSYNC_TSTRING) \ - ? psync_strndup((v).str, (v).length) \ - : psync_strdup(psql_expect_str(__FILE__, __FUNCTION__, \ + ? putil_strndup((v).str, (v).length) \ + : putil_strdup(psql_expect_str(__FILE__, __FUNCTION__, \ __LINE__, &(v)))) #define psync_get_lstring(v, l) \ psql_lstring_expected(__FILE__, __FUNCTION__, __LINE__, &(v), l) @@ -165,7 +165,7 @@ static inline void psync_get_string_id(char *dst, const char *prefix, uint64_t i plen = strlen(prefix); dst = (char *)memcpy(dst, prefix, plen) + plen; do { - *dst++ = base64_table[id % 64]; + *dst++ = putil_base64_table[id % 64]; id /= 64; } while (id); *dst = 0; @@ -177,12 +177,12 @@ static inline void psync_get_string_id2(char *dst, const char *prefix, uint64_t plen = strlen(prefix); dst = (char *)memcpy(dst, prefix, plen) + plen; do { - *dst++ = base64_table[id1 % 64]; + *dst++ = putil_base64_table[id1 % 64]; id1 /= 64; } while (id1); *dst++ = '.'; do { - *dst++ = base64_table[id2 % 64]; + *dst++ = putil_base64_table[id2 % 64]; id2 /= 64; } while (id2); *dst = 0; diff --git a/pclsync/plocalnotify.c b/pclsync/plocalnotify.c index 4a0b28f..b6f222c 100644 --- a/pclsync/plocalnotify.c +++ b/pclsync/plocalnotify.c @@ -119,7 +119,7 @@ static void add_dir_scan(localnotify_dir *dir, const char *path) { if (de->d_name[0] != '.' || (de->d_name[1] != 0 && (de->d_name[1] != '.' || de->d_name[2] != 0))) { - psync_strlcpy(cpath + pl, de->d_name, namelen + 1); + putil_strlcpy(cpath + pl, de->d_name, namelen + 1); if (!lstat(cpath, &st) && S_ISDIR(st.st_mode)) add_dir_scan(dir, cpath); } @@ -222,7 +222,7 @@ static uint32_t process_notification(localnotify_dir *dir) { while (wch) { if (wch->watchid == ev.wd) { wch->path[wch->pathlen] = '/'; - psync_strlcpy(wch->path + wch->pathlen + 1, + putil_strlcpy(wch->path + wch->pathlen + 1, buff + off + offsetof(struct inotify_event, name), wch->namelen + 1); if (!lstat(wch->path, &st) && S_ISDIR(st.st_mode)) diff --git a/pclsync/plocalscan.c b/pclsync/plocalscan.c index 836ed3c..7c3d276 100644 --- a/pclsync/plocalscan.c +++ b/pclsync/plocalscan.c @@ -143,7 +143,7 @@ static void scanner_set_syncs_to_list(psync_list *lst, psync_list_init(lst); psync_list_init(lst_deviceid_full); - syncmp = psync_fs_getmountpoint(); + syncmp = pfs_getmountpoint(); res = psql_query_rdlock( "SELECT id, folderid, localpath, synctype, deviceid, inode FROM " "syncfolder WHERE synctype&" NTO_STR(PSYNC_UPLOAD_ONLY) "=" NTO_STR( @@ -438,7 +438,7 @@ static void add_new_element(const sync_folderlist *e, psync_folderid_t folderid, return; if (psync_is_name_to_ignore(e->name)) return; - if (!psync_is_valid_utf8(e->name)) { + if (!putil_is_valid_utf8(e->name)) { pdbg_logf(D_WARNING, "ignoring %s with invalid UTF8 name %s", e->isfolder ? "folder" : "file", e->name); return; @@ -569,7 +569,7 @@ scanner_scan_folder(const char *localpath, psync_folderid_t folderid, psync_list_for_each_element(l, &disklist, sync_folderlist, list) if (l->isfolder && l->localid && l->deviceid == deviceid) { - subpath = psync_strcat(localpath, "/", l->name, NULL); + subpath = putil_strcat(localpath, "/", l->name, NULL); scanner_scan_folder(subpath, l->remoteid, l->localid, syncid, synctype, deviceid); free(subpath); diff --git a/pclsync/pnetlibs.c b/pclsync/pnetlibs.c index 4fd5608..d055afa 100644 --- a/pclsync/pnetlibs.c +++ b/pclsync/pnetlibs.c @@ -342,7 +342,7 @@ void psync_apipool_release_bad(psock_t *api) { psync_ret_api(api); } static void rm_all(void *vpath, ppath_stat *st) { char *path; - path = psync_strcat((char *)vpath, "/", st->name, NULL); + path = putil_strcat((char *)vpath, "/", st->name, NULL); if (pfile_stat_isfolder(&st->stat)) { ppath_ls(path, rm_all, path); rmdir(path); @@ -355,7 +355,7 @@ static void rm_ign(void *vpath, ppath_stat *st) { char *path; int ign; ign = psync_is_name_to_ignore(st->name); - path = psync_strcat((char *)vpath, "/", st->name, NULL); + path = putil_strcat((char *)vpath, "/", st->name, NULL); if (pfile_stat_isfolder(&st->stat)) { if (ign) ppath_ls(path, rm_all, path); @@ -984,9 +984,9 @@ cont: *ptr = 0; /* pdbg_logf(D_NOTICE, "key=%s, value=%s", key, val);*/ if (!memcmp(key, "content-length", 14)) - clen = psync_ato64(val); + clen = putil_ato64(val); else if (!memcmp(key, "keep-alive", 10) && !memcmp(val, "timeout=", 8)) - keepalive = psync_ato32(val + 8); + keepalive = putil_ato32(val + 8); key = ptr + 1; isval = 0; } else if (ch == ':' && !isval) { @@ -1482,9 +1482,9 @@ cont: *ptr = 0; /* pdbg_logf(D_NOTICE, "key=%s, value=%s", key, val);*/ if (!memcmp(key, "content-length", 14)) - clen = psync_ato64(val); + clen = putil_ato64(val); else if (!memcmp(key, "keep-alive", 10) && !memcmp(val, "timeout=", 8)) - keepalive = psync_ato32(val + 8); + keepalive = putil_ato32(val + 8); key = ptr + 1; isval = 0; } else if (ch == ':' && !isval) { @@ -1624,7 +1624,7 @@ static int psync_net_get_checksums(psock_t *api, psync_fileid_t fileid, } hosts = papi_find_result2(res, "hosts", PARAM_ARRAY); requestpath = papi_find_result2(res, "path", PARAM_STR)->str; - psync_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", + putil_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", papi_find_result2(res, "dwltag", PARAM_STR)->str); http = NULL; for (i = 0; i < hosts->length; i++) @@ -2682,13 +2682,13 @@ int psync_do_run_command_res(const char *cmd, size_t cmdlen, if (result) { pdbg_logf(D_WARNING, "command %s returned code %u", cmd, (unsigned)result); if (err) - *err = psync_strdup(papi_find_result2(res, "error", PARAM_STR)->str); + *err = putil_strdup(papi_find_result2(res, "error", PARAM_STR)->str); psync_process_api_error(result); } free(res); return (int)result; neterr: if (err) - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); return -1; } diff --git a/pclsync/pnotify.c b/pclsync/pnotify.c index 845ad8b..aa9caad 100644 --- a/pclsync/pnotify.c +++ b/pclsync/pnotify.c @@ -80,12 +80,12 @@ static void psync_notifications_download_thumb(const binresult *thumb, filename = strrchr(path, '/'); if (pdbg_unlikely(!filename++)) return; - filepath = psync_strcat(thumbpath, "/", filename, NULL); + filepath = putil_strcat(thumbpath, "/", filename, NULL); if (!stat(filepath, &st)) { pdbg_logf(D_NOTICE, "skipping download of %s as it already exists", filename); goto err0; } - tmpfilepath = psync_strcat(filepath, ".part", NULL); + tmpfilepath = putil_strcat(filepath, ".part", NULL); pdbg_logf(D_NOTICE, "downloading thumbnail %s", filename); if (pdbg_unlikely((fd = pfile_open(tmpfilepath, O_WRONLY, O_CREAT | O_TRUNC)) == @@ -95,7 +95,7 @@ static void psync_notifications_download_thumb(const binresult *thumb, papi_find_result2(thumb, "hosts", PARAM_ARRAY), &host); if (pdbg_unlikely(!sock)) goto err2; - psync_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", + putil_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", papi_find_result2(thumb, "dwltag", PARAM_STR)->str); if (pdbg_unlikely(psync_http_request(sock, host, path, 0, 0, cookie))) goto err3; @@ -187,7 +187,7 @@ void pnotify_set_callback( pthread_mutex_lock(&ntf_mutex); ts = ntf_thumb_size; if (thumbsize) - ntf_thumb_size = psync_strdup(thumbsize); + ntf_thumb_size = putil_strdup(thumbsize); else ntf_thumb_size = NULL; if (ts) @@ -326,7 +326,7 @@ psync_notification_list_t *pnotify_get() { filename = strrchr(papi_find_result2(br, "path", PARAM_STR)->str, '/'); if (filename++) { psync_notification_remove_from_list(&thumbs, filename); - filepath = psync_strcat(thumbpath, "/", + filepath = putil_strcat(thumbpath, "/", filename, NULL); if (!stat(filepath, &st)) { pntf->thumb = filepath; @@ -355,7 +355,7 @@ psync_notification_list_t *pnotify_get() { nx = ptree_get_next_safe(thumbs); pdbg_logf(D_NOTICE, "deleting unused thumb %s", ptree_element(thumbs, psync_thumb_list_t, tree)->name); - filepath = psync_strcat( + filepath = putil_strcat( thumbpath, "/", ptree_element(thumbs, psync_thumb_list_t, tree)->name, NULL); pfile_delete(filepath); diff --git a/pclsync/ppagecache.c b/pclsync/ppagecache.c index 537a075..dd79029 100644 --- a/pclsync/ppagecache.c +++ b/pclsync/ppagecache.c @@ -526,7 +526,7 @@ static void set_urls(psync_urls_t *urls, binresult *res) { } static void psync_pagecache_set_bad_encoder(psync_openfile_t *of) { - psync_fs_lock_file(of); + pfs_lock_file(of); if (likely(of->encoder == PSYNC_CRYPTO_LOADING_SECTOR_ENCODER)) { of->encoder = PSYNC_CRYPTO_FAILED_SECTOR_ENCODER; pthread_cond_broadcast(&enc_key_cond); @@ -618,7 +618,7 @@ static int get_urls(psync_request_t *request, psync_urls_t *urls) { goto err4; pdbg_logf(D_BUG, "got key for fileid %lu", (unsigned long)request->fileid); free(ret); - psync_fs_lock_file(request->of); + pfs_lock_file(request->of); if (pdbg_likely(request->of->encoder == PSYNC_CRYPTO_LOADING_SECTOR_ENCODER)) { request->of->encoder = enc; @@ -2171,7 +2171,7 @@ int ppagecache_read_mod_locked(psync_openfile_t *of, char *buf, rd = ppagecache_read_unmod_locked(of, buf, size, offset); if (rd < 0) return rd; - psync_fs_lock_file(of); + pfs_lock_file(of); fi = psync_interval_tree_first_interval_containing_or_after( of->writeintervals, offset); if (!fi || fi->from >= offset + size) { @@ -2266,7 +2266,7 @@ static void psync_pagecache_send_error(psync_request_t *request, int err) { unlock_wait(request->ash); if (request->needkey) psync_pagecache_set_bad_encoder(request->of); - psync_fs_dec_of_refcnt_and_readers(request->of); + pfs_dec_of_refcnt_and_readers(request->of); psync_pagecache_free_request(request); } @@ -2384,7 +2384,7 @@ char *psync_http_construct_range_next_header(psync_request_t *request, } if (off < sizeof(PSYNC_CONSTRUCT_HEADER)) return NULL; - return psync_strdup((char *)memcpy( + return putil_strdup((char *)memcpy( buff + off - sizeof(PSYNC_CONSTRUCT_HEADER) + 3, PSYNC_CONSTRUCT_HEADER, sizeof(PSYNC_CONSTRUCT_HEADER) - 1)); } @@ -2422,7 +2422,7 @@ retry: psync_pagecache_send_error(request, -EIO); return; } - psync_fs_lock_file(request->of); + pfs_lock_file(request->of); if (pdbg_likely(request->of->encoder == PSYNC_CRYPTO_LOADING_SECTOR_ENCODER)) { request->of->encoder = enc; @@ -2435,12 +2435,12 @@ retry: } if (psync_list_isempty(&request->ranges)) { release_urls(urls); - psync_fs_dec_of_refcnt_and_readers(request->of); + pfs_dec_of_refcnt_and_readers(request->of); psync_pagecache_free_request(request); return; } hosts = papi_find_result2(urls->urls, "hosts", PARAM_ARRAY); - psync_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", + putil_slprintf(cookie, sizeof(cookie), "Cookie: dwltag=%s\015\012", papi_find_result2(urls->urls, "dwltag", PARAM_STR)->str); sock = psync_http_connect_multihost_from_cache(hosts, &host); if (!sock) { @@ -2571,7 +2571,7 @@ retry: psync_http_close(sock); pdbg_logf(D_NOTICE, "request from %s finished", host); ok1: - psync_fs_dec_of_refcnt_and_readers(request->of); + pfs_dec_of_refcnt_and_readers(request->of); psync_pagecache_free_request(request); release_urls(urls); return; @@ -2740,7 +2740,7 @@ static void psync_pagecache_read_unmodified_readahead( uint32_t asize, aoff; for (i = 0; i < pagecnt; i += PSYNC_CRYPTO_HASH_TREE_SECTORS) { for (l = 0; l < offsets->treelevels; l++) { - pfscrypto_get_auth_off(first_page_id + i, l, offsets, + pfs_crpt_get_auth_off(first_page_id + i, l, offsets, &aoffset, &asize, &aoff); pageid = aoffset / PSYNC_FS_PAGE_SIZE; check_or_request_page(fileid, hash, pageid, ranges); @@ -2750,8 +2750,8 @@ static void psync_pagecache_read_unmodified_readahead( } } // this may include some auth sectors, but should do no harm - rto = pfscrypto_sector_id(first_page_id + pagecnt); - first_page_id = pfscrypto_sector_id(first_page_id); + rto = pfs_crpt_sector_id(first_page_id + pagecnt); + first_page_id = pfs_crpt_sector_id(first_page_id); pagecnt = rto - first_page_id; } pages_in_db = has_pages_in_db(hash, first_page_id, pagecnt, 1); @@ -2950,7 +2950,7 @@ int ppagecache_read_unmod_locked(psync_openfile_t *of, char *buf, rq->fileid = fileid; rq->hash = hash; rq->needkey = 0; - psync_fs_inc_of_refcnt_and_readers(of); + pfs_inc_of_refcnt_and_readers(of); prun_thread1("read unmodified", psync_pagecache_read_unmodified_thread, rq); } else @@ -3097,7 +3097,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, needkey = 0; pthread_mutex_unlock(&of->mutex); pdbg_assert(PSYNC_CRYPTO_SECTOR_SIZE == PSYNC_FS_PAGE_SIZE); - pfscrypto_offset_by_size(initialsize, &offsets); + pfs_crpt_offset_by_size(initialsize, &offsets); if (offset >= initialsize) return 0; if (offset + size > initialsize) @@ -3121,7 +3121,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, dp[i].authpage = ap; continue; } - pfscrypto_get_auth_off(first_page_id + i, 0, &offsets, + pfs_crpt_get_auth_off(first_page_id + i, 0, &offsets, &aoffset, &asize, &aoff); ap = malloc(sizeof(psync_crypto_auth_page)); ap->waiter = NULL; @@ -3141,7 +3141,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, unsigned long l; lap = ap; for (l = 1; l <= offsets.treelevels; l++) { - pfscrypto_get_auth_off(first_page_id + i, l, &offsets, + pfs_crpt_get_auth_off(first_page_id + i, l, &offsets, &aoffset, &asize, &aoff); cap = malloc(sizeof(psync_crypto_auth_page)); cap->waiter = NULL; @@ -3181,7 +3181,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, } dp[i].buff = pbuff; dp[i].pagesize = apsize; - apageid = pfscrypto_sector_id(first_page_id + i); + apageid = pfs_crpt_sector_id(first_page_id + i); rb = check_page_in_memory_by_hash(hash, apageid, pbuff, apsize, 0); if (rb == -1) rb = check_page_in_database_by_hash(hash, apageid, pbuff, apsize, 0); @@ -3199,7 +3199,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, rq->fileid = fileid; rq->hash = hash; rq->needkey = needkey; - psync_fs_inc_of_refcnt_and_readers(of); + pfs_inc_of_refcnt_and_readers(of); prun_thread1("crypto read unmodified", psync_pagecache_read_unmodified_thread, rq); } else @@ -3207,7 +3207,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, ret = 0; if (needkey) { pdbg_logf(D_NOTICE, "waiting for key to download"); - psync_fs_lock_file(of); + pfs_lock_file(of); while (of->encoder == PSYNC_CRYPTO_LOADING_SECTOR_ENCODER) pthread_cond_wait(&enc_key_cond, &of->mutex); if (of->encoder == PSYNC_CRYPTO_FAILED_SECTOR_ENCODER) { @@ -3232,7 +3232,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, (unsigned long)ap->firstpageid, (unsigned long)ap->firstpageid + ap->size / PSYNC_CRYPTO_AUTH_SIZE, (int)offsets.treelevels); - psync_fs_lock_file(of); + pfs_lock_file(of); if (likely(of->hash == hash)) psync_interval_tree_add( &of->authenticatedints, ap->firstpageid * PSYNC_FS_PAGE_SIZE, @@ -3276,7 +3276,7 @@ int ppagecache_read_unmod_enc_locked(psync_openfile_t *of, } while (p); ap = dp[i].authpage; if (!ret) { - psync_fs_lock_file(of); + pfs_lock_file(of); if (likely(of->hash == hash)) psync_interval_tree_add( &of->authenticatedints, ap->firstpageid * PSYNC_FS_PAGE_SIZE, @@ -3371,7 +3371,7 @@ int ppagecache_readv_locked(psync_openfile_t *of, psync_list_init(&waiting); for (i = 0; i < cnt; i++) { pdbg_assert(ranges[i].offset + ranges[i].size <= of->encrypted - ? pfscrypto_crypto_size(initialsize) + ? pfs_crpt_crypto_size(initialsize) : initialsize); poffset = offset_round_down_to_page(ranges[i].offset); pageoff = ranges[i].offset - poffset; @@ -3427,14 +3427,14 @@ int ppagecache_readv_locked(psync_openfile_t *of, rq->fileid = fileid; rq->hash = hash; rq->needkey = needkey; - psync_fs_inc_of_refcnt_and_readers(of); + pfs_inc_of_refcnt_and_readers(of); prun_thread1("readv unmodified", psync_pagecache_read_unmodified_thread, rq); } ret = 0; if (needkey) { pdbg_logf(D_NOTICE, "waiting for key to download"); - psync_fs_lock_file(of); + pfs_lock_file(of); while (of->encoder == PSYNC_CRYPTO_LOADING_SECTOR_ENCODER) pthread_cond_wait(&enc_key_cond, &of->mutex); if (of->encoder == PSYNC_CRYPTO_FAILED_SECTOR_ENCODER) { @@ -3527,7 +3527,7 @@ static void psync_pagecache_new_upload_to_cache(uint64_t taskid, uint64_t hash, fileidhex[sizeof(psync_fsfileid_t)] = 'd'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; tm = ptimer_time(); - filename = psync_strcat(psync_setting_get_string(_PS(fscachepath)), + filename = putil_strcat(psync_setting_get_string(_PS(fscachepath)), "/", fileidhex, NULL); fd = pfile_open(filename, O_RDONLY, 0); if (fd == INVALID_HANDLE_VALUE) { @@ -3613,10 +3613,10 @@ static void psync_pagecache_modify_to_cache(uint64_t taskid, uint64_t hash, tm = ptimer_time(); cachepath = psync_setting_get_string(_PS(fscachepath)); filename = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); fileidhex[sizeof(psync_fsfileid_t)] = 'i'; indexname = - psync_strcat(cachepath, "/", fileidhex, NULL); + putil_strcat(cachepath, "/", fileidhex, NULL); fd = pfile_open(indexname, O_RDONLY, 0); if (unlikely(fd == INVALID_HANDLE_VALUE)) { pdbg_logf(D_ERROR, @@ -3630,7 +3630,7 @@ static void psync_pagecache_modify_to_cache(uint64_t taskid, uint64_t hash, } tree = NULL; if (pdbg_unlikely((fs = pfile_size(fd)) == -1 || - psync_fs_load_interval_tree(fd, fs, &tree) == -1)) + pfs_load_interval_tree(fd, fs, &tree) == -1)) goto err2; pfile_close(fd); fd = pfile_open(filename, O_RDONLY, 0); @@ -3867,7 +3867,7 @@ static void psync_pagecache_upload_to_cache() { psql_run_free(res); psql_commit(); if (wake) - psync_fsupload_wake(); + pfs_upld_wake(); psync_pagecache_check_free_space(); } } @@ -4109,7 +4109,7 @@ void ppagecache_init() { if (stat(cache_dir, &st)) { mkdir(cache_dir, PSYNC_DEFAULT_POSIX_FOLDER_MODE); } - cache_file = psync_strcat(cache_dir, "/", + cache_file = putil_strcat(cache_dir, "/", PSYNC_DEFAULT_READ_CACHE_FILE, NULL); if (stat(cache_file, &st)) psql_statement("DELETE FROM pagecache"); @@ -4192,7 +4192,7 @@ void ppagecache_reopen_read() { if (stat(cache_dir, &st)) { mkdir(cache_dir, PSYNC_DEFAULT_POSIX_FOLDER_MODE); } - cache_file = psync_strcat(cache_dir, "/", + cache_file = putil_strcat(cache_dir, "/", PSYNC_DEFAULT_READ_CACHE_FILE, NULL); readcache = pfile_open(cache_file, O_RDWR, O_CREAT); free(cache_file); @@ -4240,7 +4240,7 @@ int ppagecache_move(const char *path) { int newrdcache, ordcache; uint32_t i, cnt; pdbg_logf(D_NOTICE, "start"); - rdpath = psync_strcat(path, "/", + rdpath = putil_strcat(path, "/", PSYNC_DEFAULT_READ_CACHE_FILE, NULL); if (!stat(rdpath, &st)) { free(rdpath); @@ -4251,7 +4251,7 @@ int ppagecache_move(const char *path) { free(rdpath); return pdbg_return_const(PERROR_CACHE_MOVE_NO_WRITE_ACCESS); } - opath = psync_strdup(psync_setting_get_string(_PS(fscachepath))); + opath = putil_strdup(psync_setting_get_string(_PS(fscachepath))); pthread_mutex_lock(&clean_cache_mutex); pthread_mutex_lock(&flush_cache_mutex); psql_start(); diff --git a/pclsync/ppath.c b/pclsync/ppath.c index 2669fe6..5d0c601 100644 --- a/pclsync/ppath.c +++ b/pclsync/ppath.c @@ -20,13 +20,13 @@ char *ppath_default_db() { return NULL; } - dbp = psync_strcat(pcdir, "/", PSYNC_DEFAULT_DB_NAME, NULL); + dbp = putil_strcat(pcdir, "/", PSYNC_DEFAULT_DB_NAME, NULL); free(pcdir); if (stat(dbp, &st)) { // Inline the old database path function here if ((home = ppath_home())) { - oldp = psync_strcat(home, "/", PSYNC_DEFAULT_POSIX_DBNAME, NULL); + oldp = putil_strcat(home, "/", PSYNC_DEFAULT_POSIX_DBNAME, NULL); free(home); if (oldp) { @@ -69,7 +69,7 @@ char *ppath_home() { return NULL; dir = result->pw_dir; } - return psync_strdup(dir); + return putil_strdup(dir); } int ppath_ls(const char *path, ppath_ls_cb callback, void *ptr) { @@ -100,7 +100,7 @@ int ppath_ls(const char *path, ppath_ls_cb callback, void *ptr) { (de->d_name[1] == 0 || (de->d_name[1] == '.' && de->d_name[2] == 0))) continue; - psync_strlcpy(cpath + pl, de->d_name, NAME_MAX + 1); + putil_strlcpy(cpath + pl, de->d_name, NAME_MAX + 1); if (pdbg_likely(!lstat(cpath, &pst.stat)) && (S_ISREG(pst.stat.st_mode) || S_ISDIR(pst.stat.st_mode))) { @@ -150,7 +150,7 @@ int ppath_ls_fast(const char *path, ppath_ls_fast_cb callback, void *ptr) { callback(ptr, &pst); } else if (de->d_type == DT_UNKNOWN) { // Fall back to lstat for unknown file types - psync_strlcpy(cpath + pl, de->d_name, NAME_MAX + 1); + putil_strlcpy(cpath + pl, de->d_name, NAME_MAX + 1); if (!pdbg_unlikely(lstat(cpath, &st))) { pst.isfolder = S_ISDIR(st.st_mode); callback(ptr, &pst); @@ -172,7 +172,7 @@ char *ppath_pcloud() { return NULL; } - path = psync_strcat(homedir, "/", PSYNC_DEFAULT_POSIX_DIR, NULL); + path = putil_strcat(homedir, "/", PSYNC_DEFAULT_POSIX_DIR, NULL); free(homedir); if (pdbg_unlikely(!path)) { return NULL; @@ -192,7 +192,7 @@ char *ppath_private(char *name) { path = ppath_pcloud(); if (!path) return NULL; - rpath = psync_strcat(path, "/", name, NULL); + rpath = putil_strcat(path, "/", name, NULL); if (stat(rpath, &st) && mkdir(path, PSYNC_DEFAULT_POSIX_FOLDER_MODE)) { free(rpath); free(path); diff --git a/pclsync/ppathstatus.c b/pclsync/ppathstatus.c index 3468749..a38f983 100644 --- a/pclsync/ppathstatus.c +++ b/pclsync/ppathstatus.c @@ -339,7 +339,7 @@ void ppathstatus_drive_fldr_changed(psync_folderid_t folderid) { folder_tasks_t *ft; int changed; psql_lock(); - folder = psync_fstask_get_folder_tasks_rdlocked(folderid); + folder = pfs_task_get_folder_tasks_rdlocked(folderid); changed = folder && (folder->creats || folder->mkdirs); ft = get_folder_tasks(folderid, changed); if ((!changed && (!ft || ft->child_task_cnt)) || @@ -931,7 +931,7 @@ restart: if (off && is_slash(path[off - 1])) { poff = off + 1; } else { - folder = psync_fstask_get_folder_tasks_rdlocked(folderid); + folder = pfs_task_get_folder_tasks_rdlocked(folderid); if (folder) { if (unlikely(off - poff >= sizeof(buff))) return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC); @@ -943,9 +943,9 @@ restart: path + poff, off - poff))) return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC); } - if (psync_fstask_find_mkdir(folder, buff, 0)) + if (pfs_task_find_mkdir(folder, buff, 0)) return rdunlock_return_in_prog(); - if (psync_fstask_find_rmdir(folder, buff, 0)) + if (pfs_task_find_rmdir(folder, buff, 0)) return rdunlock_return(PSYNC_PATH_STATUS_NOT_FOUND); } comp_hash(path + poff, off - poff, hash, folderid, drv_hash_seed); @@ -1016,7 +1016,7 @@ restart: } if (poff == path_len) return psync_path_status_drive_folder_locked(folderid); - folder = psync_fstask_get_folder_tasks_rdlocked(folderid); + folder = pfs_task_get_folder_tasks_rdlocked(folderid); name = path + poff; namelen = path_len - poff; if (folder) { @@ -1027,9 +1027,9 @@ restart: name = buff; namelen = strlen(buff); } - if (psync_fstask_find_mkdir(folder, name, 0)) + if (pfs_task_find_mkdir(folder, name, 0)) return rdunlock_return_in_prog(); - if (psync_fstask_find_creat(folder, name, 0)) + if (pfs_task_find_creat(folder, name, 0)) return rdunlock_return_in_prog(); } // we do the hash with the unencrypted name @@ -1050,12 +1050,12 @@ restart: } if (found) { if (flags & ENTRY_FLAG_FOLDER) { - if (folder && psync_fstask_find_rmdir(folder, name, 0)) + if (folder && pfs_task_find_rmdir(folder, name, 0)) return rdunlock_return(PSYNC_PATH_STATUS_NOT_FOUND); else return psync_path_status_drive_folder_locked(folderid); } else { - if (folder && psync_fstask_find_unlink(folder, name, 0)) + if (folder && pfs_task_find_unlink(folder, name, 0)) return rdunlock_return(PSYNC_PATH_STATUS_NOT_FOUND); else return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC); @@ -1073,9 +1073,9 @@ restart: psql_bind_uint(res, 1, folderid); psql_bind_lstr(res, 2, name, namelen); row = psql_fetch_int(res); - if (!row || (folder && psync_fstask_find_rmdir(folder, path + poff, 0))) { + if (!row || (folder && pfs_task_find_rmdir(folder, path + poff, 0))) { psql_free(res); - if (folder && psync_fstask_find_unlink(folder, path + poff, 0)) + if (folder && pfs_task_find_unlink(folder, path + poff, 0)) return rdunlock_return(PSYNC_PATH_STATUS_NOT_FOUND); res = psql_query_nolock( "SELECT id FROM file WHERE parentfolderid=? AND name=?"); @@ -1426,7 +1426,7 @@ psync_path_status_t ppathstatus_get(const char *path) { return psync_path_status_drive(path + drive_path_len, len - drive_path_len); } else { - dp = psync_fs_getmountpoint(); + dp = pfs_getmountpoint(); if (dp) { // assign the len before the mutex, so we use it as a barrier drive_path_len = strlen(dp); diff --git a/pclsync/psettings.c b/pclsync/psettings.c index 62b1b89..aca3f05 100644 --- a/pclsync/psettings.c +++ b/pclsync/psettings.c @@ -61,7 +61,7 @@ typedef struct { static void lower_patterns(void *ptr); -static void fsroot_change() { psync_fs_remount(); } +static void fsroot_change() { pfs_remount(); } #define PSYNC_SETTING_owneremail 16 @@ -117,11 +117,11 @@ void psync_settings_reset() { char *home, *defaultfs, *defaultcache; psync_settingid_t i; home = ppath_home(); - defaultfs = psync_strcat(home, "/", + defaultfs = putil_strcat(home, "/", PSYNC_DEFAULT_FS_FOLDER, NULL); free(home); home = ppath_pcloud(); - defaultcache = psync_strcat(home, "/", + defaultcache = putil_strcat(home, "/", PSYNC_DEFAULT_CACHE_FOLDER, NULL); free(home); for (i = 0; i < ARRAY_SIZE(settings); i++) @@ -151,7 +151,7 @@ void psync_settings_reset() { settings[_PS(ignorepaths)].str = PSYNC_IGNORE_PATHS_DEFAULT; for (i = 0; i < ARRAY_SIZE(settings); i++) { if (settings[i].type == PSYNC_TSTRING) { - settings[i].str = psync_strdup(settings[i].str); + settings[i].str = putil_strdup(settings[i].str); if (settings[i].fix_callback) settings[i].fix_callback(&settings[i].str); } else if (settings[i].fix_callback) { @@ -172,11 +172,11 @@ void psync_settings_init() { char *home, *defaultfs, *defaultcache; psync_settingid_t i; home = ppath_home(); - defaultfs = psync_strcat(home, "/", + defaultfs = putil_strcat(home, "/", PSYNC_DEFAULT_FS_FOLDER, NULL); free(home); home = ppath_pcloud(); - defaultcache = psync_strcat(home, "/", + defaultcache = putil_strcat(home, "/", PSYNC_DEFAULT_CACHE_FOLDER, NULL); free(home); settings[_PS(ignorepatterns)].str = PSYNC_IGNORE_PATTERNS_DEFAULT; @@ -195,7 +195,7 @@ void psync_settings_init() { settings[_PS(ignorepaths)].str = PSYNC_IGNORE_PATHS_DEFAULT; for (i = 0; i < ARRAY_SIZE(settings); i++) { if (settings[i].type == PSYNC_TSTRING) { - settings[i].str = psync_strdup(settings[i].str); + settings[i].str = putil_strdup(settings[i].str); if (settings[i].fix_callback) settings[i].fix_callback(&settings[i].str); } else if (settings[i].fix_callback) { @@ -214,7 +214,7 @@ void psync_settings_init() { if (!strcmp(name, settings[i].name)) { if (settings[i].type == PSYNC_TSTRING) { free(settings[i].str); - settings[i].str = psync_strdup(row[1]); + settings[i].str = putil_strdup(row[1]); if (settings[i].fix_callback) settings[i].fix_callback(&settings[i].str); } else if (settings[i].type == PSYNC_TNUMBER) { @@ -333,7 +333,7 @@ int psync_setting_set_string(psync_settingid_t settingid, const char *value) { char *oldval, *newval; CHECK_SETTINGID_AND_TYPE(-1, PSYNC_TSTRING); oldval = settings[settingid].str; - newval = psync_strdup(value); + newval = putil_strdup(value); if (settings[settingid].fix_callback) settings[settingid].fix_callback(&newval); settings[settingid].str = newval; diff --git a/pclsync/psock.c b/pclsync/psock.c index e8e153a..7ee97ce 100644 --- a/pclsync/psock.c +++ b/pclsync/psock.c @@ -461,7 +461,7 @@ psock_t *psock_connect(const char *host, int unsigned port, int ssl) { void *sslc; int sock; char sport[8]; - psync_slprintf(sport, sizeof(sport), "%d", port); + putil_slprintf(sport, sizeof(sport), "%d", port); sock = connect_socket(host, sport); if (pdbg_unlikely(sock == INVALID_SOCKET)) { diff --git a/pclsync/psql.c b/pclsync/psql.c index fc1e02b..5cc738c 100644 --- a/pclsync/psql.c +++ b/pclsync/psql.c @@ -199,7 +199,7 @@ void psql_dump_locks() { rd_lock_data *lock; char dttime[36]; if (wrlocked) { - time_format(lockstart.tv_sec, lockstart.tv_nsec, dttime); + putil_time_format(lockstart.tv_sec, lockstart.tv_nsec, dttime); pdbg_logf(D_ERROR, "write lock taken by thread %s from %s:%u at %s", wrlockthread, wrlockfile, wrlockline, dttime); sendpdbg_logf("write lock taken by thread %s from %s:%u at %s", wrlockthread, @@ -207,7 +207,7 @@ void psql_dump_locks() { } pthread_mutex_lock(&rdmutex); psync_list_for_each_element(lock, &rdlocks, rd_lock_data, list) { - time_format(lock->tm.tv_sec, lock->tm.tv_nsec, dttime); + putil_time_format(lock->tm.tv_sec, lock->tm.tv_nsec, dttime); pdbg_logf(D_ERROR, "read lock taken by thread %s from %s:%u at %s", lock->thread, lock->file, lock->line, dttime); sendpdbg_logf("read lock taken by thread %s from %s:%u at %s", lock->thread, @@ -628,7 +628,7 @@ char *psql_cellstr(const char *sql) { char *ret; ret = (char *)sqlite3_column_text(stmt, 0); if (ret) - ret = psync_strdup(ret); + ret = putil_strdup(ret); sqlite3_finalize(stmt); psql_rdunlock(); return ret; diff --git a/pclsync/pssl.c b/pclsync/pssl.c index 1398724..172070e 100644 --- a/pclsync/pssl.c +++ b/pclsync/pssl.c @@ -704,7 +704,7 @@ char *psymkey_derive(const char *username, mbedtls_pkcs5_pbkdf2_hmac(&ctx, (const unsigned char *)passphrase, strlen(passphrase), usersha512, PSYNC_SHA512_DIGEST_LEN, 5000, sizeof(passwordbin), passwordbin); mbedtls_md_free(&ctx); - usercopy = psync_base64_encode(passwordbin, sizeof(passwordbin), &userlen); + usercopy = putil_base64_encode(passwordbin, sizeof(passwordbin), &userlen); return (char *)usercopy; } diff --git a/pclsync/pstatus.c b/pclsync/pstatus.c index 1b5ec78..e26f9b4 100644 --- a/pclsync/pstatus.c +++ b/pclsync/pstatus.c @@ -218,7 +218,7 @@ void pstatus_upload_recalc() { fileidhex[sizeof(psync_fsfileid_t)] = 'd'; fileidhex[sizeof(psync_fsfileid_t) + 1] = 0; filename = - psync_strcat(fscpath, "/", fileidhex, NULL); + putil_strcat(fscpath, "/", fileidhex, NULL); if (!stat(filename, &st)) { filestou++; bytestou += pfile_stat_size(&st); diff --git a/pclsync/psuggest.c b/pclsync/psuggest.c index 8806a88..ca01908 100644 --- a/pclsync/psuggest.c +++ b/pclsync/psuggest.c @@ -222,7 +222,7 @@ psuggested_folders_t *psuggest_scan_folder(const char *path) { qsort(scnt, PSYNC_SCAN_TYPES_CNT, sizeof(scnt[0]), sort_comp_tuple_rev); for (i = 0; i < PSYNC_SCAN_TYPES_CNT; i++) if (scnt[i][1] && scnt[i][0] >= PSYNC_SCANNER_MIN_DISPLAY) { - off += psync_slprintf(buff + off, sizeof(buff) - off, "%u %s, ", + off += putil_slprintf(buff + off, sizeof(buff) - off, "%u %s, ", (unsigned)scnt[i][0], psync_scan_typenames[scnt[i][1]]); if (off >= sizeof(buff)) diff --git a/pclsync/psyncer.c b/pclsync/psyncer.c index d7f6d3d..a71d976 100644 --- a/pclsync/psyncer.c +++ b/pclsync/psyncer.c @@ -192,7 +192,7 @@ psync_folderid_t psyncer_db_folder_create( for (ptr = name; *ptr; ptr++) if (pfile_invalid_chars[(unsigned char)*ptr]) { if (!vname) - vname = psync_strdup(name); + vname = putil_strdup(name); vname[ptr - name] = '_'; } if (vname) @@ -307,7 +307,7 @@ static void psync_sync_newsyncedfolder(psync_syncid_t syncid) { folderid = psync_get_number(row[0]); synctype = psync_get_number(row[1]); localpath = - psync_strndup(psync_get_string(row[2]), strlen(psync_get_string(row[2]))); + putil_strndup(psync_get_string(row[2]), strlen(psync_get_string(row[2]))); psql_free(res); if (synctype & PSYNC_DOWNLOAD_ONLY) { psyncer_dl_folder_add(syncid, synctype, folderid, 0); @@ -463,8 +463,8 @@ re: continue; } - localpath = psync_strdup(localpath); - remotepath = psync_strdup(remotepath); + localpath = putil_strdup(localpath); + remotepath = putil_strdup(remotepath); psql_free(res); folderid = pfolder_id_create(remotepath); diff --git a/pclsync/psynclib.c b/pclsync/psynclib.c index b38437c..a31b7ec 100644 --- a/pclsync/psynclib.c +++ b/pclsync/psynclib.c @@ -112,7 +112,7 @@ static inline int psync_status_is_offline() { uint32_t psync_get_last_error() { return psync_error; } void psync_set_database_path(const char *databasepath) { - psync_database = psync_strdup(databasepath); + psync_database = putil_strdup(databasepath); } static void psync_stop_crypto_on_sleep() { @@ -235,7 +235,7 @@ void psync_start_sync(pstatus_change_callback_t status_callback, psync_localscan_init(); pp2p_init(); if (psync_setting_get_bool(_PS(autostartfs))) - psync_fs_start(); + pfs_start(); pdevmon_init(); } @@ -255,7 +255,7 @@ void psync_destroy() { if (pshm_cleanup() == -1) { pdbg_logf(D_ERROR, "failed to cleanup shm"); } - psync_fs_stop(); + pfs_stop(); pstatus_wait_term(); pstatus_send_status_update(); ptask_stop_async(); @@ -288,10 +288,10 @@ void psync_set_user_pass(const char *username, const char *password, int save) { } else { pthread_mutex_lock(&psync_my_auth_mutex); free(psync_my_user); - psync_my_user = psync_strdup(username); + psync_my_user = putil_strdup(username); free(psync_my_pass); if (password && password[0]) - psync_my_pass = psync_strdup(password); + psync_my_pass = putil_strdup(password); pthread_mutex_unlock(&psync_my_auth_mutex); } pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED); @@ -305,7 +305,7 @@ void psync_set_pass(const char *password, int save) { else { pthread_mutex_lock(&psync_my_auth_mutex); free(psync_my_pass); - psync_my_pass = psync_strdup(password); + psync_my_pass = putil_strdup(password); pthread_mutex_unlock(&psync_my_auth_mutex); } pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED); @@ -316,7 +316,7 @@ void psync_set_auth(const char *auth, int save) { if (save) psync_set_string_value("auth", auth); else - psync_strlcpy(psync_my_auth, auth, sizeof(psync_my_auth)); + putil_strlcpy(psync_my_auth, auth, sizeof(psync_my_auth)); pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED); } @@ -350,7 +350,7 @@ void psync_logout(uint32_t auth_status, int doinvauth) { pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING); pstatus_set(PSTATUS_TYPE_AUTH, auth_status); - psync_fs_pause_until_login(); + pfs_pause_until_login(); pdownload_stop_all(); pupload_stop_all(); ptask_stop_async(); @@ -358,8 +358,8 @@ void psync_logout(uint32_t auth_status, int doinvauth) { psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT); psync_restart_localscan(); ptimer_notify_exception(); - if (psync_fs_need_per_folder_refresh()) { - psync_fs_refresh_folder(0); + if (pfs_need_per_folder_refresh()) { + pfs_refresh_folder(0); } } @@ -380,7 +380,7 @@ apiservers_list_t *psync_get_apiservers(char **err) { if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't get api from the pool. No pool ?\n"); - *err = psync_strndup("Can't get api from the pool.", 29); + *err = putil_strndup("Can't get api from the pool.", 29); return NULL; } bres = papi_send2(api, "getlocationapi", params); @@ -389,13 +389,13 @@ apiservers_list_t *psync_get_apiservers(char **err) { else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned invalid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command getlocationapi returned error code %u", (unsigned)result); return NULL; @@ -492,8 +492,8 @@ void psync_unlink() { pthread_mutex_unlock(&psync_my_auth_mutex); pdbg_logf(D_NOTICE, "clearing database, finished"); - psync_fs_pause_until_login(); - psync_fs_clean_tasks(); + pfs_pause_until_login(); + pfs_clean_tasks(); ppathstatus_init(); psyncer_dl_queue_clear(); psql_unlock(); @@ -508,8 +508,8 @@ void psync_unlink() { pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED); pstatus_set(PSTATUS_TYPE_RUN, PSTATUS_RUN_RUN); psync_resume_localscan(); - if (psync_fs_need_per_folder_refresh()) { - psync_fs_refresh_folder(0); + if (pfs_need_per_folder_refresh()) { + pfs_refresh_folder(0); } } @@ -529,9 +529,9 @@ static void check_tfa_result(uint64_t result) { static char *binresult_to_str(const binresult *res) { if (!res) - return psync_strdup("field not found"); + return putil_strdup("field not found"); if (res->type == PARAM_STR) - return psync_strdup(res->str); + return putil_strdup(res->str); else if (res->type == PARAM_NUM) { char buff[32], *ptr; uint64_t n; @@ -542,9 +542,9 @@ static char *binresult_to_str(const binresult *res) { *--ptr = '0' + n % 10; n /= 10; } while (n); - return psync_strdup(ptr); + return putil_strdup(ptr); } else { - return psync_strdup("bad field type"); + return putil_strdup("bad field type"); } } @@ -905,7 +905,7 @@ static int do_run_command_get_res(const char *cmd, size_t cmdlen, if (result) { pdbg_logf(D_WARNING, "command %s returned code %u", cmd, (unsigned)result); if (err) - *err = psync_strdup(papi_find_result2(res, "error", PARAM_STR)->str); + *err = putil_strdup(papi_find_result2(res, "error", PARAM_STR)->str); psync_process_api_error(result); } if (result) @@ -915,7 +915,7 @@ static int do_run_command_get_res(const char *cmd, size_t cmdlen, return (int)result; neterr: if (err) - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); return -1; } @@ -931,14 +931,14 @@ int psync_register(const char *email, const char *password, int termsaccepted, psync_set_apiserver(binapi, locationid); else { if (err) - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT); return -1; } sock = papi_connect(binapi, psync_setting_get_bool(_PS(usessl))); if (pdbg_unlikely(!sock)) { if (err) - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT); return -1; } @@ -946,7 +946,7 @@ int psync_register(const char *email, const char *password, int termsaccepted, if (pdbg_unlikely(!res)) { psock_close(sock); if (err) - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT); return -1; } @@ -954,7 +954,7 @@ int psync_register(const char *email, const char *password, int termsaccepted, if (result) { pdbg_logf(D_WARNING, "command register returned code %u", (unsigned)result); if (err) - *err = psync_strdup(papi_find_result2(res, "error", PARAM_STR)->str); + *err = putil_strdup(papi_find_result2(res, "error", PARAM_STR)->str); psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT); } psock_close(sock); @@ -993,7 +993,7 @@ int psync_change_password(const char *currentpass, const char *newpass, free(device); if (ret) return ret; - psync_strlcpy(psync_my_auth, papi_find_result2(res, "auth", PARAM_STR)->str, + putil_strlcpy(psync_my_auth, papi_find_result2(res, "auth", PARAM_STR)->str, sizeof(psync_my_auth)); free(res); return 0; @@ -1130,7 +1130,7 @@ char *psync_get_string_value(const char *valuename) { psql_bind_str(res, 1, valuename); row = psql_fetch_str(res); if (row) - ret = psync_strdup(row[0]); + ret = putil_strdup(row[0]); else ret = NULL; psql_free(res); @@ -1495,7 +1495,7 @@ static void psync_del_all_except(void *ptr, ppath_fast_stat *st) { nmarr = (const char **)ptr; if (!strcmp(st->name, nmarr[1]) || pfile_stat_fast_isfolder(st)) return; - fp = psync_strcat(nmarr[0], "/", st->name, NULL); + fp = putil_strcat(nmarr[0], "/", st->name, NULL); pdbg_logf(D_NOTICE, "deleting old update file %s", fp); if (pfile_delete(fp)) pdbg_logf(D_WARNING, "could not delete %s", fp); @@ -1516,7 +1516,7 @@ static char *psync_filename_from_res(const binresult *res) { nmarr[0] = path; nmarr[1] = nmd; ppath_ls_fast(path, psync_del_all_except, (void *)nmarr); - ret = psync_strcat(path, "/", nmd, NULL); + ret = putil_strcat(path, "/", nmd, NULL); free(nmd); free(path); return ret; @@ -2097,15 +2097,15 @@ int psync_setlanguage(const char *language, char **err) { return psync_run_command("setlanguage", params, err); } -void psync_fs_clean_read_cache() { ppagecache_clean_read(); } +void pfs_clean_read_cache() { ppagecache_clean_read(); } -int psync_fs_move_cache(const char *path) { +int pfs_move_cache(const char *path) { return ppagecache_move(path); } char *psync_get_token() { if (psync_my_auth[0]) - return psync_strdup(psync_my_auth); + return putil_strdup(psync_my_auth); else return NULL; } @@ -2136,7 +2136,7 @@ int psync_get_promo(char **url, uint64_t *width, uint64_t *height) { return result; } - *url = psync_strdup(papi_find_result2(res, "url", PARAM_STR)->str); + *url = putil_strdup(papi_find_result2(res, "url", PARAM_STR)->str); if (!papi_find_result2(res, "width", PARAM_NUM)->num) { pdbg_logf(D_NOTICE, "Parameter width not found."); @@ -2166,12 +2166,12 @@ int psync_get_promo(char **url, uint64_t *width, uint64_t *height) { psync_folderid_t psync_get_fsfolderid_by_path(const char *path, uint32_t *pflags, uint32_t *pPerm) { - return psync_fsfolderidperm_by_path(path, pflags, pPerm); + return pfs_fldr_idperm_by_path(path, pflags, pPerm); } uint32_t psync_get_fsfolderflags_by_id(psync_folderid_t folderid, uint32_t *pPerm) { - return psync_fsfolderflags_by_id(folderid, pPerm); + return pfs_fldr_flags_by_id(folderid, pPerm); } uint64_t psync_crypto_priv_key_flags() { @@ -2241,13 +2241,13 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) { if (psyncer_str_has_prefix(srow[0], localPath)) { psql_free(sql); - *errMsg = psync_strdup("There is already an active sync or backup for a " + *errMsg = putil_strdup("There is already an active sync or backup for a " "parent of this folder."); return PERROR_PARENT_OR_SUBFOLDER_ALREADY_SYNCING; } else if (!strcmp(srow[0], localPath)) { psql_free(sql); - *errMsg = psync_strdup( + *errMsg = putil_strdup( "There is already an active sync or backup for this folder."); return PERROR_FOLDER_ALREADY_SYNCING; } @@ -2256,7 +2256,7 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) { pdbg_logf(D_NOTICE, "Check if folder is not on the Drive."); - syncmp = psync_fs_getmountpoint(); + syncmp = pfs_getmountpoint(); pdbg_logf(D_NOTICE, "Mount point: [%s].", syncmp); if (syncmp) { @@ -2268,7 +2268,7 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) { localPath[len] == '\\')) { free(syncmp); - *errMsg = psync_strdup("Folder is located on pCloud drive."); + *errMsg = putil_strdup("Folder is located on pCloud drive."); return PERROR_LOCAL_IS_ON_PDRIVE; } free(syncmp); @@ -2283,7 +2283,7 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) { localPath); if (psyncer_str_starts_with(folders.folders[i], localPath)) { - *errMsg = psync_strdup( + *errMsg = putil_strdup( "This folder is a child of a folder in your ignore folders list."); return PERROR_PARENT_IS_IGNORED; } @@ -2304,7 +2304,7 @@ psync_folderid_t create_bup_mach_folder(char **msgErr) { rootFolIdObj = NULL; tmpBuff = get_pc_name(); - psync_strlcpy(bRootFoName, tmpBuff, 64); + putil_strlcpy(bRootFoName, tmpBuff, 64); free(tmpBuff); @@ -2377,10 +2377,10 @@ int psync_create_backup(char *path, char **errMsg) { if (folders.cnt > 1) { oParCnt = 1; - optFolName = psync_strdup(folders.folders[folders.cnt - 2]); + optFolName = putil_strdup(folders.folders[folders.cnt - 2]); } else { oParCnt = 0; - optFolName = psync_strdup(""); + optFolName = putil_strdup(""); } eventParams reqPar = {4, // Number of parameters we are passing below. @@ -2406,7 +2406,7 @@ int psync_create_backup(char *path, char **errMsg) { free(retData); if (syncFId < 0) { - *errMsg = psync_strdup("Error creating backup."); + *errMsg = putil_strdup("Error creating backup."); return syncFId; } diff --git a/pclsync/psynclib.h b/pclsync/psynclib.h index e8700d1..7111093 100644 --- a/pclsync/psynclib.h +++ b/pclsync/psynclib.h @@ -1118,13 +1118,13 @@ int psync_upload_file_as(const char *remote_path, const char *remote_filename, /* Filesystem functions. * - * psync_fs_start() - starts the filesystem - * psync_fs_isstarted() - returns 1 if the filesystem is started and 0 otherwise - * psync_fs_stop() - stops the filesystem - * psync_fs_getmountpoint() - returns current mountpoint of the filesystem, or + * pfs_start() - starts the filesystem + * pfs_isstarted() - returns 1 if the filesystem is started and 0 otherwise + * pfs_stop() - stops the filesystem + * pfs_getmountpoint() - returns current mountpoint of the filesystem, or * NULL if the filesystem is not mounted, you are supposed to free the returned - * pointer psync_fs_register_start_callback() - registers a callback that will - * be called once the drive is started psync_fs_get_path_by_folderid() - returns + * pointer pfs_register_start_callback() - registers a callback that will + * be called once the drive is started pfs_get_path_by_folderid() - returns * full path (including mountpoint) of a given folderid on the filesystem or * NULL if it is not mounted or folder could not be * found. You are supposed to free the returned pointer. @@ -1132,7 +1132,7 @@ int psync_upload_file_as(const char *remote_path, const char *remote_filename, * fileid on the filesystem or NULL if it is not mounted or parent folder could * not be found. You are supposed to free the returned pointer. * - * psync_fs_clean_read_cache() - cleans the filesystem read cache. This function + * pfs_clean_read_cache() - cleans the filesystem read cache. This function * does not fail. The general expectation is that the function takes some * moderate time to execute - maybe 0.5-2 seconds depending on the system and * it's load. In the unlikely case of cache flush or cache garbage collection @@ -1141,9 +1141,9 @@ int psync_upload_file_as(const char *remote_path, const char *remote_filename, * filesystem operations will hang and wait for the process to finish, so please * design the UI accordingly. * - * psync_fs_move_cache() - cleans filesystem read cache and moves both read + * pfs_move_cache() - cleans filesystem read cache and moves both read * cache and write queue to specified directory. The function has the same - * overall complexity as psync_fs_clean_read_cache(). Returns 0 on success, + * overall complexity as pfs_clean_read_cache(). Returns 0 on success, * PERROR_CACHE_MOVE_NOT_EMPTY if the target directory already has a read cache * file in it, PERROR_CACHE_MOVE_NO_WRITE_ACCESS if request to open a file for * writing in the provided directory fails or PERROR_CACHE_MOVE_DRIVE_HAS_TASKS @@ -1152,16 +1152,16 @@ int psync_upload_file_as(const char *remote_path, const char *remote_filename, * */ -int psync_fs_start(); -int psync_fs_isstarted(); -void psync_fs_stop(); -char *psync_fs_getmountpoint(); -void psync_fs_register_start_callback(psync_generic_callback_t callback); -char *psync_fs_get_path_by_folderid(psync_folderid_t folderid); -char *psync_fs_get_path_by_fileid(psync_fileid_t fileid); +int pfs_start(); +int pfs_isstarted(); +void pfs_stop(); +char *pfs_getmountpoint(); +void pfs_register_start_callback(psync_generic_callback_t callback); +char *pfs_get_path_by_folderid(psync_folderid_t folderid); +char *pfs_get_path_by_fileid(psync_fileid_t fileid); -void psync_fs_clean_read_cache(); -int psync_fs_move_cache(const char *path); +void pfs_clean_read_cache(); +int pfs_move_cache(const char *path); /* psync_password_quality estimates password quality, returns one of: * 0 - weak diff --git a/pclsync/ptask.c b/pclsync/ptask.c index 7fde0a9..8fe2869 100644 --- a/pclsync/ptask.c +++ b/pclsync/ptask.c @@ -457,7 +457,7 @@ static int handle_download(async_params_t *prms, s->process_data = download_process_headers; fda->localpath = dwl->localpath; fda->fd = INVALID_HANDLE_VALUE; - len = psync_slprintf(buff, sizeof(buff), + len = putil_slprintf(buff, sizeof(buff), "act=dwl,strm=%" PRIu64 ",fileid=%" PRIu64 "\n", (uint64_t)s->streamid, (uint64_t)dwl->fileid); if (data_send(prms, buff, len)) { @@ -488,7 +488,7 @@ static int handle_download_nm(async_params_t *prms, memcpy(fda->osha1hex, dwl->sha1hex, PSYNC_SHA1_DIGEST_HEXLEN); fda->localpath = dwl->localpath; fda->fd = INVALID_HANDLE_VALUE; - len = psync_slprintf( + len = putil_slprintf( buff, sizeof(buff), "act=dwlnm,strm=%" PRIu64 ",fileid=%" PRIu64 ",sha1=%.40s\n", (uint64_t)s->streamid, (uint64_t)dwl->fileid, dwl->sha1hex); diff --git a/pclsync/ptools.c b/pclsync/ptools.c index ada94b2..f70e2f7 100644 --- a/pclsync/ptools.c +++ b/pclsync/ptools.c @@ -76,10 +76,10 @@ char *ptools_get_mac_addr() { buffer[12] = 0; if (buffer[0] == 0) { - return psync_strdup("GENERIC_MAC"); + return putil_strdup("GENERIC_MAC"); } else { - return psync_strdup(buffer); + return putil_strdup(buffer); } } @@ -102,7 +102,7 @@ int ptools_create_backend_event(const char *binapi, const char *category, if (pdbg_unlikely(!sock)) { if (err) { - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); } return -1; @@ -189,7 +189,7 @@ int ptools_create_backend_event(const char *binapi, const char *category, psock_close(sock); if (err) { - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); } return -1; @@ -201,7 +201,7 @@ int ptools_create_backend_event(const char *binapi, const char *category, if (result) { if (err) { - *err = psync_strdup(papi_find_result2(res, "error", PARAM_STR)->str); + *err = putil_strdup(papi_find_result2(res, "error", PARAM_STR)->str); } pdbg_logf(D_CRITICAL, "Event command failed. Error:[%s]", *err); @@ -298,7 +298,7 @@ int ptools_backend_call(const char *binapi, const char *wsPath, if (pdbg_unlikely(!sock)) { if (err) { - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); } return -1; @@ -313,7 +313,7 @@ int ptools_backend_call(const char *binapi, const char *wsPath, psock_close(sock); if (err) { - *err = psync_strdup("Could not connect to the server."); + *err = putil_strdup("Could not connect to the server."); } return -1; @@ -325,7 +325,7 @@ int ptools_backend_call(const char *binapi, const char *wsPath, if (result) { if (err) { - *err = psync_strdup(papi_find_result2(res, "error", PARAM_STR)->str); + *err = putil_strdup(papi_find_result2(res, "error", PARAM_STR)->str); } pdbg_logf(D_CRITICAL, "Backend command failed. Error:[%s]", *err); @@ -353,7 +353,7 @@ char *ptools_get_machine_name() { strcpy(pcName, "LinuxMachine"); } - return psync_strdup(pcName); + return putil_strdup(pcName); } void ptools_parse_os_path(char *path, folderPath *folders, char *delim, int mode) { @@ -371,8 +371,8 @@ void ptools_parse_os_path(char *path, folderPath *folders, char *delim, int mode // In case we meet a ":" as in C:\ we set the name to Drive + the string // before the ":" fName[k] = '\0'; - buff = psync_strcat("Drive ", &fName, NULL); - psync_strlcpy(fName, buff, strlen(buff) + 1); + buff = putil_strcat("Drive ", &fName, NULL); + putil_strlcpy(fName, buff, strlen(buff) + 1); k = k + strlen("Drive "); } else { @@ -381,7 +381,7 @@ void ptools_parse_os_path(char *path, folderPath *folders, char *delim, int mode } } else { fName[k] = 0; - folders->folders[j] = psync_strdup(fName); + folders->folders[j] = putil_strdup(fName); k = 0; j++; @@ -393,7 +393,7 @@ void ptools_parse_os_path(char *path, folderPath *folders, char *delim, int mode fName[k] = 0; if (strlen(fName) > 0) { - folders->folders[j] = psync_strdup(fName); + folders->folders[j] = putil_strdup(fName); j++; } diff --git a/pclsync/publiclinks.c b/pclsync/publiclinks.c index 22f2073..50119db 100644 --- a/pclsync/publiclinks.c +++ b/pclsync/publiclinks.c @@ -143,7 +143,7 @@ int64_t do_psync_file_public_link(const char *path, int64_t *plinkid, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return 2; } @@ -165,7 +165,7 @@ int64_t do_psync_file_public_link(const char *path, int64_t *plinkid, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); free(t); return 1; } @@ -179,13 +179,13 @@ int64_t do_psync_file_public_link(const char *path, int64_t *plinkid, else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return 2; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command getfilepublink returned error code %u", (unsigned)result); psync_process_api_error(result); @@ -194,7 +194,7 @@ int64_t do_psync_file_public_link(const char *path, int64_t *plinkid, } rescode = papi_find_result2(bres, "link", PARAM_STR)->str; - *link = psync_strndup(rescode, strlen(rescode)); + *link = putil_strndup(rescode, strlen(rescode)); linkid = papi_find_result2(bres, "linkid", PARAM_NUM)->num; if (plinkid) *plinkid = linkid; @@ -221,7 +221,7 @@ int64_t do_psync_folder_public_link(const char *path, char **link /*OUT*/, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send2(api, "getfolderpublink", params); @@ -242,7 +242,7 @@ int64_t do_psync_folder_public_link(const char *path, char **link /*OUT*/, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send(api, "getfolderpublink", @@ -259,19 +259,19 @@ int64_t do_psync_folder_public_link(const char *path, char **link /*OUT*/, result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command getfilepublink returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } rescode = papi_find_result2(bres, "link", PARAM_STR)->str; - *link = psync_strndup(rescode, strlen(rescode)); + *link = putil_strndup(rescode, strlen(rescode)); result = papi_find_result2(bres, "linkid", PARAM_NUM)->num; free(bres); @@ -295,7 +295,7 @@ int64_t do_psync_folder_public_link_full(const char *path, char **link /*OUT*/, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send2(api, "getfolderpublink", params); @@ -318,7 +318,7 @@ int64_t do_psync_folder_public_link_full(const char *path, char **link /*OUT*/, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send(api, "getfolderpublink", @@ -336,20 +336,20 @@ int64_t do_psync_folder_public_link_full(const char *path, char **link /*OUT*/, result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command getfilepublink returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } rescode = papi_find_result2(bres, "link", PARAM_STR)->str; - *link = psync_strndup(rescode, strlen(rescode)); + *link = putil_strndup(rescode, strlen(rescode)); result = papi_find_result2(bres, "linkid", PARAM_NUM)->num; free(bres); @@ -371,7 +371,7 @@ int64_t do_psync_folder_updownlink_link(int canupload, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't get api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send2(api, "publink/createfolderlinkandsend", params); @@ -386,7 +386,7 @@ int64_t do_psync_folder_updownlink_link(int canupload, result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command createfolderlinkwithuploadandsend returned error code %u", (unsigned)result); @@ -394,7 +394,7 @@ int64_t do_psync_folder_updownlink_link(int canupload, if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } @@ -439,7 +439,7 @@ int64_t do_ptree_public_link(const char *linkname, const char *root, if (root) { ids = (char *)malloc(FOLDERID_ENTRY_SIZE); - id = psync_fsfolderid_by_path(root, 0); + id = pfs_fldr_id_by_path(root, 0); k = sprintf(ids, "%lld", (long long)id); init_param_str(t + pind++, "folderid", ids); } @@ -448,7 +448,7 @@ int64_t do_ptree_public_link(const char *linkname, const char *root, ids1 = (char *)malloc(numfolders * FOLDERID_ENTRY_SIZE); idsp = ids1; for (i = 0; i < numfolders; ++i) { - id = psync_fsfolderid_by_path(folders[i], 0); + id = pfs_fldr_id_by_path(folders[i], 0); k = sprintf(idsp, "%lld", (long long)id); if (unlikely(k <= 0)) break; @@ -469,7 +469,7 @@ int64_t do_ptree_public_link(const char *linkname, const char *root, idsp = ids2; for (i = 0; i < numfiles; ++i) { psql_rdlock(); - filep = psync_fsfolder_resolve_path(files[i]); + filep = pfs_fldr_resolve_path(files[i]); if (filep) { res = psql_query_nolock("select id from file where parentfolderid " "= ? and name = ? limit 1"); @@ -507,7 +507,7 @@ int64_t do_ptree_public_link(const char *linkname, const char *root, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -519,26 +519,26 @@ int64_t do_ptree_public_link(const char *linkname, const char *root, else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command gettreepublink returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } rescode = papi_find_result2(bres, "link", PARAM_STR)->str; - *link = psync_strndup(rescode, strlen(rescode)); + *link = putil_strndup(rescode, strlen(rescode)); result = papi_find_result2(bres, "linkid", PARAM_NUM)->num; @@ -575,7 +575,7 @@ int cache_links(char *err, size_t err_size /*OUT*/) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - //*err = psync_strndup("Connection error.", 17); + //*err = putil_strndup("Connection error.", 17); snprintf(err, err_size, "Connection error."); return -2; } @@ -588,7 +588,7 @@ int cache_links(char *err, size_t err_size /*OUT*/) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - //*err = psync_strndup("Connection error.", 17); + //*err = putil_strndup("Connection error.", 17); snprintf(err, err_size, "Connection error."); return -2; } @@ -602,7 +602,7 @@ int cache_links(char *err, size_t err_size /*OUT*/) { else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - //*err = psync_strndup("Connection error.", 17); + //*err = putil_strndup("Connection error.", 17); snprintf(err, err_size, "Connection error."); free(bres); return 0; @@ -610,7 +610,7 @@ int cache_links(char *err, size_t err_size /*OUT*/) { result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - //*err = psync_strndup(errorret, strlen(errorret)); + //*err = putil_strndup(errorret, strlen(errorret)); snprintf(err, err_size, "%s", errorret); pdbg_logf(D_WARNING, "command listpublinks returned error code %u", (unsigned)result); @@ -619,7 +619,7 @@ int cache_links(char *err, size_t err_size /*OUT*/) { if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - //*err = psync_strndup("Connection error.", 17); + //*err = putil_strndup("Connection error.", 17); snprintf(err, err_size, "Connection error."); return 0; } @@ -725,7 +725,7 @@ int do_psync_delete_link(int64_t linkid, char **err /*OUT*/) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send2(api, "deletepublink", params); @@ -735,20 +735,20 @@ int do_psync_delete_link(int64_t linkid, char **err /*OUT*/) { else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command deletepublink returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } @@ -765,20 +765,20 @@ int process_bres(const char *cmd, binresult *bres, psock_t *api, else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command %s returned error code %u", cmd, (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } @@ -827,7 +827,7 @@ int do_psync_change_link(unsigned long long linkid, unsigned long long expire, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't get api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send(api, "changepublink", sizeof("changepublink") - 1, t, @@ -847,7 +847,7 @@ int do_change_link_expire(unsigned long long linkid, unsigned long long expire, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -877,7 +877,7 @@ int do_change_link_password(unsigned long long linkid, const char *password, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -906,7 +906,7 @@ int do_change_link_enable_upload(unsigned long long linkid, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } if (enableuploadforeveryone || enableuploadforchosenusers) { @@ -945,7 +945,7 @@ int64_t do_psync_upload_link(const char *path, const char *comment, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -969,7 +969,7 @@ int64_t do_psync_upload_link(const char *path, const char *comment, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send(api, "createuploadlink", @@ -982,26 +982,26 @@ int64_t do_psync_upload_link(const char *path, const char *comment, else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command createuploadlink returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } rescode = papi_find_result2(bres, "link", PARAM_STR)->str; - *link = psync_strndup(rescode, strlen(rescode)); + *link = putil_strndup(rescode, strlen(rescode)); result = papi_find_result2(bres, "uploadlinkid", PARAM_NUM)->num; @@ -1022,7 +1022,7 @@ int do_psync_delete_upload_link(int64_t uploadlinkid, char **err /*OUT*/) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -1126,7 +1126,7 @@ plink_contents_t *do_show_link(const char *code, char **err /*OUT*/) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Can't gat api from the pool.", 29); + *err = putil_strndup("Can't gat api from the pool.", 29); return NULL; } @@ -1137,7 +1137,7 @@ plink_contents_t *do_show_link(const char *code, char **err /*OUT*/) { else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } @@ -1204,7 +1204,7 @@ int cache_upload_links(char **err /*OUT*/) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send2(api, "listuploadlinks", params); @@ -1215,7 +1215,7 @@ int cache_upload_links(char **err /*OUT*/) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } bres = papi_send2(api, "listuploadlinks", params); @@ -1226,20 +1226,20 @@ int cache_upload_links(char **err /*OUT*/) { else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command listpublinks returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return -result; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -1; } } @@ -1415,7 +1415,7 @@ preciever_list_t *do_list_email_with_access(unsigned long long linkid, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } bres = papi_send2(api, "publink/listemailswithaccess", params); @@ -1424,20 +1424,20 @@ preciever_list_t *do_list_email_with_access(unsigned long long linkid, else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command listemailswithaccess returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return NULL; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } } @@ -1484,7 +1484,7 @@ int do_link_add_access(unsigned long long linkid, const char *mail, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -1507,7 +1507,7 @@ int do_link_remove_access(unsigned long long linkid, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -1534,7 +1534,7 @@ bookmarks_list_t *do_cache_bookmarks(char **err) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } @@ -1545,20 +1545,20 @@ bookmarks_list_t *do_cache_bookmarks(char **err) { else { psync_apipool_release_bad(api); pdbg_logf(D_WARNING, "Send command returned in valid result.\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } result = papi_find_result2(bres, "result", PARAM_NUM)->num; if (unlikely(result)) { errorret = papi_find_result2(bres, "error", PARAM_STR)->str; - *err = psync_strndup(errorret, strlen(errorret)); + *err = putil_strndup(errorret, strlen(errorret)); pdbg_logf(D_WARNING, "command deletepublink returned error code %u", (unsigned)result); psync_process_api_error(result); if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL) return NULL; else { - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return NULL; } } @@ -1618,7 +1618,7 @@ int do_remove_bookmark(const char *code, int locationid, char **err) { api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } @@ -1643,7 +1643,7 @@ int do_change_bookmark(const char *code, int locationid, const char *name, api = psync_apipool_get(); if (unlikely(!api)) { pdbg_logf(D_WARNING, "Can't gat api from the pool. No pool ?\n"); - *err = psync_strndup("Connection error.", 17); + *err = putil_strndup("Connection error.", 17); return -2; } diff --git a/pclsync/pupload.c b/pclsync/pupload.c index 2d1bb91..1bded1c 100644 --- a/pclsync/pupload.c +++ b/pclsync/pupload.c @@ -1067,7 +1067,7 @@ static int upload_big_file(const char *localpath, const unsigned char *hashhex, sql = psql_query_rdlock("SELECT name FROM localfile WHERE id=?"); psql_bind_uint(sql, 1, localfileid); if ((srow = psql_fetch_str(sql))) { - char *nname = psync_strdup(srow[0]); + char *nname = putil_strdup(srow[0]); psql_free(sql); pdbg_logf(D_NOTICE, "looking for folderid=%lu and name=%s in file", (unsigned long)folderid, nname); @@ -1463,7 +1463,7 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid, } if (*s1 == *s2) { //==0 pdbg_logf(D_NOTICE, "uploading %s as %s", name, srow[0]); - nname = psync_strdup(srow[0]); + nname = putil_strdup(srow[0]); name = nname; } } diff --git a/pclsync/putil.c b/pclsync/putil.c index 58dad8d..0d56cb3 100644 --- a/pclsync/putil.c +++ b/pclsync/putil.c @@ -14,7 +14,7 @@ static char normalize_table[256]; -const char base64_table[] = { +const char putil_base64_table[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', @@ -73,7 +73,7 @@ void putil_wipe(void *mem, size_t sz) { } } -void time_format(time_t tm, unsigned long ns, char *result) { +void putil_time_format(time_t tm, unsigned long ns, char *result) { static const char month_names[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -117,13 +117,13 @@ void time_format(time_t tm, unsigned long ns, char *result) { memcpy(result, " +0000", 7); // copies the null byte } -char *psync_strdup(const char *str) { +char *putil_strdup(const char *str) { size_t len; len = strlen(str) + 1; return (char *)memcpy(malloc(sizeof(char) * len), str, len); } -char *psync_strnormalize_filename(const char *str) { +char *putil_strnormalize_filename(const char *str) { size_t len, i; char *ptr; len = strlen(str) + 1; @@ -133,14 +133,14 @@ char *psync_strnormalize_filename(const char *str) { return ptr; } -char *psync_strndup(const char *str, size_t len) { +char *putil_strndup(const char *str, size_t len) { char *ptr; ptr = (char *)memcpy(malloc(sizeof(char) * len + 1), str, len); ptr[len] = 0; return ptr; } -char *psync_strcat(const char *str, ...) { +char *putil_strcat(const char *str, ...) { size_t i, size, len; const char *strs[64]; size_t lengths[64]; @@ -170,7 +170,7 @@ char *psync_strcat(const char *str, ...) { return ptr3; } -int psync_slprintf(char *str, size_t size, const char *format, ...) { +int putil_slprintf(char *str, size_t size, const char *format, ...) { va_list ap; int ret; va_start(ap, format); @@ -181,7 +181,7 @@ int psync_slprintf(char *str, size_t size, const char *format, ...) { return ret; } -unsigned char *psync_base32_encode(const unsigned char *str, size_t length, +unsigned char *putil_base32_encode(const unsigned char *str, size_t length, size_t *ret_length) { static const unsigned char *table = (const unsigned char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; @@ -220,7 +220,7 @@ unsigned char *psync_base32_encode(const unsigned char *str, size_t length, return result; } -unsigned char *psync_base32_decode(const unsigned char *str, size_t length, +unsigned char *putil_base32_decode(const unsigned char *str, size_t length, size_t *ret_length) { unsigned char *result, *p; uint32_t bits, buff; @@ -252,7 +252,7 @@ unsigned char *psync_base32_decode(const unsigned char *str, size_t length, return result; } -unsigned char *psync_base64_encode(const unsigned char *str, size_t length, +unsigned char *putil_base64_encode(const unsigned char *str, size_t length, size_t *ret_length) { const unsigned char *current = str; unsigned char *p; @@ -262,22 +262,22 @@ unsigned char *psync_base64_encode(const unsigned char *str, size_t length, p = result; while (length > 2) { - *p++ = base64_table[current[0] >> 2]; - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; - *p++ = base64_table[current[2] & 0x3f]; + *p++ = putil_base64_table[current[0] >> 2]; + *p++ = putil_base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; + *p++ = putil_base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; + *p++ = putil_base64_table[current[2] & 0x3f]; current += 3; length -= 3; } if (length != 0) { - *p++ = base64_table[current[0] >> 2]; + *p++ = putil_base64_table[current[0] >> 2]; if (length > 1) { - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[(current[1] & 0x0f) << 2]; + *p++ = putil_base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; + *p++ = putil_base64_table[(current[1] & 0x0f) << 2]; *p++ = '='; /* Add padding */ } else { - *p++ = base64_table[(current[0] & 0x03) << 4]; + *p++ = putil_base64_table[(current[0] & 0x03) << 4]; *p++ = '='; /* Add padding */ *p++ = '='; /* Add padding */ } @@ -288,7 +288,7 @@ unsigned char *psync_base64_encode(const unsigned char *str, size_t length, return result; } -unsigned char *psync_base64_decode(const unsigned char *str, size_t length, +unsigned char *putil_base64_decode(const unsigned char *str, size_t length, size_t *ret_length) { const unsigned char *current = str; unsigned char *result; @@ -328,7 +328,7 @@ unsigned char *psync_base64_decode(const unsigned char *str, size_t length, return result; } -int psync_is_valid_utf8(const char *str) { +int putil_is_valid_utf8(const char *str) { static const int8_t trailing[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -359,14 +359,14 @@ int psync_is_valid_utf8(const char *str) { return 1; } -uint64_t psync_ato64(const char *str) { +uint64_t putil_ato64(const char *str) { uint64_t n = 0; while (*str >= '0' && *str <= '9') n = n * 10 + (*str++) - '0'; return n; } -uint32_t psync_ato32(const char *str) { +uint32_t putil_ato32(const char *str) { uint32_t n = 0; while (*str >= '0' && *str <= '9') n = n * 10 + (*str++) - '0'; diff --git a/pclsync/putil.h b/pclsync/putil.h index 656e5ae..2823e96 100644 --- a/pclsync/putil.h +++ b/pclsync/putil.h @@ -24,24 +24,24 @@ extern "C" { return PSYNC_INVALID_SYNCID; \ } while (0) -extern const char base64_table[]; +extern const char putil_base64_table[]; void putil_wipe(void *mem, size_t sz); -void time_format(time_t tm, unsigned long ns, char *result); -char *psync_strdup(const char *str) PSYNC_MALLOC PSYNC_NONNULL(1); -char *psync_strnormalize_filename(const char *str) PSYNC_MALLOC PSYNC_NONNULL(1); -char *psync_strndup(const char *str, size_t len) PSYNC_MALLOC PSYNC_NONNULL(1); -char *psync_strcat(const char *str, ...) PSYNC_MALLOC PSYNC_SENTINEL; -int psync_slprintf(char *str, size_t size, const char *format, ...) PSYNC_NONNULL(1, 3); -unsigned char *psync_base32_encode(const unsigned char *str, size_t length, size_t *ret_length); -unsigned char *psync_base32_decode(const unsigned char *str, size_t length, size_t *ret_length); -unsigned char *psync_base64_encode(const unsigned char *str, size_t length, size_t *ret_length); -unsigned char *psync_base64_decode(const unsigned char *str, size_t length, size_t *ret_length); -int psync_is_valid_utf8(const char *str); -uint64_t psync_ato64(const char *str); -uint32_t psync_ato32(const char *str); +void putil_time_format(time_t tm, unsigned long ns, char *result); +char *putil_strdup(const char *str) PSYNC_MALLOC PSYNC_NONNULL(1); +char *putil_strnormalize_filename(const char *str) PSYNC_MALLOC PSYNC_NONNULL(1); +char *putil_strndup(const char *str, size_t len) PSYNC_MALLOC PSYNC_NONNULL(1); +char *putil_strcat(const char *str, ...) PSYNC_MALLOC PSYNC_SENTINEL; +int putil_slprintf(char *str, size_t size, const char *format, ...) PSYNC_NONNULL(1, 3); +unsigned char *putil_base32_encode(const unsigned char *str, size_t length, size_t *ret_length); +unsigned char *putil_base32_decode(const unsigned char *str, size_t length, size_t *ret_length); +unsigned char *putil_base64_encode(const unsigned char *str, size_t length, size_t *ret_length); +unsigned char *putil_base64_decode(const unsigned char *str, size_t length, size_t *ret_length); +int putil_is_valid_utf8(const char *str); +uint64_t putil_ato64(const char *str); +uint32_t putil_ato32(const char *str); -static inline size_t psync_strlcpy(char *dst, const char *src, size_t size) { +static inline size_t putil_strlcpy(char *dst, const char *src, size_t size) { size_t len; len = strlen(src); if (likely(len < size)) { diff --git a/pclsync_lib.cpp b/pclsync_lib.cpp index 464b8db..5a007c1 100644 --- a/pclsync_lib.cpp +++ b/pclsync_lib.cpp @@ -486,7 +486,7 @@ static void status_change(pstatus_t *status) { lib_setup_cripto(); } } - psync_fs_start(); + pfs_start(); } if (clib::pclsync_lib::get_lib().status_callback_) { clib::pclsync_lib::get_lib().status_callback_(