patch-2.1.14 linux/fs/smbfs/file.c
Next file: linux/fs/smbfs/inode.c
Previous file: linux/fs/smbfs/dir.c
Back to the patch index
Back to the overall index
- Lines: 347
- Date:
Sun Dec 1 18:26:22 1996
- Orig file:
v2.1.13/linux/fs/smbfs/file.c
- Orig date:
Tue Oct 29 19:58:44 1996
diff -u --recursive --new-file v2.1.13/linux/fs/smbfs/file.c linux/fs/smbfs/file.c
@@ -1,13 +1,10 @@
/*
* file.c
*
- * Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
+ * Copyright (C) 1995, 1996 by Paal-Kr. Engstad and Volker Lendecke
*
*/
-#include <asm/uaccess.h>
-#include <asm/system.h>
-
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/errno.h>
@@ -17,12 +14,16 @@
#include <linux/smb_fs.h>
#include <linux/malloc.h>
-static inline int min(int a, int b)
+#include <asm/uaccess.h>
+#include <asm/system.h>
+
+static inline int
+min(int a, int b)
{
- return a<b ? a : b;
+ return a < b ? a : b;
}
-static int
+static int
smb_fsync(struct inode *inode, struct file *file)
{
return 0;
@@ -31,36 +32,37 @@
int
smb_make_open(struct inode *i, int right)
{
- struct smb_dirent *dirent;
-
- if (i == NULL) {
- printk("smb_make_open: got NULL inode\n");
- return -EINVAL;
- }
+ struct smb_dirent *dirent;
- dirent = &(SMB_INOP(i)->finfo);
+ if (i == NULL)
+ {
+ printk("smb_make_open: got NULL inode\n");
+ return -EINVAL;
+ }
+ dirent = &(SMB_INOP(i)->finfo);
- DDPRINTK("smb_make_open: dirent->opened = %d\n", dirent->opened);
+ DDPRINTK("smb_make_open: dirent->opened = %d\n", dirent->opened);
- if ((dirent->opened) == 0) {
- /* tries max. rights */
+ if ((dirent->opened) == 0)
+ {
+ /* tries max. rights */
int open_result = smb_proc_open(SMB_SERVER(i),
- dirent->path, dirent->len,
+ SMB_INOP(i)->dir,
+ dirent->name, dirent->len,
dirent);
- if (open_result)
+ if (open_result)
{
- return open_result;
+ return open_result;
}
- }
-
- if ( ((right == O_RDONLY) && ( (dirent->access == O_RDONLY)
- || (dirent->access == O_RDWR)))
- || ((right == O_WRONLY) && ( (dirent->access == O_WRONLY)
- || (dirent->access == O_RDWR)))
- || ((right == O_RDWR) && (dirent->access == O_RDWR)))
- return 0;
+ }
+ if (((right == O_RDONLY) && ((dirent->access == O_RDONLY)
+ || (dirent->access == O_RDWR)))
+ || ((right == O_WRONLY) && ((dirent->access == O_WRONLY)
+ || (dirent->access == O_RDWR)))
+ || ((right == O_RDWR) && (dirent->access == O_RDWR)))
+ return 0;
- return -EACCES;
+ return -EACCES;
}
static long
@@ -68,76 +70,67 @@
{
int result, bufsize, to_read, already_read;
off_t pos;
- int errno;
+ int errno;
+
+ DPRINTK("smb_file_read: enter %s\n", SMB_FINFO(inode)->name);
- DPRINTK("smb_file_read: enter %s\n", SMB_FINFO(inode)->path);
-
- if (!inode) {
+ if (!inode)
+ {
DPRINTK("smb_file_read: inode = NULL\n");
return -EINVAL;
}
-
- if (!S_ISREG(inode->i_mode)) {
+ if (!S_ISREG(inode->i_mode))
+ {
DPRINTK("smb_file_read: read from non-file, mode %07o\n",
- inode->i_mode);
+ inode->i_mode);
return -EINVAL;
}
+ if ((errno = smb_make_open(inode, O_RDONLY)) != 0)
+ return errno;
- if ((errno = smb_make_open(inode, O_RDONLY)) != 0)
- return errno;
-
pos = file->f_pos;
if (pos + count > inode->i_size)
+ {
count = inode->i_size - pos;
-
+ }
if (count <= 0)
+ {
return 0;
+ }
bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
- already_read = 0;
+ already_read = 0;
/* First read in as much as possible for each bufsize. */
- while (already_read < count) {
-
- result = 0;
- to_read = 0;
-
- if ((SMB_SERVER(inode)->blkmode & 1) != 0) {
- to_read = min(65535, count - already_read);
- DPRINTK("smb_file_read: Raw %d bytes\n", to_read);
- result = smb_proc_read_raw(SMB_SERVER(inode),
- SMB_FINFO(inode),
- pos, to_read, buf);
- DPRINTK("smb_file_read: returned %d\n", result);
- }
-
- if (result <= 0) {
- to_read = min(bufsize, count - already_read);
- result = smb_proc_read(SMB_SERVER(inode),
- SMB_FINFO(inode),
- pos, to_read, buf, 1);
- }
-
+ while (already_read < count)
+ {
+ to_read = min(bufsize, count - already_read);
+ result = smb_proc_read(SMB_SERVER(inode), SMB_FINFO(inode),
+ pos, to_read, buf, 1);
if (result < 0)
+ {
return result;
+ }
pos += result;
buf += result;
- already_read += result;
+ already_read += result;
- if (result < to_read) {
- break;
+ if (result < to_read)
+ {
+ break;
}
}
- file->f_pos = pos;
+ file->f_pos = pos;
- if (!IS_RDONLY(inode)) inode->i_atime = CURRENT_TIME;
+ if (!IS_RDONLY(inode))
+ inode->i_atime = CURRENT_TIME;
inode->i_dirt = 1;
- DPRINTK("smb_file_read: exit %s\n", SMB_FINFO(inode)->path);
+ DPRINTK("smb_file_read: exit %s\n", SMB_FINFO(inode)->name);
- return already_read;
+ return already_read;
}
static long
@@ -145,28 +138,30 @@
unsigned long count)
{
int result, bufsize, to_write, already_written;
- off_t pos;
- int errno;
-
- if (!inode) {
+ off_t pos;
+ int errno;
+
+ if (!inode)
+ {
DPRINTK("smb_file_write: inode = NULL\n");
return -EINVAL;
}
-
- if (!S_ISREG(inode->i_mode)) {
+ if (!S_ISREG(inode->i_mode))
+ {
DPRINTK("smb_file_write: write to non-file, mode %07o\n",
- inode->i_mode);
+ inode->i_mode);
return -EINVAL;
}
+ DPRINTK("smb_file_write: enter %s\n", SMB_FINFO(inode)->name);
- DPRINTK("smb_file_write: enter %s\n", SMB_FINFO(inode)->path);
-
- if (!count)
+ if (count <= 0)
+ {
return 0;
-
- if ((errno = smb_make_open(inode, O_RDWR)) != 0)
- return errno;
-
+ }
+ if ((errno = smb_make_open(inode, O_RDWR)) != 0)
+ {
+ return errno;
+ }
pos = file->f_pos;
if (file->f_flags & O_APPEND)
@@ -174,41 +169,28 @@
bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
- already_written = 0;
+ already_written = 0;
- DPRINTK("smb_write_file: blkmode = %d, blkmode & 2 = %d\n",
- SMB_SERVER(inode)->blkmode,
- SMB_SERVER(inode)->blkmode & 2);
-
- while (already_written < count) {
-
- result = 0;
- to_write = 0;
-
- if ((SMB_SERVER(inode)->blkmode & 2) != 0) {
- to_write = min(65535, count - already_written);
- DPRINTK("smb_file_write: Raw %d bytes\n", to_write);
- result = smb_proc_write_raw(SMB_SERVER(inode),
- SMB_FINFO(inode),
- pos, to_write, buf);
- DPRINTK("smb_file_write: returned %d\n", result);
- }
-
- if (result <= 0) {
- to_write = min(bufsize, count - already_written);
- result = smb_proc_write(SMB_SERVER(inode),
- SMB_FINFO(inode),
- pos, to_write, buf);
- }
+ DPRINTK("smb_write_file: blkmode = %d, blkmode & 2 = %d\n",
+ SMB_SERVER(inode)->blkmode,
+ SMB_SERVER(inode)->blkmode & 2);
+
+ while (already_written < count)
+ {
+ to_write = min(bufsize, count - already_written);
+ result = smb_proc_write(SMB_SERVER(inode), SMB_FINFO(inode),
+ pos, to_write, buf);
if (result < 0)
+ {
return result;
-
+ }
pos += result;
buf += result;
- already_written += result;
+ already_written += result;
- if (result < to_write) {
+ if (result < to_write)
+ {
break;
}
}
@@ -218,29 +200,31 @@
file->f_pos = pos;
- if (pos > inode->i_size) {
- inode->i_size = pos;
- }
-
- DPRINTK("smb_file_write: exit %s\n", SMB_FINFO(inode)->path);
+ if (pos > inode->i_size)
+ {
+ inode->i_size = pos;
+ }
+ DPRINTK("smb_file_write: exit %s\n", SMB_FINFO(inode)->name);
return already_written;
}
-static struct file_operations smb_file_operations = {
+static struct file_operations smb_file_operations =
+{
NULL, /* lseek - default */
smb_file_read, /* read */
smb_file_write, /* write */
NULL, /* readdir - bad */
NULL, /* select - default */
smb_ioctl, /* ioctl */
- smb_mmap, /* mmap */
- NULL, /* open */
- NULL, /* release */
+ smb_mmap, /* mmap */
+ NULL, /* open */
+ NULL, /* release */
smb_fsync, /* fsync */
};
-struct inode_operations smb_file_inode_operations = {
+struct inode_operations smb_file_inode_operations =
+{
&smb_file_operations, /* default file operations */
NULL, /* create */
NULL, /* lookup */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov