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 "../afs/param.h" /* Should be always first */
11 #include "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h" /* afs statistics */
14 #include "../h/smp_lock.h"
17 int afs_osicred_initialized=0;
18 struct AFS_UCRED afs_osi_cred;
19 afs_lock_t afs_xosi; /* lock is for tvattr */
20 extern struct osi_dev cacheDev;
21 extern struct super_block *afs_cacheSBp;
23 void *osi_UFSOpen(ainode)
27 register struct osi_file *afile = NULL;
28 extern int cacheDiskType;
31 struct inode *tip = NULL;
32 struct file *filp = NULL;
33 AFS_STATCNT(osi_UFSOpen);
34 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
35 osi_Panic("UFSOpen called for non-UFS cache\n");
37 if (!afs_osicred_initialized) {
38 /* valid for alpha_osf, SunOS, Ultrix */
39 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
40 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
41 afs_osicred_initialized = 1;
43 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
46 osi_Panic("osi_UFSOpen: Failed to allocate %d bytes for osi_file.\n",
47 sizeof(struct osi_file));
49 memset(afile, 0, sizeof(struct osi_file));
51 filp->f_dentry = &afile->dentry;
52 tip = iget(afs_cacheSBp, (u_long)ainode);
54 osi_Panic("Can't get inode %d\n", ainode);
55 FILE_INODE(filp) = tip;
56 tip->i_flags |= MS_NOATIME; /* Disable updating access times. */
57 filp->f_flags = O_RDWR;
58 #if defined(AFS_LINUX24_ENV)
59 filp->f_op = fops_get(tip->i_fop);
61 filp->f_op = tip->i_op->default_file_ops;
63 if (filp->f_op && filp->f_op->open)
64 code = filp->f_op->open(tip, filp);
66 osi_Panic("Can't open inode %d\n", ainode);
67 afile->size = tip->i_size;
70 afile->proc = (int (*)()) 0;
71 afile->inum = ainode; /* for hint validity checking */
75 afs_osi_Stat(afile, astat)
76 register struct osi_file *afile;
77 register struct osi_stat *astat; {
78 register afs_int32 code;
79 AFS_STATCNT(osi_Stat);
80 MObtainWriteLock(&afs_xosi,320);
81 astat->size = FILE_INODE(&afile->file)->i_size;
82 astat->blksize = FILE_INODE(&afile->file)->i_blksize;
83 astat->mtime = FILE_INODE(&afile->file)->i_mtime;
84 astat->atime = FILE_INODE(&afile->file)->i_atime;
86 MReleaseWriteLock(&afs_xosi);
91 register struct osi_file *afile;
93 AFS_STATCNT(osi_Close);
95 if (FILE_INODE(&afile->file)) {
96 struct file *filp = &afile->file;
97 if (filp->f_op && filp->f_op->release)
98 filp->f_op->release(FILE_INODE(filp), filp);
99 iput(FILE_INODE(filp));
103 osi_FreeSmallSpace(afile);
107 #if defined(AFS_LINUX24_ENV)
108 int osi_notify_change(struct dentry * dentry, struct iattr * attr)
110 struct inode *inode = dentry->d_inode;
112 time_t now = CURRENT_TIME;
113 unsigned int ia_valid = attr->ia_valid;
115 attr->ia_ctime = now;
116 if (!(ia_valid & ATTR_ATIME_SET))
117 attr->ia_atime = now;
118 if (!(ia_valid & ATTR_MTIME_SET))
119 attr->ia_mtime = now;
122 if (inode && inode->i_op && inode->i_op->setattr)
123 error = inode->i_op->setattr(dentry, attr);
125 error = inode_change_ok(inode, attr);
127 inode_setattr(inode, attr);
134 osi_UFSTruncate(afile, asize)
135 register struct osi_file *afile;
137 struct AFS_UCRED *oldCred;
138 register afs_int32 code;
139 struct osi_stat tstat;
140 struct iattr newattrs;
141 struct inode *inode = FILE_INODE(&afile->file);
142 AFS_STATCNT(osi_Truncate);
144 /* This routine only shrinks files, and most systems
145 * have very slow truncates, even when the file is already
146 * small enough. Check now and save some time.
148 code = afs_osi_Stat(afile, &tstat);
149 if (code || tstat.size <= asize) return code;
150 MObtainWriteLock(&afs_xosi,321);
153 #if defined(AFS_LINUX24_ENV)
154 newattrs.ia_size = asize;
155 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
156 code = osi_notify_change(&afile->dentry, &newattrs);
158 inode->i_size = newattrs.ia_size = asize;
159 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
160 if (inode->i_sb->s_op && inode->i_sb->s_op->notify_change) {
161 code = inode->i_sb->s_op->notify_change(&afile->dentry, &newattrs);
164 truncate_inode_pages(inode, asize);
165 if (inode->i_op && inode->i_op->truncate)
166 inode->i_op->truncate(inode);
172 MReleaseWriteLock(&afs_xosi);
177 /* Generic read interface */
178 afs_osi_Read(afile, offset, aptr, asize)
179 register struct osi_file *afile;
183 struct AFS_UCRED *oldCred;
185 register afs_int32 code;
186 register afs_int32 cnt1=0;
187 AFS_STATCNT(osi_Read);
190 * If the osi_file passed in is NULL, panic only if AFS is not shutting
191 * down. No point in crashing when we are already shutting down
194 if ( !afs_shuttingdown )
195 osi_Panic("osi_Read called with null param");
200 if (offset != -1) afile->offset = offset;
202 code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid);
205 code = asize - resid;
206 afile->offset += code;
209 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
210 ICL_TYPE_INT32, code);
216 /* Generic write interface */
217 afs_osi_Write(afile, offset, aptr, asize)
218 register struct osi_file *afile;
222 struct AFS_UCRED *oldCred;
224 register afs_int32 code;
225 AFS_STATCNT(osi_Write);
227 osi_Panic("afs_osi_Write called with null param");
228 if (offset != -1) afile->offset = offset;
230 code = osi_rdwr(UIO_WRITE, afile, (caddr_t)aptr, asize, &resid);
233 code = asize - resid;
234 afile->offset += code;
237 if (code == ENOSPC) afs_warnuser("\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. */
250 int afs_osi_MapStrategy(aproc, bp)
252 register struct buf *bp;
254 afs_int32 returnCode;
256 AFS_STATCNT(osi_MapStrategy);
257 returnCode = (*aproc) (bp);
265 extern int afs_cold_shutdown;
267 AFS_STATCNT(shutdown_osifile);
268 if (afs_cold_shutdown) {
269 afs_osicred_initialized = 0;