#include "gbos.h" /* ln TARGET NAME: give an existing file a second name. * * A real hard link, not a copy: both names share one inode, so the data is * stored once and `rm` only frees it when the last name goes. gbfs always had * the link count - nothing had ever incremented it. * * The syscall takes a request block (two paths, and the trap needs HL for its * dispatch table), and that block is a static living at $A000 - so the paths * are copied to the stack first, like every other program that has statics. */ static unsigned char req[4]; void main(void) { char paths[64]; char *argv[4]; unsigned char argc = argv_parse(argv, 4); unsigned char i, j = 0; char *tgt, *name; if (argc < 2) { puts("usage: ln TARGET NAME"); nl(); sexit(2); } tgt = paths; for (i = 0; argv[0][i] && j < 30; i++) paths[j++] = argv[0][i]; paths[j++] = 0; name = paths + j; for (i = 0; argv[1][i] && j < 62; i++) paths[j++] = argv[1][i]; paths[j] = 0; req[0] = (unsigned char)(unsigned int)tgt; req[1] = (unsigned char)(((unsigned int)tgt) >> 8); req[2] = (unsigned char)(unsigned int)name; req[3] = (unsigned char)(((unsigned int)name) >> 8); if (sys_link(req) != 0) { puts("ln: cannot link "); puts(name); nl(); sexit(1); } }