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 "h/module.h" /* early to avoid printf->printk mapping */
17 #include "afs/sysincludes.h" /* Standard vendor system headers */
18 #include "afsincludes.h" /* Afs-based standard headers */
19 #include "afs/afs_stats.h" /* afs statistics */
20 #include "h/smp_lock.h"
23 int afs_osicred_initialized = 0;
24 struct AFS_UCRED afs_osi_cred;
25 afs_lock_t afs_xosi; /* lock is for tvattr */
26 extern struct osi_dev cacheDev;
27 extern struct super_block *afs_cacheSBp;
30 osi_UFSOpen(afs_int32 ainode)
32 register struct osi_file *afile = NULL;
33 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 memset((char *)&afs_osi_cred, 0, 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_AllocLargeSpace(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_LINUX26_ENV)
63 filp->f_mapping = tip->i_mapping;
65 #if defined(AFS_LINUX24_ENV)
66 filp->f_op = fops_get(tip->i_fop);
68 filp->f_op = tip->i_op->default_file_ops;
70 if (filp->f_op && filp->f_op->open)
71 code = filp->f_op->open(tip, filp);
73 osi_Panic("Can't open inode %d\n", ainode);
74 afile->size = tip->i_size;
77 afile->proc = (int (*)())0;
78 afile->inum = ainode; /* for hint validity checking */
83 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
85 register afs_int32 code;
86 AFS_STATCNT(osi_Stat);
87 MObtainWriteLock(&afs_xosi, 320);
88 astat->size = FILE_INODE(&afile->file)->i_size;
89 astat->blksize = FILE_INODE(&afile->file)->i_blksize;
90 #if defined(AFS_LINUX26_ENV)
91 astat->mtime = FILE_INODE(&afile->file)->i_mtime.tv_sec;
92 astat->atime = FILE_INODE(&afile->file)->i_atime.tv_sec;
94 astat->mtime = FILE_INODE(&afile->file)->i_mtime;
95 astat->atime = FILE_INODE(&afile->file)->i_atime;
98 MReleaseWriteLock(&afs_xosi);
103 osi_UFSClose(register struct osi_file *afile)
105 AFS_STATCNT(osi_Close);
107 if (FILE_INODE(&afile->file)) {
108 struct file *filp = &afile->file;
109 if (filp->f_op && filp->f_op->release)
110 filp->f_op->release(FILE_INODE(filp), filp);
111 iput(FILE_INODE(filp));
115 osi_FreeLargeSpace(afile);
120 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
122 register afs_int32 code;
123 struct osi_stat tstat;
124 struct iattr newattrs;
125 struct inode *inode = FILE_INODE(&afile->file);
126 AFS_STATCNT(osi_Truncate);
128 /* This routine only shrinks files, and most systems
129 * have very slow truncates, even when the file is already
130 * small enough. Check now and save some time.
132 code = afs_osi_Stat(afile, &tstat);
133 if (code || tstat.size <= asize)
135 MObtainWriteLock(&afs_xosi, 321);
137 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
138 down_write(&inode->i_alloc_sem);
141 inode->i_size = newattrs.ia_size = asize;
142 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
143 #if defined(AFS_LINUX24_ENV)
144 newattrs.ia_ctime = CURRENT_TIME;
146 /* avoid notify_change() since it wants to update dentry->d_parent */
148 code = inode_change_ok(inode, &newattrs);
150 #ifdef INODE_SETATTR_NOT_VOID
151 code = inode_setattr(inode, &newattrs);
153 inode_setattr(inode, &newattrs);
157 truncate_inode_pages(&inode->i_data, asize);
159 if (inode->i_sb->s_op && inode->i_sb->s_op->notify_change) {
160 code = inode->i_sb->s_op->notify_change(&afile->dentry, &newattrs);
163 truncate_inode_pages(inode, asize);
164 if (inode->i_op && inode->i_op->truncate)
165 inode->i_op->truncate(inode);
170 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
171 up_write(&inode->i_alloc_sem);
174 MReleaseWriteLock(&afs_xosi);
179 /* Generic read interface */
181 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
185 register afs_int32 code;
186 AFS_STATCNT(osi_Read);
189 * If the osi_file passed in is NULL, panic only if AFS is not shutting
190 * down. No point in crashing when we are already shutting down
193 if (!afs_shuttingdown)
194 osi_Panic("osi_Read called with null param");
200 afile->offset = offset;
202 code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid);
205 code = asize - resid;
206 afile->offset += code;
208 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
209 ICL_TYPE_INT32, code);
215 /* Generic write interface */
217 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
221 register afs_int32 code;
222 AFS_STATCNT(osi_Write);
224 if (!afs_shuttingdown)
225 osi_Panic("afs_osi_Write called with null param");
230 afile->offset = offset;
232 code = osi_rdwr(UIO_WRITE, afile, (caddr_t) aptr, asize, &resid);
235 code = asize - resid;
236 afile->offset += code;
240 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
244 (*afile->proc) (afile, code);
250 /* This work should be handled by physstrat in ca/machdep.c.
251 This routine written from the RT NFS port strategy routine.
252 It has been generalized a bit, but should still be pretty clear. */
254 afs_osi_MapStrategy(int (*aproc) (struct buf * bp), register struct buf *bp)
256 afs_int32 returnCode;
258 AFS_STATCNT(osi_MapStrategy);
259 returnCode = (*aproc) (bp);
265 shutdown_osifile(void)
267 extern int afs_cold_shutdown;
269 AFS_STATCNT(shutdown_osifile);
270 if (afs_cold_shutdown) {
271 afs_osicred_initialized = 0;