~ubuntu-branches/ubuntu/hardy/ntfs-3g/hardy

« back to all changes in this revision

Viewing changes to libntfs-3g/device.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Cécile (Le_Vert)
  • Date: 2006-11-24 00:33:43 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061124003343-9ag45l8hiuz69nkd
Tags: upstream-0.0.0+20061031
Import upstream version 0.0.0+20061031

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * device.c - Low level device io functions. Part of the Linux-NTFS project.
 
2
 * device.c - Low level device io functions. Originated from the Linux-NTFS project.
3
3
 *
4
4
 * Copyright (c) 2004-2006 Anton Altaparmakov
5
5
 * Copyright (c) 2004-2006 Szabolcs Szakacsits
15
15
 * GNU General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program (in the main directory of the Linux-NTFS
 
18
 * along with this program (in the main directory of the NTFS-3G
19
19
 * distribution in the file COPYING); if not, write to the Free Software
20
20
 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
21
 */
230
230
s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count,
231
231
                const void *b)
232
232
{
233
 
        s64 written, total;
 
233
        s64 written, total, ret = -1;
234
234
        struct ntfs_device_operations *dops;
235
235
 
236
236
        ntfs_log_trace("Entering for pos 0x%llx, count 0x%llx.\n", pos, count);
237
237
        if (!b || count < 0 || pos < 0) {
238
238
                errno = EINVAL;
239
 
                return -1;
 
239
                goto out;
240
240
        }
241
241
        if (!count)
242
242
                return 0;
243
243
        if (NDevReadOnly(dev)) {
244
244
                errno = EROFS;
245
 
                return -1;
 
245
                goto out;
246
246
        }
247
247
        dops = dev->d_ops;
248
248
        /* Locate to position. */
249
249
        if (dops->seek(dev, pos, SEEK_SET) == (off_t)-1) {
250
250
                ntfs_log_perror("ntfs_pwrite: seek to 0x%llx returned error",
251
251
                                pos);
252
 
                return -1;
 
252
                goto out;
253
253
        }
254
254
        NDevSetDirty(dev);
255
 
        /* Write the data. */
256
255
        for (total = 0; count; count -= written, total += written) {
257
256
                written = dops->write(dev, (const char*)b + total, count);
258
257
                /* If everything ok, continue. */
264
263
                if (!written || total)
265
264
                        break;
266
265
                /* Nothing written and error, return error status. */
267
 
                return written;
 
266
                total = written;
 
267
                break;
268
268
        }
269
 
        /* Finally, return the number of bytes written. */
270
 
        return total;
 
269
        ret = total;
 
270
out:    
 
271
        return ret;
271
272
}
272
273
 
273
274
/**