xv6 chmod function. Most of the code is below, just need to add in the code expl
ID: 3754869 • Letter: X
Question
xv6 chmod function.
Most of the code is below, just need to add in the code explained in lines 453-456.
examples of argstr, argint, and namei:
445 int 46 sys_chmod(void)// chmod implementation 447 448 char path;// file/directory path name 449 int mode; 45 struct inode ip; / ptr to inode 451 452 53 11 Add code here to: 454 111) Retrieve the path and mode arguments and ensure they are valid formats. If not, exit. 455 1 2) Evaluate the path and return corresponding inode (ip). If path is not valid, exit 56 / Hint: You will need to use the argstr, argint, and namei functions 457 458 begin op): ait until there is space for log entry or if another transaction is taking place 459 ilock (ip)/ Lock inode 466 461 ip->mode mode; // update mode 462 463 update(ip) copy modified inode to disk 464 unlockput(ip); unlock inode 65 end op(); 466 467 return e; 468 //permission /decrement outstanding count of sys calls&start commit process when concurrent sys calls are done 469 /chmodExplanation / Answer
/*If it helps then Please Upvote*/
CODE:-
int sys_chmod(void)
{
char *path; // file/directory path name
int mode; // permission
struct inode *ip; // ptr to inode
if(argstr(0, &path) < 0 || argint(1, &mode) < 0)
return -1;
begin_op();
if((ip = namei(path)) == 0) {
end_op();
return -1;
}
ilock(ip);
ip->mode = mode;
iupdate(ip); // Copy to disk
iunlockput(ip);
end_op();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.