tests: use ncplib for salvage NCP delete smoke
All checks were successful
Source release / source-package (push) Successful in 55s
All checks were successful
Source release / source-package (push) Successful in 55s
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
/*
|
||||
* Linux smoke helper for classic NetWare file create/delete.
|
||||
*
|
||||
* The helper intentionally uses normal NCP file create/close/delete requests,
|
||||
* not a local Unix unlink. It is used by the salvage smoke script to verify
|
||||
* that mars_nwe captures files deleted through the server path.
|
||||
* The helper intentionally uses the official ncpfs ncplib create/close/erase
|
||||
* APIs, not private request packing or a local Unix unlink. It is used by
|
||||
* the salvage smoke script to verify that mars_nwe captures files deleted
|
||||
* through the server path.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@@ -16,14 +17,6 @@
|
||||
#include <ncp/ncplib.h>
|
||||
#include <ncp/kernel/ncp.h>
|
||||
|
||||
#define NCP_CREATE_FILE_OVERWRITE 0x43
|
||||
#define NCP_CLOSE_FILE 0x42
|
||||
#define NCP_DELETE_FILE 0x44
|
||||
#define NWE_INVALID_PATH 0x9c
|
||||
#ifndef NWE_INVALID_NCP_PACKET_LENGTH
|
||||
#define NWE_INVALID_NCP_PACKET_LENGTH 0x7e
|
||||
#endif
|
||||
|
||||
static void usage(const char *prog)
|
||||
{
|
||||
fprintf(stderr,
|
||||
@@ -51,94 +44,6 @@ static int parse_u32(const char *text, uint32_t *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t le32_to_cpu(const uint8_t p[4])
|
||||
{
|
||||
return ((uint32_t)p[0]) |
|
||||
((uint32_t)p[1] << 8) |
|
||||
((uint32_t)p[2] << 16) |
|
||||
((uint32_t)p[3] << 24);
|
||||
}
|
||||
|
||||
static void cpu_to_le32(uint32_t v, uint8_t p[4])
|
||||
{
|
||||
p[0] = (uint8_t)v;
|
||||
p[1] = (uint8_t)(v >> 8);
|
||||
p[2] = (uint8_t)(v >> 16);
|
||||
p[3] = (uint8_t)(v >> 24);
|
||||
}
|
||||
|
||||
static NWCCODE ncp_create_file(NWCONN_HANDLE conn, const char *path,
|
||||
uint32_t *file_handle)
|
||||
{
|
||||
size_t path_len = strlen(path);
|
||||
uint8_t request[1 + 1 + 1 + 255];
|
||||
uint8_t reply_buf[2 + 4 + 2 + 64];
|
||||
NW_FRAGMENT reply;
|
||||
NWCCODE err;
|
||||
|
||||
if (path_len > 255)
|
||||
return NWE_INVALID_PATH;
|
||||
|
||||
request[0] = 0; /* directory handle 0, raw VOL:path */
|
||||
request[1] = 0; /* create attributes */
|
||||
request[2] = (uint8_t)path_len;
|
||||
memcpy(request + 3, path, path_len);
|
||||
|
||||
memset(reply_buf, 0, sizeof(reply_buf));
|
||||
reply.fragAddr.rw = reply_buf;
|
||||
reply.fragSize = sizeof(reply_buf);
|
||||
|
||||
err = NWRequestSimple(conn, NCP_CREATE_FILE_OVERWRITE,
|
||||
request, 3 + path_len, &reply);
|
||||
if (err)
|
||||
return err;
|
||||
if (reply.fragSize < 6)
|
||||
return NWE_INVALID_NCP_PACKET_LENGTH;
|
||||
|
||||
*file_handle = le32_to_cpu(reply_buf + 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NWCCODE ncp_close_file(NWCONN_HANDLE conn, uint32_t file_handle)
|
||||
{
|
||||
uint8_t request[1 + 2 + 4];
|
||||
NW_FRAGMENT reply;
|
||||
NWCCODE err;
|
||||
|
||||
memset(request, 0, sizeof(request));
|
||||
request[0] = 0; /* reserved */
|
||||
request[1] = 0;
|
||||
request[2] = 0; /* extended file handle */
|
||||
cpu_to_le32(file_handle, request + 3);
|
||||
|
||||
reply.fragAddr.rw = NULL;
|
||||
reply.fragSize = 0;
|
||||
|
||||
err = NWRequestSimple(conn, NCP_CLOSE_FILE,
|
||||
request, sizeof(request), &reply);
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWCCODE ncp_delete_file(NWCONN_HANDLE conn, const char *path)
|
||||
{
|
||||
size_t path_len = strlen(path);
|
||||
uint8_t request[1 + 1 + 1 + 255];
|
||||
NW_FRAGMENT reply;
|
||||
|
||||
if (path_len > 255)
|
||||
return NWE_INVALID_PATH;
|
||||
|
||||
request[0] = 0; /* directory handle 0, raw VOL:path */
|
||||
request[1] = 0; /* search attributes */
|
||||
request[2] = (uint8_t)path_len;
|
||||
memcpy(request + 3, path, path_len);
|
||||
|
||||
reply.fragAddr.rw = NULL;
|
||||
reply.fragSize = 0;
|
||||
|
||||
return NWRequestSimple(conn, NCP_DELETE_FILE,
|
||||
request, 3 + path_len, &reply);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -146,11 +51,11 @@ int main(int argc, char **argv)
|
||||
long init_err = 0;
|
||||
const char *path = NULL;
|
||||
uint32_t expect_delete = 0xffffffffU;
|
||||
uint32_t file_handle = 0;
|
||||
struct ncp_file_info file_info;
|
||||
int create = 1;
|
||||
int delete = 1;
|
||||
int i;
|
||||
NWCCODE err;
|
||||
long err;
|
||||
|
||||
if (NWCallsInit(NULL, NULL)) {
|
||||
fprintf(stderr, "NWCallsInit failed\n");
|
||||
@@ -199,29 +104,29 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (create) {
|
||||
err = ncp_create_file(conn, path, &file_handle);
|
||||
memset(&file_info, 0, sizeof(file_info));
|
||||
err = ncp_create_file(conn, 0, path, 0, &file_info);
|
||||
if (err) {
|
||||
fprintf(stderr, "NCP create failed: path=%s error=0x%04x\n",
|
||||
path, (unsigned int)err);
|
||||
ncp_close(conn);
|
||||
return 1;
|
||||
}
|
||||
err = ncp_close_file(conn, file_handle);
|
||||
err = ncp_close_file(conn, file_info.file_id);
|
||||
if (err) {
|
||||
fprintf(stderr,
|
||||
"NCP close failed: path=%s handle=0x%08x error=0x%04x\n",
|
||||
path, (unsigned int)file_handle, (unsigned int)err);
|
||||
"NCP close failed: path=%s error=0x%04x\n",
|
||||
path, (unsigned int)err);
|
||||
ncp_close(conn);
|
||||
return 1;
|
||||
}
|
||||
printf("NCP create path=%s handle=0x%08x verified\n",
|
||||
path, (unsigned int)file_handle);
|
||||
printf("NCP create path=%s verified\n", path);
|
||||
}
|
||||
|
||||
if (delete) {
|
||||
err = ncp_delete_file(conn, path);
|
||||
err = ncp_erase_file(conn, 0, path, 0);
|
||||
if (expect_delete != 0xffffffffU) {
|
||||
if (err != (NWCCODE)expect_delete) {
|
||||
if (err != (long)expect_delete) {
|
||||
fprintf(stderr,
|
||||
"NCP delete completion mismatch: path=%s got=0x%04x expected=0x%02x\n",
|
||||
path, (unsigned int)err, (unsigned int)expect_delete);
|
||||
|
||||
Reference in New Issue
Block a user