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

4.104.114.84.95
Last change on this file since d1941587 was d1941587, checked in by Joel Sherrill <joel.sherrill@…>, on 01/12/01 at 13:44:12

2001-01-12 Jake Janovetz <janovetz@…>

  • src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c, src/imfs/miniimfs_init.c: Final developmental update to "tarfs". When rtems_tarfs_load() is called, it checks the permissions on each file. If there is write permission, it just creates a standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE. If there is no write permission, it creates a LINEAR_FILE node with the appropriate properties. If the permission is ever changed to writeable, IMFS_fchmod converts it to a regular memory file.
  • 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#include <errno.h>
15
16#include <rtems/libio_.h>
17#include "imfs.h"
18
19int IMFS_fchmod(
20  rtems_filesystem_location_info_t *loc,
21  mode_t                            mode
22)
23{
24  IMFS_jnode_t  *jnode;
25#if defined(RTEMS_POSIX_API)
26  uid_t          st_uid;
27#endif
28   
29  jnode = loc->node_access;
30
31  /*
32   *  Verify I am the owner of the node or the super user.
33   */
34#if defined(RTEMS_POSIX_API)
35  st_uid = geteuid();
36
37  if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) )
38    set_errno_and_return_minus_one( EPERM );
39#endif
40
41  /*
42   * Change only the RWX permissions on the jnode to mode.
43   */
44  if ( mode & (~ (S_IRWXU | S_IRWXG | S_IRWXO ) ) )
45    set_errno_and_return_minus_one( EPERM );
46
47  /*
48   * If we make a linear-file writeable, construct a block file
49   * from it first.
50   */
51  if ( (jnode->type == IMFS_LINEAR_FILE) &&
52       (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) )
53  {
54    unsigned32 count = jnode->info.linearfile.size;
55    const unsigned char *buffer = jnode->info.linearfile.direct;
56
57    jnode->type = IMFS_MEMORY_FILE;
58    jnode->info.file.size            = 0;
59    jnode->info.file.indirect        = 0;
60    jnode->info.file.doubly_indirect = 0;
61    jnode->info.file.triply_indirect = 0;
62    if (IMFS_memfile_write(jnode, 0, buffer, count) == -1)
63       return(-1);
64  }
65
66  jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO);
67  jnode->st_mode |= mode;
68
69  IMFS_update_ctime( jnode );
70
71  return 0;
72}
73
Note: See TracBrowser for help on using the repository browser.