hi I'm trying to understand system calls: directories and files on unix, .. I found this website where they explain some calls with their own examples, but do not understand these code snippets ..
void state (char *file)
{
struct stat buf;
struct passwd *pw;
struct group *gr;
int i;
if (stat(file, &buf)==-1)
{
perror(file);
exit(-1);
}
printf ("file: %s\n", archivo);
printf ("\t resides in the device: %d, %d\n",(buf.st_dev & 0xFF00)>>8, buf.st_dev & 0x00FF);
printf ("\t i-node number: %d\n", buf.st_ino);
printf ("\t type: ");
switch (buf.st_mode & S_IFMT)
{
case S_IFREG: printf ("ordinario\n"); break;
case S_IFDIR: printf ("directorio\n"); break;
case S_IFCHR: printf ("tipo caracter\n"); break;
case S_IFBLK: printf ("tipo bloque\n"); break;
case S_IFIFO: printf ("FIFO\n"); break;
}
if (buf.st_mode & S_ISUID) printf ("\tSUID activo");
if (buf.st_mode & S_ISGID) printf ("\tSGID activo");
if (buf.st_mode & S_ISVTX) printf ("\tStiky bit activo\n");
/* Permissions access */
printf ("\tPermission: 0%o ",buf.st_mode & 0777);
for (i=0; i<9; i++)
if (buf.st_mode & (0400>>i)) printf ("%c", permisos[(8-i)%3]);
else printf ("-"); ....
I do not understand the comparison to find out which device file is missing .. someone could help me understand? specifically here ..
printf ("\tReside en el dispositivo: %d, %d\n", (buf.st_dev & 0xFF00)>>8,
buf.st_dev & 0x00FF);
/* Permissions */
printf ("\tPermission: 0%o ",buf.st_mode & 0777);
for (i=0; i<9; i++)
if (buf.st_mode & (0400>>i)) printf ("%c", permisos[(8-i)%3]);
else printf ("-");
would welcome any help or explanation of the comparisons that are made on both sides PD: sorry for my english =P
link where it appears the entire code example 1 called estado.c
http://translate.googleusercontent.com/translate_c?hl=es&ie=UTF-8&sl=es&tl=en&u=http://malicia.super.unam.mx/wiki/index.php/Llamadas%5Fal%5FSistema%3A%5FDirectorios%5Fy%5FArchivos&prev=%5Ft&rurl=translate.google.co.ve&twu=1&usg=ALkJrhhwwFSx-UiPs4rtgSJADbrZy13v7A