When I try to rename a file from a cifs mount to a local path (moving the file from server to local hdd), I get a -1. I can remove the file, and I can add new files, I just can't use the rename() function to do it. The program is being ran as root and the user in the cifs mount has full rights to the share and to the local filesystem on the server.
Server: Windows XP SP3 x32
Local: Ubuntu 13.04 x64
smb mount:
sudo mount -t cifs -o username=admin_account,password=<passw> \
//server/share /local/mount/point
C code:
void
function moveFile(char *fname){
char *base;
base = basename(fname);
char newF[strlen(getSaveDir()) + strlen(base)];
sprintf(newF,"%s%s", getSaveDir(), base);
int result;
result = rename(fname, newF);
if( result == 0 ) {
printf("Moved file: %s to %s", fname, newF);
} else {
printf("There was an error moving %s to %s (ID: %d)", fname, newF, result);
//TODO figure out better fix than this
remove(fname);
}
}
rename() only works on the same device, it just changes its name(or "moves" the name to another directory). rename() cannot move the file data from one location to another.
If you want to copy or move the file, you need to do it yourself: