|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* Copyright (C) 2014 Colin Walters <walters@verbum.org>
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* SPDX-License-Identifier: LGPL-2.0+
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0fba15 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0fba15 |
* version 2 of the License, or (at your option) any later version.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0fba15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0fba15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0fba15 |
* Lesser General Public License for more details.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License along with this library; if not, write to the
|
|
rpm-build |
0fba15 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
rpm-build |
0fba15 |
* Boston, MA 02111-1307, USA.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "config.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "ostree-linuxfsutil.h"
|
|
rpm-build |
0fba15 |
#include "otutil.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include <fcntl.h>
|
|
rpm-build |
0fba15 |
#include <sys/ioctl.h>
|
|
rpm-build |
0fba15 |
#include <ext2fs/ext2_fs.h>
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "otutil.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/**
|
|
rpm-build |
0fba15 |
* _ostree_linuxfs_fd_alter_immutable_flag:
|
|
rpm-build |
0fba15 |
* @fd: A file descriptor
|
|
rpm-build |
0fba15 |
* @new_immutable_state: Set this to %TRUE to make the file immutable, %FALSE to unset the flag
|
|
rpm-build |
0fba15 |
* @cancellable: Cancellable
|
|
rpm-build |
0fba15 |
* @error: GError
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* Alter the immutable flag of object referred to by @fd; may be a
|
|
rpm-build |
0fba15 |
* regular file or a directory.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* If the operation is not supported by the underlying filesystem, or
|
|
rpm-build |
0fba15 |
* we are running without sufficient privileges, this function will
|
|
rpm-build |
0fba15 |
* silently do nothing.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
_ostree_linuxfs_fd_alter_immutable_flag (int fd,
|
|
rpm-build |
0fba15 |
gboolean new_immutable_state,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
static gint no_alter_immutable = 0;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (g_atomic_int_get (&no_alter_immutable))
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
unsigned long flags;
|
|
rpm-build |
0fba15 |
int r = ioctl (fd, EXT2_IOC_GETFLAGS, &flags);
|
|
rpm-build |
0fba15 |
if (r == -1)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (errno == EPERM)
|
|
rpm-build |
0fba15 |
g_atomic_int_set (&no_alter_immutable, 1);
|
|
rpm-build |
0fba15 |
else if (errno == EOPNOTSUPP || errno == ENOTTY)
|
|
rpm-build |
0fba15 |
;
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
return glnx_throw_errno_prefix (error, "ioctl(EXT2_IOC_GETFLAGS)");
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
gboolean prev_immutable_state = (flags & EXT2_IMMUTABLE_FL) > 0;
|
|
rpm-build |
0fba15 |
if (prev_immutable_state == new_immutable_state)
|
|
rpm-build |
0fba15 |
return TRUE; /* Nothing to do */
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (new_immutable_state)
|
|
rpm-build |
0fba15 |
flags |= EXT2_IMMUTABLE_FL;
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
flags &= ~EXT2_IMMUTABLE_FL;
|
|
rpm-build |
0fba15 |
r = ioctl (fd, EXT2_IOC_SETFLAGS, &flags);
|
|
rpm-build |
0fba15 |
if (r == -1)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (errno == EPERM)
|
|
rpm-build |
0fba15 |
g_atomic_int_set (&no_alter_immutable, 1);
|
|
rpm-build |
0fba15 |
else if (errno == EOPNOTSUPP || errno == ENOTTY)
|
|
rpm-build |
0fba15 |
;
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
return glnx_throw_errno_prefix (error, "ioctl(EXT2_IOC_SETFLAGS)");
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|