tools: add shared endian helpers
Move common little-endian and big-endian buffer helpers into tools.c and declare them in net.h. Replace local duplicate implementations in FLAG, FLAGDIR and NDIR with the shared helpers. This keeps the existing packet layouts unchanged while reducing copy/paste code across the DOS utilities. NCOPY and the experimental NCP copy code are intentionally left untouched for now.
This commit is contained in:
37
flag.c
37
flag.c
@@ -56,27 +56,6 @@
|
||||
#define NWFA_DI 0x00040000UL
|
||||
#define NWFA_CI 0x00080000UL
|
||||
|
||||
static void flag_put_word_lh(uint8 *p, uint16 v)
|
||||
{
|
||||
p[0] = (uint8)(v & 0xff);
|
||||
p[1] = (uint8)((v >> 8) & 0xff);
|
||||
}
|
||||
|
||||
static void flag_put_dword_lh(uint8 *p, uint32 v)
|
||||
{
|
||||
p[0] = (uint8)(v & 0xff);
|
||||
p[1] = (uint8)((v >> 8) & 0xff);
|
||||
p[2] = (uint8)((v >> 16) & 0xff);
|
||||
p[3] = (uint8)((v >> 24) & 0xff);
|
||||
}
|
||||
|
||||
static uint32 flag_get_dword_lh(uint8 *p)
|
||||
{
|
||||
return((uint32)p[0] |
|
||||
((uint32)p[1] << 8) |
|
||||
((uint32)p[2] << 16) |
|
||||
((uint32)p[3] << 24));
|
||||
}
|
||||
|
||||
static int flag_add_handle_path(uint8 *p, uint8 dhandle, char *name)
|
||||
{
|
||||
@@ -93,7 +72,7 @@ static int flag_add_handle_path(uint8 *p, uint8 dhandle, char *name)
|
||||
* path components: 1 component, length, bytes
|
||||
*/
|
||||
*p++ = dhandle;
|
||||
flag_put_dword_lh(p, 0L); p += 4;
|
||||
tool_put_dword_lh(p, 0L); p += 4;
|
||||
*p++ = 0; /* dirstyle = handle */
|
||||
*p++ = 1; /* one path component */
|
||||
*p++ = (uint8)nlen;
|
||||
@@ -136,8 +115,8 @@ static int flag_ncp87_obtain_attrs(char *name, uint32 *attrs)
|
||||
*p++ = 6; /* subfunction: obtain file/subdir info */
|
||||
*p++ = FLAG_NW_NS_DOS; /* source namespace */
|
||||
*p++ = FLAG_NW_NS_DOS; /* target namespace */
|
||||
flag_put_word_lh(p, FLAG_SA_ALL); p += 2;
|
||||
flag_put_dword_lh(p, FLAG_RIM_ATTRIBUTES); p += 4;
|
||||
tool_put_word_lh(p, FLAG_SA_ALL); p += 2;
|
||||
tool_put_dword_lh(p, FLAG_RIM_ATTRIBUTES); p += 4;
|
||||
hlen = flag_add_handle_path(p, dhandle, name);
|
||||
p += hlen;
|
||||
|
||||
@@ -153,7 +132,7 @@ static int flag_ncp87_obtain_attrs(char *name, uint32 *attrs)
|
||||
* First dword is the 32-bit Attributes field.
|
||||
*/
|
||||
if (attrs)
|
||||
*attrs = flag_get_dword_lh(repl.data);
|
||||
*attrs = tool_get_dword_lh(repl.data);
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -231,7 +210,7 @@ static int flag_ncp22_1e_obtain_attrs(char *name, uint32 *attrs)
|
||||
* ...
|
||||
*/
|
||||
if (attrs)
|
||||
*attrs = flag_get_dword_lh(repl.data + 8);
|
||||
*attrs = tool_get_dword_lh(repl.data + 8);
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -332,10 +311,10 @@ static int flag_ncp87_modify_attrs(char *name, uint32 attrs)
|
||||
*p++ = 7; /* subfunction: modify DOS info */
|
||||
*p++ = FLAG_NW_NS_DOS;
|
||||
*p++ = 0; /* reserved */
|
||||
flag_put_word_lh(p, FLAG_SA_ALL); p += 2;
|
||||
tool_put_word_lh(p, FLAG_SA_ALL); p += 2;
|
||||
|
||||
flag_put_dword_lh(p, FLAG_DM_ATTRIBUTES); p += 4; /* modify mask: DM_ATTRIBUTES */
|
||||
flag_put_dword_lh(p, attrs); p += 4; /* Attributes */
|
||||
tool_put_dword_lh(p, FLAG_DM_ATTRIBUTES); p += 4; /* modify mask: DM_ATTRIBUTES */
|
||||
tool_put_dword_lh(p, attrs); p += 4; /* Attributes */
|
||||
|
||||
/*
|
||||
* Remaining ncp_dos_info fields. Mask says only Attributes is valid,
|
||||
|
||||
19
flagdir.c
19
flagdir.c
@@ -55,21 +55,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
static void fd_put_dword_lh(uint8 *p, uint32 v)
|
||||
{
|
||||
p[0] = (uint8)(v & 0xff);
|
||||
p[1] = (uint8)((v >> 8) & 0xff);
|
||||
p[2] = (uint8)((v >> 16) & 0xff);
|
||||
p[3] = (uint8)((v >> 24) & 0xff);
|
||||
}
|
||||
|
||||
static uint32 fd_get_dword_lh(uint8 *p)
|
||||
{
|
||||
return((uint32)p[0] |
|
||||
((uint32)p[1] << 8) |
|
||||
((uint32)p[2] << 16) |
|
||||
((uint32)p[3] << 24));
|
||||
}
|
||||
|
||||
static int fd_copy_ncp22_name(uint8 *dst, char *src, uint8 *len_out)
|
||||
{
|
||||
@@ -136,7 +121,7 @@ static int fd_ncp22_1e_obtain_attrs(char *name, uint32 *attrs)
|
||||
|
||||
/* NCP22/30 Scan Directory returns attributes at offset 8. */
|
||||
if (attrs)
|
||||
*attrs = fd_get_dword_lh(repl.data + 8);
|
||||
*attrs = tool_get_dword_lh(repl.data + 8);
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -176,7 +161,7 @@ static int fd_ncp22_25_modify_attrs(char *name, uint32 attrs)
|
||||
req.search_attributes = 0x16; /* hidden/system/subdir */
|
||||
U32_TO_BE32(0xffffffffUL, req.searchsequence);
|
||||
U32_TO_32(FD_DM_ATTRIBUTES, req.change_bits);
|
||||
fd_put_dword_lh(req.attributes, attrs);
|
||||
tool_put_dword_lh(req.attributes, attrs);
|
||||
|
||||
if (fd_copy_ncp22_name(req.name, name, &req.namlen))
|
||||
return(-1);
|
||||
|
||||
9
ndir.c
9
ndir.c
@@ -502,13 +502,6 @@ static void ndir_old_rights_string(uint8 old_rights, char *out)
|
||||
}
|
||||
|
||||
|
||||
static uint32 ndir_get_dword_lh(uint8 *p)
|
||||
{
|
||||
return((uint32)p[0] |
|
||||
((uint32)p[1] << 8) |
|
||||
((uint32)p[2] << 16) |
|
||||
((uint32)p[3] << 24));
|
||||
}
|
||||
|
||||
static int ndir_copy_ncp22_name(uint8 *dst, char *src, uint8 *len_out)
|
||||
{
|
||||
@@ -583,7 +576,7 @@ static int ndir_ncp22_scan_entry(char *name, int want_dir, uint32 *attrs)
|
||||
* Client32 namespace calls are used for richer metadata.
|
||||
*/
|
||||
if (attrs)
|
||||
*attrs = ndir_get_dword_lh(repl.data + 8);
|
||||
*attrs = tool_get_dword_lh(repl.data + 8);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
8
net.h
8
net.h
@@ -167,6 +167,14 @@ extern void get_path_fn(char *s, char *p, char *fn);
|
||||
|
||||
/* Shared DOS utility helpers. Keep command frontends small so the
|
||||
* historical multicall net.exe can later be split into smaller groups. */
|
||||
extern void tool_put_word_lh(uint8 *p, uint16 v);
|
||||
extern void tool_put_dword_lh(uint8 *p, uint32 v);
|
||||
extern uint16 tool_get_word_lh(uint8 *p);
|
||||
extern uint32 tool_get_dword_lh(uint8 *p);
|
||||
extern void tool_put_word_hl(uint8 *p, uint16 v);
|
||||
extern void tool_put_dword_hl(uint8 *p, uint32 v);
|
||||
extern uint16 tool_get_word_hl(uint8 *p);
|
||||
extern uint32 tool_get_dword_hl(uint8 *p);
|
||||
extern int tool_strsame(char *a, char *b);
|
||||
extern int tool_is_help_arg(char *s);
|
||||
extern int tool_is_option(char *s);
|
||||
|
||||
102
tools.c
102
tools.c
@@ -25,6 +25,108 @@
|
||||
|
||||
#include "net.h"
|
||||
|
||||
/*
|
||||
* tool_put_word_lh
|
||||
*
|
||||
* Purpose:
|
||||
* Stores a 16-bit value in NetWare low-high (little-endian) order.
|
||||
*/
|
||||
void tool_put_word_lh(uint8 *p, uint16 v)
|
||||
{
|
||||
p[0] = (uint8)(v & 0xff);
|
||||
p[1] = (uint8)((v >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_put_dword_lh
|
||||
*
|
||||
* Purpose:
|
||||
* Stores a 32-bit value in NetWare low-high (little-endian) order.
|
||||
*/
|
||||
void tool_put_dword_lh(uint8 *p, uint32 v)
|
||||
{
|
||||
p[0] = (uint8)(v & 0xff);
|
||||
p[1] = (uint8)((v >> 8) & 0xff);
|
||||
p[2] = (uint8)((v >> 16) & 0xff);
|
||||
p[3] = (uint8)((v >> 24) & 0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_get_word_lh
|
||||
*
|
||||
* Purpose:
|
||||
* Reads a 16-bit value stored in NetWare low-high order.
|
||||
*/
|
||||
uint16 tool_get_word_lh(uint8 *p)
|
||||
{
|
||||
return((uint16)p[0] | ((uint16)p[1] << 8));
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_get_dword_lh
|
||||
*
|
||||
* Purpose:
|
||||
* Reads a 32-bit value stored in NetWare low-high order.
|
||||
*/
|
||||
uint32 tool_get_dword_lh(uint8 *p)
|
||||
{
|
||||
return((uint32)p[0] |
|
||||
((uint32)p[1] << 8) |
|
||||
((uint32)p[2] << 16) |
|
||||
((uint32)p[3] << 24));
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_put_word_hl
|
||||
*
|
||||
* Purpose:
|
||||
* Stores a 16-bit value in NetWare high-low (big-endian) order.
|
||||
*/
|
||||
void tool_put_word_hl(uint8 *p, uint16 v)
|
||||
{
|
||||
p[0] = (uint8)((v >> 8) & 0xff);
|
||||
p[1] = (uint8)(v & 0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_put_dword_hl
|
||||
*
|
||||
* Purpose:
|
||||
* Stores a 32-bit value in NetWare high-low (big-endian) order.
|
||||
*/
|
||||
void tool_put_dword_hl(uint8 *p, uint32 v)
|
||||
{
|
||||
p[0] = (uint8)((v >> 24) & 0xff);
|
||||
p[1] = (uint8)((v >> 16) & 0xff);
|
||||
p[2] = (uint8)((v >> 8) & 0xff);
|
||||
p[3] = (uint8)(v & 0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_get_word_hl
|
||||
*
|
||||
* Purpose:
|
||||
* Reads a 16-bit value stored in NetWare high-low order.
|
||||
*/
|
||||
uint16 tool_get_word_hl(uint8 *p)
|
||||
{
|
||||
return(((uint16)p[0] << 8) | (uint16)p[1]);
|
||||
}
|
||||
|
||||
/*
|
||||
* tool_get_dword_hl
|
||||
*
|
||||
* Purpose:
|
||||
* Reads a 32-bit value stored in NetWare high-low order.
|
||||
*/
|
||||
uint32 tool_get_dword_hl(uint8 *p)
|
||||
{
|
||||
return(((uint32)p[0] << 24) |
|
||||
((uint32)p[1] << 16) |
|
||||
((uint32)p[2] << 8) |
|
||||
(uint32)p[3]);
|
||||
}
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
/*
|
||||
* Borland C compatibility wrappers used by the historical mars-nwe DOS tools.
|
||||
|
||||
Reference in New Issue
Block a user