5 * File handling routines for the OSTA-UDF(tm) filesystem. 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 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. 18 * (C) 1998-1999 Dave Boynton 19 * (C) 1998-1999 Ben Fennema 20 * (C) 1999 Stelias Computing Inc 24 * 10/02/98 dgb Attempt to integrate into udf.o 25 * 10/07/98 Switched to using generic_readpage, etc., like isofs 27 * 12/06/98 blf Added udf_file_read. uses generic_file_read for all cases but 29 * 04/06/99 64 bit file handling on 32 bit systems taken from ext2 file.c 30 * 05/12/99 Preliminary file write support 35 #include <linux/udf_fs.h> 36 #include <asm/uaccess.h> 37 #include <linux/kernel.h> 38 #include <linux/string.h>/* memset */ 39 #include <linux/errno.h> 40 #include <linux/locks.h> 47 typedefvoid* poll_table
; 49 static long longudf_file_llseek(struct file
*,long long,int); 50 static ssize_t
udf_file_read_adinicb(struct file
*,char*,size_t, loff_t
*); 51 static ssize_t
udf_file_write(struct file
*,const char*,size_t, loff_t
*); 52 #if BITS_PER_LONG < 64 53 static intudf_open_file(struct inode
*,struct file
*); 55 static intudf_release_file(struct inode
*,struct file
*); 57 static struct file_operations udf_file_operations
= { 58 udf_file_llseek
,/* llseek */ 59 generic_file_read
,/* read */ 60 udf_file_write
,/* write */ 64 generic_file_mmap
,/* mmap */ 65 #if BITS_PER_LONG == 64 68 udf_open_file
,/* open */ 71 udf_release_file
,/* release */ 72 udf_sync_file
,/* fsync */ 74 NULL
,/* check_media_change */ 79 struct inode_operations udf_file_inode_operations
= { 91 NULL
,/* follow_link */ 92 udf_get_block
,/* get_block */ 93 block_read_full_page
,/* readpage */ 94 block_write_full_page
,/* writepage */ 95 block_flushpage
,/* flushpage */ 97 udf_truncate
,/* truncate */ 101 NULL
,/* permission */ 103 NULL
/* revalidate */ 106 static struct file_operations udf_file_operations_adinicb
= { 107 udf_file_llseek
,/* llseek */ 108 udf_file_read_adinicb
,/* read */ 109 udf_file_write
,/* write */ 112 udf_ioctl
,/* ioctl */ 116 udf_release_file
,/* release */ 117 udf_sync_file
,/* fsync */ 119 NULL
,/* check_media_change */ 120 NULL
,/* revalidate */ 124 struct inode_operations udf_file_inode_operations_adinicb
= { 125 &udf_file_operations_adinicb
, 136 NULL
,/* follow_link */ 137 udf_get_block
,/* get_block */ 138 block_read_full_page
,/* readpage */ 139 block_write_full_page
,/* writepage */ 140 block_flushpage
,/* flushpage */ 142 udf_truncate
,/* truncate */ 146 NULL
,/* permission */ 148 NULL
/* revalidate */ 152 * Make sure the offset never goes beyond the 32-bit mark.. 154 static long longudf_file_llseek(struct file
* file
,long long offset
,int origin
) 156 struct inode
* inode
= file
->f_dentry
->d_inode
; 162 offset
+= inode
->i_size
; 167 offset
+= file
->f_pos
; 171 #if BITS_PER_LONG < 64 172 if(((unsigned long long) offset
>>32) !=0) 177 if(offset
!= file
->f_pos
) 179 file
->f_pos
= offset
; 181 file
->f_version
= ++event
; 186 staticinlinevoidremove_suid(struct inode
* inode
) 190 /* set S_IGID if S_IXGRP is set, and always set S_ISUID */ 191 mode
= (inode
->i_mode
& S_IXGRP
)*(S_ISGID
/S_IXGRP
) | S_ISUID
; 193 /* was any of the uid bits set? */ 194 mode
&= inode
->i_mode
; 195 if(mode
&& !capable(CAP_FSETID
)) 197 inode
->i_mode
&= ~mode
; 198 mark_inode_dirty(inode
); 202 static ssize_t
udf_file_write(struct file
* file
,const char* buf
, 203 size_t count
, loff_t
*ppos
) 206 struct inode
*inode
= file
->f_dentry
->d_inode
; 209 if(UDF_I_ALLOCTYPE(inode
) == ICB_FLAG_AD_IN_ICB
) 212 struct buffer_head
*bh
; 214 if((bh
=udf_expand_adinicb(inode
, &i
,0, &err
))) 215 udf_release_data(bh
); 218 retval
=generic_file_write(file
, buf
, count
, ppos
, block_write_partial_page
); 222 inode
->i_ctime
= inode
->i_mtime
= CURRENT_TIME
; 223 UDF_I_UCTIME(inode
) =UDF_I_UMTIME(inode
) = CURRENT_UTIME
; 225 mark_inode_dirty(inode
); 233 * Read from an open file. 236 * Optional - sys_read() will return -EINVAL if this routine is not 239 * Refer to sys_read() in fs/read_write.c 242 * Note that you can use generic_file_read() instead, which requires that 243 * udf_readpage() be available, but you can use generic_readpage(), which 244 * requires that udf_block_map() be available. Reading will then be done by 245 * memory-mapping the file a page at a time. This is not suitable for 246 * devices that don't handle read-ahead [example: CD-R/RW that may have 247 * blank sectors that shouldn't be read]. 249 * Refer to generic_file_read() in mm/filemap.c and to generic_readpage() 252 * Block devices can use block_read() instead. Refer to fs/block_dev.c 255 * inode Pointer to inode to read from (never NULL). 256 * filp Pointer to file to read from (never NULL). 257 * buf Point to read buffer (validated). 258 * bufsize Size of read buffer. 261 * <return> Bytes read (>=0) or an error code (<0) that 262 * sys_read() will return. 265 * July 1, 1997 - Andrew E. Mileski 266 * Written, tested, and released. 268 static ssize_t
udf_file_read_adinicb(struct file
* filp
,char* buf
, 269 size_t bufsize
, loff_t
* loff
) 271 struct inode
*inode
= filp
->f_dentry
->d_inode
; 272 Uint32 size
, left
, pos
, block
; 273 struct buffer_head
*bh
= NULL
; 275 size
= inode
->i_size
; 286 pos
= *loff
+UDF_I_EXT0OFFS(inode
); 287 block
=udf_block_map(inode
,0); 288 if(!(bh
=udf_tread(inode
->i_sb
, 289 udf_get_lb_pblock(inode
->i_sb
,UDF_I_LOCATION(inode
),0), 290 inode
->i_sb
->s_blocksize
))) 294 if(!copy_to_user(buf
, bh
->b_data
+ pos
, left
)) 309 * Optional - sys_ioctl() will return -ENOTTY if this routine is not 310 * available, and the ioctl cannot be handled without filesystem help. 312 * sys_ioctl() handles these ioctls that apply only to regular files: 313 * FIBMAP [requires udf_block_map()], FIGETBSZ, FIONREAD 314 * These ioctls are also handled by sys_ioctl(): 315 * FIOCLEX, FIONCLEX, FIONBIO, FIOASYNC 316 * All other ioctls are passed to the filesystem. 318 * Refer to sys_ioctl() in fs/ioctl.c 322 * inode Pointer to inode that ioctl was issued on. 323 * filp Pointer to file that ioctl was issued on. 324 * cmd The ioctl command. 325 * arg The ioctl argument [can be interpreted as a 326 * user-space pointer if desired]. 329 * <return> Success (>=0) or an error code (<=0) that 330 * sys_ioctl() will return. 333 * July 1, 1997 - Andrew E. Mileski 334 * Written, tested, and released. 336 intudf_ioctl(struct inode
*inode
,struct file
*filp
,unsigned int cmd
, 341 struct buffer_head
*bh
= NULL
; 342 struct FileEntry
*fe
; 345 if(permission(inode
, MAY_READ
) !=0) 347 udf_debug("no permission to access inode %lu\n", 354 udf_debug("invalid argument to udf_ioctl\n"); 358 /* first, do ioctls that don't need to udf_read */ 361 case UDF_GETVOLIDENT
: 362 if( (result
==verify_area(VERIFY_WRITE
, (char*)arg
,32)) ==0) 363 result
=copy_to_user((char*)arg
,UDF_SB_VOLIDENT(inode
->i_sb
),32); 368 /* ok, we need to read the inode */ 369 bh
=udf_read_ptagged(inode
->i_sb
,UDF_I_LOCATION(inode
),0, &ident
); 371 if(!bh
|| ident
!= TID_FILE_ENTRY
) 373 udf_debug("bread failed (ino=%ld) or ident (%d) != TID_FILE_ENTRY", 374 inode
->i_ino
, ident
); 378 fe
= (struct FileEntry
*)bh
->b_data
; 379 size
=le32_to_cpu(fe
->lengthExtendedAttr
); 384 if( (result
=verify_area(VERIFY_WRITE
, (char*)arg
,4)) ==0) 385 result
=put_user(size
, (int*)arg
); 389 if( (result
=verify_area(VERIFY_WRITE
, (char*)arg
, size
)) ==0) 390 result
=copy_to_user((char*)arg
, fe
->extendedAttr
, size
); 394 udf_debug("ino=%ld, cmd=%d\n", inode
->i_ino
, cmd
); 398 udf_release_data(bh
); 406 * Called when all references to the file are closed 409 * Discard prealloced blocks 414 static intudf_release_file(struct inode
* inode
,struct file
* filp
) 416 if(filp
->f_mode
& FMODE_WRITE
) 417 udf_discard_prealloc(inode
); 421 #if BITS_PER_LONG < 64 426 * Called when an inode is about to be open. 429 * Use this to disallow opening RW large files on 32 bit systems. 434 static intudf_open_file(struct inode
* inode
,struct file
* filp
) 436 if(inode
->i_size
== (Uint32
)-1&& (filp
->f_mode
& FMODE_WRITE
))