Files
mars-nwe/include/nwsalvage.h
ChatGPT 3fb45fd624
All checks were successful
Source release / source-package (push) Successful in 55s
salvage: hook delete path through nwsalvage
2026-05-31 13:35:58 +02:00

160 lines
5.7 KiB
C

#ifndef _NWSALVAGE_H_
#define _NWSALVAGE_H_
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
typedef int (*nwsalvage_ini_getter)(int entry, char *str,
size_t strsize, void *data);
#define NWSALVAGE_ENABLE_INI_SECTION 48
#define NWSALVAGE_REPOSITORY_INI_SECTION 49
#define NWSALVAGE_DEFAULT_ENABLED 1
#define NWSALVAGE_DEFAULT_RECYCLE_NAME ".recycle"
#define NWSALVAGE_DEFAULT_METADATA_NAME ".salvage"
#define NWSALVAGE_REPOSITORY_NAME_MAX 64
#define NWSALVAGE_PATH_MAX 4096
#define NWSALVAGE_NAME_MAX 256
#define NWSALVAGE_USER_NAME_MAX 128
#define NWSALVAGE_FINDER_INFO_HEX_LEN 64
#define NWSALVAGE_AFP_ENTRY_ID_MAX 32
#define NWSALVAGE_TRUSTEE_MAX 100
struct nwsalvage_config {
int enabled;
char recycle_repository[NWSALVAGE_REPOSITORY_NAME_MAX];
char metadata_repository[NWSALVAGE_REPOSITORY_NAME_MAX];
};
struct nwsalvage_trustee_entry {
unsigned long object_id;
unsigned int rights;
};
struct nwsalvage_deleted_entry {
const char *source;
const char *volume_name;
const char *deleted_by;
long deleted_at;
const char *original_path;
unsigned long original_parent_entry_id;
const char *original_name;
const char *recycle_relative_path;
const char *salvage_relative_path;
unsigned int attributes;
unsigned long mode;
unsigned long long size;
long atime;
long mtime;
long ctime;
const char *finder_info_hex;
const char *afp_entry_id;
unsigned int afp_attributes;
unsigned long long resource_fork_size;
unsigned int netware_archive_flags;
unsigned int netware_archive_date;
unsigned int netware_archive_time;
unsigned long netware_archiver_id;
unsigned int netware_fileinfo_flags;
unsigned int netware_create_date;
unsigned int netware_create_time;
unsigned long netware_creator_id;
unsigned long netware_modifier_id;
unsigned int inherited_rights_mask;
unsigned int trustee_count;
struct nwsalvage_trustee_entry trustees[NWSALVAGE_TRUSTEE_MAX];
};
struct nwsalvage_metadata_entry {
char source[NWSALVAGE_USER_NAME_MAX];
char volume_name[NWSALVAGE_REPOSITORY_NAME_MAX];
char deleted_by[NWSALVAGE_USER_NAME_MAX];
long deleted_at;
char original_path[NWSALVAGE_PATH_MAX];
unsigned long original_parent_entry_id;
char original_name[NWSALVAGE_NAME_MAX];
char recycle_relative_path[NWSALVAGE_PATH_MAX];
char salvage_relative_path[NWSALVAGE_PATH_MAX];
unsigned int attributes;
unsigned long mode;
unsigned long long size;
long atime;
long mtime;
long ctime;
char finder_info_hex[NWSALVAGE_FINDER_INFO_HEX_LEN + 1];
char afp_entry_id[NWSALVAGE_AFP_ENTRY_ID_MAX];
unsigned int afp_attributes;
unsigned long long resource_fork_size;
unsigned int netware_archive_flags;
unsigned int netware_archive_date;
unsigned int netware_archive_time;
unsigned long netware_archiver_id;
unsigned int netware_fileinfo_flags;
unsigned int netware_create_date;
unsigned int netware_create_time;
unsigned long netware_creator_id;
unsigned long netware_modifier_id;
unsigned int inherited_rights_mask;
unsigned int trustee_count;
struct nwsalvage_trustee_entry trustees[NWSALVAGE_TRUSTEE_MAX];
};
int nwsalvage_config_defaults(struct nwsalvage_config *config);
int nwsalvage_config_set_repositories(struct nwsalvage_config *config,
const char *recycle_repository,
const char *metadata_repository);
int nwsalvage_config_parse_enabled(struct nwsalvage_config *config,
const char *line);
int nwsalvage_config_parse_repositories(struct nwsalvage_config *config,
const char *line);
int nwsalvage_config_load_from_ini(struct nwsalvage_config *config,
nwsalvage_ini_getter getter,
void *data);
int nwsalvage_repository_name_valid(const char *name);
int nwsalvage_relative_path_valid(const char *relative_path);
int nwsalvage_build_recycle_relative_path(char *out, size_t out_len,
const struct nwsalvage_config *config,
const char *relative_path);
int nwsalvage_build_metadata_relative_path(char *out, size_t out_len,
const struct nwsalvage_config *config,
const char *relative_path);
int nwsalvage_build_recycle_path(char *out, size_t out_len,
const struct nwsalvage_config *config,
const char *volume_root,
const char *relative_path);
int nwsalvage_build_metadata_path(char *out, size_t out_len,
const struct nwsalvage_config *config,
const char *volume_root,
const char *relative_path);
int nwsalvage_write_metadata(const char *metadata_path,
const struct nwsalvage_deleted_entry *entry);
int nwsalvage_read_metadata(const char *metadata_path,
struct nwsalvage_metadata_entry *entry);
/*
* Capture a server-side delete before nw_unlink_node() would remove it.
* Returns 0 when the file was moved to the recycle repository and metadata
* was written. Returns 1 when salvage is disabled or the node is not
* salvageable and the caller should continue with the normal unlink path.
* Returns -1 on a real salvage failure; the caller should keep the live file.
*/
int nwsalvage_capture_node_delete(int volume, const char *unixname,
const struct stat *stb);
#endif