"Fossies" - the Fresh Open Source Software Archive

Member "cdfs-2.6.27/cddata.c" (8 Dec 2008, 5441 Bytes) of archive /linux/misc/cdfs-2.6.27.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cddata.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2   
    3   File cddata.c - routines for 2048 byte frames for cdfs
    4 
    5   
    6   Copyright (c) 1999, 2000, 2001 by Michiel Ronsse 
    7   
    8   
    9   This program is free software; you can redistribute it and/or modify
   10   it under the terms of the GNU General Public License as published by
   11   the Free Software Foundation; either version 2, or (at your option)
   12   any later version.
   13   
   14   This program is distributed in the hope that it will be useful,
   15   but WITHOUT ANY WARRANTY; without even the implied warranty of
   16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17   GNU General Public License for more details.
   18   
   19   You should have received a copy of the GNU General Public License
   20   along with this program; if not, write to the Free Software
   21   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
   22   
   23 */
   24 
   25 
   26 #include "cdfs.h"
   27 
   28 
   29 /***************************************************************************/
   30 
   31 
   32 unsigned cdfs_data_bmap(struct super_block * sb, int inode, int block){
   33   int result;
   34   cd * this_cd = cdfs_info(sb);
   35   track_info * this_track = &(this_cd->track[inode]);
   36   int session;
   37 
   38   if ((this_track->type == BOOT) || (this_track->type == HFS) || (block<20) || this_cd->single)  
   39     /* 20 sectors seems to be OK for ISO */ 
   40 
   41     result = this_track->start_lba+block;
   42 
   43   else {
   44     
   45     /* ISO past sector 18 */
   46     result = block;
   47     
   48     /* post processing */
   49     for (session=0; session < this_cd->nr_iso_sessions; session++){
   50       PRINT("this is sector %d, checking session %d: %d-%d\n", result, session, 
   51             this_cd->lba_iso_sessions[session].start,
   52             this_cd->lba_iso_sessions[session].stop);
   53       if ((this_cd->lba_iso_sessions[session].start<=result)
   54           && (result<=this_cd->lba_iso_sessions[session].stop)) 
   55         goto exit;    /* OK, reading from an ISO session */
   56       if ((this_cd->lba_iso_sessions[session].stop<result)
   57           && (result<this_cd->lba_iso_sessions[session].start)) {
   58         result = 0;
   59         goto exit;    /* not OK, reading between two ISO sessions => we force 0*/
   60       }
   61     }
   62 
   63     /* We only get here if we read past the last session => we force 0 */
   64     result = 0;
   65 
   66   }
   67 
   68  exit: 
   69 
   70   PRINT("BMAP('%s', block %d) => sector %d\n", this_track->name, block, result);
   71 
   72   return result;
   73 }
   74 
   75 /***************************************************************************/
   76 
   77 
   78 struct file_operations cdfs_cddata_file_operations = {
   79   .read = do_sync_read,
   80   .aio_read = generic_file_aio_read,
   81 #ifdef OLD_KERNEL
   82   .mmap             = generic_file_mmap
   83 #else
   84   .mmap             = generic_file_readonly_mmap,
   85   .sendfile         = generic_file_sendfile
   86 #endif
   87 };
   88 
   89 struct address_space_operations cdfs_cddata_aops = {
   90   .readpage         = kcdfsd_add_cddata_request
   91 };
   92 
   93 /************************************************************/
   94 
   95 int kcdfsd_add_cddata_request(struct file * file, struct page *page){
   96   return kcdfsd_add_request(file->f_dentry, page, CDDATA_REQUEST);
   97 }
   98 
   99 /***********************************************************/            
  100 
  101 int cdfs_read_rawDATA_frame(struct super_block * sb, unsigned lba, unsigned char *buf) {     
  102   struct buffer_head * bh;
  103 
  104   bh=cdfs_bread(sb, lba, CD_FRAMESIZE);
  105   if (!bh) {
  106     // dit gebeurt indien track1!=ISO is, bv. De Morgen CD
  107     printk("cdfs_read_rawDATA(%x, %u, %x) FAILED!\n", (unsigned)sb, lba, (unsigned)buf);
  108   } else {
  109     memcpy(buf, bh->b_data, CD_FRAMESIZE);
  110     brelse(bh);
  111   }
  112   return 0;
  113 }
  114 
  115 /***********************************************************/            
  116 
  117 void cdfs_copy_from_cddata(struct super_block * sb, int inode, unsigned int start,
  118     unsigned int stop, char * buf){
  119   int start_sector, start_byte, stop_sector, stop_byte, sector;
  120   int status;
  121   cd * this_cd = cdfs_info(sb);
  122   unsigned int data_size = CD_FRAMESIZE;
  123     
  124   start_sector = start / data_size;
  125   start_byte   = start % data_size;
  126   stop_sector  = stop  / data_size;
  127   stop_byte    = stop  % data_size;
  128 
  129   if (!stop_byte) {            /* empty frame */
  130     stop_sector -= 1;
  131     stop_byte    = CD_FRAMESIZE;
  132   }
  133   
  134   PRINT("%d[%d-%d] -> 0x%x...0x%x  ... (%d,%d),(%d,%d)\n",
  135         inode, start, stop, (int)buf, (int)buf+stop-start,
  136         start_sector,start_byte,stop_sector,stop_byte);
  137   
  138   for (sector=start_sector; sector<=stop_sector; sector++) {
  139     
  140     unsigned lba = cdfs_data_bmap(sb, inode, sector);
  141     
  142     PRINT("reading sector %d, lba=%d\n", sector, lba);
  143     
  144     if (this_cd->cache_sector == lba) {
  145       PRINT("using cache\n");
  146     } else {
  147       this_cd->cache_sector = lba;
  148       if((status = cdfs_read_rawDATA_frame(sb, lba, this_cd->cache))) {
  149         printk("copy_from_cddata(%d): ioctl failed: %d\n", lba, status);
  150         return;
  151       }          
  152     }
  153     
  154     {
  155       char * copy_start;
  156       int copy_length;
  157       
  158       if (sector==start_sector) {
  159         copy_start  = this_cd->cache+start_byte;
  160         if (sector!=stop_sector)
  161           copy_length = data_size-start_byte;
  162         else
  163           copy_length = stop_byte-start_byte;
  164       } else if (sector==stop_sector) {
  165         copy_start  = this_cd->cache;
  166         copy_length = stop_byte;
  167       } else {
  168         copy_start  = this_cd->cache;
  169         copy_length = data_size;
  170       }
  171       PRINT("memcpy(0x%x, %x, %d)\n", (int)buf, (int)copy_start, copy_length);      
  172       memcpy(buf, (char*)copy_start, copy_length);
  173       buf+=copy_length;
  174     }
  175 
  176   }
  177 }
  178 
  179 
  180 /***************************************************************************/