1

I was trying to implement pwd command in xv6 system. But i am getting a error in sysfile.c execution. The function is as follows showing the error:-

int sys_getcwd(void) {
    char *p;
    int n;
    if(argint(1, &n) < 0 || argptr(0, &p, n) < 0)
       return -1;
    return name_for_inode(p, n, proc->cwd);
}

I get error as follows:

error: ‘proc’ undeclared (first use in this function)
return name_for_inode(p, n, proc->cwd);

But I also included proc.h in this file.

Mathieu
  • 8,840
  • 7
  • 32
  • 45
MSD
  • 11
  • 3
  • Please do not post an image of an error trace. Instead, edit your question and post the code of the problematic function (`sys_getcwd`). See also [ask] – Mathieu Apr 05 '20 at 22:44

2 Answers2

2

proc is not defined, and warning, it's a struct name.

You have to query the current process, you can do it with myproc() function

int sys_getcwd(void) {
    char *p;
    int n;
    struct proc *curproc = myproc();

    if(argint(1, &n) < 0 || argptr(0, &p, n) < 0)
       return -1;

    return name_for_inode(p, n, curproc->cwd);
}
Mathieu
  • 8,840
  • 7
  • 32
  • 45
  • 1
    @MSD If this or any answer has solved your question please consider [accepting](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Mathieu Apr 06 '20 at 14:29
0

Yes proc is not global variable so initialize it with current process on which cpu is working.

struct proc *proc = myproc();
return name_for_inode(p, n, proc->cwd);
sm8799
  • 11
  • 1