1 /*
2 * ialloc.c
3 *
4 * PURPOSE
5 * Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
6 *
7 * CONTACTS
8 * E-mail regarding any portion of the Linux UDF file system should be
9 * directed to the development team mailing list (run by majordomo):
10 * linux_udf@hootie.lvld.hp.com
11 *
12 * COPYRIGHT
13 * This file is distributed under the terms of the GNU General Public
14 * License (GPL). Copies of the GPL can be obtained from:
15 * ftp://prep.ai.mit.edu/pub/gnu/GPL
16 * Each contributing author retains all rights to their own work.
17 *
18 * (C) 1998-2000 Ben Fennema
19 *
20 * HISTORY
21 *
22 * 02/24/99 blf Created.
23 *
24 */
25
26 #include "udfdecl.h"
27 #include <linux/fs.h>
28 #include <linux/locks.h>
29 #include <linux/quotaops.h>
30 #include <linux/udf_fs.h>
31
32 #include "udf_i.h"
33 #include "udf_sb.h"
34
35 void udf_free_inode(struct inode * inode)
36 {
37 struct super_block * sb = inode->i_sb;
38 int is_directory;
39 unsigned long ino;
40
41 ino = inode->i_ino;
42
43 /*
44 * Note: we must free any quota before locking the superblock,
45 * as writing the quota to disk may need the lock as well.
46 */
47 DQUOT_FREE_INODE(sb, inode);
48 DQUOT_DROP(inode);
49
50 lock_super(sb);
51
52 is_directory = S_ISDIR(inode->i_mode);
53
54 clear_inode(inode);
55
56 if (UDF_SB_LVIDBH(sb))
57 {
58 if (is_directory)
59 UDF_SB_LVIDIU(sb)->numDirs =
60 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) - 1);
61 else
62 UDF_SB_LVIDIU(sb)->numFiles =
63 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) - 1);
64
65 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
66 }
67
68 unlock_super(sb);
69
70 udf_free_blocks(inode, UDF_I_LOCATION(inode), 0, 1);
71 }
72
73 struct inode * udf_new_inode (const struct inode *dir, int mode, int * err)
74 {
75 struct super_block *sb;
76 struct inode * inode;
77 int block;
78 Uint32 start = UDF_I_LOCATION(dir).logicalBlockNum;
79
80 sb = dir->i_sb;
81 inode = new_inode(sb);
82 if (!inode)
83 {
84 *err = -ENOMEM;
85 return NULL;
86 }
87 *err = -ENOSPC;
88
89 block = udf_new_block(dir, UDF_I_LOCATION(dir).partitionReferenceNum,
90 start, err);
91 if (*err)
92 {
93 iput(inode);
94 return NULL;
95 }
96 lock_super(sb);
97
98 if (UDF_SB_LVIDBH(sb))
99 {
100 struct LogicalVolHeaderDesc *lvhd;
101 Uint64 uniqueID;
102 lvhd = (struct LogicalVolHeaderDesc *)(UDF_SB_LVID(sb)->logicalVolContentsUse);
103 if (S_ISDIR(mode))
104 UDF_SB_LVIDIU(sb)->numDirs =
105 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) + 1);
106 else
107 UDF_SB_LVIDIU(sb)->numFiles =
108 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + 1);
109 UDF_I_UNIQUE(inode) = uniqueID = le64_to_cpu(lvhd->uniqueID);
110 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
111 uniqueID += 16;
112 lvhd->uniqueID = cpu_to_le64(uniqueID);
113 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
114 }
115 inode->i_mode = mode;
116 inode->i_uid = current->fsuid;
117 if (dir->i_mode & S_ISGID) {
118 inode->i_gid = dir->i_gid;
119 if (S_ISDIR(mode))
120 mode |= S_ISGID;
121 }
122 else
123 inode->i_gid = current->fsgid;
124
125 UDF_I_LOCATION(inode).logicalBlockNum = block;
126 UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum;
127 inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0);
128 inode->i_blksize = PAGE_SIZE;
129 inode->i_blocks = 0;
130 UDF_I_LENEATTR(inode) = 0;
131 UDF_I_LENALLOC(inode) = 0;
132 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE))
133 {
134 UDF_I_EXTENDED_FE(inode) = 1;
135 UDF_UPDATE_UDFREV(inode->i_sb, UDF_VERS_USE_EXTENDED_FE);
136 }
137 else
138 UDF_I_EXTENDED_FE(inode) = 0;
139 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
140 UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_IN_ICB;
141 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
142 UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_SHORT;
143 else
144 UDF_I_ALLOCTYPE(inode) = ICB_FLAG_AD_LONG;
145 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
146 UDF_I_UMTIME(inode) = UDF_I_UATIME(inode) = UDF_I_UCTIME(inode) = CURRENT_UTIME;
147 UDF_I_NEW_INODE(inode) = 1;
148 insert_inode_hash(inode);
149 mark_inode_dirty(inode);
150
151 unlock_super(sb);
152 if (DQUOT_ALLOC_INODE(sb, inode))
153 {
154 sb->dq_op->drop(inode);
155 inode->i_nlink = 0;
156 iput(inode);
157 *err = -EDQUOT;
158 return NULL;
159 }
160
161 *err = 0;
162 return inode;
163 }
164
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.