1 | /* |
---|
2 | * IMFS file change mode routine. |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1999. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.OARcorp.com/rtems/license.html. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #if HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <errno.h> |
---|
19 | |
---|
20 | #include <rtems/libio_.h> |
---|
21 | #include "imfs.h" |
---|
22 | |
---|
23 | int IMFS_fchmod( |
---|
24 | rtems_filesystem_location_info_t *loc, |
---|
25 | mode_t mode |
---|
26 | ) |
---|
27 | { |
---|
28 | IMFS_jnode_t *jnode; |
---|
29 | #if defined(RTEMS_POSIX_API) |
---|
30 | uid_t st_uid; |
---|
31 | #endif |
---|
32 | |
---|
33 | jnode = loc->node_access; |
---|
34 | |
---|
35 | /* |
---|
36 | * Verify I am the owner of the node or the super user. |
---|
37 | */ |
---|
38 | #if defined(RTEMS_POSIX_API) |
---|
39 | st_uid = geteuid(); |
---|
40 | |
---|
41 | if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) ) |
---|
42 | set_errno_and_return_minus_one( EPERM ); |
---|
43 | #endif |
---|
44 | |
---|
45 | /* |
---|
46 | * Change only the RWX permissions on the jnode to mode. |
---|
47 | */ |
---|
48 | if ( mode & (~ (S_IRWXU | S_IRWXG | S_IRWXO ) ) ) |
---|
49 | set_errno_and_return_minus_one( EPERM ); |
---|
50 | |
---|
51 | /* |
---|
52 | * If we make a linear-file writeable, construct a block file |
---|
53 | * from it first. |
---|
54 | */ |
---|
55 | if ( (jnode->type == IMFS_LINEAR_FILE) && |
---|
56 | (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) ) |
---|
57 | { |
---|
58 | unsigned32 count = jnode->info.linearfile.size; |
---|
59 | const unsigned char *buffer = jnode->info.linearfile.direct; |
---|
60 | |
---|
61 | jnode->type = IMFS_MEMORY_FILE; |
---|
62 | jnode->info.file.size = 0; |
---|
63 | jnode->info.file.indirect = 0; |
---|
64 | jnode->info.file.doubly_indirect = 0; |
---|
65 | jnode->info.file.triply_indirect = 0; |
---|
66 | if (IMFS_memfile_write(jnode, 0, buffer, count) == -1) |
---|
67 | return(-1); |
---|
68 | } |
---|
69 | |
---|
70 | jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO); |
---|
71 | jnode->st_mode |= mode; |
---|
72 | |
---|
73 | IMFS_update_ctime( jnode ); |
---|
74 | |
---|
75 | return 0; |
---|
76 | } |
---|
77 | |
---|