Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
How can we mount a file as read-only in Linux through Go?

I want to know how can we mount an file as read-only in Linux CentOS 7 Server through Golang. I have tried syscall but that doesn't work, syscall mounts the file but as read-write i have tried to give ro argument in the data but still it's mounting as read-write. Here is my go code:

syscall.Mount(src, dst, "auto", syscall.MS_BIND, "ro")

You can see I have given ro argument in the data, i have also tried to give only r and readonly and also read-only but none of them works, when i compile the go file and execute it and then when i check /etc/mtab then i am getting this output :

cat /etc/mtab | grep "firewall"
/dev/vda1 /root/firewall.txt ext4 rw,relatime,data=ordered,jqfmt=vfsv1,usrjquota=quota.user 0 0

Here you can see that firewall.txt is mounted as rw means read-write

I want to mount it as read-only , can anyone help me how can i do that in Golang?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I have faced similar issue, It was fixed by setting fstype as bind and flags as MS_REMOUNT MS_RDONLY and MS_BIND . You can use these codes:

syscall.Mount(source, destination, "bind", syscall.MS_REMOUNT|syscall.MS_RDONLY|syscall.MS_BIND, "")
over 4 years ago · Santiago Trujillo Report

0

Read-only mode is defined by the syscall flag MS_RDONLY, which is also defined in the syscall package. So the call should be:

syscall.Mount(src, dst, "auto", syscall.MS_BIND | syscall.MS_RDONLY, "")
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!