亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 7307 | 回復(fù): 5
打印 上一主題 下一主題

[Linux] ioctl: Operation not supported [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2012-12-11 22:00 |只看該作者 |倒序瀏覽
程序如下:
/*
* setext2.c - Set ext2 special flags
*/
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/ext2_fs.h>
#include <sys/ioctl.h>
#include <errno.h>

int main(int argc, char *argv[])
{
    int fd;
    long flags;

    /* Usage nag */
    if (argc != 2) {
        puts("USAGE:setext2 {filename}");
        exit(EXIT_FAILURE);
    }

    if ((fd = open(argv[1], O_RDONLY)) < 0) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    /* These are the flags we'll set on the file */
    flags = EXT2_SYNC_FL | EXT2_NODUMP_FL;
    if (ioctl(fd, EXT2_IOC_SETFLAGS, &flags)) {
        perror("ioctl");
        close(fd);
        exit(EXIT_FAILURE);
    }

    if (flags & EXT2_SYNC_FL)
        puts("SYNC flag set");
    if (flags & EXT2_NODUMP_FL)
        puts("NODUMP flag set");

    close(fd);
    exit(EXIT_SUCCESS);
}


為什么編譯的時候報錯ioctl: Operation not supported

論壇徽章:
0
2 [報告]
發(fā)表于 2012-12-12 09:38 |只看該作者
本帖最后由 seaquester 于 2012-12-12 11:10 編輯

你說的這個錯誤信息“ioctl: Operation not supported” 不像是編譯是的錯誤信息,反倒像執(zhí)行是的錯誤信息。

我在CentOS 6.3下編譯是下面的錯誤:
$ gcc -Wall -o setext2 setext2.c
In file included from setext2.c:10:
/usr/include/linux/ext2_fs.h: In function ‘ext2_mask_flags’:
/usr/include/linux/ext2_fs.h:182: error: ‘FS_DIRSYNC_FL’ undeclared (first use in this function)
/usr/include/linux/ext2_fs.h:182: error: (Each undeclared identifier is reported only once
/usr/include/linux/ext2_fs.h:182: error: for each function it appears in.)
/usr/include/linux/ext2_fs.h:182: error: ‘FS_TOPDIR_FL’ undeclared (first use in this function)
/usr/include/linux/ext2_fs.h:184: error: ‘FS_NODUMP_FL’ undeclared (first use in this function)
/usr/include/linux/ext2_fs.h:184: error: ‘FS_NOATIME_FL’ undeclared (first use in this function)
setext2.c: In function ‘main’:
setext2.c:30: error: ‘FS_SYNC_FL’ undeclared (first use in this function)
setext2.c:30: error: ‘FS_NODUMP_FL’ undeclared (first use in this function)
setext2.c:31: error: ‘FS_IOC_SETFLAGS’ undeclared (first use in this function)

在 #include <linux/ext2_fs.h>之前,include 另外一個頭文件 fs.h 之后就可以編譯了。
#include <linux/fs.h>

論壇徽章:
0
3 [報告]
發(fā)表于 2012-12-12 11:10 |只看該作者
回復(fù) 1# xiaoruoax

經(jīng)過嘗試發(fā)現(xiàn),解決方法很簡單。
只需要,先通過EXT2_IOC_GETFLAGS獲取 ext2 flags,然后,將要設(shè)置的flag通過 “|” 操作附加上去,然后通過EXT2_IOC_SETFLAGS設(shè)置就可以成功,在CentOS 6.3 (x86_64)上面測試通過。設(shè)置完成后,通過lsattr可以查看設(shè)置的結(jié)果(chattr可以設(shè)置flags)。

示例代碼如下:

  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <fcntl.h>
  6. #include <linux/fs.h>
  7. #include <linux/ext2_fs.h>
  8. #include <sys/ioctl.h>
  9. #include <errno.h>


  10. int main(int argc, char *argv[])
  11. {
  12.     int fd;
  13.     long flags;

  14.     if (argc != 2) {
  15.         printf("Usage: %s <filename>\n", argv[0]);
  16.         exit(EXIT_FAILURE);
  17.     }

  18.     if ((fd = open(argv[1], O_RDONLY)) < 0) {
  19.         perror("open");
  20.         exit(EXIT_FAILURE);
  21.     }

  22.     /* Get attributes from the file */
  23.     if (ioctl(fd, EXT2_IOC_GETFLAGS, &flags)) {
  24.         perror("ioctl");
  25.         exit(EXIT_FAILURE);
  26.     }

  27.     /* Set attributes to the file */
  28.     flags |= (EXT2_SYNC_FL | EXT2_NODUMP_FL);
  29.     if (ioctl(fd, EXT2_IOC_SETFLAGS, &flags)) {
  30.         perror("ioctl");
  31.         close(fd);
  32.         exit(EXIT_FAILURE);
  33.     }

  34.     if (flags & EXT2_SYNC_FL) {
  35.         puts("SYNC flag set");
  36.     }
  37.     if (flags & EXT2_NODUMP_FL) {
  38.         puts("NODUMP flag set");
  39.     }

  40.     close(fd);
  41.     exit(EXIT_SUCCESS);
  42. }
復(fù)制代碼

論壇徽章:
0
4 [報告]
發(fā)表于 2012-12-12 16:55 |只看該作者
不好意思,修改一下,是執(zhí)行的時候的報錯

論壇徽章:
0
5 [報告]
發(fā)表于 2012-12-14 09:07 |只看該作者
回復(fù) 4# xiaoruoax


    試試我修改的那份代碼,在我這邊可以執(zhí)行,沒錯誤。

論壇徽章:
0
6 [報告]
發(fā)表于 2012-12-15 21:45 |只看該作者
回復(fù) 5# seaquester


    果然好了!謝謝O(∩_∩)O
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP