2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
19 #include "h/smp_lock.h"
22 int afs_osicred_initialized = 0;
23 struct AFS_UCRED afs_osi_cred;
24 afs_lock_t afs_xosi; /* lock is for tvattr */
25 extern struct osi_dev cacheDev;
26 extern struct super_block *afs_cacheSBp;
29 osi_UFSOpen(afs_int32 ainode)
32 register struct osi_file *afile = NULL;
33 extern int cacheDiskType;
36 struct inode *tip = NULL;
37 struct file *filp = NULL;
38 AFS_STATCNT(osi_UFSOpen);
39 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
40 osi_Panic("UFSOpen called for non-UFS cache\n");
42 if (!afs_osicred_initialized) {
43 /* valid for alpha_osf, SunOS, Ultrix */
44 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
45 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
46 afs_osicred_initialized = 1;
48 afile = (struct osi_file *)osi_AllocLargeSpace(sizeof(struct osi_file));
51 osi_Panic("osi_UFSOpen: Failed to allocate %d bytes for osi_file.\n",
52 sizeof(struct osi_file));
54 memset(afile, 0, sizeof(struct osi_file));
56 filp->f_dentry = &afile->dentry;
57 tip = iget(afs_cacheSBp, (u_long) ainode);
59 osi_Panic("Can't get inode %d\n", ainode);
60 FILE_INODE(filp) = tip;
61 tip->i_flags |= MS_NOATIME; /* Disable updating access times. */
62 filp->f_flags = O_RDWR;
63 #if defined(AFS_LINUX24_ENV)
64 filp->f_op = fops_get(tip->i_fop);
66 filp->f_op = tip->i_op->default_file_ops;
68 if (filp->f_op && filp->f_op->open)
69 code = filp->f_op->open(tip, filp);
71 osi_Panic("Can't open inode %d\n", ainode);
72 afile->size = tip->i_size;
75 afile->proc = (int (*)())0;
76 afile->inum = ainode; /* for hint validity checking */
81 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
83 register afs_int32 code;
84 AFS_STATCNT(osi_Stat);
85 MObtainWriteLock(&afs_xosi, 320);
86 astat->size = FILE_INODE(&afile->file)->i_size;
87 astat->blksize = FILE_INODE(&afile->file)->i_blksize;
88 astat->mtime = FILE_INODE(&afile->file)->i_mtime;
89 astat->atime = FILE_INODE(&afile->file)->i_atime;
91 MReleaseWriteLock(&afs_xosi);
96 osi_UFSClose(register struct osi_file *afile)
98 AFS_STATCNT(osi_Close);
100 if (FILE_INODE(&afile->file)) {
101 struct file *filp = &afile->file;
102 if (filp->f_op && filp->f_op->release)
103 filp->f_op->release(FILE_INODE(filp), filp);
104 iput(FILE_INODE(filp));
108 osi_FreeLargeSpace(afile);
113 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
115 struct AFS_UCRED *oldCred;
116 register afs_int32 code;
117 struct osi_stat tstat;
118 struct iattr newattrs;
119 struct inode *inode = FILE_INODE(&afile->file);
120 AFS_STATCNT(osi_Truncate);
122 /* This routine only shrinks files, and most systems
123 * have very slow truncates, even when the file is already
124 * small enough. Check now and save some time.
126 code = afs_osi_Stat(afile, &tstat);
127 if (code || tstat.size <= asize)
129 MObtainWriteLock(&afs_xosi, 321);
131 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
132 down_write(&inode->i_alloc_sem);
135 inode->i_size = newattrs.ia_size = asize;
136 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
137 #if defined(AFS_LINUX24_ENV)
138 newattrs.ia_ctime = CURRENT_TIME;
140 /* avoid notify_change() since it wants to update dentry->d_parent */
142 code = inode_change_ok(inode, &newattrs);
144 #ifdef INODE_SETATTR_NOT_VOID
145 code = inode_setattr(inode, &newattrs);
147 inode_setattr(inode, &newattrs);
151 truncate_inode_pages(&inode->i_data, asize);
153 if (inode->i_sb->s_op && inode->i_sb->s_op->notify_change) {
154 code = inode->i_sb->s_op->notify_change(&afile->dentry, &newattrs);
157 truncate_inode_pages(inode, asize);
158 if (inode->i_op && inode->i_op->truncate)
159 inode->i_op->truncate(inode);
164 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
165 up_write(&inode->i_alloc_sem);
168 MReleaseWriteLock(&afs_xosi);
173 /* Generic read interface */
175 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
178 struct AFS_UCRED *oldCred;
180 register afs_int32 code;
181 register afs_int32 cnt1 = 0;
182 AFS_STATCNT(osi_Read);
185 * If the osi_file passed in is NULL, panic only if AFS is not shutting
186 * down. No point in crashing when we are already shutting down
189 if (!afs_shuttingdown)
190 osi_Panic("osi_Read called with null param");
196 afile->offset = offset;
198 code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid);
201 code = asize - resid;
202 afile->offset += code;
204 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
205 ICL_TYPE_INT32, code);
211 /* Generic write interface */
213 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
216 struct AFS_UCRED *oldCred;
218 register afs_int32 code;
219 AFS_STATCNT(osi_Write);
221 if (!afs_shuttingdown)
222 osi_Panic("afs_osi_Write called with null param");
227 afile->offset = offset;
229 code = osi_rdwr(UIO_WRITE, afile, (caddr_t) aptr, asize, &resid);
232 code = asize - resid;
233 afile->offset += code;
237 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
241 (*afile->proc) (afile, code);
247 /* This work should be handled by physstrat in ca/machdep.c.
248 This routine written from the RT NFS port strategy routine.
249 It has been generalized a bit, but should still be pretty clear. */
251 afs_osi_MapStrategy(int (*aproc) (struct buf * bp), register struct buf *bp)
253 afs_int32 returnCode;
255 AFS_STATCNT(osi_MapStrategy);
256 returnCode = (*aproc) (bp);
262 shutdown_osifile(void)
264 extern int afs_cold_shutdown;
266 AFS_STATCNT(shutdown_osifile);
267 if (afs_cold_shutdown) {
268 afs_osicred_initialized = 0;