static int dkpart_init(struct Device_Conf *cf, const char *pfx, int dkno, int partno, offset_t start, offset_t len, FILE *cont, const char *fstype, const char *mntpt){ struct DiskPart *dkp = alloc(sizeof(struct DiskPart)); // name this if( mntpt ){ snprintf(dkp->name, sizeof(dkp->name), "%s", mntpt); }else{ snprintf(dkp->name, sizeof(dkp->name), "%s%d%c:", pfx, dkno, partno + 'a'); } dkp->flags = cf->flags; dkp->fdev = cont; dkp->part_offset = start * DISK_BLOCK_SIZE; dkp->part_len = len * DISK_BLOCK_SIZE; finit( & dkp->file ); dkp->file.d = (void*)dkp; dkp->file.fs = &dkpart_fs; fmount( & dkp->file, dkp->name, 0); if( fstype ) fmount( & dkp->file, dkp->name, fstype ); bootmsg( "%s unit %d/%d %qd blocks mounted on %s type %s\n", cf->name, dkno, partno, len, dkp->name, fstype ); return 0; }
/*----------------------------------------------------------------------------- * Initialize a Flash Memory Card *----------------------------------------------------------------------------*/ static void init_filesystem (void) { int32_t retv; retv = finit ("M0:"); if (retv == 0) { retv = fmount ("M0:"); if (retv == 0) { printf ("Drive M0 ready!\n"); } else { printf ("Drive M0 mount failed!\n"); } } else { printf ("Drive M0 initialization failed!\n"); } }
int main(int argc, const char* argv[] ) { fmount(); if (strcmp(argv[0], "help") == 0) help(); else if (strcmp(argv[0], "structure") == 0) if (mounted) structure(); else printf("You must mount a floppy first.\n"); else if(strcmp(argv[0], "showsector") == 0) if (mounted) showsector(argv); else printf("You must mount a floppy first.\n"); else if(strcmp(argv[0], "traverse") == 0) if (mounted) traverse(argc, argv); else printf("You must mount a floppy first.\n"); else if(strcmp(argv[0], "showfat") == 0) if (mounted) showfat(); else printf("You must mount a floppy first.\n"); else if(strcmp(argv[0], "showfile") == 0) if (mounted) showfile(argv); else printf("You must mount a floppy first.\n"); else if (strcmp(argv[0], "quit") == 0) return 0; else { printf("%s command not supported.\n", argv[0]); return -1; } //if (fork() == 0) //printf("Other command needed"); //TODO OTHER COMMANDS: FORK EXEC INTO THEM OR RETURN ERROR MESSAGE return 1; }
int romdisk_init(struct Device_Conf *dev){ int port = dev->port; char info[32]; int c = dev->unit; finit( & romdsk[c].file ); romdsk[c].file.d = (void*)& romdsk[c]; romdsk[c].file.fs = & romdsk_fs; bootmsg( "%s %d bytes\n", dev->name, ROMDISK_SIZE); // set flags=1 to not automount if( ! dev->flags ){ snprintf(info, sizeof(info), "%s:", dev->name); fmount( & romdsk[c].file, info, "fatfs" ); bootmsg( "%s mounted on %s type %s\n", dev->name, info, "fatfs" ); } return (int)& romdsk[c].file; }
void fuzix_main(void) { /* setup state */ inint = false; udata.u_insys = true; #ifdef PROGTOP /* FIXME */ ramtop = (uaddr_t)PROGTOP; #endif tty_init(); if (d_open(TTYDEV, 0) != 0) panic(PANIC_NOTTY); /* Sign on messages */ kprintf( "FUZIX version %s\n" "Copyright (c) 1988-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza\n" "Copyright (c) 1997-2001 by Arcady Schekochikhin, Adriano C. R. da Cunha\n" "Copyright (c) 2013-2015 Will Sowerbutts <*****@*****.**>\n" "Copyright (c) 2014-2015 Alan Cox <*****@*****.**>\nDevboot\n", sysinfo.uname); #ifndef SWAPDEV #ifdef PROC_SIZE maxproc = procmem / PROC_SIZE; /* Check we don't exceed the process table size limit */ if (maxproc > PTABSIZE) { kprintf("WARNING: Increase PTABSIZE to %d to use available RAM\n", maxproc); maxproc = PTABSIZE; } #else maxproc = PTABSIZE; #endif #else maxproc = PTABSIZE; #endif /* Used as a stop marker to make compares fast on process scheduling and the like */ ptab_end = &ptab[maxproc]; /* Parameters message */ kprintf("%dkB total RAM, %dkB available to processes (%d processes max)\n", ramsize, procmem, maxproc); bufinit(); fstabinit(); pagemap_init(); create_init(); /* runtime configurable, defaults to build time setting */ ticks_per_dsecond = TICKSPERSEC / 10; kputs("Enabling interrupts ... "); __hard_ei(); /* Physical interrupts on */ kputs("ok.\n"); /* get the root device */ root_dev = get_root_dev(); /* finish building argv */ complete_init(); /* initialise hardware devices */ device_init(); /* Mount the root device */ kprintf("Mounting root fs (root_dev=%d, r%c): ", root_dev, ro ? 'o' : 'w'); if (fmount(root_dev, NULLINODE, ro)) panic(PANIC_NOFILESYS); root = i_open(root_dev, ROOTINODE); if (!root) panic(PANIC_NOROOT); kputs("OK\n"); udata.u_cwd = i_ref(root); udata.u_root = i_ref(root); rdtime32(&udata.u_time); exec_or_die(); }
static int doattach(register Cs_t* state, const char* path, int op, int mode, char* user, char* opath, char* tmp, char* serv, char*b) { register int n; int fd; char* s; #if CS_LIB_STREAM || CS_LIB_V10 int fds[2]; struct stat st; if (op & CS_OPEN_CREATE) { n = errno; if (chmod(path, mode)) { remove(path); if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)) < 0) { messagef((state->id, NiL, -1, "open: %s: %s: creat %o error", state->path, path, mode)); return -1; } close(fd); chmod(path, mode); } errno = n; if (pipe(fds)) { messagef((state->id, NiL, -1, "open: %s: pipe error", state->path, path)); return -1; } #if CS_LIB_V10 if ((n = ioctl(fds[1], FIOPUSHLD, &conn_ld)) || fmount(3, fds[1], path, 0)) #else if ((n = ioctl(fds[1], I_PUSH, "connld")) || fattach(fds[1], path)) #endif { messagef((state->id, NiL, -1, "open: %s: %s: %s error", state->path, path, n ? "connld" : "fattach")); close(fds[0]); close(fds[1]); errno = ENXIO; return -1; } close(fds[1]); fd = fds[0]; } else for (;;) { if ((fd = open(path, O_RDWR)) >= 0) { if (!fstat(fd, &st) && !S_ISREG(st.st_mode)) break; close(fd); remove(path); } else if ((op & CS_OPEN_TEST) || errno == EACCES) { messagef((state->id, NiL, -1, "open: %s: %s: open error", state->path, path)); return -1; } if (initiate(state, user, opath, tmp, serv)) { messagef((state->id, NiL, -1, "open: %s: %s: service initiate error", state->path, path)); return -1; } op = CS_OPEN_TEST; } #else #if CS_LIB_SOCKET_UN int pid; int namlen; char c; struct sockaddr_un nam; messagef((state->id, NiL, -8, "%s:%d state.path=`%s' state.mount=`%s' path=`%s' opath=`%s' user=`%s' serv=`%s'", __FILE__, __LINE__, state->path, state->mount, path, opath, user, serv)); nam.sun_family = AF_UNIX; strcpy(nam.sun_path, path); namlen = sizeof(nam.sun_family) + strlen(path) + 1; for (n = 0;; n++) { if (n >= 10) { errno = ENXIO; badcon: close(fd); return -1; } if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { messagef((state->id, NiL, -1, "open: %s: %s: AF_UNIX socket error", state->path, path)); return -1; } if (!connect(fd, (struct sockaddr*)&nam, namlen)) { if (op & CS_OPEN_CREATE) { errno = EEXIST; goto badcon; } #if CS_LIB_SOCKET_RIGHTS if (read(fd, &c, 1) == 1 && !cssend(state, fd, NiL, 0)) break; #else break; #endif } else { messagef((state->id, NiL, -1, "open: %s: %s: connect error", state->path, path)); if (errno == EACCES) goto badcon; else if (errno == EADDRNOTAVAIL || errno == ECONNREFUSED) { c = 0; for (;;) { *b = CS_MNT_PROCESS; pid = pathgetlink(path, state->temp, sizeof(state->temp)); *b = CS_MNT_STREAM; if (pid > 0 || ++c >= 5) break; sleep(1); } if (pid > 0 && (s = strrchr(state->temp, '/')) && (pid = strtol(s + 1, NiL, 0)) > 0) { if (!kill(pid, 0) || errno != ESRCH) { if (op & CS_OPEN_CREATE) { errno = EEXIST; goto badcon; } close(fd); if (n) sleep(1); continue; } *b = CS_MNT_PROCESS; remove(path); *b = CS_MNT_STREAM; } } } close(fd); errno = ENOENT; if (op & CS_OPEN_CREATE) { if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { messagef((state->id, NiL, -1, "open: %s: %s: AF_UNIX socket error", state->path, path)); return -1; } if (!bind(fd, (struct sockaddr*)&nam, namlen)) { chmod(path, mode); if (listen(fd, 32)) { messagef((state->id, NiL, -1, "open: %s: %s: listen error", state->path, path)); n = errno; remove(path); errno = n; goto badcon; } break; } else messagef((state->id, NiL, -1, "open: %s: %s: bind error", state->path, path)); if (errno != EADDRINUSE || n && remove(path) && errno != ENOENT) goto badcon; close(fd); } else if (op & CS_OPEN_TEST) return -1; else if (!n && initiate(state, user, opath, tmp, serv)) { messagef((state->id, NiL, -1, "open: %s: %s: service initiate error", state->path, path)); return -1; } else sleep(2); } #else errno = (op & CS_OPEN_CREATE) ? ENXIO : ENOENT; messagef((state->id, NiL, -1, "open: %s: %s: not supported", state->path, path)); fd = -1; #endif #endif #if CS_LIB_SOCKET_UN || CS_LIB_STREAM || CS_LIB_V10 touch(path, (time_t)0, (time_t)0, 0); strcpy(state->path, path); #endif return fd; }
void fuzix_main(void) { /* setup state */ inint = false; udata.u_insys = true; ramtop = PROGTOP; tty_init(); if (d_open(TTYDEV, 0) != 0) panic("no tty"); /* Sign on messages (stashed in a buffer so we can bin them */ kprintf((char *)bufpool[0].bf_data, uname_str); #ifndef SWAPDEV #ifdef PROC_SIZE maxproc = procmem / PROC_SIZE; /* Check we don't exceed the process table size limit */ if (maxproc > PTABSIZE) { kprintf((char *)bufpool[1].bf_data, maxproc); maxproc = PTABSIZE; } #else maxproc = PTABSIZE; #endif #else maxproc = PTABSIZE; #endif /* Parameters message */ kprintf((char *)bufpool[2].bf_data, ramsize, procmem, maxproc); /* Now blow away the strings */ bufinit(); pagemap_init(); create_init(); kprintf("%x:%x\n", udata.u_page, udata.u_page2); kprintf("%x:%x\n", udata.u_ptab->p_page, udata.u_ptab->p_page2); kputs("Enabling interrupts ... "); ei(); kputs("ok.\n"); /* initialise hardware devices */ device_init(); root_dev = DEFAULT_ROOT; if (cmdline && *cmdline) { while (*cmdline == ' ') ++cmdline; root_dev = *cmdline - '0'; } else { kputs("bootdev: "); udata.u_base = bootline; udata.u_sysio = 1; udata.u_count = 2; udata.u_euid = 0; /* Always begin as superuser */ cdread(TTYDEV, O_RDONLY); /* read root filesystem name from tty */ if (*bootline >= '0') root_dev = *bootline - '0'; } /* Mount the root device */ kprintf("Mounting root fs (root_dev=%d): ", root_dev); if (fmount(root_dev, NULLINODE, 0)) panic("no filesys"); root = i_open(root_dev, ROOTINODE); if (!root) panic("no root"); kputs("OK\n"); i_ref(udata.u_cwd = root); i_ref(udata.u_root = root); rdtime32(&udata.u_time); exec_or_die(); }