Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
steam-runtime-tools
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steamrt
steam-runtime-tools
Commits
0cf0955a
Commit
0cf0955a
authored
5 years ago
by
Colin Walters
Browse files
Options
Downloads
Patches
Plain Diff
fdio: Add glnx_tmpfile_reopen_rdonly()
For fs-verity.
parent
41ecc544
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
glnx-fdio.c
+40
-2
40 additions, 2 deletions
glnx-fdio.c
glnx-fdio.h
+4
-0
4 additions, 0 deletions
glnx-fdio.h
with
44 additions
and
2 deletions
glnx-fdio.c
+
40
−
2
View file @
0cf0955a
...
...
@@ -363,8 +363,7 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
{
/* This case we have O_TMPFILE, so our reference to it is via /proc/self/fd */
char
proc_fd_path
[
strlen
(
"/proc/self/fd/"
)
+
DECIMAL_STR_MAX
(
tmpf
->
fd
)
+
1
];
sprintf
(
proc_fd_path
,
"/proc/self/fd/%i"
,
tmpf
->
fd
);
snprintf
(
proc_fd_path
,
sizeof
(
proc_fd_path
),
"/proc/self/fd/%i"
,
tmpf
->
fd
);
if
(
replace
)
{
...
...
@@ -424,6 +423,45 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
return
TRUE
;
}
/* glnx_tmpfile_reopen_rdonly:
* @tmpf: tmpfile
* @error: Error
*
* Give up write access to the file descriptior. One use
* case for this is fs-verity, which requires a read-only fd.
* It could also be useful to allocate an anonymous tmpfile
* write some sort of caching/indexing data to it, then reopen it
* read-only thereafter.
**/
gboolean
glnx_tmpfile_reopen_rdonly
(
GLnxTmpfile
*
tmpf
,
GError
**
error
)
{
g_return_val_if_fail
(
tmpf
->
fd
>=
0
,
FALSE
);
g_return_val_if_fail
(
tmpf
->
src_dfd
==
AT_FDCWD
||
tmpf
->
src_dfd
>=
0
,
FALSE
);
glnx_fd_close
int
rdonly_fd
=
-
1
;
if
(
tmpf
->
path
)
{
if
(
!
glnx_openat_rdonly
(
tmpf
->
src_dfd
,
tmpf
->
path
,
FALSE
,
&
rdonly_fd
,
error
))
return
FALSE
;
}
else
{
/* This case we have O_TMPFILE, so our reference to it is via /proc/self/fd */
char
proc_fd_path
[
strlen
(
"/proc/self/fd/"
)
+
DECIMAL_STR_MAX
(
tmpf
->
fd
)
+
1
];
snprintf
(
proc_fd_path
,
sizeof
(
proc_fd_path
),
"/proc/self/fd/%i"
,
tmpf
->
fd
);
if
(
!
glnx_openat_rdonly
(
AT_FDCWD
,
proc_fd_path
,
TRUE
,
&
rdonly_fd
,
error
))
return
FALSE
;
}
glnx_close_fd
(
&
tmpf
->
fd
);
tmpf
->
fd
=
glnx_steal_fd
(
&
rdonly_fd
);
return
TRUE
;
}
/**
* glnx_openat_rdonly:
* @dfd: File descriptor for origin directory
...
...
This diff is collapsed.
Click to expand it.
glnx-fdio.h
+
4
−
0
View file @
0cf0955a
...
...
@@ -110,6 +110,10 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
const
char
*
target
,
GError
**
error
);
gboolean
glnx_tmpfile_reopen_rdonly
(
GLnxTmpfile
*
tmpf
,
GError
**
error
);
gboolean
glnx_openat_rdonly
(
int
dfd
,
const
char
*
path
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment