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"
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
16 #include "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h" /* afs statistics */
18 #include "../h/smp_lock.h"
21 int afs_osicred_initialized=0;
22 struct AFS_UCRED afs_osi_cred;
23 afs_lock_t afs_xosi; /* lock is for tvattr */
24 extern struct osi_dev cacheDev;
25 extern struct super_block *afs_cacheSBp;
27 void *osi_UFSOpen(ainode)
31 register struct osi_file *afile = NULL;
32 extern int cacheDiskType;
35 struct inode *tip = NULL;
36 struct file *filp = NULL;
37 AFS_STATCNT(osi_UFSOpen);
38 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
39 osi_Panic("UFSOpen called for non-UFS cache\n");
41 if (!afs_osicred_initialized) {
42 /* valid for alpha_osf, SunOS, Ultrix */
43 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
44 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
45 afs_osicred_initialized = 1;
47 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
50 osi_Panic("osi_UFSOpen: Failed to allocate %d bytes for osi_file.\n",
51 sizeof(struct osi_file));
53 memset(afile, 0, sizeof(struct osi_file));
55 filp->f_dentry = &afile->dentry;
56 tip = iget(afs_cacheSBp, (u_long)ainode);
58 osi_Panic("Can't get inode %d\n", ainode);
59 FILE_INODE(filp) = tip;
60 tip->i_flags |= MS_NOATIME; /* Disable updating access times. */
61 filp->f_flags = O_RDWR;
62 #if defined(AFS_LINUX24_ENV)
63 filp->f_op = fops_get(tip->i_fop);
65 filp->f_op = tip->i_op->default_file_ops;
67 if (filp->f_op && filp->f_op->open)
68 code = filp->f_op->open(tip, filp);
70 osi_Panic("Can't open inode %d\n", ainode);
71 afile->size = tip->i_size;
74 afile->proc = (int (*)()) 0;
75 afile->inum = ainode; /* for hint validity checking */
79 afs_osi_Stat(afile, astat)
80 register struct osi_file *afile;
81 register struct osi_stat *astat; {
82 register afs_int32 code;
83 AFS_STATCNT(osi_Stat);
84 MObtainWriteLock(&afs_xosi,320);
85 astat->size = FILE_INODE(&afile->file)->i_size;
86 astat->blksize = FILE_INODE(&afile->file)->i_blksize;
87 astat->mtime = FILE_INODE(&afile->file)->i_mtime;
88 astat->atime = FILE_INODE(&afile->file)->i_atime;
90 MReleaseWriteLock(&afs_xosi);
95 register struct osi_file *afile;
97 AFS_STATCNT(osi_Close);
99 if (FILE_INODE(&afile->file)) {
100 struct file *filp = &afile->file;
101 if (filp->f_op && filp->f_op->release)
102 filp->f_op->release(FILE_INODE(filp), filp);
103 iput(FILE_INODE(filp));
107 osi_FreeSmallSpace(afile);
111 osi_UFSTruncate(afile, asize)
112 register struct osi_file *afile;
114 struct AFS_UCRED *oldCred;
115 register afs_int32 code;
116 struct osi_stat tstat;
117 struct iattr newattrs;
118 struct inode *inode = FILE_INODE(&afile->file);
119 AFS_STATCNT(osi_Truncate);
121 /* This routine only shrinks files, and most systems
122 * have very slow truncates, even when the file is already
123 * small enough. Check now and save some time.
125 code = afs_osi_Stat(afile, &tstat);
126 if (code || tstat.size <= asize) return code;
127 MObtainWriteLock(&afs_xosi,321);
130 inode->i_size = newattrs.ia_size = asize;
131 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
132 #if defined(AFS_LINUX24_ENV)
133 newattrs.ia_ctime = CURRENT_TIME;
135 /* avoid notify_change() since it wants to update dentry->d_parent */
137 code = inode_change_ok(inode, &newattrs);
139 #ifdef INODE_SETATTR_NOT_VOID
140 code = inode_setattr(inode, &newattrs);
142 inode_setattr(inode, &newattrs);
146 truncate_inode_pages(&inode->i_data, asize);
148 if (inode->i_sb->s_op && inode->i_sb->s_op->notify_change) {
149 code = inode->i_sb->s_op->notify_change(&afile->dentry, &newattrs);
152 truncate_inode_pages(inode, asize);
153 if (inode->i_op && inode->i_op->truncate)
154 inode->i_op->truncate(inode);
160 MReleaseWriteLock(&afs_xosi);
165 /* Generic read interface */
166 afs_osi_Read(afile, offset, aptr, asize)
167 register struct osi_file *afile;
171 struct AFS_UCRED *oldCred;
173 register afs_int32 code;
174 register afs_int32 cnt1=0;
175 AFS_STATCNT(osi_Read);
178 * If the osi_file passed in is NULL, panic only if AFS is not shutting
179 * down. No point in crashing when we are already shutting down
182 if ( !afs_shuttingdown )
183 osi_Panic("osi_Read called with null param");
188 if (offset != -1) afile->offset = offset;
190 code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid);
193 code = asize - resid;
194 afile->offset += code;
197 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
198 ICL_TYPE_INT32, code);
204 /* Generic write interface */
205 afs_osi_Write(afile, offset, aptr, asize)
206 register struct osi_file *afile;
210 struct AFS_UCRED *oldCred;
212 register afs_int32 code;
213 AFS_STATCNT(osi_Write);
215 osi_Panic("afs_osi_Write called with null param");
216 if (offset != -1) afile->offset = offset;
218 code = osi_rdwr(UIO_WRITE, afile, (caddr_t)aptr, asize, &resid);
221 code = asize - resid;
222 afile->offset += code;
225 if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
229 (*afile->proc)(afile, code);
235 /* This work should be handled by physstrat in ca/machdep.c.
236 This routine written from the RT NFS port strategy routine.
237 It has been generalized a bit, but should still be pretty clear. */
238 int afs_osi_MapStrategy(aproc, bp)
240 register struct buf *bp;
242 afs_int32 returnCode;
244 AFS_STATCNT(osi_MapStrategy);
245 returnCode = (*aproc) (bp);
253 extern int afs_cold_shutdown;
255 AFS_STATCNT(shutdown_osifile);
256 if (afs_cold_shutdown) {
257 afs_osicred_initialized = 0;