嗨,我正在尝试理解系统调用: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
显示名为 estado.c 的整个代码示例 1 的链接
最佳答案
我假设你的意思是这样的:
(buf.st_dev & 0xFF00)>>8
这不是比较。 >>
是右移运算符。它将第一个操作数向右移动第二个操作数指定的位数。该表达式将 buf.st_dev 中除第 9 到第 16 位以外的所有位清零(这就是 & 0xFF00
所做的),然后将所得的 8 位下移到第 1 到第 8 个最低有效位。这将产生 0 到 255 之间的数字。
关于c - unix 中的系统调用 : directories and files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1898444/