feat: add Client32 NCP support for FLAG

This commit is contained in:
Mario Fetka
2026-05-23 22:13:54 +02:00
parent 7f98d73738
commit 87c1e50cf9
9 changed files with 432 additions and 2461 deletions

101
flag.c
View File

@@ -1,6 +1,7 @@
/* flag.c - Novell FLAG-like DOS utility, stage 1 */
#include "net.h"
#include "c32ncp.h"
#include <dos.h>
/*
@@ -121,6 +122,14 @@ static int flag_ncp87_obtain_attrs(char *name, uint32 *attrs)
if (flag_current_dhandle(&dhandle))
return(-1);
/*
* Prefer the verified Client32 NCP87 path. If it is not available,
* fall back to the historical INT 21h/Net_Call path below.
*/
if (c32_ncp87_obtain_rim_attributes(name, (uint16)dhandle,
attrs, NULL, NULL, NULL) == 0)
return(0);
memset(&req, 0, sizeof(req));
memset(&repl, 0, sizeof(repl));
@@ -167,6 +176,19 @@ static int flag_ncp87_modify_attrs(char *name, uint32 attrs)
if (flag_current_dhandle(&dhandle))
return(-1);
/*
* Prefer verified Client32 modify path. The old INT 21h/F257 modify path
* can hang under DOS Client32 for high FLAG bits such as T/P/DI/RI.
*/
{
uint16 actual = 0;
uint16 hlo = 0;
uint16 hhi = 0;
if (!c32_ncp87_modify_dos_attributes(name, (uint16)dhandle, attrs,
&actual, &hlo, &hhi))
return(0);
}
memset(&req, 0, sizeof(req));
memset(&repl, 0, sizeof(repl));
@@ -257,7 +279,7 @@ static void flag_help(void)
fprintf(stdout, "SUB\n");
}
static int flag_attr_mask(char *s, unsigned *setbits, unsigned *clearbits)
static int flag_attr_mask(char *s, uint32 *setbits, uint32 *clearbits)
{
int set = 1;
char *p = s;
@@ -274,51 +296,51 @@ static int flag_attr_mask(char *s, unsigned *setbits, unsigned *clearbits)
if (flag_same(p, "RO")) {
if (set) {
*setbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
*setbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
} else {
*clearbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
*clearbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
}
} else if (flag_same(p, "RW")) {
*clearbits |= (unsigned)(NWFA_RO | NWFA_DI | NWFA_RI);
*clearbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "S")) {
if (set) *setbits |= (unsigned)NWFA_S;
else *clearbits |= (unsigned)NWFA_S;
if (set) *setbits |= NWFA_S;
else *clearbits |= NWFA_S;
} else if (flag_same(p, "H")) {
if (set) *setbits |= (unsigned)NWFA_H;
else *clearbits |= (unsigned)NWFA_H;
if (set) *setbits |= NWFA_H;
else *clearbits |= NWFA_H;
} else if (flag_same(p, "SY") || flag_same(p, "SYS") || flag_same(p, "SYSTEM")) {
if (set) *setbits |= (unsigned)NWFA_SY;
else *clearbits |= (unsigned)NWFA_SY;
if (set) *setbits |= NWFA_SY;
else *clearbits |= NWFA_SY;
} else if (flag_same(p, "T")) {
if (set) *setbits |= (unsigned)NWFA_T;
else *clearbits |= (unsigned)NWFA_T;
if (set) *setbits |= NWFA_T;
else *clearbits |= NWFA_T;
} else if (flag_same(p, "P")) {
if (set) *setbits |= (unsigned)NWFA_P;
else *clearbits |= (unsigned)NWFA_P;
if (set) *setbits |= NWFA_P;
else *clearbits |= NWFA_P;
} else if (flag_same(p, "A")) {
if (set) *setbits |= (unsigned)NWFA_A;
else *clearbits |= (unsigned)NWFA_A;
if (set) *setbits |= NWFA_A;
else *clearbits |= NWFA_A;
} else if (flag_same(p, "RA")) {
if (set) *setbits |= (unsigned)NWFA_RA;
else *clearbits |= (unsigned)NWFA_RA;
if (set) *setbits |= NWFA_RA;
else *clearbits |= NWFA_RA;
} else if (flag_same(p, "WA")) {
if (set) *setbits |= (unsigned)NWFA_WA;
else *clearbits |= (unsigned)NWFA_WA;
if (set) *setbits |= NWFA_WA;
else *clearbits |= NWFA_WA;
} else if (flag_same(p, "CI")) {
if (set) *setbits |= (unsigned)NWFA_CI;
else *clearbits |= (unsigned)NWFA_CI;
if (set) *setbits |= NWFA_CI;
else *clearbits |= NWFA_CI;
} else if (flag_same(p, "DI")) {
if (set) *setbits |= (unsigned)NWFA_DI;
else *clearbits |= (unsigned)NWFA_DI;
if (set) *setbits |= NWFA_DI;
else *clearbits |= NWFA_DI;
} else if (flag_same(p, "RI")) {
if (set) *setbits |= (unsigned)NWFA_RI;
else *clearbits |= (unsigned)NWFA_RI;
if (set) *setbits |= NWFA_RI;
else *clearbits |= NWFA_RI;
} else if (flag_same(p, "N") || flag_same(p, "NORMAL")) {
*clearbits |= (unsigned)(NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
*clearbits |= (NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "ALL")) {
*setbits |= (unsigned)(NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
*setbits |= (NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
} else {
@@ -329,18 +351,19 @@ static int flag_attr_mask(char *s, unsigned *setbits, unsigned *clearbits)
return(0);
}
static void flag_print_attrs(unsigned attr)
static void flag_print_attrs(uint32 attr)
{
/*
* Novell order:
* RO/RW S A H Sy T P RA WA CI DI RI
* Ro/Rw S A - H Sy T P Ra Wa CI DI RI
*/
fprintf(stdout, "[ ");
fprintf(stdout, "%s ", (attr & NWFA_RO) ? "RO" : "Rw");
fprintf(stdout, "%s ", (attr & NWFA_RO) ? "Ro" : "Rw");
fprintf(stdout, "%c ", (attr & NWFA_S) ? 'S' : '-');
fprintf(stdout, "%c ", (attr & NWFA_A) ? 'A' : '-');
fprintf(stdout, "- ");
fprintf(stdout, "%c ", (attr & NWFA_H) ? 'H' : '-');
fprintf(stdout, "%s ", (attr & NWFA_SY) ? "Sy" : "-");
fprintf(stdout, "%s ", (attr & NWFA_SY) ? "Sy" : "--");
fprintf(stdout, "%c ", (attr & NWFA_T) ? 'T' : '-');
fprintf(stdout, "%c ", (attr & NWFA_P) ? 'P' : '-');
fprintf(stdout, "%s ", (attr & NWFA_RA) ? "Ra" : "--");
@@ -351,7 +374,7 @@ static void flag_print_attrs(unsigned attr)
fprintf(stdout, "]");
}
static void flag_display_one(char *name, unsigned attr)
static void flag_display_one(char *name, uint32 attr)
{
fprintf(stdout, " %-23s ", name);
flag_print_attrs(attr);
@@ -383,7 +406,7 @@ static int flag_list(char *pattern)
if (flag_ncp87_obtain_attrs(ff.name, &nwattrs))
nwattrs = (uint32)ff.attrib;
flag_display_one(ff.name, (unsigned)nwattrs);
flag_display_one(ff.name, nwattrs);
found++;
}
} while (!_dos_findnext(&ff));
@@ -391,7 +414,7 @@ static int flag_list(char *pattern)
return(found);
}
static int flag_apply(char *pattern, unsigned setbits, unsigned clearbits)
static int flag_apply(char *pattern, uint32 setbits, uint32 clearbits)
{
struct find_t ff;
unsigned findattr = _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH;
@@ -416,7 +439,7 @@ static int flag_apply(char *pattern, unsigned setbits, unsigned clearbits)
if (newattrs != attrs) {
if (flag_ncp87_modify_attrs(fname, newattrs)) {
unsigned dosattr = (unsigned)(newattrs & (_A_RDONLY|_A_HIDDEN|_A_SYSTEM|_A_ARCH));
unsigned dosattr = (newattrs & (_A_RDONLY|_A_HIDDEN|_A_SYSTEM|_A_ARCH));
if (_dos_setfileattr(fname, dosattr)) {
fprintf(stderr, "You don't have rights to change : %s\n", fname);
continue;
@@ -427,7 +450,7 @@ static int flag_apply(char *pattern, unsigned setbits, unsigned clearbits)
if (flag_ncp87_obtain_attrs(fname, &attrs))
attrs = newattrs;
flag_display_one(fname, (unsigned)attrs);
flag_display_one(fname, newattrs);
shown++;
} while (!_dos_findnext(&ff));
@@ -439,8 +462,8 @@ int func_flag(int argc, char *argv[], int mode)
{
char *path = "*.*";
int i;
unsigned setbits = 0;
unsigned clearbits = 0;
uint32 setbits = 0;
uint32 clearbits = 0;
int have_change = 0;
int rc;