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 #ifdef AFS_LINUX24_ENV
17 #include "h/module.h" /* early to avoid printf->printk mapping */
19 #include "afs/sysincludes.h" /* Standard vendor system headers */
20 #include "afsincludes.h" /* Afs-based standard headers */
21 #include "afs/afs_stats.h" /* afs statistics */
22 #include "h/smp_lock.h"
25 int afs_osicred_initialized = 0;
26 struct AFS_UCRED afs_osi_cred;
27 afs_lock_t afs_xosi; /* lock is for tvattr */
28 extern struct osi_dev cacheDev;
29 extern struct super_block *afs_cacheSBp;
32 osi_UFSOpen(afs_int32 ainode)
34 register struct osi_file *afile = NULL;
35 extern int cacheDiskType;
37 struct inode *tip = NULL;
38 struct file *filp = NULL;
39 AFS_STATCNT(osi_UFSOpen);
40 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
41 osi_Panic("UFSOpen called for non-UFS cache\n");
43 if (!afs_osicred_initialized) {
44 /* valid for alpha_osf, SunOS, Ultrix */
45 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
46 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
47 afs_osicred_initialized = 1;
49 afile = (struct osi_file *)osi_AllocLargeSpace(sizeof(struct osi_file));
52 osi_Panic("osi_UFSOpen: Failed to allocate %d bytes for osi_file.\n",
53 sizeof(struct osi_file));
55 memset(afile, 0, sizeof(struct osi_file));
57 filp->f_dentry = &afile->dentry;
58 tip = iget(afs_cacheSBp, (u_long) ainode);
60 osi_Panic("Can't get inode %d\n", ainode);
61 FILE_INODE(filp) = tip;
62 tip->i_flags |= MS_NOATIME; /* Disable updating access times. */
63 filp->f_flags = O_RDWR;
64 #if defined(AFS_LINUX26_ENV)
65 filp->f_mapping = tip->i_mapping;
67 #if defined(AFS_LINUX24_ENV)
68 filp->f_op = fops_get(tip->i_fop);
70 filp->f_op = tip->i_op->default_file_ops;
72 if (filp->f_op && filp->f_op->open)
73 code = filp->f_op->open(tip, filp);
75 osi_Panic("Can't open inode %d\n", ainode);
76 afile->size = tip->i_size;
79 afile->proc = (int (*)())0;
80 afile->inum = ainode; /* for hint validity checking */
85 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
87 register afs_int32 code;
88 AFS_STATCNT(osi_Stat);
89 MObtainWriteLock(&afs_xosi, 320);
90 astat->size = FILE_INODE(&afile->file)->i_size;
91 astat->blksize = FILE_INODE(&afile->file)->i_blksize;
92 #if defined(AFS_LINUX26_ENV)
93 astat->mtime = FILE_INODE(&afile->file)->i_mtime.tv_sec;
94 astat->atime = FILE_INODE(&afile->file)->i_atime.tv_sec;
96 astat->mtime = FILE_INODE(&afile->file)->i_mtime;
97 astat->atime = FILE_INODE(&afile->file)->i_atime;
100 MReleaseWriteLock(&afs_xosi);
105 osi_UFSClose(register struct osi_file *afile)
107 AFS_STATCNT(osi_Close);
109 if (FILE_INODE(&afile->file)) {
110 struct file *filp = &afile->file;
111 if (filp->f_op && filp->f_op->release)
112 filp->f_op->release(FILE_INODE(filp), filp);
113 iput(FILE_INODE(filp));
117 osi_FreeLargeSpace(afile);
122 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
124 register afs_int32 code;
125 struct osi_stat tstat;
126 struct iattr newattrs;
127 struct inode *inode = FILE_INODE(&afile->file);
128 AFS_STATCNT(osi_Truncate);
130 /* This routine only shrinks files, and most systems
131 * have very slow truncates, even when the file is already
132 * small enough. Check now and save some time.
134 code = afs_osi_Stat(afile, &tstat);
135 if (code || tstat.size <= asize)
137 MObtainWriteLock(&afs_xosi, 321);
139 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
140 down_write(&inode->i_alloc_sem);
143 newattrs.ia_size = asize;
144 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
145 #if defined(AFS_LINUX24_ENV)
146 newattrs.ia_ctime = CURRENT_TIME;
148 /* avoid notify_change() since it wants to update dentry->d_parent */
150 code = inode_change_ok(inode, &newattrs);
152 #ifdef INODE_SETATTR_NOT_VOID
153 code = inode_setattr(inode, &newattrs);
155 inode_setattr(inode, &newattrs);
159 truncate_inode_pages(&inode->i_data, asize);
161 inode->i_size = asize;
162 if (inode->i_sb->s_op && inode->i_sb->s_op->notify_change) {
163 code = inode->i_sb->s_op->notify_change(&afile->dentry, &newattrs);
166 truncate_inode_pages(inode, asize);
167 if (inode->i_op && inode->i_op->truncate)
168 inode->i_op->truncate(inode);
173 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
174 up_write(&inode->i_alloc_sem);
177 MReleaseWriteLock(&afs_xosi);
182 /* Generic read interface */
184 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
188 register afs_int32 code;
189 AFS_STATCNT(osi_Read);
192 * If the osi_file passed in is NULL, panic only if AFS is not shutting
193 * down. No point in crashing when we are already shutting down
196 if (!afs_shuttingdown)
197 osi_Panic("osi_Read called with null param");
203 afile->offset = offset;
205 code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid);
208 code = asize - resid;
209 afile->offset += code;
211 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
212 ICL_TYPE_INT32, code);
218 /* Generic write interface */
220 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
224 register afs_int32 code;
225 AFS_STATCNT(osi_Write);
227 if (!afs_shuttingdown)
228 osi_Panic("afs_osi_Write called with null param");
233 afile->offset = offset;
235 code = osi_rdwr(UIO_WRITE, afile, (caddr_t) aptr, asize, &resid);
238 code = asize - resid;
239 afile->offset += code;
243 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
247 (*afile->proc) (afile, code);
253 /* This work should be handled by physstrat in ca/machdep.c.
254 This routine written from the RT NFS port strategy routine.
255 It has been generalized a bit, but should still be pretty clear. */
257 afs_osi_MapStrategy(int (*aproc) (struct buf * bp), register struct buf *bp)
259 afs_int32 returnCode;
261 AFS_STATCNT(osi_MapStrategy);
262 returnCode = (*aproc) (bp);
268 shutdown_osifile(void)
270 extern int afs_cold_shutdown;
272 AFS_STATCNT(shutdown_osifile);
273 if (afs_cold_shutdown) {
274 afs_osicred_initialized = 0;