Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
truenas-rk3588
zfs
Commits
c23bf227
Commit
c23bf227
authored
2 years ago
by
Umer Saleem
Browse files
Options
Download
Email Patches
Plain Diff
Set immutable flag on auto-generated dataset mountpoints
Signed-off-by:
Umer Saleem
<
usaleem@ixsystems.com
>
parent
2bb9ef45
NAS-117807-1
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/libzfs/libzfs_mount.c
+41
-0
lib/libzfs/libzfs_mount.c
with
41 additions
and
0 deletions
+41
-0
lib/libzfs/libzfs_mount.c
View file @
c23bf227
...
...
@@ -82,6 +82,7 @@
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/dsl_crypt.h>
#include <linux/fs.h>
#include <libzfs.h>
...
...
@@ -363,6 +364,34 @@ zfs_add_options(zfs_handle_t *zhp, char *options, int len)
return
(
error
);
}
static
int
zfs_mount_set_uchg
(
const
char
*
mountpoint
)
{
int
fd
,
r
;
uint32_t
attrs
;
fd
=
open
(
mountpoint
,
(
O_RDONLY
|
O_NONBLOCK
|
O_NOFOLLOW
));
if
(
fd
<
0
)
return
-
1
;
printf
(
"Mountpoint %s opened!
\n
"
,
mountpoint
);
r
=
ioctl
(
fd
,
FS_IOC_GETFLAGS
,
&
attrs
);
if
(
r
<
0
)
goto
out
;
printf
(
"Attributes before: 0x%x
\n
"
,
attrs
);
attrs
|=
FS_IMMUTABLE_FL
;
r
=
ioctl
(
fd
,
FS_IOC_SETFLAGS
,
&
attrs
);
if
(
r
<
0
)
goto
out
;
attrs
=
-
1
;
r
=
ioctl
(
fd
,
FS_IOC_GETFLAGS
,
&
attrs
);
if
(
r
<
0
)
goto
out
;
printf
(
"Attributes after: 0x%x
\n
"
,
attrs
);
out:
close
(
fd
);
return
r
;
}
int
zfs_mount
(
zfs_handle_t
*
zhp
,
const
char
*
options
,
int
flags
)
{
...
...
@@ -391,6 +420,7 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
libzfs_handle_t
*
hdl
=
zhp
->
zfs_hdl
;
uint64_t
keystatus
;
int
remount
=
0
,
rc
;
boolean_t
set_uchg
=
B_FALSE
;
if
(
options
==
NULL
)
{
(
void
)
strlcpy
(
mntopts
,
MNTOPT_DEFAULTS
,
sizeof
(
mntopts
));
...
...
@@ -495,6 +525,7 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
dgettext
(
TEXT_DOMAIN
,
"cannot mount '%s'"
),
mountpoint
));
}
set_uchg
=
B_TRUE
;
}
/*
...
...
@@ -561,6 +592,16 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
/* add the mounted entry into our cache */
libzfs_mnttab_add
(
hdl
,
zfs_get_name
(
zhp
),
mountpoint
,
mntopts
);
if
(
set_uchg
)
{
if
(
zfs_mount_set_uchg
(
mountpoint
)
<
0
)
{
return
(
zfs_error_fmt
(
hdl
,
EZFS_MOUNTFAILED
,
dgettext
(
TEXT_DOMAIN
,
"cannot set immuteable"
"flag on auto generated mountpoint '%s' of "
"mount '%s'"
),
mountpoint
,
zhp
->
zfs_name
));
}
}
return
(
0
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help