pfscrypto namespace
This commit is contained in:
parent
97c10b3870
commit
990fde0b64
|
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Display help if requested
|
||||
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||
echo "Usage: $(basename "$0") [OPTIONS]"
|
||||
echo
|
||||
echo "Reads 'oldpattern => newpattern' pairs from STDIN and replaces all occurrences"
|
||||
echo "of oldpattern with newpattern in all .c and .h files in the current directory"
|
||||
echo "and its subdirectories."
|
||||
echo
|
||||
echo "OPTIONS:"
|
||||
echo " -h, --help Display this help and exit"
|
||||
echo
|
||||
echo "EXAMPLES:"
|
||||
echo " cat patterns.txt | $(basename "$0")"
|
||||
echo " $(basename "$0") < patterns.txt"
|
||||
echo
|
||||
echo " Or interactively:"
|
||||
echo " $(basename "$0")"
|
||||
echo " oldFunction => newFunction"
|
||||
echo " oldStruct => newStruct"
|
||||
echo " [Ctrl+D to end input]"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Process each line from STDIN
|
||||
while IFS= read -r line; do
|
||||
# Skip empty lines
|
||||
if [[ -z "$line" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if the line contains "=>"
|
||||
if echo "$line" | grep -q "=>"; then
|
||||
# Extract old and new patterns
|
||||
oldpattern=$(echo "$line" | cut -d "=" -f 1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
newpattern=$(echo "$line" | cut -d ">" -f 2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
|
||||
# Escape special characters for sed
|
||||
oldpattern_escaped=$(echo "$oldpattern" | sed 's/[\/&]/\\&/g')
|
||||
newpattern_escaped=$(echo "$newpattern" | sed 's/[\/&]/\\&/g')
|
||||
|
||||
echo "Replacing: '$oldpattern' with '$newpattern'"
|
||||
|
||||
# Execute the find and sed command
|
||||
find . -name "*.[ch]" -exec sed -i "s/$oldpattern_escaped/$newpattern_escaped/g" {} \;
|
||||
else
|
||||
echo "Warning: Line does not match the 'oldpattern => newpattern' format: $line" >&2
|
||||
fi
|
||||
done
|
||||
|
||||
echo "All replacements completed!"
|
||||
|
|
@ -187,7 +187,7 @@ int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid,
|
|||
psync_interval_tree_free(fl->authenticatedints);
|
||||
fl->authenticatedints = NULL;
|
||||
}
|
||||
size = psync_fs_crypto_plain_size(size);
|
||||
size = pfscrypto_plain_size(size);
|
||||
}
|
||||
debug(D_NOTICE, "updating fileid %ld to %lu, hash %lu size %lu",
|
||||
(long)fileid, (unsigned long)newfileid, (unsigned long)hash,
|
||||
|
|
@ -461,7 +461,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 = psync_fs_crypto_plain_size(size);
|
||||
size = pfscrypto_plain_size(size);
|
||||
memset(stbuf, 0, sizeof(struct FUSE_STAT));
|
||||
#ifdef FUSE_STAT_HAS_BIRTHTIME
|
||||
stbuf->st_birthtime = psync_get_number(row[2]);
|
||||
|
|
@ -657,7 +657,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 = psync_fs_crypto_plain_size(pfile_stat_size(&st));
|
||||
size = pfscrypto_plain_size(pfile_stat_size(&st));
|
||||
stbuf->st_size = size;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1022,7 +1022,7 @@ psync_fs_create_file(psync_fsfileid_t fileid, psync_fsfileid_t remotefileid,
|
|||
} else {
|
||||
fl = psync_new(psync_openfile_t);
|
||||
memset(fl, 0, sizeof(psync_openfile_t));
|
||||
size = psync_fs_crypto_plain_size(size);
|
||||
size = pfscrypto_plain_size(size);
|
||||
}
|
||||
if (d < 0)
|
||||
psync_tree_add_before(&openfiles, tr, &fl->tree);
|
||||
|
|
@ -1156,7 +1156,7 @@ static int open_write_files(psync_openfile_t *of, int trunc) {
|
|||
if (unlikely_log(fs == -1))
|
||||
return -EIO;
|
||||
if (of->encrypted)
|
||||
of->currentsize = psync_fs_crypto_plain_size(fs);
|
||||
of->currentsize = pfscrypto_plain_size(fs);
|
||||
else
|
||||
of->currentsize = fs;
|
||||
} else {
|
||||
|
|
@ -1197,7 +1197,7 @@ static int open_write_files(psync_openfile_t *of, int trunc) {
|
|||
(long)of->fileid);
|
||||
return -EIO;
|
||||
}
|
||||
ret = psync_fs_crypto_init_log(of);
|
||||
ret = pfscrypto_init_log(of);
|
||||
if (ret) {
|
||||
debug(D_ERROR, "could not init log file for fileid %ld",
|
||||
(long)of->fileid);
|
||||
|
|
@ -1840,7 +1840,7 @@ static void psync_fs_write_timer(psync_timer_t timer, void *ptr) {
|
|||
debug(D_ERROR, "file is static file, which should not generally happen");
|
||||
goto unlock_ex;
|
||||
}
|
||||
if (unlikely(of->encrypted && psync_fs_crypto_flush_file(of))) {
|
||||
if (unlikely(of->encrypted && pfscrypto_flush(of))) {
|
||||
debug(D_WARNING,
|
||||
"we are in timer and we failed to flush crypto file, life sux");
|
||||
goto unlock_ex;
|
||||
|
|
@ -1878,7 +1878,7 @@ static int psync_fs_flush(const char *path, struct fuse_file_info *fi) {
|
|||
}
|
||||
writeid = of->writeid;
|
||||
if (of->encrypted) {
|
||||
ret = psync_fs_crypto_flush_file(of);
|
||||
ret = pfscrypto_flush(of);
|
||||
if (unlikely_log(ret)) {
|
||||
pthread_mutex_unlock(&of->mutex);
|
||||
return ret;
|
||||
|
|
@ -1940,7 +1940,7 @@ static int psync_fs_fsync(const char *path, int datasync,
|
|||
return 0;
|
||||
}
|
||||
if (of->encrypted) {
|
||||
ret = psync_fs_crypto_flush_file(of);
|
||||
ret = pfscrypto_flush(of);
|
||||
if (unlikely_log(ret)) {
|
||||
pthread_mutex_unlock(&of->mutex);
|
||||
return ret;
|
||||
|
|
@ -2022,9 +2022,9 @@ static int psync_fs_read(const char *path, char *buf, size_t size,
|
|||
}
|
||||
if (of->encrypted) {
|
||||
if (of->newfile)
|
||||
return psync_fs_crypto_read_newfile_locked(of, buf, size, offset);
|
||||
return pfscrypto_read_new(of, buf, size, offset);
|
||||
else if (of->modified)
|
||||
return psync_fs_crypto_read_modified_locked(of, buf, size, offset);
|
||||
return pfscrypto_read_mod(of, buf, size, offset);
|
||||
else
|
||||
return psync_pagecache_read_unmodified_encrypted_locked(of, buf, size,
|
||||
offset);
|
||||
|
|
@ -2137,7 +2137,7 @@ psync_fs_reopen_file_for_writing(psync_openfile_t *of) {
|
|||
psync_sql_unlock();
|
||||
return -PRINT_RETURN_CONST(PSYNC_FS_ERR_CRYPTO_EXPIRED);
|
||||
}
|
||||
size = psync_fs_crypto_crypto_size(of->initialsize);
|
||||
size = pfscrypto_crypto_size(of->initialsize);
|
||||
encsymkey = pcryptofolder_filencoder_key_get(of->fileid, of->hash,
|
||||
&encsymkeylen);
|
||||
if (unlikely_log(psync_crypto_is_error(encsymkey))) {
|
||||
|
|
@ -2278,10 +2278,10 @@ psync_fs_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 = psync_fs_crypto_data_sectorid_by_sectorid(offset /
|
||||
from = pfscrypto_sector_id(offset /
|
||||
PSYNC_CRYPTO_SECTOR_SIZE) *
|
||||
PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
to = psync_fs_crypto_data_sectorid_by_sectorid((offset + size) /
|
||||
to = pfscrypto_sector_id((offset + size) /
|
||||
PSYNC_CRYPTO_SECTOR_SIZE) *
|
||||
PSYNC_CRYPTO_SECTOR_SIZE +
|
||||
(offset + size) % PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
|
|
@ -2468,7 +2468,7 @@ static int psync_fs_write(const char *path, const char *buf, size_t size,
|
|||
retry:
|
||||
if (of->newfile) {
|
||||
if (of->encrypted)
|
||||
return psync_fs_crypto_write_newfile_locked(of, buf, size, offset);
|
||||
return pfscrypto_write_new(of, buf, size, offset);
|
||||
else
|
||||
ret = psync_fs_write_newfile(of, buf, size, offset);
|
||||
pthread_mutex_unlock(&of->mutex);
|
||||
|
|
@ -2487,7 +2487,7 @@ retry:
|
|||
}
|
||||
}
|
||||
if (of->encrypted)
|
||||
return psync_fs_crypto_write_modified_locked(of, buf, size, offset);
|
||||
return pfscrypto_write_mod(of, buf, size, offset);
|
||||
else {
|
||||
debug(D_NOTICE, "write of %lu bytes at offset %lu", (unsigned long)size,
|
||||
(unsigned long)offset);
|
||||
|
|
@ -3223,7 +3223,7 @@ retry:
|
|||
return ret;
|
||||
}
|
||||
if (of->encrypted)
|
||||
return psync_fs_crypto_ftruncate(of, size);
|
||||
return pfscrypto_truncate(of, size);
|
||||
else {
|
||||
if (psync_fs_modfile_check_size_ok(of, size))
|
||||
ret = -PRINT_RETURN_CONST(EIO);
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ static const uint64_t max_level_size[PSYNC_CRYPTO_MAX_HASH_TREE_LEVEL + 1] = {
|
|||
0x10204081000, 0x810204081000, 0x40810204081000};
|
||||
|
||||
psync_crypto_sectorid_t
|
||||
psync_fs_crypto_data_sectorid_by_sectorid(psync_crypto_sectorid_t sectorid) {
|
||||
pfscrypto_sector_id(psync_crypto_sectorid_t sectorid) {
|
||||
psync_crypto_sectorid_t sect;
|
||||
sect = sectorid;
|
||||
while (sectorid >= PSYNC_CRYPTO_HASH_TREE_SECTORS) {
|
||||
|
|
@ -136,7 +136,7 @@ static uint64_t psync_fs_crypto_auth_offset(uint32_t level, uint32_t id) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void psync_fs_crypto_offsets_by_plainsize(uint64_t size,
|
||||
void pfscrypto_offset_by_size(uint64_t size,
|
||||
psync_crypto_offsets_t *offsets) {
|
||||
uint64_t off;
|
||||
psync_crypto_sectorid_t lastsectorid;
|
||||
|
|
@ -209,7 +209,7 @@ psync_fs_crypto_offsets_by_cryptosize(uint64_t size,
|
|||
offsets->plainsize = size;
|
||||
}
|
||||
|
||||
int psync_fs_crypto_init_log(psync_openfile_t *of) {
|
||||
int pfscrypto_init_log(psync_openfile_t *of) {
|
||||
char buff[PSYNC_CRYPTO_SECTOR_SIZE];
|
||||
ssize_t wrt;
|
||||
assert(sizeof(psync_crypto_master_record) <= PSYNC_CRYPTO_SECTOR_SIZE);
|
||||
|
|
@ -241,7 +241,7 @@ static int psync_fs_crypto_read_newfile_full_sector_from_log(
|
|||
return -EIO;
|
||||
}
|
||||
assert(hdr.offset ==
|
||||
(uint64_t)psync_fs_crypto_data_sectorid_by_sectorid(se->sectorid) *
|
||||
(uint64_t)pfscrypto_sector_id(se->sectorid) *
|
||||
PSYNC_CRYPTO_SECTOR_SIZE);
|
||||
assert(hdr.length <= PSYNC_CRYPTO_SECTOR_SIZE);
|
||||
rd = pfile_pread(of->logfile, buff, hdr.length,
|
||||
|
|
@ -477,7 +477,7 @@ static int psync_fs_unlock_ret(psync_openfile_t *of, int ret) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int psync_fs_crypto_read_newfile_locked(psync_openfile_t *of, char *buf,
|
||||
int pfscrypto_read_new(psync_openfile_t *of, char *buf,
|
||||
uint64_t size, uint64_t offset) {
|
||||
uint64_t off2, offdiff;
|
||||
psync_crypto_sectorid_t sectorid;
|
||||
|
|
@ -1054,7 +1054,7 @@ static int psync_fs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) {
|
|||
char *olog, *flog;
|
||||
char fileidhex[sizeof(psync_fsfileid_t) * 2 + 2];
|
||||
int ret;
|
||||
psync_fs_crypto_offsets_by_plainsize(of->currentsize, &offsets);
|
||||
pfscrypto_offset_by_size(of->currentsize, &offsets);
|
||||
if (of->logoffset == PSYNC_CRYPTO_SECTOR_SIZE &&
|
||||
offsets.masterauthoff +
|
||||
(offsets.needmasterauth ? PSYNC_CRYPTO_AUTH_SIZE : 0) ==
|
||||
|
|
@ -1064,7 +1064,7 @@ static int psync_fs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) {
|
|||
}
|
||||
debug(D_NOTICE, "finalizing log of %s size %lu", of->currentname,
|
||||
(unsigned long)of->currentsize);
|
||||
psync_fs_crypto_offsets_by_plainsize(of->currentsize, &offsets);
|
||||
pfscrypto_offset_by_size(of->currentsize, &offsets);
|
||||
ret = psync_fs_write_auth_tree_to_log(of, &offsets);
|
||||
if (unlikely_log(ret))
|
||||
return ret;
|
||||
|
|
@ -1099,7 +1099,7 @@ static int psync_fs_crypto_do_finalize_log(psync_openfile_t *of, int fullsync) {
|
|||
unlikely_log((of->logfile = pfile_open(olog, O_RDWR,
|
||||
O_CREAT | O_TRUNC)) ==
|
||||
INVALID_HANDLE_VALUE) ||
|
||||
unlikely_log(psync_fs_crypto_init_log(of))) {
|
||||
unlikely_log(pfscrypto_init_log(of))) {
|
||||
psync_free(olog);
|
||||
psync_free(flog);
|
||||
return -EIO;
|
||||
|
|
@ -1129,7 +1129,7 @@ static int psync_fs_crypto_finalize_log(psync_openfile_t *of, int fullsync) {
|
|||
static void psync_fs_crypt_add_sector_to_interval_tree(
|
||||
psync_openfile_t *of, psync_crypto_sectorid_t sectorid, size_t size) {
|
||||
uint64_t offset;
|
||||
offset = (uint64_t)psync_fs_crypto_data_sectorid_by_sectorid(sectorid) *
|
||||
offset = (uint64_t)pfscrypto_sector_id(sectorid) *
|
||||
PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
psync_interval_tree_add(&of->writeintervals, offset, offset + size);
|
||||
}
|
||||
|
|
@ -1154,7 +1154,7 @@ psync_fs_crypto_reset_log_to_off(psync_openfile_t *of, uint32_t off) {
|
|||
of->currentname);
|
||||
return;
|
||||
}
|
||||
of->currentsize = psync_fs_crypto_plain_size(sz);
|
||||
of->currentsize = pfscrypto_plain_size(sz);
|
||||
debug(D_WARNING, "emptying log");
|
||||
pfile_close(of->logfile);
|
||||
cachepath = psync_setting_get_string(_PS(fscachepath));
|
||||
|
|
@ -1168,7 +1168,7 @@ psync_fs_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)
|
||||
debug(D_WARNING, "could not create new file %s", log);
|
||||
else if (psync_fs_crypto_init_log(of))
|
||||
else if (pfscrypto_init_log(of))
|
||||
debug(D_WARNING, "could not init log file %s", log);
|
||||
|
||||
} else
|
||||
|
|
@ -1266,7 +1266,7 @@ fail:
|
|||
return PRINT_RETURN(ret);
|
||||
}
|
||||
|
||||
static int psync_fs_crypto_write_newfile_locked_nu(psync_openfile_t *of,
|
||||
static int pfscrypto_write_new_nu(psync_openfile_t *of,
|
||||
const char *buf,
|
||||
uint64_t size,
|
||||
uint64_t offset,
|
||||
|
|
@ -1353,14 +1353,14 @@ static int psync_fs_crypto_write_newfile_locked_nu(psync_openfile_t *of,
|
|||
return wrt;
|
||||
}
|
||||
|
||||
int psync_fs_crypto_write_newfile_locked(psync_openfile_t *of, const char *buf,
|
||||
int pfscrypto_write_new(psync_openfile_t *of, const char *buf,
|
||||
uint64_t size, uint64_t offset) {
|
||||
int ret = psync_fs_crypto_write_newfile_locked_nu(of, buf, size, offset, 1);
|
||||
int ret = pfscrypto_write_new_nu(of, buf, size, offset, 1);
|
||||
pthread_mutex_unlock(&of->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int psync_fs_crypto_read_modified_locked(psync_openfile_t *of, char *buf,
|
||||
int pfscrypto_read_mod(psync_openfile_t *of, char *buf,
|
||||
uint64_t size, uint64_t offset) {
|
||||
psync_interval_tree_t *itr;
|
||||
char *bufoff;
|
||||
|
|
@ -1384,7 +1384,7 @@ int psync_fs_crypto_read_modified_locked(psync_openfile_t *of, char *buf,
|
|||
rfr = 0;
|
||||
itr = NULL;
|
||||
for (sectorid = firstsectorid; sectorid <= lastsectorid; sectorid++) {
|
||||
esectorid = psync_fs_crypto_data_sectorid_by_sectorid(sectorid);
|
||||
esectorid = pfscrypto_sector_id(sectorid);
|
||||
eoffset = (uint64_t)esectorid * PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
if (itr && itr->from <= eoffset && itr->to > eoffset)
|
||||
rfr |= 1;
|
||||
|
|
@ -1400,7 +1400,7 @@ int psync_fs_crypto_read_modified_locked(psync_openfile_t *of, char *buf,
|
|||
if (rfr == 1) {
|
||||
debug(D_NOTICE, "doing read at offset %lu size %lu from local changes",
|
||||
(unsigned long)offset, (unsigned long)size);
|
||||
return psync_fs_crypto_read_newfile_locked(of, buf, size, offset);
|
||||
return pfscrypto_read_new(of, buf, size, offset);
|
||||
} else if (rfr == 2) {
|
||||
debug(D_NOTICE, "doing read at offset %lu size %lu from remote only",
|
||||
(unsigned long)offset, (unsigned long)size);
|
||||
|
|
@ -1427,7 +1427,7 @@ int psync_fs_crypto_read_modified_locked(psync_openfile_t *of, char *buf,
|
|||
}
|
||||
offmod = offset % PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
for (sectorid = firstsectorid; sectorid <= lastsectorid; sectorid++) {
|
||||
esectorid = psync_fs_crypto_data_sectorid_by_sectorid(sectorid);
|
||||
esectorid = pfscrypto_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(
|
||||
|
|
@ -1463,7 +1463,7 @@ int psync_fs_crypto_read_modified_locked(psync_openfile_t *of, char *buf,
|
|||
return psync_fs_unlock_ret(of, size);
|
||||
}
|
||||
|
||||
int psync_fs_crypto_write_modified_locked_nu(psync_openfile_t *of,
|
||||
int pfscrypto_write_mod_nu(psync_openfile_t *of,
|
||||
const char *buf, uint64_t size,
|
||||
uint64_t offset,
|
||||
int checkextender);
|
||||
|
|
@ -1485,7 +1485,7 @@ static int psync_fs_modfile_fillzero(psync_openfile_t *of, uint64_t size,
|
|||
else
|
||||
wr = size;
|
||||
}
|
||||
ret = psync_fs_crypto_write_modified_locked_nu(of, buff, wr, offset,
|
||||
ret = pfscrypto_write_mod_nu(of, buff, wr, offset,
|
||||
checkextender);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
|
|
@ -1495,7 +1495,7 @@ static int psync_fs_modfile_fillzero(psync_openfile_t *of, uint64_t size,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int psync_fs_crypto_write_modified_locked_nu(psync_openfile_t *of,
|
||||
int pfscrypto_write_mod_nu(psync_openfile_t *of,
|
||||
const char *buf, uint64_t size,
|
||||
uint64_t offset,
|
||||
int checkextender) {
|
||||
|
|
@ -1540,7 +1540,7 @@ retry:
|
|||
if ((uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE >= of->initialsize ||
|
||||
(uint64_t)sectorid * PSYNC_CRYPTO_SECTOR_SIZE >= of->currentsize)
|
||||
break;
|
||||
esectorid = psync_fs_crypto_data_sectorid_by_sectorid(sectorid);
|
||||
esectorid = pfscrypto_sector_id(sectorid);
|
||||
eoffset = (uint64_t)esectorid * PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
if (itr && itr->from <= eoffset && itr->to > eoffset)
|
||||
continue;
|
||||
|
|
@ -1563,11 +1563,11 @@ retry:
|
|||
// already moved all trailing checksums to a new location and they would be
|
||||
// in of->writeintervals anyway.
|
||||
if (of->extender)
|
||||
psync_fs_crypto_offsets_by_plainsize(of->extender->extendedto, &offsets);
|
||||
pfscrypto_offset_by_size(of->extender->extendedto, &offsets);
|
||||
else
|
||||
psync_fs_crypto_offsets_by_plainsize(of->currentsize, &offsets);
|
||||
pfscrypto_offset_by_size(of->currentsize, &offsets);
|
||||
for (l = 0; l <= offsets.treelevels; l++) {
|
||||
psync_fs_crypto_get_auth_sector_off(sectorid, l, &offsets, &eoffset,
|
||||
pfscrypto_get_auth_off(sectorid, l, &offsets, &eoffset,
|
||||
&asize, &aid);
|
||||
itr = psync_interval_tree_first_interval_containing_or_after(
|
||||
of->writeintervals, eoffset);
|
||||
|
|
@ -1583,9 +1583,9 @@ retry:
|
|||
icnt = 0;
|
||||
isize = 0;
|
||||
if (of->currentsize < of->initialsize)
|
||||
eoffset = psync_fs_crypto_crypto_size(of->currentsize);
|
||||
eoffset = pfscrypto_crypto_size(of->currentsize);
|
||||
else
|
||||
eoffset = psync_fs_crypto_crypto_size(of->initialsize);
|
||||
eoffset = pfscrypto_crypto_size(of->initialsize);
|
||||
itr = psync_interval_tree_get_first(needtodwl);
|
||||
do {
|
||||
// if we are past initialsize, we are probably trying to download
|
||||
|
|
@ -1673,18 +1673,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 psync_fs_crypto_write_newfile_locked_nu(of, buf, size, offset,
|
||||
return pfscrypto_write_new_nu(of, buf, size, offset,
|
||||
checkextender);
|
||||
}
|
||||
|
||||
int psync_fs_crypto_write_modified_locked(psync_openfile_t *of, const char *buf,
|
||||
int pfscrypto_write_mod(psync_openfile_t *of, const char *buf,
|
||||
uint64_t size, uint64_t offset) {
|
||||
int ret = psync_fs_crypto_write_modified_locked_nu(of, buf, size, offset, 1);
|
||||
int ret = pfscrypto_write_mod_nu(of, buf, size, offset, 1);
|
||||
pthread_mutex_unlock(&of->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int psync_fs_crypto_ftruncate_to_zero(psync_openfile_t *of) {
|
||||
static int pfscrypto_truncate_to_zero(psync_openfile_t *of) {
|
||||
int ret;
|
||||
debug(D_NOTICE, "truncating file %s from %lu to zero", of->currentname,
|
||||
(unsigned long)of->currentsize);
|
||||
|
|
@ -1693,14 +1693,14 @@ static int psync_fs_crypto_ftruncate_to_zero(psync_openfile_t *of) {
|
|||
debug(D_WARNING, "failed to truncate log file of %s", of->currentname);
|
||||
return -EIO;
|
||||
}
|
||||
ret = psync_fs_crypto_init_log(of);
|
||||
ret = pfscrypto_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,
|
||||
psync_fs_crypto_crypto_size(of->initialsize));
|
||||
pfscrypto_crypto_size(of->initialsize));
|
||||
}
|
||||
psync_tree_for_each_element_call_safe(of->sectorsinlog, psync_sector_inlog_t,
|
||||
tree, psync_free);
|
||||
|
|
@ -1710,7 +1710,7 @@ static int psync_fs_crypto_ftruncate_to_zero(psync_openfile_t *of) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int psync_fs_crypto_ftruncate_down(psync_openfile_t *of, uint64_t size) {
|
||||
static int pfscrypto_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;
|
||||
|
|
@ -1746,7 +1746,7 @@ static int psync_fs_crypto_ftruncate_down(psync_openfile_t *of, uint64_t size) {
|
|||
lastsectoroldsize = PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
else
|
||||
lastsectoroldsize = of->currentsize - lastsectoff;
|
||||
elastsectorid = psync_fs_crypto_data_sectorid_by_sectorid(lastsectorid);
|
||||
elastsectorid = pfscrypto_sector_id(lastsectorid);
|
||||
elastsectoroff = (uint64_t)elastsectorid * PSYNC_CRYPTO_SECTOR_SIZE;
|
||||
retry:
|
||||
if (of->newfile ||
|
||||
|
|
@ -1759,7 +1759,7 @@ retry:
|
|||
assert(ret == lastsectoroldsize);
|
||||
} else {
|
||||
writeid = of->writeid;
|
||||
ret = psync_fs_crypto_read_modified_locked(of, buf, lastsectoroldsize,
|
||||
ret = pfscrypto_read_mod(of, buf, lastsectoroldsize,
|
||||
lastsectoff);
|
||||
// unlocked now
|
||||
if (ret < 0)
|
||||
|
|
@ -1771,7 +1771,7 @@ retry:
|
|||
}
|
||||
// the write will push all the auth data we need to the datafile (it is
|
||||
// probably in cache from the read)
|
||||
ret = psync_fs_crypto_write_modified_locked(of, buf, lastsectoroldsize,
|
||||
ret = pfscrypto_write_mod(of, buf, lastsectoroldsize,
|
||||
lastsectoff);
|
||||
// unlocked now
|
||||
if (ret < 0)
|
||||
|
|
@ -1801,7 +1801,7 @@ retry:
|
|||
of->currentsize = size;
|
||||
if (!of->newfile)
|
||||
psync_interval_tree_cut_end(&of->writeintervals,
|
||||
psync_fs_crypto_crypto_size(size));
|
||||
pfscrypto_crypto_size(size));
|
||||
debug(D_NOTICE, "file %s truncated to %lu", of->currentname,
|
||||
(unsigned long)size);
|
||||
return 0;
|
||||
|
|
@ -1899,7 +1899,7 @@ static int psync_fs_crypto_run_extender(psync_openfile_t *of, uint64_t size) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int psync_fs_crypto_ftruncate(psync_openfile_t *of, uint64_t size) {
|
||||
int pfscrypto_truncate(psync_openfile_t *of, uint64_t size) {
|
||||
int ret;
|
||||
assert(of->modified);
|
||||
retry:
|
||||
|
|
@ -1948,35 +1948,35 @@ retry:
|
|||
of->currentsize, 0);
|
||||
} else if (of->currentsize > size) {
|
||||
if (size == 0)
|
||||
ret = psync_fs_crypto_ftruncate_to_zero(of);
|
||||
ret = pfscrypto_truncate_to_zero(of);
|
||||
else
|
||||
return psync_fs_crypto_ftruncate_down(of, size);
|
||||
return pfscrypto_truncate_down(of, size);
|
||||
} else
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int psync_fs_crypto_flush_file(psync_openfile_t *of) {
|
||||
int pfscrypto_flush(psync_openfile_t *of) {
|
||||
int ret = psync_fs_crypto_wait_no_extender_locked(of);
|
||||
if (ret)
|
||||
return ret;
|
||||
return psync_fs_crypto_finalize_log(of, 1);
|
||||
}
|
||||
|
||||
uint64_t psync_fs_crypto_plain_size(uint64_t cryptosize) {
|
||||
uint64_t pfscrypto_plain_size(uint64_t cryptosize) {
|
||||
psync_crypto_offsets_t offsets;
|
||||
psync_fs_crypto_offsets_by_cryptosize(cryptosize, &offsets);
|
||||
return offsets.plainsize;
|
||||
}
|
||||
|
||||
uint64_t psync_fs_crypto_crypto_size(uint64_t plainsize) {
|
||||
uint64_t pfscrypto_crypto_size(uint64_t plainsize) {
|
||||
psync_crypto_offsets_t offsets;
|
||||
psync_fs_crypto_offsets_by_plainsize(plainsize, &offsets);
|
||||
pfscrypto_offset_by_size(plainsize, &offsets);
|
||||
return offsets.masterauthoff +
|
||||
(offsets.needmasterauth ? PSYNC_CRYPTO_AUTH_SIZE : 0);
|
||||
}
|
||||
|
||||
void psync_fs_crypto_get_auth_sector_off(psync_crypto_sectorid_t sectorid,
|
||||
void pfscrypto_get_auth_off(psync_crypto_sectorid_t sectorid,
|
||||
uint32_t level,
|
||||
psync_crypto_offsets_t *offsets,
|
||||
uint64_t *offset, uint32_t *size,
|
||||
|
|
@ -2097,7 +2097,7 @@ static void psync_fs_crypto_check_file(void *ptr, ppath_fast_stat *st) {
|
|||
}
|
||||
}
|
||||
|
||||
void psync_fs_crypto_check_logs() {
|
||||
void pfscrypto_check_logs() {
|
||||
const char *cachepath;
|
||||
cachepath = psync_setting_get_string(_PS(fscachepath));
|
||||
debug(D_NOTICE, "checking for unprocessed log files in %s", cachepath);
|
||||
|
|
|
|||
|
|
@ -51,33 +51,20 @@ typedef struct {
|
|||
pcrypto_sector_auth_t auth;
|
||||
} psync_sector_inlog_t;
|
||||
|
||||
typedef pcrypto_sector_auth_t
|
||||
psync_crypto_auth_sector_t[PSYNC_CRYPTO_HASH_TREE_SECTORS];
|
||||
typedef pcrypto_sector_auth_t psync_crypto_auth_sector_t[PSYNC_CRYPTO_HASH_TREE_SECTORS];
|
||||
|
||||
int psync_fs_crypto_init_log(psync_openfile_t *of);
|
||||
int psync_fs_crypto_read_newfile_locked(psync_openfile_t *of, char *buf,
|
||||
uint64_t size, uint64_t offset);
|
||||
int psync_fs_crypto_write_newfile_locked(psync_openfile_t *of, const char *buf,
|
||||
uint64_t size, uint64_t offset);
|
||||
int psync_fs_crypto_read_modified_locked(psync_openfile_t *of, char *buf,
|
||||
uint64_t size, uint64_t offset);
|
||||
int psync_fs_crypto_write_modified_locked(psync_openfile_t *of, const char *buf,
|
||||
uint64_t size, uint64_t offset);
|
||||
int psync_fs_crypto_ftruncate(psync_openfile_t *of, uint64_t size);
|
||||
int psync_fs_crypto_flush_file(psync_openfile_t *of);
|
||||
|
||||
psync_crypto_sectorid_t
|
||||
psync_fs_crypto_data_sectorid_by_sectorid(psync_crypto_sectorid_t sectorid);
|
||||
void psync_fs_crypto_offsets_by_plainsize(uint64_t size,
|
||||
psync_crypto_offsets_t *offsets);
|
||||
uint64_t psync_fs_crypto_plain_size(uint64_t cryptosize);
|
||||
uint64_t psync_fs_crypto_crypto_size(uint64_t plainsize);
|
||||
void psync_fs_crypto_get_auth_sector_off(psync_crypto_sectorid_t sectorid,
|
||||
uint32_t level,
|
||||
psync_crypto_offsets_t *offsets,
|
||||
uint64_t *offset, uint32_t *size,
|
||||
uint32_t *authid);
|
||||
|
||||
void psync_fs_crypto_check_logs();
|
||||
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();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2146,7 +2146,7 @@ static void psync_fsupload_thread() {
|
|||
}
|
||||
|
||||
void psync_fsupload_init() {
|
||||
psync_fs_crypto_check_logs();
|
||||
pfscrypto_check_logs();
|
||||
psync_timer_exception_handler(psync_fsupload_wake);
|
||||
prun_thread("fsupload main", psync_fsupload_thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2421,7 +2421,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++) {
|
||||
psync_fs_crypto_get_auth_sector_off(first_page_id + i, l, offsets,
|
||||
pfscrypto_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);
|
||||
|
|
@ -2431,8 +2431,8 @@ static void psync_pagecache_read_unmodified_readahead(
|
|||
}
|
||||
}
|
||||
// this may include some auth sectors, but should do no harm
|
||||
rto = psync_fs_crypto_data_sectorid_by_sectorid(first_page_id + pagecnt);
|
||||
first_page_id = psync_fs_crypto_data_sectorid_by_sectorid(first_page_id);
|
||||
rto = pfscrypto_sector_id(first_page_id + pagecnt);
|
||||
first_page_id = pfscrypto_sector_id(first_page_id);
|
||||
pagecnt = rto - first_page_id;
|
||||
}
|
||||
pages_in_db = has_pages_in_db(hash, first_page_id, pagecnt, 1);
|
||||
|
|
@ -2778,7 +2778,7 @@ int psync_pagecache_read_unmodified_encrypted_locked(psync_openfile_t *of,
|
|||
needkey = 0;
|
||||
pthread_mutex_unlock(&of->mutex);
|
||||
assert(PSYNC_CRYPTO_SECTOR_SIZE == PSYNC_FS_PAGE_SIZE);
|
||||
psync_fs_crypto_offsets_by_plainsize(initialsize, &offsets);
|
||||
pfscrypto_offset_by_size(initialsize, &offsets);
|
||||
if (offset >= initialsize)
|
||||
return 0;
|
||||
if (offset + size > initialsize)
|
||||
|
|
@ -2802,7 +2802,7 @@ int psync_pagecache_read_unmodified_encrypted_locked(psync_openfile_t *of,
|
|||
dp[i].authpage = ap;
|
||||
continue;
|
||||
}
|
||||
psync_fs_crypto_get_auth_sector_off(first_page_id + i, 0, &offsets,
|
||||
pfscrypto_get_auth_off(first_page_id + i, 0, &offsets,
|
||||
&aoffset, &asize, &aoff);
|
||||
ap = psync_new(psync_crypto_auth_page);
|
||||
ap->waiter = NULL;
|
||||
|
|
@ -2822,7 +2822,7 @@ int psync_pagecache_read_unmodified_encrypted_locked(psync_openfile_t *of,
|
|||
unsigned long l;
|
||||
lap = ap;
|
||||
for (l = 1; l <= offsets.treelevels; l++) {
|
||||
psync_fs_crypto_get_auth_sector_off(first_page_id + i, l, &offsets,
|
||||
pfscrypto_get_auth_off(first_page_id + i, l, &offsets,
|
||||
&aoffset, &asize, &aoff);
|
||||
cap = psync_new(psync_crypto_auth_page);
|
||||
cap->waiter = NULL;
|
||||
|
|
@ -2862,7 +2862,7 @@ int psync_pagecache_read_unmodified_encrypted_locked(psync_openfile_t *of,
|
|||
}
|
||||
dp[i].buff = pbuff;
|
||||
dp[i].pagesize = apsize;
|
||||
apageid = psync_fs_crypto_data_sectorid_by_sectorid(first_page_id + i);
|
||||
apageid = pfscrypto_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);
|
||||
|
|
@ -3054,7 +3054,7 @@ int psync_pagecache_readv_locked(psync_openfile_t *of,
|
|||
psync_list_init(&waiting);
|
||||
for (i = 0; i < cnt; i++) {
|
||||
assert(ranges[i].offset + ranges[i].size <= of->encrypted
|
||||
? psync_fs_crypto_crypto_size(initialsize)
|
||||
? pfscrypto_crypto_size(initialsize)
|
||||
: initialsize);
|
||||
poffset = offset_round_down_to_page(ranges[i].offset);
|
||||
pageoff = ranges[i].offset - poffset;
|
||||
|
|
|
|||
Loading…
Reference in New Issue