%% filedir.tex
%%
-%% Copyright (C) 2000-2002 Simone Piccardi. Permission is granted to
+%% Copyright (C) 2000-2004 Simone Piccardi. Permission is granted to
%% copy, distribute and/or modify this document under the terms of the GNU Free
%% Documentation License, Version 1.1 or any later version published by the
%% Free Software Foundation; with the Invariant Sections being "Prefazione",
\textbf{Funzione} & \textbf{Segue il link} & \textbf{Non segue il link} \\
\hline
\hline
- \func{access} & $\bullet$ & \\
- \func{chdir} & $\bullet$ & \\
- \func{chmod} & $\bullet$ & \\
- \func{chown} & & $\bullet$ \\
- \func{creat} & $\bullet$ & \\
- \func{exec} & $\bullet$ & \\
+ \func{access} & $\bullet$ & -- \\
+ \func{chdir} & $\bullet$ & -- \\
+ \func{chmod} & $\bullet$ & -- \\
+ \func{chown} & -- & $\bullet$ \\
+ \func{creat} & $\bullet$ & -- \\
+ \func{exec} & $\bullet$ & -- \\
\func{lchown} & $\bullet$ & $\bullet$ \\
- \func{link} & & \\
- \func{lstat} & & $\bullet$ \\
- \func{mkdir} & $\bullet$ & \\
- \func{mkfifo} & $\bullet$ & \\
- \func{mknod} & $\bullet$ & \\
- \func{open} & $\bullet$ & \\
- \func{opendir} & $\bullet$ & \\
- \func{pathconf} & $\bullet$ & \\
- \func{readlink} & & $\bullet$ \\
- \func{remove} & & $\bullet$ \\
- \func{rename} & & $\bullet$ \\
- \func{stat} & $\bullet$ & \\
- \func{truncate} & $\bullet$ & \\
- \func{unlink} & & $\bullet$ \\
+ \func{link} & -- & -- \\
+ \func{lstat} & -- & $\bullet$ \\
+ \func{mkdir} & $\bullet$ & -- \\
+ \func{mkfifo} & $\bullet$ & -- \\
+ \func{mknod} & $\bullet$ & -- \\
+ \func{open} & $\bullet$ & -- \\
+ \func{opendir} & $\bullet$ & -- \\
+ \func{pathconf} & $\bullet$ & -- \\
+ \func{readlink} & -- & $\bullet$ \\
+ \func{remove} & -- & $\bullet$ \\
+ \func{rename} & -- & $\bullet$ \\
+ \func{stat} & $\bullet$ & -- \\
+ \func{truncate} & $\bullet$ & -- \\
+ \func{unlink} & -- & $\bullet$ \\
\hline
\end{tabular}
\caption{Uso dei link simbolici da parte di alcune funzioni.}
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{}
-struct dirent {
- ino_t d_ino; /* inode number */
- off_t d_off; /* offset to the next dirent */
- unsigned short int d_reclen; /* length of this record */
- unsigned char d_type; /* type of file */
- char d_name[256]; /* We must not include limits.h! */
-};
- \end{lstlisting}
+ \includestruct{listati/dirent.c}
\end{minipage}
\normalsize
\caption{La struttura \structd{dirent} per la lettura delle informazioni dei
\cmd{ls}).
\begin{figure}[!htb]
- \footnotesize
- \begin{lstlisting}{}
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h> /* directory */
-#include <stdlib.h> /* C standard library */
-#include <unistd.h>
-
-/* computation function for DirScan */
-int do_ls(struct dirent * direntry);
-/* main body */
-int main(int argc, char *argv[])
-{
- ...
- if ((argc - optind) != 1) { /* There must be remaing parameters */
- printf("Wrong number of arguments %d\n", argc - optind);
- usage();
- }
- DirScan(argv[1], do_ls);
- exit(0);
-}
-/*
- * Routine to print file name and size inside DirScan
- */
-int do_ls(struct dirent * direntry)
-{
- struct stat data;
-
- stat(direntry->d_name, &data); /* get stat data */
- printf("File: %s \t size: %d\n", direntry->d_name, data.st_size);
- return 0;
-}
- \end{lstlisting}
+ \footnotesize \centering
+ \begin{minipage}[c]{15.6cm}
+ \includecodesample{listati/my_ls.c}
+ \end{minipage}
\caption{Esempio di codice per eseguire la lista dei file contenuti in una
directory.}
\label{fig:file_my_ls}
valore di ritorno per indicare una esecuzione senza errori.
\begin{figure}[!htb]
- \footnotesize
- \begin{lstlisting}{}
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h> /* directory */
-#include <stdlib.h> /* C standard library */
-#include <unistd.h>
-
-/*
- * Function DirScan:
- *
- * Input: the directory name and a computation function
- * Return: 0 if OK, -1 on errors
- */
-int DirScan(char * dirname, int(*compute)(struct dirent *))
-{
- DIR * dir;
- struct dirent *direntry;
-
- if ( (dir = opendir(dirname)) == NULL) { /* oper directory */
- printf("Opening %s\n", dirname); /* on error print messages */
- perror("Cannot open directory"); /* and then return */
- return -1;
- }
- fd = dirfd(dir); /* get file descriptor */
- fchdir(fd); /* change directory */
- /* loop on directory entries */
- while ( (direntry = readdir(dir)) != NULL) { /* read entry */
- if (compute(direntry)) { /* execute function on it */
- return -1; /* on error return */
- }
- }
- closedir(dir);
- return 0;
-}
-
- \end{lstlisting}
+ \footnotesize \centering
+ \begin{minipage}[c]{15.6cm}
+ \includecodesample{listati/DirScan.c}
+ \end{minipage}
\caption{Codice della routine di scansione di una directory contenuta nel
file \file{DirScan.c}.}
\label{fig:file_dirscan}
\footnotesize
\centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{}
-struct stat {
- dev_t st_dev; /* device */
- ino_t st_ino; /* inode */
- mode_t st_mode; /* protection */
- nlink_t st_nlink; /* number of hard links */
- uid_t st_uid; /* user ID of owner */
- gid_t st_gid; /* group ID of owner */
- dev_t st_rdev; /* device type (if inode device) */
- off_t st_size; /* total size, in bytes */
- unsigned long st_blksize; /* blocksize for filesystem I/O */
- unsigned long st_blocks; /* number of blocks allocated */
- time_t st_atime; /* time of last access */
- time_t st_mtime; /* time of last modification */
- time_t st_ctime; /* time of last change */
-};
- \end{lstlisting}
+ \includestruct{listati/stat.h}
\end{minipage}
\normalsize
\caption{La struttura \structd{stat} per la lettura delle informazioni dei
Ad esempio se si volesse impostare una condizione che permetta di controllare
se un file è una directory o un file ordinario si potrebbe definire la macro
di preprocessore:
-\begin{lstlisting}[labelstep=0,frame=,indent=1cm]{}
-#define IS_FILE_DIR(x) (((x) & S_IFMT) & (S_IFDIR | S_IFREG))
-\end{lstlisting}
+\includecodesnip{listati/is_file_dir.h}
in cui prima si estraggono da \var{st\_mode} i bit relativi al tipo di file e
poi si effettua il confronto con la combinazione di tipi scelta.
\hline
\hline
\func{chmod}, \func{fchmod}
- & & &$\bullet$& & & & \\
+ & -- & -- &$\bullet$& -- & -- & -- & \\
\func{chown}, \func{fchown}
- & & &$\bullet$& & & & \\
+ & -- & -- &$\bullet$& -- & -- & -- & \\
\func{creat}
- &$\bullet$&$\bullet$&$\bullet$& &$\bullet$&$\bullet$& con
+ &$\bullet$&$\bullet$&$\bullet$& -- &$\bullet$&$\bullet$& con
\const{O\_CREATE} \\ \func{creat}
- & &$\bullet$&$\bullet$& &$\bullet$&$\bullet$&
+ & -- &$\bullet$&$\bullet$& -- &$\bullet$&$\bullet$&
con \const{O\_TRUNC} \\ \func{exec}
- &$\bullet$& & & & & & \\
+ &$\bullet$& -- & -- & -- & -- & -- & \\
\func{lchown}
- & & &$\bullet$& & & & \\
+ & -- & -- &$\bullet$& -- & -- & -- & \\
\func{link}
- & & &$\bullet$& &$\bullet$&$\bullet$& \\
+ & -- & -- &$\bullet$& -- &$\bullet$&$\bullet$& \\
\func{mkdir}
- &$\bullet$&$\bullet$&$\bullet$& &$\bullet$&$\bullet$& \\
+ &$\bullet$&$\bullet$&$\bullet$& -- &$\bullet$&$\bullet$& \\
\func{mkfifo}
- &$\bullet$&$\bullet$&$\bullet$& &$\bullet$&$\bullet$& \\
+ &$\bullet$&$\bullet$&$\bullet$& -- &$\bullet$&$\bullet$& \\
\func{open}
- &$\bullet$&$\bullet$&$\bullet$& &$\bullet$&$\bullet$& con
+ &$\bullet$&$\bullet$&$\bullet$& -- &$\bullet$&$\bullet$& con
\const{O\_CREATE} \\ \func{open}
- & &$\bullet$&$\bullet$& & & & con
+ & -- &$\bullet$&$\bullet$& -- & -- & -- & con
\const{O\_TRUNC} \\ \func{pipe}
- &$\bullet$&$\bullet$&$\bullet$& & & & \\
+ &$\bullet$&$\bullet$&$\bullet$& -- & -- & -- & \\
\func{read}
- &$\bullet$& & & & & & \\
+ &$\bullet$& -- & -- & -- & -- & -- & \\
\func{remove}
- & & &$\bullet$& &$\bullet$&$\bullet$& se esegue
+ & -- & -- &$\bullet$& -- &$\bullet$&$\bullet$& se esegue
\func{unlink}\\ \func{remove}
- & & & & &$\bullet$&$\bullet$& se esegue
+ & -- & -- & -- & -- &$\bullet$&$\bullet$& se esegue
\func{rmdir}\\ \func{rename}
- & & &$\bullet$& &$\bullet$&$\bullet$& per entrambi
+ & -- & -- &$\bullet$& -- &$\bullet$&$\bullet$& per entrambi
gli argomenti\\ \func{rmdir}
- & & & & &$\bullet$&$\bullet$& \\
+ & -- & -- & -- & -- &$\bullet$&$\bullet$& \\
\func{truncate}, \func{ftruncate}
- & &$\bullet$&$\bullet$& & & & \\
+ & -- &$\bullet$&$\bullet$& -- & -- & -- & \\
\func{unlink}
- & & &$\bullet$& &$\bullet$&$\bullet$& \\
+ & -- & -- &$\bullet$& -- &$\bullet$&$\bullet$& \\
\func{utime}
- &$\bullet$&$\bullet$&$\bullet$& & & & \\
+ &$\bullet$&$\bullet$&$\bullet$& -- & -- & -- & \\
\func{write}
- & &$\bullet$&$\bullet$& & & & \\
+ & -- &$\bullet$&$\bullet$& -- & -- & -- & \\
\hline
\end{tabular}
\caption{Prospetto dei cambiamenti effettuati sui tempi di ultimo
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{}
-struct utimbuf {
- time_t actime; /* access time */
- time_t modtime; /* modification time */
-};
- \end{lstlisting}
+ \includestruct{listati/utimbuf.h}
\end{minipage}
\normalsize
\caption{La struttura \structd{utimbuf}, usata da \func{utime} per modificare
-&1&-&-&-&0&-&-&-&-&-&-&Il \textit{mandatory locking} è abilitato\\
-&-&1&-&-&-&-&-&-&-&-&-&Non utilizzato\\
-&-&-&1&-&-&-&-&-&-&-&-&Permesso di lettura per il proprietario\\
- -&-&-&-&1&-&-&-&-&-&-&-&Permesso di lettura per il gruppo proprietario\\
- -&-&-&-&-&1&-&-&-&-&-&-&Permesso di lettura per tutti gli altri\\
- -&-&-&-&-&-&1&-&-&-&-&-&Permesso di scrittura per il proprietario\\
+ -&-&-&-&1&-&-&-&-&-&-&-&Permesso di scrittura per il proprietario\\
+ -&-&-&-&-&1&-&-&-&-&-&-&Permesso di esecuzione per il proprietario\\
+ -&-&-&-&-&-&1&-&-&-&-&-&Permesso di lettura per il gruppo proprietario\\
-&-&-&-&-&-&-&1&-&-&-&-&Permesso di scrittura per il gruppo proprietario\\
- -&-&-&-&-&-&-&-&1&-&-&-&Permesso di scrittura per tutti gli altri \\
- -&-&-&-&-&-&-&-&-&1&-&-&Permesso di esecuzione per il proprietario\\
- -&-&-&-&-&-&-&-&-&-&1&-&Permesso di esecuzione per il gruppo proprietario\\
+ -&-&-&-&-&-&-&-&1&-&-&-&Permesso di esecuzione per il gruppo proprietario\\
+ -&-&-&-&-&-&-&-&-&1&-&-&Permesso di lettura per tutti gli altri\\
+ -&-&-&-&-&-&-&-&-&-&1&-&Permesso di scrittura per tutti gli altri \\
-&-&-&-&-&-&-&-&-&-&-&1&Permesso di esecuzione per tutti gli altri\\
\hline
\end{tabular}
-&1&-&-&-&-&-&-&-&-&-&-&Propaga il gruppo proprietario ai nuovi file creati\\
-&-&1&-&-&-&-&-&-&-&-&-&Limita l'accesso in scrittura dei file nella directory\\
-&-&-&1&-&-&-&-&-&-&-&-&Permesso di visualizzazione per il proprietario\\
- -&-&-&-&1&-&-&-&-&-&-&-&Permesso di visualizzazione per il gruppo proprietario\\
- -&-&-&-&-&1&-&-&-&-&-&-&Permesso di visualizzazione per tutti gli altri\\
- -&-&-&-&-&-&1&-&-&-&-&-&Permesso di aggiornamento per il proprietario\\
+ -&-&-&-&1&-&-&-&-&-&-&-&Permesso di aggiornamento per il proprietario\\
+ -&-&-&-&-&1&-&-&-&-&-&-&Permesso di attraversamento per il proprietario\\
+ -&-&-&-&-&-&1&-&-&-&-&-&Permesso di visualizzazione per il gruppo proprietario\\
-&-&-&-&-&-&-&1&-&-&-&-&Permesso di aggiornamento per il gruppo proprietario\\
- -&-&-&-&-&-&-&-&1&-&-&-&Permesso di aggiornamento per tutti gli altri \\
- -&-&-&-&-&-&-&-&-&1&-&-&Permesso di attraversamento per il proprietario\\
- -&-&-&-&-&-&-&-&-&-&1&-&Permesso di attraversamento per il gruppo proprietario\\
+ -&-&-&-&-&-&-&-&1&-&-&-&Permesso di attraversamento per il gruppo proprietario\\
+ -&-&-&-&-&-&-&-&-&1&-&-&Permesso di visualizzazione per tutti gli altri\\
+ -&-&-&-&-&-&-&-&-&-&1&-&Permesso di aggiornamento per tutti gli altri \\
-&-&-&-&-&-&-&-&-&-&-&1&Permesso di attraversamento per tutti gli altri\\
\hline
\end{tabular}
\label{tab:file_dirperm_bits}
\end{table}
-Nelle tabelle si è indicato con $-$ il fatto che il valore degli altri bit non
-è influente rispetto a quanto indicato in ciascuna riga; l'operazione fa
+Nelle tabelle si è indicato con ``-'' il fatto che il valore degli altri bit
+non è influente rispetto a quanto indicato in ciascuna riga; l'operazione fa
riferimento soltanto alla combinazione di bit per i quali il valore è
riportato esplicitamente.