1 /* libc/sys/linux/inode.c - Inode-related system calls */
2 
3 /* Written 2000 by Werner Almesberger */
4 
5 
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <sys/utime.h>
11 #include <linux/dirent.h>
12 #include <machine/syscall.h>
13 
14 #define _LIBC 1
15 #include <sys/lock.h>
16 
17 
18 #define __NR___umask __NR_umask
19 
_syscall2(int,link,const char *,oldpath,const char *,newpath)20 _syscall2(int,link,const char *,oldpath,const char *,newpath)
21 _syscall1(int,unlink,const char *,pathname)
22 _syscall1(int,chdir,const char *,path)
23 _syscall1(int,fchdir,int,fd)
24 _syscall2(int,access,const char *,filename,int,mode)
25 _syscall2(int,mkdir,const char *,pathname,mode_t,mode)
26 _syscall1(int,rmdir,const char *,pathname)
27 _syscall1(int,chroot,const char *,path)
28 _syscall2(int,stat,const char *,file_name,struct stat *,buf)
29 _syscall2(int,statfs,const char *,file_name,struct statfs *,buf)
30 _syscall2(int,fstat,int,filedes,struct stat *,buf)
31 _syscall2(int,fstatfs,int,filedes,struct statfs *,buf)
32 _syscall3(int,getdents,int,fd,struct dirent *,dirp,unsigned int,count)
33 
34 #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2
35 _syscall2(int,chmod,const char *,path,mode_t,mode)
36 _syscall3(int,chown,const char *,path,uid_t,owner,gid_t,group)
37 _syscall2(int,fchmod,int,filedes,mode_t,mode)
38 _syscall2(int,lstat,const char *,file_name,struct stat *,buf)
39 _syscall3(int,readlink,const char *,path,char *,buf,size_t,bufsiz)
40 _syscall2(int,symlink,const char *,oldpath,const char *,newpath)
41 _syscall2(int,utime,const char *,filename,const struct utimbuf *,buf)
42 #endif
43 
44 #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 3
45 _syscall1(int,pipe,int *,filedes)
46 #endif
47 
48 #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 4
49 _syscall3(int,mknod,const char *,pathname,mode_t,mode,dev_t,dev)
50 #endif
51 
52 weak_alias(__libc_statfs,__statfs)
53 weak_alias(__libc_fstatfs,__fstatfs)
54 
55 static _syscall3(int,fchown32,int,fd,uid_t,owner,gid_t,group)
56 
57 int
58 fchown (int fd, uid_t owner, gid_t group)
59 {
60   return __libc_fchown32 (fd, owner, group);
61 }
62 
63 #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2
64 
65 __LOCK_INIT(static, umask_lock);
66 
_syscall1(mode_t,__umask,mode_t,mask)67 _syscall1(mode_t,__umask,mode_t,mask)
68 
69 mode_t
70 umask (mode_t mask)
71 {
72   mode_t old_mask;
73 
74   /* we need to lock so as to not interfere with getumask */
75   __lock_acquire(umask_lock);
76   old_mask = __umask (mask);
77   __lock_release(umask_lock);
78 
79   return old_mask;
80 }
81 
82 mode_t
getumask(void)83 getumask (void)
84 {
85   mode_t mask;
86 
87   __lock_acquire(umask_lock);
88 
89   mask = __umask (0);
90   mask = __umask (mask);
91 
92   __lock_release(umask_lock);
93 
94   return mask;
95 }
96 
97 #endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 2 */
98