Skip to content

Fix mountinfo parsing #153#154

Merged
muesli merged 9 commits into
muesli:masterfrom
IGLOU-EU:adrien/fix153
Feb 7, 2022
Merged

Fix mountinfo parsing #153#154
muesli merged 9 commits into
muesli:masterfrom
IGLOU-EU:adrien/fix153

Conversation

@IGLOU-EU

@IGLOU-EU IGLOU-EU commented Jan 9, 2022

Copy link
Copy Markdown
Contributor

Quick patch to fix
#153 mount -t tmpfs - /tmp -> "found invalid line"

Split directly with strings.Fields instead of "(8) separator: marks the end of the optional fields"

Todo:

Signed-off-by: Adrien Kara adrien@iglou.eu

@muesli

muesli commented Jan 9, 2022

Copy link
Copy Markdown
Owner

We should probably add a test for various valid and/or problematic entries.

@IGLOU-EU

IGLOU-EU commented Jan 9, 2022

Copy link
Copy Markdown
Contributor Author

Do you have any test cases in mind ?

By reading the source code of glib:

I tested the encoded part

$ sudo mount -t tmpfs a-b /mnt/a\ b
$ cat /proc/self/mountinfo
...
94 27 0:38 / /mnt/a\040b rw,relatime shared:263 - tmpfs a-b rw,inode64

There was no need to go so far ... https://man7.org/linux/man-pages/man5/fstab.5.html

The second field (fs_file) => If the name of the mount point contains spaces or tabs these can be escaped as `\040' and '\011' respectively.

EDIT:
Because of the apparent "complexity", I think a dedicated function is needed. Don't you?
If it is good for you, I will add a mounts_linux_internal_test.go file

scr_100122_152913

@muesli ?

@muesli

muesli commented Feb 1, 2022

Copy link
Copy Markdown
Owner

Do you have any test cases in mind ?

The second field (fs_file) => If the name of the mount point contains spaces or tabs these can be escaped as `\040' and '\011' respectively.

That should we test for as well.

EDIT: Because of the apparent "complexity", I think a dedicated function is needed. Don't you? If it is good for you, I will add a mounts_linux_internal_test.go file

I agree.

Nice work so far, will give this a proper review asap.

@IGLOU-EU IGLOU-EU changed the title [WIP] Fix mountinfo parsing #153 Fix mountinfo parsing #153 Feb 6, 2022
@IGLOU-EU

IGLOU-EU commented Feb 6, 2022

Copy link
Copy Markdown
Contributor Author

@muesli , can you review ? 🙂

scr_060222_044535

IGLOU-EU and others added 9 commits February 6, 2022 09:09
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Added a getFields function to parse fields as defined in
    "proc(5)" section "/proc/[pid]/mountinfo".
It is possible to use forbidden characters in the mountinfo file, for this
    Linux kernel encodes them
    https://github.com/torvalds/linux/blob/master/fs/proc_namespace.c#L87.
Skip empty or commented lines.

Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
Signed-off-by: Adrien Kara <adrien@iglou.eu>
@muesli

muesli commented Feb 7, 2022

Copy link
Copy Markdown
Owner

Ok, I've simplified the mountinfo parsing a bit. Everything seems to be working and testing fine, but maybe you wanna give it one more review as well. unescapeFstab seems to decode the strings just fine, so I've removed the newly added decodeName function again.

@muesli muesli added the bug Something isn't working label Feb 7, 2022
@IGLOU-EU

IGLOU-EU commented Feb 7, 2022

Copy link
Copy Markdown
Contributor Author

Cool, I hadn't seen it.
I'm not sure if it's a good idea to not respect the official mountinfo index, like defined by proc man pages.

Otherwise, it's good to me

@muesli muesli merged commit e98632a into muesli:master Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants