void s_move_dest(char *m, MESG *md) { char *dest; char *fromdest; RSTATUS *rp; char *found = (char *)0; short num_ok = 0; (void) getmessage(m, S_MOVE_DEST, &fromdest, &dest); syslog(LOG_DEBUG, "s_move_dest(%s, %s)", (fromdest ? fromdest : "NULL"), (dest ? dest : "NULL")); if (!search_pstatus(fromdest) && !search_cstatus(fromdest)) { mputm(md, R_MOVE_DEST, MNODEST, fromdest, 0); return; } if (!(search_pstatus(dest)) && !(search_cstatus(dest))) { mputm(md, R_MOVE_DEST, MNODEST, dest, 0); return; } if (STREQU(dest, fromdest)) { mputm(md, R_MOVE_DEST, MOK, "", 0); return; } for (rp = Request_List; rp != NULL; rp = rp->next) { if ((STREQU(rp->request->destination, fromdest)) && (!(rp->request->outcome & (RS_DONE|RS_CHANGING|RS_NOTIFYING)))) { if (mv_file(rp, dest) == MOK) { num_ok++; continue; } } if (found) mputm(md, R_MOVE_DEST, MMORERR, found, 0); found = rp->secure->req_id; } if (found) mputm(md, R_MOVE_DEST, MERRDEST, found, num_ok); else mputm(md, R_MOVE_DEST, MOK, "", num_ok); }
int main (int argc, char ** argv) { open_FS(); printf ("\nREPETOIRE AVANT:\n"); list_dir (); if (mv_file (argv[1], argv[2])) printf ("%s n'existe pas\n", argv[1]); else { printf ("\nREPETOIRE APRES :\n"); list_dir (); } close_FS (); return EXIT_SUCCESS; }
void s_move_request(char *m, MESG *md) { RSTATUS *rp; short err; char *req_id; char *dest; (void) getmessage(m, S_MOVE_REQUEST, &req_id, &dest); syslog(LOG_DEBUG, "s_move_request(%s, %s)", (req_id ? req_id : "NULL"), (dest ? dest : "NULL")); if (!(search_pstatus(dest)) && !(search_cstatus(dest))) { mputm(md, R_MOVE_REQUEST, MNODEST, 0L); return; } if ((rp = request_by_id(req_id))) { if (STREQU(rp->request->destination, dest)) { mputm(md, R_MOVE_REQUEST, MOK, 0L); return; } if (rp->request->outcome & (RS_DONE|RS_NOTIFYING)) { mputm(md, R_MOVE_REQUEST, M2LATE, 0L); return; } if (rp->request->outcome & RS_CHANGING) { mputm(md, R_MOVE_REQUEST, MBUSY, 0L); return; } if ((err = mv_file(rp, dest)) == MOK) { mputm(md, R_MOVE_REQUEST, MOK, 0L); return; } mputm(md, R_MOVE_REQUEST, err, chkprinter_result); return; } mputm(md, R_MOVE_REQUEST, MUNKNOWN, 0L); }
//This tests the mv function //It does so by calling mv on two files and checks to make sure the oldfile no longer eixsts and the newfile does //If the oldfile exists or the newfile does not exist it will return 0. int mvTest() { MINODE *test_mip = running->cwd; INODE *ip = NULL; int ino = 0, newino = 0; strcpy(pathname, ""); cd(pathname); test_mip = running->cwd; printf("\n\n-------- TESTING MV FUNCTION --------\n\n"); strcpy(pathname, "tiny"); strcpy(third, "mvtiny"); printf("Testing >mv tiny mvtiny\n"); mv_file(pathname); strcpy(pathname, "tiny"); ino = getino(test_mip, pathname); strcpy(pathname, "mvtiny"); newino = getino(test_mip, pathname); printf("\n\nino of tiny: %d\n", ino); printf("ino of mvtiny: %d\n", newino); if(ino != 0 || newino == 0) { printf("TEST FAILED\n\n"); return 0; } else printf("TEST PASSED\n\n"); strcpy(pathname, "mvtiny"); strcpy(third, "/Y/testmv"); printf("Testing >mv mvtiny /Y/testmv\n"); mv_file(pathname); strcpy(pathname, "mvtiny"); ino = getino(test_mip, pathname); strcpy(pathname, "/Y/testmv"); newino = getino(test_mip, pathname); strcpy(pathname, "Y"); printf(">ls /Y\n"); ls(pathname); printf("\n\nino of mvtiny: %d\n", ino); printf("ino of /Y/testmv: %d\n", newino); if(ino != 0 || newino == 0) { printf("TEST FAILED\n\n"); return 0; } else printf("TEST PASSED\n\n"); printf("ALL MV TESTS PASSED\n\n\n"); strcpy(pathname, ""); cd(pathname); return 1; }
void s_end_change_request(char *m, MESG *md) { char *req_id; RSTATUS *rp; off_t size; off_t osize; short err; short status; REQUEST *r = 0; REQUEST oldr; int call_schedule = 0; int move_ok = 0; char *path; char tmpName[BUFSIZ]; struct stat tmpBuf; (void) getmessage(m, S_END_CHANGE_REQUEST, &req_id); syslog(LOG_DEBUG, "s_end_change_request(%s)", (req_id ? req_id : "NULL")); if (!(rp = request_by_id(req_id))) status = MUNKNOWN; else if ((md->admin == 0) && (is_system_labeled()) && (md->slabel != NULL) && (rp->secure->slabel != NULL) && (!STREQU(md->slabel, rp->secure->slabel))) status = MUNKNOWN; else if (!(rp->request->outcome & RS_CHANGING)) status = MNOSTART; else { path = makepath(Lp_Tmp, rp->req_file, (char *)0); (void) chownmod(path, Lp_Uid, Lp_Gid, 0644); Free(path); #ifdef LP_USE_PAPI_ATTR /* * Check if the PAPI job attribute file exists, * if it does change the permission and the ownership * of the file to be "Lp_Uid". */ snprintf(tmpName, sizeof (tmpName), "%s-%s", strtok(strdup(rp->req_file), "-"), LP_PAPIATTRNAME); path = makepath(Lp_Tmp, tmpName, (char *)0); if (stat(path, &tmpBuf) == 0) { syslog(LOG_DEBUG, "s_end_change_request: attribute file ='%s'", path); /* * IPP job attribute file exists for this job so * change permissions and ownership of the file */ (void) chownmod(path, Lp_Uid, Lp_Gid, 0644); Free(path); } else { syslog(LOG_DEBUG, "s_end_change_request: no attribute file"); } #endif rp->request->outcome &= ~(RS_CHANGING); del_flt_act(md, FLT_CHANGE); /* * The RS_CHANGING bit may have been the only thing * preventing this request from filtering or printing, * so regardless of what happens below, * we must check to see if the request can proceed. */ call_schedule = 1; if (!(r = Getrequest(rp->req_file))) status = MNOOPEN; else { oldr = *(rp->request); *(rp->request) = *r; move_ok = STREQU(oldr.destination, r->destination); /* * Preserve the current request status! */ rp->request->outcome = oldr.outcome; /* * Here's an example of the dangers one meets * when public flags are used for private * purposes. ".actions" (indeed, anything in the * REQUEST structure) is set by the person * changing the job. However, lpsched uses * ".actions" as place to indicate that a job * came from a remote system and we must send * back job completion--this is a strictly * private flag that we must preserve. */ rp->request->actions |= (oldr.actions & ACT_NOTIFY); if ((rp->request->actions & ACT_SPECIAL) == ACT_HOLD) { rp->request->outcome |= RS_HELD; /* * To be here means either the user owns * the request or he or she is the * administrator. Since we don't want to * set the RS_ADMINHELD flag if the user * is the administrator, the following * compare will work. */ if (md->uid != rp->secure->uid) rp->request->outcome |= RS_ADMINHELD; } if ((rp->request->actions & ACT_SPECIAL) == ACT_RESUME) { if ((rp->request->outcome & RS_ADMINHELD) && !md->admin) { status = MNOPERM; goto Return; } rp->request->outcome &= ~(RS_ADMINHELD|RS_HELD); } if ((rp->request->actions & ACT_SPECIAL) == ACT_IMMEDIATE) { if (!md->admin) { status = MNOPERM; goto Return; } rp->request->outcome |= RS_IMMEDIATE; } size = chfiles(rp->request->file_list, Lp_Uid, Lp_Gid); if (size < 0) { status = MUNKNOWN; goto Return; } if (!(rp->request->outcome & RS_HELD) && size == 0) { status = MNOPERM; goto Return; } osize = rp->secure->size; rp->secure->size = size; if (move_ok == 0) { char *dest = strdup(r->destination); if ((status = mv_file(rp, dest)) == MOK) rp->secure->size = osize; free(dest); } else if ((err = validate_request(rp, (char **)0, move_ok)) != MOK) { status = err; rp->secure->size = osize; } else { status = MOK; if ((rp->request->outcome & RS_IMMEDIATE) || (rp->request->priority != oldr.priority)) { remover(rp); insertr(rp); } freerequest(&oldr); (void) putrequest(rp->req_file, rp->request); /* * fix for bugid 1103890. * use Putsecure instead. */ (void) Putsecure(rp->req_file, rp->secure); } } } Return: if (status != MOK && rp) { if (r) { freerequest(r); *(rp->request) = oldr; } if (status != MNOSTART) (void) putrequest(rp->req_file, rp->request); } if (call_schedule) maybe_schedule(rp); mputm(md, R_END_CHANGE_REQUEST, status, chkprinter_result); }
void main(int argc, char *argv[]) { int i = 0, cmd = -1, fd = 0; char line[128], cname[64], temp_pathname[124], pathname[124] = "NULL", basename[124] = "NULL", dirname[124] = "NULL", parameter[124] = "NULL", *device; //GETS DISK NAME TO MOUNT /* printf("Enter the name of your disk image\n"); fgets(device, 128, stdin); device[strlen(device)-1] = 0; // kill the \n char at end */ device = "mydisk"; mount_root(device, &fd); while(1) { //printf("P%d running: ", running.uid); printf("nick's@linux:"); pwd(P0.cwd); printf("$ "); fgets(line, 128, stdin); line[strlen(line)-1] = 0; // kill the \n char at end if (line[0]==0) continue; sscanf(line, "%s %s %s", cname, pathname, parameter); if(strcmp(pathname,"NULL") != 0) strcpy(PATHNAME, pathname); if(strcmp(parameter,"NULL") != 0) strcpy(PARAMETER, parameter); cmd = findCmd(cname); // map cname to an index switch(cmd) { case 0 : menu(); break; case 1 : pwd(P0.cwd);printf("\n"); break; case 2 : ls(); break; case 3 : cd(); break; case 4 : make_dir(); break; case 5 : rmdir(); break; case 6 : creat_file(); break; case 7 : link(); break; case 8 : unlink(); break; case 9 : symlink(); break; case 10: rm_file(); break; case 11: chmod_file(); break; case 12: chown_file(); break; case 13: stat_file(); break; case 14: touch_file(); break; case 20: open_file(); break; //LEVEL 2 case 21: close_file((int)PATHNAME); break; case 22: pfd(); break; case 23: lseek_file(); break; case 24: //access_file(); break; break; case 25: //read_file(); break; case 26: write_file(); break; case 27: cat_file(); break; case 28: cp_file(); break; case 29: mv_file(); break; case 30: mount(); break; //LEVLEL 3 case 31: //umount(); break; case 32: //cs(); break; case 33: //do_fork(); break; case 34: //do_ps(); break; case 40: //sync(); break; case 41: quit(); break; case 42 : system("clear"); break; default: printf("invalid command\n"); break; } //RESET NAMES strcpy(parameter, "NULL"); strcpy(pathname, "NULL"); strcpy(PATHNAME, "NULL"); } }