[Coco] Undocumented NitrOS9 system call (Boisy?)
Barry Nelson
barry.nelson at amobiledevice.com
Thu Nov 5 04:21:19 EST 2015
In some old C code for a dir command I have I found this function I was using to read the file attributes. The variable inp is a pointer to a file handle to the device that is left open until the program exits. The character string dir is the directory being read. Once inp is open, multiple calls can be made to get_fd to get file descriptors on that device. The variable s->dir_addr is the LSN of the file descriptor from the directory entry.
int inp;
char indev[8];
char *dir;
struct fildesc ifdes;
struct dirent *s;
get_dev(dir, indev);
if ((inp = open(indev, READ)) == -1) {
write(STDERR, "Error reading input device.\n", 28);
exit(errno);
}
get_fd(inp, &ifdes, s->dir_addr);
/*
** seek to 'pos' on device 'pn' and read
** 'fildes' bytes into 'buf'
*/
get_fd(pn, buf, pos)
int pn;
struct fildesc *buf;
char *pos;
{
l3seek(pn, pos);
if ((read(pn, buf, sizeof(struct fildesc))) == -1) {
write(STDERR, "Error reading file desc.\n", 25);
exit(errno);
}
}
/*
** seek to the LSN specified by the 3 char string 'pos'
*/
l3seek(pn, pos)
int pn;
char *pos;
{
long lpos;
int j;
register char *p = &lpos;
for (j = 3; j ; j--)
*p++ = *pos++;
*p = 0;
lseek(pn, lpos, 0);
}
/*
** return in 'buf' the device name where
** file 's' resides.
*/
get_dev(s, buf)
char *s, *buf;
{
char temp[32];
int pn;
if ((pn = open(s, DIR + READ + flag)) == -1)
return(-1);
lgetstat(pn, SS_DEVNM, temp, 0, 0);
*buf++ = '/';
strhcpy(buf, temp);
strcat(buf, "@");
close(pn);
}
/*
** local getstat
** r_a = path number r_b = code
** r_x = parameter r_y = parameter r_u = parameter
*/
lgetstat(r_a, r_b, r_x, r_y, r_u)
char r_a, r_b;
int r_x, r_y, r_u;
{
struct registers reg;
reg.rg_a = r_a;
reg.rg_b = r_b;
reg.rg_x = r_x;
reg.rg_y = r_y;
reg.rg_u = r_u;
if (_os9(I_GETSTT, ®) == -1)
exit(reg.rg_b);
return(reg.rg_x);
}
More information about the Coco
mailing list