int do_wri(u8 * file){ s8 ret,fd; u32 retlba ; u8 i=0; u32 ch; u8 buff[256] = {0}; if (!check_for_args(WRI,1))return 1; fd = openf(file,O_RW); if ( fd == -1){ retlba=NO_LBA; if (ERROR_NO == NO_DIR_FILE) retlba = creatf(file , 064); if (retlba == NO_LBA){ vd_puts ( "COULD NOT OPEN OR CREATE THE DESTINATION FILE\n" ); errormessage(geterror()); closef(fd); fl_clean(); return 0; } fd = openf(file,O_RW); } if(fd == -1){ vd_puts("CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } while(1){ ch=getche(); if(ch == 1) break; if( ch == 13 || ch == 10){printf("\n"); ch = '\n';} if (i == 255){ i=0; ret = writef(fd,buff,256); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } } buff[i++] = ch; } ret = writef(fd,buff,i); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } closef(fd); vd_puts(" \n"); fl_clean(); return 0; }
int do_app(u8 * file){ s8 ret,fd; u8 i=0; u32 ch; u8 buff[256]; struct fnode fn; u32 size; if (!check_for_args(APP,1)) return 1; fd = openf(file,O_RW); if(fd == -1){ vd_puts( "CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } finfo(fd, & fn); size = fn.size; ret= seekf(fd, size,SEEK_BEG); while(1){ ch=getche(); if(ch == 1) break; if (ch == 13 || ch == 10 ){ printf("\n");ch='\n'; } if (i == 255){ i=0; ret = writef(fd,buff,256); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } } buff[i++] = (u8)ch; } ret = writef(fd,buff,i); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } puts(" "); closef(fd); fl_clean(); return 0; }
int do_rf(u8 * file){ s8 ret; if (!check_for_args(RF,1)) return 1; ret = unlinkf(file); if(ret == -1){ vd_puts("CANNOT REMOVE THE FILE\n"); errormessage(geterror()); } fl_clean(); return 0; }
void clean_q(struct printer *pp) { char *cp, *cp1, *lp; struct dirent **queue; size_t linerem; int didhead, i, n, nitems, rmcp; cln_queuecnt++; didhead = 0; if (generic_qselect == QSEL_BYNAME) { printf("%s:\n", pp->printer); didhead = 1; } lp = line; cp = pp->spool_dir; while (lp < &line[sizeof(line) - 1]) { if ((*lp++ = *cp++) == 0) break; } lp[-1] = '/'; linerem = sizeof(line) - (lp - line); cln_foundcore = 0; seteuid(euid); nitems = scandir(pp->spool_dir, &queue, doselect, sortq); seteuid(uid); if (nitems < 0) { if (!didhead) { printf("%s:\n", pp->printer); didhead = 1; } printf("\tcannot examine spool directory\n"); return; } if (cln_foundcore) { if (!didhead) { printf("%s:\n", pp->printer); didhead = 1; } printf("\t** found a core file in %s !\n", pp->spool_dir); } if (nitems == 0) return; if (!didhead) printf("%s:\n", pp->printer); if (cln_debug) { printf("\t** ----- Sorted list of files being checked:\n"); i = 0; do { cp = queue[i]->d_name; printf("\t** [%3d] = %s\n", i, cp); } while (++i < nitems); printf("\t** ----- end of sorted list\n"); } i = 0; do { cp = queue[i]->d_name; rmcp = 0; if (*cp == 'c') { /* * A control file. Look for matching data-files. */ /* XXX * Note the logic here assumes that the hostname * part of cf-filenames match the hostname part * in df-filenames, and that is not necessarily * true (eg: for multi-homed hosts). This needs * some further thought... */ n = 0; while (i + 1 < nitems) { cp1 = queue[i + 1]->d_name; if (*cp1 != 'd' || strcmp(cp + 3, cp1 + 3)) break; i++; n++; } if (n == 0) { rmcp = 1; } } else if (*cp == 'e') { /* * Must be an errrs or email temp file. */ rmcp = 1; } else { /* * Must be a df with no cf (otherwise, it would have * been skipped above) or an rf or tf file (which can * always be removed if it is old enough). */ rmcp = 1; } if (rmcp) { if (strlen(cp) >= linerem) { printf("\t** internal error: 'line' overflow!\n"); printf("\t** spooldir = %s\n", pp->spool_dir); printf("\t** cp = %s\n", cp); return; } strlcpy(lp, cp, linerem); unlinkf(line); } } while (++i < nitems); }
/* * Remove incomplete jobs from spooling area. */ static void cleanpr(void) { int i, n; char *cp, *cp1, *lp; struct dirent **queue; int nitems; if (cgetstr(bp, "sd", &SD) == -1) SD = _PATH_DEFSPOOL; printf("%s:\n", printer); /* XXX depends on SD being non-NUL */ for (lp = line, cp = SD; (lp - line) < sizeof(line) && (*lp++ = *cp++) != '\0'; ) ; lp[-1] = '/'; if (lp - line >= sizeof(line)) { printf("\tspool directory name too long\n"); return; } PRIV_START; nitems = scandir(SD, &queue, doselect, sortq); PRIV_END; if (nitems < 0) { printf("\tcannot examine spool directory\n"); return; } if (nitems == 0) return; i = 0; do { cp = queue[i]->d_name; if (*cp == 'c') { n = 0; while (i + 1 < nitems) { cp1 = queue[i + 1]->d_name; if (*cp1 != 'd' || strcmp(cp + 3, cp1 + 3)) break; i++; n++; } if (n == 0) { if (strlcpy(lp, cp, sizeof(line) - (lp - line)) >= sizeof(line) - (lp - line)) printf("\tpath too long, %s/%s", SD, cp); else unlinkf(line); } } else { /* * Must be a df with no cf (otherwise, it would have * been skipped above) or a tf file (which can always * be removed). */ if (strlcpy(lp, cp, sizeof(line) - (lp - line)) >= sizeof(line) - (lp - line)) printf("\tpath too long, %s/%s", SD, cp); else unlinkf(line); } } while (++i < nitems); }
int do_cp(u8 * src , u8 * dst){ s8 sfd,dfd,ret ; u32 retlba; struct fnode fn; u32 size; u8 buff[1024]; if (!check_for_args(CP,2)) return 1; sfd=openf(src,O_READ); if ( sfd == -1){ vd_puts("COULD NOT OPEN SOURCE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } dfd = openf(dst, O_RW); if ( dfd == -1){ retlba = creatf(dst , 064); if (retlba == NO_LBA){ vd_puts("COULD NOT OPEN OR CREATE THE DESTINATION FILE\n"); errormessage(geterror()); fl_clean(); return 0; } dfd = openf(dst,O_RW); } ret = finfo(sfd, &fn); if (ret == -1){ vd_puts("HAD PROBLEMS WITH GETTING INFO OF SOURCE FILE\n"); errormessage(geterror()); closef(sfd); closef(dfd); fl_clean(); return 1; } size = fn.size; while (size ){ ret = readf(sfd , buff, (size < 1024 ? size : 1024)); if ( ret == -1){ vd_puts("ERRROR OCCURED IN READING SOURCE FILE\n"); errormessage(geterror()); closef(sfd); closef(dfd); fl_clean(); return 1; } ret = writef(dfd, buff , (size < 1024 ? size : 1024)); if (ret == -1){ vd_puts("ERROR IN WRITE DELETING THE FILE\n"); errormessage(geterror()); closef(sfd); closef(dfd); unlinkf(dst); fl_clean(); return 1; } if (size >= 1024){ size-=1024; }else size=0; } fl_clean(); return 0; }