You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
6.0 KiB
228 lines
6.0 KiB
\chapter{Hardware} |
|
\label{chap:hardware} |
|
|
|
% ----------------------------------------------------------- |
|
\section{Joystick}\index{joystick} |
|
|
|
\begin{verbatim} |
|
int foo, joy_fd; |
|
struct js_event js; |
|
|
|
|
|
joy_fd = open(joy_device , O_RDONLY); |
|
foo = read(joy_fd, &js, sizeof(struct js_event)); |
|
|
|
\end{verbatim} |
|
|
|
% ----------------------------------------------------------- |
|
|
|
\section{Diagnostics} |
|
|
|
Quand les choses ne se passent pas comme prévu, quand il |
|
y a des accrocs dans le plan, que le résultat n'est |
|
qu'une video totalement noire de 17 minutes. |
|
dmesg, lshw, lsusb, lspci\dots |
|
|
|
% ----------------------------------------------------------- |
|
\section{Ports série} |
|
\index{rs232} \label{rs232} |
|
|
|
\begin{quote} |
|
RS-232 (parfois appelée EIA RS-232, EIA 232 ou TIA 232) est |
|
une norme standardisant une voie de communication de type série. |
|
Le standard RS-232 recouvre plusieurs autres standards~: |
|
les recommandations UIT-T V.24 (définition des circuits) |
|
et V.28 (caractéristiques électriques), |
|
ainsi que la norme ISO 2110 pour la connectique. |
|
\end{quote} |
|
|
|
Comment détecter si un \textit{device} correspond bien |
|
à un port série ? |
|
|
|
\begin{lstlisting}[language=C] |
|
#include <stdio.h> |
|
#include <fcntl.h> |
|
#include <termios.h> |
|
|
|
#define TTY "/dev/ttyS18" |
|
|
|
int main(void) { |
|
int fd = open(TTY, O_RDWR | O_NOCTTY); |
|
if (fd < 0) { |
|
perror("open " TTY); |
|
return 1; |
|
} |
|
|
|
struct termios tio; |
|
if (tcgetattr(fd, &tio)) { |
|
perror("tcgetattr " TTY); |
|
return 1; |
|
} |
|
|
|
return 0; |
|
} |
|
\end{lstlisting} |
|
|
|
Et la question qui, je le sens, va venir~: « à quoi peut bien |
|
servir un port série ? » appelle un réponse presque évidente~: |
|
« à plusieurs choses ». Une petite liste~: |
|
Connecter un Minitel\index{MINITEL} |
|
pour dialoguer avec Ulla Trentsixquinze ? Brancher un |
|
Sportster 14400 pour retrouver Fidonet\index{Fidonet} ? |
|
Discuter avec un équipement avionnique ? Rediriger |
|
l'impression d'un MSX\index{MSX} vers Cups\index{cups} ? |
|
|
|
Les possibilités sont infinies. C'est votre imagination qui |
|
est la limite\footnote{Comme à peu près tout dans la vie.} |
|
|
|
% ----------------------------------------------------------- |
|
\section{Ports //} \label{portparallele} |
|
\index{port //} |
|
|
|
% http://people.redhat.com/twaugh/parport/html/x623.html |
|
|
|
périphérique \texttt{/dev/parport} |
|
|
|
% ----------------------------------------------------------- |
|
|
|
\section{Disques durs} |
|
|
|
Iozone ? Bonnie ? Smart\index{smart} ? UUID\index{uuid} ? |
|
Ddrescue\index{ddrescue} ? |
|
|
|
\subsection{blkid \& lsblk} |
|
|
|
À mi-chemin entre le matériel et le système, la commande |
|
\texttt{blkid}\index{blkid} affiche quelques informations |
|
sur les périphériques blocs |
|
et surtout les partitions qu'ils contiennent~: |
|
|
|
\begin{itemize} |
|
\item Périphérique dans \texttt{/dev/} |
|
\item UUID XXX\index{XXX} |
|
\item Type de la partition |
|
\item Label textuel |
|
\item PARTUID |
|
\end{itemize} |
|
|
|
|
|
\vspace{1em} |
|
|
|
Quand à \texttt{lsblk}\index{lsblk}, elle affiche |
|
le même genre d'information, mais en plus joli |
|
(j'ai utilisé l'option \texttt{-i} pour que le résultat |
|
passe mieux à l'impression)~: |
|
|
|
\begin{verbatim} |
|
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT |
|
sda 8:0 0 232.9G 0 disk |
|
+-sda1 8:1 0 18.6G 0 part / |
|
+-sda2 8:2 0 3.8G 0 part [SWAP] |
|
+-sda3 8:3 0 488M 0 part /boot |
|
+-sda4 8:4 0 210G 0 part /home |
|
\end{verbatim} |
|
|
|
|
|
% ----------------------------------------------------------- |
|
|
|
\subsection{Smart}\index{smart} |
|
|
|
Self-Monitoring, Analysis and Reporting Technology% |
|
\footnote{http://www.smartmontools.org/} est un ensemble |
|
de choses pour la surveillance de l'état des disques durs |
|
et dérivés (SSD\index{SSD}). Il permettrait, dans un monde |
|
idéal, la prédiction des pannes. |
|
|
|
\begin{verbatim} |
|
smartctl -a /dev/sda |
|
Print a large amount of SMART information for drive /dev/sda . |
|
\end{verbatim} |
|
|
|
% ----------------------------------------------------------- |
|
\subsection{fsck}\index{fsck}\index{fuck} |
|
|
|
\textsl{Check and repair a Linux filesystem} |
|
|
|
Fortune du jour : \textsf{Franchement, là, je préfère que ce soit vous qui prenne la |
|
tronçonneuse, parce que là, c'est pas beau à voir\dots} |
|
|
|
% ----------------------------------------------------------- |
|
\subsection{tune2fs}\index{tune2fs} |
|
|
|
\textsl{Adjust tunable filesystem parameters on ext2/ext3/ext4 |
|
filesystems}\footnote{You can tune a fs, but you can't tuna fish}. |
|
|
|
% ----------------------------------------------------------- |
|
|
|
\section{Interface réseau}\index{NIC} |
|
|
|
On a parfois besoin de savoir dans quel état est une interface |
|
réseau Ethernet |
|
(\textsc{up}, \textsc{running} dans la sortie de ifconfig). |
|
Parfois, je n'aime pas trop \textit{parser} celle-ci à grand |
|
coup de \textit{regexp}\index{regexp}, en particulier dans un |
|
contexte de type Busybox\index{busybox}. Et pour ce cas-là, je |
|
préfère utiliser un binaire brassé à la maison, et dont voici |
|
un fragment de source : |
|
|
|
|
|
\begin{lstlisting}[language=C] |
|
int get_if_flags(char *ifname, short *p_flags) |
|
{ |
|
int fd; |
|
int retcode; |
|
struct ifreq req; |
|
|
|
#if DEBUG_LEVEL |
|
fprintf(stderr, ">>> %s \"%s\" to %p\n", \ |
|
__func__, ifname, p_flags); |
|
#endif |
|
|
|
/* Sanity check */ |
|
if ( strlen(ifname) > (IFNAMSIZ-1) ) |
|
{ |
|
fprintf(stderr, "name %s to long\n", ifname); |
|
abort(); |
|
} |
|
|
|
fd = socket(PF_INET, SOCK_DGRAM, 0); |
|
if (fd < 0) |
|
{ |
|
perror("socket bla..."); |
|
return -2; |
|
} |
|
|
|
/* populate the struct for the request */ |
|
memset(&req, 0, sizeof(req)); |
|
strcpy(req.ifr_name, ifname); |
|
|
|
/* do the call */ |
|
retcode = ioctl(fd, SIOCGIFFLAGS, &req); |
|
if (retcode < 0) |
|
{ |
|
perror("ioctl SIOCGIFFLAGS"); |
|
close(fd); |
|
return -1; |
|
} |
|
#if DEBUG_LEVEL |
|
/* display the result */ |
|
fprintf(stderr, "flags = 0x%04x\n", req.ifr_flags); |
|
#endif |
|
|
|
close(fd); |
|
|
|
*p_flags = req.ifr_flags; |
|
return 0; |
|
} |
|
\end{lstlisting} |
|
|
|
Hélas, je n'ai pas pu trop tester ce truc sur beaucoup de systèmes, |
|
et je vous propose de ne pas trop lui faire confiance pour une |
|
application critique... |
|
|
|
|
|
% ----------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|