Re: materiel: control du ventilo de CPU\

Pàgina inicial

Reply to this message
Autor: Edgar Bonet
Data:  
A: guilde
Assumpte: Re: materiel: control du ventilo de CPU\
Le jeudi 6 novembre, Stephane Driussi a écrit :
> ************* scsistart.c *******************
> #include <stdio.h>
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> #include <sys/ioctl.h>
> #include <scsi/scsi_ioctl.h>
>
> main(int argc, char **argv){


warning: return type defaults to `int'

> int fd;
>
>  if (argc != 2) {
>    fprintf(stderr, "Usage: %s /dev/something\n", argv[0]);
>    exit(1);


warning: implicit declaration of function `exit'

> }
>
>  if ((fd=open(argv[1], O_RDONLY))==-1) {
>    perror(argv[0]);


Tu veux dire perror(argv[1]); je pense.

>    exit(2);
>  }

>
> if (ioctl(fd, SCSI_IOCTL_START_UNIT)) {


C'est cet ioctl qui fait tout le boulot. Le tout était de connaître son
existence...

>    perror(argv[0]);
>    exit(3);
>  }

>
> exit(0);
> }
>
> ************* scsistop.c *******************


Presqu'identique au précédent. C'est un peu dommage d'en faire deux
programmes. Voici les deux regroupés en un seul, avec ces erreurs
corrigées. Il faut en faire deux liens (durs ou symboliques) appelés
scsistart et scsistop.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <scsi/scsi_ioctl.h>

int main(int argc, char **argv) {
int fd;
int action;
char *end_cmd;

  end_cmd = argv[0] + strlen(argv[0]);
  if (strcmp(end_cmd - 5, "start") == 0)
    action = SCSI_IOCTL_START_UNIT;
  else if (strcmp(end_cmd - 4, "stop") == 0)
    action = SCSI_IOCTL_STOP_UNIT;
  else {
    fprintf(stderr, "The name of this command "
        "should end with \"start\" or \"stop\".\n");
    exit(1);
  }


  if (argc != 2) {
    fprintf(stderr, "Usage: %s /dev/something\n", argv[0]);
    exit(1);
  }


  if ((fd=open(argv[1], O_RDONLY))==-1) {
    perror(argv[1]);
    exit(2);
  }


  if (ioctl(fd, action)) {
    perror(argv[1]);
    exit(3);
  }


return EXIT_SUCCESS;
}

-- 
Edgar Bonet           Maison : 04 76 21 29 16    Bureau : 04 76 88 10 96
3 rue Jean Prévost    Mobile : 06 77 19 79 39    Fax    : 04 76 88 11 91
38000 Grenoble        guilde@???     www.edgar-bonet.org