source: rtems/c/src/libfs/src/imfs/imfs_fchmod.c @ d6b1d73

4.104.114.84.95
Last change on this file since d6b1d73 was d6b1d73, checked in by Joel Sherrill <joel.sherrill@…>, on 01/22/01 at 14:05:14

2001-01-22 Ralf Corsepius <corsepiu@…>

  • configure.in: Add src/imfs/config.h
  • src/imfs/Makefile.am: Add INCLUDES += -I. to pickup config.h
  • src/imfs/.cvsignore: Add config.h and stamp-h
  • src/imfs/*.c: Add config.h support.
  • Property mode set to 100644
File size: 1.7 KB
Line 
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
23int 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
Note: See TracBrowser for help on using the repository browser.