diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-08-17 07:15:54 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-08-17 07:15:54 +0000 |
commit | 4c5c26b1ef4be862fc2037dd5fcc120cb35bacca (patch) | |
tree | 7cd5959978923119145186e2a3838eb4ea3d3737 /source3/smbd/fileio.c | |
parent | 72ed7049d88e5296ebec362189e62a384385ad34 (diff) | |
download | samba-4c5c26b1ef4be862fc2037dd5fcc120cb35bacca.tar.gz samba-4c5c26b1ef4be862fc2037dd5fcc120cb35bacca.tar.bz2 samba-4c5c26b1ef4be862fc2037dd5fcc120cb35bacca.zip |
now that we have no global arrays we can start to split up the monster
server.c without breaking things.
this splits off netprot.c and fileio.c for negprot and read/write/seek
handling respectively.
(This used to be commit b3d7014643ec9f2eef6e6f598f5b9db1fe2f930d)
Diffstat (limited to 'source3/smbd/fileio.c')
-rw-r--r-- | source3/smbd/fileio.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c new file mode 100644 index 0000000000..edf87f3e7b --- /dev/null +++ b/source3/smbd/fileio.c @@ -0,0 +1,117 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + read/write to a files_struct + Copyright (C) Andrew Tridgell 1992-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + + +/**************************************************************************** +seek a file. Try to avoid the seek if possible +****************************************************************************/ +int seek_file(files_struct *fsp,uint32 pos) +{ + uint32 offset = 0; + + if (fsp->print_file && lp_postscript(fsp->conn->service)) + offset = 3; + + fsp->pos = (int)(lseek(fsp->fd_ptr->fd,pos+offset,SEEK_SET) - offset); + return(fsp->pos); +} + +/**************************************************************************** +read from a file +****************************************************************************/ +int read_file(files_struct *fsp,char *data,uint32 pos,int n) +{ + int ret=0,readret; + +#if USE_READ_PREDICTION + if (!fsp->can_write) + { + ret = read_predict(fsp->fd_ptr->fd,pos,data,NULL,n); + + data += ret; + n -= ret; + pos += ret; + } +#endif + +#if WITH_MMAP + if (fsp->mmap_ptr) + { + int num = (fsp->mmap_size > pos) ? (fsp->mmap_size - pos) : -1; + num = MIN(n,num); + if (num > 0) + { + memcpy(data,fsp->mmap_ptr+pos,num); + data += num; + pos += num; + n -= num; + ret += num; + } + } +#endif + + if (n <= 0) + return(ret); + + if (seek_file(fsp,pos) != pos) + { + DEBUG(3,("Failed to seek to %d\n",pos)); + return(ret); + } + + if (n > 0) { + readret = read(fsp->fd_ptr->fd,data,n); + if (readret > 0) ret += readret; + } + + return(ret); +} + + +/**************************************************************************** +write to a file +****************************************************************************/ +int write_file(files_struct *fsp,char *data,int n) +{ + + if (!fsp->can_write) { + errno = EPERM; + return(0); + } + + if (!fsp->modified) { + struct stat st; + fsp->modified = True; + if (fstat(fsp->fd_ptr->fd,&st) == 0) { + int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st); + if (MAP_ARCHIVE(fsp->conn) && !IS_DOS_ARCHIVE(dosmode)) { + dos_chmod(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st); + } + } + } + + return(write_data(fsp->fd_ptr->fd,data,n)); +} + |