+ /* Sanity checks to ensure we can touch this volume */
+ if (volinfo.v_vfs_ea != AFPVOL_EA_AD && volinfo.v_vfs_ea != AFPVOL_EA_SYS) {
+ dbd_log( LOGSTD, "Unknown Extended Attributes option: %u", volinfo.v_vfs_ea);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Put "/.AppleDB" at end of volpath, get path from volinfo file */
+ if ( (strlen(volinfo.v_dbpath) + strlen("/.AppleDB")) > (PATH_MAX - 1) ) {
+ dbd_log( LOGSTD, "Volume pathname too long");
+ exit(EXIT_FAILURE);
+ }
+ strncpy(dbpath, volinfo.v_dbpath, PATH_MAX - 9 - 1);
+ strcat(dbpath, "/.AppleDB");
+
+ /* Check or create dbpath */
+ int dbdirfd = open(dbpath, O_RDONLY);
+ if (dbdirfd == -1 && errno == ENOENT) {
+ if (errno == ENOENT) {
+ if ((mkdir(dbpath, 0755)) != 0) {
+ dbd_log( LOGSTD, "Can't create .AppleDB for \"%s\": %s", dbpath, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ dbd_log( LOGSTD, "Somethings wrong with .AppleDB for \"%s\", giving up: %s", dbpath, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ close(dbdirfd);
+ }
+
+ /*
+ Before we do anything else, check if there is an instance of cnid_dbd
+ running already and silently exit if yes.
+ */
+ lockfd = get_lock(dbpath);
+
+ /* Prepare upgrade ? */
+ if (prep_upgrade) {
+ if (dbif_prep_upgrade(dbpath))
+ goto exit_failure;
+ goto exit_success;
+ }
+