嗨,我正在尝试理解系统调用:unix 上的目录和文件,.. 我发现这个网站他们用自己的例子解释了一些调用,但不理解这些代码片段..
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 ("-"); ....
我不明白比较以找出缺少哪个设备文件..有人可以帮助我理解吗?特别在这里..
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 ("-");
欢迎对双方进行的比较提供任何帮助或解释 PD:对不起我的英语=P
链接显示整个代码示例 1,名为 estado.c