1

I am writing a startup script for a daemon that runs inside an embedded Linux installation. That means that chmod is from BusyBox v1.24.2.

I don't want to cause any unnecessary write cycles on flash media.

That is why I am wondering whether issuing a chmod 03755 (with umask 022) on a directory will result in any disk write I/O.

In other words is it necessary to insert a check whether the directory permissions are already setup correct and only execute the chmod when the permissions are incorrect?

Or is a directory permissions check wasted effort because busybox chmod will not result in any disk write I/O when permissions don't need any change?

migrated from stackoverflow.com Dec 8 '16 at 12:19

This question came from our site for professional and enthusiast programmers.

0

You can find out by using "strace chmod 03755" on the respective file". You might have add strace to your busybox image.

  • When alternating chmod 03755 with 03750 I don' see any differences except from the memory addresses and the 03755/03750. strace command doesn't seem to signal disk I/O. – Pro Backup Dec 7 '16 at 17:51
  • You are already observing the disk io. A file permission is changed via the chmod syscall. The kernel will execute the syscall, changing the permissions in the respective inode of the file system. In the end it will be written out to the disk. – Frank Meerkötter Dec 7 '16 at 18:10
  • Sorry that I don't understand the output. Where in the strace results can I recognize that I/**O** output is written to disk? (One of my goals is to differentiate the reads (I) from the writes (O)) – Pro Backup Dec 7 '16 at 18:28
  • 1
    Ah, I had to re-read your original question. I am sorry, but strace won't help you here. – Frank Meerkötter Dec 7 '16 at 18:40
0

My less optimal solution for now is to print the number of writes before and after the command.

First I disable disk write cache:

# hdparm -W 0 /dev/sda

Then I try to exclude disk writes of other processes by repeating the kernel disk stat command a few times:

# cat /sys/block/sda/stat | awk '{ print $5 }';chmod 03755 /opt/etc/tinydns;cat /sys/block/sda/stat | awk '{ print $5 }'
1725
1725
# cat /sys/block/sda/stat | awk '{ print $5 }';chmod 03755 /opt/etc/tinydns;cat /sys/block/sda/stat | awk '{ print $5 }'
1725
1725
# cat /sys/block/sda/stat | awk '{ print $5 }';chmod 03755 /opt/etc/tinydns;cat /sys/block/sda/stat | awk '{ print $5 }'
1725
1725

I would guess that in this case the chmod doesn't issue any disk output/write activity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.