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 */
16 int afs_osicred_initialized=0;
17 struct AFS_UCRED afs_osi_cred;
18 afs_lock_t afs_xosi; /* lock is for tvattr */
19 extern struct osi_dev cacheDev;
20 extern struct super_block *afs_cacheSBp;
22 void *osi_UFSOpen(ainode)
26 register struct osi_file *afile = NULL;
27 extern int cacheDiskType;
30 struct inode *tip = NULL;
31 struct file *filp = NULL;
32 AFS_STATCNT(osi_UFSOpen);
33 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
34 osi_Panic("UFSOpen called for non-UFS cache\n");
36 if (!afs_osicred_initialized) {
37 /* valid for alpha_osf, SunOS, Ultrix */
38 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
39 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
40 afs_osicred_initialized = 1;
42 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
45 osi_Panic("osi_UFSOpen: Failed to allocate %d bytes for osi_file.\n",
46 sizeof(struct osi_file));
48 memset(afile, 0, sizeof(struct osi_file));
50 filp->f_dentry = &afile->dentry;
51 tip = iget(afs_cacheSBp, (u_long)ainode);
53 osi_Panic("Can't get inode %d\n", ainode);
54 FILE_INODE(filp) = tip;
55 tip->i_flags |= MS_NOATIME; /* Disable updating access times. */
56 filp->f_flags = O_RDWR;
57 filp->f_op = tip->i_op->default_file_ops;
58 if (filp->f_op && filp->f_op->open)
59 code = filp->f_op->open(tip, filp);
61 osi_Panic("Can't open inode %d\n", ainode);
62 afile->size = tip->i_size;
65 afile->proc = (int (*)()) 0;
66 afile->inum = ainode; /* for hint validity checking */
70 afs_osi_Stat(afile, astat)
71 register struct osi_file *afile;
72 register struct osi_stat *astat; {
73 register afs_int32 code;
74 AFS_STATCNT(osi_Stat);
75 MObtainWriteLock(&afs_xosi,320);
76 astat->size = FILE_INODE(&afile->file)->i_size;
77 astat->blksize = FILE_INODE(&afile->file)->i_blksize;
78 astat->mtime = FILE_INODE(&afile->file)->i_mtime;
79 astat->atime = FILE_INODE(&afile->file)->i_atime;
81 MReleaseWriteLock(&afs_xosi);
86 register struct osi_file *afile;
88 AFS_STATCNT(osi_Close);
90 if (FILE_INODE(&afile->file)) {
91 struct file *filp = &afile->file;
92 if (filp->f_op && filp->f_op->release)
93 filp->f_op->release(FILE_INODE(filp), filp);
94 iput(FILE_INODE(filp));
98 osi_FreeSmallSpace(afile);
102 osi_UFSTruncate(afile, asize)
103 register struct osi_file *afile;
105 struct AFS_UCRED *oldCred;
106 register afs_int32 code;
107 struct osi_stat tstat;
108 struct iattr newattrs;
109 struct inode *inode = FILE_INODE(&afile->file);
110 AFS_STATCNT(osi_Truncate);
112 /* This routine only shrinks files, and most systems
113 * have very slow truncates, even when the file is already
114 * small enough. Check now and save some time.
116 code = afs_osi_Stat(afile, &tstat);
117 if (code || tstat.size <= asize) return code;
118 MObtainWriteLock(&afs_xosi,321);
121 inode->i_size = newattrs.ia_size = asize;
122 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
123 if (inode->i_sb->s_op && inode->i_sb->s_op->notify_change) {
124 code = inode->i_sb->s_op->notify_change(&afile->dentry, &newattrs);
127 truncate_inode_pages(inode, asize);
128 if (inode->i_op && inode->i_op->truncate)
129 inode->i_op->truncate(inode);
134 MReleaseWriteLock(&afs_xosi);
139 /* Generic read interface */
140 afs_osi_Read(afile, offset, aptr, asize)
141 register struct osi_file *afile;
145 struct AFS_UCRED *oldCred;
147 register afs_int32 code;
148 register afs_int32 cnt1=0;
149 AFS_STATCNT(osi_Read);
152 * If the osi_file passed in is NULL, panic only if AFS is not shutting
153 * down. No point in crashing when we are already shutting down
156 if ( !afs_shuttingdown )
157 osi_Panic("osi_Read called with null param");
162 if (offset != -1) afile->offset = offset;
164 code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid);
167 code = asize - resid;
168 afile->offset += code;
171 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
172 ICL_TYPE_INT32, code);
178 /* Generic write interface */
179 afs_osi_Write(afile, offset, aptr, asize)
180 register struct osi_file *afile;
184 struct AFS_UCRED *oldCred;
186 register afs_int32 code;
187 AFS_STATCNT(osi_Write);
189 osi_Panic("afs_osi_Write called with null param");
190 if (offset != -1) afile->offset = offset;
192 code = osi_rdwr(UIO_WRITE, afile, (caddr_t)aptr, asize, &resid);
195 code = asize - resid;
196 afile->offset += code;
199 if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
203 (*afile->proc)(afile, code);
209 /* This work should be handled by physstrat in ca/machdep.c.
210 This routine written from the RT NFS port strategy routine.
211 It has been generalized a bit, but should still be pretty clear. */
212 int afs_osi_MapStrategy(aproc, bp)
214 register struct buf *bp;
216 afs_int32 returnCode;
218 AFS_STATCNT(osi_MapStrategy);
219 returnCode = (*aproc) (bp);
227 extern int afs_cold_shutdown;
229 AFS_STATCNT(shutdown_osifile);
230 if (afs_cold_shutdown) {
231 afs_osicred_initialized = 0;