source: mainline/uspace/lib/posix/sys/stat.h@ 63fc519

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 63fc519 was e7f7c93, checked in by Petr Koupy <petr.koupy@…>, 14 years ago

Reverted changes causing circular dependencies in types.h.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Zarevucky
3 * Copyright (c) 2011 Petr Koupy
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file
34 */
35
36#ifndef POSIX_SYS_STAT_H_
37#define POSIX_SYS_STAT_H_
38
39#include "../libc/sys/stat.h"
40#include "types.h"
41#include "../time.h"
42#include <ipc/devmap.h>
43#include <task.h>
44
45typedef devmap_handle_t posix_dev_t;
46typedef task_id_t posix_pid_t;
47
48/* values are the same as on Linux */
49
50#undef S_IFMT
51#undef S_IFSOCK
52#undef S_IFLNK
53#undef S_IFREG
54#undef S_IFBLK
55#undef S_IFDIR
56#undef S_IFCHR
57#undef S_IFIFO
58#define S_IFMT 0170000 /* all file types */
59#define S_IFSOCK 0140000 /* socket */
60#define S_IFLNK 0120000 /* symbolic link */
61#define S_IFREG 0100000 /* regular file */
62#define S_IFBLK 0060000 /* block device */
63#define S_IFDIR 0040000 /* directory */
64#define S_IFCHR 0020000 /* character device */
65#define S_IFIFO 0010000 /* FIFO */
66
67#undef S_ISUID
68#undef S_ISGID
69#undef S_ISVTX
70#define S_ISUID 0004000 /* SUID */
71#define S_ISGID 0002000 /* SGID */
72#define S_ISVTX 0001000 /* sticky */
73
74#undef S_IRWXU
75#undef S_IRUSR
76#undef S_IWUSR
77#undef S_IXUSR
78#define S_IRWXU 00700 /* owner permissions */
79#define S_IRUSR 00400
80#define S_IWUSR 00200
81#define S_IXUSR 00100
82
83#undef S_IRWXG
84#undef S_IRGRP
85#undef S_IWGRP
86#undef S_IXGRP
87#define S_IRWXG 00070 /* group permissions */
88#define S_IRGRP 00040
89#define S_IWGRP 00020
90#define S_IXGRP 00010
91
92#undef S_IRWXO
93#undef S_IROTH
94#undef S_IWOTH
95#undef S_IXOTH
96#define S_IRWXO 00007 /* other permissions */
97#define S_IROTH 00004
98#define S_IWOTH 00002
99#define S_IXOTH 00001
100
101#undef S_ISREG
102#undef S_ISDIR
103#undef S_ISCHR
104#undef S_ISBLK
105#undef S_ISFIFO
106#undef S_ISLNK
107#undef S_ISSOCK
108#define S_ISREG(m) ((m & S_IFREG) != 0)
109#define S_ISDIR(m) ((m & S_IFDIR) != 0)
110#define S_ISCHR(m) ((m & S_IFCHR) != 0)
111#define S_ISBLK(m) ((m & S_IFBLK) != 0)
112#define S_ISFIFO(m) ((m & S_IFIFO) != 0)
113#define S_ISLNK(m) ((m & S_IFLNK) != 0) /* symbolic link? (Not in POSIX.1-1996.) */
114#define S_ISSOCK(m) ((m & S_IFSOCK) != 0) /* socket? (Not in POSIX.1-1996.) */
115
116struct posix_stat {
117 struct stat sys_stat;
118
119 posix_dev_t st_dev; /* ID of device containing file */
120 posix_ino_t st_ino; /* inode number */
121 mode_t st_mode; /* protection */
122 posix_nlink_t st_nlink; /* number of hard links */
123 posix_uid_t st_uid; /* user ID of owner */
124 posix_gid_t st_gid; /* group ID of owner */
125 posix_dev_t st_rdev; /* device ID (if special file) */
126 posix_off_t st_size; /* total size, in bytes */
127 posix_blksize_t st_blksize; /* blocksize for file system I/O */
128 posix_blkcnt_t st_blocks; /* number of 512B blocks allocated */
129 time_t st_atime; /* time of last access */
130 time_t st_mtime; /* time of last modification */
131 time_t st_ctime; /* time of last status change */
132};
133
134extern int posix_fstat(int fd, struct posix_stat *st);
135extern int posix_lstat(const char *restrict path, struct posix_stat *restrict st);
136extern int posix_stat(const char *restrict path, struct posix_stat *restrict st);
137extern int posix_chmod(const char *path, mode_t mode);
138extern mode_t posix_umask(mode_t mask);
139
140#ifndef LIBPOSIX_INTERNAL
141 #define dev_t posix_dev_t
142 #define pid_t posix_pid_t
143 #define fstat posix_fstat
144 #define lstat posix_lstat
145 #define stat posix_stat
146 #define chmod posix_chmod
147 #define umask posix_umask
148#endif
149
150#endif /* POSIX_SYS_STAT_H */
151
152/** @}
153 */
Note: See TracBrowser for help on using the repository browser.