Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda