Import 2.3.26pre2
[davej-history.git] / fs / hfs / sysdep.c
blobfb68e9ab21e658b80ae05702218ab31b9670236b
1 /*
2 * linux/fs/hfs/sysdep.c
4 * Copyright (C) 1996 Paul H. Hargrove
5 * This file may be distributed under the terms of the GNU Public License.
7 * This file contains the code to do various system dependent things.
9 * "XXX" in a comment is a note to myself to consider changing something.
11 * In function preconditions the term "valid" applied to a pointer to
12 * a structure means that the pointer is non-NULL and the structure it
13 * points to has all fields initialized to consistent values.
16 #include "hfs.h"
17 #include <linux/hfs_fs_sb.h>
18 #include <linux/hfs_fs_i.h>
19 #include <linux/hfs_fs.h>
21 static int hfs_revalidate_dentry(struct dentry *, int);
22 static int hfs_hash_dentry(struct dentry *, struct qstr *);
23 static int hfs_compare_dentry(struct dentry *, struct qstr *, struct qstr *);
24 static void hfs_dentry_iput(struct dentry *, struct inode *);
25 struct dentry_operations hfs_dentry_operations =
27 hfs_revalidate_dentry, /* d_revalidate(struct dentry *) */
28 hfs_hash_dentry, /* d_hash */
29 hfs_compare_dentry, /* d_compare */
30 NULL, /* d_delete(struct dentry *) */
31 NULL, /* d_release(struct dentry *) */
32 hfs_dentry_iput /* d_iput(struct dentry *, struct inode *) */
36 * hfs_buffer_get()
38 * Return a buffer for the 'block'th block of the media.
39 * If ('read'==0) then the buffer is not read from disk.
41 hfs_buffer hfs_buffer_get(hfs_sysmdb sys_mdb, int block, int read) {
42 hfs_buffer tmp = HFS_BAD_BUFFER;
44 if (read) {
45 tmp = bread(sys_mdb->s_dev, block, HFS_SECTOR_SIZE);
46 } else {
47 tmp = getblk(sys_mdb->s_dev, block, HFS_SECTOR_SIZE);
48 if (tmp) {
49 mark_buffer_uptodate(tmp, 1);
52 if (!tmp) {
53 hfs_error("hfs_fs: unable to read block 0x%08x from dev %s\n",
54 block, hfs_mdb_name(sys_mdb));
57 return tmp;
60 /* dentry case-handling: just lowercase everything */
62 /* hfs_strhash now uses the same hashing function as the dcache. */
63 static int hfs_hash_dentry(struct dentry *dentry, struct qstr *this)
65 if (this->len > HFS_NAMELEN)
66 return 0;
68 this->hash = hfs_strhash(this->name, this->len);
69 return 0;
72 /* return 1 on failure and 0 on success */
73 static int hfs_compare_dentry(struct dentry *dentry, struct qstr *a,
74 struct qstr *b)
76 if (a->len != b->len) return 1;
78 if (a->len > HFS_NAMELEN)
79 return 1;
81 return !hfs_streq(a->name, a->len, b->name, b->len);
84 static void hfs_dentry_iput(struct dentry *dentry, struct inode *inode)
86 struct hfs_cat_entry *entry = HFS_I(inode)->entry;
88 entry->sys_entry[HFS_ITYPE_TO_INT(HFS_ITYPE(inode->i_ino))] = NULL;
89 iput(inode);
92 static int hfs_revalidate_dentry(struct dentry *dentry, int flags)
94 struct inode *inode = dentry->d_inode;
95 int diff;
97 /* fix up inode on a timezone change */
98 if (inode &&
99 (diff = (hfs_to_utc(0) - HFS_I(inode)->tz_secondswest))) {
100 inode->i_ctime += diff;
101 inode->i_atime += diff;
102 inode->i_mtime += diff;
103 HFS_I(inode)->tz_secondswest += diff;
105 return 1;