static INT64_T chirp_fs_local_rmall(const char *path) { PREAMBLE("rmall(`%s')", path); RESOLVE(path) rc = unlink_recursive(path); PROLOGUE }
static INT64_T chirp_fs_local_fsync(int fd) { PREAMBLE("fsync(%d)", fd); SETUP_FILE rc = fsync(lfd); PROLOGUE }
static INT64_T chirp_fs_local_unlink(const char *path) { PREAMBLE("unlink(`%s')", path); RESOLVE(path) rc = unlink(path); /* On Solaris, an unlink on a directory returns EPERM when it should return EISDIR. Check for this cast, and then fix it. */ if(rc < 0 && errno == EPERM) { struct stat64 linfo; rc = stat64(path, &linfo); if(rc == 0 && S_ISDIR(linfo.st_mode)) { rc = -1; errno = EISDIR; } else { rc = -1; errno = EPERM; } } PROLOGUE }
static INT64_T chirp_fs_local_lockf (int fd, int cmd, INT64_T len) { PREAMBLE("lockf(%d, 0o%o, %" PRId64 ")", fd, cmd, len); SETUP_FILE rc = lockf(lfd, cmd, len); PROLOGUE }
static INT64_T chirp_fs_local_ftruncate(int fd, INT64_T length) { PREAMBLE("ftruncate(%d, %" PRId64 ")", fd, length); SETUP_FILE rc = ftruncate64(lfd, length); PROLOGUE }
static int chirp_fs_local_fname (int fd, char path[CHIRP_PATH_MAX]) { PREAMBLE("fname(%d, %p)", fd, path); SETUP_FILE strcpy(path, open_files[fd].path); PROLOGUE }
static INT64_T chirp_fs_local_fstatfs(int fd, struct chirp_statfs *info) { PREAMBLE("fstatfs(%d, %p)", fd, info); SETUP_FILE struct statfs64 linfo; rc = fstatfs64(lfd, &linfo); if (rc == 0) COPY_STATFS_LOCAL_TO_CHIRP(*info, linfo); PROLOGUE }
static INT64_T chirp_fs_local_pwrite(int fd, const void *buffer, INT64_T length, INT64_T offset) { PREAMBLE("pwrite(%d, %p, %zu, %" PRId64 ")", fd, buffer, (size_t)length, offset); SETUP_FILE rc = full_pwrite64(lfd, buffer, length, offset); if(rc < 0 && errno == ESPIPE) { /* if this is a pipe, then just write without the offset. */ rc = full_write(lfd, buffer, length); } PROLOGUE }
static INT64_T chirp_fs_local_pread(int fd, void *buffer, INT64_T length, INT64_T offset) { PREAMBLE("pread(%d, %p, %zu, %" PRId64 ")", fd, buffer, (size_t)length, offset); SETUP_FILE rc = full_pread64(lfd, buffer, length, offset); if(rc < 0 && errno == ESPIPE) { /* if this is a pipe, return whatever amount is available */ rc = read(lfd, buffer, length); } PROLOGUE }
static INT64_T chirp_fs_local_close(int fd) { PREAMBLE("close(%d)", fd); SETUP_FILE rc = close(lfd); if (rc == 0) { open_files[fd].fd = -1; open_files[fd].path[0] = '\0'; } PROLOGUE }
static INT64_T chirp_fs_local_fchmod(int fd, INT64_T mode) { struct stat64 linfo; PREAMBLE("fchmod(%d, 0o%" PRIo64 ")", fd, mode); SETUP_FILE mode &= S_IXUSR|S_IRWXG|S_IRWXO; /* users can only set owner execute and group/other bits */ if (fstat64(lfd, &linfo) == -1) return -1; if(S_ISDIR(linfo.st_mode)) { mode |= S_IRWXU; /* all owner bits must be set */ } else { mode |= S_IRUSR|S_IWUSR; /* owner read/write must be set */ } rc = fchmod(lfd, mode); PROLOGUE }
static INT64_T chirp_fs_local_open(const char *path, INT64_T flags, INT64_T mode) { PREAMBLE("open(`%s', 0x%" PRIx64 ", 0o%" PRIo64 ")", path, flags, mode); const char *unresolved = path; RESOLVE(path) INT64_T fd = getfd(); if (fd == -1) return -1; mode &= S_IXUSR|S_IRWXG|S_IRWXO; mode |= S_IRUSR|S_IWUSR; rc = open64(path, flags, (int) mode); if (rc >= 0) { open_files[fd].fd = rc; strcpy(open_files[fd].path, unresolved); rc = fd; } PROLOGUE }
static int chirp_fs_local_init(const char url[CHIRP_PATH_MAX]) { PREAMBLE("init(`%s')", url); int i; char tmp[CHIRP_PATH_MAX]; for (i = 0; i < CHIRP_FILESYSTEM_MAXFD; i++) open_files[i].fd = -1; if (strprfx(url, "local://") || strprfx(url, "file://")) strcpy(tmp, strstr(url, "//")+2); else strcpy(tmp, url); path_collapse(tmp, local_root, 1); rc = create_dir(local_root, 0711); PROLOGUE }
static void hello_world (void) { int ch = 0; int i; pgno = -1; prints (" HELLO WORLD! "); PAUSE (30); ch = 4; TEXT_RESTART; prints ("Character set - Text 1"); CR; CR; for (i = 32; i <= 127; i++) { printc (i); if ((i & 15) == 15) CR; } MIDROW (italic, 0); for (i = 32; i <= 127; i++) { printc (i); if ((i & 15) == 15) CR; } MIDROW (white, underline); for (i = 32; i <= 127; i++) { printc (i); if ((i & 15) == 15) CR; } MIDROW (white, 0); prints ("Special: "); for (i = 0; i <= 15; i++) { SPECIAL_CHAR (i); } CR; prints ("DONE - Text 1 "); PAUSE (50); ch = 5; TEXT_RESTART; prints ("Styles - Text 2"); CR; CR; MIDROW (white, 0); prints ("WHITE"); CR; MIDROW (red, 0); prints ("RED"); CR; MIDROW (green, 0); prints ("GREEN"); CR; MIDROW (blue, 0); prints ("BLUE"); CR; MIDROW (yellow, 0); prints ("YELLOW"); CR; MIDROW (cyan, 0); prints ("CYAN"); CR; MIDROW (magenta, 0); prints ("MAGENTA"); BLACK (0); CR; BACKG (white, opaque); prints ("WHITE"); BACKG (black, opaque); CR; BACKG (red, opaque); prints ("RED"); BACKG (black, opaque); CR; BACKG (green, opaque); prints ("GREEN"); BACKG (black, opaque); CR; BACKG (blue, opaque); prints ("BLUE"); BACKG (black, opaque); CR; BACKG (yellow, opaque); prints ("YELLOW"); BACKG (black, opaque); CR; BACKG (cyan, opaque); prints ("CYAN"); BACKG (black, opaque); CR; BACKG (magenta, opaque); prints ("MAGENTA"); BACKG (black, opaque); CR; TRANSP; prints (" TRANSPARENT BACKGROUND "); BACKG (black, opaque); CR; MIDROW (white, 0); FLASH_ON; prints (" Flashing Text (if implemented) "); CR; MIDROW (white, 0); prints ("DONE - Text 2 "); PAUSE (50); ch = 0; ROLL_UP (2); ERASE_DISPLAY; prints (" ROLL-UP TEST "); CR; PAUSE (20); prints (">> A young Jedi named Darth"); CR; PAUSE (20); prints ("Vader, who was a pupil of"); CR; PAUSE (20); prints ("mine until he turned to evil,"); CR; PAUSE (20); prints ("helped the Empire hunt down"); CR; PAUSE (20); prints ("and destroy the Jedi Knights."); CR; PAUSE (20); prints ("He betrayed and murdered your"); CR; PAUSE (20); prints ("father. Now the Jedi are all"); CR; PAUSE (20); prints ("but extinct. Vader was seduced"); CR; PAUSE (20); prints ("by the dark side of the Force."); CR; PAUSE (20); prints (">> The Force?"); CR; PAUSE (20); prints (">> Well, the Force is what gives"); CR; PAUSE (20); prints ("a Jedi his power. It's an energy"); CR; PAUSE (20); prints ("field created by all living"); CR; PAUSE (20); prints ("things."); CR; PAUSE (20); prints ("It surrounds us and penetrates"); CR; PAUSE (20); prints ("us."); CR; PAUSE (20); prints ("It binds the galaxy together."); CR; PAUSE (20); CR; PAUSE (30); prints (" DONE - Caption 1 "); PAUSE (30); ch = 1; RESUME_DIRECT; ERASE_DISPLAY; MIDROW (yellow, 0); INDENT (2, 10, 0); prints (" FOO "); CR; INDENT (3, 10, 0); prints (" MIKE WAS HERE "); CR; PAUSE (20); MIDROW (red, 0); INDENT (6, 13, 0); prints (" AND NOW... "); CR; INDENT (8, 13, 0); prints (" HE'S HERE "); CR; PAUSE (20); PREAMBLE (12, cyan, 0); prints ("01234567890123456789012345678901234567890123456789"); CR; MIDROW (white, 0); prints (" DONE - Caption 2 "); CR; PAUSE (30); }