跟我一起写操作系统

    返回首页    发表留言
本文作者:李德强
          第三节 ls命令
 
 

         ls为list directory contents的简写,即显示目录下的文件相关信息。我们需要让ls命令来显示文件的组号、用户号、权限、文件名等信息。实现如下:

char *current_path = malloc(SHELL_CMD_LEN);
int params[2];
params[0] = 6;
params[1] = (int) current_path;
__asm__ volatile("int $0x80" :: "a"(params));
FILE *fp = malloc(sizeof(FILE));
FILE *p = fp;
fopendir(current_path, fp);
while (p->fs.dot != 0)
{
        printf("%d %d %o %s\n", p->fs.owner, p->fs.group, p->fs.mode, p->fs.name);
        fdirnext(p);
}
fclosedir(fp);
free(fp);
free(current_path);

         运行结果:



 

        源代码的下载地址为:

https            https://github.com/magicworldos/lidqos.git 
git              git@github.com:magicworldos/lidqos.git 
subverion        https://github.com/magicworldos/lidqos 
branch           v0.30

 

    返回首页    返回顶部
  看不清?点击刷新

 

  Copyright © 2015-2023 问渠网 辽ICP备15013245号