5 * Inode allocation handling routines for the OSTA-UDF(tm) filesystem.
8 * This file is distributed under the terms of the GNU General Public
9 * License (GPL). Copies of the GPL can be obtained from:
10 * ftp://prep.ai.mit.edu/pub/gnu/GPL
11 * Each contributing author retains all rights to their own work.
13 * (C) 1998-2001 Ben Fennema
17 * 02/24/99 blf Created.
23 #include <linux/quotaops.h>
24 #include <linux/udf_fs.h>
25 #include <linux/sched.h>
26 #include <linux/slab.h>
31 void udf_free_inode(struct inode
* inode
)
33 struct super_block
*sb
= inode
->i_sb
;
34 struct udf_sb_info
*sbi
= UDF_SB(sb
);
37 * Note: we must free any quota before locking the superblock,
38 * as writing the quota to disk may need the lock as well.
40 DQUOT_FREE_INODE(inode
);
45 mutex_lock(&sbi
->s_alloc_mutex
);
47 if (S_ISDIR(inode
->i_mode
))
48 UDF_SB_LVIDIU(sb
)->numDirs
=
49 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
) - 1);
51 UDF_SB_LVIDIU(sb
)->numFiles
=
52 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) - 1);
54 mark_buffer_dirty(sbi
->s_lvidbh
);
56 mutex_unlock(&sbi
->s_alloc_mutex
);
58 udf_free_blocks(sb
, NULL
, UDF_I_LOCATION(inode
), 0, 1);
61 struct inode
* udf_new_inode (struct inode
*dir
, int mode
, int * err
)
63 struct super_block
*sb
= dir
->i_sb
;
64 struct udf_sb_info
*sbi
= UDF_SB(sb
);
67 uint32_t start
= UDF_I_LOCATION(dir
).logicalBlockNum
;
69 inode
= new_inode(sb
);
78 block
= udf_new_block(dir
->i_sb
, NULL
, UDF_I_LOCATION(dir
).partitionReferenceNum
,
86 mutex_lock(&sbi
->s_alloc_mutex
);
87 UDF_I_UNIQUE(inode
) = 0;
88 UDF_I_LENEXTENTS(inode
) = 0;
89 UDF_I_NEXT_ALLOC_BLOCK(inode
) = 0;
90 UDF_I_NEXT_ALLOC_GOAL(inode
) = 0;
91 UDF_I_STRAT4096(inode
) = 0;
92 if (UDF_SB_LVIDBH(sb
))
94 struct logicalVolHeaderDesc
*lvhd
;
96 lvhd
= (struct logicalVolHeaderDesc
*)(UDF_SB_LVID(sb
)->logicalVolContentsUse
);
98 UDF_SB_LVIDIU(sb
)->numDirs
=
99 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
) + 1);
101 UDF_SB_LVIDIU(sb
)->numFiles
=
102 cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) + 1);
103 UDF_I_UNIQUE(inode
) = uniqueID
= le64_to_cpu(lvhd
->uniqueID
);
104 if (!(++uniqueID
& 0x00000000FFFFFFFFUL
))
106 lvhd
->uniqueID
= cpu_to_le64(uniqueID
);
107 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
109 inode
->i_mode
= mode
;
110 inode
->i_uid
= current
->fsuid
;
111 if (dir
->i_mode
& S_ISGID
)
113 inode
->i_gid
= dir
->i_gid
;
118 inode
->i_gid
= current
->fsgid
;
120 UDF_I_LOCATION(inode
).logicalBlockNum
= block
;
121 UDF_I_LOCATION(inode
).partitionReferenceNum
= UDF_I_LOCATION(dir
).partitionReferenceNum
;
122 inode
->i_ino
= udf_get_lb_pblock(sb
, UDF_I_LOCATION(inode
), 0);
123 inode
->i_blksize
= PAGE_SIZE
;
125 UDF_I_LENEATTR(inode
) = 0;
126 UDF_I_LENALLOC(inode
) = 0;
127 UDF_I_USE(inode
) = 0;
128 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_EXTENDED_FE
))
130 UDF_I_EFE(inode
) = 1;
131 UDF_UPDATE_UDFREV(inode
->i_sb
, UDF_VERS_USE_EXTENDED_FE
);
132 UDF_I_DATA(inode
) = kmalloc(inode
->i_sb
->s_blocksize
- sizeof(struct extendedFileEntry
), GFP_KERNEL
);
133 memset(UDF_I_DATA(inode
), 0x00, inode
->i_sb
->s_blocksize
- sizeof(struct extendedFileEntry
));
137 UDF_I_EFE(inode
) = 0;
138 UDF_I_DATA(inode
) = kmalloc(inode
->i_sb
->s_blocksize
- sizeof(struct fileEntry
), GFP_KERNEL
);
139 memset(UDF_I_DATA(inode
), 0x00, inode
->i_sb
->s_blocksize
- sizeof(struct fileEntry
));
141 if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_AD_IN_ICB
))
142 UDF_I_ALLOCTYPE(inode
) = ICBTAG_FLAG_AD_IN_ICB
;
143 else if (UDF_QUERY_FLAG(inode
->i_sb
, UDF_FLAG_USE_SHORT_AD
))
144 UDF_I_ALLOCTYPE(inode
) = ICBTAG_FLAG_AD_SHORT
;
146 UDF_I_ALLOCTYPE(inode
) = ICBTAG_FLAG_AD_LONG
;
147 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
148 UDF_I_CRTIME(inode
) = current_fs_time(inode
->i_sb
);
149 insert_inode_hash(inode
);
150 mark_inode_dirty(inode
);
151 mutex_unlock(&sbi
->s_alloc_mutex
);
153 if (DQUOT_ALLOC_INODE(inode
))
156 inode
->i_flags
|= S_NOQUOTA
;