ncp: share salvage endpoint operation helpers

This commit is contained in:
OpenAI
2026-05-31 19:15:05 +00:00
committed by Mario Fetka
parent 4bfb1a46bd
commit 629d17427f

View File

@@ -2775,6 +2775,17 @@ static int nsp_salvage_build_info(const struct nwsalvage_metadata_entry *entry,
return(result);
}
static int nsp_salvage_scan_by_dbe(DIR_BASE_ENTRY *dbe,
unsigned long sequence,
struct nwsalvage_scan_result *scan);
static int nsp_salvage_recover_by_dbe(DIR_BASE_ENTRY *dbe,
unsigned long sequence, int task,
int exists_error,
struct nwsalvage_scan_result *scan);
static int nsp_salvage_purge_by_dbe(DIR_BASE_ENTRY *dbe,
unsigned long sequence,
struct nwsalvage_scan_result *scan);
int handle_func_0x57_salvage_scan(uint8 *q, int request_len,
uint8 *responsedata, int task)
{
@@ -2824,14 +2835,9 @@ int handle_func_0x57_salvage_scan(uint8 *q, int request_len,
if (!S_ISDIR(dbe->nwpath.statb.st_mode))
return(-0x9c);
memset(&scan, 0, sizeof(scan));
result = nwsalvage_scan_directory(dbe->nwpath.volume,
(char *)dbe->nwpath.path,
dbe->basehandle, scan_sequence, &scan);
if (result < 0)
return(-0x98);
if (result == 0)
return(-0xff);
result = nsp_salvage_scan_by_dbe(dbe, scan_sequence, &scan);
if (result)
return(result);
U32_TO_32((uint32)scan.scan_sequence, p); p += 4;
un_time_2_nw((time_t)scan.metadata.deleted_at, p, 0); p += 2;
@@ -2926,6 +2932,54 @@ static int nsp_salvage_find_current_by_dbe(DIR_BASE_ENTRY *dbe,
return(0);
}
static int nsp_salvage_recover_by_dbe(DIR_BASE_ENTRY *dbe,
unsigned long sequence, int task,
int exists_error,
struct nwsalvage_scan_result *scan)
{
char *dest_unixname;
int result;
result = nsp_salvage_find_current_by_dbe(dbe, sequence, scan);
if (result)
return(result);
dest_unixname = alloc_nwpath2unix_extra(&(dbe->nwpath), 0,
scan->metadata.original_name);
if (!dest_unixname)
return(-0x96);
result = nwsalvage_recover_scan_result(dbe->nwpath.volume, scan,
dest_unixname, task);
xfree(dest_unixname);
if (result < 0) {
if (errno == EEXIST)
return(exists_error);
return(-0x98);
}
if (result == 0)
return(-0xff);
return(0);
}
static int nsp_salvage_purge_by_dbe(DIR_BASE_ENTRY *dbe,
unsigned long sequence,
struct nwsalvage_scan_result *scan)
{
int result;
result = nsp_salvage_find_current_by_dbe(dbe, sequence, scan);
if (result)
return(result);
result = nwsalvage_purge_scan_result(scan);
if (result < 0)
return(-0x98);
if (result == 0)
return(-0xff);
return(0);
}
static int nsp_salvage_build_old_info(const struct nwsalvage_scan_result *scan,
uint8 *p)
{
@@ -2999,7 +3053,6 @@ int handle_func_0x16_salvage_recover(uint8 *q, int request_len,
int new_len;
DIR_BASE_ENTRY *dbe = NULL;
struct nwsalvage_scan_result scan;
char *dest_unixname;
int result;
(void)responsedata;
@@ -3020,26 +3073,10 @@ int handle_func_0x16_salvage_recover(uint8 *q, int request_len,
if (result < 0)
return(result);
result = nsp_salvage_find_current_by_dbe(dbe, sequence, &scan);
result = nsp_salvage_recover_by_dbe(dbe, sequence, task, -0xfe, &scan);
if (result)
return(result);
dest_unixname = alloc_nwpath2unix_extra(&(dbe->nwpath), 0,
scan.metadata.original_name);
if (!dest_unixname)
return(-0x96);
result = nwsalvage_recover_scan_result(dbe->nwpath.volume, &scan,
dest_unixname, task);
xfree(dest_unixname);
if (result < 0) {
if (errno == EEXIST)
return(-0xfe);
return(-0x98);
}
if (result == 0)
return(-0xff);
XDPRINTF((3, 0,
"INFO SALVAGE 22/28 DONE fn=0x16 sub=0x1c dh=0x%02x seq=0x%08lx name=\"%s\"",
dir_handle, (unsigned long)sequence, scan.metadata.original_name));
@@ -3068,16 +3105,10 @@ int handle_func_0x16_salvage_purge(uint8 *q, int request_len,
if (result < 0)
return(result);
result = nsp_salvage_find_current_by_dbe(dbe, sequence, &scan);
result = nsp_salvage_purge_by_dbe(dbe, sequence, &scan);
if (result)
return(result);
result = nwsalvage_purge_scan_result(&scan);
if (result < 0)
return(-0x98);
if (result == 0)
return(-0xff);
XDPRINTF((3, 0,
"INFO SALVAGE 22/29 DONE fn=0x16 sub=0x1d dh=0x%02x seq=0x%08lx name=\"%s\"",
dir_handle, (unsigned long)sequence, scan.metadata.original_name));
@@ -3091,10 +3122,8 @@ int handle_func_0x57_salvage_recover(uint8 *q, int request_len,
uint32 scan_sequence;
uint32 volume;
uint32 directory_base;
unsigned long previous_sequence;
int result;
DIR_BASE_ENTRY *dbe;
char *dest_unixname;
struct nwsalvage_scan_result scan;
(void)responsedata;
@@ -3131,31 +3160,10 @@ int handle_func_0x57_salvage_recover(uint8 *q, int request_len,
if (!S_ISDIR(dbe->nwpath.statb.st_mode))
return(-0x9c);
memset(&scan, 0, sizeof(scan));
previous_sequence = scan_sequence ? scan_sequence - 1 : 0xffffffffUL;
result = nwsalvage_scan_directory((int)volume, (char *)dbe->nwpath.path,
directory_base, previous_sequence, &scan);
if (result < 0)
return(-0x98);
if (result == 0 || scan.scan_sequence != scan_sequence ||
scan.scan_directory_base != directory_base)
return(-0xff);
dest_unixname = alloc_nwpath2unix_extra(&(dbe->nwpath), 0,
scan.metadata.original_name);
if (!dest_unixname)
return(-0x96);
result = nwsalvage_recover_scan_result((int)volume, &scan, dest_unixname,
task);
xfree(dest_unixname);
if (result < 0) {
if (errno == EEXIST)
return(-0x92);
return(-0x98);
}
if (result == 0)
return(-0xff);
result = nsp_salvage_recover_by_dbe(dbe, scan_sequence, task, -0x92,
&scan);
if (result)
return(result);
XDPRINTF((3, 0,
"NCP 87/17 salvage recover ns=%d seq=0x%lx vol=%lu base=0x%lx result=%d",
@@ -3198,16 +3206,10 @@ int handle_func_0x57_salvage_purge(uint8 *q, int request_len,
if (!S_ISDIR(dbe->nwpath.statb.st_mode))
return(-0x9c);
result = nsp_salvage_find_current_by_dbe(dbe, scan_sequence, &scan);
result = nsp_salvage_purge_by_dbe(dbe, scan_sequence, &scan);
if (result)
return(result);
result = nwsalvage_purge_scan_result(&scan);
if (result < 0)
return(-0x98);
if (result == 0)
return(-0xff);
XDPRINTF((3, 0,
"INFO SALVAGE 87/18 DONE fn=0x57 sub=0x12 ns=0x%02x seq=0x%08lx vol=0x%08lx base=0x%08lx name=\"%s\"",
namespace, (unsigned long)scan_sequence, (unsigned long)volume,