Refactor pfs sub-modules to use namespaced function prefixes

- pfscrypto_* → pfs_crpt_*
- psync_fsstatic_* → pfs_stat_*
- psync_fsupload_* → pfs_upld_*
- psync_fstask_* → pfs_task_* (functions only; typedefs unchanged)
- psync_fsfolder_*/psync_fsfolderid_*/psync_fsfolderflags_*/
  get_decname_for_folder/psync_get_folderid → pfs_fldr_*

Type names, macro constants, and typedef aliases are unchanged.
Updated all call sites across 17 files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-03-02 22:44:55 +01:00
parent ad844106a3
commit 2e61a723a6
17 changed files with 646 additions and 646 deletions

View File

@ -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;
}

View File

@ -181,7 +181,7 @@ int pfs_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,
@ -305,9 +305,9 @@ int pfs_rename_openfile_locked(psync_fsfileid_t fileid,
fl = ptree_element(tr, psync_openfile_t, tree);
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 = putil_strdup(name);
@ -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
@ -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
@ -767,10 +767,10 @@ static int pfs_getattr(const char *path, struct FUSE_STAT *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 = -pfs_crypto_err_to_errno(crr);
pdbg_logf(D_NOTICE, "got crypto error for %s, returning %d", path, crr);
@ -781,10 +781,10 @@ static int pfs_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 pfs_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 pfs_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;
@ -868,12 +868,12 @@ static int pfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
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(
-pfs_crypto_err_to_errno(psync_fsfolder_crypto_error()));
-pfs_crypto_err_to_errno(pfs_fldr_crypto_error()));
else
return -pdbg_return_const(ENOENT);
}
@ -889,7 +889,7 @@ static int pfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
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 pfs_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 pfs_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);
@ -999,7 +999,7 @@ pfs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid,
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 @@ pfs_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);
@ -1150,7 +1150,7 @@ 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 {
@ -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);
@ -1213,19 +1213,19 @@ static void pfs_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);
}
pfs_dec_of_refcnt(of);
psql_unlock();
@ -1251,10 +1251,10 @@ static int pfs_open(const char *path, struct fuse_file_info *fi) {
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 = -pfs_crypto_err_to_errno(ret);
return pdbg_return(ret);
@ -1276,9 +1276,9 @@ static int pfs_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=?");
@ -1327,9 +1327,9 @@ static int pfs_open(const char *path, struct fuse_file_info *fi) {
} else
encoder = PSYNC_CRYPTO_INVALID_ENCODER;
of = pfs_create_file(fileid, 0, 0, 0, 1, writeid,
psync_fstask_get_ref_locked(folder),
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);
@ -1381,9 +1381,9 @@ static int pfs_open(const char *path, struct fuse_file_info *fi) {
} else
encoder = PSYNC_CRYPTO_INVALID_ENCODER;
of = pfs_create_file(cr->fileid, fileid, size, hash, 1, writeid,
psync_fstask_get_ref_locked(folder),
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;
@ -1399,12 +1399,12 @@ static int pfs_open(const char *path, struct fuse_file_info *fi) {
} else { /* cr->fileid==0 */
psync_fstask_local_creat_t *lc;
lc = psync_fstask_creat_get_local(cr);
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 pfs_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);
@ -1475,16 +1475,16 @@ static int pfs_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 = pfs_create_file(cr->fileid, 0, 0, 0, 1, 0,
psync_fstask_get_ref_locked(folder), fpath->name,
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;
@ -1507,7 +1507,7 @@ static int pfs_open(const char *path, struct fuse_file_info *fi) {
} else
encoder = PSYNC_CRYPTO_INVALID_ENCODER;
of = pfs_create_file(fileid, fileid, size, hash, 0, 0,
psync_fstask_get_ref_locked(folder), fpath->name,
pfs_task_get_ref_locked(folder), fpath->name,
encoder);
of->origctime = ctime;
fi->fh = openfile_to_fh(of);
@ -1515,7 +1515,7 @@ static int pfs_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;
@ -1526,12 +1526,12 @@ static int pfs_file_exists_in_folder(psync_fstask_folder_t *folder,
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=?");
@ -1557,12 +1557,12 @@ static int pfs_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);
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,
psync_fstask_get_ref_locked(folder), fpath->name,
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();
@ -1586,10 +1586,10 @@ static int pfs_creat(const char *path, mode_t mode,
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 = pfs_crypto_err_to_errno(ret);
return pdbg_return(-ret);
@ -1608,9 +1608,9 @@ static int pfs_creat(const char *path, mode_t mode,
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);
if (pfs_file_exists_in_folder(folder, fpath->name)) {
psync_fstask_release_folder_tasks_locked(folder);
pfs_task_release_folder_tasks_locked(folder);
pdbg_logf(D_NOTICE, "file %s already exists, processing as open", path);
ret = pfs_open(path, fi);
psql_unlock();
@ -1619,7 +1619,7 @@ static int pfs_creat(const char *path, mode_t mode,
}
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,7 +1627,7 @@ static int pfs_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 -pfs_crypto_err_to_errno(psync_crypto_to_error(encsymkey));
@ -1635,7 +1635,7 @@ static int pfs_creat(const char *path, mode_t mode,
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,19 +1646,19 @@ static int pfs_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 = pfs_create_file(cr->fileid, 0, 0, 0, 1, 0,
psync_fstask_get_ref_locked(folder), fpath->name,
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;
@ -1701,7 +1701,7 @@ static void pfs_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 &&
@ -1725,7 +1725,7 @@ static void pfs_free_openfile(psync_openfile_t *of) {
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,7 +1733,7 @@ static void pfs_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);
}
@ -1805,7 +1805,7 @@ static void pfs_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 int1<?");
@ -1834,7 +1834,7 @@ static void pfs_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;
@ -1872,7 +1872,7 @@ static int pfs_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 pfs_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 int1<?");
@ -1934,7 +1934,7 @@ static int pfs_fsync(const char *path, int datasync,
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;
@ -2016,9 +2016,9 @@ static int pfs_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);
@ -2047,7 +2047,7 @@ static void pfs_inc_writeid_locked(psync_openfile_t *of) {
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();
}
@ -2131,7 +2131,7 @@ pfs_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))) {
@ -2150,7 +2150,7 @@ pfs_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();
@ -2183,7 +2183,7 @@ pfs_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);
@ -2231,20 +2231,20 @@ pfs_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;
}
pfs_update_openfile_fileid_locked(of, cr->fileid);
pfs_xatr_static_to_task(taskid, cr->taskid);
cr = psync_fstask_find_creat(of->currentfolder, of->currentname, 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--;
@ -2272,10 +2272,10 @@ pfs_check_modified_file_write_space(psync_openfile_t *of, size_t size,
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;
@ -2462,7 +2462,7 @@ static int pfs_write(const char *path, const char *buf, size_t size,
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 = pfs_write_newfile(of, buf, size, offset);
pthread_mutex_unlock(&of->mutex);
@ -2481,7 +2481,7 @@ 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);
@ -2508,7 +2508,7 @@ static int pfs_mkdir(const char *path, mode_t mode) {
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 pfs_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);
@ -2534,13 +2534,13 @@ static int pfs_can_rmdir(const char *path) {
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);
@ -2555,13 +2555,13 @@ static int pfs_rmdir(const char *path) {
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);
@ -2575,13 +2575,13 @@ static int pfs_can_unlink(const char *path) {
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);
@ -2596,13 +2596,13 @@ static int pfs_unlink(const char *path) {
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) {
@ -2627,12 +2627,12 @@ static int pfs_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 pfs_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);
@ -2700,7 +2700,7 @@ static int pfs_rename_folder(psync_fsfolderid_t folderid,
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);
}
@ -2713,7 +2713,7 @@ static int pfs_rename_file(psync_fsfileid_t fileid,
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);
}
@ -2721,15 +2721,15 @@ 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;
}
@ -2749,15 +2749,15 @@ 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;
}
@ -2777,35 +2777,35 @@ 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;
}
@ -2817,18 +2817,18 @@ static int pfs_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))) {
if ((mk = pfs_task_find_mkdir(folder, name, 0))) {
ret = pfs_is_folder_nonempty(mk->folderid) + 1;
} 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;
@ -2869,8 +2869,8 @@ static int pfs_rename(const char *old_path, const char *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,13 +2889,13 @@ static int pfs_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 ((mkdir = pfs_task_find_mkdir(folder, fold_path->name, 0))) {
if (pfs_is_file(fnew_path->folderid, fnew_path->name)) {
ret = -ENOTDIR;
} else if (pfs_is_nonempty_folder(fnew_path->folderid,
@ -2911,7 +2911,7 @@ static int pfs_rename(const char *old_path, const char *new_path) {
}
goto finish;
} else if ((creat = psync_fstask_find_creat(folder, fold_path->name, 0))) {
} 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))
@ -2926,7 +2926,7 @@ static int pfs_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);
@ -2959,7 +2959,7 @@ static int pfs_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);
@ -2982,7 +2982,7 @@ static int pfs_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);
@ -3038,7 +3038,7 @@ 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;
@ -3106,9 +3106,9 @@ static int pfs_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=?");
@ -3128,10 +3128,10 @@ static int pfs_set_time_locked(psync_fsfolderid_t folderid,
} else
return pfs_set_filetime_locked(creat->fileid, tv, crtime, 0);
}
if ((mkdir = psync_fstask_find_mkdir(folder, name, 0)))
if ((mkdir = pfs_task_find_mkdir(folder, name, 0)))
return pfs_set_foldertime_locked(mkdir->folderid, tv, crtime, 0);
un = psync_fstask_find_unlink(folder, name, 0);
rm = psync_fstask_find_rmdir(folder, name, 0);
un = pfs_task_find_unlink(folder, name, 0);
rm = pfs_task_find_rmdir(folder, name, 0);
} else {
un = NULL;
rm = NULL;
@ -3174,7 +3174,7 @@ static int pfs_set_time(const char *path, const struct timespec *tv,
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))
@ -3217,7 +3217,7 @@ retry:
return ret;
}
if (of->encrypted)
return pfscrypto_truncate(of, size);
return pfs_crpt_truncate(of, size);
else {
if (pfs_modfile_check_size_ok(of, size))
ret = -pdbg_return_const(EIO);
@ -3499,7 +3499,7 @@ static void pfs_dump_internals() {
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();
}
@ -3623,12 +3623,12 @@ static void pfs_init_once() {
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(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() {
@ -3826,7 +3826,7 @@ void pfs_pause_until_login() {
psql_unlock();
}
void pfs_clean_tasks() { psync_fstask_clean(); }
void pfs_clean_tasks() { pfs_task_clean(); }
int pfs_start() {
uint32_t status;

View File

@ -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) {
@ -131,7 +131,7 @@ static uint64_t pfs_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;
@ -204,7 +204,7 @@ pfs_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);
@ -236,7 +236,7 @@ static int pfs_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,
@ -472,7 +472,7 @@ static int pfs_unlock_ret(psync_openfile_t *of, int ret) {
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;
@ -1049,7 +1049,7 @@ static int pfs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) {
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,7 +1059,7 @@ static int pfs_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);
pfs_crpt_offset_by_size(of->currentsize, &offsets);
ret = pfs_write_auth_tree_to_log(of, &offsets);
if (pdbg_unlikely(ret))
return ret;
@ -1094,7 +1094,7 @@ static int pfs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) {
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;
@ -1123,7 +1123,7 @@ static int pfs_crypto_finalize_log(psync_openfile_t *of, int fullsync) {
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);
}
@ -1148,7 +1148,7 @@ pfs_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));
@ -1162,7 +1162,7 @@ pfs_crypto_reset_log_to_off(psync_openfile_t *of, uint32_t off) {
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
@ -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,
@ -1347,14 +1347,14 @@ static int pfscrypto_write_new_nu(psync_openfile_t *of,
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;
@ -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);
@ -1421,7 +1421,7 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf,
}
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(
@ -1457,7 +1457,7 @@ int pfscrypto_read_mod(psync_openfile_t *of, char *buf,
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);
@ -1479,7 +1479,7 @@ static int pfs_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 pfs_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) {
@ -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
@ -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,14 +1687,14 @@ 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;
@ -1703,7 +1703,7 @@ static int pfscrypto_truncate_to_zero(psync_openfile_t *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;
@ -1739,7 +1739,7 @@ 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 ||
@ -1752,7 +1752,7 @@ retry:
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)
@ -1764,7 +1764,7 @@ 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)
@ -1794,7 +1794,7 @@ retry:
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;
@ -1892,7 +1892,7 @@ static int pfs_crypto_run_extender(psync_openfile_t *of, uint64_t size) {
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:
@ -1941,35 +1941,35 @@ retry:
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 pfs_crpt_flush(psync_openfile_t *of) {
int ret = pfs_crypto_wait_no_extender_locked(of);
if (ret)
return ret;
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;
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,
@ -2090,7 +2090,7 @@ static void pfs_crypto_check_file(void *ptr, ppath_fast_stat *st) {
}
}
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);

View File

@ -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

View File

@ -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;
@ -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 = putil_strndup(ename, elen);
if ((mk = psync_fstask_find_mkdir(folder, name, 0))) {
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 = putil_strndup(ename, elen);
if ((mk = psync_fstask_find_mkdir(folder, name, 0))) {
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 = putil_strndup(ename, elen);
if ((mk = psync_fstask_find_mkdir(folder, name, 0))) {
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;

View File

@ -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

View File

@ -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));
}

View File

@ -31,6 +31,6 @@
#ifndef _PSYNC_FSSTATIC_H
#define _PSYNC_FSSTATIC_H
void psync_fsstatic_add_files();
void pfs_stat_add_files();
#endif

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -155,7 +155,7 @@ 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);
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;
@ -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;
@ -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();
@ -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);
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);
@ -590,7 +590,7 @@ 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);
@ -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);
@ -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;
@ -1354,7 +1354,7 @@ 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);
pfs_xatr_task_to_file(task->id, fileid);
@ -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;
@ -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);
@ -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();
@ -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);

View File

@ -34,9 +34,9 @@
#include <stdint.h>
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

View File

@ -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);

View File

@ -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);
@ -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);
@ -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;
@ -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();
}
}

View File

@ -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=?");

View File

@ -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() {

View File

@ -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");