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
1288bd85
Commit
1288bd85
authored
10 years ago
by
Colin Walters
Browse files
Options
Downloads
Patches
Plain Diff
xattrs: Migrate some code from ostree here
This also uses GBytes and avoids malloc where possible.
parent
1ebfefa5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
glnx-xattrs.c
+129
-0
129 additions, 0 deletions
glnx-xattrs.c
glnx-xattrs.h
+20
-0
20 additions, 0 deletions
glnx-xattrs.h
with
149 additions
and
0 deletions
glnx-xattrs.c
+
129
−
0
View file @
1288bd85
...
...
@@ -395,3 +395,132 @@ glnx_fd_set_all_xattrs (int fd,
out:
return
ret
;
}
/**
* glnx_lgetxattrat:
* @dfd: Directory file descriptor
* @subpath: Subpath
* @attribute: Extended attribute to retrieve
* @error: Error
*
* Retrieve an extended attribute value, relative to a directory file
* descriptor.
*/
GBytes
*
glnx_lgetxattrat
(
int
dfd
,
const
char
*
subpath
,
const
char
*
attribute
,
GError
**
error
)
{
char
pathbuf
[
PATH_MAX
];
GBytes
*
bytes
=
NULL
;
ssize_t
bytes_read
,
real_size
;
guint8
*
buf
;
snprintf
(
pathbuf
,
sizeof
(
pathbuf
),
"/proc/self/fd/%d/%s"
,
dfd
,
subpath
);
do
bytes_read
=
lgetxattr
(
pathbuf
,
attribute
,
NULL
,
0
);
while
(
G_UNLIKELY
(
bytes_read
<
0
&&
errno
==
EINTR
));
if
(
G_UNLIKELY
(
bytes_read
<
0
))
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
buf
=
g_malloc
(
bytes_read
);
do
real_size
=
lgetxattr
(
pathbuf
,
attribute
,
buf
,
bytes_read
);
while
(
G_UNLIKELY
(
real_size
<
0
&&
errno
==
EINTR
));
if
(
G_UNLIKELY
(
real_size
<
0
))
{
glnx_set_error_from_errno
(
error
);
g_free
(
buf
);
goto
out
;
}
bytes
=
g_bytes_new_take
(
buf
,
real_size
);
out:
return
bytes
;
}
/**
* glnx_fgetxattr_bytes:
* @fd: Directory file descriptor
* @attribute: Extended attribute to retrieve
* @error: Error
*
* Returns: (transfer full): An extended attribute value, or %NULL on error
*/
GBytes
*
glnx_fgetxattr_bytes
(
int
fd
,
const
char
*
attribute
,
GError
**
error
)
{
GBytes
*
bytes
=
NULL
;
ssize_t
bytes_read
,
real_size
;
guint8
*
buf
;
do
bytes_read
=
fgetxattr
(
fd
,
attribute
,
NULL
,
0
);
while
(
G_UNLIKELY
(
bytes_read
<
0
&&
errno
==
EINTR
));
if
(
G_UNLIKELY
(
bytes_read
<
0
))
{
glnx_set_error_from_errno
(
error
);
goto
out
;
}
buf
=
g_malloc
(
bytes_read
);
do
real_size
=
fgetxattr
(
fd
,
attribute
,
buf
,
bytes_read
);
while
(
G_UNLIKELY
(
real_size
<
0
&&
errno
==
EINTR
));
if
(
G_UNLIKELY
(
real_size
<
0
))
{
glnx_set_error_from_errno
(
error
);
g_free
(
buf
);
goto
out
;
}
bytes
=
g_bytes_new_take
(
buf
,
real_size
);
out:
return
bytes
;
}
/**
* glnx_lsetxattrat:
* @dfd: Directory file descriptor
* @subpath: Path
* @attribute: An attribute name
* @value: (array length=len) (element-type guint8): Attribute value
* @len: Length of @value
* @flags: Flags, containing either XATTR_CREATE or XATTR_REPLACE
* @error: Error
*
* Set an extended attribute, relative to a directory file descriptor.
*/
gboolean
glnx_lsetxattrat
(
int
dfd
,
const
char
*
subpath
,
const
char
*
attribute
,
const
guint8
*
value
,
gsize
len
,
int
flags
,
GError
**
error
)
{
char
pathbuf
[
PATH_MAX
];
int
res
;
snprintf
(
pathbuf
,
sizeof
(
pathbuf
),
"/proc/self/fd/%d/%s"
,
dfd
,
subpath
);
do
res
=
lsetxattr
(
subpath
,
attribute
,
value
,
len
,
flags
);
while
(
G_UNLIKELY
(
res
==
-
1
&&
errno
==
EINTR
));
if
(
G_UNLIKELY
(
res
==
-
1
))
{
glnx_set_error_from_errno
(
error
);
return
FALSE
;
}
return
TRUE
;
}
This diff is collapsed.
Click to expand it.
glnx-xattrs.h
+
20
−
0
View file @
1288bd85
...
...
@@ -55,4 +55,24 @@ glnx_fd_set_all_xattrs (int fd,
GCancellable
*
cancellable
,
GError
**
error
);
GBytes
*
glnx_lgetxattrat
(
int
dfd
,
const
char
*
subpath
,
const
char
*
attribute
,
GError
**
error
);
GBytes
*
glnx_fgetxattr_bytes
(
int
fd
,
const
char
*
attribute
,
GError
**
error
);
gboolean
glnx_lsetxattrat
(
int
dfd
,
const
char
*
subpath
,
const
char
*
attribute
,
const
guint8
*
value
,
gsize
len
,
int
flags
,
GError
**
error
);
G_END_DECLS
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