int seagate_st0x_queue_command (Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *)) { int result, reconnect; Scsi_Cmnd * SCtmp; done_fn = done; current_target = SCpnt->target; current_lun = SCpnt->lun; current_cmnd = SCpnt->cmnd; current_data = (unsigned char *) SCpnt->request_buffer; current_bufflen = SCpnt->request_bufflen; SCint = SCpnt; if(recursion_depth) { return 0; }; recursion_depth++; do{ #ifdef LINKED /* * Set linked command bit in control field of SCSI command. */ current_cmnd[SCpnt->cmd_len] |= 0x01; if (linked_connected) { #if (DEBUG & DEBUG_LINKED) printk("scsi%d : using linked commands, current I_T_L nexus is ", hostno); #endif if ((linked_target == current_target) && (linked_lun == current_lun)) { #if (DEBUG & DEBUG_LINKED) printk("correct\n"); #endif reconnect = LINKED_RIGHT; } else { #if (DEBUG & DEBUG_LINKED) printk("incorrect\n"); #endif reconnect = LINKED_WRONG; } } else #endif /* LINKED */ reconnect = CAN_RECONNECT; result = internal_command (SCint->target, SCint->lun, SCint->cmnd, SCint->request_buffer, SCint->request_bufflen, reconnect); if (msg_byte(result) == DISCONNECT) break; SCtmp = SCint; SCint = NULL; SCtmp->result = result; done_fn (SCtmp); } while(SCint); recursion_depth--; return 0; }
static void seagate_reconnect_intr(int irq, void *dev_id, struct pt_regs *regs) { int temp; Scsi_Cmnd * SCtmp; /* enable all other interrupts. */ sti(); #if (DEBUG & PHASE_RESELECT) printk("scsi%d : seagate_reconnect_intr() called\n", hostno); #endif if (!should_reconnect) printk("scsi%d: unexpected interrupt.\n", hostno); else { should_reconnect = 0; #if (DEBUG & PHASE_RESELECT) printk("scsi%d : internal_command(" "%d, %08x, %08x, %d, RECONNECT_NOW\n", hostno, current_target, current_data, current_bufflen); #endif temp = internal_command (current_target, current_lun, current_cmnd, current_data, current_bufflen, RECONNECT_NOW); if (msg_byte(temp) != DISCONNECT) { if (done_fn) { #if (DEBUG & PHASE_RESELECT) printk("scsi%d : done_fn(%d,%08x)", hostno, hostno, temp); #endif if(!SCint) panic("SCint == NULL in seagate"); SCtmp = SCint; SCint = NULL; SCtmp->result = temp; done_fn (SCtmp); } else printk("done_fn() not defined.\n"); } } }
/* * The main shell function */ main() { int i; char **args; int result; int block; int output; int input; int append; int child_id; int status; char *output_filename; char *input_filename; // Set up the signal handler sigset(SIGCHLD, sig_handler); // memset(&sa, 0, sizeof(sa)); // sa.sa_handler = delete_zombies; // if(sigaction(SIGCHLD, &sa, 0)) { // perror("sigaction"); // return 1; // } // Loop forever while(1) { // Print out the prompt and get the input printf("prompt->"); args = getaline(); // No input, continue if(args[0] == NULL) continue; // Check for internal shell commands, such as exit if(internal_command(args)) continue; // Check for an ampersand int block = should_block(args); if(check_for_pipes(args)) { int in = 0; char **tmp_args = args; char **ptr; // loop over args, set each | to NULL for(ptr = args; *ptr != NULL; ptr++) { //printf("tmpargs[0]: %s [1]: %s [2]: %s\n", tmp_args[0], tmp_args[1], tmp_args[2]); if(strcmp(*ptr, "|") == 0) { free(*ptr); *ptr = NULL; // do stuff with tmp_args as your new "args" int pipefd[2]; pipe(pipefd); child_id = do_command(tmp_args, in, pipefd[1], 1, block); close(pipefd[1]); if(child_id < 0) { printf("syntax error\n"); continue; } in = pipefd[0]; tmp_args = ptr + 1; } } //printf("tmpargs[0]: %s [1]: %s\n", tmp_args[0], tmp_args[1]); child_id = do_command(tmp_args, in, 1, 1, block); if(child_id < 0) { printf("syntax error\n"); continue; } } else { child_id = do_command(args, 0, 0, 0, block); if(child_id < 0) { printf("syntax error\n"); continue; } } // Wait for the child process to complete, if necessary if(block) { printf("Waiting for child, pid = %d\n", child_id); result = waitpid(child_id, &status, 0); } } }
/* * The main shell function */ main() { int i; char **args; int result; int block; int output; int input; char *output_filename; char *input_filename; // Set up the signal handler sigset(SIGCHLD, sig_handler); // Setup the signal handler struct sigaction sa; // Setup the SIGPROCMASK sigset_t blockmask; // Make sure the signal handlers are setup if(sigprocmask(SIG_BLOCK, &blockmask, NULL) == -1) { perror("Failed to setup signal handler."); return 1; } // Loop forever while(1) { // Print out the prompt and get the input printf("->"); args = getline(); // No input, continue if(args[0] == NULL) continue; // Check for internal shell commands, such as exit if(internal_command(args)) continue; // Check for an ampersand block = (ampersand(args) == 0); // Check for redirected input input = redirect_input(args, &input_filename); switch(input) { case -1: printf("Syntax error!\n"); continue; break; case 0: break; case 1: printf("Redirecting input from: %s\n", input_filename); break; } // Check for redirected output output = redirect_output(args, &output_filename); switch(output) { case -1: printf("Syntax error!\n"); continue; break; case 0: break; case 1: printf("Redirecting output to: %s\n", output_filename); break; case 2: printf("Appending output to: %s\n", output_filename); break; } // Do the command do_command(args, block, input, input_filename, output, output_filename, sigaction, blockmask, 0, 0); } }
/* * The main shell function */ main() { int i; char **args; int result; int block; int output; int input; char *output_filename; char *input_filename; // Set up the signal handler sigset(SIGCHLD, sig_handler); // Loop forever while(1) { // Print out the prompt and get the input printf("->"); args = my_getline(); // No input, continue if(args[0] == NULL) continue; // Check for internal shell commands, such as exit if(internal_command(args)) continue; // Check for tilde (~) tilde(args); // Check for an ampersand block = (ampersand(args) == 0); // Check for redirected input input = redirect_input(args, &input_filename); switch(input) { case -1: printf("Syntax error!\n"); continue; break; case 0: break; case 1: if (DEBUG) printf("Redirecting input from: %s\n", input_filename); break; } // Check for redirected output output = redirect_output(args, &output_filename); switch(output) { case -1: printf("Syntax error!\n"); continue; break; case 0: break; case 1: if (DEBUG) printf("Redirecting (Overriding) output to: %s\n", output_filename); break; case 2: if (DEBUG) printf("Redirecting (Appending) output to: %s\n", output_filename); break; } // Do the command do_command(args, block, input, input_filename, output, output_filename); for (i = 0; args[i] != NULL; i++) free(args[i]); } }
int wskbd_translate(struct wskbd_internal *id, u_int type, int value) { struct wskbd_softc *sc = id->t_sc; keysym_t ksym, res, *group; struct wscons_keymap kpbuf, *kp; int gindex, iscommand = 0; if (type == WSCONS_EVENT_ALL_KEYS_UP) { #if NWSDISPLAY > 0 if (sc != NULL && sc->sc_repeating) { sc->sc_repeating = 0; timeout_del(&sc->sc_repeat_ch); } #endif id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R | MOD_CONTROL_L | MOD_CONTROL_R | MOD_META_L | MOD_META_R | MOD_MODESHIFT | MOD_MODELOCK | MOD_COMMAND | MOD_COMMAND1 | MOD_COMMAND2); return (0); } if (sc != NULL) { if (value < 0 || value >= sc->sc_maplen) { #ifdef DEBUG printf("wskbd_translate: keycode %d out of range\n", value); #endif return (0); } kp = sc->sc_map + value; } else { kp = &kpbuf; wskbd_get_mapentry(&id->t_keymap, value, kp); } /* if this key has a command, process it first */ if (sc != NULL && kp->command != KS_voidSymbol) iscommand = internal_command(sc, &type, kp->command, kp->group1[0]); /* Now update modifiers */ switch (kp->group1[0]) { case KS_Shift_L: update_modifier(id, type, 0, MOD_SHIFT_L); break; case KS_Shift_R: update_modifier(id, type, 0, MOD_SHIFT_R); break; case KS_Shift_Lock: update_modifier(id, type, 1, MOD_SHIFTLOCK); break; case KS_Caps_Lock: update_modifier(id, type, 1, MOD_CAPSLOCK); break; case KS_Control_L: update_modifier(id, type, 0, MOD_CONTROL_L); break; case KS_Control_R: update_modifier(id, type, 0, MOD_CONTROL_R); break; case KS_Alt_L: update_modifier(id, type, 0, MOD_META_L); break; case KS_Alt_R: update_modifier(id, type, 0, MOD_META_R); break; case KS_Mode_switch: update_modifier(id, type, 0, MOD_MODESHIFT); break; case KS_Mode_Lock: update_modifier(id, type, 1, MOD_MODELOCK); break; case KS_Num_Lock: update_modifier(id, type, 1, MOD_NUMLOCK); break; #if NWSDISPLAY > 0 case KS_Hold_Screen: if (sc != NULL) { update_modifier(id, type, 1, MOD_HOLDSCREEN); if (sc->sc_displaydv != NULL) wsdisplay_kbdholdscreen(sc->sc_displaydv, id->t_modifiers & MOD_HOLDSCREEN); } break; default: if (sc != NULL && sc->sc_repeating && ((type == WSCONS_EVENT_KEY_UP && value != sc->sc_repkey) || (type == WSCONS_EVENT_KEY_DOWN && value == sc->sc_repkey))) return (0); break; #endif } #if NWSDISPLAY > 0 if (sc != NULL) { if (sc->sc_repeating) { sc->sc_repeating = 0; timeout_del(&sc->sc_repeat_ch); } sc->sc_repkey = value; } #endif /* If this is a key release or we are in command mode, we are done */ if (type != WSCONS_EVENT_KEY_DOWN || iscommand) return (0); /* Get the keysym */ if (id->t_modifiers & (MOD_MODESHIFT|MOD_MODELOCK) && !MOD_ONESET(id, MOD_ANYCONTROL)) group = & kp->group2[0]; else group = & kp->group1[0]; if ((id->t_modifiers & MOD_NUMLOCK) && KS_GROUP(group[1]) == KS_GROUP_Keypad) { gindex = !MOD_ONESET(id, MOD_ANYSHIFT); ksym = group[gindex]; } else { /* CAPS alone should only affect letter keys */ if ((id->t_modifiers & (MOD_CAPSLOCK | MOD_ANYSHIFT)) == MOD_CAPSLOCK) { gindex = 0; ksym = ksym_upcase(group[0]); } else { gindex = MOD_ONESET(id, MOD_ANYSHIFT); ksym = group[gindex]; } } /* Submit Audio keys for hotkey processing */ if (KS_GROUP(ksym) == KS_GROUP_Function) { switch (ksym) { #if NAUDIO > 0 case KS_AudioMute: wskbd_set_mixervolume(0, 1); return (0); case KS_AudioLower: wskbd_set_mixervolume(-1, 1); return (0); case KS_AudioRaise: wskbd_set_mixervolume(1, 1); return (0); #endif default: break; } } /* Process compose sequence and dead accents */ res = KS_voidSymbol; switch (KS_GROUP(ksym)) { case KS_GROUP_Ascii: case KS_GROUP_Keypad: case KS_GROUP_Function: res = ksym; break; case KS_GROUP_Mod: if (ksym == KS_Multi_key) { update_modifier(id, 1, 0, MOD_COMPOSE); id->t_composelen = 2; } break; case KS_GROUP_Dead: if (id->t_composelen == 0) { update_modifier(id, 1, 0, MOD_COMPOSE); id->t_composelen = 1; id->t_composebuf[0] = ksym; } else res = ksym; break; } if (res == KS_voidSymbol) return (0); if (id->t_composelen > 0) { /* * If the compose key also serves as AltGr (i.e. set to both * KS_Multi_key and KS_Mode_switch), and would provide a valid, * distinct combination as AltGr, leave compose mode. */ if (id->t_composelen == 2 && group == &kp->group2[0]) { if (kp->group1[gindex] != kp->group2[gindex]) id->t_composelen = 0; } if (id->t_composelen != 0) { id->t_composebuf[2 - id->t_composelen] = res; if (--id->t_composelen == 0) { res = wskbd_compose_value(id->t_composebuf); update_modifier(id, 0, 0, MOD_COMPOSE); } else { return (0); } } } /* We are done, return the symbol */ if (KS_GROUP(res) == KS_GROUP_Ascii) { if (MOD_ONESET(id, MOD_ANYCONTROL)) { if ((res >= KS_at && res <= KS_z) || res == KS_space) res = res & 0x1f; else if (res == KS_2) res = 0x00; else if (res >= KS_3 && res <= KS_7) res = KS_Escape + (res - KS_3); else if (res == KS_8) res = KS_Delete; } if (MOD_ONESET(id, MOD_ANYMETA)) { if (id->t_flags & WSKFL_METAESC) { id->t_symbols[0] = KS_Escape; id->t_symbols[1] = res; return (2); } else res |= 0x80; } } id->t_symbols[0] = res; return (1); }
int seagate_st0x_command (Scsi_Cmnd * SCpnt) { return internal_command (SCpnt->target, SCpnt->lun, SCpnt->cmnd, SCpnt->request_buffer, SCpnt->request_bufflen, (int) NO_RECONNECT); }
/* Fonction: executer_commande * Entrees: aucune * * Sortie: aucune * * Execute une commande */ void executer_commande() { pid_t pid; /* on commence par regarder s'il y a des pipes */ int nb_pipes = number_pipes(); if (nb_pipes > 0) { my_pipe(nb_pipes); } /* on exécute les commandes internes (pas de fork) */ /* pas de pipes, donc la position de la commande est 0 */ else if (internal_command(0) == 0) { pid = fork(); /* le fork permet de lancer une commande en continuant d'executer le shell */ if (pid == 0) /* fils */ { /* on commence par vérifier si on veut faire une redirection */ int i = 0; /* recherche du nombre d'éléments */ while (commande[i] != NULL) i++; if (commande[i-1][0] == '>') { /* ouverture d'un fichier de destination */ int file = open(&commande[i-1][1], O_WRONLY | O_CREAT | O_TRUNC, 0666); /* O_WRONLY : on va seulement écrire dans le fichier * O_CREAT : créé le fichier s'il n'existe pas * O_TRUNC : le fichier est tronqué à une longueur nulle s'il existe * 0666 : tout le monde peut lire et écrire dans ce fichier */ if (file == -1) { printf("Erreur, impossible de créer le fichier"); exit(1); } dup2(file, 1); /* remplace la sortie standard par un fichier de sortie */ close(file); /* fermeture du fichier de destination */ /* il faut supprimer le dernier argument pour effectuer la commande externe */ commande[i-1] = NULL; } /* on exécute ensuite les commandes externes */ const char* path = get_path(commande[0]); /* on récupère le chemin */ if (strcmp(path, "echec") != 0) { /* si on réussit à récupérer le path */ stockCommande(); execv(path, commande); } else my_exit(commande); } else if(pid<0) printf("Erreur, fork a échoué.\n"); else /* père */ { int status; waitpid(pid, &status, 0); /* attente bloquante */ } } }
static int wskbd_translate(struct wskbd_internal *id, u_int type, int value) { struct wskbd_softc *sc = id->t_sc; keysym_t ksym, res, *group; struct wscons_keymap kpbuf, *kp; int iscommand = 0; int ishotkey = 0; if (type == WSCONS_EVENT_ALL_KEYS_UP) { id->t_modifiers &= ~(MOD_SHIFT_L | MOD_SHIFT_R | MOD_CONTROL_L | MOD_CONTROL_R | MOD_META_L | MOD_META_R | MOD_MODESHIFT | MOD_COMMAND | MOD_COMMAND1 | MOD_COMMAND2); update_leds(id); return (0); } if (sc != NULL) { if (sc->sc_hotkey != NULL) ishotkey = sc->sc_hotkey(sc, sc->sc_hotkeycookie, type, value); if (ishotkey) return 0; if (value < 0 || value >= sc->sc_maplen) { #ifdef DEBUG printf("%s: keycode %d out of range\n", __func__, value); #endif return (0); } kp = sc->sc_map + value; } else { kp = &kpbuf; wskbd_get_mapentry(id->t_keymap, value, kp); } /* if this key has a command, process it first */ if (sc != NULL && kp->command != KS_voidSymbol) iscommand = internal_command(sc, &type, kp->command, kp->group1[0]); /* Now update modifiers */ switch (kp->group1[0]) { case KS_Shift_L: update_modifier(id, type, 0, MOD_SHIFT_L); break; case KS_Shift_R: update_modifier(id, type, 0, MOD_SHIFT_R); break; case KS_Shift_Lock: update_modifier(id, type, 1, MOD_SHIFTLOCK); break; case KS_Caps_Lock: update_modifier(id, type, 1, MOD_CAPSLOCK); break; case KS_Control_L: update_modifier(id, type, 0, MOD_CONTROL_L); break; case KS_Control_R: update_modifier(id, type, 0, MOD_CONTROL_R); break; case KS_Alt_L: update_modifier(id, type, 0, MOD_META_L); break; case KS_Alt_R: update_modifier(id, type, 0, MOD_META_R); break; case KS_Mode_switch: update_modifier(id, type, 0, MOD_MODESHIFT); break; case KS_Num_Lock: update_modifier(id, type, 1, MOD_NUMLOCK); break; #if NWSDISPLAY > 0 case KS_Hold_Screen: if (sc != NULL) { update_modifier(id, type, 1, MOD_HOLDSCREEN); wskbd_holdscreen(sc, id->t_modifiers & MOD_HOLDSCREEN); } break; #endif } /* If this is a key release or we are in command mode, we are done */ if (type != WSCONS_EVENT_KEY_DOWN || iscommand) { update_leds(id); return (0); } /* Get the keysym */ if (id->t_modifiers & MOD_MODESHIFT) group = & kp->group2[0]; else group = & kp->group1[0]; if ((id->t_modifiers & MOD_NUMLOCK) != 0 && KS_GROUP(group[1]) == KS_GROUP_Keypad) { if (MOD_ONESET(id, MOD_ANYSHIFT)) ksym = group[0]; else ksym = group[1]; } else if (! MOD_ONESET(id, MOD_ANYSHIFT | MOD_CAPSLOCK)) { ksym = group[0]; } else if (MOD_ONESET(id, MOD_CAPSLOCK)) { if (! MOD_ONESET(id, MOD_SHIFT_L | MOD_SHIFT_R)) ksym = group[0]; else ksym = group[1]; if (ksym >= KS_a && ksym <= KS_z) ksym += KS_A - KS_a; else if (ksym >= KS_agrave && ksym <= KS_thorn && ksym != KS_division) ksym += KS_Agrave - KS_agrave; } else if (MOD_ONESET(id, MOD_ANYSHIFT)) { ksym = group[1]; } else { ksym = group[0]; } /* Process compose sequence and dead accents */ res = KS_voidSymbol; switch (KS_GROUP(ksym)) { case KS_GROUP_Plain: case KS_GROUP_Keypad: case KS_GROUP_Function: res = ksym; break; case KS_GROUP_Mod: if (ksym == KS_Multi_key) { update_modifier(id, 1, 0, MOD_COMPOSE); id->t_composelen = 2; } break; case KS_GROUP_Dead: if (id->t_composelen == 0) { update_modifier(id, 1, 0, MOD_COMPOSE); id->t_composelen = 1; id->t_composebuf[0] = ksym; } else res = ksym; break; } if (res == KS_voidSymbol) { update_leds(id); return (0); } if (id->t_composelen > 0) { id->t_composebuf[2 - id->t_composelen] = res; if (--id->t_composelen == 0) { res = wskbd_compose_value(id->t_composebuf); update_modifier(id, 0, 0, MOD_COMPOSE); } else { return (0); } } update_leds(id); /* We are done, return the symbol */ if (KS_GROUP(res) == KS_GROUP_Plain) { if (MOD_ONESET(id, MOD_ANYCONTROL)) { if ((res >= KS_at && res <= KS_z) || res == KS_space) res = res & 0x1f; else if (res == KS_2) res = 0x00; else if (res >= KS_3 && res <= KS_7) res = KS_Escape + (res - KS_3); else if (res == KS_8) res = KS_Delete; /* convert CTL-/ to ^_ as xterm does (undo in emacs) */ else if (res == KS_slash) res = KS_underscore & 0x1f; } if (MOD_ONESET(id, MOD_ANYMETA)) { if (id->t_flags & WSKFL_METAESC) { id->t_symbols[0] = KS_Escape; id->t_symbols[1] = res; return (2); } else res |= 0x80; } } id->t_symbols[0] = res; return (1); }