[Libburn] get_sectors clean and up global namespace
Tiago Cogumbreiro
cogumbreiro@linus.uac.pt
Sun, 14 Dec 2003 14:31:35 -0100
--=-UFme4dST7ZmUq9aPNm7M
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi again.
I started by adding funcs for getting sector of a dsic and session but i
have a question, do i count lead-out/in? If so how do i know if the disc
will open/closed
Then i looked carefully to the namespace and took the liberty to make
the following changes:
+ added: burn_disc_get_sectors, burn_session_get_sectors
Major changes:
With the idea of OOP i changed the following funcs:
old function name -> new function name
burn_get_disc_status -> burn_disc_get_status
burn_get_drive_status -> burn_drive_get_status
burn_erase_disc -> burn_disc_erase
burn_read_disc -> burn_disc_read
burn_write_disc -> burn_disc_write
Because we are adding a session to a disc why not:
burn_session_add -> burn_disc_add
burn_session_del -> burn_disc_del
The same thing applies to adding tracks to sessions:
burn_track_add -> burn_session_add
burn_track_del -> burn_session_del
Comments, correction, flames? :D
Btw, when the lib is somewhat stable i'll start making bindings to it, I
can do Python, Java and maybe C# (little new on that lang), might be a
good improvement on the lib to be cross language ;)
This way we will have .BURN :P haha
Tiago Cogumbreiro
--=-UFme4dST7ZmUq9aPNm7M
Content-Disposition: attachment; filename=namespace_cleanup.diff
Content-Type: text/x-patch; name=namespace_cleanup.diff; charset=
Content-Transfer-Encoding: 7bit
? libburn/.libburn.h.swp
Index: libburn/async.c
===================================================================
RCS file: /cvs/burn/burn/libburn/async.c,v
retrieving revision 1.12
diff -p -u -r1.12 async.c
--- libburn/async.c 9 Dec 2003 00:55:43 -0000 1.12
+++ libburn/async.c 14 Dec 2003 15:25:01 -0000
@@ -133,12 +133,12 @@ int burn_drive_scan(struct burn_drive_in
static void* erase_worker_func(struct w_list *w)
{
- burn_erase_disc_sync(w->u.erase.drive, w->u.erase.fast);
+ burn_disc_erase_sync(w->u.erase.drive, w->u.erase.fast);
remove_worker(pthread_self());
return NULL;
}
-void burn_erase_disc(struct drive *drive, int fast)
+void burn_disc_erase(struct drive *drive, int fast)
{
struct erase_opts o;
@@ -153,7 +153,7 @@ void burn_erase_disc(struct drive *drive
static void* write_disc_worker_func(struct w_list *w)
{
- burn_write_disc_sync(w->u.write.drive, w->u.write.disc,
+ burn_disc_write_sync(w->u.write.drive, w->u.write.disc,
w->u.write.opts);
/* the options are refcounted, free out ref count which we added
@@ -164,7 +164,7 @@ static void* write_disc_worker_func(stru
return NULL;
}
-void burn_write_disc(struct drive *drive, struct disc *disc,
+void burn_disc_write(struct drive *drive, struct disc *disc,
struct burn_write_opts *opts)
{
struct write_opts o;
Index: libburn/drive.c
===================================================================
RCS file: /cvs/burn/burn/libburn/drive.c,v
retrieving revision 1.243
diff -p -u -r1.243 drive.c
--- libburn/drive.c 14 Dec 2003 02:04:06 -0000 1.243
+++ libburn/drive.c 14 Dec 2003 15:25:02 -0000
@@ -144,7 +144,7 @@ void burn_wait_all()
}
}
-void burn_erase_disc_sync(struct drive *d, int fast)
+void burn_disc_erase_sync(struct drive *d, int fast)
{
burn_message_clear_queue();
@@ -177,7 +177,7 @@ void burn_erase_disc_sync(struct drive *
d->busy = BURN_DRIVE_IDLE;
}
-enum burn_disc_status burn_get_disc_status(struct drive *d)
+enum burn_disc_status burn_disc_get_status(struct drive *d)
{
assert(!d->released);
return d->status;
@@ -187,7 +187,7 @@ int burn_disc_erasable(struct drive *d)
{
return d->erasable;
}
-enum burn_drive_status burn_get_drive_status(struct drive *d, struct burn_progress *p)
+enum burn_drive_status burn_drive_get_status(struct drive *d, struct burn_progress *p)
{
if (p) {
memcpy(p, &(d->progress), sizeof(struct burn_progress));
Index: libburn/libburn.h
===================================================================
RCS file: /cvs/burn/burn/libburn/libburn.h,v
retrieving revision 1.173
diff -p -u -r1.173 libburn.h
--- libburn/libburn.h 14 Dec 2003 02:57:10 -0000 1.173
+++ libburn/libburn.h 14 Dec 2003 15:25:06 -0000
@@ -508,7 +508,7 @@ void burn_drive_info_free(struct burn_dr
int burn_drive_grab(struct drive *drive, int load);
/** Release a drive. This should not be done until the drive is no longer
- busy (see burn_get_drive_status).
+ busy (see burn_drive_get_status).
@param drive The drive to release.
@param eject Nonzero to make the drive eject the disc in it.
*/
@@ -528,7 +528,7 @@ int burn_drive_get_block_types(struct dr
@param drive The drive to query for a disc.
@return The status of the drive, or what kind of disc is in it.
*/
-enum burn_disc_status burn_get_disc_status(struct drive *drive);
+enum burn_disc_status burn_disc_get_status(struct drive *drive);
/** Tells whether a disc can be erased or not
@return Non-zero means erasable
@@ -540,7 +540,7 @@ int burn_disc_erasable(struct drive *d);
@param p Returns the progress of the operation, NULL if you don't care
@return the current status of the drive. See also burn_drive_status.
*/
-enum burn_drive_status burn_get_drive_status(struct drive *drive, struct burn_progress *p);
+enum burn_drive_status burn_drive_get_status(struct drive *drive, struct burn_progress *p);
struct burn_write_opts *burn_write_opts_new();
void burn_write_opts_free(struct burn_write_opts *opts);
@@ -557,7 +557,7 @@ void burn_read_opts_free(struct burn_rea
@param fast Nonzero to do a fast erase, where only the disc's headers are
erased; zero to erase the entire disc.
*/
-void burn_erase_disc(struct drive *drive, int fast);
+void burn_disc_erase(struct drive *drive, int fast);
/** Read a disc from the drive and write it to an fd pair. The drive must be
grabbed successfully BEFORE calling this function. Always ensure that the
@@ -565,7 +565,7 @@ void burn_erase_disc(struct drive *drive
@param drive The drive from which to read a disc.
@param o The options for the read operation.
*/
-void burn_read_disc(struct drive *drive, const struct burn_read_opts *o);
+void burn_disc_read(struct drive *drive, const struct burn_read_opts *o);
/** Write a disc in the drive. The drive must be grabbed successfully BEFORE
calling this function. Always ensure that the drive reports a status of
@@ -575,7 +575,7 @@ void burn_read_disc(struct drive *drive,
@param disc The struct disc * that described the disc to be created
@param o The options for the writing operation.
*/
-void burn_write_disc(struct drive *drive, struct disc *disc,
+void burn_disc_write(struct drive *drive, struct disc *disc,
struct burn_write_opts *o);
/** Cancel an operation on a drive.
@@ -626,13 +626,13 @@ void burn_session_free(struct session *s
@param pos position to add at (BURN_POS_END is "at the end")
@return 0 for failure, 1 for success
*/
-int burn_session_add(struct disc *d, struct session *s, unsigned int pos);
+int burn_disc_add(struct disc *d, struct session *s, unsigned int pos);
/** Remove a session from a disc
@param d Disc to remove session from
@param s Session pointer to find and remove
*/
-int burn_session_del(struct disc *d, struct session *s);
+int burn_disc_del(struct disc *d, struct session *s);
/** Create a track (for TAO recording, or to put in a session) */
@@ -649,14 +649,14 @@ void burn_track_free(struct track *t);
@param pos position to add at (BURN_POS_END is "at the end")
@return 0 for failure, 1 for success
*/
-int burn_track_add(struct session *s, struct track *t, unsigned int pos);
+int burn_session_add(struct session *s, struct track *t, unsigned int pos);
/** Remove a track from a session
@param s Session to remove track from
@param t Track pointer to find and remove
@return 0 for failure, 1 for success
*/
-int burn_track_del(struct session *s, struct track *t);
+int burn_session_del(struct session *s, struct track *t);
/** Define the data in a track
Index: libburn/mmc.c
===================================================================
RCS file: /cvs/burn/burn/libburn/mmc.c,v
retrieving revision 1.125
diff -p -u -r1.125 mmc.c
--- libburn/mmc.c 14 Dec 2003 02:57:10 -0000 1.125
+++ libburn/mmc.c 14 Dec 2003 15:25:07 -0000
@@ -164,7 +164,7 @@ void mmc_read_toc(struct drive *d)
for (i = 0; i < c.page->data[3]; i++) {
session = burn_session_create();
- burn_session_add(d->disc, session, BURN_POS_END);
+ burn_disc_add(d->disc, session, BURN_POS_END);
burn_session_free(session);
}
for (i = 0; i < d->toc_entries; i++, tdata += 11) {
@@ -179,7 +179,7 @@ void mmc_read_toc(struct drive *d)
if (burn_msf_to_lba(tdata[8], tdata[9], tdata[10])) {
d->disc->session[0]->hidefirst = 1;
track = burn_track_create();
- burn_track_add(
+ burn_session_add(
d->disc->session[tdata[0] - 1],
track, BURN_POS_END);
burn_track_free(track);
@@ -188,7 +188,7 @@ void mmc_read_toc(struct drive *d)
}
if (tdata[3] < 100) {
track = burn_track_create();
- burn_track_add(d->disc->session[tdata[0] - 1],
+ burn_session_add(d->disc->session[tdata[0] - 1],
track, BURN_POS_END);
track->entry = &d->toc_entry[i];
burn_track_free(track);
Index: libburn/read.c
===================================================================
RCS file: /cvs/burn/burn/libburn/read.c,v
retrieving revision 1.12
diff -p -u -r1.12 read.c
--- libburn/read.c 9 Dec 2003 01:47:50 -0000 1.12
+++ libburn/read.c 14 Dec 2003 15:25:07 -0000
@@ -22,7 +22,7 @@
#include "read.h"
#include "options.h"
-void burn_read_disc(struct drive *d, const struct burn_read_opts *o)
+void burn_disc_read(struct drive *d, const struct burn_read_opts *o)
{
#if 0
int i, end, maxsects, finish;
Index: libburn/structure.c
===================================================================
RCS file: /cvs/burn/burn/libburn/structure.c,v
retrieving revision 1.23
diff -p -u -r1.23 structure.c
--- libburn/structure.c 14 Dec 2003 02:30:43 -0000 1.23
+++ libburn/structure.c 14 Dec 2003 15:25:10 -0000
@@ -81,7 +81,7 @@ void burn_session_free(struct session *s
}
-int burn_session_add(struct disc *d, struct session *s, unsigned int pos)
+int burn_disc_add(struct disc *d, struct session *s, unsigned int pos)
{
RESIZE(d, session, pos);
d->session[pos] = s;
@@ -117,7 +117,7 @@ void burn_track_free(struct track *t)
}
}
-int burn_track_add(struct session *s, struct track *t, unsigned int pos)
+int burn_session_add(struct session *s, struct track *t, unsigned int pos)
{
RESIZE(s, track, pos);
s->track[pos] = t;
@@ -125,7 +125,7 @@ int burn_track_add(struct session *s, st
return 1;
}
-int burn_track_del(struct session *s, struct track *t)
+int burn_session_del(struct session *s, struct track *t)
{
int i, pos = -1;
assert(s->track != NULL);
@@ -222,3 +222,19 @@ int burn_track_get_sectors(struct track
printf("%d sectors of %d length\n", sectors, seclen);
return sectors;
}
+
+int burn_session_get_sectors(struct session *s)
+{
+ int sectors = 0, i;
+ for (i = 0; i < s->tracks; i++)
+ sectors += burn_track_get_sectors(s->track[i]);
+ return sectors;
+}
+
+int burn_disc_get_sectors(struct disc *d)
+{
+ int sectors = 0; i;
+ for (i = 0; i < d->sessions; i++)
+ sectors += burn_session_get_sectors(d->session[i]);
+ return sectors;
+}
Index: libburn/write.c
===================================================================
RCS file: /cvs/burn/burn/libburn/write.c,v
retrieving revision 1.31
diff -p -u -r1.31 write.c
--- libburn/write.c 14 Dec 2003 02:57:10 -0000 1.31
+++ libburn/write.c 14 Dec 2003 15:25:12 -0000
@@ -309,7 +309,7 @@ printf("cutting short by %d sectors\n",
i = t->offset;
}
-void burn_write_disc_sync(struct drive *d, struct disc *disc,
+void burn_disc_write_sync(struct drive *d, struct disc *disc,
const struct burn_write_opts *o)
{
struct buffer buf;
Index: test/blank.c
===================================================================
RCS file: /cvs/burn/burn/test/blank.c,v
retrieving revision 1.19
diff -p -u -r1.19 blank.c
--- test/blank.c 14 Dec 2003 00:44:33 -0000 1.19
+++ test/blank.c 14 Dec 2003 15:25:14 -0000
@@ -21,11 +21,11 @@ static void blank_disc(struct drive *dri
return;
}
- while (burn_get_drive_status(drive, NULL)) {
+ while (burn_drive_get_status(drive, NULL)) {
usleep(1000);
}
- while ((s = burn_get_disc_status(drive)) == BURN_DISC_UNREADY)
+ while ((s = burn_disc_get_status(drive)) == BURN_DISC_UNREADY)
usleep(1000);
printf("%d\n", s);
if (s != BURN_DISC_FULL) {
@@ -35,9 +35,9 @@ static void blank_disc(struct drive *dri
}
fprintf(stderr, "Blanking disc...");
- burn_erase_disc(drive, 1);
+ burn_disc_erase(drive, 1);
- while (burn_get_drive_status(drive, &p)) {
+ while (burn_drive_get_status(drive, &p)) {
printf("%d\n", p.current_sector);
usleep(1000);
}
Index: test/burniso.c
===================================================================
RCS file: /cvs/burn/burn/test/burniso.c,v
retrieving revision 1.43
diff -p -u -r1.43 burniso.c
--- test/burniso.c 14 Dec 2003 00:44:33 -0000 1.43
+++ test/burniso.c 14 Dec 2003 15:25:14 -0000
@@ -26,7 +26,7 @@ void burn_iso(struct drive *drive, const
disc = burn_disc_create();
session = burn_session_create();
- burn_session_add(disc, session, BURN_POS_END);
+ burn_disc_add(disc, session, BURN_POS_END);
tr = burn_track_create();
burn_track_define_data(tr, 0, 0, 0, BURN_BYTES | BURN_MODE1);
src = burn_file_source_new(path, NULL);
@@ -36,17 +36,17 @@ void burn_iso(struct drive *drive, const
printf("problem with the source\n");
return;
}
- burn_track_add(session, tr, BURN_POS_END);
+ burn_session_add(session, tr, BURN_POS_END);
burn_source_free(src);
if (!burn_drive_grab(drive, 1)) {
printf("Unable to open the drive!\n");
return;
}
- while (burn_get_drive_status(drive, NULL))
+ while (burn_drive_get_status(drive, NULL))
usleep(1000);
- while ((s = burn_get_disc_status(drive)) == BURN_DISC_UNREADY)
+ while ((s = burn_disc_get_status(drive)) == BURN_DISC_UNREADY)
usleep(1000);
if (s != BURN_DISC_BLANK) {
@@ -62,10 +62,10 @@ void burn_iso(struct drive *drive, const
o->underrun_proof = 0;
burn_structure_print_disc(disc);
- burn_write_disc(drive, disc, o);
+ burn_disc_write(drive, disc, o);
burn_write_opts_free(o);
- while (burn_get_drive_status(drive, &p)) {
+ while (burn_drive_get_status(drive, &p)) {
printf("S: %d/%d ", p.session, p.sessions);
printf("T: %d/%d ", p.track, p.tracks);
printf("L: %d: %d/%d\n", p.start_sector, p.current_sector, p.sectors);
Index: test/master.c
===================================================================
RCS file: /cvs/burn/burn/test/master.c,v
retrieving revision 1.16
diff -p -u -r1.16 master.c
--- test/master.c 14 Dec 2003 00:44:33 -0000 1.16
+++ test/master.c 14 Dec 2003 15:25:15 -0000
@@ -22,10 +22,10 @@ void burn_files(struct drive *drive, str
printf("Unable to open the drive!\n");
return;
}
- while (burn_get_drive_status(drive, NULL))
+ while (burn_drive_get_status(drive, NULL))
usleep(1000);
- while ((s = burn_get_disc_status(drive)) == BURN_DISC_UNREADY)
+ while ((s = burn_disc_get_status(drive)) == BURN_DISC_UNREADY)
usleep(1000);
if (s != BURN_DISC_BLANK) {
@@ -40,10 +40,10 @@ void burn_files(struct drive *drive, str
o->simulate = 1;
o->underrun_proof = 0;
burn_structure_print_disc(disc);
- burn_write_disc(drive, disc, o);
+ burn_disc_write(drive, disc, o);
burn_write_opts_free(o);
- while (burn_get_drive_status(drive, NULL)) {
+ while (burn_drive_get_status(drive, NULL)) {
sleep(1);
}
printf("\n");
@@ -61,7 +61,7 @@ void parse_args(int argc, char **argv, i
*disc = burn_disc_create();
session = burn_session_create();
- burn_session_add(*disc, session, BURN_POS_END);
+ burn_disc_add(*disc, session, BURN_POS_END);
for (i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "--drive")) {
++i;
@@ -86,7 +86,7 @@ void parse_args(int argc, char **argv, i
burn_track_set_source(tr, src);
burn_source_free(src);
burn_track_define_data(tr, 0, 0, 1, BURN_BYTES | BURN_AUDIO);
- burn_track_add(session, tr, BURN_POS_END);
+ burn_session_add(session, tr, BURN_POS_END);
}
}
if (help) {
Index: test/poll.c
===================================================================
RCS file: /cvs/burn/burn/test/poll.c,v
retrieving revision 1.9
diff -p -u -r1.9 poll.c
--- test/poll.c 14 Dec 2003 00:44:33 -0000 1.9
+++ test/poll.c 14 Dec 2003 15:25:15 -0000
@@ -23,10 +23,10 @@ static void poll_drive(int d)
return;
}
- while (burn_get_drive_status(drives[d].drive, NULL))
+ while (burn_drive_get_status(drives[d].drive, NULL))
usleep(1000);
- while ((s = burn_get_disc_status(drives[d].drive))
+ while ((s = burn_disc_get_status(drives[d].drive))
== BURN_DISC_UNREADY)
usleep(1000);
Index: test/rip.c
===================================================================
RCS file: /cvs/burn/burn/test/rip.c,v
retrieving revision 1.14
diff -p -u -r1.14 rip.c
--- test/rip.c 14 Dec 2003 01:49:17 -0000 1.14
+++ test/rip.c 14 Dec 2003 15:25:15 -0000
@@ -42,11 +42,11 @@ int main()
return EXIT_FAILURE;
}
- while (burn_get_drive_status(drive, NULL))
+ while (burn_drive_get_status(drive, NULL))
usleep(1000);
- burn_read_disc(drive, &o);
+ burn_disc_read(drive, &o);
#endif
return EXIT_SUCCESS;
}
Index: test/structest.c
===================================================================
RCS file: /cvs/burn/burn/test/structest.c,v
retrieving revision 1.9
diff -p -u -r1.9 structest.c
--- test/structest.c 14 Dec 2003 02:30:43 -0000 1.9
+++ test/structest.c 14 Dec 2003 15:25:15 -0000
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
disc = burn_disc_create();
session = burn_session_create();
- burn_session_add(disc, session, BURN_POS_END);
+ burn_disc_add(disc, session, BURN_POS_END);
/* Define a source for all of the tracks*/
path = strdup("/etc/hosts");
@@ -23,7 +23,7 @@ int main(int argc, char **argv)
/* Add ten tracks to a session */
for (i = 0; i < 10; i++) {
track = burn_track_create();
- burn_track_add(session, track, 0);
+ burn_session_add(session, track, 0);
if (burn_track_set_source(track, src) != BURN_SOURCE_OK) {
printf("problem with the source\n");
return 0;
@@ -34,7 +34,7 @@ int main(int argc, char **argv)
/* Add ten tracks to a session */
for (i = 0; i < 10; i++) {
track = burn_track_create();
- burn_track_add(session, track, 0);
+ burn_session_add(session, track, 0);
if (burn_track_set_source(track, src) != BURN_SOURCE_OK) {
printf("problem with the source\n");
return 0;
@@ -42,7 +42,7 @@ int main(int argc, char **argv)
}
/* Delete a session */
- burn_track_del(session, track);
+ burn_session_del(session, track);
burn_structure_print_disc(disc);
return EXIT_SUCCESS;
Index: test/toc.c
===================================================================
RCS file: /cvs/burn/burn/test/toc.c,v
retrieving revision 1.27
diff -p -u -r1.27 toc.c
--- test/toc.c 14 Dec 2003 02:57:10 -0000 1.27
+++ test/toc.c 14 Dec 2003 15:25:15 -0000
@@ -26,10 +26,10 @@ static void show_tocs()
continue;
}
- while (burn_get_drive_status(drives[i].drive, NULL))
+ while (burn_drive_get_status(drives[i].drive, NULL))
usleep(1000);
- while ((s = burn_get_disc_status(drives[i].drive))
+ while ((s = burn_disc_get_status(drives[i].drive))
== BURN_DISC_UNREADY)
usleep(1000);
if (s != BURN_DISC_FULL) {
--=-UFme4dST7ZmUq9aPNm7M--