c - unix 中的系统调用 : directories and files

标签 c unix file directory system-calls

嗨,我正在尝试理解系统调用: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 的链接

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_al_Sistema:_Directorios_y_Archivos&prev=_t&rurl=translate.google.co.ve&twu=1&usg=ALkJrhhwwFSx-UiPs4rtgSJADbrZy13v7A

最佳答案

我假设你的意思是这样的:

(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/

相关文章:

c++ - gcc/ld : what is to -Wl, 动态链接中的-rpath 什么是静态链接中的-l 到-L?

linux - 过滤 Sudoers 文件中的用户

linux - root创建的所有文件都被写保护

java - 如何在 Java 中获取文件的文件扩展名?

c - 组播回显服务器

c - 结构体和指针算术

c - 代码效率不高

c++ - 可以在没有终端的情况下在 Unix 进程上写入标准输出吗?

c# - 如何以编程方式从共享点站点下载文件?

c - ‘main’ 通常是一个非静态函数 ERROR