1/* 2 * smb_fs.h 3 * 4 * Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke 5 * Copyright (C) 1997 by Volker Lendecke 6 * 7 */ 8 9#ifndef _LINUX_SMB_FS_H 10#define _LINUX_SMB_FS_H 11 12#include <linux/smb.h> 13 14/* 15 * ioctl commands 16 */ 17#define SMB_IOC_GETMOUNTUID _IOR('u', 1, __kernel_old_uid_t) 18#define SMB_IOC_NEWCONN _IOW('u', 2, struct smb_conn_opt) 19 20/* __kernel_uid_t can never change, so we have to use __kernel_uid32_t */ 21#define SMB_IOC_GETMOUNTUID32 _IOR('u', 3, __kernel_uid32_t) 22 23 24#ifdef __KERNEL__ 25 26#include <linux/pagemap.h> 27#include <linux/vmalloc.h> 28#include <linux/smb_mount.h> 29#include <asm/unaligned.h> 30 31 32/* macro names are short for word, double-word, long value (?) */ 33#define WVAL(buf,pos) \ 34 (le16_to_cpu(get_unaligned((u16 *)((u8 *)(buf) + (pos))))) 35#define DVAL(buf,pos) \ 36 (le32_to_cpu(get_unaligned((u32 *)((u8 *)(buf) + (pos))))) 37#define LVAL(buf,pos) \ 38 (le64_to_cpu(get_unaligned((u64 *)((u8 *)(buf) + (pos))))) 39#define WSET(buf,pos,val) \ 40 put_unaligned(cpu_to_le16((u16)(val)), (u16 *)((u8 *)(buf) + (pos))) 41#define DSET(buf,pos,val) \ 42 put_unaligned(cpu_to_le32((u32)(val)), (u32 *)((u8 *)(buf) + (pos))) 43#define LSET(buf,pos,val) \ 44 put_unaligned(cpu_to_le64((u64)(val)), (u64 *)((u8 *)(buf) + (pos))) 45 46/* where to find the base of the SMB packet proper */ 47#define smb_base(buf) ((u8 *)(((u8 *)(buf))+4)) 48 49#ifdef DEBUG_SMB_MALLOC 50 51#include <linux/slab.h> 52 53extern int smb_malloced; 54extern int smb_current_vmalloced; 55extern int smb_current_kmalloced; 56 57static inline void * 58smb_vmalloc(unsigned int size) 59{ 60 smb_malloced += 1; 61 smb_current_vmalloced += 1; 62 return vmalloc(size); 63} 64 65static inline void 66smb_vfree(void *obj) 67{ 68 smb_current_vmalloced -= 1; 69 vfree(obj); 70} 71 72static inline void * 73smb_kmalloc(size_t size, int flags) 74{ 75 smb_malloced += 1; 76 smb_current_kmalloced += 1; 77 return kmalloc(size, flags); 78} 79 80static inline void 81smb_kfree(void *obj) 82{ 83 smb_current_kmalloced -= 1; 84 kfree(obj); 85} 86 87#else /* DEBUG_SMB_MALLOC */ 88 89#define smb_kmalloc(s,p) kmalloc(s,p) 90#define smb_kfree(o) kfree(o) 91#define smb_vmalloc(s) vmalloc(s) 92#define smb_vfree(o) vfree(o) 93 94#endif /* DEBUG_SMB_MALLOC */ 95 96/* 97 * Flags for the in-memory inode 98 */ 99#define SMB_F_LOCALWRITE 0x02 /* file modified locally */ 100 101 102/* NT1 protocol capability bits */ 103#define SMB_CAP_RAW_MODE 0x0001 104#define SMB_CAP_MPX_MODE 0x0002 105#define SMB_CAP_UNICODE 0x0004 106#define SMB_CAP_LARGE_FILES 0x0008 107#define SMB_CAP_NT_SMBS 0x0010 108#define SMB_CAP_RPC_REMOTE_APIS 0x0020 109#define SMB_CAP_STATUS32 0x0040 110#define SMB_CAP_LEVEL_II_OPLOCKS 0x0080 111#define SMB_CAP_LOCK_AND_READ 0x0100 112#define SMB_CAP_NT_FIND 0x0200 113#define SMB_CAP_DFS 0x1000 114#define SMB_CAP_LARGE_READX 0x4000 115 116 117/* 118 * This is the time we allow an inode, dentry or dir cache to live. It is bad 119 * for performance to have shorter ttl on an inode than on the cache. It can 120 * cause refresh on each inode for a dir listing ... one-by-one 121 */ 122#define SMB_MAX_AGE(server) (((server)->mnt->ttl * HZ) / 1000) 123 124static inline void 125smb_age_dentry(struct smb_sb_info *server, struct dentry *dentry) 126{ 127 dentry->d_time = jiffies - SMB_MAX_AGE(server); 128} 129 130struct smb_cache_head { 131 time_t mtime; /* unused */ 132 unsigned long time; /* cache age */ 133 unsigned long end; /* last valid fpos in cache */ 134 int eof; 135}; 136 137#define SMB_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *))) 138union smb_dir_cache { 139 struct smb_cache_head head; 140 struct dentry *dentry[SMB_DIRCACHE_SIZE]; 141}; 142 143#define SMB_FIRSTCACHE_SIZE ((int)((SMB_DIRCACHE_SIZE * \ 144 sizeof(struct dentry *) - sizeof(struct smb_cache_head)) / \ 145 sizeof(struct dentry *))) 146 147#define SMB_DIRCACHE_START (SMB_DIRCACHE_SIZE - SMB_FIRSTCACHE_SIZE) 148 149struct smb_cache_control { 150 struct smb_cache_head head; 151 struct page *page; 152 union smb_dir_cache *cache; 153 unsigned long fpos, ofs; 154 int filled, valid, idx; 155}; 156 157static inline int 158smb_is_open(struct inode *i) 159{ 160 return (i->u.smbfs_i.open == server_from_inode(i)->generation); 161} 162 163 164#endif /* __KERNEL__ */ 165 166#endif /* _LINUX_SMB_FS_H */ 167