OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libfs/] [src/] [imfs/] [imfs_fchmod.c] - Blame information for rev 1026

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  imfs_fchmod.c,v 1.7 2002/01/04 18:30:58 joel Exp
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 <rtems/seterr.h>
22
#include "imfs.h"
23
 
24
int IMFS_fchmod(
25
  rtems_filesystem_location_info_t *loc,
26
  mode_t                            mode
27
)
28
{
29
  IMFS_jnode_t  *jnode;
30
#if defined(RTEMS_POSIX_API)
31
  uid_t          st_uid;
32
#endif
33
 
34
  jnode = loc->node_access;
35
 
36
  /*
37
   *  Verify I am the owner of the node or the super user.
38
   */
39
#if defined(RTEMS_POSIX_API)
40
  st_uid = geteuid();
41
 
42
  if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) )
43
    rtems_set_errno_and_return_minus_one( EPERM );
44
#endif
45
 
46
  /*
47
   * Change only the RWX permissions on the jnode to mode.
48
   */
49
  if ( mode & (~ (S_IRWXU | S_IRWXG | S_IRWXO ) ) )
50
    rtems_set_errno_and_return_minus_one( EPERM );
51
 
52
  /*
53
   * If we make a linear-file writeable, construct a block file
54
   * from it first.
55
   */
56
  if ( (jnode->type == IMFS_LINEAR_FILE) &&
57
       (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) )
58
  {
59
    unsigned32 count = jnode->info.linearfile.size;
60
    const unsigned char *buffer = jnode->info.linearfile.direct;
61
 
62
    jnode->type = IMFS_MEMORY_FILE;
63
    jnode->info.file.size            = 0;
64
    jnode->info.file.indirect        = 0;
65
    jnode->info.file.doubly_indirect = 0;
66
    jnode->info.file.triply_indirect = 0;
67
    if (IMFS_memfile_write(jnode, 0, buffer, count) == -1)
68
       return(-1);
69
  }
70
 
71
  jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO);
72
  jnode->st_mode |= mode;
73
 
74
  IMFS_update_ctime( jnode );
75
 
76
  return 0;
77
}
78
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.