Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With reference to:

We have a Seagate BlackArmor NAS device, which is mounted on our Ubuntu 10.04 server as follows:

mount -t cifs -o defaults,credentials=/etc/smbpass/demo.smbpass,uid=1005,gid=1005,dir_mode=0770,file_mod=0660 // /var/www/mysite/src/files/

It seems that any operation that is supposed to truncate files and then insert content into those files on the NAS ends up only replacing the first few bytes of the file (up until the length of the new contents), and then the rest of the previous "old" content is still in the file.

For Example:

Contents of myfile.txt: thisisabigfatpandaonwheelsgoingdownthestreet

Run PHP script with code: file_put_contents('myfile.txt', 'blah');

Contents of myfile.txt: blahisabigfatpandaonwheelsgoingdownthestreet

The expected contents of the file is obviously blah, but that's not the case.

Using PHP's fwrite() after creating a file handle with fopen('filename', 'w'); has the same effect. ftruncate() also does not work properly. Using a shell command such as echo -n "blah" > myfile.txt has the same effect (that's how I know it's not a PHP-specific problem).

My only work-around currently is to delete the files and then create them from scratch, but I'd prefer not to change any code in my application, if possible (we only started using the NAS device recently). I'd rather apply a solution to what seems to be an OS-related/mount-related problem.

Any ideas?

share|improve this question

I had the exact same symptoms on a samba setup of my own (Debian 6 x64 with samba 3.5.6.). I finally narrowed it down to the following option causing the exact same behaviour:

large readwrite = no

When set to yes instead (or removed, as yes is the default setting), the issues were gone.

Filed bug reports against Debain and upstream Samba:

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .