kernels/linux-2.4.0/fs/smbfs/proc.c
/*
 * We're called with the server locked, and we leave it that way.
 */
We're called with the server locked, and we leave it that way.
We ' re called with the server locked and we leave it that way .
static int
smb_proc_open(struct smb_sb_info *server, struct dentry *dentry, int wish)
{
	struct inode *ino = dentry->d_inode;
	int mode, read_write = 0x42, read_only = 0x40;
	int res;
	char *p;
	mode = read_write;
	if (!(ino->i_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
		mode = read_only;
#if 0
	if (!(wish & (O_WRONLY | O_RDWR)))
		mode = read_only;
#endif
      retry:
	p = smb_setup_header(server, SMBopen, 2, 0);
	WSET(server->packet, smb_vwv0, mode);
	WSET(server->packet, smb_vwv1, aSYSTEM | aHIDDEN | aDIR);
	*p++ = 4;
	res = smb_encode_path(server, p, dentry, NULL);
	if (res < 0)
		goto out;
	p += res;
	smb_setup_bcc(server, p);
	res = smb_request_ok(server, SMBopen, 7, 0);
	if (res != 0) {
		if (smb_retry(server))
			goto retry;
		if (mode == read_write &&
		    (res == -EACCES || res == -ETXTBSY || res == -EROFS))
		{
			VERBOSE("%s/%s R/W failed, error=%d, retrying R/O\n",
				DENTRY_PATH(dentry), res);
			mode = read_only;
			goto retry;
		}
		goto out;
	}
	ino->u.smbfs_i.fileid = WVAL(server->packet, smb_vwv0);
	ino->u.smbfs_i.attr   = WVAL(server->packet, smb_vwv1);
	ino->u.smbfs_i.access = (WVAL(server->packet, smb_vwv6) & SMB_ACCMASK);
	if (!(wish & (O_WRONLY | O_RDWR)))
		ino->u.smbfs_i.access = SMB_O_RDONLY;
	ino->u.smbfs_i.open = server->generation;
out:
	return res;
}
static int smb_proc_open ( struct smb_sb_info * server , struct dentry * dentry , int wish ) { struct inode * ino = dentry -> d_inode ; int mode , read_write = 0x42 , read_only = 0x40 ; int res ; char * p ; mode = read_write ; if ( ! ( ino -> i_mode & ( S_IWUSR | S_IWGRP | S_IWOTH ) ) ) mode = read_only ; #if 0 if ( ! ( wish & ( O_WRONLY | O_RDWR ) ) ) mode = read_only ; #endif retry : p = smb_setup_header ( server , SMBopen , 2 , 0 ) ; WSET ( server -> packet , smb_vwv0 , mode ) ; WSET ( server -> packet , smb_vwv1 , aSYSTEM | aHIDDEN | aDIR ) ; * p ++ = 4 ; res = smb_encode_path ( server , p , dentry , NULL ) ; if ( res < 0 ) goto out ; p += res ; smb_setup_bcc ( server , p ) ; res = smb_request_ok ( server , SMBopen , 7 , 0 ) ; if ( res != 0 ) { if ( smb_retry ( server ) ) goto retry ; if ( mode == read_write && ( res == - EACCES || res == - ETXTBSY || res == - EROFS ) ) { VERBOSE ( " \n " , DENTRY_PATH ( dentry ) , res ) ; mode = read_only ; goto retry ; } goto out ; } ino -> u . smbfs_i . fileid = WVAL ( server -> packet , smb_vwv0 ) ; ino -> u . smbfs_i . attr = WVAL ( server -> packet , smb_vwv1 ) ; ino -> u . smbfs_i . access = ( WVAL ( server -> packet , smb_vwv6 ) & SMB_ACCMASK ) ; if ( ! ( wish & ( O_WRONLY | O_RDWR ) ) ) ino -> u . smbfs_i . access = SMB_O_RDONLY ; ino -> u . smbfs_i . open = server -> generation ; out : return res ; }
We're called with the server locked, and we leave it that way.
We ' re called with the server locked and we leave it that way .
/*
	 * Attempt to open r/w, unless there are no write privileges.
	 */ /* FIXME: why is this code not in? below we fix it so that a caller
	   wanting RO doesn't get RW. smb_revalidate_inode does some 
	   optimization based on access mode. tail -f needs it to be correct. */ /* We should now have data in vwv[0..6]. */ /* smb_vwv2 has mtime */ /* smb_vwv4 has size  */