-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc1.c
More file actions
60 lines (47 loc) · 1.12 KB
/
Copy pathmisc1.c
File metadata and controls
60 lines (47 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef MISC1
#define MISC1
#include "type.h"
#include "util.c"
#include "alloc_dalloc.c"
int my_chmod(char *permissions, char *pathname)
{
// (1) get the in-memory INODE of a file
int ino = getino(pathname);
MINODE *mip = iget(dev, ino);
// (2) modify permissions of INODE
short p = mip->INODE.i_mode;
// clear first 9 bits of p
for (int i = 0; i < 9; i++)
{
p = p & ~(1 << i);
}
// set first 9 bits of p
int dec = (int)strtol(permissions, 0, 8);
int i = 0;
while(dec > 0 && i < 9)
{
int bit = dec % 2;
if (bit == 1) p = p | (1 << i);
dec /= 2;
i++;
}
// update i_mode
mip->INODE.i_mode = p;
// (3) INODE modified => mark as dirty
mip->dirty = 1;
// (4) write back
iput(mip);
}
int my_utime(char *pathname)
{
// (1) get the in-memory INODE of a file
int ino = getino(pathname);
MINODE *mip = iget(dev, ino);
// (2) modify permissions of INODE
mip->INODE.i_atime = time(0L);
// (3) INODE modified => mark as dirty
mip->dirty = 1;
// (4) write back
iput(mip);
}
#endif